nsinit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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/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_LOCAL_BANK_FIELD:
  205. info->field_count++;
  206. break;
  207. case ACPI_TYPE_BUFFER:
  208. info->buffer_count++;
  209. break;
  210. case ACPI_TYPE_PACKAGE:
  211. info->package_count++;
  212. break;
  213. default:
  214. /* No init required, just exit now */
  215. return (AE_OK);
  216. }
  217. /*
  218. * If the object is already initialized, nothing else to do
  219. */
  220. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  221. return (AE_OK);
  222. }
  223. /*
  224. * Must lock the interpreter before executing AML code
  225. */
  226. acpi_ex_enter_interpreter();
  227. /*
  228. * Each of these types can contain executable AML code within the
  229. * declaration.
  230. */
  231. switch (type) {
  232. case ACPI_TYPE_REGION:
  233. info->op_region_init++;
  234. status = acpi_ds_get_region_arguments(obj_desc);
  235. break;
  236. case ACPI_TYPE_BUFFER_FIELD:
  237. info->field_init++;
  238. status = acpi_ds_get_buffer_field_arguments(obj_desc);
  239. break;
  240. case ACPI_TYPE_LOCAL_BANK_FIELD:
  241. info->field_init++;
  242. status = acpi_ds_get_bank_field_arguments(obj_desc);
  243. break;
  244. case ACPI_TYPE_BUFFER:
  245. info->buffer_init++;
  246. status = acpi_ds_get_buffer_arguments(obj_desc);
  247. break;
  248. case ACPI_TYPE_PACKAGE:
  249. info->package_init++;
  250. status = acpi_ds_get_package_arguments(obj_desc);
  251. break;
  252. default:
  253. /* No other types can get here */
  254. break;
  255. }
  256. if (ACPI_FAILURE(status)) {
  257. ACPI_EXCEPTION((AE_INFO, status,
  258. "Could not execute arguments for [%4.4s] (%s)",
  259. acpi_ut_get_node_name(node),
  260. acpi_ut_get_type_name(type)));
  261. }
  262. /*
  263. * Print a dot for each object unless we are going to print the entire
  264. * pathname
  265. */
  266. if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
  267. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  268. }
  269. /*
  270. * We ignore errors from above, and always return OK, since we don't want
  271. * to abort the walk on any single error.
  272. */
  273. acpi_ex_exit_interpreter();
  274. return (AE_OK);
  275. }
  276. /*******************************************************************************
  277. *
  278. * FUNCTION: acpi_ns_find_ini_methods
  279. *
  280. * PARAMETERS: acpi_walk_callback
  281. *
  282. * RETURN: acpi_status
  283. *
  284. * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
  285. * device/processor/thermal objects, and marks the entire subtree
  286. * with a SUBTREE_HAS_INI flag. This flag is used during the
  287. * subsequent device initialization walk to avoid entire subtrees
  288. * that do not contain an _INI.
  289. *
  290. ******************************************************************************/
  291. static acpi_status
  292. acpi_ns_find_ini_methods(acpi_handle obj_handle,
  293. u32 nesting_level, void *context, void **return_value)
  294. {
  295. struct acpi_device_walk_info *info =
  296. ACPI_CAST_PTR(struct acpi_device_walk_info, context);
  297. struct acpi_namespace_node *node;
  298. struct acpi_namespace_node *parent_node;
  299. /* Keep count of device/processor/thermal objects */
  300. node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  301. if ((node->type == ACPI_TYPE_DEVICE) ||
  302. (node->type == ACPI_TYPE_PROCESSOR) ||
  303. (node->type == ACPI_TYPE_THERMAL)) {
  304. info->device_count++;
  305. return (AE_OK);
  306. }
  307. /* We are only looking for methods named _INI */
  308. if (!ACPI_COMPARE_NAME(node->name.ascii, METHOD_NAME__INI)) {
  309. return (AE_OK);
  310. }
  311. /*
  312. * The only _INI methods that we care about are those that are
  313. * present under Device, Processor, and Thermal objects.
  314. */
  315. parent_node = acpi_ns_get_parent_node(node);
  316. switch (parent_node->type) {
  317. case ACPI_TYPE_DEVICE:
  318. case ACPI_TYPE_PROCESSOR:
  319. case ACPI_TYPE_THERMAL:
  320. /* Mark parent and bubble up the INI present flag to the root */
  321. while (parent_node) {
  322. parent_node->flags |= ANOBJ_SUBTREE_HAS_INI;
  323. parent_node = acpi_ns_get_parent_node(parent_node);
  324. }
  325. break;
  326. default:
  327. break;
  328. }
  329. return (AE_OK);
  330. }
  331. /*******************************************************************************
  332. *
  333. * FUNCTION: acpi_ns_init_one_device
  334. *
  335. * PARAMETERS: acpi_walk_callback
  336. *
  337. * RETURN: acpi_status
  338. *
  339. * DESCRIPTION: This is called once per device soon after ACPI is enabled
  340. * to initialize each device. It determines if the device is
  341. * present, and if so, calls _INI.
  342. *
  343. ******************************************************************************/
  344. static acpi_status
  345. acpi_ns_init_one_device(acpi_handle obj_handle,
  346. u32 nesting_level, void *context, void **return_value)
  347. {
  348. struct acpi_device_walk_info *walk_info =
  349. ACPI_CAST_PTR(struct acpi_device_walk_info, context);
  350. struct acpi_evaluate_info *info = walk_info->evaluate_info;
  351. u32 flags;
  352. acpi_status status;
  353. struct acpi_namespace_node *device_node;
  354. ACPI_FUNCTION_TRACE(ns_init_one_device);
  355. /* We are interested in Devices, Processors and thermal_zones only */
  356. device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  357. if ((device_node->type != ACPI_TYPE_DEVICE) &&
  358. (device_node->type != ACPI_TYPE_PROCESSOR) &&
  359. (device_node->type != ACPI_TYPE_THERMAL)) {
  360. return_ACPI_STATUS(AE_OK);
  361. }
  362. /*
  363. * Because of an earlier namespace analysis, all subtrees that contain an
  364. * _INI method are tagged.
  365. *
  366. * If this device subtree does not contain any _INI methods, we
  367. * can exit now and stop traversing this entire subtree.
  368. */
  369. if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) {
  370. return_ACPI_STATUS(AE_CTRL_DEPTH);
  371. }
  372. /*
  373. * Run _STA to determine if this device is present and functioning. We
  374. * must know this information for two important reasons (from ACPI spec):
  375. *
  376. * 1) We can only run _INI if the device is present.
  377. * 2) We must abort the device tree walk on this subtree if the device is
  378. * not present and is not functional (we will not examine the children)
  379. *
  380. * The _STA method is not required to be present under the device, we
  381. * assume the device is present if _STA does not exist.
  382. */
  383. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  384. (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA));
  385. status = acpi_ut_execute_STA(device_node, &flags);
  386. if (ACPI_FAILURE(status)) {
  387. /* Ignore error and move on to next device */
  388. return_ACPI_STATUS(AE_OK);
  389. }
  390. /*
  391. * Flags == -1 means that _STA was not found. In this case, we assume that
  392. * the device is both present and functional.
  393. *
  394. * From the ACPI spec, description of _STA:
  395. *
  396. * "If a device object (including the processor object) does not have an
  397. * _STA object, then OSPM assumes that all of the above bits are set (in
  398. * other words, the device is present, ..., and functioning)"
  399. */
  400. if (flags != ACPI_UINT32_MAX) {
  401. walk_info->num_STA++;
  402. }
  403. /*
  404. * Examine the PRESENT and FUNCTIONING status bits
  405. *
  406. * Note: ACPI spec does not seem to specify behavior for the present but
  407. * not functioning case, so we assume functioning if present.
  408. */
  409. if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
  410. /* Device is not present, we must examine the Functioning bit */
  411. if (flags & ACPI_STA_DEVICE_FUNCTIONING) {
  412. /*
  413. * Device is not present but is "functioning". In this case,
  414. * we will not run _INI, but we continue to examine the children
  415. * of this device.
  416. *
  417. * From the ACPI spec, description of _STA: (Note - no mention
  418. * of whether to run _INI or not on the device in question)
  419. *
  420. * "_STA may return bit 0 clear (not present) with bit 3 set
  421. * (device is functional). This case is used to indicate a valid
  422. * device for which no device driver should be loaded (for example,
  423. * a bridge device.) Children of this device may be present and
  424. * valid. OSPM should continue enumeration below a device whose
  425. * _STA returns this bit combination"
  426. */
  427. return_ACPI_STATUS(AE_OK);
  428. } else {
  429. /*
  430. * Device is not present and is not functioning. We must abort the
  431. * walk of this subtree immediately -- don't look at the children
  432. * of such a device.
  433. *
  434. * From the ACPI spec, description of _INI:
  435. *
  436. * "If the _STA method indicates that the device is not present,
  437. * OSPM will not run the _INI and will not examine the children
  438. * of the device for _INI methods"
  439. */
  440. return_ACPI_STATUS(AE_CTRL_DEPTH);
  441. }
  442. }
  443. /*
  444. * The device is present or is assumed present if no _STA exists.
  445. * Run the _INI if it exists (not required to exist)
  446. *
  447. * Note: We know there is an _INI within this subtree, but it may not be
  448. * under this particular device, it may be lower in the branch.
  449. */
  450. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  451. (ACPI_TYPE_METHOD, device_node, METHOD_NAME__INI));
  452. info->prefix_node = device_node;
  453. info->pathname = METHOD_NAME__INI;
  454. info->parameters = NULL;
  455. info->flags = ACPI_IGNORE_RETURN_VALUE;
  456. /*
  457. * Some hardware relies on this being executed as atomically
  458. * as possible (without an NMI being received in the middle of
  459. * this) - so disable NMIs and initialize the device:
  460. */
  461. acpi_nmi_disable();
  462. status = acpi_ns_evaluate(info);
  463. acpi_nmi_enable();
  464. if (ACPI_SUCCESS(status)) {
  465. walk_info->num_INI++;
  466. if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) &&
  467. (!(acpi_dbg_level & ACPI_LV_INFO))) {
  468. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
  469. }
  470. }
  471. #ifdef ACPI_DEBUG_OUTPUT
  472. else if (status != AE_NOT_FOUND) {
  473. /* Ignore error and move on to next device */
  474. char *scope_name =
  475. acpi_ns_get_external_pathname(info->resolved_node);
  476. ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution",
  477. scope_name));
  478. ACPI_FREE(scope_name);
  479. }
  480. #endif
  481. /* Ignore errors from above */
  482. status = AE_OK;
  483. /*
  484. * The _INI method has been run if present; call the Global Initialization
  485. * Handler for this device.
  486. */
  487. if (acpi_gbl_init_handler) {
  488. status =
  489. acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI);
  490. }
  491. return_ACPI_STATUS(status);
  492. }