1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2010, 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>
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME("evgpeblk")
52 /* Local prototypes */
54 acpi_ev_match_gpe_method(acpi_handle obj_handle,
55 u32 level, void *obj_desc, void **return_value);
58 acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
59 u32 level, void *info, void **return_value);
61 static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
65 acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
68 acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
69 u32 interrupt_number);
72 acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
74 /*******************************************************************************
76 * FUNCTION: acpi_ev_valid_gpe_event
78 * PARAMETERS: gpe_event_info - Info for this GPE
80 * RETURN: TRUE if the gpe_event is valid
82 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
83 * Should be called only when the GPE lists are semaphore locked
84 * and not subject to change.
86 ******************************************************************************/
88 u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
90 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
91 struct acpi_gpe_block_info *gpe_block;
93 ACPI_FUNCTION_ENTRY();
95 /* No need for spin lock since we are not changing any list elements */
97 /* Walk the GPE interrupt levels */
99 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
100 while (gpe_xrupt_block) {
101 gpe_block = gpe_xrupt_block->gpe_block_list_head;
103 /* Walk the GPE blocks on this interrupt level */
106 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
107 (&gpe_block->event_info[gpe_block->gpe_count] >
112 gpe_block = gpe_block->next;
115 gpe_xrupt_block = gpe_xrupt_block->next;
121 /*******************************************************************************
123 * FUNCTION: acpi_ev_walk_gpe_list
125 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
126 * Context - Value passed to callback
130 * DESCRIPTION: Walk the GPE lists.
132 ******************************************************************************/
135 acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
137 struct acpi_gpe_block_info *gpe_block;
138 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
139 acpi_status status = AE_OK;
140 acpi_cpu_flags flags;
142 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
144 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
146 /* Walk the interrupt level descriptor list */
148 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
149 while (gpe_xrupt_info) {
151 /* Walk all Gpe Blocks attached to this interrupt level */
153 gpe_block = gpe_xrupt_info->gpe_block_list_head;
156 /* One callback per GPE block */
159 gpe_walk_callback(gpe_xrupt_info, gpe_block,
161 if (ACPI_FAILURE(status)) {
162 if (status == AE_CTRL_END) { /* Callback abort */
165 goto unlock_and_exit;
168 gpe_block = gpe_block->next;
171 gpe_xrupt_info = gpe_xrupt_info->next;
175 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
176 return_ACPI_STATUS(status);
179 /*******************************************************************************
181 * FUNCTION: acpi_ev_delete_gpe_handlers
183 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
184 * gpe_block - Gpe Block info
188 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
189 * Used only prior to termination.
191 ******************************************************************************/
194 acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
195 struct acpi_gpe_block_info *gpe_block,
198 struct acpi_gpe_event_info *gpe_event_info;
202 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
204 /* Examine each GPE Register within the block */
206 for (i = 0; i < gpe_block->register_count; i++) {
208 /* Now look at the individual GPEs in this byte register */
210 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
211 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
212 ACPI_GPE_REGISTER_WIDTH)
215 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
216 ACPI_GPE_DISPATCH_HANDLER) {
217 ACPI_FREE(gpe_event_info->dispatch.handler);
218 gpe_event_info->dispatch.handler = NULL;
219 gpe_event_info->flags &=
220 ~ACPI_GPE_DISPATCH_MASK;
225 return_ACPI_STATUS(AE_OK);
228 /*******************************************************************************
230 * FUNCTION: acpi_ev_match_gpe_method
232 * PARAMETERS: Callback from walk_namespace
236 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
237 * control method under the _GPE portion of the namespace.
238 * Extract the name and GPE type from the object, saving this
239 * information for quick lookup during GPE dispatch
241 * The name of each GPE control method is of the form:
242 * "_Lxx" or "_Exx", where:
243 * L - means that the GPE is level triggered
244 * E - means that the GPE is edge triggered
245 * xx - is the GPE number [in HEX]
247 ******************************************************************************/
250 acpi_ev_match_gpe_method(acpi_handle obj_handle,
251 u32 level, void *obj_desc, void **return_value)
253 struct acpi_namespace_node *method_node =
254 ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
255 struct acpi_gpe_block_info *gpe_block = (void *)obj_desc;
256 struct acpi_gpe_event_info *gpe_event_info;
258 char name[ACPI_NAME_SIZE + 1];
261 ACPI_FUNCTION_TRACE(ev_save_method_info);
264 * Match and decode the _Lxx and _Exx GPE method names
266 * 1) Extract the method name and null terminate it
268 ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
269 name[ACPI_NAME_SIZE] = 0;
271 /* 2) Name must begin with an underscore */
273 if (name[0] != '_') {
274 return_ACPI_STATUS(AE_OK); /* Ignore this method */
278 * 3) Edge/Level determination is based on the 2nd character
281 * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
282 * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
286 type = ACPI_GPE_LEVEL_TRIGGERED;
290 type = ACPI_GPE_EDGE_TRIGGERED;
294 /* Unknown method type, just ignore it */
296 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
297 "Ignoring unknown GPE method type: %s "
298 "(name not of form _Lxx or _Exx)", name));
299 return_ACPI_STATUS(AE_OK);
302 /* 4) The last two characters of the name are the hex GPE Number */
304 gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
305 if (gpe_number == ACPI_UINT32_MAX) {
307 /* Conversion failed; invalid method, just ignore it */
309 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
310 "Could not extract GPE number from name: %s "
311 "(name is not of form _Lxx or _Exx)", name));
312 return_ACPI_STATUS(AE_OK);
315 /* Ensure that we have a valid GPE number for this GPE block */
317 gpe_event_info = acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
318 if (!gpe_event_info) {
320 * This gpe_number is not valid for this GPE block, just ignore it.
321 * However, it may be valid for a different GPE block, since GPE0
322 * and GPE1 methods both appear under \_GPE.
324 return_ACPI_STATUS(AE_OK);
328 * Add the GPE information from above to the gpe_event_info block for
329 * use during dispatch of this GPE.
331 gpe_event_info->flags = (u8)(type | ACPI_GPE_DISPATCH_METHOD);
332 gpe_event_info->dispatch.method_node = method_node;
334 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
335 "Registered GPE method %s as GPE number 0x%.2X\n",
337 return_ACPI_STATUS(AE_OK);
340 /*******************************************************************************
342 * FUNCTION: acpi_ev_match_prw_and_gpe
344 * PARAMETERS: Callback from walk_namespace
346 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
347 * not aborted on a single _PRW failure.
349 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
350 * Device. Run the _PRW method. If present, extract the GPE
351 * number and mark the GPE as a CAN_WAKE GPE.
353 ******************************************************************************/
356 acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
357 u32 level, void *info, void **return_value)
359 struct acpi_gpe_walk_info *gpe_info = (void *)info;
360 struct acpi_namespace_node *gpe_device;
361 struct acpi_gpe_block_info *gpe_block;
362 struct acpi_namespace_node *target_gpe_device;
363 struct acpi_gpe_event_info *gpe_event_info;
364 union acpi_operand_object *pkg_desc;
365 union acpi_operand_object *obj_desc;
369 ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
371 /* Check for a _PRW method under this device */
373 status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
374 ACPI_BTYPE_PACKAGE, &pkg_desc);
375 if (ACPI_FAILURE(status)) {
377 /* Ignore all errors from _PRW, we don't want to abort the walk */
379 return_ACPI_STATUS(AE_OK);
382 /* The returned _PRW package must have at least two elements */
384 if (pkg_desc->package.count < 2) {
388 /* Extract pointers from the input context */
390 gpe_device = gpe_info->gpe_device;
391 gpe_block = gpe_info->gpe_block;
394 * The _PRW object must return a package, we are only interested in the
397 obj_desc = pkg_desc->package.elements[0];
399 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
401 /* Use FADT-defined GPE device (from definition of _PRW) */
403 target_gpe_device = acpi_gbl_fadt_gpe_device;
405 /* Integer is the GPE number in the FADT described GPE blocks */
407 gpe_number = (u32) obj_desc->integer.value;
408 } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
410 /* Package contains a GPE reference and GPE number within a GPE block */
412 if ((obj_desc->package.count < 2) ||
413 ((obj_desc->package.elements[0])->common.type !=
414 ACPI_TYPE_LOCAL_REFERENCE) ||
415 ((obj_desc->package.elements[1])->common.type !=
416 ACPI_TYPE_INTEGER)) {
420 /* Get GPE block reference and decode */
423 obj_desc->package.elements[0]->reference.node;
424 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
426 /* Unknown type, just ignore it */
432 * Is this GPE within this block?
434 * TRUE if and only if these conditions are true:
435 * 1) The GPE devices match.
436 * 2) The GPE index(number) is within the range of the Gpe Block
437 * associated with the GPE device.
439 if (gpe_device != target_gpe_device) {
443 gpe_event_info = acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
444 if (gpe_event_info) {
445 /* This GPE can wake the system */
447 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
451 acpi_ut_remove_reference(pkg_desc);
452 return_ACPI_STATUS(AE_OK);
455 /*******************************************************************************
457 * FUNCTION: acpi_ev_get_gpe_xrupt_block
459 * PARAMETERS: interrupt_number - Interrupt for a GPE block
461 * RETURN: A GPE interrupt block
463 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
464 * block per unique interrupt level used for GPEs. Should be
465 * called only when the GPE lists are semaphore locked and not
468 ******************************************************************************/
470 static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
473 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
474 struct acpi_gpe_xrupt_info *gpe_xrupt;
476 acpi_cpu_flags flags;
478 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
480 /* No need for lock since we are not changing any list elements here */
482 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
483 while (next_gpe_xrupt) {
484 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
485 return_PTR(next_gpe_xrupt);
488 next_gpe_xrupt = next_gpe_xrupt->next;
491 /* Not found, must allocate a new xrupt descriptor */
493 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
498 gpe_xrupt->interrupt_number = interrupt_number;
500 /* Install new interrupt descriptor with spin lock */
502 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
503 if (acpi_gbl_gpe_xrupt_list_head) {
504 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
505 while (next_gpe_xrupt->next) {
506 next_gpe_xrupt = next_gpe_xrupt->next;
509 next_gpe_xrupt->next = gpe_xrupt;
510 gpe_xrupt->previous = next_gpe_xrupt;
512 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
514 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
516 /* Install new interrupt handler if not SCI_INT */
518 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
519 status = acpi_os_install_interrupt_handler(interrupt_number,
520 acpi_ev_gpe_xrupt_handler,
522 if (ACPI_FAILURE(status)) {
524 "Could not install GPE interrupt handler at level 0x%X",
530 return_PTR(gpe_xrupt);
533 /*******************************************************************************
535 * FUNCTION: acpi_ev_delete_gpe_xrupt
537 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
541 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
542 * interrupt handler if not the SCI interrupt.
544 ******************************************************************************/
547 acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
550 acpi_cpu_flags flags;
552 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
554 /* We never want to remove the SCI interrupt handler */
556 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
557 gpe_xrupt->gpe_block_list_head = NULL;
558 return_ACPI_STATUS(AE_OK);
561 /* Disable this interrupt */
564 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
565 acpi_ev_gpe_xrupt_handler);
566 if (ACPI_FAILURE(status)) {
567 return_ACPI_STATUS(status);
570 /* Unlink the interrupt block with lock */
572 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
573 if (gpe_xrupt->previous) {
574 gpe_xrupt->previous->next = gpe_xrupt->next;
576 /* No previous, update list head */
578 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
581 if (gpe_xrupt->next) {
582 gpe_xrupt->next->previous = gpe_xrupt->previous;
584 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
588 ACPI_FREE(gpe_xrupt);
589 return_ACPI_STATUS(AE_OK);
592 /*******************************************************************************
594 * FUNCTION: acpi_ev_install_gpe_block
596 * PARAMETERS: gpe_block - New GPE block
597 * interrupt_number - Xrupt to be associated with this
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;
613 acpi_cpu_flags flags;
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)
666 acpi_cpu_flags flags;
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 */
678 acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
680 if (!gpe_block->previous && !gpe_block->next) {
682 /* This is the last gpe_block on this interrupt */
684 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
685 if (ACPI_FAILURE(status)) {
686 goto unlock_and_exit;
689 /* Remove the block on this interrupt with lock */
691 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
692 if (gpe_block->previous) {
693 gpe_block->previous->next = gpe_block->next;
695 gpe_block->xrupt_block->gpe_block_list_head =
699 if (gpe_block->next) {
700 gpe_block->next->previous = gpe_block->previous;
702 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
705 acpi_current_gpe_count -= gpe_block->gpe_count;
707 /* Free the gpe_block */
709 ACPI_FREE(gpe_block->register_info);
710 ACPI_FREE(gpe_block->event_info);
711 ACPI_FREE(gpe_block);
714 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
715 return_ACPI_STATUS(status);
718 /*******************************************************************************
720 * FUNCTION: acpi_ev_create_gpe_info_blocks
722 * PARAMETERS: gpe_block - New GPE block
726 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
728 ******************************************************************************/
731 acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
733 struct acpi_gpe_register_info *gpe_register_info = NULL;
734 struct acpi_gpe_event_info *gpe_event_info = NULL;
735 struct acpi_gpe_event_info *this_event;
736 struct acpi_gpe_register_info *this_register;
741 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
743 /* Allocate the GPE register information block */
745 gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
748 acpi_gpe_register_info));
749 if (!gpe_register_info) {
751 "Could not allocate the GpeRegisterInfo table"));
752 return_ACPI_STATUS(AE_NO_MEMORY);
756 * Allocate the GPE event_info block. There are eight distinct GPEs
757 * per register. Initialization to zeros is sufficient.
759 gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
761 acpi_gpe_event_info));
762 if (!gpe_event_info) {
764 "Could not allocate the GpeEventInfo table"));
765 status = AE_NO_MEMORY;
769 /* Save the new Info arrays in the GPE block */
771 gpe_block->register_info = gpe_register_info;
772 gpe_block->event_info = gpe_event_info;
775 * Initialize the GPE Register and Event structures. A goal of these
776 * tables is to hide the fact that there are two separate GPE register
777 * sets in a given GPE hardware block, the status registers occupy the
778 * first half, and the enable registers occupy the second half.
780 this_register = gpe_register_info;
781 this_event = gpe_event_info;
783 for (i = 0; i < gpe_block->register_count; i++) {
785 /* Init the register_info for this GPE register (8 GPEs) */
787 this_register->base_gpe_number =
788 (u8) (gpe_block->block_base_number +
789 (i * ACPI_GPE_REGISTER_WIDTH));
791 this_register->status_address.address =
792 gpe_block->block_address.address + i;
794 this_register->enable_address.address =
795 gpe_block->block_address.address + i +
796 gpe_block->register_count;
798 this_register->status_address.space_id =
799 gpe_block->block_address.space_id;
800 this_register->enable_address.space_id =
801 gpe_block->block_address.space_id;
802 this_register->status_address.bit_width =
803 ACPI_GPE_REGISTER_WIDTH;
804 this_register->enable_address.bit_width =
805 ACPI_GPE_REGISTER_WIDTH;
806 this_register->status_address.bit_offset = 0;
807 this_register->enable_address.bit_offset = 0;
809 /* Init the event_info for each GPE within this register */
811 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
812 this_event->gpe_number =
813 (u8) (this_register->base_gpe_number + j);
814 this_event->register_info = this_register;
818 /* Disable all GPEs within this register */
820 status = acpi_hw_write(0x00, &this_register->enable_address);
821 if (ACPI_FAILURE(status)) {
825 /* Clear any pending GPE events within this register */
827 status = acpi_hw_write(0xFF, &this_register->status_address);
828 if (ACPI_FAILURE(status)) {
835 return_ACPI_STATUS(AE_OK);
838 if (gpe_register_info) {
839 ACPI_FREE(gpe_register_info);
841 if (gpe_event_info) {
842 ACPI_FREE(gpe_event_info);
845 return_ACPI_STATUS(status);
848 /*******************************************************************************
850 * FUNCTION: acpi_ev_create_gpe_block
852 * PARAMETERS: gpe_device - Handle to the parent GPE block
853 * gpe_block_address - Address and space_iD
854 * register_count - Number of GPE register pairs in the block
855 * gpe_block_base_number - Starting GPE number for the block
856 * interrupt_number - H/W interrupt for the block
857 * return_gpe_block - Where the new block descriptor is returned
861 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
862 * the block are disabled at exit.
863 * Note: Assumes namespace is locked.
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)
876 struct acpi_gpe_block_info *gpe_block;
878 ACPI_FUNCTION_TRACE(ev_create_gpe_block);
880 if (!register_count) {
881 return_ACPI_STATUS(AE_OK);
884 /* Allocate a new GPE block */
886 gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
888 return_ACPI_STATUS(AE_NO_MEMORY);
891 /* Initialize the new GPE block */
893 gpe_block->node = gpe_device;
894 gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
895 gpe_block->register_count = register_count;
896 gpe_block->block_base_number = gpe_block_base_number;
898 ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
899 sizeof(struct acpi_generic_address));
902 * Create the register_info and event_info sub-structures
903 * Note: disables and clears all GPEs in the block
905 status = acpi_ev_create_gpe_info_blocks(gpe_block);
906 if (ACPI_FAILURE(status)) {
907 ACPI_FREE(gpe_block);
908 return_ACPI_STATUS(status);
911 /* Install the new block in the global lists */
913 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
914 if (ACPI_FAILURE(status)) {
915 ACPI_FREE(gpe_block);
916 return_ACPI_STATUS(status);
919 /* Find all GPE methods (_Lxx, _Exx) for this block */
921 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
922 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
923 acpi_ev_match_gpe_method, NULL,
926 /* Return the new block */
928 if (return_gpe_block) {
929 (*return_gpe_block) = gpe_block;
932 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
933 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
934 (u32) gpe_block->block_base_number,
935 (u32) (gpe_block->block_base_number +
936 (gpe_block->gpe_count - 1)),
937 gpe_device->name.ascii, gpe_block->register_count,
940 /* Update global count of currently available GPEs */
942 acpi_current_gpe_count += gpe_block->gpe_count;
943 return_ACPI_STATUS(AE_OK);
946 /*******************************************************************************
948 * FUNCTION: acpi_ev_initialize_gpe_block
950 * PARAMETERS: gpe_device - Handle to the parent GPE block
951 * gpe_block - Gpe Block info
955 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
956 * _PRT methods associated with the block, then enable the
958 * Note: Assumes namespace is locked.
960 ******************************************************************************/
963 acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
964 struct acpi_gpe_block_info *gpe_block)
967 struct acpi_gpe_event_info *gpe_event_info;
968 struct acpi_gpe_walk_info gpe_info;
970 u32 gpe_enabled_count;
976 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
978 /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
981 return_ACPI_STATUS(AE_OK);
985 * Runtime option: Should wake GPEs be enabled at runtime? The default
986 * is no, they should only be enabled just as the machine goes to sleep.
988 if (acpi_gbl_leave_wake_gpes_disabled) {
990 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
991 * Each GPE that has one or more _PRWs that reference it is by
992 * definition a wake GPE and will not be enabled while the machine
995 gpe_info.gpe_block = gpe_block;
996 gpe_info.gpe_device = gpe_device;
998 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
999 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
1000 acpi_ev_match_prw_and_gpe, NULL,
1002 if (ACPI_FAILURE(status)) {
1003 ACPI_EXCEPTION((AE_INFO, status,
1004 "While executing _PRW methods"));
1009 * Enable all GPEs that have a corresponding method and are not
1010 * capable of generating wakeups. Any other GPEs within this block
1011 * must be enabled via the acpi_enable_gpe interface.
1014 gpe_enabled_count = 0;
1016 if (gpe_device == acpi_gbl_fadt_gpe_device) {
1020 for (i = 0; i < gpe_block->register_count; i++) {
1021 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
1023 /* Get the info block for this particular GPE */
1025 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
1026 gpe_event_info = &gpe_block->event_info[gpe_index];
1028 if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
1030 if (acpi_gbl_leave_wake_gpes_disabled) {
1035 /* Ignore GPEs that have no corresponding _Lxx/_Exx method */
1037 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
1041 /* Enable this GPE */
1043 gpe_number = gpe_index + gpe_block->block_base_number;
1044 status = acpi_enable_gpe(gpe_device, gpe_number,
1045 ACPI_GPE_TYPE_RUNTIME);
1046 if (ACPI_FAILURE(status)) {
1047 ACPI_EXCEPTION((AE_INFO, status,
1048 "Could not enable GPE 0x%02X",
1053 gpe_enabled_count++;
1057 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1058 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1059 wake_gpe_count, gpe_enabled_count));
1061 return_ACPI_STATUS(AE_OK);
1064 /*******************************************************************************
1066 * FUNCTION: acpi_ev_gpe_initialize
1072 * DESCRIPTION: Initialize the GPE data structures
1074 ******************************************************************************/
1076 acpi_status acpi_ev_gpe_initialize(void)
1078 u32 register_count0 = 0;
1079 u32 register_count1 = 0;
1080 u32 gpe_number_max = 0;
1083 ACPI_FUNCTION_TRACE(ev_gpe_initialize);
1085 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
1086 if (ACPI_FAILURE(status)) {
1087 return_ACPI_STATUS(status);
1091 * Initialize the GPE Block(s) defined in the FADT
1093 * Why the GPE register block lengths are divided by 2: From the ACPI
1094 * Spec, section "General-Purpose Event Registers", we have:
1096 * "Each register block contains two registers of equal length
1097 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1098 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1099 * The length of the GPE1_STS and GPE1_EN registers is equal to
1100 * half the GPE1_LEN. If a generic register block is not supported
1101 * then its respective block pointer and block length values in the
1102 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1103 * to be the same size."
1107 * Determine the maximum GPE number for this machine.
1109 * Note: both GPE0 and GPE1 are optional, and either can exist without
1112 * If EITHER the register length OR the block address are zero, then that
1113 * particular block is not supported.
1115 if (acpi_gbl_FADT.gpe0_block_length &&
1116 acpi_gbl_FADT.xgpe0_block.address) {
1118 /* GPE block 0 exists (has both length and address > 0) */
1120 register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
1123 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1125 /* Install GPE Block 0 */
1127 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
1128 &acpi_gbl_FADT.xgpe0_block,
1130 acpi_gbl_FADT.sci_interrupt,
1131 &acpi_gbl_gpe_fadt_blocks[0]);
1133 if (ACPI_FAILURE(status)) {
1134 ACPI_EXCEPTION((AE_INFO, status,
1135 "Could not create GPE Block 0"));
1139 if (acpi_gbl_FADT.gpe1_block_length &&
1140 acpi_gbl_FADT.xgpe1_block.address) {
1142 /* GPE block 1 exists (has both length and address > 0) */
1144 register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
1146 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1148 if ((register_count0) &&
1149 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
1150 ACPI_ERROR((AE_INFO,
1151 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
1152 "(GPE %u to %u) - Ignoring GPE1",
1153 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1154 acpi_gbl_FADT.gpe1_base +
1156 ACPI_GPE_REGISTER_WIDTH) - 1)));
1158 /* Ignore GPE1 block by setting the register count to zero */
1160 register_count1 = 0;
1162 /* Install GPE Block 1 */
1165 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
1166 &acpi_gbl_FADT.xgpe1_block,
1168 acpi_gbl_FADT.gpe1_base,
1171 &acpi_gbl_gpe_fadt_blocks
1174 if (ACPI_FAILURE(status)) {
1175 ACPI_EXCEPTION((AE_INFO, status,
1176 "Could not create GPE Block 1"));
1180 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1181 * space. However, GPE0 always starts at GPE number zero.
1183 gpe_number_max = acpi_gbl_FADT.gpe1_base +
1184 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1188 /* Exit if there are no GPE registers */
1190 if ((register_count0 + register_count1) == 0) {
1192 /* GPEs are not required by ACPI, this is OK */
1194 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1195 "There are no GPE blocks defined in the FADT\n"));
1200 /* Check for Max GPE number out-of-range */
1202 if (gpe_number_max > ACPI_GPE_MAX) {
1203 ACPI_ERROR((AE_INFO,
1204 "Maximum GPE number from FADT is too large: 0x%X",
1206 status = AE_BAD_VALUE;
1211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1212 return_ACPI_STATUS(AE_OK);