Adjust naming conventions and general refactoring in HLE Project (#490)
* Rename enum fields
* Naming conventions
* Remove unneeded ".this"
* Remove unneeded semicolons
* Remove unused Usings
* Don't use var
* Remove unneeded enum underlying types
* Explicitly label class visibility
* Remove unneeded @ prefixes
* Remove unneeded commas
* Remove unneeded if expressions
* Method doesn't use unsafe code
* Remove unneeded casts
* Initialized objects don't need an empty constructor
* Remove settings from DotSettings
* Revert "Explicitly label class visibility"
This reverts commit ad5eb5787c
.
* Small changes
* Revert external enum renaming
* Changes from feedback
* Remove unneeded property setters
This commit is contained in:
parent
c86aacde76
commit
85dbb9559a
299 changed files with 12268 additions and 12276 deletions
|
@ -5,73 +5,73 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvGpuAS
|
|||
{
|
||||
class NvGpuASCtx
|
||||
{
|
||||
public NvGpuVmm Vmm { get; private set; }
|
||||
public NvGpuVmm Vmm { get; }
|
||||
|
||||
private class Range
|
||||
{
|
||||
public ulong Start { get; private set; }
|
||||
public ulong End { get; private set; }
|
||||
public ulong Start { get; }
|
||||
public ulong End { get; }
|
||||
|
||||
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; private set; }
|
||||
public bool VaAllocated { get; private set; }
|
||||
public long PhysicalAddress { get; }
|
||||
public bool VaAllocated { get; }
|
||||
|
||||
public MappedMemory(
|
||||
long Position,
|
||||
long Size,
|
||||
long PhysicalAddress,
|
||||
bool VaAllocated) : base(Position, Size)
|
||||
long position,
|
||||
long size,
|
||||
long physicalAddress,
|
||||
bool vaAllocated) : base(position, size)
|
||||
{
|
||||
this.PhysicalAddress = PhysicalAddress;
|
||||
this.VaAllocated = VaAllocated;
|
||||
PhysicalAddress = physicalAddress;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 _);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue