47e979e7ba3591a5deeb50ccf79e17695cfe73d2
[sfrench/cifs-2.6.git] / drivers / acpi / resources / rsmemory.c
1 /*******************************************************************************
2  *
3  * Module Name: rsmem24 - Memory 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
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
46
47 #define _COMPONENT          ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsmemory")
49
50 /*******************************************************************************
51  *
52  * FUNCTION:    acpi_rs_get_memory24
53  *
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
57  *
58  * RETURN:      Status
59  *
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.
63  *
64  ******************************************************************************/
65 acpi_status
66 acpi_rs_get_memory24(union aml_resource * aml,
67                      u16 aml_resource_length, struct acpi_resource * resource)
68 {
69         ACPI_FUNCTION_TRACE("rs_get_memory24");
70
71         /* Get the Read/Write bit */
72
73         resource->data.memory24.read_write_attribute =
74             (aml->memory24.information & 0x01);
75
76         /*
77          * Get the following contiguous fields from the AML descriptor:
78          * Minimum Base Address
79          * Maximum Base Address
80          * Address Base Alignment
81          * Range Length
82          */
83         acpi_rs_move_data(&resource->data.memory24.minimum,
84                           &aml->memory24.minimum, 4, ACPI_MOVE_TYPE_16_TO_32);
85
86         /* Complete the resource header */
87
88         resource->type = ACPI_RESOURCE_TYPE_MEMORY24;
89         resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_memory24);
90         return_ACPI_STATUS(AE_OK);
91 }
92
93 /*******************************************************************************
94  *
95  * FUNCTION:    acpi_rs_set_memory24
96  *
97  * PARAMETERS:  Resource            - Pointer to the resource descriptor
98  *              Aml                 - Where the AML descriptor is returned
99  *
100  * RETURN:      Status
101  *
102  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
103  *              external AML resource descriptor.
104  *
105  ******************************************************************************/
106
107 acpi_status
108 acpi_rs_set_memory24(struct acpi_resource *resource, union aml_resource *aml)
109 {
110         ACPI_FUNCTION_TRACE("rs_set_memory24");
111
112         /* Set the Information Byte */
113
114         aml->memory24.information = (u8)
115             (resource->data.memory24.read_write_attribute & 0x01);
116
117         /*
118          * Set the following contiguous fields in the AML descriptor:
119          * Minimum Base Address
120          * Maximum Base Address
121          * Address Base Alignment
122          * Range Length
123          */
124         acpi_rs_move_data(&aml->memory24.minimum,
125                           &resource->data.memory24.minimum, 4,
126                           ACPI_MOVE_TYPE_32_TO_16);
127
128         /* Complete the AML descriptor header */
129
130         acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_MEMORY24,
131                                     sizeof(struct aml_resource_memory24), aml);
132         return_ACPI_STATUS(AE_OK);
133 }
134
135 /*******************************************************************************
136  *
137  * FUNCTION:    acpi_rs_get_memory32
138  *
139  * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
140  *              aml_resource_length - Length of the resource from the AML header
141  *              Resource            - Where the internal resource is returned
142  *
143  * RETURN:      Status
144  *
145  * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
146  *              internal resource descriptor, simplifying bitflags and handling
147  *              alignment and endian issues if necessary.
148  *
149  ******************************************************************************/
150
151 acpi_status
152 acpi_rs_get_memory32(union aml_resource *aml,
153                      u16 aml_resource_length, struct acpi_resource *resource)
154 {
155         ACPI_FUNCTION_TRACE("rs_get_memory32");
156
157         /* Get the Read/Write bit */
158
159         resource->data.memory32.read_write_attribute =
160             (aml->memory32.information & 0x01);
161
162         /*
163          * Get the following contiguous fields from the AML descriptor:
164          * Minimum Base Address
165          * Maximum Base Address
166          * Address Base Alignment
167          * Range Length
168          */
169         acpi_rs_move_data(&resource->data.memory32.minimum,
170                           &aml->memory32.minimum, 4, ACPI_MOVE_TYPE_32_TO_32);
171
172         /* Complete the resource header */
173
174         resource->type = ACPI_RESOURCE_TYPE_MEMORY32;
175         resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_memory32);
176         return_ACPI_STATUS(AE_OK);
177 }
178
179 /*******************************************************************************
180  *
181  * FUNCTION:    acpi_rs_set_memory32
182  *
183  * PARAMETERS:  Resource            - Pointer to the resource descriptor
184  *              Aml                 - Where the AML descriptor is returned
185  *
186  * RETURN:      Status
187  *
188  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
189  *              external AML resource descriptor.
190  *
191  ******************************************************************************/
192
193 acpi_status
194 acpi_rs_set_memory32(struct acpi_resource *resource, union aml_resource *aml)
195 {
196         ACPI_FUNCTION_TRACE("rs_set_memory32");
197
198         /* Set the Information Byte */
199
200         aml->memory32.information = (u8)
201             (resource->data.memory32.read_write_attribute & 0x01);
202
203         /*
204          * Set the following contiguous fields in the AML descriptor:
205          * Minimum Base Address
206          * Maximum Base Address
207          * Address Base Alignment
208          * Range Length
209          */
210         acpi_rs_move_data(&aml->memory32.minimum,
211                           &resource->data.memory32.minimum, 4,
212                           ACPI_MOVE_TYPE_32_TO_32);
213
214         /* Complete the AML descriptor header */
215
216         acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_MEMORY32,
217                                     sizeof(struct aml_resource_memory32), aml);
218         return_ACPI_STATUS(AE_OK);
219 }
220
221 /*******************************************************************************
222  *
223  * FUNCTION:    acpi_rs_get_fixed_memory32
224  *
225  * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
226  *              aml_resource_length - Length of the resource from the AML header
227  *              Resource            - Where the internal resource is returned
228  *
229  * RETURN:      Status
230  *
231  * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
232  *              internal resource descriptor, simplifying bitflags and handling
233  *              alignment and endian issues if necessary.
234  *
235  ******************************************************************************/
236
237 acpi_status
238 acpi_rs_get_fixed_memory32(union aml_resource *aml,
239                            u16 aml_resource_length,
240                            struct acpi_resource *resource)
241 {
242         ACPI_FUNCTION_TRACE("rs_get_fixed_memory32");
243
244         /* Get the Read/Write bit */
245
246         resource->data.fixed_memory32.read_write_attribute =
247             (aml->fixed_memory32.information & 0x01);
248
249         /*
250          * Get the following contiguous fields from the AML descriptor:
251          * Base Address
252          * Range Length
253          */
254         ACPI_MOVE_32_TO_32(&resource->data.fixed_memory32.address,
255                            &aml->fixed_memory32.address);
256         ACPI_MOVE_32_TO_32(&resource->data.fixed_memory32.address_length,
257                            &aml->fixed_memory32.address_length);
258
259         /* Complete the resource header */
260
261         resource->type = ACPI_RESOURCE_TYPE_FIXED_MEMORY32;
262         resource->length =
263             ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_memory32);
264         return_ACPI_STATUS(AE_OK);
265 }
266
267 /*******************************************************************************
268  *
269  * FUNCTION:    acpi_rs_set_fixed_memory32
270  *
271  * PARAMETERS:  Resource            - Pointer to the resource descriptor
272  *              Aml                 - Where the AML descriptor is returned
273  *
274  * RETURN:      Status
275  *
276  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
277  *              external AML resource descriptor.
278  *
279  ******************************************************************************/
280
281 acpi_status
282 acpi_rs_set_fixed_memory32(struct acpi_resource *resource,
283                            union aml_resource *aml)
284 {
285         ACPI_FUNCTION_TRACE("rs_set_fixed_memory32");
286
287         /* Set the Information Byte */
288
289         aml->fixed_memory32.information = (u8)
290             (resource->data.fixed_memory32.read_write_attribute & 0x01);
291
292         /*
293          * Set the following contiguous fields in the AML descriptor:
294          * Base Address
295          * Range Length
296          */
297         ACPI_MOVE_32_TO_32(&aml->fixed_memory32.address,
298                            &resource->data.fixed_memory32.address);
299         ACPI_MOVE_32_TO_32(&aml->fixed_memory32.address_length,
300                            &resource->data.fixed_memory32.address_length);
301
302         /* Complete the AML descriptor header */
303
304         acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_FIXED_MEMORY32,
305                                     sizeof(struct aml_resource_fixed_memory32),
306                                     aml);
307         return_ACPI_STATUS(AE_OK);
308 }