PlatformInfo.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. ((PlatformInfoHob->BoardId >= TypePlatformVendorMin) && (PlatformInfoHob->BoardId <= TypePlatformVendorMax))) {
  333. //
  334. // Valid Platform Identified
  335. //
  336. DEBUG ((DEBUG_INFO, "Platform Info from PDR: Type = %x\n",PlatformInfoHob->BoardId));
  337. } else {
  338. //
  339. // Reading PIT from SPI PDR Failed or a unknown platform identified
  340. //
  341. DEBUG ((EFI_D_ERROR, "PIT from SPI PDR reports Platform ID as %x. This is unknown ID. Assuming Greencity Platform!\n", PlatformInfoHob->BoardId));
  342. PlatformInfoHob->BoardId = TypePlatformUnknown;
  343. Status = EFI_INCOMPATIBLE_VERSION;
  344. }
  345. return Status;
  346. }
  347. VOID
  348. GatherQATInfo(OUT EFI_PLATFORM_INFO *PlatformInfoHob)
  349. /**
  350. GC_TODO: add routine description
  351. @param None
  352. @ret None
  353. **/
  354. {
  355. EFI_STATUS Status;
  356. GPIO_CONFIG PadConfig;
  357. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  358. // Gpio programming to QAT board detection
  359. PadConfig.PadMode = GpioPadModeGpio;
  360. PadConfig.HostSoftPadOwn = GpioHostOwnDefault;
  361. PadConfig.Direction = GpioDirIn;
  362. PadConfig.OutputState = GpioOutLow;
  363. PadConfig.InterruptConfig = GpioIntDis;
  364. PadConfig.PowerConfig = GpioResetPwrGood;
  365. PadConfig.ElectricalConfig = GpioTermNone;
  366. PadConfig.LockConfig = GpioPadConfigLock;
  367. PadConfig.OtherSettings = 00;
  368. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  369. if (EFI_ERROR (Status)) {
  370. ASSERT_EFI_ERROR (Status);
  371. return;
  372. }
  373. Status = DynamicSiLibraryPpi->GpioSetPadConfig (GPIO_SKL_H_GPP_B3, &PadConfig);
  374. Status = DynamicSiLibraryPpi->GpioGetInputValue (GPIO_SKL_H_GPP_B3, &PlatformInfoHob->QATDis);
  375. Status = DynamicSiLibraryPpi->GpioSetPadConfig (GPIO_SKL_H_GPP_B4, &PadConfig);
  376. Status = DynamicSiLibraryPpi->GpioGetInputValue (GPIO_SKL_H_GPP_B4, &PlatformInfoHob->QATSel);
  377. }
  378. EFI_STATUS
  379. GetPlatformInfo (
  380. IN CONST EFI_PEI_SERVICES **PeiServices,
  381. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  382. )
  383. /**
  384. GC_TODO: add routine description
  385. @param PeiServices - GC_TODO: add arg description
  386. @param PlatformInfoHob - GC_TODO: add arg description
  387. @retval EFI_UNSUPPORTED - GC_TODO: add retval description
  388. @retval EFI_SUCCESS - GC_TODO: add retval description
  389. **/
  390. {
  391. UINT32 BoardId;
  392. UINT32 BoardRev;
  393. EFI_PEI_PCI_CFG2_PPI *PciCfgPpi;
  394. EFI_STATUS Status;
  395. PciCfgPpi = (**PeiServices).PciCfg;
  396. ASSERT (PciCfgPpi != NULL);
  397. PlatformInfoHob->BoardId = TypeNeonCityEPRP;
  398. //
  399. //Check if BoardId is fixed during build time.
  400. //
  401. BoardId = FixedPcdGet8 (PcdBoardId);
  402. if (BoardId != 0) {
  403. PlatformInfoHob->BoardId = (UINT8)BoardId;
  404. PlatformInfoHob->TypeRevisionId = FixedPcdGet8 (PcdBoardRevId);
  405. DEBUG((DEBUG_INFO, "Board ID = %2x Board Rev = %x \n", PlatformInfoHob->BoardId, PlatformInfoHob->TypeRevisionId));
  406. return EFI_SUCCESS;
  407. }
  408. DEBUG ((DEBUG_INFO, "Use GPIO to read Board ID\n"));
  409. Status = GpioGetBoardId (&BoardId);
  410. if (EFI_ERROR (Status)) {
  411. DEBUG ((EFI_D_ERROR, "Error: Can't read GPIO to get Board ID!\n"));
  412. return Status;
  413. }
  414. Status = GpioGetBoardRevId (&BoardRev);
  415. if (EFI_ERROR(Status)) {
  416. DEBUG ((EFI_D_ERROR, "Error: Can't read GPIO to get Board ID!\n"));
  417. return Status;
  418. }
  419. PlatformInfoHob->TypeRevisionId = BoardRev;
  420. switch (BoardId) {
  421. case 0x00: // for Simics
  422. PlatformInfoHob->BoardId = TypeWilsonCityRP;
  423. break;
  424. case 0x01:
  425. PlatformInfoHob->BoardId = TypeWilsonCityRP;
  426. DEBUG ((DEBUG_INFO, "Board ID = TypeWilsonCityRP\n"));
  427. break;
  428. case 0x12:
  429. PlatformInfoHob->BoardId = TypeWilsonCityRP;
  430. DEBUG((DEBUG_INFO, "Board ID = TypeWilsonCityRP\n"));
  431. break;
  432. case 0x15:
  433. PlatformInfoHob->BoardId = TypeWilsonCitySMT;
  434. DEBUG((DEBUG_INFO, "Board ID = TypeWilsonCitySMT\n"));
  435. break;
  436. case 0x17:
  437. case 0x18:
  438. PlatformInfoHob->BoardId = TypeCooperCityRP;
  439. DEBUG((DEBUG_INFO, "Board ID = TypeCooperCityRP\n"));
  440. break;
  441. default:
  442. PlatformInfoHob->BoardId = TypePlatformDefault;
  443. DEBUG ((DEBUG_INFO, "Board ID = %2X Default set to TypePlatformDefault\n",BoardId));
  444. break;
  445. }
  446. GatherQATInfo(PlatformInfoHob);
  447. DEBUG ((DEBUG_INFO, "Board Rev.: %d\n", BoardRev));
  448. return EFI_SUCCESS;
  449. }
  450. /**
  451. This function initializes the board related flag to indicates if
  452. PCH and Lan-On-Motherboard (LOM) devices is supported.
  453. **/
  454. VOID
  455. GetPchLanSupportInfo(
  456. IN EFI_PLATFORM_INFO *PlatformInfoHob
  457. )
  458. {
  459. PlatformInfoHob->PchData.LomLanSupported = 0;
  460. }
  461. /**
  462. GC_TODO: add routine description
  463. @param PeiVariable - GC_TODO: add arg description
  464. @param PlatformInfoHob - GC_TODO: add arg description
  465. @retval EFI_SUCCESS - GC_TODO: add retval description
  466. **/
  467. EFI_STATUS
  468. EFIAPI
  469. GetIioCommonRcPlatformSetupPolicy(
  470. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  471. )
  472. {
  473. UINT8 IsocEn;
  474. CopyMem (&IsocEn, (UINT8 *)PcdGetPtr(PcdSocketCommonRcConfig) + OFFSET_OF(SOCKET_COMMONRC_CONFIGURATION, IsocEn), sizeof(UINT8));
  475. PlatformInfoHob->SysData.IsocEn = IsocEn; // ISOC enabled
  476. return EFI_SUCCESS;
  477. }
  478. /**
  479. GC_TODO: add routine description
  480. @param PeiVariable - GC_TODO: add arg description
  481. @param PlatformInfoHob - GC_TODO: add arg description
  482. @retval EFI_SUCCESS - GC_TODO: add retval description
  483. **/
  484. EFI_STATUS
  485. EFIAPI
  486. GetIioPlatformSetupPolicy(
  487. OUT EFI_PLATFORM_INFO *PlatformInfoHob
  488. )
  489. {
  490. return EFI_SUCCESS;
  491. }
  492. /**
  493. Platform Type detection. Because the PEI globle variable
  494. is in the flash, it could not change directly.So use
  495. 2 PPIs to distinguish the platform type.
  496. @param FfsHeader - Pointer to Firmware File System file header.
  497. @param PeiServices - General purpose services available to every PEIM.
  498. @retval EFI_SUCCESS - Memory initialization completed successfully.
  499. @retval Others - All other error conditions encountered result in an ASSERT.
  500. **/
  501. EFI_STATUS
  502. EFIAPI
  503. PlatformInfoInit (
  504. IN EFI_PEI_FILE_HANDLE FileHandle,
  505. IN CONST EFI_PEI_SERVICES **PeiServices
  506. )
  507. {
  508. EFI_STATUS Status;
  509. EFI_PEI_PCI_CFG2_PPI *PciCfgPpi;
  510. EFI_PEI_READ_ONLY_VARIABLE2_PPI *PeiVariable;
  511. EFI_PLATFORM_INFO PlatformInfoHob;
  512. EFI_PLATFORM_INFO tempPlatformInfoHob;
  513. UINT8 ChipId;
  514. UINT32 Delay;
  515. UINT32 CpuType;
  516. UINT8 CpuStepping;
  517. DYNAMIC_SI_LIBARY_PPI *DynamicSiLibraryPpi = NULL;
  518. PciCfgPpi = (**PeiServices).PciCfg;
  519. if (PciCfgPpi == NULL) {
  520. DEBUG ((EFI_D_ERROR, "\nError! PlatformInfoInit() - PeiServices is a NULL Pointer!!!\n"));
  521. ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
  522. return EFI_INVALID_PARAMETER;
  523. }
  524. //
  525. // Locate Variable PPI
  526. //
  527. Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, &PeiVariable);
  528. (*PeiServices)->SetMem (&PlatformInfoHob, sizeof (PlatformInfoHob), 0);
  529. Status = PeiServicesLocatePpi (&gDynamicSiLibraryPpiGuid, 0, NULL, &DynamicSiLibraryPpi);
  530. if (EFI_ERROR (Status)) {
  531. ASSERT_EFI_ERROR (Status);
  532. return Status;
  533. }
  534. //
  535. // --------------------------------------------------
  536. //
  537. // Detect the iBMC SIO for CV/CRB Platforms
  538. // 0x2E/0x2F decoding has been enabled in MonoStatusCode PEIM.
  539. //
  540. IoWrite8 (PILOTIV_SIO_INDEX_PORT, PILOTIV_SIO_UNLOCK);
  541. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  542. IoWrite8 (PILOTIV_SIO_INDEX_PORT, PILOTIV_CHIP_ID_REG);
  543. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  544. ChipId = IoRead8 (PILOTIV_SIO_DATA_PORT);
  545. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  546. IoWrite8 (PILOTIV_SIO_INDEX_PORT, PILOTIV_SIO_LOCK);
  547. for (Delay = 0; Delay < 40; Delay++) IoRead8 (0x61);
  548. if (EFI_ERROR (Status))
  549. {
  550. DEBUG((EFI_D_ERROR, "LocatePpi Error in PlatformInfo.c !\n"));
  551. }
  552. Status = GetIioPlatformSetupPolicy (&PlatformInfoHob);
  553. ASSERT_EFI_ERROR (Status);
  554. Status = GetIioCommonRcPlatformSetupPolicy (&PlatformInfoHob);
  555. ASSERT_EFI_ERROR (Status);
  556. //
  557. // Update PCH Type
  558. //
  559. PlatformInfoHob.PchType = DynamicSiLibraryPpi->GetPchSeries ();
  560. PlatformInfoHob.PchSku = DynamicSiLibraryPpi->GetPchLpcDeviceId ();
  561. PlatformInfoHob.PchRevision = (UINT8) DynamicSiLibraryPpi->PchStepping ();
  562. PlatformInfoHob.MaxNumOfPchs = 1;
  563. Status = EFI_SUCCESS;
  564. if(!EFI_ERROR(Status)) {
  565. Status = GetPlatformInfo (PeiServices, &PlatformInfoHob);
  566. if(EFI_ERROR (Status)) {
  567. Status = PdrGetPlatformInfo (PeiServices, &tempPlatformInfoHob);
  568. PlatformInfoHob.BoardId = tempPlatformInfoHob.BoardId;
  569. PlatformInfoHob.TypeRevisionId = tempPlatformInfoHob.TypeRevisionId;
  570. if (EFI_ERROR(Status)) {
  571. PlatformInfoHob.BoardId = TypePlatformUnknown;
  572. }
  573. }
  574. } else {
  575. PlatformInfoHob.BoardId = TypePlatformUnknown;
  576. }
  577. //
  578. // Update IIO Type
  579. //
  580. PlatformInfoHob.IioRevision = 0;
  581. //
  582. // Get Subtractive decode enable bit from descriptor
  583. //
  584. if (DynamicSiLibraryPpi->PchIsGbeRegionValid () == FALSE) {
  585. PlatformInfoHob.PchData.GbeRegionInvalid = 1;
  586. } else {
  587. PlatformInfoHob.PchData.GbeRegionInvalid = 0;
  588. }
  589. GetPchLanSupportInfo (&PlatformInfoHob);
  590. PlatformInfoHob.PchData.GbePciePortNum = 0xFF;
  591. PlatformInfoHob.PchData.GbePciePortNum = (UINT8) DynamicSiLibraryPpi->PchGetGbePortNumber ();
  592. PlatformInfoHob.PchData.GbeEnabled = DynamicSiLibraryPpi->PchIsGbePresent ();
  593. PlatformInfoHob.PchData.PchStepping = (UINT8) DynamicSiLibraryPpi->PchStepping ();
  594. PlatformInfoHob.SysData.SysSioExist = (UINT8)IsSioExist();
  595. GetCpuInfo (&CpuType, &CpuStepping);
  596. PlatformInfoHob.CpuType = CpuType;
  597. PlatformInfoHob.CpuStepping = CpuStepping;
  598. //
  599. // Set default memory topology to DaisyChainTopology. This should be modified in UBA board
  600. // specific file.
  601. //
  602. (*PeiServices)->SetMem (&PlatformInfoHob.MemoryTopology, sizeof (PlatformInfoHob.MemoryTopology), DaisyChainTopology);
  603. //
  604. // Set default memory type connector to DimmConnectorPth. This should be modified in UBA board
  605. // specific file.
  606. //
  607. (*PeiServices)->SetMem (&PlatformInfoHob.MemoryConnectorType, sizeof (PlatformInfoHob.MemoryConnectorType), DimmConnectorPth);
  608. //
  609. // Build HOB for setup memory information
  610. //
  611. BuildGuidDataHob (
  612. &gEfiPlatformInfoGuid,
  613. &(PlatformInfoHob),
  614. sizeof (EFI_PLATFORM_INFO)
  615. );
  616. Status = (**PeiServices).InstallPpi (PeiServices, &mPlatformInfoPpi);
  617. ASSERT_EFI_ERROR (Status);
  618. //
  619. // Save PlatformInfoHob.BoardId in CMOS
  620. //
  621. IoWrite8 (R_IOPORT_CMOS_UPPER_INDEX, CMOS_PLATFORM_ID_LO);
  622. IoWrite8 (R_IOPORT_CMOS_UPPER_DATA, (UINT8)PlatformInfoHob.BoardId);
  623. IoWrite8 (R_IOPORT_CMOS_UPPER_INDEX, CMOS_PLATFORM_ID_HI);
  624. IoWrite8 (R_IOPORT_CMOS_UPPER_DATA, (UINT8)((PlatformInfoHob.PcieRiser2Type << 4) + (PlatformInfoHob.PcieRiser1Type)));
  625. return EFI_SUCCESS;
  626. }