diff options
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Nv/NvGpuAS')
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASCtx.cs | 146 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASIoctl.cs | 244 |
2 files changed, 195 insertions, 195 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASCtx.cs b/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASCtx.cs index cd1ab7cd..70275b2a 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASCtx.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASCtx.cs @@ -5,73 +5,73 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS { class NvGpuASCtx { - public NvGpuVmm Vmm { get; } + public NvGpuVmm Vmm { get; private set; } private class Range { - public ulong Start { get; } - public ulong End { get; } + public ulong Start { get; private set; } + public ulong End { get; private set; } - public Range(long position, long size) + public Range(long Position, long Size) { - Start = (ulong)position; - End = (ulong)size + Start; + Start = (ulong)Position; + End = (ulong)Size + Start; } } private class MappedMemory : Range { - public long PhysicalAddress { get; } - public bool VaAllocated { get; } + public long PhysicalAddress { get; private set; } + public bool VaAllocated { get; private set; } public MappedMemory( - long position, - long size, - long physicalAddress, - bool vaAllocated) : base(position, size) + long Position, + long Size, + long PhysicalAddress, + bool VaAllocated) : base(Position, Size) { - PhysicalAddress = physicalAddress; - VaAllocated = vaAllocated; + this.PhysicalAddress = PhysicalAddress; + this.VaAllocated = VaAllocated; } } - private SortedList<long, Range> _maps; - private SortedList<long, Range> _reservations; + private SortedList<long, Range> Maps; + private SortedList<long, Range> Reservations; - public NvGpuASCtx(ServiceCtx context) + public NvGpuASCtx(ServiceCtx Context) { - Vmm = new NvGpuVmm(context.Memory); + Vmm = new NvGpuVmm(Context.Memory); - _maps = new SortedList<long, Range>(); - _reservations = new SortedList<long, Range>(); + Maps = new SortedList<long, Range>(); + Reservations = new SortedList<long, Range>(); } - public bool ValidateFixedBuffer(long position, long size) + public bool ValidateFixedBuffer(long Position, long Size) { - long mapEnd = position + size; + long MapEnd = Position + Size; //Check if size is valid (0 is also not allowed). - if ((ulong)mapEnd <= (ulong)position) + if ((ulong)MapEnd <= (ulong)Position) { return false; } //Check if address is page aligned. - if ((position & NvGpuVmm.PageMask) != 0) + if ((Position & NvGpuVmm.PageMask) != 0) { return false; } //Check if region is reserved. - if (BinarySearch(_reservations, position) == null) + if (BinarySearch(Reservations, Position) == null) { return false; } //Check for overlap with already mapped buffers. - Range map = BinarySearchLt(_maps, mapEnd); + Range Map = BinarySearchLt(Maps, MapEnd); - if (map != null && map.End > (ulong)position) + if (Map != null && Map.End > (ulong)Position) { return false; } @@ -80,25 +80,25 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS } public void AddMap( - long position, - long size, - long physicalAddress, - bool vaAllocated) + long Position, + long Size, + long PhysicalAddress, + bool VaAllocated) { - _maps.Add(position, new MappedMemory(position, size, physicalAddress, vaAllocated)); + Maps.Add(Position, new MappedMemory(Position, Size, PhysicalAddress, VaAllocated)); } - public bool RemoveMap(long position, out long size) + public bool RemoveMap(long Position, out long Size) { - size = 0; + Size = 0; - if (_maps.Remove(position, out Range value)) + if (Maps.Remove(Position, out Range Value)) { - MappedMemory map = (MappedMemory)value; + MappedMemory Map = (MappedMemory)Value; - if (map.VaAllocated) + if (Map.VaAllocated) { - size = (long)(map.End - map.Start); + Size = (long)(Map.End - Map.Start); } return true; @@ -107,94 +107,94 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS return false; } - public bool TryGetMapPhysicalAddress(long position, out long physicalAddress) + public bool TryGetMapPhysicalAddress(long Position, out long PhysicalAddress) { - Range map = BinarySearch(_maps, position); + Range Map = BinarySearch(Maps, Position); - if (map != null) + if (Map != null) { - physicalAddress = ((MappedMemory)map).PhysicalAddress; + PhysicalAddress = ((MappedMemory)Map).PhysicalAddress; return true; } - physicalAddress = 0; + PhysicalAddress = 0; return false; } - public void AddReservation(long position, long size) + public void AddReservation(long Position, long Size) { - _reservations.Add(position, new Range(position, size)); + Reservations.Add(Position, new Range(Position, Size)); } - public bool RemoveReservation(long position) + public bool RemoveReservation(long Position) { - return _reservations.Remove(position); + return Reservations.Remove(Position); } - private Range BinarySearch(SortedList<long, Range> lst, long position) + private Range BinarySearch(SortedList<long, Range> Lst, long Position) { - int left = 0; - int right = lst.Count - 1; + int Left = 0; + int Right = Lst.Count - 1; - while (left <= right) + while (Left <= Right) { - int size = right - left; + int Size = Right - Left; - int middle = left + (size >> 1); + int Middle = Left + (Size >> 1); - Range rg = lst.Values[middle]; + Range Rg = Lst.Values[Middle]; - if ((ulong)position >= rg.Start && (ulong)position < rg.End) + if ((ulong)Position >= Rg.Start && (ulong)Position < Rg.End) { - return rg; + return Rg; } - if ((ulong)position < rg.Start) + if ((ulong)Position < Rg.Start) { - right = middle - 1; + Right = Middle - 1; } else { - left = middle + 1; + Left = Middle + 1; } } return null; } - private Range BinarySearchLt(SortedList<long, Range> lst, long position) + private Range BinarySearchLt(SortedList<long, Range> Lst, long Position) { - Range ltRg = null; + Range LtRg = null; - int left = 0; - int right = lst.Count - 1; + int Left = 0; + int Right = Lst.Count - 1; - while (left <= right) + while (Left <= Right) { - int size = right - left; + int Size = Right - Left; - int middle = left + (size >> 1); + int Middle = Left + (Size >> 1); - Range rg = lst.Values[middle]; + Range Rg = Lst.Values[Middle]; - if ((ulong)position < rg.Start) + if ((ulong)Position < Rg.Start) { - right = middle - 1; + Right = Middle - 1; } else { - left = middle + 1; + Left = Middle + 1; - if ((ulong)position > rg.Start) + if ((ulong)Position > Rg.Start) { - ltRg = rg; + LtRg = Rg; } } } - return ltRg; + return LtRg; } } }
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASIoctl.cs b/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASIoctl.cs index 8e128a0d..7fe3bbed 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASIoctl.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvGpuAS/NvGpuASIoctl.cs @@ -14,182 +14,182 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS private const int FlagRemapSubRange = 0x100; - private static ConcurrentDictionary<KProcess, NvGpuASCtx> _asCtxs; + private static ConcurrentDictionary<KProcess, NvGpuASCtx> ASCtxs; static NvGpuASIoctl() { - _asCtxs = new ConcurrentDictionary<KProcess, NvGpuASCtx>(); + ASCtxs = new ConcurrentDictionary<KProcess, NvGpuASCtx>(); } - public static int ProcessIoctl(ServiceCtx context, int cmd) + public static int ProcessIoctl(ServiceCtx Context, int Cmd) { - switch (cmd & 0xffff) + switch (Cmd & 0xffff) { - case 0x4101: return BindChannel (context); - case 0x4102: return AllocSpace (context); - case 0x4103: return FreeSpace (context); - case 0x4105: return UnmapBuffer (context); - case 0x4106: return MapBufferEx (context); - case 0x4108: return GetVaRegions(context); - case 0x4109: return InitializeEx(context); - case 0x4114: return Remap (context, cmd); + case 0x4101: return BindChannel (Context); + case 0x4102: return AllocSpace (Context); + case 0x4103: return FreeSpace (Context); + case 0x4105: return UnmapBuffer (Context); + case 0x4106: return MapBufferEx (Context); + case 0x4108: return GetVaRegions(Context); + case 0x4109: return InitializeEx(Context); + case 0x4114: return Remap (Context, Cmd); } - throw new NotImplementedException(cmd.ToString("x8")); + throw new NotImplementedException(Cmd.ToString("x8")); } - private static int BindChannel(ServiceCtx context) + private static int BindChannel(ServiceCtx Context) { - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; Logger.PrintStub(LogClass.ServiceNv, "Stubbed."); return NvResult.Success; } - private static int AllocSpace(ServiceCtx context) + private static int AllocSpace(ServiceCtx Context) { - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; - NvGpuASAllocSpace args = MemoryHelper.Read<NvGpuASAllocSpace>(context.Memory, inputPosition); + NvGpuASAllocSpace Args = MemoryHelper.Read<NvGpuASAllocSpace>(Context.Memory, InputPosition); - NvGpuASCtx asCtx = GetASCtx(context); + NvGpuASCtx ASCtx = GetASCtx(Context); - ulong size = (ulong)args.Pages * - (ulong)args.PageSize; + ulong Size = (ulong)Args.Pages * + (ulong)Args.PageSize; - int result = NvResult.Success; + int Result = NvResult.Success; - lock (asCtx) + lock (ASCtx) { //Note: When the fixed offset flag is not set, //the Offset field holds the alignment size instead. - if ((args.Flags & FlagFixedOffset) != 0) + if ((Args.Flags & FlagFixedOffset) != 0) { - args.Offset = asCtx.Vmm.ReserveFixed(args.Offset, (long)size); + Args.Offset = ASCtx.Vmm.ReserveFixed(Args.Offset, (long)Size); } else { - args.Offset = asCtx.Vmm.Reserve((long)size, args.Offset); + Args.Offset = ASCtx.Vmm.Reserve((long)Size, Args.Offset); } - if (args.Offset < 0) + if (Args.Offset < 0) { - args.Offset = 0; + Args.Offset = 0; - Logger.PrintWarning(LogClass.ServiceNv, $"Failed to allocate size {size:x16}!"); + Logger.PrintWarning(LogClass.ServiceNv, $"Failed to allocate size {Size:x16}!"); - result = NvResult.OutOfMemory; + Result = NvResult.OutOfMemory; } else { - asCtx.AddReservation(args.Offset, (long)size); + ASCtx.AddReservation(Args.Offset, (long)Size); } } - MemoryHelper.Write(context.Memory, outputPosition, args); + MemoryHelper.Write(Context.Memory, OutputPosition, Args); - return result; + return Result; } - private static int FreeSpace(ServiceCtx context) + private static int FreeSpace(ServiceCtx Context) { - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; - NvGpuASAllocSpace args = MemoryHelper.Read<NvGpuASAllocSpace>(context.Memory, inputPosition); + NvGpuASAllocSpace Args = MemoryHelper.Read<NvGpuASAllocSpace>(Context.Memory, InputPosition); - NvGpuASCtx asCtx = GetASCtx(context); + NvGpuASCtx ASCtx = GetASCtx(Context); - int result = NvResult.Success; + int Result = NvResult.Success; - lock (asCtx) + lock (ASCtx) { - ulong size = (ulong)args.Pages * - (ulong)args.PageSize; + ulong Size = (ulong)Args.Pages * + (ulong)Args.PageSize; - if (asCtx.RemoveReservation(args.Offset)) + if (ASCtx.RemoveReservation(Args.Offset)) { - asCtx.Vmm.Free(args.Offset, (long)size); + ASCtx.Vmm.Free(Args.Offset, (long)Size); } else { Logger.PrintWarning(LogClass.ServiceNv, - $"Failed to free offset 0x{args.Offset:x16} size 0x{size:x16}!"); + $"Failed to free offset 0x{Args.Offset:x16} size 0x{Size:x16}!"); - result = NvResult.InvalidInput; + Result = NvResult.InvalidInput; } } - return result; + return Result; } - private static int UnmapBuffer(ServiceCtx context) + private static int UnmapBuffer(ServiceCtx Context) { - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; - NvGpuASUnmapBuffer args = MemoryHelper.Read<NvGpuASUnmapBuffer>(context.Memory, inputPosition); + NvGpuASUnmapBuffer Args = MemoryHelper.Read<NvGpuASUnmapBuffer>(Context.Memory, InputPosition); - NvGpuASCtx asCtx = GetASCtx(context); + NvGpuASCtx ASCtx = GetASCtx(Context); - lock (asCtx) + lock (ASCtx) { - if (asCtx.RemoveMap(args.Offset, out long size)) + if (ASCtx.RemoveMap(Args.Offset, out long Size)) { - if (size != 0) + if (Size != 0) { - asCtx.Vmm.Free(args.Offset, size); + ASCtx.Vmm.Free(Args.Offset, Size); } } else { - Logger.PrintWarning(LogClass.ServiceNv, $"Invalid buffer offset {args.Offset:x16}!"); + Logger.PrintWarning(LogClass.ServiceNv, $"Invalid buffer offset {Args.Offset:x16}!"); } } return NvResult.Success; } - private static int MapBufferEx(ServiceCtx context) + private static int MapBufferEx(ServiceCtx Context) { - const string mapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16} and size 0x{1:x16}!"; + const string MapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16} and size 0x{1:x16}!"; - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; - NvGpuASMapBufferEx args = MemoryHelper.Read<NvGpuASMapBufferEx>(context.Memory, inputPosition); + NvGpuASMapBufferEx Args = MemoryHelper.Read<NvGpuASMapBufferEx>(Context.Memory, InputPosition); - NvGpuASCtx asCtx = GetASCtx(context); + NvGpuASCtx ASCtx = GetASCtx(Context); - NvMapHandle map = NvMapIoctl.GetNvMapWithFb(context, args.NvMapHandle); + NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle); - if (map == null) + if (Map == null) { - Logger.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{args.NvMapHandle:x8}!"); + Logger.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{Args.NvMapHandle:x8}!"); return NvResult.InvalidInput; } - long pa; + long PA; - if ((args.Flags & FlagRemapSubRange) != 0) + if ((Args.Flags & FlagRemapSubRange) != 0) { - lock (asCtx) + lock (ASCtx) { - if (asCtx.TryGetMapPhysicalAddress(args.Offset, out pa)) + if (ASCtx.TryGetMapPhysicalAddress(Args.Offset, out PA)) { - long va = args.Offset + args.BufferOffset; + long VA = Args.Offset + Args.BufferOffset; - pa += args.BufferOffset; + PA += Args.BufferOffset; - if (asCtx.Vmm.Map(pa, va, args.MappingSize) < 0) + if (ASCtx.Vmm.Map(PA, VA, Args.MappingSize) < 0) { - string msg = string.Format(mapErrorMsg, va, args.MappingSize); + string Msg = string.Format(MapErrorMsg, VA, Args.MappingSize); - Logger.PrintWarning(LogClass.ServiceNv, msg); + Logger.PrintWarning(LogClass.ServiceNv, Msg); return NvResult.InvalidInput; } @@ -198,117 +198,117 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS } else { - Logger.PrintWarning(LogClass.ServiceNv, $"Address 0x{args.Offset:x16} not mapped!"); + Logger.PrintWarning(LogClass.ServiceNv, $"Address 0x{Args.Offset:x16} not mapped!"); return NvResult.InvalidInput; } } } - pa = map.Address + args.BufferOffset; + PA = Map.Address + Args.BufferOffset; - long size = args.MappingSize; + long Size = Args.MappingSize; - if (size == 0) + if (Size == 0) { - size = (uint)map.Size; + Size = (uint)Map.Size; } - int result = NvResult.Success; + int Result = NvResult.Success; - lock (asCtx) + lock (ASCtx) { //Note: When the fixed offset flag is not set, //the Offset field holds the alignment size instead. - bool vaAllocated = (args.Flags & FlagFixedOffset) == 0; + bool VaAllocated = (Args.Flags & FlagFixedOffset) == 0; - if (!vaAllocated) + if (!VaAllocated) { - if (asCtx.ValidateFixedBuffer(args.Offset, size)) + if (ASCtx.ValidateFixedBuffer(Args.Offset, Size)) { - args.Offset = asCtx.Vmm.Map(pa, args.Offset, size); + Args.Offset = ASCtx.Vmm.Map(PA, Args.Offset, Size); } else { - string msg = string.Format(mapErrorMsg, args.Offset, size); + string Msg = string.Format(MapErrorMsg, Args.Offset, Size); - Logger.PrintWarning(LogClass.ServiceNv, msg); + Logger.PrintWarning(LogClass.ServiceNv, Msg); - result = NvResult.InvalidInput; + Result = NvResult.InvalidInput; } } else { - args.Offset = asCtx.Vmm.Map(pa, size); + Args.Offset = ASCtx.Vmm.Map(PA, Size); } - if (args.Offset < 0) + if (Args.Offset < 0) { - args.Offset = 0; + Args.Offset = 0; - Logger.PrintWarning(LogClass.ServiceNv, $"Failed to map size 0x{size:x16}!"); + Logger.PrintWarning(LogClass.ServiceNv, $"Failed to map size 0x{Size:x16}!"); - result = NvResult.InvalidInput; + Result = NvResult.InvalidInput; } else { - asCtx.AddMap(args.Offset, size, pa, vaAllocated); + ASCtx.AddMap(Args.Offset, Size, PA, VaAllocated); } } - MemoryHelper.Write(context.Memory, outputPosition, args); + MemoryHelper.Write(Context.Memory, OutputPosition, Args); - return result; + return Result; } - private static int GetVaRegions(ServiceCtx context) + private static int GetVaRegions(ServiceCtx Context) { - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; Logger.PrintStub(LogClass.ServiceNv, "Stubbed."); return NvResult.Success; } - private static int InitializeEx(ServiceCtx context) + private static int InitializeEx(ServiceCtx Context) { - long inputPosition = context.Request.GetBufferType0x21().Position; - long outputPosition = context.Request.GetBufferType0x22().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; + long OutputPosition = Context.Request.GetBufferType0x22().Position; Logger.PrintStub(LogClass.ServiceNv, "Stubbed."); return NvResult.Success; } - private static int Remap(ServiceCtx context, int cmd) + private static int Remap(ServiceCtx Context, int Cmd) { - int count = ((cmd >> 16) & 0xff) / 0x14; + int Count = ((Cmd >> 16) & 0xff) / 0x14; - long inputPosition = context.Request.GetBufferType0x21().Position; + long InputPosition = Context.Request.GetBufferType0x21().Position; - for (int index = 0; index < count; index++, inputPosition += 0x14) + for (int Index = 0; Index < Count; Index++, InputPosition += 0x14) { - NvGpuASRemap args = MemoryHelper.Read<NvGpuASRemap>(context.Memory, inputPosition); + NvGpuASRemap Args = MemoryHelper.Read<NvGpuASRemap>(Context.Memory, InputPosition); - NvGpuVmm vmm = GetASCtx(context).Vmm; + NvGpuVmm Vmm = GetASCtx(Context).Vmm; - NvMapHandle map = NvMapIoctl.GetNvMapWithFb(context, args.NvMapHandle); + NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle); - if (map == null) + if (Map == null) { - Logger.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{args.NvMapHandle:x8}!"); + Logger.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{Args.NvMapHandle:x8}!"); return NvResult.InvalidInput; } - long result = vmm.Map(map.Address, (long)(uint)args.Offset << 16, - (long)(uint)args.Pages << 16); + long Result = Vmm.Map(Map.Address, (long)(uint)Args.Offset << 16, + (long)(uint)Args.Pages << 16); - if (result < 0) + if (Result < 0) { Logger.PrintWarning(LogClass.ServiceNv, - $"Page 0x{args.Offset:x16} size 0x{args.Pages:x16} not allocated!"); + $"Page 0x{Args.Offset:x16} size 0x{Args.Pages:x16} not allocated!"); return NvResult.InvalidInput; } @@ -317,14 +317,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS return NvResult.Success; } - public static NvGpuASCtx GetASCtx(ServiceCtx context) + public static NvGpuASCtx GetASCtx(ServiceCtx Context) { - return _asCtxs.GetOrAdd(context.Process, (key) => new NvGpuASCtx(context)); + return ASCtxs.GetOrAdd(Context.Process, (Key) => new NvGpuASCtx(Context)); } - public static void UnloadProcess(KProcess process) + public static void UnloadProcess(KProcess Process) { - _asCtxs.TryRemove(process, out _); + ASCtxs.TryRemove(Process, out _); } } }
\ No newline at end of file |
