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
111 * a non-zero address within. However, don't return an error
112 * because the PM1A/B code must not fail if B isn't present.
118 /* Get a local copy of the address. Handles possible alignment issues */
120 ACPI_MOVE_64_TO_64(&address, ®->address);
125 /* Supported widths are 8/16/32 */
127 width = reg->bit_width;
128 if ((width != 8) && (width != 16) && (width != 32)) {
132 /* Initialize entire 32-bit return value to zero */
137 * Two address spaces supported: Memory or IO.
138 * PCI_Config is not supported here because the GAS struct is insufficient
140 switch (reg->space_id) {
141 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
143 status = acpi_os_read_memory((acpi_physical_address) address,
147 case ACPI_ADR_SPACE_SYSTEM_IO:
150 acpi_os_read_port((acpi_io_address) address, value, width);
155 "Unsupported address space: %X", reg->space_id));
156 return (AE_BAD_PARAMETER);
159 ACPI_DEBUG_PRINT((ACPI_DB_IO,
160 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
161 *value, width, ACPI_FORMAT_UINT64(address),
162 acpi_ut_get_region_name(reg->space_id)));
167 ACPI_EXPORT_SYMBOL(acpi_read)
169 /******************************************************************************
171 * FUNCTION: acpi_write
173 * PARAMETERS: Value - To be written
174 * Reg - GAS register structure
178 * DESCRIPTION: Write to either memory or IO space.
180 ******************************************************************************/
181 acpi_status acpi_write(u32 value, struct acpi_generic_address *reg)
187 ACPI_FUNCTION_NAME(acpi_write);
190 * Must have a valid pointer to a GAS structure, and
191 * a non-zero address within. However, don't return an error
192 * because the PM1A/B code must not fail if B isn't present.
198 /* Get a local copy of the address. Handles possible alignment issues */
200 ACPI_MOVE_64_TO_64(&address, ®->address);
205 /* Supported widths are 8/16/32 */
207 width = reg->bit_width;
208 if ((width != 8) && (width != 16) && (width != 32)) {
213 * Two address spaces supported: Memory or IO.
214 * PCI_Config is not supported here because the GAS struct is insufficient
216 switch (reg->space_id) {
217 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
219 status = acpi_os_write_memory((acpi_physical_address) address,
223 case ACPI_ADR_SPACE_SYSTEM_IO:
225 status = acpi_os_write_port((acpi_io_address) address, value,
231 "Unsupported address space: %X", reg->space_id));
232 return (AE_BAD_PARAMETER);
235 ACPI_DEBUG_PRINT((ACPI_DB_IO,
236 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
237 value, width, ACPI_FORMAT_UINT64(address),
238 acpi_ut_get_region_name(reg->space_id)));
243 ACPI_EXPORT_SYMBOL(acpi_write)
245 /*******************************************************************************
247 * FUNCTION: acpi_get_register_unlocked
249 * PARAMETERS: register_id - ID of ACPI bit_register to access
250 * return_value - Value that was read from the register
252 * RETURN: Status and the value read from specified Register. Value
253 * returned is normalized to bit0 (is shifted all the way right)
255 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
257 ******************************************************************************/
258 acpi_status acpi_get_register_unlocked(u32 register_id, u32 *return_value)
260 u32 register_value = 0;
261 struct acpi_bit_register_info *bit_reg_info;
264 ACPI_FUNCTION_TRACE(acpi_get_register_unlocked);
266 /* Get the info structure corresponding to the requested ACPI Register */
268 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
270 return_ACPI_STATUS(AE_BAD_PARAMETER);
273 /* Read from the register */
275 status = acpi_hw_register_read(bit_reg_info->parent_register,
278 if (ACPI_SUCCESS(status)) {
280 /* Normalize the value that was read */
283 ((register_value & bit_reg_info->access_bit_mask)
284 >> bit_reg_info->bit_position);
286 *return_value = register_value;
288 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
290 bit_reg_info->parent_register));
293 return_ACPI_STATUS(status);
296 ACPI_EXPORT_SYMBOL(acpi_get_register_unlocked)
298 /*******************************************************************************
300 * FUNCTION: acpi_get_register
302 * PARAMETERS: register_id - ID of ACPI bit_register to access
303 * return_value - Value that was read from the register
305 * RETURN: Status and the value read from specified Register. Value
306 * returned is normalized to bit0 (is shifted all the way right)
308 * DESCRIPTION: ACPI bit_register read function.
310 ******************************************************************************/
311 acpi_status acpi_get_register(u32 register_id, u32 *return_value)
314 acpi_cpu_flags flags;
316 flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
317 status = acpi_get_register_unlocked(register_id, return_value);
318 acpi_os_release_lock(acpi_gbl_hardware_lock, flags);
323 ACPI_EXPORT_SYMBOL(acpi_get_register)
325 /*******************************************************************************
327 * FUNCTION: acpi_set_register
329 * PARAMETERS: register_id - ID of ACPI bit_register to access
330 * Value - (only used on write) value to write to the
331 * Register, NOT pre-normalized to the bit pos
335 * DESCRIPTION: ACPI Bit Register write function.
337 ******************************************************************************/
338 acpi_status acpi_set_register(u32 register_id, u32 value)
340 u32 register_value = 0;
341 struct acpi_bit_register_info *bit_reg_info;
343 acpi_cpu_flags lock_flags;
345 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id);
347 /* Get the info structure corresponding to the requested ACPI Register */
349 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
351 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
353 return_ACPI_STATUS(AE_BAD_PARAMETER);
356 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
358 /* Always do a register read first so we can insert the new bits */
360 status = acpi_hw_register_read(bit_reg_info->parent_register,
362 if (ACPI_FAILURE(status)) {
363 goto unlock_and_exit;
367 * Decode the Register ID
368 * Register ID = [Register block ID] | [bit ID]
370 * Check bit ID to fine locate Register offset.
371 * Check Mask to determine Register offset, and then read-write.
373 switch (bit_reg_info->parent_register) {
374 case ACPI_REGISTER_PM1_STATUS:
377 * Status Registers are different from the rest. Clear by
378 * writing 1, and writing 0 has no effect. So, the only relevant
379 * information is the single bit we're interested in, all others should
380 * be written as 0 so they will be left unchanged.
382 value = ACPI_REGISTER_PREPARE_BITS(value,
383 bit_reg_info->bit_position,
388 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
394 case ACPI_REGISTER_PM1_ENABLE:
396 ACPI_REGISTER_INSERT_VALUE(register_value,
397 bit_reg_info->bit_position,
398 bit_reg_info->access_bit_mask,
401 status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE,
402 (u16) register_value);
405 case ACPI_REGISTER_PM1_CONTROL:
408 * Write the PM1 Control register.
409 * Note that at this level, the fact that there are actually TWO
410 * registers (A and B - and B may not exist) is abstracted.
412 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
415 ACPI_REGISTER_INSERT_VALUE(register_value,
416 bit_reg_info->bit_position,
417 bit_reg_info->access_bit_mask,
420 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
421 (u16) register_value);
424 case ACPI_REGISTER_PM2_CONTROL:
426 status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL,
428 if (ACPI_FAILURE(status)) {
429 goto unlock_and_exit;
432 ACPI_DEBUG_PRINT((ACPI_DB_IO,
433 "PM2 control: Read %X from %8.8X%8.8X\n",
435 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
439 ACPI_REGISTER_INSERT_VALUE(register_value,
440 bit_reg_info->bit_position,
441 bit_reg_info->access_bit_mask,
444 ACPI_DEBUG_PRINT((ACPI_DB_IO,
445 "About to write %4.4X to %8.8X%8.8X\n",
447 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
451 status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL,
452 (u8) (register_value));
461 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
463 /* Normalize the value that was read */
465 ACPI_DEBUG_EXEC(register_value =
466 ((register_value & bit_reg_info->access_bit_mask) >>
467 bit_reg_info->bit_position));
469 ACPI_DEBUG_PRINT((ACPI_DB_IO,
470 "Set bits: %8.8X actual %8.8X register %X\n", value,
471 register_value, bit_reg_info->parent_register));
472 return_ACPI_STATUS(status);
475 ACPI_EXPORT_SYMBOL(acpi_set_register)
477 /*******************************************************************************
479 * FUNCTION: acpi_get_sleep_type_data
481 * PARAMETERS: sleep_state - Numeric sleep state
482 * *sleep_type_a - Where SLP_TYPa is returned
483 * *sleep_type_b - Where SLP_TYPb is returned
485 * RETURN: Status - ACPI status
487 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
490 ******************************************************************************/
492 acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
494 acpi_status status = AE_OK;
495 struct acpi_evaluate_info *info;
497 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
499 /* Validate parameters */
501 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
502 return_ACPI_STATUS(AE_BAD_PARAMETER);
505 /* Allocate the evaluation information block */
507 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
509 return_ACPI_STATUS(AE_NO_MEMORY);
513 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
515 /* Evaluate the namespace object containing the values for this state */
517 status = acpi_ns_evaluate(info);
518 if (ACPI_FAILURE(status)) {
519 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
520 "%s while evaluating SleepState [%s]\n",
521 acpi_format_exception(status),
527 /* Must have a return object */
529 if (!info->return_object) {
530 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
532 status = AE_NOT_EXIST;
535 /* It must be of type Package */
537 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
539 "Sleep State return object is not a Package"));
540 status = AE_AML_OPERAND_TYPE;
544 * The package must have at least two elements. NOTE (March 2005): This
545 * goes against the current ACPI spec which defines this object as a
546 * package with one encoded DWORD element. However, existing practice
547 * by BIOS vendors seems to be to have 2 or more elements, at least
548 * one per sleep type (A/B).
550 else if (info->return_object->package.count < 2) {
552 "Sleep State return package does not have at least two elements"));
553 status = AE_AML_NO_OPERAND;
556 /* The first two elements must both be of type Integer */
558 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
559 != ACPI_TYPE_INTEGER) ||
560 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
561 != ACPI_TYPE_INTEGER)) {
563 "Sleep State return package elements are not both Integers (%s, %s)",
564 acpi_ut_get_object_type_name(info->return_object->
565 package.elements[0]),
566 acpi_ut_get_object_type_name(info->return_object->
567 package.elements[1])));
568 status = AE_AML_OPERAND_TYPE;
570 /* Valid _Sx_ package size, type, and value */
573 (info->return_object->package.elements[0])->integer.value;
575 (info->return_object->package.elements[1])->integer.value;
578 if (ACPI_FAILURE(status)) {
579 ACPI_EXCEPTION((AE_INFO, status,
580 "While evaluating SleepState [%s], bad Sleep object %p type %s",
581 info->pathname, info->return_object,
582 acpi_ut_get_object_type_name(info->
586 acpi_ut_remove_reference(info->return_object);
590 return_ACPI_STATUS(status);
593 ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)