rsxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsxface - Public interfaces to the resource manager
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <linux/module.h>
  43. #include <acpi/acpi.h>
  44. #include <acpi/acresrc.h>
  45. #define _COMPONENT ACPI_RESOURCES
  46. ACPI_MODULE_NAME ("rsxface")
  47. /* Local macros for 16,32-bit to 64-bit conversion */
  48. #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
  49. #define ACPI_COPY_ADDRESS(out, in) \
  50. ACPI_COPY_FIELD(out, in, resource_type); \
  51. ACPI_COPY_FIELD(out, in, producer_consumer); \
  52. ACPI_COPY_FIELD(out, in, decode); \
  53. ACPI_COPY_FIELD(out, in, min_address_fixed); \
  54. ACPI_COPY_FIELD(out, in, max_address_fixed); \
  55. ACPI_COPY_FIELD(out, in, attribute); \
  56. ACPI_COPY_FIELD(out, in, granularity); \
  57. ACPI_COPY_FIELD(out, in, min_address_range); \
  58. ACPI_COPY_FIELD(out, in, max_address_range); \
  59. ACPI_COPY_FIELD(out, in, address_translation_offset); \
  60. ACPI_COPY_FIELD(out, in, address_length); \
  61. ACPI_COPY_FIELD(out, in, resource_source);
  62. /*******************************************************************************
  63. *
  64. * FUNCTION: acpi_get_irq_routing_table
  65. *
  66. * PARAMETERS: device_handle - a handle to the Bus device we are querying
  67. * ret_buffer - a pointer to a buffer to receive the
  68. * current resources for the device
  69. *
  70. * RETURN: Status
  71. *
  72. * DESCRIPTION: This function is called to get the IRQ routing table for a
  73. * specific bus. The caller must first acquire a handle for the
  74. * desired bus. The routine table is placed in the buffer pointed
  75. * to by the ret_buffer variable parameter.
  76. *
  77. * If the function fails an appropriate status will be returned
  78. * and the value of ret_buffer is undefined.
  79. *
  80. * This function attempts to execute the _PRT method contained in
  81. * the object indicated by the passed device_handle.
  82. *
  83. ******************************************************************************/
  84. acpi_status
  85. acpi_get_irq_routing_table (
  86. acpi_handle device_handle,
  87. struct acpi_buffer *ret_buffer)
  88. {
  89. acpi_status status;
  90. ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table ");
  91. /*
  92. * Must have a valid handle and buffer, So we have to have a handle
  93. * and a return buffer structure, and if there is a non-zero buffer length
  94. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  95. * we'll be returning the needed buffer size, so keep going.
  96. */
  97. if (!device_handle) {
  98. return_ACPI_STATUS (AE_BAD_PARAMETER);
  99. }
  100. status = acpi_ut_validate_buffer (ret_buffer);
  101. if (ACPI_FAILURE (status)) {
  102. return_ACPI_STATUS (status);
  103. }
  104. status = acpi_rs_get_prt_method_data (device_handle, ret_buffer);
  105. return_ACPI_STATUS (status);
  106. }
  107. /*******************************************************************************
  108. *
  109. * FUNCTION: acpi_get_current_resources
  110. *
  111. * PARAMETERS: device_handle - a handle to the device object for the
  112. * device we are querying
  113. * ret_buffer - a pointer to a buffer to receive the
  114. * current resources for the device
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: This function is called to get the current resources for a
  119. * specific device. The caller must first acquire a handle for
  120. * the desired device. The resource data is placed in the buffer
  121. * pointed to by the ret_buffer variable parameter.
  122. *
  123. * If the function fails an appropriate status will be returned
  124. * and the value of ret_buffer is undefined.
  125. *
  126. * This function attempts to execute the _CRS method contained in
  127. * the object indicated by the passed device_handle.
  128. *
  129. ******************************************************************************/
  130. acpi_status
  131. acpi_get_current_resources (
  132. acpi_handle device_handle,
  133. struct acpi_buffer *ret_buffer)
  134. {
  135. acpi_status status;
  136. ACPI_FUNCTION_TRACE ("acpi_get_current_resources");
  137. /*
  138. * Must have a valid handle and buffer, So we have to have a handle
  139. * and a return buffer structure, and if there is a non-zero buffer length
  140. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  141. * we'll be returning the needed buffer size, so keep going.
  142. */
  143. if (!device_handle) {
  144. return_ACPI_STATUS (AE_BAD_PARAMETER);
  145. }
  146. status = acpi_ut_validate_buffer (ret_buffer);
  147. if (ACPI_FAILURE (status)) {
  148. return_ACPI_STATUS (status);
  149. }
  150. status = acpi_rs_get_crs_method_data (device_handle, ret_buffer);
  151. return_ACPI_STATUS (status);
  152. }
  153. EXPORT_SYMBOL(acpi_get_current_resources);
  154. /*******************************************************************************
  155. *
  156. * FUNCTION: acpi_get_possible_resources
  157. *
  158. * PARAMETERS: device_handle - a handle to the device object for the
  159. * device we are querying
  160. * ret_buffer - a pointer to a buffer to receive the
  161. * resources for the device
  162. *
  163. * RETURN: Status
  164. *
  165. * DESCRIPTION: This function is called to get a list of the possible resources
  166. * for a specific device. The caller must first acquire a handle
  167. * for the desired device. The resource data is placed in the
  168. * buffer pointed to by the ret_buffer variable.
  169. *
  170. * If the function fails an appropriate status will be returned
  171. * and the value of ret_buffer is undefined.
  172. *
  173. ******************************************************************************/
  174. #ifdef ACPI_FUTURE_USAGE
  175. acpi_status
  176. acpi_get_possible_resources (
  177. acpi_handle device_handle,
  178. struct acpi_buffer *ret_buffer)
  179. {
  180. acpi_status status;
  181. ACPI_FUNCTION_TRACE ("acpi_get_possible_resources");
  182. /*
  183. * Must have a valid handle and buffer, So we have to have a handle
  184. * and a return buffer structure, and if there is a non-zero buffer length
  185. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  186. * we'll be returning the needed buffer size, so keep going.
  187. */
  188. if (!device_handle) {
  189. return_ACPI_STATUS (AE_BAD_PARAMETER);
  190. }
  191. status = acpi_ut_validate_buffer (ret_buffer);
  192. if (ACPI_FAILURE (status)) {
  193. return_ACPI_STATUS (status);
  194. }
  195. status = acpi_rs_get_prs_method_data (device_handle, ret_buffer);
  196. return_ACPI_STATUS (status);
  197. }
  198. EXPORT_SYMBOL(acpi_get_possible_resources);
  199. #endif /* ACPI_FUTURE_USAGE */
  200. /*******************************************************************************
  201. *
  202. * FUNCTION: acpi_walk_resources
  203. *
  204. * PARAMETERS: device_handle - a handle to the device object for the
  205. * device we are querying
  206. * Path - method name of the resources we want
  207. * (METHOD_NAME__CRS or METHOD_NAME__PRS)
  208. * user_function - called for each resource
  209. * Context - passed to user_function
  210. *
  211. * RETURN: Status
  212. *
  213. * DESCRIPTION: Retrieves the current or possible resource list for the
  214. * specified device. The user_function is called once for
  215. * each resource in the list.
  216. *
  217. ******************************************************************************/
  218. acpi_status
  219. acpi_walk_resources (
  220. acpi_handle device_handle,
  221. char *path,
  222. ACPI_WALK_RESOURCE_CALLBACK user_function,
  223. void *context)
  224. {
  225. acpi_status status;
  226. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  227. struct acpi_resource *resource;
  228. struct acpi_resource *buffer_end;
  229. ACPI_FUNCTION_TRACE ("acpi_walk_resources");
  230. if (!device_handle ||
  231. (ACPI_STRNCMP (path, METHOD_NAME__CRS, sizeof (METHOD_NAME__CRS)) &&
  232. ACPI_STRNCMP (path, METHOD_NAME__PRS, sizeof (METHOD_NAME__PRS)))) {
  233. return_ACPI_STATUS (AE_BAD_PARAMETER);
  234. }
  235. status = acpi_rs_get_method_data (device_handle, path, &buffer);
  236. if (ACPI_FAILURE (status)) {
  237. return_ACPI_STATUS (status);
  238. }
  239. /* Setup pointers */
  240. resource = (struct acpi_resource *) buffer.pointer;
  241. buffer_end = ACPI_CAST_PTR (struct acpi_resource,
  242. ((u8 *) buffer.pointer + buffer.length));
  243. /* Walk the resource list */
  244. for (;;) {
  245. if (!resource || resource->id == ACPI_RSTYPE_END_TAG) {
  246. break;
  247. }
  248. status = user_function (resource, context);
  249. switch (status) {
  250. case AE_OK:
  251. case AE_CTRL_DEPTH:
  252. /* Just keep going */
  253. status = AE_OK;
  254. break;
  255. case AE_CTRL_TERMINATE:
  256. /* Exit now, with OK stats */
  257. status = AE_OK;
  258. goto cleanup;
  259. default:
  260. /* All others are valid exceptions */
  261. goto cleanup;
  262. }
  263. /* Get the next resource descriptor */
  264. resource = ACPI_NEXT_RESOURCE (resource);
  265. /* Check for end-of-buffer */
  266. if (resource >= buffer_end) {
  267. goto cleanup;
  268. }
  269. }
  270. cleanup:
  271. acpi_os_free (buffer.pointer);
  272. return_ACPI_STATUS (status);
  273. }
  274. EXPORT_SYMBOL(acpi_walk_resources);
  275. /*******************************************************************************
  276. *
  277. * FUNCTION: acpi_set_current_resources
  278. *
  279. * PARAMETERS: device_handle - a handle to the device object for the
  280. * device we are changing the resources of
  281. * in_buffer - a pointer to a buffer containing the
  282. * resources to be set for the device
  283. *
  284. * RETURN: Status
  285. *
  286. * DESCRIPTION: This function is called to set the current resources for a
  287. * specific device. The caller must first acquire a handle for
  288. * the desired device. The resource data is passed to the routine
  289. * the buffer pointed to by the in_buffer variable.
  290. *
  291. ******************************************************************************/
  292. acpi_status
  293. acpi_set_current_resources (
  294. acpi_handle device_handle,
  295. struct acpi_buffer *in_buffer)
  296. {
  297. acpi_status status;
  298. ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
  299. /* Must have a valid handle and buffer */
  300. if ((!device_handle) ||
  301. (!in_buffer) ||
  302. (!in_buffer->pointer) ||
  303. (!in_buffer->length)) {
  304. return_ACPI_STATUS (AE_BAD_PARAMETER);
  305. }
  306. status = acpi_rs_set_srs_method_data (device_handle, in_buffer);
  307. return_ACPI_STATUS (status);
  308. }
  309. EXPORT_SYMBOL(acpi_set_current_resources);
  310. /******************************************************************************
  311. *
  312. * FUNCTION: acpi_resource_to_address64
  313. *
  314. * PARAMETERS: resource - Pointer to a resource
  315. * out - Pointer to the users's return
  316. * buffer (a struct
  317. * struct acpi_resource_address64)
  318. *
  319. * RETURN: Status
  320. *
  321. * DESCRIPTION: If the resource is an address16, address32, or address64,
  322. * copy it to the address64 return buffer. This saves the
  323. * caller from having to duplicate code for different-sized
  324. * addresses.
  325. *
  326. ******************************************************************************/
  327. acpi_status
  328. acpi_resource_to_address64 (
  329. struct acpi_resource *resource,
  330. struct acpi_resource_address64 *out)
  331. {
  332. struct acpi_resource_address16 *address16;
  333. struct acpi_resource_address32 *address32;
  334. switch (resource->id) {
  335. case ACPI_RSTYPE_ADDRESS16:
  336. address16 = (struct acpi_resource_address16 *) &resource->data;
  337. ACPI_COPY_ADDRESS (out, address16);
  338. break;
  339. case ACPI_RSTYPE_ADDRESS32:
  340. address32 = (struct acpi_resource_address32 *) &resource->data;
  341. ACPI_COPY_ADDRESS (out, address32);
  342. break;
  343. case ACPI_RSTYPE_ADDRESS64:
  344. /* Simple copy for 64 bit source */
  345. ACPI_MEMCPY (out, &resource->data, sizeof (struct acpi_resource_address64));
  346. break;
  347. default:
  348. return (AE_BAD_PARAMETER);
  349. }
  350. return (AE_OK);
  351. }
  352. EXPORT_SYMBOL(acpi_resource_to_address64);