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 6D2FC940F17 for ; Thu, 19 Oct 2023 02:59:43 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=nW7JgGOsVevj+stPEWGuEBwROLTG886Q1ki3jemWIqo=; 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-Type:Content-Transfer-Encoding; s=20140610; t=1697684382; v=1; b=HgF2mt0+3FgOxcjIAly1INiI3K109aHOj4GbBtCBciYufBmJ1+0WES7hmm1TSNebj5PdyUoB /kZrE6p1kaaKsAVIYQLWjwxb0RmoYIdahL1Yl07CnxPHcmkTXJ8eQzZ1OGsxKGGhot8mch2lwWr J5iiE/1jWJTcB8FtjyWvw/jA= X-Received: by 127.0.0.2 with SMTP id DXioYY7687511xn0jFdhvcQA; Wed, 18 Oct 2023 19:59:42 -0700 X-Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by mx.groups.io with SMTP id smtpd.web10.19414.1697684381044230046 for ; Wed, 18 Oct 2023 19:59:41 -0700 X-Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id 57169808F; Thu, 19 Oct 2023 10:59:39 +0800 (CST) X-Received: from EXMBX073.cuchost.com (172.16.6.83) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 19 Oct 2023 10:59:39 +0800 X-Received: from localhost.localdomain (202.188.176.82) by EXMBX073.cuchost.com (172.16.6.83) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 19 Oct 2023 10:59:37 +0800 From: "John Chew" To: CC: John Chew , Sunil V L Subject: [edk2-devel] [PATCH v1 5/6] StarFive/JH7110Pkg: Implement boot services memory allocation driver Date: Thu, 19 Oct 2023 10:59:20 +0800 Message-ID: <20231019025921.1593-5-yuinyee.chew@starfivetech.com> In-Reply-To: <20231019025921.1593-1-yuinyee.chew@starfivetech.com> References: <20231019025921.1593-1-yuinyee.chew@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [202.188.176.82] X-ClientProxiedBy: EXCAS061.cuchost.com (172.16.6.21) To EXMBX073.cuchost.com (172.16.6.83) X-YovoleRuleAgent: yovoleflag 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,yuinyee.chew@starfivetech.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: QEa3bdnfvLVIntEyhVDMZzMtx7686176AA= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=HgF2mt0+; 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 Some DXE drivers such as MMC's DMA can only work with 32-bit addressing. So, EfiBootServicesData need to set within 32-bit range only. This is achieved by setting all EfiConventionalMemory to EfiBootServicesData before any memory allocations in the early stage of DXE. Cc: Sunil V L Signed-off-by: John Chew --- Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServicesDxe.c | 10= 8 ++++++++++++++++++++ Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServicesDxe.inf | 3= 4 ++++++ 2 files changed, 142 insertions(+) diff --git a/Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServices= Dxe.c b/Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServicesDxe.c new file mode 100644 index 000000000000..a26a77661d4e --- /dev/null +++ b/Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServicesDxe.c @@ -0,0 +1,108 @@ +/** @file + * + * Copyright (c) 2023, StarFive Technology Co., Ltd. All rights reserved.=
+ * + * SPDX-License-Identifier: BSD-2-Clause-Patent + * + **/ + +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +BootServicesInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINTN MemoryMapSize; + EFI_MEMORY_DESCRIPTOR *MemoryMap, *Desc; + UINTN MapKey; + UINTN DescriptorSize; + UINT32 DescriptorVersion; + EFI_PHYSICAL_ADDRESS Addr; + UINTN Idx; + UINTN Pages; + + MemoryMap =3D NULL; + MemoryMapSize =3D 0; + Pages =3D 0; + + Status =3D gBS->GetMemoryMap ( + &MemoryMapSize, + MemoryMap, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { + Pages =3D EFI_SIZE_TO_PAGES (MemoryMapSize) + 1; + MemoryMap =3D AllocatePages (Pages); + + // + // Get System MemoryMap + // + Status =3D gBS->GetMemoryMap ( + &MemoryMapSize, + MemoryMap, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + } + + if (EFI_ERROR (Status) || (MemoryMap =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get memory map\n", __func__)); + if (MemoryMap) { + FreePages ((VOID *)MemoryMap, Pages); + } + + return EFI_SUCCESS; + } + + Desc =3D MemoryMap; + + // + // Change 64-bit EfiConventionalMemory with EfiBootServicesData + // So that DXE driver only allocate EfiBootServicesData in 32-bit addres= ses + // + for (Idx =3D 0; Idx < (MemoryMapSize / DescriptorSize); Idx++) { + if ((Desc->Type =3D=3D EfiConventionalMemory) && + ((Desc->PhysicalStart > MAX_UINT32) || ((Desc->PhysicalStart + Des= c->NumberOfPages * EFI_PAGE_SIZE) > MAX_UINT32))) + { + if (Desc->PhysicalStart > MAX_UINT32) { + Addr =3D Desc->PhysicalStart; + Status =3D gBS->AllocatePages ( + AllocateAddress, + EfiBootServicesData, + Desc->NumberOfPages, + &Addr + ); + } else { + Addr =3D 0x100000000ULL; + Status =3D gBS->AllocatePages ( + AllocateAddress, + EfiBootServicesData, + Desc->NumberOfPages - EFI_SIZE_TO_PAG= ES (0x100000000 - Desc->PhysicalStart), + &Addr + ); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate boot service data at = %llX\n", __func__, Addr)); + } + } + + Desc =3D (EFI_MEMORY_DESCRIPTOR *)((UINT64)Desc + DescriptorSize); + } + + FreePages ((VOID *)MemoryMap, Pages); + + return EFI_SUCCESS; +} diff --git a/Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServices= Dxe.inf b/Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServicesDxe= .inf new file mode 100644 index 000000000000..33a777ae5a24 --- /dev/null +++ b/Silicon/StarFive/JH7110Pkg/Driver/BootServicesDxe/BootServicesDxe.inf @@ -0,0 +1,34 @@ +## @file +# DXE Boot Service driver for StarFive JH7110 SoC +# +# Copyright (c) 2023, StarFive Technology Co., Ltd. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010019 + BASE_NAME =3D BootServicesDxe + FILE_GUID =3D E7B2A7CF-4A9B-4F63-9B9E-12B34C5D6E78 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + + ENTRY_POINT =3D BootServicesInitialize + +[Sources] + BootServicesDxe.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + DebugLib + MemoryAllocationLib + +[Guids] + gEfiEventReadyToBootGuid + +[Depex] + TRUE --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109783): https://edk2.groups.io/g/devel/message/109783 Mute This Topic: https://groups.io/mt/102053685/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-