From 1e7347bf722a0b318966dad747bec34a708f0fd1 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 24 Oct 2021 16:36:29 +0100 Subject: [PATCH] Use semantic wrapping for nvdrv where appropriate --- .../skyline/services/nvdrv/INvDrvServices.cpp | 17 +++++++++++++---- .../skyline/services/nvdrv/devices/nvdevice.cpp | 10 +++++----- .../services/nvdrv/devices/nvhost/as_gpu.cpp | 9 +++++++-- .../services/nvdrv/devices/nvhost/as_gpu.h | 9 +++++++-- .../services/nvdrv/devices/nvhost/ctrl_gpu.cpp | 8 ++++---- .../nvdrv/devices/nvhost/gpu_channel.cpp | 15 +++++++++------ .../services/nvdrv/devices/nvhost/gpu_channel.h | 9 +++++++-- .../skyline/services/nvdrv/devices/nvmap.cpp | 11 ++++++++--- .../cpp/skyline/services/nvdrv/devices/nvmap.h | 8 ++++++-- .../main/cpp/skyline/services/nvdrv/driver.cpp | 10 +++++----- 10 files changed, 71 insertions(+), 35 deletions(-) diff --git a/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp b/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp index f3e1d2c5..93552250 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp @@ -16,7 +16,10 @@ } (x) namespace skyline::service::nvdrv { - INvDrvServices::INvDrvServices(const DeviceState &state, ServiceManager &manager, Driver &driver, const SessionPermissions &perms) : BaseService(state, manager), driver(driver), ctx(SessionContext{.perms = perms}) {} + INvDrvServices::INvDrvServices(const DeviceState &state, ServiceManager &manager, Driver &driver, const SessionPermissions &perms) + : BaseService(state, manager), + driver(driver), + ctx(SessionContext{.perms = perms}) {} Result INvDrvServices::Open(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { constexpr FileDescriptor SessionFdLimit{std::numeric_limits::digits * 2}; //!< Nvdrv uses two 64 bit variables to store a bitset @@ -59,7 +62,9 @@ namespace skyline::service::nvdrv { auto fd{request.Pop()}; auto ioctl{request.Pop()}; - auto buf{GetMainIoctlBuffer(ioctl, !request.inputBuf.empty() ? request.inputBuf.at(0) : span{}, !request.outputBuf.empty() ? request.outputBuf.at(0) : span{})}; + auto buf{GetMainIoctlBuffer(ioctl, + !request.inputBuf.empty() ? request.inputBuf.at(0) : span{}, + !request.outputBuf.empty() ? request.outputBuf.at(0) : span{})}; if (!buf) return NVRESULT(buf); else @@ -104,7 +109,9 @@ namespace skyline::service::nvdrv { // Inline buffer is optional auto inlineBuf{request.inputBuf.size() > 1 ? request.inputBuf.at(1) : span{}}; - auto buf{GetMainIoctlBuffer(ioctl, !request.inputBuf.empty() ? request.inputBuf.at(0) : span{}, !request.outputBuf.empty() ? request.outputBuf.at(0) : span{})}; + auto buf{GetMainIoctlBuffer(ioctl, + !request.inputBuf.empty() ? request.inputBuf.at(0) : span{}, + !request.outputBuf.empty() ? request.outputBuf.at(0) : span{})}; if (!buf) return NVRESULT(buf); else @@ -118,7 +125,9 @@ namespace skyline::service::nvdrv { // Inline buffer is optional auto inlineBuf{request.outputBuf.size() > 1 ? request.outputBuf.at(1) : span{}}; - auto buf{GetMainIoctlBuffer(ioctl, !request.inputBuf.empty() ? request.inputBuf.at(0) : span{}, !request.outputBuf.empty() ? request.outputBuf.at(0) : span{})}; + auto buf{GetMainIoctlBuffer(ioctl, + !request.inputBuf.empty() ? request.inputBuf.at(0) : span{}, + !request.outputBuf.empty() ? request.outputBuf.at(0) : span{})}; if (!buf) return NVRESULT(buf); else diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvdevice.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvdevice.cpp index 6e42601f..5c229c97 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvdevice.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvdevice.cpp @@ -5,11 +5,11 @@ #include "nvdevice.h" namespace skyline::service::nvdrv::device { - NvDevice::NvDevice(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) : - state(state), - driver(driver), - core(core), - ctx(ctx) {} + NvDevice::NvDevice(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) + : state(state), + driver(driver), + core(core), + ctx(ctx) {} const std::string &NvDevice::GetName() { if (name.empty()) { diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp index 39871e16..bf1e9c7b 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp @@ -170,7 +170,9 @@ namespace skyline::service::nvdrv::device::nvhost { return PosixResult::Success; } - PosixResult AsGpu::MapBufferEx(In flags, In kind, In handle, In bufferOffset, In mappingSize, InOut offset) { + PosixResult AsGpu::MapBufferEx(In flags, In kind, + In handle, In bufferOffset, + In mappingSize, InOut offset) { state.logger->Debug("flags: ( fixed: {}, remap: {} ), kind: {}, handle: {}, bufferOffset: 0x{:X}, mappingSize: 0x{:X}, offset: 0x{:X}", flags.fixed, flags.remap, kind, handle, bufferOffset, mappingSize, offset); @@ -271,7 +273,10 @@ namespace skyline::service::nvdrv::device::nvhost { return GetVaRegions(bufAddr, bufSize, vaRegions); } - PosixResult AsGpu::AllocAsEx(In flags, In asFd, In bigPageSize, In vaRangeStart, In vaRangeEnd, In vaRangeSplit) { + PosixResult AsGpu::AllocAsEx(In flags, + In asFd, + In bigPageSize, + In vaRangeStart, In vaRangeEnd, In vaRangeSplit) { std::scoped_lock lock(mutex); if (vm.initialised) diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.h b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.h index 1487b2de..a4abb45c 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.h +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.h @@ -131,7 +131,9 @@ namespace skyline::service::nvdrv::device::nvhost { * @brief Maps a region into this address space with extra parameters * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_MAP_BUFFER_EX */ - PosixResult MapBufferEx(In flags, In kind, In handle, In bufferOffset, In mappingSize, InOut offset); + PosixResult MapBufferEx(In flags, In kind, + In handle, In bufferOffset, + In mappingSize, InOut offset); /** * @brief Returns info about the address space and its page sizes @@ -148,7 +150,10 @@ namespace skyline::service::nvdrv::device::nvhost { * @brief Allocates this address space with the given parameters * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_ALLOC_AS_EX */ - PosixResult AllocAsEx(In flags, In asFd, In bigPageSize, In vaRangeStart, In vaRangeEnd, In vaRangeSplit); + PosixResult AllocAsEx(In flags, + In asFd, + In bigPageSize, + In vaRangeStart, In vaRangeEnd, In vaRangeSplit); /** * @brief Remaps a region of the GPU address space diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl_gpu.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl_gpu.cpp index 09f93bf5..b845893f 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl_gpu.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl_gpu.cpp @@ -5,10 +5,10 @@ #include "ctrl_gpu.h" namespace skyline::service::nvdrv::device::nvhost { - CtrlGpu::CtrlGpu(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) : - NvDevice(state, driver, core, ctx), - errorNotifierEvent(std::make_shared(state, false)), - unknownEvent(std::make_shared(state, false)) {} + CtrlGpu::CtrlGpu(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) + : NvDevice(state, driver, core, ctx), + errorNotifierEvent(std::make_shared(state, false)), + unknownEvent(std::make_shared(state, false)) {} PosixResult CtrlGpu::ZCullGetCtxSize(Out size) { size = 0x1; diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp index fd579ca8..cce97cf7 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp @@ -6,11 +6,11 @@ #include "gpu_channel.h" namespace skyline::service::nvdrv::device::nvhost { - GpuChannel::GpuChannel(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) : - NvDevice(state, driver, core, ctx), - smExceptionBreakpointIntReportEvent(std::make_shared(state, false)), - smExceptionBreakpointPauseReportEvent(std::make_shared(state, false)), - errorNotifierEvent(std::make_shared(state, false)) { + GpuChannel::GpuChannel(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) + : NvDevice(state, driver, core, ctx), + smExceptionBreakpointIntReportEvent(std::make_shared(state, false)), + smExceptionBreakpointPauseReportEvent(std::make_shared(state, false)), + errorNotifierEvent(std::make_shared(state, false)) { channelSyncpoint = core.syncpointManager.AllocateSyncpoint(false); } @@ -75,7 +75,10 @@ namespace skyline::service::nvdrv::device::nvhost { return PosixResult::Success; } - PosixResult GpuChannel::SubmitGpfifo(In userAddress, In numEntries, InOut flags, InOut fence, span gpEntries) { + PosixResult GpuChannel::SubmitGpfifo(In userAddress, In numEntries, + InOut flags, + InOut fence, + span gpEntries) { state.logger->Debug("userAddress: 0x{:X}, numEntries: {}," "flags ( fenceWait: {}, fenceIncrement: {}, hwFormat: {}, suppressWfi: {}, incrementWithValue: {})," "fence ( id: {}, threshold: {} )", diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h index b5f3461c..55a119ea 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h @@ -69,12 +69,17 @@ namespace skyline::service::nvdrv::device::nvhost { * @brief Submits GPFIFO entries for this channel * @url https://switchbrew.org/wiki/NV_services#NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO */ - PosixResult SubmitGpfifo(In userAddress, In numEntries, InOut flags, InOut fence, span gpEntries); + PosixResult SubmitGpfifo(In userAddress, In numEntries, + InOut flags, + InOut fence, + span gpEntries); /** * @brief Ioctl2 variant of SubmitGpfifo */ - PosixResult SubmitGpfifo2(span inlineBuffer, In userAddress, In numEntries, InOut flags, InOut fence); + PosixResult SubmitGpfifo2(span inlineBuffer, In userAddress, In numEntries, + InOut flags, + InOut fence); /** * @brief Allocates a graphic context object diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp index 274cf9ed..926e769b 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp @@ -38,8 +38,11 @@ namespace skyline::service::nvdrv::device { return result; } - PosixResult NvMap::Alloc(In handle, In heapMask, In flags, InOut align, In kind, In address) { - state.logger->Debug("handle: {}, flags: ( mapUncached: {}, keepUncachedAfterFree: {} ), align: 0x{:X}, kind: {}, address: 0x{:X}", handle, flags.mapUncached, flags.keepUncachedAfterFree, align, kind, address); + PosixResult NvMap::Alloc(In handle, + In heapMask, In flags, + InOut align, In kind, In address) { + state.logger->Debug("handle: {}, flags: ( mapUncached: {}, keepUncachedAfterFree: {} ), align: 0x{:X}, kind: {}, address: 0x{:X}", + handle, flags.mapUncached, flags.keepUncachedAfterFree, align, kind, address); if (!handle) [[unlikely]] return PosixResult::InvalidArgument; @@ -58,7 +61,9 @@ namespace skyline::service::nvdrv::device { return handleDesc->Alloc(flags, align, kind, address); } - PosixResult NvMap::Free(In handle, Out address, Out size, Out flags) { + PosixResult NvMap::Free(In handle, + Out address, Out size, + Out flags) { state.logger->Debug("handle: {}", handle); if (!handle) [[unlikely]] diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.h b/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.h index 74fe4557..0a0b71b9 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.h +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.h @@ -41,13 +41,17 @@ namespace skyline::service::nvdrv::device { * @brief Adds the given backing memory to the nvmap handle * @url https://switchbrew.org/wiki/NV_services#NVMAP_IOC_ALLOC */ - PosixResult Alloc(In handle, In heapMask, In flags, InOut align, In kind, In address); + PosixResult Alloc(In handle, + In heapMask, In flags, + InOut align, In kind, In address); /** * @brief Attempts to free a handle and unpin it from SMMU memory * @url https://switchbrew.org/wiki/NV_services#NVMAP_IOC_FREE */ - PosixResult Free(In handle, Out address, Out size, Out flags); + PosixResult Free(In handle, + Out address, Out size, + Out flags); /** * @brief Returns info about a property of the nvmap handle diff --git a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp index 0f551f44..4f5cfebb 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp @@ -81,7 +81,7 @@ namespace skyline::service::nvdrv { std::shared_lock lock(deviceMutex); return ConvertResult(devices.at(fd)->Ioctl(cmd, buffer)); } catch (const std::out_of_range &) { - throw exception("Ioctl was called with invalid file descriptor: {}", fd); + throw exception("Ioctl was called with invalid fd: {}", fd); } } @@ -92,7 +92,7 @@ namespace skyline::service::nvdrv { std::shared_lock lock(deviceMutex); return ConvertResult(devices.at(fd)->Ioctl2(cmd, buffer, inlineBuffer)); } catch (const std::out_of_range &) { - throw exception("Ioctl2 was called with invalid file descriptor: 0x{:X}", fd); + throw exception("Ioctl2 was called with invalid fd: {}", fd); } } @@ -103,7 +103,7 @@ namespace skyline::service::nvdrv { std::shared_lock lock(deviceMutex); return ConvertResult(devices.at(fd)->Ioctl3(cmd, buffer, inlineBuffer)); } catch (const std::out_of_range &) { - throw exception("Ioctl3 was called with invalid file descriptor: {}", fd); + throw exception("Ioctl3 was called with invalid fd: {}", fd); } } @@ -112,7 +112,7 @@ namespace skyline::service::nvdrv { std::unique_lock lock(deviceMutex); devices.erase(fd); } catch (const std::out_of_range &) { - state.logger->Warn("Trying to close non-existent file descriptor: {}"); + state.logger->Warn("Trying to close invalid fd: {}"); } } @@ -123,7 +123,7 @@ namespace skyline::service::nvdrv { std::shared_lock lock(deviceMutex); return devices.at(fd)->QueryEvent(eventId); } catch (const std::exception &) { - throw exception("QueryEvent was called with invalid file descriptor: {}", fd); + throw exception("QueryEvent was called with invalid fd: {}", fd); } } }