rsutils.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsutils - Utilities for 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 <acpi/acpi.h>
  43. #include <acpi/acnamesp.h>
  44. #include <acpi/acresrc.h>
  45. #define _COMPONENT ACPI_RESOURCES
  46. ACPI_MODULE_NAME ("rsutils")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_rs_get_prt_method_data
  50. *
  51. * PARAMETERS: Handle - a handle to the containing object
  52. * ret_buffer - a pointer to a buffer structure for the
  53. * results
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: This function is called to get the _PRT value of an object
  58. * contained in an object specified by the handle passed in
  59. *
  60. * If the function fails an appropriate status will be returned
  61. * and the contents of the callers buffer is undefined.
  62. *
  63. ******************************************************************************/
  64. acpi_status
  65. acpi_rs_get_prt_method_data (
  66. acpi_handle handle,
  67. struct acpi_buffer *ret_buffer)
  68. {
  69. union acpi_operand_object *obj_desc;
  70. acpi_status status;
  71. ACPI_FUNCTION_TRACE ("rs_get_prt_method_data");
  72. /* Parameters guaranteed valid by caller */
  73. /* Execute the method, no parameters */
  74. status = acpi_ut_evaluate_object (handle, METHOD_NAME__PRT,
  75. ACPI_BTYPE_PACKAGE, &obj_desc);
  76. if (ACPI_FAILURE (status)) {
  77. return_ACPI_STATUS (status);
  78. }
  79. /*
  80. * Create a resource linked list from the byte stream buffer that comes
  81. * back from the _CRS method execution.
  82. */
  83. status = acpi_rs_create_pci_routing_table (obj_desc, ret_buffer);
  84. /* On exit, we must delete the object returned by evaluate_object */
  85. acpi_ut_remove_reference (obj_desc);
  86. return_ACPI_STATUS (status);
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_rs_get_crs_method_data
  91. *
  92. * PARAMETERS: Handle - a handle to the containing object
  93. * ret_buffer - a pointer to a buffer structure for the
  94. * results
  95. *
  96. * RETURN: Status
  97. *
  98. * DESCRIPTION: This function is called to get the _CRS value of an object
  99. * contained in an object specified by the handle passed in
  100. *
  101. * If the function fails an appropriate status will be returned
  102. * and the contents of the callers buffer is undefined.
  103. *
  104. ******************************************************************************/
  105. acpi_status
  106. acpi_rs_get_crs_method_data (
  107. acpi_handle handle,
  108. struct acpi_buffer *ret_buffer)
  109. {
  110. union acpi_operand_object *obj_desc;
  111. acpi_status status;
  112. ACPI_FUNCTION_TRACE ("rs_get_crs_method_data");
  113. /* Parameters guaranteed valid by caller */
  114. /* Execute the method, no parameters */
  115. status = acpi_ut_evaluate_object (handle, METHOD_NAME__CRS,
  116. ACPI_BTYPE_BUFFER, &obj_desc);
  117. if (ACPI_FAILURE (status)) {
  118. return_ACPI_STATUS (status);
  119. }
  120. /*
  121. * Make the call to create a resource linked list from the
  122. * byte stream buffer that comes back from the _CRS method
  123. * execution.
  124. */
  125. status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
  126. /* on exit, we must delete the object returned by evaluate_object */
  127. acpi_ut_remove_reference (obj_desc);
  128. return_ACPI_STATUS (status);
  129. }
  130. /*******************************************************************************
  131. *
  132. * FUNCTION: acpi_rs_get_prs_method_data
  133. *
  134. * PARAMETERS: Handle - a handle to the containing object
  135. * ret_buffer - a pointer to a buffer structure for the
  136. * results
  137. *
  138. * RETURN: Status
  139. *
  140. * DESCRIPTION: This function is called to get the _PRS value of an object
  141. * contained in an object specified by the handle passed in
  142. *
  143. * If the function fails an appropriate status will be returned
  144. * and the contents of the callers buffer is undefined.
  145. *
  146. ******************************************************************************/
  147. #ifdef ACPI_FUTURE_USAGE
  148. acpi_status
  149. acpi_rs_get_prs_method_data (
  150. acpi_handle handle,
  151. struct acpi_buffer *ret_buffer)
  152. {
  153. union acpi_operand_object *obj_desc;
  154. acpi_status status;
  155. ACPI_FUNCTION_TRACE ("rs_get_prs_method_data");
  156. /* Parameters guaranteed valid by caller */
  157. /* Execute the method, no parameters */
  158. status = acpi_ut_evaluate_object (handle, METHOD_NAME__PRS,
  159. ACPI_BTYPE_BUFFER, &obj_desc);
  160. if (ACPI_FAILURE (status)) {
  161. return_ACPI_STATUS (status);
  162. }
  163. /*
  164. * Make the call to create a resource linked list from the
  165. * byte stream buffer that comes back from the _CRS method
  166. * execution.
  167. */
  168. status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
  169. /* on exit, we must delete the object returned by evaluate_object */
  170. acpi_ut_remove_reference (obj_desc);
  171. return_ACPI_STATUS (status);
  172. }
  173. #endif /* ACPI_FUTURE_USAGE */
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_rs_get_method_data
  177. *
  178. * PARAMETERS: Handle - a handle to the containing object
  179. * Path - Path to method, relative to Handle
  180. * ret_buffer - a pointer to a buffer structure for the
  181. * results
  182. *
  183. * RETURN: Status
  184. *
  185. * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
  186. * object contained in an object specified by the handle passed in
  187. *
  188. * If the function fails an appropriate status will be returned
  189. * and the contents of the callers buffer is undefined.
  190. *
  191. ******************************************************************************/
  192. acpi_status
  193. acpi_rs_get_method_data (
  194. acpi_handle handle,
  195. char *path,
  196. struct acpi_buffer *ret_buffer)
  197. {
  198. union acpi_operand_object *obj_desc;
  199. acpi_status status;
  200. ACPI_FUNCTION_TRACE ("rs_get_method_data");
  201. /* Parameters guaranteed valid by caller */
  202. /* Execute the method, no parameters */
  203. status = acpi_ut_evaluate_object (handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
  204. if (ACPI_FAILURE (status)) {
  205. return_ACPI_STATUS (status);
  206. }
  207. /*
  208. * Make the call to create a resource linked list from the
  209. * byte stream buffer that comes back from the method
  210. * execution.
  211. */
  212. status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
  213. /* On exit, we must delete the object returned by evaluate_object */
  214. acpi_ut_remove_reference (obj_desc);
  215. return_ACPI_STATUS (status);
  216. }
  217. /*******************************************************************************
  218. *
  219. * FUNCTION: acpi_rs_set_srs_method_data
  220. *
  221. * PARAMETERS: Handle - a handle to the containing object
  222. * in_buffer - a pointer to a buffer structure of the
  223. * parameter
  224. *
  225. * RETURN: Status
  226. *
  227. * DESCRIPTION: This function is called to set the _SRS of an object contained
  228. * in an object specified by the handle passed in
  229. *
  230. * If the function fails an appropriate status will be returned
  231. * and the contents of the callers buffer is undefined.
  232. *
  233. ******************************************************************************/
  234. acpi_status
  235. acpi_rs_set_srs_method_data (
  236. acpi_handle handle,
  237. struct acpi_buffer *in_buffer)
  238. {
  239. struct acpi_parameter_info info;
  240. union acpi_operand_object *params[2];
  241. acpi_status status;
  242. struct acpi_buffer buffer;
  243. ACPI_FUNCTION_TRACE ("rs_set_srs_method_data");
  244. /* Parameters guaranteed valid by caller */
  245. /*
  246. * The in_buffer parameter will point to a linked list of
  247. * resource parameters. It needs to be formatted into a
  248. * byte stream to be sent in as an input parameter to _SRS
  249. *
  250. * Convert the linked list into a byte stream
  251. */
  252. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  253. status = acpi_rs_create_byte_stream (in_buffer->pointer, &buffer);
  254. if (ACPI_FAILURE (status)) {
  255. return_ACPI_STATUS (status);
  256. }
  257. /* Init the param object */
  258. params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);
  259. if (!params[0]) {
  260. acpi_os_free (buffer.pointer);
  261. return_ACPI_STATUS (AE_NO_MEMORY);
  262. }
  263. /* Set up the parameter object */
  264. params[0]->buffer.length = (u32) buffer.length;
  265. params[0]->buffer.pointer = buffer.pointer;
  266. params[0]->common.flags = AOPOBJ_DATA_VALID;
  267. params[1] = NULL;
  268. info.node = handle;
  269. info.parameters = params;
  270. info.parameter_type = ACPI_PARAM_ARGS;
  271. /* Execute the method, no return value */
  272. status = acpi_ns_evaluate_relative (METHOD_NAME__SRS, &info);
  273. if (ACPI_SUCCESS (status)) {
  274. /* Delete any return object (especially if implicit_return is enabled) */
  275. if (info.return_object) {
  276. acpi_ut_remove_reference (info.return_object);
  277. }
  278. }
  279. /* Clean up and return the status from acpi_ns_evaluate_relative */
  280. acpi_ut_remove_reference (params[0]);
  281. return_ACPI_STATUS (status);
  282. }