psargs.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /******************************************************************************
  2. *
  3. * Module Name: psargs - Parse AML opcode arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2017, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acparser.h"
  45. #include "amlcode.h"
  46. #include "acnamesp.h"
  47. #include "acdispat.h"
  48. #include "acconvert.h"
  49. #define _COMPONENT ACPI_PARSER
  50. ACPI_MODULE_NAME("psargs")
  51. /* Local prototypes */
  52. static u32
  53. acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
  54. static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
  55. *parser_state);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ps_get_next_package_length
  59. *
  60. * PARAMETERS: parser_state - Current parser state object
  61. *
  62. * RETURN: Decoded package length. On completion, the AML pointer points
  63. * past the length byte or bytes.
  64. *
  65. * DESCRIPTION: Decode and return a package length field.
  66. * Note: Largest package length is 28 bits, from ACPI specification
  67. *
  68. ******************************************************************************/
  69. static u32
  70. acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
  71. {
  72. u8 *aml = parser_state->aml;
  73. u32 package_length = 0;
  74. u32 byte_count;
  75. u8 byte_zero_mask = 0x3F; /* Default [0:5] */
  76. ACPI_FUNCTION_TRACE(ps_get_next_package_length);
  77. /*
  78. * Byte 0 bits [6:7] contain the number of additional bytes
  79. * used to encode the package length, either 0,1,2, or 3
  80. */
  81. byte_count = (aml[0] >> 6);
  82. parser_state->aml += ((acpi_size)byte_count + 1);
  83. /* Get bytes 3, 2, 1 as needed */
  84. while (byte_count) {
  85. /*
  86. * Final bit positions for the package length bytes:
  87. * Byte3->[20:27]
  88. * Byte2->[12:19]
  89. * Byte1->[04:11]
  90. * Byte0->[00:03]
  91. */
  92. package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
  93. byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */
  94. byte_count--;
  95. }
  96. /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
  97. package_length |= (aml[0] & byte_zero_mask);
  98. return_UINT32(package_length);
  99. }
  100. /*******************************************************************************
  101. *
  102. * FUNCTION: acpi_ps_get_next_package_end
  103. *
  104. * PARAMETERS: parser_state - Current parser state object
  105. *
  106. * RETURN: Pointer to end-of-package +1
  107. *
  108. * DESCRIPTION: Get next package length and return a pointer past the end of
  109. * the package. Consumes the package length field
  110. *
  111. ******************************************************************************/
  112. u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
  113. {
  114. u8 *start = parser_state->aml;
  115. u32 package_length;
  116. ACPI_FUNCTION_TRACE(ps_get_next_package_end);
  117. /* Function below updates parser_state->Aml */
  118. package_length = acpi_ps_get_next_package_length(parser_state);
  119. return_PTR(start + package_length); /* end of package */
  120. }
  121. /*******************************************************************************
  122. *
  123. * FUNCTION: acpi_ps_get_next_namestring
  124. *
  125. * PARAMETERS: parser_state - Current parser state object
  126. *
  127. * RETURN: Pointer to the start of the name string (pointer points into
  128. * the AML.
  129. *
  130. * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
  131. * prefix characters. Set parser state to point past the string.
  132. * (Name is consumed from the AML.)
  133. *
  134. ******************************************************************************/
  135. char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
  136. {
  137. u8 *start = parser_state->aml;
  138. u8 *end = parser_state->aml;
  139. ACPI_FUNCTION_TRACE(ps_get_next_namestring);
  140. /* Point past any namestring prefix characters (backslash or carat) */
  141. while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) {
  142. end++;
  143. }
  144. /* Decode the path prefix character */
  145. switch (*end) {
  146. case 0:
  147. /* null_name */
  148. if (end == start) {
  149. start = NULL;
  150. }
  151. end++;
  152. break;
  153. case AML_DUAL_NAME_PREFIX:
  154. /* Two name segments */
  155. end += 1 + (2 * ACPI_NAME_SIZE);
  156. break;
  157. case AML_MULTI_NAME_PREFIX:
  158. /* Multiple name segments, 4 chars each, count in next byte */
  159. end += 2 + (*(end + 1) * ACPI_NAME_SIZE);
  160. break;
  161. default:
  162. /* Single name segment */
  163. end += ACPI_NAME_SIZE;
  164. break;
  165. }
  166. parser_state->aml = end;
  167. return_PTR((char *)start);
  168. }
  169. /*******************************************************************************
  170. *
  171. * FUNCTION: acpi_ps_get_next_namepath
  172. *
  173. * PARAMETERS: parser_state - Current parser state object
  174. * arg - Where the namepath will be stored
  175. * arg_count - If the namepath points to a control method
  176. * the method's argument is returned here.
  177. * possible_method_call - Whether the namepath can possibly be the
  178. * start of a method call
  179. *
  180. * RETURN: Status
  181. *
  182. * DESCRIPTION: Get next name (if method call, return # of required args).
  183. * Names are looked up in the internal namespace to determine
  184. * if the name represents a control method. If a method
  185. * is found, the number of arguments to the method is returned.
  186. * This information is critical for parsing to continue correctly.
  187. *
  188. ******************************************************************************/
  189. acpi_status
  190. acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
  191. struct acpi_parse_state *parser_state,
  192. union acpi_parse_object *arg, u8 possible_method_call)
  193. {
  194. acpi_status status;
  195. char *path;
  196. union acpi_parse_object *name_op;
  197. union acpi_operand_object *method_desc;
  198. struct acpi_namespace_node *node;
  199. u8 *start = parser_state->aml;
  200. ACPI_FUNCTION_TRACE(ps_get_next_namepath);
  201. path = acpi_ps_get_next_namestring(parser_state);
  202. acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
  203. /* Null path case is allowed, just exit */
  204. if (!path) {
  205. arg->common.value.name = path;
  206. return_ACPI_STATUS(AE_OK);
  207. }
  208. /*
  209. * Lookup the name in the internal namespace, starting with the current
  210. * scope. We don't want to add anything new to the namespace here,
  211. * however, so we use MODE_EXECUTE.
  212. * Allow searching of the parent tree, but don't open a new scope -
  213. * we just want to lookup the object (must be mode EXECUTE to perform
  214. * the upsearch)
  215. */
  216. status = acpi_ns_lookup(walk_state->scope_info, path,
  217. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  218. ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
  219. NULL, &node);
  220. /*
  221. * If this name is a control method invocation, we must
  222. * setup the method call
  223. */
  224. if (ACPI_SUCCESS(status) &&
  225. possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
  226. if ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
  227. ARGP_SUPERNAME)
  228. || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
  229. ARGP_TARGET)) {
  230. /*
  231. * acpi_ps_get_next_namestring has increased the AML pointer past
  232. * the method invocation namestring, so we need to restore the
  233. * saved AML pointer back to the original method invocation
  234. * namestring.
  235. */
  236. walk_state->parser_state.aml = start;
  237. walk_state->arg_count = 1;
  238. acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
  239. }
  240. /* This name is actually a control method invocation */
  241. method_desc = acpi_ns_get_attached_object(node);
  242. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  243. "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
  244. node->name.ascii, node, method_desc, path));
  245. name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start);
  246. if (!name_op) {
  247. return_ACPI_STATUS(AE_NO_MEMORY);
  248. }
  249. /* Change Arg into a METHOD CALL and attach name to it */
  250. acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
  251. name_op->common.value.name = path;
  252. /* Point METHODCALL/NAME to the METHOD Node */
  253. name_op->common.node = node;
  254. acpi_ps_append_arg(arg, name_op);
  255. if (!method_desc) {
  256. ACPI_ERROR((AE_INFO,
  257. "Control Method %p has no attached object",
  258. node));
  259. return_ACPI_STATUS(AE_AML_INTERNAL);
  260. }
  261. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  262. "Control Method - %p Args %X\n",
  263. node, method_desc->method.param_count));
  264. /* Get the number of arguments to expect */
  265. walk_state->arg_count = method_desc->method.param_count;
  266. return_ACPI_STATUS(AE_OK);
  267. }
  268. /*
  269. * Special handling if the name was not found during the lookup -
  270. * some not_found cases are allowed
  271. */
  272. if (status == AE_NOT_FOUND) {
  273. /* 1) not_found is ok during load pass 1/2 (allow forward references) */
  274. if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
  275. ACPI_PARSE_EXECUTE) {
  276. status = AE_OK;
  277. }
  278. /* 2) not_found during a cond_ref_of(x) is ok by definition */
  279. else if (walk_state->op->common.aml_opcode ==
  280. AML_CONDITIONAL_REF_OF_OP) {
  281. status = AE_OK;
  282. }
  283. /*
  284. * 3) not_found while building a Package is ok at this point, we
  285. * may flag as an error later if slack mode is not enabled.
  286. * (Some ASL code depends on allowing this behavior)
  287. */
  288. else if ((arg->common.parent) &&
  289. ((arg->common.parent->common.aml_opcode ==
  290. AML_PACKAGE_OP)
  291. || (arg->common.parent->common.aml_opcode ==
  292. AML_VARIABLE_PACKAGE_OP))) {
  293. status = AE_OK;
  294. }
  295. }
  296. /* Final exception check (may have been changed from code above) */
  297. if (ACPI_FAILURE(status)) {
  298. ACPI_ERROR_NAMESPACE(path, status);
  299. if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
  300. ACPI_PARSE_EXECUTE) {
  301. /* Report a control method execution error */
  302. status = acpi_ds_method_error(status, walk_state);
  303. }
  304. }
  305. /* Save the namepath */
  306. arg->common.value.name = path;
  307. return_ACPI_STATUS(status);
  308. }
  309. /*******************************************************************************
  310. *
  311. * FUNCTION: acpi_ps_get_next_simple_arg
  312. *
  313. * PARAMETERS: parser_state - Current parser state object
  314. * arg_type - The argument type (AML_*_ARG)
  315. * arg - Where the argument is returned
  316. *
  317. * RETURN: None
  318. *
  319. * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
  320. *
  321. ******************************************************************************/
  322. void
  323. acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
  324. u32 arg_type, union acpi_parse_object *arg)
  325. {
  326. u32 length;
  327. u16 opcode;
  328. u8 *aml = parser_state->aml;
  329. ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
  330. switch (arg_type) {
  331. case ARGP_BYTEDATA:
  332. /* Get 1 byte from the AML stream */
  333. opcode = AML_BYTE_OP;
  334. arg->common.value.integer = (u64) *aml;
  335. length = 1;
  336. break;
  337. case ARGP_WORDDATA:
  338. /* Get 2 bytes from the AML stream */
  339. opcode = AML_WORD_OP;
  340. ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
  341. length = 2;
  342. break;
  343. case ARGP_DWORDDATA:
  344. /* Get 4 bytes from the AML stream */
  345. opcode = AML_DWORD_OP;
  346. ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
  347. length = 4;
  348. break;
  349. case ARGP_QWORDDATA:
  350. /* Get 8 bytes from the AML stream */
  351. opcode = AML_QWORD_OP;
  352. ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
  353. length = 8;
  354. break;
  355. case ARGP_CHARLIST:
  356. /* Get a pointer to the string, point past the string */
  357. opcode = AML_STRING_OP;
  358. arg->common.value.string = ACPI_CAST_PTR(char, aml);
  359. /* Find the null terminator */
  360. length = 0;
  361. while (aml[length]) {
  362. length++;
  363. }
  364. length++;
  365. break;
  366. case ARGP_NAME:
  367. case ARGP_NAMESTRING:
  368. acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
  369. arg->common.value.name =
  370. acpi_ps_get_next_namestring(parser_state);
  371. return_VOID;
  372. default:
  373. ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
  374. return_VOID;
  375. }
  376. acpi_ps_init_op(arg, opcode);
  377. parser_state->aml += length;
  378. return_VOID;
  379. }
  380. /*******************************************************************************
  381. *
  382. * FUNCTION: acpi_ps_get_next_field
  383. *
  384. * PARAMETERS: parser_state - Current parser state object
  385. *
  386. * RETURN: A newly allocated FIELD op
  387. *
  388. * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
  389. *
  390. ******************************************************************************/
  391. static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
  392. *parser_state)
  393. {
  394. u8 *aml;
  395. union acpi_parse_object *field;
  396. union acpi_parse_object *arg = NULL;
  397. u16 opcode;
  398. u32 name;
  399. u8 access_type;
  400. u8 access_attribute;
  401. u8 access_length;
  402. u32 pkg_length;
  403. u8 *pkg_end;
  404. u32 buffer_length;
  405. ACPI_FUNCTION_TRACE(ps_get_next_field);
  406. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  407. aml = parser_state->aml;
  408. /* Determine field type */
  409. switch (ACPI_GET8(parser_state->aml)) {
  410. case AML_FIELD_OFFSET_OP:
  411. opcode = AML_INT_RESERVEDFIELD_OP;
  412. parser_state->aml++;
  413. break;
  414. case AML_FIELD_ACCESS_OP:
  415. opcode = AML_INT_ACCESSFIELD_OP;
  416. parser_state->aml++;
  417. break;
  418. case AML_FIELD_CONNECTION_OP:
  419. opcode = AML_INT_CONNECTION_OP;
  420. parser_state->aml++;
  421. break;
  422. case AML_FIELD_EXT_ACCESS_OP:
  423. opcode = AML_INT_EXTACCESSFIELD_OP;
  424. parser_state->aml++;
  425. break;
  426. default:
  427. opcode = AML_INT_NAMEDFIELD_OP;
  428. break;
  429. }
  430. /* Allocate a new field op */
  431. field = acpi_ps_alloc_op(opcode, aml);
  432. if (!field) {
  433. return_PTR(NULL);
  434. }
  435. /* Decode the field type */
  436. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  437. switch (opcode) {
  438. case AML_INT_NAMEDFIELD_OP:
  439. /* Get the 4-character name */
  440. ACPI_MOVE_32_TO_32(&name, parser_state->aml);
  441. acpi_ps_set_name(field, name);
  442. parser_state->aml += ACPI_NAME_SIZE;
  443. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  444. #ifdef ACPI_ASL_COMPILER
  445. /*
  446. * Because the package length isn't represented as a parse tree object,
  447. * take comments surrounding this and add to the previously created
  448. * parse node.
  449. */
  450. if (field->common.inline_comment) {
  451. field->common.name_comment =
  452. field->common.inline_comment;
  453. }
  454. field->common.inline_comment = acpi_gbl_current_inline_comment;
  455. acpi_gbl_current_inline_comment = NULL;
  456. #endif
  457. /* Get the length which is encoded as a package length */
  458. field->common.value.size =
  459. acpi_ps_get_next_package_length(parser_state);
  460. break;
  461. case AML_INT_RESERVEDFIELD_OP:
  462. /* Get the length which is encoded as a package length */
  463. field->common.value.size =
  464. acpi_ps_get_next_package_length(parser_state);
  465. break;
  466. case AML_INT_ACCESSFIELD_OP:
  467. case AML_INT_EXTACCESSFIELD_OP:
  468. /*
  469. * Get access_type and access_attrib and merge into the field Op
  470. * access_type is first operand, access_attribute is second. stuff
  471. * these bytes into the node integer value for convenience.
  472. */
  473. /* Get the two bytes (Type/Attribute) */
  474. access_type = ACPI_GET8(parser_state->aml);
  475. parser_state->aml++;
  476. access_attribute = ACPI_GET8(parser_state->aml);
  477. parser_state->aml++;
  478. field->common.value.integer = (u8)access_type;
  479. field->common.value.integer |= (u16)(access_attribute << 8);
  480. /* This opcode has a third byte, access_length */
  481. if (opcode == AML_INT_EXTACCESSFIELD_OP) {
  482. access_length = ACPI_GET8(parser_state->aml);
  483. parser_state->aml++;
  484. field->common.value.integer |=
  485. (u32)(access_length << 16);
  486. }
  487. break;
  488. case AML_INT_CONNECTION_OP:
  489. /*
  490. * Argument for Connection operator can be either a Buffer
  491. * (resource descriptor), or a name_string.
  492. */
  493. aml = parser_state->aml;
  494. if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
  495. parser_state->aml++;
  496. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  497. pkg_end = parser_state->aml;
  498. pkg_length =
  499. acpi_ps_get_next_package_length(parser_state);
  500. pkg_end += pkg_length;
  501. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  502. if (parser_state->aml < pkg_end) {
  503. /* Non-empty list */
  504. arg =
  505. acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
  506. if (!arg) {
  507. acpi_ps_free_op(field);
  508. return_PTR(NULL);
  509. }
  510. /* Get the actual buffer length argument */
  511. opcode = ACPI_GET8(parser_state->aml);
  512. parser_state->aml++;
  513. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  514. switch (opcode) {
  515. case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
  516. buffer_length =
  517. ACPI_GET8(parser_state->aml);
  518. parser_state->aml += 1;
  519. break;
  520. case AML_WORD_OP: /* AML_WORDDATA_ARG */
  521. buffer_length =
  522. ACPI_GET16(parser_state->aml);
  523. parser_state->aml += 2;
  524. break;
  525. case AML_DWORD_OP: /* AML_DWORDATA_ARG */
  526. buffer_length =
  527. ACPI_GET32(parser_state->aml);
  528. parser_state->aml += 4;
  529. break;
  530. default:
  531. buffer_length = 0;
  532. break;
  533. }
  534. /* Fill in bytelist data */
  535. ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
  536. arg->named.value.size = buffer_length;
  537. arg->named.data = parser_state->aml;
  538. }
  539. /* Skip to End of byte data */
  540. parser_state->aml = pkg_end;
  541. } else {
  542. arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
  543. if (!arg) {
  544. acpi_ps_free_op(field);
  545. return_PTR(NULL);
  546. }
  547. /* Get the Namestring argument */
  548. arg->common.value.name =
  549. acpi_ps_get_next_namestring(parser_state);
  550. }
  551. /* Link the buffer/namestring to parent (CONNECTION_OP) */
  552. acpi_ps_append_arg(field, arg);
  553. break;
  554. default:
  555. /* Opcode was set in previous switch */
  556. break;
  557. }
  558. return_PTR(field);
  559. }
  560. /*******************************************************************************
  561. *
  562. * FUNCTION: acpi_ps_get_next_arg
  563. *
  564. * PARAMETERS: walk_state - Current state
  565. * parser_state - Current parser state object
  566. * arg_type - The argument type (AML_*_ARG)
  567. * return_arg - Where the next arg is returned
  568. *
  569. * RETURN: Status, and an op object containing the next argument.
  570. *
  571. * DESCRIPTION: Get next argument (including complex list arguments that require
  572. * pushing the parser stack)
  573. *
  574. ******************************************************************************/
  575. acpi_status
  576. acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
  577. struct acpi_parse_state *parser_state,
  578. u32 arg_type, union acpi_parse_object **return_arg)
  579. {
  580. union acpi_parse_object *arg = NULL;
  581. union acpi_parse_object *prev = NULL;
  582. union acpi_parse_object *field;
  583. u32 subop;
  584. acpi_status status = AE_OK;
  585. ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
  586. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  587. "Expected argument type ARGP: %s (%2.2X)\n",
  588. acpi_ut_get_argument_type_name(arg_type), arg_type));
  589. switch (arg_type) {
  590. case ARGP_BYTEDATA:
  591. case ARGP_WORDDATA:
  592. case ARGP_DWORDDATA:
  593. case ARGP_CHARLIST:
  594. case ARGP_NAME:
  595. case ARGP_NAMESTRING:
  596. /* Constants, strings, and namestrings are all the same size */
  597. arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
  598. if (!arg) {
  599. return_ACPI_STATUS(AE_NO_MEMORY);
  600. }
  601. acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
  602. break;
  603. case ARGP_PKGLENGTH:
  604. /* Package length, nothing returned */
  605. parser_state->pkg_end =
  606. acpi_ps_get_next_package_end(parser_state);
  607. break;
  608. case ARGP_FIELDLIST:
  609. if (parser_state->aml < parser_state->pkg_end) {
  610. /* Non-empty list */
  611. while (parser_state->aml < parser_state->pkg_end) {
  612. field = acpi_ps_get_next_field(parser_state);
  613. if (!field) {
  614. return_ACPI_STATUS(AE_NO_MEMORY);
  615. }
  616. if (prev) {
  617. prev->common.next = field;
  618. } else {
  619. arg = field;
  620. }
  621. prev = field;
  622. }
  623. /* Skip to End of byte data */
  624. parser_state->aml = parser_state->pkg_end;
  625. }
  626. break;
  627. case ARGP_BYTELIST:
  628. if (parser_state->aml < parser_state->pkg_end) {
  629. /* Non-empty list */
  630. arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
  631. parser_state->aml);
  632. if (!arg) {
  633. return_ACPI_STATUS(AE_NO_MEMORY);
  634. }
  635. /* Fill in bytelist data */
  636. arg->common.value.size = (u32)
  637. ACPI_PTR_DIFF(parser_state->pkg_end,
  638. parser_state->aml);
  639. arg->named.data = parser_state->aml;
  640. /* Skip to End of byte data */
  641. parser_state->aml = parser_state->pkg_end;
  642. }
  643. break;
  644. case ARGP_SIMPLENAME:
  645. case ARGP_NAME_OR_REF:
  646. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  647. "**** SimpleName/NameOrRef: %s (%2.2X)\n",
  648. acpi_ut_get_argument_type_name(arg_type),
  649. arg_type));
  650. subop = acpi_ps_peek_opcode(parser_state);
  651. if (subop == 0 ||
  652. acpi_ps_is_leading_char(subop) ||
  653. ACPI_IS_ROOT_PREFIX(subop) ||
  654. ACPI_IS_PARENT_PREFIX(subop)) {
  655. /* null_name or name_string */
  656. arg =
  657. acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
  658. parser_state->aml);
  659. if (!arg) {
  660. return_ACPI_STATUS(AE_NO_MEMORY);
  661. }
  662. status =
  663. acpi_ps_get_next_namepath(walk_state, parser_state,
  664. arg,
  665. ACPI_NOT_METHOD_CALL);
  666. } else {
  667. /* Single complex argument, nothing returned */
  668. walk_state->arg_count = 1;
  669. }
  670. break;
  671. case ARGP_TARGET:
  672. case ARGP_SUPERNAME:
  673. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  674. "**** Target/Supername: %s (%2.2X)\n",
  675. acpi_ut_get_argument_type_name(arg_type),
  676. arg_type));
  677. subop = acpi_ps_peek_opcode(parser_state);
  678. if (subop == 0 ||
  679. acpi_ps_is_leading_char(subop) ||
  680. ACPI_IS_ROOT_PREFIX(subop) ||
  681. ACPI_IS_PARENT_PREFIX(subop)) {
  682. /* NULL target (zero). Convert to a NULL namepath */
  683. arg =
  684. acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
  685. parser_state->aml);
  686. if (!arg) {
  687. return_ACPI_STATUS(AE_NO_MEMORY);
  688. }
  689. status =
  690. acpi_ps_get_next_namepath(walk_state, parser_state,
  691. arg,
  692. ACPI_POSSIBLE_METHOD_CALL);
  693. if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) {
  694. acpi_ps_free_op(arg);
  695. arg = NULL;
  696. walk_state->arg_count = 1;
  697. }
  698. } else {
  699. /* Single complex argument, nothing returned */
  700. walk_state->arg_count = 1;
  701. }
  702. break;
  703. case ARGP_DATAOBJ:
  704. case ARGP_TERMARG:
  705. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  706. "**** TermArg/DataObj: %s (%2.2X)\n",
  707. acpi_ut_get_argument_type_name(arg_type),
  708. arg_type));
  709. /* Single complex argument, nothing returned */
  710. walk_state->arg_count = 1;
  711. break;
  712. case ARGP_DATAOBJLIST:
  713. case ARGP_TERMLIST:
  714. case ARGP_OBJLIST:
  715. if (parser_state->aml < parser_state->pkg_end) {
  716. /* Non-empty list of variable arguments, nothing returned */
  717. walk_state->arg_count = ACPI_VAR_ARGS;
  718. }
  719. break;
  720. default:
  721. ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
  722. status = AE_AML_OPERAND_TYPE;
  723. break;
  724. }
  725. *return_arg = arg;
  726. return_ACPI_STATUS(status);
  727. }