blob: 23b54baa0cb2ebd6e451fff26967ba79b2b00eba [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
61/*******************************************************************************
62 *
63 * FUNCTION: acpi_rs_decode_general_flags
64 *
65 * PARAMETERS: Resource - Address resource data struct
66 * Flags - Actual flag byte
67 *
68 * RETURN: Decoded flag bits in resource struct
69 *
70 * DESCRIPTION: Decode a general flag byte to an address resource struct
71 *
72 ******************************************************************************/
73
74static void
75acpi_rs_decode_general_flags(union acpi_resource_data *resource, u8 flags)
76{
77 ACPI_FUNCTION_ENTRY();
78
79 /* Producer / Consumer - flag bit[0] */
80
81 resource->address.producer_consumer = (u32) (flags & 0x01);
82
83 /* Decode (_DEC) - flag bit[1] */
84
85 resource->address.decode = (u32) ((flags >> 1) & 0x01);
86
87 /* Min Address Fixed (_MIF) - flag bit[2] */
88
89 resource->address.min_address_fixed = (u32) ((flags >> 2) & 0x01);
90
91 /* Max Address Fixed (_MAF) - flag bit[3] */
92
93 resource->address.max_address_fixed = (u32) ((flags >> 3) & 0x01);
94}
95
96/*******************************************************************************
97 *
98 * FUNCTION: acpi_rs_encode_general_flags
99 *
100 * PARAMETERS: Resource - Address resource data struct
101 *
102 * RETURN: Encoded general flag byte
103 *
104 * DESCRIPTION: Construct a general flag byte from an address resource struct
105 *
106 ******************************************************************************/
107
108static u8 acpi_rs_encode_general_flags(union acpi_resource_data *resource)
109{
110 u8 flags;
111
112 ACPI_FUNCTION_ENTRY();
113
114 /* Producer / Consumer - flag bit[0] */
115
116 flags = (u8) (resource->address.producer_consumer & 0x01);
117
118 /* Decode (_DEC) - flag bit[1] */
119
120 flags |= (u8) ((resource->address.decode & 0x01) << 1);
121
122 /* Min Address Fixed (_MIF) - flag bit[2] */
123
124 flags |= (u8) ((resource->address.min_address_fixed & 0x01) << 2);
125
126 /* Max Address Fixed (_MAF) - flag bit[3] */
127
128 flags |= (u8) ((resource->address.max_address_fixed & 0x01) << 3);
129
130 return (flags);
131}
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_rs_decode_specific_flags
136 *
137 * PARAMETERS: Resource - Address resource data struct
138 * Flags - Actual flag byte
139 *
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{
192 u8 flags = 0;
193
194 ACPI_FUNCTION_ENTRY();
195
196 if (resource->address.resource_type == ACPI_MEMORY_RANGE) {
197 /* Write Status (_RW) - flag bit[0] */
198
199 flags = (u8)
200 (resource->address.attribute.memory.
201 read_write_attribute & 0x01);
202
203 /* Memory Attributes (_MEM) - flag bits[2:1] */
204
205 flags |= (u8)
206 ((resource->address.attribute.memory.
207 cache_attribute & 0x03) << 1);
208 } else if (resource->address.resource_type == ACPI_IO_RANGE) {
209 /* Ranges (_RNG) - flag bits[1:0] */
210
211 flags = (u8)
212 (resource->address.attribute.io.range_attribute & 0x03);
213
214 /* Translations (_TTP and _TRS) - flag bits[5:4] */
215
216 flags |= (u8)
217 ((resource->address.attribute.io.
218 translation_attribute & 0x03) << 4);
219 }
220
221 return (flags);
222}
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*******************************************************************************
225 *
226 * FUNCTION: acpi_rs_address16_resource
227 *
228 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
229 * stream
230 * bytes_consumed - Pointer to where the number of bytes
231 * consumed the byte_stream_buffer is
232 * returned
233 * output_buffer - Pointer to the return data buffer
234 * structure_size - Pointer to where the number of bytes
235 * in the return data struct is returned
236 *
237 * RETURN: Status
238 *
239 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
240 * structure pointed to by the output_buffer. Return the
241 * number of bytes consumed from the byte stream.
242 *
243 ******************************************************************************/
Robert Mooreaff8c272005-09-02 17:24:17 -0400244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400246acpi_rs_address16_resource(u8 * byte_stream_buffer,
247 acpi_size * bytes_consumed,
248 u8 ** output_buffer, acpi_size * structure_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Len Brown4be44fc2005-08-05 00:44:28 -0400250 u32 index;
251 u16 temp16;
252 u8 temp8;
253 u8 *temp_ptr;
254 u8 *buffer = byte_stream_buffer;
255 struct acpi_resource *output_struct = (void *)*output_buffer;
256 acpi_size struct_size =
257 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 ACPI_FUNCTION_TRACE("rs_address16_resource");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Robert Mooreaff8c272005-09-02 17:24:17 -0400261 /* Get the Descriptor Length field */
Robert Moore44f6c012005-04-18 22:49:35 -0400262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 buffer += 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400264 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266 /* Validate minimum descriptor length */
267
268 if (temp16 < 13) {
Len Brown4be44fc2005-08-05 00:44:28 -0400269 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271
272 *bytes_consumed = temp16 + 3;
273 output_struct->id = ACPI_RSTYPE_ADDRESS16;
274
Robert Moore44f6c012005-04-18 22:49:35 -0400275 /* Get the Resource Type (Byte3) */
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 buffer += 2;
278 temp8 = *buffer;
279
280 /* Values 0-2 and 0xC0-0xFF are valid */
281
282 if ((temp8 > 2) && (temp8 < 0xC0)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400283 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 output_struct->data.address16.resource_type = temp8;
287
Robert Moore44f6c012005-04-18 22:49:35 -0400288 /* Get the General Flags (Byte4) */
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 buffer += 1;
Robert Mooreaff8c272005-09-02 17:24:17 -0400291 acpi_rs_decode_general_flags(&output_struct->data, *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Robert Moore44f6c012005-04-18 22:49:35 -0400293 /* Get the Type Specific Flags (Byte5) */
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 buffer += 1;
Robert Mooreaff8c272005-09-02 17:24:17 -0400296 acpi_rs_decode_specific_flags(&output_struct->data, *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Robert Moore44f6c012005-04-18 22:49:35 -0400298 /* Get Granularity (Bytes 6-7) */
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 buffer += 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400301 ACPI_MOVE_16_TO_32(&output_struct->data.address16.granularity, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Robert Moore44f6c012005-04-18 22:49:35 -0400303 /* Get min_address_range (Bytes 8-9) */
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 buffer += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400306 ACPI_MOVE_16_TO_32(&output_struct->data.address16.min_address_range,
307 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Robert Moore44f6c012005-04-18 22:49:35 -0400309 /* Get max_address_range (Bytes 10-11) */
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 buffer += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400312 ACPI_MOVE_16_TO_32(&output_struct->data.address16.max_address_range,
313 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Robert Moore44f6c012005-04-18 22:49:35 -0400315 /* Get address_translation_offset (Bytes 12-13) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Robert Moore44f6c012005-04-18 22:49:35 -0400317 buffer += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400318 ACPI_MOVE_16_TO_32(&output_struct->data.address16.
319 address_translation_offset, buffer);
Robert Moore44f6c012005-04-18 22:49:35 -0400320
321 /* Get address_length (Bytes 14-15) */
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 buffer += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400324 ACPI_MOVE_16_TO_32(&output_struct->data.address16.address_length,
325 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Robert Moore44f6c012005-04-18 22:49:35 -0400327 /* Resource Source Index (if present) */
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 buffer += 2;
330
331 /*
332 * This will leave us pointing to the Resource Source Index
333 * If it is present, then save it off and calculate the
334 * pointer to where the null terminated string goes:
335 * Each Interrupt takes 32-bits + the 5 bytes of the
336 * stream that are default.
337 *
338 * Note: Some resource descriptors will have an additional null, so
339 * we add 1 to the length.
340 */
341 if (*bytes_consumed > (16 + 1)) {
342 /* Dereference the Index */
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 output_struct->data.address16.resource_source.index =
Robert Mooreaff8c272005-09-02 17:24:17 -0400345 (u32) * buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 /* Point to the String */
348
349 buffer += 1;
350
351 /* Point the String pointer to the end of this structure */
352
353 output_struct->data.address16.resource_source.string_ptr =
Len Brown4be44fc2005-08-05 00:44:28 -0400354 (char *)((u8 *) output_struct + struct_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Robert Moore44f6c012005-04-18 22:49:35 -0400356 temp_ptr = (u8 *)
Len Brown4be44fc2005-08-05 00:44:28 -0400357 output_struct->data.address16.resource_source.string_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Robert Mooreaff8c272005-09-02 17:24:17 -0400359 /* Copy the resource_source string into the buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 index = 0;
Robert Mooreaff8c272005-09-02 17:24:17 -0400362 while (*buffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 *temp_ptr = *buffer;
364
Robert Mooreaff8c272005-09-02 17:24:17 -0400365 temp_ptr++;
366 buffer++;
367 index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
Robert Mooreaff8c272005-09-02 17:24:17 -0400370 /* Add the terminating null and set the string length */
Robert Moore44f6c012005-04-18 22:49:35 -0400371
Robert Mooreaff8c272005-09-02 17:24:17 -0400372 *temp_ptr = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400373 output_struct->data.address16.resource_source.string_length =
374 index + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /*
377 * In order for the struct_size to fall on a 32-bit boundary,
378 * calculate the length of the string and expand the
379 * struct_size to the next 32-bit boundary.
380 */
381 temp8 = (u8) (index + 1);
Len Brown4be44fc2005-08-05 00:44:28 -0400382 struct_size += ACPI_ROUND_UP_to_32_bITS(temp8);
383 } else {
Robert Mooreaff8c272005-09-02 17:24:17 -0400384 output_struct->data.address16.resource_source.index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 output_struct->data.address16.resource_source.string_length = 0;
386 output_struct->data.address16.resource_source.string_ptr = NULL;
387 }
388
Robert Moore44f6c012005-04-18 22:49:35 -0400389 /* Set the Length parameter */
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 output_struct->length = (u32) struct_size;
392
Robert Moore44f6c012005-04-18 22:49:35 -0400393 /* Return the final size of the structure */
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 *structure_size = struct_size;
Len Brown4be44fc2005-08-05 00:44:28 -0400396 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399/*******************************************************************************
400 *
401 * FUNCTION: acpi_rs_address16_stream
402 *
403 * PARAMETERS: linked_list - Pointer to the resource linked list
404 * output_buffer - Pointer to the user's return buffer
405 * bytes_consumed - Pointer to where the number of bytes
406 * used in the output_buffer is returned
407 *
408 * RETURN: Status
409 *
410 * DESCRIPTION: Take the linked list resource structure and fills in the
411 * the appropriate bytes in a byte stream
412 *
413 ******************************************************************************/
414
415acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400416acpi_rs_address16_stream(struct acpi_resource *linked_list,
417 u8 ** output_buffer, acpi_size * bytes_consumed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Len Brown4be44fc2005-08-05 00:44:28 -0400419 u8 *buffer = *output_buffer;
420 u8 *length_field;
Len Brown4be44fc2005-08-05 00:44:28 -0400421 acpi_size actual_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 ACPI_FUNCTION_TRACE("rs_address16_stream");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Robert Mooreaff8c272005-09-02 17:24:17 -0400425 /* Set the Descriptor Type field */
Robert Moore44f6c012005-04-18 22:49:35 -0400426
Robert Mooreaff8c272005-09-02 17:24:17 -0400427 *buffer = ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 buffer += 1;
429
Robert Moore44f6c012005-04-18 22:49:35 -0400430 /* Save a pointer to the Length field - to be filled in later */
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 length_field = buffer;
433 buffer += 2;
434
Robert Moore44f6c012005-04-18 22:49:35 -0400435 /* Set the Resource Type (Memory, Io, bus_number) */
436
Robert Mooreaff8c272005-09-02 17:24:17 -0400437 *buffer = (u8) (linked_list->data.address16.resource_type & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 buffer += 1;
439
Robert Moore44f6c012005-04-18 22:49:35 -0400440 /* Set the general flags */
441
Robert Mooreaff8c272005-09-02 17:24:17 -0400442 *buffer = acpi_rs_encode_general_flags(&linked_list->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 buffer += 1;
444
Robert Moore44f6c012005-04-18 22:49:35 -0400445 /* Set the type specific flags */
446
Robert Mooreaff8c272005-09-02 17:24:17 -0400447 *buffer = acpi_rs_encode_specific_flags(&linked_list->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 buffer += 1;
449
Robert Moore44f6c012005-04-18 22:49:35 -0400450 /* Set the address space granularity */
451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 ACPI_MOVE_32_TO_16(buffer, &linked_list->data.address16.granularity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 buffer += 2;
454
Robert Moore44f6c012005-04-18 22:49:35 -0400455 /* Set the address range minimum */
456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 ACPI_MOVE_32_TO_16(buffer,
458 &linked_list->data.address16.min_address_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 buffer += 2;
460
Robert Moore44f6c012005-04-18 22:49:35 -0400461 /* Set the address range maximum */
462
Len Brown4be44fc2005-08-05 00:44:28 -0400463 ACPI_MOVE_32_TO_16(buffer,
464 &linked_list->data.address16.max_address_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 buffer += 2;
466
Robert Moore44f6c012005-04-18 22:49:35 -0400467 /* Set the address translation offset */
468
Len Brown4be44fc2005-08-05 00:44:28 -0400469 ACPI_MOVE_32_TO_16(buffer,
470 &linked_list->data.address16.
471 address_translation_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 buffer += 2;
473
Robert Moore44f6c012005-04-18 22:49:35 -0400474 /* Set the address length */
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476 ACPI_MOVE_32_TO_16(buffer, &linked_list->data.address16.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 buffer += 2;
478
Robert Moore44f6c012005-04-18 22:49:35 -0400479 /* Resource Source Index and Resource Source are optional */
480
Robert Mooreaff8c272005-09-02 17:24:17 -0400481 if (linked_list->data.address16.resource_source.string_length) {
482 *buffer =
483 (u8) linked_list->data.address16.resource_source.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 buffer += 1;
485
Robert Mooreaff8c272005-09-02 17:24:17 -0400486 /* Copy the resource_source string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Robert Mooreaff8c272005-09-02 17:24:17 -0400488 ACPI_STRCPY((char *)buffer,
Len Brown4be44fc2005-08-05 00:44:28 -0400489 linked_list->data.address16.resource_source.
490 string_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 /*
Robert Mooreaff8c272005-09-02 17:24:17 -0400493 * Buffer needs to be set to the length of the string + one for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 * terminating null
495 */
Len Brown4be44fc2005-08-05 00:44:28 -0400496 buffer +=
497 (acpi_size) (ACPI_STRLEN
498 (linked_list->data.address16.resource_source.
499 string_ptr) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501
Robert Moore44f6c012005-04-18 22:49:35 -0400502 /* Return the number of bytes consumed in this operation */
503
Len Brown4be44fc2005-08-05 00:44:28 -0400504 actual_bytes = ACPI_PTR_DIFF(buffer, *output_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 *bytes_consumed = actual_bytes;
506
507 /*
508 * Set the length field to the number of bytes consumed
509 * minus the header size (3 bytes)
510 */
511 actual_bytes -= 3;
Len Brown4be44fc2005-08-05 00:44:28 -0400512 ACPI_MOVE_SIZE_TO_16(length_field, &actual_bytes);
513 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516/*******************************************************************************
517 *
518 * FUNCTION: acpi_rs_address32_resource
519 *
520 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
521 * stream
522 * bytes_consumed - Pointer to where the number of bytes
523 * consumed the byte_stream_buffer is
524 * returned
525 * output_buffer - Pointer to the return data buffer
526 * structure_size - Pointer to where the number of bytes
527 * in the return data struct is returned
528 *
529 * RETURN: Status
530 *
531 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
532 * structure pointed to by the output_buffer. Return the
533 * number of bytes consumed from the byte stream.
534 *
535 ******************************************************************************/
536
537acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400538acpi_rs_address32_resource(u8 * byte_stream_buffer,
539 acpi_size * bytes_consumed,
540 u8 ** output_buffer, acpi_size * structure_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Len Brown4be44fc2005-08-05 00:44:28 -0400542 u16 temp16;
543 u8 temp8;
544 u8 *temp_ptr;
Len Brown4be44fc2005-08-05 00:44:28 -0400545 u32 index;
Robert Mooreaff8c272005-09-02 17:24:17 -0400546 u8 *buffer = byte_stream_buffer;
547 struct acpi_resource *output_struct = (void *)*output_buffer;
548 acpi_size struct_size =
549 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 ACPI_FUNCTION_TRACE("rs_address32_resource");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Robert Mooreaff8c272005-09-02 17:24:17 -0400553 /* Get the Descriptor Length field */
Robert Moore44f6c012005-04-18 22:49:35 -0400554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 buffer += 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400556 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 /* Validate minimum descriptor length */
559
560 if (temp16 < 23) {
Len Brown4be44fc2005-08-05 00:44:28 -0400561 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563
564 *bytes_consumed = temp16 + 3;
565 output_struct->id = ACPI_RSTYPE_ADDRESS32;
566
Robert Moore44f6c012005-04-18 22:49:35 -0400567 /* Get the Resource Type (Byte3) */
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 buffer += 2;
570 temp8 = *buffer;
571
572 /* Values 0-2 and 0xC0-0xFF are valid */
573
574 if ((temp8 > 2) && (temp8 < 0xC0)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400575 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
578 output_struct->data.address32.resource_type = temp8;
579
Robert Moore44f6c012005-04-18 22:49:35 -0400580 /* Get the General Flags (Byte4) */
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 buffer += 1;
Robert Mooreaff8c272005-09-02 17:24:17 -0400583 acpi_rs_decode_general_flags(&output_struct->data, *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Robert Moore44f6c012005-04-18 22:49:35 -0400585 /* Get the Type Specific Flags (Byte5) */
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 buffer += 1;
Robert Mooreaff8c272005-09-02 17:24:17 -0400588 acpi_rs_decode_specific_flags(&output_struct->data, *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Robert Moore44f6c012005-04-18 22:49:35 -0400590 /* Get Granularity (Bytes 6-9) */
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 buffer += 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400593 ACPI_MOVE_32_TO_32(&output_struct->data.address32.granularity, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Robert Moore44f6c012005-04-18 22:49:35 -0400595 /* Get min_address_range (Bytes 10-13) */
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 buffer += 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400598 ACPI_MOVE_32_TO_32(&output_struct->data.address32.min_address_range,
599 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Robert Moore44f6c012005-04-18 22:49:35 -0400601 /* Get max_address_range (Bytes 14-17) */
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 buffer += 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400604 ACPI_MOVE_32_TO_32(&output_struct->data.address32.max_address_range,
605 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Robert Moore44f6c012005-04-18 22:49:35 -0400607 /* Get address_translation_offset (Bytes 18-21) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Robert Moore44f6c012005-04-18 22:49:35 -0400609 buffer += 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400610 ACPI_MOVE_32_TO_32(&output_struct->data.address32.
611 address_translation_offset, buffer);
Robert Moore44f6c012005-04-18 22:49:35 -0400612
613 /* Get address_length (Bytes 22-25) */
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 buffer += 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400616 ACPI_MOVE_32_TO_32(&output_struct->data.address32.address_length,
617 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Robert Moore44f6c012005-04-18 22:49:35 -0400619 /* Resource Source Index (if present) */
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 buffer += 4;
622
623 /*
624 * This will leave us pointing to the Resource Source Index
625 * If it is present, then save it off and calculate the
626 * pointer to where the null terminated string goes:
627 *
628 * Note: Some resource descriptors will have an additional null, so
629 * we add 1 to the length.
630 */
631 if (*bytes_consumed > (26 + 1)) {
632 /* Dereference the Index */
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 output_struct->data.address32.resource_source.index =
Robert Mooreaff8c272005-09-02 17:24:17 -0400635 (u32) * buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 /* Point to the String */
638
639 buffer += 1;
640
641 /* Point the String pointer to the end of this structure */
642
643 output_struct->data.address32.resource_source.string_ptr =
Len Brown4be44fc2005-08-05 00:44:28 -0400644 (char *)((u8 *) output_struct + struct_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Robert Moore44f6c012005-04-18 22:49:35 -0400646 temp_ptr = (u8 *)
Len Brown4be44fc2005-08-05 00:44:28 -0400647 output_struct->data.address32.resource_source.string_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Robert Mooreaff8c272005-09-02 17:24:17 -0400649 /* Copy the resource_source string into the buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 index = 0;
Robert Mooreaff8c272005-09-02 17:24:17 -0400652 while (*buffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 *temp_ptr = *buffer;
654
Robert Mooreaff8c272005-09-02 17:24:17 -0400655 temp_ptr++;
656 buffer++;
657 index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
Robert Mooreaff8c272005-09-02 17:24:17 -0400660 /* Add the terminating null and set the string length */
Robert Moore44f6c012005-04-18 22:49:35 -0400661
Robert Mooreaff8c272005-09-02 17:24:17 -0400662 *temp_ptr = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400663 output_struct->data.address32.resource_source.string_length =
664 index + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 /*
667 * In order for the struct_size to fall on a 32-bit boundary,
668 * calculate the length of the string and expand the
669 * struct_size to the next 32-bit boundary.
670 */
671 temp8 = (u8) (index + 1);
Len Brown4be44fc2005-08-05 00:44:28 -0400672 struct_size += ACPI_ROUND_UP_to_32_bITS(temp8);
673 } else {
Robert Mooreaff8c272005-09-02 17:24:17 -0400674 output_struct->data.address32.resource_source.index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 output_struct->data.address32.resource_source.string_length = 0;
676 output_struct->data.address32.resource_source.string_ptr = NULL;
677 }
678
Robert Moore44f6c012005-04-18 22:49:35 -0400679 /* Set the Length parameter */
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 output_struct->length = (u32) struct_size;
682
Robert Moore44f6c012005-04-18 22:49:35 -0400683 /* Return the final size of the structure */
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 *structure_size = struct_size;
Len Brown4be44fc2005-08-05 00:44:28 -0400686 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689/*******************************************************************************
690 *
691 * FUNCTION: acpi_rs_address32_stream
692 *
693 * PARAMETERS: linked_list - Pointer to the resource linked list
694 * output_buffer - Pointer to the user's return buffer
695 * bytes_consumed - Pointer to where the number of bytes
696 * used in the output_buffer is returned
697 *
698 * RETURN: Status
699 *
700 * DESCRIPTION: Take the linked list resource structure and fills in the
701 * the appropriate bytes in a byte stream
702 *
703 ******************************************************************************/
704
705acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400706acpi_rs_address32_stream(struct acpi_resource *linked_list,
707 u8 ** output_buffer, acpi_size * bytes_consumed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Len Brown4be44fc2005-08-05 00:44:28 -0400709 u8 *buffer;
710 u16 *length_field;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Len Brown4be44fc2005-08-05 00:44:28 -0400712 ACPI_FUNCTION_TRACE("rs_address32_stream");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
714 buffer = *output_buffer;
715
Robert Mooreaff8c272005-09-02 17:24:17 -0400716 /* Set the Descriptor Type field */
Robert Moore44f6c012005-04-18 22:49:35 -0400717
Robert Mooreaff8c272005-09-02 17:24:17 -0400718 *buffer = ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 buffer += 1;
720
Robert Mooreaff8c272005-09-02 17:24:17 -0400721 /* Save a pointer to the Length field - to be filled in later */
Robert Moore44f6c012005-04-18 22:49:35 -0400722
Len Brown4be44fc2005-08-05 00:44:28 -0400723 length_field = ACPI_CAST_PTR(u16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 buffer += 2;
725
Robert Moore44f6c012005-04-18 22:49:35 -0400726 /* Set the Resource Type (Memory, Io, bus_number) */
727
Robert Mooreaff8c272005-09-02 17:24:17 -0400728 *buffer = (u8) (linked_list->data.address32.resource_type & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 buffer += 1;
730
Robert Moore44f6c012005-04-18 22:49:35 -0400731 /* Set the general flags */
732
Robert Mooreaff8c272005-09-02 17:24:17 -0400733 *buffer = acpi_rs_encode_general_flags(&linked_list->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 buffer += 1;
735
Robert Moore44f6c012005-04-18 22:49:35 -0400736 /* Set the type specific flags */
737
Robert Mooreaff8c272005-09-02 17:24:17 -0400738 *buffer = acpi_rs_encode_specific_flags(&linked_list->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 buffer += 1;
740
Robert Moore44f6c012005-04-18 22:49:35 -0400741 /* Set the address space granularity */
742
Len Brown4be44fc2005-08-05 00:44:28 -0400743 ACPI_MOVE_32_TO_32(buffer, &linked_list->data.address32.granularity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 buffer += 4;
745
Robert Moore44f6c012005-04-18 22:49:35 -0400746 /* Set the address range minimum */
747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 ACPI_MOVE_32_TO_32(buffer,
749 &linked_list->data.address32.min_address_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 buffer += 4;
751
Robert Moore44f6c012005-04-18 22:49:35 -0400752 /* Set the address range maximum */
753
Len Brown4be44fc2005-08-05 00:44:28 -0400754 ACPI_MOVE_32_TO_32(buffer,
755 &linked_list->data.address32.max_address_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 buffer += 4;
757
Robert Moore44f6c012005-04-18 22:49:35 -0400758 /* Set the address translation offset */
759
Len Brown4be44fc2005-08-05 00:44:28 -0400760 ACPI_MOVE_32_TO_32(buffer,
761 &linked_list->data.address32.
762 address_translation_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 buffer += 4;
764
Robert Moore44f6c012005-04-18 22:49:35 -0400765 /* Set the address length */
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767 ACPI_MOVE_32_TO_32(buffer, &linked_list->data.address32.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 buffer += 4;
769
Robert Moore44f6c012005-04-18 22:49:35 -0400770 /* Resource Source Index and Resource Source are optional */
771
Robert Mooreaff8c272005-09-02 17:24:17 -0400772 if (linked_list->data.address32.resource_source.string_length) {
773 *buffer =
774 (u8) linked_list->data.address32.resource_source.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 buffer += 1;
776
Robert Mooreaff8c272005-09-02 17:24:17 -0400777 /* Copy the resource_source string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Robert Mooreaff8c272005-09-02 17:24:17 -0400779 ACPI_STRCPY((char *)buffer,
Len Brown4be44fc2005-08-05 00:44:28 -0400780 linked_list->data.address32.resource_source.
781 string_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783 /*
Robert Mooreaff8c272005-09-02 17:24:17 -0400784 * Buffer needs to be set to the length of the string + one for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 * terminating null
786 */
Len Brown4be44fc2005-08-05 00:44:28 -0400787 buffer +=
788 (acpi_size) (ACPI_STRLEN
789 (linked_list->data.address32.resource_source.
790 string_ptr) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792
Robert Moore44f6c012005-04-18 22:49:35 -0400793 /* Return the number of bytes consumed in this operation */
794
Len Brown4be44fc2005-08-05 00:44:28 -0400795 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 /*
798 * Set the length field to the number of bytes consumed
Robert Mooreaff8c272005-09-02 17:24:17 -0400799 * minus the header size (3 bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 */
801 *length_field = (u16) (*bytes_consumed - 3);
Len Brown4be44fc2005-08-05 00:44:28 -0400802 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803}
804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805/*******************************************************************************
806 *
807 * FUNCTION: acpi_rs_address64_resource
808 *
809 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
810 * stream
811 * bytes_consumed - Pointer to where the number of bytes
812 * consumed the byte_stream_buffer is
813 * returned
814 * output_buffer - Pointer to the return data buffer
815 * structure_size - Pointer to where the number of bytes
816 * in the return data struct is returned
817 *
818 * RETURN: Status
819 *
820 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
821 * structure pointed to by the output_buffer. Return the
822 * number of bytes consumed from the byte stream.
823 *
824 ******************************************************************************/
825
826acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400827acpi_rs_address64_resource(u8 * byte_stream_buffer,
828 acpi_size * bytes_consumed,
829 u8 ** output_buffer, acpi_size * structure_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Len Brown4be44fc2005-08-05 00:44:28 -0400831 u16 temp16;
832 u8 temp8;
833 u8 resource_type;
834 u8 *temp_ptr;
Len Brown4be44fc2005-08-05 00:44:28 -0400835 u32 index;
Robert Mooreaff8c272005-09-02 17:24:17 -0400836 u8 *buffer = byte_stream_buffer;
837 struct acpi_resource *output_struct = (void *)*output_buffer;
838 acpi_size struct_size =
839 ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Len Brown4be44fc2005-08-05 00:44:28 -0400841 ACPI_FUNCTION_TRACE("rs_address64_resource");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Robert Mooreaff8c272005-09-02 17:24:17 -0400843 /* Get the Descriptor Type */
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 resource_type = *buffer;
846
Robert Mooreaff8c272005-09-02 17:24:17 -0400847 /* Get the Descriptor Length field */
Robert Moore44f6c012005-04-18 22:49:35 -0400848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 buffer += 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400850 ACPI_MOVE_16_TO_16(&temp16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 /* Validate minimum descriptor length */
853
854 if (temp16 < 43) {
Len Brown4be44fc2005-08-05 00:44:28 -0400855 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
857
858 *bytes_consumed = temp16 + 3;
859 output_struct->id = ACPI_RSTYPE_ADDRESS64;
860
Robert Moore44f6c012005-04-18 22:49:35 -0400861 /* Get the Resource Type (Byte3) */
862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 buffer += 2;
864 temp8 = *buffer;
865
866 /* Values 0-2 and 0xC0-0xFF are valid */
867
868 if ((temp8 > 2) && (temp8 < 0xC0)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400869 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871
872 output_struct->data.address64.resource_type = temp8;
873
Robert Moore44f6c012005-04-18 22:49:35 -0400874 /* Get the General Flags (Byte4) */
875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 buffer += 1;
Robert Mooreaff8c272005-09-02 17:24:17 -0400877 acpi_rs_decode_general_flags(&output_struct->data, *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Robert Moore44f6c012005-04-18 22:49:35 -0400879 /* Get the Type Specific Flags (Byte5) */
880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 buffer += 1;
Robert Mooreaff8c272005-09-02 17:24:17 -0400882 acpi_rs_decode_specific_flags(&output_struct->data, *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) {
885 /* Move past revision_id and Reserved byte */
886
887 buffer += 2;
888 }
889
Robert Moore44f6c012005-04-18 22:49:35 -0400890 /* Get Granularity (Bytes 6-13) or (Bytes 8-15) */
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 buffer += 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400893 ACPI_MOVE_64_TO_64(&output_struct->data.address64.granularity, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Robert Moore44f6c012005-04-18 22:49:35 -0400895 /* Get min_address_range (Bytes 14-21) or (Bytes 16-23) */
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 buffer += 8;
Len Brown4be44fc2005-08-05 00:44:28 -0400898 ACPI_MOVE_64_TO_64(&output_struct->data.address64.min_address_range,
899 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Robert Moore44f6c012005-04-18 22:49:35 -0400901 /* Get max_address_range (Bytes 22-29) or (Bytes 24-31) */
902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 buffer += 8;
Len Brown4be44fc2005-08-05 00:44:28 -0400904 ACPI_MOVE_64_TO_64(&output_struct->data.address64.max_address_range,
905 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Robert Moore44f6c012005-04-18 22:49:35 -0400907 /* Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Robert Moore44f6c012005-04-18 22:49:35 -0400909 buffer += 8;
Len Brown4be44fc2005-08-05 00:44:28 -0400910 ACPI_MOVE_64_TO_64(&output_struct->data.address64.
911 address_translation_offset, buffer);
Robert Moore44f6c012005-04-18 22:49:35 -0400912
913 /* Get address_length (Bytes 38-45) or (Bytes 40-47) */
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 buffer += 8;
Len Brown4be44fc2005-08-05 00:44:28 -0400916 ACPI_MOVE_64_TO_64(&output_struct->data.address64.address_length,
917 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Robert Mooreaff8c272005-09-02 17:24:17 -0400919 output_struct->data.address64.resource_source.index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 output_struct->data.address64.resource_source.string_length = 0;
921 output_struct->data.address64.resource_source.string_ptr = NULL;
922
923 if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) {
924 /* Get type_specific_attribute (Bytes 48-55) */
925
926 buffer += 8;
Len Brown4be44fc2005-08-05 00:44:28 -0400927 ACPI_MOVE_64_TO_64(&output_struct->data.address64.
928 type_specific_attributes, buffer);
929 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 output_struct->data.address64.type_specific_attributes = 0;
931
Robert Moore44f6c012005-04-18 22:49:35 -0400932 /* Resource Source Index (if present) */
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 buffer += 8;
935
936 /*
937 * This will leave us pointing to the Resource Source Index
938 * If it is present, then save it off and calculate the
939 * pointer to where the null terminated string goes:
940 * Each Interrupt takes 32-bits + the 5 bytes of the
941 * stream that are default.
942 *
943 * Note: Some resource descriptors will have an additional null, so
944 * we add 1 to the length.
945 */
946 if (*bytes_consumed > (46 + 1)) {
947 /* Dereference the Index */
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 output_struct->data.address64.resource_source.index =
Robert Mooreaff8c272005-09-02 17:24:17 -0400950 (u32) * buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /* Point to the String */
953
954 buffer += 1;
955
956 /* Point the String pointer to the end of this structure */
957
Len Brown4be44fc2005-08-05 00:44:28 -0400958 output_struct->data.address64.resource_source.
959 string_ptr =
960 (char *)((u8 *) output_struct + struct_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Robert Moore44f6c012005-04-18 22:49:35 -0400962 temp_ptr = (u8 *)
Len Brown4be44fc2005-08-05 00:44:28 -0400963 output_struct->data.address64.resource_source.
964 string_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Robert Mooreaff8c272005-09-02 17:24:17 -0400966 /* Copy the resource_source string into the buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 index = 0;
Robert Mooreaff8c272005-09-02 17:24:17 -0400969 while (*buffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 *temp_ptr = *buffer;
971
Robert Mooreaff8c272005-09-02 17:24:17 -0400972 temp_ptr++;
973 buffer++;
974 index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976
977 /*
Robert Mooreaff8c272005-09-02 17:24:17 -0400978 * Add the terminating null and set the string length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 */
Robert Mooreaff8c272005-09-02 17:24:17 -0400980 *temp_ptr = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400981 output_struct->data.address64.resource_source.
982 string_length = index + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 /*
985 * In order for the struct_size to fall on a 32-bit boundary,
986 * calculate the length of the string and expand the
987 * struct_size to the next 32-bit boundary.
988 */
989 temp8 = (u8) (index + 1);
Len Brown4be44fc2005-08-05 00:44:28 -0400990 struct_size += ACPI_ROUND_UP_to_32_bITS(temp8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
992 }
993
Robert Moore44f6c012005-04-18 22:49:35 -0400994 /* Set the Length parameter */
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 output_struct->length = (u32) struct_size;
997
Robert Moore44f6c012005-04-18 22:49:35 -0400998 /* Return the final size of the structure */
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 *structure_size = struct_size;
Len Brown4be44fc2005-08-05 00:44:28 -04001001 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004/*******************************************************************************
1005 *
1006 * FUNCTION: acpi_rs_address64_stream
1007 *
1008 * PARAMETERS: linked_list - Pointer to the resource linked list
1009 * output_buffer - Pointer to the user's return buffer
1010 * bytes_consumed - Pointer to where the number of bytes
1011 * used in the output_buffer is returned
1012 *
1013 * RETURN: Status
1014 *
1015 * DESCRIPTION: Take the linked list resource structure and fills in the
1016 * the appropriate bytes in a byte stream
1017 *
1018 ******************************************************************************/
1019
1020acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001021acpi_rs_address64_stream(struct acpi_resource *linked_list,
1022 u8 ** output_buffer, acpi_size * bytes_consumed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023{
Len Brown4be44fc2005-08-05 00:44:28 -04001024 u8 *buffer;
1025 u16 *length_field;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Len Brown4be44fc2005-08-05 00:44:28 -04001027 ACPI_FUNCTION_TRACE("rs_address64_stream");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 buffer = *output_buffer;
1030
Robert Mooreaff8c272005-09-02 17:24:17 -04001031 /* Set the Descriptor Type field */
Robert Moore44f6c012005-04-18 22:49:35 -04001032
Robert Mooreaff8c272005-09-02 17:24:17 -04001033 *buffer = ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 buffer += 1;
1035
Robert Mooreaff8c272005-09-02 17:24:17 -04001036 /* Save a pointer to the Length field - to be filled in later */
Robert Moore44f6c012005-04-18 22:49:35 -04001037
Len Brown4be44fc2005-08-05 00:44:28 -04001038 length_field = ACPI_CAST_PTR(u16, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 buffer += 2;
1040
Robert Moore44f6c012005-04-18 22:49:35 -04001041 /* Set the Resource Type (Memory, Io, bus_number) */
1042
Robert Mooreaff8c272005-09-02 17:24:17 -04001043 *buffer = (u8) (linked_list->data.address64.resource_type & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 buffer += 1;
1045
Robert Moore44f6c012005-04-18 22:49:35 -04001046 /* Set the general flags */
1047
Robert Mooreaff8c272005-09-02 17:24:17 -04001048 *buffer = acpi_rs_encode_general_flags(&linked_list->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 buffer += 1;
1050
Robert Moore44f6c012005-04-18 22:49:35 -04001051 /* Set the type specific flags */
1052
Robert Mooreaff8c272005-09-02 17:24:17 -04001053 *buffer = acpi_rs_encode_specific_flags(&linked_list->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 buffer += 1;
1055
Robert Moore44f6c012005-04-18 22:49:35 -04001056 /* Set the address space granularity */
1057
Len Brown4be44fc2005-08-05 00:44:28 -04001058 ACPI_MOVE_64_TO_64(buffer, &linked_list->data.address64.granularity);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 buffer += 8;
1060
Robert Moore44f6c012005-04-18 22:49:35 -04001061 /* Set the address range minimum */
1062
Len Brown4be44fc2005-08-05 00:44:28 -04001063 ACPI_MOVE_64_TO_64(buffer,
1064 &linked_list->data.address64.min_address_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 buffer += 8;
1066
Robert Moore44f6c012005-04-18 22:49:35 -04001067 /* Set the address range maximum */
1068
Len Brown4be44fc2005-08-05 00:44:28 -04001069 ACPI_MOVE_64_TO_64(buffer,
1070 &linked_list->data.address64.max_address_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 buffer += 8;
1072
Robert Moore44f6c012005-04-18 22:49:35 -04001073 /* Set the address translation offset */
1074
Len Brown4be44fc2005-08-05 00:44:28 -04001075 ACPI_MOVE_64_TO_64(buffer,
1076 &linked_list->data.address64.
1077 address_translation_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 buffer += 8;
1079
Robert Moore44f6c012005-04-18 22:49:35 -04001080 /* Set the address length */
1081
Len Brown4be44fc2005-08-05 00:44:28 -04001082 ACPI_MOVE_64_TO_64(buffer, &linked_list->data.address64.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 buffer += 8;
1084
Robert Moore44f6c012005-04-18 22:49:35 -04001085 /* Resource Source Index and Resource Source are optional */
1086
Robert Mooreaff8c272005-09-02 17:24:17 -04001087 if (linked_list->data.address64.resource_source.string_length) {
1088 *buffer =
1089 (u8) linked_list->data.address64.resource_source.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 buffer += 1;
1091
Robert Mooreaff8c272005-09-02 17:24:17 -04001092 /* Copy the resource_source string */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Robert Mooreaff8c272005-09-02 17:24:17 -04001094 ACPI_STRCPY((char *)buffer,
Len Brown4be44fc2005-08-05 00:44:28 -04001095 linked_list->data.address64.resource_source.
1096 string_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 /*
Robert Mooreaff8c272005-09-02 17:24:17 -04001099 * Buffer needs to be set to the length of the string + one for the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 * terminating null
1101 */
Len Brown4be44fc2005-08-05 00:44:28 -04001102 buffer +=
1103 (acpi_size) (ACPI_STRLEN
1104 (linked_list->data.address64.resource_source.
1105 string_ptr) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 }
1107
Robert Moore44f6c012005-04-18 22:49:35 -04001108 /* Return the number of bytes consumed in this operation */
1109
Len Brown4be44fc2005-08-05 00:44:28 -04001110 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 /*
1113 * Set the length field to the number of bytes consumed
1114 * minus the header size (3 bytes)
1115 */
1116 *length_field = (u16) (*bytes_consumed - 3);
Len Brown4be44fc2005-08-05 00:44:28 -04001117 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}