1
2
3
4
5
6
7
8#include <acpi/acpi.h>
9#include "accommon.h"
10#include "acparser.h"
11#include "acinterp.h"
12#include "acnamesp.h"
13
14#define _COMPONENT ACPI_NAMESPACE
15ACPI_MODULE_NAME("nseval")
16
17
18static void
19acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
20 struct acpi_evaluate_info *info);
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
49{
50 acpi_status status;
51
52 ACPI_FUNCTION_TRACE(ns_evaluate);
53
54 if (!info) {
55 return_ACPI_STATUS(AE_BAD_PARAMETER);
56 }
57
58 if (!info->node) {
59
60
61
62
63
64
65
66
67 status =
68 acpi_ns_get_node(info->prefix_node, info->relative_pathname,
69 ACPI_NS_NO_UPSEARCH, &info->node);
70 if (ACPI_FAILURE(status)) {
71 return_ACPI_STATUS(status);
72 }
73 }
74
75
76
77
78
79 if (acpi_ns_get_type(info->node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) {
80 info->node =
81 ACPI_CAST_PTR(struct acpi_namespace_node,
82 info->node->object);
83 }
84
85
86
87 info->return_object = NULL;
88 info->node_flags = info->node->flags;
89 info->obj_desc = acpi_ns_get_attached_object(info->node);
90
91 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n",
92 info->relative_pathname, info->node,
93 acpi_ns_get_attached_object(info->node)));
94
95
96
97 info->predefined =
98 acpi_ut_match_predefined_method(info->node->name.ascii);
99
100
101
102 info->full_pathname = acpi_ns_get_normalized_pathname(info->node, TRUE);
103 if (!info->full_pathname) {
104 return_ACPI_STATUS(AE_NO_MEMORY);
105 }
106
107
108
109 info->param_count = 0;
110 if (info->parameters) {
111 while (info->parameters[info->param_count]) {
112 info->param_count++;
113 }
114
115
116
117 if (info->param_count > ACPI_METHOD_NUM_ARGS) {
118 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
119 ACPI_WARN_ALWAYS,
120 "Excess arguments (%u) - using only %u",
121 info->param_count,
122 ACPI_METHOD_NUM_ARGS));
123
124 info->param_count = ACPI_METHOD_NUM_ARGS;
125 }
126 }
127
128
129
130
131
132 acpi_ns_check_acpi_compliance(info->full_pathname, info->node,
133 info->predefined);
134
135
136
137
138
139 acpi_ns_check_argument_count(info->full_pathname, info->node,
140 info->param_count, info->predefined);
141
142
143
144 acpi_ns_check_argument_types(info);
145
146
147
148
149
150
151
152
153 switch (acpi_ns_get_type(info->node)) {
154 case ACPI_TYPE_ANY:
155 case ACPI_TYPE_DEVICE:
156 case ACPI_TYPE_EVENT:
157 case ACPI_TYPE_MUTEX:
158 case ACPI_TYPE_REGION:
159 case ACPI_TYPE_THERMAL:
160 case ACPI_TYPE_LOCAL_SCOPE:
161
162
163
164
165 ACPI_ERROR((AE_INFO,
166 "%s: This object type [%s] "
167 "never contains data and cannot be evaluated",
168 info->full_pathname,
169 acpi_ut_get_type_name(info->node->type)));
170
171 status = AE_TYPE;
172 goto cleanup;
173
174 case ACPI_TYPE_METHOD:
175
176
177
178
179
180
181 if (!info->obj_desc) {
182 ACPI_ERROR((AE_INFO,
183 "%s: Method has no attached sub-object",
184 info->full_pathname));
185 status = AE_NULL_OBJECT;
186 goto cleanup;
187 }
188
189 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
190 "**** Execute method [%s] at AML address %p length %X\n",
191 info->full_pathname,
192 info->obj_desc->method.aml_start + 1,
193 info->obj_desc->method.aml_length - 1));
194
195
196
197
198
199
200
201
202
203 acpi_ex_enter_interpreter();
204 status = acpi_ps_execute_method(info);
205 acpi_ex_exit_interpreter();
206 break;
207
208 default:
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 acpi_ex_enter_interpreter();
230
231
232
233 info->return_object =
234 ACPI_CAST_PTR(union acpi_operand_object, info->node);
235
236 status =
237 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
238 (struct acpi_namespace_node,
239 &info->return_object), NULL);
240 acpi_ex_exit_interpreter();
241
242 if (ACPI_FAILURE(status)) {
243 info->return_object = NULL;
244 goto cleanup;
245 }
246
247 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Returned object %p [%s]\n",
248 info->return_object,
249 acpi_ut_get_object_type_name(info->
250 return_object)));
251
252 status = AE_CTRL_RETURN_VALUE;
253 break;
254 }
255
256
257
258
259
260 (void)acpi_ns_check_return_value(info->node, info, info->param_count,
261 status, &info->return_object);
262
263
264
265 if (status == AE_CTRL_RETURN_VALUE) {
266
267
268
269 if (info->flags & ACPI_IGNORE_RETURN_VALUE) {
270 acpi_ut_remove_reference(info->return_object);
271 info->return_object = NULL;
272 }
273
274
275
276 status = AE_OK;
277 } else if (ACPI_FAILURE(status)) {
278
279
280
281 if (info->return_object) {
282 acpi_ut_remove_reference(info->return_object);
283 info->return_object = NULL;
284 }
285 }
286
287 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
288 "*** Completed evaluation of object %s ***\n",
289 info->relative_pathname));
290
291cleanup:
292
293
294
295
296 ACPI_FREE(info->full_pathname);
297 info->full_pathname = NULL;
298 return_ACPI_STATUS(status);
299}
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326void acpi_ns_exec_module_code_list(void)
327{
328 union acpi_operand_object *prev;
329 union acpi_operand_object *next;
330 struct acpi_evaluate_info *info;
331 u32 method_count = 0;
332
333 ACPI_FUNCTION_TRACE(ns_exec_module_code_list);
334
335
336
337 next = acpi_gbl_module_code_list;
338 if (!next) {
339 ACPI_DEBUG_PRINT((ACPI_DB_INIT_NAMES,
340 "Legacy MLC block list is empty\n"));
341
342 return_VOID;
343 }
344
345
346
347 info = ACPI_ALLOCATE(sizeof(struct acpi_evaluate_info));
348 if (!info) {
349 return_VOID;
350 }
351
352
353
354 while (next) {
355 prev = next;
356 next = next->method.mutex;
357
358
359
360 prev->method.mutex = NULL;
361 acpi_ns_exec_module_code(prev, info);
362 method_count++;
363
364
365
366 acpi_ut_remove_reference(prev);
367 }
368
369 ACPI_INFO(("Executed %u blocks of module-level executable AML code",
370 method_count));
371
372 ACPI_FREE(info);
373 acpi_gbl_module_code_list = NULL;
374 return_VOID;
375}
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393static void
394acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
395 struct acpi_evaluate_info *info)
396{
397 union acpi_operand_object *parent_obj;
398 struct acpi_namespace_node *parent_node;
399 acpi_object_type type;
400 acpi_status status;
401
402 ACPI_FUNCTION_TRACE(ns_exec_module_code);
403
404
405
406
407
408 parent_node =
409 ACPI_CAST_PTR(struct acpi_namespace_node,
410 method_obj->method.next_object);
411 type = acpi_ns_get_type(parent_node);
412
413
414
415
416
417
418
419
420 if ((type == ACPI_TYPE_DEVICE) && parent_node->object) {
421 method_obj->method.dispatch.handler =
422 parent_node->object->device.handler;
423 }
424
425
426
427 method_obj->method.next_object = NULL;
428
429
430
431 memset(info, 0, sizeof(struct acpi_evaluate_info));
432 info->prefix_node = parent_node;
433
434
435
436
437
438
439 parent_obj = acpi_ns_get_attached_object(parent_node);
440 if (parent_obj) {
441 acpi_ut_add_reference(parent_obj);
442 }
443
444
445
446 status =
447 acpi_ns_attach_object(parent_node, method_obj, ACPI_TYPE_METHOD);
448 if (ACPI_FAILURE(status)) {
449 goto exit;
450 }
451
452
453
454 status = acpi_ns_evaluate(info);
455
456 ACPI_DEBUG_PRINT((ACPI_DB_INIT_NAMES,
457 "Executed module-level code at %p\n",
458 method_obj->method.aml_start));
459
460
461
462 if (info->return_object) {
463 acpi_ut_remove_reference(info->return_object);
464 }
465
466
467
468 acpi_ns_detach_object(parent_node);
469
470
471
472 if (parent_obj) {
473 status = acpi_ns_attach_object(parent_node, parent_obj, type);
474 } else {
475 parent_node->type = (u8)type;
476 }
477
478exit:
479 if (parent_obj) {
480 acpi_ut_remove_reference(parent_obj);
481 }
482 return_VOID;
483}
484