rsxface.c 18 KB

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