From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web09.1966.1623795641635028504 for ; Tue, 15 Jun 2021 15:20:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=SitcsQC/; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: guo.dong@intel.com) IronPort-SDR: cQf5IifXlGZ1zq32Cu15Fk+PlVNm3j3+Z9W78SoeavaacXemepdNvsOLpWOdNXeNpsFoxelgnk a8M5z28Xu52Q== X-IronPort-AV: E=McAfee;i="6200,9189,10016"; a="203055375" X-IronPort-AV: E=Sophos;i="5.83,276,1616482800"; d="scan'208";a="203055375" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2021 15:20:40 -0700 IronPort-SDR: KiPMnD9d5xzfV04pvLhuoZGK4pDT+Xm0+8gLabLqp3l90AOyWh+Mi4oZMY6h0a4h+lIqZ7GhZr klLqLtZ07MzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,276,1616482800"; d="scan'208";a="415526650" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga007.fm.intel.com with ESMTP; 15 Jun 2021 15:20:39 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 15 Jun 2021 15:20:39 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 15 Jun 2021 15:20:38 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Tue, 15 Jun 2021 15:20:38 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.4; Tue, 15 Jun 2021 15:20:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PzpX/FwELhKF3AelDUl+8NzB99kVPmqWQ4lbqfw5uM+CmtD8tXlsRryoSuaLEIX1weoiipQRBjGrI3C0F6ryhtKXqOv9BeSG6It3H4Z75qUJU9zVLe72BqU3ngW1NA4ITF+LZhzRRq4BU5Z7ZsGLRoIL6qJ78EpKkV6WBUC4nsZJd+g1OySovADSEOF+fffUwhUjLpmI0Dfy8jms6naU28n35L588y9V8XselR+XniEHNs8YLnUOXkImc9rT2x6ui9mhukbwcpspscWGbvpYvro8MY33tEp+Wt0Q+KaWpkO927Ud6/jpT6o/zN3nJazkryr6mOHUcTeONE3cycdDUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vaCbj83ax6turq5e6ETq7puyI3Y1PYmbrst1bO1ld90=; b=Gtjs/J7IuUTK/IRz2pXlsQ/E+3ztAktO9CLktEpW6jreis5pWurL+v8veX8HR9GUPGrl9/ZTbYfqhZWfBVITSR0Ytod59pE3qP/nZYWO2T1/vTeeL9aK6Nw/g+CzTW6nJ6aokbUjACjKo0XQqMdfrkiuCaEk1vpXyF35QpTNrfKzEQLzggc2dLNWYXH4rqCGp8uLBtqIhciouuBIiAafZXAHFeIK5cnlOPX32ddly0+dTuxUXYEhM0vhrsAY6ZCPXV02bjYMFPbL3r7p7LwuBcOiOPlvSEfDLvFL0h8dMrJwLO3e6ZOOvSotg/1CMugo0CHHNawpCjxpzpDAcGWnWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vaCbj83ax6turq5e6ETq7puyI3Y1PYmbrst1bO1ld90=; b=SitcsQC/7jFSXXKA+ZBc8Ifu+7YymMpcfpdKZ5wHrZWSVAsa9tdsmXN/dRJRuXlytYRniewyN7Wnh8R8SJ5aJmJIl2/KtOjACZuQwAZS3g2W44kYSi5ndwDyrc35xj3+u3MfqFWZgtRBZUxpP88reIi8iexwgJyJyXraIdKoJGk= Received: from BYAPR11MB3622.namprd11.prod.outlook.com (2603:10b6:a03:fe::30) by BY5PR11MB4008.namprd11.prod.outlook.com (2603:10b6:a03:186::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.23; Tue, 15 Jun 2021 22:20:37 +0000 Received: from BYAPR11MB3622.namprd11.prod.outlook.com ([fe80::247b:262c:b8da:710b]) by BYAPR11MB3622.namprd11.prod.outlook.com ([fe80::247b:262c:b8da:710b%7]) with mapi id 15.20.4219.025; Tue, 15 Jun 2021 22:20:36 +0000 From: "Guo Dong" To: "devel@edk2.groups.io" , "patrick.rudolph@9elements.com" CC: "Ma, Maurice" , "You, Benjamin" Subject: Re: [edk2-devel] [PATCH] UefiPayloadPkg/UefiPayloadEntry: Improve bootloader memrange parsing Thread-Topic: [edk2-devel] [PATCH] UefiPayloadPkg/UefiPayloadEntry: Improve bootloader memrange parsing Thread-Index: AQHXYembaVFd/JxI40W4jmM8SUcikasVSBhg Date: Tue, 15 Jun 2021 22:20:36 +0000 Message-ID: References: <20210615132254.3364910-1-patrick.rudolph@9elements.com> In-Reply-To: <20210615132254.3364910-1-patrick.rudolph@9elements.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [2600:8800:1704:2800:5466:f4d7:26f9:3cf6] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fbd1186e-a0ca-4b75-c5f5-08d9304bccdb x-ms-traffictypediagnostic: BY5PR11MB4008: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: IVQ45uj/TUY7uaJjEw/vL3r4kKRJ1h9A2wgwpRkHzMMmKtKaSku968pxOwnVSWii2g07Zsx4AXV8zviYXJ61j/EnLboSyFHQUv3dHhuhNb8/ooA6x/GIEcJEmkG/iSSixx3aII0FEWARR6hZmQ0RCNlvECNqrrBjYzixqesjsFgIiefRH0Pa4fHZy6ObS3cRRHzToXzmqnb+37kPsM+/y6rB+l9QBX8SSfpUbFJTHor0j9QeeAQkawkOkYzmUlPCYrXusn5KCPTtr5VJIOgPYMzaI6PEgp/g/y00gJBd0PzQ2UZIO+CagwQNpIAr2DF5jj2N+3bLesRSMZR3tEhgn2cuxBGkylLn6x+i+6qW1VPkDar2DZgkuBdvQOf4UymBsYtFvVJaD4n+KN5IEXCmbPu+MfJDT9ORxscLP8pJiz5UGg+1SCYYbrBjl+MYrwPCg1qBAsXhuzpz94AeYKpw9M5k67R2tN8DYHoWQQS3vOwT78IUp7WWeQHZp9z/5y6D3OT1HS+JfF1hUzmFBWiLM7UNoR5m+mw9/2UQK/rimrW98+TJI3wiL0ruFKLcSdZK+YADMX2fruPvoaFS3zEdH6rw3Vd/KSya36yNCRVQQ0Dfmj4bu0oR5LFRkxch8zFuLEuoW7LiSVLQD0LY22TS4zKILdvsdsL4+qKCo9Vz9A/hbXYQPRAkCgw2BPklNDJQl4PVe7PHd9Fpi4yx74OC38YFgsL4zENCExWqxtsq58S4CAKB/tE5rc81jgaMEhyw3DZKq6xgJhZPb34XI3uQxw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR11MB3622.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(396003)(346002)(376002)(39860400002)(110136005)(30864003)(54906003)(316002)(966005)(478600001)(33656002)(86362001)(52536014)(53546011)(8676002)(2906002)(7696005)(6506007)(71200400001)(76116006)(107886003)(4326008)(83380400001)(55016002)(66946007)(64756008)(66556008)(66476007)(66446008)(5660300002)(38100700002)(186003)(8936002)(9686003)(122000001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?9wuGZOp5oQkoBXRqDOBt7/yH5AC+/kQTiJiukkWfIsQyH2vuqpPrX4D57IsK?= =?us-ascii?Q?HjR2jY2wX9v2DGRlGX65OAWrauxolKA4nIRf4nlW9ew1AC/Ra/y8DJO4U4Gz?= =?us-ascii?Q?r+NW9t5UzlDeOr8SW6PoKYNfZI68BHeniS/bSXGoPaRFnNH85mGRjMX0+3u6?= =?us-ascii?Q?1SXO9I4EedX8U+wkhcmVfDqd47VRlsk/2w0ZOVatnVwx/LArMhcPF904B0vP?= =?us-ascii?Q?/RjVUOn2ICiYLApIlhl8tbZnjYua9E8iiiTAB0J65BHkD4eLUpL6uGpHkMm+?= =?us-ascii?Q?otXoYK2mmsdO9oKf6BiEsuwf1CbYhJGby4dfVTDHlKbFNtqZWw8Mvn7qAYnG?= =?us-ascii?Q?Byc+KI2/0T8HPJYKQe4GZM0SDz8EVFPhAtaYaKB6cebmm9MG5nffhcW9qA3p?= =?us-ascii?Q?TOkkLlDfEzxXRHLq31HmRroygb+7BGLev3eZHYb4/LaF2s3qAN+HHkJi0ywR?= =?us-ascii?Q?Yhi96qP83b7pJRSK/oRYERimBGto/8bJ7irA4YBcgf4RQuPFNK5aI9tAgYxd?= =?us-ascii?Q?aSwxZQxJscSB1IITNurqj2x14BznQ8iwfQBjO1kt/N5AH7uceIZEgF+SVsI2?= =?us-ascii?Q?7dH8KHbDJXhre2t8oKSjqCFLqTt8u4MJOjUqqdb50Re66c5ba5Epn7jTIr/f?= =?us-ascii?Q?lrB5k74Fhhe3eTASbbxYaz4VdqG+IjUGf0DeVPtRDxpnAcHQFpNq5kBWByxh?= =?us-ascii?Q?L2gYJMC1dWYD1DM6hKbymuD3JPfaW7OyEMVi8fswnihd63iLo6BKfHtAgVbN?= =?us-ascii?Q?F97gFtEqv+4MfRvFseGAgcGYGVz6mmMAvUUxOEeP1ED0085ozriGiMti7nCm?= =?us-ascii?Q?/uWWRXAYs7LDRIwvZC5lfysiLVgr+nTwVpOMwTv6ALrQZT4d8C5QKJn4pcKg?= =?us-ascii?Q?VWuTk8Q9a1feqsZII+vMs4zpyfWX9EKH+vAf0J3TrSpjmRAAy08jcSi/jo5J?= =?us-ascii?Q?PpKJoiS2Q6VlMqKBkbr0FMab+F3Td4YVxi7c7UtMU/4bJqw8SY9y8C35YCtW?= =?us-ascii?Q?YeDXQb5zPvwbkUy+E1zAf2B/Pe4LI0qZJoYJ/Y1l4QxzxhKw7fgRZTMJVX7o?= =?us-ascii?Q?OlKZKeRcZ9DYhkfqfrOridUge3gMctIUaMxbJnj39Zbwiswo55D2y2uu5bWv?= =?us-ascii?Q?dRlN2ETAGP18iBYDGpKrA+rLt5zK+7F7Nj7O4UdF0Pn7rGwYXQhSdjIUXj0z?= =?us-ascii?Q?Tj7tm0cnoohSseEvik3FnMMevKlc2TIYGoInHilIgzUQDqrr/VGkz1xB2qZX?= =?us-ascii?Q?zvRT0SlYer3ve4ER9ZSglRzx9e6atOqNQDc90ui8sFBDuo+HXatwDZV/jtit?= =?us-ascii?Q?BTfr+XM/uzNJtxboAJoCPpFyLRdLAXOSBrGo1Rxf+eUB/WBfbf+isJSUrUKW?= =?us-ascii?Q?e4m6s54rs8gaNM2RLnmXSZ25IM9x?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3622.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbd1186e-a0ca-4b75-c5f5-08d9304bccdb X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jun 2021 22:20:36.5772 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: R9APxlZjpo3Dp9BTL1w1tV+Whe/qaZdcWeJcuASccf95d80hJpVwlF0ug4QU56YRsSYWRPVgHNbzVTIx/6fzdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB4008 Return-Path: guo.dong@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Could you provide more info on the issues in fixed by this patch? There is a UEFI payload patch (under code review) to support the bootloader= to provide a HOB on the PCI resources, this way the UEFI payload doesn't need collect resour= ces again by parsing all the PCI devices. Not sure if that patch (UefiPayloadPkg: UefiPayload re= trieve PCI root bridge from Guid Hob) could avoid the issues. In this patch, as it mentioned some information (system memory or MMIO) is = missing in the bootloader E820 style table. Guessing the TOLUD might work in most cases, b= ut may fail since the assumptions. I saw this patch fixed the memory type for ACPI memory. I think we could ha= ve this fix if the TOLUD guessing could be avoided. Thanks, Guo > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Patrick > Rudolph > Sent: Tuesday, June 15, 2021 6:23 AM > To: devel@edk2.groups.io > Cc: Ma, Maurice ; Dong, Guo > ; You, Benjamin > Subject: [edk2-devel] [PATCH] UefiPayloadPkg/UefiPayloadEntry: Improve > bootloader memrange parsing >=20 > Currently several DXE crash due to invalid memory resource settings. > coreboot and slimbootloader provide an e820 compatible memory map, > which doesn't work well with EDK2 as the e820 spec is missing MMIO region= s. > In e820 'reserved' could either mean "DRAM used by boot firmware" or > "MMIO > in use and not detectable by OS". >=20 > Guess Top of lower usable DRAM (TOLUD) by walking memory ranges and > then > mark everything reserved below TOLUD as DRAM and everything reserved > above > TOLUD as MMIO. >=20 > This fixes several assertions seen in PciHostBridgeDxe. >=20 > Signed-off-by: Patrick Rudolph > --- > .../UefiPayloadEntry/UefiPayloadEntry.c | 187 +++++++++++++++++- > .../UefiPayloadEntry/UefiPayloadEntry.h | 10 + > 2 files changed, 194 insertions(+), 3 deletions(-) >=20 > diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > index 805f5448d9..d20e1a0862 100644 > --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > @@ -7,10 +7,162 @@ >=20 >=20 > #include "UefiPayloadEntry.h" >=20 >=20 >=20 > +STATIC UINT32 TopOfLowerUsableDram =3D 0; >=20 > + >=20 > /** >=20 > Callback function to build resource descriptor HOB >=20 >=20 >=20 > This function build a HOB based on the memory map entry info. >=20 > + It creates only EFI_RESOURCE_MEMORY_MAPPED_IO and > EFI_RESOURCE_MEMORY_RESERVED >=20 > + resources. >=20 > + >=20 > + @param MemoryMapEntry Memory map entry info got from > bootloader. >=20 > + @param Params A pointer to ACPI_BOARD_INFO. >=20 > + >=20 > + @retval RETURN_SUCCESS Successfully build a HOB. >=20 > + @retval EFI_INVALID_PARAMETER Invalid parameter provided. >=20 > +**/ >=20 > +EFI_STATUS >=20 > +MemInfoCallbackMMIO ( >=20 > + IN MEMROY_MAP_ENTRY *MemoryMapEntry, >=20 > + IN VOID *Params >=20 > + ) >=20 > +{ >=20 > + EFI_PHYSICAL_ADDRESS Base; >=20 > + EFI_RESOURCE_TYPE Type; >=20 > + UINT64 Size; >=20 > + EFI_RESOURCE_ATTRIBUTE_TYPE Attribue; >=20 > + ACPI_BOARD_INFO *AcpiBoardInfo; >=20 > + >=20 > + AcpiBoardInfo =3D (ACPI_BOARD_INFO *)Params; >=20 > + if (AcpiBoardInfo =3D=3D NULL) { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + // >=20 > + // Skip types already handled in MemInfoCallback >=20 > + // >=20 > + if (MemoryMapEntry->Type =3D=3D E820_RAM || MemoryMapEntry->Type =3D= =3D > E820_ACPI) { >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + if (MemoryMapEntry->Base =3D=3D AcpiBoardInfo->PcieBaseAddress) { >=20 > + // >=20 > + // MMCONF is always MMIO >=20 > + // >=20 > + Type =3D EFI_RESOURCE_MEMORY_MAPPED_IO; >=20 > + } else if (MemoryMapEntry->Base < TopOfLowerUsableDram) { >=20 > + // >=20 > + // It's in DRAM and thus must be reserved >=20 > + // >=20 > + Type =3D EFI_RESOURCE_MEMORY_RESERVED; >=20 > + } else if (MemoryMapEntry->Base < 0x100000000ULL && >=20 > + MemoryMapEntry->Base >=3D TopOfLowerUsableDram) { >=20 > + // >=20 > + // It's not in DRAM, must be MMIO >=20 > + // >=20 > + Type =3D EFI_RESOURCE_MEMORY_MAPPED_IO; >=20 > + } else { >=20 > + Type =3D EFI_RESOURCE_MEMORY_RESERVED; >=20 > + } >=20 > + >=20 > + Base =3D MemoryMapEntry->Base; >=20 > + Size =3D MemoryMapEntry->Size; >=20 > + >=20 > + Attribue =3D EFI_RESOURCE_ATTRIBUTE_PRESENT | >=20 > + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | >=20 > + EFI_RESOURCE_ATTRIBUTE_TESTED | >=20 > + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | >=20 > + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | >=20 > + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | >=20 > + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE; >=20 > + >=20 > + BuildResourceDescriptorHob (Type, Attribue, > (EFI_PHYSICAL_ADDRESS)Base, Size); >=20 > + DEBUG ((DEBUG_INFO , "buildhob: base =3D 0x%lx, size =3D 0x%lx, type = =3D > 0x%x\n", Base, Size, Type)); >=20 > + >=20 > + if (MemoryMapEntry->Type =3D=3D E820_NVS) { >=20 > + BuildMemoryAllocationHob (Base, Size, EfiACPIMemoryNVS); >=20 > + } else if (MemoryMapEntry->Type =3D=3D E820_UNUSABLE || >=20 > + MemoryMapEntry->Type =3D=3D E820_DISABLED) { >=20 > + BuildMemoryAllocationHob (Base, Size, EfiUnusableMemory); >=20 > + } else if (MemoryMapEntry->Type =3D=3D E820_PMEM) { >=20 > + BuildMemoryAllocationHob (Base, Size, EfiPersistentMemory); >=20 > + } >=20 > + >=20 > + return RETURN_SUCCESS; >=20 > +} >=20 > + >=20 > + >=20 > +/** >=20 > + Callback function to find TOLUD (Top of Lower Usable DRAM) >=20 > + >=20 > + Estimate where TOLUD (Top of Lower Usable DRAM) resides. The exact > position >=20 > + would require platform specific code. >=20 > + >=20 > + @param MemoryMapEntry Memory map entry info got from > bootloader. >=20 > + @param Params Not used for now. >=20 > + >=20 > + @retval RETURN_SUCCESS Successfully updated > TopOfLowerUsableDram. >=20 > +**/ >=20 > +EFI_STATUS >=20 > +FindToludCallback ( >=20 > + IN MEMROY_MAP_ENTRY *MemoryMapEntry, >=20 > + IN VOID *Params >=20 > + ) >=20 > +{ >=20 > + // >=20 > + // This code assumes that the memory map on this x86 machine below > 4GiB is continous >=20 > + // until TOLUD. In addition it assumes that the bootloader provided > memory tables have >=20 > + // no "holes" and thus the first memory range not covered by e820 mark= s > the end of >=20 > + // usable DRAM. In addition it's assumed that every reserved memory > region touching >=20 > + // usable RAM is also covering DRAM, everything else that is marked > reserved thus must be >=20 > + // MMIO not detectable by bootloader/OS >=20 > + // >=20 > + >=20 > + // >=20 > + // Skip memory types not RAM or reserved >=20 > + // >=20 > + if (MemoryMapEntry->Type =3D=3D E820_NVS || MemoryMapEntry->Type =3D= =3D > E820_UNUSABLE || >=20 > + MemoryMapEntry->Type =3D=3D E820_DISABLED || MemoryMapEntry->Type > =3D=3D E820_PMEM) { >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + // >=20 > + // Skip resources above 4GiB >=20 > + // >=20 > + if (MemoryMapEntry->Base >=3D 0x100000000ULL) { >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + if ((MemoryMapEntry->Type =3D=3D E820_RAM) || >=20 > + (MemoryMapEntry->Type =3D=3D E820_ACPI)) { >=20 > + // >=20 > + // It's usable DRAM. Update TOLUD. >=20 > + // >=20 > + if (TopOfLowerUsableDram < (MemoryMapEntry->Base + > MemoryMapEntry->Size)) { >=20 > + TopOfLowerUsableDram =3D MemoryMapEntry->Base + > MemoryMapEntry->Size; >=20 > + } >=20 > + } else { >=20 > + // >=20 > + // It might be reserved DRAM or MMIO. >=20 > + // >=20 > + // If it touches usable DRAM at Base assume it's DRAM as well, >=20 > + // as it could be bootloader installed tables, TSEG, GTT, ... >=20 > + // >=20 > + if (TopOfLowerUsableDram =3D=3D MemoryMapEntry->Base) { >=20 > + TopOfLowerUsableDram =3D MemoryMapEntry->Base + > MemoryMapEntry->Size; >=20 > + } >=20 > + } >=20 > + >=20 > + return RETURN_SUCCESS; >=20 > +} >=20 > + >=20 > + >=20 > +/** >=20 > + Callback function to build resource descriptor HOB >=20 > + >=20 > + This function build a HOB based on the memory map entry info. >=20 > + Only add EFI_RESOURCE_SYSTEM_MEMORY. >=20 >=20 >=20 > @param MemoryMapEntry Memory map entry info got from > bootloader. >=20 > @param Params Not used for now. >=20 > @@ -28,7 +180,15 @@ MemInfoCallback ( > UINT64 Size; >=20 > EFI_RESOURCE_ATTRIBUTE_TYPE Attribue; >=20 >=20 >=20 > - Type =3D (MemoryMapEntry->Type =3D=3D 1) ? > EFI_RESOURCE_SYSTEM_MEMORY : EFI_RESOURCE_MEMORY_RESERVED; >=20 > + // >=20 > + // Skip everything not known to be usable DRAM. >=20 > + // It will be added later. >=20 > + // >=20 > + if (MemoryMapEntry->Type !=3D E820_RAM && MemoryMapEntry->Type !=3D > E820_ACPI) { >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + Type =3D EFI_RESOURCE_SYSTEM_MEMORY; >=20 > Base =3D MemoryMapEntry->Base; >=20 > Size =3D MemoryMapEntry->Size; >=20 >=20 >=20 > @@ -40,7 +200,7 @@ MemInfoCallback ( > EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | >=20 > EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE; >=20 >=20 >=20 > - if (Base >=3D BASE_4GB ) { >=20 > + if (Base >=3D BASE_4GB) { >=20 > // Remove tested attribute to avoid DXE core to dispatch driver to m= emory > above 4GB >=20 > Attribue &=3D ~EFI_RESOURCE_ATTRIBUTE_TESTED; >=20 > } >=20 > @@ -48,6 +208,10 @@ MemInfoCallback ( > BuildResourceDescriptorHob (Type, Attribue, > (EFI_PHYSICAL_ADDRESS)Base, Size); >=20 > DEBUG ((DEBUG_INFO , "buildhob: base =3D 0x%lx, size =3D 0x%lx, type = =3D > 0x%x\n", Base, Size, Type)); >=20 >=20 >=20 > + if (MemoryMapEntry->Type =3D=3D E820_ACPI) { >=20 > + BuildMemoryAllocationHob (Base, Size, EfiACPIReclaimMemory); >=20 > + } >=20 > + >=20 > return RETURN_SUCCESS; >=20 > } >=20 >=20 >=20 > @@ -236,7 +400,16 @@ BuildHobFromBl ( > EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *NewGfxDeviceInfo; >=20 >=20 >=20 > // >=20 > - // Parse memory info and build memory HOBs >=20 > + // First find TOLUD >=20 > + // >=20 > + Status =3D ParseMemoryInfo (FindToludCallback, NULL); >=20 > + if (EFI_ERROR(Status)) { >=20 > + return Status; >=20 > + } >=20 > + DEBUG ((DEBUG_INFO , "Assuming TOLUD =3D 0x%x\n", > TopOfLowerUsableDram)); >=20 > + >=20 > + // >=20 > + // Parse memory info and build memory HOBs for Usable RAM >=20 > // >=20 > Status =3D ParseMemoryInfo (MemInfoCallback, NULL); >=20 > if (EFI_ERROR(Status)) { >=20 > @@ -289,6 +462,14 @@ BuildHobFromBl ( > DEBUG ((DEBUG_INFO, "Create acpi board info guid hob\n")); >=20 > } >=20 >=20 >=20 > + // >=20 > + // Parse memory info and build memory HOBs for reserved DRAM and > MMIO >=20 > + // >=20 > + Status =3D ParseMemoryInfo (MemInfoCallbackMMIO, &AcpiBoardInfo); >=20 > + if (EFI_ERROR(Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > // >=20 > // Parse platform specific information. >=20 > // >=20 > diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h > b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h > index 2c84d6ed53..35ea23d202 100644 > --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h > +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h > @@ -38,6 +38,16 @@ > #define GET_OCCUPIED_SIZE(ActualSize, Alignment) \ >=20 > ((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & > ((Alignment) - 1))) >=20 >=20 >=20 > + >=20 > +#define E820_RAM 1 >=20 > +#define E820_RESERVED 2 >=20 > +#define E820_ACPI 3 >=20 > +#define E820_NVS 4 >=20 > +#define E820_UNUSABLE 5 >=20 > +#define E820_DISABLED 6 >=20 > +#define E820_PMEM 7 >=20 > +#define E820_UNDEFINED 8 >=20 > + >=20 > /** >=20 > Auto-generated function that calls the library constructors for all of= the > module's >=20 > dependent libraries. >=20 > -- > 2.30.2 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#76517): https://edk2.groups.io/g/devel/message/76517 > Mute This Topic: https://groups.io/mt/83555387/1781375 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [guo.dong@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20