nvdrv.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <unordered_map>
  7. #include <vector>
  8. #include "common/common_types.h"
  9. #include "core/hle/service/service.h"
  10. namespace Service::NVFlinger {
  11. class NVFlinger;
  12. }
  13. namespace Service::Nvidia {
  14. namespace Devices {
  15. class nvdevice;
  16. }
  17. struct IoctlFence {
  18. u32 id;
  19. u32 value;
  20. };
  21. static_assert(sizeof(IoctlFence) == 8, "IoctlFence has wrong size");
  22. class Module final {
  23. public:
  24. Module();
  25. ~Module();
  26. /// Returns a pointer to one of the available devices, identified by its name.
  27. template <typename T>
  28. std::shared_ptr<T> GetDevice(const std::string& name) {
  29. auto itr = devices.find(name);
  30. if (itr == devices.end())
  31. return nullptr;
  32. return std::static_pointer_cast<T>(itr->second);
  33. }
  34. /// Opens a device node and returns a file descriptor to it.
  35. u32 Open(const std::string& device_name);
  36. /// Sends an ioctl command to the specified file descriptor.
  37. u32 Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output);
  38. /// Closes a device file descriptor and returns operation success.
  39. ResultCode Close(u32 fd);
  40. private:
  41. /// Id to use for the next open file descriptor.
  42. u32 next_fd = 1;
  43. /// Mapping of file descriptors to the devices they reference.
  44. std::unordered_map<u32, std::shared_ptr<Devices::nvdevice>> open_files;
  45. /// Mapping of device node names to their implementation.
  46. std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices;
  47. };
  48. /// Registers all NVDRV services with the specified service manager.
  49. void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger);
  50. } // namespace Service::Nvidia