]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
ArmPlatformPkg/NorFlashDxe: Fix coding mistakes that would prevent Runtime mode
[mirror_edk2.git] / ArmPlatformPkg / Drivers / NorFlashDxe / NorFlashDxe.c
index 7953b6c9f563441a27b38a0f9049f29b0dae7d6b..f6551253d1f7d653e5fd4040fd219b1d09051925 100644 (file)
@@ -1,6 +1,6 @@
 /** @file  NorFlashDxe.c\r
 \r
-  Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -72,7 +72,7 @@ NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {
     FvbEraseBlocks, // EraseBlocks\r
     NULL, //ParentHandle\r
   }, //  FvbProtoccol;\r
-\r
+  NULL, // FvbBuffer\r
   {\r
     {\r
       {\r
@@ -109,7 +109,7 @@ NorFlashCreateInstance (
 \r
   ASSERT(NorFlashInstance != NULL);\r
 \r
-  Instance = AllocateCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);\r
+  Instance = AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);\r
   if (Instance == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -123,11 +123,15 @@ NorFlashCreateInstance (
   Instance->Media.BlockSize = BlockSize;\r
   Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;\r
 \r
-  CopyGuid (&Instance->DevicePath.Vendor.Guid,NorFlashGuid);\r
+  CopyGuid (&Instance->DevicePath.Vendor.Guid, NorFlashGuid);\r
 \r
   if (SupportFvb) {\r
     Instance->SupportFvb = TRUE;\r
     Instance->Initialize = NorFlashFvbInitialize;\r
+    Instance->FvbBuffer = AllocateRuntimePool (BlockSize);;\r
+    if (Instance->FvbBuffer == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &Instance->Handle,\r
@@ -137,7 +141,7 @@ NorFlashCreateInstance (
                   NULL\r
                   );\r
     if (EFI_ERROR(Status)) {\r
-      FreePool(Instance);\r
+      FreePool (Instance);\r
       return Status;\r
     }\r
   } else {\r
@@ -150,7 +154,7 @@ NorFlashCreateInstance (
                     NULL\r
                     );\r
     if (EFI_ERROR(Status)) {\r
-      FreePool(Instance);\r
+      FreePool (Instance);\r
       return Status;\r
     }\r
   }\r
@@ -340,8 +344,14 @@ NorFlashUnlockAndEraseSingleBlock (
   UINTN           Index;\r
   EFI_TPL         OriginalTPL;\r
 \r
-  // Raise TPL to TPL_HIGH to stop anyone from interrupting us.\r
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  if (!EfiAtRuntime ()) {\r
+    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.\r
+    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  } else {\r
+    // This initialization is only to prevent the compiler to complain about the\r
+    // use of uninitialized variables\r
+    OriginalTPL = TPL_HIGH_LEVEL;\r
+  }\r
 \r
   Index = 0;\r
   // The block erase might fail a first time (SW bug ?). Retry it ...\r
@@ -358,8 +368,10 @@ NorFlashUnlockAndEraseSingleBlock (
     DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));\r
   }\r
 \r
-  // Interruptions can resume.\r
-  gBS->RestoreTPL (OriginalTPL);\r
+  if (!EfiAtRuntime ()) {\r
+    // Interruptions can resume.\r
+    gBS->RestoreTPL (OriginalTPL);\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -581,8 +593,14 @@ NorFlashWriteSingleBlock (
   // Start writing from the first address at the start of the block\r
   WordAddress = BlockAddress;\r
 \r
-  // Raise TPL to TPL_HIGH to stop anyone from interrupting us.\r
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  if (!EfiAtRuntime ()) {\r
+    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.\r
+    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  } else {\r
+    // This initialization is only to prevent the compiler to complain about the\r
+    // use of uninitialized variables\r
+    OriginalTPL = TPL_HIGH_LEVEL;\r
+  }\r
 \r
   Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);\r
   if (EFI_ERROR(Status)) {\r
@@ -632,8 +650,10 @@ NorFlashWriteSingleBlock (
   }\r
 \r
 EXIT:\r
-  // Interruptions can resume.\r
-  gBS->RestoreTPL (OriginalTPL);\r
+  if (!EfiAtRuntime ()) {\r
+    // Interruptions can resume.\r
+    gBS->RestoreTPL (OriginalTPL);\r
+  }\r
 \r
   if (EFI_ERROR(Status)) {\r
     DEBUG((EFI_D_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));\r
@@ -797,7 +817,7 @@ NorFlashInitialise (
     return Status;\r
   }\r
 \r
-  mNorFlashInstances = AllocatePool (sizeof(NOR_FLASH_INSTANCE*) * NorFlashDeviceCount);\r
+  mNorFlashInstances = AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE*) * NorFlashDeviceCount);\r
 \r
   for (Index = 0; Index < NorFlashDeviceCount; Index++) {\r
     // Check if this NOR Flash device contain the variable storage region\r