1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, Intel Corp.
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 */
53 acpi_ev_save_method_info(acpi_handle obj_handle
,
54 u32 level
, void *obj_desc
, void **return_value
);
57 acpi_ev_match_prw_and_gpe(acpi_handle obj_handle
,
58 u32 level
, void *info
, void **return_value
);
60 static struct acpi_gpe_xrupt_info
*acpi_ev_get_gpe_xrupt_block(u32
64 acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info
*gpe_xrupt
);
67 acpi_ev_install_gpe_block(struct acpi_gpe_block_info
*gpe_block
,
68 u32 interrupt_number
);
71 acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info
*gpe_block
);
73 /*******************************************************************************
75 * FUNCTION: acpi_ev_valid_gpe_event
77 * PARAMETERS: gpe_event_info - Info for this GPE
79 * RETURN: TRUE if the gpe_event is valid
81 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
82 * Should be called only when the GPE lists are semaphore locked
83 * and not subject to change.
85 ******************************************************************************/
87 u8
acpi_ev_valid_gpe_event(struct acpi_gpe_event_info
*gpe_event_info
)
89 struct acpi_gpe_xrupt_info
*gpe_xrupt_block
;
90 struct acpi_gpe_block_info
*gpe_block
;
92 ACPI_FUNCTION_ENTRY();
94 /* No need for spin lock since we are not changing any list elements */
96 /* Walk the GPE interrupt levels */
98 gpe_xrupt_block
= acpi_gbl_gpe_xrupt_list_head
;
99 while (gpe_xrupt_block
) {
100 gpe_block
= gpe_xrupt_block
->gpe_block_list_head
;
102 /* Walk the GPE blocks on this interrupt level */
105 if ((&gpe_block
->event_info
[0] <= gpe_event_info
) &&
107 event_info
[((acpi_size
) gpe_block
->
108 register_count
) * 8] >
113 gpe_block
= gpe_block
->next
;
116 gpe_xrupt_block
= gpe_xrupt_block
->next
;
122 /*******************************************************************************
124 * FUNCTION: acpi_ev_walk_gpe_list
126 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
130 * DESCRIPTION: Walk the GPE lists.
132 ******************************************************************************/
134 acpi_status
acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback
)
136 struct acpi_gpe_block_info
*gpe_block
;
137 struct acpi_gpe_xrupt_info
*gpe_xrupt_info
;
138 acpi_status status
= AE_OK
;
139 acpi_cpu_flags flags
;
141 ACPI_FUNCTION_TRACE(ev_walk_gpe_list
);
143 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
145 /* Walk the interrupt level descriptor list */
147 gpe_xrupt_info
= acpi_gbl_gpe_xrupt_list_head
;
148 while (gpe_xrupt_info
) {
150 /* Walk all Gpe Blocks attached to this interrupt level */
152 gpe_block
= gpe_xrupt_info
->gpe_block_list_head
;
155 /* One callback per GPE block */
157 status
= gpe_walk_callback(gpe_xrupt_info
, gpe_block
);
158 if (ACPI_FAILURE(status
)) {
159 goto unlock_and_exit
;
162 gpe_block
= gpe_block
->next
;
165 gpe_xrupt_info
= gpe_xrupt_info
->next
;
169 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
170 return_ACPI_STATUS(status
);
173 /*******************************************************************************
175 * FUNCTION: acpi_ev_delete_gpe_handlers
177 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
178 * gpe_block - Gpe Block info
182 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
183 * Used only prior to termination.
185 ******************************************************************************/
188 acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
189 struct acpi_gpe_block_info
*gpe_block
)
191 struct acpi_gpe_event_info
*gpe_event_info
;
195 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers
);
197 /* Examine each GPE Register within the block */
199 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
201 /* Now look at the individual GPEs in this byte register */
203 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++) {
206 event_info
[((acpi_size
) i
*
207 ACPI_GPE_REGISTER_WIDTH
) + j
];
209 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
210 ACPI_GPE_DISPATCH_HANDLER
) {
211 ACPI_FREE(gpe_event_info
->dispatch
.handler
);
212 gpe_event_info
->dispatch
.handler
= NULL
;
213 gpe_event_info
->flags
&=
214 ~ACPI_GPE_DISPATCH_MASK
;
219 return_ACPI_STATUS(AE_OK
);
222 /*******************************************************************************
224 * FUNCTION: acpi_ev_save_method_info
226 * PARAMETERS: Callback from walk_namespace
230 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
231 * control method under the _GPE portion of the namespace.
232 * Extract the name and GPE type from the object, saving this
233 * information for quick lookup during GPE dispatch
235 * The name of each GPE control method is of the form:
238 * L - means that the GPE is level triggered
239 * E - means that the GPE is edge triggered
240 * xx - is the GPE number [in HEX]
242 ******************************************************************************/
245 acpi_ev_save_method_info(acpi_handle obj_handle
,
246 u32 level
, void *obj_desc
, void **return_value
)
248 struct acpi_gpe_block_info
*gpe_block
= (void *)obj_desc
;
249 struct acpi_gpe_event_info
*gpe_event_info
;
251 char name
[ACPI_NAME_SIZE
+ 1];
255 ACPI_FUNCTION_TRACE(ev_save_method_info
);
258 * _Lxx and _Exx GPE method support
260 * 1) Extract the name from the object and convert to a string
262 ACPI_MOVE_32_TO_32(name
,
263 &((struct acpi_namespace_node
*)obj_handle
)->name
.
265 name
[ACPI_NAME_SIZE
] = 0;
268 * 2) Edge/Level determination is based on the 2nd character
271 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
272 * if a _PRW object is found that points to this GPE.
276 type
= ACPI_GPE_LEVEL_TRIGGERED
;
280 type
= ACPI_GPE_EDGE_TRIGGERED
;
284 /* Unknown method type, just ignore it! */
286 ACPI_DEBUG_PRINT((ACPI_DB_LOAD
,
287 "Ignoring unknown GPE method type: %s (name not of form _Lxx or _Exx)",
289 return_ACPI_STATUS(AE_OK
);
292 /* Convert the last two characters of the name to the GPE Number */
294 gpe_number
= ACPI_STRTOUL(&name
[2], NULL
, 16);
295 if (gpe_number
== ACPI_UINT32_MAX
) {
297 /* Conversion failed; invalid method, just ignore it */
299 ACPI_DEBUG_PRINT((ACPI_DB_LOAD
,
300 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)",
302 return_ACPI_STATUS(AE_OK
);
305 /* Ensure that we have a valid GPE number for this GPE block */
307 if ((gpe_number
< gpe_block
->block_base_number
) ||
309 (gpe_block
->block_base_number
+
310 (gpe_block
->register_count
* 8)))) {
312 * Not valid for this GPE block, just ignore it
313 * However, it may be valid for a different GPE block, since GPE0 and GPE1
314 * methods both appear under \_GPE.
316 return_ACPI_STATUS(AE_OK
);
320 * Now we can add this information to the gpe_event_info block
321 * for use during dispatch of this GPE. Default type is RUNTIME, although
322 * this may change when the _PRW methods are executed later.
325 &gpe_block
->event_info
[gpe_number
- gpe_block
->block_base_number
];
327 gpe_event_info
->flags
= (u8
)
328 (type
| ACPI_GPE_DISPATCH_METHOD
| ACPI_GPE_TYPE_RUNTIME
);
330 gpe_event_info
->dispatch
.method_node
=
331 (struct acpi_namespace_node
*)obj_handle
;
333 /* Update enable mask, but don't enable the HW GPE as of yet */
335 status
= acpi_ev_enable_gpe(gpe_event_info
, FALSE
);
337 ACPI_DEBUG_PRINT((ACPI_DB_LOAD
,
338 "Registered GPE method %s as GPE number 0x%.2X\n",
340 return_ACPI_STATUS(status
);
343 /*******************************************************************************
345 * FUNCTION: acpi_ev_match_prw_and_gpe
347 * PARAMETERS: Callback from walk_namespace
349 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
350 * not aborted on a single _PRW failure.
352 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
353 * Device. Run the _PRW method. If present, extract the GPE
354 * number and mark the GPE as a WAKE GPE.
356 ******************************************************************************/
359 acpi_ev_match_prw_and_gpe(acpi_handle obj_handle
,
360 u32 level
, void *info
, void **return_value
)
362 struct acpi_gpe_walk_info
*gpe_info
= (void *)info
;
363 struct acpi_namespace_node
*gpe_device
;
364 struct acpi_gpe_block_info
*gpe_block
;
365 struct acpi_namespace_node
*target_gpe_device
;
366 struct acpi_gpe_event_info
*gpe_event_info
;
367 union acpi_operand_object
*pkg_desc
;
368 union acpi_operand_object
*obj_desc
;
372 ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe
);
374 /* Check for a _PRW method under this device */
376 status
= acpi_ut_evaluate_object(obj_handle
, METHOD_NAME__PRW
,
377 ACPI_BTYPE_PACKAGE
, &pkg_desc
);
378 if (ACPI_FAILURE(status
)) {
380 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
382 return_ACPI_STATUS(AE_OK
);
385 /* The returned _PRW package must have at least two elements */
387 if (pkg_desc
->package
.count
< 2) {
391 /* Extract pointers from the input context */
393 gpe_device
= gpe_info
->gpe_device
;
394 gpe_block
= gpe_info
->gpe_block
;
397 * The _PRW object must return a package, we are only interested
398 * in the first element
400 obj_desc
= pkg_desc
->package
.elements
[0];
402 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
404 /* Use FADT-defined GPE device (from definition of _PRW) */
406 target_gpe_device
= acpi_gbl_fadt_gpe_device
;
408 /* Integer is the GPE number in the FADT described GPE blocks */
410 gpe_number
= (u32
) obj_desc
->integer
.value
;
411 } else if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
413 /* Package contains a GPE reference and GPE number within a GPE block */
415 if ((obj_desc
->package
.count
< 2) ||
416 (ACPI_GET_OBJECT_TYPE(obj_desc
->package
.elements
[0]) !=
417 ACPI_TYPE_LOCAL_REFERENCE
)
418 || (ACPI_GET_OBJECT_TYPE(obj_desc
->package
.elements
[1]) !=
419 ACPI_TYPE_INTEGER
)) {
423 /* Get GPE block reference and decode */
426 obj_desc
->package
.elements
[0]->reference
.node
;
427 gpe_number
= (u32
) obj_desc
->package
.elements
[1]->integer
.value
;
429 /* Unknown type, just ignore it */
435 * Is this GPE within this block?
437 * TRUE iff these conditions are true:
438 * 1) The GPE devices match.
439 * 2) The GPE index(number) is within the range of the Gpe Block
440 * associated with the GPE device.
442 if ((gpe_device
== target_gpe_device
) &&
443 (gpe_number
>= gpe_block
->block_base_number
) &&
445 gpe_block
->block_base_number
+ (gpe_block
->register_count
* 8))) {
447 &gpe_block
->event_info
[gpe_number
-
448 gpe_block
->block_base_number
];
450 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
452 gpe_event_info
->flags
&=
453 ~(ACPI_GPE_WAKE_ENABLED
| ACPI_GPE_RUN_ENABLED
);
456 acpi_ev_set_gpe_type(gpe_event_info
, ACPI_GPE_TYPE_WAKE
);
457 if (ACPI_FAILURE(status
)) {
461 acpi_ev_update_gpe_enable_masks(gpe_event_info
,
466 acpi_ut_remove_reference(pkg_desc
);
467 return_ACPI_STATUS(AE_OK
);
470 /*******************************************************************************
472 * FUNCTION: acpi_ev_get_gpe_xrupt_block
474 * PARAMETERS: interrupt_number - Interrupt for a GPE block
476 * RETURN: A GPE interrupt block
478 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
479 * block per unique interrupt level used for GPEs.
480 * Should be called only when the GPE lists are semaphore locked
481 * and not subject to change.
483 ******************************************************************************/
485 static struct acpi_gpe_xrupt_info
*acpi_ev_get_gpe_xrupt_block(u32
488 struct acpi_gpe_xrupt_info
*next_gpe_xrupt
;
489 struct acpi_gpe_xrupt_info
*gpe_xrupt
;
491 acpi_cpu_flags flags
;
493 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block
);
495 /* No need for lock since we are not changing any list elements here */
497 next_gpe_xrupt
= acpi_gbl_gpe_xrupt_list_head
;
498 while (next_gpe_xrupt
) {
499 if (next_gpe_xrupt
->interrupt_number
== interrupt_number
) {
500 return_PTR(next_gpe_xrupt
);
503 next_gpe_xrupt
= next_gpe_xrupt
->next
;
506 /* Not found, must allocate a new xrupt descriptor */
508 gpe_xrupt
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info
));
513 gpe_xrupt
->interrupt_number
= interrupt_number
;
515 /* Install new interrupt descriptor with spin lock */
517 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
518 if (acpi_gbl_gpe_xrupt_list_head
) {
519 next_gpe_xrupt
= acpi_gbl_gpe_xrupt_list_head
;
520 while (next_gpe_xrupt
->next
) {
521 next_gpe_xrupt
= next_gpe_xrupt
->next
;
524 next_gpe_xrupt
->next
= gpe_xrupt
;
525 gpe_xrupt
->previous
= next_gpe_xrupt
;
527 acpi_gbl_gpe_xrupt_list_head
= gpe_xrupt
;
529 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
531 /* Install new interrupt handler if not SCI_INT */
533 if (interrupt_number
!= acpi_gbl_FADT
.sci_interrupt
) {
534 status
= acpi_os_install_interrupt_handler(interrupt_number
,
535 acpi_ev_gpe_xrupt_handler
,
537 if (ACPI_FAILURE(status
)) {
539 "Could not install GPE interrupt handler at level 0x%X",
545 return_PTR(gpe_xrupt
);
548 /*******************************************************************************
550 * FUNCTION: acpi_ev_delete_gpe_xrupt
552 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
556 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
557 * interrupt handler if not the SCI interrupt.
559 ******************************************************************************/
562 acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info
*gpe_xrupt
)
565 acpi_cpu_flags flags
;
567 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt
);
569 /* We never want to remove the SCI interrupt handler */
571 if (gpe_xrupt
->interrupt_number
== acpi_gbl_FADT
.sci_interrupt
) {
572 gpe_xrupt
->gpe_block_list_head
= NULL
;
573 return_ACPI_STATUS(AE_OK
);
576 /* Disable this interrupt */
579 acpi_os_remove_interrupt_handler(gpe_xrupt
->interrupt_number
,
580 acpi_ev_gpe_xrupt_handler
);
581 if (ACPI_FAILURE(status
)) {
582 return_ACPI_STATUS(status
);
585 /* Unlink the interrupt block with lock */
587 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
588 if (gpe_xrupt
->previous
) {
589 gpe_xrupt
->previous
->next
= gpe_xrupt
->next
;
591 /* No previous, update list head */
593 acpi_gbl_gpe_xrupt_list_head
= gpe_xrupt
->next
;
596 if (gpe_xrupt
->next
) {
597 gpe_xrupt
->next
->previous
= gpe_xrupt
->previous
;
599 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
603 ACPI_FREE(gpe_xrupt
);
604 return_ACPI_STATUS(AE_OK
);
607 /*******************************************************************************
609 * FUNCTION: acpi_ev_install_gpe_block
611 * PARAMETERS: gpe_block - New GPE block
612 * interrupt_number - Xrupt to be associated with this GPE block
616 * DESCRIPTION: Install new GPE block with mutex support
618 ******************************************************************************/
621 acpi_ev_install_gpe_block(struct acpi_gpe_block_info
*gpe_block
,
622 u32 interrupt_number
)
624 struct acpi_gpe_block_info
*next_gpe_block
;
625 struct acpi_gpe_xrupt_info
*gpe_xrupt_block
;
627 acpi_cpu_flags flags
;
629 ACPI_FUNCTION_TRACE(ev_install_gpe_block
);
631 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
632 if (ACPI_FAILURE(status
)) {
633 return_ACPI_STATUS(status
);
636 gpe_xrupt_block
= acpi_ev_get_gpe_xrupt_block(interrupt_number
);
637 if (!gpe_xrupt_block
) {
638 status
= AE_NO_MEMORY
;
639 goto unlock_and_exit
;
642 /* Install the new block at the end of the list with lock */
644 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
645 if (gpe_xrupt_block
->gpe_block_list_head
) {
646 next_gpe_block
= gpe_xrupt_block
->gpe_block_list_head
;
647 while (next_gpe_block
->next
) {
648 next_gpe_block
= next_gpe_block
->next
;
651 next_gpe_block
->next
= gpe_block
;
652 gpe_block
->previous
= next_gpe_block
;
654 gpe_xrupt_block
->gpe_block_list_head
= gpe_block
;
657 gpe_block
->xrupt_block
= gpe_xrupt_block
;
658 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
661 status
= acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
662 return_ACPI_STATUS(status
);
665 /*******************************************************************************
667 * FUNCTION: acpi_ev_delete_gpe_block
669 * PARAMETERS: gpe_block - Existing GPE block
673 * DESCRIPTION: Remove a GPE block
675 ******************************************************************************/
677 acpi_status
acpi_ev_delete_gpe_block(struct acpi_gpe_block_info
*gpe_block
)
680 acpi_cpu_flags flags
;
682 ACPI_FUNCTION_TRACE(ev_install_gpe_block
);
684 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
685 if (ACPI_FAILURE(status
)) {
686 return_ACPI_STATUS(status
);
689 /* Disable all GPEs in this block */
691 status
= acpi_hw_disable_gpe_block(gpe_block
->xrupt_block
, gpe_block
);
693 if (!gpe_block
->previous
&& !gpe_block
->next
) {
695 /* This is the last gpe_block on this interrupt */
697 status
= acpi_ev_delete_gpe_xrupt(gpe_block
->xrupt_block
);
698 if (ACPI_FAILURE(status
)) {
699 goto unlock_and_exit
;
702 /* Remove the block on this interrupt with lock */
704 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
705 if (gpe_block
->previous
) {
706 gpe_block
->previous
->next
= gpe_block
->next
;
708 gpe_block
->xrupt_block
->gpe_block_list_head
=
712 if (gpe_block
->next
) {
713 gpe_block
->next
->previous
= gpe_block
->previous
;
715 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
718 /* Free the gpe_block */
720 ACPI_FREE(gpe_block
->register_info
);
721 ACPI_FREE(gpe_block
->event_info
);
722 ACPI_FREE(gpe_block
);
725 status
= acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
726 return_ACPI_STATUS(status
);
729 /*******************************************************************************
731 * FUNCTION: acpi_ev_create_gpe_info_blocks
733 * PARAMETERS: gpe_block - New GPE block
737 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
739 ******************************************************************************/
742 acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info
*gpe_block
)
744 struct acpi_gpe_register_info
*gpe_register_info
= NULL
;
745 struct acpi_gpe_event_info
*gpe_event_info
= NULL
;
746 struct acpi_gpe_event_info
*this_event
;
747 struct acpi_gpe_register_info
*this_register
;
752 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks
);
754 /* Allocate the GPE register information block */
756 gpe_register_info
= ACPI_ALLOCATE_ZEROED((acpi_size
) gpe_block
->
759 acpi_gpe_register_info
));
760 if (!gpe_register_info
) {
762 "Could not allocate the GpeRegisterInfo table"));
763 return_ACPI_STATUS(AE_NO_MEMORY
);
767 * Allocate the GPE event_info block. There are eight distinct GPEs
768 * per register. Initialization to zeros is sufficient.
770 gpe_event_info
= ACPI_ALLOCATE_ZEROED(((acpi_size
) gpe_block
->
772 ACPI_GPE_REGISTER_WIDTH
) *
774 acpi_gpe_event_info
));
775 if (!gpe_event_info
) {
777 "Could not allocate the GpeEventInfo table"));
778 status
= AE_NO_MEMORY
;
782 /* Save the new Info arrays in the GPE block */
784 gpe_block
->register_info
= gpe_register_info
;
785 gpe_block
->event_info
= gpe_event_info
;
788 * Initialize the GPE Register and Event structures. A goal of these
789 * tables is to hide the fact that there are two separate GPE register sets
790 * in a given GPE hardware block, the status registers occupy the first half,
791 * and the enable registers occupy the second half.
793 this_register
= gpe_register_info
;
794 this_event
= gpe_event_info
;
796 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
798 /* Init the register_info for this GPE register (8 GPEs) */
800 this_register
->base_gpe_number
=
801 (u8
) (gpe_block
->block_base_number
+
802 (i
* ACPI_GPE_REGISTER_WIDTH
));
804 this_register
->status_address
.address
=
805 gpe_block
->block_address
.address
+ i
;
807 this_register
->enable_address
.address
=
808 gpe_block
->block_address
.address
+ i
+
809 gpe_block
->register_count
;
811 this_register
->status_address
.space_id
=
812 gpe_block
->block_address
.space_id
;
813 this_register
->enable_address
.space_id
=
814 gpe_block
->block_address
.space_id
;
815 this_register
->status_address
.bit_width
=
816 ACPI_GPE_REGISTER_WIDTH
;
817 this_register
->enable_address
.bit_width
=
818 ACPI_GPE_REGISTER_WIDTH
;
819 this_register
->status_address
.bit_offset
=
820 ACPI_GPE_REGISTER_WIDTH
;
821 this_register
->enable_address
.bit_offset
=
822 ACPI_GPE_REGISTER_WIDTH
;
824 /* Init the event_info for each GPE within this register */
826 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++) {
827 this_event
->gpe_number
=
828 (u8
) (this_register
->base_gpe_number
+ j
);
829 this_event
->register_info
= this_register
;
833 /* Disable all GPEs within this register */
835 status
= acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH
, 0x00,
838 if (ACPI_FAILURE(status
)) {
842 /* Clear any pending GPE events within this register */
844 status
= acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH
, 0xFF,
847 if (ACPI_FAILURE(status
)) {
854 return_ACPI_STATUS(AE_OK
);
857 if (gpe_register_info
) {
858 ACPI_FREE(gpe_register_info
);
860 if (gpe_event_info
) {
861 ACPI_FREE(gpe_event_info
);
864 return_ACPI_STATUS(status
);
867 /*******************************************************************************
869 * FUNCTION: acpi_ev_create_gpe_block
871 * PARAMETERS: gpe_device - Handle to the parent GPE block
872 * gpe_block_address - Address and space_iD
873 * register_count - Number of GPE register pairs in the block
874 * gpe_block_base_number - Starting GPE number for the block
875 * interrupt_number - H/W interrupt for the block
876 * return_gpe_block - Where the new block descriptor is returned
880 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
881 * the block are disabled at exit.
882 * Note: Assumes namespace is locked.
884 ******************************************************************************/
887 acpi_ev_create_gpe_block(struct acpi_namespace_node
*gpe_device
,
888 struct acpi_generic_address
*gpe_block_address
,
890 u8 gpe_block_base_number
,
891 u32 interrupt_number
,
892 struct acpi_gpe_block_info
**return_gpe_block
)
895 struct acpi_gpe_block_info
*gpe_block
;
897 ACPI_FUNCTION_TRACE(ev_create_gpe_block
);
899 if (!register_count
) {
900 return_ACPI_STATUS(AE_OK
);
903 /* Allocate a new GPE block */
905 gpe_block
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info
));
907 return_ACPI_STATUS(AE_NO_MEMORY
);
910 /* Initialize the new GPE block */
912 gpe_block
->node
= gpe_device
;
913 gpe_block
->register_count
= register_count
;
914 gpe_block
->block_base_number
= gpe_block_base_number
;
916 ACPI_MEMCPY(&gpe_block
->block_address
, gpe_block_address
,
917 sizeof(struct acpi_generic_address
));
920 * Create the register_info and event_info sub-structures
921 * Note: disables and clears all GPEs in the block
923 status
= acpi_ev_create_gpe_info_blocks(gpe_block
);
924 if (ACPI_FAILURE(status
)) {
925 ACPI_FREE(gpe_block
);
926 return_ACPI_STATUS(status
);
929 /* Install the new block in the global lists */
931 status
= acpi_ev_install_gpe_block(gpe_block
, interrupt_number
);
932 if (ACPI_FAILURE(status
)) {
933 ACPI_FREE(gpe_block
);
934 return_ACPI_STATUS(status
);
937 /* Find all GPE methods (_Lxx, _Exx) for this block */
939 status
= acpi_ns_walk_namespace(ACPI_TYPE_METHOD
, gpe_device
,
940 ACPI_UINT32_MAX
, ACPI_NS_WALK_NO_UNLOCK
,
941 acpi_ev_save_method_info
, gpe_block
,
944 /* Return the new block */
946 if (return_gpe_block
) {
947 (*return_gpe_block
) = gpe_block
;
950 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
951 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
952 (u32
) gpe_block
->block_base_number
,
953 (u32
) (gpe_block
->block_base_number
+
954 ((gpe_block
->register_count
*
955 ACPI_GPE_REGISTER_WIDTH
) - 1)),
956 gpe_device
->name
.ascii
, gpe_block
->register_count
,
959 return_ACPI_STATUS(AE_OK
);
962 /*******************************************************************************
964 * FUNCTION: acpi_ev_initialize_gpe_block
966 * PARAMETERS: gpe_device - Handle to the parent GPE block
967 * gpe_block - Gpe Block info
971 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
972 * _PRT methods associated with the block, then enable the
974 * Note: Assumes namespace is locked.
976 ******************************************************************************/
979 acpi_ev_initialize_gpe_block(struct acpi_namespace_node
*gpe_device
,
980 struct acpi_gpe_block_info
*gpe_block
)
983 struct acpi_gpe_event_info
*gpe_event_info
;
984 struct acpi_gpe_walk_info gpe_info
;
986 u32 gpe_enabled_count
;
990 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block
);
992 /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
995 return_ACPI_STATUS(AE_OK
);
999 * Runtime option: Should wake GPEs be enabled at runtime? The default
1000 * is no, they should only be enabled just as the machine goes to sleep.
1002 if (acpi_gbl_leave_wake_gpes_disabled
) {
1004 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
1005 * Each GPE that has one or more _PRWs that reference it is by
1006 * definition a wake GPE and will not be enabled while the machine
1009 gpe_info
.gpe_block
= gpe_block
;
1010 gpe_info
.gpe_device
= gpe_device
;
1013 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
1014 ACPI_UINT32_MAX
, ACPI_NS_WALK_UNLOCK
,
1015 acpi_ev_match_prw_and_gpe
, &gpe_info
,
1020 * Enable all GPEs in this block that have these attributes:
1021 * 1) are "runtime" or "run/wake" GPEs, and
1022 * 2) have a corresponding _Lxx or _Exx method
1024 * Any other GPEs within this block must be enabled via the acpi_enable_gpe()
1025 * external interface.
1028 gpe_enabled_count
= 0;
1030 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
1031 for (j
= 0; j
< 8; j
++) {
1033 /* Get the info block for this particular GPE */
1037 event_info
[((acpi_size
) i
*
1038 ACPI_GPE_REGISTER_WIDTH
) + j
];
1040 if (((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
1041 ACPI_GPE_DISPATCH_METHOD
)
1042 && (gpe_event_info
->flags
& ACPI_GPE_TYPE_RUNTIME
)) {
1043 gpe_enabled_count
++;
1046 if (gpe_event_info
->flags
& ACPI_GPE_TYPE_WAKE
) {
1052 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
1053 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1054 wake_gpe_count
, gpe_enabled_count
));
1056 /* Enable all valid runtime GPEs found above */
1058 status
= acpi_hw_enable_runtime_gpe_block(NULL
, gpe_block
);
1059 if (ACPI_FAILURE(status
)) {
1060 ACPI_ERROR((AE_INFO
, "Could not enable GPEs in GpeBlock %p",
1064 return_ACPI_STATUS(status
);
1067 /*******************************************************************************
1069 * FUNCTION: acpi_ev_gpe_initialize
1075 * DESCRIPTION: Initialize the GPE data structures
1077 ******************************************************************************/
1079 acpi_status
acpi_ev_gpe_initialize(void)
1081 u32 register_count0
= 0;
1082 u32 register_count1
= 0;
1083 u32 gpe_number_max
= 0;
1086 ACPI_FUNCTION_TRACE(ev_gpe_initialize
);
1088 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
1089 if (ACPI_FAILURE(status
)) {
1090 return_ACPI_STATUS(status
);
1094 * Initialize the GPE Block(s) defined in the FADT
1096 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1097 * section "General-Purpose Event Registers", we have:
1099 * "Each register block contains two registers of equal length
1100 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1101 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1102 * The length of the GPE1_STS and GPE1_EN registers is equal to
1103 * half the GPE1_LEN. If a generic register block is not supported
1104 * then its respective block pointer and block length values in the
1105 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1106 * to be the same size."
1110 * Determine the maximum GPE number for this machine.
1112 * Note: both GPE0 and GPE1 are optional, and either can exist without
1115 * If EITHER the register length OR the block address are zero, then that
1116 * particular block is not supported.
1118 if (acpi_gbl_FADT
.gpe0_block_length
&&
1119 acpi_gbl_FADT
.xgpe0_block
.address
) {
1121 /* GPE block 0 exists (has both length and address > 0) */
1123 register_count0
= (u16
) (acpi_gbl_FADT
.gpe0_block_length
/ 2);
1126 (register_count0
* ACPI_GPE_REGISTER_WIDTH
) - 1;
1128 /* Install GPE Block 0 */
1130 status
= acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device
,
1131 &acpi_gbl_FADT
.xgpe0_block
,
1133 acpi_gbl_FADT
.sci_interrupt
,
1134 &acpi_gbl_gpe_fadt_blocks
[0]);
1136 if (ACPI_FAILURE(status
)) {
1137 ACPI_EXCEPTION((AE_INFO
, status
,
1138 "Could not create GPE Block 0"));
1142 if (acpi_gbl_FADT
.gpe1_block_length
&&
1143 acpi_gbl_FADT
.xgpe1_block
.address
) {
1145 /* GPE block 1 exists (has both length and address > 0) */
1147 register_count1
= (u16
) (acpi_gbl_FADT
.gpe1_block_length
/ 2);
1149 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1151 if ((register_count0
) &&
1152 (gpe_number_max
>= acpi_gbl_FADT
.gpe1_base
)) {
1153 ACPI_ERROR((AE_INFO
,
1154 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1",
1155 gpe_number_max
, acpi_gbl_FADT
.gpe1_base
,
1156 acpi_gbl_FADT
.gpe1_base
+
1158 ACPI_GPE_REGISTER_WIDTH
) - 1)));
1160 /* Ignore GPE1 block by setting the register count to zero */
1162 register_count1
= 0;
1164 /* Install GPE Block 1 */
1167 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device
,
1168 &acpi_gbl_FADT
.xgpe1_block
,
1170 acpi_gbl_FADT
.gpe1_base
,
1173 &acpi_gbl_gpe_fadt_blocks
1176 if (ACPI_FAILURE(status
)) {
1177 ACPI_EXCEPTION((AE_INFO
, status
,
1178 "Could not create GPE Block 1"));
1182 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1183 * space. However, GPE0 always starts at GPE number zero.
1185 gpe_number_max
= acpi_gbl_FADT
.gpe1_base
+
1186 ((register_count1
* ACPI_GPE_REGISTER_WIDTH
) - 1);
1190 /* Exit if there are no GPE registers */
1192 if ((register_count0
+ register_count1
) == 0) {
1194 /* GPEs are not required by ACPI, this is OK */
1196 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
1197 "There are no GPE blocks defined in the FADT\n"));
1202 /* Check for Max GPE number out-of-range */
1204 if (gpe_number_max
> ACPI_GPE_MAX
) {
1205 ACPI_ERROR((AE_INFO
,
1206 "Maximum GPE number from FADT is too large: 0x%X",
1208 status
= AE_BAD_VALUE
;
1213 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
1214 return_ACPI_STATUS(AE_OK
);