nvdrv.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <utility>
  5. #include "core/hle/ipc_helpers.h"
  6. #include "core/hle/service/nvdrv/devices/nvdevice.h"
  7. #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
  8. #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h"
  9. #include "core/hle/service/nvdrv/devices/nvhost_ctrl.h"
  10. #include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h"
  11. #include "core/hle/service/nvdrv/devices/nvhost_gpu.h"
  12. #include "core/hle/service/nvdrv/devices/nvhost_nvdec.h"
  13. #include "core/hle/service/nvdrv/devices/nvmap.h"
  14. #include "core/hle/service/nvdrv/interface.h"
  15. #include "core/hle/service/nvdrv/nvdrv.h"
  16. #include "core/hle/service/nvdrv/nvmemp.h"
  17. namespace Service::Nvidia {
  18. std::weak_ptr<Module> nvdrv;
  19. void InstallInterfaces(SM::ServiceManager& service_manager) {
  20. auto module_ = std::make_shared<Module>();
  21. std::make_shared<NVDRV>(module_, "nvdrv")->InstallAsService(service_manager);
  22. std::make_shared<NVDRV>(module_, "nvdrv:a")->InstallAsService(service_manager);
  23. std::make_shared<NVDRV>(module_, "nvdrv:s")->InstallAsService(service_manager);
  24. std::make_shared<NVDRV>(module_, "nvdrv:t")->InstallAsService(service_manager);
  25. std::make_shared<NVMEMP>()->InstallAsService(service_manager);
  26. nvdrv = module_;
  27. }
  28. Module::Module() {
  29. auto nvmap_dev = std::make_shared<Devices::nvmap>();
  30. devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>(nvmap_dev);
  31. devices["/dev/nvhost-gpu"] = std::make_shared<Devices::nvhost_gpu>(nvmap_dev);
  32. devices["/dev/nvhost-ctrl-gpu"] = std::make_shared<Devices::nvhost_ctrl_gpu>();
  33. devices["/dev/nvmap"] = nvmap_dev;
  34. devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev);
  35. devices["/dev/nvhost-ctrl"] = std::make_shared<Devices::nvhost_ctrl>();
  36. devices["/dev/nvhost-nvdec"] = std::make_shared<Devices::nvhost_nvdec>();
  37. }
  38. u32 Module::Open(const std::string& device_name) {
  39. ASSERT_MSG(devices.find(device_name) != devices.end(), "Trying to open unknown device {}",
  40. device_name);
  41. auto device = devices[device_name];
  42. const u32 fd = next_fd++;
  43. open_files[fd] = std::move(device);
  44. return fd;
  45. }
  46. u32 Module::Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output) {
  47. auto itr = open_files.find(fd);
  48. ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
  49. auto& device = itr->second;
  50. return device->ioctl({command}, input, output);
  51. }
  52. ResultCode Module::Close(u32 fd) {
  53. auto itr = open_files.find(fd);
  54. ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
  55. open_files.erase(itr);
  56. // TODO(flerovium): return correct result code if operation failed.
  57. return RESULT_SUCCESS;
  58. }
  59. } // namespace Service::Nvidia