blob: 981e5db21a3bbf011df965f92665d6a80f867e13 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*******************************************************************************
3 *
4 * Module Name: hwregs - Read/write access functions for the various ACPI
5 * control and status registers.
6 *
7 ******************************************************************************/
8
9/*
Len Brown75a44ce2008-04-23 23:00:13 -040010 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * All rights reserved.
12 *
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.
27 *
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.
31 *
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.
44 */
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
47#include <acpi/acnamesp.h>
48#include <acpi/acevents.h>
49
50#define _COMPONENT ACPI_HARDWARE
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("hwregs")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_hw_clear_acpi_status
56 *
Bob Moored8c71b62007-02-02 19:48:21 +030057 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 *
Bob Moore7db5d822008-12-30 11:04:48 +080059 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * DESCRIPTION: Clears all fixed and general purpose status bits
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
63 *
64 ******************************************************************************/
Bob Moored8c71b62007-02-02 19:48:21 +030065acpi_status acpi_hw_clear_acpi_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Len Brown4be44fc2005-08-05 00:44:28 -040067 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -040068 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Bob Mooreb229cf92006-04-21 17:15:00 -040070 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Len Brown4be44fc2005-08-05 00:44:28 -040072 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
73 ACPI_BITMASK_ALL_FIXED_STATUS,
Bob Mooref3d2e782007-02-02 19:48:18 +030074 (u16) acpi_gbl_FADT.xpm1a_event_block.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Moore4c90ece2006-06-08 16:29:00 -040076 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +040078 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
Len Brown4be44fc2005-08-05 00:44:28 -040079 ACPI_BITMASK_ALL_FIXED_STATUS);
80 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 goto unlock_and_exit;
82 }
83
84 /* Clear the fixed events */
85
Bob Mooref3d2e782007-02-02 19:48:18 +030086 if (acpi_gbl_FADT.xpm1b_event_block.address) {
Bob Mooreecfbbc72008-12-31 02:55:32 +080087 status = acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS,
88 &acpi_gbl_FADT.xpm1b_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -040089 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 goto unlock_and_exit;
91 }
92 }
93
94 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
95
Bob Mooree97d6bf2008-12-30 09:45:17 +080096 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Len Brown4be44fc2005-08-05 00:44:28 -040098 unlock_and_exit:
Bob Moore4c90ece2006-06-08 16:29:00 -040099 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400100 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*******************************************************************************
104 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 * FUNCTION: acpi_hw_get_register_bit_mask
106 *
107 * PARAMETERS: register_id - Index of ACPI Register to access
108 *
Robert Moore44f6c012005-04-18 22:49:35 -0400109 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 *
Robert Moore44f6c012005-04-18 22:49:35 -0400111 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 *
113 ******************************************************************************/
Bob Moore7db5d822008-12-30 11:04:48 +0800114
Len Brown4be44fc2005-08-05 00:44:28 -0400115struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500117 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 if (register_id > ACPI_BITREG_MAX) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400120 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500121 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return (NULL);
123 }
124
125 return (&acpi_gbl_bit_register_info[register_id]);
126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/******************************************************************************
129 *
130 * FUNCTION: acpi_hw_register_read
131 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400132 * PARAMETERS: register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400133 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 *
135 * RETURN: Status and the value read.
136 *
Bob Moore967440e2006-06-23 17:04:00 -0400137 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 *
139 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140acpi_status
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400141acpi_hw_register_read(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Len Brown4be44fc2005-08-05 00:44:28 -0400143 u32 value1 = 0;
144 u32 value2 = 0;
145 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Bob Mooreb229cf92006-04-21 17:15:00 -0400147 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Bob Mooreecfbbc72008-12-31 02:55:32 +0800152 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400153 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400154 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 }
156
157 /* PM1B is optional */
158
Bob Mooreecfbbc72008-12-31 02:55:32 +0800159 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 value1 |= value2;
161 break;
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bob Mooreecfbbc72008-12-31 02:55:32 +0800165 status = acpi_read(&value1, &acpi_gbl_xpm1a_enable);
Len Brown4be44fc2005-08-05 00:44:28 -0400166 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400167 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
170 /* PM1B is optional */
171
Bob Mooreecfbbc72008-12-31 02:55:32 +0800172 status = acpi_read(&value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 value1 |= value2;
174 break;
175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Bob Mooreecfbbc72008-12-31 02:55:32 +0800178 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400179 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400180 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182
Bob Mooreecfbbc72008-12-31 02:55:32 +0800183 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 value1 |= value2;
185 break;
186
Len Brown4be44fc2005-08-05 00:44:28 -0400187 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Bob Mooreecfbbc72008-12-31 02:55:32 +0800189 status = acpi_read(&value1, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 break;
191
Len Brown4be44fc2005-08-05 00:44:28 -0400192 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Bob Mooreecfbbc72008-12-31 02:55:32 +0800194 status = acpi_read(&value1, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 break;
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Bob Mooref3d2e782007-02-02 19:48:18 +0300199 status =
200 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 break;
202
203 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500204 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 status = AE_BAD_PARAMETER;
206 break;
207 }
208
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400209 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Len Brown4be44fc2005-08-05 00:44:28 -0400211 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 *return_value = value1;
213 }
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218/******************************************************************************
219 *
220 * FUNCTION: acpi_hw_register_write
221 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400222 * PARAMETERS: register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 * Value - The value to write
224 *
225 * RETURN: Status
226 *
Bob Moore967440e2006-06-23 17:04:00 -0400227 * DESCRIPTION: Write to the specified ACPI register
228 *
229 * NOTE: In accordance with the ACPI specification, this function automatically
230 * preserves the value of the following bits, meaning that these bits cannot be
231 * changed via this interface:
232 *
233 * PM1_CONTROL[0] = SCI_EN
234 * PM1_CONTROL[9]
235 * PM1_STATUS[11]
236 *
237 * ACPI References:
238 * 1) Hardware Ignored Bits: When software writes to a register with ignored
239 * bit fields, it preserves the ignored bit fields
240 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 *
242 ******************************************************************************/
243
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400244acpi_status acpi_hw_register_write(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Len Brown4be44fc2005-08-05 00:44:28 -0400246 acpi_status status;
Bob Moore967440e2006-06-23 17:04:00 -0400247 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Bob Mooreb229cf92006-04-21 17:15:00 -0400249 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Bob Moore967440e2006-06-23 17:04:00 -0400254 /* Perform a read first to preserve certain bits (per ACPI spec) */
255
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400256 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
Bob Moore967440e2006-06-23 17:04:00 -0400257 &read_value);
258 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400259 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400260 }
261
262 /* Insert the bits to be preserved */
263
264 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
265 read_value);
266
267 /* Now we can write the data */
268
Bob Mooreecfbbc72008-12-31 02:55:32 +0800269 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400270 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400271 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
273
274 /* PM1B is optional */
275
Bob Mooreecfbbc72008-12-31 02:55:32 +0800276 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 break;
278
Len Brown4be44fc2005-08-05 00:44:28 -0400279 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Bob Mooreecfbbc72008-12-31 02:55:32 +0800281 status = acpi_write(value, &acpi_gbl_xpm1a_enable);
Len Brown4be44fc2005-08-05 00:44:28 -0400282 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400283 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 /* PM1B is optional */
287
Bob Mooreecfbbc72008-12-31 02:55:32 +0800288 status = acpi_write(value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 break;
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Bob Moore967440e2006-06-23 17:04:00 -0400293 /*
294 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moore967440e2006-06-23 17:04:00 -0400295 */
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400296 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
Bob Moore967440e2006-06-23 17:04:00 -0400297 &read_value);
298 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400299 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400300 }
301
302 /* Insert the bits to be preserved */
303
304 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
305 read_value);
306
307 /* Now we can write the data */
308
Bob Mooreecfbbc72008-12-31 02:55:32 +0800309 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400310 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400311 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
313
Bob Mooreecfbbc72008-12-31 02:55:32 +0800314 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 break;
316
Len Brown4be44fc2005-08-05 00:44:28 -0400317 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Bob Mooreecfbbc72008-12-31 02:55:32 +0800319 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 break;
321
Len Brown4be44fc2005-08-05 00:44:28 -0400322 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Bob Mooreecfbbc72008-12-31 02:55:32 +0800324 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 break;
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Bob Mooreecfbbc72008-12-31 02:55:32 +0800329 status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 break;
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Bob Mooreecfbbc72008-12-31 02:55:32 +0800334 status = acpi_write(value, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 break;
336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /* SMI_CMD is currently always in IO space */
340
Bob Mooref3d2e782007-02-02 19:48:18 +0300341 status =
342 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 break;
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 default:
346 status = AE_BAD_PARAMETER;
347 break;
348 }
349
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400350 exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400351 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}