Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: rscalc - Calculate stream and list lengths |
| 5 | * |
| 6 | ******************************************************************************/ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 9 | #include "accommon.h" |
| 10 | #include "acresrc.h" |
| 11 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #define _COMPONENT ACPI_RESOURCES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 14 | ACPI_MODULE_NAME("rscalc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 16 | /* Local prototypes */ |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 17 | static u8 acpi_rs_count_set_bits(u16 bit_field); |
| 18 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 19 | static acpi_rs_length |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 20 | acpi_rs_struct_option_length(struct acpi_resource_source *resource_source); |
| 21 | |
| 22 | static u32 |
| 23 | acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length); |
| 24 | |
| 25 | /******************************************************************************* |
| 26 | * |
| 27 | * FUNCTION: acpi_rs_count_set_bits |
| 28 | * |
| 29 | * PARAMETERS: bit_field - Field in which to count bits |
| 30 | * |
| 31 | * RETURN: Number of bits set within the field |
| 32 | * |
| 33 | * DESCRIPTION: Count the number of bits set in a resource field. Used for |
| 34 | * (Short descriptor) interrupt and DMA lists. |
| 35 | * |
| 36 | ******************************************************************************/ |
| 37 | |
| 38 | static u8 acpi_rs_count_set_bits(u16 bit_field) |
| 39 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 40 | u8 bits_set; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 41 | |
| 42 | ACPI_FUNCTION_ENTRY(); |
| 43 | |
| 44 | for (bits_set = 0; bit_field; bits_set++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 45 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 46 | /* Zero the least significant bit that is set */ |
| 47 | |
Bob Moore | 1d18c05 | 2008-04-10 19:06:40 +0400 | [diff] [blame] | 48 | bit_field &= (u16) (bit_field - 1); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 51 | return (bits_set); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 56 | * FUNCTION: acpi_rs_struct_option_length |
| 57 | * |
| 58 | * PARAMETERS: resource_source - Pointer to optional descriptor field |
| 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
| 62 | * DESCRIPTION: Common code to handle optional resource_source_index and |
| 63 | * resource_source fields in some Large descriptors. Used during |
| 64 | * list-to-stream conversion |
| 65 | * |
| 66 | ******************************************************************************/ |
| 67 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 68 | static acpi_rs_length |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 69 | acpi_rs_struct_option_length(struct acpi_resource_source *resource_source) |
| 70 | { |
| 71 | ACPI_FUNCTION_ENTRY(); |
| 72 | |
| 73 | /* |
| 74 | * If the resource_source string is valid, return the size of the string |
| 75 | * (string_length includes the NULL terminator) plus the size of the |
| 76 | * resource_source_index (1). |
| 77 | */ |
| 78 | if (resource_source->string_ptr) { |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 79 | return ((acpi_rs_length)(resource_source->string_length + 1)); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return (0); |
| 83 | } |
| 84 | |
| 85 | /******************************************************************************* |
| 86 | * |
| 87 | * FUNCTION: acpi_rs_stream_option_length |
| 88 | * |
| 89 | * PARAMETERS: resource_length - Length from the resource header |
| 90 | * minimum_total_length - Minimum length of this resource, before |
| 91 | * any optional fields. Includes header size |
| 92 | * |
| 93 | * RETURN: Length of optional string (0 if no string present) |
| 94 | * |
| 95 | * DESCRIPTION: Common code to handle optional resource_source_index and |
| 96 | * resource_source fields in some Large descriptors. Used during |
| 97 | * stream-to-list conversion |
| 98 | * |
| 99 | ******************************************************************************/ |
| 100 | |
| 101 | static u32 |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 102 | acpi_rs_stream_option_length(u32 resource_length, |
| 103 | u32 minimum_aml_resource_length) |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 104 | { |
| 105 | u32 string_length = 0; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 106 | |
| 107 | ACPI_FUNCTION_ENTRY(); |
| 108 | |
| 109 | /* |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 110 | * The resource_source_index and resource_source are optional elements of |
| 111 | * some Large-type resource descriptors. |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 112 | */ |
| 113 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 114 | /* |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 115 | * If the length of the actual resource descriptor is greater than the |
| 116 | * ACPI spec-defined minimum length, it means that a resource_source_index |
| 117 | * exists and is followed by a (required) null terminated string. The |
| 118 | * string length (including the null terminator) is the resource length |
| 119 | * minus the minimum length, minus one byte for the resource_source_index |
| 120 | * itself. |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 121 | */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 122 | if (resource_length > minimum_aml_resource_length) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 123 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 124 | /* Compute the length of the optional string */ |
| 125 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 126 | string_length = |
| 127 | resource_length - minimum_aml_resource_length - 1; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 128 | } |
| 129 | |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 130 | /* |
| 131 | * Round the length up to a multiple of the native word in order to |
| 132 | * guarantee that the entire resource descriptor is native word aligned |
| 133 | */ |
| 134 | return ((u32) ACPI_ROUND_UP_TO_NATIVE_WORD(string_length)); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 135 | } |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /******************************************************************************* |
| 138 | * |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 139 | * FUNCTION: acpi_rs_get_aml_length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 141 | * PARAMETERS: resource - Pointer to the resource linked list |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 142 | * resource_list_size - Size of the resource linked list |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 143 | * size_needed - Where the required size is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | * |
| 145 | * RETURN: Status |
| 146 | * |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 147 | * DESCRIPTION: Takes a linked list of internal resource descriptors and |
| 148 | * calculates the size buffer needed to hold the corresponding |
| 149 | * external resource byte stream. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * |
| 151 | ******************************************************************************/ |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | acpi_status |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 154 | acpi_rs_get_aml_length(struct acpi_resource *resource, |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 155 | acpi_size resource_list_size, acpi_size *size_needed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 157 | acpi_size aml_size_needed = 0; |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 158 | struct acpi_resource *resource_end; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 159 | acpi_rs_length total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 161 | ACPI_FUNCTION_TRACE(rs_get_aml_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 163 | /* Traverse entire list of internal resource descriptors */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 164 | |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 165 | resource_end = |
| 166 | ACPI_ADD_PTR(struct acpi_resource, resource, resource_list_size); |
| 167 | while (resource < resource_end) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 168 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 169 | /* Validate the descriptor type */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 171 | if (resource->type > ACPI_RESOURCE_TYPE_MAX) { |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 172 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
| 173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Bob Moore | c13085e | 2013-03-08 09:19:38 +0000 | [diff] [blame] | 175 | /* Sanity check the length. It must not be zero, or we loop forever */ |
| 176 | |
| 177 | if (!resource->length) { |
| 178 | return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); |
| 179 | } |
| 180 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 181 | /* Get the base size of the (external stream) resource descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 183 | total_size = acpi_gbl_aml_resource_sizes[resource->type]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 185 | /* |
| 186 | * Augment the base size for descriptors with optional and/or |
| 187 | * variable-length fields |
| 188 | */ |
| 189 | switch (resource->type) { |
Bob Moore | 1d5b285 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 190 | case ACPI_RESOURCE_TYPE_IRQ: |
| 191 | |
Bob Moore | 66d3ca9 | 2008-04-10 19:06:44 +0400 | [diff] [blame] | 192 | /* Length can be 3 or 2 */ |
| 193 | |
Bob Moore | 1d5b285 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 194 | if (resource->data.irq.descriptor_length == 2) { |
| 195 | total_size--; |
| 196 | } |
| 197 | break; |
| 198 | |
Bob Moore | 66d3ca9 | 2008-04-10 19:06:44 +0400 | [diff] [blame] | 199 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
| 200 | |
| 201 | /* Length can be 1 or 0 */ |
| 202 | |
| 203 | if (resource->data.irq.descriptor_length == 0) { |
| 204 | total_size--; |
| 205 | } |
| 206 | break; |
| 207 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 208 | case ACPI_RESOURCE_TYPE_VENDOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 210 | * Vendor Defined Resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | * For a Vendor Specific resource, if the Length is between 1 and 7 |
| 212 | * it will be created as a Small Resource data type, otherwise it |
| 213 | * is a Large Resource data type. |
| 214 | */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 215 | if (resource->data.vendor.byte_length > 7) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 216 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 217 | /* Base size of a Large resource descriptor */ |
| 218 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 219 | total_size = |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 220 | sizeof(struct aml_resource_large_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 222 | |
| 223 | /* Add the size of the vendor-specific data */ |
| 224 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 225 | total_size = (acpi_rs_length) |
| 226 | (total_size + resource->data.vendor.byte_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | break; |
| 228 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 229 | case ACPI_RESOURCE_TYPE_END_TAG: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 231 | * End Tag: |
| 232 | * We are done -- return the accumulated total size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | */ |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 234 | *size_needed = aml_size_needed + total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 236 | /* Normal exit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 238 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 240 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | /* |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 242 | * 16-Bit Address Resource: |
| 243 | * Add the size of the optional resource_source info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | */ |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 245 | total_size = (acpi_rs_length)(total_size + |
| 246 | acpi_rs_struct_option_length |
| 247 | (&resource->data. |
| 248 | address16. |
| 249 | resource_source)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | break; |
| 251 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 252 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 254 | * 32-Bit Address Resource: |
| 255 | * Add the size of the optional resource_source info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | */ |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 257 | total_size = (acpi_rs_length)(total_size + |
| 258 | acpi_rs_struct_option_length |
| 259 | (&resource->data. |
| 260 | address32. |
| 261 | resource_source)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | break; |
| 263 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 264 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | /* |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 266 | * 64-Bit Address Resource: |
| 267 | * Add the size of the optional resource_source info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | */ |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 269 | total_size = (acpi_rs_length)(total_size + |
| 270 | acpi_rs_struct_option_length |
| 271 | (&resource->data. |
| 272 | address64. |
| 273 | resource_source)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | break; |
| 275 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 276 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 278 | * Extended IRQ Resource: |
| 279 | * Add the size of each additional optional interrupt beyond the |
| 280 | * required 1 (4 bytes for each u32 interrupt number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | */ |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 282 | total_size = (acpi_rs_length)(total_size + |
| 283 | ((resource->data. |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 284 | extended_irq. |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 285 | interrupt_count - |
| 286 | 1) * 4) + |
| 287 | /* Add the size of the optional resource_source info */ |
| 288 | acpi_rs_struct_option_length |
| 289 | (&resource->data. |
| 290 | extended_irq. |
| 291 | resource_source)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | break; |
| 293 | |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 294 | case ACPI_RESOURCE_TYPE_GPIO: |
| 295 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 296 | total_size = (acpi_rs_length)(total_size + |
| 297 | (resource->data.gpio. |
| 298 | pin_table_length * 2) + |
| 299 | resource->data.gpio. |
| 300 | resource_source. |
| 301 | string_length + |
| 302 | resource->data.gpio. |
| 303 | vendor_length); |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 304 | |
| 305 | break; |
| 306 | |
Mika Westerberg | 2b72693 | 2017-06-05 16:39:14 +0800 | [diff] [blame] | 307 | case ACPI_RESOURCE_TYPE_PIN_FUNCTION: |
| 308 | |
| 309 | total_size = (acpi_rs_length)(total_size + |
| 310 | (resource->data. |
| 311 | pin_function. |
| 312 | pin_table_length * 2) + |
| 313 | resource->data. |
| 314 | pin_function. |
| 315 | resource_source. |
| 316 | string_length + |
| 317 | resource->data. |
| 318 | pin_function. |
| 319 | vendor_length); |
| 320 | |
| 321 | break; |
| 322 | |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 323 | case ACPI_RESOURCE_TYPE_SERIAL_BUS: |
| 324 | |
| 325 | total_size = |
| 326 | acpi_gbl_aml_resource_serial_bus_sizes[resource-> |
| 327 | data. |
| 328 | common_serial_bus. |
| 329 | type]; |
| 330 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 331 | total_size = (acpi_rs_length)(total_size + |
| 332 | resource->data. |
| 333 | i2c_serial_bus. |
| 334 | resource_source. |
| 335 | string_length + |
| 336 | resource->data. |
| 337 | i2c_serial_bus. |
| 338 | vendor_length); |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 339 | |
| 340 | break; |
| 341 | |
Mika Westerberg | 97028ce | 2017-06-05 16:39:19 +0800 | [diff] [blame] | 342 | case ACPI_RESOURCE_TYPE_PIN_CONFIG: |
| 343 | |
| 344 | total_size = (acpi_rs_length)(total_size + |
| 345 | (resource->data. |
| 346 | pin_config. |
| 347 | pin_table_length * 2) + |
| 348 | resource->data.pin_config. |
| 349 | resource_source. |
| 350 | string_length + |
| 351 | resource->data.pin_config. |
| 352 | vendor_length); |
| 353 | |
| 354 | break; |
| 355 | |
Mika Westerberg | fdaa098 | 2017-06-05 16:39:25 +0800 | [diff] [blame] | 356 | case ACPI_RESOURCE_TYPE_PIN_GROUP: |
| 357 | |
| 358 | total_size = (acpi_rs_length)(total_size + |
| 359 | (resource->data.pin_group. |
| 360 | pin_table_length * 2) + |
| 361 | resource->data.pin_group. |
| 362 | resource_label. |
| 363 | string_length + |
| 364 | resource->data.pin_group. |
| 365 | vendor_length); |
| 366 | |
| 367 | break; |
| 368 | |
Mika Westerberg | f8a6c86 | 2017-06-05 16:39:31 +0800 | [diff] [blame] | 369 | case ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION: |
| 370 | |
| 371 | total_size = (acpi_rs_length)(total_size + |
| 372 | resource->data. |
| 373 | pin_group_function. |
| 374 | resource_source. |
| 375 | string_length + |
| 376 | resource->data. |
| 377 | pin_group_function. |
| 378 | resource_source_label. |
| 379 | string_length + |
| 380 | resource->data. |
| 381 | pin_group_function. |
| 382 | vendor_length); |
| 383 | |
| 384 | break; |
| 385 | |
Mika Westerberg | 044b723 | 2017-06-05 16:39:37 +0800 | [diff] [blame] | 386 | case ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG: |
| 387 | |
| 388 | total_size = (acpi_rs_length)(total_size + |
| 389 | resource->data. |
| 390 | pin_group_config. |
| 391 | resource_source. |
| 392 | string_length + |
| 393 | resource->data. |
| 394 | pin_group_config. |
| 395 | resource_source_label. |
| 396 | string_length + |
| 397 | resource->data. |
| 398 | pin_group_config. |
| 399 | vendor_length); |
| 400 | |
| 401 | break; |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 404 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 405 | break; |
| 406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 408 | /* Update the total */ |
| 409 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 410 | aml_size_needed += total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 412 | /* Point to the next object */ |
| 413 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 414 | resource = |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 415 | ACPI_ADD_PTR(struct acpi_resource, resource, |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 416 | resource->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 419 | /* Did not find an end_tag resource descriptor */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 420 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 421 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /******************************************************************************* |
| 425 | * |
| 426 | * FUNCTION: acpi_rs_get_list_length |
| 427 | * |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 428 | * PARAMETERS: aml_buffer - Pointer to the resource byte stream |
| 429 | * aml_buffer_length - Size of aml_buffer |
| 430 | * size_needed - Where the size needed is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | * |
| 432 | * RETURN: Status |
| 433 | * |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 434 | * DESCRIPTION: Takes an external resource byte stream and calculates the size |
| 435 | * buffer needed to hold the corresponding internal resource |
| 436 | * descriptor linked list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | * |
| 438 | ******************************************************************************/ |
| 439 | |
| 440 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 441 | acpi_rs_get_list_length(u8 *aml_buffer, |
| 442 | u32 aml_buffer_length, acpi_size *size_needed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 444 | acpi_status status; |
| 445 | u8 *end_aml; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 446 | u8 *buffer; |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 447 | u32 buffer_size; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | u16 temp16; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 449 | u16 resource_length; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 450 | u32 extra_struct_bytes; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 451 | u8 resource_index; |
| 452 | u8 minimum_aml_resource_length; |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 453 | union aml_resource *aml_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 455 | ACPI_FUNCTION_TRACE(rs_get_list_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 457 | *size_needed = ACPI_RS_SIZE_MIN; /* Minimum size is one end_tag */ |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 458 | end_aml = aml_buffer + aml_buffer_length; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 459 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 460 | /* Walk the list of AML resource descriptors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 462 | while (aml_buffer < end_aml) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 463 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 464 | /* Validate the Resource Type and Resource Length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Bob Moore | 886308e | 2012-12-19 05:38:07 +0000 | [diff] [blame] | 466 | status = |
| 467 | acpi_ut_validate_resource(NULL, aml_buffer, |
| 468 | &resource_index); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 469 | if (ACPI_FAILURE(status)) { |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 470 | /* |
| 471 | * Exit on failure. Cannot continue because the descriptor length |
| 472 | * may be bogus also. |
| 473 | */ |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 474 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 477 | aml_resource = (void *)aml_buffer; |
| 478 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 479 | /* Get the resource length and base (minimum) AML size */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 480 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 481 | resource_length = acpi_ut_get_resource_length(aml_buffer); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 482 | minimum_aml_resource_length = |
| 483 | acpi_gbl_resource_aml_sizes[resource_index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 485 | /* |
| 486 | * Augment the size for descriptors with optional |
| 487 | * and/or variable length fields |
| 488 | */ |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 489 | extra_struct_bytes = 0; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 490 | buffer = |
| 491 | aml_buffer + acpi_ut_get_resource_header_length(aml_buffer); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 492 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 493 | switch (acpi_ut_get_resource_type(aml_buffer)) { |
| 494 | case ACPI_RESOURCE_NAME_IRQ: |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 495 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 496 | * IRQ Resource: |
| 497 | * Get the number of bits set in the 16-bit IRQ mask |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 498 | */ |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 499 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 500 | extra_struct_bytes = acpi_rs_count_set_bits(temp16); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 501 | break; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 502 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 503 | case ACPI_RESOURCE_NAME_DMA: |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 504 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 505 | * DMA Resource: |
| 506 | * Get the number of bits set in the 8-bit DMA mask |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 507 | */ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 508 | extra_struct_bytes = acpi_rs_count_set_bits(*buffer); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 509 | break; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 510 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 511 | case ACPI_RESOURCE_NAME_VENDOR_SMALL: |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 512 | case ACPI_RESOURCE_NAME_VENDOR_LARGE: |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 513 | /* |
| 514 | * Vendor Resource: |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 515 | * Get the number of vendor data bytes |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 516 | */ |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 517 | extra_struct_bytes = resource_length; |
Feng Tang | bee6dc3 | 2012-10-31 02:27:15 +0000 | [diff] [blame] | 518 | |
| 519 | /* |
| 520 | * There is already one byte included in the minimum |
| 521 | * descriptor size. If there are extra struct bytes, |
| 522 | * subtract one from the count. |
| 523 | */ |
| 524 | if (extra_struct_bytes) { |
| 525 | extra_struct_bytes--; |
| 526 | } |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 527 | break; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 528 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 529 | case ACPI_RESOURCE_NAME_END_TAG: |
| 530 | /* |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 531 | * End Tag: This is the normal exit |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 532 | */ |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 533 | return_ACPI_STATUS(AE_OK); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 534 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 535 | case ACPI_RESOURCE_NAME_ADDRESS32: |
| 536 | case ACPI_RESOURCE_NAME_ADDRESS16: |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 537 | case ACPI_RESOURCE_NAME_ADDRESS64: |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 538 | /* |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 539 | * Address Resource: |
| 540 | * Add the size of the optional resource_source |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 541 | */ |
| 542 | extra_struct_bytes = |
| 543 | acpi_rs_stream_option_length(resource_length, |
| 544 | minimum_aml_resource_length); |
| 545 | break; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 546 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 547 | case ACPI_RESOURCE_NAME_EXTENDED_IRQ: |
| 548 | /* |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 549 | * Extended IRQ Resource: |
| 550 | * Using the interrupt_table_length, add 4 bytes for each additional |
| 551 | * interrupt. Note: at least one interrupt is required and is |
| 552 | * included in the minimum descriptor size (reason for the -1) |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 553 | */ |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 554 | extra_struct_bytes = (buffer[1] - 1) * sizeof(u32); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 555 | |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 556 | /* Add the size of the optional resource_source */ |
| 557 | |
| 558 | extra_struct_bytes += |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 559 | acpi_rs_stream_option_length(resource_length - |
| 560 | extra_struct_bytes, |
| 561 | minimum_aml_resource_length); |
| 562 | break; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 563 | |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 564 | case ACPI_RESOURCE_NAME_GPIO: |
| 565 | |
| 566 | /* Vendor data is optional */ |
| 567 | |
| 568 | if (aml_resource->gpio.vendor_length) { |
| 569 | extra_struct_bytes += |
| 570 | aml_resource->gpio.vendor_offset - |
| 571 | aml_resource->gpio.pin_table_offset + |
| 572 | aml_resource->gpio.vendor_length; |
| 573 | } else { |
| 574 | extra_struct_bytes += |
| 575 | aml_resource->large_header.resource_length + |
| 576 | sizeof(struct aml_resource_large_header) - |
| 577 | aml_resource->gpio.pin_table_offset; |
| 578 | } |
| 579 | break; |
| 580 | |
Mika Westerberg | 2b72693 | 2017-06-05 16:39:14 +0800 | [diff] [blame] | 581 | case ACPI_RESOURCE_NAME_PIN_FUNCTION: |
| 582 | |
| 583 | /* Vendor data is optional */ |
| 584 | |
| 585 | if (aml_resource->pin_function.vendor_length) { |
| 586 | extra_struct_bytes += |
| 587 | aml_resource->pin_function.vendor_offset - |
| 588 | aml_resource->pin_function. |
| 589 | pin_table_offset + |
| 590 | aml_resource->pin_function.vendor_length; |
| 591 | } else { |
| 592 | extra_struct_bytes += |
| 593 | aml_resource->large_header.resource_length + |
| 594 | sizeof(struct aml_resource_large_header) - |
| 595 | aml_resource->pin_function.pin_table_offset; |
| 596 | } |
| 597 | break; |
| 598 | |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 599 | case ACPI_RESOURCE_NAME_SERIAL_BUS: |
| 600 | |
| 601 | minimum_aml_resource_length = |
| 602 | acpi_gbl_resource_aml_serial_bus_sizes |
| 603 | [aml_resource->common_serial_bus.type]; |
| 604 | extra_struct_bytes += |
| 605 | aml_resource->common_serial_bus.resource_length - |
| 606 | minimum_aml_resource_length; |
| 607 | break; |
| 608 | |
Mika Westerberg | 97028ce | 2017-06-05 16:39:19 +0800 | [diff] [blame] | 609 | case ACPI_RESOURCE_NAME_PIN_CONFIG: |
| 610 | |
| 611 | /* Vendor data is optional */ |
| 612 | |
| 613 | if (aml_resource->pin_config.vendor_length) { |
| 614 | extra_struct_bytes += |
| 615 | aml_resource->pin_config.vendor_offset - |
| 616 | aml_resource->pin_config.pin_table_offset + |
| 617 | aml_resource->pin_config.vendor_length; |
| 618 | } else { |
| 619 | extra_struct_bytes += |
| 620 | aml_resource->large_header.resource_length + |
| 621 | sizeof(struct aml_resource_large_header) - |
| 622 | aml_resource->pin_config.pin_table_offset; |
| 623 | } |
| 624 | break; |
| 625 | |
Mika Westerberg | fdaa098 | 2017-06-05 16:39:25 +0800 | [diff] [blame] | 626 | case ACPI_RESOURCE_NAME_PIN_GROUP: |
| 627 | |
| 628 | extra_struct_bytes += |
| 629 | aml_resource->pin_group.vendor_offset - |
| 630 | aml_resource->pin_group.pin_table_offset + |
| 631 | aml_resource->pin_group.vendor_length; |
| 632 | |
| 633 | break; |
| 634 | |
Mika Westerberg | f8a6c86 | 2017-06-05 16:39:31 +0800 | [diff] [blame] | 635 | case ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION: |
| 636 | |
| 637 | extra_struct_bytes += |
| 638 | aml_resource->pin_group_function.vendor_offset - |
| 639 | aml_resource->pin_group_function.res_source_offset + |
| 640 | aml_resource->pin_group_function.vendor_length; |
| 641 | |
| 642 | break; |
| 643 | |
Mika Westerberg | 044b723 | 2017-06-05 16:39:37 +0800 | [diff] [blame] | 644 | case ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG: |
| 645 | |
| 646 | extra_struct_bytes += |
| 647 | aml_resource->pin_group_config.vendor_offset - |
| 648 | aml_resource->pin_group_config.res_source_offset + |
| 649 | aml_resource->pin_group_config.vendor_length; |
| 650 | |
| 651 | break; |
| 652 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 653 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 654 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 655 | break; |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 658 | /* |
| 659 | * Update the required buffer size for the internal descriptor structs |
| 660 | * |
| 661 | * Important: Round the size up for the appropriate alignment. This |
| 662 | * is a requirement on IA64. |
| 663 | */ |
Lin Ming | e0fe0a8 | 2011-11-16 14:38:13 +0800 | [diff] [blame] | 664 | if (acpi_ut_get_resource_type(aml_buffer) == |
| 665 | ACPI_RESOURCE_NAME_SERIAL_BUS) { |
| 666 | buffer_size = |
| 667 | acpi_gbl_resource_struct_serial_bus_sizes |
| 668 | [aml_resource->common_serial_bus.type] + |
| 669 | extra_struct_bytes; |
| 670 | } else { |
| 671 | buffer_size = |
| 672 | acpi_gbl_resource_struct_sizes[resource_index] + |
| 673 | extra_struct_bytes; |
| 674 | } |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 675 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 676 | buffer_size = (u32)ACPI_ROUND_UP_TO_NATIVE_WORD(buffer_size); |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 677 | *size_needed += buffer_size; |
| 678 | |
| 679 | ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 680 | "Type %.2X, AmlLength %.2X InternalLength %.2X\n", |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 681 | acpi_ut_get_resource_type(aml_buffer), |
| 682 | acpi_ut_get_descriptor_length(aml_buffer), |
| 683 | buffer_size)); |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 684 | |
| 685 | /* |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 686 | * Point to the next resource within the AML stream using the length |
| 687 | * contained in the resource descriptor header |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 688 | */ |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 689 | aml_buffer += acpi_ut_get_descriptor_length(aml_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 692 | /* Did not find an end_tag resource descriptor */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 693 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 694 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | /******************************************************************************* |
| 698 | * |
| 699 | * FUNCTION: acpi_rs_get_pci_routing_table_length |
| 700 | * |
| 701 | * PARAMETERS: package_object - Pointer to the package object |
| 702 | * buffer_size_needed - u32 pointer of the size buffer |
| 703 | * needed to properly return the |
| 704 | * parsed data |
| 705 | * |
| 706 | * RETURN: Status |
| 707 | * |
| 708 | * DESCRIPTION: Given a package representing a PCI routing table, this |
| 709 | * calculates the size of the corresponding linked list of |
| 710 | * descriptions. |
| 711 | * |
| 712 | ******************************************************************************/ |
| 713 | |
| 714 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 715 | acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object, |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 716 | acpi_size *buffer_size_needed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | u32 number_of_elements; |
| 719 | acpi_size temp_size_needed = 0; |
| 720 | union acpi_operand_object **top_object_list; |
| 721 | u32 index; |
| 722 | union acpi_operand_object *package_element; |
| 723 | union acpi_operand_object **sub_object_list; |
| 724 | u8 name_found; |
| 725 | u32 table_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 727 | ACPI_FUNCTION_TRACE(rs_get_pci_routing_table_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
| 729 | number_of_elements = package_object->package.count; |
| 730 | |
| 731 | /* |
| 732 | * Calculate the size of the return buffer. |
| 733 | * The base size is the number of elements * the sizes of the |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 734 | * structures. Additional space for the strings is added below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | * The minus one is to subtract the size of the u8 Source[1] |
| 736 | * member because it is added below. |
| 737 | * |
| 738 | * But each PRT_ENTRY structure has a pointer to a string and |
| 739 | * the size of that string must be found. |
| 740 | */ |
| 741 | top_object_list = package_object->package.elements; |
| 742 | |
| 743 | for (index = 0; index < number_of_elements; index++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 744 | |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 745 | /* Dereference the subpackage */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | package_element = *top_object_list; |
| 748 | |
Robert Moore | 53951bd | 2009-05-02 11:48:37 -0700 | [diff] [blame] | 749 | /* We must have a valid Package object */ |
| 750 | |
| 751 | if (!package_element || |
| 752 | (package_element->common.type != ACPI_TYPE_PACKAGE)) { |
Bob Moore | 474caff | 2009-05-21 10:10:16 +0800 | [diff] [blame] | 753 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Robert Moore | 53951bd | 2009-05-02 11:48:37 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | /* |
| 757 | * The sub_object_list will now point to an array of the |
| 758 | * four IRQ elements: Address, Pin, Source and source_index |
| 759 | */ |
| 760 | sub_object_list = package_element->package.elements; |
| 761 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 762 | /* Scan the irq_table_elements for the Source Name String */ |
| 763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | name_found = FALSE; |
| 765 | |
Lv Zheng | aa6329c | 2013-06-08 09:01:01 +0800 | [diff] [blame] | 766 | for (table_index = 0; |
| 767 | table_index < package_element->package.count |
| 768 | && !name_found; table_index++) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 769 | if (*sub_object_list && /* Null object allowed */ |
| 770 | ((ACPI_TYPE_STRING == |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 771 | (*sub_object_list)->common.type) || |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 772 | ((ACPI_TYPE_LOCAL_REFERENCE == |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 773 | (*sub_object_list)->common.type) && |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 774 | ((*sub_object_list)->reference.class == |
| 775 | ACPI_REFCLASS_NAME)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | name_found = TRUE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 777 | } else { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 778 | /* Look at the next element */ |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | sub_object_list++; |
| 781 | } |
| 782 | } |
| 783 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 784 | temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 786 | /* Was a String type found? */ |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | if (name_found) { |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 789 | if ((*sub_object_list)->common.type == ACPI_TYPE_STRING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | /* |
| 791 | * The length String.Length field does not include the |
| 792 | * terminating NULL, add 1 |
| 793 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 794 | temp_size_needed += ((acpi_size) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 795 | (*sub_object_list)->string. |
| 796 | length + 1); |
| 797 | } else { |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 798 | temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | /* |
| 802 | * If no name was found, then this is a NULL, which is |
| 803 | * translated as a u32 zero. |
| 804 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 805 | temp_size_needed += sizeof(u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* Round up the size since each element must be aligned */ |
| 809 | |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 810 | temp_size_needed = ACPI_ROUND_UP_TO_64BIT(temp_size_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 812 | /* Point to the next union acpi_operand_object */ |
| 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | top_object_list++; |
| 815 | } |
| 816 | |
| 817 | /* |
Bob Moore | ea936b7 | 2006-02-17 00:00:00 -0500 | [diff] [blame] | 818 | * Add an extra element to the end of the list, essentially a |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 819 | * NULL terminator |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 821 | *buffer_size_needed = |
| 822 | temp_size_needed + sizeof(struct acpi_pci_routing_table); |
| 823 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |