1 /*******************************************************************************
3 * Module Name: rsaddr - Acpi_rs_address16_resource
4 * Acpi_rs_address16_stream
5 * Acpi_rs_address32_resource
6 * Acpi_rs_address32_stream
9 ******************************************************************************/
12 * Copyright (C) 2000, 2001 R. Byron Moore
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #define _COMPONENT ACPI_RESOURCES
34 MODULE_NAME ("rsaddr")
37 /*******************************************************************************
39 * FUNCTION: Acpi_rs_address16_resource
41 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
43 * Bytes_consumed - u32 pointer that is filled with
44 * the number of bytes consumed from
45 * the Byte_stream_buffer
46 * Output_buffer - Pointer to the user's return buffer
47 * Structure_size - u32 pointer that is filled with
48 * the number of bytes in the filled
51 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
53 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
54 * structure pointed to by the Output_buffer. Return the
55 * number of bytes consumed from the byte stream.
57 ******************************************************************************/
60 acpi_rs_address16_resource (
61 u8 *byte_stream_buffer,
66 u8 *buffer = byte_stream_buffer;
67 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
71 u32 struct_size = sizeof(ADDRESS16_RESOURCE) +
72 RESOURCE_LENGTH_NO_DATA;
76 * Point past the Descriptor to get the number of bytes consumed
80 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
82 *bytes_consumed = temp16 + 3;
84 output_struct->id = address16;
86 output_struct->length = struct_size;
89 * Get the Resource Type (Byte3)
94 /* Values 0-2 are valid */
96 return (AE_AML_ERROR);
99 output_struct->data.address16.resource_type = temp8 & 0x03;
102 * Get the General Flags (Byte4)
108 * Producer / Consumer
110 output_struct->data.address16.producer_consumer = temp8 & 0x01;
115 output_struct->data.address16.decode = (temp8 >> 1) & 0x01;
120 output_struct->data.address16.min_address_fixed = (temp8 >> 2) & 0x01;
125 output_struct->data.address16.max_address_fixed = (temp8 >> 3) & 0x01;
128 * Get the Type Specific Flags (Byte5)
133 if (MEMORY_RANGE == output_struct->data.address16.resource_type) {
134 output_struct->data.address16.attribute.memory.read_write_attribute =
135 (u16) (temp8 & 0x01);
136 output_struct->data.address16.attribute.memory.cache_attribute =
137 (u16) ((temp8 >> 1) & 0x0F);
141 if (IO_RANGE == output_struct->data.address16.resource_type) {
142 output_struct->data.address16.attribute.io.range_attribute =
143 (u16) (temp8 & 0x03);
147 /* BUS_NUMBER_RANGE == Address32_data->Resource_type */
148 /* Nothing needs to be filled in */
153 * Get Granularity (Bytes 6-7)
156 MOVE_UNALIGNED16_TO_16 (&output_struct->data.address16.granularity,
160 * Get Min_address_range (Bytes 8-9)
163 MOVE_UNALIGNED16_TO_16 (&output_struct->data.address16.min_address_range,
167 * Get Max_address_range (Bytes 10-11)
170 MOVE_UNALIGNED16_TO_16
171 (&output_struct->data.address16.max_address_range,
175 * Get Address_translation_offset (Bytes 12-13)
178 MOVE_UNALIGNED16_TO_16
179 (&output_struct->data.address16.address_translation_offset,
183 * Get Address_length (Bytes 14-15)
186 MOVE_UNALIGNED16_TO_16
187 (&output_struct->data.address16.address_length,
191 * Resource Source Index (if present)
196 * This will leave us pointing to the Resource Source Index
197 * If it is present, then save it off and calculate the
198 * pointer to where the null terminated string goes:
199 * Each Interrupt takes 32-bits + the 5 bytes of the
200 * stream that are default.
202 if (*bytes_consumed > 16) {
203 /* Dereference the Index */
206 output_struct->data.address16.resource_source_index =
209 /* Point to the String */
213 /* Copy the string into the buffer */
217 while (0x00 != *buffer) {
218 output_struct->data.address16.resource_source[index] =
226 * Add the terminating null
228 output_struct->data.address16.resource_source[index] = 0x00;
230 output_struct->data.address16.resource_source_string_length =
234 * In order for the Struct_size to fall on a 32-bit boundry,
235 * calculate the length of the string and expand the
236 * Struct_size to the next 32-bit boundry.
238 temp8 = (u8) (index + 1);
239 struct_size += ROUND_UP_TO_32_bITS (temp8);
240 output_struct->length = struct_size;
243 output_struct->data.address16.resource_source_index = 0x00;
244 output_struct->data.address16.resource_source_string_length = 0;
245 output_struct->data.address16.resource_source[0] = 0x00;
249 * Return the final size of the structure
251 *structure_size = struct_size;
257 /*******************************************************************************
259 * FUNCTION: Acpi_rs_address16_stream
261 * PARAMETERS: Linked_list - Pointer to the resource linked list
262 * Output_buffer - Pointer to the user's return buffer
263 * Bytes_consumed - u32 pointer that is filled with
264 * the number of bytes of the
267 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
269 * DESCRIPTION: Take the linked list resource structure and fills in the
270 * the appropriate bytes in a byte stream
272 ******************************************************************************/
275 acpi_rs_address16_stream (
276 RESOURCE *linked_list,
280 u8 *buffer = *output_buffer;
283 NATIVE_CHAR *temp_pointer = NULL;
288 * The descriptor field is static
294 * Save a pointer to the Length field - to be filled in later
296 length_field = buffer;
300 * Set the Resource Type (Memory, Io, Bus_number)
302 temp8 = (u8) (linked_list->data.address16.resource_type & 0x03);
307 * Set the general flags
309 temp8 = (u8) (linked_list->data.address16.producer_consumer & 0x01);
311 temp8 |= (linked_list->data.address16.decode & 0x01) << 1;
312 temp8 |= (linked_list->data.address16.min_address_fixed & 0x01) << 2;
313 temp8 |= (linked_list->data.address16.max_address_fixed & 0x01) << 3;
319 * Set the type specific flags
323 if (MEMORY_RANGE == linked_list->data.address16.resource_type) {
325 (linked_list->data.address16.attribute.memory.read_write_attribute &
329 (linked_list->data.address16.attribute.memory.cache_attribute &
333 else if (IO_RANGE == linked_list->data.address16.resource_type) {
335 (linked_list->data.address16.attribute.io.range_attribute &
343 * Set the address space granularity
345 MOVE_UNALIGNED16_TO_16 (buffer,
346 &linked_list->data.address16.granularity);
350 * Set the address range minimum
352 MOVE_UNALIGNED16_TO_16 (buffer,
353 &linked_list->data.address16.min_address_range);
357 * Set the address range maximum
359 MOVE_UNALIGNED16_TO_16 (buffer,
360 &linked_list->data.address16.max_address_range);
364 * Set the address translation offset
366 MOVE_UNALIGNED16_TO_16 (buffer,
367 &linked_list->data.address16.address_translation_offset);
371 * Set the address length
373 MOVE_UNALIGNED16_TO_16 (buffer,
374 &linked_list->data.address16.address_length);
378 * Resource Source Index and Resource Source are optional
380 if (0 != linked_list->data.address16.resource_source_string_length) {
381 temp8 = (u8) linked_list->data.address16.resource_source_index;
386 temp_pointer = (NATIVE_CHAR *) buffer;
391 STRCPY (temp_pointer, linked_list->data.address16.resource_source);
394 * Buffer needs to be set to the length of the sting + one for the
397 buffer += (STRLEN (linked_list->data.address16.resource_source) + 1);
401 * Return the number of bytes consumed in this operation
403 actual_bytes = (u32) ((NATIVE_UINT) buffer -
404 (NATIVE_UINT) *output_buffer);
406 *bytes_consumed = actual_bytes;
409 * Set the length field to the number of bytes consumed
410 * minus the header size (3 bytes)
413 MOVE_UNALIGNED16_TO_16 (length_field, &actual_bytes);
419 /*******************************************************************************
421 * FUNCTION: Acpi_rs_address32_resource
423 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
425 * Bytes_consumed - u32 pointer that is filled with
426 * the number of bytes consumed from
427 * the Byte_stream_buffer
428 * Output_buffer - Pointer to the user's return buffer
429 * Structure_size - u32 pointer that is filled with
430 * the number of bytes in the filled
433 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
435 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
436 * structure pointed to by the Output_buffer. Return the
437 * number of bytes consumed from the byte stream.
439 ******************************************************************************/
442 acpi_rs_address32_resource (
443 u8 *byte_stream_buffer,
449 RESOURCE *output_struct;
456 buffer = byte_stream_buffer;
458 output_struct = (RESOURCE *) *output_buffer;
460 struct_size = sizeof (ADDRESS32_RESOURCE) +
461 RESOURCE_LENGTH_NO_DATA;
464 * Point past the Descriptor to get the number of bytes consumed
467 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
469 *bytes_consumed = temp16 + 3;
471 output_struct->id = address32;
474 * Get the Resource Type (Byte3)
479 /* Values 0-2 are valid */
481 return (AE_AML_ERROR);
484 output_struct->data.address32.resource_type = temp8 & 0x03;
487 * Get the General Flags (Byte4)
493 * Producer / Consumer
495 output_struct->data.address32.producer_consumer = temp8 & 0x01;
500 output_struct->data.address32.decode = (temp8 >> 1) & 0x01;
505 output_struct->data.address32.min_address_fixed = (temp8 >> 2) & 0x01;
510 output_struct->data.address32.max_address_fixed = (temp8 >> 3) & 0x01;
513 * Get the Type Specific Flags (Byte5)
518 if (MEMORY_RANGE == output_struct->data.address32.resource_type) {
519 output_struct->data.address32.attribute.memory.read_write_attribute =
520 (u16) (temp8 & 0x01);
522 output_struct->data.address32.attribute.memory.cache_attribute =
523 (u16) ((temp8 >> 1) & 0x0F);
527 if (IO_RANGE == output_struct->data.address32.resource_type) {
528 output_struct->data.address32.attribute.io.range_attribute =
529 (u16) (temp8 & 0x03);
533 /* BUS_NUMBER_RANGE == Output_struct->Data.Address32.Resource_type */
534 /* Nothing needs to be filled in */
539 * Get Granularity (Bytes 6-9)
542 MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.granularity,
546 * Get Min_address_range (Bytes 10-13)
549 MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.min_address_range,
553 * Get Max_address_range (Bytes 14-17)
556 MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.max_address_range,
560 * Get Address_translation_offset (Bytes 18-21)
563 MOVE_UNALIGNED32_TO_32
564 (&output_struct->data.address32.address_translation_offset,
568 * Get Address_length (Bytes 22-25)
571 MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.address_length,
575 * Resource Source Index (if present)
580 * This will leave us pointing to the Resource Source Index
581 * If it is present, then save it off and calculate the
582 * pointer to where the null terminated string goes:
583 * Each Interrupt takes 32-bits + the 5 bytes of the
584 * stream that are default.
586 if (*bytes_consumed > 26) {
587 /* Dereference the Index */
590 output_struct->data.address32.resource_source_index = (u32)temp8;
592 /* Point to the String */
596 /* Copy the string into the buffer */
600 while (0x00 != *buffer) {
601 output_struct->data.address32.resource_source[index] = *buffer;
607 * Add the terminating null
609 output_struct->data.address32.resource_source[index] = 0x00;
611 output_struct->data.address32.resource_source_string_length = index + 1;
614 * In order for the Struct_size to fall on a 32-bit boundry,
615 * calculate the length of the string and expand the
616 * Struct_size to the next 32-bit boundry.
618 temp8 = (u8) (index + 1);
619 struct_size += ROUND_UP_TO_32_bITS (temp8);
623 output_struct->data.address32.resource_source_index = 0x00;
624 output_struct->data.address32.resource_source_string_length = 0;
625 output_struct->data.address32.resource_source[0] = 0x00;
629 * Set the Length parameter
631 output_struct->length = struct_size;
634 * Return the final size of the structure
636 *structure_size = struct_size;
642 /*******************************************************************************
644 * FUNCTION: Acpi_rs_address32_stream
646 * PARAMETERS: Linked_list - Pointer to the resource linked list
647 * Output_buffer - Pointer to the user's return buffer
648 * Bytes_consumed - u32 pointer that is filled with
649 * the number of bytes of the
652 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
654 * DESCRIPTION: Take the linked list resource structure and fills in the
655 * the appropriate bytes in a byte stream
657 ******************************************************************************/
660 acpi_rs_address32_stream (
661 RESOURCE *linked_list,
668 NATIVE_CHAR *temp_pointer;
671 buffer = *output_buffer;
674 * The descriptor field is static
680 * Set a pointer to the Length field - to be filled in later
683 length_field = (u16 *)buffer;
687 * Set the Resource Type (Memory, Io, Bus_number)
689 temp8 = (u8) (linked_list->data.address32.resource_type & 0x03);
695 * Set the general flags
697 temp8 = (u8) (linked_list->data.address32.producer_consumer & 0x01);
698 temp8 |= (linked_list->data.address32.decode & 0x01) << 1;
699 temp8 |= (linked_list->data.address32.min_address_fixed & 0x01) << 2;
700 temp8 |= (linked_list->data.address32.max_address_fixed & 0x01) << 3;
706 * Set the type specific flags
710 if(MEMORY_RANGE == linked_list->data.address32.resource_type) {
712 (linked_list->data.address32.attribute.memory.read_write_attribute &
716 (linked_list->data.address32.attribute.memory.cache_attribute &
720 else if (IO_RANGE == linked_list->data.address32.resource_type) {
722 (linked_list->data.address32.attribute.io.range_attribute &
730 * Set the address space granularity
732 MOVE_UNALIGNED32_TO_32 (buffer,
733 &linked_list->data.address32.granularity);
737 * Set the address range minimum
739 MOVE_UNALIGNED32_TO_32 (buffer,
740 &linked_list->data.address32.min_address_range);
744 * Set the address range maximum
746 MOVE_UNALIGNED32_TO_32 (buffer,
747 &linked_list->data.address32.max_address_range);
751 * Set the address translation offset
753 MOVE_UNALIGNED32_TO_32 (buffer,
754 &linked_list->data.address32.address_translation_offset);
758 * Set the address length
760 MOVE_UNALIGNED32_TO_32 (buffer,
761 &linked_list->data.address32.address_length);
765 * Resource Source Index and Resource Source are optional
767 if (0 != linked_list->data.address32.resource_source_string_length) {
768 temp8 = (u8) linked_list->data.address32.resource_source_index;
773 temp_pointer = (NATIVE_CHAR *) buffer;
778 STRCPY (temp_pointer, linked_list->data.address32.resource_source);
781 * Buffer needs to be set to the length of the sting + one for the
784 buffer += (STRLEN (linked_list->data.address32.resource_source) + 1);
788 * Return the number of bytes consumed in this operation
790 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
791 (NATIVE_UINT) *output_buffer);
794 * Set the length field to the number of bytes consumed
795 * minus the header size (3 bytes)
797 *length_field = (u16) (*bytes_consumed - 3);