]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: Add AcpiPlatformDxe
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 May 2012 23:15:00 +0000 (23:15 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 May 2012 23:15:00 +0000 (23:15 +0000)
This driver is currently a direct copy of
MdeModulePkg/Universal/Acpi/AcpiPlatformDxe.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13384 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c [new file with mode: 0644]
OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf [new file with mode: 0644]
OvmfPkg/OvmfPkgIa32.dsc
OvmfPkg/OvmfPkgIa32.fdf
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgIa32X64.fdf
OvmfPkg/OvmfPkgX64.dsc
OvmfPkg/OvmfPkgX64.fdf

diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
new file mode 100644 (file)
index 0000000..44bdd94
--- /dev/null
@@ -0,0 +1,260 @@
+/** @file\r
+  Sample ACPI Platform Driver\r
+\r
+  Copyright (c) 2008 - 2011, 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
+  http://opensource.org/licenses/bsd-license.php\r
+\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
+#include <Protocol/AcpiTable.h>\r
+#include <Protocol/FirmwareVolume2.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <IndustryStandard/Acpi.h>\r
+\r
+/**\r
+  Locate the first instance of a protocol.  If the protocol requested is an\r
+  FV protocol, then it will return the first FV that contains the ACPI table\r
+  storage file.\r
+\r
+  @param  Instance      Return pointer to the first instance of the protocol\r
+\r
+  @return EFI_SUCCESS           The function completed successfully.\r
+  @return EFI_NOT_FOUND         The protocol could not be located.\r
+  @return EFI_OUT_OF_RESOURCES  There are not enough resources to find the protocol.\r
+\r
+**/\r
+EFI_STATUS\r
+LocateFvInstanceWithTables (\r
+  OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_HANDLE                    *HandleBuffer;\r
+  UINTN                         NumberOfHandles;\r
+  EFI_FV_FILETYPE               FileType;\r
+  UINT32                        FvStatus;\r
+  EFI_FV_FILE_ATTRIBUTES        Attributes;\r
+  UINTN                         Size;\r
+  UINTN                         Index;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;\r
+\r
+  FvStatus = 0;\r
+\r
+  //\r
+  // Locate protocol.\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                   ByProtocol,\r
+                   &gEfiFirmwareVolume2ProtocolGuid,\r
+                   NULL,\r
+                   &NumberOfHandles,\r
+                   &HandleBuffer\r
+                   );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Defined errors at this time are not found and out of resources.\r
+    //\r
+    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
+    // This should not fail because of LocateHandleBuffer\r
+    //\r
+    Status = gBS->HandleProtocol (\r
+                     HandleBuffer[Index],\r
+                     &gEfiFirmwareVolume2ProtocolGuid,\r
+                     (VOID**) &FvInstance\r
+                     );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // See if it has the ACPI storage file\r
+    //\r
+    Status = FvInstance->ReadFile (\r
+                           FvInstance,\r
+                           (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r
+                           NULL,\r
+                           &Size,\r
+                           &FileType,\r
+                           &Attributes,\r
+                           &FvStatus\r
+                           );\r
+\r
+    //\r
+    // If we found it, then we are done\r
+    //\r
+    if (Status == EFI_SUCCESS) {\r
+      *Instance = FvInstance;\r
+      break;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Our exit status is determined by the success of the previous operations\r
+  // If the protocol was found, Instance already points to it.\r
+  //\r
+\r
+  //\r
+  // Free any allocated buffers\r
+  //\r
+  gBS->FreePool (HandleBuffer);\r
+\r
+  return Status;\r
+}\r
+\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
+\r
+  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);\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
+\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
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AcpiPlatformEntryPoint (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\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
+\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
+  }\r
+\r
+  //\r
+  // Locate the firmware volume protocol\r
+  //\r
+  Status = LocateFvInstanceWithTables (&FwVol);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Read tables from the storage file.\r
+  //\r
+  while (Status == EFI_SUCCESS) {\r
+\r
+    Status = FwVol->ReadSection (\r
+                      FwVol,\r
+                      (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r
+                      EFI_SECTION_RAW,\r
+                      Instance,\r
+                      (VOID**) &CurrentTable,\r
+                      &Size,\r
+                      &FvStatus\r
+                      );\r
+    if (!EFI_ERROR(Status)) {\r
+      //\r
+      // Add the table\r
+      //\r
+      TableHandle = 0;\r
+\r
+      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
+\r
+      //\r
+      // Free memory allocated by ReadSection\r
+      //\r
+      gBS->FreePool (CurrentTable);\r
+\r
+      if (EFI_ERROR(Status)) {\r
+        return EFI_ABORTED;\r
+      }\r
+\r
+      //\r
+      // Increment the instance\r
+      //\r
+      Instance++;\r
+      CurrentTable = NULL;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
new file mode 100644 (file)
index 0000000..1034a0a
--- /dev/null
@@ -0,0 +1,53 @@
+## @file\r
+#  Sample ACPI Platform Driver\r
+#\r
+#  Copyright (c) 2008 - 2010, 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
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = AcpiPlatform\r
+  FILE_GUID                      = cb933912-df8f-4305-b1f9-7b44fa11395c\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = AcpiPlatformEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  AcpiPlatform.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  DxeServicesLib\r
+  PcdLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+\r
+[Protocols]\r
+  gEfiAcpiTableProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile\r
+\r
+[Depex]\r
+  gEfiAcpiTableProtocolGuid\r
+\r
index ffd9238a7194a3ac7344614e920bda816337ae33..f65efb0bd0253d9082b3532fcca98d390d843155 100644 (file)
   # ACPI Support\r
   #\r
   MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf\r
-  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
+  OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
   OvmfPkg/AcpiTables/AcpiTables.inf\r
 \r
   #\r
index eda00ce0974b9c9e6c5b5653650743ae1bc7f752..1b46149917e98fe209f5b25a42627a913664ab2e 100644 (file)
@@ -210,7 +210,7 @@ INF  MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
 INF  OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf\r
 \r
 INF  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf\r
-INF  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
+INF  OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
 INF  RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf\r
 \r
 INF  RuleOverride = BINARY FatBinPkg/EnhancedFatDxe/Fat.inf\r
index fc2677f024723662298b6576980fc1f1c0bab9ad..213854a16dc5811c4c38fa7e7c72f5134afc2557 100644 (file)
   # ACPI Support\r
   #\r
   MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf\r
-  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
+  OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
   OvmfPkg/AcpiTables/AcpiTables.inf\r
 \r
   #\r
index 7c98a6a2a8c731d71eae772b637573db1e0439d3..4bcc069f859dd9534afb451f30782c679a30369f 100644 (file)
@@ -210,7 +210,7 @@ INF  MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
 INF  OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf\r
 \r
 INF  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf\r
-INF  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
+INF  OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
 INF  RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf\r
 \r
 INF  RuleOverride = BINARY USE = X64 FatBinPkg/EnhancedFatDxe/Fat.inf\r
index f2bd5a7a1fc8bf53976268415d0781d370df1ba2..ee33e83270c8a339313c58564e6288fc4288e364 100644 (file)
   # ACPI Support\r
   #\r
   MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf\r
-  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
+  OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
   OvmfPkg/AcpiTables/AcpiTables.inf\r
 \r
   #\r
index 490829844855241227b1d02794d8309ccdff8181..693174a9cdea4141500a81d6d9da5a8dd78ef8c1 100644 (file)
@@ -210,7 +210,7 @@ INF  MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
 INF  OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf\r
 \r
 INF  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf\r
-INF  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
+INF  OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf\r
 INF  RuleOverride=ACPITABLE OvmfPkg/AcpiTables/AcpiTables.inf\r
 \r
 INF  RuleOverride = BINARY FatBinPkg/EnhancedFatDxe/Fat.inf\r