hwacpi.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer
2 1.1.1.2.2.2 bouyer /******************************************************************************
3 1.1.1.2.2.2 bouyer *
4 1.1.1.2.2.2 bouyer * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
5 1.1.1.2.2.2 bouyer *
6 1.1.1.2.2.2 bouyer *****************************************************************************/
7 1.1.1.2.2.2 bouyer
8 1.1.1.2.2.2 bouyer /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.2.2 bouyer */
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #define __HWACPI_C__
46 1.1.1.2.2.2 bouyer
47 1.1.1.2.2.2 bouyer #include "acpi.h"
48 1.1.1.2.2.2 bouyer #include "accommon.h"
49 1.1.1.2.2.2 bouyer
50 1.1.1.2.2.2 bouyer
51 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_HARDWARE
52 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("hwacpi")
53 1.1.1.2.2.2 bouyer
54 1.1.1.2.2.2 bouyer
55 1.1.1.2.2.2 bouyer /******************************************************************************
56 1.1.1.2.2.2 bouyer *
57 1.1.1.2.2.2 bouyer * FUNCTION: AcpiHwSetMode
58 1.1.1.2.2.2 bouyer *
59 1.1.1.2.2.2 bouyer * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
60 1.1.1.2.2.2 bouyer *
61 1.1.1.2.2.2 bouyer * RETURN: Status
62 1.1.1.2.2.2 bouyer *
63 1.1.1.2.2.2 bouyer * DESCRIPTION: Transitions the system into the requested mode.
64 1.1.1.2.2.2 bouyer *
65 1.1.1.2.2.2 bouyer ******************************************************************************/
66 1.1.1.2.2.2 bouyer
67 1.1.1.2.2.2 bouyer ACPI_STATUS
68 1.1.1.2.2.2 bouyer AcpiHwSetMode (
69 1.1.1.2.2.2 bouyer UINT32 Mode)
70 1.1.1.2.2.2 bouyer {
71 1.1.1.2.2.2 bouyer
72 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
73 1.1.1.2.2.2 bouyer UINT32 Retry;
74 1.1.1.2.2.2 bouyer
75 1.1.1.2.2.2 bouyer
76 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (HwSetMode);
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer /*
79 1.1.1.2.2.2 bouyer * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
80 1.1.1.2.2.2 bouyer * system does not support mode transition.
81 1.1.1.2.2.2 bouyer */
82 1.1.1.2.2.2 bouyer if (!AcpiGbl_FADT.SmiCommand)
83 1.1.1.2.2.2 bouyer {
84 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "No SMI_CMD in FADT, mode transition failed"));
85 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
86 1.1.1.2.2.2 bouyer }
87 1.1.1.2.2.2 bouyer
88 1.1.1.2.2.2 bouyer /*
89 1.1.1.2.2.2 bouyer * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
90 1.1.1.2.2.2 bouyer * in FADT: If it is zero, enabling or disabling is not supported.
91 1.1.1.2.2.2 bouyer * As old systems may have used zero for mode transition,
92 1.1.1.2.2.2 bouyer * we make sure both the numbers are zero to determine these
93 1.1.1.2.2.2 bouyer * transitions are not supported.
94 1.1.1.2.2.2 bouyer */
95 1.1.1.2.2.2 bouyer if (!AcpiGbl_FADT.AcpiEnable && !AcpiGbl_FADT.AcpiDisable)
96 1.1.1.2.2.2 bouyer {
97 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
98 1.1.1.2.2.2 bouyer "No ACPI mode transition supported in this system "
99 1.1.1.2.2.2 bouyer "(enable/disable both zero)"));
100 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
101 1.1.1.2.2.2 bouyer }
102 1.1.1.2.2.2 bouyer
103 1.1.1.2.2.2 bouyer switch (Mode)
104 1.1.1.2.2.2 bouyer {
105 1.1.1.2.2.2 bouyer case ACPI_SYS_MODE_ACPI:
106 1.1.1.2.2.2 bouyer
107 1.1.1.2.2.2 bouyer /* BIOS should have disabled ALL fixed and GP events */
108 1.1.1.2.2.2 bouyer
109 1.1.1.2.2.2 bouyer Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
110 1.1.1.2.2.2 bouyer (UINT32) AcpiGbl_FADT.AcpiEnable, 8);
111 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
112 1.1.1.2.2.2 bouyer break;
113 1.1.1.2.2.2 bouyer
114 1.1.1.2.2.2 bouyer case ACPI_SYS_MODE_LEGACY:
115 1.1.1.2.2.2 bouyer
116 1.1.1.2.2.2 bouyer /*
117 1.1.1.2.2.2 bouyer * BIOS should clear all fixed status bits and restore fixed event
118 1.1.1.2.2.2 bouyer * enable bits to default
119 1.1.1.2.2.2 bouyer */
120 1.1.1.2.2.2 bouyer Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
121 1.1.1.2.2.2 bouyer (UINT32) AcpiGbl_FADT.AcpiDisable, 8);
122 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
123 1.1.1.2.2.2 bouyer "Attempting to enable Legacy (non-ACPI) mode\n"));
124 1.1.1.2.2.2 bouyer break;
125 1.1.1.2.2.2 bouyer
126 1.1.1.2.2.2 bouyer default:
127 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
128 1.1.1.2.2.2 bouyer }
129 1.1.1.2.2.2 bouyer
130 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
131 1.1.1.2.2.2 bouyer {
132 1.1.1.2.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status,
133 1.1.1.2.2.2 bouyer "Could not write ACPI mode change"));
134 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
135 1.1.1.2.2.2 bouyer }
136 1.1.1.2.2.2 bouyer
137 1.1.1.2.2.2 bouyer /*
138 1.1.1.2.2.2 bouyer * Some hardware takes a LONG time to switch modes. Give them 3 sec to
139 1.1.1.2.2.2 bouyer * do so, but allow faster systems to proceed more quickly.
140 1.1.1.2.2.2 bouyer */
141 1.1.1.2.2.2 bouyer Retry = 3000;
142 1.1.1.2.2.2 bouyer while (Retry)
143 1.1.1.2.2.2 bouyer {
144 1.1.1.2.2.2 bouyer if (AcpiHwGetMode() == Mode)
145 1.1.1.2.2.2 bouyer {
146 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n",
147 1.1.1.2.2.2 bouyer Mode));
148 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
149 1.1.1.2.2.2 bouyer }
150 1.1.1.2.2.2 bouyer AcpiOsStall(1000);
151 1.1.1.2.2.2 bouyer Retry--;
152 1.1.1.2.2.2 bouyer }
153 1.1.1.2.2.2 bouyer
154 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Hardware did not change modes"));
155 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
156 1.1.1.2.2.2 bouyer }
157 1.1.1.2.2.2 bouyer
158 1.1.1.2.2.2 bouyer
159 1.1.1.2.2.2 bouyer /*******************************************************************************
160 1.1.1.2.2.2 bouyer *
161 1.1.1.2.2.2 bouyer * FUNCTION: AcpiHwGetMode
162 1.1.1.2.2.2 bouyer *
163 1.1.1.2.2.2 bouyer * PARAMETERS: none
164 1.1.1.2.2.2 bouyer *
165 1.1.1.2.2.2 bouyer * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
166 1.1.1.2.2.2 bouyer *
167 1.1.1.2.2.2 bouyer * DESCRIPTION: Return current operating state of system. Determined by
168 1.1.1.2.2.2 bouyer * querying the SCI_EN bit.
169 1.1.1.2.2.2 bouyer *
170 1.1.1.2.2.2 bouyer ******************************************************************************/
171 1.1.1.2.2.2 bouyer
172 1.1.1.2.2.2 bouyer UINT32
173 1.1.1.2.2.2 bouyer AcpiHwGetMode (
174 1.1.1.2.2.2 bouyer void)
175 1.1.1.2.2.2 bouyer {
176 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
177 1.1.1.2.2.2 bouyer UINT32 Value;
178 1.1.1.2.2.2 bouyer
179 1.1.1.2.2.2 bouyer
180 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (HwGetMode);
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer
183 1.1.1.2.2.2 bouyer /*
184 1.1.1.2.2.2 bouyer * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
185 1.1.1.2.2.2 bouyer * system does not support mode transition.
186 1.1.1.2.2.2 bouyer */
187 1.1.1.2.2.2 bouyer if (!AcpiGbl_FADT.SmiCommand)
188 1.1.1.2.2.2 bouyer {
189 1.1.1.2.2.2 bouyer return_UINT32 (ACPI_SYS_MODE_ACPI);
190 1.1.1.2.2.2 bouyer }
191 1.1.1.2.2.2 bouyer
192 1.1.1.2.2.2 bouyer Status = AcpiReadBitRegister (ACPI_BITREG_SCI_ENABLE, &Value);
193 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
194 1.1.1.2.2.2 bouyer {
195 1.1.1.2.2.2 bouyer return_UINT32 (ACPI_SYS_MODE_LEGACY);
196 1.1.1.2.2.2 bouyer }
197 1.1.1.2.2.2 bouyer
198 1.1.1.2.2.2 bouyer if (Value)
199 1.1.1.2.2.2 bouyer {
200 1.1.1.2.2.2 bouyer return_UINT32 (ACPI_SYS_MODE_ACPI);
201 1.1.1.2.2.2 bouyer }
202 1.1.1.2.2.2 bouyer else
203 1.1.1.2.2.2 bouyer {
204 1.1.1.2.2.2 bouyer return_UINT32 (ACPI_SYS_MODE_LEGACY);
205 1.1.1.2.2.2 bouyer }
206 1.1.1.2.2.2 bouyer }
207