nvdrv.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. ResultCode Module::Close(u32 fd) {
  41. auto itr = open_files.find(fd);
  42. ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
  43. open_files.erase(itr);
  44. // TODO(flerovium): return correct result code if operation failed.
  45. return RESULT_SUCCESS;
  46. }
  47. } // namespace Nvidia
  48. } // namespace Service