1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-05 02:42:01 +00:00
Ryujinx/Ryujinx.HLE/HOS/Services/Nv/NvHostChannel/NvHostChannelIoctl.cs

203 lines
6.8 KiB
C#
Raw Normal View History

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());
}
}
2018-12-01 20:01:59 +00:00
private static ConcurrentDictionary<KProcess, ChannelsPerProcess> _channels;
static NvHostChannelIoctl()
{
2018-12-01 20:01:59 +00:00
_channels = new ConcurrentDictionary<KProcess, ChannelsPerProcess>();
}
2018-12-01 20:01:59 +00:00
public static int ProcessIoctlGpu(ServiceCtx context, int cmd)
{
2018-12-01 20:01:59 +00:00
return ProcessIoctl(context, NvChannelName.Gpu, cmd);
}
2018-12-01 20:01:59 +00:00
public static int ProcessIoctl(ServiceCtx context, NvChannelName channel, int cmd)
{
2018-12-01 20:01:59 +00:00
switch (cmd & 0xffff)
{
2018-12-01 20:01:59 +00:00
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);
}
2018-12-01 20:01:59 +00:00
throw new NotImplementedException(cmd.ToString("x8"));
}
2018-12-01 20:01:59 +00:00
private static int SetUserData(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int SetNvMap(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int SetTimeout(ServiceCtx context, NvChannelName channel)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
2018-12-01 20:01:59 +00:00
GetChannel(context, channel).Timeout = context.Memory.ReadInt32(inputPosition);
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int SubmitGpfifo(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
2018-12-01 20:01:59 +00:00
NvHostChannelSubmitGpfifo args = MemoryHelper.Read<NvHostChannelSubmitGpfifo>(context.Memory, inputPosition);
2018-12-01 20:01:59 +00:00
NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm;;
2018-12-01 20:01:59 +00:00
for (int index = 0; index < args.NumEntries; index++)
{
2018-12-01 20:01:59 +00:00
long gpfifo = context.Memory.ReadInt64(inputPosition + 0x18 + index * 8);
2018-12-01 20:01:59 +00:00
PushGpfifo(context, vmm, gpfifo);
}
2018-12-01 20:01:59 +00:00
args.SyncptId = 0;
args.SyncptValue = 0;
2018-12-01 20:01:59 +00:00
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int AllocObjCtx(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int ZcullBind(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int SetErrorNotifier(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int SetPriority(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int AllocGpfifoEx2(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
Logger.PrintStub(LogClass.ServiceNv, "Stubbed.");
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static int KickoffPbWithAttr(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long inputPosition = context.Request.GetBufferType0x21().Position;
long outputPosition = context.Request.GetBufferType0x22().Position;
2018-12-01 20:01:59 +00:00
NvHostChannelSubmitGpfifo args = MemoryHelper.Read<NvHostChannelSubmitGpfifo>(context.Memory, inputPosition);
2018-12-01 20:01:59 +00:00
NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm;;
2018-12-01 20:01:59 +00:00
for (int index = 0; index < args.NumEntries; index++)
{
2018-12-01 20:01:59 +00:00
long gpfifo = context.Memory.ReadInt64(args.Address + index * 8);
2018-12-01 20:01:59 +00:00
PushGpfifo(context, vmm, gpfifo);
}
2018-12-01 20:01:59 +00:00
args.SyncptId = 0;
args.SyncptValue = 0;
2018-12-01 20:01:59 +00:00
MemoryHelper.Write(context.Memory, outputPosition, args);
return NvResult.Success;
}
2018-12-01 20:01:59 +00:00
private static void PushGpfifo(ServiceCtx context, NvGpuVmm vmm, long gpfifo)
{
2018-12-01 20:01:59 +00:00
context.Device.Gpu.Pusher.Push(vmm, gpfifo);
}
2018-12-01 20:01:59 +00:00
public static NvChannel GetChannel(ServiceCtx context, NvChannelName channel)
{
2018-12-01 20:01:59 +00:00
ChannelsPerProcess cpp = _channels.GetOrAdd(context.Process, (key) =>
{
return new ChannelsPerProcess();
});
2018-12-01 20:01:59 +00:00
return cpp.Channels[channel];
}
2018-12-01 20:01:59 +00:00
public static void UnloadProcess(KProcess process)
{
2018-12-01 20:01:59 +00:00
_channels.TryRemove(process, out _);
}
}
}