diff --git a/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs b/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs index c4570a5324..69913c9d85 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs @@ -32,14 +32,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv { "/dev/nvhost-ctrl-gpu", typeof(NvHostCtrlGpuDeviceFile) }, { "/dev/nvhost-as-gpu", typeof(NvHostAsGpuDeviceFile) }, { "/dev/nvhost-gpu", typeof(NvHostGpuDeviceFile) }, - //{ "/dev/nvhost-msenc", typeof(NvHostChannelDeviceFile) }, + //{ "/dev/nvhost-msenc", typeof(NvHostChannelDeviceFile) }, { "/dev/nvhost-nvdec", typeof(NvHostChannelDeviceFile) }, - //{ "/dev/nvhost-nvjpg", typeof(NvHostChannelDeviceFile) }, + //{ "/dev/nvhost-nvjpg", typeof(NvHostChannelDeviceFile) }, { "/dev/nvhost-vic", typeof(NvHostChannelDeviceFile) }, - //{ "/dev/nvhost-display", typeof(NvHostChannelDeviceFile) }, + //{ "/dev/nvhost-display", typeof(NvHostChannelDeviceFile) }, }; private static IdDictionary _deviceFileIdRegistry = new IdDictionary(); + private KProcess _owner; public INvDrvServices(ServiceCtx context) @@ -76,7 +77,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv NvIoctl.Direction ioctlDirection = ioctlCommand.DirectionValue; uint ioctlSize = ioctlCommand.Size; - bool isRead = (ioctlDirection & NvIoctl.Direction.Read) != 0; + bool isRead = (ioctlDirection & NvIoctl.Direction.Read) != 0; bool isWrite = (ioctlDirection & NvIoctl.Direction.Write) != 0; if ((isWrite && ioctlSize > outputDataSize) || (isRead && ioctlSize > inputDataSize)) @@ -332,7 +333,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv if (internalResult == NvInternalResult.NotImplemented) { - throw new NvQueryEventlNotImplementedException(context, deviceFile, eventId); + throw new NvQueryEventNotImplementedException(context, deviceFile, eventId); } errorCode = ConvertInternalErrorCode(internalResult); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs index 41c0cc7507..a3b48b0691 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs @@ -10,15 +10,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { class NvHostAsGpuDeviceFile : NvDeviceFile { - private const int FlagFixedOffset = 1; - private const int FlagRemapSubRange = 0x100; - private static ConcurrentDictionary _addressSpaceContextRegistry = new ConcurrentDictionary(); - public NvHostAsGpuDeviceFile(ServiceCtx context) : base(context) - { - - } + public NvHostAsGpuDeviceFile(ServiceCtx context) : base(context) { } public override NvInternalResult Ioctl(NvIoctl command, Span arguments) { @@ -95,7 +89,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { // Note: When the fixed offset flag is not set, // the Offset field holds the alignment size instead. - if ((arguments.Flags & FlagFixedOffset) != 0) + if ((arguments.Flags & AddressSpaceFlags.FixedOffset) != 0) { arguments.Offset = addressSpaceContext.Vmm.ReserveFixed(arguments.Offset, (long)size); } @@ -184,23 +178,23 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu return NvInternalResult.InvalidInput; } - long pa; + long physicalAddress; - if ((arguments.Flags & FlagRemapSubRange) != 0) + if ((arguments.Flags & AddressSpaceFlags.RemapSubRange) != 0) { lock (addressSpaceContext) { - if (addressSpaceContext.TryGetMapPhysicalAddress(arguments.Offset, out pa)) + if (addressSpaceContext.TryGetMapPhysicalAddress(arguments.Offset, out physicalAddress)) { - long va = arguments.Offset + arguments.BufferOffset; + long virtualAddress = arguments.Offset + arguments.BufferOffset; - pa += arguments.BufferOffset; + physicalAddress += arguments.BufferOffset; - if (addressSpaceContext.Vmm.Map(pa, va, arguments.MappingSize) < 0) + if (addressSpaceContext.Vmm.Map(physicalAddress, virtualAddress, arguments.MappingSize) < 0) { - string msg = string.Format(mapErrorMsg, va, arguments.MappingSize); + string message = string.Format(mapErrorMsg, virtualAddress, arguments.MappingSize); - Logger.PrintWarning(LogClass.ServiceNv, msg); + Logger.PrintWarning(LogClass.ServiceNv, message); return NvInternalResult.InvalidInput; } @@ -216,7 +210,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu } } - pa = map.Address + arguments.BufferOffset; + physicalAddress = map.Address + arguments.BufferOffset; long size = arguments.MappingSize; @@ -231,26 +225,26 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { // Note: When the fixed offset flag is not set, // the Offset field holds the alignment size instead. - bool vaAllocated = (arguments.Flags & FlagFixedOffset) == 0; + bool virtualAddressAllocated = (arguments.Flags & AddressSpaceFlags.FixedOffset) == 0; - if (!vaAllocated) + if (!virtualAddressAllocated) { if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size)) { - arguments.Offset = addressSpaceContext.Vmm.Map(pa, arguments.Offset, size); + arguments.Offset = addressSpaceContext.Vmm.Map(physicalAddress, arguments.Offset, size); } else { - string msg = string.Format(mapErrorMsg, arguments.Offset, size); + string message = string.Format(mapErrorMsg, arguments.Offset, size); - Logger.PrintWarning(LogClass.ServiceNv, msg); + Logger.PrintWarning(LogClass.ServiceNv, message); result = NvInternalResult.InvalidInput; } } else { - arguments.Offset = addressSpaceContext.Vmm.Map(pa, size); + arguments.Offset = addressSpaceContext.Vmm.Map(physicalAddress, size); } if (arguments.Offset < 0) @@ -263,7 +257,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu } else { - addressSpaceContext.AddMap(arguments.Offset, size, pa, vaAllocated); + addressSpaceContext.AddMap(arguments.Offset, size, physicalAddress, virtualAddressAllocated); } } @@ -314,10 +308,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu return NvInternalResult.Success; } - public override void Close() - { - - } + public override void Close() { } public static AddressSpaceContext GetAddressSpaceContext(KProcess process) { diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs index b124356907..b03f463f95 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceContext.cs @@ -14,12 +14,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types private class Range { public ulong Start { get; private set; } - public ulong End { get; private set; } + public ulong End { get; private set; } public Range(long position, long size) { Start = (ulong)position; - End = (ulong)size + Start; + End = (ulong)size + Start; } } @@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types bool vaAllocated) : base(position, size) { PhysicalAddress = physicalAddress; - VaAllocated = vaAllocated; + VaAllocated = vaAllocated; } } @@ -46,7 +46,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types { Vmm = new NvGpuVmm(process.CpuMemory); - _maps = new SortedList(); + _maps = new SortedList(); _reservations = new SortedList(); } @@ -139,7 +139,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types private Range BinarySearch(SortedList lst, long position) { - int left = 0; + int left = 0; int right = lst.Count - 1; while (left <= right) @@ -172,7 +172,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types { Range ltRg = null; - int left = 0; + int left = 0; int right = lst.Count - 1; while (left <= right) diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs new file mode 100644 index 0000000000..611cf78bfc --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AddressSpaceFlags.cs @@ -0,0 +1,11 @@ +using System; + +namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types +{ + [Flags] + enum AddressSpaceFlags : uint + { + FixedOffset = 1, + RemapSubRange = 0x100, + } +} diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs index b8eee88c15..73f746e2dc 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/AllocSpaceArguments.cs @@ -5,10 +5,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types [StructLayout(LayoutKind.Sequential)] struct AllocSpaceArguments { - public uint Pages; - public uint PageSize; - public uint Flags; - public uint Padding; - public long Offset; + public uint Pages; + public uint PageSize; + public AddressSpaceFlags Flags; + public uint Padding; + public long Offset; } } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs index 5672b79724..02e058df63 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/Types/MapBufferExArguments.cs @@ -5,12 +5,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types [StructLayout(LayoutKind.Sequential)] struct MapBufferExArguments { - public int Flags; - public int Kind; - public int NvMapHandle; - public int PageSize; - public long BufferOffset; - public long MappingSize; - public long Offset; + public AddressSpaceFlags Flags; + public int Kind; + public int NvMapHandle; + public int PageSize; + public long BufferOffset; + public long MappingSize; + public long Offset; } } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs index c7a2190cd9..bd3d182bbb 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs @@ -21,11 +21,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel public NvHostChannelDeviceFile(ServiceCtx context) : base(context) { - _gpu = context.Device.Gpu; - _memory = context.Memory; - _timeout = 3000; - _submitTimeout = 0; - _timeslice = 0; + _gpu = context.Device.Gpu; + _memory = context.Memory; + _timeout = 3000; + _submitTimeout = 0; + _timeslice = 0; } public override NvInternalResult Ioctl(NvIoctl command, Span arguments) @@ -116,14 +116,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel { NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(_owner, commandBufferEntry.MemoryId); - int[] cmdBufData = new int[commandBufferEntry.WordsCount]; + int[] commandBufferData = new int[commandBufferEntry.WordsCount]; - for (int offset = 0; offset < cmdBufData.Length; offset++) + for (int offset = 0; offset < commandBufferData.Length; offset++) { - cmdBufData[offset] = _memory.ReadInt32(map.Address + commandBufferEntry.Offset + offset * 4); + commandBufferData[offset] = _memory.ReadInt32(map.Address + commandBufferEntry.Offset + offset * 4); } - _gpu.PushCommandBuffer(vmm, cmdBufData); + _gpu.PushCommandBuffer(vmm, commandBufferData); } return NvInternalResult.Success; @@ -195,8 +195,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel Span commandBufferEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, commandBufferHeader.NumEntries); NvGpuVmm vmm = NvHostAsGpuDeviceFile.GetAddressSpaceContext(_owner).Vmm; - // TODO - foreach (ref CommandBufferHandle commandBufferEntry in commandBufferEntries) { NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(_owner, commandBufferEntry.MapHandle); @@ -240,9 +238,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult SubmitGpfifo(Span arguments) { - int headerSize = Unsafe.SizeOf(); - SubmitGpfifoArguments gpfifoSubmissionHeader = MemoryMarshal.Cast(arguments)[0]; - Span gpfifoEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, gpfifoSubmissionHeader.NumEntries); + int headerSize = Unsafe.SizeOf(); + SubmitGpfifoArguments gpfifoSubmissionHeader = MemoryMarshal.Cast(arguments)[0]; + Span gpfifoEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, gpfifoSubmissionHeader.NumEntries); return SubmitGpfifo(ref gpfifoSubmissionHeader, gpfifoEntries); } @@ -344,9 +342,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel return NvInternalResult.Success; } - public override void Close() - { - - } + public override void Close() { } } } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs index 01b206dca6..18a30a0ca7 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs @@ -31,6 +31,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel break; } } + return result; } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs index b12c1d63b1..6a7e3da803 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types { public int NumEntries; public int DataAddress; // Ignored by the driver. - public bool AttachHostChDas; + public bool AttachHostChDas; public byte Padding1; public short Padding2; } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs index b0d4a5d4f3..710625f74a 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs @@ -78,8 +78,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl case 0x1f: result = CallIoctlMethod(EventRegister, arguments); break; - default: - break; } } @@ -398,9 +396,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl return null; } - public override void Close() - { - - } + public override void Close() { } } } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs index 358f673c92..3ee318a379 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/Types/GetConfigurationArguments.cs @@ -11,8 +11,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl.Types public static GetConfigurationArguments FromSpan(Span span) { - string domain = Encoding.ASCII.GetString(span.Slice(0, 0x41)); - string parameter = Encoding.ASCII.GetString(span.Slice(0x41, 0x41)); + string domain = Encoding.ASCII.GetString(span.Slice(0, 0x41)); + string parameter = Encoding.ASCII.GetString(span.Slice(0x41, 0x41)); GetConfigurationArguments result = new GetConfigurationArguments { diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs index b76f813d88..027d6764ee 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs @@ -114,10 +114,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu return NvInternalResult.Success; } - public override void Close() - { - - } + public override void Close() { } private NvInternalResult ZcullGetCtxSize(ref ZcullGetCtxSizeArguments arguments) { @@ -212,7 +209,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu arguments.TpcMask = tpcMask; } - return NvInternalResult.Success; } diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs index ceed2acc16..e21e437e82 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/Types/ZbcSetTableArguments.cs @@ -5,6 +5,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types [StructLayout(LayoutKind.Sequential)] struct ZbcSetTableArguments { - + // TODO } } diff --git a/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs b/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs index 30cab31e80..b7a72eba00 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs @@ -4,17 +4,17 @@ using System.Text; namespace Ryujinx.HLE.HOS.Services.Nv.Types { - class NvQueryEventlNotImplementedException : Exception + class NvQueryEventNotImplementedException : Exception { public ServiceCtx Context { get; } public NvDeviceFile DeviceFile { get; } public uint EventId { get; } - public NvQueryEventlNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, uint eventId) + public NvQueryEventNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, uint eventId) : this(context, deviceFile, eventId, "This query event is not implemented.") { } - public NvQueryEventlNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, uint eventId, string message) + public NvQueryEventNotImplementedException(ServiceCtx context, NvDeviceFile deviceFile, uint eventId, string message) : base(message) { Context = context;