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 /* Local Prototypes */
56 acpi_hw_read_multiple(u32
*value
,
57 struct acpi_generic_address
*register_a
,
58 struct acpi_generic_address
*register_b
);
61 acpi_hw_write_multiple(u32 value
,
62 struct acpi_generic_address
*register_a
,
63 struct acpi_generic_address
*register_b
);
65 /*******************************************************************************
67 * FUNCTION: acpi_hw_clear_acpi_status
73 * DESCRIPTION: Clears all fixed and general purpose status bits
75 ******************************************************************************/
77 acpi_status
acpi_hw_clear_acpi_status(void)
80 acpi_cpu_flags lock_flags
= 0;
82 ACPI_FUNCTION_TRACE(hw_clear_acpi_status
);
84 ACPI_DEBUG_PRINT((ACPI_DB_IO
, "About to write %04X to %0llX\n",
85 ACPI_BITMASK_ALL_FIXED_STATUS
,
86 acpi_gbl_xpm1a_status
.address
));
88 lock_flags
= acpi_os_acquire_lock(acpi_gbl_hardware_lock
);
90 /* Clear the fixed events in PM1 A/B */
92 status
= acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS
,
93 ACPI_BITMASK_ALL_FIXED_STATUS
);
94 if (ACPI_FAILURE(status
)) {
98 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
100 status
= acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block
, NULL
);
103 acpi_os_release_lock(acpi_gbl_hardware_lock
, lock_flags
);
104 return_ACPI_STATUS(status
);
107 /*******************************************************************************
109 * FUNCTION: acpi_hw_get_register_bit_mask
111 * PARAMETERS: register_id - Index of ACPI Register to access
113 * RETURN: The bitmask to be used when accessing the register
115 * DESCRIPTION: Map register_id into a register bitmask.
117 ******************************************************************************/
119 struct acpi_bit_register_info
*acpi_hw_get_bit_register_info(u32 register_id
)
121 ACPI_FUNCTION_ENTRY();
123 if (register_id
> ACPI_BITREG_MAX
) {
124 ACPI_ERROR((AE_INFO
, "Invalid BitRegister ID: %X",
129 return (&acpi_gbl_bit_register_info
[register_id
]);
132 /******************************************************************************
134 * FUNCTION: acpi_hw_register_read
136 * PARAMETERS: register_id - ACPI Register ID
137 * return_value - Where the register value is returned
139 * RETURN: Status and the value read.
141 * DESCRIPTION: Read from the specified ACPI register
143 ******************************************************************************/
145 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
: /* PM1 A/B: 16-bit access each */
155 status
= acpi_hw_read_multiple(&value
,
156 &acpi_gbl_xpm1a_status
,
157 &acpi_gbl_xpm1b_status
);
160 case ACPI_REGISTER_PM1_ENABLE
: /* PM1 A/B: 16-bit access each */
162 status
= acpi_hw_read_multiple(&value
,
163 &acpi_gbl_xpm1a_enable
,
164 &acpi_gbl_xpm1b_enable
);
167 case ACPI_REGISTER_PM1_CONTROL
: /* PM1 A/B: 16-bit access each */
169 status
= acpi_hw_read_multiple(&value
,
173 xpm1b_control_block
);
176 case ACPI_REGISTER_PM2_CONTROL
: /* 8-bit access */
178 status
= acpi_read(&value
, &acpi_gbl_FADT
.xpm2_control_block
);
181 case ACPI_REGISTER_PM_TIMER
: /* 32-bit access */
183 status
= acpi_read(&value
, &acpi_gbl_FADT
.xpm_timer_block
);
186 case ACPI_REGISTER_SMI_COMMAND_BLOCK
: /* 8-bit access */
189 acpi_os_read_port(acpi_gbl_FADT
.smi_command
, &value
, 8);
193 ACPI_ERROR((AE_INFO
, "Unknown Register ID: %X", register_id
));
194 status
= AE_BAD_PARAMETER
;
198 if (ACPI_SUCCESS(status
)) {
199 *return_value
= value
;
202 return_ACPI_STATUS(status
);
205 /******************************************************************************
207 * FUNCTION: acpi_hw_register_write
209 * PARAMETERS: register_id - ACPI Register ID
210 * Value - The value to write
214 * DESCRIPTION: Write to the specified ACPI register
216 * NOTE: In accordance with the ACPI specification, this function automatically
217 * preserves the value of the following bits, meaning that these bits cannot be
218 * changed via this interface:
220 * PM1_CONTROL[0] = SCI_EN
225 * 1) Hardware Ignored Bits: When software writes to a register with ignored
226 * bit fields, it preserves the ignored bit fields
227 * 2) SCI_EN: OSPM always preserves this bit position
229 ******************************************************************************/
231 acpi_status
acpi_hw_register_write(u32 register_id
, u32 value
)
236 ACPI_FUNCTION_TRACE(hw_register_write
);
238 switch (register_id
) {
239 case ACPI_REGISTER_PM1_STATUS
: /* PM1 A/B: 16-bit access each */
241 /* Perform a read first to preserve certain bits (per ACPI spec) */
243 status
= acpi_hw_read_multiple(&read_value
,
244 &acpi_gbl_xpm1a_status
,
245 &acpi_gbl_xpm1b_status
);
246 if (ACPI_FAILURE(status
)) {
250 /* Insert the bits to be preserved */
252 ACPI_INSERT_BITS(value
, ACPI_PM1_STATUS_PRESERVED_BITS
,
255 /* Now we can write the data */
257 status
= acpi_hw_write_multiple(value
,
258 &acpi_gbl_xpm1a_status
,
259 &acpi_gbl_xpm1b_status
);
262 case ACPI_REGISTER_PM1_ENABLE
: /* PM1 A/B: 16-bit access */
264 status
= acpi_hw_write_multiple(value
,
265 &acpi_gbl_xpm1a_enable
,
266 &acpi_gbl_xpm1b_enable
);
269 case ACPI_REGISTER_PM1_CONTROL
: /* PM1 A/B: 16-bit access each */
272 * Perform a read first to preserve certain bits (per ACPI spec)
273 * Note: This includes SCI_EN, we never want to change this bit
275 status
= acpi_hw_read_multiple(&read_value
,
279 xpm1b_control_block
);
280 if (ACPI_FAILURE(status
)) {
284 /* Insert the bits to be preserved */
286 ACPI_INSERT_BITS(value
, ACPI_PM1_CONTROL_PRESERVED_BITS
,
289 /* Now we can write the data */
291 status
= acpi_hw_write_multiple(value
,
295 xpm1b_control_block
);
298 case ACPI_REGISTER_PM1A_CONTROL
: /* 16-bit access */
300 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm1a_control_block
);
303 case ACPI_REGISTER_PM1B_CONTROL
: /* 16-bit access */
305 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm1b_control_block
);
308 case ACPI_REGISTER_PM2_CONTROL
: /* 8-bit access */
310 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm2_control_block
);
313 case ACPI_REGISTER_PM_TIMER
: /* 32-bit access */
315 status
= acpi_write(value
, &acpi_gbl_FADT
.xpm_timer_block
);
318 case ACPI_REGISTER_SMI_COMMAND_BLOCK
: /* 8-bit access */
320 /* SMI_CMD is currently always in IO space */
323 acpi_os_write_port(acpi_gbl_FADT
.smi_command
, value
, 8);
327 ACPI_ERROR((AE_INFO
, "Unknown Register ID: %X", register_id
));
328 status
= AE_BAD_PARAMETER
;
333 return_ACPI_STATUS(status
);
336 /******************************************************************************
338 * FUNCTION: acpi_hw_read_multiple
340 * PARAMETERS: Value - Where the register value is returned
341 * register_a - First ACPI register (required)
342 * register_b - Second ACPI register (optional)
346 * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
348 ******************************************************************************/
351 acpi_hw_read_multiple(u32
*value
,
352 struct acpi_generic_address
*register_a
,
353 struct acpi_generic_address
*register_b
)
359 /* The first register is always required */
361 status
= acpi_read(&value_a
, register_a
);
362 if (ACPI_FAILURE(status
)) {
366 /* Second register is optional */
368 if (register_b
->address
) {
369 status
= acpi_read(&value_b
, register_b
);
370 if (ACPI_FAILURE(status
)) {
376 * OR the two return values together. No shifting or masking is necessary,
377 * because of how the PM1 registers are defined in the ACPI specification:
379 * "Although the bits can be split between the two register blocks (each
380 * register block has a unique pointer within the FADT), the bit positions
381 * are maintained. The register block with unimplemented bits (that is,
382 * those implemented in the other register block) always returns zeros,
383 * and writes have no side effects"
385 *value
= (value_a
| value_b
);
389 /******************************************************************************
391 * FUNCTION: acpi_hw_write_multiple
393 * PARAMETERS: Value - The value to write
394 * register_a - First ACPI register (required)
395 * register_b - Second ACPI register (optional)
399 * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
401 ******************************************************************************/
404 acpi_hw_write_multiple(u32 value
,
405 struct acpi_generic_address
*register_a
,
406 struct acpi_generic_address
*register_b
)
410 /* The first register is always required */
412 status
= acpi_write(value
, register_a
);
413 if (ACPI_FAILURE(status
)) {
418 * Second register is optional
420 * No bit shifting or clearing is necessary, because of how the PM1
421 * registers are defined in the ACPI specification:
423 * "Although the bits can be split between the two register blocks (each
424 * register block has a unique pointer within the FADT), the bit positions
425 * are maintained. The register block with unimplemented bits (that is,
426 * those implemented in the other register block) always returns zeros,
427 * and writes have no side effects"
429 if (register_b
->address
) {
430 status
= acpi_write(value
, register_b
);