| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 | * | 
|  | 3 | * Module Name: rsirq - IRQ resource descriptors | 
|  | 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 |  | 
|  | 44 |  | 
|  | 45 | #include <acpi/acpi.h> | 
|  | 46 | #include <acpi/acresrc.h> | 
|  | 47 |  | 
|  | 48 | #define _COMPONENT          ACPI_RESOURCES | 
|  | 49 | ACPI_MODULE_NAME    ("rsirq") | 
|  | 50 |  | 
|  | 51 |  | 
|  | 52 | /******************************************************************************* | 
|  | 53 | * | 
|  | 54 | * FUNCTION:    acpi_rs_irq_resource | 
|  | 55 | * | 
|  | 56 | * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte | 
|  | 57 | *                                        stream | 
|  | 58 | *              bytes_consumed          - Pointer to where the number of bytes | 
|  | 59 | *                                        consumed the byte_stream_buffer is | 
|  | 60 | *                                        returned | 
|  | 61 | *              output_buffer           - Pointer to the return data buffer | 
|  | 62 | *              structure_size          - Pointer to where the number of bytes | 
|  | 63 | *                                        in the return data struct is returned | 
|  | 64 | * | 
|  | 65 | * RETURN:      Status | 
|  | 66 | * | 
|  | 67 | * DESCRIPTION: Take the resource byte stream and fill out the appropriate | 
|  | 68 | *              structure pointed to by the output_buffer. Return the | 
|  | 69 | *              number of bytes consumed from the byte stream. | 
|  | 70 | * | 
|  | 71 | ******************************************************************************/ | 
|  | 72 |  | 
|  | 73 | acpi_status | 
|  | 74 | acpi_rs_irq_resource ( | 
|  | 75 | u8                              *byte_stream_buffer, | 
|  | 76 | acpi_size                       *bytes_consumed, | 
|  | 77 | u8                              **output_buffer, | 
|  | 78 | acpi_size                       *structure_size) | 
|  | 79 | { | 
|  | 80 | u8                              *buffer = byte_stream_buffer; | 
|  | 81 | struct acpi_resource            *output_struct = (void *) *output_buffer; | 
|  | 82 | u16                             temp16 = 0; | 
|  | 83 | u8                              temp8 = 0; | 
|  | 84 | u8                              index; | 
|  | 85 | u8                              i; | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 86 | acpi_size                       struct_size = ACPI_SIZEOF_RESOURCE ( | 
|  | 87 | struct acpi_resource_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 |  | 
|  | 89 |  | 
|  | 90 | ACPI_FUNCTION_TRACE ("rs_irq_resource"); | 
|  | 91 |  | 
|  | 92 |  | 
|  | 93 | /* | 
|  | 94 | * The number of bytes consumed are contained in the descriptor | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 95 | * (Bits:0-1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ | 
|  | 97 | temp8 = *buffer; | 
|  | 98 | *bytes_consumed = (temp8 & 0x03) + 1; | 
|  | 99 | output_struct->id = ACPI_RSTYPE_IRQ; | 
|  | 100 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 101 | /* Point to the 16-bits of Bytes 1 and 2 */ | 
|  | 102 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | buffer += 1; | 
|  | 104 | ACPI_MOVE_16_TO_16 (&temp16, buffer); | 
|  | 105 |  | 
|  | 106 | output_struct->data.irq.number_of_interrupts = 0; | 
|  | 107 |  | 
|  | 108 | /* Decode the IRQ bits */ | 
|  | 109 |  | 
|  | 110 | for (i = 0, index = 0; index < 16; index++) { | 
|  | 111 | if ((temp16 >> index) & 0x01) { | 
|  | 112 | output_struct->data.irq.interrupts[i] = index; | 
|  | 113 | i++; | 
|  | 114 | } | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | /* Zero interrupts is valid */ | 
|  | 118 |  | 
|  | 119 | output_struct->data.irq.number_of_interrupts = i; | 
|  | 120 | if (i > 0) { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 121 | /* Calculate the structure size based upon the number of interrupts */ | 
|  | 122 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | struct_size += ((acpi_size) i - 1) * 4; | 
|  | 124 | } | 
|  | 125 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 126 | /* Point to Byte 3 if it is used */ | 
|  | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | if (4 == *bytes_consumed) { | 
|  | 129 | buffer += 2; | 
|  | 130 | temp8 = *buffer; | 
|  | 131 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 132 | /* Check for HE, LL interrupts */ | 
|  | 133 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | switch (temp8 & 0x09) { | 
|  | 135 | case 0x01: /* HE */ | 
|  | 136 | output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE; | 
|  | 137 | output_struct->data.irq.active_high_low = ACPI_ACTIVE_HIGH; | 
|  | 138 | break; | 
|  | 139 |  | 
|  | 140 | case 0x08: /* LL */ | 
|  | 141 | output_struct->data.irq.edge_level = ACPI_LEVEL_SENSITIVE; | 
|  | 142 | output_struct->data.irq.active_high_low = ACPI_ACTIVE_LOW; | 
|  | 143 | break; | 
|  | 144 |  | 
|  | 145 | default: | 
|  | 146 | /* | 
|  | 147 | * Only _LL and _HE polarity/trigger interrupts | 
|  | 148 | * are allowed (ACPI spec, section "IRQ Format") | 
|  | 149 | * so 0x00 and 0x09 are illegal. | 
|  | 150 | */ | 
|  | 151 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 152 | "Invalid interrupt polarity/trigger in resource list, %X\n", | 
|  | 153 | temp8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | return_ACPI_STATUS (AE_BAD_DATA); | 
|  | 155 | } | 
|  | 156 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 157 | /* Check for sharable */ | 
|  | 158 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01; | 
|  | 160 | } | 
|  | 161 | else { | 
|  | 162 | /* | 
|  | 163 | * Assume Edge Sensitive, Active High, Non-Sharable | 
|  | 164 | * per ACPI Specification | 
|  | 165 | */ | 
|  | 166 | output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE; | 
|  | 167 | output_struct->data.irq.active_high_low = ACPI_ACTIVE_HIGH; | 
|  | 168 | output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE; | 
|  | 169 | } | 
|  | 170 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 171 | /* Set the Length parameter */ | 
|  | 172 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | output_struct->length = (u32) struct_size; | 
|  | 174 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 175 | /* Return the final size of the structure */ | 
|  | 176 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | *structure_size = struct_size; | 
|  | 178 | return_ACPI_STATUS (AE_OK); | 
|  | 179 | } | 
|  | 180 |  | 
|  | 181 |  | 
|  | 182 | /******************************************************************************* | 
|  | 183 | * | 
|  | 184 | * FUNCTION:    acpi_rs_irq_stream | 
|  | 185 | * | 
|  | 186 | * PARAMETERS:  linked_list             - Pointer to the resource linked list | 
|  | 187 | *              output_buffer           - Pointer to the user's return buffer | 
|  | 188 | *              bytes_consumed          - Pointer to where the number of bytes | 
|  | 189 | *                                        used in the output_buffer is returned | 
|  | 190 | * | 
|  | 191 | * RETURN:      Status | 
|  | 192 | * | 
|  | 193 | * DESCRIPTION: Take the linked list resource structure and fills in the | 
|  | 194 | *              the appropriate bytes in a byte stream | 
|  | 195 | * | 
|  | 196 | ******************************************************************************/ | 
|  | 197 |  | 
|  | 198 | acpi_status | 
|  | 199 | acpi_rs_irq_stream ( | 
|  | 200 | struct acpi_resource            *linked_list, | 
|  | 201 | u8                              **output_buffer, | 
|  | 202 | acpi_size                       *bytes_consumed) | 
|  | 203 | { | 
|  | 204 | u8                              *buffer = *output_buffer; | 
|  | 205 | u16                             temp16 = 0; | 
|  | 206 | u8                              temp8 = 0; | 
|  | 207 | u8                              index; | 
|  | 208 | u8                              IRqinfo_byte_needed; | 
|  | 209 |  | 
|  | 210 |  | 
|  | 211 | ACPI_FUNCTION_TRACE ("rs_irq_stream"); | 
|  | 212 |  | 
|  | 213 |  | 
|  | 214 | /* | 
|  | 215 | * The descriptor field is set based upon whether a third byte is | 
|  | 216 | * needed to contain the IRQ Information. | 
|  | 217 | */ | 
|  | 218 | if (ACPI_EDGE_SENSITIVE == linked_list->data.irq.edge_level && | 
|  | 219 | ACPI_ACTIVE_HIGH == linked_list->data.irq.active_high_low && | 
|  | 220 | ACPI_EXCLUSIVE == linked_list->data.irq.shared_exclusive) { | 
|  | 221 | *buffer = 0x22; | 
|  | 222 | IRqinfo_byte_needed = FALSE; | 
|  | 223 | } | 
|  | 224 | else { | 
|  | 225 | *buffer = 0x23; | 
|  | 226 | IRqinfo_byte_needed = TRUE; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | buffer += 1; | 
|  | 230 | temp16 = 0; | 
|  | 231 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 232 | /* Loop through all of the interrupts and set the mask bits */ | 
|  | 233 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | for(index = 0; | 
|  | 235 | index < linked_list->data.irq.number_of_interrupts; | 
|  | 236 | index++) { | 
|  | 237 | temp8 = (u8) linked_list->data.irq.interrupts[index]; | 
|  | 238 | temp16 |= 0x1 << temp8; | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | ACPI_MOVE_16_TO_16 (buffer, &temp16); | 
|  | 242 | buffer += 2; | 
|  | 243 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 244 | /* Set the IRQ Info byte if needed. */ | 
|  | 245 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (IRqinfo_byte_needed) { | 
|  | 247 | temp8 = 0; | 
|  | 248 | temp8 = (u8) ((linked_list->data.irq.shared_exclusive & | 
|  | 249 | 0x01) << 4); | 
|  | 250 |  | 
|  | 251 | if (ACPI_LEVEL_SENSITIVE == linked_list->data.irq.edge_level && | 
|  | 252 | ACPI_ACTIVE_LOW == linked_list->data.irq.active_high_low) { | 
|  | 253 | temp8 |= 0x08; | 
|  | 254 | } | 
|  | 255 | else { | 
|  | 256 | temp8 |= 0x01; | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | *buffer = temp8; | 
|  | 260 | buffer += 1; | 
|  | 261 | } | 
|  | 262 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 263 | /* Return the number of bytes consumed in this operation */ | 
|  | 264 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); | 
|  | 266 | return_ACPI_STATUS (AE_OK); | 
|  | 267 | } | 
|  | 268 |  | 
|  | 269 |  | 
|  | 270 | /******************************************************************************* | 
|  | 271 | * | 
|  | 272 | * FUNCTION:    acpi_rs_extended_irq_resource | 
|  | 273 | * | 
|  | 274 | * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte | 
|  | 275 | *                                        stream | 
|  | 276 | *              bytes_consumed          - Pointer to where the number of bytes | 
|  | 277 | *                                        consumed the byte_stream_buffer is | 
|  | 278 | *                                        returned | 
|  | 279 | *              output_buffer           - Pointer to the return data buffer | 
|  | 280 | *              structure_size          - Pointer to where the number of bytes | 
|  | 281 | *                                        in the return data struct is returned | 
|  | 282 | * | 
|  | 283 | * RETURN:      Status | 
|  | 284 | * | 
|  | 285 | * DESCRIPTION: Take the resource byte stream and fill out the appropriate | 
|  | 286 | *              structure pointed to by the output_buffer. Return the | 
|  | 287 | *              number of bytes consumed from the byte stream. | 
|  | 288 | * | 
|  | 289 | ******************************************************************************/ | 
|  | 290 |  | 
|  | 291 | acpi_status | 
|  | 292 | acpi_rs_extended_irq_resource ( | 
|  | 293 | u8                              *byte_stream_buffer, | 
|  | 294 | acpi_size                       *bytes_consumed, | 
|  | 295 | u8                              **output_buffer, | 
|  | 296 | acpi_size                       *structure_size) | 
|  | 297 | { | 
|  | 298 | u8                              *buffer = byte_stream_buffer; | 
|  | 299 | struct acpi_resource            *output_struct = (void *) *output_buffer; | 
|  | 300 | u16                             temp16 = 0; | 
|  | 301 | u8                              temp8 = 0; | 
|  | 302 | u8                              *temp_ptr; | 
|  | 303 | u8                              index; | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 304 | acpi_size                       struct_size = ACPI_SIZEOF_RESOURCE ( | 
|  | 305 | struct acpi_resource_ext_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 |  | 
|  | 307 |  | 
|  | 308 | ACPI_FUNCTION_TRACE ("rs_extended_irq_resource"); | 
|  | 309 |  | 
|  | 310 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 311 | /* Point past the Descriptor to get the number of bytes consumed */ | 
|  | 312 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | buffer += 1; | 
|  | 314 | ACPI_MOVE_16_TO_16 (&temp16, buffer); | 
|  | 315 |  | 
|  | 316 | /* Validate minimum descriptor length */ | 
|  | 317 |  | 
|  | 318 | if (temp16 < 6) { | 
|  | 319 | return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH); | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 | *bytes_consumed = temp16 + 3; | 
|  | 323 | output_struct->id = ACPI_RSTYPE_EXT_IRQ; | 
|  | 324 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 325 | /* Point to the Byte3 */ | 
|  | 326 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | buffer += 2; | 
|  | 328 | temp8 = *buffer; | 
|  | 329 |  | 
|  | 330 | output_struct->data.extended_irq.producer_consumer = temp8 & 0x01; | 
|  | 331 |  | 
|  | 332 | /* | 
|  | 333 | * Check for Interrupt Mode | 
|  | 334 | * | 
|  | 335 | * The definition of an Extended IRQ changed between ACPI spec v1.0b | 
|  | 336 | * and ACPI spec 2.0 (section 6.4.3.6 in both). | 
|  | 337 | * | 
|  | 338 | * - Edge/Level are defined opposite in the table vs the headers | 
|  | 339 | */ | 
|  | 340 | output_struct->data.extended_irq.edge_level = | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 341 | (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 343 | /* Check Interrupt Polarity */ | 
|  | 344 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1; | 
|  | 346 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 347 | /* Check for sharable */ | 
|  | 348 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01; | 
|  | 350 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 351 | /* Point to Byte4 (IRQ Table length) */ | 
|  | 352 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | buffer += 1; | 
|  | 354 | temp8 = *buffer; | 
|  | 355 |  | 
|  | 356 | /* Must have at least one IRQ */ | 
|  | 357 |  | 
|  | 358 | if (temp8 < 1) { | 
|  | 359 | return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH); | 
|  | 360 | } | 
|  | 361 |  | 
|  | 362 | output_struct->data.extended_irq.number_of_interrupts = temp8; | 
|  | 363 |  | 
|  | 364 | /* | 
|  | 365 | * Add any additional structure size to properly calculate | 
|  | 366 | * the next pointer at the end of this function | 
|  | 367 | */ | 
|  | 368 | struct_size += (temp8 - 1) * 4; | 
|  | 369 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 370 | /* Point to Byte5 (First IRQ Number) */ | 
|  | 371 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | buffer += 1; | 
|  | 373 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 374 | /* Cycle through every IRQ in the table */ | 
|  | 375 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | for (index = 0; index < temp8; index++) { | 
|  | 377 | ACPI_MOVE_32_TO_32 ( | 
|  | 378 | &output_struct->data.extended_irq.interrupts[index], buffer); | 
|  | 379 |  | 
|  | 380 | /* Point to the next IRQ */ | 
|  | 381 |  | 
|  | 382 | buffer += 4; | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | /* | 
|  | 386 | * This will leave us pointing to the Resource Source Index | 
|  | 387 | * If it is present, then save it off and calculate the | 
|  | 388 | * pointer to where the null terminated string goes: | 
|  | 389 | * Each Interrupt takes 32-bits + the 5 bytes of the | 
|  | 390 | * stream that are default. | 
|  | 391 | * | 
|  | 392 | * Note: Some resource descriptors will have an additional null, so | 
|  | 393 | * we add 1 to the length. | 
|  | 394 | */ | 
|  | 395 | if (*bytes_consumed > | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 396 | ((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) + | 
|  | 397 | (5 + 1)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | /* Dereference the Index */ | 
|  | 399 |  | 
|  | 400 | temp8 = *buffer; | 
|  | 401 | output_struct->data.extended_irq.resource_source.index = (u32) temp8; | 
|  | 402 |  | 
|  | 403 | /* Point to the String */ | 
|  | 404 |  | 
|  | 405 | buffer += 1; | 
|  | 406 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 407 | /* Point the String pointer to the end of this structure. */ | 
|  | 408 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | output_struct->data.extended_irq.resource_source.string_ptr = | 
|  | 410 | (char *)((char *) output_struct + struct_size); | 
|  | 411 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 412 | temp_ptr = (u8 *) | 
|  | 413 | output_struct->data.extended_irq.resource_source.string_ptr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 |  | 
|  | 415 | /* Copy the string into the buffer */ | 
|  | 416 |  | 
|  | 417 | index = 0; | 
|  | 418 | while (0x00 != *buffer) { | 
|  | 419 | *temp_ptr = *buffer; | 
|  | 420 |  | 
|  | 421 | temp_ptr += 1; | 
|  | 422 | buffer += 1; | 
|  | 423 | index += 1; | 
|  | 424 | } | 
|  | 425 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 426 | /* Add the terminating null */ | 
|  | 427 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | *temp_ptr = 0x00; | 
|  | 429 | output_struct->data.extended_irq.resource_source.string_length = index + 1; | 
|  | 430 |  | 
|  | 431 | /* | 
|  | 432 | * In order for the struct_size to fall on a 32-bit boundary, | 
|  | 433 | * calculate the length of the string and expand the | 
|  | 434 | * struct_size to the next 32-bit boundary. | 
|  | 435 | */ | 
|  | 436 | temp8 = (u8) (index + 1); | 
|  | 437 | struct_size += ACPI_ROUND_UP_to_32_bITS (temp8); | 
|  | 438 | } | 
|  | 439 | else { | 
|  | 440 | output_struct->data.extended_irq.resource_source.index = 0x00; | 
|  | 441 | output_struct->data.extended_irq.resource_source.string_length = 0; | 
|  | 442 | output_struct->data.extended_irq.resource_source.string_ptr = NULL; | 
|  | 443 | } | 
|  | 444 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 445 | /* Set the Length parameter */ | 
|  | 446 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | output_struct->length = (u32) struct_size; | 
|  | 448 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 449 | /* Return the final size of the structure */ | 
|  | 450 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | *structure_size = struct_size; | 
|  | 452 | return_ACPI_STATUS (AE_OK); | 
|  | 453 | } | 
|  | 454 |  | 
|  | 455 |  | 
|  | 456 | /******************************************************************************* | 
|  | 457 | * | 
|  | 458 | * FUNCTION:    acpi_rs_extended_irq_stream | 
|  | 459 | * | 
|  | 460 | * PARAMETERS:  linked_list             - Pointer to the resource linked list | 
|  | 461 | *              output_buffer           - Pointer to the user's return buffer | 
|  | 462 | *              bytes_consumed          - Pointer to where the number of bytes | 
|  | 463 | *                                        used in the output_buffer is returned | 
|  | 464 | * | 
|  | 465 | * RETURN:      Status | 
|  | 466 | * | 
|  | 467 | * DESCRIPTION: Take the linked list resource structure and fills in the | 
|  | 468 | *              the appropriate bytes in a byte stream | 
|  | 469 | * | 
|  | 470 | ******************************************************************************/ | 
|  | 471 |  | 
|  | 472 | acpi_status | 
|  | 473 | acpi_rs_extended_irq_stream ( | 
|  | 474 | struct acpi_resource            *linked_list, | 
|  | 475 | u8                              **output_buffer, | 
|  | 476 | acpi_size                       *bytes_consumed) | 
|  | 477 | { | 
|  | 478 | u8                              *buffer = *output_buffer; | 
|  | 479 | u16                             *length_field; | 
|  | 480 | u8                              temp8 = 0; | 
|  | 481 | u8                              index; | 
|  | 482 | char                            *temp_pointer = NULL; | 
|  | 483 |  | 
|  | 484 |  | 
|  | 485 | ACPI_FUNCTION_TRACE ("rs_extended_irq_stream"); | 
|  | 486 |  | 
|  | 487 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 488 | /* The descriptor field is static */ | 
|  | 489 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | *buffer = 0x89; | 
|  | 491 | buffer += 1; | 
|  | 492 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 493 | /* Set a pointer to the Length field - to be filled in later */ | 
|  | 494 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | length_field = ACPI_CAST_PTR (u16, buffer); | 
|  | 496 | buffer += 2; | 
|  | 497 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 498 | /* Set the Interrupt vector flags */ | 
|  | 499 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01); | 
|  | 501 | temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3); | 
|  | 502 |  | 
|  | 503 | /* | 
|  | 504 | * Set the Interrupt Mode | 
|  | 505 | * | 
|  | 506 | * The definition of an Extended IRQ changed between ACPI spec v1.0b | 
|  | 507 | * and ACPI spec 2.0 (section 6.4.3.6 in both).  This code does not | 
|  | 508 | * implement the more restrictive definition of 1.0b | 
|  | 509 | * | 
|  | 510 | * - Edge/Level are defined opposite in the table vs the headers | 
|  | 511 | */ | 
|  | 512 | if (ACPI_EDGE_SENSITIVE == linked_list->data.extended_irq.edge_level) { | 
|  | 513 | temp8 |= 0x2; | 
|  | 514 | } | 
|  | 515 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 516 | /* Set the Interrupt Polarity */ | 
|  | 517 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2); | 
|  | 519 |  | 
|  | 520 | *buffer = temp8; | 
|  | 521 | buffer += 1; | 
|  | 522 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 523 | /* Set the Interrupt table length */ | 
|  | 524 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts; | 
|  | 526 |  | 
|  | 527 | *buffer = temp8; | 
|  | 528 | buffer += 1; | 
|  | 529 |  | 
|  | 530 | for (index = 0; index < linked_list->data.extended_irq.number_of_interrupts; | 
|  | 531 | index++) { | 
|  | 532 | ACPI_MOVE_32_TO_32 (buffer, | 
|  | 533 | &linked_list->data.extended_irq.interrupts[index]); | 
|  | 534 | buffer += 4; | 
|  | 535 | } | 
|  | 536 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 537 | /* Resource Source Index and Resource Source are optional */ | 
|  | 538 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | if (0 != linked_list->data.extended_irq.resource_source.string_length) { | 
|  | 540 | *buffer = (u8) linked_list->data.extended_irq.resource_source.index; | 
|  | 541 | buffer += 1; | 
|  | 542 |  | 
|  | 543 | temp_pointer = (char *) buffer; | 
|  | 544 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 545 | /* Copy the string */ | 
|  | 546 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | ACPI_STRCPY (temp_pointer, | 
|  | 548 | linked_list->data.extended_irq.resource_source.string_ptr); | 
|  | 549 |  | 
|  | 550 | /* | 
|  | 551 | * Buffer needs to be set to the length of the sting + one for the | 
|  | 552 | * terminating null | 
|  | 553 | */ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 554 | buffer += (acpi_size) (ACPI_STRLEN ( | 
|  | 555 | linked_list->data.extended_irq.resource_source.string_ptr) + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } | 
|  | 557 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 558 | /* Return the number of bytes consumed in this operation */ | 
|  | 559 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); | 
|  | 561 |  | 
|  | 562 | /* | 
|  | 563 | * Set the length field to the number of bytes consumed | 
|  | 564 | * minus the header size (3 bytes) | 
|  | 565 | */ | 
|  | 566 | *length_field = (u16) (*bytes_consumed - 3); | 
|  | 567 | return_ACPI_STATUS (AE_OK); | 
|  | 568 | } | 
|  | 569 |  |