blob: 223bdc4932690bd39d020223cfdd2a84af54df13 [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/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Robert Moorebda663d2005-09-16 16:51:15 -040052/* Local prototypes */
Robert Moorebda663d2005-09-16 16:51:15 -040053static u8 acpi_rs_count_set_bits(u16 bit_field);
54
Bob Moore08978312005-10-21 00:00:00 -040055static acpi_rs_length
Robert Moorebda663d2005-09-16 16:51:15 -040056acpi_rs_struct_option_length(struct acpi_resource_source *resource_source);
57
58static u32
59acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length);
60
61/*******************************************************************************
62 *
63 * FUNCTION: acpi_rs_count_set_bits
64 *
65 * PARAMETERS: bit_field - Field in which to count bits
66 *
67 * RETURN: Number of bits set within the field
68 *
69 * DESCRIPTION: Count the number of bits set in a resource field. Used for
70 * (Short descriptor) interrupt and DMA lists.
71 *
72 ******************************************************************************/
73
74static u8 acpi_rs_count_set_bits(u16 bit_field)
75{
76 u8 bits_set;
77
78 ACPI_FUNCTION_ENTRY();
79
80 for (bits_set = 0; bit_field; bits_set++) {
Bob Moore52fc0b02006-10-02 00:00:00 -040081
Robert Moorebda663d2005-09-16 16:51:15 -040082 /* Zero the least significant bit that is set */
83
84 bit_field &= (bit_field - 1);
85 }
86
87 return (bits_set);
88}
89
90/*******************************************************************************
91 *
Robert Moorebda663d2005-09-16 16:51:15 -040092 * FUNCTION: acpi_rs_struct_option_length
93 *
94 * PARAMETERS: resource_source - Pointer to optional descriptor field
95 *
96 * RETURN: Status
97 *
98 * DESCRIPTION: Common code to handle optional resource_source_index and
99 * resource_source fields in some Large descriptors. Used during
100 * list-to-stream conversion
101 *
102 ******************************************************************************/
103
Bob Moore08978312005-10-21 00:00:00 -0400104static acpi_rs_length
Robert Moorebda663d2005-09-16 16:51:15 -0400105acpi_rs_struct_option_length(struct acpi_resource_source *resource_source)
106{
107 ACPI_FUNCTION_ENTRY();
108
109 /*
110 * If the resource_source string is valid, return the size of the string
111 * (string_length includes the NULL terminator) plus the size of the
112 * resource_source_index (1).
113 */
114 if (resource_source->string_ptr) {
Bob Moore08978312005-10-21 00:00:00 -0400115 return ((acpi_rs_length) (resource_source->string_length + 1));
Robert Moorebda663d2005-09-16 16:51:15 -0400116 }
117
118 return (0);
119}
120
121/*******************************************************************************
122 *
123 * FUNCTION: acpi_rs_stream_option_length
124 *
125 * PARAMETERS: resource_length - Length from the resource header
126 * minimum_total_length - Minimum length of this resource, before
127 * any optional fields. Includes header size
128 *
129 * RETURN: Length of optional string (0 if no string present)
130 *
131 * DESCRIPTION: Common code to handle optional resource_source_index and
132 * resource_source fields in some Large descriptors. Used during
133 * stream-to-list conversion
134 *
135 ******************************************************************************/
136
137static u32
Bob Moore50eca3e2005-09-30 19:03:00 -0400138acpi_rs_stream_option_length(u32 resource_length,
139 u32 minimum_aml_resource_length)
Robert Moorebda663d2005-09-16 16:51:15 -0400140{
141 u32 string_length = 0;
Robert Moorebda663d2005-09-16 16:51:15 -0400142
143 ACPI_FUNCTION_ENTRY();
144
145 /*
146 * The resource_source_index and resource_source are optional elements of some
147 * Large-type resource descriptors.
148 */
149
Robert Moorebda663d2005-09-16 16:51:15 -0400150 /*
151 * If the length of the actual resource descriptor is greater than the ACPI
152 * spec-defined minimum length, it means that a resource_source_index exists
153 * and is followed by a (required) null terminated string. The string length
154 * (including the null terminator) is the resource length minus the minimum
155 * length, minus one byte for the resource_source_index itself.
156 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400157 if (resource_length > minimum_aml_resource_length) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400158
Robert Moorebda663d2005-09-16 16:51:15 -0400159 /* Compute the length of the optional string */
160
Bob Moore50eca3e2005-09-30 19:03:00 -0400161 string_length =
162 resource_length - minimum_aml_resource_length - 1;
Robert Moorebda663d2005-09-16 16:51:15 -0400163 }
164
165 /* Round up length to 32 bits for internal structure alignment */
166
Bob Moore52fc0b02006-10-02 00:00:00 -0400167 return ((u32) ACPI_ROUND_UP_to_32_bITS(string_length));
Robert Moorebda663d2005-09-16 16:51:15 -0400168}
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/*******************************************************************************
171 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400172 * FUNCTION: acpi_rs_get_aml_length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 *
Robert Moorebda663d2005-09-16 16:51:15 -0400174 * PARAMETERS: Resource - Pointer to the resource linked list
175 * size_needed - Where the required size is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 *
177 * RETURN: Status
178 *
Robert Moorebda663d2005-09-16 16:51:15 -0400179 * DESCRIPTION: Takes a linked list of internal resource descriptors and
180 * calculates the size buffer needed to hold the corresponding
181 * external resource byte stream.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 *
183 ******************************************************************************/
Robert Moorebda663d2005-09-16 16:51:15 -0400184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400186acpi_rs_get_aml_length(struct acpi_resource * resource, acpi_size * size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Bob Moore50eca3e2005-09-30 19:03:00 -0400188 acpi_size aml_size_needed = 0;
Bob Moore08978312005-10-21 00:00:00 -0400189 acpi_rs_length total_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Moore50eca3e2005-09-30 19:03:00 -0400191 ACPI_FUNCTION_TRACE("rs_get_aml_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Robert Moorebda663d2005-09-16 16:51:15 -0400193 /* Traverse entire list of internal resource descriptors */
Robert Moore44f6c012005-04-18 22:49:35 -0400194
Robert Moorebda663d2005-09-16 16:51:15 -0400195 while (resource) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400196
Robert Moorebda663d2005-09-16 16:51:15 -0400197 /* Validate the descriptor type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Bob Moore50eca3e2005-09-30 19:03:00 -0400199 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
Robert Moorebda663d2005-09-16 16:51:15 -0400200 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Robert Moorebda663d2005-09-16 16:51:15 -0400203 /* Get the base size of the (external stream) resource descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Bob Moore08978312005-10-21 00:00:00 -0400205 total_size = acpi_gbl_aml_resource_sizes[resource->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Robert Moorebda663d2005-09-16 16:51:15 -0400207 /*
208 * Augment the base size for descriptors with optional and/or
209 * variable-length fields
210 */
211 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400212 case ACPI_RESOURCE_TYPE_VENDOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400214 * Vendor Defined Resource:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 * For a Vendor Specific resource, if the Length is between 1 and 7
216 * it will be created as a Small Resource data type, otherwise it
217 * is a Large Resource data type.
218 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400219 if (resource->data.vendor.byte_length > 7) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400220
Robert Moorebda663d2005-09-16 16:51:15 -0400221 /* Base size of a Large resource descriptor */
222
Bob Moore08978312005-10-21 00:00:00 -0400223 total_size =
Bob Moore50eca3e2005-09-30 19:03:00 -0400224 sizeof(struct aml_resource_large_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
Robert Moorebda663d2005-09-16 16:51:15 -0400226
227 /* Add the size of the vendor-specific data */
228
Bob Moore08978312005-10-21 00:00:00 -0400229 total_size = (acpi_rs_length)
230 (total_size + resource->data.vendor.byte_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 break;
232
Bob Moore50eca3e2005-09-30 19:03:00 -0400233 case ACPI_RESOURCE_TYPE_END_TAG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400235 * End Tag:
236 * We are done -- return the accumulated total size.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 */
Bob Moore08978312005-10-21 00:00:00 -0400238 *size_needed = aml_size_needed + total_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Robert Moorebda663d2005-09-16 16:51:15 -0400240 /* Normal exit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Robert Moorebda663d2005-09-16 16:51:15 -0400242 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Bob Moore50eca3e2005-09-30 19:03:00 -0400244 case ACPI_RESOURCE_TYPE_ADDRESS16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400246 * 16-Bit Address Resource:
247 * Add the size of the optional resource_source info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 */
Bob Moore08978312005-10-21 00:00:00 -0400249 total_size = (acpi_rs_length)
250 (total_size +
251 acpi_rs_struct_option_length(&resource->data.
252 address16.
253 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 break;
255
Bob Moore50eca3e2005-09-30 19:03:00 -0400256 case ACPI_RESOURCE_TYPE_ADDRESS32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400258 * 32-Bit Address Resource:
259 * Add the size of the optional resource_source info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 */
Bob Moore08978312005-10-21 00:00:00 -0400261 total_size = (acpi_rs_length)
262 (total_size +
263 acpi_rs_struct_option_length(&resource->data.
264 address32.
265 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
267
Bob Moore50eca3e2005-09-30 19:03:00 -0400268 case ACPI_RESOURCE_TYPE_ADDRESS64:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400270 * 64-Bit Address Resource:
271 * Add the size of the optional resource_source info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 */
Bob Moore08978312005-10-21 00:00:00 -0400273 total_size = (acpi_rs_length)
274 (total_size +
275 acpi_rs_struct_option_length(&resource->data.
276 address64.
277 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 break;
279
Bob Moore50eca3e2005-09-30 19:03:00 -0400280 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400282 * Extended IRQ Resource:
283 * Add the size of each additional optional interrupt beyond the
284 * required 1 (4 bytes for each u32 interrupt number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 */
Bob Moore08978312005-10-21 00:00:00 -0400286 total_size = (acpi_rs_length)
287 (total_size +
288 ((resource->data.extended_irq.interrupt_count -
289 1) * 4) +
290 /* Add the size of the optional resource_source info */
291 acpi_rs_struct_option_length(&resource->data.
292 extended_irq.
293 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 break;
295
296 default:
Robert Moorebda663d2005-09-16 16:51:15 -0400297 break;
298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Robert Moore44f6c012005-04-18 22:49:35 -0400300 /* Update the total */
301
Bob Moore08978312005-10-21 00:00:00 -0400302 aml_size_needed += total_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Robert Moore44f6c012005-04-18 22:49:35 -0400304 /* Point to the next object */
305
Bob Moore96db2552005-11-02 00:00:00 -0500306 resource =
Bob Moorec51a4de2005-11-17 13:07:00 -0500307 ACPI_ADD_PTR(struct acpi_resource, resource,
Bob Moore96db2552005-11-02 00:00:00 -0500308 resource->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310
Bob Moore96db2552005-11-02 00:00:00 -0500311 /* Did not find an end_tag resource descriptor */
Robert Moore44f6c012005-04-18 22:49:35 -0400312
Bob Moore96db2552005-11-02 00:00:00 -0500313 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316/*******************************************************************************
317 *
318 * FUNCTION: acpi_rs_get_list_length
319 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400320 * PARAMETERS: aml_buffer - Pointer to the resource byte stream
321 * aml_buffer_length - Size of aml_buffer
322 * size_needed - Where the size needed is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 *
324 * RETURN: Status
325 *
Robert Moorebda663d2005-09-16 16:51:15 -0400326 * DESCRIPTION: Takes an external resource byte stream and calculates the size
327 * buffer needed to hold the corresponding internal resource
328 * descriptor linked list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 *
330 ******************************************************************************/
331
332acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400333acpi_rs_get_list_length(u8 * aml_buffer,
334 u32 aml_buffer_length, acpi_size * size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Bob Moore96db2552005-11-02 00:00:00 -0500336 acpi_status status;
337 u8 *end_aml;
Robert Moorebda663d2005-09-16 16:51:15 -0400338 u8 *buffer;
Len Brown4be44fc2005-08-05 00:44:28 -0400339 u32 buffer_size = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400340 u16 temp16;
Robert Moorebda663d2005-09-16 16:51:15 -0400341 u16 resource_length;
Robert Moorebda663d2005-09-16 16:51:15 -0400342 u32 extra_struct_bytes;
Bob Moore96db2552005-11-02 00:00:00 -0500343 u8 resource_index;
344 u8 minimum_aml_resource_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Len Brown4be44fc2005-08-05 00:44:28 -0400346 ACPI_FUNCTION_TRACE("rs_get_list_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Bob Moore96db2552005-11-02 00:00:00 -0500348 end_aml = aml_buffer + aml_buffer_length;
Robert Moore44f6c012005-04-18 22:49:35 -0400349
Bob Moore96db2552005-11-02 00:00:00 -0500350 /* Walk the list of AML resource descriptors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Bob Moore96db2552005-11-02 00:00:00 -0500352 while (aml_buffer < end_aml) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400353
Bob Moore96db2552005-11-02 00:00:00 -0500354 /* Validate the Resource Type and Resource Length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Bob Moore96db2552005-11-02 00:00:00 -0500356 status = acpi_ut_validate_resource(aml_buffer, &resource_index);
357 if (ACPI_FAILURE(status)) {
358 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360
Bob Moore96db2552005-11-02 00:00:00 -0500361 /* Get the resource length and base (minimum) AML size */
Robert Moore44f6c012005-04-18 22:49:35 -0400362
Bob Moore08978312005-10-21 00:00:00 -0400363 resource_length = acpi_ut_get_resource_length(aml_buffer);
Bob Moore96db2552005-11-02 00:00:00 -0500364 minimum_aml_resource_length =
365 acpi_gbl_resource_aml_sizes[resource_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Bob Moore96db2552005-11-02 00:00:00 -0500367 /*
368 * Augment the size for descriptors with optional
369 * and/or variable length fields
370 */
Robert Moorebda663d2005-09-16 16:51:15 -0400371 extra_struct_bytes = 0;
Bob Moore96db2552005-11-02 00:00:00 -0500372 buffer =
373 aml_buffer + acpi_ut_get_resource_header_length(aml_buffer);
Robert Moorebda663d2005-09-16 16:51:15 -0400374
Bob Moore96db2552005-11-02 00:00:00 -0500375 switch (acpi_ut_get_resource_type(aml_buffer)) {
376 case ACPI_RESOURCE_NAME_IRQ:
Robert Moorebda663d2005-09-16 16:51:15 -0400377 /*
Bob Moore96db2552005-11-02 00:00:00 -0500378 * IRQ Resource:
379 * Get the number of bits set in the 16-bit IRQ mask
Robert Moorebda663d2005-09-16 16:51:15 -0400380 */
Bob Moore96db2552005-11-02 00:00:00 -0500381 ACPI_MOVE_16_TO_16(&temp16, buffer);
Bob Moorec51a4de2005-11-17 13:07:00 -0500382 extra_struct_bytes = acpi_rs_count_set_bits(temp16);
Bob Moore96db2552005-11-02 00:00:00 -0500383 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400384
Bob Moore96db2552005-11-02 00:00:00 -0500385 case ACPI_RESOURCE_NAME_DMA:
Robert Moorebda663d2005-09-16 16:51:15 -0400386 /*
Bob Moore96db2552005-11-02 00:00:00 -0500387 * DMA Resource:
388 * Get the number of bits set in the 8-bit DMA mask
Robert Moorebda663d2005-09-16 16:51:15 -0400389 */
Bob Moorec51a4de2005-11-17 13:07:00 -0500390 extra_struct_bytes = acpi_rs_count_set_bits(*buffer);
Bob Moore96db2552005-11-02 00:00:00 -0500391 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400392
Bob Moore96db2552005-11-02 00:00:00 -0500393 case ACPI_RESOURCE_NAME_VENDOR_SMALL:
394 /*
395 * Vendor Resource:
396 * Ensure a 32-bit boundary for the structure
397 */
Bob Moore52fc0b02006-10-02 00:00:00 -0400398 extra_struct_bytes = (u32)
Len Brown46358612006-03-31 02:16:19 -0500399 ACPI_ROUND_UP_to_32_bITS(resource_length) -
400 resource_length;
Bob Moore96db2552005-11-02 00:00:00 -0500401 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400402
Bob Moore96db2552005-11-02 00:00:00 -0500403 case ACPI_RESOURCE_NAME_END_TAG:
404 /*
Bob Moorec51a4de2005-11-17 13:07:00 -0500405 * End Tag: This is the normal exit, add size of end_tag
Bob Moore96db2552005-11-02 00:00:00 -0500406 */
Bob Moorec51a4de2005-11-17 13:07:00 -0500407 *size_needed = buffer_size + ACPI_RS_SIZE_MIN;
Bob Moore96db2552005-11-02 00:00:00 -0500408 return_ACPI_STATUS(AE_OK);
Robert Moorebda663d2005-09-16 16:51:15 -0400409
Bob Moore96db2552005-11-02 00:00:00 -0500410 case ACPI_RESOURCE_NAME_VENDOR_LARGE:
411 /*
412 * Vendor Resource:
413 * Add vendor data and ensure a 32-bit boundary for the structure
414 */
Bob Moore52fc0b02006-10-02 00:00:00 -0400415 extra_struct_bytes = (u32)
Len Brown46358612006-03-31 02:16:19 -0500416 ACPI_ROUND_UP_to_32_bITS(resource_length) -
417 resource_length;
Bob Moore96db2552005-11-02 00:00:00 -0500418 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400419
Bob Moore96db2552005-11-02 00:00:00 -0500420 case ACPI_RESOURCE_NAME_ADDRESS32:
421 case ACPI_RESOURCE_NAME_ADDRESS16:
422 /*
423 * 32-Bit or 16-bit Address Resource:
424 * Add the size of any optional data (resource_source)
425 */
426 extra_struct_bytes =
427 acpi_rs_stream_option_length(resource_length,
428 minimum_aml_resource_length);
429 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400430
Bob Moore96db2552005-11-02 00:00:00 -0500431 case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
432 /*
433 * Extended IRQ:
434 * Point past the interrupt_vector_flags to get the
435 * interrupt_table_length.
436 */
437 buffer++;
Robert Moorebda663d2005-09-16 16:51:15 -0400438
Bob Moore52fc0b02006-10-02 00:00:00 -0400439 extra_struct_bytes = (u32)
Bob Moore96db2552005-11-02 00:00:00 -0500440 /*
441 * Add 4 bytes for each additional interrupt. Note: at
442 * least one interrupt is required and is included in
443 * the minimum descriptor size
444 */
445 ((*buffer - 1) * sizeof(u32)) +
446 /* Add the size of any optional data (resource_source) */
447 acpi_rs_stream_option_length(resource_length -
448 extra_struct_bytes,
449 minimum_aml_resource_length);
450 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400451
Bob Moore96db2552005-11-02 00:00:00 -0500452 case ACPI_RESOURCE_NAME_ADDRESS64:
453 /*
454 * 64-Bit Address Resource:
455 * Add the size of any optional data (resource_source)
456 * Ensure a 64-bit boundary for the structure
457 */
Bob Moore52fc0b02006-10-02 00:00:00 -0400458 extra_struct_bytes = (u32)
Bob Moore96db2552005-11-02 00:00:00 -0500459 ACPI_ROUND_UP_to_64_bITS
460 (acpi_rs_stream_option_length
461 (resource_length, minimum_aml_resource_length));
462 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400463
Bob Moore96db2552005-11-02 00:00:00 -0500464 default:
465 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400466 }
467
468 /* Update the required buffer size for the internal descriptor structs */
469
Bob Moore96db2552005-11-02 00:00:00 -0500470 temp16 = (u16) (acpi_gbl_resource_struct_sizes[resource_index] +
471 extra_struct_bytes);
Bob Moorec51a4de2005-11-17 13:07:00 -0500472 buffer_size += (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(temp16);
Robert Moorebda663d2005-09-16 16:51:15 -0400473
474 /*
Bob Moore96db2552005-11-02 00:00:00 -0500475 * Point to the next resource within the stream
Robert Moorebda663d2005-09-16 16:51:15 -0400476 * using the size of the header plus the length contained in the header
477 */
Bob Moore96db2552005-11-02 00:00:00 -0500478 aml_buffer += acpi_ut_get_descriptor_length(aml_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480
Bob Moore96db2552005-11-02 00:00:00 -0500481 /* Did not find an end_tag resource descriptor */
Robert Moore44f6c012005-04-18 22:49:35 -0400482
Bob Moore96db2552005-11-02 00:00:00 -0500483 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486/*******************************************************************************
487 *
488 * FUNCTION: acpi_rs_get_pci_routing_table_length
489 *
490 * PARAMETERS: package_object - Pointer to the package object
491 * buffer_size_needed - u32 pointer of the size buffer
492 * needed to properly return the
493 * parsed data
494 *
495 * RETURN: Status
496 *
497 * DESCRIPTION: Given a package representing a PCI routing table, this
498 * calculates the size of the corresponding linked list of
499 * descriptions.
500 *
501 ******************************************************************************/
502
503acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400504acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
505 acpi_size * buffer_size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Len Brown4be44fc2005-08-05 00:44:28 -0400507 u32 number_of_elements;
508 acpi_size temp_size_needed = 0;
509 union acpi_operand_object **top_object_list;
510 u32 index;
511 union acpi_operand_object *package_element;
512 union acpi_operand_object **sub_object_list;
513 u8 name_found;
514 u32 table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 ACPI_FUNCTION_TRACE("rs_get_pci_routing_table_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 number_of_elements = package_object->package.count;
519
520 /*
521 * Calculate the size of the return buffer.
522 * The base size is the number of elements * the sizes of the
523 * structures. Additional space for the strings is added below.
524 * The minus one is to subtract the size of the u8 Source[1]
525 * member because it is added below.
526 *
527 * But each PRT_ENTRY structure has a pointer to a string and
528 * the size of that string must be found.
529 */
530 top_object_list = package_object->package.elements;
531
532 for (index = 0; index < number_of_elements; index++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400533
Robert Moore44f6c012005-04-18 22:49:35 -0400534 /* Dereference the sub-package */
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 package_element = *top_object_list;
537
538 /*
539 * The sub_object_list will now point to an array of the
540 * four IRQ elements: Address, Pin, Source and source_index
541 */
542 sub_object_list = package_element->package.elements;
543
Robert Moore44f6c012005-04-18 22:49:35 -0400544 /* Scan the irq_table_elements for the Source Name String */
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 name_found = FALSE;
547
Len Brown4be44fc2005-08-05 00:44:28 -0400548 for (table_index = 0; table_index < 4 && !name_found;
549 table_index++) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500550 if (*sub_object_list && /* Null object allowed */
551 ((ACPI_TYPE_STRING ==
552 ACPI_GET_OBJECT_TYPE(*sub_object_list)) ||
553 ((ACPI_TYPE_LOCAL_REFERENCE ==
554 ACPI_GET_OBJECT_TYPE(*sub_object_list)) &&
555 ((*sub_object_list)->reference.opcode ==
556 AML_INT_NAMEPATH_OP)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 name_found = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400558 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400559 /* Look at the next element */
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 sub_object_list++;
562 }
563 }
564
Len Brown4be44fc2005-08-05 00:44:28 -0400565 temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Robert Moore44f6c012005-04-18 22:49:35 -0400567 /* Was a String type found? */
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (name_found) {
Len Brown4be44fc2005-08-05 00:44:28 -0400570 if (ACPI_GET_OBJECT_TYPE(*sub_object_list) ==
571 ACPI_TYPE_STRING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 /*
573 * The length String.Length field does not include the
574 * terminating NULL, add 1
575 */
Robert Moore44f6c012005-04-18 22:49:35 -0400576 temp_size_needed += ((acpi_size)
Len Brown4be44fc2005-08-05 00:44:28 -0400577 (*sub_object_list)->string.
578 length + 1);
579 } else {
Bob Moore50eca3e2005-09-30 19:03:00 -0400580 temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
Len Brown4be44fc2005-08-05 00:44:28 -0400582 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 /*
584 * If no name was found, then this is a NULL, which is
585 * translated as a u32 zero.
586 */
Len Brown4be44fc2005-08-05 00:44:28 -0400587 temp_size_needed += sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
590 /* Round up the size since each element must be aligned */
591
Len Brown4be44fc2005-08-05 00:44:28 -0400592 temp_size_needed = ACPI_ROUND_UP_to_64_bITS(temp_size_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Robert Moore44f6c012005-04-18 22:49:35 -0400594 /* Point to the next union acpi_operand_object */
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 top_object_list++;
597 }
598
599 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400600 * Adding an extra element to the end of the list, essentially a
601 * NULL terminator
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 */
Len Brown4be44fc2005-08-05 00:44:28 -0400603 *buffer_size_needed =
604 temp_size_needed + sizeof(struct acpi_pci_routing_table);
605 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}