2020-05-01 14:18:42 -07:00
|
|
|
|
using Ryujinx.Common.Logging;
|
2019-11-02 15:47:56 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2020-05-01 14:18:42 -07:00
|
|
|
|
using System.Reflection;
|
2019-11-02 15:47:56 -07:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices
|
|
|
|
|
{
|
|
|
|
|
abstract class NvDeviceFile
|
|
|
|
|
{
|
2019-10-12 23:02:07 -07:00
|
|
|
|
public readonly ServiceCtx Context;
|
2022-02-09 12:18:07 -08:00
|
|
|
|
public readonly ulong Owner;
|
2019-11-02 15:47:56 -07:00
|
|
|
|
|
2020-07-11 20:07:01 -07:00
|
|
|
|
public string Path;
|
|
|
|
|
|
2022-02-09 12:18:07 -08:00
|
|
|
|
public NvDeviceFile(ServiceCtx context, ulong owner)
|
2019-11-02 15:47:56 -07:00
|
|
|
|
{
|
2019-10-12 23:02:07 -07:00
|
|
|
|
Context = context;
|
2020-12-01 15:23:43 -08:00
|
|
|
|
Owner = owner;
|
2019-11-02 15:47:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
|
|
|
|
{
|
|
|
|
|
eventHandle = 0;
|
|
|
|
|
|
|
|
|
|
return NvInternalResult.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 10:19:10 -08:00
|
|
|
|
public virtual NvInternalResult MapSharedMemory(int sharedMemoryHandle, uint argument)
|
2019-11-02 15:47:56 -07:00
|
|
|
|
{
|
2020-12-03 10:19:10 -08:00
|
|
|
|
// Close shared memory immediately as we don't use it.
|
|
|
|
|
Context.Device.System.KernelContext.Syscall.CloseHandle(sharedMemoryHandle);
|
|
|
|
|
|
2019-11-02 15:47:56 -07:00
|
|
|
|
return NvInternalResult.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual NvInternalResult Ioctl(NvIoctl command, Span<byte> arguments)
|
|
|
|
|
{
|
|
|
|
|
return NvInternalResult.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
|
|
|
|
|
{
|
|
|
|
|
return NvInternalResult.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual NvInternalResult Ioctl3(NvIoctl command, Span<byte> arguments, Span<byte> inlineOutBuffer)
|
|
|
|
|
{
|
|
|
|
|
return NvInternalResult.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected delegate NvInternalResult IoctlProcessor<T>(ref T arguments);
|
|
|
|
|
protected delegate NvInternalResult IoctlProcessorSpan<T>(Span<T> arguments);
|
|
|
|
|
protected delegate NvInternalResult IoctlProcessorInline<T, T1>(ref T arguments, ref T1 inlineData);
|
|
|
|
|
protected delegate NvInternalResult IoctlProcessorInlineSpan<T, T1>(ref T arguments, Span<T1> inlineData);
|
|
|
|
|
|
2020-05-01 14:18:42 -07:00
|
|
|
|
private static NvInternalResult PrintResult(MethodInfo info, NvInternalResult result)
|
|
|
|
|
{
|
2020-08-03 16:32:53 -07:00
|
|
|
|
Logger.Debug?.Print(LogClass.ServiceNv, $"{info.Name} returned result {result}");
|
2020-05-01 14:18:42 -07:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 15:47:56 -07:00
|
|
|
|
protected static NvInternalResult CallIoctlMethod<T>(IoctlProcessor<T> callback, Span<byte> arguments) where T : struct
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(arguments.Length == Unsafe.SizeOf<T>());
|
|
|
|
|
|
2020-05-01 14:18:42 -07:00
|
|
|
|
return PrintResult(callback.Method, callback(ref MemoryMarshal.Cast<byte, T>(arguments)[0]));
|
2019-11-02 15:47:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static NvInternalResult CallIoctlMethod<T, T1>(IoctlProcessorInline<T, T1> callback, Span<byte> arguments, Span<byte> inlineBuffer) where T : struct where T1 : struct
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(arguments.Length == Unsafe.SizeOf<T>());
|
|
|
|
|
Debug.Assert(inlineBuffer.Length == Unsafe.SizeOf<T1>());
|
|
|
|
|
|
2020-05-01 14:18:42 -07:00
|
|
|
|
return PrintResult(callback.Method, callback(ref MemoryMarshal.Cast<byte, T>(arguments)[0], ref MemoryMarshal.Cast<byte, T1>(inlineBuffer)[0]));
|
2019-11-02 15:47:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static NvInternalResult CallIoctlMethod<T>(IoctlProcessorSpan<T> callback, Span<byte> arguments) where T : struct
|
|
|
|
|
{
|
2020-05-01 14:18:42 -07:00
|
|
|
|
return PrintResult(callback.Method, callback(MemoryMarshal.Cast<byte, T>(arguments)));
|
2019-11-02 15:47:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static NvInternalResult CallIoctlMethod<T, T1>(IoctlProcessorInlineSpan<T, T1> callback, Span<byte> arguments, Span<byte> inlineBuffer) where T : struct where T1 : struct
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(arguments.Length == Unsafe.SizeOf<T>());
|
|
|
|
|
|
2020-05-01 14:18:42 -07:00
|
|
|
|
return PrintResult(callback.Method, callback(ref MemoryMarshal.Cast<byte, T>(arguments)[0], MemoryMarshal.Cast<byte, T1>(inlineBuffer)));
|
2019-11-02 15:47:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void Close();
|
|
|
|
|
}
|
|
|
|
|
}
|