nsxfname.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 "accommon.h"
  45. #include "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. prefix_node = acpi_ns_map_handle_to_node(parent);
  80. if (!prefix_node) {
  81. return (AE_BAD_PARAMETER);
  82. }
  83. }
  84. /*
  85. * Valid cases are:
  86. * 1) Fully qualified pathname
  87. * 2) Parent + Relative pathname
  88. *
  89. * Error for <null Parent + relative path>
  90. */
  91. if (acpi_ns_valid_root_prefix(pathname[0])) {
  92. /* Pathname is fully qualified (starts with '\') */
  93. /* Special case for root-only, since we can't search for it */
  94. if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
  95. *ret_handle =
  96. acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
  97. return (AE_OK);
  98. }
  99. } else if (!prefix_node) {
  100. /* Relative path with null prefix is disallowed */
  101. return (AE_BAD_PARAMETER);
  102. }
  103. /* Find the Node and convert to a handle */
  104. status =
  105. acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
  106. if (ACPI_SUCCESS(status)) {
  107. *ret_handle = acpi_ns_convert_entry_to_handle(node);
  108. }
  109. return (status);
  110. }
  111. ACPI_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. ACPI_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_ALLOCATE_ZEROED(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. status = AE_BAD_PARAMETER;
  216. goto cleanup;
  217. }
  218. /* Init return structure */
  219. size = sizeof(struct acpi_device_info);
  220. info->type = node->type;
  221. info->name = node->name.integer;
  222. info->valid = 0;
  223. if (node->type == ACPI_TYPE_METHOD) {
  224. info->param_count = node->object->method.param_count;
  225. }
  226. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  227. if (ACPI_FAILURE(status)) {
  228. goto cleanup;
  229. }
  230. /* If not a device, we are all done */
  231. if (info->type == ACPI_TYPE_DEVICE) {
  232. /*
  233. * Get extra info for ACPI Devices objects only:
  234. * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
  235. *
  236. * Note: none of these methods are required, so they may or may
  237. * not be present for this device. The Info->Valid bitfield is used
  238. * to indicate which methods were found and ran successfully.
  239. */
  240. /* Execute the Device._HID method */
  241. status = acpi_ut_execute_HID(node, &info->hardware_id);
  242. if (ACPI_SUCCESS(status)) {
  243. info->valid |= ACPI_VALID_HID;
  244. }
  245. /* Execute the Device._UID method */
  246. status = acpi_ut_execute_UID(node, &info->unique_id);
  247. if (ACPI_SUCCESS(status)) {
  248. info->valid |= ACPI_VALID_UID;
  249. }
  250. /* Execute the Device._CID method */
  251. status = acpi_ut_execute_CID(node, &cid_list);
  252. if (ACPI_SUCCESS(status)) {
  253. size += cid_list->size;
  254. info->valid |= ACPI_VALID_CID;
  255. }
  256. /* Execute the Device._STA method */
  257. status = acpi_ut_execute_STA(node, &info->current_status);
  258. if (ACPI_SUCCESS(status)) {
  259. info->valid |= ACPI_VALID_STA;
  260. }
  261. /* Execute the Device._ADR method */
  262. status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
  263. &info->address);
  264. if (ACPI_SUCCESS(status)) {
  265. info->valid |= ACPI_VALID_ADR;
  266. }
  267. /* Execute the Device._sx_d methods */
  268. status = acpi_ut_execute_sxds(node, info->highest_dstates);
  269. if (ACPI_SUCCESS(status)) {
  270. info->valid |= ACPI_VALID_SXDS;
  271. }
  272. }
  273. /* Validate/Allocate/Clear caller buffer */
  274. status = acpi_ut_initialize_buffer(buffer, size);
  275. if (ACPI_FAILURE(status)) {
  276. goto cleanup;
  277. }
  278. /* Populate the return buffer */
  279. return_info = buffer->pointer;
  280. ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
  281. if (cid_list) {
  282. ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
  283. cid_list->size);
  284. }
  285. cleanup:
  286. ACPI_FREE(info);
  287. if (cid_list) {
  288. ACPI_FREE(cid_list);
  289. }
  290. return (status);
  291. }
  292. ACPI_EXPORT_SYMBOL(acpi_get_object_info)