aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Services/Spl
diff options
context:
space:
mode:
authorTSR Berry <20988865+TSRBerry@users.noreply.github.com>2023-04-08 01:22:00 +0200
committerMary <thog@protonmail.com>2023-04-27 23:51:14 +0200
commitcee712105850ac3385cd0091a923438167433f9f (patch)
tree4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/Ryujinx.HLE/HOS/Services/Spl
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'src/Ryujinx.HLE/HOS/Services/Spl')
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs126
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs38
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs12
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs24
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs35
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs8
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs12
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs20
8 files changed, 275 insertions, 0 deletions
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs b/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs
new file mode 100644
index 00000000..aa350b73
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/IGeneralInterface.cs
@@ -0,0 +1,126 @@
+using Ryujinx.HLE.FileSystem;
+using Ryujinx.HLE.HOS.Kernel.Common;
+using Ryujinx.HLE.HOS.Services.Spl.Types;
+
+namespace Ryujinx.HLE.HOS.Services.Spl
+{
+ [Service("spl:")]
+ [Service("spl:es")]
+ [Service("spl:fs")]
+ [Service("spl:manu")]
+ [Service("spl:mig")]
+ [Service("spl:ssl")]
+ class IGeneralInterface : IpcService
+ {
+ public IGeneralInterface(ServiceCtx context) { }
+
+ [CommandCmif(0)]
+ // GetConfig(u32 config_item) -> u64 config_value
+ public ResultCode GetConfig(ServiceCtx context)
+ {
+ ConfigItem configItem = (ConfigItem)context.RequestData.ReadUInt32();
+
+ // NOTE: Nintendo explicitly blacklists package2 hash here, amusingly.
+ // This is not blacklisted in safemode, but we're never in safe mode...
+ if (configItem == ConfigItem.Package2Hash)
+ {
+ return ResultCode.InvalidArguments;
+ }
+
+ // TODO: This should call svcCallSecureMonitor using arg 0xC3000002.
+ // Since it's currently not implemented we can use a private method for now.
+ SmcResult result = SmcGetConfig(context, out ulong configValue, configItem);
+
+ // Nintendo has some special handling here for hardware type/is_retail.
+ if (result == SmcResult.InvalidArgument)
+ {
+ switch (configItem)
+ {
+ case ConfigItem.HardwareType:
+ configValue = (ulong)HardwareType.Icosa;
+ result = SmcResult.Success;
+ break;
+ case ConfigItem.HardwareState:
+ configValue = (ulong)HardwareState.Development;
+ result = SmcResult.Success;
+ break;
+ default:
+ break;
+ }
+ }
+
+ context.ResponseData.Write(configValue);
+
+ return (ResultCode)((int)result << 9) | ResultCode.ModuleId;
+ }
+
+ private SmcResult SmcGetConfig(ServiceCtx context, out ulong configValue, ConfigItem configItem)
+ {
+ configValue = default;
+
+ SystemVersion version = context.Device.System.ContentManager.GetCurrentFirmwareVersion();
+ MemorySize memorySize = context.Device.Configuration.MemoryConfiguration.ToKernelMemorySize();
+
+ switch (configItem)
+ {
+ case ConfigItem.DisableProgramVerification:
+ configValue = 0;
+ break;
+ case ConfigItem.DramId:
+ if (memorySize == MemorySize.MemorySize8GiB)
+ {
+ configValue = (ulong)DramId.IowaSamsung8GiB;
+ }
+ else if (memorySize == MemorySize.MemorySize6GiB)
+ {
+ configValue = (ulong)DramId.IcosaSamsung6GiB;
+ }
+ else
+ {
+ configValue = (ulong)DramId.IcosaSamsung4GiB;
+ }
+ break;
+ case ConfigItem.SecurityEngineInterruptNumber:
+ return SmcResult.NotImplemented;
+ case ConfigItem.FuseVersion:
+ return SmcResult.NotImplemented;
+ case ConfigItem.HardwareType:
+ configValue = (ulong)HardwareType.Icosa;
+ break;
+ case ConfigItem.HardwareState:
+ configValue = (ulong)HardwareState.Production;
+ break;
+ case ConfigItem.IsRecoveryBoot:
+ configValue = 0;
+ break;
+ case ConfigItem.DeviceId:
+ return SmcResult.NotImplemented;
+ case ConfigItem.BootReason:
+ // This was removed in firmware 4.0.0.
+ return SmcResult.InvalidArgument;
+ case ConfigItem.MemoryMode:
+ configValue = (ulong)context.Device.Configuration.MemoryConfiguration;
+ break;
+ case ConfigItem.IsDevelopmentFunctionEnabled:
+ configValue = 0;
+ break;
+ case ConfigItem.KernelConfiguration:
+ return SmcResult.NotImplemented;
+ case ConfigItem.IsChargerHiZModeEnabled:
+ return SmcResult.NotImplemented;
+ case ConfigItem.QuestState:
+ return SmcResult.NotImplemented;
+ case ConfigItem.RegulatorType:
+ return SmcResult.NotImplemented;
+ case ConfigItem.DeviceUniqueKeyGeneration:
+ return SmcResult.NotImplemented;
+ case ConfigItem.Package2Hash:
+ return SmcResult.NotImplemented;
+ default:
+ return SmcResult.InvalidArgument;
+ }
+
+ return SmcResult.Success;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs b/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs
new file mode 100644
index 00000000..c911f434
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs
@@ -0,0 +1,38 @@
+using System.Security.Cryptography;
+
+namespace Ryujinx.HLE.HOS.Services.Spl
+{
+ [Service("csrng")]
+ class IRandomInterface : DisposableIpcService
+ {
+ private RandomNumberGenerator _rng;
+
+ private object _lock = new object();
+
+ public IRandomInterface(ServiceCtx context)
+ {
+ _rng = RandomNumberGenerator.Create();
+ }
+
+ [CommandCmif(0)]
+ // GetRandomBytes() -> buffer<unknown, 6>
+ public ResultCode GetRandomBytes(ServiceCtx context)
+ {
+ byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
+
+ _rng.GetBytes(randomBytes);
+
+ context.Memory.Write(context.Request.ReceiveBuff[0].Position, randomBytes);
+
+ return ResultCode.Success;
+ }
+
+ protected override void Dispose(bool isDisposing)
+ {
+ if (isDisposing)
+ {
+ _rng.Dispose();
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs b/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs
new file mode 100644
index 00000000..4f61998a
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/ResultCode.cs
@@ -0,0 +1,12 @@
+namespace Ryujinx.HLE.HOS.Services.Spl
+{
+ enum ResultCode
+ {
+ ModuleId = 26,
+ ErrorCodeShift = 9,
+
+ Success = 0,
+
+ InvalidArguments = (101 << ErrorCodeShift) | ModuleId
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs
new file mode 100644
index 00000000..f08bbeaa
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/ConfigItem.cs
@@ -0,0 +1,24 @@
+namespace Ryujinx.HLE.HOS.Services.Spl.Types
+{
+ enum ConfigItem
+ {
+ // Standard config items.
+ DisableProgramVerification = 1,
+ DramId = 2,
+ SecurityEngineInterruptNumber = 3,
+ FuseVersion = 4,
+ HardwareType = 5,
+ HardwareState = 6,
+ IsRecoveryBoot = 7,
+ DeviceId = 8,
+ BootReason = 9,
+ MemoryMode = 10,
+ IsDevelopmentFunctionEnabled = 11,
+ KernelConfiguration = 12,
+ IsChargerHiZModeEnabled = 13,
+ QuestState = 14,
+ RegulatorType = 15,
+ DeviceUniqueKeyGeneration = 16,
+ Package2Hash = 17
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs
new file mode 100644
index 00000000..422c8d69
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/DramId.cs
@@ -0,0 +1,35 @@
+namespace Ryujinx.HLE.HOS.Services.Spl.Types
+{
+ enum DramId
+ {
+ IcosaSamsung4GiB,
+ IcosaHynix4GiB,
+ IcosaMicron4GiB,
+ IowaHynix1y4GiB,
+ IcosaSamsung6GiB,
+ HoagHynix1y4GiB,
+ AulaHynix1y4GiB,
+ IowaX1X2Samsung4GiB,
+ IowaSansung4GiB,
+ IowaSamsung8GiB,
+ IowaHynix4GiB,
+ IowaMicron4GiB,
+ HoagSamsung4GiB,
+ HoagSamsung8GiB,
+ HoagHynix4GiB,
+ HoagMicron4GiB,
+ IowaSamsung4GiBY,
+ IowaSamsung1y4GiBX,
+ IowaSamsung1y8GiBX,
+ HoagSamsung1y4GiBX,
+ IowaSamsung1y4GiBY,
+ IowaSamsung1y8GiBY,
+ AulaSamsung1y4GiB,
+ HoagSamsung1y8GiBX,
+ AulaSamsung1y4GiBX,
+ IowaMicron1y4GiB,
+ HoagMicron1y4GiB,
+ AulaMicron1y4GiB,
+ AulaSamsung1y8GiBX
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs
new file mode 100644
index 00000000..414d0f11
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareState.cs
@@ -0,0 +1,8 @@
+namespace Ryujinx.HLE.HOS.Services.Spl.Types
+{
+ enum HardwareState
+ {
+ Development,
+ Production
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs
new file mode 100644
index 00000000..491eb943
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/HardwareType.cs
@@ -0,0 +1,12 @@
+namespace Ryujinx.HLE.HOS.Services.Spl.Types
+{
+ enum HardwareType
+ {
+ Icosa,
+ Copper,
+ Hoag,
+ Iowa,
+ Calcio,
+ Aula
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs b/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs
new file mode 100644
index 00000000..d5f424a6
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Spl/Types/SmcResult.cs
@@ -0,0 +1,20 @@
+namespace Ryujinx.HLE.HOS.Services.Spl.Types
+{
+ enum SmcResult
+ {
+ Success = 0,
+ NotImplemented = 1,
+ InvalidArgument = 2,
+ Busy = 3,
+ NoAsyncOperation = 4,
+ InvalidAsyncOperation = 5,
+ NotPermitted = 6,
+ NotInitialized = 7,
+
+ PsciSuccess = 0,
+ PsciNotSupported = -1,
+ PsciInvalidParameters = -2,
+ PsciDenied = -3,
+ PsciAlreadyOn = -4
+ }
+} \ No newline at end of file