]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
[mirror_edk2.git] / OvmfPkg / EmuVariableFvbRuntimeDxe / Fvb.c
index c1f46a7d9d2fb66650ed8e1b26cfd84151bd423a..dec6d4af50df8eee1b4424b542ffb3eb217f0d6c 100644 (file)
@@ -2,7 +2,7 @@
   Firmware Block Services to support emulating non-volatile variables\r
   by pretending that a memory buffer is storage for the NV variables.\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -655,14 +655,17 @@ InitializeFvAndVariableStoreHeaders (
       0,\r
 \r
       // UINT8                     Reserved[1];\r
-      0,\r
+      {0},\r
 \r
       // UINT8                     Revision;\r
       EFI_FVH_REVISION,\r
 \r
       // EFI_FV_BLOCK_MAP_ENTRY    BlockMap[1];\r
-      { 2, // UINT32 NumBlocks;\r
-        EMU_FVB_BLOCK_SIZE  // UINT32 Length;\r
+      { \r
+        {\r
+          2, // UINT32 NumBlocks;\r
+          EMU_FVB_BLOCK_SIZE  // UINT32 Length;\r
+        }\r
       }\r
     },\r
     // EFI_FV_BLOCK_MAP_ENTRY     EndBlockMap;\r
@@ -721,14 +724,17 @@ InitializeFvAndVariableStoreHeaders (
       0,\r
 \r
       // UINT8                     Reserved[1];\r
-      0,\r
+      {0},\r
 \r
       // UINT8                     Revision;\r
       EFI_FVH_REVISION,\r
 \r
       // EFI_FV_BLOCK_MAP_ENTRY    BlockMap[1];\r
-      { 2, // UINT32 NumBlocks;\r
-        EMU_FVB_BLOCK_SIZE  // UINT32 Length;\r
+      {\r
+        {\r
+          2, // UINT32 NumBlocks;\r
+          EMU_FVB_BLOCK_SIZE  // UINT32 Length;\r
+        }\r
       }\r
     },\r
     // EFI_FV_BLOCK_MAP_ENTRY     EndBlockMap;\r
@@ -775,52 +781,6 @@ InitializeFvAndVariableStoreHeaders (
   Fv->Checksum = CalculateCheckSum16 (Ptr, Fv->HeaderLength);\r
 }\r
 \r
-\r
-/**\r
-  Initializes the Fault Tolerant Write data structure\r
-\r
-  This data structure is used by the Fault Tolerant Write driver.\r
-\r
-  @param[in]  Buffer - Location for the FTW data structure\r
-\r
-**/\r
-VOID\r
-InitializeFtwState (\r
-  IN  VOID   *Buffer\r
-  )\r
-{\r
-  EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *Hdr;\r
-  UINT32                                  TempCrc;\r
-  STATIC EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER DefaultFtw = {\r
-    EFI_SYSTEM_NV_DATA_FV_GUID, // EFI_GUID  Signature;\r
-    ERASED_UINT32,              // UINT32    Crc;\r
-    ERASED_BIT,                 // UINT8     WorkingBlockValid : 1;\r
-    ERASED_BIT,                 // UINT8     WorkingBlockInvalid : 1;\r
-    0,                          // UINT8     Reserved : 6;\r
-    { 0, 0, 0 },                // UINT8     Reserved3[3];\r
-    FTW_WRITE_QUEUE_SIZE        // UINT64    WriteQueueSize;\r
-  };\r
-\r
-  CopyMem (Buffer, (VOID*) &DefaultFtw, sizeof (DefaultFtw));\r
-\r
-  Hdr = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER*) Buffer;\r
-\r
-  //\r
-  // Calculate checksum.\r
-  //\r
-  // The Crc, WorkingBlockValid and WorkingBlockInvalid bits should\r
-  // be set to the erased state before computing the checksum.\r
-  //\r
-  gBS->CalculateCrc32 (Buffer, sizeof (DefaultFtw), &TempCrc);\r
-  Hdr->Crc = TempCrc;\r
-\r
-  //\r
-  // Mark as valid.\r
-  //\r
-  Hdr->WorkingBlockValid = NOT_ERASED_BIT;\r
-}\r
-\r
-\r
 /**\r
   Main entry point.\r
 \r
@@ -843,6 +803,7 @@ FvbInitialize (
   BOOLEAN                             Initialize;\r
   EFI_HANDLE                          Handle;\r
   EFI_PHYSICAL_ADDRESS                Address;\r
+  RETURN_STATUS                       PcdStatus;\r
 \r
   DEBUG ((EFI_D_INFO, "EMU Variable FVB Started\n"));\r
 \r
@@ -859,6 +820,12 @@ FvbInitialize (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {\r
+    DEBUG ((EFI_D_INFO, "Disabling EMU Variable FVB since "\r
+                        "flash variables appear to be supported.\n"));\r
+    return EFI_ABORTED;\r
+  }\r
+\r
   //\r
   // By default we will initialize the FV contents.  But, if\r
   // PcdEmuVariableNvStoreReserved is non-zero, then we will\r
@@ -896,22 +863,24 @@ FvbInitialize (
     SetMem (Ptr, EMU_FVB_SIZE, ERASED_UINT8);\r
     InitializeFvAndVariableStoreHeaders (Ptr);\r
   }\r
-  PcdSet64 (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN) Ptr);\r
+  PcdStatus = PcdSet64S (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN) Ptr);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
 \r
   //\r
   // Initialize the Fault Tolerant Write data area\r
   //\r
   SubPtr = (VOID*) ((UINT8*) Ptr + PcdGet32 (PcdVariableStoreSize));\r
-  if (Initialize) {\r
-    InitializeFtwState (SubPtr);\r
-  }\r
-  PcdSet32 (PcdFlashNvStorageFtwWorkingBase, (UINT32)(UINTN) SubPtr);\r
+  PcdStatus = PcdSet32S (PcdFlashNvStorageFtwWorkingBase,\r
+                (UINT32)(UINTN) SubPtr);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
 \r
   //\r
   // Initialize the Fault Tolerant Write spare block\r
   //\r
   SubPtr = (VOID*) ((UINT8*) Ptr + EMU_FVB_BLOCK_SIZE);\r
-  PcdSet32 (PcdFlashNvStorageFtwSpareBase, (UINT32)(UINTN) SubPtr);\r
+  PcdStatus = PcdSet32S (PcdFlashNvStorageFtwSpareBase,\r
+                (UINT32)(UINTN) SubPtr);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
 \r
   //\r
   // Setup FVB device path\r