nsxfname.c 9.8 KB

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