blob: 0dab8cdfa80072a66a36db70b2d3c3bf43e226d9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
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 Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acresrc.h>
46
47#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("rsio")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/*******************************************************************************
51 *
Bob Moore50eca3e2005-09-30 19:03:00 -040052 * FUNCTION: acpi_rs_get_io
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 *
Bob Moore50eca3e2005-09-30 19:03:00 -040054 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
58 * RETURN: Status
59 *
Bob Moore50eca3e2005-09-30 19:03:00 -040060 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 *
64 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070065acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -040066acpi_rs_get_io(union aml_resource *aml,
67 u16 aml_resource_length, struct acpi_resource *resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Bob Moore50eca3e2005-09-30 19:03:00 -040069 ACPI_FUNCTION_TRACE("rs_get_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Bob Moore50eca3e2005-09-30 19:03:00 -040071 /* Get the Decode flag */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Bob Moore50eca3e2005-09-30 19:03:00 -040073 resource->data.io.io_decode = aml->io.information & 0x01;
Robert Moore44f6c012005-04-18 22:49:35 -040074
Bob Moore50eca3e2005-09-30 19:03:00 -040075 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Bob Moore50eca3e2005-09-30 19:03:00 -040087 /* Complete the resource header */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Bob Moore50eca3e2005-09-30 19:03:00 -040089 resource->type = ACPI_RESOURCE_TYPE_IO;
90 resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_io);
Len Brown4be44fc2005-08-05 00:44:28 -040091 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/*******************************************************************************
95 *
Bob Moore50eca3e2005-09-30 19:03:00 -040096 * FUNCTION: acpi_rs_set_io
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 *
Bob Moore50eca3e2005-09-30 19:03:00 -040098 * PARAMETERS: Resource - Pointer to the resource descriptor
99 * Aml - Where the AML descriptor is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 * RETURN: Status
102 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400103 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
104 * external AML resource descriptor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 *
106 ******************************************************************************/
107
108acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400109acpi_rs_set_io(struct acpi_resource *resource, union aml_resource *aml)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Bob Moore50eca3e2005-09-30 19:03:00 -0400111 ACPI_FUNCTION_TRACE("rs_set_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Bob Moore50eca3e2005-09-30 19:03:00 -0400113 /* I/O Information Byte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Bob Moore50eca3e2005-09-30 19:03:00 -0400115 aml->io.information = (u8) (resource->data.io.io_decode & 0x01);
Robert Moore44f6c012005-04-18 22:49:35 -0400116
Bob Moore50eca3e2005-09-30 19:03:00 -0400117 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Bob Moore50eca3e2005-09-30 19:03:00 -0400129 /* Complete the AML descriptor header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Bob Moore50eca3e2005-09-30 19:03:00 -0400131 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IO,
132 sizeof(struct aml_resource_io), aml);
Len Brown4be44fc2005-08-05 00:44:28 -0400133 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/*******************************************************************************
137 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400138 * FUNCTION: acpi_rs_get_fixed_io
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400140 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 *
144 * RETURN: Status
145 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400146 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 *
150 ******************************************************************************/
151
152acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400153acpi_rs_get_fixed_io(union aml_resource *aml,
154 u16 aml_resource_length, struct acpi_resource *resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Bob Moore50eca3e2005-09-30 19:03:00 -0400156 ACPI_FUNCTION_TRACE("rs_get_fixed_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Bob Moore50eca3e2005-09-30 19:03:00 -0400158 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Bob Moore50eca3e2005-09-30 19:03:00 -0400167 /* Complete the resource header */
Robert Moore44f6c012005-04-18 22:49:35 -0400168
Bob Moore50eca3e2005-09-30 19:03:00 -0400169 resource->type = ACPI_RESOURCE_TYPE_FIXED_IO;
170 resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io);
Len Brown4be44fc2005-08-05 00:44:28 -0400171 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/*******************************************************************************
175 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400176 * FUNCTION: acpi_rs_set_fixed_io
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400178 * PARAMETERS: Resource - Pointer to the resource descriptor
179 * Aml - Where the AML descriptor is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 *
181 * RETURN: Status
182 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400183 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
184 * external AML resource descriptor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 *
186 ******************************************************************************/
187
188acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400189acpi_rs_set_fixed_io(struct acpi_resource *resource, union aml_resource *aml)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Bob Moore50eca3e2005-09-30 19:03:00 -0400191 ACPI_FUNCTION_TRACE("rs_set_fixed_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Bob Moore50eca3e2005-09-30 19:03:00 -0400193 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Bob Moore50eca3e2005-09-30 19:03:00 -0400203 /* Complete the AML descriptor header */
Robert Moore44f6c012005-04-18 22:49:35 -0400204
Bob Moore50eca3e2005-09-30 19:03:00 -0400205 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_FIXED_IO,
206 sizeof(struct aml_resource_fixed_io), aml);
Len Brown4be44fc2005-08-05 00:44:28 -0400207 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/*******************************************************************************
211 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400212 * FUNCTION: acpi_rs_get_dma
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400214 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 *
218 * RETURN: Status
219 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400220 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 *
224 ******************************************************************************/
225
226acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400227acpi_rs_get_dma(union aml_resource *aml,
228 u16 aml_resource_length, struct acpi_resource *resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Bob Moore50eca3e2005-09-30 19:03:00 -0400230 u32 channel_count = 0;
231 u32 i;
232 u8 temp8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Bob Moore50eca3e2005-09-30 19:03:00 -0400234 ACPI_FUNCTION_TRACE("rs_get_dma");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 /* Decode the DMA channel bits */
237
Bob Moore50eca3e2005-09-30 19:03:00 -0400238 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++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243 }
244
Bob Moore50eca3e2005-09-30 19:03:00 -0400245 resource->length = 0;
246 resource->data.dma.channel_count = channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Bob Moore50eca3e2005-09-30 19:03:00 -0400248 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
Bob Moore50eca3e2005-09-30 19:03:00 -0400256 /* Get the flags: transfer preference, bus mastering, channel speed */
Robert Moore44f6c012005-04-18 22:49:35 -0400257
Bob Moore50eca3e2005-09-30 19:03:00 -0400258 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Bob Moore50eca3e2005-09-30 19:03:00 -0400263 if (resource->data.dma.transfer == 0x03) {
Len Brown4be44fc2005-08-05 00:44:28 -0400264 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
265 "Invalid DMA.Transfer preference (3)\n"));
266 return_ACPI_STATUS(AE_BAD_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268
Bob Moore50eca3e2005-09-30 19:03:00 -0400269 /* Complete the resource header */
Robert Moore44f6c012005-04-18 22:49:35 -0400270
Bob Moore50eca3e2005-09-30 19:03:00 -0400271 resource->type = ACPI_RESOURCE_TYPE_DMA;
272 resource->length += ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma);
Len Brown4be44fc2005-08-05 00:44:28 -0400273 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*******************************************************************************
277 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400278 * FUNCTION: acpi_rs_set_dma
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400280 * PARAMETERS: Resource - Pointer to the resource descriptor
281 * Aml - Where the AML descriptor is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 *
283 * RETURN: Status
284 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400285 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
286 * external AML resource descriptor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 *
288 ******************************************************************************/
289
290acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400291acpi_rs_set_dma(struct acpi_resource *resource, union aml_resource *aml)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Bob Moore50eca3e2005-09-30 19:03:00 -0400293 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Bob Moore50eca3e2005-09-30 19:03:00 -0400295 ACPI_FUNCTION_TRACE("rs_set_dma");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Bob Moore50eca3e2005-09-30 19:03:00 -0400297 /* Convert channel list to 8-bit DMA channel bitmask */
Robert Moore44f6c012005-04-18 22:49:35 -0400298
Bob Moore50eca3e2005-09-30 19:03:00 -0400299 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]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
Bob Moore50eca3e2005-09-30 19:03:00 -0400305 /* Set the DMA Flag bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Bob Moore50eca3e2005-09-30 19:03:00 -0400307 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));
Robert Moore44f6c012005-04-18 22:49:35 -0400311
Bob Moore50eca3e2005-09-30 19:03:00 -0400312 /* Complete the AML descriptor header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Bob Moore50eca3e2005-09-30 19:03:00 -0400314 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_DMA,
315 sizeof(struct aml_resource_dma), aml);
Len Brown4be44fc2005-08-05 00:44:28 -0400316 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}