1
1

exresnte.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /******************************************************************************
  2. *
  3. * Module Name: exresnte - AML Interpreter object resolution
  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 "acdispat.h"
  45. #include "acinterp.h"
  46. #include "acnamesp.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME ("exresnte")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: AcpiExResolveNodeToValue
  52. *
  53. * PARAMETERS: ObjectPtr - Pointer to a location that contains
  54. * a pointer to a NS node, and will receive a
  55. * pointer to the resolved object.
  56. * WalkState - Current state. Valid only if executing AML
  57. * code. NULL if simply resolving an object
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Resolve a Namespace node to a valued object
  62. *
  63. * Note: for some of the data types, the pointer attached to the Node
  64. * can be either a pointer to an actual internal object or a pointer into the
  65. * AML stream itself. These types are currently:
  66. *
  67. * ACPI_TYPE_INTEGER
  68. * ACPI_TYPE_STRING
  69. * ACPI_TYPE_BUFFER
  70. * ACPI_TYPE_MUTEX
  71. * ACPI_TYPE_PACKAGE
  72. *
  73. ******************************************************************************/
  74. ACPI_STATUS
  75. AcpiExResolveNodeToValue (
  76. ACPI_NAMESPACE_NODE **ObjectPtr,
  77. ACPI_WALK_STATE *WalkState)
  78. {
  79. ACPI_STATUS Status = AE_OK;
  80. ACPI_OPERAND_OBJECT *SourceDesc;
  81. ACPI_OPERAND_OBJECT *ObjDesc = NULL;
  82. ACPI_NAMESPACE_NODE *Node;
  83. ACPI_OBJECT_TYPE EntryType;
  84. ACPI_FUNCTION_TRACE (ExResolveNodeToValue);
  85. /*
  86. * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the
  87. * object that is attached to the Node.
  88. */
  89. Node = *ObjectPtr;
  90. SourceDesc = AcpiNsGetAttachedObject (Node);
  91. EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
  92. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
  93. Node, SourceDesc, AcpiUtGetTypeName (EntryType)));
  94. if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) ||
  95. (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS))
  96. {
  97. /* There is always exactly one level of indirection */
  98. Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
  99. SourceDesc = AcpiNsGetAttachedObject (Node);
  100. EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
  101. *ObjectPtr = Node;
  102. }
  103. /*
  104. * Several object types require no further processing:
  105. * 1) Device/Thermal objects don't have a "real" subobject, return Node
  106. * 2) Method locals and arguments have a pseudo-Node
  107. * 3) 10/2007: Added method type to assist with Package construction.
  108. */
  109. if ((EntryType == ACPI_TYPE_DEVICE) ||
  110. (EntryType == ACPI_TYPE_THERMAL) ||
  111. (EntryType == ACPI_TYPE_METHOD) ||
  112. (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL)))
  113. {
  114. return_ACPI_STATUS (AE_OK);
  115. }
  116. if (!SourceDesc)
  117. {
  118. ACPI_ERROR ((AE_INFO, "No object attached to node [%4.4s] %p",
  119. Node->Name.Ascii, Node));
  120. return_ACPI_STATUS (AE_AML_UNINITIALIZED_NODE);
  121. }
  122. /*
  123. * Action is based on the type of the Node, which indicates the type
  124. * of the attached object or pointer
  125. */
  126. switch (EntryType)
  127. {
  128. case ACPI_TYPE_PACKAGE:
  129. if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE)
  130. {
  131. ACPI_ERROR ((AE_INFO, "Object not a Package, type %s",
  132. AcpiUtGetObjectTypeName (SourceDesc)));
  133. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  134. }
  135. Status = AcpiDsGetPackageArguments (SourceDesc);
  136. if (ACPI_SUCCESS (Status))
  137. {
  138. /* Return an additional reference to the object */
  139. ObjDesc = SourceDesc;
  140. AcpiUtAddReference (ObjDesc);
  141. }
  142. break;
  143. case ACPI_TYPE_BUFFER:
  144. if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
  145. {
  146. ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s",
  147. AcpiUtGetObjectTypeName (SourceDesc)));
  148. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  149. }
  150. Status = AcpiDsGetBufferArguments (SourceDesc);
  151. if (ACPI_SUCCESS (Status))
  152. {
  153. /* Return an additional reference to the object */
  154. ObjDesc = SourceDesc;
  155. AcpiUtAddReference (ObjDesc);
  156. }
  157. break;
  158. case ACPI_TYPE_STRING:
  159. if (SourceDesc->Common.Type != ACPI_TYPE_STRING)
  160. {
  161. ACPI_ERROR ((AE_INFO, "Object not a String, type %s",
  162. AcpiUtGetObjectTypeName (SourceDesc)));
  163. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  164. }
  165. /* Return an additional reference to the object */
  166. ObjDesc = SourceDesc;
  167. AcpiUtAddReference (ObjDesc);
  168. break;
  169. case ACPI_TYPE_INTEGER:
  170. if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
  171. {
  172. ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s",
  173. AcpiUtGetObjectTypeName (SourceDesc)));
  174. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  175. }
  176. /* Return an additional reference to the object */
  177. ObjDesc = SourceDesc;
  178. AcpiUtAddReference (ObjDesc);
  179. break;
  180. case ACPI_TYPE_BUFFER_FIELD:
  181. case ACPI_TYPE_LOCAL_REGION_FIELD:
  182. case ACPI_TYPE_LOCAL_BANK_FIELD:
  183. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  184. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  185. "FieldRead Node=%p SourceDesc=%p Type=%X\n",
  186. Node, SourceDesc, EntryType));
  187. Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc);
  188. break;
  189. /* For these objects, just return the object attached to the Node */
  190. case ACPI_TYPE_MUTEX:
  191. case ACPI_TYPE_POWER:
  192. case ACPI_TYPE_PROCESSOR:
  193. case ACPI_TYPE_EVENT:
  194. case ACPI_TYPE_REGION:
  195. /* Return an additional reference to the object */
  196. ObjDesc = SourceDesc;
  197. AcpiUtAddReference (ObjDesc);
  198. break;
  199. /* TYPE_ANY is untyped, and thus there is no object associated with it */
  200. case ACPI_TYPE_ANY:
  201. ACPI_ERROR ((AE_INFO,
  202. "Untyped entry %p, no attached object!", Node));
  203. return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
  204. case ACPI_TYPE_LOCAL_REFERENCE:
  205. switch (SourceDesc->Reference.Class)
  206. {
  207. case ACPI_REFCLASS_TABLE: /* This is a DdbHandle */
  208. case ACPI_REFCLASS_REFOF:
  209. case ACPI_REFCLASS_INDEX:
  210. /* Return an additional reference to the object */
  211. ObjDesc = SourceDesc;
  212. AcpiUtAddReference (ObjDesc);
  213. break;
  214. default:
  215. /* No named references are allowed here */
  216. ACPI_ERROR ((AE_INFO,
  217. "Unsupported Reference type 0x%X",
  218. SourceDesc->Reference.Class));
  219. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  220. }
  221. break;
  222. default:
  223. /* Default case is for unknown types */
  224. ACPI_ERROR ((AE_INFO,
  225. "Node %p - Unknown object type 0x%X",
  226. Node, EntryType));
  227. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  228. } /* switch (EntryType) */
  229. /* Return the object descriptor */
  230. *ObjectPtr = (void *) ObjDesc;
  231. return_ACPI_STATUS (Status);
  232. }