1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-14 11:16:39 +00:00
Ryujinx/Ryujinx.HLE/HOS/Services/Nv/NvHostChannel/NvHostChannelIoctl.cs
gdkchan 00579927e4
Better process implementation (#491)
* Initial implementation of KProcess

* Some improvements to the memory manager, implement back guest stack trace printing

* Better GetInfo implementation, improve checking in some places with information from process capabilities

* Allow the cpu to read/write from the correct memory locations for accesses crossing a page boundary

* Change long -> ulong for address/size on memory related methods to avoid unnecessary casts

* Attempt at implementing ldr:ro with new KProcess

* Allow BSS with size 0 on ldr:ro

* Add checking for memory block slab heap usage, return errors if full, exit gracefully

* Use KMemoryBlockSize const from KMemoryManager

* Allow all methods to read from non-contiguous locations

* Fix for TransactParcelAuto

* Address PR feedback, additionally fix some small issues related to the KIP loader and implement SVCs GetProcessId, GetProcessList, GetSystemInfo, CreatePort and ManageNamedPort

* Fix wrong check for source pages count from page list on MapPhysicalMemory

* Fix some issues with UnloadNro on ldr:ro
2018-11-28 20:18:09 -02:00

203 lines
No EOL
6.8 KiB
C#

using ChocolArm64.Memory;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Memory;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Services.Nv.NvGpuAS;
using System;
using System.Collections.Concurrent;
namespace Ryujinx.HLE.HOS.Services.Nv.NvHostChannel
{
class NvHostChannelIoctl
{
private class ChannelsPerProcess
{
public ConcurrentDictionary<NvChannelName, NvChannel> Channels { get; private set; }
public ChannelsPerProcess()
{
Channels = new ConcurrentDictionary<NvChannelName, NvChannel>();
Channels.TryAdd(NvChannelName.Gpu, new NvChannel());
}
}
private static ConcurrentDictionary<KProcess, ChannelsPerProcess> Channels;
static NvHostChannelIoctl()
{
Channels = new ConcurrentDictionary<KProcess, ChannelsPerProcess>();
}
public static int ProcessIoctlGpu(ServiceCtx Context, int Cmd)
{
return ProcessIoctl(Context, NvChannelName.Gpu, Cmd);
}
public static int ProcessIoctl(ServiceCtx Context, NvChannelName Channel, int Cmd)
{
switch (Cmd & 0xffff)
{
case 0x4714: return SetUserData (Context);
case 0x4801: return SetNvMap (Context);
case 0x4803: return SetTimeout (Context, Channel);
case 0x4808: return SubmitGpfifo (Context);
case 0x4809: return AllocObjCtx (Context);
case 0x480b: return ZcullBind (Context);
case 0x480c: return SetErrorNotifier (Context);
case 0x480d: return SetPriority (Context);
case 0x481a: return AllocGpfifoEx2 (Context);
case 0x481b: return KickoffPbWithAttr(Context);
}
throw new NotImplementedException(Cmd.ToString("x8"));
}
private static int SetUserData(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int SetNvMap(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int SetTimeout(ServiceCtx Context, NvChannelName Channel)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
GetChannel(Context, Channel).Timeout = Context.Memory.ReadInt32(InputPosition);
return NvResult.Success;
}
private static int SubmitGpfifo(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
NvHostChannelSubmitGpfifo Args = MemoryHelper.Read<NvHostChannelSubmitGpfifo>(Context.Memory, InputPosition);
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;;
for (int Index = 0; Index < Args.NumEntries; Index++)
{
long Gpfifo = Context.Memory.ReadInt64(InputPosition + 0x18 + Index * 8);
PushGpfifo(Context, Vmm, Gpfifo);
}
Args.SyncptId = 0;
Args.SyncptValue = 0;
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
return NvResult.Success;
}
private static int AllocObjCtx(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int ZcullBind(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int SetErrorNotifier(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int SetPriority(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int AllocGpfifoEx2(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
private static int KickoffPbWithAttr(ServiceCtx Context)
{
long InputPosition = Context.Request.GetBufferType0x21().Position;
long OutputPosition = Context.Request.GetBufferType0x22().Position;
NvHostChannelSubmitGpfifo Args = MemoryHelper.Read<NvHostChannelSubmitGpfifo>(Context.Memory, InputPosition);
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;;
for (int Index = 0; Index < Args.NumEntries; Index++)
{
long Gpfifo = Context.Memory.ReadInt64(Args.Address + Index * 8);
PushGpfifo(Context, Vmm, Gpfifo);
}
Args.SyncptId = 0;
Args.SyncptValue = 0;
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
return NvResult.Success;
}
private static void PushGpfifo(ServiceCtx Context, NvGpuVmm Vmm, long Gpfifo)
{
Context.Device.Gpu.Pusher.Push(Vmm, Gpfifo);
}
public static NvChannel GetChannel(ServiceCtx Context, NvChannelName Channel)
{
ChannelsPerProcess Cpp = Channels.GetOrAdd(Context.Process, (Key) =>
{
return new ChannelsPerProcess();
});
return Cpp.Channels[Channel];
}
public static void UnloadProcess(KProcess Process)
{
Channels.TryRemove(Process, out _);
}
}
}