nsutils.c 28 KB

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