]>
Commit | Line | Data |
---|---|---|
170ef2d9 GS |
1 | /** @file\r |
2 | Provide constructor and GetTick for Base instance of ACPI Timer Library\r | |
3 | \r | |
4 | Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r | |
5 | \r | |
6 | This program and the accompanying materials are licensed and made\r | |
7 | available under the terms and conditions of the BSD License which\r | |
8 | accompanies this distribution. The full text of the license may\r | |
9 | be found at http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | **/\r | |
14 | \r | |
15 | #include <Library/DebugLib.h>\r | |
16 | #include <Library/IoLib.h>\r | |
17 | #include <Library/PciLib.h>\r | |
18 | #include <OvmfPlatforms.h>\r | |
19 | \r | |
170ef2d9 GS |
20 | //\r |
21 | // Cached ACPI Timer IO Address\r | |
22 | //\r | |
23 | STATIC UINT32 mAcpiTimerIoAddr;\r | |
24 | \r | |
25 | /**\r | |
f122712b GS |
26 | The constructor function caches the ACPI tick counter address, and,\r |
27 | if necessary, enables ACPI IO space.\r | |
170ef2d9 GS |
28 | \r |
29 | @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r | |
30 | \r | |
31 | **/\r | |
32 | RETURN_STATUS\r | |
33 | EFIAPI\r | |
34 | AcpiTimerLibConstructor (\r | |
35 | VOID\r | |
36 | )\r | |
37 | {\r | |
38 | UINT16 HostBridgeDevId;\r | |
39 | UINTN Pmba;\r | |
1466b76f LE |
40 | UINT32 PmbaAndVal;\r |
41 | UINT32 PmbaOrVal;\r | |
e2ab3f81 GS |
42 | UINTN AcpiCtlReg;\r |
43 | UINT8 AcpiEnBit;\r | |
170ef2d9 GS |
44 | \r |
45 | //\r | |
46 | // Query Host Bridge DID to determine platform type\r | |
47 | //\r | |
48 | HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r | |
49 | switch (HostBridgeDevId) {\r | |
50 | case INTEL_82441_DEVICE_ID:\r | |
da372167 | 51 | Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r |
1466b76f LE |
52 | PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;\r |
53 | PmbaOrVal = PIIX4_PMBA_VALUE;\r | |
da372167 LE |
54 | AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);\r |
55 | AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;\r | |
170ef2d9 GS |
56 | break;\r |
57 | case INTEL_Q35_MCH_DEVICE_ID:\r | |
bc9d05d6 | 58 | Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r |
1466b76f LE |
59 | PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;\r |
60 | PmbaOrVal = ICH9_PMBASE_VALUE;\r | |
bc9d05d6 LE |
61 | AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);\r |
62 | AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;\r | |
170ef2d9 GS |
63 | break;\r |
64 | default:\r | |
65 | DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r | |
66 | __FUNCTION__, HostBridgeDevId));\r | |
67 | ASSERT (FALSE);\r | |
68 | return RETURN_UNSUPPORTED;\r | |
69 | }\r | |
70 | \r | |
f122712b GS |
71 | //\r |
72 | // Check to see if the Power Management Base Address is already enabled\r | |
73 | //\r | |
e2ab3f81 | 74 | if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {\r |
f122712b GS |
75 | //\r |
76 | // If the Power Management Base Address is not programmed,\r | |
b2f4da39 | 77 | // then program it now.\r |
f122712b | 78 | //\r |
1466b76f | 79 | PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);\r |
f122712b GS |
80 | \r |
81 | //\r | |
e2ab3f81 | 82 | // Enable PMBA I/O port decodes\r |
f122712b | 83 | //\r |
e2ab3f81 | 84 | PciOr8 (AcpiCtlReg, AcpiEnBit);\r |
f122712b GS |
85 | }\r |
86 | \r | |
ac759060 | 87 | mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r |
170ef2d9 GS |
88 | return RETURN_SUCCESS;\r |
89 | }\r | |
90 | \r | |
91 | /**\r | |
92 | Internal function to read the current tick counter of ACPI.\r | |
93 | \r | |
94 | Read the current ACPI tick counter using the counter address cached\r | |
95 | by this instance's constructor.\r | |
96 | \r | |
97 | @return The tick counter read.\r | |
98 | \r | |
99 | **/\r | |
100 | UINT32\r | |
101 | InternalAcpiGetTimerTick (\r | |
102 | VOID\r | |
103 | )\r | |
104 | {\r | |
105 | //\r | |
106 | // Return the current ACPI timer value.\r | |
107 | //\r | |
108 | return IoRead32 (mAcpiTimerIoAddr);\r | |
109 | }\r |