1 /****************************************************************************** 2 * 3 * Module Name: hwgpe - Low level GPE enable/disable/clear functions 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 *****************************************************************************/ 115 116 #include "acpi.h" 117 #include "accommon.h" 118 #include "acevents.h" 119 120 #define _COMPONENT ACPI_HARDWARE 121 ACPI_MODULE_NAME ("hwgpe") 122 123 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ 124 125 /* Local prototypes */ 126 127 static ACPI_STATUS 128 AcpiHwEnableWakeupGpeBlock ( 129 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 130 ACPI_GPE_BLOCK_INFO *GpeBlock, 131 void *Context); 132 133 134 /****************************************************************************** 135 * 136 * FUNCTION: AcpiHwGetGpeRegisterBit 137 * 138 * PARAMETERS: GpeEventInfo - Info block for the GPE 139 * 140 * RETURN: Register mask with a one in the GPE bit position 141 * 142 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the 143 * correct position for the input GPE. 144 * 145 ******************************************************************************/ 146 147 UINT32 148 AcpiHwGetGpeRegisterBit ( 149 ACPI_GPE_EVENT_INFO *GpeEventInfo) 150 { 151 152 return ((UINT32) 1 << 153 (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber)); 154 } 155 156 157 /****************************************************************************** 158 * 159 * FUNCTION: AcpiHwLowSetGpe 160 * 161 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled 162 * Action - Enable or disable 163 * 164 * RETURN: Status 165 * 166 * DESCRIPTION: Enable or disable a single GPE in the parent enable register. 167 * 168 ******************************************************************************/ 169 170 ACPI_STATUS 171 AcpiHwLowSetGpe ( 172 ACPI_GPE_EVENT_INFO *GpeEventInfo, 173 UINT32 Action) 174 { 175 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo; 176 ACPI_STATUS Status; 177 UINT32 EnableMask; 178 UINT32 RegisterBit; 179 180 181 ACPI_FUNCTION_ENTRY (); 182 183 184 /* Get the info block for the entire GPE register */ 185 186 GpeRegisterInfo = GpeEventInfo->RegisterInfo; 187 if (!GpeRegisterInfo) 188 { 189 return (AE_NOT_EXIST); 190 } 191 192 /* Get current value of the enable register that contains this GPE */ 193 194 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress); 195 if (ACPI_FAILURE (Status)) 196 { 197 return (Status); 198 } 199 200 /* Set or clear just the bit that corresponds to this GPE */ 201 202 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo); 203 switch (Action) 204 { 205 case ACPI_GPE_CONDITIONAL_ENABLE: 206 207 /* Only enable if the EnableForRun bit is set */ 208 209 if (!(RegisterBit & GpeRegisterInfo->EnableForRun)) 210 { 211 return (AE_BAD_PARAMETER); 212 } 213 214 /*lint -fallthrough */ 215 216 case ACPI_GPE_ENABLE: 217 218 ACPI_SET_BIT (EnableMask, RegisterBit); 219 break; 220 221 case ACPI_GPE_DISABLE: 222 223 ACPI_CLEAR_BIT (EnableMask, RegisterBit); 224 break; 225 226 default: 227 228 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action)); 229 return (AE_BAD_PARAMETER); 230 } 231 232 /* Write the updated enable mask */ 233 234 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress); 235 return (Status); 236 } 237 238 239 /****************************************************************************** 240 * 241 * FUNCTION: AcpiHwClearGpe 242 * 243 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared 244 * 245 * RETURN: Status 246 * 247 * DESCRIPTION: Clear the status bit for a single GPE. 248 * 249 ******************************************************************************/ 250 251 ACPI_STATUS 252 AcpiHwClearGpe ( 253 ACPI_GPE_EVENT_INFO *GpeEventInfo) 254 { 255 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo; 256 ACPI_STATUS Status; 257 UINT32 RegisterBit; 258 259 260 ACPI_FUNCTION_ENTRY (); 261 262 /* Get the info block for the entire GPE register */ 263 264 GpeRegisterInfo = GpeEventInfo->RegisterInfo; 265 if (!GpeRegisterInfo) 266 { 267 return (AE_NOT_EXIST); 268 } 269 270 /* 271 * Write a one to the appropriate bit in the status register to 272 * clear this GPE. 273 */ 274 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo); 275 276 Status = AcpiHwWrite (RegisterBit, 277 &GpeRegisterInfo->StatusAddress); 278 279 return (Status); 280 } 281 282 283 /****************************************************************************** 284 * 285 * FUNCTION: AcpiHwGetGpeStatus 286 * 287 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried 288 * EventStatus - Where the GPE status is returned 289 * 290 * RETURN: Status 291 * 292 * DESCRIPTION: Return the status of a single GPE. 293 * 294 ******************************************************************************/ 295 296 ACPI_STATUS 297 AcpiHwGetGpeStatus ( 298 ACPI_GPE_EVENT_INFO *GpeEventInfo, 299 ACPI_EVENT_STATUS *EventStatus) 300 { 301 UINT32 InByte; 302 UINT32 RegisterBit; 303 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo; 304 ACPI_EVENT_STATUS LocalEventStatus = 0; 305 ACPI_STATUS Status; 306 307 308 ACPI_FUNCTION_ENTRY (); 309 310 311 if (!EventStatus) 312 { 313 return (AE_BAD_PARAMETER); 314 } 315 316 /* Get the info block for the entire GPE register */ 317 318 GpeRegisterInfo = GpeEventInfo->RegisterInfo; 319 320 /* Get the register bitmask for this GPE */ 321 322 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo); 323 324 /* GPE currently enabled? (enabled for runtime?) */ 325 326 if (RegisterBit & GpeRegisterInfo->EnableForRun) 327 { 328 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED; 329 } 330 331 /* GPE enabled for wake? */ 332 333 if (RegisterBit & GpeRegisterInfo->EnableForWake) 334 { 335 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED; 336 } 337 338 /* GPE currently active (status bit == 1)? */ 339 340 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress); 341 if (ACPI_FAILURE (Status)) 342 { 343 return (Status); 344 } 345 346 if (RegisterBit & InByte) 347 { 348 LocalEventStatus |= ACPI_EVENT_FLAG_SET; 349 } 350 351 /* Set return value */ 352 353 (*EventStatus) = LocalEventStatus; 354 return (AE_OK); 355 } 356 357 358 /****************************************************************************** 359 * 360 * FUNCTION: AcpiHwDisableGpeBlock 361 * 362 * PARAMETERS: GpeXruptInfo - GPE Interrupt info 363 * GpeBlock - Gpe Block info 364 * 365 * RETURN: Status 366 * 367 * DESCRIPTION: Disable all GPEs within a single GPE block 368 * 369 ******************************************************************************/ 370 371 ACPI_STATUS 372 AcpiHwDisableGpeBlock ( 373 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 374 ACPI_GPE_BLOCK_INFO *GpeBlock, 375 void *Context) 376 { 377 UINT32 i; 378 ACPI_STATUS Status; 379 380 381 /* Examine each GPE Register within the block */ 382 383 for (i = 0; i < GpeBlock->RegisterCount; i++) 384 { 385 /* Disable all GPEs in this register */ 386 387 Status = AcpiHwWrite (0x00, &GpeBlock->RegisterInfo[i].EnableAddress); 388 if (ACPI_FAILURE (Status)) 389 { 390 return (Status); 391 } 392 } 393 394 return (AE_OK); 395 } 396 397 398 /****************************************************************************** 399 * 400 * FUNCTION: AcpiHwClearGpeBlock 401 * 402 * PARAMETERS: GpeXruptInfo - GPE Interrupt info 403 * GpeBlock - Gpe Block info 404 * 405 * RETURN: Status 406 * 407 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block 408 * 409 ******************************************************************************/ 410 411 ACPI_STATUS 412 AcpiHwClearGpeBlock ( 413 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 414 ACPI_GPE_BLOCK_INFO *GpeBlock, 415 void *Context) 416 { 417 UINT32 i; 418 ACPI_STATUS Status; 419 420 421 /* Examine each GPE Register within the block */ 422 423 for (i = 0; i < GpeBlock->RegisterCount; i++) 424 { 425 /* Clear status on all GPEs in this register */ 426 427 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress); 428 if (ACPI_FAILURE (Status)) 429 { 430 return (Status); 431 } 432 } 433 434 return (AE_OK); 435 } 436 437 438 /****************************************************************************** 439 * 440 * FUNCTION: AcpiHwEnableRuntimeGpeBlock 441 * 442 * PARAMETERS: GpeXruptInfo - GPE Interrupt info 443 * GpeBlock - Gpe Block info 444 * 445 * RETURN: Status 446 * 447 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes 448 * combination wake/run GPEs. 449 * 450 ******************************************************************************/ 451 452 ACPI_STATUS 453 AcpiHwEnableRuntimeGpeBlock ( 454 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 455 ACPI_GPE_BLOCK_INFO *GpeBlock, 456 void *Context) 457 { 458 UINT32 i; 459 ACPI_STATUS Status; 460 461 462 /* NOTE: assumes that all GPEs are currently disabled */ 463 464 /* Examine each GPE Register within the block */ 465 466 for (i = 0; i < GpeBlock->RegisterCount; i++) 467 { 468 if (!GpeBlock->RegisterInfo[i].EnableForRun) 469 { 470 continue; 471 } 472 473 /* Enable all "runtime" GPEs in this register */ 474 475 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForRun, 476 &GpeBlock->RegisterInfo[i].EnableAddress); 477 if (ACPI_FAILURE (Status)) 478 { 479 return (Status); 480 } 481 } 482 483 return (AE_OK); 484 } 485 486 487 /****************************************************************************** 488 * 489 * FUNCTION: AcpiHwEnableWakeupGpeBlock 490 * 491 * PARAMETERS: GpeXruptInfo - GPE Interrupt info 492 * GpeBlock - Gpe Block info 493 * 494 * RETURN: Status 495 * 496 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes 497 * combination wake/run GPEs. 498 * 499 ******************************************************************************/ 500 501 static ACPI_STATUS 502 AcpiHwEnableWakeupGpeBlock ( 503 ACPI_GPE_XRUPT_INFO *GpeXruptInfo, 504 ACPI_GPE_BLOCK_INFO *GpeBlock, 505 void *Context) 506 { 507 UINT32 i; 508 ACPI_STATUS Status; 509 510 511 /* Examine each GPE Register within the block */ 512 513 for (i = 0; i < GpeBlock->RegisterCount; i++) 514 { 515 if (!GpeBlock->RegisterInfo[i].EnableForWake) 516 { 517 continue; 518 } 519 520 /* Enable all "wake" GPEs in this register */ 521 522 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForWake, 523 &GpeBlock->RegisterInfo[i].EnableAddress); 524 if (ACPI_FAILURE (Status)) 525 { 526 return (Status); 527 } 528 } 529 530 return (AE_OK); 531 } 532 533 534 /****************************************************************************** 535 * 536 * FUNCTION: AcpiHwDisableAllGpes 537 * 538 * PARAMETERS: None 539 * 540 * RETURN: Status 541 * 542 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks 543 * 544 ******************************************************************************/ 545 546 ACPI_STATUS 547 AcpiHwDisableAllGpes ( 548 void) 549 { 550 ACPI_STATUS Status; 551 552 553 ACPI_FUNCTION_TRACE (HwDisableAllGpes); 554 555 556 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL); 557 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL); 558 return_ACPI_STATUS (Status); 559 } 560 561 562 /****************************************************************************** 563 * 564 * FUNCTION: AcpiHwEnableAllRuntimeGpes 565 * 566 * PARAMETERS: None 567 * 568 * RETURN: Status 569 * 570 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks 571 * 572 ******************************************************************************/ 573 574 ACPI_STATUS 575 AcpiHwEnableAllRuntimeGpes ( 576 void) 577 { 578 ACPI_STATUS Status; 579 580 581 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes); 582 583 584 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL); 585 return_ACPI_STATUS (Status); 586 } 587 588 589 /****************************************************************************** 590 * 591 * FUNCTION: AcpiHwEnableAllWakeupGpes 592 * 593 * PARAMETERS: None 594 * 595 * RETURN: Status 596 * 597 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks 598 * 599 ******************************************************************************/ 600 601 ACPI_STATUS 602 AcpiHwEnableAllWakeupGpes ( 603 void) 604 { 605 ACPI_STATUS Status; 606 607 608 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes); 609 610 611 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL); 612 return_ACPI_STATUS (Status); 613 } 614 615 #endif /* !ACPI_REDUCED_HARDWARE */ 616