nsxfname.c 9.8 KB

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