rslist.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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: acpi_walk_aml_callback
  51. * resource_ptr - Pointer to the buffer that will
  52. * contain the output structures
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Convert an AML resource to an internal representation of the
  57. * resource that is aligned and easier to access.
  58. *
  59. ******************************************************************************/
  60. acpi_status
  61. acpi_rs_convert_aml_to_resources(u8 * aml,
  62. u32 length,
  63. u32 offset,
  64. u8 resource_index, void **resource_ptr)
  65. {
  66. struct acpi_resource *resource = *resource_ptr;
  67. acpi_status status;
  68. ACPI_FUNCTION_TRACE("rs_convert_aml_to_resources");
  69. /*
  70. * Check that the input buffer and all subsequent pointers into it
  71. * are aligned on a native word boundary. Most important on IA64
  72. */
  73. if (ACPI_IS_MISALIGNED(resource)) {
  74. ACPI_WARNING((AE_INFO,
  75. "Misaligned resource pointer %p", resource));
  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 aml_resource,
  81. aml),
  82. acpi_gbl_get_resource_dispatch
  83. [resource_index]);
  84. if (ACPI_FAILURE(status)) {
  85. ACPI_EXCEPTION((AE_INFO, status,
  86. "Could not convert AML resource (Type %X)",
  87. *aml));
  88. return_ACPI_STATUS(status);
  89. }
  90. ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
  91. "Type %.2X, aml_length %.2X internal_length %.2X\n",
  92. acpi_ut_get_resource_type(aml), length,
  93. resource->length));
  94. /* Point to the next structure in the output buffer */
  95. *resource_ptr = ACPI_ADD_PTR(void, resource, resource->length);
  96. return_ACPI_STATUS(AE_OK);
  97. }
  98. /*******************************************************************************
  99. *
  100. * FUNCTION: acpi_rs_convert_resources_to_aml
  101. *
  102. * PARAMETERS: Resource - Pointer to the resource linked list
  103. * aml_size_needed - Calculated size of the byte stream
  104. * needed from calling acpi_rs_get_aml_length()
  105. * The size of the output_buffer is
  106. * guaranteed to be >= aml_size_needed
  107. * output_buffer - Pointer to the buffer that will
  108. * contain the byte stream
  109. *
  110. * RETURN: Status
  111. *
  112. * DESCRIPTION: Takes the resource linked list and parses it, creating a
  113. * byte stream of resources in the caller's output buffer
  114. *
  115. ******************************************************************************/
  116. acpi_status
  117. acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
  118. acpi_size aml_size_needed, u8 * output_buffer)
  119. {
  120. u8 *aml = output_buffer;
  121. u8 *end_aml = output_buffer + aml_size_needed;
  122. acpi_status status;
  123. ACPI_FUNCTION_TRACE("rs_convert_resources_to_aml");
  124. /* Walk the resource descriptor list, convert each descriptor */
  125. while (aml < end_aml) {
  126. /* Validate the (internal) Resource Type */
  127. if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
  128. ACPI_ERROR((AE_INFO,
  129. "Invalid descriptor type (%X) in resource list",
  130. resource->type));
  131. return_ACPI_STATUS(AE_BAD_DATA);
  132. }
  133. /* Perform the conversion */
  134. status = acpi_rs_convert_resource_to_aml(resource,
  135. ACPI_CAST_PTR(union
  136. aml_resource,
  137. aml),
  138. acpi_gbl_set_resource_dispatch
  139. [resource->type]);
  140. if (ACPI_FAILURE(status)) {
  141. ACPI_EXCEPTION((AE_INFO, status,
  142. "Could not convert resource (type %X) to AML",
  143. resource->type));
  144. return_ACPI_STATUS(status);
  145. }
  146. /* Perform final sanity check on the new AML resource descriptor */
  147. status =
  148. acpi_ut_validate_resource(ACPI_CAST_PTR
  149. (union aml_resource, aml), NULL);
  150. if (ACPI_FAILURE(status)) {
  151. return_ACPI_STATUS(status);
  152. }
  153. /* Check for end-of-list, normal exit */
  154. if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
  155. /* An End Tag indicates the end of the input Resource Template */
  156. return_ACPI_STATUS(AE_OK);
  157. }
  158. /*
  159. * Extract the total length of the new descriptor and set the
  160. * Aml to point to the next (output) resource descriptor
  161. */
  162. aml += acpi_ut_get_descriptor_length(aml);
  163. /* Point to the next input resource descriptor */
  164. resource =
  165. ACPI_ADD_PTR(struct acpi_resource, resource,
  166. resource->length);
  167. }
  168. /* Completed buffer, but did not find an end_tag resource descriptor */
  169. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  170. }