IGeneralInterface.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Ryujinx.HLE.FileSystem;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using Ryujinx.HLE.HOS.Services.Spl.Types;
  4. namespace Ryujinx.HLE.HOS.Services.Spl
  5. {
  6. [Service("spl:")]
  7. [Service("spl:es")]
  8. [Service("spl:fs")]
  9. [Service("spl:manu")]
  10. [Service("spl:mig")]
  11. [Service("spl:ssl")]
  12. class IGeneralInterface : IpcService
  13. {
  14. public IGeneralInterface(ServiceCtx context) { }
  15. [CommandHipc(0)]
  16. // GetConfig(u32 config_item) -> u64 config_value
  17. public ResultCode GetConfig(ServiceCtx context)
  18. {
  19. ConfigItem configItem = (ConfigItem)context.RequestData.ReadUInt32();
  20. // NOTE: Nintendo explicitly blacklists package2 hash here, amusingly.
  21. // This is not blacklisted in safemode, but we're never in safe mode...
  22. if (configItem == ConfigItem.Package2Hash)
  23. {
  24. return ResultCode.InvalidArguments;
  25. }
  26. // TODO: This should call svcCallSecureMonitor using arg 0xC3000002.
  27. // Since it's currently not implemented we can use a private method for now.
  28. SmcResult result = SmcGetConfig(context, out ulong configValue, configItem);
  29. // Nintendo has some special handling here for hardware type/is_retail.
  30. if (result == SmcResult.InvalidArgument)
  31. {
  32. switch (configItem)
  33. {
  34. case ConfigItem.HardwareType:
  35. configValue = (ulong)HardwareType.Icosa;
  36. result = SmcResult.Success;
  37. break;
  38. case ConfigItem.HardwareState:
  39. configValue = (ulong)HardwareState.Development;
  40. result = SmcResult.Success;
  41. break;
  42. default:
  43. break;
  44. }
  45. }
  46. context.ResponseData.Write(configValue);
  47. return (ResultCode)((int)result << 9) | ResultCode.ModuleId;
  48. }
  49. private SmcResult SmcGetConfig(ServiceCtx context, out ulong configValue, ConfigItem configItem)
  50. {
  51. configValue = default;
  52. SystemVersion version = context.Device.System.ContentManager.GetCurrentFirmwareVersion();
  53. MemorySize memorySize = context.Device.Configuration.MemoryConfiguration.ToKernelMemorySize();
  54. switch (configItem)
  55. {
  56. case ConfigItem.DisableProgramVerification:
  57. configValue = 0;
  58. break;
  59. case ConfigItem.DramId:
  60. if (memorySize == MemorySize.MemorySize8GB)
  61. {
  62. configValue = (ulong)DramId.IowaSamsung8GB;
  63. }
  64. else if (memorySize == MemorySize.MemorySize6GB)
  65. {
  66. configValue = (ulong)DramId.IcosaSamsung6GB;
  67. }
  68. else
  69. {
  70. configValue = (ulong)DramId.IcosaSamsung4GB;
  71. }
  72. break;
  73. case ConfigItem.SecurityEngineInterruptNumber:
  74. return SmcResult.NotImplemented;
  75. case ConfigItem.FuseVersion:
  76. return SmcResult.NotImplemented;
  77. case ConfigItem.HardwareType:
  78. configValue = (ulong)HardwareType.Icosa;
  79. break;
  80. case ConfigItem.HardwareState:
  81. configValue = (ulong)HardwareState.Production;
  82. break;
  83. case ConfigItem.IsRecoveryBoot:
  84. configValue = 0;
  85. break;
  86. case ConfigItem.DeviceId:
  87. return SmcResult.NotImplemented;
  88. case ConfigItem.BootReason:
  89. // This was removed in firmware 4.0.0.
  90. return SmcResult.InvalidArgument;
  91. case ConfigItem.MemoryMode:
  92. configValue = (ulong)context.Device.Configuration.MemoryConfiguration;
  93. break;
  94. case ConfigItem.IsDevelopmentFunctionEnabled:
  95. configValue = 0;
  96. break;
  97. case ConfigItem.KernelConfiguration:
  98. return SmcResult.NotImplemented;
  99. case ConfigItem.IsChargerHiZModeEnabled:
  100. return SmcResult.NotImplemented;
  101. case ConfigItem.QuestState:
  102. return SmcResult.NotImplemented;
  103. case ConfigItem.RegulatorType:
  104. return SmcResult.NotImplemented;
  105. case ConfigItem.DeviceUniqueKeyGeneration:
  106. return SmcResult.NotImplemented;
  107. case ConfigItem.Package2Hash:
  108. return SmcResult.NotImplemented;
  109. default:
  110. return SmcResult.InvalidArgument;
  111. }
  112. return SmcResult.Success;
  113. }
  114. }
  115. }