Skip to contentSkip to conversation

ArmPkg: allow HYP timer interrupt to be omitted

PATCH Superseded Ard Biesheuvel 5 participants 72 messages Jan 26, 2015 – Feb 3, 2015 34 messages not in the archive

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/29 ArmPkg: allow HYP timer interrupt to be omitted

The DT binding for the ARM generic timer describes the secure, non-secure, virtual and hypervisor timer interrupts, respectively. However, under virtualization, only the virtual timer is usable, and the device tree may omit the hypervisor timer interrupt. (Other timer interrupts cannot be omitted simply due to the fact that the virtual timer is listed third)

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPkg/Drivers/TimerDxe/TimerDxe.c                          | 14 +++++++++++---
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c |  6 +++---
 2 files changed, 14 insertions(+), 6 deletions(-)
ArmPkg/Drivers/TimerDxe/TimerDxe.c +11 -3
index d0a819fc2729..1169d426b255 100644
@@ -369,7 +369,8 @@ TimerInitialize (
 {
   EFI_HANDLE  Handle = NULL;
   EFI_STATUS  Status;
-  UINTN TimerCtrlReg;
+  UINTN       TimerCtrlReg;
+  UINT32      TimerHypIntrNum;
 
   if (ArmIsArchTimerImplemented () == 0) {
     DEBUG ((EFI_D_ERROR, "ARM Architectural Timer is not available in the CPU, hence cann't use this Driver \n"));
@@ -395,8 +396,15 @@ TimerInitialize (
   Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerVirtIntrNum), TimerInterruptHandler);
   ASSERT_EFI_ERROR (Status);
 
-  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerHypIntrNum), TimerInterruptHandler);
-  ASSERT_EFI_ERROR (Status);
+  //
+  // The hypervisor timer interrupt may be omitted by implementations that
+  // execute under virtualization.
+  //
+  TimerHypIntrNum = PcdGet32 (PcdArmArchTimerHypIntrNum);
+  if (TimerHypIntrNum != 0) {
+    Status = gInterrupt->RegisterInterruptSource (gInterrupt, TimerHypIntrNum, TimerInterruptHandler);
+    ASSERT_EFI_ERROR (Status);
+  }
 
   Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum), TimerInterruptHandler);
   ASSERT_EFI_ERROR (Status);
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +3 -3
index 751864d4db9c..1d44f9ba02b3 100644
@@ -274,7 +274,7 @@ InitializeVirtFdtDxe (
       //  hypervisor timers, in that order.
       //
       InterruptProp = fdt_getprop (DeviceTreeBase, Node, "interrupts", &Len);
-      ASSERT (Len == 48);
+      ASSERT (Len == 36 || Len == 48);
 
       SecIntrNum = fdt32_to_cpu (InterruptProp[0].Number)
                    + (InterruptProp[0].Type ? 16 : 0);
@@ -282,8 +282,8 @@ InitializeVirtFdtDxe (
                 + (InterruptProp[1].Type ? 16 : 0);
       VirtIntrNum = fdt32_to_cpu (InterruptProp[2].Number)
                     + (InterruptProp[2].Type ? 16 : 0);
-      HypIntrNum = fdt32_to_cpu (InterruptProp[3].Number)
-                   + (InterruptProp[3].Type ? 16 : 0);
+      HypIntrNum = Len < 48 ? 0 : fdt32_to_cpu (InterruptProp[3].Number)
+                                  + (InterruptProp[3].Type ? 16 : 0);
 
       DEBUG ((EFI_D_INFO, "Found Timer interrupts %d, %d, %d, %d\n",
         SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum));
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH v2 2/29 ArmPkg: allow patchable PCDs for memory, FD and FV addresses

In reply to a message not in the archive

In order to allow a runtime self relocating PrePi instance, change the allowable PCD types for the following PCDs:

gArmTokenSpaceGuid.PcdSystemMemoryBase
gArmTokenSpaceGuid.PcdSystemMemorySize
gArmTokenSpaceGuid.PcdFdBaseAddress
gArmTokenSpaceGuid.PcdFvBaseAddress

to include PcdsPatchableInModule. This makes the build system correctly distinguish fixed PCDs from PCDs whose value may be different from the assigned value at compile time.

Note that this only affects platforms that explicitly mark these PCDs as PatchableInModule in the DSC. All existing platforms that use FixedPcd will not be affected by this change.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPkg/ArmPkg.dec | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
ArmPkg/ArmPkg.dec +14 -11
index d7a4826d931a..b01de13e5f78 100644
@@ -93,14 +93,6 @@
   gArmTokenSpaceGuid.PcdSecureFvSize|0x0|UINT32|0x00000030
 
   #
-  # ARM Normal (or Non Secure) Firmware PCDs
-  #
-  gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
-  gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
-  gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
-  gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
-
-  #
   # ARM Hypervisor Firmware PCDs
   #
   gArmTokenSpaceGuid.PcdHypFdBaseAddress|0|UINT32|0x0000003A
@@ -127,6 +119,15 @@
   # Maximum file size for TFTP servers that do not support 'tsize' extension
   gArmTokenSpaceGuid.PcdMaxTftpFileSize|0x01000000|UINT32|0x00000000
 
+  #
+  # ARM Normal (or Non Secure) Firmware PCDs
+  #
+  gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
+  gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
+
+[PcdsFixedAtBuild.common, PcdsPatchableInModule.common]
+  gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
+  gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
 
 [PcdsFixedAtBuild.ARM]
   #
@@ -207,16 +208,18 @@
 
 
 #
-# These PCDs are also defined as 'PcdsDynamic' to be redefined when using UEFI in a
-# context of virtual machine.
+# These PCDs are also defined as 'PcdsDynamic' or 'PcdsPatchableInModule' to be
+# redefined when using UEFI in a context of virtual machine.
 #
-[PcdsFixedAtBuild.common, PcdsDynamic.common]
+[PcdsFixedAtBuild.common, PcdsDynamic.common, PcdsPatchableInModule.common]
+
   # System Memory (DRAM): These PCDs define the region of in-built system memory
   # Some platforms can get DRAM extensions, these additional regions will be declared
   # to UEFI by ArmPlatformLib
   gArmTokenSpaceGuid.PcdSystemMemoryBase|0|UINT64|0x00000029
   gArmTokenSpaceGuid.PcdSystemMemorySize|0|UINT64|0x0000002A
 
+[PcdsFixedAtBuild.common, PcdsDynamic.common]
   #
   # ARM Architectural Timer
   #
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH v2 3/29 ArmPlatformPkg: allow patchable PCD for FD base address

In reply to a message not in the archive

This moves the reference to gArmTokenSpaceGuid.PcdFdBaseAddress from the [FixedPcd] to the [Pcd] section in the INF file of PrePiArmPlatformGlobalVariableLib so that its users may choose to use a patchable PCD instead.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf +1 -1
index 596f5595412e..37de35e7d00e 100644
@@ -34,7 +34,6 @@
   PcdLib
 
 [FixedPcd]
-  gArmTokenSpaceGuid.PcdFdBaseAddress
   gArmTokenSpaceGuid.PcdFdSize
 
   gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize
@@ -43,4 +42,5 @@
 [Pcd]
   gArmTokenSpaceGuid.PcdSystemMemoryBase
   gArmTokenSpaceGuid.PcdSystemMemorySize
+  gArmTokenSpaceGuid.PcdFdBaseAddress
 
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH v2 4/29 ArmVirtualizationPkg: add GICv3 detection to VirtFdtDxe

In reply to a message not in the archive

This adds support for detecting the presence of a GICv3 interrupt controller from the device tree, and recording its distributor base address in a PCD.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +19 -0
index 1d44f9ba02b3..31164905d34e 100644
@@ -46,6 +46,7 @@ typedef enum {
   PropertyTypeTimer,
   PropertyTypePsci,
   PropertyTypeFwCfg,
+  PropertyTypeGicV3,
 } PROPERTY_TYPE;
 
 typedef struct {
@@ -62,6 +63,7 @@ STATIC CONST PROPERTY CompatibleProperties[] = {
   { PropertyTypeTimer,   "arm,armv8-timer"     },
   { PropertyTypePsci,    "arm,psci-0.2"        },
   { PropertyTypeFwCfg,   "qemu,fw-cfg-mmio"    },
+  { PropertyTypeGicV3,   "arm,gic-v3"          },
   { PropertyTypeUnknown, ""                    }
 };
 
@@ -256,6 +258,23 @@ InitializeVirtFdtDxe (
       DEBUG ((EFI_D_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase));
       break;
 
+    case PropertyTypeGicV3:
+      //
+      // The GIC v3 DT binding describes a series of at least 3 physical base
+      // addresses, but we are only interested in the first one, which is the
+      // distributor interface. (We use the system register CPU interface, not
+      // the MMIO one)
+      //
+      ASSERT (Len >= 16);
+
+      DistBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);
+      ASSERT (DistBase < MAX_UINT32);
+
+      PcdSet32 (PcdGicDistributorBase, (UINT32)DistBase);
+
+      DEBUG ((EFI_D_INFO, "Found GIC v3 distributor @ 0x%Lx\n", DistBase));
+      break;
+
     case PropertyTypeRtc:
       ASSERT (Len == 16);
 
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH v2 5/29 ArmVirtualizationPkg: allow patchable PCD for device tree base address

In reply to a message not in the archive

To allow a runtime self relocating PrePi instance to discover the base address of the device tree at runtime, allow the use of a patchable PCD for gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress. We will not be using the build time patch tool in this case, but using a patchable PCD will make the build system aware that its value is not a compile time constant.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec                    | 2 +-
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +1 -1
index 99411548aff6..d83117fc6abe 100644
@@ -34,7 +34,7 @@
   gArmVirtualizationTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
 
-[PcdsFixedAtBuild]
+[PcdsFixedAtBuild, PcdsPatchableInModule]
   #
   # This is the physical address where the device tree is expected to be stored
   # upon first entry into UEFI. This needs to be a FixedAtBuild PCD, so that we
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c +1 -1
index aa4ced4582e8..3e3074af72f1 100644
@@ -96,7 +96,7 @@ ArmPlatformInitializeSystemMemory (
   ASSERT (HobData != NULL);
   *HobData = 0;
 
-  DeviceTreeBase = (VOID *)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
   ASSERT (DeviceTreeBase != NULL);
 
   //
Signature · 1 line
1.8.3.2
#6 lore raw

PATCH v2 6/29 ArmVirtualizationPkg: move early UART discovery to PlatformPeim

In reply to a message not in the archive

This is partially motivated by the desire to use PrePi in a virt environment, and in that configuration, ArmPlatformInitializeSystemMemory() is never called. But actually, this is a more suitable place anyway.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 .../ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf |  3 ---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c                | 46 ++--------------------------------------------
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c                    | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf                  |  3 +++
 4 files changed, 53 insertions(+), 47 deletions(-)
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf +0 -3
index d1572882af1b..43b3c6ca1bef 100644
@@ -62,6 +62,3 @@
   gArmTokenSpaceGuid.PcdArmPrimaryCore
   gArmTokenSpaceGuid.PcdFdBaseAddress
   gArmTokenSpaceGuid.PcdFdSize
-
-[Guids]
-  gEarlyPL011BaseAddressGuid
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c +2 -44

77 lines not on this page · raw message

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c +48 -0

66 lines not on this page · raw message

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +3 -0
index e544b528d261..a376fbd1f345 100644
@@ -44,5 +44,8 @@
 [Pcd]
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
 
+[Guids]
+  gEarlyPL011BaseAddressGuid
+
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid
Signature · 1 line
1.8.3.2
#7 lore raw

PATCH v2 7/29 ArmVirtualizationPkg: use a HOB to store device tree blob

In reply to a message not in the archive

Instead of using a dynamic PCD, store the device tree address in a HOB so that we can also run under a configuration that does not support dynamic PCDs.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec                                              |  2 --
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc                                             |  3 ---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf |  2 --
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c                               | 11 ++++++++---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf                             |  4 +---
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c                                               | 10 ++++++++--
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf                                             |  3 ++-
 EmbeddedPkg/EmbeddedPkg.dec                                                                               |  2 ++
 EmbeddedPkg/Include/Guid/FdtHob.h                                                                         | 26 ++++++++++++++++++++++++++
 9 files changed, 47 insertions(+), 16 deletions(-)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +0 -2
index d83117fc6abe..868488906643 100644
@@ -44,8 +44,6 @@
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0|UINT64|0x00000001
 
 [PcdsDynamic, PcdsFixedAtBuild]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0|UINT64|0x00000002
-
   #
   # ARM PSCI function invocations can be done either through hypervisor
   # calls (HVC) or secure monitor calls (SMC).
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -3
index dff4e2507058..4f8eb632143c 100644
@@ -160,9 +160,6 @@
   # System Memory Size -- 1 MB initially, actual size will be fetched from DT
   gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000
 
-  # location of the device tree blob passed by QEMU
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0
-
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
   gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0
   gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf +0 -2
index 43b3c6ca1bef..c57002f3e9da 100644
@@ -33,8 +33,6 @@
   ArmLib
   PrintLib
   FdtLib
-  SerialPortLib
-  HobLib
 
 [Sources.common]
   Virt.c
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c +8 -3
index 58bc2b828dcd..c500d5964b25 100644
@@ -22,6 +22,7 @@
 #include <libfdt.h>
 
 #include <Guid/EarlyPL011BaseAddress.h>
+#include <Guid/FdtHob.h>
 
 EFI_STATUS
 EFIAPI
@@ -32,6 +33,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
   CONST CHAR8        *Compatible;
@@ -41,15 +43,18 @@ PlatformPeim (
   UINT64             UartBase;
 
 
-  Base = (VOID*)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  Base = (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
   FdtSize = fdt_totalsize (Base);
   NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
   ASSERT (NewBase != NULL);
-
   CopyMem (NewBase, Base, FdtSize);
-  PcdSet64 (PcdDeviceTreeBaseAddress, (UINT64)(UINTN)NewBase);
+
+  FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
+  ASSERT (FdtHobData != NULL);
+  *FdtHobData = (UINTN)NewBase;
 
   UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *UartHobData);
   ASSERT (UartHobData != NULL);
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +1 -3
index a376fbd1f345..96019e4009ff 100644
@@ -41,11 +41,9 @@
   gArmTokenSpaceGuid.PcdFvSize
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
 
-[Pcd]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
-
 [Guids]
   gEarlyPL011BaseAddressGuid
+  gFdtHobGuid
 
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +8 -2
index 31164905d34e..34fac40fa803 100644
@@ -24,10 +24,12 @@
 #include <Library/DevicePathLib.h>
 #include <Library/PcdLib.h>
 #include <Library/DxeServicesLib.h>
+#include <Library/HobLib.h>
 #include <libfdt.h>
 
 #include <Guid/Fdt.h>
 #include <Guid/VirtioMmioTransport.h>
+#include <Guid/FdtHob.h>
 
 #pragma pack (1)
 typedef struct {
@@ -105,6 +107,7 @@ InitializeVirtFdtDxe (
   IN EFI_SYSTEM_TABLE     *SystemTable
   )
 {
+  VOID                           *Hob;
   VOID                           *DeviceTreeBase;
   INT32                          Node, Prev;
   INT32                          RtcNode;
@@ -125,8 +128,11 @@ InitializeVirtFdtDxe (
   UINT64                         FwCfgDataAddress;
   UINT64                         FwCfgDataSize;
 
-  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress);
-  ASSERT (DeviceTreeBase != NULL);
+  Hob = GetFirstGuidHob(&gFdtHobGuid);
+  if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {
+    return EFI_NOT_FOUND;
+  }
+  DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);
 
   if (fdt_check_header (DeviceTreeBase) != 0) {
     DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__, DeviceTreeBase));
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf +2 -1
index 514ce2fdf658..1392c7c3fa45 100644
@@ -40,13 +40,14 @@
   DxeServicesLib
   FdtLib
   VirtioMmioDeviceLib
+  HobLib
 
 [Guids]
   gFdtTableGuid
   gVirtioMmioTransportGuid
+  gFdtHobGuid
 
 [Pcd]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
   gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod
   gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress
   gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress
EmbeddedPkg/EmbeddedPkg.dec +2 -0
index 600d0e54c4b3..2f261ece9212 100644
@@ -52,6 +52,8 @@
   ## FDT Configuration Table
   # Include/Guid/Fdt.h
   gFdtTableGuid = { 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
+  # Include/Guid/FdtHob.h
+  gFdtHobGuid   = { 0x16958446, 0x19B7, 0x480B, { 0xB0, 0x47, 0x74, 0x85, 0xAD, 0x3F, 0x71, 0x6D } }
 
 [Protocols.common]
   gHardwareInterruptProtocolGuid =  { 0x2890B3EA, 0x053D, 0x1643, { 0xAD, 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } }
EmbeddedPkg/Include/Guid/FdtHob.h new file +26 -0
new file mode 100644
index 000000000000..287729e0c350
@@ -0,0 +1,26 @@
+/** @file
+  GUID for the HOB that contains the copy of the flattened device tree blob
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License that accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __FDT_HOB_H__
+#define __FDT_HOB_H__
+
+#define FDT_HOB_GUID { \
+          0x16958446, 0x19B7, 0x480B, \
+          { 0xB0, 0x47, 0x74, 0x85, 0xAD, 0x3F, 0x71, 0x6D } \
+        }
+
+extern EFI_GUID gFdtHobGuid;
+
+#endif
Signature · 1 line
1.8.3.2
#8 lore raw

PATCH v2 8/29 ArmVirtualizationPkg: add padding to FDT allocation

In reply to a message not in the archive

Our primary user QEMU/mach-virt presents us with a FDT blob padded to 64 KB with plenty of room to set additional properties. However, in the general case, we should only add properties after making sure there is enough room available.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c +14 -3
index c500d5964b25..42a87309aebe 100644
@@ -24,6 +24,15 @@
 #include <Guid/EarlyPL011BaseAddress.h>
 #include <Guid/FdtHob.h>
 
+//
+// We may want to apply some changes to the device tree before passing it
+// to the OS: for instance, if we find a PL031 RTC node and attach our
+// runtime driver to it, we should disable it in the device tree by setting
+// its status property to "disabled". Add some padding to make sure this is
+// possible.
+//
+#define FDT_PADDING   256
+
 EFI_STATUS
 EFIAPI
 PlatformPeim (
@@ -33,6 +42,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINTN              FdtPages;
   UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
@@ -47,10 +57,11 @@ PlatformPeim (
   ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
-  FdtSize = fdt_totalsize (Base);
-  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
+  FdtSize = fdt_totalsize (Base) + FDT_PADDING;
+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
+  NewBase = AllocatePages (FdtPages);
   ASSERT (NewBase != NULL);
-  CopyMem (NewBase, Base, FdtSize);
+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
 
   FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
   ASSERT (FdtHobData != NULL);
Signature · 1 line
1.8.3.2
#9 lore raw

PATCH v2 9/29 ArmPlatformPkg/PrePi: allow use of patchable PCDs

In reply to a message not in the archive

Avoid using FixedPcdGetXX () to reference system memory and FD base address PCDs so that the platform can choose to use patchable PCDs instead. This allows a runtime self-relocating PrePi to poke alternate values into them that can only be discovered at runtime.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S | 8 ++++----
 ArmPlatformPkg/PrePi/PrePi.c                    | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S +4 -4
index fcea9496cbd5..3fa6bf1f0322 100644
@@ -42,14 +42,14 @@ _SetSVCMode:
 // at the top of the DRAM)
 _SetupStackPosition:
   // Compute Top of System Memory
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1)
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2)
+  ldr   x1, PcdGet64 (PcdSystemMemoryBase)
+  ldr   x2, PcdGet64 (PcdSystemMemorySize)
   sub   x2, x2, #1
   add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
 
   // Calculate Top of the Firmware Device
-  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)
-  LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)
+  ldr   x2, PcdGet64 (PcdFdBaseAddress)
+  ldr   w3, PcdGet32 (PcdFdSize)
   sub   x3, x3, #1
   add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
 
ArmPlatformPkg/PrePi/PrePi.c +4 -4
index 9a5e067ef537..0e551c518d6b 100755
@@ -30,8 +30,8 @@
 #include "PrePi.h"
 #include "LzmaDecompress.h"
 
-#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \
-                  ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))
+#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \
+                  ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))
 
 // Not used when PrePi in run in XIP mode
 UINTN mGlobalVariableBase = 0;
@@ -108,8 +108,8 @@ PrePiMain (
 
   // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
   ASSERT (IS_XIP() ||
-          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&
-           ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize)))));
+          ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) &&
+           ((UINT32)(PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) <= (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))));
 
   // Initialize the architecture specific bits
   ArchInitialize ();
Signature · 1 line
1.8.3.2
#10 lore raw

PATCH v2 10/29 ArmPlatformPkg/PrePi: allow unicore PrePi on multicore capable CPU

In reply to a message not in the archive

Under virtualization, typically, the guest is entered with only a single CPU turned on, and any remaining CPUs are started by the OS using PSCI. So refactor the PrePi code in such a way that we can implement a unicore flavor which can be allowed to execute on a MPcore CPU.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/PrePi/MainMPCore.c  | 2 +-
 ArmPlatformPkg/PrePi/MainUniCore.c | 2 +-
 ArmPlatformPkg/PrePi/PrePi.c       | 9 ++++-----
 ArmPlatformPkg/PrePi/PrePi.h       | 3 ++-
 4 files changed, 8 insertions(+), 8 deletions(-)
ArmPlatformPkg/PrePi/MainMPCore.c +1 -1
index bf813730d341..8e5f9947d499 100644
@@ -35,7 +35,7 @@ PrimaryMain (
     ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));
   }
 
-  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp, ArmIsMpCore());
 
   // We must never return
   ASSERT(FALSE);
ArmPlatformPkg/PrePi/MainUniCore.c +1 -1
index 43588a50ddb5..918ea4dcdf7b 100644
@@ -27,7 +27,7 @@ PrimaryMain (
     ASSERT(ArmIsMpCore() == 0);
   DEBUG_CODE_END();
 
-  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp, ArmIsMpCore());
 
   // We must never return
   ASSERT(FALSE);
ArmPlatformPkg/PrePi/PrePi.c +4 -5
index 0e551c518d6b..5b058dba80fa 100755
@@ -94,7 +94,8 @@ PrePiMain (
   IN  UINTN                     UefiMemoryBase,
   IN  UINTN                     StacksBase,
   IN  UINTN                     GlobalVariableBase,
-  IN  UINT64                    StartTimeStamp
+  IN  UINT64                    StartTimeStamp,
+  IN  BOOLEAN                   IsMpCore
   )
 {
   EFI_HOB_HANDOFF_INFO_TABLE*   HobList;
@@ -138,7 +139,7 @@ PrePiMain (
   ASSERT_EFI_ERROR (Status);
 
   // Create the Stacks HOB (reserve the memory for all stacks)
-  if (ArmIsMpCore ()) {
+  if (IsMpCore) {
     StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +
                  ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));
   } else {
@@ -152,7 +153,7 @@ PrePiMain (
   //TODO: Call CpuPei as a library
   BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
 
-  if (ArmIsMpCore ()) {
+  if (IsMpCore) {
     // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
     Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);
 
@@ -209,8 +210,6 @@ CEntryPoint (
 {
   UINT64   StartTimeStamp;
 
-  ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));
-
   // Initialize the platform specific controllers
   ArmPlatformInitialize (MpId);
 
ArmPlatformPkg/PrePi/PrePi.h +2 -1
index e67795f4490a..468569b3a28b 100644
@@ -40,7 +40,8 @@ PrePiMain (
   IN  UINTN                     UefiMemoryBase,
   IN  UINTN                     StacksBase,
   IN  UINTN                     GlobalVariableBase,
-  IN  UINT64                    StartTimeStamp
+  IN  UINT64                    StartTimeStamp,
+  IN  BOOLEAN                   IsMpCore
   );
 
 EFI_STATUS
Signature · 1 line
1.8.3.2
#11 lore raw

PATCH v2 11/29 ArmPlatformPkg/PrePi: add a relocatable version of PrePi

In reply to a message not in the archive

This patch introduces a relocatable PrePi, which can execute from arbitrary offsets in RAM. This is intendend to be run from a boot loader which passes a description of the actual platform in a device tree, for instance.

---
 ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S |  27 +++++++++++++++++++++++
 ArmPlatformPkg/PrePi/MainUniCoreRelocatable.c   |  38 ++++++++++++++++++++++++++++++++
 ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf  | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/PrePi/Scripts/PrePi-PIE.lds      |  28 ++++++++++++++++++++++++
 4 files changed, 204 insertions(+)
ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S +27 -0
index 3fa6bf1f0322..54ac01c4b9c3 100644
@@ -28,6 +28,33 @@ GCC_ASM_EXPORT(_ModuleEntryPoint)
 StartupAddr:        .8byte ASM_PFX(CEntryPoint)
 
 ASM_PFX(_ModuleEntryPoint):
+
+#if defined (SELF_RELOCATE)
+  //
+  // If we are built as a ET_DYN PIE executable, we need to process all
+  // relative relocations regardless of whether or not we are executing from
+  // the same offset we were linked at. This is only possible if we are
+  // running from RAM.
+  //
+  adr   x8, __reloc_base
+  adr   x9, __reloc_start
+  adr   x10, __reloc_end
+
+.Lreloc_loop:
+  cmp   x9, x10
+  bhs   .Lreloc_done
+
+  ldp   x11, x12, [x9], #24
+  cmp   x12, #0x403    // R_AARCH64_RELATIVE
+  bne   .Lreloc_loop
+
+  ldr   x12, [x9, #-8]
+  add   x12, x12, x8
+  str   x12, [x11, x8]
+  b     .Lreloc_loop
+.Lreloc_done:
+#endif
+
   // Do early platform specific actions
   bl    ASM_PFX(ArmPlatformPeiBootAction)
 
ArmPlatformPkg/PrePi/MainUniCoreRelocatable.c new file +38 -0
new file mode 100644
index 000000000000..594579971a2d
@@ -0,0 +1,38 @@
+/** @file
+*
+*  Copyright (c) 2011, ARM Limited. All rights reserved.
+*
+*  This program and the accompanying materials
+*  are licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#include "PrePi.h"
+
+VOID
+PrimaryMain (
+  IN  UINTN                     UefiMemoryBase,
+  IN  UINTN                     StacksBase,
+  IN  UINTN                     GlobalVariableBase,
+  IN  UINT64                    StartTimeStamp
+  )
+{
+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp, FALSE);
+
+  // We must never return
+  ASSERT(FALSE);
+}
+
+VOID
+SecondaryMain (
+  IN  UINTN                     MpId
+  )
+{
+  // We must never get into this function on UniCore system
+  ASSERT(FALSE);
+}
ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf new file +111 -0

111 lines not on this page · raw message

ArmPlatformPkg/PrePi/Scripts/PrePi-PIE.lds new file +28 -0
new file mode 100644
index 000000000000..880f9b114ddd
@@ -0,0 +1,28 @@
+SECTIONS
+{
+  .text 0x0 : {
+    PROVIDE(__reloc_base = .);
+
+    *(.text .text*)
+    *(.got .got*)
+    *(.rodata .rodata*)
+    *(.data .data*)
+
+    . = ALIGN(0x20);
+    PROVIDE(__reloc_start = .);
+    *(.rela .rela*)
+    PROVIDE(__reloc_end = .);
+  }
+  .bss ALIGN(0x20) : { *(.bss .bss*) }
+
+  /DISCARD/ : {
+    *(.note.GNU-stack)
+    *(.gnu_debuglink)
+    *(.interp)
+    *(.dynamic)
+    *(.dynsym)
+    *(.dynstr)
+    *(.hash)
+    *(.comment)
+  }
+}
Signature · 1 line
1.8.3.2
#12 lore raw

PATCH v2 12/29 ArmVirtualizationPkg: implement custom MemoryInitPeiLib

In reply to a message not in the archive

This implements a MemoryInitPeiLib instance that differs from the stock ArmPlatformPkg version only in the fact that it does not remove the memory used by the flash device (FD). The reason is that, when using PrePi, the DXE core is started immediately and never returns so there is no reason to preserve any of the memory that the flash device occupied originally, and it is preferable to release is so that the OS loader can reuse it. This is especially important for the relocatable PrePi configuration, which is aimed at being launched from a boot loader that itself adheres to the Linux arm64 boot protocol.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 .../Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c              | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 .../Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf            | 66 +++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c new file +91 -0
new file mode 100644
index 000000000000..5f6cd059c47f
@@ -0,0 +1,91 @@
+/** @file
+*
+*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
+*  Copyright (c) 2014, Linaro Limited. All rights reserved.
+*
+*  This program and the accompanying materials
+*  are licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#include <PiPei.h>
+
+#include <Library/ArmPlatformLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+VOID
+BuildMemoryTypeInformationHob (
+  VOID
+  );
+
+VOID
+InitMmu (
+  VOID
+  )
+{
+  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable;
+  VOID                          *TranslationTableBase;
+  UINTN                         TranslationTableSize;
+  RETURN_STATUS                 Status;
+
+  // Get Virtual Memory Map from the Platform Library
+  ArmPlatformGetVirtualMemoryMap (&MemoryTable);
+
+  //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
+  //      DRAM (even at the top of DRAM as it is the first permanent memory allocation)
+  Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));
+  }
+}
+
+EFI_STATUS
+EFIAPI
+MemoryPeim (
+  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,
+  IN UINT64                             UefiMemorySize
+  )
+{
+  EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
+
+  // Ensure PcdSystemMemorySize has been set
+  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
+
+  //
+  // Now, the permanent memory has been installed, we can call AllocatePages()
+  //
+  ResourceAttributes = (
+      EFI_RESOURCE_ATTRIBUTE_PRESENT |
+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
+      EFI_RESOURCE_ATTRIBUTE_TESTED
+  );
+
+  BuildResourceDescriptorHob (
+      EFI_RESOURCE_SYSTEM_MEMORY,
+      ResourceAttributes,
+      PcdGet64 (PcdSystemMemoryBase),
+      PcdGet64 (PcdSystemMemorySize)
+  );
+
+  // Build Memory Allocation Hob
+  InitMmu ();
+
+  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
+    // Optional feature that helps prevent EFI memory map fragmentation.
+    BuildMemoryTypeInformationHob ();
+  }
+
+  return EFI_SUCCESS;
+}
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#13 lore raw

PATCH v2 13/29 ArmVirtualizationPkg: allow patchable PCD for FV base address

In reply to a message not in the archive

Allow the use of a patchable PCD for gArmTokenSpaceGuid.PcdFvBaseAddress by moving it from the [FixedPcd] to the [Pcd] section in the INF file of PlatformPeiLib.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +3 -1
index 96019e4009ff..1fca9b28f9e2 100644
@@ -37,9 +37,11 @@
   FdtLib
 
 [FixedPcd]
-  gArmTokenSpaceGuid.PcdFvBaseAddress
   gArmTokenSpaceGuid.PcdFvSize
+
+[Pcd]
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
+  gArmTokenSpaceGuid.PcdFvBaseAddress
 
 [Guids]
   gEarlyPL011BaseAddressGuid
Signature · 1 line
1.8.3.2
#14 lore raw

PATCH v2 14/29 ArmVirtualizationPkg: Xen/PV relocatable platformlib instance

In reply to a message not in the archive

Add a ArmPlatformLib instance that can deal with the self relocation and truly dynamic discovery of system RAM base and size.

---
 .../ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/MemnodeParser.S          | 232 +++++++++++++++++++++++++++++++++++++++++++++++
 .../ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S  | 161 ++++++++++++++++++++++++++++++++
 .../ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf |  59 ++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c     |  71 +++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c          |  83 +++++++++++++++++
 5 files changed, 606 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/MemnodeParser.S new file +232 -0
new file mode 100644
index 000000000000..cce2c4800c51
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ *
+ * This program and the accompanying materials
+ * are licensed and made available under the terms and conditions of the BSD License
+ * which accompanies this distribution.  The full text of the license may be found at
+ * http://opensource.org/licenses/bsd-license.php
+ *
+ * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ */
+
+/*
+ * Theory of operation
+ * -------------------
+ *
+ * This code parses a Flattened Device Tree binary (DTB) to find the base of
+ * system RAM. It is written in assembly so that it can be executed before a
+ * stack has been set up.
+ *
+ * To find the base of system RAM, we have to traverse the FDT to find a memory
+ * node. In the context of this implementation, the first node that has a
+ * device_type property with the value 'memory' and a 'reg' property is
+ * acceptable, and the name of the node (memory[@xxx]) is ignored, as are any
+ * other nodes that match the above constraints.
+ *
+ * In pseudo code, this implementation does the following:
+ *
+ * for each node {
+ *	have_device_type = false
+ *	have_reg = false
+ *
+ *	for each property {
+ *		if property value == 'memory' {
+ *			if property name == 'device_type' {
+ *				have_device_type = true
+ *			}
+ *		} else {
+ *			if property name == 'reg' {
+ *				have_reg = true
+ *				membase = property value[0]
+ *				memsize = property value[1]
+ *			}
+ *		}
+ *	}
+ *	if have_device_type and have_reg {
+ *		return membase and memsize
+ *	}
+ * }
+ * return NOT_FOUND
+ */
+
+#define FDT_MAGIC	0xedfe0dd0
+
+#define FDT_BEGIN_NODE	0x1
+#define FDT_END_NODE	0x2
+#define FDT_PROP	0x3
+#define FDT_END		0x9
+
+	xMEMSIZE	.req	x0
+	xMEMBASE	.req	x1
+
+	xLR		.req	x8
+	xDTP		.req	x9
+	xSTRTAB		.req	x10
+	xMEMNODE	.req	x11
+
+	.text
+	.align	3
+_memory:
+	.asciz	"memory"
+_reg:
+	.asciz	"reg"
+_device_type:
+	.asciz	"device_type"
+
+	/*
+	 * Compare strings in x4 and x5, return in w7
+	 */
+	.align	3
+strcmp:
+	ldrb	w2, [x4], #1
+	ldrb	w3, [x5], #1
+	subs	w7, w2, w3
+	cbz	w2, 0f
+	cbz	w3, 0f
+	beq	strcmp
+0:	ret
+
+	.globl	find_memnode
+find_memnode:
+	// preserve link register
+	mov	xLR, x30
+	mov	xDTP, x0
+	mov	xMEMNODE, #0
+
+	/*
+	 * Check the DTB magic at offset 0
+	 */
+	movz	w4, #:abs_g0_nc:FDT_MAGIC
+	movk	w4, #:abs_g1:FDT_MAGIC
+	ldr	w5, [xDTP]
+	cmp	w4, w5
+	bne	err_invalid_magic
+
+	/*
+	 * Read the string offset and store it for later use
+	 */
+	ldr	w4, [xDTP, #12]
+	rev	w4, w4
+	add	xSTRTAB, xDTP, x4
+
+	/*
+	 * Read the struct offset and add it to the DT pointer
+	 */
+	ldr	w5, [xDTP, #8]
+	rev	w5, w5
+	add	xDTP, xDTP, x5
+
+	/*
+	 * Check current tag for FDT_BEGIN_NODE
+	 */
+	ldr	w5, [xDTP]
+	rev	w5, w5
+	cmp	w5, #FDT_BEGIN_NODE
+	bne	err_unexpected_begin_tag
+
+begin_node:
+	mov	xMEMNODE, #0
+	add	xDTP, xDTP, #4
+
+	/*
+	 * Advance xDTP past NULL terminated string
+	 */
+0:	ldrb	w4, [xDTP], #1
+	cbnz	w4, 0b
+
+next_tag:
+	add	xDTP, xDTP, #3
+	and	xDTP, xDTP, #~3
+
+	/*
+	 * Read the next tag, could be BEGIN_NODE, END_NODE, PROP, END
+	 */
+	ldr	w5, [xDTP]
+	rev	w5, w5
+	cmp	w5, #FDT_BEGIN_NODE
+	beq	begin_node
+	cmp	w5, #FDT_END_NODE
+	beq	end_node
+	cmp	w5, #FDT_PROP
+	beq	prop_node
+	cmp	w5, #FDT_END
+	beq	err_end_of_fdt
+	b	err_unexpected_tag
+
+prop_node:
+	/*
+	 * If propname == 'reg', record as membase and memsize
+	 * If propname == 'device_type' and value == 'memory',
+	 * set the 'is_memnode' flag for this node
+	 */
+	ldr	w6, [xDTP, #4]
+	add	xDTP, xDTP, #12
+	rev	w6, w6
+	mov	x5, xDTP
+	adr	x4, _memory
+	bl	strcmp
+
+	/*
+	 * Get handle to property name
+	 */
+	ldr	w5, [xDTP, #-4]
+	rev	w5, w5
+	add	x5, xSTRTAB, x5
+
+	cbz	w7, check_device_type
+
+	/*
+	 * Check for 'reg' property
+	 */
+	adr	x4, _reg
+	bl	strcmp
+	cbnz	w7, inc_and_next_tag
+
+	/*
+	 * Extract two 64-bit quantities from the 'reg' property. These values
+	 * will only be used if the node also turns out to have a device_type
+	 * property with a value of 'memory'.
+	 *
+	 * NOTE: xDTP is only guaranteed to be 32 bit aligned, and we are most
+	 *       likely executing with the MMU off, so we cannot use 64 bit
+	 *       wide accesses here.
+	 */
+	ldp	w4, w5, [xDTP]
+	orr	xMEMBASE, x4, x5, lsl #32
+	ldp	w4, w5, [xDTP, #8]
+	orr	xMEMSIZE, x4, x5, lsl #32
+	rev	xMEMBASE, xMEMBASE
+	rev	xMEMSIZE, xMEMSIZE
+	orr	xMEMNODE, xMEMNODE, #2
+	b	inc_and_next_tag
+
+check_device_type:
+	/*
+	 * Check whether the current property's name is 'device_type'
+	 */
+	adr	x4, _device_type
+	bl	strcmp
+	cbnz	w7, inc_and_next_tag
+	orr	xMEMNODE, xMEMNODE, #1
+
+inc_and_next_tag:
+	add	xDTP, xDTP, x6
+	b	next_tag
+
+end_node:
+	/*
+	 * Check for device_type = memory and reg = xxxx
+	 * If we have both, we are done
+	 */
+	add	xDTP, xDTP, #4
+	cmp	xMEMNODE, #3
+	bne	next_tag
+
+	ret	xLR
+
+err_invalid_magic:
+err_unexpected_begin_tag:
+err_unexpected_tag:
+err_end_of_fdt:
+	wfi
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S new file +161 -0

161 lines not on this page · raw message

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf new file +59 -0

59 lines not on this page · raw message

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c new file +71 -0

71 lines not on this page · raw message

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#15 lore raw

PATCH v2 15/29 Ovmf/Xen: move Xen interface version to <xen.h>

In reply to a message not in the archive

Tiancore has its private copy of the Xen headers, and all drivers that depend on it should use the same Xen interface version, so let's move the #define to xen.h itself.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/IndustryStandard/Xen/xen.h | 5 +++++
 OvmfPkg/XenBusDxe/XenBusDxe.h              | 5 -----
 OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h          | 4 ----
 3 files changed, 5 insertions(+), 9 deletions(-)
OvmfPkg/Include/IndustryStandard/Xen/xen.h +5 -0
index 79697fcb6152..1cd7ab3ab136 100644
@@ -27,6 +27,11 @@
 #ifndef __XEN_PUBLIC_XEN_H__
 #define __XEN_PUBLIC_XEN_H__
 
+//
+// Xen interface version used by Tianocore
+//
+#define __XEN_INTERFACE_VERSION__ 0x00040400
+
 #include "xen-compat.h"
 
 #if defined(MDE_CPU_IA32) || defined(MDE_CPU_X64)
OvmfPkg/XenBusDxe/XenBusDxe.h +0 -5
index 11640223ebf4..80253b7d1ca9 100644
@@ -19,11 +19,6 @@
 #include <Uefi.h>
 
 //
-// Xen interface version used
-//
-#define  __XEN_INTERFACE_VERSION__ 0x00040400
-
-//
 // Libraries
 //
 #include <Library/UefiBootServicesTableLib.h>
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h +0 -4
index e5b1b5f4b90d..c0b62c4f38ca 100644
@@ -18,10 +18,6 @@
 
 #include <Uefi.h>
 
-//
-// Xen interface version used
-//
-#define __XEN_INTERFACE_VERSION__ 0x00040400
 #define xen_mb() MemoryFence()
 #define xen_rmb() MemoryFence()
 #define xen_wmb() MemoryFence()
Signature · 1 line
1.8.3.2
#16 lore raw

PATCH v2 16/29 Ovmf/Xen: fix pointer to int cast in XenBusDxe

In reply to a message not in the archive

On ARM, xen_pfn_t is 64 bits but the size of a pointer is only 32 bits, so casting between them needs to go via (UINTN). Also move the xen_pfn_t cast outside the shift so that we can avoid shifting 64-bit quantities on 32-bit architectures, which may require runtime library support.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/GrantTable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
OvmfPkg/XenBusDxe/GrantTable.c +2 -2
index 37d3bf786c64..8405edc51bc4 100644
@@ -160,7 +160,7 @@ XenGrantTableInit (
     Parameters.domid = DOMID_SELF;
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
-    Parameters.gpfn = (((xen_pfn_t) GrantTable) >> EFI_PAGE_SHIFT) + Index;
+    Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));
@@ -182,7 +182,7 @@ XenGrantTableDeinit (
 
   for (Index = NR_GRANT_FRAMES - 1; Index >= 0; Index--) {
     Parameters.domid = DOMID_SELF;
-    Parameters.gpfn = (((xen_pfn_t) GrantTable) >> EFI_PAGE_SHIFT) + Index;
+    Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
     ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {
Signature · 1 line
1.8.3.2
#17 lore raw

PATCH v2 17/29 Ovmf/Xen: refactor XenBusDxe hypercall implementation

In reply to a message not in the archive

This refactors the Xen hypercall implementation that is part of the XenBusDxe driver, in preparation of splitting it off entirely into a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall() prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info page is not strictly part of the Xen hypercall interface, and is not used by other expected users of XenHypercallLib such as the Xen console version of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage there; the existing asm implementations are renamed to __XenHypercall2() and invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/EventChannel.c      | 11 +++--------
 OvmfPkg/XenBusDxe/GrantTable.c        |  4 ++--
 OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
 OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c         | 44 +++++++++++++++++++++++++++++++++++++++++++-
 OvmfPkg/XenBusDxe/XenBusDxe.h         |  1 -
 OvmfPkg/XenBusDxe/XenHypercall.c      | 50 ++++++++++++++------------------------------------
 OvmfPkg/XenBusDxe/XenHypercall.h      | 28 +++-------------------------
 OvmfPkg/XenBusDxe/XenStore.c          |  4 ++--
 9 files changed, 73 insertions(+), 81 deletions(-)
OvmfPkg/XenBusDxe/EventChannel.c +3 -8
index 03efaf9cb904..a86323e6adfd 100644
@@ -28,7 +28,7 @@ XenEventChannelNotify (
   evtchn_send_t Send;
 
   Send.port = Port;
-  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send);
+  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, &Send);
   return (UINT32)ReturnCode;
 }
 
@@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
   OUT evtchn_port_t   *Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_alloc_unbound_t Parameter;
   UINT32 ReturnCode;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
-
   Parameter.dom = DOMID_SELF;
   Parameter.remote_dom = DomainId;
-  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private->Dev,
+  ReturnCode = (UINT32)XenHypercallEventChannelOp (
                                    EVTCHNOP_alloc_unbound,
                                    &Parameter);
   if (ReturnCode != 0) {
@@ -79,10 +76,8 @@ XenBusEventChannelClose (
   IN evtchn_port_t   Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_close_t Close;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
   Close.port = Port;
-  return (UINT32)XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close);
+  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, &Close);
 }
OvmfPkg/XenBusDxe/GrantTable.c +2 -2
index 8405edc51bc4..53cb99f0e004 100644
@@ -161,7 +161,7 @@ XenGrantTableInit (
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));
     }
@@ -184,7 +184,7 @@ XenGrantTableDeinit (
     Parameters.domid = DOMID_SELF;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, remove_from_physmap hypercall error: %d\n", ReturnCode));
     }
OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +3 -3
index 8547c30b81ee..e0fa71bb5ba8 100644
@@ -2,13 +2,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   ; Save only ebx, ecx is supposed to be a scratch register and needs to be
   ; saved by the caller
   push ebx
OvmfPkg/XenBusDxe/X64/hypercall.nasm +3 -3
index 177f271ef094..5e6a0c05c5c4 100644
@@ -3,13 +3,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   push rdi
   push rsi
   ; Copy HypercallAddr to rax
OvmfPkg/XenBusDxe/XenBusDxe.c +43 -1

62 lines not on this page · raw message

OvmfPkg/XenBusDxe/XenBusDxe.h +0 -1
index 80253b7d1ca9..9b7219906a69 100644
@@ -91,7 +91,6 @@ struct _XENBUS_DEVICE {
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
 
-  VOID                          *Hyperpage;
   shared_info_t                 *SharedInfo;
 };
 
OvmfPkg/XenBusDxe/XenHypercall.c +14 -36

100 lines not on this page · raw message

OvmfPkg/XenBusDxe/XenHypercall.h +3 -25
index 06693830e16e..9d49e33eb5af 100644
@@ -18,9 +18,9 @@
 
 /**
   This function will put the two arguments in the right place (registers) and
-  call HypercallAddr, which correspond to an entry in the hypercall pages.
+  invoke the hypercall identified by HypercallID.
 
-  @param HypercallAddr  A memory address where the hypercall to call is.
+  @param HypercallID    The symbolic ID of the hypercall to be invoked
   @param Arg1           First argument.
   @param Arg2           Second argument.
 
@@ -29,7 +29,7 @@
 INTN
 EFIAPI
 XenHypercall2 (
-  IN     VOID *HypercallAddr,
+  IN     INTN HypercallID,
   IN OUT INTN Arg1,
   IN OUT INTN Arg2
   );
@@ -44,27 +44,23 @@ XenHypercall2 (
 **/
 EFI_STATUS
 XenHyperpageInit (
-  XENBUS_DEVICE *Dev
   );
 
 /**
   Return the value of the HVM parameter Index.
 
-  @param Dev    A XENBUS_DEVICE instance.
   @param Index  The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN.
 
   @return   The value of the asked parameter or 0 in case of error.
 **/
 UINT64
 XenHypercallHvmGetParam (
-  XENBUS_DEVICE *Dev,
   UINT32 Index
   );
 
 /**
   Hypercall to do different operation on the memory.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. XENMEM_add_to_physmap.
   @param Arguments  The arguments associated to the operation.
 
@@ -73,7 +69,6 @@ XenHypercallHvmGetParam (
 **/
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   );
@@ -81,7 +76,6 @@ XenHypercallMemoryOp (
 /**
   Do an operation on the event channels.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. EVTCHNOP_send.
   @param Arguments  The argument associated to the operation.
 
@@ -90,24 +84,8 @@ XenHypercallMemoryOp (
 **/
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   );
 
-/**
-  Map the shared_info_t page into memory.
-
-  @param Dev    A XENBUS_DEVICE instance.
-
-  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
-                          the shared info page
-  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
-                          hypercall returned an error.
-**/
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
-  );
-
 #endif
OvmfPkg/XenBusDxe/XenStore.c +2 -2
index 2df8f5348585..7ec1e634bc5c 100644
@@ -1057,8 +1057,8 @@ XenStoreInit (
 
   xs.Dev = Dev;
 
-  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_EVTCHN);
-  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_PFN);
+  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (HVM_PARAM_STORE_EVTCHN);
+  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (HVM_PARAM_STORE_PFN);
   xs.XenStore = (VOID *) (XenStoreGpfn << EFI_PAGE_SHIFT);
   DEBUG ((EFI_D_INFO, "XenBusInit: XenBus rings @%p, event channel %x\n",
           xs.XenStore, xs.EventChannel));
Signature · 1 line
1.8.3.2
#18 lore raw

PATCH v2 18/29 Ovmf/Xen: move XenBusDxe hypercall code to separate library

In reply to a message not in the archive

This moves all of the Xen hypercall code that was private to XenBusDxe to a new library class XenHypercallLib. This will allow us to reimplement it for ARM, and to export the Xen hypercall functionality to other parts of the code, such as a Xen console SerialPortLib driver.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/{XenBusDxe/XenHypercall.h => Include/Library/XenHypercallLib.h} | 16 ++-------------
 OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/Ia32/hypercall.nasm      |  0
 OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/X64/hypercall.nasm       |  0
 OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/XenHypercall.c           | 37 ++--------------------------------
 OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c                     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf                | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                                                     |  4 ++++
 OvmfPkg/OvmfPkgIa32.dsc                                                 |  1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                                              |  1 +
 OvmfPkg/OvmfPkgX64.dsc                                                  |  1 +
 OvmfPkg/XenBusDxe/EventChannel.c                                        |  3 ++-
 OvmfPkg/XenBusDxe/GrantTable.c                                          |  2 +-
 OvmfPkg/XenBusDxe/XenBusDxe.c                                           |  9 +--------
 OvmfPkg/XenBusDxe/XenBusDxe.inf                                         | 11 +----------
 OvmfPkg/XenBusDxe/XenStore.c                                            |  2 +-
 15 files changed, 146 insertions(+), 70 deletions(-)
OvmfPkg/Include/Library/XenHypercallLib.h renamed from OvmfPkg/XenBusDxe/XenHypercall.h +2 -14
similarity index 82%
rename from OvmfPkg/XenBusDxe/XenHypercall.h
rename to OvmfPkg/Include/Library/XenHypercallLib.h
index 9d49e33eb5af..dc2c5424683c 100644
@@ -13,8 +13,8 @@
 
 **/
 
-#ifndef __XENBUS_DXE_HYPERCALL_H__
-#define __XENBUS_DXE_HYPERCALL_H__
+#ifndef __XEN_HYPERCALL_LIB_H_
+#define __XEN_HYPERCALL_LIB_H_
 
 /**
   This function will put the two arguments in the right place (registers) and
@@ -35,18 +35,6 @@ XenHypercall2 (
   );
 
 /**
-  Get the page where all hypercall are from the XenInfo hob.
-
-  @param Dev    A XENBUS_DEVICE instance.
-
-  @retval EFI_NOT_FOUND   hyperpage could not be found.
-  @retval EFI_SUCCESS     Successfully retrieve the hyperpage pointer.
-**/
-EFI_STATUS
-XenHyperpageInit (
-  );
-
-/**
   Return the value of the HVM parameter Index.
 
   @param Index  The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN.
OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm renamed from OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +0 -0
similarity index 100%
rename from OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
rename to OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm
OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm renamed from OvmfPkg/XenBusDxe/X64/hypercall.nasm +0 -0
similarity index 100%
rename from OvmfPkg/XenBusDxe/X64/hypercall.nasm
rename to OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm
OvmfPkg/Library/XenHypercallLib/XenHypercall.c renamed from OvmfPkg/XenBusDxe/XenHypercall.c +2 -35
similarity index 66%
rename from OvmfPkg/XenBusDxe/XenHypercall.c
rename to OvmfPkg/Library/XenHypercallLib/XenHypercall.c
index 9bcf3197633e..ecc757cf707c 100644
@@ -14,32 +14,12 @@
 **/
 
 #include <PiDxe.h>
-#include <Library/HobLib.h>
-#include <Guid/XenInfo.h>
-
-#include "XenBusDxe.h"
-#include "XenHypercall.h"
 
 #include <IndustryStandard/Xen/hvm/params.h>
 #include <IndustryStandard/Xen/memory.h>
 
-STATIC VOID       *Hyperpage;
-
-EFI_STATUS
-XenHyperpageInit (
-  )
-{
-  EFI_HOB_GUID_TYPE   *GuidHob;
-  EFI_XEN_INFO        *XenInfo;
-
-  GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
-  if (GuidHob == NULL) {
-    return EFI_NOT_FOUND;
-  }
-  XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
-  Hyperpage = XenInfo->HyperPages;
-  return EFI_SUCCESS;
-}
+#include <Library/DebugLib.h>
+#include <Library/XenHypercallLib.h>
 
 UINT64
 XenHypercallHvmGetParam (
@@ -81,16 +61,3 @@ XenHypercallEventChannelOp (
   return XenHypercall2 (__HYPERVISOR_event_channel_op,
                         Operation, (INTN) Arguments);
 }
-
-INTN
-EFIAPI
-XenHypercall2 (
-  IN     INTN HypercallID,
-  IN OUT INTN Arg1,
-  IN OUT INTN Arg2
-  )
-{
-  ASSERT (HyperPage != NULL);
-
-  return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);
-}
OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c new file +77 -0

77 lines not on this page · raw message

OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf new file +52 -0

52 lines not on this page · raw message

OvmfPkg/OvmfPkg.dec +4 -0
index 6eb551a8d436..30a9fb1e9b42 100644
@@ -44,6 +44,10 @@
   #
   SerializeVariablesLib|Include/Library/SerializeVariablesLib.h
 
+  ##  @libraryclass  Invoke Xen hypercalls
+  #
+  XenHypercallLib|Include/Library/XenHypercallLib.h
+
 [Guids]
   gUefiOvmfPkgTokenSpaceGuid      = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}
   gEfiXenInfoGuid                 = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}
OvmfPkg/OvmfPkgIa32.dsc +1 -0
index ca656698754b..90540272745c 100644
@@ -128,6 +128,7 @@
   S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
+  XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
 
 [LibraryClasses.common]
 !if $(SECURE_BOOT_ENABLE) == TRUE
OvmfPkg/OvmfPkgIa32X64.dsc +1 -0
index 4b4a1da717c1..0a331eda8be0 100644
@@ -133,6 +133,7 @@
   S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
+  XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
 
 [LibraryClasses.common]
 !if $(SECURE_BOOT_ENABLE) == TRUE
OvmfPkg/OvmfPkgX64.dsc +1 -0
index eb3f34b8350b..e2b37c271681 100644
@@ -133,6 +133,7 @@
   S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
+  XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
 
 [LibraryClasses.common]
 !if $(SECURE_BOOT_ENABLE) == TRUE
OvmfPkg/XenBusDxe/EventChannel.c +2 -1
index a86323e6adfd..6a36dca29911 100644
@@ -16,7 +16,8 @@
 
 **/
 #include "EventChannel.h"
-#include "XenHypercall.h"
+
+#include <Library/XenHypercallLib.h>
 
 UINT32
 XenEventChannelNotify (
OvmfPkg/XenBusDxe/GrantTable.c +1 -1
index 53cb99f0e004..a80d5eff39cd 100644
@@ -34,7 +34,7 @@
 
 #include <IndustryStandard/Xen/memory.h>
 
-#include "XenHypercall.h"
+#include <Library/XenHypercallLib.h>
 
 #include "GrantTable.h"
 #include "InterlockedCompareExchange16.h"
OvmfPkg/XenBusDxe/XenBusDxe.c +1 -8
index d333b331b6db..cc334c086c1f 100644
@@ -26,10 +26,10 @@
 #include <IndustryStandard/Pci.h>
 #include <IndustryStandard/Acpi.h>
 #include <Library/DebugLib.h>
+#include <Library/XenHypercallLib.h>
 
 #include "XenBusDxe.h"
 
-#include "XenHypercall.h"
 #include "GrantTable.h"
 #include "XenStore.h"
 #include "XenBus.h"
@@ -390,13 +390,6 @@ XenBusDxeDriverBindingStart (
   MmioAddr = BarDesc->AddrRangeMin;
   FreePool (BarDesc);
 
-  Status = XenHyperpageInit ();
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));
-    Status = EFI_UNSUPPORTED;
-    goto ErrorAllocated;
-  }
-
   Status = XenGetSharedInfoPage (Dev);
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "XenBus: Unable to get the shared info page.\n"));
OvmfPkg/XenBusDxe/XenBusDxe.inf +1 -10
index 4ce474345452..714607dbd6f8 100644
@@ -34,8 +34,6 @@
   DriverBinding.h
   ComponentName.c
   ComponentName.h
-  XenHypercall.c
-  XenHypercall.h
   InterlockedCompareExchange16.c
   InterlockedCompareExchange16.h
   GrantTable.c
@@ -49,12 +47,10 @@
   Helpers.c
 
 [Sources.IA32]
-  Ia32/hypercall.nasm
   Ia32/InterlockedCompareExchange16.nasm
   Ia32/TestAndClearBit.nasm
 
 [Sources.X64]
-  X64/hypercall.nasm
   X64/InterlockedCompareExchange16.nasm
   X64/TestAndClearBit.nasm
 
@@ -67,8 +63,7 @@
   UefiLib
   DevicePathLib
   DebugLib
-  HobLib
-
+  XenHypercallLib
 
 [Protocols]
   gEfiDriverBindingProtocolGuid
@@ -77,7 +72,3 @@
   gEfiComponentNameProtocolGuid
   gXenBusProtocolGuid
 
-
-[Guids]
-  gEfiXenInfoGuid
-
OvmfPkg/XenBusDxe/XenStore.c +1 -1
index 7ec1e634bc5c..9850f1e644fc 100644
@@ -60,8 +60,8 @@
 
 #include <IndustryStandard/Xen/hvm/params.h>
 
-#include "XenHypercall.h"
 #include "EventChannel.h"
+#include <Library/XenHypercallLib.h>
 
 //
 // Private Data Structures
Signature · 1 line
1.8.3.2
#19 lore raw

PATCH v2 19/29 Ovmf/Xen: introduce XENIO_PROTOCOL

In reply to a message not in the archive

This introduces the abstract XENIO_PROTOCOL that will be used to communicate the Xen grant table address to drivers supporting this protocol. Primary purpose is allowing us to change the XenBusDxe implementation so that it can support non-PCI Xen implementations such as Xen on ARM.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/Protocol/XenIo.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec              |  1 +
 2 files changed, 49 insertions(+)
OvmfPkg/Include/Protocol/XenIo.h new file +48 -0
new file mode 100644
index 000000000000..510391f3b3e8
@@ -0,0 +1,48 @@
+/** @file
+  XenIo protocol to abstract arch specific details
+
+  The Xen implementations for the Intel and ARM archictures differ in the way
+  the base address of the grant table is communicated to the guest. The former
+  uses a virtual PCI device, while the latter uses a device tree node.
+  In order to allow the XenBusDxe UEFI driver to be reused for the non-PCI
+  Xen implementation, this abstract protocol can be installed on a handle
+  with the appropriate base address.
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __PROTOCOL_XENIO_H__
+#define __PROTOCOL_XENIO_H__
+
+#include <IndustryStandard/Xen/xen.h>
+
+#define XENIO_PROTOCOL_GUID \
+  {0x6efac84f, 0x0ab0, 0x4747, {0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}}
+
+///
+/// Forward declaration
+///
+typedef struct _XENIO_PROTOCOL XENIO_PROTOCOL;
+
+///
+/// Protocol structure
+///
+struct _XENIO_PROTOCOL {
+  //
+  // Protocol data fields
+  //
+  EFI_PHYSICAL_ADDRESS          GrantTableAddress;
+};
+
+extern EFI_GUID gXenIoProtocolGuid;
+
+#endif
OvmfPkg/OvmfPkg.dec +1 -0
index 30a9fb1e9b42..3711fa922311 100644
@@ -58,6 +58,7 @@
   gVirtioDeviceProtocolGuid       = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
   gBlockMmioProtocolGuid          = {0x6b558ce3, 0x69e5, 0x4c67, {0xa6, 0x34, 0xf7, 0xfe, 0x72, 0xad, 0xbe, 0x84}}
   gXenBusProtocolGuid             = {0x3d3ca290, 0xb9a5, 0x11e3, {0xb7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}}
+  gXenIoProtocolGuid              = {0x6efac84f, 0x0ab0, 0x4747, {0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}}
 
 [PcdsFixedAtBuild]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase|0x0|UINT32|0
Signature · 1 line
1.8.3.2
#20 lore raw

PATCH v2 20/29 Ovmf/Xen: add separate driver for Xen PCI device

In reply to a message not in the archive

Prepare for making XenBusDxe suitable for use with non-PCI devices (such as the DT node exposed by Xen on ARM) by introducing a separate DXE driver that binds to the Xen virtual PCI device and exposes the abstract XENIO_PROTOCOL for XenBusDxe to bind against.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenIoPciDxe/XenIoPciDxe.c   | 365 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf |  45 +++++++++++++
 2 files changed, 410 insertions(+)
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +365 -0
new file mode 100644
index 000000000000..8c91590f7eb5
@@ -0,0 +1,365 @@
+/** @file
+
+  Driver for the virtual Xen PCI device
+
+  Copyright (C) 2012, Red Hat, Inc.
+  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (C) 2013, ARM Ltd.
+  Copyright (C) 2015, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <IndustryStandard/Pci.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/PciIo.h>
+#include <Protocol/XenIo.h>
+
+#define PCI_VENDOR_ID_XEN                0x5853
+#define PCI_DEVICE_ID_XEN_PLATFORM       0x0001
+
+/**
+
+  Device probe function for this driver.
+
+  The DXE core calls this function for any given device in order to see if the
+  driver can drive the device.
+
+  @param[in]  This                The EFI_DRIVER_BINDING_PROTOCOL object
+                                  incorporating this driver (independently of
+                                  any device).
+
+  @param[in] DeviceHandle         The device to probe.
+
+  @param[in] RemainingDevicePath  Relevant only for bus drivers, ignored.
+
+
+  @retval EFI_SUCCESS      The driver supports the device being probed.
+
+  @retval EFI_UNSUPPORTED  The driver does not support the device being probed.
+
+  @return                  Error codes from the OpenProtocol() boot service or
+                           the PciIo protocol.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingSupported (
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,
+  IN EFI_HANDLE                  DeviceHandle,
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath
+  )
+{
+  EFI_STATUS          Status;
+  EFI_PCI_IO_PROTOCOL *PciIo;
+  PCI_TYPE00          Pci;
+
+  //
+  // Attempt to open the device with the PciIo set of interfaces. On success,
+  // the protocol is "instantiated" for the PCI device. Covers duplicate open
+  // attempts (EFI_ALREADY_STARTED).
+  //
+  Status = gBS->OpenProtocol (
+                  DeviceHandle,               // candidate device
+                  &gEfiPciIoProtocolGuid,     // for generic PCI access
+                  (VOID **)&PciIo,            // handle to instantiate
+                  This->DriverBindingHandle,  // requestor driver identity
+                  DeviceHandle,               // ControllerHandle, according to
+                                              // the UEFI Driver Model
+                  EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive PciIo access to
+                                              // the device; to be released
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  //
+  // Read entire PCI configuration header for more extensive check ahead.
+  //
+  Status = PciIo->Pci.Read (
+                        PciIo,                        // (protocol, device)
+                                                      // handle
+                        EfiPciIoWidthUint32,          // access width & copy
+                                                      // mode
+                        0,                            // Offset
+                        sizeof Pci / sizeof (UINT32), // Count
+                        &Pci                          // target buffer
+                        );
+
+  if (Status == EFI_SUCCESS) {
+    if ((Pci.Hdr.VendorId == PCI_VENDOR_ID_XEN) &&
+        (Pci.Hdr.DeviceId == PCI_DEVICE_ID_XEN_PLATFORM)) {
+      Status = EFI_SUCCESS;
+    } else {
+      Status = EFI_UNSUPPORTED;
+    }
+  }
+
+  //
+  // We needed PCI IO access only transitorily, to see whether we support the
+  // device or not.
+  //
+  gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle, DeviceHandle);
+
+  return Status;
+}
+
+/**
+
+  After we've pronounced support for a specific device in
+  DriverBindingSupported(), we start managing said device (passed in by the
+  Driver Exeuction Environment) with the following service.
+
+  See DriverBindingSupported() for specification references.
+
+  @param[in]  This                The EFI_DRIVER_BINDING_PROTOCOL object
+                                  incorporating this driver (independently of
+                                  any device).
+
+  @param[in] DeviceHandle         The supported device to drive.
+
+  @param[in] RemainingDevicePath  Relevant only for bus drivers, ignored.
+
+
+  @retval EFI_SUCCESS           The device was started.
+
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
+
+  @return                       Error codes from the OpenProtocol() boot
+                                service, the PciIo protocol or the
+                                InstallProtocolInterface() boot service.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingStart (
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,
+  IN EFI_HANDLE                  DeviceHandle,
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath
+  )
+{
+  EFI_STATUS                        Status;
+  XENIO_PROTOCOL                    *XenIo;
+  EFI_PCI_IO_PROTOCOL               *PciIo;
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc;
+
+  Status = gBS->OpenProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+                  (VOID **)&PciIo, This->DriverBindingHandle,
+                  DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  XenIo = (XENIO_PROTOCOL *) AllocateZeroPool (sizeof *XenIo);
+  if (XenIo == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // The BAR1 of this PCI device is used for shared memory and is supposed to
+  // look like MMIO. The address space of the BAR1 will be used to map the
+  // Grant Table.
+  //
+  Status = PciIo->GetBarAttributes (PciIo, PCI_BAR_IDX1, NULL, (VOID**) &BarDesc);
+  ASSERT_EFI_ERROR (Status);
+  ASSERT (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM);
+
+  /* Get a Memory address for mapping the Grant Table. */
+  DEBUG ((EFI_D_INFO, "XenBus: BAR at %LX\n", BarDesc->AddrRangeMin));
+  XenIo->GrantTableAddress = BarDesc->AddrRangeMin;
+  FreePool (BarDesc);
+
+  Status = gBS->InstallProtocolInterface (DeviceHandle,
+             &gXenIoProtocolGuid, EFI_NATIVE_INTERFACE, XenIo);
+
+  if (!EFI_ERROR (Status)) {
+    return EFI_SUCCESS;
+  }
+
+  gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle, DeviceHandle);
+
+  FreePool (XenIo);
+  return Status;
+}
+
+/**
+
+  Stop driving the XenIo PCI device
+
+  @param[in] This               The EFI_DRIVER_BINDING_PROTOCOL object
+                                incorporating this driver (independently of any
+                                device).
+
+  @param[in] DeviceHandle       Stop driving this device.
+
+  @param[in] NumberOfChildren   Since this function belongs to a device driver
+                                only (as opposed to a bus driver), the caller
+                                environment sets NumberOfChildren to zero, and
+                                we ignore it.
+
+  @param[in] ChildHandleBuffer  Ignored (corresponding to NumberOfChildren).
+
+  @retval EFI_SUCCESS           Driver instance has been stopped and the PCI
+                                configuration attributes have been restored.
+
+  @return                       Error codes from the OpenProtocol() or
+                                CloseProtocol(), UninstallProtocolInterface()
+                                boot services.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingStop (
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,
+  IN EFI_HANDLE                  DeviceHandle,
+  IN UINTN                       NumberOfChildren,
+  IN EFI_HANDLE                  *ChildHandleBuffer
+  )
+{
+  EFI_STATUS               Status;
+  XENIO_PROTOCOL           *XenIo;
+
+  Status = gBS->OpenProtocol (
+                  DeviceHandle,                  // candidate device
+                  &gXenIoProtocolGuid,           // retrieve the XenIo iface
+                  (VOID **)&XenIo,               // target pointer
+                  This->DriverBindingHandle,     // requestor driver identity
+                  DeviceHandle,                  // requesting lookup for dev.
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  //
+  // Handle Stop() requests for in-use driver instances gracefully.
+  //
+  Status = gBS->UninstallProtocolInterface (DeviceHandle,
+                  &gXenIoProtocolGuid, XenIo);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle, DeviceHandle);
+
+  FreePool (XenIo);
+
+  return Status;
+}
+
+
+//
+// The static object that groups the Supported() (ie. probe), Start() and
+// Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata
+// C, 10.1 EFI Driver Binding Protocol.
+//
+STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {
+  &XenIoPciDeviceBindingSupported,
+  &XenIoPciDeviceBindingStart,
+  &XenIoPciDeviceBindingStop,
+  0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers
+  NULL, // ImageHandle, to be overwritten by
+        // EfiLibInstallDriverBindingComponentName2() in XenIoPciDeviceEntryPoint()
+  NULL  // DriverBindingHandle, ditto
+};
+
+
+//
+// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
+// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
+// in English, for display on standard console devices. This is recommended for
+// UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
+// Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
+//
+STATIC
+EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {
+  { "eng;en", L"XenIo PCI Driver" },
+  { NULL,     NULL                }
+};
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL gComponentName;
+
+EFI_STATUS
+EFIAPI
+XenIoPciGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,
+  IN  CHAR8                       *Language,
+  OUT CHAR16                      **DriverName
+  )
+{
+  return LookupUnicodeString2 (
+           Language,
+           This->SupportedLanguages,
+           mDriverNameTable,
+           DriverName,
+           (BOOLEAN)(This == &gComponentName) // Iso639Language
+           );
+}
+
+EFI_STATUS
+EFIAPI
+XenIoPciGetDeviceName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,
+  IN  EFI_HANDLE                  DeviceHandle,
+  IN  EFI_HANDLE                  ChildHandle,
+  IN  CHAR8                       *Language,
+  OUT CHAR16                      **ControllerName
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
+  &XenIoPciGetDriverName,
+  &XenIoPciGetDeviceName,
+  "eng" // SupportedLanguages, ISO 639-2 language codes
+};
+
+STATIC
+EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)     &XenIoPciGetDriverName,
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &XenIoPciGetDeviceName,
+  "en" // SupportedLanguages, RFC 4646 language codes
+};
+
+
+//
+// Entry point of this driver.
+//
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceEntryPoint (
+  IN EFI_HANDLE       ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  return EfiLibInstallDriverBindingComponentName2 (
+           ImageHandle,
+           SystemTable,
+           &gDriverBinding,
+           ImageHandle,
+           &gComponentName,
+           &gComponentName2
+           );
+}
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#21 lore raw

PATCH v2 21/29 Ovmf/Xen: move XenBusDxe to abstract XENIO_PROTOCOL

In reply to a message not in the archive

While Xen on Intel uses a virtual PCI device to communicate the base address of the grant table, the ARM implementation uses a DT node, which is fundamentally incompatible with the way XenBusDxe is implemented, i.e., as a UEFI Driver Model implementation for a PCI device.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/OvmfPkgIa32.dsc           |  1 +
 OvmfPkg/OvmfPkgIa32.fdf           |  1 +
 OvmfPkg/OvmfPkgIa32X64.dsc        |  1 +
 OvmfPkg/OvmfPkgIa32X64.fdf        |  1 +
 OvmfPkg/OvmfPkgX64.dsc            |  1 +
 OvmfPkg/OvmfPkgX64.fdf            |  1 +
 OvmfPkg/XenBusDxe/ComponentName.c |  2 +-
 OvmfPkg/XenBusDxe/GrantTable.c    |  5 ++---
 OvmfPkg/XenBusDxe/GrantTable.h    |  3 +--
 OvmfPkg/XenBusDxe/XenBus.c        |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c     | 57 ++++++++++++++-------------------------------------------
 OvmfPkg/XenBusDxe/XenBusDxe.h     |  8 ++------
 OvmfPkg/XenBusDxe/XenBusDxe.inf   |  2 +-
 13 files changed, 30 insertions(+), 59 deletions(-)
OvmfPkg/OvmfPkgIa32.dsc +1 -0
index 90540272745c..8c880613851d 100644
@@ -444,6 +444,7 @@
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
OvmfPkg/OvmfPkgIa32.fdf +1 -0
index f47e7ddc7834..ecef963d1e85 100644
@@ -227,6 +227,7 @@ INF  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
 INF  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
 
OvmfPkg/OvmfPkgIa32X64.dsc +1 -0
index 0a331eda8be0..ff32ecefd07b 100644
@@ -451,6 +451,7 @@
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
OvmfPkg/OvmfPkgIa32X64.fdf +1 -0
index 4c034460d5d2..29414ff04082 100644
@@ -227,6 +227,7 @@ INF  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
 INF  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
 
OvmfPkg/OvmfPkgX64.dsc +1 -0
index e2b37c271681..8bac6dc313f0 100644
@@ -449,6 +449,7 @@
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
OvmfPkg/OvmfPkgX64.fdf +1 -0
index 2323eb2edf33..f1feb698ba66 100644
@@ -227,6 +227,7 @@ INF  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
 INF  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
 
OvmfPkg/XenBusDxe/ComponentName.c +1 -1
index 4530509e65dc..3f2dd406c77d 100644
@@ -155,7 +155,7 @@ XenBusDxeComponentNameGetControllerName (
   Status = EfiTestManagedDevice (
              ControllerHandle,
              gXenBusDxeDriverBinding.DriverBindingHandle,
-             &gEfiPciIoProtocolGuid
+             &gXenIoProtocolGuid
              );
   if (EFI_ERROR (Status)) {
     return Status;
OvmfPkg/XenBusDxe/GrantTable.c +2 -3
index a80d5eff39cd..19117fbe0373 100644
@@ -139,8 +139,7 @@ XenGrantTableEndAccess (
 
 VOID
 XenGrantTableInit (
-  IN XENBUS_DEVICE  *Dev,
-  IN UINT64         MmioAddr
+  IN XENBUS_DEVICE  *Dev
   )
 {
   xen_add_to_physmap_t Parameters;
@@ -155,7 +154,7 @@ XenGrantTableInit (
     XenGrantTablePutFreeEntry ((grant_ref_t)Index);
   }
 
-  GrantTable = (VOID*)(UINTN) MmioAddr;
+  GrantTable = (VOID*)(UINTN) Dev->XenIo->GrantTableAddress;
   for (Index = 0; Index < NR_GRANT_FRAMES; Index++) {
     Parameters.domid = DOMID_SELF;
     Parameters.idx = Index;
OvmfPkg/XenBusDxe/GrantTable.h +1 -2
index 5772c56662df..194275ba7ed5 100644
@@ -29,8 +29,7 @@
 **/
 VOID
 XenGrantTableInit (
-  IN XENBUS_DEVICE  *Dev,
-  IN UINT64         MmioAddr
+  IN XENBUS_DEVICE  *Dev
   );
 
 /**
OvmfPkg/XenBusDxe/XenBus.c +3 -3
index f69c27dd184a..ee9526c33252 100644
@@ -138,7 +138,7 @@ XenBusAddDevice (
   XENBUS_PRIVATE_DATA *Private;
   EFI_STATUS Status;
   XENBUS_DEVICE_PATH *TempXenBusPath;
-  VOID *ChildPciIo;
+  VOID *ChildXenIo;
 
   AsciiSPrint (DevicePath, sizeof (DevicePath),
                "device/%a/%a", Type, Id);
@@ -208,8 +208,8 @@ XenBusAddDevice (
     }
 
     Status = gBS->OpenProtocol (Dev->ControllerHandle,
-               &gEfiPciIoProtocolGuid,
-               &ChildPciIo, Dev->This->DriverBindingHandle,
+               &gXenIoProtocolGuid,
+               &ChildXenIo, Dev->This->DriverBindingHandle,
                Private->Handle,
                EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER);
     if (EFI_ERROR (Status)) {
OvmfPkg/XenBusDxe/XenBusDxe.c +14 -43

124 lines not on this page · raw message

OvmfPkg/XenBusDxe/XenBusDxe.h +2 -6
index 9b7219906a69..6c306e017b07 100644
@@ -39,7 +39,7 @@
 //
 // Consumed Protocols
 //
-#include <Protocol/PciIo.h>
+#include <Protocol/XenIo.h>
 
 
 //
@@ -73,10 +73,6 @@ extern EFI_COMPONENT_NAME_PROTOCOL  gXenBusDxeComponentName;
 //
 #include <IndustryStandard/Xen/xen.h>
 
-#define PCI_VENDOR_ID_XEN                0x5853
-#define PCI_DEVICE_ID_XEN_PLATFORM       0x0001
-
-
 typedef struct _XENBUS_DEVICE_PATH XENBUS_DEVICE_PATH;
 typedef struct _XENBUS_DEVICE XENBUS_DEVICE;
 
@@ -86,7 +82,7 @@ struct _XENBUS_DEVICE {
   UINT32                        Signature;
   EFI_DRIVER_BINDING_PROTOCOL   *This;
   EFI_HANDLE                    ControllerHandle;
-  EFI_PCI_IO_PROTOCOL           *PciIo;
+  XENIO_PROTOCOL                *XenIo;
   EFI_EVENT                     ExitBootEvent;
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
OvmfPkg/XenBusDxe/XenBusDxe.inf +1 -1
index 714607dbd6f8..31553ac5a64a 100644
@@ -67,8 +67,8 @@
 
 [Protocols]
   gEfiDriverBindingProtocolGuid
-  gEfiPciIoProtocolGuid
   gEfiComponentName2ProtocolGuid
   gEfiComponentNameProtocolGuid
   gXenBusProtocolGuid
+  gXenIoProtocolGuid
 
Signature · 1 line
1.8.3.2
#22 lore raw

PATCH v2 22/29 Ovmf/Xen: implement XenHypercallLib for ARM

In reply to a message not in the archive

This patch adds an implementation of XenHypercallLib for both AArch64 and AArch32 execution modes on ARM systems.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/IndustryStandard/Xen/arch-arm/xen.h    | 436 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Include/IndustryStandard/Xen/xen.h             |   2 +-
 OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S    |  26 ++++++
 OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S        |  25 +++++
 OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf |  40 ++++++++
 5 files changed, 528 insertions(+), 1 deletion(-)
OvmfPkg/Include/IndustryStandard/Xen/arch-arm/xen.h new file +436 -0
new file mode 100644
index 000000000000..655a221f6337
@@ -0,0 +1,436 @@
+/******************************************************************************
+ * arch-arm.h
+ *
+ * Guest OS interface to ARM Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2011 (C) Citrix Systems
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_ARM_H__
+#define __XEN_PUBLIC_ARCH_ARM_H__
+
+/*
+ * `incontents 50 arm_abi Hypercall Calling Convention
+ *
+ * A hypercall is issued using the ARM HVC instruction.
+ *
+ * A hypercall can take up to 5 arguments. These are passed in
+ * registers, the first argument in x0/r0 (for arm64/arm32 guests
+ * respectively irrespective of whether the underlying hypervisor is
+ * 32- or 64-bit), the second argument in x1/r1, the third in x2/r2,
+ * the forth in x3/r3 and the fifth in x4/r4.
+ *
+ * The hypercall number is passed in r12 (arm) or x16 (arm64). In both
+ * cases the relevant ARM procedure calling convention specifies this
+ * is an inter-procedure-call scratch register (e.g. for use in linker
+ * stubs). This use does not conflict with use during a hypercall.
+ *
+ * The HVC ISS must contain a Xen specific TAG: XEN_HYPERCALL_TAG.
+ *
+ * The return value is in x0/r0.
+ *
+ * The hypercall will clobber x16/r12 and the argument registers used
+ * by that hypercall (except r0 which is the return value) i.e. in
+ * addition to x16/r12 a 2 argument hypercall will clobber x1/r1 and a
+ * 4 argument hypercall will clobber x1/r1, x2/r2 and x3/r3.
+ *
+ * Parameter structs passed to hypercalls are laid out according to
+ * the Procedure Call Standard for the ARM Architecture (AAPCS, AKA
+ * EABI) and Procedure Call Standard for the ARM 64-bit Architecture
+ * (AAPCS64). Where there is a conflict the 64-bit standard should be
+ * used regardless of guest type. Structures which are passed as
+ * hypercall arguments are always little endian.
+ *
+ * All memory which is shared with other entities in the system
+ * (including the hypervisor and other guests) must reside in memory
+ * which is mapped as Normal Inner-cacheable. This applies to:
+ *  - hypercall arguments passed via a pointer to guest memory.
+ *  - memory shared via the grant table mechanism (including PV I/O
+ *    rings etc).
+ *  - memory shared with the hypervisor (struct shared_info, struct
+ *    vcpu_info, the grant table, etc).
+ *
+ * Any Inner cache allocation strategy (Write-Back, Write-Through etc)
+ * is acceptable. There is no restriction on the Outer-cacheability.
+ */
+
+/*
+ * `incontents 55 arm_hcall Supported Hypercalls
+ *
+ * Xen on ARM makes extensive use of hardware facilities and therefore
+ * only a subset of the potential hypercalls are required.
+ *
+ * Since ARM uses second stage paging any machine/physical addresses
+ * passed to hypercalls are Guest Physical Addresses (Intermediate
+ * Physical Addresses) unless otherwise noted.
+ *
+ * The following hypercalls (and sub operations) are supported on the
+ * ARM platform. Other hypercalls should be considered
+ * unavailable/unsupported.
+ *
+ *  HYPERVISOR_memory_op
+ *   All generic sub-operations.
+ *
+ *   In addition the following arch specific sub-ops:
+ *    * XENMEM_add_to_physmap
+ *    * XENMEM_add_to_physmap_batch
+ *
+ *  HYPERVISOR_domctl
+ *   All generic sub-operations, with the exception of:
+ *    * XEN_DOMCTL_iomem_permission (not yet implemented)
+ *    * XEN_DOMCTL_irq_permission (not yet implemented)
+ *
+ *  HYPERVISOR_sched_op
+ *   All generic sub-operations, with the exception of:
+ *    * SCHEDOP_block -- prefer wfi hardware instruction
+ *
+ *  HYPERVISOR_console_io
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_xen_version
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_event_channel_op
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_physdev_op
+ *   No sub-operations are currenty supported
+ *
+ *  HYPERVISOR_sysctl
+ *   All generic sub-operations, with the exception of:
+ *    * XEN_SYSCTL_page_offline_op
+ *    * XEN_SYSCTL_get_pmstat
+ *    * XEN_SYSCTL_pm_op
+ *
+ *  HYPERVISOR_hvm_op
+ *   Exactly these sub-operations are supported:
+ *    * HVMOP_set_param
+ *    * HVMOP_get_param
+ *
+ *  HYPERVISOR_grant_table_op
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_vcpu_op
+ *   Exactly these sub-operations are supported:
+ *    * VCPUOP_register_vcpu_info
+ *    * VCPUOP_register_runstate_memory_area
+ *
+ *
+ * Other notes on the ARM ABI:
+ *
+ * - struct start_info is not exported to ARM guests.
+ *
+ * - struct shared_info is mapped by ARM guests using the
+ *   HYPERVISOR_memory_op sub-op XENMEM_add_to_physmap, passing
+ *   XENMAPSPACE_shared_info as space parameter.
+ *
+ * - All the per-cpu struct vcpu_info are mapped by ARM guests using the
+ *   HYPERVISOR_vcpu_op sub-op VCPUOP_register_vcpu_info, including cpu0
+ *   struct vcpu_info.
+ *
+ * - The grant table is mapped using the HYPERVISOR_memory_op sub-op
+ *   XENMEM_add_to_physmap, passing XENMAPSPACE_grant_table as space
+ *   parameter. The memory range specified under the Xen compatible
+ *   hypervisor node on device tree can be used as target gpfn for the
+ *   mapping.
+ *
+ * - Xenstore is initialized by using the two hvm_params
+ *   HVM_PARAM_STORE_PFN and HVM_PARAM_STORE_EVTCHN. They can be read
+ *   with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
+ *
+ * - The paravirtualized console is initialized by using the two
+ *   hvm_params HVM_PARAM_CONSOLE_PFN and HVM_PARAM_CONSOLE_EVTCHN. They
+ *   can be read with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
+ *
+ * - Event channel notifications are delivered using the percpu GIC
+ *   interrupt specified under the Xen compatible hypervisor node on
+ *   device tree.
+ *
+ * - The device tree Xen compatible node is fully described under Linux
+ *   at Documentation/devicetree/bindings/arm/xen.txt.
+ */
+
+#define XEN_HYPERCALL_TAG   0XEA1
+
+#define uint64_aligned_t UINT64 __attribute__((aligned(8)))
+
+#ifndef __ASSEMBLY__
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
+    typedef union { type *p; unsigned long q; }                 \
+        __guest_handle_ ## name;                                \
+    typedef union { type *p; uint64_aligned_t q; }              \
+        __guest_handle_64_ ## name;
+
+/*
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
+ * in a struct in memory. On ARM is always 8 bytes sizes and 8 bytes
+ * aligned.
+ * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
+ * hypercall argument. It is 4 bytes on aarch and 8 bytes on aarch64.
+ */
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
+/* this is going to be changed on 64 bit */
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
+#define set_xen_guest_handle_raw(hnd, val)                  \
+    do {                                                    \
+        typeof(&(hnd)) _sxghr_tmp = &(hnd);                 \
+        _sxghr_tmp->q = 0;                                  \
+        _sxghr_tmp->p = val;                                \
+    } while ( 0 )
+#ifdef __XEN_TOOLS__
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
+#endif
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+/* Anonymous union includes both 32- and 64-bit names (e.g., r0/x0). */
+# define __DECL_REG(n64, n32) union {          \
+        UINT64 n64;                          \
+        UINT32 n32;                          \
+    }
+#else
+/* Non-gcc sources must always use the proper 64-bit name (e.g., x0). */
+#define __DECL_REG(n64, n32) UINT64 n64
+#endif
+
+struct vcpu_guest_core_regs
+{
+    /*         Aarch64       Aarch32 */
+    __DECL_REG(x0,           r0_usr);
+    __DECL_REG(x1,           r1_usr);
+    __DECL_REG(x2,           r2_usr);
+    __DECL_REG(x3,           r3_usr);
+    __DECL_REG(x4,           r4_usr);
+    __DECL_REG(x5,           r5_usr);
+    __DECL_REG(x6,           r6_usr);
+    __DECL_REG(x7,           r7_usr);
+    __DECL_REG(x8,           r8_usr);
+    __DECL_REG(x9,           r9_usr);
+    __DECL_REG(x10,          r10_usr);
+    __DECL_REG(x11,          r11_usr);
+    __DECL_REG(x12,          r12_usr);
+
+    __DECL_REG(x13,          sp_usr);
+    __DECL_REG(x14,          lr_usr);
+
+    __DECL_REG(x15,          __unused_sp_hyp);
+
+    __DECL_REG(x16,          lr_irq);
+    __DECL_REG(x17,          sp_irq);
+
+    __DECL_REG(x18,          lr_svc);
+    __DECL_REG(x19,          sp_svc);
+
+    __DECL_REG(x20,          lr_abt);
+    __DECL_REG(x21,          sp_abt);
+
+    __DECL_REG(x22,          lr_und);
+    __DECL_REG(x23,          sp_und);
+
+    __DECL_REG(x24,          r8_fiq);
+    __DECL_REG(x25,          r9_fiq);
+    __DECL_REG(x26,          r10_fiq);
+    __DECL_REG(x27,          r11_fiq);
+    __DECL_REG(x28,          r12_fiq);
+
+    __DECL_REG(x29,          sp_fiq);
+    __DECL_REG(x30,          lr_fiq);
+
+    /* Return address and mode */
+    __DECL_REG(pc64,         pc32);             /* ELR_EL2 */
+    UINT32 cpsr;                              /* SPSR_EL2 */
+
+    union {
+        UINT32 spsr_el1;       /* AArch64 */
+        UINT32 spsr_svc;       /* AArch32 */
+    };
+
+    /* AArch32 guests only */
+    UINT32 spsr_fiq, spsr_irq, spsr_und, spsr_abt;
+
+    /* AArch64 guests only */
+    UINT64 sp_el0;
+    UINT64 sp_el1, elr_el1;
+};
+typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
+
+#undef __DECL_REG
+
+typedef UINT64 xen_pfn_t;
+#define PRI_xen_pfn PRIx64
+
+/* Maximum number of virtual CPUs in legacy multi-processor guests. */
+/* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
+#define XEN_LEGACY_MAX_VCPUS 1
+
+typedef UINT64 xen_ulong_t;
+#define PRI_xen_ulong PRIx64
+
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+struct vcpu_guest_context {
+#define _VGCF_online                   0
+#define VGCF_online                    (1<<_VGCF_online)
+    UINT32 flags;                         /* VGCF_* */
+
+    struct vcpu_guest_core_regs user_regs;  /* Core CPU registers */
+
+    UINT32 sctlr;
+    UINT64 ttbcr, ttbr0, ttbr1;
+};
+typedef struct vcpu_guest_context vcpu_guest_context_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
+#endif
+
+struct arch_vcpu_info {
+};
+typedef struct arch_vcpu_info arch_vcpu_info_t;
+
+struct arch_shared_info {
+};
+typedef struct arch_shared_info arch_shared_info_t;
+typedef UINT64 xen_callback_t;
+
+#endif
+
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+
+/* PSR bits (CPSR, SPSR)*/
+
+#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
+#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
+#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
+
+/* 32 bit modes */
+#define PSR_MODE_USR 0x10
+#define PSR_MODE_FIQ 0x11
+#define PSR_MODE_IRQ 0x12
+#define PSR_MODE_SVC 0x13
+#define PSR_MODE_MON 0x16
+#define PSR_MODE_ABT 0x17
+#define PSR_MODE_HYP 0x1a
+#define PSR_MODE_UND 0x1b
+#define PSR_MODE_SYS 0x1f
+
+/* 64 bit modes */
+#define PSR_MODE_BIT  0x10 /* Set iff AArch32 */
+#define PSR_MODE_EL3h 0x0d
+#define PSR_MODE_EL3t 0x0c
+#define PSR_MODE_EL2h 0x09
+#define PSR_MODE_EL2t 0x08
+#define PSR_MODE_EL1h 0x05
+#define PSR_MODE_EL1t 0x04
+#define PSR_MODE_EL0t 0x00
+
+#define PSR_GUEST32_INIT  (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)
+#define PSR_GUEST64_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h)
+
+#define SCTLR_GUEST_INIT    0x00c50078
+
+/*
+ * Virtual machine platform (memory layout, interrupts)
+ *
+ * These are defined for consistency between the tools and the
+ * hypervisor. Guests must not rely on these hardcoded values but
+ * should instead use the FDT.
+ */
+
+/* Physical Address Space */
+
+/* vGIC mappings: Only one set of mapping is used by the guest.
+ * Therefore they can overlap.
+ */
+
+/* vGIC v2 mappings */
+#define GUEST_GICD_BASE   0x03001000ULL
+#define GUEST_GICD_SIZE   0x00001000ULL
+#define GUEST_GICC_BASE   0x03002000ULL
+#define GUEST_GICC_SIZE   0x00000100ULL
+
+/* vGIC v3 mappings */
+#define GUEST_GICV3_GICD_BASE      0x03001000ULL
+#define GUEST_GICV3_GICD_SIZE      0x00010000ULL
+
+#define GUEST_GICV3_RDIST_STRIDE   0x20000ULL
+#define GUEST_GICV3_RDIST_REGIONS  1
+
+#define GUEST_GICV3_GICR0_BASE     0x03020000ULL    /* vCPU0 - vCPU7 */
+#define GUEST_GICV3_GICR0_SIZE     0x00100000ULL
+
+/* 16MB == 4096 pages reserved for guest to use as a region to map its
+ * grant table in.
+ */
+#define GUEST_GNTTAB_BASE 0x38000000ULL
+#define GUEST_GNTTAB_SIZE 0x01000000ULL
+
+#define GUEST_MAGIC_BASE  0x39000000ULL
+#define GUEST_MAGIC_SIZE  0x01000000ULL
+
+#define GUEST_RAM_BANKS   2
+
+#define GUEST_RAM0_BASE   0x40000000ULL /* 3GB of low RAM @ 1GB */
+#define GUEST_RAM0_SIZE   0xc0000000ULL
+
+#define GUEST_RAM1_BASE   0x0200000000ULL /* 1016GB of RAM @ 8GB */
+#define GUEST_RAM1_SIZE   0xfe00000000ULL
+
+#define GUEST_RAM_BASE    GUEST_RAM0_BASE /* Lowest RAM address */
+/* Largest amount of actual RAM, not including holes */
+#define GUEST_RAM_MAX     (GUEST_RAM0_SIZE + GUEST_RAM1_SIZE)
+/* Suitable for e.g. const uint64_t ramfoo[] = GUEST_RAM_BANK_FOOS; */
+#define GUEST_RAM_BANK_BASES   { GUEST_RAM0_BASE, GUEST_RAM1_BASE }
+#define GUEST_RAM_BANK_SIZES   { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
+
+/* Interrupts */
+#define GUEST_TIMER_VIRT_PPI    27
+#define GUEST_TIMER_PHYS_S_PPI  29
+#define GUEST_TIMER_PHYS_NS_PPI 30
+#define GUEST_EVTCHN_PPI        31
+
+/* PSCI functions */
+#define PSCI_cpu_suspend 0
+#define PSCI_cpu_off     1
+#define PSCI_cpu_on      2
+#define PSCI_migrate     3
+
+#endif
+
+#endif /*  __XEN_PUBLIC_ARCH_ARM_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
OvmfPkg/Include/IndustryStandard/Xen/xen.h +1 -1
index 1cd7ab3ab136..8596ca1bd26f 100644
@@ -37,7 +37,7 @@
 #if defined(MDE_CPU_IA32) || defined(MDE_CPU_X64)
 #include "arch-x86/xen.h"
 #elif defined(__arm__) || defined (__aarch64__)
-#include "arch-arm.h"
+#include "arch-arm/xen.h"
 #else
 #error "Unsupported architecture"
 #endif
OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S new file +26 -0
new file mode 100644
index 000000000000..b1b5d4cc3f28
@@ -0,0 +1,26 @@
+
+/** @file
+  AArch64 implementation of XenHypercall2
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Xen/arch-arm/xen.h>
+
+  .text
+  .global   ASM_PFX(XenHypercall2)
+ASM_PFX(XenHypercall2):
+  mov     x16, x0
+  mov     x0, x1
+  mov     x1, x2
+  hvc     #XEN_HYPERCALL_TAG
+  ret
OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S new file +25 -0
new file mode 100644
index 000000000000..b38e1a8f18da
@@ -0,0 +1,25 @@
+/** @file
+  ARM (AArch32) implementation of XenHypercall2
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Xen/arch-arm/xen.h>
+
+  .text
+  .global   ASM_PFX(XenHypercall2)
+ASM_PFX(XenHypercall2):
+  mov     r12, r0
+  mov     r0, r1
+  mov     r1, r2
+  hvc     #XEN_HYPERCALL_TAG
+  bx      lr
OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf new file +40 -0
new file mode 100644
index 000000000000..9cbbeb5d8789
@@ -0,0 +1,40 @@
+## @file
+#  Xen Hypercall abstraction lib for ARM architecture
+#
+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenHypercallLibArm
+  FILE_GUID                      = 9607AC2E-FCB9-499B-9475-612282019568
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = XenHypercallLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = ARM AARCH64
+#
+
+[Sources.ARM]
+  Arm/Hypercall.S
+
+[Sources.AARCH64]
+  Aarch64/Hypercall.S
+
+[Sources]
+  XenHypercall.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
Signature · 1 line
1.8.3.2
#23 lore raw

PATCH v2 23/29 Ovmf/Xen: add ARM and AArch64 support to XenBusDxe

In reply to a message not in the archive

This patch adds support to XenBusDxe for executing on ARM and AArch64 machines (the former only when built with GCC).

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/AtomicsGcc.c  | 44 ++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/XenBusDxe/XenBusDxe.inf |  3 +++
 2 files changed, 47 insertions(+)
OvmfPkg/XenBusDxe/AtomicsGcc.c new file +44 -0
new file mode 100644
index 000000000000..a0bdcbf67440
@@ -0,0 +1,44 @@
+/** @file
+  Arch-independent implementations of XenBusDxe atomics using GCC __builtins
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+UINT16
+EFIAPI
+InternalSyncCompareExchange16 (
+  IN      volatile UINT16           *Value,
+  IN      UINT16                    CompareValue,
+  IN      UINT16                    ExchangeValue
+  )
+{
+  return __sync_val_compare_and_swap_2 (Value, CompareValue, ExchangeValue);
+}
+
+INT32
+EFIAPI
+TestAndClearBit (
+  IN INT32            Bit,
+  IN volatile VOID    *Address
+  )
+{
+  //
+  // Calculate the effective address relative to 'Address' based on the
+  // higher order bits of 'Bit'. Use signed shift instead of division to
+  // ensure we round towards -Inf, and end up with a positive shift in 'Bit',
+  // even if 'Bit' itself is negative.
+  //
+  Address += (Bit >> 5) * sizeof(INT32);
+  Bit &= 31;
+
+  return (__sync_fetch_and_and_4 (Address, ~(1U << Bit)) & (1U << Bit)) != 0;
+}
OvmfPkg/XenBusDxe/XenBusDxe.inf +3 -0
index 31553ac5a64a..949ec0a0c732 100644
@@ -54,6 +54,9 @@
   X64/InterlockedCompareExchange16.nasm
   X64/TestAndClearBit.nasm
 
+[Sources.AARCH64, Sources.ARM]
+  AtomicsGcc.c | GCC
+
 [LibraryClasses]
   UefiDriverEntryPoint
   UefiBootServicesTableLib
Signature · 1 line
1.8.3.2
#24 lore raw

PATCH v2 24/29 Ovmf/Xen: add Xen PV console SerialPortLib driver

In reply to a message not in the archive

This implements a SerialPortLib instance that wires up to the PV console ring used by domU guests. Also imports the required upstream Xen io/console.h header.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/IndustryStandard/Xen/io/console.h                   |  51 ++++++++++++++++++++++++++
 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c   | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf |  34 +++++++++++++++++
 3 files changed, 232 insertions(+)
OvmfPkg/Include/IndustryStandard/Xen/io/console.h new file +51 -0
new file mode 100644
index 000000000000..f1caa9765bcf
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * console.h
+ *
+ * Console I/O interface for Xen guest OSes.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2005, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_IO_CONSOLE_H__
+#define __XEN_PUBLIC_IO_CONSOLE_H__
+
+typedef UINT32 XENCONS_RING_IDX;
+
+#define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1))
+
+struct xencons_interface {
+    char in[1024];
+    char out[2048];
+    XENCONS_RING_IDX in_cons, in_prod;
+    XENCONS_RING_IDX out_cons, out_prod;
+};
+
+#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c new file +147 -0

147 lines not on this page · raw message

OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf new file +34 -0
new file mode 100644
index 000000000000..f7925b3e6bc3
@@ -0,0 +1,34 @@
+#/** @file
+#
+#  Component description file for XenConsoleSerialPortLib module
+#
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenConsoleSerialPortLib
+  FILE_GUID                      = 401406DD-BCAC-4B91-9F4E-72A7FEBE4762
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = SerialPortLib
+
+[Sources.common]
+  XenConsoleSerialPortLib.c
+
+[LibraryClasses]
+  BaseLib
+  XenHypercallLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
Signature · 1 line
1.8.3.2
#25 lore raw

PATCH v2 25/29 Ovmf/Xen: implement dummy RealTimeClockLib for Xen

In reply to a message not in the archive

This implements a dummy RealTimeClockLib for Xen, as there is no guest interface to access the time kept by Xen that can be shared between UEFI and the OS.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c   | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf |  38 ++++++++++++++++
 2 files changed, 234 insertions(+)
OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c new file +196 -0
new file mode 100644
index 000000000000..70204ac22a92
@@ -0,0 +1,196 @@
+/** @file
+  Implement EFI RealTimeClock runtime services via Xen shared info page
+
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Uefi.h>
+#include <PiDxe.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+
+/**
+  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
+ **/
+STATIC
+VOID
+EpochToEfiTime (
+  IN  UINTN     EpochSeconds,
+  OUT EFI_TIME  *Time
+  )
+{
+  UINTN         a;
+  UINTN         b;
+  UINTN         c;
+  UINTN         d;
+  UINTN         g;
+  UINTN         j;
+  UINTN         m;
+  UINTN         y;
+  UINTN         da;
+  UINTN         db;
+  UINTN         dc;
+  UINTN         dg;
+  UINTN         hh;
+  UINTN         mm;
+  UINTN         ss;
+  UINTN         J;
+
+  J  = (EpochSeconds / 86400) + 2440588;
+  j  = J + 32044;
+  g  = j / 146097;
+  dg = j % 146097;
+  c  = (((dg / 36524) + 1) * 3) / 4;
+  dc = dg - (c * 36524);
+  b  = dc / 1461;
+  db = dc % 1461;
+  a  = (((db / 365) + 1) * 3) / 4;
+  da = db - (a * 365);
+  y  = (g * 400) + (c * 100) + (b * 4) + a;
+  m  = (((da * 5) + 308) / 153) - 2;
+  d  = da - (((m + 4) * 153) / 5) + 122;
+
+  Time->Year  = y - 4800 + ((m + 2) / 12);
+  Time->Month = ((m + 2) % 12) + 1;
+  Time->Day   = d + 1;
+
+  ss = EpochSeconds % 60;
+  a  = (EpochSeconds - ss) / 60;
+  mm = a % 60;
+  b = (a - mm) / 60;
+  hh = b % 24;
+
+  Time->Hour        = hh;
+  Time->Minute      = mm;
+  Time->Second      = ss;
+  Time->Nanosecond  = 0;
+
+}
+
+/**
+  Returns the current time and date information, and the time-keeping capabilities
+  of the hardware platform.
+
+  @param  Time                  A pointer to storage to receive a snapshot of the current time.
+  @param  Capabilities          An optional pointer to a buffer to receive the real time clock
+                                device's capabilities.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+  @retval EFI_INVALID_PARAMETER Time is NULL.
+  @retval EFI_DEVICE_ERROR      The time could not be retrieved due to hardware error.
+
+**/
+EFI_STATUS
+EFIAPI
+LibGetTime (
+  OUT EFI_TIME                *Time,
+  OUT  EFI_TIME_CAPABILITIES  *Capabilities
+  )
+{
+  ASSERT (Time != NULL);
+
+  //
+  // For now, there is nothing that we can do besides returning a bogus time,
+  // as Xen's timekeeping uses a shared info page which cannot be shared
+  // between UEFI and the OS
+  //
+  EpochToEfiTime(1421770011, Time);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Sets the current local time and date information.
+
+  @param  Time                  A pointer to the current time.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+  @retval EFI_INVALID_PARAMETER A time field is out of range.
+  @retval EFI_DEVICE_ERROR      The time could not be set due due to hardware error.
+
+**/
+EFI_STATUS
+EFIAPI
+LibSetTime (
+  IN EFI_TIME                *Time
+  )
+{
+  return EFI_DEVICE_ERROR;
+}
+
+
+/**
+  Returns the current wakeup alarm clock setting.
+
+  @param  Enabled               Indicates if the alarm is currently enabled or disabled.
+  @param  Pending               Indicates if the alarm signal is pending and requires acknowledgement.
+  @param  Time                  The current alarm setting.
+
+  @retval EFI_SUCCESS           The alarm settings were returned.
+  @retval EFI_INVALID_PARAMETER Any parameter is NULL.
+  @retval EFI_DEVICE_ERROR      The wakeup time could not be retrieved due to a hardware error.
+  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.
+
+**/
+EFI_STATUS
+EFIAPI
+LibGetWakeupTime (
+  OUT BOOLEAN     *Enabled,
+  OUT BOOLEAN     *Pending,
+  OUT EFI_TIME    *Time
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Sets the system wakeup alarm clock time.
+
+  @param  Enabled               Enable or disable the wakeup alarm.
+  @param  Time                  If Enable is TRUE, the time to set the wakeup alarm for.
+
+  @retval EFI_SUCCESS           If Enable is TRUE, then the wakeup alarm was enabled. If
+                                Enable is FALSE, then the wakeup alarm was disabled.
+  @retval EFI_INVALID_PARAMETER A time field is out of range.
+  @retval EFI_DEVICE_ERROR      The wakeup time could not be set due to a hardware error.
+  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.
+
+**/
+EFI_STATUS
+EFIAPI
+LibSetWakeupTime (
+  IN BOOLEAN      Enabled,
+  OUT EFI_TIME    *Time
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This is the declaration of an EFI image entry point. This can be the entry point to an application
+  written to this specification, an EFI boot service driver, or an EFI runtime driver.
+
+  @param  ImageHandle           Handle that identifies the loaded image.
+  @param  SystemTable           System Table for this image.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+LibRtcInitialize (
+  IN EFI_HANDLE                            ImageHandle,
+  IN EFI_SYSTEM_TABLE                      *SystemTable
+  )
+{
+  return EFI_SUCCESS;
+}
OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf new file +38 -0
new file mode 100644
index 000000000000..aafbfda6b491
@@ -0,0 +1,38 @@
+#/** @file
+#
+# Copyright (c) 2015, L Ltd. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenRealTimeClockLib
+  FILE_GUID                      = EC2557E8-7005-430B-9F6F-9BA109698248
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = RealTimeClockLib|DXE_CORE DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
+
+[Sources.common]
+  XenRealTimeClockLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+
+[LibraryClasses]
+  UefiLib
+  DebugLib
+  DxeServicesTableLib
+  UefiRuntimeLib
+
+[Guids]
+  gEfiEventVirtualAddressChangeGuid
Signature · 1 line
1.8.3.2
#26 lore raw

PATCH v2 26/29 Ovfm/Xen: add a Vendor Hardware device path GUID for the XenBus root

In reply to a message not in the archive

On non-PCI Xen guests (such as ARM), the XenBus root is not a PCI device but an abstract 'platform' device. Add a dedicated Vendor Hardware device path GUID to identify this node.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/Guid/XenBusRootDevice.h | 24 ++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                     |  1 +
 2 files changed, 25 insertions(+)
OvmfPkg/Include/Guid/XenBusRootDevice.h new file +24 -0
new file mode 100644
index 000000000000..2b6e71018052
@@ -0,0 +1,24 @@
+/** @file
+  GUID to be used to identify the XenBus root node on non-PCI Xen guests
+
+  Copyright (C) 2015, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License that accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __XENBUS_ROOT_DEVICE_H__
+#define __XENBUS_ROOT_DEVICE_H__
+
+#define XENBUS_ROOT_DEVICE_GUID \
+{0xa732241f, 0x383d, 0x4d9c, {0x8a, 0xe1, 0x8e, 0x09, 0x83, 0x75, 0x89, 0xd7}}
+
+extern EFI_GUID gXenBusRootDeviceGuid;
+
+#endif
OvmfPkg/OvmfPkg.dec +1 -0
index 3711fa922311..d61600225919 100644
@@ -53,6 +53,7 @@
   gEfiXenInfoGuid                 = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}
   gOvmfPlatformConfigGuid         = {0x7235c51c, 0x0c80, 0x4cab, {0x87, 0xac, 0x3b, 0x08, 0x4a, 0x63, 0x04, 0xb1}}
   gVirtioMmioTransportGuid        = {0x837dca9e, 0xe874, 0x4d82, {0xb2, 0x9a, 0x23, 0xfe, 0x0e, 0x23, 0xd1, 0xe2}}
+  gXenBusRootDeviceGuid           = {0xa732241f, 0x383d, 0x4d9c, {0x8a, 0xe1, 0x8e, 0x09, 0x83, 0x75, 0x89, 0xd7}}
 
 [Protocols]
   gVirtioDeviceProtocolGuid       = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
Signature · 1 line
1.8.3.2
#27 lore raw

PATCH v2 27/29 ArmVirtualizationPkg: add XenIoMmioLib

In reply to a message not in the archive

This adds a XenIoMmioLib declaration and implementation that can be invoked to install the XENIO_PROTOCOL and a corresponding grant table address on a EFI handle.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec              |  6 +++++
 ArmPlatformPkg/ArmVirtualizationPkg/Include/Library/XenIoMmioLib.h        | 20 +++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c   | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf | 38 +++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +6 -0
index 868488906643..c690f1481093 100644
@@ -30,6 +30,12 @@
 [Includes.common]
   Include                        # Root include for the package
 
+[LibraryClasses]
+  #
+  # library to create handles containing the XENIO_PROTOCOL I/O protocol
+  #
+  XenIoMmioLib|Include/Library/XenIoMmioLib.h
+
 [Guids.common]
   gArmVirtualizationTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
ArmPlatformPkg/ArmVirtualizationPkg/Include/Library/XenIoMmioLib.h new file +20 -0
new file mode 100644
index 000000000000..faeabe5affe0
@@ -0,0 +1,20 @@
+/** @file
+*  Library to install the XENIO_PROTOCOL on a handle
+*
+*  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+*
+*  This program and the accompanying materials are
+*  licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+EFI_STATUS
+XenIoMmioInstall (
+  IN  EFI_HANDLE  *Handle,
+  IN  UINT64      GrantTableAddress
+  );
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +91 -0

91 lines not on this page · raw message

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf new file +38 -0
new file mode 100644
index 000000000000..14f24ff7fd2c
@@ -0,0 +1,38 @@
+## @file
+# Library to install the XENIO_PROTOCOL on a handle
+#
+# Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php.
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenIoMmioLib
+  FILE_GUID                      = 3CD90EEC-EBF3-425D-AAE8-B16215AC4F50
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = XenIoMmioLib
+
+[Sources]
+  XenIoMmioLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+
+[Guids]
+  gXenBusRootDeviceGuid
+
+[Protocols]
+  gEfiDevicePathProtocolGuid
Signature · 1 line
1.8.3.2
#28 lore raw

PATCH v2 28/29 ArmVirtualizationPkg/VirtFdtDxe: wire up XenBusDxe to "xen, xen" DT node

In reply to a message not in the archive

This patchs adds support to VirtFdtDxe for the Xen DT node which contains the base address of the Grant Table. This data is communicated to XenBusDxe using a XENIO_PROTOCOL instance.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c   | 23 +++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf |  1 +
 2 files changed, 24 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +23 -0
index 34fac40fa803..1ceb85146430 100644
@@ -26,6 +26,7 @@
 #include <Library/DxeServicesLib.h>
 #include <Library/HobLib.h>
 #include <libfdt.h>
+#include <Library/XenIoMmioLib.h>
 
 #include <Guid/Fdt.h>
 #include <Guid/VirtioMmioTransport.h>
@@ -49,6 +50,7 @@ typedef enum {
   PropertyTypePsci,
   PropertyTypeFwCfg,
   PropertyTypeGicV3,
+  PropertyTypeXen,
 } PROPERTY_TYPE;
 
 typedef struct {
@@ -66,6 +68,7 @@ STATIC CONST PROPERTY CompatibleProperties[] = {
   { PropertyTypePsci,    "arm,psci-0.2"        },
   { PropertyTypeFwCfg,   "qemu,fw-cfg-mmio"    },
   { PropertyTypeGicV3,   "arm,gic-v3"          },
+  { PropertyTypeXen,     "xen,xen"             },
   { PropertyTypeUnknown, ""                    }
 };
 
@@ -332,6 +335,26 @@ InitializeVirtFdtDxe (
       }
       break;
 
+    case PropertyTypeXen:
+      ASSERT (Len == 16);
+
+      //
+      // Retrieve the reg base from this node and add it to a
+      // XENIO_PROTOCOL instance installed on a new handle.
+      //
+      RegBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);
+      Handle = NULL;
+      Status = XenIoMmioInstall (&Handle, RegBase);
+      if (EFI_ERROR (Status)) {
+        DEBUG ((EFI_D_ERROR, "%a: Failed to install XENIO_PROTOCOL on a new handle "
+          "(Status == %r)\n", __FUNCTION__, Status));
+        break;
+      }
+
+      DEBUG ((EFI_D_INFO, "Found Xen node with Grant table @ 0x%p\n", RegBase));
+
+      break;
+
     default:
       break;
     }
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf +1 -0
index 1392c7c3fa45..f8a58238c37b 100644
@@ -41,6 +41,7 @@
   FdtLib
   VirtioMmioDeviceLib
   HobLib
+  XenIoMmioLib
 
 [Guids]
   gFdtTableGuid
Signature · 1 line
1.8.3.2
#29 lore raw

PATCH v2 29/29 ArmVirtualizationPkg: add platform description for Xen guests

In reply to a message not in the archive

This adds the .dsc and .fdf descriptions to build a UEFI image that is bootable by a Xen guest on 64-bit ARM (AArch64)

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf | 337 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 616 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +279 -0
new file mode 100644
index 000000000000..bcc9742c6828
@@ -0,0 +1,279 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+################################################################################
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+[Defines]
+  PLATFORM_NAME                  = ArmVirtualizationQemu
+  PLATFORM_GUID                  = 37d7e986-f7e9-45c2-8067-e371421a626c
+  PLATFORM_VERSION               = 0.1
+  DSC_SPECIFICATION              = 0x00010005
+  OUTPUT_DIRECTORY               = Build/ArmVirtualizationXen-$(ARCH)
+  SUPPORTED_ARCHITECTURES        = AARCH64
+  BUILD_TARGETS                  = DEBUG|RELEASE
+  SKUID_IDENTIFIER               = DEFAULT
+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf
+
+!include ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
+
+[LibraryClasses]
+  SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
+  XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf
+  XenIoMmioLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf
+
+[LibraryClasses.AARCH64]
+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf
+
+[LibraryClasses.ARM]
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf
+
+[LibraryClasses.common]
+  # Virtio Support
+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
+
+  ArmPlatformLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
+  ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf
+
+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
+
+!ifdef INTEL_BDS
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+  GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+  PlatformBdsLib|ArmPlatformPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
+  CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+!endif
+
+[LibraryClasses.common.UEFI_DRIVER]
+  UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+
+[LibraryClasses.AARCH64.SEC]
+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf
+
+[LibraryClasses.ARM.SEC]
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf
+
+[BuildOptions]
+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+  GCC:*_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+ 
+################################################################################
+#
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform
+#
+################################################################################
+
+[PcdsFeatureFlag.common]
+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.
+  #  It could be set FALSE to save size.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE
+
+[PcdsFixedAtBuild.common]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F
+
+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"XEN-UEFI"
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"$(FIRMWARE_VER)"
+
+  gArmPlatformTokenSpaceGuid.PcdCoreCount|1
+!if $(ARCH) == AARCH64
+  gArmTokenSpaceGuid.PcdVFPEnabled|1
+!endif
+
+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000
+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000
+
+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000
+
+  #
+  # ARM Pcds
+  #
+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000
+
+  ## Trustzone enable (to make the transition from EL3 to EL2 in ArmPlatformPkg/Sec)
+  gArmTokenSpaceGuid.PcdTrustzoneSupport|FALSE
+
+  #
+  # ARM PrimeCell
+  #
+
+  ## PL011 - Serial Terminal
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400
+
+  #
+  # ARM OS Loader
+  #
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux (EFI stub) on virtio31:hd0:part0"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000)/HD(1,MBR,0x00000000,0x3F,0x19FC0)/Image"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 console=ttyAMA0 earlycon uefi_debug"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|0
+
+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)
+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"
+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"
+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|3
+
+  #
+  # ARM Virtual Architectural Timer
+  #
+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000
+
+  #
+  # NV Storage PCDs. Use base of 0x04000000 for NOR1
+  #
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x04000000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x04040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x04080000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00040000
+
+!ifdef INTEL_BDS
+  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
+!endif
+
+[PcdsPatchableInModule.common]
+  #
+  # This will be overridden in the code
+  #
+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x0
+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x0
+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0
+
+  gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
+  gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
+
+[PcdsDynamicDefault.common]
+
+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0
+
+  #
+  # ARM General Interrupt Controller
+  #
+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x0
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x0
+
+  ## PL031 RealTimeClock
+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0
+
+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0
+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress|0x0
+
+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod|0
+
+################################################################################
+#
+# Components Section - list of all EDK II Modules needed by this Platform
+#
+################################################################################
+[Components.common]
+  #
+  # PEI Phase modules
+  #
+  ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf {
+    <LibraryClasses>
+      ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
+      LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
+      PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
+      HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
+      PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
+      MemoryInitPeiLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf
+      ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf
+      MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf
+      SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+      DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
+  }
+
+  #
+  # DXE
+  #
+  MdeModulePkg/Core/Dxe/DxeMain.inf {
+    <LibraryClasses>
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
+  }
+  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+
+  #
+  # Architectural Protocols
+  #
+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf
+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+
+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
+
+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
+
+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+
+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # Platform Driver
+  #
+  ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+  OvmfPkg/VirtioNetDxe/VirtioNet.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Bds
+  #
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+!ifdef INTEL_BDS
+  MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
+  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+!else
+  ArmPlatformPkg/Bds/Bds.inf
+!endif
+
+  #
+  # SCSI Bus and Disk Driver
+  #
+  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+
+  OvmfPkg/XenBusDxe/XenBusDxe.inf
+  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +337 -0

337 lines not on this page · raw message

Signature · 1 line
1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#31 lore raw

Re: [PATCH v2 24/29] Ovmf/Xen: add Xen PV console SerialPortLib driver

Hi Ard,

Review

Quoted 9 lines · Ard Biesheuvel
(quoted diff) +9 -0
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+  VOID
+  )
+{
+  mXenConsoleEventChain.port = (UINT32)XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_EVTCHN);
+  mXenConsoleInterface = (struct xencons_interface *)(UINTN)
+    (XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_PFN) << EFI_PAGE_SHIFT);

IIRC, x86 PVH is using a different way to get the console PFN.

It might be good to add a comment stating we only support x86 HVM and ARM guest here.

Regards,

Signature · 1 line
Julien Grall
Reviewed-by
#32 lore raw

Re: [PATCH v2 24/29] Ovmf/Xen: add Xen PV console SerialPortLib driver

In reply to a message not in the archive
Quoted 6 lines · Ard Biesheuvel

This implements a SerialPortLib instance that wires up to the PV console ring used by domU guests. Also imports the required upstream Xen io/console.h header.

Contributed-under: TianoCore Contribution Agreement 1.0

Quoted 264 lines
 OvmfPkg/Include/IndustryStandard/Xen/io/console.h                   |  51 ++++++++++++++++++++++++++
 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c   | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf |  34 +++++++++++++++++
 3 files changed, 232 insertions(+)
OvmfPkg/Include/IndustryStandard/Xen/io/console.h new file +51 -0
new file mode 100644
index 000000000000..f1caa9765bcf
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * console.h
+ *
+ * Console I/O interface for Xen guest OSes.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2005, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_IO_CONSOLE_H__
+#define __XEN_PUBLIC_IO_CONSOLE_H__
+
+typedef UINT32 XENCONS_RING_IDX;
+
+#define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1))
+
+struct xencons_interface {
+    char in[1024];
+    char out[2048];
+    XENCONS_RING_IDX in_cons, in_prod;
+    XENCONS_RING_IDX out_cons, out_prod;
+};
+
+#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c new file +147 -0
new file mode 100644
index 000000000000..97344dc4efb0
@@ -0,0 +1,147 @@
+/** @file
+  Xen console SerialPortLib instance
+
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Uefi/UefiBaseType.h>
+
+#include <Library/BaseLib.h>
+#include <Library/SerialPortLib.h>
+#include <Library/XenHypercallLib.h>
+
+#include <IndustryStandard/Xen/io/console.h>
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/event_channel.h>
+
+STATIC evtchn_send_t              mXenConsoleEventChain;
+STATIC struct xencons_interface   *mXenConsoleInterface;
+
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+  VOID
+  )
+{
+  mXenConsoleEventChain.port = (UINT32)XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_EVTCHN);
+  mXenConsoleInterface = (struct xencons_interface *)(UINTN)
+    (XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_PFN) << EFI_PAGE_SHIFT);
+
+  //
+  // No point in ASSERT'ing here as we won't be seeing the output
+  //
+  return RETURN_SUCCESS;
+}
+
+/**
+  Write data to serial device.
+
+  @param  Buffer           Point of data buffer which need to be written.
+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.
+
+  @retval 0                Write data failed.
+  @retval !0               Actual number of bytes written to serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+  IN UINT8     *Buffer,
+  IN UINTN     NumberOfBytes
+  )
+{
+  XENCONS_RING_IDX  Consumer, Producer;
+  UINTN             Sent;
+
+  if (!mXenConsoleInterface) {
+    return 0;
+  }
+
+  Consumer = mXenConsoleInterface->out_cons;
+  Producer = mXenConsoleInterface->out_prod;
+
+  MemoryFence ();
+
+  Sent = 0;
+  while (Sent < NumberOfBytes && ((Producer - Consumer) < sizeof (mXenConsoleInterface->out)))
+    mXenConsoleInterface->out[MASK_XENCONS_IDX(Producer++, mXenConsoleInterface->out)] = Buffer[Sent++];
+
+  MemoryFence ();
+
+  mXenConsoleInterface->out_prod = Producer;
+
+  if (Sent > 0) {
+    XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain);
+  }
+
+  return Sent;
+}
+
+/**
+  Read data from serial device and save the data in buffer.
+
+  @param  Buffer           Point of data buffer which need to be written.
+  @param  NumberOfBytes    Size of Buffer[].
+
+  @retval 0                Read data failed.
+  @retval !0               Actual number of bytes read from serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+  OUT UINT8     *Buffer,
+  IN  UINTN     NumberOfBytes
+)
+{
+  XENCONS_RING_IDX  Consumer, Producer;
+  UINTN             Received;
+
+  if (!mXenConsoleInterface) {
+    return 0;
+  }
+
+  Consumer = mXenConsoleInterface->in_cons;
+  Producer = mXenConsoleInterface->in_prod;
+
+  MemoryFence ();
+
+  Received = 0;
+  while (Received < NumberOfBytes && Consumer < Producer)
+     Buffer[Received++] = mXenConsoleInterface->in[MASK_XENCONS_IDX(Consumer++, mXenConsoleInterface->in)];
+
+  MemoryFence ();
+
+  mXenConsoleInterface->in_cons = Consumer;
+
+  XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain);
+
+  return Received;
+}
+
+/**
+  Check to see if any data is available to be read from the debug device.
+
+  @retval TRUE       At least one byte of data is available to be read
+  @retval FALSE      No data is available to be read
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+  VOID
+  )
+{
+  return mXenConsoleInterface &&
+    mXenConsoleInterface->in_cons != mXenConsoleInterface->in_prod;
+}
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf new file +34 -0
new file mode 100644
index 000000000000..f7925b3e6bc3
@@ -0,0 +1,34 @@
+#/** @file
+#
+#  Component description file for XenConsoleSerialPortLib module
+#
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenConsoleSerialPortLib
+  FILE_GUID                      = 401406DD-BCAC-4B91-9F4E-72A7FEBE4762
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = SerialPortLib
+
+[Sources.common]
+  XenConsoleSerialPortLib.c
+
+[LibraryClasses]
+  BaseLib
+  XenHypercallLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
Signature · 7 lines
1.8.3.2


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#33 lore raw

Re: [PATCH v2 24/29] Ovmf/Xen: add Xen PV console SerialPortLib driver

In reply to a message not in the archive

Unless I'm wrong, please:

Quoted 93 lines · Ard Biesheuvel

This implements a SerialPortLib instance that wires up to the PV console ring used by domU guests. Also imports the required upstream Xen io/console.h header.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/IndustryStandard/Xen/io/console.h                   |  51 ++++++++++++++++++++++++++
 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c   | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf |  34 +++++++++++++++++
 3 files changed, 232 insertions(+)
OvmfPkg/Include/IndustryStandard/Xen/io/console.h new file +51 -0
new file mode 100644
index 000000000000..f1caa9765bcf
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * console.h
+ *
+ * Console I/O interface for Xen guest OSes.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2005, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_IO_CONSOLE_H__
+#define __XEN_PUBLIC_IO_CONSOLE_H__
+
+typedef UINT32 XENCONS_RING_IDX;
+
+#define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1))
+
+struct xencons_interface {
+    char in[1024];
+    char out[2048];
+    XENCONS_RING_IDX in_cons, in_prod;
+    XENCONS_RING_IDX out_cons, out_prod;
+};
+
+#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c new file +18 -0
new file mode 100644
index 000000000000..97344dc4efb0
@@ -0,0 +1,147 @@
+/** @file
+  Xen console SerialPortLib instance
+
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Uefi/UefiBaseType.h>
+

OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c line 28

Quoted 10 lines
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c new file +10 -0
+#include <Library/BaseLib.h>
+#include <Library/SerialPortLib.h>
+#include <Library/XenHypercallLib.h>
+
+#include <IndustryStandard/Xen/io/console.h>
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/event_channel.h>
+
+STATIC evtchn_send_t              mXenConsoleEventChain;
+STATIC struct xencons_interface   *mXenConsoleInterface;

add a big fat warning above these variables with static storage duration. You didn't restrict the UEFI phases in which this library is usable, hence I'm thinking you'll use it in PEIMs and probably even in SEC. Writable globals in SEC & PEI depend on those phases running out of DRAM, not flash, which makes this library specific to PrePi. I think the variables above merit a comment about this.

No other comments from me for this patch (the R-b from Stefano should suffice).

Thanks
Laszlo

Quoted 160 lines
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c new file +119 -0
+
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+  VOID
+  )
+{
+  mXenConsoleEventChain.port = (UINT32)XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_EVTCHN);
+  mXenConsoleInterface = (struct xencons_interface *)(UINTN)
+    (XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_PFN) << EFI_PAGE_SHIFT);
+
+  //
+  // No point in ASSERT'ing here as we won't be seeing the output
+  //
+  return RETURN_SUCCESS;
+}
+
+/**
+  Write data to serial device.
+
+  @param  Buffer           Point of data buffer which need to be written.
+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.
+
+  @retval 0                Write data failed.
+  @retval !0               Actual number of bytes written to serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+  IN UINT8     *Buffer,
+  IN UINTN     NumberOfBytes
+  )
+{
+  XENCONS_RING_IDX  Consumer, Producer;
+  UINTN             Sent;
+
+  if (!mXenConsoleInterface) {
+    return 0;
+  }
+
+  Consumer = mXenConsoleInterface->out_cons;
+  Producer = mXenConsoleInterface->out_prod;
+
+  MemoryFence ();
+
+  Sent = 0;
+  while (Sent < NumberOfBytes && ((Producer - Consumer) < sizeof (mXenConsoleInterface->out)))
+    mXenConsoleInterface->out[MASK_XENCONS_IDX(Producer++, mXenConsoleInterface->out)] = Buffer[Sent++];
+
+  MemoryFence ();
+
+  mXenConsoleInterface->out_prod = Producer;
+
+  if (Sent > 0) {
+    XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain);
+  }
+
+  return Sent;
+}
+
+/**
+  Read data from serial device and save the data in buffer.
+
+  @param  Buffer           Point of data buffer which need to be written.
+  @param  NumberOfBytes    Size of Buffer[].
+
+  @retval 0                Read data failed.
+  @retval !0               Actual number of bytes read from serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+  OUT UINT8     *Buffer,
+  IN  UINTN     NumberOfBytes
+)
+{
+  XENCONS_RING_IDX  Consumer, Producer;
+  UINTN             Received;
+
+  if (!mXenConsoleInterface) {
+    return 0;
+  }
+
+  Consumer = mXenConsoleInterface->in_cons;
+  Producer = mXenConsoleInterface->in_prod;
+
+  MemoryFence ();
+
+  Received = 0;
+  while (Received < NumberOfBytes && Consumer < Producer)
+     Buffer[Received++] = mXenConsoleInterface->in[MASK_XENCONS_IDX(Consumer++, mXenConsoleInterface->in)];
+
+  MemoryFence ();
+
+  mXenConsoleInterface->in_cons = Consumer;
+
+  XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain);
+
+  return Received;
+}
+
+/**
+  Check to see if any data is available to be read from the debug device.
+
+  @retval TRUE       At least one byte of data is available to be read
+  @retval FALSE      No data is available to be read
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+  VOID
+  )
+{
+  return mXenConsoleInterface &&
+    mXenConsoleInterface->in_cons != mXenConsoleInterface->in_prod;
+}
OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf new file +34 -0
new file mode 100644
index 000000000000..f7925b3e6bc3
@@ -0,0 +1,34 @@
+#/** @file
+#
+#  Component description file for XenConsoleSerialPortLib module
+#
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenConsoleSerialPortLib
+  FILE_GUID                      = 401406DD-BCAC-4B91-9F4E-72A7FEBE4762
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = SerialPortLib
+
+[Sources.common]
+  XenConsoleSerialPortLib.c
+
+[LibraryClasses]
+  BaseLib
+  XenHypercallLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec

A message that is not in the archive (sent off-list or not yet received): [email protected]

#35 lore raw

Re: [PATCH v2 28/29] ArmVirtualizationPkg/VirtFdtDxe: wire up XenBusDxe to "xen, xen" DT node

Hi Ard,

Quoted 10 lines · Ard Biesheuvel

typedef struct {

(quoted diff) +1 -0
@@ -66,6 +68,7 @@ STATIC CONST PROPERTY CompatibleProperties[] = {
   { PropertyTypePsci,    "arm,psci-0.2"        },
   { PropertyTypeFwCfg,   "qemu,fw-cfg-mmio"    },
   { PropertyTypeGicV3,   "arm,gic-v3"          },
+  { PropertyTypeXen,     "xen,xen"             },
   { PropertyTypeUnknown, ""                    }
 };
 

Review InitializeVirtFdtDxe ( · line 340

Quoted 6 lines
(quoted diff) +3 -0
@@ -332,6 +335,26 @@ InitializeVirtFdtDxe (
       }
       break;
 
+    case PropertyTypeXen:
+      ASSERT (Len == 16);
+

I would not assume that the reg property is always 16 bytes (8 bytes for the address and 8 bytes for the size). We may decide to change it in the future. That's why #address-cells and #size-cells exist in the DT.

But it looks like that the other part of the code in this function always assume a fixed length. I guess we could live with it. I would add a comment explaining this restriction.

Regards,

Signature · 1 line
Julien Grall
#36 lore raw

Re: [PATCH v2 28/29] ArmVirtualizationPkg/VirtFdtDxe: wire up XenBusDxe to "xen, xen" DT node

Quoted 16 lines · Julien Grall

Hi Ard,

Quoted 13 lines · Ard Biesheuvel

typedef struct {

(quoted diff) +1 -0
@@ -66,6 +68,7 @@ STATIC CONST PROPERTY CompatibleProperties[] = {
   { PropertyTypePsci,    "arm,psci-0.2"        },
   { PropertyTypeFwCfg,   "qemu,fw-cfg-mmio"    },
   { PropertyTypeGicV3,   "arm,gic-v3"          },
+  { PropertyTypeXen,     "xen,xen"             },
   { PropertyTypeUnknown, ""                    }
 };
 
@@ -332,6 +335,26 @@ InitializeVirtFdtDxe (
       }
       break;
 
Quoted 8 lines

Review InitializeVirtFdtDxe ( · line 340

Quoted 3 lines
(quoted diff) +3 -0
+    case PropertyTypeXen:
+      ASSERT (Len == 16);
+

I would not assume that the reg property is always 16 bytes (8 bytes for the address and 8 bytes for the size). We may decide to change it in the future. That's why #address-cells and #size-cells exist in the DT.

Yes, you are quite correct. However, this code was originally created as a counterpart to QEMU/mach-virt, which is known to use 64-bit quantities for memory ranges, and adding variable address size support to it implies that we need to start caring about how the nodes are nested, which we currently don't. (#address-cells and #size-cells properties are inherited by child nodes)

For Xen on arm64, #address-cells = 2 and #size-cells = 2 is the only meaningful option anyway, but I agree that blindly assuming it is not the most elegant approach.

Quoted 4 lines

But it looks like that the other part of the code in this function always assume a fixed length. I guess we could live with it. I would add a comment explaining this restriction.

Indeed.

Signature · 1 line
Ard.
Reviewed-by
#37 lore raw

Re: [PATCH v2 28/29] ArmVirtualizationPkg/VirtFdtDxe: wire up XenBusDxe to "xen, xen" DT node

In reply to a message not in the archive
Quoted 46 lines · Ard Biesheuvel

This patchs adds support to VirtFdtDxe for the Xen DT node which contains the base address of the Grant Table. This data is communicated to XenBusDxe using a XENIO_PROTOCOL instance.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c   | 23 +++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf |  1 +
 2 files changed, 24 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +6 -0
index 34fac40fa803..1ceb85146430 100644
@@ -26,6 +26,7 @@
 #include <Library/DxeServicesLib.h>
 #include <Library/HobLib.h>
 #include <libfdt.h>
+#include <Library/XenIoMmioLib.h>
 
 #include <Guid/Fdt.h>
 #include <Guid/VirtioMmioTransport.h>
@@ -49,6 +50,7 @@ typedef enum {
   PropertyTypePsci,
   PropertyTypeFwCfg,
   PropertyTypeGicV3,
+  PropertyTypeXen,
 } PROPERTY_TYPE;
 
 typedef struct {
@@ -66,6 +68,7 @@ STATIC CONST PROPERTY CompatibleProperties[] = {
   { PropertyTypePsci,    "arm,psci-0.2"        },
   { PropertyTypeFwCfg,   "qemu,fw-cfg-mmio"    },
   { PropertyTypeGicV3,   "arm,gic-v3"          },
+  { PropertyTypeXen,     "xen,xen"             },
   { PropertyTypeUnknown, ""                    }
 };
 
@@ -332,6 +335,26 @@ InitializeVirtFdtDxe (
       }
       break;
 
+    case PropertyTypeXen:
+      ASSERT (Len == 16);
+

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c InitializeVirtFdtDxe ( · line 350

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +10 -0
+      //
+      // Retrieve the reg base from this node and add it to a
+      // XENIO_PROTOCOL instance installed on a new handle.
+      //
+      RegBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);
+      Handle = NULL;
+      Status = XenIoMmioInstall (&Handle, RegBase);
+      if (EFI_ERROR (Status)) {
+        DEBUG ((EFI_D_ERROR, "%a: Failed to install XENIO_PROTOCOL on a new handle "
+          "(Status == %r)\n", __FUNCTION__, Status));

(1) I don't think it's necessary to mention XENIO_PROTOCOL here. XenIoMmioInstall() does more, and can fail for more reasons. I think it would suffice to mention XenIoMmioInstall() and the status it returns. (XenIoMmioInstall() logs errors internally anyway.) I don't insist though.

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c InitializeVirtFdtDxe ( · line 354

Quoted 4 lines
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +4 -0
+        break;
+      }
+
+      DEBUG ((EFI_D_INFO, "Found Xen node with Grant table @ 0x%p\n", RegBase));

(2) 0x%p is incorrect here, please say 0x%Lx. RegBase is not a pointer but a UINT64.

Quoted 12 lines
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +3 -0
+
+      break;
+
     default:
       break;
     }
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf +0 -0
index 1392c7c3fa45..f8a58238c37b 100644

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf line 47

Quoted 7 lines
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf +1 -0
@@ -41,6 +41,7 @@
   FdtLib
   VirtioMmioDeviceLib
   HobLib
+  XenIoMmioLib
 
 [Guids]
   gFdtTableGuid

With those changes:

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#39 lore raw

Re: [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

Quoted 311 lines · Ard Biesheuvel

This refactors the Xen hypercall implementation that is part of the XenBusDxe driver, in preparation of splitting it off entirely into a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall() prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info page is not strictly part of the Xen hypercall interface, and is not used by other expected users of XenHypercallLib such as the Xen console version of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage there; the existing asm implementations are renamed to __XenHypercall2() and invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/EventChannel.c      | 11 +++--------
 OvmfPkg/XenBusDxe/GrantTable.c        |  4 ++--
 OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
 OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c         | 44 +++++++++++++++++++++++++++++++++++++++++++-
 OvmfPkg/XenBusDxe/XenBusDxe.h         |  1 -
 OvmfPkg/XenBusDxe/XenHypercall.c      | 50 ++++++++++++++------------------------------------
 OvmfPkg/XenBusDxe/XenHypercall.h      | 28 +++-------------------------
 OvmfPkg/XenBusDxe/XenStore.c          |  4 ++--
 9 files changed, 73 insertions(+), 81 deletions(-)
OvmfPkg/XenBusDxe/EventChannel.c +3 -8
index 03efaf9cb904..a86323e6adfd 100644
@@ -28,7 +28,7 @@ XenEventChannelNotify (
   evtchn_send_t Send;
 
   Send.port = Port;
-  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send);
+  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, &Send);
   return (UINT32)ReturnCode;
 }
 
@@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
   OUT evtchn_port_t   *Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_alloc_unbound_t Parameter;
   UINT32 ReturnCode;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
-
   Parameter.dom = DOMID_SELF;
   Parameter.remote_dom = DomainId;
-  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private->Dev,
+  ReturnCode = (UINT32)XenHypercallEventChannelOp (
                                    EVTCHNOP_alloc_unbound,
                                    &Parameter);
   if (ReturnCode != 0) {
@@ -79,10 +76,8 @@ XenBusEventChannelClose (
   IN evtchn_port_t   Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_close_t Close;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
   Close.port = Port;
-  return (UINT32)XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close);
+  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, &Close);
 }
OvmfPkg/XenBusDxe/GrantTable.c +2 -2
index 8405edc51bc4..53cb99f0e004 100644
@@ -161,7 +161,7 @@ XenGrantTableInit (
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));
     }
@@ -184,7 +184,7 @@ XenGrantTableDeinit (
     Parameters.domid = DOMID_SELF;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, remove_from_physmap hypercall error: %d\n", ReturnCode));
     }
OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +3 -3
index 8547c30b81ee..e0fa71bb5ba8 100644
@@ -2,13 +2,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   ; Save only ebx, ecx is supposed to be a scratch register and needs to be
   ; saved by the caller
   push ebx
OvmfPkg/XenBusDxe/X64/hypercall.nasm +3 -3
index 177f271ef094..5e6a0c05c5c4 100644
@@ -3,13 +3,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   push rdi
   push rsi
   ; Copy HypercallAddr to rax
OvmfPkg/XenBusDxe/XenBusDxe.c +43 -1
index 7a7fd82d559d..d333b331b6db 100644
@@ -34,6 +34,8 @@
 #include "XenStore.h"
 #include "XenBus.h"
 
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
 
 ///
 /// Driver Binding Protocol instance
@@ -52,6 +54,46 @@ STATIC EFI_LOCK       mMyDeviceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK
 STATIC XENBUS_DEVICE *mMyDevice = NULL;
 
 /**
+  Map the shared_info_t page into memory.
+
+  @param Dev    A XENBUS_DEVICE instance.
+
+  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
+                          the shared info page
+  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
+                          hypercall returned an error.
+**/
+STATIC
+EFI_STATUS
+XenGetSharedInfoPage (
+  IN OUT XENBUS_DEVICE *Dev
+  )
+{
+  xen_add_to_physmap_t Parameter;
+
+  ASSERT (Dev->SharedInfo == NULL);
+
+  Parameter.domid = DOMID_SELF;
+  Parameter.space = XENMAPSPACE_shared_info;
+  Parameter.idx = 0;
+
+  //
+  // using reserved page because the page is not released when Linux is
+  // starting because of the add_to_physmap. QEMU might try to access the
+  // page, and fail because it have no right to do so (segv).
+  //
+  Dev->SharedInfo = AllocateReservedPages (1);
+  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
+  if (XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameter) != 0) {
+    FreePages (Dev->SharedInfo, 1);
+    Dev->SharedInfo = NULL;
+    return EFI_LOAD_ERROR;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   Unloads an image.
 
   @param  ImageHandle           Handle that identifies the image to be unloaded.
@@ -348,7 +390,7 @@ XenBusDxeDriverBindingStart (
   MmioAddr = BarDesc->AddrRangeMin;
   FreePool (BarDesc);
 
-  Status = XenHyperpageInit (Dev);
+  Status = XenHyperpageInit ();
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));
     Status = EFI_UNSUPPORTED;
OvmfPkg/XenBusDxe/XenBusDxe.h +0 -1
index 80253b7d1ca9..9b7219906a69 100644
@@ -91,7 +91,6 @@ struct _XENBUS_DEVICE {
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
 
-  VOID                          *Hyperpage;
   shared_info_t                 *SharedInfo;
 };
 
OvmfPkg/XenBusDxe/XenHypercall.c +13 -27
index 34d92e76b7e3..9bcf3197633e 100644
@@ -23,9 +23,10 @@
 #include <IndustryStandard/Xen/hvm/params.h>
 #include <IndustryStandard/Xen/memory.h>
 
+STATIC VOID       *Hyperpage;
+
 EFI_STATUS
 XenHyperpageInit (
-  IN OUT XENBUS_DEVICE *Dev
   )
 {
   EFI_HOB_GUID_TYPE   *GuidHob;
@@ -36,24 +37,21 @@ XenHyperpageInit (
     return EFI_NOT_FOUND;
   }
   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
-  Dev->Hyperpage = XenInfo->HyperPages;
+  Hyperpage = XenInfo->HyperPages;
   return EFI_SUCCESS;
 }
 
 UINT64
 XenHypercallHvmGetParam (
-  IN XENBUS_DEVICE *Dev,
   IN UINT32        Index
   )
 {
   xen_hvm_param_t     Parameter;
   INTN                Error;
 
-  ASSERT (Dev->Hyperpage != NULL);
-
   Parameter.domid = DOMID_SELF;
   Parameter.index = Index;
-  Error = XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_hvm_op * 32,
+  Error = XenHypercall2 (__HYPERVISOR_hvm_op,
                          HVMOP_get_param, (INTN) &Parameter);
   if (Error != 0) {
     DEBUG ((EFI_D_ERROR,
@@ -66,53 +64,33 @@ XenHypercallHvmGetParam (
 
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_memory_op * 32,
+  return XenHypercall2 (__HYPERVISOR_memory_op,
                         Operation, (INTN) Arguments);
 }
 
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32,
+  return XenHypercall2 (__HYPERVISOR_event_channel_op,
                         Operation, (INTN) Arguments);
 }
 
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
+INTN
+EFIAPI
+XenHypercall2 (
+  IN     INTN HypercallID,
+  IN OUT INTN Arg1,
+  IN OUT INTN Arg2
   )
 {
-  xen_add_to_physmap_t Parameter;
-
-  ASSERT (Dev->SharedInfo == NULL);
+  ASSERT (HyperPage != NULL);
 
-  Parameter.domid = DOMID_SELF;
-  Parameter.space = XENMAPSPACE_shared_info;
-  Parameter.idx = 0;
-
-  //
-  // using reserved page because the page is not released when Linux is
-  // starting because of the add_to_physmap. QEMU might try to access the
-  // page, and fail because it have no right to do so (segv).
-  //

OvmfPkg/XenBusDxe/XenHypercall.c XenHypercallHvmGetParam ( · line 95

Quoted 10 lines
OvmfPkg/XenBusDxe/XenHypercall.c +1 -9
-  Dev->SharedInfo = AllocateReservedPages (1);
-  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
-  if (XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameter) != 0) {
-    FreePages (Dev->SharedInfo, 1);
-    Dev->SharedInfo = NULL;
-    return EFI_LOAD_ERROR;
-  }
-
-  return EFI_SUCCESS;
+  return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);

^ shouldn't it be Hyperpage?

Quoted 113 lines
OvmfPkg/XenBusDxe/XenHypercall.c +0 -0
 }
OvmfPkg/XenBusDxe/XenHypercall.h +3 -25
index 06693830e16e..9d49e33eb5af 100644
@@ -18,9 +18,9 @@
 
 /**
   This function will put the two arguments in the right place (registers) and
-  call HypercallAddr, which correspond to an entry in the hypercall pages.
+  invoke the hypercall identified by HypercallID.
 
-  @param HypercallAddr  A memory address where the hypercall to call is.
+  @param HypercallID    The symbolic ID of the hypercall to be invoked
   @param Arg1           First argument.
   @param Arg2           Second argument.
 
@@ -29,7 +29,7 @@
 INTN
 EFIAPI
 XenHypercall2 (
-  IN     VOID *HypercallAddr,
+  IN     INTN HypercallID,
   IN OUT INTN Arg1,
   IN OUT INTN Arg2
   );
@@ -44,27 +44,23 @@ XenHypercall2 (
 **/
 EFI_STATUS
 XenHyperpageInit (
-  XENBUS_DEVICE *Dev
   );
 
 /**
   Return the value of the HVM parameter Index.
 
-  @param Dev    A XENBUS_DEVICE instance.
   @param Index  The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN.
 
   @return   The value of the asked parameter or 0 in case of error.
 **/
 UINT64
 XenHypercallHvmGetParam (
-  XENBUS_DEVICE *Dev,
   UINT32 Index
   );
 
 /**
   Hypercall to do different operation on the memory.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. XENMEM_add_to_physmap.
   @param Arguments  The arguments associated to the operation.
 
@@ -73,7 +69,6 @@ XenHypercallHvmGetParam (
 **/
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   );
@@ -81,7 +76,6 @@ XenHypercallMemoryOp (
 /**
   Do an operation on the event channels.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. EVTCHNOP_send.
   @param Arguments  The argument associated to the operation.
 
@@ -90,24 +84,8 @@ XenHypercallMemoryOp (
 **/
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   );
 
-/**
-  Map the shared_info_t page into memory.
-
-  @param Dev    A XENBUS_DEVICE instance.
-
-  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
-                          the shared info page
-  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
-                          hypercall returned an error.
-**/
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
-  );
-
 #endif
OvmfPkg/XenBusDxe/XenStore.c +2 -2
index 2df8f5348585..7ec1e634bc5c 100644
@@ -1057,8 +1057,8 @@ XenStoreInit (
 
   xs.Dev = Dev;
 
-  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_EVTCHN);
-  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_PFN);
+  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (HVM_PARAM_STORE_EVTCHN);
+  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (HVM_PARAM_STORE_PFN);
   xs.XenStore = (VOID *) (XenStoreGpfn << EFI_PAGE_SHIFT);
   DEBUG ((EFI_D_INFO, "XenBusInit: XenBus rings @%p, event channel %x\n",
           xs.XenStore, xs.EventChannel));
Signature · 1 line
1.8.3.2
#40 lore raw

Re: [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

Quoted 315 lines · Stefano Stabellini
Quoted 314 lines · Ard Biesheuvel

This refactors the Xen hypercall implementation that is part of the XenBusDxe driver, in preparation of splitting it off entirely into a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall() prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info page is not strictly part of the Xen hypercall interface, and is not used by other expected users of XenHypercallLib such as the Xen console version of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage there; the existing asm implementations are renamed to __XenHypercall2() and invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/EventChannel.c      | 11 +++--------
 OvmfPkg/XenBusDxe/GrantTable.c        |  4 ++--
 OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
 OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c         | 44 +++++++++++++++++++++++++++++++++++++++++++-
 OvmfPkg/XenBusDxe/XenBusDxe.h         |  1 -
 OvmfPkg/XenBusDxe/XenHypercall.c      | 50 ++++++++++++++------------------------------------
 OvmfPkg/XenBusDxe/XenHypercall.h      | 28 +++-------------------------
 OvmfPkg/XenBusDxe/XenStore.c          |  4 ++--
 9 files changed, 73 insertions(+), 81 deletions(-)
OvmfPkg/XenBusDxe/EventChannel.c +3 -8
index 03efaf9cb904..a86323e6adfd 100644
@@ -28,7 +28,7 @@ XenEventChannelNotify (
   evtchn_send_t Send;
 
   Send.port = Port;
-  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send);
+  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, &Send);
   return (UINT32)ReturnCode;
 }
 
@@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
   OUT evtchn_port_t   *Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_alloc_unbound_t Parameter;
   UINT32 ReturnCode;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
-
   Parameter.dom = DOMID_SELF;
   Parameter.remote_dom = DomainId;
-  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private->Dev,
+  ReturnCode = (UINT32)XenHypercallEventChannelOp (
                                    EVTCHNOP_alloc_unbound,
                                    &Parameter);
   if (ReturnCode != 0) {
@@ -79,10 +76,8 @@ XenBusEventChannelClose (
   IN evtchn_port_t   Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_close_t Close;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
   Close.port = Port;
-  return (UINT32)XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close);
+  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, &Close);
 }
OvmfPkg/XenBusDxe/GrantTable.c +2 -2
index 8405edc51bc4..53cb99f0e004 100644
@@ -161,7 +161,7 @@ XenGrantTableInit (
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));
     }
@@ -184,7 +184,7 @@ XenGrantTableDeinit (
     Parameters.domid = DOMID_SELF;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, remove_from_physmap hypercall error: %d\n", ReturnCode));
     }
OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +3 -3
index 8547c30b81ee..e0fa71bb5ba8 100644
@@ -2,13 +2,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   ; Save only ebx, ecx is supposed to be a scratch register and needs to be
   ; saved by the caller
   push ebx
OvmfPkg/XenBusDxe/X64/hypercall.nasm +3 -3
index 177f271ef094..5e6a0c05c5c4 100644
@@ -3,13 +3,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   push rdi
   push rsi
   ; Copy HypercallAddr to rax
OvmfPkg/XenBusDxe/XenBusDxe.c +43 -1
index 7a7fd82d559d..d333b331b6db 100644
@@ -34,6 +34,8 @@
 #include "XenStore.h"
 #include "XenBus.h"
 
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
 
 ///
 /// Driver Binding Protocol instance
@@ -52,6 +54,46 @@ STATIC EFI_LOCK       mMyDeviceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK
 STATIC XENBUS_DEVICE *mMyDevice = NULL;
 
 /**
+  Map the shared_info_t page into memory.
+
+  @param Dev    A XENBUS_DEVICE instance.
+
+  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
+                          the shared info page
+  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
+                          hypercall returned an error.
+**/
+STATIC
+EFI_STATUS
+XenGetSharedInfoPage (
+  IN OUT XENBUS_DEVICE *Dev
+  )
+{
+  xen_add_to_physmap_t Parameter;
+
+  ASSERT (Dev->SharedInfo == NULL);
+
+  Parameter.domid = DOMID_SELF;
+  Parameter.space = XENMAPSPACE_shared_info;
+  Parameter.idx = 0;
+
+  //
+  // using reserved page because the page is not released when Linux is
+  // starting because of the add_to_physmap. QEMU might try to access the
+  // page, and fail because it have no right to do so (segv).
+  //
+  Dev->SharedInfo = AllocateReservedPages (1);
+  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
+  if (XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameter) != 0) {
+    FreePages (Dev->SharedInfo, 1);
+    Dev->SharedInfo = NULL;
+    return EFI_LOAD_ERROR;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   Unloads an image.
 
   @param  ImageHandle           Handle that identifies the image to be unloaded.
@@ -348,7 +390,7 @@ XenBusDxeDriverBindingStart (
   MmioAddr = BarDesc->AddrRangeMin;
   FreePool (BarDesc);
 
-  Status = XenHyperpageInit (Dev);
+  Status = XenHyperpageInit ();
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));
     Status = EFI_UNSUPPORTED;
OvmfPkg/XenBusDxe/XenBusDxe.h +0 -1
index 80253b7d1ca9..9b7219906a69 100644
@@ -91,7 +91,6 @@ struct _XENBUS_DEVICE {
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
 
-  VOID                          *Hyperpage;
   shared_info_t                 *SharedInfo;
 };
 
OvmfPkg/XenBusDxe/XenHypercall.c +13 -30
index 34d92e76b7e3..9bcf3197633e 100644
@@ -23,9 +23,10 @@
 #include <IndustryStandard/Xen/hvm/params.h>
 #include <IndustryStandard/Xen/memory.h>
 
+STATIC VOID       *Hyperpage;
+
 EFI_STATUS
 XenHyperpageInit (
-  IN OUT XENBUS_DEVICE *Dev
   )
 {
   EFI_HOB_GUID_TYPE   *GuidHob;
@@ -36,24 +37,21 @@ XenHyperpageInit (
     return EFI_NOT_FOUND;
   }
   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
-  Dev->Hyperpage = XenInfo->HyperPages;
+  Hyperpage = XenInfo->HyperPages;
   return EFI_SUCCESS;
 }
 
 UINT64
 XenHypercallHvmGetParam (
-  IN XENBUS_DEVICE *Dev,
   IN UINT32        Index
   )
 {
   xen_hvm_param_t     Parameter;
   INTN                Error;
 
-  ASSERT (Dev->Hyperpage != NULL);
-
   Parameter.domid = DOMID_SELF;
   Parameter.index = Index;
-  Error = XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_hvm_op * 32,
+  Error = XenHypercall2 (__HYPERVISOR_hvm_op,
                          HVMOP_get_param, (INTN) &Parameter);
   if (Error != 0) {
     DEBUG ((EFI_D_ERROR,
@@ -66,53 +64,33 @@ XenHypercallHvmGetParam (
 
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_memory_op * 32,
+  return XenHypercall2 (__HYPERVISOR_memory_op,
                         Operation, (INTN) Arguments);
 }
 
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32,
+  return XenHypercall2 (__HYPERVISOR_event_channel_op,
                         Operation, (INTN) Arguments);
 }
 
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
+INTN
+EFIAPI
+XenHypercall2 (
+  IN     INTN HypercallID,
+  IN OUT INTN Arg1,
+  IN OUT INTN Arg2
   )
 {
-  xen_add_to_physmap_t Parameter;
-
-  ASSERT (Dev->SharedInfo == NULL);
+  ASSERT (HyperPage != NULL);
 
-  Parameter.domid = DOMID_SELF;
-  Parameter.space = XENMAPSPACE_shared_info;
-  Parameter.idx = 0;
-
-  //
-  // using reserved page because the page is not released when Linux is
-  // starting because of the add_to_physmap. QEMU might try to access the
-  // page, and fail because it have no right to do so (segv).
-  //
-  Dev->SharedInfo = AllocateReservedPages (1);
-  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
-  if (XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameter) != 0) {
Quoted 9 lines

OvmfPkg/XenBusDxe/XenHypercall.c XenHypercallHvmGetParam ( · line 95

Quoted 7 lines
OvmfPkg/XenBusDxe/XenHypercall.c +1 -6
-    FreePages (Dev->SharedInfo, 1);
-    Dev->SharedInfo = NULL;
-    return EFI_LOAD_ERROR;
-  }
-
-  return EFI_SUCCESS;
+  return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);

^ shouldn't it be Hyperpage?

Yes, you are quite right. My build test on x86 should have spotted this, so apparently I screwed that up in some way as well.

Cheers,
Ard.

Quoted 113 lines
Quoted 113 lines
OvmfPkg/XenBusDxe/XenHypercall.c +0 -0
 }
OvmfPkg/XenBusDxe/XenHypercall.h +3 -25
index 06693830e16e..9d49e33eb5af 100644
@@ -18,9 +18,9 @@
 
 /**
   This function will put the two arguments in the right place (registers) and
-  call HypercallAddr, which correspond to an entry in the hypercall pages.
+  invoke the hypercall identified by HypercallID.
 
-  @param HypercallAddr  A memory address where the hypercall to call is.
+  @param HypercallID    The symbolic ID of the hypercall to be invoked
   @param Arg1           First argument.
   @param Arg2           Second argument.
 
@@ -29,7 +29,7 @@
 INTN
 EFIAPI
 XenHypercall2 (
-  IN     VOID *HypercallAddr,
+  IN     INTN HypercallID,
   IN OUT INTN Arg1,
   IN OUT INTN Arg2
   );
@@ -44,27 +44,23 @@ XenHypercall2 (
 **/
 EFI_STATUS
 XenHyperpageInit (
-  XENBUS_DEVICE *Dev
   );
 
 /**
   Return the value of the HVM parameter Index.
 
-  @param Dev    A XENBUS_DEVICE instance.
   @param Index  The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN.
 
   @return   The value of the asked parameter or 0 in case of error.
 **/
 UINT64
 XenHypercallHvmGetParam (
-  XENBUS_DEVICE *Dev,
   UINT32 Index
   );
 
 /**
   Hypercall to do different operation on the memory.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. XENMEM_add_to_physmap.
   @param Arguments  The arguments associated to the operation.
 
@@ -73,7 +69,6 @@ XenHypercallHvmGetParam (
 **/
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   );
@@ -81,7 +76,6 @@ XenHypercallMemoryOp (
 /**
   Do an operation on the event channels.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. EVTCHNOP_send.
   @param Arguments  The argument associated to the operation.
 
@@ -90,24 +84,8 @@ XenHypercallMemoryOp (
 **/
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   );
 
-/**
-  Map the shared_info_t page into memory.
-
-  @param Dev    A XENBUS_DEVICE instance.
-
-  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
-                          the shared info page
-  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
-                          hypercall returned an error.
-**/
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
-  );
-
 #endif
OvmfPkg/XenBusDxe/XenStore.c +2 -3
index 2df8f5348585..7ec1e634bc5c 100644
@@ -1057,8 +1057,8 @@ XenStoreInit (
 
   xs.Dev = Dev;
 
-  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_EVTCHN);
-  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_PFN);
+  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (HVM_PARAM_STORE_EVTCHN);
+  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (HVM_PARAM_STORE_PFN);
   xs.XenStore = (VOID *) (XenStoreGpfn << EFI_PAGE_SHIFT);
   DEBUG ((EFI_D_INFO, "XenBusInit: XenBus rings @%p, event channel %x\n",
           xs.XenStore, xs.EventChannel));
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): CAKv+Gu9T2toY5O+wNtOpXPG7bHcG2C=OATHYA4=4OUznG5KpHg@mail.gmail.com

#42 lore raw

Re: [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

Quoted 327 lines · Ard Biesheuvel
Quoted 315 lines · Stefano Stabellini
Quoted 314 lines · Ard Biesheuvel

This refactors the Xen hypercall implementation that is part of the XenBusDxe driver, in preparation of splitting it off entirely into a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall() prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info page is not strictly part of the Xen hypercall interface, and is not used by other expected users of XenHypercallLib such as the Xen console version of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage there; the existing asm implementations are renamed to __XenHypercall2() and invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/EventChannel.c      | 11 +++--------
 OvmfPkg/XenBusDxe/GrantTable.c        |  4 ++--
 OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
 OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c         | 44 +++++++++++++++++++++++++++++++++++++++++++-
 OvmfPkg/XenBusDxe/XenBusDxe.h         |  1 -
 OvmfPkg/XenBusDxe/XenHypercall.c      | 50 ++++++++++++++------------------------------------
 OvmfPkg/XenBusDxe/XenHypercall.h      | 28 +++-------------------------
 OvmfPkg/XenBusDxe/XenStore.c          |  4 ++--
 9 files changed, 73 insertions(+), 81 deletions(-)
OvmfPkg/XenBusDxe/EventChannel.c +3 -8
index 03efaf9cb904..a86323e6adfd 100644
@@ -28,7 +28,7 @@ XenEventChannelNotify (
   evtchn_send_t Send;
 
   Send.port = Port;
-  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send);
+  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, &Send);
   return (UINT32)ReturnCode;
 }
 
@@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
   OUT evtchn_port_t   *Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_alloc_unbound_t Parameter;
   UINT32 ReturnCode;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
-
   Parameter.dom = DOMID_SELF;
   Parameter.remote_dom = DomainId;
-  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private->Dev,
+  ReturnCode = (UINT32)XenHypercallEventChannelOp (
                                    EVTCHNOP_alloc_unbound,
                                    &Parameter);
   if (ReturnCode != 0) {
@@ -79,10 +76,8 @@ XenBusEventChannelClose (
   IN evtchn_port_t   Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_close_t Close;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
   Close.port = Port;
-  return (UINT32)XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close);
+  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, &Close);
 }
OvmfPkg/XenBusDxe/GrantTable.c +2 -2
index 8405edc51bc4..53cb99f0e004 100644
@@ -161,7 +161,7 @@ XenGrantTableInit (
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));
     }
@@ -184,7 +184,7 @@ XenGrantTableDeinit (
     Parameters.domid = DOMID_SELF;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, remove_from_physmap hypercall error: %d\n", ReturnCode));
     }
OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +3 -3
index 8547c30b81ee..e0fa71bb5ba8 100644
@@ -2,13 +2,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   ; Save only ebx, ecx is supposed to be a scratch register and needs to be
   ; saved by the caller
   push ebx
OvmfPkg/XenBusDxe/X64/hypercall.nasm +3 -3
index 177f271ef094..5e6a0c05c5c4 100644
@@ -3,13 +3,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   push rdi
   push rsi
   ; Copy HypercallAddr to rax
OvmfPkg/XenBusDxe/XenBusDxe.c +43 -1
index 7a7fd82d559d..d333b331b6db 100644
@@ -34,6 +34,8 @@
 #include "XenStore.h"
 #include "XenBus.h"
 
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
 
 ///
 /// Driver Binding Protocol instance
@@ -52,6 +54,46 @@ STATIC EFI_LOCK       mMyDeviceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK
 STATIC XENBUS_DEVICE *mMyDevice = NULL;
 
 /**
+  Map the shared_info_t page into memory.
+
+  @param Dev    A XENBUS_DEVICE instance.
+
+  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
+                          the shared info page
+  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
+                          hypercall returned an error.
+**/
+STATIC
+EFI_STATUS
+XenGetSharedInfoPage (
+  IN OUT XENBUS_DEVICE *Dev
+  )
+{
+  xen_add_to_physmap_t Parameter;
+
+  ASSERT (Dev->SharedInfo == NULL);
+
+  Parameter.domid = DOMID_SELF;
+  Parameter.space = XENMAPSPACE_shared_info;
+  Parameter.idx = 0;
+
+  //
+  // using reserved page because the page is not released when Linux is
+  // starting because of the add_to_physmap. QEMU might try to access the
+  // page, and fail because it have no right to do so (segv).
+  //
+  Dev->SharedInfo = AllocateReservedPages (1);
+  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
+  if (XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameter) != 0) {
+    FreePages (Dev->SharedInfo, 1);
+    Dev->SharedInfo = NULL;
+    return EFI_LOAD_ERROR;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   Unloads an image.
 
   @param  ImageHandle           Handle that identifies the image to be unloaded.
@@ -348,7 +390,7 @@ XenBusDxeDriverBindingStart (
   MmioAddr = BarDesc->AddrRangeMin;
   FreePool (BarDesc);
 
-  Status = XenHyperpageInit (Dev);
+  Status = XenHyperpageInit ();
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));
     Status = EFI_UNSUPPORTED;
OvmfPkg/XenBusDxe/XenBusDxe.h +0 -1
index 80253b7d1ca9..9b7219906a69 100644
@@ -91,7 +91,6 @@ struct _XENBUS_DEVICE {
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
 
-  VOID                          *Hyperpage;
   shared_info_t                 *SharedInfo;
 };
 
OvmfPkg/XenBusDxe/XenHypercall.c +13 -30
index 34d92e76b7e3..9bcf3197633e 100644
@@ -23,9 +23,10 @@
 #include <IndustryStandard/Xen/hvm/params.h>
 #include <IndustryStandard/Xen/memory.h>
 
+STATIC VOID       *Hyperpage;
+
 EFI_STATUS
 XenHyperpageInit (
-  IN OUT XENBUS_DEVICE *Dev
   )
 {
   EFI_HOB_GUID_TYPE   *GuidHob;
@@ -36,24 +37,21 @@ XenHyperpageInit (
     return EFI_NOT_FOUND;
   }
   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
-  Dev->Hyperpage = XenInfo->HyperPages;
+  Hyperpage = XenInfo->HyperPages;
   return EFI_SUCCESS;
 }
 
 UINT64
 XenHypercallHvmGetParam (
-  IN XENBUS_DEVICE *Dev,
   IN UINT32        Index
   )
 {
   xen_hvm_param_t     Parameter;
   INTN                Error;
 
-  ASSERT (Dev->Hyperpage != NULL);
-
   Parameter.domid = DOMID_SELF;
   Parameter.index = Index;
-  Error = XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_hvm_op * 32,
+  Error = XenHypercall2 (__HYPERVISOR_hvm_op,
                          HVMOP_get_param, (INTN) &Parameter);
   if (Error != 0) {
     DEBUG ((EFI_D_ERROR,
@@ -66,53 +64,33 @@ XenHypercallHvmGetParam (
 
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_memory_op * 32,
+  return XenHypercall2 (__HYPERVISOR_memory_op,
                         Operation, (INTN) Arguments);
 }
 
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32,
+  return XenHypercall2 (__HYPERVISOR_event_channel_op,
                         Operation, (INTN) Arguments);
 }
 
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
+INTN
+EFIAPI
+XenHypercall2 (
+  IN     INTN HypercallID,
+  IN OUT INTN Arg1,
+  IN OUT INTN Arg2
   )
 {
-  xen_add_to_physmap_t Parameter;
-
-  ASSERT (Dev->SharedInfo == NULL);
+  ASSERT (HyperPage != NULL);
 
-  Parameter.domid = DOMID_SELF;
-  Parameter.space = XENMAPSPACE_shared_info;
-  Parameter.idx = 0;
-
-  //
-  // using reserved page because the page is not released when Linux is
-  // starting because of the add_to_physmap. QEMU might try to access the
-  // page, and fail because it have no right to do so (segv).
-  //
-  Dev->SharedInfo = AllocateReservedPages (1);
-  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
-  if (XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameter) != 0) {
Quoted 9 lines

OvmfPkg/XenBusDxe/XenHypercall.c XenHypercallHvmGetParam ( · line 95

Quoted 7 lines
OvmfPkg/XenBusDxe/XenHypercall.c +1 -6
-    FreePages (Dev->SharedInfo, 1);
-    Dev->SharedInfo = NULL;
-    return EFI_LOAD_ERROR;
-  }
-
-  return EFI_SUCCESS;
+  return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);

^ shouldn't it be Hyperpage?

Quoted 3 lines

Yes, you are quite right. My build test on x86 should have spotted this, so apparently I screwed that up in some way as well.

Turns out this was a refactoring error that got cleaned up by the next patch, and I did not perform the x86 build test on each patch in isolation.
Will be fixed in v3

Signature · 1 line
Ard.
Quoted 113 lines
Quoted 113 lines
Quoted 113 lines
OvmfPkg/XenBusDxe/XenHypercall.c +0 -0
 }
OvmfPkg/XenBusDxe/XenHypercall.h +3 -25
index 06693830e16e..9d49e33eb5af 100644
@@ -18,9 +18,9 @@
 
 /**
   This function will put the two arguments in the right place (registers) and
-  call HypercallAddr, which correspond to an entry in the hypercall pages.
+  invoke the hypercall identified by HypercallID.
 
-  @param HypercallAddr  A memory address where the hypercall to call is.
+  @param HypercallID    The symbolic ID of the hypercall to be invoked
   @param Arg1           First argument.
   @param Arg2           Second argument.
 
@@ -29,7 +29,7 @@
 INTN
 EFIAPI
 XenHypercall2 (
-  IN     VOID *HypercallAddr,
+  IN     INTN HypercallID,
   IN OUT INTN Arg1,
   IN OUT INTN Arg2
   );
@@ -44,27 +44,23 @@ XenHypercall2 (
 **/
 EFI_STATUS
 XenHyperpageInit (
-  XENBUS_DEVICE *Dev
   );
 
 /**
   Return the value of the HVM parameter Index.
 
-  @param Dev    A XENBUS_DEVICE instance.
   @param Index  The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN.
 
   @return   The value of the asked parameter or 0 in case of error.
 **/
 UINT64
 XenHypercallHvmGetParam (
-  XENBUS_DEVICE *Dev,
   UINT32 Index
   );
 
 /**
   Hypercall to do different operation on the memory.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. XENMEM_add_to_physmap.
   @param Arguments  The arguments associated to the operation.
 
@@ -73,7 +69,6 @@ XenHypercallHvmGetParam (
 **/
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   );
@@ -81,7 +76,6 @@ XenHypercallMemoryOp (
 /**
   Do an operation on the event channels.
 
-  @param Dev        A XENBUS_DEVICE instance.
   @param Operation  The operation number, e.g. EVTCHNOP_send.
   @param Arguments  The argument associated to the operation.
 
@@ -90,24 +84,8 @@ XenHypercallMemoryOp (
 **/
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   );
 
-/**
-  Map the shared_info_t page into memory.
-
-  @param Dev    A XENBUS_DEVICE instance.
-
-  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
-                          the shared info page
-  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
-                          hypercall returned an error.
-**/
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
-  );
-
 #endif
OvmfPkg/XenBusDxe/XenStore.c +2 -3
index 2df8f5348585..7ec1e634bc5c 100644
@@ -1057,8 +1057,8 @@ XenStoreInit (
 
   xs.Dev = Dev;
 
-  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_EVTCHN);
-  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_PFN);
+  xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (HVM_PARAM_STORE_EVTCHN);
+  XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (HVM_PARAM_STORE_PFN);
   xs.XenStore = (VOID *) (XenStoreGpfn << EFI_PAGE_SHIFT);
   DEBUG ((EFI_D_INFO, "XenBusInit: XenBus rings @%p, event channel %x\n",
           xs.XenStore, xs.EventChannel));
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): CAKv+Gu_FZ-fJU3LTEE4p+VXvZ9BJg9Y7SOPfwcV9_M+BJRMvzg@mail.gmail.com

Acked-by
#44 lore raw

Re: [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

Quoted 328 lines · Ard Biesheuvel
Quoted 327 lines · Ard Biesheuvel
Quoted 324 lines · Stefano Stabellini
Quoted 311 lines · Ard Biesheuvel

This refactors the Xen hypercall implementation that is part of the XenBusDxe driver, in preparation of splitting it off entirely into a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall() prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info page is not strictly part of the Xen hypercall interface, and is not used by other expected users of XenHypercallLib such as the Xen console version of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage there; the existing asm implementations are renamed to __XenHypercall2() and invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/EventChannel.c      | 11 +++--------
 OvmfPkg/XenBusDxe/GrantTable.c        |  4 ++--
 OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
 OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c         | 44 +++++++++++++++++++++++++++++++++++++++++++-
 OvmfPkg/XenBusDxe/XenBusDxe.h         |  1 -
 OvmfPkg/XenBusDxe/XenHypercall.c      | 50 ++++++++++++++------------------------------------
 OvmfPkg/XenBusDxe/XenHypercall.h      | 28 +++-------------------------
 OvmfPkg/XenBusDxe/XenStore.c          |  4 ++--
 9 files changed, 73 insertions(+), 81 deletions(-)
OvmfPkg/XenBusDxe/EventChannel.c +3 -8
index 03efaf9cb904..a86323e6adfd 100644
@@ -28,7 +28,7 @@ XenEventChannelNotify (
   evtchn_send_t Send;
 
   Send.port = Port;
-  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send);
+  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, &Send);
   return (UINT32)ReturnCode;
 }
 
@@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
   OUT evtchn_port_t   *Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_alloc_unbound_t Parameter;
   UINT32 ReturnCode;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
-
   Parameter.dom = DOMID_SELF;
   Parameter.remote_dom = DomainId;
-  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private->Dev,
+  ReturnCode = (UINT32)XenHypercallEventChannelOp (
                                    EVTCHNOP_alloc_unbound,
                                    &Parameter);
   if (ReturnCode != 0) {
@@ -79,10 +76,8 @@ XenBusEventChannelClose (
   IN evtchn_port_t   Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_close_t Close;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
   Close.port = Port;
-  return (UINT32)XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close);
+  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, &Close);
 }
OvmfPkg/XenBusDxe/GrantTable.c +2 -2
index 8405edc51bc4..53cb99f0e004 100644
@@ -161,7 +161,7 @@ XenGrantTableInit (
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));
     }
@@ -184,7 +184,7 @@ XenGrantTableDeinit (
     Parameters.domid = DOMID_SELF;
     Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
-    ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
+    ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, remove_from_physmap hypercall error: %d\n", ReturnCode));
     }
OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +3 -3
index 8547c30b81ee..e0fa71bb5ba8 100644
@@ -2,13 +2,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   ; Save only ebx, ecx is supposed to be a scratch register and needs to be
   ; saved by the caller
   push ebx
OvmfPkg/XenBusDxe/X64/hypercall.nasm +3 -3
index 177f271ef094..5e6a0c05c5c4 100644
@@ -3,13 +3,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN     VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   push rdi
   push rsi
   ; Copy HypercallAddr to rax
OvmfPkg/XenBusDxe/XenBusDxe.c +43 -1
index 7a7fd82d559d..d333b331b6db 100644
@@ -34,6 +34,8 @@
 #include "XenStore.h"
 #include "XenBus.h"
 
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
 
 ///
 /// Driver Binding Protocol instance
@@ -52,6 +54,46 @@ STATIC EFI_LOCK       mMyDeviceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK
 STATIC XENBUS_DEVICE *mMyDevice = NULL;
 
 /**
+  Map the shared_info_t page into memory.
+
+  @param Dev    A XENBUS_DEVICE instance.
+
+  @retval EFI_SUCCESS     Dev->SharedInfo whill contain a pointer to
+                          the shared info page
+  @retval EFI_LOAD_ERROR  The shared info page could not be mapped. The
+                          hypercall returned an error.
+**/
+STATIC
+EFI_STATUS
+XenGetSharedInfoPage (
+  IN OUT XENBUS_DEVICE *Dev
+  )
+{
+  xen_add_to_physmap_t Parameter;
+
+  ASSERT (Dev->SharedInfo == NULL);
+
+  Parameter.domid = DOMID_SELF;
+  Parameter.space = XENMAPSPACE_shared_info;
+  Parameter.idx = 0;
+
+  //
+  // using reserved page because the page is not released when Linux is
+  // starting because of the add_to_physmap. QEMU might try to access the
+  // page, and fail because it have no right to do so (segv).
+  //
+  Dev->SharedInfo = AllocateReservedPages (1);
+  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
+  if (XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameter) != 0) {
+    FreePages (Dev->SharedInfo, 1);
+    Dev->SharedInfo = NULL;
+    return EFI_LOAD_ERROR;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   Unloads an image.
 
   @param  ImageHandle           Handle that identifies the image to be unloaded.
@@ -348,7 +390,7 @@ XenBusDxeDriverBindingStart (
   MmioAddr = BarDesc->AddrRangeMin;
   FreePool (BarDesc);
 
-  Status = XenHyperpageInit (Dev);
+  Status = XenHyperpageInit ();
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));
     Status = EFI_UNSUPPORTED;
OvmfPkg/XenBusDxe/XenBusDxe.h +0 -1
index 80253b7d1ca9..9b7219906a69 100644
@@ -91,7 +91,6 @@ struct _XENBUS_DEVICE {
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
 
-  VOID                          *Hyperpage;
   shared_info_t                 *SharedInfo;
 };
 
OvmfPkg/XenBusDxe/XenHypercall.c +13 -27
index 34d92e76b7e3..9bcf3197633e 100644
@@ -23,9 +23,10 @@
 #include <IndustryStandard/Xen/hvm/params.h>
 #include <IndustryStandard/Xen/memory.h>
 
+STATIC VOID       *Hyperpage;
+
 EFI_STATUS
 XenHyperpageInit (
-  IN OUT XENBUS_DEVICE *Dev
   )
 {
   EFI_HOB_GUID_TYPE   *GuidHob;
@@ -36,24 +37,21 @@ XenHyperpageInit (
     return EFI_NOT_FOUND;
   }
   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
-  Dev->Hyperpage = XenInfo->HyperPages;
+  Hyperpage = XenInfo->HyperPages;
   return EFI_SUCCESS;
 }
 
 UINT64
 XenHypercallHvmGetParam (
-  IN XENBUS_DEVICE *Dev,
   IN UINT32        Index
   )
 {
   xen_hvm_param_t     Parameter;
   INTN                Error;
 
-  ASSERT (Dev->Hyperpage != NULL);
-
   Parameter.domid = DOMID_SELF;
   Parameter.index = Index;
-  Error = XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_hvm_op * 32,
+  Error = XenHypercall2 (__HYPERVISOR_hvm_op,
                          HVMOP_get_param, (INTN) &Parameter);
   if (Error != 0) {
     DEBUG ((EFI_D_ERROR,
@@ -66,53 +64,33 @@ XenHypercallHvmGetParam (
 
 INTN
 XenHypercallMemoryOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     UINTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_memory_op * 32,
+  return XenHypercall2 (__HYPERVISOR_memory_op,
                         Operation, (INTN) Arguments);
 }
 
 INTN
 XenHypercallEventChannelOp (
-  IN     XENBUS_DEVICE *Dev,
   IN     INTN Operation,
   IN OUT VOID *Arguments
   )
 {
-  ASSERT (Dev->Hyperpage != NULL);
-  return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32,
+  return XenHypercall2 (__HYPERVISOR_event_channel_op,
                         Operation, (INTN) Arguments);
 }
 
-EFI_STATUS
-XenGetSharedInfoPage (
-  IN OUT XENBUS_DEVICE *Dev
+INTN
+EFIAPI
+XenHypercall2 (
+  IN     INTN HypercallID,
+  IN OUT INTN Arg1,
+  IN OUT INTN Arg2
   )
 {
-  xen_add_to_physmap_t Parameter;
-
-  ASSERT (Dev->SharedInfo == NULL);
+  ASSERT (HyperPage != NULL);
 
-  Parameter.domid = DOMID_SELF;
-  Parameter.space = XENMAPSPACE_shared_info;
-  Parameter.idx = 0;
-
-  //
-  // using reserved page because the page is not released when Linux is
-  // starting because of the add_to_physmap. QEMU might try to access the
-  // page, and fail because it have no right to do so (segv).
-  //

OvmfPkg/XenBusDxe/XenHypercall.c XenHypercallHvmGetParam ( · line 95

Quoted 10 lines
OvmfPkg/XenBusDxe/XenHypercall.c +1 -9
-  Dev->SharedInfo = AllocateReservedPages (1);
-  Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
-  if (XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameter) != 0) {
-    FreePages (Dev->SharedInfo, 1);
-    Dev->SharedInfo = NULL;
-    return EFI_LOAD_ERROR;
-  }
-
-  return EFI_SUCCESS;
+  return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);

^ shouldn't it be Hyperpage?

Quoted 9 lines
Quoted 3 lines

Yes, you are quite right. My build test on x86 should have spotted this, so apparently I screwed that up in some way as well.

Turns out this was a refactoring error that got cleaned up by the next patch, and I did not perform the x86 build test on each patch in isolation.
Will be fixed in v3

I skimmed this patch. It makes sense to me as preparation for librarizing the hypercall machinery (as you say in the commit message), if the Xen guys don't have any objections.

I peeked forward at patch 18. The librarization is certainly possible given that the origin of your info is the GUID HOB with gEfiXenInfoGuid.

So, I got curious about the data pointed-to by the gEfiXenInfoGuid HOB... It's set up in OvmfPkg/PlatformPei/Xen.c. I froze for a second, but then I noticed it uses BuildGuidDataHob(), *not* BuildGuidHob(); ie. it *copies* mXenInfo into the HOB. Good.

I think this patch (and the next one) improve OVMF/Xen even in isolation (== without thinking of ARM at all).

For v3:

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#46 lore raw

Re: [PATCH v2 29/29] ArmVirtualizationPkg: add platform description for Xen guests

Hi Ard,

I don't know how works platform description in tianocore, but I have few questions about some file includes in the build.

Review

Quoted 6 lines · Ard Biesheuvel
(quoted diff) +6 -0
+  #
+  # ARM PrimeCell
+  #
+
+  ## PL011 - Serial Terminal
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

We don't use PL011, so maybe it's not necessary.

Review

Quoted 4 lines
(quoted diff) +4 -0
+  #
+  # ARM OS Loader
+  #
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux (EFI stub) on virtio31:hd0:part0"

The description look wrong here.

Review

Quoted 2 lines
(quoted diff) +2 -0
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000)/HD(1,MBR,0x00000000,0x3F,0x19FC0)/Image"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 console=ttyAMA0 earlycon uefi_debug"

This wouldn't not work by default on ARM guest.

root=/dev/xvda2 (assuming we want to use partition 2) console=hvc0

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+  ## PL031 RealTimeClock
+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0

Will we use it on Xen guest?

[..]

Review

Quoted 7 lines
(quoted diff) +7 -0
+  #
+  # Platform Driver
+  #
+  ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+  OvmfPkg/VirtioNetDxe/VirtioNet.inf

Doesn't see useful as we won't support Virtio for now.

[..]

Quoted 5 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +0 -0
new file mode 100644
index 000000000000..4676a7b2b29f

[..]

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf

Quoted 6 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +6 -0
+  #
+  # Multiple Console IO support
+  #
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

We don't have graphic support for Xen guest.

Quoted 11 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +11 -0
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +10 -0
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Platform Driver
+  #
+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  INF OvmfPkg/VirtioNetDxe/VirtioNet.inf
+  INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf

Ditto for virtio.

[..]

Quoted 5 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +5 -0
+  #
+  # Networking stack
+  #
+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf
+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +10 -0
+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

AFAIK, we don't have PV network for Xen in tianocore. Maybe we could drop the networking stack.

Regards,

Signature · 1 line
Julien Grall
#47 lore raw

Re: [PATCH v2 29/29] ArmVirtualizationPkg: add platform description for Xen guests

Quoted 6 lines · Julien Grall

Hi Ard,

I don't know how works platform description in tianocore, but I have few questions about some file includes in the build.

On 26/01/15 19:03, Ard Biesheuvel wrote:

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+  #
+  # ARM PrimeCell
+  #
+
+  ## PL011 - Serial Terminal
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

We don't use PL011, so maybe it's not necessary.

Correct.

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+  #
+  # ARM OS Loader
+  #
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux (EFI stub) on virtio31:hd0:part0"

The description look wrong here.

Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000)/HD(1,MBR,0x00000000,0x3F,0x19FC0)/Image"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 console=ttyAMA0 earlycon uefi_debug"

This wouldn't not work by default on ARM guest.

root=/dev/xvda2 (assuming we want to use partition 2) console=hvc0

This is completely bogus, and just copy-paste from the QEMU version. I will correct this in the next version

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+  ## PL031 RealTimeClock
+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0

Will we use it on Xen guest?

Nope

Quoted 10 lines

[..]

Review

Quoted 7 lines
(quoted diff) +7 -0
+  #
+  # Platform Driver
+  #
+  ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+  OvmfPkg/VirtioNetDxe/VirtioNet.inf
Quoted 2 lines

Doesn't see useful as we won't support Virtio for now.

Correct.

Quoted 10 lines

[..]

Quoted 5 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +0 -0
new file mode 100644
index 000000000000..4676a7b2b29f

[..]

Quoted 9 lines

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf

Quoted 6 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +6 -0
+  #
+  # Multiple Console IO support
+  #
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

We don't have graphic support for Xen guest.

OK

Quoted 42 lines
Quoted 11 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +11 -0
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +10 -0
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Platform Driver
+  #
+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  INF OvmfPkg/VirtioNetDxe/VirtioNet.inf
+  INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf

Ditto for virtio.

[..]

Quoted 5 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +5 -0
+  #
+  # Networking stack
+  #
+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf
+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +10 -0
+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
Quoted 3 lines

AFAIK, we don't have PV network for Xen in tianocore. Maybe we could drop the networking stack.

Ah yes, we only have PV block devices. Yes, this can be removed then.

Signature · 1 line
Ard.
Acked-by
#48 lore raw

Re: [PATCH v2 29/29] ArmVirtualizationPkg: add platform description for Xen guests

In reply to a message not in the archive
Quoted 27 lines · Ard Biesheuvel

This adds the .dsc and .fdf descriptions to build a UEFI image that is bootable by a Xen guest on 64-bit ARM (AArch64)

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf | 337 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 616 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +11 -0
new file mode 100644
index 000000000000..bcc9742c6828
@@ -0,0 +1,279 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc line 21

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +10 -0
+#
+#
+
+################################################################################
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+[Defines]
+  PLATFORM_NAME                  = ArmVirtualizationQemu

Wut? :)

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc line 22

Quoted 1 line
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +1 -0
+  PLATFORM_GUID                  = 37d7e986-f7e9-45c2-8067-e371421a626c

PLATFORM_GUID shoud be updated as well.

I won't check the rest of the patch now; you got several notes from Julien. Please eyeball this patch for any leftovers from the QEMU files. You can add my

then.

Also, I think I finished reviewing the series. (Some patches I didn't comment on; I didn't want to review those.)

Thanks!
Laszlo

Quoted 601 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +257 -0
+  PLATFORM_VERSION               = 0.1
+  DSC_SPECIFICATION              = 0x00010005
+  OUTPUT_DIRECTORY               = Build/ArmVirtualizationXen-$(ARCH)
+  SUPPORTED_ARCHITECTURES        = AARCH64
+  BUILD_TARGETS                  = DEBUG|RELEASE
+  SKUID_IDENTIFIER               = DEFAULT
+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf
+
+!include ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
+
+[LibraryClasses]
+  SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
+  XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf
+  XenIoMmioLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf
+
+[LibraryClasses.AARCH64]
+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf
+
+[LibraryClasses.ARM]
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf
+
+[LibraryClasses.common]
+  # Virtio Support
+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
+
+  ArmPlatformLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
+  ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf
+
+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
+
+!ifdef INTEL_BDS
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+  GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+  PlatformBdsLib|ArmPlatformPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
+  CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+!endif
+
+[LibraryClasses.common.UEFI_DRIVER]
+  UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+
+[LibraryClasses.AARCH64.SEC]
+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf
+
+[LibraryClasses.ARM.SEC]
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf
+
+[BuildOptions]
+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+  GCC:*_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+ 
+################################################################################
+#
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform
+#
+################################################################################
+
+[PcdsFeatureFlag.common]
+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.
+  #  It could be set FALSE to save size.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE
+
+[PcdsFixedAtBuild.common]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F
+
+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"XEN-UEFI"
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"$(FIRMWARE_VER)"
+
+  gArmPlatformTokenSpaceGuid.PcdCoreCount|1
+!if $(ARCH) == AARCH64
+  gArmTokenSpaceGuid.PcdVFPEnabled|1
+!endif
+
+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000
+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000
+
+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000
+
+  #
+  # ARM Pcds
+  #
+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000
+
+  ## Trustzone enable (to make the transition from EL3 to EL2 in ArmPlatformPkg/Sec)
+  gArmTokenSpaceGuid.PcdTrustzoneSupport|FALSE
+
+  #
+  # ARM PrimeCell
+  #
+
+  ## PL011 - Serial Terminal
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400
+
+  #
+  # ARM OS Loader
+  #
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux (EFI stub) on virtio31:hd0:part0"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000)/HD(1,MBR,0x00000000,0x3F,0x19FC0)/Image"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 console=ttyAMA0 earlycon uefi_debug"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|0
+
+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)
+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"
+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"
+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|3
+
+  #
+  # ARM Virtual Architectural Timer
+  #
+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000
+
+  #
+  # NV Storage PCDs. Use base of 0x04000000 for NOR1
+  #
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x04000000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x04040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x04080000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00040000
+
+!ifdef INTEL_BDS
+  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
+!endif
+
+[PcdsPatchableInModule.common]
+  #
+  # This will be overridden in the code
+  #
+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x0
+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x0
+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0
+
+  gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
+  gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
+
+[PcdsDynamicDefault.common]
+
+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0
+
+  #
+  # ARM General Interrupt Controller
+  #
+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x0
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x0
+
+  ## PL031 RealTimeClock
+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0
+
+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0
+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress|0x0
+
+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod|0
+
+################################################################################
+#
+# Components Section - list of all EDK II Modules needed by this Platform
+#
+################################################################################
+[Components.common]
+  #
+  # PEI Phase modules
+  #
+  ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf {
+    <LibraryClasses>
+      ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
+      LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
+      PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
+      HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
+      PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
+      MemoryInitPeiLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf
+      ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf
+      MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf
+      SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+      DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
+  }
+
+  #
+  # DXE
+  #
+  MdeModulePkg/Core/Dxe/DxeMain.inf {
+    <LibraryClasses>
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
+  }
+  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+
+  #
+  # Architectural Protocols
+  #
+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf
+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+
+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
+
+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
+
+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+
+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # Platform Driver
+  #
+  ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+  OvmfPkg/VirtioNetDxe/VirtioNet.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Bds
+  #
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+!ifdef INTEL_BDS
+  MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
+  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+!else
+  ArmPlatformPkg/Bds/Bds.inf
+!endif
+
+  #
+  # SCSI Bus and Disk Driver
+  #
+  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+
+  OvmfPkg/XenBusDxe/XenBusDxe.inf
+  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +337 -0
new file mode 100644
index 000000000000..4676a7b2b29f
@@ -0,0 +1,337 @@
+#
+#  Copyright (c) 2011, 2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+################################################################################
+#
+# FD Section
+# The [FD] Section is made up of the definition statements and a
+# description of what goes into  the Flash Device Image.  Each FD section
+# defines one flash "device" image.  A flash device image may be one of
+# the following: Removable media bootable image (like a boot floppy
+# image,) an Option ROM image (that would be "flashed" into an add-in
+# card,) a System "Flash"  image (that would be burned into a system's
+# flash) or an Update ("Capsule") image that will be used to update and
+# existing system flash.
+#
+################################################################################
+
+[FD.XEN_EFI]
+BaseAddress   = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress
+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize
+ErasePolarity = 1
+
+# This one is tricky, it must be: BlockSize * NumBlocks = Size
+BlockSize     = 0x00001000
+NumBlocks     = 0x200
+
+################################################################################
+#
+# Following are lists of FD Region layout which correspond to the locations of different
+# images within the flash device.
+#
+# Regions must be defined in ascending order and may not overlap.
+#
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by
+# the pipe "|" character, followed by the size of the region, also in hex with the leading
+# "0x" characters. Like:
+# Offset|Size
+# PcdOffsetCName|PcdSizeCName
+# RegionType <FV, DATA, or FILE>
+#
+################################################################################
+
+#
+# Implement the Linux kernel header layout so that the Xen loader will identify
+# it as something bootable, and execute it with a FDT pointer in x0. This area
+# will be reused to store a copy of the FDT so round it up to 8 KB.
+#
+0x00000000|0x00002000
+DATA = {
+  0x01, 0x00, 0x00, 0x10,                         # code0: adr x1, .
+  0xff, 0x07, 0x00, 0x14,                         # code1: b 0x2000
+  0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, # text_offset: 512 KB
+  0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, # image_size: 2 MB
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # flags
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # res2
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # res3
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # res4
+  0x41, 0x52, 0x4d, 0x64,                         # magic: "ARM\x64"
+  0x00, 0x00, 0x00, 0x00                          # res5
+}
+
+0x00002000|0x001fe000
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
+FV = FVMAIN_COMPACT
+
+
+################################################################################
+#
+# FV Section
+#
+# [FV] section is used to define what components or modules are placed within a flash
+# device file.  This section also defines order the components and modules are positioned
+# within the image.  The [FV] section consists of define statements, set statements and
+# module statements.
+#
+################################################################################
+
+[FV.FvMain]
+BlockSize          = 0x40
+NumBlocks          = 0         # This FV gets compressed so make it just big enough
+FvAlignment        = 16        # FV alignment and FV attributes setting.
+ERASE_POLARITY     = 1
+MEMORY_MAPPED      = TRUE
+STICKY_WRITE       = TRUE
+LOCK_CAP           = TRUE
+LOCK_STATUS        = TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP  = TRUE
+WRITE_STATUS       = TRUE
+WRITE_LOCK_CAP     = TRUE
+WRITE_LOCK_STATUS  = TRUE
+READ_DISABLED_CAP  = TRUE
+READ_ENABLED_CAP   = TRUE
+READ_STATUS        = TRUE
+READ_LOCK_CAP      = TRUE
+READ_LOCK_STATUS   = TRUE
+
+  APRIORI DXE {
+    INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+    INF ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  }
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf
+  INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+  INF ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+
+  #
+  # PI DXE Drivers producing Architectural Protocols (EFI Services)
+  #
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+
+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
+
+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+
+  #
+  # Multiple Console IO support
+  #
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Platform Driver
+  #
+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  INF OvmfPkg/VirtioNetDxe/VirtioNet.inf
+  INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+
+  #
+  # UEFI application (Shell Embedded Boot Loader)
+  #
+  INF ShellBinPkg/UefiShell/UefiShell.inf
+
+  #
+  # Bds
+  #
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+!ifdef INTEL_BDS
+  INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
+  INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+  INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+!else
+  INF ArmPlatformPkg/Bds/Bds.inf
+!endif
+
+  #
+  # Networking stack
+  #
+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf
+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf
+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
+
+  #
+  # SCSI Bus and Disk Driver
+  #
+  INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+  INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+
+  INF OvmfPkg/XenBusDxe/XenBusDxe.inf
+  INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+
+[FV.FVMAIN_COMPACT]
+FvAlignment        = 16
+ERASE_POLARITY     = 1
+MEMORY_MAPPED      = TRUE
+STICKY_WRITE       = TRUE
+LOCK_CAP           = TRUE
+LOCK_STATUS        = TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP  = TRUE
+WRITE_STATUS       = TRUE
+WRITE_LOCK_CAP     = TRUE
+WRITE_LOCK_STATUS  = TRUE
+READ_DISABLED_CAP  = TRUE
+READ_ENABLED_CAP   = TRUE
+READ_STATUS        = TRUE
+READ_LOCK_CAP      = TRUE
+READ_LOCK_STATUS   = TRUE
+
+  INF ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf
+
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
+      SECTION FV_IMAGE = FVMAIN
+    }
+  }
+
+
+################################################################################
+#
+# Rules are use with the [FV] section's module INF type to define
+# how an FFS file is created for a given INF file. The following Rule are the default
+# rules for the different module type. User can add the customized rules to define the
+# content of the FFS file.
+#
+################################################################################
+
+
+############################################################################
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #
+############################################################################
+#
+#[Rule.Common.DXE_DRIVER]
+#  FILE DRIVER = $(NAMED_GUID) {
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+#    COMPRESS PI_STD {
+#      GUIDED {
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
+#        UI       STRING="$(MODULE_NAME)" Optional
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+#      }
+#    }
+#  }
+#
+############################################################################
+
+[Rule.Common.SEC]
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
+    TE  TE Align = 4K                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+  }
+
+[Rule.Common.PEI_CORE]
+  FILE PEI_CORE = $(NAMED_GUID) {
+    TE     TE Align = 8                 $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI     STRING ="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.PEIM]
+  FILE PEIM = $(NAMED_GUID) {
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
+     TE       TE Align = 8              $(INF_OUTPUT)/$(MODULE_NAME).efi
+     UI       STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.PEIM.TIANOCOMPRESSED]
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
+      UI        STRING="$(MODULE_NAME)" Optional
+    }
+  }
+
+[Rule.Common.DXE_CORE]
+  FILE DXE_CORE = $(NAMED_GUID) {
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI       STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.UEFI_DRIVER]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.DXE_DRIVER]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.DXE_RUNTIME_DRIVER]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.UEFI_APPLICATION]
+  FILE APPLICATION = $(NAMED_GUID) {
+    UI     STRING ="$(MODULE_NAME)"     Optional
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
+  }
+
+[Rule.Common.UEFI_DRIVER.BINARY]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX DXE_DEPEX Optional      |.depex
+    PE32      PE32                    |.efi
+    UI        STRING="$(MODULE_NAME)" Optional
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+  }
+
+[Rule.Common.UEFI_APPLICATION.BINARY]
+  FILE APPLICATION = $(NAMED_GUID) {
+    PE32      PE32                    |.efi
+    UI        STRING="$(MODULE_NAME)" Optional
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+  }
+
+[Rule.Common.USER_DEFINED.ACPITABLE]
+  FILE FREEFORM = $(NAMED_GUID) {
+    RAW       ACPI                    |.acpi
+    RAW       ASL                     |.aml
+    UI        STRING="$(MODULE_NAME)" Optional
+  }

A message that is not in the archive (sent off-list or not yet received): [email protected]

#50 lore raw

Re: [PATCH v2 29/29] ArmVirtualizationPkg: add platform description for Xen guests

Quoted 32 lines · Laszlo Ersek
Quoted 31 lines · Ard Biesheuvel

This adds the .dsc and .fdf descriptions to build a UEFI image that is bootable by a Xen guest on 64-bit ARM (AArch64)

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf | 337 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 616 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +15 -0
new file mode 100644
index 000000000000..bcc9742c6828
@@ -0,0 +1,279 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+################################################################################
Quoted 9 lines

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc line 21

Quoted 6 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +6 -0
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+[Defines]
+  PLATFORM_NAME                  = ArmVirtualizationQemu

Wut? :)

Y I spotted that one myself in the mean time

Quoted 4 lines

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc line 22

Quoted 1 line
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +1 -0
+  PLATFORM_GUID                  = 37d7e986-f7e9-45c2-8067-e371421a626c

PLATFORM_GUID shoud be updated as well.

OK

Quoted 8 lines

I won't check the rest of the patch now; you got several notes from Julien. Please eyeball this patch for any leftovers from the QEMU files. You can add my

then.

Yes. I am removing all the virtio references and ARM bds bits.

Quoted 3 lines

Also, I think I finished reviewing the series. (Some patches I didn't comment on; I didn't want to review those.)

Many thanks for taking so much time to review this. I really appreciate it a lot!

I intend to send out v3 before heading off to Hong Kong for Linaro Connect, so probably tomorrow by the end of the day.

Cheers,
Ard.

Quoted 602 lines
Quoted 601 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc new file +257 -0
+  PLATFORM_VERSION               = 0.1
+  DSC_SPECIFICATION              = 0x00010005
+  OUTPUT_DIRECTORY               = Build/ArmVirtualizationXen-$(ARCH)
+  SUPPORTED_ARCHITECTURES        = AARCH64
+  BUILD_TARGETS                  = DEBUG|RELEASE
+  SKUID_IDENTIFIER               = DEFAULT
+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf
+
+!include ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
+
+[LibraryClasses]
+  SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
+  XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf
+  XenIoMmioLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf
+
+[LibraryClasses.AARCH64]
+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf
+
+[LibraryClasses.ARM]
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf
+
+[LibraryClasses.common]
+  # Virtio Support
+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
+
+  ArmPlatformLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
+  ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf
+
+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
+
+!ifdef INTEL_BDS
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+  GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+  PlatformBdsLib|ArmPlatformPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
+  CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+!endif
+
+[LibraryClasses.common.UEFI_DRIVER]
+  UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+
+[LibraryClasses.AARCH64.SEC]
+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf
+
+[LibraryClasses.ARM.SEC]
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf
+
+[BuildOptions]
+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+  GCC:*_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include
+
+################################################################################
+#
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform
+#
+################################################################################
+
+[PcdsFeatureFlag.common]
+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.
+  #  It could be set FALSE to save size.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE
+
+[PcdsFixedAtBuild.common]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F
+
+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"XEN-UEFI"
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"$(FIRMWARE_VER)"
+
+  gArmPlatformTokenSpaceGuid.PcdCoreCount|1
+!if $(ARCH) == AARCH64
+  gArmTokenSpaceGuid.PcdVFPEnabled|1
+!endif
+
+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000
+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000
+
+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000
+
+  #
+  # ARM Pcds
+  #
+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000
+
+  ## Trustzone enable (to make the transition from EL3 to EL2 in ArmPlatformPkg/Sec)
+  gArmTokenSpaceGuid.PcdTrustzoneSupport|FALSE
+
+  #
+  # ARM PrimeCell
+  #
+
+  ## PL011 - Serial Terminal
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400
+
+  #
+  # ARM OS Loader
+  #
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux (EFI stub) on virtio31:hd0:part0"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000)/HD(1,MBR,0x00000000,0x3F,0x19FC0)/Image"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 console=ttyAMA0 earlycon uefi_debug"
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|0
+
+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)
+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"
+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"
+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|3
+
+  #
+  # ARM Virtual Architectural Timer
+  #
+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000
+
+  #
+  # NV Storage PCDs. Use base of 0x04000000 for NOR1
+  #
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x04000000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x04040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00040000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x04080000
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00040000
+
+!ifdef INTEL_BDS
+  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
+!endif
+
+[PcdsPatchableInModule.common]
+  #
+  # This will be overridden in the code
+  #
+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x0
+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x0
+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0
+
+  gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
+  gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
+
+[PcdsDynamicDefault.common]
+
+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0
+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0
+
+  #
+  # ARM General Interrupt Controller
+  #
+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x0
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x0
+
+  ## PL031 RealTimeClock
+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0
+
+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0
+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress|0x0
+
+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod|0
+
+################################################################################
+#
+# Components Section - list of all EDK II Modules needed by this Platform
+#
+################################################################################
+[Components.common]
+  #
+  # PEI Phase modules
+  #
+  ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf {
+    <LibraryClasses>
+      ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
+      LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
+      PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
+      HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
+      PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
+      MemoryInitPeiLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf
+      ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf
+      MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf
+      SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+      DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
+  }
+
+  #
+  # DXE
+  #
+  MdeModulePkg/Core/Dxe/DxeMain.inf {
+    <LibraryClasses>
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
+  }
+  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+
+  #
+  # Architectural Protocols
+  #
+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf
+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+
+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
+
+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
+
+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+
+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # Platform Driver
+  #
+  ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+  OvmfPkg/VirtioNetDxe/VirtioNet.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Bds
+  #
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+!ifdef INTEL_BDS
+  MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
+  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+!else
+  ArmPlatformPkg/Bds/Bds.inf
+!endif
+
+  #
+  # SCSI Bus and Disk Driver
+  #
+  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+
+  OvmfPkg/XenBusDxe/XenBusDxe.inf
+  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.fdf new file +337 -0
new file mode 100644
index 000000000000..4676a7b2b29f
@@ -0,0 +1,337 @@
+#
+#  Copyright (c) 2011, 2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+################################################################################
+#
+# FD Section
+# The [FD] Section is made up of the definition statements and a
+# description of what goes into  the Flash Device Image.  Each FD section
+# defines one flash "device" image.  A flash device image may be one of
+# the following: Removable media bootable image (like a boot floppy
+# image,) an Option ROM image (that would be "flashed" into an add-in
+# card,) a System "Flash"  image (that would be burned into a system's
+# flash) or an Update ("Capsule") image that will be used to update and
+# existing system flash.
+#
+################################################################################
+
+[FD.XEN_EFI]
+BaseAddress   = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress
+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize
+ErasePolarity = 1
+
+# This one is tricky, it must be: BlockSize * NumBlocks = Size
+BlockSize     = 0x00001000
+NumBlocks     = 0x200
+
+################################################################################
+#
+# Following are lists of FD Region layout which correspond to the locations of different
+# images within the flash device.
+#
+# Regions must be defined in ascending order and may not overlap.
+#
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by
+# the pipe "|" character, followed by the size of the region, also in hex with the leading
+# "0x" characters. Like:
+# Offset|Size
+# PcdOffsetCName|PcdSizeCName
+# RegionType <FV, DATA, or FILE>
+#
+################################################################################
+
+#
+# Implement the Linux kernel header layout so that the Xen loader will identify
+# it as something bootable, and execute it with a FDT pointer in x0. This area
+# will be reused to store a copy of the FDT so round it up to 8 KB.
+#
+0x00000000|0x00002000
+DATA = {
+  0x01, 0x00, 0x00, 0x10,                         # code0: adr x1, .
+  0xff, 0x07, 0x00, 0x14,                         # code1: b 0x2000
+  0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, # text_offset: 512 KB
+  0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, # image_size: 2 MB
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # flags
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # res2
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # res3
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # res4
+  0x41, 0x52, 0x4d, 0x64,                         # magic: "ARM\x64"
+  0x00, 0x00, 0x00, 0x00                          # res5
+}
+
+0x00002000|0x001fe000
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
+FV = FVMAIN_COMPACT
+
+
+################################################################################
+#
+# FV Section
+#
+# [FV] section is used to define what components or modules are placed within a flash
+# device file.  This section also defines order the components and modules are positioned
+# within the image.  The [FV] section consists of define statements, set statements and
+# module statements.
+#
+################################################################################
+
+[FV.FvMain]
+BlockSize          = 0x40
+NumBlocks          = 0         # This FV gets compressed so make it just big enough
+FvAlignment        = 16        # FV alignment and FV attributes setting.
+ERASE_POLARITY     = 1
+MEMORY_MAPPED      = TRUE
+STICKY_WRITE       = TRUE
+LOCK_CAP           = TRUE
+LOCK_STATUS        = TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP  = TRUE
+WRITE_STATUS       = TRUE
+WRITE_LOCK_CAP     = TRUE
+WRITE_LOCK_STATUS  = TRUE
+READ_DISABLED_CAP  = TRUE
+READ_ENABLED_CAP   = TRUE
+READ_STATUS        = TRUE
+READ_LOCK_CAP      = TRUE
+READ_LOCK_STATUS   = TRUE
+
+  APRIORI DXE {
+    INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+    INF ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+  }
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf
+  INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+  INF ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
+
+  #
+  # PI DXE Drivers producing Architectural Protocols (EFI Services)
+  #
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+
+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
+
+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+
+  #
+  # Multiple Console IO support
+  #
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf
+
+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+
+  #
+  # FAT filesystem + GPT/MBR partitioning
+  #
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+
+  #
+  # Platform Driver
+  #
+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+  INF OvmfPkg/VirtioNetDxe/VirtioNet.inf
+  INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+
+  #
+  # UEFI application (Shell Embedded Boot Loader)
+  #
+  INF ShellBinPkg/UefiShell/UefiShell.inf
+
+  #
+  # Bds
+  #
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+!ifdef INTEL_BDS
+  INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
+  INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+  INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+!else
+  INF ArmPlatformPkg/Bds/Bds.inf
+!endif
+
+  #
+  # Networking stack
+  #
+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf
+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf
+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
+
+  #
+  # SCSI Bus and Disk Driver
+  #
+  INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+  INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+
+  INF OvmfPkg/XenBusDxe/XenBusDxe.inf
+  INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+
+[FV.FVMAIN_COMPACT]
+FvAlignment        = 16
+ERASE_POLARITY     = 1
+MEMORY_MAPPED      = TRUE
+STICKY_WRITE       = TRUE
+LOCK_CAP           = TRUE
+LOCK_STATUS        = TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP  = TRUE
+WRITE_STATUS       = TRUE
+WRITE_LOCK_CAP     = TRUE
+WRITE_LOCK_STATUS  = TRUE
+READ_DISABLED_CAP  = TRUE
+READ_ENABLED_CAP   = TRUE
+READ_STATUS        = TRUE
+READ_LOCK_CAP      = TRUE
+READ_LOCK_STATUS   = TRUE
+
+  INF ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf
+
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
+      SECTION FV_IMAGE = FVMAIN
+    }
+  }
+
+
+################################################################################
+#
+# Rules are use with the [FV] section's module INF type to define
+# how an FFS file is created for a given INF file. The following Rule are the default
+# rules for the different module type. User can add the customized rules to define the
+# content of the FFS file.
+#
+################################################################################
+
+
+############################################################################
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #
+############################################################################
+#
+#[Rule.Common.DXE_DRIVER]
+#  FILE DRIVER = $(NAMED_GUID) {
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+#    COMPRESS PI_STD {
+#      GUIDED {
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
+#        UI       STRING="$(MODULE_NAME)" Optional
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+#      }
+#    }
+#  }
+#
+############################################################################
+
+[Rule.Common.SEC]
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
+    TE  TE Align = 4K                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+  }
+
+[Rule.Common.PEI_CORE]
+  FILE PEI_CORE = $(NAMED_GUID) {
+    TE     TE Align = 8                 $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI     STRING ="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.PEIM]
+  FILE PEIM = $(NAMED_GUID) {
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
+     TE       TE Align = 8              $(INF_OUTPUT)/$(MODULE_NAME).efi
+     UI       STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.PEIM.TIANOCOMPRESSED]
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
+      UI        STRING="$(MODULE_NAME)" Optional
+    }
+  }
+
+[Rule.Common.DXE_CORE]
+  FILE DXE_CORE = $(NAMED_GUID) {
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI       STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.UEFI_DRIVER]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.DXE_DRIVER]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.DXE_RUNTIME_DRIVER]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
+    UI           STRING="$(MODULE_NAME)" Optional
+  }
+
+[Rule.Common.UEFI_APPLICATION]
+  FILE APPLICATION = $(NAMED_GUID) {
+    UI     STRING ="$(MODULE_NAME)"     Optional
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
+  }
+
+[Rule.Common.UEFI_DRIVER.BINARY]
+  FILE DRIVER = $(NAMED_GUID) {
+    DXE_DEPEX DXE_DEPEX Optional      |.depex
+    PE32      PE32                    |.efi
+    UI        STRING="$(MODULE_NAME)" Optional
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+  }
+
+[Rule.Common.UEFI_APPLICATION.BINARY]
+  FILE APPLICATION = $(NAMED_GUID) {
+    PE32      PE32                    |.efi
+    UI        STRING="$(MODULE_NAME)" Optional
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+  }
+
+[Rule.Common.USER_DEFINED.ACPITABLE]
+  FILE FREEFORM = $(NAMED_GUID) {
+    RAW       ACPI                    |.acpi
+    RAW       ASL                     |.aml
+    UI        STRING="$(MODULE_NAME)" Optional
+  }

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#52 lore raw

Re: [PATCH v2 22/29] Ovmf/Xen: implement XenHypercallLib for ARM

Quoted 5 lines · Ard Biesheuvel

This patch adds an implementation of XenHypercallLib for both AArch64 and AArch32 execution modes on ARM systems.

Contributed-under: TianoCore Contribution Agreement 1.0

Quoted 574 lines
 OvmfPkg/Include/IndustryStandard/Xen/arch-arm/xen.h    | 436 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Include/IndustryStandard/Xen/xen.h             |   2 +-
 OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S    |  26 ++++++
 OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S        |  25 +++++
 OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf |  40 ++++++++
 5 files changed, 528 insertions(+), 1 deletion(-)
OvmfPkg/Include/IndustryStandard/Xen/arch-arm/xen.h new file +436 -0
new file mode 100644
index 000000000000..655a221f6337
@@ -0,0 +1,436 @@
+/******************************************************************************
+ * arch-arm.h
+ *
+ * Guest OS interface to ARM Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2011 (C) Citrix Systems
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_ARM_H__
+#define __XEN_PUBLIC_ARCH_ARM_H__
+
+/*
+ * `incontents 50 arm_abi Hypercall Calling Convention
+ *
+ * A hypercall is issued using the ARM HVC instruction.
+ *
+ * A hypercall can take up to 5 arguments. These are passed in
+ * registers, the first argument in x0/r0 (for arm64/arm32 guests
+ * respectively irrespective of whether the underlying hypervisor is
+ * 32- or 64-bit), the second argument in x1/r1, the third in x2/r2,
+ * the forth in x3/r3 and the fifth in x4/r4.
+ *
+ * The hypercall number is passed in r12 (arm) or x16 (arm64). In both
+ * cases the relevant ARM procedure calling convention specifies this
+ * is an inter-procedure-call scratch register (e.g. for use in linker
+ * stubs). This use does not conflict with use during a hypercall.
+ *
+ * The HVC ISS must contain a Xen specific TAG: XEN_HYPERCALL_TAG.
+ *
+ * The return value is in x0/r0.
+ *
+ * The hypercall will clobber x16/r12 and the argument registers used
+ * by that hypercall (except r0 which is the return value) i.e. in
+ * addition to x16/r12 a 2 argument hypercall will clobber x1/r1 and a
+ * 4 argument hypercall will clobber x1/r1, x2/r2 and x3/r3.
+ *
+ * Parameter structs passed to hypercalls are laid out according to
+ * the Procedure Call Standard for the ARM Architecture (AAPCS, AKA
+ * EABI) and Procedure Call Standard for the ARM 64-bit Architecture
+ * (AAPCS64). Where there is a conflict the 64-bit standard should be
+ * used regardless of guest type. Structures which are passed as
+ * hypercall arguments are always little endian.
+ *
+ * All memory which is shared with other entities in the system
+ * (including the hypervisor and other guests) must reside in memory
+ * which is mapped as Normal Inner-cacheable. This applies to:
+ *  - hypercall arguments passed via a pointer to guest memory.
+ *  - memory shared via the grant table mechanism (including PV I/O
+ *    rings etc).
+ *  - memory shared with the hypervisor (struct shared_info, struct
+ *    vcpu_info, the grant table, etc).
+ *
+ * Any Inner cache allocation strategy (Write-Back, Write-Through etc)
+ * is acceptable. There is no restriction on the Outer-cacheability.
+ */
+
+/*
+ * `incontents 55 arm_hcall Supported Hypercalls
+ *
+ * Xen on ARM makes extensive use of hardware facilities and therefore
+ * only a subset of the potential hypercalls are required.
+ *
+ * Since ARM uses second stage paging any machine/physical addresses
+ * passed to hypercalls are Guest Physical Addresses (Intermediate
+ * Physical Addresses) unless otherwise noted.
+ *
+ * The following hypercalls (and sub operations) are supported on the
+ * ARM platform. Other hypercalls should be considered
+ * unavailable/unsupported.
+ *
+ *  HYPERVISOR_memory_op
+ *   All generic sub-operations.
+ *
+ *   In addition the following arch specific sub-ops:
+ *    * XENMEM_add_to_physmap
+ *    * XENMEM_add_to_physmap_batch
+ *
+ *  HYPERVISOR_domctl
+ *   All generic sub-operations, with the exception of:
+ *    * XEN_DOMCTL_iomem_permission (not yet implemented)
+ *    * XEN_DOMCTL_irq_permission (not yet implemented)
+ *
+ *  HYPERVISOR_sched_op
+ *   All generic sub-operations, with the exception of:
+ *    * SCHEDOP_block -- prefer wfi hardware instruction
+ *
+ *  HYPERVISOR_console_io
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_xen_version
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_event_channel_op
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_physdev_op
+ *   No sub-operations are currenty supported
+ *
+ *  HYPERVISOR_sysctl
+ *   All generic sub-operations, with the exception of:
+ *    * XEN_SYSCTL_page_offline_op
+ *    * XEN_SYSCTL_get_pmstat
+ *    * XEN_SYSCTL_pm_op
+ *
+ *  HYPERVISOR_hvm_op
+ *   Exactly these sub-operations are supported:
+ *    * HVMOP_set_param
+ *    * HVMOP_get_param
+ *
+ *  HYPERVISOR_grant_table_op
+ *   All generic sub-operations
+ *
+ *  HYPERVISOR_vcpu_op
+ *   Exactly these sub-operations are supported:
+ *    * VCPUOP_register_vcpu_info
+ *    * VCPUOP_register_runstate_memory_area
+ *
+ *
+ * Other notes on the ARM ABI:
+ *
+ * - struct start_info is not exported to ARM guests.
+ *
+ * - struct shared_info is mapped by ARM guests using the
+ *   HYPERVISOR_memory_op sub-op XENMEM_add_to_physmap, passing
+ *   XENMAPSPACE_shared_info as space parameter.
+ *
+ * - All the per-cpu struct vcpu_info are mapped by ARM guests using the
+ *   HYPERVISOR_vcpu_op sub-op VCPUOP_register_vcpu_info, including cpu0
+ *   struct vcpu_info.
+ *
+ * - The grant table is mapped using the HYPERVISOR_memory_op sub-op
+ *   XENMEM_add_to_physmap, passing XENMAPSPACE_grant_table as space
+ *   parameter. The memory range specified under the Xen compatible
+ *   hypervisor node on device tree can be used as target gpfn for the
+ *   mapping.
+ *
+ * - Xenstore is initialized by using the two hvm_params
+ *   HVM_PARAM_STORE_PFN and HVM_PARAM_STORE_EVTCHN. They can be read
+ *   with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
+ *
+ * - The paravirtualized console is initialized by using the two
+ *   hvm_params HVM_PARAM_CONSOLE_PFN and HVM_PARAM_CONSOLE_EVTCHN. They
+ *   can be read with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
+ *
+ * - Event channel notifications are delivered using the percpu GIC
+ *   interrupt specified under the Xen compatible hypervisor node on
+ *   device tree.
+ *
+ * - The device tree Xen compatible node is fully described under Linux
+ *   at Documentation/devicetree/bindings/arm/xen.txt.
+ */
+
+#define XEN_HYPERCALL_TAG   0XEA1
+
+#define uint64_aligned_t UINT64 __attribute__((aligned(8)))
+
+#ifndef __ASSEMBLY__
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
+    typedef union { type *p; unsigned long q; }                 \
+        __guest_handle_ ## name;                                \
+    typedef union { type *p; uint64_aligned_t q; }              \
+        __guest_handle_64_ ## name;
+
+/*
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
+ * in a struct in memory. On ARM is always 8 bytes sizes and 8 bytes
+ * aligned.
+ * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
+ * hypercall argument. It is 4 bytes on aarch and 8 bytes on aarch64.
+ */
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
+/* this is going to be changed on 64 bit */
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
+#define set_xen_guest_handle_raw(hnd, val)                  \
+    do {                                                    \
+        typeof(&(hnd)) _sxghr_tmp = &(hnd);                 \
+        _sxghr_tmp->q = 0;                                  \
+        _sxghr_tmp->p = val;                                \
+    } while ( 0 )
+#ifdef __XEN_TOOLS__
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
+#endif
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+/* Anonymous union includes both 32- and 64-bit names (e.g., r0/x0). */
+# define __DECL_REG(n64, n32) union {          \
+        UINT64 n64;                          \
+        UINT32 n32;                          \
+    }
+#else
+/* Non-gcc sources must always use the proper 64-bit name (e.g., x0). */
+#define __DECL_REG(n64, n32) UINT64 n64
+#endif
+
+struct vcpu_guest_core_regs
+{
+    /*         Aarch64       Aarch32 */
+    __DECL_REG(x0,           r0_usr);
+    __DECL_REG(x1,           r1_usr);
+    __DECL_REG(x2,           r2_usr);
+    __DECL_REG(x3,           r3_usr);
+    __DECL_REG(x4,           r4_usr);
+    __DECL_REG(x5,           r5_usr);
+    __DECL_REG(x6,           r6_usr);
+    __DECL_REG(x7,           r7_usr);
+    __DECL_REG(x8,           r8_usr);
+    __DECL_REG(x9,           r9_usr);
+    __DECL_REG(x10,          r10_usr);
+    __DECL_REG(x11,          r11_usr);
+    __DECL_REG(x12,          r12_usr);
+
+    __DECL_REG(x13,          sp_usr);
+    __DECL_REG(x14,          lr_usr);
+
+    __DECL_REG(x15,          __unused_sp_hyp);
+
+    __DECL_REG(x16,          lr_irq);
+    __DECL_REG(x17,          sp_irq);
+
+    __DECL_REG(x18,          lr_svc);
+    __DECL_REG(x19,          sp_svc);
+
+    __DECL_REG(x20,          lr_abt);
+    __DECL_REG(x21,          sp_abt);
+
+    __DECL_REG(x22,          lr_und);
+    __DECL_REG(x23,          sp_und);
+
+    __DECL_REG(x24,          r8_fiq);
+    __DECL_REG(x25,          r9_fiq);
+    __DECL_REG(x26,          r10_fiq);
+    __DECL_REG(x27,          r11_fiq);
+    __DECL_REG(x28,          r12_fiq);
+
+    __DECL_REG(x29,          sp_fiq);
+    __DECL_REG(x30,          lr_fiq);
+
+    /* Return address and mode */
+    __DECL_REG(pc64,         pc32);             /* ELR_EL2 */
+    UINT32 cpsr;                              /* SPSR_EL2 */
+
+    union {
+        UINT32 spsr_el1;       /* AArch64 */
+        UINT32 spsr_svc;       /* AArch32 */
+    };
+
+    /* AArch32 guests only */
+    UINT32 spsr_fiq, spsr_irq, spsr_und, spsr_abt;
+
+    /* AArch64 guests only */
+    UINT64 sp_el0;
+    UINT64 sp_el1, elr_el1;
+};
+typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
+
+#undef __DECL_REG
+
+typedef UINT64 xen_pfn_t;
+#define PRI_xen_pfn PRIx64
+
+/* Maximum number of virtual CPUs in legacy multi-processor guests. */
+/* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
+#define XEN_LEGACY_MAX_VCPUS 1
+
+typedef UINT64 xen_ulong_t;
+#define PRI_xen_ulong PRIx64
+
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+struct vcpu_guest_context {
+#define _VGCF_online                   0
+#define VGCF_online                    (1<<_VGCF_online)
+    UINT32 flags;                         /* VGCF_* */
+
+    struct vcpu_guest_core_regs user_regs;  /* Core CPU registers */
+
+    UINT32 sctlr;
+    UINT64 ttbcr, ttbr0, ttbr1;
+};
+typedef struct vcpu_guest_context vcpu_guest_context_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
+#endif
+
+struct arch_vcpu_info {
+};
+typedef struct arch_vcpu_info arch_vcpu_info_t;
+
+struct arch_shared_info {
+};
+typedef struct arch_shared_info arch_shared_info_t;
+typedef UINT64 xen_callback_t;
+
+#endif
+
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+
+/* PSR bits (CPSR, SPSR)*/
+
+#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
+#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
+#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
+
+/* 32 bit modes */
+#define PSR_MODE_USR 0x10
+#define PSR_MODE_FIQ 0x11
+#define PSR_MODE_IRQ 0x12
+#define PSR_MODE_SVC 0x13
+#define PSR_MODE_MON 0x16
+#define PSR_MODE_ABT 0x17
+#define PSR_MODE_HYP 0x1a
+#define PSR_MODE_UND 0x1b
+#define PSR_MODE_SYS 0x1f
+
+/* 64 bit modes */
+#define PSR_MODE_BIT  0x10 /* Set iff AArch32 */
+#define PSR_MODE_EL3h 0x0d
+#define PSR_MODE_EL3t 0x0c
+#define PSR_MODE_EL2h 0x09
+#define PSR_MODE_EL2t 0x08
+#define PSR_MODE_EL1h 0x05
+#define PSR_MODE_EL1t 0x04
+#define PSR_MODE_EL0t 0x00
+
+#define PSR_GUEST32_INIT  (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)
+#define PSR_GUEST64_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h)
+
+#define SCTLR_GUEST_INIT    0x00c50078
+
+/*
+ * Virtual machine platform (memory layout, interrupts)
+ *
+ * These are defined for consistency between the tools and the
+ * hypervisor. Guests must not rely on these hardcoded values but
+ * should instead use the FDT.
+ */
+
+/* Physical Address Space */
+
+/* vGIC mappings: Only one set of mapping is used by the guest.
+ * Therefore they can overlap.
+ */
+
+/* vGIC v2 mappings */
+#define GUEST_GICD_BASE   0x03001000ULL
+#define GUEST_GICD_SIZE   0x00001000ULL
+#define GUEST_GICC_BASE   0x03002000ULL
+#define GUEST_GICC_SIZE   0x00000100ULL
+
+/* vGIC v3 mappings */
+#define GUEST_GICV3_GICD_BASE      0x03001000ULL
+#define GUEST_GICV3_GICD_SIZE      0x00010000ULL
+
+#define GUEST_GICV3_RDIST_STRIDE   0x20000ULL
+#define GUEST_GICV3_RDIST_REGIONS  1
+
+#define GUEST_GICV3_GICR0_BASE     0x03020000ULL    /* vCPU0 - vCPU7 */
+#define GUEST_GICV3_GICR0_SIZE     0x00100000ULL
+
+/* 16MB == 4096 pages reserved for guest to use as a region to map its
+ * grant table in.
+ */
+#define GUEST_GNTTAB_BASE 0x38000000ULL
+#define GUEST_GNTTAB_SIZE 0x01000000ULL
+
+#define GUEST_MAGIC_BASE  0x39000000ULL
+#define GUEST_MAGIC_SIZE  0x01000000ULL
+
+#define GUEST_RAM_BANKS   2
+
+#define GUEST_RAM0_BASE   0x40000000ULL /* 3GB of low RAM @ 1GB */
+#define GUEST_RAM0_SIZE   0xc0000000ULL
+
+#define GUEST_RAM1_BASE   0x0200000000ULL /* 1016GB of RAM @ 8GB */
+#define GUEST_RAM1_SIZE   0xfe00000000ULL
+
+#define GUEST_RAM_BASE    GUEST_RAM0_BASE /* Lowest RAM address */
+/* Largest amount of actual RAM, not including holes */
+#define GUEST_RAM_MAX     (GUEST_RAM0_SIZE + GUEST_RAM1_SIZE)
+/* Suitable for e.g. const uint64_t ramfoo[] = GUEST_RAM_BANK_FOOS; */
+#define GUEST_RAM_BANK_BASES   { GUEST_RAM0_BASE, GUEST_RAM1_BASE }
+#define GUEST_RAM_BANK_SIZES   { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
+
+/* Interrupts */
+#define GUEST_TIMER_VIRT_PPI    27
+#define GUEST_TIMER_PHYS_S_PPI  29
+#define GUEST_TIMER_PHYS_NS_PPI 30
+#define GUEST_EVTCHN_PPI        31
+
+/* PSCI functions */
+#define PSCI_cpu_suspend 0
+#define PSCI_cpu_off     1
+#define PSCI_cpu_on      2
+#define PSCI_migrate     3
+
+#endif
+
+#endif /*  __XEN_PUBLIC_ARCH_ARM_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
OvmfPkg/Include/IndustryStandard/Xen/xen.h +1 -1
index 1cd7ab3ab136..8596ca1bd26f 100644
@@ -37,7 +37,7 @@
 #if defined(MDE_CPU_IA32) || defined(MDE_CPU_X64)
 #include "arch-x86/xen.h"
 #elif defined(__arm__) || defined (__aarch64__)
-#include "arch-arm.h"
+#include "arch-arm/xen.h"
 #else
 #error "Unsupported architecture"
 #endif
OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S new file +26 -0
new file mode 100644
index 000000000000..b1b5d4cc3f28
@@ -0,0 +1,26 @@
+
+/** @file
+  AArch64 implementation of XenHypercall2
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Xen/arch-arm/xen.h>
+
+  .text
+  .global   ASM_PFX(XenHypercall2)
+ASM_PFX(XenHypercall2):
+  mov     x16, x0
+  mov     x0, x1
+  mov     x1, x2
+  hvc     #XEN_HYPERCALL_TAG
+  ret
OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S new file +25 -0
new file mode 100644
index 000000000000..b38e1a8f18da
@@ -0,0 +1,25 @@
+/** @file
+  ARM (AArch32) implementation of XenHypercall2
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Xen/arch-arm/xen.h>
+
+  .text
+  .global   ASM_PFX(XenHypercall2)
+ASM_PFX(XenHypercall2):
+  mov     r12, r0
+  mov     r0, r1
+  mov     r1, r2
+  hvc     #XEN_HYPERCALL_TAG
+  bx      lr
OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf new file +40 -0
new file mode 100644
index 000000000000..9cbbeb5d8789
@@ -0,0 +1,40 @@
+## @file
+#  Xen Hypercall abstraction lib for ARM architecture
+#
+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenHypercallLibArm
+  FILE_GUID                      = 9607AC2E-FCB9-499B-9475-612282019568
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = XenHypercallLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = ARM AARCH64
+#
+
+[Sources.ARM]
+  Arm/Hypercall.S
+
+[Sources.AARCH64]
+  Aarch64/Hypercall.S
+
+[Sources]
+  XenHypercall.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
Signature · 1 line
1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#54 lore raw
Quoted 62 lines · Ard Biesheuvel

The DT binding for the ARM generic timer describes the secure, non-secure, virtual and hypervisor timer interrupts, respectively. However, under virtualization, only the virtual timer is usable, and the device tree may omit the hypervisor timer interrupt. (Other timer interrupts cannot be omitted simply due to the fact that the virtual timer is listed third)

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPkg/Drivers/TimerDxe/TimerDxe.c                          | 14 +++++++++++---
 ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c |  6 +++---
 2 files changed, 14 insertions(+), 6 deletions(-)
ArmPkg/Drivers/TimerDxe/TimerDxe.c +11 -3
index d0a819fc2729..1169d426b255 100644
@@ -369,7 +369,8 @@ TimerInitialize (
 {
   EFI_HANDLE  Handle = NULL;
   EFI_STATUS  Status;
-  UINTN TimerCtrlReg;
+  UINTN       TimerCtrlReg;
+  UINT32      TimerHypIntrNum;
 
   if (ArmIsArchTimerImplemented () == 0) {
     DEBUG ((EFI_D_ERROR, "ARM Architectural Timer is not available in the CPU, hence cann't use this Driver \n"));
@@ -395,8 +396,15 @@ TimerInitialize (
   Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerVirtIntrNum), TimerInterruptHandler);
   ASSERT_EFI_ERROR (Status);
 
-  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerHypIntrNum), TimerInterruptHandler);
-  ASSERT_EFI_ERROR (Status);
+  //
+  // The hypervisor timer interrupt may be omitted by implementations that
+  // execute under virtualization.
+  //
+  TimerHypIntrNum = PcdGet32 (PcdArmArchTimerHypIntrNum);
+  if (TimerHypIntrNum != 0) {
+    Status = gInterrupt->RegisterInterruptSource (gInterrupt, TimerHypIntrNum, TimerInterruptHandler);
+    ASSERT_EFI_ERROR (Status);
+  }
 
   Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum), TimerInterruptHandler);
   ASSERT_EFI_ERROR (Status);
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +1 -1
index 751864d4db9c..1d44f9ba02b3 100644
@@ -274,7 +274,7 @@ InitializeVirtFdtDxe (
       //  hypervisor timers, in that order.
       //
       InterruptProp = fdt_getprop (DeviceTreeBase, Node, "interrupts", &Len);
-      ASSERT (Len == 48);
+      ASSERT (Len == 36 || Len == 48);
 
       SecIntrNum = fdt32_to_cpu (InterruptProp[0].Number)
                    + (InterruptProp[0].Type ? 16 : 0);

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c InitializeVirtFdtDxe ( · line 289

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +2 -2
@@ -282,8 +282,8 @@ InitializeVirtFdtDxe (
                 + (InterruptProp[1].Type ? 16 : 0);
       VirtIntrNum = fdt32_to_cpu (InterruptProp[2].Number)
                     + (InterruptProp[2].Type ? 16 : 0);
-      HypIntrNum = fdt32_to_cpu (InterruptProp[3].Number)
-                   + (InterruptProp[3].Type ? 16 : 0);
+      HypIntrNum = Len < 48 ? 0 : fdt32_to_cpu (InterruptProp[3].Number)
+                                  + (InterruptProp[3].Type ? 16 : 0);
 
       DEBUG ((EFI_D_INFO, "Found Timer interrupts %d, %d, %d, %d\n",
         SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum));

A message that is not in the archive (sent off-list or not yet received): [email protected]

Acked-by
#56 lore raw

Re: [PATCH v2 02/29] ArmPkg: allow patchable PCDs for memory, FD and FV addresses

Quoted 70 lines · Ard Biesheuvel

In order to allow a runtime self relocating PrePi instance, change the allowable PCD types for the following PCDs:

gArmTokenSpaceGuid.PcdSystemMemoryBase
gArmTokenSpaceGuid.PcdSystemMemorySize
gArmTokenSpaceGuid.PcdFdBaseAddress
gArmTokenSpaceGuid.PcdFvBaseAddress

to include PcdsPatchableInModule. This makes the build system correctly distinguish fixed PCDs from PCDs whose value may be different from the assigned value at compile time.

Note that this only affects platforms that explicitly mark these PCDs as PatchableInModule in the DSC. All existing platforms that use FixedPcd will not be affected by this change.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPkg/ArmPkg.dec | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
ArmPkg/ArmPkg.dec +13 -11
index d7a4826d931a..b01de13e5f78 100644
@@ -93,14 +93,6 @@
   gArmTokenSpaceGuid.PcdSecureFvSize|0x0|UINT32|0x00000030
 
   #
-  # ARM Normal (or Non Secure) Firmware PCDs
-  #
-  gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
-  gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
-  gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
-  gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
-
-  #
   # ARM Hypervisor Firmware PCDs
   #
   gArmTokenSpaceGuid.PcdHypFdBaseAddress|0|UINT32|0x0000003A
@@ -127,6 +119,15 @@
   # Maximum file size for TFTP servers that do not support 'tsize' extension
   gArmTokenSpaceGuid.PcdMaxTftpFileSize|0x01000000|UINT32|0x00000000
 
+  #
+  # ARM Normal (or Non Secure) Firmware PCDs
+  #
+  gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
+  gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
+
+[PcdsFixedAtBuild.common, PcdsPatchableInModule.common]
+  gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
+  gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
 
 [PcdsFixedAtBuild.ARM]
   #
@@ -207,16 +208,18 @@
 
 
 #
-# These PCDs are also defined as 'PcdsDynamic' to be redefined when using UEFI in a
-# context of virtual machine.
+# These PCDs are also defined as 'PcdsDynamic' or 'PcdsPatchableInModule' to be
+# redefined when using UEFI in a context of virtual machine.
 #
-[PcdsFixedAtBuild.common, PcdsDynamic.common]
+[PcdsFixedAtBuild.common, PcdsDynamic.common, PcdsPatchableInModule.common]
+

ArmPkg/ArmPkg.dec line 225

Quoted 10 lines
ArmPkg/ArmPkg.dec +1 -0
   # System Memory (DRAM): These PCDs define the region of in-built system memory
   # Some platforms can get DRAM extensions, these additional regions will be declared
   # to UEFI by ArmPlatformLib
   gArmTokenSpaceGuid.PcdSystemMemoryBase|0|UINT64|0x00000029
   gArmTokenSpaceGuid.PcdSystemMemorySize|0|UINT64|0x0000002A
 
+[PcdsFixedAtBuild.common, PcdsDynamic.common]
   #
   # ARM Architectural Timer
   #
Reviewed-by
#57 lore raw

Re: [PATCH v2 02/29] ArmPkg: allow patchable PCDs for memory, FD and FV addresses

In reply to a message not in the archive
Quoted 101 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 02/29] ArmPkg: allow patchable PCDs for memory, FD and FV addresses

In order to allow a runtime self relocating PrePi instance, change the allowable PCD types for the following PCDs:

gArmTokenSpaceGuid.PcdSystemMemoryBase
gArmTokenSpaceGuid.PcdSystemMemorySize
gArmTokenSpaceGuid.PcdFdBaseAddress
gArmTokenSpaceGuid.PcdFvBaseAddress

to include PcdsPatchableInModule. This makes the build system correctly distinguish fixed PCDs from PCDs whose value may be different from the assigned value at compile time.

Note that this only affects platforms that explicitly mark these PCDs as
PatchableInModule in the DSC. All existing platforms that use FixedPcd will not be affected by this change.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPkg/ArmPkg.dec | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
ArmPkg/ArmPkg.dec +0 -8
index d7a4826d931a..b01de13e5f78 100644
@@ -93,14 +93,6 @@
   gArmTokenSpaceGuid.PcdSecureFvSize|0x0|UINT32|0x00000030
 
   #
-  # ARM Normal (or Non Secure) Firmware PCDs
-  #
-  gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
-  gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
-  gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
-  gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
-
-  #
   # ARM Hypervisor Firmware PCDs
   #
   gArmTokenSpaceGuid.PcdHypFdBaseAddress|0|UINT32|0x0000003A
@@ -127,6 +119,15 @@
   # Maximum file size for TFTP servers that do not support 'tsize'

extension
gArmTokenSpaceGuid.PcdMaxTftpFileSize|0x01000000|UINT32|0x00000000

ArmPkg/ArmPkg.dec +9 -1
+  #
+  # ARM Normal (or Non Secure) Firmware PCDs
+  #
+  gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
+  gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
+
+[PcdsFixedAtBuild.common, PcdsPatchableInModule.common]
+  gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
+  gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
 
 [PcdsFixedAtBuild.ARM]
   #
@@ -207,16 +208,18 @@
 
 
 #
-# These PCDs are also defined as 'PcdsDynamic' to be redefined when

using UEFI in a

ArmPkg/ArmPkg.dec +1 -1
-# context of virtual machine.
+# These PCDs are also defined as 'PcdsDynamic' or

'PcdsPatchableInModule' to be
+# redefined when using UEFI in a context of virtual machine.
#
-[PcdsFixedAtBuild.common, PcdsDynamic.common] +[PcdsFixedAtBuild.common, PcdsDynamic.common, PcdsPatchableInModule.common]
+
# System Memory (DRAM): These PCDs define the region of in-built
system memory
# Some platforms can get DRAM extensions, these additional regions
will be declared

   # to UEFI by ArmPlatformLib
   gArmTokenSpaceGuid.PcdSystemMemoryBase|0|UINT64|0x00000029
   gArmTokenSpaceGuid.PcdSystemMemorySize|0|UINT64|0x0000002A

+[PcdsFixedAtBuild.common, PcdsDynamic.common]
#
# ARM Architectural Timer
#
--
1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#59 lore raw

Re: [PATCH v2 03/29] ArmPlatformPkg: allow patchable PCD for FD base address

Quoted 54 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 03/29] ArmPlatformPkg: allow patchable PCD for FD base address

This moves the reference to gArmTokenSpaceGuid.PcdFdBaseAddress from the [FixedPcd] to the [Pcd] section in the INF file of PrePiArmPlatformGlobalVariableLib so that its users may choose to use a patchable PCD instead.

Contributed-under: TianoCore Contribution Agreement 1.0

---

ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatf ormGlobalVariableLib.inf | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPla tformGlobalVariableLib.inf b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPla tformGlobalVariableLib.inf
index 596f5595412e..37de35e7d00e 100644
---
a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPla tformGlobalVariableLib.inf
+++
b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPla tformGlobalVariableLib.inf

(quoted diff) +1 -2
@@ -34,7 +34,6 @@
   PcdLib
 
 [FixedPcd]
-  gArmTokenSpaceGuid.PcdFdBaseAddress
   gArmTokenSpaceGuid.PcdFdSize
 
   gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize
@@ -43,4 +42,5 @@
 [Pcd]
   gArmTokenSpaceGuid.PcdSystemMemoryBase
   gArmTokenSpaceGuid.PcdSystemMemorySize
+  gArmTokenSpaceGuid.PcdFdBaseAddress
 
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#61 lore raw

Re: [PATCH v2 05/29] ArmVirtualizationPkg: allow patchable PCD for device tree base address

Quoted 74 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 05/29] ArmVirtualizationPkg: allow patchable PCD for device tree base address

To allow a runtime self relocating PrePi instance to discover the base address of the device tree at runtime, allow the use of a patchable PCD for gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress. We will not be using the build time patch tool in this case, but using a patchable PCD will make the build system aware that its value is not a compile time constant.

Contributed-under: TianoCore Contribution Agreement 1.0

---
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec
| 2 +-

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLi b/Virt.c | 2 +-

 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec index 99411548aff6..d83117fc6abe 100644

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +1 -1
@@ -34,7 +34,7 @@
   gArmVirtualizationTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, {
 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, {
 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
 
-[PcdsFixedAtBuild]
+[PcdsFixedAtBuild, PcdsPatchableInModule]
   #

# This is the physical address where the device tree is expected to
be stored

   # upon first entry into UEFI. This needs to be a FixedAtBuild PCD,
so that we
diff --git
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform
Lib/Virt.c
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform
Lib/Virt.c
index aa4ced4582e8..3e3074af72f1 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform
Lib/Virt.c
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform
Lib/Virt.c
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +1 -1
@@ -96,7 +96,7 @@ ArmPlatformInitializeSystemMemory (
   ASSERT (HobData != NULL);
   *HobData = 0;
 
-  DeviceTreeBase = (VOID *)(UINTN)FixedPcdGet64
 (PcdDeviceTreeInitialBaseAddress);
+  DeviceTreeBase = (VOID *)(UINTN)PcdGet64
 (PcdDeviceTreeInitialBaseAddress);
   ASSERT (DeviceTreeBase != NULL);
   //

--
1.8.3.2

Reviewed-by
#62 lore raw

Re: [PATCH v2 05/29] ArmVirtualizationPkg: allow patchable PCD for device tree base address

In reply to a message not in the archive
Quoted 33 lines · Ard Biesheuvel

To allow a runtime self relocating PrePi instance to discover the base address of the device tree at runtime, allow the use of a patchable PCD for gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress. We will not be using the build time patch tool in this case, but using a patchable PCD will make the build system aware that its value is not a compile time constant.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec                    | 2 +-
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +1 -1
index 99411548aff6..d83117fc6abe 100644
@@ -34,7 +34,7 @@
   gArmVirtualizationTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
 
-[PcdsFixedAtBuild]
+[PcdsFixedAtBuild, PcdsPatchableInModule]
   #
   # This is the physical address where the device tree is expected to be stored
   # upon first entry into UEFI. This needs to be a FixedAtBuild PCD, so that we
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c +0 -0
index aa4ced4582e8..3e3074af72f1 100644

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c ArmPlatformInitializeSystemMemory ( · line 102

Quoted 8 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c +1 -1
@@ -96,7 +96,7 @@ ArmPlatformInitializeSystemMemory (
   ASSERT (HobData != NULL);
   *HobData = 0;
 
-  DeviceTreeBase = (VOID *)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
   ASSERT (DeviceTreeBase != NULL);
 
   //

A message that is not in the archive (sent off-list or not yet received): [email protected]

#64 lore raw

Re: [PATCH v2 07/29] ArmVirtualizationPkg: use a HOB to store device tree blob

I do not have a strong opinion on this patch.
It would be better to keep the dynamic PCD support in this patch. But I am aware it is not possible with PrePi (I had the issue a couple of weeks ago). Dynamic Pcds are actually supported when you use the PeiCore with PcdPeim. But the PeiCore only make sense at the moment on platforms that have DRAM initialized by the UEFI firmware.
I would like to extend the PI spec to also be able to use PeiCore in the case where the DRAM is already initialized at the time of the UEFI firmware. That would mean we could use the PcdPeim and Dynamic Pcd. But it will take time before we have support for it.
And I do not want to gate the patch set for this reason.

I am ok to accept it if no one reject it.

Anyway, this patch breaks the ARM Toolchain build:

"armlink" --partial -o /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/ArmPlatformPrePeiCore.lib --via /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/object_files.lst
"armlink" --ro-base 0 --no_scanlib --reloc --no_exceptions --datacompressor off --strict --symbols --diag_style=ide --entry _ModuleEntryPoint --map --list /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.map -o /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll --via /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/static_library_files.lst armlink : error L6218: Undefined symbol AllocatePages (referred from ArmVirtualizationPlatformLib.lib).
armlink : Not enough information to list image symbols.
armlink : Finished: 1 information, 0 warning and 1 error messages.

Quoted 299 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 07/29] ArmVirtualizationPkg: use a HOB to store device tree blob

Instead of using a dynamic PCD, store the device tree address in a HOB so that we can also run under a configuration that does not support dynamic PCDs.

Contributed-under: TianoCore Contribution Agreement 1.0

---
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec
| 2 --
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
| 3 ---

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLi b/ArmVirtualizationPlatformLib.inf | 2 --

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL
ib.c | 11 ++++++++---

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL
ib.inf | 4 +---
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c
| 10 ++++++++--
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
| 3 ++-
EmbeddedPkg/EmbeddedPkg.dec
| 2 ++
EmbeddedPkg/Include/Guid/FdtHob.h
| 26 ++++++++++++++++++++++++++

 9 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec index d83117fc6abe..868488906643 100644

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +0 -0
@@ -44,8 +44,6 @@
 

gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0|UI NT64|0x00000001

[PcdsDynamic, PcdsFixedAtBuild]
- gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0|UINT64|0x 00000002
-
#
# ARM PSCI function invocations can be done either through
hypervisor

   # calls (HVC) or secure monitor calls (SMC).
diff --git
a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
index dff4e2507058..4f8eb632143c 100644
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -0
@@ -160,9 +160,6 @@
   # System Memory Size -- 1 MB initially, actual size will be fetched

from DT
gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -3
-  # location of the device tree blob passed by QEMU
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0
-
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
   gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0
   gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf
index 43b3c6ca1bef..c57002f3e9da 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -2
@@ -33,8 +33,6 @@
   ArmLib
   PrintLib
   FdtLib
-  SerialPortLib
-  HobLib
 
 [Sources.common]
   Virt.c

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
index 58bc2b828dcd..c500d5964b25 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +8 -3
@@ -22,6 +22,7 @@
 #include <libfdt.h>
 
 #include <Guid/EarlyPL011BaseAddress.h>
+#include <Guid/FdtHob.h>
 
 EFI_STATUS
 EFIAPI
@@ -32,6 +33,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
   CONST CHAR8        *Compatible;
@@ -41,15 +43,18 @@ PlatformPeim (
   UINT64             UartBase;
 
 
-  Base = (VOID*)(UINTN)FixedPcdGet64
 (PcdDeviceTreeInitialBaseAddress);
+  Base = (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
   FdtSize = fdt_totalsize (Base);
   NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
   ASSERT (NewBase != NULL);
-
   CopyMem (NewBase, Base, FdtSize);
-  PcdSet64 (PcdDeviceTreeBaseAddress, (UINT64)(UINTN)NewBase);
+
+  FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
+  ASSERT (FdtHobData != NULL);
+  *FdtHobData = (UINTN)NewBase;
 
   UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof
*UartHobData);
   ASSERT (UartHobData != NULL);

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf
index a376fbd1f345..96019e4009ff 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +1 -3
@@ -41,11 +41,9 @@
   gArmTokenSpaceGuid.PcdFvSize
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
 
-[Pcd]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
-
 [Guids]
   gEarlyPL011BaseAddressGuid
+  gFdtHobGuid
 
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c b/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c index 31164905d34e..34fac40fa803 100644

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +8 -2
@@ -24,10 +24,12 @@
 #include <Library/DevicePathLib.h>
 #include <Library/PcdLib.h>
 #include <Library/DxeServicesLib.h>
+#include <Library/HobLib.h>
 #include <libfdt.h>
 
 #include <Guid/Fdt.h>
 #include <Guid/VirtioMmioTransport.h>
+#include <Guid/FdtHob.h>
 
 #pragma pack (1)
 typedef struct {
@@ -105,6 +107,7 @@ InitializeVirtFdtDxe (
   IN EFI_SYSTEM_TABLE     *SystemTable
   )
 {
+  VOID                           *Hob;
   VOID                           *DeviceTreeBase;
   INT32                          Node, Prev;
   INT32                          RtcNode;
@@ -125,8 +128,11 @@ InitializeVirtFdtDxe (
   UINT64                         FwCfgDataAddress;
   UINT64                         FwCfgDataSize;
 
-  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress);
-  ASSERT (DeviceTreeBase != NULL);
+  Hob = GetFirstGuidHob(&gFdtHobGuid);
+  if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64))
 {
+    return EFI_NOT_FOUND;
+  }
+  DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);
 
   if (fdt_check_header (DeviceTreeBase) != 0) {
     DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__,

DeviceTreeBase));
diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf b/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf index 514ce2fdf658..1392c7c3fa45 100644

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf +2 -1
@@ -40,13 +40,14 @@
   DxeServicesLib
   FdtLib
   VirtioMmioDeviceLib
+  HobLib
 
 [Guids]
   gFdtTableGuid
   gVirtioMmioTransportGuid
+  gFdtHobGuid
 
 [Pcd]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
   gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod
   gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress
   gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress
EmbeddedPkg/EmbeddedPkg.dec +2 -0
index 600d0e54c4b3..2f261ece9212 100644
@@ -52,6 +52,8 @@
   ## FDT Configuration Table
   # Include/Guid/Fdt.h
   gFdtTableGuid = { 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9,
 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
+  # Include/Guid/FdtHob.h
+  gFdtHobGuid   = { 0x16958446, 0x19B7, 0x480B, { 0xB0, 0x47, 0x74,
 0x85, 0xAD, 0x3F, 0x71, 0x6D } }
 

[Protocols.common]
gHardwareInterruptProtocolGuid = { 0x2890B3EA, 0x053D, 0x1643, {
0xAD, 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } }

EmbeddedPkg/Include/Guid/FdtHob.h new file +2 -0
new file mode 100644
index 000000000000..287729e0c350
@@ -0,0 +1,26 @@
+/** @file
+  GUID for the HOB that contains the copy of the flattened device tree

blob

EmbeddedPkg/Include/Guid/FdtHob.h new file +4 -0
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made

available
+ under the terms and conditions of the BSD License that accompanies this

EmbeddedPkg/Include/Guid/FdtHob.h new file +4 -0
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"

BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

EmbeddedPkg/Include/Guid/FdtHob.h new file +14 -1
+
+**/
+
+#ifndef __FDT_HOB_H__
+#define __FDT_HOB_H__
+
+#define FDT_HOB_GUID { \
+          0x16958446, 0x19B7, 0x480B, \
+          { 0xB0, 0x47, 0x74, 0x85, 0xAD, 0x3F, 0x71, 0x6D } \
+        }
+
+extern EFI_GUID gFdtHobGuid;
+
+#endif
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#66 lore raw

Re: [PATCH v2 07/29] ArmVirtualizationPkg: use a HOB to store device tree blob

Quoted 12 lines · Olivier Martin

I do not have a strong opinion on this patch.
It would be better to keep the dynamic PCD support in this patch. But I am aware it is not possible with PrePi (I had the issue a couple of weeks ago). Dynamic Pcds are actually supported when you use the PeiCore with PcdPeim. But the PeiCore only make sense at the moment on platforms that have DRAM initialized by the UEFI firmware.
I would like to extend the PI spec to also be able to use PeiCore in the case where the DRAM is already initialized at the time of the UEFI firmware. That would mean we could use the PcdPeim and Dynamic Pcd. But it will take time before we have support for it.
And I do not want to gate the patch set for this reason.

OK.

Quoted 15 lines

I am ok to accept it if no one reject it.

Anyway, this patch breaks the ARM Toolchain build:

"armlink" --partial -o /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/ArmPlatformPrePeiCore.lib --via /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/object_files.lst
"armlink" --ro-base 0 --no_scanlib --reloc --no_exceptions --datacompressor off --strict --symbols --diag_style=ide --entry _ModuleEntryPoint --map --list /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.map -o

Quoted 9 lines

/tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll --via /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/static_library_files.lst armlink : error L6218: Undefined symbol AllocatePages (referred from ArmVirtualizationPlatformLib.lib).
armlink : Not enough information to list image symbols.
armlink : Finished: 1 information, 0 warning and 1 error messages.

Probably just a missing MemoryAllocationLib dependency in ArmVirtualizationPlatformLib.inf

Quoted 304 lines
Quoted 300 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 07/29] ArmVirtualizationPkg: use a HOB to store device tree blob

Instead of using a dynamic PCD, store the device tree address in a HOB so that we can also run under a configuration that does not support dynamic PCDs.

Contributed-under: TianoCore Contribution Agreement 1.0

---
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec
| 2 --
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
| 3 ---

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLi b/ArmVirtualizationPlatformLib.inf | 2 --

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL
ib.c | 11 ++++++++---

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL
ib.inf | 4 +---
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c
| 10 ++++++++--
ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
| 3 ++-
EmbeddedPkg/EmbeddedPkg.dec
| 2 ++
EmbeddedPkg/Include/Guid/FdtHob.h
| 26 ++++++++++++++++++++++++++

 9 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec index d83117fc6abe..868488906643 100644

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +0 -0
@@ -44,8 +44,6 @@
 

gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0|UI NT64|0x00000001

[PcdsDynamic, PcdsFixedAtBuild]
- gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0|UINT64|0x 00000002
-
#
# ARM PSCI function invocations can be done either through
hypervisor

   # calls (HVC) or secure monitor calls (SMC).
diff --git
a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
index dff4e2507058..4f8eb632143c 100644
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -0
@@ -160,9 +160,6 @@
   # System Memory Size -- 1 MB initially, actual size will be fetched

from DT
gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -3
-  # location of the device tree blob passed by QEMU
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0
-
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
   gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0
   gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf
index 43b3c6ca1bef..c57002f3e9da 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatform Lib/ArmVirtualizationPlatformLib.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +0 -2
@@ -33,8 +33,6 @@
   ArmLib
   PrintLib
   FdtLib
-  SerialPortLib
-  HobLib
 
 [Sources.common]
   Virt.c

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
index 58bc2b828dcd..c500d5964b25 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +8 -3
@@ -22,6 +22,7 @@
 #include <libfdt.h>
 
 #include <Guid/EarlyPL011BaseAddress.h>
+#include <Guid/FdtHob.h>
 
 EFI_STATUS
 EFIAPI
@@ -32,6 +33,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
   CONST CHAR8        *Compatible;
@@ -41,15 +43,18 @@ PlatformPeim (
   UINT64             UartBase;
 
 
-  Base = (VOID*)(UINTN)FixedPcdGet64
 (PcdDeviceTreeInitialBaseAddress);
+  Base = (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
   FdtSize = fdt_totalsize (Base);
   NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
   ASSERT (NewBase != NULL);
-
   CopyMem (NewBase, Base, FdtSize);
-  PcdSet64 (PcdDeviceTreeBaseAddress, (UINT64)(UINTN)NewBase);
+
+  FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
+  ASSERT (FdtHobData != NULL);
+  *FdtHobData = (UINTN)NewBase;
 
   UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof
*UartHobData);
   ASSERT (UartHobData != NULL);

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf
index a376fbd1f345..96019e4009ff 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.inf

ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +1 -3
@@ -41,11 +41,9 @@
   gArmTokenSpaceGuid.PcdFvSize
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
 
-[Pcd]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
-
 [Guids]
   gEarlyPL011BaseAddressGuid
+  gFdtHobGuid
 
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c b/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c index 31164905d34e..34fac40fa803 100644

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c +8 -2
@@ -24,10 +24,12 @@
 #include <Library/DevicePathLib.h>
 #include <Library/PcdLib.h>
 #include <Library/DxeServicesLib.h>
+#include <Library/HobLib.h>
 #include <libfdt.h>
 
 #include <Guid/Fdt.h>
 #include <Guid/VirtioMmioTransport.h>
+#include <Guid/FdtHob.h>
 
 #pragma pack (1)
 typedef struct {
@@ -105,6 +107,7 @@ InitializeVirtFdtDxe (
   IN EFI_SYSTEM_TABLE     *SystemTable
   )
 {
+  VOID                           *Hob;
   VOID                           *DeviceTreeBase;
   INT32                          Node, Prev;
   INT32                          RtcNode;
@@ -125,8 +128,11 @@ InitializeVirtFdtDxe (
   UINT64                         FwCfgDataAddress;
   UINT64                         FwCfgDataSize;
 
-  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress);
-  ASSERT (DeviceTreeBase != NULL);
+  Hob = GetFirstGuidHob(&gFdtHobGuid);
+  if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64))
 {
+    return EFI_NOT_FOUND;
+  }
+  DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);
 
   if (fdt_check_header (DeviceTreeBase) != 0) {
     DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__,

DeviceTreeBase));
diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf b/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf index 514ce2fdf658..1392c7c3fa45 100644

ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf +2 -1
@@ -40,13 +40,14 @@
   DxeServicesLib
   FdtLib
   VirtioMmioDeviceLib
+  HobLib
 
 [Guids]
   gFdtTableGuid
   gVirtioMmioTransportGuid
+  gFdtHobGuid
 
 [Pcd]
-  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
   gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod
   gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress
   gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress
EmbeddedPkg/EmbeddedPkg.dec +2 -0
index 600d0e54c4b3..2f261ece9212 100644
@@ -52,6 +52,8 @@
   ## FDT Configuration Table
   # Include/Guid/Fdt.h
   gFdtTableGuid = { 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9,
 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
+  # Include/Guid/FdtHob.h
+  gFdtHobGuid   = { 0x16958446, 0x19B7, 0x480B, { 0xB0, 0x47, 0x74,
 0x85, 0xAD, 0x3F, 0x71, 0x6D } }
 

[Protocols.common]
gHardwareInterruptProtocolGuid = { 0x2890B3EA, 0x053D, 0x1643, {
0xAD, 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } }

EmbeddedPkg/Include/Guid/FdtHob.h new file +2 -0
new file mode 100644
index 000000000000..287729e0c350
@@ -0,0 +1,26 @@
+/** @file
+  GUID for the HOB that contains the copy of the flattened device tree

blob

EmbeddedPkg/Include/Guid/FdtHob.h new file +4 -0
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made

available
+ under the terms and conditions of the BSD License that accompanies this

EmbeddedPkg/Include/Guid/FdtHob.h new file +4 -0
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"

BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

EmbeddedPkg/Include/Guid/FdtHob.h new file +14 -1
+
+**/
+
+#ifndef __FDT_HOB_H__
+#define __FDT_HOB_H__
+
+#define FDT_HOB_GUID { \
+          0x16958446, 0x19B7, 0x480B, \
+          { 0xB0, 0x47, 0x74, 0x85, 0xAD, 0x3F, 0x71, 0x6D } \
+        }
+
+extern EFI_GUID gFdtHobGuid;
+
+#endif
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): CAKv+Gu-Tttj044s044M9vro5ZAQs1Kv6d+EK56HyDS4Yi7BrpQ@mail.gmail.com

Reviewed-by
#68 lore raw

Re: [PATCH v2 07/29] ArmVirtualizationPkg: use a HOB to store device tree blob

Quoted 41 lines · Ard Biesheuvel
Quoted 12 lines · Olivier Martin

I do not have a strong opinion on this patch.
It would be better to keep the dynamic PCD support in this patch. But I am aware it is not possible with PrePi (I had the issue a couple of weeks ago). Dynamic Pcds are actually supported when you use the PeiCore with PcdPeim. But the PeiCore only make sense at the moment on platforms that have DRAM initialized by the UEFI firmware.
I would like to extend the PI spec to also be able to use PeiCore in the case where the DRAM is already initialized at the time of the UEFI firmware. That would mean we could use the PcdPeim and Dynamic Pcd. But it will take time before we have support for it.
And I do not want to gate the patch set for this reason.

OK.

Quoted 15 lines

I am ok to accept it if no one reject it.

Anyway, this patch breaks the ARM Toolchain build:

"armlink" --partial -o /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/ArmPlatformPrePeiCore.lib --via /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/object_files.lst
"armlink" --ro-base 0 --no_scanlib --reloc --no_exceptions --datacompressor off --strict --symbols --diag_style=ide --entry _ModuleEntryPoint --map --list /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.map -o

Quoted 9 lines

/tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll --via /tianocore/Build/ArmVirtualizationQemu-ARM/DEBUG_RVCTLINUX/ARM/ArmPlatformPk g/PrePeiCore/PrePeiCoreUniCore/OUTPUT/static_library_files.lst armlink : error L6218: Undefined symbol AllocatePages (referred from ArmVirtualizationPlatformLib.lib).
armlink : Not enough information to list image symbols.
armlink : Finished: 1 information, 0 warning and 1 error messages.

Quoted 2 lines

Probably just a missing MemoryAllocationLib dependency in ArmVirtualizationPlatformLib.inf

If you fix that in the next version, you can add

Thanks!
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#70 lore raw

Re: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT allocation

Same question as last time, would it not be better to have a PCD instead of hardcoded value?
Some platforms might want to have a larger FDT padding.

Quoted 82 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT allocation

Our primary user QEMU/mach-virt presents us with a FDT blob padded to 64 KB with plenty of room to set additional properties. However, in the general case, we should only add properties after making sure there is enough room available.

Contributed-under: TianoCore Contribution Agreement 1.0

---

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL ib.c | 17 ++++++++++++++---

 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
index c500d5964b25..42a87309aebe 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c

(quoted diff) +2 -0
@@ -24,6 +24,15 @@
 #include <Guid/EarlyPL011BaseAddress.h>
 #include <Guid/FdtHob.h>
 
+//
+// We may want to apply some changes to the device tree before passing

it

(quoted diff) +2 -0
+// to the OS: for instance, if we find a PL031 RTC node and attach our
+// runtime driver to it, we should disable it in the device tree by

setting
+// its status property to "disabled". Add some padding to make sure this is

(quoted diff) +9 -4
+// possible.
+//
+#define FDT_PADDING   256
+
 EFI_STATUS
 EFIAPI
 PlatformPeim (
@@ -33,6 +42,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINTN              FdtPages;
   UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
@@ -47,10 +57,11 @@ PlatformPeim (
   ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
-  FdtSize = fdt_totalsize (Base);
-  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
+  FdtSize = fdt_totalsize (Base) + FDT_PADDING;
+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
+  NewBase = AllocatePages (FdtPages);
   ASSERT (NewBase != NULL);
-  CopyMem (NewBase, Base, FdtSize);
+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
 
   FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
   ASSERT (FdtHobData != NULL);
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#72 lore raw

Re: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT allocation

Quoted 2 lines · Olivier Martin

Same question as last time, would it not be better to have a PCD instead of hardcoded value?

Ah yes, I remember reading that but failed to take it into account.

Quoted 2 lines

Some platforms might want to have a larger FDT padding.

Agreed. Will add it to v3

Quoted 87 lines
Quoted 83 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT allocation

Our primary user QEMU/mach-virt presents us with a FDT blob padded to 64 KB with plenty of room to set additional properties. However, in the general case, we should only add properties after making sure there is enough room available.

Contributed-under: TianoCore Contribution Agreement 1.0

---

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL ib.c | 17 ++++++++++++++---

 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
index c500d5964b25..42a87309aebe 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c

(quoted diff) +2 -0
@@ -24,6 +24,15 @@
 #include <Guid/EarlyPL011BaseAddress.h>
 #include <Guid/FdtHob.h>
 
+//
+// We may want to apply some changes to the device tree before passing

it

(quoted diff) +2 -0
+// to the OS: for instance, if we find a PL031 RTC node and attach our
+// runtime driver to it, we should disable it in the device tree by

setting
+// its status property to "disabled". Add some padding to make sure this is

(quoted diff) +9 -4
+// possible.
+//
+#define FDT_PADDING   256
+
 EFI_STATUS
 EFIAPI
 PlatformPeim (
@@ -33,6 +42,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINTN              FdtPages;
   UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
@@ -47,10 +57,11 @@ PlatformPeim (
   ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
-  FdtSize = fdt_totalsize (Base);
-  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
+  FdtSize = fdt_totalsize (Base) + FDT_PADDING;
+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
+  NewBase = AllocatePages (FdtPages);
   ASSERT (NewBase != NULL);
-  CopyMem (NewBase, Base, FdtSize);
+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
 
   FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
   ASSERT (FdtHobData != NULL);
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): CAKv+Gu8rxq-=Z_aNwYBnG46CWjSCM7Ce8d3fOZWe0CAqJJN5fA@mail.gmail.com

Reviewed-by
#74 lore raw

Re: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT allocation

Quoted 10 lines · Ard Biesheuvel
Quoted 2 lines · Olivier Martin

Same question as last time, would it not be better to have a PCD instead of hardcoded value?

Ah yes, I remember reading that but failed to take it into account.

Quoted 2 lines

Some platforms might want to have a larger FDT padding.

Agreed. Will add it to v3

I think using a FixedPcd will be okay.

With that change, you can add

Thanks
Laszlo

Quoted 89 lines
Quoted 89 lines
Quoted 85 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT allocation

Our primary user QEMU/mach-virt presents us with a FDT blob padded to 64 KB with plenty of room to set additional properties. However, in the general case, we should only add properties after making sure there is enough room available.

Contributed-under: TianoCore Contribution Agreement 1.0

---

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL ib.c | 17 ++++++++++++++---

 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
index c500d5964b25..42a87309aebe 100644
---
a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c
+++
b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe iLib.c

(quoted diff) +2 -0
@@ -24,6 +24,15 @@
 #include <Guid/EarlyPL011BaseAddress.h>
 #include <Guid/FdtHob.h>
 
+//
+// We may want to apply some changes to the device tree before passing

it

(quoted diff) +2 -0
+// to the OS: for instance, if we find a PL031 RTC node and attach our
+// runtime driver to it, we should disable it in the device tree by

setting
+// its status property to "disabled". Add some padding to make sure this is

(quoted diff) +9 -4
+// possible.
+//
+#define FDT_PADDING   256
+
 EFI_STATUS
 EFIAPI
 PlatformPeim (
@@ -33,6 +42,7 @@ PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINTN              FdtPages;
   UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
@@ -47,10 +57,11 @@ PlatformPeim (
   ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
-  FdtSize = fdt_totalsize (Base);
-  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
+  FdtSize = fdt_totalsize (Base) + FDT_PADDING;
+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
+  NewBase = AllocatePages (FdtPages);
   ASSERT (NewBase != NULL);
-  CopyMem (NewBase, Base, FdtSize);
+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
 
   FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
   ASSERT (FdtHobData != NULL);
--

1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#76 lore raw

Re: [PATCH v2 09/29] ArmPlatformPkg/PrePi: allow use of patchable PCDs

Quoted 92 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 09/29] ArmPlatformPkg/PrePi: allow use of patchable PCDs

Avoid using FixedPcdGetXX () to reference system memory and FD base address PCDs so that the platform can choose to use patchable PCDs instead. This allows a runtime self-relocating PrePi to poke alternate values into them that can only be discovered at runtime.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S | 8 ++++----
 ArmPlatformPkg/PrePi/PrePi.c                    | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S +5 -4
index fcea9496cbd5..3fa6bf1f0322 100644
@@ -42,14 +42,14 @@ _SetSVCMode:
 // at the top of the DRAM)
 _SetupStackPosition:
   // Compute Top of System Memory
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1)
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2)
+  ldr   x1, PcdGet64 (PcdSystemMemoryBase)
+  ldr   x2, PcdGet64 (PcdSystemMemorySize)
   sub   x2, x2, #1
   add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase
+ PcdSystemMemorySize
 
   // Calculate Top of the Firmware Device
-  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)
-  LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)
+  ldr   x2, PcdGet64 (PcdFdBaseAddress)
+  ldr   w3, PcdGet32 (PcdFdSize)
   sub   x3, x3, #1
   add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
ArmPlatformPkg/PrePi/PrePi.c +0 -1
index 9a5e067ef537..0e551c518d6b 100755
@@ -30,8 +30,8 @@
 #include "PrePi.h"
 #include "LzmaDecompress.h"
 
-#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) >

(UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \
- ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32
(PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase))) +#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \
+ ((PcdGet64 (PcdFdBaseAddress) + PcdGet32
(PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))

// Not used when PrePi in run in XIP mode
UINTN mGlobalVariableBase = 0;

ArmPlatformPkg/PrePi/PrePi.c +0 -1
@@ -108,8 +108,8 @@ PrePiMain (
 
   // If ensure the FD is either part of the System Memory or totally
 outside of the System Memory (XIP)
   ASSERT (IS_XIP() ||
-          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64

(PcdSystemMemoryBase)) &&
- ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32
(PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize)))));
+ ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64
(PcdSystemMemoryBase)) &&
+ ((UINT32)(PcdGet64 (PcdFdBaseAddress) + PcdGet32
(PcdFdSize)) <= (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))));

   // Initialize the architecture specific bits
   ArchInitialize ();

--
1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#78 lore raw

Re: [PATCH v2 09/29] ArmPlatformPkg/PrePi: allow use of patchable PCDs

Quoted 2 lines · Olivier Martin

Looking at these patches again, it might make sense to replace #9, #10 and #11 with a single patch that introduces RelocatablePrePi under ArmVirtualizationPkg with these changes already applied. That way, we adhere to the single .inf per directory rule and not affect any existing platforms with changes that are irrelevant to them.

Quoted 96 lines
Quoted 92 lines

-----Original Message-----
From: Ard Biesheuvel [mailto:[email protected]]
Sent: 26 January 2015 19:03
To: [email protected]; [email protected]; Olivier Martin; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; xen- [email protected]; [email protected]
Cc: Ard Biesheuvel
Subject: [PATCH v2 09/29] ArmPlatformPkg/PrePi: allow use of patchable PCDs

Avoid using FixedPcdGetXX () to reference system memory and FD base address PCDs so that the platform can choose to use patchable PCDs instead. This allows a runtime self-relocating PrePi to poke alternate values into them that can only be discovered at runtime.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S | 8 ++++----
 ArmPlatformPkg/PrePi/PrePi.c                    | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S +5 -4
index fcea9496cbd5..3fa6bf1f0322 100644
@@ -42,14 +42,14 @@ _SetSVCMode:
 // at the top of the DRAM)
 _SetupStackPosition:
   // Compute Top of System Memory
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1)
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2)
+  ldr   x1, PcdGet64 (PcdSystemMemoryBase)
+  ldr   x2, PcdGet64 (PcdSystemMemorySize)
   sub   x2, x2, #1
   add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase
+ PcdSystemMemorySize
 
   // Calculate Top of the Firmware Device
-  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)
-  LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)
+  ldr   x2, PcdGet64 (PcdFdBaseAddress)
+  ldr   w3, PcdGet32 (PcdFdSize)
   sub   x3, x3, #1
   add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
ArmPlatformPkg/PrePi/PrePi.c +0 -1
index 9a5e067ef537..0e551c518d6b 100755
@@ -30,8 +30,8 @@
 #include "PrePi.h"
 #include "LzmaDecompress.h"
 
-#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) >

(UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \
- ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32
(PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase))) +#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \
+ ((PcdGet64 (PcdFdBaseAddress) + PcdGet32
(PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))

// Not used when PrePi in run in XIP mode
UINTN mGlobalVariableBase = 0;

ArmPlatformPkg/PrePi/PrePi.c +0 -1
@@ -108,8 +108,8 @@ PrePiMain (
 
   // If ensure the FD is either part of the System Memory or totally
 outside of the System Memory (XIP)
   ASSERT (IS_XIP() ||
-          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64

(PcdSystemMemoryBase)) &&
- ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32
(PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize)))));
+ ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64
(PcdSystemMemoryBase)) &&
+ ((UINT32)(PcdGet64 (PcdFdBaseAddress) + PcdGet32
(PcdFdSize)) <= (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))));

   // Initialize the architecture specific bits
   ArchInitialize ();

--
1.8.3.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

Acked-by
#80 lore raw

Re: [PATCH v2 12/29] ArmVirtualizationPkg: implement custom MemoryInitPeiLib

Quoted 177 lines · Ard Biesheuvel

This implements a MemoryInitPeiLib instance that differs from the stock ArmPlatformPkg version only in the fact that it does not remove the memory used by the flash device (FD). The reason is that, when using PrePi, the DXE core is started immediately and never returns so there is no reason to preserve any of the memory that the flash device occupied originally, and it is preferable to release is so that the OS loader can reuse it. This is especially important for the relocatable PrePi configuration, which is aimed at being launched from a boot loader that itself adheres to the Linux arm64 boot protocol.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 .../Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c              | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 .../Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf            | 66 +++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c new file +91 -0
new file mode 100644
index 000000000000..5f6cd059c47f
@@ -0,0 +1,91 @@
+/** @file
+*
+*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
+*  Copyright (c) 2014, Linaro Limited. All rights reserved.
+*
+*  This program and the accompanying materials
+*  are licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#include <PiPei.h>
+
+#include <Library/ArmPlatformLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+VOID
+BuildMemoryTypeInformationHob (
+  VOID
+  );
+
+VOID
+InitMmu (
+  VOID
+  )
+{
+  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable;
+  VOID                          *TranslationTableBase;
+  UINTN                         TranslationTableSize;
+  RETURN_STATUS                 Status;
+
+  // Get Virtual Memory Map from the Platform Library
+  ArmPlatformGetVirtualMemoryMap (&MemoryTable);
+
+  //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
+  //      DRAM (even at the top of DRAM as it is the first permanent memory allocation)
+  Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));
+  }
+}
+
+EFI_STATUS
+EFIAPI
+MemoryPeim (
+  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,
+  IN UINT64                             UefiMemorySize
+  )
+{
+  EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
+
+  // Ensure PcdSystemMemorySize has been set
+  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
+
+  //
+  // Now, the permanent memory has been installed, we can call AllocatePages()
+  //
+  ResourceAttributes = (
+      EFI_RESOURCE_ATTRIBUTE_PRESENT |
+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
+      EFI_RESOURCE_ATTRIBUTE_TESTED
+  );
+
+  BuildResourceDescriptorHob (
+      EFI_RESOURCE_SYSTEM_MEMORY,
+      ResourceAttributes,
+      PcdGet64 (PcdSystemMemoryBase),
+      PcdGet64 (PcdSystemMemorySize)
+  );
+
+  // Build Memory Allocation Hob
+  InitMmu ();
+
+  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
+    // Optional feature that helps prevent EFI memory map fragmentation.
+    BuildMemoryTypeInformationHob ();
+  }
+
+  return EFI_SUCCESS;
+}
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf new file +56 -0
new file mode 100644
index 000000000000..fcdae06de7c2
@@ -0,0 +1,66 @@
+#/** @file
+#
+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>
+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = ArmVirtMemoryInitPeiLib
+  FILE_GUID                      = 021b6156-3cc8-4e99-85ee-13d8a871edf2
+  MODULE_TYPE                    = SEC
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = MemoryInitPeiLib
+
+[Sources]
+  ArmVirtualizationMemoryInitPeiLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  ArmPkg/ArmPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+
+[LibraryClasses]
+  DebugLib
+  HobLib
+  ArmLib
+  ArmPlatformLib
+
+[Guids]
+  gEfiMemoryTypeInformationGuid
+
+[FeaturePcd]
+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob
+
+[FixedPcd]
+  gArmTokenSpaceGuid.PcdFdSize
+
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
+
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData

ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf line 66

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf new file +10 -0
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData
+
+[Pcd]
+  gArmTokenSpaceGuid.PcdSystemMemoryBase
+  gArmTokenSpaceGuid.PcdSystemMemorySize
+  gArmTokenSpaceGuid.PcdFdBaseAddress
+
+[Depex]
+  TRUE

As per the discussion of the previous version of this patch, and because I can see that "ArmVirtualizationMemoryInitPeiLib.inf" is only referenced in patch v2 29/29, where it is added to "ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc":

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#82 lore raw

Re: [PATCH v2 13/29] ArmVirtualizationPkg: allow patchable PCD for FV base address

Quoted 18 lines · Ard Biesheuvel

Allow the use of a patchable PCD for gArmTokenSpaceGuid.PcdFvBaseAddress by moving it from the [FixedPcd] to the [Pcd] section in the INF file of PlatformPeiLib.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +0 -0
index 96019e4009ff..1fca9b28f9e2 100644
@@ -37,9 +37,11 @@
   FdtLib
 

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf line 47

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +3 -1
 [FixedPcd]
-  gArmTokenSpaceGuid.PcdFvBaseAddress
   gArmTokenSpaceGuid.PcdFvSize
+
+[Pcd]
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
+  gArmTokenSpaceGuid.PcdFvBaseAddress
 
 [Guids]
   gEarlyPL011BaseAddressGuid

It also seems to change the PCD type of PcdDeviceTreeInitialBaseAddress. Care to mention that too in the commit message, just for completeness?

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

Acked-by
#84 lore raw

Re: [PATCH v2 14/29] ArmVirtualizationPkg: Xen/PV relocatable platformlib instance

Quoted 11 lines · Ard Biesheuvel

Add a ArmPlatformLib instance that can deal with the self relocation and truly dynamic discovery of system RAM base and size.

---
 .../ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/MemnodeParser.S          | 232 +++++++++++++++++++++++++++++++++++++++++++++++
 .../ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S  | 161 ++++++++++++++++++++++++++++++++
 .../ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf |  59 ++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c     |  71 +++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c          |  83 +++++++++++++++++
 5 files changed, 606 insertions(+)

Five new files; it appears impossible that this patch regress QEMU VMs. Hence

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#86 lore raw

Re: [PATCH v2 16/29] Ovmf/Xen: fix pointer to int cast in XenBusDxe

Quoted 28 lines · Ard Biesheuvel

On ARM, xen_pfn_t is 64 bits but the size of a pointer is only 32 bits, so casting between them needs to go via (UINTN). Also move the xen_pfn_t cast outside the shift so that we can avoid shifting 64-bit quantities on 32-bit architectures, which may require runtime library support.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenBusDxe/GrantTable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
OvmfPkg/XenBusDxe/GrantTable.c +1 -1
index 37d3bf786c64..8405edc51bc4 100644
@@ -160,7 +160,7 @@ XenGrantTableInit (
     Parameters.domid = DOMID_SELF;
     Parameters.idx = Index;
     Parameters.space = XENMAPSPACE_grant_table;
-    Parameters.gpfn = (((xen_pfn_t) GrantTable) >> EFI_PAGE_SHIFT) + Index;
+    Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters);
     if (ReturnCode != 0) {
       DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode));

OvmfPkg/XenBusDxe/GrantTable.c XenGrantTableDeinit ( · line 188

Quoted 8 lines
OvmfPkg/XenBusDxe/GrantTable.c +1 -1
@@ -182,7 +182,7 @@ XenGrantTableDeinit (
 
   for (Index = NR_GRANT_FRAMES - 1; Index >= 0; Index--) {
     Parameters.domid = DOMID_SELF;
-    Parameters.gpfn = (((xen_pfn_t) GrantTable) >> EFI_PAGE_SHIFT) + Index;
+    Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable >> EFI_PAGE_SHIFT) + Index;
     DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn));
     ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters);
     if (ReturnCode != 0) {

One edk2 coding style guideline that I consistently reject & never apply is the first space in

(type) expr1 <op> expr2

We had an obscure bug due to this guideline earlier, which I luckily managed to catch through review, before it could do damage.

The problem with the first space is that it actively obscures the fact that the cast operator has one of the strongest operator bindings. Most of the time, the above means

((type)expr1) <op> expr2

and not

(type)(expr1 <op> expr2)

as the space would incorrectly suggest.

Your patch is fine, but I had to think thrice. :)

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#88 lore raw

Re: [PATCH v2 18/29] Ovmf/Xen: move XenBusDxe hypercall code to separate library

one important comment

Quoted 33 lines · Ard Biesheuvel

This moves all of the Xen hypercall code that was private to XenBusDxe to a new library class XenHypercallLib. This will allow us to reimplement it for ARM, and to export the Xen hypercall functionality to other parts of the code, such as a Xen console SerialPortLib driver.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/{XenBusDxe/XenHypercall.h => Include/Library/XenHypercallLib.h} | 16 ++-------------
 OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/Ia32/hypercall.nasm      |  0
 OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/X64/hypercall.nasm       |  0
 OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/XenHypercall.c           | 37 ++--------------------------------
 OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c                     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf                | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                                                     |  4 ++++
 OvmfPkg/OvmfPkgIa32.dsc                                                 |  1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                                              |  1 +
 OvmfPkg/OvmfPkgX64.dsc                                                  |  1 +
 OvmfPkg/XenBusDxe/EventChannel.c                                        |  3 ++-
 OvmfPkg/XenBusDxe/GrantTable.c                                          |  2 +-
 OvmfPkg/XenBusDxe/XenBusDxe.c                                           |  9 +--------
 OvmfPkg/XenBusDxe/XenBusDxe.inf                                         | 11 +----------
 OvmfPkg/XenBusDxe/XenStore.c                                            |  2 +-
 15 files changed, 146 insertions(+), 70 deletions(-)
OvmfPkg/Include/Library/XenHypercallLib.h renamed from OvmfPkg/XenBusDxe/XenHypercall.h +0 -0
similarity index 82%
rename from OvmfPkg/XenBusDxe/XenHypercall.h
rename to OvmfPkg/Include/Library/XenHypercallLib.h
index 9d49e33eb5af..dc2c5424683c 100644

OvmfPkg/Include/Library/XenHypercallLib.h line 17

Quoted 7 lines
OvmfPkg/Include/Library/XenHypercallLib.h renamed from OvmfPkg/XenBusDxe/XenHypercall.h +2 -2
@@ -13,8 +13,8 @@
 
 **/
 
-#ifndef __XENBUS_DXE_HYPERCALL_H__
-#define __XENBUS_DXE_HYPERCALL_H__
+#ifndef __XEN_HYPERCALL_LIB_H_
+#define __XEN_HYPERCALL_LIB_H_

I guess if you lead it with "__", then you should also trail it with "__". :)

Other than that, it looks good to me.

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#90 lore raw

Re: [PATCH v2 19/29] Ovmf/Xen: introduce XENIO_PROTOCOL

Quoted 73 lines · Ard Biesheuvel

This introduces the abstract XENIO_PROTOCOL that will be used to communicate the Xen grant table address to drivers supporting this protocol. Primary purpose is allowing us to change the XenBusDxe implementation so that it can support non-PCI Xen implementations such as Xen on ARM.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/Protocol/XenIo.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec              |  1 +
 2 files changed, 49 insertions(+)
OvmfPkg/Include/Protocol/XenIo.h new file +48 -0
new file mode 100644
index 000000000000..510391f3b3e8
@@ -0,0 +1,48 @@
+/** @file
+  XenIo protocol to abstract arch specific details
+
+  The Xen implementations for the Intel and ARM archictures differ in the way
+  the base address of the grant table is communicated to the guest. The former
+  uses a virtual PCI device, while the latter uses a device tree node.
+  In order to allow the XenBusDxe UEFI driver to be reused for the non-PCI
+  Xen implementation, this abstract protocol can be installed on a handle
+  with the appropriate base address.
+
+  Copyright (C) 2014, Linaro Ltd.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __PROTOCOL_XENIO_H__
+#define __PROTOCOL_XENIO_H__
+
+#include <IndustryStandard/Xen/xen.h>
+
+#define XENIO_PROTOCOL_GUID \
+  {0x6efac84f, 0x0ab0, 0x4747, {0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}}
+
+///
+/// Forward declaration
+///
+typedef struct _XENIO_PROTOCOL XENIO_PROTOCOL;
+
+///
+/// Protocol structure
+///
+struct _XENIO_PROTOCOL {
+  //
+  // Protocol data fields
+  //
+  EFI_PHYSICAL_ADDRESS          GrantTableAddress;
+};
+
+extern EFI_GUID gXenIoProtocolGuid;
+
+#endif
OvmfPkg/OvmfPkg.dec +0 -0
index 30a9fb1e9b42..3711fa922311 100644

OvmfPkg/OvmfPkg.dec line 64

Quoted 7 lines
OvmfPkg/OvmfPkg.dec +1 -0
@@ -58,6 +58,7 @@
   gVirtioDeviceProtocolGuid       = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
   gBlockMmioProtocolGuid          = {0x6b558ce3, 0x69e5, 0x4c67, {0xa6, 0x34, 0xf7, 0xfe, 0x72, 0xad, 0xbe, 0x84}}
   gXenBusProtocolGuid             = {0x3d3ca290, 0xb9a5, 0x11e3, {0xb7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}}
+  gXenIoProtocolGuid              = {0x6efac84f, 0x0ab0, 0x4747, {0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}}
 
 [PcdsFixedAtBuild]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase|0x0|UINT32|0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#92 lore raw

Re: [PATCH v2 20/29] Ovmf/Xen: add separate driver for Xen PCI device

This code brings back memories :) It even has my earliest edk2 comments whose vocabulary (in retrospect) is not entirely correct. :) But, they're not the reason I'll ask for a respin here:

Quoted 180 lines · Ard Biesheuvel

Prepare for making XenBusDxe suitable for use with non-PCI devices (such as the DT node exposed by Xen on ARM) by introducing a separate DXE driver that binds to the Xen virtual PCI device and exposes the abstract XENIO_PROTOCOL for XenBusDxe to bind against.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/XenIoPciDxe/XenIoPciDxe.c   | 365 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf |  45 +++++++++++++
 2 files changed, 410 insertions(+)
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +162 -0
new file mode 100644
index 000000000000..8c91590f7eb5
@@ -0,0 +1,365 @@
+/** @file
+
+  Driver for the virtual Xen PCI device
+
+  Copyright (C) 2012, Red Hat, Inc.
+  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (C) 2013, ARM Ltd.
+  Copyright (C) 2015, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <IndustryStandard/Pci.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/PciIo.h>
+#include <Protocol/XenIo.h>
+
+#define PCI_VENDOR_ID_XEN                0x5853
+#define PCI_DEVICE_ID_XEN_PLATFORM       0x0001
+
+/**
+
+  Device probe function for this driver.
+
+  The DXE core calls this function for any given device in order to see if the
+  driver can drive the device.
+
+  @param[in]  This                The EFI_DRIVER_BINDING_PROTOCOL object
+                                  incorporating this driver (independently of
+                                  any device).
+
+  @param[in] DeviceHandle         The device to probe.
+
+  @param[in] RemainingDevicePath  Relevant only for bus drivers, ignored.
+
+
+  @retval EFI_SUCCESS      The driver supports the device being probed.
+
+  @retval EFI_UNSUPPORTED  The driver does not support the device being probed.
+
+  @return                  Error codes from the OpenProtocol() boot service or
+                           the PciIo protocol.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingSupported (
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,
+  IN EFI_HANDLE                  DeviceHandle,
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath
+  )
+{
+  EFI_STATUS          Status;
+  EFI_PCI_IO_PROTOCOL *PciIo;
+  PCI_TYPE00          Pci;
+
+  //
+  // Attempt to open the device with the PciIo set of interfaces. On success,
+  // the protocol is "instantiated" for the PCI device. Covers duplicate open
+  // attempts (EFI_ALREADY_STARTED).
+  //
+  Status = gBS->OpenProtocol (
+                  DeviceHandle,               // candidate device
+                  &gEfiPciIoProtocolGuid,     // for generic PCI access
+                  (VOID **)&PciIo,            // handle to instantiate
+                  This->DriverBindingHandle,  // requestor driver identity
+                  DeviceHandle,               // ControllerHandle, according to
+                                              // the UEFI Driver Model
+                  EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive PciIo access to
+                                              // the device; to be released
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  //
+  // Read entire PCI configuration header for more extensive check ahead.
+  //
+  Status = PciIo->Pci.Read (
+                        PciIo,                        // (protocol, device)
+                                                      // handle
+                        EfiPciIoWidthUint32,          // access width & copy
+                                                      // mode
+                        0,                            // Offset
+                        sizeof Pci / sizeof (UINT32), // Count
+                        &Pci                          // target buffer
+                        );
+
+  if (Status == EFI_SUCCESS) {
+    if ((Pci.Hdr.VendorId == PCI_VENDOR_ID_XEN) &&
+        (Pci.Hdr.DeviceId == PCI_DEVICE_ID_XEN_PLATFORM)) {
+      Status = EFI_SUCCESS;
+    } else {
+      Status = EFI_UNSUPPORTED;
+    }
+  }
+
+  //
+  // We needed PCI IO access only transitorily, to see whether we support the
+  // device or not.
+  //
+  gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle, DeviceHandle);
+
+  return Status;
+}
+
+/**
+
+  After we've pronounced support for a specific device in
+  DriverBindingSupported(), we start managing said device (passed in by the
+  Driver Exeuction Environment) with the following service.
+
+  See DriverBindingSupported() for specification references.
+
+  @param[in]  This                The EFI_DRIVER_BINDING_PROTOCOL object
+                                  incorporating this driver (independently of
+                                  any device).
+
+  @param[in] DeviceHandle         The supported device to drive.
+
+  @param[in] RemainingDevicePath  Relevant only for bus drivers, ignored.
+
+
+  @retval EFI_SUCCESS           The device was started.
+
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
+
+  @return                       Error codes from the OpenProtocol() boot
+                                service, the PciIo protocol or the
+                                InstallProtocolInterface() boot service.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingStart (
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,
+  IN EFI_HANDLE                  DeviceHandle,
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath
+  )
+{
+  EFI_STATUS                        Status;
+  XENIO_PROTOCOL                    *XenIo;
+  EFI_PCI_IO_PROTOCOL               *PciIo;
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc;
+
+  Status = gBS->OpenProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,

OvmfPkg/XenIoPciDxe/XenIoPciDxe.c line 172

Quoted 10 lines
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +10 -0
+                  (VOID **)&PciIo, This->DriverBindingHandle,
+                  DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  XenIo = (XENIO_PROTOCOL *) AllocateZeroPool (sizeof *XenIo);
+  if (XenIo == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }

Bug #1. :)

It seems that you reordered the AllocateZeroPool() call with the gBS->OpenProtocol() call, relative to VirtioBlkDriverBindingStart() or VirtioPciDeviceBindingStart(), whichever was your model. The reordering in itself is of course fine, but when you fail the second step (whichever is the second step), you must roll back the first. Release the allocated block, or close the protocol. Otherwise you'll leak memory, or a protocol reference.

So, just apply the usual cascading error labels.

OvmfPkg/XenIoPciDxe/XenIoPciDxe.c line 184

Quoted 12 lines
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +12 -0
+
+  //
+  // The BAR1 of this PCI device is used for shared memory and is supposed to
+  // look like MMIO. The address space of the BAR1 will be used to map the
+  // Grant Table.
+  //
+  Status = PciIo->GetBarAttributes (PciIo, PCI_BAR_IDX1, NULL, (VOID**) &BarDesc);
+  ASSERT_EFI_ERROR (Status);
+  ASSERT (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM);
+
+  /* Get a Memory address for mapping the Grant Table. */
+  DEBUG ((EFI_D_INFO, "XenBus: BAR at %LX\n", BarDesc->AddrRangeMin));

Hm, "XenIo" would be a more suitable message I guess.

OvmfPkg/XenIoPciDxe/XenIoPciDxe.c line 188

Quoted 4 lines
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +4 -0
+  XenIo->GrantTableAddress = BarDesc->AddrRangeMin;
+  FreePool (BarDesc);
+
+  Status = gBS->InstallProtocolInterface (DeviceHandle,

Bug #2.

You need to say &DeviceHandle, not DeviceHandle. The reason is that InstallProtocolInterface() is the API that creates new handles too (when you install the first protocol on an initially NULL handle).

You might ask why the compiler has not caught it. The answer is that, *sadly*, EFI_HANDLE is not a typedef of "pointer to opaque struct". That would catch such errors. But no, EFI_HANDLE is a typedef of "pointer to void". And a pointer-to-void can be cast to pointer-to-anything, including to pointer-to-pointer-to-void. (See C99 6.3.2.3 Pointers, p1.)

So, whether an API expects EFI_HANDLE, EFI_HANDLE*, EFI_HANDLE**, or EFI_HANDLE***************, if you mess up and pass in EFI_HANDLE, the compiler will not complain. You'll probably only see undefined behavior at runtime. If you're lucky, some signature check will catch it and ASSERT().

I think the EFI_HANDLE typedef is a huge mistake in the UEFI specification (see 2.3.1 Data Types). Worse, EFI_EVENT is VOID* too...

Anyway: please write &DeviceHandle.

OvmfPkg/XenIoPciDxe/XenIoPciDxe.c line 198

Quoted 10 lines
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +10 -0
+             &gXenIoProtocolGuid, EFI_NATIVE_INTERFACE, XenIo);
+
+  if (!EFI_ERROR (Status)) {
+    return EFI_SUCCESS;
+  }
+
+  gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle, DeviceHandle);
+
+  FreePool (XenIo);

This is where you'll have to insert a label (and possibly reorder these "release" actions so that their order mirror the "acquire" at the top of the function).

Quoted 209 lines
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c new file +167 -0
+  return Status;
+}
+
+/**
+
+  Stop driving the XenIo PCI device
+
+  @param[in] This               The EFI_DRIVER_BINDING_PROTOCOL object
+                                incorporating this driver (independently of any
+                                device).
+
+  @param[in] DeviceHandle       Stop driving this device.
+
+  @param[in] NumberOfChildren   Since this function belongs to a device driver
+                                only (as opposed to a bus driver), the caller
+                                environment sets NumberOfChildren to zero, and
+                                we ignore it.
+
+  @param[in] ChildHandleBuffer  Ignored (corresponding to NumberOfChildren).
+
+  @retval EFI_SUCCESS           Driver instance has been stopped and the PCI
+                                configuration attributes have been restored.
+
+  @return                       Error codes from the OpenProtocol() or
+                                CloseProtocol(), UninstallProtocolInterface()
+                                boot services.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingStop (
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,
+  IN EFI_HANDLE                  DeviceHandle,
+  IN UINTN                       NumberOfChildren,
+  IN EFI_HANDLE                  *ChildHandleBuffer
+  )
+{
+  EFI_STATUS               Status;
+  XENIO_PROTOCOL           *XenIo;
+
+  Status = gBS->OpenProtocol (
+                  DeviceHandle,                  // candidate device
+                  &gXenIoProtocolGuid,           // retrieve the XenIo iface
+                  (VOID **)&XenIo,               // target pointer
+                  This->DriverBindingHandle,     // requestor driver identity
+                  DeviceHandle,                  // requesting lookup for dev.
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  //
+  // Handle Stop() requests for in-use driver instances gracefully.
+  //
+  Status = gBS->UninstallProtocolInterface (DeviceHandle,
+                  &gXenIoProtocolGuid, XenIo);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle, DeviceHandle);
+
+  FreePool (XenIo);
+
+  return Status;
+}
+
+
+//
+// The static object that groups the Supported() (ie. probe), Start() and
+// Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata
+// C, 10.1 EFI Driver Binding Protocol.
+//
+STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {
+  &XenIoPciDeviceBindingSupported,
+  &XenIoPciDeviceBindingStart,
+  &XenIoPciDeviceBindingStop,
+  0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers
+  NULL, // ImageHandle, to be overwritten by
+        // EfiLibInstallDriverBindingComponentName2() in XenIoPciDeviceEntryPoint()
+  NULL  // DriverBindingHandle, ditto
+};
+
+
+//
+// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
+// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
+// in English, for display on standard console devices. This is recommended for
+// UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
+// Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
+//
+STATIC
+EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {
+  { "eng;en", L"XenIo PCI Driver" },
+  { NULL,     NULL                }
+};
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL gComponentName;
+
+EFI_STATUS
+EFIAPI
+XenIoPciGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,
+  IN  CHAR8                       *Language,
+  OUT CHAR16                      **DriverName
+  )
+{
+  return LookupUnicodeString2 (
+           Language,
+           This->SupportedLanguages,
+           mDriverNameTable,
+           DriverName,
+           (BOOLEAN)(This == &gComponentName) // Iso639Language
+           );
+}
+
+EFI_STATUS
+EFIAPI
+XenIoPciGetDeviceName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,
+  IN  EFI_HANDLE                  DeviceHandle,
+  IN  EFI_HANDLE                  ChildHandle,
+  IN  CHAR8                       *Language,
+  OUT CHAR16                      **ControllerName
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
+  &XenIoPciGetDriverName,
+  &XenIoPciGetDeviceName,
+  "eng" // SupportedLanguages, ISO 639-2 language codes
+};
+
+STATIC
+EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)     &XenIoPciGetDriverName,
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &XenIoPciGetDeviceName,
+  "en" // SupportedLanguages, RFC 4646 language codes
+};
+
+
+//
+// Entry point of this driver.
+//
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceEntryPoint (
+  IN EFI_HANDLE       ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  return EfiLibInstallDriverBindingComponentName2 (
+           ImageHandle,
+           SystemTable,
+           &gDriverBinding,
+           ImageHandle,
+           &gComponentName,
+           &gComponentName2
+           );
+}
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf new file +35 -0
new file mode 100644
index 000000000000..b32075a38163
@@ -0,0 +1,45 @@
+## @file
+#  Driver for the virtual Xen PCI device
+#
+#  Copyright (C) 2015, Linaro Ltd.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION               = 0x00010005
+  BASE_NAME                 = XenIoPciDxe
+  FILE_GUID                 = cf569f50-de44-4f54-b4d7-f4ae25cda599
+  MODULE_TYPE               = UEFI_DRIVER
+  VERSION_STRING            = 1.0
+  ENTRY_POINT               = XenIoPciDeviceEntryPoint
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[Sources]
+  XenIoPciDxe.c
+
+[LibraryClasses]
+  UefiDriverEntryPoint
+  UefiBootServicesTableLib
+  MemoryAllocationLib
+  BaseMemoryLib

OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf line 45

Quoted 10 lines
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf new file +10 -0
+  BaseLib
+  UefiLib
+  DebugLib
+
+[Protocols]
+  gEfiDriverBindingProtocolGuid
+  gEfiPciIoProtocolGuid
+  gEfiComponentName2ProtocolGuid
+  gEfiComponentNameProtocolGuid
+  gXenIoProtocolGuid

Please fix the two bugs; the rest seems okay.

You can smoke-test a UEFI driver model driver by repeatedly connecting it and disconnecting it in the UEFI shell, using the connect and disconnect commands. There are options for recursive connecting too. See also "dh -d -v", "drivers" and "devices".

Thanks,
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

Acked-by
#94 lore raw

Re: [PATCH v2 21/29] Ovmf/Xen: move XenBusDxe to abstract XENIO_PROTOCOL

comments below

Quoted 212 lines · Ard Biesheuvel

While Xen on Intel uses a virtual PCI device to communicate the base address of the grant table, the ARM implementation uses a DT node, which is fundamentally incompatible with the way XenBusDxe is implemented, i.e., as a UEFI Driver Model implementation for a PCI device.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/OvmfPkgIa32.dsc           |  1 +
 OvmfPkg/OvmfPkgIa32.fdf           |  1 +
 OvmfPkg/OvmfPkgIa32X64.dsc        |  1 +
 OvmfPkg/OvmfPkgIa32X64.fdf        |  1 +
 OvmfPkg/OvmfPkgX64.dsc            |  1 +
 OvmfPkg/OvmfPkgX64.fdf            |  1 +
 OvmfPkg/XenBusDxe/ComponentName.c |  2 +-
 OvmfPkg/XenBusDxe/GrantTable.c    |  5 ++---
 OvmfPkg/XenBusDxe/GrantTable.h    |  3 +--
 OvmfPkg/XenBusDxe/XenBus.c        |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c     | 57 ++++++++++++++-------------------------------------------
 OvmfPkg/XenBusDxe/XenBusDxe.h     |  8 ++------
 OvmfPkg/XenBusDxe/XenBusDxe.inf   |  2 +-
 13 files changed, 30 insertions(+), 59 deletions(-)
OvmfPkg/OvmfPkgIa32.dsc +1 -0
index 90540272745c..8c880613851d 100644
@@ -444,6 +444,7 @@
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
OvmfPkg/OvmfPkgIa32.fdf +1 -0
index f47e7ddc7834..ecef963d1e85 100644
@@ -227,6 +227,7 @@ INF  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
 INF  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
 
OvmfPkg/OvmfPkgIa32X64.dsc +1 -0
index 0a331eda8be0..ff32ecefd07b 100644
@@ -451,6 +451,7 @@
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
OvmfPkg/OvmfPkgIa32X64.fdf +1 -0
index 4c034460d5d2..29414ff04082 100644
@@ -227,6 +227,7 @@ INF  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
 INF  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
 
OvmfPkg/OvmfPkgX64.dsc +1 -0
index e2b37c271681..8bac6dc313f0 100644
@@ -449,6 +449,7 @@
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
OvmfPkg/OvmfPkgX64.fdf +1 -0
index 2323eb2edf33..f1feb698ba66 100644
@@ -227,6 +227,7 @@ INF  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
 INF  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
 
OvmfPkg/XenBusDxe/ComponentName.c +1 -1
index 4530509e65dc..3f2dd406c77d 100644
@@ -155,7 +155,7 @@ XenBusDxeComponentNameGetControllerName (
   Status = EfiTestManagedDevice (
              ControllerHandle,
              gXenBusDxeDriverBinding.DriverBindingHandle,
-             &gEfiPciIoProtocolGuid
+             &gXenIoProtocolGuid
              );
   if (EFI_ERROR (Status)) {
     return Status;
OvmfPkg/XenBusDxe/GrantTable.c +2 -3
index a80d5eff39cd..19117fbe0373 100644
@@ -139,8 +139,7 @@ XenGrantTableEndAccess (
 
 VOID
 XenGrantTableInit (
-  IN XENBUS_DEVICE  *Dev,
-  IN UINT64         MmioAddr
+  IN XENBUS_DEVICE  *Dev
   )
 {
   xen_add_to_physmap_t Parameters;
@@ -155,7 +154,7 @@ XenGrantTableInit (
     XenGrantTablePutFreeEntry ((grant_ref_t)Index);
   }
 
-  GrantTable = (VOID*)(UINTN) MmioAddr;
+  GrantTable = (VOID*)(UINTN) Dev->XenIo->GrantTableAddress;
   for (Index = 0; Index < NR_GRANT_FRAMES; Index++) {
     Parameters.domid = DOMID_SELF;
     Parameters.idx = Index;
OvmfPkg/XenBusDxe/GrantTable.h +1 -2
index 5772c56662df..194275ba7ed5 100644
@@ -29,8 +29,7 @@
 **/
 VOID
 XenGrantTableInit (
-  IN XENBUS_DEVICE  *Dev,
-  IN UINT64         MmioAddr
+  IN XENBUS_DEVICE  *Dev
   );
 
 /**
OvmfPkg/XenBusDxe/XenBus.c +3 -3
index f69c27dd184a..ee9526c33252 100644
@@ -138,7 +138,7 @@ XenBusAddDevice (
   XENBUS_PRIVATE_DATA *Private;
   EFI_STATUS Status;
   XENBUS_DEVICE_PATH *TempXenBusPath;
-  VOID *ChildPciIo;
+  VOID *ChildXenIo;
 
   AsciiSPrint (DevicePath, sizeof (DevicePath),
                "device/%a/%a", Type, Id);
@@ -208,8 +208,8 @@ XenBusAddDevice (
     }
 
     Status = gBS->OpenProtocol (Dev->ControllerHandle,
-               &gEfiPciIoProtocolGuid,
-               &ChildPciIo, Dev->This->DriverBindingHandle,
+               &gXenIoProtocolGuid,
+               &ChildXenIo, Dev->This->DriverBindingHandle,
                Private->Handle,
                EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER);
     if (EFI_ERROR (Status)) {
OvmfPkg/XenBusDxe/XenBusDxe.c +4 -12
index cc334c086c1f..6474428b79e5 100644
@@ -23,8 +23,6 @@
 
 **/
 
-#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Acpi.h>
 #include <Library/DebugLib.h>
 #include <Library/XenHypercallLib.h>
 
@@ -233,35 +231,23 @@ XenBusDxeDriverBindingSupported (
   )
 {
   EFI_STATUS          Status;
-  EFI_PCI_IO_PROTOCOL *PciIo;
-  PCI_TYPE00          Pci;
+  XENIO_PROTOCOL      *XenIo;
 
   Status = gBS->OpenProtocol (
                      ControllerHandle,
-                     &gEfiPciIoProtocolGuid,
-                     (VOID **)&PciIo,
+                     &gXenIoProtocolGuid,
+                     (VOID **)&XenIo,
                      This->DriverBindingHandle,
                      ControllerHandle,
                      EFI_OPEN_PROTOCOL_BY_DRIVER
                      );
+
   if (EFI_ERROR (Status)) {
     return Status;
   }
 
-  Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0,
-                            sizeof Pci / sizeof (UINT32), &Pci);
-
-  if (Status == EFI_SUCCESS) {
-    if (Pci.Hdr.VendorId == PCI_VENDOR_ID_XEN &&
-        Pci.Hdr.DeviceId == PCI_DEVICE_ID_XEN_PLATFORM) {

OvmfPkg/XenBusDxe/XenBusDxe.c XenBusDxeDriverBindingSupported ( · line 250

Quoted 10 lines
OvmfPkg/XenBusDxe/XenBusDxe.c +2 -8
-      Status = EFI_SUCCESS;
-    } else {
-      Status = EFI_UNSUPPORTED;
-    }
-  }
-
-  gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,
-         This->DriverBindingHandle, ControllerHandle);
+  gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid,
+    This->DriverBindingHandle, ControllerHandle);

Whitespace damage. The parameter should be indented one or two spaces relative to the called member.

Quoted 123 lines
OvmfPkg/XenBusDxe/XenBusDxe.c +8 -23
   return Status;
 }
@@ -326,19 +312,18 @@ XenBusDxeDriverBindingStart (
 {
   EFI_STATUS Status;
   XENBUS_DEVICE *Dev;
-  EFI_PCI_IO_PROTOCOL *PciIo;
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc;
-  UINT64 MmioAddr;
+  XENIO_PROTOCOL *XenIo;
   EFI_DEVICE_PATH_PROTOCOL *DevicePath;
 
   Status = gBS->OpenProtocol (
                      ControllerHandle,
-                     &gEfiPciIoProtocolGuid,
-                     (VOID **) &PciIo,
+                     &gXenIoProtocolGuid,
+                     (VOID**)&XenIo,
                      This->DriverBindingHandle,
                      ControllerHandle,
                      EFI_OPEN_PROTOCOL_BY_DRIVER
                      );
+
   if (EFI_ERROR (Status)) {
     return Status;
   }
@@ -360,7 +345,7 @@ XenBusDxeDriverBindingStart (
   Dev->Signature = XENBUS_DEVICE_SIGNATURE;
   Dev->This = This;
   Dev->ControllerHandle = ControllerHandle;
-  Dev->PciIo = PciIo;
+  Dev->XenIo = XenIo;
   Dev->DevicePath = DevicePath;
   InitializeListHead (&Dev->ChildList);
 
@@ -376,20 +361,6 @@ XenBusDxeDriverBindingStart (
   mMyDevice = Dev;
   EfiReleaseLock (&mMyDeviceLock);
 
-  //
-  // The BAR1 of this PCI device is used for shared memory and is supposed to
-  // look like MMIO. The address space of the BAR1 will be used to map the
-  // Grant Table.
-  //
-  Status = PciIo->GetBarAttributes (PciIo, PCI_BAR_IDX1, NULL, (VOID**) &BarDesc);
-  ASSERT_EFI_ERROR (Status);
-  ASSERT (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM);
-
-  /* Get a Memory address for mapping the Grant Table. */
-  DEBUG ((EFI_D_INFO, "XenBus: BAR at %LX\n", BarDesc->AddrRangeMin));
-  MmioAddr = BarDesc->AddrRangeMin;
-  FreePool (BarDesc);
-
   Status = XenGetSharedInfoPage (Dev);
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "XenBus: Unable to get the shared info page.\n"));
@@ -397,7 +368,7 @@ XenBusDxeDriverBindingStart (
     goto ErrorAllocated;
   }
 
-  XenGrantTableInit (Dev, MmioAddr);
+  XenGrantTableInit (Dev);
 
   Status = XenStoreInit (Dev);
   ASSERT_EFI_ERROR (Status);
@@ -417,7 +388,7 @@ ErrorAllocated:
   gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid,
                       This->DriverBindingHandle, ControllerHandle);
 ErrorOpenningProtocol:
-  gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,
+  gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid,
                       This->DriverBindingHandle, ControllerHandle);
   return Status;
 }
@@ -507,7 +478,7 @@ XenBusDxeDriverBindingStop (
 
   gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid,
          This->DriverBindingHandle, ControllerHandle);
-  gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,
+  gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid,
          This->DriverBindingHandle, ControllerHandle);
 
   mMyDevice = NULL;
OvmfPkg/XenBusDxe/XenBusDxe.h +2 -6
index 9b7219906a69..6c306e017b07 100644
@@ -39,7 +39,7 @@
 //
 // Consumed Protocols
 //
-#include <Protocol/PciIo.h>
+#include <Protocol/XenIo.h>
 
 
 //
@@ -73,10 +73,6 @@ extern EFI_COMPONENT_NAME_PROTOCOL  gXenBusDxeComponentName;
 //
 #include <IndustryStandard/Xen/xen.h>
 
-#define PCI_VENDOR_ID_XEN                0x5853
-#define PCI_DEVICE_ID_XEN_PLATFORM       0x0001
-
-
 typedef struct _XENBUS_DEVICE_PATH XENBUS_DEVICE_PATH;
 typedef struct _XENBUS_DEVICE XENBUS_DEVICE;
 
@@ -86,7 +82,7 @@ struct _XENBUS_DEVICE {
   UINT32                        Signature;
   EFI_DRIVER_BINDING_PROTOCOL   *This;
   EFI_HANDLE                    ControllerHandle;
-  EFI_PCI_IO_PROTOCOL           *PciIo;
+  XENIO_PROTOCOL                *XenIo;
   EFI_EVENT                     ExitBootEvent;
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
   LIST_ENTRY                    ChildList;
OvmfPkg/XenBusDxe/XenBusDxe.inf +0 -0
index 714607dbd6f8..31553ac5a64a 100644

OvmfPkg/XenBusDxe/XenBusDxe.inf line 74

Quoted 9 lines
OvmfPkg/XenBusDxe/XenBusDxe.inf +1 -1
@@ -67,8 +67,8 @@
 
 [Protocols]
   gEfiDriverBindingProtocolGuid
-  gEfiPciIoProtocolGuid
   gEfiComponentName2ProtocolGuid
   gEfiComponentNameProtocolGuid
   gXenBusProtocolGuid
+  gXenIoProtocolGuid
 

I won't "audit" XenBusDxe, obviously, but if you covered all PciIo occurrences with the above, then it should not regress anything.

Please restore the indentation.

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#96 lore raw

Re: [PATCH v2 26/29] Ovfm/Xen: add a Vendor Hardware device path GUID for the XenBus root

Quoted 47 lines · Ard Biesheuvel

On non-PCI Xen guests (such as ARM), the XenBus root is not a PCI device but an abstract 'platform' device. Add a dedicated Vendor Hardware device path GUID to identify this node.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Include/Guid/XenBusRootDevice.h | 24 ++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                     |  1 +
 2 files changed, 25 insertions(+)
OvmfPkg/Include/Guid/XenBusRootDevice.h new file +24 -0
new file mode 100644
index 000000000000..2b6e71018052
@@ -0,0 +1,24 @@
+/** @file
+  GUID to be used to identify the XenBus root node on non-PCI Xen guests
+
+  Copyright (C) 2015, Linaro Ltd.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License that accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __XENBUS_ROOT_DEVICE_H__
+#define __XENBUS_ROOT_DEVICE_H__
+
+#define XENBUS_ROOT_DEVICE_GUID \
+{0xa732241f, 0x383d, 0x4d9c, {0x8a, 0xe1, 0x8e, 0x09, 0x83, 0x75, 0x89, 0xd7}}
+
+extern EFI_GUID gXenBusRootDeviceGuid;
+
+#endif
OvmfPkg/OvmfPkg.dec +0 -0
index 3711fa922311..d61600225919 100644

OvmfPkg/OvmfPkg.dec line 59

Quoted 7 lines
OvmfPkg/OvmfPkg.dec +1 -0
@@ -53,6 +53,7 @@
   gEfiXenInfoGuid                 = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}
   gOvmfPlatformConfigGuid         = {0x7235c51c, 0x0c80, 0x4cab, {0x87, 0xac, 0x3b, 0x08, 0x4a, 0x63, 0x04, 0xb1}}
   gVirtioMmioTransportGuid        = {0x837dca9e, 0xe874, 0x4d82, {0xb2, 0x9a, 0x23, 0xfe, 0x0e, 0x23, 0xd1, 0xe2}}
+  gXenBusRootDeviceGuid           = {0xa732241f, 0x383d, 0x4d9c, {0x8a, 0xe1, 0x8e, 0x09, 0x83, 0x75, 0x89, 0xd7}}
 
 [Protocols]
   gVirtioDeviceProtocolGuid       = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}

A message that is not in the archive (sent off-list or not yet received): [email protected]

#98 lore raw

Re: [PATCH v2 25/29] Ovmf/Xen: implement dummy RealTimeClockLib for Xen

Quoted 248 lines · Ard Biesheuvel

This implements a dummy RealTimeClockLib for Xen, as there is no guest interface to access the time kept by Xen that can be shared between UEFI and the OS.

Contributed-under: TianoCore Contribution Agreement 1.0

---
 OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c   | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf |  38 ++++++++++++++++
 2 files changed, 234 insertions(+)
OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c new file +196 -0
new file mode 100644
index 000000000000..70204ac22a92
@@ -0,0 +1,196 @@
+/** @file
+  Implement EFI RealTimeClock runtime services via Xen shared info page
+
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Uefi.h>
+#include <PiDxe.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+
+/**
+  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
+ **/
+STATIC
+VOID
+EpochToEfiTime (
+  IN  UINTN     EpochSeconds,
+  OUT EFI_TIME  *Time
+  )
+{
+  UINTN         a;
+  UINTN         b;
+  UINTN         c;
+  UINTN         d;
+  UINTN         g;
+  UINTN         j;
+  UINTN         m;
+  UINTN         y;
+  UINTN         da;
+  UINTN         db;
+  UINTN         dc;
+  UINTN         dg;
+  UINTN         hh;
+  UINTN         mm;
+  UINTN         ss;
+  UINTN         J;
+
+  J  = (EpochSeconds / 86400) + 2440588;
+  j  = J + 32044;
+  g  = j / 146097;
+  dg = j % 146097;
+  c  = (((dg / 36524) + 1) * 3) / 4;
+  dc = dg - (c * 36524);
+  b  = dc / 1461;
+  db = dc % 1461;
+  a  = (((db / 365) + 1) * 3) / 4;
+  da = db - (a * 365);
+  y  = (g * 400) + (c * 100) + (b * 4) + a;
+  m  = (((da * 5) + 308) / 153) - 2;
+  d  = da - (((m + 4) * 153) / 5) + 122;
+
+  Time->Year  = y - 4800 + ((m + 2) / 12);
+  Time->Month = ((m + 2) % 12) + 1;
+  Time->Day   = d + 1;
+
+  ss = EpochSeconds % 60;
+  a  = (EpochSeconds - ss) / 60;
+  mm = a % 60;
+  b = (a - mm) / 60;
+  hh = b % 24;
+
+  Time->Hour        = hh;
+  Time->Minute      = mm;
+  Time->Second      = ss;
+  Time->Nanosecond  = 0;
+
+}
+
+/**
+  Returns the current time and date information, and the time-keeping capabilities
+  of the hardware platform.
+
+  @param  Time                  A pointer to storage to receive a snapshot of the current time.
+  @param  Capabilities          An optional pointer to a buffer to receive the real time clock
+                                device's capabilities.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+  @retval EFI_INVALID_PARAMETER Time is NULL.
+  @retval EFI_DEVICE_ERROR      The time could not be retrieved due to hardware error.
+
+**/
+EFI_STATUS
+EFIAPI
+LibGetTime (
+  OUT EFI_TIME                *Time,
+  OUT  EFI_TIME_CAPABILITIES  *Capabilities
+  )
+{
+  ASSERT (Time != NULL);
+
+  //
+  // For now, there is nothing that we can do besides returning a bogus time,
+  // as Xen's timekeeping uses a shared info page which cannot be shared
+  // between UEFI and the OS
+  //
+  EpochToEfiTime(1421770011, Time);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Sets the current local time and date information.
+
+  @param  Time                  A pointer to the current time.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+  @retval EFI_INVALID_PARAMETER A time field is out of range.
+  @retval EFI_DEVICE_ERROR      The time could not be set due due to hardware error.
+
+**/
+EFI_STATUS
+EFIAPI
+LibSetTime (
+  IN EFI_TIME                *Time
+  )
+{
+  return EFI_DEVICE_ERROR;
+}
+
+
+/**
+  Returns the current wakeup alarm clock setting.
+
+  @param  Enabled               Indicates if the alarm is currently enabled or disabled.
+  @param  Pending               Indicates if the alarm signal is pending and requires acknowledgement.
+  @param  Time                  The current alarm setting.
+
+  @retval EFI_SUCCESS           The alarm settings were returned.
+  @retval EFI_INVALID_PARAMETER Any parameter is NULL.
+  @retval EFI_DEVICE_ERROR      The wakeup time could not be retrieved due to a hardware error.
+  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.
+
+**/
+EFI_STATUS
+EFIAPI
+LibGetWakeupTime (
+  OUT BOOLEAN     *Enabled,
+  OUT BOOLEAN     *Pending,
+  OUT EFI_TIME    *Time
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Sets the system wakeup alarm clock time.
+
+  @param  Enabled               Enable or disable the wakeup alarm.
+  @param  Time                  If Enable is TRUE, the time to set the wakeup alarm for.
+
+  @retval EFI_SUCCESS           If Enable is TRUE, then the wakeup alarm was enabled. If
+                                Enable is FALSE, then the wakeup alarm was disabled.
+  @retval EFI_INVALID_PARAMETER A time field is out of range.
+  @retval EFI_DEVICE_ERROR      The wakeup time could not be set due to a hardware error.
+  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.
+
+**/
+EFI_STATUS
+EFIAPI
+LibSetWakeupTime (
+  IN BOOLEAN      Enabled,
+  OUT EFI_TIME    *Time
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This is the declaration of an EFI image entry point. This can be the entry point to an application
+  written to this specification, an EFI boot service driver, or an EFI runtime driver.
+
+  @param  ImageHandle           Handle that identifies the loaded image.
+  @param  SystemTable           System Table for this image.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+LibRtcInitialize (
+  IN EFI_HANDLE                            ImageHandle,
+  IN EFI_SYSTEM_TABLE                      *SystemTable
+  )
+{
+  return EFI_SUCCESS;
+}
OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf new file +28 -0
new file mode 100644
index 000000000000..aafbfda6b491
@@ -0,0 +1,38 @@
+#/** @file
+#
+# Copyright (c) 2015, L Ltd. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenRealTimeClockLib
+  FILE_GUID                      = EC2557E8-7005-430B-9F6F-9BA109698248
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = RealTimeClockLib|DXE_CORE DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
+
+[Sources.common]
+  XenRealTimeClockLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec

OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf line 38

Quoted 10 lines
OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf new file +10 -0
+  EmbeddedPkg/EmbeddedPkg.dec
+
+[LibraryClasses]
+  UefiLib
+  DebugLib
+  DxeServicesTableLib
+  UefiRuntimeLib
+
+[Guids]
+  gEfiEventVirtualAddressChangeGuid

I think this library belongs under
"ArmPlatformPkg/ArmVirtualizationPkg/Library/".

The RealTimeClockLib library class (interface) is declared in "EmbeddedPkg/Include/Library/RealTimeClockLib.h", and it is completely unused in OVMF. OTOH ArmPlatformPkg uses the library class in a number of places, and it even provides one library instance (PL031RealTimeClockLib).

Thanks,
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#100 lore raw

Re: [PATCH v2 27/29] ArmVirtualizationPkg: add XenIoMmioLib

comments below

Quoted 4 lines · Ard Biesheuvel

This adds a XenIoMmioLib declaration and implementation that can be invoked to install the XENIO_PROTOCOL and a corresponding grant table address on a EFI handle.

Quoted 8 lines

Contributed-under: TianoCore Contribution Agreement 1.0

---
 ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec              |  6 +++++
 ArmPlatformPkg/ArmVirtualizationPkg/Include/Library/XenIoMmioLib.h        | 20 +++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c   | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf | 38 +++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+)

(1) In order to stay "symmetric" with VirtioMmioDeviceLib, I propose to add this library (both class & the first instance) to OvmfPkg.

Quoted 33 lines
ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec +6 -0
index 868488906643..c690f1481093 100644
@@ -30,6 +30,12 @@
 [Includes.common]
   Include                        # Root include for the package
 
+[LibraryClasses]
+  #
+  # library to create handles containing the XENIO_PROTOCOL I/O protocol
+  #
+  XenIoMmioLib|Include/Library/XenIoMmioLib.h
+
 [Guids.common]
   gArmVirtualizationTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
ArmPlatformPkg/ArmVirtualizationPkg/Include/Library/XenIoMmioLib.h new file +10 -0
new file mode 100644
index 000000000000..faeabe5affe0
@@ -0,0 +1,20 @@
+/** @file
+*  Library to install the XENIO_PROTOCOL on a handle
+*
+*  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+*
+*  This program and the accompanying materials are
+*  licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*

ArmPlatformPkg/ArmVirtualizationPkg/Include/Library/XenIoMmioLib.h line 20

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Include/Library/XenIoMmioLib.h new file +10 -0
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+EFI_STATUS
+XenIoMmioInstall (
+  IN  EFI_HANDLE  *Handle,
+  IN  UINT64      GrantTableAddress
+  );

(2) Please add an uninstall function.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 2

Quoted 8 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +2 -0
new file mode 100644
index 000000000000..2d8413638680
@@ -0,0 +1,91 @@
+/** @file
+*  Library to install the XENIO_PROTOCOL on a handle

(3) The XenIoMmioInstall() function does more than that, it also installs the device path protocol. That's okay per se, but you should be fully clear about it in the leading comment here, or in the function's comment.

If you update this comment here, please update all of its occurrences.

Quoted 33 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +33 -0
+*
+*  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+*
+*  This program and the accompanying materials are
+*  licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/XenIoMmioLib.h>
+
+#include <Protocol/XenIo.h>
+#include <Guid/XenBusRootDevice.h>
+
+#pragma pack (1)
+typedef struct {
+  VENDOR_DEVICE_PATH                  Vendor;
+  EFI_DEVICE_PATH_PROTOCOL            End;
+} XENBUS_ROOT_DEVICE_PATH;
+#pragma pack ()
+
+EFI_STATUS

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 45

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +10 -0
+XenIoMmioInstall (
+  IN  EFI_HANDLE  *Handle,
+  IN  UINT64      GrantTableAddress
+  )
+{
+  EFI_STATUS                     Status;
+  XENIO_PROTOCOL                 *XenIo;
+  XENBUS_ROOT_DEVICE_PATH        *XenBusDevicePath;
+
+  ASSERT (Handle != NULL);

(4) This is wrong. (I'm not sure how you are using the library in the following patches, but this in itself does look wrong.)

A handle is created in UEFI when you install the first protocol on an initially NULL handle. Please see the documentation of InstallProtocolInterface(). Similarly, if UninstallProtocolInterface() removes the last protocol interface from a handle, the handle is released.

(Same applies to InstallMultipleProtocolInterfaces() and UninstallMultipleProtocolInterfaces().)

Meaning, the prototype of your function is *almost* correct. It takes EFI_HANDLE*, which is fine, but you should qualify it as IN OUT.

If the caller passes in a non-NULL handle, you'll just add two more protocol interfaces, fine.

If the caller passes in a NULL handle, you'll *allocate* tha handle for the caller, transparently in the first protocol interface installation.

Similarly, if something goes wrong in the function, then on the error path (== destruction path) you'll uninstall the protocols you have installed thus far. If you created the handle in the first place, then that error handling will release it for you at once.

(Note that the uninstall functions can't null the Handle parameter in that case -- which means that you should save a copy of the incoming handle, and restore it at the end when something fails. If it was non-NULL initially, nothing will change, but if it was NULL initially, you have to reset it to NULL.)

... If you find this too complex, then you can demand a non-NULL handle on input, but:

- not with an ASSERT() please (return EFI_INVALID_PARAMETER instead),

- remember that the caller can also only create a new handle by installing *some* protocol interface on an initially NULL handle. Since you're installing the device path and the xenio protocols here, I'm not sure what's left for the caller to install *before* it calls this function. (But, given your ASSERT(), this is a problem you must have solved anyway.)

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 48

Quoted 3 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +3 -0
+
+  XenIo = AllocateZeroPool (sizeof *XenIo);
+  ASSERT (XenIo != NULL);

(5) Please return EFI_OUT_OF_RESOURCES instead.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 54

Quoted 6 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +6 -0
+  XenIo->GrantTableAddress = GrantTableAddress;
+
+  XenBusDevicePath = (XENBUS_ROOT_DEVICE_PATH *)CreateDeviceNode (
+                                HARDWARE_DEVICE_PATH,
+                                HW_VENDOR_DP,
+                                sizeof (XENBUS_ROOT_DEVICE_PATH));

(6) I dislike this. The indentation is incorrect, but that's a minor nit.

The problem is a semantic one. CreateDeviceNode() is supposed to create a *single* device path node. It allows you to set the size because you might want to pack untold horrors later into that *one* node. (Especially a vendor hw node.)

I can see that later on you fix up the size of the first node, but it's misleading and ugly.

I recommend to allocate the full device path structure with AllocatePool, and fill it in field-wise.

Another frequent approach is to create an initialized template (of static storage duration) of the XENBUS_ROOT_DEVICE_PATH structure, and use AllocateCopyPool() here.

... Anyway I realize this follows existing code in "ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c". If I didn't complain then, I shouldn't now. :) I'll leave it to you, it's not a bug after all.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 58

Quoted 4 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +4 -0
+  if (XenBusDevicePath == NULL) {
+    DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }

(7) This will leak XenIo.

Please employ the cascade style error handling, with the ladder of goto labels. There's really no way around it.

Not when I'm your reviewer, anyway. ;)

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 61

Quoted 3 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +3 -0
+
+  CopyMem (&XenBusDevicePath->Vendor.Guid, &gXenBusRootDeviceGuid,
+    sizeof (EFI_GUID));

Side remark: CopyGuid() is preferred. (Yes, yes, "ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c" says CopyMem too. :))

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 63

Quoted 2 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +2 -0
+  SetDevicePathNodeLength (&XenBusDevicePath->Vendor,
+    sizeof (*XenBusDevicePath) - sizeof (XenBusDevicePath->End));

Brrrrr. :) See (6). But, again, not strictly a bug.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 68

Quoted 5 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +5 -0
+  SetDevicePathEndNode (&XenBusDevicePath->End);
+
+  Status = gBS->InstallProtocolInterface (Handle,
+                 &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
+                 XenBusDevicePath);

(8) Not a bug in itself, just a tip: since you are installing two protocol interfaces, please call InstallMultipleProtocolInterfaces() instead. That function is preferable because:
- It saves you some effort with error handling. Either both protocol interfaces will be installed, or none.
- This function internally enforces the unicity of device paths in the system (so that every handle remains uniquely addressable). Now, because you use an invariable device path, the second call to your function will be guaranteed to fail.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 71

Quoted 3 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +3 -0
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH "
+      "protocol on handle 0x%p (Status == %r)\n",

I prefer not to use 0x before %p, but it's your call.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 75

Quoted 4 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +4 -0
+      __FUNCTION__, *Handle, Status));
+    FreePool (XenBusDevicePath);
+    return Status;
+  }

Leaks XenIo. (I'm not adding a new numbered point for this, see (7) -- please just cover everything with the cascading error handling.)

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 82

Quoted 7 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +7 -0
+
+  Status = gBS->InstallProtocolInterface (Handle,
+                 &gXenIoProtocolGuid, EFI_NATIVE_INTERFACE,
+                 XenIo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "%a: Failed to install XENIO_PROTOCOL on handle 0x%p "
+      "(Status == %r)\n", __FUNCTION__, *Handle, Status));

(0x%p)

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c line 89

Quoted 7 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +7 -0
+
+    Status = gBS->UninstallProtocolInterface (*Handle,
+                    &gEfiDevicePathProtocolGuid, XenBusDevicePath);
+    ASSERT_EFI_ERROR (Status);
+    FreePool (XenBusDevicePath);
+    FreePool (XenIo);
+  }

Right, this is why this style of free-on-error is not recommended. When you remember to free everything (as you do here), it doesn't scale (ever growing error handling blocks). And, it's easy to forget stuff to free.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf line 4

Quoted 12 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.c new file +2 -0
+  return Status;
+}
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf new file +4 -0
new file mode 100644
index 000000000000..14f24ff7fd2c
@@ -0,0 +1,38 @@
+## @file
+# Library to install the XENIO_PROTOCOL on a handle
+#
+# Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>

Indentation is off by one, but it's not a deal breaker. :)

Quoted 5 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf new file +5 -0
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php.

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf line 19

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf new file +10 -0
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = XenIoMmioLib
+  FILE_GUID                      = 3CD90EEC-EBF3-425D-AAE8-B16215AC4F50

(9) I've been on the lookout throughout your patch series, and finally here it is. A FILE_GUID that you forgot to set from a fresh invocation of "uuidgen" :)

This FILE_GUID is already used in "ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/ArmVirtualizationDxeHobLib.inf".

(What, you don't write your INF files from zero? Unforgivable! ;))

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf new file +9 -0
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = XenIoMmioLib
+
+[Sources]
+  XenIoMmioLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec

ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf line 38

Quoted 10 lines
ArmPlatformPkg/ArmVirtualizationPkg/Library/XenIoMmioLib/XenIoMmioLib.inf new file +10 -0
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+
+[Guids]
+  gXenBusRootDeviceGuid
+
+[Protocols]
+  gEfiDevicePathProtocolGuid

Thanks
Laszlo

#101 lore raw

Re: [PATCH v2 27/29] ArmVirtualizationPkg: add XenIoMmioLib

In reply to a message not in the archive

Review

Quoted 5 lines · Ard Biesheuvel
(quoted diff) +5 -0
+EFI_STATUS
+XenIoMmioInstall (
+  IN  EFI_HANDLE  *Handle,
+  IN  UINT64      GrantTableAddress
+  );

Sorry I had another (pedantic) remark here -- consider EFI_PHYSICAL_ADDRESS instead of UINT64. (It looks better and that's what's in your protocol struct anyway, IIRC.)

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#103 lore raw

Re: [PATCH v2 27/29] ArmVirtualizationPkg: add XenIoMmioLib

Quoted 4 lines · Laszlo Ersek

comments below

On 01/26/15 20:03, Ard Biesheuvel wrote:

Quoted 14 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+EFI_STATUS
+XenIoMmioInstall (
+  IN  EFI_HANDLE  *Handle,
+  IN  UINT64      GrantTableAddress
+  )
+{
+  EFI_STATUS                     Status;
+  XENIO_PROTOCOL                 *XenIo;
+  XENBUS_ROOT_DEVICE_PATH        *XenBusDevicePath;
+
+  ASSERT (Handle != NULL);

(4) This is wrong. (I'm not sure how you are using the library in the following patches, but this in itself does look wrong.)

Heh, I tricked myself. This ASSERT() is valid. I missed you weren't saying *Handle.

However, I believe the following remains valid from my point (4):

Quoted 5 lines

(Note that the uninstall functions can't null the Handle parameter in that case -- which means that you should save a copy of the incoming handle, and restore it at the end when something fails. If it was non-NULL initially, nothing will change, but if it was NULL initially, you have to reset it to NULL.)

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#105 lore raw

Re: [PATCH v2 27/29] ArmVirtualizationPkg: add XenIoMmioLib

Quoted 20 lines · Laszlo Ersek
Quoted 4 lines · Laszlo Ersek

comments below

On 01/26/15 20:03, Ard Biesheuvel wrote:

Quoted 14 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+EFI_STATUS
+XenIoMmioInstall (
+  IN  EFI_HANDLE  *Handle,
+  IN  UINT64      GrantTableAddress
+  )
+{
+  EFI_STATUS                     Status;
+  XENIO_PROTOCOL                 *XenIo;
+  XENBUS_ROOT_DEVICE_PATH        *XenBusDevicePath;
+
+  ASSERT (Handle != NULL);

(4) This is wrong. (I'm not sure how you are using the library in the following patches, but this in itself does look wrong.)

Quoted 3 lines

Heh, I tricked myself. This ASSERT() is valid. I missed you weren't saying *Handle.

Right. You confused me there for a second.

Quoted 7 lines

However, I believe the following remains valid from my point (4):

Quoted 5 lines

(Note that the uninstall functions can't null the Handle parameter in that case -- which means that you should save a copy of the incoming handle, and restore it at the end when something fails. If it was non-NULL initially, nothing will change, but if it was NULL initially, you have to reset it to NULL.)

OK, got it