rslist.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*******************************************************************************
  2. *
  3. * Module Name: rslist - Linked list utilities
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. #define _COMPONENT ACPI_RESOURCES
  46. ACPI_MODULE_NAME("rslist")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_rs_convert_aml_to_resources
  50. *
  51. * PARAMETERS: acpi_walk_aml_callback
  52. * resource_ptr - Pointer to the buffer that will
  53. * contain the output structures
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Convert an AML resource to an internal representation of the
  58. * resource that is aligned and easier to access.
  59. *
  60. ******************************************************************************/
  61. acpi_status
  62. acpi_rs_convert_aml_to_resources(u8 * aml,
  63. u32 length,
  64. u32 offset, u8 resource_index, void **context)
  65. {
  66. struct acpi_resource **resource_ptr =
  67. ACPI_CAST_INDIRECT_PTR(struct acpi_resource, context);
  68. struct acpi_resource *resource;
  69. union aml_resource *aml_resource;
  70. struct acpi_rsconvert_info *conversion_table;
  71. acpi_status status;
  72. ACPI_FUNCTION_TRACE(rs_convert_aml_to_resources);
  73. /*
  74. * Check that the input buffer and all subsequent pointers into it
  75. * are aligned on a native word boundary. Most important on IA64
  76. */
  77. resource = *resource_ptr;
  78. if (ACPI_IS_MISALIGNED(resource)) {
  79. ACPI_WARNING((AE_INFO,
  80. "Misaligned resource pointer %p", resource));
  81. }
  82. /* Get the appropriate conversion info table */
  83. aml_resource = ACPI_CAST_PTR(union aml_resource, aml);
  84. if (acpi_ut_get_resource_type(aml) == ACPI_RESOURCE_NAME_SERIAL_BUS) {
  85. if (aml_resource->common_serial_bus.type >
  86. AML_RESOURCE_MAX_SERIALBUSTYPE) {
  87. conversion_table = NULL;
  88. } else {
  89. /* This is an I2C, SPI, or UART serial_bus descriptor */
  90. conversion_table =
  91. acpi_gbl_convert_resource_serial_bus_dispatch
  92. [aml_resource->common_serial_bus.type];
  93. }
  94. } else {
  95. conversion_table =
  96. acpi_gbl_get_resource_dispatch[resource_index];
  97. }
  98. if (!conversion_table) {
  99. ACPI_ERROR((AE_INFO,
  100. "Invalid/unsupported resource descriptor: Type 0x%2.2X",
  101. resource_index));
  102. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  103. }
  104. /* Convert the AML byte stream resource to a local resource struct */
  105. status =
  106. acpi_rs_convert_aml_to_resource(resource, aml_resource,
  107. conversion_table);
  108. if (ACPI_FAILURE(status)) {
  109. ACPI_EXCEPTION((AE_INFO, status,
  110. "Could not convert AML resource (Type 0x%X)",
  111. *aml));
  112. return_ACPI_STATUS(status);
  113. }
  114. ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
  115. "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
  116. acpi_ut_get_resource_type(aml), length,
  117. resource->length));
  118. /* Point to the next structure in the output buffer */
  119. *resource_ptr = ACPI_NEXT_RESOURCE(resource);
  120. return_ACPI_STATUS(AE_OK);
  121. }
  122. /*******************************************************************************
  123. *
  124. * FUNCTION: acpi_rs_convert_resources_to_aml
  125. *
  126. * PARAMETERS: resource - Pointer to the resource linked list
  127. * aml_size_needed - Calculated size of the byte stream
  128. * needed from calling acpi_rs_get_aml_length()
  129. * The size of the output_buffer is
  130. * guaranteed to be >= aml_size_needed
  131. * output_buffer - Pointer to the buffer that will
  132. * contain the byte stream
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Takes the resource linked list and parses it, creating a
  137. * byte stream of resources in the caller's output buffer
  138. *
  139. ******************************************************************************/
  140. acpi_status
  141. acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
  142. acpi_size aml_size_needed, u8 * output_buffer)
  143. {
  144. u8 *aml = output_buffer;
  145. u8 *end_aml = output_buffer + aml_size_needed;
  146. struct acpi_rsconvert_info *conversion_table;
  147. acpi_status status;
  148. ACPI_FUNCTION_TRACE(rs_convert_resources_to_aml);
  149. /* Walk the resource descriptor list, convert each descriptor */
  150. while (aml < end_aml) {
  151. /* Validate the (internal) Resource Type */
  152. if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
  153. ACPI_ERROR((AE_INFO,
  154. "Invalid descriptor type (0x%X) in resource list",
  155. resource->type));
  156. return_ACPI_STATUS(AE_BAD_DATA);
  157. }
  158. /* Sanity check the length. It must not be zero, or we loop forever */
  159. if (!resource->length) {
  160. ACPI_ERROR((AE_INFO,
  161. "Invalid zero length descriptor in resource list\n"));
  162. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  163. }
  164. /* Perform the conversion */
  165. if (resource->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
  166. if (resource->data.common_serial_bus.type >
  167. AML_RESOURCE_MAX_SERIALBUSTYPE) {
  168. conversion_table = NULL;
  169. } else {
  170. /* This is an I2C, SPI, or UART serial_bus descriptor */
  171. conversion_table =
  172. acpi_gbl_convert_resource_serial_bus_dispatch
  173. [resource->data.common_serial_bus.type];
  174. }
  175. } else {
  176. conversion_table =
  177. acpi_gbl_set_resource_dispatch[resource->type];
  178. }
  179. if (!conversion_table) {
  180. ACPI_ERROR((AE_INFO,
  181. "Invalid/unsupported resource descriptor: Type 0x%2.2X",
  182. resource->type));
  183. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  184. }
  185. status = acpi_rs_convert_resource_to_aml(resource,
  186. ACPI_CAST_PTR(union
  187. aml_resource,
  188. aml),
  189. conversion_table);
  190. if (ACPI_FAILURE(status)) {
  191. ACPI_EXCEPTION((AE_INFO, status,
  192. "Could not convert resource (type 0x%X) to AML",
  193. resource->type));
  194. return_ACPI_STATUS(status);
  195. }
  196. /* Perform final sanity check on the new AML resource descriptor */
  197. status = acpi_ut_validate_resource(NULL,
  198. ACPI_CAST_PTR(union
  199. aml_resource,
  200. aml), NULL);
  201. if (ACPI_FAILURE(status)) {
  202. return_ACPI_STATUS(status);
  203. }
  204. /* Check for end-of-list, normal exit */
  205. if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
  206. /* An End Tag indicates the end of the input Resource Template */
  207. return_ACPI_STATUS(AE_OK);
  208. }
  209. /*
  210. * Extract the total length of the new descriptor and set the
  211. * Aml to point to the next (output) resource descriptor
  212. */
  213. aml += acpi_ut_get_descriptor_length(aml);
  214. /* Point to the next input resource descriptor */
  215. resource = ACPI_NEXT_RESOURCE(resource);
  216. }
  217. /* Completed buffer, but did not find an end_tag resource descriptor */
  218. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  219. }