1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, 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
111 * DESCRIPTION: Walk the GPE lists.
112 * FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
114 ******************************************************************************/
117 acpi_ev_walk_gpe_list (
118 ACPI_GPE_CALLBACK gpe_walk_callback)
120 struct acpi_gpe_block_info *gpe_block;
121 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
122 acpi_status status = AE_OK;
125 ACPI_FUNCTION_TRACE ("ev_walk_gpe_list");
128 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_ISR);
130 /* Walk the interrupt level descriptor list */
132 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
133 while (gpe_xrupt_info) {
134 /* Walk all Gpe Blocks attached to this interrupt level */
136 gpe_block = gpe_xrupt_info->gpe_block_list_head;
138 /* One callback per GPE block */
140 status = gpe_walk_callback (gpe_xrupt_info, gpe_block);
141 if (ACPI_FAILURE (status)) {
142 goto unlock_and_exit;
145 gpe_block = gpe_block->next;
148 gpe_xrupt_info = gpe_xrupt_info->next;
152 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_ISR);
153 return_ACPI_STATUS (status);
157 /*******************************************************************************
159 * FUNCTION: acpi_ev_save_method_info
161 * PARAMETERS: Callback from walk_namespace
165 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
166 * control method under the _GPE portion of the namespace.
167 * Extract the name and GPE type from the object, saving this
168 * information for quick lookup during GPE dispatch
170 * The name of each GPE control method is of the form:
173 * L - means that the GPE is level triggered
174 * E - means that the GPE is edge triggered
175 * xx - is the GPE number [in HEX]
177 ******************************************************************************/
180 acpi_ev_save_method_info (
181 acpi_handle obj_handle,
186 struct acpi_gpe_block_info *gpe_block = (void *) obj_desc;
187 struct acpi_gpe_event_info *gpe_event_info;
189 char name[ACPI_NAME_SIZE + 1];
193 ACPI_FUNCTION_TRACE ("ev_save_method_info");
197 * _Lxx and _Exx GPE method support
199 * 1) Extract the name from the object and convert to a string
201 ACPI_MOVE_32_TO_32 (name,
202 &((struct acpi_namespace_node *) obj_handle)->name.integer);
203 name[ACPI_NAME_SIZE] = 0;
206 * 2) Edge/Level determination is based on the 2nd character
209 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE if a
210 * _PRW object is found that points to this GPE.
214 type = ACPI_GPE_LEVEL_TRIGGERED | ACPI_GPE_TYPE_RUNTIME;
218 type = ACPI_GPE_EDGE_TRIGGERED | ACPI_GPE_TYPE_RUNTIME;
222 /* Unknown method type, just ignore it! */
224 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
225 "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n",
227 return_ACPI_STATUS (AE_OK);
230 /* Convert the last two characters of the name to the GPE Number */
232 gpe_number = ACPI_STRTOUL (&name[2], NULL, 16);
233 if (gpe_number == ACPI_UINT32_MAX) {
234 /* Conversion failed; invalid method, just ignore it */
236 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
237 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n",
239 return_ACPI_STATUS (AE_OK);
242 /* Ensure that we have a valid GPE number for this GPE block */
244 if ((gpe_number < gpe_block->block_base_number) ||
245 (gpe_number >= (gpe_block->block_base_number + (gpe_block->register_count * 8)))) {
247 * Not valid for this GPE block, just ignore it
248 * However, it may be valid for a different GPE block, since GPE0 and GPE1
249 * methods both appear under \_GPE.
251 return_ACPI_STATUS (AE_OK);
255 * Now we can add this information to the gpe_event_info block
256 * for use during dispatch of this GPE.
258 gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
260 gpe_event_info->flags = type;
261 gpe_event_info->method_node = (struct acpi_namespace_node *) obj_handle;
263 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
264 "Registered GPE method %s as GPE number 0x%.2X\n",
266 return_ACPI_STATUS (AE_OK);
270 /*******************************************************************************
272 * FUNCTION: acpi_ev_get_gpe_type
274 * PARAMETERS: Callback from walk_namespace
278 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
279 * Device. Run the _PRW method. If present, extract the GPE
280 * number and mark the GPE as a WAKE GPE.
282 ******************************************************************************/
285 acpi_ev_get_gpe_type (
286 acpi_handle obj_handle,
291 struct acpi_gpe_walk_info *gpe_info = (void *) info;
292 struct acpi_namespace_node *gpe_device;
293 struct acpi_gpe_block_info *gpe_block;
294 struct acpi_namespace_node *target_gpe_device;
295 struct acpi_gpe_event_info *gpe_event_info;
296 union acpi_operand_object *pkg_desc;
297 union acpi_operand_object *obj_desc;
302 ACPI_FUNCTION_TRACE ("ev_get_gpe_type");
305 /* Check for a _PRW method under this device */
307 status = acpi_ut_evaluate_object (obj_handle, METHOD_NAME__PRW,
308 ACPI_BTYPE_PACKAGE, &pkg_desc);
309 if (status == AE_NOT_FOUND) {
310 return_ACPI_STATUS (AE_OK);
312 else if (ACPI_FAILURE (status)) {
313 return_ACPI_STATUS (status);
316 /* The returned _PRW package must have at least two elements */
318 if (pkg_desc->package.count < 2) {
322 /* Extract pointers from the input context */
324 gpe_device = gpe_info->gpe_device;
325 gpe_block = gpe_info->gpe_block;
328 * The _PRW object must return a package, we are only interested
329 * in the first element
331 obj_desc = pkg_desc->package.elements[0];
333 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
334 /* Use FADT-defined GPE device (from definition of _PRW) */
336 target_gpe_device = acpi_gbl_fadt_gpe_device;
338 /* Integer is the GPE number in the FADT described GPE blocks */
340 gpe_number = (u32) obj_desc->integer.value;
342 else if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
343 /* Package contains a GPE reference and GPE number within a GPE block */
345 if ((obj_desc->package.count < 2) ||
346 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[0]) != ACPI_TYPE_LOCAL_REFERENCE) ||
347 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[1]) != ACPI_TYPE_INTEGER)) {
351 /* Get GPE block reference and decode */
353 target_gpe_device = obj_desc->package.elements[0]->reference.node;
354 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
357 /* Unknown type, just ignore it */
363 * Is this GPE within this block?
365 * TRUE iff these conditions are true:
366 * 1) The GPE devices match.
367 * 2) The GPE index(number) is within the range of the Gpe Block
368 * associated with the GPE device.
370 if ((gpe_device == target_gpe_device) &&
371 (gpe_number >= gpe_block->block_base_number) &&
372 (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) {
373 /* Mark GPE for WAKE but DISABLED (even for wake) */
375 gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
376 gpe_event_info->flags |= ACPI_GPE_TYPE_WAKE;
380 acpi_ut_remove_reference (pkg_desc);
382 return_ACPI_STATUS (status);
386 /*******************************************************************************
388 * FUNCTION: acpi_ev_get_gpe_xrupt_block
390 * PARAMETERS: interrupt_level - Interrupt for a GPE block
392 * RETURN: A GPE interrupt block
394 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
395 * block per unique interrupt level used for GPEs.
396 * Should be called only when the GPE lists are semaphore locked
397 * and not subject to change.
399 ******************************************************************************/
401 static struct acpi_gpe_xrupt_info *
402 acpi_ev_get_gpe_xrupt_block (
405 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
406 struct acpi_gpe_xrupt_info *gpe_xrupt;
410 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block");
413 /* No need for spin lock since we are not changing any list elements here */
415 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
416 while (next_gpe_xrupt) {
417 if (next_gpe_xrupt->interrupt_level == interrupt_level) {
418 return_PTR (next_gpe_xrupt);
421 next_gpe_xrupt = next_gpe_xrupt->next;
424 /* Not found, must allocate a new xrupt descriptor */
426 gpe_xrupt = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_xrupt_info));
431 gpe_xrupt->interrupt_level = interrupt_level;
433 /* Install new interrupt descriptor with spin lock */
435 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
436 if (acpi_gbl_gpe_xrupt_list_head) {
437 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
438 while (next_gpe_xrupt->next) {
439 next_gpe_xrupt = next_gpe_xrupt->next;
442 next_gpe_xrupt->next = gpe_xrupt;
443 gpe_xrupt->previous = next_gpe_xrupt;
446 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
448 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
450 /* Install new interrupt handler if not SCI_INT */
452 if (interrupt_level != acpi_gbl_FADT->sci_int) {
453 status = acpi_os_install_interrupt_handler (interrupt_level,
454 acpi_ev_gpe_xrupt_handler, gpe_xrupt);
455 if (ACPI_FAILURE (status)) {
456 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
457 "Could not install GPE interrupt handler at level 0x%X\n",
463 return_PTR (gpe_xrupt);
467 /*******************************************************************************
469 * FUNCTION: acpi_ev_delete_gpe_xrupt
471 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
475 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
476 * interrupt handler if not the SCI interrupt.
478 ******************************************************************************/
481 acpi_ev_delete_gpe_xrupt (
482 struct acpi_gpe_xrupt_info *gpe_xrupt)
487 ACPI_FUNCTION_TRACE ("ev_delete_gpe_xrupt");
490 /* We never want to remove the SCI interrupt handler */
492 if (gpe_xrupt->interrupt_level == acpi_gbl_FADT->sci_int) {
493 gpe_xrupt->gpe_block_list_head = NULL;
494 return_ACPI_STATUS (AE_OK);
497 /* Disable this interrupt */
499 status = acpi_os_remove_interrupt_handler (gpe_xrupt->interrupt_level,
500 acpi_ev_gpe_xrupt_handler);
501 if (ACPI_FAILURE (status)) {
502 return_ACPI_STATUS (status);
505 /* Unlink the interrupt block with lock */
507 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
508 if (gpe_xrupt->previous) {
509 gpe_xrupt->previous->next = gpe_xrupt->next;
512 if (gpe_xrupt->next) {
513 gpe_xrupt->next->previous = gpe_xrupt->previous;
515 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
519 ACPI_MEM_FREE (gpe_xrupt);
520 return_ACPI_STATUS (AE_OK);
524 /*******************************************************************************
526 * FUNCTION: acpi_ev_install_gpe_block
528 * PARAMETERS: gpe_block - New GPE block
529 * interrupt_level - Level to be associated with this GPE block
533 * DESCRIPTION: Install new GPE block with mutex support
535 ******************************************************************************/
538 acpi_ev_install_gpe_block (
539 struct acpi_gpe_block_info *gpe_block,
542 struct acpi_gpe_block_info *next_gpe_block;
543 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
547 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
550 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
551 if (ACPI_FAILURE (status)) {
552 return_ACPI_STATUS (status);
555 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block (interrupt_level);
556 if (!gpe_xrupt_block) {
557 status = AE_NO_MEMORY;
558 goto unlock_and_exit;
561 /* Install the new block at the end of the list for this interrupt with lock */
563 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
564 if (gpe_xrupt_block->gpe_block_list_head) {
565 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
566 while (next_gpe_block->next) {
567 next_gpe_block = next_gpe_block->next;
570 next_gpe_block->next = gpe_block;
571 gpe_block->previous = next_gpe_block;
574 gpe_xrupt_block->gpe_block_list_head = gpe_block;
577 gpe_block->xrupt_block = gpe_xrupt_block;
578 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
581 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
582 return_ACPI_STATUS (status);
586 /*******************************************************************************
588 * FUNCTION: acpi_ev_delete_gpe_block
590 * PARAMETERS: gpe_block - Existing GPE block
594 * DESCRIPTION: Remove a GPE block
596 ******************************************************************************/
599 acpi_ev_delete_gpe_block (
600 struct acpi_gpe_block_info *gpe_block)
605 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
608 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
609 if (ACPI_FAILURE (status)) {
610 return_ACPI_STATUS (status);
613 /* Disable all GPEs in this block */
615 status = acpi_hw_disable_gpe_block (gpe_block->xrupt_block, gpe_block);
617 if (!gpe_block->previous && !gpe_block->next) {
618 /* This is the last gpe_block on this interrupt */
620 status = acpi_ev_delete_gpe_xrupt (gpe_block->xrupt_block);
621 if (ACPI_FAILURE (status)) {
622 goto unlock_and_exit;
626 /* Remove the block on this interrupt with lock */
628 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
629 if (gpe_block->previous) {
630 gpe_block->previous->next = gpe_block->next;
633 gpe_block->xrupt_block->gpe_block_list_head = gpe_block->next;
636 if (gpe_block->next) {
637 gpe_block->next->previous = gpe_block->previous;
639 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
642 /* Free the gpe_block */
644 ACPI_MEM_FREE (gpe_block->register_info);
645 ACPI_MEM_FREE (gpe_block->event_info);
646 ACPI_MEM_FREE (gpe_block);
649 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
650 return_ACPI_STATUS (status);
654 /*******************************************************************************
656 * FUNCTION: acpi_ev_create_gpe_info_blocks
658 * PARAMETERS: gpe_block - New GPE block
662 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
664 ******************************************************************************/
667 acpi_ev_create_gpe_info_blocks (
668 struct acpi_gpe_block_info *gpe_block)
670 struct acpi_gpe_register_info *gpe_register_info = NULL;
671 struct acpi_gpe_event_info *gpe_event_info = NULL;
672 struct acpi_gpe_event_info *this_event;
673 struct acpi_gpe_register_info *this_register;
679 ACPI_FUNCTION_TRACE ("ev_create_gpe_info_blocks");
682 /* Allocate the GPE register information block */
684 gpe_register_info = ACPI_MEM_CALLOCATE (
685 (acpi_size) gpe_block->register_count *
686 sizeof (struct acpi_gpe_register_info));
687 if (!gpe_register_info) {
688 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
689 "Could not allocate the gpe_register_info table\n"));
690 return_ACPI_STATUS (AE_NO_MEMORY);
694 * Allocate the GPE event_info block. There are eight distinct GPEs
695 * per register. Initialization to zeros is sufficient.
697 gpe_event_info = ACPI_MEM_CALLOCATE (
698 ((acpi_size) gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) *
699 sizeof (struct acpi_gpe_event_info));
700 if (!gpe_event_info) {
701 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the gpe_event_info table\n"));
702 status = AE_NO_MEMORY;
706 /* Save the new Info arrays in the GPE block */
708 gpe_block->register_info = gpe_register_info;
709 gpe_block->event_info = gpe_event_info;
712 * Initialize the GPE Register and Event structures. A goal of these
713 * tables is to hide the fact that there are two separate GPE register sets
714 * in a given gpe hardware block, the status registers occupy the first half,
715 * and the enable registers occupy the second half.
717 this_register = gpe_register_info;
718 this_event = gpe_event_info;
720 for (i = 0; i < gpe_block->register_count; i++) {
721 /* Init the register_info for this GPE register (8 GPEs) */
723 this_register->base_gpe_number = (u8) (gpe_block->block_base_number +
724 (i * ACPI_GPE_REGISTER_WIDTH));
726 ACPI_STORE_ADDRESS (this_register->status_address.address,
727 (gpe_block->block_address.address
730 ACPI_STORE_ADDRESS (this_register->enable_address.address,
731 (gpe_block->block_address.address
733 + gpe_block->register_count));
735 this_register->status_address.address_space_id = gpe_block->block_address.address_space_id;
736 this_register->enable_address.address_space_id = gpe_block->block_address.address_space_id;
737 this_register->status_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH;
738 this_register->enable_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH;
739 this_register->status_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH;
740 this_register->enable_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH;
742 /* Init the event_info for each GPE within this register */
744 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
745 this_event->bit_mask = acpi_gbl_decode_to8bit[j];
746 this_event->register_info = this_register;
751 * Clear the status/enable registers. Note that status registers
752 * are cleared by writing a '1', while enable registers are cleared
755 status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0x00,
756 &this_register->enable_address);
757 if (ACPI_FAILURE (status)) {
761 status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0xFF,
762 &this_register->status_address);
763 if (ACPI_FAILURE (status)) {
770 return_ACPI_STATUS (AE_OK);
774 if (gpe_register_info) {
775 ACPI_MEM_FREE (gpe_register_info);
777 if (gpe_event_info) {
778 ACPI_MEM_FREE (gpe_event_info);
781 return_ACPI_STATUS (status);
785 /*******************************************************************************
787 * FUNCTION: acpi_ev_create_gpe_block
789 * PARAMETERS: gpe_device - Handle to the parent GPE block
790 * gpe_block_address - Address and space_iD
791 * register_count - Number of GPE register pairs in the block
792 * gpe_block_base_number - Starting GPE number for the block
793 * interrupt_level - H/W interrupt for the block
794 * return_gpe_block - Where the new block descriptor is returned
798 * DESCRIPTION: Create and Install a block of GPE registers
800 ******************************************************************************/
803 acpi_ev_create_gpe_block (
804 struct acpi_namespace_node *gpe_device,
805 struct acpi_generic_address *gpe_block_address,
807 u8 gpe_block_base_number,
809 struct acpi_gpe_block_info **return_gpe_block)
811 struct acpi_gpe_block_info *gpe_block;
812 struct acpi_gpe_event_info *gpe_event_info;
816 u32 gpe_enabled_count;
818 struct acpi_gpe_walk_info gpe_info;
820 ACPI_FUNCTION_TRACE ("ev_create_gpe_block");
823 if (!register_count) {
824 return_ACPI_STATUS (AE_OK);
827 /* Allocate a new GPE block */
829 gpe_block = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_block_info));
831 return_ACPI_STATUS (AE_NO_MEMORY);
834 /* Initialize the new GPE block */
836 gpe_block->register_count = register_count;
837 gpe_block->block_base_number = gpe_block_base_number;
839 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address, sizeof (struct acpi_generic_address));
841 /* Create the register_info and event_info sub-structures */
843 status = acpi_ev_create_gpe_info_blocks (gpe_block);
844 if (ACPI_FAILURE (status)) {
845 ACPI_MEM_FREE (gpe_block);
846 return_ACPI_STATUS (status);
849 /* Install the new block in the global list(s) */
851 status = acpi_ev_install_gpe_block (gpe_block, interrupt_level);
852 if (ACPI_FAILURE (status)) {
853 ACPI_MEM_FREE (gpe_block);
854 return_ACPI_STATUS (status);
857 /* Dump info about this GPE block */
859 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
860 "GPE %02d to %02d [%4.4s] %d regs at %8.8X%8.8X on int %d\n",
861 gpe_block->block_base_number,
862 (u32) (gpe_block->block_base_number +
863 ((gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) -1)),
864 gpe_device->name.ascii,
865 gpe_block->register_count,
866 ACPI_FORMAT_UINT64 (gpe_block->block_address.address),
869 /* Find all GPE methods (_Lxx, _Exx) for this block */
871 status = acpi_ns_walk_namespace (ACPI_TYPE_METHOD, gpe_device,
872 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, acpi_ev_save_method_info,
876 * Runtime option: Should Wake GPEs be enabled at runtime? The default is
877 * No,they should only be enabled just as the machine goes to sleep.
879 if (acpi_gbl_leave_wake_gpes_disabled) {
881 * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods. (Each
882 * GPE that has one or more _PRWs that reference it is by definition a
883 * WAKE GPE and will not be enabled while the machine is running.)
885 gpe_info.gpe_block = gpe_block;
886 gpe_info.gpe_device = gpe_device;
888 status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
889 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ev_get_gpe_type,
894 * Enable all GPEs in this block that are 1) "runtime" GPEs, and 2) have
895 * a corresponding _Lxx or _Exx method. All other GPEs must be enabled via
896 * the acpi_enable_gpe() external interface.
899 gpe_enabled_count = 0;
901 for (i = 0; i < gpe_block->register_count; i++) {
902 for (j = 0; j < 8; j++) {
903 /* Get the info block for this particular GPE */
905 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
906 if ((gpe_event_info->method_node) &&
907 ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == ACPI_GPE_TYPE_RUNTIME)) {
908 /* Enable this GPE, it is 1) RUNTIME and 2) has an _Lxx or _Exx method */
910 status = acpi_hw_enable_gpe (gpe_event_info);
911 if (ACPI_FAILURE (status)) {
912 return_ACPI_STATUS (status);
917 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == ACPI_GPE_TYPE_WAKE) {
923 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
924 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
925 wake_gpe_count, gpe_enabled_count));
927 /* Return the new block */
929 if (return_gpe_block) {
930 (*return_gpe_block) = gpe_block;
933 return_ACPI_STATUS (AE_OK);
937 /*******************************************************************************
939 * FUNCTION: acpi_ev_gpe_initialize
945 * DESCRIPTION: Initialize the GPE data structures
947 ******************************************************************************/
950 acpi_ev_gpe_initialize (
953 u32 register_count0 = 0;
954 u32 register_count1 = 0;
955 u32 gpe_number_max = 0;
959 ACPI_FUNCTION_TRACE ("ev_gpe_initialize");
962 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
963 if (ACPI_FAILURE (status)) {
964 return_ACPI_STATUS (status);
968 * Initialize the GPE Block(s) defined in the FADT
970 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
971 * section "General-Purpose Event Registers", we have:
973 * "Each register block contains two registers of equal length
974 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
975 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
976 * The length of the GPE1_STS and GPE1_EN registers is equal to
977 * half the GPE1_LEN. If a generic register block is not supported
978 * then its respective block pointer and block length values in the
979 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
980 * to be the same size."
984 * Determine the maximum GPE number for this machine.
986 * Note: both GPE0 and GPE1 are optional, and either can exist without
989 * If EITHER the register length OR the block address are zero, then that
990 * particular block is not supported.
992 if (acpi_gbl_FADT->gpe0_blk_len &&
993 acpi_gbl_FADT->xgpe0_blk.address) {
994 /* GPE block 0 exists (has both length and address > 0) */
996 register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2);
998 gpe_number_max = (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1000 /* Install GPE Block 0 */
1002 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe0_blk,
1003 register_count0, 0, acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]);
1005 if (ACPI_FAILURE (status)) {
1006 ACPI_REPORT_ERROR ((
1007 "Could not create GPE Block 0, %s\n",
1008 acpi_format_exception (status)));
1012 if (acpi_gbl_FADT->gpe1_blk_len &&
1013 acpi_gbl_FADT->xgpe1_blk.address) {
1014 /* GPE block 1 exists (has both length and address > 0) */
1016 register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2);
1018 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1020 if ((register_count0) &&
1021 (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) {
1022 ACPI_REPORT_ERROR ((
1023 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n",
1024 gpe_number_max, acpi_gbl_FADT->gpe1_base,
1025 acpi_gbl_FADT->gpe1_base +
1026 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
1028 /* Ignore GPE1 block by setting the register count to zero */
1030 register_count1 = 0;
1033 /* Install GPE Block 1 */
1035 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe1_blk,
1036 register_count1, acpi_gbl_FADT->gpe1_base,
1037 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]);
1039 if (ACPI_FAILURE (status)) {
1040 ACPI_REPORT_ERROR ((
1041 "Could not create GPE Block 1, %s\n",
1042 acpi_format_exception (status)));
1046 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1047 * space. However, GPE0 always starts at GPE number zero.
1049 gpe_number_max = acpi_gbl_FADT->gpe1_base +
1050 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1054 /* Exit if there are no GPE registers */
1056 if ((register_count0 + register_count1) == 0) {
1057 /* GPEs are not required by ACPI, this is OK */
1059 ACPI_REPORT_INFO (("There are no GPE blocks defined in the FADT\n"));
1064 /* Check for Max GPE number out-of-range */
1066 if (gpe_number_max > ACPI_GPE_MAX) {
1067 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
1069 status = AE_BAD_VALUE;
1074 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
1075 return_ACPI_STATUS (AE_OK);