2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

nvdrv: fix up remaining copy calls

This commit is contained in:
Liam 2023-10-24 13:41:48 -04:00
parent 18450ebd78
commit 94b7ac50bb
3 changed files with 22 additions and 17 deletions

View file

@ -65,7 +65,7 @@ NvResult nvhost_gpu::Ioctl1(DeviceFD fd, Ioctl command, std::span<const u8> inpu
case 0x3: case 0x3:
return Wrap1(&nvhost_gpu::ChannelSetTimeout, input, output); return Wrap1(&nvhost_gpu::ChannelSetTimeout, input, output);
case 0x8: case 0x8:
return SubmitGPFIFOBase1(input, output, false); return SubmitGPFIFOBase1(input, false);
case 0x9: case 0x9:
return Wrap1(&nvhost_gpu::AllocateObjectContext, input, output); return Wrap1(&nvhost_gpu::AllocateObjectContext, input, output);
case 0xb: case 0xb:
@ -77,7 +77,7 @@ NvResult nvhost_gpu::Ioctl1(DeviceFD fd, Ioctl command, std::span<const u8> inpu
case 0x1a: case 0x1a:
return Wrap1(&nvhost_gpu::AllocGPFIFOEx2, input, output); return Wrap1(&nvhost_gpu::AllocGPFIFOEx2, input, output);
case 0x1b: case 0x1b:
return SubmitGPFIFOBase1(input, output, true); return SubmitGPFIFOBase1(input, true);
case 0x1d: case 0x1d:
return Wrap1(&nvhost_gpu::ChannelSetTimeslice, input, output); return Wrap1(&nvhost_gpu::ChannelSetTimeslice, input, output);
default: default:
@ -105,7 +105,7 @@ NvResult nvhost_gpu::Ioctl2(DeviceFD fd, Ioctl command, std::span<const u8> inpu
case 'H': case 'H':
switch (command.cmd) { switch (command.cmd) {
case 0x1b: case 0x1b:
return SubmitGPFIFOBase2(input, inline_input, output); return SubmitGPFIFOBase2(input, inline_input);
} }
break; break;
} }
@ -227,8 +227,7 @@ static boost::container::small_vector<Tegra::CommandHeader, 512> BuildIncrementW
return result; return result;
} }
NvResult nvhost_gpu::SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, std::span<u8> output, NvResult nvhost_gpu::SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, Tegra::CommandList&& entries) {
Tegra::CommandList&& entries) {
LOG_TRACE(Service_NVDRV, "called, gpfifo={:X}, num_entries={:X}, flags={:X}", params.address, LOG_TRACE(Service_NVDRV, "called, gpfifo={:X}, num_entries={:X}, flags={:X}", params.address,
params.num_entries, params.flags.raw); params.num_entries, params.flags.raw);
@ -272,8 +271,7 @@ NvResult nvhost_gpu::SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, std::span<u8> o
return NvResult::Success; return NvResult::Success;
} }
NvResult nvhost_gpu::SubmitGPFIFOBase1(std::span<const u8> input, std::span<u8> output, NvResult nvhost_gpu::SubmitGPFIFOBase1(std::span<const u8> input, bool kickoff) {
bool kickoff) {
if (input.size() < sizeof(IoctlSubmitGpfifo)) { if (input.size() < sizeof(IoctlSubmitGpfifo)) {
UNIMPLEMENTED(); UNIMPLEMENTED();
return NvResult::InvalidSize; return NvResult::InvalidSize;
@ -290,11 +288,11 @@ NvResult nvhost_gpu::SubmitGPFIFOBase1(std::span<const u8> input, std::span<u8>
params.num_entries * sizeof(Tegra::CommandListHeader)); params.num_entries * sizeof(Tegra::CommandListHeader));
} }
return SubmitGPFIFOImpl(params, output, std::move(entries)); return SubmitGPFIFOImpl(params, std::move(entries));
} }
NvResult nvhost_gpu::SubmitGPFIFOBase2(std::span<const u8> input, std::span<const u8> input_inline, NvResult nvhost_gpu::SubmitGPFIFOBase2(std::span<const u8> input,
std::span<u8> output) { std::span<const u8> input_inline) {
if (input.size() < sizeof(IoctlSubmitGpfifo)) { if (input.size() < sizeof(IoctlSubmitGpfifo)) {
UNIMPLEMENTED(); UNIMPLEMENTED();
return NvResult::InvalidSize; return NvResult::InvalidSize;
@ -303,7 +301,7 @@ NvResult nvhost_gpu::SubmitGPFIFOBase2(std::span<const u8> input, std::span<cons
std::memcpy(&params, input.data(), sizeof(IoctlSubmitGpfifo)); std::memcpy(&params, input.data(), sizeof(IoctlSubmitGpfifo));
Tegra::CommandList entries(params.num_entries); Tegra::CommandList entries(params.num_entries);
std::memcpy(entries.command_lists.data(), input_inline.data(), input_inline.size()); std::memcpy(entries.command_lists.data(), input_inline.data(), input_inline.size());
return SubmitGPFIFOImpl(params, output, std::move(entries)); return SubmitGPFIFOImpl(params, std::move(entries));
} }
NvResult nvhost_gpu::GetWaitbase(IoctlGetWaitbase& params) { NvResult nvhost_gpu::GetWaitbase(IoctlGetWaitbase& params) {

View file

@ -195,12 +195,9 @@ private:
NvResult AllocGPFIFOEx2(IoctlAllocGpfifoEx2& params); NvResult AllocGPFIFOEx2(IoctlAllocGpfifoEx2& params);
NvResult AllocateObjectContext(IoctlAllocObjCtx& params); NvResult AllocateObjectContext(IoctlAllocObjCtx& params);
NvResult SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, std::span<u8> output, NvResult SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, Tegra::CommandList&& entries);
Tegra::CommandList&& entries); NvResult SubmitGPFIFOBase1(std::span<const u8> input, bool kickoff = false);
NvResult SubmitGPFIFOBase1(std::span<const u8> input, std::span<u8> output, NvResult SubmitGPFIFOBase2(std::span<const u8> input, std::span<const u8> input_inline);
bool kickoff = false);
NvResult SubmitGPFIFOBase2(std::span<const u8> input, std::span<const u8> input_inline,
std::span<u8> output);
NvResult GetWaitbase(IoctlGetWaitbase& params); NvResult GetWaitbase(IoctlGetWaitbase& params);
NvResult ChannelSetTimeout(IoctlChannelSetTimeout& params); NvResult ChannelSetTimeout(IoctlChannelSetTimeout& params);

View file

@ -29,6 +29,9 @@ std::size_t SliceVectors(std::span<const u8> input, std::vector<T>& dst, std::si
return 0; return 0;
} }
const size_t bytes_copied = count * sizeof(T); const size_t bytes_copied = count * sizeof(T);
if (input.size() < offset + bytes_copied) {
return 0;
}
std::memcpy(dst.data(), input.data() + offset, bytes_copied); std::memcpy(dst.data(), input.data() + offset, bytes_copied);
return bytes_copied; return bytes_copied;
} }
@ -41,6 +44,9 @@ std::size_t WriteVectors(std::span<u8> dst, const std::vector<T>& src, std::size
return 0; return 0;
} }
const size_t bytes_copied = src.size() * sizeof(T); const size_t bytes_copied = src.size() * sizeof(T);
if (dst.size() < offset + bytes_copied) {
return 0;
}
std::memcpy(dst.data() + offset, src.data(), bytes_copied); std::memcpy(dst.data() + offset, src.data(), bytes_copied);
return bytes_copied; return bytes_copied;
} }
@ -71,6 +77,10 @@ NvResult nvhost_nvdec_common::SetNVMAPfd(IoctlSetNvmapFD& params) {
} }
NvResult nvhost_nvdec_common::Submit(DeviceFD fd, std::span<const u8> input, std::span<u8> output) { NvResult nvhost_nvdec_common::Submit(DeviceFD fd, std::span<const u8> input, std::span<u8> output) {
if (input.size() < sizeof(IoctlSubmit) || output.size() < sizeof(IoctlSubmit)) {
UNIMPLEMENTED();
return NvResult::InvalidSize;
}
IoctlSubmit params{}; IoctlSubmit params{};
std::memcpy(&params, input.data(), std::min(input.size(), sizeof(IoctlSubmit))); std::memcpy(&params, input.data(), std::min(input.size(), sizeof(IoctlSubmit)));
LOG_DEBUG(Service_NVDRV, "called NVDEC Submit, cmd_buffer_count={}", params.cmd_buffer_count); LOG_DEBUG(Service_NVDRV, "called NVDEC Submit, cmd_buffer_count={}", params.cmd_buffer_count);