Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[linux-2.6] / drivers / acpi / resources / rsaddr.c
1 /*******************************************************************************
2  *
3  * Module Name: rsaddr - Address resource descriptors (16/32/64)
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2008, Intel Corp.
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
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
46
47 #define _COMPONENT          ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsaddr")
49
50 /*******************************************************************************
51  *
52  * acpi_rs_convert_address16 - All WORD (16-bit) address resources
53  *
54  ******************************************************************************/
55 struct acpi_rsconvert_info acpi_rs_convert_address16[5] = {
56         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS16,
57          ACPI_RS_SIZE(struct acpi_resource_address16),
58          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address16)},
59
60         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS16,
61          sizeof(struct aml_resource_address16),
62          0},
63
64         /* Resource Type, General Flags, and Type-Specific Flags */
65
66         {ACPI_RSC_ADDRESS, 0, 0, 0},
67
68         /*
69          * These fields are contiguous in both the source and destination:
70          * Address Granularity
71          * Address Range Minimum
72          * Address Range Maximum
73          * Address Translation Offset
74          * Address Length
75          */
76         {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.address16.granularity),
77          AML_OFFSET(address16.granularity),
78          5},
79
80         /* Optional resource_source (Index and String) */
81
82         {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address16.resource_source),
83          0,
84          sizeof(struct aml_resource_address16)}
85 };
86
87 /*******************************************************************************
88  *
89  * acpi_rs_convert_address32 - All DWORD (32-bit) address resources
90  *
91  ******************************************************************************/
92
93 struct acpi_rsconvert_info acpi_rs_convert_address32[5] = {
94         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS32,
95          ACPI_RS_SIZE(struct acpi_resource_address32),
96          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address32)},
97
98         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS32,
99          sizeof(struct aml_resource_address32),
100          0},
101
102         /* Resource Type, General Flags, and Type-Specific Flags */
103
104         {ACPI_RSC_ADDRESS, 0, 0, 0},
105
106         /*
107          * These fields are contiguous in both the source and destination:
108          * Address Granularity
109          * Address Range Minimum
110          * Address Range Maximum
111          * Address Translation Offset
112          * Address Length
113          */
114         {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.address32.granularity),
115          AML_OFFSET(address32.granularity),
116          5},
117
118         /* Optional resource_source (Index and String) */
119
120         {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address32.resource_source),
121          0,
122          sizeof(struct aml_resource_address32)}
123 };
124
125 /*******************************************************************************
126  *
127  * acpi_rs_convert_address64 - All QWORD (64-bit) address resources
128  *
129  ******************************************************************************/
130
131 struct acpi_rsconvert_info acpi_rs_convert_address64[5] = {
132         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS64,
133          ACPI_RS_SIZE(struct acpi_resource_address64),
134          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address64)},
135
136         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS64,
137          sizeof(struct aml_resource_address64),
138          0},
139
140         /* Resource Type, General Flags, and Type-Specific Flags */
141
142         {ACPI_RSC_ADDRESS, 0, 0, 0},
143
144         /*
145          * These fields are contiguous in both the source and destination:
146          * Address Granularity
147          * Address Range Minimum
148          * Address Range Maximum
149          * Address Translation Offset
150          * Address Length
151          */
152         {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.address64.granularity),
153          AML_OFFSET(address64.granularity),
154          5},
155
156         /* Optional resource_source (Index and String) */
157
158         {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address64.resource_source),
159          0,
160          sizeof(struct aml_resource_address64)}
161 };
162
163 /*******************************************************************************
164  *
165  * acpi_rs_convert_ext_address64 - All Extended (64-bit) address resources
166  *
167  ******************************************************************************/
168
169 struct acpi_rsconvert_info acpi_rs_convert_ext_address64[5] = {
170         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64,
171          ACPI_RS_SIZE(struct acpi_resource_extended_address64),
172          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_ext_address64)},
173
174         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,
175          sizeof(struct aml_resource_extended_address64),
176          0},
177
178         /* Resource Type, General Flags, and Type-Specific Flags */
179
180         {ACPI_RSC_ADDRESS, 0, 0, 0},
181
182         /* Revision ID */
183
184         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.ext_address64.revision_iD),
185          AML_OFFSET(ext_address64.revision_iD),
186          1},
187         /*
188          * These fields are contiguous in both the source and destination:
189          * Address Granularity
190          * Address Range Minimum
191          * Address Range Maximum
192          * Address Translation Offset
193          * Address Length
194          * Type-Specific Attribute
195          */
196         {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.ext_address64.granularity),
197          AML_OFFSET(ext_address64.granularity),
198          6}
199 };
200
201 /*******************************************************************************
202  *
203  * acpi_rs_convert_general_flags - Flags common to all address descriptors
204  *
205  ******************************************************************************/
206
207 static struct acpi_rsconvert_info acpi_rs_convert_general_flags[6] = {
208         {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.flags),
209          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_general_flags)},
210
211         /* Resource Type (Memory, Io, bus_number, etc.) */
212
213         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.address.resource_type),
214          AML_OFFSET(address.resource_type),
215          1},
216
217         /* General Flags - Consume, Decode, min_fixed, max_fixed */
218
219         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.producer_consumer),
220          AML_OFFSET(address.flags),
221          0},
222
223         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.decode),
224          AML_OFFSET(address.flags),
225          1},
226
227         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.min_address_fixed),
228          AML_OFFSET(address.flags),
229          2},
230
231         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.max_address_fixed),
232          AML_OFFSET(address.flags),
233          3}
234 };
235
236 /*******************************************************************************
237  *
238  * acpi_rs_convert_mem_flags - Flags common to Memory address descriptors
239  *
240  ******************************************************************************/
241
242 static struct acpi_rsconvert_info acpi_rs_convert_mem_flags[5] = {
243         {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
244          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_mem_flags)},
245
246         /* Memory-specific flags */
247
248         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.write_protect),
249          AML_OFFSET(address.specific_flags),
250          0},
251
252         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.caching),
253          AML_OFFSET(address.specific_flags),
254          1},
255
256         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.range_type),
257          AML_OFFSET(address.specific_flags),
258          3},
259
260         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.translation),
261          AML_OFFSET(address.specific_flags),
262          5}
263 };
264
265 /*******************************************************************************
266  *
267  * acpi_rs_convert_io_flags - Flags common to I/O address descriptors
268  *
269  ******************************************************************************/
270
271 static struct acpi_rsconvert_info acpi_rs_convert_io_flags[4] = {
272         {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
273          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_io_flags)},
274
275         /* I/O-specific flags */
276
277         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.io.range_type),
278          AML_OFFSET(address.specific_flags),
279          0},
280
281         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.io.translation),
282          AML_OFFSET(address.specific_flags),
283          4},
284
285         {ACPI_RSC_1BITFLAG,
286          ACPI_RS_OFFSET(data.address.info.io.translation_type),
287          AML_OFFSET(address.specific_flags),
288          5}
289 };
290
291 /*******************************************************************************
292  *
293  * FUNCTION:    acpi_rs_get_address_common
294  *
295  * PARAMETERS:  Resource            - Pointer to the internal resource struct
296  *              Aml                 - Pointer to the AML resource descriptor
297  *
298  * RETURN:      TRUE if the resource_type field is OK, FALSE otherwise
299  *
300  * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
301  *              to an internal resource descriptor
302  *
303  ******************************************************************************/
304
305 u8
306 acpi_rs_get_address_common(struct acpi_resource *resource,
307                            union aml_resource *aml)
308 {
309         ACPI_FUNCTION_ENTRY();
310
311         /* Validate the Resource Type */
312
313         if ((aml->address.resource_type > 2)
314             && (aml->address.resource_type < 0xC0)) {
315                 return (FALSE);
316         }
317
318         /* Get the Resource Type and General Flags */
319
320         (void)acpi_rs_convert_aml_to_resource(resource, aml,
321                                               acpi_rs_convert_general_flags);
322
323         /* Get the Type-Specific Flags (Memory and I/O descriptors only) */
324
325         if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
326                 (void)acpi_rs_convert_aml_to_resource(resource, aml,
327                                                       acpi_rs_convert_mem_flags);
328         } else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
329                 (void)acpi_rs_convert_aml_to_resource(resource, aml,
330                                                       acpi_rs_convert_io_flags);
331         } else {
332                 /* Generic resource type, just grab the type_specific byte */
333
334                 resource->data.address.info.type_specific =
335                     aml->address.specific_flags;
336         }
337
338         return (TRUE);
339 }
340
341 /*******************************************************************************
342  *
343  * FUNCTION:    acpi_rs_set_address_common
344  *
345  * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
346  *              Resource            - Pointer to the internal resource struct
347  *
348  * RETURN:      None
349  *
350  * DESCRIPTION: Convert common flag fields from a resource descriptor to an
351  *              AML descriptor
352  *
353  ******************************************************************************/
354
355 void
356 acpi_rs_set_address_common(union aml_resource *aml,
357                            struct acpi_resource *resource)
358 {
359         ACPI_FUNCTION_ENTRY();
360
361         /* Set the Resource Type and General Flags */
362
363         (void)acpi_rs_convert_resource_to_aml(resource, aml,
364                                               acpi_rs_convert_general_flags);
365
366         /* Set the Type-Specific Flags (Memory and I/O descriptors only) */
367
368         if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
369                 (void)acpi_rs_convert_resource_to_aml(resource, aml,
370                                                       acpi_rs_convert_mem_flags);
371         } else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
372                 (void)acpi_rs_convert_resource_to_aml(resource, aml,
373                                                       acpi_rs_convert_io_flags);
374         } else {
375                 /* Generic resource type, just copy the type_specific byte */
376
377                 aml->address.specific_flags =
378                     resource->data.address.info.type_specific;
379         }
380 }