diff options
| author | 2023-10-24 12:53:53 -0400 | |
|---|---|---|
| committer | 2023-10-25 13:05:55 -0400 | |
| commit | 4df063209bebeb8737cbefd47a8958977aff9c2d (patch) | |
| tree | 4b0d8b2c2b777aaeebe2a3d10b3b770bf809b824 /src | |
| parent | nvdrv: add ioctl command serialization, convert nvhost_as_gpu (diff) | |
| download | yuzu-4df063209bebeb8737cbefd47a8958977aff9c2d.tar.gz yuzu-4df063209bebeb8737cbefd47a8958977aff9c2d.tar.xz yuzu-4df063209bebeb8737cbefd47a8958977aff9c2d.zip | |
nvdrv: convert nvhost_ctrl_gpu
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp | 112 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h | 28 |
2 files changed, 43 insertions, 97 deletions
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp index 6081d92e9..92e677b3d 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "core/core.h" | 7 | #include "core/core.h" |
| 8 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/nvdrv/devices/ioctl_serialization.h" | ||
| 9 | #include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h" | 10 | #include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h" |
| 10 | #include "core/hle/service/nvdrv/nvdrv.h" | 11 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 11 | 12 | ||
| @@ -27,23 +28,23 @@ NvResult nvhost_ctrl_gpu::Ioctl1(DeviceFD fd, Ioctl command, std::span<const u8> | |||
| 27 | case 'G': | 28 | case 'G': |
| 28 | switch (command.cmd) { | 29 | switch (command.cmd) { |
| 29 | case 0x1: | 30 | case 0x1: |
| 30 | return ZCullGetCtxSize(input, output); | 31 | return Wrap1(&nvhost_ctrl_gpu::ZCullGetCtxSize, input, output); |
| 31 | case 0x2: | 32 | case 0x2: |
| 32 | return ZCullGetInfo(input, output); | 33 | return Wrap1(&nvhost_ctrl_gpu::ZCullGetInfo, input, output); |
| 33 | case 0x3: | 34 | case 0x3: |
| 34 | return ZBCSetTable(input, output); | 35 | return Wrap1(&nvhost_ctrl_gpu::ZBCSetTable, input, output); |
| 35 | case 0x4: | 36 | case 0x4: |
| 36 | return ZBCQueryTable(input, output); | 37 | return Wrap1(&nvhost_ctrl_gpu::ZBCQueryTable, input, output); |
| 37 | case 0x5: | 38 | case 0x5: |
| 38 | return GetCharacteristics(input, output); | 39 | return Wrap1(&nvhost_ctrl_gpu::GetCharacteristics1, input, output); |
| 39 | case 0x6: | 40 | case 0x6: |
| 40 | return GetTPCMasks(input, output); | 41 | return Wrap1(&nvhost_ctrl_gpu::GetTPCMasks1, input, output); |
| 41 | case 0x7: | 42 | case 0x7: |
| 42 | return FlushL2(input, output); | 43 | return Wrap1(&nvhost_ctrl_gpu::FlushL2, input, output); |
| 43 | case 0x14: | 44 | case 0x14: |
| 44 | return GetActiveSlotMask(input, output); | 45 | return Wrap1(&nvhost_ctrl_gpu::GetActiveSlotMask, input, output); |
| 45 | case 0x1c: | 46 | case 0x1c: |
| 46 | return GetGpuTime(input, output); | 47 | return Wrap1(&nvhost_ctrl_gpu::GetGpuTime, input, output); |
| 47 | default: | 48 | default: |
| 48 | break; | 49 | break; |
| 49 | } | 50 | } |
| @@ -65,9 +66,9 @@ NvResult nvhost_ctrl_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span<const u8> | |||
| 65 | case 'G': | 66 | case 'G': |
| 66 | switch (command.cmd) { | 67 | switch (command.cmd) { |
| 67 | case 0x5: | 68 | case 0x5: |
| 68 | return GetCharacteristics(input, output, inline_output); | 69 | return Wrap3(&nvhost_ctrl_gpu::GetCharacteristics3, input, output, inline_output); |
| 69 | case 0x6: | 70 | case 0x6: |
| 70 | return GetTPCMasks(input, output, inline_output); | 71 | return Wrap3(&nvhost_ctrl_gpu::GetTPCMasks3, input, output, inline_output); |
| 71 | default: | 72 | default: |
| 72 | break; | 73 | break; |
| 73 | } | 74 | } |
| @@ -82,10 +83,8 @@ NvResult nvhost_ctrl_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span<const u8> | |||
| 82 | void nvhost_ctrl_gpu::OnOpen(DeviceFD fd) {} | 83 | void nvhost_ctrl_gpu::OnOpen(DeviceFD fd) {} |
| 83 | void nvhost_ctrl_gpu::OnClose(DeviceFD fd) {} | 84 | void nvhost_ctrl_gpu::OnClose(DeviceFD fd) {} |
| 84 | 85 | ||
| 85 | NvResult nvhost_ctrl_gpu::GetCharacteristics(std::span<const u8> input, std::span<u8> output) { | 86 | NvResult nvhost_ctrl_gpu::GetCharacteristics1(IoctlCharacteristics& params) { |
| 86 | LOG_DEBUG(Service_NVDRV, "called"); | 87 | LOG_DEBUG(Service_NVDRV, "called"); |
| 87 | IoctlCharacteristics params{}; | ||
| 88 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 89 | params.gc.arch = 0x120; | 88 | params.gc.arch = 0x120; |
| 90 | params.gc.impl = 0xb; | 89 | params.gc.impl = 0xb; |
| 91 | params.gc.rev = 0xa1; | 90 | params.gc.rev = 0xa1; |
| @@ -123,15 +122,13 @@ NvResult nvhost_ctrl_gpu::GetCharacteristics(std::span<const u8> input, std::spa | |||
| 123 | params.gc.gr_compbit_store_base_hw = 0x0; | 122 | params.gc.gr_compbit_store_base_hw = 0x0; |
| 124 | params.gpu_characteristics_buf_size = 0xA0; | 123 | params.gpu_characteristics_buf_size = 0xA0; |
| 125 | params.gpu_characteristics_buf_addr = 0xdeadbeef; // Cannot be 0 (UNUSED) | 124 | params.gpu_characteristics_buf_addr = 0xdeadbeef; // Cannot be 0 (UNUSED) |
| 126 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 127 | return NvResult::Success; | 125 | return NvResult::Success; |
| 128 | } | 126 | } |
| 129 | 127 | ||
| 130 | NvResult nvhost_ctrl_gpu::GetCharacteristics(std::span<const u8> input, std::span<u8> output, | 128 | NvResult nvhost_ctrl_gpu::GetCharacteristics3(IoctlCharacteristics& params, |
| 131 | std::span<u8> inline_output) { | 129 | std::span<u8> inline_output) { |
| 132 | LOG_DEBUG(Service_NVDRV, "called"); | 130 | LOG_DEBUG(Service_NVDRV, "called"); |
| 133 | IoctlCharacteristics params{}; | 131 | |
| 134 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 135 | params.gc.arch = 0x120; | 132 | params.gc.arch = 0x120; |
| 136 | params.gc.impl = 0xb; | 133 | params.gc.impl = 0xb; |
| 137 | params.gc.rev = 0xa1; | 134 | params.gc.rev = 0xa1; |
| @@ -169,70 +166,46 @@ NvResult nvhost_ctrl_gpu::GetCharacteristics(std::span<const u8> input, std::spa | |||
| 169 | params.gc.gr_compbit_store_base_hw = 0x0; | 166 | params.gc.gr_compbit_store_base_hw = 0x0; |
| 170 | params.gpu_characteristics_buf_size = 0xA0; | 167 | params.gpu_characteristics_buf_size = 0xA0; |
| 171 | params.gpu_characteristics_buf_addr = 0xdeadbeef; // Cannot be 0 (UNUSED) | 168 | params.gpu_characteristics_buf_addr = 0xdeadbeef; // Cannot be 0 (UNUSED) |
| 172 | 169 | std::memcpy(inline_output.data(), ¶ms.gc, | |
| 173 | std::memcpy(output.data(), ¶ms, output.size()); | 170 | std::min(sizeof(params.gc), inline_output.size())); |
| 174 | std::memcpy(inline_output.data(), ¶ms.gc, inline_output.size()); | ||
| 175 | return NvResult::Success; | 171 | return NvResult::Success; |
| 176 | } | 172 | } |
| 177 | 173 | ||
| 178 | NvResult nvhost_ctrl_gpu::GetTPCMasks(std::span<const u8> input, std::span<u8> output) { | 174 | NvResult nvhost_ctrl_gpu::GetTPCMasks1(IoctlGpuGetTpcMasksArgs& params) { |
| 179 | IoctlGpuGetTpcMasksArgs params{}; | ||
| 180 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 181 | LOG_DEBUG(Service_NVDRV, "called, mask_buffer_size=0x{:X}", params.mask_buffer_size); | 175 | LOG_DEBUG(Service_NVDRV, "called, mask_buffer_size=0x{:X}", params.mask_buffer_size); |
| 182 | if (params.mask_buffer_size != 0) { | 176 | if (params.mask_buffer_size != 0) { |
| 183 | params.tcp_mask = 3; | 177 | params.tcp_mask = 3; |
| 184 | } | 178 | } |
| 185 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 186 | return NvResult::Success; | 179 | return NvResult::Success; |
| 187 | } | 180 | } |
| 188 | 181 | ||
| 189 | NvResult nvhost_ctrl_gpu::GetTPCMasks(std::span<const u8> input, std::span<u8> output, | 182 | NvResult nvhost_ctrl_gpu::GetTPCMasks3(IoctlGpuGetTpcMasksArgs& params, |
| 190 | std::span<u8> inline_output) { | 183 | std::span<u8> inline_output) { |
| 191 | IoctlGpuGetTpcMasksArgs params{}; | ||
| 192 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 193 | LOG_DEBUG(Service_NVDRV, "called, mask_buffer_size=0x{:X}", params.mask_buffer_size); | 184 | LOG_DEBUG(Service_NVDRV, "called, mask_buffer_size=0x{:X}", params.mask_buffer_size); |
| 194 | if (params.mask_buffer_size != 0) { | 185 | if (params.mask_buffer_size != 0) { |
| 195 | params.tcp_mask = 3; | 186 | params.tcp_mask = 3; |
| 196 | } | 187 | } |
| 197 | std::memcpy(output.data(), ¶ms, output.size()); | 188 | std::memcpy(inline_output.data(), ¶ms.tcp_mask, |
| 198 | std::memcpy(inline_output.data(), ¶ms.tcp_mask, inline_output.size()); | 189 | std::min(sizeof(params.tcp_mask), inline_output.size())); |
| 199 | return NvResult::Success; | 190 | return NvResult::Success; |
| 200 | } | 191 | } |
| 201 | 192 | ||
| 202 | NvResult nvhost_ctrl_gpu::GetActiveSlotMask(std::span<const u8> input, std::span<u8> output) { | 193 | NvResult nvhost_ctrl_gpu::GetActiveSlotMask(IoctlActiveSlotMask& params) { |
| 203 | LOG_DEBUG(Service_NVDRV, "called"); | 194 | LOG_DEBUG(Service_NVDRV, "called"); |
| 204 | 195 | ||
| 205 | IoctlActiveSlotMask params{}; | ||
| 206 | if (input.size() > 0) { | ||
| 207 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 208 | } | ||
| 209 | params.slot = 0x07; | 196 | params.slot = 0x07; |
| 210 | params.mask = 0x01; | 197 | params.mask = 0x01; |
| 211 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 212 | return NvResult::Success; | 198 | return NvResult::Success; |
| 213 | } | 199 | } |
| 214 | 200 | ||
| 215 | NvResult nvhost_ctrl_gpu::ZCullGetCtxSize(std::span<const u8> input, std::span<u8> output) { | 201 | NvResult nvhost_ctrl_gpu::ZCullGetCtxSize(IoctlZcullGetCtxSize& params) { |
| 216 | LOG_DEBUG(Service_NVDRV, "called"); | 202 | LOG_DEBUG(Service_NVDRV, "called"); |
| 217 | |||
| 218 | IoctlZcullGetCtxSize params{}; | ||
| 219 | if (input.size() > 0) { | ||
| 220 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 221 | } | ||
| 222 | params.size = 0x1; | 203 | params.size = 0x1; |
| 223 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 224 | return NvResult::Success; | 204 | return NvResult::Success; |
| 225 | } | 205 | } |
| 226 | 206 | ||
| 227 | NvResult nvhost_ctrl_gpu::ZCullGetInfo(std::span<const u8> input, std::span<u8> output) { | 207 | NvResult nvhost_ctrl_gpu::ZCullGetInfo(IoctlNvgpuGpuZcullGetInfoArgs& params) { |
| 228 | LOG_DEBUG(Service_NVDRV, "called"); | 208 | LOG_DEBUG(Service_NVDRV, "called"); |
| 229 | |||
| 230 | IoctlNvgpuGpuZcullGetInfoArgs params{}; | ||
| 231 | |||
| 232 | if (input.size() > 0) { | ||
| 233 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 234 | } | ||
| 235 | |||
| 236 | params.width_align_pixels = 0x20; | 209 | params.width_align_pixels = 0x20; |
| 237 | params.height_align_pixels = 0x20; | 210 | params.height_align_pixels = 0x20; |
| 238 | params.pixel_squares_by_aliquots = 0x400; | 211 | params.pixel_squares_by_aliquots = 0x400; |
| @@ -243,53 +216,28 @@ NvResult nvhost_ctrl_gpu::ZCullGetInfo(std::span<const u8> input, std::span<u8> | |||
| 243 | params.subregion_width_align_pixels = 0x20; | 216 | params.subregion_width_align_pixels = 0x20; |
| 244 | params.subregion_height_align_pixels = 0x40; | 217 | params.subregion_height_align_pixels = 0x40; |
| 245 | params.subregion_count = 0x10; | 218 | params.subregion_count = 0x10; |
| 246 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 247 | return NvResult::Success; | 219 | return NvResult::Success; |
| 248 | } | 220 | } |
| 249 | 221 | ||
| 250 | NvResult nvhost_ctrl_gpu::ZBCSetTable(std::span<const u8> input, std::span<u8> output) { | 222 | NvResult nvhost_ctrl_gpu::ZBCSetTable(IoctlZbcSetTable& params) { |
| 251 | LOG_WARNING(Service_NVDRV, "(STUBBED) called"); | 223 | LOG_WARNING(Service_NVDRV, "(STUBBED) called"); |
| 252 | |||
| 253 | IoctlZbcSetTable params{}; | ||
| 254 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 255 | // TODO(ogniK): What does this even actually do? | 224 | // TODO(ogniK): What does this even actually do? |
| 256 | |||
| 257 | // Prevent null pointer being passed as arg 1 | ||
| 258 | if (output.empty()) { | ||
| 259 | LOG_WARNING(Service_NVDRV, "Avoiding passing null pointer to memcpy"); | ||
| 260 | } else { | ||
| 261 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 262 | } | ||
| 263 | return NvResult::Success; | 225 | return NvResult::Success; |
| 264 | } | 226 | } |
| 265 | 227 | ||
| 266 | NvResult nvhost_ctrl_gpu::ZBCQueryTable(std::span<const u8> input, std::span<u8> output) { | 228 | NvResult nvhost_ctrl_gpu::ZBCQueryTable(IoctlZbcQueryTable& params) { |
| 267 | LOG_WARNING(Service_NVDRV, "(STUBBED) called"); | 229 | LOG_WARNING(Service_NVDRV, "(STUBBED) called"); |
| 268 | |||
| 269 | IoctlZbcQueryTable params{}; | ||
| 270 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 271 | // TODO : To implement properly | ||
| 272 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 273 | return NvResult::Success; | 230 | return NvResult::Success; |
| 274 | } | 231 | } |
| 275 | 232 | ||
| 276 | NvResult nvhost_ctrl_gpu::FlushL2(std::span<const u8> input, std::span<u8> output) { | 233 | NvResult nvhost_ctrl_gpu::FlushL2(IoctlFlushL2& params) { |
| 277 | LOG_WARNING(Service_NVDRV, "(STUBBED) called"); | 234 | LOG_WARNING(Service_NVDRV, "(STUBBED) called"); |
| 278 | |||
| 279 | IoctlFlushL2 params{}; | ||
| 280 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 281 | // TODO : To implement properly | ||
| 282 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 283 | return NvResult::Success; | 235 | return NvResult::Success; |
| 284 | } | 236 | } |
| 285 | 237 | ||
| 286 | NvResult nvhost_ctrl_gpu::GetGpuTime(std::span<const u8> input, std::span<u8> output) { | 238 | NvResult nvhost_ctrl_gpu::GetGpuTime(IoctlGetGpuTime& params) { |
| 287 | LOG_DEBUG(Service_NVDRV, "called"); | 239 | LOG_DEBUG(Service_NVDRV, "called"); |
| 288 | |||
| 289 | IoctlGetGpuTime params{}; | ||
| 290 | std::memcpy(¶ms, input.data(), input.size()); | ||
| 291 | params.gpu_time = static_cast<u64_le>(system.CoreTiming().GetGlobalTimeNs().count()); | 240 | params.gpu_time = static_cast<u64_le>(system.CoreTiming().GetGlobalTimeNs().count()); |
| 292 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 293 | return NvResult::Success; | 241 | return NvResult::Success; |
| 294 | } | 242 | } |
| 295 | 243 | ||
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h index 97995551c..e1977a6b5 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h | |||
| @@ -151,21 +151,19 @@ private: | |||
| 151 | }; | 151 | }; |
| 152 | static_assert(sizeof(IoctlGetGpuTime) == 0x10, "IoctlGetGpuTime is incorrect size"); | 152 | static_assert(sizeof(IoctlGetGpuTime) == 0x10, "IoctlGetGpuTime is incorrect size"); |
| 153 | 153 | ||
| 154 | NvResult GetCharacteristics(std::span<const u8> input, std::span<u8> output); | 154 | NvResult GetCharacteristics1(IoctlCharacteristics& params); |
| 155 | NvResult GetCharacteristics(std::span<const u8> input, std::span<u8> output, | 155 | NvResult GetCharacteristics3(IoctlCharacteristics& params, std::span<u8> inline_output); |
| 156 | std::span<u8> inline_output); | 156 | |
| 157 | 157 | NvResult GetTPCMasks1(IoctlGpuGetTpcMasksArgs& params); | |
| 158 | NvResult GetTPCMasks(std::span<const u8> input, std::span<u8> output); | 158 | NvResult GetTPCMasks3(IoctlGpuGetTpcMasksArgs& params, std::span<u8> inline_output); |
| 159 | NvResult GetTPCMasks(std::span<const u8> input, std::span<u8> output, | 159 | |
| 160 | std::span<u8> inline_output); | 160 | NvResult GetActiveSlotMask(IoctlActiveSlotMask& params); |
| 161 | 161 | NvResult ZCullGetCtxSize(IoctlZcullGetCtxSize& params); | |
| 162 | NvResult GetActiveSlotMask(std::span<const u8> input, std::span<u8> output); | 162 | NvResult ZCullGetInfo(IoctlNvgpuGpuZcullGetInfoArgs& params); |
| 163 | NvResult ZCullGetCtxSize(std::span<const u8> input, std::span<u8> output); | 163 | NvResult ZBCSetTable(IoctlZbcSetTable& params); |
| 164 | NvResult ZCullGetInfo(std::span<const u8> input, std::span<u8> output); | 164 | NvResult ZBCQueryTable(IoctlZbcQueryTable& params); |
| 165 | NvResult ZBCSetTable(std::span<const u8> input, std::span<u8> output); | 165 | NvResult FlushL2(IoctlFlushL2& params); |
| 166 | NvResult ZBCQueryTable(std::span<const u8> input, std::span<u8> output); | 166 | NvResult GetGpuTime(IoctlGetGpuTime& params); |
| 167 | NvResult FlushL2(std::span<const u8> input, std::span<u8> output); | ||
| 168 | NvResult GetGpuTime(std::span<const u8> input, std::span<u8> output); | ||
| 169 | 167 | ||
| 170 | EventInterface& events_interface; | 168 | EventInterface& events_interface; |
| 171 | 169 | ||