dsinit.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /******************************************************************************
  2. *
  3. * Module Name: dsinit - Object initialization namespace walk
  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 "acdispat.h"
  45. #include "acnamesp.h"
  46. #include "actables.h"
  47. #define _COMPONENT ACPI_DISPATCHER
  48. ACPI_MODULE_NAME ("dsinit")
  49. /* Local prototypes */
  50. static ACPI_STATUS
  51. AcpiDsInitOneObject (
  52. ACPI_HANDLE ObjHandle,
  53. UINT32 Level,
  54. void *Context,
  55. void **ReturnValue);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: AcpiDsInitOneObject
  59. *
  60. * PARAMETERS: ObjHandle - Node for the object
  61. * Level - Current nesting level
  62. * Context - Points to a init info struct
  63. * ReturnValue - Not used
  64. *
  65. * RETURN: Status
  66. *
  67. * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
  68. * within the namespace.
  69. *
  70. * Currently, the only objects that require initialization are:
  71. * 1) Methods
  72. * 2) Operation Regions
  73. *
  74. ******************************************************************************/
  75. static ACPI_STATUS
  76. AcpiDsInitOneObject (
  77. ACPI_HANDLE ObjHandle,
  78. UINT32 Level,
  79. void *Context,
  80. void **ReturnValue)
  81. {
  82. ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
  83. ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
  84. ACPI_STATUS Status;
  85. ACPI_OPERAND_OBJECT *ObjDesc;
  86. ACPI_FUNCTION_ENTRY ();
  87. /*
  88. * We are only interested in NS nodes owned by the table that
  89. * was just loaded
  90. */
  91. if (Node->OwnerId != Info->OwnerId)
  92. {
  93. return (AE_OK);
  94. }
  95. Info->ObjectCount++;
  96. /* And even then, we are only interested in a few object types */
  97. switch (AcpiNsGetType (ObjHandle))
  98. {
  99. case ACPI_TYPE_REGION:
  100. Status = AcpiDsInitializeRegion (ObjHandle);
  101. if (ACPI_FAILURE (Status))
  102. {
  103. ACPI_EXCEPTION ((AE_INFO, Status,
  104. "During Region initialization %p [%4.4s]",
  105. ObjHandle, AcpiUtGetNodeName (ObjHandle)));
  106. }
  107. Info->OpRegionCount++;
  108. break;
  109. case ACPI_TYPE_METHOD:
  110. /*
  111. * Auto-serialization support. We will examine each method that is
  112. * NotSerialized to determine if it creates any Named objects. If
  113. * it does, it will be marked serialized to prevent problems if
  114. * the method is entered by two or more threads and an attempt is
  115. * made to create the same named object twice -- which results in
  116. * an AE_ALREADY_EXISTS exception and method abort.
  117. */
  118. Info->MethodCount++;
  119. ObjDesc = AcpiNsGetAttachedObject (Node);
  120. if (!ObjDesc)
  121. {
  122. break;
  123. }
  124. /* Ignore if already serialized */
  125. if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
  126. {
  127. Info->SerialMethodCount++;
  128. break;
  129. }
  130. if (AcpiGbl_AutoSerializeMethods)
  131. {
  132. /* Parse/scan method and serialize it if necessary */
  133. AcpiDsAutoSerializeMethod (Node, ObjDesc);
  134. if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
  135. {
  136. /* Method was just converted to Serialized */
  137. Info->SerialMethodCount++;
  138. Info->SerializedMethodCount++;
  139. break;
  140. }
  141. }
  142. Info->NonSerialMethodCount++;
  143. break;
  144. case ACPI_TYPE_DEVICE:
  145. Info->DeviceCount++;
  146. break;
  147. default:
  148. break;
  149. }
  150. /*
  151. * We ignore errors from above, and always return OK, since
  152. * we don't want to abort the walk on a single error.
  153. */
  154. return (AE_OK);
  155. }
  156. /*******************************************************************************
  157. *
  158. * FUNCTION: AcpiDsInitializeObjects
  159. *
  160. * PARAMETERS: TableDesc - Descriptor for parent ACPI table
  161. * StartNode - Root of subtree to be initialized.
  162. *
  163. * RETURN: Status
  164. *
  165. * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
  166. * necessary initialization on the objects found therein
  167. *
  168. ******************************************************************************/
  169. ACPI_STATUS
  170. AcpiDsInitializeObjects (
  171. UINT32 TableIndex,
  172. ACPI_NAMESPACE_NODE *StartNode)
  173. {
  174. ACPI_STATUS Status;
  175. ACPI_INIT_WALK_INFO Info;
  176. ACPI_TABLE_HEADER *Table;
  177. ACPI_OWNER_ID OwnerId;
  178. ACPI_FUNCTION_TRACE (DsInitializeObjects);
  179. Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
  180. if (ACPI_FAILURE (Status))
  181. {
  182. return_ACPI_STATUS (Status);
  183. }
  184. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  185. "**** Starting initialization of namespace objects ****\n"));
  186. /* Set all init info to zero */
  187. memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
  188. Info.OwnerId = OwnerId;
  189. Info.TableIndex = TableIndex;
  190. /* Walk entire namespace from the supplied root */
  191. Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
  192. if (ACPI_FAILURE (Status))
  193. {
  194. return_ACPI_STATUS (Status);
  195. }
  196. /*
  197. * We don't use AcpiWalkNamespace since we do not want to acquire
  198. * the namespace reader lock.
  199. */
  200. Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
  201. ACPI_NS_WALK_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
  202. if (ACPI_FAILURE (Status))
  203. {
  204. ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
  205. }
  206. (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
  207. Status = AcpiGetTableByIndex (TableIndex, &Table);
  208. if (ACPI_FAILURE (Status))
  209. {
  210. return_ACPI_STATUS (Status);
  211. }
  212. /* DSDT is always the first AML table */
  213. if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
  214. {
  215. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  216. "\nInitializing Namespace objects:\n"));
  217. }
  218. /* Summary of objects initialized */
  219. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  220. "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
  221. "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
  222. Table->Signature, Table->OemTableId, OwnerId, Info.ObjectCount,
  223. Info.DeviceCount,Info.OpRegionCount, Info.MethodCount,
  224. Info.SerialMethodCount, Info.NonSerialMethodCount,
  225. Info.SerializedMethodCount));
  226. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
  227. Info.MethodCount, Info.OpRegionCount));
  228. return_ACPI_STATUS (AE_OK);
  229. }