| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 | * | 
|  | 3 | * Module Name: rscalc - Calculate stream and list lengths | 
|  | 4 | * | 
|  | 5 | ******************************************************************************/ | 
|  | 6 |  | 
|  | 7 | /* | 
|  | 8 | * Copyright (C) 2000 - 2005, R. Byron Moore | 
|  | 9 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("rscalc") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
|  | 52 | /******************************************************************************* | 
|  | 53 | * | 
|  | 54 | * FUNCTION:    acpi_rs_get_byte_stream_length | 
|  | 55 | * | 
|  | 56 | * PARAMETERS:  linked_list         - Pointer to the resource linked list | 
|  | 57 | *              size_needed         - u32 pointer of the size buffer needed | 
|  | 58 | *                                    to properly return the parsed data | 
|  | 59 | * | 
|  | 60 | * RETURN:      Status | 
|  | 61 | * | 
|  | 62 | * DESCRIPTION: Takes the resource byte stream and parses it once, calculating | 
|  | 63 | *              the size buffer needed to hold the linked list that conveys | 
|  | 64 | *              the resource data. | 
|  | 65 | * | 
|  | 66 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | acpi_rs_get_byte_stream_length(struct acpi_resource *linked_list, | 
|  | 69 | acpi_size * size_needed) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | acpi_size byte_stream_size_needed = 0; | 
|  | 72 | acpi_size segment_size; | 
|  | 73 | u8 done = FALSE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | ACPI_FUNCTION_TRACE("rs_get_byte_stream_length"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | while (!done) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 78 | /* Init the variable that will hold the size to add to the total. */ | 
|  | 79 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | segment_size = 0; | 
|  | 81 |  | 
|  | 82 | switch (linked_list->id) { | 
|  | 83 | case ACPI_RSTYPE_IRQ: | 
|  | 84 | /* | 
|  | 85 | * IRQ Resource | 
|  | 86 | * For an IRQ Resource, Byte 3, although optional, will always be | 
|  | 87 | * created - it holds IRQ information. | 
|  | 88 | */ | 
|  | 89 | segment_size = 4; | 
|  | 90 | break; | 
|  | 91 |  | 
|  | 92 | case ACPI_RSTYPE_DMA: | 
|  | 93 | /* | 
|  | 94 | * DMA Resource | 
|  | 95 | * For this resource the size is static | 
|  | 96 | */ | 
|  | 97 | segment_size = 3; | 
|  | 98 | break; | 
|  | 99 |  | 
|  | 100 | case ACPI_RSTYPE_START_DPF: | 
|  | 101 | /* | 
|  | 102 | * Start Dependent Functions Resource | 
|  | 103 | * For a start_dependent_functions Resource, Byte 1, although | 
|  | 104 | * optional, will always be created. | 
|  | 105 | */ | 
|  | 106 | segment_size = 2; | 
|  | 107 | break; | 
|  | 108 |  | 
|  | 109 | case ACPI_RSTYPE_END_DPF: | 
|  | 110 | /* | 
|  | 111 | * End Dependent Functions Resource | 
|  | 112 | * For this resource the size is static | 
|  | 113 | */ | 
|  | 114 | segment_size = 1; | 
|  | 115 | break; | 
|  | 116 |  | 
|  | 117 | case ACPI_RSTYPE_IO: | 
|  | 118 | /* | 
|  | 119 | * IO Port Resource | 
|  | 120 | * For this resource the size is static | 
|  | 121 | */ | 
|  | 122 | segment_size = 8; | 
|  | 123 | break; | 
|  | 124 |  | 
|  | 125 | case ACPI_RSTYPE_FIXED_IO: | 
|  | 126 | /* | 
|  | 127 | * Fixed IO Port Resource | 
|  | 128 | * For this resource the size is static | 
|  | 129 | */ | 
|  | 130 | segment_size = 4; | 
|  | 131 | break; | 
|  | 132 |  | 
|  | 133 | case ACPI_RSTYPE_VENDOR: | 
|  | 134 | /* | 
|  | 135 | * Vendor Defined Resource | 
|  | 136 | * For a Vendor Specific resource, if the Length is between 1 and 7 | 
|  | 137 | * it will be created as a Small Resource data type, otherwise it | 
|  | 138 | * is a Large Resource data type. | 
|  | 139 | */ | 
|  | 140 | if (linked_list->data.vendor_specific.length > 7) { | 
|  | 141 | segment_size = 3; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | segment_size = 1; | 
|  | 144 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | segment_size += | 
|  | 146 | linked_list->data.vendor_specific.length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | break; | 
|  | 148 |  | 
|  | 149 | case ACPI_RSTYPE_END_TAG: | 
|  | 150 | /* | 
|  | 151 | * End Tag | 
|  | 152 | * For this resource the size is static | 
|  | 153 | */ | 
|  | 154 | segment_size = 2; | 
|  | 155 | done = TRUE; | 
|  | 156 | break; | 
|  | 157 |  | 
|  | 158 | case ACPI_RSTYPE_MEM24: | 
|  | 159 | /* | 
|  | 160 | * 24-Bit Memory Resource | 
|  | 161 | * For this resource the size is static | 
|  | 162 | */ | 
|  | 163 | segment_size = 12; | 
|  | 164 | break; | 
|  | 165 |  | 
|  | 166 | case ACPI_RSTYPE_MEM32: | 
|  | 167 | /* | 
|  | 168 | * 32-Bit Memory Range Resource | 
|  | 169 | * For this resource the size is static | 
|  | 170 | */ | 
|  | 171 | segment_size = 20; | 
|  | 172 | break; | 
|  | 173 |  | 
|  | 174 | case ACPI_RSTYPE_FIXED_MEM32: | 
|  | 175 | /* | 
|  | 176 | * 32-Bit Fixed Memory Resource | 
|  | 177 | * For this resource the size is static | 
|  | 178 | */ | 
|  | 179 | segment_size = 12; | 
|  | 180 | break; | 
|  | 181 |  | 
|  | 182 | case ACPI_RSTYPE_ADDRESS16: | 
|  | 183 | /* | 
|  | 184 | * 16-Bit Address Resource | 
|  | 185 | * The base size of this byte stream is 16. If a Resource Source | 
|  | 186 | * string is not NULL, add 1 for the Index + the length of the null | 
|  | 187 | * terminated string Resource Source + 1 for the null. | 
|  | 188 | */ | 
|  | 189 | segment_size = 16; | 
|  | 190 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | if (linked_list->data.address16.resource_source. | 
|  | 192 | string_ptr) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 193 | segment_size += | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | linked_list->data.address16.resource_source. | 
|  | 195 | string_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | segment_size++; | 
|  | 197 | } | 
|  | 198 | break; | 
|  | 199 |  | 
|  | 200 | case ACPI_RSTYPE_ADDRESS32: | 
|  | 201 | /* | 
|  | 202 | * 32-Bit Address Resource | 
|  | 203 | * The base size of this byte stream is 26. If a Resource | 
|  | 204 | * Source string is not NULL, add 1 for the Index + the | 
|  | 205 | * length of the null terminated string Resource Source + | 
|  | 206 | * 1 for the null. | 
|  | 207 | */ | 
|  | 208 | segment_size = 26; | 
|  | 209 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | if (linked_list->data.address32.resource_source. | 
|  | 211 | string_ptr) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 212 | segment_size += | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | linked_list->data.address32.resource_source. | 
|  | 214 | string_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | segment_size++; | 
|  | 216 | } | 
|  | 217 | break; | 
|  | 218 |  | 
|  | 219 | case ACPI_RSTYPE_ADDRESS64: | 
|  | 220 | /* | 
|  | 221 | * 64-Bit Address Resource | 
|  | 222 | * The base size of this byte stream is 46. If a resource_source | 
|  | 223 | * string is not NULL, add 1 for the Index + the length of the null | 
|  | 224 | * terminated string Resource Source + 1 for the null. | 
|  | 225 | */ | 
|  | 226 | segment_size = 46; | 
|  | 227 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | if (linked_list->data.address64.resource_source. | 
|  | 229 | string_ptr) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 230 | segment_size += | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | linked_list->data.address64.resource_source. | 
|  | 232 | string_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | segment_size++; | 
|  | 234 | } | 
|  | 235 | break; | 
|  | 236 |  | 
|  | 237 | case ACPI_RSTYPE_EXT_IRQ: | 
|  | 238 | /* | 
|  | 239 | * Extended IRQ Resource | 
|  | 240 | * The base size of this byte stream is 9. This is for an Interrupt | 
|  | 241 | * table length of 1.  For each additional interrupt, add 4. | 
|  | 242 | * If a Resource Source string is not NULL, add 1 for the | 
|  | 243 | * Index + the length of the null terminated string | 
|  | 244 | * Resource Source + 1 for the null. | 
|  | 245 | */ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 246 | segment_size = 9 + (((acpi_size) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | linked_list->data.extended_irq. | 
|  | 248 | number_of_interrupts - 1) * 4); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | if (linked_list->data.extended_irq.resource_source. | 
|  | 251 | string_ptr) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 252 | segment_size += | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | linked_list->data.extended_irq. | 
|  | 254 | resource_source.string_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | segment_size++; | 
|  | 256 | } | 
|  | 257 | break; | 
|  | 258 |  | 
|  | 259 | default: | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 260 |  | 
|  | 261 | /* If we get here, everything is out of sync, exit with error */ | 
|  | 262 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | }		/* switch (linked_list->Id) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 267 | /* Update the total */ | 
|  | 268 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | byte_stream_size_needed += segment_size; | 
|  | 270 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 271 | /* Point to the next object */ | 
|  | 272 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | linked_list = ACPI_PTR_ADD(struct acpi_resource, | 
|  | 274 | linked_list, linked_list->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } | 
|  | 276 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 277 | /* This is the data the caller needs */ | 
|  | 278 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | *size_needed = byte_stream_size_needed; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } | 
|  | 282 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | /******************************************************************************* | 
|  | 284 | * | 
|  | 285 | * FUNCTION:    acpi_rs_get_list_length | 
|  | 286 | * | 
|  | 287 | * PARAMETERS:  byte_stream_buffer      - Pointer to the resource byte stream | 
|  | 288 | *              byte_stream_buffer_length - Size of byte_stream_buffer | 
|  | 289 | *              size_needed             - u32 pointer of the size buffer | 
|  | 290 | *                                        needed to properly return the | 
|  | 291 | *                                        parsed data | 
|  | 292 | * | 
|  | 293 | * RETURN:      Status | 
|  | 294 | * | 
|  | 295 | * DESCRIPTION: Takes the resource byte stream and parses it once, calculating | 
|  | 296 | *              the size buffer needed to hold the linked list that conveys | 
|  | 297 | *              the resource data. | 
|  | 298 | * | 
|  | 299 | ******************************************************************************/ | 
|  | 300 |  | 
|  | 301 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | acpi_rs_get_list_length(u8 * byte_stream_buffer, | 
|  | 303 | u32 byte_stream_buffer_length, acpi_size * size_needed) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | u32 buffer_size = 0; | 
|  | 306 | u32 bytes_parsed = 0; | 
|  | 307 | u8 number_of_interrupts = 0; | 
|  | 308 | u8 number_of_channels = 0; | 
|  | 309 | u8 resource_type; | 
|  | 310 | u32 structure_size; | 
|  | 311 | u32 bytes_consumed; | 
|  | 312 | u8 *buffer; | 
|  | 313 | u8 temp8; | 
|  | 314 | u16 temp16; | 
|  | 315 | u8 index; | 
|  | 316 | u8 additional_bytes; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | ACPI_FUNCTION_TRACE("rs_get_list_length"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 |  | 
|  | 320 | while (bytes_parsed < byte_stream_buffer_length) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 321 | /* The next byte in the stream is the resource type */ | 
|  | 322 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | resource_type = acpi_rs_get_resource_type(*byte_stream_buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 |  | 
|  | 325 | switch (resource_type) { | 
|  | 326 | case ACPI_RDESC_TYPE_MEMORY_24: | 
|  | 327 | /* | 
|  | 328 | * 24-Bit Memory Resource | 
|  | 329 | */ | 
|  | 330 | bytes_consumed = 12; | 
|  | 331 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | structure_size = | 
|  | 333 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | break; | 
|  | 335 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | case ACPI_RDESC_TYPE_LARGE_VENDOR: | 
|  | 337 | /* | 
|  | 338 | * Vendor Defined Resource | 
|  | 339 | */ | 
|  | 340 | buffer = byte_stream_buffer; | 
|  | 341 | ++buffer; | 
|  | 342 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | bytes_consumed = temp16 + 3; | 
|  | 345 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 346 | /* Ensure a 32-bit boundary for the structure */ | 
|  | 347 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | temp16 = (u16) ACPI_ROUND_UP_to_32_bITS(temp16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | structure_size = | 
|  | 351 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) + | 
|  | 352 | (temp16 * sizeof(u8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | break; | 
|  | 354 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | case ACPI_RDESC_TYPE_MEMORY_32: | 
|  | 356 | /* | 
|  | 357 | * 32-Bit Memory Range Resource | 
|  | 358 | */ | 
|  | 359 | bytes_consumed = 20; | 
|  | 360 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | structure_size = | 
|  | 362 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | break; | 
|  | 364 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | case ACPI_RDESC_TYPE_FIXED_MEMORY_32: | 
|  | 366 | /* | 
|  | 367 | * 32-Bit Fixed Memory Resource | 
|  | 368 | */ | 
|  | 369 | bytes_consumed = 12; | 
|  | 370 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | structure_size = | 
|  | 372 | ACPI_SIZEOF_RESOURCE(struct | 
|  | 373 | acpi_resource_fixed_mem32); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | break; | 
|  | 375 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE: | 
|  | 377 | /* | 
|  | 378 | * 64-Bit Address Resource | 
|  | 379 | */ | 
|  | 380 | buffer = byte_stream_buffer; | 
|  | 381 |  | 
|  | 382 | ++buffer; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 |  | 
|  | 385 | bytes_consumed = temp16 + 3; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | structure_size = | 
|  | 387 | ACPI_SIZEOF_RESOURCE(struct | 
|  | 388 | acpi_resource_address64); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | break; | 
|  | 390 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE: | 
|  | 392 | /* | 
|  | 393 | * 64-Bit Address Resource | 
|  | 394 | */ | 
|  | 395 | buffer = byte_stream_buffer; | 
|  | 396 |  | 
|  | 397 | ++buffer; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 |  | 
|  | 400 | bytes_consumed = temp16 + 3; | 
|  | 401 |  | 
|  | 402 | /* | 
|  | 403 | * Resource Source Index and Resource Source are optional elements. | 
|  | 404 | * Check the length of the Bytestream.  If it is greater than 43, | 
|  | 405 | * that means that an Index exists and is followed by a null | 
|  | 406 | * terminated string.  Therefore, set the temp variable to the | 
|  | 407 | * length minus the minimum byte stream length plus the byte for | 
|  | 408 | * the Index to determine the size of the NULL terminated string. | 
|  | 409 | */ | 
|  | 410 | if (43 < temp16) { | 
|  | 411 | temp8 = (u8) (temp16 - 44); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | temp8 = 0; | 
|  | 414 | } | 
|  | 415 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 416 | /* Ensure a 64-bit boundary for the structure */ | 
|  | 417 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 418 | temp8 = (u8) ACPI_ROUND_UP_to_64_bITS(temp8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | structure_size = | 
|  | 421 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64) | 
|  | 422 | + (temp8 * sizeof(u8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | break; | 
|  | 424 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE: | 
|  | 426 | /* | 
|  | 427 | * 32-Bit Address Resource | 
|  | 428 | */ | 
|  | 429 | buffer = byte_stream_buffer; | 
|  | 430 |  | 
|  | 431 | ++buffer; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 |  | 
|  | 434 | bytes_consumed = temp16 + 3; | 
|  | 435 |  | 
|  | 436 | /* | 
|  | 437 | * Resource Source Index and Resource Source are optional elements. | 
|  | 438 | * Check the length of the Bytestream.  If it is greater than 23, | 
|  | 439 | * that means that an Index exists and is followed by a null | 
|  | 440 | * terminated string.  Therefore, set the temp variable to the | 
|  | 441 | * length minus the minimum byte stream length plus the byte for | 
|  | 442 | * the Index to determine the size of the NULL terminated string. | 
|  | 443 | */ | 
|  | 444 | if (23 < temp16) { | 
|  | 445 | temp8 = (u8) (temp16 - 24); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | temp8 = 0; | 
|  | 448 | } | 
|  | 449 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 450 | /* Ensure a 32-bit boundary for the structure */ | 
|  | 451 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | structure_size = | 
|  | 455 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32) | 
|  | 456 | + (temp8 * sizeof(u8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | break; | 
|  | 458 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE: | 
|  | 460 | /* | 
|  | 461 | * 16-Bit Address Resource | 
|  | 462 | */ | 
|  | 463 | buffer = byte_stream_buffer; | 
|  | 464 |  | 
|  | 465 | ++buffer; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 |  | 
|  | 468 | bytes_consumed = temp16 + 3; | 
|  | 469 |  | 
|  | 470 | /* | 
|  | 471 | * Resource Source Index and Resource Source are optional elements. | 
|  | 472 | * Check the length of the Bytestream.  If it is greater than 13, | 
|  | 473 | * that means that an Index exists and is followed by a null | 
|  | 474 | * terminated string.  Therefore, set the temp variable to the | 
|  | 475 | * length minus the minimum byte stream length plus the byte for | 
|  | 476 | * the Index to determine the size of the NULL terminated string. | 
|  | 477 | */ | 
|  | 478 | if (13 < temp16) { | 
|  | 479 | temp8 = (u8) (temp16 - 14); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 480 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | temp8 = 0; | 
|  | 482 | } | 
|  | 483 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 484 | /* Ensure a 32-bit boundary for the structure */ | 
|  | 485 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | structure_size = | 
|  | 489 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16) | 
|  | 490 | + (temp8 * sizeof(u8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | break; | 
|  | 492 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | case ACPI_RDESC_TYPE_EXTENDED_XRUPT: | 
|  | 494 | /* | 
|  | 495 | * Extended IRQ | 
|  | 496 | */ | 
|  | 497 | buffer = byte_stream_buffer; | 
|  | 498 |  | 
|  | 499 | ++buffer; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 |  | 
|  | 502 | bytes_consumed = temp16 + 3; | 
|  | 503 |  | 
|  | 504 | /* | 
|  | 505 | * Point past the length field and the Interrupt vector flags to | 
|  | 506 | * save off the Interrupt table length to the Temp8 variable. | 
|  | 507 | */ | 
|  | 508 | buffer += 3; | 
|  | 509 | temp8 = *buffer; | 
|  | 510 |  | 
|  | 511 | /* | 
|  | 512 | * To compensate for multiple interrupt numbers, add 4 bytes for | 
|  | 513 | * each additional interrupts greater than 1 | 
|  | 514 | */ | 
|  | 515 | additional_bytes = (u8) ((temp8 - 1) * 4); | 
|  | 516 |  | 
|  | 517 | /* | 
|  | 518 | * Resource Source Index and Resource Source are optional elements. | 
|  | 519 | * Check the length of the Bytestream.  If it is greater than 9, | 
|  | 520 | * that means that an Index exists and is followed by a null | 
|  | 521 | * terminated string.  Therefore, set the temp variable to the | 
|  | 522 | * length minus the minimum byte stream length plus the byte for | 
|  | 523 | * the Index to determine the size of the NULL terminated string. | 
|  | 524 | */ | 
|  | 525 | if (9 + additional_bytes < temp16) { | 
|  | 526 | temp8 = (u8) (temp16 - (9 + additional_bytes)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | temp8 = 0; | 
|  | 529 | } | 
|  | 530 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 531 | /* Ensure a 32-bit boundary for the structure */ | 
|  | 532 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 533 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 535 | structure_size = | 
|  | 536 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq) + | 
|  | 537 | (additional_bytes * sizeof(u8)) + | 
|  | 538 | (temp8 * sizeof(u8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | break; | 
|  | 540 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | case ACPI_RDESC_TYPE_IRQ_FORMAT: | 
|  | 542 | /* | 
|  | 543 | * IRQ Resource. | 
|  | 544 | * Determine if it there are two or three trailing bytes | 
|  | 545 | */ | 
|  | 546 | buffer = byte_stream_buffer; | 
|  | 547 | temp8 = *buffer; | 
|  | 548 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 549 | if (temp8 & 0x01) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | bytes_consumed = 4; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 551 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | bytes_consumed = 3; | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | /* Point past the descriptor */ | 
|  | 556 |  | 
|  | 557 | ++buffer; | 
|  | 558 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 559 | /* Look at the number of bits set */ | 
|  | 560 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 561 | ACPI_MOVE_16_TO_16(&temp16, buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 |  | 
|  | 563 | for (index = 0; index < 16; index++) { | 
|  | 564 | if (temp16 & 0x1) { | 
|  | 565 | ++number_of_interrupts; | 
|  | 566 | } | 
|  | 567 |  | 
|  | 568 | temp16 >>= 1; | 
|  | 569 | } | 
|  | 570 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | structure_size = | 
|  | 572 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_io) + | 
|  | 573 | (number_of_interrupts * sizeof(u32)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | break; | 
|  | 575 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | case ACPI_RDESC_TYPE_DMA_FORMAT: | 
|  | 577 | /* | 
|  | 578 | * DMA Resource | 
|  | 579 | */ | 
|  | 580 | buffer = byte_stream_buffer; | 
|  | 581 | bytes_consumed = 3; | 
|  | 582 |  | 
|  | 583 | /* Point past the descriptor */ | 
|  | 584 |  | 
|  | 585 | ++buffer; | 
|  | 586 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 587 | /* Look at the number of bits set */ | 
|  | 588 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | temp8 = *buffer; | 
|  | 590 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 591 | for (index = 0; index < 8; index++) { | 
|  | 592 | if (temp8 & 0x1) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | ++number_of_channels; | 
|  | 594 | } | 
|  | 595 |  | 
|  | 596 | temp8 >>= 1; | 
|  | 597 | } | 
|  | 598 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | structure_size = | 
|  | 600 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma) + | 
|  | 601 | (number_of_channels * sizeof(u32)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | break; | 
|  | 603 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | case ACPI_RDESC_TYPE_START_DEPENDENT: | 
|  | 605 | /* | 
|  | 606 | * Start Dependent Functions Resource | 
|  | 607 | * Determine if it there are two or three trailing bytes | 
|  | 608 | */ | 
|  | 609 | buffer = byte_stream_buffer; | 
|  | 610 | temp8 = *buffer; | 
|  | 611 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 612 | if (temp8 & 0x01) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | bytes_consumed = 2; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 614 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | bytes_consumed = 1; | 
|  | 616 | } | 
|  | 617 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 618 | structure_size = | 
|  | 619 | ACPI_SIZEOF_RESOURCE(struct | 
|  | 620 | acpi_resource_start_dpf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | break; | 
|  | 622 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | case ACPI_RDESC_TYPE_END_DEPENDENT: | 
|  | 624 | /* | 
|  | 625 | * End Dependent Functions Resource | 
|  | 626 | */ | 
|  | 627 | bytes_consumed = 1; | 
|  | 628 | structure_size = ACPI_RESOURCE_LENGTH; | 
|  | 629 | break; | 
|  | 630 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | case ACPI_RDESC_TYPE_IO_PORT: | 
|  | 632 | /* | 
|  | 633 | * IO Port Resource | 
|  | 634 | */ | 
|  | 635 | bytes_consumed = 8; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | structure_size = | 
|  | 637 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_io); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | break; | 
|  | 639 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | case ACPI_RDESC_TYPE_FIXED_IO_PORT: | 
|  | 641 | /* | 
|  | 642 | * Fixed IO Port Resource | 
|  | 643 | */ | 
|  | 644 | bytes_consumed = 4; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 645 | structure_size = | 
|  | 646 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | break; | 
|  | 648 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | case ACPI_RDESC_TYPE_SMALL_VENDOR: | 
|  | 650 | /* | 
|  | 651 | * Vendor Specific Resource | 
|  | 652 | */ | 
|  | 653 | buffer = byte_stream_buffer; | 
|  | 654 |  | 
|  | 655 | temp8 = *buffer; | 
|  | 656 | temp8 = (u8) (temp8 & 0x7); | 
|  | 657 | bytes_consumed = temp8 + 1; | 
|  | 658 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 659 | /* Ensure a 32-bit boundary for the structure */ | 
|  | 660 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8); | 
|  | 662 | structure_size = | 
|  | 663 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) + | 
|  | 664 | (temp8 * sizeof(u8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | break; | 
|  | 666 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | case ACPI_RDESC_TYPE_END_TAG: | 
|  | 668 | /* | 
|  | 669 | * End Tag | 
|  | 670 | */ | 
|  | 671 | bytes_consumed = 2; | 
|  | 672 | structure_size = ACPI_RESOURCE_LENGTH; | 
|  | 673 | byte_stream_buffer_length = bytes_parsed; | 
|  | 674 | break; | 
|  | 675 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | default: | 
|  | 677 | /* | 
|  | 678 | * If we get here, everything is out of sync, | 
|  | 679 | * exit with an error | 
|  | 680 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } | 
|  | 683 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 684 | /* Update the return value and counter */ | 
|  | 685 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 686 | buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(structure_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | bytes_parsed += bytes_consumed; | 
|  | 688 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 689 | /* Set the byte stream to point to the next resource */ | 
|  | 690 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | byte_stream_buffer += bytes_consumed; | 
|  | 692 | } | 
|  | 693 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 694 | /* This is the data the caller needs */ | 
|  | 695 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | *size_needed = buffer_size; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 697 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } | 
|  | 699 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | /******************************************************************************* | 
|  | 701 | * | 
|  | 702 | * FUNCTION:    acpi_rs_get_pci_routing_table_length | 
|  | 703 | * | 
|  | 704 | * PARAMETERS:  package_object          - Pointer to the package object | 
|  | 705 | *              buffer_size_needed      - u32 pointer of the size buffer | 
|  | 706 | *                                        needed to properly return the | 
|  | 707 | *                                        parsed data | 
|  | 708 | * | 
|  | 709 | * RETURN:      Status | 
|  | 710 | * | 
|  | 711 | * DESCRIPTION: Given a package representing a PCI routing table, this | 
|  | 712 | *              calculates the size of the corresponding linked list of | 
|  | 713 | *              descriptions. | 
|  | 714 | * | 
|  | 715 | ******************************************************************************/ | 
|  | 716 |  | 
|  | 717 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object, | 
|  | 719 | acpi_size * buffer_size_needed) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 721 | u32 number_of_elements; | 
|  | 722 | acpi_size temp_size_needed = 0; | 
|  | 723 | union acpi_operand_object **top_object_list; | 
|  | 724 | u32 index; | 
|  | 725 | union acpi_operand_object *package_element; | 
|  | 726 | union acpi_operand_object **sub_object_list; | 
|  | 727 | u8 name_found; | 
|  | 728 | u32 table_index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 730 | ACPI_FUNCTION_TRACE("rs_get_pci_routing_table_length"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 |  | 
|  | 732 | number_of_elements = package_object->package.count; | 
|  | 733 |  | 
|  | 734 | /* | 
|  | 735 | * Calculate the size of the return buffer. | 
|  | 736 | * The base size is the number of elements * the sizes of the | 
|  | 737 | * structures.  Additional space for the strings is added below. | 
|  | 738 | * The minus one is to subtract the size of the u8 Source[1] | 
|  | 739 | * member because it is added below. | 
|  | 740 | * | 
|  | 741 | * But each PRT_ENTRY structure has a pointer to a string and | 
|  | 742 | * the size of that string must be found. | 
|  | 743 | */ | 
|  | 744 | top_object_list = package_object->package.elements; | 
|  | 745 |  | 
|  | 746 | for (index = 0; index < number_of_elements; index++) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 747 | /* Dereference the sub-package */ | 
|  | 748 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | package_element = *top_object_list; | 
|  | 750 |  | 
|  | 751 | /* | 
|  | 752 | * The sub_object_list will now point to an array of the | 
|  | 753 | * four IRQ elements: Address, Pin, Source and source_index | 
|  | 754 | */ | 
|  | 755 | sub_object_list = package_element->package.elements; | 
|  | 756 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 757 | /* Scan the irq_table_elements for the Source Name String */ | 
|  | 758 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | name_found = FALSE; | 
|  | 760 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 761 | for (table_index = 0; table_index < 4 && !name_found; | 
|  | 762 | table_index++) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 763 | if ((ACPI_TYPE_STRING == | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 764 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) | 
|  | 765 | || | 
|  | 766 | ((ACPI_TYPE_LOCAL_REFERENCE == | 
|  | 767 | ACPI_GET_OBJECT_TYPE(*sub_object_list)) | 
|  | 768 | && ((*sub_object_list)->reference.opcode == | 
|  | 769 | AML_INT_NAMEPATH_OP))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | name_found = TRUE; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | } else { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 772 | /* Look at the next element */ | 
|  | 773 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | sub_object_list++; | 
|  | 775 | } | 
|  | 776 | } | 
|  | 777 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 778 | temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 780 | /* Was a String type found? */ | 
|  | 781 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | if (name_found) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 783 | if (ACPI_GET_OBJECT_TYPE(*sub_object_list) == | 
|  | 784 | ACPI_TYPE_STRING) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | /* | 
|  | 786 | * The length String.Length field does not include the | 
|  | 787 | * terminating NULL, add 1 | 
|  | 788 | */ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 789 | temp_size_needed += ((acpi_size) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 790 | (*sub_object_list)->string. | 
|  | 791 | length + 1); | 
|  | 792 | } else { | 
|  | 793 | temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 795 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | /* | 
|  | 797 | * If no name was found, then this is a NULL, which is | 
|  | 798 | * translated as a u32 zero. | 
|  | 799 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | temp_size_needed += sizeof(u32); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } | 
|  | 802 |  | 
|  | 803 | /* Round up the size since each element must be aligned */ | 
|  | 804 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 805 | temp_size_needed = ACPI_ROUND_UP_to_64_bITS(temp_size_needed); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 807 | /* Point to the next union acpi_operand_object */ | 
|  | 808 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | top_object_list++; | 
|  | 810 | } | 
|  | 811 |  | 
|  | 812 | /* | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 813 | * Adding an extra element to the end of the list, essentially a | 
|  | 814 | * NULL terminator | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 816 | *buffer_size_needed = | 
|  | 817 | temp_size_needed + sizeof(struct acpi_pci_routing_table); | 
|  | 818 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |