2019-07-14 20:50:11 +00:00
|
|
|
using Ryujinx.Common;
|
2022-05-31 19:29:35 +00:00
|
|
|
using Ryujinx.Cpu;
|
2019-07-14 20:50:11 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
2018-02-10 00:14:55 +00:00
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
class ISteadyClock : IpcService
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
private SteadyClockCore _steadyClock;
|
|
|
|
private bool _writePermission;
|
|
|
|
private bool _bypassUninitializedClock;
|
|
|
|
|
|
|
|
public ISteadyClock(SteadyClockCore steadyClock, bool writePermission, bool bypassUninitializedClock)
|
|
|
|
{
|
|
|
|
_steadyClock = steadyClock;
|
|
|
|
_writePermission = writePermission;
|
|
|
|
_bypassUninitializedClock = bypassUninitializedClock;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(0)]
|
2019-07-12 01:13:43 +00:00
|
|
|
// GetCurrentTimePoint() -> nn::time::SteadyClockTimePoint
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetCurrentTimePoint(ServiceCtx context)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
2022-05-31 19:29:35 +00:00
|
|
|
ITickSource tickSource = context.Device.System.TickSource;
|
|
|
|
|
|
|
|
SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(tickSource);
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
context.ResponseData.WriteStruct(currentTimePoint);
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(2)]
|
2019-07-12 01:13:43 +00:00
|
|
|
// GetTestOffset() -> nn::TimeSpanType
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetTestOffset(ServiceCtx context)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.WriteStruct(_steadyClock.GetTestOffset());
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(3)]
|
2019-07-12 01:13:43 +00:00
|
|
|
// SetTestOffset(nn::TimeSpanType)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode SetTestOffset(ServiceCtx context)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_writePermission)
|
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
TimeSpanType testOffset = context.RequestData.ReadStruct<TimeSpanType>();
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
_steadyClock.SetTestOffset(testOffset);
|
2019-07-14 20:50:11 +00:00
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
return ResultCode.Success;
|
2019-07-14 20:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(100)] // 2.0.0+
|
2019-07-15 17:52:35 +00:00
|
|
|
// GetRtcValue() -> u64
|
|
|
|
public ResultCode GetRtcValue(ServiceCtx context)
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode result = _steadyClock.GetRtcValue(out ulong rtcValue);
|
2019-07-15 17:52:35 +00:00
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(rtcValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(101)] // 2.0.0+
|
2019-07-15 17:52:35 +00:00
|
|
|
// IsRtcResetDetected() -> bool
|
|
|
|
public ResultCode IsRtcResetDetected(ServiceCtx context)
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.Write(_steadyClock.IsRtcResetDetected());
|
2019-07-15 17:52:35 +00:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(102)] // 2.0.0+
|
2019-07-15 17:52:35 +00:00
|
|
|
// GetSetupResultValue() -> u32
|
|
|
|
public ResultCode GetSetupResultValue(ServiceCtx context)
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.Write((uint)_steadyClock.GetSetupResultValue());
|
2019-07-15 17:52:35 +00:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(200)] // 3.0.0+
|
2019-07-14 20:50:11 +00:00
|
|
|
// GetInternalOffset() -> nn::TimeSpanType
|
|
|
|
public ResultCode GetInternalOffset(ServiceCtx context)
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.WriteStruct(_steadyClock.GetInternalOffset());
|
2019-07-14 20:50:11 +00:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(201)] // 3.0.0-3.0.2
|
2019-07-14 20:50:11 +00:00
|
|
|
// SetInternalOffset(nn::TimeSpanType)
|
|
|
|
public ResultCode SetInternalOffset(ServiceCtx context)
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
if (!_writePermission)
|
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_bypassUninitializedClock && !_steadyClock.IsInitialized())
|
|
|
|
{
|
|
|
|
return ResultCode.UninitializedClock;
|
|
|
|
}
|
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
TimeSpanType internalOffset = context.RequestData.ReadStruct<TimeSpanType>();
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
_steadyClock.SetInternalOffset(internalOffset);
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|