nsutils.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 - 2017, Intel Corp.
  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 "accommon.h"
  45. #include "acnamesp.h"
  46. #include "amlcode.h"
  47. #define _COMPONENT ACPI_NAMESPACE
  48. ACPI_MODULE_NAME("nsutils")
  49. /* Local prototypes */
  50. #ifdef ACPI_OBSOLETE_FUNCTIONS
  51. acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search);
  52. #endif
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_ns_print_node_pathname
  56. *
  57. * PARAMETERS: node - Object
  58. * message - Prefix message
  59. *
  60. * DESCRIPTION: Print an object's full namespace pathname
  61. * Manages allocation/freeing of a pathname buffer
  62. *
  63. ******************************************************************************/
  64. void
  65. acpi_ns_print_node_pathname(struct acpi_namespace_node *node,
  66. const char *message)
  67. {
  68. struct acpi_buffer buffer;
  69. acpi_status status;
  70. if (!node) {
  71. acpi_os_printf("[NULL NAME]");
  72. return;
  73. }
  74. /* Convert handle to full pathname and print it (with supplied message) */
  75. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  76. status = acpi_ns_handle_to_pathname(node, &buffer, TRUE);
  77. if (ACPI_SUCCESS(status)) {
  78. if (message) {
  79. acpi_os_printf("%s ", message);
  80. }
  81. acpi_os_printf("[%s] (Node %p)", (char *)buffer.pointer, node);
  82. ACPI_FREE(buffer.pointer);
  83. }
  84. }
  85. /*******************************************************************************
  86. *
  87. * FUNCTION: acpi_ns_get_type
  88. *
  89. * PARAMETERS: node - Parent Node to be examined
  90. *
  91. * RETURN: Type field from Node whose handle is passed
  92. *
  93. * DESCRIPTION: Return the type of a Namespace node
  94. *
  95. ******************************************************************************/
  96. acpi_object_type acpi_ns_get_type(struct acpi_namespace_node * node)
  97. {
  98. ACPI_FUNCTION_TRACE(ns_get_type);
  99. if (!node) {
  100. ACPI_WARNING((AE_INFO, "Null Node parameter"));
  101. return_UINT8(ACPI_TYPE_ANY);
  102. }
  103. return_UINT8(node->type);
  104. }
  105. /*******************************************************************************
  106. *
  107. * FUNCTION: acpi_ns_local
  108. *
  109. * PARAMETERS: type - A namespace object type
  110. *
  111. * RETURN: LOCAL if names must be found locally in objects of the
  112. * passed type, 0 if enclosing scopes should be searched
  113. *
  114. * DESCRIPTION: Returns scope rule for the given object type.
  115. *
  116. ******************************************************************************/
  117. u32 acpi_ns_local(acpi_object_type type)
  118. {
  119. ACPI_FUNCTION_TRACE(ns_local);
  120. if (!acpi_ut_valid_object_type(type)) {
  121. /* Type code out of range */
  122. ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type));
  123. return_UINT32(ACPI_NS_NORMAL);
  124. }
  125. return_UINT32(acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL);
  126. }
  127. /*******************************************************************************
  128. *
  129. * FUNCTION: acpi_ns_get_internal_name_length
  130. *
  131. * PARAMETERS: info - Info struct initialized with the
  132. * external name pointer.
  133. *
  134. * RETURN: None
  135. *
  136. * DESCRIPTION: Calculate the length of the internal (AML) namestring
  137. * corresponding to the external (ASL) namestring.
  138. *
  139. ******************************************************************************/
  140. void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info)
  141. {
  142. const char *next_external_char;
  143. u32 i;
  144. ACPI_FUNCTION_ENTRY();
  145. next_external_char = info->external_name;
  146. info->num_carats = 0;
  147. info->num_segments = 0;
  148. info->fully_qualified = FALSE;
  149. /*
  150. * For the internal name, the required length is 4 bytes per segment,
  151. * plus 1 each for root_prefix, multi_name_prefix_op, segment count,
  152. * trailing null (which is not really needed, but no there's harm in
  153. * putting it there)
  154. *
  155. * strlen() + 1 covers the first name_seg, which has no path separator
  156. */
  157. if (ACPI_IS_ROOT_PREFIX(*next_external_char)) {
  158. info->fully_qualified = TRUE;
  159. next_external_char++;
  160. /* Skip redundant root_prefix, like \\_SB.PCI0.SBRG.EC0 */
  161. while (ACPI_IS_ROOT_PREFIX(*next_external_char)) {
  162. next_external_char++;
  163. }
  164. } else {
  165. /* Handle Carat prefixes */
  166. while (ACPI_IS_PARENT_PREFIX(*next_external_char)) {
  167. info->num_carats++;
  168. next_external_char++;
  169. }
  170. }
  171. /*
  172. * Determine the number of ACPI name "segments" by counting the number of
  173. * path separators within the string. Start with one segment since the
  174. * segment count is [(# separators) + 1], and zero separators is ok.
  175. */
  176. if (*next_external_char) {
  177. info->num_segments = 1;
  178. for (i = 0; next_external_char[i]; i++) {
  179. if (ACPI_IS_PATH_SEPARATOR(next_external_char[i])) {
  180. info->num_segments++;
  181. }
  182. }
  183. }
  184. info->length = (ACPI_NAME_SIZE * info->num_segments) +
  185. 4 + info->num_carats;
  186. info->next_external_char = next_external_char;
  187. }
  188. /*******************************************************************************
  189. *
  190. * FUNCTION: acpi_ns_build_internal_name
  191. *
  192. * PARAMETERS: info - Info struct fully initialized
  193. *
  194. * RETURN: Status
  195. *
  196. * DESCRIPTION: Construct the internal (AML) namestring
  197. * corresponding to the external (ASL) namestring.
  198. *
  199. ******************************************************************************/
  200. acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info)
  201. {
  202. u32 num_segments = info->num_segments;
  203. char *internal_name = info->internal_name;
  204. const char *external_name = info->next_external_char;
  205. char *result = NULL;
  206. u32 i;
  207. ACPI_FUNCTION_TRACE(ns_build_internal_name);
  208. /* Setup the correct prefixes, counts, and pointers */
  209. if (info->fully_qualified) {
  210. internal_name[0] = AML_ROOT_PREFIX;
  211. if (num_segments <= 1) {
  212. result = &internal_name[1];
  213. } else if (num_segments == 2) {
  214. internal_name[1] = AML_DUAL_NAME_PREFIX;
  215. result = &internal_name[2];
  216. } else {
  217. internal_name[1] = AML_MULTI_NAME_PREFIX;
  218. internal_name[2] = (char)num_segments;
  219. result = &internal_name[3];
  220. }
  221. } else {
  222. /*
  223. * Not fully qualified.
  224. * Handle Carats first, then append the name segments
  225. */
  226. i = 0;
  227. if (info->num_carats) {
  228. for (i = 0; i < info->num_carats; i++) {
  229. internal_name[i] = AML_PARENT_PREFIX;
  230. }
  231. }
  232. if (num_segments <= 1) {
  233. result = &internal_name[i];
  234. } else if (num_segments == 2) {
  235. internal_name[i] = AML_DUAL_NAME_PREFIX;
  236. result = &internal_name[(acpi_size)i + 1];
  237. } else {
  238. internal_name[i] = AML_MULTI_NAME_PREFIX;
  239. internal_name[(acpi_size)i + 1] = (char)num_segments;
  240. result = &internal_name[(acpi_size)i + 2];
  241. }
  242. }
  243. /* Build the name (minus path separators) */
  244. for (; num_segments; num_segments--) {
  245. for (i = 0; i < ACPI_NAME_SIZE; i++) {
  246. if (ACPI_IS_PATH_SEPARATOR(*external_name) ||
  247. (*external_name == 0)) {
  248. /* Pad the segment with underscore(s) if segment is short */
  249. result[i] = '_';
  250. } else {
  251. /* Convert the character to uppercase and save it */
  252. result[i] = (char)toupper((int)*external_name);
  253. external_name++;
  254. }
  255. }
  256. /* Now we must have a path separator, or the pathname is bad */
  257. if (!ACPI_IS_PATH_SEPARATOR(*external_name) &&
  258. (*external_name != 0)) {
  259. return_ACPI_STATUS(AE_BAD_PATHNAME);
  260. }
  261. /* Move on the next segment */
  262. external_name++;
  263. result += ACPI_NAME_SIZE;
  264. }
  265. /* Terminate the string */
  266. *result = 0;
  267. if (info->fully_qualified) {
  268. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  269. "Returning [%p] (abs) \"\\%s\"\n",
  270. internal_name, internal_name));
  271. } else {
  272. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
  273. internal_name, internal_name));
  274. }
  275. return_ACPI_STATUS(AE_OK);
  276. }
  277. /*******************************************************************************
  278. *
  279. * FUNCTION: acpi_ns_internalize_name
  280. *
  281. * PARAMETERS: *external_name - External representation of name
  282. * **Converted name - Where to return the resulting
  283. * internal represention of the name
  284. *
  285. * RETURN: Status
  286. *
  287. * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
  288. * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
  289. *
  290. *******************************************************************************/
  291. acpi_status
  292. acpi_ns_internalize_name(const char *external_name, char **converted_name)
  293. {
  294. char *internal_name;
  295. struct acpi_namestring_info info;
  296. acpi_status status;
  297. ACPI_FUNCTION_TRACE(ns_internalize_name);
  298. if ((!external_name) || (*external_name == 0) || (!converted_name)) {
  299. return_ACPI_STATUS(AE_BAD_PARAMETER);
  300. }
  301. /* Get the length of the new internal name */
  302. info.external_name = external_name;
  303. acpi_ns_get_internal_name_length(&info);
  304. /* We need a segment to store the internal name */
  305. internal_name = ACPI_ALLOCATE_ZEROED(info.length);
  306. if (!internal_name) {
  307. return_ACPI_STATUS(AE_NO_MEMORY);
  308. }
  309. /* Build the name */
  310. info.internal_name = internal_name;
  311. status = acpi_ns_build_internal_name(&info);
  312. if (ACPI_FAILURE(status)) {
  313. ACPI_FREE(internal_name);
  314. return_ACPI_STATUS(status);
  315. }
  316. *converted_name = internal_name;
  317. return_ACPI_STATUS(AE_OK);
  318. }
  319. /*******************************************************************************
  320. *
  321. * FUNCTION: acpi_ns_externalize_name
  322. *
  323. * PARAMETERS: internal_name_length - Lenth of the internal name below
  324. * internal_name - Internal representation of name
  325. * converted_name_length - Where the length is returned
  326. * converted_name - Where the resulting external name
  327. * is returned
  328. *
  329. * RETURN: Status
  330. *
  331. * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
  332. * to its external (printable) form (e.g. "\_PR_.CPU0")
  333. *
  334. ******************************************************************************/
  335. acpi_status
  336. acpi_ns_externalize_name(u32 internal_name_length,
  337. const char *internal_name,
  338. u32 * converted_name_length, char **converted_name)
  339. {
  340. u32 names_index = 0;
  341. u32 num_segments = 0;
  342. u32 required_length;
  343. u32 prefix_length = 0;
  344. u32 i = 0;
  345. u32 j = 0;
  346. ACPI_FUNCTION_TRACE(ns_externalize_name);
  347. if (!internal_name_length || !internal_name || !converted_name) {
  348. return_ACPI_STATUS(AE_BAD_PARAMETER);
  349. }
  350. /* Check for a prefix (one '\' | one or more '^') */
  351. switch (internal_name[0]) {
  352. case AML_ROOT_PREFIX:
  353. prefix_length = 1;
  354. break;
  355. case AML_PARENT_PREFIX:
  356. for (i = 0; i < internal_name_length; i++) {
  357. if (ACPI_IS_PARENT_PREFIX(internal_name[i])) {
  358. prefix_length = i + 1;
  359. } else {
  360. break;
  361. }
  362. }
  363. if (i == internal_name_length) {
  364. prefix_length = i;
  365. }
  366. break;
  367. default:
  368. break;
  369. }
  370. /*
  371. * Check for object names. Note that there could be 0-255 of these
  372. * 4-byte elements.
  373. */
  374. if (prefix_length < internal_name_length) {
  375. switch (internal_name[prefix_length]) {
  376. case AML_MULTI_NAME_PREFIX:
  377. /* <count> 4-byte names */
  378. names_index = prefix_length + 2;
  379. num_segments = (u8)
  380. internal_name[(acpi_size)prefix_length + 1];
  381. break;
  382. case AML_DUAL_NAME_PREFIX:
  383. /* Two 4-byte names */
  384. names_index = prefix_length + 1;
  385. num_segments = 2;
  386. break;
  387. case 0:
  388. /* null_name */
  389. names_index = 0;
  390. num_segments = 0;
  391. break;
  392. default:
  393. /* one 4-byte name */
  394. names_index = prefix_length;
  395. num_segments = 1;
  396. break;
  397. }
  398. }
  399. /*
  400. * Calculate the length of converted_name, which equals the length
  401. * of the prefix, length of all object names, length of any required
  402. * punctuation ('.') between object names, plus the NULL terminator.
  403. */
  404. required_length = prefix_length + (4 * num_segments) +
  405. ((num_segments > 0) ? (num_segments - 1) : 0) + 1;
  406. /*
  407. * Check to see if we're still in bounds. If not, there's a problem
  408. * with internal_name (invalid format).
  409. */
  410. if (required_length > internal_name_length) {
  411. ACPI_ERROR((AE_INFO, "Invalid internal name"));
  412. return_ACPI_STATUS(AE_BAD_PATHNAME);
  413. }
  414. /* Build the converted_name */
  415. *converted_name = ACPI_ALLOCATE_ZEROED(required_length);
  416. if (!(*converted_name)) {
  417. return_ACPI_STATUS(AE_NO_MEMORY);
  418. }
  419. j = 0;
  420. for (i = 0; i < prefix_length; i++) {
  421. (*converted_name)[j++] = internal_name[i];
  422. }
  423. if (num_segments > 0) {
  424. for (i = 0; i < num_segments; i++) {
  425. if (i > 0) {
  426. (*converted_name)[j++] = '.';
  427. }
  428. /* Copy and validate the 4-char name segment */
  429. ACPI_MOVE_NAME(&(*converted_name)[j],
  430. &internal_name[names_index]);
  431. acpi_ut_repair_name(&(*converted_name)[j]);
  432. j += ACPI_NAME_SIZE;
  433. names_index += ACPI_NAME_SIZE;
  434. }
  435. }
  436. if (converted_name_length) {
  437. *converted_name_length = (u32) required_length;
  438. }
  439. return_ACPI_STATUS(AE_OK);
  440. }
  441. /*******************************************************************************
  442. *
  443. * FUNCTION: acpi_ns_validate_handle
  444. *
  445. * PARAMETERS: handle - Handle to be validated and typecast to a
  446. * namespace node.
  447. *
  448. * RETURN: A pointer to a namespace node
  449. *
  450. * DESCRIPTION: Convert a namespace handle to a namespace node. Handles special
  451. * cases for the root node.
  452. *
  453. * NOTE: Real integer handles would allow for more verification
  454. * and keep all pointers within this subsystem - however this introduces
  455. * more overhead and has not been necessary to this point. Drivers
  456. * holding handles are typically notified before a node becomes invalid
  457. * due to a table unload.
  458. *
  459. ******************************************************************************/
  460. struct acpi_namespace_node *acpi_ns_validate_handle(acpi_handle handle)
  461. {
  462. ACPI_FUNCTION_ENTRY();
  463. /* Parameter validation */
  464. if ((!handle) || (handle == ACPI_ROOT_OBJECT)) {
  465. return (acpi_gbl_root_node);
  466. }
  467. /* We can at least attempt to verify the handle */
  468. if (ACPI_GET_DESCRIPTOR_TYPE(handle) != ACPI_DESC_TYPE_NAMED) {
  469. return (NULL);
  470. }
  471. return (ACPI_CAST_PTR(struct acpi_namespace_node, handle));
  472. }
  473. /*******************************************************************************
  474. *
  475. * FUNCTION: acpi_ns_terminate
  476. *
  477. * PARAMETERS: none
  478. *
  479. * RETURN: none
  480. *
  481. * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
  482. *
  483. ******************************************************************************/
  484. void acpi_ns_terminate(void)
  485. {
  486. acpi_status status;
  487. union acpi_operand_object *prev;
  488. union acpi_operand_object *next;
  489. ACPI_FUNCTION_TRACE(ns_terminate);
  490. /* Delete any module-level code blocks */
  491. next = acpi_gbl_module_code_list;
  492. while (next) {
  493. prev = next;
  494. next = next->method.mutex;
  495. prev->method.mutex = NULL; /* Clear the Mutex (cheated) field */
  496. acpi_ut_remove_reference(prev);
  497. }
  498. /*
  499. * Free the entire namespace -- all nodes and all objects
  500. * attached to the nodes
  501. */
  502. acpi_ns_delete_namespace_subtree(acpi_gbl_root_node);
  503. /* Delete any objects attached to the root node */
  504. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  505. if (ACPI_FAILURE(status)) {
  506. return_VOID;
  507. }
  508. acpi_ns_delete_node(acpi_gbl_root_node);
  509. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  510. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n"));
  511. return_VOID;
  512. }
  513. /*******************************************************************************
  514. *
  515. * FUNCTION: acpi_ns_opens_scope
  516. *
  517. * PARAMETERS: type - A valid namespace type
  518. *
  519. * RETURN: NEWSCOPE if the passed type "opens a name scope" according
  520. * to the ACPI specification, else 0
  521. *
  522. ******************************************************************************/
  523. u32 acpi_ns_opens_scope(acpi_object_type type)
  524. {
  525. ACPI_FUNCTION_ENTRY();
  526. if (type > ACPI_TYPE_LOCAL_MAX) {
  527. /* type code out of range */
  528. ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type));
  529. return (ACPI_NS_NORMAL);
  530. }
  531. return (((u32)acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE);
  532. }
  533. /*******************************************************************************
  534. *
  535. * FUNCTION: acpi_ns_get_node_unlocked
  536. *
  537. * PARAMETERS: *pathname - Name to be found, in external (ASL) format. The
  538. * \ (backslash) and ^ (carat) prefixes, and the
  539. * . (period) to separate segments are supported.
  540. * prefix_node - Root of subtree to be searched, or NS_ALL for the
  541. * root of the name space. If Name is fully
  542. * qualified (first s8 is '\'), the passed value
  543. * of Scope will not be accessed.
  544. * flags - Used to indicate whether to perform upsearch or
  545. * not.
  546. * return_node - Where the Node is returned
  547. *
  548. * DESCRIPTION: Look up a name relative to a given scope and return the
  549. * corresponding Node. NOTE: Scope can be null.
  550. *
  551. * MUTEX: Doesn't locks namespace
  552. *
  553. ******************************************************************************/
  554. acpi_status
  555. acpi_ns_get_node_unlocked(struct acpi_namespace_node *prefix_node,
  556. const char *pathname,
  557. u32 flags, struct acpi_namespace_node **return_node)
  558. {
  559. union acpi_generic_state scope_info;
  560. acpi_status status;
  561. char *internal_path;
  562. ACPI_FUNCTION_TRACE_PTR(ns_get_node_unlocked,
  563. ACPI_CAST_PTR(char, pathname));
  564. /* Simplest case is a null pathname */
  565. if (!pathname) {
  566. *return_node = prefix_node;
  567. if (!prefix_node) {
  568. *return_node = acpi_gbl_root_node;
  569. }
  570. return_ACPI_STATUS(AE_OK);
  571. }
  572. /* Quick check for a reference to the root */
  573. if (ACPI_IS_ROOT_PREFIX(pathname[0]) && (!pathname[1])) {
  574. *return_node = acpi_gbl_root_node;
  575. return_ACPI_STATUS(AE_OK);
  576. }
  577. /* Convert path to internal representation */
  578. status = acpi_ns_internalize_name(pathname, &internal_path);
  579. if (ACPI_FAILURE(status)) {
  580. return_ACPI_STATUS(status);
  581. }
  582. /* Setup lookup scope (search starting point) */
  583. scope_info.scope.node = prefix_node;
  584. /* Lookup the name in the namespace */
  585. status = acpi_ns_lookup(&scope_info, internal_path, ACPI_TYPE_ANY,
  586. ACPI_IMODE_EXECUTE,
  587. (flags | ACPI_NS_DONT_OPEN_SCOPE), NULL,
  588. return_node);
  589. if (ACPI_FAILURE(status)) {
  590. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s, %s\n",
  591. pathname, acpi_format_exception(status)));
  592. }
  593. ACPI_FREE(internal_path);
  594. return_ACPI_STATUS(status);
  595. }
  596. /*******************************************************************************
  597. *
  598. * FUNCTION: acpi_ns_get_node
  599. *
  600. * PARAMETERS: *pathname - Name to be found, in external (ASL) format. The
  601. * \ (backslash) and ^ (carat) prefixes, and the
  602. * . (period) to separate segments are supported.
  603. * prefix_node - Root of subtree to be searched, or NS_ALL for the
  604. * root of the name space. If Name is fully
  605. * qualified (first s8 is '\'), the passed value
  606. * of Scope will not be accessed.
  607. * flags - Used to indicate whether to perform upsearch or
  608. * not.
  609. * return_node - Where the Node is returned
  610. *
  611. * DESCRIPTION: Look up a name relative to a given scope and return the
  612. * corresponding Node. NOTE: Scope can be null.
  613. *
  614. * MUTEX: Locks namespace
  615. *
  616. ******************************************************************************/
  617. acpi_status
  618. acpi_ns_get_node(struct acpi_namespace_node *prefix_node,
  619. const char *pathname,
  620. u32 flags, struct acpi_namespace_node **return_node)
  621. {
  622. acpi_status status;
  623. ACPI_FUNCTION_TRACE_PTR(ns_get_node, ACPI_CAST_PTR(char, pathname));
  624. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  625. if (ACPI_FAILURE(status)) {
  626. return_ACPI_STATUS(status);
  627. }
  628. status = acpi_ns_get_node_unlocked(prefix_node, pathname,
  629. flags, return_node);
  630. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  631. return_ACPI_STATUS(status);
  632. }