ReactOS 0.4.15-dev-7918-g2a2556c
evgpeinit.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Module Name: evgpeinit - System GPE initialization and update
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2022, 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 MERCHANTABILITY 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.h"
45#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48
49#define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evgpeinit")
51
52#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53
54/*
55 * Note: History of _PRW support in ACPICA
56 *
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.
60 *
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.
69 */
70
71/*******************************************************************************
72 *
73 * FUNCTION: AcpiEvGpeInitialize
74 *
75 * PARAMETERS: None
76 *
77 * RETURN: Status
78 *
79 * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
80 *
81 ******************************************************************************/
82
85 void)
86{
87 UINT32 RegisterCount0 = 0;
88 UINT32 RegisterCount1 = 0;
89 UINT32 GpeNumberMax = 0;
91
92
93 ACPI_FUNCTION_TRACE (EvGpeInitialize);
94
95
97 "Initializing General Purpose Events (GPEs):\n"));
98
100 if (ACPI_FAILURE (Status))
101 {
103 }
104
105 /*
106 * Initialize the GPE Block(s) defined in the FADT
107 *
108 * Why the GPE register block lengths are divided by 2: From the ACPI
109 * Spec, section "General-Purpose Event Registers", we have:
110 *
111 * "Each register block contains two registers of equal length
112 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
113 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
114 * The length of the GPE1_STS and GPE1_EN registers is equal to
115 * half the GPE1_LEN. If a generic register block is not supported
116 * then its respective block pointer and block length values in the
117 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
118 * to be the same size."
119 */
120
121 /*
122 * Determine the maximum GPE number for this machine.
123 *
124 * Note: both GPE0 and GPE1 are optional, and either can exist without
125 * the other.
126 *
127 * If EITHER the register length OR the block address are zero, then that
128 * particular block is not supported.
129 */
130 if (AcpiGbl_FADT.Gpe0BlockLength &&
131 AcpiGbl_FADT.XGpe0Block.Address)
132 {
133 /* GPE block 0 exists (has both length and address > 0) */
134
135 RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
136 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
137
138 /* Install GPE Block 0 */
139
140 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
141 AcpiGbl_FADT.XGpe0Block.Address,
142 AcpiGbl_FADT.XGpe0Block.SpaceId,
143 RegisterCount0, 0,
144 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
145
146 if (ACPI_FAILURE (Status))
147 {
149 "Could not create GPE Block 0"));
150 }
151 }
152
153 if (AcpiGbl_FADT.Gpe1BlockLength &&
154 AcpiGbl_FADT.XGpe1Block.Address)
155 {
156 /* GPE block 1 exists (has both length and address > 0) */
157
158 RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
159
160 /* Check for GPE0/GPE1 overlap (if both banks exist) */
161
162 if ((RegisterCount0) &&
163 (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
164 {
166 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
167 "(GPE %u to %u) - Ignoring GPE1",
168 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
169 AcpiGbl_FADT.Gpe1Base +
170 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
171
172 /* Ignore GPE1 block by setting the register count to zero */
173
174 RegisterCount1 = 0;
175 }
176 else
177 {
178 /* Install GPE Block 1 */
179
180 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
181 AcpiGbl_FADT.XGpe1Block.Address,
182 AcpiGbl_FADT.XGpe1Block.SpaceId,
183 RegisterCount1,
184 AcpiGbl_FADT.Gpe1Base,
185 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
186
187 if (ACPI_FAILURE (Status))
188 {
190 "Could not create GPE Block 1"));
191 }
192
193 /*
194 * GPE0 and GPE1 do not have to be contiguous in the GPE number
195 * space. However, GPE0 always starts at GPE number zero.
196 */
197 }
198 }
199
200 /* Exit if there are no GPE registers */
201
202 if ((RegisterCount0 + RegisterCount1) == 0)
203 {
204 /* GPEs are not required by ACPI, this is OK */
205
207 "There are no GPE blocks defined in the FADT\n"));
208 goto Cleanup;
209 }
210
211
212Cleanup:
215}
216
217
218/*******************************************************************************
219 *
220 * FUNCTION: AcpiEvUpdateGpes
221 *
222 * PARAMETERS: TableOwnerId - ID of the newly-loaded ACPI table
223 *
224 * RETURN: None
225 *
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.
229 *
230 ******************************************************************************/
231
232void
234 ACPI_OWNER_ID TableOwnerId)
235{
236 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
237 ACPI_GPE_BLOCK_INFO *GpeBlock;
238 ACPI_GPE_WALK_INFO WalkInfo;
240
241
242 /*
243 * Find any _Lxx/_Exx GPE methods that have just been loaded.
244 *
245 * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
246 * enabled.
247 *
248 * Examine the namespace underneath each GpeDevice within the
249 * GpeBlock lists.
250 */
252 if (ACPI_FAILURE (Status))
253 {
254 return;
255 }
256
257 WalkInfo.Count = 0;
258 WalkInfo.OwnerId = TableOwnerId;
259 WalkInfo.ExecuteByOwnerId = TRUE;
260
261 /* Walk the interrupt level descriptor list */
262
263 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
264 while (GpeXruptInfo)
265 {
266 /* Walk all Gpe Blocks attached to this interrupt level */
267
268 GpeBlock = GpeXruptInfo->GpeBlockListHead;
269 while (GpeBlock)
270 {
271 WalkInfo.GpeBlock = GpeBlock;
272 WalkInfo.GpeDevice = GpeBlock->Node;
273
275 WalkInfo.GpeDevice, ACPI_UINT32_MAX,
277 NULL, &WalkInfo, NULL);
278 if (ACPI_FAILURE (Status))
279 {
281 "While decoding _Lxx/_Exx methods"));
282 }
283
284 GpeBlock = GpeBlock->Next;
285 }
286
287 GpeXruptInfo = GpeXruptInfo->Next;
288 }
289
290 if (WalkInfo.Count)
291 {
292 ACPI_INFO (("Enabled %u new GPEs", WalkInfo.Count));
293 }
294
296 return;
297}
298
299
300/*******************************************************************************
301 *
302 * FUNCTION: AcpiEvMatchGpeMethod
303 *
304 * PARAMETERS: Callback from WalkNamespace
305 *
306 * RETURN: Status
307 *
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.
314 *
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]
320 *
321 * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
322 * with that owner.
323 *
324 ******************************************************************************/
325
328 ACPI_HANDLE ObjHandle,
330 void *Context,
331 void **ReturnValue)
332{
333 ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
338 UINT8 TempGpeNumber;
339 char Name[ACPI_NAMESEG_SIZE + 1];
340 UINT8 Type;
341
342
343 ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
344
345
346 /* Check if requested OwnerId matches this OwnerId */
347
348 if ((WalkInfo->ExecuteByOwnerId) &&
349 (MethodNode->OwnerId != WalkInfo->OwnerId))
350 {
352 }
353
354 /*
355 * Match and decode the _Lxx and _Exx GPE method names
356 *
357 * 1) Extract the method name and null terminate it
358 */
359 ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
361
362 /* 2) Name must begin with an underscore */
363
364 if (Name[0] != '_')
365 {
366 return_ACPI_STATUS (AE_OK); /* Ignore this method */
367 }
368
369 /*
370 * 3) Edge/Level determination is based on the 2nd character
371 * of the method name
372 */
373 switch (Name[1])
374 {
375 case 'L':
376
378 break;
379
380 case 'E':
381
383 break;
384
385 default:
386
387 /* Unknown method type, just ignore it */
388
390 "Ignoring unknown GPE method type: %s "
391 "(name not of form _Lxx or _Exx)", Name));
393 }
394
395 /* 4) The last two characters of the name are the hex GPE Number */
396
397 Status = AcpiUtAsciiToHexByte (&Name[2], &TempGpeNumber);
398 if (ACPI_FAILURE (Status))
399 {
400 /* Conversion failed; invalid method, just ignore it */
401
403 "Could not extract GPE number from name: %s "
404 "(name is not of form _Lxx or _Exx)", Name));
406 }
407
408 /* Ensure that we have a valid GPE number for this GPE block */
409
410 GpeNumber = (UINT32) TempGpeNumber;
412 if (!GpeEventInfo)
413 {
414 /*
415 * This GpeNumber is not valid for this GPE block, just ignore it.
416 * However, it may be valid for a different GPE block, since GPE0
417 * and GPE1 methods both appear under \_GPE.
418 */
420 }
421
426 {
427 /* If there is already a handler, ignore this GPE method */
428
430 }
431
434 {
435 /*
436 * If there is already a method, ignore this method. But check
437 * for a type mismatch (if both the _Lxx AND _Exx exist)
438 */
440 {
442 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
444 }
446 }
447
448 /* Disable the GPE in case it's been enabled already. */
449
451
452 /*
453 * Add the GPE information from above to the GpeEventInfo block for
454 * use during dispatch of this GPE.
455 */
458 GpeEventInfo->Dispatch.MethodNode = MethodNode;
459
461 "Registered GPE method %s as GPE number 0x%.2X\n",
462 Name, GpeNumber));
464}
465
466#endif /* !ACPI_REDUCED_HARDWARE */
unsigned short UINT16
unsigned char UINT8
unsigned int UINT32
Type
Definition: Type.h:7
UINT32 void void ** ReturnValue
Definition: acevents.h:216
ACPI_GPE_EVENT_INFO * GpeEventInfo
Definition: acevents.h:195
ACPI_GPE_EVENT_INFO UINT32 GpeNumber
Definition: acevents.h:196
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_OK
Definition: acexcep.h:97
#define ACPI_MTX_NAMESPACE
Definition: aclocal.h:85
#define ACPI_MTX_EVENTS
Definition: aclocal.h:87
#define ACPI_MOVE_32_TO_32(d, s)
Definition: acmacros.h:148
#define ACPI_NS_WALK_NO_UNLOCK
Definition: acnamesp.h:76
ACPI_STATUS AcpiNsWalkNamespace(ACPI_OBJECT_TYPE Type, ACPI_HANDLE StartObject, UINT32 MaxDepth, UINT32 Flags, ACPI_WALK_CALLBACK DescendingCallback, ACPI_WALK_CALLBACK AscendingCallback, void *Context, void **ReturnValue)
Definition: nswalk.c:190
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define ACPI_DB_LOAD
Definition: acoutput.h:164
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_INFO(plist)
Definition: acoutput.h:237
#define ACPI_DEBUG_PRINT_RAW(pl)
Definition: acoutput.h:476
#define ACPI_DB_INIT
Definition: acoutput.h:151
#define ACPI_GPE_DISPATCH_MASK
Definition: actypes.h:824
#define ACPI_GPE_LEVEL_TRIGGERED
Definition: actypes.h:827
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_GPE_DISPATCH_TYPE(flags)
Definition: actypes.h:825
#define ACPI_GPE_DISPATCH_METHOD
Definition: actypes.h:820
#define ACPI_GPE_DISABLE
Definition: actypes.h:804
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
#define ACPI_UINT32_MAX
Definition: actypes.h:66
#define ACPI_GPE_DISPATCH_RAW_HANDLER
Definition: actypes.h:823
#define ACPI_GPE_XRUPT_TYPE_MASK
Definition: actypes.h:829
#define ACPI_GPE_EDGE_TRIGGERED
Definition: actypes.h:828
UINT16 ACPI_OWNER_ID
Definition: actypes.h:486
#define ACPI_GPE_REGISTER_WIDTH
Definition: actypes.h:407
#define ACPI_TYPE_METHOD
Definition: actypes.h:695
#define ACPI_GPE_DISPATCH_HANDLER
Definition: actypes.h:821
#define ACPI_NAMESEG_SIZE
Definition: actypes.h:415
ACPI_STATUS AcpiUtAcquireMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:256
ACPI_STATUS AcpiUtReleaseMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:348
ACPI_STATUS AcpiUtAsciiToHexByte(char *TwoAsciiChars, UINT8 *ReturnByte)
Definition: uthex.c:100
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static const WCHAR Cleanup[]
Definition: register.c:80
ACPI_GPE_EVENT_INFO * AcpiEvLowGetGpeInfo(UINT32 GpeNumber, ACPI_GPE_BLOCK_INFO *GpeBlock)
Definition: evgpe.c:327
ACPI_STATUS AcpiEvCreateGpeBlock(ACPI_NAMESPACE_NODE *GpeDevice, UINT64 Address, UINT8 SpaceId, UINT32 RegisterCount, UINT16 GpeBlockBaseNumber, UINT32 InterruptNumber, ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
Definition: evgpeblk.c:371
ACPI_STATUS AcpiEvMatchGpeMethod(ACPI_HANDLE ObjHandle, UINT32 Level, void *Context, void **ReturnValue)
Definition: evgpeinit.c:327
ACPI_STATUS AcpiEvGpeInitialize(void)
Definition: evgpeinit.c:84
void AcpiEvUpdateGpes(ACPI_OWNER_ID TableOwnerId)
Definition: evgpeinit.c:233
Status
Definition: gdiplustypes.h:25
ACPI_STATUS AcpiHwLowSetGpe(ACPI_GPE_EVENT_INFO *GpeEventInfo, UINT32 Action)
Definition: hwgpe.c:106
struct acpi_gpe_block_info * Next
Definition: aclocal.h:585
ACPI_NAMESPACE_NODE * Node
Definition: aclocal.h:583
union acpi_gpe_dispatch_info Dispatch
Definition: aclocal.h:554
ACPI_GPE_BLOCK_INFO * GpeBlock
Definition: aclocal.h:612
ACPI_NAMESPACE_NODE * GpeDevice
Definition: aclocal.h:611
BOOLEAN ExecuteByOwnerId
Definition: aclocal.h:615
ACPI_OWNER_ID OwnerId
Definition: aclocal.h:614
struct acpi_gpe_xrupt_info * Next
Definition: aclocal.h:603
ACPI_GPE_BLOCK_INFO * GpeBlockListHead
Definition: aclocal.h:604
ACPI_OWNER_ID OwnerId
Definition: aclocal.h:195
ACPI_NAME_UNION Name
Definition: aclocal.h:191
ACPI_NAMESPACE_NODE * MethodNode
Definition: aclocal.h:542
UINT32 Integer
Definition: actbl.h:393
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56