nsinit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. static acpi_status
  56. acpi_ns_find_ini_methods(acpi_handle obj_handle,
  57. u32 nesting_level, void *context, void **return_value);
  58. /*******************************************************************************
  59. *
  60. * FUNCTION: acpi_ns_initialize_objects
  61. *
  62. * PARAMETERS: None
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Walk the entire namespace and perform any necessary
  67. * initialization on the objects found therein
  68. *
  69. ******************************************************************************/
  70. acpi_status acpi_ns_initialize_objects(void)
  71. {
  72. acpi_status status;
  73. struct acpi_init_walk_info info;
  74. ACPI_FUNCTION_TRACE(ns_initialize_objects);
  75. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  76. "**** Starting initialization of namespace objects ****\n"));
  77. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  78. "Completing Region/Field/Buffer/Package initialization:"));
  79. /* Set all init info to zero */
  80. ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info));
  81. /* Walk entire namespace from the supplied root */
  82. status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  83. ACPI_UINT32_MAX, acpi_ns_init_one_object,
  84. &info, NULL);
  85. if (ACPI_FAILURE(status)) {
  86. ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
  87. }
  88. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  89. "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n",
  90. info.op_region_init, info.op_region_count,
  91. info.field_init, info.field_count,
  92. info.buffer_init, info.buffer_count,
  93. info.package_init, info.package_count,
  94. info.object_count));
  95. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  96. "%hd Control Methods found\n", info.method_count));
  97. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  98. "%hd Op Regions found\n", info.op_region_count));
  99. return_ACPI_STATUS(AE_OK);
  100. }
  101. /*******************************************************************************
  102. *
  103. * FUNCTION: acpi_ns_initialize_devices
  104. *
  105. * PARAMETERS: None
  106. *
  107. * RETURN: acpi_status
  108. *
  109. * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
  110. * This means running _INI on all present devices.
  111. *
  112. * Note: We install PCI config space handler on region access,
  113. * not here.
  114. *
  115. ******************************************************************************/
  116. acpi_status acpi_ns_initialize_devices(void)
  117. {
  118. acpi_status status;
  119. struct acpi_device_walk_info info;
  120. ACPI_FUNCTION_TRACE(ns_initialize_devices);
  121. /* Init counters */
  122. info.device_count = 0;
  123. info.num_STA = 0;
  124. info.num_INI = 0;
  125. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  126. "Initializing Device/Processor/Thermal objects by executing _INI methods:"));
  127. /* Tree analysis: find all subtrees that contain _INI methods */
  128. status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  129. ACPI_UINT32_MAX, FALSE,
  130. acpi_ns_find_ini_methods, &info, NULL);
  131. if (ACPI_FAILURE(status)) {
  132. goto error_exit;
  133. }
  134. /* Allocate the evaluation information block */
  135. info.evaluate_info =
  136. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  137. if (!info.evaluate_info) {
  138. status = AE_NO_MEMORY;
  139. goto error_exit;
  140. }
  141. /* Walk namespace to execute all _INIs on present devices */
  142. status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  143. ACPI_UINT32_MAX, FALSE,
  144. acpi_ns_init_one_device, &info, NULL);
  145. ACPI_FREE(info.evaluate_info);
  146. if (ACPI_FAILURE(status)) {
  147. goto error_exit;
  148. }
  149. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  150. "\nExecuted %hd _INI methods requiring %hd _STA executions (examined %hd objects)\n",
  151. info.num_INI, info.num_STA, info.device_count));
  152. return_ACPI_STATUS(status);
  153. error_exit:
  154. ACPI_EXCEPTION((AE_INFO, status, "During device initialization"));
  155. return_ACPI_STATUS(status);
  156. }
  157. /*******************************************************************************
  158. *
  159. * FUNCTION: acpi_ns_init_one_object
  160. *
  161. * PARAMETERS: obj_handle - Node
  162. * Level - Current nesting level
  163. * Context - Points to a init info struct
  164. * return_value - Not used
  165. *
  166. * RETURN: Status
  167. *
  168. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  169. * within the namespace.
  170. *
  171. * Currently, the only objects that require initialization are:
  172. * 1) Methods
  173. * 2) Op Regions
  174. *
  175. ******************************************************************************/
  176. static acpi_status
  177. acpi_ns_init_one_object(acpi_handle obj_handle,
  178. u32 level, void *context, void **return_value)
  179. {
  180. acpi_object_type type;
  181. acpi_status status;
  182. struct acpi_init_walk_info *info =
  183. (struct acpi_init_walk_info *)context;
  184. struct acpi_namespace_node *node =
  185. (struct acpi_namespace_node *)obj_handle;
  186. union acpi_operand_object *obj_desc;
  187. ACPI_FUNCTION_NAME(ns_init_one_object);
  188. info->object_count++;
  189. /* And even then, we are only interested in a few object types */
  190. type = acpi_ns_get_type(obj_handle);
  191. obj_desc = acpi_ns_get_attached_object(node);
  192. if (!obj_desc) {
  193. return (AE_OK);
  194. }
  195. /* Increment counters for object types we are looking for */
  196. switch (type) {
  197. case ACPI_TYPE_REGION:
  198. info->op_region_count++;
  199. break;
  200. case ACPI_TYPE_BUFFER_FIELD:
  201. info->field_count++;
  202. break;
  203. case ACPI_TYPE_BUFFER:
  204. info->buffer_count++;
  205. break;
  206. case ACPI_TYPE_PACKAGE:
  207. info->package_count++;
  208. break;
  209. default:
  210. /* No init required, just exit now */
  211. return (AE_OK);
  212. }
  213. /*
  214. * If the object is already initialized, nothing else to do
  215. */
  216. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  217. return (AE_OK);
  218. }
  219. /*
  220. * Must lock the interpreter before executing AML code
  221. */
  222. status = acpi_ex_enter_interpreter();
  223. if (ACPI_FAILURE(status)) {
  224. return (status);
  225. }
  226. /*
  227. * Each of these types can contain executable AML code within the
  228. * declaration.
  229. */
  230. switch (type) {
  231. case ACPI_TYPE_REGION:
  232. info->op_region_init++;
  233. status = acpi_ds_get_region_arguments(obj_desc);
  234. break;
  235. case ACPI_TYPE_BUFFER_FIELD:
  236. info->field_init++;
  237. status = acpi_ds_get_buffer_field_arguments(obj_desc);
  238. break;
  239. case ACPI_TYPE_BUFFER:
  240. info->buffer_init++;
  241. status = acpi_ds_get_buffer_arguments(obj_desc);
  242. break;
  243. case ACPI_TYPE_PACKAGE:
  244. info->package_init++;
  245. status = acpi_ds_get_package_arguments(obj_desc);
  246. break;
  247. default:
  248. /* No other types can get here */
  249. break;
  250. }
  251. if (ACPI_FAILURE(status)) {
  252. ACPI_EXCEPTION((AE_INFO, status,
  253. "Could not execute arguments for [%4.4s] (%s)",
  254. acpi_ut_get_node_name(node),
  255. acpi_ut_get_type_name(type)));
  256. }
  257. /*
  258. * Print a dot for each object unless we are going to print the entire
  259. * pathname
  260. */
  261. if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
  262. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  263. }
  264. /*
  265. * We ignore errors from above, and always return OK, since we don't want
  266. * to abort the walk on any single error.
  267. */
  268. acpi_ex_exit_interpreter();
  269. return (AE_OK);
  270. }
  271. /*******************************************************************************
  272. *
  273. * FUNCTION: acpi_ns_find_ini_methods
  274. *
  275. * PARAMETERS: acpi_walk_callback
  276. *
  277. * RETURN: acpi_status
  278. *
  279. * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
  280. * device/processor/thermal objects, and marks the entire subtree
  281. * with a SUBTREE_HAS_INI flag. This flag is used during the
  282. * subsequent device initialization walk to avoid entire subtrees
  283. * that do not contain an _INI.
  284. *
  285. ******************************************************************************/
  286. static acpi_status
  287. acpi_ns_find_ini_methods(acpi_handle obj_handle,
  288. u32 nesting_level, void *context, void **return_value)
  289. {
  290. struct acpi_device_walk_info *info =
  291. ACPI_CAST_PTR(struct acpi_device_walk_info, context);
  292. struct acpi_namespace_node *node;
  293. struct acpi_namespace_node *parent_node;
  294. /* Keep count of device/processor/thermal objects */
  295. node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  296. if ((node->type == ACPI_TYPE_DEVICE) ||
  297. (node->type == ACPI_TYPE_PROCESSOR) ||
  298. (node->type == ACPI_TYPE_THERMAL)) {
  299. info->device_count++;
  300. return (AE_OK);
  301. }
  302. /* We are only looking for methods named _INI */
  303. if (!ACPI_COMPARE_NAME(node->name.ascii, METHOD_NAME__INI)) {
  304. return (AE_OK);
  305. }
  306. /*
  307. * The only _INI methods that we care about are those that are
  308. * present under Device, Processor, and Thermal objects.
  309. */
  310. parent_node = acpi_ns_get_parent_node(node);
  311. switch (parent_node->type) {
  312. case ACPI_TYPE_DEVICE:
  313. case ACPI_TYPE_PROCESSOR:
  314. case ACPI_TYPE_THERMAL:
  315. /* Mark parent and bubble up the INI present flag to the root */
  316. while (parent_node) {
  317. parent_node->flags |= ANOBJ_SUBTREE_HAS_INI;
  318. parent_node = acpi_ns_get_parent_node(parent_node);
  319. }
  320. break;
  321. default:
  322. break;
  323. }
  324. return (AE_OK);
  325. }
  326. /*******************************************************************************
  327. *
  328. * FUNCTION: acpi_ns_init_one_device
  329. *
  330. * PARAMETERS: acpi_walk_callback
  331. *
  332. * RETURN: acpi_status
  333. *
  334. * DESCRIPTION: This is called once per device soon after ACPI is enabled
  335. * to initialize each device. It determines if the device is
  336. * present, and if so, calls _INI.
  337. *
  338. ******************************************************************************/
  339. static acpi_status
  340. acpi_ns_init_one_device(acpi_handle obj_handle,
  341. u32 nesting_level, void *context, void **return_value)
  342. {
  343. struct acpi_device_walk_info *walk_info =
  344. ACPI_CAST_PTR(struct acpi_device_walk_info, context);
  345. struct acpi_evaluate_info *info = walk_info->evaluate_info;
  346. u32 flags;
  347. acpi_status status;
  348. struct acpi_namespace_node *device_node;
  349. ACPI_FUNCTION_TRACE(ns_init_one_device);
  350. /* We are interested in Devices, Processors and thermal_zones only */
  351. device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  352. if ((device_node->type != ACPI_TYPE_DEVICE) &&
  353. (device_node->type != ACPI_TYPE_PROCESSOR) &&
  354. (device_node->type != ACPI_TYPE_THERMAL)) {
  355. return_ACPI_STATUS(AE_OK);
  356. }
  357. /*
  358. * Because of an earlier namespace analysis, all subtrees that contain an
  359. * _INI method are tagged.
  360. *
  361. * If this device subtree does not contain any _INI methods, we
  362. * can exit now and stop traversing this entire subtree.
  363. */
  364. if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) {
  365. return_ACPI_STATUS(AE_CTRL_DEPTH);
  366. }
  367. /*
  368. * Run _STA to determine if this device is present and functioning. We
  369. * must know this information for two important reasons (from ACPI spec):
  370. *
  371. * 1) We can only run _INI if the device is present.
  372. * 2) We must abort the device tree walk on this subtree if the device is
  373. * not present and is not functional (we will not examine the children)
  374. *
  375. * The _STA method is not required to be present under the device, we
  376. * assume the device is present if _STA does not exist.
  377. */
  378. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  379. (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA));
  380. status = acpi_ut_execute_STA(device_node, &flags);
  381. if (ACPI_FAILURE(status)) {
  382. /* Ignore error and move on to next device */
  383. return_ACPI_STATUS(AE_OK);
  384. }
  385. /*
  386. * Flags == -1 means that _STA was not found. In this case, we assume that
  387. * the device is both present and functional.
  388. *
  389. * From the ACPI spec, description of _STA:
  390. *
  391. * "If a device object (including the processor object) does not have an
  392. * _STA object, then OSPM assumes that all of the above bits are set (in
  393. * other words, the device is present, ..., and functioning)"
  394. */
  395. if (flags != ACPI_UINT32_MAX) {
  396. walk_info->num_STA++;
  397. }
  398. /*
  399. * Examine the PRESENT and FUNCTIONING status bits
  400. *
  401. * Note: ACPI spec does not seem to specify behavior for the present but
  402. * not functioning case, so we assume functioning if present.
  403. */
  404. if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
  405. /* Device is not present, we must examine the Functioning bit */
  406. if (flags & ACPI_STA_DEVICE_FUNCTIONING) {
  407. /*
  408. * Device is not present but is "functioning". In this case,
  409. * we will not run _INI, but we continue to examine the children
  410. * of this device.
  411. *
  412. * From the ACPI spec, description of _STA: (Note - no mention
  413. * of whether to run _INI or not on the device in question)
  414. *
  415. * "_STA may return bit 0 clear (not present) with bit 3 set
  416. * (device is functional). This case is used to indicate a valid
  417. * device for which no device driver should be loaded (for example,
  418. * a bridge device.) Children of this device may be present and
  419. * valid. OSPM should continue enumeration below a device whose
  420. * _STA returns this bit combination"
  421. */
  422. return_ACPI_STATUS(AE_OK);
  423. } else {
  424. /*
  425. * Device is not present and is not functioning. We must abort the
  426. * walk of this subtree immediately -- don't look at the children
  427. * of such a device.
  428. *
  429. * From the ACPI spec, description of _INI:
  430. *
  431. * "If the _STA method indicates that the device is not present,
  432. * OSPM will not run the _INI and will not examine the children
  433. * of the device for _INI methods"
  434. */
  435. return_ACPI_STATUS(AE_CTRL_DEPTH);
  436. }
  437. }
  438. /*
  439. * The device is present or is assumed present if no _STA exists.
  440. * Run the _INI if it exists (not required to exist)
  441. *
  442. * Note: We know there is an _INI within this subtree, but it may not be
  443. * under this particular device, it may be lower in the branch.
  444. */
  445. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  446. (ACPI_TYPE_METHOD, device_node, METHOD_NAME__INI));
  447. info->prefix_node = device_node;
  448. info->pathname = METHOD_NAME__INI;
  449. info->parameters = NULL;
  450. info->parameter_type = ACPI_PARAM_ARGS;
  451. info->flags = ACPI_IGNORE_RETURN_VALUE;
  452. status = acpi_ns_evaluate(info);
  453. if (ACPI_SUCCESS(status)) {
  454. walk_info->num_INI++;
  455. if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) &&
  456. (!(acpi_dbg_level & ACPI_LV_INFO))) {
  457. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  458. }
  459. }
  460. #ifdef ACPI_DEBUG_OUTPUT
  461. else if (status != AE_NOT_FOUND) {
  462. /* Ignore error and move on to next device */
  463. char *scope_name =
  464. acpi_ns_get_external_pathname(info->resolved_node);
  465. ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution",
  466. scope_name));
  467. ACPI_FREE(scope_name);
  468. }
  469. #endif
  470. /* Ignore errors from above */
  471. status = AE_OK;
  472. /*
  473. * The _INI method has been run if present; call the Global Initialization
  474. * Handler for this device.
  475. */
  476. if (acpi_gbl_init_handler) {
  477. status =
  478. acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI);
  479. }
  480. return_ACPI_STATUS(status);
  481. }