PlatformInfo.c 21 KB

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