nsinit.c 12 KB

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