ProcessorSubClass.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /** @file
  2. *
  3. * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
  4. * Copyright (c) 2015, Linaro Limited. All rights reserved.
  5. *
  6. * This program and the accompanying materials
  7. * are licensed and made available under the terms and conditions of the BSD License
  8. * which accompanies this distribution. The full text of the license may be found at
  9. * http://opensource.org/licenses/bsd-license.php
  10. *
  11. * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  13. *
  14. **/
  15. #include "ProcessorSubClass.h"
  16. #include <FrameworkDxe.h>
  17. EFI_HII_HANDLE mHiiHandle;
  18. EFI_SMBIOS_PROTOCOL *mSmbios;
  19. SMBIOS_TABLE_TYPE7 mSmbiosCacheTable[] = {
  20. //L1 Instruction Cache
  21. {
  22. { //Header
  23. EFI_SMBIOS_TYPE_CACHE_INFORMATION, //Type
  24. sizeof(SMBIOS_TABLE_TYPE7), //Length
  25. 0 //Handle
  26. },
  27. 1, //SocketDesignation
  28. 0, //CacheConfiguration
  29. 0, //MaximumCacheSize
  30. 48, //InstalledSize
  31. { //SupportedSRAMType
  32. 0
  33. },
  34. { //CurrentSRAMType
  35. 0
  36. },
  37. 0, //CacheSpeed
  38. CacheErrorParity, //ErrorCorrectionType
  39. CacheTypeInstruction, //SystemCacheType
  40. CacheAssociativity8Way //Associativity
  41. },
  42. //L1 Data Cache
  43. {
  44. { //Header
  45. EFI_SMBIOS_TYPE_CACHE_INFORMATION, //Type
  46. sizeof(SMBIOS_TABLE_TYPE7), //Length
  47. 0 //Handle
  48. },
  49. 1, //SocketDesignation
  50. 0, //CacheConfiguration
  51. 0, //MaximumCacheSize
  52. 32, //InstalledSize
  53. { //SupportedSRAMType
  54. 0
  55. },
  56. { //CurrentSRAMType
  57. 0
  58. },
  59. 0, //CacheSpeed
  60. CacheErrorSingleBit, //ErrorCorrectionType
  61. CacheTypeData, //SystemCacheType
  62. CacheAssociativity8Way //Associativity
  63. },
  64. //L2 Cache
  65. {
  66. { //Header
  67. EFI_SMBIOS_TYPE_CACHE_INFORMATION, //Type
  68. sizeof(SMBIOS_TABLE_TYPE7), //Length
  69. 0 //Handle
  70. },
  71. 1, //SocketDesignation
  72. 0, //CacheConfiguration
  73. 0, //MaximumCacheSize
  74. 4096, //InstalledSize
  75. { //SupportedSRAMType
  76. 0
  77. },
  78. { //CurrentSRAMType
  79. 0
  80. },
  81. 0, //CacheSpeed
  82. CacheErrorSingleBit, //ErrorCorrectionType
  83. CacheTypeUnified, //SystemCacheType
  84. CacheAssociativity8Way //Associativity
  85. },
  86. //L3 Cache
  87. {
  88. { //Header
  89. EFI_SMBIOS_TYPE_CACHE_INFORMATION, //Type
  90. sizeof(SMBIOS_TABLE_TYPE7), //Length
  91. 0 //Handle
  92. },
  93. 1, //SocketDesignation
  94. 0, //CacheConfiguration
  95. 0, //MaximumCacheSize
  96. 16384, //InstalledSize
  97. { //SupportedSRAMType
  98. 0
  99. },
  100. { //CurrentSRAMType
  101. 0
  102. },
  103. 0, //CacheSpeed
  104. CacheErrorSingleBit, //ErrorCorrectionType
  105. CacheTypeUnified, //SystemCacheType
  106. CacheAssociativity16Way //Associativity
  107. }
  108. };
  109. SMBIOS_TABLE_TYPE4 mSmbiosProcessorTable[] = {
  110. //CPU0
  111. {
  112. { //Header
  113. EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, //Type
  114. sizeof(SMBIOS_TABLE_TYPE4), //Length
  115. 0 //Handle
  116. },
  117. 1, //Socket
  118. CentralProcessor, //ProcessorType
  119. ProcessorFamilyOther, //ProcessorFamily
  120. 2, //ProcessorManufacture
  121. { //ProcessorId
  122. { //Signature
  123. 0
  124. },
  125. { //FeatureFlags
  126. 0
  127. }
  128. },
  129. 3, //ProcessorVersion
  130. { //Voltage
  131. 0
  132. },
  133. EXTERNAL_CLOCK, //ExternalClock
  134. CPU_MAX_SPEED, //MaxSpeed
  135. 0, //CurrentSpeed
  136. 0, //Status
  137. ProcessorUpgradeUnknown, //ProcessorUpgrade
  138. 0xFFFF, //L1CacheHandle
  139. 0xFFFF, //L2CacheHandle
  140. 0xFFFF, //L3CacheHandle
  141. 4, //SerialNumber
  142. 5, //AssetTag
  143. 6, //PartNumber
  144. 0, //CoreCount
  145. 0, //EnabledCoreCount
  146. 0, //ThreadCount
  147. 0, //ProcessorCharacteristics
  148. ProcessorFamilyARM, //ProcessorFamily2
  149. 0, //CoreCount2
  150. 0, //EnabledCoreCount2
  151. 0 //ThreadCount2
  152. },
  153. //CPU1
  154. {
  155. { //Header
  156. EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, //Type
  157. sizeof(SMBIOS_TABLE_TYPE4), //Length
  158. 0 //Handle
  159. },
  160. 1, //Socket
  161. CentralProcessor, //ProcessorType
  162. ProcessorFamilyOther, //ProcessorFamily
  163. 2, //ProcessorManufacture
  164. { //ProcessorId
  165. { //Signature
  166. 0
  167. },
  168. { //FeatureFlags
  169. 0
  170. }
  171. },
  172. 3, //ProcessorVersion
  173. { //Voltage
  174. 0
  175. },
  176. EXTERNAL_CLOCK, //ExternalClock
  177. CPU_MAX_SPEED, //MaxSpeed
  178. 0, //CurrentSpeed
  179. 0, //Status
  180. ProcessorUpgradeUnknown, //ProcessorUpgrade
  181. 0xFFFF, //L1CacheHandle
  182. 0xFFFF, //L2CacheHandle
  183. 0xFFFF, //L3CacheHandle
  184. 4, //SerialNumber
  185. 5, //AssetTag
  186. 6, //PartNumber
  187. 0, //CoreCount
  188. 0, //EnabledCoreCount
  189. 0, //ThreadCount
  190. 0, //ProcessorCharacteristics
  191. ProcessorFamilyARM, //ProcessorFamily2
  192. 0, //CoreCount2
  193. 0, //EnabledCoreCount2
  194. 0 //ThreadCount2
  195. }
  196. };
  197. UINT16
  198. GetCpuFrequency (
  199. IN UINT8 ProcessorNumber
  200. )
  201. {
  202. return (UINT16)(PlatformGetCpuFreq(ProcessorNumber)/1000/1000);
  203. }
  204. UINTN
  205. GetCacheSocketStr (
  206. IN UINT8 CacheLevel,
  207. OUT CHAR16 *CacheSocketStr
  208. )
  209. {
  210. UINTN CacheSocketStrLen;
  211. if(CacheLevel == CPU_CACHE_L1_Instruction)
  212. {
  213. CacheSocketStrLen = UnicodeSPrint (CacheSocketStr, SMBIOS_STRING_MAX_LENGTH - 1, L"L%x Instruction Cache", CacheLevel + 1);
  214. }
  215. else if(CacheLevel == CPU_CACHE_L1_Data)
  216. {
  217. CacheSocketStrLen = UnicodeSPrint (CacheSocketStr, SMBIOS_STRING_MAX_LENGTH - 1, L"L%x Data Cache", CacheLevel);
  218. }
  219. else
  220. {
  221. CacheSocketStrLen = UnicodeSPrint (CacheSocketStr, SMBIOS_STRING_MAX_LENGTH - 1, L"L%x Cache", CacheLevel);
  222. }
  223. return CacheSocketStrLen;
  224. }
  225. VOID
  226. UpdateSmbiosCacheTable (
  227. IN UINT8 CacheLevel
  228. )
  229. {
  230. UINT16 CoreCount;
  231. UINT32 TotalSize;
  232. UINT32 CacheSize;
  233. UINT16 MaximumCacheSize;
  234. UINT16 InstalledSize;
  235. CACHE_CONFIGURATION CacheConfig;
  236. CACHE_SRAM_TYPE_DATA CacheSramType = {0};
  237. CoreCount = 16; // Default value is 16 Core
  238. //
  239. // Set Cache Configuration
  240. //
  241. CacheConfig.Bits.Socketed = 0; // Not Socketed
  242. CacheConfig.Bits.Reserved1 = 0; //
  243. CacheConfig.Bits.Location = 0; // Internal
  244. CacheConfig.Bits.Enable = 1; // Enabled
  245. CacheConfig.Bits.Reserved2 = 0;
  246. if(CacheLevel == CPU_CACHE_L1_Instruction || CacheLevel == CPU_CACHE_L1_Data)
  247. {
  248. CacheConfig.Bits.Level = 0;
  249. CacheConfig.Bits.OperationalMode = 1; // Write Back
  250. }
  251. else
  252. {
  253. CacheConfig.Bits.Level = CacheLevel - 1;
  254. CacheConfig.Bits.OperationalMode = 2; // Varies with Memory Address
  255. }
  256. mSmbiosCacheTable[CacheLevel].CacheConfiguration = CacheConfig.Data;
  257. //
  258. // Set Cache Size
  259. //
  260. CacheSize = mSmbiosCacheTable[CacheLevel].InstalledSize;
  261. if (PACKAGE_16CORE != PlatformGetPackageType()) // 32 Core
  262. {
  263. CoreCount = CoreCount * 2;
  264. if (CacheLevel > 1)
  265. {
  266. CacheSize = CacheSize * 2;
  267. }
  268. }
  269. if(CacheLevel <= 1)
  270. {
  271. TotalSize = CacheSize * CoreCount;
  272. }
  273. else
  274. {
  275. TotalSize = CacheSize;
  276. }
  277. if((TotalSize >> 15) == 0) // 1K granularity
  278. {
  279. MaximumCacheSize = (UINT16)TotalSize;
  280. InstalledSize = (UINT16)TotalSize;
  281. }
  282. else // 64K granularity
  283. {
  284. MaximumCacheSize = (UINT16)(TotalSize >> 6);
  285. InstalledSize = (UINT16)(TotalSize >> 6);
  286. // Set BIT15 to 1
  287. MaximumCacheSize |= BIT15;
  288. InstalledSize |= BIT15;
  289. }
  290. mSmbiosCacheTable[CacheLevel].MaximumCacheSize = MaximumCacheSize;
  291. mSmbiosCacheTable[CacheLevel].InstalledSize = InstalledSize;
  292. //
  293. // Set SRAM Type
  294. //
  295. CacheSramType.Synchronous = 1;
  296. (VOID)CopyMem(&mSmbiosCacheTable[CacheLevel].SupportedSRAMType, &CacheSramType, sizeof(CACHE_SRAM_TYPE_DATA));
  297. (VOID)CopyMem(&mSmbiosCacheTable[CacheLevel].CurrentSRAMType, &CacheSramType, sizeof(CACHE_SRAM_TYPE_DATA));
  298. }
  299. /**
  300. Add Type 7 SMBIOS Record for Cache Information.
  301. @param[in] ProcessorNumber Processor number of specified processor.
  302. @param[out] L1CacheHandle Pointer to the handle of the L1 Cache SMBIOS record.
  303. @param[out] L2CacheHandle Pointer to the handle of the L2 Cache SMBIOS record.
  304. @param[out] L3CacheHandle Pointer to the handle of the L3 Cache SMBIOS record.
  305. **/
  306. EFI_STATUS
  307. AddSmbiosCacheTypeTable (
  308. IN UINTN ProcessorNumber,
  309. OUT EFI_SMBIOS_HANDLE *L1CacheHandle,
  310. OUT EFI_SMBIOS_HANDLE *L2CacheHandle,
  311. OUT EFI_SMBIOS_HANDLE *L3CacheHandle
  312. )
  313. {
  314. EFI_STATUS Status;
  315. SMBIOS_TABLE_TYPE7 *Type7Record;
  316. EFI_SMBIOS_HANDLE SmbiosHandle;
  317. UINTN TableSize;
  318. UINT8 CacheLevel;
  319. CHAR8 *OptionalStrStart;
  320. EFI_STRING CacheSocketStr;
  321. UINTN CacheSocketStrLen;
  322. UINTN StringBufferSize;
  323. Status = EFI_SUCCESS;
  324. //
  325. // Get Cache information
  326. //
  327. for(CacheLevel = 0; CacheLevel < MAX_CACHE_LEVEL; CacheLevel++)
  328. {
  329. Type7Record = NULL;
  330. if(mSmbiosCacheTable[CacheLevel].InstalledSize == 0)
  331. {
  332. continue;
  333. }
  334. //
  335. // Update Cache information
  336. //
  337. if (mSmbiosCacheTable[CacheLevel].MaximumCacheSize == 0)
  338. {
  339. UpdateSmbiosCacheTable (CacheLevel);
  340. }
  341. StringBufferSize = sizeof(CHAR16) * SMBIOS_STRING_MAX_LENGTH;
  342. CacheSocketStr = AllocateZeroPool(StringBufferSize);
  343. if (CacheSocketStr == NULL)
  344. {
  345. Status = EFI_OUT_OF_RESOURCES;
  346. goto Exit;
  347. }
  348. CacheSocketStrLen = GetCacheSocketStr (CacheLevel, CacheSocketStr);
  349. TableSize = sizeof(SMBIOS_TABLE_TYPE7) + CacheSocketStrLen + 1 + 1;
  350. Type7Record = AllocateZeroPool (TableSize);
  351. if (Type7Record == NULL)
  352. {
  353. Status = EFI_OUT_OF_RESOURCES;
  354. goto Exit;
  355. }
  356. (VOID)CopyMem(Type7Record, &mSmbiosCacheTable[CacheLevel], sizeof (SMBIOS_TABLE_TYPE7));
  357. OptionalStrStart = (CHAR8 *) (Type7Record + 1);
  358. UnicodeStrToAsciiStr (CacheSocketStr, OptionalStrStart);
  359. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  360. Status = mSmbios->Add (mSmbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *)Type7Record);
  361. if (EFI_ERROR (Status))
  362. {
  363. goto Exit;
  364. }
  365. // Config L1/L2/L3 Cache Handle
  366. switch(CacheLevel)
  367. {
  368. case CPU_CACHE_L1_Instruction:
  369. case CPU_CACHE_L1_Data:
  370. *L1CacheHandle = SmbiosHandle;
  371. break;
  372. case CPU_CACHE_L2:
  373. *L2CacheHandle = SmbiosHandle;
  374. break;
  375. case CPU_CACHE_L3:
  376. *L3CacheHandle = SmbiosHandle;
  377. break;
  378. default :
  379. break;
  380. }
  381. Exit:
  382. if(Type7Record != NULL)
  383. {
  384. FreePool (Type7Record);
  385. }
  386. if(CacheSocketStr != NULL)
  387. {
  388. FreePool (CacheSocketStr);
  389. CacheSocketStr = NULL;
  390. }
  391. }
  392. return Status;
  393. }
  394. /**
  395. Add Type 4 SMBIOS Record for Processor Information.
  396. @param[in] ProcessorNumber Processor number of specified processor.
  397. **/
  398. EFI_STATUS
  399. AddSmbiosProcessorTypeTable (
  400. IN UINTN ProcessorNumber
  401. )
  402. {
  403. EFI_STATUS Status;
  404. SMBIOS_TABLE_TYPE4 *Type4Record;
  405. EFI_SMBIOS_HANDLE SmbiosHandle;
  406. EFI_SMBIOS_HANDLE L1CacheHandle;
  407. EFI_SMBIOS_HANDLE L2CacheHandle;
  408. EFI_SMBIOS_HANDLE L3CacheHandle;
  409. CHAR8 *OptionalStrStart;
  410. EFI_STRING_ID ProcessorManu;
  411. EFI_STRING_ID ProcessorVersion;
  412. EFI_STRING_ID SerialNumber;
  413. EFI_STRING_ID AssetTag;
  414. EFI_STRING_ID PartNumber;
  415. EFI_STRING ProcessorSocketStr;
  416. EFI_STRING ProcessorManuStr;
  417. EFI_STRING ProcessorVersionStr;
  418. EFI_STRING SerialNumberStr;
  419. EFI_STRING AssetTagStr;
  420. EFI_STRING PartNumberStr;
  421. UINTN ProcessorSocketStrLen;
  422. UINTN ProcessorManuStrLen;
  423. UINTN ProcessorVersionStrLen;
  424. UINTN SerialNumberStrLen;
  425. UINTN AssetTagStrLen;
  426. UINTN PartNumberStrLen;
  427. UINTN StringBufferSize;
  428. UINTN TotalSize;
  429. UINT8 Voltage;
  430. UINT16 CoreCount;
  431. UINT16 CoreEnabled;
  432. UINT16 ThreadCount;
  433. UINT16 CurrentSpeed;
  434. PROCESSOR_STATUS_DATA ProcessorStatus = {{0}};
  435. PROCESSOR_CHARACTERISTICS_DATA ProcessorCharacteristics = {{0}};
  436. CHAR16 *CpuVersion;
  437. STRING_REF TokenToUpdate;
  438. UINT64 *ProcessorId;
  439. Type4Record = NULL;
  440. ProcessorManuStr = NULL;
  441. ProcessorVersionStr = NULL;
  442. SerialNumberStr = NULL;
  443. AssetTagStr = NULL;
  444. PartNumberStr = NULL;
  445. if(OemIsSocketPresent(ProcessorNumber)) //CPU is present
  446. {
  447. Voltage = BIT7 | 9; // 0.9V
  448. Status = AddSmbiosCacheTypeTable (ProcessorNumber, &L1CacheHandle, &L2CacheHandle, &L3CacheHandle);
  449. if(EFI_ERROR(Status))
  450. {
  451. return Status;
  452. }
  453. CurrentSpeed = GetCpuFrequency(ProcessorNumber);
  454. CoreCount = PlatformGetCoreCount();
  455. CoreEnabled = CoreCount;
  456. ThreadCount = CoreCount;
  457. CpuVersion = (CHAR16 *) PcdGetPtr (PcdCPUInfo);
  458. if (StrLen(CpuVersion) > 0)
  459. {
  460. TokenToUpdate = STRING_TOKEN (STR_PROCESSOR_VERSION);
  461. HiiSetString (mHiiHandle, TokenToUpdate, CpuVersion, NULL);
  462. }
  463. ProcessorManu = STRING_TOKEN (STR_PROCESSOR_MANUFACTURE);
  464. ProcessorVersion = STRING_TOKEN (STR_PROCESSOR_VERSION);
  465. SerialNumber = STRING_TOKEN (STR_PROCESSOR_SERIAL_NUMBER);
  466. AssetTag = STRING_TOKEN (STR_PROCESSOR_ASSET_TAG);
  467. PartNumber = STRING_TOKEN (STR_PROCESSOR_PART_NUMBER);
  468. // Processor Status
  469. ProcessorStatus.Bits.CpuStatus = 1; // CPU Enabled
  470. ProcessorStatus.Bits.Reserved1 = 0;
  471. ProcessorStatus.Bits.SocketPopulated = 1; // CPU Socket Populated
  472. ProcessorStatus.Bits.Reserved2 = 0;
  473. // Processor Characteristics
  474. ProcessorCharacteristics.Bits.Reserved = 0;
  475. ProcessorCharacteristics.Bits.Capable64Bit = 1; // 64-bit Capable
  476. ProcessorCharacteristics.Bits.Unknown = 0;
  477. ProcessorCharacteristics.Bits.EnhancedVirtualization = 1;
  478. ProcessorCharacteristics.Bits.HardwareThread = 0;
  479. ProcessorCharacteristics.Bits.MultiCore = 1;
  480. ProcessorCharacteristics.Bits.ExecuteProtection = 1;
  481. ProcessorCharacteristics.Bits.PowerPerformanceControl = 1;
  482. ProcessorCharacteristics.Bits.Reserved2 = 0;
  483. }
  484. else
  485. {
  486. Voltage = 0;
  487. CurrentSpeed = 0;
  488. CoreCount = 0;
  489. CoreEnabled = 0;
  490. ThreadCount = 0;
  491. L1CacheHandle = 0xFFFF;
  492. L2CacheHandle = 0xFFFF;
  493. L3CacheHandle = 0xFFFF;
  494. ProcessorManu = STRING_TOKEN (STR_PROCESSOR_UNKNOWN);
  495. ProcessorVersion = STRING_TOKEN (STR_PROCESSOR_UNKNOWN);
  496. SerialNumber = STRING_TOKEN (STR_PROCESSOR_UNKNOWN);
  497. AssetTag = STRING_TOKEN (STR_PROCESSOR_UNKNOWN);
  498. PartNumber = STRING_TOKEN (STR_PROCESSOR_UNKNOWN);
  499. }
  500. // Processor Socket Designation
  501. StringBufferSize = sizeof(CHAR16) * SMBIOS_STRING_MAX_LENGTH;
  502. ProcessorSocketStr = AllocateZeroPool(StringBufferSize);
  503. if (ProcessorSocketStr == NULL)
  504. {
  505. Status = EFI_OUT_OF_RESOURCES;
  506. goto Exit;
  507. }
  508. ProcessorSocketStrLen = UnicodeSPrint (ProcessorSocketStr, StringBufferSize, L"CPU%02d", ProcessorNumber + 1);
  509. // Processor Manufacture
  510. ProcessorManuStr = HiiGetPackageString (&gEfiCallerIdGuid, ProcessorManu, NULL);
  511. ProcessorManuStrLen = StrLen (ProcessorManuStr);
  512. // Processor Version
  513. ProcessorVersionStr = HiiGetPackageString (&gEfiCallerIdGuid, ProcessorVersion, NULL);
  514. ProcessorVersionStrLen = StrLen (ProcessorVersionStr);
  515. // Serial Number
  516. SerialNumberStr = HiiGetPackageString (&gEfiCallerIdGuid, SerialNumber, NULL);
  517. SerialNumberStrLen = StrLen (SerialNumberStr);
  518. // Asset Tag
  519. AssetTagStr = HiiGetPackageString (&gEfiCallerIdGuid, AssetTag, NULL);
  520. AssetTagStrLen = StrLen (AssetTagStr);
  521. // Part Number
  522. PartNumberStr = HiiGetPackageString (&gEfiCallerIdGuid, PartNumber, NULL);
  523. PartNumberStrLen = StrLen (PartNumberStr);
  524. TotalSize = sizeof (SMBIOS_TABLE_TYPE4) + ProcessorSocketStrLen + 1 + ProcessorManuStrLen + 1 + ProcessorVersionStrLen + 1 + SerialNumberStrLen + 1 + AssetTagStrLen + 1 + PartNumberStrLen + 1 + 1;
  525. Type4Record = AllocateZeroPool (TotalSize);
  526. if (Type4Record == NULL)
  527. {
  528. Status = EFI_OUT_OF_RESOURCES;
  529. goto Exit;
  530. }
  531. (VOID)CopyMem(Type4Record, &mSmbiosProcessorTable[ProcessorNumber], sizeof (SMBIOS_TABLE_TYPE4));
  532. *(UINT8 *) &Type4Record->Voltage = Voltage;
  533. Type4Record->CurrentSpeed = CurrentSpeed;
  534. Type4Record->Status = ProcessorStatus.Data;
  535. Type4Record->L1CacheHandle = L1CacheHandle;
  536. Type4Record->L2CacheHandle = L2CacheHandle;
  537. Type4Record->L3CacheHandle = L3CacheHandle;
  538. Type4Record->CoreCount = CoreCount;
  539. Type4Record->EnabledCoreCount = CoreEnabled;
  540. Type4Record->ThreadCount = ThreadCount;
  541. Type4Record->ProcessorCharacteristics = ProcessorCharacteristics.Data;
  542. Type4Record->ExternalClock = (UINT16)(ArmReadCntFrq() / 1000 / 1000);
  543. ProcessorId = (UINT64 *)&(Type4Record->ProcessorId);
  544. *ProcessorId = ArmReadMidr();
  545. OptionalStrStart = (CHAR8 *) (Type4Record + 1);
  546. UnicodeStrToAsciiStr (ProcessorSocketStr, OptionalStrStart);
  547. UnicodeStrToAsciiStr (ProcessorManuStr, OptionalStrStart + ProcessorSocketStrLen + 1);
  548. UnicodeStrToAsciiStr (ProcessorVersionStr, OptionalStrStart + ProcessorSocketStrLen + 1 + ProcessorManuStrLen + 1);
  549. UnicodeStrToAsciiStr (SerialNumberStr, OptionalStrStart + ProcessorSocketStrLen + 1 + ProcessorManuStrLen + 1 + ProcessorVersionStrLen + 1);
  550. UnicodeStrToAsciiStr (AssetTagStr, OptionalStrStart + ProcessorSocketStrLen + 1 + ProcessorManuStrLen + 1 + ProcessorVersionStrLen + 1 + SerialNumberStrLen + 1);
  551. UnicodeStrToAsciiStr (PartNumberStr, OptionalStrStart + ProcessorSocketStrLen + 1 + ProcessorManuStrLen + 1 + ProcessorVersionStrLen + 1 + SerialNumberStrLen + 1 + AssetTagStrLen + 1);
  552. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  553. Status = mSmbios->Add (mSmbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *)Type4Record);
  554. if (EFI_ERROR (Status))
  555. {
  556. DEBUG((EFI_D_ERROR, "[%a]:[%dL] Smbios Type04 Table Log Failed! %r \n", __FUNCTION__, __LINE__, Status));
  557. }
  558. FreePool (Type4Record);
  559. Exit:
  560. if(ProcessorSocketStr != NULL)
  561. {
  562. FreePool (ProcessorSocketStr);
  563. }
  564. if(ProcessorManuStr != NULL)
  565. {
  566. FreePool (ProcessorManuStr);
  567. }
  568. if(ProcessorVersionStr != NULL)
  569. {
  570. FreePool (ProcessorVersionStr);
  571. }
  572. if(SerialNumberStr != NULL)
  573. {
  574. FreePool (SerialNumberStr);
  575. }
  576. if(AssetTagStr != NULL)
  577. {
  578. FreePool (AssetTagStr);
  579. }
  580. if(PartNumberStr != NULL)
  581. {
  582. FreePool (PartNumberStr);
  583. }
  584. return Status;
  585. }
  586. /**
  587. Standard EFI driver point. This driver locates the ProcessorConfigurationData Variable,
  588. if it exists, add the related SMBIOS tables by PI SMBIOS protocol.
  589. @param ImageHandle Handle for the image of this driver
  590. @param SystemTable Pointer to the EFI System Table
  591. @retval EFI_SUCCESS The data was successfully stored.
  592. **/
  593. EFI_STATUS
  594. EFIAPI
  595. ProcessorSubClassEntryPoint(
  596. IN EFI_HANDLE ImageHandle,
  597. IN EFI_SYSTEM_TABLE *SystemTable
  598. )
  599. {
  600. EFI_STATUS Status;
  601. UINT32 SocketIndex;
  602. //
  603. // Locate dependent protocols
  604. //
  605. Status = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&mSmbios);
  606. if (EFI_ERROR(Status))
  607. {
  608. DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol. %r\n", Status));
  609. return Status;
  610. }
  611. //
  612. // Add our default strings to the HII database. They will be modified later.
  613. //
  614. mHiiHandle = HiiAddPackages (
  615. &gEfiCallerIdGuid,
  616. NULL,
  617. ProcessorSubClassStrings,
  618. NULL,
  619. NULL
  620. );
  621. if (mHiiHandle == NULL)
  622. {
  623. return EFI_OUT_OF_RESOURCES;
  624. }
  625. //
  626. // Add SMBIOS tables for populated sockets.
  627. //
  628. for (SocketIndex = 0; SocketIndex < MAX_SOCKET; SocketIndex++)
  629. {
  630. if((SocketIndex == 1) && !OemIsMpBoot())
  631. {
  632. break;
  633. }
  634. Status = AddSmbiosProcessorTypeTable (SocketIndex);
  635. if(EFI_ERROR(Status))
  636. {
  637. DEBUG((EFI_D_ERROR, "Add Processor Type Table Failed! %r.\n", Status));
  638. return Status;
  639. }
  640. }
  641. return Status;
  642. }