nsinit.c 17 KB

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