From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.2055.1678125209452526499 for ; Mon, 06 Mar 2023 09:53:29 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DlK7aQ6U; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DDB906101F for ; Mon, 6 Mar 2023 17:53:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50DB3C433EF for ; Mon, 6 Mar 2023 17:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678125208; bh=cy+CjH11Ts8ycjllcs0eMfR5kGzBNciT1vVtZX7byeY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DlK7aQ6Ul7HeGuo+1CKFSdrYv/V62wMMk1bPbxs0pA9i+A6e8yZ/AoKSiVkZiLwX2 WUVcB8LjGuLjvIW6SAJ54+4rRvqYc3Xx+PRGTIC+KYz2/0CSVCPKGG6AuqTKw233Yb UqhDRjZsr8BXAj7P5FO+E1UWH0oU4sql9mBL3l8dsy+1hn6gE4Sx90keqLk1TmrGg2 Y7Z6i0fRo6Rs6ZtkaUUSYYKdtKNY8F7kePu9rbKdY5VXNHelhkVGvTuWWzPGFfb05M i5nTHzE0OmexHrk0tsJjlpZpblsYlsm+3GjiMUGtZkhEyBE270o/58haAJfrfedkwi MO5y5YISkVRlA== Received: by mail-lj1-f175.google.com with SMTP id z42so10506125ljq.13 for ; Mon, 06 Mar 2023 09:53:28 -0800 (PST) X-Gm-Message-State: AO0yUKXYAM+mLUlEBmQEG0Buzso54piPyHRSXp2VXP8AAQ+fYpeKQ8NF q+YzopOIKqbZIOLfFUlFqc4MCmXpZQnLG5Kxfb8= X-Google-Smtp-Source: AK7set+fOKfwW82R8oJXQ5UObf1EuHQrVSz5pGxYKn+SRr9m3xPQwtgNuZqOK2z0Kmqv6iVKb5h2ZA4iZCtA/iXpIbI= X-Received: by 2002:a2e:8341:0:b0:293:4ba5:f626 with SMTP id l1-20020a2e8341000000b002934ba5f626mr6102276ljh.2.1678125206372; Mon, 06 Mar 2023 09:53:26 -0800 (PST) MIME-Version: 1.0 References: <20230306173316.10319-1-tphan@ventanamicro.com> <20230306173316.10319-6-tphan@ventanamicro.com> In-Reply-To: <20230306173316.10319-6-tphan@ventanamicro.com> From: "Ard Biesheuvel" Date: Mon, 6 Mar 2023 18:53:15 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH 5/7] OvmfPkg/VirtNorFlashDxe: Not add memory space if it exists To: devel@edk2.groups.io, tphan@ventanamicro.com Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com Content-Type: text/plain; charset="UTF-8" On Mon, 6 Mar 2023 at 18:33, Tuan Phan wrote: > > The flash base address can be added to GCD before this driver run. > So only add it if it has not been done. > How do you end up in this situation? You cannot skip this registration, as it is required to get the region marked as EFI_MEMORY_RUNTIME, and without that, EFI variables will be broken when running under the OS. > Signed-off-by: Tuan Phan > --- > OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c | 25 +++++++++++++++-------- > 1 file changed, 16 insertions(+), 9 deletions(-) > > diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c > index f9a41f6aab0f..8875824f3333 100644 > --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c > +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c > @@ -372,10 +372,11 @@ NorFlashFvbInitialize ( > IN NOR_FLASH_INSTANCE *Instance > ) > { > - EFI_STATUS Status; > - UINT32 FvbNumLba; > - EFI_BOOT_MODE BootMode; > - UINTN RuntimeMmioRegionSize; > + EFI_STATUS Status; > + UINT32 FvbNumLba; > + EFI_BOOT_MODE BootMode; > + UINTN RuntimeMmioRegionSize; > + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc; > > DEBUG ((DEBUG_BLKIO, "NorFlashFvbInitialize\n")); > ASSERT ((Instance != NULL)); > @@ -390,13 +391,19 @@ NorFlashFvbInitialize ( > // is written as the base of the flash region (ie: Instance->DeviceBaseAddress) > RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size; > > - Status = gDS->AddMemorySpace ( > - EfiGcdMemoryTypeMemoryMappedIo, > + Status = gDS->GetMemorySpaceDescriptor ( > Instance->DeviceBaseAddress, > - RuntimeMmioRegionSize, > - EFI_MEMORY_UC | EFI_MEMORY_RUNTIME > + &Desc > ); > - ASSERT_EFI_ERROR (Status); > + if (Status == EFI_NOT_FOUND) { > + Status = gDS->AddMemorySpace ( > + EfiGcdMemoryTypeMemoryMappedIo, > + Instance->DeviceBaseAddress, > + RuntimeMmioRegionSize, > + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME > + ); > + ASSERT_EFI_ERROR (Status); > + } > > Status = gDS->SetMemorySpaceAttributes ( > Instance->DeviceBaseAddress, > -- > 2.25.1 > > > > ------------ > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#100754): https://edk2.groups.io/g/devel/message/100754 > Mute This Topic: https://groups.io/mt/97430554/1131722 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [ardb@kernel.org] > ------------ > >