nsutils.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. /******************************************************************************
  2. *
  3. * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
  4. * parents and siblings and Scope manipulation
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2006, R. Byron Moore
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/amlcode.h>
  46. #include <acpi/actables.h>
  47. #define _COMPONENT ACPI_NAMESPACE
  48. ACPI_MODULE_NAME("nsutils")
  49. /* Local prototypes */
  50. static u8 acpi_ns_valid_path_separator(char sep);
  51. #ifdef ACPI_OBSOLETE_FUNCTIONS
  52. acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search);
  53. #endif
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_ns_report_error
  57. *
  58. * PARAMETERS: module_name - Caller's module name (for error output)
  59. * line_number - Caller's line number (for error output)
  60. * internal_name - Name or path of the namespace node
  61. * lookup_status - Exception code from NS lookup
  62. *
  63. * RETURN: None
  64. *
  65. * DESCRIPTION: Print warning message with full pathname
  66. *
  67. ******************************************************************************/
  68. void
  69. acpi_ns_report_error(char *module_name,
  70. u32 line_number,
  71. char *internal_name, acpi_status lookup_status)
  72. {
  73. acpi_status status;
  74. char *name = NULL;
  75. acpi_ut_report_error(module_name, line_number);
  76. if (lookup_status == AE_BAD_CHARACTER) {
  77. /* There is a non-ascii character in the name */
  78. acpi_os_printf("[0x%4.4X] (NON-ASCII)\n",
  79. *(ACPI_CAST_PTR(u32, internal_name)));
  80. } else {
  81. /* Convert path to external format */
  82. status = acpi_ns_externalize_name(ACPI_UINT32_MAX,
  83. internal_name, NULL, &name);
  84. /* Print target name */
  85. if (ACPI_SUCCESS(status)) {
  86. acpi_os_printf("[%s]", name);
  87. } else {
  88. acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
  89. }
  90. if (name) {
  91. ACPI_MEM_FREE(name);
  92. }
  93. }
  94. acpi_os_printf("Namespace lookup failure, %s\n",
  95. acpi_format_exception(lookup_status));
  96. }
  97. /*******************************************************************************
  98. *
  99. * FUNCTION: acpi_ns_report_method_error
  100. *
  101. * PARAMETERS: module_name - Caller's module name (for error output)
  102. * line_number - Caller's line number (for error output)
  103. * Message - Error message to use on failure
  104. * prefix_node - Prefix relative to the path
  105. * Path - Path to the node (optional)
  106. * method_status - Execution status
  107. *
  108. * RETURN: None
  109. *
  110. * DESCRIPTION: Print warning message with full pathname
  111. *
  112. ******************************************************************************/
  113. void
  114. acpi_ns_report_method_error(char *module_name,
  115. u32 line_number,
  116. char *message,
  117. struct acpi_namespace_node *prefix_node,
  118. char *path, acpi_status method_status)
  119. {
  120. acpi_status status;
  121. struct acpi_namespace_node *node = prefix_node;
  122. acpi_ut_report_error(module_name, line_number);
  123. if (path) {
  124. status = acpi_ns_get_node_by_path(path, prefix_node,
  125. ACPI_NS_NO_UPSEARCH, &node);
  126. if (ACPI_FAILURE(status)) {
  127. acpi_os_printf("[Could not get node by pathname]");
  128. }
  129. }
  130. acpi_ns_print_node_pathname(node, message);
  131. acpi_os_printf(", %s\n", acpi_format_exception(method_status));
  132. }
  133. /*******************************************************************************
  134. *
  135. * FUNCTION: acpi_ns_print_node_pathname
  136. *
  137. * PARAMETERS: Node - Object
  138. * Message - Prefix message
  139. *
  140. * DESCRIPTION: Print an object's full namespace pathname
  141. * Manages allocation/freeing of a pathname buffer
  142. *
  143. ******************************************************************************/
  144. void
  145. acpi_ns_print_node_pathname(struct acpi_namespace_node *node, char *message)
  146. {
  147. struct acpi_buffer buffer;
  148. acpi_status status;
  149. if (!node) {
  150. acpi_os_printf("[NULL NAME]");
  151. return;
  152. }
  153. /* Convert handle to full pathname and print it (with supplied message) */
  154. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  155. status = acpi_ns_handle_to_pathname(node, &buffer);
  156. if (ACPI_SUCCESS(status)) {
  157. if (message) {
  158. acpi_os_printf("%s ", message);
  159. }
  160. acpi_os_printf("[%s] (Node %p)", (char *)buffer.pointer, node);
  161. ACPI_MEM_FREE(buffer.pointer);
  162. }
  163. }
  164. /*******************************************************************************
  165. *
  166. * FUNCTION: acpi_ns_valid_root_prefix
  167. *
  168. * PARAMETERS: Prefix - Character to be checked
  169. *
  170. * RETURN: TRUE if a valid prefix
  171. *
  172. * DESCRIPTION: Check if a character is a valid ACPI Root prefix
  173. *
  174. ******************************************************************************/
  175. u8 acpi_ns_valid_root_prefix(char prefix)
  176. {
  177. return ((u8) (prefix == '\\'));
  178. }
  179. /*******************************************************************************
  180. *
  181. * FUNCTION: acpi_ns_valid_path_separator
  182. *
  183. * PARAMETERS: Sep - Character to be checked
  184. *
  185. * RETURN: TRUE if a valid path separator
  186. *
  187. * DESCRIPTION: Check if a character is a valid ACPI path separator
  188. *
  189. ******************************************************************************/
  190. static u8 acpi_ns_valid_path_separator(char sep)
  191. {
  192. return ((u8) (sep == '.'));
  193. }
  194. /*******************************************************************************
  195. *
  196. * FUNCTION: acpi_ns_get_type
  197. *
  198. * PARAMETERS: Node - Parent Node to be examined
  199. *
  200. * RETURN: Type field from Node whose handle is passed
  201. *
  202. * DESCRIPTION: Return the type of a Namespace node
  203. *
  204. ******************************************************************************/
  205. acpi_object_type acpi_ns_get_type(struct acpi_namespace_node * node)
  206. {
  207. ACPI_FUNCTION_TRACE("ns_get_type");
  208. if (!node) {
  209. ACPI_REPORT_WARNING(("Null Node parameter\n"));
  210. return_UINT32(ACPI_TYPE_ANY);
  211. }
  212. return_UINT32((acpi_object_type) node->type);
  213. }
  214. /*******************************************************************************
  215. *
  216. * FUNCTION: acpi_ns_local
  217. *
  218. * PARAMETERS: Type - A namespace object type
  219. *
  220. * RETURN: LOCAL if names must be found locally in objects of the
  221. * passed type, 0 if enclosing scopes should be searched
  222. *
  223. * DESCRIPTION: Returns scope rule for the given object type.
  224. *
  225. ******************************************************************************/
  226. u32 acpi_ns_local(acpi_object_type type)
  227. {
  228. ACPI_FUNCTION_TRACE("ns_local");
  229. if (!acpi_ut_valid_object_type(type)) {
  230. /* Type code out of range */
  231. ACPI_REPORT_WARNING(("Invalid Object Type %X\n", type));
  232. return_UINT32(ACPI_NS_NORMAL);
  233. }
  234. return_UINT32((u32) acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL);
  235. }
  236. /*******************************************************************************
  237. *
  238. * FUNCTION: acpi_ns_get_internal_name_length
  239. *
  240. * PARAMETERS: Info - Info struct initialized with the
  241. * external name pointer.
  242. *
  243. * RETURN: None
  244. *
  245. * DESCRIPTION: Calculate the length of the internal (AML) namestring
  246. * corresponding to the external (ASL) namestring.
  247. *
  248. ******************************************************************************/
  249. void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info)
  250. {
  251. char *next_external_char;
  252. u32 i;
  253. ACPI_FUNCTION_ENTRY();
  254. next_external_char = info->external_name;
  255. info->num_carats = 0;
  256. info->num_segments = 0;
  257. info->fully_qualified = FALSE;
  258. /*
  259. * For the internal name, the required length is 4 bytes per segment, plus
  260. * 1 each for root_prefix, multi_name_prefix_op, segment count, trailing null
  261. * (which is not really needed, but no there's harm in putting it there)
  262. *
  263. * strlen() + 1 covers the first name_seg, which has no path separator
  264. */
  265. if (acpi_ns_valid_root_prefix(next_external_char[0])) {
  266. info->fully_qualified = TRUE;
  267. next_external_char++;
  268. } else {
  269. /*
  270. * Handle Carat prefixes
  271. */
  272. while (*next_external_char == '^') {
  273. info->num_carats++;
  274. next_external_char++;
  275. }
  276. }
  277. /*
  278. * Determine the number of ACPI name "segments" by counting the number of
  279. * path separators within the string. Start with one segment since the
  280. * segment count is [(# separators) + 1], and zero separators is ok.
  281. */
  282. if (*next_external_char) {
  283. info->num_segments = 1;
  284. for (i = 0; next_external_char[i]; i++) {
  285. if (acpi_ns_valid_path_separator(next_external_char[i])) {
  286. info->num_segments++;
  287. }
  288. }
  289. }
  290. info->length = (ACPI_NAME_SIZE * info->num_segments) +
  291. 4 + info->num_carats;
  292. info->next_external_char = next_external_char;
  293. }
  294. /*******************************************************************************
  295. *
  296. * FUNCTION: acpi_ns_build_internal_name
  297. *
  298. * PARAMETERS: Info - Info struct fully initialized
  299. *
  300. * RETURN: Status
  301. *
  302. * DESCRIPTION: Construct the internal (AML) namestring
  303. * corresponding to the external (ASL) namestring.
  304. *
  305. ******************************************************************************/
  306. acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info)
  307. {
  308. u32 num_segments = info->num_segments;
  309. char *internal_name = info->internal_name;
  310. char *external_name = info->next_external_char;
  311. char *result = NULL;
  312. acpi_native_uint i;
  313. ACPI_FUNCTION_TRACE("ns_build_internal_name");
  314. /* Setup the correct prefixes, counts, and pointers */
  315. if (info->fully_qualified) {
  316. internal_name[0] = '\\';
  317. if (num_segments <= 1) {
  318. result = &internal_name[1];
  319. } else if (num_segments == 2) {
  320. internal_name[1] = AML_DUAL_NAME_PREFIX;
  321. result = &internal_name[2];
  322. } else {
  323. internal_name[1] = AML_MULTI_NAME_PREFIX_OP;
  324. internal_name[2] = (char)num_segments;
  325. result = &internal_name[3];
  326. }
  327. } else {
  328. /*
  329. * Not fully qualified.
  330. * Handle Carats first, then append the name segments
  331. */
  332. i = 0;
  333. if (info->num_carats) {
  334. for (i = 0; i < info->num_carats; i++) {
  335. internal_name[i] = '^';
  336. }
  337. }
  338. if (num_segments <= 1) {
  339. result = &internal_name[i];
  340. } else if (num_segments == 2) {
  341. internal_name[i] = AML_DUAL_NAME_PREFIX;
  342. result = &internal_name[(acpi_native_uint) (i + 1)];
  343. } else {
  344. internal_name[i] = AML_MULTI_NAME_PREFIX_OP;
  345. internal_name[(acpi_native_uint) (i + 1)] =
  346. (char)num_segments;
  347. result = &internal_name[(acpi_native_uint) (i + 2)];
  348. }
  349. }
  350. /* Build the name (minus path separators) */
  351. for (; num_segments; num_segments--) {
  352. for (i = 0; i < ACPI_NAME_SIZE; i++) {
  353. if (acpi_ns_valid_path_separator(*external_name) ||
  354. (*external_name == 0)) {
  355. /* Pad the segment with underscore(s) if segment is short */
  356. result[i] = '_';
  357. } else {
  358. /* Convert the character to uppercase and save it */
  359. result[i] =
  360. (char)ACPI_TOUPPER((int)*external_name);
  361. external_name++;
  362. }
  363. }
  364. /* Now we must have a path separator, or the pathname is bad */
  365. if (!acpi_ns_valid_path_separator(*external_name) &&
  366. (*external_name != 0)) {
  367. return_ACPI_STATUS(AE_BAD_PARAMETER);
  368. }
  369. /* Move on the next segment */
  370. external_name++;
  371. result += ACPI_NAME_SIZE;
  372. }
  373. /* Terminate the string */
  374. *result = 0;
  375. if (info->fully_qualified) {
  376. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  377. "Returning [%p] (abs) \"\\%s\"\n",
  378. internal_name, internal_name));
  379. } else {
  380. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
  381. internal_name, internal_name));
  382. }
  383. return_ACPI_STATUS(AE_OK);
  384. }
  385. /*******************************************************************************
  386. *
  387. * FUNCTION: acpi_ns_internalize_name
  388. *
  389. * PARAMETERS: *external_name - External representation of name
  390. * **Converted Name - Where to return the resulting
  391. * internal represention of the name
  392. *
  393. * RETURN: Status
  394. *
  395. * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
  396. * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
  397. *
  398. *******************************************************************************/
  399. acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name)
  400. {
  401. char *internal_name;
  402. struct acpi_namestring_info info;
  403. acpi_status status;
  404. ACPI_FUNCTION_TRACE("ns_internalize_name");
  405. if ((!external_name) || (*external_name == 0) || (!converted_name)) {
  406. return_ACPI_STATUS(AE_BAD_PARAMETER);
  407. }
  408. /* Get the length of the new internal name */
  409. info.external_name = external_name;
  410. acpi_ns_get_internal_name_length(&info);
  411. /* We need a segment to store the internal name */
  412. internal_name = ACPI_MEM_CALLOCATE(info.length);
  413. if (!internal_name) {
  414. return_ACPI_STATUS(AE_NO_MEMORY);
  415. }
  416. /* Build the name */
  417. info.internal_name = internal_name;
  418. status = acpi_ns_build_internal_name(&info);
  419. if (ACPI_FAILURE(status)) {
  420. ACPI_MEM_FREE(internal_name);
  421. return_ACPI_STATUS(status);
  422. }
  423. *converted_name = internal_name;
  424. return_ACPI_STATUS(AE_OK);
  425. }
  426. /*******************************************************************************
  427. *
  428. * FUNCTION: acpi_ns_externalize_name
  429. *
  430. * PARAMETERS: internal_name_length - Lenth of the internal name below
  431. * internal_name - Internal representation of name
  432. * converted_name_length - Where the length is returned
  433. * converted_name - Where the resulting external name
  434. * is returned
  435. *
  436. * RETURN: Status
  437. *
  438. * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
  439. * to its external (printable) form (e.g. "\_PR_.CPU0")
  440. *
  441. ******************************************************************************/
  442. acpi_status
  443. acpi_ns_externalize_name(u32 internal_name_length,
  444. char *internal_name,
  445. u32 * converted_name_length, char **converted_name)
  446. {
  447. acpi_native_uint names_index = 0;
  448. acpi_native_uint num_segments = 0;
  449. acpi_native_uint required_length;
  450. acpi_native_uint prefix_length = 0;
  451. acpi_native_uint i = 0;
  452. acpi_native_uint j = 0;
  453. ACPI_FUNCTION_TRACE("ns_externalize_name");
  454. if (!internal_name_length || !internal_name || !converted_name) {
  455. return_ACPI_STATUS(AE_BAD_PARAMETER);
  456. }
  457. /*
  458. * Check for a prefix (one '\' | one or more '^').
  459. */
  460. switch (internal_name[0]) {
  461. case '\\':
  462. prefix_length = 1;
  463. break;
  464. case '^':
  465. for (i = 0; i < internal_name_length; i++) {
  466. if (internal_name[i] == '^') {
  467. prefix_length = i + 1;
  468. } else {
  469. break;
  470. }
  471. }
  472. if (i == internal_name_length) {
  473. prefix_length = i;
  474. }
  475. break;
  476. default:
  477. break;
  478. }
  479. /*
  480. * Check for object names. Note that there could be 0-255 of these
  481. * 4-byte elements.
  482. */
  483. if (prefix_length < internal_name_length) {
  484. switch (internal_name[prefix_length]) {
  485. case AML_MULTI_NAME_PREFIX_OP:
  486. /* <count> 4-byte names */
  487. names_index = prefix_length + 2;
  488. num_segments = (acpi_native_uint) (u8)
  489. internal_name[(acpi_native_uint)
  490. (prefix_length + 1)];
  491. break;
  492. case AML_DUAL_NAME_PREFIX:
  493. /* Two 4-byte names */
  494. names_index = prefix_length + 1;
  495. num_segments = 2;
  496. break;
  497. case 0:
  498. /* null_name */
  499. names_index = 0;
  500. num_segments = 0;
  501. break;
  502. default:
  503. /* one 4-byte name */
  504. names_index = prefix_length;
  505. num_segments = 1;
  506. break;
  507. }
  508. }
  509. /*
  510. * Calculate the length of converted_name, which equals the length
  511. * of the prefix, length of all object names, length of any required
  512. * punctuation ('.') between object names, plus the NULL terminator.
  513. */
  514. required_length = prefix_length + (4 * num_segments) +
  515. ((num_segments > 0) ? (num_segments - 1) : 0) + 1;
  516. /*
  517. * Check to see if we're still in bounds. If not, there's a problem
  518. * with internal_name (invalid format).
  519. */
  520. if (required_length > internal_name_length) {
  521. ACPI_REPORT_ERROR(("Invalid internal name\n"));
  522. return_ACPI_STATUS(AE_BAD_PATHNAME);
  523. }
  524. /*
  525. * Build converted_name
  526. */
  527. *converted_name = ACPI_MEM_CALLOCATE(required_length);
  528. if (!(*converted_name)) {
  529. return_ACPI_STATUS(AE_NO_MEMORY);
  530. }
  531. j = 0;
  532. for (i = 0; i < prefix_length; i++) {
  533. (*converted_name)[j++] = internal_name[i];
  534. }
  535. if (num_segments > 0) {
  536. for (i = 0; i < num_segments; i++) {
  537. if (i > 0) {
  538. (*converted_name)[j++] = '.';
  539. }
  540. (*converted_name)[j++] = internal_name[names_index++];
  541. (*converted_name)[j++] = internal_name[names_index++];
  542. (*converted_name)[j++] = internal_name[names_index++];
  543. (*converted_name)[j++] = internal_name[names_index++];
  544. }
  545. }
  546. if (converted_name_length) {
  547. *converted_name_length = (u32) required_length;
  548. }
  549. return_ACPI_STATUS(AE_OK);
  550. }
  551. /*******************************************************************************
  552. *
  553. * FUNCTION: acpi_ns_map_handle_to_node
  554. *
  555. * PARAMETERS: Handle - Handle to be converted to an Node
  556. *
  557. * RETURN: A Name table entry pointer
  558. *
  559. * DESCRIPTION: Convert a namespace handle to a real Node
  560. *
  561. * Note: Real integer handles would allow for more verification
  562. * and keep all pointers within this subsystem - however this introduces
  563. * more (and perhaps unnecessary) overhead.
  564. *
  565. ******************************************************************************/
  566. struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle)
  567. {
  568. ACPI_FUNCTION_ENTRY();
  569. /*
  570. * Simple implementation.
  571. */
  572. if (!handle) {
  573. return (NULL);
  574. }
  575. if (handle == ACPI_ROOT_OBJECT) {
  576. return (acpi_gbl_root_node);
  577. }
  578. /* We can at least attempt to verify the handle */
  579. if (ACPI_GET_DESCRIPTOR_TYPE(handle) != ACPI_DESC_TYPE_NAMED) {
  580. return (NULL);
  581. }
  582. return ((struct acpi_namespace_node *)handle);
  583. }
  584. /*******************************************************************************
  585. *
  586. * FUNCTION: acpi_ns_convert_entry_to_handle
  587. *
  588. * PARAMETERS: Node - Node to be converted to a Handle
  589. *
  590. * RETURN: A user handle
  591. *
  592. * DESCRIPTION: Convert a real Node to a namespace handle
  593. *
  594. ******************************************************************************/
  595. acpi_handle acpi_ns_convert_entry_to_handle(struct acpi_namespace_node *node)
  596. {
  597. /*
  598. * Simple implementation for now;
  599. */
  600. return ((acpi_handle) node);
  601. /* Example future implementation ---------------------
  602. if (!Node)
  603. {
  604. return (NULL);
  605. }
  606. if (Node == acpi_gbl_root_node)
  607. {
  608. return (ACPI_ROOT_OBJECT);
  609. }
  610. return ((acpi_handle) Node);
  611. ------------------------------------------------------*/
  612. }
  613. /*******************************************************************************
  614. *
  615. * FUNCTION: acpi_ns_terminate
  616. *
  617. * PARAMETERS: none
  618. *
  619. * RETURN: none
  620. *
  621. * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
  622. *
  623. ******************************************************************************/
  624. void acpi_ns_terminate(void)
  625. {
  626. union acpi_operand_object *obj_desc;
  627. ACPI_FUNCTION_TRACE("ns_terminate");
  628. /*
  629. * 1) Free the entire namespace -- all nodes and objects
  630. *
  631. * Delete all object descriptors attached to namepsace nodes
  632. */
  633. acpi_ns_delete_namespace_subtree(acpi_gbl_root_node);
  634. /* Detach any objects attached to the root */
  635. obj_desc = acpi_ns_get_attached_object(acpi_gbl_root_node);
  636. if (obj_desc) {
  637. acpi_ns_detach_object(acpi_gbl_root_node);
  638. }
  639. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n"));
  640. /*
  641. * 2) Now we can delete the ACPI tables
  642. */
  643. acpi_tb_delete_all_tables();
  644. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
  645. return_VOID;
  646. }
  647. /*******************************************************************************
  648. *
  649. * FUNCTION: acpi_ns_opens_scope
  650. *
  651. * PARAMETERS: Type - A valid namespace type
  652. *
  653. * RETURN: NEWSCOPE if the passed type "opens a name scope" according
  654. * to the ACPI specification, else 0
  655. *
  656. ******************************************************************************/
  657. u32 acpi_ns_opens_scope(acpi_object_type type)
  658. {
  659. ACPI_FUNCTION_TRACE_STR("ns_opens_scope", acpi_ut_get_type_name(type));
  660. if (!acpi_ut_valid_object_type(type)) {
  661. /* type code out of range */
  662. ACPI_REPORT_WARNING(("Invalid Object Type %X\n", type));
  663. return_UINT32(ACPI_NS_NORMAL);
  664. }
  665. return_UINT32(((u32) acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE);
  666. }
  667. /*******************************************************************************
  668. *
  669. * FUNCTION: acpi_ns_get_node_by_path
  670. *
  671. * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
  672. * \ (backslash) and ^ (carat) prefixes, and the
  673. * . (period) to separate segments are supported.
  674. * start_node - Root of subtree to be searched, or NS_ALL for the
  675. * root of the name space. If Name is fully
  676. * qualified (first s8 is '\'), the passed value
  677. * of Scope will not be accessed.
  678. * Flags - Used to indicate whether to perform upsearch or
  679. * not.
  680. * return_node - Where the Node is returned
  681. *
  682. * DESCRIPTION: Look up a name relative to a given scope and return the
  683. * corresponding Node. NOTE: Scope can be null.
  684. *
  685. * MUTEX: Locks namespace
  686. *
  687. ******************************************************************************/
  688. acpi_status
  689. acpi_ns_get_node_by_path(char *pathname,
  690. struct acpi_namespace_node *start_node,
  691. u32 flags, struct acpi_namespace_node **return_node)
  692. {
  693. union acpi_generic_state scope_info;
  694. acpi_status status;
  695. char *internal_path = NULL;
  696. ACPI_FUNCTION_TRACE_PTR("ns_get_node_by_path", pathname);
  697. if (pathname) {
  698. /* Convert path to internal representation */
  699. status = acpi_ns_internalize_name(pathname, &internal_path);
  700. if (ACPI_FAILURE(status)) {
  701. return_ACPI_STATUS(status);
  702. }
  703. }
  704. /* Must lock namespace during lookup */
  705. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  706. if (ACPI_FAILURE(status)) {
  707. goto cleanup;
  708. }
  709. /* Setup lookup scope (search starting point) */
  710. scope_info.scope.node = start_node;
  711. /* Lookup the name in the namespace */
  712. status = acpi_ns_lookup(&scope_info, internal_path,
  713. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  714. (flags | ACPI_NS_DONT_OPEN_SCOPE),
  715. NULL, return_node);
  716. if (ACPI_FAILURE(status)) {
  717. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s, %s\n",
  718. internal_path,
  719. acpi_format_exception(status)));
  720. }
  721. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  722. cleanup:
  723. if (internal_path) {
  724. ACPI_MEM_FREE(internal_path);
  725. }
  726. return_ACPI_STATUS(status);
  727. }
  728. /*******************************************************************************
  729. *
  730. * FUNCTION: acpi_ns_get_parent_node
  731. *
  732. * PARAMETERS: Node - Current table entry
  733. *
  734. * RETURN: Parent entry of the given entry
  735. *
  736. * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
  737. *
  738. ******************************************************************************/
  739. struct acpi_namespace_node *acpi_ns_get_parent_node(struct acpi_namespace_node
  740. *node)
  741. {
  742. ACPI_FUNCTION_ENTRY();
  743. if (!node) {
  744. return (NULL);
  745. }
  746. /*
  747. * Walk to the end of this peer list. The last entry is marked with a flag
  748. * and the peer pointer is really a pointer back to the parent. This saves
  749. * putting a parent back pointer in each and every named object!
  750. */
  751. while (!(node->flags & ANOBJ_END_OF_PEER_LIST)) {
  752. node = node->peer;
  753. }
  754. return (node->peer);
  755. }
  756. /*******************************************************************************
  757. *
  758. * FUNCTION: acpi_ns_get_next_valid_node
  759. *
  760. * PARAMETERS: Node - Current table entry
  761. *
  762. * RETURN: Next valid Node in the linked node list. NULL if no more valid
  763. * nodes.
  764. *
  765. * DESCRIPTION: Find the next valid node within a name table.
  766. * Useful for implementing NULL-end-of-list loops.
  767. *
  768. ******************************************************************************/
  769. struct acpi_namespace_node *acpi_ns_get_next_valid_node(struct
  770. acpi_namespace_node
  771. *node)
  772. {
  773. /* If we are at the end of this peer list, return NULL */
  774. if (node->flags & ANOBJ_END_OF_PEER_LIST) {
  775. return NULL;
  776. }
  777. /* Otherwise just return the next peer */
  778. return (node->peer);
  779. }
  780. #ifdef ACPI_OBSOLETE_FUNCTIONS
  781. /*******************************************************************************
  782. *
  783. * FUNCTION: acpi_ns_find_parent_name
  784. *
  785. * PARAMETERS: *child_node - Named Obj whose name is to be found
  786. *
  787. * RETURN: The ACPI name
  788. *
  789. * DESCRIPTION: Search for the given obj in its parent scope and return the
  790. * name segment, or "????" if the parent name can't be found
  791. * (which "should not happen").
  792. *
  793. ******************************************************************************/
  794. acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node * child_node)
  795. {
  796. struct acpi_namespace_node *parent_node;
  797. ACPI_FUNCTION_TRACE("ns_find_parent_name");
  798. if (child_node) {
  799. /* Valid entry. Get the parent Node */
  800. parent_node = acpi_ns_get_parent_node(child_node);
  801. if (parent_node) {
  802. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  803. "Parent of %p [%4.4s] is %p [%4.4s]\n",
  804. child_node,
  805. acpi_ut_get_node_name(child_node),
  806. parent_node,
  807. acpi_ut_get_node_name(parent_node)));
  808. if (parent_node->name.integer) {
  809. return_VALUE((acpi_name) parent_node->name.
  810. integer);
  811. }
  812. }
  813. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  814. "Unable to find parent of %p (%4.4s)\n",
  815. child_node,
  816. acpi_ut_get_node_name(child_node)));
  817. }
  818. return_VALUE(ACPI_UNKNOWN_NAME);
  819. }
  820. #endif