nsinit.c 17 KB

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