rsutils.c 11 KB

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