nsxfname.c 9.9 KB

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