From nobody Thu Apr 18 02:37:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1534499973636249.2691964184188; Fri, 17 Aug 2018 02:59:33 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0250A210F41F3; Fri, 17 Aug 2018 02:59:32 -0700 (PDT) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 65958210F30BB for ; Fri, 17 Aug 2018 02:59:30 -0700 (PDT) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Aug 2018 02:59:29 -0700 Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga007.jf.intel.com with ESMTP; 17 Aug 2018 02:59:21 -0700 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 17 Aug 2018 02:59:21 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 17 Aug 2018 02:59:20 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.240]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.185]) with mapi id 14.03.0319.002; Fri, 17 Aug 2018 17:59:17 +0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=mang.guo@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,250,1531810800"; d="dat'59?scan'59,208,59";a="65668982" From: "Guo, Mang" To: "edk2-devel@lists.01.org" Thread-Topic: [Patch][edk2-platforms/devel-IntelAtomProcessorE3900] EEPROM change Thread-Index: AdQ2EOmmya0skGjeTFOytuJusHwKKw== Date: Fri, 17 Aug 2018 09:59:17 +0000 Message-ID: <22D2C85ED001C54AA20BFE3B0E4751D1526D13F9@SHSMSX103.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <22D2C85ED001C54AA20BFE3B0E4751D1526D13F9@SHSMSX103.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.27 Subject: [edk2] [Patch][edk2-platforms/devel-IntelAtomProcessorE3900] EEPROM change X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Wei, David" Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Fixed 32-bit build failure in the EEPROM code. Cleaned up the EEPROM code . Define an EEPROM FPGA structure to hold FPGA bitstreams. Cc: David Wei Cc: Mike Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Kelly Steele Signed-off-by: Guo Mang --- .../Common/Features/Eeprom/EepromApp/EepromApp.c | 78 +- .../Eeprom/EepromBinary/Docs/EepromLayout.txt | 33 +- .../Docs/HowToInstallAnEepromBinary.txt | 1 + .../Common/Features/Eeprom/EepromBinary/ReadMe.txt | 189 ++++ .../EepromDataLib/EEPROM/EepromDataEepromLib.c | 20 +- .../EepromDataLib/EEPROM/EepromDataEepromLib.h | 3 +- .../Features/Eeprom/EepromDataLib/EEPROM/HobData.c | 2 +- .../Features/Eeprom/EepromDataLib/EEPROM/I2cLib.c | 1164 ----------------= ---- .../Features/Eeprom/EepromDataLib/EEPROM/I2cLib.h | 181 --- .../Features/Eeprom/EepromDataLib/EepromDataLib.c | 64 -- .../Features/Eeprom/EepromDataLib/EepromDataLib.h | 5 + .../Eeprom/EepromDataLib/EepromDataLib.inf | 7 +- .../EepromDataLib/EepromDataLibConstructor.c | 61 + .../Eeprom/EepromDataLib/EepromDataNullLib.inf | 3 + .../EepromDataLib/EepromDataNullLibConstructor.c | 36 + .../Eeprom/EepromDataLib/EepromDataNullPeiLib.inf | 46 + .../Eeprom/EepromDataLib/EepromDataPeiLib.inf | 7 +- .../Features/Eeprom/EepromDataLib/Memory/HobData.c | 2 +- .../Eeprom/EepromDataLib/MemoryAllocation.c | 17 + .../Eeprom/EepromDataLib/MemoryAllocationPei.c | 21 + .../Common/Features/Eeprom/EepromLib/EepromLib.c | 308 +++--- .../Common/Features/Eeprom/EepromLib/EepromLib.h | 9 +- .../Features/Eeprom/EepromLib/Null/EepromNullLib.c | 5 +- .../Eeprom/EepromLib/Pei/ValidateHashPei.c | 76 +- .../Features/Eeprom/EepromLib/ValidateHash.c | 149 ++- .../Common/Features/Eeprom/Include/EepromStruct.h | 45 +- .../Eeprom/Include/Library/EepromDataLib.h | 7 + .../Features/Eeprom/Include/Library/EepromLib.h | 24 +- .../Eeprom/Include/Library/EepromPlatformLib.h | 117 ++ 29 files changed, 942 insertions(+), 1738 deletions(-) delete mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eepr= omDataLib/EEPROM/I2cLib.c delete mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eepr= omDataLib/EEPROM/I2cLib.h create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eepr= omDataLib/EepromDataLibConstructor.c create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eepr= omDataLib/EepromDataNullLibConstructor.c create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eepr= omDataLib/EepromDataNullPeiLib.inf create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Incl= ude/Library/EepromPlatformLib.h diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/E= epromApp.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/E= epromApp.c index 9e1eb66..3b1b48b 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/EepromAp= p.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/EepromAp= p.c @@ -85,7 +85,7 @@ ShellAppMain ( // // Skip this if we are doing a scan. // - Print (L"- GetValidEepromLibrary() =3D %a\n", mEepromLibraryString[Get= ValidEepromLibrary (TRUE, TRUE)]); + Print (L"- GetValidEepromLibrary() =3D %a\n", mEepromLibraryString[Get= ValidEepromLibrary (TRUE)]); } else { // Scanning Status =3D ScanOption (&ProgramInfo); @@ -546,7 +546,7 @@ DumpHumanOption ( IN PROGRAM_INFO *ProgramInfo ) { - CHAR8 AsciiData[16]; + CHAR8 AsciiData[32]; VOID *Buffer; UINT32 BufferSize; UINT32 count; @@ -648,7 +648,7 @@ DumpHumanOption ( // // Check for $AcpiTbl // - if (AsciiStrnCmp (GenericHeader->signature, "$AcpiTbl", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_ACPI_TABLE_SIGNAT= URE, 8) =3D=3D 0) { ACPI_TABLE *AcpiTable; AcpiTable =3D (ACPI_TABLE *) Buffer; Ptr =3D (UINT8 *) Buffer + sizeof (ACPI_TABLE); @@ -657,7 +657,7 @@ DumpHumanOption ( // // Check for $BrdInfo // - if (AsciiStrnCmp (GenericHeader->signature, "$BrdInfo", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_BOARD_INFO_SIGNAT= URE, 8) =3D=3D 0) { BOARD_INFO_TABLE *BoardInfo; BoardInfo =3D (BOARD_INFO_TABLE *) Buffer; ZeroMem (AsciiData, 17); @@ -673,10 +673,10 @@ DumpHumanOption ( Print (L"Fab ID =3D %08x\n", BoardInfo->fabid); Print (L"EC ID =3D %08x\n", BoardInfo->ecid); Print (L"Board type =3D "); - if (BoardInfo->boardtype =3D=3D 0) { + if (BoardInfo->boardtype =3D=3D EEPROM_BOARD_TYPE_REDBOX) { Print (L"Main board (RedBox)\n"); } else - if (BoardInfo->boardtype =3D=3D 1) { + if (BoardInfo->boardtype =3D=3D EEPROM_BOARD_TYPE_PLUGIN) { Print (L"Plug-in board\n"); } else { @@ -686,7 +686,7 @@ DumpHumanOption ( // // Check for $EeprMap // - if (AsciiStrnCmp (GenericHeader->signature, "$EeprMap", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_MAP_SIGNATURE, 8)= =3D=3D 0) { EEPROM_MAP *EepromMap; EEPROM_MAP_RECORD *MapRecord; EepromMap =3D (EEPROM_MAP *) Buffer; @@ -709,13 +709,13 @@ DumpHumanOption ( Print (L"[%02x] - Unknown\n", EepromMap->master); } Print (L"I2C speed =3D "); - if (EepromMap->speed =3D=3D 1) { + if (EepromMap->speed =3D=3D EEPROM_SPEED_STANDARD) { Print (L"100KHz (Standard speed)\n"); } else - if (EepromMap->speed =3D=3D 2) { + if (EepromMap->speed =3D=3D EEPROM_SPEED_FAST) { Print (L"400KHz (Fast speed)\n"); } else - if (EepromMap->speed =3D=3D 3) { + if (EepromMap->speed =3D=3D EEPROM_SPEED_HIGH) { Print (L"3.4MHz (High speed)\n"); } else { @@ -740,7 +740,7 @@ DumpHumanOption ( // // Check for $Eeprom$ structure // - if (AsciiStrnCmp (GenericHeader->signature, "$Eeprom$", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_HEADER_SIGNATURE,= 8) =3D=3D 0) { EEPROM_HEADER *EepromHeader; EepromHeader =3D (EEPROM_HEADER *) Buffer; Print (L"Image length =3D %08x\n", EepromHeader->structleng= th); @@ -751,7 +751,7 @@ DumpHumanOption ( // // Check for $GpioDat // - if (AsciiStrnCmp (GenericHeader->signature, "$GpioDat", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_GPIO_SIGNATURE, 8= ) =3D=3D 0) { GPIO_DATA_HEADER *GpioHeader; GPIO_DATA_RECORD *GpioRecord; GpioHeader =3D (GPIO_DATA_HEADER *) Buffer; @@ -769,19 +769,19 @@ DumpHumanOption ( Print (L" - GPIO OR data =3D %08x\n", GpioRecord->ordata); Print (L" - GPIO data size =3D %08x\n", GpioRecord->datasize); Print (L" - GPIO data type =3D "); - if (GpioRecord->datasize =3D=3D 0) { + if (GpioRecord->datasize =3D=3D EEPROM_GPIO_TYPE_IO) { Print (L"IO\n"); } else - if (GpioRecord->datasize =3D=3D 1) { + if (GpioRecord->datasize =3D=3D EEPROM_GPIO_TYPE_MMIO) { Print (L"MMIO\n"); } else - if (GpioRecord->datasize =3D=3D 2) { + if (GpioRecord->datasize =3D=3D EEPROM_GPIO_TYPE_PCI) { Print (L"PCI\n"); } else - if (GpioRecord->datasize =3D=3D 3) { + if (GpioRecord->datasize =3D=3D EEPROM_GPIO_TYPE_PCIE) { Print (L"PCIe\n"); } else - if (GpioRecord->datasize =3D=3D 4) { + if (GpioRecord->datasize =3D=3D EEPROM_GPIO_TYPE_PAD_OFFSET) { Print (L"PAD offset\n"); } else { @@ -796,7 +796,7 @@ DumpHumanOption ( // // Check for $HdCodec // - if (AsciiStrnCmp (GenericHeader->signature, "$HdCodec", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_HDA_CODEC_SIGNATU= RE, 8) =3D=3D 0) { HDA_CODEC *HdaCodec; HdaCodec =3D (HDA_CODEC *) Buffer; Ptr =3D (UINT8 *) Buffer + sizeof (HDA_CODEC); @@ -805,7 +805,7 @@ DumpHumanOption ( // // Check for $Logo$ // - if (AsciiStrnCmp (GenericHeader->signature, "$Logo$", 6) =3D=3D 0) { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_LOGO_DATA_SIGNATU= RE, 6) =3D=3D 0) { LOGO_DATA *LogoData; LogoData =3D (LOGO_DATA *) Buffer; Ptr =3D (UINT8 *) Buffer + sizeof (LOGO_DATA); @@ -814,7 +814,7 @@ DumpHumanOption ( // // Check for $MacInfo // - if (AsciiStrnCmp (GenericHeader->signature, "$MacInfo", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_NIC_INFO_SIGNATUR= E, 8) =3D=3D 0) { NIC_INFO *NicInfo; NicInfo =3D (NIC_INFO *) Buffer; ZeroMem (AsciiData, 9); @@ -828,50 +828,54 @@ DumpHumanOption ( // // Check for $MemCnfg // - if (AsciiStrnCmp (GenericHeader->signature, "$MemCnfg", 8) =3D=3D 0)= { - UINT8 Slot; - MEMORY_SPD *MemoryData; - MemoryData =3D (MEMORY_SPD *) Buffer; + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_MEMORY_DATA_SIGNA= TURE, 8) =3D=3D 0) { + UINT8 Slot; + MEMORY_DATA *MemoryData; + MemoryData =3D (MEMORY_DATA *) Buffer; Print (L"SPD slot flags =3D %04x\n", MemoryData->spdslot); - for (Slot =3D 0; Slot < 16; Slot++) { - if (MemoryData->spdslot & (1 << Slot)) { - Print (L" - Slot %d support.\n", Slot + 1); + if (MemoryData->spdslot =3D=3D 0) { + Print (L" - SMIP binary.\n"); + } else { + for (Slot =3D 0; Slot < 16; Slot++) { + if (MemoryData->spdslot & (1 << Slot)) { + Print (L" - Slot %d support.\n", Slot + 1); + } } } - Ptr =3D (UINT8 *) Buffer + sizeof (MEMORY_SPD); + Ptr =3D (UINT8 *) Buffer + sizeof (MEMORY_DATA); if (ProgramInfo->VerboseFlag) DumpParagraph (Ptr, (MemoryData->len= gth - (Ptr - (UINT8 *) Buffer))); } else // // Check for $PromSig // - if (AsciiStrnCmp (GenericHeader->signature, "$PromSig", 8) =3D=3D 0)= { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_SIGNATURE_SIGNATU= RE, 8) =3D=3D 0) { UINT16 HashType; SIGNATURE_DATA *SignatureData; SignatureData =3D (SIGNATURE_DATA *) Buffer; Hash =3D (UINT8 *) Buffer + sizeof (SIGNATURE_DATA); HashType =3D (SignatureData->hashtype & 0x7FFF); Print (L"Hash type =3D "); - if (HashType =3D=3D HASH_NONE) { + if (HashType =3D=3D EEPROM_SIGNATURE_TYPE_NONE) { Print (L"None\n"); HashSize =3D 0; } else - if (HashType =3D=3D HASH_MD5) { + if (HashType =3D=3D EEPROM_SIGNATURE_TYPE_MD5) { Print (L"MD5\n"); HashSize =3D MD5DigestSize; } else - if (HashType =3D=3D HASH_SHA1) { + if (HashType =3D=3D EEPROM_SIGNATURE_TYPE_SHA1) { Print (L"SHA1\n"); HashSize =3D SHA1DigestSize; } else - if (HashType =3D=3D HASH_SHA256) { + if (HashType =3D=3D EEPROM_SIGNATURE_TYPE_SHA256) { Print (L"SHA256\n"); HashSize =3D SHA256DigestSize; } else - if (HashType =3D=3D HASH_SHA384) { + if (HashType =3D=3D EEPROM_SIGNATURE_TYPE_SHA384) { Print (L"SHA384\n"); HashSize =3D SHA384DigestSize; } else - if (HashType =3D=3D HASH_SHA512) { + if (HashType =3D=3D EEPROM_SIGNATURE_TYPE_SHA512) { Print (L"SHA512\n"); HashSize =3D SHA512DigestSize; } else @@ -912,7 +916,7 @@ DumpHumanOption ( // // Check for $uCode$ // - if (AsciiStrnCmp (GenericHeader->signature, "$uCode$", 7) =3D=3D 0) { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_MICROCODE_SIGNATU= RE, 7) =3D=3D 0) { MICROCODE *MicrocodeData; MicrocodeData =3D (MICROCODE *) Buffer; Ptr =3D (UINT8 *) Buffer + sizeof (MICROCODE); @@ -921,7 +925,7 @@ DumpHumanOption ( // // Check for $Video$ // - if (AsciiStrnCmp (GenericHeader->signature, "$Video$", 7) =3D=3D 0) { + if (AsciiStrnCmp (GenericHeader->signature, EEPROM_VIDEO_DATA_SIGNAT= URE, 7) =3D=3D 0) { VIDEO_DATA *VideoData; VideoData =3D (VIDEO_DATA *) Buffer; Ptr =3D (UINT8 *) Buffer + sizeof (VIDEO_DATA); diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinar= y/Docs/EepromLayout.txt b/Platform/BroxtonPlatformPkg/Common/Features/Eepro= m/EepromBinary/Docs/EepromLayout.txt index 19a64a5..7a4f004 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/= EepromLayout.txt +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/= EepromLayout.txt @@ -13,8 +13,8 @@ # ## =20 -Version: 1.00 -Dated: 07-02-2018 +Version: 1.10 +Dated: 07-31-2018 =20 - The first 4KB of the EEPROM data MUST be accessible from I2C bus gPlatformModuleTokenSpaceGuid.PcdEepromBus, address @@ -75,6 +75,7 @@ Dated: 07-02-2018 =20 - GPIO data records are applied in order. IE - Start at the beginning and = apply the records in order. + WARNING: Care must be exercised to ensure that non-whitelisted data is n= ot programmed. =20 - If characters in a Signature[8] or a Label[16] don't fill the entire all= ocated length, append string with $ as a sentinel value. IE - Signature[8] : "$uCode" s= hall be "$uCode$" @@ -165,6 +166,7 @@ Offset | Length | Label | Default value | Descripti= on 0x2A | 0x01 | BusNumber | 0x00 | I2C Device Bus 0x2B | 0x01 | Master | 0x00 | Set to 1 if EEPROM is master= , 0 otherwise 0x2C | 0x01 | Speed | 0x00 | The speed the EEPROM part sh= ould run at + | | | | 0 - Unknown | | | | 1 - 100KHz (Standard speed) | | | | 2 - 400KHz (Fast speed) | | | | 3 - 3.4MHz (High speed) @@ -180,6 +182,24 @@ Offset | Length | Label | Default value | Descript= ion 0x18 | 0x01 | Address | 0x00 | I2C Device address, 7-bit 0x19 | 0x07 | Reserved | 0x0000 | Reserved for future info =20 +FPGA info structure +Offset | Length | Label | Default value | Description +=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + 0x00 | 0x08 | Signature | "$FPGAnfo" | Marks the beginning of the F= PGA Info structure + 0x08 | 0x02 | VerMajor | 0x0001 | Version, major + 0x0A | 0x02 | VerMinor | 0x0000 | Version, minor + 0x0C | 0x04 | Length | 0x0000???? | Length in bytes of this stru= cture + 0x10 | 0x01 | DataType | 0x00 | How is the data getting to t= he FPGA? + | | | | 0 - Unknown + | | | | 1 - UART + | | | | 2 - I2C + | | | | 3 - SPI + | | | | 4 - PCI + 0x11 | 0x01 | DevNum | 0x00 | Device the FPGA connected to + 0x12 | 0x01 | FuncNum | 0x00 | Function/chip select the FPG= A connected to + 0x13 | 0x0D | Reserved | 0x00 | Reserved for future info + 0x20 | ???? | FpgaData | 0x00 | FPGA bitstream + GPIO data structure Offset | Length | Label | Default value | Description =3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -232,18 +252,19 @@ Offset | Length | Label | Default value | Descrip= tion 0x10 | 0x10 | Reserved | 0x00 | Reserved for future info 0x20 | ???? | LogoData | 0x00 | Logo data =20 -Memory SPD structure +Memory data structure Offset | Length | Label | Default value | Description =3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - 0x00 | 0x08 | Signature | "$MemCnfg" | Marks the beginning of the m= emory SPD structure + 0x00 | 0x08 | Signature | "$MemCnfg" | Marks the beginning of the m= emory data structure 0x08 | 0x02 | VerMajor | 0x0001 | Version, major 0x0A | 0x02 | VerMinor | 0x0000 | Version, minor 0x0C | 0x04 | Length | 0x0000???? | Length in bytes of this stru= cture - 0x10 | 0x02 | SpdSlot | 0x0000 | Which slot this SPD data bel= ongs to in bit flag format + 0x10 | 0x02 | SpdSlot | 0x0000 | Which slot this memory data = belongs to in bit flag format + | | | | - 0x0000 - SMIP data | | | | - 0x0001 - This is for Slot = 1 only | | | | - 0x0005 - This is for Slot = 1 & 3 only 0x12 | 0x0E | Reserved | 0x00 | Reserved for future info - 0x20 | ???? | SpdData | 0x00 | SPD data for memory + 0x20 | ???? | MemData | 0x00 | Memory data =20 NIC info structure Offset | Length | Label | Default value | Description diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinar= y/Docs/HowToInstallAnEepromBinary.txt b/Platform/BroxtonPlatformPkg/Common/= Features/Eeprom/EepromBinary/Docs/HowToInstallAnEepromBinary.txt index a9b319c..155e6ca 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/= HowToInstallAnEepromBinary.txt +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/= HowToInstallAnEepromBinary.txt @@ -13,6 +13,7 @@ # ## =20 +How to install an EEPROM image into an EEPROM: 1. Generate the EEPROM binary. 2. Copy the EEPROM binary and EepromApp.efi onto a USB drive. 3. Insert the USB drive into the target system. diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinar= y/ReadMe.txt b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBin= ary/ReadMe.txt index b413fad..d161e4d 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/ReadM= e.txt +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/ReadM= e.txt @@ -165,8 +165,197 @@ EepromApp.efi =20 =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + UEFI EEPROM PCDs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + [PcdsDynamic,PcdsDynamicEx] + ## Used to store the EEPROM memory buffer pointer + gPlatformModuleTokenSpaceGuid.PcdEepromMemoryPointer|0|UINT64|0xEEEE00= 00 + ## Used to store the EEPROM memory buffer size + gPlatformModuleTokenSpaceGuid.PcdEepromMemorySize|0|UINT32|0xEEEE0001 + ## Used to store the EEPROM data library valid flags + gPlatformModuleTokenSpaceGuid.PcdEepromLibraryValid|{0x00, 0x00, 0x00,= 0x00}|VOID*|0xEEEE0002 + ## Flag to indicate that a HOB exists with EEPROM_MEMORY data + gPlatformModuleTokenSpaceGuid.PcdEepromMemoryHobPresent|FALSE|BOOLEAN|= 0xEEEE0003 + ## Pointer to the Part head link + gPlatformModuleTokenSpaceGuid.PcdEepromPartsHeadLink|0|UINT64|0xEEEE00= 04 + ## Pointer to the Parts table + gPlatformModuleTokenSpaceGuid.PcdEepromParts|0|UINT64|0xEEEE0005 + ## Flag to tell if EEPROM Map is in memory + gPlatformModuleTokenSpaceGuid.PcdEepromInMemoryFlag|0|BOOLEAN|0xEEEE00= 06 + ## Flag to tell if EEPROM Map is in HOB + gPlatformModuleTokenSpaceGuid.PcdEepromMapHobValid|0|BOOLEAN|0xEEEE0007 + + [PcdsFixedAtBuild] + ## I2C bus the master EEPROM is hanging on + gPlatformModuleTokenSpaceGuid.PcdEepromBus|0x06|UINT8|0xEEEE2000 + ## 7-bit address of the master EEPROM + gPlatformModuleTokenSpaceGuid.PcdEepromAddress|0x50|UINT8|0xEEEE2001 + ## Priority order of EEPROM data libraries + ## 00 - Null; 01 - EEPROM; 02 - FV; 03 - Memory; FF - End of list + ## Memory should be first + gPlatformModuleTokenSpaceGuid.PcdEepromAutoPriority|{0x03, 0x01, 0x02,= 0x00, 0xFF}|VOID*|0xEEEE2002 + ## Public key file GUID - 5D8A38A3-FBBD-4077-8105-11170C2AF54D + gPlatformModuleTokenSpaceGuid.PcdEepromPublicKeyFile|{0xA3, 0x38, 0x8A= , 0x5D, 0xBD, 0xFB, 0x77, 0x40, 0x81, 0x05, 0x11, 0x17, 0x0C, 0x2A, 0xF5, 0= x4D}|VOID*|0xEEEE2003 + ## FV EEPROM Image file GUID - BFBD3DAC-01EB-4FEB-A9DE-BCC9D1BA5531 + gPlatformModuleTokenSpaceGuid.PcdEepromFvImageFile|{0xAC, 0x3D, 0xBD, = 0xBF, 0xEB, 0x01, 0xEB, 0x4F, 0xA9, 0xDE, 0xBC, 0xC9, 0xD1, 0xBA, 0x55, 0x3= 1}|VOID*|0xEEEE2004 + ## GPIO PAD whitelist | END OF ARRAY | + gPlatformModuleTokenSpaceGuid.PcdGpioWhiteList|{0xFF, 0xFF, 0xFF, 0xFF= }|VOID*|0xEEEE2005 + + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D UEFI EEPROM Libraries =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + EepromLib.h + UINTN + EFIAPI + DisplayStackPointer ( + IN CHAR8 *Function, + IN UINTN LineNumber + ); + + EFI_STATUS + EFIAPI + EraseEeprom ( + IN UINT8 LibraryIndex + ); + + EFI_STATUS + EFIAPI + GetEepromStructure ( + IN UINT8 LibraryIndex, + IN OUT CHAR8 Signature[EEPROM_SIGNATURE_SIZE], + IN OUT UINT8 **Buffer, + IN OUT UINT32 *Size + ); + + UINT32 + EFIAPI + GetImageSize ( + IN UINT8 LibraryIndex + ); + + EFI_STATUS + EFIAPI + GetNextEepromStructure ( + IN UINT8 LibraryIndex, + IN OUT UINT32 *Index, + IN OUT UINT8 **Buffer, + IN OUT UINT32 *Size + ); + + UINT8 + EFIAPI + GetValidEepromLibrary ( + IN BOOLEAN CopyToMemory, + IN BOOLEAN MemoryInitialized + ); + + BOOLEAN + EFIAPI + InPeiPhase (VOID); + + EFI_STATUS + EFIAPI + ValidateEeprom ( + IN UINT8 LibraryIndex + ); + + // + // Desc: Registers the raw data libraries + // Variables: None + // Return: EFI_SUCCESS + // + EFI_STATUS + EFIAPI + EepromInitConstructor (VOID); + + EepromDataLib.h + // + // Desc: Copies the contents of an existing memory pool into a = new memory pool of equal or greater size. + // Variables: Size Size of the pool to copy existing pool = into + // SourcePointer Pointer to the source buffer to copy + // Return: Pointer Pointer to your copy of the pool + // + VOID* + EFIAPI + EepromAllocateCopyPool ( + IN UINTN Size, + IN VOID *SourcePointer + ); + + // + // Desc: Creates a new memory pool. + // Variables: Size Size of the pool requested + // Return: Pointer Pointer the new pool + // + VOID* + EFIAPI + EepromAllocatePool ( + IN UINTN Size + ); + + EFI_STATUS + EFIAPI + EepromDataLibNemToMemory (VOID); + + // + // Desc: Frees a memory pool. + // Variables: Pointer Pointer to the beginning of the pool to= be freed + // Return: Pointer NULL + // + VOID* + EFIAPI + EepromFreePool ( + IN VOID *Pointer + ); + + // + // Desc: Reads from the EEPROM and copies to the passed in buff= er. + // Variables: LibraryIndex Determines which raw data library to use + // Offset Start copying from the offset + // Size Size of the buffer and the number of by= tes to copy + // - If set to 0, then return size of EEPR= OM binary + // Buffer Storage buffer for the copied data from= the EEPROM + // FunctionInfo Pointer to function specific data + // Return: EFI_SUCCESS Data copied successfully + // EFI_UNSUPPORTED This function is not supported + // EFI_INVALID_PARAMETER One of the parameters is inval= id + // EFI_NOT_READY Called before all necessary li= brary available + // EFI_DEVICE_ERROR Communication error with device + // + EFI_STATUS + EFIAPI + ReadEeprom ( + IN UINT8 LibraryIndex, + IN UINT32 Offset, + IN OUT UINT32 *Size, + IN OUT UINT8 *Buffer, + IN OUT VOID *FunctionInfo + ); + + // + // Desc: Writes to the EEPROM and copies to the passed in buffe= r. + // Variables: LibraryIndex Determines which raw data library to use + // Offset Start copying from the offset + // Size Size of the buffer and the number of by= tes to copy + // - If set to 0, then return size of EEPR= OM binary + // Buffer Data to be copied to the EEPROM + // FunctionInfo Pointer to function specific data + // Return: EFI_SUCCESS Data copied successfully + // EFI_UNSUPPORTED This function is not supported + // EFI_INVALID_PARAMETER One of the parameters is inval= id + // EFI_NOT_READY Called before all necessary li= brary available + // EFI_DEVICE_ERROR Communication error with device + // + EFI_STATUS + EFIAPI + WriteEeprom ( + IN UINT8 LibraryIndex, + IN UINT32 Offset, + IN OUT UINT32 *Size, + IN OUT UINT8 *Buffer, + IN OUT VOID *FunctionInfo + ); =20 =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EEPROM/EepromDataEepromLib.c b/Platform/BroxtonPlatformPkg/Common/Featur= es/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.c index 6f8e98c..09171fd 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/EepromDataEepromLib.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/EepromDataEepromLib.c @@ -378,7 +378,7 @@ FillEepromMap ( // Sanity check EEPROM contents // AsciiSPrint (AsciiBuffer, 32, "%8a", (CHAR8 *) Ptr); - if (AsciiStrnCmp (AsciiBuffer, "$Eeprom$", 0x08) !=3D 0) { + if (AsciiStrnCmp (AsciiBuffer, EEPROM_HEADER_SIGNATURE, 0x08) !=3D 0) { // // Not a vallid EEPROM image. Bail. // @@ -406,7 +406,7 @@ FillEepromMap ( AsciiSPrint (AsciiBuffer, 32, "%8a", EepromHeader->signature); AsciiBuffer[8] =3D 0; if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Structur= e =3D %a @ 0x%08x\n", __FUNCTION__, __LINE__, AsciiBuffer, EepromHeader)); - if (AsciiStrnCmp (EepromHeader->signature, "$EeprMap", 0x08) !=3D 0) { + if (AsciiStrnCmp (EepromHeader->signature, EEPROM_MAP_SIGNATURE, 0x08)= !=3D 0) { // // This is not our structure. Skip to next structure. // @@ -924,6 +924,20 @@ EFI_STATUS EFIAPI LoadEepromMap (VOID) { +//KES: // +//KES: // Initialize variables +//KES: // +//KES: gEepromParts =3D (EEPROM_PART_INFO *) (UINTN) PcdGet64 (= PcdEepromParts); +//KES: gEepromPartsHeadLink =3D (LIST_ENTRY *) (UINTN) PcdGet64 (PcdEep= romPartsHeadLink); +//KES: +//KES: // +//KES: // Load from HOB if present +//KES: // +//KES: if (PcdGetBool (PcdEepromMapHobValid)) { +//KES: // +//KES: // HOB is valid, load it into memory. +//KES: // +//KES: } =20 return EFI_SUCCESS; } @@ -1226,7 +1240,7 @@ ScanI2cBusForImages ( // if (mEepromDataLibDebugFlag &&((index % 0x10) =3D=3D 0)) DEBUG ((DEBUG= _INFO, ".")); Status =3D I2cReadPages (I2cBus, index, 0, sizeof (EEPROM_HEADER), (UI= NT8 *) &EepromHeader); - if (!EFI_ERROR (Status) && (AsciiStrnCmp (EepromHeader.signature, "$Ee= prom$", 0x08) =3D=3D 0)) { + if (!EFI_ERROR (Status) && (AsciiStrnCmp (EepromHeader.signature, EEPR= OM_HEADER_SIGNATURE, 0x08) =3D=3D 0)) { // // Update array and count, since this devices starts with $Eeprom$ // diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EEPROM/EepromDataEepromLib.h b/Platform/BroxtonPlatformPkg/Common/Featur= es/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.h index 931d778..d47eca7 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/EepromDataEepromLib.h +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/EepromDataEepromLib.h @@ -22,11 +22,12 @@ #include #include #include +#include +#include #include #include =20 #include -#include "I2cLib.h" =20 // // Defines diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EEPROM/HobData.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Ee= promDataLib/EEPROM/HobData.c index 46523db..ebc62a1 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/HobData.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/HobData.c @@ -72,7 +72,7 @@ GetEepromDataHobData (VOID) // // Yep. Copy existing buffer to larger buffer. // - Buffer =3D EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize= ) + BlockSize, (UINT8 *) PcdGet64 (PcdEepromMemoryPointer)); + Buffer =3D EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize= ) + BlockSize, (UINT8 *) (UINTN) PcdGet64 (PcdEepromMemoryPointer)); if (Buffer =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Unable to allocate bu= ffer!\n", __FUNCTION__, __LINE__)); Status =3D EFI_OUT_OF_RESOURCES; diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EEPROM/I2cLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eep= romDataLib/EEPROM/I2cLib.c deleted file mode 100644 index 32f9d3f..0000000 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/I2cLib.c +++ /dev/null @@ -1,1164 +0,0 @@ -/** @file - I2C library instance. - - Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BS= D License - which accompanies this distribution. The full text of the license may b= e found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. - -**/ - -#include "I2cLib.h" - -// -// List of I2C controllers -// -LPSS_PCI_DEVICE_INFO mLpssPciDeviceList[] =3D { - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTI= ON_NUMBER_LPSS_I2C0, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*0), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*0) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTI= ON_NUMBER_LPSS_I2C1, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*1), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*1) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTI= ON_NUMBER_LPSS_I2C2, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*2), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*2) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTI= ON_NUMBER_LPSS_I2C3, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*3), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*3) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTI= ON_NUMBER_LPSS_I2C4, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*4), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*4) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTI= ON_NUMBER_LPSS_I2C5, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*5), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*5) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTI= ON_NUMBER_LPSS_I2C6, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*6), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*6) + LPSS_I2C_TMP_BAR1_OFFSET}, - {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTI= ON_NUMBER_LPSS_I2C7, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*7), LPSS= _I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*7) + LPSS_I2C_TMP_BAR1_OFFSET} -}; -#define LPSS_PCI_DEVICE_NUMBER (sizeof (mLpssPciDeviceList) / sizeof (LPS= S_PCI_DEVICE_INFO)) - -// -// List of I2C controller clock values -// -LPSS_I2C_CLOCK_SCL_INFO mLPSS_I2C_CLOCK_SCL_INFO[] =3D { - {0x244, 0x2D0, 0x64, 0xC8, 0x06, 0x13}, - {0x244, 0x2D0, 0x64, 0xC8, 0x06, 0x13}, - {0x244, 0x2D0, 0x64, 0xC8, 0x06, 0x13}, - {0x244, 0x2DA, 0x1E, 0x3C, 0x06, 0x13}, - {0x244, 0x2DA, 0x1E, 0x50, 0x06, 0x13}, - {0x244, 0x2D0, 0x69, 0xC8, 0x06, 0x13}, - {0x244, 0x2D0, 0x69, 0xC8, 0x06, 0x13}, - {0x244, 0x2D0, 0x70, 0xC8, 0x06, 0x13} -}; -#define LPSS_I2C_CLOCK_SCL_INFO_NUMBER (sizeof (mLPSS_I2C_CLOCK_SCL_INFO)= / sizeof (LPSS_I2C_CLOCK_SCL_INFO)) - -// -// List of I2C controller PAD settings -// -BXT_GPIO_PAD_INIT mLPSS_PAD_INFO[] =3D { - BXT_GPIO_PAD_CONF (L"GPIO_124 LPSS_I2C0_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0000, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_125 LPSS_I2C0_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0008, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_126 LPSS_I2C1_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0010, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_127 LPSS_I2C1_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0018, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_128 LPSS_I2C2_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0020, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_129 LPSS_I2C2_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0028, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_130 LPSS_I2C3_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0030, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_131 LPSS_I2C3_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0038, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_132 LPSS_I2C4_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0040, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_133 LPSS_I2C4_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0048, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_134 LPSS_I2C5_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0050, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_135 LPSS_I2C5_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0058, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_136 LPSS_I2C6_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0060, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_137 LPSS_I2C6_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0068, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_138 LPSS_I2C7_SDA", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D0RxDRx0I, EnPu, GPIO_PADBAR + 0x0070, WEST), - BXT_GPIO_PAD_CONF (L"GPIO_139 LPSS_I2C7_SCL", M1, NA, NA, NA, NA, Wake_D= isabled, P_20K_H, NA, NA, D0RxDRx0I, EnPu, GPIO_PADBAR + 0x0078, WEST) -}; - -BOOLEAN gI2cDebugFlag =3D FALSE; - -//// -//// Internal I2C functions -//// -// -// Desc: Clears the interrupts on this I2C controller -// Input: I2cBaseAddress - Pointer to the MMIO base address for t= he I2C controller -// Output: NA -// -VOID -I2cClearInterrupts ( - IN UINT32 I2cBaseAddress - ) -{ - MmioRead32 (I2cBaseAddress + R_IC_CLR_INTR); - return; -} - -// -// Desc: Clears the TX Abort on this I2C controller -// Input: I2cBaseAddress - Pointer to the MMIO base address for t= he I2C controller -// Output: NA -// -VOID -I2cClearTxAbort ( - IN UINT32 I2cBaseAddress - ) -{ - MmioRead32 (I2cBaseAddress + R_IC_CLR_TX_ABRT); - return; -} - -// -// Desc: Disable this I2C controller -// Input: I2cBaseAddress - Pointer to the MMIO base address for t= he I2C controller -// Output: Status - EFI_SUCCESS - I2C host controller is= completely inactive -// EFI_NOT_READY - I2C host controller is= still in an enabled state -// -EFI_STATUS -I2cDisable ( - IN UINT32 I2cBaseAddress - ) -{ - UINT32 NumTries; - EFI_STATUS Status; - - // - // Initialize variables - // - Status =3D EFI_SUCCESS; - - // - // Disable I2C controller - // - MmioWrite32 (I2cBaseAddress + R_IC_ENABLE, 0); - NumTries =3D 10000; // 0.1 seconds - while (0 !=3D (MmioRead32 (I2cBaseAddress + R_IC_ENABLE_STATUS) & 0x03))= { - MicroSecondDelay (10); - NumTries --; - if (0 =3D=3D NumTries) { - Status =3D EFI_NOT_READY; - goto Exit; - } - } - -Exit: - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -/** - Enable I2C host controller - - @param[in] I2CBaseAddress - BAR0 address of I2C host controller - - @retval EFI_SUCCESS - I2C host controller is in an enabled sta= te. - @retval EFI_NOT_READY - I2C host controller is still inactive. -**/ -EFI_STATUS -I2cEnable ( - IN UINT32 I2cBaseAddress - ) -{ - UINT32 NumTries; - EFI_STATUS Status; - - // - // Initialize variables - // - NumTries =3D 10000; // 0.1 seconds - Status =3D EFI_SUCCESS; - - // - // Enable I2C controller - // - MmioWrite32 (I2cBaseAddress + R_IC_ENABLE, I2C_ENABLE_ENABLE); - while (I2C_ENABLE_ENABLE !=3D (MmioRead32 (I2cBaseAddress + R_IC_ENABLE_= STATUS) & I2C_ENABLE_ENABLE)) { - MicroSecondDelay (10); - NumTries --; - if (0 =3D=3D NumTries) { - Status =3D EFI_NOT_READY; - goto Exit; - } - } - -Exit: - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -UINT16 -I2cGetTxAbortStatus ( - IN UINT32 I2cBaseAddress - ) -{ - UINT16 TxAbortStatus; - - if (I2cBaseAddress =3D=3D 0) { - TxAbortStatus =3D 0xFFFF; - } else { - TxAbortStatus =3D (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_TX_ABRT_= SOURCE) & 0xFFFF); - } - return TxAbortStatus; -} - -/** - Get I2C controller raw interrupt status - - @param[in] I2CBaseAddress - BAR0 address of I2C host controller - - @retval UINT16 - Raw interrupt status bit flags -**/ -UINT16 -I2cGetRawStatus ( - IN UINT32 I2cBaseAddress - ) -{ - UINT16 RawStatus; - - if (I2cBaseAddress =3D=3D 0) { - RawStatus =3D 0xFFFF; - } else { - RawStatus =3D (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_RAW_INTR_STA= T) & 0x3FFF); - } - - return RawStatus; -} - -/** - Get I2C controller RX FIFO count - - @param[in] I2CBaseAddress - BAR0 address of I2C host controller - - @retval UINT16 - RX FIFO count -**/ -UINT16 -I2cGetRxFifo ( - IN UINT32 I2cBaseAddress - ) -{ - UINT16 RxFifo; - - if (I2cBaseAddress =3D=3D 0) { - RxFifo =3D 0xFFFF; - } else { - RxFifo =3D (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_RXFLR) & 0x01FF= ); - } - - return RxFifo; -} - -/** - Get I2C controller status - - @param[in] I2CBaseAddress - BAR0 address of I2C host controller - - @retval UINT16 - Status bit flags -**/ -UINT16 -I2cGetStatus ( - IN UINT32 I2cBaseAddress - ) -{ - UINT16 I2cStatus; - - if (I2cBaseAddress =3D=3D 0) { - I2cStatus =3D 0xFFFF; - } else { - I2cStatus =3D (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_STATUS) & 0x= 007F); - } - - return I2cStatus; -} - -/** - Get I2C controller TX FIFO count - - @param[in] I2CBaseAddress - BAR0 address of I2C host controller - - @retval UINT16 - TX FIFO count -**/ -UINT16 -I2cGetTxFifo ( - IN UINT32 I2cBaseAddress - ) -{ - UINT16 TxFifo; - - if (I2cBaseAddress =3D=3D 0) { - TxFifo =3D 0xFFFF; - } else { - TxFifo =3D (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_TXFLR) & 0x01FF= ); - } - - return TxFifo; -} - -EFI_STATUS -I2cProgramPad ( - IN UINT8 Bus - ) -{ - UINT8 index; - EFI_STATUS Status; - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Programming PADs for= bus #%d\n", __FUNCTION__, __LINE__, Bus)); - - // - // Initialize variables - // - Status =3D EFI_SUCCESS; - - // - // Sanity checks - // - if (Bus > MAX_I2C_BUS) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - - // - // Program SDA/SCL - // - for (index =3D 0; index < 2; index++) { - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Programming PAD %s= \n", __FUNCTION__, __LINE__, mLPSS_PAD_INFO[(Bus * 2) + index].pad_name)); - GpioPadConfigTable (1, &mLPSS_PAD_INFO[(Bus * 2) + index]); - } - - // - // Pause a bit - // - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - -Exit: - return Status; -} - -/** - Set the I2C controller bus clock frequency. - - The software and controller do a best case effort of using the specified - frequency for the I2C bus. If the frequency does not match exactly then - the controller will use a slightly lower frequency for the I2C to avoid - exceeding the operating conditions for any of the I2C devices on the bus. - For example if 400 KHz was specified and the controller's divide network - only supports 402 KHz or 398 KHz then the controller would be set to 398 - KHz. However if the desired frequency is 400 KHz and the controller only - supports 1 MHz and 100 KHz then this routine would return EFI_UNSUPPORTE= D. - - @param[in] Bus - I2C Bus number to which the I2C device h= as been connected - @param[in] I2CBaseAddress - BAR0 address of I2C host controller - - @retval EFI_SUCCESS - The bus frequency was set successfully. -**/ -EFI_STATUS -I2cSetBusFrequency ( - IN UINT8 Bus, - IN UINT32 I2cBaseAddress - ) -{ - EFI_STATUS Status; - - // - // Initialize variables - // - Status =3D EFI_SUCCESS; - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet b= us: %d\n", __FUNCTION__, __LINE__, Bus)); - ASSERT ((Bus < LPSS_I2C_CLOCK_SCL_INFO_NUMBER)); - // - // Set the 100 KHz clock divider according to SV result and I2C spec - // - MmioWrite32 (I2cBaseAddress + R_IC_SS_SCL_HCNT, (UINT16) mLPSS_I2C_CLOCK= _SCL_INFO[Bus].SS_SCL_HCNT); - MmioWrite32 (I2cBaseAddress + R_IC_SS_SCL_LCNT, (UINT16) mLPSS_I2C_CLOCK= _SCL_INFO[Bus].SS_SCL_LCNT); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R= _IC_SS_SCL_HCNT: 0x%08X, R_IC_SS_SCL_LCNT: 0x%08X\r\n", - __FUNCTION__, - __LINE__, - MmioRead32 (I2cBaseAddress + R_IC_SS_SCL_HCNT), - MmioRead32 (I2cBaseAddress + R_IC_SS_SCL_LCNT))); - // - // Set the 400 KHz clock divider according to SV result and I2C spec - // - MmioWrite32 (I2cBaseAddress + R_IC_FS_SCL_HCNT, (UINT16) mLPSS_I2C_CLOCK= _SCL_INFO[Bus].FS_SCL_HCNT); - MmioWrite32 (I2cBaseAddress + R_IC_FS_SCL_LCNT, (UINT16) mLPSS_I2C_CLOCK= _SCL_INFO[Bus].FS_SCL_LCNT); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R= _IC_FS_SCL_HCNT: 0x%08X, R_IC_FS_SCL_LCNT: 0x%08X\r\n", - __FUNCTION__, - __LINE__, - MmioRead32 (I2cBaseAddress + R_IC_FS_SCL_HCNT), - MmioRead32 (I2cBaseAddress + R_IC_FS_SCL_LCNT))); - // - // Set the 3.4MHz clock divider according to SV result and I2C spec - // - MmioWrite32 (I2cBaseAddress + R_IC_HS_SCL_HCNT, (UINT16)mLPSS_I2C_CLOCK_= SCL_INFO[Bus].HS_SCL_HCNT); - MmioWrite32 (I2cBaseAddress + R_IC_HS_SCL_LCNT, (UINT16)mLPSS_I2C_CLOCK_= SCL_INFO[Bus].HS_SCL_LCNT); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R= _IC_HS_SCL_HCNT: 0x%08X, R_IC_HS_SCL_LCNT: 0x%08X\r\n", - __FUNCTION__, - __LINE__, - MmioRead32 (I2cBaseAddress + R_IC_HS_SCL_HCNT), - MmioRead32 (I2cBaseAddress + R_IC_HS_SCL_LCNT))); - - // - // Set hold register - // - MmioWrite32 (I2cBaseAddress + R_IC_SDA_HOLD, (UINT16) 0x06); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R= _IC_SDA_HOLD: 0x%08X\r\n", __FUNCTION__, __LINE__, MmioRead32 (I2cBaseAddre= ss + R_IC_SDA_HOLD))); - - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -/** - Program LPSS I2C PCI controller's BAR0 and enable memory decode. - - @param[in] Bus - I2C Bus number to which the I2C device h= as been connected - - @retval EFI_SUCCESS - I2C controller's BAR0 is programmed and = memory decode enabled. - @retval EFI_NOT_READY - I2C controller's is not exist or its fun= ction has been disabled. - @retval EFI_DEVICE_ERROR - I2C controller can't be enabled. -**/ -EFI_STATUS -ProgramPciLpssI2C ( - IN UINT8 Bus - ) -{ - UINT32 Data32; - UINT32 I2CBar0; - UINT32 I2CBar1; - UINTN PciMmBase; - UINT32 PmcBase; - EFI_STATUS Status; - UINT32 I2cPortDisable[] =3D { - B_PMC_FUNC_DIS_LPSS_I2C0, - B_PMC_FUNC_DIS_LPSS_I2C1, - B_PMC_FUNC_DIS_LPSS_I2C2, - B_PMC_FUNC_DIS_LPSS_I2C3, - B_PMC_FUNC_DIS_LPSS_I2C4, - B_PMC_FUNC_DIS_LPSS_I2C5, - B_PMC_FUNC_DIS_LPSS_I2C6, - B_PMC_FUNC_DIS_LPSS_I2C7 - }; - - // - // Initialize variables - // - PciMmBase =3D 0; - Status =3D EFI_SUCCESS; - - // - // Set PADs to I2C mode - // - I2cProgramPad (Bus); - - // - // Check PMC disable register - // - PmcBase =3D PMC_BASE_ADDRESS; - Data32 =3D MmioRead32 (PmcBase + R_PMC_FUNC_DIS); - - if (Data32 =3D=3D 0xFFFFFFFF) { - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C(= ) PMC disable register not available. [%08x]\n", __FUNCTION__, __LINE__, PM= C_BASE_ADDRESS)); - } else { - if ((Data32 & I2cPortDisable[Bus]) !=3D 0) { - // This I2C port is disabled. Turn it on. - Data32 &=3D ~I2cPortDisable[Bus]; - MmioWrite32 (PmcBase + R_PMC_FUNC_DIS, Data32); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2= C() enable I2C controller #%x\n", __FUNCTION__, __LINE__, Bus)); - // Make sure it took. - if (Data32 !=3D MmioRead32 (PmcBase + R_PMC_FUNC_DIS)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ProgramPciLpssI2C() failed to en= able I2C controller #%x [%08x:%08x]\n", - __FUNCTION__, - __LINE__, - Bus, - Data32, - MmioRead32 (PmcBase + R_PMC_FUNC_DIS))); - Status =3D EFI_DEVICE_ERROR; - goto Exit; - } - } - } - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C()-= -----------BusNo=3D%x\n", __FUNCTION__, __LINE__, Bus)); - - PciMmBase =3D MmPciAddress ( - mLpssPciDeviceList[Bus].Segment, - mLpssPciDeviceList[Bus].BusNum, - mLpssPciDeviceList[Bus].DeviceNum, - mLpssPciDeviceList[Bus].FunctionNum, - 0 - ); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Program Pci Lpss I2C= Device %x %x %x PciMmBase:%x\n", - __FUNCTION__, - __LINE__, - mLpssPciDeviceList[Bus].BusNum, - mLpssPciDeviceList[Bus].DeviceNum, - mLpssPciDeviceList[Bus].FunctionNum, PciMmBase)); - - // - // Check if device present - // - if (MmioRead32 (PciMmBase) !=3D 0xFFFFFFFF) { - if ((MmioRead32 (PciMmBase + R_LPSS_IO_STSCMD) & B_LPSS_IO_STSCMD_MSE)= ) { - // - // In Pei stage, we always disable Bus master, and memory space enab= ling for BAR re-programming - // In DXE stage, will read existing BAR value instead of re-programm= ing - // - I2CBar0 =3D MmioRead32 (PciMmBase + R_LPSS_IO_BAR) & B_LPSS_IO_BAR_B= A; - I2CBar1 =3D MmioRead32 (PciMmBase + R_LPSS_IO_BAR1) & B_LPSS_IO_BAR_= BA; - if ((I2CBar0 !=3D (UINT32) mLpssPciDeviceList[Bus].Bar0) || (I2CBar1= !=3D (UINT32) mLpssPciDeviceList[Bus].Bar1)) { - mLpssPciDeviceList[Bus].Bar0 =3D MmioRead32 (PciMmBase + R_LPSS_IO= _BAR) & B_LPSS_IO_BAR_BA; // get the address allocated. - mLpssPciDeviceList[Bus].Bar1 =3D MmioRead32 (PciMmBase + R_LPSS_IO= _BAR1) & B_LPSS_IO_BAR_BA; - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Get bar0:0x%x = bar1:0x%x\n", - __FUNCTION__, - __LINE__, - mLpssPciDeviceList[Bus].Bar0, - mLpssPciDeviceList[Bus].Bar1)); - } - } else { - // - // Program BAR 0 - // - ASSERT (((mLpssPciDeviceList[Bus].Bar0 & B_LPSS_IO_BAR_BA) =3D=3D mL= pssPciDeviceList[Bus].Bar0) && (mLpssPciDeviceList[Bus].Bar0 !=3D 0)); - MmioWrite32 ((UINTN) (PciMmBase + R_LPSS_IO_BAR), (UINT32) (mLpssPci= DeviceList[Bus].Bar0 & B_LPSS_IO_BAR_BA)); - // - // Program BAR 1 - // - ASSERT (((mLpssPciDeviceList[Bus].Bar1 & B_LPSS_IO_BAR1_BA) =3D=3D m= LpssPciDeviceList[Bus].Bar1) && (mLpssPciDeviceList[Bus].Bar1 !=3D 0)); - MmioWrite32 ((UINTN) (PciMmBase + R_LPSS_IO_BAR1), (UINT32) (mLpssPc= iDeviceList[Bus].Bar1 & B_LPSS_IO_BAR1_BA)); - // - // Bus Master Enable & Memory Space Enable - // - MmioOr32 ((UINTN) (PciMmBase + R_LPSS_IO_STSCMD), (UINT32) (B_LPSS_I= O_STSCMD_BME | B_LPSS_IO_STSCMD_MSE)); - ASSERT (MmioRead32 (mLpssPciDeviceList[Bus].Bar0) !=3D 0xFFFFFFFF); - } - - // - // Release Resets - // - MmioWrite32 (mLpssPciDeviceList[Bus].Bar0 + R_LPSS_IO_MEM_RESETS, B_LP= SS_IO_MEM_HC_RESET_REL | B_LPSS_IO_MEM_iDMA_RESET_REL); - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C(= ) Programmed()\n", __FUNCTION__, __LINE__)); - Status =3D EFI_SUCCESS; - goto Exit; - } else { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Pci Lpss I2C Device %x %x %x does = not exist!\n", - __FUNCTION__, - __LINE__, - mLpssPciDeviceList[Bus].BusNum, - mLpssPciDeviceList[Bus].DeviceNum, - mLpssPciDeviceList[Bus].FunctionNum)); - - Status =3D EFI_NOT_READY; - goto Exit; - } - -Exit: - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -//// -//// Public I2C functions -//// -// -// Desc: Initializes the controller and returns the MMIO base address -// Input: Bus - I2C controller, 0 based -// Address - 7-bit slave address -// Speed - Uses the I2C_SPEED enum to set the con= troller speed -// I2cBaseAddress - Pointer to the MMIO base address for t= he I2C controller -// Output: EFI_SUCCESS - Initialization completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cInit ( - IN UINT8 Bus, - IN UINT16 Address, - IN UINT8 Speed, - IN OUT UINT32 *I2cBaseAddress - ) -{ - UINT32 BaseAddress; - UINTN PciMmBase; - EFI_STATUS Status; - - // - // Sanity checks - // - if (Bus > MAX_I2C_BUS) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - if (Address > MAX_I2C_ADDRESS) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - if (Speed > Max_Speed) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - if (I2cBaseAddress =3D=3D NULL) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - - // - // Initialize variables - // - *I2cBaseAddress =3D 0; - - // - // Get current MMIO base address - // - PciMmBase =3D MmPciAddress ( - mLpssPciDeviceList[Bus].Segment, - mLpssPciDeviceList[Bus].BusNum, - mLpssPciDeviceList[Bus].DeviceNum, - mLpssPciDeviceList[Bus].FunctionNum, - 0 - ); - BaseAddress =3D MmioRead32 (PciMmBase + R_LPSS_IO_BAR) & B_LPSS_IO_BAR_B= A; - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2CBaseAddress =3D 0= x%08x:0x%08x \n", __FUNCTION__, __LINE__, BaseAddress, (UINT32) mLpssPciDev= iceList[Bus].Bar0)); - - // - // Skip reinit if targeting the same I2C bus - // - if (BaseAddress =3D=3D (UINT32) mLpssPciDeviceList[Bus].Bar0) { - MmioWrite32 (BaseAddress + R_IC_TAR, Address); - *I2cBaseAddress =3D BaseAddress; - Status =3D EFI_SUCCESS; - goto Exit; - } - - // - // Program I2C controller - // - Status =3D ProgramPciLpssI2C (Bus); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ProgramPciLpssI2C failed! %r\n", __F= UNCTION__, __LINE__, Status)); - goto Exit; - } - - // - // Retrieve I2C MMIO base address - // - BaseAddress =3D (UINT32) mLpssPciDeviceList[Bus].Bar0; - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2CBaseAddress =3D 0= x%x \n", __FUNCTION__, __LINE__, BaseAddress)); - - // - // Reset controller - // - Status =3D I2cReset (BaseAddress, Bus, Address, Speed); - if (EFI_ERROR (Status)) { - goto Exit; - } - - // - // Pause a bit - // - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - - // - // Pass out MMIO base - // - *I2cBaseAddress =3D BaseAddress; - Status =3D EFI_SUCCESS; - -Exit: - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -// -// Desc: Polls the I2C controller with reads until it responds. -// Input: I2cBaseAddress - Pointer to the MMIO base address for t= he I2C controller -// Output: EFI_SUCCESS - Initialization completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// -EFI_STATUS -I2cPoll ( - IN UINT32 I2cBaseAddress - ) -{ - EFI_STATUS Status; - UINT16 Timeout; - UINT8 Value; - - // - // Use a read to poll the slave - // - Status =3D EFI_DEVICE_ERROR; - Timeout =3D 0; - while (EFI_ERROR (Status) && Timeout < 1000) { - MicroSecondDelay (10); - Status =3D I2cRead (I2cBaseAddress, &Value, TRUE, TRUE); - Timeout++; - } - - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -// -// Desc: Read a byte from the I2C controller -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Data - Pointer to where to store the data -// Start - Send start bit? -// End - Send end bit? -// Output: EFI_SUCCESS - Read completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cRead ( - IN UINT32 I2cBaseAddress, - IN OUT UINT8 *Data, - IN BOOLEAN Start, - IN BOOLEAN End - ) -{ - UINT32 Data32; - EFI_STATUS Status; - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting\n", __FUNCT= ION__, __LINE__)); - - // - // Sanity checks - // - if (Data =3D=3D NULL) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - - // - // Send CMD for read - // - Data32 =3D B_READ_CMD; - Status =3D I2cSendCommand (I2cBaseAddress, &Data32, Start, End); - *Data =3D (UINT8) (Data32 & 0xFF); - -Exit: - // - // Pause a bit - // - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Display error messages - // - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -// -// Desc: Resets the I2C controller into a known good state -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Bus - I2C controller, 0 based -// Address - 7-bit slave address -// Speed - Uses the I2C_SPEED enum to set the con= troller speed -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cReset ( - IN UINT32 I2cBaseAddress, - IN UINT8 Bus, - IN UINT16 Address, - IN UINT8 Speed - ) -{ - UINT16 I2cMode; - UINT32 NumTries; - EFI_STATUS Status; - - // - // Wait for master activity to stop - // - NumTries =3D 10000; // 1 seconds - while ((STAT_MST_ACTIVITY =3D=3D (I2cGetStatus (I2cBaseAddress) & STAT_M= ST_ACTIVITY))) { - MicroSecondDelay (10); - NumTries--; - if (0 =3D=3D NumTries) { - DEBUG ((DEBUG_ERROR, "%a(#%4d) - Try timeout\n", __FUNCTION__, __LIN= E__)); - Status =3D EFI_DEVICE_ERROR; - goto Exit; - } - } - // - // Abort controller - // - MmioWrite32 (I2cBaseAddress + R_IC_ENABLE, I2C_ENABLE_ABORT); - MicroSecondDelay (10 * EEPROM_ROUTINE_DELAY); - // - // Disable I2C controller - // - Status =3D I2cDisable (I2cBaseAddress); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cDisable Status = =3D %r\n", __FUNCTION__, __LINE__, Status)); - if (EFI_ERROR (Status)) { - goto Exit; - } - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Set I2C controller speed - // - I2cSetBusFrequency (Bus, I2cBaseAddress); // Set I2cMode - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - switch (Speed) { - case Standard_Speed: - //100K - I2cMode =3D V_SPEED_STANDARD; - break; - - case Fast_Speed: - //400K - I2cMode =3D V_SPEED_FAST; - break; - - case High_Speed: - //3.4M - I2cMode =3D V_SPEED_HIGH; - break; - - default: - //400K - I2cMode =3D V_SPEED_FAST; - } - I2cMode |=3D B_IC_RESTART_EN | B_IC_SLAVE_DISABLE | B_MASTER_MODE; - // - // Set slave address - // - MmioWrite32 (I2cBaseAddress + R_IC_INTR_MASK, 0x0); - if (Address > MAX_I2C_ADDRESS) { - Address =3D (Address & 0x3FF) | IC_TAR_10BITADDR_MASTER; - } - MmioWrite32 (I2cBaseAddress + R_IC_TAR, Address); - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Set RX & TX FIFO full threshold to 1 byte - // - MmioWrite32 (I2cBaseAddress + R_IC_RX_TL, 0); - MmioWrite32 (I2cBaseAddress + R_IC_TX_TL, 0); - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Set I2C Mode - // - MmioWrite32 (I2cBaseAddress + R_IC_CON, I2cMode); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cMode: 0x%04x\r\n"= , __FUNCTION__, __LINE__, I2cMode)); - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Enable I2C controller - // - Status =3D I2cEnable (I2cBaseAddress); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cEnable Status =3D= %r\n", __FUNCTION__, __LINE__, Status)); - if (EFI_ERROR (Status)) { - goto Exit; - } - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Clear TX abort - // - I2cClearTxAbort (I2cBaseAddress); - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Clear interrupts - // - I2cClearInterrupts (I2cBaseAddress); - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - -Exit: - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -// -// Desc: Write a byte to the I2C controller -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Data - Data from the I2C controller -// Start - Send start bit? -// End - Send end bit? -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cSendCommand ( - IN UINT32 I2cBaseAddress, - IN UINT32 *Data, - IN BOOLEAN Start, - IN BOOLEAN End - ) -{ - BOOLEAN CommandSent; - UINT32 Count; - UINT32 CountOut; - UINT32 Data32; - BOOLEAN ReadFlag; - EFI_STATUS Status; - UINT16 TxAbortStatus; - - // - // Initialize variables - // - CommandSent =3D FALSE; - Count =3D 0; - CountOut =3D 0x00000100; - Status =3D EFI_NOT_READY; - if ((*Data & B_READ_CMD) =3D=3D B_READ_CMD) { - ReadFlag =3D TRUE; - } else { - ReadFlag =3D FALSE; - } - - // - // Send a command byte - // - while (CountOut-- > 0) { - // - // Check for NACK - // - if ((I2cGetRawStatus (I2cBaseAddress) & I2C_INTR_TX_ABRT) !=3D 0) { - TxAbortStatus =3D I2cGetTxAbortStatus (I2cBaseAddress); - DEBUG ((DEBUG_ERROR, "%a (#%4d) - TX ABRT [%04x]\n", __FUNCTION__, _= _LINE__, TxAbortStatus)); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - RX FIFO =3D %04x= \n", __FUNCTION__, __LINE__, I2cGetRxFifo (I2cBaseAddress))); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - TX FIFO =3D %04x= \n", __FUNCTION__, __LINE__, I2cGetTxFifo (I2cBaseAddress))); - // - // Clear TX Abort - // - I2cClearTxAbort (I2cBaseAddress); - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - // - // Clear interrupts - // - I2cClearInterrupts (I2cBaseAddress); - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - // - // Set status - // - if (TxAbortStatus & (I2C_ABRT_7B_ADDR_NOACK | I2C_ABRT_10ADDR1_NOACK= | I2C_ABRT_10ADDR2_NOACK)) { - DEBUG ((DEBUG_ERROR, "%a(#%4d) - Nobody home!\n", __FUNCTION__, __= LINE__)); - Status =3D EFI_NO_RESPONSE; - } else { - Status =3D EFI_DEVICE_ERROR; - } - goto Exit; - } - // - // Determine if another byte was received and we were expecting it - // - if (((I2cGetStatus (I2cBaseAddress) & STAT_RFNE) !=3D 0) && ReadFlag) { - *Data =3D MmioRead32 (I2cBaseAddress + R_IC_DATA_CMD) & 0xFF; - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - MmioRead32, byte= 0x%02x was received [%d:%d]\n", __FUNCTION__, __LINE__, *Data, Start, End)= ); - MicroSecondDelay (FIFO_WRITE_DELAY); - // - // Now empty the RX FIFO if stop bit set - // - while (End && ((I2cGetStatus (I2cBaseAddress) & STAT_RFNE) =3D=3D ST= AT_RFNE)) { - MmioRead32 (I2cBaseAddress + R_IC_DATA_CMD); - MicroSecondDelay (FIFO_WRITE_DELAY); - } - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - RX FIFO =3D %04x= \n", __FUNCTION__, __LINE__, I2cGetRxFifo (I2cBaseAddress))); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - TX FIFO =3D %04x= \n", __FUNCTION__, __LINE__, I2cGetTxFifo (I2cBaseAddress))); - Status =3D EFI_SUCCESS; - goto Exit; - } - // - // Wait for room in TX buffer - // - if ((I2cGetStatus (I2cBaseAddress) & STAT_TFNF) =3D=3D 0) { - MicroSecondDelay (FIFO_WRITE_DELAY); - continue; - } - if (!CommandSent) { - // - // Send CMD - // - Data32 =3D *Data; - if (Start) Data32 |=3D B_CMD_RESTART; - if (End) Data32 |=3D B_CMD_STOP; - MmioWrite32 (I2cBaseAddress + R_IC_DATA_CMD, Data32); - CommandSent =3D TRUE; - } - // - // Add a small delay to work around some odd behavior being seen. Wit= hout this delay bytes get dropped. - // - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - // - // Time out check for write CMD - // - while (!ReadFlag) { - if ((I2cGetRawStatus (I2cBaseAddress) & I2C_INTR_TX_ABRT) !=3D 0) { - TxAbortStatus =3D I2cGetTxAbortStatus (I2cBaseAddress); - DEBUG ((DEBUG_ERROR, "%a (#%4d) - TX ABRT [%04x]\n", __FUNCTION__,= __LINE__, TxAbortStatus)); - // - // Clear TX Abort - // - I2cClearTxAbort (I2cBaseAddress); - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - // - // Clear interrupts - // - I2cClearInterrupts (I2cBaseAddress); - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - // - // Set status - // - if (TxAbortStatus & (I2C_ABRT_7B_ADDR_NOACK | I2C_ABRT_10ADDR1_NOA= CK | I2C_ABRT_10ADDR2_NOACK)) { - DEBUG ((DEBUG_ERROR, "%a(#%4d) - Nobody home!\n", __FUNCTION__, = __LINE__)); - Status =3D EFI_NO_RESPONSE; - } else { - Status =3D EFI_DEVICE_ERROR; - } - } - if (I2cGetTxFifo (I2cBaseAddress) =3D=3D 0) { - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - MmioRead32, by= te 0x%04x was sent [%d:%d]\n", __FUNCTION__, __LINE__, Data32, Start, End)); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - RX FIFO =3D %0= 4x\n", __FUNCTION__, __LINE__, I2cGetRxFifo (I2cBaseAddress))); - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - TX FIFO =3D %0= 4x\n", __FUNCTION__, __LINE__, I2cGetTxFifo (I2cBaseAddress))); - Status =3D EFI_SUCCESS; - goto Exit; - } - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - if (Count++ < 1024) { //to avoid sys hung without ul-pmc device on R= VP - continue; //Waiting the last request to get data and make (Receive= DataEnd > ReadBuffer) =3DTRUE. - } else { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - hardware timeout, 1024 times try= !\n", __FUNCTION__, __LINE__)); - Status =3D EFI_TIMEOUT; - goto Exit; - } - } - } - - // - // Check for count out - // - if (CountOut =3D=3D 0) { - Status =3D EFI_TIMEOUT; - } - -Exit: - // - // Pause a bit - // - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Display error messages - // - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r [%x]\n", __FUNCTION= __, __LINE__, Status, CountOut)); - } - return Status; -} - -// -// Desc: Set I2C target slave offset -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Offset - Pointer to offset data -// Size - Size of the offset data -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cSetOffset ( - IN UINT32 I2cBaseAddress, - IN UINT8 *Offset, - IN UINT8 Size - ) -{ - UINT8 index; - EFI_STATUS Status; - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting\n", __FUNCT= ION__, __LINE__)); - - // - // Sanity checks - // - if (Offset =3D=3D NULL) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - if (Size =3D=3D 0) { - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - // - // Set offset - // - for (index =3D 0; index < Size; index++) { - if (index =3D=3D 0) { - // - // First byte of the offset - // - Status =3D I2cWrite (I2cBaseAddress, Offset[index], TRUE, FALSE); - } else { - Status =3D I2cWrite (I2cBaseAddress, Offset[index], FALSE, FALSE); - } - if (EFI_ERROR (Status)) { - goto Exit; - } - // - // Pause a bit - // - MicroSecondDelay (EEPROM_WRITE_TIMEOUT); - } - -Exit: - // - // Pause a bit - // - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Display error messages - // - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - -// -// Desc: Write a byte to the I2C controller -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Data - Data from the I2C controller -// Start - Send start bit? -// End - Send end bit? -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cWrite ( - IN UINT32 I2cBaseAddress, - IN UINT8 Data, - IN BOOLEAN Start, - IN BOOLEAN End - ) -{ - UINT32 Data32; - EFI_STATUS Status; - - if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting\n", __FUNCT= ION__, __LINE__)); - - // - // Send CMD for write - // - Data32 =3D Data; - Status =3D I2cSendCommand (I2cBaseAddress, &Data32, Start, End); - // - // Pause a bit - // - MicroSecondDelay (EEPROM_ROUTINE_DELAY); - // - // Display error messages - // - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); - } - return Status; -} - diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EEPROM/I2cLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eep= romDataLib/EEPROM/I2cLib.h deleted file mode 100644 index 4134caa..0000000 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPR= OM/I2cLib.h +++ /dev/null @@ -1,181 +0,0 @@ -/** @file - Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BS= D License - which accompanies this distribution. The full text of the license may b= e found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. - -**/ - -#ifndef _EEPROM_I2C_LIB_ -#define _EEPROM_I2C_LIB_ -//// -//// Header files -//// -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -// -// Defines -// -#define EEPROM_WRITE_TIMEOUT 5 -#define FIFO_WRITE_DELAY 5 -#define EEPROM_ROUTINE_DELAY 10 -#define INVALID_I2C_ADDRESS 0xFF -#define MAX_I2C_ADDRESS 0x7F -#define MAX_I2C_BUS 7 - -// -// Enums -// -typedef enum { - Standard_Speed =3D 1, - Fast_Speed =3D 2, - High_Speed =3D 3, - Max_Speed =3D 3 -} I2C_SPEED; - -// -// Externs -// -extern BOOLEAN gI2cDebugFlag; - -// -// Structures -// -typedef struct _LPSS_PCI_DEVICE_INFO { - UINT8 Segment; - UINT8 BusNum; - UINT8 DeviceNum; - UINT8 FunctionNum; - UINT32 Bar0; - UINT32 Bar1; -} LPSS_PCI_DEVICE_INFO; - -typedef struct _LPSS_I2C_CLOCK_SCL_INFO { - UINT16 SS_SCL_HCNT; - UINT16 SS_SCL_LCNT; - UINT16 FS_SCL_HCNT; - UINT16 FS_SCL_LCNT; - UINT16 HS_SCL_HCNT; - UINT16 HS_SCL_LCNT; -} LPSS_I2C_CLOCK_SCL_INFO; - -// -// Functions -// -// -// Desc: Initializes the controller and returns the MMIO base address -// Input: Bus - I2C controller, 0 based -// Address - 7-bit slave address -// Speed - Uses the I2C_SPEED enum to set the con= troller speed -// I2cBaseAddress - Pointer to the MMIO base address for t= he I2C controller -// Output: EFI_SUCCESS - Initialization completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cInit ( - IN UINT8 Bus, - IN UINT16 Address, - IN UINT8 Speed, - IN OUT UINT32 *I2cBaseAddress - ); - -EFI_STATUS -I2cPoll ( - IN UINT32 I2cBaseAddress - ); - -// -// Desc: Read a byte from the I2C controller -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Data - Pointer to where to store the data -// Start - Send start bit? -// End - Send end bit? -// Output: EFI_SUCCESS - Read completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cRead ( - IN UINT32 I2cBaseAddress, - IN OUT UINT8 *Data, - IN BOOLEAN Start, - IN BOOLEAN End - ); - -// -// Desc: Resets the I2C controller into a known good state -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cReset ( - IN UINT32 I2cBaseAddress, - IN UINT8 Bus, - IN UINT16 Address, - IN UINT8 Speed - ); - -EFI_STATUS -I2cSendCommand ( - IN UINT32 I2cBaseAddress, - IN UINT32 *Data, - IN BOOLEAN Start, - IN BOOLEAN End - ); - -// -// Desc: Set I2C slave offset -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Offset - Pointer to offset data -// Size - Size of the offset data -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cSetOffset ( - IN UINT32 I2cBaseAddress, - IN UINT8 *Offset, - IN UINT8 Size - ); - -// -// Desc: Write a byte to the I2C controller -// Input: I2cBaseAddress - MMIO base address for the I2C controll= er -// Data - Data from the I2C controller -// Start - Send start bit? -// End - Send end bit? -// Output: EFI_SUCCESS - Write completed successfully -// EFI_DEVICE_ERROR - I2C controller error -// EFI_INVALID_PARAMETER - Invalid input parameter -// -EFI_STATUS -I2cWrite ( - IN UINT32 I2cBaseAddress, - IN UINT8 Data, - IN BOOLEAN Start, - IN BOOLEAN End - ); - -#endif // _EEPROM_I2C_LIB_ - diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eep= romDataLib/EepromDataLib.c index e5ffc85..eff1a75 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLib.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLib.c @@ -150,67 +150,3 @@ Exit: return Status; } =20 -// -// Desc: Registers the raw data libraries -// Variables: None -// Return: EFI_SUCCESS, anything else will cause an ASSERT -// -EFI_STATUS -EFIAPI -EepromDataNullInitConstructor (VOID) -{ - // - // 00 - NULL raw library - // - if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPR= OM_NULL)); - mEepromDataLibIndex[EEPROM_NULL].Active =3D TRUE; - mEepromDataLibIndex[EEPROM_NULL].ReadFunction =3D ReadEepromNull; - mEepromDataLibIndex[EEPROM_NULL].WriteFunction =3D WriteEepromNull; - - return EFI_SUCCESS; -} - -// -// Desc: Registers the raw data libraries -// Variables: None -// Return: EFI_SUCCESS, anything else will cause an ASSERT -// -EFI_STATUS -EFIAPI -EepromDataInitConstructor (VOID) -{ - // - // 00 - NULL raw library - // - if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPR= OM_NULL)); - mEepromDataLibIndex[EEPROM_NULL].Active =3D TRUE; - mEepromDataLibIndex[EEPROM_NULL].ReadFunction =3D ReadEepromNull; - mEepromDataLibIndex[EEPROM_NULL].WriteFunction =3D WriteEepromNull; - - // - // 01 - EEPROM raw library - // - if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_EE= PROM)); - mEepromDataLibIndex[EEPROM_EEPROM].Active =3D TRUE; - mEepromDataLibIndex[EEPROM_EEPROM].ReadFunction =3D ReadEepromEeprom; - mEepromDataLibIndex[EEPROM_EEPROM].WriteFunction =3D WriteEepromEeprom; - - // - // 02 - FV raw library - // - if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM FV raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM= _FV)); - mEepromDataLibIndex[EEPROM_FV].Active =3D TRUE; - mEepromDataLibIndex[EEPROM_FV].ReadFunction =3D ReadEepromFv; - mEepromDataLibIndex[EEPROM_FV].WriteFunction =3D WriteEepromFv; - - // - // 03 - Memory raw library - // - if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM memory raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EE= PROM_MEMORY)); - mEepromDataLibIndex[EEPROM_MEMORY].Active =3D TRUE; - mEepromDataLibIndex[EEPROM_MEMORY].ReadFunction =3D ReadEepromMemory; - mEepromDataLibIndex[EEPROM_MEMORY].WriteFunction =3D WriteEepromMemory; - - return EFI_SUCCESS; -} - diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Eep= romDataLib/EepromDataLib.h index 899487a..9a22ec3 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLib.h +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLib.h @@ -72,6 +72,11 @@ typedef struct { } EEPROM_ALLOCATION_STRUCT; =20 //// +//// Externs +//// +extern EEPROM_DATA_LIBRARY_INDEX mEepromDataLibIndex[]; + +//// //// Functions //// // diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/E= epromDataLib/EepromDataLib.inf index 67416ae..0ce2aaf 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLib.inf +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLib.inf @@ -32,7 +32,7 @@ BaseLib BaseMemoryLib DebugLib - GpioLib + EepromPlatformLib HobLib MemoryAllocationLib PcdLib @@ -53,8 +53,6 @@ gPlatformModuleTokenSpaceGuid.PcdEepromMemorySize gPlatformModuleTokenSpaceGuid.PcdEepromParts gPlatformModuleTokenSpaceGuid.PcdEepromPartsHeadLink - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## SOMETIMES_CONSUMES - gEfiBxtTokenSpaceGuid.PcdPmcGcrBaseAddress ## SOMETIMES_CONSUMES =20 [Protocols] gEfiLoadedImageProtocolGuid @@ -63,12 +61,11 @@ [Sources] EepromDataLib.c EepromDataLib.h + EepromDataLibConstructor.c MemoryAllocation.c EEPROM/EepromDataEepromLib.c EEPROM/EepromDataEepromLib.h EEPROM/HobData.c - EEPROM/I2cLib.c - EEPROM/I2cLib.h FV/EepromDataFvLib.c FV/EepromDataFvLib.h FV/GetImage.c diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataLibConstructor.c b/Platform/BroxtonPlatformPkg/Common/Features= /Eeprom/EepromDataLib/EepromDataLibConstructor.c new file mode 100644 index 0000000..45041dd --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataLibConstructor.c @@ -0,0 +1,61 @@ +/** @file + Common EEPROM raw data library instance. + + Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "EepromDataLib.h" + +// +// Desc: Registers the raw data libraries +// Variables: None +// Return: EFI_SUCCESS, anything else will cause an ASSERT +// +EFI_STATUS +EFIAPI +EepromDataInitConstructor (VOID) +{ + // + // 00 - NULL raw library + // + if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPR= OM_NULL)); + mEepromDataLibIndex[EEPROM_NULL].Active =3D TRUE; + mEepromDataLibIndex[EEPROM_NULL].ReadFunction =3D ReadEepromNull; + mEepromDataLibIndex[EEPROM_NULL].WriteFunction =3D WriteEepromNull; + + // + // 01 - EEPROM raw library + // + if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_EE= PROM)); + mEepromDataLibIndex[EEPROM_EEPROM].Active =3D TRUE; + mEepromDataLibIndex[EEPROM_EEPROM].ReadFunction =3D ReadEepromEeprom; + mEepromDataLibIndex[EEPROM_EEPROM].WriteFunction =3D WriteEepromEeprom; + + // + // 02 - FV raw library + // + if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM FV raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM= _FV)); + mEepromDataLibIndex[EEPROM_FV].Active =3D TRUE; + mEepromDataLibIndex[EEPROM_FV].ReadFunction =3D ReadEepromFv; + mEepromDataLibIndex[EEPROM_FV].WriteFunction =3D WriteEepromFv; + + // + // 03 - Memory raw library + // + if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM memory raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EE= PROM_MEMORY)); + mEepromDataLibIndex[EEPROM_MEMORY].Active =3D TRUE; + mEepromDataLibIndex[EEPROM_MEMORY].ReadFunction =3D ReadEepromMemory; + mEepromDataLibIndex[EEPROM_MEMORY].WriteFunction =3D WriteEepromMemory; + + return EFI_SUCCESS; +} + diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataNullLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eepr= om/EepromDataLib/EepromDataNullLib.inf index 71cec04..d980eb5 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataNullLib.inf +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataNullLib.inf @@ -31,10 +31,13 @@ =20 [Packages] MdePkg/MdePkg.dec + BroxtonPlatformPkg/PlatformPkg.dec =20 [Sources] EepromDataLib.c EepromDataLib.h + EepromDataNullLibConstructor.c + MemoryAllocation.c Null/EepromDataNullLib.c Null/EepromDataNullLib.h =20 diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataNullLibConstructor.c b/Platform/BroxtonPlatformPkg/Common/Feat= ures/Eeprom/EepromDataLib/EepromDataNullLibConstructor.c new file mode 100644 index 0000000..6bb4cf5 --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataNullLibConstructor.c @@ -0,0 +1,36 @@ +/** @file + Common EEPROM raw data library instance. + + Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "EepromDataLib.h" + +// +// Desc: Registers the raw data libraries +// Variables: None +// Return: EFI_SUCCESS, anything else will cause an ASSERT +// +EFI_STATUS +EFIAPI +EepromDataNullInitConstructor (VOID) +{ + // + // 00 - NULL raw library + // + if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EE= PROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPR= OM_NULL)); + mEepromDataLibIndex[EEPROM_NULL].Active =3D TRUE; + mEepromDataLibIndex[EEPROM_NULL].ReadFunction =3D ReadEepromNull; + mEepromDataLibIndex[EEPROM_NULL].WriteFunction =3D WriteEepromNull; + + return EFI_SUCCESS; +} diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataNullPeiLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/E= eprom/EepromDataLib/EepromDataNullPeiLib.inf new file mode 100644 index 0000000..456d75d --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataNullPeiLib.inf @@ -0,0 +1,46 @@ +## @file +# Library producing EEPROM raw data functionality. +# +# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may b= e found at +# http://opensource.org/licenses/bsd-license.php. +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D EepromDataNullPeiLib + FILE_GUID =3D F4A687F7-BC3C-4BFB-AB8E-EA6599B2F62F + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D EepromDataNullPeiLib + CONSTRUCTOR =3D EepromDataNullInitConstructor + +[Depex] + TRUE + +[Guids] + gEepromVariableGuid + +[LibraryClasses] + BaseLib + DebugLib + +[Packages] + MdePkg/MdePkg.dec + BroxtonPlatformPkg/PlatformPkg.dec + +[Sources] + EepromDataLib.c + EepromDataLib.h + EepromDataNullLibConstructor.c + MemoryAllocationPei.c + Null/EepromDataNullLib.c + Null/EepromDataNullLib.h + diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/EepromDataPeiLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eepro= m/EepromDataLib/EepromDataPeiLib.inf index 86a047e..de14765 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataPeiLib.inf +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Eepr= omDataPeiLib.inf @@ -32,7 +32,7 @@ BaseLib BaseMemoryLib DebugLib - GpioLib + EepromPlatformLib HobLib PcdLib PeiServicesLib @@ -52,18 +52,15 @@ gPlatformModuleTokenSpaceGuid.PcdEepromMemorySize gPlatformModuleTokenSpaceGuid.PcdEepromParts gPlatformModuleTokenSpaceGuid.PcdEepromPartsHeadLink - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## SOMETIMES_CONSUMES - gEfiBxtTokenSpaceGuid.PcdPmcGcrBaseAddress ## SOMETIMES_CONSUMES =20 [Sources] EepromDataLib.c EepromDataLib.h + EepromDataLibConstructor.c MemoryAllocationPei.c EEPROM/EepromDataEepromLib.c EEPROM/EepromDataEepromLib.h EEPROM/HobDataPei.c - EEPROM/I2cLib.c - EEPROM/I2cLib.h FV/EepromDataFvLib.c FV/EepromDataFvLib.h FV/GetImagePei.c diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/Memory/HobData.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Ee= promDataLib/Memory/HobData.c index 03e263e..1b19b52 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memo= ry/HobData.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memo= ry/HobData.c @@ -72,7 +72,7 @@ GetEepromDataHobData (VOID) // // Yep. Copy existing buffer to larger buffer. // - Buffer =3D EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize= ) + BlockSize, (UINT8 *) PcdGet64 (PcdEepromMemoryPointer)); + Buffer =3D EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize= ) + BlockSize, (UINT8 *) (UINTN) PcdGet64 (PcdEepromMemoryPointer)); if (Buffer =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Unable to allocate bu= ffer!\n", __FUNCTION__, __LINE__)); Status =3D EFI_OUT_OF_RESOURCES; diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/MemoryAllocation.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/= EepromDataLib/MemoryAllocation.c index 4d4b9ed..7ec8218 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memo= ryAllocation.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memo= ryAllocation.c @@ -17,6 +17,23 @@ =20 #include =20 +UINTN +EFIAPI +DisplayStackPointer ( + IN CHAR8 *Function, + IN UINTN LineNumber + ) +{ + UINT8 *Temp; + + Temp =3D AllocatePool (1); + if (mEepromDataLibDebugFlag) { + DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom =3D %08x\n", __FUNCT= ION__, __LINE__, Temp)); + } + + return (UINTN) Temp; +} + // // Desc: Copies the contents of an existing memory pool into a new = memory pool of equal or greater size. // Variables: Size Size of the pool to copy existing pool into diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataL= ib/MemoryAllocationPei.c b/Platform/BroxtonPlatformPkg/Common/Features/Eepr= om/EepromDataLib/MemoryAllocationPei.c index 250666f..9bfccc7 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memo= ryAllocationPei.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memo= ryAllocationPei.c @@ -102,6 +102,27 @@ Exit: return Status; } =20 +UINTN +EFIAPI +DisplayStackPointer ( + IN CHAR8 *Function, + IN UINTN LineNumber + ) +{ + EFI_HOB_HANDOFF_INFO_TABLE *Hob; + UINTN Temp; + + Hob =3D GetHobList (); + Temp =3D 0; + if ((Hob !=3D NULL) & (mEepromDataLibDebugFlag)) { + DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeTop =3D %08x\n", __FUNCT= ION__, __LINE__, Hob->EfiFreeMemoryTop)); + DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom =3D %08x\n", __FUNCT= ION__, __LINE__, Hob->EfiFreeMemoryBottom)); + Temp =3D (UINTN) Hob->EfiFreeMemoryBottom; + } + + return Temp; +} + // // Desc: Dumps the EEPROM memory allocation status. // Variables: HobPointer Pointer to the EEPROM memory allocation HOB diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/E= epromLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/E= epromLib.c index 6ab06da..eccd28f 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLi= b.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLi= b.c @@ -61,19 +61,59 @@ InitializeCrc32Table ( UINTN Index; UINT32 Value; =20 - for (TableEntry =3D 0; TableEntry < 256; TableEntry++) { - Value =3D ReverseBits ((UINT32) TableEntry); - for (Index =3D 0; Index < 8; Index++) { - if ((Value & 0x80000000) !=3D 0) { - Value =3D (Value << 1) ^ 0x04C11DB7; - } else { - Value =3D Value << 1; + if (!mCrcInitFlag) { + for (TableEntry =3D 0; TableEntry < 256; TableEntry++) { + Value =3D ReverseBits ((UINT32) TableEntry); + for (Index =3D 0; Index < 8; Index++) { + if ((Value & 0x80000000) !=3D 0) { + Value =3D (Value << 1) ^ 0x04C11DB7; + } else { + Value =3D Value << 1; + } } + mCrcTable[TableEntry] =3D ReverseBits (Value); } + mCrcInitFlag =3D TRUE; + } +} + +UINT32 +EFIAPI +StartCrc32 (VOID) +{ + // Table initialized? + InitializeCrc32Table (); + + return 0xFFFFFFFF; +} =20 - mCrcTable[TableEntry] =3D ReverseBits (Value); +UINT32 +EFIAPI +AddToCrc32 ( + IN VOID *Data, + IN UINTN DataSize, + IN UINT32 Crc + ) +{ + UINT32 Crc32; + UINTN Index; + UINT8 *Ptr; + + Crc32 =3D Crc; + Ptr =3D (UINT8 *) Data; + for (Index =3D 0; Index < DataSize; Index++) { + Crc32 =3D (Crc32 >> 8) ^ mCrcTable[(UINT8) Crc32 ^ Ptr[Index]]; } - mCrcInitFlag =3D TRUE; + return Crc32; +} + +UINT32 +EFIAPI +FinishCrc32 ( + IN UINT32 Crc32 + ) +{ + return (Crc32 ^ 0xFFFFFFFF); } =20 /*++ @@ -87,7 +127,7 @@ Arguments: Data - The buffer contaning the data to be processed DataSize - The size of data to be processed CrcOut - A pointer to the caller allocated UINT32 that on - contains the CRC32 checksum of Data + exits, contains the CRC32 checksum of Data =20 Returns: =20 @@ -97,15 +137,13 @@ Returns: --*/ EFI_STATUS EFIAPI -CalculateCrc32 ( +EepromCalculateCrc32 ( IN UINT8 *Data, IN UINTN DataSize, IN OUT UINT32 *CrcOut ) { - UINT32 Crc; - UINTN Index; - UINT8 *Ptr; + UINT32 Crc32; =20 if (mEepromLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting...\n"= , __FUNCTION__, __LINE__)); =20 @@ -114,15 +152,9 @@ CalculateCrc32 ( return EFI_INVALID_PARAMETER; } =20 - // Table initialized? - if (!mCrcInitFlag) InitializeCrc32Table (); - - Crc =3D 0xFFFFFFFF; - for (Index =3D 0, Ptr =3D Data; Index < DataSize; Index++, Ptr++) { - Crc =3D (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr]; - } - - *CrcOut =3D Crc ^ 0xFFFFFFFF; + Crc32 =3D StartCrc32 (); + Crc32 =3D AddToCrc32 (Data, DataSize, Crc32); + *CrcOut =3D FinishCrc32 (Crc32); =20 return EFI_SUCCESS; } @@ -319,7 +351,7 @@ GetImageSize ( Size =3D sizeof (EEPROM_HEADER); ZeroMem (&EepromHeader, Size); Status =3D ReadEeprom (LibraryIndex, 0, &Size, (UINT8 *) &EepromHeader, = &EepromInfo); - if (EFI_ERROR (Status) || (AsciiStrnCmp (EepromHeader.signature, "$Eepro= m$", 8) !=3D 0)) { + if (EFI_ERROR (Status) || (AsciiStrnCmp (EepromHeader.signature, EEPROM_= HEADER_SIGNATURE, 8) !=3D 0)) { // // Oops! // @@ -430,7 +462,7 @@ GetNextEepromStructure ( Status =3D EFI_END_OF_FILE; goto Exit; } - =20 + // // Read in the next header // @@ -502,8 +534,7 @@ Exit: UINT8 EFIAPI GetValidEepromLibrary ( - IN BOOLEAN CopyToMemory, - IN BOOLEAN MemoryInitialized + IN BOOLEAN CopyToMemory ) { UINT8 *EepromAutoList; @@ -542,9 +573,8 @@ GetValidEepromLibrary ( // Display current stack pointer // DisplayStackPointer (__FUNCTION__, __LINE__); - // - // Loop thru PcdEepromAutoPriority looking for a validated image. + // Loop thru PcdEepromAutoPriority looking for a previously validated im= age. // index =3D 0; while (EepromAutoList[index] !=3D 0xFF) { @@ -569,15 +599,7 @@ GetValidEepromLibrary ( // index++; } - // - // Check to see if we need to validate and copy into memory - // - if (!CopyToMemory) { - // - // Nope. Bail. - // - goto Exit; - } + // // Display current stack pointer // @@ -609,6 +631,7 @@ GetValidEepromLibrary ( index++; } } + // // Display current stack pointer // @@ -646,13 +669,13 @@ GetValidEepromLibrary ( // Get BoardInfo records // Size =3D 0; - Status =3D GetEepromStructure (EEPROM_EEPROM, "$BrdInfo", (UINT8 **) &= EepromBoardInfo, &Size); + Status =3D GetEepromStructure (EEPROM_EEPROM, EEPROM_BOARD_INFO_SIGNAT= URE, (UINT8 **) &EepromBoardInfo, &Size); if (EFI_ERROR (Status) || (Size =3D=3D 0) || (EepromBoardInfo =3D=3D N= ULL)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get EEPROM Board = Info structure! (%r)\n", __FUNCTION__, __LINE__, Status)); Library =3D EEPROM_FV; } else { Size =3D 0; - Status =3D GetEepromStructure (EEPROM_FV, "$BrdInfo", (UINT8 **) &Fv= BoardInfo, &Size); + Status =3D GetEepromStructure (EEPROM_FV, EEPROM_BOARD_INFO_SIGNATUR= E, (UINT8 **) &FvBoardInfo, &Size); if (EFI_ERROR (Status) || (Size =3D=3D 0) || (FvBoardInfo =3D=3D NUL= L)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get FV Board In= fo structure! (%r)\n", __FUNCTION__, __LINE__, Status)); Library =3D EEPROM_EEPROM; @@ -670,13 +693,13 @@ GetValidEepromLibrary ( // Get EepromHeader records // Size =3D 0; - Status =3D GetEepromStructure (EEPROM_EEPROM, "$Eeprom$", (UINT8= **) &EepromEepromHeader, &Size); + Status =3D GetEepromStructure (EEPROM_EEPROM, EEPROM_HEADER_SIGN= ATURE, (UINT8 **) &EepromEepromHeader, &Size); if (EFI_ERROR (Status) || (Size =3D=3D 0) || (EepromEepromHeader= =3D=3D NULL)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get EEPROM = header structure! (%r)\n", __FUNCTION__, __LINE__, Status)); Library =3D EEPROM_FV; } else { Size =3D 0; - Status =3D GetEepromStructure (EEPROM_FV, "$Eeprom$", (UINT8 *= *) &FvEepromHeader, &Size); + Status =3D GetEepromStructure (EEPROM_FV, EEPROM_HEADER_SIGNAT= URE, (UINT8 **) &FvEepromHeader, &Size); if (EFI_ERROR (Status) || (Size =3D=3D 0) || (FvEepromHeader = =3D=3D NULL)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get FV he= ader structure! (%r)\n", __FUNCTION__, __LINE__, Status)); Library =3D EEPROM_EEPROM; @@ -711,10 +734,14 @@ GetValidEepromLibrary ( // Display current stack pointer // DisplayStackPointer (__FUNCTION__, __LINE__); + // - // If we don't have memory, then bail so we don't take up all of the sta= ck space in NEM. + // Check to see if we need to copy into memory and not in PEI // - if (!MemoryInitialized) { + if (!CopyToMemory || InPeiPhase ()) { + // + // Nope. Bail. + // goto Exit; } // @@ -793,19 +820,18 @@ ValidateEeprom ( IN UINT8 LibraryIndex ) { + UINT32 BufferSize; UINT32 Count; UINT32 Crc32; UINT32 Crc32Size; EEPROM_HEADER *EepromHeader; EEPROM_FUNCTION_INFO EepromInfo; - UINT8 *Hash; UINT32 HashSize; - UINT16 HashType; UINT8 *ImageBuffer; UINT32 ImageSize; - SIGNATURE_DATA *Signature; - UINT8 *SignedHash; - UINT32 SignedHashSize; + UINT32 Offset; + UINT32 OriginalCrc32; + UINT32 Size; EFI_STATUS Status; GENERIC_HEADER *Structure; INTN Test; @@ -821,10 +847,7 @@ ValidateEeprom ( EepromInfo.Bus =3D PcdGet8 (PcdEepromBus); EepromInfo.Address =3D PcdGet8 (PcdEepromAddress); EepromInfo.LibraryIndex =3D EEPROM_EEPROM; - Hash =3D NULL; ImageBuffer =3D NULL; - SignedHash =3D NULL; - SignedHashSize =3D 0; Status =3D EFI_SUCCESS; Structure =3D NULL; =20 @@ -848,117 +871,133 @@ ValidateEeprom ( Status =3D EFI_NOT_FOUND; goto Exit; } - // - // Get a buffer to hold the image - // - ImageBuffer =3D EepromAllocatePool (ImageSize); - if (ImageBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Unable to allocate 0x%08x byt= es for the image buffer!\n", __FUNCTION__, __LINE__, ImageSize)); - Status =3D EFI_OUT_OF_RESOURCES; - goto Exit; - } - // - // Read in the image - // - Status =3D ReadEeprom (LibraryIndex, 0, &ImageSize, ImageBuffer, &Eeprom= Info); - if (EFI_ERROR (Status)) { - // - // Oops!!! - // - goto Exit; - } - EepromHeader =3D (EEPROM_HEADER *) ImageBuffer; + // // Verify structure order // - Count =3D 0; - Structure =3D (GENERIC_HEADER *) ImageBuffer; - while ((UINT8 *) Structure < (UINT8 *) (ImageBuffer + ImageSize)) { - // - // Increment count - // - Count++; - // - // Sanity check header - // - if (Count =3D=3D 1) { - // - // First structure must be $Eeprom$ - // - Test =3D AsciiStrnCmp (Structure->signature, "$Eeprom$", 8); - // - // Set CRC32 size - // - Crc32Size =3D EepromHeader->crclength; - } else if (Count =3D=3D 2) { - // - // Second structure must be $EeprMap - // - Test =3D AsciiStrnCmp (Structure->signature, "$EeprMap", 8); - } else if (Count =3D=3D 3) { - // - // Third structure must be $BrdInfo - // - Test =3D AsciiStrnCmp (Structure->signature, "$BrdInfo", 8); - } else { - // - // All header signatures begin with $ - // - Test =3D AsciiStrnCmp (Structure->signature, "$", 0x01); - } - if (Test !=3D 0) { + Count =3D 0; + Offset =3D 0; + Status =3D EFI_SUCCESS; + while (!EFI_ERROR (Status) && (Offset < ImageSize)) { + Status =3D GetNextEepromStructure (LibraryIndex, &Offset, (UINT8 **) &= ImageBuffer, &BufferSize); + if (!EFI_ERROR (Status)) { // - // Sanity check failed! Bail. + // Increment count // - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __F= UNCTION__, __LINE__)); - Status =3D EFI_VOLUME_CORRUPTED; - goto Exit; - } - if (AsciiStrnCmp (Structure->signature, "$PromSig", 8) =3D=3D 0) { + Count++; + Structure =3D (GENERIC_HEADER *) ImageBuffer; // - // Check if this is the last structure + // Sanity check header // - Signature =3D (SIGNATURE_DATA *) Structure; - HashSize =3D Signature->length - sizeof (SIGNATURE_DATA); - Hash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA); - HashType =3D Signature->hashtype; - if (((UINT8 *) Signature - ImageBuffer) + Signature->length + (Struc= ture->length % 0x10) !=3D ImageSize) { + if (Count =3D=3D 1) { + // + // First structure must be $Eeprom$ // - // Oops! $PromSig is not the last structure. + Test =3D AsciiStrnCmp (Structure->signature, EEPROM_HEADER_SIGNATU= RE, 8); + } else if (Count =3D=3D 2) { // - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: $PromSig structure is not= the last structure!\n", __FUNCTION__, __LINE__)); + // Second structure must be $EeprMap + // + Test =3D AsciiStrnCmp (Structure->signature, EEPROM_MAP_SIGNATURE,= 8); + } else if (Count =3D=3D 3) { + // + // Third structure must be $BrdInfo + // + Test =3D AsciiStrnCmp (Structure->signature, EEPROM_BOARD_INFO_SIG= NATURE, 8); + } else { + // + // All header signatures begin with $ + // + Test =3D AsciiStrnCmp (Structure->signature, "$", 0x01); + } + if (Test !=3D 0) { + // + // Sanity check failed! Bail. + // + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", _= _FUNCTION__, __LINE__)); Status =3D EFI_VOLUME_CORRUPTED; goto Exit; } + if (AsciiStrnCmp (Structure->signature, EEPROM_SIGNATURE_SIGNATURE, = 8) =3D=3D 0) { + // + // Check if this is the last structure + // + HashSize =3D Structure->length - sizeof (SIGNATURE_DATA); + if (Offset < ImageSize) { + // + // Oops! $PromSig is not the last structure. + // + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: $PromSig structure is n= ot the last structure!\n", __FUNCTION__, __LINE__)); + Status =3D EFI_VOLUME_CORRUPTED; + goto Exit; + } + } } - // - // Get next structure on paragraph boundary - // - Structure =3D (GENERIC_HEADER *) ((UINT8 *) Structure + Structure->len= gth + (Structure->length % 0x10)); + } + ImageBuffer =3D EepromFreePool (ImageBuffer); + + // + // Get $Eeprom$ structure + // + Size =3D 0; + Status =3D GetEepromStructure (LibraryIndex, EEPROM_HEADER_SIGNATURE, (U= INT8 **) &EepromHeader, &Size); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUN= CTION__, __LINE__)); + Status =3D EFI_VOLUME_CORRUPTED; + goto Exit; } // - // Verify CRC32 + // Start CRC32 calculations with $Eeprom$ // - Crc32 =3D EepromHeader->crc32; + OriginalCrc32 =3D EepromHeader->crc32; + Crc32Size =3D EepromHeader->crclength; EepromHeader->crc32 =3D 0; - CalculateCrc32 (ImageBuffer, Crc32Size, &EepromHeader->crc32); - if (EepromHeader->crc32 !=3D Crc32) { + Crc32 =3D StartCrc32 (); + Crc32 =3D AddToCrc32 (EepromHeader, Size, Crc32); + Offset =3D Size; + // + // Add the rest of the binary + // + Size =3D 1024; + ImageBuffer =3D EepromAllocatePool (Size); + if (ImageBuffer =3D=3D NULL) { + // + // Failed to allocate pool + // + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to allocate pool for B= uffer!\n", __FUNCTION__, __LINE__)); + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + Status =3D EFI_SUCCESS; + while (!EFI_ERROR (Status) && (Offset < Crc32Size)) { + if ((Offset + Size) > Crc32Size) { + Size =3D Crc32Size - Offset; + } + Status =3D ReadEeprom (LibraryIndex, Offset, &Size, ImageBuffer, &Eep= romInfo); + Offset +=3D Size; + if (!EFI_ERROR (Status)) { + Crc32 =3D AddToCrc32 (ImageBuffer, Size, Crc32); + } + } + Crc32 =3D FinishCrc32 (Crc32); + if (OriginalCrc32 !=3D Crc32) { // // Oops! // - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: CRC32 check failed! [%08x:%08= x]\n", __FUNCTION__, __LINE__, EepromHeader->crc32, Crc32)); + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: CRC32 check failed! [%08x:%08= x]\n", __FUNCTION__, __LINE__, OriginalCrc32, Crc32)); Status =3D EFI_SECURITY_VIOLATION; goto Exit; } + EepromHeader =3D EepromFreePool (EepromHeader); + // // Verify hash // - Status =3D EFI_SUCCESS; if (HashSize > 0) { // // Check hash // - Status =3D SignedHashCheck (LibraryIndex, ImageBuffer, Crc32Size, Sign= ature); + Status =3D SignedHashCheck (LibraryIndex); if (EFI_ERROR (Status) && (Status !=3D EFI_MEDIA_CHANGED)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to verify the hash!\= n", __FUNCTION__, __LINE__)); goto Exit; @@ -969,7 +1008,8 @@ Exit: // // Free resources // - ImageBuffer =3D EepromFreePool (ImageBuffer); + EepromHeader =3D EepromFreePool (EepromHeader); + ImageBuffer =3D EepromFreePool (ImageBuffer); if (EFI_ERROR (Status) && (Status !=3D EFI_MEDIA_CHANGED)) { gImageValidFlag[LibraryIndex] =3D FALSE; DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/E= epromLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/E= epromLib.h index 83871a4..047b559 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLi= b.h +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLi= b.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -34,7 +33,6 @@ //// //// Defines //// -#define HASH_SIGNED_FLAG (1 << 15) #define HASH_TYPE_MASK 0x00FF #define MAX_HASH_TYPE 5 #define MAX_DIGEST_SIZE SHA512_DIGEST_SIZE @@ -53,7 +51,7 @@ //// EFI_STATUS EFIAPI -CalculateCrc32 ( +EepromCalculateCrc32 ( IN UINT8 *Data, IN UINTN DataSize, IN OUT UINT32 *CrcOut @@ -66,10 +64,7 @@ EepromLibNemToMemory (VOID); EFI_STATUS EFIAPI SignedHashCheck ( - IN UINT8 LibraryIndex, - IN UINT8 *ImageBuffer, - IN UINT32 Crc32Size, - IN SIGNATURE_DATA *Signature + IN UINT8 LibraryIndex ); =20 #endif // _EEPROM_LIB_COMMON_ diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/N= ull/EepromNullLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Ee= promLib/Null/EepromNullLib.c index 612408a..a235d8a 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Null/Eep= romNullLib.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Null/Eep= romNullLib.c @@ -42,7 +42,7 @@ GetImageSize ( IN UINT8 LibraryIndex ) { - return EFI_UNSUPPORTED; + return 0; } =20 EFI_STATUS @@ -60,8 +60,7 @@ GetNextEepromStructure ( UINT8 EFIAPI GetValidEepromLibrary ( - IN BOOLEAN CopyToMemory, - IN BOOLEAN MemoryInitialized + IN BOOLEAN CopyToMemory ) { return EEPROM_NULL; diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/P= ei/ValidateHashPei.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/E= epromLib/Pei/ValidateHashPei.c index b039d98..a0f7b6b 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Pei/Vali= dateHashPei.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Pei/Vali= dateHashPei.c @@ -20,27 +20,6 @@ #include #include =20 -UINTN -EFIAPI -DisplayStackPointer ( - IN CHAR8 *Function, - IN UINTN LineNumber - ) -{ - EFI_HOB_HANDOFF_INFO_TABLE *Hob; - UINTN Temp; - =20 - Hob =3D GetHobList (); - Temp =3D 0; - if ((Hob !=3D NULL) & (mEepromDataLibDebugFlag)) { - DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeTop =3D %08x\n", __FUNCT= ION__, __LINE__, Hob->EfiFreeMemoryTop)); - DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom =3D %08x\n", __FUNCT= ION__, __LINE__, Hob->EfiFreeMemoryBottom)); - Temp =3D (UINTN) Hob->EfiFreeMemoryBottom; - } - - return Temp; -} - EFI_STATUS EFIAPI GetEepromVariable ( @@ -165,26 +144,16 @@ InPeiPhase (VOID) EFI_STATUS EFIAPI SignedHashCheck ( - IN UINT8 LibraryIndex, - IN UINT8 *ImageBuffer, - IN UINT32 Crc32Size, - IN SIGNATURE_DATA *Signature + IN UINT8 LibraryIndex ) { - UINT8 *Hash; - UINT32 HashSize; - EFI_STATUS Status; - UINT8 *Variable; - UINT32 VariableSize; - - // - // Initialize variables - // - Hash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA); - HashSize =3D Signature->length - sizeof (SIGNATURE_DATA); - Status =3D EFI_UNSUPPORTED; - Variable =3D NULL; - VariableSize =3D 0; + UINT8 *Hash; + UINT32 HashSize; + SIGNATURE_DATA *Signature; + UINT32 Size; + EFI_STATUS Status; + UINT8 *Variable; + UINT32 VariableSize; =20 // // Sanity checks @@ -194,22 +163,25 @@ SignedHashCheck ( Status =3D EFI_INVALID_PARAMETER; goto Exit; } - if (Signature =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Buffer is NULL!\n", __FUNCTIO= N__, __LINE__)); - Status =3D EFI_INVALID_PARAMETER; - goto Exit; - } - if (Signature->hashtype =3D=3D 0) { - // - // Nothing to do. Bail. - // - Status =3D EFI_SUCCESS; + + // + // Get $PromSig structure + // + Size =3D 0; + Status =3D GetEepromStructure (LibraryIndex, EEPROM_SIGNATURE_SIGNATURE,= (UINT8 **) &Signature, &Size); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUN= CTION__, __LINE__)); + Status =3D EFI_VOLUME_CORRUPTED; goto Exit; } + Hash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA); + HashSize =3D Signature->length - sizeof (SIGNATURE_DATA); =20 // // Get stored hash // + Variable =3D NULL; + VariableSize =3D 0; Status =3D GetEepromVariable (LibraryIndex, &Variable, &VariableSize); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get variable! [%r]\= n", __FUNCTION__, __LINE__, Status)); @@ -245,7 +217,11 @@ SignedHashCheck ( } =20 Exit: - Variable =3D EepromFreePool (Variable); + // + // Clear resources + // + Signature =3D EepromFreePool (Signature); + Variable =3D EepromFreePool (Variable); return Status; } =20 diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/V= alidateHash.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLi= b/ValidateHash.c index 355033c..7d670c5 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Validate= Hash.c +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Validate= Hash.c @@ -28,23 +28,6 @@ CONST UINT8 mHashSizeLookup[] =3D { SHA512_DIGEST_SIZE }; =20 -UINTN -EFIAPI -DisplayStackPointer ( - IN CHAR8 *Function, - IN UINTN LineNumber - ) -{ - UINT8 *Temp; - =20 - Temp =3D AllocatePool (1); - if (mEepromDataLibDebugFlag) { - DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom =3D %08x\n", __FUNCT= ION__, __LINE__, Temp)); - } - - return (UINTN) Temp; -} - BOOLEAN EFIAPI InPeiPhase (VOID) @@ -102,47 +85,47 @@ Exit: EFI_STATUS EFIAPI SignedHashCheck ( - IN UINT8 LibraryIndex, - IN UINT8 *ImageBuffer, - IN UINT32 Crc32Size, - IN SIGNATURE_DATA *Signature + IN UINT8 LibraryIndex ) { - UINT8 Digest[MAX_DIGEST_SIZE]; - FV_FUNCTION_INFO FvInfo; - EFI_GUID FvPublicKeyFile; - UINT8 *Hash; - UINT32 HashSize; - BOOLEAN HashStatus; - UINT16 HashType; - UINT8 *PublicKey; - UINT32 PublicKeySize; - VOID *Rsa; - BOOLEAN RsaStatus; - UINT8 *SignedHash; - UINT32 SignedHashSize; - EFI_STATUS Status; + UINT32 Crc32Size; + UINT8 Digest[MAX_DIGEST_SIZE]; + EEPROM_HEADER *EepromHeader; + EEPROM_FUNCTION_INFO EepromInfo; + FV_FUNCTION_INFO FvInfo; + EFI_GUID FvPublicKeyFile; + UINT8 *Hash; + UINT32 HashSize; + BOOLEAN HashStatus; + UINT16 HashType; + UINT8 *ImageBuffer; + UINT32 ImageSize; + UINT8 *PublicKey; + UINT32 PublicKeySize; + VOID *Rsa; + BOOLEAN RsaStatus; + SIGNATURE_DATA *Signature; + UINT8 *SignedHash; + UINT32 SignedHashSize; + UINT32 Size; + EFI_STATUS Status; =20 // // Initialize variables // CopyMem (&FvPublicKeyFile, PcdGetPtr (PcdEepromPublicKeyFile), sizeof (E= FI_GUID)); ZeroMem (&FvInfo, sizeof (FV_FUNCTION_INFO)); + EepromInfo.Bus =3D PcdGet8 (PcdEepromBus); + EepromInfo.Address =3D PcdGet8 (PcdEepromAddress); + EepromInfo.LibraryIndex =3D EEPROM_EEPROM; FvInfo.LibraryIndex =3D EEPROM_FV; FvInfo.FvFileGuid =3D &FvPublicKeyFile; - Hash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA); - HashType =3D Signature->hashtype; - HashSize =3D mHashSizeLookup[HashType & HASH_TYPE_MASK]; PublicKey =3D NULL; PublicKeySize =3D 0; Rsa =3D NULL; SignedHash =3D NULL; SignedHashSize =3D 0; Status =3D EFI_UNSUPPORTED; - if (HashType & HASH_SIGNED_FLAG) { - SignedHash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA) + H= ashSize; - SignedHashSize =3D Signature->length - sizeof (SIGNATURE_DATA) - HashS= ize; - } =20 // // Sanity checks @@ -152,16 +135,53 @@ SignedHashCheck ( Status =3D EFI_INVALID_PARAMETER; goto Exit; } - if ((ImageBuffer =3D=3D NULL) || (Signature =3D=3D NULL)) { - DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Buffer is NULL!\n", __FUNCTIO= N__, __LINE__)); - Status =3D EFI_INVALID_PARAMETER; + + // + // Get binary image size + // + ImageSize =3D GetImageSize (LibraryIndex); + if (ImageSize =3D=3D 0) { + // + // Oops! + // + Status =3D EFI_NOT_FOUND; + goto Exit; + } + + // + // Get $Eeprom$ structure + // + Size =3D 0; + Status =3D GetEepromStructure (LibraryIndex, EEPROM_HEADER_SIGNATURE, (U= INT8 **) &EepromHeader, &Size); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUN= CTION__, __LINE__)); + Status =3D EFI_VOLUME_CORRUPTED; goto Exit; } + Crc32Size =3D EepromHeader->crclength; if (Crc32Size =3D=3D 0) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Buffer size is 0!\n", __FUNCT= ION__, __LINE__)); Status =3D EFI_INVALID_PARAMETER; goto Exit; } + + // + // Get $PromSig structure + // + Size =3D 0; + Status =3D GetEepromStructure (LibraryIndex, EEPROM_SIGNATURE_SIGNATURE,= (UINT8 **) &Signature, &Size); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUN= CTION__, __LINE__)); + Status =3D EFI_VOLUME_CORRUPTED; + goto Exit; + } + Hash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA); + HashType =3D Signature->hashtype; + HashSize =3D mHashSizeLookup[HashType & HASH_TYPE_MASK]; + if (HashType & EEPROM_SIGNATURE_TYPE_SIGNED) { + SignedHash =3D ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA) + H= ashSize; + SignedHashSize =3D Signature->length - sizeof (SIGNATURE_DATA) - HashS= ize; + } if (HashType =3D=3D 0) { // // Nothing to do. Bail. @@ -186,6 +206,26 @@ SignedHashCheck ( } =20 // + // Get binary image + // + ImageBuffer =3D EepromAllocatePool (ImageSize); + if (ImageBuffer =3D=3D NULL) { + // + // Failed to allocate pool + // + DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to allocate pool for B= uffer!\n", __FUNCTION__, __LINE__)); + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + Status =3D ReadEeprom (LibraryIndex, 0, &ImageSize, ImageBuffer, &Eeprom= Info); + if (EFI_ERROR (Status)) { + // + // Oops!!! + // + goto Exit; + } + + // // Clear existing NvStorage variable if it exists. gEepromVariableGuid:L= "PromSig-#" // Status =3D SetEepromVariable (LibraryIndex, NULL, 0); @@ -198,12 +238,12 @@ SignedHashCheck ( // Figure out what hash is being used // switch (HashType & HASH_TYPE_MASK) { - case HASH_NONE: + case EEPROM_SIGNATURE_TYPE_NONE: // // Nothing to do. Bail. // break; - case HASH_MD5: + case EEPROM_SIGNATURE_TYPE_MD5: // // MD5 hashing // @@ -221,7 +261,7 @@ SignedHashCheck ( } HashSize =3D MD5_DIGEST_SIZE; break; - case HASH_SHA1: + case EEPROM_SIGNATURE_TYPE_SHA1: // // SHA1 hashing // @@ -239,7 +279,7 @@ SignedHashCheck ( } HashSize =3D SHA1_DIGEST_SIZE; break; - case HASH_SHA256: + case EEPROM_SIGNATURE_TYPE_SHA256: // // SHA256 hashing // @@ -257,7 +297,7 @@ SignedHashCheck ( } HashSize =3D SHA256_DIGEST_SIZE; break; - case HASH_SHA384: + case EEPROM_SIGNATURE_TYPE_SHA384: // // SHA384 hashing // @@ -275,7 +315,7 @@ SignedHashCheck ( } HashSize =3D SHA384_DIGEST_SIZE; break; - case HASH_SHA512: + case EEPROM_SIGNATURE_TYPE_SHA512: // // SHA512 hashing // @@ -306,7 +346,7 @@ SignedHashCheck ( // // Does this have a signed hash? // - if ((HashType & HASH_SIGNED_FLAG) !=3D HASH_SIGNED_FLAG) { + if ((HashType & EEPROM_SIGNATURE_TYPE_SIGNED) !=3D EEPROM_SIGNATURE_TYPE= _SIGNED) { // // Nope. Bail. // @@ -382,7 +422,10 @@ Exit: if (Rsa !=3D NULL) { RsaFree (Rsa); } - PublicKey =3D EepromFreePool (PublicKey); + EepromHeader =3D EepromFreePool (EepromHeader); + ImageBuffer =3D EepromFreePool (ImageBuffer); + PublicKey =3D EepromFreePool (PublicKey); + Signature =3D EepromFreePool (Signature); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __L= INE__, Status)); } else if (HashType !=3D 0) { diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Eep= romStruct.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Ee= promStruct.h index e3d0fa6..0c4f6bd 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/EepromStru= ct.h +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/EepromStru= ct.h @@ -36,6 +36,8 @@ typedef struct { CHAR8 reserved[16]; }EEPROM_HEADER; =20 +#define EEPROM_HEADER_SIGNATURE "$Eeprom$" + =20 typedef struct { CHAR8 signature[8]; @@ -46,6 +48,8 @@ typedef struct { // UINT8 acpitbl[0]; }ACPI_TABLE; =20 +#define EEPROM_ACPI_TABLE_SIGNATURE "$AcpiTbl" + =20 typedef struct { CHAR8 signature[8]; @@ -62,6 +66,10 @@ typedef struct { CHAR8 reserved[19]; }BOARD_INFO_TABLE; =20 +#define EEPROM_BOARD_INFO_SIGNATURE "$BrdInfo" +#define EEPROM_BOARD_TYPE_REDBOX 0x00 +#define EEPROM_BOARD_TYPE_PLUGIN 0x01 + =20 typedef struct { CHAR8 signature[8]; @@ -79,6 +87,8 @@ typedef struct { // UINT8 mapdata[0]; }EEPROM_MAP; =20 +#define EEPROM_MAP_SIGNATURE "$EeprMap" + =20 typedef struct { CHAR8 maplabel[16]; @@ -88,6 +98,10 @@ typedef struct { CHAR8 reserved[7]; }EEPROM_MAP_RECORD; =20 +#define EEPROM_SPEED_STANDARD 0x01 +#define EEPROM_SPEED_FAST 0x02 +#define EEPROM_SPEED_HIGH 0x03 + =20 typedef struct { CHAR8 signature[8]; @@ -98,6 +112,8 @@ typedef struct { // UINT8 gpiodata[0]; }GPIO_DATA_HEADER; =20 +#define EEPROM_GPIO_SIGNATURE "$GpioDat" + =20 typedef struct { CHAR8 gpiolabel[16]; @@ -110,6 +126,12 @@ typedef struct { CHAR8 reserved[14]; }GPIO_DATA_RECORD; =20 +#define EEPROM_GPIO_TYPE_IO 0x00 +#define EEPROM_GPIO_TYPE_MMIO 0x01 +#define EEPROM_GPIO_TYPE_PCI 0x02 +#define EEPROM_GPIO_TYPE_PCIE 0x03 +#define EEPROM_GPIO_TYPE_PAD_OFFSET 0x04 + =20 typedef struct { CHAR8 signature[8]; @@ -120,6 +142,8 @@ typedef struct { // UINT8 hdacodec[0]; }HDA_CODEC; =20 +#define EEPROM_HDA_CODEC_SIGNATURE "$HdCodec" + =20 typedef struct { CHAR8 signature[8]; @@ -129,7 +153,9 @@ typedef struct { UINT16 spdslot; CHAR8 reserved[14]; // UINT8 spddata[0]; -}MEMORY_SPD; +}MEMORY_DATA; + +#define EEPROM_MEMORY_DATA_SIGNATURE "$MemCnfg" =20 =20 typedef struct { @@ -144,6 +170,8 @@ typedef struct { // UINT8 nicdata[0]; }NIC_INFO; =20 +#define EEPROM_NIC_INFO_SIGNATURE "$MacInfo" + =20 typedef struct { CHAR8 signature[8]; @@ -155,6 +183,15 @@ typedef struct { // UINT8 eepromsig[0]; }SIGNATURE_DATA; =20 +#define EEPROM_SIGNATURE_SIGNATURE "$PromSig" +#define EEPROM_SIGNATURE_TYPE_NONE 0x0000 +#define EEPROM_SIGNATURE_TYPE_MD5 0x0001 +#define EEPROM_SIGNATURE_TYPE_SHA1 0x0002 +#define EEPROM_SIGNATURE_TYPE_SHA256 0x0003 +#define EEPROM_SIGNATURE_TYPE_SHA384 0x0004 +#define EEPROM_SIGNATURE_TYPE_SHA512 0x0005 +#define EEPROM_SIGNATURE_TYPE_SIGNED 0x8000 + =20 typedef struct { CHAR8 signature[8]; @@ -165,6 +202,8 @@ typedef struct { // UINT8 ucodedata[0]; }MICROCODE; =20 +#define EEPROM_MICROCODE_SIGNATURE "$uCode$" + =20 typedef struct { CHAR8 signature[8]; @@ -175,6 +214,8 @@ typedef struct { // UINT8 videodata[0]; }VIDEO_DATA; =20 +#define EEPROM_VIDEO_DATA_SIGNATURE "$Video$" + =20 typedef struct { CHAR8 signature[8]; @@ -185,5 +226,7 @@ typedef struct { // UINT8 logodata[0]; }LOGO_DATA; =20 +#define EEPROM_LOGO_DATA_SIGNATURE "$Logo$" + #pragma pack() #endif diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Lib= rary/EepromDataLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/I= nclude/Library/EepromDataLib.h index 0d71b3d..0c9fcfe 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/Ee= promDataLib.h +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/Ee= promDataLib.h @@ -67,6 +67,13 @@ typedef struct { //// //// Functions //// +UINTN +EFIAPI +DisplayStackPointer ( + IN CHAR8 *Function, + IN UINTN LineNumber + ); + // // Desc: Copies the contents of an existing memory pool into a new = memory pool of equal or greater size. // Variables: Size Size of the pool to copy existing pool into diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Lib= rary/EepromLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Inclu= de/Library/EepromLib.h index b386e8c..f9bcdb6 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/Ee= promLib.h +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/Ee= promLib.h @@ -19,6 +19,7 @@ #include =20 #include +#include =20 =20 //// @@ -28,28 +29,8 @@ =20 =20 //// -//// Enums -//// -typedef enum { - HASH_NONE =3D 0, - HASH_MD5 =3D 1, - HASH_SHA1 =3D 2, - HASH_SHA256 =3D 3, - HASH_SHA384 =3D 4, - HASH_SHA512 =3D 5 -} EEPROM_HASH_TYPE; - - -//// //// Functions //// -UINTN -EFIAPI -DisplayStackPointer ( - IN CHAR8 *Function, - IN UINTN LineNumber - ); - EFI_STATUS EFIAPI EraseEeprom ( @@ -83,8 +64,7 @@ GetNextEepromStructure ( UINT8 EFIAPI GetValidEepromLibrary ( - IN BOOLEAN CopyToMemory, - IN BOOLEAN MemoryInitialized + IN BOOLEAN CopyToMemory ); =20 BOOLEAN diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Lib= rary/EepromPlatformLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eepr= om/Include/Library/EepromPlatformLib.h new file mode 100644 index 0000000..b585327 --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/Ee= promPlatformLib.h @@ -0,0 +1,117 @@ +/** @file + Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef _EEPROM_PLATFORM_LIB_ +#define _EEPROM_PLATFORM_LIB_ +//// +//// Header files +//// +#include + +#include +#include +#include + + +//// +//// defines +//// +#define END_OF_GPIO_ARRAY 0xFFFFFFFF + + +//// +//// Functions +//// +/** + Returns the $BrdInfo structure + + @param[out] BoardInfo Buffer containing the BOARD_INFO_TABLE stru= cture + - Up to the caller to free the buffer + + @retval EFI_SUCCESS $BrdInfo structure found + @retval EFI_NOT_FOUND $BrdInfo structure not found +**/ +EFI_STATUS +EepromGetBoardInfo ( + OUT BOARD_INFO_TABLE **BoardInfo + ); + +/** + Returns the $Logo$ data + + @param[out] LogoData Buffer containing the $Logo$ data + @param[out] LogoSize Size of the LogoData buffer + + @retval EFI_SUCCESS $Logo$ data found + @retval EFI_NOT_FOUND $Logo$ data not found +**/ +EFI_STATUS +EepromGetLogo ( + OUT UINT8 **LogoData, + OUT UINT32 *LogoSize + ); + +/** + Returns the $Video$ data + + @param[out] VideoData Buffer containing the $Video$ data + @param[out] VideoSize Size of the VideoData buffer + + @retval EFI_SUCCESS $Logo$ data found + @retval EFI_NOT_FOUND $Logo$ data not found +**/ + +EFI_STATUS +EepromGetVbt ( + OUT UINT8 **VideoData, + OUT UINT32 *VideoSize + ); + +/** + Checks whether the PadOffset is in the platform GPIO whitelist. + + @param[in] PadOffset The PAD offset to check against the platform wh= itelist + + @retval TRUE PAD offset is in the whitelist + @retval FALSE PAD offset is not in the whitelist +**/ +BOOLEAN +EepromPadCheck ( + IN UINT32 PadOffset + ); + +/** + Programs the ACPI SSDT data in $AcpiTbl + + @param[in] VOID + + @retval EFI_SUCCESS $AcpiTbl data found + @retval EFI_NOT_FOUND $AcpiTbl data not found + @retval EFI_NOT_READY $AcpiTbl data not ready to be programmed +**/ +EFI_STATUS +EepromProgramAcpi (VOID); + +/** + Program GPIOs per binary and whitelist. + + @param[in] VOID + + @retval EFI_SUCCESS GPIOs programmed successfully. + @retval EFI_NOT_FOUND GPIO data not found. +**/ +EFI_STATUS +EepromProgramGpioPads (VOID); + +#endif // _EEPROM_PLATFORM_LIB_ + --=20 2.10.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel