nsinit.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /******************************************************************************
  2. *
  3. * Module Name: nsinit - namespace initialization
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acnamesp.h>
  44. #include <acpi/acdispat.h>
  45. #include <acpi/acinterp.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME ("nsinit")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_ns_initialize_objects
  51. *
  52. * PARAMETERS: None
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Walk the entire namespace and perform any necessary
  57. * initialization on the objects found therein
  58. *
  59. ******************************************************************************/
  60. acpi_status
  61. acpi_ns_initialize_objects (
  62. void)
  63. {
  64. acpi_status status;
  65. struct acpi_init_walk_info info;
  66. ACPI_FUNCTION_TRACE ("ns_initialize_objects");
  67. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  68. "**** Starting initialization of namespace objects ****\n"));
  69. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  70. "Completing Region/Field/Buffer/Package initialization:"));
  71. /* Set all init info to zero */
  72. ACPI_MEMSET (&info, 0, sizeof (struct acpi_init_walk_info));
  73. /* Walk entire namespace from the supplied root */
  74. status = acpi_walk_namespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  75. ACPI_UINT32_MAX, acpi_ns_init_one_object,
  76. &info, NULL);
  77. if (ACPI_FAILURE (status)) {
  78. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed! %s\n",
  79. acpi_format_exception (status)));
  80. }
  81. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  82. "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n",
  83. info.op_region_init, info.op_region_count,
  84. info.field_init, info.field_count,
  85. info.buffer_init, info.buffer_count,
  86. info.package_init, info.package_count, info.object_count));
  87. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  88. "%hd Control Methods found\n", info.method_count));
  89. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  90. "%hd Op Regions found\n", info.op_region_count));
  91. return_ACPI_STATUS (AE_OK);
  92. }
  93. /*******************************************************************************
  94. *
  95. * FUNCTION: acpi_ns_initialize_devices
  96. *
  97. * PARAMETERS: None
  98. *
  99. * RETURN: acpi_status
  100. *
  101. * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
  102. * This means running _INI on all present devices.
  103. *
  104. * Note: We install PCI config space handler on region access,
  105. * not here.
  106. *
  107. ******************************************************************************/
  108. acpi_status
  109. acpi_ns_initialize_devices (
  110. void)
  111. {
  112. acpi_status status;
  113. struct acpi_device_walk_info info;
  114. ACPI_FUNCTION_TRACE ("ns_initialize_devices");
  115. /* Init counters */
  116. info.device_count = 0;
  117. info.num_STA = 0;
  118. info.num_INI = 0;
  119. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  120. "Executing all Device _STA and_INI methods:"));
  121. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  122. if (ACPI_FAILURE (status)) {
  123. return_ACPI_STATUS (status);
  124. }
  125. /* Walk namespace for all objects */
  126. status = acpi_ns_walk_namespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  127. ACPI_UINT32_MAX, TRUE, acpi_ns_init_one_device, &info, NULL);
  128. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  129. if (ACPI_FAILURE (status)) {
  130. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed! %s\n",
  131. acpi_format_exception (status)));
  132. }
  133. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
  134. "\n%hd Devices found containing: %hd _STA, %hd _INI methods\n",
  135. info.device_count, info.num_STA, info.num_INI));
  136. return_ACPI_STATUS (status);
  137. }
  138. /*******************************************************************************
  139. *
  140. * FUNCTION: acpi_ns_init_one_object
  141. *
  142. * PARAMETERS: obj_handle - Node
  143. * Level - Current nesting level
  144. * Context - Points to a init info struct
  145. * return_value - Not used
  146. *
  147. * RETURN: Status
  148. *
  149. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  150. * within the namespace.
  151. *
  152. * Currently, the only objects that require initialization are:
  153. * 1) Methods
  154. * 2) Op Regions
  155. *
  156. ******************************************************************************/
  157. acpi_status
  158. acpi_ns_init_one_object (
  159. acpi_handle obj_handle,
  160. u32 level,
  161. void *context,
  162. void **return_value)
  163. {
  164. acpi_object_type type;
  165. acpi_status status;
  166. struct acpi_init_walk_info *info = (struct acpi_init_walk_info *) context;
  167. struct acpi_namespace_node *node = (struct acpi_namespace_node *) obj_handle;
  168. union acpi_operand_object *obj_desc;
  169. ACPI_FUNCTION_NAME ("ns_init_one_object");
  170. info->object_count++;
  171. /* And even then, we are only interested in a few object types */
  172. type = acpi_ns_get_type (obj_handle);
  173. obj_desc = acpi_ns_get_attached_object (node);
  174. if (!obj_desc) {
  175. return (AE_OK);
  176. }
  177. /* Increment counters for object types we are looking for */
  178. switch (type) {
  179. case ACPI_TYPE_REGION:
  180. info->op_region_count++;
  181. break;
  182. case ACPI_TYPE_BUFFER_FIELD:
  183. info->field_count++;
  184. break;
  185. case ACPI_TYPE_BUFFER:
  186. info->buffer_count++;
  187. break;
  188. case ACPI_TYPE_PACKAGE:
  189. info->package_count++;
  190. break;
  191. default:
  192. /* No init required, just exit now */
  193. return (AE_OK);
  194. }
  195. /*
  196. * If the object is already initialized, nothing else to do
  197. */
  198. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  199. return (AE_OK);
  200. }
  201. /*
  202. * Must lock the interpreter before executing AML code
  203. */
  204. status = acpi_ex_enter_interpreter ();
  205. if (ACPI_FAILURE (status)) {
  206. return (status);
  207. }
  208. /*
  209. * Each of these types can contain executable AML code within the
  210. * declaration.
  211. */
  212. switch (type) {
  213. case ACPI_TYPE_REGION:
  214. info->op_region_init++;
  215. status = acpi_ds_get_region_arguments (obj_desc);
  216. break;
  217. case ACPI_TYPE_BUFFER_FIELD:
  218. info->field_init++;
  219. status = acpi_ds_get_buffer_field_arguments (obj_desc);
  220. break;
  221. case ACPI_TYPE_BUFFER:
  222. info->buffer_init++;
  223. status = acpi_ds_get_buffer_arguments (obj_desc);
  224. break;
  225. case ACPI_TYPE_PACKAGE:
  226. info->package_init++;
  227. status = acpi_ds_get_package_arguments (obj_desc);
  228. break;
  229. default:
  230. /* No other types can get here */
  231. break;
  232. }
  233. if (ACPI_FAILURE (status)) {
  234. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ERROR, "\n"));
  235. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  236. "Could not execute arguments for [%4.4s] (%s), %s\n",
  237. acpi_ut_get_node_name (node), acpi_ut_get_type_name (type),
  238. acpi_format_exception (status)));
  239. }
  240. /*
  241. * Print a dot for each object unless we are going to print the entire
  242. * pathname
  243. */
  244. if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
  245. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
  246. }
  247. /*
  248. * We ignore errors from above, and always return OK, since we don't want
  249. * to abort the walk on any single error.
  250. */
  251. acpi_ex_exit_interpreter ();
  252. return (AE_OK);
  253. }
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: acpi_ns_init_one_device
  257. *
  258. * PARAMETERS: acpi_walk_callback
  259. *
  260. * RETURN: acpi_status
  261. *
  262. * DESCRIPTION: This is called once per device soon after ACPI is enabled
  263. * to initialize each device. It determines if the device is
  264. * present, and if so, calls _INI.
  265. *
  266. ******************************************************************************/
  267. acpi_status
  268. acpi_ns_init_one_device (
  269. acpi_handle obj_handle,
  270. u32 nesting_level,
  271. void *context,
  272. void **return_value)
  273. {
  274. struct acpi_device_walk_info *info = (struct acpi_device_walk_info *) context;
  275. struct acpi_parameter_info pinfo;
  276. u32 flags;
  277. acpi_status status;
  278. ACPI_FUNCTION_TRACE ("ns_init_one_device");
  279. pinfo.parameters = NULL;
  280. pinfo.parameter_type = ACPI_PARAM_ARGS;
  281. pinfo.node = acpi_ns_map_handle_to_node (obj_handle);
  282. if (!pinfo.node) {
  283. return_ACPI_STATUS (AE_BAD_PARAMETER);
  284. }
  285. /*
  286. * We will run _STA/_INI on Devices, Processors and thermal_zones only
  287. */
  288. if ((pinfo.node->type != ACPI_TYPE_DEVICE) &&
  289. (pinfo.node->type != ACPI_TYPE_PROCESSOR) &&
  290. (pinfo.node->type != ACPI_TYPE_THERMAL)) {
  291. return_ACPI_STATUS (AE_OK);
  292. }
  293. if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) &&
  294. (!(acpi_dbg_level & ACPI_LV_INFO))) {
  295. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
  296. }
  297. info->device_count++;
  298. /*
  299. * Run _STA to determine if we can run _INI on the device.
  300. */
  301. ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_STA"));
  302. status = acpi_ut_execute_STA (pinfo.node, &flags);
  303. if (ACPI_FAILURE (status)) {
  304. if (pinfo.node->type == ACPI_TYPE_DEVICE) {
  305. /* Ignore error and move on to next device */
  306. return_ACPI_STATUS (AE_OK);
  307. }
  308. /* _STA is not required for Processor or thermal_zone objects */
  309. }
  310. else {
  311. info->num_STA++;
  312. if (!(flags & 0x01)) {
  313. /* Don't look at children of a not present device */
  314. return_ACPI_STATUS(AE_CTRL_DEPTH);
  315. }
  316. }
  317. /*
  318. * The device is present. Run _INI.
  319. */
  320. ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_INI"));
  321. status = acpi_ns_evaluate_relative ("_INI", &pinfo);
  322. if (ACPI_FAILURE (status)) {
  323. /* No _INI (AE_NOT_FOUND) means device requires no initialization */
  324. if (status != AE_NOT_FOUND) {
  325. /* Ignore error and move on to next device */
  326. #ifdef ACPI_DEBUG_OUTPUT
  327. char *scope_name = acpi_ns_get_external_pathname (pinfo.node);
  328. ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "%s._INI failed: %s\n",
  329. scope_name, acpi_format_exception (status)));
  330. ACPI_MEM_FREE (scope_name);
  331. #endif
  332. }
  333. status = AE_OK;
  334. }
  335. else {
  336. /* Delete any return object (especially if implicit_return is enabled) */
  337. if (pinfo.return_object) {
  338. acpi_ut_remove_reference (pinfo.return_object);
  339. }
  340. /* Count of successful INIs */
  341. info->num_INI++;
  342. }
  343. if (acpi_gbl_init_handler) {
  344. /* External initialization handler is present, call it */
  345. status = acpi_gbl_init_handler (pinfo.node, ACPI_INIT_DEVICE_INI);
  346. }
  347. return_ACPI_STATUS (status);
  348. }