NvHostGpuDeviceFile.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Ryujinx.HLE.HOS.Kernel.Common;
  2. using Ryujinx.HLE.HOS.Kernel.Threading;
  3. using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types;
  4. using Ryujinx.Memory;
  5. using System;
  6. namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
  7. {
  8. internal class NvHostGpuDeviceFile : NvHostChannelDeviceFile
  9. {
  10. private KEvent _smExceptionBptIntReportEvent;
  11. private KEvent _smExceptionBptPauseReportEvent;
  12. private KEvent _errorNotifierEvent;
  13. public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, memory, owner)
  14. {
  15. _smExceptionBptIntReportEvent = new KEvent(context.Device.System.KernelContext);
  16. _smExceptionBptPauseReportEvent = new KEvent(context.Device.System.KernelContext);
  17. _errorNotifierEvent = new KEvent(context.Device.System.KernelContext);
  18. }
  19. public override NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
  20. {
  21. NvInternalResult result = NvInternalResult.NotImplemented;
  22. if (command.Type == NvIoctl.NvHostMagic)
  23. {
  24. switch (command.Number)
  25. {
  26. case 0x1b:
  27. result = CallIoctlMethod<SubmitGpfifoArguments, ulong>(SubmitGpfifoEx, arguments, inlineInBuffer);
  28. break;
  29. }
  30. }
  31. return result;
  32. }
  33. public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
  34. {
  35. // TODO: accurately represent and implement those events.
  36. KEvent targetEvent = null;
  37. switch (eventId)
  38. {
  39. case 0x1:
  40. targetEvent = _smExceptionBptIntReportEvent;
  41. break;
  42. case 0x2:
  43. targetEvent = _smExceptionBptPauseReportEvent;
  44. break;
  45. case 0x3:
  46. targetEvent = _errorNotifierEvent;
  47. break;
  48. }
  49. if (targetEvent != null)
  50. {
  51. if (Context.Process.HandleTable.GenerateHandle(targetEvent.ReadableEvent, out eventHandle) != KernelResult.Success)
  52. {
  53. throw new InvalidOperationException("Out of handles!");
  54. }
  55. }
  56. else
  57. {
  58. eventHandle = 0;
  59. return NvInternalResult.InvalidInput;
  60. }
  61. return NvInternalResult.Success;
  62. }
  63. private NvInternalResult SubmitGpfifoEx(ref SubmitGpfifoArguments arguments, Span<ulong> inlineData)
  64. {
  65. return SubmitGpfifo(ref arguments, inlineData);
  66. }
  67. }
  68. }