ACPICA: Cleanup source to reduce differences between Linux and ACPICA.
[linux-2.6-block.git] / drivers / acpi / acpica / hwregs.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
3 * Module Name: hwregs - Read/write access functions for the various ACPI
4 * control and status registers.
5 *
6 ******************************************************************************/
7
8/*
77848130 9 * Copyright (C) 2000 - 2012, Intel Corp.
1da177e4
LT
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
1da177e4 45#include <acpi/acpi.h>
e2f7a777 46#include "accommon.h"
e2f7a777 47#include "acevents.h"
1da177e4
LT
48
49#define _COMPONENT ACPI_HARDWARE
4be44fcd 50ACPI_MODULE_NAME("hwregs")
1da177e4 51
33620c54 52#if (!ACPI_REDUCED_HARDWARE)
c520abad
BM
53/* Local Prototypes */
54static acpi_status
55acpi_hw_read_multiple(u32 *value,
56 struct acpi_generic_address *register_a,
57 struct acpi_generic_address *register_b);
58
59static acpi_status
60acpi_hw_write_multiple(u32 value,
61 struct acpi_generic_address *register_a,
62 struct acpi_generic_address *register_b);
63
33620c54
BM
64#endif /* !ACPI_REDUCED_HARDWARE */
65
c6b5774c
BM
66/******************************************************************************
67 *
68 * FUNCTION: acpi_hw_validate_register
69 *
ba494bee 70 * PARAMETERS: reg - GAS register structure
c6b5774c 71 * max_bit_width - Max bit_width supported (32 or 64)
ba494bee 72 * address - Pointer to where the gas->address
c6b5774c
BM
73 * is returned
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
78 * pointer, Address, space_id, bit_width, and bit_offset.
79 *
80 ******************************************************************************/
81
82acpi_status
83acpi_hw_validate_register(struct acpi_generic_address *reg,
84 u8 max_bit_width, u64 *address)
85{
86
87 /* Must have a valid pointer to a GAS structure */
88
89 if (!reg) {
90 return (AE_BAD_PARAMETER);
91 }
92
93 /*
94 * Copy the target address. This handles possible alignment issues.
95 * Address must not be null. A null address also indicates an optional
96 * ACPI register that is not supported, so no error message.
97 */
98 ACPI_MOVE_64_TO_64(address, &reg->address);
99 if (!(*address)) {
100 return (AE_BAD_ADDRESS);
101 }
102
ba494bee 103 /* Validate the space_ID */
c6b5774c
BM
104
105 if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
106 (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
107 ACPI_ERROR((AE_INFO,
108 "Unsupported address space: 0x%X", reg->space_id));
109 return (AE_SUPPORT);
110 }
111
112 /* Validate the bit_width */
113
114 if ((reg->bit_width != 8) &&
115 (reg->bit_width != 16) &&
116 (reg->bit_width != 32) && (reg->bit_width != max_bit_width)) {
117 ACPI_ERROR((AE_INFO,
118 "Unsupported register bit width: 0x%X",
119 reg->bit_width));
120 return (AE_SUPPORT);
121 }
122
123 /* Validate the bit_offset. Just a warning for now. */
124
125 if (reg->bit_offset != 0) {
126 ACPI_WARNING((AE_INFO,
127 "Unsupported register bit offset: 0x%X",
128 reg->bit_offset));
129 }
130
131 return (AE_OK);
132}
133
134/******************************************************************************
135 *
136 * FUNCTION: acpi_hw_read
137 *
ba494bee
BM
138 * PARAMETERS: value - Where the value is returned
139 * reg - GAS register structure
c6b5774c
BM
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
144 * version of acpi_read, used internally since the overhead of
145 * 64-bit values is not needed.
146 *
147 * LIMITATIONS: <These limitations also apply to acpi_hw_write>
148 * bit_width must be exactly 8, 16, or 32.
ba494bee 149 * space_ID must be system_memory or system_IO.
c6b5774c
BM
150 * bit_offset and access_width are currently ignored, as there has
151 * not been a need to implement these.
152 *
153 ******************************************************************************/
154
155acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
156{
157 u64 address;
653f4b53 158 u64 value64;
c6b5774c
BM
159 acpi_status status;
160
161 ACPI_FUNCTION_NAME(hw_read);
162
163 /* Validate contents of the GAS register */
164
165 status = acpi_hw_validate_register(reg, 32, &address);
166 if (ACPI_FAILURE(status)) {
167 return (status);
168 }
169
170 /* Initialize entire 32-bit return value to zero */
171
172 *value = 0;
173
174 /*
175 * Two address spaces supported: Memory or IO. PCI_Config is
176 * not supported here because the GAS structure is insufficient
177 */
178 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
179 status = acpi_os_read_memory((acpi_physical_address)
653f4b53
BM
180 address, &value64, reg->bit_width);
181
182 *value = (u32)value64;
c6b5774c
BM
183 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
184
185 status = acpi_hw_read_port((acpi_io_address)
186 address, value, reg->bit_width);
187 }
188
189 ACPI_DEBUG_PRINT((ACPI_DB_IO,
190 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
191 *value, reg->bit_width, ACPI_FORMAT_UINT64(address),
192 acpi_ut_get_region_name(reg->space_id)));
193
194 return (status);
195}
196
197/******************************************************************************
198 *
199 * FUNCTION: acpi_hw_write
200 *
ba494bee
BM
201 * PARAMETERS: value - Value to be written
202 * reg - GAS register structure
c6b5774c
BM
203 *
204 * RETURN: Status
205 *
206 * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
207 * version of acpi_write, used internally since the overhead of
208 * 64-bit values is not needed.
209 *
210 ******************************************************************************/
211
212acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
213{
214 u64 address;
215 acpi_status status;
216
217 ACPI_FUNCTION_NAME(hw_write);
218
219 /* Validate contents of the GAS register */
220
221 status = acpi_hw_validate_register(reg, 32, &address);
222 if (ACPI_FAILURE(status)) {
223 return (status);
224 }
225
226 /*
227 * Two address spaces supported: Memory or IO. PCI_Config is
228 * not supported here because the GAS structure is insufficient
229 */
230 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
231 status = acpi_os_write_memory((acpi_physical_address)
653f4b53
BM
232 address, (u64)value,
233 reg->bit_width);
c6b5774c
BM
234 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
235
236 status = acpi_hw_write_port((acpi_io_address)
237 address, value, reg->bit_width);
238 }
239
240 ACPI_DEBUG_PRINT((ACPI_DB_IO,
241 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
242 value, reg->bit_width, ACPI_FORMAT_UINT64(address),
243 acpi_ut_get_region_name(reg->space_id)));
244
245 return (status);
246}
247
33620c54 248#if (!ACPI_REDUCED_HARDWARE)
1da177e4
LT
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_hw_clear_acpi_status
252 *
d8c71b6d 253 * PARAMETERS: None
1da177e4 254 *
7db5d82d 255 * RETURN: Status
1da177e4
LT
256 *
257 * DESCRIPTION: Clears all fixed and general purpose status bits
1da177e4
LT
258 *
259 ******************************************************************************/
c520abad 260
d8c71b6d 261acpi_status acpi_hw_clear_acpi_status(void)
1da177e4 262{
4be44fcd 263 acpi_status status;
4c90ece2 264 acpi_cpu_flags lock_flags = 0;
1da177e4 265
b229cf92 266 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
1da177e4 267
8eb7b247 268 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
4be44fcd 269 ACPI_BITMASK_ALL_FIXED_STATUS,
8eb7b247 270 ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
1da177e4 271
4c90ece2 272 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
1da177e4 273
227243a0 274 /* Clear the fixed events in PM1 A/B */
531c633d 275
d30dc9ab 276 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
4be44fcd 277 ACPI_BITMASK_ALL_FIXED_STATUS);
f7f71cfb
RM
278
279 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
280
281 if (ACPI_FAILURE(status))
282 goto exit;
1da177e4 283
1da177e4
LT
284 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
285
e97d6bf1 286 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
1da177e4 287
f7f71cfb 288exit:
4be44fcd 289 return_ACPI_STATUS(status);
1da177e4
LT
290}
291
1da177e4
LT
292/*******************************************************************************
293 *
33620c54 294 * FUNCTION: acpi_hw_get_bit_register_info
1da177e4
LT
295 *
296 * PARAMETERS: register_id - Index of ACPI Register to access
297 *
44f6c012 298 * RETURN: The bitmask to be used when accessing the register
1da177e4 299 *
44f6c012 300 * DESCRIPTION: Map register_id into a register bitmask.
1da177e4
LT
301 *
302 ******************************************************************************/
7db5d82d 303
4be44fcd 304struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
1da177e4 305{
4a90c7e8 306 ACPI_FUNCTION_ENTRY();
1da177e4
LT
307
308 if (register_id > ACPI_BITREG_MAX) {
f6a22b0b 309 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
b8e4d893 310 register_id));
1da177e4
LT
311 return (NULL);
312 }
313
314 return (&acpi_gbl_bit_register_info[register_id]);
315}
316
32c9ef99
BM
317/******************************************************************************
318 *
319 * FUNCTION: acpi_hw_write_pm1_control
320 *
321 * PARAMETERS: pm1a_control - Value to be written to PM1A control
322 * pm1b_control - Value to be written to PM1B control
323 *
324 * RETURN: Status
325 *
326 * DESCRIPTION: Write the PM1 A/B control registers. These registers are
327 * different than than the PM1 A/B status and enable registers
328 * in that different values can be written to the A/B registers.
329 * Most notably, the SLP_TYP bits can be different, as per the
330 * values returned from the _Sx predefined methods.
331 *
332 ******************************************************************************/
333
334acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
335{
336 acpi_status status;
337
338 ACPI_FUNCTION_TRACE(hw_write_pm1_control);
339
c6b5774c
BM
340 status =
341 acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
32c9ef99
BM
342 if (ACPI_FAILURE(status)) {
343 return_ACPI_STATUS(status);
344 }
345
346 if (acpi_gbl_FADT.xpm1b_control_block.address) {
347 status =
c6b5774c
BM
348 acpi_hw_write(pm1b_control,
349 &acpi_gbl_FADT.xpm1b_control_block);
32c9ef99
BM
350 }
351 return_ACPI_STATUS(status);
352}
353
1da177e4
LT
354/******************************************************************************
355 *
356 * FUNCTION: acpi_hw_register_read
357 *
d30dc9ab 358 * PARAMETERS: register_id - ACPI Register ID
44f6c012 359 * return_value - Where the register value is returned
1da177e4
LT
360 *
361 * RETURN: Status and the value read.
362 *
967440e3 363 * DESCRIPTION: Read from the specified ACPI register
1da177e4
LT
364 *
365 ******************************************************************************/
1da177e4 366acpi_status
d30dc9ab 367acpi_hw_register_read(u32 register_id, u32 * return_value)
1da177e4 368{
c520abad 369 u32 value = 0;
4be44fcd 370 acpi_status status;
1da177e4 371
b229cf92 372 ACPI_FUNCTION_TRACE(hw_register_read);
1da177e4 373
1da177e4 374 switch (register_id) {
c520abad 375 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
1da177e4 376
c520abad
BM
377 status = acpi_hw_read_multiple(&value,
378 &acpi_gbl_xpm1a_status,
379 &acpi_gbl_xpm1b_status);
1da177e4
LT
380 break;
381
c520abad 382 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
1da177e4 383
c520abad
BM
384 status = acpi_hw_read_multiple(&value,
385 &acpi_gbl_xpm1a_enable,
386 &acpi_gbl_xpm1b_enable);
1da177e4
LT
387 break;
388
c520abad 389 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
1da177e4 390
c520abad
BM
391 status = acpi_hw_read_multiple(&value,
392 &acpi_gbl_FADT.
393 xpm1a_control_block,
394 &acpi_gbl_FADT.
395 xpm1b_control_block);
c3dd25f4
LM
396
397 /*
398 * Zero the write-only bits. From the ACPI specification, "Hardware
399 * Write-Only Bits": "Upon reads to registers with write-only bits,
400 * software masks out all write-only bits."
401 */
402 value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
1da177e4
LT
403 break;
404
4be44fcd 405 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
1da177e4 406
c6b5774c
BM
407 status =
408 acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block);
1da177e4
LT
409 break;
410
4be44fcd 411 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
1da177e4 412
c6b5774c 413 status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block);
1da177e4
LT
414 break;
415
4be44fcd 416 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
1da177e4 417
f3d2e786 418 status =
7f071903 419 acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
1da177e4
LT
420 break;
421
422 default:
f6a22b0b 423 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
1da177e4
LT
424 status = AE_BAD_PARAMETER;
425 break;
426 }
427
4be44fcd 428 if (ACPI_SUCCESS(status)) {
c520abad 429 *return_value = value;
1da177e4
LT
430 }
431
4be44fcd 432 return_ACPI_STATUS(status);
1da177e4
LT
433}
434
1da177e4
LT
435/******************************************************************************
436 *
437 * FUNCTION: acpi_hw_register_write
438 *
d30dc9ab 439 * PARAMETERS: register_id - ACPI Register ID
ba494bee 440 * value - The value to write
1da177e4
LT
441 *
442 * RETURN: Status
443 *
967440e3
BM
444 * DESCRIPTION: Write to the specified ACPI register
445 *
446 * NOTE: In accordance with the ACPI specification, this function automatically
447 * preserves the value of the following bits, meaning that these bits cannot be
448 * changed via this interface:
449 *
450 * PM1_CONTROL[0] = SCI_EN
451 * PM1_CONTROL[9]
452 * PM1_STATUS[11]
453 *
454 * ACPI References:
455 * 1) Hardware Ignored Bits: When software writes to a register with ignored
456 * bit fields, it preserves the ignored bit fields
457 * 2) SCI_EN: OSPM always preserves this bit position
1da177e4
LT
458 *
459 ******************************************************************************/
460
d30dc9ab 461acpi_status acpi_hw_register_write(u32 register_id, u32 value)
1da177e4 462{
4be44fcd 463 acpi_status status;
967440e3 464 u32 read_value;
1da177e4 465
b229cf92 466 ACPI_FUNCTION_TRACE(hw_register_write);
1da177e4 467
1da177e4 468 switch (register_id) {
c520abad 469 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
8636f8d2
BM
470 /*
471 * Handle the "ignored" bit in PM1 Status. According to the ACPI
472 * specification, ignored bits are to be preserved when writing.
473 * Normally, this would mean a read/modify/write sequence. However,
474 * preserving a bit in the status register is different. Writing a
475 * one clears the status, and writing a zero preserves the status.
476 * Therefore, we must always write zero to the ignored bit.
477 *
478 * This behavior is clarified in the ACPI 4.0 specification.
479 */
480 value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
967440e3 481
c520abad
BM
482 status = acpi_hw_write_multiple(value,
483 &acpi_gbl_xpm1a_status,
484 &acpi_gbl_xpm1b_status);
1da177e4
LT
485 break;
486
75c8044f 487 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
1da177e4 488
c520abad
BM
489 status = acpi_hw_write_multiple(value,
490 &acpi_gbl_xpm1a_enable,
491 &acpi_gbl_xpm1b_enable);
1da177e4
LT
492 break;
493
c520abad 494 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
1da177e4 495
967440e3
BM
496 /*
497 * Perform a read first to preserve certain bits (per ACPI spec)
c520abad 498 * Note: This includes SCI_EN, we never want to change this bit
967440e3 499 */
c520abad
BM
500 status = acpi_hw_read_multiple(&read_value,
501 &acpi_gbl_FADT.
502 xpm1a_control_block,
503 &acpi_gbl_FADT.
504 xpm1b_control_block);
967440e3 505 if (ACPI_FAILURE(status)) {
d30dc9ab 506 goto exit;
967440e3
BM
507 }
508
509 /* Insert the bits to be preserved */
510
511 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
512 read_value);
513
514 /* Now we can write the data */
515
c520abad
BM
516 status = acpi_hw_write_multiple(value,
517 &acpi_gbl_FADT.
518 xpm1a_control_block,
519 &acpi_gbl_FADT.
520 xpm1b_control_block);
1da177e4
LT
521 break;
522
4be44fcd 523 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
1da177e4 524
20869dcf
BM
525 /*
526 * For control registers, all reserved bits must be preserved,
527 * as per the ACPI spec.
528 */
529 status =
c6b5774c
BM
530 acpi_hw_read(&read_value,
531 &acpi_gbl_FADT.xpm2_control_block);
20869dcf
BM
532 if (ACPI_FAILURE(status)) {
533 goto exit;
534 }
535
536 /* Insert the bits to be preserved */
537
538 ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
539 read_value);
540
c6b5774c
BM
541 status =
542 acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block);
1da177e4
LT
543 break;
544
4be44fcd 545 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
1da177e4 546
c6b5774c 547 status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block);
1da177e4
LT
548 break;
549
4be44fcd 550 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
1da177e4
LT
551
552 /* SMI_CMD is currently always in IO space */
553
f3d2e786 554 status =
7f071903 555 acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
1da177e4
LT
556 break;
557
1da177e4 558 default:
f6a22b0b 559 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
1da177e4
LT
560 status = AE_BAD_PARAMETER;
561 break;
562 }
563
d30dc9ab 564 exit:
4be44fcd 565 return_ACPI_STATUS(status);
1da177e4 566}
c520abad
BM
567
568/******************************************************************************
569 *
570 * FUNCTION: acpi_hw_read_multiple
571 *
ba494bee 572 * PARAMETERS: value - Where the register value is returned
c520abad
BM
573 * register_a - First ACPI register (required)
574 * register_b - Second ACPI register (optional)
575 *
576 * RETURN: Status
577 *
578 * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
579 *
580 ******************************************************************************/
581
582static acpi_status
583acpi_hw_read_multiple(u32 *value,
584 struct acpi_generic_address *register_a,
585 struct acpi_generic_address *register_b)
586{
587 u32 value_a = 0;
588 u32 value_b = 0;
589 acpi_status status;
590
591 /* The first register is always required */
592
c6b5774c 593 status = acpi_hw_read(&value_a, register_a);
c520abad
BM
594 if (ACPI_FAILURE(status)) {
595 return (status);
596 }
597
598 /* Second register is optional */
599
600 if (register_b->address) {
c6b5774c 601 status = acpi_hw_read(&value_b, register_b);
c520abad
BM
602 if (ACPI_FAILURE(status)) {
603 return (status);
604 }
605 }
606
aefc7f9a
BM
607 /*
608 * OR the two return values together. No shifting or masking is necessary,
609 * because of how the PM1 registers are defined in the ACPI specification:
610 *
611 * "Although the bits can be split between the two register blocks (each
612 * register block has a unique pointer within the FADT), the bit positions
613 * are maintained. The register block with unimplemented bits (that is,
614 * those implemented in the other register block) always returns zeros,
615 * and writes have no side effects"
616 */
617 *value = (value_a | value_b);
c520abad
BM
618 return (AE_OK);
619}
620
621/******************************************************************************
622 *
623 * FUNCTION: acpi_hw_write_multiple
624 *
ba494bee 625 * PARAMETERS: value - The value to write
c520abad
BM
626 * register_a - First ACPI register (required)
627 * register_b - Second ACPI register (optional)
628 *
629 * RETURN: Status
630 *
631 * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
632 *
633 ******************************************************************************/
634
635static acpi_status
636acpi_hw_write_multiple(u32 value,
637 struct acpi_generic_address *register_a,
638 struct acpi_generic_address *register_b)
639{
640 acpi_status status;
641
642 /* The first register is always required */
643
c6b5774c 644 status = acpi_hw_write(value, register_a);
c520abad
BM
645 if (ACPI_FAILURE(status)) {
646 return (status);
647 }
648
aefc7f9a
BM
649 /*
650 * Second register is optional
651 *
652 * No bit shifting or clearing is necessary, because of how the PM1
653 * registers are defined in the ACPI specification:
654 *
655 * "Although the bits can be split between the two register blocks (each
656 * register block has a unique pointer within the FADT), the bit positions
657 * are maintained. The register block with unimplemented bits (that is,
658 * those implemented in the other register block) always returns zeros,
659 * and writes have no side effects"
660 */
c520abad 661 if (register_b->address) {
c6b5774c 662 status = acpi_hw_write(value, register_b);
c520abad
BM
663 }
664
665 return (status);
666}
33620c54
BM
667
668#endif /* !ACPI_REDUCED_HARDWARE */