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