nsutils.c 28 KB

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