Re: [edk2] [RFC PATCH v1 6/8] OvmfPkg: Copy 8254TimerDxe driver from PcAtChipsetPkg

2019-04-03 Thread Laszlo Ersek
On 04/03/19 09:00, Hao Wu wrote:
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1496
> 
> This commit copies the exact 8254TimerDxe driver from PcAtChipsetPkg to
> OvmfPkg.
> 
> Cc: Jordan Justen 
> Cc: Laszlo Ersek 
> Cc: Ard Biesheuvel 
> Cc: David Woodhouse 
> Cc: Ray Ni 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Hao Wu 
> ---
>  OvmfPkg/8254TimerDxe/8254Timer.inf  |  48 +++
>  OvmfPkg/8254TimerDxe/Timer.h| 191 +
>  OvmfPkg/8254TimerDxe/Timer.c| 407 
>  OvmfPkg/8254TimerDxe/Timer.uni  |  22 ++
>  OvmfPkg/8254TimerDxe/TimerExtra.uni |  20 +
>  5 files changed, 688 insertions(+)

Reviewed-by: Laszlo Ersek 

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [RFC PATCH v1 6/8] OvmfPkg: Copy 8254TimerDxe driver from PcAtChipsetPkg

2019-04-03 Thread Hao Wu
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1496

This commit copies the exact 8254TimerDxe driver from PcAtChipsetPkg to
OvmfPkg.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Cc: David Woodhouse 
Cc: Ray Ni 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu 
---
 OvmfPkg/8254TimerDxe/8254Timer.inf  |  48 +++
 OvmfPkg/8254TimerDxe/Timer.h| 191 +
 OvmfPkg/8254TimerDxe/Timer.c| 407 
 OvmfPkg/8254TimerDxe/Timer.uni  |  22 ++
 OvmfPkg/8254TimerDxe/TimerExtra.uni |  20 +
 5 files changed, 688 insertions(+)

diff --git a/OvmfPkg/8254TimerDxe/8254Timer.inf 
b/OvmfPkg/8254TimerDxe/8254Timer.inf
new file mode 100644
index 00..46cf01de39
--- /dev/null
+++ b/OvmfPkg/8254TimerDxe/8254Timer.inf
@@ -0,0 +1,48 @@
+## @file
+# 8254 timer driver that provides Timer Arch protocol.
+#
+# Copyright (c) 2005 - 2018, Intel Corporation. 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]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = Timer
+  MODULE_UNI_FILE= Timer.uni
+  FILE_GUID  = f2765dec-6b41-11d5-8e71-00902707b35e
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+
+  ENTRY_POINT= TimerDriverInitialize
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelFrameworkPkg/IntelFrameworkPkg.dec
+
+[LibraryClasses]
+  UefiBootServicesTableLib
+  BaseLib
+  DebugLib
+  UefiDriverEntryPoint
+  IoLib
+
+[Sources]
+  Timer.h
+  Timer.c
+
+[Protocols]
+  gEfiCpuArchProtocolGuid   ## CONSUMES
+  gEfiLegacy8259ProtocolGuid## CONSUMES
+  gEfiTimerArchProtocolGuid ## PRODUCES
+
+[Depex]
+  gEfiCpuArchProtocolGuid AND gEfiLegacy8259ProtocolGuid
+[UserExtensions.TianoCore."ExtraFiles"]
+  TimerExtra.uni
diff --git a/OvmfPkg/8254TimerDxe/Timer.h b/OvmfPkg/8254TimerDxe/Timer.h
new file mode 100644
index 00..9d70e3aa19
--- /dev/null
+++ b/OvmfPkg/8254TimerDxe/Timer.h
@@ -0,0 +1,191 @@
+/** @file
+  Private data structures
+
+Copyright (c) 2005 - 2018, Intel Corporation. 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.
+**/
+
+#ifndef _TIMER_H_
+#define _TIMER_H_
+
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+//
+// The PCAT 8253/8254 has an input clock at 1.193182 MHz and Timer 0 is
+// initialized as a 16 bit free running counter that generates an 
interrupt(IRQ0)
+// each time the counter rolls over.
+//
+//   65536 counts
+//  * 1,000,000 uS/S = 54925.4 uS = 549254 * 100 ns
+//   1,193,182 Hz
+//
+
+//
+// The maximum tick duration for 8254 timer
+//
+#define MAX_TIMER_TICK_DURATION 549254
+//
+// The default timer tick duration is set to 10 ms = 10 100 ns units
+//
+#define DEFAULT_TIMER_TICK_DURATION 10
+#define TIMER_CONTROL_PORT  0x43
+#define TIMER0_COUNT_PORT   0x40
+
+//
+// Function Prototypes
+//
+/**
+  Initialize the Timer Architectural Protocol driver
+
+  @param ImageHandle ImageHandle of the loaded driver
+  @param SystemTable Pointer to the System Table
+
+  @retval EFI_SUCCESSTimer Architectural Protocol created
+  @retval EFI_OUT_OF_RESOURCES   Not enough resources available to initialize 
driver.
+  @retval EFI_DEVICE_ERROR   A device error occurred attempting to 
initialize the driver.
+
+**/
+EFI_STATUS
+EFIAPI
+TimerDriverInitialize (
+  IN EFI_HANDLEImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+;
+
+/**
+
+  This function adjusts the period of timer interrupts to the value specified
+  by TimerPeriod.  If the timer period is updated, then the selected timer
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
+  If an error occurs while attempting to update the timer period, then the
+  timer hardware will be put back in its state prior to this call, and
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt
+  is disabled.  This is not the same as disabling the CPU's interrupts.
+  Instead, it must either turn off the timer hardware,