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