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_REPORT_ERROR(("walk_namespace failed! %s\n",
  84. acpi_format_exception(status)));
  85. }
  86. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  87. "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n",
  88. info.op_region_init, info.op_region_count,
  89. info.field_init, info.field_count,
  90. info.buffer_init, info.buffer_count,
  91. info.package_init, info.package_count,
  92. info.object_count));
  93. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  94. "%hd Control Methods found\n", info.method_count));
  95. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  96. "%hd Op Regions found\n", info.op_region_count));
  97. return_ACPI_STATUS(AE_OK);
  98. }
  99. /*******************************************************************************
  100. *
  101. * FUNCTION: acpi_ns_initialize_devices
  102. *
  103. * PARAMETERS: None
  104. *
  105. * RETURN: acpi_status
  106. *
  107. * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
  108. * This means running _INI on all present devices.
  109. *
  110. * Note: We install PCI config space handler on region access,
  111. * not here.
  112. *
  113. ******************************************************************************/
  114. acpi_status acpi_ns_initialize_devices(void)
  115. {
  116. acpi_status status;
  117. struct acpi_device_walk_info info;
  118. ACPI_FUNCTION_TRACE("ns_initialize_devices");
  119. /* Init counters */
  120. info.device_count = 0;
  121. info.num_STA = 0;
  122. info.num_INI = 0;
  123. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  124. "Executing all Device _STA and_INI methods:"));
  125. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  126. if (ACPI_FAILURE(status)) {
  127. return_ACPI_STATUS(status);
  128. }
  129. /* Walk namespace for all objects */
  130. status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  131. ACPI_UINT32_MAX, TRUE,
  132. acpi_ns_init_one_device, &info, NULL);
  133. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  134. if (ACPI_FAILURE(status)) {
  135. ACPI_REPORT_ERROR(("walk_namespace failed! %s\n",
  136. acpi_format_exception(status)));
  137. }
  138. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  139. "\n%hd Devices found containing: %hd _STA, %hd _INI methods\n",
  140. info.device_count, info.num_STA, info.num_INI));
  141. return_ACPI_STATUS(status);
  142. }
  143. /*******************************************************************************
  144. *
  145. * FUNCTION: acpi_ns_init_one_object
  146. *
  147. * PARAMETERS: obj_handle - Node
  148. * Level - Current nesting level
  149. * Context - Points to a init info struct
  150. * return_value - Not used
  151. *
  152. * RETURN: Status
  153. *
  154. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  155. * within the namespace.
  156. *
  157. * Currently, the only objects that require initialization are:
  158. * 1) Methods
  159. * 2) Op Regions
  160. *
  161. ******************************************************************************/
  162. static acpi_status
  163. acpi_ns_init_one_object(acpi_handle obj_handle,
  164. u32 level, void *context, void **return_value)
  165. {
  166. acpi_object_type type;
  167. acpi_status status;
  168. struct acpi_init_walk_info *info =
  169. (struct acpi_init_walk_info *)context;
  170. struct acpi_namespace_node *node =
  171. (struct acpi_namespace_node *)obj_handle;
  172. union acpi_operand_object *obj_desc;
  173. ACPI_FUNCTION_NAME("ns_init_one_object");
  174. info->object_count++;
  175. /* And even then, we are only interested in a few object types */
  176. type = acpi_ns_get_type(obj_handle);
  177. obj_desc = acpi_ns_get_attached_object(node);
  178. if (!obj_desc) {
  179. return (AE_OK);
  180. }
  181. /* Increment counters for object types we are looking for */
  182. switch (type) {
  183. case ACPI_TYPE_REGION:
  184. info->op_region_count++;
  185. break;
  186. case ACPI_TYPE_BUFFER_FIELD:
  187. info->field_count++;
  188. break;
  189. case ACPI_TYPE_BUFFER:
  190. info->buffer_count++;
  191. break;
  192. case ACPI_TYPE_PACKAGE:
  193. info->package_count++;
  194. break;
  195. default:
  196. /* No init required, just exit now */
  197. return (AE_OK);
  198. }
  199. /*
  200. * If the object is already initialized, nothing else to do
  201. */
  202. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  203. return (AE_OK);
  204. }
  205. /*
  206. * Must lock the interpreter before executing AML code
  207. */
  208. status = acpi_ex_enter_interpreter();
  209. if (ACPI_FAILURE(status)) {
  210. return (status);
  211. }
  212. /*
  213. * Each of these types can contain executable AML code within the
  214. * declaration.
  215. */
  216. switch (type) {
  217. case ACPI_TYPE_REGION:
  218. info->op_region_init++;
  219. status = acpi_ds_get_region_arguments(obj_desc);
  220. break;
  221. case ACPI_TYPE_BUFFER_FIELD:
  222. info->field_init++;
  223. status = acpi_ds_get_buffer_field_arguments(obj_desc);
  224. break;
  225. case ACPI_TYPE_BUFFER:
  226. info->buffer_init++;
  227. status = acpi_ds_get_buffer_arguments(obj_desc);
  228. break;
  229. case ACPI_TYPE_PACKAGE:
  230. info->package_init++;
  231. status = acpi_ds_get_package_arguments(obj_desc);
  232. break;
  233. default:
  234. /* No other types can get here */
  235. break;
  236. }
  237. if (ACPI_FAILURE(status)) {
  238. ACPI_REPORT_ERROR(("\nCould not execute arguments for [%4.4s] (%s), %s\n", acpi_ut_get_node_name(node), acpi_ut_get_type_name(type), 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. static acpi_status
  268. acpi_ns_init_one_device(acpi_handle obj_handle,
  269. u32 nesting_level, void *context, void **return_value)
  270. {
  271. struct acpi_device_walk_info *info =
  272. (struct acpi_device_walk_info *)context;
  273. struct acpi_parameter_info pinfo;
  274. u32 flags;
  275. acpi_status status;
  276. struct acpi_namespace_node *ini_node;
  277. struct acpi_namespace_node *device_node;
  278. ACPI_FUNCTION_TRACE("ns_init_one_device");
  279. device_node = acpi_ns_map_handle_to_node(obj_handle);
  280. if (!device_node) {
  281. return_ACPI_STATUS(AE_BAD_PARAMETER);
  282. }
  283. /*
  284. * We will run _STA/_INI on Devices, Processors and thermal_zones only
  285. */
  286. if ((device_node->type != ACPI_TYPE_DEVICE) &&
  287. (device_node->type != ACPI_TYPE_PROCESSOR) &&
  288. (device_node->type != ACPI_TYPE_THERMAL)) {
  289. return_ACPI_STATUS(AE_OK);
  290. }
  291. if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) &&
  292. (!(acpi_dbg_level & ACPI_LV_INFO))) {
  293. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  294. }
  295. info->device_count++;
  296. /*
  297. * Check if the _INI method exists for this device -
  298. * if _INI does not exist, there is no need to run _STA
  299. * No _INI means device requires no initialization
  300. */
  301. status = acpi_ns_search_node(*ACPI_CAST_PTR(u32, METHOD_NAME__INI),
  302. device_node, ACPI_TYPE_METHOD, &ini_node);
  303. if (ACPI_FAILURE(status)) {
  304. /* No _INI method found - move on to next device */
  305. return_ACPI_STATUS(AE_OK);
  306. }
  307. /*
  308. * Run _STA to determine if we can run _INI on the device -
  309. * the device must be present before _INI can be run.
  310. * However, _STA is not required - assume device present if no _STA
  311. */
  312. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD,
  313. device_node,
  314. METHOD_NAME__STA));
  315. pinfo.node = device_node;
  316. pinfo.parameters = NULL;
  317. pinfo.parameter_type = ACPI_PARAM_ARGS;
  318. status = acpi_ut_execute_STA(pinfo.node, &flags);
  319. if (ACPI_FAILURE(status)) {
  320. /* Ignore error and move on to next device */
  321. return_ACPI_STATUS(AE_OK);
  322. }
  323. if (flags != ACPI_UINT32_MAX) {
  324. info->num_STA++;
  325. }
  326. if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
  327. /* Don't look at children of a not present device */
  328. return_ACPI_STATUS(AE_CTRL_DEPTH);
  329. }
  330. /*
  331. * The device is present and _INI exists. Run the _INI method.
  332. * (We already have the _INI node from above)
  333. */
  334. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD,
  335. pinfo.node,
  336. METHOD_NAME__INI));
  337. pinfo.node = ini_node;
  338. status = acpi_ns_evaluate_by_handle(&pinfo);
  339. if (ACPI_FAILURE(status)) {
  340. /* Ignore error and move on to next device */
  341. #ifdef ACPI_DEBUG_OUTPUT
  342. char *scope_name = acpi_ns_get_external_pathname(ini_node);
  343. ACPI_REPORT_WARNING(("%s._INI failed: %s\n",
  344. scope_name,
  345. 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. }