Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: rsio - IO and DMA 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acresrc.h> |
| 46 | |
| 47 | #define _COMPONENT ACPI_RESOURCES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | ACPI_MODULE_NAME("rsio") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | /******************************************************************************* |
| 51 | * |
| 52 | * FUNCTION: acpi_rs_io_resource |
| 53 | * |
| 54 | * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte |
| 55 | * stream |
| 56 | * bytes_consumed - Pointer to where the number of bytes |
| 57 | * consumed the byte_stream_buffer is |
| 58 | * returned |
| 59 | * output_buffer - Pointer to the return data buffer |
| 60 | * structure_size - Pointer to where the number of bytes |
| 61 | * in the return data struct is returned |
| 62 | * |
| 63 | * RETURN: Status |
| 64 | * |
| 65 | * DESCRIPTION: Take the resource byte stream and fill out the appropriate |
| 66 | * structure pointed to by the output_buffer. Return the |
| 67 | * number of bytes consumed from the byte stream. |
| 68 | * |
| 69 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | acpi_rs_io_resource(u8 * byte_stream_buffer, |
| 72 | acpi_size * bytes_consumed, |
| 73 | u8 ** output_buffer, acpi_size * structure_size) |
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 | u8 *buffer = byte_stream_buffer; |
| 76 | struct acpi_resource *output_struct = (void *)*output_buffer; |
| 77 | u16 temp16 = 0; |
| 78 | u8 temp8 = 0; |
| 79 | acpi_size struct_size = ACPI_SIZEOF_RESOURCE(struct acpi_resource_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | ACPI_FUNCTION_TRACE("rs_io_resource"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 83 | /* The number of bytes consumed are Constant */ |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | *bytes_consumed = 8; |
| 86 | |
| 87 | output_struct->id = ACPI_RSTYPE_IO; |
| 88 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 89 | /* Check Decode */ |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | buffer += 1; |
| 92 | temp8 = *buffer; |
| 93 | |
| 94 | output_struct->data.io.io_decode = temp8 & 0x01; |
| 95 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 96 | /* Check min_base Address */ |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | buffer += 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | output_struct->data.io.min_base_address = temp16; |
| 102 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 103 | /* Check max_base Address */ |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | buffer += 2; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | output_struct->data.io.max_base_address = temp16; |
| 109 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 110 | /* Check Base alignment */ |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | buffer += 2; |
| 113 | temp8 = *buffer; |
| 114 | |
| 115 | output_struct->data.io.alignment = temp8; |
| 116 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 117 | /* Check range_length */ |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | buffer += 1; |
| 120 | temp8 = *buffer; |
| 121 | |
| 122 | output_struct->data.io.range_length = temp8; |
| 123 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 124 | /* Set the Length parameter */ |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | output_struct->length = (u32) struct_size; |
| 127 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 128 | /* Return the final size of the structure */ |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | *structure_size = struct_size; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /******************************************************************************* |
| 135 | * |
| 136 | * FUNCTION: acpi_rs_fixed_io_resource |
| 137 | * |
| 138 | * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte |
| 139 | * stream |
| 140 | * bytes_consumed - Pointer to where the number of bytes |
| 141 | * consumed the byte_stream_buffer is |
| 142 | * returned |
| 143 | * output_buffer - Pointer to the return data buffer |
| 144 | * structure_size - Pointer to where the number of bytes |
| 145 | * in the return data struct is returned |
| 146 | * |
| 147 | * RETURN: Status |
| 148 | * |
| 149 | * DESCRIPTION: Take the resource byte stream and fill out the appropriate |
| 150 | * structure pointed to by the output_buffer. Return the |
| 151 | * number of bytes consumed from the byte stream. |
| 152 | * |
| 153 | ******************************************************************************/ |
| 154 | |
| 155 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | acpi_rs_fixed_io_resource(u8 * byte_stream_buffer, |
| 157 | acpi_size * bytes_consumed, |
| 158 | u8 ** output_buffer, acpi_size * structure_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | u8 *buffer = byte_stream_buffer; |
| 161 | struct acpi_resource *output_struct = (void *)*output_buffer; |
| 162 | u16 temp16 = 0; |
| 163 | u8 temp8 = 0; |
| 164 | acpi_size struct_size = |
| 165 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | ACPI_FUNCTION_TRACE("rs_fixed_io_resource"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 169 | /* The number of bytes consumed are Constant */ |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | *bytes_consumed = 4; |
| 172 | |
| 173 | output_struct->id = ACPI_RSTYPE_FIXED_IO; |
| 174 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 175 | /* Check Range Base Address */ |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | buffer += 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | output_struct->data.fixed_io.base_address = temp16; |
| 181 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 182 | /* Check range_length */ |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | buffer += 2; |
| 185 | temp8 = *buffer; |
| 186 | |
| 187 | output_struct->data.fixed_io.range_length = temp8; |
| 188 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 189 | /* Set the Length parameter */ |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | output_struct->length = (u32) struct_size; |
| 192 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 193 | /* Return the final size of the structure */ |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | *structure_size = struct_size; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | /******************************************************************************* |
| 200 | * |
| 201 | * FUNCTION: acpi_rs_io_stream |
| 202 | * |
| 203 | * PARAMETERS: linked_list - Pointer to the resource linked list |
| 204 | * output_buffer - Pointer to the user's return buffer |
| 205 | * bytes_consumed - Pointer to where the number of bytes |
| 206 | * used in the output_buffer is returned |
| 207 | * |
| 208 | * RETURN: Status |
| 209 | * |
| 210 | * DESCRIPTION: Take the linked list resource structure and fills in the |
| 211 | * the appropriate bytes in a byte stream |
| 212 | * |
| 213 | ******************************************************************************/ |
| 214 | |
| 215 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | acpi_rs_io_stream(struct acpi_resource *linked_list, |
| 217 | u8 ** output_buffer, acpi_size * bytes_consumed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | u8 *buffer = *output_buffer; |
| 220 | u16 temp16 = 0; |
| 221 | u8 temp8 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | ACPI_FUNCTION_TRACE("rs_io_stream"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 225 | /* The descriptor field is static */ |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | *buffer = 0x47; |
| 228 | buffer += 1; |
| 229 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 230 | /* Io Information Byte */ |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | temp8 = (u8) (linked_list->data.io.io_decode & 0x01); |
| 233 | |
| 234 | *buffer = temp8; |
| 235 | buffer += 1; |
| 236 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 237 | /* Set the Range minimum base address */ |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | temp16 = (u16) linked_list->data.io.min_base_address; |
| 240 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | ACPI_MOVE_16_TO_16(buffer, &temp16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | buffer += 2; |
| 243 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 244 | /* Set the Range maximum base address */ |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | temp16 = (u16) linked_list->data.io.max_base_address; |
| 247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | ACPI_MOVE_16_TO_16(buffer, &temp16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | buffer += 2; |
| 250 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 251 | /* Set the base alignment */ |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | temp8 = (u8) linked_list->data.io.alignment; |
| 254 | |
| 255 | *buffer = temp8; |
| 256 | buffer += 1; |
| 257 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 258 | /* Set the range length */ |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | temp8 = (u8) linked_list->data.io.range_length; |
| 261 | |
| 262 | *buffer = temp8; |
| 263 | buffer += 1; |
| 264 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 265 | /* Return the number of bytes consumed in this operation */ |
| 266 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer); |
| 268 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /******************************************************************************* |
| 272 | * |
| 273 | * FUNCTION: acpi_rs_fixed_io_stream |
| 274 | * |
| 275 | * PARAMETERS: linked_list - Pointer to the resource linked list |
| 276 | * output_buffer - Pointer to the user's return buffer |
| 277 | * bytes_consumed - Pointer to where the number of bytes |
| 278 | * used in the output_buffer is returned |
| 279 | * |
| 280 | * RETURN: Status |
| 281 | * |
| 282 | * DESCRIPTION: Take the linked list resource structure and fills in the |
| 283 | * the appropriate bytes in a byte stream |
| 284 | * |
| 285 | ******************************************************************************/ |
| 286 | |
| 287 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | acpi_rs_fixed_io_stream(struct acpi_resource *linked_list, |
| 289 | u8 ** output_buffer, acpi_size * bytes_consumed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | u8 *buffer = *output_buffer; |
| 292 | u16 temp16 = 0; |
| 293 | u8 temp8 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 295 | ACPI_FUNCTION_TRACE("rs_fixed_io_stream"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 297 | /* The descriptor field is static */ |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | *buffer = 0x4B; |
| 300 | |
| 301 | buffer += 1; |
| 302 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 303 | /* Set the Range base address */ |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | temp16 = (u16) linked_list->data.fixed_io.base_address; |
| 306 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | ACPI_MOVE_16_TO_16(buffer, &temp16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | buffer += 2; |
| 309 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 310 | /* Set the range length */ |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | temp8 = (u8) linked_list->data.fixed_io.range_length; |
| 313 | |
| 314 | *buffer = temp8; |
| 315 | buffer += 1; |
| 316 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 317 | /* Return the number of bytes consumed in this operation */ |
| 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer); |
| 320 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | /******************************************************************************* |
| 324 | * |
| 325 | * FUNCTION: acpi_rs_dma_resource |
| 326 | * |
| 327 | * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte |
| 328 | * stream |
| 329 | * bytes_consumed - Pointer to where the number of bytes |
| 330 | * consumed the byte_stream_buffer is |
| 331 | * returned |
| 332 | * output_buffer - Pointer to the return data buffer |
| 333 | * structure_size - Pointer to where the number of bytes |
| 334 | * in the return data struct is returned |
| 335 | * |
| 336 | * RETURN: Status |
| 337 | * |
| 338 | * DESCRIPTION: Take the resource byte stream and fill out the appropriate |
| 339 | * structure pointed to by the output_buffer. Return the |
| 340 | * number of bytes consumed from the byte stream. |
| 341 | * |
| 342 | ******************************************************************************/ |
| 343 | |
| 344 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | acpi_rs_dma_resource(u8 * byte_stream_buffer, |
| 346 | acpi_size * bytes_consumed, |
| 347 | u8 ** output_buffer, acpi_size * structure_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 349 | u8 *buffer = byte_stream_buffer; |
| 350 | struct acpi_resource *output_struct = (void *)*output_buffer; |
| 351 | u8 temp8 = 0; |
| 352 | u8 index; |
| 353 | u8 i; |
| 354 | acpi_size struct_size = ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 356 | ACPI_FUNCTION_TRACE("rs_dma_resource"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 358 | /* The number of bytes consumed are Constant */ |
| 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | *bytes_consumed = 3; |
| 361 | output_struct->id = ACPI_RSTYPE_DMA; |
| 362 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 363 | /* Point to the 8-bits of Byte 1 */ |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | buffer += 1; |
| 366 | temp8 = *buffer; |
| 367 | |
| 368 | /* Decode the DMA channel bits */ |
| 369 | |
| 370 | for (i = 0, index = 0; index < 8; index++) { |
| 371 | if ((temp8 >> index) & 0x01) { |
| 372 | output_struct->data.dma.channels[i] = index; |
| 373 | i++; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /* Zero DMA channels is valid */ |
| 378 | |
| 379 | output_struct->data.dma.number_of_channels = i; |
| 380 | if (i > 0) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 381 | /* Calculate the structure size based upon the number of interrupts */ |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | struct_size += ((acpi_size) i - 1) * 4; |
| 384 | } |
| 385 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 386 | /* Point to Byte 2 */ |
| 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | buffer += 1; |
| 389 | temp8 = *buffer; |
| 390 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 391 | /* Check for transfer preference (Bits[1:0]) */ |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | output_struct->data.dma.transfer = temp8 & 0x03; |
| 394 | |
| 395 | if (0x03 == output_struct->data.dma.transfer) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 397 | "Invalid DMA.Transfer preference (3)\n")); |
| 398 | return_ACPI_STATUS(AE_BAD_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 401 | /* Get bus master preference (Bit[2]) */ |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01; |
| 404 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 405 | /* Get channel speed support (Bits[6:5]) */ |
| 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | output_struct->data.dma.type = (temp8 >> 5) & 0x03; |
| 408 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 409 | /* Set the Length parameter */ |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | output_struct->length = (u32) struct_size; |
| 412 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 413 | /* Return the final size of the structure */ |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | *structure_size = struct_size; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /******************************************************************************* |
| 420 | * |
| 421 | * FUNCTION: acpi_rs_dma_stream |
| 422 | * |
| 423 | * PARAMETERS: linked_list - Pointer to the resource linked list |
| 424 | * output_buffer - Pointer to the user's return buffer |
| 425 | * bytes_consumed - Pointer to where the number of bytes |
| 426 | * used in the output_buffer is returned |
| 427 | * |
| 428 | * RETURN: Status |
| 429 | * |
| 430 | * DESCRIPTION: Take the linked list resource structure and fills in the |
| 431 | * the appropriate bytes in a byte stream |
| 432 | * |
| 433 | ******************************************************************************/ |
| 434 | |
| 435 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | acpi_rs_dma_stream(struct acpi_resource *linked_list, |
| 437 | u8 ** output_buffer, acpi_size * bytes_consumed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | u8 *buffer = *output_buffer; |
| 440 | u16 temp16 = 0; |
| 441 | u8 temp8 = 0; |
| 442 | u8 index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | ACPI_FUNCTION_TRACE("rs_dma_stream"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 446 | /* The descriptor field is static */ |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | *buffer = 0x2A; |
| 449 | buffer += 1; |
| 450 | temp8 = 0; |
| 451 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 452 | /* Loop through all of the Channels and set the mask bits */ |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | for (index = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 455 | index < linked_list->data.dma.number_of_channels; index++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | temp16 = (u16) linked_list->data.dma.channels[index]; |
| 457 | temp8 |= 0x1 << temp16; |
| 458 | } |
| 459 | |
| 460 | *buffer = temp8; |
| 461 | buffer += 1; |
| 462 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 463 | /* Set the DMA Info */ |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5); |
| 466 | temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2); |
| 467 | temp8 |= (linked_list->data.dma.transfer & 0x03); |
| 468 | |
| 469 | *buffer = temp8; |
| 470 | buffer += 1; |
| 471 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 472 | /* Return the number of bytes consumed in this operation */ |
| 473 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer); |
| 475 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |