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
33 #define _COMPONENT ACPI_RESOURCES
34 MODULE_NAME ("rscalc")
37 /*******************************************************************************
39 * FUNCTION: Acpi_rs_calculate_byte_stream_length
41 * PARAMETERS: Linked_list - Pointer to the resource linked list
42 * Size_needed - u32 pointer of the size buffer needed
43 * to properly return the parsed data
45 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
47 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
48 * the size buffer needed to hold the linked list that conveys
51 ******************************************************************************/
54 acpi_rs_calculate_byte_stream_length (
55 RESOURCE
*linked_list
,
58 u32 byte_stream_size_needed
= 0;
60 EXTENDED_IRQ_RESOURCE
*ex_irq
= NULL
;
67 * Init the variable that will hold the size to add to the
72 switch (linked_list
->id
) {
78 * For an IRQ Resource, Byte 3, although optional, will
79 * always be created - it holds IRQ information.
89 * For this resource the size is static
94 case start_dependent_functions
:
96 * Start Dependent Functions Resource
99 * For a Start_dependent_functions Resource, Byte 1,
100 * although optional, will always be created.
105 case end_dependent_functions
:
107 * End Dependent Functions Resource
110 * For this resource the size is static
120 * For this resource the size is static
127 * Fixed IO Port Resource
130 * For this resource the size is static
135 case vendor_specific
:
137 * Vendor Defined Resource
140 * For a Vendor Specific resource, if the Length is
141 * between 1 and 7 it will be created as a Small
142 * Resource data type, otherwise it is a Large
143 * Resource data type.
145 if(linked_list
->data
.vendor_specific
.length
> 7) {
152 linked_list
->data
.vendor_specific
.length
;
160 * For this resource the size is static
168 * 24-Bit Memory Resource
171 * For this resource the size is static
178 * 32-Bit Memory Range Resource
181 * For this resource the size is static
188 * 32-Bit Fixed Memory Resource
191 * For this resource the size is static
198 * 16-Bit Address Resource
201 * The base size of this byte stream is 16. If a
202 * Resource Source string is not NULL, add 1 for
203 * the Index + the length of the null terminated
204 * string Resource Source + 1 for the null.
208 if(NULL
!= linked_list
->data
.address16
.resource_source
) {
210 linked_list
->data
.address16
.resource_source_string_length
);
216 * 32-Bit Address Resource
219 * The base size of this byte stream is 26. If a Resource
220 * Source string is not NULL, add 1 for the Index + the
221 * length of the null terminated string Resource Source +
226 if(NULL
!= linked_list
->data
.address16
.resource_source
) {
228 linked_list
->data
.address16
.resource_source_string_length
);
234 * Extended IRQ Resource
237 * The base size of this byte stream is 9. This is for an
238 * Interrupt table length of 1. For each additional
240 * If a Resource Source string is not NULL, add 1 for the
241 * Index + the length of the null terminated string
242 * Resource Source + 1 for the null.
247 (linked_list
->data
.extended_irq
.number_of_interrupts
-
250 if(NULL
!= ex_irq
->resource_source
) {
252 linked_list
->data
.extended_irq
.resource_source_string_length
);
258 * If we get here, everything is out of sync,
259 * so exit with an error
261 return (AE_AML_ERROR
);
264 } /* switch (Linked_list->Id) */
269 byte_stream_size_needed
+= segment_size
;
272 * Point to the next object
274 linked_list
= (RESOURCE
*) ((NATIVE_UINT
) linked_list
+
275 (NATIVE_UINT
) linked_list
->length
);
279 * This is the data the caller needs
281 *size_needed
= byte_stream_size_needed
;
287 /*******************************************************************************
289 * FUNCTION: Acpi_rs_calculate_list_length
291 * PARAMETERS: Byte_stream_buffer - Pointer to the resource byte stream
292 * Byte_stream_buffer_length - Size of Byte_stream_buffer
293 * Size_needed - u32 pointer of the size buffer
294 * needed to properly return the
297 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
299 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
300 * the size buffer needed to hold the linked list that conveys
303 ******************************************************************************/
306 acpi_rs_calculate_list_length (
307 u8
*byte_stream_buffer
,
308 u32 byte_stream_buffer_length
,
312 u32 bytes_parsed
= 0;
313 u8 number_of_interrupts
= 0;
314 u8 number_of_channels
= 0;
325 while (bytes_parsed
< byte_stream_buffer_length
) {
327 * Look at the next byte in the stream
329 resource_type
= *byte_stream_buffer
;
332 * See if this is a small or large resource
334 if(resource_type
& 0x80) {
336 * Large Resource Type
338 switch (resource_type
) {
339 case MEMORY_RANGE_24
:
341 * 24-Bit Memory Resource
345 structure_size
= sizeof (MEMORY24_RESOURCE
) +
346 RESOURCE_LENGTH_NO_DATA
;
349 case LARGE_VENDOR_DEFINED
:
351 * Vendor Defined Resource
353 buffer
= byte_stream_buffer
;
356 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
357 bytes_consumed
= temp16
+ 3;
360 * Ensure a 32-bit boundary for the structure
362 temp16
= (u16
) ROUND_UP_TO_32_bITS (temp16
);
364 structure_size
= sizeof (VENDOR_RESOURCE
) +
365 RESOURCE_LENGTH_NO_DATA
+
366 (temp16
* sizeof (u8
));
369 case MEMORY_RANGE_32
:
371 * 32-Bit Memory Range Resource
376 structure_size
= sizeof (MEMORY32_RESOURCE
) +
377 RESOURCE_LENGTH_NO_DATA
;
380 case FIXED_MEMORY_RANGE_32
:
382 * 32-Bit Fixed Memory Resource
386 structure_size
= sizeof(FIXED_MEMORY32_RESOURCE
) +
387 RESOURCE_LENGTH_NO_DATA
;
390 case DWORD_ADDRESS_SPACE
:
392 * 32-Bit Address Resource
394 buffer
= byte_stream_buffer
;
397 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
399 bytes_consumed
= temp16
+ 3;
402 * Resource Source Index and Resource Source are
403 * optional elements. Check the length of the
404 * Bytestream. If it is greater than 23, that
405 * means that an Index exists and is followed by
406 * a null termininated string. Therefore, set
407 * the temp variable to the length minus the minimum
408 * byte stream length plus the byte for the Index to
409 * determine the size of the NULL terminiated string.
412 temp8
= (u8
) (temp16
- 24);
419 * Ensure a 32-bit boundary for the structure
421 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
423 structure_size
= sizeof (ADDRESS32_RESOURCE
) +
424 RESOURCE_LENGTH_NO_DATA
+
425 (temp8
* sizeof (u8
));
428 case WORD_ADDRESS_SPACE
:
430 * 16-Bit Address Resource
432 buffer
= byte_stream_buffer
;
435 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
437 bytes_consumed
= temp16
+ 3;
440 * Resource Source Index and Resource Source are
441 * optional elements. Check the length of the
442 * Bytestream. If it is greater than 13, that
443 * means that an Index exists and is followed by
444 * a null termininated string. Therefore, set
445 * the temp variable to the length minus the minimum
446 * byte stream length plus the byte for the Index to
447 * determine the size of the NULL terminiated string.
450 temp8
= (u8
) (temp16
- 14);
457 * Ensure a 32-bit boundry for the structure
459 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
461 structure_size
= sizeof (ADDRESS16_RESOURCE
) +
462 RESOURCE_LENGTH_NO_DATA
+
463 (temp8
* sizeof (u8
));
470 buffer
= byte_stream_buffer
;
473 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
475 bytes_consumed
= temp16
+ 3;
478 * Point past the length field and the
479 * Interrupt vector flags to save off the
480 * Interrupt table length to the Temp8 variable.
486 * To compensate for multiple interrupt numbers,
487 * Add 4 bytes for each additional interrupts
490 additional_bytes
= (u8
) ((temp8
- 1) * 4);
493 * Resource Source Index and Resource Source are
494 * optional elements. Check the length of the
495 * Bytestream. If it is greater than 9, that
496 * means that an Index exists and is followed by
497 * a null termininated string. Therefore, set
498 * the temp variable to the length minus the minimum
499 * byte stream length plus the byte for the Index to
500 * determine the size of the NULL terminiated string.
502 if (9 + additional_bytes
< temp16
) {
503 temp8
= (u8
) (temp16
- (9 + additional_bytes
));
511 * Ensure a 32-bit boundry for the structure
513 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
515 structure_size
= sizeof (EXTENDED_IRQ_RESOURCE
) +
516 RESOURCE_LENGTH_NO_DATA
+
517 (additional_bytes
* sizeof (u8
)) +
518 (temp8
* sizeof (u8
));
522 /* TBD: [Future] 64-bit not currently supported */
530 * If we get here, everything is out of sync,
531 * so exit with an error
533 return (AE_AML_ERROR
);
540 * Small Resource Type
541 * Only bits 7:3 are valid
545 switch (resource_type
) {
551 * Determine if it there are two or three
554 buffer
= byte_stream_buffer
;
566 * Point past the descriptor
571 * Look at the number of bits set
573 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
575 for (index
= 0; index
< 16; index
++) {
577 ++number_of_interrupts
;
583 structure_size
= sizeof (IO_RESOURCE
) +
584 RESOURCE_LENGTH_NO_DATA
+
585 (number_of_interrupts
* sizeof (u32
));
594 buffer
= byte_stream_buffer
;
599 * Point past the descriptor
604 * Look at the number of bits set
608 for(index
= 0; index
< 8; index
++) {
610 ++number_of_channels
;
616 structure_size
= sizeof (DMA_RESOURCE
) +
617 RESOURCE_LENGTH_NO_DATA
+
618 (number_of_channels
* sizeof (u32
));
622 case START_DEPENDENT_TAG
:
625 * Start Dependent Functions Resource
628 * Determine if it there are two or three trailing bytes
630 buffer
= byte_stream_buffer
;
642 sizeof (START_DEPENDENT_FUNCTIONS_RESOURCE
) +
643 RESOURCE_LENGTH_NO_DATA
;
647 case END_DEPENDENT_TAG
:
650 * End Dependent Functions Resource
653 structure_size
= RESOURCE_LENGTH
;
657 case IO_PORT_DESCRIPTOR
:
662 structure_size
= sizeof (IO_RESOURCE
) +
663 RESOURCE_LENGTH_NO_DATA
;
667 case FIXED_LOCATION_IO_DESCRIPTOR
:
670 * Fixed IO Port Resource
673 structure_size
= sizeof (FIXED_IO_RESOURCE
) +
674 RESOURCE_LENGTH_NO_DATA
;
678 case SMALL_VENDOR_DEFINED
:
681 * Vendor Specific Resource
683 buffer
= byte_stream_buffer
;
686 temp8
= (u8
) (temp8
& 0x7);
687 bytes_consumed
= temp8
+ 1;
690 * Ensure a 32-bit boundry for the structure
692 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
693 structure_size
= sizeof (VENDOR_RESOURCE
) +
694 RESOURCE_LENGTH_NO_DATA
+
695 (temp8
* sizeof (u8
));
705 structure_size
= RESOURCE_LENGTH
;
706 byte_stream_buffer_length
= bytes_parsed
;
712 * If we get here, everything is out of sync,
713 * so exit with an error
715 return (AE_AML_ERROR
);
720 } /* if(Resource_type & 0x80) */
723 * Update the return value and counter
725 buffer_size
+= structure_size
;
726 bytes_parsed
+= bytes_consumed
;
729 * Set the byte stream to point to the next resource
731 byte_stream_buffer
+= bytes_consumed
;
736 * This is the data the caller needs
738 *size_needed
= buffer_size
;
744 /*******************************************************************************
746 * FUNCTION: Acpi_rs_calculate_pci_routing_table_length
748 * PARAMETERS: Package_object - Pointer to the package object
749 * Buffer_size_needed - u32 pointer of the size buffer
750 * needed to properly return the
753 * RETURN: Status AE_OK
755 * DESCRIPTION: Given a package representing a PCI routing table, this
756 * calculates the size of the corresponding linked list of
759 ******************************************************************************/
762 acpi_rs_calculate_pci_routing_table_length (
763 ACPI_OPERAND_OBJECT
*package_object
,
764 u32
*buffer_size_needed
)
766 u32 number_of_elements
;
767 u32 temp_size_needed
= 0;
768 ACPI_OPERAND_OBJECT
**top_object_list
;
770 ACPI_OPERAND_OBJECT
*package_element
;
771 ACPI_OPERAND_OBJECT
**sub_object_list
;
776 number_of_elements
= package_object
->package
.count
;
779 * Calculate the size of the return buffer.
780 * The base size is the number of elements * the sizes of the
781 * structures. Additional space for the strings is added below.
782 * The minus one is to subtract the size of the u8 Source[1]
783 * member because it is added below.
787 * But each PRT_ENTRY structure has a pointer to a string and
788 * the size of that string must be found.
790 top_object_list
= package_object
->package
.elements
;
792 for (index
= 0; index
< number_of_elements
; index
++) {
794 * Dereference the sub-package
796 package_element
= *top_object_list
;
799 * The Sub_object_list will now point to an array of the
800 * four IRQ elements: Address, Pin, Source and Source_index
802 sub_object_list
= package_element
->package
.elements
;
805 * Scan the Irq_table_elements for the Source Name String
809 for (table_index
= 0; table_index
< 4 && !name_found
; table_index
++) {
810 if ((ACPI_TYPE_STRING
== (*sub_object_list
)->common
.type
) ||
811 ((INTERNAL_TYPE_REFERENCE
== (*sub_object_list
)->common
.type
) &&
812 ((*sub_object_list
)->reference
.opcode
== AML_NAMEPATH_OP
))) {
818 * Look at the next element
824 temp_size_needed
+= (sizeof (PCI_ROUTING_TABLE
) - 4);
827 * Was a String type found?
829 if (TRUE
== name_found
) {
830 if (ACPI_TYPE_STRING
== (*sub_object_list
)->common
.type
) {
832 * The length String.Length field includes the
835 temp_size_needed
+= (*sub_object_list
)->string
.length
;
838 temp_size_needed
+= acpi_ns_get_pathname_length ((*sub_object_list
)->reference
.node
);
844 * If no name was found, then this is a NULL, which is
845 * translated as a u32 zero.
847 temp_size_needed
+= sizeof(u32
);
851 /* Round up the size since each element must be aligned */
853 temp_size_needed
= ROUND_UP_TO_64_bITS (temp_size_needed
);
856 * Point to the next ACPI_OPERAND_OBJECT
863 * Adding an extra element to the end of the list, essentially a NULL terminator
865 *buffer_size_needed
= temp_size_needed
+ sizeof (PCI_ROUTING_TABLE
);