nvdrv.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/hle/ipc_helpers.h"
  5. #include "core/hle/service/nvdrv/devices/nvdevice.h"
  6. #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
  7. #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h"
  8. #include "core/hle/service/nvdrv/devices/nvmap.h"
  9. #include "core/hle/service/nvdrv/nvdrv.h"
  10. #include "core/hle/service/nvdrv/interface.h"
  11. namespace Service {
  12. namespace Nvidia {
  13. std::weak_ptr<Module> nvdrv;
  14. void InstallInterfaces(SM::ServiceManager& service_manager) {
  15. auto module_ = std::make_shared<Module>();
  16. std::make_shared<NVDRV>(module_, "nvdrv")->InstallAsService(service_manager);
  17. std::make_shared<NVDRV>(module_, "nvdrv:a")->InstallAsService(service_manager);
  18. nvdrv = module_;
  19. }
  20. Module::Module() {
  21. auto nvmap_dev = std::make_shared<Devices::nvmap>();
  22. devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>();
  23. devices["/dev/nvmap"] = nvmap_dev;
  24. devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev);
  25. }
  26. u32 Module::Open(std::string device_name) {
  27. ASSERT_MSG(devices.find(device_name) != devices.end(), "Trying to open unknown device %s",
  28. device_name.c_str());
  29. auto device = devices[device_name];
  30. u32 fd = next_fd++;
  31. open_files[fd] = device;
  32. return fd;
  33. }
  34. u32 Module::Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output) {
  35. auto itr = open_files.find(fd);
  36. ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
  37. auto device = itr->second;
  38. return device->ioctl(command, input, output);
  39. }
  40. } // namespace Nvidia
  41. } // namespace Service