[ACPI]
[reactos.git] / reactos / drivers / bus / acpi / acpica / events / evxfgpe.c
1 /******************************************************************************
2 *
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2014, 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
117 #define __EVXFGPE_C__
118 #define EXPORT_ACPI_INTERFACES
119
120 #include "acpi.h"
121 #include "accommon.h"
122 #include "acevents.h"
123 #include "acnamesp.h"
124
125 #define _COMPONENT ACPI_EVENTS
126 ACPI_MODULE_NAME ("evxfgpe")
127
128
129 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
130 /*******************************************************************************
131 *
132 * FUNCTION: AcpiUpdateAllGpes
133 *
134 * PARAMETERS: None
135 *
136 * RETURN: Status
137 *
138 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
139 * associated _Lxx or _Exx methods and are not pointed to by any
140 * device _PRW methods (this indicates that these GPEs are
141 * generally intended for system or device wakeup. Such GPEs
142 * have to be enabled directly when the devices whose _PRW
143 * methods point to them are set up for wakeup signaling.)
144 *
145 * NOTE: Should be called after any GPEs are added to the system. Primarily,
146 * after the system _PRW methods have been run, but also after a GPE Block
147 * Device has been added or if any new GPE methods have been added via a
148 * dynamic table load.
149 *
150 ******************************************************************************/
151
152 ACPI_STATUS
153 AcpiUpdateAllGpes (
154 void)
155 {
156 ACPI_STATUS Status;
157
158
159 ACPI_FUNCTION_TRACE (AcpiUpdateAllGpes);
160
161
162 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
163 if (ACPI_FAILURE (Status))
164 {
165 return_ACPI_STATUS (Status);
166 }
167
168 if (AcpiGbl_AllGpesInitialized)
169 {
170 goto UnlockAndExit;
171 }
172
173 Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
174 if (ACPI_SUCCESS (Status))
175 {
176 AcpiGbl_AllGpesInitialized = TRUE;
177 }
178
179 UnlockAndExit:
180 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
181 return_ACPI_STATUS (Status);
182 }
183
184 ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
185
186
187 /*******************************************************************************
188 *
189 * FUNCTION: AcpiEnableGpe
190 *
191 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
192 * GpeNumber - GPE level within the GPE block
193 *
194 * RETURN: Status
195 *
196 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
197 * hardware-enabled.
198 *
199 ******************************************************************************/
200
201 ACPI_STATUS
202 AcpiEnableGpe (
203 ACPI_HANDLE GpeDevice,
204 UINT32 GpeNumber)
205 {
206 ACPI_STATUS Status = AE_BAD_PARAMETER;
207 ACPI_GPE_EVENT_INFO *GpeEventInfo;
208 ACPI_CPU_FLAGS Flags;
209
210
211 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
212
213
214 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
215
216 /* Ensure that we have a valid GPE number */
217
218 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
219 if (GpeEventInfo)
220 {
221 Status = AcpiEvAddGpeReference (GpeEventInfo);
222 }
223
224 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
225 return_ACPI_STATUS (Status);
226 }
227
228 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
229
230
231 /*******************************************************************************
232 *
233 * FUNCTION: AcpiDisableGpe
234 *
235 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
236 * GpeNumber - GPE level within the GPE block
237 *
238 * RETURN: Status
239 *
240 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
241 * removed, only then is the GPE disabled (for runtime GPEs), or
242 * the GPE mask bit disabled (for wake GPEs)
243 *
244 ******************************************************************************/
245
246 ACPI_STATUS
247 AcpiDisableGpe (
248 ACPI_HANDLE GpeDevice,
249 UINT32 GpeNumber)
250 {
251 ACPI_STATUS Status = AE_BAD_PARAMETER;
252 ACPI_GPE_EVENT_INFO *GpeEventInfo;
253 ACPI_CPU_FLAGS Flags;
254
255
256 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
257
258
259 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
260
261 /* Ensure that we have a valid GPE number */
262
263 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
264 if (GpeEventInfo)
265 {
266 Status = AcpiEvRemoveGpeReference (GpeEventInfo);
267 }
268
269 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
270 return_ACPI_STATUS (Status);
271 }
272
273 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
274
275
276 /*******************************************************************************
277 *
278 * FUNCTION: AcpiSetGpe
279 *
280 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
281 * GpeNumber - GPE level within the GPE block
282 * Action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
283 *
284 * RETURN: Status
285 *
286 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
287 * the reference count mechanism used in the AcpiEnableGpe and
288 * AcpiDisableGpe interfaces -- and should be used with care.
289 *
290 * Note: Typically used to disable a runtime GPE for short period of time,
291 * then re-enable it, without disturbing the existing reference counts. This
292 * is useful, for example, in the Embedded Controller (EC) driver.
293 *
294 ******************************************************************************/
295
296 ACPI_STATUS
297 AcpiSetGpe (
298 ACPI_HANDLE GpeDevice,
299 UINT32 GpeNumber,
300 UINT8 Action)
301 {
302 ACPI_GPE_EVENT_INFO *GpeEventInfo;
303 ACPI_STATUS Status;
304 ACPI_CPU_FLAGS Flags;
305
306
307 ACPI_FUNCTION_TRACE (AcpiSetGpe);
308
309
310 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
311
312 /* Ensure that we have a valid GPE number */
313
314 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
315 if (!GpeEventInfo)
316 {
317 Status = AE_BAD_PARAMETER;
318 goto UnlockAndExit;
319 }
320
321 /* Perform the action */
322
323 switch (Action)
324 {
325 case ACPI_GPE_ENABLE:
326
327 Status = AcpiEvEnableGpe (GpeEventInfo);
328 break;
329
330 case ACPI_GPE_DISABLE:
331
332 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
333 break;
334
335 default:
336
337 Status = AE_BAD_PARAMETER;
338 break;
339 }
340
341 UnlockAndExit:
342 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
343 return_ACPI_STATUS (Status);
344 }
345
346 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
347
348
349 /*******************************************************************************
350 *
351 * FUNCTION: AcpiSetupGpeForWake
352 *
353 * PARAMETERS: WakeDevice - Device associated with the GPE (via _PRW)
354 * GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
355 * GpeNumber - GPE level within the GPE block
356 *
357 * RETURN: Status
358 *
359 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
360 * interface is intended to be used as the host executes the
361 * _PRW methods (Power Resources for Wake) in the system tables.
362 * Each _PRW appears under a Device Object (The WakeDevice), and
363 * contains the info for the wake GPE associated with the
364 * WakeDevice.
365 *
366 ******************************************************************************/
367
368 ACPI_STATUS
369 AcpiSetupGpeForWake (
370 ACPI_HANDLE WakeDevice,
371 ACPI_HANDLE GpeDevice,
372 UINT32 GpeNumber)
373 {
374 ACPI_STATUS Status;
375 ACPI_GPE_EVENT_INFO *GpeEventInfo;
376 ACPI_NAMESPACE_NODE *DeviceNode;
377 ACPI_GPE_NOTIFY_INFO *Notify;
378 ACPI_GPE_NOTIFY_INFO *NewNotify;
379 ACPI_CPU_FLAGS Flags;
380
381
382 ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
383
384
385 /* Parameter Validation */
386
387 if (!WakeDevice)
388 {
389 /*
390 * By forcing WakeDevice to be valid, we automatically enable the
391 * implicit notify feature on all hosts.
392 */
393 return_ACPI_STATUS (AE_BAD_PARAMETER);
394 }
395
396 /* Handle root object case */
397
398 if (WakeDevice == ACPI_ROOT_OBJECT)
399 {
400 DeviceNode = AcpiGbl_RootNode;
401 }
402 else
403 {
404 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
405 }
406
407 /* Validate WakeDevice is of type Device */
408
409 if (DeviceNode->Type != ACPI_TYPE_DEVICE)
410 {
411 return_ACPI_STATUS (AE_BAD_PARAMETER);
412 }
413
414 /*
415 * Allocate a new notify object up front, in case it is needed.
416 * Memory allocation while holding a spinlock is a big no-no
417 * on some hosts.
418 */
419 NewNotify = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_NOTIFY_INFO));
420 if (!NewNotify)
421 {
422 return_ACPI_STATUS (AE_NO_MEMORY);
423 }
424
425 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
426
427 /* Ensure that we have a valid GPE number */
428
429 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
430 if (!GpeEventInfo)
431 {
432 Status = AE_BAD_PARAMETER;
433 goto UnlockAndExit;
434 }
435
436 /*
437 * If there is no method or handler for this GPE, then the
438 * WakeDevice will be notified whenever this GPE fires. This is
439 * known as an "implicit notify". Note: The GPE is assumed to be
440 * level-triggered (for windows compatibility).
441 */
442 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
443 ACPI_GPE_DISPATCH_NONE)
444 {
445 /*
446 * This is the first device for implicit notify on this GPE.
447 * Just set the flags here, and enter the NOTIFY block below.
448 */
449 GpeEventInfo->Flags =
450 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
451 }
452
453 /*
454 * If we already have an implicit notify on this GPE, add
455 * this device to the notify list.
456 */
457 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
458 ACPI_GPE_DISPATCH_NOTIFY)
459 {
460 /* Ensure that the device is not already in the list */
461
462 Notify = GpeEventInfo->Dispatch.NotifyList;
463 while (Notify)
464 {
465 if (Notify->DeviceNode == DeviceNode)
466 {
467 Status = AE_ALREADY_EXISTS;
468 goto UnlockAndExit;
469 }
470 Notify = Notify->Next;
471 }
472
473 /* Add this device to the notify list for this GPE */
474
475 NewNotify->DeviceNode = DeviceNode;
476 NewNotify->Next = GpeEventInfo->Dispatch.NotifyList;
477 GpeEventInfo->Dispatch.NotifyList = NewNotify;
478 NewNotify = NULL;
479 }
480
481 /* Mark the GPE as a possible wake event */
482
483 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
484 Status = AE_OK;
485
486
487 UnlockAndExit:
488 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
489
490 /* Delete the notify object if it was not used above */
491
492 if (NewNotify)
493 {
494 ACPI_FREE (NewNotify);
495 }
496 return_ACPI_STATUS (Status);
497 }
498
499 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
500
501
502 /*******************************************************************************
503 *
504 * FUNCTION: AcpiSetGpeWakeMask
505 *
506 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
507 * GpeNumber - GPE level within the GPE block
508 * Action - Enable or Disable
509 *
510 * RETURN: Status
511 *
512 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
513 * already be marked as a WAKE GPE.
514 *
515 ******************************************************************************/
516
517 ACPI_STATUS
518 AcpiSetGpeWakeMask (
519 ACPI_HANDLE GpeDevice,
520 UINT32 GpeNumber,
521 UINT8 Action)
522 {
523 ACPI_STATUS Status = AE_OK;
524 ACPI_GPE_EVENT_INFO *GpeEventInfo;
525 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
526 ACPI_CPU_FLAGS Flags;
527 UINT32 RegisterBit;
528
529
530 ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
531
532
533 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
534
535 /*
536 * Ensure that we have a valid GPE number and that this GPE is in
537 * fact a wake GPE
538 */
539 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
540 if (!GpeEventInfo)
541 {
542 Status = AE_BAD_PARAMETER;
543 goto UnlockAndExit;
544 }
545
546 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
547 {
548 Status = AE_TYPE;
549 goto UnlockAndExit;
550 }
551
552 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
553 if (!GpeRegisterInfo)
554 {
555 Status = AE_NOT_EXIST;
556 goto UnlockAndExit;
557 }
558
559 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
560
561 /* Perform the action */
562
563 switch (Action)
564 {
565 case ACPI_GPE_ENABLE:
566
567 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
568 break;
569
570 case ACPI_GPE_DISABLE:
571
572 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
573 break;
574
575 default:
576
577 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
578 Status = AE_BAD_PARAMETER;
579 break;
580 }
581
582 UnlockAndExit:
583 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
584 return_ACPI_STATUS (Status);
585 }
586
587 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
588
589
590 /*******************************************************************************
591 *
592 * FUNCTION: AcpiClearGpe
593 *
594 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
595 * GpeNumber - GPE level within the GPE block
596 *
597 * RETURN: Status
598 *
599 * DESCRIPTION: Clear an ACPI event (general purpose)
600 *
601 ******************************************************************************/
602
603 ACPI_STATUS
604 AcpiClearGpe (
605 ACPI_HANDLE GpeDevice,
606 UINT32 GpeNumber)
607 {
608 ACPI_STATUS Status = AE_OK;
609 ACPI_GPE_EVENT_INFO *GpeEventInfo;
610 ACPI_CPU_FLAGS Flags;
611
612
613 ACPI_FUNCTION_TRACE (AcpiClearGpe);
614
615
616 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
617
618 /* Ensure that we have a valid GPE number */
619
620 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
621 if (!GpeEventInfo)
622 {
623 Status = AE_BAD_PARAMETER;
624 goto UnlockAndExit;
625 }
626
627 Status = AcpiHwClearGpe (GpeEventInfo);
628
629 UnlockAndExit:
630 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
631 return_ACPI_STATUS (Status);
632 }
633
634 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
635
636
637 /*******************************************************************************
638 *
639 * FUNCTION: AcpiGetGpeStatus
640 *
641 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
642 * GpeNumber - GPE level within the GPE block
643 * EventStatus - Where the current status of the event
644 * will be returned
645 *
646 * RETURN: Status
647 *
648 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
649 *
650 ******************************************************************************/
651
652 ACPI_STATUS
653 AcpiGetGpeStatus (
654 ACPI_HANDLE GpeDevice,
655 UINT32 GpeNumber,
656 ACPI_EVENT_STATUS *EventStatus)
657 {
658 ACPI_STATUS Status = AE_OK;
659 ACPI_GPE_EVENT_INFO *GpeEventInfo;
660 ACPI_CPU_FLAGS Flags;
661
662
663 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
664
665
666 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
667
668 /* Ensure that we have a valid GPE number */
669
670 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
671 if (!GpeEventInfo)
672 {
673 Status = AE_BAD_PARAMETER;
674 goto UnlockAndExit;
675 }
676
677 /* Obtain status on the requested GPE number */
678
679 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
680
681 UnlockAndExit:
682 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
683 return_ACPI_STATUS (Status);
684 }
685
686 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
687
688
689 /*******************************************************************************
690 *
691 * FUNCTION: AcpiFinishGpe
692 *
693 * PARAMETERS: GpeDevice - Namespace node for the GPE Block
694 * (NULL for FADT defined GPEs)
695 * GpeNumber - GPE level within the GPE block
696 *
697 * RETURN: Status
698 *
699 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
700 * processing. Intended for use by asynchronous host-installed
701 * GPE handlers. The GPE is only reenabled if the EnableForRun bit
702 * is set in the GPE info.
703 *
704 ******************************************************************************/
705
706 ACPI_STATUS
707 AcpiFinishGpe (
708 ACPI_HANDLE GpeDevice,
709 UINT32 GpeNumber)
710 {
711 ACPI_GPE_EVENT_INFO *GpeEventInfo;
712 ACPI_STATUS Status;
713 ACPI_CPU_FLAGS Flags;
714
715
716 ACPI_FUNCTION_TRACE (AcpiFinishGpe);
717
718
719 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
720
721 /* Ensure that we have a valid GPE number */
722
723 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
724 if (!GpeEventInfo)
725 {
726 Status = AE_BAD_PARAMETER;
727 goto UnlockAndExit;
728 }
729
730 Status = AcpiEvFinishGpe (GpeEventInfo);
731
732 UnlockAndExit:
733 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
734 return_ACPI_STATUS (Status);
735 }
736
737 ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
738
739
740 /******************************************************************************
741 *
742 * FUNCTION: AcpiDisableAllGpes
743 *
744 * PARAMETERS: None
745 *
746 * RETURN: Status
747 *
748 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
749 *
750 ******************************************************************************/
751
752 ACPI_STATUS
753 AcpiDisableAllGpes (
754 void)
755 {
756 ACPI_STATUS Status;
757
758
759 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
760
761
762 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
763 if (ACPI_FAILURE (Status))
764 {
765 return_ACPI_STATUS (Status);
766 }
767
768 Status = AcpiHwDisableAllGpes ();
769 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
770
771 return_ACPI_STATUS (Status);
772 }
773
774 ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
775
776
777 /******************************************************************************
778 *
779 * FUNCTION: AcpiEnableAllRuntimeGpes
780 *
781 * PARAMETERS: None
782 *
783 * RETURN: Status
784 *
785 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
786 *
787 ******************************************************************************/
788
789 ACPI_STATUS
790 AcpiEnableAllRuntimeGpes (
791 void)
792 {
793 ACPI_STATUS Status;
794
795
796 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
797
798
799 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
800 if (ACPI_FAILURE (Status))
801 {
802 return_ACPI_STATUS (Status);
803 }
804
805 Status = AcpiHwEnableAllRuntimeGpes ();
806 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
807
808 return_ACPI_STATUS (Status);
809 }
810
811 ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
812
813
814 /*******************************************************************************
815 *
816 * FUNCTION: AcpiInstallGpeBlock
817 *
818 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
819 * GpeBlockAddress - Address and SpaceID
820 * RegisterCount - Number of GPE register pairs in the block
821 * InterruptNumber - H/W interrupt for the block
822 *
823 * RETURN: Status
824 *
825 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
826 * enabled here.
827 *
828 ******************************************************************************/
829
830 ACPI_STATUS
831 AcpiInstallGpeBlock (
832 ACPI_HANDLE GpeDevice,
833 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
834 UINT32 RegisterCount,
835 UINT32 InterruptNumber)
836 {
837 ACPI_STATUS Status;
838 ACPI_OPERAND_OBJECT *ObjDesc;
839 ACPI_NAMESPACE_NODE *Node;
840 ACPI_GPE_BLOCK_INFO *GpeBlock;
841
842
843 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
844
845
846 if ((!GpeDevice) ||
847 (!GpeBlockAddress) ||
848 (!RegisterCount))
849 {
850 return_ACPI_STATUS (AE_BAD_PARAMETER);
851 }
852
853 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
854 if (ACPI_FAILURE (Status))
855 {
856 return_ACPI_STATUS (Status);
857 }
858
859 Node = AcpiNsValidateHandle (GpeDevice);
860 if (!Node)
861 {
862 Status = AE_BAD_PARAMETER;
863 goto UnlockAndExit;
864 }
865
866 /* Validate the parent device */
867
868 if (Node->Type != ACPI_TYPE_DEVICE)
869 {
870 Status = AE_TYPE;
871 goto UnlockAndExit;
872 }
873
874 if (Node->Object)
875 {
876 Status = AE_ALREADY_EXISTS;
877 goto UnlockAndExit;
878 }
879
880 /*
881 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
882 * is always zero
883 */
884 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
885 0, InterruptNumber, &GpeBlock);
886 if (ACPI_FAILURE (Status))
887 {
888 goto UnlockAndExit;
889 }
890
891 /* Install block in the DeviceObject attached to the node */
892
893 ObjDesc = AcpiNsGetAttachedObject (Node);
894 if (!ObjDesc)
895 {
896 /*
897 * No object, create a new one (Device nodes do not always have
898 * an attached object)
899 */
900 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
901 if (!ObjDesc)
902 {
903 Status = AE_NO_MEMORY;
904 goto UnlockAndExit;
905 }
906
907 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
908
909 /* Remove local reference to the object */
910
911 AcpiUtRemoveReference (ObjDesc);
912 if (ACPI_FAILURE (Status))
913 {
914 goto UnlockAndExit;
915 }
916 }
917
918 /* Now install the GPE block in the DeviceObject */
919
920 ObjDesc->Device.GpeBlock = GpeBlock;
921
922
923 UnlockAndExit:
924 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
925 return_ACPI_STATUS (Status);
926 }
927
928 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
929
930
931 /*******************************************************************************
932 *
933 * FUNCTION: AcpiRemoveGpeBlock
934 *
935 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
936 *
937 * RETURN: Status
938 *
939 * DESCRIPTION: Remove a previously installed block of GPE registers
940 *
941 ******************************************************************************/
942
943 ACPI_STATUS
944 AcpiRemoveGpeBlock (
945 ACPI_HANDLE GpeDevice)
946 {
947 ACPI_OPERAND_OBJECT *ObjDesc;
948 ACPI_STATUS Status;
949 ACPI_NAMESPACE_NODE *Node;
950
951
952 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
953
954
955 if (!GpeDevice)
956 {
957 return_ACPI_STATUS (AE_BAD_PARAMETER);
958 }
959
960 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
961 if (ACPI_FAILURE (Status))
962 {
963 return_ACPI_STATUS (Status);
964 }
965
966 Node = AcpiNsValidateHandle (GpeDevice);
967 if (!Node)
968 {
969 Status = AE_BAD_PARAMETER;
970 goto UnlockAndExit;
971 }
972
973 /* Validate the parent device */
974
975 if (Node->Type != ACPI_TYPE_DEVICE)
976 {
977 Status = AE_TYPE;
978 goto UnlockAndExit;
979 }
980
981 /* Get the DeviceObject attached to the node */
982
983 ObjDesc = AcpiNsGetAttachedObject (Node);
984 if (!ObjDesc ||
985 !ObjDesc->Device.GpeBlock)
986 {
987 return_ACPI_STATUS (AE_NULL_OBJECT);
988 }
989
990 /* Delete the GPE block (but not the DeviceObject) */
991
992 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
993 if (ACPI_SUCCESS (Status))
994 {
995 ObjDesc->Device.GpeBlock = NULL;
996 }
997
998 UnlockAndExit:
999 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1000 return_ACPI_STATUS (Status);
1001 }
1002
1003 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
1004
1005
1006 /*******************************************************************************
1007 *
1008 * FUNCTION: AcpiGetGpeDevice
1009 *
1010 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
1011 * GpeDevice - Where the parent GPE Device is returned
1012 *
1013 * RETURN: Status
1014 *
1015 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
1016 * gpe device indicates that the gpe number is contained in one of
1017 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
1018 *
1019 ******************************************************************************/
1020
1021 ACPI_STATUS
1022 AcpiGetGpeDevice (
1023 UINT32 Index,
1024 ACPI_HANDLE *GpeDevice)
1025 {
1026 ACPI_GPE_DEVICE_INFO Info;
1027 ACPI_STATUS Status;
1028
1029
1030 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
1031
1032
1033 if (!GpeDevice)
1034 {
1035 return_ACPI_STATUS (AE_BAD_PARAMETER);
1036 }
1037
1038 if (Index >= AcpiCurrentGpeCount)
1039 {
1040 return_ACPI_STATUS (AE_NOT_EXIST);
1041 }
1042
1043 /* Setup and walk the GPE list */
1044
1045 Info.Index = Index;
1046 Info.Status = AE_NOT_EXIST;
1047 Info.GpeDevice = NULL;
1048 Info.NextBlockBaseIndex = 0;
1049
1050 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
1051 if (ACPI_FAILURE (Status))
1052 {
1053 return_ACPI_STATUS (Status);
1054 }
1055
1056 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
1057 return_ACPI_STATUS (Info.Status);
1058 }
1059
1060 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
1061
1062 #endif /* !ACPI_REDUCED_HARDWARE */