From mboxrd@z Thu Jan 1 00:00:00 1970 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.535.1631804644618736797 for ; Thu, 16 Sep 2021 08:04:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hNdI2XBx; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631804643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LiMkDLS6zdXB2G8Y9Mm1p72HZX0oWWYIFg77vIEmL4Q=; b=hNdI2XBxisdO0msfjZnSpPZozQ8zlU0p+H+uVoIBv2H5Y++tb4DU80Z3bNrwzz4eh0W5+n vHRGB9qk2Zt+l2LW0ycEaA9ZmdC/Xf4Lin+SONJ8g1sDCiplNpQ+Kpf+OBIeXFMY3OEVtr LCIKuMgyZFwPHcxpgWbDk8F2QCGp91w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-EtP-8aKhP_WQCo10WPvmiA-1; Thu, 16 Sep 2021 11:03:59 -0400 X-MC-Unique: EtP-8aKhP_WQCo10WPvmiA-1 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 4328F10059CD; Thu, 16 Sep 2021 15:03:58 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D250100164A; Thu, 16 Sep 2021 15:03:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 319AD18000B2; Thu, 16 Sep 2021 17:03:52 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Philippe Mathieu-Daude , Jiewen Yao , Jordan Justen , Ard Biesheuvel , Gerd Hoffmann Subject: [PATCH v3 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements Date: Thu, 16 Sep 2021 17:03:50 +0200 Message-Id: <20210916150352.2662317-2-kraxel@redhat.com> In-Reply-To: <20210916150352.2662317-1-kraxel@redhat.com> References: <20210916150352.2662317-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" 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=3593 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daude --- OvmfPkg/PlatformPei/MemDetect.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index 2c2c4641ec8a..500c1d4d5231 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -200,6 +200,8 @@ QemuUc32BaseInitialization ( STATIC EFI_STATUS ScanOrAdd64BitE820Ram ( + IN BOOLEAN AddHighHob, + OUT UINT64 *LowMemory OPTIONAL, OUT UINT64 *MaxAddress OPTIONAL ) { @@ -217,6 +219,9 @@ ScanOrAdd64BitE820Ram ( return EFI_PROTOCOL_ERROR; } + if (LowMemory != NULL) { + *LowMemory = 0; + } if (MaxAddress != NULL) { *MaxAddress = BASE_4GB; } @@ -232,9 +237,8 @@ ScanOrAdd64BitE820Ram ( E820Entry.Length, E820Entry.Type )); - if (E820Entry.Type == EfiAcpiAddressRangeMemory && - E820Entry.BaseAddr >= BASE_4GB) { - if (MaxAddress == NULL) { + if (E820Entry.Type == EfiAcpiAddressRangeMemory) { + if (AddHighHob && E820Entry.BaseAddr >= BASE_4GB) { UINT64 Base; UINT64 End; @@ -254,11 +258,12 @@ ScanOrAdd64BitE820Ram ( End )); } - } else { + } + if (MaxAddress || LowMemory) { UINT64 Candidate; Candidate = E820Entry.BaseAddr + E820Entry.Length; - if (Candidate > *MaxAddress) { + if (MaxAddress && Candidate > *MaxAddress) { *MaxAddress = Candidate; DEBUG (( DEBUG_VERBOSE, @@ -267,6 +272,15 @@ ScanOrAdd64BitE820Ram ( *MaxAddress )); } + if (LowMemory && Candidate > *LowMemory && Candidate < BASE_4GB) { + *LowMemory = Candidate; + DEBUG (( + DEBUG_VERBOSE, + "%a: LowMemory=0x%Lx\n", + __FUNCTION__, + *LowMemory + )); + } } } } @@ -353,7 +367,7 @@ GetFirstNonAddress ( // Otherwise, get the flat size of the memory above 4GB from the CMOS (which // can only express a size smaller than 1TB), and add it to 4GB. // - Status = ScanOrAdd64BitE820Ram (&FirstNonAddress); + Status = ScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); if (EFI_ERROR (Status)) { FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb (); } @@ -754,7 +768,7 @@ QemuInitializeRam ( // entries. Otherwise, create a single memory HOB with the flat >=4GB // memory size read from the CMOS. // - Status = ScanOrAdd64BitE820Ram (NULL); + Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL); if (EFI_ERROR (Status) && UpperMemorySize != 0) { AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); } -- 2.31.1