2 /******************************************************************************
4 * Module Name: hwxface - Public ACPICA hardware interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME("hwxface")
52 /******************************************************************************
54 * FUNCTION: acpi_reset
60 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
61 * support reset register in PCI config space, this must be
64 ******************************************************************************/
65 acpi_status
acpi_reset(void)
67 struct acpi_generic_address
*reset_reg
;
70 ACPI_FUNCTION_TRACE(acpi_reset
);
72 reset_reg
= &acpi_gbl_FADT
.reset_register
;
74 /* Check if the reset register is supported */
76 if (!(acpi_gbl_FADT
.flags
& ACPI_FADT_RESET_REGISTER
) ||
77 !reset_reg
->address
) {
78 return_ACPI_STATUS(AE_NOT_EXIST
);
81 /* Write the reset value to the reset register */
83 status
= acpi_write(acpi_gbl_FADT
.reset_value
, reset_reg
);
84 return_ACPI_STATUS(status
);
87 ACPI_EXPORT_SYMBOL(acpi_reset
)
89 /******************************************************************************
93 * PARAMETERS: Value - Where the value is returned
94 * Reg - GAS register structure
98 * DESCRIPTION: Read from either memory or IO space.
100 ******************************************************************************/
101 acpi_status
acpi_read(u32
*value
, struct acpi_generic_address
*reg
)
107 ACPI_FUNCTION_NAME(acpi_read
);
110 * Must have a valid pointer to a GAS structure, and a non-zero address
114 return (AE_BAD_PARAMETER
);
117 /* Get a local copy of the address. Handles possible alignment issues */
119 ACPI_MOVE_64_TO_64(&address
, ®
->address
);
121 return (AE_BAD_ADDRESS
);
124 /* Supported widths are 8/16/32 */
126 width
= reg
->bit_width
;
127 if ((width
!= 8) && (width
!= 16) && (width
!= 32)) {
131 /* Initialize entire 32-bit return value to zero */
136 * Two address spaces supported: Memory or IO.
137 * PCI_Config is not supported here because the GAS struct is insufficient
139 switch (reg
->space_id
) {
140 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
142 status
= acpi_os_read_memory((acpi_physical_address
) address
,
146 case ACPI_ADR_SPACE_SYSTEM_IO
:
149 acpi_os_read_port((acpi_io_address
) address
, value
, width
);
154 "Unsupported address space: %X", reg
->space_id
));
155 return (AE_BAD_PARAMETER
);
158 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
159 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
160 *value
, width
, ACPI_FORMAT_UINT64(address
),
161 acpi_ut_get_region_name(reg
->space_id
)));
166 ACPI_EXPORT_SYMBOL(acpi_read
)
168 /******************************************************************************
170 * FUNCTION: acpi_write
172 * PARAMETERS: Value - To be written
173 * Reg - GAS register structure
177 * DESCRIPTION: Write to either memory or IO space.
179 ******************************************************************************/
180 acpi_status
acpi_write(u32 value
, struct acpi_generic_address
*reg
)
186 ACPI_FUNCTION_NAME(acpi_write
);
189 * Must have a valid pointer to a GAS structure, and a non-zero address
193 return (AE_BAD_PARAMETER
);
196 /* Get a local copy of the address. Handles possible alignment issues */
198 ACPI_MOVE_64_TO_64(&address
, ®
->address
);
200 return (AE_BAD_ADDRESS
);
203 /* Supported widths are 8/16/32 */
205 width
= reg
->bit_width
;
206 if ((width
!= 8) && (width
!= 16) && (width
!= 32)) {
211 * Two address spaces supported: Memory or IO.
212 * PCI_Config is not supported here because the GAS struct is insufficient
214 switch (reg
->space_id
) {
215 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
217 status
= acpi_os_write_memory((acpi_physical_address
) address
,
221 case ACPI_ADR_SPACE_SYSTEM_IO
:
223 status
= acpi_os_write_port((acpi_io_address
) address
, value
,
229 "Unsupported address space: %X", reg
->space_id
));
230 return (AE_BAD_PARAMETER
);
233 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
234 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
235 value
, width
, ACPI_FORMAT_UINT64(address
),
236 acpi_ut_get_region_name(reg
->space_id
)));
241 ACPI_EXPORT_SYMBOL(acpi_write
)
243 /*******************************************************************************
245 * FUNCTION: acpi_read_bit_register
247 * PARAMETERS: register_id - ID of ACPI Bit Register to access
248 * return_value - Value that was read from the register,
249 * normalized to bit position zero.
251 * RETURN: Status and the value read from the specified Register. Value
252 * returned is normalized to bit0 (is shifted all the way right)
254 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
256 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
259 * Note: The hardware lock is not required when reading the ACPI bit registers
260 * since almost all of them are single bit and it does not matter that
261 * the parent hardware register can be split across two physical
262 * registers. The only multi-bit field is SLP_TYP in the PM1 control
263 * register, but this field does not cross an 8-bit boundary (nor does
264 * it make much sense to actually read this field.)
266 ******************************************************************************/
267 acpi_status
acpi_read_bit_register(u32 register_id
, u32
*return_value
)
269 u32 register_value
= 0;
270 struct acpi_bit_register_info
*bit_reg_info
;
273 ACPI_FUNCTION_TRACE(acpi_read_bit_register
);
275 /* Get the info structure corresponding to the requested ACPI Register */
277 bit_reg_info
= acpi_hw_get_bit_register_info(register_id
);
279 return_ACPI_STATUS(AE_BAD_PARAMETER
);
282 /* Read the entire parent register */
284 status
= acpi_hw_register_read(bit_reg_info
->parent_register
,
287 if (ACPI_SUCCESS(status
)) {
289 /* Normalize the value that was read */
292 ((register_value
& bit_reg_info
->access_bit_mask
)
293 >> bit_reg_info
->bit_position
);
295 *return_value
= register_value
;
297 ACPI_DEBUG_PRINT((ACPI_DB_IO
, "Read value %8.8X register %X\n",
299 bit_reg_info
->parent_register
));
302 return_ACPI_STATUS(status
);
305 ACPI_EXPORT_SYMBOL(acpi_read_bit_register
)
307 /*******************************************************************************
309 * FUNCTION: acpi_write_bit_register
311 * PARAMETERS: register_id - ID of ACPI Bit Register to access
312 * Value - Value to write to the register, in bit
313 * position zero. The bit is automaticallly
314 * shifted to the correct position.
318 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
319 * since most operations require a read/modify/write sequence.
321 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
324 ******************************************************************************/
325 acpi_status
acpi_write_bit_register(u32 register_id
, u32 value
)
327 u32 register_value
= 0;
328 struct acpi_bit_register_info
*bit_reg_info
;
330 acpi_cpu_flags lock_flags
;
332 ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register
, register_id
);
334 /* Get the info structure corresponding to the requested ACPI Register */
336 bit_reg_info
= acpi_hw_get_bit_register_info(register_id
);
338 ACPI_ERROR((AE_INFO
, "Bad ACPI HW RegisterId: %X",
340 return_ACPI_STATUS(AE_BAD_PARAMETER
);
343 lock_flags
= acpi_os_acquire_lock(acpi_gbl_hardware_lock
);
345 /* Always do a register read first so we can insert the new bits */
347 status
= acpi_hw_register_read(bit_reg_info
->parent_register
,
349 if (ACPI_FAILURE(status
)) {
350 goto unlock_and_exit
;
354 * Decode the Register ID
355 * Register ID = [Register block ID] | [bit ID]
357 * Check bit ID to fine locate Register offset.
358 * Check Mask to determine Register offset, and then read-write.
360 switch (bit_reg_info
->parent_register
) {
361 case ACPI_REGISTER_PM1_STATUS
:
364 * Status Registers are different from the rest. Clear by
365 * writing 1, and writing 0 has no effect. So, the only relevant
366 * information is the single bit we're interested in, all others should
367 * be written as 0 so they will be left unchanged.
369 value
= ACPI_REGISTER_PREPARE_BITS(value
,
370 bit_reg_info
->bit_position
,
375 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS
,
381 case ACPI_REGISTER_PM1_ENABLE
:
383 ACPI_REGISTER_INSERT_VALUE(register_value
,
384 bit_reg_info
->bit_position
,
385 bit_reg_info
->access_bit_mask
,
388 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE
,
389 (u16
) register_value
);
392 case ACPI_REGISTER_PM1_CONTROL
:
395 * Write the PM1 Control register.
396 * Note that at this level, the fact that there are actually TWO
397 * registers (A and B - and B may not exist) is abstracted.
399 ACPI_DEBUG_PRINT((ACPI_DB_IO
, "PM1 control: Read %X\n",
402 ACPI_REGISTER_INSERT_VALUE(register_value
,
403 bit_reg_info
->bit_position
,
404 bit_reg_info
->access_bit_mask
,
407 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL
,
408 (u16
) register_value
);
411 case ACPI_REGISTER_PM2_CONTROL
:
413 status
= acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL
,
415 if (ACPI_FAILURE(status
)) {
416 goto unlock_and_exit
;
419 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
420 "PM2 control: Read %X from %8.8X%8.8X\n",
422 ACPI_FORMAT_UINT64(acpi_gbl_FADT
.
426 ACPI_REGISTER_INSERT_VALUE(register_value
,
427 bit_reg_info
->bit_position
,
428 bit_reg_info
->access_bit_mask
,
431 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
432 "About to write %4.4X to %8.8X%8.8X\n",
434 ACPI_FORMAT_UINT64(acpi_gbl_FADT
.
438 status
= acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL
,
439 (u8
) (register_value
));
448 acpi_os_release_lock(acpi_gbl_hardware_lock
, lock_flags
);
450 /* Normalize the value that was read */
452 ACPI_DEBUG_EXEC(register_value
=
453 ((register_value
& bit_reg_info
->access_bit_mask
) >>
454 bit_reg_info
->bit_position
));
456 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
457 "Set bits: %8.8X actual %8.8X register %X\n", value
,
458 register_value
, bit_reg_info
->parent_register
));
459 return_ACPI_STATUS(status
);
462 ACPI_EXPORT_SYMBOL(acpi_write_bit_register
)
464 /*******************************************************************************
466 * FUNCTION: acpi_get_sleep_type_data
468 * PARAMETERS: sleep_state - Numeric sleep state
469 * *sleep_type_a - Where SLP_TYPa is returned
470 * *sleep_type_b - Where SLP_TYPb is returned
472 * RETURN: Status - ACPI status
474 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
477 ******************************************************************************/
479 acpi_get_sleep_type_data(u8 sleep_state
, u8
*sleep_type_a
, u8
*sleep_type_b
)
481 acpi_status status
= AE_OK
;
482 struct acpi_evaluate_info
*info
;
484 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data
);
486 /* Validate parameters */
488 if ((sleep_state
> ACPI_S_STATES_MAX
) || !sleep_type_a
|| !sleep_type_b
) {
489 return_ACPI_STATUS(AE_BAD_PARAMETER
);
492 /* Allocate the evaluation information block */
494 info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info
));
496 return_ACPI_STATUS(AE_NO_MEMORY
);
500 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names
[sleep_state
]);
502 /* Evaluate the namespace object containing the values for this state */
504 status
= acpi_ns_evaluate(info
);
505 if (ACPI_FAILURE(status
)) {
506 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
507 "%s while evaluating SleepState [%s]\n",
508 acpi_format_exception(status
),
514 /* Must have a return object */
516 if (!info
->return_object
) {
517 ACPI_ERROR((AE_INFO
, "No Sleep State object returned from [%s]",
519 status
= AE_NOT_EXIST
;
522 /* It must be of type Package */
524 else if (info
->return_object
->common
.type
!= ACPI_TYPE_PACKAGE
) {
526 "Sleep State return object is not a Package"));
527 status
= AE_AML_OPERAND_TYPE
;
531 * The package must have at least two elements. NOTE (March 2005): This
532 * goes against the current ACPI spec which defines this object as a
533 * package with one encoded DWORD element. However, existing practice
534 * by BIOS vendors seems to be to have 2 or more elements, at least
535 * one per sleep type (A/B).
537 else if (info
->return_object
->package
.count
< 2) {
539 "Sleep State return package does not have at least two elements"));
540 status
= AE_AML_NO_OPERAND
;
543 /* The first two elements must both be of type Integer */
545 else if (((info
->return_object
->package
.elements
[0])->common
.type
546 != ACPI_TYPE_INTEGER
) ||
547 ((info
->return_object
->package
.elements
[1])->common
.type
548 != ACPI_TYPE_INTEGER
)) {
550 "Sleep State return package elements are not both Integers (%s, %s)",
551 acpi_ut_get_object_type_name(info
->return_object
->
552 package
.elements
[0]),
553 acpi_ut_get_object_type_name(info
->return_object
->
554 package
.elements
[1])));
555 status
= AE_AML_OPERAND_TYPE
;
557 /* Valid _Sx_ package size, type, and value */
560 (info
->return_object
->package
.elements
[0])->integer
.value
;
562 (info
->return_object
->package
.elements
[1])->integer
.value
;
565 if (ACPI_FAILURE(status
)) {
566 ACPI_EXCEPTION((AE_INFO
, status
,
567 "While evaluating SleepState [%s], bad Sleep object %p type %s",
568 info
->pathname
, info
->return_object
,
569 acpi_ut_get_object_type_name(info
->
573 acpi_ut_remove_reference(info
->return_object
);
577 return_ACPI_STATUS(status
);
580 ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data
)