Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / events / evxfgpe.c
blobe76b7f1ed3364ac27788e4de3eff3ab784be8089
1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #define __EVXFGPE_C__
46 #define EXPORT_ACPI_INTERFACES
48 #include "acpi.h"
49 #include "accommon.h"
50 #include "acevents.h"
51 #include "acnamesp.h"
53 #define _COMPONENT ACPI_EVENTS
54 ACPI_MODULE_NAME ("evxfgpe")
57 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
58 /*******************************************************************************
60 * FUNCTION: AcpiUpdateAllGpes
62 * PARAMETERS: None
64 * RETURN: Status
66 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
67 * associated _Lxx or _Exx methods and are not pointed to by any
68 * device _PRW methods (this indicates that these GPEs are
69 * generally intended for system or device wakeup. Such GPEs
70 * have to be enabled directly when the devices whose _PRW
71 * methods point to them are set up for wakeup signaling.)
73 * NOTE: Should be called after any GPEs are added to the system. Primarily,
74 * after the system _PRW methods have been run, but also after a GPE Block
75 * Device has been added or if any new GPE methods have been added via a
76 * dynamic table load.
78 ******************************************************************************/
80 ACPI_STATUS
81 AcpiUpdateAllGpes (
82 void)
84 ACPI_STATUS Status;
87 ACPI_FUNCTION_TRACE (AcpiUpdateAllGpes);
90 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
91 if (ACPI_FAILURE (Status))
93 return_ACPI_STATUS (Status);
96 if (AcpiGbl_AllGpesInitialized)
98 goto UnlockAndExit;
101 Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
102 if (ACPI_SUCCESS (Status))
104 AcpiGbl_AllGpesInitialized = TRUE;
107 UnlockAndExit:
108 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
109 return_ACPI_STATUS (Status);
112 ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
115 /*******************************************************************************
117 * FUNCTION: AcpiEnableGpe
119 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
120 * GpeNumber - GPE level within the GPE block
122 * RETURN: Status
124 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
125 * hardware-enabled.
127 ******************************************************************************/
129 ACPI_STATUS
130 AcpiEnableGpe (
131 ACPI_HANDLE GpeDevice,
132 UINT32 GpeNumber)
134 ACPI_STATUS Status = AE_BAD_PARAMETER;
135 ACPI_GPE_EVENT_INFO *GpeEventInfo;
136 ACPI_CPU_FLAGS Flags;
139 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
142 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
144 /* Ensure that we have a valid GPE number */
146 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
147 if (GpeEventInfo)
149 Status = AcpiEvAddGpeReference (GpeEventInfo);
152 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
153 return_ACPI_STATUS (Status);
156 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
159 /*******************************************************************************
161 * FUNCTION: AcpiDisableGpe
163 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
164 * GpeNumber - GPE level within the GPE block
166 * RETURN: Status
168 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
169 * removed, only then is the GPE disabled (for runtime GPEs), or
170 * the GPE mask bit disabled (for wake GPEs)
172 ******************************************************************************/
174 ACPI_STATUS
175 AcpiDisableGpe (
176 ACPI_HANDLE GpeDevice,
177 UINT32 GpeNumber)
179 ACPI_STATUS Status = AE_BAD_PARAMETER;
180 ACPI_GPE_EVENT_INFO *GpeEventInfo;
181 ACPI_CPU_FLAGS Flags;
184 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
187 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
189 /* Ensure that we have a valid GPE number */
191 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
192 if (GpeEventInfo)
194 Status = AcpiEvRemoveGpeReference (GpeEventInfo);
197 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
198 return_ACPI_STATUS (Status);
201 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
204 /*******************************************************************************
206 * FUNCTION: AcpiSetGpe
208 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
209 * GpeNumber - GPE level within the GPE block
210 * Action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
212 * RETURN: Status
214 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
215 * the reference count mechanism used in the AcpiEnableGpe and
216 * AcpiDisableGpe interfaces -- and should be used with care.
218 * Note: Typically used to disable a runtime GPE for short period of time,
219 * then re-enable it, without disturbing the existing reference counts. This
220 * is useful, for example, in the Embedded Controller (EC) driver.
222 ******************************************************************************/
224 ACPI_STATUS
225 AcpiSetGpe (
226 ACPI_HANDLE GpeDevice,
227 UINT32 GpeNumber,
228 UINT8 Action)
230 ACPI_GPE_EVENT_INFO *GpeEventInfo;
231 ACPI_STATUS Status;
232 ACPI_CPU_FLAGS Flags;
235 ACPI_FUNCTION_TRACE (AcpiSetGpe);
238 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
240 /* Ensure that we have a valid GPE number */
242 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
243 if (!GpeEventInfo)
245 Status = AE_BAD_PARAMETER;
246 goto UnlockAndExit;
249 /* Perform the action */
251 switch (Action)
253 case ACPI_GPE_ENABLE:
255 Status = AcpiEvEnableGpe (GpeEventInfo);
256 break;
258 case ACPI_GPE_DISABLE:
260 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
261 break;
263 default:
265 Status = AE_BAD_PARAMETER;
266 break;
269 UnlockAndExit:
270 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
271 return_ACPI_STATUS (Status);
274 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
277 /*******************************************************************************
279 * FUNCTION: AcpiSetupGpeForWake
281 * PARAMETERS: WakeDevice - Device associated with the GPE (via _PRW)
282 * GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
283 * GpeNumber - GPE level within the GPE block
285 * RETURN: Status
287 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
288 * interface is intended to be used as the host executes the
289 * _PRW methods (Power Resources for Wake) in the system tables.
290 * Each _PRW appears under a Device Object (The WakeDevice), and
291 * contains the info for the wake GPE associated with the
292 * WakeDevice.
294 ******************************************************************************/
296 ACPI_STATUS
297 AcpiSetupGpeForWake (
298 ACPI_HANDLE WakeDevice,
299 ACPI_HANDLE GpeDevice,
300 UINT32 GpeNumber)
302 ACPI_STATUS Status;
303 ACPI_GPE_EVENT_INFO *GpeEventInfo;
304 ACPI_NAMESPACE_NODE *DeviceNode;
305 ACPI_GPE_NOTIFY_INFO *Notify;
306 ACPI_GPE_NOTIFY_INFO *NewNotify;
307 ACPI_CPU_FLAGS Flags;
310 ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
313 /* Parameter Validation */
315 if (!WakeDevice)
318 * By forcing WakeDevice to be valid, we automatically enable the
319 * implicit notify feature on all hosts.
321 return_ACPI_STATUS (AE_BAD_PARAMETER);
324 /* Handle root object case */
326 if (WakeDevice == ACPI_ROOT_OBJECT)
328 DeviceNode = AcpiGbl_RootNode;
330 else
332 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
335 /* Validate WakeDevice is of type Device */
337 if (DeviceNode->Type != ACPI_TYPE_DEVICE)
339 return_ACPI_STATUS (AE_BAD_PARAMETER);
343 * Allocate a new notify object up front, in case it is needed.
344 * Memory allocation while holding a spinlock is a big no-no
345 * on some hosts.
347 NewNotify = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_NOTIFY_INFO));
348 if (!NewNotify)
350 return_ACPI_STATUS (AE_NO_MEMORY);
353 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
355 /* Ensure that we have a valid GPE number */
357 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
358 if (!GpeEventInfo)
360 Status = AE_BAD_PARAMETER;
361 goto UnlockAndExit;
365 * If there is no method or handler for this GPE, then the
366 * WakeDevice will be notified whenever this GPE fires. This is
367 * known as an "implicit notify". Note: The GPE is assumed to be
368 * level-triggered (for windows compatibility).
370 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
371 ACPI_GPE_DISPATCH_NONE)
374 * This is the first device for implicit notify on this GPE.
375 * Just set the flags here, and enter the NOTIFY block below.
377 GpeEventInfo->Flags =
378 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
382 * If we already have an implicit notify on this GPE, add
383 * this device to the notify list.
385 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
386 ACPI_GPE_DISPATCH_NOTIFY)
388 /* Ensure that the device is not already in the list */
390 Notify = GpeEventInfo->Dispatch.NotifyList;
391 while (Notify)
393 if (Notify->DeviceNode == DeviceNode)
395 Status = AE_ALREADY_EXISTS;
396 goto UnlockAndExit;
398 Notify = Notify->Next;
401 /* Add this device to the notify list for this GPE */
403 NewNotify->DeviceNode = DeviceNode;
404 NewNotify->Next = GpeEventInfo->Dispatch.NotifyList;
405 GpeEventInfo->Dispatch.NotifyList = NewNotify;
406 NewNotify = NULL;
409 /* Mark the GPE as a possible wake event */
411 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
412 Status = AE_OK;
415 UnlockAndExit:
416 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
418 /* Delete the notify object if it was not used above */
420 if (NewNotify)
422 ACPI_FREE (NewNotify);
424 return_ACPI_STATUS (Status);
427 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
430 /*******************************************************************************
432 * FUNCTION: AcpiSetGpeWakeMask
434 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
435 * GpeNumber - GPE level within the GPE block
436 * Action - Enable or Disable
438 * RETURN: Status
440 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
441 * already be marked as a WAKE GPE.
443 ******************************************************************************/
445 ACPI_STATUS
446 AcpiSetGpeWakeMask (
447 ACPI_HANDLE GpeDevice,
448 UINT32 GpeNumber,
449 UINT8 Action)
451 ACPI_STATUS Status = AE_OK;
452 ACPI_GPE_EVENT_INFO *GpeEventInfo;
453 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
454 ACPI_CPU_FLAGS Flags;
455 UINT32 RegisterBit;
458 ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
461 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
464 * Ensure that we have a valid GPE number and that this GPE is in
465 * fact a wake GPE
467 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
468 if (!GpeEventInfo)
470 Status = AE_BAD_PARAMETER;
471 goto UnlockAndExit;
474 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
476 Status = AE_TYPE;
477 goto UnlockAndExit;
480 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
481 if (!GpeRegisterInfo)
483 Status = AE_NOT_EXIST;
484 goto UnlockAndExit;
487 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
489 /* Perform the action */
491 switch (Action)
493 case ACPI_GPE_ENABLE:
495 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
496 break;
498 case ACPI_GPE_DISABLE:
500 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
501 break;
503 default:
505 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
506 Status = AE_BAD_PARAMETER;
507 break;
510 UnlockAndExit:
511 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
512 return_ACPI_STATUS (Status);
515 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
518 /*******************************************************************************
520 * FUNCTION: AcpiClearGpe
522 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
523 * GpeNumber - GPE level within the GPE block
525 * RETURN: Status
527 * DESCRIPTION: Clear an ACPI event (general purpose)
529 ******************************************************************************/
531 ACPI_STATUS
532 AcpiClearGpe (
533 ACPI_HANDLE GpeDevice,
534 UINT32 GpeNumber)
536 ACPI_STATUS Status = AE_OK;
537 ACPI_GPE_EVENT_INFO *GpeEventInfo;
538 ACPI_CPU_FLAGS Flags;
541 ACPI_FUNCTION_TRACE (AcpiClearGpe);
544 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
546 /* Ensure that we have a valid GPE number */
548 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
549 if (!GpeEventInfo)
551 Status = AE_BAD_PARAMETER;
552 goto UnlockAndExit;
555 Status = AcpiHwClearGpe (GpeEventInfo);
557 UnlockAndExit:
558 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
559 return_ACPI_STATUS (Status);
562 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
565 /*******************************************************************************
567 * FUNCTION: AcpiGetGpeStatus
569 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
570 * GpeNumber - GPE level within the GPE block
571 * EventStatus - Where the current status of the event
572 * will be returned
574 * RETURN: Status
576 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
578 ******************************************************************************/
580 ACPI_STATUS
581 AcpiGetGpeStatus (
582 ACPI_HANDLE GpeDevice,
583 UINT32 GpeNumber,
584 ACPI_EVENT_STATUS *EventStatus)
586 ACPI_STATUS Status = AE_OK;
587 ACPI_GPE_EVENT_INFO *GpeEventInfo;
588 ACPI_CPU_FLAGS Flags;
591 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
594 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
596 /* Ensure that we have a valid GPE number */
598 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
599 if (!GpeEventInfo)
601 Status = AE_BAD_PARAMETER;
602 goto UnlockAndExit;
605 /* Obtain status on the requested GPE number */
607 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
609 UnlockAndExit:
610 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
611 return_ACPI_STATUS (Status);
614 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
617 /*******************************************************************************
619 * FUNCTION: AcpiFinishGpe
621 * PARAMETERS: GpeDevice - Namespace node for the GPE Block
622 * (NULL for FADT defined GPEs)
623 * GpeNumber - GPE level within the GPE block
625 * RETURN: Status
627 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
628 * processing. Intended for use by asynchronous host-installed
629 * GPE handlers. The GPE is only reenabled if the EnableForRun bit
630 * is set in the GPE info.
632 ******************************************************************************/
634 ACPI_STATUS
635 AcpiFinishGpe (
636 ACPI_HANDLE GpeDevice,
637 UINT32 GpeNumber)
639 ACPI_GPE_EVENT_INFO *GpeEventInfo;
640 ACPI_STATUS Status;
641 ACPI_CPU_FLAGS Flags;
644 ACPI_FUNCTION_TRACE (AcpiFinishGpe);
647 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
649 /* Ensure that we have a valid GPE number */
651 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
652 if (!GpeEventInfo)
654 Status = AE_BAD_PARAMETER;
655 goto UnlockAndExit;
658 Status = AcpiEvFinishGpe (GpeEventInfo);
660 UnlockAndExit:
661 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
662 return_ACPI_STATUS (Status);
665 ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
668 /******************************************************************************
670 * FUNCTION: AcpiDisableAllGpes
672 * PARAMETERS: None
674 * RETURN: Status
676 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
678 ******************************************************************************/
680 ACPI_STATUS
681 AcpiDisableAllGpes (
682 void)
684 ACPI_STATUS Status;
687 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
690 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
691 if (ACPI_FAILURE (Status))
693 return_ACPI_STATUS (Status);
696 Status = AcpiHwDisableAllGpes ();
697 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
699 return_ACPI_STATUS (Status);
702 ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
705 /******************************************************************************
707 * FUNCTION: AcpiEnableAllRuntimeGpes
709 * PARAMETERS: None
711 * RETURN: Status
713 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
715 ******************************************************************************/
717 ACPI_STATUS
718 AcpiEnableAllRuntimeGpes (
719 void)
721 ACPI_STATUS Status;
724 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
727 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
728 if (ACPI_FAILURE (Status))
730 return_ACPI_STATUS (Status);
733 Status = AcpiHwEnableAllRuntimeGpes ();
734 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
736 return_ACPI_STATUS (Status);
739 ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
742 /*******************************************************************************
744 * FUNCTION: AcpiInstallGpeBlock
746 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
747 * GpeBlockAddress - Address and SpaceID
748 * RegisterCount - Number of GPE register pairs in the block
749 * InterruptNumber - H/W interrupt for the block
751 * RETURN: Status
753 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
754 * enabled here.
756 ******************************************************************************/
758 ACPI_STATUS
759 AcpiInstallGpeBlock (
760 ACPI_HANDLE GpeDevice,
761 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
762 UINT32 RegisterCount,
763 UINT32 InterruptNumber)
765 ACPI_STATUS Status;
766 ACPI_OPERAND_OBJECT *ObjDesc;
767 ACPI_NAMESPACE_NODE *Node;
768 ACPI_GPE_BLOCK_INFO *GpeBlock;
771 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
774 if ((!GpeDevice) ||
775 (!GpeBlockAddress) ||
776 (!RegisterCount))
778 return_ACPI_STATUS (AE_BAD_PARAMETER);
781 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
782 if (ACPI_FAILURE (Status))
784 return_ACPI_STATUS (Status);
787 Node = AcpiNsValidateHandle (GpeDevice);
788 if (!Node)
790 Status = AE_BAD_PARAMETER;
791 goto UnlockAndExit;
795 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
796 * is always zero
798 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
799 0, InterruptNumber, &GpeBlock);
800 if (ACPI_FAILURE (Status))
802 goto UnlockAndExit;
805 /* Install block in the DeviceObject attached to the node */
807 ObjDesc = AcpiNsGetAttachedObject (Node);
808 if (!ObjDesc)
811 * No object, create a new one (Device nodes do not always have
812 * an attached object)
814 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
815 if (!ObjDesc)
817 Status = AE_NO_MEMORY;
818 goto UnlockAndExit;
821 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
823 /* Remove local reference to the object */
825 AcpiUtRemoveReference (ObjDesc);
826 if (ACPI_FAILURE (Status))
828 goto UnlockAndExit;
832 /* Now install the GPE block in the DeviceObject */
834 ObjDesc->Device.GpeBlock = GpeBlock;
837 UnlockAndExit:
838 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
839 return_ACPI_STATUS (Status);
842 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
845 /*******************************************************************************
847 * FUNCTION: AcpiRemoveGpeBlock
849 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
851 * RETURN: Status
853 * DESCRIPTION: Remove a previously installed block of GPE registers
855 ******************************************************************************/
857 ACPI_STATUS
858 AcpiRemoveGpeBlock (
859 ACPI_HANDLE GpeDevice)
861 ACPI_OPERAND_OBJECT *ObjDesc;
862 ACPI_STATUS Status;
863 ACPI_NAMESPACE_NODE *Node;
866 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
869 if (!GpeDevice)
871 return_ACPI_STATUS (AE_BAD_PARAMETER);
874 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
875 if (ACPI_FAILURE (Status))
877 return_ACPI_STATUS (Status);
880 Node = AcpiNsValidateHandle (GpeDevice);
881 if (!Node)
883 Status = AE_BAD_PARAMETER;
884 goto UnlockAndExit;
887 /* Get the DeviceObject attached to the node */
889 ObjDesc = AcpiNsGetAttachedObject (Node);
890 if (!ObjDesc ||
891 !ObjDesc->Device.GpeBlock)
893 return_ACPI_STATUS (AE_NULL_OBJECT);
896 /* Delete the GPE block (but not the DeviceObject) */
898 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
899 if (ACPI_SUCCESS (Status))
901 ObjDesc->Device.GpeBlock = NULL;
904 UnlockAndExit:
905 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
906 return_ACPI_STATUS (Status);
909 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
912 /*******************************************************************************
914 * FUNCTION: AcpiGetGpeDevice
916 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
917 * GpeDevice - Where the parent GPE Device is returned
919 * RETURN: Status
921 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
922 * gpe device indicates that the gpe number is contained in one of
923 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
925 ******************************************************************************/
927 ACPI_STATUS
928 AcpiGetGpeDevice (
929 UINT32 Index,
930 ACPI_HANDLE *GpeDevice)
932 ACPI_GPE_DEVICE_INFO Info;
933 ACPI_STATUS Status;
936 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
939 if (!GpeDevice)
941 return_ACPI_STATUS (AE_BAD_PARAMETER);
944 if (Index >= AcpiCurrentGpeCount)
946 return_ACPI_STATUS (AE_NOT_EXIST);
949 /* Setup and walk the GPE list */
951 Info.Index = Index;
952 Info.Status = AE_NOT_EXIST;
953 Info.GpeDevice = NULL;
954 Info.NextBlockBaseIndex = 0;
956 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
957 if (ACPI_FAILURE (Status))
959 return_ACPI_STATUS (Status);
962 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
963 return_ACPI_STATUS (Info.Status);
966 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
968 #endif /* !ACPI_REDUCED_HARDWARE */