1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acevents.h"
47
48#define _COMPONENT ACPI_EVENTS
49ACPI_MODULE_NAME("evgpeutil")
50
51
52
53
54
55
56
57
58
59
60
61
62
63acpi_status
64acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
65{
66 struct acpi_gpe_block_info *gpe_block;
67 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
68 acpi_status status = AE_OK;
69 acpi_cpu_flags flags;
70
71 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
72
73 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
74
75
76
77 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
78 while (gpe_xrupt_info) {
79
80
81
82 gpe_block = gpe_xrupt_info->gpe_block_list_head;
83 while (gpe_block) {
84
85
86
87 status =
88 gpe_walk_callback(gpe_xrupt_info, gpe_block,
89 context);
90 if (ACPI_FAILURE(status)) {
91 if (status == AE_CTRL_END) {
92 status = AE_OK;
93 }
94 goto unlock_and_exit;
95 }
96
97 gpe_block = gpe_block->next;
98 }
99
100 gpe_xrupt_info = gpe_xrupt_info->next;
101 }
102
103 unlock_and_exit:
104 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
105 return_ACPI_STATUS(status);
106}
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
123{
124 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
125 struct acpi_gpe_block_info *gpe_block;
126
127 ACPI_FUNCTION_ENTRY();
128
129
130
131
132
133 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
134 while (gpe_xrupt_block) {
135 gpe_block = gpe_xrupt_block->gpe_block_list_head;
136
137
138
139 while (gpe_block) {
140 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
141 (&gpe_block->event_info[gpe_block->gpe_count] >
142 gpe_event_info)) {
143 return (TRUE);
144 }
145
146 gpe_block = gpe_block->next;
147 }
148
149 gpe_xrupt_block = gpe_xrupt_block->next;
150 }
151
152 return (FALSE);
153}
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168acpi_status
169acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
170 struct acpi_gpe_block_info *gpe_block, void *context)
171{
172 struct acpi_gpe_device_info *info = context;
173
174
175
176 info->next_block_base_index += gpe_block->gpe_count;
177
178 if (info->index < info->next_block_base_index) {
179
180
181
182
183 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
184 info->gpe_device = gpe_block->node;
185 }
186
187 info->status = AE_OK;
188 return (AE_CTRL_END);
189 }
190
191 return (AE_OK);
192}
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 interrupt_number)
210{
211 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
212 struct acpi_gpe_xrupt_info *gpe_xrupt;
213 acpi_status status;
214 acpi_cpu_flags flags;
215
216 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
217
218
219
220 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
221 while (next_gpe_xrupt) {
222 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
223 return_PTR(next_gpe_xrupt);
224 }
225
226 next_gpe_xrupt = next_gpe_xrupt->next;
227 }
228
229
230
231 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
232 if (!gpe_xrupt) {
233 return_PTR(NULL);
234 }
235
236 gpe_xrupt->interrupt_number = interrupt_number;
237
238
239
240 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
241 if (acpi_gbl_gpe_xrupt_list_head) {
242 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
243 while (next_gpe_xrupt->next) {
244 next_gpe_xrupt = next_gpe_xrupt->next;
245 }
246
247 next_gpe_xrupt->next = gpe_xrupt;
248 gpe_xrupt->previous = next_gpe_xrupt;
249 } else {
250 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
251 }
252 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
253
254
255
256 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
257 status = acpi_os_install_interrupt_handler(interrupt_number,
258 acpi_ev_gpe_xrupt_handler,
259 gpe_xrupt);
260 if (ACPI_FAILURE(status)) {
261 ACPI_ERROR((AE_INFO,
262 "Could not install GPE interrupt handler at level 0x%X",
263 interrupt_number));
264 return_PTR(NULL);
265 }
266 }
267
268 return_PTR(gpe_xrupt);
269}
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284acpi_status acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
285{
286 acpi_status status;
287 acpi_cpu_flags flags;
288
289 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
290
291
292
293 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
294 gpe_xrupt->gpe_block_list_head = NULL;
295 return_ACPI_STATUS(AE_OK);
296 }
297
298
299
300 status =
301 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
302 acpi_ev_gpe_xrupt_handler);
303 if (ACPI_FAILURE(status)) {
304 return_ACPI_STATUS(status);
305 }
306
307
308
309 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
310 if (gpe_xrupt->previous) {
311 gpe_xrupt->previous->next = gpe_xrupt->next;
312 } else {
313
314
315 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
316 }
317
318 if (gpe_xrupt->next) {
319 gpe_xrupt->next->previous = gpe_xrupt->previous;
320 }
321 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
322
323
324
325 ACPI_FREE(gpe_xrupt);
326 return_ACPI_STATUS(AE_OK);
327}
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343acpi_status
344acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
345 struct acpi_gpe_block_info *gpe_block,
346 void *context)
347{
348 struct acpi_gpe_event_info *gpe_event_info;
349 u32 i;
350 u32 j;
351
352 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
353
354
355
356 for (i = 0; i < gpe_block->register_count; i++) {
357
358
359
360 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
361 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
362 ACPI_GPE_REGISTER_WIDTH)
363 + j];
364
365 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
366 ACPI_GPE_DISPATCH_HANDLER) {
367 ACPI_FREE(gpe_event_info->dispatch.handler);
368 gpe_event_info->dispatch.handler = NULL;
369 gpe_event_info->flags &=
370 ~ACPI_GPE_DISPATCH_MASK;
371 }
372 }
373 }
374
375 return_ACPI_STATUS(AE_OK);
376}
377