rsxface.c 18 KB

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