Update to ACPICA 20121018.
[haiku.git] / src / add-ons / kernel / bus_managers / acpi / acpica / components / events / evgpeinit.c
blobfe7ca2f2645d3eb62791dcb6a6869d4d4389c1c2
1 /******************************************************************************
3 * Module Name: evgpeinit - System GPE initialization and update
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2012, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************/
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acevents.h"
120 #include "acnamesp.h"
122 #define _COMPONENT ACPI_EVENTS
123 ACPI_MODULE_NAME ("evgpeinit")
125 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
128 * Note: History of _PRW support in ACPICA
130 * Originally (2000 - 2010), the GPE initialization code performed a walk of
131 * the entire namespace to execute the _PRW methods and detect all GPEs
132 * capable of waking the system.
134 * As of 10/2010, the _PRW method execution has been removed since it is
135 * actually unnecessary. The host OS must in fact execute all _PRW methods
136 * in order to identify the device/power-resource dependencies. We now put
137 * the onus on the host OS to identify the wake GPEs as part of this process
138 * and to inform ACPICA of these GPEs via the AcpiSetupGpeForWake interface. This
139 * not only reduces the complexity of the ACPICA initialization code, but in
140 * some cases (on systems with very large namespaces) it should reduce the
141 * kernel boot time as well.
144 /*******************************************************************************
146 * FUNCTION: AcpiEvGpeInitialize
148 * PARAMETERS: None
150 * RETURN: Status
152 * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
154 ******************************************************************************/
156 ACPI_STATUS
157 AcpiEvGpeInitialize (
158 void)
160 UINT32 RegisterCount0 = 0;
161 UINT32 RegisterCount1 = 0;
162 UINT32 GpeNumberMax = 0;
163 ACPI_STATUS Status;
166 ACPI_FUNCTION_TRACE (EvGpeInitialize);
169 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
170 if (ACPI_FAILURE (Status))
172 return_ACPI_STATUS (Status);
176 * Initialize the GPE Block(s) defined in the FADT
178 * Why the GPE register block lengths are divided by 2: From the ACPI
179 * Spec, section "General-Purpose Event Registers", we have:
181 * "Each register block contains two registers of equal length
182 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
183 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
184 * The length of the GPE1_STS and GPE1_EN registers is equal to
185 * half the GPE1_LEN. If a generic register block is not supported
186 * then its respective block pointer and block length values in the
187 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
188 * to be the same size."
192 * Determine the maximum GPE number for this machine.
194 * Note: both GPE0 and GPE1 are optional, and either can exist without
195 * the other.
197 * If EITHER the register length OR the block address are zero, then that
198 * particular block is not supported.
200 if (AcpiGbl_FADT.Gpe0BlockLength &&
201 AcpiGbl_FADT.XGpe0Block.Address)
203 /* GPE block 0 exists (has both length and address > 0) */
205 RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
207 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
209 /* Install GPE Block 0 */
211 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
212 &AcpiGbl_FADT.XGpe0Block, RegisterCount0, 0,
213 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
215 if (ACPI_FAILURE (Status))
217 ACPI_EXCEPTION ((AE_INFO, Status,
218 "Could not create GPE Block 0"));
222 if (AcpiGbl_FADT.Gpe1BlockLength &&
223 AcpiGbl_FADT.XGpe1Block.Address)
225 /* GPE block 1 exists (has both length and address > 0) */
227 RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
229 /* Check for GPE0/GPE1 overlap (if both banks exist) */
231 if ((RegisterCount0) &&
232 (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
234 ACPI_ERROR ((AE_INFO,
235 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
236 "(GPE %u to %u) - Ignoring GPE1",
237 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
238 AcpiGbl_FADT.Gpe1Base +
239 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
241 /* Ignore GPE1 block by setting the register count to zero */
243 RegisterCount1 = 0;
245 else
247 /* Install GPE Block 1 */
249 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
250 &AcpiGbl_FADT.XGpe1Block, RegisterCount1,
251 AcpiGbl_FADT.Gpe1Base,
252 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
254 if (ACPI_FAILURE (Status))
256 ACPI_EXCEPTION ((AE_INFO, Status,
257 "Could not create GPE Block 1"));
261 * GPE0 and GPE1 do not have to be contiguous in the GPE number
262 * space. However, GPE0 always starts at GPE number zero.
264 GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
265 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
269 /* Exit if there are no GPE registers */
271 if ((RegisterCount0 + RegisterCount1) == 0)
273 /* GPEs are not required by ACPI, this is OK */
275 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
276 "There are no GPE blocks defined in the FADT\n"));
277 Status = AE_OK;
278 goto Cleanup;
281 /* Check for Max GPE number out-of-range */
283 if (GpeNumberMax > ACPI_GPE_MAX)
285 ACPI_ERROR ((AE_INFO,
286 "Maximum GPE number from FADT is too large: 0x%X",
287 GpeNumberMax));
288 Status = AE_BAD_VALUE;
289 goto Cleanup;
292 Cleanup:
293 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
294 return_ACPI_STATUS (AE_OK);
298 /*******************************************************************************
300 * FUNCTION: AcpiEvUpdateGpes
302 * PARAMETERS: TableOwnerId - ID of the newly-loaded ACPI table
304 * RETURN: None
306 * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
307 * result of a Load() or LoadTable() operation. If new GPE
308 * methods have been installed, register the new methods.
310 ******************************************************************************/
312 void
313 AcpiEvUpdateGpes (
314 ACPI_OWNER_ID TableOwnerId)
316 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
317 ACPI_GPE_BLOCK_INFO *GpeBlock;
318 ACPI_GPE_WALK_INFO WalkInfo;
319 ACPI_STATUS Status = AE_OK;
323 * Find any _Lxx/_Exx GPE methods that have just been loaded.
325 * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
326 * enabled.
328 * Examine the namespace underneath each GpeDevice within the
329 * GpeBlock lists.
331 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
332 if (ACPI_FAILURE (Status))
334 return;
337 WalkInfo.Count = 0;
338 WalkInfo.OwnerId = TableOwnerId;
339 WalkInfo.ExecuteByOwnerId = TRUE;
341 /* Walk the interrupt level descriptor list */
343 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
344 while (GpeXruptInfo)
346 /* Walk all Gpe Blocks attached to this interrupt level */
348 GpeBlock = GpeXruptInfo->GpeBlockListHead;
349 while (GpeBlock)
351 WalkInfo.GpeBlock = GpeBlock;
352 WalkInfo.GpeDevice = GpeBlock->Node;
354 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
355 WalkInfo.GpeDevice, ACPI_UINT32_MAX,
356 ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
357 NULL, &WalkInfo, NULL);
358 if (ACPI_FAILURE (Status))
360 ACPI_EXCEPTION ((AE_INFO, Status,
361 "While decoding _Lxx/_Exx methods"));
364 GpeBlock = GpeBlock->Next;
367 GpeXruptInfo = GpeXruptInfo->Next;
370 if (WalkInfo.Count)
372 ACPI_INFO ((AE_INFO, "Enabled %u new GPEs", WalkInfo.Count));
375 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
376 return;
380 /*******************************************************************************
382 * FUNCTION: AcpiEvMatchGpeMethod
384 * PARAMETERS: Callback from WalkNamespace
386 * RETURN: Status
388 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
389 * control method under the _GPE portion of the namespace.
390 * Extract the name and GPE type from the object, saving this
391 * information for quick lookup during GPE dispatch. Allows a
392 * per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
393 * WalkInfo parameter block.
395 * The name of each GPE control method is of the form:
396 * "_Lxx" or "_Exx", where:
397 * L - means that the GPE is level triggered
398 * E - means that the GPE is edge triggered
399 * xx - is the GPE number [in HEX]
401 * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
402 * with that owner.
404 ******************************************************************************/
406 ACPI_STATUS
407 AcpiEvMatchGpeMethod (
408 ACPI_HANDLE ObjHandle,
409 UINT32 Level,
410 void *Context,
411 void **ReturnValue)
413 ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
414 ACPI_GPE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
415 ACPI_GPE_EVENT_INFO *GpeEventInfo;
416 UINT32 GpeNumber;
417 char Name[ACPI_NAME_SIZE + 1];
418 UINT8 Type;
421 ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
424 /* Check if requested OwnerId matches this OwnerId */
426 if ((WalkInfo->ExecuteByOwnerId) &&
427 (MethodNode->OwnerId != WalkInfo->OwnerId))
429 return_ACPI_STATUS (AE_OK);
433 * Match and decode the _Lxx and _Exx GPE method names
435 * 1) Extract the method name and null terminate it
437 ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
438 Name[ACPI_NAME_SIZE] = 0;
440 /* 2) Name must begin with an underscore */
442 if (Name[0] != '_')
444 return_ACPI_STATUS (AE_OK); /* Ignore this method */
448 * 3) Edge/Level determination is based on the 2nd character
449 * of the method name
451 switch (Name[1])
453 case 'L':
454 Type = ACPI_GPE_LEVEL_TRIGGERED;
455 break;
457 case 'E':
458 Type = ACPI_GPE_EDGE_TRIGGERED;
459 break;
461 default:
462 /* Unknown method type, just ignore it */
464 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
465 "Ignoring unknown GPE method type: %s "
466 "(name not of form _Lxx or _Exx)", Name));
467 return_ACPI_STATUS (AE_OK);
470 /* 4) The last two characters of the name are the hex GPE Number */
472 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
473 if (GpeNumber == ACPI_UINT32_MAX)
475 /* Conversion failed; invalid method, just ignore it */
477 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
478 "Could not extract GPE number from name: %s "
479 "(name is not of form _Lxx or _Exx)", Name));
480 return_ACPI_STATUS (AE_OK);
483 /* Ensure that we have a valid GPE number for this GPE block */
485 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
486 if (!GpeEventInfo)
489 * This GpeNumber is not valid for this GPE block, just ignore it.
490 * However, it may be valid for a different GPE block, since GPE0
491 * and GPE1 methods both appear under \_GPE.
493 return_ACPI_STATUS (AE_OK);
496 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
497 ACPI_GPE_DISPATCH_HANDLER)
499 /* If there is already a handler, ignore this GPE method */
501 return_ACPI_STATUS (AE_OK);
504 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
505 ACPI_GPE_DISPATCH_METHOD)
508 * If there is already a method, ignore this method. But check
509 * for a type mismatch (if both the _Lxx AND _Exx exist)
511 if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
513 ACPI_ERROR ((AE_INFO,
514 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
515 GpeNumber, GpeNumber, GpeNumber));
517 return_ACPI_STATUS (AE_OK);
521 * Add the GPE information from above to the GpeEventInfo block for
522 * use during dispatch of this GPE.
524 GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK);
525 GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
526 GpeEventInfo->Dispatch.MethodNode = MethodNode;
528 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
529 "Registered GPE method %s as GPE number 0x%.2X\n",
530 Name, GpeNumber));
531 return_ACPI_STATUS (AE_OK);
534 #endif /* !ACPI_REDUCED_HARDWARE */