Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: psargs - Parse AML opcode arguments
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
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 /* Local prototypes */
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  * FUNCTION:    acpi_ps_get_next_package_length
0031  *
0032  * PARAMETERS:  parser_state        - Current parser state object
0033  *
0034  * RETURN:      Decoded package length. On completion, the AML pointer points
0035  *              past the length byte or bytes.
0036  *
0037  * DESCRIPTION: Decode and return a package length field.
0038  *              Note: Largest package length is 28 bits, from ACPI specification
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;   /* Default [0:5] */
0049 
0050     ACPI_FUNCTION_TRACE(ps_get_next_package_length);
0051 
0052     /*
0053      * Byte 0 bits [6:7] contain the number of additional bytes
0054      * used to encode the package length, either 0,1,2, or 3
0055      */
0056     byte_count = (aml[0] >> 6);
0057     parser_state->aml += ((acpi_size)byte_count + 1);
0058 
0059     /* Get bytes 3, 2, 1 as needed */
0060 
0061     while (byte_count) {
0062         /*
0063          * Final bit positions for the package length bytes:
0064          *      Byte3->[20:27]
0065          *      Byte2->[12:19]
0066          *      Byte1->[04:11]
0067          *      Byte0->[00:03]
0068          */
0069         package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
0070 
0071         byte_zero_mask = 0x0F;  /* Use bits [0:3] of byte 0 */
0072         byte_count--;
0073     }
0074 
0075     /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
0076 
0077     package_length |= (aml[0] & byte_zero_mask);
0078     return_UINT32(package_length);
0079 }
0080 
0081 /*******************************************************************************
0082  *
0083  * FUNCTION:    acpi_ps_get_next_package_end
0084  *
0085  * PARAMETERS:  parser_state        - Current parser state object
0086  *
0087  * RETURN:      Pointer to end-of-package +1
0088  *
0089  * DESCRIPTION: Get next package length and return a pointer past the end of
0090  *              the package. Consumes the package length field
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     /* Function below updates parser_state->Aml */
0102 
0103     package_length = acpi_ps_get_next_package_length(parser_state);
0104 
0105     return_PTR(start + package_length); /* end of package */
0106 }
0107 
0108 /*******************************************************************************
0109  *
0110  * FUNCTION:    acpi_ps_get_next_namestring
0111  *
0112  * PARAMETERS:  parser_state        - Current parser state object
0113  *
0114  * RETURN:      Pointer to the start of the name string (pointer points into
0115  *              the AML.
0116  *
0117  * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
0118  *              prefix characters. Set parser state to point past the string.
0119  *              (Name is consumed from the AML.)
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     /* Point past any namestring prefix characters (backslash or carat) */
0131 
0132     while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) {
0133         end++;
0134     }
0135 
0136     /* Decode the path prefix character */
0137 
0138     switch (*end) {
0139     case 0:
0140 
0141         /* null_name */
0142 
0143         if (end == start) {
0144             start = NULL;
0145         }
0146         end++;
0147         break;
0148 
0149     case AML_DUAL_NAME_PREFIX:
0150 
0151         /* Two name segments */
0152 
0153         end += 1 + (2 * ACPI_NAMESEG_SIZE);
0154         break;
0155 
0156     case AML_MULTI_NAME_PREFIX:
0157 
0158         /* Multiple name segments, 4 chars each, count in next byte */
0159 
0160         end += 2 + (*(end + 1) * ACPI_NAMESEG_SIZE);
0161         break;
0162 
0163     default:
0164 
0165         /* Single name segment */
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  * FUNCTION:    acpi_ps_get_next_namepath
0178  *
0179  * PARAMETERS:  parser_state        - Current parser state object
0180  *              arg                 - Where the namepath will be stored
0181  *              arg_count           - If the namepath points to a control method
0182  *                                    the method's argument is returned here.
0183  *              possible_method_call - Whether the namepath can possibly be the
0184  *                                    start of a method call
0185  *
0186  * RETURN:      Status
0187  *
0188  * DESCRIPTION: Get next name (if method call, return # of required args).
0189  *              Names are looked up in the internal namespace to determine
0190  *              if the name represents a control method. If a method
0191  *              is found, the number of arguments to the method is returned.
0192  *              This information is critical for parsing to continue correctly.
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     /* Null path case is allowed, just exit */
0214 
0215     if (!path) {
0216         arg->common.value.name = path;
0217         return_ACPI_STATUS(AE_OK);
0218     }
0219 
0220     /*
0221      * Lookup the name in the internal namespace, starting with the current
0222      * scope. We don't want to add anything new to the namespace here,
0223      * however, so we use MODE_EXECUTE.
0224      * Allow searching of the parent tree, but don't open a new scope -
0225      * we just want to lookup the object (must be mode EXECUTE to perform
0226      * the upsearch)
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      * If this name is a control method invocation, we must
0235      * setup the method call
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              * acpi_ps_get_next_namestring has increased the AML pointer past
0245              * the method invocation namestring, so we need to restore the
0246              * saved AML pointer back to the original method invocation
0247              * namestring.
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         /* This name is actually a control method invocation */
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         /* Change Arg into a METHOD CALL and attach name to it */
0267 
0268         acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
0269         name_op->common.value.name = path;
0270 
0271         /* Point METHODCALL/NAME to the METHOD Node */
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         /* Get the number of arguments to expect */
0288 
0289         walk_state->arg_count = method_desc->method.param_count;
0290         return_ACPI_STATUS(AE_OK);
0291     }
0292 
0293     /*
0294      * Special handling if the name was not found during the lookup -
0295      * some not_found cases are allowed
0296      */
0297     if (status == AE_NOT_FOUND) {
0298 
0299         /* 1) not_found is ok during load pass 1/2 (allow forward references) */
0300 
0301         if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
0302             ACPI_PARSE_EXECUTE) {
0303             status = AE_OK;
0304         }
0305 
0306         /* 2) not_found during a cond_ref_of(x) is ok by definition */
0307 
0308         else if (walk_state->op->common.aml_opcode ==
0309              AML_CONDITIONAL_REF_OF_OP) {
0310             status = AE_OK;
0311         }
0312 
0313         /*
0314          * 3) not_found while building a Package is ok at this point, we
0315          * may flag as an error later if slack mode is not enabled.
0316          * (Some ASL code depends on allowing this behavior)
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     /* Final exception check (may have been changed from code above) */
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             /* Report a control method execution error */
0336 
0337             status = acpi_ds_method_error(status, walk_state);
0338         }
0339     }
0340 
0341     /* Save the namepath */
0342 
0343     arg->common.value.name = path;
0344     return_ACPI_STATUS(status);
0345 }
0346 
0347 /*******************************************************************************
0348  *
0349  * FUNCTION:    acpi_ps_get_next_simple_arg
0350  *
0351  * PARAMETERS:  parser_state        - Current parser state object
0352  *              arg_type            - The argument type (AML_*_ARG)
0353  *              arg                 - Where the argument is returned
0354  *
0355  * RETURN:      None
0356  *
0357  * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
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         /* Get 1 byte from the AML stream */
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         /* Get 2 bytes from the AML stream */
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         /* Get 4 bytes from the AML stream */
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         /* Get 8 bytes from the AML stream */
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         /* Get a pointer to the string, point past the string */
0411 
0412         opcode = AML_STRING_OP;
0413         arg->common.value.string = ACPI_CAST_PTR(char, aml);
0414 
0415         /* Find the null terminator */
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  * FUNCTION:    acpi_ps_get_next_field
0446  *
0447  * PARAMETERS:  parser_state        - Current parser state object
0448  *
0449  * RETURN:      A newly allocated FIELD op
0450  *
0451  * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
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     /* Determine field type */
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     /* Allocate a new field op */
0509 
0510     field = acpi_ps_alloc_op(opcode, aml);
0511     if (!field) {
0512         return_PTR(NULL);
0513     }
0514 
0515     /* Decode the field type */
0516 
0517     ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
0518     switch (opcode) {
0519     case AML_INT_NAMEDFIELD_OP:
0520 
0521         /* Get the 4-character name */
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          * Because the package length isn't represented as a parse tree object,
0532          * take comments surrounding this and add to the previously created
0533          * parse node.
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         /* Get the length which is encoded as a package length */
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         /* Get the length which is encoded as a package length */
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          * Get access_type and access_attrib and merge into the field Op
0562          * access_type is first operand, access_attribute is second. stuff
0563          * these bytes into the node integer value for convenience.
0564          */
0565 
0566         /* Get the two bytes (Type/Attribute) */
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         /* This opcode has a third byte, access_length */
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          * Argument for Connection operator can be either a Buffer
0591          * (resource descriptor), or a name_string.
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                 /* Non-empty list */
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                 /* Get the actual buffer length argument */
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:   /* AML_BYTEDATA_ARG */
0623 
0624                     buffer_length =
0625                         ACPI_GET8(parser_state->aml);
0626                     parser_state->aml += 1;
0627                     break;
0628 
0629                 case AML_WORD_OP:   /* AML_WORDDATA_ARG */
0630 
0631                     buffer_length =
0632                         ACPI_GET16(parser_state->aml);
0633                     parser_state->aml += 2;
0634                     break;
0635 
0636                 case AML_DWORD_OP:  /* AML_DWORDATA_ARG */
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                 /* Fill in bytelist data */
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             /* Skip to End of byte data */
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             /* Get the Namestring argument */
0667 
0668             arg->common.value.name =
0669                 acpi_ps_get_next_namestring(parser_state);
0670         }
0671 
0672         /* Link the buffer/namestring to parent (CONNECTION_OP) */
0673 
0674         acpi_ps_append_arg(field, arg);
0675         break;
0676 
0677     default:
0678 
0679         /* Opcode was set in previous switch */
0680         break;
0681     }
0682 
0683     return_PTR(field);
0684 }
0685 
0686 /*******************************************************************************
0687  *
0688  * FUNCTION:    acpi_ps_get_next_arg
0689  *
0690  * PARAMETERS:  walk_state          - Current state
0691  *              parser_state        - Current parser state object
0692  *              arg_type            - The argument type (AML_*_ARG)
0693  *              return_arg          - Where the next arg is returned
0694  *
0695  * RETURN:      Status, and an op object containing the next argument.
0696  *
0697  * DESCRIPTION: Get next argument (including complex list arguments that require
0698  *              pushing the parser stack)
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         /* Constants, strings, and namestrings are all the same size */
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         /* Package length, nothing returned */
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             /* Non-empty list */
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             /* Skip to End of byte data */
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             /* Non-empty list */
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             /* Fill in bytelist data */
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             /* Skip to End of byte data */
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             /* null_name or name_string */
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             /* Single complex argument, nothing returned */
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             /* NULL target (zero). Convert to a NULL namepath */
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                 /* Free method call op and corresponding namestring sub-ob */
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             /* Single complex argument, nothing returned */
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         /* Single complex argument, nothing returned */
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             /* Non-empty list of variable arguments, nothing returned */
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 }