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