]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/OvmfXen: Introduce XenTimerDxe
authorAnthony PERARD <anthony.perard@citrix.com>
Tue, 13 Aug 2019 11:31:14 +0000 (12:31 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 21 Aug 2019 16:03:49 +0000 (18:03 +0200)
"OvmfPkg/8254TimerDxe" is replaced with a Xen-specific
EFI_TIMER_ARCH_PROTOCOL implementation. Also remove
8259InterruptControllerDxe as it is not used anymore.

This Timer uses the local APIC timer as time source as it can work on
both a Xen PVH guest and an HVM one.

Based on the "OvmfPkg/8254TimerDxe" implementation.

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

Maintainers.txt
OvmfPkg/OvmfXen.dsc
OvmfPkg/OvmfXen.fdf
OvmfPkg/XenTimerDxe/XenTimerDxe.c [new file with mode: 0644]
OvmfPkg/XenTimerDxe/XenTimerDxe.h [new file with mode: 0644]
OvmfPkg/XenTimerDxe/XenTimerDxe.inf [new file with mode: 0644]

index f51731a6b658057b2228b89b07551afec8d60599..78e9f889abf64b5a22e7b99dc8246417cb8b3f46 100644 (file)
@@ -385,6 +385,7 @@ F: OvmfPkg/XenIoPciDxe/
 F: OvmfPkg/XenPlatformPei/\r
 F: OvmfPkg/XenPvBlkDxe/\r
 F: OvmfPkg/XenResetVector/\r
+F: OvmfPkg/XenTimerDxe/\r
 R: Anthony Perard <anthony.perard@citrix.com>\r
 R: Julien Grall <julien.grall@arm.com>\r
 \r
index 477d8c76a154c357cb5cc46a9b4073fa0b1440c0..54ac910d8eede5968d44d0e95dcae55cb0f61d10 100644 (file)
   MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
 \r
   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
-  OvmfPkg/8259InterruptControllerDxe/8259.inf\r
+  OvmfPkg/XenTimerDxe/XenTimerDxe.inf\r
   UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf\r
   UefiCpuPkg/CpuDxe/CpuDxe.inf\r
-  OvmfPkg/8254TimerDxe/8254Timer.inf\r
   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf\r
   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf\r
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
index 49997fee9b79a4e6ed25e0dbea4542742d53903a..fa0830a3241cfdac08f59a9205054311f8e7e5e3 100644 (file)
@@ -298,10 +298,9 @@ INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
 INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
 INF  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
 INF  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
-INF  OvmfPkg/8259InterruptControllerDxe/8259.inf\r
+INF  OvmfPkg/XenTimerDxe/XenTimerDxe.inf\r
 INF  UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf\r
 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf\r
-INF  OvmfPkg/8254TimerDxe/8254Timer.inf\r
 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf\r
 INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf\r
 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf\r
diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.c b/OvmfPkg/XenTimerDxe/XenTimerDxe.c
new file mode 100644 (file)
index 0000000..9f9e047
--- /dev/null
@@ -0,0 +1,355 @@
+/** @file\r
+  Timer Architectural Protocol as defined in the DXE CIS\r
+\r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2019, Citrix Systems, Inc.\r
+\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "XenTimerDxe.h"\r
+\r
+//\r
+// The handle onto which the Timer Architectural Protocol will be installed\r
+//\r
+EFI_HANDLE                mTimerHandle = NULL;\r
+\r
+//\r
+// The Timer Architectural Protocol that this driver produces\r
+//\r
+EFI_TIMER_ARCH_PROTOCOL   mTimer = {\r
+  TimerDriverRegisterHandler,\r
+  TimerDriverSetTimerPeriod,\r
+  TimerDriverGetTimerPeriod,\r
+  TimerDriverGenerateSoftInterrupt\r
+};\r
+\r
+//\r
+// Pointer to the CPU Architectural Protocol instance\r
+//\r
+EFI_CPU_ARCH_PROTOCOL     *mCpu;\r
+\r
+//\r
+// The notification function to call on every timer interrupt.\r
+// A bug in the compiler prevents us from initializing this here.\r
+//\r
+EFI_TIMER_NOTIFY mTimerNotifyFunction;\r
+\r
+//\r
+// The current period of the timer interrupt\r
+//\r
+volatile UINT64           mTimerPeriod = 0;\r
+\r
+//\r
+// Worker Functions\r
+//\r
+/**\r
+  Interrupt Handler.\r
+\r
+  @param InterruptType    The type of interrupt that occurred\r
+  @param SystemContext    A pointer to the system context when the interrupt occurred\r
+**/\r
+VOID\r
+EFIAPI\r
+TimerInterruptHandler (\r
+  IN EFI_EXCEPTION_TYPE   InterruptType,\r
+  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  )\r
+{\r
+  EFI_TPL OriginalTPL;\r
+\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  SendApicEoi();\r
+\r
+  if (mTimerNotifyFunction != NULL) {\r
+    //\r
+    // @bug : This does not handle missed timer interrupts\r
+    //\r
+    mTimerNotifyFunction (mTimerPeriod);\r
+  }\r
+\r
+  gBS->RestoreTPL (OriginalTPL);\r
+}\r
+\r
+/**\r
+\r
+  This function registers the handler NotifyFunction so it is called every time\r
+  the timer interrupt fires.  It also passes the amount of time since the last\r
+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the\r
+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is\r
+  returned.  If the CPU does not support registering a timer interrupt handler,\r
+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler\r
+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.\r
+  If an attempt is made to unregister a handler when a handler is not registered,\r
+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to\r
+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR\r
+  is returned.\r
+\r
+\r
+  @param This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param NotifyFunction   The function to call when a timer interrupt fires.  This\r
+                          function executes at TPL_HIGH_LEVEL.  The DXE Core will\r
+                          register a handler for the timer interrupt, so it can know\r
+                          how much time has passed.  This information is used to\r
+                          signal timer based events.  NULL will unregister the handler.\r
+\r
+  @retval        EFI_SUCCESS            The timer handler was registered.\r
+  @retval        EFI_UNSUPPORTED        The platform does not support timer interrupts.\r
+  @retval        EFI_ALREADY_STARTED    NotifyFunction is not NULL, and a handler is already\r
+                                        registered.\r
+  @retval        EFI_INVALID_PARAMETER  NotifyFunction is NULL, and a handler was not\r
+                                        previously registered.\r
+  @retval        EFI_DEVICE_ERROR       The timer handler could not be registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  )\r
+{\r
+  //\r
+  // Check for invalid parameters\r
+  //\r
+  if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  mTimerNotifyFunction = NotifyFunction;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified\r
+  by TimerPeriod.  If the timer period is updated, then the selected timer\r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If\r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
+  If an error occurs while attempting to update the timer period, then the\r
+  timer hardware will be put back in its state prior to this call, and\r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt\r
+  is disabled.  This is not the same as disabling the CPU's interrupts.\r
+  Instead, it must either turn off the timer hardware, or it must adjust the\r
+  interrupt controller so that a CPU interrupt is not generated when the timer\r
+  interrupt fires.\r
+\r
+\r
+  @param This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param TimerPeriod     The rate to program the timer interrupt in 100 nS units.  If\r
+                         the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                         returned.  If the timer is programmable, then the timer period\r
+                         will be rounded up to the nearest timer period that is supported\r
+                         by the timer hardware.  If TimerPeriod is set to 0, then the\r
+                         timer interrupts will be disabled.\r
+\r
+  @retval        EFI_SUCCESS       The timer period was changed.\r
+  @retval        EFI_UNSUPPORTED   The platform cannot change the period of the timer interrupt.\r
+  @retval        EFI_DEVICE_ERROR  The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+{\r
+  UINT64  TimerCount;\r
+  UINT32  TimerFrequency;\r
+  UINTN   DivideValue = 1;\r
+\r
+  if (TimerPeriod == 0) {\r
+    //\r
+    // Disable timer interrupt for a TimerPeriod of 0\r
+    //\r
+    DisableApicTimerInterrupt();\r
+  } else {\r
+    TimerFrequency = PcdGet32(PcdFSBClock) / DivideValue;\r
+\r
+    //\r
+    // Convert TimerPeriod into local APIC counts\r
+    //\r
+    // TimerPeriod is in 100ns\r
+    // TimerPeriod/10000000 will be in seconds.\r
+    TimerCount = DivU64x32 (MultU64x32 (TimerPeriod, TimerFrequency),\r
+                            10000000);\r
+\r
+    // Check for overflow\r
+    if (TimerCount > MAX_UINT32) {\r
+      TimerCount = MAX_UINT32;\r
+      /* TimerPeriod = (MAX_UINT32 / TimerFrequency) * 10000000; */\r
+      TimerPeriod = 429496730;\r
+    }\r
+\r
+    //\r
+    // Program the timer with the new count value\r
+    //\r
+    InitializeApicTimer(DivideValue, TimerCount, TRUE, LOCAL_APIC_TIMER_VECTOR);\r
+\r
+    //\r
+    // Enable timer interrupt\r
+    //\r
+    EnableApicTimerInterrupt();\r
+  }\r
+  //\r
+  // Save the new timer period\r
+  //\r
+  mTimerPeriod = TimerPeriod;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  This function retrieves the period of timer interrupts in 100 ns units,\r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod\r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is\r
+  returned, then the timer is currently disabled.\r
+\r
+\r
+  @param This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param TimerPeriod     A pointer to the timer period to retrieve in 100 ns units.  If\r
+                         0 is returned, then the timer is currently disabled.\r
+\r
+  @retval EFI_SUCCESS            The timer period was returned in TimerPeriod.\r
+  @retval EFI_INVALID_PARAMETER  TimerPeriod is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  )\r
+{\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *TimerPeriod = mTimerPeriod;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  This function generates a soft timer interrupt. If the platform does not support soft\r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.\r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()\r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is\r
+  enabled when this service is called, then the registered handler will be invoked. The\r
+  registered handler should not be able to distinguish a hardware-generated timer\r
+  interrupt from a software-generated timer interrupt.\r
+\r
+\r
+  @param This              The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS       The soft timer interrupt was generated.\r
+  @retval EFI_UNSUPPORTED   The platform does not support the generation of soft timer interrupts.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_TPL     OriginalTPL;\r
+\r
+  if (GetApicTimerInterruptState()) {\r
+    //\r
+    // Invoke the registered handler\r
+    //\r
+    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+    if (mTimerNotifyFunction != NULL) {\r
+      //\r
+      // @bug : This does not handle missed timer interrupts\r
+      //\r
+      mTimerNotifyFunction (mTimerPeriod);\r
+    }\r
+\r
+    gBS->RestoreTPL (OriginalTPL);\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize the Timer Architectural Protocol driver\r
+\r
+  @param ImageHandle     ImageHandle of the loaded driver\r
+  @param SystemTable     Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS            Timer Architectural Protocol created\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough resources available to initialize driver.\r
+  @retval EFI_DEVICE_ERROR       A device error occurred attempting to initialize the driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Initialize the pointer to our notify function.\r
+  //\r
+  mTimerNotifyFunction = NULL;\r
+\r
+  //\r
+  // Make sure the Timer Architectural Protocol is not already installed in the system\r
+  //\r
+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiTimerArchProtocolGuid);\r
+\r
+  //\r
+  // Find the CPU architectural protocol.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **) &mCpu);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Force the timer to be disabled\r
+  //\r
+  Status = TimerDriverSetTimerPeriod (&mTimer, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Install interrupt handler for Local APIC Timer\r
+  //\r
+  Status = mCpu->RegisterInterruptHandler (mCpu, LOCAL_APIC_TIMER_VECTOR,\r
+                                           TimerInterruptHandler);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Force the timer to be enabled at its default period\r
+  //\r
+  Status = TimerDriverSetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mTimerHandle,\r
+                  &gEfiTimerArchProtocolGuid, &mTimer,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.h b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
new file mode 100644 (file)
index 0000000..e0a3d95
--- /dev/null
@@ -0,0 +1,177 @@
+/** @file\r
+  Private data structures\r
+\r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2019, Citrix Systems, Inc.\r
+\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#ifndef _TIMER_H_\r
+#define _TIMER_H_\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/Timer.h>\r
+\r
+#include <Register/LocalApic.h>\r
+\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/LocalApicLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+// The default timer tick duration is set to 10 ms = 100000 100 ns units\r
+//\r
+#define DEFAULT_TIMER_TICK_DURATION 100000\r
+\r
+//\r
+// The Timer Vector use for interrupt\r
+//\r
+#define LOCAL_APIC_TIMER_VECTOR 32\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+/**\r
+  Initialize the Timer Architectural Protocol driver\r
+\r
+  @param ImageHandle     ImageHandle of the loaded driver\r
+  @param SystemTable     Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS            Timer Architectural Protocol created\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough resources available to initialize driver.\r
+  @retval EFI_DEVICE_ERROR       A device error occurred attempting to initialize the driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+;\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified\r
+  by TimerPeriod.  If the timer period is updated, then the selected timer\r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If\r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
+  If an error occurs while attempting to update the timer period, then the\r
+  timer hardware will be put back in its state prior to this call, and\r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt\r
+  is disabled.  This is not the same as disabling the CPU's interrupts.\r
+  Instead, it must either turn off the timer hardware, or it must adjust the\r
+  interrupt controller so that a CPU interrupt is not generated when the timer\r
+  interrupt fires.\r
+\r
+\r
+  @param This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param NotifyFunction  The rate to program the timer interrupt in 100 nS units.  If\r
+                         the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                         returned.  If the timer is programmable, then the timer period\r
+                         will be rounded up to the nearest timer period that is supported\r
+                         by the timer hardware.  If TimerPeriod is set to 0, then the\r
+                         timer interrupts will be disabled.\r
+\r
+  @retval        EFI_SUCCESS       The timer period was changed.\r
+  @retval        EFI_UNSUPPORTED   The platform cannot change the period of the timer interrupt.\r
+  @retval        EFI_DEVICE_ERROR  The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  )\r
+;\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified\r
+  by TimerPeriod.  If the timer period is updated, then the selected timer\r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If\r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
+  If an error occurs while attempting to update the timer period, then the\r
+  timer hardware will be put back in its state prior to this call, and\r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt\r
+  is disabled.  This is not the same as disabling the CPU's interrupts.\r
+  Instead, it must either turn off the timer hardware, or it must adjust the\r
+  interrupt controller so that a CPU interrupt is not generated when the timer\r
+  interrupt fires.\r
+\r
+\r
+  @param This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param TimerPeriod     The rate to program the timer interrupt in 100 nS units.  If\r
+                         the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                         returned.  If the timer is programmable, then the timer period\r
+                         will be rounded up to the nearest timer period that is supported\r
+                         by the timer hardware.  If TimerPeriod is set to 0, then the\r
+                         timer interrupts will be disabled.\r
+\r
+  @retval        EFI_SUCCESS       The timer period was changed.\r
+  @retval        EFI_UNSUPPORTED   The platform cannot change the period of the timer interrupt.\r
+  @retval        EFI_DEVICE_ERROR  The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+;\r
+\r
+/**\r
+\r
+  This function retrieves the period of timer interrupts in 100 ns units,\r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod\r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is\r
+  returned, then the timer is currently disabled.\r
+\r
+\r
+  @param This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param TimerPeriod     A pointer to the timer period to retrieve in 100 ns units.  If\r
+                         0 is returned, then the timer is currently disabled.\r
+\r
+  @retval EFI_SUCCESS            The timer period was returned in TimerPeriod.\r
+  @retval EFI_INVALID_PARAMETER  TimerPeriod is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  )\r
+;\r
+\r
+/**\r
+\r
+  This function generates a soft timer interrupt. If the platform does not support soft\r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.\r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()\r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is\r
+  enabled when this service is called, then the registered handler will be invoked. The\r
+  registered handler should not be able to distinguish a hardware-generated timer\r
+  interrupt from a software-generated timer interrupt.\r
+\r
+\r
+  @param This              The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS       The soft timer interrupt was generated.\r
+  @retval EFI_UNSUPPORTED   The platform does not support the generation of soft timer interrupts.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.inf b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
new file mode 100644 (file)
index 0000000..add1d01
--- /dev/null
@@ -0,0 +1,42 @@
+## @file\r
+# Local APIC timer driver that provides Timer Arch protocol.\r
+#\r
+# Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2019, Citrix Systems, Inc.\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = XenTimerDxe\r
+  FILE_GUID                      = 52fe8196-f9de-4d07-b22f-51f77a0e7c41\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = TimerDriverInitialize\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UefiCpuPkg/UefiCpuPkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  BaseLib\r
+  DebugLib\r
+  UefiDriverEntryPoint\r
+  LocalApicLib\r
+\r
+[Sources]\r
+  XenTimerDxe.h\r
+  XenTimerDxe.c\r
+\r
+[Protocols]\r
+  gEfiCpuArchProtocolGuid       ## CONSUMES\r
+  gEfiTimerArchProtocolGuid     ## PRODUCES\r
+[Pcd]\r
+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock  ## CONSUMES\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid\r