nvdrv.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/nvhost_ctrl.h"
  9. #include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h"
  10. #include "core/hle/service/nvdrv/devices/nvhost_gpu.h"
  11. #include "core/hle/service/nvdrv/devices/nvmap.h"
  12. #include "core/hle/service/nvdrv/interface.h"
  13. #include "core/hle/service/nvdrv/nvdrv.h"
  14. #include "core/hle/service/nvdrv/nvmemp.h"
  15. namespace Service {
  16. namespace Nvidia {
  17. std::weak_ptr<Module> nvdrv;
  18. void InstallInterfaces(SM::ServiceManager& service_manager) {
  19. auto module_ = std::make_shared<Module>();
  20. std::make_shared<NVDRV>(module_, "nvdrv")->InstallAsService(service_manager);
  21. std::make_shared<NVDRV>(module_, "nvdrv:a")->InstallAsService(service_manager);
  22. std::make_shared<NVDRV>(module_, "nvdrv:s")->InstallAsService(service_manager);
  23. std::make_shared<NVDRV>(module_, "nvdrv:t")->InstallAsService(service_manager);
  24. std::make_shared<NVMEMP>()->InstallAsService(service_manager);
  25. nvdrv = module_;
  26. }
  27. Module::Module() {
  28. auto nvmap_dev = std::make_shared<Devices::nvmap>();
  29. devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>(nvmap_dev);
  30. devices["/dev/nvhost-gpu"] = std::make_shared<Devices::nvhost_gpu>(nvmap_dev);
  31. devices["/dev/nvhost-ctrl-gpu"] = std::make_shared<Devices::nvhost_ctrl_gpu>();
  32. devices["/dev/nvmap"] = nvmap_dev;
  33. devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev);
  34. devices["/dev/nvhost-ctrl"] = std::make_shared<Devices::nvhost_ctrl>();
  35. }
  36. u32 Module::Open(std::string device_name) {
  37. ASSERT_MSG(devices.find(device_name) != devices.end(), "Trying to open unknown device %s",
  38. device_name.c_str());
  39. auto device = devices[device_name];
  40. u32 fd = next_fd++;
  41. open_files[fd] = device;
  42. return fd;
  43. }
  44. u32 Module::Ioctl(u32 fd, u32_le command, const std::vector<u8>& input, std::vector<u8>& output) {
  45. auto itr = open_files.find(fd);
  46. ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
  47. auto device = itr->second;
  48. return device->ioctl({command}, input, output);
  49. }
  50. ResultCode Module::Close(u32 fd) {
  51. auto itr = open_files.find(fd);
  52. ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
  53. open_files.erase(itr);
  54. // TODO(flerovium): return correct result code if operation failed.
  55. return RESULT_SUCCESS;
  56. }
  57. } // namespace Nvidia
  58. } // namespace Service