blob: cc70f3fdcdd1a0f1d4222f6f7e6a84ca9ff7ebf5 [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 Mooreb4e104e2011-01-17 11:05:40 +080010 * Copyright (C) 2000 - 2011, 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 Moorec520aba2009-02-18 14:20:12 +080054/* Local Prototypes */
55static acpi_status
56acpi_hw_read_multiple(u32 *value,
57 struct acpi_generic_address *register_a,
58 struct acpi_generic_address *register_b);
59
60static acpi_status
61acpi_hw_write_multiple(u32 value,
62 struct acpi_generic_address *register_a,
63 struct acpi_generic_address *register_b);
64
Bob Moorec6b57742009-06-24 09:44:06 +080065/******************************************************************************
66 *
67 * FUNCTION: acpi_hw_validate_register
68 *
69 * PARAMETERS: Reg - GAS register structure
70 * max_bit_width - Max bit_width supported (32 or 64)
71 * Address - Pointer to where the gas->address
72 * is returned
73 *
74 * RETURN: Status
75 *
76 * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
77 * pointer, Address, space_id, bit_width, and bit_offset.
78 *
79 ******************************************************************************/
80
81acpi_status
82acpi_hw_validate_register(struct acpi_generic_address *reg,
83 u8 max_bit_width, u64 *address)
84{
85
86 /* Must have a valid pointer to a GAS structure */
87
88 if (!reg) {
89 return (AE_BAD_PARAMETER);
90 }
91
92 /*
93 * Copy the target address. This handles possible alignment issues.
94 * Address must not be null. A null address also indicates an optional
95 * ACPI register that is not supported, so no error message.
96 */
97 ACPI_MOVE_64_TO_64(address, &reg->address);
98 if (!(*address)) {
99 return (AE_BAD_ADDRESS);
100 }
101
102 /* Validate the space_iD */
103
104 if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
105 (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
106 ACPI_ERROR((AE_INFO,
107 "Unsupported address space: 0x%X", reg->space_id));
108 return (AE_SUPPORT);
109 }
110
111 /* Validate the bit_width */
112
113 if ((reg->bit_width != 8) &&
114 (reg->bit_width != 16) &&
115 (reg->bit_width != 32) && (reg->bit_width != max_bit_width)) {
116 ACPI_ERROR((AE_INFO,
117 "Unsupported register bit width: 0x%X",
118 reg->bit_width));
119 return (AE_SUPPORT);
120 }
121
122 /* Validate the bit_offset. Just a warning for now. */
123
124 if (reg->bit_offset != 0) {
125 ACPI_WARNING((AE_INFO,
126 "Unsupported register bit offset: 0x%X",
127 reg->bit_offset));
128 }
129
130 return (AE_OK);
131}
132
133/******************************************************************************
134 *
135 * FUNCTION: acpi_hw_read
136 *
137 * PARAMETERS: Value - Where the value is returned
138 * Reg - GAS register structure
139 *
140 * RETURN: Status
141 *
142 * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
143 * version of acpi_read, used internally since the overhead of
144 * 64-bit values is not needed.
145 *
146 * LIMITATIONS: <These limitations also apply to acpi_hw_write>
147 * bit_width must be exactly 8, 16, or 32.
148 * space_iD must be system_memory or system_iO.
149 * bit_offset and access_width are currently ignored, as there has
150 * not been a need to implement these.
151 *
152 ******************************************************************************/
153
154acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
155{
156 u64 address;
157 acpi_status status;
158
159 ACPI_FUNCTION_NAME(hw_read);
160
161 /* Validate contents of the GAS register */
162
163 status = acpi_hw_validate_register(reg, 32, &address);
164 if (ACPI_FAILURE(status)) {
165 return (status);
166 }
167
168 /* Initialize entire 32-bit return value to zero */
169
170 *value = 0;
171
172 /*
173 * Two address spaces supported: Memory or IO. PCI_Config is
174 * not supported here because the GAS structure is insufficient
175 */
176 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
177 status = acpi_os_read_memory((acpi_physical_address)
178 address, value, reg->bit_width);
179 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
180
181 status = acpi_hw_read_port((acpi_io_address)
182 address, value, reg->bit_width);
183 }
184
185 ACPI_DEBUG_PRINT((ACPI_DB_IO,
186 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
187 *value, reg->bit_width, ACPI_FORMAT_UINT64(address),
188 acpi_ut_get_region_name(reg->space_id)));
189
190 return (status);
191}
192
193/******************************************************************************
194 *
195 * FUNCTION: acpi_hw_write
196 *
197 * PARAMETERS: Value - Value to be written
198 * Reg - GAS register structure
199 *
200 * RETURN: Status
201 *
202 * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
203 * version of acpi_write, used internally since the overhead of
204 * 64-bit values is not needed.
205 *
206 ******************************************************************************/
207
208acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
209{
210 u64 address;
211 acpi_status status;
212
213 ACPI_FUNCTION_NAME(hw_write);
214
215 /* Validate contents of the GAS register */
216
217 status = acpi_hw_validate_register(reg, 32, &address);
218 if (ACPI_FAILURE(status)) {
219 return (status);
220 }
221
222 /*
223 * Two address spaces supported: Memory or IO. PCI_Config is
224 * not supported here because the GAS structure is insufficient
225 */
226 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
227 status = acpi_os_write_memory((acpi_physical_address)
228 address, value, reg->bit_width);
229 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
230
231 status = acpi_hw_write_port((acpi_io_address)
232 address, value, reg->bit_width);
233 }
234
235 ACPI_DEBUG_PRINT((ACPI_DB_IO,
236 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
237 value, reg->bit_width, ACPI_FORMAT_UINT64(address),
238 acpi_ut_get_region_name(reg->space_id)));
239
240 return (status);
241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*******************************************************************************
244 *
245 * FUNCTION: acpi_hw_clear_acpi_status
246 *
Bob Moored8c71b62007-02-02 19:48:21 +0300247 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 *
Bob Moore7db5d822008-12-30 11:04:48 +0800249 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 *
251 * DESCRIPTION: Clears all fixed and general purpose status bits
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *
253 ******************************************************************************/
Bob Moorec520aba2009-02-18 14:20:12 +0800254
Bob Moored8c71b62007-02-02 19:48:21 +0300255acpi_status acpi_hw_clear_acpi_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Len Brown4be44fc2005-08-05 00:44:28 -0400257 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400258 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Bob Mooreb229cf92006-04-21 17:15:00 -0400260 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Bob Moore8eb7b242009-04-22 10:28:22 +0800262 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400263 ACPI_BITMASK_ALL_FIXED_STATUS,
Bob Moore8eb7b242009-04-22 10:28:22 +0800264 ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Bob Moore4c90ece2006-06-08 16:29:00 -0400266 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Bob Moore227243a2009-02-18 14:24:50 +0800268 /* Clear the fixed events in PM1 A/B */
Bob Moore531c6332009-02-18 14:06:12 +0800269
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400270 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
Len Brown4be44fc2005-08-05 00:44:28 -0400271 ACPI_BITMASK_ALL_FIXED_STATUS);
Rakib Mullickf7f71cf2011-11-06 21:18:17 +0600272
273 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
274
275 if (ACPI_FAILURE(status))
276 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
279
Bob Mooree97d6bf2008-12-30 09:45:17 +0800280 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Rakib Mullickf7f71cf2011-11-06 21:18:17 +0600282exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400283 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286/*******************************************************************************
287 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 * FUNCTION: acpi_hw_get_register_bit_mask
289 *
290 * PARAMETERS: register_id - Index of ACPI Register to access
291 *
Robert Moore44f6c012005-04-18 22:49:35 -0400292 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 *
Robert Moore44f6c012005-04-18 22:49:35 -0400294 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 *
296 ******************************************************************************/
Bob Moore7db5d822008-12-30 11:04:48 +0800297
Len Brown4be44fc2005-08-05 00:44:28 -0400298struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500300 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (register_id > ACPI_BITREG_MAX) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800303 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500304 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return (NULL);
306 }
307
308 return (&acpi_gbl_bit_register_info[register_id]);
309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/******************************************************************************
312 *
Bob Moore32c9ef92009-02-18 14:36:05 +0800313 * FUNCTION: acpi_hw_write_pm1_control
314 *
315 * PARAMETERS: pm1a_control - Value to be written to PM1A control
316 * pm1b_control - Value to be written to PM1B control
317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: Write the PM1 A/B control registers. These registers are
321 * different than than the PM1 A/B status and enable registers
322 * in that different values can be written to the A/B registers.
323 * Most notably, the SLP_TYP bits can be different, as per the
324 * values returned from the _Sx predefined methods.
325 *
326 ******************************************************************************/
327
328acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
329{
330 acpi_status status;
331
332 ACPI_FUNCTION_TRACE(hw_write_pm1_control);
333
Bob Moorec6b57742009-06-24 09:44:06 +0800334 status =
335 acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
Bob Moore32c9ef92009-02-18 14:36:05 +0800336 if (ACPI_FAILURE(status)) {
337 return_ACPI_STATUS(status);
338 }
339
340 if (acpi_gbl_FADT.xpm1b_control_block.address) {
341 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800342 acpi_hw_write(pm1b_control,
343 &acpi_gbl_FADT.xpm1b_control_block);
Bob Moore32c9ef92009-02-18 14:36:05 +0800344 }
345 return_ACPI_STATUS(status);
346}
347
348/******************************************************************************
349 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 * FUNCTION: acpi_hw_register_read
351 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400352 * PARAMETERS: register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400353 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 *
355 * RETURN: Status and the value read.
356 *
Bob Moore967440e2006-06-23 17:04:00 -0400357 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 *
359 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360acpi_status
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400361acpi_hw_register_read(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Bob Moorec520aba2009-02-18 14:20:12 +0800363 u32 value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400364 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Bob Mooreb229cf92006-04-21 17:15:00 -0400366 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 switch (register_id) {
Bob Moorec520aba2009-02-18 14:20:12 +0800369 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Bob Moorec520aba2009-02-18 14:20:12 +0800371 status = acpi_hw_read_multiple(&value,
372 &acpi_gbl_xpm1a_status,
373 &acpi_gbl_xpm1b_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
375
Bob Moorec520aba2009-02-18 14:20:12 +0800376 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Bob Moorec520aba2009-02-18 14:20:12 +0800378 status = acpi_hw_read_multiple(&value,
379 &acpi_gbl_xpm1a_enable,
380 &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 break;
382
Bob Moorec520aba2009-02-18 14:20:12 +0800383 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Bob Moorec520aba2009-02-18 14:20:12 +0800385 status = acpi_hw_read_multiple(&value,
386 &acpi_gbl_FADT.
387 xpm1a_control_block,
388 &acpi_gbl_FADT.
389 xpm1b_control_block);
Lin Mingc3dd25f2009-03-19 09:51:01 +0800390
391 /*
392 * Zero the write-only bits. From the ACPI specification, "Hardware
393 * Write-Only Bits": "Upon reads to registers with write-only bits,
394 * software masks out all write-only bits."
395 */
396 value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 break;
398
Len Brown4be44fc2005-08-05 00:44:28 -0400399 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Bob Moorec6b57742009-06-24 09:44:06 +0800401 status =
402 acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 break;
404
Len Brown4be44fc2005-08-05 00:44:28 -0400405 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Bob Moorec6b57742009-06-24 09:44:06 +0800407 status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 break;
409
Len Brown4be44fc2005-08-05 00:44:28 -0400410 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Bob Mooref3d2e782007-02-02 19:48:18 +0300412 status =
Bob Moore7f071902009-03-19 09:37:47 +0800413 acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 break;
415
416 default:
Bob Mooref6a22b02010-03-05 17:56:40 +0800417 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 status = AE_BAD_PARAMETER;
419 break;
420 }
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 if (ACPI_SUCCESS(status)) {
Bob Moorec520aba2009-02-18 14:20:12 +0800423 *return_value = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425
Len Brown4be44fc2005-08-05 00:44:28 -0400426 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429/******************************************************************************
430 *
431 * FUNCTION: acpi_hw_register_write
432 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400433 * PARAMETERS: register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 * Value - The value to write
435 *
436 * RETURN: Status
437 *
Bob Moore967440e2006-06-23 17:04:00 -0400438 * DESCRIPTION: Write to the specified ACPI register
439 *
440 * NOTE: In accordance with the ACPI specification, this function automatically
441 * preserves the value of the following bits, meaning that these bits cannot be
442 * changed via this interface:
443 *
444 * PM1_CONTROL[0] = SCI_EN
445 * PM1_CONTROL[9]
446 * PM1_STATUS[11]
447 *
448 * ACPI References:
449 * 1) Hardware Ignored Bits: When software writes to a register with ignored
450 * bit fields, it preserves the ignored bit fields
451 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 *
453 ******************************************************************************/
454
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400455acpi_status acpi_hw_register_write(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
Len Brown4be44fc2005-08-05 00:44:28 -0400457 acpi_status status;
Bob Moore967440e2006-06-23 17:04:00 -0400458 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Bob Mooreb229cf92006-04-21 17:15:00 -0400460 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 switch (register_id) {
Bob Moorec520aba2009-02-18 14:20:12 +0800463 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
Bob Moore8636f8d2009-03-09 16:32:20 +0800464 /*
465 * Handle the "ignored" bit in PM1 Status. According to the ACPI
466 * specification, ignored bits are to be preserved when writing.
467 * Normally, this would mean a read/modify/write sequence. However,
468 * preserving a bit in the status register is different. Writing a
469 * one clears the status, and writing a zero preserves the status.
470 * Therefore, we must always write zero to the ignored bit.
471 *
472 * This behavior is clarified in the ACPI 4.0 specification.
473 */
474 value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
Bob Moore967440e2006-06-23 17:04:00 -0400475
Bob Moorec520aba2009-02-18 14:20:12 +0800476 status = acpi_hw_write_multiple(value,
477 &acpi_gbl_xpm1a_status,
478 &acpi_gbl_xpm1b_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 break;
480
Bob Moorec520aba2009-02-18 14:20:12 +0800481 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Bob Moorec520aba2009-02-18 14:20:12 +0800483 status = acpi_hw_write_multiple(value,
484 &acpi_gbl_xpm1a_enable,
485 &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
487
Bob Moorec520aba2009-02-18 14:20:12 +0800488 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Bob Moore967440e2006-06-23 17:04:00 -0400490 /*
491 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moorec520aba2009-02-18 14:20:12 +0800492 * Note: This includes SCI_EN, we never want to change this bit
Bob Moore967440e2006-06-23 17:04:00 -0400493 */
Bob Moorec520aba2009-02-18 14:20:12 +0800494 status = acpi_hw_read_multiple(&read_value,
495 &acpi_gbl_FADT.
496 xpm1a_control_block,
497 &acpi_gbl_FADT.
498 xpm1b_control_block);
Bob Moore967440e2006-06-23 17:04:00 -0400499 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400500 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400501 }
502
503 /* Insert the bits to be preserved */
504
505 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
506 read_value);
507
508 /* Now we can write the data */
509
Bob Moorec520aba2009-02-18 14:20:12 +0800510 status = acpi_hw_write_multiple(value,
511 &acpi_gbl_FADT.
512 xpm1a_control_block,
513 &acpi_gbl_FADT.
514 xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 break;
516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Bob Moore20869dc2009-03-13 09:10:46 +0800519 /*
520 * For control registers, all reserved bits must be preserved,
521 * as per the ACPI spec.
522 */
523 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800524 acpi_hw_read(&read_value,
525 &acpi_gbl_FADT.xpm2_control_block);
Bob Moore20869dc2009-03-13 09:10:46 +0800526 if (ACPI_FAILURE(status)) {
527 goto exit;
528 }
529
530 /* Insert the bits to be preserved */
531
532 ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
533 read_value);
534
Bob Moorec6b57742009-06-24 09:44:06 +0800535 status =
536 acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 break;
538
Len Brown4be44fc2005-08-05 00:44:28 -0400539 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Bob Moorec6b57742009-06-24 09:44:06 +0800541 status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 break;
543
Len Brown4be44fc2005-08-05 00:44:28 -0400544 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /* SMI_CMD is currently always in IO space */
547
Bob Mooref3d2e782007-02-02 19:48:18 +0300548 status =
Bob Moore7f071902009-03-19 09:37:47 +0800549 acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 break;
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 default:
Bob Mooref6a22b02010-03-05 17:56:40 +0800553 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 status = AE_BAD_PARAMETER;
555 break;
556 }
557
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400558 exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400559 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
Bob Moorec520aba2009-02-18 14:20:12 +0800561
562/******************************************************************************
563 *
564 * FUNCTION: acpi_hw_read_multiple
565 *
566 * PARAMETERS: Value - Where the register value is returned
567 * register_a - First ACPI register (required)
568 * register_b - Second ACPI register (optional)
569 *
570 * RETURN: Status
571 *
572 * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
573 *
574 ******************************************************************************/
575
576static acpi_status
577acpi_hw_read_multiple(u32 *value,
578 struct acpi_generic_address *register_a,
579 struct acpi_generic_address *register_b)
580{
581 u32 value_a = 0;
582 u32 value_b = 0;
583 acpi_status status;
584
585 /* The first register is always required */
586
Bob Moorec6b57742009-06-24 09:44:06 +0800587 status = acpi_hw_read(&value_a, register_a);
Bob Moorec520aba2009-02-18 14:20:12 +0800588 if (ACPI_FAILURE(status)) {
589 return (status);
590 }
591
592 /* Second register is optional */
593
594 if (register_b->address) {
Bob Moorec6b57742009-06-24 09:44:06 +0800595 status = acpi_hw_read(&value_b, register_b);
Bob Moorec520aba2009-02-18 14:20:12 +0800596 if (ACPI_FAILURE(status)) {
597 return (status);
598 }
599 }
600
Bob Mooreaefc7f92009-02-18 14:26:02 +0800601 /*
602 * OR the two return values together. No shifting or masking is necessary,
603 * because of how the PM1 registers are defined in the ACPI specification:
604 *
605 * "Although the bits can be split between the two register blocks (each
606 * register block has a unique pointer within the FADT), the bit positions
607 * are maintained. The register block with unimplemented bits (that is,
608 * those implemented in the other register block) always returns zeros,
609 * and writes have no side effects"
610 */
611 *value = (value_a | value_b);
Bob Moorec520aba2009-02-18 14:20:12 +0800612 return (AE_OK);
613}
614
615/******************************************************************************
616 *
617 * FUNCTION: acpi_hw_write_multiple
618 *
619 * PARAMETERS: Value - The value to write
620 * register_a - First ACPI register (required)
621 * register_b - Second ACPI register (optional)
622 *
623 * RETURN: Status
624 *
625 * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
626 *
627 ******************************************************************************/
628
629static acpi_status
630acpi_hw_write_multiple(u32 value,
631 struct acpi_generic_address *register_a,
632 struct acpi_generic_address *register_b)
633{
634 acpi_status status;
635
636 /* The first register is always required */
637
Bob Moorec6b57742009-06-24 09:44:06 +0800638 status = acpi_hw_write(value, register_a);
Bob Moorec520aba2009-02-18 14:20:12 +0800639 if (ACPI_FAILURE(status)) {
640 return (status);
641 }
642
Bob Mooreaefc7f92009-02-18 14:26:02 +0800643 /*
644 * Second register is optional
645 *
646 * No bit shifting or clearing is necessary, because of how the PM1
647 * registers are defined in the ACPI specification:
648 *
649 * "Although the bits can be split between the two register blocks (each
650 * register block has a unique pointer within the FADT), the bit positions
651 * are maintained. The register block with unimplemented bits (that is,
652 * those implemented in the other register block) always returns zeros,
653 * and writes have no side effects"
654 */
Bob Moorec520aba2009-02-18 14:20:12 +0800655 if (register_b->address) {
Bob Moorec6b57742009-06-24 09:44:06 +0800656 status = acpi_hw_write(value, register_b);
Bob Moorec520aba2009-02-18 14:20:12 +0800657 }
658
659 return (status);
660}