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")
52 /*******************************************************************************
54 * FUNCTION: acpi_ev_valid_gpe_event
56 * PARAMETERS: gpe_event_info - Info for this GPE
58 * RETURN: TRUE if the gpe_event is valid
60 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
61 * Should be called only when the GPE lists are semaphore locked
62 * and not subject to change.
64 ******************************************************************************/
67 acpi_ev_valid_gpe_event (
68 struct acpi_gpe_event_info *gpe_event_info)
70 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
71 struct acpi_gpe_block_info *gpe_block;
74 ACPI_FUNCTION_ENTRY ();
77 /* No need for spin lock since we are not changing any list elements */
79 /* Walk the GPE interrupt levels */
81 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
82 while (gpe_xrupt_block) {
83 gpe_block = gpe_xrupt_block->gpe_block_list_head;
85 /* Walk the GPE blocks on this interrupt level */
88 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
89 (&gpe_block->event_info[((acpi_size) gpe_block->register_count) * 8] > gpe_event_info)) {
93 gpe_block = gpe_block->next;
96 gpe_xrupt_block = gpe_xrupt_block->next;
103 /*******************************************************************************
105 * FUNCTION: acpi_ev_walk_gpe_list
107 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
108 * Flags - ACPI_NOT_ISR or ACPI_ISR
112 * DESCRIPTION: Walk the GPE lists.
114 ******************************************************************************/
117 acpi_ev_walk_gpe_list (
118 ACPI_GPE_CALLBACK gpe_walk_callback,
121 struct acpi_gpe_block_info *gpe_block;
122 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
123 acpi_status status = AE_OK;
126 ACPI_FUNCTION_TRACE ("ev_walk_gpe_list");
129 acpi_os_acquire_lock (acpi_gbl_gpe_lock, flags);
131 /* Walk the interrupt level descriptor list */
133 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
134 while (gpe_xrupt_info) {
135 /* Walk all Gpe Blocks attached to this interrupt level */
137 gpe_block = gpe_xrupt_info->gpe_block_list_head;
139 /* One callback per GPE block */
141 status = gpe_walk_callback (gpe_xrupt_info, gpe_block);
142 if (ACPI_FAILURE (status)) {
143 goto unlock_and_exit;
146 gpe_block = gpe_block->next;
149 gpe_xrupt_info = gpe_xrupt_info->next;
153 acpi_os_release_lock (acpi_gbl_gpe_lock, flags);
154 return_ACPI_STATUS (status);
158 /******************************************************************************
160 * FUNCTION: acpi_ev_delete_gpe_handlers
162 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
163 * gpe_block - Gpe Block info
167 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
168 * Used only prior to termination.
170 ******************************************************************************/
173 acpi_ev_delete_gpe_handlers (
174 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
175 struct acpi_gpe_block_info *gpe_block)
177 struct acpi_gpe_event_info *gpe_event_info;
182 ACPI_FUNCTION_TRACE ("ev_delete_gpe_handlers");
185 /* Examine each GPE Register within the block */
187 for (i = 0; i < gpe_block->register_count; i++) {
188 /* Now look at the individual GPEs in this byte register */
190 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
191 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
193 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) {
194 ACPI_MEM_FREE (gpe_event_info->dispatch.handler);
195 gpe_event_info->dispatch.handler = NULL;
196 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK;
201 return_ACPI_STATUS (AE_OK);
205 /*******************************************************************************
207 * FUNCTION: acpi_ev_save_method_info
209 * PARAMETERS: Callback from walk_namespace
213 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
214 * control method under the _GPE portion of the namespace.
215 * Extract the name and GPE type from the object, saving this
216 * information for quick lookup during GPE dispatch
218 * The name of each GPE control method is of the form:
221 * L - means that the GPE is level triggered
222 * E - means that the GPE is edge triggered
223 * xx - is the GPE number [in HEX]
225 ******************************************************************************/
228 acpi_ev_save_method_info (
229 acpi_handle obj_handle,
234 struct acpi_gpe_block_info *gpe_block = (void *) obj_desc;
235 struct acpi_gpe_event_info *gpe_event_info;
237 char name[ACPI_NAME_SIZE + 1];
242 ACPI_FUNCTION_TRACE ("ev_save_method_info");
246 * _Lxx and _Exx GPE method support
248 * 1) Extract the name from the object and convert to a string
250 ACPI_MOVE_32_TO_32 (name,
251 &((struct acpi_namespace_node *) obj_handle)->name.integer);
252 name[ACPI_NAME_SIZE] = 0;
255 * 2) Edge/Level determination is based on the 2nd character
258 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
259 * if a _PRW object is found that points to this GPE.
263 type = ACPI_GPE_LEVEL_TRIGGERED;
267 type = ACPI_GPE_EDGE_TRIGGERED;
271 /* Unknown method type, just ignore it! */
273 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
274 "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n",
276 return_ACPI_STATUS (AE_OK);
279 /* Convert the last two characters of the name to the GPE Number */
281 gpe_number = ACPI_STRTOUL (&name[2], NULL, 16);
282 if (gpe_number == ACPI_UINT32_MAX) {
283 /* Conversion failed; invalid method, just ignore it */
285 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
286 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n",
288 return_ACPI_STATUS (AE_OK);
291 /* Ensure that we have a valid GPE number for this GPE block */
293 if ((gpe_number < gpe_block->block_base_number) ||
294 (gpe_number >= (gpe_block->block_base_number + (gpe_block->register_count * 8)))) {
296 * Not valid for this GPE block, just ignore it
297 * However, it may be valid for a different GPE block, since GPE0 and GPE1
298 * methods both appear under \_GPE.
300 return_ACPI_STATUS (AE_OK);
304 * Now we can add this information to the gpe_event_info block
305 * for use during dispatch of this GPE. Default type is RUNTIME, although
306 * this may change when the _PRW methods are executed later.
308 gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
310 gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD |
311 ACPI_GPE_TYPE_RUNTIME);
313 gpe_event_info->dispatch.method_node = (struct acpi_namespace_node *) obj_handle;
315 /* Update enable mask, but don't enable the HW GPE as of yet */
317 status = acpi_ev_enable_gpe (gpe_event_info, FALSE);
319 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
320 "Registered GPE method %s as GPE number 0x%.2X\n",
322 return_ACPI_STATUS (status);
326 /*******************************************************************************
328 * FUNCTION: acpi_ev_match_prw_and_gpe
330 * PARAMETERS: Callback from walk_namespace
332 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
333 * not aborted on a single _PRW failure.
335 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
336 * Device. Run the _PRW method. If present, extract the GPE
337 * number and mark the GPE as a WAKE GPE.
339 ******************************************************************************/
342 acpi_ev_match_prw_and_gpe (
343 acpi_handle obj_handle,
348 struct acpi_gpe_walk_info *gpe_info = (void *) info;
349 struct acpi_namespace_node *gpe_device;
350 struct acpi_gpe_block_info *gpe_block;
351 struct acpi_namespace_node *target_gpe_device;
352 struct acpi_gpe_event_info *gpe_event_info;
353 union acpi_operand_object *pkg_desc;
354 union acpi_operand_object *obj_desc;
359 ACPI_FUNCTION_TRACE ("ev_match_prw_and_gpe");
362 /* Check for a _PRW method under this device */
364 status = acpi_ut_evaluate_object (obj_handle, METHOD_NAME__PRW,
365 ACPI_BTYPE_PACKAGE, &pkg_desc);
366 if (ACPI_FAILURE (status)) {
367 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
369 return_ACPI_STATUS (AE_OK);
372 /* The returned _PRW package must have at least two elements */
374 if (pkg_desc->package.count < 2) {
378 /* Extract pointers from the input context */
380 gpe_device = gpe_info->gpe_device;
381 gpe_block = gpe_info->gpe_block;
384 * The _PRW object must return a package, we are only interested
385 * in the first element
387 obj_desc = pkg_desc->package.elements[0];
389 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
390 /* Use FADT-defined GPE device (from definition of _PRW) */
392 target_gpe_device = acpi_gbl_fadt_gpe_device;
394 /* Integer is the GPE number in the FADT described GPE blocks */
396 gpe_number = (u32) obj_desc->integer.value;
398 else if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
399 /* Package contains a GPE reference and GPE number within a GPE block */
401 if ((obj_desc->package.count < 2) ||
402 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[0]) != ACPI_TYPE_LOCAL_REFERENCE) ||
403 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[1]) != ACPI_TYPE_INTEGER)) {
407 /* Get GPE block reference and decode */
409 target_gpe_device = obj_desc->package.elements[0]->reference.node;
410 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
413 /* Unknown type, just ignore it */
419 * Is this GPE within this block?
421 * TRUE iff these conditions are true:
422 * 1) The GPE devices match.
423 * 2) The GPE index(number) is within the range of the Gpe Block
424 * associated with the GPE device.
426 if ((gpe_device == target_gpe_device) &&
427 (gpe_number >= gpe_block->block_base_number) &&
428 (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) {
429 gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
431 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
433 gpe_event_info->flags &= ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
434 status = acpi_ev_set_gpe_type (gpe_event_info, ACPI_GPE_TYPE_WAKE);
435 if (ACPI_FAILURE (status)) {
438 status = acpi_ev_update_gpe_enable_masks (gpe_event_info, ACPI_GPE_DISABLE);
442 acpi_ut_remove_reference (pkg_desc);
443 return_ACPI_STATUS (AE_OK);
447 /*******************************************************************************
449 * FUNCTION: acpi_ev_get_gpe_xrupt_block
451 * PARAMETERS: interrupt_level - Interrupt for a GPE block
453 * RETURN: A GPE interrupt block
455 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
456 * block per unique interrupt level used for GPEs.
457 * Should be called only when the GPE lists are semaphore locked
458 * and not subject to change.
460 ******************************************************************************/
462 static struct acpi_gpe_xrupt_info *
463 acpi_ev_get_gpe_xrupt_block (
466 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
467 struct acpi_gpe_xrupt_info *gpe_xrupt;
471 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block");
474 /* No need for spin lock since we are not changing any list elements here */
476 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
477 while (next_gpe_xrupt) {
478 if (next_gpe_xrupt->interrupt_level == interrupt_level) {
479 return_PTR (next_gpe_xrupt);
482 next_gpe_xrupt = next_gpe_xrupt->next;
485 /* Not found, must allocate a new xrupt descriptor */
487 gpe_xrupt = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_xrupt_info));
492 gpe_xrupt->interrupt_level = interrupt_level;
494 /* Install new interrupt descriptor with spin lock */
496 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
497 if (acpi_gbl_gpe_xrupt_list_head) {
498 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
499 while (next_gpe_xrupt->next) {
500 next_gpe_xrupt = next_gpe_xrupt->next;
503 next_gpe_xrupt->next = gpe_xrupt;
504 gpe_xrupt->previous = next_gpe_xrupt;
507 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
509 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
511 /* Install new interrupt handler if not SCI_INT */
513 if (interrupt_level != acpi_gbl_FADT->sci_int) {
514 status = acpi_os_install_interrupt_handler (interrupt_level,
515 acpi_ev_gpe_xrupt_handler, gpe_xrupt);
516 if (ACPI_FAILURE (status)) {
517 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
518 "Could not install GPE interrupt handler at level 0x%X\n",
524 return_PTR (gpe_xrupt);
528 /*******************************************************************************
530 * FUNCTION: acpi_ev_delete_gpe_xrupt
532 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
536 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
537 * interrupt handler if not the SCI interrupt.
539 ******************************************************************************/
542 acpi_ev_delete_gpe_xrupt (
543 struct acpi_gpe_xrupt_info *gpe_xrupt)
548 ACPI_FUNCTION_TRACE ("ev_delete_gpe_xrupt");
551 /* We never want to remove the SCI interrupt handler */
553 if (gpe_xrupt->interrupt_level == acpi_gbl_FADT->sci_int) {
554 gpe_xrupt->gpe_block_list_head = NULL;
555 return_ACPI_STATUS (AE_OK);
558 /* Disable this interrupt */
560 status = acpi_os_remove_interrupt_handler (gpe_xrupt->interrupt_level,
561 acpi_ev_gpe_xrupt_handler);
562 if (ACPI_FAILURE (status)) {
563 return_ACPI_STATUS (status);
566 /* Unlink the interrupt block with lock */
568 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
569 if (gpe_xrupt->previous) {
570 gpe_xrupt->previous->next = gpe_xrupt->next;
573 if (gpe_xrupt->next) {
574 gpe_xrupt->next->previous = gpe_xrupt->previous;
576 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
580 ACPI_MEM_FREE (gpe_xrupt);
581 return_ACPI_STATUS (AE_OK);
585 /*******************************************************************************
587 * FUNCTION: acpi_ev_install_gpe_block
589 * PARAMETERS: gpe_block - New GPE block
590 * interrupt_level - Level to be associated with this GPE block
594 * DESCRIPTION: Install new GPE block with mutex support
596 ******************************************************************************/
599 acpi_ev_install_gpe_block (
600 struct acpi_gpe_block_info *gpe_block,
603 struct acpi_gpe_block_info *next_gpe_block;
604 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
608 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
611 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
612 if (ACPI_FAILURE (status)) {
613 return_ACPI_STATUS (status);
616 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block (interrupt_level);
617 if (!gpe_xrupt_block) {
618 status = AE_NO_MEMORY;
619 goto unlock_and_exit;
622 /* Install the new block at the end of the list for this interrupt with lock */
624 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
625 if (gpe_xrupt_block->gpe_block_list_head) {
626 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
627 while (next_gpe_block->next) {
628 next_gpe_block = next_gpe_block->next;
631 next_gpe_block->next = gpe_block;
632 gpe_block->previous = next_gpe_block;
635 gpe_xrupt_block->gpe_block_list_head = gpe_block;
638 gpe_block->xrupt_block = gpe_xrupt_block;
639 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
642 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
643 return_ACPI_STATUS (status);
647 /*******************************************************************************
649 * FUNCTION: acpi_ev_delete_gpe_block
651 * PARAMETERS: gpe_block - Existing GPE block
655 * DESCRIPTION: Remove a GPE block
657 ******************************************************************************/
660 acpi_ev_delete_gpe_block (
661 struct acpi_gpe_block_info *gpe_block)
666 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
669 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
670 if (ACPI_FAILURE (status)) {
671 return_ACPI_STATUS (status);
674 /* Disable all GPEs in this block */
676 status = acpi_hw_disable_gpe_block (gpe_block->xrupt_block, gpe_block);
678 if (!gpe_block->previous && !gpe_block->next) {
679 /* This is the last gpe_block on this interrupt */
681 status = acpi_ev_delete_gpe_xrupt (gpe_block->xrupt_block);
682 if (ACPI_FAILURE (status)) {
683 goto unlock_and_exit;
687 /* Remove the block on this interrupt with lock */
689 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
690 if (gpe_block->previous) {
691 gpe_block->previous->next = gpe_block->next;
694 gpe_block->xrupt_block->gpe_block_list_head = gpe_block->next;
697 if (gpe_block->next) {
698 gpe_block->next->previous = gpe_block->previous;
700 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
703 /* Free the gpe_block */
705 ACPI_MEM_FREE (gpe_block->register_info);
706 ACPI_MEM_FREE (gpe_block->event_info);
707 ACPI_MEM_FREE (gpe_block);
710 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
711 return_ACPI_STATUS (status);
715 /*******************************************************************************
717 * FUNCTION: acpi_ev_create_gpe_info_blocks
719 * PARAMETERS: gpe_block - New GPE block
723 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
725 ******************************************************************************/
728 acpi_ev_create_gpe_info_blocks (
729 struct acpi_gpe_block_info *gpe_block)
731 struct acpi_gpe_register_info *gpe_register_info = NULL;
732 struct acpi_gpe_event_info *gpe_event_info = NULL;
733 struct acpi_gpe_event_info *this_event;
734 struct acpi_gpe_register_info *this_register;
740 ACPI_FUNCTION_TRACE ("ev_create_gpe_info_blocks");
743 /* Allocate the GPE register information block */
745 gpe_register_info = ACPI_MEM_CALLOCATE (
746 (acpi_size) gpe_block->register_count *
747 sizeof (struct acpi_gpe_register_info));
748 if (!gpe_register_info) {
749 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
750 "Could not allocate the gpe_register_info table\n"));
751 return_ACPI_STATUS (AE_NO_MEMORY);
755 * Allocate the GPE event_info block. There are eight distinct GPEs
756 * per register. Initialization to zeros is sufficient.
758 gpe_event_info = ACPI_MEM_CALLOCATE (
759 ((acpi_size) gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) *
760 sizeof (struct acpi_gpe_event_info));
761 if (!gpe_event_info) {
762 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the gpe_event_info table\n"));
763 status = AE_NO_MEMORY;
767 /* Save the new Info arrays in the GPE block */
769 gpe_block->register_info = gpe_register_info;
770 gpe_block->event_info = gpe_event_info;
773 * Initialize the GPE Register and Event structures. A goal of these
774 * tables is to hide the fact that there are two separate GPE register sets
775 * in a given gpe hardware block, the status registers occupy the first half,
776 * and the enable registers occupy the second half.
778 this_register = gpe_register_info;
779 this_event = gpe_event_info;
781 for (i = 0; i < gpe_block->register_count; i++) {
782 /* Init the register_info for this GPE register (8 GPEs) */
784 this_register->base_gpe_number = (u8) (gpe_block->block_base_number +
785 (i * ACPI_GPE_REGISTER_WIDTH));
787 ACPI_STORE_ADDRESS (this_register->status_address.address,
788 (gpe_block->block_address.address
791 ACPI_STORE_ADDRESS (this_register->enable_address.address,
792 (gpe_block->block_address.address
794 + gpe_block->register_count));
796 this_register->status_address.address_space_id = gpe_block->block_address.address_space_id;
797 this_register->enable_address.address_space_id = gpe_block->block_address.address_space_id;
798 this_register->status_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH;
799 this_register->enable_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH;
800 this_register->status_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH;
801 this_register->enable_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH;
803 /* Init the event_info for each GPE within this register */
805 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
806 this_event->register_bit = acpi_gbl_decode_to8bit[j];
807 this_event->register_info = this_register;
812 * Clear the status/enable registers. Note that status registers
813 * are cleared by writing a '1', while enable registers are cleared
816 status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0x00,
817 &this_register->enable_address);
818 if (ACPI_FAILURE (status)) {
822 status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0xFF,
823 &this_register->status_address);
824 if (ACPI_FAILURE (status)) {
831 return_ACPI_STATUS (AE_OK);
835 if (gpe_register_info) {
836 ACPI_MEM_FREE (gpe_register_info);
838 if (gpe_event_info) {
839 ACPI_MEM_FREE (gpe_event_info);
842 return_ACPI_STATUS (status);
846 /*******************************************************************************
848 * FUNCTION: acpi_ev_create_gpe_block
850 * PARAMETERS: gpe_device - Handle to the parent GPE block
851 * gpe_block_address - Address and space_iD
852 * register_count - Number of GPE register pairs in the block
853 * gpe_block_base_number - Starting GPE number for the block
854 * interrupt_level - H/W interrupt for the block
855 * return_gpe_block - Where the new block descriptor is returned
859 * DESCRIPTION: Create and Install a block of GPE registers
861 ******************************************************************************/
864 acpi_ev_create_gpe_block (
865 struct acpi_namespace_node *gpe_device,
866 struct acpi_generic_address *gpe_block_address,
868 u8 gpe_block_base_number,
870 struct acpi_gpe_block_info **return_gpe_block)
872 struct acpi_gpe_block_info *gpe_block;
873 struct acpi_gpe_event_info *gpe_event_info;
877 u32 gpe_enabled_count;
879 struct acpi_gpe_walk_info gpe_info;
882 ACPI_FUNCTION_TRACE ("ev_create_gpe_block");
885 if (!register_count) {
886 return_ACPI_STATUS (AE_OK);
889 /* Allocate a new GPE block */
891 gpe_block = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_block_info));
893 return_ACPI_STATUS (AE_NO_MEMORY);
896 /* Initialize the new GPE block */
898 gpe_block->register_count = register_count;
899 gpe_block->block_base_number = gpe_block_base_number;
900 gpe_block->node = gpe_device;
902 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address, sizeof (struct acpi_generic_address));
904 /* Create the register_info and event_info sub-structures */
906 status = acpi_ev_create_gpe_info_blocks (gpe_block);
907 if (ACPI_FAILURE (status)) {
908 ACPI_MEM_FREE (gpe_block);
909 return_ACPI_STATUS (status);
912 /* Install the new block in the global list(s) */
914 status = acpi_ev_install_gpe_block (gpe_block, interrupt_level);
915 if (ACPI_FAILURE (status)) {
916 ACPI_MEM_FREE (gpe_block);
917 return_ACPI_STATUS (status);
920 /* Find all GPE methods (_Lxx, _Exx) for this block */
922 status = acpi_ns_walk_namespace (ACPI_TYPE_METHOD, gpe_device,
923 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, acpi_ev_save_method_info,
927 * Runtime option: Should Wake GPEs be enabled at runtime? The default
928 * is No, they should only be enabled just as the machine goes to sleep.
930 if (acpi_gbl_leave_wake_gpes_disabled) {
932 * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods.
933 * (Each GPE that has one or more _PRWs that reference it is by
934 * definition a WAKE GPE and will not be enabled while the machine
937 gpe_info.gpe_block = gpe_block;
938 gpe_info.gpe_device = gpe_device;
940 status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
941 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ev_match_prw_and_gpe,
946 * Enable all GPEs in this block that are 1) "runtime" or "run/wake" GPEs,
947 * and 2) have a corresponding _Lxx or _Exx method. All other GPEs must
948 * be enabled via the acpi_enable_gpe() external interface.
951 gpe_enabled_count = 0;
953 for (i = 0; i < gpe_block->register_count; i++) {
954 for (j = 0; j < 8; j++) {
955 /* Get the info block for this particular GPE */
957 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
959 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) &&
960 (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
964 if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) {
970 /* Dump info about this GPE block */
972 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
973 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
974 (u32) gpe_block->block_base_number,
975 (u32) (gpe_block->block_base_number +
976 ((gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) -1)),
977 gpe_device->name.ascii,
978 gpe_block->register_count,
981 /* Enable all valid GPEs found above */
983 status = acpi_hw_enable_runtime_gpe_block (NULL, gpe_block);
985 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
986 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
987 wake_gpe_count, gpe_enabled_count));
989 /* Return the new block */
991 if (return_gpe_block) {
992 (*return_gpe_block) = gpe_block;
995 return_ACPI_STATUS (AE_OK);
999 /*******************************************************************************
1001 * FUNCTION: acpi_ev_gpe_initialize
1007 * DESCRIPTION: Initialize the GPE data structures
1009 ******************************************************************************/
1012 acpi_ev_gpe_initialize (
1015 u32 register_count0 = 0;
1016 u32 register_count1 = 0;
1017 u32 gpe_number_max = 0;
1021 ACPI_FUNCTION_TRACE ("ev_gpe_initialize");
1024 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
1025 if (ACPI_FAILURE (status)) {
1026 return_ACPI_STATUS (status);
1030 * Initialize the GPE Block(s) defined in the FADT
1032 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1033 * section "General-Purpose Event Registers", we have:
1035 * "Each register block contains two registers of equal length
1036 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1037 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1038 * The length of the GPE1_STS and GPE1_EN registers is equal to
1039 * half the GPE1_LEN. If a generic register block is not supported
1040 * then its respective block pointer and block length values in the
1041 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1042 * to be the same size."
1046 * Determine the maximum GPE number for this machine.
1048 * Note: both GPE0 and GPE1 are optional, and either can exist without
1051 * If EITHER the register length OR the block address are zero, then that
1052 * particular block is not supported.
1054 if (acpi_gbl_FADT->gpe0_blk_len &&
1055 acpi_gbl_FADT->xgpe0_blk.address) {
1056 /* GPE block 0 exists (has both length and address > 0) */
1058 register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2);
1060 gpe_number_max = (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1062 /* Install GPE Block 0 */
1064 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe0_blk,
1065 register_count0, 0, acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]);
1067 if (ACPI_FAILURE (status)) {
1068 ACPI_REPORT_ERROR ((
1069 "Could not create GPE Block 0, %s\n",
1070 acpi_format_exception (status)));
1074 if (acpi_gbl_FADT->gpe1_blk_len &&
1075 acpi_gbl_FADT->xgpe1_blk.address) {
1076 /* GPE block 1 exists (has both length and address > 0) */
1078 register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2);
1080 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1082 if ((register_count0) &&
1083 (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) {
1084 ACPI_REPORT_ERROR ((
1085 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n",
1086 gpe_number_max, acpi_gbl_FADT->gpe1_base,
1087 acpi_gbl_FADT->gpe1_base +
1088 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
1090 /* Ignore GPE1 block by setting the register count to zero */
1092 register_count1 = 0;
1095 /* Install GPE Block 1 */
1097 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe1_blk,
1098 register_count1, acpi_gbl_FADT->gpe1_base,
1099 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]);
1101 if (ACPI_FAILURE (status)) {
1102 ACPI_REPORT_ERROR ((
1103 "Could not create GPE Block 1, %s\n",
1104 acpi_format_exception (status)));
1108 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1109 * space. However, GPE0 always starts at GPE number zero.
1111 gpe_number_max = acpi_gbl_FADT->gpe1_base +
1112 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1116 /* Exit if there are no GPE registers */
1118 if ((register_count0 + register_count1) == 0) {
1119 /* GPEs are not required by ACPI, this is OK */
1121 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1122 "There are no GPE blocks defined in the FADT\n"));
1127 /* Check for Max GPE number out-of-range */
1129 if (gpe_number_max > ACPI_GPE_MAX) {
1130 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
1132 status = AE_BAD_VALUE;
1137 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
1138 return_ACPI_STATUS (AE_OK);