Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
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 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acresrc.h> | |
46 | ||
47 | #define _COMPONENT ACPI_RESOURCES | |
4be44fcd | 48 | ACPI_MODULE_NAME("rsaddr") |
1da177e4 | 49 | |
aff8c277 RM |
50 | /* Local prototypes */ |
51 | static void | |
52 | acpi_rs_decode_general_flags(union acpi_resource_data *resource, u8 flags); | |
53 | ||
54 | static u8 acpi_rs_encode_general_flags(union acpi_resource_data *resource); | |
55 | ||
56 | static void | |
57 | acpi_rs_decode_specific_flags(union acpi_resource_data *resource, u8 flags); | |
58 | ||
59 | static 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 | ||
74 | static void | |
75 | acpi_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 | ||
108 | static 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 | ||
148 | static void | |
149 | acpi_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 | ||
190 | static 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 | ||
1da177e4 LT |
224 | /******************************************************************************* |
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 | ******************************************************************************/ | |
aff8c277 | 244 | |
1da177e4 | 245 | acpi_status |
4be44fcd LB |
246 | acpi_rs_address16_resource(u8 * byte_stream_buffer, |
247 | acpi_size * bytes_consumed, | |
248 | u8 ** output_buffer, acpi_size * structure_size) | |
1da177e4 | 249 | { |
4be44fcd LB |
250 | 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); | |
1da177e4 | 258 | |
4be44fcd | 259 | ACPI_FUNCTION_TRACE("rs_address16_resource"); |
1da177e4 | 260 | |
aff8c277 | 261 | /* Get the Descriptor Length field */ |
44f6c012 | 262 | |
1da177e4 | 263 | buffer += 1; |
4be44fcd | 264 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
1da177e4 LT |
265 | |
266 | /* Validate minimum descriptor length */ | |
267 | ||
268 | if (temp16 < 13) { | |
4be44fcd | 269 | return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); |
1da177e4 LT |
270 | } |
271 | ||
272 | *bytes_consumed = temp16 + 3; | |
273 | output_struct->id = ACPI_RSTYPE_ADDRESS16; | |
274 | ||
44f6c012 RM |
275 | /* Get the Resource Type (Byte3) */ |
276 | ||
1da177e4 LT |
277 | buffer += 2; |
278 | temp8 = *buffer; | |
279 | ||
280 | /* Values 0-2 and 0xC0-0xFF are valid */ | |
281 | ||
282 | if ((temp8 > 2) && (temp8 < 0xC0)) { | |
4be44fcd | 283 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
1da177e4 LT |
284 | } |
285 | ||
286 | output_struct->data.address16.resource_type = temp8; | |
287 | ||
44f6c012 RM |
288 | /* Get the General Flags (Byte4) */ |
289 | ||
1da177e4 | 290 | buffer += 1; |
aff8c277 | 291 | acpi_rs_decode_general_flags(&output_struct->data, *buffer); |
1da177e4 | 292 | |
44f6c012 RM |
293 | /* Get the Type Specific Flags (Byte5) */ |
294 | ||
1da177e4 | 295 | buffer += 1; |
aff8c277 | 296 | acpi_rs_decode_specific_flags(&output_struct->data, *buffer); |
1da177e4 | 297 | |
44f6c012 RM |
298 | /* Get Granularity (Bytes 6-7) */ |
299 | ||
1da177e4 | 300 | buffer += 1; |
4be44fcd | 301 | ACPI_MOVE_16_TO_32(&output_struct->data.address16.granularity, buffer); |
1da177e4 | 302 | |
44f6c012 RM |
303 | /* Get min_address_range (Bytes 8-9) */ |
304 | ||
1da177e4 | 305 | buffer += 2; |
4be44fcd LB |
306 | ACPI_MOVE_16_TO_32(&output_struct->data.address16.min_address_range, |
307 | buffer); | |
1da177e4 | 308 | |
44f6c012 RM |
309 | /* Get max_address_range (Bytes 10-11) */ |
310 | ||
1da177e4 | 311 | buffer += 2; |
4be44fcd LB |
312 | ACPI_MOVE_16_TO_32(&output_struct->data.address16.max_address_range, |
313 | buffer); | |
1da177e4 | 314 | |
44f6c012 RM |
315 | /* Get address_translation_offset (Bytes 12-13) */ |
316 | ||
1da177e4 | 317 | buffer += 2; |
4be44fcd LB |
318 | ACPI_MOVE_16_TO_32(&output_struct->data.address16. |
319 | address_translation_offset, buffer); | |
44f6c012 RM |
320 | |
321 | /* Get address_length (Bytes 14-15) */ | |
1da177e4 | 322 | |
1da177e4 | 323 | buffer += 2; |
4be44fcd LB |
324 | ACPI_MOVE_16_TO_32(&output_struct->data.address16.address_length, |
325 | buffer); | |
1da177e4 | 326 | |
44f6c012 RM |
327 | /* Resource Source Index (if present) */ |
328 | ||
1da177e4 LT |
329 | 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 | ||
4be44fcd | 344 | output_struct->data.address16.resource_source.index = |
aff8c277 | 345 | (u32) * buffer; |
1da177e4 LT |
346 | |
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 = | |
4be44fcd | 354 | (char *)((u8 *) output_struct + struct_size); |
1da177e4 | 355 | |
44f6c012 | 356 | temp_ptr = (u8 *) |
4be44fcd | 357 | output_struct->data.address16.resource_source.string_ptr; |
1da177e4 | 358 | |
aff8c277 | 359 | /* Copy the resource_source string into the buffer */ |
1da177e4 LT |
360 | |
361 | index = 0; | |
aff8c277 | 362 | while (*buffer) { |
1da177e4 LT |
363 | *temp_ptr = *buffer; |
364 | ||
aff8c277 RM |
365 | temp_ptr++; |
366 | buffer++; | |
367 | index++; | |
1da177e4 LT |
368 | } |
369 | ||
aff8c277 | 370 | /* Add the terminating null and set the string length */ |
1da177e4 | 371 | |
aff8c277 | 372 | *temp_ptr = 0; |
4be44fcd LB |
373 | output_struct->data.address16.resource_source.string_length = |
374 | index + 1; | |
1da177e4 LT |
375 | |
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); | |
4be44fcd LB |
382 | struct_size += ACPI_ROUND_UP_to_32_bITS(temp8); |
383 | } else { | |
aff8c277 | 384 | output_struct->data.address16.resource_source.index = 0; |
1da177e4 LT |
385 | output_struct->data.address16.resource_source.string_length = 0; |
386 | output_struct->data.address16.resource_source.string_ptr = NULL; | |
387 | } | |
388 | ||
44f6c012 RM |
389 | /* Set the Length parameter */ |
390 | ||
1da177e4 LT |
391 | output_struct->length = (u32) struct_size; |
392 | ||
44f6c012 RM |
393 | /* Return the final size of the structure */ |
394 | ||
1da177e4 | 395 | *structure_size = struct_size; |
4be44fcd | 396 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
397 | } |
398 | ||
1da177e4 LT |
399 | /******************************************************************************* |
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 | ||
415 | acpi_status | |
4be44fcd LB |
416 | acpi_rs_address16_stream(struct acpi_resource *linked_list, |
417 | u8 ** output_buffer, acpi_size * bytes_consumed) | |
1da177e4 | 418 | { |
4be44fcd LB |
419 | u8 *buffer = *output_buffer; |
420 | u8 *length_field; | |
4be44fcd | 421 | acpi_size actual_bytes; |
1da177e4 | 422 | |
4be44fcd | 423 | ACPI_FUNCTION_TRACE("rs_address16_stream"); |
1da177e4 | 424 | |
aff8c277 | 425 | /* Set the Descriptor Type field */ |
44f6c012 | 426 | |
aff8c277 | 427 | *buffer = ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE; |
1da177e4 LT |
428 | buffer += 1; |
429 | ||
44f6c012 RM |
430 | /* Save a pointer to the Length field - to be filled in later */ |
431 | ||
1da177e4 LT |
432 | length_field = buffer; |
433 | buffer += 2; | |
434 | ||
44f6c012 RM |
435 | /* Set the Resource Type (Memory, Io, bus_number) */ |
436 | ||
aff8c277 | 437 | *buffer = (u8) (linked_list->data.address16.resource_type & 0x03); |
1da177e4 LT |
438 | buffer += 1; |
439 | ||
44f6c012 RM |
440 | /* Set the general flags */ |
441 | ||
aff8c277 | 442 | *buffer = acpi_rs_encode_general_flags(&linked_list->data); |
1da177e4 LT |
443 | buffer += 1; |
444 | ||
44f6c012 RM |
445 | /* Set the type specific flags */ |
446 | ||
aff8c277 | 447 | *buffer = acpi_rs_encode_specific_flags(&linked_list->data); |
1da177e4 LT |
448 | buffer += 1; |
449 | ||
44f6c012 RM |
450 | /* Set the address space granularity */ |
451 | ||
4be44fcd | 452 | ACPI_MOVE_32_TO_16(buffer, &linked_list->data.address16.granularity); |
1da177e4 LT |
453 | buffer += 2; |
454 | ||
44f6c012 RM |
455 | /* Set the address range minimum */ |
456 | ||
4be44fcd LB |
457 | ACPI_MOVE_32_TO_16(buffer, |
458 | &linked_list->data.address16.min_address_range); | |
1da177e4 LT |
459 | buffer += 2; |
460 | ||
44f6c012 RM |
461 | /* Set the address range maximum */ |
462 | ||
4be44fcd LB |
463 | ACPI_MOVE_32_TO_16(buffer, |
464 | &linked_list->data.address16.max_address_range); | |
1da177e4 LT |
465 | buffer += 2; |
466 | ||
44f6c012 RM |
467 | /* Set the address translation offset */ |
468 | ||
4be44fcd LB |
469 | ACPI_MOVE_32_TO_16(buffer, |
470 | &linked_list->data.address16. | |
471 | address_translation_offset); | |
1da177e4 LT |
472 | buffer += 2; |
473 | ||
44f6c012 RM |
474 | /* Set the address length */ |
475 | ||
4be44fcd | 476 | ACPI_MOVE_32_TO_16(buffer, &linked_list->data.address16.address_length); |
1da177e4 LT |
477 | buffer += 2; |
478 | ||
44f6c012 RM |
479 | /* Resource Source Index and Resource Source are optional */ |
480 | ||
aff8c277 RM |
481 | if (linked_list->data.address16.resource_source.string_length) { |
482 | *buffer = | |
483 | (u8) linked_list->data.address16.resource_source.index; | |
1da177e4 LT |
484 | buffer += 1; |
485 | ||
aff8c277 | 486 | /* Copy the resource_source string */ |
44f6c012 | 487 | |
aff8c277 | 488 | ACPI_STRCPY((char *)buffer, |
4be44fcd LB |
489 | linked_list->data.address16.resource_source. |
490 | string_ptr); | |
1da177e4 LT |
491 | |
492 | /* | |
aff8c277 | 493 | * Buffer needs to be set to the length of the string + one for the |
1da177e4 LT |
494 | * terminating null |
495 | */ | |
4be44fcd LB |
496 | buffer += |
497 | (acpi_size) (ACPI_STRLEN | |
498 | (linked_list->data.address16.resource_source. | |
499 | string_ptr) + 1); | |
1da177e4 LT |
500 | } |
501 | ||
44f6c012 RM |
502 | /* Return the number of bytes consumed in this operation */ |
503 | ||
4be44fcd | 504 | actual_bytes = ACPI_PTR_DIFF(buffer, *output_buffer); |
1da177e4 LT |
505 | *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; | |
4be44fcd LB |
512 | ACPI_MOVE_SIZE_TO_16(length_field, &actual_bytes); |
513 | return_ACPI_STATUS(AE_OK); | |
1da177e4 LT |
514 | } |
515 | ||
1da177e4 LT |
516 | /******************************************************************************* |
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 | ||
537 | acpi_status | |
4be44fcd LB |
538 | acpi_rs_address32_resource(u8 * byte_stream_buffer, |
539 | acpi_size * bytes_consumed, | |
540 | u8 ** output_buffer, acpi_size * structure_size) | |
1da177e4 | 541 | { |
4be44fcd LB |
542 | u16 temp16; |
543 | u8 temp8; | |
544 | u8 *temp_ptr; | |
4be44fcd | 545 | u32 index; |
aff8c277 RM |
546 | 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); | |
1da177e4 | 550 | |
4be44fcd | 551 | ACPI_FUNCTION_TRACE("rs_address32_resource"); |
1da177e4 | 552 | |
aff8c277 | 553 | /* Get the Descriptor Length field */ |
44f6c012 | 554 | |
1da177e4 | 555 | buffer += 1; |
4be44fcd | 556 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
1da177e4 LT |
557 | |
558 | /* Validate minimum descriptor length */ | |
559 | ||
560 | if (temp16 < 23) { | |
4be44fcd | 561 | return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); |
1da177e4 LT |
562 | } |
563 | ||
564 | *bytes_consumed = temp16 + 3; | |
565 | output_struct->id = ACPI_RSTYPE_ADDRESS32; | |
566 | ||
44f6c012 RM |
567 | /* Get the Resource Type (Byte3) */ |
568 | ||
1da177e4 LT |
569 | buffer += 2; |
570 | temp8 = *buffer; | |
571 | ||
572 | /* Values 0-2 and 0xC0-0xFF are valid */ | |
573 | ||
574 | if ((temp8 > 2) && (temp8 < 0xC0)) { | |
4be44fcd | 575 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
1da177e4 LT |
576 | } |
577 | ||
578 | output_struct->data.address32.resource_type = temp8; | |
579 | ||
44f6c012 RM |
580 | /* Get the General Flags (Byte4) */ |
581 | ||
1da177e4 | 582 | buffer += 1; |
aff8c277 | 583 | acpi_rs_decode_general_flags(&output_struct->data, *buffer); |
1da177e4 | 584 | |
44f6c012 RM |
585 | /* Get the Type Specific Flags (Byte5) */ |
586 | ||
1da177e4 | 587 | buffer += 1; |
aff8c277 | 588 | acpi_rs_decode_specific_flags(&output_struct->data, *buffer); |
1da177e4 | 589 | |
44f6c012 RM |
590 | /* Get Granularity (Bytes 6-9) */ |
591 | ||
1da177e4 | 592 | buffer += 1; |
4be44fcd | 593 | ACPI_MOVE_32_TO_32(&output_struct->data.address32.granularity, buffer); |
1da177e4 | 594 | |
44f6c012 RM |
595 | /* Get min_address_range (Bytes 10-13) */ |
596 | ||
1da177e4 | 597 | buffer += 4; |
4be44fcd LB |
598 | ACPI_MOVE_32_TO_32(&output_struct->data.address32.min_address_range, |
599 | buffer); | |
1da177e4 | 600 | |
44f6c012 RM |
601 | /* Get max_address_range (Bytes 14-17) */ |
602 | ||
1da177e4 | 603 | buffer += 4; |
4be44fcd LB |
604 | ACPI_MOVE_32_TO_32(&output_struct->data.address32.max_address_range, |
605 | buffer); | |
1da177e4 | 606 | |
44f6c012 RM |
607 | /* Get address_translation_offset (Bytes 18-21) */ |
608 | ||
1da177e4 | 609 | buffer += 4; |
4be44fcd LB |
610 | ACPI_MOVE_32_TO_32(&output_struct->data.address32. |
611 | address_translation_offset, buffer); | |
44f6c012 RM |
612 | |
613 | /* Get address_length (Bytes 22-25) */ | |
1da177e4 | 614 | |
1da177e4 | 615 | buffer += 4; |
4be44fcd LB |
616 | ACPI_MOVE_32_TO_32(&output_struct->data.address32.address_length, |
617 | buffer); | |
1da177e4 | 618 | |
44f6c012 RM |
619 | /* Resource Source Index (if present) */ |
620 | ||
1da177e4 LT |
621 | 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 | ||
1da177e4 | 634 | output_struct->data.address32.resource_source.index = |
aff8c277 | 635 | (u32) * buffer; |
1da177e4 LT |
636 | |
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 = | |
4be44fcd | 644 | (char *)((u8 *) output_struct + struct_size); |
1da177e4 | 645 | |
44f6c012 | 646 | temp_ptr = (u8 *) |
4be44fcd | 647 | output_struct->data.address32.resource_source.string_ptr; |
1da177e4 | 648 | |
aff8c277 | 649 | /* Copy the resource_source string into the buffer */ |
1da177e4 LT |
650 | |
651 | index = 0; | |
aff8c277 | 652 | while (*buffer) { |
1da177e4 LT |
653 | *temp_ptr = *buffer; |
654 | ||
aff8c277 RM |
655 | temp_ptr++; |
656 | buffer++; | |
657 | index++; | |
1da177e4 LT |
658 | } |
659 | ||
aff8c277 | 660 | /* Add the terminating null and set the string length */ |
44f6c012 | 661 | |
aff8c277 | 662 | *temp_ptr = 0; |
4be44fcd LB |
663 | output_struct->data.address32.resource_source.string_length = |
664 | index + 1; | |
1da177e4 LT |
665 | |
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); | |
4be44fcd LB |
672 | struct_size += ACPI_ROUND_UP_to_32_bITS(temp8); |
673 | } else { | |
aff8c277 | 674 | output_struct->data.address32.resource_source.index = 0; |
1da177e4 LT |
675 | output_struct->data.address32.resource_source.string_length = 0; |
676 | output_struct->data.address32.resource_source.string_ptr = NULL; | |
677 | } | |
678 | ||
44f6c012 RM |
679 | /* Set the Length parameter */ |
680 | ||
1da177e4 LT |
681 | output_struct->length = (u32) struct_size; |
682 | ||
44f6c012 RM |
683 | /* Return the final size of the structure */ |
684 | ||
1da177e4 | 685 | *structure_size = struct_size; |
4be44fcd | 686 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
687 | } |
688 | ||
1da177e4 LT |
689 | /******************************************************************************* |
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 | ||
705 | acpi_status | |
4be44fcd LB |
706 | acpi_rs_address32_stream(struct acpi_resource *linked_list, |
707 | u8 ** output_buffer, acpi_size * bytes_consumed) | |
1da177e4 | 708 | { |
4be44fcd LB |
709 | u8 *buffer; |
710 | u16 *length_field; | |
1da177e4 | 711 | |
4be44fcd | 712 | ACPI_FUNCTION_TRACE("rs_address32_stream"); |
1da177e4 LT |
713 | |
714 | buffer = *output_buffer; | |
715 | ||
aff8c277 | 716 | /* Set the Descriptor Type field */ |
44f6c012 | 717 | |
aff8c277 | 718 | *buffer = ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE; |
1da177e4 LT |
719 | buffer += 1; |
720 | ||
aff8c277 | 721 | /* Save a pointer to the Length field - to be filled in later */ |
44f6c012 | 722 | |
4be44fcd | 723 | length_field = ACPI_CAST_PTR(u16, buffer); |
1da177e4 LT |
724 | buffer += 2; |
725 | ||
44f6c012 RM |
726 | /* Set the Resource Type (Memory, Io, bus_number) */ |
727 | ||
aff8c277 | 728 | *buffer = (u8) (linked_list->data.address32.resource_type & 0x03); |
1da177e4 LT |
729 | buffer += 1; |
730 | ||
44f6c012 RM |
731 | /* Set the general flags */ |
732 | ||
aff8c277 | 733 | *buffer = acpi_rs_encode_general_flags(&linked_list->data); |
1da177e4 LT |
734 | buffer += 1; |
735 | ||
44f6c012 RM |
736 | /* Set the type specific flags */ |
737 | ||
aff8c277 | 738 | *buffer = acpi_rs_encode_specific_flags(&linked_list->data); |
1da177e4 LT |
739 | buffer += 1; |
740 | ||
44f6c012 RM |
741 | /* Set the address space granularity */ |
742 | ||
4be44fcd | 743 | ACPI_MOVE_32_TO_32(buffer, &linked_list->data.address32.granularity); |
1da177e4 LT |
744 | buffer += 4; |
745 | ||
44f6c012 RM |
746 | /* Set the address range minimum */ |
747 | ||
4be44fcd LB |
748 | ACPI_MOVE_32_TO_32(buffer, |
749 | &linked_list->data.address32.min_address_range); | |
1da177e4 LT |
750 | buffer += 4; |
751 | ||
44f6c012 RM |
752 | /* Set the address range maximum */ |
753 | ||
4be44fcd LB |
754 | ACPI_MOVE_32_TO_32(buffer, |
755 | &linked_list->data.address32.max_address_range); | |
1da177e4 LT |
756 | buffer += 4; |
757 | ||
44f6c012 RM |
758 | /* Set the address translation offset */ |
759 | ||
4be44fcd LB |
760 | ACPI_MOVE_32_TO_32(buffer, |
761 | &linked_list->data.address32. | |
762 | address_translation_offset); | |
1da177e4 LT |
763 | buffer += 4; |
764 | ||
44f6c012 RM |
765 | /* Set the address length */ |
766 | ||
4be44fcd | 767 | ACPI_MOVE_32_TO_32(buffer, &linked_list->data.address32.address_length); |
1da177e4 LT |
768 | buffer += 4; |
769 | ||
44f6c012 RM |
770 | /* Resource Source Index and Resource Source are optional */ |
771 | ||
aff8c277 RM |
772 | if (linked_list->data.address32.resource_source.string_length) { |
773 | *buffer = | |
774 | (u8) linked_list->data.address32.resource_source.index; | |
1da177e4 LT |
775 | buffer += 1; |
776 | ||
aff8c277 | 777 | /* Copy the resource_source string */ |
44f6c012 | 778 | |
aff8c277 | 779 | ACPI_STRCPY((char *)buffer, |
4be44fcd LB |
780 | linked_list->data.address32.resource_source. |
781 | string_ptr); | |
1da177e4 LT |
782 | |
783 | /* | |
aff8c277 | 784 | * Buffer needs to be set to the length of the string + one for the |
1da177e4 LT |
785 | * terminating null |
786 | */ | |
4be44fcd LB |
787 | buffer += |
788 | (acpi_size) (ACPI_STRLEN | |
789 | (linked_list->data.address32.resource_source. | |
790 | string_ptr) + 1); | |
1da177e4 LT |
791 | } |
792 | ||
44f6c012 RM |
793 | /* Return the number of bytes consumed in this operation */ |
794 | ||
4be44fcd | 795 | *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer); |
1da177e4 LT |
796 | |
797 | /* | |
798 | * Set the length field to the number of bytes consumed | |
aff8c277 | 799 | * minus the header size (3 bytes) |
1da177e4 LT |
800 | */ |
801 | *length_field = (u16) (*bytes_consumed - 3); | |
4be44fcd | 802 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
803 | } |
804 | ||
1da177e4 LT |
805 | /******************************************************************************* |
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 | ||
826 | acpi_status | |
4be44fcd LB |
827 | acpi_rs_address64_resource(u8 * byte_stream_buffer, |
828 | acpi_size * bytes_consumed, | |
829 | u8 ** output_buffer, acpi_size * structure_size) | |
1da177e4 | 830 | { |
4be44fcd LB |
831 | u16 temp16; |
832 | u8 temp8; | |
833 | u8 resource_type; | |
834 | u8 *temp_ptr; | |
4be44fcd | 835 | u32 index; |
aff8c277 RM |
836 | 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); | |
1da177e4 | 840 | |
4be44fcd | 841 | ACPI_FUNCTION_TRACE("rs_address64_resource"); |
1da177e4 | 842 | |
aff8c277 RM |
843 | /* Get the Descriptor Type */ |
844 | ||
1da177e4 LT |
845 | resource_type = *buffer; |
846 | ||
aff8c277 | 847 | /* Get the Descriptor Length field */ |
44f6c012 | 848 | |
1da177e4 | 849 | buffer += 1; |
4be44fcd | 850 | ACPI_MOVE_16_TO_16(&temp16, buffer); |
1da177e4 LT |
851 | |
852 | /* Validate minimum descriptor length */ | |
853 | ||
854 | if (temp16 < 43) { | |
4be44fcd | 855 | return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); |
1da177e4 LT |
856 | } |
857 | ||
858 | *bytes_consumed = temp16 + 3; | |
859 | output_struct->id = ACPI_RSTYPE_ADDRESS64; | |
860 | ||
44f6c012 RM |
861 | /* Get the Resource Type (Byte3) */ |
862 | ||
1da177e4 LT |
863 | buffer += 2; |
864 | temp8 = *buffer; | |
865 | ||
866 | /* Values 0-2 and 0xC0-0xFF are valid */ | |
867 | ||
868 | if ((temp8 > 2) && (temp8 < 0xC0)) { | |
4be44fcd | 869 | return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); |
1da177e4 LT |
870 | } |
871 | ||
872 | output_struct->data.address64.resource_type = temp8; | |
873 | ||
44f6c012 RM |
874 | /* Get the General Flags (Byte4) */ |
875 | ||
1da177e4 | 876 | buffer += 1; |
aff8c277 | 877 | acpi_rs_decode_general_flags(&output_struct->data, *buffer); |
1da177e4 | 878 | |
44f6c012 RM |
879 | /* Get the Type Specific Flags (Byte5) */ |
880 | ||
1da177e4 | 881 | buffer += 1; |
aff8c277 | 882 | acpi_rs_decode_specific_flags(&output_struct->data, *buffer); |
1da177e4 LT |
883 | |
884 | if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) { | |
885 | /* Move past revision_id and Reserved byte */ | |
886 | ||
887 | buffer += 2; | |
888 | } | |
889 | ||
44f6c012 RM |
890 | /* Get Granularity (Bytes 6-13) or (Bytes 8-15) */ |
891 | ||
1da177e4 | 892 | buffer += 1; |
4be44fcd | 893 | ACPI_MOVE_64_TO_64(&output_struct->data.address64.granularity, buffer); |
1da177e4 | 894 | |
44f6c012 RM |
895 | /* Get min_address_range (Bytes 14-21) or (Bytes 16-23) */ |
896 | ||
1da177e4 | 897 | buffer += 8; |
4be44fcd LB |
898 | ACPI_MOVE_64_TO_64(&output_struct->data.address64.min_address_range, |
899 | buffer); | |
1da177e4 | 900 | |
44f6c012 RM |
901 | /* Get max_address_range (Bytes 22-29) or (Bytes 24-31) */ |
902 | ||
1da177e4 | 903 | buffer += 8; |
4be44fcd LB |
904 | ACPI_MOVE_64_TO_64(&output_struct->data.address64.max_address_range, |
905 | buffer); | |
1da177e4 | 906 | |
44f6c012 RM |
907 | /* Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) */ |
908 | ||
1da177e4 | 909 | buffer += 8; |
4be44fcd LB |
910 | ACPI_MOVE_64_TO_64(&output_struct->data.address64. |
911 | address_translation_offset, buffer); | |
44f6c012 RM |
912 | |
913 | /* Get address_length (Bytes 38-45) or (Bytes 40-47) */ | |
1da177e4 | 914 | |
1da177e4 | 915 | buffer += 8; |
4be44fcd LB |
916 | ACPI_MOVE_64_TO_64(&output_struct->data.address64.address_length, |
917 | buffer); | |
1da177e4 | 918 | |
aff8c277 | 919 | output_struct->data.address64.resource_source.index = 0; |
1da177e4 LT |
920 | 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; | |
4be44fcd LB |
927 | ACPI_MOVE_64_TO_64(&output_struct->data.address64. |
928 | type_specific_attributes, buffer); | |
929 | } else { | |
1da177e4 LT |
930 | output_struct->data.address64.type_specific_attributes = 0; |
931 | ||
44f6c012 RM |
932 | /* Resource Source Index (if present) */ |
933 | ||
1da177e4 LT |
934 | 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 | ||
1da177e4 | 949 | output_struct->data.address64.resource_source.index = |
aff8c277 | 950 | (u32) * buffer; |
1da177e4 LT |
951 | |
952 | /* Point to the String */ | |
953 | ||
954 | buffer += 1; | |
955 | ||
956 | /* Point the String pointer to the end of this structure */ | |
957 | ||
4be44fcd LB |
958 | output_struct->data.address64.resource_source. |
959 | string_ptr = | |
960 | (char *)((u8 *) output_struct + struct_size); | |
1da177e4 | 961 | |
44f6c012 | 962 | temp_ptr = (u8 *) |
4be44fcd LB |
963 | output_struct->data.address64.resource_source. |
964 | string_ptr; | |
1da177e4 | 965 | |
aff8c277 | 966 | /* Copy the resource_source string into the buffer */ |
1da177e4 LT |
967 | |
968 | index = 0; | |
aff8c277 | 969 | while (*buffer) { |
1da177e4 LT |
970 | *temp_ptr = *buffer; |
971 | ||
aff8c277 RM |
972 | temp_ptr++; |
973 | buffer++; | |
974 | index++; | |
1da177e4 LT |
975 | } |
976 | ||
977 | /* | |
aff8c277 | 978 | * Add the terminating null and set the string length |
1da177e4 | 979 | */ |
aff8c277 | 980 | *temp_ptr = 0; |
4be44fcd LB |
981 | output_struct->data.address64.resource_source. |
982 | string_length = index + 1; | |
1da177e4 LT |
983 | |
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); | |
4be44fcd | 990 | struct_size += ACPI_ROUND_UP_to_32_bITS(temp8); |
1da177e4 LT |
991 | } |
992 | } | |
993 | ||
44f6c012 RM |
994 | /* Set the Length parameter */ |
995 | ||
1da177e4 LT |
996 | output_struct->length = (u32) struct_size; |
997 | ||
44f6c012 RM |
998 | /* Return the final size of the structure */ |
999 | ||
1da177e4 | 1000 | *structure_size = struct_size; |
4be44fcd | 1001 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
1002 | } |
1003 | ||
1da177e4 LT |
1004 | /******************************************************************************* |
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 | ||
1020 | acpi_status | |
4be44fcd LB |
1021 | acpi_rs_address64_stream(struct acpi_resource *linked_list, |
1022 | u8 ** output_buffer, acpi_size * bytes_consumed) | |
1da177e4 | 1023 | { |
4be44fcd LB |
1024 | u8 *buffer; |
1025 | u16 *length_field; | |
1da177e4 | 1026 | |
4be44fcd | 1027 | ACPI_FUNCTION_TRACE("rs_address64_stream"); |
1da177e4 LT |
1028 | |
1029 | buffer = *output_buffer; | |
1030 | ||
aff8c277 | 1031 | /* Set the Descriptor Type field */ |
44f6c012 | 1032 | |
aff8c277 | 1033 | *buffer = ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE; |
1da177e4 LT |
1034 | buffer += 1; |
1035 | ||
aff8c277 | 1036 | /* Save a pointer to the Length field - to be filled in later */ |
44f6c012 | 1037 | |
4be44fcd | 1038 | length_field = ACPI_CAST_PTR(u16, buffer); |
1da177e4 LT |
1039 | buffer += 2; |
1040 | ||
44f6c012 RM |
1041 | /* Set the Resource Type (Memory, Io, bus_number) */ |
1042 | ||
aff8c277 | 1043 | *buffer = (u8) (linked_list->data.address64.resource_type & 0x03); |
1da177e4 LT |
1044 | buffer += 1; |
1045 | ||
44f6c012 RM |
1046 | /* Set the general flags */ |
1047 | ||
aff8c277 | 1048 | *buffer = acpi_rs_encode_general_flags(&linked_list->data); |
1da177e4 LT |
1049 | buffer += 1; |
1050 | ||
44f6c012 RM |
1051 | /* Set the type specific flags */ |
1052 | ||
aff8c277 | 1053 | *buffer = acpi_rs_encode_specific_flags(&linked_list->data); |
1da177e4 LT |
1054 | buffer += 1; |
1055 | ||
44f6c012 RM |
1056 | /* Set the address space granularity */ |
1057 | ||
4be44fcd | 1058 | ACPI_MOVE_64_TO_64(buffer, &linked_list->data.address64.granularity); |
1da177e4 LT |
1059 | buffer += 8; |
1060 | ||
44f6c012 RM |
1061 | /* Set the address range minimum */ |
1062 | ||
4be44fcd LB |
1063 | ACPI_MOVE_64_TO_64(buffer, |
1064 | &linked_list->data.address64.min_address_range); | |
1da177e4 LT |
1065 | buffer += 8; |
1066 | ||
44f6c012 RM |
1067 | /* Set the address range maximum */ |
1068 | ||
4be44fcd LB |
1069 | ACPI_MOVE_64_TO_64(buffer, |
1070 | &linked_list->data.address64.max_address_range); | |
1da177e4 LT |
1071 | buffer += 8; |
1072 | ||
44f6c012 RM |
1073 | /* Set the address translation offset */ |
1074 | ||
4be44fcd LB |
1075 | ACPI_MOVE_64_TO_64(buffer, |
1076 | &linked_list->data.address64. | |
1077 | address_translation_offset); | |
1da177e4 LT |
1078 | buffer += 8; |
1079 | ||
44f6c012 RM |
1080 | /* Set the address length */ |
1081 | ||
4be44fcd | 1082 | ACPI_MOVE_64_TO_64(buffer, &linked_list->data.address64.address_length); |
1da177e4 LT |
1083 | buffer += 8; |
1084 | ||
44f6c012 RM |
1085 | /* Resource Source Index and Resource Source are optional */ |
1086 | ||
aff8c277 RM |
1087 | if (linked_list->data.address64.resource_source.string_length) { |
1088 | *buffer = | |
1089 | (u8) linked_list->data.address64.resource_source.index; | |
1da177e4 LT |
1090 | buffer += 1; |
1091 | ||
aff8c277 | 1092 | /* Copy the resource_source string */ |
44f6c012 | 1093 | |
aff8c277 | 1094 | ACPI_STRCPY((char *)buffer, |
4be44fcd LB |
1095 | linked_list->data.address64.resource_source. |
1096 | string_ptr); | |
1da177e4 LT |
1097 | |
1098 | /* | |
aff8c277 | 1099 | * Buffer needs to be set to the length of the string + one for the |
1da177e4 LT |
1100 | * terminating null |
1101 | */ | |
4be44fcd LB |
1102 | buffer += |
1103 | (acpi_size) (ACPI_STRLEN | |
1104 | (linked_list->data.address64.resource_source. | |
1105 | string_ptr) + 1); | |
1da177e4 LT |
1106 | } |
1107 | ||
44f6c012 RM |
1108 | /* Return the number of bytes consumed in this operation */ |
1109 | ||
4be44fcd | 1110 | *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer); |
1da177e4 LT |
1111 | |
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); | |
4be44fcd | 1117 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 1118 | } |