nsutils.c 21 KB

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