OSDN Git Service

klibc基本機能実装. ACPICAの準備
[vaneos/DivergeMirror.git] / drivers / acpi / components / hardware / hwgpe.c
1 /******************************************************************************
2  *
3  * Module Name: hwgpe - Low level GPE enable/disable/clear functions
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "acevents.h"
119
120 #define _COMPONENT          ACPI_HARDWARE
121         ACPI_MODULE_NAME    ("hwgpe")
122
123 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
124
125 /* Local prototypes */
126
127 static ACPI_STATUS
128 AcpiHwEnableWakeupGpeBlock (
129     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
130     ACPI_GPE_BLOCK_INFO     *GpeBlock,
131     void                    *Context);
132
133 static ACPI_STATUS
134 AcpiHwGpeEnableWrite (
135     UINT8                   EnableMask,
136     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo);
137
138
139 /******************************************************************************
140  *
141  * FUNCTION:    AcpiHwGetGpeRegisterBit
142  *
143  * PARAMETERS:  GpeEventInfo        - Info block for the GPE
144  *
145  * RETURN:      Register mask with a one in the GPE bit position
146  *
147  * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
148  *              correct position for the input GPE.
149  *
150  ******************************************************************************/
151
152 UINT32
153 AcpiHwGetGpeRegisterBit (
154     ACPI_GPE_EVENT_INFO     *GpeEventInfo)
155 {
156
157     return ((UINT32) 1 <<
158         (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber));
159 }
160
161
162 /******************************************************************************
163  *
164  * FUNCTION:    AcpiHwLowSetGpe
165  *
166  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to be disabled
167  *              Action              - Enable or disable
168  *
169  * RETURN:      Status
170  *
171  * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
172  *
173  ******************************************************************************/
174
175 ACPI_STATUS
176 AcpiHwLowSetGpe (
177     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
178     UINT32                  Action)
179 {
180     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
181     ACPI_STATUS             Status;
182     UINT32                  EnableMask;
183     UINT32                  RegisterBit;
184
185
186     ACPI_FUNCTION_ENTRY ();
187
188
189     /* Get the info block for the entire GPE register */
190
191     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
192     if (!GpeRegisterInfo)
193     {
194         return (AE_NOT_EXIST);
195     }
196
197     /* Get current value of the enable register that contains this GPE */
198
199     Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
200     if (ACPI_FAILURE (Status))
201     {
202         return (Status);
203     }
204
205     /* Set or clear just the bit that corresponds to this GPE */
206
207     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
208     switch (Action & ~ACPI_GPE_SAVE_MASK)
209     {
210     case ACPI_GPE_CONDITIONAL_ENABLE:
211
212         /* Only enable if the corresponding EnableMask bit is set */
213
214         if (!(RegisterBit & GpeRegisterInfo->EnableMask))
215         {
216             return (AE_BAD_PARAMETER);
217         }
218
219         /*lint -fallthrough */
220
221     case ACPI_GPE_ENABLE:
222
223         ACPI_SET_BIT (EnableMask, RegisterBit);
224         break;
225
226     case ACPI_GPE_DISABLE:
227
228         ACPI_CLEAR_BIT (EnableMask, RegisterBit);
229         break;
230
231     default:
232
233         ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
234         return (AE_BAD_PARAMETER);
235     }
236
237     /* Write the updated enable mask */
238
239     Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
240     if (ACPI_SUCCESS (Status) && (Action & ACPI_GPE_SAVE_MASK))
241     {
242         GpeRegisterInfo->EnableMask = (UINT8) EnableMask;
243     }
244     return (Status);
245 }
246
247
248 /******************************************************************************
249  *
250  * FUNCTION:    AcpiHwClearGpe
251  *
252  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to be cleared
253  *
254  * RETURN:      Status
255  *
256  * DESCRIPTION: Clear the status bit for a single GPE.
257  *
258  ******************************************************************************/
259
260 ACPI_STATUS
261 AcpiHwClearGpe (
262     ACPI_GPE_EVENT_INFO     *GpeEventInfo)
263 {
264     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
265     ACPI_STATUS             Status;
266     UINT32                  RegisterBit;
267
268
269     ACPI_FUNCTION_ENTRY ();
270
271     /* Get the info block for the entire GPE register */
272
273     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
274     if (!GpeRegisterInfo)
275     {
276         return (AE_NOT_EXIST);
277     }
278
279     /*
280      * Write a one to the appropriate bit in the status register to
281      * clear this GPE.
282      */
283     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
284
285     Status = AcpiHwWrite (RegisterBit,
286                     &GpeRegisterInfo->StatusAddress);
287
288     return (Status);
289 }
290
291
292 /******************************************************************************
293  *
294  * FUNCTION:    AcpiHwGetGpeStatus
295  *
296  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to queried
297  *              EventStatus         - Where the GPE status is returned
298  *
299  * RETURN:      Status
300  *
301  * DESCRIPTION: Return the status of a single GPE.
302  *
303  ******************************************************************************/
304
305 ACPI_STATUS
306 AcpiHwGetGpeStatus (
307     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
308     ACPI_EVENT_STATUS       *EventStatus)
309 {
310     UINT32                  InByte;
311     UINT32                  RegisterBit;
312     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
313     ACPI_EVENT_STATUS       LocalEventStatus = 0;
314     ACPI_STATUS             Status;
315
316
317     ACPI_FUNCTION_ENTRY ();
318
319
320     if (!EventStatus)
321     {
322         return (AE_BAD_PARAMETER);
323     }
324
325     /* GPE currently handled? */
326
327     if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
328             ACPI_GPE_DISPATCH_NONE)
329     {
330         LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
331     }
332
333     /* Get the info block for the entire GPE register */
334
335     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
336
337     /* Get the register bitmask for this GPE */
338
339     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
340
341     /* GPE currently enabled? (enabled for runtime?) */
342
343     if (RegisterBit & GpeRegisterInfo->EnableForRun)
344     {
345         LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
346     }
347
348     /* GPE enabled for wake? */
349
350     if (RegisterBit & GpeRegisterInfo->EnableForWake)
351     {
352         LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
353     }
354
355     /* GPE currently enabled (enable bit == 1)? */
356
357     Status = AcpiHwRead (&InByte, &GpeRegisterInfo->EnableAddress);
358     if (ACPI_FAILURE (Status))
359     {
360         return (Status);
361     }
362
363     if (RegisterBit & InByte)
364     {
365         LocalEventStatus |= ACPI_EVENT_FLAG_ENABLE_SET;
366     }
367
368     /* GPE currently active (status bit == 1)? */
369
370     Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
371     if (ACPI_FAILURE (Status))
372     {
373         return (Status);
374     }
375
376     if (RegisterBit & InByte)
377     {
378         LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
379     }
380
381     /* Set return value */
382
383     (*EventStatus) = LocalEventStatus;
384     return (AE_OK);
385 }
386
387
388 /******************************************************************************
389  *
390  * FUNCTION:    AcpiHwGpeEnableWrite
391  *
392  * PARAMETERS:  EnableMask          - Bit mask to write to the GPE register
393  *              GpeRegisterInfo     - Gpe Register info
394  *
395  * RETURN:      Status
396  *
397  * DESCRIPTION: Write the enable mask byte to the given GPE register.
398  *
399  ******************************************************************************/
400
401 static ACPI_STATUS
402 AcpiHwGpeEnableWrite (
403     UINT8                   EnableMask,
404     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo)
405 {
406     ACPI_STATUS             Status;
407
408
409     Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
410     if (ACPI_SUCCESS (Status))
411     {
412         GpeRegisterInfo->EnableMask = EnableMask;
413     }
414
415     return (Status);
416 }
417
418
419 /******************************************************************************
420  *
421  * FUNCTION:    AcpiHwDisableGpeBlock
422  *
423  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
424  *              GpeBlock            - Gpe Block info
425  *
426  * RETURN:      Status
427  *
428  * DESCRIPTION: Disable all GPEs within a single GPE block
429  *
430  ******************************************************************************/
431
432 ACPI_STATUS
433 AcpiHwDisableGpeBlock (
434     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
435     ACPI_GPE_BLOCK_INFO     *GpeBlock,
436     void                    *Context)
437 {
438     UINT32                  i;
439     ACPI_STATUS             Status;
440
441
442     /* Examine each GPE Register within the block */
443
444     for (i = 0; i < GpeBlock->RegisterCount; i++)
445     {
446         /* Disable all GPEs in this register */
447
448         Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
449         if (ACPI_FAILURE (Status))
450         {
451             return (Status);
452         }
453     }
454
455     return (AE_OK);
456 }
457
458
459 /******************************************************************************
460  *
461  * FUNCTION:    AcpiHwClearGpeBlock
462  *
463  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
464  *              GpeBlock            - Gpe Block info
465  *
466  * RETURN:      Status
467  *
468  * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
469  *
470  ******************************************************************************/
471
472 ACPI_STATUS
473 AcpiHwClearGpeBlock (
474     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
475     ACPI_GPE_BLOCK_INFO     *GpeBlock,
476     void                    *Context)
477 {
478     UINT32                  i;
479     ACPI_STATUS             Status;
480
481
482     /* Examine each GPE Register within the block */
483
484     for (i = 0; i < GpeBlock->RegisterCount; i++)
485     {
486         /* Clear status on all GPEs in this register */
487
488         Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
489         if (ACPI_FAILURE (Status))
490         {
491             return (Status);
492         }
493     }
494
495     return (AE_OK);
496 }
497
498
499 /******************************************************************************
500  *
501  * FUNCTION:    AcpiHwEnableRuntimeGpeBlock
502  *
503  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
504  *              GpeBlock            - Gpe Block info
505  *
506  * RETURN:      Status
507  *
508  * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
509  *              combination wake/run GPEs.
510  *
511  ******************************************************************************/
512
513 ACPI_STATUS
514 AcpiHwEnableRuntimeGpeBlock (
515     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
516     ACPI_GPE_BLOCK_INFO     *GpeBlock,
517     void                    *Context)
518 {
519     UINT32                  i;
520     ACPI_STATUS             Status;
521     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
522
523
524     /* NOTE: assumes that all GPEs are currently disabled */
525
526     /* Examine each GPE Register within the block */
527
528     for (i = 0; i < GpeBlock->RegisterCount; i++)
529     {
530         GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
531         if (!GpeRegisterInfo->EnableForRun)
532         {
533             continue;
534         }
535
536         /* Enable all "runtime" GPEs in this register */
537
538         Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForRun,
539                     GpeRegisterInfo);
540         if (ACPI_FAILURE (Status))
541         {
542             return (Status);
543         }
544     }
545
546     return (AE_OK);
547 }
548
549
550 /******************************************************************************
551  *
552  * FUNCTION:    AcpiHwEnableWakeupGpeBlock
553  *
554  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
555  *              GpeBlock            - Gpe Block info
556  *
557  * RETURN:      Status
558  *
559  * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
560  *              combination wake/run GPEs.
561  *
562  ******************************************************************************/
563
564 static ACPI_STATUS
565 AcpiHwEnableWakeupGpeBlock (
566     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
567     ACPI_GPE_BLOCK_INFO     *GpeBlock,
568     void                    *Context)
569 {
570     UINT32                  i;
571     ACPI_STATUS             Status;
572     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
573
574
575     /* Examine each GPE Register within the block */
576
577     for (i = 0; i < GpeBlock->RegisterCount; i++)
578     {
579         GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
580
581         /*
582          * Enable all "wake" GPEs in this register and disable the
583          * remaining ones.
584          */
585         Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
586                     GpeRegisterInfo);
587         if (ACPI_FAILURE (Status))
588         {
589             return (Status);
590         }
591     }
592
593     return (AE_OK);
594 }
595
596
597 /******************************************************************************
598  *
599  * FUNCTION:    AcpiHwDisableAllGpes
600  *
601  * PARAMETERS:  None
602  *
603  * RETURN:      Status
604  *
605  * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
606  *
607  ******************************************************************************/
608
609 ACPI_STATUS
610 AcpiHwDisableAllGpes (
611     void)
612 {
613     ACPI_STATUS             Status;
614
615
616     ACPI_FUNCTION_TRACE (HwDisableAllGpes);
617
618
619     Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
620     Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
621     return_ACPI_STATUS (Status);
622 }
623
624
625 /******************************************************************************
626  *
627  * FUNCTION:    AcpiHwEnableAllRuntimeGpes
628  *
629  * PARAMETERS:  None
630  *
631  * RETURN:      Status
632  *
633  * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
634  *
635  ******************************************************************************/
636
637 ACPI_STATUS
638 AcpiHwEnableAllRuntimeGpes (
639     void)
640 {
641     ACPI_STATUS             Status;
642
643
644     ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
645
646
647     Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
648     return_ACPI_STATUS (Status);
649 }
650
651
652 /******************************************************************************
653  *
654  * FUNCTION:    AcpiHwEnableAllWakeupGpes
655  *
656  * PARAMETERS:  None
657  *
658  * RETURN:      Status
659  *
660  * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
661  *
662  ******************************************************************************/
663
664 ACPI_STATUS
665 AcpiHwEnableAllWakeupGpes (
666     void)
667 {
668     ACPI_STATUS             Status;
669
670
671     ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
672
673
674     Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
675     return_ACPI_STATUS (Status);
676 }
677
678 #endif /* !ACPI_REDUCED_HARDWARE */