From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by mx.groups.io with SMTP id smtpd.web11.7197.1628347881640878376 for ; Sat, 07 Aug 2021 07:51:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20161025 header.b=EG0ojuLQ; spf=pass (domain: flex--chengchieh.bounces.google.com, ip: 209.85.219.201, mailfrom: 36j0oyqokbw0nspyrnstpsrzzrwp.nzxopgpwpovn.rczfad.tz@flex--chengchieh.bounces.google.com) Received: by mail-yb1-f201.google.com with SMTP id c19-20020a25c0130000b029059337c4e310so5680367ybf.3 for ; Sat, 07 Aug 2021 07:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=5dCR0YgjrySqxUK/xf/VrJjRx6FedGqkcVXGwIOA0/M=; b=EG0ojuLQgaJobpWVQxIUaXuKFCo3xnCmQQaY9UGIHGvuP4jp6ECuLt0/GSOk5Bl8PD 11jURut2GNqtDVitzVewNXQ1/KB1BBRqhs+S+x1icaD0zi4viqq/I2qZW7Bh1m4BaSeH 5uPFp2K68MXs+ofvwBsqQY2bk5Vx4s92hhngIgnSGE7FfdcXOL+3Vxlyi3RoWk+NOG3U bQyZ5MRN8Iho7PgN2Ww2Db8ETEnVrhAacMNprB4QipGwuI10n/UB00QNlCP+dJNNWSWz fzaVyodo4QkCdLCOEm8VNt0kGXA+osvqb4Iiis7DIsmhepNoaSegFfVerD2vg/MTejWO ngqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5dCR0YgjrySqxUK/xf/VrJjRx6FedGqkcVXGwIOA0/M=; b=hR1YuhgIFS45j9yBFDWJadvQmUSGtOO1IfrxQSX/loKzcpGLgmNBr/175rzQJ79Y/i t8Jor3J1+ULrF/94x/eUcpCMggVylCd8q//AXk8C6CuDHVrHKaOcUvq6EhuF0gRaYZty 6tk351f/HsTyrJ6E4RerR7pa4OM7tKMQbXvQE301ypQf+oN/QgwWsNHE4HdA2u4uqLyp nks6T4Ht41cR+7aMCUf9Jug4Fi4tq0OXJ+LxJHbunGhsAZiU6u/hhES0UVBUEWwykY7i Gb90DHxFEHXFx2x5hSbgtX7ZRfMQlDvZP7yAlJLbLLsfq7qmtNR2p9vfCfEcV9LkQd2N edHA== X-Gm-Message-State: AOAM533JwrzsBYhyeGJMX26o/kIiguOLGZHl5DJnUJTblQnjvkPI/hx9 LEe+OoJutpytcfwStc22iDXwbyJ5cPp96WlVNBq87tKWrn5JkiIOWbVkX6FQNUcIwIUPR6dg4Vj lSpvkmckv8DjIWBkGP9RbOIVEO6oBYxnZtNpdn2r7eyHBu653SCOOuHTwxeX7OTw0WVGREg== X-Google-Smtp-Source: ABdhPJxH67Irb6Ap45S7XmPQVmaiH4vjRgLQshRf7Zf1iE3ANexrHXPbkC2ba0Ey47u0zTatdEtYrul+RMXu0oFp X-Received: from ratho96.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:aae]) (user=chengchieh job=sendgmr) by 2002:a25:be09:: with SMTP id h9mr20548489ybk.239.1628347880705; Sat, 07 Aug 2021 07:51:20 -0700 (PDT) Date: Sat, 7 Aug 2021 14:51:03 +0000 In-Reply-To: <20210807145106.2236803-1-chengchieh@google.com> Message-Id: <20210807145106.2236803-2-chengchieh@google.com> Mime-Version: 1.0 References: <20210807145106.2236803-1-chengchieh@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v2 1/4] UefiPayloadPkg: Add LINUXBOOT payload target From: Cheng-Chieh Huang To: devel@edk2.groups.io Cc: Cheng-Chieh Huang , Daniel Schaefer , Trammell Hudson , Maurice Ma , Guo Dong , Benjamin You Content-Type: text/plain; charset="UTF-8" Initial commit to support linuxboot payload. Signed-off-by: Cheng-Chieh Huang Cc: Cheng-Chieh Huang Cc: Daniel Schaefer Cc: Trammell Hudson Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You --- UefiPayloadPkg/UefiPayloadPkg.dsc | 16 +- UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf | 39 +++++ UefiPayloadPkg/Library/LbParseLib/Linuxboot.h | 47 +++++ UefiPayloadPkg/Library/LbParseLib/LbParseLib.c | 182 ++++++++++++++++++++ UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c | 6 +- 5 files changed, 283 insertions(+), 7 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index bcedf1c746b4..54576ba485b7 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -33,6 +33,7 @@ [Defines] # # SBL: UEFI payload for Slim Bootloader # COREBOOT: UEFI payload for coreboot + # LINUXBOOT: UEFI payload for linuxboot # DEFINE BOOTLOADER = SBL @@ -93,6 +94,9 @@ [Defines] [BuildOptions] *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES +!if $(BOOTLOADER) == "LINUXBOOT" + *_*_*_CC_FLAGS = -D LINUXBOOT_PAYLOAD +!endif GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG @@ -222,11 +226,13 @@ [LibraryClasses] !endif PlatformSupportLib|UefiPayloadPkg/Library/PlatformSupportLibNull/PlatformSupportLibNull.inf !if $(UNIVERSAL_PAYLOAD) == FALSE - !if $(BOOTLOADER) == "COREBOOT" - BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf - !else - BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf - !endif + !if $(BOOTLOADER) == "COREBOOT" + BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf + !elseif $(BOOTLOADER) == "LINUXBOOT" + BlParseLib|UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf + !else + BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf + !endif !endif DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf diff --git a/UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf b/UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf new file mode 100644 index 000000000000..d75ba8db8cf3 --- /dev/null +++ b/UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf @@ -0,0 +1,39 @@ +## @file +# Linuxboot Table Parse Library. +# +# Copyright (c) 2021, the u-root Authors. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = LbParseLib + FILE_GUID = DBA15E1E-4C16-47DF-93C0-AB5888ED14C3 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = BlParseLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + LbParseLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + IoLib + DebugLib + PcdLib + +[Pcd] + gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemBase diff --git a/UefiPayloadPkg/Library/LbParseLib/Linuxboot.h b/UefiPayloadPkg/Library/LbParseLib/Linuxboot.h new file mode 100644 index 000000000000..34ca18069983 --- /dev/null +++ b/UefiPayloadPkg/Library/LbParseLib/Linuxboot.h @@ -0,0 +1,47 @@ +/** @file + LinuxBoot PEI module include file. +**/ +#ifndef _LINUXBOOT_PEI_H_INCLUDED_ +#define _LINUXBOOT_PEI_H_INCLUDED_ + +#if defined(_MSC_VER) +#pragma warning(disable : 4200) +#endif + +#pragma pack(1) +typedef struct SerialPortConfigStruct { + UINT32 Type; + UINT32 BaseAddr; + UINT32 Baud; + UINT32 RegWidth; + UINT32 InputHertz; + UINT32 UartPciAddr; +} SerialPortConfig; + +typedef struct MemoryMapEntryStruct { + UINT64 Start; + UINT64 End; + UINT32 Type; +} MemoryMapEntry; + +typedef struct UefiPayloadConfigStruct { + UINT64 Version; + UINT64 AcpiBase; + UINT64 AcpiSize; + UINT64 SmbiosBase; + UINT64 SmbiosSize; + SerialPortConfig SerialConfig; + UINT32 NumMemoryMapEntries; + MemoryMapEntry MemoryMapEntries[0]; +} UefiPayloadConfig; +#pragma pack() + +#define UEFI_PAYLOAD_CONFIG_VERSION 1 + +#define LINUXBOOT_MEM_RAM 1 +#define LINUXBOOT_MEM_DEFAULT 2 +#define LINUXBOOT_MEM_ACPI 3 +#define LINUXBOOT_MEM_NVS 4 +#define LINUXBOOT_MEM_RESERVED 5 + +#endif // _LINUXBOOT_PEI_H_INCLUDED_ diff --git a/UefiPayloadPkg/Library/LbParseLib/LbParseLib.c b/UefiPayloadPkg/Library/LbParseLib/LbParseLib.c new file mode 100644 index 000000000000..410062af314a --- /dev/null +++ b/UefiPayloadPkg/Library/LbParseLib/LbParseLib.c @@ -0,0 +1,182 @@ +/** @file + This library will parse the linuxboot table in memory and extract those required + information. + + Copyright (c) 2021, the u-root Authors. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Retrieve UefiPayloadConfig from Linuxboot's uefiboot +UefiPayloadConfig* GetUefiPayLoadConfig() { + UefiPayloadConfig *Config = + (UefiPayloadConfig*)(UINTN)(PcdGet32(PcdPayloadFdMemBase) - SIZE_64KB); + if (Config->Version != UEFI_PAYLOAD_CONFIG_VERSION) { + DEBUG((DEBUG_ERROR, "Expect payload Config version: %d, but get %d\n", + UEFI_PAYLOAD_CONFIG_VERSION, Config->Version)); + CpuDeadLoop (); + } + return Config; +} + +// Align the address and add memory rang to MemInfoCallback +void AddMemoryRange( + IN BL_MEM_INFO_CALLBACK MemInfoCallback, + IN UINTN start, + IN UINTN end, + IN int type) { + MEMROY_MAP_ENTRY MemoryMap; + UINTN AlignedStart; + UINTN AlignedEnd; + AlignedStart = ALIGN_VALUE(start, SIZE_4KB); + AlignedEnd = ALIGN_VALUE(end, SIZE_4KB); + // Conservative adjustment on Memory map. This should happen when booting from + // non UEFI bios and it may report a memory region less than 4KB. + if (AlignedStart > start && type != LINUXBOOT_MEM_RAM) { + AlignedStart -= SIZE_4KB; + } + if (AlignedEnd > end + 1 && type == LINUXBOOT_MEM_RAM) { + AlignedEnd -= SIZE_4KB; + } + MemoryMap.Base = AlignedStart; + MemoryMap.Size = AlignedEnd - AlignedStart; + MemoryMap.Type = type; + MemoryMap.Flag = 0; + MemInfoCallback(&MemoryMap, NULL); +} + +/** + Acquire the memory information from the linuxboot table in memory. + + @param MemInfoCallback The callback routine + @param Params Pointer to the callback routine parameter + + @retval RETURN_SUCCESS Successfully find out the memory information. + @retval RETURN_NOT_FOUND Failed to find the memory information. + +**/ +RETURN_STATUS +EFIAPI +ParseMemoryInfo( + IN BL_MEM_INFO_CALLBACK MemInfoCallback, + IN VOID* Params + ) { + UefiPayloadConfig *Config; + int Index; + + Config = GetUefiPayLoadConfig(); + + DEBUG((DEBUG_INFO, "MemoryMap #entries: %d\n", Config->NumMemoryMapEntries)); + + MemoryMapEntry* entry = &Config->MemoryMapEntries[0]; + for (Index = 0; Index < Config->NumMemoryMapEntries; Index++) { + DEBUG((DEBUG_INFO, "Start: 0x%lx End: 0x%lx Type:%d\n", entry->Start, + entry->End, entry->Type)); + AddMemoryRange(MemInfoCallback, entry->Start, entry->End, entry->Type); + entry++; + } + return RETURN_SUCCESS; +} + +/** + Acquire acpi table and smbios table from linuxboot + + @param SystemTableInfo Pointer to the system table info + + @retval RETURN_SUCCESS Successfully find out the tables. + @retval RETURN_NOT_FOUND Failed to find the tables. + +**/ +RETURN_STATUS +EFIAPI +ParseSystemTable( + OUT SYSTEM_TABLE_INFO* SystemTableInfo + ) { + UefiPayloadConfig *Config; + + Config = GetUefiPayLoadConfig(); + SystemTableInfo->AcpiTableBase = Config->AcpiBase; + SystemTableInfo->AcpiTableSize = Config->AcpiSize; + + SystemTableInfo->SmbiosTableBase = Config->SmbiosBase; + SystemTableInfo->SmbiosTableSize = Config->SmbiosSize; + + return RETURN_SUCCESS; +} + +/** + Find the serial port information + + @param SERIAL_PORT_INFO Pointer to serial port info structure + + @retval RETURN_SUCCESS Successfully find the serial port information. + @retval RETURN_NOT_FOUND Failed to find the serial port information . + +**/ +RETURN_STATUS +EFIAPI +ParseSerialInfo( + OUT SERIAL_PORT_INFO* SerialPortInfo + ) { + UefiPayloadConfig *Config; + Config = GetUefiPayLoadConfig(); + + SerialPortInfo->BaseAddr = Config->SerialConfig.BaseAddr; + SerialPortInfo->RegWidth = Config->SerialConfig.RegWidth; + SerialPortInfo->Type = Config->SerialConfig.Type; + SerialPortInfo->Baud = Config->SerialConfig.Baud; + SerialPortInfo->InputHertz = Config->SerialConfig.InputHertz; + SerialPortInfo->UartPciAddr = Config->SerialConfig.UartPciAddr; + + return RETURN_SUCCESS; +} + +/** + Find the video frame buffer information + + @param GfxInfo Pointer to the EFI_PEI_GRAPHICS_INFO_HOB structure + + @retval RETURN_SUCCESS Successfully find the video frame buffer +information. + @retval RETURN_NOT_FOUND Failed to find the video frame buffer information . + +**/ +RETURN_STATUS +EFIAPI +ParseGfxInfo( + OUT EFI_PEI_GRAPHICS_INFO_HOB* GfxInfo + ) { + // Not supported + return RETURN_NOT_FOUND; +} + +/** + Find the video frame buffer device information + + @param GfxDeviceInfo Pointer to the EFI_PEI_GRAPHICS_DEVICE_INFO_HOB +structure + + @retval RETURN_SUCCESS Successfully find the video frame buffer +information. + @retval RETURN_NOT_FOUND Failed to find the video frame buffer information. + +**/ +RETURN_STATUS +EFIAPI +ParseGfxDeviceInfo( + OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB* GfxDeviceInfo + ) { + return RETURN_NOT_FOUND; +} diff --git a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c index b0268f05069c..a4f714f765ea 100644 --- a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c +++ b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c @@ -40,8 +40,9 @@ AdjustRootBridgeResource ( IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G ) { +#ifndef LINUXBOOT_PAYLOAD UINT64 Mask; - +#endif // // For now try to downgrade everything into MEM32 since // - coreboot does not assign resource above 4GB @@ -80,7 +81,7 @@ AdjustRootBridgeResource ( PMemAbove4G->Base = MAX_UINT64; PMemAbove4G->Limit = 0; } - +#ifndef LINUXBOOT_PAYLOAD // // Align IO resource at 4K boundary // @@ -98,6 +99,7 @@ AdjustRootBridgeResource ( if (Mem->Base != MAX_UINT64) { Mem->Base &= ~Mask; } +#endif } /** -- 2.32.0.605.g8dce9f2422-goog