rsxface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsxface - Public interfaces to the resource manager
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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, info); \
  56. ACPI_COPY_FIELD(out, in, granularity); \
  57. ACPI_COPY_FIELD(out, in, minimum); \
  58. ACPI_COPY_FIELD(out, in, maximum); \
  59. ACPI_COPY_FIELD(out, in, translation_offset); \
  60. ACPI_COPY_FIELD(out, in, address_length); \
  61. ACPI_COPY_FIELD(out, in, resource_source);
  62. /* Local prototypes */
  63. static acpi_status
  64. acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
  65. /*******************************************************************************
  66. *
  67. * FUNCTION: acpi_get_irq_routing_table
  68. *
  69. * PARAMETERS: device_handle - a handle to the Bus device we are querying
  70. * ret_buffer - a pointer to a buffer to receive the
  71. * current resources for the device
  72. *
  73. * RETURN: Status
  74. *
  75. * DESCRIPTION: This function is called to get the IRQ routing table for a
  76. * specific bus. The caller must first acquire a handle for the
  77. * desired bus. The routine table is placed in the buffer pointed
  78. * to by the ret_buffer variable parameter.
  79. *
  80. * If the function fails an appropriate status will be returned
  81. * and the value of ret_buffer is undefined.
  82. *
  83. * This function attempts to execute the _PRT method contained in
  84. * the object indicated by the passed device_handle.
  85. *
  86. ******************************************************************************/
  87. acpi_status
  88. acpi_get_irq_routing_table(acpi_handle device_handle,
  89. struct acpi_buffer *ret_buffer)
  90. {
  91. acpi_status status;
  92. ACPI_FUNCTION_TRACE("acpi_get_irq_routing_table ");
  93. /*
  94. * Must have a valid handle and buffer, So we have to have a handle
  95. * and a return buffer structure, and if there is a non-zero buffer length
  96. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  97. * we'll be returning the needed buffer size, so keep going.
  98. */
  99. if (!device_handle) {
  100. return_ACPI_STATUS(AE_BAD_PARAMETER);
  101. }
  102. status = acpi_ut_validate_buffer(ret_buffer);
  103. if (ACPI_FAILURE(status)) {
  104. return_ACPI_STATUS(status);
  105. }
  106. status = acpi_rs_get_prt_method_data(device_handle, ret_buffer);
  107. return_ACPI_STATUS(status);
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_get_current_resources
  112. *
  113. * PARAMETERS: device_handle - a handle to the device object for the
  114. * device we are querying
  115. * ret_buffer - a pointer to a buffer to receive the
  116. * current resources for the device
  117. *
  118. * RETURN: Status
  119. *
  120. * DESCRIPTION: This function is called to get the current resources for a
  121. * specific device. The caller must first acquire a handle for
  122. * the desired device. The resource data is placed in the buffer
  123. * pointed to by the ret_buffer variable parameter.
  124. *
  125. * If the function fails an appropriate status will be returned
  126. * and the value of ret_buffer is undefined.
  127. *
  128. * This function attempts to execute the _CRS method contained in
  129. * the object indicated by the passed device_handle.
  130. *
  131. ******************************************************************************/
  132. acpi_status
  133. acpi_get_current_resources(acpi_handle device_handle,
  134. struct acpi_buffer *ret_buffer)
  135. {
  136. acpi_status status;
  137. ACPI_FUNCTION_TRACE("acpi_get_current_resources");
  138. /*
  139. * Must have a valid handle and buffer, So we have to have a handle
  140. * and a return buffer structure, and if there is a non-zero buffer length
  141. * we also need a valid pointer in the buffer. If it's a zero buffer length,
  142. * we'll be returning the needed buffer size, so keep going.
  143. */
  144. if (!device_handle) {
  145. return_ACPI_STATUS(AE_BAD_PARAMETER);
  146. }
  147. status = acpi_ut_validate_buffer(ret_buffer);
  148. if (ACPI_FAILURE(status)) {
  149. return_ACPI_STATUS(status);
  150. }
  151. status = acpi_rs_get_crs_method_data(device_handle, ret_buffer);
  152. return_ACPI_STATUS(status);
  153. }
  154. EXPORT_SYMBOL(acpi_get_current_resources);
  155. /*******************************************************************************
  156. *
  157. * FUNCTION: acpi_get_possible_resources
  158. *
  159. * PARAMETERS: device_handle - a handle to the device object for the
  160. * device we are querying
  161. * ret_buffer - a pointer to a buffer to receive the
  162. * resources for the device
  163. *
  164. * RETURN: Status
  165. *
  166. * DESCRIPTION: This function is called to get a list of the possible resources
  167. * for a specific device. The caller must first acquire a handle
  168. * for the desired device. The resource data is placed in the
  169. * buffer pointed to by the ret_buffer variable.
  170. *
  171. * If the function fails an appropriate status will be returned
  172. * and the value of ret_buffer is undefined.
  173. *
  174. ******************************************************************************/
  175. #ifdef ACPI_FUTURE_USAGE
  176. acpi_status
  177. acpi_get_possible_resources(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 - Handle to the device object for the
  205. * device we are querying
  206. * Name - 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(acpi_handle device_handle,
  220. char *name,
  221. ACPI_WALK_RESOURCE_CALLBACK user_function, void *context)
  222. {
  223. acpi_status status;
  224. struct acpi_buffer buffer;
  225. struct acpi_resource *resource;
  226. struct acpi_resource *resource_end;
  227. ACPI_FUNCTION_TRACE("acpi_walk_resources");
  228. /* Parameter validation */
  229. if (!device_handle || !user_function || !name ||
  230. (ACPI_STRNCMP(name, METHOD_NAME__CRS, sizeof(METHOD_NAME__CRS)) &&
  231. ACPI_STRNCMP(name, METHOD_NAME__PRS, sizeof(METHOD_NAME__PRS)))) {
  232. return_ACPI_STATUS(AE_BAD_PARAMETER);
  233. }
  234. /* Get the _CRS or _PRS resource list */
  235. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  236. status = acpi_rs_get_method_data(device_handle, name, &buffer);
  237. if (ACPI_FAILURE(status)) {
  238. return_ACPI_STATUS(status);
  239. }
  240. /* Buffer now contains the resource list */
  241. resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer);
  242. resource_end =
  243. ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length);
  244. /* Walk the resource list until the end_tag is found (or buffer end) */
  245. while (resource < resource_end) {
  246. /* Sanity check the resource */
  247. if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
  248. status = AE_AML_INVALID_RESOURCE_TYPE;
  249. break;
  250. }
  251. /* Invoke the user function, abort on any error returned */
  252. status = user_function(resource, context);
  253. if (ACPI_FAILURE(status)) {
  254. if (status == AE_CTRL_TERMINATE) {
  255. /* This is an OK termination by the user function */
  256. status = AE_OK;
  257. }
  258. break;
  259. }
  260. /* end_tag indicates end-of-list */
  261. if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
  262. break;
  263. }
  264. /* Get the next resource descriptor */
  265. resource =
  266. ACPI_ADD_PTR(struct acpi_resource, resource,
  267. resource->length);
  268. }
  269. ACPI_MEM_FREE(buffer.pointer);
  270. return_ACPI_STATUS(status);
  271. }
  272. EXPORT_SYMBOL(acpi_walk_resources);
  273. /*******************************************************************************
  274. *
  275. * FUNCTION: acpi_set_current_resources
  276. *
  277. * PARAMETERS: device_handle - a handle to the device object for the
  278. * device we are changing the resources of
  279. * in_buffer - a pointer to a buffer containing the
  280. * resources to be set for the device
  281. *
  282. * RETURN: Status
  283. *
  284. * DESCRIPTION: This function is called to set the current resources for a
  285. * specific device. The caller must first acquire a handle for
  286. * the desired device. The resource data is passed to the routine
  287. * the buffer pointed to by the in_buffer variable.
  288. *
  289. ******************************************************************************/
  290. acpi_status
  291. acpi_set_current_resources(acpi_handle device_handle,
  292. struct acpi_buffer *in_buffer)
  293. {
  294. acpi_status status;
  295. ACPI_FUNCTION_TRACE("acpi_set_current_resources");
  296. /* Must have a valid handle and buffer */
  297. if ((!device_handle) ||
  298. (!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
  299. return_ACPI_STATUS(AE_BAD_PARAMETER);
  300. }
  301. status = acpi_rs_set_srs_method_data(device_handle, in_buffer);
  302. return_ACPI_STATUS(status);
  303. }
  304. EXPORT_SYMBOL(acpi_set_current_resources);
  305. /******************************************************************************
  306. *
  307. * FUNCTION: acpi_resource_to_address64
  308. *
  309. * PARAMETERS: Resource - Pointer to a resource
  310. * Out - Pointer to the users's return
  311. * buffer (a struct
  312. * struct acpi_resource_address64)
  313. *
  314. * RETURN: Status
  315. *
  316. * DESCRIPTION: If the resource is an address16, address32, or address64,
  317. * copy it to the address64 return buffer. This saves the
  318. * caller from having to duplicate code for different-sized
  319. * addresses.
  320. *
  321. ******************************************************************************/
  322. acpi_status
  323. acpi_resource_to_address64(struct acpi_resource *resource,
  324. struct acpi_resource_address64 *out)
  325. {
  326. struct acpi_resource_address16 *address16;
  327. struct acpi_resource_address32 *address32;
  328. if (!resource || !out) {
  329. return (AE_BAD_PARAMETER);
  330. }
  331. /* Convert 16 or 32 address descriptor to 64 */
  332. switch (resource->type) {
  333. case ACPI_RESOURCE_TYPE_ADDRESS16:
  334. address16 = (struct acpi_resource_address16 *)&resource->data;
  335. ACPI_COPY_ADDRESS(out, address16);
  336. break;
  337. case ACPI_RESOURCE_TYPE_ADDRESS32:
  338. address32 = (struct acpi_resource_address32 *)&resource->data;
  339. ACPI_COPY_ADDRESS(out, address32);
  340. break;
  341. case ACPI_RESOURCE_TYPE_ADDRESS64:
  342. /* Simple copy for 64 bit source */
  343. ACPI_MEMCPY(out, &resource->data,
  344. sizeof(struct acpi_resource_address64));
  345. break;
  346. default:
  347. return (AE_BAD_PARAMETER);
  348. }
  349. return (AE_OK);
  350. }
  351. EXPORT_SYMBOL(acpi_resource_to_address64);
  352. /*******************************************************************************
  353. *
  354. * FUNCTION: acpi_get_vendor_resource
  355. *
  356. * PARAMETERS: device_handle - Handle for the parent device object
  357. * Name - Method name for the parent resource
  358. * (METHOD_NAME__CRS or METHOD_NAME__PRS)
  359. * Uuid - Pointer to the UUID to be matched.
  360. * includes both subtype and 16-byte UUID
  361. * ret_buffer - Where the vendor resource is returned
  362. *
  363. * RETURN: Status
  364. *
  365. * DESCRIPTION: Walk a resource template for the specified evice to find a
  366. * vendor-defined resource that matches the supplied UUID and
  367. * UUID subtype. Returns a struct acpi_resource of type Vendor.
  368. *
  369. ******************************************************************************/
  370. acpi_status
  371. acpi_get_vendor_resource(acpi_handle device_handle,
  372. char *name,
  373. struct acpi_vendor_uuid * uuid,
  374. struct acpi_buffer * ret_buffer)
  375. {
  376. struct acpi_vendor_walk_info info;
  377. acpi_status status;
  378. /* Other parameters are validated by acpi_walk_resources */
  379. if (!uuid || !ret_buffer) {
  380. return (AE_BAD_PARAMETER);
  381. }
  382. info.uuid = uuid;
  383. info.buffer = ret_buffer;
  384. info.status = AE_NOT_EXIST;
  385. /* Walk the _CRS or _PRS resource list for this device */
  386. status =
  387. acpi_walk_resources(device_handle, name,
  388. acpi_rs_match_vendor_resource, &info);
  389. if (ACPI_FAILURE(status)) {
  390. return (status);
  391. }
  392. return (info.status);
  393. }
  394. /*******************************************************************************
  395. *
  396. * FUNCTION: acpi_rs_match_vendor_resource
  397. *
  398. * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
  399. *
  400. * RETURN: Status
  401. *
  402. * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
  403. *
  404. ******************************************************************************/
  405. static acpi_status
  406. acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
  407. {
  408. struct acpi_vendor_walk_info *info = context;
  409. struct acpi_resource_vendor_typed *vendor;
  410. struct acpi_buffer *buffer;
  411. acpi_status status;
  412. /* Ignore all descriptors except Vendor */
  413. if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) {
  414. return (AE_OK);
  415. }
  416. vendor = &resource->data.vendor_typed;
  417. /*
  418. * For a valid match, these conditions must hold:
  419. *
  420. * 1) Length of descriptor data must be at least as long as a UUID struct
  421. * 2) The UUID subtypes must match
  422. * 3) The UUID data must match
  423. */
  424. if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) ||
  425. (vendor->uuid_subtype != info->uuid->subtype) ||
  426. (ACPI_MEMCMP(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) {
  427. return (AE_OK);
  428. }
  429. /* Validate/Allocate/Clear caller buffer */
  430. buffer = info->buffer;
  431. status = acpi_ut_initialize_buffer(buffer, resource->length);
  432. if (ACPI_FAILURE(status)) {
  433. return (status);
  434. }
  435. /* Found the correct resource, copy and return it */
  436. ACPI_MEMCPY(buffer->pointer, resource, resource->length);
  437. buffer->length = resource->length;
  438. /* Found the desired descriptor, terminate resource walk */
  439. info->status = AE_OK;
  440. return (AE_CTRL_TERMINATE);
  441. }