[PATCH] selinux: endian notations
[linux-ginger.git] / drivers / acpi / hardware / hwregs.c
blob6d9e4eb848361539bce2d394279d37d7ce8389ab
2 /*******************************************************************************
4 * Module Name: hwregs - Read/write access functions for the various ACPI
5 * control and status registers.
7 ******************************************************************************/
9 /*
10 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions, and the following disclaimer,
18 * without modification.
19 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
20 * substantially similar to the "NO WARRANTY" disclaimer below
21 * ("Disclaimer") and any redistribution must be conditioned upon
22 * including a substantially similar Disclaimer requirement for further
23 * binary redistribution.
24 * 3. Neither the names of the above-listed copyright holders nor the names
25 * of any contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * Alternatively, this software may be distributed under the terms of the
29 * GNU General Public License ("GPL") version 2 as published by the Free
30 * Software Foundation.
32 * NO WARRANTY
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGES.
46 #include <linux/module.h>
48 #include <acpi/acpi.h>
49 #include <acpi/acnamesp.h>
50 #include <acpi/acevents.h>
52 #define _COMPONENT ACPI_HARDWARE
53 ACPI_MODULE_NAME ("hwregs")
56 /*******************************************************************************
58 * FUNCTION: acpi_hw_clear_acpi_status
60 * PARAMETERS: Flags - Lock the hardware or not
62 * RETURN: none
64 * DESCRIPTION: Clears all fixed and general purpose status bits
65 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
67 ******************************************************************************/
69 acpi_status
70 acpi_hw_clear_acpi_status (
71 u32 flags)
73 acpi_status status;
76 ACPI_FUNCTION_TRACE ("hw_clear_acpi_status");
79 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n",
80 ACPI_BITMASK_ALL_FIXED_STATUS,
81 (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
83 if (flags & ACPI_MTX_LOCK) {
84 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
85 if (ACPI_FAILURE (status)) {
86 return_ACPI_STATUS (status);
90 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
91 ACPI_REGISTER_PM1_STATUS,
92 ACPI_BITMASK_ALL_FIXED_STATUS);
93 if (ACPI_FAILURE (status)) {
94 goto unlock_and_exit;
97 /* Clear the fixed events */
99 if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
100 status = acpi_hw_low_level_write (16, ACPI_BITMASK_ALL_FIXED_STATUS,
101 &acpi_gbl_FADT->xpm1b_evt_blk);
102 if (ACPI_FAILURE (status)) {
103 goto unlock_and_exit;
107 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
109 status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, ACPI_ISR);
111 unlock_and_exit:
112 if (flags & ACPI_MTX_LOCK) {
113 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
115 return_ACPI_STATUS (status);
119 /*******************************************************************************
121 * FUNCTION: acpi_get_sleep_type_data
123 * PARAMETERS: sleep_state - Numeric sleep state
124 * *sleep_type_a - Where SLP_TYPa is returned
125 * *sleep_type_b - Where SLP_TYPb is returned
127 * RETURN: Status - ACPI status
129 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
130 * state.
132 ******************************************************************************/
134 acpi_status
135 acpi_get_sleep_type_data (
136 u8 sleep_state,
137 u8 *sleep_type_a,
138 u8 *sleep_type_b)
140 acpi_status status = AE_OK;
141 struct acpi_parameter_info info;
142 char *sleep_state_name;
145 ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
148 /* Validate parameters */
150 if ((sleep_state > ACPI_S_STATES_MAX) ||
151 !sleep_type_a || !sleep_type_b) {
152 return_ACPI_STATUS (AE_BAD_PARAMETER);
155 /* Evaluate the namespace object containing the values for this state */
157 info.parameters = NULL;
158 info.return_object = NULL;
159 sleep_state_name = (char *) acpi_gbl_sleep_state_names[sleep_state];
161 status = acpi_ns_evaluate_by_name (sleep_state_name, &info);
162 if (ACPI_FAILURE (status)) {
163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
164 "%s while evaluating sleep_state [%s]\n",
165 acpi_format_exception (status), sleep_state_name));
167 return_ACPI_STATUS (status);
170 /* Must have a return object */
172 if (!info.return_object) {
173 ACPI_REPORT_ERROR (("No Sleep State object returned from [%s]\n",
174 sleep_state_name));
175 status = AE_NOT_EXIST;
178 /* It must be of type Package */
180 else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) {
181 ACPI_REPORT_ERROR (("Sleep State return object is not a Package\n"));
182 status = AE_AML_OPERAND_TYPE;
186 * The package must have at least two elements. NOTE (March 2005): This
187 * goes against the current ACPI spec which defines this object as a
188 * package with one encoded DWORD element. However, existing practice
189 * by BIOS vendors seems to be to have 2 or more elements, at least
190 * one per sleep type (A/B).
192 else if (info.return_object->package.count < 2) {
193 ACPI_REPORT_ERROR ((
194 "Sleep State return package does not have at least two elements\n"));
195 status = AE_AML_NO_OPERAND;
198 /* The first two elements must both be of type Integer */
200 else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0])
201 != ACPI_TYPE_INTEGER) ||
202 (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1])
203 != ACPI_TYPE_INTEGER)) {
204 ACPI_REPORT_ERROR ((
205 "Sleep State return package elements are not both Integers (%s, %s)\n",
206 acpi_ut_get_object_type_name (info.return_object->package.elements[0]),
207 acpi_ut_get_object_type_name (info.return_object->package.elements[1])));
208 status = AE_AML_OPERAND_TYPE;
210 else {
211 /* Valid _Sx_ package size, type, and value */
213 *sleep_type_a = (u8)
214 (info.return_object->package.elements[0])->integer.value;
215 *sleep_type_b = (u8)
216 (info.return_object->package.elements[1])->integer.value;
219 if (ACPI_FAILURE (status)) {
220 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
221 "%s While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
222 acpi_format_exception (status),
223 sleep_state_name, info.return_object,
224 acpi_ut_get_object_type_name (info.return_object)));
227 acpi_ut_remove_reference (info.return_object);
228 return_ACPI_STATUS (status);
230 EXPORT_SYMBOL(acpi_get_sleep_type_data);
233 /*******************************************************************************
235 * FUNCTION: acpi_hw_get_register_bit_mask
237 * PARAMETERS: register_id - Index of ACPI Register to access
239 * RETURN: The bitmask to be used when accessing the register
241 * DESCRIPTION: Map register_id into a register bitmask.
243 ******************************************************************************/
245 struct acpi_bit_register_info *
246 acpi_hw_get_bit_register_info (
247 u32 register_id)
249 ACPI_FUNCTION_NAME ("hw_get_bit_register_info");
252 if (register_id > ACPI_BITREG_MAX) {
253 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid bit_register ID: %X\n", register_id));
254 return (NULL);
257 return (&acpi_gbl_bit_register_info[register_id]);
261 /*******************************************************************************
263 * FUNCTION: acpi_get_register
265 * PARAMETERS: register_id - ID of ACPI bit_register to access
266 * return_value - Value that was read from the register
267 * Flags - Lock the hardware or not
269 * RETURN: Status and the value read from specified Register. Value
270 * returned is normalized to bit0 (is shifted all the way right)
272 * DESCRIPTION: ACPI bit_register read function.
274 ******************************************************************************/
276 acpi_status
277 acpi_get_register (
278 u32 register_id,
279 u32 *return_value,
280 u32 flags)
282 u32 register_value = 0;
283 struct acpi_bit_register_info *bit_reg_info;
284 acpi_status status;
287 ACPI_FUNCTION_TRACE ("acpi_get_register");
290 /* Get the info structure corresponding to the requested ACPI Register */
292 bit_reg_info = acpi_hw_get_bit_register_info (register_id);
293 if (!bit_reg_info) {
294 return_ACPI_STATUS (AE_BAD_PARAMETER);
297 if (flags & ACPI_MTX_LOCK) {
298 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
299 if (ACPI_FAILURE (status)) {
300 return_ACPI_STATUS (status);
304 /* Read from the register */
306 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
307 bit_reg_info->parent_register, &register_value);
309 if (flags & ACPI_MTX_LOCK) {
310 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
313 if (ACPI_SUCCESS (status)) {
314 /* Normalize the value that was read */
316 register_value = ((register_value & bit_reg_info->access_bit_mask)
317 >> bit_reg_info->bit_position);
319 *return_value = register_value;
321 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read value %8.8X register %X\n",
322 register_value, bit_reg_info->parent_register));
325 return_ACPI_STATUS (status);
327 EXPORT_SYMBOL(acpi_get_register);
330 /*******************************************************************************
332 * FUNCTION: acpi_set_register
334 * PARAMETERS: register_id - ID of ACPI bit_register to access
335 * Value - (only used on write) value to write to the
336 * Register, NOT pre-normalized to the bit pos
337 * Flags - Lock the hardware or not
339 * RETURN: Status
341 * DESCRIPTION: ACPI Bit Register write function.
343 ******************************************************************************/
345 acpi_status
346 acpi_set_register (
347 u32 register_id,
348 u32 value,
349 u32 flags)
351 u32 register_value = 0;
352 struct acpi_bit_register_info *bit_reg_info;
353 acpi_status status;
356 ACPI_FUNCTION_TRACE_U32 ("acpi_set_register", register_id);
359 /* Get the info structure corresponding to the requested ACPI Register */
361 bit_reg_info = acpi_hw_get_bit_register_info (register_id);
362 if (!bit_reg_info) {
363 ACPI_REPORT_ERROR (("Bad ACPI HW register_id: %X\n", register_id));
364 return_ACPI_STATUS (AE_BAD_PARAMETER);
367 if (flags & ACPI_MTX_LOCK) {
368 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
369 if (ACPI_FAILURE (status)) {
370 return_ACPI_STATUS (status);
374 /* Always do a register read first so we can insert the new bits */
376 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
377 bit_reg_info->parent_register, &register_value);
378 if (ACPI_FAILURE (status)) {
379 goto unlock_and_exit;
383 * Decode the Register ID
384 * Register ID = [Register block ID] | [bit ID]
386 * Check bit ID to fine locate Register offset.
387 * Check Mask to determine Register offset, and then read-write.
389 switch (bit_reg_info->parent_register) {
390 case ACPI_REGISTER_PM1_STATUS:
393 * Status Registers are different from the rest. Clear by
394 * writing 1, and writing 0 has no effect. So, the only relevant
395 * information is the single bit we're interested in, all others should
396 * be written as 0 so they will be left unchanged.
398 value = ACPI_REGISTER_PREPARE_BITS (value,
399 bit_reg_info->bit_position, bit_reg_info->access_bit_mask);
400 if (value) {
401 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
402 ACPI_REGISTER_PM1_STATUS, (u16) value);
403 register_value = 0;
405 break;
408 case ACPI_REGISTER_PM1_ENABLE:
410 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
411 bit_reg_info->access_bit_mask, value);
413 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
414 ACPI_REGISTER_PM1_ENABLE, (u16) register_value);
415 break;
418 case ACPI_REGISTER_PM1_CONTROL:
421 * Write the PM1 Control register.
422 * Note that at this level, the fact that there are actually TWO
423 * registers (A and B - and B may not exist) is abstracted.
425 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM1 control: Read %X\n", register_value));
427 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
428 bit_reg_info->access_bit_mask, value);
430 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
431 ACPI_REGISTER_PM1_CONTROL, (u16) register_value);
432 break;
435 case ACPI_REGISTER_PM2_CONTROL:
437 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
438 ACPI_REGISTER_PM2_CONTROL, &register_value);
439 if (ACPI_FAILURE (status)) {
440 goto unlock_and_exit;
443 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
444 register_value,
445 ACPI_FORMAT_UINT64 (
446 acpi_gbl_FADT->xpm2_cnt_blk.address)));
448 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
449 bit_reg_info->access_bit_mask, value);
451 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
452 register_value,
453 ACPI_FORMAT_UINT64 (
454 acpi_gbl_FADT->xpm2_cnt_blk.address)));
456 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
457 ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
458 break;
461 default:
462 break;
466 unlock_and_exit:
468 if (flags & ACPI_MTX_LOCK) {
469 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
472 /* Normalize the value that was read */
474 ACPI_DEBUG_EXEC (register_value =
475 ((register_value & bit_reg_info->access_bit_mask) >>
476 bit_reg_info->bit_position));
478 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
479 value, register_value, bit_reg_info->parent_register));
480 return_ACPI_STATUS (status);
482 EXPORT_SYMBOL(acpi_set_register);
485 /******************************************************************************
487 * FUNCTION: acpi_hw_register_read
489 * PARAMETERS: use_lock - Mutex hw access
490 * register_id - register_iD + Offset
491 * return_value - Where the register value is returned
493 * RETURN: Status and the value read.
495 * DESCRIPTION: Acpi register read function. Registers are read at the
496 * given offset.
498 ******************************************************************************/
500 acpi_status
501 acpi_hw_register_read (
502 u8 use_lock,
503 u32 register_id,
504 u32 *return_value)
506 u32 value1 = 0;
507 u32 value2 = 0;
508 acpi_status status;
511 ACPI_FUNCTION_TRACE ("hw_register_read");
514 if (ACPI_MTX_LOCK == use_lock) {
515 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
516 if (ACPI_FAILURE (status)) {
517 return_ACPI_STATUS (status);
521 switch (register_id) {
522 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
524 status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_evt_blk);
525 if (ACPI_FAILURE (status)) {
526 goto unlock_and_exit;
529 /* PM1B is optional */
531 status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_evt_blk);
532 value1 |= value2;
533 break;
536 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
538 status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_xpm1a_enable);
539 if (ACPI_FAILURE (status)) {
540 goto unlock_and_exit;
543 /* PM1B is optional */
545 status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_xpm1b_enable);
546 value1 |= value2;
547 break;
550 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
552 status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_cnt_blk);
553 if (ACPI_FAILURE (status)) {
554 goto unlock_and_exit;
557 status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_cnt_blk);
558 value1 |= value2;
559 break;
562 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
564 status = acpi_hw_low_level_read (8, &value1, &acpi_gbl_FADT->xpm2_cnt_blk);
565 break;
568 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
570 status = acpi_hw_low_level_read (32, &value1, &acpi_gbl_FADT->xpm_tmr_blk);
571 break;
573 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
575 status = acpi_os_read_port (acpi_gbl_FADT->smi_cmd, &value1, 8);
576 break;
578 default:
579 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n",
580 register_id));
581 status = AE_BAD_PARAMETER;
582 break;
585 unlock_and_exit:
586 if (ACPI_MTX_LOCK == use_lock) {
587 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
590 if (ACPI_SUCCESS (status)) {
591 *return_value = value1;
594 return_ACPI_STATUS (status);
598 /******************************************************************************
600 * FUNCTION: acpi_hw_register_write
602 * PARAMETERS: use_lock - Mutex hw access
603 * register_id - register_iD + Offset
604 * Value - The value to write
606 * RETURN: Status
608 * DESCRIPTION: Acpi register Write function. Registers are written at the
609 * given offset.
611 ******************************************************************************/
613 acpi_status
614 acpi_hw_register_write (
615 u8 use_lock,
616 u32 register_id,
617 u32 value)
619 acpi_status status;
622 ACPI_FUNCTION_TRACE ("hw_register_write");
625 if (ACPI_MTX_LOCK == use_lock) {
626 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
627 if (ACPI_FAILURE (status)) {
628 return_ACPI_STATUS (status);
632 switch (register_id) {
633 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
635 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_evt_blk);
636 if (ACPI_FAILURE (status)) {
637 goto unlock_and_exit;
640 /* PM1B is optional */
642 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_evt_blk);
643 break;
646 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access*/
648 status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1a_enable);
649 if (ACPI_FAILURE (status)) {
650 goto unlock_and_exit;
653 /* PM1B is optional */
655 status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1b_enable);
656 break;
659 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
661 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
662 if (ACPI_FAILURE (status)) {
663 goto unlock_and_exit;
666 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
667 break;
670 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
672 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
673 break;
676 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
678 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
679 break;
682 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
684 status = acpi_hw_low_level_write (8, value, &acpi_gbl_FADT->xpm2_cnt_blk);
685 break;
688 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
690 status = acpi_hw_low_level_write (32, value, &acpi_gbl_FADT->xpm_tmr_blk);
691 break;
694 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
696 /* SMI_CMD is currently always in IO space */
698 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, value, 8);
699 break;
702 default:
703 status = AE_BAD_PARAMETER;
704 break;
707 unlock_and_exit:
708 if (ACPI_MTX_LOCK == use_lock) {
709 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
712 return_ACPI_STATUS (status);
716 /******************************************************************************
718 * FUNCTION: acpi_hw_low_level_read
720 * PARAMETERS: Width - 8, 16, or 32
721 * Value - Where the value is returned
722 * Reg - GAS register structure
724 * RETURN: Status
726 * DESCRIPTION: Read from either memory or IO space.
728 ******************************************************************************/
730 acpi_status
731 acpi_hw_low_level_read (
732 u32 width,
733 u32 *value,
734 struct acpi_generic_address *reg)
736 u64 address;
737 acpi_status status;
740 ACPI_FUNCTION_NAME ("hw_low_level_read");
744 * Must have a valid pointer to a GAS structure, and
745 * a non-zero address within. However, don't return an error
746 * because the PM1A/B code must not fail if B isn't present.
748 if (!reg) {
749 return (AE_OK);
752 /* Get a local copy of the address. Handles possible alignment issues */
754 ACPI_MOVE_64_TO_64 (&address, &reg->address);
755 if (!address) {
756 return (AE_OK);
758 *value = 0;
761 * Two address spaces supported: Memory or IO.
762 * PCI_Config is not supported here because the GAS struct is insufficient
764 switch (reg->address_space_id) {
765 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
767 status = acpi_os_read_memory (
768 (acpi_physical_address) address,
769 value, width);
770 break;
773 case ACPI_ADR_SPACE_SYSTEM_IO:
775 status = acpi_os_read_port ((acpi_io_address) address,
776 value, width);
777 break;
780 default:
781 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
782 "Unsupported address space: %X\n", reg->address_space_id));
783 return (AE_BAD_PARAMETER);
786 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
787 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
788 *value, width,
789 ACPI_FORMAT_UINT64 (address),
790 acpi_ut_get_region_name (reg->address_space_id)));
792 return (status);
796 /******************************************************************************
798 * FUNCTION: acpi_hw_low_level_write
800 * PARAMETERS: Width - 8, 16, or 32
801 * Value - To be written
802 * Reg - GAS register structure
804 * RETURN: Status
806 * DESCRIPTION: Write to either memory or IO space.
808 ******************************************************************************/
810 acpi_status
811 acpi_hw_low_level_write (
812 u32 width,
813 u32 value,
814 struct acpi_generic_address *reg)
816 u64 address;
817 acpi_status status;
820 ACPI_FUNCTION_NAME ("hw_low_level_write");
824 * Must have a valid pointer to a GAS structure, and
825 * a non-zero address within. However, don't return an error
826 * because the PM1A/B code must not fail if B isn't present.
828 if (!reg) {
829 return (AE_OK);
832 /* Get a local copy of the address. Handles possible alignment issues */
834 ACPI_MOVE_64_TO_64 (&address, &reg->address);
835 if (!address) {
836 return (AE_OK);
840 * Two address spaces supported: Memory or IO.
841 * PCI_Config is not supported here because the GAS struct is insufficient
843 switch (reg->address_space_id) {
844 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
846 status = acpi_os_write_memory (
847 (acpi_physical_address) address,
848 value, width);
849 break;
852 case ACPI_ADR_SPACE_SYSTEM_IO:
854 status = acpi_os_write_port ((acpi_io_address) address,
855 value, width);
856 break;
859 default:
860 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
861 "Unsupported address space: %X\n", reg->address_space_id));
862 return (AE_BAD_PARAMETER);
865 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
866 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
867 value, width,
868 ACPI_FORMAT_UINT64 (address),
869 acpi_ut_get_region_name (reg->address_space_id)));
871 return (status);