1 /*******************************************************************************
3 * Module Name: rscalc - Acpi_rs_calculate_byte_stream_length
4 * Acpi_rs_calculate_list_length
7 ******************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define _COMPONENT ACPI_RESOURCES
31 MODULE_NAME ("rscalc")
34 /*******************************************************************************
36 * FUNCTION: Acpi_rs_calculate_byte_stream_length
38 * PARAMETERS: Linked_list - Pointer to the resource linked list
39 * Size_needed - u32 pointer of the size buffer needed
40 * to properly return the parsed data
42 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
44 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
45 * the size buffer needed to hold the linked list that conveys
48 ******************************************************************************/
51 acpi_rs_calculate_byte_stream_length (
52 RESOURCE
*linked_list
,
55 u32 byte_stream_size_needed
= 0;
57 EXTENDED_IRQ_RESOURCE
*ex_irq
= NULL
;
64 * Init the variable that will hold the size to add to the
69 switch (linked_list
->id
) {
75 * For an IRQ Resource, Byte 3, although optional, will
76 * always be created - it holds IRQ information.
86 * For this resource the size is static
91 case start_dependent_functions
:
93 * Start Dependent Functions Resource
96 * For a Start_dependent_functions Resource, Byte 1,
97 * although optional, will always be created.
102 case end_dependent_functions
:
104 * End Dependent Functions Resource
107 * For this resource the size is static
117 * For this resource the size is static
124 * Fixed IO Port Resource
127 * For this resource the size is static
132 case vendor_specific
:
134 * Vendor Defined Resource
137 * For a Vendor Specific resource, if the Length is
138 * between 1 and 7 it will be created as a Small
139 * Resource data type, otherwise it is a Large
140 * Resource data type.
142 if(linked_list
->data
.vendor_specific
.length
> 7) {
149 linked_list
->data
.vendor_specific
.length
;
157 * For this resource the size is static
165 * 24-Bit Memory Resource
168 * For this resource the size is static
175 * 32-Bit Memory Range Resource
178 * For this resource the size is static
185 * 32-Bit Fixed Memory Resource
188 * For this resource the size is static
195 * 16-Bit Address Resource
198 * The base size of this byte stream is 16. If a
199 * Resource Source string is not NULL, add 1 for
200 * the Index + the length of the null terminated
201 * string Resource Source + 1 for the null.
205 if(NULL
!= linked_list
->data
.address16
.resource_source
) {
207 linked_list
->data
.address16
.resource_source_string_length
);
213 * 32-Bit Address Resource
216 * The base size of this byte stream is 26. If a Resource
217 * Source string is not NULL, add 1 for the Index + the
218 * length of the null terminated string Resource Source +
223 if(NULL
!= linked_list
->data
.address16
.resource_source
) {
225 linked_list
->data
.address16
.resource_source_string_length
);
231 * Extended IRQ Resource
234 * The base size of this byte stream is 9. This is for an
235 * Interrupt table length of 1. For each additional
237 * If a Resource Source string is not NULL, add 1 for the
238 * Index + the length of the null terminated string
239 * Resource Source + 1 for the null.
244 (linked_list
->data
.extended_irq
.number_of_interrupts
-
247 if(NULL
!= ex_irq
->resource_source
) {
249 linked_list
->data
.extended_irq
.resource_source_string_length
);
255 * If we get here, everything is out of sync,
256 * so exit with an error
258 return (AE_AML_ERROR
);
261 } /* switch (Linked_list->Id) */
266 byte_stream_size_needed
+= segment_size
;
269 * Point to the next object
271 linked_list
= (RESOURCE
*) ((NATIVE_UINT
) linked_list
+
272 (NATIVE_UINT
) linked_list
->length
);
276 * This is the data the caller needs
278 *size_needed
= byte_stream_size_needed
;
284 /*******************************************************************************
286 * FUNCTION: Acpi_rs_calculate_list_length
288 * PARAMETERS: Byte_stream_buffer - Pointer to the resource byte stream
289 * Byte_stream_buffer_length - Size of Byte_stream_buffer
290 * Size_needed - u32 pointer of the size buffer
291 * needed to properly return the
294 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
296 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
297 * the size buffer needed to hold the linked list that conveys
300 ******************************************************************************/
303 acpi_rs_calculate_list_length (
304 u8
*byte_stream_buffer
,
305 u32 byte_stream_buffer_length
,
309 u32 bytes_parsed
= 0;
310 u8 number_of_interrupts
= 0;
311 u8 number_of_channels
= 0;
322 while (bytes_parsed
< byte_stream_buffer_length
) {
324 * Look at the next byte in the stream
326 resource_type
= *byte_stream_buffer
;
329 * See if this is a small or large resource
331 if(resource_type
& 0x80) {
333 * Large Resource Type
335 switch (resource_type
) {
336 case MEMORY_RANGE_24
:
338 * 24-Bit Memory Resource
342 structure_size
= sizeof (MEMORY24_RESOURCE
) +
343 RESOURCE_LENGTH_NO_DATA
;
346 case LARGE_VENDOR_DEFINED
:
348 * Vendor Defined Resource
350 buffer
= byte_stream_buffer
;
353 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
354 bytes_consumed
= temp16
+ 3;
357 * Ensure a 32-bit boundary for the structure
359 temp16
= (u16
) ROUND_UP_TO_32_bITS (temp16
);
361 structure_size
= sizeof (VENDOR_RESOURCE
) +
362 RESOURCE_LENGTH_NO_DATA
+
363 (temp16
* sizeof (u8
));
366 case MEMORY_RANGE_32
:
368 * 32-Bit Memory Range Resource
373 structure_size
= sizeof (MEMORY32_RESOURCE
) +
374 RESOURCE_LENGTH_NO_DATA
;
377 case FIXED_MEMORY_RANGE_32
:
379 * 32-Bit Fixed Memory Resource
383 structure_size
= sizeof(FIXED_MEMORY32_RESOURCE
) +
384 RESOURCE_LENGTH_NO_DATA
;
387 case DWORD_ADDRESS_SPACE
:
389 * 32-Bit Address Resource
391 buffer
= byte_stream_buffer
;
394 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
396 bytes_consumed
= temp16
+ 3;
399 * Resource Source Index and Resource Source are
400 * optional elements. Check the length of the
401 * Bytestream. If it is greater than 23, that
402 * means that an Index exists and is followed by
403 * a null termininated string. Therefore, set
404 * the temp variable to the length minus the minimum
405 * byte stream length plus the byte for the Index to
406 * determine the size of the NULL terminiated string.
409 temp8
= (u8
) (temp16
- 24);
416 * Ensure a 32-bit boundary for the structure
418 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
420 structure_size
= sizeof (ADDRESS32_RESOURCE
) +
421 RESOURCE_LENGTH_NO_DATA
+
422 (temp8
* sizeof (u8
));
425 case WORD_ADDRESS_SPACE
:
427 * 16-Bit Address Resource
429 buffer
= byte_stream_buffer
;
432 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
434 bytes_consumed
= temp16
+ 3;
437 * Resource Source Index and Resource Source are
438 * optional elements. Check the length of the
439 * Bytestream. If it is greater than 13, that
440 * means that an Index exists and is followed by
441 * a null termininated string. Therefore, set
442 * the temp variable to the length minus the minimum
443 * byte stream length plus the byte for the Index to
444 * determine the size of the NULL terminiated string.
447 temp8
= (u8
) (temp16
- 14);
454 * Ensure a 32-bit boundry for the structure
456 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
458 structure_size
= sizeof (ADDRESS16_RESOURCE
) +
459 RESOURCE_LENGTH_NO_DATA
+
460 (temp8
* sizeof (u8
));
467 buffer
= byte_stream_buffer
;
470 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
472 bytes_consumed
= temp16
+ 3;
475 * Point past the length field and the
476 * Interrupt vector flags to save off the
477 * Interrupt table length to the Temp8 variable.
483 * To compensate for multiple interrupt numbers,
484 * Add 4 bytes for each additional interrupts
487 additional_bytes
= (u8
) ((temp8
- 1) * 4);
490 * Resource Source Index and Resource Source are
491 * optional elements. Check the length of the
492 * Bytestream. If it is greater than 9, that
493 * means that an Index exists and is followed by
494 * a null termininated string. Therefore, set
495 * the temp variable to the length minus the minimum
496 * byte stream length plus the byte for the Index to
497 * determine the size of the NULL terminiated string.
499 if (9 + additional_bytes
< temp16
) {
500 temp8
= (u8
) (temp16
- (9 + additional_bytes
));
508 * Ensure a 32-bit boundry for the structure
510 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
512 structure_size
= sizeof (EXTENDED_IRQ_RESOURCE
) +
513 RESOURCE_LENGTH_NO_DATA
+
514 (additional_bytes
* sizeof (u8
)) +
515 (temp8
* sizeof (u8
));
519 /* TBD: [Future] 64-bit not currently supported */
527 * If we get here, everything is out of sync,
528 * so exit with an error
530 return (AE_AML_ERROR
);
537 * Small Resource Type
538 * Only bits 7:3 are valid
542 switch (resource_type
) {
548 * Determine if it there are two or three
551 buffer
= byte_stream_buffer
;
563 * Point past the descriptor
568 * Look at the number of bits set
570 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
572 for (index
= 0; index
< 16; index
++) {
574 ++number_of_interrupts
;
580 structure_size
= sizeof (IO_RESOURCE
) +
581 RESOURCE_LENGTH_NO_DATA
+
582 (number_of_interrupts
* sizeof (u32
));
591 buffer
= byte_stream_buffer
;
596 * Point past the descriptor
601 * Look at the number of bits set
605 for(index
= 0; index
< 8; index
++) {
607 ++number_of_channels
;
613 structure_size
= sizeof (DMA_RESOURCE
) +
614 RESOURCE_LENGTH_NO_DATA
+
615 (number_of_channels
* sizeof (u32
));
619 case START_DEPENDENT_TAG
:
622 * Start Dependent Functions Resource
625 * Determine if it there are two or three trailing bytes
627 buffer
= byte_stream_buffer
;
639 sizeof (START_DEPENDENT_FUNCTIONS_RESOURCE
) +
640 RESOURCE_LENGTH_NO_DATA
;
644 case END_DEPENDENT_TAG
:
647 * End Dependent Functions Resource
650 structure_size
= RESOURCE_LENGTH
;
654 case IO_PORT_DESCRIPTOR
:
659 structure_size
= sizeof (IO_RESOURCE
) +
660 RESOURCE_LENGTH_NO_DATA
;
664 case FIXED_LOCATION_IO_DESCRIPTOR
:
667 * Fixed IO Port Resource
670 structure_size
= sizeof (FIXED_IO_RESOURCE
) +
671 RESOURCE_LENGTH_NO_DATA
;
675 case SMALL_VENDOR_DEFINED
:
678 * Vendor Specific Resource
680 buffer
= byte_stream_buffer
;
683 temp8
= (u8
) (temp8
& 0x7);
684 bytes_consumed
= temp8
+ 1;
687 * Ensure a 32-bit boundry for the structure
689 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
690 structure_size
= sizeof (VENDOR_RESOURCE
) +
691 RESOURCE_LENGTH_NO_DATA
+
692 (temp8
* sizeof (u8
));
702 structure_size
= RESOURCE_LENGTH
;
703 byte_stream_buffer_length
= bytes_parsed
;
709 * If we get here, everything is out of sync,
710 * so exit with an error
712 return (AE_AML_ERROR
);
717 } /* if(Resource_type & 0x80) */
720 * Update the return value and counter
722 buffer_size
+= structure_size
;
723 bytes_parsed
+= bytes_consumed
;
726 * Set the byte stream to point to the next resource
728 byte_stream_buffer
+= bytes_consumed
;
733 * This is the data the caller needs
735 *size_needed
= buffer_size
;
741 /*******************************************************************************
743 * FUNCTION: Acpi_rs_calculate_pci_routing_table_length
745 * PARAMETERS: Package_object - Pointer to the package object
746 * Buffer_size_needed - u32 pointer of the size buffer
747 * needed to properly return the
750 * RETURN: Status AE_OK
752 * DESCRIPTION: Given a package representing a PCI routing table, this
753 * calculates the size of the corresponding linked list of
756 ******************************************************************************/
759 acpi_rs_calculate_pci_routing_table_length (
760 ACPI_OPERAND_OBJECT
*package_object
,
761 u32
*buffer_size_needed
)
763 u32 number_of_elements
;
764 u32 temp_size_needed
= 0;
765 ACPI_OPERAND_OBJECT
**top_object_list
;
767 ACPI_OPERAND_OBJECT
*package_element
;
768 ACPI_OPERAND_OBJECT
**sub_object_list
;
773 number_of_elements
= package_object
->package
.count
;
776 * Calculate the size of the return buffer.
777 * The base size is the number of elements * the sizes of the
778 * structures. Additional space for the strings is added below.
779 * The minus one is to subtract the size of the u8 Source[1]
780 * member because it is added below.
784 * But each PRT_ENTRY structure has a pointer to a string and
785 * the size of that string must be found.
787 top_object_list
= package_object
->package
.elements
;
789 for (index
= 0; index
< number_of_elements
; index
++) {
791 * Dereference the sub-package
793 package_element
= *top_object_list
;
796 * The Sub_object_list will now point to an array of the
797 * four IRQ elements: Address, Pin, Source and Source_index
799 sub_object_list
= package_element
->package
.elements
;
802 * Scan the Irq_table_elements for the Source Name String
806 for (table_index
= 0; table_index
< 4 && !name_found
; table_index
++) {
807 if ((ACPI_TYPE_STRING
== (*sub_object_list
)->common
.type
) ||
808 ((INTERNAL_TYPE_REFERENCE
== (*sub_object_list
)->common
.type
) &&
809 ((*sub_object_list
)->reference
.opcode
== AML_NAMEPATH_OP
))) {
815 * Look at the next element
821 temp_size_needed
+= (sizeof (PCI_ROUTING_TABLE
) - 4);
824 * Was a String type found?
826 if (TRUE
== name_found
) {
827 if (ACPI_TYPE_STRING
== (*sub_object_list
)->common
.type
) {
829 * The length String.Length field includes the
832 temp_size_needed
+= (*sub_object_list
)->string
.length
;
835 temp_size_needed
+= acpi_ns_get_pathname_length ((*sub_object_list
)->reference
.node
);
841 * If no name was found, then this is a NULL, which is
842 * translated as a u32 zero.
844 temp_size_needed
+= sizeof(u32
);
848 /* Round up the size since each element must be aligned */
850 temp_size_needed
= ROUND_UP_TO_64_bITS (temp_size_needed
);
853 * Point to the next ACPI_OPERAND_OBJECT
860 * Adding an extra element to the end of the list, essentially a NULL terminator
862 *buffer_size_needed
= temp_size_needed
+ sizeof (PCI_ROUTING_TABLE
);