IGeneralInterface.cs 5.0 KB

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