psargs.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /******************************************************************************
  2. *
  3. * Module Name: psargs - Parse AML opcode arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2019, 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.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 UINT32
  53. AcpiPsGetNextPackageLength (
  54. ACPI_PARSE_STATE *ParserState);
  55. static ACPI_PARSE_OBJECT *
  56. AcpiPsGetNextField (
  57. ACPI_PARSE_STATE *ParserState);
  58. /*******************************************************************************
  59. *
  60. * FUNCTION: AcpiPsGetNextPackageLength
  61. *
  62. * PARAMETERS: ParserState - Current parser state object
  63. *
  64. * RETURN: Decoded package length. On completion, the AML pointer points
  65. * past the length byte or bytes.
  66. *
  67. * DESCRIPTION: Decode and return a package length field.
  68. * Note: Largest package length is 28 bits, from ACPI specification
  69. *
  70. ******************************************************************************/
  71. static UINT32
  72. AcpiPsGetNextPackageLength (
  73. ACPI_PARSE_STATE *ParserState)
  74. {
  75. UINT8 *Aml = ParserState->Aml;
  76. UINT32 PackageLength = 0;
  77. UINT32 ByteCount;
  78. UINT8 ByteZeroMask = 0x3F; /* Default [0:5] */
  79. ACPI_FUNCTION_TRACE (PsGetNextPackageLength);
  80. /*
  81. * Byte 0 bits [6:7] contain the number of additional bytes
  82. * used to encode the package length, either 0,1,2, or 3
  83. */
  84. ByteCount = (Aml[0] >> 6);
  85. ParserState->Aml += ((ACPI_SIZE) ByteCount + 1);
  86. /* Get bytes 3, 2, 1 as needed */
  87. while (ByteCount)
  88. {
  89. /*
  90. * Final bit positions for the package length bytes:
  91. * Byte3->[20:27]
  92. * Byte2->[12:19]
  93. * Byte1->[04:11]
  94. * Byte0->[00:03]
  95. */
  96. PackageLength |= (Aml[ByteCount] << ((ByteCount << 3) - 4));
  97. ByteZeroMask = 0x0F; /* Use bits [0:3] of byte 0 */
  98. ByteCount--;
  99. }
  100. /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
  101. PackageLength |= (Aml[0] & ByteZeroMask);
  102. return_UINT32 (PackageLength);
  103. }
  104. /*******************************************************************************
  105. *
  106. * FUNCTION: AcpiPsGetNextPackageEnd
  107. *
  108. * PARAMETERS: ParserState - Current parser state object
  109. *
  110. * RETURN: Pointer to end-of-package +1
  111. *
  112. * DESCRIPTION: Get next package length and return a pointer past the end of
  113. * the package. Consumes the package length field
  114. *
  115. ******************************************************************************/
  116. UINT8 *
  117. AcpiPsGetNextPackageEnd (
  118. ACPI_PARSE_STATE *ParserState)
  119. {
  120. UINT8 *Start = ParserState->Aml;
  121. UINT32 PackageLength;
  122. ACPI_FUNCTION_TRACE (PsGetNextPackageEnd);
  123. /* Function below updates ParserState->Aml */
  124. PackageLength = AcpiPsGetNextPackageLength (ParserState);
  125. return_PTR (Start + PackageLength); /* end of package */
  126. }
  127. /*******************************************************************************
  128. *
  129. * FUNCTION: AcpiPsGetNextNamestring
  130. *
  131. * PARAMETERS: ParserState - Current parser state object
  132. *
  133. * RETURN: Pointer to the start of the name string (pointer points into
  134. * the AML.
  135. *
  136. * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
  137. * prefix characters. Set parser state to point past the string.
  138. * (Name is consumed from the AML.)
  139. *
  140. ******************************************************************************/
  141. char *
  142. AcpiPsGetNextNamestring (
  143. ACPI_PARSE_STATE *ParserState)
  144. {
  145. UINT8 *Start = ParserState->Aml;
  146. UINT8 *End = ParserState->Aml;
  147. ACPI_FUNCTION_TRACE (PsGetNextNamestring);
  148. /* Point past any namestring prefix characters (backslash or carat) */
  149. while (ACPI_IS_ROOT_PREFIX (*End) ||
  150. ACPI_IS_PARENT_PREFIX (*End))
  151. {
  152. End++;
  153. }
  154. /* Decode the path prefix character */
  155. switch (*End)
  156. {
  157. case 0:
  158. /* NullName */
  159. if (End == Start)
  160. {
  161. Start = NULL;
  162. }
  163. End++;
  164. break;
  165. case AML_DUAL_NAME_PREFIX:
  166. /* Two name segments */
  167. End += 1 + (2 * ACPI_NAMESEG_SIZE);
  168. break;
  169. case AML_MULTI_NAME_PREFIX:
  170. /* Multiple name segments, 4 chars each, count in next byte */
  171. End += 2 + (*(End + 1) * ACPI_NAMESEG_SIZE);
  172. break;
  173. default:
  174. /* Single name segment */
  175. End += ACPI_NAMESEG_SIZE;
  176. break;
  177. }
  178. ParserState->Aml = End;
  179. return_PTR ((char *) Start);
  180. }
  181. /*******************************************************************************
  182. *
  183. * FUNCTION: AcpiPsGetNextNamepath
  184. *
  185. * PARAMETERS: ParserState - Current parser state object
  186. * Arg - Where the namepath will be stored
  187. * ArgCount - If the namepath points to a control method
  188. * the method's argument is returned here.
  189. * PossibleMethodCall - Whether the namepath can possibly be the
  190. * start of a method call
  191. *
  192. * RETURN: Status
  193. *
  194. * DESCRIPTION: Get next name (if method call, return # of required args).
  195. * Names are looked up in the internal namespace to determine
  196. * if the name represents a control method. If a method
  197. * is found, the number of arguments to the method is returned.
  198. * This information is critical for parsing to continue correctly.
  199. *
  200. ******************************************************************************/
  201. ACPI_STATUS
  202. AcpiPsGetNextNamepath (
  203. ACPI_WALK_STATE *WalkState,
  204. ACPI_PARSE_STATE *ParserState,
  205. ACPI_PARSE_OBJECT *Arg,
  206. BOOLEAN PossibleMethodCall)
  207. {
  208. ACPI_STATUS Status;
  209. char *Path;
  210. ACPI_PARSE_OBJECT *NameOp;
  211. ACPI_OPERAND_OBJECT *MethodDesc;
  212. ACPI_NAMESPACE_NODE *Node;
  213. UINT8 *Start = ParserState->Aml;
  214. ACPI_FUNCTION_TRACE (PsGetNextNamepath);
  215. Path = AcpiPsGetNextNamestring (ParserState);
  216. AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
  217. /* Null path case is allowed, just exit */
  218. if (!Path)
  219. {
  220. Arg->Common.Value.Name = Path;
  221. return_ACPI_STATUS (AE_OK);
  222. }
  223. /*
  224. * Lookup the name in the internal namespace, starting with the current
  225. * scope. We don't want to add anything new to the namespace here,
  226. * however, so we use MODE_EXECUTE.
  227. * Allow searching of the parent tree, but don't open a new scope -
  228. * we just want to lookup the object (must be mode EXECUTE to perform
  229. * the upsearch)
  230. */
  231. Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
  232. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  233. ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
  234. /*
  235. * If this name is a control method invocation, we must
  236. * setup the method call
  237. */
  238. if (ACPI_SUCCESS (Status) &&
  239. PossibleMethodCall &&
  240. (Node->Type == ACPI_TYPE_METHOD))
  241. {
  242. if ((GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_SUPERNAME) ||
  243. (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_TARGET))
  244. {
  245. /*
  246. * AcpiPsGetNextNamestring has increased the AML pointer past
  247. * the method invocation namestring, so we need to restore the
  248. * saved AML pointer back to the original method invocation
  249. * namestring.
  250. */
  251. WalkState->ParserState.Aml = Start;
  252. WalkState->ArgCount = 1;
  253. AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
  254. }
  255. /* This name is actually a control method invocation */
  256. MethodDesc = AcpiNsGetAttachedObject (Node);
  257. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  258. "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
  259. Node->Name.Ascii, Node, MethodDesc, Path));
  260. NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Start);
  261. if (!NameOp)
  262. {
  263. return_ACPI_STATUS (AE_NO_MEMORY);
  264. }
  265. /* Change Arg into a METHOD CALL and attach name to it */
  266. AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
  267. NameOp->Common.Value.Name = Path;
  268. /* Point METHODCALL/NAME to the METHOD Node */
  269. NameOp->Common.Node = Node;
  270. AcpiPsAppendArg (Arg, NameOp);
  271. if (!MethodDesc)
  272. {
  273. ACPI_ERROR ((AE_INFO,
  274. "Control Method %p has no attached object",
  275. Node));
  276. return_ACPI_STATUS (AE_AML_INTERNAL);
  277. }
  278. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  279. "Control Method - %p Args %X\n",
  280. Node, MethodDesc->Method.ParamCount));
  281. /* Get the number of arguments to expect */
  282. WalkState->ArgCount = MethodDesc->Method.ParamCount;
  283. return_ACPI_STATUS (AE_OK);
  284. }
  285. /*
  286. * Special handling if the name was not found during the lookup -
  287. * some NotFound cases are allowed
  288. */
  289. if (Status == AE_NOT_FOUND)
  290. {
  291. /* 1) NotFound is ok during load pass 1/2 (allow forward references) */
  292. if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=
  293. ACPI_PARSE_EXECUTE)
  294. {
  295. Status = AE_OK;
  296. }
  297. /* 2) NotFound during a CondRefOf(x) is ok by definition */
  298. else if (WalkState->Op->Common.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)
  299. {
  300. Status = AE_OK;
  301. }
  302. /*
  303. * 3) NotFound while building a Package is ok at this point, we
  304. * may flag as an error later if slack mode is not enabled.
  305. * (Some ASL code depends on allowing this behavior)
  306. */
  307. else if ((Arg->Common.Parent) &&
  308. ((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  309. (Arg->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP)))
  310. {
  311. Status = AE_OK;
  312. }
  313. }
  314. /* Final exception check (may have been changed from code above) */
  315. if (ACPI_FAILURE (Status))
  316. {
  317. ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
  318. if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
  319. ACPI_PARSE_EXECUTE)
  320. {
  321. /* Report a control method execution error */
  322. Status = AcpiDsMethodError (Status, WalkState);
  323. }
  324. }
  325. /* Save the namepath */
  326. Arg->Common.Value.Name = Path;
  327. return_ACPI_STATUS (Status);
  328. }
  329. /*******************************************************************************
  330. *
  331. * FUNCTION: AcpiPsGetNextSimpleArg
  332. *
  333. * PARAMETERS: ParserState - Current parser state object
  334. * ArgType - The argument type (AML_*_ARG)
  335. * Arg - Where the argument is returned
  336. *
  337. * RETURN: None
  338. *
  339. * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
  340. *
  341. ******************************************************************************/
  342. void
  343. AcpiPsGetNextSimpleArg (
  344. ACPI_PARSE_STATE *ParserState,
  345. UINT32 ArgType,
  346. ACPI_PARSE_OBJECT *Arg)
  347. {
  348. UINT32 Length;
  349. UINT16 Opcode;
  350. UINT8 *Aml = ParserState->Aml;
  351. ACPI_FUNCTION_TRACE_U32 (PsGetNextSimpleArg, ArgType);
  352. switch (ArgType)
  353. {
  354. case ARGP_BYTEDATA:
  355. /* Get 1 byte from the AML stream */
  356. Opcode = AML_BYTE_OP;
  357. Arg->Common.Value.Integer = (UINT64) *Aml;
  358. Length = 1;
  359. break;
  360. case ARGP_WORDDATA:
  361. /* Get 2 bytes from the AML stream */
  362. Opcode = AML_WORD_OP;
  363. ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
  364. Length = 2;
  365. break;
  366. case ARGP_DWORDDATA:
  367. /* Get 4 bytes from the AML stream */
  368. Opcode = AML_DWORD_OP;
  369. ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
  370. Length = 4;
  371. break;
  372. case ARGP_QWORDDATA:
  373. /* Get 8 bytes from the AML stream */
  374. Opcode = AML_QWORD_OP;
  375. ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
  376. Length = 8;
  377. break;
  378. case ARGP_CHARLIST:
  379. /* Get a pointer to the string, point past the string */
  380. Opcode = AML_STRING_OP;
  381. Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
  382. /* Find the null terminator */
  383. Length = 0;
  384. while (Aml[Length])
  385. {
  386. Length++;
  387. }
  388. Length++;
  389. break;
  390. case ARGP_NAME:
  391. case ARGP_NAMESTRING:
  392. AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
  393. Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
  394. return_VOID;
  395. default:
  396. ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));
  397. return_VOID;
  398. }
  399. AcpiPsInitOp (Arg, Opcode);
  400. ParserState->Aml += Length;
  401. return_VOID;
  402. }
  403. /*******************************************************************************
  404. *
  405. * FUNCTION: AcpiPsGetNextField
  406. *
  407. * PARAMETERS: ParserState - Current parser state object
  408. *
  409. * RETURN: A newly allocated FIELD op
  410. *
  411. * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
  412. *
  413. ******************************************************************************/
  414. static ACPI_PARSE_OBJECT *
  415. AcpiPsGetNextField (
  416. ACPI_PARSE_STATE *ParserState)
  417. {
  418. UINT8 *Aml;
  419. ACPI_PARSE_OBJECT *Field;
  420. ACPI_PARSE_OBJECT *Arg = NULL;
  421. UINT16 Opcode;
  422. UINT32 Name;
  423. UINT8 AccessType;
  424. UINT8 AccessAttribute;
  425. UINT8 AccessLength;
  426. UINT32 PkgLength;
  427. UINT8 *PkgEnd;
  428. UINT32 BufferLength;
  429. ACPI_FUNCTION_TRACE (PsGetNextField);
  430. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  431. Aml = ParserState->Aml;
  432. /* Determine field type */
  433. switch (ACPI_GET8 (ParserState->Aml))
  434. {
  435. case AML_FIELD_OFFSET_OP:
  436. Opcode = AML_INT_RESERVEDFIELD_OP;
  437. ParserState->Aml++;
  438. break;
  439. case AML_FIELD_ACCESS_OP:
  440. Opcode = AML_INT_ACCESSFIELD_OP;
  441. ParserState->Aml++;
  442. break;
  443. case AML_FIELD_CONNECTION_OP:
  444. Opcode = AML_INT_CONNECTION_OP;
  445. ParserState->Aml++;
  446. break;
  447. case AML_FIELD_EXT_ACCESS_OP:
  448. Opcode = AML_INT_EXTACCESSFIELD_OP;
  449. ParserState->Aml++;
  450. break;
  451. default:
  452. Opcode = AML_INT_NAMEDFIELD_OP;
  453. break;
  454. }
  455. /* Allocate a new field op */
  456. Field = AcpiPsAllocOp (Opcode, Aml);
  457. if (!Field)
  458. {
  459. return_PTR (NULL);
  460. }
  461. /* Decode the field type */
  462. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  463. switch (Opcode)
  464. {
  465. case AML_INT_NAMEDFIELD_OP:
  466. /* Get the 4-character name */
  467. ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
  468. AcpiPsSetName (Field, Name);
  469. ParserState->Aml += ACPI_NAMESEG_SIZE;
  470. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  471. #ifdef ACPI_ASL_COMPILER
  472. /*
  473. * Because the package length isn't represented as a parse tree object,
  474. * take comments surrounding this and add to the previously created
  475. * parse node.
  476. */
  477. if (Field->Common.InlineComment)
  478. {
  479. Field->Common.NameComment = Field->Common.InlineComment;
  480. }
  481. Field->Common.InlineComment = AcpiGbl_CurrentInlineComment;
  482. AcpiGbl_CurrentInlineComment = NULL;
  483. #endif
  484. /* Get the length which is encoded as a package length */
  485. Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
  486. break;
  487. case AML_INT_RESERVEDFIELD_OP:
  488. /* Get the length which is encoded as a package length */
  489. Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
  490. break;
  491. case AML_INT_ACCESSFIELD_OP:
  492. case AML_INT_EXTACCESSFIELD_OP:
  493. /*
  494. * Get AccessType and AccessAttrib and merge into the field Op
  495. * AccessType is first operand, AccessAttribute is second. stuff
  496. * these bytes into the node integer value for convenience.
  497. */
  498. /* Get the two bytes (Type/Attribute) */
  499. AccessType = ACPI_GET8 (ParserState->Aml);
  500. ParserState->Aml++;
  501. AccessAttribute = ACPI_GET8 (ParserState->Aml);
  502. ParserState->Aml++;
  503. Field->Common.Value.Integer = (UINT8) AccessType;
  504. Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
  505. /* This opcode has a third byte, AccessLength */
  506. if (Opcode == AML_INT_EXTACCESSFIELD_OP)
  507. {
  508. AccessLength = ACPI_GET8 (ParserState->Aml);
  509. ParserState->Aml++;
  510. Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
  511. }
  512. break;
  513. case AML_INT_CONNECTION_OP:
  514. /*
  515. * Argument for Connection operator can be either a Buffer
  516. * (resource descriptor), or a NameString.
  517. */
  518. Aml = ParserState->Aml;
  519. if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
  520. {
  521. ParserState->Aml++;
  522. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  523. PkgEnd = ParserState->Aml;
  524. PkgLength = AcpiPsGetNextPackageLength (ParserState);
  525. PkgEnd += PkgLength;
  526. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  527. if (ParserState->Aml < PkgEnd)
  528. {
  529. /* Non-empty list */
  530. Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP, Aml);
  531. if (!Arg)
  532. {
  533. AcpiPsFreeOp (Field);
  534. return_PTR (NULL);
  535. }
  536. /* Get the actual buffer length argument */
  537. Opcode = ACPI_GET8 (ParserState->Aml);
  538. ParserState->Aml++;
  539. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  540. switch (Opcode)
  541. {
  542. case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
  543. BufferLength = ACPI_GET8 (ParserState->Aml);
  544. ParserState->Aml += 1;
  545. break;
  546. case AML_WORD_OP: /* AML_WORDDATA_ARG */
  547. BufferLength = ACPI_GET16 (ParserState->Aml);
  548. ParserState->Aml += 2;
  549. break;
  550. case AML_DWORD_OP: /* AML_DWORDATA_ARG */
  551. BufferLength = ACPI_GET32 (ParserState->Aml);
  552. ParserState->Aml += 4;
  553. break;
  554. default:
  555. BufferLength = 0;
  556. break;
  557. }
  558. /* Fill in bytelist data */
  559. ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
  560. Arg->Named.Value.Size = BufferLength;
  561. Arg->Named.Data = ParserState->Aml;
  562. }
  563. /* Skip to End of byte data */
  564. ParserState->Aml = PkgEnd;
  565. }
  566. else
  567. {
  568. Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Aml);
  569. if (!Arg)
  570. {
  571. AcpiPsFreeOp (Field);
  572. return_PTR (NULL);
  573. }
  574. /* Get the Namestring argument */
  575. Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
  576. }
  577. /* Link the buffer/namestring to parent (CONNECTION_OP) */
  578. AcpiPsAppendArg (Field, Arg);
  579. break;
  580. default:
  581. /* Opcode was set in previous switch */
  582. break;
  583. }
  584. return_PTR (Field);
  585. }
  586. /*******************************************************************************
  587. *
  588. * FUNCTION: AcpiPsGetNextArg
  589. *
  590. * PARAMETERS: WalkState - Current state
  591. * ParserState - Current parser state object
  592. * ArgType - The argument type (AML_*_ARG)
  593. * ReturnArg - Where the next arg is returned
  594. *
  595. * RETURN: Status, and an op object containing the next argument.
  596. *
  597. * DESCRIPTION: Get next argument (including complex list arguments that require
  598. * pushing the parser stack)
  599. *
  600. ******************************************************************************/
  601. ACPI_STATUS
  602. AcpiPsGetNextArg (
  603. ACPI_WALK_STATE *WalkState,
  604. ACPI_PARSE_STATE *ParserState,
  605. UINT32 ArgType,
  606. ACPI_PARSE_OBJECT **ReturnArg)
  607. {
  608. ACPI_PARSE_OBJECT *Arg = NULL;
  609. ACPI_PARSE_OBJECT *Prev = NULL;
  610. ACPI_PARSE_OBJECT *Field;
  611. UINT32 Subop;
  612. ACPI_STATUS Status = AE_OK;
  613. ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
  614. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  615. "Expected argument type ARGP: %s (%2.2X)\n",
  616. AcpiUtGetArgumentTypeName (ArgType), ArgType));
  617. switch (ArgType)
  618. {
  619. case ARGP_BYTEDATA:
  620. case ARGP_WORDDATA:
  621. case ARGP_DWORDDATA:
  622. case ARGP_CHARLIST:
  623. case ARGP_NAME:
  624. case ARGP_NAMESTRING:
  625. /* Constants, strings, and namestrings are all the same size */
  626. Arg = AcpiPsAllocOp (AML_BYTE_OP, ParserState->Aml);
  627. if (!Arg)
  628. {
  629. return_ACPI_STATUS (AE_NO_MEMORY);
  630. }
  631. AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
  632. break;
  633. case ARGP_PKGLENGTH:
  634. /* Package length, nothing returned */
  635. ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
  636. break;
  637. case ARGP_FIELDLIST:
  638. if (ParserState->Aml < ParserState->PkgEnd)
  639. {
  640. /* Non-empty list */
  641. while (ParserState->Aml < ParserState->PkgEnd)
  642. {
  643. Field = AcpiPsGetNextField (ParserState);
  644. if (!Field)
  645. {
  646. return_ACPI_STATUS (AE_NO_MEMORY);
  647. }
  648. if (Prev)
  649. {
  650. Prev->Common.Next = Field;
  651. }
  652. else
  653. {
  654. Arg = Field;
  655. }
  656. Prev = Field;
  657. }
  658. /* Skip to End of byte data */
  659. ParserState->Aml = ParserState->PkgEnd;
  660. }
  661. break;
  662. case ARGP_BYTELIST:
  663. if (ParserState->Aml < ParserState->PkgEnd)
  664. {
  665. /* Non-empty list */
  666. Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP,
  667. ParserState->Aml);
  668. if (!Arg)
  669. {
  670. return_ACPI_STATUS (AE_NO_MEMORY);
  671. }
  672. /* Fill in bytelist data */
  673. Arg->Common.Value.Size = (UINT32)
  674. ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
  675. Arg->Named.Data = ParserState->Aml;
  676. /* Skip to End of byte data */
  677. ParserState->Aml = ParserState->PkgEnd;
  678. }
  679. break;
  680. case ARGP_SIMPLENAME:
  681. case ARGP_NAME_OR_REF:
  682. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  683. "**** SimpleName/NameOrRef: %s (%2.2X)\n",
  684. AcpiUtGetArgumentTypeName (ArgType), ArgType));
  685. Subop = AcpiPsPeekOpcode (ParserState);
  686. if (Subop == 0 ||
  687. AcpiPsIsLeadingChar (Subop) ||
  688. ACPI_IS_ROOT_PREFIX (Subop) ||
  689. ACPI_IS_PARENT_PREFIX (Subop))
  690. {
  691. /* NullName or NameString */
  692. Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);
  693. if (!Arg)
  694. {
  695. return_ACPI_STATUS (AE_NO_MEMORY);
  696. }
  697. Status = AcpiPsGetNextNamepath (WalkState, ParserState,
  698. Arg, ACPI_NOT_METHOD_CALL);
  699. }
  700. else
  701. {
  702. /* Single complex argument, nothing returned */
  703. WalkState->ArgCount = 1;
  704. }
  705. break;
  706. case ARGP_TARGET:
  707. case ARGP_SUPERNAME:
  708. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  709. "**** Target/Supername: %s (%2.2X)\n",
  710. AcpiUtGetArgumentTypeName (ArgType), ArgType));
  711. Subop = AcpiPsPeekOpcode (ParserState);
  712. if (Subop == 0 ||
  713. AcpiPsIsLeadingChar (Subop) ||
  714. ACPI_IS_ROOT_PREFIX (Subop) ||
  715. ACPI_IS_PARENT_PREFIX (Subop))
  716. {
  717. /* NULL target (zero). Convert to a NULL namepath */
  718. Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);
  719. if (!Arg)
  720. {
  721. return_ACPI_STATUS (AE_NO_MEMORY);
  722. }
  723. Status = AcpiPsGetNextNamepath (WalkState, ParserState,
  724. Arg, ACPI_POSSIBLE_METHOD_CALL);
  725. if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
  726. {
  727. /* Free method call op and corresponding namestring sub-ob */
  728. AcpiPsFreeOp (Arg->Common.Value.Arg);
  729. AcpiPsFreeOp (Arg);
  730. Arg = NULL;
  731. WalkState->ArgCount = 1;
  732. }
  733. }
  734. else
  735. {
  736. /* Single complex argument, nothing returned */
  737. WalkState->ArgCount = 1;
  738. }
  739. break;
  740. case ARGP_DATAOBJ:
  741. case ARGP_TERMARG:
  742. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  743. "**** TermArg/DataObj: %s (%2.2X)\n",
  744. AcpiUtGetArgumentTypeName (ArgType), ArgType));
  745. /* Single complex argument, nothing returned */
  746. WalkState->ArgCount = 1;
  747. break;
  748. case ARGP_DATAOBJLIST:
  749. case ARGP_TERMLIST:
  750. case ARGP_OBJLIST:
  751. if (ParserState->Aml < ParserState->PkgEnd)
  752. {
  753. /* Non-empty list of variable arguments, nothing returned */
  754. WalkState->ArgCount = ACPI_VAR_ARGS;
  755. }
  756. break;
  757. default:
  758. ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
  759. Status = AE_AML_OPERAND_TYPE;
  760. break;
  761. }
  762. *ReturnArg = Arg;
  763. return_ACPI_STATUS (Status);
  764. }