nsinit.c 18 KB

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