rsxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_get_irq_routing_table
  50. *
  51. * PARAMETERS: device_handle - a handle to the Bus device we are querying
  52. * ret_buffer - a pointer to a buffer to receive the
  53. * current resources for the device
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: This function is called to get the IRQ routing table for a
  58. * specific bus. The caller must first acquire a handle for the
  59. * desired bus. The routine table is placed in the buffer pointed
  60. * to by the ret_buffer variable parameter.
  61. *
  62. * If the function fails an appropriate status will be returned
  63. * and the value of ret_buffer is undefined.
  64. *
  65. * This function attempts to execute the _PRT method contained in
  66. * the object indicated by the passed device_handle.
  67. *
  68. ******************************************************************************/
  69. acpi_status
  70. acpi_get_irq_routing_table (
  71. acpi_handle device_handle,
  72. struct acpi_buffer *ret_buffer)
  73. {
  74. acpi_status status;
  75. ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table ");
  76. /*
  77. * Must have a valid handle and buffer, So we have to have a handle
  78. * and a return buffer structure, and if there is a non-zero buffer length
  79. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  80. * we'll be returning the needed buffer size, so keep going.
  81. */
  82. if (!device_handle) {
  83. return_ACPI_STATUS (AE_BAD_PARAMETER);
  84. }
  85. status = acpi_ut_validate_buffer (ret_buffer);
  86. if (ACPI_FAILURE (status)) {
  87. return_ACPI_STATUS (status);
  88. }
  89. status = acpi_rs_get_prt_method_data (device_handle, ret_buffer);
  90. return_ACPI_STATUS (status);
  91. }
  92. /*******************************************************************************
  93. *
  94. * FUNCTION: acpi_get_current_resources
  95. *
  96. * PARAMETERS: device_handle - a handle to the device object for the
  97. * device we are querying
  98. * ret_buffer - a pointer to a buffer to receive the
  99. * current resources for the device
  100. *
  101. * RETURN: Status
  102. *
  103. * DESCRIPTION: This function is called to get the current resources for a
  104. * specific device. The caller must first acquire a handle for
  105. * the desired device. The resource data is placed in the buffer
  106. * pointed to by the ret_buffer variable parameter.
  107. *
  108. * If the function fails an appropriate status will be returned
  109. * and the value of ret_buffer is undefined.
  110. *
  111. * This function attempts to execute the _CRS method contained in
  112. * the object indicated by the passed device_handle.
  113. *
  114. ******************************************************************************/
  115. acpi_status
  116. acpi_get_current_resources (
  117. acpi_handle device_handle,
  118. struct acpi_buffer *ret_buffer)
  119. {
  120. acpi_status status;
  121. ACPI_FUNCTION_TRACE ("acpi_get_current_resources");
  122. /*
  123. * Must have a valid handle and buffer, So we have to have a handle
  124. * and a return buffer structure, and if there is a non-zero buffer length
  125. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  126. * we'll be returning the needed buffer size, so keep going.
  127. */
  128. if (!device_handle) {
  129. return_ACPI_STATUS (AE_BAD_PARAMETER);
  130. }
  131. status = acpi_ut_validate_buffer (ret_buffer);
  132. if (ACPI_FAILURE (status)) {
  133. return_ACPI_STATUS (status);
  134. }
  135. status = acpi_rs_get_crs_method_data (device_handle, ret_buffer);
  136. return_ACPI_STATUS (status);
  137. }
  138. EXPORT_SYMBOL(acpi_get_current_resources);
  139. /*******************************************************************************
  140. *
  141. * FUNCTION: acpi_get_possible_resources
  142. *
  143. * PARAMETERS: device_handle - a handle to the device object for the
  144. * device we are querying
  145. * ret_buffer - a pointer to a buffer to receive the
  146. * resources for the device
  147. *
  148. * RETURN: Status
  149. *
  150. * DESCRIPTION: This function is called to get a list of the possible resources
  151. * for a specific device. The caller must first acquire a handle
  152. * for the desired device. The resource data is placed in the
  153. * buffer pointed to by the ret_buffer variable.
  154. *
  155. * If the function fails an appropriate status will be returned
  156. * and the value of ret_buffer is undefined.
  157. *
  158. ******************************************************************************/
  159. #ifdef ACPI_FUTURE_USAGE
  160. acpi_status
  161. acpi_get_possible_resources (
  162. acpi_handle device_handle,
  163. struct acpi_buffer *ret_buffer)
  164. {
  165. acpi_status status;
  166. ACPI_FUNCTION_TRACE ("acpi_get_possible_resources");
  167. /*
  168. * Must have a valid handle and buffer, So we have to have a handle
  169. * and a return buffer structure, and if there is a non-zero buffer length
  170. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  171. * we'll be returning the needed buffer size, so keep going.
  172. */
  173. if (!device_handle) {
  174. return_ACPI_STATUS (AE_BAD_PARAMETER);
  175. }
  176. status = acpi_ut_validate_buffer (ret_buffer);
  177. if (ACPI_FAILURE (status)) {
  178. return_ACPI_STATUS (status);
  179. }
  180. status = acpi_rs_get_prs_method_data (device_handle, ret_buffer);
  181. return_ACPI_STATUS (status);
  182. }
  183. EXPORT_SYMBOL(acpi_get_possible_resources);
  184. #endif /* ACPI_FUTURE_USAGE */
  185. /*******************************************************************************
  186. *
  187. * FUNCTION: acpi_walk_resources
  188. *
  189. * PARAMETERS: device_handle - a handle to the device object for the
  190. * device we are querying
  191. * Path - method name of the resources we want
  192. * (METHOD_NAME__CRS or METHOD_NAME__PRS)
  193. * user_function - called for each resource
  194. * Context - passed to user_function
  195. *
  196. * RETURN: Status
  197. *
  198. * DESCRIPTION: Retrieves the current or possible resource list for the
  199. * specified device. The user_function is called once for
  200. * each resource in the list.
  201. *
  202. ******************************************************************************/
  203. acpi_status
  204. acpi_walk_resources (
  205. acpi_handle device_handle,
  206. char *path,
  207. ACPI_WALK_RESOURCE_CALLBACK user_function,
  208. void *context)
  209. {
  210. acpi_status status;
  211. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  212. struct acpi_resource *resource;
  213. struct acpi_resource *buffer_end;
  214. ACPI_FUNCTION_TRACE ("acpi_walk_resources");
  215. if (!device_handle ||
  216. (ACPI_STRNCMP (path, METHOD_NAME__CRS, sizeof (METHOD_NAME__CRS)) &&
  217. ACPI_STRNCMP (path, METHOD_NAME__PRS, sizeof (METHOD_NAME__PRS)))) {
  218. return_ACPI_STATUS (AE_BAD_PARAMETER);
  219. }
  220. status = acpi_rs_get_method_data (device_handle, path, &buffer);
  221. if (ACPI_FAILURE (status)) {
  222. return_ACPI_STATUS (status);
  223. }
  224. /* Setup pointers */
  225. resource = (struct acpi_resource *) buffer.pointer;
  226. buffer_end = ACPI_CAST_PTR (struct acpi_resource,
  227. ((u8 *) buffer.pointer + buffer.length));
  228. /* Walk the resource list */
  229. for (;;) {
  230. if (!resource || resource->id == ACPI_RSTYPE_END_TAG) {
  231. break;
  232. }
  233. status = user_function (resource, context);
  234. switch (status) {
  235. case AE_OK:
  236. case AE_CTRL_DEPTH:
  237. /* Just keep going */
  238. status = AE_OK;
  239. break;
  240. case AE_CTRL_TERMINATE:
  241. /* Exit now, with OK stats */
  242. status = AE_OK;
  243. goto cleanup;
  244. default:
  245. /* All others are valid exceptions */
  246. goto cleanup;
  247. }
  248. /* Get the next resource descriptor */
  249. resource = ACPI_NEXT_RESOURCE (resource);
  250. /* Check for end-of-buffer */
  251. if (resource >= buffer_end) {
  252. goto cleanup;
  253. }
  254. }
  255. cleanup:
  256. acpi_os_free (buffer.pointer);
  257. return_ACPI_STATUS (status);
  258. }
  259. EXPORT_SYMBOL(acpi_walk_resources);
  260. /*******************************************************************************
  261. *
  262. * FUNCTION: acpi_set_current_resources
  263. *
  264. * PARAMETERS: device_handle - a handle to the device object for the
  265. * device we are changing the resources of
  266. * in_buffer - a pointer to a buffer containing the
  267. * resources to be set for the device
  268. *
  269. * RETURN: Status
  270. *
  271. * DESCRIPTION: This function is called to set the current resources for a
  272. * specific device. The caller must first acquire a handle for
  273. * the desired device. The resource data is passed to the routine
  274. * the buffer pointed to by the in_buffer variable.
  275. *
  276. ******************************************************************************/
  277. acpi_status
  278. acpi_set_current_resources (
  279. acpi_handle device_handle,
  280. struct acpi_buffer *in_buffer)
  281. {
  282. acpi_status status;
  283. ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
  284. /*
  285. * Must have a valid handle and buffer
  286. */
  287. if ((!device_handle) ||
  288. (!in_buffer) ||
  289. (!in_buffer->pointer) ||
  290. (!in_buffer->length)) {
  291. return_ACPI_STATUS (AE_BAD_PARAMETER);
  292. }
  293. status = acpi_rs_set_srs_method_data (device_handle, in_buffer);
  294. return_ACPI_STATUS (status);
  295. }
  296. EXPORT_SYMBOL(acpi_set_current_resources);
  297. #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
  298. #define ACPI_COPY_ADDRESS(out, in) \
  299. ACPI_COPY_FIELD(out, in, resource_type); \
  300. ACPI_COPY_FIELD(out, in, producer_consumer); \
  301. ACPI_COPY_FIELD(out, in, decode); \
  302. ACPI_COPY_FIELD(out, in, min_address_fixed); \
  303. ACPI_COPY_FIELD(out, in, max_address_fixed); \
  304. ACPI_COPY_FIELD(out, in, attribute); \
  305. ACPI_COPY_FIELD(out, in, granularity); \
  306. ACPI_COPY_FIELD(out, in, min_address_range); \
  307. ACPI_COPY_FIELD(out, in, max_address_range); \
  308. ACPI_COPY_FIELD(out, in, address_translation_offset); \
  309. ACPI_COPY_FIELD(out, in, address_length); \
  310. ACPI_COPY_FIELD(out, in, resource_source);
  311. /******************************************************************************
  312. *
  313. * FUNCTION: acpi_resource_to_address64
  314. *
  315. * PARAMETERS: resource - Pointer to a resource
  316. * out - Pointer to the users's return
  317. * buffer (a struct
  318. * struct acpi_resource_address64)
  319. *
  320. * RETURN: Status
  321. *
  322. * DESCRIPTION: If the resource is an address16, address32, or address64,
  323. * copy it to the address64 return buffer. This saves the
  324. * caller from having to duplicate code for different-sized
  325. * addresses.
  326. *
  327. ******************************************************************************/
  328. acpi_status
  329. acpi_resource_to_address64 (
  330. struct acpi_resource *resource,
  331. struct acpi_resource_address64 *out)
  332. {
  333. struct acpi_resource_address16 *address16;
  334. struct acpi_resource_address32 *address32;
  335. switch (resource->id) {
  336. case ACPI_RSTYPE_ADDRESS16:
  337. address16 = (struct acpi_resource_address16 *) &resource->data;
  338. ACPI_COPY_ADDRESS(out, address16);
  339. break;
  340. case ACPI_RSTYPE_ADDRESS32:
  341. address32 = (struct acpi_resource_address32 *) &resource->data;
  342. ACPI_COPY_ADDRESS(out, address32);
  343. break;
  344. case ACPI_RSTYPE_ADDRESS64:
  345. /* Simple copy for 64 bit source */
  346. ACPI_MEMCPY (out, &resource->data, sizeof (struct acpi_resource_address64));
  347. break;
  348. default:
  349. return (AE_BAD_PARAMETER);
  350. }
  351. return (AE_OK);
  352. }
  353. EXPORT_SYMBOL(acpi_resource_to_address64);