--- /dev/null
+/** @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
--- /dev/null
+## @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