Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /******************************************************************************* | |
3 | * | |
4 | * Module Name: hwregs - Read/write access functions for the various ACPI | |
5 | * control and status registers. | |
6 | * | |
7 | ******************************************************************************/ | |
8 | ||
9 | /* | |
75a44ce0 | 10 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
11 | * 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 | ||
1da177e4 | 46 | #include <acpi/acpi.h> |
e2f7a777 LB |
47 | #include "accommon.h" |
48 | #include "acnamesp.h" | |
49 | #include "acevents.h" | |
1da177e4 LT |
50 | |
51 | #define _COMPONENT ACPI_HARDWARE | |
4be44fcd | 52 | ACPI_MODULE_NAME("hwregs") |
1da177e4 LT |
53 | |
54 | /******************************************************************************* | |
55 | * | |
56 | * FUNCTION: acpi_hw_clear_acpi_status | |
57 | * | |
d8c71b6d | 58 | * PARAMETERS: None |
1da177e4 | 59 | * |
7db5d82d | 60 | * RETURN: Status |
1da177e4 LT |
61 | * |
62 | * DESCRIPTION: Clears all fixed and general purpose status bits | |
63 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED | |
64 | * | |
65 | ******************************************************************************/ | |
d8c71b6d | 66 | acpi_status acpi_hw_clear_acpi_status(void) |
1da177e4 | 67 | { |
4be44fcd | 68 | acpi_status status; |
4c90ece2 | 69 | acpi_cpu_flags lock_flags = 0; |
1da177e4 | 70 | |
b229cf92 | 71 | ACPI_FUNCTION_TRACE(hw_clear_acpi_status); |
1da177e4 | 72 | |
4be44fcd LB |
73 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n", |
74 | ACPI_BITMASK_ALL_FIXED_STATUS, | |
f3d2e786 | 75 | (u16) acpi_gbl_FADT.xpm1a_event_block.address)); |
1da177e4 | 76 | |
4c90ece2 | 77 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
1da177e4 | 78 | |
d30dc9ab | 79 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
4be44fcd LB |
80 | ACPI_BITMASK_ALL_FIXED_STATUS); |
81 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
82 | goto unlock_and_exit; |
83 | } | |
84 | ||
85 | /* Clear the fixed events */ | |
86 | ||
f3d2e786 | 87 | if (acpi_gbl_FADT.xpm1b_event_block.address) { |
ecfbbc7b BM |
88 | status = acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS, |
89 | &acpi_gbl_FADT.xpm1b_event_block); | |
4be44fcd | 90 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
91 | goto unlock_and_exit; |
92 | } | |
93 | } | |
94 | ||
95 | /* Clear the GPE Bits in all GPE registers in all GPE blocks */ | |
96 | ||
e97d6bf1 | 97 | status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); |
1da177e4 | 98 | |
4be44fcd | 99 | unlock_and_exit: |
4c90ece2 | 100 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
4be44fcd | 101 | return_ACPI_STATUS(status); |
1da177e4 LT |
102 | } |
103 | ||
1da177e4 LT |
104 | /******************************************************************************* |
105 | * | |
106 | * FUNCTION: acpi_hw_get_register_bit_mask | |
107 | * | |
108 | * PARAMETERS: register_id - Index of ACPI Register to access | |
109 | * | |
44f6c012 | 110 | * RETURN: The bitmask to be used when accessing the register |
1da177e4 | 111 | * |
44f6c012 | 112 | * DESCRIPTION: Map register_id into a register bitmask. |
1da177e4 LT |
113 | * |
114 | ******************************************************************************/ | |
7db5d82d | 115 | |
4be44fcd | 116 | struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) |
1da177e4 | 117 | { |
4a90c7e8 | 118 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
119 | |
120 | if (register_id > ACPI_BITREG_MAX) { | |
b229cf92 | 121 | ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X", |
b8e4d893 | 122 | register_id)); |
1da177e4 LT |
123 | return (NULL); |
124 | } | |
125 | ||
126 | return (&acpi_gbl_bit_register_info[register_id]); | |
127 | } | |
128 | ||
1da177e4 LT |
129 | /****************************************************************************** |
130 | * | |
131 | * FUNCTION: acpi_hw_register_read | |
132 | * | |
d30dc9ab | 133 | * PARAMETERS: register_id - ACPI Register ID |
44f6c012 | 134 | * return_value - Where the register value is returned |
1da177e4 LT |
135 | * |
136 | * RETURN: Status and the value read. | |
137 | * | |
967440e3 | 138 | * DESCRIPTION: Read from the specified ACPI register |
1da177e4 LT |
139 | * |
140 | ******************************************************************************/ | |
1da177e4 | 141 | acpi_status |
d30dc9ab | 142 | acpi_hw_register_read(u32 register_id, u32 * return_value) |
1da177e4 | 143 | { |
4be44fcd LB |
144 | u32 value1 = 0; |
145 | u32 value2 = 0; | |
146 | acpi_status status; | |
1da177e4 | 147 | |
b229cf92 | 148 | ACPI_FUNCTION_TRACE(hw_register_read); |
1da177e4 | 149 | |
1da177e4 | 150 | switch (register_id) { |
4be44fcd | 151 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ |
1da177e4 | 152 | |
ecfbbc7b | 153 | status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_event_block); |
4be44fcd | 154 | if (ACPI_FAILURE(status)) { |
d30dc9ab | 155 | goto exit; |
1da177e4 LT |
156 | } |
157 | ||
158 | /* PM1B is optional */ | |
159 | ||
ecfbbc7b | 160 | status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_event_block); |
1da177e4 LT |
161 | value1 |= value2; |
162 | break; | |
163 | ||
4be44fcd | 164 | case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ |
1da177e4 | 165 | |
ecfbbc7b | 166 | status = acpi_read(&value1, &acpi_gbl_xpm1a_enable); |
4be44fcd | 167 | if (ACPI_FAILURE(status)) { |
d30dc9ab | 168 | goto exit; |
1da177e4 LT |
169 | } |
170 | ||
171 | /* PM1B is optional */ | |
172 | ||
ecfbbc7b | 173 | status = acpi_read(&value2, &acpi_gbl_xpm1b_enable); |
1da177e4 LT |
174 | value1 |= value2; |
175 | break; | |
176 | ||
4be44fcd | 177 | case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ |
1da177e4 | 178 | |
ecfbbc7b | 179 | status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_control_block); |
4be44fcd | 180 | if (ACPI_FAILURE(status)) { |
d30dc9ab | 181 | goto exit; |
1da177e4 LT |
182 | } |
183 | ||
ecfbbc7b | 184 | status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_control_block); |
1da177e4 LT |
185 | value1 |= value2; |
186 | break; | |
187 | ||
4be44fcd | 188 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
1da177e4 | 189 | |
ecfbbc7b | 190 | status = acpi_read(&value1, &acpi_gbl_FADT.xpm2_control_block); |
1da177e4 LT |
191 | break; |
192 | ||
4be44fcd | 193 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
1da177e4 | 194 | |
ecfbbc7b | 195 | status = acpi_read(&value1, &acpi_gbl_FADT.xpm_timer_block); |
1da177e4 LT |
196 | break; |
197 | ||
4be44fcd | 198 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
1da177e4 | 199 | |
f3d2e786 BM |
200 | status = |
201 | acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8); | |
1da177e4 LT |
202 | break; |
203 | ||
204 | default: | |
b8e4d893 | 205 | ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id)); |
1da177e4 LT |
206 | status = AE_BAD_PARAMETER; |
207 | break; | |
208 | } | |
209 | ||
d30dc9ab | 210 | exit: |
1da177e4 | 211 | |
4be44fcd | 212 | if (ACPI_SUCCESS(status)) { |
1da177e4 LT |
213 | *return_value = value1; |
214 | } | |
215 | ||
4be44fcd | 216 | return_ACPI_STATUS(status); |
1da177e4 LT |
217 | } |
218 | ||
1da177e4 LT |
219 | /****************************************************************************** |
220 | * | |
221 | * FUNCTION: acpi_hw_register_write | |
222 | * | |
d30dc9ab | 223 | * PARAMETERS: register_id - ACPI Register ID |
1da177e4 LT |
224 | * Value - The value to write |
225 | * | |
226 | * RETURN: Status | |
227 | * | |
967440e3 BM |
228 | * DESCRIPTION: Write to the specified ACPI register |
229 | * | |
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: | |
233 | * | |
234 | * PM1_CONTROL[0] = SCI_EN | |
235 | * PM1_CONTROL[9] | |
236 | * PM1_STATUS[11] | |
237 | * | |
238 | * ACPI References: | |
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 | |
1da177e4 LT |
242 | * |
243 | ******************************************************************************/ | |
244 | ||
d30dc9ab | 245 | acpi_status acpi_hw_register_write(u32 register_id, u32 value) |
1da177e4 | 246 | { |
4be44fcd | 247 | acpi_status status; |
967440e3 | 248 | u32 read_value; |
1da177e4 | 249 | |
b229cf92 | 250 | ACPI_FUNCTION_TRACE(hw_register_write); |
1da177e4 | 251 | |
1da177e4 | 252 | switch (register_id) { |
4be44fcd | 253 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ |
1da177e4 | 254 | |
967440e3 BM |
255 | /* Perform a read first to preserve certain bits (per ACPI spec) */ |
256 | ||
d30dc9ab | 257 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, |
967440e3 BM |
258 | &read_value); |
259 | if (ACPI_FAILURE(status)) { | |
d30dc9ab | 260 | goto exit; |
967440e3 BM |
261 | } |
262 | ||
263 | /* Insert the bits to be preserved */ | |
264 | ||
265 | ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS, | |
266 | read_value); | |
267 | ||
268 | /* Now we can write the data */ | |
269 | ||
ecfbbc7b | 270 | status = acpi_write(value, &acpi_gbl_FADT.xpm1a_event_block); |
4be44fcd | 271 | if (ACPI_FAILURE(status)) { |
d30dc9ab | 272 | goto exit; |
1da177e4 LT |
273 | } |
274 | ||
275 | /* PM1B is optional */ | |
276 | ||
ecfbbc7b | 277 | status = acpi_write(value, &acpi_gbl_FADT.xpm1b_event_block); |
1da177e4 LT |
278 | break; |
279 | ||
4be44fcd | 280 | case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ |
1da177e4 | 281 | |
ecfbbc7b | 282 | status = acpi_write(value, &acpi_gbl_xpm1a_enable); |
4be44fcd | 283 | if (ACPI_FAILURE(status)) { |
d30dc9ab | 284 | goto exit; |
1da177e4 LT |
285 | } |
286 | ||
287 | /* PM1B is optional */ | |
288 | ||
ecfbbc7b | 289 | status = acpi_write(value, &acpi_gbl_xpm1b_enable); |
1da177e4 LT |
290 | break; |
291 | ||
4be44fcd | 292 | case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ |
1da177e4 | 293 | |
967440e3 BM |
294 | /* |
295 | * Perform a read first to preserve certain bits (per ACPI spec) | |
967440e3 | 296 | */ |
d30dc9ab | 297 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
967440e3 BM |
298 | &read_value); |
299 | if (ACPI_FAILURE(status)) { | |
d30dc9ab | 300 | goto exit; |
967440e3 BM |
301 | } |
302 | ||
303 | /* Insert the bits to be preserved */ | |
304 | ||
305 | ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS, | |
306 | read_value); | |
307 | ||
308 | /* Now we can write the data */ | |
309 | ||
ecfbbc7b | 310 | status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block); |
4be44fcd | 311 | if (ACPI_FAILURE(status)) { |
d30dc9ab | 312 | goto exit; |
1da177e4 LT |
313 | } |
314 | ||
ecfbbc7b | 315 | status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block); |
1da177e4 LT |
316 | break; |
317 | ||
4be44fcd | 318 | case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */ |
1da177e4 | 319 | |
ecfbbc7b | 320 | status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block); |
1da177e4 LT |
321 | break; |
322 | ||
4be44fcd | 323 | case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */ |
1da177e4 | 324 | |
ecfbbc7b | 325 | status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block); |
1da177e4 LT |
326 | break; |
327 | ||
4be44fcd | 328 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
1da177e4 | 329 | |
ecfbbc7b | 330 | status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block); |
1da177e4 LT |
331 | break; |
332 | ||
4be44fcd | 333 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
1da177e4 | 334 | |
ecfbbc7b | 335 | status = acpi_write(value, &acpi_gbl_FADT.xpm_timer_block); |
1da177e4 LT |
336 | break; |
337 | ||
4be44fcd | 338 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
1da177e4 LT |
339 | |
340 | /* SMI_CMD is currently always in IO space */ | |
341 | ||
f3d2e786 BM |
342 | status = |
343 | acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8); | |
1da177e4 LT |
344 | break; |
345 | ||
1da177e4 LT |
346 | default: |
347 | status = AE_BAD_PARAMETER; | |
348 | break; | |
349 | } | |
350 | ||
d30dc9ab | 351 | exit: |
4be44fcd | 352 | return_ACPI_STATUS(status); |
1da177e4 | 353 | } |