1 /*******************************************************************************
3 * Module Name: rsio - IO and DMA resource descriptors
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsio")
52 /*******************************************************************************
54 * FUNCTION: acpi_rs_io_resource
56 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
58 * bytes_consumed - Pointer to where the number of bytes
59 * consumed the byte_stream_buffer is
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
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.
71 ******************************************************************************/
75 u8 *byte_stream_buffer,
76 acpi_size *bytes_consumed,
78 acpi_size *structure_size)
80 u8 *buffer = byte_stream_buffer;
81 struct acpi_resource *output_struct = (void *) *output_buffer;
84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
85 struct acpi_resource_io);
88 ACPI_FUNCTION_TRACE ("rs_io_resource");
91 /* The number of bytes consumed are Constant */
95 output_struct->id = ACPI_RSTYPE_IO;
102 output_struct->data.io.io_decode = temp8 & 0x01;
104 /* Check min_base Address */
107 ACPI_MOVE_16_TO_16 (&temp16, buffer);
109 output_struct->data.io.min_base_address = temp16;
111 /* Check max_base Address */
114 ACPI_MOVE_16_TO_16 (&temp16, buffer);
116 output_struct->data.io.max_base_address = temp16;
118 /* Check Base alignment */
123 output_struct->data.io.alignment = temp8;
125 /* Check range_length */
130 output_struct->data.io.range_length = temp8;
132 /* Set the Length parameter */
134 output_struct->length = (u32) struct_size;
136 /* Return the final size of the structure */
138 *structure_size = struct_size;
139 return_ACPI_STATUS (AE_OK);
143 /*******************************************************************************
145 * FUNCTION: acpi_rs_fixed_io_resource
147 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
149 * bytes_consumed - Pointer to where the number of bytes
150 * consumed the byte_stream_buffer is
152 * output_buffer - Pointer to the return data buffer
153 * structure_size - Pointer to where the number of bytes
154 * in the return data struct is returned
158 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
159 * structure pointed to by the output_buffer. Return the
160 * number of bytes consumed from the byte stream.
162 ******************************************************************************/
165 acpi_rs_fixed_io_resource (
166 u8 *byte_stream_buffer,
167 acpi_size *bytes_consumed,
169 acpi_size *structure_size)
171 u8 *buffer = byte_stream_buffer;
172 struct acpi_resource *output_struct = (void *) *output_buffer;
175 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
176 struct acpi_resource_fixed_io);
179 ACPI_FUNCTION_TRACE ("rs_fixed_io_resource");
182 /* The number of bytes consumed are Constant */
186 output_struct->id = ACPI_RSTYPE_FIXED_IO;
188 /* Check Range Base Address */
191 ACPI_MOVE_16_TO_16 (&temp16, buffer);
193 output_struct->data.fixed_io.base_address = temp16;
195 /* Check range_length */
200 output_struct->data.fixed_io.range_length = temp8;
202 /* Set the Length parameter */
204 output_struct->length = (u32) struct_size;
206 /* Return the final size of the structure */
208 *structure_size = struct_size;
209 return_ACPI_STATUS (AE_OK);
213 /*******************************************************************************
215 * FUNCTION: acpi_rs_io_stream
217 * PARAMETERS: linked_list - Pointer to the resource linked list
218 * output_buffer - Pointer to the user's return buffer
219 * bytes_consumed - Pointer to where the number of bytes
220 * used in the output_buffer is returned
224 * DESCRIPTION: Take the linked list resource structure and fills in the
225 * the appropriate bytes in a byte stream
227 ******************************************************************************/
231 struct acpi_resource *linked_list,
233 acpi_size *bytes_consumed)
235 u8 *buffer = *output_buffer;
240 ACPI_FUNCTION_TRACE ("rs_io_stream");
243 /* The descriptor field is static */
248 /* Io Information Byte */
250 temp8 = (u8) (linked_list->data.io.io_decode & 0x01);
255 /* Set the Range minimum base address */
257 temp16 = (u16) linked_list->data.io.min_base_address;
259 ACPI_MOVE_16_TO_16 (buffer, &temp16);
262 /* Set the Range maximum base address */
264 temp16 = (u16) linked_list->data.io.max_base_address;
266 ACPI_MOVE_16_TO_16 (buffer, &temp16);
269 /* Set the base alignment */
271 temp8 = (u8) linked_list->data.io.alignment;
276 /* Set the range length */
278 temp8 = (u8) linked_list->data.io.range_length;
283 /* Return the number of bytes consumed in this operation */
285 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
286 return_ACPI_STATUS (AE_OK);
290 /*******************************************************************************
292 * FUNCTION: acpi_rs_fixed_io_stream
294 * PARAMETERS: linked_list - Pointer to the resource linked list
295 * output_buffer - Pointer to the user's return buffer
296 * bytes_consumed - Pointer to where the number of bytes
297 * used in the output_buffer is returned
301 * DESCRIPTION: Take the linked list resource structure and fills in the
302 * the appropriate bytes in a byte stream
304 ******************************************************************************/
307 acpi_rs_fixed_io_stream (
308 struct acpi_resource *linked_list,
310 acpi_size *bytes_consumed)
312 u8 *buffer = *output_buffer;
317 ACPI_FUNCTION_TRACE ("rs_fixed_io_stream");
320 /* The descriptor field is static */
326 /* Set the Range base address */
328 temp16 = (u16) linked_list->data.fixed_io.base_address;
330 ACPI_MOVE_16_TO_16 (buffer, &temp16);
333 /* Set the range length */
335 temp8 = (u8) linked_list->data.fixed_io.range_length;
340 /* Return the number of bytes consumed in this operation */
342 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
343 return_ACPI_STATUS (AE_OK);
347 /*******************************************************************************
349 * FUNCTION: acpi_rs_dma_resource
351 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
353 * bytes_consumed - Pointer to where the number of bytes
354 * consumed the byte_stream_buffer is
356 * output_buffer - Pointer to the return data buffer
357 * structure_size - Pointer to where the number of bytes
358 * in the return data struct is returned
362 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
363 * structure pointed to by the output_buffer. Return the
364 * number of bytes consumed from the byte stream.
366 ******************************************************************************/
369 acpi_rs_dma_resource (
370 u8 *byte_stream_buffer,
371 acpi_size *bytes_consumed,
373 acpi_size *structure_size)
375 u8 *buffer = byte_stream_buffer;
376 struct acpi_resource *output_struct = (void *) *output_buffer;
380 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
381 struct acpi_resource_dma);
384 ACPI_FUNCTION_TRACE ("rs_dma_resource");
387 /* The number of bytes consumed are Constant */
390 output_struct->id = ACPI_RSTYPE_DMA;
392 /* Point to the 8-bits of Byte 1 */
397 /* Decode the DMA channel bits */
399 for (i = 0, index = 0; index < 8; index++) {
400 if ((temp8 >> index) & 0x01) {
401 output_struct->data.dma.channels[i] = index;
406 /* Zero DMA channels is valid */
408 output_struct->data.dma.number_of_channels = i;
410 /* Calculate the structure size based upon the number of interrupts */
412 struct_size += ((acpi_size) i - 1) * 4;
415 /* Point to Byte 2 */
420 /* Check for transfer preference (Bits[1:0]) */
422 output_struct->data.dma.transfer = temp8 & 0x03;
424 if (0x03 == output_struct->data.dma.transfer) {
425 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
426 "Invalid DMA.Transfer preference (3)\n"));
427 return_ACPI_STATUS (AE_BAD_DATA);
430 /* Get bus master preference (Bit[2]) */
432 output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01;
434 /* Get channel speed support (Bits[6:5]) */
436 output_struct->data.dma.type = (temp8 >> 5) & 0x03;
438 /* Set the Length parameter */
440 output_struct->length = (u32) struct_size;
442 /* Return the final size of the structure */
444 *structure_size = struct_size;
445 return_ACPI_STATUS (AE_OK);
449 /*******************************************************************************
451 * FUNCTION: acpi_rs_dma_stream
453 * PARAMETERS: linked_list - Pointer to the resource linked list
454 * output_buffer - Pointer to the user's return buffer
455 * bytes_consumed - Pointer to where the number of bytes
456 * used in the output_buffer is returned
460 * DESCRIPTION: Take the linked list resource structure and fills in the
461 * the appropriate bytes in a byte stream
463 ******************************************************************************/
467 struct acpi_resource *linked_list,
469 acpi_size *bytes_consumed)
471 u8 *buffer = *output_buffer;
477 ACPI_FUNCTION_TRACE ("rs_dma_stream");
480 /* The descriptor field is static */
486 /* Loop through all of the Channels and set the mask bits */
489 index < linked_list->data.dma.number_of_channels;
491 temp16 = (u16) linked_list->data.dma.channels[index];
492 temp8 |= 0x1 << temp16;
498 /* Set the DMA Info */
500 temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5);
501 temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2);
502 temp8 |= (linked_list->data.dma.transfer & 0x03);
507 /* Return the number of bytes consumed in this operation */
509 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
510 return_ACPI_STATUS (AE_OK);