nsxfname.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /******************************************************************************
  2. *
  3. * Module Name: nsxfname - Public interfaces to the ACPI subsystem
  4. * ACPI Namespace oriented interfaces
  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 <linux/module.h>
  44. #include <acpi/acpi.h>
  45. #include <acpi/acnamesp.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME ("nsxfname")
  48. /******************************************************************************
  49. *
  50. * FUNCTION: acpi_get_handle
  51. *
  52. * PARAMETERS: Parent - Object to search under (search scope).
  53. * path_name - Pointer to an asciiz string containing the
  54. * name
  55. * ret_handle - Where the return handle is placed
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: This routine will search for a caller specified name in the
  60. * name space. The caller can restrict the search region by
  61. * specifying a non NULL parent. The parent value is itself a
  62. * namespace handle.
  63. *
  64. ******************************************************************************/
  65. acpi_status
  66. acpi_get_handle (
  67. acpi_handle parent,
  68. acpi_string pathname,
  69. acpi_handle *ret_handle)
  70. {
  71. acpi_status status;
  72. struct acpi_namespace_node *node = NULL;
  73. struct acpi_namespace_node *prefix_node = NULL;
  74. ACPI_FUNCTION_ENTRY ();
  75. /* Parameter Validation */
  76. if (!ret_handle || !pathname) {
  77. return (AE_BAD_PARAMETER);
  78. }
  79. /* Convert a parent handle to a prefix node */
  80. if (parent) {
  81. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  82. if (ACPI_FAILURE (status)) {
  83. return (status);
  84. }
  85. prefix_node = acpi_ns_map_handle_to_node (parent);
  86. if (!prefix_node) {
  87. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  88. return (AE_BAD_PARAMETER);
  89. }
  90. status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  91. if (ACPI_FAILURE (status)) {
  92. return (status);
  93. }
  94. }
  95. /* Special case for root, since we can't search for it */
  96. if (ACPI_STRCMP (pathname, ACPI_NS_ROOT_PATH) == 0) {
  97. *ret_handle = acpi_ns_convert_entry_to_handle (acpi_gbl_root_node);
  98. return (AE_OK);
  99. }
  100. /*
  101. * Find the Node and convert to a handle
  102. */
  103. status = acpi_ns_get_node_by_path (pathname, prefix_node, ACPI_NS_NO_UPSEARCH,
  104. &node);
  105. *ret_handle = NULL;
  106. if (ACPI_SUCCESS (status)) {
  107. *ret_handle = acpi_ns_convert_entry_to_handle (node);
  108. }
  109. return (status);
  110. }
  111. EXPORT_SYMBOL(acpi_get_handle);
  112. /******************************************************************************
  113. *
  114. * FUNCTION: acpi_get_name
  115. *
  116. * PARAMETERS: Handle - Handle to be converted to a pathname
  117. * name_type - Full pathname or single segment
  118. * Buffer - Buffer for returned path
  119. *
  120. * RETURN: Pointer to a string containing the fully qualified Name.
  121. *
  122. * DESCRIPTION: This routine returns the fully qualified name associated with
  123. * the Handle parameter. This and the acpi_pathname_to_handle are
  124. * complementary functions.
  125. *
  126. ******************************************************************************/
  127. acpi_status
  128. acpi_get_name (
  129. acpi_handle handle,
  130. u32 name_type,
  131. struct acpi_buffer *buffer)
  132. {
  133. acpi_status status;
  134. struct acpi_namespace_node *node;
  135. /* Parameter validation */
  136. if (name_type > ACPI_NAME_TYPE_MAX) {
  137. return (AE_BAD_PARAMETER);
  138. }
  139. status = acpi_ut_validate_buffer (buffer);
  140. if (ACPI_FAILURE (status)) {
  141. return (status);
  142. }
  143. if (name_type == ACPI_FULL_PATHNAME) {
  144. /* Get the full pathname (From the namespace root) */
  145. status = acpi_ns_handle_to_pathname (handle, buffer);
  146. return (status);
  147. }
  148. /*
  149. * Wants the single segment ACPI name.
  150. * Validate handle and convert to a namespace Node
  151. */
  152. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  153. if (ACPI_FAILURE (status)) {
  154. return (status);
  155. }
  156. node = acpi_ns_map_handle_to_node (handle);
  157. if (!node) {
  158. status = AE_BAD_PARAMETER;
  159. goto unlock_and_exit;
  160. }
  161. /* Validate/Allocate/Clear caller buffer */
  162. status = acpi_ut_initialize_buffer (buffer, ACPI_PATH_SEGMENT_LENGTH);
  163. if (ACPI_FAILURE (status)) {
  164. goto unlock_and_exit;
  165. }
  166. /* Just copy the ACPI name from the Node and zero terminate it */
  167. ACPI_STRNCPY (buffer->pointer, acpi_ut_get_node_name (node),
  168. ACPI_NAME_SIZE);
  169. ((char *) buffer->pointer) [ACPI_NAME_SIZE] = 0;
  170. status = AE_OK;
  171. unlock_and_exit:
  172. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  173. return (status);
  174. }
  175. EXPORT_SYMBOL(acpi_get_name);
  176. /******************************************************************************
  177. *
  178. * FUNCTION: acpi_get_object_info
  179. *
  180. * PARAMETERS: Handle - Object Handle
  181. * Info - Where the info is returned
  182. *
  183. * RETURN: Status
  184. *
  185. * DESCRIPTION: Returns information about an object as gleaned from the
  186. * namespace node and possibly by running several standard
  187. * control methods (Such as in the case of a device.)
  188. *
  189. ******************************************************************************/
  190. acpi_status
  191. acpi_get_object_info (
  192. acpi_handle handle,
  193. struct acpi_buffer *buffer)
  194. {
  195. acpi_status status;
  196. struct acpi_namespace_node *node;
  197. struct acpi_device_info *info;
  198. struct acpi_device_info *return_info;
  199. struct acpi_compatible_id_list *cid_list = NULL;
  200. acpi_size size;
  201. /* Parameter validation */
  202. if (!handle || !buffer) {
  203. return (AE_BAD_PARAMETER);
  204. }
  205. status = acpi_ut_validate_buffer (buffer);
  206. if (ACPI_FAILURE (status)) {
  207. return (status);
  208. }
  209. info = ACPI_MEM_CALLOCATE (sizeof (struct acpi_device_info));
  210. if (!info) {
  211. return (AE_NO_MEMORY);
  212. }
  213. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  214. if (ACPI_FAILURE (status)) {
  215. goto cleanup;
  216. }
  217. node = acpi_ns_map_handle_to_node (handle);
  218. if (!node) {
  219. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  220. goto cleanup;
  221. }
  222. /* Init return structure */
  223. size = sizeof (struct acpi_device_info);
  224. info->type = node->type;
  225. info->name = node->name.integer;
  226. info->valid = 0;
  227. status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  228. if (ACPI_FAILURE (status)) {
  229. goto cleanup;
  230. }
  231. /* If not a device, we are all done */
  232. if (info->type == ACPI_TYPE_DEVICE) {
  233. /*
  234. * Get extra info for ACPI Devices objects only:
  235. * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
  236. *
  237. * Note: none of these methods are required, so they may or may
  238. * not be present for this device. The Info->Valid bitfield is used
  239. * to indicate which methods were found and ran successfully.
  240. */
  241. /* Execute the Device._HID method */
  242. status = acpi_ut_execute_HID (node, &info->hardware_id);
  243. if (ACPI_SUCCESS (status)) {
  244. info->valid |= ACPI_VALID_HID;
  245. }
  246. /* Execute the Device._UID method */
  247. status = acpi_ut_execute_UID (node, &info->unique_id);
  248. if (ACPI_SUCCESS (status)) {
  249. info->valid |= ACPI_VALID_UID;
  250. }
  251. /* Execute the Device._CID method */
  252. status = acpi_ut_execute_CID (node, &cid_list);
  253. if (ACPI_SUCCESS (status)) {
  254. size += ((acpi_size) cid_list->count - 1) *
  255. sizeof (struct acpi_compatible_id);
  256. info->valid |= ACPI_VALID_CID;
  257. }
  258. /* Execute the Device._STA method */
  259. status = acpi_ut_execute_STA (node, &info->current_status);
  260. if (ACPI_SUCCESS (status)) {
  261. info->valid |= ACPI_VALID_STA;
  262. }
  263. /* Execute the Device._ADR method */
  264. status = acpi_ut_evaluate_numeric_object (METHOD_NAME__ADR, node,
  265. &info->address);
  266. if (ACPI_SUCCESS (status)) {
  267. info->valid |= ACPI_VALID_ADR;
  268. }
  269. /* Execute the Device._sx_d methods */
  270. status = acpi_ut_execute_sxds (node, info->highest_dstates);
  271. if (ACPI_SUCCESS (status)) {
  272. info->valid |= ACPI_VALID_SXDS;
  273. }
  274. }
  275. /* Validate/Allocate/Clear caller buffer */
  276. status = acpi_ut_initialize_buffer (buffer, size);
  277. if (ACPI_FAILURE (status)) {
  278. goto cleanup;
  279. }
  280. /* Populate the return buffer */
  281. return_info = buffer->pointer;
  282. ACPI_MEMCPY (return_info, info, sizeof (struct acpi_device_info));
  283. if (cid_list) {
  284. ACPI_MEMCPY (&return_info->compatibility_id, cid_list, cid_list->size);
  285. }
  286. cleanup:
  287. ACPI_MEM_FREE (info);
  288. if (cid_list) {
  289. ACPI_MEM_FREE (cid_list);
  290. }
  291. return (status);
  292. }
  293. EXPORT_SYMBOL(acpi_get_object_info);