1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acevents.h>
46 #include <acpi/acnamesp.h>
48 #define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evgpeblk")
51 /* Local prototypes */
54 acpi_ev_save_method_info (
55 acpi_handle obj_handle
,
61 acpi_ev_match_prw_and_gpe (
62 acpi_handle obj_handle
,
67 static struct acpi_gpe_xrupt_info
*
68 acpi_ev_get_gpe_xrupt_block (
72 acpi_ev_delete_gpe_xrupt (
73 struct acpi_gpe_xrupt_info
*gpe_xrupt
);
76 acpi_ev_install_gpe_block (
77 struct acpi_gpe_block_info
*gpe_block
,
81 acpi_ev_create_gpe_info_blocks (
82 struct acpi_gpe_block_info
*gpe_block
);
85 /*******************************************************************************
87 * FUNCTION: acpi_ev_valid_gpe_event
89 * PARAMETERS: gpe_event_info - Info for this GPE
91 * RETURN: TRUE if the gpe_event is valid
93 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
94 * Should be called only when the GPE lists are semaphore locked
95 * and not subject to change.
97 ******************************************************************************/
100 acpi_ev_valid_gpe_event (
101 struct acpi_gpe_event_info
*gpe_event_info
)
103 struct acpi_gpe_xrupt_info
*gpe_xrupt_block
;
104 struct acpi_gpe_block_info
*gpe_block
;
107 ACPI_FUNCTION_ENTRY ();
110 /* No need for spin lock since we are not changing any list elements */
112 /* Walk the GPE interrupt levels */
114 gpe_xrupt_block
= acpi_gbl_gpe_xrupt_list_head
;
115 while (gpe_xrupt_block
) {
116 gpe_block
= gpe_xrupt_block
->gpe_block_list_head
;
118 /* Walk the GPE blocks on this interrupt level */
121 if ((&gpe_block
->event_info
[0] <= gpe_event_info
) &&
122 (&gpe_block
->event_info
[((acpi_size
) gpe_block
->register_count
) * 8] > gpe_event_info
)) {
126 gpe_block
= gpe_block
->next
;
129 gpe_xrupt_block
= gpe_xrupt_block
->next
;
136 /*******************************************************************************
138 * FUNCTION: acpi_ev_walk_gpe_list
140 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
141 * Flags - ACPI_NOT_ISR or ACPI_ISR
145 * DESCRIPTION: Walk the GPE lists.
147 ******************************************************************************/
150 acpi_ev_walk_gpe_list (
151 ACPI_GPE_CALLBACK gpe_walk_callback
,
154 struct acpi_gpe_block_info
*gpe_block
;
155 struct acpi_gpe_xrupt_info
*gpe_xrupt_info
;
156 acpi_status status
= AE_OK
;
159 ACPI_FUNCTION_TRACE ("ev_walk_gpe_list");
162 acpi_os_acquire_lock (acpi_gbl_gpe_lock
, flags
);
164 /* Walk the interrupt level descriptor list */
166 gpe_xrupt_info
= acpi_gbl_gpe_xrupt_list_head
;
167 while (gpe_xrupt_info
) {
168 /* Walk all Gpe Blocks attached to this interrupt level */
170 gpe_block
= gpe_xrupt_info
->gpe_block_list_head
;
172 /* One callback per GPE block */
174 status
= gpe_walk_callback (gpe_xrupt_info
, gpe_block
);
175 if (ACPI_FAILURE (status
)) {
176 goto unlock_and_exit
;
179 gpe_block
= gpe_block
->next
;
182 gpe_xrupt_info
= gpe_xrupt_info
->next
;
186 acpi_os_release_lock (acpi_gbl_gpe_lock
, flags
);
187 return_ACPI_STATUS (status
);
191 /*******************************************************************************
193 * FUNCTION: acpi_ev_delete_gpe_handlers
195 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
196 * gpe_block - Gpe Block info
200 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
201 * Used only prior to termination.
203 ******************************************************************************/
206 acpi_ev_delete_gpe_handlers (
207 struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
208 struct acpi_gpe_block_info
*gpe_block
)
210 struct acpi_gpe_event_info
*gpe_event_info
;
215 ACPI_FUNCTION_TRACE ("ev_delete_gpe_handlers");
218 /* Examine each GPE Register within the block */
220 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
221 /* Now look at the individual GPEs in this byte register */
223 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++) {
224 gpe_event_info
= &gpe_block
->event_info
[(i
* ACPI_GPE_REGISTER_WIDTH
) + j
];
226 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
227 ACPI_GPE_DISPATCH_HANDLER
) {
228 ACPI_MEM_FREE (gpe_event_info
->dispatch
.handler
);
229 gpe_event_info
->dispatch
.handler
= NULL
;
230 gpe_event_info
->flags
&= ~ACPI_GPE_DISPATCH_MASK
;
235 return_ACPI_STATUS (AE_OK
);
239 /*******************************************************************************
241 * FUNCTION: acpi_ev_save_method_info
243 * PARAMETERS: Callback from walk_namespace
247 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
248 * control method under the _GPE portion of the namespace.
249 * Extract the name and GPE type from the object, saving this
250 * information for quick lookup during GPE dispatch
252 * The name of each GPE control method is of the form:
255 * L - means that the GPE is level triggered
256 * E - means that the GPE is edge triggered
257 * xx - is the GPE number [in HEX]
259 ******************************************************************************/
262 acpi_ev_save_method_info (
263 acpi_handle obj_handle
,
268 struct acpi_gpe_block_info
*gpe_block
= (void *) obj_desc
;
269 struct acpi_gpe_event_info
*gpe_event_info
;
271 char name
[ACPI_NAME_SIZE
+ 1];
276 ACPI_FUNCTION_TRACE ("ev_save_method_info");
280 * _Lxx and _Exx GPE method support
282 * 1) Extract the name from the object and convert to a string
284 ACPI_MOVE_32_TO_32 (name
,
285 &((struct acpi_namespace_node
*) obj_handle
)->name
.integer
);
286 name
[ACPI_NAME_SIZE
] = 0;
289 * 2) Edge/Level determination is based on the 2nd character
292 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
293 * if a _PRW object is found that points to this GPE.
297 type
= ACPI_GPE_LEVEL_TRIGGERED
;
301 type
= ACPI_GPE_EDGE_TRIGGERED
;
305 /* Unknown method type, just ignore it! */
307 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
308 "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n",
310 return_ACPI_STATUS (AE_OK
);
313 /* Convert the last two characters of the name to the GPE Number */
315 gpe_number
= ACPI_STRTOUL (&name
[2], NULL
, 16);
316 if (gpe_number
== ACPI_UINT32_MAX
) {
317 /* Conversion failed; invalid method, just ignore it */
319 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
320 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n",
322 return_ACPI_STATUS (AE_OK
);
325 /* Ensure that we have a valid GPE number for this GPE block */
327 if ((gpe_number
< gpe_block
->block_base_number
) ||
328 (gpe_number
>= (gpe_block
->block_base_number
+ (gpe_block
->register_count
* 8)))) {
330 * Not valid for this GPE block, just ignore it
331 * However, it may be valid for a different GPE block, since GPE0 and GPE1
332 * methods both appear under \_GPE.
334 return_ACPI_STATUS (AE_OK
);
338 * Now we can add this information to the gpe_event_info block
339 * for use during dispatch of this GPE. Default type is RUNTIME, although
340 * this may change when the _PRW methods are executed later.
342 gpe_event_info
= &gpe_block
->event_info
[gpe_number
- gpe_block
->block_base_number
];
344 gpe_event_info
->flags
= (u8
) (type
| ACPI_GPE_DISPATCH_METHOD
|
345 ACPI_GPE_TYPE_RUNTIME
);
347 gpe_event_info
->dispatch
.method_node
= (struct acpi_namespace_node
*) obj_handle
;
349 /* Update enable mask, but don't enable the HW GPE as of yet */
351 status
= acpi_ev_enable_gpe (gpe_event_info
, FALSE
);
353 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
,
354 "Registered GPE method %s as GPE number 0x%.2X\n",
356 return_ACPI_STATUS (status
);
360 /*******************************************************************************
362 * FUNCTION: acpi_ev_match_prw_and_gpe
364 * PARAMETERS: Callback from walk_namespace
366 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
367 * not aborted on a single _PRW failure.
369 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
370 * Device. Run the _PRW method. If present, extract the GPE
371 * number and mark the GPE as a WAKE GPE.
373 ******************************************************************************/
376 acpi_ev_match_prw_and_gpe (
377 acpi_handle obj_handle
,
382 struct acpi_gpe_walk_info
*gpe_info
= (void *) info
;
383 struct acpi_namespace_node
*gpe_device
;
384 struct acpi_gpe_block_info
*gpe_block
;
385 struct acpi_namespace_node
*target_gpe_device
;
386 struct acpi_gpe_event_info
*gpe_event_info
;
387 union acpi_operand_object
*pkg_desc
;
388 union acpi_operand_object
*obj_desc
;
393 ACPI_FUNCTION_TRACE ("ev_match_prw_and_gpe");
396 /* Check for a _PRW method under this device */
398 status
= acpi_ut_evaluate_object (obj_handle
, METHOD_NAME__PRW
,
399 ACPI_BTYPE_PACKAGE
, &pkg_desc
);
400 if (ACPI_FAILURE (status
)) {
401 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
403 return_ACPI_STATUS (AE_OK
);
406 /* The returned _PRW package must have at least two elements */
408 if (pkg_desc
->package
.count
< 2) {
412 /* Extract pointers from the input context */
414 gpe_device
= gpe_info
->gpe_device
;
415 gpe_block
= gpe_info
->gpe_block
;
418 * The _PRW object must return a package, we are only interested
419 * in the first element
421 obj_desc
= pkg_desc
->package
.elements
[0];
423 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_INTEGER
) {
424 /* Use FADT-defined GPE device (from definition of _PRW) */
426 target_gpe_device
= acpi_gbl_fadt_gpe_device
;
428 /* Integer is the GPE number in the FADT described GPE blocks */
430 gpe_number
= (u32
) obj_desc
->integer
.value
;
432 else if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_PACKAGE
) {
433 /* Package contains a GPE reference and GPE number within a GPE block */
435 if ((obj_desc
->package
.count
< 2) ||
436 (ACPI_GET_OBJECT_TYPE (obj_desc
->package
.elements
[0]) != ACPI_TYPE_LOCAL_REFERENCE
) ||
437 (ACPI_GET_OBJECT_TYPE (obj_desc
->package
.elements
[1]) != ACPI_TYPE_INTEGER
)) {
441 /* Get GPE block reference and decode */
443 target_gpe_device
= obj_desc
->package
.elements
[0]->reference
.node
;
444 gpe_number
= (u32
) obj_desc
->package
.elements
[1]->integer
.value
;
447 /* Unknown type, just ignore it */
453 * Is this GPE within this block?
455 * TRUE iff these conditions are true:
456 * 1) The GPE devices match.
457 * 2) The GPE index(number) is within the range of the Gpe Block
458 * associated with the GPE device.
460 if ((gpe_device
== target_gpe_device
) &&
461 (gpe_number
>= gpe_block
->block_base_number
) &&
462 (gpe_number
< gpe_block
->block_base_number
+ (gpe_block
->register_count
* 8))) {
463 gpe_event_info
= &gpe_block
->event_info
[gpe_number
- gpe_block
->block_base_number
];
465 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
467 gpe_event_info
->flags
&= ~(ACPI_GPE_WAKE_ENABLED
| ACPI_GPE_RUN_ENABLED
);
468 status
= acpi_ev_set_gpe_type (gpe_event_info
, ACPI_GPE_TYPE_WAKE
);
469 if (ACPI_FAILURE (status
)) {
472 status
= acpi_ev_update_gpe_enable_masks (gpe_event_info
, ACPI_GPE_DISABLE
);
476 acpi_ut_remove_reference (pkg_desc
);
477 return_ACPI_STATUS (AE_OK
);
481 /*******************************************************************************
483 * FUNCTION: acpi_ev_get_gpe_xrupt_block
485 * PARAMETERS: interrupt_level - Interrupt for a GPE block
487 * RETURN: A GPE interrupt block
489 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
490 * block per unique interrupt level used for GPEs.
491 * Should be called only when the GPE lists are semaphore locked
492 * and not subject to change.
494 ******************************************************************************/
496 static struct acpi_gpe_xrupt_info
*
497 acpi_ev_get_gpe_xrupt_block (
500 struct acpi_gpe_xrupt_info
*next_gpe_xrupt
;
501 struct acpi_gpe_xrupt_info
*gpe_xrupt
;
505 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block");
508 /* No need for lock since we are not changing any list elements here */
510 next_gpe_xrupt
= acpi_gbl_gpe_xrupt_list_head
;
511 while (next_gpe_xrupt
) {
512 if (next_gpe_xrupt
->interrupt_level
== interrupt_level
) {
513 return_PTR (next_gpe_xrupt
);
516 next_gpe_xrupt
= next_gpe_xrupt
->next
;
519 /* Not found, must allocate a new xrupt descriptor */
521 gpe_xrupt
= ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_xrupt_info
));
526 gpe_xrupt
->interrupt_level
= interrupt_level
;
528 /* Install new interrupt descriptor with spin lock */
530 acpi_os_acquire_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
531 if (acpi_gbl_gpe_xrupt_list_head
) {
532 next_gpe_xrupt
= acpi_gbl_gpe_xrupt_list_head
;
533 while (next_gpe_xrupt
->next
) {
534 next_gpe_xrupt
= next_gpe_xrupt
->next
;
537 next_gpe_xrupt
->next
= gpe_xrupt
;
538 gpe_xrupt
->previous
= next_gpe_xrupt
;
541 acpi_gbl_gpe_xrupt_list_head
= gpe_xrupt
;
543 acpi_os_release_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
545 /* Install new interrupt handler if not SCI_INT */
547 if (interrupt_level
!= acpi_gbl_FADT
->sci_int
) {
548 status
= acpi_os_install_interrupt_handler (interrupt_level
,
549 acpi_ev_gpe_xrupt_handler
, gpe_xrupt
);
550 if (ACPI_FAILURE (status
)) {
551 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
552 "Could not install GPE interrupt handler at level 0x%X\n",
558 return_PTR (gpe_xrupt
);
562 /*******************************************************************************
564 * FUNCTION: acpi_ev_delete_gpe_xrupt
566 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
570 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
571 * interrupt handler if not the SCI interrupt.
573 ******************************************************************************/
576 acpi_ev_delete_gpe_xrupt (
577 struct acpi_gpe_xrupt_info
*gpe_xrupt
)
582 ACPI_FUNCTION_TRACE ("ev_delete_gpe_xrupt");
585 /* We never want to remove the SCI interrupt handler */
587 if (gpe_xrupt
->interrupt_level
== acpi_gbl_FADT
->sci_int
) {
588 gpe_xrupt
->gpe_block_list_head
= NULL
;
589 return_ACPI_STATUS (AE_OK
);
592 /* Disable this interrupt */
594 status
= acpi_os_remove_interrupt_handler (gpe_xrupt
->interrupt_level
,
595 acpi_ev_gpe_xrupt_handler
);
596 if (ACPI_FAILURE (status
)) {
597 return_ACPI_STATUS (status
);
600 /* Unlink the interrupt block with lock */
602 acpi_os_acquire_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
603 if (gpe_xrupt
->previous
) {
604 gpe_xrupt
->previous
->next
= gpe_xrupt
->next
;
607 if (gpe_xrupt
->next
) {
608 gpe_xrupt
->next
->previous
= gpe_xrupt
->previous
;
610 acpi_os_release_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
614 ACPI_MEM_FREE (gpe_xrupt
);
615 return_ACPI_STATUS (AE_OK
);
619 /*******************************************************************************
621 * FUNCTION: acpi_ev_install_gpe_block
623 * PARAMETERS: gpe_block - New GPE block
624 * interrupt_level - Level to be associated with this GPE block
628 * DESCRIPTION: Install new GPE block with mutex support
630 ******************************************************************************/
633 acpi_ev_install_gpe_block (
634 struct acpi_gpe_block_info
*gpe_block
,
637 struct acpi_gpe_block_info
*next_gpe_block
;
638 struct acpi_gpe_xrupt_info
*gpe_xrupt_block
;
642 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
645 status
= acpi_ut_acquire_mutex (ACPI_MTX_EVENTS
);
646 if (ACPI_FAILURE (status
)) {
647 return_ACPI_STATUS (status
);
650 gpe_xrupt_block
= acpi_ev_get_gpe_xrupt_block (interrupt_level
);
651 if (!gpe_xrupt_block
) {
652 status
= AE_NO_MEMORY
;
653 goto unlock_and_exit
;
656 /* Install the new block at the end of the list with lock */
658 acpi_os_acquire_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
659 if (gpe_xrupt_block
->gpe_block_list_head
) {
660 next_gpe_block
= gpe_xrupt_block
->gpe_block_list_head
;
661 while (next_gpe_block
->next
) {
662 next_gpe_block
= next_gpe_block
->next
;
665 next_gpe_block
->next
= gpe_block
;
666 gpe_block
->previous
= next_gpe_block
;
669 gpe_xrupt_block
->gpe_block_list_head
= gpe_block
;
672 gpe_block
->xrupt_block
= gpe_xrupt_block
;
673 acpi_os_release_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
676 status
= acpi_ut_release_mutex (ACPI_MTX_EVENTS
);
677 return_ACPI_STATUS (status
);
681 /*******************************************************************************
683 * FUNCTION: acpi_ev_delete_gpe_block
685 * PARAMETERS: gpe_block - Existing GPE block
689 * DESCRIPTION: Remove a GPE block
691 ******************************************************************************/
694 acpi_ev_delete_gpe_block (
695 struct acpi_gpe_block_info
*gpe_block
)
700 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
703 status
= acpi_ut_acquire_mutex (ACPI_MTX_EVENTS
);
704 if (ACPI_FAILURE (status
)) {
705 return_ACPI_STATUS (status
);
708 /* Disable all GPEs in this block */
710 status
= acpi_hw_disable_gpe_block (gpe_block
->xrupt_block
, gpe_block
);
712 if (!gpe_block
->previous
&& !gpe_block
->next
) {
713 /* This is the last gpe_block on this interrupt */
715 status
= acpi_ev_delete_gpe_xrupt (gpe_block
->xrupt_block
);
716 if (ACPI_FAILURE (status
)) {
717 goto unlock_and_exit
;
721 /* Remove the block on this interrupt with lock */
723 acpi_os_acquire_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
724 if (gpe_block
->previous
) {
725 gpe_block
->previous
->next
= gpe_block
->next
;
728 gpe_block
->xrupt_block
->gpe_block_list_head
= gpe_block
->next
;
731 if (gpe_block
->next
) {
732 gpe_block
->next
->previous
= gpe_block
->previous
;
734 acpi_os_release_lock (acpi_gbl_gpe_lock
, ACPI_NOT_ISR
);
737 /* Free the gpe_block */
739 ACPI_MEM_FREE (gpe_block
->register_info
);
740 ACPI_MEM_FREE (gpe_block
->event_info
);
741 ACPI_MEM_FREE (gpe_block
);
744 status
= acpi_ut_release_mutex (ACPI_MTX_EVENTS
);
745 return_ACPI_STATUS (status
);
749 /*******************************************************************************
751 * FUNCTION: acpi_ev_create_gpe_info_blocks
753 * PARAMETERS: gpe_block - New GPE block
757 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
759 ******************************************************************************/
762 acpi_ev_create_gpe_info_blocks (
763 struct acpi_gpe_block_info
*gpe_block
)
765 struct acpi_gpe_register_info
*gpe_register_info
= NULL
;
766 struct acpi_gpe_event_info
*gpe_event_info
= NULL
;
767 struct acpi_gpe_event_info
*this_event
;
768 struct acpi_gpe_register_info
*this_register
;
774 ACPI_FUNCTION_TRACE ("ev_create_gpe_info_blocks");
777 /* Allocate the GPE register information block */
779 gpe_register_info
= ACPI_MEM_CALLOCATE (
780 (acpi_size
) gpe_block
->register_count
*
781 sizeof (struct acpi_gpe_register_info
));
782 if (!gpe_register_info
) {
783 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
784 "Could not allocate the gpe_register_info table\n"));
785 return_ACPI_STATUS (AE_NO_MEMORY
);
789 * Allocate the GPE event_info block. There are eight distinct GPEs
790 * per register. Initialization to zeros is sufficient.
792 gpe_event_info
= ACPI_MEM_CALLOCATE (
793 ((acpi_size
) gpe_block
->register_count
*
794 ACPI_GPE_REGISTER_WIDTH
) *
795 sizeof (struct acpi_gpe_event_info
));
796 if (!gpe_event_info
) {
797 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
798 "Could not allocate the gpe_event_info table\n"));
799 status
= AE_NO_MEMORY
;
803 /* Save the new Info arrays in the GPE block */
805 gpe_block
->register_info
= gpe_register_info
;
806 gpe_block
->event_info
= gpe_event_info
;
809 * Initialize the GPE Register and Event structures. A goal of these
810 * tables is to hide the fact that there are two separate GPE register sets
811 * in a given gpe hardware block, the status registers occupy the first half,
812 * and the enable registers occupy the second half.
814 this_register
= gpe_register_info
;
815 this_event
= gpe_event_info
;
817 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
818 /* Init the register_info for this GPE register (8 GPEs) */
820 this_register
->base_gpe_number
= (u8
) (gpe_block
->block_base_number
+
821 (i
* ACPI_GPE_REGISTER_WIDTH
));
823 ACPI_STORE_ADDRESS (this_register
->status_address
.address
,
824 (gpe_block
->block_address
.address
827 ACPI_STORE_ADDRESS (this_register
->enable_address
.address
,
828 (gpe_block
->block_address
.address
830 + gpe_block
->register_count
));
832 this_register
->status_address
.address_space_id
= gpe_block
->block_address
.address_space_id
;
833 this_register
->enable_address
.address_space_id
= gpe_block
->block_address
.address_space_id
;
834 this_register
->status_address
.register_bit_width
= ACPI_GPE_REGISTER_WIDTH
;
835 this_register
->enable_address
.register_bit_width
= ACPI_GPE_REGISTER_WIDTH
;
836 this_register
->status_address
.register_bit_offset
= ACPI_GPE_REGISTER_WIDTH
;
837 this_register
->enable_address
.register_bit_offset
= ACPI_GPE_REGISTER_WIDTH
;
839 /* Init the event_info for each GPE within this register */
841 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++) {
842 this_event
->register_bit
= acpi_gbl_decode_to8bit
[j
];
843 this_event
->register_info
= this_register
;
848 * Clear the status/enable registers. Note that status registers
849 * are cleared by writing a '1', while enable registers are cleared
852 status
= acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH
, 0x00,
853 &this_register
->enable_address
);
854 if (ACPI_FAILURE (status
)) {
858 status
= acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH
, 0xFF,
859 &this_register
->status_address
);
860 if (ACPI_FAILURE (status
)) {
867 return_ACPI_STATUS (AE_OK
);
871 if (gpe_register_info
) {
872 ACPI_MEM_FREE (gpe_register_info
);
874 if (gpe_event_info
) {
875 ACPI_MEM_FREE (gpe_event_info
);
878 return_ACPI_STATUS (status
);
882 /*******************************************************************************
884 * FUNCTION: acpi_ev_create_gpe_block
886 * PARAMETERS: gpe_device - Handle to the parent GPE block
887 * gpe_block_address - Address and space_iD
888 * register_count - Number of GPE register pairs in the block
889 * gpe_block_base_number - Starting GPE number for the block
890 * interrupt_level - H/W interrupt for the block
891 * return_gpe_block - Where the new block descriptor is returned
895 * DESCRIPTION: Create and Install a block of GPE registers
897 ******************************************************************************/
900 acpi_ev_create_gpe_block (
901 struct acpi_namespace_node
*gpe_device
,
902 struct acpi_generic_address
*gpe_block_address
,
904 u8 gpe_block_base_number
,
906 struct acpi_gpe_block_info
**return_gpe_block
)
908 struct acpi_gpe_block_info
*gpe_block
;
909 struct acpi_gpe_event_info
*gpe_event_info
;
913 u32 gpe_enabled_count
;
915 struct acpi_gpe_walk_info gpe_info
;
918 ACPI_FUNCTION_TRACE ("ev_create_gpe_block");
921 if (!register_count
) {
922 return_ACPI_STATUS (AE_OK
);
925 /* Allocate a new GPE block */
927 gpe_block
= ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_block_info
));
929 return_ACPI_STATUS (AE_NO_MEMORY
);
932 /* Initialize the new GPE block */
934 gpe_block
->register_count
= register_count
;
935 gpe_block
->block_base_number
= gpe_block_base_number
;
936 gpe_block
->node
= gpe_device
;
938 ACPI_MEMCPY (&gpe_block
->block_address
, gpe_block_address
,
939 sizeof (struct acpi_generic_address
));
941 /* Create the register_info and event_info sub-structures */
943 status
= acpi_ev_create_gpe_info_blocks (gpe_block
);
944 if (ACPI_FAILURE (status
)) {
945 ACPI_MEM_FREE (gpe_block
);
946 return_ACPI_STATUS (status
);
949 /* Install the new block in the global list(s) */
951 status
= acpi_ev_install_gpe_block (gpe_block
, interrupt_level
);
952 if (ACPI_FAILURE (status
)) {
953 ACPI_MEM_FREE (gpe_block
);
954 return_ACPI_STATUS (status
);
957 /* Find all GPE methods (_Lxx, _Exx) for this block */
959 status
= acpi_ns_walk_namespace (ACPI_TYPE_METHOD
, gpe_device
,
960 ACPI_UINT32_MAX
, ACPI_NS_WALK_NO_UNLOCK
, acpi_ev_save_method_info
,
964 * Runtime option: Should Wake GPEs be enabled at runtime? The default
965 * is No, they should only be enabled just as the machine goes to sleep.
967 if (acpi_gbl_leave_wake_gpes_disabled
) {
969 * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods.
970 * (Each GPE that has one or more _PRWs that reference it is by
971 * definition a WAKE GPE and will not be enabled while the machine
974 gpe_info
.gpe_block
= gpe_block
;
975 gpe_info
.gpe_device
= gpe_device
;
977 status
= acpi_ns_walk_namespace (ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
978 ACPI_UINT32_MAX
, ACPI_NS_WALK_UNLOCK
, acpi_ev_match_prw_and_gpe
,
983 * Enable all GPEs in this block that are 1) "runtime" or "run/wake" GPEs,
984 * and 2) have a corresponding _Lxx or _Exx method. All other GPEs must
985 * be enabled via the acpi_enable_gpe() external interface.
988 gpe_enabled_count
= 0;
990 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
991 for (j
= 0; j
< 8; j
++) {
992 /* Get the info block for this particular GPE */
994 gpe_event_info
= &gpe_block
->event_info
[(i
* ACPI_GPE_REGISTER_WIDTH
) + j
];
996 if (((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) == ACPI_GPE_DISPATCH_METHOD
) &&
997 (gpe_event_info
->flags
& ACPI_GPE_TYPE_RUNTIME
)) {
1001 if (gpe_event_info
->flags
& ACPI_GPE_TYPE_WAKE
) {
1007 /* Dump info about this GPE block */
1009 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
,
1010 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
1011 (u32
) gpe_block
->block_base_number
,
1012 (u32
) (gpe_block
->block_base_number
+
1013 ((gpe_block
->register_count
* ACPI_GPE_REGISTER_WIDTH
) -1)),
1014 gpe_device
->name
.ascii
,
1015 gpe_block
->register_count
,
1018 /* Enable all valid GPEs found above */
1020 status
= acpi_hw_enable_runtime_gpe_block (NULL
, gpe_block
);
1022 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
,
1023 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1024 wake_gpe_count
, gpe_enabled_count
));
1026 /* Return the new block */
1028 if (return_gpe_block
) {
1029 (*return_gpe_block
) = gpe_block
;
1032 return_ACPI_STATUS (AE_OK
);
1036 /*******************************************************************************
1038 * FUNCTION: acpi_ev_gpe_initialize
1044 * DESCRIPTION: Initialize the GPE data structures
1046 ******************************************************************************/
1049 acpi_ev_gpe_initialize (
1052 u32 register_count0
= 0;
1053 u32 register_count1
= 0;
1054 u32 gpe_number_max
= 0;
1058 ACPI_FUNCTION_TRACE ("ev_gpe_initialize");
1061 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
1062 if (ACPI_FAILURE (status
)) {
1063 return_ACPI_STATUS (status
);
1067 * Initialize the GPE Block(s) defined in the FADT
1069 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1070 * section "General-Purpose Event Registers", we have:
1072 * "Each register block contains two registers of equal length
1073 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1074 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1075 * The length of the GPE1_STS and GPE1_EN registers is equal to
1076 * half the GPE1_LEN. If a generic register block is not supported
1077 * then its respective block pointer and block length values in the
1078 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1079 * to be the same size."
1083 * Determine the maximum GPE number for this machine.
1085 * Note: both GPE0 and GPE1 are optional, and either can exist without
1088 * If EITHER the register length OR the block address are zero, then that
1089 * particular block is not supported.
1091 if (acpi_gbl_FADT
->gpe0_blk_len
&&
1092 acpi_gbl_FADT
->xgpe0_blk
.address
) {
1093 /* GPE block 0 exists (has both length and address > 0) */
1095 register_count0
= (u16
) (acpi_gbl_FADT
->gpe0_blk_len
/ 2);
1097 gpe_number_max
= (register_count0
* ACPI_GPE_REGISTER_WIDTH
) - 1;
1099 /* Install GPE Block 0 */
1101 status
= acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device
,
1102 &acpi_gbl_FADT
->xgpe0_blk
, register_count0
, 0,
1103 acpi_gbl_FADT
->sci_int
, &acpi_gbl_gpe_fadt_blocks
[0]);
1105 if (ACPI_FAILURE (status
)) {
1106 ACPI_REPORT_ERROR ((
1107 "Could not create GPE Block 0, %s\n",
1108 acpi_format_exception (status
)));
1112 if (acpi_gbl_FADT
->gpe1_blk_len
&&
1113 acpi_gbl_FADT
->xgpe1_blk
.address
) {
1114 /* GPE block 1 exists (has both length and address > 0) */
1116 register_count1
= (u16
) (acpi_gbl_FADT
->gpe1_blk_len
/ 2);
1118 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1120 if ((register_count0
) &&
1121 (gpe_number_max
>= acpi_gbl_FADT
->gpe1_base
)) {
1122 ACPI_REPORT_ERROR ((
1123 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n",
1124 gpe_number_max
, acpi_gbl_FADT
->gpe1_base
,
1125 acpi_gbl_FADT
->gpe1_base
+
1126 ((register_count1
* ACPI_GPE_REGISTER_WIDTH
) - 1)));
1128 /* Ignore GPE1 block by setting the register count to zero */
1130 register_count1
= 0;
1133 /* Install GPE Block 1 */
1135 status
= acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device
,
1136 &acpi_gbl_FADT
->xgpe1_blk
, register_count1
,
1137 acpi_gbl_FADT
->gpe1_base
,
1138 acpi_gbl_FADT
->sci_int
, &acpi_gbl_gpe_fadt_blocks
[1]);
1140 if (ACPI_FAILURE (status
)) {
1141 ACPI_REPORT_ERROR ((
1142 "Could not create GPE Block 1, %s\n",
1143 acpi_format_exception (status
)));
1147 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1148 * space. However, GPE0 always starts at GPE number zero.
1150 gpe_number_max
= acpi_gbl_FADT
->gpe1_base
+
1151 ((register_count1
* ACPI_GPE_REGISTER_WIDTH
) - 1);
1155 /* Exit if there are no GPE registers */
1157 if ((register_count0
+ register_count1
) == 0) {
1158 /* GPEs are not required by ACPI, this is OK */
1160 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
,
1161 "There are no GPE blocks defined in the FADT\n"));
1166 /* Check for Max GPE number out-of-range */
1168 if (gpe_number_max
> ACPI_GPE_MAX
) {
1169 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
1171 status
= AE_BAD_VALUE
;
1176 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
1177 return_ACPI_STATUS (AE_OK
);