1 | /****************************************************************************** |
2 | * |
3 | * Module Name: evgpeinit - System GPE initialization and update |
4 | * |
5 | *****************************************************************************/ |
6 | |
7 | /* |
8 | * Copyright (C) 2000 - 2016, 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 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. |
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 | |
83 | ACPI_STATUS |
84 | AcpiEvGpeInitialize ( |
85 | void) |
86 | { |
87 | UINT32 RegisterCount0 = 0; |
88 | UINT32 RegisterCount1 = 0; |
89 | UINT32 GpeNumberMax = 0; |
90 | ACPI_STATUS Status; |
91 | |
92 | |
93 | ACPI_FUNCTION_TRACE (EvGpeInitialize); |
94 | |
95 | |
96 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, |
97 | "Initializing General Purpose Events (GPEs):\n" )); |
98 | |
99 | Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); |
100 | if (ACPI_FAILURE (Status)) |
101 | { |
102 | return_ACPI_STATUS (Status); |
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 | { |
148 | ACPI_EXCEPTION ((AE_INFO, Status, |
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 | { |
165 | ACPI_ERROR ((AE_INFO, |
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 | { |
189 | ACPI_EXCEPTION ((AE_INFO, Status, |
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 | GpeNumberMax = AcpiGbl_FADT.Gpe1Base + |
198 | ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1); |
199 | } |
200 | } |
201 | |
202 | /* Exit if there are no GPE registers */ |
203 | |
204 | if ((RegisterCount0 + RegisterCount1) == 0) |
205 | { |
206 | /* GPEs are not required by ACPI, this is OK */ |
207 | |
208 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, |
209 | "There are no GPE blocks defined in the FADT\n" )); |
210 | Status = AE_OK; |
211 | goto Cleanup; |
212 | } |
213 | |
214 | |
215 | Cleanup: |
216 | (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); |
217 | return_ACPI_STATUS (AE_OK); |
218 | } |
219 | |
220 | |
221 | /******************************************************************************* |
222 | * |
223 | * FUNCTION: AcpiEvUpdateGpes |
224 | * |
225 | * PARAMETERS: TableOwnerId - ID of the newly-loaded ACPI table |
226 | * |
227 | * RETURN: None |
228 | * |
229 | * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a |
230 | * result of a Load() or LoadTable() operation. If new GPE |
231 | * methods have been installed, register the new methods. |
232 | * |
233 | ******************************************************************************/ |
234 | |
235 | void |
236 | AcpiEvUpdateGpes ( |
237 | ACPI_OWNER_ID TableOwnerId) |
238 | { |
239 | ACPI_GPE_XRUPT_INFO *GpeXruptInfo; |
240 | ACPI_GPE_BLOCK_INFO *GpeBlock; |
241 | ACPI_GPE_WALK_INFO WalkInfo; |
242 | ACPI_STATUS Status = AE_OK; |
243 | |
244 | |
245 | /* |
246 | * Find any _Lxx/_Exx GPE methods that have just been loaded. |
247 | * |
248 | * Any GPEs that correspond to new _Lxx/_Exx methods are immediately |
249 | * enabled. |
250 | * |
251 | * Examine the namespace underneath each GpeDevice within the |
252 | * GpeBlock lists. |
253 | */ |
254 | Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS); |
255 | if (ACPI_FAILURE (Status)) |
256 | { |
257 | return; |
258 | } |
259 | |
260 | WalkInfo.Count = 0; |
261 | WalkInfo.OwnerId = TableOwnerId; |
262 | WalkInfo.ExecuteByOwnerId = TRUE; |
263 | |
264 | /* Walk the interrupt level descriptor list */ |
265 | |
266 | GpeXruptInfo = AcpiGbl_GpeXruptListHead; |
267 | while (GpeXruptInfo) |
268 | { |
269 | /* Walk all Gpe Blocks attached to this interrupt level */ |
270 | |
271 | GpeBlock = GpeXruptInfo->GpeBlockListHead; |
272 | while (GpeBlock) |
273 | { |
274 | WalkInfo.GpeBlock = GpeBlock; |
275 | WalkInfo.GpeDevice = GpeBlock->Node; |
276 | |
277 | Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, |
278 | WalkInfo.GpeDevice, ACPI_UINT32_MAX, |
279 | ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod, |
280 | NULL, &WalkInfo, NULL); |
281 | if (ACPI_FAILURE (Status)) |
282 | { |
283 | ACPI_EXCEPTION ((AE_INFO, Status, |
284 | "While decoding _Lxx/_Exx methods" )); |
285 | } |
286 | |
287 | GpeBlock = GpeBlock->Next; |
288 | } |
289 | |
290 | GpeXruptInfo = GpeXruptInfo->Next; |
291 | } |
292 | |
293 | if (WalkInfo.Count) |
294 | { |
295 | ACPI_INFO (("Enabled %u new GPEs" , WalkInfo.Count)); |
296 | } |
297 | |
298 | (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS); |
299 | return; |
300 | } |
301 | |
302 | |
303 | /******************************************************************************* |
304 | * |
305 | * FUNCTION: AcpiEvMatchGpeMethod |
306 | * |
307 | * PARAMETERS: Callback from WalkNamespace |
308 | * |
309 | * RETURN: Status |
310 | * |
311 | * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a |
312 | * control method under the _GPE portion of the namespace. |
313 | * Extract the name and GPE type from the object, saving this |
314 | * information for quick lookup during GPE dispatch. Allows a |
315 | * per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the |
316 | * WalkInfo parameter block. |
317 | * |
318 | * The name of each GPE control method is of the form: |
319 | * "_Lxx" or "_Exx", where: |
320 | * L - means that the GPE is level triggered |
321 | * E - means that the GPE is edge triggered |
322 | * xx - is the GPE number [in HEX] |
323 | * |
324 | * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods |
325 | * with that owner. |
326 | * |
327 | ******************************************************************************/ |
328 | |
329 | ACPI_STATUS |
330 | AcpiEvMatchGpeMethod ( |
331 | ACPI_HANDLE ObjHandle, |
332 | UINT32 Level, |
333 | void *Context, |
334 | void **ReturnValue) |
335 | { |
336 | ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); |
337 | ACPI_GPE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context); |
338 | ACPI_GPE_EVENT_INFO *GpeEventInfo; |
339 | ACPI_STATUS Status; |
340 | UINT32 GpeNumber; |
341 | UINT8 TempGpeNumber; |
342 | char Name[ACPI_NAME_SIZE + 1]; |
343 | UINT8 Type; |
344 | |
345 | |
346 | ACPI_FUNCTION_TRACE (EvMatchGpeMethod); |
347 | |
348 | |
349 | /* Check if requested OwnerId matches this OwnerId */ |
350 | |
351 | if ((WalkInfo->ExecuteByOwnerId) && |
352 | (MethodNode->OwnerId != WalkInfo->OwnerId)) |
353 | { |
354 | return_ACPI_STATUS (AE_OK); |
355 | } |
356 | |
357 | /* |
358 | * Match and decode the _Lxx and _Exx GPE method names |
359 | * |
360 | * 1) Extract the method name and null terminate it |
361 | */ |
362 | ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer); |
363 | Name[ACPI_NAME_SIZE] = 0; |
364 | |
365 | /* 2) Name must begin with an underscore */ |
366 | |
367 | if (Name[0] != '_') |
368 | { |
369 | return_ACPI_STATUS (AE_OK); /* Ignore this method */ |
370 | } |
371 | |
372 | /* |
373 | * 3) Edge/Level determination is based on the 2nd character |
374 | * of the method name |
375 | */ |
376 | switch (Name[1]) |
377 | { |
378 | case 'L': |
379 | |
380 | Type = ACPI_GPE_LEVEL_TRIGGERED; |
381 | break; |
382 | |
383 | case 'E': |
384 | |
385 | Type = ACPI_GPE_EDGE_TRIGGERED; |
386 | break; |
387 | |
388 | default: |
389 | |
390 | /* Unknown method type, just ignore it */ |
391 | |
392 | ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, |
393 | "Ignoring unknown GPE method type: %s " |
394 | "(name not of form _Lxx or _Exx)" , Name)); |
395 | return_ACPI_STATUS (AE_OK); |
396 | } |
397 | |
398 | /* 4) The last two characters of the name are the hex GPE Number */ |
399 | |
400 | Status = AcpiUtAsciiToHexByte (&Name[2], &TempGpeNumber); |
401 | if (ACPI_FAILURE (Status)) |
402 | { |
403 | /* Conversion failed; invalid method, just ignore it */ |
404 | |
405 | ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, |
406 | "Could not extract GPE number from name: %s " |
407 | "(name is not of form _Lxx or _Exx)" , Name)); |
408 | return_ACPI_STATUS (AE_OK); |
409 | } |
410 | |
411 | /* Ensure that we have a valid GPE number for this GPE block */ |
412 | |
413 | GpeNumber = (UINT32) TempGpeNumber; |
414 | GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock); |
415 | if (!GpeEventInfo) |
416 | { |
417 | /* |
418 | * This GpeNumber is not valid for this GPE block, just ignore it. |
419 | * However, it may be valid for a different GPE block, since GPE0 |
420 | * and GPE1 methods both appear under \_GPE. |
421 | */ |
422 | return_ACPI_STATUS (AE_OK); |
423 | } |
424 | |
425 | if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == |
426 | ACPI_GPE_DISPATCH_HANDLER) || |
427 | (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == |
428 | ACPI_GPE_DISPATCH_RAW_HANDLER)) |
429 | { |
430 | /* If there is already a handler, ignore this GPE method */ |
431 | |
432 | return_ACPI_STATUS (AE_OK); |
433 | } |
434 | |
435 | if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == |
436 | ACPI_GPE_DISPATCH_METHOD) |
437 | { |
438 | /* |
439 | * If there is already a method, ignore this method. But check |
440 | * for a type mismatch (if both the _Lxx AND _Exx exist) |
441 | */ |
442 | if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK)) |
443 | { |
444 | ACPI_ERROR ((AE_INFO, |
445 | "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods" , |
446 | GpeNumber, GpeNumber, GpeNumber)); |
447 | } |
448 | return_ACPI_STATUS (AE_OK); |
449 | } |
450 | |
451 | /* Disable the GPE in case it's been enabled already. */ |
452 | |
453 | (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE); |
454 | |
455 | /* |
456 | * Add the GPE information from above to the GpeEventInfo block for |
457 | * use during dispatch of this GPE. |
458 | */ |
459 | GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK); |
460 | GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD); |
461 | GpeEventInfo->Dispatch.MethodNode = MethodNode; |
462 | |
463 | ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, |
464 | "Registered GPE method %s as GPE number 0x%.2X\n" , |
465 | Name, GpeNumber)); |
466 | return_ACPI_STATUS (AE_OK); |
467 | } |
468 | |
469 | #endif /* !ACPI_REDUCED_HARDWARE */ |
470 | |