nsinit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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 "accommon.h"
  44. #include "acnamesp.h"
  45. #include "acdispat.h"
  46. #include "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 "
  92. "Buffers %hd/%hd Packages (%hd nodes)\n",
  93. info.op_region_init, info.op_region_count,
  94. info.field_init, info.field_count,
  95. info.buffer_init, info.buffer_count,
  96. info.package_init, info.package_count,
  97. info.object_count));
  98. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  99. "%hd Control Methods found\n", info.method_count));
  100. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  101. "%hd Op Regions found\n", info.op_region_count));
  102. return_ACPI_STATUS(AE_OK);
  103. }
  104. /*******************************************************************************
  105. *
  106. * FUNCTION: acpi_ns_initialize_devices
  107. *
  108. * PARAMETERS: None
  109. *
  110. * RETURN: acpi_status
  111. *
  112. * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
  113. * This means running _INI on all present devices.
  114. *
  115. * Note: We install PCI config space handler on region access,
  116. * not here.
  117. *
  118. ******************************************************************************/
  119. acpi_status acpi_ns_initialize_devices(void)
  120. {
  121. acpi_status status;
  122. struct acpi_device_walk_info info;
  123. ACPI_FUNCTION_TRACE(ns_initialize_devices);
  124. /* Init counters */
  125. info.device_count = 0;
  126. info.num_STA = 0;
  127. info.num_INI = 0;
  128. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  129. "Initializing Device/Processor/Thermal objects "
  130. "by executing _INI methods:"));
  131. /* Tree analysis: find all subtrees that contain _INI methods */
  132. status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  133. ACPI_UINT32_MAX, FALSE,
  134. acpi_ns_find_ini_methods, &info, NULL);
  135. if (ACPI_FAILURE(status)) {
  136. goto error_exit;
  137. }
  138. /* Allocate the evaluation information block */
  139. info.evaluate_info =
  140. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  141. if (!info.evaluate_info) {
  142. status = AE_NO_MEMORY;
  143. goto error_exit;
  144. }
  145. /* Walk namespace to execute all _INIs on present devices */
  146. status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  147. ACPI_UINT32_MAX, FALSE,
  148. acpi_ns_init_one_device, &info, NULL);
  149. ACPI_FREE(info.evaluate_info);
  150. if (ACPI_FAILURE(status)) {
  151. goto error_exit;
  152. }
  153. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  154. "\nExecuted %hd _INI methods requiring %hd _STA executions "
  155. "(examined %hd objects)\n",
  156. info.num_INI, info.num_STA, info.device_count));
  157. return_ACPI_STATUS(status);
  158. error_exit:
  159. ACPI_EXCEPTION((AE_INFO, status, "During device initialization"));
  160. return_ACPI_STATUS(status);
  161. }
  162. /*******************************************************************************
  163. *
  164. * FUNCTION: acpi_ns_init_one_object
  165. *
  166. * PARAMETERS: obj_handle - Node
  167. * Level - Current nesting level
  168. * Context - Points to a init info struct
  169. * return_value - Not used
  170. *
  171. * RETURN: Status
  172. *
  173. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  174. * within the namespace.
  175. *
  176. * Currently, the only objects that require initialization are:
  177. * 1) Methods
  178. * 2) Op Regions
  179. *
  180. ******************************************************************************/
  181. static acpi_status
  182. acpi_ns_init_one_object(acpi_handle obj_handle,
  183. u32 level, void *context, void **return_value)
  184. {
  185. acpi_object_type type;
  186. acpi_status status = AE_OK;
  187. struct acpi_init_walk_info *info =
  188. (struct acpi_init_walk_info *)context;
  189. struct acpi_namespace_node *node =
  190. (struct acpi_namespace_node *)obj_handle;
  191. union acpi_operand_object *obj_desc;
  192. ACPI_FUNCTION_NAME(ns_init_one_object);
  193. info->object_count++;
  194. /* And even then, we are only interested in a few object types */
  195. type = acpi_ns_get_type(obj_handle);
  196. obj_desc = acpi_ns_get_attached_object(node);
  197. if (!obj_desc) {
  198. return (AE_OK);
  199. }
  200. /* Increment counters for object types we are looking for */
  201. switch (type) {
  202. case ACPI_TYPE_REGION:
  203. info->op_region_count++;
  204. break;
  205. case ACPI_TYPE_BUFFER_FIELD:
  206. info->field_count++;
  207. break;
  208. case ACPI_TYPE_LOCAL_BANK_FIELD:
  209. info->field_count++;
  210. break;
  211. case ACPI_TYPE_BUFFER:
  212. info->buffer_count++;
  213. break;
  214. case ACPI_TYPE_PACKAGE:
  215. info->package_count++;
  216. break;
  217. default:
  218. /* No init required, just exit now */
  219. return (AE_OK);
  220. }
  221. /* If the object is already initialized, nothing else to do */
  222. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  223. return (AE_OK);
  224. }
  225. /* Must lock the interpreter before executing AML code */
  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. }