ACPI: drivers/acpi: elide a non-zero test on a result that is never 0
[linux/fpc-iii.git] / drivers / acpi / hardware / hwregs.c
blob73f9c5fb1ba74b54022ed1490d8fc378c693b8af
2 /*******************************************************************************
4 * Module Name: hwregs - Read/write access functions for the various ACPI
5 * control and status registers.
7 ******************************************************************************/
9 /*
10 * Copyright (C) 2000 - 2007, 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 <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
48 #include <acpi/acevents.h>
50 #define _COMPONENT ACPI_HARDWARE
51 ACPI_MODULE_NAME("hwregs")
53 /*******************************************************************************
55 * FUNCTION: acpi_hw_clear_acpi_status
57 * PARAMETERS: None
59 * RETURN: None
61 * DESCRIPTION: Clears all fixed and general purpose status bits
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
64 ******************************************************************************/
65 acpi_status acpi_hw_clear_acpi_status(void)
67 acpi_status status;
68 acpi_cpu_flags lock_flags = 0;
70 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
72 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
73 ACPI_BITMASK_ALL_FIXED_STATUS,
74 (u16) acpi_gbl_FADT.xpm1a_event_block.address));
76 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
78 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
79 ACPI_BITMASK_ALL_FIXED_STATUS);
80 if (ACPI_FAILURE(status)) {
81 goto unlock_and_exit;
84 /* Clear the fixed events */
86 if (acpi_gbl_FADT.xpm1b_event_block.address) {
87 status =
88 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
89 &acpi_gbl_FADT.xpm1b_event_block);
90 if (ACPI_FAILURE(status)) {
91 goto unlock_and_exit;
95 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
97 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
99 unlock_and_exit:
100 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
101 return_ACPI_STATUS(status);
104 /*******************************************************************************
106 * FUNCTION: acpi_get_sleep_type_data
108 * PARAMETERS: sleep_state - Numeric sleep state
109 * *sleep_type_a - Where SLP_TYPa is returned
110 * *sleep_type_b - Where SLP_TYPb is returned
112 * RETURN: Status - ACPI status
114 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
115 * state.
117 ******************************************************************************/
119 acpi_status
120 acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
122 acpi_status status = AE_OK;
123 struct acpi_evaluate_info *info;
125 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
127 /* Validate parameters */
129 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
130 return_ACPI_STATUS(AE_BAD_PARAMETER);
133 /* Allocate the evaluation information block */
135 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
136 if (!info) {
137 return_ACPI_STATUS(AE_NO_MEMORY);
140 info->pathname =
141 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
143 /* Evaluate the namespace object containing the values for this state */
145 status = acpi_ns_evaluate(info);
146 if (ACPI_FAILURE(status)) {
147 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
148 "%s while evaluating SleepState [%s]\n",
149 acpi_format_exception(status),
150 info->pathname));
152 goto cleanup;
155 /* Must have a return object */
157 if (!info->return_object) {
158 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
159 info->pathname));
160 status = AE_NOT_EXIST;
163 /* It must be of type Package */
165 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
166 ACPI_ERROR((AE_INFO,
167 "Sleep State return object is not a Package"));
168 status = AE_AML_OPERAND_TYPE;
172 * The package must have at least two elements. NOTE (March 2005): This
173 * goes against the current ACPI spec which defines this object as a
174 * package with one encoded DWORD element. However, existing practice
175 * by BIOS vendors seems to be to have 2 or more elements, at least
176 * one per sleep type (A/B).
178 else if (info->return_object->package.count < 2) {
179 ACPI_ERROR((AE_INFO,
180 "Sleep State return package does not have at least two elements"));
181 status = AE_AML_NO_OPERAND;
184 /* The first two elements must both be of type Integer */
186 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
187 != ACPI_TYPE_INTEGER) ||
188 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
189 != ACPI_TYPE_INTEGER)) {
190 ACPI_ERROR((AE_INFO,
191 "Sleep State return package elements are not both Integers (%s, %s)",
192 acpi_ut_get_object_type_name(info->return_object->
193 package.elements[0]),
194 acpi_ut_get_object_type_name(info->return_object->
195 package.elements[1])));
196 status = AE_AML_OPERAND_TYPE;
197 } else {
198 /* Valid _Sx_ package size, type, and value */
200 *sleep_type_a = (u8)
201 (info->return_object->package.elements[0])->integer.value;
202 *sleep_type_b = (u8)
203 (info->return_object->package.elements[1])->integer.value;
206 if (ACPI_FAILURE(status)) {
207 ACPI_EXCEPTION((AE_INFO, status,
208 "While evaluating SleepState [%s], bad Sleep object %p type %s",
209 info->pathname, info->return_object,
210 acpi_ut_get_object_type_name(info->
211 return_object)));
214 acpi_ut_remove_reference(info->return_object);
216 cleanup:
217 ACPI_FREE(info);
218 return_ACPI_STATUS(status);
221 ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
223 /*******************************************************************************
225 * FUNCTION: acpi_hw_get_register_bit_mask
227 * PARAMETERS: register_id - Index of ACPI Register to access
229 * RETURN: The bitmask to be used when accessing the register
231 * DESCRIPTION: Map register_id into a register bitmask.
233 ******************************************************************************/
234 struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
236 ACPI_FUNCTION_ENTRY();
238 if (register_id > ACPI_BITREG_MAX) {
239 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
240 register_id));
241 return (NULL);
244 return (&acpi_gbl_bit_register_info[register_id]);
247 /*******************************************************************************
249 * FUNCTION: acpi_get_register
251 * PARAMETERS: register_id - ID of ACPI bit_register to access
252 * return_value - Value that was read from the register
254 * RETURN: Status and the value read from specified Register. Value
255 * returned is normalized to bit0 (is shifted all the way right)
257 * DESCRIPTION: ACPI bit_register read function.
259 ******************************************************************************/
261 acpi_status acpi_get_register_unlocked(u32 register_id, u32 * return_value)
263 u32 register_value = 0;
264 struct acpi_bit_register_info *bit_reg_info;
265 acpi_status status;
267 ACPI_FUNCTION_TRACE(acpi_get_register);
269 /* Get the info structure corresponding to the requested ACPI Register */
271 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
272 if (!bit_reg_info) {
273 return_ACPI_STATUS(AE_BAD_PARAMETER);
276 /* Read from the register */
278 status = acpi_hw_register_read(bit_reg_info->parent_register,
279 &register_value);
281 if (ACPI_SUCCESS(status)) {
283 /* Normalize the value that was read */
285 register_value =
286 ((register_value & bit_reg_info->access_bit_mask)
287 >> bit_reg_info->bit_position);
289 *return_value = register_value;
291 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
292 register_value,
293 bit_reg_info->parent_register));
296 return_ACPI_STATUS(status);
299 acpi_status acpi_get_register(u32 register_id, u32 * return_value)
301 acpi_status status;
302 acpi_cpu_flags flags;
303 flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
304 status = acpi_get_register_unlocked(register_id, return_value);
305 acpi_os_release_lock(acpi_gbl_hardware_lock, flags);
306 return status;
309 ACPI_EXPORT_SYMBOL(acpi_get_register)
311 /*******************************************************************************
313 * FUNCTION: acpi_set_register
315 * PARAMETERS: register_id - ID of ACPI bit_register to access
316 * Value - (only used on write) value to write to the
317 * Register, NOT pre-normalized to the bit pos
319 * RETURN: Status
321 * DESCRIPTION: ACPI Bit Register write function.
323 ******************************************************************************/
324 acpi_status acpi_set_register(u32 register_id, u32 value)
326 u32 register_value = 0;
327 struct acpi_bit_register_info *bit_reg_info;
328 acpi_status status;
329 acpi_cpu_flags lock_flags;
331 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id);
333 /* Get the info structure corresponding to the requested ACPI Register */
335 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
336 if (!bit_reg_info) {
337 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
338 register_id));
339 return_ACPI_STATUS(AE_BAD_PARAMETER);
342 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
344 /* Always do a register read first so we can insert the new bits */
346 status = acpi_hw_register_read(bit_reg_info->parent_register,
347 &register_value);
348 if (ACPI_FAILURE(status)) {
349 goto unlock_and_exit;
353 * Decode the Register ID
354 * Register ID = [Register block ID] | [bit ID]
356 * Check bit ID to fine locate Register offset.
357 * Check Mask to determine Register offset, and then read-write.
359 switch (bit_reg_info->parent_register) {
360 case ACPI_REGISTER_PM1_STATUS:
363 * Status Registers are different from the rest. Clear by
364 * writing 1, and writing 0 has no effect. So, the only relevant
365 * information is the single bit we're interested in, all others should
366 * be written as 0 so they will be left unchanged.
368 value = ACPI_REGISTER_PREPARE_BITS(value,
369 bit_reg_info->bit_position,
370 bit_reg_info->
371 access_bit_mask);
372 if (value) {
373 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
374 (u16) value);
375 register_value = 0;
377 break;
379 case ACPI_REGISTER_PM1_ENABLE:
381 ACPI_REGISTER_INSERT_VALUE(register_value,
382 bit_reg_info->bit_position,
383 bit_reg_info->access_bit_mask,
384 value);
386 status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE,
387 (u16) register_value);
388 break;
390 case ACPI_REGISTER_PM1_CONTROL:
393 * Write the PM1 Control register.
394 * Note that at this level, the fact that there are actually TWO
395 * registers (A and B - and B may not exist) is abstracted.
397 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
398 register_value));
400 ACPI_REGISTER_INSERT_VALUE(register_value,
401 bit_reg_info->bit_position,
402 bit_reg_info->access_bit_mask,
403 value);
405 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
406 (u16) register_value);
407 break;
409 case ACPI_REGISTER_PM2_CONTROL:
411 status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL,
412 &register_value);
413 if (ACPI_FAILURE(status)) {
414 goto unlock_and_exit;
417 ACPI_DEBUG_PRINT((ACPI_DB_IO,
418 "PM2 control: Read %X from %8.8X%8.8X\n",
419 register_value,
420 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
421 xpm2_control_block.
422 address)));
424 ACPI_REGISTER_INSERT_VALUE(register_value,
425 bit_reg_info->bit_position,
426 bit_reg_info->access_bit_mask,
427 value);
429 ACPI_DEBUG_PRINT((ACPI_DB_IO,
430 "About to write %4.4X to %8.8X%8.8X\n",
431 register_value,
432 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
433 xpm2_control_block.
434 address)));
436 status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL,
437 (u8) (register_value));
438 break;
440 default:
441 break;
444 unlock_and_exit:
446 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
448 /* Normalize the value that was read */
450 ACPI_DEBUG_EXEC(register_value =
451 ((register_value & bit_reg_info->access_bit_mask) >>
452 bit_reg_info->bit_position));
454 ACPI_DEBUG_PRINT((ACPI_DB_IO,
455 "Set bits: %8.8X actual %8.8X register %X\n", value,
456 register_value, bit_reg_info->parent_register));
457 return_ACPI_STATUS(status);
460 ACPI_EXPORT_SYMBOL(acpi_set_register)
462 /******************************************************************************
464 * FUNCTION: acpi_hw_register_read
466 * PARAMETERS: register_id - ACPI Register ID
467 * return_value - Where the register value is returned
469 * RETURN: Status and the value read.
471 * DESCRIPTION: Read from the specified ACPI register
473 ******************************************************************************/
474 acpi_status
475 acpi_hw_register_read(u32 register_id, u32 * return_value)
477 u32 value1 = 0;
478 u32 value2 = 0;
479 acpi_status status;
481 ACPI_FUNCTION_TRACE(hw_register_read);
483 switch (register_id) {
484 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
486 status =
487 acpi_hw_low_level_read(16, &value1,
488 &acpi_gbl_FADT.xpm1a_event_block);
489 if (ACPI_FAILURE(status)) {
490 goto exit;
493 /* PM1B is optional */
495 status =
496 acpi_hw_low_level_read(16, &value2,
497 &acpi_gbl_FADT.xpm1b_event_block);
498 value1 |= value2;
499 break;
501 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
503 status =
504 acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable);
505 if (ACPI_FAILURE(status)) {
506 goto exit;
509 /* PM1B is optional */
511 status =
512 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
513 value1 |= value2;
514 break;
516 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
518 status =
519 acpi_hw_low_level_read(16, &value1,
520 &acpi_gbl_FADT.xpm1a_control_block);
521 if (ACPI_FAILURE(status)) {
522 goto exit;
525 status =
526 acpi_hw_low_level_read(16, &value2,
527 &acpi_gbl_FADT.xpm1b_control_block);
528 value1 |= value2;
529 break;
531 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
533 status =
534 acpi_hw_low_level_read(8, &value1,
535 &acpi_gbl_FADT.xpm2_control_block);
536 break;
538 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
540 status =
541 acpi_hw_low_level_read(32, &value1,
542 &acpi_gbl_FADT.xpm_timer_block);
543 break;
545 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
547 status =
548 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
549 break;
551 default:
552 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
553 status = AE_BAD_PARAMETER;
554 break;
557 exit:
559 if (ACPI_SUCCESS(status)) {
560 *return_value = value1;
563 return_ACPI_STATUS(status);
566 /******************************************************************************
568 * FUNCTION: acpi_hw_register_write
570 * PARAMETERS: register_id - ACPI Register ID
571 * Value - The value to write
573 * RETURN: Status
575 * DESCRIPTION: Write to the specified ACPI register
577 * NOTE: In accordance with the ACPI specification, this function automatically
578 * preserves the value of the following bits, meaning that these bits cannot be
579 * changed via this interface:
581 * PM1_CONTROL[0] = SCI_EN
582 * PM1_CONTROL[9]
583 * PM1_STATUS[11]
585 * ACPI References:
586 * 1) Hardware Ignored Bits: When software writes to a register with ignored
587 * bit fields, it preserves the ignored bit fields
588 * 2) SCI_EN: OSPM always preserves this bit position
590 ******************************************************************************/
592 acpi_status acpi_hw_register_write(u32 register_id, u32 value)
594 acpi_status status;
595 u32 read_value;
597 ACPI_FUNCTION_TRACE(hw_register_write);
599 switch (register_id) {
600 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
602 /* Perform a read first to preserve certain bits (per ACPI spec) */
604 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
605 &read_value);
606 if (ACPI_FAILURE(status)) {
607 goto exit;
610 /* Insert the bits to be preserved */
612 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
613 read_value);
615 /* Now we can write the data */
617 status =
618 acpi_hw_low_level_write(16, value,
619 &acpi_gbl_FADT.xpm1a_event_block);
620 if (ACPI_FAILURE(status)) {
621 goto exit;
624 /* PM1B is optional */
626 status =
627 acpi_hw_low_level_write(16, value,
628 &acpi_gbl_FADT.xpm1b_event_block);
629 break;
631 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
633 status =
634 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
635 if (ACPI_FAILURE(status)) {
636 goto exit;
639 /* PM1B is optional */
641 status =
642 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
643 break;
645 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
648 * Perform a read first to preserve certain bits (per ACPI spec)
650 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
651 &read_value);
652 if (ACPI_FAILURE(status)) {
653 goto exit;
656 /* Insert the bits to be preserved */
658 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
659 read_value);
661 /* Now we can write the data */
663 status =
664 acpi_hw_low_level_write(16, value,
665 &acpi_gbl_FADT.xpm1a_control_block);
666 if (ACPI_FAILURE(status)) {
667 goto exit;
670 status =
671 acpi_hw_low_level_write(16, value,
672 &acpi_gbl_FADT.xpm1b_control_block);
673 break;
675 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
677 status =
678 acpi_hw_low_level_write(16, value,
679 &acpi_gbl_FADT.xpm1a_control_block);
680 break;
682 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
684 status =
685 acpi_hw_low_level_write(16, value,
686 &acpi_gbl_FADT.xpm1b_control_block);
687 break;
689 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
691 status =
692 acpi_hw_low_level_write(8, value,
693 &acpi_gbl_FADT.xpm2_control_block);
694 break;
696 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
698 status =
699 acpi_hw_low_level_write(32, value,
700 &acpi_gbl_FADT.xpm_timer_block);
701 break;
703 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
705 /* SMI_CMD is currently always in IO space */
707 status =
708 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
709 break;
711 default:
712 status = AE_BAD_PARAMETER;
713 break;
716 exit:
717 return_ACPI_STATUS(status);
720 /******************************************************************************
722 * FUNCTION: acpi_hw_low_level_read
724 * PARAMETERS: Width - 8, 16, or 32
725 * Value - Where the value is returned
726 * Reg - GAS register structure
728 * RETURN: Status
730 * DESCRIPTION: Read from either memory or IO space.
732 ******************************************************************************/
734 acpi_status
735 acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
737 u64 address;
738 acpi_status status;
740 ACPI_FUNCTION_NAME(hw_low_level_read);
743 * Must have a valid pointer to a GAS structure, and
744 * a non-zero address within. However, don't return an error
745 * because the PM1A/B code must not fail if B isn't present.
747 if (!reg) {
748 return (AE_OK);
751 /* Get a local copy of the address. Handles possible alignment issues */
753 ACPI_MOVE_64_TO_64(&address, &reg->address);
754 if (!address) {
755 return (AE_OK);
757 *value = 0;
760 * Two address spaces supported: Memory or IO.
761 * PCI_Config is not supported here because the GAS struct is insufficient
763 switch (reg->space_id) {
764 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
766 status = acpi_os_read_memory((acpi_physical_address) address,
767 value, width);
768 break;
770 case ACPI_ADR_SPACE_SYSTEM_IO:
772 status =
773 acpi_os_read_port((acpi_io_address) address, value, width);
774 break;
776 default:
777 ACPI_ERROR((AE_INFO,
778 "Unsupported address space: %X", reg->space_id));
779 return (AE_BAD_PARAMETER);
782 ACPI_DEBUG_PRINT((ACPI_DB_IO,
783 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
784 *value, width, ACPI_FORMAT_UINT64(address),
785 acpi_ut_get_region_name(reg->space_id)));
787 return (status);
790 /******************************************************************************
792 * FUNCTION: acpi_hw_low_level_write
794 * PARAMETERS: Width - 8, 16, or 32
795 * Value - To be written
796 * Reg - GAS register structure
798 * RETURN: Status
800 * DESCRIPTION: Write to either memory or IO space.
802 ******************************************************************************/
804 acpi_status
805 acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
807 u64 address;
808 acpi_status status;
810 ACPI_FUNCTION_NAME(hw_low_level_write);
813 * Must have a valid pointer to a GAS structure, and
814 * a non-zero address within. However, don't return an error
815 * because the PM1A/B code must not fail if B isn't present.
817 if (!reg) {
818 return (AE_OK);
821 /* Get a local copy of the address. Handles possible alignment issues */
823 ACPI_MOVE_64_TO_64(&address, &reg->address);
824 if (!address) {
825 return (AE_OK);
829 * Two address spaces supported: Memory or IO.
830 * PCI_Config is not supported here because the GAS struct is insufficient
832 switch (reg->space_id) {
833 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
835 status = acpi_os_write_memory((acpi_physical_address) address,
836 value, width);
837 break;
839 case ACPI_ADR_SPACE_SYSTEM_IO:
841 status = acpi_os_write_port((acpi_io_address) address, value,
842 width);
843 break;
845 default:
846 ACPI_ERROR((AE_INFO,
847 "Unsupported address space: %X", reg->space_id));
848 return (AE_BAD_PARAMETER);
851 ACPI_DEBUG_PRINT((ACPI_DB_IO,
852 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
853 value, width, ACPI_FORMAT_UINT64(address),
854 acpi_ut_get_region_name(reg->space_id)));
856 return (status);