]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
OvmfPkg/Library/AcpiTimerLib: Modified to support Xen HVM
[mirror_edk2.git] / OvmfPkg / Library / AcpiTimerLib / AcpiTimerLib.c
index 7f41a869d87e1778693e5642c5b972c754915aea..6c5cccc27305104d01508c1ac91d19ceb121c494 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
   ACPI Timer implements one instance of Timer Library.\r
 \r
-  Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r
+\r
   This program and the accompanying materials are\r
   licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include <Library/BaseLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/PciLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+//\r
+// PIIX4 Power Management Base Address\r
+//\r
+UINT32 mPmba = 0x401;\r
 \r
+#define PCI_BAR_IO             0x1\r
 #define ACPI_TIMER_FREQUENCY   3579545\r
 #define ACPI_TIMER_COUNT_SIZE  0x01000000\r
+#define ACPI_TIMER_OFFSET      0x8\r
 \r
 /**\r
   The constructor function enables ACPI IO space.\r
@@ -41,12 +51,21 @@ AcpiTimerLibConstructor (
   Device = 1;\r
   // Device = 7;\r
 \r
+  if (PciRead8 (PCI_LIB_ADDRESS (0,Device,3,0x80)) & 1) {\r
+    mPmba = PciRead32 (PCI_LIB_ADDRESS (0,Device,3,0x40));\r
+    ASSERT (mPmba & PCI_BAR_IO);\r
+    mPmba &= ~PCI_BAR_IO;\r
+  } else {\r
+    PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,3,0x40),\r
+                    (UINT32) ~0xfc0, mPmba);\r
+    PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x04), 0x01);\r
+  }\r
+\r
   //\r
   // ACPI Timer enable is in Bus 0, Device ?, Function 3\r
   //\r
-  PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x04), 0x01);\r
-  PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,3,0x40), (UINT32) ~0xfc0, 0x400);\r
-  PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x80), 0x01);  return RETURN_SUCCESS;\r
+  PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x80), 0x01);\r
+  return RETURN_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -63,7 +82,7 @@ InternalAcpiGetTimerTick (
   VOID\r
   )\r
 {\r
-  return IoRead32 (0x408);\r
+  return IoRead32 (mPmba + ACPI_TIMER_OFFSET);\r
 }\r
 \r
 /**\r