rsxface.c 14 KB

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