diff options
| author | 2018-01-15 17:39:00 -0500 | |
|---|---|---|
| committer | 2018-01-16 19:03:49 -0500 | |
| commit | 30657f9ca1485dcf9611d3c4ea3c74d52b350dec (patch) | |
| tree | 66254dcdc6002297706d9c7169a46eaff806c611 /src | |
| parent | VI: Stubbed GetNativeHandle, Create/DestroyStrayLayer and CloseDisplay (diff) | |
| download | yuzu-30657f9ca1485dcf9611d3c4ea3c74d52b350dec.tar.gz yuzu-30657f9ca1485dcf9611d3c4ea3c74d52b350dec.tar.xz yuzu-30657f9ca1485dcf9611d3c4ea3c74d52b350dec.zip | |
NV: Move the nvdrv classes into the Nvidia namespace, and move the functionality to a s single module that services call.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvdevice.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvdisp_disp0.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvmap.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvmap.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/nvdrv.cpp | 43 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/nvdrv.h | 124 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/nvdrv_a.cpp | 27 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/nvdrv_a.h | 30 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/service/vi/vi.cpp | 6 |
13 files changed, 95 insertions, 165 deletions
diff --git a/src/core/hle/service/nvdrv/devices/nvdevice.h b/src/core/hle/service/nvdrv/devices/nvdevice.h index 1ee2787c6..5ee33b3d6 100644 --- a/src/core/hle/service/nvdrv/devices/nvdevice.h +++ b/src/core/hle/service/nvdrv/devices/nvdevice.h | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | 9 | ||
| 10 | namespace Service { | 10 | namespace Service { |
| 11 | namespace NVDRV { | 11 | namespace Nvidia { |
| 12 | namespace Devices { | 12 | namespace Devices { |
| 13 | 13 | ||
| 14 | /// Represents an abstract nvidia device node. It is to be subclassed by concrete device nodes to | 14 | /// Represents an abstract nvidia device node. It is to be subclassed by concrete device nodes to |
| @@ -29,5 +29,5 @@ public: | |||
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | } // namespace Devices | 31 | } // namespace Devices |
| 32 | } // namespace NVDRV | 32 | } // namespace Nvidia |
| 33 | } // namespace Service | 33 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp index 992f70b45..c42a65b36 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | #include "video_core/video_core.h" | 10 | #include "video_core/video_core.h" |
| 11 | 11 | ||
| 12 | namespace Service { | 12 | namespace Service { |
| 13 | namespace NVDRV { | 13 | namespace Nvidia { |
| 14 | namespace Devices { | 14 | namespace Devices { |
| 15 | 15 | ||
| 16 | u32 nvdisp_disp0::ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) { | 16 | u32 nvdisp_disp0::ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) { |
| @@ -32,5 +32,5 @@ void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u3 | |||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | } // namespace Devices | 34 | } // namespace Devices |
| 35 | } // namespace NVDRV | 35 | } // namespace Nvidia |
| 36 | } // namespace Service | 36 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h index 601068af1..f5f9de3f4 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | #include "core/hle/service/nvdrv/devices/nvdevice.h" | 10 | #include "core/hle/service/nvdrv/devices/nvdevice.h" |
| 11 | 11 | ||
| 12 | namespace Service { | 12 | namespace Service { |
| 13 | namespace NVDRV { | 13 | namespace Nvidia { |
| 14 | namespace Devices { | 14 | namespace Devices { |
| 15 | 15 | ||
| 16 | class nvmap; | 16 | class nvmap; |
| @@ -30,5 +30,5 @@ private: | |||
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | } // namespace Devices | 32 | } // namespace Devices |
| 33 | } // namespace NVDRV | 33 | } // namespace Nvidia |
| 34 | } // namespace Service | 34 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index c7bf79050..9db08339a 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" | 7 | #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" |
| 8 | 8 | ||
| 9 | namespace Service { | 9 | namespace Service { |
| 10 | namespace NVDRV { | 10 | namespace Nvidia { |
| 11 | namespace Devices { | 11 | namespace Devices { |
| 12 | 12 | ||
| 13 | u32 nvhost_as_gpu::ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) { | 13 | u32 nvhost_as_gpu::ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) { |
| @@ -16,5 +16,5 @@ u32 nvhost_as_gpu::ioctl(u32 command, const std::vector<u8>& input, std::vector< | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | } // namespace Devices | 18 | } // namespace Devices |
| 19 | } // namespace NVDRV | 19 | } // namespace Nvidia |
| 20 | } // namespace Service | 20 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index 6f441b020..01f8861c8 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include "core/hle/service/nvdrv/devices/nvdevice.h" | 9 | #include "core/hle/service/nvdrv/devices/nvdevice.h" |
| 10 | 10 | ||
| 11 | namespace Service { | 11 | namespace Service { |
| 12 | namespace NVDRV { | 12 | namespace Nvidia { |
| 13 | namespace Devices { | 13 | namespace Devices { |
| 14 | 14 | ||
| 15 | class nvhost_as_gpu final : public nvdevice { | 15 | class nvhost_as_gpu final : public nvdevice { |
| @@ -21,5 +21,5 @@ public: | |||
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | } // namespace Devices | 23 | } // namespace Devices |
| 24 | } // namespace NVDRV | 24 | } // namespace Nvidia |
| 25 | } // namespace Service | 25 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index 2d6f30e3e..d37b5b159 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include "core/hle/service/nvdrv/devices/nvmap.h" | 9 | #include "core/hle/service/nvdrv/devices/nvmap.h" |
| 10 | 10 | ||
| 11 | namespace Service { | 11 | namespace Service { |
| 12 | namespace NVDRV { | 12 | namespace Nvidia { |
| 13 | namespace Devices { | 13 | namespace Devices { |
| 14 | 14 | ||
| 15 | VAddr nvmap::GetObjectAddress(u32 handle) const { | 15 | VAddr nvmap::GetObjectAddress(u32 handle) const { |
| @@ -151,5 +151,5 @@ u32 nvmap::IocParam(const std::vector<u8>& input, std::vector<u8>& output) { | |||
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | } // namespace Devices | 153 | } // namespace Devices |
| 154 | } // namespace NVDRV | 154 | } // namespace Nvidia |
| 155 | } // namespace Service | 155 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index e74f356e5..6954c0324 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | #include "core/hle/service/nvdrv/devices/nvdevice.h" | 13 | #include "core/hle/service/nvdrv/devices/nvdevice.h" |
| 14 | 14 | ||
| 15 | namespace Service { | 15 | namespace Service { |
| 16 | namespace NVDRV { | 16 | namespace Nvidia { |
| 17 | namespace Devices { | 17 | namespace Devices { |
| 18 | 18 | ||
| 19 | class nvmap final : public nvdevice { | 19 | class nvmap final : public nvdevice { |
| @@ -104,5 +104,5 @@ private: | |||
| 104 | }; | 104 | }; |
| 105 | 105 | ||
| 106 | } // namespace Devices | 106 | } // namespace Devices |
| 107 | } // namespace NVDRV | 107 | } // namespace Nvidia |
| 108 | } // namespace Service | 108 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index c874e6395..be9946505 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp | |||
| @@ -2,19 +2,50 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 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" | ||
| 5 | #include "core/hle/service/nvdrv/nvdrv.h" | 9 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 6 | #include "core/hle/service/nvdrv/nvdrv_a.h" | 10 | #include "core/hle/service/nvdrv/nvdrv_a.h" |
| 7 | 11 | ||
| 8 | namespace Service { | 12 | namespace Service { |
| 9 | namespace NVDRV { | 13 | namespace Nvidia { |
| 10 | 14 | ||
| 11 | std::weak_ptr<NVDRV_A> nvdrv_a; | 15 | std::weak_ptr<Module> nvdrv; |
| 12 | 16 | ||
| 13 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 17 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
| 14 | auto nvdrv = std::make_shared<NVDRV_A>(); | 18 | auto module_ = std::make_shared<Module>(); |
| 15 | nvdrv->InstallAsService(service_manager); | 19 | std::make_shared<NVDRV_A>(module_)->InstallAsService(service_manager); |
| 16 | nvdrv_a = nvdrv; | 20 | nvdrv = module_; |
| 17 | } | 21 | } |
| 18 | 22 | ||
| 19 | } // namespace NVDRV | 23 | Module::Module() { |
| 24 | auto nvmap_dev = std::make_shared<Devices::nvmap>(); | ||
| 25 | devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>(); | ||
| 26 | devices["/dev/nvmap"] = nvmap_dev; | ||
| 27 | devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev); | ||
| 28 | } | ||
| 29 | |||
| 30 | u32 Module::Open(std::string device_name) { | ||
| 31 | ASSERT_MSG(devices.find(device_name) != devices.end(), "Trying to open unknown device %s", | ||
| 32 | device_name.c_str()); | ||
| 33 | |||
| 34 | auto device = devices[device_name]; | ||
| 35 | u32 fd = next_fd++; | ||
| 36 | |||
| 37 | open_files[fd] = device; | ||
| 38 | |||
| 39 | return fd; | ||
| 40 | } | ||
| 41 | |||
| 42 | u32 Module::Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output) { | ||
| 43 | auto itr = open_files.find(fd); | ||
| 44 | ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device"); | ||
| 45 | |||
| 46 | auto device = itr->second; | ||
| 47 | return device->ioctl(command, input, output); | ||
| 48 | } | ||
| 49 | |||
| 50 | } // namespace Nvidia | ||
| 20 | } // namespace Service | 51 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h index a1c050416..1940ced99 100644 --- a/src/core/hle/service/nvdrv/nvdrv.h +++ b/src/core/hle/service/nvdrv/nvdrv.h | |||
| @@ -11,110 +11,46 @@ | |||
| 11 | #include "core/hle/service/service.h" | 11 | #include "core/hle/service/service.h" |
| 12 | 12 | ||
| 13 | namespace Service { | 13 | namespace Service { |
| 14 | namespace NVDRV { | 14 | namespace Nvidia { |
| 15 | 15 | ||
| 16 | class nvdevice { | 16 | namespace Devices { |
| 17 | public: | 17 | class nvdevice; |
| 18 | virtual ~nvdevice() = default; | 18 | } |
| 19 | |||
| 20 | virtual u32 ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) = 0; | ||
| 21 | }; | ||
| 22 | 19 | ||
| 23 | class nvmap : public nvdevice { | 20 | class Module final { |
| 24 | public: | 21 | public: |
| 25 | /// Returns the allocated address of an nvmap object given its handle. | 22 | Module(); |
| 26 | VAddr GetObjectAddress(u32 handle) const; | 23 | ~Module() = default; |
| 27 | 24 | ||
| 28 | u32 ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) override; | 25 | /// Returns a pointer to one of the available devices, identified by its name. |
| 26 | template <typename T> | ||
| 27 | std::shared_ptr<T> GetDevice(std::string name) { | ||
| 28 | auto itr = devices.find(name); | ||
| 29 | if (itr == devices.end()) | ||
| 30 | return nullptr; | ||
| 31 | return std::static_pointer_cast<T>(itr->second); | ||
| 32 | } | ||
| 33 | |||
| 34 | /// Opens a device node and returns a file descriptor to it. | ||
| 35 | u32 Open(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); | ||
| 29 | 38 | ||
| 30 | private: | 39 | private: |
| 31 | // Represents an nvmap object. | 40 | /// Id to use for the next open file descriptor. |
| 32 | struct Object { | 41 | u32 next_fd = 1; |
| 33 | enum class Status { Created, Allocated }; | ||
| 34 | u32 id; | ||
| 35 | u32 size; | ||
| 36 | u32 flags; | ||
| 37 | u32 align; | ||
| 38 | u8 kind; | ||
| 39 | VAddr addr; | ||
| 40 | Status status; | ||
| 41 | }; | ||
| 42 | |||
| 43 | u32 next_handle = 1; | ||
| 44 | u32 next_id = 1; | ||
| 45 | std::unordered_map<u32, std::shared_ptr<Object>> handles; | ||
| 46 | |||
| 47 | enum IoctlCommands { | ||
| 48 | IocCreateCommand = 0xC0080101, | ||
| 49 | IocFromIdCommand = 0xC0080103, | ||
| 50 | IocAllocCommand = 0xC0200104, | ||
| 51 | IocParamCommand = 0xC00C0109, | ||
| 52 | IocGetIdCommand = 0xC008010E | ||
| 53 | }; | ||
| 54 | |||
| 55 | struct IocCreateParams { | ||
| 56 | // Input | ||
| 57 | u32_le size; | ||
| 58 | // Output | ||
| 59 | u32_le handle; | ||
| 60 | }; | ||
| 61 | |||
| 62 | struct IocAllocParams { | ||
| 63 | // Input | ||
| 64 | u32_le handle; | ||
| 65 | u32_le heap_mask; | ||
| 66 | u32_le flags; | ||
| 67 | u32_le align; | ||
| 68 | u8 kind; | ||
| 69 | INSERT_PADDING_BYTES(7); | ||
| 70 | u64_le addr; | ||
| 71 | }; | ||
| 72 | |||
| 73 | struct IocGetIdParams { | ||
| 74 | // Output | ||
| 75 | u32_le id; | ||
| 76 | // Input | ||
| 77 | u32_le handle; | ||
| 78 | }; | ||
| 79 | 42 | ||
| 80 | struct IocFromIdParams { | 43 | /// Mapping of file descriptors to the devices they reference. |
| 81 | // Input | 44 | std::unordered_map<u32, std::shared_ptr<Devices::nvdevice>> open_files; |
| 82 | u32_le id; | ||
| 83 | // Output | ||
| 84 | u32_le handle; | ||
| 85 | }; | ||
| 86 | 45 | ||
| 87 | struct IocParamParams { | 46 | /// Mapping of device node names to their implementation. |
| 88 | // Input | 47 | std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices; |
| 89 | u32_le handle; | ||
| 90 | u32_le type; | ||
| 91 | // Output | ||
| 92 | u32_le value; | ||
| 93 | }; | ||
| 94 | |||
| 95 | u32 IocCreate(const std::vector<u8>& input, std::vector<u8>& output); | ||
| 96 | u32 IocAlloc(const std::vector<u8>& input, std::vector<u8>& output); | ||
| 97 | u32 IocGetId(const std::vector<u8>& input, std::vector<u8>& output); | ||
| 98 | u32 IocFromId(const std::vector<u8>& input, std::vector<u8>& output); | ||
| 99 | u32 IocParam(const std::vector<u8>& input, std::vector<u8>& output); | ||
| 100 | }; | ||
| 101 | |||
| 102 | class nvdisp_disp0 : public nvdevice { | ||
| 103 | public: | ||
| 104 | nvdisp_disp0(std::shared_ptr<nvmap> nvmap_dev) : nvdevice(), nvmap_dev(std::move(nvmap_dev)) {} | ||
| 105 | ~nvdisp_disp0() = default; | ||
| 106 | |||
| 107 | u32 ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) override; | ||
| 108 | |||
| 109 | /// Performs a screen flip, drawing the buffer pointed to by the handle. | ||
| 110 | void flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u32 height, u32 stride); | ||
| 111 | |||
| 112 | private: | ||
| 113 | std::shared_ptr<nvmap> nvmap_dev; | ||
| 114 | }; | 48 | }; |
| 115 | 49 | ||
| 116 | /// Registers all NVDRV services with the specified service manager. | 50 | /// Registers all NVDRV services with the specified service manager. |
| 117 | void InstallInterfaces(SM::ServiceManager& service_manager); | 51 | void InstallInterfaces(SM::ServiceManager& service_manager); |
| 118 | 52 | ||
| 119 | } // namespace NVDRV | 53 | extern std::weak_ptr<Module> nvdrv; |
| 54 | |||
| 55 | } // namespace Nvidia | ||
| 120 | } // namespace Service | 56 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/nvdrv_a.cpp b/src/core/hle/service/nvdrv/nvdrv_a.cpp index 84d89cb49..5d3e68792 100644 --- a/src/core/hle/service/nvdrv/nvdrv_a.cpp +++ b/src/core/hle/service/nvdrv/nvdrv_a.cpp | |||
| @@ -4,15 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 6 | #include "core/hle/ipc_helpers.h" | 6 | #include "core/hle/ipc_helpers.h" |
| 7 | #include "core/hle/service/nvdrv/devices/nvdevice.h" | ||
| 8 | #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" | ||
| 9 | #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" | ||
| 10 | #include "core/hle/service/nvdrv/devices/nvmap.h" | ||
| 11 | #include "core/hle/service/nvdrv/nvdrv.h" | 7 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 12 | #include "core/hle/service/nvdrv/nvdrv_a.h" | 8 | #include "core/hle/service/nvdrv/nvdrv_a.h" |
| 13 | 9 | ||
| 14 | namespace Service { | 10 | namespace Service { |
| 15 | namespace NVDRV { | 11 | namespace Nvidia { |
| 16 | 12 | ||
| 17 | void NVDRV_A::Open(Kernel::HLERequestContext& ctx) { | 13 | void NVDRV_A::Open(Kernel::HLERequestContext& ctx) { |
| 18 | LOG_WARNING(Service, "(STUBBED) called"); | 14 | LOG_WARNING(Service, "(STUBBED) called"); |
| @@ -21,11 +17,7 @@ void NVDRV_A::Open(Kernel::HLERequestContext& ctx) { | |||
| 21 | 17 | ||
| 22 | std::string device_name = Memory::ReadCString(buffer.Address(), buffer.Size()); | 18 | std::string device_name = Memory::ReadCString(buffer.Address(), buffer.Size()); |
| 23 | 19 | ||
| 24 | auto device = devices[device_name]; | 20 | u32 fd = nvdrv->Open(device_name); |
| 25 | u32 fd = next_fd++; | ||
| 26 | |||
| 27 | open_files[fd] = device; | ||
| 28 | |||
| 29 | IPC::RequestBuilder rb{ctx, 4}; | 21 | IPC::RequestBuilder rb{ctx, 4}; |
| 30 | rb.Push(RESULT_SUCCESS); | 22 | rb.Push(RESULT_SUCCESS); |
| 31 | rb.Push<u32>(fd); | 23 | rb.Push<u32>(fd); |
| @@ -46,11 +38,8 @@ void NVDRV_A::Ioctl(Kernel::HLERequestContext& ctx) { | |||
| 46 | std::vector<u8> output(output_buffer.Size()); | 38 | std::vector<u8> output(output_buffer.Size()); |
| 47 | 39 | ||
| 48 | Memory::ReadBlock(input_buffer.Address(), input.data(), input_buffer.Size()); | 40 | Memory::ReadBlock(input_buffer.Address(), input.data(), input_buffer.Size()); |
| 49 | auto itr = open_files.find(fd); | ||
| 50 | ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device"); | ||
| 51 | 41 | ||
| 52 | auto device = itr->second; | 42 | u32 nv_result = nvdrv->Ioctl(fd, command, input, output); |
| 53 | u32 nv_result = device->ioctl(command, input, output); | ||
| 54 | 43 | ||
| 55 | Memory::WriteBlock(output_buffer.Address(), output.data(), output_buffer.Size()); | 44 | Memory::WriteBlock(output_buffer.Address(), output.data(), output_buffer.Size()); |
| 56 | 45 | ||
| @@ -66,19 +55,15 @@ void NVDRV_A::Initialize(Kernel::HLERequestContext& ctx) { | |||
| 66 | rb.Push<u32>(0); | 55 | rb.Push<u32>(0); |
| 67 | } | 56 | } |
| 68 | 57 | ||
| 69 | NVDRV_A::NVDRV_A() : ServiceFramework("nvdrv:a") { | 58 | NVDRV_A::NVDRV_A(std::shared_ptr<Module> nvdrv) |
| 59 | : ServiceFramework("nvdrv:a"), nvdrv(std::move(nvdrv)) { | ||
| 70 | static const FunctionInfo functions[] = { | 60 | static const FunctionInfo functions[] = { |
| 71 | {0, &NVDRV_A::Open, "Open"}, | 61 | {0, &NVDRV_A::Open, "Open"}, |
| 72 | {1, &NVDRV_A::Ioctl, "Ioctl"}, | 62 | {1, &NVDRV_A::Ioctl, "Ioctl"}, |
| 73 | {3, &NVDRV_A::Initialize, "Initialize"}, | 63 | {3, &NVDRV_A::Initialize, "Initialize"}, |
| 74 | }; | 64 | }; |
| 75 | RegisterHandlers(functions); | 65 | RegisterHandlers(functions); |
| 76 | |||
| 77 | auto nvmap_dev = std::make_shared<Devices::nvmap>(); | ||
| 78 | devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>(); | ||
| 79 | devices["/dev/nvmap"] = nvmap_dev; | ||
| 80 | devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev); | ||
| 81 | } | 66 | } |
| 82 | 67 | ||
| 83 | } // namespace NVDRV | 68 | } // namespace Nvidia |
| 84 | } // namespace Service | 69 | } // namespace Service |
diff --git a/src/core/hle/service/nvdrv/nvdrv_a.h b/src/core/hle/service/nvdrv/nvdrv_a.h index 62f10e9f6..743870555 100644 --- a/src/core/hle/service/nvdrv/nvdrv_a.h +++ b/src/core/hle/service/nvdrv/nvdrv_a.h | |||
| @@ -10,42 +10,20 @@ | |||
| 10 | #include "core/hle/service/service.h" | 10 | #include "core/hle/service/service.h" |
| 11 | 11 | ||
| 12 | namespace Service { | 12 | namespace Service { |
| 13 | namespace NVDRV { | 13 | namespace Nvidia { |
| 14 | |||
| 15 | namespace Devices { | ||
| 16 | class nvdevice; | ||
| 17 | } | ||
| 18 | 14 | ||
| 19 | class NVDRV_A final : public ServiceFramework<NVDRV_A> { | 15 | class NVDRV_A final : public ServiceFramework<NVDRV_A> { |
| 20 | public: | 16 | public: |
| 21 | NVDRV_A(); | 17 | NVDRV_A(std::shared_ptr<Module> nvdrv); |
| 22 | ~NVDRV_A() = default; | 18 | ~NVDRV_A() = default; |
| 23 | 19 | ||
| 24 | /// Returns a pointer to one of the available devices, identified by its name. | ||
| 25 | template <typename T> | ||
| 26 | std::shared_ptr<T> GetDevice(std::string name) { | ||
| 27 | auto itr = devices.find(name); | ||
| 28 | if (itr == devices.end()) | ||
| 29 | return nullptr; | ||
| 30 | return std::static_pointer_cast<T>(itr->second); | ||
| 31 | } | ||
| 32 | |||
| 33 | private: | 20 | private: |
| 34 | void Open(Kernel::HLERequestContext& ctx); | 21 | void Open(Kernel::HLERequestContext& ctx); |
| 35 | void Ioctl(Kernel::HLERequestContext& ctx); | 22 | void Ioctl(Kernel::HLERequestContext& ctx); |
| 36 | void Initialize(Kernel::HLERequestContext& ctx); | 23 | void Initialize(Kernel::HLERequestContext& ctx); |
| 37 | 24 | ||
| 38 | /// Id to use for the next open file descriptor. | 25 | std::shared_ptr<Module> nvdrv; |
| 39 | u32 next_fd = 1; | ||
| 40 | |||
| 41 | /// Mapping of file descriptors to the devices they reference. | ||
| 42 | std::unordered_map<u32, std::shared_ptr<Devices::nvdevice>> open_files; | ||
| 43 | |||
| 44 | /// Mapping of device node names to their implementation. | ||
| 45 | std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices; | ||
| 46 | }; | 26 | }; |
| 47 | 27 | ||
| 48 | extern std::weak_ptr<NVDRV_A> nvdrv_a; | 28 | } // namespace Nvidia |
| 49 | |||
| 50 | } // namespace NVDRV | ||
| 51 | } // namespace Service | 29 | } // namespace Service |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 02d434660..44623d40f 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -170,7 +170,7 @@ void Init() { | |||
| 170 | Audio::InstallInterfaces(*SM::g_service_manager); | 170 | Audio::InstallInterfaces(*SM::g_service_manager); |
| 171 | HID::InstallInterfaces(*SM::g_service_manager); | 171 | HID::InstallInterfaces(*SM::g_service_manager); |
| 172 | LM::InstallInterfaces(*SM::g_service_manager); | 172 | LM::InstallInterfaces(*SM::g_service_manager); |
| 173 | NVDRV::InstallInterfaces(*SM::g_service_manager); | 173 | Nvidia::InstallInterfaces(*SM::g_service_manager); |
| 174 | PCTL::InstallInterfaces(*SM::g_service_manager); | 174 | PCTL::InstallInterfaces(*SM::g_service_manager); |
| 175 | Time::InstallInterfaces(*SM::g_service_manager); | 175 | Time::InstallInterfaces(*SM::g_service_manager); |
| 176 | VI::InstallInterfaces(*SM::g_service_manager); | 176 | VI::InstallInterfaces(*SM::g_service_manager); |
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 6e1bf481b..cae2c4466 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include "core/core_timing.h" | 9 | #include "core/core_timing.h" |
| 10 | #include "core/hle/ipc_helpers.h" | 10 | #include "core/hle/ipc_helpers.h" |
| 11 | #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" | 11 | #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" |
| 12 | #include "core/hle/service/nvdrv/nvdrv_a.h" | 12 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 13 | #include "core/hle/service/vi/vi.h" | 13 | #include "core/hle/service/vi/vi.h" |
| 14 | #include "core/hle/service/vi/vi_m.h" | 14 | #include "core/hle/service/vi/vi_m.h" |
| 15 | #include "video_core/renderer_base.h" | 15 | #include "video_core/renderer_base.h" |
| @@ -834,12 +834,12 @@ void NVFlinger::Compose() { | |||
| 834 | auto& igbp_buffer = buffer->igbp_buffer; | 834 | auto& igbp_buffer = buffer->igbp_buffer; |
| 835 | 835 | ||
| 836 | // Now send the buffer to the GPU for drawing. | 836 | // Now send the buffer to the GPU for drawing. |
| 837 | auto nvdrv = NVDRV::nvdrv_a.lock(); | 837 | auto nvdrv = Nvidia::nvdrv.lock(); |
| 838 | ASSERT(nvdrv); | 838 | ASSERT(nvdrv); |
| 839 | 839 | ||
| 840 | // TODO(Subv): Support more than just disp0. The display device selection is probably based | 840 | // TODO(Subv): Support more than just disp0. The display device selection is probably based |
| 841 | // on which display we're drawing (Default, Internal, External, etc) | 841 | // on which display we're drawing (Default, Internal, External, etc) |
| 842 | auto nvdisp = nvdrv->GetDevice<NVDRV::Devices::nvdisp_disp0>("/dev/nvdisp_disp0"); | 842 | auto nvdisp = nvdrv->GetDevice<Nvidia::Devices::nvdisp_disp0>("/dev/nvdisp_disp0"); |
| 843 | ASSERT(nvdisp); | 843 | ASSERT(nvdisp); |
| 844 | 844 | ||
| 845 | nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.format, | 845 | nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.format, |