hwxface.c revision 1.1.1.7 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.6 christos * Copyright (C) 2000 - 2016, 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.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.1.3 christos UINT32 ValueLo;
143 1.1.1.3 christos UINT32 ValueHi;
144 1.1 jruoho UINT32 Width;
145 1.1 jruoho UINT64 Address;
146 1.1 jruoho ACPI_STATUS Status;
147 1.1 jruoho
148 1.1 jruoho
149 1.1 jruoho ACPI_FUNCTION_NAME (AcpiRead);
150 1.1 jruoho
151 1.1 jruoho
152 1.1 jruoho if (!ReturnValue)
153 1.1 jruoho {
154 1.1 jruoho return (AE_BAD_PARAMETER);
155 1.1 jruoho }
156 1.1 jruoho
157 1.1 jruoho /* Validate contents of the GAS register. Allow 64-bit transfers */
158 1.1 jruoho
159 1.1 jruoho Status = AcpiHwValidateRegister (Reg, 64, &Address);
160 1.1 jruoho if (ACPI_FAILURE (Status))
161 1.1 jruoho {
162 1.1 jruoho return (Status);
163 1.1 jruoho }
164 1.1 jruoho
165 1.1 jruoho /*
166 1.1.1.3 christos * Two address spaces supported: Memory or I/O. PCI_Config is
167 1.1 jruoho * not supported here because the GAS structure is insufficient
168 1.1 jruoho */
169 1.1 jruoho if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
170 1.1 jruoho {
171 1.1 jruoho Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
172 1.1.1.6 christos Address, ReturnValue, Reg->BitWidth);
173 1.1 jruoho if (ACPI_FAILURE (Status))
174 1.1 jruoho {
175 1.1 jruoho return (Status);
176 1.1 jruoho }
177 1.1 jruoho }
178 1.1 jruoho else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
179 1.1 jruoho {
180 1.1.1.3 christos ValueLo = 0;
181 1.1.1.3 christos ValueHi = 0;
182 1.1.1.3 christos
183 1.1.1.3 christos Width = Reg->BitWidth;
184 1.1.1.3 christos if (Width == 64)
185 1.1.1.3 christos {
186 1.1.1.3 christos Width = 32; /* Break into two 32-bit transfers */
187 1.1.1.3 christos }
188 1.1.1.3 christos
189 1.1 jruoho Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
190 1.1.1.6 christos Address, &ValueLo, Width);
191 1.1 jruoho if (ACPI_FAILURE (Status))
192 1.1 jruoho {
193 1.1 jruoho return (Status);
194 1.1 jruoho }
195 1.1 jruoho
196 1.1 jruoho if (Reg->BitWidth == 64)
197 1.1 jruoho {
198 1.1 jruoho /* Read the top 32 bits */
199 1.1 jruoho
200 1.1 jruoho Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
201 1.1.1.6 christos (Address + 4), &ValueHi, 32);
202 1.1 jruoho if (ACPI_FAILURE (Status))
203 1.1 jruoho {
204 1.1 jruoho return (Status);
205 1.1 jruoho }
206 1.1 jruoho }
207 1.1.1.3 christos
208 1.1.1.3 christos /* Set the return value only if status is AE_OK */
209 1.1.1.3 christos
210 1.1.1.3 christos *ReturnValue = (ValueLo | ((UINT64) ValueHi << 32));
211 1.1 jruoho }
212 1.1 jruoho
213 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_IO,
214 1.1 jruoho "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
215 1.1 jruoho ACPI_FORMAT_UINT64 (*ReturnValue), Reg->BitWidth,
216 1.1 jruoho ACPI_FORMAT_UINT64 (Address),
217 1.1 jruoho AcpiUtGetRegionName (Reg->SpaceId)));
218 1.1 jruoho
219 1.1.1.3 christos return (AE_OK);
220 1.1 jruoho }
221 1.1 jruoho
222 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiRead)
223 1.1 jruoho
224 1.1 jruoho
225 1.1 jruoho /******************************************************************************
226 1.1 jruoho *
227 1.1 jruoho * FUNCTION: AcpiWrite
228 1.1 jruoho *
229 1.1 jruoho * PARAMETERS: Value - Value to be written
230 1.1 jruoho * Reg - GAS register structure
231 1.1 jruoho *
232 1.1 jruoho * RETURN: Status
233 1.1 jruoho *
234 1.1 jruoho * DESCRIPTION: Write to either memory or IO space.
235 1.1 jruoho *
236 1.1 jruoho ******************************************************************************/
237 1.1 jruoho
238 1.1 jruoho ACPI_STATUS
239 1.1 jruoho AcpiWrite (
240 1.1 jruoho UINT64 Value,
241 1.1 jruoho ACPI_GENERIC_ADDRESS *Reg)
242 1.1 jruoho {
243 1.1 jruoho UINT32 Width;
244 1.1 jruoho UINT64 Address;
245 1.1 jruoho ACPI_STATUS Status;
246 1.1 jruoho
247 1.1 jruoho
248 1.1 jruoho ACPI_FUNCTION_NAME (AcpiWrite);
249 1.1 jruoho
250 1.1 jruoho
251 1.1 jruoho /* Validate contents of the GAS register. Allow 64-bit transfers */
252 1.1 jruoho
253 1.1 jruoho Status = AcpiHwValidateRegister (Reg, 64, &Address);
254 1.1 jruoho if (ACPI_FAILURE (Status))
255 1.1 jruoho {
256 1.1 jruoho return (Status);
257 1.1 jruoho }
258 1.1 jruoho
259 1.1 jruoho /*
260 1.1 jruoho * Two address spaces supported: Memory or IO. PCI_Config is
261 1.1 jruoho * not supported here because the GAS structure is insufficient
262 1.1 jruoho */
263 1.1 jruoho if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
264 1.1 jruoho {
265 1.1 jruoho Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
266 1.1.1.6 christos Address, Value, Reg->BitWidth);
267 1.1 jruoho if (ACPI_FAILURE (Status))
268 1.1 jruoho {
269 1.1 jruoho return (Status);
270 1.1 jruoho }
271 1.1 jruoho }
272 1.1 jruoho else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
273 1.1 jruoho {
274 1.1.1.3 christos Width = Reg->BitWidth;
275 1.1.1.3 christos if (Width == 64)
276 1.1.1.3 christos {
277 1.1.1.3 christos Width = 32; /* Break into two 32-bit transfers */
278 1.1.1.3 christos }
279 1.1.1.3 christos
280 1.1 jruoho Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
281 1.1.1.6 christos Address, ACPI_LODWORD (Value), Width);
282 1.1 jruoho if (ACPI_FAILURE (Status))
283 1.1 jruoho {
284 1.1 jruoho return (Status);
285 1.1 jruoho }
286 1.1 jruoho
287 1.1 jruoho if (Reg->BitWidth == 64)
288 1.1 jruoho {
289 1.1 jruoho Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
290 1.1.1.6 christos (Address + 4), ACPI_HIDWORD (Value), 32);
291 1.1 jruoho if (ACPI_FAILURE (Status))
292 1.1 jruoho {
293 1.1 jruoho return (Status);
294 1.1 jruoho }
295 1.1 jruoho }
296 1.1 jruoho }
297 1.1 jruoho
298 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_IO,
299 1.1 jruoho "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
300 1.1 jruoho ACPI_FORMAT_UINT64 (Value), Reg->BitWidth,
301 1.1 jruoho ACPI_FORMAT_UINT64 (Address),
302 1.1 jruoho AcpiUtGetRegionName (Reg->SpaceId)));
303 1.1 jruoho
304 1.1 jruoho return (Status);
305 1.1 jruoho }
306 1.1 jruoho
307 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiWrite)
308 1.1 jruoho
309 1.1 jruoho
310 1.1.1.3 christos #if (!ACPI_REDUCED_HARDWARE)
311 1.1 jruoho /*******************************************************************************
312 1.1 jruoho *
313 1.1 jruoho * FUNCTION: AcpiReadBitRegister
314 1.1 jruoho *
315 1.1 jruoho * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
316 1.1 jruoho * ReturnValue - Value that was read from the register,
317 1.1 jruoho * normalized to bit position zero.
318 1.1 jruoho *
319 1.1 jruoho * RETURN: Status and the value read from the specified Register. Value
320 1.1 jruoho * returned is normalized to bit0 (is shifted all the way right)
321 1.1 jruoho *
322 1.1 jruoho * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
323 1.1 jruoho *
324 1.1 jruoho * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
325 1.1 jruoho * PM2 Control.
326 1.1 jruoho *
327 1.1 jruoho * Note: The hardware lock is not required when reading the ACPI bit registers
328 1.1 jruoho * since almost all of them are single bit and it does not matter that
329 1.1 jruoho * the parent hardware register can be split across two physical
330 1.1 jruoho * registers. The only multi-bit field is SLP_TYP in the PM1 control
331 1.1 jruoho * register, but this field does not cross an 8-bit boundary (nor does
332 1.1 jruoho * it make much sense to actually read this field.)
333 1.1 jruoho *
334 1.1 jruoho ******************************************************************************/
335 1.1 jruoho
336 1.1 jruoho ACPI_STATUS
337 1.1 jruoho AcpiReadBitRegister (
338 1.1 jruoho UINT32 RegisterId,
339 1.1 jruoho UINT32 *ReturnValue)
340 1.1 jruoho {
341 1.1 jruoho ACPI_BIT_REGISTER_INFO *BitRegInfo;
342 1.1 jruoho UINT32 RegisterValue;
343 1.1 jruoho UINT32 Value;
344 1.1 jruoho ACPI_STATUS Status;
345 1.1 jruoho
346 1.1 jruoho
347 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId);
348 1.1 jruoho
349 1.1 jruoho
350 1.1 jruoho /* Get the info structure corresponding to the requested ACPI Register */
351 1.1 jruoho
352 1.1 jruoho BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
353 1.1 jruoho if (!BitRegInfo)
354 1.1 jruoho {
355 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
356 1.1 jruoho }
357 1.1 jruoho
358 1.1 jruoho /* Read the entire parent register */
359 1.1 jruoho
360 1.1 jruoho Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
361 1.1.1.6 christos &RegisterValue);
362 1.1 jruoho if (ACPI_FAILURE (Status))
363 1.1 jruoho {
364 1.1 jruoho return_ACPI_STATUS (Status);
365 1.1 jruoho }
366 1.1 jruoho
367 1.1 jruoho /* Normalize the value that was read, mask off other bits */
368 1.1 jruoho
369 1.1 jruoho Value = ((RegisterValue & BitRegInfo->AccessBitMask)
370 1.1.1.6 christos >> BitRegInfo->BitPosition);
371 1.1 jruoho
372 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_IO,
373 1.1 jruoho "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
374 1.1 jruoho RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
375 1.1 jruoho
376 1.1 jruoho *ReturnValue = Value;
377 1.1 jruoho return_ACPI_STATUS (AE_OK);
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiReadBitRegister)
381 1.1 jruoho
382 1.1 jruoho
383 1.1 jruoho /*******************************************************************************
384 1.1 jruoho *
385 1.1 jruoho * FUNCTION: AcpiWriteBitRegister
386 1.1 jruoho *
387 1.1 jruoho * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
388 1.1 jruoho * Value - Value to write to the register, in bit
389 1.1.1.3 christos * position zero. The bit is automatically
390 1.1 jruoho * shifted to the correct position.
391 1.1 jruoho *
392 1.1 jruoho * RETURN: Status
393 1.1 jruoho *
394 1.1 jruoho * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
395 1.1 jruoho * since most operations require a read/modify/write sequence.
396 1.1 jruoho *
397 1.1 jruoho * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
398 1.1 jruoho * PM2 Control.
399 1.1 jruoho *
400 1.1 jruoho * Note that at this level, the fact that there may be actually two
401 1.1 jruoho * hardware registers (A and B - and B may not exist) is abstracted.
402 1.1 jruoho *
403 1.1 jruoho ******************************************************************************/
404 1.1 jruoho
405 1.1 jruoho ACPI_STATUS
406 1.1 jruoho AcpiWriteBitRegister (
407 1.1 jruoho UINT32 RegisterId,
408 1.1 jruoho UINT32 Value)
409 1.1 jruoho {
410 1.1 jruoho ACPI_BIT_REGISTER_INFO *BitRegInfo;
411 1.1 jruoho ACPI_CPU_FLAGS LockFlags;
412 1.1 jruoho UINT32 RegisterValue;
413 1.1 jruoho ACPI_STATUS Status = AE_OK;
414 1.1 jruoho
415 1.1 jruoho
416 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId);
417 1.1 jruoho
418 1.1 jruoho
419 1.1 jruoho /* Get the info structure corresponding to the requested ACPI Register */
420 1.1 jruoho
421 1.1 jruoho BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
422 1.1 jruoho if (!BitRegInfo)
423 1.1 jruoho {
424 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
425 1.1 jruoho }
426 1.1 jruoho
427 1.1 jruoho LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
428 1.1 jruoho
429 1.1 jruoho /*
430 1.1 jruoho * At this point, we know that the parent register is one of the
431 1.1 jruoho * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
432 1.1 jruoho */
433 1.1 jruoho if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
434 1.1 jruoho {
435 1.1 jruoho /*
436 1.1 jruoho * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
437 1.1 jruoho *
438 1.1 jruoho * Perform a register read to preserve the bits that we are not
439 1.1 jruoho * interested in
440 1.1 jruoho */
441 1.1 jruoho Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
442 1.1.1.6 christos &RegisterValue);
443 1.1 jruoho if (ACPI_FAILURE (Status))
444 1.1 jruoho {
445 1.1 jruoho goto UnlockAndExit;
446 1.1 jruoho }
447 1.1 jruoho
448 1.1 jruoho /*
449 1.1 jruoho * Insert the input bit into the value that was just read
450 1.1 jruoho * and write the register
451 1.1 jruoho */
452 1.1 jruoho ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
453 1.1 jruoho BitRegInfo->AccessBitMask, Value);
454 1.1 jruoho
455 1.1 jruoho Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister,
456 1.1.1.6 christos RegisterValue);
457 1.1 jruoho }
458 1.1 jruoho else
459 1.1 jruoho {
460 1.1 jruoho /*
461 1.1 jruoho * 2) Case for PM1 Status
462 1.1 jruoho *
463 1.1 jruoho * The Status register is different from the rest. Clear an event
464 1.1 jruoho * by writing 1, writing 0 has no effect. So, the only relevant
465 1.1 jruoho * information is the single bit we're interested in, all others
466 1.1 jruoho * should be written as 0 so they will be left unchanged.
467 1.1 jruoho */
468 1.1 jruoho RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
469 1.1 jruoho BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
470 1.1 jruoho
471 1.1 jruoho /* No need to write the register if value is all zeros */
472 1.1 jruoho
473 1.1 jruoho if (RegisterValue)
474 1.1 jruoho {
475 1.1 jruoho Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
476 1.1.1.6 christos RegisterValue);
477 1.1 jruoho }
478 1.1 jruoho }
479 1.1 jruoho
480 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_IO,
481 1.1 jruoho "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
482 1.1 jruoho RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
483 1.1 jruoho
484 1.1 jruoho
485 1.1 jruoho UnlockAndExit:
486 1.1 jruoho
487 1.1 jruoho AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
488 1.1 jruoho return_ACPI_STATUS (Status);
489 1.1 jruoho }
490 1.1 jruoho
491 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister)
492 1.1 jruoho
493 1.1.1.3 christos #endif /* !ACPI_REDUCED_HARDWARE */
494 1.1.1.3 christos
495 1.1 jruoho
496 1.1 jruoho /*******************************************************************************
497 1.1 jruoho *
498 1.1 jruoho * FUNCTION: AcpiGetSleepTypeData
499 1.1 jruoho *
500 1.1 jruoho * PARAMETERS: SleepState - Numeric sleep state
501 1.1 jruoho * *SleepTypeA - Where SLP_TYPa is returned
502 1.1 jruoho * *SleepTypeB - Where SLP_TYPb is returned
503 1.1 jruoho *
504 1.1.1.3 christos * RETURN: Status
505 1.1.1.3 christos *
506 1.1.1.3 christos * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
507 1.1.1.3 christos * sleep state via the appropriate \_Sx object.
508 1.1.1.3 christos *
509 1.1.1.3 christos * The sleep state package returned from the corresponding \_Sx_ object
510 1.1.1.3 christos * must contain at least one integer.
511 1.1 jruoho *
512 1.1.1.3 christos * March 2005:
513 1.1.1.3 christos * Added support for a package that contains two integers. This
514 1.1.1.3 christos * goes against the ACPI specification which defines this object as a
515 1.1.1.3 christos * package with one encoded DWORD integer. However, existing practice
516 1.1.1.3 christos * by many BIOS vendors is to return a package with 2 or more integer
517 1.1.1.3 christos * elements, at least one per sleep type (A/B).
518 1.1.1.3 christos *
519 1.1.1.3 christos * January 2013:
520 1.1.1.3 christos * Therefore, we must be prepared to accept a package with either a
521 1.1.1.3 christos * single integer or multiple integers.
522 1.1.1.3 christos *
523 1.1.1.3 christos * The single integer DWORD format is as follows:
524 1.1.1.3 christos * BYTE 0 - Value for the PM1A SLP_TYP register
525 1.1.1.3 christos * BYTE 1 - Value for the PM1B SLP_TYP register
526 1.1.1.3 christos * BYTE 2-3 - Reserved
527 1.1.1.3 christos *
528 1.1.1.3 christos * The dual integer format is as follows:
529 1.1.1.3 christos * Integer 0 - Value for the PM1A SLP_TYP register
530 1.1.1.3 christos * Integer 1 - Value for the PM1A SLP_TYP register
531 1.1 jruoho *
532 1.1 jruoho ******************************************************************************/
533 1.1 jruoho
534 1.1 jruoho ACPI_STATUS
535 1.1 jruoho AcpiGetSleepTypeData (
536 1.1 jruoho UINT8 SleepState,
537 1.1 jruoho UINT8 *SleepTypeA,
538 1.1 jruoho UINT8 *SleepTypeB)
539 1.1 jruoho {
540 1.1.1.3 christos ACPI_STATUS Status;
541 1.1 jruoho ACPI_EVALUATE_INFO *Info;
542 1.1.1.3 christos ACPI_OPERAND_OBJECT **Elements;
543 1.1 jruoho
544 1.1 jruoho
545 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
546 1.1 jruoho
547 1.1 jruoho
548 1.1 jruoho /* Validate parameters */
549 1.1 jruoho
550 1.1 jruoho if ((SleepState > ACPI_S_STATES_MAX) ||
551 1.1.1.3 christos !SleepTypeA || !SleepTypeB)
552 1.1 jruoho {
553 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
554 1.1 jruoho }
555 1.1 jruoho
556 1.1 jruoho /* Allocate the evaluation information block */
557 1.1 jruoho
558 1.1 jruoho Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
559 1.1 jruoho if (!Info)
560 1.1 jruoho {
561 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
562 1.1 jruoho }
563 1.1 jruoho
564 1.1.1.3 christos /*
565 1.1.1.3 christos * Evaluate the \_Sx namespace object containing the register values
566 1.1.1.3 christos * for this state
567 1.1.1.3 christos */
568 1.1.1.7 christos Info->RelativePathname = AcpiGbl_SleepStateNames[SleepState];
569 1.1.1.6 christos
570 1.1 jruoho Status = AcpiNsEvaluate (Info);
571 1.1 jruoho if (ACPI_FAILURE (Status))
572 1.1 jruoho {
573 1.1.1.6 christos if (Status == AE_NOT_FOUND)
574 1.1.1.6 christos {
575 1.1.1.6 christos /* The _Sx states are optional, ignore NOT_FOUND */
576 1.1.1.6 christos
577 1.1.1.6 christos goto FinalCleanup;
578 1.1.1.6 christos }
579 1.1.1.6 christos
580 1.1.1.6 christos goto WarningCleanup;
581 1.1 jruoho }
582 1.1 jruoho
583 1.1 jruoho /* Must have a return object */
584 1.1 jruoho
585 1.1 jruoho if (!Info->ReturnObject)
586 1.1 jruoho {
587 1.1 jruoho ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
588 1.1.1.3 christos Info->RelativePathname));
589 1.1.1.3 christos Status = AE_AML_NO_RETURN_VALUE;
590 1.1.1.6 christos goto WarningCleanup;
591 1.1 jruoho }
592 1.1 jruoho
593 1.1.1.3 christos /* Return object must be of type Package */
594 1.1 jruoho
595 1.1.1.3 christos if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
596 1.1 jruoho {
597 1.1 jruoho ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
598 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
599 1.1.1.6 christos goto ReturnValueCleanup;
600 1.1 jruoho }
601 1.1 jruoho
602 1.1 jruoho /*
603 1.1.1.3 christos * Any warnings about the package length or the object types have
604 1.1.1.3 christos * already been issued by the predefined name module -- there is no
605 1.1.1.3 christos * need to repeat them here.
606 1.1 jruoho */
607 1.1.1.3 christos Elements = Info->ReturnObject->Package.Elements;
608 1.1.1.3 christos switch (Info->ReturnObject->Package.Count)
609 1.1 jruoho {
610 1.1.1.3 christos case 0:
611 1.1 jruoho
612 1.1.1.3 christos Status = AE_AML_PACKAGE_LIMIT;
613 1.1.1.3 christos break;
614 1.1 jruoho
615 1.1.1.3 christos case 1:
616 1.1.1.3 christos
617 1.1.1.3 christos if (Elements[0]->Common.Type != ACPI_TYPE_INTEGER)
618 1.1.1.3 christos {
619 1.1.1.3 christos Status = AE_AML_OPERAND_TYPE;
620 1.1.1.3 christos break;
621 1.1.1.3 christos }
622 1.1.1.3 christos
623 1.1.1.3 christos /* A valid _Sx_ package with one integer */
624 1.1.1.3 christos
625 1.1.1.3 christos *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
626 1.1.1.3 christos *SleepTypeB = (UINT8) (Elements[0]->Integer.Value >> 8);
627 1.1.1.3 christos break;
628 1.1 jruoho
629 1.1.1.3 christos case 2:
630 1.1.1.3 christos default:
631 1.1.1.3 christos
632 1.1.1.3 christos if ((Elements[0]->Common.Type != ACPI_TYPE_INTEGER) ||
633 1.1.1.3 christos (Elements[1]->Common.Type != ACPI_TYPE_INTEGER))
634 1.1.1.3 christos {
635 1.1.1.3 christos Status = AE_AML_OPERAND_TYPE;
636 1.1.1.3 christos break;
637 1.1.1.3 christos }
638 1.1.1.3 christos
639 1.1.1.3 christos /* A valid _Sx_ package with two integers */
640 1.1.1.3 christos
641 1.1.1.3 christos *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
642 1.1.1.3 christos *SleepTypeB = (UINT8) Elements[1]->Integer.Value;
643 1.1.1.3 christos break;
644 1.1 jruoho }
645 1.1 jruoho
646 1.1.1.6 christos ReturnValueCleanup:
647 1.1.1.3 christos AcpiUtRemoveReference (Info->ReturnObject);
648 1.1.1.3 christos
649 1.1.1.6 christos WarningCleanup:
650 1.1 jruoho if (ACPI_FAILURE (Status))
651 1.1 jruoho {
652 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
653 1.1.1.6 christos "While evaluating Sleep State [%s]",
654 1.1.1.6 christos Info->RelativePathname));
655 1.1 jruoho }
656 1.1 jruoho
657 1.1.1.6 christos FinalCleanup:
658 1.1 jruoho ACPI_FREE (Info);
659 1.1 jruoho return_ACPI_STATUS (Status);
660 1.1 jruoho }
661 1.1 jruoho
662 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)
663