From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 330A0740032 for ; Fri, 24 May 2024 02:06:33 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=CBy6I2M1qwKg6ZQ8diGF+8RuvfAz+53WoEyYM7c/l9s=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1716516391; v=1; b=reqHgi8oNEWxqPTA98vAHRTtffqBeXW+C3J60RW2tEgca6QpwMyfMt0bDdw4yd/1WE3zAS9k OqvS1y86RhjYboiFQUlLpsP0ARTO7wu61mTCpbBRnn5eH5LUBCOJ1NZkjQe/11iREGJs2K3B9vT yDHvdYd/Zy8FPFIuivF5Ki81NyJ8h2UoWXyaMTeK68ryi2d22yYZVudjen8kR2oSSlsc3aPOqUF 7xdOny1yhXXsAFeUj9VznbrTxIZ2DET4L3ZPONAh4+DrWZlrgEiv2srxqpMAnyq5cupiwBpRJYZ uxEPTr/otYR9RxZdzGyf9kiHV1PHSiFr1Uj9LFy3O4y+w== X-Received: by 127.0.0.2 with SMTP id 3plCYY7687511xxB8QSxVD2W; Thu, 23 May 2024 19:06:31 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mx.groups.io with SMTP id smtpd.web10.6819.1716516390293986290 for ; Thu, 23 May 2024 19:06:30 -0700 X-CSE-ConnectionGUID: 36YIaJXrSu+v6IUbdHohwQ== X-CSE-MsgGUID: LrhXtzwzQMiFg4HIfwHODg== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="16712525" X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="16712525" X-Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 19:06:30 -0700 X-CSE-ConnectionGUID: 3clYxWqSSyqXVJpIfTNPuQ== X-CSE-MsgGUID: bL92wZVIToOjvUrW6uyd4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="33877056" X-Received: from linusliu-desk1.gar.corp.intel.com ([10.225.76.64]) by fmviesa006.fm.intel.com with ESMTP; 23 May 2024 19:06:27 -0700 From: "Linus Liu" To: devel@edk2.groups.io Cc: Benny Lin , Gua Guo , Chasel Chiu , James Lu , Dhaval Sharma Subject: [edk2-devel] [PATCH v1 4/6] UefiPayloadPkg: Update PayloadLoader to suport FDT. Date: Thu, 23 May 2024 19:06:21 -0700 Message-Id: <20240524020621.1735-1-linus.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 23 May 2024 19:06:30 -0700 Resent-From: linus.liu@intel.com Reply-To: devel@edk2.groups.io,linus.liu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: qhcknVjmW31IwfFaK97fgQBWx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=reqHgi8o; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io Create FDT nodes (reserved-memory, serial, pci-rb, options) in FdtPpiNotifyCallback function right after gEfiEndOfPeiSignalPpiGuid. Cc: Benny Lin Cc: Gua Guo Cc: Chasel Chiu Cc: James Lu Cc: Dhaval Sharma Signed-off-by: Linus Liu --- UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c | 1004 +++++++++= ++++++++++- UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c | 71 +- UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf | 16 +- UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf | 12 + 4 files changed, 1077 insertions(+), 26 deletions(-) diff --git a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c b/Uefi= PayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c index de33d49bd1c6..00016c7756c5 100644 --- a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c +++ b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c @@ -6,18 +6,74 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D #include =0D #include =0D +#include =0D #include =0D +#include =0D #include =0D -=0D +#include =0D #include =0D =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D #include =0D #include =0D #include =0D #include =0D #include =0D -=0D +#include =0D +#include =0D +#include =0D #include "FitLib.h"=0D +#define STACK_SIZE 0x20000=0D +#define N_NON_RELOCATABLE BIT31=0D +#define P_NON_PREFETCHABLE BIT30=0D +#define SS_CONFIGURATION_SPACE 0=0D +#define SS_IO_SPACE BIT24=0D +#define SS_32BIT_MEMORY_SPACE BIT25=0D +#define SS_64BIT_MEMORY_SPACE BIT24+BIT25=0D +=0D +CONST EFI_PEI_PPI_DESCRIPTOR gReadyToPayloadSignalPpi =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gUplReadyToPayloadPpiGuid,=0D + NULL=0D +};=0D +=0D +EFI_PEI_PPI_DESCRIPTOR mEndOfPeiSignalPpi =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gEfiEndOfPeiSignalPpiGuid,=0D + NULL=0D +};=0D +=0D +#define MEMORY_ATTRIBUTE_DEFAULT (EFI_RESOURCE_ATTRIBUTE_PRESENT = | \=0D + EFI_RESOURCE_ATTRIBUTE_INITIALIZED = | \=0D + EFI_RESOURCE_ATTRIBUTE_TESTED = | \=0D + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE = | \=0D + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEA= BLE | \=0D + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_= CACHEABLE | \=0D + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CAC= HEABLE )=0D +=0D +CHAR8 *mMemoryAllocType[] =3D {=0D + "Reserved",=0D + "LoaderCode",=0D + "LoaderData",=0D + "boot-code",=0D + "boot-data",=0D + "runtime-code",=0D + "runtime-data",=0D + "ConventionalMemory",=0D + "UnusableMemory",=0D + "acpi",=0D + "acpi-nvs",=0D + "mmio",=0D + "MemoryMappedIOPortSpace",=0D + "PalCode",=0D + "PersistentMemory",=0D +};=0D =0D /**=0D The wrapper function of PeiLoadImageLoadImage().=0D @@ -50,6 +106,15 @@ PeiLoadFileLoadPayload ( UINTN Delta;=0D UINTN Index;=0D =0D + #if (FixedPcdGetBool (PcdHandOffFdtEnable))=0D + VOID *BaseOfStack;=0D + VOID *TopOfStack;=0D + UNIVERSAL_PAYLOAD_DEVICE_TREE *Fdt;=0D + VOID *Hob;=0D +=0D + Fdt =3D NULL;=0D + #endif=0D +=0D Instance =3D 0;=0D do {=0D Status =3D PeiServicesFfsFindSectionData3 (EFI_SECTION_RAW, Instance++= , FileHandle, &Binary, AuthenticationState);=0D @@ -66,13 +131,15 @@ PeiLoadFileLoadPayload ( return Status;=0D }=0D =0D - DEBUG ((=0D - DEBUG_INFO,=0D - "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoin= t: 0x%08x\n",=0D - Context.PayloadBaseAddress,=0D - Context.PayloadSize,=0D - Context.PayloadEntryPoint=0D - ));=0D + DEBUG (=0D + (=0D + DEBUG_INFO,=0D + "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoi= nt: 0x%08x\n",=0D + Context.PayloadBaseAddress,=0D + Context.PayloadSize,=0D + Context.PayloadEntryPoint=0D + )=0D + );=0D Context.PayloadBaseAddress =3D (EFI_PHYSICAL_ADDRESS)AllocatePages (EFI_= SIZE_TO_PAGES (Context.PayloadSize));=0D =0D RelocateTable =3D (FIT_RELOCATE_ITEM *)(UINTN)(Context.PayloadBaseAddres= s + Context.RelocateTableOffset);=0D @@ -96,13 +163,15 @@ PeiLoadFileLoadPayload ( }=0D }=0D =0D - DEBUG ((=0D - DEBUG_INFO,=0D - "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint= : 0x%08x\n",=0D - Context.PayloadBaseAddress,=0D - Context.PayloadSize,=0D - Context.PayloadEntryPoint=0D - ));=0D + DEBUG (=0D + (=0D + DEBUG_INFO,=0D + "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoin= t: 0x%08x\n",=0D + Context.PayloadBaseAddress,=0D + Context.PayloadSize,=0D + Context.PayloadEntryPoint=0D + )=0D + );=0D =0D Length =3D sizeof (UNIVERSAL_PAYLOAD_BASE);=0D PayloadBase =3D BuildGuidHob (=0D @@ -115,6 +184,42 @@ PeiLoadFileLoadPayload ( *ImageSizeArg =3D Context.PayloadSize;=0D *EntryPoint =3D Context.PayloadEntryPoint;=0D =0D + Status =3D PeiServicesInstallPpi (&mEndOfPeiSignalPpi);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D PeiServicesInstallPpi (&gReadyToPayloadSignalPpi);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + #if (FixedPcdGetBool (PcdHandOffFdtEnable))=0D + Hob =3D GetFirstGuidHob (&gUniversalPayloadDeviceTreeGuid);=0D + if (Hob !=3D NULL) {=0D + Fdt =3D (UNIVERSAL_PAYLOAD_DEVICE_TREE *)GET_GUID_HOB_DATA (Hob);=0D + }=0D +=0D + //=0D + // Allocate 128KB for the Stack=0D + //=0D + BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));=0D + ASSERT (BaseOfStack !=3D NULL);=0D +=0D + //=0D + // Compute the top of the stack we were allocated. Pre-allocate a UINTN= =0D + // for safety.=0D + //=0D + TopOfStack =3D (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SI= ZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);=0D + TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);=0D +=0D + //=0D + // Transfer the control to the entry point of UniveralPayloadEntry.=0D + //=0D + SwitchStack (=0D + (SWITCH_STACK_ENTRY_POINT)(UINTN)Context.PayloadEntryPoint,=0D + (VOID *)(Fdt->DeviceTreeAddress),=0D + NULL,=0D + TopOfStack=0D + );=0D + #endif=0D +=0D return EFI_SUCCESS;=0D }=0D =0D @@ -128,6 +233,865 @@ EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList =3D { &mPeiLoadFilePpi=0D };=0D =0D +#if (FixedPcdGetBool (PcdHandOffFdtEnable))=0D +=0D +/**=0D + Discover Hobs data and report data into a FDT.=0D + @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES= table published by the PEI Foundation.=0D + @param[in] NotifyDescriptor Address of the notification descriptor data= structure.=0D + @param[in] Ppi Address of the PPI that was installed.=0D + @retval EFI_SUCCESS Hobs data is discovered.=0D + @return Others No Hobs data is discovered.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +FdtPpiNotifyCallback (=0D + IN EFI_PEI_SERVICES **PeiServices,=0D + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,=0D + IN VOID *Ppi=0D + );=0D +=0D +EFI_PEI_NOTIFY_DESCRIPTOR mReadyToPayloadNotifyList[] =3D {=0D + {=0D + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMI= NATE_LIST),=0D + &gUplReadyToPayloadPpiGuid,=0D + FdtPpiNotifyCallback=0D + }=0D +};=0D +#endif=0D +=0D +/**=0D + Print FDT data.=0D + @param[in] FdtBase Address of the Fdt data.=0D +**/=0D +VOID=0D +PrintFdt (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + UINT8 *Fdt;=0D + UINT32 i;=0D +=0D + Fdt =3D NULL;=0D + i =3D 0;=0D +=0D + DEBUG ((DEBUG_ERROR, "FDT DTB data:"));=0D + for (Fdt =3D FdtBase, i =3D 0; i < Fdt32ToCpu (((FDT_HEADER *)FdtBase)->= TotalSize); i++, Fdt++) {=0D + if (i % 16 =3D=3D 0) {=0D + DEBUG ((DEBUG_ERROR, "\n"));=0D + }=0D +=0D + DEBUG ((DEBUG_ERROR, "%02x ", *Fdt));=0D + }=0D +=0D + DEBUG ((DEBUG_ERROR, "\n"));=0D +}=0D +=0D +/**=0D + It will build FDT based on memory information from Hobs.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForMemory (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_PEI_HOB_POINTERS Hob;=0D + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;=0D + VOID *HobStart;=0D + VOID *Fdt;=0D + INT32 TempNode;=0D + CHAR8 TempStr[32];=0D + UINT64 RegTmp[2];=0D +=0D + Fdt =3D FdtBase;=0D +=0D + HobStart =3D GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);=0D + //=0D + // Scan resource descriptor hobs to set memory nodes=0D + //=0D + for (Hob.Raw =3D HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw =3D GET_NEXT_= HOB (Hob)) {=0D + if (GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {=0D + ResourceHob =3D Hob.ResourceDescriptor;=0D + // Memory=0D + if (ResourceHob->ResourceType =3D=3D EFI_RESOURCE_SYSTEM_MEMORY) {=0D + // DEBUG ((DEBUG_ERROR, "Found hob for memory: base %016lX length= %016lX\n", ResourceHob->PhysicalStart, ResourceHob->ResourceLength));=0D +=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "memory@%lX",= ResourceHob->PhysicalStart);=0D + TempNode =3D FdtAddSubnode (Fdt, 0, TempStr);=0D + ASSERT (TempNode > 0);=0D +=0D + RegTmp[0] =3D CpuToFdt64 (ResourceHob->PhysicalStart);=0D + RegTmp[1] =3D CpuToFdt64 (ResourceHob->ResourceLength);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegTmp, sizeof (R= egTmp));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "device_type", "memory", (UI= NT32)(AsciiStrLen ("memory")+1));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + It will build FDT based on memory allocation information from Hobs.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForMemAlloc (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_PEI_HOB_POINTERS Hob;=0D + VOID *HobStart;=0D + VOID *Fdt;=0D + INT32 ParentNode;=0D + INT32 TempNode;=0D + CHAR8 TempStr[32];=0D + UINT64 RegTmp[2];=0D + UINT32 AllocMemType;=0D + EFI_GUID *AllocMemName;=0D + UINT8 IsStackHob;=0D + UINT8 IsBspStore;=0D + UINT32 Data32;=0D + // UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmbiosTable;=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTable;=0D +=0D + Fdt =3D FdtBase;=0D +=0D + ParentNode =3D FdtAddSubnode (Fdt, 0, "reserved-memory");=0D + ASSERT (ParentNode > 0);=0D +=0D + Data32 =3D CpuToFdt32 (2);=0D + Status =3D FdtSetProp (Fdt, ParentNode, "#address-cells", &Data32, sizeo= f (UINT32));=0D + Status =3D FdtSetProp (Fdt, ParentNode, "#size-cells", &Data32, sizeof (= UINT32));=0D +=0D + HobStart =3D GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);=0D + //=0D + // Scan memory allocation hobs to set memory type=0D + //=0D + for (Hob.Raw =3D HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw =3D GET_NEXT_= HOB (Hob)) {=0D + if (GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_MEMORY_ALLOCATION) {=0D + AllocMemName =3D NULL;=0D + IsStackHob =3D 0;=0D + IsBspStore =3D 0;=0D + if (CompareGuid (&(Hob.MemoryAllocationModule->MemoryAllocationHeade= r.Name), &gEfiHobMemoryAllocModuleGuid)) {=0D + continue;=0D + } else if (IsZeroGuid (&(Hob.MemoryAllocationModule->MemoryAllocatio= nHeader.Name)) =3D=3D FALSE) {=0D + AllocMemName =3D &(Hob.MemoryAllocationModule->MemoryAllocationHea= der.Name);=0D +=0D + if (CompareGuid (AllocMemName, &gEfiHobMemoryAllocStackGuid)) {=0D + IsStackHob =3D 1;=0D + } else if (CompareGuid (AllocMemName, &gEfiHobMemoryAllocBspStoreG= uid)) {=0D + IsBspStore =3D 1;=0D + }=0D + }=0D +=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "Found hob for rsvd memory alloc: base %016lX length %016lX type= %x\n",=0D + Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress,=0D + Hob.MemoryAllocation->AllocDescriptor.MemoryLength,=0D + Hob.MemoryAllocation->AllocDescriptor.MemoryType=0D + ));=0D +=0D + AllocMemType =3D Hob.MemoryAllocation->AllocDescriptor.MemoryType;=0D + if (IsStackHob =3D=3D 1) {=0D + Status =3D AsciiSPrint (=0D + TempStr,=0D + sizeof (TempStr),=0D + "%a@%lX",=0D + "stackhob",=0D + Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress= =0D + );=0D + } else if (IsBspStore =3D=3D 1) {=0D + Status =3D AsciiSPrint (=0D + TempStr,=0D + sizeof (TempStr),=0D + "%a@%lX",=0D + "bspstore",=0D + Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress= =0D + );=0D + } else {=0D + Status =3D AsciiSPrint (=0D + TempStr,=0D + sizeof (TempStr),=0D + "%a@%lX",=0D + mMemoryAllocType[AllocMemType],=0D + Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress= =0D + );=0D + }=0D +=0D + if (AsciiStrCmp (mMemoryAllocType[AllocMemType], "ConventionalMemory= ") =3D=3D 0) {=0D + continue;=0D + }=0D +=0D + if (AsciiStrCmp (mMemoryAllocType[AllocMemType], "acpi") =3D=3D 0) {= =0D + GuidHob =3D GetFirstGuidHob (&gUniversalPayloadAcpiTableGuid);=0D + if (GuidHob !=3D NULL) {=0D + AcpiTable =3D (UNIVERSAL_PAYLOAD_ACPI_TABLE *)GET_GUID_HOB_DATA = (GuidHob);=0D + RegTmp[0] =3D CpuToFdt64 ((UINTN)AcpiTable->Rsdp);=0D + RegTmp[1] =3D CpuToFdt64 (Hob.MemoryAllocation->AllocDescriptor.= MemoryBaseAddress);=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "To build acpi memory FDT , Rsdp :%x, MemoryBa= seAddress :%x\n", RegTmp[0], RegTmp[1]));=0D + if (RegTmp[0] !=3D RegTmp[1]) {=0D + DEBUG ((DEBUG_INFO, "Not Match , skip \n"));=0D + continue;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "To build acpi memory FDT \n"));=0D + }=0D +=0D + if (AsciiStrCmp (mMemoryAllocType[AllocMemType], "mmio") =3D=3D 0) {= =0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "mmio@%lX", Hob= .MemoryAllocation->AllocDescriptor.MemoryBaseAddress);=0D + } else {=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "memory@%lX", H= ob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress);=0D + }=0D +=0D + TempNode =3D FdtAddSubnode (Fdt, ParentNode, TempStr);=0D + DEBUG ((DEBUG_INFO, "FdtAddSubnode %x", TempNode));=0D + if (TempNode < 0) {=0D + continue;=0D + }=0D +=0D + RegTmp[0] =3D CpuToFdt64 (Hob.MemoryAllocation->AllocDescriptor.Memo= ryBaseAddress);=0D + RegTmp[1] =3D CpuToFdt64 (Hob.MemoryAllocation->AllocDescriptor.Memo= ryLength);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegTmp, sizeof (Reg= Tmp));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + // if (!(AsciiStrCmp (mMemoryAllocType[AllocMemType], "mmio") =3D=3D= 0)) {=0D + // Status =3D FdtSetProp (Fdt, TempNode, "compatible", mMemoryAlloc= Type[AllocMemType], (UINT32)(AsciiStrLen (mMemoryAllocType[AllocMemType])+1= ));=0D + // ASSERT_EFI_ERROR (Status);=0D + // }=0D +=0D + if (AllocMemName !=3D NULL) {=0D + AllocMemName->Data1 =3D CpuToFdt32 (AllocMemName->Data1);=0D + AllocMemName->Data2 =3D CpuToFdt16 (AllocMemName->Data2);=0D + AllocMemName->Data3 =3D CpuToFdt16 (AllocMemName->Data3);=0D + Status =3D FdtSetProp (Fdt, TempNode, "guid", AllocMe= mName, sizeof (EFI_GUID));=0D + }=0D + }=0D + }=0D +=0D + // SmbiosTable =3D NULL;=0D + // SmbiosTable =3D (UNIVERSAL_PAYLOAD_SMBIOS_TABLE *)GetFirstGuidHob (&g= UniversalPayloadSmbios3TableGuid);=0D + // if (SmbiosTable !=3D NULL) {=0D + // DEBUG ((DEBUG_INFO, "To build Smbios memory FDT\n"));=0D + // Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "memory@%lX", S= mbiosTable->SmBiosEntryPoint);=0D + // TempNode =3D FdtAddSubnode (Fdt, ParentNode, TempStr);=0D + // DEBUG ((DEBUG_INFO, "FdtAddSubnode %x", TempNode));=0D + // RegTmp[0] =3D CpuToFdt64 (SmbiosTable->SmBiosEntryPoint);=0D + // RegTmp[1] =3D CpuToFdt64 (sizeof (UNIVERSAL_PAYLOAD_SMBIOS_TABLE) + = sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT));=0D + // Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegTmp, sizeof (Reg= Tmp));=0D + // ASSERT_EFI_ERROR (Status);=0D +=0D + // Status =3D FdtSetProp (Fdt, TempNode, "compatible", "smbios", (UINT3= 2)(AsciiStrLen ("smbios")+1));=0D + // ASSERT_EFI_ERROR (Status);=0D + // }=0D + return Status;=0D +}=0D +=0D +/**=0D + It will build FDT based on serial information.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForSerial (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D + VOID *Fdt;=0D + INT32 TempNode;=0D + UINT64 RegisterBase;=0D + CHAR8 TempStr[32];=0D + UINT64 RegData[3];=0D + UINT32 Data32;=0D +=0D + Fdt =3D FdtBase;=0D + RegisterBase =3D 0;=0D +=0D + //=0D + // Create SerialPortInfo FDT node.=0D + //=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "serial@%lX", (Regi= sterBase =3D=3D 0) ? PcdGet64 (PcdSerialRegisterBase) : RegisterBase);=0D + TempNode =3D FdtAddSubnode (Fdt, 0, TempStr);=0D + ASSERT (TempNode > 0);=0D +=0D + Data32 =3D CpuToFdt32 (PcdGet32 (PcdSerialBaudRate));=0D + Status =3D FdtSetProp (Fdt, TempNode, "current-speed", &Data32, sizeof (= Data32));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + // Data32 =3D CpuToFdt32 (PcdGet32 (PcdSerialRegisterStride));=0D + // Status =3D FdtSetProp (Fdt, TempNode, "reg-shift", &Data32, sizeof (D= ata32));=0D + // ASSERT_EFI_ERROR (Status);=0D +=0D + // Data32 =3D CpuToFdt32 (8);=0D + // Status =3D FdtSetProp (Fdt, TempNode, "reg-width", &Data32, sizeof (= Data32));=0D + // ASSERT_EFI_ERROR (Status);=0D +=0D + if (PcdGetBool (PcdSerialUseMmio)) {=0D + RegData[0] =3D CpuToFdt64 (0);=0D + RegData[1] =3D CpuToFdt64 ((RegisterBase =3D=3D 0) ? PcdGet64 (PcdSeri= alRegisterBase) : RegisterBase);=0D + RegData[2] =3D CpuToFdt64 (0x80);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegData, sizeof (Reg= Data));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (4);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg-io-width", &Data32, sizeof = (Data32));=0D + ASSERT_EFI_ERROR (Status);=0D + } else {=0D + RegData[0] =3D CpuToFdt64 (1);=0D + RegData[1] =3D CpuToFdt64 ((RegisterBase =3D=3D 0) ? PcdGet64 (PcdSeri= alRegisterBase) : RegisterBase);=0D + RegData[2] =3D CpuToFdt64 (8);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegData, sizeof (Reg= Data));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (1);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg-io-width", &Data32, sizeof = (Data32));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "compatible", "isa", (UINT32)(Asci= iStrLen ("isa")+1));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + It will build FDT based on BuildFdtForPciRootBridge information.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForPciRootBridge (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D + VOID *Fdt;=0D + INT32 TempNode;=0D + CHAR8 TempStr[32];=0D + UINT16 RegTmp[2];=0D + UINT32 RegData[21];=0D + UINT32 DMARegData[8];=0D + UINT32 Data32;=0D + UINT64 Data64;=0D + UINT8 BusNumber;=0D + UINT8 BusLimit;=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;=0D + UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *PciRootBridgeInfo;=0D + UINT8 Index;=0D +=0D + Fdt =3D FdtBase;=0D + BusNumber =3D 0;=0D + BusLimit =3D 0;=0D + Status =3D EFI_SUCCESS;=0D + PciRootBridgeInfo =3D NULL;=0D +=0D + DEBUG ((DEBUG_INFO, "%a: #1 \n", __func__));=0D + //=0D + // Create BuildFdtForPciRootBridge FDT node.=0D + //=0D +=0D + GuidHob =3D GetFirstGuidHob (&gUniversalPayloadPciRootBridgeInfoGuid);=0D + if (GuidHob !=3D NULL) {=0D + GenericHeader =3D (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DAT= A (GuidHob);=0D + if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) <=3D GET_GUID_HOB_DATA_= SIZE (GuidHob)) && (GenericHeader->Length <=3D GET_GUID_HOB_DATA_SIZE (Guid= Hob))) {=0D + if ((GenericHeader->Revision =3D=3D UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDG= ES_REVISION) && (GenericHeader->Length >=3D sizeof (UNIVERSAL_PAYLOAD_PCI_R= OOT_BRIDGES))) {=0D + DEBUG ((DEBUG_INFO, "%a: #2 \n", __func__));=0D +=0D + //=0D + // UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES structure is used when Revis= ion equals to UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES_REVISION=0D + //=0D + PciRootBridgeInfo =3D (UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *)GET_GU= ID_HOB_DATA (GuidHob);=0D + }=0D + }=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridgeInfo->Count %x\n", PciRootBridgeInfo->= Count));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Segment %x, \n", PciRootBridgeInfo->= RootBridge[0].Segment));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Bus.Base %x, \n", PciRootBridgeInfo-= >RootBridge[0].Bus.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Bus.limit %x, \n", PciRootBridgeInfo= ->RootBridge[0].Bus.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.Base %x, \n", PciRootBridgeInfo-= >RootBridge[0].Mem.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.limit %x, \n", PciRootBridgeInfo= ->RootBridge[0].Mem.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.Base %llx, \n", PciRootBr= idgeInfo->RootBridge[0].MemAbove4G.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.limit %llx, \n", PciRootB= ridgeInfo->RootBridge[0].MemAbove4G.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->PMem.Base %llx, \n", PciRootBridgeIn= fo->RootBridge[0].PMem.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->PMem.limit %llx, \n", PciRootBridgeI= nfo->RootBridge[0].PMem.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Bus.Base %x, \n", PciRootBridgeInfo-= >RootBridge[1].Bus.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Bus.limit %x, \n", PciRootBridgeInfo= ->RootBridge[1].Bus.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.Base %x, \n", PciRootBridgeInfo-= >RootBridge[1].Mem.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.limit %x, \n", PciRootBridgeInfo= ->RootBridge[1].Mem.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.Base %llx, \n", PciRootBr= idgeInfo->RootBridge[1].MemAbove4G.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.limit %llx, \n", PciRootB= ridgeInfo->RootBridge[1].MemAbove4G.Limit));=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->PMem.Base %x, \n", PciRootBridgeInfo= ->RootBridge[1].PMem.Base));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->PMem.limit %x, \n", PciRootBridgeInf= o->RootBridge[1].PMem.Limit));=0D +=0D + if (PciRootBridgeInfo !=3D NULL) {=0D + for (Index =3D 0; Index < PciRootBridgeInfo->Count; Index++) {=0D + UINTN PciExpressBaseAddress;=0D +=0D + PciExpressBaseAddress =3D PcdGet64 (PcdPciExpressBaseAddress) + (PCI= _LIB_ADDRESS (PciRootBridgeInfo->RootBridge[Index].Bus.Base, 0, 0, 0));=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "p= ci-rb%d@%lX", Index, PciExpressBaseAddress);=0D + TempNode =3D FdtAddSubnode (Fdt, 0, TempStr);=0D + ASSERT (TempNode > 0);=0D + SetMem (RegData, sizeof (RegData), 0);=0D +=0D + // non-reloc/non-prefetch/mmio, child-addr, parent-addr, length=0D + Data32 =3D (N_NON_RELOCATABLE + P_NON_PREFETCHABLE + SS_32BIT_ME= MORY_SPACE);=0D + RegData[0] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.Base RegData[0] %x, \n", Dat= a32));=0D +=0D + // child-addr=0D + RegData[1] =3D CpuToFdt32 (0);=0D + Data32 =3D (UINT32)PciRootBridgeInfo->RootBridge[Index].Mem.Base= ;=0D + RegData[2] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.Base RegData[2] %x, \n", Dat= a32));=0D +=0D + // parent-addr=0D + RegData[3] =3D CpuToFdt32 (0);=0D + RegData[4] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.Base RegData[4] %x, \n", Dat= a32));=0D +=0D + // size=0D + Data64 =3D (PciRootBridgeInfo->RootBridge[Index].Mem.Limit - PciRoot= BridgeInfo->RootBridge[Index].Mem.Base + 1);=0D + if (Data64 & 0xFFFFFFFF00000000) {=0D + Data32 =3D (UINT32)RShiftU64 ((Data64 & 0xFFFFFFFF00000000), 31);= =0D + } else {=0D + Data32 =3D 0;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.size RegData[5] %x, \n", Dat= a32));=0D + RegData[5] =3D CpuToFdt32 (Data32);=0D + Data32 =3D (UINT32)((Data64 & 0x0FFFFFFFF));=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Mem.size RegData[6] %x, \n", Dat= a32));=0D +=0D + RegData[6] =3D CpuToFdt32 (Data32);=0D +=0D + // non-reloc/non-prefetch/64 mmio, child-addr, parent-addr, length=0D + Data32 =3D (N_NON_RELOCATABLE + P_NON_PREFETCHABLE + SS_64BIT_ME= MORY_SPACE);=0D + RegData[7] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.Base RegData[7] %x, \= n", Data32));=0D +=0D + // child-addr=0D + Data64 =3D PciRootBridgeInfo->RootBridge[Index].MemAbove4G.Base;=0D + Data32 =3D (UINT32)RShiftU64 ((Data64 & 0xFFFFFFFF00000000), 32);=0D +=0D + RegData[8] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.Base RegData[8] %x, \= n", Data32));=0D + Data32 =3D (UINT32)((Data64 & 0x0FFFFFFFF));=0D + RegData[9] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.Base RegData[9] %x, \= n", Data32));=0D +=0D + // parent-addr=0D + RegData[10] =3D RegData[8];=0D + RegData[11] =3D RegData[9];=0D +=0D + // size=0D + Data64 =3D (PciRootBridgeInfo->RootBridge[Index].MemAbove4G.Limit - = PciRootBridgeInfo->RootBridge[Index].MemAbove4G.Base + 1);=0D + if (Data64 & 0xFFFFFFFF00000000) {=0D + Data32 =3D (UINT32)RShiftU64 ((Data64 & 0xFFFFFFFF00000000), 32);= =0D + } else {=0D + Data32 =3D 0;=0D + }=0D +=0D + RegData[12] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.size RegData[12] %x, = \n", Data32));=0D +=0D + Data32 =3D (UINT32)((Data64 & 0x0FFFFFFFF));=0D + RegData[13] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->MemAbove4G.size RegData[13] %x, = \n", Data32));=0D +=0D + // non-reloc/32bit/io, child-addr, parent-addr, length=0D + Data32 =3D (N_NON_RELOCATABLE + SS_IO_SPACE);=0D +=0D + RegData[14] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Io.base RegData[14] %x, \n", Dat= a32));=0D +=0D + Data32 =3D (UINT32)PciRootBridgeInfo->RootBridge[Index].Io.Base;=0D + // child-addr=0D + RegData[15] =3D CpuToFdt32 (0);=0D + RegData[16] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Io.base RegData[16] %x, \n", Dat= a32));=0D +=0D + // parent-addr=0D + RegData[17] =3D CpuToFdt32 (0);=0D + RegData[18] =3D CpuToFdt32 (Data32);=0D + // size=0D + Data64 =3D (PciRootBridgeInfo->RootBridge[Index].Io.Limit - PciRootB= ridgeInfo->RootBridge[Index].Io.Base + 1);=0D + if (Data64 & 0xFFFFFFFF00000000) {=0D + Data32 =3D (UINT32)RShiftU64 ((Data64 & 0xFFFFFFFF00000000), 32);= =0D + } else {=0D + Data32 =3D 0;=0D + }=0D +=0D + RegData[19] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Io.base size [19] %x, \n", Data3= 2));=0D +=0D + Data32 =3D (UINT32)((Data64 & 0x0FFFFFFFF));=0D + RegData[20] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->Io.base size [20] %x, \n", Data3= 2));=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "ranges", &RegData, sizeof (Re= gData));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + // non-reloc/non-prefetch/memory, child-addr, parent-addr, length=0D + // indicate rb1 does not support above 4GB DMA=0D + Data32 =3D (N_NON_RELOCATABLE + P_NON_PREFETCHABLE + SS_32BIT_MEMORY= _SPACE);=0D +=0D + DMARegData[0] =3D CpuToFdt32 (Data32);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->DMA base RegData[0] %x, \n", Da= ta32));=0D +=0D + // child-addr=0D + DMARegData[2] =3D CpuToFdt32 (0);=0D + DMARegData[3] =3D CpuToFdt32 (0);=0D + // parent-addr=0D + DMARegData[4] =3D CpuToFdt32 (0);=0D + DMARegData[5] =3D CpuToFdt32 (0);=0D + // size=0D + DMARegData[6] =3D CpuToFdt32 (1);=0D + DMARegData[7] =3D CpuToFdt32 (0);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "dma-ranges", &DMARegData, siz= eof (DMARegData));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (2);=0D + Status =3D FdtSetProp (Fdt, TempNode, "#size-cells", &Data32, sizeof= (UINT32));=0D +=0D + Data32 =3D CpuToFdt32 (3);=0D + Status =3D FdtSetProp (Fdt, TempNode, "#address-cells", &Data32, siz= eof (UINT32));=0D +=0D + BusNumber =3D PciRootBridgeInfo->RootBridge[Index].Bus.Base & 0xFF;= =0D + RegTmp[0] =3D CpuToFdt16 (BusNumber);=0D + BusLimit =3D PciRootBridgeInfo->RootBridge[Index].Bus.Limit & 0xFF;= =0D + RegTmp[1] =3D CpuToFdt16 (BusLimit);=0D + DEBUG ((DEBUG_INFO, "PciRootBridge->BusNumber %x, \n", BusNumber));= =0D + DEBUG ((DEBUG_INFO, "PciRootBridge->BusLimit %x, \n", BusLimit));=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "bus-range", &RegTmp, sizeof (= RegTmp));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "compatible", "pci", (UINT32)(= AsciiStrLen ("pci")+1));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: #3 \n", __func__));=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + It will build FDT based on FrameBuffer.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForFrameBuffer (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D + VOID *Fdt;=0D + INT32 TempNode;=0D + UINT32 Data32;=0D + CHAR8 TempStr[32];=0D + UINT64 RegData[2];=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + EFI_PEI_GRAPHICS_INFO_HOB *GraphicsInfo;=0D +=0D + Fdt =3D FdtBase;=0D +=0D + GuidHob =3D GetFirstGuidHob (&gEfiGraphicsInfoHobGuid);=0D + if (GuidHob !=3D NULL) {=0D + GraphicsInfo =3D (EFI_PEI_GRAPHICS_INFO_HOB *)(GET_GUID_HOB_DATA (Guid= Hob));=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "framebuffer@= %lX", GraphicsInfo->FrameBufferBase);=0D + TempNode =3D FdtAddSubnode (Fdt, 0, TempStr);=0D + ASSERT (TempNode > 0);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "format", "a8r8g8b8", (UINT32)(A= sciiStrLen ("a8r8g8b8")+1));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (GraphicsInfo->GraphicsMode.VerticalResolution);= =0D + Status =3D FdtSetProp (Fdt, TempNode, "height", &Data32, sizeof (UINT3= 2));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (GraphicsInfo->GraphicsMode.HorizontalResolution= );=0D + Status =3D FdtSetProp (Fdt, TempNode, "width", &Data32, sizeof (UINT32= ));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + RegData[0] =3D CpuToFdt64 (GraphicsInfo->FrameBufferBase);=0D + RegData[1] =3D CpuToFdt64 (GraphicsInfo->FrameBufferSize);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegData, sizeof (Reg= Data));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "compatible", "simple-framebuffe= r", (UINT32)(AsciiStrLen ("simple-framebuffer")+1));=0D + ASSERT_EFI_ERROR (Status);=0D + } else {=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "framebuffer@%lX"= , 0xB0000000);=0D + TempNode =3D FdtAddSubnode (Fdt, 0, TempStr);=0D + ASSERT (TempNode > 0);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "format", "a8r8g8b8", (UINT32)(A= sciiStrLen ("a8r8g8b8")+1));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (1024);=0D + Status =3D FdtSetProp (Fdt, TempNode, "height", &Data32, sizeof (UINT3= 2));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Data32 =3D CpuToFdt32 (1280);=0D + Status =3D FdtSetProp (Fdt, TempNode, "width", &Data32, sizeof (UINT32= ));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + RegData[0] =3D CpuToFdt64 (0xB0000000);=0D + RegData[1] =3D CpuToFdt64 (0x500000);=0D + Status =3D FdtSetProp (Fdt, TempNode, "reg", &RegData, sizeof (Reg= Data));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D FdtSetProp (Fdt, TempNode, "compatible", "simple-framebuffe= r", (UINT32)(AsciiStrLen ("simple-framebuffer")+1));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + It will build FDT for UPL required data.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForUplRequired (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D + VOID *Fdt;=0D + VOID *Fit;=0D + INT32 ParentNode;=0D + INT32 CustomNode;=0D + INT32 UPLParaNode;=0D + INT32 UPLImageNode;=0D + EFI_HOB_CPU *CpuHob;=0D + UINT64 Data64;=0D + UINT32 Data32;=0D + UINT16 Data16;=0D + VOID *HobPtr;=0D + EFI_BOOT_MODE BootMode;=0D + CHAR8 TempStr[32];=0D + UINT8 *GuidHob;=0D + UNIVERSAL_PAYLOAD_BASE *PayloadBase;=0D +=0D + Fdt =3D FdtBase;=0D + Fit =3D NULL;=0D +=0D + //=0D + // Create Hob list FDT node.=0D + //=0D + ParentNode =3D FdtAddSubnode (Fdt, 0, "options");=0D + ASSERT (ParentNode > 0);=0D +=0D + UPLParaNode =3D FdtAddSubnode (Fdt, ParentNode, "upl-params");=0D + ASSERT (UPLParaNode > 0);=0D +=0D + //=0D + // Create CPU info FDT node=0D + //=0D + CpuHob =3D GetFirstHob (EFI_HOB_TYPE_CPU);=0D + ASSERT (CpuHob !=3D NULL);=0D +=0D + Data16 =3D CpuToFdt16 (0);=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "pci-enum-done", &Data16, sizeo= f (Data16)/ sizeof (UINT16));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + BootMode =3D GetBootModeHob ();=0D +=0D + Data32 =3D CpuToFdt32 ((UINT32)CpuHob->SizeOfMemorySpace);=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "addr-width", &Data32, sizeof (= Data32));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + if (BootMode =3D=3D BOOT_WITH_FULL_CONFIGURATION) {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "normal", (UINT3= 2)(AsciiStrLen ("normal")+1));=0D + } else if (BootMode =3D=3D BOOT_WITH_MINIMAL_CONFIGURATION) {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "fast", (UINT32)= (AsciiStrLen ("fast")+1));=0D + } else if (BootMode =3D=3D BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS= ) {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "full", (UINT32)= (AsciiStrLen ("full")+1));=0D + } else if (BootMode =3D=3D BOOT_WITH_DEFAULT_SETTINGS) {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "default", (UINT= 32)(AsciiStrLen ("default")+1));=0D + } else if (BootMode =3D=3D BOOT_ON_S4_RESUME) {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "s4", (UINT32)(A= sciiStrLen ("s4")+1));=0D + } else if (BootMode =3D=3D BOOT_ON_S3_RESUME) {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "s3", (UINT32)(A= sciiStrLen ("s3")+1));=0D + } else {=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "boot-mode", "na", (UINT32)(A= sciiStrLen ("na")+1));=0D + }=0D +=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D FdtSetProp (Fdt, UPLParaNode, "compatible", "upl", (UINT32)(A= sciiStrLen ("upl")+1));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + GuidHob =3D GetFirstGuidHob (&gUniversalPayloadBaseGuid);=0D + if (GuidHob !=3D NULL) {=0D + PayloadBase =3D (UNIVERSAL_PAYLOAD_BASE *)GET_GUID_HOB_DATA (GuidHob);= =0D + Fit =3D (VOID *)(UINTN)PayloadBase->Entry;=0D + DEBUG ((DEBUG_INFO, "PayloadBase Entry =3D 0x%08x\n", PayloadBase->Ent= ry));=0D +=0D + Status =3D AsciiSPrint (TempStr, sizeof (TempStr), "upl-images@%= lX", (UINTN)(Fit));=0D + UPLImageNode =3D FdtAddSubnode (Fdt, ParentNode, TempStr);=0D +=0D + Data64 =3D CpuToFdt64 ((UINTN)Fit);=0D + Status =3D FdtSetProp (FdtBase, UPLImageNode, "addr", &Data64, sizeof = (Data64));=0D + }=0D +=0D + CustomNode =3D FdtAddSubnode (Fdt, ParentNode, "upl-custom");=0D + ASSERT (CustomNode > 0);=0D +=0D + HobPtr =3D GetHobList ();=0D + Data64 =3D CpuToFdt64 ((UINT64)(EFI_PHYSICAL_ADDRESS)HobPtr);=0D + Status =3D FdtSetProp (Fdt, CustomNode, "hoblistptr", &Data64, sizeof (D= ata64));=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + It will build FDT for UPL consumed.=0D + @param[in] FdtBase Address of the Fdt data.=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval Others If it failed to build required FDT.=0D +**/=0D +EFI_STATUS=0D +BuildFdtForUPL (=0D + IN VOID *FdtBase=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + //=0D + // Build FDT for memory related=0D + //=0D + Status =3D BuildFdtForMemory (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + // Status =3D BuildFdtForReservedMemory (FdtBase);=0D + // ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D BuildFdtForMemAlloc (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D BuildFdtForSerial (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D BuildFdtForPciRootBridge (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D BuildFdtForFrameBuffer (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D BuildFdtForUplRequired (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return Status;=0D +}=0D +=0D +#if (FixedPcdGetBool (PcdHandOffFdtEnable))=0D +=0D +/**=0D + Discover Hobs data and report data into a FDT.=0D + @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES= table published by the PEI Foundation.=0D + @param[in] NotifyDescriptor Address of the notification descriptor data= structure.=0D + @param[in] Ppi Address of the PPI that was installed.=0D + @retval EFI_SUCCESS Hobs data is discovered.=0D + @return Others No Hobs data is discovered.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +FdtPpiNotifyCallback (=0D + IN EFI_PEI_SERVICES **PeiServices,=0D + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,=0D + IN VOID *Ppi=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UNIVERSAL_PAYLOAD_DEVICE_TREE *Fdt;=0D + UINT32 FdtSize;=0D + UINTN FdtPages;=0D + VOID *FdtBase;=0D + UINT32 Data32;=0D +=0D + Fdt =3D NULL;=0D + FdtSize =3D 4 * EFI_PAGE_SIZE;=0D + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize);=0D + FdtBase =3D AllocatePages (FdtPages);=0D + if (FdtBase =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a: AllocatePages failed\n", __func__));=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + Status =3D FdtCreateEmptyTree (FdtBase, (UINT32)FdtSize);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: cannot create FDT\n", __func__));=0D + }=0D +=0D + // Set cell property of root node=0D + Data32 =3D CpuToFdt32 (2);=0D + Status =3D FdtSetProp (FdtBase, 0, "#address-cells", &Data32, sizeof (UI= NT32));=0D + Status =3D FdtSetProp (FdtBase, 0, "#size-cells", &Data32, sizeof (UINT3= 2));=0D +=0D + Status =3D BuildFdtForUPL (FdtBase);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + PrintFdt (FdtBase);=0D +=0D + Fdt =3D BuildGuidHob (&gUniversalPayloadDeviceTreeGuid, sizeof (UNIVERSA= L_PAYLOAD_DEVICE_TREE));=0D + if (Fdt =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a: Build FDT Hob failed\n", __func__));=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "%a: fdt at 0x%x (size %d)\n",=0D + __func__,=0D + FdtBase,=0D + Fdt32ToCpu (((FDT_HEADER *)FdtBase)->TotalSize)=0D + ));=0D +=0D + Fdt->Header.Revision =3D UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION;=0D + Fdt->Header.Length =3D sizeof (UNIVERSAL_PAYLOAD_DEVICE_TREE);=0D + Fdt->DeviceTreeAddress =3D (UINT64)FdtBase;=0D +=0D + return Status;=0D +}=0D +=0D +#endif=0D +=0D /**=0D Install Pei Load File PPI.=0D @param FileHandle Handle of the file being invoked.=0D @@ -146,5 +1110,13 @@ InitializeFitPayloadLoaderPeim ( =0D Status =3D PeiServicesInstallPpi (&gPpiLoadFilePpiList);=0D =0D + #if (FixedPcdGetBool (PcdHandOffFdtEnable))=0D +=0D + //=0D + // Build FDT in end of PEI notify callback.=0D + //=0D + Status =3D PeiServicesNotifyPpi (&mReadyToPayloadNotifyList[0]);=0D + ASSERT_EFI_ERROR (Status);=0D + #endif=0D return Status;=0D }=0D diff --git a/UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c b/UefiPay= loadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c index 9f9d3c13e13d..fe7aa2682f4d 100644 --- a/UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c +++ b/UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c @@ -17,9 +17,49 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D -=0D +#include =0D #include "ElfLib.h"=0D =0D +CONST EFI_PEI_PPI_DESCRIPTOR gReadyToPayloadSignalPpi =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gUplReadyToPayloadPpiGuid,=0D + NULL=0D +};=0D +=0D +/**=0D + Notify ReadyToPayLoad signal.=0D + @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES= table published by the PEI Foundation.=0D + @param[in] NotifyDescriptor Address of the notification descriptor data= structure.=0D + @param[in] Ppi Address of the PPI that was installed.=0D + @retval EFI_SUCCESS Hobs data is discovered.=0D + @return Others No Hobs data is discovered.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +EndOfPeiPpiNotifyCallback (=0D + IN EFI_PEI_SERVICES **PeiServices,=0D + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,=0D + IN VOID *Ppi=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + //=0D + // Ready to Payload phase signal=0D + //=0D + Status =3D PeiServicesInstallPpi (&gReadyToPayloadSignalPpi);=0D +=0D + return Status;=0D +}=0D +=0D +EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiNotifyList[] =3D {=0D + {=0D + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMI= NATE_LIST),=0D + &gEfiEndOfPeiSignalPpiGuid,=0D + EndOfPeiPpiNotifyCallback=0D + }=0D +};=0D +=0D /**=0D The wrapper function of PeiLoadImageLoadImage().=0D =0D @@ -47,6 +87,7 @@ PeiLoadFileLoadPayload ( EFI_STATUS Status;=0D VOID *Elf;=0D UNIVERSAL_PAYLOAD_EXTRA_DATA *ExtraData;=0D + UNIVERSAL_PAYLOAD_BASE *PayloadBase;=0D ELF_IMAGE_CONTEXT Context;=0D UINT32 Index;=0D UINT16 ExtraDataIndex;=0D @@ -73,13 +114,22 @@ PeiLoadFileLoadPayload ( Status =3D ParseElfImage (Elf, &Context);=0D } while (EFI_ERROR (Status));=0D =0D - DEBUG ((=0D - DEBUG_INFO,=0D - "Payload File Size: 0x%08X, Mem Size: 0x%08x, Reload: %d\n",=0D - Context.FileSize,=0D - Context.ImageSize,=0D - Context.ReloadRequired=0D - ));=0D + Length =3D sizeof (UNIVERSAL_PAYLOAD_BASE);=0D + PayloadBase =3D BuildGuidHob (=0D + &gUniversalPayloadBaseGuid,=0D + Length=0D + );=0D + PayloadBase->Entry =3D (EFI_PHYSICAL_ADDRESS)Context.FileBase;=0D +=0D + DEBUG (=0D + (=0D + DEBUG_INFO,=0D + "Payload File Size: 0x%08X, Mem Size: 0x%08x, Reload: %d\n",=0D + Context.FileSize,=0D + Context.ImageSize,=0D + Context.ReloadRequired=0D + )=0D + );=0D =0D //=0D // Get UNIVERSAL_PAYLOAD_INFO_HEADER and number of additional PLD sectio= ns.=0D @@ -153,6 +203,11 @@ PeiLoadFileLoadPayload ( *ImageSizeArg =3D Context.ImageSize;=0D }=0D =0D + DEBUG ((DEBUG_INFO, "LoadElfImage :%r, EntryPoint :%x\n", Status, (UINTN= )Context.EntryPoint));=0D +=0D + Status =3D PeiServicesNotifyPpi (&mEndOfPeiNotifyList[0]);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D return Status;=0D }=0D =0D diff --git a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf b/Ue= fiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf index cd0cb186e138..c860c3da8dee 100644 --- a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf +++ b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf @@ -35,7 +35,6 @@ =0D [LibraryClasses]=0D PcdLib=0D - MemoryAllocationLib=0D BaseMemoryLib=0D PeiServicesLib=0D HobLib=0D @@ -46,14 +45,27 @@ =0D [Ppis]=0D gEfiPeiLoadFilePpiGuid ## PRODUCES=0D + gUplReadyToPayloadPpiGuid ## PRODUCES=0D + gEfiEndOfPeiSignalPpiGuid ## CONSUMES=0D =0D [Pcd]=0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister=0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister=0D + gUefiPayloadPkgTokenSpaceGuid.PcdHandOffFdtEnable=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio=0D + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress=0D + gEfiMdePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion=0D =0D [Guids]=0D - gUniversalPayloadExtraDataGuid ## PRODUCES=0D gUniversalPayloadBaseGuid ## PRODUCES=0D + gUniversalPayloadDeviceTreeGuid ## CONSUMES=0D + gEfiGraphicsInfoHobGuid ## CONSUMES=0D + gUniversalPayloadPciRootBridgeInfoGuid ## CONSUMES=0D + gUniversalPayloadAcpiTableGuid ## CONSUMES=0D =0D [Depex]=0D TRUE=0D diff --git a/UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf b/UefiP= ayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf index 06e83dbadce0..8db026eaa1b8 100644 --- a/UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf +++ b/UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf @@ -52,6 +52,8 @@ =0D [Ppis]=0D gEfiPeiLoadFilePpiGuid ## PRODUCES=0D + gEfiEndOfPeiSignalPpiGuid ## CONSUMES=0D + gUplReadyToPayloadPpiGuid ## PRODUCES=0D =0D [Pcd]=0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister=0D @@ -59,6 +61,16 @@ =0D [Guids]=0D gUniversalPayloadExtraDataGuid ## PRODUCES=0D + gUniversalPayloadBaseGuid ## PRODUCES=0D =0D [Depex]=0D TRUE=0D +=0D +[BuildOptions]=0D + MSFT:*_*_*_CC_FLAGS =3D /wd4244=0D + GCC:*_*_IA32_CC_FLAGS =3D -Wno-error=3Dpointer-to-int-cast -Wno-error= =3Dint-to-pointer-cast=0D + GCC:*_*_X64_CC_FLAGS =3D -Wno-error=3Dpointer-to-int-cast -Wno-error= =3Dint-to-pointer-cast=0D + GCC:*_*_ARM_CC_FLAGS =3D -Wno-error=3Dpointer-to-int-cast -Wno-error= =3Dint-to-pointer-cast=0D + GCC:*_*_AARCH64_CC_FLAGS =3D -Wno-error=3Dpointer-to-int-cast -Wno-error= =3Dint-to-pointer-cast=0D + GCC:*_*_RISCV64_CC_FLAGS =3D -Wno-error=3Dpointer-to-int-cast -Wno-error= =3Dint-to-pointer-cast=0D + GCC:*_*_LOONGARCH64_CC_FLAGS =3D -Wno-error=3Dpointer-to-int-cast -Wno-e= rror=3Dint-to-pointer-cast=0D --=20 2.39.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119175): https://edk2.groups.io/g/devel/message/119175 Mute This Topic: https://groups.io/mt/106274772/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-