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.web12.379.1624385496716695976 for ; Tue, 22 Jun 2021 11:11:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=G1MgR1RT; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: guo.dong@intel.com) IronPort-SDR: BizCtp9mdrKws3tgsJlBjFBj3n+3IPZYrtJG+Z7Ur8DGASPCKjfQFHl5pal/twk4Pws/lKTVqx 9HmvLuHwhroA== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="204109808" X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="204109808" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 11:11:33 -0700 IronPort-SDR: 1ZYnpALlkWs5fAvtDOGaySsnXncIkc/IuSXTuUJ6rQtzAVlbAlcacLQVqbp6LfnF4YA31zPiEb hDWSmTFVSigQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="406414556" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga003.jf.intel.com with ESMTP; 22 Jun 2021 11:11:16 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 22 Jun 2021 11:11:15 -0700 Received: from fmsmsx606.amr.corp.intel.com (10.18.126.86) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 22 Jun 2021 11:11:15 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx606.amr.corp.intel.com (10.18.126.86) 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, 22 Jun 2021 11:11:14 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.169) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.4; Tue, 22 Jun 2021 11:11:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=haqZfcnz4VcUThD0dM6P9e9kvdZPLP6KjIQDQJhGiWgwGK75R7X6axPJsDvcdiLjTvx7HCRH68J9aB1HArRCxJs6OB/6MCrMyQ6fh9dMerpwj5/C1+K7dnbfCRSR3jbxPYM+qZOHXM3ujRpnsbWpRyj0LWtD2yGPh2WaNa6hlPBCxTQYGHSSHZ9/hs2vwRQRTUTf/rHg/SmdP/EsXfHbfqBlZd3js8gG3GP7RDTf/Hwt1GZ+OirI5eJlEizxnV1cESgdKAOcLWmCsz+c3yvRsJ1Ow+nqKLhzJyh6m75lQr8PwL9wqAv3KHEpkgNIrBhdO84dMvVdy2y4ZvH4WxPI1Q== 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=y3GGx7VWydlDobmi5rUjW1qsPfNrnoK5Tbg/aGAFzXQ=; b=ahcH/0Qt8CUh8r+ZdQDa2kam3wHX3YSt5vxT87+kt2r4qsFDr1aCIRNWwSORrdZv9bbg1XlrcS+2XMjHDwHdzmVFdJ/le/L1i4p9p0k8Feyk5kkxYEBUU3MbZYEHfdKdofvxicjqNctXV0YeIhrfr4/v3lKbLyCbrptMubIordiiHUYir2Q9kXRln9TGk9gBeKFhzakwDmnJTiEsJGZF3hPmRwhSFpmjKDAwqdFt8WC0hd/b2ZuaQRsDl/0NzGNZpFLx5tFCHRUGoyRN1AbsyS2Bb3ue+xFmclUr5/66DvBDuWoodn27Wc/Dzpd982yTxCrXjs8KOEHaiFlelvtDiw== 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=y3GGx7VWydlDobmi5rUjW1qsPfNrnoK5Tbg/aGAFzXQ=; b=G1MgR1RTUO5leSDKhxRjynUmhvuyAKK+ioZau0Hj0HeJa6d2VAsz5Dzovtr3VKhXDaKkR8iSlZoY9Mvqu5vuZtumpwtXZwRSDJRJmwgFgVyKT6Y9YlqGS5cHAhnrz18guUZkJ1FeijxUARXQCJxnUYm0vQZniYDIti3JnwFcj1k= Received: from BYAPR11MB3622.namprd11.prod.outlook.com (2603:10b6:a03:fe::30) by BYAPR11MB3061.namprd11.prod.outlook.com (2603:10b6:a03:83::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.23; Tue, 22 Jun 2021 18:11:12 +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.4242.023; Tue, 22 Jun 2021 18:11:12 +0000 From: "Guo Dong" To: Patrick Rudolph , "devel@edk2.groups.io" CC: "Ma, Maurice" , "You, Benjamin" Subject: Re: [PATCH v3] UefiPayloadPkg/UefiPayloadEntry: Improve bootloader memrange parsing Thread-Topic: [PATCH v3] UefiPayloadPkg/UefiPayloadEntry: Improve bootloader memrange parsing Thread-Index: AQHXZnTaqXyapkhIy0uyKURlWyEDzKsgVuWA Date: Tue, 22 Jun 2021 18:11:12 +0000 Message-ID: References: <20210621080937.76468-1-patrick.rudolph@9elements.com> In-Reply-To: <20210621080937.76468-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: 9elements.com; dkim=none (message not signed) header.d=none;9elements.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [68.104.146.79] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 330ac227-5a96-44bc-3950-08d935a91e46 x-ms-traffictypediagnostic: BYAPR11MB3061: 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: VRKBPdCh2v5M8XXk6H81lcaOX1spI1JU3OVuBkmXk9l0IIirQ5B4xb4DK4yQumOCW8lQCGKv/EvaA7/24qXViEmWMX7gLF81wy39b0qBe0IA7AUjrddqdFwltv9ChF/ewtJW5ZAs4d0IjRdmYC9hG+BdyEVMl8a/u+sA+ZpjKzpLDy8fsCTxQ09PuRwxocOB7IUkalTC60qEpA/jCvUNawdXv4Bl9MqJXGsL5lSfPvDUP82ihNumg9IEhYhbe2uISVdXk+ZRlYqJokDLS4NzthT0+yC0fdyQKX1jOuJVFGhaF/7bGNNsgrgOnMFeOVdLWU771lSicao5cqXl70JyKhxSYj9Pd/4hZMy47ulU5vOK0g5AJSdMWqYioQ5N48qj1RgIjUFrAhKYZoXVJBrkdTSBY3FqGzWRFuTsOQiMA6KBT4YtwxNJVz6RmkMJWmAXzOJFcWwnNgV6lphr5fMqies4Bmu+hCOzf77Onk9vFFeei5YdfcfrtTQzXnuhA17W+9PIapzlnlP8mbkmIKurr9U2PX4k9gRvVLKaG2U+SU0DhESvc7ljWGvxzIvehvyfYMRJ/ZPtBjqkyJmhxSpO9A6vlCca75/AjxEi3XxbR6i6bVunaYJT/Eo65XUzmkvPBMHZ9Ie+0SIv5w0A/6bYG/5xJD+ldPf/UGFBF3HkxJYG7ZFllEIDJ+IN093PyFI+XjTspRvDwz+jplxSruPUXIEBWC44ekTLm4OEQyIKVzKFEMrIBMbJ9BMt9O33kMN9yfaczjOvtqYfbsMfofUStQ== 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:(366004)(52536014)(66446008)(55016002)(64756008)(66556008)(122000001)(38100700002)(83380400001)(6506007)(66476007)(7696005)(33656002)(5660300002)(8936002)(54906003)(8676002)(110136005)(66946007)(966005)(30864003)(2906002)(186003)(26005)(107886003)(71200400001)(4326008)(86362001)(498600001)(9686003)(53546011)(76116006);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?7hc+JvOYPwrtBEqrbgUi9gMgkC0MLspj1wzTnTee6ilIClo2DCKJ8k6V4gNZ?= =?us-ascii?Q?l/FfZQpNr12Pkd4C8D7q/KN0CtClkOuwGxhWytDpOKlRienh/AQYB42lyyHb?= =?us-ascii?Q?yiyVoFfjRm9FwocyIhkhDRIhW6NjBaemvlGdcGXSU7oH1lb264p1EEkGAokg?= =?us-ascii?Q?DdZwxE0t9m1D77to5GQbAC1xXeyRPx938PS1hC4rbKEqoC+M6RQmG5pGPW5Q?= =?us-ascii?Q?p1GRRFs33wG84pBseTACdA0gKzbFlh5XfXO+CZ6scMm0Wm+zEIGB+nH11quA?= =?us-ascii?Q?mxv2WlB2D6QOnRveM1MKr8QW3kBXMcMZXUkbw1KlNW7GNBUSQEHkQjaLSntv?= =?us-ascii?Q?F5xgie5xchA7xsGh5SSzHoMEWjCV2htWxAkdHeStsqzBtkeOfBWadoJuUsQQ?= =?us-ascii?Q?OrImSz8PfWHwnU2tbJVsYNRrQscaRDiyjZSA27seDGSG2GqxdYFTh+Dwt6iV?= =?us-ascii?Q?bMxthfm7ppZ3bzMEJEjzuw+7IXIUpj4MewGfVqUwZQXUpAmp0+jkg0H/yRYl?= =?us-ascii?Q?MqrTw/LJMXce+8D/K25BcZpAfMyGvXKqxDVKeGYPmaHRG9PQA7XOj5RepNrB?= =?us-ascii?Q?M/aemoeymREzZlTBZKSTn8dfX4eJjaFElDL0ofgoQIdAji9bYz/fmdHbsKF0?= =?us-ascii?Q?mYiioNNNvpTUlr2uMlKAgDx39TCbjPqsT4Ib6i+jFzdFNMGfQWGOZODMjzh7?= =?us-ascii?Q?MC4Qlb3Gyq1QhX8ochDelvta4SbIUkqa3tdyQccgb7zozlb23On2oS7mE1qS?= =?us-ascii?Q?37Hly9ucCE1cUHPs+sT+tTeQM3jUd21SCExBO1gIUeigqYzlYcyBYLnmxLHL?= =?us-ascii?Q?EnGlNIUjfjq8f1N/dvQcGCz7CBSVb8WCz+RC5bOKHL6RmWSaQjmqfsQTuugV?= =?us-ascii?Q?2PgVUbBRiLVTdlxbvQLcZjG10u1wcIB/itaQVj9ZzLfMCBmnfD44YTRul/1K?= =?us-ascii?Q?Axo1UOIMWgR78VC8Awa677uqJdiUEOvgx8HGgYOn8VVXDGqXGMEylSifqFKl?= =?us-ascii?Q?g9NXcGGwzFN7T7aplWsOZPpatZy0Fh7IBiAAlHWpHdVqrcaCE2YxkuBrd3QQ?= =?us-ascii?Q?uuEUSaddl4IY6sjsZdjL+zYxFs0QAIfhatp89vwzqvPbn0KkdEvb5G2MrFu6?= =?us-ascii?Q?5l+Dke5oXgq1zq4FtTvws3+xQUYzaz/hYXhThALD/nfdgmcl4E9W1Q1INiIt?= =?us-ascii?Q?IZu7c0jrTNmXCp3iH7Fw5+X8zMEP1ZbE13e/j6fTCoXziC/axLnP7fNaKQNg?= =?us-ascii?Q?btAcweGjeJI8kAMAuKOOxhqveYr0jB92o8XZZu6LXhlPhoMmi4zwZ84q9xhk?= =?us-ascii?Q?P1VUFXA01PURdxPqtMxTHax5?= 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: 330ac227-5a96-44bc-3950-08d935a91e46 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jun 2021 18:11:12.2450 (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: a8hpLSrbM2JG4luVY28HZL7+cz8mZEjTMXTriCbNbimY7ZaxXxCuMNrGZbKYG0FAqnmLeTD/MRwXbVKHR+1X/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3061 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 Patch pushed @ https://github.com/tianocore/edk2/commit/1e5e58d39bb18a127e9= 78d6e46a7454430799e57 > -----Original Message----- > From: Patrick Rudolph > Sent: Monday, June 21, 2021 1:10 AM > To: devel@edk2.groups.io > Cc: Ma, Maurice ; Dong, Guo > ; You, Benjamin > Subject: [PATCH v3] UefiPayloadPkg/UefiPayloadEntry: Improve bootloader > memrange parsing >=20 > Currently several DXE crash due to invalid memory resource settings. > The PciHostBridgeDxe which expects the MMCONF and PCI Aperature > to be EfiMemoryMappedIO, but currently those regions are (partly) > mapped as EfiReservedMemoryType. >=20 > 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 the bootloader > provided > memory ranges. Memory types of RAM, ACPI and ACPI NVS below 4 GiB are > used > to increment TOLUD and reserved memory ranges touching TOLUD at the > base > are also assumed to be reserved DRAM, which increment TOLUD. >=20 > Then mark everything reserved below TOLUD as EfiReservedMemoryType > and > everything reserved above TOLUD as EfiMemoryMappedIO. >=20 > This fixes assertions seen in PciHostBridgeDxe. >=20 > Signed-off-by: Patrick Rudolph > --- > .../UefiPayloadEntry/UefiPayloadEntry.c | 190 +++++++++++++++++- > .../UefiPayloadEntry/UefiPayloadEntry.h | 10 + > 2 files changed, 197 insertions(+), 3 deletions(-) >=20 > diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > index 805f5448d9..04c58f776c 100644 > --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c > @@ -7,10 +7,159 @@ >=20 >=20 > #include "UefiPayloadEntry.h" >=20 >=20 >=20 > +STATIC UINT32 mTopOfLowerUsableDram =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 EFI_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 EFI_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 < mTopOfLowerUsableDram) { >=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) && > (MemoryMapEntry->Base >=3D mTopOfLowerUsableDram)) { >=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_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 EFI_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 EFI_SUCCESS Successfully updated > mTopOfLowerUsableDram. >=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_UNUSABLE) || (MemoryMapEntry- > >Type =3D=3D E820_DISABLED) || >=20 > + (MemoryMapEntry->Type =3D=3D E820_PMEM)) { >=20 > + return EFI_SUCCESS; >=20 > + } >=20 > + >=20 > + // >=20 > + // Skip resources above 4GiB >=20 > + // >=20 > + if ((MemoryMapEntry->Base + MemoryMapEntry->Size) > > 0x100000000ULL) { >=20 > + return EFI_SUCCESS; >=20 > + } >=20 > + >=20 > + if ((MemoryMapEntry->Type =3D=3D E820_RAM) || (MemoryMapEntry->Type > =3D=3D E820_ACPI) || >=20 > + (MemoryMapEntry->Type =3D=3D E820_NVS)) { >=20 > + // >=20 > + // It's usable DRAM. Update TOLUD. >=20 > + // >=20 > + if (mTopOfLowerUsableDram < (MemoryMapEntry->Base + > MemoryMapEntry->Size)) { >=20 > + mTopOfLowerUsableDram =3D (UINT32)(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 (mTopOfLowerUsableDram =3D=3D MemoryMapEntry->Base) { >=20 > + mTopOfLowerUsableDram =3D (UINT32)(MemoryMapEntry->Base + > MemoryMapEntry->Size); >=20 > + } >=20 > + } >=20 > + >=20 > + return EFI_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 +177,16 @@ 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 > + (MemoryMapEntry->Type !=3D E820_NVS)) { >=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 +198,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 +206,12 @@ 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 > + } else if (MemoryMapEntry->Type =3D=3D E820_NVS) { >=20 > + BuildMemoryAllocationHob (Base, Size, EfiACPIMemoryNVS); >=20 > + } >=20 > + >=20 > return RETURN_SUCCESS; >=20 > } >=20 >=20 >=20 > @@ -236,8 +400,19 @@ 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 > + DEBUG ((DEBUG_INFO , "Guessing Top of Lower Usable DRAM:\n")); >=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", > mTopOfLowerUsableDram)); >=20 > + >=20 > + // >=20 > + // Parse memory info and build memory HOBs for Usable RAM >=20 > // >=20 > + DEBUG ((DEBUG_INFO , "Building ResourceDescriptorHobs for usable > memory:\n")); >=20 > Status =3D ParseMemoryInfo (MemInfoCallback, NULL); >=20 > if (EFI_ERROR(Status)) { >=20 > return Status; >=20 > @@ -289,6 +464,15 @@ 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 > + DEBUG ((DEBUG_INFO , "Building ResourceDescriptorHobs for reserved > memory:\n")); >=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..4fd50e47cd 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