PlatformInfo.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /** @file
  2. Platform Info PEIM.
  3. @copyright
  4. Copyright 1999 - 2021 Intel Corporation.
  5. Copyright (c) 2021, American Megatrends International LLC. <BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include "PlatformInfo.h"
  9. #include <GpioPinsSklH.h>
  10. #include <Library/GpioLib.h>
  11. #include <Library/PchInfoLib.h>
  12. #include <Ppi/DynamicSiLibraryPpi.h>
  13. #include <Library/UbaGpioPlatformConfig.h>
  14. #include <UncoreCommonIncludes.h>
  15. #include <PlatformInfoTypes.h>
  16. #include <Library/PeiServicesLib.h>
  17. #define TEMP_BUS_NUMBER (0x3F)
  18. STATIC EFI_PEI_PPI_DESCRIPTOR mPlatformInfoPpi = {
  19. EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
  20. &gEfiPlatformInfoGuid,
  21. NULL
  22. };
  23. #define BOARD_ID_GPIO_PADS_NUMBER 6
  24. #define BOARD_REV_ID_GPIO_PADS_NUMBER 3
  25. //
  26. // These pads shall not be board specific as these are used for Board ID and Rev ID detection
  27. // Therefore can not be moved to UBA and are common for all Purley boards
  28. //
  29. GPIO_PAD mBoardId [BOARD_ID_GPIO_PADS_NUMBER] = {
  30. // BoardId pads - PADCFG register for GPIO G12
  31. // WARNING: The pad number must be obtained from board schematics
  32. GPIO_SKL_H_GPP_G12,
  33. GPIO_SKL_H_GPP_G13,
  34. GPIO_SKL_H_GPP_G14,
  35. GPIO_SKL_H_GPP_G15,
  36. GPIO_SKL_H_GPP_G16,
  37. GPIO_SKL_H_GPP_B19
  38. };
  39. GPIO_PAD mBoardRevId [BOARD_REV_ID_GPIO_PADS_NUMBER] = {
  40. // Board RevId pads - Start from pad C12
  41. // WARNING: This should be obtained from board schematics
  42. GPIO_SKL_H_GPP_C12,
  43. GPIO_SKL_H_GPP_C13,
  44. GPIO_SKL_H_GPP_B9
  45. };
  46. GPIO_CONFIG mBoardAndRevIdConfig = {
  47. // Board and Revision ID pads configuration required for proper reading the values
  48. GpioPadModeGpio, GpioHostOwnDefault, GpioDirIn, GpioOutDefault, GpioIntDefault,
  49. GpioPlatformReset, GpioTermDefault, GpioLockDefault, GpioRxRaw1Default
  50. };
  51. VOID
  52. GpioConfigForBoardId (
  53. VOID
  54. )
  55. {
  56. UINT8 i;
  57. EFI_STATUS Status;
  58. GPIO_CONFIG PadConfig;
  59. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  60. PadConfig.PadMode = mBoardAndRevIdConfig.PadMode;
  61. PadConfig.HostSoftPadOwn = mBoardAndRevIdConfig.HostSoftPadOwn;
  62. PadConfig.Direction = mBoardAndRevIdConfig.Direction;
  63. PadConfig.OutputState = mBoardAndRevIdConfig.OutputState;
  64. PadConfig.InterruptConfig = mBoardAndRevIdConfig.InterruptConfig;
  65. PadConfig.PowerConfig = mBoardAndRevIdConfig.PowerConfig;
  66. PadConfig.ElectricalConfig = mBoardAndRevIdConfig.ElectricalConfig;
  67. PadConfig.LockConfig = mBoardAndRevIdConfig.LockConfig;
  68. PadConfig.OtherSettings = mBoardAndRevIdConfig.OtherSettings;
  69. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  70. if (EFI_ERROR (Status)) {
  71. ASSERT_EFI_ERROR (Status);
  72. return;
  73. }
  74. for (i = 0; i < BOARD_ID_GPIO_PADS_NUMBER; i++) {
  75. Status = DynamicSiLibraryPpi->GpioSetPadConfig (mBoardId[i], &PadConfig);
  76. ASSERT_EFI_ERROR (Status);
  77. }
  78. }
  79. VOID
  80. GpioConfigForBoardRevId (
  81. VOID
  82. )
  83. {
  84. UINT8 i;
  85. EFI_STATUS Status;
  86. GPIO_CONFIG PadConfig;
  87. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  88. PadConfig.PadMode = mBoardAndRevIdConfig.PadMode;
  89. PadConfig.HostSoftPadOwn = mBoardAndRevIdConfig.HostSoftPadOwn;
  90. PadConfig.Direction = mBoardAndRevIdConfig.Direction;
  91. PadConfig.OutputState = mBoardAndRevIdConfig.OutputState;
  92. PadConfig.InterruptConfig = mBoardAndRevIdConfig.InterruptConfig;
  93. PadConfig.PowerConfig = mBoardAndRevIdConfig.PowerConfig;
  94. PadConfig.ElectricalConfig = mBoardAndRevIdConfig.ElectricalConfig;
  95. PadConfig.LockConfig = mBoardAndRevIdConfig.LockConfig;
  96. PadConfig.OtherSettings = mBoardAndRevIdConfig.OtherSettings;
  97. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  98. if (EFI_ERROR (Status)) {
  99. ASSERT_EFI_ERROR (Status);
  100. return;
  101. }
  102. for (i = 0; i < BOARD_REV_ID_GPIO_PADS_NUMBER; i++) {
  103. Status = DynamicSiLibraryPpi->GpioSetPadConfig (mBoardRevId[i], &PadConfig);
  104. ASSERT_EFI_ERROR (Status);
  105. }
  106. }
  107. /**
  108. Reads GPIO pins to get Board ID value
  109. @retval Status - Success if GPIO's are read properly
  110. **/
  111. EFI_STATUS
  112. GpioGetBoardId (
  113. OUT UINT32 *BoardId
  114. )
  115. {
  116. EFI_STATUS Status = EFI_DEVICE_ERROR;
  117. UINT32 Data32;
  118. UINT8 i;
  119. UINT32 BdId;
  120. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  121. if (BoardId == NULL) {
  122. return EFI_UNSUPPORTED;
  123. }
  124. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  125. if (EFI_ERROR (Status)) {
  126. ASSERT_EFI_ERROR (Status);
  127. return Status;
  128. }
  129. BdId = 0;
  130. GpioConfigForBoardId ();
  131. for (i = 0; i < BOARD_ID_GPIO_PADS_NUMBER; i++) {
  132. Status = DynamicSiLibraryPpi->GpioGetInputValue (mBoardId[i], &Data32);
  133. if (EFI_ERROR(Status)) {
  134. break;
  135. }
  136. if (Data32) {
  137. BdId = BdId | (1 << i);
  138. }
  139. }
  140. if (Status != EFI_SUCCESS) {
  141. return Status;
  142. }
  143. *BoardId = BdId;
  144. return EFI_SUCCESS;
  145. }
  146. /**
  147. Reads GPIO pins to get Board Revision ID value
  148. @retval Status - Success if GPIO's are read properly
  149. **/
  150. EFI_STATUS
  151. GpioGetBoardRevId (
  152. OUT UINT32 *BoardRevId
  153. )
  154. {
  155. EFI_STATUS Status = EFI_DEVICE_ERROR;
  156. UINT32 Data32;
  157. UINT8 i;
  158. UINT32 RevId;
  159. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  160. if (BoardRevId == NULL) {
  161. return EFI_UNSUPPORTED;
  162. }
  163. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  164. if (EFI_ERROR (Status)) {
  165. ASSERT_EFI_ERROR (Status);
  166. return Status;
  167. }
  168. RevId = 0;
  169. GpioConfigForBoardRevId ();
  170. for (i = 0; i < BOARD_REV_ID_GPIO_PADS_NUMBER; i++){
  171. Status = DynamicSiLibraryPpi->GpioGetInputValue (mBoardRevId[i], &Data32);
  172. if (EFI_ERROR(Status)) {
  173. break;
  174. }
  175. if (Data32) {
  176. RevId = RevId | (1 << i);
  177. }
  178. }
  179. if (Status != EFI_SUCCESS) {
  180. return Status;
  181. }
  182. *BoardRevId = RevId;
  183. return EFI_SUCCESS;
  184. }
  185. /**
  186. Returns the Model ID of the CPU.
  187. Model ID = EAX[7:4]
  188. **/
  189. VOID
  190. GetCpuInfo (
  191. UINT32 *CpuType,
  192. UINT8 *CpuStepping
  193. )
  194. {
  195. UINT32 RegEax=0;
  196. AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL);
  197. *CpuStepping = (UINT8) (RegEax & 0x0F);
  198. *CpuType = (UINT32) (RegEax >> 4);
  199. }
  200. /**
  201. GC_TODO: add routine description
  202. @param BAR - GC_TODO: add arg description
  203. @param PeiServices - GC_TODO: add arg description
  204. @retval None
  205. **/
  206. VOID
  207. InitGSX(
  208. UINT32 *BAR,
  209. IN EFI_PEI_SERVICES **PeiServices
  210. )
  211. {
  212. }
  213. /**
  214. GC_TODO: add routine description
  215. @param Data - GC_TODO: add arg description
  216. @param PeiServices - GC_TODO: add arg description
  217. @retval EFI_SUCCESS - GC_TODO: add retval description
  218. @retval EFI_UNSUPPORTED - GC_TODO: add retval description
  219. **/
  220. EFI_STATUS
  221. GsxRead(
  222. UINT32 *Data,
  223. IN EFI_PEI_SERVICES **PeiServices
  224. )
  225. {
  226. return EFI_UNSUPPORTED;
  227. }
  228. /**
  229. GC_TODO: add routine description
  230. @param Data - GC_TODO: add arg description
  231. @param PeiServices - GC_TODO: add arg description
  232. @retval None
  233. **/
  234. VOID
  235. GetGsxBoardID(
  236. BOARD_ID *Data,
  237. IN EFI_PEI_SERVICES **PeiServices
  238. )
  239. {
  240. EFI_STATUS Status;
  241. UINT32 GSXIN[2];
  242. UINT32 RetryCount;
  243. RetryCount = 0;
  244. GSXIN[0] = 0;
  245. GSXIN[1] = 0;
  246. do {
  247. Status = GsxRead(GSXIN, PeiServices);
  248. if(Status){
  249. // if EFI_SUCCESS != Success then retry one more time
  250. RetryCount ++;
  251. }else{
  252. // if EFI_SUCCESS read Board ID and exit
  253. RetryCount = 0xFFFFFFFF;
  254. }
  255. if (GSXIN[0] & BIT0) {
  256. Data->BoardID.BoardID0 = 1;
  257. }
  258. if (GSXIN[0] & BIT1) {
  259. Data->BoardID.BoardID1 = 1;
  260. }
  261. if (GSXIN[0] & BIT2) {
  262. Data->BoardID.BoardID2 = 1;
  263. }
  264. if (GSXIN[0] & BIT3) {
  265. Data->BoardID.BoardID3 = 1;
  266. }
  267. if (GSXIN[0] & BIT4) {
  268. Data->BoardID.BoardID4 = 1;
  269. }
  270. if (GSXIN[0] & BIT5) {
  271. Data->BoardID.BoardRev0 = 1;
  272. }
  273. if (GSXIN[0] & BIT6) {
  274. Data->BoardID.BoardRev1 = 1;
  275. }
  276. } while(RetryCount < 1);
  277. if(Status){
  278. //
  279. // Unhable to read GSX HW error Hang the system
  280. //
  281. DEBUG ((EFI_D_ERROR, "ERROR: GSX HW is unavailable, SYSTEM HANG\n"));
  282. CpuDeadLoop ();
  283. }
  284. }
  285. /**
  286. Get Platform Type by read Platform Data Region in SPI flash.
  287. SPI Descriptor Mode Routines for Accessing Platform Info from Platform Data Region (PDR)
  288. @param PeiServices - General purpose services available to every PEIM.
  289. @param PlatformInfoHob - Platform Type is returned in PlatformInfoHob->BoardId
  290. @retval Status EFI_SUCCESS - PDR read success
  291. @retval Status EFI_INCOMPATIBLE_VERSION - PDR read but it is not valid Platform Type
  292. **/
  293. EFI_STATUS
  294. PdrGetPlatformInfo (
  295. IN CONST EFI_PEI_SERVICES **PeiServices,
  296. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  297. )
  298. {
  299. EFI_STATUS Status;
  300. PCH_SPI_PROTOCOL *SpiPpi;
  301. UINTN Size;
  302. //
  303. // Locate the SPI PPI Interface
  304. //
  305. Status = (*PeiServices)->LocatePpi (
  306. PeiServices,
  307. &gPchSpiPpiGuid,
  308. 0,
  309. NULL,
  310. &SpiPpi
  311. );
  312. if (EFI_ERROR (Status)) {
  313. ASSERT_EFI_ERROR (Status);
  314. return Status;
  315. }
  316. //
  317. // Read the PIT (Platform Info Table) from the SPI Flash Platform Data Region
  318. //
  319. Size = sizeof (EFI_PLATFORM_INFO);
  320. Status = SpiPpi->FlashRead (
  321. SpiPpi,
  322. FlashRegionPlatformData,
  323. PDR_REGION_START_OFFSET,
  324. (UINT32) Size,
  325. (UINT8 *) PlatformInfoHob
  326. );
  327. if (EFI_ERROR (Status)) {
  328. ASSERT_EFI_ERROR (Status);
  329. return Status;
  330. }
  331. if ((PlatformInfoHob->BoardId >= TypePlatformMin) && (PlatformInfoHob->BoardId <= TypePlatformMax)) {
  332. //
  333. // Valid Platform Identified
  334. //
  335. DEBUG ((DEBUG_INFO, "Platform Info from PDR: Type = %x\n",PlatformInfoHob->BoardId));
  336. } else {
  337. //
  338. // Reading PIT from SPI PDR Failed or a unknown platform identified
  339. //
  340. DEBUG ((EFI_D_ERROR, "PIT from SPI PDR reports Platform ID as %x. This is unknown ID. Assuming Greencity Platform!\n", PlatformInfoHob->BoardId));
  341. PlatformInfoHob->BoardId = TypePlatformUnknown;
  342. Status = EFI_INCOMPATIBLE_VERSION;
  343. }
  344. return Status;
  345. }
  346. VOID
  347. GatherQATInfo(OUT EFI_PLATFORM_INFO *PlatformInfoHob)
  348. /**
  349. GC_TODO: add routine description
  350. @param None
  351. @ret None
  352. **/
  353. {
  354. EFI_STATUS Status;
  355. GPIO_CONFIG PadConfig;
  356. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  357. // Gpio programming to QAT board detection
  358. PadConfig.PadMode = GpioPadModeGpio;
  359. PadConfig.HostSoftPadOwn = GpioHostOwnDefault;
  360. PadConfig.Direction = GpioDirIn;
  361. PadConfig.OutputState = GpioOutLow;
  362. PadConfig.InterruptConfig = GpioIntDis;
  363. PadConfig.PowerConfig = GpioResetPwrGood;
  364. PadConfig.ElectricalConfig = GpioTermNone;
  365. PadConfig.LockConfig = GpioPadConfigLock;
  366. PadConfig.OtherSettings = 00;
  367. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  368. if (EFI_ERROR (Status)) {
  369. ASSERT_EFI_ERROR (Status);
  370. return;
  371. }
  372. Status = DynamicSiLibraryPpi->GpioSetPadConfig (GPIO_SKL_H_GPP_B3, &PadConfig);
  373. Status = DynamicSiLibraryPpi->GpioGetInputValue (GPIO_SKL_H_GPP_B3, &PlatformInfoHob->QATDis);
  374. Status = DynamicSiLibraryPpi->GpioSetPadConfig (GPIO_SKL_H_GPP_B4, &PadConfig);
  375. Status = DynamicSiLibraryPpi->GpioGetInputValue (GPIO_SKL_H_GPP_B4, &PlatformInfoHob->QATSel);
  376. }
  377. EFI_STATUS
  378. GetPlatformInfo (
  379. IN CONST EFI_PEI_SERVICES **PeiServices,
  380. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  381. )
  382. /**
  383. GC_TODO: add routine description
  384. @param PeiServices - GC_TODO: add arg description
  385. @param PlatformInfoHob - GC_TODO: add arg description
  386. @retval EFI_UNSUPPORTED - GC_TODO: add retval description
  387. @retval EFI_SUCCESS - GC_TODO: add retval description
  388. **/
  389. {
  390. UINT32 BoardId;
  391. UINT32 BoardRev;
  392. EFI_PEI_PCI_CFG2_PPI *PciCfgPpi;
  393. EFI_STATUS Status;
  394. PciCfgPpi = (**PeiServices).PciCfg;
  395. ASSERT (PciCfgPpi != NULL);
  396. PlatformInfoHob->BoardId = TypeNeonCityEPRP;
  397. //
  398. //Check if BoardId is fixed during build time.
  399. //
  400. BoardId = FixedPcdGet8 (PcdBoardId);
  401. if (BoardId != 0) {
  402. PlatformInfoHob->BoardId = (UINT8)BoardId;
  403. PlatformInfoHob->TypeRevisionId = FixedPcdGet8 (PcdBoardRevId);
  404. DEBUG((DEBUG_INFO, "Board ID = %2x Board Rev = %x \n", PlatformInfoHob->BoardId, PlatformInfoHob->TypeRevisionId));
  405. return EFI_SUCCESS;
  406. }
  407. DEBUG ((DEBUG_INFO, "Use GPIO to read Board ID\n"));
  408. Status = GpioGetBoardId (&BoardId);
  409. if (EFI_ERROR (Status)) {
  410. DEBUG ((EFI_D_ERROR, "Error: Can't read GPIO to get Board ID!\n"));
  411. return Status;
  412. }
  413. Status = GpioGetBoardRevId (&BoardRev);
  414. if (EFI_ERROR(Status)) {
  415. DEBUG ((EFI_D_ERROR, "Error: Can't read GPIO to get Board ID!\n"));
  416. return Status;
  417. }
  418. PlatformInfoHob->TypeRevisionId = BoardRev;
  419. switch (BoardId) {
  420. case 0x00: // for Simics
  421. PlatformInfoHob->BoardId = TypeWilsonCityRP;
  422. break;
  423. case 0x01:
  424. PlatformInfoHob->BoardId = TypeWilsonCityRP;
  425. DEBUG ((DEBUG_INFO, "Board ID = TypeWilsonCityRP\n"));
  426. break;
  427. case 0x12:
  428. PlatformInfoHob->BoardId = TypeWilsonCityRP;
  429. DEBUG((DEBUG_INFO, "Board ID = TypeWilsonCityRP\n"));
  430. break;
  431. case 0x15:
  432. PlatformInfoHob->BoardId = TypeWilsonCitySMT;
  433. DEBUG((DEBUG_INFO, "Board ID = TypeWilsonCitySMT\n"));
  434. break;
  435. case 0x17:
  436. case 0x18:
  437. PlatformInfoHob->BoardId = TypeCooperCityRP;
  438. DEBUG((DEBUG_INFO, "Board ID = TypeCooperCityRP\n"));
  439. break;
  440. default:
  441. PlatformInfoHob->BoardId = TypePlatformDefault;
  442. DEBUG ((DEBUG_INFO, "Board ID = %2X Default set to TypePlatformDefault\n",BoardId));
  443. break;
  444. }
  445. GatherQATInfo(PlatformInfoHob);
  446. DEBUG ((DEBUG_INFO, "Board Rev.: %d\n", BoardRev));
  447. return EFI_SUCCESS;
  448. }
  449. /**
  450. This function initializes the board related flag to indicates if
  451. PCH and Lan-On-Motherboard (LOM) devices is supported.
  452. **/
  453. VOID
  454. GetPchLanSupportInfo(
  455. IN EFI_PLATFORM_INFO *PlatformInfoHob
  456. )
  457. {
  458. PlatformInfoHob->PchData.LomLanSupported = 0;
  459. }
  460. /**
  461. GC_TODO: add routine description
  462. @param PeiVariable - GC_TODO: add arg description
  463. @param PlatformInfoHob - GC_TODO: add arg description
  464. @retval EFI_SUCCESS - GC_TODO: add retval description
  465. **/
  466. EFI_STATUS
  467. EFIAPI
  468. GetIioCommonRcPlatformSetupPolicy(
  469. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  470. )
  471. {
  472. UINT8 IsocEn;
  473. CopyMem (&IsocEn, (UINT8 *)PcdGetPtr(PcdSocketCommonRcConfig) + OFFSET_OF(SOCKET_COMMONRC_CONFIGURATION, IsocEn), sizeof(UINT8));
  474. PlatformInfoHob->SysData.IsocEn = IsocEn; // ISOC enabled
  475. return EFI_SUCCESS;
  476. }
  477. /**
  478. GC_TODO: add routine description
  479. @param PeiVariable - GC_TODO: add arg description
  480. @param PlatformInfoHob - GC_TODO: add arg description
  481. @retval EFI_SUCCESS - GC_TODO: add retval description
  482. **/
  483. EFI_STATUS
  484. EFIAPI
  485. GetIioPlatformSetupPolicy(
  486. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  487. )
  488. {
  489. return EFI_SUCCESS;
  490. }
  491. /**
  492. Platform Type detection. Because the PEI globle variable
  493. is in the flash, it could not change directly.So use
  494. 2 PPIs to distinguish the platform type.
  495. @param FfsHeader - Pointer to Firmware File System file header.
  496. @param PeiServices - General purpose services available to every PEIM.
  497. @retval EFI_SUCCESS - Memory initialization completed successfully.
  498. @retval Others - All other error conditions encountered result in an ASSERT.
  499. **/
  500. EFI_STATUS
  501. EFIAPI
  502. PlatformInfoInit (
  503. IN EFI_PEI_FILE_HANDLE FileHandle,
  504. IN CONST EFI_PEI_SERVICES **PeiServices
  505. )
  506. {
  507. EFI_STATUS Status;
  508. EFI_PEI_PCI_CFG2_PPI *PciCfgPpi;
  509. EFI_PEI_READ_ONLY_VARIABLE2_PPI *PeiVariable;
  510. EFI_PLATFORM_INFO PlatformInfoHob;
  511. EFI_PLATFORM_INFO tempPlatformInfoHob;
  512. UINT8 ChipId;
  513. UINT32 Delay;
  514. UINT32 CpuType;
  515. UINT8 CpuStepping;
  516. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  517. PciCfgPpi = (**PeiServices).PciCfg;
  518. if (PciCfgPpi == NULL) {
  519. DEBUG ((EFI_D_ERROR, "\nError! PlatformInfoInit() - PeiServices is a NULL Pointer!!!\n"));
  520. ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
  521. return EFI_INVALID_PARAMETER;
  522. }
  523. //
  524. // Locate Variable PPI
  525. //
  526. Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, &PeiVariable);
  527. (*PeiServices)->SetMem (&PlatformInfoHob, sizeof (PlatformInfoHob), 0);
  528. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  529. if (EFI_ERROR (Status)) {
  530. ASSERT_EFI_ERROR (Status);
  531. return Status;
  532. }
  533. //
  534. // --------------------------------------------------
  535. //
  536. // Detect the iBMC SIO for CV/CRB Platforms
  537. // 0x2E/0x2F decoding has been enabled in MonoStatusCode PEIM.
  538. //
  539. IoWrite8 (PILOTIV_SIO_INDEX_PORT, PILOTIV_SIO_UNLOCK);
  540. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  541. IoWrite8 (PILOTIV_SIO_INDEX_PORT, PILOTIV_CHIP_ID_REG);
  542. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  543. ChipId = IoRead8 (PILOTIV_SIO_DATA_PORT);
  544. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  545. IoWrite8 (PILOTIV_SIO_INDEX_PORT, PILOTIV_SIO_LOCK);
  546. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  547. if (EFI_ERROR (Status))
  548. {
  549. DEBUG((EFI_D_ERROR, "LocatePpi Error in PlatformInfo.c !\n"));
  550. }
  551. Status = GetIioPlatformSetupPolicy (&PlatformInfoHob);
  552. ASSERT_EFI_ERROR (Status);
  553. Status = GetIioCommonRcPlatformSetupPolicy (&PlatformInfoHob);
  554. ASSERT_EFI_ERROR (Status);
  555. //
  556. // Update PCH Type
  557. //
  558. PlatformInfoHob.PchType = DynamicSiLibraryPpi->GetPchSeries ();
  559. PlatformInfoHob.PchSku = DynamicSiLibraryPpi->GetPchLpcDeviceId ();
  560. PlatformInfoHob.PchRevision = (UINT8) DynamicSiLibraryPpi->PchStepping ();
  561. PlatformInfoHob.MaxNumOfPchs = 1;
  562. Status = EFI_SUCCESS;
  563. if(!EFI_ERROR(Status)) {
  564. Status = GetPlatformInfo (PeiServices, &PlatformInfoHob);
  565. if(EFI_ERROR (Status)) {
  566. Status = PdrGetPlatformInfo (PeiServices, &tempPlatformInfoHob);
  567. PlatformInfoHob.BoardId = tempPlatformInfoHob.BoardId;
  568. PlatformInfoHob.TypeRevisionId = tempPlatformInfoHob.TypeRevisionId;
  569. if (EFI_ERROR(Status)) {
  570. PlatformInfoHob.BoardId = TypePlatformUnknown;
  571. }
  572. }
  573. } else {
  574. PlatformInfoHob.BoardId = TypePlatformUnknown;
  575. }
  576. //
  577. // Update IIO Type
  578. //
  579. PlatformInfoHob.IioRevision = 0;
  580. //
  581. // Get Subtractive decode enable bit from descriptor
  582. //
  583. if (DynamicSiLibraryPpi->PchIsGbeRegionValid () == FALSE) {
  584. PlatformInfoHob.PchData.GbeRegionInvalid = 1;
  585. } else {
  586. PlatformInfoHob.PchData.GbeRegionInvalid = 0;
  587. }
  588. GetPchLanSupportInfo (&PlatformInfoHob);
  589. PlatformInfoHob.PchData.GbePciePortNum = 0xFF;
  590. PlatformInfoHob.PchData.GbePciePortNum = (UINT8) DynamicSiLibraryPpi->PchGetGbePortNumber ();
  591. PlatformInfoHob.PchData.GbeEnabled = DynamicSiLibraryPpi->PchIsGbePresent ();
  592. PlatformInfoHob.PchData.PchStepping = (UINT8) DynamicSiLibraryPpi->PchStepping ();
  593. PlatformInfoHob.SysData.SysSioExist = (UINT8)IsSioExist();
  594. GetCpuInfo (&CpuType, &CpuStepping);
  595. PlatformInfoHob.CpuType = CpuType;
  596. PlatformInfoHob.CpuStepping = CpuStepping;
  597. //
  598. // Set default memory topology to DaisyChainTopology. This should be modified in UBA board
  599. // specific file.
  600. //
  601. (*PeiServices)->SetMem (&PlatformInfoHob.MemoryTopology, sizeof (PlatformInfoHob.MemoryTopology), DaisyChainTopology);
  602. //
  603. // Set default memory type connector to DimmConnectorPth. This should be modified in UBA board
  604. // specific file.
  605. //
  606. (*PeiServices)->SetMem (&PlatformInfoHob.MemoryConnectorType, sizeof (PlatformInfoHob.MemoryConnectorType), DimmConnectorPth);
  607. //
  608. // Build HOB for setup memory information
  609. //
  610. BuildGuidDataHob (
  611. &gEfiPlatformInfoGuid,
  612. &(PlatformInfoHob),
  613. sizeof (EFI_PLATFORM_INFO)
  614. );
  615. Status = (**PeiServices).InstallPpi (PeiServices, &mPlatformInfoPpi);
  616. ASSERT_EFI_ERROR (Status);
  617. //
  618. // Save PlatformInfoHob.BoardId in CMOS
  619. //
  620. IoWrite8 (R_IOPORT_CMOS_UPPER_INDEX, CMOS_PLATFORM_ID_LO);
  621. IoWrite8 (R_IOPORT_CMOS_UPPER_DATA, (UINT8)PlatformInfoHob.BoardId);
  622. IoWrite8 (R_IOPORT_CMOS_UPPER_INDEX, CMOS_PLATFORM_ID_HI);
  623. IoWrite8 (R_IOPORT_CMOS_UPPER_DATA, (UINT8)((PlatformInfoHob.PcieRiser2Type << 4) + (PlatformInfoHob.PcieRiser1Type)));
  624. return EFI_SUCCESS;
  625. }