From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 0EB0D7803CC for ; Mon, 11 Mar 2024 09:39:43 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=RZp6BYa+hpQpdcJrF8R3yKgeVWJk4WOkvsWn8drY3TQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1710149982; v=1; b=n4//bBXT0unsRWSKl0fviR+18+isJFhOd09lESQpkhedJi/fa3eDcVyefSHV6k93YQ8tqWB/ WIm+KsZPDju9ud7vuzPe0qN0dU3D+N65Jd0gvUf8ULaEH8mcswmcR2gdqkT+K9eCs89j2Q7d3iP IR1dnOybasu/nZ0KnzCYWJpTIQINfNufmI0aXdq0OD9AcLkYgsh4PhiA+CRKrdP0CVCOw/U4ijB Y1tasqa3vs+bDyZoco9mBxPbe5YNzhloiwebUPpaW6YRn+zqacbcYzC3Fce5oMh79To14Vqj9p2 65SMCsTwCZvuqgPLHs4cvEYuaGEdxnRPut0QyTLb2tyVQ== X-Received: by 127.0.0.2 with SMTP id hZijYY7687511x2DkdQIXSLu; Mon, 11 Mar 2024 02:39:42 -0700 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.58780.1710149981632208132 for ; Mon, 11 Mar 2024 02:39:42 -0700 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8BxefBb0e5lHhsXAA--.57945S3; Mon, 11 Mar 2024 17:39:39 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxdMxa0e5lLCVWAA--.46811S2; Mon, 11 Mar 2024 17:39:38 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Bibo Mao , Dongyan Qian , Xianglai Li Subject: [edk2-devel] [PATCH v1 24/26] OvmfPkg/LoongArchVirt: Support PEI phase Date: Mon, 11 Mar 2024 02:39:42 -0700 Message-Id: <20240311093937.1254802-1-lichao@loongson.cn> In-Reply-To: <20240311093631.1251466-1-lichao@loongson.cn> References: <20240311093631.1251466-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxdMxa0e5lLCVWAA--.46811S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQANCGXuwOYBAQABso X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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 Reply-To: devel@edk2.groups.io,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: t3fv9VcBOrluhukO9wj95u7xx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b="n4//bBXT"; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Platfrom PEI module for LoongArch platfrom initialization. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Bibo Mao Cc: Dongyan Qian Signed-off-by: Chao Li Co-authored-by: Xianglai Li Co-authored-by: Bibo Mao Reviewed-by: Bibo Mao --- OvmfPkg/LoongArchVirt/PlatformPei/Fv.c | 39 ++ OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c | 202 +++++++++ OvmfPkg/LoongArchVirt/PlatformPei/Platform.c | 393 ++++++++++++++++++ OvmfPkg/LoongArchVirt/PlatformPei/Platform.h | 128 ++++++ .../LoongArchVirt/PlatformPei/PlatformPei.inf | 72 ++++ 5 files changed, 834 insertions(+) create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Fv.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Platform.c create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/Platform.h create mode 100644 OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c b/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c new file mode 100644 index 0000000000..d46326f135 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Fv.c @@ -0,0 +1,39 @@ +/** @file + Build FV related hobs for platform. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "Platform.h" + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n")); + + // + // Create a memory allocation HOB for the PEI FV. + // + BuildMemoryAllocationHob ( + FixedPcdGet64 (PcdOvmfSecPeiTempRamBase), + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize), + EfiBootServicesData + ); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c b/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c new file mode 100644 index 0000000000..61f61ee099 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/MemDetect.c @@ -0,0 +1,202 @@ +/** @file + Memory Detection for Virtual Machines. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +// The package level header files this module uses +// +#include + +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Platform.h" + +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS (128) +#define LOONGARCH_FW_RAM_TOP BASE_256MB + +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 Base; + UINT64 Size; + UINT64 RamTop; + + // + // Determine the range of memory to use during PEI + // + Base = FixedPcdGet64 (PcdOvmfSecPeiTempRamBase) + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize); + RamTop = LOONGARCH_FW_RAM_TOP; + Size = RamTop - Base; + + // + // Publish this memory to the PEI Core + // + Status = PublishSystemMemory (Base, Size); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Publish Memory Initialize done.\n")); + return Status; +} + +/** + Peform Memory Detection + Publish system RAM and reserve memory regions +**/ +VOID +InitializeRamRegions ( + VOID + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + MEMMAP_ENTRY MemoryMapEntry; + MEMMAP_ENTRY *StartEntry; + MEMMAP_ENTRY *pEntry; + UINTN Processed; + + Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __func__, __LINE__, Status)); + return; + } + + if (FwCfgSize % sizeof MemoryMapEntry != 0) { + DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize)); + return; + } + + QemuFwCfgSelectItem (FwCfgItem); + StartEntry = AllocatePages (EFI_SIZE_TO_PAGES (FwCfgSize)); + QemuFwCfgReadBytes (FwCfgSize, StartEntry); + for (Processed = 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); Processed++) { + pEntry = StartEntry + Processed; + if (pEntry->Length == 0) { + continue; + } + + DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p type %d\n", pEntry->BaseAddr, pEntry->Length, pEntry->Type)); + if (pEntry->Type != EfiAcpiAddressRangeMemory) { + continue; + } + + AddMemoryRangeHob (pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Length); + } + + // + // When 0 address protection is enabled, + // 0-4k memory needs to be preallocated to prevent UEFI applications from allocating use, + // such as grub + // + if (PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) { + BuildMemoryAllocationHob ( + 0, + EFI_PAGE_SIZE, + EfiBootServicesData + ); + } +} + +/** + Gets the Virtual Memory Map of corresponding platforms. + + This Virtual Memory Map is used by initialize the MMU on corresponding + platforms. + + @param[out] MemoryTable Array of EFI_MEMORY_DESCRIPTOR + describing a Physical-to-Virtual Memory + mapping. This array must be ended by a + zero-filled entry. The allocated memory + will not be freed. +**/ +VOID +EFIAPI +GetMemoryMapPolicy ( + OUT EFI_MEMORY_DESCRIPTOR **MemoryTable + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + MEMMAP_ENTRY MemoryMapEntry; + MEMMAP_ENTRY *StartEntry; + MEMMAP_ENTRY *pEntry; + UINTN Processed; + EFI_MEMORY_DESCRIPTOR *VirtualMemoryTable; + UINTN Index = 0; + + ASSERT (MemoryTable != NULL); + + VirtualMemoryTable = AllocatePool ( + sizeof (EFI_MEMORY_DESCRIPTOR) * + MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS + ); + + // + // Add the 0x10000000-0x20000000. In the virtual machine, this area use for CPU UART, flash, PIC etc. + // + VirtualMemoryTable[Index].PhysicalStart = BASE_256MB; + VirtualMemoryTable[Index].VirtualStart = VirtualMemoryTable[Index].PhysicalStart; + VirtualMemoryTable[Index].NumberOfPages = EFI_SIZE_TO_PAGES (SIZE_256MB); + VirtualMemoryTable[Index].Attribute = EFI_MEMORY_UC; + ++Index; + + Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __func__, __LINE__, Status)); + ZeroMem (&VirtualMemoryTable[Index], sizeof (EFI_MEMORY_DESCRIPTOR)); + *MemoryTable = VirtualMemoryTable; + return; + } + + if (FwCfgSize % sizeof MemoryMapEntry != 0) { + DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize)); + } + + QemuFwCfgSelectItem (FwCfgItem); + StartEntry = AllocatePages (EFI_SIZE_TO_PAGES (FwCfgSize)); + QemuFwCfgReadBytes (FwCfgSize, StartEntry); + for (Processed = 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); Processed++) { + pEntry = StartEntry + Processed; + if (pEntry->Length == 0) { + continue; + } + + DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p type %d\n", pEntry->BaseAddr, pEntry->Length, pEntry->Type)); + VirtualMemoryTable[Index].PhysicalStart = pEntry->BaseAddr; + VirtualMemoryTable[Index].VirtualStart = VirtualMemoryTable[Index].PhysicalStart; + VirtualMemoryTable[Index].NumberOfPages = EFI_SIZE_TO_PAGES (pEntry->Length); + VirtualMemoryTable[Index].Attribute = EFI_MEMORY_WB; + ++Index; + } + + FreePages (StartEntry, EFI_SIZE_TO_PAGES (FwCfgSize)); + // End of Table + ZeroMem (&VirtualMemoryTable[Index], sizeof (EFI_MEMORY_DESCRIPTOR)); + *MemoryTable = VirtualMemoryTable; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c new file mode 100644 index 0000000000..0560ea86bf --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c @@ -0,0 +1,393 @@ +/** @file + Platform PEI driver + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Mem - Memory +**/ + +// +// The package level header files this module uses +// +#include +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Platform.h" + +VOID +SaveRtcRegisterAddressHob ( + UINT64 RtcRegisterBase + ); + +/* TODO */ +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { + { EfiReservedMemoryType, 0x004 }, + { EfiRuntimeServicesData, 0x024 }, + { EfiRuntimeServicesCode, 0x030 }, + { EfiBootServicesCode, 0x180 }, + { EfiBootServicesData, 0xF00 }, + { EfiMaxMemoryType, 0x000 } +}; + +// +// Module globals +// +CONST EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMasterBootModePpiGuid, + NULL +}; + +STATIC EFI_BOOT_MODE mBootMode = BOOT_WITH_FULL_CONFIGURATION; + +/** + Create Reserved type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Create system type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ) +{ + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + MemoryBase, + MemorySize + ); +} + +/** + Create memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); +} + +/** + Create memory type information hand off block. + + @param VOID + + @return VOID +**/ +VOID +MemMapInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "==%a==\n", __func__)); + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( + &gEfiMemoryTypeInformationGuid, + mDefaultMemoryTypeInformation, + sizeof (mDefaultMemoryTypeInformation) + ); +} + +/** Get the Rtc base address from the DT. + + This function fetches the node referenced in the "loongson,ls7a-rtc" + property of the "reg" node and returns the base address of + the RTC. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [out] RtcBaseAddress If success, contains the base address + of the Rtc. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND RTC info not found in DT. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GetRtcAddress ( + IN CONST VOID *Fdt, + OUT UINT64 *RtcBaseAddress + ) +{ + INT32 Node; + INT32 Prev; + CONST CHAR8 *Type; + INT32 Len; + CONST UINT64 *RegProp; + EFI_STATUS Status; + + if ((Fdt == NULL) || (fdt_check_header (Fdt) != 0)) { + return EFI_INVALID_PARAMETER; + } + + Status = EFI_NOT_FOUND; + for (Prev = 0; ; Prev = Node) { + Node = fdt_next_node (Fdt, Prev, NULL); + if (Node < 0) { + break; + } + + // + // Check for memory node + // + Type = fdt_getprop (Fdt, Node, "compatible", &Len); + if ((Type) && (AsciiStrnCmp (Type, "loongson,ls7a-rtc", Len) == 0)) { + // + // Get the 'reg' property of this node. For now, we will assume + // two 8 byte quantities for base and size, respectively. + // + RegProp = fdt_getprop (Fdt, Node, "reg", &Len); + if ((RegProp != 0) && (Len == (2 * sizeof (UINT64)))) { + *RtcBaseAddress = SwapBytes64 (RegProp[0]); + Status = RETURN_SUCCESS; + DEBUG ((DEBUG_INFO, "%a Len %d RtcBase %llx\n", __func__, Len, *RtcBaseAddress)); + break; + } else { + DEBUG ((DEBUG_ERROR, "%a: Failed to parse FDT rtc node\n", __func__)); + break; + } + } + } + + return Status; +} + +/** + Misc Initialization. + + @param VOID + + @return VOID +**/ +VOID +MiscInitialization ( + VOID + ) +{ + CPUCFG_REG1_INFO_DATA CpucfgReg1Data; + UINT8 CpuPhysMemAddressWidth; + + DEBUG ((DEBUG_INFO, "==%a==\n", __func__)); + + // + // Get the the CPU physical memory address width. + // + AsmCpucfg (CPUCFG_REG1_INFO, &CpucfgReg1Data.Uint32); + + CpuPhysMemAddressWidth = (UINT8)(CpucfgReg1Data.Bits.PALEN + 1); + + // + // Creat CPU HOBs. + // + BuildCpuHob (CpuPhysMemAddressWidth, FixedPcdGet8 (PcdPrePiCpuIoSize)); +} + +/** + add fdt hand off block. + + @param VOID + + @return VOID +**/ +VOID +AddFdtHob ( + VOID + ) +{ + VOID *Base; + VOID *NewBase; + UINTN FdtSize; + UINTN FdtPages; + UINT64 *FdtHobData; + UINT64 RtcBaseAddress; + RETURN_STATUS Status; + + Base = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress); + ASSERT (Base != NULL); + + Status = GetRtcAddress (Base, &RtcBaseAddress); + if (RETURN_ERROR (Status)) { + return; + } + + SaveRtcRegisterAddressHob (RtcBaseAddress); + + FdtSize = fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreeAllocationPadding); + FdtPages = EFI_SIZE_TO_PAGES (FdtSize); + NewBase = AllocatePages (FdtPages); + ASSERT (NewBase != NULL); + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages)); + + FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData); + ASSERT (FdtHobData != NULL); + *FdtHobData = (UINTN)NewBase; +} + +/** + Fetch the size of system memory from QEMU. + + @param VOID + + @return VOID +**/ +VOID +ReportSystemMemorySize ( + VOID + ) +{ + UINT64 RamSize; + + QemuFwCfgSelectItem (QemuFwCfgItemRamSize); + RamSize = QemuFwCfgRead64 (); + DEBUG (( + DEBUG_INFO, + "%a: QEMU reports %dM system memory\n", + __func__, + RamSize/1024/1024 + )); + + // + // Assert false if QEMU report system memory size is less then 256M. + // + if (RamSize <= SIZE_256MB) { + ASSERT (FALSE); + } +} + +/** + Perform Platform PEI initialization. + + @param FileHandle Handle of the file being invoked. + @param PeiServices Describes the list of possible PEI Services. + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +EFIAPI +InitializePlatform ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + UINTN TranslationTableSize; + EFI_MEMORY_DESCRIPTOR *MemoryTable; + + DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); + + Status = PeiServicesSetBootMode (mBootMode); + ASSERT_EFI_ERROR (Status); + + Status = PeiServicesInstallPpi (&mPpiListBootMode); + ASSERT_EFI_ERROR (Status); + + ReportSystemMemorySize (); + + PublishPeiMemory (); + + PeiFvInitialization (); + InitializeRamRegions (); + MemMapInitialization (); + + Status = PlatformHookSerialPortInitialize (); + ASSERT_EFI_ERROR (Status); + + // + // Collect numbers of on line processors and all of APs APIC ID + // TODO: Current, the NULL library is used, this library will be populated in the future. + // + CollectAllProcessorResource (); + + MiscInitialization (); + + AddFdtHob (); + + // + // Initialization MMU + // + GetMemoryMapPolicy (&MemoryTable); + Status = ConfigureMemoryManagementUnit ( + MemoryTable, + NULL, + &TranslationTableSize + ); + ASSERT_EFI_ERROR (Status); + + MpInitLibInitialize (); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Platform.h b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.h new file mode 100644 index 0000000000..5775e954af --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.h @@ -0,0 +1,128 @@ +/** @file + Platform PEI module include file. + + Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PLATFORM_H_ +#define PLATFORM_H_ + +#include +#include +#include +#include + +typedef struct { + UINT64 BaseAddr; + UINT64 Length; + UINT32 Type; + UINT32 Reserved; +} MEMMAP_ENTRY; + +VOID +EFIAPI +CollectAllProcessorResource ( + VOID + ); + +VOID +EFIAPI +SaveProcessorResource ( + VOID + ); + +/** + Create system type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +/** + Create memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ); + +/** + Create Reserved type memory range hand off block. + + @param MemoryBase memory base address. + @param MemoryLimit memory length. + + @return VOID +**/ +VOID +AddReservedMemoryBaseSizeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + UINT64 MemorySize + ); + +/** + Publish PEI core memory + + @return EFI_SUCCESS The PEIM initialized successfully. +**/ +EFI_STATUS +PublishPeiMemory ( + VOID + ); + +/** + Publish system RAM and reserve memory regions + + @return VOID +**/ +VOID +InitializeRamRegions ( + VOID + ); + +/** + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI + and DXE know about them. + + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. +**/ +EFI_STATUS +PeiFvInitialization ( + VOID + ); + +/** + Gets the Virtual Memory Map of corresponding platforms. + + This Virtual Memory Map is used by initialize the MMU on corresponding + platforms. + + @param[out] MemoryTable Array of EFI_MEMORY_DESCRIPTOR + describing a Physical-to-Virtual Memory + mapping. This array must be ended by a + zero-filled entry. The allocated memory + will not be freed. +**/ +VOID +EFIAPI +GetMemoryMapPolicy ( + OUT EFI_MEMORY_DESCRIPTOR **MemoryTable + ); + +#endif // PLATFORM_H_ diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf b/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf new file mode 100644 index 0000000000..e185567da8 --- /dev/null +++ b/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf @@ -0,0 +1,72 @@ +## @file +# Platform PEI driver +# +# Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = PlatformPei + FILE_GUID = 4c0e81e5-e8e3-4eef-b24b-19b686e9ab53 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + ENTRY_POINT = InitializePlatform + +# +# VALID_ARCHITECTURES = LOONGARCH64 +# + +[Sources] + Fv.c + MemDetect.c + Platform.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Ppis] + gEfiPeiMasterBootModePpiGuid + +[Guids] + gEfiMemoryTypeInformationGuid + gFdtHobGuid + +[LibraryClasses] + BaseMemoryLib + CollectApResourceLib + CpuMmuInitLib + DebugLib + HobLib + IoLib + MemoryAllocationLib + MpInitLib + PcdLib + PeiResourcePublicationLib + PeiServicesLib + PeiServicesTablePointerLib + PeimEntryPoint + PlatformHookLib + QemuFwCfgLib + RealTimeClockLib + TimerLib + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask + +[FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize + gUefiCpuPkgTokenSpaceGuid.PcdCpuExceptionVectorBaseAddress + +[Depex] + TRUE -- 2.27.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116607): https://edk2.groups.io/g/devel/message/116607 Mute This Topic: https://groups.io/mt/104859901/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-