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