1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acevents.h"
13#include "acnamesp.h"
14#include "acinterp.h"
15
16#define _COMPONENT ACPI_EVENTS
17ACPI_MODULE_NAME("evhandler")
18
19
20static acpi_status
21acpi_ev_install_handler(acpi_handle obj_handle,
22 u32 level, void *context, void **return_value);
23
24
25
26u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = {
27 ACPI_ADR_SPACE_SYSTEM_MEMORY,
28 ACPI_ADR_SPACE_SYSTEM_IO,
29 ACPI_ADR_SPACE_PCI_CONFIG,
30 ACPI_ADR_SPACE_DATA_TABLE
31};
32
33
34
35
36
37
38
39
40
41
42
43
44
45acpi_status acpi_ev_install_region_handlers(void)
46{
47 acpi_status status;
48 u32 i;
49
50 ACPI_FUNCTION_TRACE(ev_install_region_handlers);
51
52 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
53 if (ACPI_FAILURE(status)) {
54 return_ACPI_STATUS(status);
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
77 status = acpi_ev_install_space_handler(acpi_gbl_root_node,
78 acpi_gbl_default_address_spaces
79 [i],
80 ACPI_DEFAULT_HANDLER,
81 NULL, NULL);
82 switch (status) {
83 case AE_OK:
84 case AE_SAME_HANDLER:
85 case AE_ALREADY_EXISTS:
86
87
88
89 status = AE_OK;
90 break;
91
92 default:
93
94 goto unlock_and_exit;
95 }
96 }
97
98unlock_and_exit:
99 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
100 return_ACPI_STATUS(status);
101}
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117u8
118acpi_ev_has_default_handler(struct acpi_namespace_node *node,
119 acpi_adr_space_type space_id)
120{
121 union acpi_operand_object *obj_desc;
122 union acpi_operand_object *handler_obj;
123
124
125
126 obj_desc = acpi_ns_get_attached_object(node);
127 if (obj_desc) {
128 handler_obj = obj_desc->common_notify.handler;
129
130
131
132 while (handler_obj) {
133 if (handler_obj->address_space.space_id == space_id) {
134 if (handler_obj->address_space.handler_flags &
135 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) {
136 return (TRUE);
137 }
138 }
139
140 handler_obj = handler_obj->address_space.next;
141 }
142 }
143
144 return (FALSE);
145}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164static acpi_status
165acpi_ev_install_handler(acpi_handle obj_handle,
166 u32 level, void *context, void **return_value)
167{
168 union acpi_operand_object *handler_obj;
169 union acpi_operand_object *next_handler_obj;
170 union acpi_operand_object *obj_desc;
171 struct acpi_namespace_node *node;
172 acpi_status status;
173
174 ACPI_FUNCTION_NAME(ev_install_handler);
175
176 handler_obj = (union acpi_operand_object *)context;
177
178
179
180 if (!handler_obj) {
181 return (AE_OK);
182 }
183
184
185
186 node = acpi_ns_validate_handle(obj_handle);
187 if (!node) {
188 return (AE_BAD_PARAMETER);
189 }
190
191
192
193
194
195 if ((node->type != ACPI_TYPE_DEVICE) &&
196 (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
197 return (AE_OK);
198 }
199
200
201
202 obj_desc = acpi_ns_get_attached_object(node);
203 if (!obj_desc) {
204
205
206
207 return (AE_OK);
208 }
209
210
211
212 if (obj_desc->common.type == ACPI_TYPE_DEVICE) {
213
214
215
216 next_handler_obj =
217 acpi_ev_find_region_handler(handler_obj->address_space.
218 space_id,
219 obj_desc->common_notify.
220 handler);
221 if (next_handler_obj) {
222
223
224
225 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
226 "Found handler for region [%s] in device %p(%p) handler %p\n",
227 acpi_ut_get_region_name(handler_obj->
228 address_space.
229 space_id),
230 obj_desc, next_handler_obj,
231 handler_obj));
232
233
234
235
236
237
238
239
240 return (AE_CTRL_DEPTH);
241 }
242
243
244
245
246
247 return (AE_OK);
248 }
249
250
251
252 if (obj_desc->region.space_id != handler_obj->address_space.space_id) {
253
254
255
256 return (AE_OK);
257 }
258
259
260
261
262
263
264 acpi_ev_detach_region(obj_desc, FALSE);
265
266
267
268 status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE);
269 return (status);
270}
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286union acpi_operand_object *acpi_ev_find_region_handler(acpi_adr_space_type
287 space_id,
288 union acpi_operand_object
289 *handler_obj)
290{
291
292
293
294 while (handler_obj) {
295
296
297
298 if (handler_obj->address_space.space_id == space_id) {
299 return (handler_obj);
300 }
301
302
303
304 handler_obj = handler_obj->address_space.next;
305 }
306
307 return (NULL);
308}
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327acpi_status
328acpi_ev_install_space_handler(struct acpi_namespace_node *node,
329 acpi_adr_space_type space_id,
330 acpi_adr_space_handler handler,
331 acpi_adr_space_setup setup, void *context)
332{
333 union acpi_operand_object *obj_desc;
334 union acpi_operand_object *handler_obj;
335 acpi_status status = AE_OK;
336 acpi_object_type type;
337 u8 flags = 0;
338
339 ACPI_FUNCTION_TRACE(ev_install_space_handler);
340
341
342
343
344
345 if ((node->type != ACPI_TYPE_DEVICE) &&
346 (node->type != ACPI_TYPE_PROCESSOR) &&
347 (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) {
348 status = AE_BAD_PARAMETER;
349 goto unlock_and_exit;
350 }
351
352 if (handler == ACPI_DEFAULT_HANDLER) {
353 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
354
355 switch (space_id) {
356 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
357
358 handler = acpi_ex_system_memory_space_handler;
359 setup = acpi_ev_system_memory_region_setup;
360 break;
361
362 case ACPI_ADR_SPACE_SYSTEM_IO:
363
364 handler = acpi_ex_system_io_space_handler;
365 setup = acpi_ev_io_space_region_setup;
366 break;
367
368 case ACPI_ADR_SPACE_PCI_CONFIG:
369
370 handler = acpi_ex_pci_config_space_handler;
371 setup = acpi_ev_pci_config_region_setup;
372 break;
373
374 case ACPI_ADR_SPACE_CMOS:
375
376 handler = acpi_ex_cmos_space_handler;
377 setup = acpi_ev_cmos_region_setup;
378 break;
379
380 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
381
382 handler = acpi_ex_pci_bar_space_handler;
383 setup = acpi_ev_pci_bar_region_setup;
384 break;
385
386 case ACPI_ADR_SPACE_DATA_TABLE:
387
388 handler = acpi_ex_data_table_space_handler;
389 setup = NULL;
390 break;
391
392 default:
393
394 status = AE_BAD_PARAMETER;
395 goto unlock_and_exit;
396 }
397 }
398
399
400
401 if (!setup) {
402 setup = acpi_ev_default_region_setup;
403 }
404
405
406
407 obj_desc = acpi_ns_get_attached_object(node);
408 if (obj_desc) {
409
410
411
412
413 handler_obj = acpi_ev_find_region_handler(space_id,
414 obj_desc->
415 common_notify.
416 handler);
417
418 if (handler_obj) {
419 if (handler_obj->address_space.handler == handler) {
420
421
422
423
424
425 status = AE_SAME_HANDLER;
426 goto unlock_and_exit;
427 } else {
428
429
430 status = AE_ALREADY_EXISTS;
431 }
432
433 goto unlock_and_exit;
434 }
435 } else {
436 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
437 "Creating object on Device %p while installing handler\n",
438 node));
439
440
441
442 if (node->type == ACPI_TYPE_ANY) {
443 type = ACPI_TYPE_DEVICE;
444 } else {
445 type = node->type;
446 }
447
448 obj_desc = acpi_ut_create_internal_object(type);
449 if (!obj_desc) {
450 status = AE_NO_MEMORY;
451 goto unlock_and_exit;
452 }
453
454
455
456 obj_desc->common.type = (u8)type;
457
458
459
460 status = acpi_ns_attach_object(node, obj_desc, type);
461
462
463
464 acpi_ut_remove_reference(obj_desc);
465
466 if (ACPI_FAILURE(status)) {
467 goto unlock_and_exit;
468 }
469 }
470
471 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
472 "Installing address handler for region %s(%X) "
473 "on Device %4.4s %p(%p)\n",
474 acpi_ut_get_region_name(space_id), space_id,
475 acpi_ut_get_node_name(node), node, obj_desc));
476
477
478
479
480
481
482
483 handler_obj =
484 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
485 if (!handler_obj) {
486 status = AE_NO_MEMORY;
487 goto unlock_and_exit;
488 }
489
490
491
492 status =
493 acpi_os_create_mutex(&handler_obj->address_space.context_mutex);
494 if (ACPI_FAILURE(status)) {
495 acpi_ut_remove_reference(handler_obj);
496 goto unlock_and_exit;
497 }
498
499 handler_obj->address_space.space_id = (u8)space_id;
500 handler_obj->address_space.handler_flags = flags;
501 handler_obj->address_space.region_list = NULL;
502 handler_obj->address_space.node = node;
503 handler_obj->address_space.handler = handler;
504 handler_obj->address_space.context = context;
505 handler_obj->address_space.setup = setup;
506
507
508
509 handler_obj->address_space.next = obj_desc->common_notify.handler;
510
511
512
513
514
515 obj_desc->common_notify.handler = handler_obj;
516
517
518
519
520
521
522
523
524
525
526
527 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node,
528 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
529 acpi_ev_install_handler, NULL,
530 handler_obj, NULL);
531
532unlock_and_exit:
533 return_ACPI_STATUS(status);
534}
535