OemMiscLib.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /** @file
  2. * OemMiscLib.c
  3. *
  4. * Copyright (c) 2021, NUVIA Inc. All rights reserved.
  5. * Copyright (c) 2020, Linaro Ltd. All rights reserved.
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause-Patent
  8. *
  9. **/
  10. #include <Uefi.h>
  11. #include <Guid/ZeroGuid.h>
  12. #include <Library/BaseMemoryLib.h>
  13. #include <Library/DebugLib.h>
  14. #include <Library/FdtHelperLib.h>
  15. #include <Library/HiiLib.h>
  16. #include <Library/IoLib.h>
  17. #include <Library/OemMiscLib.h>
  18. #include <Library/PcdLib.h>
  19. #include <Library/SerialPortLib.h>
  20. #include <Library/TimerLib.h>
  21. #include <libfdt.h>
  22. /** Returns whether the specified processor is present or not.
  23. @param ProcessorIndex The processor index to check.
  24. @return TRUE if the processor is present, FALSE otherwise.
  25. **/
  26. BOOLEAN
  27. EFIAPI
  28. OemIsProcessorPresent (
  29. UINTN ProcessorIndex
  30. )
  31. {
  32. if (ProcessorIndex < FdtHelperCountCpus ()) {
  33. return TRUE;
  34. }
  35. return FALSE;
  36. }
  37. /** Gets the CPU frequency of the specified processor.
  38. @param ProcessorIndex Index of the processor to get the frequency for.
  39. @return CPU frequency in Hz
  40. **/
  41. UINTN
  42. EFIAPI
  43. OemGetCpuFreq (
  44. UINT8 ProcessorIndex
  45. )
  46. {
  47. return 2000000000; // 2 GHz
  48. }
  49. /** Gets information about the specified processor and stores it in
  50. the structures provided.
  51. @param ProcessorIndex Index of the processor to get the information for.
  52. @param ProcessorStatus Processor status.
  53. @param ProcessorCharacteristics Processor characteritics.
  54. @param MiscProcessorData Miscellaneous processor information.
  55. @return TRUE on success, FALSE on failure.
  56. **/
  57. BOOLEAN
  58. EFIAPI
  59. OemGetProcessorInformation (
  60. IN UINTN ProcessorIndex,
  61. IN OUT PROCESSOR_STATUS_DATA *ProcessorStatus,
  62. IN OUT PROCESSOR_CHARACTERISTIC_FLAGS *ProcessorCharacteristics,
  63. IN OUT OEM_MISC_PROCESSOR_DATA *MiscProcessorData
  64. )
  65. {
  66. UINT16 ProcessorCount;
  67. ProcessorCount = FdtHelperCountCpus ();
  68. if (ProcessorIndex < ProcessorCount) {
  69. ProcessorStatus->Bits.CpuStatus = 1; // CPU enabled
  70. ProcessorStatus->Bits.Reserved1 = 0;
  71. ProcessorStatus->Bits.SocketPopulated = 1;
  72. ProcessorStatus->Bits.Reserved2 = 0;
  73. } else {
  74. ProcessorStatus->Bits.CpuStatus = 0; // CPU disabled
  75. ProcessorStatus->Bits.Reserved1 = 0;
  76. ProcessorStatus->Bits.SocketPopulated = 0;
  77. ProcessorStatus->Bits.Reserved2 = 0;
  78. }
  79. ProcessorCharacteristics->ProcessorReserved1 = 0;
  80. ProcessorCharacteristics->ProcessorUnknown = 0;
  81. ProcessorCharacteristics->Processor64BitCapable = 1;
  82. ProcessorCharacteristics->ProcessorMultiCore = 0;
  83. ProcessorCharacteristics->ProcessorHardwareThread = 0;
  84. ProcessorCharacteristics->ProcessorExecuteProtection = 1;
  85. ProcessorCharacteristics->ProcessorEnhancedVirtualization = 0;
  86. ProcessorCharacteristics->ProcessorPowerPerformanceCtrl = 0;
  87. ProcessorCharacteristics->Processor128BitCapable = 0;
  88. ProcessorCharacteristics->ProcessorArm64SocId = 1;
  89. ProcessorCharacteristics->ProcessorReserved2 = 0;
  90. MiscProcessorData->CurrentSpeed = 2000;
  91. MiscProcessorData->MaxSpeed = 2000;
  92. MiscProcessorData->CoreCount = 1;
  93. MiscProcessorData->CoresEnabled = 1;
  94. MiscProcessorData->ThreadCount = 1;
  95. return TRUE;
  96. }
  97. /** Gets the maximum number of processors supported by the platform.
  98. @return The maximum number of processors.
  99. **/
  100. UINT8
  101. EFIAPI
  102. OemGetMaxProcessors (
  103. VOID
  104. )
  105. {
  106. return FdtHelperCountCpus ();
  107. }
  108. /** Gets information about the cache at the specified cache level.
  109. @param ProcessorIndex The processor to get information for.
  110. @param CacheLevel The cache level to get information for.
  111. @param DataCache Whether the cache is a data cache.
  112. @param UnifiedCache Whether the cache is a unified cache.
  113. @param SmbiosCacheTable The SMBIOS Type7 cache information structure.
  114. @return TRUE on success, FALSE on failure.
  115. **/
  116. BOOLEAN
  117. EFIAPI
  118. OemGetCacheInformation (
  119. IN UINT8 ProcessorIndex,
  120. IN UINT8 CacheLevel,
  121. IN BOOLEAN DataCache,
  122. IN BOOLEAN UnifiedCache,
  123. IN OUT SMBIOS_TABLE_TYPE7 *SmbiosCacheTable
  124. )
  125. {
  126. SmbiosCacheTable->CacheConfiguration = CacheLevel - 1;
  127. if (CacheLevel == 1 && !DataCache && !UnifiedCache) {
  128. // Unknown operational mode
  129. SmbiosCacheTable->CacheConfiguration |= (3 << 8);
  130. } else {
  131. // Write back operational mode
  132. SmbiosCacheTable->CacheConfiguration |= (1 << 8);
  133. }
  134. return TRUE;
  135. }
  136. /** Gets the type of chassis for the system.
  137. @retval The type of the chassis.
  138. **/
  139. MISC_CHASSIS_TYPE
  140. EFIAPI
  141. OemGetChassisType (
  142. VOID
  143. )
  144. {
  145. return MiscChassisTypeMainServerChassis;
  146. }
  147. /** Updates the HII string for the specified field.
  148. @param HiiHandle The HII handle.
  149. @param TokenToUpdate The string to update.
  150. @param Field The field to get information about.
  151. **/
  152. VOID
  153. EFIAPI
  154. OemUpdateSmbiosInfo (
  155. IN EFI_HII_HANDLE HiiHandle,
  156. IN EFI_STRING_ID TokenToUpdate,
  157. IN OEM_MISC_SMBIOS_HII_STRING_FIELD Field
  158. )
  159. {
  160. CHAR16 *String;
  161. // These values are fixed for now, but should be configurable via
  162. // something like an emulated SCP.
  163. switch (Field) {
  164. case SystemManufacturerType01:
  165. String = (CHAR16*)PcdGetPtr (PcdSystemManufacturer);
  166. break;
  167. case SerialNumType01:
  168. String = (CHAR16*)PcdGetPtr (PcdSystemSerialNumber);
  169. break;
  170. case SkuNumberType01:
  171. String = (CHAR16*)PcdGetPtr (PcdSystemSKU);
  172. break;
  173. case FamilyType01:
  174. String = (CHAR16*)PcdGetPtr (PcdSystemFamily);
  175. break;
  176. case AssetTagType02:
  177. String = (CHAR16*)PcdGetPtr (PcdBaseBoardAssetTag);
  178. break;
  179. case SerialNumberType02:
  180. String = (CHAR16*)PcdGetPtr (PcdBaseBoardSerialNumber);
  181. break;
  182. case BoardManufacturerType02:
  183. String = (CHAR16*)PcdGetPtr (PcdBaseBoardManufacturer);
  184. break;
  185. case SkuNumberType02:
  186. String = (CHAR16*)PcdGetPtr (PcdBaseBoardSKU);
  187. break;
  188. case ChassisLocationType02:
  189. String = (CHAR16*)PcdGetPtr (PcdBaseBoardLocation);
  190. break;
  191. case SerialNumberType03:
  192. String = (CHAR16*)PcdGetPtr (PcdChassisSerialNumber);
  193. break;
  194. case VersionType03:
  195. String = (CHAR16*)PcdGetPtr (PcdChassisVersion);
  196. break;
  197. case ManufacturerType03:
  198. String = (CHAR16*)PcdGetPtr (PcdChassisManufacturer);
  199. break;
  200. case AssetTagType03:
  201. String = (CHAR16*)PcdGetPtr (PcdChassisAssetTag);
  202. break;
  203. case SkuNumberType03:
  204. String = (CHAR16*)PcdGetPtr (PcdChassisSKU);
  205. break;
  206. default:
  207. String = NULL;
  208. break;
  209. }
  210. if (String != NULL) {
  211. HiiSetString (HiiHandle, TokenToUpdate, String, NULL);
  212. }
  213. }
  214. /** Fetches the Type 32 boot information status.
  215. @return Boot status.
  216. **/
  217. MISC_BOOT_INFORMATION_STATUS_DATA_TYPE
  218. EFIAPI
  219. OemGetBootStatus (
  220. VOID
  221. )
  222. {
  223. return BootInformationStatusNoError;
  224. }
  225. /** Fetches the chassis status when it was last booted.
  226. @return Chassis status.
  227. **/
  228. MISC_CHASSIS_STATE
  229. EFIAPI
  230. OemGetChassisBootupState (
  231. VOID
  232. )
  233. {
  234. return ChassisStateSafe;
  235. }
  236. /** Fetches the chassis power supply/supplies status when last booted.
  237. @return Chassis power supply/supplies status.
  238. **/
  239. MISC_CHASSIS_STATE
  240. EFIAPI
  241. OemGetChassisPowerSupplyState (
  242. VOID
  243. )
  244. {
  245. return ChassisStateSafe;
  246. }
  247. /** Fetches the chassis thermal status when last booted.
  248. @return Chassis thermal status.
  249. **/
  250. MISC_CHASSIS_STATE
  251. EFIAPI
  252. OemGetChassisThermalState (
  253. VOID
  254. )
  255. {
  256. return ChassisStateSafe;
  257. }
  258. /** Fetches the chassis security status when last booted.
  259. @return Chassis security status.
  260. **/
  261. MISC_CHASSIS_SECURITY_STATE
  262. EFIAPI
  263. OemGetChassisSecurityStatus (
  264. VOID
  265. )
  266. {
  267. return ChassisSecurityStatusNone;
  268. }
  269. /** Fetches the chassis height in RMUs (Rack Mount Units).
  270. @return The height of the chassis.
  271. **/
  272. UINT8
  273. EFIAPI
  274. OemGetChassisHeight (
  275. VOID
  276. )
  277. {
  278. return 1U;
  279. }
  280. /** Fetches the number of power cords.
  281. @return The number of power cords.
  282. **/
  283. UINT8
  284. EFIAPI
  285. OemGetChassisNumPowerCords (
  286. VOID
  287. )
  288. {
  289. return 1;
  290. }
  291. /**
  292. Fetches the system UUID.
  293. @param[out] SystemUuid The pointer to the buffer to store the System UUID.
  294. **/
  295. VOID
  296. EFIAPI
  297. OemGetSystemUuid (
  298. OUT GUID *SystemUuid
  299. )
  300. {
  301. CopyGuid (SystemUuid, &gZeroGuid);
  302. }
  303. /** Fetches the BIOS release.
  304. @return The BIOS release.
  305. **/
  306. UINT16
  307. EFIAPI
  308. OemGetBiosRelease (
  309. VOID
  310. )
  311. {
  312. return PcdGet16 (PcdSystemBiosRelease);
  313. }
  314. /** Fetches the embedded controller firmware release.
  315. @return The embedded controller firmware release.
  316. **/
  317. UINT16
  318. EFIAPI
  319. OemGetEmbeddedControllerFirmwareRelease (
  320. VOID
  321. )
  322. {
  323. return PcdGet16 (PcdEmbeddedControllerFirmwareRelease);
  324. }