]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
[mirror_edk2.git] / OvmfPkg / AcpiPlatformDxe / AcpiPlatform.c
index 44bdd94fa8db68b16caced77f4165429ef4bd9cb..61166c65c33cd2c366b4b8d11df95f522bff5a43 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Sample ACPI Platform Driver\r
+  OVMF ACPI Platform Driver\r
 \r
-  Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2012, 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
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-**/ \r
-\r
-#include <PiDxe.h>\r
+**/\r
 \r
-#include <Protocol/AcpiTable.h>\r
-#include <Protocol/FirmwareVolume2.h>\r
+#include "AcpiPlatform.h"\r
 \r
-#include <Library/BaseLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
+EFI_STATUS\r
+EFIAPI\r
+InstallAcpiTable (\r
+  IN   EFI_ACPI_TABLE_PROTOCOL       *AcpiProtocol,\r
+  IN   VOID                          *AcpiTableBuffer,\r
+  IN   UINTN                         AcpiTableBufferSize,\r
+  OUT  UINTN                         *TableKey\r
+  )\r
+{\r
+  return AcpiProtocol->InstallAcpiTable (\r
+                         AcpiProtocol,\r
+                         AcpiTableBuffer,\r
+                         AcpiTableBufferSize,\r
+                         TableKey\r
+                         );\r
+}\r
 \r
-#include <IndustryStandard/Acpi.h>\r
 \r
 /**\r
   Locate the first instance of a protocol.  If the protocol requested is an\r
@@ -70,12 +78,9 @@ LocateFvInstanceWithTables (
     return Status;\r
   }\r
 \r
-\r
-\r
   //\r
   // Looking for FV with ACPI storage file\r
   //\r
-\r
   for (Index = 0; Index < NumberOfHandles; Index++) {\r
     //\r
     // Get the protocol on this handle\r
@@ -125,72 +130,41 @@ LocateFvInstanceWithTables (
 \r
 \r
 /**\r
-  This function calculates and updates an UINT8 checksum.\r
-\r
-  @param  Buffer          Pointer to buffer to checksum\r
-  @param  Size            Number of bytes to checksum\r
-\r
-**/\r
-VOID\r
-AcpiPlatformChecksum (\r
-  IN UINT8      *Buffer,\r
-  IN UINTN      Size\r
-  )\r
-{\r
-  UINTN ChecksumOffset;\r
+  Find ACPI tables in an FV and install them. \r
 \r
-  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);\r
+  This is now a fall-back path. Normally, we will search for tables provided\r
+  by the VMM first.\r
 \r
-  //\r
-  // Set checksum to 0 first\r
-  //\r
-  Buffer[ChecksumOffset] = 0;\r
-\r
-  //\r
-  // Update checksum value\r
-  //\r
-  Buffer[ChecksumOffset] = CalculateCheckSum8(Buffer, Size);\r
-}\r
+  If that fails, we use this function to load the ACPI tables from an FV. The\r
+  sources for the FV based tables is located under OvmfPkg/AcpiTables.\r
 \r
-\r
-/**\r
-  Entrypoint of Acpi Platform driver.\r
-\r
-  @param  ImageHandle\r
-  @param  SystemTable\r
-\r
-  @return EFI_SUCCESS\r
-  @return EFI_LOAD_ERROR\r
-  @return EFI_OUT_OF_RESOURCES\r
+  @param  AcpiTable     Protocol instance pointer    \r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-AcpiPlatformEntryPoint (\r
-  IN EFI_HANDLE         ImageHandle,\r
-  IN EFI_SYSTEM_TABLE   *SystemTable\r
+InstallOvmfFvTables (\r
+  IN  EFI_ACPI_TABLE_PROTOCOL     *AcpiTable\r
   )\r
 {\r
-  EFI_STATUS                     Status;\r
-  EFI_ACPI_TABLE_PROTOCOL        *AcpiTable;\r
-  EFI_FIRMWARE_VOLUME2_PROTOCOL  *FwVol;\r
-  INTN                           Instance;\r
-  EFI_ACPI_COMMON_HEADER         *CurrentTable;\r
-  UINTN                          TableHandle;\r
-  UINT32                         FvStatus;\r
-  UINTN                          TableSize;\r
-  UINTN                          Size;\r
+  EFI_STATUS                           Status;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL        *FwVol;\r
+  INTN                                 Instance;\r
+  EFI_ACPI_COMMON_HEADER               *CurrentTable;\r
+  UINTN                                TableHandle;\r
+  UINT32                               FvStatus;\r
+  UINTN                                TableSize;\r
+  UINTN                                Size;\r
+  EFI_ACPI_TABLE_INSTALL_ACPI_TABLE    TableInstallFunction;\r
 \r
   Instance     = 0;\r
   CurrentTable = NULL;\r
   TableHandle  = 0;\r
 \r
-  //\r
-  // Find the AcpiTable protocol\r
-  //\r
-  Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID**)&AcpiTable);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
+  if (QemuDetected ()) {\r
+    TableInstallFunction = QemuInstallAcpiTable;\r
+  } else {\r
+    TableInstallFunction = InstallAcpiTable;\r
   }\r
 \r
   //\r
@@ -214,7 +188,7 @@ AcpiPlatformEntryPoint (
                       &Size,\r
                       &FvStatus\r
                       );\r
-    if (!EFI_ERROR(Status)) {\r
+    if (!EFI_ERROR (Status)) {\r
       //\r
       // Add the table\r
       //\r
@@ -223,27 +197,22 @@ AcpiPlatformEntryPoint (
       TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;\r
       ASSERT (Size >= TableSize);\r
 \r
-      //\r
-      // Checksum ACPI table\r
-      //\r
-      AcpiPlatformChecksum ((UINT8*)CurrentTable, TableSize);\r
-\r
       //\r
       // Install ACPI table\r
       //\r
-      Status = AcpiTable->InstallAcpiTable (\r
-                            AcpiTable,\r
-                            CurrentTable,\r
-                            TableSize,\r
-                            &TableHandle\r
-                            );\r
+      Status = TableInstallFunction (\r
+                 AcpiTable,\r
+                 CurrentTable,\r
+                 TableSize,\r
+                 &TableHandle\r
+                 );\r
 \r
       //\r
       // Free memory allocated by ReadSection\r
       //\r
       gBS->FreePool (CurrentTable);\r
 \r
-      if (EFI_ERROR(Status)) {\r
+      if (EFI_ERROR (Status)) {\r
         return EFI_ABORTED;\r
       }\r
 \r
@@ -258,3 +227,35 @@ AcpiPlatformEntryPoint (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Effective entrypoint of Acpi Platform driver.\r
+\r
+  @param  ImageHandle\r
+  @param  SystemTable\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_LOAD_ERROR\r
+  @return EFI_OUT_OF_RESOURCES\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InstallAcpiTables (\r
+  IN   EFI_ACPI_TABLE_PROTOCOL       *AcpiTable\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+\r
+  if (XenDetected ()) {\r
+    Status = InstallXenTables (AcpiTable);\r
+  } else {\r
+    Status = InstallQemuFwCfgTables (AcpiTable);\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    Status = InstallOvmfFvTables (AcpiTable);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r