0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acparser.h"
0013 #include "amlcode.h"
0014 #include "acnamesp.h"
0015 #include "acdispat.h"
0016 #include "acconvert.h"
0017
0018 #define _COMPONENT ACPI_PARSER
0019 ACPI_MODULE_NAME("psargs")
0020
0021
0022 static u32
0023 acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
0024
0025 static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
0026 *parser_state);
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 static u32
0043 acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
0044 {
0045 u8 *aml = parser_state->aml;
0046 u32 package_length = 0;
0047 u32 byte_count;
0048 u8 byte_zero_mask = 0x3F;
0049
0050 ACPI_FUNCTION_TRACE(ps_get_next_package_length);
0051
0052
0053
0054
0055
0056 byte_count = (aml[0] >> 6);
0057 parser_state->aml += ((acpi_size)byte_count + 1);
0058
0059
0060
0061 while (byte_count) {
0062
0063
0064
0065
0066
0067
0068
0069 package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
0070
0071 byte_zero_mask = 0x0F;
0072 byte_count--;
0073 }
0074
0075
0076
0077 package_length |= (aml[0] & byte_zero_mask);
0078 return_UINT32(package_length);
0079 }
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
0095 {
0096 u8 *start = parser_state->aml;
0097 u32 package_length;
0098
0099 ACPI_FUNCTION_TRACE(ps_get_next_package_end);
0100
0101
0102
0103 package_length = acpi_ps_get_next_package_length(parser_state);
0104
0105 return_PTR(start + package_length);
0106 }
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
0124 {
0125 u8 *start = parser_state->aml;
0126 u8 *end = parser_state->aml;
0127
0128 ACPI_FUNCTION_TRACE(ps_get_next_namestring);
0129
0130
0131
0132 while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) {
0133 end++;
0134 }
0135
0136
0137
0138 switch (*end) {
0139 case 0:
0140
0141
0142
0143 if (end == start) {
0144 start = NULL;
0145 }
0146 end++;
0147 break;
0148
0149 case AML_DUAL_NAME_PREFIX:
0150
0151
0152
0153 end += 1 + (2 * ACPI_NAMESEG_SIZE);
0154 break;
0155
0156 case AML_MULTI_NAME_PREFIX:
0157
0158
0159
0160 end += 2 + (*(end + 1) * ACPI_NAMESEG_SIZE);
0161 break;
0162
0163 default:
0164
0165
0166
0167 end += ACPI_NAMESEG_SIZE;
0168 break;
0169 }
0170
0171 parser_state->aml = end;
0172 return_PTR((char *)start);
0173 }
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 acpi_status
0197 acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
0198 struct acpi_parse_state *parser_state,
0199 union acpi_parse_object *arg, u8 possible_method_call)
0200 {
0201 acpi_status status;
0202 char *path;
0203 union acpi_parse_object *name_op;
0204 union acpi_operand_object *method_desc;
0205 struct acpi_namespace_node *node;
0206 u8 *start = parser_state->aml;
0207
0208 ACPI_FUNCTION_TRACE(ps_get_next_namepath);
0209
0210 path = acpi_ps_get_next_namestring(parser_state);
0211 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
0212
0213
0214
0215 if (!path) {
0216 arg->common.value.name = path;
0217 return_ACPI_STATUS(AE_OK);
0218 }
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228 status = acpi_ns_lookup(walk_state->scope_info, path,
0229 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0230 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
0231 NULL, &node);
0232
0233
0234
0235
0236
0237 if (ACPI_SUCCESS(status) &&
0238 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
0239 if ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
0240 ARGP_SUPERNAME)
0241 || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
0242 ARGP_TARGET)) {
0243
0244
0245
0246
0247
0248
0249 walk_state->parser_state.aml = start;
0250 walk_state->arg_count = 1;
0251 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
0252 }
0253
0254
0255
0256 method_desc = acpi_ns_get_attached_object(node);
0257 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
0258 "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
0259 node->name.ascii, node, method_desc, path));
0260
0261 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start);
0262 if (!name_op) {
0263 return_ACPI_STATUS(AE_NO_MEMORY);
0264 }
0265
0266
0267
0268 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
0269 name_op->common.value.name = path;
0270
0271
0272
0273 name_op->common.node = node;
0274 acpi_ps_append_arg(arg, name_op);
0275
0276 if (!method_desc) {
0277 ACPI_ERROR((AE_INFO,
0278 "Control Method %p has no attached object",
0279 node));
0280 return_ACPI_STATUS(AE_AML_INTERNAL);
0281 }
0282
0283 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
0284 "Control Method - %p Args %X\n",
0285 node, method_desc->method.param_count));
0286
0287
0288
0289 walk_state->arg_count = method_desc->method.param_count;
0290 return_ACPI_STATUS(AE_OK);
0291 }
0292
0293
0294
0295
0296
0297 if (status == AE_NOT_FOUND) {
0298
0299
0300
0301 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
0302 ACPI_PARSE_EXECUTE) {
0303 status = AE_OK;
0304 }
0305
0306
0307
0308 else if (walk_state->op->common.aml_opcode ==
0309 AML_CONDITIONAL_REF_OF_OP) {
0310 status = AE_OK;
0311 }
0312
0313
0314
0315
0316
0317
0318 else if ((arg->common.parent) &&
0319 ((arg->common.parent->common.aml_opcode ==
0320 AML_PACKAGE_OP)
0321 || (arg->common.parent->common.aml_opcode ==
0322 AML_VARIABLE_PACKAGE_OP))) {
0323 status = AE_OK;
0324 }
0325 }
0326
0327
0328
0329 if (ACPI_FAILURE(status)) {
0330 ACPI_ERROR_NAMESPACE(walk_state->scope_info, path, status);
0331
0332 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
0333 ACPI_PARSE_EXECUTE) {
0334
0335
0336
0337 status = acpi_ds_method_error(status, walk_state);
0338 }
0339 }
0340
0341
0342
0343 arg->common.value.name = path;
0344 return_ACPI_STATUS(status);
0345 }
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361 void
0362 acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
0363 u32 arg_type, union acpi_parse_object *arg)
0364 {
0365 u32 length;
0366 u16 opcode;
0367 u8 *aml = parser_state->aml;
0368
0369 ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
0370
0371 switch (arg_type) {
0372 case ARGP_BYTEDATA:
0373
0374
0375
0376 opcode = AML_BYTE_OP;
0377 arg->common.value.integer = (u64) *aml;
0378 length = 1;
0379 break;
0380
0381 case ARGP_WORDDATA:
0382
0383
0384
0385 opcode = AML_WORD_OP;
0386 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
0387 length = 2;
0388 break;
0389
0390 case ARGP_DWORDDATA:
0391
0392
0393
0394 opcode = AML_DWORD_OP;
0395 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
0396 length = 4;
0397 break;
0398
0399 case ARGP_QWORDDATA:
0400
0401
0402
0403 opcode = AML_QWORD_OP;
0404 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
0405 length = 8;
0406 break;
0407
0408 case ARGP_CHARLIST:
0409
0410
0411
0412 opcode = AML_STRING_OP;
0413 arg->common.value.string = ACPI_CAST_PTR(char, aml);
0414
0415
0416
0417 length = 0;
0418 while (aml[length]) {
0419 length++;
0420 }
0421 length++;
0422 break;
0423
0424 case ARGP_NAME:
0425 case ARGP_NAMESTRING:
0426
0427 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
0428 arg->common.value.name =
0429 acpi_ps_get_next_namestring(parser_state);
0430 return_VOID;
0431
0432 default:
0433
0434 ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
0435 return_VOID;
0436 }
0437
0438 acpi_ps_init_op(arg, opcode);
0439 parser_state->aml += length;
0440 return_VOID;
0441 }
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455 static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
0456 *parser_state)
0457 {
0458 u8 *aml;
0459 union acpi_parse_object *field;
0460 union acpi_parse_object *arg = NULL;
0461 u16 opcode;
0462 u32 name;
0463 u8 access_type;
0464 u8 access_attribute;
0465 u8 access_length;
0466 u32 pkg_length;
0467 u8 *pkg_end;
0468 u32 buffer_length;
0469
0470 ACPI_FUNCTION_TRACE(ps_get_next_field);
0471
0472 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0473 aml = parser_state->aml;
0474
0475
0476
0477 switch (ACPI_GET8(parser_state->aml)) {
0478 case AML_FIELD_OFFSET_OP:
0479
0480 opcode = AML_INT_RESERVEDFIELD_OP;
0481 parser_state->aml++;
0482 break;
0483
0484 case AML_FIELD_ACCESS_OP:
0485
0486 opcode = AML_INT_ACCESSFIELD_OP;
0487 parser_state->aml++;
0488 break;
0489
0490 case AML_FIELD_CONNECTION_OP:
0491
0492 opcode = AML_INT_CONNECTION_OP;
0493 parser_state->aml++;
0494 break;
0495
0496 case AML_FIELD_EXT_ACCESS_OP:
0497
0498 opcode = AML_INT_EXTACCESSFIELD_OP;
0499 parser_state->aml++;
0500 break;
0501
0502 default:
0503
0504 opcode = AML_INT_NAMEDFIELD_OP;
0505 break;
0506 }
0507
0508
0509
0510 field = acpi_ps_alloc_op(opcode, aml);
0511 if (!field) {
0512 return_PTR(NULL);
0513 }
0514
0515
0516
0517 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0518 switch (opcode) {
0519 case AML_INT_NAMEDFIELD_OP:
0520
0521
0522
0523 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
0524 acpi_ps_set_name(field, name);
0525 parser_state->aml += ACPI_NAMESEG_SIZE;
0526
0527 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0528
0529 #ifdef ACPI_ASL_COMPILER
0530
0531
0532
0533
0534
0535 if (field->common.inline_comment) {
0536 field->common.name_comment =
0537 field->common.inline_comment;
0538 }
0539 field->common.inline_comment = acpi_gbl_current_inline_comment;
0540 acpi_gbl_current_inline_comment = NULL;
0541 #endif
0542
0543
0544
0545 field->common.value.size =
0546 acpi_ps_get_next_package_length(parser_state);
0547 break;
0548
0549 case AML_INT_RESERVEDFIELD_OP:
0550
0551
0552
0553 field->common.value.size =
0554 acpi_ps_get_next_package_length(parser_state);
0555 break;
0556
0557 case AML_INT_ACCESSFIELD_OP:
0558 case AML_INT_EXTACCESSFIELD_OP:
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568 access_type = ACPI_GET8(parser_state->aml);
0569 parser_state->aml++;
0570 access_attribute = ACPI_GET8(parser_state->aml);
0571 parser_state->aml++;
0572
0573 field->common.value.integer = (u8)access_type;
0574 field->common.value.integer |= (u16)(access_attribute << 8);
0575
0576
0577
0578 if (opcode == AML_INT_EXTACCESSFIELD_OP) {
0579 access_length = ACPI_GET8(parser_state->aml);
0580 parser_state->aml++;
0581
0582 field->common.value.integer |=
0583 (u32)(access_length << 16);
0584 }
0585 break;
0586
0587 case AML_INT_CONNECTION_OP:
0588
0589
0590
0591
0592
0593 aml = parser_state->aml;
0594 if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
0595 parser_state->aml++;
0596
0597 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0598 pkg_end = parser_state->aml;
0599 pkg_length =
0600 acpi_ps_get_next_package_length(parser_state);
0601 pkg_end += pkg_length;
0602
0603 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0604 if (parser_state->aml < pkg_end) {
0605
0606
0607
0608 arg =
0609 acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
0610 if (!arg) {
0611 acpi_ps_free_op(field);
0612 return_PTR(NULL);
0613 }
0614
0615
0616
0617 opcode = ACPI_GET8(parser_state->aml);
0618 parser_state->aml++;
0619
0620 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0621 switch (opcode) {
0622 case AML_BYTE_OP:
0623
0624 buffer_length =
0625 ACPI_GET8(parser_state->aml);
0626 parser_state->aml += 1;
0627 break;
0628
0629 case AML_WORD_OP:
0630
0631 buffer_length =
0632 ACPI_GET16(parser_state->aml);
0633 parser_state->aml += 2;
0634 break;
0635
0636 case AML_DWORD_OP:
0637
0638 buffer_length =
0639 ACPI_GET32(parser_state->aml);
0640 parser_state->aml += 4;
0641 break;
0642
0643 default:
0644
0645 buffer_length = 0;
0646 break;
0647 }
0648
0649
0650
0651 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0652 arg->named.value.size = buffer_length;
0653 arg->named.data = parser_state->aml;
0654 }
0655
0656
0657
0658 parser_state->aml = pkg_end;
0659 } else {
0660 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
0661 if (!arg) {
0662 acpi_ps_free_op(field);
0663 return_PTR(NULL);
0664 }
0665
0666
0667
0668 arg->common.value.name =
0669 acpi_ps_get_next_namestring(parser_state);
0670 }
0671
0672
0673
0674 acpi_ps_append_arg(field, arg);
0675 break;
0676
0677 default:
0678
0679
0680 break;
0681 }
0682
0683 return_PTR(field);
0684 }
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702 acpi_status
0703 acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
0704 struct acpi_parse_state *parser_state,
0705 u32 arg_type, union acpi_parse_object **return_arg)
0706 {
0707 union acpi_parse_object *arg = NULL;
0708 union acpi_parse_object *prev = NULL;
0709 union acpi_parse_object *field;
0710 u32 subop;
0711 acpi_status status = AE_OK;
0712
0713 ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
0714
0715 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
0716 "Expected argument type ARGP: %s (%2.2X)\n",
0717 acpi_ut_get_argument_type_name(arg_type), arg_type));
0718
0719 switch (arg_type) {
0720 case ARGP_BYTEDATA:
0721 case ARGP_WORDDATA:
0722 case ARGP_DWORDDATA:
0723 case ARGP_CHARLIST:
0724 case ARGP_NAME:
0725 case ARGP_NAMESTRING:
0726
0727
0728
0729 arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
0730 if (!arg) {
0731 return_ACPI_STATUS(AE_NO_MEMORY);
0732 }
0733
0734 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
0735 break;
0736
0737 case ARGP_PKGLENGTH:
0738
0739
0740
0741 parser_state->pkg_end =
0742 acpi_ps_get_next_package_end(parser_state);
0743 break;
0744
0745 case ARGP_FIELDLIST:
0746
0747 if (parser_state->aml < parser_state->pkg_end) {
0748
0749
0750
0751 while (parser_state->aml < parser_state->pkg_end) {
0752 field = acpi_ps_get_next_field(parser_state);
0753 if (!field) {
0754 return_ACPI_STATUS(AE_NO_MEMORY);
0755 }
0756
0757 if (prev) {
0758 prev->common.next = field;
0759 } else {
0760 arg = field;
0761 }
0762 prev = field;
0763 }
0764
0765
0766
0767 parser_state->aml = parser_state->pkg_end;
0768 }
0769 break;
0770
0771 case ARGP_BYTELIST:
0772
0773 if (parser_state->aml < parser_state->pkg_end) {
0774
0775
0776
0777 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
0778 parser_state->aml);
0779 if (!arg) {
0780 return_ACPI_STATUS(AE_NO_MEMORY);
0781 }
0782
0783
0784
0785 arg->common.value.size = (u32)
0786 ACPI_PTR_DIFF(parser_state->pkg_end,
0787 parser_state->aml);
0788 arg->named.data = parser_state->aml;
0789
0790
0791
0792 parser_state->aml = parser_state->pkg_end;
0793 }
0794 break;
0795
0796 case ARGP_SIMPLENAME:
0797 case ARGP_NAME_OR_REF:
0798
0799 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
0800 "**** SimpleName/NameOrRef: %s (%2.2X)\n",
0801 acpi_ut_get_argument_type_name(arg_type),
0802 arg_type));
0803
0804 subop = acpi_ps_peek_opcode(parser_state);
0805 if (subop == 0 ||
0806 acpi_ps_is_leading_char(subop) ||
0807 ACPI_IS_ROOT_PREFIX(subop) ||
0808 ACPI_IS_PARENT_PREFIX(subop)) {
0809
0810
0811
0812 arg =
0813 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
0814 parser_state->aml);
0815 if (!arg) {
0816 return_ACPI_STATUS(AE_NO_MEMORY);
0817 }
0818
0819 status =
0820 acpi_ps_get_next_namepath(walk_state, parser_state,
0821 arg,
0822 ACPI_NOT_METHOD_CALL);
0823 } else {
0824
0825
0826 walk_state->arg_count = 1;
0827 }
0828 break;
0829
0830 case ARGP_TARGET:
0831 case ARGP_SUPERNAME:
0832
0833 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
0834 "**** Target/Supername: %s (%2.2X)\n",
0835 acpi_ut_get_argument_type_name(arg_type),
0836 arg_type));
0837
0838 subop = acpi_ps_peek_opcode(parser_state);
0839 if (subop == 0 ||
0840 acpi_ps_is_leading_char(subop) ||
0841 ACPI_IS_ROOT_PREFIX(subop) ||
0842 ACPI_IS_PARENT_PREFIX(subop)) {
0843
0844
0845
0846 arg =
0847 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
0848 parser_state->aml);
0849 if (!arg) {
0850 return_ACPI_STATUS(AE_NO_MEMORY);
0851 }
0852
0853 status =
0854 acpi_ps_get_next_namepath(walk_state, parser_state,
0855 arg,
0856 ACPI_POSSIBLE_METHOD_CALL);
0857
0858 if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) {
0859
0860
0861
0862 acpi_ps_free_op(arg->common.value.arg);
0863 acpi_ps_free_op(arg);
0864 arg = NULL;
0865 walk_state->arg_count = 1;
0866 }
0867 } else {
0868
0869
0870 walk_state->arg_count = 1;
0871 }
0872 break;
0873
0874 case ARGP_DATAOBJ:
0875 case ARGP_TERMARG:
0876
0877 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
0878 "**** TermArg/DataObj: %s (%2.2X)\n",
0879 acpi_ut_get_argument_type_name(arg_type),
0880 arg_type));
0881
0882
0883
0884 walk_state->arg_count = 1;
0885 break;
0886
0887 case ARGP_DATAOBJLIST:
0888 case ARGP_TERMLIST:
0889 case ARGP_OBJLIST:
0890
0891 if (parser_state->aml < parser_state->pkg_end) {
0892
0893
0894
0895 walk_state->arg_count = ACPI_VAR_ARGS;
0896 }
0897 break;
0898
0899 default:
0900
0901 ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
0902 status = AE_AML_OPERAND_TYPE;
0903 break;
0904 }
0905
0906 *return_arg = arg;
0907 return_ACPI_STATUS(status);
0908 }