<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 6, 2023 at 9:53 AM Ard Biesheuvel <<a href="mailto:ardb@kernel.org">ardb@kernel.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">On Mon, 6 Mar 2023 at 18:33, Tuan Phan <<a href="mailto:tphan@ventanamicro.com" target="_blank">tphan@ventanamicro.com</a>> wrote:<br>
><br>
> The flash base address can be added to GCD before this driver run.<br>
> So only add it if it has not been done.<br>
><br>
<br>
How do you end up in this situation?<br>
<br>
You cannot skip this registration, as it is required to get the region<br>
marked as EFI_MEMORY_RUNTIME, and without that, EFI variables will be<br>
broken when running under the OS.<br></blockquote><div><br></div><div>Ard,</div><div>The patch only skips AddMemorySpace if it is already done in the early SEC phase for RiscV platform.</div><div>The EFI_MEMORY_RUNTIME always be set in the next line with SetMemorySpaceAttributes.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
> Signed-off-by: Tuan Phan <<a href="mailto:tphan@ventanamicro.com" target="_blank">tphan@ventanamicro.com</a>><br>
> ---<br>
>  OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c | 25 +++++++++++++++--------<br>
>  1 file changed, 16 insertions(+), 9 deletions(-)<br>
><br>
> diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c<br>
> index f9a41f6aab0f..8875824f3333 100644<br>
> --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c<br>
> +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c<br>
> @@ -372,10 +372,11 @@ NorFlashFvbInitialize (<br>
>    IN NOR_FLASH_INSTANCE  *Instance<br>
>    )<br>
>  {<br>
> -  EFI_STATUS     Status;<br>
> -  UINT32         FvbNumLba;<br>
> -  EFI_BOOT_MODE  BootMode;<br>
> -  UINTN          RuntimeMmioRegionSize;<br>
> +  EFI_STATUS                      Status;<br>
> +  UINT32                          FvbNumLba;<br>
> +  EFI_BOOT_MODE                   BootMode;<br>
> +  UINTN                           RuntimeMmioRegionSize;<br>
> +  EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;<br>
><br>
>    DEBUG ((DEBUG_BLKIO, "NorFlashFvbInitialize\n"));<br>
>    ASSERT ((Instance != NULL));<br>
> @@ -390,13 +391,19 @@ NorFlashFvbInitialize (<br>
>    //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)<br>
>    RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;<br>
><br>
> -  Status = gDS->AddMemorySpace (<br>
> -                  EfiGcdMemoryTypeMemoryMappedIo,<br>
> +  Status = gDS->GetMemorySpaceDescriptor (<br>
>                    Instance->DeviceBaseAddress,<br>
> -                  RuntimeMmioRegionSize,<br>
> -                  EFI_MEMORY_UC | EFI_MEMORY_RUNTIME<br>
> +                  &Desc<br>
>                    );<br>
> -  ASSERT_EFI_ERROR (Status);<br>
> +  if (Status == EFI_NOT_FOUND) {<br>
> +    Status = gDS->AddMemorySpace (<br>
> +                    EfiGcdMemoryTypeMemoryMappedIo,<br>
> +                    Instance->DeviceBaseAddress,<br>
> +                    RuntimeMmioRegionSize,<br>
> +                    EFI_MEMORY_UC | EFI_MEMORY_RUNTIME<br>
> +                    );<br>
> +    ASSERT_EFI_ERROR (Status);<br>
> +  }<br>
><br>
>    Status = gDS->SetMemorySpaceAttributes (<br>
>                    Instance->DeviceBaseAddress,<br>
> --<br>
> 2.25.1<br>
><br>
><br>
><br>
> ------------<br>
> Groups.io Links: You receive all messages sent to this group.<br>
> View/Reply Online (#100754): <a href="https://edk2.groups.io/g/devel/message/100754" rel="noreferrer" target="_blank">https://edk2.groups.io/g/devel/message/100754</a><br>
> Mute This Topic: <a href="https://groups.io/mt/97430554/1131722" rel="noreferrer" target="_blank">https://groups.io/mt/97430554/1131722</a><br>
> Group Owner: <a href="mailto:devel%2Bowner@edk2.groups.io" target="_blank">devel+owner@edk2.groups.io</a><br>
> Unsubscribe: <a href="https://edk2.groups.io/g/devel/unsub" rel="noreferrer" target="_blank">https://edk2.groups.io/g/devel/unsub</a> [<a href="mailto:ardb@kernel.org" target="_blank">ardb@kernel.org</a>]<br>
> ------------<br>
><br>
><br>
</blockquote></div></div>


<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>


Groups.io Links:<p>


  
    You receive all messages sent to this group.
  
  


<p>
<a target="_blank" href="https://edk2.groups.io/g/devel/message/105276">View/Reply Online (#105276)</a> |


  

|

  <a target="_blank" href="https://groups.io/mt/97430554/1813853">Mute This Topic</a>

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>




<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>