nsinit.c 17 KB

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