diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-02-02 01:06:15 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-02-02 01:06:15 -0500 |
commit | 59ed2f59e4ea6a32f9591e378da7935f713a7000 (patch) | |
tree | a1276a611dbb1bc44685ef8af363e99603e60047 /drivers/acpi/resources/rscalc.c | |
parent | 9ad11ab48b1ad618bf47076e9e579f267f5306c2 (diff) | |
parent | b8e4d89357fc434618a59c1047cac72641191805 (diff) |
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6
Diffstat (limited to 'drivers/acpi/resources/rscalc.c')
-rw-r--r-- | drivers/acpi/resources/rscalc.c | 831 |
1 files changed, 306 insertions, 525 deletions
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c index 378f58390fc1..7d6481d9fbec 100644 --- a/drivers/acpi/resources/rscalc.c +++ b/drivers/acpi/resources/rscalc.c | |||
@@ -5,7 +5,7 @@ | |||
5 | ******************************************************************************/ | 5 | ******************************************************************************/ |
6 | 6 | ||
7 | /* | 7 | /* |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
9 | * All rights reserved. | 9 | * All rights reserved. |
10 | * | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without |
@@ -49,652 +49,433 @@ | |||
49 | #define _COMPONENT ACPI_RESOURCES | 49 | #define _COMPONENT ACPI_RESOURCES |
50 | ACPI_MODULE_NAME("rscalc") | 50 | ACPI_MODULE_NAME("rscalc") |
51 | 51 | ||
52 | /* Local prototypes */ | ||
53 | static u8 acpi_rs_count_set_bits(u16 bit_field); | ||
54 | |||
55 | static acpi_rs_length | ||
56 | acpi_rs_struct_option_length(struct acpi_resource_source *resource_source); | ||
57 | |||
58 | static u32 | ||
59 | acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length); | ||
60 | |||
52 | /******************************************************************************* | 61 | /******************************************************************************* |
53 | * | 62 | * |
54 | * FUNCTION: acpi_rs_get_byte_stream_length | 63 | * FUNCTION: acpi_rs_count_set_bits |
55 | * | 64 | * |
56 | * PARAMETERS: linked_list - Pointer to the resource linked list | 65 | * PARAMETERS: bit_field - Field in which to count bits |
57 | * size_needed - u32 pointer of the size buffer needed | ||
58 | * to properly return the parsed data | ||
59 | * | 66 | * |
60 | * RETURN: Status | 67 | * RETURN: Number of bits set within the field |
61 | * | 68 | * |
62 | * DESCRIPTION: Takes the resource byte stream and parses it once, calculating | 69 | * DESCRIPTION: Count the number of bits set in a resource field. Used for |
63 | * the size buffer needed to hold the linked list that conveys | 70 | * (Short descriptor) interrupt and DMA lists. |
64 | * the resource data. | ||
65 | * | 71 | * |
66 | ******************************************************************************/ | 72 | ******************************************************************************/ |
67 | acpi_status | ||
68 | acpi_rs_get_byte_stream_length(struct acpi_resource *linked_list, | ||
69 | acpi_size * size_needed) | ||
70 | { | ||
71 | acpi_size byte_stream_size_needed = 0; | ||
72 | acpi_size segment_size; | ||
73 | u8 done = FALSE; | ||
74 | |||
75 | ACPI_FUNCTION_TRACE("rs_get_byte_stream_length"); | ||
76 | |||
77 | while (!done) { | ||
78 | /* Init the variable that will hold the size to add to the total. */ | ||
79 | |||
80 | segment_size = 0; | ||
81 | |||
82 | switch (linked_list->id) { | ||
83 | case ACPI_RSTYPE_IRQ: | ||
84 | /* | ||
85 | * IRQ Resource | ||
86 | * For an IRQ Resource, Byte 3, although optional, will always be | ||
87 | * created - it holds IRQ information. | ||
88 | */ | ||
89 | segment_size = 4; | ||
90 | break; | ||
91 | |||
92 | case ACPI_RSTYPE_DMA: | ||
93 | /* | ||
94 | * DMA Resource | ||
95 | * For this resource the size is static | ||
96 | */ | ||
97 | segment_size = 3; | ||
98 | break; | ||
99 | |||
100 | case ACPI_RSTYPE_START_DPF: | ||
101 | /* | ||
102 | * Start Dependent Functions Resource | ||
103 | * For a start_dependent_functions Resource, Byte 1, although | ||
104 | * optional, will always be created. | ||
105 | */ | ||
106 | segment_size = 2; | ||
107 | break; | ||
108 | |||
109 | case ACPI_RSTYPE_END_DPF: | ||
110 | /* | ||
111 | * End Dependent Functions Resource | ||
112 | * For this resource the size is static | ||
113 | */ | ||
114 | segment_size = 1; | ||
115 | break; | ||
116 | |||
117 | case ACPI_RSTYPE_IO: | ||
118 | /* | ||
119 | * IO Port Resource | ||
120 | * For this resource the size is static | ||
121 | */ | ||
122 | segment_size = 8; | ||
123 | break; | ||
124 | 73 | ||
125 | case ACPI_RSTYPE_FIXED_IO: | 74 | static u8 acpi_rs_count_set_bits(u16 bit_field) |
126 | /* | 75 | { |
127 | * Fixed IO Port Resource | 76 | u8 bits_set; |
128 | * For this resource the size is static | ||
129 | */ | ||
130 | segment_size = 4; | ||
131 | break; | ||
132 | |||
133 | case ACPI_RSTYPE_VENDOR: | ||
134 | /* | ||
135 | * Vendor Defined Resource | ||
136 | * For a Vendor Specific resource, if the Length is between 1 and 7 | ||
137 | * it will be created as a Small Resource data type, otherwise it | ||
138 | * is a Large Resource data type. | ||
139 | */ | ||
140 | if (linked_list->data.vendor_specific.length > 7) { | ||
141 | segment_size = 3; | ||
142 | } else { | ||
143 | segment_size = 1; | ||
144 | } | ||
145 | segment_size += | ||
146 | linked_list->data.vendor_specific.length; | ||
147 | break; | ||
148 | |||
149 | case ACPI_RSTYPE_END_TAG: | ||
150 | /* | ||
151 | * End Tag | ||
152 | * For this resource the size is static | ||
153 | */ | ||
154 | segment_size = 2; | ||
155 | done = TRUE; | ||
156 | break; | ||
157 | |||
158 | case ACPI_RSTYPE_MEM24: | ||
159 | /* | ||
160 | * 24-Bit Memory Resource | ||
161 | * For this resource the size is static | ||
162 | */ | ||
163 | segment_size = 12; | ||
164 | break; | ||
165 | 77 | ||
166 | case ACPI_RSTYPE_MEM32: | 78 | ACPI_FUNCTION_ENTRY(); |
167 | /* | ||
168 | * 32-Bit Memory Range Resource | ||
169 | * For this resource the size is static | ||
170 | */ | ||
171 | segment_size = 20; | ||
172 | break; | ||
173 | 79 | ||
174 | case ACPI_RSTYPE_FIXED_MEM32: | 80 | for (bits_set = 0; bit_field; bits_set++) { |
175 | /* | 81 | /* Zero the least significant bit that is set */ |
176 | * 32-Bit Fixed Memory Resource | ||
177 | * For this resource the size is static | ||
178 | */ | ||
179 | segment_size = 12; | ||
180 | break; | ||
181 | 82 | ||
182 | case ACPI_RSTYPE_ADDRESS16: | 83 | bit_field &= (bit_field - 1); |
183 | /* | 84 | } |
184 | * 16-Bit Address Resource | ||
185 | * The base size of this byte stream is 16. If a Resource Source | ||
186 | * string is not NULL, add 1 for the Index + the length of the null | ||
187 | * terminated string Resource Source + 1 for the null. | ||
188 | */ | ||
189 | segment_size = 16; | ||
190 | |||
191 | if (linked_list->data.address16.resource_source. | ||
192 | string_ptr) { | ||
193 | segment_size += | ||
194 | linked_list->data.address16.resource_source. | ||
195 | string_length; | ||
196 | segment_size++; | ||
197 | } | ||
198 | break; | ||
199 | 85 | ||
200 | case ACPI_RSTYPE_ADDRESS32: | 86 | return (bits_set); |
201 | /* | 87 | } |
202 | * 32-Bit Address Resource | ||
203 | * The base size of this byte stream is 26. If a Resource | ||
204 | * Source string is not NULL, add 1 for the Index + the | ||
205 | * length of the null terminated string Resource Source + | ||
206 | * 1 for the null. | ||
207 | */ | ||
208 | segment_size = 26; | ||
209 | |||
210 | if (linked_list->data.address32.resource_source. | ||
211 | string_ptr) { | ||
212 | segment_size += | ||
213 | linked_list->data.address32.resource_source. | ||
214 | string_length; | ||
215 | segment_size++; | ||
216 | } | ||
217 | break; | ||
218 | 88 | ||
219 | case ACPI_RSTYPE_ADDRESS64: | 89 | /******************************************************************************* |
220 | /* | 90 | * |
221 | * 64-Bit Address Resource | 91 | * FUNCTION: acpi_rs_struct_option_length |
222 | * The base size of this byte stream is 46. If a resource_source | 92 | * |
223 | * string is not NULL, add 1 for the Index + the length of the null | 93 | * PARAMETERS: resource_source - Pointer to optional descriptor field |
224 | * terminated string Resource Source + 1 for the null. | 94 | * |
225 | */ | 95 | * RETURN: Status |
226 | segment_size = 46; | 96 | * |
227 | 97 | * DESCRIPTION: Common code to handle optional resource_source_index and | |
228 | if (linked_list->data.address64.resource_source. | 98 | * resource_source fields in some Large descriptors. Used during |
229 | string_ptr) { | 99 | * list-to-stream conversion |
230 | segment_size += | 100 | * |
231 | linked_list->data.address64.resource_source. | 101 | ******************************************************************************/ |
232 | string_length; | ||
233 | segment_size++; | ||
234 | } | ||
235 | break; | ||
236 | 102 | ||
237 | case ACPI_RSTYPE_EXT_IRQ: | 103 | static acpi_rs_length |
238 | /* | 104 | acpi_rs_struct_option_length(struct acpi_resource_source *resource_source) |
239 | * Extended IRQ Resource | 105 | { |
240 | * The base size of this byte stream is 9. This is for an Interrupt | 106 | ACPI_FUNCTION_ENTRY(); |
241 | * table length of 1. For each additional interrupt, add 4. | ||
242 | * If a Resource Source string is not NULL, add 1 for the | ||
243 | * Index + the length of the null terminated string | ||
244 | * Resource Source + 1 for the null. | ||
245 | */ | ||
246 | segment_size = 9 + (((acpi_size) | ||
247 | linked_list->data.extended_irq. | ||
248 | number_of_interrupts - 1) * 4); | ||
249 | |||
250 | if (linked_list->data.extended_irq.resource_source. | ||
251 | string_ptr) { | ||
252 | segment_size += | ||
253 | linked_list->data.extended_irq. | ||
254 | resource_source.string_length; | ||
255 | segment_size++; | ||
256 | } | ||
257 | break; | ||
258 | 107 | ||
259 | default: | 108 | /* |
109 | * If the resource_source string is valid, return the size of the string | ||
110 | * (string_length includes the NULL terminator) plus the size of the | ||
111 | * resource_source_index (1). | ||
112 | */ | ||
113 | if (resource_source->string_ptr) { | ||
114 | return ((acpi_rs_length) (resource_source->string_length + 1)); | ||
115 | } | ||
260 | 116 | ||
261 | /* If we get here, everything is out of sync, exit with error */ | 117 | return (0); |
118 | } | ||
262 | 119 | ||
263 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); | 120 | /******************************************************************************* |
121 | * | ||
122 | * FUNCTION: acpi_rs_stream_option_length | ||
123 | * | ||
124 | * PARAMETERS: resource_length - Length from the resource header | ||
125 | * minimum_total_length - Minimum length of this resource, before | ||
126 | * any optional fields. Includes header size | ||
127 | * | ||
128 | * RETURN: Length of optional string (0 if no string present) | ||
129 | * | ||
130 | * DESCRIPTION: Common code to handle optional resource_source_index and | ||
131 | * resource_source fields in some Large descriptors. Used during | ||
132 | * stream-to-list conversion | ||
133 | * | ||
134 | ******************************************************************************/ | ||
264 | 135 | ||
265 | } /* switch (linked_list->Id) */ | 136 | static u32 |
137 | acpi_rs_stream_option_length(u32 resource_length, | ||
138 | u32 minimum_aml_resource_length) | ||
139 | { | ||
140 | u32 string_length = 0; | ||
266 | 141 | ||
267 | /* Update the total */ | 142 | ACPI_FUNCTION_ENTRY(); |
268 | 143 | ||
269 | byte_stream_size_needed += segment_size; | 144 | /* |
145 | * The resource_source_index and resource_source are optional elements of some | ||
146 | * Large-type resource descriptors. | ||
147 | */ | ||
270 | 148 | ||
271 | /* Point to the next object */ | 149 | /* |
150 | * If the length of the actual resource descriptor is greater than the ACPI | ||
151 | * spec-defined minimum length, it means that a resource_source_index exists | ||
152 | * and is followed by a (required) null terminated string. The string length | ||
153 | * (including the null terminator) is the resource length minus the minimum | ||
154 | * length, minus one byte for the resource_source_index itself. | ||
155 | */ | ||
156 | if (resource_length > minimum_aml_resource_length) { | ||
157 | /* Compute the length of the optional string */ | ||
272 | 158 | ||
273 | linked_list = ACPI_PTR_ADD(struct acpi_resource, | 159 | string_length = |
274 | linked_list, linked_list->length); | 160 | resource_length - minimum_aml_resource_length - 1; |
275 | } | 161 | } |
276 | 162 | ||
277 | /* This is the data the caller needs */ | 163 | /* Round up length to 32 bits for internal structure alignment */ |
278 | 164 | ||
279 | *size_needed = byte_stream_size_needed; | 165 | return (ACPI_ROUND_UP_to_32_bITS(string_length)); |
280 | return_ACPI_STATUS(AE_OK); | ||
281 | } | 166 | } |
282 | 167 | ||
283 | /******************************************************************************* | 168 | /******************************************************************************* |
284 | * | 169 | * |
285 | * FUNCTION: acpi_rs_get_list_length | 170 | * FUNCTION: acpi_rs_get_aml_length |
286 | * | 171 | * |
287 | * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream | 172 | * PARAMETERS: Resource - Pointer to the resource linked list |
288 | * byte_stream_buffer_length - Size of byte_stream_buffer | 173 | * size_needed - Where the required size is returned |
289 | * size_needed - u32 pointer of the size buffer | ||
290 | * needed to properly return the | ||
291 | * parsed data | ||
292 | * | 174 | * |
293 | * RETURN: Status | 175 | * RETURN: Status |
294 | * | 176 | * |
295 | * DESCRIPTION: Takes the resource byte stream and parses it once, calculating | 177 | * DESCRIPTION: Takes a linked list of internal resource descriptors and |
296 | * the size buffer needed to hold the linked list that conveys | 178 | * calculates the size buffer needed to hold the corresponding |
297 | * the resource data. | 179 | * external resource byte stream. |
298 | * | 180 | * |
299 | ******************************************************************************/ | 181 | ******************************************************************************/ |
300 | 182 | ||
301 | acpi_status | 183 | acpi_status |
302 | acpi_rs_get_list_length(u8 * byte_stream_buffer, | 184 | acpi_rs_get_aml_length(struct acpi_resource * resource, acpi_size * size_needed) |
303 | u32 byte_stream_buffer_length, acpi_size * size_needed) | ||
304 | { | 185 | { |
305 | u32 buffer_size = 0; | 186 | acpi_size aml_size_needed = 0; |
306 | u32 bytes_parsed = 0; | 187 | acpi_rs_length total_size; |
307 | u8 number_of_interrupts = 0; | ||
308 | u8 number_of_channels = 0; | ||
309 | u8 resource_type; | ||
310 | u32 structure_size; | ||
311 | u32 bytes_consumed; | ||
312 | u8 *buffer; | ||
313 | u8 temp8; | ||
314 | u16 temp16; | ||
315 | u8 index; | ||
316 | u8 additional_bytes; | ||
317 | |||
318 | ACPI_FUNCTION_TRACE("rs_get_list_length"); | ||
319 | 188 | ||
320 | while (bytes_parsed < byte_stream_buffer_length) { | 189 | ACPI_FUNCTION_TRACE("rs_get_aml_length"); |
321 | /* The next byte in the stream is the resource type */ | ||
322 | 190 | ||
323 | resource_type = acpi_rs_get_resource_type(*byte_stream_buffer); | 191 | /* Traverse entire list of internal resource descriptors */ |
324 | 192 | ||
325 | switch (resource_type) { | 193 | while (resource) { |
326 | case ACPI_RDESC_TYPE_MEMORY_24: | 194 | /* Validate the descriptor type */ |
327 | /* | ||
328 | * 24-Bit Memory Resource | ||
329 | */ | ||
330 | bytes_consumed = 12; | ||
331 | |||
332 | structure_size = | ||
333 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24); | ||
334 | break; | ||
335 | 195 | ||
336 | case ACPI_RDESC_TYPE_LARGE_VENDOR: | 196 | if (resource->type > ACPI_RESOURCE_TYPE_MAX) { |
337 | /* | 197 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
338 | * Vendor Defined Resource | 198 | } |
339 | */ | ||
340 | buffer = byte_stream_buffer; | ||
341 | ++buffer; | ||
342 | |||
343 | ACPI_MOVE_16_TO_16(&temp16, buffer); | ||
344 | bytes_consumed = temp16 + 3; | ||
345 | |||
346 | /* Ensure a 32-bit boundary for the structure */ | ||
347 | 199 | ||
348 | temp16 = (u16) ACPI_ROUND_UP_to_32_bITS(temp16); | 200 | /* Get the base size of the (external stream) resource descriptor */ |
349 | 201 | ||
350 | structure_size = | 202 | total_size = acpi_gbl_aml_resource_sizes[resource->type]; |
351 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) + | ||
352 | (temp16 * sizeof(u8)); | ||
353 | break; | ||
354 | 203 | ||
355 | case ACPI_RDESC_TYPE_MEMORY_32: | 204 | /* |
205 | * Augment the base size for descriptors with optional and/or | ||
206 | * variable-length fields | ||
207 | */ | ||
208 | switch (resource->type) { | ||
209 | case ACPI_RESOURCE_TYPE_VENDOR: | ||
356 | /* | 210 | /* |
357 | * 32-Bit Memory Range Resource | 211 | * Vendor Defined Resource: |
212 | * For a Vendor Specific resource, if the Length is between 1 and 7 | ||
213 | * it will be created as a Small Resource data type, otherwise it | ||
214 | * is a Large Resource data type. | ||
358 | */ | 215 | */ |
359 | bytes_consumed = 20; | 216 | if (resource->data.vendor.byte_length > 7) { |
217 | /* Base size of a Large resource descriptor */ | ||
360 | 218 | ||
361 | structure_size = | 219 | total_size = |
362 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32); | 220 | sizeof(struct aml_resource_large_header); |
363 | break; | 221 | } |
364 | 222 | ||
365 | case ACPI_RDESC_TYPE_FIXED_MEMORY_32: | 223 | /* Add the size of the vendor-specific data */ |
366 | /* | ||
367 | * 32-Bit Fixed Memory Resource | ||
368 | */ | ||
369 | bytes_consumed = 12; | ||
370 | 224 | ||
371 | structure_size = | 225 | total_size = (acpi_rs_length) |
372 | ACPI_SIZEOF_RESOURCE(struct | 226 | (total_size + resource->data.vendor.byte_length); |
373 | acpi_resource_fixed_mem32); | ||
374 | break; | 227 | break; |
375 | 228 | ||
376 | case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE: | 229 | case ACPI_RESOURCE_TYPE_END_TAG: |
377 | /* | 230 | /* |
378 | * 64-Bit Address Resource | 231 | * End Tag: |
232 | * We are done -- return the accumulated total size. | ||
379 | */ | 233 | */ |
380 | buffer = byte_stream_buffer; | 234 | *size_needed = aml_size_needed + total_size; |
381 | 235 | ||
382 | ++buffer; | 236 | /* Normal exit */ |
383 | ACPI_MOVE_16_TO_16(&temp16, buffer); | ||
384 | 237 | ||
385 | bytes_consumed = temp16 + 3; | 238 | return_ACPI_STATUS(AE_OK); |
386 | structure_size = | ||
387 | ACPI_SIZEOF_RESOURCE(struct | ||
388 | acpi_resource_address64); | ||
389 | break; | ||
390 | 239 | ||
391 | case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE: | 240 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
392 | /* | 241 | /* |
393 | * 64-Bit Address Resource | 242 | * 16-Bit Address Resource: |
243 | * Add the size of the optional resource_source info | ||
394 | */ | 244 | */ |
395 | buffer = byte_stream_buffer; | 245 | total_size = (acpi_rs_length) |
396 | 246 | (total_size + | |
397 | ++buffer; | 247 | acpi_rs_struct_option_length(&resource->data. |
398 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 248 | address16. |
399 | 249 | resource_source)); | |
400 | bytes_consumed = temp16 + 3; | 250 | break; |
401 | 251 | ||
252 | case ACPI_RESOURCE_TYPE_ADDRESS32: | ||
402 | /* | 253 | /* |
403 | * Resource Source Index and Resource Source are optional elements. | 254 | * 32-Bit Address Resource: |
404 | * Check the length of the Bytestream. If it is greater than 43, | 255 | * Add the size of the optional resource_source info |
405 | * that means that an Index exists and is followed by a null | ||
406 | * terminated string. Therefore, set the temp variable to the | ||
407 | * length minus the minimum byte stream length plus the byte for | ||
408 | * the Index to determine the size of the NULL terminated string. | ||
409 | */ | 256 | */ |
410 | if (43 < temp16) { | 257 | total_size = (acpi_rs_length) |
411 | temp8 = (u8) (temp16 - 44); | 258 | (total_size + |
412 | } else { | 259 | acpi_rs_struct_option_length(&resource->data. |
413 | temp8 = 0; | 260 | address32. |
414 | } | 261 | resource_source)); |
415 | |||
416 | /* Ensure a 64-bit boundary for the structure */ | ||
417 | |||
418 | temp8 = (u8) ACPI_ROUND_UP_to_64_bITS(temp8); | ||
419 | |||
420 | structure_size = | ||
421 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64) | ||
422 | + (temp8 * sizeof(u8)); | ||
423 | break; | 262 | break; |
424 | 263 | ||
425 | case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE: | 264 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
426 | /* | 265 | /* |
427 | * 32-Bit Address Resource | 266 | * 64-Bit Address Resource: |
267 | * Add the size of the optional resource_source info | ||
428 | */ | 268 | */ |
429 | buffer = byte_stream_buffer; | 269 | total_size = (acpi_rs_length) |
430 | 270 | (total_size + | |
431 | ++buffer; | 271 | acpi_rs_struct_option_length(&resource->data. |
432 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 272 | address64. |
433 | 273 | resource_source)); | |
434 | bytes_consumed = temp16 + 3; | 274 | break; |
435 | 275 | ||
276 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | ||
436 | /* | 277 | /* |
437 | * Resource Source Index and Resource Source are optional elements. | 278 | * Extended IRQ Resource: |
438 | * Check the length of the Bytestream. If it is greater than 23, | 279 | * Add the size of each additional optional interrupt beyond the |
439 | * that means that an Index exists and is followed by a null | 280 | * required 1 (4 bytes for each u32 interrupt number) |
440 | * terminated string. Therefore, set the temp variable to the | ||
441 | * length minus the minimum byte stream length plus the byte for | ||
442 | * the Index to determine the size of the NULL terminated string. | ||
443 | */ | 281 | */ |
444 | if (23 < temp16) { | 282 | total_size = (acpi_rs_length) |
445 | temp8 = (u8) (temp16 - 24); | 283 | (total_size + |
446 | } else { | 284 | ((resource->data.extended_irq.interrupt_count - |
447 | temp8 = 0; | 285 | 1) * 4) + |
448 | } | 286 | /* Add the size of the optional resource_source info */ |
449 | 287 | acpi_rs_struct_option_length(&resource->data. | |
450 | /* Ensure a 32-bit boundary for the structure */ | 288 | extended_irq. |
451 | 289 | resource_source)); | |
452 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 290 | break; |
453 | 291 | ||
454 | structure_size = | 292 | default: |
455 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32) | ||
456 | + (temp8 * sizeof(u8)); | ||
457 | break; | 293 | break; |
294 | } | ||
458 | 295 | ||
459 | case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE: | 296 | /* Update the total */ |
460 | /* | ||
461 | * 16-Bit Address Resource | ||
462 | */ | ||
463 | buffer = byte_stream_buffer; | ||
464 | 297 | ||
465 | ++buffer; | 298 | aml_size_needed += total_size; |
466 | ACPI_MOVE_16_TO_16(&temp16, buffer); | ||
467 | 299 | ||
468 | bytes_consumed = temp16 + 3; | 300 | /* Point to the next object */ |
469 | 301 | ||
470 | /* | 302 | resource = |
471 | * Resource Source Index and Resource Source are optional elements. | 303 | ACPI_ADD_PTR(struct acpi_resource, resource, |
472 | * Check the length of the Bytestream. If it is greater than 13, | 304 | resource->length); |
473 | * that means that an Index exists and is followed by a null | 305 | } |
474 | * terminated string. Therefore, set the temp variable to the | ||
475 | * length minus the minimum byte stream length plus the byte for | ||
476 | * the Index to determine the size of the NULL terminated string. | ||
477 | */ | ||
478 | if (13 < temp16) { | ||
479 | temp8 = (u8) (temp16 - 14); | ||
480 | } else { | ||
481 | temp8 = 0; | ||
482 | } | ||
483 | 306 | ||
484 | /* Ensure a 32-bit boundary for the structure */ | 307 | /* Did not find an end_tag resource descriptor */ |
485 | 308 | ||
486 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 309 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); |
310 | } | ||
487 | 311 | ||
488 | structure_size = | 312 | /******************************************************************************* |
489 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16) | 313 | * |
490 | + (temp8 * sizeof(u8)); | 314 | * FUNCTION: acpi_rs_get_list_length |
491 | break; | 315 | * |
316 | * PARAMETERS: aml_buffer - Pointer to the resource byte stream | ||
317 | * aml_buffer_length - Size of aml_buffer | ||
318 | * size_needed - Where the size needed is returned | ||
319 | * | ||
320 | * RETURN: Status | ||
321 | * | ||
322 | * DESCRIPTION: Takes an external resource byte stream and calculates the size | ||
323 | * buffer needed to hold the corresponding internal resource | ||
324 | * descriptor linked list. | ||
325 | * | ||
326 | ******************************************************************************/ | ||
492 | 327 | ||
493 | case ACPI_RDESC_TYPE_EXTENDED_XRUPT: | 328 | acpi_status |
494 | /* | 329 | acpi_rs_get_list_length(u8 * aml_buffer, |
495 | * Extended IRQ | 330 | u32 aml_buffer_length, acpi_size * size_needed) |
496 | */ | 331 | { |
497 | buffer = byte_stream_buffer; | 332 | acpi_status status; |
333 | u8 *end_aml; | ||
334 | u8 *buffer; | ||
335 | u32 buffer_size = 0; | ||
336 | u16 temp16; | ||
337 | u16 resource_length; | ||
338 | u32 extra_struct_bytes; | ||
339 | u8 resource_index; | ||
340 | u8 minimum_aml_resource_length; | ||
498 | 341 | ||
499 | ++buffer; | 342 | ACPI_FUNCTION_TRACE("rs_get_list_length"); |
500 | ACPI_MOVE_16_TO_16(&temp16, buffer); | ||
501 | 343 | ||
502 | bytes_consumed = temp16 + 3; | 344 | end_aml = aml_buffer + aml_buffer_length; |
503 | 345 | ||
504 | /* | 346 | /* Walk the list of AML resource descriptors */ |
505 | * Point past the length field and the Interrupt vector flags to | ||
506 | * save off the Interrupt table length to the Temp8 variable. | ||
507 | */ | ||
508 | buffer += 3; | ||
509 | temp8 = *buffer; | ||
510 | 347 | ||
511 | /* | 348 | while (aml_buffer < end_aml) { |
512 | * To compensate for multiple interrupt numbers, add 4 bytes for | 349 | /* Validate the Resource Type and Resource Length */ |
513 | * each additional interrupts greater than 1 | ||
514 | */ | ||
515 | additional_bytes = (u8) ((temp8 - 1) * 4); | ||
516 | 350 | ||
517 | /* | 351 | status = acpi_ut_validate_resource(aml_buffer, &resource_index); |
518 | * Resource Source Index and Resource Source are optional elements. | 352 | if (ACPI_FAILURE(status)) { |
519 | * Check the length of the Bytestream. If it is greater than 9, | 353 | return_ACPI_STATUS(status); |
520 | * that means that an Index exists and is followed by a null | 354 | } |
521 | * terminated string. Therefore, set the temp variable to the | ||
522 | * length minus the minimum byte stream length plus the byte for | ||
523 | * the Index to determine the size of the NULL terminated string. | ||
524 | */ | ||
525 | if (9 + additional_bytes < temp16) { | ||
526 | temp8 = (u8) (temp16 - (9 + additional_bytes)); | ||
527 | } else { | ||
528 | temp8 = 0; | ||
529 | } | ||
530 | 355 | ||
531 | /* Ensure a 32-bit boundary for the structure */ | 356 | /* Get the resource length and base (minimum) AML size */ |
532 | 357 | ||
533 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 358 | resource_length = acpi_ut_get_resource_length(aml_buffer); |
359 | minimum_aml_resource_length = | ||
360 | acpi_gbl_resource_aml_sizes[resource_index]; | ||
534 | 361 | ||
535 | structure_size = | 362 | /* |
536 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq) + | 363 | * Augment the size for descriptors with optional |
537 | (additional_bytes * sizeof(u8)) + | 364 | * and/or variable length fields |
538 | (temp8 * sizeof(u8)); | 365 | */ |
539 | break; | 366 | extra_struct_bytes = 0; |
367 | buffer = | ||
368 | aml_buffer + acpi_ut_get_resource_header_length(aml_buffer); | ||
540 | 369 | ||
541 | case ACPI_RDESC_TYPE_IRQ_FORMAT: | 370 | switch (acpi_ut_get_resource_type(aml_buffer)) { |
371 | case ACPI_RESOURCE_NAME_IRQ: | ||
542 | /* | 372 | /* |
543 | * IRQ Resource. | 373 | * IRQ Resource: |
544 | * Determine if it there are two or three trailing bytes | 374 | * Get the number of bits set in the 16-bit IRQ mask |
545 | */ | 375 | */ |
546 | buffer = byte_stream_buffer; | ||
547 | temp8 = *buffer; | ||
548 | |||
549 | if (temp8 & 0x01) { | ||
550 | bytes_consumed = 4; | ||
551 | } else { | ||
552 | bytes_consumed = 3; | ||
553 | } | ||
554 | |||
555 | /* Point past the descriptor */ | ||
556 | |||
557 | ++buffer; | ||
558 | |||
559 | /* Look at the number of bits set */ | ||
560 | |||
561 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 376 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
562 | 377 | extra_struct_bytes = acpi_rs_count_set_bits(temp16); | |
563 | for (index = 0; index < 16; index++) { | ||
564 | if (temp16 & 0x1) { | ||
565 | ++number_of_interrupts; | ||
566 | } | ||
567 | |||
568 | temp16 >>= 1; | ||
569 | } | ||
570 | |||
571 | structure_size = | ||
572 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_io) + | ||
573 | (number_of_interrupts * sizeof(u32)); | ||
574 | break; | 378 | break; |
575 | 379 | ||
576 | case ACPI_RDESC_TYPE_DMA_FORMAT: | 380 | case ACPI_RESOURCE_NAME_DMA: |
577 | /* | 381 | /* |
578 | * DMA Resource | 382 | * DMA Resource: |
383 | * Get the number of bits set in the 8-bit DMA mask | ||
579 | */ | 384 | */ |
580 | buffer = byte_stream_buffer; | 385 | extra_struct_bytes = acpi_rs_count_set_bits(*buffer); |
581 | bytes_consumed = 3; | ||
582 | |||
583 | /* Point past the descriptor */ | ||
584 | |||
585 | ++buffer; | ||
586 | |||
587 | /* Look at the number of bits set */ | ||
588 | |||
589 | temp8 = *buffer; | ||
590 | |||
591 | for (index = 0; index < 8; index++) { | ||
592 | if (temp8 & 0x1) { | ||
593 | ++number_of_channels; | ||
594 | } | ||
595 | |||
596 | temp8 >>= 1; | ||
597 | } | ||
598 | |||
599 | structure_size = | ||
600 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma) + | ||
601 | (number_of_channels * sizeof(u32)); | ||
602 | break; | 386 | break; |
603 | 387 | ||
604 | case ACPI_RDESC_TYPE_START_DEPENDENT: | 388 | case ACPI_RESOURCE_NAME_VENDOR_SMALL: |
605 | /* | 389 | /* |
606 | * Start Dependent Functions Resource | 390 | * Vendor Resource: |
607 | * Determine if it there are two or three trailing bytes | 391 | * Ensure a 32-bit boundary for the structure |
608 | */ | 392 | */ |
609 | buffer = byte_stream_buffer; | 393 | extra_struct_bytes = |
610 | temp8 = *buffer; | 394 | ACPI_ROUND_UP_to_32_bITS(resource_length) - |
611 | 395 | resource_length; | |
612 | if (temp8 & 0x01) { | ||
613 | bytes_consumed = 2; | ||
614 | } else { | ||
615 | bytes_consumed = 1; | ||
616 | } | ||
617 | |||
618 | structure_size = | ||
619 | ACPI_SIZEOF_RESOURCE(struct | ||
620 | acpi_resource_start_dpf); | ||
621 | break; | 396 | break; |
622 | 397 | ||
623 | case ACPI_RDESC_TYPE_END_DEPENDENT: | 398 | case ACPI_RESOURCE_NAME_END_TAG: |
624 | /* | 399 | /* |
625 | * End Dependent Functions Resource | 400 | * End Tag: This is the normal exit, add size of end_tag |
626 | */ | 401 | */ |
627 | bytes_consumed = 1; | 402 | *size_needed = buffer_size + ACPI_RS_SIZE_MIN; |
628 | structure_size = ACPI_RESOURCE_LENGTH; | 403 | return_ACPI_STATUS(AE_OK); |
629 | break; | ||
630 | 404 | ||
631 | case ACPI_RDESC_TYPE_IO_PORT: | 405 | case ACPI_RESOURCE_NAME_VENDOR_LARGE: |
632 | /* | 406 | /* |
633 | * IO Port Resource | 407 | * Vendor Resource: |
408 | * Add vendor data and ensure a 32-bit boundary for the structure | ||
634 | */ | 409 | */ |
635 | bytes_consumed = 8; | 410 | extra_struct_bytes = |
636 | structure_size = | 411 | ACPI_ROUND_UP_to_32_bITS(resource_length) - |
637 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_io); | 412 | resource_length; |
638 | break; | 413 | break; |
639 | 414 | ||
640 | case ACPI_RDESC_TYPE_FIXED_IO_PORT: | 415 | case ACPI_RESOURCE_NAME_ADDRESS32: |
416 | case ACPI_RESOURCE_NAME_ADDRESS16: | ||
641 | /* | 417 | /* |
642 | * Fixed IO Port Resource | 418 | * 32-Bit or 16-bit Address Resource: |
419 | * Add the size of any optional data (resource_source) | ||
643 | */ | 420 | */ |
644 | bytes_consumed = 4; | 421 | extra_struct_bytes = |
645 | structure_size = | 422 | acpi_rs_stream_option_length(resource_length, |
646 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io); | 423 | minimum_aml_resource_length); |
647 | break; | 424 | break; |
648 | 425 | ||
649 | case ACPI_RDESC_TYPE_SMALL_VENDOR: | 426 | case ACPI_RESOURCE_NAME_EXTENDED_IRQ: |
650 | /* | 427 | /* |
651 | * Vendor Specific Resource | 428 | * Extended IRQ: |
429 | * Point past the interrupt_vector_flags to get the | ||
430 | * interrupt_table_length. | ||
652 | */ | 431 | */ |
653 | buffer = byte_stream_buffer; | 432 | buffer++; |
654 | 433 | ||
655 | temp8 = *buffer; | 434 | extra_struct_bytes = |
656 | temp8 = (u8) (temp8 & 0x7); | 435 | /* |
657 | bytes_consumed = temp8 + 1; | 436 | * Add 4 bytes for each additional interrupt. Note: at |
658 | 437 | * least one interrupt is required and is included in | |
659 | /* Ensure a 32-bit boundary for the structure */ | 438 | * the minimum descriptor size |
660 | 439 | */ | |
661 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 440 | ((*buffer - 1) * sizeof(u32)) + |
662 | structure_size = | 441 | /* Add the size of any optional data (resource_source) */ |
663 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) + | 442 | acpi_rs_stream_option_length(resource_length - |
664 | (temp8 * sizeof(u8)); | 443 | extra_struct_bytes, |
444 | minimum_aml_resource_length); | ||
665 | break; | 445 | break; |
666 | 446 | ||
667 | case ACPI_RDESC_TYPE_END_TAG: | 447 | case ACPI_RESOURCE_NAME_ADDRESS64: |
668 | /* | 448 | /* |
669 | * End Tag | 449 | * 64-Bit Address Resource: |
450 | * Add the size of any optional data (resource_source) | ||
451 | * Ensure a 64-bit boundary for the structure | ||
670 | */ | 452 | */ |
671 | bytes_consumed = 2; | 453 | extra_struct_bytes = |
672 | structure_size = ACPI_RESOURCE_LENGTH; | 454 | ACPI_ROUND_UP_to_64_bITS |
673 | byte_stream_buffer_length = bytes_parsed; | 455 | (acpi_rs_stream_option_length |
456 | (resource_length, minimum_aml_resource_length)); | ||
674 | break; | 457 | break; |
675 | 458 | ||
676 | default: | 459 | default: |
677 | /* | 460 | break; |
678 | * If we get here, everything is out of sync, | ||
679 | * exit with an error | ||
680 | */ | ||
681 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); | ||
682 | } | 461 | } |
683 | 462 | ||
684 | /* Update the return value and counter */ | 463 | /* Update the required buffer size for the internal descriptor structs */ |
685 | |||
686 | buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(structure_size); | ||
687 | bytes_parsed += bytes_consumed; | ||
688 | 464 | ||
689 | /* Set the byte stream to point to the next resource */ | 465 | temp16 = (u16) (acpi_gbl_resource_struct_sizes[resource_index] + |
466 | extra_struct_bytes); | ||
467 | buffer_size += (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(temp16); | ||
690 | 468 | ||
691 | byte_stream_buffer += bytes_consumed; | 469 | /* |
470 | * Point to the next resource within the stream | ||
471 | * using the size of the header plus the length contained in the header | ||
472 | */ | ||
473 | aml_buffer += acpi_ut_get_descriptor_length(aml_buffer); | ||
692 | } | 474 | } |
693 | 475 | ||
694 | /* This is the data the caller needs */ | 476 | /* Did not find an end_tag resource descriptor */ |
695 | 477 | ||
696 | *size_needed = buffer_size; | 478 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); |
697 | return_ACPI_STATUS(AE_OK); | ||
698 | } | 479 | } |
699 | 480 | ||
700 | /******************************************************************************* | 481 | /******************************************************************************* |
@@ -760,13 +541,13 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object, | |||
760 | 541 | ||
761 | for (table_index = 0; table_index < 4 && !name_found; | 542 | for (table_index = 0; table_index < 4 && !name_found; |
762 | table_index++) { | 543 | table_index++) { |
763 | if ((ACPI_TYPE_STRING == | 544 | if (*sub_object_list && /* Null object allowed */ |
764 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) | 545 | ((ACPI_TYPE_STRING == |
765 | || | 546 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) || |
766 | ((ACPI_TYPE_LOCAL_REFERENCE == | 547 | ((ACPI_TYPE_LOCAL_REFERENCE == |
767 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) | 548 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) && |
768 | && ((*sub_object_list)->reference.opcode == | 549 | ((*sub_object_list)->reference.opcode == |
769 | AML_INT_NAMEPATH_OP))) { | 550 | AML_INT_NAMEPATH_OP)))) { |
770 | name_found = TRUE; | 551 | name_found = TRUE; |
771 | } else { | 552 | } else { |
772 | /* Look at the next element */ | 553 | /* Look at the next element */ |