Re: [edk2-devel] [PATCH v3 31/35] OvmfPkg/OvmfXen: Introduce XenTimerDxe

2019-07-10 Thread Laszlo Ersek
On 07/04/19 16:42, Anthony PERARD wrote:
> "PcAtChipsetPkg/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 "PcAtChipsetPkg/8254TimerDxe" implementation.
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
> Signed-off-by: Anthony PERARD 
> ---
> 
> Notes:
> v3:
> - rebased, SPDX, copyright

(1) Please replace both occurrences of "PcAtChipsetPkg" in the commit
message with "OvmfPkg". (You rebased the DSC/FDF files correctly, but
missed the commit message.)

With that:

Acked-by: Laszlo Ersek 

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43473): https://edk2.groups.io/g/devel/message/43473
Mute This Topic: https://groups.io/mt/32308717/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 31/35] OvmfPkg/OvmfXen: Introduce XenTimerDxe

2019-07-04 Thread Anthony PERARD
"PcAtChipsetPkg/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 "PcAtChipsetPkg/8254TimerDxe" implementation.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- rebased, SPDX, copyright

v2:
- Use InitializeApicTimer instead of WriteLocalApicReg
- rework comments (remove many that don't apply)
- remove unused includes, and libs
- have a macro to the timervector.
- cleanup, copyright
- rework calculation of TimerCount, value to be use by the APIC timer
- check for overflow of TimerPeriod, with the apic timer, the period can
  be up to about 42s on Xen (or even higher by changing the DivideValue).

 OvmfPkg/OvmfXen.dsc |   3 +-
 OvmfPkg/OvmfXen.fdf |   3 +-
 OvmfPkg/XenTimerDxe/XenTimerDxe.inf |  42 
 OvmfPkg/XenTimerDxe/XenTimerDxe.h   | 177 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.c   | 355 
 5 files changed, 576 insertions(+), 4 deletions(-)
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.inf
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.h
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index bc6b6602c6..1ecae3fb45 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -547,10 +547,9 @@ [Components]
   MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

 

   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

-  OvmfPkg/8259InterruptControllerDxe/8259.inf

+  OvmfPkg/XenTimerDxe/XenTimerDxe.inf

   UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf

   UefiCpuPkg/CpuDxe/CpuDxe.inf

-  OvmfPkg/8254TimerDxe/8254Timer.inf

   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf

   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf

   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 49997fee9b..fa0830a324 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -298,10 +298,9 @@ [FV.DXEFV]
 INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

 INF  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

 INF  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

-INF  OvmfPkg/8259InterruptControllerDxe/8259.inf

+INF  OvmfPkg/XenTimerDxe/XenTimerDxe.inf

 INF  UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf

 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf

-INF  OvmfPkg/8254TimerDxe/8254Timer.inf

 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf

 INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf

 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf

diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.inf 
b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
new file mode 100644
index 00..add1d01bbf
--- /dev/null
+++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
@@ -0,0 +1,42 @@
+## @file

+# Local APIC timer driver that provides Timer Arch protocol.

+#

+# Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.

+# Copyright (c) 2019, Citrix Systems, Inc.

+#

+# SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION= 0x00010005

+  BASE_NAME  = XenTimerDxe

+  FILE_GUID  = 52fe8196-f9de-4d07-b22f-51f77a0e7c41

+  MODULE_TYPE= DXE_DRIVER

+  VERSION_STRING = 1.0

+

+  ENTRY_POINT= TimerDriverInitialize

+

+[Packages]

+  MdePkg/MdePkg.dec

+  UefiCpuPkg/UefiCpuPkg.dec

+  OvmfPkg/OvmfPkg.dec

+

+[LibraryClasses]

+  UefiBootServicesTableLib

+  BaseLib

+  DebugLib

+  UefiDriverEntryPoint

+  LocalApicLib

+

+[Sources]

+  XenTimerDxe.h

+  XenTimerDxe.c

+

+[Protocols]

+  gEfiCpuArchProtocolGuid   ## CONSUMES

+  gEfiTimerArchProtocolGuid ## PRODUCES

+[Pcd]

+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock  ## CONSUMES

+[Depex]

+  gEfiCpuArchProtocolGuid

diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.h 
b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
new file mode 100644
index 00..e0a3d95fd0
--- /dev/null
+++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
@@ -0,0 +1,177 @@
+/** @file

+  Private data structures

+

+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.

+Copyright (c) 2019, Citrix Systems, Inc.

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#ifndef _TIMER_H_

+#define _TIMER_H_

+

+#include 

+

+#include 

+#include 

+

+#include 

+

+#include 

+#include 

+#include 

+#include 

+#include 

+

+// The default timer tick duration is set to 10 ms = 10 100 ns units

+//

+#define DEFAULT_TIMER_TICK_DURATION 10

+

+//

+// The Timer Vector use for interrupt

+//

+#define LOCAL_APIC_TIMER_VECTOR 32

+

+//

+// Function Prototypes

+//

+/**

+  Initialize the Timer