rsutils.c 11 KB

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