Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / events / evgpeinit.c
blobdae7dc1ffd9e65f07c5aab2775c975d5db9c27c9
1 /******************************************************************************
3 * Module Name: evgpeinit - System GPE initialization and update
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
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.
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.
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.
45 #include "acpi.h"
46 #include "accommon.h"
47 #include "acevents.h"
48 #include "acnamesp.h"
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME ("evgpeinit")
53 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
56 * Note: History of _PRW support in ACPICA
58 * Originally (2000 - 2010), the GPE initialization code performed a walk of
59 * the entire namespace to execute the _PRW methods and detect all GPEs
60 * capable of waking the system.
62 * As of 10/2010, the _PRW method execution has been removed since it is
63 * actually unnecessary. The host OS must in fact execute all _PRW methods
64 * in order to identify the device/power-resource dependencies. We now put
65 * the onus on the host OS to identify the wake GPEs as part of this process
66 * and to inform ACPICA of these GPEs via the AcpiSetupGpeForWake interface. This
67 * not only reduces the complexity of the ACPICA initialization code, but in
68 * some cases (on systems with very large namespaces) it should reduce the
69 * kernel boot time as well.
72 /*******************************************************************************
74 * FUNCTION: AcpiEvGpeInitialize
76 * PARAMETERS: None
78 * RETURN: Status
80 * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
82 ******************************************************************************/
84 ACPI_STATUS
85 AcpiEvGpeInitialize (
86 void)
88 UINT32 RegisterCount0 = 0;
89 UINT32 RegisterCount1 = 0;
90 UINT32 GpeNumberMax = 0;
91 ACPI_STATUS Status;
94 ACPI_FUNCTION_TRACE (EvGpeInitialize);
97 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
98 "Initializing General Purpose Events (GPEs):\n"));
100 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
101 if (ACPI_FAILURE (Status))
103 return_ACPI_STATUS (Status);
107 * Initialize the GPE Block(s) defined in the FADT
109 * Why the GPE register block lengths are divided by 2: From the ACPI
110 * Spec, section "General-Purpose Event Registers", we have:
112 * "Each register block contains two registers of equal length
113 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
114 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
115 * The length of the GPE1_STS and GPE1_EN registers is equal to
116 * half the GPE1_LEN. If a generic register block is not supported
117 * then its respective block pointer and block length values in the
118 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
119 * to be the same size."
123 * Determine the maximum GPE number for this machine.
125 * Note: both GPE0 and GPE1 are optional, and either can exist without
126 * the other.
128 * If EITHER the register length OR the block address are zero, then that
129 * particular block is not supported.
131 if (AcpiGbl_FADT.Gpe0BlockLength &&
132 AcpiGbl_FADT.XGpe0Block.Address)
134 /* GPE block 0 exists (has both length and address > 0) */
136 RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
137 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
139 /* Install GPE Block 0 */
141 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
142 &AcpiGbl_FADT.XGpe0Block, RegisterCount0, 0,
143 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
145 if (ACPI_FAILURE (Status))
147 ACPI_EXCEPTION ((AE_INFO, Status,
148 "Could not create GPE Block 0"));
152 if (AcpiGbl_FADT.Gpe1BlockLength &&
153 AcpiGbl_FADT.XGpe1Block.Address)
155 /* GPE block 1 exists (has both length and address > 0) */
157 RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
159 /* Check for GPE0/GPE1 overlap (if both banks exist) */
161 if ((RegisterCount0) &&
162 (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
164 ACPI_ERROR ((AE_INFO,
165 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
166 "(GPE %u to %u) - Ignoring GPE1",
167 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
168 AcpiGbl_FADT.Gpe1Base +
169 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
171 /* Ignore GPE1 block by setting the register count to zero */
173 RegisterCount1 = 0;
175 else
177 /* Install GPE Block 1 */
179 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
180 &AcpiGbl_FADT.XGpe1Block, RegisterCount1,
181 AcpiGbl_FADT.Gpe1Base,
182 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
184 if (ACPI_FAILURE (Status))
186 ACPI_EXCEPTION ((AE_INFO, Status,
187 "Could not create GPE Block 1"));
191 * GPE0 and GPE1 do not have to be contiguous in the GPE number
192 * space. However, GPE0 always starts at GPE number zero.
194 GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
195 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
199 /* Exit if there are no GPE registers */
201 if ((RegisterCount0 + RegisterCount1) == 0)
203 /* GPEs are not required by ACPI, this is OK */
205 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
206 "There are no GPE blocks defined in the FADT\n"));
207 Status = AE_OK;
208 goto Cleanup;
212 Cleanup:
213 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
214 return_ACPI_STATUS (AE_OK);
218 /*******************************************************************************
220 * FUNCTION: AcpiEvUpdateGpes
222 * PARAMETERS: TableOwnerId - ID of the newly-loaded ACPI table
224 * RETURN: None
226 * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
227 * result of a Load() or LoadTable() operation. If new GPE
228 * methods have been installed, register the new methods.
230 ******************************************************************************/
232 void
233 AcpiEvUpdateGpes (
234 ACPI_OWNER_ID TableOwnerId)
236 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
237 ACPI_GPE_BLOCK_INFO *GpeBlock;
238 ACPI_GPE_WALK_INFO WalkInfo;
239 ACPI_STATUS Status = AE_OK;
243 * Find any _Lxx/_Exx GPE methods that have just been loaded.
245 * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
246 * enabled.
248 * Examine the namespace underneath each GpeDevice within the
249 * GpeBlock lists.
251 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
252 if (ACPI_FAILURE (Status))
254 return;
257 WalkInfo.Count = 0;
258 WalkInfo.OwnerId = TableOwnerId;
259 WalkInfo.ExecuteByOwnerId = TRUE;
261 /* Walk the interrupt level descriptor list */
263 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
264 while (GpeXruptInfo)
266 /* Walk all Gpe Blocks attached to this interrupt level */
268 GpeBlock = GpeXruptInfo->GpeBlockListHead;
269 while (GpeBlock)
271 WalkInfo.GpeBlock = GpeBlock;
272 WalkInfo.GpeDevice = GpeBlock->Node;
274 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
275 WalkInfo.GpeDevice, ACPI_UINT32_MAX,
276 ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
277 NULL, &WalkInfo, NULL);
278 if (ACPI_FAILURE (Status))
280 ACPI_EXCEPTION ((AE_INFO, Status,
281 "While decoding _Lxx/_Exx methods"));
284 GpeBlock = GpeBlock->Next;
287 GpeXruptInfo = GpeXruptInfo->Next;
290 if (WalkInfo.Count)
292 ACPI_INFO ((AE_INFO, "Enabled %u new GPEs", WalkInfo.Count));
295 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
296 return;
300 /*******************************************************************************
302 * FUNCTION: AcpiEvMatchGpeMethod
304 * PARAMETERS: Callback from WalkNamespace
306 * RETURN: Status
308 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
309 * control method under the _GPE portion of the namespace.
310 * Extract the name and GPE type from the object, saving this
311 * information for quick lookup during GPE dispatch. Allows a
312 * per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
313 * WalkInfo parameter block.
315 * The name of each GPE control method is of the form:
316 * "_Lxx" or "_Exx", where:
317 * L - means that the GPE is level triggered
318 * E - means that the GPE is edge triggered
319 * xx - is the GPE number [in HEX]
321 * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
322 * with that owner.
324 ******************************************************************************/
326 ACPI_STATUS
327 AcpiEvMatchGpeMethod (
328 ACPI_HANDLE ObjHandle,
329 UINT32 Level,
330 void *Context,
331 void **ReturnValue)
333 ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
334 ACPI_GPE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
335 ACPI_GPE_EVENT_INFO *GpeEventInfo;
336 UINT32 GpeNumber;
337 char Name[ACPI_NAME_SIZE + 1];
338 UINT8 Type;
341 ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
344 /* Check if requested OwnerId matches this OwnerId */
346 if ((WalkInfo->ExecuteByOwnerId) &&
347 (MethodNode->OwnerId != WalkInfo->OwnerId))
349 return_ACPI_STATUS (AE_OK);
353 * Match and decode the _Lxx and _Exx GPE method names
355 * 1) Extract the method name and null terminate it
357 ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
358 Name[ACPI_NAME_SIZE] = 0;
360 /* 2) Name must begin with an underscore */
362 if (Name[0] != '_')
364 return_ACPI_STATUS (AE_OK); /* Ignore this method */
368 * 3) Edge/Level determination is based on the 2nd character
369 * of the method name
371 switch (Name[1])
373 case 'L':
375 Type = ACPI_GPE_LEVEL_TRIGGERED;
376 break;
378 case 'E':
380 Type = ACPI_GPE_EDGE_TRIGGERED;
381 break;
383 default:
385 /* Unknown method type, just ignore it */
387 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
388 "Ignoring unknown GPE method type: %s "
389 "(name not of form _Lxx or _Exx)", Name));
390 return_ACPI_STATUS (AE_OK);
393 /* 4) The last two characters of the name are the hex GPE Number */
395 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
396 if (GpeNumber == ACPI_UINT32_MAX)
398 /* Conversion failed; invalid method, just ignore it */
400 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
401 "Could not extract GPE number from name: %s "
402 "(name is not of form _Lxx or _Exx)", Name));
403 return_ACPI_STATUS (AE_OK);
406 /* Ensure that we have a valid GPE number for this GPE block */
408 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
409 if (!GpeEventInfo)
412 * This GpeNumber is not valid for this GPE block, just ignore it.
413 * However, it may be valid for a different GPE block, since GPE0
414 * and GPE1 methods both appear under \_GPE.
416 return_ACPI_STATUS (AE_OK);
419 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
420 ACPI_GPE_DISPATCH_HANDLER)
422 /* If there is already a handler, ignore this GPE method */
424 return_ACPI_STATUS (AE_OK);
427 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
428 ACPI_GPE_DISPATCH_METHOD)
431 * If there is already a method, ignore this method. But check
432 * for a type mismatch (if both the _Lxx AND _Exx exist)
434 if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
436 ACPI_ERROR ((AE_INFO,
437 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
438 GpeNumber, GpeNumber, GpeNumber));
440 return_ACPI_STATUS (AE_OK);
444 * Add the GPE information from above to the GpeEventInfo block for
445 * use during dispatch of this GPE.
447 GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK);
448 GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
449 GpeEventInfo->Dispatch.MethodNode = MethodNode;
451 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
452 "Registered GPE method %s as GPE number 0x%.2X\n",
453 Name, GpeNumber));
454 return_ACPI_STATUS (AE_OK);
457 #endif /* !ACPI_REDUCED_HARDWARE */