1 | /** @file
|
---|
2 | Provide constructor and GetTick for BaseRom instance of ACPI Timer Library
|
---|
3 |
|
---|
4 | Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
|
---|
5 | Copyright (c) 2011, Andrei Warkentin <[email protected]>
|
---|
6 |
|
---|
7 | This program and the accompanying materials are licensed and made
|
---|
8 | available under the terms and conditions of the BSD License which
|
---|
9 | accompanies this distribution. The full text of the license may
|
---|
10 | be found at http://opensource.org/licenses/bsd-license.php
|
---|
11 |
|
---|
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
14 | **/
|
---|
15 |
|
---|
16 | #include <Library/DebugLib.h>
|
---|
17 | #include <Library/IoLib.h>
|
---|
18 | #include <Library/PciLib.h>
|
---|
19 | #include <OvmfPlatforms.h>
|
---|
20 |
|
---|
21 | /**
|
---|
22 | The constructor function enables ACPI IO space.
|
---|
23 |
|
---|
24 | If ACPI I/O space not enabled, this function will enable it.
|
---|
25 | It will always return RETURN_SUCCESS.
|
---|
26 |
|
---|
27 | @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
|
---|
28 |
|
---|
29 | **/
|
---|
30 | RETURN_STATUS
|
---|
31 | EFIAPI
|
---|
32 | AcpiTimerLibConstructor (
|
---|
33 | VOID
|
---|
34 | )
|
---|
35 | {
|
---|
36 | UINT16 HostBridgeDevId;
|
---|
37 | UINTN Pmba;
|
---|
38 | UINT32 PmbaAndVal;
|
---|
39 | UINT32 PmbaOrVal;
|
---|
40 | UINTN AcpiCtlReg;
|
---|
41 | UINT8 AcpiEnBit;
|
---|
42 |
|
---|
43 | //
|
---|
44 | // Query Host Bridge DID to determine platform type
|
---|
45 | //
|
---|
46 | HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
|
---|
47 | switch (HostBridgeDevId) {
|
---|
48 | case INTEL_82441_DEVICE_ID:
|
---|
49 | #ifdef VBOX
|
---|
50 | // HACK ALERT! There is no host bridge device in the PCIe chipset, and the same PIIX4 PM device is used.
|
---|
51 | // But there might be some other device at 0:0.0.
|
---|
52 | default:
|
---|
53 | #endif
|
---|
54 | Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
|
---|
55 | PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
|
---|
56 | PmbaOrVal = PIIX4_PMBA_VALUE;
|
---|
57 | AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);
|
---|
58 | AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;
|
---|
59 | break;
|
---|
60 | case INTEL_Q35_MCH_DEVICE_ID:
|
---|
61 | Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
|
---|
62 | PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;
|
---|
63 | PmbaOrVal = ICH9_PMBASE_VALUE;
|
---|
64 | AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);
|
---|
65 | AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
|
---|
66 | break;
|
---|
67 | #ifndef VBOX
|
---|
68 | default:
|
---|
69 | DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
|
---|
70 | __FUNCTION__, HostBridgeDevId));
|
---|
71 | ASSERT (FALSE);
|
---|
72 | return RETURN_UNSUPPORTED;
|
---|
73 | #endif
|
---|
74 | }
|
---|
75 |
|
---|
76 | //
|
---|
77 | // Check to see if the Power Management Base Address is already enabled
|
---|
78 | //
|
---|
79 | if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
|
---|
80 | //
|
---|
81 | // If the Power Management Base Address is not programmed,
|
---|
82 | // then program it now.
|
---|
83 | //
|
---|
84 | PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
|
---|
85 |
|
---|
86 | //
|
---|
87 | // Enable PMBA I/O port decodes
|
---|
88 | //
|
---|
89 | PciOr8 (AcpiCtlReg, AcpiEnBit);
|
---|
90 | }
|
---|
91 |
|
---|
92 | return RETURN_SUCCESS;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | Internal function to read the current tick counter of ACPI.
|
---|
97 |
|
---|
98 | Dynamically compute the address of the ACPI tick counter based on the
|
---|
99 | properties of the underlying platform, to avoid relying on global variables.
|
---|
100 |
|
---|
101 | @return The tick counter read.
|
---|
102 |
|
---|
103 | **/
|
---|
104 | UINT32
|
---|
105 | InternalAcpiGetTimerTick (
|
---|
106 | VOID
|
---|
107 | )
|
---|
108 | {
|
---|
109 | UINT16 HostBridgeDevId;
|
---|
110 | UINTN Pmba;
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Query Host Bridge DID to determine platform type
|
---|
114 | //
|
---|
115 | HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
|
---|
116 | switch (HostBridgeDevId) {
|
---|
117 | case INTEL_82441_DEVICE_ID:
|
---|
118 | Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
|
---|
119 | break;
|
---|
120 | case INTEL_Q35_MCH_DEVICE_ID:
|
---|
121 | Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
|
---|
122 | break;
|
---|
123 | default:
|
---|
124 | DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
|
---|
125 | __FUNCTION__, HostBridgeDevId));
|
---|
126 | ASSERT (FALSE);
|
---|
127 | return 0;
|
---|
128 | }
|
---|
129 |
|
---|
130 | //
|
---|
131 | // Read PMBA to read and return the current ACPI timer value.
|
---|
132 | //
|
---|
133 | return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);
|
---|
134 | }
|
---|