Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: rscalc - Calculate stream and list lengths | |
4 | * | |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
9 | * All rights reserved. | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acresrc.h> | |
46 | #include <acpi/amlcode.h> | |
bda663d3 | 47 | #include <acpi/amlresrc.h> |
1da177e4 LT |
48 | #include <acpi/acnamesp.h> |
49 | ||
50 | #define _COMPONENT ACPI_RESOURCES | |
4be44fcd | 51 | ACPI_MODULE_NAME("rscalc") |
1da177e4 | 52 | |
bda663d3 RM |
53 | /* |
54 | * Base sizes for external resource descriptors, indexed by internal type. | |
55 | * Includes size of the descriptor header (1 byte for small descriptors, | |
56 | * 3 bytes for large descriptors) | |
57 | */ | |
58 | static u8 acpi_gbl_stream_sizes[] = { | |
59 | 4, /* ACPI_RSTYPE_IRQ (Byte 3 is optional, but always created) */ | |
60 | 3, /* ACPI_RSTYPE_DMA */ | |
61 | 2, /* ACPI_RSTYPE_START_DPF (Byte 1 is optional, but always created) */ | |
62 | 1, /* ACPI_RSTYPE_END_DPF */ | |
63 | 8, /* ACPI_RSTYPE_IO */ | |
64 | 4, /* ACPI_RSTYPE_FIXED_IO */ | |
65 | 1, /* ACPI_RSTYPE_VENDOR */ | |
66 | 2, /* ACPI_RSTYPE_END_TAG */ | |
67 | 12, /* ACPI_RSTYPE_MEM24 */ | |
68 | 20, /* ACPI_RSTYPE_MEM32 */ | |
69 | 12, /* ACPI_RSTYPE_FIXED_MEM32 */ | |
70 | 16, /* ACPI_RSTYPE_ADDRESS16 */ | |
71 | 26, /* ACPI_RSTYPE_ADDRESS32 */ | |
72 | 46, /* ACPI_RSTYPE_ADDRESS64 */ | |
73 | 9, /* ACPI_RSTYPE_EXT_IRQ */ | |
74 | 15 /* ACPI_RSTYPE_GENERIC_REG */ | |
75 | }; | |
76 | ||
77 | /* | |
78 | * Base sizes of resource descriptors, both the actual AML stream length and | |
79 | * size of the internal struct representation. | |
80 | */ | |
486368bf | 81 | struct acpi_resource_sizes { |
bda663d3 RM |
82 | u8 minimum_stream_size; |
83 | u8 minimum_struct_size; | |
486368bf | 84 | }; |
bda663d3 | 85 | |
486368bf LB |
86 | static struct acpi_resource_sizes acpi_gbl_sm_resource_sizes[] = { |
87 | {0, 0}, /* 0x00, Reserved */ | |
88 | {0, 0}, /* 0x01, Reserved */ | |
89 | {0, 0}, /* 0x02, Reserved */ | |
90 | {0, 0}, /* 0x03, Reserved */ | |
91 | {3, ACPI_SIZEOF_RESOURCE(struct acpi_resource_irq)}, /* ACPI_RDESC_TYPE_IRQ_FORMAT */ | |
92 | {3, ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma)}, /* ACPI_RDESC_TYPE_DMA_FORMAT */ | |
93 | {1, ACPI_SIZEOF_RESOURCE(struct acpi_resource_start_dpf)}, /* ACPI_RDESC_TYPE_START_DEPENDENT */ | |
94 | {1, ACPI_RESOURCE_LENGTH}, /* ACPI_RDESC_TYPE_END_DEPENDENT */ | |
95 | {8, ACPI_SIZEOF_RESOURCE(struct acpi_resource_io)}, /* ACPI_RDESC_TYPE_IO_PORT */ | |
96 | {4, ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io)}, /* ACPI_RDESC_TYPE_FIXED_IO_PORT */ | |
97 | {0, 0}, /* 0x0A, Reserved */ | |
98 | {0, 0}, /* 0x0B, Reserved */ | |
99 | {0, 0}, /* 0x0C, Reserved */ | |
100 | {0, 0}, /* 0x0D, Reserved */ | |
101 | {1, ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor)}, /* ACPI_RDESC_TYPE_SMALL_VENDOR */ | |
102 | {2, ACPI_RESOURCE_LENGTH}, /* ACPI_RDESC_TYPE_END_TAG */ | |
bda663d3 RM |
103 | }; |
104 | ||
486368bf LB |
105 | static struct acpi_resource_sizes acpi_gbl_lg_resource_sizes[] = { |
106 | {0, 0}, /* 0x00, Reserved */ | |
107 | {12, ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24)}, /* ACPI_RDESC_TYPE_MEMORY_24 */ | |
108 | {15, ACPI_SIZEOF_RESOURCE(struct acpi_resource_generic_reg)}, /* ACPI_RDESC_TYPE_GENERIC_REGISTER */ | |
109 | {0, 0}, /* 0x03, Reserved */ | |
110 | {3, ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor)}, /* ACPI_RDESC_TYPE_LARGE_VENDOR */ | |
111 | {20, ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32)}, /* ACPI_RDESC_TYPE_MEMORY_32 */ | |
112 | {12, ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_mem32)}, /* ACPI_RDESC_TYPE_FIXED_MEMORY_32 */ | |
113 | {26, ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32)}, /* ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE */ | |
114 | {16, ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16)}, /* ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE */ | |
115 | {9, ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq)}, /* ACPI_RDESC_TYPE_EXTENDED_XRUPT */ | |
116 | {46, ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64)}, /* ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE */ | |
117 | {56, ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64)}, /* ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE */ | |
bda663d3 RM |
118 | }; |
119 | ||
120 | /* Local prototypes */ | |
121 | ||
122 | static u8 acpi_rs_count_set_bits(u16 bit_field); | |
123 | ||
486368bf | 124 | static struct acpi_resource_sizes *acpi_rs_get_resource_sizes(u8 resource_type); |
bda663d3 RM |
125 | |
126 | static u16 acpi_rs_get_resource_length(u8 * resource); | |
127 | ||
128 | static acpi_size | |
129 | acpi_rs_struct_option_length(struct acpi_resource_source *resource_source); | |
130 | ||
131 | static u32 | |
132 | acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length); | |
133 | ||
1da177e4 LT |
134 | /******************************************************************************* |
135 | * | |
bda663d3 | 136 | * FUNCTION: acpi_rs_count_set_bits |
1da177e4 | 137 | * |
bda663d3 | 138 | * PARAMETERS: bit_field - Field in which to count bits |
1da177e4 | 139 | * |
bda663d3 | 140 | * RETURN: Number of bits set within the field |
1da177e4 | 141 | * |
bda663d3 RM |
142 | * DESCRIPTION: Count the number of bits set in a resource field. Used for |
143 | * (Short descriptor) interrupt and DMA lists. | |
1da177e4 LT |
144 | * |
145 | ******************************************************************************/ | |
1da177e4 | 146 | |
bda663d3 RM |
147 | static u8 acpi_rs_count_set_bits(u16 bit_field) |
148 | { | |
149 | u8 bits_set; | |
44f6c012 | 150 | |
bda663d3 | 151 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 152 | |
bda663d3 RM |
153 | for (bits_set = 0; bit_field; bits_set++) { |
154 | /* Zero the least significant bit that is set */ | |
1da177e4 | 155 | |
bda663d3 RM |
156 | bit_field &= (bit_field - 1); |
157 | } | |
1da177e4 | 158 | |
bda663d3 RM |
159 | return (bits_set); |
160 | } | |
1da177e4 | 161 | |
bda663d3 RM |
162 | /******************************************************************************* |
163 | * | |
164 | * FUNCTION: acpi_rs_get_resource_sizes | |
165 | * | |
166 | * PARAMETERS: resource_type - Byte 0 of a resource descriptor | |
167 | * | |
168 | * RETURN: Pointer to the resource conversion handler | |
169 | * | |
170 | * DESCRIPTION: Extract the Resource Type/Name from the first byte of | |
171 | * a resource descriptor. | |
172 | * | |
173 | ******************************************************************************/ | |
1da177e4 | 174 | |
486368bf | 175 | static struct acpi_resource_sizes *acpi_rs_get_resource_sizes(u8 resource_type) |
bda663d3 | 176 | { |
486368bf | 177 | struct acpi_resource_sizes *size_info; |
1da177e4 | 178 | |
bda663d3 | 179 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 180 | |
bda663d3 | 181 | /* Determine if this is a small or large resource */ |
1da177e4 | 182 | |
bda663d3 RM |
183 | if (resource_type & ACPI_RDESC_TYPE_LARGE) { |
184 | /* Large Resource Type -- bits 6:0 contain the name */ | |
1da177e4 | 185 | |
bda663d3 RM |
186 | if (resource_type > ACPI_RDESC_LARGE_MAX) { |
187 | return (NULL); | |
188 | } | |
1da177e4 | 189 | |
bda663d3 RM |
190 | size_info = &acpi_gbl_lg_resource_sizes[(resource_type & |
191 | ACPI_RDESC_LARGE_MASK)]; | |
192 | } else { | |
193 | /* Small Resource Type -- bits 6:3 contain the name */ | |
1da177e4 | 194 | |
bda663d3 RM |
195 | size_info = &acpi_gbl_sm_resource_sizes[((resource_type & |
196 | ACPI_RDESC_SMALL_MASK) | |
197 | >> 3)]; | |
198 | } | |
1da177e4 | 199 | |
bda663d3 | 200 | /* Zero entry indicates an invalid resource type */ |
1da177e4 | 201 | |
bda663d3 RM |
202 | if (!size_info->minimum_stream_size) { |
203 | return (NULL); | |
204 | } | |
1da177e4 | 205 | |
bda663d3 RM |
206 | return (size_info); |
207 | } | |
1da177e4 | 208 | |
bda663d3 RM |
209 | /******************************************************************************* |
210 | * | |
211 | * FUNCTION: acpi_rs_get_resource_length | |
212 | * | |
213 | * PARAMETERS: Resource - Pointer to the resource descriptor | |
214 | * | |
215 | * RETURN: Byte length of the (AML byte stream) descriptor. By definition, | |
216 | * this does not include the size of the descriptor header and the | |
217 | * length field itself. | |
218 | * | |
219 | * DESCRIPTION: Extract the length of a resource descriptor. | |
220 | * | |
221 | ******************************************************************************/ | |
44f6c012 | 222 | |
bda663d3 RM |
223 | static u16 acpi_rs_get_resource_length(u8 * resource) |
224 | { | |
225 | u16 resource_length; | |
44f6c012 | 226 | |
bda663d3 | 227 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 228 | |
bda663d3 | 229 | /* Determine if this is a small or large resource */ |
1da177e4 | 230 | |
bda663d3 RM |
231 | if (*resource & ACPI_RDESC_TYPE_LARGE) { |
232 | /* Large Resource type -- length is in bytes 1-2 */ | |
44f6c012 | 233 | |
bda663d3 | 234 | ACPI_MOVE_16_TO_16(&resource_length, (resource + 1)); |
1da177e4 | 235 | |
bda663d3 RM |
236 | } else { |
237 | /* Small Resource Type -- bits 2:0 of byte 0 contain the length */ | |
44f6c012 | 238 | |
bda663d3 RM |
239 | resource_length = |
240 | (u16) (*resource & ACPI_RDESC_SMALL_LENGTH_MASK); | |
1da177e4 LT |
241 | } |
242 | ||
bda663d3 | 243 | return (resource_length); |
1da177e4 LT |
244 | } |
245 | ||
1da177e4 LT |
246 | /******************************************************************************* |
247 | * | |
bda663d3 | 248 | * FUNCTION: acpi_rs_struct_option_length |
1da177e4 | 249 | * |
bda663d3 | 250 | * PARAMETERS: resource_source - Pointer to optional descriptor field |
1da177e4 LT |
251 | * |
252 | * RETURN: Status | |
253 | * | |
bda663d3 RM |
254 | * DESCRIPTION: Common code to handle optional resource_source_index and |
255 | * resource_source fields in some Large descriptors. Used during | |
256 | * list-to-stream conversion | |
1da177e4 LT |
257 | * |
258 | ******************************************************************************/ | |
259 | ||
bda663d3 RM |
260 | static acpi_size |
261 | acpi_rs_struct_option_length(struct acpi_resource_source *resource_source) | |
1da177e4 | 262 | { |
bda663d3 RM |
263 | ACPI_FUNCTION_ENTRY(); |
264 | ||
265 | /* | |
266 | * If the resource_source string is valid, return the size of the string | |
267 | * (string_length includes the NULL terminator) plus the size of the | |
268 | * resource_source_index (1). | |
269 | */ | |
270 | if (resource_source->string_ptr) { | |
271 | return ((acpi_size) resource_source->string_length + 1); | |
272 | } | |
1da177e4 | 273 | |
bda663d3 RM |
274 | return (0); |
275 | } | |
1da177e4 | 276 | |
bda663d3 RM |
277 | /******************************************************************************* |
278 | * | |
279 | * FUNCTION: acpi_rs_stream_option_length | |
280 | * | |
281 | * PARAMETERS: resource_length - Length from the resource header | |
282 | * minimum_total_length - Minimum length of this resource, before | |
283 | * any optional fields. Includes header size | |
284 | * | |
285 | * RETURN: Length of optional string (0 if no string present) | |
286 | * | |
287 | * DESCRIPTION: Common code to handle optional resource_source_index and | |
288 | * resource_source fields in some Large descriptors. Used during | |
289 | * stream-to-list conversion | |
290 | * | |
291 | ******************************************************************************/ | |
1da177e4 | 292 | |
bda663d3 RM |
293 | static u32 |
294 | acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length) | |
295 | { | |
296 | u32 string_length = 0; | |
297 | u32 minimum_resource_length; | |
1da177e4 | 298 | |
bda663d3 | 299 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 300 | |
bda663d3 RM |
301 | /* |
302 | * The resource_source_index and resource_source are optional elements of some | |
303 | * Large-type resource descriptors. | |
304 | */ | |
44f6c012 | 305 | |
bda663d3 | 306 | /* Compute minimum size of the data part of the resource descriptor */ |
1da177e4 | 307 | |
bda663d3 RM |
308 | minimum_resource_length = |
309 | minimum_total_length - sizeof(struct asl_large_header); | |
1da177e4 | 310 | |
bda663d3 RM |
311 | /* |
312 | * If the length of the actual resource descriptor is greater than the ACPI | |
313 | * spec-defined minimum length, it means that a resource_source_index exists | |
314 | * and is followed by a (required) null terminated string. The string length | |
315 | * (including the null terminator) is the resource length minus the minimum | |
316 | * length, minus one byte for the resource_source_index itself. | |
317 | */ | |
318 | if (resource_length > minimum_resource_length) { | |
319 | /* Compute the length of the optional string */ | |
1da177e4 | 320 | |
bda663d3 RM |
321 | string_length = resource_length - minimum_resource_length - 1; |
322 | } | |
1da177e4 | 323 | |
bda663d3 | 324 | /* Round up length to 32 bits for internal structure alignment */ |
1da177e4 | 325 | |
bda663d3 RM |
326 | return (ACPI_ROUND_UP_to_32_bITS(string_length)); |
327 | } | |
1da177e4 | 328 | |
bda663d3 RM |
329 | /******************************************************************************* |
330 | * | |
331 | * FUNCTION: acpi_rs_get_byte_stream_length | |
332 | * | |
333 | * PARAMETERS: Resource - Pointer to the resource linked list | |
334 | * size_needed - Where the required size is returned | |
335 | * | |
336 | * RETURN: Status | |
337 | * | |
338 | * DESCRIPTION: Takes a linked list of internal resource descriptors and | |
339 | * calculates the size buffer needed to hold the corresponding | |
340 | * external resource byte stream. | |
341 | * | |
342 | ******************************************************************************/ | |
1da177e4 | 343 | |
bda663d3 RM |
344 | acpi_status |
345 | acpi_rs_get_byte_stream_length(struct acpi_resource * resource, | |
346 | acpi_size * size_needed) | |
347 | { | |
348 | acpi_size byte_stream_size_needed = 0; | |
349 | acpi_size segment_size; | |
1da177e4 | 350 | |
bda663d3 | 351 | ACPI_FUNCTION_TRACE("rs_get_byte_stream_length"); |
1da177e4 | 352 | |
bda663d3 | 353 | /* Traverse entire list of internal resource descriptors */ |
1da177e4 | 354 | |
bda663d3 RM |
355 | while (resource) { |
356 | /* Validate the descriptor type */ | |
1da177e4 | 357 | |
bda663d3 RM |
358 | if (resource->type > ACPI_RSTYPE_MAX) { |
359 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); | |
360 | } | |
44f6c012 | 361 | |
bda663d3 | 362 | /* Get the base size of the (external stream) resource descriptor */ |
1da177e4 | 363 | |
bda663d3 | 364 | segment_size = acpi_gbl_stream_sizes[resource->type]; |
1da177e4 | 365 | |
bda663d3 RM |
366 | /* |
367 | * Augment the base size for descriptors with optional and/or | |
368 | * variable-length fields | |
369 | */ | |
370 | switch (resource->type) { | |
371 | case ACPI_RSTYPE_VENDOR: | |
1da177e4 | 372 | /* |
bda663d3 RM |
373 | * Vendor Defined Resource: |
374 | * For a Vendor Specific resource, if the Length is between 1 and 7 | |
375 | * it will be created as a Small Resource data type, otherwise it | |
376 | * is a Large Resource data type. | |
1da177e4 | 377 | */ |
bda663d3 RM |
378 | if (resource->data.vendor_specific.length > 7) { |
379 | /* Base size of a Large resource descriptor */ | |
1da177e4 | 380 | |
bda663d3 | 381 | segment_size = 3; |
1da177e4 LT |
382 | } |
383 | ||
bda663d3 | 384 | /* Add the size of the vendor-specific data */ |
44f6c012 | 385 | |
bda663d3 | 386 | segment_size += resource->data.vendor_specific.length; |
1da177e4 LT |
387 | break; |
388 | ||
bda663d3 | 389 | case ACPI_RSTYPE_END_TAG: |
1da177e4 | 390 | /* |
bda663d3 RM |
391 | * End Tag: |
392 | * We are done -- return the accumulated total size. | |
1da177e4 | 393 | */ |
bda663d3 | 394 | *size_needed = byte_stream_size_needed + segment_size; |
1da177e4 | 395 | |
bda663d3 | 396 | /* Normal exit */ |
1da177e4 | 397 | |
bda663d3 | 398 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 399 | |
bda663d3 | 400 | case ACPI_RSTYPE_ADDRESS16: |
1da177e4 | 401 | /* |
bda663d3 RM |
402 | * 16-Bit Address Resource: |
403 | * Add the size of the optional resource_source info | |
1da177e4 | 404 | */ |
bda663d3 RM |
405 | segment_size += |
406 | acpi_rs_struct_option_length(&resource->data. | |
407 | address16. | |
408 | resource_source); | |
1da177e4 LT |
409 | break; |
410 | ||
bda663d3 | 411 | case ACPI_RSTYPE_ADDRESS32: |
1da177e4 | 412 | /* |
bda663d3 RM |
413 | * 32-Bit Address Resource: |
414 | * Add the size of the optional resource_source info | |
1da177e4 | 415 | */ |
bda663d3 RM |
416 | segment_size += |
417 | acpi_rs_struct_option_length(&resource->data. | |
418 | address32. | |
419 | resource_source); | |
1da177e4 LT |
420 | break; |
421 | ||
bda663d3 | 422 | case ACPI_RSTYPE_ADDRESS64: |
1da177e4 | 423 | /* |
bda663d3 RM |
424 | * 64-Bit Address Resource: |
425 | * Add the size of the optional resource_source info | |
1da177e4 | 426 | */ |
bda663d3 RM |
427 | segment_size += |
428 | acpi_rs_struct_option_length(&resource->data. | |
429 | address64. | |
430 | resource_source); | |
1da177e4 LT |
431 | break; |
432 | ||
bda663d3 | 433 | case ACPI_RSTYPE_EXT_IRQ: |
1da177e4 | 434 | /* |
bda663d3 RM |
435 | * Extended IRQ Resource: |
436 | * Add the size of each additional optional interrupt beyond the | |
437 | * required 1 (4 bytes for each u32 interrupt number) | |
1da177e4 | 438 | */ |
bda663d3 RM |
439 | segment_size += (((acpi_size) |
440 | resource->data.extended_irq. | |
441 | number_of_interrupts - 1) * 4); | |
1da177e4 | 442 | |
bda663d3 | 443 | /* Add the size of the optional resource_source info */ |
1da177e4 | 444 | |
bda663d3 RM |
445 | segment_size += |
446 | acpi_rs_struct_option_length(&resource->data. | |
447 | extended_irq. | |
448 | resource_source); | |
449 | break; | |
1da177e4 | 450 | |
bda663d3 | 451 | default: |
1da177e4 | 452 | break; |
bda663d3 | 453 | } |
1da177e4 | 454 | |
bda663d3 | 455 | /* Update the total */ |
1da177e4 | 456 | |
bda663d3 | 457 | byte_stream_size_needed += segment_size; |
1da177e4 | 458 | |
bda663d3 | 459 | /* Point to the next object */ |
1da177e4 | 460 | |
bda663d3 RM |
461 | resource = ACPI_PTR_ADD(struct acpi_resource, |
462 | resource, resource->length); | |
463 | } | |
1da177e4 | 464 | |
bda663d3 | 465 | /* Did not find an END_TAG descriptor */ |
1da177e4 | 466 | |
bda663d3 RM |
467 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
468 | } | |
1da177e4 | 469 | |
bda663d3 RM |
470 | /******************************************************************************* |
471 | * | |
472 | * FUNCTION: acpi_rs_get_list_length | |
473 | * | |
474 | * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream | |
475 | * byte_stream_buffer_length - Size of byte_stream_buffer | |
476 | * size_needed - Where the size needed is returned | |
477 | * | |
478 | * RETURN: Status | |
479 | * | |
480 | * DESCRIPTION: Takes an external resource byte stream and calculates the size | |
481 | * buffer needed to hold the corresponding internal resource | |
482 | * descriptor linked list. | |
483 | * | |
484 | ******************************************************************************/ | |
485 | ||
486 | acpi_status | |
487 | acpi_rs_get_list_length(u8 * byte_stream_buffer, | |
488 | u32 byte_stream_buffer_length, acpi_size * size_needed) | |
489 | { | |
490 | u8 *buffer; | |
486368bf | 491 | struct acpi_resource_sizes *resource_info; |
bda663d3 RM |
492 | u32 buffer_size = 0; |
493 | u32 bytes_parsed = 0; | |
494 | u8 resource_type; | |
495 | u16 temp16; | |
496 | u16 resource_length; | |
497 | u16 header_length; | |
498 | u32 extra_struct_bytes; | |
1da177e4 | 499 | |
bda663d3 | 500 | ACPI_FUNCTION_TRACE("rs_get_list_length"); |
1da177e4 | 501 | |
bda663d3 RM |
502 | while (bytes_parsed < byte_stream_buffer_length) { |
503 | /* The next byte in the stream is the resource descriptor type */ | |
44f6c012 | 504 | |
bda663d3 | 505 | resource_type = acpi_rs_get_resource_type(*byte_stream_buffer); |
1da177e4 | 506 | |
bda663d3 | 507 | /* Get the base stream size and structure sizes for the descriptor */ |
1da177e4 | 508 | |
bda663d3 RM |
509 | resource_info = acpi_rs_get_resource_sizes(resource_type); |
510 | if (!resource_info) { | |
4be44fcd | 511 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
1da177e4 LT |
512 | } |
513 | ||
bda663d3 RM |
514 | /* Get the Length field from the input resource descriptor */ |
515 | ||
516 | resource_length = | |
517 | acpi_rs_get_resource_length(byte_stream_buffer); | |
518 | ||
519 | /* Augment the size for descriptors with optional fields */ | |
520 | ||
521 | extra_struct_bytes = 0; | |
522 | ||
523 | if (!(resource_type & ACPI_RDESC_TYPE_LARGE)) { | |
524 | /* | |
525 | * Small resource descriptors | |
526 | */ | |
527 | header_length = 1; | |
528 | buffer = byte_stream_buffer + header_length; | |
529 | ||
530 | switch (resource_type) { | |
531 | case ACPI_RDESC_TYPE_IRQ_FORMAT: | |
532 | /* | |
533 | * IRQ Resource: | |
534 | * Get the number of bits set in the IRQ word | |
535 | */ | |
536 | ACPI_MOVE_16_TO_16(&temp16, buffer); | |
537 | ||
538 | extra_struct_bytes = | |
539 | (acpi_rs_count_set_bits(temp16) * | |
540 | sizeof(u32)); | |
541 | break; | |
542 | ||
543 | case ACPI_RDESC_TYPE_DMA_FORMAT: | |
544 | /* | |
545 | * DMA Resource: | |
546 | * Get the number of bits set in the DMA channels byte | |
547 | */ | |
548 | extra_struct_bytes = | |
549 | (acpi_rs_count_set_bits((u16) * buffer) * | |
550 | sizeof(u32)); | |
551 | break; | |
552 | ||
553 | case ACPI_RDESC_TYPE_SMALL_VENDOR: | |
554 | /* | |
555 | * Vendor Specific Resource: | |
556 | * Ensure a 32-bit boundary for the structure | |
557 | */ | |
558 | extra_struct_bytes = | |
559 | ACPI_ROUND_UP_to_32_bITS(resource_length); | |
560 | break; | |
561 | ||
562 | case ACPI_RDESC_TYPE_END_TAG: | |
563 | /* | |
564 | * End Tag: | |
565 | * Terminate the loop now | |
566 | */ | |
567 | byte_stream_buffer_length = bytes_parsed; | |
568 | break; | |
569 | ||
570 | default: | |
571 | break; | |
572 | } | |
573 | } else { | |
574 | /* | |
575 | * Large resource descriptors | |
576 | */ | |
577 | header_length = sizeof(struct asl_large_header); | |
578 | buffer = byte_stream_buffer + header_length; | |
579 | ||
580 | switch (resource_type) { | |
581 | case ACPI_RDESC_TYPE_LARGE_VENDOR: | |
582 | /* | |
583 | * Vendor Defined Resource: | |
584 | * Add vendor data and ensure a 32-bit boundary for the structure | |
585 | */ | |
586 | extra_struct_bytes = | |
587 | ACPI_ROUND_UP_to_32_bITS(resource_length); | |
588 | break; | |
589 | ||
590 | case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE: | |
591 | case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE: | |
592 | /* | |
593 | * 32-Bit or 16-bit Address Resource: | |
594 | * Add the size of any optional data (resource_source) | |
595 | */ | |
596 | extra_struct_bytes = | |
597 | acpi_rs_stream_option_length | |
598 | (resource_length, | |
599 | resource_info->minimum_stream_size); | |
600 | break; | |
601 | ||
602 | case ACPI_RDESC_TYPE_EXTENDED_XRUPT: | |
603 | /* | |
604 | * Extended IRQ: | |
605 | * Point past the interrupt_vector_flags to get the | |
606 | * interrupt_table_length. | |
607 | */ | |
608 | buffer++; | |
609 | ||
610 | /* | |
611 | * Add 4 bytes for each additional interrupt. Note: at least one | |
612 | * interrupt is required and is included in the minimum | |
613 | * descriptor size | |
614 | */ | |
615 | extra_struct_bytes = | |
616 | ((*buffer - 1) * sizeof(u32)); | |
617 | ||
618 | /* Add the size of any optional data (resource_source) */ | |
619 | ||
620 | extra_struct_bytes += | |
621 | acpi_rs_stream_option_length(resource_length | |
622 | - | |
623 | extra_struct_bytes, | |
624 | resource_info-> | |
625 | minimum_stream_size); | |
626 | break; | |
627 | ||
628 | case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE: | |
629 | /* | |
630 | * 64-Bit Address Resource: | |
631 | * Add the size of any optional data (resource_source) | |
632 | * Ensure a 64-bit boundary for the structure | |
633 | */ | |
634 | extra_struct_bytes = | |
635 | ACPI_ROUND_UP_to_64_bITS | |
636 | (acpi_rs_stream_option_length | |
637 | (resource_length, | |
638 | resource_info->minimum_stream_size)); | |
639 | break; | |
640 | ||
641 | default: | |
642 | break; | |
643 | } | |
644 | } | |
44f6c012 | 645 | |
bda663d3 | 646 | /* Update the required buffer size for the internal descriptor structs */ |
1da177e4 | 647 | |
bda663d3 RM |
648 | temp16 = |
649 | (u16) (resource_info->minimum_struct_size + | |
650 | extra_struct_bytes); | |
651 | buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(temp16); | |
44f6c012 | 652 | |
bda663d3 RM |
653 | /* |
654 | * Update byte count and point to the next resource within the stream | |
655 | * using the size of the header plus the length contained in the header | |
656 | */ | |
657 | temp16 = (u16) (header_length + resource_length); | |
658 | bytes_parsed += temp16; | |
659 | byte_stream_buffer += temp16; | |
1da177e4 LT |
660 | } |
661 | ||
44f6c012 RM |
662 | /* This is the data the caller needs */ |
663 | ||
1da177e4 | 664 | *size_needed = buffer_size; |
4be44fcd | 665 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
666 | } |
667 | ||
1da177e4 LT |
668 | /******************************************************************************* |
669 | * | |
670 | * FUNCTION: acpi_rs_get_pci_routing_table_length | |
671 | * | |
672 | * PARAMETERS: package_object - Pointer to the package object | |
673 | * buffer_size_needed - u32 pointer of the size buffer | |
674 | * needed to properly return the | |
675 | * parsed data | |
676 | * | |
677 | * RETURN: Status | |
678 | * | |
679 | * DESCRIPTION: Given a package representing a PCI routing table, this | |
680 | * calculates the size of the corresponding linked list of | |
681 | * descriptions. | |
682 | * | |
683 | ******************************************************************************/ | |
684 | ||
685 | acpi_status | |
4be44fcd LB |
686 | acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object, |
687 | acpi_size * buffer_size_needed) | |
1da177e4 | 688 | { |
4be44fcd LB |
689 | u32 number_of_elements; |
690 | acpi_size temp_size_needed = 0; | |
691 | union acpi_operand_object **top_object_list; | |
692 | u32 index; | |
693 | union acpi_operand_object *package_element; | |
694 | union acpi_operand_object **sub_object_list; | |
695 | u8 name_found; | |
696 | u32 table_index; | |
1da177e4 | 697 | |
4be44fcd | 698 | ACPI_FUNCTION_TRACE("rs_get_pci_routing_table_length"); |
1da177e4 LT |
699 | |
700 | number_of_elements = package_object->package.count; | |
701 | ||
702 | /* | |
703 | * Calculate the size of the return buffer. | |
704 | * The base size is the number of elements * the sizes of the | |
705 | * structures. Additional space for the strings is added below. | |
706 | * The minus one is to subtract the size of the u8 Source[1] | |
707 | * member because it is added below. | |
708 | * | |
709 | * But each PRT_ENTRY structure has a pointer to a string and | |
710 | * the size of that string must be found. | |
711 | */ | |
712 | top_object_list = package_object->package.elements; | |
713 | ||
714 | for (index = 0; index < number_of_elements; index++) { | |
44f6c012 RM |
715 | /* Dereference the sub-package */ |
716 | ||
1da177e4 LT |
717 | package_element = *top_object_list; |
718 | ||
719 | /* | |
720 | * The sub_object_list will now point to an array of the | |
721 | * four IRQ elements: Address, Pin, Source and source_index | |
722 | */ | |
723 | sub_object_list = package_element->package.elements; | |
724 | ||
44f6c012 RM |
725 | /* Scan the irq_table_elements for the Source Name String */ |
726 | ||
1da177e4 LT |
727 | name_found = FALSE; |
728 | ||
4be44fcd LB |
729 | for (table_index = 0; table_index < 4 && !name_found; |
730 | table_index++) { | |
44f6c012 | 731 | if ((ACPI_TYPE_STRING == |
4be44fcd LB |
732 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) |
733 | || | |
734 | ((ACPI_TYPE_LOCAL_REFERENCE == | |
735 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) | |
736 | && ((*sub_object_list)->reference.opcode == | |
737 | AML_INT_NAMEPATH_OP))) { | |
1da177e4 | 738 | name_found = TRUE; |
4be44fcd | 739 | } else { |
44f6c012 RM |
740 | /* Look at the next element */ |
741 | ||
1da177e4 LT |
742 | sub_object_list++; |
743 | } | |
744 | } | |
745 | ||
4be44fcd | 746 | temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4); |
1da177e4 | 747 | |
44f6c012 RM |
748 | /* Was a String type found? */ |
749 | ||
1da177e4 | 750 | if (name_found) { |
4be44fcd LB |
751 | if (ACPI_GET_OBJECT_TYPE(*sub_object_list) == |
752 | ACPI_TYPE_STRING) { | |
1da177e4 LT |
753 | /* |
754 | * The length String.Length field does not include the | |
755 | * terminating NULL, add 1 | |
756 | */ | |
44f6c012 | 757 | temp_size_needed += ((acpi_size) |
4be44fcd LB |
758 | (*sub_object_list)->string. |
759 | length + 1); | |
760 | } else { | |
486368bf LB |
761 | temp_size_needed += |
762 | acpi_ns_get_pathname_length((*sub_object_list)->reference.node); | |
1da177e4 | 763 | } |
4be44fcd | 764 | } else { |
1da177e4 LT |
765 | /* |
766 | * If no name was found, then this is a NULL, which is | |
767 | * translated as a u32 zero. | |
768 | */ | |
4be44fcd | 769 | temp_size_needed += sizeof(u32); |
1da177e4 LT |
770 | } |
771 | ||
772 | /* Round up the size since each element must be aligned */ | |
773 | ||
4be44fcd | 774 | temp_size_needed = ACPI_ROUND_UP_to_64_bITS(temp_size_needed); |
1da177e4 | 775 | |
44f6c012 RM |
776 | /* Point to the next union acpi_operand_object */ |
777 | ||
1da177e4 LT |
778 | top_object_list++; |
779 | } | |
780 | ||
781 | /* | |
44f6c012 RM |
782 | * Adding an extra element to the end of the list, essentially a |
783 | * NULL terminator | |
1da177e4 | 784 | */ |
4be44fcd LB |
785 | *buffer_size_needed = |
786 | temp_size_needed + sizeof(struct acpi_pci_routing_table); | |
787 | return_ACPI_STATUS(AE_OK); | |
1da177e4 | 788 | } |