nsutils.c 21 KB

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