nsinit.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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(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_DEBUG_PRINT((ACPI_DB_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_DEBUG_PRINT((ACPI_DB_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_DEBUG_PRINT_RAW((ACPI_DB_ERROR, "\n"));
  239. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  240. "Could not execute arguments for [%4.4s] (%s), %s\n",
  241. acpi_ut_get_node_name(node),
  242. acpi_ut_get_type_name(type),
  243. acpi_format_exception(status)));
  244. }
  245. /*
  246. * Print a dot for each object unless we are going to print the entire
  247. * pathname
  248. */
  249. if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
  250. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  251. }
  252. /*
  253. * We ignore errors from above, and always return OK, since we don't want
  254. * to abort the walk on any single error.
  255. */
  256. acpi_ex_exit_interpreter();
  257. return (AE_OK);
  258. }
  259. /*******************************************************************************
  260. *
  261. * FUNCTION: acpi_ns_init_one_device
  262. *
  263. * PARAMETERS: acpi_walk_callback
  264. *
  265. * RETURN: acpi_status
  266. *
  267. * DESCRIPTION: This is called once per device soon after ACPI is enabled
  268. * to initialize each device. It determines if the device is
  269. * present, and if so, calls _INI.
  270. *
  271. ******************************************************************************/
  272. static acpi_status
  273. acpi_ns_init_one_device(acpi_handle obj_handle,
  274. u32 nesting_level, void *context, void **return_value)
  275. {
  276. struct acpi_device_walk_info *info =
  277. (struct acpi_device_walk_info *)context;
  278. struct acpi_parameter_info pinfo;
  279. u32 flags;
  280. acpi_status status;
  281. ACPI_FUNCTION_TRACE("ns_init_one_device");
  282. pinfo.parameters = NULL;
  283. pinfo.parameter_type = ACPI_PARAM_ARGS;
  284. pinfo.node = acpi_ns_map_handle_to_node(obj_handle);
  285. if (!pinfo.node) {
  286. return_ACPI_STATUS(AE_BAD_PARAMETER);
  287. }
  288. /*
  289. * We will run _STA/_INI on Devices, Processors and thermal_zones only
  290. */
  291. if ((pinfo.node->type != ACPI_TYPE_DEVICE) &&
  292. (pinfo.node->type != ACPI_TYPE_PROCESSOR) &&
  293. (pinfo.node->type != ACPI_TYPE_THERMAL)) {
  294. return_ACPI_STATUS(AE_OK);
  295. }
  296. if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) &&
  297. (!(acpi_dbg_level & ACPI_LV_INFO))) {
  298. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  299. }
  300. info->device_count++;
  301. /*
  302. * Run _STA to determine if we can run _INI on the device.
  303. */
  304. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD,
  305. pinfo.node,
  306. METHOD_NAME__STA));
  307. status = acpi_ut_execute_STA(pinfo.node, &flags);
  308. if (ACPI_FAILURE(status)) {
  309. if (pinfo.node->type == ACPI_TYPE_DEVICE) {
  310. /* Ignore error and move on to next device */
  311. return_ACPI_STATUS(AE_OK);
  312. }
  313. /* _STA is not required for Processor or thermal_zone objects */
  314. } else {
  315. info->num_STA++;
  316. if (!(flags & 0x01)) {
  317. /* Don't look at children of a not present device */
  318. return_ACPI_STATUS(AE_CTRL_DEPTH);
  319. }
  320. }
  321. /*
  322. * The device is present. Run _INI.
  323. */
  324. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD,
  325. pinfo.node,
  326. METHOD_NAME__INI));
  327. status = acpi_ns_evaluate_relative(METHOD_NAME__INI, &pinfo);
  328. if (ACPI_FAILURE(status)) {
  329. /* No _INI (AE_NOT_FOUND) means device requires no initialization */
  330. if (status != AE_NOT_FOUND) {
  331. /* Ignore error and move on to next device */
  332. #ifdef ACPI_DEBUG_OUTPUT
  333. char *scope_name =
  334. acpi_ns_get_external_pathname(pinfo.node);
  335. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "%s._INI failed: %s\n",
  336. scope_name,
  337. acpi_format_exception(status)));
  338. ACPI_MEM_FREE(scope_name);
  339. #endif
  340. }
  341. status = AE_OK;
  342. } else {
  343. /* Delete any return object (especially if implicit_return is enabled) */
  344. if (pinfo.return_object) {
  345. acpi_ut_remove_reference(pinfo.return_object);
  346. }
  347. /* Count of successful INIs */
  348. info->num_INI++;
  349. }
  350. if (acpi_gbl_init_handler) {
  351. /* External initialization handler is present, call it */
  352. status =
  353. acpi_gbl_init_handler(pinfo.node, ACPI_INIT_DEVICE_INI);
  354. }
  355. return_ACPI_STATUS(status);
  356. }