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 "acparser.h"
47#include "amlcode.h"
48
49#define _COMPONENT ACPI_PARSER
50ACPI_MODULE_NAME("psobject")
51
52
53static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state);
54
55
56
57
58
59
60
61
62
63
64
65
66
67static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
68{
69 u32 aml_offset;
70
71 ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
72
73 walk_state->aml = walk_state->parser_state.aml;
74 walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state));
75
76
77
78
79
80
81
82 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
83
84 switch (walk_state->op_info->class) {
85 case AML_CLASS_ASCII:
86 case AML_CLASS_PREFIX:
87
88
89
90
91 walk_state->opcode = AML_INT_NAMEPATH_OP;
92 walk_state->arg_types = ARGP_NAMESTRING;
93 break;
94
95 case AML_CLASS_UNKNOWN:
96
97
98
99 if (walk_state->pass_number == 2) {
100 aml_offset = (u32)ACPI_PTR_DIFF(walk_state->aml,
101 walk_state->
102 parser_state.aml_start);
103
104 ACPI_ERROR((AE_INFO,
105 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
106 walk_state->opcode,
107 (u32)(aml_offset +
108 sizeof(struct acpi_table_header))));
109
110 ACPI_DUMP_BUFFER((walk_state->parser_state.aml - 16),
111 48);
112
113#ifdef ACPI_ASL_COMPILER
114
115
116
117
118 acpi_os_printf
119 ("/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
120 walk_state->opcode,
121 (u32)(aml_offset +
122 sizeof(struct acpi_table_header)));
123
124
125
126 acpi_ut_dump_buffer(((u8 *)walk_state->parser_state.
127 aml - 16), 48, DB_BYTE_DISPLAY,
128 (aml_offset +
129 sizeof(struct acpi_table_header) -
130 16));
131 acpi_os_printf(" */\n");
132#endif
133 }
134
135
136
137 walk_state->parser_state.aml++;
138 if (walk_state->opcode > 0xFF) {
139 walk_state->parser_state.aml++;
140 }
141
142 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
143
144 default:
145
146
147
148 walk_state->parser_state.aml +=
149 acpi_ps_get_opcode_size(walk_state->opcode);
150 walk_state->arg_types = walk_state->op_info->parse_args;
151 break;
152 }
153
154 return_ACPI_STATUS(AE_OK);
155}
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172acpi_status
173acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
174 u8 *aml_op_start,
175 union acpi_parse_object *unnamed_op,
176 union acpi_parse_object **op)
177{
178 acpi_status status = AE_OK;
179 union acpi_parse_object *arg = NULL;
180
181 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
182
183 unnamed_op->common.value.arg = NULL;
184 unnamed_op->common.arg_list_length = 0;
185 unnamed_op->common.aml_opcode = walk_state->opcode;
186
187
188
189
190
191 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
192 (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
193 status =
194 acpi_ps_get_next_arg(walk_state,
195 &(walk_state->parser_state),
196 GET_CURRENT_ARG_TYPE(walk_state->
197 arg_types), &arg);
198 if (ACPI_FAILURE(status)) {
199 return_ACPI_STATUS(status);
200 }
201
202 acpi_ps_append_arg(unnamed_op, arg);
203 INCREMENT_ARG_LIST(walk_state->arg_types);
204 }
205
206
207
208
209 if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
210 return_ACPI_STATUS(AE_AML_NO_OPERAND);
211 }
212
213
214
215 INCREMENT_ARG_LIST(walk_state->arg_types);
216
217
218
219
220
221 walk_state->op = NULL;
222
223 status = walk_state->descending_callback(walk_state, op);
224 if (ACPI_FAILURE(status)) {
225 if (status != AE_CTRL_TERMINATE) {
226 ACPI_EXCEPTION((AE_INFO, status,
227 "During name lookup/catalog"));
228 }
229 return_ACPI_STATUS(status);
230 }
231
232 if (!*op) {
233 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
234 }
235
236 status = acpi_ps_next_parse_state(walk_state, *op, status);
237 if (ACPI_FAILURE(status)) {
238 if (status == AE_CTRL_PENDING) {
239 status = AE_CTRL_PARSE_PENDING;
240 }
241 return_ACPI_STATUS(status);
242 }
243
244 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
245
246 if ((*op)->common.aml_opcode == AML_REGION_OP ||
247 (*op)->common.aml_opcode == AML_DATA_REGION_OP) {
248
249
250
251
252
253
254
255
256
257
258 (*op)->named.data = aml_op_start;
259 (*op)->named.length = 0;
260 }
261
262 return_ACPI_STATUS(AE_OK);
263}
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279acpi_status
280acpi_ps_create_op(struct acpi_walk_state *walk_state,
281 u8 *aml_op_start, union acpi_parse_object **new_op)
282{
283 acpi_status status = AE_OK;
284 union acpi_parse_object *op;
285 union acpi_parse_object *named_op = NULL;
286 union acpi_parse_object *parent_scope;
287 u8 argument_count;
288 const struct acpi_opcode_info *op_info;
289
290 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
291
292 status = acpi_ps_get_aml_opcode(walk_state);
293 if (status == AE_CTRL_PARSE_CONTINUE) {
294 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
295 }
296
297
298
299 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
300 op = acpi_ps_alloc_op(walk_state->opcode, aml_op_start);
301 if (!op) {
302 return_ACPI_STATUS(AE_NO_MEMORY);
303 }
304
305 if (walk_state->op_info->flags & AML_NAMED) {
306 status =
307 acpi_ps_build_named_op(walk_state, aml_op_start, op,
308 &named_op);
309 acpi_ps_free_op(op);
310 if (ACPI_FAILURE(status)) {
311 return_ACPI_STATUS(status);
312 }
313
314 *new_op = named_op;
315 return_ACPI_STATUS(AE_OK);
316 }
317
318
319
320 if (walk_state->op_info->flags & AML_CREATE) {
321
322
323
324
325 op->named.data = aml_op_start;
326 op->named.length = 0;
327 }
328
329 if (walk_state->opcode == AML_BANK_FIELD_OP) {
330
331
332
333
334 op->named.data = aml_op_start;
335 op->named.length = 0;
336 }
337
338 parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state));
339 acpi_ps_append_arg(parent_scope, op);
340
341 if (parent_scope) {
342 op_info =
343 acpi_ps_get_opcode_info(parent_scope->common.aml_opcode);
344 if (op_info->flags & AML_HAS_TARGET) {
345 argument_count =
346 acpi_ps_get_argument_count(op_info->type);
347 if (parent_scope->common.arg_list_length >
348 argument_count) {
349 op->common.flags |= ACPI_PARSEOP_TARGET;
350 }
351 } else if (parent_scope->common.aml_opcode == AML_INCREMENT_OP) {
352 op->common.flags |= ACPI_PARSEOP_TARGET;
353 }
354 }
355
356 if (walk_state->descending_callback != NULL) {
357
358
359
360
361 walk_state->op = *new_op = op;
362
363 status = walk_state->descending_callback(walk_state, &op);
364 status = acpi_ps_next_parse_state(walk_state, op, status);
365 if (status == AE_CTRL_PENDING) {
366 status = AE_CTRL_PARSE_PENDING;
367 }
368 }
369
370 return_ACPI_STATUS(status);
371}
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387acpi_status
388acpi_ps_complete_op(struct acpi_walk_state *walk_state,
389 union acpi_parse_object **op, acpi_status status)
390{
391 acpi_status status2;
392
393 ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
394
395
396
397
398 walk_state->parser_state.scope->parse_scope.arg_count--;
399
400
401
402 status2 = acpi_ps_complete_this_op(walk_state, *op);
403 if (ACPI_FAILURE(status2)) {
404 return_ACPI_STATUS(status2);
405 }
406
407 *op = NULL;
408
409 switch (status) {
410 case AE_OK:
411
412 break;
413
414 case AE_CTRL_TRANSFER:
415
416
417
418 walk_state->prev_op = NULL;
419 walk_state->prev_arg_types = walk_state->arg_types;
420 return_ACPI_STATUS(status);
421
422 case AE_CTRL_END:
423
424 acpi_ps_pop_scope(&(walk_state->parser_state), op,
425 &walk_state->arg_types,
426 &walk_state->arg_count);
427
428 if (*op) {
429 walk_state->op = *op;
430 walk_state->op_info =
431 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
432 walk_state->opcode = (*op)->common.aml_opcode;
433
434 status = walk_state->ascending_callback(walk_state);
435 status =
436 acpi_ps_next_parse_state(walk_state, *op, status);
437
438 status2 = acpi_ps_complete_this_op(walk_state, *op);
439 if (ACPI_FAILURE(status2)) {
440 return_ACPI_STATUS(status2);
441 }
442 }
443
444 status = AE_OK;
445 break;
446
447 case AE_CTRL_BREAK:
448 case AE_CTRL_CONTINUE:
449
450
451
452 while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
453 acpi_ps_pop_scope(&(walk_state->parser_state), op,
454 &walk_state->arg_types,
455 &walk_state->arg_count);
456 }
457
458
459
460 walk_state->op = *op;
461 walk_state->op_info =
462 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
463 walk_state->opcode = (*op)->common.aml_opcode;
464
465 status = walk_state->ascending_callback(walk_state);
466 status = acpi_ps_next_parse_state(walk_state, *op, status);
467
468 status2 = acpi_ps_complete_this_op(walk_state, *op);
469 if (ACPI_FAILURE(status2)) {
470 return_ACPI_STATUS(status2);
471 }
472
473 status = AE_OK;
474 break;
475
476 case AE_CTRL_TERMINATE:
477
478
479 do {
480 if (*op) {
481 status2 =
482 acpi_ps_complete_this_op(walk_state, *op);
483 if (ACPI_FAILURE(status2)) {
484 return_ACPI_STATUS(status2);
485 }
486
487 acpi_ut_delete_generic_state
488 (acpi_ut_pop_generic_state
489 (&walk_state->control_state));
490 }
491
492 acpi_ps_pop_scope(&(walk_state->parser_state), op,
493 &walk_state->arg_types,
494 &walk_state->arg_count);
495
496 } while (*op);
497
498 return_ACPI_STATUS(AE_OK);
499
500 default:
501
502 do {
503 if (*op) {
504 status2 =
505 acpi_ps_complete_this_op(walk_state, *op);
506 if (ACPI_FAILURE(status2)) {
507 return_ACPI_STATUS(status2);
508 }
509 }
510
511 acpi_ps_pop_scope(&(walk_state->parser_state), op,
512 &walk_state->arg_types,
513 &walk_state->arg_count);
514
515 } while (*op);
516
517#if 0
518
519
520
521 if (*op == NULL) {
522 acpi_ps_pop_scope(parser_state, op,
523 &walk_state->arg_types,
524 &walk_state->arg_count);
525 }
526#endif
527 walk_state->prev_op = NULL;
528 walk_state->prev_arg_types = walk_state->arg_types;
529 return_ACPI_STATUS(status);
530 }
531
532
533
534 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
535 acpi_ps_pop_scope(&(walk_state->parser_state), op,
536 &walk_state->arg_types,
537 &walk_state->arg_count);
538 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
539 } else {
540 *op = NULL;
541 }
542
543 return_ACPI_STATUS(AE_OK);
544}
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561acpi_status
562acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
563 union acpi_parse_object *op, acpi_status status)
564{
565 acpi_status status2;
566
567 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
568
569
570
571
572
573
574
575 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
576 op));
577 do {
578 if (op) {
579 if (walk_state->ascending_callback != NULL) {
580 walk_state->op = op;
581 walk_state->op_info =
582 acpi_ps_get_opcode_info(op->common.
583 aml_opcode);
584 walk_state->opcode = op->common.aml_opcode;
585
586 status =
587 walk_state->ascending_callback(walk_state);
588 status =
589 acpi_ps_next_parse_state(walk_state, op,
590 status);
591 if (status == AE_CTRL_PENDING) {
592 status =
593 acpi_ps_complete_op(walk_state, &op,
594 AE_OK);
595 if (ACPI_FAILURE(status)) {
596 return_ACPI_STATUS(status);
597 }
598 }
599
600 if (status == AE_CTRL_TERMINATE) {
601 status = AE_OK;
602
603
604 do {
605 if (op) {
606 status2 =
607 acpi_ps_complete_this_op
608 (walk_state, op);
609 if (ACPI_FAILURE
610 (status2)) {
611 return_ACPI_STATUS
612 (status2);
613 }
614 }
615
616 acpi_ps_pop_scope(&
617 (walk_state->
618 parser_state),
619 &op,
620 &walk_state->
621 arg_types,
622 &walk_state->
623 arg_count);
624
625 } while (op);
626
627 return_ACPI_STATUS(status);
628 }
629
630 else if (ACPI_FAILURE(status)) {
631
632
633
634 (void)
635 acpi_ps_complete_this_op(walk_state,
636 op);
637 return_ACPI_STATUS(status);
638 }
639 }
640
641 status2 = acpi_ps_complete_this_op(walk_state, op);
642 if (ACPI_FAILURE(status2)) {
643 return_ACPI_STATUS(status2);
644 }
645 }
646
647 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
648 &walk_state->arg_types,
649 &walk_state->arg_count);
650
651 } while (op);
652
653 return_ACPI_STATUS(status);
654}
655