rslist.c 6.8 KB

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