]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/AcpiPlatformDxe/Xen.c
OvmfPkg/CpuHotplugSmm: complete root MMI handler for CPU hotplug
[mirror_edk2.git] / OvmfPkg / AcpiPlatformDxe / Xen.c
index d9bd2ef9d1311da0653fc875ff4dba25220e1a57..289ef971c4b89f36bfad1632b37e2c220066edbf 100644 (file)
@@ -4,79 +4,18 @@
   Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2012, Bei Guan <gbtju85@gmail.com>\r
 \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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\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
 \r
 #include "AcpiPlatform.h"\r
-#include <Library/HobLib.h>\r
-#include <Guid/XenInfo.h>\r
+#include <Library/BaseLib.h>\r
 \r
 #define XEN_ACPI_PHYSICAL_ADDRESS         0x000EA020\r
 #define XEN_BIOS_PHYSICAL_END             0x000FFFFF\r
 \r
 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *XenAcpiRsdpStructurePtr = NULL;\r
 \r
-/**\r
-  Calculates the checksum of the ACPI tables.\r
-\r
-  @param  Buffer    Address of the ACPI table.\r
-  @param  Size      Size of the ACPI table need to check.\r
-\r
-**/\r
-UINT8\r
-CalculateTableChecksum (\r
-  IN VOID       *Buffer,\r
-  IN UINTN      Size\r
-  )\r
-{\r
-  UINT8 Sum;\r
-  UINT8 *Ptr;\r
-\r
-  Sum = 0;\r
-  //\r
-  // Initialize pointer\r
-  //\r
-  Ptr = Buffer;\r
-\r
-  //\r
-  // Add all content of buffer\r
-  //\r
-  while ((Size--) != 0) {\r
-    Sum = (UINT8) (Sum + (*Ptr++));\r
-  }\r
-\r
-  return Sum;\r
-}\r
-\r
-/**\r
-  This function detects if OVMF is running on Xen.\r
-\r
-**/\r
-BOOLEAN\r
-XenDetected (\r
-  VOID\r
-  )\r
-{\r
-  EFI_HOB_GUID_TYPE         *GuidHob;\r
-\r
-  //\r
-  // See if a XenInfo HOB is available\r
-  //\r
-  GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);\r
-  if (GuidHob == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  return TRUE;\r
-}\r
-\r
 /**\r
   Get the address of Xen ACPI Root System Description Pointer (RSDP)\r
   structure.\r
@@ -97,10 +36,27 @@ GetXenAcpiRsdp (
   EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER   *RsdpStructurePtr;\r
   UINT8                                          *XenAcpiPtr;\r
   UINT8                                          Sum;\r
+  EFI_XEN_INFO                                   *XenInfo;\r
 \r
   //\r
   // Detect the RSDP structure\r
   //\r
+\r
+  //\r
+  // First look for PVH one\r
+  //\r
+  XenInfo = XenGetInfoHOB ();\r
+  ASSERT (XenInfo != NULL);\r
+  if (XenInfo->RsdpPvh != NULL) {\r
+    DEBUG ((DEBUG_INFO, "%a: Use ACPI RSDP table at 0x%p\n",\r
+      gEfiCallerBaseName, XenInfo->RsdpPvh));\r
+    *RsdpPtr = XenInfo->RsdpPvh;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Otherwise, look for the HVM one\r
+  //\r
   for (XenAcpiPtr = (UINT8*)(UINTN) XEN_ACPI_PHYSICAL_ADDRESS;\r
        XenAcpiPtr < (UINT8*)(UINTN) XEN_BIOS_PHYSICAL_END;\r
        XenAcpiPtr += 0x10) {\r
@@ -113,8 +69,8 @@ GetXenAcpiRsdp (
       // RSDP ACPI 1.0 checksum for 1.0/2.0/3.0 table.\r
       // This is only the first 20 bytes of the structure\r
       //\r
-      Sum = CalculateTableChecksum (\r
-              RsdpStructurePtr,\r
+      Sum = CalculateSum8 (\r
+              (CONST UINT8 *)RsdpStructurePtr,\r
               sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER)\r
               );\r
       if (Sum != 0) {\r
@@ -125,8 +81,8 @@ GetXenAcpiRsdp (
         //\r
         // RSDP ACPI 2.0/3.0 checksum, this is the entire table\r
         //\r
-        Sum = CalculateTableChecksum (\r
-                RsdpStructurePtr,\r
+        Sum = CalculateSum8 (\r
+                (CONST UINT8 *)RsdpStructurePtr,\r
                 sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER)\r
                 );\r
         if (Sum != 0) {\r
@@ -195,12 +151,12 @@ InstallXenTables (
   }\r
 \r
   //\r
-  // If XSDT table is find, just install its tables. \r
+  // If XSDT table is find, just install its tables.\r
   // Otherwise, try to find and install the RSDT tables.\r
   //\r
   if (XenAcpiRsdpStructurePtr->XsdtAddress) {\r
     //\r
-    // Retrieve the addresses of XSDT and \r
+    // Retrieve the addresses of XSDT and\r
     // calculate the number of its table entries.\r
     //\r
     Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN)\r
@@ -219,7 +175,7 @@ InstallXenTables (
       CurrentTableEntry = (VOID *) ((UINT8 *) Xsdt +\r
                             sizeof (EFI_ACPI_DESCRIPTION_HEADER) +\r
                             Index * sizeof (UINT64));\r
-      CurrentTablePointer = *(UINT64 *)CurrentTableEntry;\r
+      CurrentTablePointer = (UINTN) *(UINT64 *)CurrentTableEntry;\r
       CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTablePointer;\r
 \r
       //\r
@@ -256,7 +212,7 @@ InstallXenTables (
     Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN)\r
              XenAcpiRsdpStructurePtr->RsdtAddress;\r
     NumberOfTableEntries = (Rsdt->Length -\r
-                             sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / \r
+                             sizeof (EFI_ACPI_DESCRIPTION_HEADER)) /\r
                              sizeof (UINT32);\r
 \r
     //\r
@@ -332,8 +288,15 @@ InstallXenTables (
   }\r
 \r
   //\r
-  // Install DSDT table.\r
+  // Install DSDT table. If we reached this point without finding the DSDT,\r
+  // then we're out of sync with the hypervisor, and cannot continue.\r
   //\r
+  if (DsdtTable == NULL) {\r
+    DEBUG ((DEBUG_ERROR, "%a: no DSDT found\n", __FUNCTION__));\r
+    ASSERT (FALSE);\r
+    CpuDeadLoop ();\r
+  }\r
+\r
   Status = InstallAcpiTable (\r
              AcpiProtocol,\r
              DsdtTable,\r