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