Bob Moore | 3fe5020 | 2010-04-27 11:41:19 +0800 | [diff] [blame^] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evgpeinit - System GPE initialization and update |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2010, Intel Corp. |
| 9 | * All rights reserved. |
| 10 | * |
| 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. |
| 25 | * |
| 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. |
| 29 | * |
| 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. |
| 42 | */ |
| 43 | |
| 44 | #include <acpi/acpi.h> |
| 45 | #include "accommon.h" |
| 46 | #include "acevents.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "acinterp.h" |
| 49 | |
| 50 | #define _COMPONENT ACPI_EVENTS |
| 51 | ACPI_MODULE_NAME("evgpeinit") |
| 52 | |
| 53 | /******************************************************************************* |
| 54 | * |
| 55 | * FUNCTION: acpi_ev_gpe_initialize |
| 56 | * |
| 57 | * PARAMETERS: None |
| 58 | * |
| 59 | * RETURN: Status |
| 60 | * |
| 61 | * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks |
| 62 | * |
| 63 | ******************************************************************************/ |
| 64 | acpi_status acpi_ev_gpe_initialize(void) |
| 65 | { |
| 66 | u32 register_count0 = 0; |
| 67 | u32 register_count1 = 0; |
| 68 | u32 gpe_number_max = 0; |
| 69 | acpi_status status; |
| 70 | |
| 71 | ACPI_FUNCTION_TRACE(ev_gpe_initialize); |
| 72 | |
| 73 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 74 | if (ACPI_FAILURE(status)) { |
| 75 | return_ACPI_STATUS(status); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Initialize the GPE Block(s) defined in the FADT |
| 80 | * |
| 81 | * Why the GPE register block lengths are divided by 2: From the ACPI |
| 82 | * Spec, section "General-Purpose Event Registers", we have: |
| 83 | * |
| 84 | * "Each register block contains two registers of equal length |
| 85 | * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the |
| 86 | * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN |
| 87 | * The length of the GPE1_STS and GPE1_EN registers is equal to |
| 88 | * half the GPE1_LEN. If a generic register block is not supported |
| 89 | * then its respective block pointer and block length values in the |
| 90 | * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need |
| 91 | * to be the same size." |
| 92 | */ |
| 93 | |
| 94 | /* |
| 95 | * Determine the maximum GPE number for this machine. |
| 96 | * |
| 97 | * Note: both GPE0 and GPE1 are optional, and either can exist without |
| 98 | * the other. |
| 99 | * |
| 100 | * If EITHER the register length OR the block address are zero, then that |
| 101 | * particular block is not supported. |
| 102 | */ |
| 103 | if (acpi_gbl_FADT.gpe0_block_length && |
| 104 | acpi_gbl_FADT.xgpe0_block.address) { |
| 105 | |
| 106 | /* GPE block 0 exists (has both length and address > 0) */ |
| 107 | |
| 108 | register_count0 = (u16)(acpi_gbl_FADT.gpe0_block_length / 2); |
| 109 | |
| 110 | gpe_number_max = |
| 111 | (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1; |
| 112 | |
| 113 | /* Install GPE Block 0 */ |
| 114 | |
| 115 | status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device, |
| 116 | &acpi_gbl_FADT.xgpe0_block, |
| 117 | register_count0, 0, |
| 118 | acpi_gbl_FADT.sci_interrupt, |
| 119 | &acpi_gbl_gpe_fadt_blocks[0]); |
| 120 | |
| 121 | if (ACPI_FAILURE(status)) { |
| 122 | ACPI_EXCEPTION((AE_INFO, status, |
| 123 | "Could not create GPE Block 0")); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if (acpi_gbl_FADT.gpe1_block_length && |
| 128 | acpi_gbl_FADT.xgpe1_block.address) { |
| 129 | |
| 130 | /* GPE block 1 exists (has both length and address > 0) */ |
| 131 | |
| 132 | register_count1 = (u16)(acpi_gbl_FADT.gpe1_block_length / 2); |
| 133 | |
| 134 | /* Check for GPE0/GPE1 overlap (if both banks exist) */ |
| 135 | |
| 136 | if ((register_count0) && |
| 137 | (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) { |
| 138 | ACPI_ERROR((AE_INFO, |
| 139 | "GPE0 block (GPE 0 to %u) overlaps the GPE1 block " |
| 140 | "(GPE %u to %u) - Ignoring GPE1", |
| 141 | gpe_number_max, acpi_gbl_FADT.gpe1_base, |
| 142 | acpi_gbl_FADT.gpe1_base + |
| 143 | ((register_count1 * |
| 144 | ACPI_GPE_REGISTER_WIDTH) - 1))); |
| 145 | |
| 146 | /* Ignore GPE1 block by setting the register count to zero */ |
| 147 | |
| 148 | register_count1 = 0; |
| 149 | } else { |
| 150 | /* Install GPE Block 1 */ |
| 151 | |
| 152 | status = |
| 153 | acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device, |
| 154 | &acpi_gbl_FADT.xgpe1_block, |
| 155 | register_count1, |
| 156 | acpi_gbl_FADT.gpe1_base, |
| 157 | acpi_gbl_FADT. |
| 158 | sci_interrupt, |
| 159 | &acpi_gbl_gpe_fadt_blocks |
| 160 | [1]); |
| 161 | |
| 162 | if (ACPI_FAILURE(status)) { |
| 163 | ACPI_EXCEPTION((AE_INFO, status, |
| 164 | "Could not create GPE Block 1")); |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * GPE0 and GPE1 do not have to be contiguous in the GPE number |
| 169 | * space. However, GPE0 always starts at GPE number zero. |
| 170 | */ |
| 171 | gpe_number_max = acpi_gbl_FADT.gpe1_base + |
| 172 | ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /* Exit if there are no GPE registers */ |
| 177 | |
| 178 | if ((register_count0 + register_count1) == 0) { |
| 179 | |
| 180 | /* GPEs are not required by ACPI, this is OK */ |
| 181 | |
| 182 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 183 | "There are no GPE blocks defined in the FADT\n")); |
| 184 | status = AE_OK; |
| 185 | goto cleanup; |
| 186 | } |
| 187 | |
| 188 | /* Check for Max GPE number out-of-range */ |
| 189 | |
| 190 | if (gpe_number_max > ACPI_GPE_MAX) { |
| 191 | ACPI_ERROR((AE_INFO, |
| 192 | "Maximum GPE number from FADT is too large: 0x%X", |
| 193 | gpe_number_max)); |
| 194 | status = AE_BAD_VALUE; |
| 195 | goto cleanup; |
| 196 | } |
| 197 | |
| 198 | cleanup: |
| 199 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 200 | return_ACPI_STATUS(AE_OK); |
| 201 | } |
| 202 | |
| 203 | /******************************************************************************* |
| 204 | * |
| 205 | * FUNCTION: acpi_ev_update_gpes |
| 206 | * |
| 207 | * PARAMETERS: table_owner_id - ID of the newly-loaded ACPI table |
| 208 | * |
| 209 | * RETURN: None |
| 210 | * |
| 211 | * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a |
| 212 | * result of a Load() or load_table() operation. If new GPE |
| 213 | * methods have been installed, register the new methods and |
| 214 | * enable and runtime GPEs that are associated with them. Also, |
| 215 | * run any newly loaded _PRW methods in order to discover any |
| 216 | * new CAN_WAKE GPEs. |
| 217 | * |
| 218 | ******************************************************************************/ |
| 219 | |
| 220 | void acpi_ev_update_gpes(acpi_owner_id table_owner_id) |
| 221 | { |
| 222 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; |
| 223 | struct acpi_gpe_block_info *gpe_block; |
| 224 | struct acpi_gpe_walk_info walk_info; |
| 225 | acpi_status status = AE_OK; |
| 226 | u32 new_wake_gpe_count = 0; |
| 227 | |
| 228 | /* We will examine only _PRW/_Lxx/_Exx methods owned by this table */ |
| 229 | |
| 230 | walk_info.owner_id = table_owner_id; |
| 231 | walk_info.execute_by_owner_id = TRUE; |
| 232 | walk_info.count = 0; |
| 233 | |
| 234 | if (acpi_gbl_leave_wake_gpes_disabled) { |
| 235 | /* |
| 236 | * 1) Run any newly-loaded _PRW methods to find any GPEs that |
| 237 | * can now be marked as CAN_WAKE GPEs. Note: We must run the |
| 238 | * _PRW methods before we process the _Lxx/_Exx methods because |
| 239 | * we will enable all runtime GPEs associated with the new |
| 240 | * _Lxx/_Exx methods at the time we process those methods. |
| 241 | * |
| 242 | * Unlock interpreter so that we can run the _PRW methods. |
| 243 | */ |
| 244 | walk_info.gpe_block = NULL; |
| 245 | walk_info.gpe_device = NULL; |
| 246 | |
| 247 | acpi_ex_exit_interpreter(); |
| 248 | |
| 249 | status = |
| 250 | acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
| 251 | ACPI_UINT32_MAX, |
| 252 | ACPI_NS_WALK_NO_UNLOCK, |
| 253 | acpi_ev_match_prw_and_gpe, NULL, |
| 254 | &walk_info, NULL); |
| 255 | if (ACPI_FAILURE(status)) { |
| 256 | ACPI_EXCEPTION((AE_INFO, status, |
| 257 | "While executing _PRW methods")); |
| 258 | } |
| 259 | |
| 260 | acpi_ex_enter_interpreter(); |
| 261 | new_wake_gpe_count = walk_info.count; |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * 2) Find any _Lxx/_Exx GPE methods that have just been loaded. |
| 266 | * |
| 267 | * Any GPEs that correspond to new _Lxx/_Exx methods and are not |
| 268 | * marked as CAN_WAKE are immediately enabled. |
| 269 | * |
| 270 | * Examine the namespace underneath each gpe_device within the |
| 271 | * gpe_block lists. |
| 272 | */ |
| 273 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 274 | if (ACPI_FAILURE(status)) { |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | walk_info.count = 0; |
| 279 | walk_info.enable_this_gpe = TRUE; |
| 280 | |
| 281 | /* Walk the interrupt level descriptor list */ |
| 282 | |
| 283 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; |
| 284 | while (gpe_xrupt_info) { |
| 285 | |
| 286 | /* Walk all Gpe Blocks attached to this interrupt level */ |
| 287 | |
| 288 | gpe_block = gpe_xrupt_info->gpe_block_list_head; |
| 289 | while (gpe_block) { |
| 290 | walk_info.gpe_block = gpe_block; |
| 291 | walk_info.gpe_device = gpe_block->node; |
| 292 | |
| 293 | status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, |
| 294 | walk_info.gpe_device, |
| 295 | ACPI_UINT32_MAX, |
| 296 | ACPI_NS_WALK_NO_UNLOCK, |
| 297 | acpi_ev_match_gpe_method, |
| 298 | NULL, &walk_info, NULL); |
| 299 | if (ACPI_FAILURE(status)) { |
| 300 | ACPI_EXCEPTION((AE_INFO, status, |
| 301 | "While decoding _Lxx/_Exx methods")); |
| 302 | } |
| 303 | |
| 304 | gpe_block = gpe_block->next; |
| 305 | } |
| 306 | |
| 307 | gpe_xrupt_info = gpe_xrupt_info->next; |
| 308 | } |
| 309 | |
| 310 | if (walk_info.count || new_wake_gpe_count) { |
| 311 | ACPI_INFO((AE_INFO, |
| 312 | "Enabled %u new runtime GPEs, added %u new wakeup GPEs", |
| 313 | walk_info.count, new_wake_gpe_count)); |
| 314 | } |
| 315 | |
| 316 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | /******************************************************************************* |
| 321 | * |
| 322 | * FUNCTION: acpi_ev_match_gpe_method |
| 323 | * |
| 324 | * PARAMETERS: Callback from walk_namespace |
| 325 | * |
| 326 | * RETURN: Status |
| 327 | * |
| 328 | * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a |
| 329 | * control method under the _GPE portion of the namespace. |
| 330 | * Extract the name and GPE type from the object, saving this |
| 331 | * information for quick lookup during GPE dispatch. Allows a |
| 332 | * per-owner_id evaluation if execute_by_owner_id is TRUE in the |
| 333 | * walk_info parameter block. |
| 334 | * |
| 335 | * The name of each GPE control method is of the form: |
| 336 | * "_Lxx" or "_Exx", where: |
| 337 | * L - means that the GPE is level triggered |
| 338 | * E - means that the GPE is edge triggered |
| 339 | * xx - is the GPE number [in HEX] |
| 340 | * |
| 341 | * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods |
| 342 | * with that owner. |
| 343 | * If walk_info->enable_this_gpe is TRUE, the GPE that is referred to by a GPE |
| 344 | * method is immediately enabled (Used for Load/load_table operators) |
| 345 | * |
| 346 | ******************************************************************************/ |
| 347 | |
| 348 | acpi_status |
| 349 | acpi_ev_match_gpe_method(acpi_handle obj_handle, |
| 350 | u32 level, void *context, void **return_value) |
| 351 | { |
| 352 | struct acpi_namespace_node *method_node = |
| 353 | ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); |
| 354 | struct acpi_gpe_walk_info *walk_info = |
| 355 | ACPI_CAST_PTR(struct acpi_gpe_walk_info, context); |
| 356 | struct acpi_gpe_event_info *gpe_event_info; |
| 357 | struct acpi_namespace_node *gpe_device; |
| 358 | acpi_status status; |
| 359 | u32 gpe_number; |
| 360 | char name[ACPI_NAME_SIZE + 1]; |
| 361 | u8 type; |
| 362 | |
| 363 | ACPI_FUNCTION_TRACE(ev_match_gpe_method); |
| 364 | |
| 365 | /* Check if requested owner_id matches this owner_id */ |
| 366 | |
| 367 | if ((walk_info->execute_by_owner_id) && |
| 368 | (method_node->owner_id != walk_info->owner_id)) { |
| 369 | return_ACPI_STATUS(AE_OK); |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Match and decode the _Lxx and _Exx GPE method names |
| 374 | * |
| 375 | * 1) Extract the method name and null terminate it |
| 376 | */ |
| 377 | ACPI_MOVE_32_TO_32(name, &method_node->name.integer); |
| 378 | name[ACPI_NAME_SIZE] = 0; |
| 379 | |
| 380 | /* 2) Name must begin with an underscore */ |
| 381 | |
| 382 | if (name[0] != '_') { |
| 383 | return_ACPI_STATUS(AE_OK); /* Ignore this method */ |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * 3) Edge/Level determination is based on the 2nd character |
| 388 | * of the method name |
| 389 | * |
| 390 | * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is |
| 391 | * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set. |
| 392 | */ |
| 393 | switch (name[1]) { |
| 394 | case 'L': |
| 395 | type = ACPI_GPE_LEVEL_TRIGGERED; |
| 396 | break; |
| 397 | |
| 398 | case 'E': |
| 399 | type = ACPI_GPE_EDGE_TRIGGERED; |
| 400 | break; |
| 401 | |
| 402 | default: |
| 403 | /* Unknown method type, just ignore it */ |
| 404 | |
| 405 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
| 406 | "Ignoring unknown GPE method type: %s " |
| 407 | "(name not of form _Lxx or _Exx)", name)); |
| 408 | return_ACPI_STATUS(AE_OK); |
| 409 | } |
| 410 | |
| 411 | /* 4) The last two characters of the name are the hex GPE Number */ |
| 412 | |
| 413 | gpe_number = ACPI_STRTOUL(&name[2], NULL, 16); |
| 414 | if (gpe_number == ACPI_UINT32_MAX) { |
| 415 | |
| 416 | /* Conversion failed; invalid method, just ignore it */ |
| 417 | |
| 418 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
| 419 | "Could not extract GPE number from name: %s " |
| 420 | "(name is not of form _Lxx or _Exx)", name)); |
| 421 | return_ACPI_STATUS(AE_OK); |
| 422 | } |
| 423 | |
| 424 | /* Ensure that we have a valid GPE number for this GPE block */ |
| 425 | |
| 426 | gpe_event_info = |
| 427 | acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block); |
| 428 | if (!gpe_event_info) { |
| 429 | /* |
| 430 | * This gpe_number is not valid for this GPE block, just ignore it. |
| 431 | * However, it may be valid for a different GPE block, since GPE0 |
| 432 | * and GPE1 methods both appear under \_GPE. |
| 433 | */ |
| 434 | return_ACPI_STATUS(AE_OK); |
| 435 | } |
| 436 | |
| 437 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 438 | ACPI_GPE_DISPATCH_HANDLER) { |
| 439 | |
| 440 | /* If there is already a handler, ignore this GPE method */ |
| 441 | |
| 442 | return_ACPI_STATUS(AE_OK); |
| 443 | } |
| 444 | |
| 445 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 446 | ACPI_GPE_DISPATCH_METHOD) { |
| 447 | /* |
| 448 | * If there is already a method, ignore this method. But check |
| 449 | * for a type mismatch (if both the _Lxx AND _Exx exist) |
| 450 | */ |
| 451 | if (type != (gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) { |
| 452 | ACPI_ERROR((AE_INFO, |
| 453 | "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods", |
| 454 | gpe_number, gpe_number, gpe_number)); |
| 455 | } |
| 456 | return_ACPI_STATUS(AE_OK); |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Add the GPE information from above to the gpe_event_info block for |
| 461 | * use during dispatch of this GPE. |
| 462 | */ |
| 463 | gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_METHOD); |
| 464 | gpe_event_info->dispatch.method_node = method_node; |
| 465 | |
| 466 | /* |
| 467 | * Enable this GPE if requested. This only happens when during the |
| 468 | * execution of a Load or load_table operator. We have found a new |
| 469 | * GPE method and want to immediately enable the GPE if it is a |
| 470 | * runtime GPE. |
| 471 | */ |
| 472 | if (walk_info->enable_this_gpe) { |
| 473 | |
| 474 | /* Ignore GPEs that can wake the system */ |
| 475 | |
| 476 | if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE) || |
| 477 | !acpi_gbl_leave_wake_gpes_disabled) { |
| 478 | walk_info->count++; |
| 479 | gpe_device = walk_info->gpe_device; |
| 480 | |
| 481 | if (gpe_device == acpi_gbl_fadt_gpe_device) { |
| 482 | gpe_device = NULL; |
| 483 | } |
| 484 | |
| 485 | status = acpi_enable_gpe(gpe_device, gpe_number, |
| 486 | ACPI_GPE_TYPE_RUNTIME); |
| 487 | if (ACPI_FAILURE(status)) { |
| 488 | ACPI_EXCEPTION((AE_INFO, status, |
| 489 | "Could not enable GPE 0x%02X", |
| 490 | gpe_number)); |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
| 496 | "Registered GPE method %s as GPE number 0x%.2X\n", |
| 497 | name, gpe_number)); |
| 498 | return_ACPI_STATUS(AE_OK); |
| 499 | } |
| 500 | |
| 501 | /******************************************************************************* |
| 502 | * |
| 503 | * FUNCTION: acpi_ev_match_prw_and_gpe |
| 504 | * |
| 505 | * PARAMETERS: Callback from walk_namespace |
| 506 | * |
| 507 | * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is |
| 508 | * not aborted on a single _PRW failure. |
| 509 | * |
| 510 | * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a |
| 511 | * Device. Run the _PRW method. If present, extract the GPE |
| 512 | * number and mark the GPE as a CAN_WAKE GPE. Allows a |
| 513 | * per-owner_id execution if execute_by_owner_id is TRUE in the |
| 514 | * walk_info parameter block. |
| 515 | * |
| 516 | * If walk_info->execute_by_owner_id is TRUE, we only execute _PRWs with that |
| 517 | * owner. |
| 518 | * If walk_info->gpe_device is NULL, we execute every _PRW found. Otherwise, |
| 519 | * we only execute _PRWs that refer to the input gpe_device. |
| 520 | * |
| 521 | ******************************************************************************/ |
| 522 | |
| 523 | acpi_status |
| 524 | acpi_ev_match_prw_and_gpe(acpi_handle obj_handle, |
| 525 | u32 level, void *context, void **return_value) |
| 526 | { |
| 527 | struct acpi_gpe_walk_info *walk_info = |
| 528 | ACPI_CAST_PTR(struct acpi_gpe_walk_info, context); |
| 529 | struct acpi_namespace_node *gpe_device; |
| 530 | struct acpi_gpe_block_info *gpe_block; |
| 531 | struct acpi_namespace_node *target_gpe_device; |
| 532 | struct acpi_namespace_node *prw_node; |
| 533 | struct acpi_gpe_event_info *gpe_event_info; |
| 534 | union acpi_operand_object *pkg_desc; |
| 535 | union acpi_operand_object *obj_desc; |
| 536 | u32 gpe_number; |
| 537 | acpi_status status; |
| 538 | |
| 539 | ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe); |
| 540 | |
| 541 | /* Check for a _PRW method under this device */ |
| 542 | |
| 543 | status = acpi_ns_get_node(obj_handle, METHOD_NAME__PRW, |
| 544 | ACPI_NS_NO_UPSEARCH, &prw_node); |
| 545 | if (ACPI_FAILURE(status)) { |
| 546 | return_ACPI_STATUS(AE_OK); |
| 547 | } |
| 548 | |
| 549 | /* Check if requested owner_id matches this owner_id */ |
| 550 | |
| 551 | if ((walk_info->execute_by_owner_id) && |
| 552 | (prw_node->owner_id != walk_info->owner_id)) { |
| 553 | return_ACPI_STATUS(AE_OK); |
| 554 | } |
| 555 | |
| 556 | /* Execute the _PRW */ |
| 557 | |
| 558 | status = acpi_ut_evaluate_object(prw_node, NULL, |
| 559 | ACPI_BTYPE_PACKAGE, &pkg_desc); |
| 560 | if (ACPI_FAILURE(status)) { |
| 561 | return_ACPI_STATUS(AE_OK); |
| 562 | } |
| 563 | |
| 564 | /* The returned _PRW package must have at least two elements */ |
| 565 | |
| 566 | if (pkg_desc->package.count < 2) { |
| 567 | goto cleanup; |
| 568 | } |
| 569 | |
| 570 | /* Extract pointers from the input context */ |
| 571 | |
| 572 | gpe_device = walk_info->gpe_device; |
| 573 | gpe_block = walk_info->gpe_block; |
| 574 | |
| 575 | /* |
| 576 | * The _PRW object must return a package, we are only interested |
| 577 | * in the first element |
| 578 | */ |
| 579 | obj_desc = pkg_desc->package.elements[0]; |
| 580 | |
| 581 | if (obj_desc->common.type == ACPI_TYPE_INTEGER) { |
| 582 | |
| 583 | /* Use FADT-defined GPE device (from definition of _PRW) */ |
| 584 | |
| 585 | target_gpe_device = NULL; |
| 586 | if (gpe_device) { |
| 587 | target_gpe_device = acpi_gbl_fadt_gpe_device; |
| 588 | } |
| 589 | |
| 590 | /* Integer is the GPE number in the FADT described GPE blocks */ |
| 591 | |
| 592 | gpe_number = (u32)obj_desc->integer.value; |
| 593 | } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) { |
| 594 | |
| 595 | /* Package contains a GPE reference and GPE number within a GPE block */ |
| 596 | |
| 597 | if ((obj_desc->package.count < 2) || |
| 598 | ((obj_desc->package.elements[0])->common.type != |
| 599 | ACPI_TYPE_LOCAL_REFERENCE) || |
| 600 | ((obj_desc->package.elements[1])->common.type != |
| 601 | ACPI_TYPE_INTEGER)) { |
| 602 | goto cleanup; |
| 603 | } |
| 604 | |
| 605 | /* Get GPE block reference and decode */ |
| 606 | |
| 607 | target_gpe_device = |
| 608 | obj_desc->package.elements[0]->reference.node; |
| 609 | gpe_number = (u32)obj_desc->package.elements[1]->integer.value; |
| 610 | } else { |
| 611 | /* Unknown type, just ignore it */ |
| 612 | |
| 613 | goto cleanup; |
| 614 | } |
| 615 | |
| 616 | /* Get the gpe_event_info for this GPE */ |
| 617 | |
| 618 | if (gpe_device) { |
| 619 | /* |
| 620 | * Is this GPE within this block? |
| 621 | * |
| 622 | * TRUE if and only if these conditions are true: |
| 623 | * 1) The GPE devices match. |
| 624 | * 2) The GPE index(number) is within the range of the Gpe Block |
| 625 | * associated with the GPE device. |
| 626 | */ |
| 627 | if (gpe_device != target_gpe_device) { |
| 628 | goto cleanup; |
| 629 | } |
| 630 | |
| 631 | gpe_event_info = |
| 632 | acpi_ev_low_get_gpe_info(gpe_number, gpe_block); |
| 633 | } else { |
| 634 | /* gpe_device is NULL, just match the target_device and gpe_number */ |
| 635 | |
| 636 | gpe_event_info = |
| 637 | acpi_ev_get_gpe_event_info(target_gpe_device, gpe_number); |
| 638 | } |
| 639 | |
| 640 | if (gpe_event_info) { |
| 641 | if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { |
| 642 | |
| 643 | /* This GPE can wake the system */ |
| 644 | |
| 645 | gpe_event_info->flags |= ACPI_GPE_CAN_WAKE; |
| 646 | walk_info->count++; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | cleanup: |
| 651 | acpi_ut_remove_reference(pkg_desc); |
| 652 | return_ACPI_STATUS(AE_OK); |
| 653 | } |