[ACPI] ACPICA 20050930
[linux-2.6-block.git] / drivers / acpi / resources / rsio.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
44#include <acpi/acpi.h>
45#include <acpi/acresrc.h>
46
47#define _COMPONENT ACPI_RESOURCES
4be44fcd 48ACPI_MODULE_NAME("rsio")
1da177e4
LT
49
50/*******************************************************************************
51 *
50eca3eb 52 * FUNCTION: acpi_rs_get_io
1da177e4 53 *
50eca3eb
BM
54 * PARAMETERS: Aml - Pointer to the AML resource descriptor
55 * aml_resource_length - Length of the resource from the AML header
56 * Resource - Where the internal resource is returned
1da177e4
LT
57 *
58 * RETURN: Status
59 *
50eca3eb
BM
60 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
61 * internal resource descriptor, simplifying bitflags and handling
62 * alignment and endian issues if necessary.
1da177e4
LT
63 *
64 ******************************************************************************/
1da177e4 65acpi_status
50eca3eb
BM
66acpi_rs_get_io(union aml_resource *aml,
67 u16 aml_resource_length, struct acpi_resource *resource)
1da177e4 68{
50eca3eb 69 ACPI_FUNCTION_TRACE("rs_get_io");
1da177e4 70
50eca3eb 71 /* Get the Decode flag */
1da177e4 72
50eca3eb 73 resource->data.io.io_decode = aml->io.information & 0x01;
44f6c012 74
50eca3eb
BM
75 /*
76 * Get the following contiguous fields from the AML descriptor:
77 * Minimum Base Address
78 * Maximum Base Address
79 * Address Alignment
80 * Length
81 */
82 ACPI_MOVE_16_TO_32(&resource->data.io.minimum, &aml->io.minimum);
83 ACPI_MOVE_16_TO_32(&resource->data.io.maximum, &aml->io.maximum);
84 resource->data.io.alignment = aml->io.alignment;
85 resource->data.io.address_length = aml->io.address_length;
1da177e4 86
50eca3eb 87 /* Complete the resource header */
1da177e4 88
50eca3eb
BM
89 resource->type = ACPI_RESOURCE_TYPE_IO;
90 resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_io);
4be44fcd 91 return_ACPI_STATUS(AE_OK);
1da177e4
LT
92}
93
1da177e4
LT
94/*******************************************************************************
95 *
50eca3eb 96 * FUNCTION: acpi_rs_set_io
1da177e4 97 *
50eca3eb
BM
98 * PARAMETERS: Resource - Pointer to the resource descriptor
99 * Aml - Where the AML descriptor is returned
1da177e4
LT
100 *
101 * RETURN: Status
102 *
50eca3eb
BM
103 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
104 * external AML resource descriptor.
1da177e4
LT
105 *
106 ******************************************************************************/
107
108acpi_status
50eca3eb 109acpi_rs_set_io(struct acpi_resource *resource, union aml_resource *aml)
1da177e4 110{
50eca3eb 111 ACPI_FUNCTION_TRACE("rs_set_io");
1da177e4 112
50eca3eb 113 /* I/O Information Byte */
44f6c012 114
50eca3eb 115 aml->io.information = (u8) (resource->data.io.io_decode & 0x01);
1da177e4 116
50eca3eb
BM
117 /*
118 * Set the following contiguous fields in the AML descriptor:
119 * Minimum Base Address
120 * Maximum Base Address
121 * Address Alignment
122 * Length
123 */
124 ACPI_MOVE_32_TO_16(&aml->io.minimum, &resource->data.io.minimum);
125 ACPI_MOVE_32_TO_16(&aml->io.maximum, &resource->data.io.maximum);
126 aml->io.alignment = (u8) resource->data.io.alignment;
127 aml->io.address_length = (u8) resource->data.io.address_length;
1da177e4 128
50eca3eb 129 /* Complete the AML descriptor header */
44f6c012 130
50eca3eb
BM
131 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IO,
132 sizeof(struct aml_resource_io), aml);
4be44fcd 133 return_ACPI_STATUS(AE_OK);
1da177e4
LT
134}
135
1da177e4
LT
136/*******************************************************************************
137 *
50eca3eb 138 * FUNCTION: acpi_rs_get_fixed_io
1da177e4 139 *
50eca3eb
BM
140 * PARAMETERS: Aml - Pointer to the AML resource descriptor
141 * aml_resource_length - Length of the resource from the AML header
142 * Resource - Where the internal resource is returned
1da177e4
LT
143 *
144 * RETURN: Status
145 *
50eca3eb
BM
146 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
147 * internal resource descriptor, simplifying bitflags and handling
148 * alignment and endian issues if necessary.
1da177e4
LT
149 *
150 ******************************************************************************/
151
152acpi_status
50eca3eb
BM
153acpi_rs_get_fixed_io(union aml_resource *aml,
154 u16 aml_resource_length, struct acpi_resource *resource)
1da177e4 155{
50eca3eb 156 ACPI_FUNCTION_TRACE("rs_get_fixed_io");
44f6c012 157
50eca3eb
BM
158 /*
159 * Get the following contiguous fields from the AML descriptor:
160 * Base Address
161 * Length
162 */
163 ACPI_MOVE_16_TO_32(&resource->data.fixed_io.address,
164 &aml->fixed_io.address);
165 resource->data.fixed_io.address_length = aml->fixed_io.address_length;
1da177e4 166
50eca3eb 167 /* Complete the resource header */
1da177e4 168
50eca3eb
BM
169 resource->type = ACPI_RESOURCE_TYPE_FIXED_IO;
170 resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io);
4be44fcd 171 return_ACPI_STATUS(AE_OK);
1da177e4
LT
172}
173
1da177e4
LT
174/*******************************************************************************
175 *
50eca3eb 176 * FUNCTION: acpi_rs_set_fixed_io
1da177e4 177 *
50eca3eb
BM
178 * PARAMETERS: Resource - Pointer to the resource descriptor
179 * Aml - Where the AML descriptor is returned
1da177e4
LT
180 *
181 * RETURN: Status
182 *
50eca3eb
BM
183 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
184 * external AML resource descriptor.
1da177e4
LT
185 *
186 ******************************************************************************/
187
188acpi_status
50eca3eb 189acpi_rs_set_fixed_io(struct acpi_resource *resource, union aml_resource *aml)
1da177e4 190{
50eca3eb
BM
191 ACPI_FUNCTION_TRACE("rs_set_fixed_io");
192
193 /*
194 * Set the following contiguous fields in the AML descriptor:
195 * Base Address
196 * Length
197 */
198 ACPI_MOVE_32_TO_16(&aml->fixed_io.address,
199 &resource->data.fixed_io.address);
200 aml->fixed_io.address_length =
201 (u8) resource->data.fixed_io.address_length;
202
203 /* Complete the AML descriptor header */
204
205 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_FIXED_IO,
206 sizeof(struct aml_resource_fixed_io), aml);
4be44fcd 207 return_ACPI_STATUS(AE_OK);
1da177e4
LT
208}
209
1da177e4
LT
210/*******************************************************************************
211 *
50eca3eb 212 * FUNCTION: acpi_rs_get_dma
1da177e4 213 *
50eca3eb
BM
214 * PARAMETERS: Aml - Pointer to the AML resource descriptor
215 * aml_resource_length - Length of the resource from the AML header
216 * Resource - Where the internal resource is returned
1da177e4
LT
217 *
218 * RETURN: Status
219 *
50eca3eb
BM
220 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
221 * internal resource descriptor, simplifying bitflags and handling
222 * alignment and endian issues if necessary.
1da177e4
LT
223 *
224 ******************************************************************************/
225
226acpi_status
50eca3eb
BM
227acpi_rs_get_dma(union aml_resource *aml,
228 u16 aml_resource_length, struct acpi_resource *resource)
1da177e4 229{
50eca3eb
BM
230 u32 channel_count = 0;
231 u32 i;
232 u8 temp8;
1da177e4 233
50eca3eb 234 ACPI_FUNCTION_TRACE("rs_get_dma");
1da177e4
LT
235
236 /* Decode the DMA channel bits */
237
50eca3eb
BM
238 for (i = 0; i < 8; i++) {
239 if ((aml->dma.dma_channel_mask >> i) & 0x01) {
240 resource->data.dma.channels[channel_count] = i;
241 channel_count++;
1da177e4
LT
242 }
243 }
244
50eca3eb
BM
245 resource->length = 0;
246 resource->data.dma.channel_count = channel_count;
44f6c012 247
50eca3eb
BM
248 /*
249 * Calculate the structure size based upon the number of channels
250 * Note: Zero DMA channels is valid
251 */
252 if (channel_count > 0) {
253 resource->length = (u32) (channel_count - 1) * 4;
1da177e4
LT
254 }
255
50eca3eb 256 /* Get the flags: transfer preference, bus mastering, channel speed */
44f6c012 257
50eca3eb
BM
258 temp8 = aml->dma.flags;
259 resource->data.dma.transfer = temp8 & 0x03;
260 resource->data.dma.bus_master = (temp8 >> 2) & 0x01;
261 resource->data.dma.type = (temp8 >> 5) & 0x03;
1da177e4 262
50eca3eb 263 if (resource->data.dma.transfer == 0x03) {
4be44fcd
LB
264 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
265 "Invalid DMA.Transfer preference (3)\n"));
266 return_ACPI_STATUS(AE_BAD_DATA);
1da177e4
LT
267 }
268
50eca3eb 269 /* Complete the resource header */
44f6c012 270
50eca3eb
BM
271 resource->type = ACPI_RESOURCE_TYPE_DMA;
272 resource->length += ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma);
4be44fcd 273 return_ACPI_STATUS(AE_OK);
1da177e4
LT
274}
275
1da177e4
LT
276/*******************************************************************************
277 *
50eca3eb 278 * FUNCTION: acpi_rs_set_dma
1da177e4 279 *
50eca3eb
BM
280 * PARAMETERS: Resource - Pointer to the resource descriptor
281 * Aml - Where the AML descriptor is returned
1da177e4
LT
282 *
283 * RETURN: Status
284 *
50eca3eb
BM
285 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
286 * external AML resource descriptor.
1da177e4
LT
287 *
288 ******************************************************************************/
289
290acpi_status
50eca3eb 291acpi_rs_set_dma(struct acpi_resource *resource, union aml_resource *aml)
1da177e4 292{
50eca3eb 293 u8 i;
44f6c012 294
50eca3eb 295 ACPI_FUNCTION_TRACE("rs_set_dma");
1da177e4 296
50eca3eb 297 /* Convert channel list to 8-bit DMA channel bitmask */
44f6c012 298
50eca3eb
BM
299 aml->dma.dma_channel_mask = 0;
300 for (i = 0; i < resource->data.dma.channel_count; i++) {
301 aml->dma.dma_channel_mask |=
302 (1 << resource->data.dma.channels[i]);
1da177e4
LT
303 }
304
50eca3eb 305 /* Set the DMA Flag bits */
1da177e4 306
50eca3eb
BM
307 aml->dma.flags = (u8)
308 (((resource->data.dma.type & 0x03) << 5) |
309 ((resource->data.dma.bus_master & 0x01) << 2) |
310 (resource->data.dma.transfer & 0x03));
1da177e4 311
50eca3eb 312 /* Complete the AML descriptor header */
44f6c012 313
50eca3eb
BM
314 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_DMA,
315 sizeof(struct aml_resource_dma), aml);
4be44fcd 316 return_ACPI_STATUS(AE_OK);
1da177e4 317}