blob: 17a78e5ef175904f6c51fcc0c60bd93314e5d10e [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/*
Bob Moore77848132012-01-12 13:27:23 +080010 * Copyright (C) 2000 - 2012, 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>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
49#include "acevents.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define _COMPONENT ACPI_HARDWARE
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("hwregs")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Bob Moore33620c52012-02-14 18:14:27 +080054#if (!ACPI_REDUCED_HARDWARE)
Bob Moorec520aba2009-02-18 14:20:12 +080055/* Local Prototypes */
56static acpi_status
57acpi_hw_read_multiple(u32 *value,
58 struct acpi_generic_address *register_a,
59 struct acpi_generic_address *register_b);
60
61static acpi_status
62acpi_hw_write_multiple(u32 value,
63 struct acpi_generic_address *register_a,
64 struct acpi_generic_address *register_b);
65
Bob Moore33620c52012-02-14 18:14:27 +080066#endif /* !ACPI_REDUCED_HARDWARE */
67
Bob Moorec6b57742009-06-24 09:44:06 +080068/******************************************************************************
69 *
70 * FUNCTION: acpi_hw_validate_register
71 *
72 * PARAMETERS: Reg - GAS register structure
73 * max_bit_width - Max bit_width supported (32 or 64)
74 * Address - Pointer to where the gas->address
75 * is returned
76 *
77 * RETURN: Status
78 *
79 * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
80 * pointer, Address, space_id, bit_width, and bit_offset.
81 *
82 ******************************************************************************/
83
84acpi_status
85acpi_hw_validate_register(struct acpi_generic_address *reg,
86 u8 max_bit_width, u64 *address)
87{
88
89 /* Must have a valid pointer to a GAS structure */
90
91 if (!reg) {
92 return (AE_BAD_PARAMETER);
93 }
94
95 /*
96 * Copy the target address. This handles possible alignment issues.
97 * Address must not be null. A null address also indicates an optional
98 * ACPI register that is not supported, so no error message.
99 */
100 ACPI_MOVE_64_TO_64(address, &reg->address);
101 if (!(*address)) {
102 return (AE_BAD_ADDRESS);
103 }
104
105 /* Validate the space_iD */
106
107 if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
108 (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
109 ACPI_ERROR((AE_INFO,
110 "Unsupported address space: 0x%X", reg->space_id));
111 return (AE_SUPPORT);
112 }
113
114 /* Validate the bit_width */
115
116 if ((reg->bit_width != 8) &&
117 (reg->bit_width != 16) &&
118 (reg->bit_width != 32) && (reg->bit_width != max_bit_width)) {
119 ACPI_ERROR((AE_INFO,
120 "Unsupported register bit width: 0x%X",
121 reg->bit_width));
122 return (AE_SUPPORT);
123 }
124
125 /* Validate the bit_offset. Just a warning for now. */
126
127 if (reg->bit_offset != 0) {
128 ACPI_WARNING((AE_INFO,
129 "Unsupported register bit offset: 0x%X",
130 reg->bit_offset));
131 }
132
133 return (AE_OK);
134}
135
136/******************************************************************************
137 *
138 * FUNCTION: acpi_hw_read
139 *
140 * PARAMETERS: Value - Where the value is returned
141 * Reg - GAS register structure
142 *
143 * RETURN: Status
144 *
145 * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
146 * version of acpi_read, used internally since the overhead of
147 * 64-bit values is not needed.
148 *
149 * LIMITATIONS: <These limitations also apply to acpi_hw_write>
150 * bit_width must be exactly 8, 16, or 32.
151 * space_iD must be system_memory or system_iO.
152 * bit_offset and access_width are currently ignored, as there has
153 * not been a need to implement these.
154 *
155 ******************************************************************************/
156
157acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
158{
159 u64 address;
160 acpi_status status;
161
162 ACPI_FUNCTION_NAME(hw_read);
163
164 /* Validate contents of the GAS register */
165
166 status = acpi_hw_validate_register(reg, 32, &address);
167 if (ACPI_FAILURE(status)) {
168 return (status);
169 }
170
171 /* Initialize entire 32-bit return value to zero */
172
173 *value = 0;
174
175 /*
176 * Two address spaces supported: Memory or IO. PCI_Config is
177 * not supported here because the GAS structure is insufficient
178 */
179 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
180 status = acpi_os_read_memory((acpi_physical_address)
181 address, value, reg->bit_width);
182 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
183
184 status = acpi_hw_read_port((acpi_io_address)
185 address, value, reg->bit_width);
186 }
187
188 ACPI_DEBUG_PRINT((ACPI_DB_IO,
189 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
190 *value, reg->bit_width, ACPI_FORMAT_UINT64(address),
191 acpi_ut_get_region_name(reg->space_id)));
192
193 return (status);
194}
195
196/******************************************************************************
197 *
198 * FUNCTION: acpi_hw_write
199 *
200 * PARAMETERS: Value - Value to be written
201 * Reg - GAS register structure
202 *
203 * RETURN: Status
204 *
205 * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
206 * version of acpi_write, used internally since the overhead of
207 * 64-bit values is not needed.
208 *
209 ******************************************************************************/
210
211acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
212{
213 u64 address;
214 acpi_status status;
215
216 ACPI_FUNCTION_NAME(hw_write);
217
218 /* Validate contents of the GAS register */
219
220 status = acpi_hw_validate_register(reg, 32, &address);
221 if (ACPI_FAILURE(status)) {
222 return (status);
223 }
224
225 /*
226 * Two address spaces supported: Memory or IO. PCI_Config is
227 * not supported here because the GAS structure is insufficient
228 */
229 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
230 status = acpi_os_write_memory((acpi_physical_address)
231 address, value, reg->bit_width);
232 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
233
234 status = acpi_hw_write_port((acpi_io_address)
235 address, value, reg->bit_width);
236 }
237
238 ACPI_DEBUG_PRINT((ACPI_DB_IO,
239 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
240 value, reg->bit_width, ACPI_FORMAT_UINT64(address),
241 acpi_ut_get_region_name(reg->space_id)));
242
243 return (status);
244}
245
Bob Moore33620c52012-02-14 18:14:27 +0800246#if (!ACPI_REDUCED_HARDWARE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/*******************************************************************************
248 *
249 * FUNCTION: acpi_hw_clear_acpi_status
250 *
Bob Moored8c71b62007-02-02 19:48:21 +0300251 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *
Bob Moore7db5d822008-12-30 11:04:48 +0800253 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 *
255 * DESCRIPTION: Clears all fixed and general purpose status bits
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 *
257 ******************************************************************************/
Bob Moorec520aba2009-02-18 14:20:12 +0800258
Bob Moored8c71b62007-02-02 19:48:21 +0300259acpi_status acpi_hw_clear_acpi_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Len Brown4be44fc2005-08-05 00:44:28 -0400261 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400262 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Bob Mooreb229cf92006-04-21 17:15:00 -0400264 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Bob Moore8eb7b242009-04-22 10:28:22 +0800266 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400267 ACPI_BITMASK_ALL_FIXED_STATUS,
Bob Moore8eb7b242009-04-22 10:28:22 +0800268 ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Bob Moore4c90ece2006-06-08 16:29:00 -0400270 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Bob Moore227243a2009-02-18 14:24:50 +0800272 /* Clear the fixed events in PM1 A/B */
Bob Moore531c6332009-02-18 14:06:12 +0800273
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400274 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
Len Brown4be44fc2005-08-05 00:44:28 -0400275 ACPI_BITMASK_ALL_FIXED_STATUS);
Rakib Mullickf7f71cf2011-11-06 21:18:17 +0600276
277 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
278
279 if (ACPI_FAILURE(status))
280 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
283
Bob Mooree97d6bf2008-12-30 09:45:17 +0800284 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Rakib Mullickf7f71cf2011-11-06 21:18:17 +0600286exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400287 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/*******************************************************************************
291 *
Bob Moore33620c52012-02-14 18:14:27 +0800292 * FUNCTION: acpi_hw_get_bit_register_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 *
294 * PARAMETERS: register_id - Index of ACPI Register to access
295 *
Robert Moore44f6c012005-04-18 22:49:35 -0400296 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 *
Robert Moore44f6c012005-04-18 22:49:35 -0400298 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 *
300 ******************************************************************************/
Bob Moore7db5d822008-12-30 11:04:48 +0800301
Len Brown4be44fc2005-08-05 00:44:28 -0400302struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500304 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 if (register_id > ACPI_BITREG_MAX) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800307 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500308 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return (NULL);
310 }
311
312 return (&acpi_gbl_bit_register_info[register_id]);
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/******************************************************************************
316 *
Bob Moore32c9ef92009-02-18 14:36:05 +0800317 * FUNCTION: acpi_hw_write_pm1_control
318 *
319 * PARAMETERS: pm1a_control - Value to be written to PM1A control
320 * pm1b_control - Value to be written to PM1B control
321 *
322 * RETURN: Status
323 *
324 * DESCRIPTION: Write the PM1 A/B control registers. These registers are
325 * different than than the PM1 A/B status and enable registers
326 * in that different values can be written to the A/B registers.
327 * Most notably, the SLP_TYP bits can be different, as per the
328 * values returned from the _Sx predefined methods.
329 *
330 ******************************************************************************/
331
332acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
333{
334 acpi_status status;
335
336 ACPI_FUNCTION_TRACE(hw_write_pm1_control);
337
Bob Moorec6b57742009-06-24 09:44:06 +0800338 status =
339 acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
Bob Moore32c9ef92009-02-18 14:36:05 +0800340 if (ACPI_FAILURE(status)) {
341 return_ACPI_STATUS(status);
342 }
343
344 if (acpi_gbl_FADT.xpm1b_control_block.address) {
345 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800346 acpi_hw_write(pm1b_control,
347 &acpi_gbl_FADT.xpm1b_control_block);
Bob Moore32c9ef92009-02-18 14:36:05 +0800348 }
349 return_ACPI_STATUS(status);
350}
351
352/******************************************************************************
353 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 * FUNCTION: acpi_hw_register_read
355 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400356 * PARAMETERS: register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400357 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 *
359 * RETURN: Status and the value read.
360 *
Bob Moore967440e32006-06-23 17:04:00 -0400361 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 *
363 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364acpi_status
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400365acpi_hw_register_read(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Bob Moorec520aba2009-02-18 14:20:12 +0800367 u32 value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400368 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Bob Mooreb229cf92006-04-21 17:15:00 -0400370 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 switch (register_id) {
Bob Moorec520aba2009-02-18 14:20:12 +0800373 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Bob Moorec520aba2009-02-18 14:20:12 +0800375 status = acpi_hw_read_multiple(&value,
376 &acpi_gbl_xpm1a_status,
377 &acpi_gbl_xpm1b_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 break;
379
Bob Moorec520aba2009-02-18 14:20:12 +0800380 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Bob Moorec520aba2009-02-18 14:20:12 +0800382 status = acpi_hw_read_multiple(&value,
383 &acpi_gbl_xpm1a_enable,
384 &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
386
Bob Moorec520aba2009-02-18 14:20:12 +0800387 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Bob Moorec520aba2009-02-18 14:20:12 +0800389 status = acpi_hw_read_multiple(&value,
390 &acpi_gbl_FADT.
391 xpm1a_control_block,
392 &acpi_gbl_FADT.
393 xpm1b_control_block);
Lin Mingc3dd25f2009-03-19 09:51:01 +0800394
395 /*
396 * Zero the write-only bits. From the ACPI specification, "Hardware
397 * Write-Only Bits": "Upon reads to registers with write-only bits,
398 * software masks out all write-only bits."
399 */
400 value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Bob Moorec6b57742009-06-24 09:44:06 +0800405 status =
406 acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Bob Moorec6b57742009-06-24 09:44:06 +0800411 status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Bob Mooref3d2e782007-02-02 19:48:18 +0300416 status =
Bob Moore7f071902009-03-19 09:37:47 +0800417 acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 break;
419
420 default:
Bob Mooref6a22b02010-03-05 17:56:40 +0800421 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 status = AE_BAD_PARAMETER;
423 break;
424 }
425
Len Brown4be44fc2005-08-05 00:44:28 -0400426 if (ACPI_SUCCESS(status)) {
Bob Moorec520aba2009-02-18 14:20:12 +0800427 *return_value = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433/******************************************************************************
434 *
435 * FUNCTION: acpi_hw_register_write
436 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400437 * PARAMETERS: register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 * Value - The value to write
439 *
440 * RETURN: Status
441 *
Bob Moore967440e32006-06-23 17:04:00 -0400442 * DESCRIPTION: Write to the specified ACPI register
443 *
444 * NOTE: In accordance with the ACPI specification, this function automatically
445 * preserves the value of the following bits, meaning that these bits cannot be
446 * changed via this interface:
447 *
448 * PM1_CONTROL[0] = SCI_EN
449 * PM1_CONTROL[9]
450 * PM1_STATUS[11]
451 *
452 * ACPI References:
453 * 1) Hardware Ignored Bits: When software writes to a register with ignored
454 * bit fields, it preserves the ignored bit fields
455 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 *
457 ******************************************************************************/
458
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400459acpi_status acpi_hw_register_write(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
Len Brown4be44fc2005-08-05 00:44:28 -0400461 acpi_status status;
Bob Moore967440e32006-06-23 17:04:00 -0400462 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Bob Mooreb229cf92006-04-21 17:15:00 -0400464 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 switch (register_id) {
Bob Moorec520aba2009-02-18 14:20:12 +0800467 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
Bob Moore8636f8d2009-03-09 16:32:20 +0800468 /*
469 * Handle the "ignored" bit in PM1 Status. According to the ACPI
470 * specification, ignored bits are to be preserved when writing.
471 * Normally, this would mean a read/modify/write sequence. However,
472 * preserving a bit in the status register is different. Writing a
473 * one clears the status, and writing a zero preserves the status.
474 * Therefore, we must always write zero to the ignored bit.
475 *
476 * This behavior is clarified in the ACPI 4.0 specification.
477 */
478 value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
Bob Moore967440e32006-06-23 17:04:00 -0400479
Bob Moorec520aba2009-02-18 14:20:12 +0800480 status = acpi_hw_write_multiple(value,
481 &acpi_gbl_xpm1a_status,
482 &acpi_gbl_xpm1b_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 break;
484
Bob Moorec520aba2009-02-18 14:20:12 +0800485 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Bob Moorec520aba2009-02-18 14:20:12 +0800487 status = acpi_hw_write_multiple(value,
488 &acpi_gbl_xpm1a_enable,
489 &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
Bob Moorec520aba2009-02-18 14:20:12 +0800492 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Bob Moore967440e32006-06-23 17:04:00 -0400494 /*
495 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moorec520aba2009-02-18 14:20:12 +0800496 * Note: This includes SCI_EN, we never want to change this bit
Bob Moore967440e32006-06-23 17:04:00 -0400497 */
Bob Moorec520aba2009-02-18 14:20:12 +0800498 status = acpi_hw_read_multiple(&read_value,
499 &acpi_gbl_FADT.
500 xpm1a_control_block,
501 &acpi_gbl_FADT.
502 xpm1b_control_block);
Bob Moore967440e32006-06-23 17:04:00 -0400503 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400504 goto exit;
Bob Moore967440e32006-06-23 17:04:00 -0400505 }
506
507 /* Insert the bits to be preserved */
508
509 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
510 read_value);
511
512 /* Now we can write the data */
513
Bob Moorec520aba2009-02-18 14:20:12 +0800514 status = acpi_hw_write_multiple(value,
515 &acpi_gbl_FADT.
516 xpm1a_control_block,
517 &acpi_gbl_FADT.
518 xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 break;
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Bob Moore20869dc2009-03-13 09:10:46 +0800523 /*
524 * For control registers, all reserved bits must be preserved,
525 * as per the ACPI spec.
526 */
527 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800528 acpi_hw_read(&read_value,
529 &acpi_gbl_FADT.xpm2_control_block);
Bob Moore20869dc2009-03-13 09:10:46 +0800530 if (ACPI_FAILURE(status)) {
531 goto exit;
532 }
533
534 /* Insert the bits to be preserved */
535
536 ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
537 read_value);
538
Bob Moorec6b57742009-06-24 09:44:06 +0800539 status =
540 acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 break;
542
Len Brown4be44fc2005-08-05 00:44:28 -0400543 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Bob Moorec6b57742009-06-24 09:44:06 +0800545 status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 break;
547
Len Brown4be44fc2005-08-05 00:44:28 -0400548 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 /* SMI_CMD is currently always in IO space */
551
Bob Mooref3d2e782007-02-02 19:48:18 +0300552 status =
Bob Moore7f071902009-03-19 09:37:47 +0800553 acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 break;
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 default:
Bob Mooref6a22b02010-03-05 17:56:40 +0800557 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 status = AE_BAD_PARAMETER;
559 break;
560 }
561
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400562 exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400563 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
Bob Moorec520aba2009-02-18 14:20:12 +0800565
566/******************************************************************************
567 *
568 * FUNCTION: acpi_hw_read_multiple
569 *
570 * PARAMETERS: Value - Where the register value is returned
571 * register_a - First ACPI register (required)
572 * register_b - Second ACPI register (optional)
573 *
574 * RETURN: Status
575 *
576 * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
577 *
578 ******************************************************************************/
579
580static acpi_status
581acpi_hw_read_multiple(u32 *value,
582 struct acpi_generic_address *register_a,
583 struct acpi_generic_address *register_b)
584{
585 u32 value_a = 0;
586 u32 value_b = 0;
587 acpi_status status;
588
589 /* The first register is always required */
590
Bob Moorec6b57742009-06-24 09:44:06 +0800591 status = acpi_hw_read(&value_a, register_a);
Bob Moorec520aba2009-02-18 14:20:12 +0800592 if (ACPI_FAILURE(status)) {
593 return (status);
594 }
595
596 /* Second register is optional */
597
598 if (register_b->address) {
Bob Moorec6b57742009-06-24 09:44:06 +0800599 status = acpi_hw_read(&value_b, register_b);
Bob Moorec520aba2009-02-18 14:20:12 +0800600 if (ACPI_FAILURE(status)) {
601 return (status);
602 }
603 }
604
Bob Mooreaefc7f92009-02-18 14:26:02 +0800605 /*
606 * OR the two return values together. No shifting or masking is necessary,
607 * because of how the PM1 registers are defined in the ACPI specification:
608 *
609 * "Although the bits can be split between the two register blocks (each
610 * register block has a unique pointer within the FADT), the bit positions
611 * are maintained. The register block with unimplemented bits (that is,
612 * those implemented in the other register block) always returns zeros,
613 * and writes have no side effects"
614 */
615 *value = (value_a | value_b);
Bob Moorec520aba2009-02-18 14:20:12 +0800616 return (AE_OK);
617}
618
619/******************************************************************************
620 *
621 * FUNCTION: acpi_hw_write_multiple
622 *
623 * PARAMETERS: Value - The value to write
624 * register_a - First ACPI register (required)
625 * register_b - Second ACPI register (optional)
626 *
627 * RETURN: Status
628 *
629 * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
630 *
631 ******************************************************************************/
632
633static acpi_status
634acpi_hw_write_multiple(u32 value,
635 struct acpi_generic_address *register_a,
636 struct acpi_generic_address *register_b)
637{
638 acpi_status status;
639
640 /* The first register is always required */
641
Bob Moorec6b57742009-06-24 09:44:06 +0800642 status = acpi_hw_write(value, register_a);
Bob Moorec520aba2009-02-18 14:20:12 +0800643 if (ACPI_FAILURE(status)) {
644 return (status);
645 }
646
Bob Mooreaefc7f92009-02-18 14:26:02 +0800647 /*
648 * Second register is optional
649 *
650 * No bit shifting or clearing is necessary, because of how the PM1
651 * registers are defined in the ACPI specification:
652 *
653 * "Although the bits can be split between the two register blocks (each
654 * register block has a unique pointer within the FADT), the bit positions
655 * are maintained. The register block with unimplemented bits (that is,
656 * those implemented in the other register block) always returns zeros,
657 * and writes have no side effects"
658 */
Bob Moorec520aba2009-02-18 14:20:12 +0800659 if (register_b->address) {
Bob Moorec6b57742009-06-24 09:44:06 +0800660 status = acpi_hw_write(value, register_b);
Bob Moorec520aba2009-02-18 14:20:12 +0800661 }
662
663 return (status);
664}
Bob Moore33620c52012-02-14 18:14:27 +0800665
666#endif /* !ACPI_REDUCED_HARDWARE */