blob: 378f58390fc14935fff3f9fa4e519e6d2293e143 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acresrc.h>
46#include <acpi/amlcode.h>
47#include <acpi/acnamesp.h>
48
49#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("rscalc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_rs_get_byte_stream_length
55 *
56 * PARAMETERS: linked_list - Pointer to the resource linked list
57 * size_needed - u32 pointer of the size buffer needed
58 * to properly return the parsed data
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
63 * the size buffer needed to hold the linked list that conveys
64 * the resource data.
65 *
66 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070067acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_rs_get_byte_stream_length(struct acpi_resource *linked_list,
69 acpi_size * size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Len Brown4be44fc2005-08-05 00:44:28 -040071 acpi_size byte_stream_size_needed = 0;
72 acpi_size segment_size;
73 u8 done = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Len Brown4be44fc2005-08-05 00:44:28 -040075 ACPI_FUNCTION_TRACE("rs_get_byte_stream_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 while (!done) {
Robert Moore44f6c012005-04-18 22:49:35 -040078 /* Init the variable that will hold the size to add to the total. */
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 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
125 case ACPI_RSTYPE_FIXED_IO:
126 /*
127 * Fixed IO Port Resource
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;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 segment_size = 1;
144 }
Len Brown4be44fc2005-08-05 00:44:28 -0400145 segment_size +=
146 linked_list->data.vendor_specific.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 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
166 case ACPI_RSTYPE_MEM32:
167 /*
168 * 32-Bit Memory Range Resource
169 * For this resource the size is static
170 */
171 segment_size = 20;
172 break;
173
174 case ACPI_RSTYPE_FIXED_MEM32:
175 /*
176 * 32-Bit Fixed Memory Resource
177 * For this resource the size is static
178 */
179 segment_size = 12;
180 break;
181
182 case ACPI_RSTYPE_ADDRESS16:
183 /*
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
Len Brown4be44fc2005-08-05 00:44:28 -0400191 if (linked_list->data.address16.resource_source.
192 string_ptr) {
Robert Moore44f6c012005-04-18 22:49:35 -0400193 segment_size +=
Len Brown4be44fc2005-08-05 00:44:28 -0400194 linked_list->data.address16.resource_source.
195 string_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 segment_size++;
197 }
198 break;
199
200 case ACPI_RSTYPE_ADDRESS32:
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
Len Brown4be44fc2005-08-05 00:44:28 -0400210 if (linked_list->data.address32.resource_source.
211 string_ptr) {
Robert Moore44f6c012005-04-18 22:49:35 -0400212 segment_size +=
Len Brown4be44fc2005-08-05 00:44:28 -0400213 linked_list->data.address32.resource_source.
214 string_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 segment_size++;
216 }
217 break;
218
219 case ACPI_RSTYPE_ADDRESS64:
220 /*
221 * 64-Bit Address Resource
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
Len Brown4be44fc2005-08-05 00:44:28 -0400228 if (linked_list->data.address64.resource_source.
229 string_ptr) {
Robert Moore44f6c012005-04-18 22:49:35 -0400230 segment_size +=
Len Brown4be44fc2005-08-05 00:44:28 -0400231 linked_list->data.address64.resource_source.
232 string_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 segment_size++;
234 }
235 break;
236
237 case ACPI_RSTYPE_EXT_IRQ:
238 /*
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 */
Robert Moore44f6c012005-04-18 22:49:35 -0400246 segment_size = 9 + (((acpi_size)
Len Brown4be44fc2005-08-05 00:44:28 -0400247 linked_list->data.extended_irq.
248 number_of_interrupts - 1) * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Len Brown4be44fc2005-08-05 00:44:28 -0400250 if (linked_list->data.extended_irq.resource_source.
251 string_ptr) {
Robert Moore44f6c012005-04-18 22:49:35 -0400252 segment_size +=
Len Brown4be44fc2005-08-05 00:44:28 -0400253 linked_list->data.extended_irq.
254 resource_source.string_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 segment_size++;
256 }
257 break;
258
259 default:
Robert Moore44f6c012005-04-18 22:49:35 -0400260
261 /* If we get here, everything is out of sync, exit with error */
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Len Brown4be44fc2005-08-05 00:44:28 -0400265 } /* switch (linked_list->Id) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Robert Moore44f6c012005-04-18 22:49:35 -0400267 /* Update the total */
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 byte_stream_size_needed += segment_size;
270
Robert Moore44f6c012005-04-18 22:49:35 -0400271 /* Point to the next object */
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 linked_list = ACPI_PTR_ADD(struct acpi_resource,
274 linked_list, linked_list->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
Robert Moore44f6c012005-04-18 22:49:35 -0400277 /* This is the data the caller needs */
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 *size_needed = byte_stream_size_needed;
Len Brown4be44fc2005-08-05 00:44:28 -0400280 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283/*******************************************************************************
284 *
285 * FUNCTION: acpi_rs_get_list_length
286 *
287 * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream
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 *
293 * RETURN: Status
294 *
295 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
296 * the size buffer needed to hold the linked list that conveys
297 * the resource data.
298 *
299 ******************************************************************************/
300
301acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400302acpi_rs_get_list_length(u8 * byte_stream_buffer,
303 u32 byte_stream_buffer_length, acpi_size * size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Len Brown4be44fc2005-08-05 00:44:28 -0400305 u32 buffer_size = 0;
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Len Brown4be44fc2005-08-05 00:44:28 -0400318 ACPI_FUNCTION_TRACE("rs_get_list_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 while (bytes_parsed < byte_stream_buffer_length) {
Robert Moore44f6c012005-04-18 22:49:35 -0400321 /* The next byte in the stream is the resource type */
322
Len Brown4be44fc2005-08-05 00:44:28 -0400323 resource_type = acpi_rs_get_resource_type(*byte_stream_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 switch (resource_type) {
326 case ACPI_RDESC_TYPE_MEMORY_24:
327 /*
328 * 24-Bit Memory Resource
329 */
330 bytes_consumed = 12;
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 structure_size =
333 ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 break;
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 case ACPI_RDESC_TYPE_LARGE_VENDOR:
337 /*
338 * Vendor Defined Resource
339 */
340 buffer = byte_stream_buffer;
341 ++buffer;
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 bytes_consumed = temp16 + 3;
345
Robert Moore44f6c012005-04-18 22:49:35 -0400346 /* Ensure a 32-bit boundary for the structure */
347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 temp16 = (u16) ACPI_ROUND_UP_to_32_bITS(temp16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 structure_size =
351 ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) +
352 (temp16 * sizeof(u8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 break;
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 case ACPI_RDESC_TYPE_MEMORY_32:
356 /*
357 * 32-Bit Memory Range Resource
358 */
359 bytes_consumed = 20;
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361 structure_size =
362 ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 break;
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
366 /*
367 * 32-Bit Fixed Memory Resource
368 */
369 bytes_consumed = 12;
370
Len Brown4be44fc2005-08-05 00:44:28 -0400371 structure_size =
372 ACPI_SIZEOF_RESOURCE(struct
373 acpi_resource_fixed_mem32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE:
377 /*
378 * 64-Bit Address Resource
379 */
380 buffer = byte_stream_buffer;
381
382 ++buffer;
Len Brown4be44fc2005-08-05 00:44:28 -0400383 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 bytes_consumed = temp16 + 3;
Len Brown4be44fc2005-08-05 00:44:28 -0400386 structure_size =
387 ACPI_SIZEOF_RESOURCE(struct
388 acpi_resource_address64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 break;
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
392 /*
393 * 64-Bit Address Resource
394 */
395 buffer = byte_stream_buffer;
396
397 ++buffer;
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 bytes_consumed = temp16 + 3;
401
402 /*
403 * Resource Source Index and Resource Source are optional elements.
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);
Len Brown4be44fc2005-08-05 00:44:28 -0400412 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 temp8 = 0;
414 }
415
Robert Moore44f6c012005-04-18 22:49:35 -0400416 /* Ensure a 64-bit boundary for the structure */
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 temp8 = (u8) ACPI_ROUND_UP_to_64_bITS(temp8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 structure_size =
421 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64)
422 + (temp8 * sizeof(u8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 break;
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
426 /*
427 * 32-Bit Address Resource
428 */
429 buffer = byte_stream_buffer;
430
431 ++buffer;
Len Brown4be44fc2005-08-05 00:44:28 -0400432 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 bytes_consumed = temp16 + 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);
Len Brown4be44fc2005-08-05 00:44:28 -0400446 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 temp8 = 0;
448 }
449
Robert Moore44f6c012005-04-18 22:49:35 -0400450 /* Ensure a 32-bit boundary for the structure */
451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 structure_size =
455 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32)
456 + (temp8 * sizeof(u8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 break;
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
460 /*
461 * 16-Bit Address Resource
462 */
463 buffer = byte_stream_buffer;
464
465 ++buffer;
Len Brown4be44fc2005-08-05 00:44:28 -0400466 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 bytes_consumed = temp16 + 3;
469
470 /*
471 * Resource Source Index and Resource Source are optional elements.
472 * Check the length of the Bytestream. If it is greater than 13,
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 */
478 if (13 < temp16) {
479 temp8 = (u8) (temp16 - 14);
Len Brown4be44fc2005-08-05 00:44:28 -0400480 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 temp8 = 0;
482 }
483
Robert Moore44f6c012005-04-18 22:49:35 -0400484 /* Ensure a 32-bit boundary for the structure */
485
Len Brown4be44fc2005-08-05 00:44:28 -0400486 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Len Brown4be44fc2005-08-05 00:44:28 -0400488 structure_size =
489 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16)
490 + (temp8 * sizeof(u8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 break;
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
494 /*
495 * Extended IRQ
496 */
497 buffer = byte_stream_buffer;
498
499 ++buffer;
Len Brown4be44fc2005-08-05 00:44:28 -0400500 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 bytes_consumed = temp16 + 3;
503
504 /*
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
511 /*
512 * To compensate for multiple interrupt numbers, add 4 bytes for
513 * each additional interrupts greater than 1
514 */
515 additional_bytes = (u8) ((temp8 - 1) * 4);
516
517 /*
518 * Resource Source Index and Resource Source are optional elements.
519 * Check the length of the Bytestream. If it is greater than 9,
520 * that means that an Index exists and is followed by a null
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));
Len Brown4be44fc2005-08-05 00:44:28 -0400527 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 temp8 = 0;
529 }
530
Robert Moore44f6c012005-04-18 22:49:35 -0400531 /* Ensure a 32-bit boundary for the structure */
532
Len Brown4be44fc2005-08-05 00:44:28 -0400533 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Len Brown4be44fc2005-08-05 00:44:28 -0400535 structure_size =
536 ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq) +
537 (additional_bytes * sizeof(u8)) +
538 (temp8 * sizeof(u8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 break;
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 case ACPI_RDESC_TYPE_IRQ_FORMAT:
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
Len Brown4be44fc2005-08-05 00:44:28 -0400549 if (temp8 & 0x01) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 bytes_consumed = 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400551 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 bytes_consumed = 3;
553 }
554
555 /* Point past the descriptor */
556
557 ++buffer;
558
Robert Moore44f6c012005-04-18 22:49:35 -0400559 /* Look at the number of bits set */
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 for (index = 0; index < 16; index++) {
564 if (temp16 & 0x1) {
565 ++number_of_interrupts;
566 }
567
568 temp16 >>= 1;
569 }
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571 structure_size =
572 ACPI_SIZEOF_RESOURCE(struct acpi_resource_io) +
573 (number_of_interrupts * sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 break;
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 case ACPI_RDESC_TYPE_DMA_FORMAT:
577 /*
578 * DMA Resource
579 */
580 buffer = byte_stream_buffer;
581 bytes_consumed = 3;
582
583 /* Point past the descriptor */
584
585 ++buffer;
586
Robert Moore44f6c012005-04-18 22:49:35 -0400587 /* Look at the number of bits set */
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 temp8 = *buffer;
590
Len Brown4be44fc2005-08-05 00:44:28 -0400591 for (index = 0; index < 8; index++) {
592 if (temp8 & 0x1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 ++number_of_channels;
594 }
595
596 temp8 >>= 1;
597 }
598
Len Brown4be44fc2005-08-05 00:44:28 -0400599 structure_size =
600 ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma) +
601 (number_of_channels * sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 break;
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 case ACPI_RDESC_TYPE_START_DEPENDENT:
605 /*
606 * Start Dependent Functions Resource
607 * Determine if it there are two or three trailing bytes
608 */
609 buffer = byte_stream_buffer;
610 temp8 = *buffer;
611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 if (temp8 & 0x01) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 bytes_consumed = 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400614 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 bytes_consumed = 1;
616 }
617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 structure_size =
619 ACPI_SIZEOF_RESOURCE(struct
620 acpi_resource_start_dpf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 case ACPI_RDESC_TYPE_END_DEPENDENT:
624 /*
625 * End Dependent Functions Resource
626 */
627 bytes_consumed = 1;
628 structure_size = ACPI_RESOURCE_LENGTH;
629 break;
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 case ACPI_RDESC_TYPE_IO_PORT:
632 /*
633 * IO Port Resource
634 */
635 bytes_consumed = 8;
Len Brown4be44fc2005-08-05 00:44:28 -0400636 structure_size =
637 ACPI_SIZEOF_RESOURCE(struct acpi_resource_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 break;
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 case ACPI_RDESC_TYPE_FIXED_IO_PORT:
641 /*
642 * Fixed IO Port Resource
643 */
644 bytes_consumed = 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400645 structure_size =
646 ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 break;
648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 case ACPI_RDESC_TYPE_SMALL_VENDOR:
650 /*
651 * Vendor Specific Resource
652 */
653 buffer = byte_stream_buffer;
654
655 temp8 = *buffer;
656 temp8 = (u8) (temp8 & 0x7);
657 bytes_consumed = temp8 + 1;
658
Robert Moore44f6c012005-04-18 22:49:35 -0400659 /* Ensure a 32-bit boundary for the structure */
660
Len Brown4be44fc2005-08-05 00:44:28 -0400661 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
662 structure_size =
663 ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) +
664 (temp8 * sizeof(u8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 break;
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 case ACPI_RDESC_TYPE_END_TAG:
668 /*
669 * End Tag
670 */
671 bytes_consumed = 2;
672 structure_size = ACPI_RESOURCE_LENGTH;
673 byte_stream_buffer_length = bytes_parsed;
674 break;
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 default:
677 /*
678 * If we get here, everything is out of sync,
679 * exit with an error
680 */
Len Brown4be44fc2005-08-05 00:44:28 -0400681 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683
Robert Moore44f6c012005-04-18 22:49:35 -0400684 /* Update the return value and counter */
685
Len Brown4be44fc2005-08-05 00:44:28 -0400686 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(structure_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 bytes_parsed += bytes_consumed;
688
Robert Moore44f6c012005-04-18 22:49:35 -0400689 /* Set the byte stream to point to the next resource */
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 byte_stream_buffer += bytes_consumed;
692 }
693
Robert Moore44f6c012005-04-18 22:49:35 -0400694 /* This is the data the caller needs */
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 *size_needed = buffer_size;
Len Brown4be44fc2005-08-05 00:44:28 -0400697 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700/*******************************************************************************
701 *
702 * FUNCTION: acpi_rs_get_pci_routing_table_length
703 *
704 * PARAMETERS: package_object - Pointer to the package object
705 * buffer_size_needed - u32 pointer of the size buffer
706 * needed to properly return the
707 * parsed data
708 *
709 * RETURN: Status
710 *
711 * DESCRIPTION: Given a package representing a PCI routing table, this
712 * calculates the size of the corresponding linked list of
713 * descriptions.
714 *
715 ******************************************************************************/
716
717acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400718acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
719 acpi_size * buffer_size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Len Brown4be44fc2005-08-05 00:44:28 -0400721 u32 number_of_elements;
722 acpi_size temp_size_needed = 0;
723 union acpi_operand_object **top_object_list;
724 u32 index;
725 union acpi_operand_object *package_element;
726 union acpi_operand_object **sub_object_list;
727 u8 name_found;
728 u32 table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Len Brown4be44fc2005-08-05 00:44:28 -0400730 ACPI_FUNCTION_TRACE("rs_get_pci_routing_table_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 number_of_elements = package_object->package.count;
733
734 /*
735 * Calculate the size of the return buffer.
736 * The base size is the number of elements * the sizes of the
737 * structures. Additional space for the strings is added below.
738 * The minus one is to subtract the size of the u8 Source[1]
739 * member because it is added below.
740 *
741 * But each PRT_ENTRY structure has a pointer to a string and
742 * the size of that string must be found.
743 */
744 top_object_list = package_object->package.elements;
745
746 for (index = 0; index < number_of_elements; index++) {
Robert Moore44f6c012005-04-18 22:49:35 -0400747 /* Dereference the sub-package */
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 package_element = *top_object_list;
750
751 /*
752 * The sub_object_list will now point to an array of the
753 * four IRQ elements: Address, Pin, Source and source_index
754 */
755 sub_object_list = package_element->package.elements;
756
Robert Moore44f6c012005-04-18 22:49:35 -0400757 /* Scan the irq_table_elements for the Source Name String */
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 name_found = FALSE;
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761 for (table_index = 0; table_index < 4 && !name_found;
762 table_index++) {
Robert Moore44f6c012005-04-18 22:49:35 -0400763 if ((ACPI_TYPE_STRING ==
Len Brown4be44fc2005-08-05 00:44:28 -0400764 ACPI_GET_OBJECT_TYPE(*sub_object_list))
765 ||
766 ((ACPI_TYPE_LOCAL_REFERENCE ==
767 ACPI_GET_OBJECT_TYPE(*sub_object_list))
768 && ((*sub_object_list)->reference.opcode ==
769 AML_INT_NAMEPATH_OP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 name_found = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400771 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400772 /* Look at the next element */
773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 sub_object_list++;
775 }
776 }
777
Len Brown4be44fc2005-08-05 00:44:28 -0400778 temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Robert Moore44f6c012005-04-18 22:49:35 -0400780 /* Was a String type found? */
781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 if (name_found) {
Len Brown4be44fc2005-08-05 00:44:28 -0400783 if (ACPI_GET_OBJECT_TYPE(*sub_object_list) ==
784 ACPI_TYPE_STRING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 /*
786 * The length String.Length field does not include the
787 * terminating NULL, add 1
788 */
Robert Moore44f6c012005-04-18 22:49:35 -0400789 temp_size_needed += ((acpi_size)
Len Brown4be44fc2005-08-05 00:44:28 -0400790 (*sub_object_list)->string.
791 length + 1);
792 } else {
793 temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
Len Brown4be44fc2005-08-05 00:44:28 -0400795 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 /*
797 * If no name was found, then this is a NULL, which is
798 * translated as a u32 zero.
799 */
Len Brown4be44fc2005-08-05 00:44:28 -0400800 temp_size_needed += sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802
803 /* Round up the size since each element must be aligned */
804
Len Brown4be44fc2005-08-05 00:44:28 -0400805 temp_size_needed = ACPI_ROUND_UP_to_64_bITS(temp_size_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Robert Moore44f6c012005-04-18 22:49:35 -0400807 /* Point to the next union acpi_operand_object */
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 top_object_list++;
810 }
811
812 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400813 * Adding an extra element to the end of the list, essentially a
814 * NULL terminator
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 */
Len Brown4be44fc2005-08-05 00:44:28 -0400816 *buffer_size_needed =
817 temp_size_needed + sizeof(struct acpi_pci_routing_table);
818 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}