]>
Commit | Line | Data |
---|---|---|
170ef2d9 GS |
1 | /** @file\r |
2 | Provide constructor and GetTick for Dxe 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/PcdLib.h>\r | |
18 | #include <Library/PciLib.h>\r | |
19 | #include <OvmfPlatforms.h>\r | |
20 | \r | |
21 | //\r | |
22 | // Power Management PCI Configuration Register fields\r | |
23 | //\r | |
24 | #define PMBA_RTE BIT0\r | |
25 | \r | |
26 | //\r | |
27 | // Offset in the Power Management Base Address to the ACPI Timer\r | |
28 | //\r | |
29 | #define ACPI_TIMER_OFFSET 0x8\r | |
30 | \r | |
31 | //\r | |
32 | // Cached ACPI Timer IO Address\r | |
33 | //\r | |
34 | STATIC UINT32 mAcpiTimerIoAddr;\r | |
35 | \r | |
36 | /**\r | |
37 | The constructor function caches the ACPI tick counter address\r | |
38 | \r | |
39 | At the time this constructor runs (DXE_CORE or later), ACPI IO space\r | |
40 | has already been enabled by either PlatformPei or by the "Base"\r | |
41 | instance of this library.\r | |
42 | In order to avoid querying the underlying platform type during each\r | |
43 | tick counter read operation, we cache the counter address during\r | |
44 | initialization of this instance of the Timer Library.\r | |
45 | \r | |
46 | @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r | |
47 | \r | |
48 | **/\r | |
49 | RETURN_STATUS\r | |
50 | EFIAPI\r | |
51 | AcpiTimerLibConstructor (\r | |
52 | VOID\r | |
53 | )\r | |
54 | {\r | |
55 | UINT16 HostBridgeDevId;\r | |
56 | UINTN Pmba;\r | |
57 | \r | |
58 | //\r | |
59 | // Query Host Bridge DID to determine platform type\r | |
60 | //\r | |
61 | HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);\r | |
62 | switch (HostBridgeDevId) {\r | |
63 | case INTEL_82441_DEVICE_ID:\r | |
da372167 | 64 | Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r |
170ef2d9 GS |
65 | break;\r |
66 | case INTEL_Q35_MCH_DEVICE_ID:\r | |
bc9d05d6 | 67 | Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r |
170ef2d9 GS |
68 | break;\r |
69 | default:\r | |
70 | DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r | |
71 | __FUNCTION__, HostBridgeDevId));\r | |
72 | ASSERT (FALSE);\r | |
73 | return RETURN_UNSUPPORTED;\r | |
74 | }\r | |
75 | \r | |
76 | mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r | |
77 | \r | |
78 | return RETURN_SUCCESS;\r | |
79 | }\r | |
80 | \r | |
81 | /**\r | |
82 | Internal function to read the current tick counter of ACPI.\r | |
83 | \r | |
84 | Read the current ACPI tick counter using the counter address cached\r | |
85 | by this instance's constructor.\r | |
86 | \r | |
87 | @return The tick counter read.\r | |
88 | \r | |
89 | **/\r | |
90 | UINT32\r | |
91 | InternalAcpiGetTimerTick (\r | |
92 | VOID\r | |
93 | )\r | |
94 | {\r | |
95 | //\r | |
96 | // Return the current ACPI timer value.\r | |
97 | //\r | |
98 | return IoRead32 (mAcpiTimerIoAddr);\r | |
99 | }\r |