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#include "acnamesp.h"
49#include "acdispat.h"
50#include "acconvert.h"
51
52#define _COMPONENT ACPI_PARSER
53ACPI_MODULE_NAME("psargs")
54
55
56static u32
57acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
58
59static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
60 *parser_state);
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76static u32
77acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
78{
79 u8 *aml = parser_state->aml;
80 u32 package_length = 0;
81 u32 byte_count;
82 u8 byte_zero_mask = 0x3F;
83
84 ACPI_FUNCTION_TRACE(ps_get_next_package_length);
85
86
87
88
89
90 byte_count = (aml[0] >> 6);
91 parser_state->aml += ((acpi_size)byte_count + 1);
92
93
94
95 while (byte_count) {
96
97
98
99
100
101
102
103 package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
104
105 byte_zero_mask = 0x0F;
106 byte_count--;
107 }
108
109
110
111 package_length |= (aml[0] & byte_zero_mask);
112 return_UINT32(package_length);
113}
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
129{
130 u8 *start = parser_state->aml;
131 u32 package_length;
132
133 ACPI_FUNCTION_TRACE(ps_get_next_package_end);
134
135
136
137 package_length = acpi_ps_get_next_package_length(parser_state);
138
139 return_PTR(start + package_length);
140}
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
158{
159 u8 *start = parser_state->aml;
160 u8 *end = parser_state->aml;
161
162 ACPI_FUNCTION_TRACE(ps_get_next_namestring);
163
164
165
166 while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) {
167 end++;
168 }
169
170
171
172 switch (*end) {
173 case 0:
174
175
176
177 if (end == start) {
178 start = NULL;
179 }
180 end++;
181 break;
182
183 case AML_DUAL_NAME_PREFIX:
184
185
186
187 end += 1 + (2 * ACPI_NAME_SIZE);
188 break;
189
190 case AML_MULTI_NAME_PREFIX:
191
192
193
194 end += 2 + (*(end + 1) * ACPI_NAME_SIZE);
195 break;
196
197 default:
198
199
200
201 end += ACPI_NAME_SIZE;
202 break;
203 }
204
205 parser_state->aml = end;
206 return_PTR((char *)start);
207}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230acpi_status
231acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
232 struct acpi_parse_state *parser_state,
233 union acpi_parse_object *arg, u8 possible_method_call)
234{
235 acpi_status status;
236 char *path;
237 union acpi_parse_object *name_op;
238 union acpi_operand_object *method_desc;
239 struct acpi_namespace_node *node;
240 u8 *start = parser_state->aml;
241
242 ACPI_FUNCTION_TRACE(ps_get_next_namepath);
243
244 path = acpi_ps_get_next_namestring(parser_state);
245 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
246
247
248
249 if (!path) {
250 arg->common.value.name = path;
251 return_ACPI_STATUS(AE_OK);
252 }
253
254
255
256
257
258
259
260
261
262 status = acpi_ns_lookup(walk_state->scope_info, path,
263 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
264 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
265 NULL, &node);
266
267
268
269
270
271 if (ACPI_SUCCESS(status) &&
272 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
273 if ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
274 ARGP_SUPERNAME)
275 || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
276 ARGP_TARGET)) {
277
278
279
280
281
282
283 walk_state->parser_state.aml = start;
284 walk_state->arg_count = 1;
285 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
286 }
287
288
289
290 method_desc = acpi_ns_get_attached_object(node);
291 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
292 "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
293 node->name.ascii, node, method_desc, path));
294
295 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start);
296 if (!name_op) {
297 return_ACPI_STATUS(AE_NO_MEMORY);
298 }
299
300
301
302 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
303 name_op->common.value.name = path;
304
305
306
307 name_op->common.node = node;
308 acpi_ps_append_arg(arg, name_op);
309
310 if (!method_desc) {
311 ACPI_ERROR((AE_INFO,
312 "Control Method %p has no attached object",
313 node));
314 return_ACPI_STATUS(AE_AML_INTERNAL);
315 }
316
317 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
318 "Control Method - %p Args %X\n",
319 node, method_desc->method.param_count));
320
321
322
323 walk_state->arg_count = method_desc->method.param_count;
324 return_ACPI_STATUS(AE_OK);
325 }
326
327
328
329
330
331 if (status == AE_NOT_FOUND) {
332
333
334
335 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
336 ACPI_PARSE_EXECUTE) {
337 status = AE_OK;
338 }
339
340
341
342 else if (walk_state->op->common.aml_opcode ==
343 AML_CONDITIONAL_REF_OF_OP) {
344 status = AE_OK;
345 }
346
347
348
349
350
351
352 else if ((arg->common.parent) &&
353 ((arg->common.parent->common.aml_opcode ==
354 AML_PACKAGE_OP)
355 || (arg->common.parent->common.aml_opcode ==
356 AML_VARIABLE_PACKAGE_OP))) {
357 status = AE_OK;
358 }
359 }
360
361
362
363 if (ACPI_FAILURE(status)) {
364 ACPI_ERROR_NAMESPACE(path, status);
365
366 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
367 ACPI_PARSE_EXECUTE) {
368
369
370
371 status = acpi_ds_method_error(status, walk_state);
372 }
373 }
374
375
376
377 arg->common.value.name = path;
378 return_ACPI_STATUS(status);
379}
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395void
396acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
397 u32 arg_type, union acpi_parse_object *arg)
398{
399 u32 length;
400 u16 opcode;
401 u8 *aml = parser_state->aml;
402
403 ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
404
405 switch (arg_type) {
406 case ARGP_BYTEDATA:
407
408
409
410 opcode = AML_BYTE_OP;
411 arg->common.value.integer = (u64) *aml;
412 length = 1;
413 break;
414
415 case ARGP_WORDDATA:
416
417
418
419 opcode = AML_WORD_OP;
420 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
421 length = 2;
422 break;
423
424 case ARGP_DWORDDATA:
425
426
427
428 opcode = AML_DWORD_OP;
429 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
430 length = 4;
431 break;
432
433 case ARGP_QWORDDATA:
434
435
436
437 opcode = AML_QWORD_OP;
438 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
439 length = 8;
440 break;
441
442 case ARGP_CHARLIST:
443
444
445
446 opcode = AML_STRING_OP;
447 arg->common.value.string = ACPI_CAST_PTR(char, aml);
448
449
450
451 length = 0;
452 while (aml[length]) {
453 length++;
454 }
455 length++;
456 break;
457
458 case ARGP_NAME:
459 case ARGP_NAMESTRING:
460
461 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
462 arg->common.value.name =
463 acpi_ps_get_next_namestring(parser_state);
464 return_VOID;
465
466 default:
467
468 ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
469 return_VOID;
470 }
471
472 acpi_ps_init_op(arg, opcode);
473 parser_state->aml += length;
474 return_VOID;
475}
476
477
478
479
480
481
482
483
484
485
486
487
488
489static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
490 *parser_state)
491{
492 u8 *aml;
493 union acpi_parse_object *field;
494 union acpi_parse_object *arg = NULL;
495 u16 opcode;
496 u32 name;
497 u8 access_type;
498 u8 access_attribute;
499 u8 access_length;
500 u32 pkg_length;
501 u8 *pkg_end;
502 u32 buffer_length;
503
504 ACPI_FUNCTION_TRACE(ps_get_next_field);
505
506 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
507 aml = parser_state->aml;
508
509
510
511 switch (ACPI_GET8(parser_state->aml)) {
512 case AML_FIELD_OFFSET_OP:
513
514 opcode = AML_INT_RESERVEDFIELD_OP;
515 parser_state->aml++;
516 break;
517
518 case AML_FIELD_ACCESS_OP:
519
520 opcode = AML_INT_ACCESSFIELD_OP;
521 parser_state->aml++;
522 break;
523
524 case AML_FIELD_CONNECTION_OP:
525
526 opcode = AML_INT_CONNECTION_OP;
527 parser_state->aml++;
528 break;
529
530 case AML_FIELD_EXT_ACCESS_OP:
531
532 opcode = AML_INT_EXTACCESSFIELD_OP;
533 parser_state->aml++;
534 break;
535
536 default:
537
538 opcode = AML_INT_NAMEDFIELD_OP;
539 break;
540 }
541
542
543
544 field = acpi_ps_alloc_op(opcode, aml);
545 if (!field) {
546 return_PTR(NULL);
547 }
548
549
550
551 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
552 switch (opcode) {
553 case AML_INT_NAMEDFIELD_OP:
554
555
556
557 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
558 acpi_ps_set_name(field, name);
559 parser_state->aml += ACPI_NAME_SIZE;
560
561 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
562
563#ifdef ACPI_ASL_COMPILER
564
565
566
567
568
569 if (field->common.inline_comment) {
570 field->common.name_comment =
571 field->common.inline_comment;
572 }
573 field->common.inline_comment = acpi_gbl_current_inline_comment;
574 acpi_gbl_current_inline_comment = NULL;
575#endif
576
577
578
579 field->common.value.size =
580 acpi_ps_get_next_package_length(parser_state);
581 break;
582
583 case AML_INT_RESERVEDFIELD_OP:
584
585
586
587 field->common.value.size =
588 acpi_ps_get_next_package_length(parser_state);
589 break;
590
591 case AML_INT_ACCESSFIELD_OP:
592 case AML_INT_EXTACCESSFIELD_OP:
593
594
595
596
597
598
599
600
601
602 access_type = ACPI_GET8(parser_state->aml);
603 parser_state->aml++;
604 access_attribute = ACPI_GET8(parser_state->aml);
605 parser_state->aml++;
606
607 field->common.value.integer = (u8)access_type;
608 field->common.value.integer |= (u16)(access_attribute << 8);
609
610
611
612 if (opcode == AML_INT_EXTACCESSFIELD_OP) {
613 access_length = ACPI_GET8(parser_state->aml);
614 parser_state->aml++;
615
616 field->common.value.integer |=
617 (u32)(access_length << 16);
618 }
619 break;
620
621 case AML_INT_CONNECTION_OP:
622
623
624
625
626
627 aml = parser_state->aml;
628 if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
629 parser_state->aml++;
630
631 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
632 pkg_end = parser_state->aml;
633 pkg_length =
634 acpi_ps_get_next_package_length(parser_state);
635 pkg_end += pkg_length;
636
637 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
638 if (parser_state->aml < pkg_end) {
639
640
641
642 arg =
643 acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
644 if (!arg) {
645 acpi_ps_free_op(field);
646 return_PTR(NULL);
647 }
648
649
650
651 opcode = ACPI_GET8(parser_state->aml);
652 parser_state->aml++;
653
654 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
655 switch (opcode) {
656 case AML_BYTE_OP:
657
658 buffer_length =
659 ACPI_GET8(parser_state->aml);
660 parser_state->aml += 1;
661 break;
662
663 case AML_WORD_OP:
664
665 buffer_length =
666 ACPI_GET16(parser_state->aml);
667 parser_state->aml += 2;
668 break;
669
670 case AML_DWORD_OP:
671
672 buffer_length =
673 ACPI_GET32(parser_state->aml);
674 parser_state->aml += 4;
675 break;
676
677 default:
678
679 buffer_length = 0;
680 break;
681 }
682
683
684
685 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
686 arg->named.value.size = buffer_length;
687 arg->named.data = parser_state->aml;
688 }
689
690
691
692 parser_state->aml = pkg_end;
693 } else {
694 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
695 if (!arg) {
696 acpi_ps_free_op(field);
697 return_PTR(NULL);
698 }
699
700
701
702 arg->common.value.name =
703 acpi_ps_get_next_namestring(parser_state);
704 }
705
706
707
708 acpi_ps_append_arg(field, arg);
709 break;
710
711 default:
712
713
714 break;
715 }
716
717 return_PTR(field);
718}
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736acpi_status
737acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
738 struct acpi_parse_state *parser_state,
739 u32 arg_type, union acpi_parse_object **return_arg)
740{
741 union acpi_parse_object *arg = NULL;
742 union acpi_parse_object *prev = NULL;
743 union acpi_parse_object *field;
744 u32 subop;
745 acpi_status status = AE_OK;
746
747 ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
748
749 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
750 "Expected argument type ARGP: %s (%2.2X)\n",
751 acpi_ut_get_argument_type_name(arg_type), arg_type));
752
753 switch (arg_type) {
754 case ARGP_BYTEDATA:
755 case ARGP_WORDDATA:
756 case ARGP_DWORDDATA:
757 case ARGP_CHARLIST:
758 case ARGP_NAME:
759 case ARGP_NAMESTRING:
760
761
762
763 arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
764 if (!arg) {
765 return_ACPI_STATUS(AE_NO_MEMORY);
766 }
767
768 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
769 break;
770
771 case ARGP_PKGLENGTH:
772
773
774
775 parser_state->pkg_end =
776 acpi_ps_get_next_package_end(parser_state);
777 break;
778
779 case ARGP_FIELDLIST:
780
781 if (parser_state->aml < parser_state->pkg_end) {
782
783
784
785 while (parser_state->aml < parser_state->pkg_end) {
786 field = acpi_ps_get_next_field(parser_state);
787 if (!field) {
788 return_ACPI_STATUS(AE_NO_MEMORY);
789 }
790
791 if (prev) {
792 prev->common.next = field;
793 } else {
794 arg = field;
795 }
796 prev = field;
797 }
798
799
800
801 parser_state->aml = parser_state->pkg_end;
802 }
803 break;
804
805 case ARGP_BYTELIST:
806
807 if (parser_state->aml < parser_state->pkg_end) {
808
809
810
811 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
812 parser_state->aml);
813 if (!arg) {
814 return_ACPI_STATUS(AE_NO_MEMORY);
815 }
816
817
818
819 arg->common.value.size = (u32)
820 ACPI_PTR_DIFF(parser_state->pkg_end,
821 parser_state->aml);
822 arg->named.data = parser_state->aml;
823
824
825
826 parser_state->aml = parser_state->pkg_end;
827 }
828 break;
829
830 case ARGP_SIMPLENAME:
831 case ARGP_NAME_OR_REF:
832
833 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
834 "**** SimpleName/NameOrRef: %s (%2.2X)\n",
835 acpi_ut_get_argument_type_name(arg_type),
836 arg_type));
837
838 subop = acpi_ps_peek_opcode(parser_state);
839 if (subop == 0 ||
840 acpi_ps_is_leading_char(subop) ||
841 ACPI_IS_ROOT_PREFIX(subop) ||
842 ACPI_IS_PARENT_PREFIX(subop)) {
843
844
845
846 arg =
847 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
848 parser_state->aml);
849 if (!arg) {
850 return_ACPI_STATUS(AE_NO_MEMORY);
851 }
852
853 status =
854 acpi_ps_get_next_namepath(walk_state, parser_state,
855 arg,
856 ACPI_NOT_METHOD_CALL);
857 } else {
858
859
860 walk_state->arg_count = 1;
861 }
862 break;
863
864 case ARGP_TARGET:
865 case ARGP_SUPERNAME:
866
867 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
868 "**** Target/Supername: %s (%2.2X)\n",
869 acpi_ut_get_argument_type_name(arg_type),
870 arg_type));
871
872 subop = acpi_ps_peek_opcode(parser_state);
873 if (subop == 0 ||
874 acpi_ps_is_leading_char(subop) ||
875 ACPI_IS_ROOT_PREFIX(subop) ||
876 ACPI_IS_PARENT_PREFIX(subop)) {
877
878
879
880 arg =
881 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
882 parser_state->aml);
883 if (!arg) {
884 return_ACPI_STATUS(AE_NO_MEMORY);
885 }
886
887 status =
888 acpi_ps_get_next_namepath(walk_state, parser_state,
889 arg,
890 ACPI_POSSIBLE_METHOD_CALL);
891
892 if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) {
893 acpi_ps_free_op(arg);
894 arg = NULL;
895 walk_state->arg_count = 1;
896 }
897 } else {
898
899
900 walk_state->arg_count = 1;
901 }
902 break;
903
904 case ARGP_DATAOBJ:
905 case ARGP_TERMARG:
906
907 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
908 "**** TermArg/DataObj: %s (%2.2X)\n",
909 acpi_ut_get_argument_type_name(arg_type),
910 arg_type));
911
912
913
914 walk_state->arg_count = 1;
915 break;
916
917 case ARGP_DATAOBJLIST:
918 case ARGP_TERMLIST:
919 case ARGP_OBJLIST:
920
921 if (parser_state->aml < parser_state->pkg_end) {
922
923
924
925 walk_state->arg_count = ACPI_VAR_ARGS;
926 }
927 break;
928
929 default:
930
931 ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
932 status = AE_AML_OPERAND_TYPE;
933 break;
934 }
935
936 *return_arg = arg;
937 return_ACPI_STATUS(status);
938}
939