1 /*******************************************************************************
3 * Module Name: rscalc - Acpi_rs_calculate_byte_stream_length
4 * Acpi_rs_calculate_list_length
7 ******************************************************************************/
10 * Copyright (C) 2000 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
31 #define _COMPONENT RESOURCE_MANAGER
32 MODULE_NAME ("rscalc")
35 /*******************************************************************************
37 * FUNCTION: Acpi_rs_calculate_byte_stream_length
39 * PARAMETERS: Linked_list - Pointer to the resource linked list
40 * Size_needed - u32 pointer of the size buffer needed
41 * to properly return the parsed data
43 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
45 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
46 * the size buffer needed to hold the linked list that conveys
49 ******************************************************************************/
52 acpi_rs_calculate_byte_stream_length (
53 RESOURCE
*linked_list
,
56 u32 byte_stream_size_needed
= 0;
58 EXTENDED_IRQ_RESOURCE
*ex_irq
= NULL
;
65 * Init the variable that will hold the size to add to the
70 switch (linked_list
->id
)
77 * For an IRQ Resource, Byte 3, although optional, will
78 * always be created - it holds IRQ information.
88 * For this resource the size is static
93 case start_dependent_functions
:
95 * Start Dependent Functions Resource
98 * For a Start_dependent_functions Resource, Byte 1,
99 * although optional, will always be created.
104 case end_dependent_functions
:
106 * End Dependent Functions Resource
109 * For this resource the size is static
119 * For this resource the size is static
126 * Fixed IO Port Resource
129 * For this resource the size is static
134 case vendor_specific
:
136 * Vendor Defined Resource
139 * For a Vendor Specific resource, if the Length is
140 * between 1 and 7 it will be created as a Small
141 * Resource data type, otherwise it is a Large
142 * Resource data type.
144 if(linked_list
->data
.vendor_specific
.length
> 7) {
151 linked_list
->data
.vendor_specific
.length
;
159 * For this resource the size is static
167 * 24-Bit Memory Resource
170 * For this resource the size is static
177 * 32-Bit Memory Range Resource
180 * For this resource the size is static
187 * 32-Bit Fixed Memory Resource
190 * For this resource the size is static
197 * 16-Bit Address Resource
200 * The base size of this byte stream is 16. If a
201 * Resource Source string is not NULL, add 1 for
202 * the Index + the length of the null terminated
203 * string Resource Source + 1 for the null.
207 if(NULL
!= linked_list
->data
.address16
.resource_source
) {
209 linked_list
->data
.address16
.resource_source_string_length
);
215 * 32-Bit Address Resource
218 * The base size of this byte stream is 26. If a Resource
219 * Source string is not NULL, add 1 for the Index + the
220 * length of the null terminated string Resource Source +
225 if(NULL
!= linked_list
->data
.address16
.resource_source
) {
227 linked_list
->data
.address16
.resource_source_string_length
);
233 * Extended IRQ Resource
236 * The base size of this byte stream is 9. This is for an
237 * Interrupt table length of 1. For each additional
239 * If a Resource Source string is not NULL, add 1 for the
240 * Index + the length of the null terminated string
241 * Resource Source + 1 for the null.
246 (linked_list
->data
.extended_irq
.number_of_interrupts
-
249 if(NULL
!= ex_irq
->resource_source
) {
251 linked_list
->data
.extended_irq
.resource_source_string_length
);
257 * If we get here, everything is out of sync,
258 * so exit with an error
260 return (AE_AML_ERROR
);
263 } /* switch (Linked_list->Id) */
268 byte_stream_size_needed
+= segment_size
;
271 * Point to the next object
273 linked_list
= (RESOURCE
*) ((NATIVE_UINT
) linked_list
+
274 (NATIVE_UINT
) linked_list
->length
);
278 * This is the data the caller needs
280 *size_needed
= byte_stream_size_needed
;
286 /*******************************************************************************
288 * FUNCTION: Acpi_rs_calculate_list_length
290 * PARAMETERS: Byte_stream_buffer - Pointer to the resource byte stream
291 * Byte_stream_buffer_length - Size of Byte_stream_buffer
292 * Size_needed - u32 pointer of the size buffer
293 * needed to properly return the
296 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
298 * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
299 * the size buffer needed to hold the linked list that conveys
302 ******************************************************************************/
305 acpi_rs_calculate_list_length (
306 u8
*byte_stream_buffer
,
307 u32 byte_stream_buffer_length
,
311 u32 bytes_parsed
= 0;
312 u8 number_of_interrupts
= 0;
313 u8 number_of_channels
= 0;
324 while (bytes_parsed
< byte_stream_buffer_length
) {
326 * Look at the next byte in the stream
328 resource_type
= *byte_stream_buffer
;
331 * See if this is a small or large resource
333 if(resource_type
& 0x80) {
335 * Large Resource Type
337 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
)
552 * Determine if it there are two or three
555 buffer
= byte_stream_buffer
;
567 * Point past the descriptor
572 * Look at the number of bits set
574 MOVE_UNALIGNED16_TO_16 (&temp16
, buffer
);
576 for (index
= 0; index
< 16; index
++) {
578 ++number_of_interrupts
;
584 structure_size
= sizeof (IO_RESOURCE
) +
585 RESOURCE_LENGTH_NO_DATA
+
586 (number_of_interrupts
* sizeof (u32
));
595 buffer
= byte_stream_buffer
;
600 * Point past the descriptor
605 * Look at the number of bits set
609 for(index
= 0; index
< 8; index
++) {
611 ++number_of_channels
;
617 structure_size
= sizeof (DMA_RESOURCE
) +
618 RESOURCE_LENGTH_NO_DATA
+
619 (number_of_channels
* sizeof (u32
));
623 case START_DEPENDENT_TAG
:
626 * Start Dependent Functions Resource
629 * Determine if it there are two or three trailing bytes
631 buffer
= byte_stream_buffer
;
643 sizeof (START_DEPENDENT_FUNCTIONS_RESOURCE
) +
644 RESOURCE_LENGTH_NO_DATA
;
648 case END_DEPENDENT_TAG
:
651 * End Dependent Functions Resource
654 structure_size
= RESOURCE_LENGTH
;
658 case IO_PORT_DESCRIPTOR
:
663 structure_size
= sizeof (IO_RESOURCE
) +
664 RESOURCE_LENGTH_NO_DATA
;
668 case FIXED_LOCATION_IO_DESCRIPTOR
:
671 * Fixed IO Port Resource
674 structure_size
= sizeof (FIXED_IO_RESOURCE
) +
675 RESOURCE_LENGTH_NO_DATA
;
679 case SMALL_VENDOR_DEFINED
:
682 * Vendor Specific Resource
684 buffer
= byte_stream_buffer
;
687 temp8
= (u8
) (temp8
& 0x7);
688 bytes_consumed
= temp8
+ 1;
691 * Ensure a 32-bit boundry for the structure
693 temp8
= (u8
) ROUND_UP_TO_32_bITS (temp8
);
694 structure_size
= sizeof (VENDOR_RESOURCE
) +
695 RESOURCE_LENGTH_NO_DATA
+
696 (temp8
* sizeof (u8
));
706 structure_size
= RESOURCE_LENGTH
;
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.
785 * NOTE: The Number_of_elements is incremented by one to add an end
786 * table structure that is essentially a structure of zeros.
790 * But each PRT_ENTRY structure has a pointer to a string and
791 * the size of that string must be found.
793 top_object_list
= package_object
->package
.elements
;
795 for (index
= 0; index
< number_of_elements
; index
++) {
797 * Dereference the sub-package
799 package_element
= *top_object_list
;
802 * The Sub_object_list will now point to an array of the
803 * four IRQ elements: Address, Pin, Source and Source_index
805 sub_object_list
= package_element
->package
.elements
;
808 * Scan the Irq_table_elements for the Source Name String
812 for (table_index
= 0; table_index
< 4 && !name_found
; table_index
++) {
813 if (ACPI_TYPE_STRING
== (*sub_object_list
)->common
.type
) {
819 * Look at the next element
825 temp_size_needed
+= (sizeof (PCI_ROUTING_TABLE
) - 1);
828 * Was a String type found?
830 if (TRUE
== name_found
) {
832 * The length String.Length field includes the
835 temp_size_needed
+= (*sub_object_list
)->string
.length
;
840 * If no name was found, then this is a NULL, which is
841 * translated as a u32 zero.
843 temp_size_needed
+= sizeof(u32
);
847 /* Round up the size since each element must be aligned */
849 temp_size_needed
= ROUND_UP_TO_64_bITS (temp_size_needed
);
852 * Point to the next ACPI_OPERAND_OBJECT
858 *buffer_size_needed
= temp_size_needed
+ sizeof (PCI_ROUTING_TABLE
);