1*4882a593Smuzhiyun // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Module Name: evgpeinit - System GPE initialization and update
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2000 - 2020, Intel Corp.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun *****************************************************************************/
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <acpi/acpi.h>
11*4882a593Smuzhiyun #include "accommon.h"
12*4882a593Smuzhiyun #include "acevents.h"
13*4882a593Smuzhiyun #include "acnamesp.h"
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #define _COMPONENT ACPI_EVENTS
16*4882a593Smuzhiyun ACPI_MODULE_NAME("evgpeinit")
17*4882a593Smuzhiyun #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
18*4882a593Smuzhiyun /*
19*4882a593Smuzhiyun * Note: History of _PRW support in ACPICA
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * Originally (2000 - 2010), the GPE initialization code performed a walk of
22*4882a593Smuzhiyun * the entire namespace to execute the _PRW methods and detect all GPEs
23*4882a593Smuzhiyun * capable of waking the system.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * As of 10/2010, the _PRW method execution has been removed since it is
26*4882a593Smuzhiyun * actually unnecessary. The host OS must in fact execute all _PRW methods
27*4882a593Smuzhiyun * in order to identify the device/power-resource dependencies. We now put
28*4882a593Smuzhiyun * the onus on the host OS to identify the wake GPEs as part of this process
29*4882a593Smuzhiyun * and to inform ACPICA of these GPEs via the acpi_setup_gpe_for_wake interface. This
30*4882a593Smuzhiyun * not only reduces the complexity of the ACPICA initialization code, but in
31*4882a593Smuzhiyun * some cases (on systems with very large namespaces) it should reduce the
32*4882a593Smuzhiyun * kernel boot time as well.
33*4882a593Smuzhiyun */
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #ifdef ACPI_GPE_USE_LOGICAL_ADDRESSES
36*4882a593Smuzhiyun #define ACPI_FADT_GPE_BLOCK_ADDRESS(N) \
37*4882a593Smuzhiyun acpi_gbl_FADT.xgpe##N##_block.space_id == \
38*4882a593Smuzhiyun ACPI_ADR_SPACE_SYSTEM_MEMORY ? \
39*4882a593Smuzhiyun (u64)acpi_gbl_xgpe##N##_block_logical_address : \
40*4882a593Smuzhiyun acpi_gbl_FADT.xgpe##N##_block.address
41*4882a593Smuzhiyun #else
42*4882a593Smuzhiyun #define ACPI_FADT_GPE_BLOCK_ADDRESS(N) acpi_gbl_FADT.xgpe##N##_block.address
43*4882a593Smuzhiyun #endif /* ACPI_GPE_USE_LOGICAL_ADDRESSES */
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /*******************************************************************************
46*4882a593Smuzhiyun *
47*4882a593Smuzhiyun * FUNCTION: acpi_ev_gpe_initialize
48*4882a593Smuzhiyun *
49*4882a593Smuzhiyun * PARAMETERS: None
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * RETURN: Status
52*4882a593Smuzhiyun *
53*4882a593Smuzhiyun * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
54*4882a593Smuzhiyun *
55*4882a593Smuzhiyun ******************************************************************************/
acpi_ev_gpe_initialize(void)56*4882a593Smuzhiyun acpi_status acpi_ev_gpe_initialize(void)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun u32 register_count0 = 0;
59*4882a593Smuzhiyun u32 register_count1 = 0;
60*4882a593Smuzhiyun u32 gpe_number_max = 0;
61*4882a593Smuzhiyun acpi_status status;
62*4882a593Smuzhiyun u64 address;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun ACPI_FUNCTION_TRACE(ev_gpe_initialize);
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
67*4882a593Smuzhiyun "Initializing General Purpose Events (GPEs):\n"));
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
70*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
71*4882a593Smuzhiyun return_ACPI_STATUS(status);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun * Initialize the GPE Block(s) defined in the FADT
76*4882a593Smuzhiyun *
77*4882a593Smuzhiyun * Why the GPE register block lengths are divided by 2: From the ACPI
78*4882a593Smuzhiyun * Spec, section "General-Purpose Event Registers", we have:
79*4882a593Smuzhiyun *
80*4882a593Smuzhiyun * "Each register block contains two registers of equal length
81*4882a593Smuzhiyun * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
82*4882a593Smuzhiyun * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
83*4882a593Smuzhiyun * The length of the GPE1_STS and GPE1_EN registers is equal to
84*4882a593Smuzhiyun * half the GPE1_LEN. If a generic register block is not supported
85*4882a593Smuzhiyun * then its respective block pointer and block length values in the
86*4882a593Smuzhiyun * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
87*4882a593Smuzhiyun * to be the same size."
88*4882a593Smuzhiyun */
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun * Determine the maximum GPE number for this machine.
92*4882a593Smuzhiyun *
93*4882a593Smuzhiyun * Note: both GPE0 and GPE1 are optional, and either can exist without
94*4882a593Smuzhiyun * the other.
95*4882a593Smuzhiyun *
96*4882a593Smuzhiyun * If EITHER the register length OR the block address are zero, then that
97*4882a593Smuzhiyun * particular block is not supported.
98*4882a593Smuzhiyun */
99*4882a593Smuzhiyun address = ACPI_FADT_GPE_BLOCK_ADDRESS(0);
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun if (acpi_gbl_FADT.gpe0_block_length && address) {
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* GPE block 0 exists (has both length and address > 0) */
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun register_count0 = (u16)(acpi_gbl_FADT.gpe0_block_length / 2);
106*4882a593Smuzhiyun gpe_number_max =
107*4882a593Smuzhiyun (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun /* Install GPE Block 0 */
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
112*4882a593Smuzhiyun address,
113*4882a593Smuzhiyun acpi_gbl_FADT.xgpe0_block.
114*4882a593Smuzhiyun space_id, register_count0, 0,
115*4882a593Smuzhiyun acpi_gbl_FADT.sci_interrupt,
116*4882a593Smuzhiyun &acpi_gbl_gpe_fadt_blocks[0]);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
119*4882a593Smuzhiyun ACPI_EXCEPTION((AE_INFO, status,
120*4882a593Smuzhiyun "Could not create GPE Block 0"));
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun address = ACPI_FADT_GPE_BLOCK_ADDRESS(1);
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun if (acpi_gbl_FADT.gpe1_block_length && address) {
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun /* GPE block 1 exists (has both length and address > 0) */
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun register_count1 = (u16)(acpi_gbl_FADT.gpe1_block_length / 2);
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /* Check for GPE0/GPE1 overlap (if both banks exist) */
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun if ((register_count0) &&
135*4882a593Smuzhiyun (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
136*4882a593Smuzhiyun ACPI_ERROR((AE_INFO,
137*4882a593Smuzhiyun "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
138*4882a593Smuzhiyun "(GPE %u to %u) - Ignoring GPE1",
139*4882a593Smuzhiyun gpe_number_max, acpi_gbl_FADT.gpe1_base,
140*4882a593Smuzhiyun acpi_gbl_FADT.gpe1_base +
141*4882a593Smuzhiyun ((register_count1 *
142*4882a593Smuzhiyun ACPI_GPE_REGISTER_WIDTH) - 1)));
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /* Ignore GPE1 block by setting the register count to zero */
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun register_count1 = 0;
147*4882a593Smuzhiyun } else {
148*4882a593Smuzhiyun /* Install GPE Block 1 */
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun status =
151*4882a593Smuzhiyun acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
152*4882a593Smuzhiyun address,
153*4882a593Smuzhiyun acpi_gbl_FADT.xgpe1_block.
154*4882a593Smuzhiyun space_id, register_count1,
155*4882a593Smuzhiyun acpi_gbl_FADT.gpe1_base,
156*4882a593Smuzhiyun acpi_gbl_FADT.
157*4882a593Smuzhiyun sci_interrupt,
158*4882a593Smuzhiyun &acpi_gbl_gpe_fadt_blocks
159*4882a593Smuzhiyun [1]);
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
162*4882a593Smuzhiyun ACPI_EXCEPTION((AE_INFO, status,
163*4882a593Smuzhiyun "Could not create GPE Block 1"));
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun /*
167*4882a593Smuzhiyun * GPE0 and GPE1 do not have to be contiguous in the GPE number
168*4882a593Smuzhiyun * space. However, GPE0 always starts at GPE number zero.
169*4882a593Smuzhiyun */
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun /* Exit if there are no GPE registers */
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun if ((register_count0 + register_count1) == 0) {
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /* GPEs are not required by ACPI, this is OK */
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_INIT,
180*4882a593Smuzhiyun "There are no GPE blocks defined in the FADT\n"));
181*4882a593Smuzhiyun goto cleanup;
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun cleanup:
185*4882a593Smuzhiyun (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
186*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun /*******************************************************************************
190*4882a593Smuzhiyun *
191*4882a593Smuzhiyun * FUNCTION: acpi_ev_update_gpes
192*4882a593Smuzhiyun *
193*4882a593Smuzhiyun * PARAMETERS: table_owner_id - ID of the newly-loaded ACPI table
194*4882a593Smuzhiyun *
195*4882a593Smuzhiyun * RETURN: None
196*4882a593Smuzhiyun *
197*4882a593Smuzhiyun * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
198*4882a593Smuzhiyun * result of a Load() or load_table() operation. If new GPE
199*4882a593Smuzhiyun * methods have been installed, register the new methods.
200*4882a593Smuzhiyun *
201*4882a593Smuzhiyun ******************************************************************************/
202*4882a593Smuzhiyun
acpi_ev_update_gpes(acpi_owner_id table_owner_id)203*4882a593Smuzhiyun void acpi_ev_update_gpes(acpi_owner_id table_owner_id)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun struct acpi_gpe_xrupt_info *gpe_xrupt_info;
206*4882a593Smuzhiyun struct acpi_gpe_block_info *gpe_block;
207*4882a593Smuzhiyun struct acpi_gpe_walk_info walk_info;
208*4882a593Smuzhiyun acpi_status status = AE_OK;
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun /*
211*4882a593Smuzhiyun * Find any _Lxx/_Exx GPE methods that have just been loaded.
212*4882a593Smuzhiyun *
213*4882a593Smuzhiyun * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
214*4882a593Smuzhiyun * enabled.
215*4882a593Smuzhiyun *
216*4882a593Smuzhiyun * Examine the namespace underneath each gpe_device within the
217*4882a593Smuzhiyun * gpe_block lists.
218*4882a593Smuzhiyun */
219*4882a593Smuzhiyun status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
220*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
221*4882a593Smuzhiyun return;
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun walk_info.count = 0;
225*4882a593Smuzhiyun walk_info.owner_id = table_owner_id;
226*4882a593Smuzhiyun walk_info.execute_by_owner_id = TRUE;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /* Walk the interrupt level descriptor list */
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
231*4882a593Smuzhiyun while (gpe_xrupt_info) {
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun /* Walk all Gpe Blocks attached to this interrupt level */
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun gpe_block = gpe_xrupt_info->gpe_block_list_head;
236*4882a593Smuzhiyun while (gpe_block) {
237*4882a593Smuzhiyun walk_info.gpe_block = gpe_block;
238*4882a593Smuzhiyun walk_info.gpe_device = gpe_block->node;
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD,
241*4882a593Smuzhiyun walk_info.gpe_device,
242*4882a593Smuzhiyun ACPI_UINT32_MAX,
243*4882a593Smuzhiyun ACPI_NS_WALK_NO_UNLOCK,
244*4882a593Smuzhiyun acpi_ev_match_gpe_method,
245*4882a593Smuzhiyun NULL, &walk_info, NULL);
246*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
247*4882a593Smuzhiyun ACPI_EXCEPTION((AE_INFO, status,
248*4882a593Smuzhiyun "While decoding _Lxx/_Exx methods"));
249*4882a593Smuzhiyun }
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun gpe_block = gpe_block->next;
252*4882a593Smuzhiyun }
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun gpe_xrupt_info = gpe_xrupt_info->next;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (walk_info.count) {
258*4882a593Smuzhiyun ACPI_INFO(("Enabled %u new GPEs", walk_info.count));
259*4882a593Smuzhiyun }
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
262*4882a593Smuzhiyun return;
263*4882a593Smuzhiyun }
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun /*******************************************************************************
266*4882a593Smuzhiyun *
267*4882a593Smuzhiyun * FUNCTION: acpi_ev_match_gpe_method
268*4882a593Smuzhiyun *
269*4882a593Smuzhiyun * PARAMETERS: Callback from walk_namespace
270*4882a593Smuzhiyun *
271*4882a593Smuzhiyun * RETURN: Status
272*4882a593Smuzhiyun *
273*4882a593Smuzhiyun * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
274*4882a593Smuzhiyun * control method under the _GPE portion of the namespace.
275*4882a593Smuzhiyun * Extract the name and GPE type from the object, saving this
276*4882a593Smuzhiyun * information for quick lookup during GPE dispatch. Allows a
277*4882a593Smuzhiyun * per-owner_id evaluation if execute_by_owner_id is TRUE in the
278*4882a593Smuzhiyun * walk_info parameter block.
279*4882a593Smuzhiyun *
280*4882a593Smuzhiyun * The name of each GPE control method is of the form:
281*4882a593Smuzhiyun * "_Lxx" or "_Exx", where:
282*4882a593Smuzhiyun * L - means that the GPE is level triggered
283*4882a593Smuzhiyun * E - means that the GPE is edge triggered
284*4882a593Smuzhiyun * xx - is the GPE number [in HEX]
285*4882a593Smuzhiyun *
286*4882a593Smuzhiyun * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods
287*4882a593Smuzhiyun * with that owner.
288*4882a593Smuzhiyun *
289*4882a593Smuzhiyun ******************************************************************************/
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun acpi_status
acpi_ev_match_gpe_method(acpi_handle obj_handle,u32 level,void * context,void ** return_value)292*4882a593Smuzhiyun acpi_ev_match_gpe_method(acpi_handle obj_handle,
293*4882a593Smuzhiyun u32 level, void *context, void **return_value)
294*4882a593Smuzhiyun {
295*4882a593Smuzhiyun struct acpi_namespace_node *method_node =
296*4882a593Smuzhiyun ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
297*4882a593Smuzhiyun struct acpi_gpe_walk_info *walk_info =
298*4882a593Smuzhiyun ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
299*4882a593Smuzhiyun struct acpi_gpe_event_info *gpe_event_info;
300*4882a593Smuzhiyun acpi_status status;
301*4882a593Smuzhiyun u32 gpe_number;
302*4882a593Smuzhiyun u8 temp_gpe_number;
303*4882a593Smuzhiyun char name[ACPI_NAMESEG_SIZE + 1];
304*4882a593Smuzhiyun u8 type;
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun ACPI_FUNCTION_TRACE(ev_match_gpe_method);
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun /* Check if requested owner_id matches this owner_id */
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun if ((walk_info->execute_by_owner_id) &&
311*4882a593Smuzhiyun (method_node->owner_id != walk_info->owner_id)) {
312*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun /*
316*4882a593Smuzhiyun * Match and decode the _Lxx and _Exx GPE method names
317*4882a593Smuzhiyun *
318*4882a593Smuzhiyun * 1) Extract the method name and null terminate it
319*4882a593Smuzhiyun */
320*4882a593Smuzhiyun ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
321*4882a593Smuzhiyun name[ACPI_NAMESEG_SIZE] = 0;
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun /* 2) Name must begin with an underscore */
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun if (name[0] != '_') {
326*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK); /* Ignore this method */
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun /*
330*4882a593Smuzhiyun * 3) Edge/Level determination is based on the 2nd character
331*4882a593Smuzhiyun * of the method name
332*4882a593Smuzhiyun */
333*4882a593Smuzhiyun switch (name[1]) {
334*4882a593Smuzhiyun case 'L':
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun type = ACPI_GPE_LEVEL_TRIGGERED;
337*4882a593Smuzhiyun break;
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun case 'E':
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun type = ACPI_GPE_EDGE_TRIGGERED;
342*4882a593Smuzhiyun break;
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun default:
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /* Unknown method type, just ignore it */
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
349*4882a593Smuzhiyun "Ignoring unknown GPE method type: %s "
350*4882a593Smuzhiyun "(name not of form _Lxx or _Exx)", name));
351*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /* 4) The last two characters of the name are the hex GPE Number */
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun status = acpi_ut_ascii_to_hex_byte(&name[2], &temp_gpe_number);
357*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun /* Conversion failed; invalid method, just ignore it */
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
362*4882a593Smuzhiyun "Could not extract GPE number from name: %s "
363*4882a593Smuzhiyun "(name is not of form _Lxx or _Exx)", name));
364*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun /* Ensure that we have a valid GPE number for this GPE block */
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun gpe_number = (u32)temp_gpe_number;
370*4882a593Smuzhiyun gpe_event_info =
371*4882a593Smuzhiyun acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
372*4882a593Smuzhiyun if (!gpe_event_info) {
373*4882a593Smuzhiyun /*
374*4882a593Smuzhiyun * This gpe_number is not valid for this GPE block, just ignore it.
375*4882a593Smuzhiyun * However, it may be valid for a different GPE block, since GPE0
376*4882a593Smuzhiyun * and GPE1 methods both appear under \_GPE.
377*4882a593Smuzhiyun */
378*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
382*4882a593Smuzhiyun ACPI_GPE_DISPATCH_HANDLER) ||
383*4882a593Smuzhiyun (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
384*4882a593Smuzhiyun ACPI_GPE_DISPATCH_RAW_HANDLER)) {
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun /* If there is already a handler, ignore this GPE method */
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
389*4882a593Smuzhiyun }
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
392*4882a593Smuzhiyun ACPI_GPE_DISPATCH_METHOD) {
393*4882a593Smuzhiyun /*
394*4882a593Smuzhiyun * If there is already a method, ignore this method. But check
395*4882a593Smuzhiyun * for a type mismatch (if both the _Lxx AND _Exx exist)
396*4882a593Smuzhiyun */
397*4882a593Smuzhiyun if (type != (gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
398*4882a593Smuzhiyun ACPI_ERROR((AE_INFO,
399*4882a593Smuzhiyun "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
400*4882a593Smuzhiyun gpe_number, gpe_number, gpe_number));
401*4882a593Smuzhiyun }
402*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
403*4882a593Smuzhiyun }
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun /* Disable the GPE in case it's been enabled already. */
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun /*
410*4882a593Smuzhiyun * Add the GPE information from above to the gpe_event_info block for
411*4882a593Smuzhiyun * use during dispatch of this GPE.
412*4882a593Smuzhiyun */
413*4882a593Smuzhiyun gpe_event_info->flags &= ~(ACPI_GPE_DISPATCH_MASK);
414*4882a593Smuzhiyun gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_METHOD);
415*4882a593Smuzhiyun gpe_event_info->dispatch.method_node = method_node;
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
418*4882a593Smuzhiyun "Registered GPE method %s as GPE number 0x%.2X\n",
419*4882a593Smuzhiyun name, gpe_number));
420*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun #endif /* !ACPI_REDUCED_HARDWARE */
424