Skip to content

Commit

Permalink
OvmfPkg/VirtNorFlashDxe: Not add memory space if it exists
Browse files Browse the repository at this point in the history
The flash base address can be added to GCD before this driver run.
So only add it if it has not been done.

Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
  • Loading branch information
tphan-ventana committed Apr 19, 2023
1 parent c422f02 commit b7387da
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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,
Expand Down

3 comments on commit b7387da

@andreiw
Copy link
Contributor

@andreiw andreiw commented on b7387da May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be hyperspecific about the "can be added to GCD before this driver run"? Is it today? When is it added and by what agent? IIRC Ard also had a question on this commit.

@andreiw
Copy link
Contributor

@andreiw andreiw commented on b7387da May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because of 8193fe8#diff-cf3a936c9de796c88588a889401935f9e29b573d02b6bd106220641bbae22f98R143? And what happens if you don't call AddIoMemoryBaseSizeHob in the PrePi SEC?

@pttuan
Copy link

@pttuan pttuan commented on b7387da May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. I recall, it is RuntimeDxe accessing FLASH address before the VirtNorFlashDxe run

Please sign in to comment.