hwxface.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: hwxface - Public ACPICA hardware interfaces
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 #include "acpi.h"
46 1.1.1.2.2.2 bouyer #include "accommon.h"
47 1.1.1.2.2.2 bouyer #include "acnamesp.h"
48 1.1.1.2.2.2 bouyer
49 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_HARDWARE
50 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("hwxface")
51 1.1.1.2.2.2 bouyer
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer /******************************************************************************
54 1.1.1.2.2.2 bouyer *
55 1.1.1.2.2.2 bouyer * FUNCTION: AcpiReset
56 1.1.1.2.2.2 bouyer *
57 1.1.1.2.2.2 bouyer * PARAMETERS: None
58 1.1.1.2.2.2 bouyer *
59 1.1.1.2.2.2 bouyer * RETURN: Status
60 1.1.1.2.2.2 bouyer *
61 1.1.1.2.2.2 bouyer * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
62 1.1.1.2.2.2 bouyer * support reset register in PCI config space, this must be
63 1.1.1.2.2.2 bouyer * handled separately.
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 AcpiReset (
69 1.1.1.2.2.2 bouyer void)
70 1.1.1.2.2.2 bouyer {
71 1.1.1.2.2.2 bouyer ACPI_GENERIC_ADDRESS *ResetReg;
72 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
73 1.1.1.2.2.2 bouyer
74 1.1.1.2.2.2 bouyer
75 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiReset);
76 1.1.1.2.2.2 bouyer
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer ResetReg = &AcpiGbl_FADT.ResetRegister;
79 1.1.1.2.2.2 bouyer
80 1.1.1.2.2.2 bouyer /* Check if the reset register is supported */
81 1.1.1.2.2.2 bouyer
82 1.1.1.2.2.2 bouyer if (!(AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) ||
83 1.1.1.2.2.2 bouyer !ResetReg->Address)
84 1.1.1.2.2.2 bouyer {
85 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NOT_EXIST);
86 1.1.1.2.2.2 bouyer }
87 1.1.1.2.2.2 bouyer
88 1.1.1.2.2.2 bouyer if (ResetReg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
89 1.1.1.2.2.2 bouyer {
90 1.1.1.2.2.2 bouyer /*
91 1.1.1.2.2.2 bouyer * For I/O space, write directly to the OSL. This bypasses the port
92 1.1.1.2.2.2 bouyer * validation mechanism, which may block a valid write to the reset
93 1.1.1.2.2.2 bouyer * register.
94 1.1.1.2.2.2 bouyer */
95 1.1.1.2.2.2 bouyer Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ResetReg->Address,
96 1.1.1.2.2.2 bouyer AcpiGbl_FADT.ResetValue, ResetReg->BitWidth);
97 1.1.1.2.2.2 bouyer }
98 1.1.1.2.2.2 bouyer else
99 1.1.1.2.2.2 bouyer {
100 1.1.1.2.2.2 bouyer /* Write the reset value to the reset register */
101 1.1.1.2.2.2 bouyer
102 1.1.1.2.2.2 bouyer Status = AcpiHwWrite (AcpiGbl_FADT.ResetValue, ResetReg);
103 1.1.1.2.2.2 bouyer }
104 1.1.1.2.2.2 bouyer
105 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
106 1.1.1.2.2.2 bouyer }
107 1.1.1.2.2.2 bouyer
108 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiReset)
109 1.1.1.2.2.2 bouyer
110 1.1.1.2.2.2 bouyer
111 1.1.1.2.2.2 bouyer /******************************************************************************
112 1.1.1.2.2.2 bouyer *
113 1.1.1.2.2.2 bouyer * FUNCTION: AcpiRead
114 1.1.1.2.2.2 bouyer *
115 1.1.1.2.2.2 bouyer * PARAMETERS: Value - Where the value is returned
116 1.1.1.2.2.2 bouyer * Reg - GAS register structure
117 1.1.1.2.2.2 bouyer *
118 1.1.1.2.2.2 bouyer * RETURN: Status
119 1.1.1.2.2.2 bouyer *
120 1.1.1.2.2.2 bouyer * DESCRIPTION: Read from either memory or IO space.
121 1.1.1.2.2.2 bouyer *
122 1.1.1.2.2.2 bouyer * LIMITATIONS: <These limitations also apply to AcpiWrite>
123 1.1.1.2.2.2 bouyer * BitWidth must be exactly 8, 16, 32, or 64.
124 1.1.1.2.2.2 bouyer * SpaceID must be SystemMemory or SystemIO.
125 1.1.1.2.2.2 bouyer * BitOffset and AccessWidth are currently ignored, as there has
126 1.1.1.2.2.2 bouyer * not been a need to implement these.
127 1.1.1.2.2.2 bouyer *
128 1.1.1.2.2.2 bouyer ******************************************************************************/
129 1.1.1.2.2.2 bouyer
130 1.1.1.2.2.2 bouyer ACPI_STATUS
131 1.1.1.2.2.2 bouyer AcpiRead (
132 1.1.1.2.2.2 bouyer UINT64 *ReturnValue,
133 1.1.1.2.2.2 bouyer ACPI_GENERIC_ADDRESS *Reg)
134 1.1.1.2.2.2 bouyer {
135 1.1.1.2.2.2 bouyer UINT32 Value;
136 1.1.1.2.2.2 bouyer UINT32 Width;
137 1.1.1.2.2.2 bouyer UINT64 Address;
138 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
139 1.1.1.2.2.2 bouyer
140 1.1.1.2.2.2 bouyer
141 1.1.1.2.2.2 bouyer ACPI_FUNCTION_NAME (AcpiRead);
142 1.1.1.2.2.2 bouyer
143 1.1.1.2.2.2 bouyer
144 1.1.1.2.2.2 bouyer if (!ReturnValue)
145 1.1.1.2.2.2 bouyer {
146 1.1.1.2.2.2 bouyer return (AE_BAD_PARAMETER);
147 1.1.1.2.2.2 bouyer }
148 1.1.1.2.2.2 bouyer
149 1.1.1.2.2.2 bouyer /* Validate contents of the GAS register. Allow 64-bit transfers */
150 1.1.1.2.2.2 bouyer
151 1.1.1.2.2.2 bouyer Status = AcpiHwValidateRegister (Reg, 64, &Address);
152 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
153 1.1.1.2.2.2 bouyer {
154 1.1.1.2.2.2 bouyer return (Status);
155 1.1.1.2.2.2 bouyer }
156 1.1.1.2.2.2 bouyer
157 1.1.1.2.2.2 bouyer Width = Reg->BitWidth;
158 1.1.1.2.2.2 bouyer if (Width == 64)
159 1.1.1.2.2.2 bouyer {
160 1.1.1.2.2.2 bouyer Width = 32; /* Break into two 32-bit transfers */
161 1.1.1.2.2.2 bouyer }
162 1.1.1.2.2.2 bouyer
163 1.1.1.2.2.2 bouyer /* Initialize entire 64-bit return value to zero */
164 1.1.1.2.2.2 bouyer
165 1.1.1.2.2.2 bouyer *ReturnValue = 0;
166 1.1.1.2.2.2 bouyer Value = 0;
167 1.1.1.2.2.2 bouyer
168 1.1.1.2.2.2 bouyer /*
169 1.1.1.2.2.2 bouyer * Two address spaces supported: Memory or IO. PCI_Config is
170 1.1.1.2.2.2 bouyer * not supported here because the GAS structure is insufficient
171 1.1.1.2.2.2 bouyer */
172 1.1.1.2.2.2 bouyer if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
173 1.1.1.2.2.2 bouyer {
174 1.1.1.2.2.2 bouyer Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
175 1.1.1.2.2.2 bouyer Address, &Value, Width);
176 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
177 1.1.1.2.2.2 bouyer {
178 1.1.1.2.2.2 bouyer return (Status);
179 1.1.1.2.2.2 bouyer }
180 1.1.1.2.2.2 bouyer *ReturnValue = Value;
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer if (Reg->BitWidth == 64)
183 1.1.1.2.2.2 bouyer {
184 1.1.1.2.2.2 bouyer /* Read the top 32 bits */
185 1.1.1.2.2.2 bouyer
186 1.1.1.2.2.2 bouyer Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
187 1.1.1.2.2.2 bouyer (Address + 4), &Value, 32);
188 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
189 1.1.1.2.2.2 bouyer {
190 1.1.1.2.2.2 bouyer return (Status);
191 1.1.1.2.2.2 bouyer }
192 1.1.1.2.2.2 bouyer *ReturnValue |= ((UINT64) Value << 32);
193 1.1.1.2.2.2 bouyer }
194 1.1.1.2.2.2 bouyer }
195 1.1.1.2.2.2 bouyer else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
196 1.1.1.2.2.2 bouyer {
197 1.1.1.2.2.2 bouyer Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
198 1.1.1.2.2.2 bouyer Address, &Value, Width);
199 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
200 1.1.1.2.2.2 bouyer {
201 1.1.1.2.2.2 bouyer return (Status);
202 1.1.1.2.2.2 bouyer }
203 1.1.1.2.2.2 bouyer *ReturnValue = Value;
204 1.1.1.2.2.2 bouyer
205 1.1.1.2.2.2 bouyer if (Reg->BitWidth == 64)
206 1.1.1.2.2.2 bouyer {
207 1.1.1.2.2.2 bouyer /* Read the top 32 bits */
208 1.1.1.2.2.2 bouyer
209 1.1.1.2.2.2 bouyer Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
210 1.1.1.2.2.2 bouyer (Address + 4), &Value, 32);
211 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
212 1.1.1.2.2.2 bouyer {
213 1.1.1.2.2.2 bouyer return (Status);
214 1.1.1.2.2.2 bouyer }
215 1.1.1.2.2.2 bouyer *ReturnValue |= ((UINT64) Value << 32);
216 1.1.1.2.2.2 bouyer }
217 1.1.1.2.2.2 bouyer }
218 1.1.1.2.2.2 bouyer
219 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_IO,
220 1.1.1.2.2.2 bouyer "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
221 1.1.1.2.2.2 bouyer ACPI_FORMAT_UINT64 (*ReturnValue), Reg->BitWidth,
222 1.1.1.2.2.2 bouyer ACPI_FORMAT_UINT64 (Address),
223 1.1.1.2.2.2 bouyer AcpiUtGetRegionName (Reg->SpaceId)));
224 1.1.1.2.2.2 bouyer
225 1.1.1.2.2.2 bouyer return (Status);
226 1.1.1.2.2.2 bouyer }
227 1.1.1.2.2.2 bouyer
228 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiRead)
229 1.1.1.2.2.2 bouyer
230 1.1.1.2.2.2 bouyer
231 1.1.1.2.2.2 bouyer /******************************************************************************
232 1.1.1.2.2.2 bouyer *
233 1.1.1.2.2.2 bouyer * FUNCTION: AcpiWrite
234 1.1.1.2.2.2 bouyer *
235 1.1.1.2.2.2 bouyer * PARAMETERS: Value - Value to be written
236 1.1.1.2.2.2 bouyer * Reg - GAS register structure
237 1.1.1.2.2.2 bouyer *
238 1.1.1.2.2.2 bouyer * RETURN: Status
239 1.1.1.2.2.2 bouyer *
240 1.1.1.2.2.2 bouyer * DESCRIPTION: Write to either memory or IO space.
241 1.1.1.2.2.2 bouyer *
242 1.1.1.2.2.2 bouyer ******************************************************************************/
243 1.1.1.2.2.2 bouyer
244 1.1.1.2.2.2 bouyer ACPI_STATUS
245 1.1.1.2.2.2 bouyer AcpiWrite (
246 1.1.1.2.2.2 bouyer UINT64 Value,
247 1.1.1.2.2.2 bouyer ACPI_GENERIC_ADDRESS *Reg)
248 1.1.1.2.2.2 bouyer {
249 1.1.1.2.2.2 bouyer UINT32 Width;
250 1.1.1.2.2.2 bouyer UINT64 Address;
251 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
252 1.1.1.2.2.2 bouyer
253 1.1.1.2.2.2 bouyer
254 1.1.1.2.2.2 bouyer ACPI_FUNCTION_NAME (AcpiWrite);
255 1.1.1.2.2.2 bouyer
256 1.1.1.2.2.2 bouyer
257 1.1.1.2.2.2 bouyer /* Validate contents of the GAS register. Allow 64-bit transfers */
258 1.1.1.2.2.2 bouyer
259 1.1.1.2.2.2 bouyer Status = AcpiHwValidateRegister (Reg, 64, &Address);
260 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
261 1.1.1.2.2.2 bouyer {
262 1.1.1.2.2.2 bouyer return (Status);
263 1.1.1.2.2.2 bouyer }
264 1.1.1.2.2.2 bouyer
265 1.1.1.2.2.2 bouyer Width = Reg->BitWidth;
266 1.1.1.2.2.2 bouyer if (Width == 64)
267 1.1.1.2.2.2 bouyer {
268 1.1.1.2.2.2 bouyer Width = 32; /* Break into two 32-bit transfers */
269 1.1.1.2.2.2 bouyer }
270 1.1.1.2.2.2 bouyer
271 1.1.1.2.2.2 bouyer /*
272 1.1.1.2.2.2 bouyer * Two address spaces supported: Memory or IO. PCI_Config is
273 1.1.1.2.2.2 bouyer * not supported here because the GAS structure is insufficient
274 1.1.1.2.2.2 bouyer */
275 1.1.1.2.2.2 bouyer if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
276 1.1.1.2.2.2 bouyer {
277 1.1.1.2.2.2 bouyer Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
278 1.1.1.2.2.2 bouyer Address, ACPI_LODWORD (Value), Width);
279 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
280 1.1.1.2.2.2 bouyer {
281 1.1.1.2.2.2 bouyer return (Status);
282 1.1.1.2.2.2 bouyer }
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer if (Reg->BitWidth == 64)
285 1.1.1.2.2.2 bouyer {
286 1.1.1.2.2.2 bouyer Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
287 1.1.1.2.2.2 bouyer (Address + 4), ACPI_HIDWORD (Value), 32);
288 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
289 1.1.1.2.2.2 bouyer {
290 1.1.1.2.2.2 bouyer return (Status);
291 1.1.1.2.2.2 bouyer }
292 1.1.1.2.2.2 bouyer }
293 1.1.1.2.2.2 bouyer }
294 1.1.1.2.2.2 bouyer else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
295 1.1.1.2.2.2 bouyer {
296 1.1.1.2.2.2 bouyer Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
297 1.1.1.2.2.2 bouyer Address, ACPI_LODWORD (Value), Width);
298 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
299 1.1.1.2.2.2 bouyer {
300 1.1.1.2.2.2 bouyer return (Status);
301 1.1.1.2.2.2 bouyer }
302 1.1.1.2.2.2 bouyer
303 1.1.1.2.2.2 bouyer if (Reg->BitWidth == 64)
304 1.1.1.2.2.2 bouyer {
305 1.1.1.2.2.2 bouyer Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
306 1.1.1.2.2.2 bouyer (Address + 4), ACPI_HIDWORD (Value), 32);
307 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
308 1.1.1.2.2.2 bouyer {
309 1.1.1.2.2.2 bouyer return (Status);
310 1.1.1.2.2.2 bouyer }
311 1.1.1.2.2.2 bouyer }
312 1.1.1.2.2.2 bouyer }
313 1.1.1.2.2.2 bouyer
314 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_IO,
315 1.1.1.2.2.2 bouyer "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
316 1.1.1.2.2.2 bouyer ACPI_FORMAT_UINT64 (Value), Reg->BitWidth,
317 1.1.1.2.2.2 bouyer ACPI_FORMAT_UINT64 (Address),
318 1.1.1.2.2.2 bouyer AcpiUtGetRegionName (Reg->SpaceId)));
319 1.1.1.2.2.2 bouyer
320 1.1.1.2.2.2 bouyer return (Status);
321 1.1.1.2.2.2 bouyer }
322 1.1.1.2.2.2 bouyer
323 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiWrite)
324 1.1.1.2.2.2 bouyer
325 1.1.1.2.2.2 bouyer
326 1.1.1.2.2.2 bouyer /*******************************************************************************
327 1.1.1.2.2.2 bouyer *
328 1.1.1.2.2.2 bouyer * FUNCTION: AcpiReadBitRegister
329 1.1.1.2.2.2 bouyer *
330 1.1.1.2.2.2 bouyer * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
331 1.1.1.2.2.2 bouyer * ReturnValue - Value that was read from the register,
332 1.1.1.2.2.2 bouyer * normalized to bit position zero.
333 1.1.1.2.2.2 bouyer *
334 1.1.1.2.2.2 bouyer * RETURN: Status and the value read from the specified Register. Value
335 1.1.1.2.2.2 bouyer * returned is normalized to bit0 (is shifted all the way right)
336 1.1.1.2.2.2 bouyer *
337 1.1.1.2.2.2 bouyer * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
338 1.1.1.2.2.2 bouyer *
339 1.1.1.2.2.2 bouyer * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
340 1.1.1.2.2.2 bouyer * PM2 Control.
341 1.1.1.2.2.2 bouyer *
342 1.1.1.2.2.2 bouyer * Note: The hardware lock is not required when reading the ACPI bit registers
343 1.1.1.2.2.2 bouyer * since almost all of them are single bit and it does not matter that
344 1.1.1.2.2.2 bouyer * the parent hardware register can be split across two physical
345 1.1.1.2.2.2 bouyer * registers. The only multi-bit field is SLP_TYP in the PM1 control
346 1.1.1.2.2.2 bouyer * register, but this field does not cross an 8-bit boundary (nor does
347 1.1.1.2.2.2 bouyer * it make much sense to actually read this field.)
348 1.1.1.2.2.2 bouyer *
349 1.1.1.2.2.2 bouyer ******************************************************************************/
350 1.1.1.2.2.2 bouyer
351 1.1.1.2.2.2 bouyer ACPI_STATUS
352 1.1.1.2.2.2 bouyer AcpiReadBitRegister (
353 1.1.1.2.2.2 bouyer UINT32 RegisterId,
354 1.1.1.2.2.2 bouyer UINT32 *ReturnValue)
355 1.1.1.2.2.2 bouyer {
356 1.1.1.2.2.2 bouyer ACPI_BIT_REGISTER_INFO *BitRegInfo;
357 1.1.1.2.2.2 bouyer UINT32 RegisterValue;
358 1.1.1.2.2.2 bouyer UINT32 Value;
359 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
360 1.1.1.2.2.2 bouyer
361 1.1.1.2.2.2 bouyer
362 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId);
363 1.1.1.2.2.2 bouyer
364 1.1.1.2.2.2 bouyer
365 1.1.1.2.2.2 bouyer /* Get the info structure corresponding to the requested ACPI Register */
366 1.1.1.2.2.2 bouyer
367 1.1.1.2.2.2 bouyer BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
368 1.1.1.2.2.2 bouyer if (!BitRegInfo)
369 1.1.1.2.2.2 bouyer {
370 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
371 1.1.1.2.2.2 bouyer }
372 1.1.1.2.2.2 bouyer
373 1.1.1.2.2.2 bouyer /* Read the entire parent register */
374 1.1.1.2.2.2 bouyer
375 1.1.1.2.2.2 bouyer Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
376 1.1.1.2.2.2 bouyer &RegisterValue);
377 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
378 1.1.1.2.2.2 bouyer {
379 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
380 1.1.1.2.2.2 bouyer }
381 1.1.1.2.2.2 bouyer
382 1.1.1.2.2.2 bouyer /* Normalize the value that was read, mask off other bits */
383 1.1.1.2.2.2 bouyer
384 1.1.1.2.2.2 bouyer Value = ((RegisterValue & BitRegInfo->AccessBitMask)
385 1.1.1.2.2.2 bouyer >> BitRegInfo->BitPosition);
386 1.1.1.2.2.2 bouyer
387 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_IO,
388 1.1.1.2.2.2 bouyer "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
389 1.1.1.2.2.2 bouyer RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
390 1.1.1.2.2.2 bouyer
391 1.1.1.2.2.2 bouyer *ReturnValue = Value;
392 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
393 1.1.1.2.2.2 bouyer }
394 1.1.1.2.2.2 bouyer
395 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiReadBitRegister)
396 1.1.1.2.2.2 bouyer
397 1.1.1.2.2.2 bouyer
398 1.1.1.2.2.2 bouyer /*******************************************************************************
399 1.1.1.2.2.2 bouyer *
400 1.1.1.2.2.2 bouyer * FUNCTION: AcpiWriteBitRegister
401 1.1.1.2.2.2 bouyer *
402 1.1.1.2.2.2 bouyer * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
403 1.1.1.2.2.2 bouyer * Value - Value to write to the register, in bit
404 1.1.1.2.2.2 bouyer * position zero. The bit is automaticallly
405 1.1.1.2.2.2 bouyer * shifted to the correct position.
406 1.1.1.2.2.2 bouyer *
407 1.1.1.2.2.2 bouyer * RETURN: Status
408 1.1.1.2.2.2 bouyer *
409 1.1.1.2.2.2 bouyer * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
410 1.1.1.2.2.2 bouyer * since most operations require a read/modify/write sequence.
411 1.1.1.2.2.2 bouyer *
412 1.1.1.2.2.2 bouyer * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
413 1.1.1.2.2.2 bouyer * PM2 Control.
414 1.1.1.2.2.2 bouyer *
415 1.1.1.2.2.2 bouyer * Note that at this level, the fact that there may be actually two
416 1.1.1.2.2.2 bouyer * hardware registers (A and B - and B may not exist) is abstracted.
417 1.1.1.2.2.2 bouyer *
418 1.1.1.2.2.2 bouyer ******************************************************************************/
419 1.1.1.2.2.2 bouyer
420 1.1.1.2.2.2 bouyer ACPI_STATUS
421 1.1.1.2.2.2 bouyer AcpiWriteBitRegister (
422 1.1.1.2.2.2 bouyer UINT32 RegisterId,
423 1.1.1.2.2.2 bouyer UINT32 Value)
424 1.1.1.2.2.2 bouyer {
425 1.1.1.2.2.2 bouyer ACPI_BIT_REGISTER_INFO *BitRegInfo;
426 1.1.1.2.2.2 bouyer ACPI_CPU_FLAGS LockFlags;
427 1.1.1.2.2.2 bouyer UINT32 RegisterValue;
428 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
429 1.1.1.2.2.2 bouyer
430 1.1.1.2.2.2 bouyer
431 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId);
432 1.1.1.2.2.2 bouyer
433 1.1.1.2.2.2 bouyer
434 1.1.1.2.2.2 bouyer /* Get the info structure corresponding to the requested ACPI Register */
435 1.1.1.2.2.2 bouyer
436 1.1.1.2.2.2 bouyer BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
437 1.1.1.2.2.2 bouyer if (!BitRegInfo)
438 1.1.1.2.2.2 bouyer {
439 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
440 1.1.1.2.2.2 bouyer }
441 1.1.1.2.2.2 bouyer
442 1.1.1.2.2.2 bouyer LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
443 1.1.1.2.2.2 bouyer
444 1.1.1.2.2.2 bouyer /*
445 1.1.1.2.2.2 bouyer * At this point, we know that the parent register is one of the
446 1.1.1.2.2.2 bouyer * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
447 1.1.1.2.2.2 bouyer */
448 1.1.1.2.2.2 bouyer if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
449 1.1.1.2.2.2 bouyer {
450 1.1.1.2.2.2 bouyer /*
451 1.1.1.2.2.2 bouyer * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
452 1.1.1.2.2.2 bouyer *
453 1.1.1.2.2.2 bouyer * Perform a register read to preserve the bits that we are not
454 1.1.1.2.2.2 bouyer * interested in
455 1.1.1.2.2.2 bouyer */
456 1.1.1.2.2.2 bouyer Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
457 1.1.1.2.2.2 bouyer &RegisterValue);
458 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
459 1.1.1.2.2.2 bouyer {
460 1.1.1.2.2.2 bouyer goto UnlockAndExit;
461 1.1.1.2.2.2 bouyer }
462 1.1.1.2.2.2 bouyer
463 1.1.1.2.2.2 bouyer /*
464 1.1.1.2.2.2 bouyer * Insert the input bit into the value that was just read
465 1.1.1.2.2.2 bouyer * and write the register
466 1.1.1.2.2.2 bouyer */
467 1.1.1.2.2.2 bouyer ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
468 1.1.1.2.2.2 bouyer BitRegInfo->AccessBitMask, Value);
469 1.1.1.2.2.2 bouyer
470 1.1.1.2.2.2 bouyer Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister,
471 1.1.1.2.2.2 bouyer RegisterValue);
472 1.1.1.2.2.2 bouyer }
473 1.1.1.2.2.2 bouyer else
474 1.1.1.2.2.2 bouyer {
475 1.1.1.2.2.2 bouyer /*
476 1.1.1.2.2.2 bouyer * 2) Case for PM1 Status
477 1.1.1.2.2.2 bouyer *
478 1.1.1.2.2.2 bouyer * The Status register is different from the rest. Clear an event
479 1.1.1.2.2.2 bouyer * by writing 1, writing 0 has no effect. So, the only relevant
480 1.1.1.2.2.2 bouyer * information is the single bit we're interested in, all others
481 1.1.1.2.2.2 bouyer * should be written as 0 so they will be left unchanged.
482 1.1.1.2.2.2 bouyer */
483 1.1.1.2.2.2 bouyer RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
484 1.1.1.2.2.2 bouyer BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
485 1.1.1.2.2.2 bouyer
486 1.1.1.2.2.2 bouyer /* No need to write the register if value is all zeros */
487 1.1.1.2.2.2 bouyer
488 1.1.1.2.2.2 bouyer if (RegisterValue)
489 1.1.1.2.2.2 bouyer {
490 1.1.1.2.2.2 bouyer Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
491 1.1.1.2.2.2 bouyer RegisterValue);
492 1.1.1.2.2.2 bouyer }
493 1.1.1.2.2.2 bouyer }
494 1.1.1.2.2.2 bouyer
495 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_IO,
496 1.1.1.2.2.2 bouyer "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
497 1.1.1.2.2.2 bouyer RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
498 1.1.1.2.2.2 bouyer
499 1.1.1.2.2.2 bouyer
500 1.1.1.2.2.2 bouyer UnlockAndExit:
501 1.1.1.2.2.2 bouyer
502 1.1.1.2.2.2 bouyer AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
503 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
504 1.1.1.2.2.2 bouyer }
505 1.1.1.2.2.2 bouyer
506 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister)
507 1.1.1.2.2.2 bouyer
508 1.1.1.2.2.2 bouyer
509 1.1.1.2.2.2 bouyer /*******************************************************************************
510 1.1.1.2.2.2 bouyer *
511 1.1.1.2.2.2 bouyer * FUNCTION: AcpiGetSleepTypeData
512 1.1.1.2.2.2 bouyer *
513 1.1.1.2.2.2 bouyer * PARAMETERS: SleepState - Numeric sleep state
514 1.1.1.2.2.2 bouyer * *SleepTypeA - Where SLP_TYPa is returned
515 1.1.1.2.2.2 bouyer * *SleepTypeB - Where SLP_TYPb is returned
516 1.1.1.2.2.2 bouyer *
517 1.1.1.2.2.2 bouyer * RETURN: Status - ACPI status
518 1.1.1.2.2.2 bouyer *
519 1.1.1.2.2.2 bouyer * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
520 1.1.1.2.2.2 bouyer * state.
521 1.1.1.2.2.2 bouyer *
522 1.1.1.2.2.2 bouyer ******************************************************************************/
523 1.1.1.2.2.2 bouyer
524 1.1.1.2.2.2 bouyer ACPI_STATUS
525 1.1.1.2.2.2 bouyer AcpiGetSleepTypeData (
526 1.1.1.2.2.2 bouyer UINT8 SleepState,
527 1.1.1.2.2.2 bouyer UINT8 *SleepTypeA,
528 1.1.1.2.2.2 bouyer UINT8 *SleepTypeB)
529 1.1.1.2.2.2 bouyer {
530 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
531 1.1.1.2.2.2 bouyer ACPI_EVALUATE_INFO *Info;
532 1.1.1.2.2.2 bouyer
533 1.1.1.2.2.2 bouyer
534 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
535 1.1.1.2.2.2 bouyer
536 1.1.1.2.2.2 bouyer
537 1.1.1.2.2.2 bouyer /* Validate parameters */
538 1.1.1.2.2.2 bouyer
539 1.1.1.2.2.2 bouyer if ((SleepState > ACPI_S_STATES_MAX) ||
540 1.1.1.2.2.2 bouyer !SleepTypeA ||
541 1.1.1.2.2.2 bouyer !SleepTypeB)
542 1.1.1.2.2.2 bouyer {
543 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
544 1.1.1.2.2.2 bouyer }
545 1.1.1.2.2.2 bouyer
546 1.1.1.2.2.2 bouyer /* Allocate the evaluation information block */
547 1.1.1.2.2.2 bouyer
548 1.1.1.2.2.2 bouyer Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
549 1.1.1.2.2.2 bouyer if (!Info)
550 1.1.1.2.2.2 bouyer {
551 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
552 1.1.1.2.2.2 bouyer }
553 1.1.1.2.2.2 bouyer
554 1.1.1.2.2.2 bouyer Info->Pathname = ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames[SleepState]);
555 1.1.1.2.2.2 bouyer
556 1.1.1.2.2.2 bouyer /* Evaluate the namespace object containing the values for this state */
557 1.1.1.2.2.2 bouyer
558 1.1.1.2.2.2 bouyer Status = AcpiNsEvaluate (Info);
559 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
560 1.1.1.2.2.2 bouyer {
561 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
562 1.1.1.2.2.2 bouyer "%s while evaluating SleepState [%s]\n",
563 1.1.1.2.2.2 bouyer AcpiFormatException (Status), Info->Pathname));
564 1.1.1.2.2.2 bouyer
565 1.1.1.2.2.2 bouyer goto Cleanup;
566 1.1.1.2.2.2 bouyer }
567 1.1.1.2.2.2 bouyer
568 1.1.1.2.2.2 bouyer /* Must have a return object */
569 1.1.1.2.2.2 bouyer
570 1.1.1.2.2.2 bouyer if (!Info->ReturnObject)
571 1.1.1.2.2.2 bouyer {
572 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
573 1.1.1.2.2.2 bouyer Info->Pathname));
574 1.1.1.2.2.2 bouyer Status = AE_NOT_EXIST;
575 1.1.1.2.2.2 bouyer }
576 1.1.1.2.2.2 bouyer
577 1.1.1.2.2.2 bouyer /* It must be of type Package */
578 1.1.1.2.2.2 bouyer
579 1.1.1.2.2.2 bouyer else if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
580 1.1.1.2.2.2 bouyer {
581 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
582 1.1.1.2.2.2 bouyer Status = AE_AML_OPERAND_TYPE;
583 1.1.1.2.2.2 bouyer }
584 1.1.1.2.2.2 bouyer
585 1.1.1.2.2.2 bouyer /*
586 1.1.1.2.2.2 bouyer * The package must have at least two elements. NOTE (March 2005): This
587 1.1.1.2.2.2 bouyer * goes against the current ACPI spec which defines this object as a
588 1.1.1.2.2.2 bouyer * package with one encoded DWORD element. However, existing practice
589 1.1.1.2.2.2 bouyer * by BIOS vendors seems to be to have 2 or more elements, at least
590 1.1.1.2.2.2 bouyer * one per sleep type (A/B).
591 1.1.1.2.2.2 bouyer */
592 1.1.1.2.2.2 bouyer else if (Info->ReturnObject->Package.Count < 2)
593 1.1.1.2.2.2 bouyer {
594 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
595 1.1.1.2.2.2 bouyer "Sleep State return package does not have at least two elements"));
596 1.1.1.2.2.2 bouyer Status = AE_AML_NO_OPERAND;
597 1.1.1.2.2.2 bouyer }
598 1.1.1.2.2.2 bouyer
599 1.1.1.2.2.2 bouyer /* The first two elements must both be of type Integer */
600 1.1.1.2.2.2 bouyer
601 1.1.1.2.2.2 bouyer else if (((Info->ReturnObject->Package.Elements[0])->Common.Type
602 1.1.1.2.2.2 bouyer != ACPI_TYPE_INTEGER) ||
603 1.1.1.2.2.2 bouyer ((Info->ReturnObject->Package.Elements[1])->Common.Type
604 1.1.1.2.2.2 bouyer != ACPI_TYPE_INTEGER))
605 1.1.1.2.2.2 bouyer {
606 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
607 1.1.1.2.2.2 bouyer "Sleep State return package elements are not both Integers "
608 1.1.1.2.2.2 bouyer "(%s, %s)",
609 1.1.1.2.2.2 bouyer AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[0]),
610 1.1.1.2.2.2 bouyer AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[1])));
611 1.1.1.2.2.2 bouyer Status = AE_AML_OPERAND_TYPE;
612 1.1.1.2.2.2 bouyer }
613 1.1.1.2.2.2 bouyer else
614 1.1.1.2.2.2 bouyer {
615 1.1.1.2.2.2 bouyer /* Valid _Sx_ package size, type, and value */
616 1.1.1.2.2.2 bouyer
617 1.1.1.2.2.2 bouyer *SleepTypeA = (UINT8)
618 1.1.1.2.2.2 bouyer (Info->ReturnObject->Package.Elements[0])->Integer.Value;
619 1.1.1.2.2.2 bouyer *SleepTypeB = (UINT8)
620 1.1.1.2.2.2 bouyer (Info->ReturnObject->Package.Elements[1])->Integer.Value;
621 1.1.1.2.2.2 bouyer }
622 1.1.1.2.2.2 bouyer
623 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
624 1.1.1.2.2.2 bouyer {
625 1.1.1.2.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status,
626 1.1.1.2.2.2 bouyer "While evaluating SleepState [%s], bad Sleep object %p type %s",
627 1.1.1.2.2.2 bouyer Info->Pathname, Info->ReturnObject,
628 1.1.1.2.2.2 bouyer AcpiUtGetObjectTypeName (Info->ReturnObject)));
629 1.1.1.2.2.2 bouyer }
630 1.1.1.2.2.2 bouyer
631 1.1.1.2.2.2 bouyer AcpiUtRemoveReference (Info->ReturnObject);
632 1.1.1.2.2.2 bouyer
633 1.1.1.2.2.2 bouyer Cleanup:
634 1.1.1.2.2.2 bouyer ACPI_FREE (Info);
635 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
636 1.1.1.2.2.2 bouyer }
637 1.1.1.2.2.2 bouyer
638 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)
639