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_xpm1a_status
.address
));
77 lock_flags
= acpi_os_acquire_lock(acpi_gbl_hardware_lock
);
79 /* Clear the fixed events */
81 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS
,
82 ACPI_BITMASK_ALL_FIXED_STATUS
);
83 if (ACPI_FAILURE(status
)) {
87 /* Write PM1B register if present */
89 if (acpi_gbl_xpm1b_status
.address
) {
90 status
= acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS
,
91 &acpi_gbl_xpm1b_status
);
92 if (ACPI_FAILURE(status
)) {
97 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
99 status
= acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block
, NULL
);
102 acpi_os_release_lock(acpi_gbl_hardware_lock
, lock_flags
);
103 return_ACPI_STATUS(status
);
106 /*******************************************************************************
108 * FUNCTION: acpi_hw_get_register_bit_mask
110 * PARAMETERS: register_id - Index of ACPI Register to access
112 * RETURN: The bitmask to be used when accessing the register
114 * DESCRIPTION: Map register_id into a register bitmask.
116 ******************************************************************************/
118 struct acpi_bit_register_info
*acpi_hw_get_bit_register_info(u32 register_id
)
120 ACPI_FUNCTION_ENTRY();
122 if (register_id
> ACPI_BITREG_MAX
) {
123 ACPI_ERROR((AE_INFO
, "Invalid BitRegister ID: %X",
128 return (&acpi_gbl_bit_register_info
[register_id
]);
131 /******************************************************************************
133 * FUNCTION: acpi_hw_register_read
135 * PARAMETERS: register_id - ACPI Register ID
136 * return_value - Where the register value is returned
138 * RETURN: Status and the value read.
140 * DESCRIPTION: Read from the specified ACPI register
142 ******************************************************************************/
144 acpi_hw_register_read(u32 register_id
, u32
* return_value
)
150 ACPI_FUNCTION_TRACE(hw_register_read
);
152 switch (register_id
) {
153 case ACPI_REGISTER_PM1_STATUS
: /* 16-bit access */
155 status
= acpi_read(&value1
, &acpi_gbl_xpm1a_status
);
156 if (ACPI_FAILURE(status
)) {
160 /* PM1B is optional */
162 status
= acpi_read(&value2
, &acpi_gbl_xpm1b_status
);
166 case ACPI_REGISTER_PM1_ENABLE
: /* 16-bit access */
168 status
= acpi_read(&value1
, &acpi_gbl_xpm1a_enable
);
169 if (ACPI_FAILURE(status
)) {
173 /* PM1B is optional */
175 status
= acpi_read(&value2
, &acpi_gbl_xpm1b_enable
);
179 case ACPI_REGISTER_PM1_CONTROL
: /* 16-bit access */
181 status
= acpi_read(&value1
, &acpi_gbl_FADT
.xpm1a_control_block
);
182 if (ACPI_FAILURE(status
)) {
186 status
= acpi_read(&value2
, &acpi_gbl_FADT
.xpm1b_control_block
);
190 case ACPI_REGISTER_PM2_CONTROL
: /* 8-bit access */
192 status
= acpi_read(&value1
, &acpi_gbl_FADT
.xpm2_control_block
);
195 case ACPI_REGISTER_PM_TIMER
: /* 32-bit access */
197 status
= acpi_read(&value1
, &acpi_gbl_FADT
.xpm_timer_block
);
200 case ACPI_REGISTER_SMI_COMMAND_BLOCK
: /* 8-bit access */
203 acpi_os_read_port(acpi_gbl_FADT
.smi_command
, &value1
, 8);
207 ACPI_ERROR((AE_INFO
, "Unknown Register ID: %X", register_id
));
208 status
= AE_BAD_PARAMETER
;
214 if (ACPI_SUCCESS(status
)) {
215 *return_value
= value1
;
218 return_ACPI_STATUS(status
);
221 /******************************************************************************
223 * FUNCTION: acpi_hw_register_write
225 * PARAMETERS: register_id - ACPI Register ID
226 * Value - The value to write
230 * DESCRIPTION: Write to the specified ACPI register
232 * NOTE: In accordance with the ACPI specification, this function automatically
233 * preserves the value of the following bits, meaning that these bits cannot be
234 * changed via this interface:
236 * PM1_CONTROL[0] = SCI_EN
241 * 1) Hardware Ignored Bits: When software writes to a register with ignored
242 * bit fields, it preserves the ignored bit fields
243 * 2) SCI_EN: OSPM always preserves this bit position
245 ******************************************************************************/
247 acpi_status
acpi_hw_register_write(u32 register_id
, u32 value
)
252 ACPI_FUNCTION_TRACE(hw_register_write
);
254 switch (register_id
) {
255 case ACPI_REGISTER_PM1_STATUS
: /* 16-bit access */
257 /* Perform a read first to preserve certain bits (per ACPI spec) */
259 status
= acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS
,
261 if (ACPI_FAILURE(status
)) {
265 /* Insert the bits to be preserved */
267 ACPI_INSERT_BITS(value
, ACPI_PM1_STATUS_PRESERVED_BITS
,
270 /* Now we can write the data */
272 status
= acpi_write(value
, &acpi_gbl_xpm1a_status
);
273 if (ACPI_FAILURE(status
)) {
277 /* PM1B is optional */
279 status
= acpi_write(value
, &acpi_gbl_xpm1b_status
);
282 case ACPI_REGISTER_PM1_ENABLE
: /* 16-bit access */
284 status
= acpi_write(value
, &acpi_gbl_xpm1a_enable
);
285 if (ACPI_FAILURE(status
)) {
289 /* PM1B is optional */
291 status
= acpi_write(value
, &acpi_gbl_xpm1b_enable
);
294 case ACPI_REGISTER_PM1_CONTROL
: /* 16-bit access */
297 * Perform a read first to preserve certain bits (per ACPI spec)
299 status
= acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL
,
301 if (ACPI_FAILURE(status
)) {
305 /* Insert the bits to be preserved */
307 ACPI_INSERT_BITS(value
, ACPI_PM1_CONTROL_PRESERVED_BITS
,
310 /* Now we can write the data */
312 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm1a_control_block
);
313 if (ACPI_FAILURE(status
)) {
317 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm1b_control_block
);
320 case ACPI_REGISTER_PM1A_CONTROL
: /* 16-bit access */
322 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm1a_control_block
);
325 case ACPI_REGISTER_PM1B_CONTROL
: /* 16-bit access */
327 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm1b_control_block
);
330 case ACPI_REGISTER_PM2_CONTROL
: /* 8-bit access */
332 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm2_control_block
);
335 case ACPI_REGISTER_PM_TIMER
: /* 32-bit access */
337 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm_timer_block
);
340 case ACPI_REGISTER_SMI_COMMAND_BLOCK
: /* 8-bit access */
342 /* SMI_CMD is currently always in IO space */
345 acpi_os_write_port(acpi_gbl_FADT
.smi_command
, value
, 8);
349 status
= AE_BAD_PARAMETER
;
354 return_ACPI_STATUS(status
);