blob: 6f48ebf3304e12caa68694b80ae64d755c4fa410 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: rsaddr - Address resource descriptors (16/32/64)
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("rsaddr")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Mooreaff8c272005-09-02 17:24:17 -040050/* Local prototypes */
51static void
52acpi_rs_decode_general_flags(union acpi_resource_data *resource, u8 flags);
53
54static u8 acpi_rs_encode_general_flags(union acpi_resource_data *resource);
55
56static void
57acpi_rs_decode_specific_flags(union acpi_resource_data *resource, u8 flags);
58
59static u8 acpi_rs_encode_specific_flags(union acpi_resource_data *resource);
60
Bob Moore50eca3e2005-09-30 19:03:00 -040061static void
62acpi_rs_set_address_common(union aml_resource *aml,
63 struct acpi_resource *resource);
64
65static u8
66acpi_rs_get_address_common(struct acpi_resource *resource,
67 union aml_resource *aml);
68
Robert Mooreaff8c272005-09-02 17:24:17 -040069/*******************************************************************************
70 *
71 * FUNCTION: acpi_rs_decode_general_flags
72 *
73 * PARAMETERS: Resource - Address resource data struct
Bob Moore50eca3e2005-09-30 19:03:00 -040074 * Flags - Raw AML flag byte
Robert Mooreaff8c272005-09-02 17:24:17 -040075 *
76 * RETURN: Decoded flag bits in resource struct
77 *
78 * DESCRIPTION: Decode a general flag byte to an address resource struct
79 *
80 ******************************************************************************/
81
82static void
83acpi_rs_decode_general_flags(union acpi_resource_data *resource, u8 flags)
84{
85 ACPI_FUNCTION_ENTRY();
86
87 /* Producer / Consumer - flag bit[0] */
88
89 resource->address.producer_consumer = (u32) (flags & 0x01);
90
91 /* Decode (_DEC) - flag bit[1] */
92
93 resource->address.decode = (u32) ((flags >> 1) & 0x01);
94
95 /* Min Address Fixed (_MIF) - flag bit[2] */
96
97 resource->address.min_address_fixed = (u32) ((flags >> 2) & 0x01);
98
99 /* Max Address Fixed (_MAF) - flag bit[3] */
100
101 resource->address.max_address_fixed = (u32) ((flags >> 3) & 0x01);
102}
103
104/*******************************************************************************
105 *
106 * FUNCTION: acpi_rs_encode_general_flags
107 *
108 * PARAMETERS: Resource - Address resource data struct
109 *
110 * RETURN: Encoded general flag byte
111 *
112 * DESCRIPTION: Construct a general flag byte from an address resource struct
113 *
114 ******************************************************************************/
115
116static u8 acpi_rs_encode_general_flags(union acpi_resource_data *resource)
117{
Robert Mooreaff8c272005-09-02 17:24:17 -0400118 ACPI_FUNCTION_ENTRY();
119
Bob Moore50eca3e2005-09-30 19:03:00 -0400120 return ((u8)
Robert Mooreaff8c272005-09-02 17:24:17 -0400121
Bob Moore50eca3e2005-09-30 19:03:00 -0400122 /* Producer / Consumer - flag bit[0] */
123 ((resource->address.producer_consumer & 0x01) |
124 /* Decode (_DEC) - flag bit[1] */
125 ((resource->address.decode & 0x01) << 1) |
126 /* Min Address Fixed (_MIF) - flag bit[2] */
127 ((resource->address.min_address_fixed & 0x01) << 2) |
128 /* Max Address Fixed (_MAF) - flag bit[3] */
129 ((resource->address.max_address_fixed & 0x01) << 3))
130 );
Robert Mooreaff8c272005-09-02 17:24:17 -0400131}
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_rs_decode_specific_flags
136 *
137 * PARAMETERS: Resource - Address resource data struct
Bob Moore50eca3e2005-09-30 19:03:00 -0400138 * Flags - Raw AML flag byte
Robert Mooreaff8c272005-09-02 17:24:17 -0400139 *
140 * RETURN: Decoded flag bits in attribute struct
141 *
142 * DESCRIPTION: Decode a type-specific flag byte to an attribute struct.
143 * Type-specific flags are only defined for the Memory and IO
144 * resource types.
145 *
146 ******************************************************************************/
147
148static void
149acpi_rs_decode_specific_flags(union acpi_resource_data *resource, u8 flags)
150{
151 ACPI_FUNCTION_ENTRY();
152
153 if (resource->address.resource_type == ACPI_MEMORY_RANGE) {
154 /* Write Status (_RW) - flag bit[0] */
155
156 resource->address.attribute.memory.read_write_attribute =
157 (u16) (flags & 0x01);
158
159 /* Memory Attributes (_MEM) - flag bits[2:1] */
160
161 resource->address.attribute.memory.cache_attribute =
162 (u16) ((flags >> 1) & 0x03);
163 } else if (resource->address.resource_type == ACPI_IO_RANGE) {
164 /* Ranges (_RNG) - flag bits[1:0] */
165
166 resource->address.attribute.io.range_attribute =
167 (u16) (flags & 0x03);
168
169 /* Translations (_TTP and _TRS) - flag bits[5:4] */
170
171 resource->address.attribute.io.translation_attribute =
172 (u16) ((flags >> 4) & 0x03);
173 }
174}
175
176/*******************************************************************************
177 *
178 * FUNCTION: acpi_rs_encode_specific_flags
179 *
180 * PARAMETERS: Resource - Address resource data struct
181 *
182 * RETURN: Encoded type-specific flag byte
183 *
184 * DESCRIPTION: Construct a type-specific flag byte from an attribute struct.
185 * Type-specific flags are only defined for the Memory and IO
186 * resource types.
187 *
188 ******************************************************************************/
189
190static u8 acpi_rs_encode_specific_flags(union acpi_resource_data *resource)
191{
Robert Mooreaff8c272005-09-02 17:24:17 -0400192 ACPI_FUNCTION_ENTRY();
193
194 if (resource->address.resource_type == ACPI_MEMORY_RANGE) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400195 return ((u8)
Robert Mooreaff8c272005-09-02 17:24:17 -0400196
Bob Moore50eca3e2005-09-30 19:03:00 -0400197 /* Write Status (_RW) - flag bit[0] */
198 ((resource->address.attribute.memory.
199 read_write_attribute & 0x01) |
200 /* Memory Attributes (_MEM) - flag bits[2:1] */
201 ((resource->address.attribute.memory.
202 cache_attribute & 0x03) << 1)));
Robert Mooreaff8c272005-09-02 17:24:17 -0400203 } else if (resource->address.resource_type == ACPI_IO_RANGE) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400204 return ((u8)
Robert Mooreaff8c272005-09-02 17:24:17 -0400205
Bob Moore50eca3e2005-09-30 19:03:00 -0400206 /* Ranges (_RNG) - flag bits[1:0] */
207 ((resource->address.attribute.io.
208 range_attribute & 0x03) |
209 /* Translations (_TTP and _TRS) - flag bits[5:4] */
210 ((resource->address.attribute.io.
211 translation_attribute & 0x03) << 4)));
Robert Mooreaff8c272005-09-02 17:24:17 -0400212 }
213
Bob Moore50eca3e2005-09-30 19:03:00 -0400214 return (0);
Robert Mooreaff8c272005-09-02 17:24:17 -0400215}
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/*******************************************************************************
218 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400219 * FUNCTION: acpi_rs_set_address_common
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400221 * PARAMETERS: Aml - Pointer to the AML resource descriptor
222 * Resource - Pointer to the internal resource struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400224 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400226 * DESCRIPTION: Convert common flag fields from a resource descriptor to an
227 * AML descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 *
229 ******************************************************************************/
Robert Mooreaff8c272005-09-02 17:24:17 -0400230
Bob Moore50eca3e2005-09-30 19:03:00 -0400231static void
232acpi_rs_set_address_common(union aml_resource *aml,
233 struct acpi_resource *resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Bob Moore50eca3e2005-09-30 19:03:00 -0400235 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Bob Moore50eca3e2005-09-30 19:03:00 -0400237 /* Set the Resource Type (Memory, Io, bus_number, etc.) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Bob Moore50eca3e2005-09-30 19:03:00 -0400239 aml->address.resource_type = (u8) resource->data.address.resource_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Robert Moore44f6c012005-04-18 22:49:35 -0400241 /* Set the general flags */
242
Bob Moore50eca3e2005-09-30 19:03:00 -0400243 aml->address.flags = acpi_rs_encode_general_flags(&resource->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Bob Moore50eca3e2005-09-30 19:03:00 -0400245 /* Set the type-specific flags */
Robert Moore44f6c012005-04-18 22:49:35 -0400246
Bob Moore50eca3e2005-09-30 19:03:00 -0400247 aml->address.specific_flags =
248 acpi_rs_encode_specific_flags(&resource->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251/*******************************************************************************
252 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400253 * FUNCTION: acpi_rs_get_address_common
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400255 * PARAMETERS: Resource - Pointer to the internal resource struct
256 * Aml - Pointer to the AML resource descriptor
257 *
258 * RETURN: TRUE if the resource_type field is OK, FALSE otherwise
259 *
260 * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
261 * to an internal resource descriptor
262 *
263 ******************************************************************************/
264
265static u8
266acpi_rs_get_address_common(struct acpi_resource *resource,
267 union aml_resource *aml)
268{
269 ACPI_FUNCTION_ENTRY();
270
271 /* Validate resource type */
272
273 if ((aml->address.resource_type > 2)
274 && (aml->address.resource_type < 0xC0)) {
275 return (FALSE);
276 }
277
278 /* Get the Resource Type (Memory, Io, bus_number, etc.) */
279
280 resource->data.address.resource_type = aml->address.resource_type;
281
282 /* Get the General Flags */
283
284 acpi_rs_decode_general_flags(&resource->data, aml->address.flags);
285
286 /* Get the Type-Specific Flags */
287
288 acpi_rs_decode_specific_flags(&resource->data,
289 aml->address.specific_flags);
290 return (TRUE);
291}
292
293/*******************************************************************************
294 *
295 * FUNCTION: acpi_rs_get_address16
296 *
297 * PARAMETERS: Aml - Pointer to the AML resource descriptor
298 * aml_resource_length - Length of the resource from the AML header
299 * Resource - Where the internal resource is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 *
301 * RETURN: Status
302 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400303 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
304 * internal resource descriptor, simplifying bitflags and handling
305 * alignment and endian issues if necessary.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 *
307 ******************************************************************************/
308
309acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400310acpi_rs_get_address16(union aml_resource * aml,
311 u16 aml_resource_length, struct acpi_resource * resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Bob Moore50eca3e2005-09-30 19:03:00 -0400313 ACPI_FUNCTION_TRACE("rs_get_address16");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Bob Moore50eca3e2005-09-30 19:03:00 -0400315 /* Get the Resource Type, general flags, and type-specific flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Bob Moore50eca3e2005-09-30 19:03:00 -0400317 if (!acpi_rs_get_address_common(resource, aml)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400318 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 /*
Bob Moore50eca3e2005-09-30 19:03:00 -0400322 * Get the following contiguous fields from the AML descriptor:
323 * Address Granularity
324 * Address Range Minimum
325 * Address Range Maximum
326 * Address Translation Offset
327 * Address Length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400329 acpi_rs_move_data(&resource->data.address16.granularity,
330 &aml->address16.granularity, 5,
331 ACPI_MOVE_TYPE_16_TO_32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Bob Moore50eca3e2005-09-30 19:03:00 -0400333 /* Get the optional resource_source (index and string) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Bob Moore50eca3e2005-09-30 19:03:00 -0400335 resource->length =
336 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16) +
337 acpi_rs_get_resource_source(aml_resource_length,
338 sizeof(struct aml_resource_address16),
339 &resource->data.address16.
340 resource_source, aml, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Bob Moore50eca3e2005-09-30 19:03:00 -0400342 /* Complete the resource header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Bob Moore50eca3e2005-09-30 19:03:00 -0400344 resource->type = ACPI_RESOURCE_TYPE_ADDRESS16;
Len Brown4be44fc2005-08-05 00:44:28 -0400345 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348/*******************************************************************************
349 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400350 * FUNCTION: acpi_rs_set_address16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400352 * PARAMETERS: Resource - Pointer to the resource descriptor
353 * Aml - Where the AML descriptor is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 *
355 * RETURN: Status
356 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400357 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
358 * external AML resource descriptor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 *
360 ******************************************************************************/
361
362acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400363acpi_rs_set_address16(struct acpi_resource *resource, union aml_resource *aml)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Bob Moore50eca3e2005-09-30 19:03:00 -0400365 acpi_size descriptor_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Bob Moore50eca3e2005-09-30 19:03:00 -0400367 ACPI_FUNCTION_TRACE("rs_set_address16");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Bob Moore50eca3e2005-09-30 19:03:00 -0400369 /* Set the Resource Type, General Flags, and Type-Specific Flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Bob Moore50eca3e2005-09-30 19:03:00 -0400371 acpi_rs_set_address_common(aml, resource);
Robert Moore44f6c012005-04-18 22:49:35 -0400372
Bob Moore50eca3e2005-09-30 19:03:00 -0400373 /*
374 * Set the following contiguous fields in the AML descriptor:
375 * Address Granularity
376 * Address Range Minimum
377 * Address Range Maximum
378 * Address Translation Offset
379 * Address Length
380 */
381 acpi_rs_move_data(&aml->address16.granularity,
382 &resource->data.address16.granularity, 5,
383 ACPI_MOVE_TYPE_32_TO_16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Robert Moore44f6c012005-04-18 22:49:35 -0400385 /* Resource Source Index and Resource Source are optional */
386
Bob Moore50eca3e2005-09-30 19:03:00 -0400387 descriptor_length = acpi_rs_set_resource_source(aml,
388 sizeof(struct
389 aml_resource_address16),
390 &resource->data.
391 address16.
392 resource_source);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Bob Moore50eca3e2005-09-30 19:03:00 -0400394 /* Complete the AML descriptor header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Bob Moore50eca3e2005-09-30 19:03:00 -0400396 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_ADDRESS16,
397 descriptor_length, aml);
Len Brown4be44fc2005-08-05 00:44:28 -0400398 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401/*******************************************************************************
402 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400403 * FUNCTION: acpi_rs_get_address32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400405 * PARAMETERS: Aml - Pointer to the AML resource descriptor
406 * aml_resource_length - Length of the resource from the AML header
407 * Resource - Where the internal resource is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 *
409 * RETURN: Status
410 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400411 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
412 * internal resource descriptor, simplifying bitflags and handling
413 * alignment and endian issues if necessary.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 *
415 ******************************************************************************/
416
417acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400418acpi_rs_get_address32(union aml_resource *aml,
419 u16 aml_resource_length, struct acpi_resource *resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Bob Moore50eca3e2005-09-30 19:03:00 -0400422 ACPI_FUNCTION_TRACE("rs_get_address32");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Bob Moore50eca3e2005-09-30 19:03:00 -0400424 /* Get the Resource Type, general flags, and type-specific flags */
Robert Mooreaff8c272005-09-02 17:24:17 -0400425
Bob Moore50eca3e2005-09-30 19:03:00 -0400426 if (!acpi_rs_get_address_common(resource, (void *)aml)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400427 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
Bob Moore50eca3e2005-09-30 19:03:00 -0400430 /*
431 * Get the following contiguous fields from the AML descriptor:
432 * Address Granularity
433 * Address Range Minimum
434 * Address Range Maximum
435 * Address Translation Offset
436 * Address Length
437 */
438 acpi_rs_move_data(&resource->data.address32.granularity,
439 &aml->address32.granularity, 5,
440 ACPI_MOVE_TYPE_32_TO_32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Bob Moore50eca3e2005-09-30 19:03:00 -0400442 /* Get the optional resource_source (index and string) */
Robert Moore44f6c012005-04-18 22:49:35 -0400443
Bob Moore50eca3e2005-09-30 19:03:00 -0400444 resource->length =
445 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32) +
446 acpi_rs_get_resource_source(aml_resource_length,
447 sizeof(struct aml_resource_address32),
448 &resource->data.address32.
449 resource_source, aml, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Bob Moore50eca3e2005-09-30 19:03:00 -0400451 /* Complete the resource header */
Robert Moore44f6c012005-04-18 22:49:35 -0400452
Bob Moore50eca3e2005-09-30 19:03:00 -0400453 resource->type = ACPI_RESOURCE_TYPE_ADDRESS32;
Len Brown4be44fc2005-08-05 00:44:28 -0400454 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457/*******************************************************************************
458 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400459 * FUNCTION: acpi_rs_set_address32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400461 * PARAMETERS: Resource - Pointer to the resource descriptor
462 * Aml - Where the AML descriptor is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 *
464 * RETURN: Status
465 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400466 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
467 * external AML resource descriptor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 *
469 ******************************************************************************/
470
471acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400472acpi_rs_set_address32(struct acpi_resource *resource, union aml_resource *aml)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Bob Moore50eca3e2005-09-30 19:03:00 -0400474 acpi_size descriptor_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Bob Moore50eca3e2005-09-30 19:03:00 -0400476 ACPI_FUNCTION_TRACE("rs_set_address32");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Bob Moore50eca3e2005-09-30 19:03:00 -0400478 /* Set the Resource Type, General Flags, and Type-Specific Flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Bob Moore50eca3e2005-09-30 19:03:00 -0400480 acpi_rs_set_address_common(aml, resource);
Robert Moore44f6c012005-04-18 22:49:35 -0400481
Bob Moore50eca3e2005-09-30 19:03:00 -0400482 /*
483 * Set the following contiguous fields in the AML descriptor:
484 * Address Granularity
485 * Address Range Minimum
486 * Address Range Maximum
487 * Address Translation Offset
488 * Address Length
489 */
490 acpi_rs_move_data(&aml->address32.granularity,
491 &resource->data.address32.granularity, 5,
492 ACPI_MOVE_TYPE_32_TO_32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Robert Moore44f6c012005-04-18 22:49:35 -0400494 /* Resource Source Index and Resource Source are optional */
495
Bob Moore50eca3e2005-09-30 19:03:00 -0400496 descriptor_length = acpi_rs_set_resource_source(aml,
497 sizeof(struct
498 aml_resource_address32),
499 &resource->data.
500 address32.
501 resource_source);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Bob Moore50eca3e2005-09-30 19:03:00 -0400503 /* Complete the AML descriptor header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Bob Moore50eca3e2005-09-30 19:03:00 -0400505 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_ADDRESS32,
506 descriptor_length, aml);
507 return_ACPI_STATUS(AE_OK);
508}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Bob Moore50eca3e2005-09-30 19:03:00 -0400510/*******************************************************************************
511 *
512 * FUNCTION: acpi_rs_get_address64
513 *
514 * PARAMETERS: Aml - Pointer to the AML resource descriptor
515 * aml_resource_length - Length of the resource from the AML header
516 * Resource - Where the internal resource is returned
517 *
518 * RETURN: Status
519 *
520 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
521 * internal resource descriptor, simplifying bitflags and handling
522 * alignment and endian issues if necessary.
523 *
524 ******************************************************************************/
525
526acpi_status
527acpi_rs_get_address64(union aml_resource *aml,
528 u16 aml_resource_length, struct acpi_resource *resource)
529{
530 ACPI_FUNCTION_TRACE("rs_get_address64");
531
532 /* Get the Resource Type, general Flags, and type-specific Flags */
533
534 if (!acpi_rs_get_address_common(resource, aml)) {
535 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
537
Bob Moore50eca3e2005-09-30 19:03:00 -0400538 /*
539 * Get the following contiguous fields from the AML descriptor:
540 * Address Granularity
541 * Address Range Minimum
542 * Address Range Maximum
543 * Address Translation Offset
544 * Address Length
545 */
546 acpi_rs_move_data(&resource->data.address64.granularity,
547 &aml->address64.granularity, 5,
548 ACPI_MOVE_TYPE_64_TO_64);
Robert Moore44f6c012005-04-18 22:49:35 -0400549
Bob Moore50eca3e2005-09-30 19:03:00 -0400550 /* Get the optional resource_source (index and string) */
551
552 resource->length =
553 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64) +
554 acpi_rs_get_resource_source(aml_resource_length,
555 sizeof(struct aml_resource_address64),
556 &resource->data.address64.
557 resource_source, aml, NULL);
558
559 /* Complete the resource header */
560
561 resource->type = ACPI_RESOURCE_TYPE_ADDRESS64;
562 return_ACPI_STATUS(AE_OK);
563}
564
565/*******************************************************************************
566 *
567 * FUNCTION: acpi_rs_set_address64
568 *
569 * PARAMETERS: Resource - Pointer to the resource descriptor
570 * Aml - Where the AML descriptor is returned
571 *
572 * RETURN: Status
573 *
574 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
575 * external AML resource descriptor.
576 *
577 ******************************************************************************/
578
579acpi_status
580acpi_rs_set_address64(struct acpi_resource *resource, union aml_resource *aml)
581{
582 acpi_size descriptor_length;
583
584 ACPI_FUNCTION_TRACE("rs_set_address64");
585
586 /* Set the Resource Type, General Flags, and Type-Specific Flags */
587
588 acpi_rs_set_address_common(aml, resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 /*
Bob Moore50eca3e2005-09-30 19:03:00 -0400591 * Set the following contiguous fields in the AML descriptor:
592 * Address Granularity
593 * Address Range Minimum
594 * Address Range Maximum
595 * Address Translation Offset
596 * Address Length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400598 acpi_rs_move_data(&aml->address64.granularity,
599 &resource->data.address64.granularity, 5,
600 ACPI_MOVE_TYPE_64_TO_64);
601
602 /* Resource Source Index and Resource Source are optional */
603
604 descriptor_length = acpi_rs_set_resource_source(aml,
605 sizeof(struct
606 aml_resource_address64),
607 &resource->data.
608 address64.
609 resource_source);
610
611 /* Complete the AML descriptor header */
612
613 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_ADDRESS64,
614 descriptor_length, aml);
615 return_ACPI_STATUS(AE_OK);
616}
617
618/*******************************************************************************
619 *
620 * FUNCTION: acpi_rs_get_ext_address64
621 *
622 * PARAMETERS: Aml - Pointer to the AML resource descriptor
623 * aml_resource_length - Length of the resource from the AML header
624 * Resource - Where the internal resource is returned
625 *
626 * RETURN: Status
627 *
628 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
629 * internal resource descriptor, simplifying bitflags and handling
630 * alignment and endian issues if necessary.
631 *
632 ******************************************************************************/
633
634acpi_status
635acpi_rs_get_ext_address64(union aml_resource *aml,
636 u16 aml_resource_length,
637 struct acpi_resource *resource)
638{
639
640 ACPI_FUNCTION_TRACE("rs_get_ext_address64");
641
642 /* Get the Resource Type, general flags, and type-specific flags */
643
644 if (!acpi_rs_get_address_common(resource, aml)) {
645 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
646 }
647
648 /*
649 * Get and validate the Revision ID
650 * Note: Only one revision ID is currently supported
651 */
652 resource->data.ext_address64.revision_iD =
653 aml->ext_address64.revision_iD;
654 if (aml->ext_address64.revision_iD !=
655 AML_RESOURCE_EXTENDED_ADDRESS_REVISION) {
656 return_ACPI_STATUS(AE_SUPPORT);
657 }
658
659 /*
660 * Get the following contiguous fields from the AML descriptor:
661 * Address Granularity
662 * Address Range Minimum
663 * Address Range Maximum
664 * Address Translation Offset
665 * Address Length
666 * Type-Specific Attribute
667 */
668 acpi_rs_move_data(&resource->data.ext_address64.granularity,
669 &aml->ext_address64.granularity, 6,
670 ACPI_MOVE_TYPE_64_TO_64);
671
672 /* Complete the resource header */
673
674 resource->type = ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64;
675 resource->length =
676 ACPI_SIZEOF_RESOURCE(struct acpi_resource_extended_address64);
677 return_ACPI_STATUS(AE_OK);
678}
679
680/*******************************************************************************
681 *
682 * FUNCTION: acpi_rs_set_ext_address64
683 *
684 * PARAMETERS: Resource - Pointer to the resource descriptor
685 * Aml - Where the AML descriptor is returned
686 *
687 * RETURN: Status
688 *
689 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
690 * external AML resource descriptor.
691 *
692 ******************************************************************************/
693
694acpi_status
695acpi_rs_set_ext_address64(struct acpi_resource *resource,
696 union aml_resource *aml)
697{
698 ACPI_FUNCTION_TRACE("rs_set_ext_address64");
699
700 /* Set the Resource Type, General Flags, and Type-Specific Flags */
701
702 acpi_rs_set_address_common(aml, resource);
703
704 /* Only one Revision ID is currently supported */
705
706 aml->ext_address64.revision_iD = AML_RESOURCE_EXTENDED_ADDRESS_REVISION;
707 aml->ext_address64.reserved = 0;
708
709 /*
710 * Set the following contiguous fields in the AML descriptor:
711 * Address Granularity
712 * Address Range Minimum
713 * Address Range Maximum
714 * Address Translation Offset
715 * Address Length
716 * Type-Specific Attribute
717 */
718 acpi_rs_move_data(&aml->ext_address64.granularity,
719 &resource->data.address64.granularity, 6,
720 ACPI_MOVE_TYPE_64_TO_64);
721
722 /* Complete the AML descriptor header */
723
724 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,
725 sizeof(struct
726 aml_resource_extended_address64),
727 aml);
Len Brown4be44fc2005-08-05 00:44:28 -0400728 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729}