nsinit.c 17 KB

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