1 /******************************************************************************
3 * Module Name: hwxface - Public ACPICA hardware interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_HARDWARE
51 ACPI_MODULE_NAME("hwxface")
53 /******************************************************************************
55 * FUNCTION: acpi_reset
61 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
62 * support reset register in PCI config space, this must be
65 ******************************************************************************/
66 acpi_status
acpi_reset(void)
68 struct acpi_generic_address
*reset_reg
;
71 ACPI_FUNCTION_TRACE(acpi_reset
);
73 reset_reg
= &acpi_gbl_FADT
.reset_register
;
75 /* Check if the reset register is supported */
77 if (!(acpi_gbl_FADT
.flags
& ACPI_FADT_RESET_REGISTER
) ||
78 !reset_reg
->address
) {
79 return_ACPI_STATUS(AE_NOT_EXIST
);
82 if (reset_reg
->space_id
== ACPI_ADR_SPACE_SYSTEM_IO
) {
84 * For I/O space, write directly to the OSL. This bypasses the port
85 * validation mechanism, which may block a valid write to the reset
89 * The ACPI spec requires the reset register width to be 8, so we
90 * hardcode it here and ignore the FADT value. This maintains
91 * compatibility with other ACPI implementations that have allowed
92 * BIOS code with bad register width values to go unnoticed.
94 status
= acpi_os_write_port((acpi_io_address
)reset_reg
->address
,
95 acpi_gbl_FADT
.reset_value
,
96 ACPI_RESET_REGISTER_WIDTH
);
98 /* Write the reset value to the reset register */
100 status
= acpi_hw_write(acpi_gbl_FADT
.reset_value
, reset_reg
);
103 return_ACPI_STATUS(status
);
106 ACPI_EXPORT_SYMBOL(acpi_reset
)
108 /******************************************************************************
110 * FUNCTION: acpi_read
112 * PARAMETERS: value - Where the value is returned
113 * reg - GAS register structure
117 * DESCRIPTION: Read from either memory or IO space.
119 * LIMITATIONS: <These limitations also apply to acpi_write>
120 * bit_width must be exactly 8, 16, 32, or 64.
121 * space_ID must be system_memory or system_IO.
122 * bit_offset and access_width are currently ignored, as there has
123 * not been a need to implement these.
125 ******************************************************************************/
126 acpi_status
acpi_read(u64
*return_value
, struct acpi_generic_address
*reg
)
134 ACPI_FUNCTION_NAME(acpi_read
);
137 return (AE_BAD_PARAMETER
);
140 /* Validate contents of the GAS register. Allow 64-bit transfers */
142 status
= acpi_hw_validate_register(reg
, 64, &address
);
143 if (ACPI_FAILURE(status
)) {
148 * Two address spaces supported: Memory or I/O. PCI_Config is
149 * not supported here because the GAS structure is insufficient
151 if (reg
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
) {
152 status
= acpi_os_read_memory((acpi_physical_address
)
153 address
, return_value
,
155 if (ACPI_FAILURE(status
)) {
158 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
163 width
= reg
->bit_width
;
165 width
= 32; /* Break into two 32-bit transfers */
168 status
= acpi_hw_read_port((acpi_io_address
)
169 address
, &value_lo
, width
);
170 if (ACPI_FAILURE(status
)) {
174 if (reg
->bit_width
== 64) {
176 /* Read the top 32 bits */
178 status
= acpi_hw_read_port((acpi_io_address
)
179 (address
+ 4), &value_hi
,
181 if (ACPI_FAILURE(status
)) {
186 /* Set the return value only if status is AE_OK */
188 *return_value
= (value_lo
| ((u64
)value_hi
<< 32));
191 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
192 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
193 ACPI_FORMAT_UINT64(*return_value
), reg
->bit_width
,
194 ACPI_FORMAT_UINT64(address
),
195 acpi_ut_get_region_name(reg
->space_id
)));
200 ACPI_EXPORT_SYMBOL(acpi_read
)
202 /******************************************************************************
204 * FUNCTION: acpi_write
206 * PARAMETERS: value - Value to be written
207 * reg - GAS register structure
211 * DESCRIPTION: Write to either memory or IO space.
213 ******************************************************************************/
214 acpi_status
acpi_write(u64 value
, struct acpi_generic_address
*reg
)
220 ACPI_FUNCTION_NAME(acpi_write
);
222 /* Validate contents of the GAS register. Allow 64-bit transfers */
224 status
= acpi_hw_validate_register(reg
, 64, &address
);
225 if (ACPI_FAILURE(status
)) {
230 * Two address spaces supported: Memory or IO. PCI_Config is
231 * not supported here because the GAS structure is insufficient
233 if (reg
->space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
) {
234 status
= acpi_os_write_memory((acpi_physical_address
)
235 address
, value
, reg
->bit_width
);
236 if (ACPI_FAILURE(status
)) {
239 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
241 width
= reg
->bit_width
;
243 width
= 32; /* Break into two 32-bit transfers */
246 status
= acpi_hw_write_port((acpi_io_address
)
247 address
, ACPI_LODWORD(value
),
249 if (ACPI_FAILURE(status
)) {
253 if (reg
->bit_width
== 64) {
254 status
= acpi_hw_write_port((acpi_io_address
)
256 ACPI_HIDWORD(value
), 32);
257 if (ACPI_FAILURE(status
)) {
263 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
264 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
265 ACPI_FORMAT_UINT64(value
), reg
->bit_width
,
266 ACPI_FORMAT_UINT64(address
),
267 acpi_ut_get_region_name(reg
->space_id
)));
272 ACPI_EXPORT_SYMBOL(acpi_write
)
274 #if (!ACPI_REDUCED_HARDWARE)
275 /*******************************************************************************
277 * FUNCTION: acpi_read_bit_register
279 * PARAMETERS: register_id - ID of ACPI Bit Register to access
280 * return_value - Value that was read from the register,
281 * normalized to bit position zero.
283 * RETURN: Status and the value read from the specified Register. Value
284 * returned is normalized to bit0 (is shifted all the way right)
286 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
288 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
291 * Note: The hardware lock is not required when reading the ACPI bit registers
292 * since almost all of them are single bit and it does not matter that
293 * the parent hardware register can be split across two physical
294 * registers. The only multi-bit field is SLP_TYP in the PM1 control
295 * register, but this field does not cross an 8-bit boundary (nor does
296 * it make much sense to actually read this field.)
298 ******************************************************************************/
299 acpi_status
acpi_read_bit_register(u32 register_id
, u32
*return_value
)
301 struct acpi_bit_register_info
*bit_reg_info
;
306 ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register
, register_id
);
308 /* Get the info structure corresponding to the requested ACPI Register */
310 bit_reg_info
= acpi_hw_get_bit_register_info(register_id
);
312 return_ACPI_STATUS(AE_BAD_PARAMETER
);
315 /* Read the entire parent register */
317 status
= acpi_hw_register_read(bit_reg_info
->parent_register
,
319 if (ACPI_FAILURE(status
)) {
320 return_ACPI_STATUS(status
);
323 /* Normalize the value that was read, mask off other bits */
325 value
= ((register_value
& bit_reg_info
->access_bit_mask
)
326 >> bit_reg_info
->bit_position
);
328 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
329 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
330 register_id
, bit_reg_info
->parent_register
,
331 register_value
, value
));
333 *return_value
= value
;
334 return_ACPI_STATUS(AE_OK
);
337 ACPI_EXPORT_SYMBOL(acpi_read_bit_register
)
339 /*******************************************************************************
341 * FUNCTION: acpi_write_bit_register
343 * PARAMETERS: register_id - ID of ACPI Bit Register to access
344 * value - Value to write to the register, in bit
345 * position zero. The bit is automatically
346 * shifted to the correct position.
350 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
351 * since most operations require a read/modify/write sequence.
353 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
356 * Note that at this level, the fact that there may be actually two
357 * hardware registers (A and B - and B may not exist) is abstracted.
359 ******************************************************************************/
360 acpi_status
acpi_write_bit_register(u32 register_id
, u32 value
)
362 struct acpi_bit_register_info
*bit_reg_info
;
363 acpi_cpu_flags lock_flags
;
365 acpi_status status
= AE_OK
;
367 ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register
, register_id
);
369 /* Get the info structure corresponding to the requested ACPI Register */
371 bit_reg_info
= acpi_hw_get_bit_register_info(register_id
);
373 return_ACPI_STATUS(AE_BAD_PARAMETER
);
376 lock_flags
= acpi_os_acquire_lock(acpi_gbl_hardware_lock
);
379 * At this point, we know that the parent register is one of the
380 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
382 if (bit_reg_info
->parent_register
!= ACPI_REGISTER_PM1_STATUS
) {
384 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
386 * Perform a register read to preserve the bits that we are not
389 status
= acpi_hw_register_read(bit_reg_info
->parent_register
,
391 if (ACPI_FAILURE(status
)) {
392 goto unlock_and_exit
;
396 * Insert the input bit into the value that was just read
397 * and write the register
399 ACPI_REGISTER_INSERT_VALUE(register_value
,
400 bit_reg_info
->bit_position
,
401 bit_reg_info
->access_bit_mask
,
404 status
= acpi_hw_register_write(bit_reg_info
->parent_register
,
408 * 2) Case for PM1 Status
410 * The Status register is different from the rest. Clear an event
411 * by writing 1, writing 0 has no effect. So, the only relevant
412 * information is the single bit we're interested in, all others
413 * should be written as 0 so they will be left unchanged.
415 register_value
= ACPI_REGISTER_PREPARE_BITS(value
,
421 /* No need to write the register if value is all zeros */
423 if (register_value
) {
425 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS
,
430 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
431 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
432 register_id
, bit_reg_info
->parent_register
, value
,
437 acpi_os_release_lock(acpi_gbl_hardware_lock
, lock_flags
);
438 return_ACPI_STATUS(status
);
441 ACPI_EXPORT_SYMBOL(acpi_write_bit_register
)
442 #endif /* !ACPI_REDUCED_HARDWARE */
443 /*******************************************************************************
445 * FUNCTION: acpi_get_sleep_type_data
447 * PARAMETERS: sleep_state - Numeric sleep state
448 * *sleep_type_a - Where SLP_TYPa is returned
449 * *sleep_type_b - Where SLP_TYPb is returned
453 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
454 * sleep state via the appropriate \_Sx object.
456 * The sleep state package returned from the corresponding \_Sx_ object
457 * must contain at least one integer.
460 * Added support for a package that contains two integers. This
461 * goes against the ACPI specification which defines this object as a
462 * package with one encoded DWORD integer. However, existing practice
463 * by many BIOS vendors is to return a package with 2 or more integer
464 * elements, at least one per sleep type (A/B).
467 * Therefore, we must be prepared to accept a package with either a
468 * single integer or multiple integers.
470 * The single integer DWORD format is as follows:
471 * BYTE 0 - Value for the PM1A SLP_TYP register
472 * BYTE 1 - Value for the PM1B SLP_TYP register
473 * BYTE 2-3 - Reserved
475 * The dual integer format is as follows:
476 * Integer 0 - Value for the PM1A SLP_TYP register
477 * Integer 1 - Value for the PM1A SLP_TYP register
479 ******************************************************************************/
481 acpi_get_sleep_type_data(u8 sleep_state
, u8
*sleep_type_a
, u8
*sleep_type_b
)
484 struct acpi_evaluate_info
*info
;
485 union acpi_operand_object
**elements
;
487 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data
);
489 /* Validate parameters */
491 if ((sleep_state
> ACPI_S_STATES_MAX
) || !sleep_type_a
|| !sleep_type_b
) {
492 return_ACPI_STATUS(AE_BAD_PARAMETER
);
495 /* Allocate the evaluation information block */
497 info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info
));
499 return_ACPI_STATUS(AE_NO_MEMORY
);
503 * Evaluate the \_Sx namespace object containing the register values
506 info
->relative_pathname
= acpi_gbl_sleep_state_names
[sleep_state
];
508 status
= acpi_ns_evaluate(info
);
509 if (ACPI_FAILURE(status
)) {
510 if (status
== AE_NOT_FOUND
) {
512 /* The _Sx states are optional, ignore NOT_FOUND */
517 goto warning_cleanup
;
520 /* Must have a return object */
522 if (!info
->return_object
) {
523 ACPI_ERROR((AE_INFO
, "No Sleep State object returned from [%s]",
524 info
->relative_pathname
));
525 status
= AE_AML_NO_RETURN_VALUE
;
526 goto warning_cleanup
;
529 /* Return object must be of type Package */
531 if (info
->return_object
->common
.type
!= ACPI_TYPE_PACKAGE
) {
533 "Sleep State return object is not a Package"));
534 status
= AE_AML_OPERAND_TYPE
;
535 goto return_value_cleanup
;
539 * Any warnings about the package length or the object types have
540 * already been issued by the predefined name module -- there is no
541 * need to repeat them here.
543 elements
= info
->return_object
->package
.elements
;
544 switch (info
->return_object
->package
.count
) {
547 status
= AE_AML_PACKAGE_LIMIT
;
552 if (elements
[0]->common
.type
!= ACPI_TYPE_INTEGER
) {
553 status
= AE_AML_OPERAND_TYPE
;
557 /* A valid _Sx_ package with one integer */
559 *sleep_type_a
= (u8
)elements
[0]->integer
.value
;
560 *sleep_type_b
= (u8
)(elements
[0]->integer
.value
>> 8);
566 if ((elements
[0]->common
.type
!= ACPI_TYPE_INTEGER
) ||
567 (elements
[1]->common
.type
!= ACPI_TYPE_INTEGER
)) {
568 status
= AE_AML_OPERAND_TYPE
;
572 /* A valid _Sx_ package with two integers */
574 *sleep_type_a
= (u8
)elements
[0]->integer
.value
;
575 *sleep_type_b
= (u8
)elements
[1]->integer
.value
;
579 return_value_cleanup
:
580 acpi_ut_remove_reference(info
->return_object
);
583 if (ACPI_FAILURE(status
)) {
584 ACPI_EXCEPTION((AE_INFO
, status
,
585 "While evaluating Sleep State [%s]",
586 info
->relative_pathname
));
591 return_ACPI_STATUS(status
);
594 ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data
)