ACPICA 20050617-0624 from Bob Moore <robert.moore@intel.com>
[firewire-audio.git] / drivers / acpi / events / evgpeblk.c
blobdfc54692b1270033ec85495cba56bcd001eb67b9
1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 static acpi_status
54 acpi_ev_save_method_info (
55 acpi_handle obj_handle,
56 u32 level,
57 void *obj_desc,
58 void **return_value);
60 static acpi_status
61 acpi_ev_match_prw_and_gpe (
62 acpi_handle obj_handle,
63 u32 level,
64 void *info,
65 void **return_value);
67 static struct acpi_gpe_xrupt_info *
68 acpi_ev_get_gpe_xrupt_block (
69 u32 interrupt_number);
71 static acpi_status
72 acpi_ev_delete_gpe_xrupt (
73 struct acpi_gpe_xrupt_info *gpe_xrupt);
75 static acpi_status
76 acpi_ev_install_gpe_block (
77 struct acpi_gpe_block_info *gpe_block,
78 u32 interrupt_number);
80 static acpi_status
81 acpi_ev_create_gpe_info_blocks (
82 struct acpi_gpe_block_info *gpe_block);
85 /*******************************************************************************
87 * FUNCTION: acpi_ev_valid_gpe_event
89 * PARAMETERS: gpe_event_info - Info for this GPE
91 * RETURN: TRUE if the gpe_event is valid
93 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
94 * Should be called only when the GPE lists are semaphore locked
95 * and not subject to change.
97 ******************************************************************************/
100 acpi_ev_valid_gpe_event (
101 struct acpi_gpe_event_info *gpe_event_info)
103 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
104 struct acpi_gpe_block_info *gpe_block;
107 ACPI_FUNCTION_ENTRY ();
110 /* No need for spin lock since we are not changing any list elements */
112 /* Walk the GPE interrupt levels */
114 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
115 while (gpe_xrupt_block) {
116 gpe_block = gpe_xrupt_block->gpe_block_list_head;
118 /* Walk the GPE blocks on this interrupt level */
120 while (gpe_block) {
121 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
122 (&gpe_block->event_info[((acpi_size) gpe_block->register_count) * 8] > gpe_event_info)) {
123 return (TRUE);
126 gpe_block = gpe_block->next;
129 gpe_xrupt_block = gpe_xrupt_block->next;
132 return (FALSE);
136 /*******************************************************************************
138 * FUNCTION: acpi_ev_walk_gpe_list
140 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
142 * RETURN: Status
144 * DESCRIPTION: Walk the GPE lists.
146 ******************************************************************************/
148 acpi_status
149 acpi_ev_walk_gpe_list (
150 ACPI_GPE_CALLBACK gpe_walk_callback)
152 struct acpi_gpe_block_info *gpe_block;
153 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
154 acpi_status status = AE_OK;
155 u32 flags;
158 ACPI_FUNCTION_TRACE ("ev_walk_gpe_list");
161 flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock);
163 /* Walk the interrupt level descriptor list */
165 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
166 while (gpe_xrupt_info) {
167 /* Walk all Gpe Blocks attached to this interrupt level */
169 gpe_block = gpe_xrupt_info->gpe_block_list_head;
170 while (gpe_block) {
171 /* One callback per GPE block */
173 status = gpe_walk_callback (gpe_xrupt_info, gpe_block);
174 if (ACPI_FAILURE (status)) {
175 goto unlock_and_exit;
178 gpe_block = gpe_block->next;
181 gpe_xrupt_info = gpe_xrupt_info->next;
184 unlock_and_exit:
185 acpi_os_release_lock (acpi_gbl_gpe_lock, flags);
186 return_ACPI_STATUS (status);
190 /*******************************************************************************
192 * FUNCTION: acpi_ev_delete_gpe_handlers
194 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
195 * gpe_block - Gpe Block info
197 * RETURN: Status
199 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
200 * Used only prior to termination.
202 ******************************************************************************/
204 acpi_status
205 acpi_ev_delete_gpe_handlers (
206 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
207 struct acpi_gpe_block_info *gpe_block)
209 struct acpi_gpe_event_info *gpe_event_info;
210 acpi_native_uint i;
211 acpi_native_uint j;
214 ACPI_FUNCTION_TRACE ("ev_delete_gpe_handlers");
217 /* Examine each GPE Register within the block */
219 for (i = 0; i < gpe_block->register_count; i++) {
220 /* Now look at the individual GPEs in this byte register */
222 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
223 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
225 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
226 ACPI_GPE_DISPATCH_HANDLER) {
227 ACPI_MEM_FREE (gpe_event_info->dispatch.handler);
228 gpe_event_info->dispatch.handler = NULL;
229 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK;
234 return_ACPI_STATUS (AE_OK);
238 /*******************************************************************************
240 * FUNCTION: acpi_ev_save_method_info
242 * PARAMETERS: Callback from walk_namespace
244 * RETURN: Status
246 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
247 * control method under the _GPE portion of the namespace.
248 * Extract the name and GPE type from the object, saving this
249 * information for quick lookup during GPE dispatch
251 * The name of each GPE control method is of the form:
252 * "_Lxx" or "_Exx"
253 * Where:
254 * L - means that the GPE is level triggered
255 * E - means that the GPE is edge triggered
256 * xx - is the GPE number [in HEX]
258 ******************************************************************************/
260 static acpi_status
261 acpi_ev_save_method_info (
262 acpi_handle obj_handle,
263 u32 level,
264 void *obj_desc,
265 void **return_value)
267 struct acpi_gpe_block_info *gpe_block = (void *) obj_desc;
268 struct acpi_gpe_event_info *gpe_event_info;
269 u32 gpe_number;
270 char name[ACPI_NAME_SIZE + 1];
271 u8 type;
272 acpi_status status;
275 ACPI_FUNCTION_TRACE ("ev_save_method_info");
279 * _Lxx and _Exx GPE method support
281 * 1) Extract the name from the object and convert to a string
283 ACPI_MOVE_32_TO_32 (name,
284 &((struct acpi_namespace_node *) obj_handle)->name.integer);
285 name[ACPI_NAME_SIZE] = 0;
288 * 2) Edge/Level determination is based on the 2nd character
289 * of the method name
291 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
292 * if a _PRW object is found that points to this GPE.
294 switch (name[1]) {
295 case 'L':
296 type = ACPI_GPE_LEVEL_TRIGGERED;
297 break;
299 case 'E':
300 type = ACPI_GPE_EDGE_TRIGGERED;
301 break;
303 default:
304 /* Unknown method type, just ignore it! */
306 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
307 "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n",
308 name));
309 return_ACPI_STATUS (AE_OK);
312 /* Convert the last two characters of the name to the GPE Number */
314 gpe_number = ACPI_STRTOUL (&name[2], NULL, 16);
315 if (gpe_number == ACPI_UINT32_MAX) {
316 /* Conversion failed; invalid method, just ignore it */
318 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
319 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n",
320 name));
321 return_ACPI_STATUS (AE_OK);
324 /* Ensure that we have a valid GPE number for this GPE block */
326 if ((gpe_number < gpe_block->block_base_number) ||
327 (gpe_number >= (gpe_block->block_base_number + (gpe_block->register_count * 8)))) {
329 * Not valid for this GPE block, just ignore it
330 * However, it may be valid for a different GPE block, since GPE0 and GPE1
331 * methods both appear under \_GPE.
333 return_ACPI_STATUS (AE_OK);
337 * Now we can add this information to the gpe_event_info block
338 * for use during dispatch of this GPE. Default type is RUNTIME, although
339 * this may change when the _PRW methods are executed later.
341 gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
343 gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD |
344 ACPI_GPE_TYPE_RUNTIME);
346 gpe_event_info->dispatch.method_node = (struct acpi_namespace_node *) obj_handle;
348 /* Update enable mask, but don't enable the HW GPE as of yet */
350 status = acpi_ev_enable_gpe (gpe_event_info, FALSE);
352 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
353 "Registered GPE method %s as GPE number 0x%.2X\n",
354 name, gpe_number));
355 return_ACPI_STATUS (status);
359 /*******************************************************************************
361 * FUNCTION: acpi_ev_match_prw_and_gpe
363 * PARAMETERS: Callback from walk_namespace
365 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
366 * not aborted on a single _PRW failure.
368 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
369 * Device. Run the _PRW method. If present, extract the GPE
370 * number and mark the GPE as a WAKE GPE.
372 ******************************************************************************/
374 static acpi_status
375 acpi_ev_match_prw_and_gpe (
376 acpi_handle obj_handle,
377 u32 level,
378 void *info,
379 void **return_value)
381 struct acpi_gpe_walk_info *gpe_info = (void *) info;
382 struct acpi_namespace_node *gpe_device;
383 struct acpi_gpe_block_info *gpe_block;
384 struct acpi_namespace_node *target_gpe_device;
385 struct acpi_gpe_event_info *gpe_event_info;
386 union acpi_operand_object *pkg_desc;
387 union acpi_operand_object *obj_desc;
388 u32 gpe_number;
389 acpi_status status;
392 ACPI_FUNCTION_TRACE ("ev_match_prw_and_gpe");
395 /* Check for a _PRW method under this device */
397 status = acpi_ut_evaluate_object (obj_handle, METHOD_NAME__PRW,
398 ACPI_BTYPE_PACKAGE, &pkg_desc);
399 if (ACPI_FAILURE (status)) {
400 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
402 return_ACPI_STATUS (AE_OK);
405 /* The returned _PRW package must have at least two elements */
407 if (pkg_desc->package.count < 2) {
408 goto cleanup;
411 /* Extract pointers from the input context */
413 gpe_device = gpe_info->gpe_device;
414 gpe_block = gpe_info->gpe_block;
417 * The _PRW object must return a package, we are only interested
418 * in the first element
420 obj_desc = pkg_desc->package.elements[0];
422 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
423 /* Use FADT-defined GPE device (from definition of _PRW) */
425 target_gpe_device = acpi_gbl_fadt_gpe_device;
427 /* Integer is the GPE number in the FADT described GPE blocks */
429 gpe_number = (u32) obj_desc->integer.value;
431 else if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
432 /* Package contains a GPE reference and GPE number within a GPE block */
434 if ((obj_desc->package.count < 2) ||
435 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[0]) != ACPI_TYPE_LOCAL_REFERENCE) ||
436 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[1]) != ACPI_TYPE_INTEGER)) {
437 goto cleanup;
440 /* Get GPE block reference and decode */
442 target_gpe_device = obj_desc->package.elements[0]->reference.node;
443 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
445 else {
446 /* Unknown type, just ignore it */
448 goto cleanup;
452 * Is this GPE within this block?
454 * TRUE iff these conditions are true:
455 * 1) The GPE devices match.
456 * 2) The GPE index(number) is within the range of the Gpe Block
457 * associated with the GPE device.
459 if ((gpe_device == target_gpe_device) &&
460 (gpe_number >= gpe_block->block_base_number) &&
461 (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) {
462 gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
464 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
466 gpe_event_info->flags &= ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
467 status = acpi_ev_set_gpe_type (gpe_event_info, ACPI_GPE_TYPE_WAKE);
468 if (ACPI_FAILURE (status)) {
469 goto cleanup;
471 status = acpi_ev_update_gpe_enable_masks (gpe_event_info, ACPI_GPE_DISABLE);
474 cleanup:
475 acpi_ut_remove_reference (pkg_desc);
476 return_ACPI_STATUS (AE_OK);
480 /*******************************************************************************
482 * FUNCTION: acpi_ev_get_gpe_xrupt_block
484 * PARAMETERS: interrupt_number - Interrupt for a GPE block
486 * RETURN: A GPE interrupt block
488 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
489 * block per unique interrupt level used for GPEs.
490 * Should be called only when the GPE lists are semaphore locked
491 * and not subject to change.
493 ******************************************************************************/
495 static struct acpi_gpe_xrupt_info *
496 acpi_ev_get_gpe_xrupt_block (
497 u32 interrupt_number)
499 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
500 struct acpi_gpe_xrupt_info *gpe_xrupt;
501 acpi_status status;
502 u32 flags;
505 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block");
508 /* No need for lock since we are not changing any list elements here */
510 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
511 while (next_gpe_xrupt) {
512 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
513 return_PTR (next_gpe_xrupt);
516 next_gpe_xrupt = next_gpe_xrupt->next;
519 /* Not found, must allocate a new xrupt descriptor */
521 gpe_xrupt = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_xrupt_info));
522 if (!gpe_xrupt) {
523 return_PTR (NULL);
526 gpe_xrupt->interrupt_number = interrupt_number;
528 /* Install new interrupt descriptor with spin lock */
530 flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock);
531 if (acpi_gbl_gpe_xrupt_list_head) {
532 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
533 while (next_gpe_xrupt->next) {
534 next_gpe_xrupt = next_gpe_xrupt->next;
537 next_gpe_xrupt->next = gpe_xrupt;
538 gpe_xrupt->previous = next_gpe_xrupt;
540 else {
541 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
543 acpi_os_release_lock (acpi_gbl_gpe_lock, flags);
545 /* Install new interrupt handler if not SCI_INT */
547 if (interrupt_number != acpi_gbl_FADT->sci_int) {
548 status = acpi_os_install_interrupt_handler (interrupt_number,
549 acpi_ev_gpe_xrupt_handler, gpe_xrupt);
550 if (ACPI_FAILURE (status)) {
551 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
552 "Could not install GPE interrupt handler at level 0x%X\n",
553 interrupt_number));
554 return_PTR (NULL);
558 return_PTR (gpe_xrupt);
562 /*******************************************************************************
564 * FUNCTION: acpi_ev_delete_gpe_xrupt
566 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
568 * RETURN: Status
570 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
571 * interrupt handler if not the SCI interrupt.
573 ******************************************************************************/
575 static acpi_status
576 acpi_ev_delete_gpe_xrupt (
577 struct acpi_gpe_xrupt_info *gpe_xrupt)
579 acpi_status status;
580 u32 flags;
583 ACPI_FUNCTION_TRACE ("ev_delete_gpe_xrupt");
586 /* We never want to remove the SCI interrupt handler */
588 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT->sci_int) {
589 gpe_xrupt->gpe_block_list_head = NULL;
590 return_ACPI_STATUS (AE_OK);
593 /* Disable this interrupt */
595 status = acpi_os_remove_interrupt_handler (gpe_xrupt->interrupt_number,
596 acpi_ev_gpe_xrupt_handler);
597 if (ACPI_FAILURE (status)) {
598 return_ACPI_STATUS (status);
601 /* Unlink the interrupt block with lock */
603 flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock);
604 if (gpe_xrupt->previous) {
605 gpe_xrupt->previous->next = gpe_xrupt->next;
608 if (gpe_xrupt->next) {
609 gpe_xrupt->next->previous = gpe_xrupt->previous;
611 acpi_os_release_lock (acpi_gbl_gpe_lock, flags);
613 /* Free the block */
615 ACPI_MEM_FREE (gpe_xrupt);
616 return_ACPI_STATUS (AE_OK);
620 /*******************************************************************************
622 * FUNCTION: acpi_ev_install_gpe_block
624 * PARAMETERS: gpe_block - New GPE block
625 * interrupt_number - Xrupt to be associated with this GPE block
627 * RETURN: Status
629 * DESCRIPTION: Install new GPE block with mutex support
631 ******************************************************************************/
633 static acpi_status
634 acpi_ev_install_gpe_block (
635 struct acpi_gpe_block_info *gpe_block,
636 u32 interrupt_number)
638 struct acpi_gpe_block_info *next_gpe_block;
639 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
640 acpi_status status;
641 u32 flags;
644 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
647 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
648 if (ACPI_FAILURE (status)) {
649 return_ACPI_STATUS (status);
652 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block (interrupt_number);
653 if (!gpe_xrupt_block) {
654 status = AE_NO_MEMORY;
655 goto unlock_and_exit;
658 /* Install the new block at the end of the list with lock */
660 flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock);
661 if (gpe_xrupt_block->gpe_block_list_head) {
662 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
663 while (next_gpe_block->next) {
664 next_gpe_block = next_gpe_block->next;
667 next_gpe_block->next = gpe_block;
668 gpe_block->previous = next_gpe_block;
670 else {
671 gpe_xrupt_block->gpe_block_list_head = gpe_block;
674 gpe_block->xrupt_block = gpe_xrupt_block;
675 acpi_os_release_lock (acpi_gbl_gpe_lock, flags);
677 unlock_and_exit:
678 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
679 return_ACPI_STATUS (status);
683 /*******************************************************************************
685 * FUNCTION: acpi_ev_delete_gpe_block
687 * PARAMETERS: gpe_block - Existing GPE block
689 * RETURN: Status
691 * DESCRIPTION: Remove a GPE block
693 ******************************************************************************/
695 acpi_status
696 acpi_ev_delete_gpe_block (
697 struct acpi_gpe_block_info *gpe_block)
699 acpi_status status;
700 u32 flags;
703 ACPI_FUNCTION_TRACE ("ev_install_gpe_block");
706 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
707 if (ACPI_FAILURE (status)) {
708 return_ACPI_STATUS (status);
711 /* Disable all GPEs in this block */
713 status = acpi_hw_disable_gpe_block (gpe_block->xrupt_block, gpe_block);
715 if (!gpe_block->previous && !gpe_block->next) {
716 /* This is the last gpe_block on this interrupt */
718 status = acpi_ev_delete_gpe_xrupt (gpe_block->xrupt_block);
719 if (ACPI_FAILURE (status)) {
720 goto unlock_and_exit;
723 else {
724 /* Remove the block on this interrupt with lock */
726 flags = acpi_os_acquire_lock (acpi_gbl_gpe_lock);
727 if (gpe_block->previous) {
728 gpe_block->previous->next = gpe_block->next;
730 else {
731 gpe_block->xrupt_block->gpe_block_list_head = gpe_block->next;
734 if (gpe_block->next) {
735 gpe_block->next->previous = gpe_block->previous;
737 acpi_os_release_lock (acpi_gbl_gpe_lock, flags);
740 /* Free the gpe_block */
742 ACPI_MEM_FREE (gpe_block->register_info);
743 ACPI_MEM_FREE (gpe_block->event_info);
744 ACPI_MEM_FREE (gpe_block);
746 unlock_and_exit:
747 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
748 return_ACPI_STATUS (status);
752 /*******************************************************************************
754 * FUNCTION: acpi_ev_create_gpe_info_blocks
756 * PARAMETERS: gpe_block - New GPE block
758 * RETURN: Status
760 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
762 ******************************************************************************/
764 static acpi_status
765 acpi_ev_create_gpe_info_blocks (
766 struct acpi_gpe_block_info *gpe_block)
768 struct acpi_gpe_register_info *gpe_register_info = NULL;
769 struct acpi_gpe_event_info *gpe_event_info = NULL;
770 struct acpi_gpe_event_info *this_event;
771 struct acpi_gpe_register_info *this_register;
772 acpi_native_uint i;
773 acpi_native_uint j;
774 acpi_status status;
777 ACPI_FUNCTION_TRACE ("ev_create_gpe_info_blocks");
780 /* Allocate the GPE register information block */
782 gpe_register_info = ACPI_MEM_CALLOCATE (
783 (acpi_size) gpe_block->register_count *
784 sizeof (struct acpi_gpe_register_info));
785 if (!gpe_register_info) {
786 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
787 "Could not allocate the gpe_register_info table\n"));
788 return_ACPI_STATUS (AE_NO_MEMORY);
792 * Allocate the GPE event_info block. There are eight distinct GPEs
793 * per register. Initialization to zeros is sufficient.
795 gpe_event_info = ACPI_MEM_CALLOCATE (
796 ((acpi_size) gpe_block->register_count *
797 ACPI_GPE_REGISTER_WIDTH) *
798 sizeof (struct acpi_gpe_event_info));
799 if (!gpe_event_info) {
800 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
801 "Could not allocate the gpe_event_info table\n"));
802 status = AE_NO_MEMORY;
803 goto error_exit;
806 /* Save the new Info arrays in the GPE block */
808 gpe_block->register_info = gpe_register_info;
809 gpe_block->event_info = gpe_event_info;
812 * Initialize the GPE Register and Event structures. A goal of these
813 * tables is to hide the fact that there are two separate GPE register sets
814 * in a given gpe hardware block, the status registers occupy the first half,
815 * and the enable registers occupy the second half.
817 this_register = gpe_register_info;
818 this_event = gpe_event_info;
820 for (i = 0; i < gpe_block->register_count; i++) {
821 /* Init the register_info for this GPE register (8 GPEs) */
823 this_register->base_gpe_number = (u8) (gpe_block->block_base_number +
824 (i * ACPI_GPE_REGISTER_WIDTH));
826 ACPI_STORE_ADDRESS (this_register->status_address.address,
827 (gpe_block->block_address.address
828 + i));
830 ACPI_STORE_ADDRESS (this_register->enable_address.address,
831 (gpe_block->block_address.address
833 + gpe_block->register_count));
835 this_register->status_address.address_space_id = gpe_block->block_address.address_space_id;
836 this_register->enable_address.address_space_id = gpe_block->block_address.address_space_id;
837 this_register->status_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH;
838 this_register->enable_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH;
839 this_register->status_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH;
840 this_register->enable_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH;
842 /* Init the event_info for each GPE within this register */
844 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
845 this_event->register_bit = acpi_gbl_decode_to8bit[j];
846 this_event->register_info = this_register;
847 this_event++;
851 * Clear the status/enable registers. Note that status registers
852 * are cleared by writing a '1', while enable registers are cleared
853 * by writing a '0'.
855 status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0x00,
856 &this_register->enable_address);
857 if (ACPI_FAILURE (status)) {
858 goto error_exit;
861 status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0xFF,
862 &this_register->status_address);
863 if (ACPI_FAILURE (status)) {
864 goto error_exit;
867 this_register++;
870 return_ACPI_STATUS (AE_OK);
873 error_exit:
874 if (gpe_register_info) {
875 ACPI_MEM_FREE (gpe_register_info);
877 if (gpe_event_info) {
878 ACPI_MEM_FREE (gpe_event_info);
881 return_ACPI_STATUS (status);
885 /*******************************************************************************
887 * FUNCTION: acpi_ev_create_gpe_block
889 * PARAMETERS: gpe_device - Handle to the parent GPE block
890 * gpe_block_address - Address and space_iD
891 * register_count - Number of GPE register pairs in the block
892 * gpe_block_base_number - Starting GPE number for the block
893 * interrupt_number - H/W interrupt for the block
894 * return_gpe_block - Where the new block descriptor is returned
896 * RETURN: Status
898 * DESCRIPTION: Create and Install a block of GPE registers
900 ******************************************************************************/
902 acpi_status
903 acpi_ev_create_gpe_block (
904 struct acpi_namespace_node *gpe_device,
905 struct acpi_generic_address *gpe_block_address,
906 u32 register_count,
907 u8 gpe_block_base_number,
908 u32 interrupt_number,
909 struct acpi_gpe_block_info **return_gpe_block)
911 struct acpi_gpe_block_info *gpe_block;
912 struct acpi_gpe_event_info *gpe_event_info;
913 acpi_native_uint i;
914 acpi_native_uint j;
915 u32 wake_gpe_count;
916 u32 gpe_enabled_count;
917 acpi_status status;
918 struct acpi_gpe_walk_info gpe_info;
921 ACPI_FUNCTION_TRACE ("ev_create_gpe_block");
924 if (!register_count) {
925 return_ACPI_STATUS (AE_OK);
928 /* Allocate a new GPE block */
930 gpe_block = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_block_info));
931 if (!gpe_block) {
932 return_ACPI_STATUS (AE_NO_MEMORY);
935 /* Initialize the new GPE block */
937 gpe_block->register_count = register_count;
938 gpe_block->block_base_number = gpe_block_base_number;
939 gpe_block->node = gpe_device;
941 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address,
942 sizeof (struct acpi_generic_address));
944 /* Create the register_info and event_info sub-structures */
946 status = acpi_ev_create_gpe_info_blocks (gpe_block);
947 if (ACPI_FAILURE (status)) {
948 ACPI_MEM_FREE (gpe_block);
949 return_ACPI_STATUS (status);
952 /* Install the new block in the global list(s) */
954 status = acpi_ev_install_gpe_block (gpe_block, interrupt_number);
955 if (ACPI_FAILURE (status)) {
956 ACPI_MEM_FREE (gpe_block);
957 return_ACPI_STATUS (status);
960 /* Find all GPE methods (_Lxx, _Exx) for this block */
962 status = acpi_ns_walk_namespace (ACPI_TYPE_METHOD, gpe_device,
963 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, acpi_ev_save_method_info,
964 gpe_block, NULL);
967 * Runtime option: Should Wake GPEs be enabled at runtime? The default
968 * is No, they should only be enabled just as the machine goes to sleep.
970 if (acpi_gbl_leave_wake_gpes_disabled) {
972 * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods.
973 * (Each GPE that has one or more _PRWs that reference it is by
974 * definition a WAKE GPE and will not be enabled while the machine
975 * is running.)
977 gpe_info.gpe_block = gpe_block;
978 gpe_info.gpe_device = gpe_device;
980 status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
981 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ev_match_prw_and_gpe,
982 &gpe_info, NULL);
986 * Enable all GPEs in this block that are 1) "runtime" or "run/wake" GPEs,
987 * and 2) have a corresponding _Lxx or _Exx method. All other GPEs must
988 * be enabled via the acpi_enable_gpe() external interface.
990 wake_gpe_count = 0;
991 gpe_enabled_count = 0;
993 for (i = 0; i < gpe_block->register_count; i++) {
994 for (j = 0; j < 8; j++) {
995 /* Get the info block for this particular GPE */
997 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
999 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) &&
1000 (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
1001 gpe_enabled_count++;
1004 if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) {
1005 wake_gpe_count++;
1010 /* Dump info about this GPE block */
1012 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1013 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
1014 (u32) gpe_block->block_base_number,
1015 (u32) (gpe_block->block_base_number +
1016 ((gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) -1)),
1017 gpe_device->name.ascii,
1018 gpe_block->register_count,
1019 interrupt_number));
1021 /* Enable all valid GPEs found above */
1023 status = acpi_hw_enable_runtime_gpe_block (NULL, gpe_block);
1025 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1026 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1027 wake_gpe_count, gpe_enabled_count));
1029 /* Return the new block */
1031 if (return_gpe_block) {
1032 (*return_gpe_block) = gpe_block;
1035 return_ACPI_STATUS (AE_OK);
1039 /*******************************************************************************
1041 * FUNCTION: acpi_ev_gpe_initialize
1043 * PARAMETERS: None
1045 * RETURN: Status
1047 * DESCRIPTION: Initialize the GPE data structures
1049 ******************************************************************************/
1051 acpi_status
1052 acpi_ev_gpe_initialize (
1053 void)
1055 u32 register_count0 = 0;
1056 u32 register_count1 = 0;
1057 u32 gpe_number_max = 0;
1058 acpi_status status;
1061 ACPI_FUNCTION_TRACE ("ev_gpe_initialize");
1064 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
1065 if (ACPI_FAILURE (status)) {
1066 return_ACPI_STATUS (status);
1070 * Initialize the GPE Block(s) defined in the FADT
1072 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1073 * section "General-Purpose Event Registers", we have:
1075 * "Each register block contains two registers of equal length
1076 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1077 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1078 * The length of the GPE1_STS and GPE1_EN registers is equal to
1079 * half the GPE1_LEN. If a generic register block is not supported
1080 * then its respective block pointer and block length values in the
1081 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1082 * to be the same size."
1086 * Determine the maximum GPE number for this machine.
1088 * Note: both GPE0 and GPE1 are optional, and either can exist without
1089 * the other.
1091 * If EITHER the register length OR the block address are zero, then that
1092 * particular block is not supported.
1094 if (acpi_gbl_FADT->gpe0_blk_len &&
1095 acpi_gbl_FADT->xgpe0_blk.address) {
1096 /* GPE block 0 exists (has both length and address > 0) */
1098 register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2);
1100 gpe_number_max = (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1102 /* Install GPE Block 0 */
1104 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device,
1105 &acpi_gbl_FADT->xgpe0_blk, register_count0, 0,
1106 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]);
1108 if (ACPI_FAILURE (status)) {
1109 ACPI_REPORT_ERROR ((
1110 "Could not create GPE Block 0, %s\n",
1111 acpi_format_exception (status)));
1115 if (acpi_gbl_FADT->gpe1_blk_len &&
1116 acpi_gbl_FADT->xgpe1_blk.address) {
1117 /* GPE block 1 exists (has both length and address > 0) */
1119 register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2);
1121 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1123 if ((register_count0) &&
1124 (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) {
1125 ACPI_REPORT_ERROR ((
1126 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n",
1127 gpe_number_max, acpi_gbl_FADT->gpe1_base,
1128 acpi_gbl_FADT->gpe1_base +
1129 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
1131 /* Ignore GPE1 block by setting the register count to zero */
1133 register_count1 = 0;
1135 else {
1136 /* Install GPE Block 1 */
1138 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device,
1139 &acpi_gbl_FADT->xgpe1_blk, register_count1,
1140 acpi_gbl_FADT->gpe1_base,
1141 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]);
1143 if (ACPI_FAILURE (status)) {
1144 ACPI_REPORT_ERROR ((
1145 "Could not create GPE Block 1, %s\n",
1146 acpi_format_exception (status)));
1150 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1151 * space. However, GPE0 always starts at GPE number zero.
1153 gpe_number_max = acpi_gbl_FADT->gpe1_base +
1154 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1158 /* Exit if there are no GPE registers */
1160 if ((register_count0 + register_count1) == 0) {
1161 /* GPEs are not required by ACPI, this is OK */
1163 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1164 "There are no GPE blocks defined in the FADT\n"));
1165 status = AE_OK;
1166 goto cleanup;
1169 /* Check for Max GPE number out-of-range */
1171 if (gpe_number_max > ACPI_GPE_MAX) {
1172 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
1173 gpe_number_max));
1174 status = AE_BAD_VALUE;
1175 goto cleanup;
1178 cleanup:
1179 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
1180 return_ACPI_STATUS (AE_OK);