nsinit.c 12 KB

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