From nobody Sun May 5 14:54:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84491+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84491+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1638946949; cv=none; d=zohomail.com; s=zohoarc; b=WqBL++w1OjVuJD3FM1EfhFF7TKI1mL+yFyiR+W1BjiTpVySkacUEqfB9XFt2XWs10E1H5VBMhiTkA2XHG1prjr54oIVJhNDnWgXJ23lkE2otpxCXVhWuF0td3zbLoBh2ii6QeZVeEZuk3TFTxp3voQxT0Iy5o40N/BOAcgC0z3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638946949; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=p/QtVojAxomzxuUqLx85hdZe7Mwejj2BDGkQMvCZqoQ=; b=DRYGM6+z2XdfFfoCjD7XsEQ01c21ktExvUjTR49d5MEmc4ufDB8BYXF6oUyUy8RReH4NKFtEl3tpOcfR/rWeMU36RsZV2RS0g/y0eZ0ShEpQ0KBvcKe9UnQqyLZsFN+X/DfImeWS2Nb9e39VlMOlpsDWvsgbxOXdNGKgaWX8LOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84491+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16389469494821013.8951740729377; Tue, 7 Dec 2021 23:02:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Lx8RYY1788612xVSYMEna11C; Tue, 07 Dec 2021 23:02:27 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web09.9158.1638946946306653074 for ; Tue, 07 Dec 2021 23:02:27 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-20--d22WovXN_ShOL5oDFK4fw-1; Wed, 08 Dec 2021 02:02:20 -0500 X-MC-Unique: -d22WovXN_ShOL5oDFK4fw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A24410144E9; Wed, 8 Dec 2021 07:02:19 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D00AB1F3; Wed, 8 Dec 2021 07:01:47 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1BAD41800094; Wed, 8 Dec 2021 08:01:46 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ard Biesheuvel , Pawel Polawski , Jordan Justen , Jiewen Yao , Gerd Hoffmann Subject: [edk2-devel] [PATCH v4 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements Date: Wed, 8 Dec 2021 08:01:44 +0100 Message-Id: <20211208070146.1239368-2-kraxel@redhat.com> In-Reply-To: <20211208070146.1239368-1-kraxel@redhat.com> References: <20211208070146.1239368-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: 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,kraxel@redhat.com X-Gm-Message-State: VO1MBLsgIXduxMBYWB9SqVm8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1638946947; bh=hgth9TqcZXhPttkBrt3wJJ+Nf66vnd3KTN0M4kMGsx0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=MGE0GAduiGgjXkwPbX+vPIAtp0GbU1FV1Mc3/0Cpx+ZfcFPKYerp1hW82exaXfFnGck /n3z2t+MYNPyld80XA5IRdbs/8WUQACs+YwiwN80vvfTR23+sQ1P7LYEva9oGw8SCEQfN yBHcwZWxLLbqyw93W3Fy1koN6XEHD6K/dFg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1638946951898100002 Content-Type: text/plain; charset="utf-8" Add a bool parameter to ScanOrAdd64BitE820Ram to explicitly specify whenever ScanOrAdd64BitE820Ram should add HOBs for high memory (above 4G) or scan only. Also add a lowmem parameter so ScanOrAdd64BitE820Ram can report the memory size below 4G. This allows a more flexible usage of ScanOrAdd64BitE820Ram, a followup patch will use it for all memory detection. No functional change. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3593 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daude --- OvmfPkg/PlatformPei/MemDetect.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 3f59a1ac79f6..912889ab9b75 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -216,6 +216,8 @@ QemuUc32BaseInitialization ( STATIC EFI_STATUS ScanOrAdd64BitE820Ram ( + IN BOOLEAN AddHighHob, + OUT UINT64 *LowMemory OPTIONAL, OUT UINT64 *MaxAddress OPTIONAL ) { @@ -234,6 +236,10 @@ ScanOrAdd64BitE820Ram ( return EFI_PROTOCOL_ERROR; } =20 + if (LowMemory !=3D NULL) { + *LowMemory =3D 0; + } + if (MaxAddress !=3D NULL) { *MaxAddress =3D BASE_4GB; } @@ -249,10 +255,8 @@ ScanOrAdd64BitE820Ram ( E820Entry.Length, E820Entry.Type )); - if ((E820Entry.Type =3D=3D EfiAcpiAddressRangeMemory) && - (E820Entry.BaseAddr >=3D BASE_4GB)) - { - if (MaxAddress =3D=3D NULL) { + if (E820Entry.Type =3D=3D EfiAcpiAddressRangeMemory) { + if (AddHighHob && (E820Entry.BaseAddr >=3D BASE_4GB)) { UINT64 Base; UINT64 End; =20 @@ -272,11 +276,13 @@ ScanOrAdd64BitE820Ram ( End )); } - } else { + } + + if (MaxAddress || LowMemory) { UINT64 Candidate; =20 Candidate =3D E820Entry.BaseAddr + E820Entry.Length; - if (Candidate > *MaxAddress) { + if (MaxAddress && (Candidate > *MaxAddress)) { *MaxAddress =3D Candidate; DEBUG (( DEBUG_VERBOSE, @@ -285,6 +291,16 @@ ScanOrAdd64BitE820Ram ( *MaxAddress )); } + + if (LowMemory && (Candidate > *LowMemory) && (Candidate < BASE_4GB= )) { + *LowMemory =3D Candidate; + DEBUG (( + DEBUG_VERBOSE, + "%a: LowMemory=3D0x%Lx\n", + __FUNCTION__, + *LowMemory + )); + } } } } @@ -369,7 +385,7 @@ GetFirstNonAddress ( // Otherwise, get the flat size of the memory above 4GB from the CMOS (w= hich // can only express a size smaller than 1TB), and add it to 4GB. // - Status =3D ScanOrAdd64BitE820Ram (&FirstNonAddress); + Status =3D ScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); if (EFI_ERROR (Status)) { FirstNonAddress =3D BASE_4GB + GetSystemMemorySizeAbove4gb (); } @@ -802,7 +818,7 @@ QemuInitializeRam ( // entries. Otherwise, create a single memory HOB with the flat >=3D4GB // memory size read from the CMOS. // - Status =3D ScanOrAdd64BitE820Ram (NULL); + Status =3D ScanOrAdd64BitE820Ram (TRUE, NULL, NULL); if (EFI_ERROR (Status) && (UpperMemorySize !=3D 0)) { AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); } --=20 2.33.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 (#84491): https://edk2.groups.io/g/devel/message/84491 Mute This Topic: https://groups.io/mt/87583845/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 14:54:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84493+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84493+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1638946979; cv=none; d=zohomail.com; s=zohoarc; b=MhczNoEN/hMe/2tYJ3RiF3aIwTkSBlp7bWiaAG2aPC9lwOBfs3Jn0+G6Lh/T0wHxcFk+RnOxhQVDRzAYyH5n8G8IqzIRZDlhGkYBwcqtsPOA+pGvr5xP2ibTtIoun9BH0ZJCYUyynTfFJQbXJ3AMvZRVD64hr1CeOdEI1RYm8hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638946979; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=fPWQs2XPll7PtX+dMB4zeXH2XOw7G3pChGBO6SyLdPc=; b=IWvKIbfP5A9oXHi51PI7JwMpyfiKoQ0+YX8JV5i2vPCU1eiUKZjaZPfQ7koGM6YClhjYGpkLExAUn1sIX0/vBfxcBPuBsbcq/uV8ZxKF3fEkq2L3p7No1KjuoLQcnG4BjLvl1pNfeVxAUidm62kjVJWX17Z+Y3LKmj5kOf2Lhyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84493+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163894697969420.404560768897; Tue, 7 Dec 2021 23:02:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5U7oYY1788612x9CTr1XSAk6; Tue, 07 Dec 2021 23:02:59 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web09.9163.1638946978671392265 for ; Tue, 07 Dec 2021 23:02:58 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-_ayRvrmbMzKkuTNwyA6d-g-1; Wed, 08 Dec 2021 02:02:54 -0500 X-MC-Unique: _ayRvrmbMzKkuTNwyA6d-g-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A5EE1006AA3; Wed, 8 Dec 2021 07:02:53 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3583710A3945; Wed, 8 Dec 2021 07:02:07 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 212CE18000B2; Wed, 8 Dec 2021 08:01:46 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ard Biesheuvel , Pawel Polawski , Jordan Justen , Jiewen Yao , Gerd Hoffmann Subject: [edk2-devel] [PATCH v4 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Date: Wed, 8 Dec 2021 08:01:45 +0100 Message-Id: <20211208070146.1239368-3-kraxel@redhat.com> In-Reply-To: <20211208070146.1239368-1-kraxel@redhat.com> References: <20211208070146.1239368-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: 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,kraxel@redhat.com X-Gm-Message-State: IsnGAOQyFUXTfC7mksbgFXIXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1638946979; bh=aL6g1Q4hnApttTTF1qaBVQCkJ78RQXUbmJ+m0vZ8irw=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=MOI4L61KJbBMN5J+kQ5bsCLeNxyZbRmwTzzwk6ox0RXq1Nh40K+cL8MERzQHMNjH64K gF279UC6prRG36fDXOuH704Irt16YA7+aaU0s3DpQLeD8ft23Xm6qgymw+vZEyJC8Z0DQ GSa1sI0on/LEj74BhTyreCQlsos4pFfu218= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1638946981689100001 Content-Type: text/plain; charset="utf-8" Prefer the e820 map provided via qemu firmware config interface for memory detection. Use rtc cmos only as fallback, which should be rarely needed these days as qemu supports etc/e820 since 2013. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3593 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daude --- OvmfPkg/PlatformPei/MemDetect.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 912889ab9b75..e0f2caa9cd3c 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -313,8 +313,15 @@ GetSystemMemorySizeBelow4gb ( VOID ) { - UINT8 Cmos0x34; - UINT8 Cmos0x35; + EFI_STATUS Status; + UINT64 LowerMemorySize =3D 0; + UINT8 Cmos0x34; + UINT8 Cmos0x35; + + Status =3D ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); + if ((Status =3D=3D EFI_SUCCESS) && (LowerMemorySize > 0)) { + return (UINT32)LowerMemorySize; + } =20 // // CMOS 0x34/0x35 specifies the system memory above 16 MB. @@ -769,7 +776,6 @@ QemuInitializeRam ( // Determine total memory size available // LowerMemorySize =3D GetSystemMemorySizeBelow4gb (); - UpperMemorySize =3D GetSystemMemorySizeAbove4gb (); =20 if (mBootMode =3D=3D BOOT_ON_S3_RESUME) { // @@ -819,8 +825,11 @@ QemuInitializeRam ( // memory size read from the CMOS. // Status =3D ScanOrAdd64BitE820Ram (TRUE, NULL, NULL); - if (EFI_ERROR (Status) && (UpperMemorySize !=3D 0)) { - AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); + if (EFI_ERROR (Status)) { + UpperMemorySize =3D GetSystemMemorySizeAbove4gb (); + if (UpperMemorySize !=3D 0) { + AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); + } } } =20 --=20 2.33.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 (#84493): https://edk2.groups.io/g/devel/message/84493 Mute This Topic: https://groups.io/mt/87583852/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 14:54:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84492+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84492+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1638946950; cv=none; d=zohomail.com; s=zohoarc; b=QVt+/NbjVoSDofK9QiVVRCBksacrZXQIQ2sUwuygg7TZawxl0MB73ZmiUA26rkgPWANZINaxUCWoSnl4uXk8WJgiJ4dY74bvbXHDR0zrKR7rnzcbQlIOF1WdRgLJcqcRcUlxMxudEGPAIs+PQ4kZkSjNww2+A/0tp2vr/0+0PW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638946950; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=kObldu/PxlsmfoZjDK+7Jk9YKogOPgaaBPmG0gY5H7k=; b=LTTrewc4gK5IWZKFzYKikXajOWa9vYhxNyJCgHiJ0tcF3arcpRymhJxSq8Z9zs1ji44okVajSoftsa5o0iJHUiB0rj3ALU3fAoj2nZLb43sTIc/3B1fPP4RuPFAdvGcTERTMusyz/uPC9OCIM4VlQ0/ECBpQA99sM83aJh8/5Vc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84492+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1638946950622877.6021672224495; Tue, 7 Dec 2021 23:02:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id eFBnYY1788612x0YqM5ucATw; Tue, 07 Dec 2021 23:02:30 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web12.8945.1638946946935128237 for ; Tue, 07 Dec 2021 23:02:27 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-487-gMmshOAYOM2raPr2bKo59w-1; Wed, 08 Dec 2021 02:02:22 -0500 X-MC-Unique: gMmshOAYOM2raPr2bKo59w-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B84781CCBA; Wed, 8 Dec 2021 07:02:21 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20C195BE0C; Wed, 8 Dec 2021 07:02:21 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2438C18003A5; Wed, 8 Dec 2021 08:01:46 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ard Biesheuvel , Pawel Polawski , Jordan Justen , Jiewen Yao , Gerd Hoffmann Subject: [edk2-devel] [PATCH v4 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos for memory detection Date: Wed, 8 Dec 2021 08:01:46 +0100 Message-Id: <20211208070146.1239368-4-kraxel@redhat.com> In-Reply-To: <20211208070146.1239368-1-kraxel@redhat.com> References: <20211208070146.1239368-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: 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,kraxel@redhat.com X-Gm-Message-State: 6GXbpb2mcypYKLt01z4VatQJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1638946950; bh=mUWXNQyplVh1Zyc1xEPeJbC3yM/A2h16BjV5i/WsAwc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UZvWinTFAVsOyPJRuXJ18ZD7ADHP+V8+2tOJ+YHaCMs907LFNcYN++tQO1yk0l+hpl2 UdXTgXdBF/o31RQAz9T3l8a1sEfCig6MM+bPKelTwjv01mXFJDGqAThSyEWlrXyaiUCmu uDGYSn86HVPE7pqJLoSKp3MC7HVTIdmSmUw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1638946952929100007 Content-Type: text/plain; charset="utf-8" Not needed for qemu 1.7 (released in 2013) and newer. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3593 Signed-off-by: Gerd Hoffmann Acked-by: Ard Biesheuvel --- OvmfPkg/PlatformPei/MemDetect.c | 59 +++------------------------------ 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index e0f2caa9cd3c..21b0b9af26a1 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -37,7 +37,6 @@ Module Name: #include =20 #include "Platform.h" -#include "Cmos.h" =20 UINT8 mPhysMemAddressWidth; =20 @@ -315,51 +314,11 @@ GetSystemMemorySizeBelow4gb ( { EFI_STATUS Status; UINT64 LowerMemorySize =3D 0; - UINT8 Cmos0x34; - UINT8 Cmos0x35; =20 Status =3D ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); - if ((Status =3D=3D EFI_SUCCESS) && (LowerMemorySize > 0)) { - return (UINT32)LowerMemorySize; - } - - // - // CMOS 0x34/0x35 specifies the system memory above 16 MB. - // * CMOS(0x35) is the high byte - // * CMOS(0x34) is the low byte - // * The size is specified in 64kb chunks - // * Since this is memory above 16MB, the 16MB must be added - // into the calculation to get the total memory size. - // - - Cmos0x34 =3D (UINT8)CmosRead8 (0x34); - Cmos0x35 =3D (UINT8)CmosRead8 (0x35); - - return (UINT32)(((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB); -} - -STATIC -UINT64 -GetSystemMemorySizeAbove4gb ( - ) -{ - UINT32 Size; - UINTN CmosIndex; - - // - // CMOS 0x5b-0x5d specifies the system memory above 4GB MB. - // * CMOS(0x5d) is the most significant size byte - // * CMOS(0x5c) is the middle size byte - // * CMOS(0x5b) is the least significant size byte - // * The size is specified in 64kb chunks - // - - Size =3D 0; - for (CmosIndex =3D 0x5d; CmosIndex >=3D 0x5b; CmosIndex--) { - Size =3D (UINT32)(Size << 8) + (UINT32)CmosRead8 (CmosIndex); - } - - return LShiftU64 (Size, 16); + ASSERT_EFI_ERROR (Status); + ASSERT (LowerMemorySize > 0); + return (UINT32)LowerMemorySize; } =20 /** @@ -389,12 +348,9 @@ GetFirstNonAddress ( // If QEMU presents an E820 map, then get the highest exclusive >=3D4GB = RAM // address from it. This can express an address >=3D 4GB+1TB. // - // Otherwise, get the flat size of the memory above 4GB from the CMOS (w= hich - // can only express a size smaller than 1TB), and add it to 4GB. - // Status =3D ScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); if (EFI_ERROR (Status)) { - FirstNonAddress =3D BASE_4GB + GetSystemMemorySizeAbove4gb (); + FirstNonAddress =3D BASE_4GB; } =20 // @@ -766,7 +722,6 @@ QemuInitializeRam ( ) { UINT64 LowerMemorySize; - UINT64 UpperMemorySize; MTRR_SETTINGS MtrrSettings; EFI_STATUS Status; =20 @@ -825,12 +780,6 @@ QemuInitializeRam ( // memory size read from the CMOS. // Status =3D ScanOrAdd64BitE820Ram (TRUE, NULL, NULL); - if (EFI_ERROR (Status)) { - UpperMemorySize =3D GetSystemMemorySizeAbove4gb (); - if (UpperMemorySize !=3D 0) { - AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); - } - } } =20 // --=20 2.33.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 (#84492): https://edk2.groups.io/g/devel/message/84492 Mute This Topic: https://groups.io/mt/87583846/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-