aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Services/Pcv/Clkrst/ClkrstManager/IClkrstSession.cs
blob: ddc4e5c7d1663eaafd8d5af8261800226ccdfd57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Pcv.Types;
using System.Linq;

namespace Ryujinx.HLE.HOS.Services.Pcv.Clkrst.ClkrstManager
{
    class IClkrstSession : IpcService
    {
        private readonly DeviceCode _deviceCode;
#pragma warning disable IDE0052 // Remove unread private member
        private readonly uint _unknown;
#pragma warning restore IDE0052
        private uint _clockRate;

        private readonly DeviceCode[] _allowedDeviceCodeTable = {
            DeviceCode.Cpu,    DeviceCode.Gpu,      DeviceCode.Disp1,    DeviceCode.Disp2,
            DeviceCode.Tsec,   DeviceCode.Mselect,  DeviceCode.Sor1,     DeviceCode.Host1x,
            DeviceCode.Vic,    DeviceCode.Nvenc,    DeviceCode.Nvjpg,    DeviceCode.Nvdec,
            DeviceCode.Ape,    DeviceCode.AudioDsp, DeviceCode.Emc,      DeviceCode.Dsi,
            DeviceCode.SysBus, DeviceCode.XusbSs,   DeviceCode.XusbHost, DeviceCode.XusbDevice,
            DeviceCode.Gpuaux, DeviceCode.Pcie,     DeviceCode.Apbdma,   DeviceCode.Sdmmc1,
            DeviceCode.Sdmmc2, DeviceCode.Sdmmc4,
        };

        public IClkrstSession(DeviceCode deviceCode, uint unknown)
        {
            _deviceCode = deviceCode;
            _unknown = unknown;
        }

        [CommandCmif(7)]
        // SetClockRate(u32 hz)
        public ResultCode SetClockRate(ServiceCtx context)
        {
            if (!_allowedDeviceCodeTable.Contains(_deviceCode))
            {
                return ResultCode.InvalidArgument;
            }

            _clockRate = context.RequestData.ReadUInt32();

            Logger.Stub?.PrintStub(LogClass.ServicePcv, new { _clockRate });

            return ResultCode.Success;
        }

        [CommandCmif(8)]
        // GetClockRate() -> u32 hz
        public ResultCode GetClockRate(ServiceCtx context)
        {
            if (!_allowedDeviceCodeTable.Contains(_deviceCode))
            {
                return ResultCode.InvalidArgument;
            }

            context.ResponseData.Write(_clockRate);

            Logger.Stub?.PrintStub(LogClass.ServicePcv, new { _clockRate });

            return ResultCode.Success;
        }
    }
}