evgpeinit.c revision 1.1 1 /******************************************************************************
2 *
3 * Module Name: evgpeinit - System GPE initialization and update
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2010, 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
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acevents.h"
120 #include "acnamesp.h"
121 #include "acinterp.h"
122
123 #define _COMPONENT ACPI_EVENTS
124 ACPI_MODULE_NAME ("evgpeinit")
125
126
127 /*******************************************************************************
128 *
129 * FUNCTION: AcpiEvGpeInitialize
130 *
131 * PARAMETERS: None
132 *
133 * RETURN: Status
134 *
135 * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
136 *
137 ******************************************************************************/
138
139 ACPI_STATUS
140 AcpiEvGpeInitialize (
141 void)
142 {
143 UINT32 RegisterCount0 = 0;
144 UINT32 RegisterCount1 = 0;
145 UINT32 GpeNumberMax = 0;
146 ACPI_STATUS Status;
147
148
149 ACPI_FUNCTION_TRACE (EvGpeInitialize);
150
151
152 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
153 if (ACPI_FAILURE (Status))
154 {
155 return_ACPI_STATUS (Status);
156 }
157
158 /*
159 * Initialize the GPE Block(s) defined in the FADT
160 *
161 * Why the GPE register block lengths are divided by 2: From the ACPI
162 * Spec, section "General-Purpose Event Registers", we have:
163 *
164 * "Each register block contains two registers of equal length
165 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
166 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
167 * The length of the GPE1_STS and GPE1_EN registers is equal to
168 * half the GPE1_LEN. If a generic register block is not supported
169 * then its respective block pointer and block length values in the
170 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
171 * to be the same size."
172 */
173
174 /*
175 * Determine the maximum GPE number for this machine.
176 *
177 * Note: both GPE0 and GPE1 are optional, and either can exist without
178 * the other.
179 *
180 * If EITHER the register length OR the block address are zero, then that
181 * particular block is not supported.
182 */
183 if (AcpiGbl_FADT.Gpe0BlockLength &&
184 AcpiGbl_FADT.XGpe0Block.Address)
185 {
186 /* GPE block 0 exists (has both length and address > 0) */
187
188 RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
189
190 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
191
192 /* Install GPE Block 0 */
193
194 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
195 &AcpiGbl_FADT.XGpe0Block, RegisterCount0, 0,
196 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
197
198 if (ACPI_FAILURE (Status))
199 {
200 ACPI_EXCEPTION ((AE_INFO, Status,
201 "Could not create GPE Block 0"));
202 }
203 }
204
205 if (AcpiGbl_FADT.Gpe1BlockLength &&
206 AcpiGbl_FADT.XGpe1Block.Address)
207 {
208 /* GPE block 1 exists (has both length and address > 0) */
209
210 RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
211
212 /* Check for GPE0/GPE1 overlap (if both banks exist) */
213
214 if ((RegisterCount0) &&
215 (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
216 {
217 ACPI_ERROR ((AE_INFO,
218 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
219 "(GPE %u to %u) - Ignoring GPE1",
220 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
221 AcpiGbl_FADT.Gpe1Base +
222 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
223
224 /* Ignore GPE1 block by setting the register count to zero */
225
226 RegisterCount1 = 0;
227 }
228 else
229 {
230 /* Install GPE Block 1 */
231
232 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
233 &AcpiGbl_FADT.XGpe1Block, RegisterCount1,
234 AcpiGbl_FADT.Gpe1Base,
235 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
236
237 if (ACPI_FAILURE (Status))
238 {
239 ACPI_EXCEPTION ((AE_INFO, Status,
240 "Could not create GPE Block 1"));
241 }
242
243 /*
244 * GPE0 and GPE1 do not have to be contiguous in the GPE number
245 * space. However, GPE0 always starts at GPE number zero.
246 */
247 GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
248 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
249 }
250 }
251
252 /* Exit if there are no GPE registers */
253
254 if ((RegisterCount0 + RegisterCount1) == 0)
255 {
256 /* GPEs are not required by ACPI, this is OK */
257
258 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
259 "There are no GPE blocks defined in the FADT\n"));
260 Status = AE_OK;
261 goto Cleanup;
262 }
263
264 /* Check for Max GPE number out-of-range */
265
266 if (GpeNumberMax > ACPI_GPE_MAX)
267 {
268 ACPI_ERROR ((AE_INFO,
269 "Maximum GPE number from FADT is too large: 0x%X",
270 GpeNumberMax));
271 Status = AE_BAD_VALUE;
272 goto Cleanup;
273 }
274
275 Cleanup:
276 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
277 return_ACPI_STATUS (AE_OK);
278 }
279
280
281 /*******************************************************************************
282 *
283 * FUNCTION: AcpiEvUpdateGpes
284 *
285 * PARAMETERS: TableOwnerId - ID of the newly-loaded ACPI table
286 *
287 * RETURN: None
288 *
289 * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
290 * result of a Load() or LoadTable() operation. If new GPE
291 * methods have been installed, register the new methods and
292 * enable and runtime GPEs that are associated with them. Also,
293 * run any newly loaded _PRW methods in order to discover any
294 * new CAN_WAKE GPEs.
295 *
296 ******************************************************************************/
297
298 void
299 AcpiEvUpdateGpes (
300 ACPI_OWNER_ID TableOwnerId)
301 {
302 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
303 ACPI_GPE_BLOCK_INFO *GpeBlock;
304 ACPI_GPE_WALK_INFO WalkInfo;
305 ACPI_STATUS Status = AE_OK;
306 UINT32 NewWakeGpeCount = 0;
307
308
309 /* We will examine only _PRW/_Lxx/_Exx methods owned by this table */
310
311 WalkInfo.OwnerId = TableOwnerId;
312 WalkInfo.ExecuteByOwnerId = TRUE;
313 WalkInfo.Count = 0;
314
315 if (AcpiGbl_LeaveWakeGpesDisabled)
316 {
317 /*
318 * 1) Run any newly-loaded _PRW methods to find any GPEs that
319 * can now be marked as CAN_WAKE GPEs. Note: We must run the
320 * _PRW methods before we process the _Lxx/_Exx methods because
321 * we will enable all runtime GPEs associated with the new
322 * _Lxx/_Exx methods at the time we process those methods.
323 *
324 * Unlock interpreter so that we can run the _PRW methods.
325 */
326 WalkInfo.GpeBlock = NULL;
327 WalkInfo.GpeDevice = NULL;
328
329 AcpiExExitInterpreter ();
330
331 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
332 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
333 AcpiEvMatchPrwAndGpe, NULL, &WalkInfo, NULL);
334 if (ACPI_FAILURE (Status))
335 {
336 ACPI_EXCEPTION ((AE_INFO, Status,
337 "While executing _PRW methods"));
338 }
339
340 AcpiExEnterInterpreter ();
341 NewWakeGpeCount = WalkInfo.Count;
342 }
343
344 /*
345 * 2) Find any _Lxx/_Exx GPE methods that have just been loaded.
346 *
347 * Any GPEs that correspond to new _Lxx/_Exx methods and are not
348 * marked as CAN_WAKE are immediately enabled.
349 *
350 * Examine the namespace underneath each GpeDevice within the
351 * GpeBlock lists.
352 */
353 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
354 if (ACPI_FAILURE (Status))
355 {
356 return;
357 }
358
359 WalkInfo.Count = 0;
360 WalkInfo.EnableThisGpe = TRUE;
361
362 /* Walk the interrupt level descriptor list */
363
364 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
365 while (GpeXruptInfo)
366 {
367 /* Walk all Gpe Blocks attached to this interrupt level */
368
369 GpeBlock = GpeXruptInfo->GpeBlockListHead;
370 while (GpeBlock)
371 {
372 WalkInfo.GpeBlock = GpeBlock;
373 WalkInfo.GpeDevice = GpeBlock->Node;
374
375 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
376 WalkInfo.GpeDevice, ACPI_UINT32_MAX,
377 ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
378 NULL, &WalkInfo, NULL);
379 if (ACPI_FAILURE (Status))
380 {
381 ACPI_EXCEPTION ((AE_INFO, Status,
382 "While decoding _Lxx/_Exx methods"));
383 }
384
385 GpeBlock = GpeBlock->Next;
386 }
387
388 GpeXruptInfo = GpeXruptInfo->Next;
389 }
390
391 if (WalkInfo.Count || NewWakeGpeCount)
392 {
393 ACPI_INFO ((AE_INFO,
394 "Enabled %u new runtime GPEs, added %u new wakeup GPEs",
395 WalkInfo.Count, NewWakeGpeCount));
396 }
397
398 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
399 return;
400 }
401
402
403 /*******************************************************************************
404 *
405 * FUNCTION: AcpiEvMatchGpeMethod
406 *
407 * PARAMETERS: Callback from WalkNamespace
408 *
409 * RETURN: Status
410 *
411 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
412 * control method under the _GPE portion of the namespace.
413 * Extract the name and GPE type from the object, saving this
414 * information for quick lookup during GPE dispatch. Allows a
415 * per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
416 * WalkInfo parameter block.
417 *
418 * The name of each GPE control method is of the form:
419 * "_Lxx" or "_Exx", where:
420 * L - means that the GPE is level triggered
421 * E - means that the GPE is edge triggered
422 * xx - is the GPE number [in HEX]
423 *
424 * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
425 * with that owner.
426 * If WalkInfo->EnableThisGpe is TRUE, the GPE that is referred to by a GPE
427 * method is immediately enabled (Used for Load/LoadTable operators)
428 *
429 ******************************************************************************/
430
431 ACPI_STATUS
432 AcpiEvMatchGpeMethod (
433 ACPI_HANDLE ObjHandle,
434 UINT32 Level,
435 void *Context,
436 void **ReturnValue)
437 {
438 ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
439 ACPI_GPE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
440 ACPI_GPE_EVENT_INFO *GpeEventInfo;
441 ACPI_NAMESPACE_NODE *GpeDevice;
442 ACPI_STATUS Status;
443 UINT32 GpeNumber;
444 char Name[ACPI_NAME_SIZE + 1];
445 UINT8 Type;
446
447
448 ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
449
450
451 /* Check if requested OwnerId matches this OwnerId */
452
453 if ((WalkInfo->ExecuteByOwnerId) &&
454 (MethodNode->OwnerId != WalkInfo->OwnerId))
455 {
456 return_ACPI_STATUS (AE_OK);
457 }
458
459 /*
460 * Match and decode the _Lxx and _Exx GPE method names
461 *
462 * 1) Extract the method name and null terminate it
463 */
464 ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
465 Name[ACPI_NAME_SIZE] = 0;
466
467 /* 2) Name must begin with an underscore */
468
469 if (Name[0] != '_')
470 {
471 return_ACPI_STATUS (AE_OK); /* Ignore this method */
472 }
473
474 /*
475 * 3) Edge/Level determination is based on the 2nd character
476 * of the method name
477 *
478 * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
479 * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
480 */
481 switch (Name[1])
482 {
483 case 'L':
484 Type = ACPI_GPE_LEVEL_TRIGGERED;
485 break;
486
487 case 'E':
488 Type = ACPI_GPE_EDGE_TRIGGERED;
489 break;
490
491 default:
492 /* Unknown method type, just ignore it */
493
494 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
495 "Ignoring unknown GPE method type: %s "
496 "(name not of form _Lxx or _Exx)", Name));
497 return_ACPI_STATUS (AE_OK);
498 }
499
500 /* 4) The last two characters of the name are the hex GPE Number */
501
502 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
503 if (GpeNumber == ACPI_UINT32_MAX)
504 {
505 /* Conversion failed; invalid method, just ignore it */
506
507 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
508 "Could not extract GPE number from name: %s "
509 "(name is not of form _Lxx or _Exx)", Name));
510 return_ACPI_STATUS (AE_OK);
511 }
512
513 /* Ensure that we have a valid GPE number for this GPE block */
514
515 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
516 if (!GpeEventInfo)
517 {
518 /*
519 * This GpeNumber is not valid for this GPE block, just ignore it.
520 * However, it may be valid for a different GPE block, since GPE0
521 * and GPE1 methods both appear under \_GPE.
522 */
523 return_ACPI_STATUS (AE_OK);
524 }
525
526 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
527 ACPI_GPE_DISPATCH_HANDLER)
528 {
529 /* If there is already a handler, ignore this GPE method */
530
531 return_ACPI_STATUS (AE_OK);
532 }
533
534 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
535 ACPI_GPE_DISPATCH_METHOD)
536 {
537 /*
538 * If there is already a method, ignore this method. But check
539 * for a type mismatch (if both the _Lxx AND _Exx exist)
540 */
541 if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
542 {
543 ACPI_ERROR ((AE_INFO,
544 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
545 GpeNumber, GpeNumber, GpeNumber));
546 }
547 return_ACPI_STATUS (AE_OK);
548 }
549
550 /*
551 * Add the GPE information from above to the GpeEventInfo block for
552 * use during dispatch of this GPE.
553 */
554 GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
555 GpeEventInfo->Dispatch.MethodNode = MethodNode;
556
557 /*
558 * Enable this GPE if requested. This only happens when during the
559 * execution of a Load or LoadTable operator. We have found a new
560 * GPE method and want to immediately enable the GPE if it is a
561 * runtime GPE.
562 */
563 if (WalkInfo->EnableThisGpe)
564 {
565 /* Ignore GPEs that can wake the system */
566
567 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE) ||
568 !AcpiGbl_LeaveWakeGpesDisabled)
569 {
570 WalkInfo->Count++;
571 GpeDevice = WalkInfo->GpeDevice;
572
573 if (GpeDevice == AcpiGbl_FadtGpeDevice)
574 {
575 GpeDevice = NULL;
576 }
577
578 Status = AcpiEnableGpe (GpeDevice, GpeNumber,
579 ACPI_GPE_TYPE_RUNTIME);
580 if (ACPI_FAILURE (Status))
581 {
582 ACPI_EXCEPTION ((AE_INFO, Status,
583 "Could not enable GPE 0x%02X", GpeNumber));
584 }
585 }
586 }
587
588 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
589 "Registered GPE method %s as GPE number 0x%.2X\n",
590 Name, GpeNumber));
591 return_ACPI_STATUS (AE_OK);
592 }
593
594
595 /*******************************************************************************
596 *
597 * FUNCTION: AcpiEvMatchPrwAndGpe
598 *
599 * PARAMETERS: Callback from WalkNamespace
600 *
601 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
602 * not aborted on a single _PRW failure.
603 *
604 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
605 * Device. Run the _PRW method. If present, extract the GPE
606 * number and mark the GPE as a CAN_WAKE GPE. Allows a
607 * per-OwnerId execution if ExecuteByOwnerId is TRUE in the
608 * WalkInfo parameter block.
609 *
610 * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute _PRWs with that
611 * owner.
612 * If WalkInfo->GpeDevice is NULL, we execute every _PRW found. Otherwise,
613 * we only execute _PRWs that refer to the input GpeDevice.
614 *
615 ******************************************************************************/
616
617 ACPI_STATUS
618 AcpiEvMatchPrwAndGpe (
619 ACPI_HANDLE ObjHandle,
620 UINT32 Level,
621 void *Context,
622 void **ReturnValue)
623 {
624 ACPI_GPE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
625 ACPI_NAMESPACE_NODE *GpeDevice;
626 ACPI_GPE_BLOCK_INFO *GpeBlock;
627 ACPI_NAMESPACE_NODE *TargetGpeDevice;
628 ACPI_NAMESPACE_NODE *PrwNode;
629 ACPI_GPE_EVENT_INFO *GpeEventInfo;
630 ACPI_OPERAND_OBJECT *PkgDesc;
631 ACPI_OPERAND_OBJECT *ObjDesc;
632 UINT32 GpeNumber;
633 ACPI_STATUS Status;
634
635
636 ACPI_FUNCTION_TRACE (EvMatchPrwAndGpe);
637
638
639 /* Check for a _PRW method under this device */
640
641 Status = AcpiNsGetNode (ObjHandle, METHOD_NAME__PRW,
642 ACPI_NS_NO_UPSEARCH, &PrwNode);
643 if (ACPI_FAILURE (Status))
644 {
645 return_ACPI_STATUS (AE_OK);
646 }
647
648 /* Check if requested OwnerId matches this OwnerId */
649
650 if ((WalkInfo->ExecuteByOwnerId) &&
651 (PrwNode->OwnerId != WalkInfo->OwnerId))
652 {
653 return_ACPI_STATUS (AE_OK);
654 }
655
656 /* Execute the _PRW */
657
658 Status = AcpiUtEvaluateObject (PrwNode, NULL,
659 ACPI_BTYPE_PACKAGE, &PkgDesc);
660 if (ACPI_FAILURE (Status))
661 {
662 return_ACPI_STATUS (AE_OK);
663 }
664
665 /* The returned _PRW package must have at least two elements */
666
667 if (PkgDesc->Package.Count < 2)
668 {
669 goto Cleanup;
670 }
671
672 /* Extract pointers from the input context */
673
674 GpeDevice = WalkInfo->GpeDevice;
675 GpeBlock = WalkInfo->GpeBlock;
676
677 /*
678 * The _PRW object must return a package, we are only interested
679 * in the first element
680 */
681 ObjDesc = PkgDesc->Package.Elements[0];
682
683 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
684 {
685 /* Use FADT-defined GPE device (from definition of _PRW) */
686
687 TargetGpeDevice = NULL;
688 if (GpeDevice)
689 {
690 TargetGpeDevice = AcpiGbl_FadtGpeDevice;
691 }
692
693 /* Integer is the GPE number in the FADT described GPE blocks */
694
695 GpeNumber = (UINT32) ObjDesc->Integer.Value;
696 }
697 else if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
698 {
699 /* Package contains a GPE reference and GPE number within a GPE block */
700
701 if ((ObjDesc->Package.Count < 2) ||
702 ((ObjDesc->Package.Elements[0])->Common.Type !=
703 ACPI_TYPE_LOCAL_REFERENCE) ||
704 ((ObjDesc->Package.Elements[1])->Common.Type !=
705 ACPI_TYPE_INTEGER))
706 {
707 goto Cleanup;
708 }
709
710 /* Get GPE block reference and decode */
711
712 TargetGpeDevice = ObjDesc->Package.Elements[0]->Reference.Node;
713 GpeNumber = (UINT32) ObjDesc->Package.Elements[1]->Integer.Value;
714 }
715 else
716 {
717 /* Unknown type, just ignore it */
718
719 goto Cleanup;
720 }
721
722 /* Get the GpeEventInfo for this GPE */
723
724 if (GpeDevice)
725 {
726 /*
727 * Is this GPE within this block?
728 *
729 * TRUE if and only if these conditions are true:
730 * 1) The GPE devices match.
731 * 2) The GPE index(number) is within the range of the Gpe Block
732 * associated with the GPE device.
733 */
734 if (GpeDevice != TargetGpeDevice)
735 {
736 goto Cleanup;
737 }
738
739 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, GpeBlock);
740 }
741 else
742 {
743 /* GpeDevice is NULL, just match the TargetDevice and GpeNumber */
744
745 GpeEventInfo = AcpiEvGetGpeEventInfo (TargetGpeDevice, GpeNumber);
746 }
747
748 if (GpeEventInfo)
749 {
750 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
751 {
752 /* This GPE can wake the system */
753
754 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
755 WalkInfo->Count++;
756 }
757 }
758
759 Cleanup:
760 AcpiUtRemoveReference (PkgDesc);
761 return_ACPI_STATUS (AE_OK);
762 }
763
764