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 (struct acpi_resource_io);
87 ACPI_FUNCTION_TRACE ("rs_io_resource");
91 * The number of bytes consumed are Constant
95 output_struct->id = ACPI_RSTYPE_IO;
103 output_struct->data.io.io_decode = temp8 & 0x01;
106 * Check min_base Address
109 ACPI_MOVE_16_TO_16 (&temp16, buffer);
111 output_struct->data.io.min_base_address = temp16;
114 * Check max_base Address
117 ACPI_MOVE_16_TO_16 (&temp16, buffer);
119 output_struct->data.io.max_base_address = temp16;
122 * Check Base alignment
127 output_struct->data.io.alignment = temp8;
135 output_struct->data.io.range_length = temp8;
138 * Set the Length parameter
140 output_struct->length = (u32) struct_size;
143 * Return the final size of the structure
145 *structure_size = struct_size;
146 return_ACPI_STATUS (AE_OK);
150 /*******************************************************************************
152 * FUNCTION: acpi_rs_fixed_io_resource
154 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
156 * bytes_consumed - Pointer to where the number of bytes
157 * consumed the byte_stream_buffer is
159 * output_buffer - Pointer to the return data buffer
160 * structure_size - Pointer to where the number of bytes
161 * in the return data struct is returned
165 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
166 * structure pointed to by the output_buffer. Return the
167 * number of bytes consumed from the byte stream.
169 ******************************************************************************/
172 acpi_rs_fixed_io_resource (
173 u8 *byte_stream_buffer,
174 acpi_size *bytes_consumed,
176 acpi_size *structure_size)
178 u8 *buffer = byte_stream_buffer;
179 struct acpi_resource *output_struct = (void *) *output_buffer;
182 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_io);
185 ACPI_FUNCTION_TRACE ("rs_fixed_io_resource");
189 * The number of bytes consumed are Constant
193 output_struct->id = ACPI_RSTYPE_FIXED_IO;
196 * Check Range Base Address
199 ACPI_MOVE_16_TO_16 (&temp16, buffer);
201 output_struct->data.fixed_io.base_address = temp16;
209 output_struct->data.fixed_io.range_length = temp8;
212 * Set the Length parameter
214 output_struct->length = (u32) struct_size;
217 * Return the final size of the structure
219 *structure_size = struct_size;
220 return_ACPI_STATUS (AE_OK);
224 /*******************************************************************************
226 * FUNCTION: acpi_rs_io_stream
228 * PARAMETERS: linked_list - Pointer to the resource linked list
229 * output_buffer - Pointer to the user's return buffer
230 * bytes_consumed - Pointer to where the number of bytes
231 * used in the output_buffer is returned
235 * DESCRIPTION: Take the linked list resource structure and fills in the
236 * the appropriate bytes in a byte stream
238 ******************************************************************************/
242 struct acpi_resource *linked_list,
244 acpi_size *bytes_consumed)
246 u8 *buffer = *output_buffer;
251 ACPI_FUNCTION_TRACE ("rs_io_stream");
255 * The descriptor field is static
261 * Io Information Byte
263 temp8 = (u8) (linked_list->data.io.io_decode & 0x01);
269 * Set the Range minimum base address
271 temp16 = (u16) linked_list->data.io.min_base_address;
273 ACPI_MOVE_16_TO_16 (buffer, &temp16);
277 * Set the Range maximum base address
279 temp16 = (u16) linked_list->data.io.max_base_address;
281 ACPI_MOVE_16_TO_16 (buffer, &temp16);
285 * Set the base alignment
287 temp8 = (u8) linked_list->data.io.alignment;
293 * Set the range length
295 temp8 = (u8) linked_list->data.io.range_length;
301 * Return the number of bytes consumed in this operation
303 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
304 return_ACPI_STATUS (AE_OK);
308 /*******************************************************************************
310 * FUNCTION: acpi_rs_fixed_io_stream
312 * PARAMETERS: linked_list - Pointer to the resource linked list
313 * output_buffer - Pointer to the user's return buffer
314 * bytes_consumed - Pointer to where the number of bytes
315 * used in the output_buffer is returned
319 * DESCRIPTION: Take the linked list resource structure and fills in the
320 * the appropriate bytes in a byte stream
322 ******************************************************************************/
325 acpi_rs_fixed_io_stream (
326 struct acpi_resource *linked_list,
328 acpi_size *bytes_consumed)
330 u8 *buffer = *output_buffer;
335 ACPI_FUNCTION_TRACE ("rs_fixed_io_stream");
339 * The descriptor field is static
346 * Set the Range base address
348 temp16 = (u16) linked_list->data.fixed_io.base_address;
350 ACPI_MOVE_16_TO_16 (buffer, &temp16);
354 * Set the range length
356 temp8 = (u8) linked_list->data.fixed_io.range_length;
362 * Return the number of bytes consumed in this operation
364 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
365 return_ACPI_STATUS (AE_OK);
369 /*******************************************************************************
371 * FUNCTION: acpi_rs_dma_resource
373 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
375 * bytes_consumed - Pointer to where the number of bytes
376 * consumed the byte_stream_buffer is
378 * output_buffer - Pointer to the return data buffer
379 * structure_size - Pointer to where the number of bytes
380 * in the return data struct is returned
384 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
385 * structure pointed to by the output_buffer. Return the
386 * number of bytes consumed from the byte stream.
388 ******************************************************************************/
391 acpi_rs_dma_resource (
392 u8 *byte_stream_buffer,
393 acpi_size *bytes_consumed,
395 acpi_size *structure_size)
397 u8 *buffer = byte_stream_buffer;
398 struct acpi_resource *output_struct = (void *) *output_buffer;
402 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_dma);
405 ACPI_FUNCTION_TRACE ("rs_dma_resource");
409 * The number of bytes consumed are Constant
412 output_struct->id = ACPI_RSTYPE_DMA;
415 * Point to the 8-bits of Byte 1
420 /* Decode the DMA channel bits */
422 for (i = 0, index = 0; index < 8; index++) {
423 if ((temp8 >> index) & 0x01) {
424 output_struct->data.dma.channels[i] = index;
429 /* Zero DMA channels is valid */
431 output_struct->data.dma.number_of_channels = i;
434 * Calculate the structure size based upon the number of interrupts
436 struct_size += ((acpi_size) i - 1) * 4;
446 * Check for transfer preference (Bits[1:0])
448 output_struct->data.dma.transfer = temp8 & 0x03;
450 if (0x03 == output_struct->data.dma.transfer) {
451 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid DMA.Transfer preference (3)\n"));
452 return_ACPI_STATUS (AE_BAD_DATA);
456 * Get bus master preference (Bit[2])
458 output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01;
461 * Get channel speed support (Bits[6:5])
463 output_struct->data.dma.type = (temp8 >> 5) & 0x03;
466 * Set the Length parameter
468 output_struct->length = (u32) struct_size;
471 * Return the final size of the structure
473 *structure_size = struct_size;
474 return_ACPI_STATUS (AE_OK);
478 /*******************************************************************************
480 * FUNCTION: acpi_rs_dma_stream
482 * PARAMETERS: linked_list - Pointer to the resource linked list
483 * output_buffer - Pointer to the user's return buffer
484 * bytes_consumed - Pointer to where the number of bytes
485 * used in the output_buffer is returned
489 * DESCRIPTION: Take the linked list resource structure and fills in the
490 * the appropriate bytes in a byte stream
492 ******************************************************************************/
496 struct acpi_resource *linked_list,
498 acpi_size *bytes_consumed)
500 u8 *buffer = *output_buffer;
506 ACPI_FUNCTION_TRACE ("rs_dma_stream");
510 * The descriptor field is static
517 * Loop through all of the Channels and set the mask bits
520 index < linked_list->data.dma.number_of_channels;
522 temp16 = (u16) linked_list->data.dma.channels[index];
523 temp8 |= 0x1 << temp16;
532 temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5);
533 temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2);
534 temp8 |= (linked_list->data.dma.transfer & 0x03);
540 * Return the number of bytes consumed in this operation
542 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
543 return_ACPI_STATUS (AE_OK);