nsutils.c 27 KB

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