1 /** @file 2 3 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR> 4 SPDX-License-Identifier: BSD-2-Clause-Patent 5 6 **/ 7 8 #include <PiPei.h> 9 #include <SaPolicyCommon.h> 10 #include <Library/DebugLib.h> 11 #include <Library/BaseMemoryLib.h> 12 #include <Library/IoLib.h> 13 #include <Library/HobLib.h> 14 #include <Library/PcdLib.h> 15 #include <Library/PchCycleDecodingLib.h> 16 #include <Library/PciLib.h> 17 #include <Library/PcdLib.h> 18 #include <Library/BaseMemoryLib.h> 19 20 #include <Library/PeiSaPolicyLib.h> 21 #include <Library/BoardInitLib.h> 22 #include <PchAccess.h> 23 #include <Library/GpioNativeLib.h> 24 #include <Library/GpioLib.h> 25 #include <GpioPinsSklLp.h> 26 #include <GpioPinsSklH.h> 27 #include <Library/GpioExpanderLib.h> 28 #include <SioRegs.h> 29 #include <Library/PchPcrLib.h> 30 #include <Library/SiliconInitLib.h> 31 32 #include "PeiKabylakeRvp3InitLib.h" 33 34 #include <ConfigBlock.h> 35 #include <ConfigBlock/MemoryConfig.h> 36 #include <Library/EcLib.h> 37 #include <EcCommands.h> 38 39 #define BOARD_ID_MASK_8BIT 0xff 40 41 /** 42 Get board fab ID. 43 44 @param[out] DataBuffer 45 46 @retval EFI_SUCCESS Command success 47 @retval EFI_DEVICE_ERROR Command error 48 **/ 49 EFI_STATUS GetBoardFabId(OUT UINT8 * DataBuffer)50GetBoardFabId ( 51 OUT UINT8 *DataBuffer 52 ) 53 { 54 UINT8 DataSize; 55 56 // 57 // For 'EC_C_FAB_ID' command NumberOfSendData = 0, NumberOfReceiveData =2. 58 // 59 DataSize = 2; 60 return (LpcEcInterface (EC_C_FAB_ID, &DataSize, DataBuffer)); 61 } 62 63 /** 64 Get RVP3 board ID. 65 There are 2 different RVP3 boards having different ID. 66 This function will return board ID to caller. 67 68 @param[out] DataBuffer 69 70 @retval EFI_SUCCESS Command success 71 @retval EFI_DEVICE_ERROR Command error 72 **/ 73 EFI_STATUS GetRvp3BoardId(UINT8 * BoardId)74GetRvp3BoardId ( 75 UINT8 *BoardId 76 ) 77 { 78 EFI_STATUS Status; 79 UINT16 EcBoardInfo; 80 UINT8 DataBuffer[2]; 81 82 Status = GetBoardFabId (DataBuffer); 83 if (Status == EFI_SUCCESS) { 84 EcBoardInfo = DataBuffer[0]; 85 EcBoardInfo = (EcBoardInfo << 8) | DataBuffer[1]; 86 // 87 // Get the following data: 88 // [7:0] - BOARD_IDx 89 // [8] - GEN_ID 90 // [11:9] - REV_FAB_IDx 91 // [12] - TP_SPD_PRSNT 92 // [15:13] - BOM_IDx 93 // 94 *BoardId = (UINT8) (EcBoardInfo & BOARD_ID_MASK_8BIT); 95 DEBUG ((DEBUG_INFO, "BoardId = %X\n", *BoardId)); 96 } 97 return Status; 98 } 99 100 EFI_STATUS 101 EFIAPI KabylakeRvp3BoardDetect(VOID)102KabylakeRvp3BoardDetect ( 103 VOID 104 ) 105 { 106 UINT8 BoardId; 107 108 if (LibPcdGetSku () != 0) { 109 return EFI_SUCCESS; 110 } 111 112 DEBUG ((DEBUG_INFO, "KabylakeRvp3DetectionCallback\n")); 113 if (GetRvp3BoardId (&BoardId) == EFI_SUCCESS) { 114 if (BoardId == BoardIdKabyLakeYLpddr3Rvp3) { 115 LibPcdSetSku (BoardIdKabyLakeYLpddr3Rvp3); 116 ASSERT (LibPcdGetSku() == BoardIdKabyLakeYLpddr3Rvp3); 117 } else if (BoardId == BoardIdSkylakeRvp3) { 118 LibPcdSetSku (BoardIdSkylakeRvp3); 119 ASSERT (LibPcdGetSku() == BoardIdSkylakeRvp3); 120 } 121 DEBUG ((DEBUG_INFO, "SKU_ID: 0x%x\n", LibPcdGetSku())); 122 } 123 return EFI_SUCCESS; 124 } 125