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 */
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;
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) {
149 /* Walk all Gpe Blocks attached to this interrupt level */
151 gpe_block = gpe_xrupt_info->gpe_block_list_head;
153 /* One callback per GPE block */
155 status = gpe_walk_callback(gpe_xrupt_info, gpe_block);
156 if (ACPI_FAILURE(status)) {
157 goto unlock_and_exit;
160 gpe_block = gpe_block->next;
163 gpe_xrupt_info = gpe_xrupt_info->next;
167 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
168 return_ACPI_STATUS(status);
171 /*******************************************************************************
173 * FUNCTION: acpi_ev_delete_gpe_handlers
175 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
176 * gpe_block - Gpe Block info
180 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
181 * Used only prior to termination.
183 ******************************************************************************/
186 acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
187 struct acpi_gpe_block_info *gpe_block)
189 struct acpi_gpe_event_info *gpe_event_info;
193 ACPI_FUNCTION_TRACE("ev_delete_gpe_handlers");
195 /* Examine each GPE Register within the block */
197 for (i = 0; i < gpe_block->register_count; i++) {
198 /* Now look at the individual GPEs in this byte register */
200 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
203 event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
205 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
206 ACPI_GPE_DISPATCH_HANDLER) {
207 ACPI_MEM_FREE(gpe_event_info->dispatch.handler);
208 gpe_event_info->dispatch.handler = NULL;
209 gpe_event_info->flags &=
210 ~ACPI_GPE_DISPATCH_MASK;
215 return_ACPI_STATUS(AE_OK);
218 /*******************************************************************************
220 * FUNCTION: acpi_ev_save_method_info
222 * PARAMETERS: Callback from walk_namespace
226 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
227 * control method under the _GPE portion of the namespace.
228 * Extract the name and GPE type from the object, saving this
229 * information for quick lookup during GPE dispatch
231 * The name of each GPE control method is of the form:
234 * L - means that the GPE is level triggered
235 * E - means that the GPE is edge triggered
236 * xx - is the GPE number [in HEX]
238 ******************************************************************************/
241 acpi_ev_save_method_info(acpi_handle obj_handle,
242 u32 level, void *obj_desc, void **return_value)
244 struct acpi_gpe_block_info *gpe_block = (void *)obj_desc;
245 struct acpi_gpe_event_info *gpe_event_info;
247 char name[ACPI_NAME_SIZE + 1];
251 ACPI_FUNCTION_TRACE("ev_save_method_info");
254 * _Lxx and _Exx GPE method support
256 * 1) Extract the name from the object and convert to a string
258 ACPI_MOVE_32_TO_32(name,
259 &((struct acpi_namespace_node *)obj_handle)->name.
261 name[ACPI_NAME_SIZE] = 0;
264 * 2) Edge/Level determination is based on the 2nd character
267 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
268 * if a _PRW object is found that points to this GPE.
272 type = ACPI_GPE_LEVEL_TRIGGERED;
276 type = ACPI_GPE_EDGE_TRIGGERED;
280 /* Unknown method type, just ignore it! */
282 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
283 "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n",
285 return_ACPI_STATUS(AE_OK);
288 /* Convert the last two characters of the name to the GPE Number */
290 gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
291 if (gpe_number == ACPI_UINT32_MAX) {
292 /* Conversion failed; invalid method, just ignore it */
294 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
295 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n",
297 return_ACPI_STATUS(AE_OK);
300 /* Ensure that we have a valid GPE number for this GPE block */
302 if ((gpe_number < gpe_block->block_base_number) ||
304 (gpe_block->block_base_number +
305 (gpe_block->register_count * 8)))) {
307 * Not valid for this GPE block, just ignore it
308 * However, it may be valid for a different GPE block, since GPE0 and GPE1
309 * methods both appear under \_GPE.
311 return_ACPI_STATUS(AE_OK);
315 * Now we can add this information to the gpe_event_info block
316 * for use during dispatch of this GPE. Default type is RUNTIME, although
317 * this may change when the _PRW methods are executed later.
320 &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
322 gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD |
323 ACPI_GPE_TYPE_RUNTIME);
325 gpe_event_info->dispatch.method_node =
326 (struct acpi_namespace_node *)obj_handle;
328 /* Update enable mask, but don't enable the HW GPE as of yet */
330 status = acpi_ev_enable_gpe(gpe_event_info, FALSE);
332 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
333 "Registered GPE method %s as GPE number 0x%.2X\n",
335 return_ACPI_STATUS(status);
338 /*******************************************************************************
340 * FUNCTION: acpi_ev_match_prw_and_gpe
342 * PARAMETERS: Callback from walk_namespace
344 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
345 * not aborted on a single _PRW failure.
347 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
348 * Device. Run the _PRW method. If present, extract the GPE
349 * number and mark the GPE as a WAKE GPE.
351 ******************************************************************************/
354 acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
355 u32 level, void *info, void **return_value)
357 struct acpi_gpe_walk_info *gpe_info = (void *)info;
358 struct acpi_namespace_node *gpe_device;
359 struct acpi_gpe_block_info *gpe_block;
360 struct acpi_namespace_node *target_gpe_device;
361 struct acpi_gpe_event_info *gpe_event_info;
362 union acpi_operand_object *pkg_desc;
363 union acpi_operand_object *obj_desc;
367 ACPI_FUNCTION_TRACE("ev_match_prw_and_gpe");
369 /* Check for a _PRW method under this device */
371 status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
372 ACPI_BTYPE_PACKAGE, &pkg_desc);
373 if (ACPI_FAILURE(status)) {
374 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
376 return_ACPI_STATUS(AE_OK);
379 /* The returned _PRW package must have at least two elements */
381 if (pkg_desc->package.count < 2) {
385 /* Extract pointers from the input context */
387 gpe_device = gpe_info->gpe_device;
388 gpe_block = gpe_info->gpe_block;
391 * The _PRW object must return a package, we are only interested
392 * in the first element
394 obj_desc = pkg_desc->package.elements[0];
396 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
397 /* Use FADT-defined GPE device (from definition of _PRW) */
399 target_gpe_device = acpi_gbl_fadt_gpe_device;
401 /* Integer is the GPE number in the FADT described GPE blocks */
403 gpe_number = (u32) obj_desc->integer.value;
404 } else if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
405 /* Package contains a GPE reference and GPE number within a GPE block */
407 if ((obj_desc->package.count < 2) ||
408 (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[0]) !=
409 ACPI_TYPE_LOCAL_REFERENCE)
410 || (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[1]) !=
411 ACPI_TYPE_INTEGER)) {
415 /* Get GPE block reference and decode */
418 obj_desc->package.elements[0]->reference.node;
419 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
421 /* Unknown type, just ignore it */
427 * Is this GPE within this block?
429 * TRUE iff these conditions are true:
430 * 1) The GPE devices match.
431 * 2) The GPE index(number) is within the range of the Gpe Block
432 * associated with the GPE device.
434 if ((gpe_device == target_gpe_device) &&
435 (gpe_number >= gpe_block->block_base_number) &&
437 gpe_block->block_base_number + (gpe_block->register_count * 8))) {
439 &gpe_block->event_info[gpe_number -
440 gpe_block->block_base_number];
442 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
444 gpe_event_info->flags &=
445 ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
447 acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
448 if (ACPI_FAILURE(status)) {
452 acpi_ev_update_gpe_enable_masks(gpe_event_info,
457 acpi_ut_remove_reference(pkg_desc);
458 return_ACPI_STATUS(AE_OK);
461 /*******************************************************************************
463 * FUNCTION: acpi_ev_get_gpe_xrupt_block
465 * PARAMETERS: interrupt_number - Interrupt for a GPE block
467 * RETURN: A GPE interrupt block
469 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
470 * block per unique interrupt level used for GPEs.
471 * Should be called only when the GPE lists are semaphore locked
472 * and not subject to change.
474 ******************************************************************************/
476 static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
479 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
480 struct acpi_gpe_xrupt_info *gpe_xrupt;
484 ACPI_FUNCTION_TRACE("ev_get_gpe_xrupt_block");
486 /* No need for lock since we are not changing any list elements here */
488 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
489 while (next_gpe_xrupt) {
490 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
491 return_PTR(next_gpe_xrupt);
494 next_gpe_xrupt = next_gpe_xrupt->next;
497 /* Not found, must allocate a new xrupt descriptor */
499 gpe_xrupt = ACPI_MEM_CALLOCATE(sizeof(struct acpi_gpe_xrupt_info));
504 gpe_xrupt->interrupt_number = interrupt_number;
506 /* Install new interrupt descriptor with spin lock */
508 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
509 if (acpi_gbl_gpe_xrupt_list_head) {
510 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
511 while (next_gpe_xrupt->next) {
512 next_gpe_xrupt = next_gpe_xrupt->next;
515 next_gpe_xrupt->next = gpe_xrupt;
516 gpe_xrupt->previous = next_gpe_xrupt;
518 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
520 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
522 /* Install new interrupt handler if not SCI_INT */
524 if (interrupt_number != acpi_gbl_FADT->sci_int) {
525 status = acpi_os_install_interrupt_handler(interrupt_number,
526 acpi_ev_gpe_xrupt_handler,
528 if (ACPI_FAILURE(status)) {
529 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
530 "Could not install GPE interrupt handler at level 0x%X\n",
536 return_PTR(gpe_xrupt);
539 /*******************************************************************************
541 * FUNCTION: acpi_ev_delete_gpe_xrupt
543 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
547 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
548 * interrupt handler if not the SCI interrupt.
550 ******************************************************************************/
553 acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
558 ACPI_FUNCTION_TRACE("ev_delete_gpe_xrupt");
560 /* We never want to remove the SCI interrupt handler */
562 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT->sci_int) {
563 gpe_xrupt->gpe_block_list_head = NULL;
564 return_ACPI_STATUS(AE_OK);
567 /* Disable this interrupt */
569 status = acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
570 acpi_ev_gpe_xrupt_handler);
571 if (ACPI_FAILURE(status)) {
572 return_ACPI_STATUS(status);
575 /* Unlink the interrupt block with lock */
577 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
578 if (gpe_xrupt->previous) {
579 gpe_xrupt->previous->next = gpe_xrupt->next;
582 if (gpe_xrupt->next) {
583 gpe_xrupt->next->previous = gpe_xrupt->previous;
585 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
589 ACPI_MEM_FREE(gpe_xrupt);
590 return_ACPI_STATUS(AE_OK);
593 /*******************************************************************************
595 * FUNCTION: acpi_ev_install_gpe_block
597 * PARAMETERS: gpe_block - New GPE block
598 * interrupt_number - Xrupt to be associated with this GPE block
602 * DESCRIPTION: Install new GPE block with mutex support
604 ******************************************************************************/
607 acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
608 u32 interrupt_number)
610 struct acpi_gpe_block_info *next_gpe_block;
611 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
615 ACPI_FUNCTION_TRACE("ev_install_gpe_block");
617 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
618 if (ACPI_FAILURE(status)) {
619 return_ACPI_STATUS(status);
622 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
623 if (!gpe_xrupt_block) {
624 status = AE_NO_MEMORY;
625 goto unlock_and_exit;
628 /* Install the new block at the end of the list with lock */
630 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
631 if (gpe_xrupt_block->gpe_block_list_head) {
632 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
633 while (next_gpe_block->next) {
634 next_gpe_block = next_gpe_block->next;
637 next_gpe_block->next = gpe_block;
638 gpe_block->previous = next_gpe_block;
640 gpe_xrupt_block->gpe_block_list_head = gpe_block;
643 gpe_block->xrupt_block = gpe_xrupt_block;
644 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
647 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
648 return_ACPI_STATUS(status);
651 /*******************************************************************************
653 * FUNCTION: acpi_ev_delete_gpe_block
655 * PARAMETERS: gpe_block - Existing GPE block
659 * DESCRIPTION: Remove a GPE block
661 ******************************************************************************/
663 acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
668 ACPI_FUNCTION_TRACE("ev_install_gpe_block");
670 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
671 if (ACPI_FAILURE(status)) {
672 return_ACPI_STATUS(status);
675 /* Disable all GPEs in this block */
677 status = acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block);
679 if (!gpe_block->previous && !gpe_block->next) {
680 /* This is the last gpe_block on this interrupt */
682 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
683 if (ACPI_FAILURE(status)) {
684 goto unlock_and_exit;
687 /* Remove the block on this interrupt with lock */
689 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
690 if (gpe_block->previous) {
691 gpe_block->previous->next = gpe_block->next;
693 gpe_block->xrupt_block->gpe_block_list_head =
697 if (gpe_block->next) {
698 gpe_block->next->previous = gpe_block->previous;
700 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
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);
714 /*******************************************************************************
716 * FUNCTION: acpi_ev_create_gpe_info_blocks
718 * PARAMETERS: gpe_block - New GPE block
722 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
724 ******************************************************************************/
727 acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
729 struct acpi_gpe_register_info *gpe_register_info = NULL;
730 struct acpi_gpe_event_info *gpe_event_info = NULL;
731 struct acpi_gpe_event_info *this_event;
732 struct acpi_gpe_register_info *this_register;
737 ACPI_FUNCTION_TRACE("ev_create_gpe_info_blocks");
739 /* Allocate the GPE register information block */
741 gpe_register_info = ACPI_MEM_CALLOCATE((acpi_size) gpe_block->
744 acpi_gpe_register_info));
745 if (!gpe_register_info) {
746 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
747 "Could not allocate the gpe_register_info table\n"));
748 return_ACPI_STATUS(AE_NO_MEMORY);
752 * Allocate the GPE event_info block. There are eight distinct GPEs
753 * per register. Initialization to zeros is sufficient.
755 gpe_event_info = ACPI_MEM_CALLOCATE(((acpi_size) gpe_block->
757 ACPI_GPE_REGISTER_WIDTH) *
758 sizeof(struct acpi_gpe_event_info));
759 if (!gpe_event_info) {
760 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
761 "Could not allocate the gpe_event_info table\n"));
762 status = AE_NO_MEMORY;
766 /* Save the new Info arrays in the GPE block */
768 gpe_block->register_info = gpe_register_info;
769 gpe_block->event_info = gpe_event_info;
772 * Initialize the GPE Register and Event structures. A goal of these
773 * tables is to hide the fact that there are two separate GPE register sets
774 * in a given gpe hardware block, the status registers occupy the first half,
775 * and the enable registers occupy the second half.
777 this_register = gpe_register_info;
778 this_event = gpe_event_info;
780 for (i = 0; i < gpe_block->register_count; i++) {
781 /* Init the register_info for this GPE register (8 GPEs) */
783 this_register->base_gpe_number =
784 (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 + i));
790 ACPI_STORE_ADDRESS(this_register->enable_address.address,
791 (gpe_block->block_address.address
792 + i + gpe_block->register_count));
794 this_register->status_address.address_space_id =
795 gpe_block->block_address.address_space_id;
796 this_register->enable_address.address_space_id =
797 gpe_block->block_address.address_space_id;
798 this_register->status_address.register_bit_width =
799 ACPI_GPE_REGISTER_WIDTH;
800 this_register->enable_address.register_bit_width =
801 ACPI_GPE_REGISTER_WIDTH;
802 this_register->status_address.register_bit_offset =
803 ACPI_GPE_REGISTER_WIDTH;
804 this_register->enable_address.register_bit_offset =
805 ACPI_GPE_REGISTER_WIDTH;
807 /* Init the event_info for each GPE within this register */
809 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
810 this_event->register_bit = acpi_gbl_decode_to8bit[j];
811 this_event->register_info = this_register;
816 * Clear the status/enable registers. Note that status registers
817 * are cleared by writing a '1', while enable registers are cleared
820 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0x00,
823 if (ACPI_FAILURE(status)) {
827 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0xFF,
830 if (ACPI_FAILURE(status)) {
837 return_ACPI_STATUS(AE_OK);
840 if (gpe_register_info) {
841 ACPI_MEM_FREE(gpe_register_info);
843 if (gpe_event_info) {
844 ACPI_MEM_FREE(gpe_event_info);
847 return_ACPI_STATUS(status);
850 /*******************************************************************************
852 * FUNCTION: acpi_ev_create_gpe_block
854 * PARAMETERS: gpe_device - Handle to the parent GPE block
855 * gpe_block_address - Address and space_iD
856 * register_count - Number of GPE register pairs in the block
857 * gpe_block_base_number - Starting GPE number for the block
858 * interrupt_number - H/W interrupt for the block
859 * return_gpe_block - Where the new block descriptor is returned
863 * DESCRIPTION: Create and Install a block of GPE registers
865 ******************************************************************************/
868 acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
869 struct acpi_generic_address *gpe_block_address,
871 u8 gpe_block_base_number,
872 u32 interrupt_number,
873 struct acpi_gpe_block_info **return_gpe_block)
875 struct acpi_gpe_block_info *gpe_block;
876 struct acpi_gpe_event_info *gpe_event_info;
880 u32 gpe_enabled_count;
882 struct acpi_gpe_walk_info gpe_info;
884 ACPI_FUNCTION_TRACE("ev_create_gpe_block");
886 if (!register_count) {
887 return_ACPI_STATUS(AE_OK);
890 /* Allocate a new GPE block */
892 gpe_block = ACPI_MEM_CALLOCATE(sizeof(struct acpi_gpe_block_info));
894 return_ACPI_STATUS(AE_NO_MEMORY);
897 /* Initialize the new GPE block */
899 gpe_block->register_count = register_count;
900 gpe_block->block_base_number = gpe_block_base_number;
901 gpe_block->node = gpe_device;
903 ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
904 sizeof(struct acpi_generic_address));
906 /* Create the register_info and event_info sub-structures */
908 status = acpi_ev_create_gpe_info_blocks(gpe_block);
909 if (ACPI_FAILURE(status)) {
910 ACPI_MEM_FREE(gpe_block);
911 return_ACPI_STATUS(status);
914 /* Install the new block in the global list(s) */
916 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
917 if (ACPI_FAILURE(status)) {
918 ACPI_MEM_FREE(gpe_block);
919 return_ACPI_STATUS(status);
922 /* Find all GPE methods (_Lxx, _Exx) for this block */
924 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
925 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
926 acpi_ev_save_method_info, gpe_block,
930 * Runtime option: Should Wake GPEs be enabled at runtime? The default
931 * is No, they should only be enabled just as the machine goes to sleep.
933 if (acpi_gbl_leave_wake_gpes_disabled) {
935 * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods.
936 * (Each GPE that has one or more _PRWs that reference it is by
937 * definition a WAKE GPE and will not be enabled while the machine
940 gpe_info.gpe_block = gpe_block;
941 gpe_info.gpe_device = gpe_device;
944 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
945 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
946 acpi_ev_match_prw_and_gpe, &gpe_info,
951 * Enable all GPEs in this block that are 1) "runtime" or "run/wake" GPEs,
952 * and 2) have a corresponding _Lxx or _Exx method. All other GPEs must
953 * be enabled via the acpi_enable_gpe() external interface.
956 gpe_enabled_count = 0;
958 for (i = 0; i < gpe_block->register_count; i++) {
959 for (j = 0; j < 8; j++) {
960 /* Get the info block for this particular GPE */
964 event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
966 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
967 ACPI_GPE_DISPATCH_METHOD)
969 flags & ACPI_GPE_TYPE_RUNTIME)) {
973 if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) {
979 /* Dump info about this GPE block */
981 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
982 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
983 (u32) gpe_block->block_base_number,
984 (u32) (gpe_block->block_base_number +
985 ((gpe_block->register_count *
986 ACPI_GPE_REGISTER_WIDTH) - 1)),
987 gpe_device->name.ascii, gpe_block->register_count,
990 /* Enable all valid GPEs found above */
992 status = acpi_hw_enable_runtime_gpe_block(NULL, gpe_block);
994 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
995 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
996 wake_gpe_count, gpe_enabled_count));
998 /* Return the new block */
1000 if (return_gpe_block) {
1001 (*return_gpe_block) = gpe_block;
1004 return_ACPI_STATUS(AE_OK);
1007 /*******************************************************************************
1009 * FUNCTION: acpi_ev_gpe_initialize
1015 * DESCRIPTION: Initialize the GPE data structures
1017 ******************************************************************************/
1019 acpi_status acpi_ev_gpe_initialize(void)
1021 u32 register_count0 = 0;
1022 u32 register_count1 = 0;
1023 u32 gpe_number_max = 0;
1026 ACPI_FUNCTION_TRACE("ev_gpe_initialize");
1028 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
1029 if (ACPI_FAILURE(status)) {
1030 return_ACPI_STATUS(status);
1034 * Initialize the GPE Block(s) defined in the FADT
1036 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1037 * section "General-Purpose Event Registers", we have:
1039 * "Each register block contains two registers of equal length
1040 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1041 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1042 * The length of the GPE1_STS and GPE1_EN registers is equal to
1043 * half the GPE1_LEN. If a generic register block is not supported
1044 * then its respective block pointer and block length values in the
1045 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1046 * to be the same size."
1050 * Determine the maximum GPE number for this machine.
1052 * Note: both GPE0 and GPE1 are optional, and either can exist without
1055 * If EITHER the register length OR the block address are zero, then that
1056 * particular block is not supported.
1058 if (acpi_gbl_FADT->gpe0_blk_len && acpi_gbl_FADT->xgpe0_blk.address) {
1059 /* GPE block 0 exists (has both length and address > 0) */
1061 register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2);
1064 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1066 /* Install GPE Block 0 */
1068 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
1069 &acpi_gbl_FADT->xgpe0_blk,
1071 acpi_gbl_FADT->sci_int,
1072 &acpi_gbl_gpe_fadt_blocks[0]);
1074 if (ACPI_FAILURE(status)) {
1075 ACPI_REPORT_ERROR(("Could not create GPE Block 0, %s\n",
1076 acpi_format_exception(status)));
1080 if (acpi_gbl_FADT->gpe1_blk_len && acpi_gbl_FADT->xgpe1_blk.address) {
1081 /* GPE block 1 exists (has both length and address > 0) */
1083 register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2);
1085 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1087 if ((register_count0) &&
1088 (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) {
1089 ACPI_REPORT_ERROR(("GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n", gpe_number_max, acpi_gbl_FADT->gpe1_base, acpi_gbl_FADT->gpe1_base + ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
1091 /* Ignore GPE1 block by setting the register count to zero */
1093 register_count1 = 0;
1095 /* Install GPE Block 1 */
1098 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
1099 &acpi_gbl_FADT->xgpe1_blk,
1101 acpi_gbl_FADT->gpe1_base,
1102 acpi_gbl_FADT->sci_int,
1103 &acpi_gbl_gpe_fadt_blocks
1106 if (ACPI_FAILURE(status)) {
1107 ACPI_REPORT_ERROR(("Could not create GPE Block 1, %s\n", acpi_format_exception(status)));
1111 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1112 * space. However, GPE0 always starts at GPE number zero.
1114 gpe_number_max = acpi_gbl_FADT->gpe1_base +
1115 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1119 /* Exit if there are no GPE registers */
1121 if ((register_count0 + register_count1) == 0) {
1122 /* GPEs are not required by ACPI, this is OK */
1124 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1125 "There are no GPE blocks defined in the FADT\n"));
1130 /* Check for Max GPE number out-of-range */
1132 if (gpe_number_max > ACPI_GPE_MAX) {
1133 ACPI_REPORT_ERROR(("Maximum GPE number from FADT is too large: 0x%X\n", gpe_number_max));
1134 status = AE_BAD_VALUE;
1139 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1140 return_ACPI_STATUS(AE_OK);