aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/resources/rscalc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/resources/rscalc.c')
-rw-r--r--drivers/acpi/resources/rscalc.c987
1 files changed, 478 insertions, 509 deletions
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index 378f58390fc1..2da7c6a8182e 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -44,651 +44,619 @@
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acresrc.h> 45#include <acpi/acresrc.h>
46#include <acpi/amlcode.h> 46#include <acpi/amlcode.h>
47#include <acpi/amlresrc.h>
47#include <acpi/acnamesp.h> 48#include <acpi/acnamesp.h>
48 49
49#define _COMPONENT ACPI_RESOURCES 50#define _COMPONENT ACPI_RESOURCES
50ACPI_MODULE_NAME("rscalc") 51ACPI_MODULE_NAME("rscalc")
51 52
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 */
58static 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 */
81struct acpi_resource_sizes {
82 u8 minimum_stream_size;
83 u8 minimum_struct_size;
84};
85
86static 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 */
103};
104
105static 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 */
118};
119
120/* Local prototypes */
121
122static u8 acpi_rs_count_set_bits(u16 bit_field);
123
124static struct acpi_resource_sizes *acpi_rs_get_resource_sizes(u8 resource_type);
125
126static u16 acpi_rs_get_resource_length(u8 * resource);
127
128static acpi_size
129acpi_rs_struct_option_length(struct acpi_resource_source *resource_source);
130
131static u32
132acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length);
133
52/******************************************************************************* 134/*******************************************************************************
53 * 135 *
54 * FUNCTION: acpi_rs_get_byte_stream_length 136 * FUNCTION: acpi_rs_count_set_bits
55 * 137 *
56 * PARAMETERS: linked_list - Pointer to the resource linked list 138 * 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 * 139 *
60 * RETURN: Status 140 * RETURN: Number of bits set within the field
61 * 141 *
62 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating 142 * 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 143 * (Short descriptor) interrupt and DMA lists.
64 * the resource data.
65 * 144 *
66 ******************************************************************************/ 145 ******************************************************************************/
67acpi_status
68acpi_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 146
77 while (!done) { 147static u8 acpi_rs_count_set_bits(u16 bit_field)
78 /* Init the variable that will hold the size to add to the total. */ 148{
149 u8 bits_set;
79 150
80 segment_size = 0; 151 ACPI_FUNCTION_ENTRY();
81 152
82 switch (linked_list->id) { 153 for (bits_set = 0; bit_field; bits_set++) {
83 case ACPI_RSTYPE_IRQ: 154 /* Zero the least significant bit that is set */
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 155
92 case ACPI_RSTYPE_DMA: 156 bit_field &= (bit_field - 1);
93 /* 157 }
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 158
109 case ACPI_RSTYPE_END_DPF: 159 return (bits_set);
110 /* 160}
111 * End Dependent Functions Resource
112 * For this resource the size is static
113 */
114 segment_size = 1;
115 break;
116 161
117 case ACPI_RSTYPE_IO: 162/*******************************************************************************
118 /* 163 *
119 * IO Port Resource 164 * FUNCTION: acpi_rs_get_resource_sizes
120 * For this resource the size is static 165 *
121 */ 166 * PARAMETERS: resource_type - Byte 0 of a resource descriptor
122 segment_size = 8; 167 *
123 break; 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 ******************************************************************************/
124 174
125 case ACPI_RSTYPE_FIXED_IO: 175static struct acpi_resource_sizes *acpi_rs_get_resource_sizes(u8 resource_type)
126 /* 176{
127 * Fixed IO Port Resource 177 struct acpi_resource_sizes *size_info;
128 * For this resource the size is static
129 */
130 segment_size = 4;
131 break;
132 178
133 case ACPI_RSTYPE_VENDOR: 179 ACPI_FUNCTION_ENTRY();
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 180
149 case ACPI_RSTYPE_END_TAG: 181 /* Determine if this is a small or large resource */
150 /*
151 * End Tag
152 * For this resource the size is static
153 */
154 segment_size = 2;
155 done = TRUE;
156 break;
157 182
158 case ACPI_RSTYPE_MEM24: 183 if (resource_type & ACPI_RDESC_TYPE_LARGE) {
159 /* 184 /* Large Resource Type -- bits 6:0 contain the name */
160 * 24-Bit Memory Resource
161 * For this resource the size is static
162 */
163 segment_size = 12;
164 break;
165 185
166 case ACPI_RSTYPE_MEM32: 186 if (resource_type > ACPI_RDESC_LARGE_MAX) {
167 /* 187 return (NULL);
168 * 32-Bit Memory Range Resource 188 }
169 * For this resource the size is static
170 */
171 segment_size = 20;
172 break;
173 189
174 case ACPI_RSTYPE_FIXED_MEM32: 190 size_info = &acpi_gbl_lg_resource_sizes[(resource_type &
175 /* 191 ACPI_RDESC_LARGE_MASK)];
176 * 32-Bit Fixed Memory Resource 192 } else {
177 * For this resource the size is static 193 /* Small Resource Type -- bits 6:3 contain the name */
178 */
179 segment_size = 12;
180 break;
181 194
182 case ACPI_RSTYPE_ADDRESS16: 195 size_info = &acpi_gbl_sm_resource_sizes[((resource_type &
183 /* 196 ACPI_RDESC_SMALL_MASK)
184 * 16-Bit Address Resource 197 >> 3)];
185 * The base size of this byte stream is 16. If a Resource Source 198 }
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 199
200 case ACPI_RSTYPE_ADDRESS32: 200 /* Zero entry indicates an invalid resource type */
201 /*
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 201
219 case ACPI_RSTYPE_ADDRESS64: 202 if (!size_info->minimum_stream_size) {
220 /* 203 return (NULL);
221 * 64-Bit Address Resource 204 }
222 * The base size of this byte stream is 46. If a resource_source
223 * string is not NULL, add 1 for the Index + the length of the null
224 * terminated string Resource Source + 1 for the null.
225 */
226 segment_size = 46;
227
228 if (linked_list->data.address64.resource_source.
229 string_ptr) {
230 segment_size +=
231 linked_list->data.address64.resource_source.
232 string_length;
233 segment_size++;
234 }
235 break;
236 205
237 case ACPI_RSTYPE_EXT_IRQ: 206 return (size_info);
238 /* 207}
239 * Extended IRQ Resource
240 * The base size of this byte stream is 9. This is for an Interrupt
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 208
259 default: 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 ******************************************************************************/
260 222
261 /* If we get here, everything is out of sync, exit with error */ 223static u16 acpi_rs_get_resource_length(u8 * resource)
224{
225 u16 resource_length;
262 226
263 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); 227 ACPI_FUNCTION_ENTRY();
264 228
265 } /* switch (linked_list->Id) */ 229 /* Determine if this is a small or large resource */
266 230
267 /* Update the total */ 231 if (*resource & ACPI_RDESC_TYPE_LARGE) {
232 /* Large Resource type -- length is in bytes 1-2 */
268 233
269 byte_stream_size_needed += segment_size; 234 ACPI_MOVE_16_TO_16(&resource_length, (resource + 1));
270 235
271 /* Point to the next object */ 236 } else {
237 /* Small Resource Type -- bits 2:0 of byte 0 contain the length */
272 238
273 linked_list = ACPI_PTR_ADD(struct acpi_resource, 239 resource_length =
274 linked_list, linked_list->length); 240 (u16) (*resource & ACPI_RDESC_SMALL_LENGTH_MASK);
275 } 241 }
276 242
277 /* This is the data the caller needs */ 243 return (resource_length);
278
279 *size_needed = byte_stream_size_needed;
280 return_ACPI_STATUS(AE_OK);
281} 244}
282 245
283/******************************************************************************* 246/*******************************************************************************
284 * 247 *
285 * FUNCTION: acpi_rs_get_list_length 248 * FUNCTION: acpi_rs_struct_option_length
286 * 249 *
287 * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream 250 * PARAMETERS: resource_source - Pointer to optional descriptor field
288 * byte_stream_buffer_length - Size of byte_stream_buffer
289 * size_needed - u32 pointer of the size buffer
290 * needed to properly return the
291 * parsed data
292 * 251 *
293 * RETURN: Status 252 * RETURN: Status
294 * 253 *
295 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating 254 * DESCRIPTION: Common code to handle optional resource_source_index and
296 * the size buffer needed to hold the linked list that conveys 255 * resource_source fields in some Large descriptors. Used during
297 * the resource data. 256 * list-to-stream conversion
298 * 257 *
299 ******************************************************************************/ 258 ******************************************************************************/
300 259
301acpi_status 260static acpi_size
302acpi_rs_get_list_length(u8 * byte_stream_buffer, 261acpi_rs_struct_option_length(struct acpi_resource_source *resource_source)
303 u32 byte_stream_buffer_length, acpi_size * size_needed)
304{ 262{
305 u32 buffer_size = 0; 263 ACPI_FUNCTION_ENTRY();
306 u32 bytes_parsed = 0;
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
320 while (bytes_parsed < byte_stream_buffer_length) {
321 /* The next byte in the stream is the resource type */
322
323 resource_type = acpi_rs_get_resource_type(*byte_stream_buffer);
324 264
325 switch (resource_type) { 265 /*
326 case ACPI_RDESC_TYPE_MEMORY_24: 266 * If the resource_source string is valid, return the size of the string
327 /* 267 * (string_length includes the NULL terminator) plus the size of the
328 * 24-Bit Memory Resource 268 * resource_source_index (1).
329 */ 269 */
330 bytes_consumed = 12; 270 if (resource_source->string_ptr) {
331 271 return ((acpi_size) resource_source->string_length + 1);
332 structure_size = 272 }
333 ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24);
334 break;
335 273
336 case ACPI_RDESC_TYPE_LARGE_VENDOR: 274 return (0);
337 /* 275}
338 * Vendor Defined Resource
339 */
340 buffer = byte_stream_buffer;
341 ++buffer;
342 276
343 ACPI_MOVE_16_TO_16(&temp16, buffer); 277/*******************************************************************************
344 bytes_consumed = temp16 + 3; 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 ******************************************************************************/
345 292
346 /* Ensure a 32-bit boundary for the structure */ 293static u32
294acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length)
295{
296 u32 string_length = 0;
297 u32 minimum_resource_length;
347 298
348 temp16 = (u16) ACPI_ROUND_UP_to_32_bITS(temp16); 299 ACPI_FUNCTION_ENTRY();
349 300
350 structure_size = 301 /*
351 ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) + 302 * The resource_source_index and resource_source are optional elements of some
352 (temp16 * sizeof(u8)); 303 * Large-type resource descriptors.
353 break; 304 */
354 305
355 case ACPI_RDESC_TYPE_MEMORY_32: 306 /* Compute minimum size of the data part of the resource descriptor */
356 /*
357 * 32-Bit Memory Range Resource
358 */
359 bytes_consumed = 20;
360 307
361 structure_size = 308 minimum_resource_length =
362 ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32); 309 minimum_total_length - sizeof(struct asl_large_header);
363 break;
364 310
365 case ACPI_RDESC_TYPE_FIXED_MEMORY_32: 311 /*
366 /* 312 * If the length of the actual resource descriptor is greater than the ACPI
367 * 32-Bit Fixed Memory Resource 313 * spec-defined minimum length, it means that a resource_source_index exists
368 */ 314 * and is followed by a (required) null terminated string. The string length
369 bytes_consumed = 12; 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 */
370 320
371 structure_size = 321 string_length = resource_length - minimum_resource_length - 1;
372 ACPI_SIZEOF_RESOURCE(struct 322 }
373 acpi_resource_fixed_mem32);
374 break;
375 323
376 case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE: 324 /* Round up length to 32 bits for internal structure alignment */
377 /*
378 * 64-Bit Address Resource
379 */
380 buffer = byte_stream_buffer;
381 325
382 ++buffer; 326 return (ACPI_ROUND_UP_to_32_bITS(string_length));
383 ACPI_MOVE_16_TO_16(&temp16, buffer); 327}
384 328
385 bytes_consumed = temp16 + 3; 329/*******************************************************************************
386 structure_size = 330 *
387 ACPI_SIZEOF_RESOURCE(struct 331 * FUNCTION: acpi_rs_get_byte_stream_length
388 acpi_resource_address64); 332 *
389 break; 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 ******************************************************************************/
390 343
391 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE: 344acpi_status
392 /* 345acpi_rs_get_byte_stream_length(struct acpi_resource * resource,
393 * 64-Bit Address Resource 346 acpi_size * size_needed)
394 */ 347{
395 buffer = byte_stream_buffer; 348 acpi_size byte_stream_size_needed = 0;
349 acpi_size segment_size;
396 350
397 ++buffer; 351 ACPI_FUNCTION_TRACE("rs_get_byte_stream_length");
398 ACPI_MOVE_16_TO_16(&temp16, buffer);
399 352
400 bytes_consumed = temp16 + 3; 353 /* Traverse entire list of internal resource descriptors */
401 354
402 /* 355 while (resource) {
403 * Resource Source Index and Resource Source are optional elements. 356 /* Validate the descriptor type */
404 * Check the length of the Bytestream. If it is greater than 43,
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 */
410 if (43 < temp16) {
411 temp8 = (u8) (temp16 - 44);
412 } else {
413 temp8 = 0;
414 }
415 357
416 /* Ensure a 64-bit boundary for the structure */ 358 if (resource->type > ACPI_RSTYPE_MAX) {
359 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
360 }
417 361
418 temp8 = (u8) ACPI_ROUND_UP_to_64_bITS(temp8); 362 /* Get the base size of the (external stream) resource descriptor */
419 363
420 structure_size = 364 segment_size = acpi_gbl_stream_sizes[resource->type];
421 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64)
422 + (temp8 * sizeof(u8));
423 break;
424 365
425 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE: 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:
426 /* 372 /*
427 * 32-Bit Address Resource 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.
428 */ 377 */
429 buffer = byte_stream_buffer; 378 if (resource->data.vendor_specific.length > 7) {
430 379 /* Base size of a Large resource descriptor */
431 ++buffer;
432 ACPI_MOVE_16_TO_16(&temp16, buffer);
433 380
434 bytes_consumed = temp16 + 3; 381 segment_size = 3;
435
436 /*
437 * Resource Source Index and Resource Source are optional elements.
438 * Check the length of the Bytestream. If it is greater than 23,
439 * that means that an Index exists and is followed by a null
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 */
444 if (23 < temp16) {
445 temp8 = (u8) (temp16 - 24);
446 } else {
447 temp8 = 0;
448 } 382 }
449 383
450 /* Ensure a 32-bit boundary for the structure */ 384 /* Add the size of the vendor-specific data */
451 385
452 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); 386 segment_size += resource->data.vendor_specific.length;
453
454 structure_size =
455 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32)
456 + (temp8 * sizeof(u8));
457 break; 387 break;
458 388
459 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE: 389 case ACPI_RSTYPE_END_TAG:
460 /* 390 /*
461 * 16-Bit Address Resource 391 * End Tag:
392 * We are done -- return the accumulated total size.
462 */ 393 */
463 buffer = byte_stream_buffer; 394 *size_needed = byte_stream_size_needed + segment_size;
464 395
465 ++buffer; 396 /* Normal exit */
466 ACPI_MOVE_16_TO_16(&temp16, buffer);
467 397
468 bytes_consumed = temp16 + 3; 398 return_ACPI_STATUS(AE_OK);
469 399
400 case ACPI_RSTYPE_ADDRESS16:
470 /* 401 /*
471 * Resource Source Index and Resource Source are optional elements. 402 * 16-Bit Address Resource:
472 * Check the length of the Bytestream. If it is greater than 13, 403 * Add the size of the optional resource_source info
473 * that means that an Index exists and is followed by a null
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 */ 404 */
478 if (13 < temp16) { 405 segment_size +=
479 temp8 = (u8) (temp16 - 14); 406 acpi_rs_struct_option_length(&resource->data.
480 } else { 407 address16.
481 temp8 = 0; 408 resource_source);
482 }
483
484 /* Ensure a 32-bit boundary for the structure */
485
486 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
487
488 structure_size =
489 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16)
490 + (temp8 * sizeof(u8));
491 break; 409 break;
492 410
493 case ACPI_RDESC_TYPE_EXTENDED_XRUPT: 411 case ACPI_RSTYPE_ADDRESS32:
494 /*
495 * Extended IRQ
496 */
497 buffer = byte_stream_buffer;
498
499 ++buffer;
500 ACPI_MOVE_16_TO_16(&temp16, buffer);
501
502 bytes_consumed = temp16 + 3;
503
504 /* 412 /*
505 * Point past the length field and the Interrupt vector flags to 413 * 32-Bit Address Resource:
506 * save off the Interrupt table length to the Temp8 variable. 414 * Add the size of the optional resource_source info
507 */ 415 */
508 buffer += 3; 416 segment_size +=
509 temp8 = *buffer; 417 acpi_rs_struct_option_length(&resource->data.
418 address32.
419 resource_source);
420 break;
510 421
422 case ACPI_RSTYPE_ADDRESS64:
511 /* 423 /*
512 * To compensate for multiple interrupt numbers, add 4 bytes for 424 * 64-Bit Address Resource:
513 * each additional interrupts greater than 1 425 * Add the size of the optional resource_source info
514 */ 426 */
515 additional_bytes = (u8) ((temp8 - 1) * 4); 427 segment_size +=
428 acpi_rs_struct_option_length(&resource->data.
429 address64.
430 resource_source);
431 break;
516 432
433 case ACPI_RSTYPE_EXT_IRQ:
517 /* 434 /*
518 * Resource Source Index and Resource Source are optional elements. 435 * Extended IRQ Resource:
519 * Check the length of the Bytestream. If it is greater than 9, 436 * Add the size of each additional optional interrupt beyond the
520 * that means that an Index exists and is followed by a null 437 * required 1 (4 bytes for each u32 interrupt number)
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 */ 438 */
525 if (9 + additional_bytes < temp16) { 439 segment_size += (((acpi_size)
526 temp8 = (u8) (temp16 - (9 + additional_bytes)); 440 resource->data.extended_irq.
527 } else { 441 number_of_interrupts - 1) * 4);
528 temp8 = 0;
529 }
530 442
531 /* Ensure a 32-bit boundary for the structure */ 443 /* Add the size of the optional resource_source info */
532 444
533 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); 445 segment_size +=
446 acpi_rs_struct_option_length(&resource->data.
447 extended_irq.
448 resource_source);
449 break;
534 450
535 structure_size = 451 default:
536 ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq) +
537 (additional_bytes * sizeof(u8)) +
538 (temp8 * sizeof(u8));
539 break; 452 break;
453 }
540 454
541 case ACPI_RDESC_TYPE_IRQ_FORMAT: 455 /* Update the total */
542 /*
543 * IRQ Resource.
544 * Determine if it there are two or three trailing bytes
545 */
546 buffer = byte_stream_buffer;
547 temp8 = *buffer;
548 456
549 if (temp8 & 0x01) { 457 byte_stream_size_needed += segment_size;
550 bytes_consumed = 4;
551 } else {
552 bytes_consumed = 3;
553 }
554 458
555 /* Point past the descriptor */ 459 /* Point to the next object */
556 460
557 ++buffer; 461 resource = ACPI_PTR_ADD(struct acpi_resource,
462 resource, resource->length);
463 }
558 464
559 /* Look at the number of bits set */ 465 /* Did not find an END_TAG descriptor */
560 466
561 ACPI_MOVE_16_TO_16(&temp16, buffer); 467 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
468}
562 469
563 for (index = 0; index < 16; index++) { 470/*******************************************************************************
564 if (temp16 & 0x1) { 471 *
565 ++number_of_interrupts; 472 * FUNCTION: acpi_rs_get_list_length
566 } 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 ******************************************************************************/
567 485
568 temp16 >>= 1; 486acpi_status
569 } 487acpi_rs_get_list_length(u8 * byte_stream_buffer,
488 u32 byte_stream_buffer_length, acpi_size * size_needed)
489{
490 u8 *buffer;
491 struct acpi_resource_sizes *resource_info;
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;
570 499
571 structure_size = 500 ACPI_FUNCTION_TRACE("rs_get_list_length");
572 ACPI_SIZEOF_RESOURCE(struct acpi_resource_io) +
573 (number_of_interrupts * sizeof(u32));
574 break;
575 501
576 case ACPI_RDESC_TYPE_DMA_FORMAT: 502 while (bytes_parsed < byte_stream_buffer_length) {
577 /* 503 /* The next byte in the stream is the resource descriptor type */
578 * DMA Resource
579 */
580 buffer = byte_stream_buffer;
581 bytes_consumed = 3;
582 504
583 /* Point past the descriptor */ 505 resource_type = acpi_rs_get_resource_type(*byte_stream_buffer);
584 506
585 ++buffer; 507 /* Get the base stream size and structure sizes for the descriptor */
586 508
587 /* Look at the number of bits set */ 509 resource_info = acpi_rs_get_resource_sizes(resource_type);
510 if (!resource_info) {
511 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
512 }
588 513
589 temp8 = *buffer; 514 /* Get the Length field from the input resource descriptor */
590 515
591 for (index = 0; index < 8; index++) { 516 resource_length =
592 if (temp8 & 0x1) { 517 acpi_rs_get_resource_length(byte_stream_buffer);
593 ++number_of_channels;
594 }
595 518
596 temp8 >>= 1; 519 /* Augment the size for descriptors with optional fields */
597 }
598 520
599 structure_size = 521 extra_struct_bytes = 0;
600 ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma) +
601 (number_of_channels * sizeof(u32));
602 break;
603 522
604 case ACPI_RDESC_TYPE_START_DEPENDENT: 523 if (!(resource_type & ACPI_RDESC_TYPE_LARGE)) {
605 /* 524 /*
606 * Start Dependent Functions Resource 525 * Small resource descriptors
607 * Determine if it there are two or three trailing bytes
608 */ 526 */
609 buffer = byte_stream_buffer; 527 header_length = 1;
610 temp8 = *buffer; 528 buffer = byte_stream_buffer + header_length;
611 529
612 if (temp8 & 0x01) { 530 switch (resource_type) {
613 bytes_consumed = 2; 531 case ACPI_RDESC_TYPE_IRQ_FORMAT:
614 } else { 532 /*
615 bytes_consumed = 1; 533 * IRQ Resource:
616 } 534 * Get the number of bits set in the IRQ word
535 */
536 ACPI_MOVE_16_TO_16(&temp16, buffer);
617 537
618 structure_size = 538 extra_struct_bytes =
619 ACPI_SIZEOF_RESOURCE(struct 539 (acpi_rs_count_set_bits(temp16) *
620 acpi_resource_start_dpf); 540 sizeof(u32));
621 break; 541 break;
622 542
623 case ACPI_RDESC_TYPE_END_DEPENDENT: 543 case ACPI_RDESC_TYPE_DMA_FORMAT:
624 /* 544 /*
625 * End Dependent Functions Resource 545 * DMA Resource:
626 */ 546 * Get the number of bits set in the DMA channels byte
627 bytes_consumed = 1; 547 */
628 structure_size = ACPI_RESOURCE_LENGTH; 548 extra_struct_bytes =
629 break; 549 (acpi_rs_count_set_bits((u16) * buffer) *
550 sizeof(u32));
551 break;
630 552
631 case ACPI_RDESC_TYPE_IO_PORT: 553 case ACPI_RDESC_TYPE_SMALL_VENDOR:
632 /* 554 /*
633 * IO Port Resource 555 * Vendor Specific Resource:
634 */ 556 * Ensure a 32-bit boundary for the structure
635 bytes_consumed = 8; 557 */
636 structure_size = 558 extra_struct_bytes =
637 ACPI_SIZEOF_RESOURCE(struct acpi_resource_io); 559 ACPI_ROUND_UP_to_32_bITS(resource_length);
638 break; 560 break;
639 561
640 case ACPI_RDESC_TYPE_FIXED_IO_PORT: 562 case ACPI_RDESC_TYPE_END_TAG:
641 /* 563 /*
642 * Fixed IO Port Resource 564 * End Tag:
643 */ 565 * Terminate the loop now
644 bytes_consumed = 4; 566 */
645 structure_size = 567 byte_stream_buffer_length = bytes_parsed;
646 ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io); 568 break;
647 break;
648 569
649 case ACPI_RDESC_TYPE_SMALL_VENDOR: 570 default:
571 break;
572 }
573 } else {
650 /* 574 /*
651 * Vendor Specific Resource 575 * Large resource descriptors
652 */ 576 */
653 buffer = byte_stream_buffer; 577 header_length = sizeof(struct asl_large_header);
578 buffer = byte_stream_buffer + header_length;
654 579
655 temp8 = *buffer; 580 switch (resource_type) {
656 temp8 = (u8) (temp8 & 0x7); 581 case ACPI_RDESC_TYPE_LARGE_VENDOR:
657 bytes_consumed = temp8 + 1; 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;
658 589
659 /* Ensure a 32-bit boundary for the structure */ 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;
660 601
661 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); 602 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
662 structure_size = 603 /*
663 ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) + 604 * Extended IRQ:
664 (temp8 * sizeof(u8)); 605 * Point past the interrupt_vector_flags to get the
665 break; 606 * interrupt_table_length.
607 */
608 buffer++;
666 609
667 case ACPI_RDESC_TYPE_END_TAG: 610 /*
668 /* 611 * Add 4 bytes for each additional interrupt. Note: at least one
669 * End Tag 612 * interrupt is required and is included in the minimum
670 */ 613 * descriptor size
671 bytes_consumed = 2; 614 */
672 structure_size = ACPI_RESOURCE_LENGTH; 615 extra_struct_bytes =
673 byte_stream_buffer_length = bytes_parsed; 616 ((*buffer - 1) * sizeof(u32));
674 break;
675 617
676 default: 618 /* Add the size of any optional data (resource_source) */
677 /*
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 }
683 619
684 /* Update the return value and counter */ 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;
685 627
686 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(structure_size); 628 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
687 bytes_parsed += bytes_consumed; 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 }
645
646 /* Update the required buffer size for the internal descriptor structs */
688 647
689 /* Set the byte stream to point to the next resource */ 648 temp16 =
649 (u16) (resource_info->minimum_struct_size +
650 extra_struct_bytes);
651 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(temp16);
690 652
691 byte_stream_buffer += bytes_consumed; 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;
692 } 660 }
693 661
694 /* This is the data the caller needs */ 662 /* This is the data the caller needs */
@@ -790,7 +758,8 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
790 (*sub_object_list)->string. 758 (*sub_object_list)->string.
791 length + 1); 759 length + 1);
792 } else { 760 } else {
793 temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node); 761 temp_size_needed +=
762 acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
794 } 763 }
795 } else { 764 } else {
796 /* 765 /*