2 /*******************************************************************************
4 * Module Name: hwregs - Read/write access functions for the various ACPI
5 * control and status registers.
7 ******************************************************************************/
10 * Copyright (C) 2000 - 2008, Intel Corp.
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
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.
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>
51 #define _COMPONENT ACPI_HARDWARE
52 ACPI_MODULE_NAME("hwregs")
54 /*******************************************************************************
56 * FUNCTION: acpi_hw_clear_acpi_status
62 * DESCRIPTION: Clears all fixed and general purpose status bits
63 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
65 ******************************************************************************/
66 acpi_status acpi_hw_clear_acpi_status(void)
69 acpi_cpu_flags lock_flags = 0;
71 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
73 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
74 ACPI_BITMASK_ALL_FIXED_STATUS,
75 (u16) acpi_gbl_FADT.xpm1a_event_block.address));
77 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
79 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
80 ACPI_BITMASK_ALL_FIXED_STATUS);
81 if (ACPI_FAILURE(status)) {
85 /* Clear the fixed events */
87 if (acpi_gbl_FADT.xpm1b_event_block.address) {
88 status = acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS,
89 &acpi_gbl_FADT.xpm1b_event_block);
90 if (ACPI_FAILURE(status)) {
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, NULL);
100 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
101 return_ACPI_STATUS(status);
104 /*******************************************************************************
106 * FUNCTION: acpi_hw_get_register_bit_mask
108 * PARAMETERS: register_id - Index of ACPI Register to access
110 * RETURN: The bitmask to be used when accessing the register
112 * DESCRIPTION: Map register_id into a register bitmask.
114 ******************************************************************************/
116 struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
118 ACPI_FUNCTION_ENTRY();
120 if (register_id > ACPI_BITREG_MAX) {
121 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
126 return (&acpi_gbl_bit_register_info[register_id]);
129 /******************************************************************************
131 * FUNCTION: acpi_hw_register_read
133 * PARAMETERS: register_id - ACPI Register ID
134 * return_value - Where the register value is returned
136 * RETURN: Status and the value read.
138 * DESCRIPTION: Read from the specified ACPI register
140 ******************************************************************************/
142 acpi_hw_register_read(u32 register_id, u32 * return_value)
148 ACPI_FUNCTION_TRACE(hw_register_read);
150 switch (register_id) {
151 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
153 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_event_block);
154 if (ACPI_FAILURE(status)) {
158 /* PM1B is optional */
160 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_event_block);
164 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
166 status = acpi_read(&value1, &acpi_gbl_xpm1a_enable);
167 if (ACPI_FAILURE(status)) {
171 /* PM1B is optional */
173 status = acpi_read(&value2, &acpi_gbl_xpm1b_enable);
177 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
179 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_control_block);
180 if (ACPI_FAILURE(status)) {
184 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_control_block);
188 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
190 status = acpi_read(&value1, &acpi_gbl_FADT.xpm2_control_block);
193 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
195 status = acpi_read(&value1, &acpi_gbl_FADT.xpm_timer_block);
198 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
201 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
205 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
206 status = AE_BAD_PARAMETER;
212 if (ACPI_SUCCESS(status)) {
213 *return_value = value1;
216 return_ACPI_STATUS(status);
219 /******************************************************************************
221 * FUNCTION: acpi_hw_register_write
223 * PARAMETERS: register_id - ACPI Register ID
224 * Value - The value to write
228 * DESCRIPTION: Write to the specified ACPI register
230 * NOTE: In accordance with the ACPI specification, this function automatically
231 * preserves the value of the following bits, meaning that these bits cannot be
232 * changed via this interface:
234 * PM1_CONTROL[0] = SCI_EN
239 * 1) Hardware Ignored Bits: When software writes to a register with ignored
240 * bit fields, it preserves the ignored bit fields
241 * 2) SCI_EN: OSPM always preserves this bit position
243 ******************************************************************************/
245 acpi_status acpi_hw_register_write(u32 register_id, u32 value)
250 ACPI_FUNCTION_TRACE(hw_register_write);
252 switch (register_id) {
253 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
255 /* Perform a read first to preserve certain bits (per ACPI spec) */
257 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
259 if (ACPI_FAILURE(status)) {
263 /* Insert the bits to be preserved */
265 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
268 /* Now we can write the data */
270 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_event_block);
271 if (ACPI_FAILURE(status)) {
275 /* PM1B is optional */
277 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_event_block);
280 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
282 status = acpi_write(value, &acpi_gbl_xpm1a_enable);
283 if (ACPI_FAILURE(status)) {
287 /* PM1B is optional */
289 status = acpi_write(value, &acpi_gbl_xpm1b_enable);
292 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
295 * Perform a read first to preserve certain bits (per ACPI spec)
297 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
299 if (ACPI_FAILURE(status)) {
303 /* Insert the bits to be preserved */
305 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
308 /* Now we can write the data */
310 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
311 if (ACPI_FAILURE(status)) {
315 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
318 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
320 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
323 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
325 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
328 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
330 status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block);
333 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
335 status = acpi_write(value, &acpi_gbl_FADT.xpm_timer_block);
338 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
340 /* SMI_CMD is currently always in IO space */
343 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
347 status = AE_BAD_PARAMETER;
352 return_ACPI_STATUS(status);