1/****************************************************************************** 2 * 3 * Module Name: evevent - Fixed and General Purpose Acpi_event 4 * handling and dispatch 5 * $Revision: 1.1.1.1 $ 6 * 7 *****************************************************************************/ 8 9/* 10 * Copyright (C) 2000, 2001 R. Byron Moore 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 */ 26 27#include "acpi.h" 28#include "achware.h" 29#include "acevents.h" 30#include "acnamesp.h" 31 32#define _COMPONENT ACPI_EVENTS 33 MODULE_NAME ("evevent") 34 35 36/******************************************************************************* 37 * 38 * FUNCTION: Acpi_ev_initialize 39 * 40 * PARAMETERS: None 41 * 42 * RETURN: Status 43 * 44 * DESCRIPTION: Ensures that the system control interrupt (SCI) is properly 45 * configured, disables SCI event sources, installs the SCI 46 * handler 47 * 48 ******************************************************************************/ 49 50acpi_status 51acpi_ev_initialize ( 52 void) 53{ 54 acpi_status status; 55 56 57 FUNCTION_TRACE ("Ev_initialize"); 58 59 60 /* Make sure we have ACPI tables */ 61 62 if (!acpi_gbl_DSDT) { 63 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n")); 64 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 65 } 66 67 68 /* Make sure the BIOS supports ACPI mode */ 69 70 if (SYS_MODE_LEGACY == acpi_hw_get_mode_capabilities()) { 71 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "ACPI Mode is not supported!\n")); 72 return_ACPI_STATUS (AE_ERROR); 73 } 74 75 76 acpi_gbl_original_mode = acpi_hw_get_mode(); 77 78 /* 79 * Initialize the Fixed and General Purpose Acpi_events prior. This is 80 * done prior to enabling SCIs to prevent interrupts from occuring 81 * before handers are installed. 82 */ 83 status = acpi_ev_fixed_event_initialize (); 84 if (ACPI_FAILURE (status)) { 85 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL, "Unable to initialize fixed events.\n")); 86 return_ACPI_STATUS (status); 87 } 88 89 status = acpi_ev_gpe_initialize (); 90 if (ACPI_FAILURE (status)) { 91 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL, "Unable to initialize general purpose events.\n")); 92 return_ACPI_STATUS (status); 93 } 94 95 /* Install the SCI handler */ 96 97 status = acpi_ev_install_sci_handler (); 98 if (ACPI_FAILURE (status)) { 99 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL, "Unable to install System Control Interrupt Handler\n")); 100 return_ACPI_STATUS (status); 101 } 102 103 104 /* Install handlers for control method GPE handlers (_Lxx, _Exx) */ 105 106 status = acpi_ev_init_gpe_control_methods (); 107 if (ACPI_FAILURE (status)) { 108 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL, "Unable to initialize Gpe control methods\n")); 109 return_ACPI_STATUS (status); 110 } 111 112 /* Install the handler for the Global Lock */ 113 114 status = acpi_ev_init_global_lock_handler (); 115 if (ACPI_FAILURE (status)) { 116 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL, "Unable to initialize Global Lock handler\n")); 117 return_ACPI_STATUS (status); 118 } 119 120 121 return_ACPI_STATUS (status); 122} 123 124 125/******************************************************************************* 126 * 127 * FUNCTION: Acpi_ev_fixed_event_initialize 128 * 129 * PARAMETERS: None 130 * 131 * RETURN: Status 132 * 133 * DESCRIPTION: Initialize the Fixed Acpi_event data structures 134 * 135 ******************************************************************************/ 136 137acpi_status 138acpi_ev_fixed_event_initialize(void) 139{ 140 int i = 0; 141 142 /* Initialize the structure that keeps track of fixed event handlers */ 143 144 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { 145 acpi_gbl_fixed_event_handlers[i].handler = NULL; 146 acpi_gbl_fixed_event_handlers[i].context = NULL; 147 } 148 149 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, TMR_EN, 0); 150 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, GBL_EN, 0); 151 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, PWRBTN_EN, 0); 152 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, SLPBTN_EN, 0); 153 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, RTC_EN, 0); 154 155 return (AE_OK); 156} 157 158 159/******************************************************************************* 160 * 161 * FUNCTION: Acpi_ev_fixed_event_detect 162 * 163 * PARAMETERS: None 164 * 165 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 166 * 167 * DESCRIPTION: Checks the PM status register for fixed events 168 * 169 ******************************************************************************/ 170 171u32 172acpi_ev_fixed_event_detect (void) 173{ 174 u32 int_status = INTERRUPT_NOT_HANDLED; 175 u32 status_register; 176 u32 enable_register; 177 178 179 PROC_NAME ("Ev_fixed_event_detect"); 180 181 182 /* 183 * Read the fixed feature status and enable registers, as all the cases 184 * depend on their values. 185 */ 186 status_register = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, PM1_STS); 187 enable_register = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, PM1_EN); 188 189 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, 190 "Fixed Acpi_event Block: Enable %08X Status %08X\n", 191 enable_register, status_register)); 192 193 194 /* power management timer roll over */ 195 196 if ((status_register & ACPI_STATUS_PMTIMER) && 197 (enable_register & ACPI_ENABLE_PMTIMER)) { 198 int_status |= acpi_ev_fixed_event_dispatch (ACPI_EVENT_PMTIMER); 199 } 200 201 /* global event (BIOS wants the global lock) */ 202 203 if ((status_register & ACPI_STATUS_GLOBAL) && 204 (enable_register & ACPI_ENABLE_GLOBAL)) { 205 int_status |= acpi_ev_fixed_event_dispatch (ACPI_EVENT_GLOBAL); 206 } 207 208 /* power button event */ 209 210 if ((status_register & ACPI_STATUS_POWER_BUTTON) && 211 (enable_register & ACPI_ENABLE_POWER_BUTTON)) { 212 int_status |= acpi_ev_fixed_event_dispatch (ACPI_EVENT_POWER_BUTTON); 213 } 214 215 /* sleep button event */ 216 217 if ((status_register & ACPI_STATUS_SLEEP_BUTTON) && 218 (enable_register & ACPI_ENABLE_SLEEP_BUTTON)) { 219 int_status |= acpi_ev_fixed_event_dispatch (ACPI_EVENT_SLEEP_BUTTON); 220 } 221 222 return (int_status); 223} 224 225 226/******************************************************************************* 227 * 228 * FUNCTION: Acpi_ev_fixed_event_dispatch 229 * 230 * PARAMETERS: Event - Event type 231 * 232 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 233 * 234 * DESCRIPTION: Clears the status bit for the requested event, calls the 235 * handler that previously registered for the event. 236 * 237 ******************************************************************************/ 238 239u32 240acpi_ev_fixed_event_dispatch ( 241 u32 event) 242{ 243 u32 register_id; 244 245 246 FUNCTION_ENTRY (); 247 248 249 /* Clear the status bit */ 250 251 switch (event) { 252 case ACPI_EVENT_PMTIMER: 253 register_id = TMR_STS; 254 break; 255 256 case ACPI_EVENT_GLOBAL: 257 register_id = GBL_STS; 258 break; 259 260 case ACPI_EVENT_POWER_BUTTON: 261 register_id = PWRBTN_STS; 262 break; 263 264 case ACPI_EVENT_SLEEP_BUTTON: 265 register_id = SLPBTN_STS; 266 break; 267 268 case ACPI_EVENT_RTC: 269 register_id = RTC_STS; 270 break; 271 272 default: 273 return 0; 274 break; 275 } 276 277 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_DO_NOT_LOCK, register_id, 1); 278 279 /* 280 * Make sure we've got a handler. If not, report an error. 281 * The event is disabled to prevent further interrupts. 282 */ 283 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) { 284 register_id = (PM1_EN | REGISTER_BIT_ID(register_id)); 285 286 acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_DO_NOT_LOCK, 287 register_id, 0); 288 289 REPORT_ERROR ( 290 ("Ev_gpe_dispatch: No installed handler for fixed event [%08X]\n", 291 event)); 292 293 return (INTERRUPT_NOT_HANDLED); 294 } 295 296 /* Invoke the handler */ 297 298 return ((acpi_gbl_fixed_event_handlers[event].handler)( 299 acpi_gbl_fixed_event_handlers[event].context)); 300} 301 302 303/******************************************************************************* 304 * 305 * FUNCTION: Acpi_ev_gpe_initialize 306 * 307 * PARAMETERS: None 308 * 309 * RETURN: Status 310 * 311 * DESCRIPTION: Initialize the GPE data structures 312 * 313 ******************************************************************************/ 314 315acpi_status 316acpi_ev_gpe_initialize (void) 317{ 318 u32 i; 319 u32 j; 320 u32 register_index; 321 u32 gpe_number; 322 u16 gpe0register_count; 323 u16 gpe1_register_count; 324 325 326 FUNCTION_TRACE ("Ev_gpe_initialize"); 327 328 /* 329 * Set up various GPE counts 330 * 331 * You may ask,why are the GPE register block lengths divided by 2? 332 * From the ACPI 2.0 Spec, section, 4.7.1.6 General-Purpose Event 333 * Registers, we have, 334 * 335 * "Each register block contains two registers of equal length 336 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the 337 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN 338 * The length of the GPE1_STS and GPE1_EN registers is equal to 339 * half the GPE1_LEN. If a generic register block is not supported 340 * then its respective block pointer and block length values in the 341 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need 342 * to be the same size." 343 */ 344 gpe0register_count = (u16) DIV_2 (acpi_gbl_FADT->gpe0blk_len); 345 gpe1_register_count = (u16) DIV_2 (acpi_gbl_FADT->gpe1_blk_len); 346 acpi_gbl_gpe_register_count = gpe0register_count + gpe1_register_count; 347 348 if (!acpi_gbl_gpe_register_count) { 349 REPORT_WARNING (("Zero GPEs are defined in the FADT\n")); 350 return_ACPI_STATUS (AE_OK); 351 } 352 353 /* 354 * Allocate the Gpe information block 355 */ 356 acpi_gbl_gpe_registers = ACPI_MEM_CALLOCATE (acpi_gbl_gpe_register_count * 357 sizeof (acpi_gpe_registers)); 358 if (!acpi_gbl_gpe_registers) { 359 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 360 "Could not allocate the Gpe_registers block\n")); 361 return_ACPI_STATUS (AE_NO_MEMORY); 362 } 363 364 /* 365 * Allocate the Gpe dispatch handler block 366 * There are eight distinct GP events per register. 367 * Initialization to zeros is sufficient 368 */ 369 acpi_gbl_gpe_info = ACPI_MEM_CALLOCATE (MUL_8 (acpi_gbl_gpe_register_count) * 370 sizeof (acpi_gpe_level_info)); 371 if (!acpi_gbl_gpe_info) { 372 ACPI_MEM_FREE (acpi_gbl_gpe_registers); 373 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the Gpe_info block\n")); 374 return_ACPI_STATUS (AE_NO_MEMORY); 375 } 376 377 /* Set the Gpe validation table to GPE_INVALID */ 378 379 MEMSET (acpi_gbl_gpe_valid, (int) ACPI_GPE_INVALID, ACPI_NUM_GPE); 380 381 /* 382 * Initialize the Gpe information and validation blocks. A goal of these 383 * blocks is to hide the fact that there are two separate GPE register sets 384 * In a given block, the status registers occupy the first half, and 385 * the enable registers occupy the second half. 386 */ 387 388 /* GPE Block 0 */ 389 390 register_index = 0; 391 392 for (i = 0; i < gpe0register_count; i++) { 393 acpi_gbl_gpe_registers[register_index].status_addr = 394 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe0blk.address) + i); 395 396 acpi_gbl_gpe_registers[register_index].enable_addr = 397 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe0blk.address) + i + gpe0register_count); 398 399 acpi_gbl_gpe_registers[register_index].gpe_base = (u8) MUL_8 (i); 400 401 for (j = 0; j < 8; j++) { 402 gpe_number = acpi_gbl_gpe_registers[register_index].gpe_base + j; 403 acpi_gbl_gpe_valid[gpe_number] = (u8) register_index; 404 } 405 406 /* 407 * Clear the status/enable registers. Note that status registers 408 * are cleared by writing a '1', while enable registers are cleared 409 * by writing a '0'. 410 */ 411 acpi_os_write_port (acpi_gbl_gpe_registers[register_index].enable_addr, 0x00, 8); 412 acpi_os_write_port (acpi_gbl_gpe_registers[register_index].status_addr, 0xFF, 8); 413 414 register_index++; 415 } 416 417 /* GPE Block 1 */ 418 419 for (i = 0; i < gpe1_register_count; i++) { 420 acpi_gbl_gpe_registers[register_index].status_addr = 421 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe1_blk.address) + i); 422 423 acpi_gbl_gpe_registers[register_index].enable_addr = 424 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe1_blk.address) + i + gpe1_register_count); 425 426 acpi_gbl_gpe_registers[register_index].gpe_base = 427 (u8) (acpi_gbl_FADT->gpe1_base + MUL_8 (i)); 428 429 for (j = 0; j < 8; j++) { 430 gpe_number = acpi_gbl_gpe_registers[register_index].gpe_base + j; 431 acpi_gbl_gpe_valid[gpe_number] = (u8) register_index; 432 } 433 434 /* 435 * Clear the status/enable registers. Note that status registers 436 * are cleared by writing a '1', while enable registers are cleared 437 * by writing a '0'. 438 */ 439 acpi_os_write_port (acpi_gbl_gpe_registers[register_index].enable_addr, 0x00, 8); 440 acpi_os_write_port (acpi_gbl_gpe_registers[register_index].status_addr, 0xFF, 8); 441 442 register_index++; 443 } 444 445 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "GPE registers: %X@%8.8X%8.8X (Blk0) %X@%8.8X%8.8X (Blk1)\n", 446 gpe0register_count, HIDWORD(acpi_gbl_FADT->Xgpe0blk.address), LODWORD(acpi_gbl_FADT->Xgpe0blk.address), 447 gpe1_register_count, HIDWORD(acpi_gbl_FADT->Xgpe1_blk.address), LODWORD(acpi_gbl_FADT->Xgpe1_blk.address))); 448 449 return_ACPI_STATUS (AE_OK); 450} 451 452 453/******************************************************************************* 454 * 455 * FUNCTION: Acpi_ev_save_method_info 456 * 457 * PARAMETERS: None 458 * 459 * RETURN: None 460 * 461 * DESCRIPTION: Called from Acpi_walk_namespace. Expects each object to be a 462 * control method under the _GPE portion of the namespace. 463 * Extract the name and GPE type from the object, saving this 464 * information for quick lookup during GPE dispatch 465 * 466 * The name of each GPE control method is of the form: 467 * "_Lnn" or "_Enn" 468 * Where: 469 * L - means that the GPE is level triggered 470 * E - means that the GPE is edge triggered 471 * nn - is the GPE number 472 * 473 ******************************************************************************/ 474 475static acpi_status 476acpi_ev_save_method_info ( 477 acpi_handle obj_handle, 478 u32 level, 479 void *obj_desc, 480 void **return_value) 481{ 482 u32 gpe_number; 483 NATIVE_CHAR name[ACPI_NAME_SIZE + 1]; 484 u8 type; 485 486 487 PROC_NAME ("Ev_save_method_info"); 488 489 490 /* Extract the name from the object and convert to a string */ 491 492 MOVE_UNALIGNED32_TO_32 (name, &((acpi_namespace_node *) obj_handle)->name); 493 name[ACPI_NAME_SIZE] = 0; 494 495 /* 496 * Edge/Level determination is based on the 2nd s8 of the method name 497 */ 498 if (name[1] == 'L') { 499 type = ACPI_EVENT_LEVEL_TRIGGERED; 500 } 501 else if (name[1] == 'E') { 502 type = ACPI_EVENT_EDGE_TRIGGERED; 503 } 504 else { 505 /* Unknown method type, just ignore it! */ 506 507 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 508 "Unknown GPE method type: %s (name not of form _Lnn or _Enn)\n", 509 name)); 510 return (AE_OK); 511 } 512 513 /* Convert the last two characters of the name to the Gpe Number */ 514 515 gpe_number = STRTOUL (&name[2], NULL, 16); 516 if (gpe_number == ACPI_UINT32_MAX) { 517 /* Conversion failed; invalid method, just ignore it */ 518 519 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 520 "Could not extract GPE number from name: %s (name not of form _Lnn or _Enn)\n", 521 name)); 522 return (AE_OK); 523 } 524 525 /* Ensure that we have a valid GPE number */ 526 527 if (acpi_gbl_gpe_valid[gpe_number] == ACPI_GPE_INVALID) { 528 /* Not valid, all we can do here is ignore it */ 529 530 return (AE_OK); 531 } 532 533 /* 534 * Now we can add this information to the Gpe_info block 535 * for use during dispatch of this GPE. 536 */ 537 acpi_gbl_gpe_info [gpe_number].type = type; 538 acpi_gbl_gpe_info [gpe_number].method_handle = obj_handle; 539 540 541 /* 542 * Enable the GPE (SCIs should be disabled at this point) 543 */ 544 acpi_hw_enable_gpe (gpe_number); 545 546 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Registered GPE method %s as GPE number %X\n", 547 name, gpe_number)); 548 return (AE_OK); 549} 550 551 552/******************************************************************************* 553 * 554 * FUNCTION: Acpi_ev_init_gpe_control_methods 555 * 556 * PARAMETERS: None 557 * 558 * RETURN: None 559 * 560 * DESCRIPTION: Obtain the control methods associated with the GPEs. 561 * 562 * NOTE: Must be called AFTER namespace initialization! 563 * 564 ******************************************************************************/ 565 566acpi_status 567acpi_ev_init_gpe_control_methods (void) 568{ 569 acpi_status status; 570 571 572 FUNCTION_TRACE ("Ev_init_gpe_control_methods"); 573 574 575 /* Get a permanent handle to the _GPE object */ 576 577 status = acpi_get_handle (NULL, "\\_GPE", &acpi_gbl_gpe_obj_handle); 578 if (ACPI_FAILURE (status)) { 579 return_ACPI_STATUS (status); 580 } 581 582 /* Traverse the namespace under \_GPE to find all methods there */ 583 584 status = acpi_walk_namespace (ACPI_TYPE_METHOD, acpi_gbl_gpe_obj_handle, 585 ACPI_UINT32_MAX, acpi_ev_save_method_info, 586 NULL, NULL); 587 588 return_ACPI_STATUS (status); 589} 590 591 592/******************************************************************************* 593 * 594 * FUNCTION: Acpi_ev_gpe_detect 595 * 596 * PARAMETERS: None 597 * 598 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 599 * 600 * DESCRIPTION: Detect if any GP events have occurred 601 * 602 ******************************************************************************/ 603 604u32 605acpi_ev_gpe_detect (void) 606{ 607 u32 int_status = INTERRUPT_NOT_HANDLED; 608 u32 i; 609 u32 j; 610 u8 enabled_status_byte; 611 u8 bit_mask; 612 613 614 PROC_NAME ("Ev_gpe_detect"); 615 616 617 /* 618 * Read all of the 8-bit GPE status and enable registers 619 * in both of the register blocks, saving all of it. 620 * Find all currently active GP events. 621 */ 622 for (i = 0; i < acpi_gbl_gpe_register_count; i++) { 623 acpi_os_read_port (acpi_gbl_gpe_registers[i].status_addr, 624 &acpi_gbl_gpe_registers[i].status, 8); 625 626 acpi_os_read_port (acpi_gbl_gpe_registers[i].enable_addr, 627 &acpi_gbl_gpe_registers[i].enable, 8); 628 629 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, 630 "GPE block at %X - Enable %08X Status %08X\n", 631 acpi_gbl_gpe_registers[i].enable_addr, 632 acpi_gbl_gpe_registers[i].status, 633 acpi_gbl_gpe_registers[i].enable)); 634 635 /* First check if there is anything active at all in this register */ 636 637 enabled_status_byte = (u8) (acpi_gbl_gpe_registers[i].status & 638 acpi_gbl_gpe_registers[i].enable); 639 640 if (!enabled_status_byte) { 641 /* No active GPEs in this register, move on */ 642 643 continue; 644 } 645 646 /* Now look at the individual GPEs in this byte register */ 647 648 for (j = 0, bit_mask = 1; j < 8; j++, bit_mask <<= 1) { 649 /* Examine one GPE bit */ 650 651 if (enabled_status_byte & bit_mask) { 652 /* 653 * Found an active GPE. Dispatch the event to a handler 654 * or method. 655 */ 656 int_status |= acpi_ev_gpe_dispatch ( 657 acpi_gbl_gpe_registers[i].gpe_base + j); 658 } 659 } 660 } 661 662 return (int_status); 663} 664 665 666/******************************************************************************* 667 * 668 * FUNCTION: Acpi_ev_asynch_execute_gpe_method 669 * 670 * PARAMETERS: Gpe_number - The 0-based Gpe number 671 * 672 * RETURN: None 673 * 674 * DESCRIPTION: Perform the actual execution of a GPE control method. This 675 * function is called from an invocation of Acpi_os_queue_for_execution 676 * (and therefore does NOT execute at interrupt level) so that 677 * the control method itself is not executed in the context of 678 * the SCI interrupt handler. 679 * 680 ******************************************************************************/ 681 682static void 683acpi_ev_asynch_execute_gpe_method ( 684 void *context) 685{ 686 unsigned long gpe_number = (unsigned long) context; 687 acpi_gpe_level_info gpe_info; 688 689 690 FUNCTION_TRACE ("Ev_asynch_execute_gpe_method"); 691 692 /* 693 * Take a snapshot of the GPE info for this level 694 */ 695 acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); 696 gpe_info = acpi_gbl_gpe_info [gpe_number]; 697 acpi_ut_release_mutex (ACPI_MTX_EVENTS); 698 699 /* 700 * Method Handler (_Lxx, _Exx): 701 * ---------------------------- 702 * Evaluate the _Lxx/_Exx control method that corresponds to this GPE. 703 */ 704 if (gpe_info.method_handle) { 705 acpi_ns_evaluate_by_handle (gpe_info.method_handle, NULL, NULL); 706 } 707 708 /* 709 * Level-Triggered? 710 * ---------------- 711 * If level-triggered we clear the GPE status bit after handling the event. 712 */ 713 if (gpe_info.type & ACPI_EVENT_LEVEL_TRIGGERED) { 714 acpi_hw_clear_gpe (gpe_number); 715 } 716 717 /* 718 * Enable the GPE. 719 */ 720 acpi_hw_enable_gpe (gpe_number); 721 722 return_VOID; 723} 724 725 726/******************************************************************************* 727 * 728 * FUNCTION: Acpi_ev_gpe_dispatch 729 * 730 * PARAMETERS: Gpe_number - The 0-based Gpe number 731 * 732 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 733 * 734 * DESCRIPTION: Handle and dispatch a General Purpose Acpi_event. 735 * Clears the status bit for the requested event. 736 * 737 * TBD: [Investigate] is this still valid or necessary: 738 * The Gpe handler differs from the fixed events in that it clears the enable 739 * bit rather than the status bit to clear the interrupt. This allows 740 * software outside of interrupt context to determine what caused the SCI and 741 * dispatch the correct AML. 742 * 743 ******************************************************************************/ 744 745u32 746acpi_ev_gpe_dispatch ( 747 u32 gpe_number) 748{ 749 acpi_gpe_level_info gpe_info; 750 751 752 FUNCTION_TRACE ("Ev_gpe_dispatch"); 753 754 755 /* 756 * Valid GPE number? 757 */ 758 if (acpi_gbl_gpe_valid[gpe_number] == ACPI_GPE_INVALID) { 759 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid GPE bit [%X].\n", gpe_number)); 760 return_VALUE (INTERRUPT_NOT_HANDLED); 761 } 762 763 /* 764 * Disable the GPE. 765 */ 766 acpi_hw_disable_gpe (gpe_number); 767 768 gpe_info = acpi_gbl_gpe_info [gpe_number]; 769 770 /* 771 * Edge-Triggered? 772 * --------------- 773 * If edge-triggered, clear the GPE status bit now. Note that 774 * level-triggered events are cleared after the GPE is serviced. 775 */ 776 if (gpe_info.type & ACPI_EVENT_EDGE_TRIGGERED) { 777 acpi_hw_clear_gpe (gpe_number); 778 } 779 /* 780 * Function Handler (e.g. EC)? 781 */ 782 if (gpe_info.handler) { 783 /* Invoke function handler (at interrupt level). */ 784 785 gpe_info.handler (gpe_info.context); 786 787 /* Level-Triggered? */ 788 789 if (gpe_info.type & ACPI_EVENT_LEVEL_TRIGGERED) { 790 acpi_hw_clear_gpe (gpe_number); 791 } 792 793 /* Enable GPE */ 794 795 acpi_hw_enable_gpe (gpe_number); 796 } 797 798 /* 799 * Method Handler (e.g. _Exx/_Lxx)? 800 */ 801 else if (gpe_info.method_handle) { 802 if (ACPI_FAILURE(acpi_os_queue_for_execution (OSD_PRIORITY_GPE, 803 acpi_ev_asynch_execute_gpe_method, (void*) (u64)gpe_number))) { 804 /* 805 * Shoudn't occur, but if it does report an error. Note that 806 * the GPE will remain disabled until the ACPI Core Subsystem 807 * is restarted, or the handler is removed/reinstalled. 808 */ 809 REPORT_ERROR (("Acpi_ev_gpe_dispatch: Unable to queue handler for GPE bit [%X]\n", gpe_number)); 810 } 811 } 812 813 /* 814 * No Handler? Report an error and leave the GPE disabled. 815 */ 816 else { 817 REPORT_ERROR (("Acpi_ev_gpe_dispatch: No installed handler for GPE [%X]\n", gpe_number)); 818 819 /* Level-Triggered? */ 820 821 if (gpe_info.type & ACPI_EVENT_LEVEL_TRIGGERED) { 822 acpi_hw_clear_gpe (gpe_number); 823 } 824 } 825 826 return_VALUE (INTERRUPT_HANDLED); 827} 828