dsobject.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /******************************************************************************
  2. *
  3. * Module Name: dsobject - Dispatcher object management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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 "acdispat.h"
  47. #include "acnamesp.h"
  48. #include "acinterp.h"
  49. #define _COMPONENT ACPI_DISPATCHER
  50. ACPI_MODULE_NAME ("dsobject")
  51. /* Local prototypes */
  52. static ACPI_STATUS
  53. AcpiDsBuildInternalObject (
  54. ACPI_WALK_STATE *WalkState,
  55. ACPI_PARSE_OBJECT *Op,
  56. ACPI_OPERAND_OBJECT **ObjDescPtr);
  57. #ifndef ACPI_NO_METHOD_EXECUTION
  58. /*******************************************************************************
  59. *
  60. * FUNCTION: AcpiDsBuildInternalObject
  61. *
  62. * PARAMETERS: WalkState - Current walk state
  63. * Op - Parser object to be translated
  64. * ObjDescPtr - Where the ACPI internal object is returned
  65. *
  66. * RETURN: Status
  67. *
  68. * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
  69. * Simple objects are any objects other than a package object!
  70. *
  71. ******************************************************************************/
  72. static ACPI_STATUS
  73. AcpiDsBuildInternalObject (
  74. ACPI_WALK_STATE *WalkState,
  75. ACPI_PARSE_OBJECT *Op,
  76. ACPI_OPERAND_OBJECT **ObjDescPtr)
  77. {
  78. ACPI_OPERAND_OBJECT *ObjDesc;
  79. ACPI_STATUS Status;
  80. ACPI_OBJECT_TYPE Type;
  81. ACPI_FUNCTION_TRACE (DsBuildInternalObject);
  82. *ObjDescPtr = NULL;
  83. if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
  84. {
  85. /*
  86. * This is a named object reference. If this name was
  87. * previously looked up in the namespace, it was stored in this op.
  88. * Otherwise, go ahead and look it up now
  89. */
  90. if (!Op->Common.Node)
  91. {
  92. Status = AcpiNsLookup (WalkState->ScopeInfo,
  93. Op->Common.Value.String,
  94. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  95. ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
  96. ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
  97. if (ACPI_FAILURE (Status))
  98. {
  99. /* Check if we are resolving a named reference within a package */
  100. if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
  101. ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  102. (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
  103. {
  104. /*
  105. * We didn't find the target and we are populating elements
  106. * of a package - ignore if slack enabled. Some ASL code
  107. * contains dangling invalid references in packages and
  108. * expects that no exception will be issued. Leave the
  109. * element as a null element. It cannot be used, but it
  110. * can be overwritten by subsequent ASL code - this is
  111. * typically the case.
  112. */
  113. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  114. "Ignoring unresolved reference in package [%4.4s]\n",
  115. WalkState->ScopeInfo->Scope.Node->Name.Ascii));
  116. return_ACPI_STATUS (AE_OK);
  117. }
  118. else
  119. {
  120. ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
  121. }
  122. return_ACPI_STATUS (Status);
  123. }
  124. }
  125. /* Special object resolution for elements of a package */
  126. if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  127. (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
  128. {
  129. /*
  130. * Attempt to resolve the node to a value before we insert it into
  131. * the package. If this is a reference to a common data type,
  132. * resolve it immediately. According to the ACPI spec, package
  133. * elements can only be "data objects" or method references.
  134. * Attempt to resolve to an Integer, Buffer, String or Package.
  135. * If cannot, return the named reference (for things like Devices,
  136. * Methods, etc.) Buffer Fields and Fields will resolve to simple
  137. * objects (int/buf/str/pkg).
  138. *
  139. * NOTE: References to things like Devices, Methods, Mutexes, etc.
  140. * will remain as named references. This behavior is not described
  141. * in the ACPI spec, but it appears to be an oversight.
  142. */
  143. ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
  144. Status = AcpiExResolveNodeToValue (
  145. ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
  146. WalkState);
  147. if (ACPI_FAILURE (Status))
  148. {
  149. return_ACPI_STATUS (Status);
  150. }
  151. /*
  152. * Special handling for Alias objects. We need to setup the type
  153. * and the Op->Common.Node to point to the Alias target. Note,
  154. * Alias has at most one level of indirection internally.
  155. */
  156. Type = Op->Common.Node->Type;
  157. if (Type == ACPI_TYPE_LOCAL_ALIAS)
  158. {
  159. Type = ObjDesc->Common.Type;
  160. Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
  161. Op->Common.Node->Object);
  162. }
  163. switch (Type)
  164. {
  165. /*
  166. * For these types, we need the actual node, not the subobject.
  167. * However, the subobject did not get an extra reference count above.
  168. *
  169. * TBD: should ExResolveNodeToValue be changed to fix this?
  170. */
  171. case ACPI_TYPE_DEVICE:
  172. case ACPI_TYPE_THERMAL:
  173. AcpiUtAddReference (Op->Common.Node->Object);
  174. /*lint -fallthrough */
  175. /*
  176. * For these types, we need the actual node, not the subobject.
  177. * The subobject got an extra reference count in ExResolveNodeToValue.
  178. */
  179. case ACPI_TYPE_MUTEX:
  180. case ACPI_TYPE_METHOD:
  181. case ACPI_TYPE_POWER:
  182. case ACPI_TYPE_PROCESSOR:
  183. case ACPI_TYPE_EVENT:
  184. case ACPI_TYPE_REGION:
  185. /* We will create a reference object for these types below */
  186. break;
  187. default:
  188. /*
  189. * All other types - the node was resolved to an actual
  190. * object, we are done.
  191. */
  192. goto Exit;
  193. }
  194. }
  195. }
  196. /* Create and init a new internal ACPI object */
  197. ObjDesc = AcpiUtCreateInternalObject (
  198. (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
  199. if (!ObjDesc)
  200. {
  201. return_ACPI_STATUS (AE_NO_MEMORY);
  202. }
  203. Status = AcpiDsInitObjectFromOp (
  204. WalkState, Op, Op->Common.AmlOpcode, &ObjDesc);
  205. if (ACPI_FAILURE (Status))
  206. {
  207. AcpiUtRemoveReference (ObjDesc);
  208. return_ACPI_STATUS (Status);
  209. }
  210. Exit:
  211. *ObjDescPtr = ObjDesc;
  212. return_ACPI_STATUS (Status);
  213. }
  214. /*******************************************************************************
  215. *
  216. * FUNCTION: AcpiDsBuildInternalBufferObj
  217. *
  218. * PARAMETERS: WalkState - Current walk state
  219. * Op - Parser object to be translated
  220. * BufferLength - Length of the buffer
  221. * ObjDescPtr - Where the ACPI internal object is returned
  222. *
  223. * RETURN: Status
  224. *
  225. * DESCRIPTION: Translate a parser Op package object to the equivalent
  226. * namespace object
  227. *
  228. ******************************************************************************/
  229. ACPI_STATUS
  230. AcpiDsBuildInternalBufferObj (
  231. ACPI_WALK_STATE *WalkState,
  232. ACPI_PARSE_OBJECT *Op,
  233. UINT32 BufferLength,
  234. ACPI_OPERAND_OBJECT **ObjDescPtr)
  235. {
  236. ACPI_PARSE_OBJECT *Arg;
  237. ACPI_OPERAND_OBJECT *ObjDesc;
  238. ACPI_PARSE_OBJECT *ByteList;
  239. UINT32 ByteListLength = 0;
  240. ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
  241. /*
  242. * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
  243. * The buffer object already exists (from the NS node), otherwise it must
  244. * be created.
  245. */
  246. ObjDesc = *ObjDescPtr;
  247. if (!ObjDesc)
  248. {
  249. /* Create a new buffer object */
  250. ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
  251. *ObjDescPtr = ObjDesc;
  252. if (!ObjDesc)
  253. {
  254. return_ACPI_STATUS (AE_NO_MEMORY);
  255. }
  256. }
  257. /*
  258. * Second arg is the buffer data (optional) ByteList can be either
  259. * individual bytes or a string initializer. In either case, a
  260. * ByteList appears in the AML.
  261. */
  262. Arg = Op->Common.Value.Arg; /* skip first arg */
  263. ByteList = Arg->Named.Next;
  264. if (ByteList)
  265. {
  266. if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
  267. {
  268. ACPI_ERROR ((AE_INFO,
  269. "Expecting bytelist, found AML opcode 0x%X in op %p",
  270. ByteList->Common.AmlOpcode, ByteList));
  271. AcpiUtRemoveReference (ObjDesc);
  272. return (AE_TYPE);
  273. }
  274. ByteListLength = (UINT32) ByteList->Common.Value.Integer;
  275. }
  276. /*
  277. * The buffer length (number of bytes) will be the larger of:
  278. * 1) The specified buffer length and
  279. * 2) The length of the initializer byte list
  280. */
  281. ObjDesc->Buffer.Length = BufferLength;
  282. if (ByteListLength > BufferLength)
  283. {
  284. ObjDesc->Buffer.Length = ByteListLength;
  285. }
  286. /* Allocate the buffer */
  287. if (ObjDesc->Buffer.Length == 0)
  288. {
  289. ObjDesc->Buffer.Pointer = NULL;
  290. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  291. "Buffer defined with zero length in AML, creating\n"));
  292. }
  293. else
  294. {
  295. ObjDesc->Buffer.Pointer =
  296. ACPI_ALLOCATE_ZEROED (ObjDesc->Buffer.Length);
  297. if (!ObjDesc->Buffer.Pointer)
  298. {
  299. AcpiUtDeleteObjectDesc (ObjDesc);
  300. return_ACPI_STATUS (AE_NO_MEMORY);
  301. }
  302. /* Initialize buffer from the ByteList (if present) */
  303. if (ByteList)
  304. {
  305. memcpy (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
  306. ByteListLength);
  307. }
  308. }
  309. ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
  310. Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
  311. return_ACPI_STATUS (AE_OK);
  312. }
  313. /*******************************************************************************
  314. *
  315. * FUNCTION: AcpiDsBuildInternalPackageObj
  316. *
  317. * PARAMETERS: WalkState - Current walk state
  318. * Op - Parser object to be translated
  319. * ElementCount - Number of elements in the package - this is
  320. * the NumElements argument to Package()
  321. * ObjDescPtr - Where the ACPI internal object is returned
  322. *
  323. * RETURN: Status
  324. *
  325. * DESCRIPTION: Translate a parser Op package object to the equivalent
  326. * namespace object
  327. *
  328. * NOTE: The number of elements in the package will be always be the NumElements
  329. * count, regardless of the number of elements in the package list. If
  330. * NumElements is smaller, only that many package list elements are used.
  331. * if NumElements is larger, the Package object is padded out with
  332. * objects of type Uninitialized (as per ACPI spec.)
  333. *
  334. * Even though the ASL compilers do not allow NumElements to be smaller
  335. * than the Package list length (for the fixed length package opcode), some
  336. * BIOS code modifies the AML on the fly to adjust the NumElements, and
  337. * this code compensates for that. This also provides compatibility with
  338. * other AML interpreters.
  339. *
  340. ******************************************************************************/
  341. ACPI_STATUS
  342. AcpiDsBuildInternalPackageObj (
  343. ACPI_WALK_STATE *WalkState,
  344. ACPI_PARSE_OBJECT *Op,
  345. UINT32 ElementCount,
  346. ACPI_OPERAND_OBJECT **ObjDescPtr)
  347. {
  348. ACPI_PARSE_OBJECT *Arg;
  349. ACPI_PARSE_OBJECT *Parent;
  350. ACPI_OPERAND_OBJECT *ObjDesc = NULL;
  351. ACPI_STATUS Status = AE_OK;
  352. UINT32 i;
  353. UINT16 Index;
  354. UINT16 ReferenceCount;
  355. ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
  356. /* Find the parent of a possibly nested package */
  357. Parent = Op->Common.Parent;
  358. while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  359. (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
  360. {
  361. Parent = Parent->Common.Parent;
  362. }
  363. /*
  364. * If we are evaluating a Named package object "Name (xxxx, Package)",
  365. * the package object already exists, otherwise it must be created.
  366. */
  367. ObjDesc = *ObjDescPtr;
  368. if (!ObjDesc)
  369. {
  370. ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
  371. *ObjDescPtr = ObjDesc;
  372. if (!ObjDesc)
  373. {
  374. return_ACPI_STATUS (AE_NO_MEMORY);
  375. }
  376. ObjDesc->Package.Node = Parent->Common.Node;
  377. }
  378. /*
  379. * Allocate the element array (array of pointers to the individual
  380. * objects) based on the NumElements parameter. Add an extra pointer slot
  381. * so that the list is always null terminated.
  382. */
  383. ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
  384. ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
  385. if (!ObjDesc->Package.Elements)
  386. {
  387. AcpiUtDeleteObjectDesc (ObjDesc);
  388. return_ACPI_STATUS (AE_NO_MEMORY);
  389. }
  390. ObjDesc->Package.Count = ElementCount;
  391. /*
  392. * Initialize the elements of the package, up to the NumElements count.
  393. * Package is automatically padded with uninitialized (NULL) elements
  394. * if NumElements is greater than the package list length. Likewise,
  395. * Package is truncated if NumElements is less than the list length.
  396. */
  397. Arg = Op->Common.Value.Arg;
  398. Arg = Arg->Common.Next;
  399. for (i = 0; Arg && (i < ElementCount); i++)
  400. {
  401. if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
  402. {
  403. if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
  404. {
  405. /*
  406. * A method reference "looks" to the parser to be a method
  407. * invocation, so we special case it here
  408. */
  409. Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
  410. Status = AcpiDsBuildInternalObject (
  411. WalkState, Arg, &ObjDesc->Package.Elements[i]);
  412. }
  413. else
  414. {
  415. /* This package element is already built, just get it */
  416. ObjDesc->Package.Elements[i] =
  417. ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
  418. }
  419. }
  420. else
  421. {
  422. Status = AcpiDsBuildInternalObject (
  423. WalkState, Arg, &ObjDesc->Package.Elements[i]);
  424. }
  425. if (*ObjDescPtr)
  426. {
  427. /* Existing package, get existing reference count */
  428. ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
  429. if (ReferenceCount > 1)
  430. {
  431. /* Make new element ref count match original ref count */
  432. for (Index = 0; Index < (ReferenceCount - 1); Index++)
  433. {
  434. AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
  435. }
  436. }
  437. }
  438. Arg = Arg->Common.Next;
  439. }
  440. /* Check for match between NumElements and actual length of PackageList */
  441. if (Arg)
  442. {
  443. /*
  444. * NumElements was exhausted, but there are remaining elements in the
  445. * PackageList. Truncate the package to NumElements.
  446. *
  447. * Note: technically, this is an error, from ACPI spec: "It is an error
  448. * for NumElements to be less than the number of elements in the
  449. * PackageList". However, we just print a message and
  450. * no exception is returned. This provides Windows compatibility. Some
  451. * BIOSs will alter the NumElements on the fly, creating this type
  452. * of ill-formed package object.
  453. */
  454. while (Arg)
  455. {
  456. /*
  457. * We must delete any package elements that were created earlier
  458. * and are not going to be used because of the package truncation.
  459. */
  460. if (Arg->Common.Node)
  461. {
  462. AcpiUtRemoveReference (
  463. ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
  464. Arg->Common.Node = NULL;
  465. }
  466. /* Find out how many elements there really are */
  467. i++;
  468. Arg = Arg->Common.Next;
  469. }
  470. ACPI_INFO ((AE_INFO,
  471. "Actual Package length (%u) is larger than "
  472. "NumElements field (%u), truncated",
  473. i, ElementCount));
  474. }
  475. else if (i < ElementCount)
  476. {
  477. /*
  478. * Arg list (elements) was exhausted, but we did not reach NumElements count.
  479. * Note: this is not an error, the package is padded out with NULLs.
  480. */
  481. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  482. "Package List length (%u) smaller than NumElements "
  483. "count (%u), padded with null elements\n",
  484. i, ElementCount));
  485. }
  486. ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
  487. Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
  488. return_ACPI_STATUS (Status);
  489. }
  490. /*******************************************************************************
  491. *
  492. * FUNCTION: AcpiDsCreateNode
  493. *
  494. * PARAMETERS: WalkState - Current walk state
  495. * Node - NS Node to be initialized
  496. * Op - Parser object to be translated
  497. *
  498. * RETURN: Status
  499. *
  500. * DESCRIPTION: Create the object to be associated with a namespace node
  501. *
  502. ******************************************************************************/
  503. ACPI_STATUS
  504. AcpiDsCreateNode (
  505. ACPI_WALK_STATE *WalkState,
  506. ACPI_NAMESPACE_NODE *Node,
  507. ACPI_PARSE_OBJECT *Op)
  508. {
  509. ACPI_STATUS Status;
  510. ACPI_OPERAND_OBJECT *ObjDesc;
  511. ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
  512. /*
  513. * Because of the execution pass through the non-control-method
  514. * parts of the table, we can arrive here twice. Only init
  515. * the named object node the first time through
  516. */
  517. if (AcpiNsGetAttachedObject (Node))
  518. {
  519. return_ACPI_STATUS (AE_OK);
  520. }
  521. if (!Op->Common.Value.Arg)
  522. {
  523. /* No arguments, there is nothing to do */
  524. return_ACPI_STATUS (AE_OK);
  525. }
  526. /* Build an internal object for the argument(s) */
  527. Status = AcpiDsBuildInternalObject (
  528. WalkState, Op->Common.Value.Arg, &ObjDesc);
  529. if (ACPI_FAILURE (Status))
  530. {
  531. return_ACPI_STATUS (Status);
  532. }
  533. /* Re-type the object according to its argument */
  534. Node->Type = ObjDesc->Common.Type;
  535. /* Attach obj to node */
  536. Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
  537. /* Remove local reference to the object */
  538. AcpiUtRemoveReference (ObjDesc);
  539. return_ACPI_STATUS (Status);
  540. }
  541. #endif /* ACPI_NO_METHOD_EXECUTION */
  542. /*******************************************************************************
  543. *
  544. * FUNCTION: AcpiDsInitObjectFromOp
  545. *
  546. * PARAMETERS: WalkState - Current walk state
  547. * Op - Parser op used to init the internal object
  548. * Opcode - AML opcode associated with the object
  549. * RetObjDesc - Namespace object to be initialized
  550. *
  551. * RETURN: Status
  552. *
  553. * DESCRIPTION: Initialize a namespace object from a parser Op and its
  554. * associated arguments. The namespace object is a more compact
  555. * representation of the Op and its arguments.
  556. *
  557. ******************************************************************************/
  558. ACPI_STATUS
  559. AcpiDsInitObjectFromOp (
  560. ACPI_WALK_STATE *WalkState,
  561. ACPI_PARSE_OBJECT *Op,
  562. UINT16 Opcode,
  563. ACPI_OPERAND_OBJECT **RetObjDesc)
  564. {
  565. const ACPI_OPCODE_INFO *OpInfo;
  566. ACPI_OPERAND_OBJECT *ObjDesc;
  567. ACPI_STATUS Status = AE_OK;
  568. ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
  569. ObjDesc = *RetObjDesc;
  570. OpInfo = AcpiPsGetOpcodeInfo (Opcode);
  571. if (OpInfo->Class == AML_CLASS_UNKNOWN)
  572. {
  573. /* Unknown opcode */
  574. return_ACPI_STATUS (AE_TYPE);
  575. }
  576. /* Perform per-object initialization */
  577. switch (ObjDesc->Common.Type)
  578. {
  579. case ACPI_TYPE_BUFFER:
  580. /*
  581. * Defer evaluation of Buffer TermArg operand
  582. */
  583. ObjDesc->Buffer.Node = ACPI_CAST_PTR (
  584. ACPI_NAMESPACE_NODE, WalkState->Operands[0]);
  585. ObjDesc->Buffer.AmlStart = Op->Named.Data;
  586. ObjDesc->Buffer.AmlLength = Op->Named.Length;
  587. break;
  588. case ACPI_TYPE_PACKAGE:
  589. /*
  590. * Defer evaluation of Package TermArg operand
  591. */
  592. ObjDesc->Package.Node = ACPI_CAST_PTR (
  593. ACPI_NAMESPACE_NODE, WalkState->Operands[0]);
  594. ObjDesc->Package.AmlStart = Op->Named.Data;
  595. ObjDesc->Package.AmlLength = Op->Named.Length;
  596. break;
  597. case ACPI_TYPE_INTEGER:
  598. switch (OpInfo->Type)
  599. {
  600. case AML_TYPE_CONSTANT:
  601. /*
  602. * Resolve AML Constants here - AND ONLY HERE!
  603. * All constants are integers.
  604. * We mark the integer with a flag that indicates that it started
  605. * life as a constant -- so that stores to constants will perform
  606. * as expected (noop). ZeroOp is used as a placeholder for optional
  607. * target operands.
  608. */
  609. ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
  610. switch (Opcode)
  611. {
  612. case AML_ZERO_OP:
  613. ObjDesc->Integer.Value = 0;
  614. break;
  615. case AML_ONE_OP:
  616. ObjDesc->Integer.Value = 1;
  617. break;
  618. case AML_ONES_OP:
  619. ObjDesc->Integer.Value = ACPI_UINT64_MAX;
  620. /* Truncate value if we are executing from a 32-bit ACPI table */
  621. #ifndef ACPI_NO_METHOD_EXECUTION
  622. (void) AcpiExTruncateFor32bitTable (ObjDesc);
  623. #endif
  624. break;
  625. case AML_REVISION_OP:
  626. ObjDesc->Integer.Value = ACPI_CA_VERSION;
  627. break;
  628. default:
  629. ACPI_ERROR ((AE_INFO,
  630. "Unknown constant opcode 0x%X", Opcode));
  631. Status = AE_AML_OPERAND_TYPE;
  632. break;
  633. }
  634. break;
  635. case AML_TYPE_LITERAL:
  636. ObjDesc->Integer.Value = Op->Common.Value.Integer;
  637. #ifndef ACPI_NO_METHOD_EXECUTION
  638. if (AcpiExTruncateFor32bitTable (ObjDesc))
  639. {
  640. /* Warn if we found a 64-bit constant in a 32-bit table */
  641. ACPI_WARNING ((AE_INFO,
  642. "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
  643. ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),
  644. (UINT32) ObjDesc->Integer.Value));
  645. }
  646. #endif
  647. break;
  648. default:
  649. ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
  650. OpInfo->Type));
  651. Status = AE_AML_OPERAND_TYPE;
  652. break;
  653. }
  654. break;
  655. case ACPI_TYPE_STRING:
  656. ObjDesc->String.Pointer = Op->Common.Value.String;
  657. ObjDesc->String.Length = (UINT32) strlen (Op->Common.Value.String);
  658. /*
  659. * The string is contained in the ACPI table, don't ever try
  660. * to delete it
  661. */
  662. ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
  663. break;
  664. case ACPI_TYPE_METHOD:
  665. break;
  666. case ACPI_TYPE_LOCAL_REFERENCE:
  667. switch (OpInfo->Type)
  668. {
  669. case AML_TYPE_LOCAL_VARIABLE:
  670. /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
  671. ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
  672. ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
  673. #ifndef ACPI_NO_METHOD_EXECUTION
  674. Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
  675. ObjDesc->Reference.Value, WalkState,
  676. ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
  677. &ObjDesc->Reference.Object));
  678. #endif
  679. break;
  680. case AML_TYPE_METHOD_ARGUMENT:
  681. /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
  682. ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
  683. ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
  684. #ifndef ACPI_NO_METHOD_EXECUTION
  685. Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
  686. ObjDesc->Reference.Value, WalkState,
  687. ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
  688. &ObjDesc->Reference.Object));
  689. #endif
  690. break;
  691. default: /* Object name or Debug object */
  692. switch (Op->Common.AmlOpcode)
  693. {
  694. case AML_INT_NAMEPATH_OP:
  695. /* Node was saved in Op */
  696. ObjDesc->Reference.Node = Op->Common.Node;
  697. ObjDesc->Reference.Object = Op->Common.Node->Object;
  698. ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
  699. break;
  700. case AML_DEBUG_OP:
  701. ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
  702. break;
  703. default:
  704. ACPI_ERROR ((AE_INFO,
  705. "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
  706. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  707. }
  708. break;
  709. }
  710. break;
  711. default:
  712. ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
  713. ObjDesc->Common.Type));
  714. Status = AE_AML_OPERAND_TYPE;
  715. break;
  716. }
  717. return_ACPI_STATUS (Status);
  718. }