]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/XenPlatformPei: Grab RSDP from PVH guest start of day struct
authorAnthony PERARD <anthony.perard@citrix.com>
Tue, 13 Aug 2019 11:30:56 +0000 (12:30 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 21 Aug 2019 16:03:49 +0000 (18:03 +0200)
Check if there's a start of the day struct provided to PVH guest, save
the ACPI RSDP address for later.

This patch import import arch-x86/hvm/start_info.h from xen.git.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20190813113119.14804-13-anthony.perard@citrix.com>

OvmfPkg/Include/Guid/XenInfo.h
OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h [new file with mode: 0644]
OvmfPkg/XenPlatformPei/Xen.c
OvmfPkg/XenPlatformPei/XenPlatformPei.inf

index b052d618fd43014454515d2d85d279a2b31fa046..25743b388400bcce282f43c7fd6b96411961c4d3 100644 (file)
@@ -25,6 +25,10 @@ typedef struct {
   /// Hypervisor minor version.\r
   ///\r
   UINT16 VersionMinor;\r
+  ///\r
+  /// Pointer to the RSDP found in the hvm_start_info provided to a PVH guest\r
+  ///\r
+  VOID *RsdpPvh;\r
 } EFI_XEN_INFO;\r
 \r
 extern EFI_GUID gEfiXenInfoGuid;\r
diff --git a/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h b/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h
new file mode 100644 (file)
index 0000000..15708d6
--- /dev/null
@@ -0,0 +1,143 @@
+/*\r
+ * SPDX-License-Identifier: MIT\r
+ *\r
+ * Copyright (c) 2016, Citrix Systems, Inc.\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__\r
+#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__\r
+\r
+/*\r
+ * Start of day structure passed to PVH guests and to HVM guests in %ebx.\r
+ *\r
+ * NOTE: nothing will be loaded at physical address 0, so a 0 value in any\r
+ * of the address fields should be treated as not present.\r
+ *\r
+ *  0 +----------------+\r
+ *    | magic          | Contains the magic value XEN_HVM_START_MAGIC_VALUE\r
+ *    |                | ("xEn3" with the 0x80 bit of the "E" set).\r
+ *  4 +----------------+\r
+ *    | version        | Version of this structure. Current version is 1. New\r
+ *    |                | versions are guaranteed to be backwards-compatible.\r
+ *  8 +----------------+\r
+ *    | flags          | SIF_xxx flags.\r
+ * 12 +----------------+\r
+ *    | nr_modules     | Number of modules passed to the kernel.\r
+ * 16 +----------------+\r
+ *    | modlist_paddr  | Physical address of an array of modules\r
+ *    |                | (layout of the structure below).\r
+ * 24 +----------------+\r
+ *    | cmdline_paddr  | Physical address of the command line,\r
+ *    |                | a zero-terminated ASCII string.\r
+ * 32 +----------------+\r
+ *    | rsdp_paddr     | Physical address of the RSDP ACPI data structure.\r
+ * 40 +----------------+\r
+ *    | memmap_paddr   | Physical address of the (optional) memory map. Only\r
+ *    |                | present in version 1 and newer of the structure.\r
+ * 48 +----------------+\r
+ *    | memmap_entries | Number of entries in the memory map table. Zero\r
+ *    |                | if there is no memory map being provided. Only\r
+ *    |                | present in version 1 and newer of the structure.\r
+ * 52 +----------------+\r
+ *    | reserved       | Version 1 and newer only.\r
+ * 56 +----------------+\r
+ *\r
+ * The layout of each entry in the module structure is the following:\r
+ *\r
+ *  0 +----------------+\r
+ *    | paddr          | Physical address of the module.\r
+ *  8 +----------------+\r
+ *    | size           | Size of the module in bytes.\r
+ * 16 +----------------+\r
+ *    | cmdline_paddr  | Physical address of the command line,\r
+ *    |                | a zero-terminated ASCII string.\r
+ * 24 +----------------+\r
+ *    | reserved       |\r
+ * 32 +----------------+\r
+ *\r
+ * The layout of each entry in the memory map table is as follows:\r
+ *\r
+ *  0 +----------------+\r
+ *    | addr           | Base address\r
+ *  8 +----------------+\r
+ *    | size           | Size of mapping in bytes\r
+ * 16 +----------------+\r
+ *    | type           | Type of mapping as defined between the hypervisor\r
+ *    |                | and guest. See XEN_HVM_MEMMAP_TYPE_* values below.\r
+ * 20 +----------------|\r
+ *    | reserved       |\r
+ * 24 +----------------+\r
+ *\r
+ * The address and sizes are always a 64bit little endian unsigned integer.\r
+ *\r
+ * NB: Xen on x86 will always try to place all the data below the 4GiB\r
+ * boundary.\r
+ *\r
+ * Version numbers of the hvm_start_info structure have evolved like this:\r
+ *\r
+ * Version 0:  Initial implementation.\r
+ *\r
+ * Version 1:  Added the memmap_paddr/memmap_entries fields (plus 4 bytes of\r
+ *             padding) to the end of the hvm_start_info struct. These new\r
+ *             fields can be used to pass a memory map to the guest. The\r
+ *             memory map is optional and so guests that understand version 1\r
+ *             of the structure must check that memmap_entries is non-zero\r
+ *             before trying to read the memory map.\r
+ */\r
+#define XEN_HVM_START_MAGIC_VALUE 0x336ec578\r
+\r
+/*\r
+ * The values used in the type field of the memory map table entries are\r
+ * defined below and match the Address Range Types as defined in the "System\r
+ * Address Map Interfaces" section of the ACPI Specification. Please refer to\r
+ * section 15 in version 6.2 of the ACPI spec: http://uefi.org/specifications\r
+ */\r
+#define XEN_HVM_MEMMAP_TYPE_RAM       1\r
+#define XEN_HVM_MEMMAP_TYPE_RESERVED  2\r
+#define XEN_HVM_MEMMAP_TYPE_ACPI      3\r
+#define XEN_HVM_MEMMAP_TYPE_NVS       4\r
+#define XEN_HVM_MEMMAP_TYPE_UNUSABLE  5\r
+#define XEN_HVM_MEMMAP_TYPE_DISABLED  6\r
+#define XEN_HVM_MEMMAP_TYPE_PMEM      7\r
+\r
+/*\r
+ * C representation of the x86/HVM start info layout.\r
+ *\r
+ * The canonical definition of this layout is above, this is just a way to\r
+ * represent the layout described there using C types.\r
+ */\r
+struct hvm_start_info {\r
+    UINT32 magic;             /* Contains the magic value 0x336ec578       */\r
+                              /* ("xEn3" with the 0x80 bit of the "E" set).*/\r
+    UINT32 version;           /* Version of this structure.                */\r
+    UINT32 flags;             /* SIF_xxx flags.                            */\r
+    UINT32 nr_modules;        /* Number of modules passed to the kernel.   */\r
+    UINT64 modlist_paddr;     /* Physical address of an array of           */\r
+                              /* hvm_modlist_entry.                        */\r
+    UINT64 cmdline_paddr;     /* Physical address of the command line.     */\r
+    UINT64 rsdp_paddr;        /* Physical address of the RSDP ACPI data    */\r
+                              /* structure.                                */\r
+    /* All following fields only present in version 1 and newer */\r
+    UINT64 memmap_paddr;      /* Physical address of an array of           */\r
+                              /* hvm_memmap_table_entry.                   */\r
+    UINT32 memmap_entries;    /* Number of entries in the memmap table.    */\r
+                              /* Value will be zero if there is no memory  */\r
+                              /* map being provided.                       */\r
+    UINT32 reserved;          /* Must be zero.                             */\r
+};\r
+\r
+struct hvm_modlist_entry {\r
+    UINT64 paddr;             /* Physical address of the module.           */\r
+    UINT64 size;              /* Size of the module in bytes.              */\r
+    UINT64 cmdline_paddr;     /* Physical address of the command line.     */\r
+    UINT64 reserved;\r
+};\r
+\r
+struct hvm_memmap_table_entry {\r
+    UINT64 addr;              /* Base address of the memory region         */\r
+    UINT64 size;              /* Size of the memory region in bytes        */\r
+    UINT32 type;              /* Mapping type                              */\r
+    UINT32 reserved;          /* Must be zero for Version 1.               */\r
+};\r
+\r
+#endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */\r
index 5c7d7ddc1c4444334e44673e9db002b75cbebf24..b366139a0af08449951ef6220d5f747aa2348b6d 100644 (file)
@@ -25,6 +25,7 @@
 #include <IndustryStandard/E820.h>\r
 #include <Library/ResourcePublicationLib.h>\r
 #include <Library/MtrrLib.h>\r
+#include <IndustryStandard/Xen/arch-x86/hvm/start_info.h>\r
 \r
 #include "Platform.h"\r
 #include "Xen.h"\r
@@ -86,6 +87,7 @@ XenConnect (
   UINT32 XenVersion;\r
   EFI_XEN_OVMF_INFO *Info;\r
   CHAR8 Sig[sizeof (Info->Signature) + 1];\r
+  UINT32 *PVHResetVectorData;\r
 \r
   AsmCpuid (XenLeaf + 2, &TransferPages, &TransferReg, NULL, NULL);\r
   mXenInfo.HyperPages = AllocatePages (TransferPages);\r
@@ -121,6 +123,29 @@ XenConnect (
     mXenHvmloaderInfo = NULL;\r
   }\r
 \r
+  mXenInfo.RsdpPvh = NULL;\r
+\r
+  //\r
+  // Locate and use information from the start of day structure if we have\r
+  // booted via the PVH entry point.\r
+  //\r
+\r
+  PVHResetVectorData = (VOID *)(UINTN) PcdGet32 (PcdXenPvhStartOfDayStructPtr);\r
+  //\r
+  // That magic value is written in XenResetVector/Ia32/XenPVHMain.asm\r
+  //\r
+  if (PVHResetVectorData[1] == SIGNATURE_32 ('X', 'P', 'V', 'H')) {\r
+    struct hvm_start_info *HVMStartInfo;\r
+\r
+    HVMStartInfo = (VOID *)(UINTN) PVHResetVectorData[0];\r
+    if (HVMStartInfo->magic == XEN_HVM_START_MAGIC_VALUE) {\r
+      ASSERT (HVMStartInfo->rsdp_paddr != 0);\r
+      if (HVMStartInfo->rsdp_paddr != 0) {\r
+        mXenInfo.RsdpPvh = (VOID *)(UINTN)HVMStartInfo->rsdp_paddr;\r
+      }\r
+    }\r
+  }\r
+\r
   BuildGuidDataHob (\r
     &gEfiXenInfoGuid,\r
     &mXenInfo,\r
index d1265c365a2fdc5f95b36db6b1c41f374e51da7f..4d00206d09d2b57717ba3a2ce86fb1e5b0c64215 100644 (file)
@@ -84,6 +84,9 @@
   gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress\r
 \r
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize\r
+\r
 [FixedPcd]\r
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress\r
 \r