2023-01-04 22:15:45 +00:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types;
|
2023-01-04 22:15:45 +00:00
|
|
|
|
using Ryujinx.Horizon.Common;
|
2020-12-01 23:23:43 +00:00
|
|
|
|
using Ryujinx.Memory;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
|
|
|
|
|
{
|
|
|
|
|
internal class NvHostGpuDeviceFile : NvHostChannelDeviceFile
|
|
|
|
|
{
|
|
|
|
|
private KEvent _smExceptionBptIntReportEvent;
|
|
|
|
|
private KEvent _smExceptionBptPauseReportEvent;
|
|
|
|
|
private KEvent _errorNotifierEvent;
|
|
|
|
|
|
2021-11-04 23:27:21 +00:00
|
|
|
|
private int _smExceptionBptIntReportEventHandle;
|
|
|
|
|
private int _smExceptionBptPauseReportEventHandle;
|
|
|
|
|
private int _errorNotifierEventHandle;
|
|
|
|
|
|
2022-02-09 20:18:07 +00:00
|
|
|
|
public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, memory, owner)
|
2019-11-02 22:47:56 +00:00
|
|
|
|
{
|
2021-11-04 23:27:21 +00:00
|
|
|
|
_smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle);
|
|
|
|
|
_smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle);
|
|
|
|
|
_errorNotifierEvent = CreateEvent(context, out _errorNotifierEventHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static KEvent CreateEvent(ServiceCtx context, out int handle)
|
|
|
|
|
{
|
|
|
|
|
KEvent evnt = new KEvent(context.Device.System.KernelContext);
|
|
|
|
|
|
2023-01-04 22:15:45 +00:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out handle) != Result.Success)
|
2021-11-04 23:27:21 +00:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return evnt;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
|
|
|
|
|
{
|
|
|
|
|
NvInternalResult result = NvInternalResult.NotImplemented;
|
|
|
|
|
|
|
|
|
|
if (command.Type == NvIoctl.NvHostMagic)
|
|
|
|
|
{
|
|
|
|
|
switch (command.Number)
|
|
|
|
|
{
|
|
|
|
|
case 0x1b:
|
2019-10-13 06:02:07 +00:00
|
|
|
|
result = CallIoctlMethod<SubmitGpfifoArguments, ulong>(SubmitGpfifoEx, arguments, inlineInBuffer);
|
2019-11-02 22:47:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
|
|
|
|
{
|
|
|
|
|
// TODO: accurately represent and implement those events.
|
|
|
|
|
switch (eventId)
|
|
|
|
|
{
|
|
|
|
|
case 0x1:
|
2021-11-04 23:27:21 +00:00
|
|
|
|
eventHandle = _smExceptionBptIntReportEventHandle;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
break;
|
|
|
|
|
case 0x2:
|
2021-11-04 23:27:21 +00:00
|
|
|
|
eventHandle = _smExceptionBptPauseReportEventHandle;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
break;
|
|
|
|
|
case 0x3:
|
2021-11-04 23:27:21 +00:00
|
|
|
|
eventHandle = _errorNotifierEventHandle;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
eventHandle = 0;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 23:27:21 +00:00
|
|
|
|
return eventHandle != 0 ? NvInternalResult.Success : NvInternalResult.InvalidInput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NvInternalResult SubmitGpfifoEx(ref SubmitGpfifoArguments arguments, Span<ulong> inlineData)
|
|
|
|
|
{
|
|
|
|
|
return SubmitGpfifo(ref arguments, inlineData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Close()
|
|
|
|
|
{
|
|
|
|
|
if (_smExceptionBptIntReportEventHandle != 0)
|
2019-11-02 22:47:56 +00:00
|
|
|
|
{
|
2021-11-04 23:27:21 +00:00
|
|
|
|
Context.Process.HandleTable.CloseHandle(_smExceptionBptIntReportEventHandle);
|
|
|
|
|
_smExceptionBptIntReportEventHandle = 0;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 23:27:21 +00:00
|
|
|
|
if (_smExceptionBptPauseReportEventHandle != 0)
|
|
|
|
|
{
|
|
|
|
|
Context.Process.HandleTable.CloseHandle(_smExceptionBptPauseReportEventHandle);
|
|
|
|
|
_smExceptionBptPauseReportEventHandle = 0;
|
2019-11-02 22:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 23:27:21 +00:00
|
|
|
|
if (_errorNotifierEventHandle != 0)
|
|
|
|
|
{
|
|
|
|
|
Context.Process.HandleTable.CloseHandle(_errorNotifierEventHandle);
|
|
|
|
|
_errorNotifierEventHandle = 0;
|
|
|
|
|
}
|
2019-11-02 22:47:56 +00:00
|
|
|
|
|
2021-11-04 23:27:21 +00:00
|
|
|
|
base.Close();
|
2019-11-02 22:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|