1 /******************************************************************************
3 * Module Name: evgpeinit - System GPE initialization and update
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acevents.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME ("evgpeinit")
55 * Note: History of _PRW support in ACPICA
57 * Originally (2000 - 2010), the GPE initialization code performed a walk of
58 * the entire namespace to execute the _PRW methods and detect all GPEs
59 * capable of waking the system.
61 * As of 10/2010, the _PRW method execution has been removed since it is
62 * actually unnecessary. The host OS must in fact execute all _PRW methods
63 * in order to identify the device/power-resource dependencies. We now put
64 * the onus on the host OS to identify the wake GPEs as part of this process
65 * and to inform ACPICA of these GPEs via the AcpiSetupGpeForWake interface. This
66 * not only reduces the complexity of the ACPICA initialization code, but in
67 * some cases (on systems with very large namespaces) it should reduce the
68 * kernel boot time as well.
71 /*******************************************************************************
73 * FUNCTION: AcpiEvGpeInitialize
79 * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
81 ******************************************************************************/
87 UINT32 RegisterCount0 = 0;
88 UINT32 RegisterCount1 = 0;
89 UINT32 GpeNumberMax = 0;
93 ACPI_FUNCTION_TRACE (EvGpeInitialize);
96 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
97 if (ACPI_FAILURE (Status))
99 return_ACPI_STATUS (Status);
103 * Initialize the GPE Block(s) defined in the FADT
105 * Why the GPE register block lengths are divided by 2: From the ACPI
106 * Spec, section "General-Purpose Event Registers", we have:
108 * "Each register block contains two registers of equal length
109 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
110 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
111 * The length of the GPE1_STS and GPE1_EN registers is equal to
112 * half the GPE1_LEN. If a generic register block is not supported
113 * then its respective block pointer and block length values in the
114 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
115 * to be the same size."
119 * Determine the maximum GPE number for this machine.
121 * Note: both GPE0 and GPE1 are optional, and either can exist without
124 * If EITHER the register length OR the block address are zero, then that
125 * particular block is not supported.
127 if (AcpiGbl_FADT.Gpe0BlockLength &&
128 AcpiGbl_FADT.XGpe0Block.Address)
130 /* GPE block 0 exists (has both length and address > 0) */
132 RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
134 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
136 /* Install GPE Block 0 */
138 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
139 &AcpiGbl_FADT.XGpe0Block, RegisterCount0, 0,
140 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
142 if (ACPI_FAILURE (Status))
144 ACPI_EXCEPTION ((AE_INFO, Status,
145 "Could not create GPE Block 0"));
149 if (AcpiGbl_FADT.Gpe1BlockLength &&
150 AcpiGbl_FADT.XGpe1Block.Address)
152 /* GPE block 1 exists (has both length and address > 0) */
154 RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
156 /* Check for GPE0/GPE1 overlap (if both banks exist) */
158 if ((RegisterCount0) &&
159 (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
161 ACPI_ERROR ((AE_INFO,
162 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
163 "(GPE %u to %u) - Ignoring GPE1",
164 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
165 AcpiGbl_FADT.Gpe1Base +
166 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
168 /* Ignore GPE1 block by setting the register count to zero */
174 /* Install GPE Block 1 */
176 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
177 &AcpiGbl_FADT.XGpe1Block, RegisterCount1,
178 AcpiGbl_FADT.Gpe1Base,
179 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
181 if (ACPI_FAILURE (Status))
183 ACPI_EXCEPTION ((AE_INFO, Status,
184 "Could not create GPE Block 1"));
188 * GPE0 and GPE1 do not have to be contiguous in the GPE number
189 * space. However, GPE0 always starts at GPE number zero.
191 GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
192 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
196 /* Exit if there are no GPE registers */
198 if ((RegisterCount0 + RegisterCount1) == 0)
200 /* GPEs are not required by ACPI, this is OK */
202 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
203 "There are no GPE blocks defined in the FADT\n"));
208 /* Check for Max GPE number out-of-range */
210 if (GpeNumberMax > ACPI_GPE_MAX)
212 ACPI_ERROR ((AE_INFO,
213 "Maximum GPE number from FADT is too large: 0x%X",
215 Status = AE_BAD_VALUE;
220 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
221 return_ACPI_STATUS (AE_OK);
225 /*******************************************************************************
227 * FUNCTION: AcpiEvUpdateGpes
229 * PARAMETERS: TableOwnerId - ID of the newly-loaded ACPI table
233 * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
234 * result of a Load() or LoadTable() operation. If new GPE
235 * methods have been installed, register the new methods.
237 ******************************************************************************/
241 ACPI_OWNER_ID TableOwnerId)
243 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
244 ACPI_GPE_BLOCK_INFO *GpeBlock;
245 ACPI_GPE_WALK_INFO WalkInfo;
246 ACPI_STATUS Status = AE_OK;
250 * Find any _Lxx/_Exx GPE methods that have just been loaded.
252 * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
255 * Examine the namespace underneath each GpeDevice within the
258 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
259 if (ACPI_FAILURE (Status))
265 WalkInfo.OwnerId = TableOwnerId;
266 WalkInfo.ExecuteByOwnerId = TRUE;
268 /* Walk the interrupt level descriptor list */
270 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
273 /* Walk all Gpe Blocks attached to this interrupt level */
275 GpeBlock = GpeXruptInfo->GpeBlockListHead;
278 WalkInfo.GpeBlock = GpeBlock;
279 WalkInfo.GpeDevice = GpeBlock->Node;
281 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
282 WalkInfo.GpeDevice, ACPI_UINT32_MAX,
283 ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
284 NULL, &WalkInfo, NULL);
285 if (ACPI_FAILURE (Status))
287 ACPI_EXCEPTION ((AE_INFO, Status,
288 "While decoding _Lxx/_Exx methods"));
291 GpeBlock = GpeBlock->Next;
294 GpeXruptInfo = GpeXruptInfo->Next;
299 ACPI_INFO ((AE_INFO, "Enabled %u new GPEs", WalkInfo.Count));
302 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
307 /*******************************************************************************
309 * FUNCTION: AcpiEvMatchGpeMethod
311 * PARAMETERS: Callback from WalkNamespace
315 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
316 * control method under the _GPE portion of the namespace.
317 * Extract the name and GPE type from the object, saving this
318 * information for quick lookup during GPE dispatch. Allows a
319 * per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
320 * WalkInfo parameter block.
322 * The name of each GPE control method is of the form:
323 * "_Lxx" or "_Exx", where:
324 * L - means that the GPE is level triggered
325 * E - means that the GPE is edge triggered
326 * xx - is the GPE number [in HEX]
328 * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
331 ******************************************************************************/
334 AcpiEvMatchGpeMethod (
335 ACPI_HANDLE ObjHandle,
340 ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
341 ACPI_GPE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
342 ACPI_GPE_EVENT_INFO *GpeEventInfo;
344 char Name[ACPI_NAME_SIZE + 1];
348 ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
351 /* Check if requested OwnerId matches this OwnerId */
353 if ((WalkInfo->ExecuteByOwnerId) &&
354 (MethodNode->OwnerId != WalkInfo->OwnerId))
356 return_ACPI_STATUS (AE_OK);
360 * Match and decode the _Lxx and _Exx GPE method names
362 * 1) Extract the method name and null terminate it
364 ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
365 Name[ACPI_NAME_SIZE] = 0;
367 /* 2) Name must begin with an underscore */
371 return_ACPI_STATUS (AE_OK); /* Ignore this method */
375 * 3) Edge/Level determination is based on the 2nd character
381 Type = ACPI_GPE_LEVEL_TRIGGERED;
385 Type = ACPI_GPE_EDGE_TRIGGERED;
389 /* Unknown method type, just ignore it */
391 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
392 "Ignoring unknown GPE method type: %s "
393 "(name not of form _Lxx or _Exx)", Name));
394 return_ACPI_STATUS (AE_OK);
397 /* 4) The last two characters of the name are the hex GPE Number */
399 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
400 if (GpeNumber == ACPI_UINT32_MAX)
402 /* Conversion failed; invalid method, just ignore it */
404 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
405 "Could not extract GPE number from name: %s "
406 "(name is not of form _Lxx or _Exx)", Name));
407 return_ACPI_STATUS (AE_OK);
410 /* Ensure that we have a valid GPE number for this GPE block */
412 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
416 * This GpeNumber is not valid for this GPE block, just ignore it.
417 * However, it may be valid for a different GPE block, since GPE0
418 * and GPE1 methods both appear under \_GPE.
420 return_ACPI_STATUS (AE_OK);
423 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
424 ACPI_GPE_DISPATCH_HANDLER)
426 /* If there is already a handler, ignore this GPE method */
428 return_ACPI_STATUS (AE_OK);
431 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
432 ACPI_GPE_DISPATCH_METHOD)
435 * If there is already a method, ignore this method. But check
436 * for a type mismatch (if both the _Lxx AND _Exx exist)
438 if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
440 ACPI_ERROR ((AE_INFO,
441 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
442 GpeNumber, GpeNumber, GpeNumber));
444 return_ACPI_STATUS (AE_OK);
448 * Add the GPE information from above to the GpeEventInfo block for
449 * use during dispatch of this GPE.
451 GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK);
452 GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
453 GpeEventInfo->Dispatch.MethodNode = MethodNode;
455 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
456 "Registered GPE method %s as GPE number 0x%.2X\n",
458 return_ACPI_STATUS (AE_OK);