2018-02-04 18:08:20 -05:00
|
|
|
using ChocolArm64.Memory;
|
2018-03-19 14:58:46 -04:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
2018-02-20 15:09:23 -05:00
|
|
|
using Ryujinx.Core.OsHle.Ipc;
|
|
|
|
using Ryujinx.Core.OsHle.Utilities;
|
|
|
|
using Ryujinx.Graphics.Gpu;
|
2018-02-04 18:08:20 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2018-04-04 20:01:36 -04:00
|
|
|
using System.IO;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-20 16:00:00 -04:00
|
|
|
namespace Ryujinx.Core.OsHle.Services.Nv
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-19 14:58:46 -04:00
|
|
|
class ServiceNvDrv : IpcService, IDisposable
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-24 23:34:16 -05:00
|
|
|
private delegate long ServiceProcessIoctl(ServiceCtx Context);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-02-24 23:34:16 -05:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private Dictionary<(string, int), ServiceProcessIoctl> IoctlCmds;
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public static GlobalStateTable Fds { get; private set; }
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public static GlobalStateTable NvMaps { get; private set; }
|
|
|
|
public static GlobalStateTable NvMapsById { get; private set; }
|
2018-03-20 11:18:25 -04:00
|
|
|
public static GlobalStateTable NvMapsFb { get; private set; }
|
2018-03-19 14:58:46 -04:00
|
|
|
|
|
|
|
private KEvent Event;
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2018-02-24 23:34:16 -05:00
|
|
|
public ServiceNvDrv()
|
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 0, Open },
|
|
|
|
{ 1, Ioctl },
|
|
|
|
{ 2, Close },
|
|
|
|
{ 3, Initialize },
|
|
|
|
{ 4, QueryEvent },
|
|
|
|
{ 8, SetClientPid },
|
|
|
|
};
|
2018-03-12 00:04:52 -04:00
|
|
|
|
|
|
|
IoctlCmds = new Dictionary<(string, int), ServiceProcessIoctl>()
|
|
|
|
{
|
|
|
|
{ ("/dev/nvhost-as-gpu", 0x4101), NvGpuAsIoctlBindChannel },
|
|
|
|
{ ("/dev/nvhost-as-gpu", 0x4102), NvGpuAsIoctlAllocSpace },
|
|
|
|
{ ("/dev/nvhost-as-gpu", 0x4106), NvGpuAsIoctlMapBufferEx },
|
|
|
|
{ ("/dev/nvhost-as-gpu", 0x4108), NvGpuAsIoctlGetVaRegions },
|
|
|
|
{ ("/dev/nvhost-as-gpu", 0x4109), NvGpuAsIoctlInitializeEx },
|
2018-04-04 20:01:36 -04:00
|
|
|
{ ("/dev/nvhost-as-gpu", 0x4114), NvGpuAsIoctlRemap },
|
2018-03-12 00:04:52 -04:00
|
|
|
{ ("/dev/nvhost-ctrl", 0x001b), NvHostIoctlCtrlGetConfig },
|
|
|
|
{ ("/dev/nvhost-ctrl", 0x001d), NvHostIoctlCtrlEventWait },
|
|
|
|
{ ("/dev/nvhost-ctrl-gpu", 0x4701), NvGpuIoctlZcullGetCtxSize },
|
|
|
|
{ ("/dev/nvhost-ctrl-gpu", 0x4702), NvGpuIoctlZcullGetInfo },
|
2018-04-05 09:18:13 -04:00
|
|
|
{ ("/dev/nvhost-ctrl-gpu", 0x4703), NvGpuIoctlZbcSetTable },
|
2018-03-12 00:04:52 -04:00
|
|
|
{ ("/dev/nvhost-ctrl-gpu", 0x4705), NvGpuIoctlGetCharacteristics },
|
|
|
|
{ ("/dev/nvhost-ctrl-gpu", 0x4706), NvGpuIoctlGetTpcMasks },
|
|
|
|
{ ("/dev/nvhost-ctrl-gpu", 0x4714), NvGpuIoctlZbcGetActiveSlotMask },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x4714), NvMapIoctlChannelSetUserData },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x4801), NvMapIoctlChannelSetNvMap },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x4808), NvMapIoctlChannelSubmitGpFifo },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x4809), NvMapIoctlChannelAllocObjCtx },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x480b), NvMapIoctlChannelZcullBind },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x480c), NvMapIoctlChannelSetErrorNotifier },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x480d), NvMapIoctlChannelSetPriority },
|
|
|
|
{ ("/dev/nvhost-gpu", 0x481a), NvMapIoctlChannelAllocGpFifoEx2 },
|
|
|
|
{ ("/dev/nvmap", 0x0101), NvMapIocCreate },
|
|
|
|
{ ("/dev/nvmap", 0x0103), NvMapIocFromId },
|
|
|
|
{ ("/dev/nvmap", 0x0104), NvMapIocAlloc },
|
|
|
|
{ ("/dev/nvmap", 0x0105), NvMapIocFree },
|
|
|
|
{ ("/dev/nvmap", 0x0109), NvMapIocParam },
|
|
|
|
{ ("/dev/nvmap", 0x010e), NvMapIocGetId },
|
|
|
|
};
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
Event = new KEvent();
|
|
|
|
}
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
static ServiceNvDrv()
|
|
|
|
{
|
|
|
|
Fds = new GlobalStateTable();
|
|
|
|
|
|
|
|
NvMaps = new GlobalStateTable();
|
|
|
|
NvMapsById = new GlobalStateTable();
|
2018-03-20 11:18:25 -04:00
|
|
|
NvMapsFb = new GlobalStateTable();
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public long Open(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long NamePtr = Context.Request.SendBuff[0].Position;
|
|
|
|
|
|
|
|
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, NamePtr);
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
int Fd = Fds.Add(Context.Process, new NvFd(Name));
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Context.ResponseData.Write(Fd);
|
|
|
|
Context.ResponseData.Write(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public long Ioctl(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
int Fd = Context.RequestData.ReadInt32();
|
|
|
|
int Cmd = Context.RequestData.ReadInt32() & 0xffff;
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvFd FdData = Fds.GetData<NvFd>(Context.Process, Fd);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Context.ResponseData.Write(0);
|
|
|
|
|
2018-02-24 23:34:16 -05:00
|
|
|
if (IoctlCmds.TryGetValue((FdData.Name, Cmd), out ServiceProcessIoctl ProcReq))
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
return ProcReq(Context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotImplementedException($"{FdData.Name} {Cmd:x4}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public long Close(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
int Fd = Context.RequestData.ReadInt32();
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
Fds.Delete(Context.Process, Fd);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Context.ResponseData.Write(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public long Initialize(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long TransferMemSize = Context.RequestData.ReadInt64();
|
|
|
|
int TransferMemHandle = Context.Request.HandleDesc.ToCopy[0];
|
|
|
|
|
|
|
|
Context.ResponseData.Write(0);
|
|
|
|
|
2018-03-20 11:18:25 -04:00
|
|
|
NvMapsFb.Add(Context.Process, 0, new NvMapFb());
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public long QueryEvent(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
int Fd = Context.RequestData.ReadInt32();
|
|
|
|
int EventId = Context.RequestData.ReadInt32();
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
//TODO: Use Fd/EventId, different channels have different events.
|
|
|
|
int Handle = Context.Process.HandleTable.OpenHandle(Event);
|
|
|
|
|
|
|
|
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Context.ResponseData.Write(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public long SetClientPid(ServiceCtx Context)
|
2018-02-06 18:28:32 -05:00
|
|
|
{
|
|
|
|
long Pid = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
Context.ResponseData.Write(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuAsIoctlBindChannel(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
int Fd = Context.Memory.ReadInt32(Position);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuAsIoctlAllocSpace(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int Pages = Reader.ReadInt32();
|
|
|
|
int PageSize = Reader.ReadInt32();
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int Padding = Reader.ReadInt32();
|
|
|
|
long Align = Reader.ReadInt64();
|
|
|
|
|
|
|
|
if ((Flags & 1) != 0)
|
|
|
|
{
|
2018-02-20 15:09:23 -05:00
|
|
|
Align = Context.Ns.Gpu.ReserveMemory(Align, (long)Pages * PageSize, 1);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-20 15:09:23 -05:00
|
|
|
Align = Context.Ns.Gpu.ReserveMemory((long)Pages * PageSize, Align);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Context.Memory.WriteInt64(Position + 0x10, Align);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuAsIoctlMapBufferEx(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int Kind = Reader.ReadInt32();
|
|
|
|
int Handle = Reader.ReadInt32();
|
2018-04-04 20:01:36 -04:00
|
|
|
int PageSize = Reader.ReadInt32();
|
2018-02-04 18:08:20 -05:00
|
|
|
long BuffAddr = Reader.ReadInt64();
|
|
|
|
long MapSize = Reader.ReadInt64();
|
|
|
|
long Offset = Reader.ReadInt64();
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Handle == 0)
|
|
|
|
{
|
2018-03-20 11:18:25 -04:00
|
|
|
//This is used to store offsets for the Framebuffer(s);
|
|
|
|
NvMapFb MapFb = (NvMapFb)NvMapsFb.GetData(Context.Process, 0);
|
|
|
|
|
|
|
|
MapFb.AddBufferOffset(BuffAddr);
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvMap Map = NvMaps.GetData<NvMap>(Context.Process, Handle);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Map == null)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
Logging.Warn($"Trying to use invalid NvMap Handle {Handle}!");
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return -1; //TODO: Corrent error code.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Flags & 1) != 0)
|
|
|
|
{
|
2018-03-20 11:18:25 -04:00
|
|
|
Offset = Context.Ns.Gpu.MapMemory(Map.CpuAddress, Offset, Map.Size);
|
2018-03-12 00:04:52 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-20 11:18:25 -04:00
|
|
|
Offset = Context.Ns.Gpu.MapMemory(Map.CpuAddress, Map.Size);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Context.Memory.WriteInt64(Position + 0x20, Offset);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuAsIoctlGetVaRegions(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position);
|
|
|
|
|
|
|
|
long Unused = Reader.ReadInt64();
|
|
|
|
int BuffSize = Reader.ReadInt32();
|
|
|
|
int Padding = Reader.ReadInt32();
|
|
|
|
|
|
|
|
BuffSize = 0x30;
|
|
|
|
|
|
|
|
Writer.WriteInt64(Unused);
|
|
|
|
Writer.WriteInt32(BuffSize);
|
|
|
|
Writer.WriteInt32(Padding);
|
|
|
|
|
|
|
|
Writer.WriteInt64(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt64(0);
|
|
|
|
|
|
|
|
Writer.WriteInt64(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt64(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuAsIoctlInitializeEx(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int BigPageSize = Reader.ReadInt32();
|
|
|
|
int AsFd = Reader.ReadInt32();
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int Reserved = Reader.ReadInt32();
|
|
|
|
long Unknown10 = Reader.ReadInt64();
|
|
|
|
long Unknown18 = Reader.ReadInt64();
|
|
|
|
long Unknown20 = Reader.ReadInt64();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:01:36 -04:00
|
|
|
private long NvGpuAsIoctlRemap(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
Context.RequestData.BaseStream.Seek(-4, SeekOrigin.Current);
|
|
|
|
|
|
|
|
int Cmd = Context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
int Size = (Cmd >> 16) & 0xff;
|
|
|
|
|
|
|
|
int Count = Size / 0x18;
|
|
|
|
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
for (int Index = 0; Index < Count; Index++)
|
|
|
|
{
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int Kind = Reader.ReadInt32();
|
|
|
|
int Handle = Reader.ReadInt32();
|
|
|
|
int Padding = Reader.ReadInt32();
|
|
|
|
int Offset = Reader.ReadInt32();
|
|
|
|
int Pages = Reader.ReadInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvHostIoctlCtrlGetConfig(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position + 0x82);
|
|
|
|
|
|
|
|
for (int Index = 0; Index < 0x101; Index++)
|
|
|
|
{
|
|
|
|
Writer.WriteByte(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvHostIoctlCtrlEventWait(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int SyncPtId = Reader.ReadInt32();
|
|
|
|
int Threshold = Reader.ReadInt32();
|
|
|
|
int Timeout = Reader.ReadInt32();
|
|
|
|
int Value = Reader.ReadInt32();
|
|
|
|
|
|
|
|
Context.Memory.WriteInt32(Position + 0xc, 0xcafe);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuIoctlZcullGetCtxSize(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Context.Memory.WriteInt32(Position, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuIoctlZcullGetInfo(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position);
|
|
|
|
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:18:13 -04:00
|
|
|
private long NvGpuIoctlZbcSetTable(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int ColorDs = Reader.ReadInt32();
|
|
|
|
int ColorL2 = Reader.ReadInt32();
|
|
|
|
int Depth = Reader.ReadInt32();
|
|
|
|
int Format = Reader.ReadInt32();
|
|
|
|
int Type = Reader.ReadInt32();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuIoctlGetCharacteristics(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position);
|
|
|
|
|
|
|
|
//Note: We should just ignore the BuffAddr, because official code
|
|
|
|
//does __memcpy_device from Position + 0x10 to BuffAddr.
|
|
|
|
long BuffSize = Reader.ReadInt64();
|
|
|
|
long BuffAddr = Reader.ReadInt64();
|
|
|
|
|
|
|
|
BuffSize = 0xa0;
|
|
|
|
|
|
|
|
Writer.WriteInt64(BuffSize);
|
|
|
|
Writer.WriteInt64(BuffAddr);
|
|
|
|
Writer.WriteInt32(0x120); //NVGPU_GPU_ARCH_GM200
|
|
|
|
Writer.WriteInt32(0xb); //NVGPU_GPU_IMPL_GM20B
|
|
|
|
Writer.WriteInt32(0xa1);
|
|
|
|
Writer.WriteInt32(1);
|
|
|
|
Writer.WriteInt64(0x40000);
|
|
|
|
Writer.WriteInt64(0);
|
|
|
|
Writer.WriteInt32(2);
|
|
|
|
Writer.WriteInt32(0x20); //NVGPU_GPU_BUS_TYPE_AXI
|
|
|
|
Writer.WriteInt32(0x20000);
|
|
|
|
Writer.WriteInt32(0x20000);
|
|
|
|
Writer.WriteInt32(0x1b);
|
|
|
|
Writer.WriteInt32(0x30000);
|
|
|
|
Writer.WriteInt32(1);
|
|
|
|
Writer.WriteInt32(0x503);
|
|
|
|
Writer.WriteInt32(0x503);
|
|
|
|
Writer.WriteInt32(0x80);
|
|
|
|
Writer.WriteInt32(0x28);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt64(0x55);
|
|
|
|
Writer.WriteInt32(0x902d); //FERMI_TWOD_A
|
|
|
|
Writer.WriteInt32(0xb197); //MAXWELL_B
|
|
|
|
Writer.WriteInt32(0xb1c0); //MAXWELL_COMPUTE_B
|
|
|
|
Writer.WriteInt32(0xb06f); //MAXWELL_CHANNEL_GPFIFO_A
|
|
|
|
Writer.WriteInt32(0xa140); //KEPLER_INLINE_TO_MEMORY_B
|
|
|
|
Writer.WriteInt32(0xb0b5); //MAXWELL_DMA_COPY_A
|
|
|
|
Writer.WriteInt32(1);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(2);
|
|
|
|
Writer.WriteInt32(1);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(1);
|
|
|
|
Writer.WriteInt32(0x21d70);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteByte((byte)'g');
|
|
|
|
Writer.WriteByte((byte)'m');
|
|
|
|
Writer.WriteByte((byte)'2');
|
|
|
|
Writer.WriteByte((byte)'0');
|
|
|
|
Writer.WriteByte((byte)'b');
|
|
|
|
Writer.WriteByte((byte)'\0');
|
|
|
|
Writer.WriteByte((byte)'\0');
|
|
|
|
Writer.WriteByte((byte)'\0');
|
|
|
|
Writer.WriteInt64(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuIoctlGetTpcMasks(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int MaskBuffSize = Reader.ReadInt32();
|
|
|
|
int Reserved = Reader.ReadInt32();
|
|
|
|
long MaskBuffAddr = Reader.ReadInt64();
|
|
|
|
long Unknown = Reader.ReadInt64();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvGpuIoctlZbcGetActiveSlotMask(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
Context.Memory.WriteInt32(Position + 0, 7);
|
|
|
|
Context.Memory.WriteInt32(Position + 4, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelSetUserData(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelSetNvMap(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
int Fd = Context.Memory.ReadInt32(Position);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelSubmitGpFifo(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position + 0x10);
|
|
|
|
|
|
|
|
long GpFifo = Reader.ReadInt64();
|
|
|
|
int Count = Reader.ReadInt32();
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int FenceId = Reader.ReadInt32();
|
|
|
|
int FenceVal = Reader.ReadInt32();
|
|
|
|
|
|
|
|
for (int Index = 0; Index < Count; Index++)
|
|
|
|
{
|
|
|
|
long GpFifoHdr = Reader.ReadInt64();
|
|
|
|
|
|
|
|
long GpuAddr = GpFifoHdr & 0xffffffffff;
|
|
|
|
|
|
|
|
int Size = (int)(GpFifoHdr >> 40) & 0x7ffffc;
|
|
|
|
|
2018-02-20 15:09:23 -05:00
|
|
|
long CpuAddr = Context.Ns.Gpu.GetCpuAddr(GpuAddr);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
if (CpuAddr != -1)
|
|
|
|
{
|
|
|
|
byte[] Data = AMemoryHelper.ReadBytes(Context.Memory, CpuAddr, Size);
|
|
|
|
|
|
|
|
NsGpuPBEntry[] PushBuffer = NsGpuPBEntry.DecodePushBuffer(Data);
|
|
|
|
|
2018-02-20 15:09:23 -05:00
|
|
|
Context.Ns.Gpu.ProcessPushBuffer(PushBuffer, Context.Memory);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelAllocObjCtx(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
int ClassNum = Context.Memory.ReadInt32(Position + 0);
|
|
|
|
int Flags = Context.Memory.ReadInt32(Position + 4);
|
|
|
|
|
|
|
|
Context.Memory.WriteInt32(Position + 8, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelZcullBind(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
long GpuVa = Reader.ReadInt64();
|
|
|
|
int Mode = Reader.ReadInt32();
|
|
|
|
int Padding = Reader.ReadInt32();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelSetErrorNotifier(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
long Offset = Reader.ReadInt64();
|
|
|
|
long Size = Reader.ReadInt64();
|
|
|
|
int Mem = Reader.ReadInt32();
|
|
|
|
int Padding = Reader.ReadInt32();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelSetPriority(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
int Priority = Context.Memory.ReadInt32(Position);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIoctlChannelAllocGpFifoEx2(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-10 18:39:16 -05:00
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position + 0xc);
|
|
|
|
|
|
|
|
int Count = Reader.ReadInt32();
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int Unknown8 = Reader.ReadInt32();
|
|
|
|
long Fence = Reader.ReadInt64();
|
|
|
|
int Unknown14 = Reader.ReadInt32();
|
|
|
|
int Unknown18 = Reader.ReadInt32();
|
|
|
|
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
Writer.WriteInt32(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIocCreate(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
int Size = Context.Memory.ReadInt32(Position);
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
NvMap Map = new NvMap() { Size = Size };
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
Map.Handle = NvMaps.Add(Context.Process, Map);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
Map.Id = NvMapsById.Add(Context.Process, Map);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
Context.Memory.WriteInt32(Position + 4, Map.Handle);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
Logging.Info($"NvMap {Map.Id} created with size {Size:x8}!");
|
2018-03-03 22:06:44 -05:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIocFromId(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
int Id = Context.Memory.ReadInt32(Position);
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvMap Map = NvMapsById.GetData<NvMap>(Context.Process, Id);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Map == null)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
Logging.Warn($"Trying to use invalid NvMap Id {Id}!");
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return -1; //TODO: Corrent error code.
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
Context.Memory.WriteInt32(Position + 4, Map.Handle);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIocAlloc(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int Handle = Reader.ReadInt32();
|
|
|
|
int HeapMask = Reader.ReadInt32();
|
|
|
|
int Flags = Reader.ReadInt32();
|
|
|
|
int Align = Reader.ReadInt32();
|
|
|
|
byte Kind = (byte)Reader.ReadInt64();
|
|
|
|
long Addr = Reader.ReadInt64();
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvMap Map = NvMaps.GetData<NvMap>(Context.Process, Handle);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Map == null)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
Logging.Warn($"Trying to use invalid NvMap Handle {Handle}!");
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return -1; //TODO: Corrent error code.
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-03-20 11:18:25 -04:00
|
|
|
Map.CpuAddress = Addr;
|
2018-03-12 00:04:52 -04:00
|
|
|
Map.Align = Align;
|
|
|
|
Map.Kind = Kind;
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIocFree(ServiceCtx Context)
|
2018-03-06 15:27:50 -05:00
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
MemWriter Writer = new MemWriter(Context.Memory, Position + 8);
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
int Handle = Reader.ReadInt32();
|
|
|
|
int Padding = Reader.ReadInt32();
|
2018-03-06 15:27:50 -05:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvMap Map = NvMaps.GetData<NvMap>(Context.Process, Handle);
|
2018-03-12 00:04:52 -04:00
|
|
|
|
|
|
|
if (Map == null)
|
|
|
|
{
|
|
|
|
Logging.Warn($"Trying to use invalid NvMap Handle {Handle}!");
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return -1; //TODO: Corrent error code.
|
|
|
|
}
|
2018-03-06 15:27:50 -05:00
|
|
|
|
|
|
|
Writer.WriteInt64(0);
|
2018-03-12 00:04:52 -04:00
|
|
|
Writer.WriteInt32(Map.Size);
|
2018-03-06 15:27:50 -05:00
|
|
|
Writer.WriteInt32(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIocParam(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
MemReader Reader = new MemReader(Context.Memory, Position);
|
|
|
|
|
|
|
|
int Handle = Reader.ReadInt32();
|
|
|
|
int Param = Reader.ReadInt32();
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvMap Map = NvMaps.GetData<NvMap>(Context.Process, Handle);
|
2018-03-12 00:04:52 -04:00
|
|
|
|
|
|
|
if (Map == null)
|
|
|
|
{
|
|
|
|
Logging.Warn($"Trying to use invalid NvMap Handle {Handle}!");
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return -1; //TODO: Corrent error code.
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
int Response = 0;
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
switch (Param)
|
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
case 1: Response = Map.Size; break;
|
|
|
|
case 2: Response = Map.Align; break;
|
|
|
|
case 4: Response = 0x40000000; break;
|
|
|
|
case 5: Response = Map.Kind; break;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Context.Memory.WriteInt32(Position + 8, Response);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
private long NvMapIocGetId(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long Position = Context.Request.GetSendBuffPtr();
|
|
|
|
|
|
|
|
int Handle = Context.Memory.ReadInt32(Position + 4);
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
NvMap Map = NvMaps.GetData<NvMap>(Context.Process, Handle);
|
2018-03-12 00:04:52 -04:00
|
|
|
|
|
|
|
if (Map == null)
|
|
|
|
{
|
|
|
|
Logging.Warn($"Trying to use invalid NvMap Handle {Handle}!");
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
return -1; //TODO: Corrent error code.
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
Context.Memory.WriteInt32(Position, Map.Id);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public void Dispose()
|
2018-03-12 00:04:52 -04:00
|
|
|
{
|
2018-03-19 14:58:46 -04:00
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool Disposing)
|
|
|
|
{
|
|
|
|
if (Disposing)
|
|
|
|
{
|
|
|
|
Event.Dispose();
|
|
|
|
}
|
2018-03-12 00:04:52 -04:00
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|