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>
46 #include <acpi/acnamesp.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME("hwxface")
51 /******************************************************************************
55 * PARAMETERS: Value - Where the value is returned
56 * Reg - GAS register structure
60 * DESCRIPTION: Read from either memory or IO space.
62 ******************************************************************************/
63 acpi_status
acpi_read(u32
*value
, struct acpi_generic_address
*reg
)
69 ACPI_FUNCTION_NAME(acpi_read
);
72 * Must have a valid pointer to a GAS structure, and
73 * a non-zero address within. However, don't return an error
74 * because the PM1A/B code must not fail if B isn't present.
80 /* Get a local copy of the address. Handles possible alignment issues */
82 ACPI_MOVE_64_TO_64(&address
, ®
->address
);
87 /* Supported widths are 8/16/32 */
89 width
= reg
->bit_width
;
90 if ((width
!= 8) && (width
!= 16) && (width
!= 32)) {
94 /* Initialize entire 32-bit return value to zero */
99 * Two address spaces supported: Memory or IO.
100 * PCI_Config is not supported here because the GAS struct is insufficient
102 switch (reg
->space_id
) {
103 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
105 status
= acpi_os_read_memory((acpi_physical_address
) address
,
109 case ACPI_ADR_SPACE_SYSTEM_IO
:
112 acpi_os_read_port((acpi_io_address
) address
, value
, width
);
117 "Unsupported address space: %X", reg
->space_id
));
118 return (AE_BAD_PARAMETER
);
121 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
122 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
123 *value
, width
, ACPI_FORMAT_UINT64(address
),
124 acpi_ut_get_region_name(reg
->space_id
)));
129 ACPI_EXPORT_SYMBOL(acpi_read
)
131 /******************************************************************************
133 * FUNCTION: acpi_write
135 * PARAMETERS: Value - To be written
136 * Reg - GAS register structure
140 * DESCRIPTION: Write to either memory or IO space.
142 ******************************************************************************/
143 acpi_status
acpi_write(u32 value
, struct acpi_generic_address
*reg
)
149 ACPI_FUNCTION_NAME(acpi_write
);
152 * Must have a valid pointer to a GAS structure, and
153 * a non-zero address within. However, don't return an error
154 * because the PM1A/B code must not fail if B isn't present.
160 /* Get a local copy of the address. Handles possible alignment issues */
162 ACPI_MOVE_64_TO_64(&address
, ®
->address
);
167 /* Supported widths are 8/16/32 */
169 width
= reg
->bit_width
;
170 if ((width
!= 8) && (width
!= 16) && (width
!= 32)) {
175 * Two address spaces supported: Memory or IO.
176 * PCI_Config is not supported here because the GAS struct is insufficient
178 switch (reg
->space_id
) {
179 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
181 status
= acpi_os_write_memory((acpi_physical_address
) address
,
185 case ACPI_ADR_SPACE_SYSTEM_IO
:
187 status
= acpi_os_write_port((acpi_io_address
) address
, value
,
193 "Unsupported address space: %X", reg
->space_id
));
194 return (AE_BAD_PARAMETER
);
197 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
198 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
199 value
, width
, ACPI_FORMAT_UINT64(address
),
200 acpi_ut_get_region_name(reg
->space_id
)));
205 ACPI_EXPORT_SYMBOL(acpi_write
)
207 /*******************************************************************************
209 * FUNCTION: acpi_get_register_unlocked
211 * PARAMETERS: register_id - ID of ACPI bit_register to access
212 * return_value - Value that was read from the register
214 * RETURN: Status and the value read from specified Register. Value
215 * returned is normalized to bit0 (is shifted all the way right)
217 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
219 ******************************************************************************/
220 acpi_status
acpi_get_register_unlocked(u32 register_id
, u32
*return_value
)
222 u32 register_value
= 0;
223 struct acpi_bit_register_info
*bit_reg_info
;
226 ACPI_FUNCTION_TRACE(acpi_get_register_unlocked
);
228 /* Get the info structure corresponding to the requested ACPI Register */
230 bit_reg_info
= acpi_hw_get_bit_register_info(register_id
);
232 return_ACPI_STATUS(AE_BAD_PARAMETER
);
235 /* Read from the register */
237 status
= acpi_hw_register_read(bit_reg_info
->parent_register
,
240 if (ACPI_SUCCESS(status
)) {
242 /* Normalize the value that was read */
245 ((register_value
& bit_reg_info
->access_bit_mask
)
246 >> bit_reg_info
->bit_position
);
248 *return_value
= register_value
;
250 ACPI_DEBUG_PRINT((ACPI_DB_IO
, "Read value %8.8X register %X\n",
252 bit_reg_info
->parent_register
));
255 return_ACPI_STATUS(status
);
258 ACPI_EXPORT_SYMBOL(acpi_get_register_unlocked
)
260 /*******************************************************************************
262 * FUNCTION: acpi_get_register
264 * PARAMETERS: register_id - ID of ACPI bit_register to access
265 * return_value - Value that was read from the register
267 * RETURN: Status and the value read from specified Register. Value
268 * returned is normalized to bit0 (is shifted all the way right)
270 * DESCRIPTION: ACPI bit_register read function.
272 ******************************************************************************/
273 acpi_status
acpi_get_register(u32 register_id
, u32
*return_value
)
276 acpi_cpu_flags flags
;
278 flags
= acpi_os_acquire_lock(acpi_gbl_hardware_lock
);
279 status
= acpi_get_register_unlocked(register_id
, return_value
);
280 acpi_os_release_lock(acpi_gbl_hardware_lock
, flags
);
285 ACPI_EXPORT_SYMBOL(acpi_get_register
)
287 /*******************************************************************************
289 * FUNCTION: acpi_set_register
291 * PARAMETERS: register_id - ID of ACPI bit_register to access
292 * Value - (only used on write) value to write to the
293 * Register, NOT pre-normalized to the bit pos
297 * DESCRIPTION: ACPI Bit Register write function.
299 ******************************************************************************/
300 acpi_status
acpi_set_register(u32 register_id
, u32 value
)
302 u32 register_value
= 0;
303 struct acpi_bit_register_info
*bit_reg_info
;
305 acpi_cpu_flags lock_flags
;
307 ACPI_FUNCTION_TRACE_U32(acpi_set_register
, register_id
);
309 /* Get the info structure corresponding to the requested ACPI Register */
311 bit_reg_info
= acpi_hw_get_bit_register_info(register_id
);
313 ACPI_ERROR((AE_INFO
, "Bad ACPI HW RegisterId: %X",
315 return_ACPI_STATUS(AE_BAD_PARAMETER
);
318 lock_flags
= acpi_os_acquire_lock(acpi_gbl_hardware_lock
);
320 /* Always do a register read first so we can insert the new bits */
322 status
= acpi_hw_register_read(bit_reg_info
->parent_register
,
324 if (ACPI_FAILURE(status
)) {
325 goto unlock_and_exit
;
329 * Decode the Register ID
330 * Register ID = [Register block ID] | [bit ID]
332 * Check bit ID to fine locate Register offset.
333 * Check Mask to determine Register offset, and then read-write.
335 switch (bit_reg_info
->parent_register
) {
336 case ACPI_REGISTER_PM1_STATUS
:
339 * Status Registers are different from the rest. Clear by
340 * writing 1, and writing 0 has no effect. So, the only relevant
341 * information is the single bit we're interested in, all others should
342 * be written as 0 so they will be left unchanged.
344 value
= ACPI_REGISTER_PREPARE_BITS(value
,
345 bit_reg_info
->bit_position
,
350 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS
,
356 case ACPI_REGISTER_PM1_ENABLE
:
358 ACPI_REGISTER_INSERT_VALUE(register_value
,
359 bit_reg_info
->bit_position
,
360 bit_reg_info
->access_bit_mask
,
363 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE
,
364 (u16
) register_value
);
367 case ACPI_REGISTER_PM1_CONTROL
:
370 * Write the PM1 Control register.
371 * Note that at this level, the fact that there are actually TWO
372 * registers (A and B - and B may not exist) is abstracted.
374 ACPI_DEBUG_PRINT((ACPI_DB_IO
, "PM1 control: Read %X\n",
377 ACPI_REGISTER_INSERT_VALUE(register_value
,
378 bit_reg_info
->bit_position
,
379 bit_reg_info
->access_bit_mask
,
382 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL
,
383 (u16
) register_value
);
386 case ACPI_REGISTER_PM2_CONTROL
:
388 status
= acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL
,
390 if (ACPI_FAILURE(status
)) {
391 goto unlock_and_exit
;
394 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
395 "PM2 control: Read %X from %8.8X%8.8X\n",
397 ACPI_FORMAT_UINT64(acpi_gbl_FADT
.
401 ACPI_REGISTER_INSERT_VALUE(register_value
,
402 bit_reg_info
->bit_position
,
403 bit_reg_info
->access_bit_mask
,
406 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
407 "About to write %4.4X to %8.8X%8.8X\n",
409 ACPI_FORMAT_UINT64(acpi_gbl_FADT
.
413 status
= acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL
,
414 (u8
) (register_value
));
423 acpi_os_release_lock(acpi_gbl_hardware_lock
, lock_flags
);
425 /* Normalize the value that was read */
427 ACPI_DEBUG_EXEC(register_value
=
428 ((register_value
& bit_reg_info
->access_bit_mask
) >>
429 bit_reg_info
->bit_position
));
431 ACPI_DEBUG_PRINT((ACPI_DB_IO
,
432 "Set bits: %8.8X actual %8.8X register %X\n", value
,
433 register_value
, bit_reg_info
->parent_register
));
434 return_ACPI_STATUS(status
);
437 ACPI_EXPORT_SYMBOL(acpi_set_register
)
439 /*******************************************************************************
441 * FUNCTION: acpi_get_sleep_type_data
443 * PARAMETERS: sleep_state - Numeric sleep state
444 * *sleep_type_a - Where SLP_TYPa is returned
445 * *sleep_type_b - Where SLP_TYPb is returned
447 * RETURN: Status - ACPI status
449 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
452 ******************************************************************************/
454 acpi_get_sleep_type_data(u8 sleep_state
, u8
*sleep_type_a
, u8
*sleep_type_b
)
456 acpi_status status
= AE_OK
;
457 struct acpi_evaluate_info
*info
;
459 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data
);
461 /* Validate parameters */
463 if ((sleep_state
> ACPI_S_STATES_MAX
) || !sleep_type_a
|| !sleep_type_b
) {
464 return_ACPI_STATUS(AE_BAD_PARAMETER
);
467 /* Allocate the evaluation information block */
469 info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info
));
471 return_ACPI_STATUS(AE_NO_MEMORY
);
475 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names
[sleep_state
]);
477 /* Evaluate the namespace object containing the values for this state */
479 status
= acpi_ns_evaluate(info
);
480 if (ACPI_FAILURE(status
)) {
481 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
482 "%s while evaluating SleepState [%s]\n",
483 acpi_format_exception(status
),
489 /* Must have a return object */
491 if (!info
->return_object
) {
492 ACPI_ERROR((AE_INFO
, "No Sleep State object returned from [%s]",
494 status
= AE_NOT_EXIST
;
497 /* It must be of type Package */
499 else if (ACPI_GET_OBJECT_TYPE(info
->return_object
) != ACPI_TYPE_PACKAGE
) {
501 "Sleep State return object is not a Package"));
502 status
= AE_AML_OPERAND_TYPE
;
506 * The package must have at least two elements. NOTE (March 2005): This
507 * goes against the current ACPI spec which defines this object as a
508 * package with one encoded DWORD element. However, existing practice
509 * by BIOS vendors seems to be to have 2 or more elements, at least
510 * one per sleep type (A/B).
512 else if (info
->return_object
->package
.count
< 2) {
514 "Sleep State return package does not have at least two elements"));
515 status
= AE_AML_NO_OPERAND
;
518 /* The first two elements must both be of type Integer */
520 else if ((ACPI_GET_OBJECT_TYPE(info
->return_object
->package
.elements
[0])
521 != ACPI_TYPE_INTEGER
) ||
522 (ACPI_GET_OBJECT_TYPE(info
->return_object
->package
.elements
[1])
523 != ACPI_TYPE_INTEGER
)) {
525 "Sleep State return package elements are not both Integers (%s, %s)",
526 acpi_ut_get_object_type_name(info
->return_object
->
527 package
.elements
[0]),
528 acpi_ut_get_object_type_name(info
->return_object
->
529 package
.elements
[1])));
530 status
= AE_AML_OPERAND_TYPE
;
532 /* Valid _Sx_ package size, type, and value */
535 (info
->return_object
->package
.elements
[0])->integer
.value
;
537 (info
->return_object
->package
.elements
[1])->integer
.value
;
540 if (ACPI_FAILURE(status
)) {
541 ACPI_EXCEPTION((AE_INFO
, status
,
542 "While evaluating SleepState [%s], bad Sleep object %p type %s",
543 info
->pathname
, info
->return_object
,
544 acpi_ut_get_object_type_name(info
->
548 acpi_ut_remove_reference(info
->return_object
);
552 return_ACPI_STATUS(status
);
555 ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data
)