rslist.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*******************************************************************************
  2. *
  3. * Module Name: rslist - Linked list utilities
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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/acresrc.h>
  44. #define _COMPONENT ACPI_RESOURCES
  45. ACPI_MODULE_NAME("rslist")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_rs_convert_aml_to_resources
  49. *
  50. * PARAMETERS: Aml - Pointer to the resource byte stream
  51. * aml_length - Length of Aml
  52. * output_buffer - Pointer to the buffer that will
  53. * contain the output structures
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Takes the resource byte stream and parses it, creating a
  58. * linked list of resources in the caller's output buffer
  59. *
  60. ******************************************************************************/
  61. acpi_status
  62. acpi_rs_convert_aml_to_resources(u8 * aml, u32 aml_length, u8 * output_buffer)
  63. {
  64. struct acpi_resource *resource = (void *)output_buffer;
  65. acpi_status status;
  66. u8 resource_index;
  67. u8 *end_aml;
  68. ACPI_FUNCTION_TRACE("rs_convert_aml_to_resources");
  69. end_aml = aml + aml_length;
  70. /* Loop until end-of-buffer or an end_tag is found */
  71. while (aml < end_aml) {
  72. /*
  73. * Check that the input buffer and all subsequent pointers into it
  74. * are aligned on a native word boundary. Most important on IA64
  75. */
  76. if (ACPI_IS_MISALIGNED(resource)) {
  77. ACPI_WARNING((AE_INFO,
  78. "Misaligned resource pointer %p",
  79. resource));
  80. }
  81. /* Validate the Resource Type and Resource Length */
  82. status = acpi_ut_validate_resource(aml, &resource_index);
  83. if (ACPI_FAILURE(status)) {
  84. return_ACPI_STATUS(status);
  85. }
  86. /* Convert the AML byte stream resource to a local resource struct */
  87. status =
  88. acpi_rs_convert_aml_to_resource(resource,
  89. ACPI_CAST_PTR(union
  90. aml_resource,
  91. aml),
  92. acpi_gbl_get_resource_dispatch
  93. [resource_index]);
  94. if (ACPI_FAILURE(status)) {
  95. ACPI_EXCEPTION((AE_INFO, status,
  96. "Could not convert AML resource (Type %X)",
  97. *aml));
  98. return_ACPI_STATUS(status);
  99. }
  100. ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
  101. "Type %.2X, Aml %.2X internal %.2X\n",
  102. acpi_ut_get_resource_type(aml),
  103. acpi_ut_get_descriptor_length(aml),
  104. resource->length));
  105. /* Normal exit on completion of an end_tag resource descriptor */
  106. if (acpi_ut_get_resource_type(aml) ==
  107. ACPI_RESOURCE_NAME_END_TAG) {
  108. return_ACPI_STATUS(AE_OK);
  109. }
  110. /* Point to the next input AML resource */
  111. aml += acpi_ut_get_descriptor_length(aml);
  112. /* Point to the next structure in the output buffer */
  113. resource =
  114. ACPI_ADD_PTR(struct acpi_resource, resource,
  115. resource->length);
  116. }
  117. /* Did not find an end_tag resource descriptor */
  118. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  119. }
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_rs_convert_resources_to_aml
  123. *
  124. * PARAMETERS: Resource - Pointer to the resource linked list
  125. * aml_size_needed - Calculated size of the byte stream
  126. * needed from calling acpi_rs_get_aml_length()
  127. * The size of the output_buffer is
  128. * guaranteed to be >= aml_size_needed
  129. * output_buffer - Pointer to the buffer that will
  130. * contain the byte stream
  131. *
  132. * RETURN: Status
  133. *
  134. * DESCRIPTION: Takes the resource linked list and parses it, creating a
  135. * byte stream of resources in the caller's output buffer
  136. *
  137. ******************************************************************************/
  138. acpi_status
  139. acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
  140. acpi_size aml_size_needed, u8 * output_buffer)
  141. {
  142. u8 *aml = output_buffer;
  143. u8 *end_aml = output_buffer + aml_size_needed;
  144. acpi_status status;
  145. ACPI_FUNCTION_TRACE("rs_convert_resources_to_aml");
  146. /* Walk the resource descriptor list, convert each descriptor */
  147. while (aml < end_aml) {
  148. /* Validate the (internal) Resource Type */
  149. if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
  150. ACPI_ERROR((AE_INFO,
  151. "Invalid descriptor type (%X) in resource list",
  152. resource->type));
  153. return_ACPI_STATUS(AE_BAD_DATA);
  154. }
  155. /* Perform the conversion */
  156. status = acpi_rs_convert_resource_to_aml(resource,
  157. ACPI_CAST_PTR(union
  158. aml_resource,
  159. aml),
  160. acpi_gbl_set_resource_dispatch
  161. [resource->type]);
  162. if (ACPI_FAILURE(status)) {
  163. ACPI_EXCEPTION((AE_INFO, status,
  164. "Could not convert resource (type %X) to AML",
  165. resource->type));
  166. return_ACPI_STATUS(status);
  167. }
  168. /* Perform final sanity check on the new AML resource descriptor */
  169. status =
  170. acpi_ut_validate_resource(ACPI_CAST_PTR
  171. (union aml_resource, aml), NULL);
  172. if (ACPI_FAILURE(status)) {
  173. return_ACPI_STATUS(status);
  174. }
  175. /* Check for end-of-list, normal exit */
  176. if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
  177. /* An End Tag indicates the end of the input Resource Template */
  178. return_ACPI_STATUS(AE_OK);
  179. }
  180. /*
  181. * Extract the total length of the new descriptor and set the
  182. * Aml to point to the next (output) resource descriptor
  183. */
  184. aml += acpi_ut_get_descriptor_length(aml);
  185. /* Point to the next input resource descriptor */
  186. resource =
  187. ACPI_ADD_PTR(struct acpi_resource, resource,
  188. resource->length);
  189. }
  190. /* Completed buffer, but did not find an end_tag resource descriptor */
  191. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  192. }