nsutils.c 20 KB

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