blob: 8eaaecf9200939ea4cb72b9a2f9842e4b80af5a7 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acnamesp.h>
47
48#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("rscalc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moorebda663d2005-09-16 16:51:15 -040051/* Local prototypes */
Robert Moorebda663d2005-09-16 16:51:15 -040052static u8 acpi_rs_count_set_bits(u16 bit_field);
53
Bob Moore08978312005-10-21 00:00:00 -040054static acpi_rs_length
Robert Moorebda663d2005-09-16 16:51:15 -040055acpi_rs_struct_option_length(struct acpi_resource_source *resource_source);
56
57static u32
58acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length);
59
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_rs_count_set_bits
63 *
64 * PARAMETERS: bit_field - Field in which to count bits
65 *
66 * RETURN: Number of bits set within the field
67 *
68 * DESCRIPTION: Count the number of bits set in a resource field. Used for
69 * (Short descriptor) interrupt and DMA lists.
70 *
71 ******************************************************************************/
72
73static u8 acpi_rs_count_set_bits(u16 bit_field)
74{
Bob Moore67a119f2008-06-10 13:42:13 +080075 u8 bits_set;
Robert Moorebda663d2005-09-16 16:51:15 -040076
77 ACPI_FUNCTION_ENTRY();
78
79 for (bits_set = 0; bit_field; bits_set++) {
Bob Moore52fc0b02006-10-02 00:00:00 -040080
Robert Moorebda663d2005-09-16 16:51:15 -040081 /* Zero the least significant bit that is set */
82
Bob Moore1d18c052008-04-10 19:06:40 +040083 bit_field &= (u16) (bit_field - 1);
Robert Moorebda663d2005-09-16 16:51:15 -040084 }
85
Bob Moore67a119f2008-06-10 13:42:13 +080086 return bits_set;
Robert Moorebda663d2005-09-16 16:51:15 -040087}
88
89/*******************************************************************************
90 *
Robert Moorebda663d2005-09-16 16:51:15 -040091 * FUNCTION: acpi_rs_struct_option_length
92 *
93 * PARAMETERS: resource_source - Pointer to optional descriptor field
94 *
95 * RETURN: Status
96 *
97 * DESCRIPTION: Common code to handle optional resource_source_index and
98 * resource_source fields in some Large descriptors. Used during
99 * list-to-stream conversion
100 *
101 ******************************************************************************/
102
Bob Moore08978312005-10-21 00:00:00 -0400103static acpi_rs_length
Robert Moorebda663d2005-09-16 16:51:15 -0400104acpi_rs_struct_option_length(struct acpi_resource_source *resource_source)
105{
106 ACPI_FUNCTION_ENTRY();
107
108 /*
109 * If the resource_source string is valid, return the size of the string
110 * (string_length includes the NULL terminator) plus the size of the
111 * resource_source_index (1).
112 */
113 if (resource_source->string_ptr) {
Bob Moore08978312005-10-21 00:00:00 -0400114 return ((acpi_rs_length) (resource_source->string_length + 1));
Robert Moorebda663d2005-09-16 16:51:15 -0400115 }
116
117 return (0);
118}
119
120/*******************************************************************************
121 *
122 * FUNCTION: acpi_rs_stream_option_length
123 *
124 * PARAMETERS: resource_length - Length from the resource header
125 * minimum_total_length - Minimum length of this resource, before
126 * any optional fields. Includes header size
127 *
128 * RETURN: Length of optional string (0 if no string present)
129 *
130 * DESCRIPTION: Common code to handle optional resource_source_index and
131 * resource_source fields in some Large descriptors. Used during
132 * stream-to-list conversion
133 *
134 ******************************************************************************/
135
136static u32
Bob Moore50eca3e2005-09-30 19:03:00 -0400137acpi_rs_stream_option_length(u32 resource_length,
138 u32 minimum_aml_resource_length)
Robert Moorebda663d2005-09-16 16:51:15 -0400139{
140 u32 string_length = 0;
Robert Moorebda663d2005-09-16 16:51:15 -0400141
142 ACPI_FUNCTION_ENTRY();
143
144 /*
145 * The resource_source_index and resource_source are optional elements of some
146 * Large-type resource descriptors.
147 */
148
Robert Moorebda663d2005-09-16 16:51:15 -0400149 /*
150 * If the length of the actual resource descriptor is greater than the ACPI
151 * spec-defined minimum length, it means that a resource_source_index exists
152 * and is followed by a (required) null terminated string. The string length
153 * (including the null terminator) is the resource length minus the minimum
154 * length, minus one byte for the resource_source_index itself.
155 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400156 if (resource_length > minimum_aml_resource_length) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400157
Robert Moorebda663d2005-09-16 16:51:15 -0400158 /* Compute the length of the optional string */
159
Bob Moore50eca3e2005-09-30 19:03:00 -0400160 string_length =
161 resource_length - minimum_aml_resource_length - 1;
Robert Moorebda663d2005-09-16 16:51:15 -0400162 }
163
Bob Mooreea936b72006-02-17 00:00:00 -0500164 /*
165 * Round the length up to a multiple of the native word in order to
166 * guarantee that the entire resource descriptor is native word aligned
167 */
168 return ((u32) ACPI_ROUND_UP_TO_NATIVE_WORD(string_length));
Robert Moorebda663d2005-09-16 16:51:15 -0400169}
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171/*******************************************************************************
172 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400173 * FUNCTION: acpi_rs_get_aml_length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 *
Robert Moorebda663d2005-09-16 16:51:15 -0400175 * PARAMETERS: Resource - Pointer to the resource linked list
176 * size_needed - Where the required size is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 *
178 * RETURN: Status
179 *
Robert Moorebda663d2005-09-16 16:51:15 -0400180 * DESCRIPTION: Takes a linked list of internal resource descriptors and
181 * calculates the size buffer needed to hold the corresponding
182 * external resource byte stream.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 *
184 ******************************************************************************/
Robert Moorebda663d2005-09-16 16:51:15 -0400185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400187acpi_rs_get_aml_length(struct acpi_resource * resource, acpi_size * size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Bob Moore50eca3e2005-09-30 19:03:00 -0400189 acpi_size aml_size_needed = 0;
Bob Moore08978312005-10-21 00:00:00 -0400190 acpi_rs_length total_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Bob Mooreb229cf92006-04-21 17:15:00 -0400192 ACPI_FUNCTION_TRACE(rs_get_aml_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Robert Moorebda663d2005-09-16 16:51:15 -0400194 /* Traverse entire list of internal resource descriptors */
Robert Moore44f6c012005-04-18 22:49:35 -0400195
Robert Moorebda663d2005-09-16 16:51:15 -0400196 while (resource) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400197
Robert Moorebda663d2005-09-16 16:51:15 -0400198 /* Validate the descriptor type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bob Moore50eca3e2005-09-30 19:03:00 -0400200 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
Robert Moorebda663d2005-09-16 16:51:15 -0400201 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Robert Moorebda663d2005-09-16 16:51:15 -0400204 /* Get the base size of the (external stream) resource descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Bob Moore08978312005-10-21 00:00:00 -0400206 total_size = acpi_gbl_aml_resource_sizes[resource->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Robert Moorebda663d2005-09-16 16:51:15 -0400208 /*
209 * Augment the base size for descriptors with optional and/or
210 * variable-length fields
211 */
212 switch (resource->type) {
Bob Moore1d5b2852008-04-10 19:06:43 +0400213 case ACPI_RESOURCE_TYPE_IRQ:
214
Bob Moore66d3ca92008-04-10 19:06:44 +0400215 /* Length can be 3 or 2 */
216
Bob Moore1d5b2852008-04-10 19:06:43 +0400217 if (resource->data.irq.descriptor_length == 2) {
218 total_size--;
219 }
220 break;
221
Bob Moore66d3ca92008-04-10 19:06:44 +0400222 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
223
224 /* Length can be 1 or 0 */
225
226 if (resource->data.irq.descriptor_length == 0) {
227 total_size--;
228 }
229 break;
230
Bob Moore50eca3e2005-09-30 19:03:00 -0400231 case ACPI_RESOURCE_TYPE_VENDOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400233 * Vendor Defined Resource:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 * For a Vendor Specific resource, if the Length is between 1 and 7
235 * it will be created as a Small Resource data type, otherwise it
236 * is a Large Resource data type.
237 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400238 if (resource->data.vendor.byte_length > 7) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400239
Robert Moorebda663d2005-09-16 16:51:15 -0400240 /* Base size of a Large resource descriptor */
241
Bob Moore08978312005-10-21 00:00:00 -0400242 total_size =
Bob Moore50eca3e2005-09-30 19:03:00 -0400243 sizeof(struct aml_resource_large_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
Robert Moorebda663d2005-09-16 16:51:15 -0400245
246 /* Add the size of the vendor-specific data */
247
Bob Moore08978312005-10-21 00:00:00 -0400248 total_size = (acpi_rs_length)
249 (total_size + resource->data.vendor.byte_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 break;
251
Bob Moore50eca3e2005-09-30 19:03:00 -0400252 case ACPI_RESOURCE_TYPE_END_TAG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400254 * End Tag:
255 * We are done -- return the accumulated total size.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 */
Bob Moore08978312005-10-21 00:00:00 -0400257 *size_needed = aml_size_needed + total_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Robert Moorebda663d2005-09-16 16:51:15 -0400259 /* Normal exit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Robert Moorebda663d2005-09-16 16:51:15 -0400261 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Bob Moore50eca3e2005-09-30 19:03:00 -0400263 case ACPI_RESOURCE_TYPE_ADDRESS16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400265 * 16-Bit Address Resource:
266 * Add the size of the optional resource_source info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 */
Bob Moore08978312005-10-21 00:00:00 -0400268 total_size = (acpi_rs_length)
269 (total_size +
270 acpi_rs_struct_option_length(&resource->data.
271 address16.
272 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 break;
274
Bob Moore50eca3e2005-09-30 19:03:00 -0400275 case ACPI_RESOURCE_TYPE_ADDRESS32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400277 * 32-Bit Address Resource:
278 * Add the size of the optional resource_source info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 */
Bob Moore08978312005-10-21 00:00:00 -0400280 total_size = (acpi_rs_length)
281 (total_size +
282 acpi_rs_struct_option_length(&resource->data.
283 address32.
284 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 break;
286
Bob Moore50eca3e2005-09-30 19:03:00 -0400287 case ACPI_RESOURCE_TYPE_ADDRESS64:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400289 * 64-Bit Address Resource:
290 * Add the size of the optional resource_source info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 */
Bob Moore08978312005-10-21 00:00:00 -0400292 total_size = (acpi_rs_length)
293 (total_size +
294 acpi_rs_struct_option_length(&resource->data.
295 address64.
296 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 break;
298
Bob Moore50eca3e2005-09-30 19:03:00 -0400299 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 /*
Robert Moorebda663d2005-09-16 16:51:15 -0400301 * Extended IRQ Resource:
302 * Add the size of each additional optional interrupt beyond the
303 * required 1 (4 bytes for each u32 interrupt number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 */
Bob Moore08978312005-10-21 00:00:00 -0400305 total_size = (acpi_rs_length)
306 (total_size +
307 ((resource->data.extended_irq.interrupt_count -
308 1) * 4) +
309 /* Add the size of the optional resource_source info */
310 acpi_rs_struct_option_length(&resource->data.
311 extended_irq.
312 resource_source));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 break;
314
315 default:
Robert Moorebda663d2005-09-16 16:51:15 -0400316 break;
317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Robert Moore44f6c012005-04-18 22:49:35 -0400319 /* Update the total */
320
Bob Moore08978312005-10-21 00:00:00 -0400321 aml_size_needed += total_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Robert Moore44f6c012005-04-18 22:49:35 -0400323 /* Point to the next object */
324
Bob Moore96db2552005-11-02 00:00:00 -0500325 resource =
Bob Moorec51a4de2005-11-17 13:07:00 -0500326 ACPI_ADD_PTR(struct acpi_resource, resource,
Bob Moore96db2552005-11-02 00:00:00 -0500327 resource->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
329
Bob Moore96db2552005-11-02 00:00:00 -0500330 /* Did not find an end_tag resource descriptor */
Robert Moore44f6c012005-04-18 22:49:35 -0400331
Bob Moore96db2552005-11-02 00:00:00 -0500332 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335/*******************************************************************************
336 *
337 * FUNCTION: acpi_rs_get_list_length
338 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400339 * PARAMETERS: aml_buffer - Pointer to the resource byte stream
340 * aml_buffer_length - Size of aml_buffer
341 * size_needed - Where the size needed is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 * RETURN: Status
344 *
Robert Moorebda663d2005-09-16 16:51:15 -0400345 * DESCRIPTION: Takes an external resource byte stream and calculates the size
346 * buffer needed to hold the corresponding internal resource
347 * descriptor linked list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 *
349 ******************************************************************************/
350
351acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400352acpi_rs_get_list_length(u8 * aml_buffer,
353 u32 aml_buffer_length, acpi_size * size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
Bob Moore96db2552005-11-02 00:00:00 -0500355 acpi_status status;
356 u8 *end_aml;
Robert Moorebda663d2005-09-16 16:51:15 -0400357 u8 *buffer;
Bob Mooreea936b72006-02-17 00:00:00 -0500358 u32 buffer_size;
Len Brown4be44fc2005-08-05 00:44:28 -0400359 u16 temp16;
Robert Moorebda663d2005-09-16 16:51:15 -0400360 u16 resource_length;
Robert Moorebda663d2005-09-16 16:51:15 -0400361 u32 extra_struct_bytes;
Bob Moore96db2552005-11-02 00:00:00 -0500362 u8 resource_index;
363 u8 minimum_aml_resource_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Bob Mooreb229cf92006-04-21 17:15:00 -0400365 ACPI_FUNCTION_TRACE(rs_get_list_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Bob Mooreea936b72006-02-17 00:00:00 -0500367 *size_needed = 0;
Bob Moore96db2552005-11-02 00:00:00 -0500368 end_aml = aml_buffer + aml_buffer_length;
Robert Moore44f6c012005-04-18 22:49:35 -0400369
Bob Moore96db2552005-11-02 00:00:00 -0500370 /* Walk the list of AML resource descriptors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Bob Moore96db2552005-11-02 00:00:00 -0500372 while (aml_buffer < end_aml) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400373
Bob Moore96db2552005-11-02 00:00:00 -0500374 /* Validate the Resource Type and Resource Length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Bob Moore96db2552005-11-02 00:00:00 -0500376 status = acpi_ut_validate_resource(aml_buffer, &resource_index);
377 if (ACPI_FAILURE(status)) {
378 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
380
Bob Moore96db2552005-11-02 00:00:00 -0500381 /* Get the resource length and base (minimum) AML size */
Robert Moore44f6c012005-04-18 22:49:35 -0400382
Bob Moore08978312005-10-21 00:00:00 -0400383 resource_length = acpi_ut_get_resource_length(aml_buffer);
Bob Moore96db2552005-11-02 00:00:00 -0500384 minimum_aml_resource_length =
385 acpi_gbl_resource_aml_sizes[resource_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Bob Moore96db2552005-11-02 00:00:00 -0500387 /*
388 * Augment the size for descriptors with optional
389 * and/or variable length fields
390 */
Robert Moorebda663d2005-09-16 16:51:15 -0400391 extra_struct_bytes = 0;
Bob Moore96db2552005-11-02 00:00:00 -0500392 buffer =
393 aml_buffer + acpi_ut_get_resource_header_length(aml_buffer);
Robert Moorebda663d2005-09-16 16:51:15 -0400394
Bob Moore96db2552005-11-02 00:00:00 -0500395 switch (acpi_ut_get_resource_type(aml_buffer)) {
396 case ACPI_RESOURCE_NAME_IRQ:
Robert Moorebda663d2005-09-16 16:51:15 -0400397 /*
Bob Moore96db2552005-11-02 00:00:00 -0500398 * IRQ Resource:
399 * Get the number of bits set in the 16-bit IRQ mask
Robert Moorebda663d2005-09-16 16:51:15 -0400400 */
Bob Moore96db2552005-11-02 00:00:00 -0500401 ACPI_MOVE_16_TO_16(&temp16, buffer);
Bob Moorec51a4de2005-11-17 13:07:00 -0500402 extra_struct_bytes = acpi_rs_count_set_bits(temp16);
Bob Moore96db2552005-11-02 00:00:00 -0500403 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400404
Bob Moore96db2552005-11-02 00:00:00 -0500405 case ACPI_RESOURCE_NAME_DMA:
Robert Moorebda663d2005-09-16 16:51:15 -0400406 /*
Bob Moore96db2552005-11-02 00:00:00 -0500407 * DMA Resource:
408 * Get the number of bits set in the 8-bit DMA mask
Robert Moorebda663d2005-09-16 16:51:15 -0400409 */
Bob Moorec51a4de2005-11-17 13:07:00 -0500410 extra_struct_bytes = acpi_rs_count_set_bits(*buffer);
Bob Moore96db2552005-11-02 00:00:00 -0500411 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400412
Bob Moore96db2552005-11-02 00:00:00 -0500413 case ACPI_RESOURCE_NAME_VENDOR_SMALL:
Bob Mooreea936b72006-02-17 00:00:00 -0500414 case ACPI_RESOURCE_NAME_VENDOR_LARGE:
Bob Moore96db2552005-11-02 00:00:00 -0500415 /*
416 * Vendor Resource:
Bob Mooreea936b72006-02-17 00:00:00 -0500417 * Get the number of vendor data bytes
Bob Moore96db2552005-11-02 00:00:00 -0500418 */
Bob Mooreea936b72006-02-17 00:00:00 -0500419 extra_struct_bytes = resource_length;
Bob Moore96db2552005-11-02 00:00:00 -0500420 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400421
Bob Moore96db2552005-11-02 00:00:00 -0500422 case ACPI_RESOURCE_NAME_END_TAG:
423 /*
Bob Mooreea936b72006-02-17 00:00:00 -0500424 * End Tag:
425 * This is the normal exit, add size of end_tag
Bob Moore96db2552005-11-02 00:00:00 -0500426 */
Bob Mooreea936b72006-02-17 00:00:00 -0500427 *size_needed += ACPI_RS_SIZE_MIN;
Bob Moore96db2552005-11-02 00:00:00 -0500428 return_ACPI_STATUS(AE_OK);
Robert Moorebda663d2005-09-16 16:51:15 -0400429
Bob Moore96db2552005-11-02 00:00:00 -0500430 case ACPI_RESOURCE_NAME_ADDRESS32:
431 case ACPI_RESOURCE_NAME_ADDRESS16:
Bob Mooreea936b72006-02-17 00:00:00 -0500432 case ACPI_RESOURCE_NAME_ADDRESS64:
Bob Moore96db2552005-11-02 00:00:00 -0500433 /*
Bob Mooreea936b72006-02-17 00:00:00 -0500434 * Address Resource:
435 * Add the size of the optional resource_source
Bob Moore96db2552005-11-02 00:00:00 -0500436 */
437 extra_struct_bytes =
438 acpi_rs_stream_option_length(resource_length,
439 minimum_aml_resource_length);
440 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400441
Bob Moore96db2552005-11-02 00:00:00 -0500442 case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
443 /*
Bob Mooreea936b72006-02-17 00:00:00 -0500444 * Extended IRQ Resource:
445 * Using the interrupt_table_length, add 4 bytes for each additional
446 * interrupt. Note: at least one interrupt is required and is
447 * included in the minimum descriptor size (reason for the -1)
Bob Moore96db2552005-11-02 00:00:00 -0500448 */
Bob Mooreea936b72006-02-17 00:00:00 -0500449 extra_struct_bytes = (buffer[1] - 1) * sizeof(u32);
Robert Moorebda663d2005-09-16 16:51:15 -0400450
Bob Mooreea936b72006-02-17 00:00:00 -0500451 /* Add the size of the optional resource_source */
452
453 extra_struct_bytes +=
Bob Moore96db2552005-11-02 00:00:00 -0500454 acpi_rs_stream_option_length(resource_length -
455 extra_struct_bytes,
456 minimum_aml_resource_length);
457 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400458
Bob Moore96db2552005-11-02 00:00:00 -0500459 default:
460 break;
Robert Moorebda663d2005-09-16 16:51:15 -0400461 }
462
Bob Mooreea936b72006-02-17 00:00:00 -0500463 /*
464 * Update the required buffer size for the internal descriptor structs
465 *
466 * Important: Round the size up for the appropriate alignment. This
467 * is a requirement on IA64.
468 */
469 buffer_size = acpi_gbl_resource_struct_sizes[resource_index] +
470 extra_struct_bytes;
Bob Moore958dd242006-05-12 17:12:00 -0400471 buffer_size = (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(buffer_size);
Robert Moorebda663d2005-09-16 16:51:15 -0400472
Bob Mooreea936b72006-02-17 00:00:00 -0500473 *size_needed += buffer_size;
474
475 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
Bob Mooreb229cf92006-04-21 17:15:00 -0400476 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
Bob Mooreea936b72006-02-17 00:00:00 -0500477 acpi_ut_get_resource_type(aml_buffer),
478 acpi_ut_get_descriptor_length(aml_buffer),
479 buffer_size));
Robert Moorebda663d2005-09-16 16:51:15 -0400480
481 /*
Bob Mooreea936b72006-02-17 00:00:00 -0500482 * Point to the next resource within the AML stream using the length
483 * contained in the resource descriptor header
Robert Moorebda663d2005-09-16 16:51:15 -0400484 */
Bob Moore96db2552005-11-02 00:00:00 -0500485 aml_buffer += acpi_ut_get_descriptor_length(aml_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487
Bob Moore96db2552005-11-02 00:00:00 -0500488 /* Did not find an end_tag resource descriptor */
Robert Moore44f6c012005-04-18 22:49:35 -0400489
Bob Moore96db2552005-11-02 00:00:00 -0500490 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493/*******************************************************************************
494 *
495 * FUNCTION: acpi_rs_get_pci_routing_table_length
496 *
497 * PARAMETERS: package_object - Pointer to the package object
498 * buffer_size_needed - u32 pointer of the size buffer
499 * needed to properly return the
500 * parsed data
501 *
502 * RETURN: Status
503 *
504 * DESCRIPTION: Given a package representing a PCI routing table, this
505 * calculates the size of the corresponding linked list of
506 * descriptions.
507 *
508 ******************************************************************************/
509
510acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400511acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
512 acpi_size * buffer_size_needed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Len Brown4be44fc2005-08-05 00:44:28 -0400514 u32 number_of_elements;
515 acpi_size temp_size_needed = 0;
516 union acpi_operand_object **top_object_list;
517 u32 index;
518 union acpi_operand_object *package_element;
519 union acpi_operand_object **sub_object_list;
520 u8 name_found;
521 u32 table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Bob Mooreb229cf92006-04-21 17:15:00 -0400523 ACPI_FUNCTION_TRACE(rs_get_pci_routing_table_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 number_of_elements = package_object->package.count;
526
527 /*
528 * Calculate the size of the return buffer.
529 * The base size is the number of elements * the sizes of the
530 * structures. Additional space for the strings is added below.
531 * The minus one is to subtract the size of the u8 Source[1]
532 * member because it is added below.
533 *
534 * But each PRT_ENTRY structure has a pointer to a string and
535 * the size of that string must be found.
536 */
537 top_object_list = package_object->package.elements;
538
539 for (index = 0; index < number_of_elements; index++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400540
Robert Moore44f6c012005-04-18 22:49:35 -0400541 /* Dereference the sub-package */
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 package_element = *top_object_list;
544
545 /*
546 * The sub_object_list will now point to an array of the
547 * four IRQ elements: Address, Pin, Source and source_index
548 */
549 sub_object_list = package_element->package.elements;
550
Robert Moore44f6c012005-04-18 22:49:35 -0400551 /* Scan the irq_table_elements for the Source Name String */
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 name_found = FALSE;
554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 for (table_index = 0; table_index < 4 && !name_found;
556 table_index++) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500557 if (*sub_object_list && /* Null object allowed */
558 ((ACPI_TYPE_STRING ==
559 ACPI_GET_OBJECT_TYPE(*sub_object_list)) ||
560 ((ACPI_TYPE_LOCAL_REFERENCE ==
561 ACPI_GET_OBJECT_TYPE(*sub_object_list)) &&
Bob Moore1044f1f2008-09-27 11:08:41 +0800562 ((*sub_object_list)->reference.class ==
563 ACPI_REFCLASS_NAME)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 name_found = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400565 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400566 /* Look at the next element */
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 sub_object_list++;
569 }
570 }
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Robert Moore44f6c012005-04-18 22:49:35 -0400574 /* Was a String type found? */
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (name_found) {
Len Brown4be44fc2005-08-05 00:44:28 -0400577 if (ACPI_GET_OBJECT_TYPE(*sub_object_list) ==
578 ACPI_TYPE_STRING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 /*
580 * The length String.Length field does not include the
581 * terminating NULL, add 1
582 */
Robert Moore44f6c012005-04-18 22:49:35 -0400583 temp_size_needed += ((acpi_size)
Len Brown4be44fc2005-08-05 00:44:28 -0400584 (*sub_object_list)->string.
585 length + 1);
586 } else {
Len Brownfd350942007-05-09 23:34:35 -0400587 temp_size_needed +=
588 acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
Bob Moore3c7db222008-08-04 11:13:01 +0800589 if (!temp_size_needed) {
590 return_ACPI_STATUS(AE_BAD_PARAMETER);
591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Len Brown4be44fc2005-08-05 00:44:28 -0400593 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 /*
595 * If no name was found, then this is a NULL, which is
596 * translated as a u32 zero.
597 */
Len Brown4be44fc2005-08-05 00:44:28 -0400598 temp_size_needed += sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
601 /* Round up the size since each element must be aligned */
602
Bob Moore958dd242006-05-12 17:12:00 -0400603 temp_size_needed = ACPI_ROUND_UP_TO_64BIT(temp_size_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Robert Moore44f6c012005-04-18 22:49:35 -0400605 /* Point to the next union acpi_operand_object */
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 top_object_list++;
608 }
609
610 /*
Bob Mooreea936b72006-02-17 00:00:00 -0500611 * Add an extra element to the end of the list, essentially a
Robert Moore44f6c012005-04-18 22:49:35 -0400612 * NULL terminator
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 */
Len Brown4be44fc2005-08-05 00:44:28 -0400614 *buffer_size_needed =
615 temp_size_needed + sizeof(struct acpi_pci_routing_table);
616 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}