NvDeviceFile.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Ryujinx.HLE.HOS.Kernel.Memory;
  2. using Ryujinx.HLE.HOS.Kernel.Process;
  3. using System;
  4. using System.Diagnostics;
  5. using System.Runtime.CompilerServices;
  6. using System.Runtime.InteropServices;
  7. namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices
  8. {
  9. abstract class NvDeviceFile
  10. {
  11. public readonly ServiceCtx Context;
  12. public readonly KProcess Owner;
  13. public NvDeviceFile(ServiceCtx context)
  14. {
  15. Context = context;
  16. Owner = context.Process;
  17. }
  18. public virtual NvInternalResult QueryEvent(out int eventHandle, uint eventId)
  19. {
  20. eventHandle = 0;
  21. return NvInternalResult.NotImplemented;
  22. }
  23. public virtual NvInternalResult MapSharedMemory(KSharedMemory sharedMemory, uint argument)
  24. {
  25. return NvInternalResult.NotImplemented;
  26. }
  27. public virtual NvInternalResult Ioctl(NvIoctl command, Span<byte> arguments)
  28. {
  29. return NvInternalResult.NotImplemented;
  30. }
  31. public virtual NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
  32. {
  33. return NvInternalResult.NotImplemented;
  34. }
  35. public virtual NvInternalResult Ioctl3(NvIoctl command, Span<byte> arguments, Span<byte> inlineOutBuffer)
  36. {
  37. return NvInternalResult.NotImplemented;
  38. }
  39. protected delegate NvInternalResult IoctlProcessor<T>(ref T arguments);
  40. protected delegate NvInternalResult IoctlProcessorSpan<T>(Span<T> arguments);
  41. protected delegate NvInternalResult IoctlProcessorInline<T, T1>(ref T arguments, ref T1 inlineData);
  42. protected delegate NvInternalResult IoctlProcessorInlineSpan<T, T1>(ref T arguments, Span<T1> inlineData);
  43. protected static NvInternalResult CallIoctlMethod<T>(IoctlProcessor<T> callback, Span<byte> arguments) where T : struct
  44. {
  45. Debug.Assert(arguments.Length == Unsafe.SizeOf<T>());
  46. return callback(ref MemoryMarshal.Cast<byte, T>(arguments)[0]);
  47. }
  48. protected static NvInternalResult CallIoctlMethod<T, T1>(IoctlProcessorInline<T, T1> callback, Span<byte> arguments, Span<byte> inlineBuffer) where T : struct where T1 : struct
  49. {
  50. Debug.Assert(arguments.Length == Unsafe.SizeOf<T>());
  51. Debug.Assert(inlineBuffer.Length == Unsafe.SizeOf<T1>());
  52. return callback(ref MemoryMarshal.Cast<byte, T>(arguments)[0], ref MemoryMarshal.Cast<byte, T1>(inlineBuffer)[0]);
  53. }
  54. protected static NvInternalResult CallIoctlMethod<T>(IoctlProcessorSpan<T> callback, Span<byte> arguments) where T : struct
  55. {
  56. return callback(MemoryMarshal.Cast<byte, T>(arguments));
  57. }
  58. protected static NvInternalResult CallIoctlMethod<T, T1>(IoctlProcessorInlineSpan<T, T1> callback, Span<byte> arguments, Span<byte> inlineBuffer) where T : struct where T1 : struct
  59. {
  60. Debug.Assert(arguments.Length == Unsafe.SizeOf<T>());
  61. return callback(ref MemoryMarshal.Cast<byte, T>(arguments)[0], MemoryMarshal.Cast<byte, T1>(inlineBuffer));
  62. }
  63. public abstract void Close();
  64. }
  65. }