]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/NorFlashDxe: Fixed driver to support UEFI Runtime mode
authorOlivier Martin <olivier.martin@arm.com>
Tue, 8 Apr 2014 18:03:25 +0000 (18:03 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 Apr 2014 18:03:25 +0000 (18:03 +0000)
- Added the NOR Flash region to the Runtime UEFI Memory Mapped IO
- Caught the gEfiEventVirtualAddressChangeGuid event to fixup the NOR Flash pointers

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15438 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c

index f6551253d1f7d653e5fd4040fd219b1d09051925..a03bf5749e9fc56893525005684fc2cd75774ed4 100644 (file)
 \r
 #include "NorFlashDxe.h"\r
 \r
+STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent;\r
 \r
 //\r
 // Global variable declarations\r
 //\r
 NOR_FLASH_INSTANCE **mNorFlashInstances;\r
+UINT32               mNorFlashDeviceCount;\r
 \r
 NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {\r
   NOR_FLASH_SIGNATURE, // Signature\r
@@ -792,6 +794,50 @@ NorFlashReset (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Fixup internal data so that EFI can be call in virtual mode.\r
+  Call the passed in Child Notify event and convert any pointers in\r
+  lib to virtual mode.\r
+\r
+  @param[in]    Event   The Event that is being processed\r
+  @param[in]    Context Event Context\r
+**/\r
+VOID\r
+EFIAPI\r
+NorFlashVirtualNotifyEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  UINTN Index;\r
+\r
+  for (Index = 0; Index < mNorFlashDeviceCount; Index++) {\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->DeviceBaseAddress);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->RegionBaseAddress);\r
+\r
+    // Convert BlockIo protocol\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.Reset);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks);\r
+\r
+    // Convert Fvb\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Read);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes);\r
+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Write);\r
+\r
+    if (mNorFlashInstances[Index]->FvbBuffer != NULL) {\r
+      EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbBuffer);\r
+    }\r
+  }\r
+\r
+  return;\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 NorFlashInitialise (\r
@@ -802,7 +848,6 @@ NorFlashInitialise (
   EFI_STATUS              Status;\r
   UINT32                  Index;\r
   NOR_FLASH_DESCRIPTION*  NorFlashDevices;\r
-  UINT32                  NorFlashDeviceCount;\r
   BOOLEAN                 ContainVariableStorage;\r
 \r
   Status = NorFlashPlatformInitialization ();\r
@@ -811,15 +856,15 @@ NorFlashInitialise (
     return Status;\r
   }\r
 \r
-  Status = NorFlashPlatformGetDevices (&NorFlashDevices,&NorFlashDeviceCount);\r
+  Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount);\r
   if (EFI_ERROR(Status)) {\r
     DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n"));\r
     return Status;\r
   }\r
 \r
-  mNorFlashInstances = AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE*) * NorFlashDeviceCount);\r
+  mNorFlashInstances = AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE*) * mNorFlashDeviceCount);\r
 \r
-  for (Index = 0; Index < NorFlashDeviceCount; Index++) {\r
+  for (Index = 0; Index < mNorFlashDeviceCount; Index++) {\r
     // Check if this NOR Flash device contain the variable storage region\r
     ContainVariableStorage =\r
         (NorFlashDevices[Index].RegionBaseAddress <= PcdGet32 (PcdFlashNvStorageVariableBase)) &&\r
@@ -840,5 +885,18 @@ NorFlashInitialise (
     }\r
   }\r
 \r
+  //\r
+  // Register for the virtual address change event\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  NorFlashVirtualNotifyEvent,\r
+                  NULL,\r
+                  &gEfiEventVirtualAddressChangeGuid,\r
+                  &mNorFlashVirtualAddrChangeEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
index 424d63925bf0a78f5cc2b87514be0e38a0a128ab..e4d767bf9441d38718f4c2cea99b5b4d74ae2a50 100644 (file)
@@ -19,6 +19,8 @@
 #include <Base.h>\r
 #include <PiDxe.h>\r
 \r
+#include <Guid/EventGroup.h>\r
+\r
 #include <Protocol/BlockIo.h>\r
 #include <Protocol/FirmwareVolumeBlock.h>\r
 \r
index dddaa3c0f8fa7dee21baee4f3c0471bc0ea3c448..a2eb27e8f6c980efd9639a5b5824e2c1a0f5709f 100644 (file)
   UefiDriverEntryPoint\r
   UefiBootServicesTableLib\r
   UefiRuntimeLib\r
+  DxeServicesTableLib\r
 \r
 [Guids]\r
   gEfiSystemNvDataFvGuid\r
   gEfiVariableGuid\r
+  gEfiEventVirtualAddressChangeGuid\r
 \r
 [Protocols]\r
   gEfiBlockIoProtocolGuid\r
index b9230c1ee007c8f147bbb86b565e1b5b8a40b65e..84890cbfce43c7c1156553cefc759ba6b72af963 100644 (file)
@@ -20,6 +20,7 @@
 #include <Library/UefiLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
 #include <Guid/VariableFormat.h>\r
@@ -27,6 +28,8 @@
 \r
 #include "NorFlashDxe.h"\r
 \r
+STATIC EFI_EVENT mFvbVirtualAddrChangeEvent;\r
+STATIC UINTN     mFlashNvStorageVariableBase;\r
 \r
 ///\r
 /// The Firmware Volume Block Protocol is the low-level interface\r
@@ -301,7 +304,7 @@ FvbGetPhysicalAddress (
 \r
   ASSERT(Address != NULL);\r
 \r
-  *Address = PcdGet32 (PcdFlashNvStorageVariableBase);\r
+  *Address = mFlashNvStorageVariableBase;\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -745,6 +748,25 @@ EXIT:
   return Status;\r
 }\r
 \r
+/**\r
+  Fixup internal data so that EFI can be call in virtual mode.\r
+  Call the passed in Child Notify event and convert any pointers in\r
+  lib to virtual mode.\r
+\r
+  @param[in]    Event   The Event that is being processed\r
+  @param[in]    Context Event Context\r
+**/\r
+VOID\r
+EFIAPI\r
+FvbVirtualNotifyEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  EfiConvertPointer (0x0, (VOID**)&mFlashNvStorageVariableBase);\r
+  return;\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 NorFlashFvbInitialize (\r
@@ -754,10 +776,12 @@ NorFlashFvbInitialize (
   EFI_STATUS  Status;\r
   UINT32      FvbNumLba;\r
   EFI_BOOT_MODE BootMode;\r
+  UINTN       RuntimeMmioRegionSize;\r
 \r
   DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));\r
 \r
   Instance->Initialized = TRUE;\r
+  mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase);\r
 \r
   // Set the index of the first LBA for the FVB\r
   Instance->StartLba = (PcdGet32 (PcdFlashNvStorageVariableBase) - Instance->RegionBaseAddress) / Instance->Media.BlockSize;\r
@@ -789,5 +813,41 @@ NorFlashFvbInitialize (
       return Status;\r
     }\r
   }\r
+\r
+  //\r
+  // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME\r
+  //\r
+\r
+  // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory;\r
+  //       even if we only use the small block region at the top of the NOR Flash.\r
+  //       The reason is when the NOR Flash memory is set into program mode, the command\r
+  //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)\r
+  RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;\r
+\r
+  Status = gDS->AddMemorySpace (\r
+      EfiGcdMemoryTypeMemoryMappedIo,\r
+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
+      );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (\r
+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Register for the virtual address change event\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  FvbVirtualNotifyEvent,\r
+                  NULL,\r
+                  &gEfiEventVirtualAddressChangeGuid,\r
+                  &mFvbVirtualAddrChangeEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r