ACPICA: ACPI 2.0, Hardware: Add access_width/bit_offset support in acpi_hw_read()
[linux-2.6-block.git] / drivers / acpi / acpica / hwregs.c
1 /*******************************************************************************
2  *
3  * Module Name: hwregs - Read/write access functions for the various ACPI
4  *                       control and status registers.
5  *
6  ******************************************************************************/
7
8 /*
9  * Copyright (C) 2000 - 2016, Intel Corp.
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
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acevents.h"
48
49 #define _COMPONENT          ACPI_HARDWARE
50 ACPI_MODULE_NAME("hwregs")
51
52 #if (!ACPI_REDUCED_HARDWARE)
53 /* Local Prototypes */
54 static u8
55 acpi_hw_get_access_bit_width(struct acpi_generic_address *reg,
56                              u8 max_bit_width);
57
58 static acpi_status
59 acpi_hw_read_multiple(u32 *value,
60                       struct acpi_generic_address *register_a,
61                       struct acpi_generic_address *register_b);
62
63 static acpi_status
64 acpi_hw_write_multiple(u32 value,
65                        struct acpi_generic_address *register_a,
66                        struct acpi_generic_address *register_b);
67
68 #endif                          /* !ACPI_REDUCED_HARDWARE */
69
70 /******************************************************************************
71  *
72  * FUNCTION:    acpi_hw_get_access_bit_width
73  *
74  * PARAMETERS:  reg                 - GAS register structure
75  *              max_bit_width       - Max bit_width supported (32 or 64)
76  *
77  * RETURN:      Status
78  *
79  * DESCRIPTION: Obtain optimal access bit width
80  *
81  ******************************************************************************/
82
83 static u8
84 acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, u8 max_bit_width)
85 {
86         u64 address;
87
88         if (!reg->access_width) {
89                 /*
90                  * Detect old register descriptors where only the bit_width field
91                  * makes senses. The target address is copied to handle possible
92                  * alignment issues.
93                  */
94                 ACPI_MOVE_64_TO_64(&address, &reg->address);
95                 if (!reg->bit_offset && reg->bit_width &&
96                     ACPI_IS_POWER_OF_TWO(reg->bit_width) &&
97                     ACPI_IS_ALIGNED(reg->bit_width, 8) &&
98                     ACPI_IS_ALIGNED(address, reg->bit_width)) {
99                         return (reg->bit_width);
100                 } else {
101                         if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
102                                 return (32);
103                         } else {
104                                 return (max_bit_width);
105                         }
106                 }
107         } else {
108                 return (1 << (reg->access_width + 2));
109         }
110 }
111
112 /******************************************************************************
113  *
114  * FUNCTION:    acpi_hw_validate_register
115  *
116  * PARAMETERS:  reg                 - GAS register structure
117  *              max_bit_width       - Max bit_width supported (32 or 64)
118  *              address             - Pointer to where the gas->address
119  *                                    is returned
120  *
121  * RETURN:      Status
122  *
123  * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
124  *              pointer, Address, space_id, bit_width, and bit_offset.
125  *
126  ******************************************************************************/
127
128 acpi_status
129 acpi_hw_validate_register(struct acpi_generic_address *reg,
130                           u8 max_bit_width, u64 *address)
131 {
132         u8 bit_width;
133         u8 access_width;
134
135         /* Must have a valid pointer to a GAS structure */
136
137         if (!reg) {
138                 return (AE_BAD_PARAMETER);
139         }
140
141         /*
142          * Copy the target address. This handles possible alignment issues.
143          * Address must not be null. A null address also indicates an optional
144          * ACPI register that is not supported, so no error message.
145          */
146         ACPI_MOVE_64_TO_64(address, &reg->address);
147         if (!(*address)) {
148                 return (AE_BAD_ADDRESS);
149         }
150
151         /* Validate the space_ID */
152
153         if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
154             (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
155                 ACPI_ERROR((AE_INFO,
156                             "Unsupported address space: 0x%X", reg->space_id));
157                 return (AE_SUPPORT);
158         }
159
160         /* Validate the access_width */
161
162         if (reg->access_width > 4) {
163                 ACPI_ERROR((AE_INFO,
164                             "Unsupported register access width: 0x%X",
165                             reg->access_width));
166                 return (AE_SUPPORT);
167         }
168
169         /* Validate the bit_width, convert access_width into number of bits */
170
171         access_width = acpi_hw_get_access_bit_width(reg, max_bit_width);
172         bit_width =
173             ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width);
174         if (max_bit_width < bit_width) {
175                 ACPI_WARNING((AE_INFO,
176                               "Requested bit width 0x%X is smaller than register bit width 0x%X",
177                               max_bit_width, bit_width));
178                 return (AE_SUPPORT);
179         }
180
181         return (AE_OK);
182 }
183
184 /******************************************************************************
185  *
186  * FUNCTION:    acpi_hw_read
187  *
188  * PARAMETERS:  value               - Where the value is returned
189  *              reg                 - GAS register structure
190  *
191  * RETURN:      Status
192  *
193  * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
194  *              version of acpi_read, used internally since the overhead of
195  *              64-bit values is not needed.
196  *
197  * LIMITATIONS: <These limitations also apply to acpi_hw_write>
198  *      space_ID must be system_memory or system_IO.
199  *
200  ******************************************************************************/
201
202 acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
203 {
204         u64 address;
205         u8 access_width;
206         u32 bit_width;
207         u8 bit_offset;
208         u64 value64;
209         u32 value32;
210         u8 index;
211         acpi_status status;
212
213         ACPI_FUNCTION_NAME(hw_read);
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          * Initialize entire 32-bit return value to zero, convert access_width
224          * into number of bits based
225          */
226         *value = 0;
227         access_width = acpi_hw_get_access_bit_width(reg, 32);
228         bit_width = reg->bit_offset + reg->bit_width;
229         bit_offset = reg->bit_offset;
230
231         /*
232          * Two address spaces supported: Memory or IO. PCI_Config is
233          * not supported here because the GAS structure is insufficient
234          */
235         index = 0;
236         while (bit_width) {
237                 if (bit_offset >= access_width) {
238                         value32 = 0;
239                         bit_offset -= access_width;
240                 } else {
241                         if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
242                                 status =
243                                     acpi_os_read_memory((acpi_physical_address)
244                                                         address +
245                                                         index *
246                                                         ACPI_DIV_8
247                                                         (access_width),
248                                                         &value64, access_width);
249                                 value32 = (u32)value64;
250                         } else {        /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
251
252                                 status = acpi_hw_read_port((acpi_io_address)
253                                                            address +
254                                                            index *
255                                                            ACPI_DIV_8
256                                                            (access_width),
257                                                            &value32,
258                                                            access_width);
259                         }
260
261                         /*
262                          * Use offset style bit masks because:
263                          * bit_offset < access_width/bit_width < access_width, and
264                          * access_width is ensured to be less than 32-bits by
265                          * acpi_hw_validate_register().
266                          */
267                         if (bit_offset) {
268                                 value32 &= ACPI_MASK_BITS_BELOW(bit_offset);
269                                 bit_offset = 0;
270                         }
271                         if (bit_width < access_width) {
272                                 value32 &= ACPI_MASK_BITS_ABOVE(bit_width);
273                         }
274                 }
275
276                 /*
277                  * Use offset style bit writes because "Index * AccessWidth" is
278                  * ensured to be less than 32-bits by acpi_hw_validate_register().
279                  */
280                 ACPI_SET_BITS(value, index * access_width,
281                               ACPI_MASK_BITS_ABOVE_32(access_width), value32);
282
283                 bit_width -=
284                     bit_width > access_width ? access_width : bit_width;
285                 index++;
286         }
287
288         ACPI_DEBUG_PRINT((ACPI_DB_IO,
289                           "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
290                           *value, access_width, ACPI_FORMAT_UINT64(address),
291                           acpi_ut_get_region_name(reg->space_id)));
292
293         return (status);
294 }
295
296 /******************************************************************************
297  *
298  * FUNCTION:    acpi_hw_write
299  *
300  * PARAMETERS:  value               - Value to be written
301  *              reg                 - GAS register structure
302  *
303  * RETURN:      Status
304  *
305  * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
306  *              version of acpi_write, used internally since the overhead of
307  *              64-bit values is not needed.
308  *
309  ******************************************************************************/
310
311 acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
312 {
313         u64 address;
314         acpi_status status;
315
316         ACPI_FUNCTION_NAME(hw_write);
317
318         /* Validate contents of the GAS register */
319
320         status = acpi_hw_validate_register(reg, 32, &address);
321         if (ACPI_FAILURE(status)) {
322                 return (status);
323         }
324
325         /*
326          * Two address spaces supported: Memory or IO. PCI_Config is
327          * not supported here because the GAS structure is insufficient
328          */
329         if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
330                 status = acpi_os_write_memory((acpi_physical_address)
331                                               address, (u64)value,
332                                               reg->bit_width);
333         } else {                /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
334
335                 status = acpi_hw_write_port((acpi_io_address)
336                                             address, value, reg->bit_width);
337         }
338
339         ACPI_DEBUG_PRINT((ACPI_DB_IO,
340                           "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
341                           value, reg->bit_width, ACPI_FORMAT_UINT64(address),
342                           acpi_ut_get_region_name(reg->space_id)));
343
344         return (status);
345 }
346
347 #if (!ACPI_REDUCED_HARDWARE)
348 /*******************************************************************************
349  *
350  * FUNCTION:    acpi_hw_clear_acpi_status
351  *
352  * PARAMETERS:  None
353  *
354  * RETURN:      Status
355  *
356  * DESCRIPTION: Clears all fixed and general purpose status bits
357  *
358  ******************************************************************************/
359
360 acpi_status acpi_hw_clear_acpi_status(void)
361 {
362         acpi_status status;
363         acpi_cpu_flags lock_flags = 0;
364
365         ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
366
367         ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
368                           ACPI_BITMASK_ALL_FIXED_STATUS,
369                           ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
370
371         lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
372
373         /* Clear the fixed events in PM1 A/B */
374
375         status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
376                                         ACPI_BITMASK_ALL_FIXED_STATUS);
377
378         acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
379
380         if (ACPI_FAILURE(status)) {
381                 goto exit;
382         }
383
384         /* Clear the GPE Bits in all GPE registers in all GPE blocks */
385
386         status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
387
388 exit:
389         return_ACPI_STATUS(status);
390 }
391
392 /*******************************************************************************
393  *
394  * FUNCTION:    acpi_hw_get_bit_register_info
395  *
396  * PARAMETERS:  register_id         - Index of ACPI Register to access
397  *
398  * RETURN:      The bitmask to be used when accessing the register
399  *
400  * DESCRIPTION: Map register_id into a register bitmask.
401  *
402  ******************************************************************************/
403
404 struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
405 {
406         ACPI_FUNCTION_ENTRY();
407
408         if (register_id > ACPI_BITREG_MAX) {
409                 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
410                             register_id));
411                 return (NULL);
412         }
413
414         return (&acpi_gbl_bit_register_info[register_id]);
415 }
416
417 /******************************************************************************
418  *
419  * FUNCTION:    acpi_hw_write_pm1_control
420  *
421  * PARAMETERS:  pm1a_control        - Value to be written to PM1A control
422  *              pm1b_control        - Value to be written to PM1B control
423  *
424  * RETURN:      Status
425  *
426  * DESCRIPTION: Write the PM1 A/B control registers. These registers are
427  *              different than than the PM1 A/B status and enable registers
428  *              in that different values can be written to the A/B registers.
429  *              Most notably, the SLP_TYP bits can be different, as per the
430  *              values returned from the _Sx predefined methods.
431  *
432  ******************************************************************************/
433
434 acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
435 {
436         acpi_status status;
437
438         ACPI_FUNCTION_TRACE(hw_write_pm1_control);
439
440         status =
441             acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
442         if (ACPI_FAILURE(status)) {
443                 return_ACPI_STATUS(status);
444         }
445
446         if (acpi_gbl_FADT.xpm1b_control_block.address) {
447                 status =
448                     acpi_hw_write(pm1b_control,
449                                   &acpi_gbl_FADT.xpm1b_control_block);
450         }
451         return_ACPI_STATUS(status);
452 }
453
454 /******************************************************************************
455  *
456  * FUNCTION:    acpi_hw_register_read
457  *
458  * PARAMETERS:  register_id         - ACPI Register ID
459  *              return_value        - Where the register value is returned
460  *
461  * RETURN:      Status and the value read.
462  *
463  * DESCRIPTION: Read from the specified ACPI register
464  *
465  ******************************************************************************/
466 acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
467 {
468         u32 value = 0;
469         acpi_status status;
470
471         ACPI_FUNCTION_TRACE(hw_register_read);
472
473         switch (register_id) {
474         case ACPI_REGISTER_PM1_STATUS:  /* PM1 A/B: 16-bit access each */
475
476                 status = acpi_hw_read_multiple(&value,
477                                                &acpi_gbl_xpm1a_status,
478                                                &acpi_gbl_xpm1b_status);
479                 break;
480
481         case ACPI_REGISTER_PM1_ENABLE:  /* PM1 A/B: 16-bit access each */
482
483                 status = acpi_hw_read_multiple(&value,
484                                                &acpi_gbl_xpm1a_enable,
485                                                &acpi_gbl_xpm1b_enable);
486                 break;
487
488         case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
489
490                 status = acpi_hw_read_multiple(&value,
491                                                &acpi_gbl_FADT.
492                                                xpm1a_control_block,
493                                                &acpi_gbl_FADT.
494                                                xpm1b_control_block);
495
496                 /*
497                  * Zero the write-only bits. From the ACPI specification, "Hardware
498                  * Write-Only Bits": "Upon reads to registers with write-only bits,
499                  * software masks out all write-only bits."
500                  */
501                 value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
502                 break;
503
504         case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
505
506                 status =
507                     acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block);
508                 break;
509
510         case ACPI_REGISTER_PM_TIMER:    /* 32-bit access */
511
512                 status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block);
513                 break;
514
515         case ACPI_REGISTER_SMI_COMMAND_BLOCK:   /* 8-bit access */
516
517                 status =
518                     acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
519                 break;
520
521         default:
522
523                 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
524                 status = AE_BAD_PARAMETER;
525                 break;
526         }
527
528         if (ACPI_SUCCESS(status)) {
529                 *return_value = value;
530         }
531
532         return_ACPI_STATUS(status);
533 }
534
535 /******************************************************************************
536  *
537  * FUNCTION:    acpi_hw_register_write
538  *
539  * PARAMETERS:  register_id         - ACPI Register ID
540  *              value               - The value to write
541  *
542  * RETURN:      Status
543  *
544  * DESCRIPTION: Write to the specified ACPI register
545  *
546  * NOTE: In accordance with the ACPI specification, this function automatically
547  * preserves the value of the following bits, meaning that these bits cannot be
548  * changed via this interface:
549  *
550  * PM1_CONTROL[0] = SCI_EN
551  * PM1_CONTROL[9]
552  * PM1_STATUS[11]
553  *
554  * ACPI References:
555  * 1) Hardware Ignored Bits: When software writes to a register with ignored
556  *      bit fields, it preserves the ignored bit fields
557  * 2) SCI_EN: OSPM always preserves this bit position
558  *
559  ******************************************************************************/
560
561 acpi_status acpi_hw_register_write(u32 register_id, u32 value)
562 {
563         acpi_status status;
564         u32 read_value;
565
566         ACPI_FUNCTION_TRACE(hw_register_write);
567
568         switch (register_id) {
569         case ACPI_REGISTER_PM1_STATUS:  /* PM1 A/B: 16-bit access each */
570                 /*
571                  * Handle the "ignored" bit in PM1 Status. According to the ACPI
572                  * specification, ignored bits are to be preserved when writing.
573                  * Normally, this would mean a read/modify/write sequence. However,
574                  * preserving a bit in the status register is different. Writing a
575                  * one clears the status, and writing a zero preserves the status.
576                  * Therefore, we must always write zero to the ignored bit.
577                  *
578                  * This behavior is clarified in the ACPI 4.0 specification.
579                  */
580                 value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
581
582                 status = acpi_hw_write_multiple(value,
583                                                 &acpi_gbl_xpm1a_status,
584                                                 &acpi_gbl_xpm1b_status);
585                 break;
586
587         case ACPI_REGISTER_PM1_ENABLE:  /* PM1 A/B: 16-bit access each */
588
589                 status = acpi_hw_write_multiple(value,
590                                                 &acpi_gbl_xpm1a_enable,
591                                                 &acpi_gbl_xpm1b_enable);
592                 break;
593
594         case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
595                 /*
596                  * Perform a read first to preserve certain bits (per ACPI spec)
597                  * Note: This includes SCI_EN, we never want to change this bit
598                  */
599                 status = acpi_hw_read_multiple(&read_value,
600                                                &acpi_gbl_FADT.
601                                                xpm1a_control_block,
602                                                &acpi_gbl_FADT.
603                                                xpm1b_control_block);
604                 if (ACPI_FAILURE(status)) {
605                         goto exit;
606                 }
607
608                 /* Insert the bits to be preserved */
609
610                 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
611                                  read_value);
612
613                 /* Now we can write the data */
614
615                 status = acpi_hw_write_multiple(value,
616                                                 &acpi_gbl_FADT.
617                                                 xpm1a_control_block,
618                                                 &acpi_gbl_FADT.
619                                                 xpm1b_control_block);
620                 break;
621
622         case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
623                 /*
624                  * For control registers, all reserved bits must be preserved,
625                  * as per the ACPI spec.
626                  */
627                 status =
628                     acpi_hw_read(&read_value,
629                                  &acpi_gbl_FADT.xpm2_control_block);
630                 if (ACPI_FAILURE(status)) {
631                         goto exit;
632                 }
633
634                 /* Insert the bits to be preserved */
635
636                 ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
637                                  read_value);
638
639                 status =
640                     acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block);
641                 break;
642
643         case ACPI_REGISTER_PM_TIMER:    /* 32-bit access */
644
645                 status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block);
646                 break;
647
648         case ACPI_REGISTER_SMI_COMMAND_BLOCK:   /* 8-bit access */
649
650                 /* SMI_CMD is currently always in IO space */
651
652                 status =
653                     acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
654                 break;
655
656         default:
657
658                 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
659                 status = AE_BAD_PARAMETER;
660                 break;
661         }
662
663 exit:
664         return_ACPI_STATUS(status);
665 }
666
667 /******************************************************************************
668  *
669  * FUNCTION:    acpi_hw_read_multiple
670  *
671  * PARAMETERS:  value               - Where the register value is returned
672  *              register_a           - First ACPI register (required)
673  *              register_b           - Second ACPI register (optional)
674  *
675  * RETURN:      Status
676  *
677  * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
678  *
679  ******************************************************************************/
680
681 static acpi_status
682 acpi_hw_read_multiple(u32 *value,
683                       struct acpi_generic_address *register_a,
684                       struct acpi_generic_address *register_b)
685 {
686         u32 value_a = 0;
687         u32 value_b = 0;
688         acpi_status status;
689
690         /* The first register is always required */
691
692         status = acpi_hw_read(&value_a, register_a);
693         if (ACPI_FAILURE(status)) {
694                 return (status);
695         }
696
697         /* Second register is optional */
698
699         if (register_b->address) {
700                 status = acpi_hw_read(&value_b, register_b);
701                 if (ACPI_FAILURE(status)) {
702                         return (status);
703                 }
704         }
705
706         /*
707          * OR the two return values together. No shifting or masking is necessary,
708          * because of how the PM1 registers are defined in the ACPI specification:
709          *
710          * "Although the bits can be split between the two register blocks (each
711          * register block has a unique pointer within the FADT), the bit positions
712          * are maintained. The register block with unimplemented bits (that is,
713          * those implemented in the other register block) always returns zeros,
714          * and writes have no side effects"
715          */
716         *value = (value_a | value_b);
717         return (AE_OK);
718 }
719
720 /******************************************************************************
721  *
722  * FUNCTION:    acpi_hw_write_multiple
723  *
724  * PARAMETERS:  value               - The value to write
725  *              register_a           - First ACPI register (required)
726  *              register_b           - Second ACPI register (optional)
727  *
728  * RETURN:      Status
729  *
730  * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
731  *
732  ******************************************************************************/
733
734 static acpi_status
735 acpi_hw_write_multiple(u32 value,
736                        struct acpi_generic_address *register_a,
737                        struct acpi_generic_address *register_b)
738 {
739         acpi_status status;
740
741         /* The first register is always required */
742
743         status = acpi_hw_write(value, register_a);
744         if (ACPI_FAILURE(status)) {
745                 return (status);
746         }
747
748         /*
749          * Second register is optional
750          *
751          * No bit shifting or clearing is necessary, because of how the PM1
752          * registers are defined in the ACPI specification:
753          *
754          * "Although the bits can be split between the two register blocks (each
755          * register block has a unique pointer within the FADT), the bit positions
756          * are maintained. The register block with unimplemented bits (that is,
757          * those implemented in the other register block) always returns zeros,
758          * and writes have no side effects"
759          */
760         if (register_b->address) {
761                 status = acpi_hw_write(value, register_b);
762         }
763
764         return (status);
765 }
766
767 #endif                          /* !ACPI_REDUCED_HARDWARE */