rslist.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. /* Validate the Resource Type and Resource Length */
  73. status = acpi_ut_validate_resource(aml, &resource_index);
  74. if (ACPI_FAILURE(status)) {
  75. return_ACPI_STATUS(status);
  76. }
  77. /* Convert the AML byte stream resource to a local resource struct */
  78. status =
  79. acpi_rs_convert_aml_to_resource(resource,
  80. ACPI_CAST_PTR(union
  81. aml_resource,
  82. aml),
  83. acpi_gbl_get_resource_dispatch
  84. [resource_index]);
  85. if (ACPI_FAILURE(status)) {
  86. ACPI_EXCEPTION((AE_INFO, status,
  87. "Could not convert AML resource (Type %X)",
  88. *aml));
  89. return_ACPI_STATUS(status);
  90. }
  91. /* Normal exit on completion of an end_tag resource descriptor */
  92. if (acpi_ut_get_resource_type(aml) ==
  93. ACPI_RESOURCE_NAME_END_TAG) {
  94. return_ACPI_STATUS(AE_OK);
  95. }
  96. /* Point to the next input AML resource */
  97. aml += acpi_ut_get_descriptor_length(aml);
  98. /* Point to the next structure in the output buffer */
  99. resource =
  100. ACPI_ADD_PTR(struct acpi_resource, resource,
  101. resource->length);
  102. }
  103. /* Did not find an end_tag resource descriptor */
  104. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  105. }
  106. /*******************************************************************************
  107. *
  108. * FUNCTION: acpi_rs_convert_resources_to_aml
  109. *
  110. * PARAMETERS: Resource - Pointer to the resource linked list
  111. * aml_size_needed - Calculated size of the byte stream
  112. * needed from calling acpi_rs_get_aml_length()
  113. * The size of the output_buffer is
  114. * guaranteed to be >= aml_size_needed
  115. * output_buffer - Pointer to the buffer that will
  116. * contain the byte stream
  117. *
  118. * RETURN: Status
  119. *
  120. * DESCRIPTION: Takes the resource linked list and parses it, creating a
  121. * byte stream of resources in the caller's output buffer
  122. *
  123. ******************************************************************************/
  124. acpi_status
  125. acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
  126. acpi_size aml_size_needed, u8 * output_buffer)
  127. {
  128. u8 *aml = output_buffer;
  129. u8 *end_aml = output_buffer + aml_size_needed;
  130. acpi_status status;
  131. ACPI_FUNCTION_TRACE("rs_convert_resources_to_aml");
  132. /* Walk the resource descriptor list, convert each descriptor */
  133. while (aml < end_aml) {
  134. /* Validate the (internal) Resource Type */
  135. if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
  136. ACPI_ERROR((AE_INFO,
  137. "Invalid descriptor type (%X) in resource list",
  138. resource->type));
  139. return_ACPI_STATUS(AE_BAD_DATA);
  140. }
  141. /* Perform the conversion */
  142. status = acpi_rs_convert_resource_to_aml(resource,
  143. ACPI_CAST_PTR(union
  144. aml_resource,
  145. aml),
  146. acpi_gbl_set_resource_dispatch
  147. [resource->type]);
  148. if (ACPI_FAILURE(status)) {
  149. ACPI_EXCEPTION((AE_INFO, status,
  150. "Could not convert resource (type %X) to AML",
  151. resource->type));
  152. return_ACPI_STATUS(status);
  153. }
  154. /* Perform final sanity check on the new AML resource descriptor */
  155. status =
  156. acpi_ut_validate_resource(ACPI_CAST_PTR
  157. (union aml_resource, aml), NULL);
  158. if (ACPI_FAILURE(status)) {
  159. return_ACPI_STATUS(status);
  160. }
  161. /* Check for end-of-list, normal exit */
  162. if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
  163. /* An End Tag indicates the end of the input Resource Template */
  164. return_ACPI_STATUS(AE_OK);
  165. }
  166. /*
  167. * Extract the total length of the new descriptor and set the
  168. * Aml to point to the next (output) resource descriptor
  169. */
  170. aml += acpi_ut_get_descriptor_length(aml);
  171. /* Point to the next input resource descriptor */
  172. resource =
  173. ACPI_ADD_PTR(struct acpi_resource, resource,
  174. resource->length);
  175. }
  176. /* Completed buffer, but did not find an end_tag resource descriptor */
  177. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  178. }