1 /*******************************************************************************
3 * Module Name: rsmem24 - Memory resource descriptors
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
47 #define _COMPONENT ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsmemory")
50 /*******************************************************************************
52 * FUNCTION: acpi_rs_memory24_resource
54 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
56 * bytes_consumed - Pointer to where the number of bytes
57 * consumed the byte_stream_buffer is
59 * output_buffer - Pointer to the return data buffer
60 * structure_size - Pointer to where the number of bytes
61 * in the return data struct is returned
65 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
66 * structure pointed to by the output_buffer. Return the
67 * number of bytes consumed from the byte stream.
69 ******************************************************************************/
71 acpi_rs_memory24_resource(u8 * byte_stream_buffer,
72 acpi_size * bytes_consumed,
73 u8 ** output_buffer, acpi_size * structure_size)
75 u8 *buffer = byte_stream_buffer;
76 struct acpi_resource *output_struct = (void *)*output_buffer;
79 acpi_size struct_size =
80 ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24);
82 ACPI_FUNCTION_TRACE("rs_memory24_resource");
84 /* Point past the Descriptor to get the number of bytes consumed */
87 ACPI_MOVE_16_TO_16(&temp16, buffer);
90 *bytes_consumed = (acpi_size) temp16 + 3;
91 output_struct->type = ACPI_RSTYPE_MEM24;
93 /* Check Byte 3 the Read/Write bit */
97 output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
99 /* Get min_base_address (Bytes 4-5) */
101 ACPI_MOVE_16_TO_16(&temp16, buffer);
103 output_struct->data.memory24.min_base_address = temp16;
105 /* Get max_base_address (Bytes 6-7) */
107 ACPI_MOVE_16_TO_16(&temp16, buffer);
109 output_struct->data.memory24.max_base_address = temp16;
111 /* Get Alignment (Bytes 8-9) */
113 ACPI_MOVE_16_TO_16(&temp16, buffer);
115 output_struct->data.memory24.alignment = temp16;
117 /* Get range_length (Bytes 10-11) */
119 ACPI_MOVE_16_TO_16(&temp16, buffer);
120 output_struct->data.memory24.range_length = temp16;
122 /* Set the Length parameter */
124 output_struct->length = (u32) struct_size;
126 /* Return the final size of the structure */
128 *structure_size = struct_size;
129 return_ACPI_STATUS(AE_OK);
132 /*******************************************************************************
134 * FUNCTION: acpi_rs_memory24_stream
136 * PARAMETERS: Resource - Pointer to the resource linked list
137 * output_buffer - Pointer to the user's return buffer
138 * bytes_consumed - Pointer to where the number of bytes
139 * used in the output_buffer is returned
143 * DESCRIPTION: Take the linked list resource structure and fills in the
144 * the appropriate bytes in a byte stream
146 ******************************************************************************/
149 acpi_rs_memory24_stream(struct acpi_resource *resource,
150 u8 ** output_buffer, acpi_size * bytes_consumed)
152 u8 *buffer = *output_buffer;
156 ACPI_FUNCTION_TRACE("rs_memory24_stream");
158 /* The Descriptor Type field is static */
160 *buffer = ACPI_RDESC_TYPE_MEMORY_24;
163 /* The length field is static */
166 ACPI_MOVE_16_TO_16(buffer, &temp16);
169 /* Set the Information Byte */
171 temp8 = (u8) (resource->data.memory24.read_write_attribute & 0x01);
175 /* Set the Range minimum base address */
177 ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.min_base_address);
180 /* Set the Range maximum base address */
182 ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.max_base_address);
185 /* Set the base alignment */
187 ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.alignment);
190 /* Set the range length */
192 ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.range_length);
195 /* Return the number of bytes consumed in this operation */
197 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
198 return_ACPI_STATUS(AE_OK);
201 /*******************************************************************************
203 * FUNCTION: acpi_rs_memory32_range_resource
205 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
207 * bytes_consumed - Pointer to where the number of bytes
208 * consumed the byte_stream_buffer is
210 * output_buffer - Pointer to the return data buffer
211 * structure_size - Pointer to where the number of bytes
212 * in the return data struct is returned
216 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
217 * structure pointed to by the output_buffer. Return the
218 * number of bytes consumed from the byte stream.
220 ******************************************************************************/
223 acpi_rs_memory32_range_resource(u8 * byte_stream_buffer,
224 acpi_size * bytes_consumed,
225 u8 ** output_buffer, acpi_size * structure_size)
227 u8 *buffer = byte_stream_buffer;
228 struct acpi_resource *output_struct = (void *)*output_buffer;
231 acpi_size struct_size =
232 ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32);
234 ACPI_FUNCTION_TRACE("rs_memory32_range_resource");
236 /* Point past the Descriptor to get the number of bytes consumed */
239 ACPI_MOVE_16_TO_16(&temp16, buffer);
242 *bytes_consumed = (acpi_size) temp16 + 3;
243 output_struct->type = ACPI_RSTYPE_MEM32;
246 * Point to the place in the output buffer where the data portion will
248 * 1. Set the RESOURCE_DATA * Data to point to its own address, then
249 * 2. Set the pointer to the next address.
251 * NOTE: output_struct->Data is cast to u8, otherwise, this addition adds
252 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
255 /* Check Byte 3 the Read/Write bit */
260 output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
262 /* Get min_base_address (Bytes 4-7) */
264 ACPI_MOVE_32_TO_32(&output_struct->data.memory32.min_base_address,
268 /* Get max_base_address (Bytes 8-11) */
270 ACPI_MOVE_32_TO_32(&output_struct->data.memory32.max_base_address,
274 /* Get Alignment (Bytes 12-15) */
276 ACPI_MOVE_32_TO_32(&output_struct->data.memory32.alignment, buffer);
279 /* Get range_length (Bytes 16-19) */
281 ACPI_MOVE_32_TO_32(&output_struct->data.memory32.range_length, buffer);
283 /* Set the Length parameter */
285 output_struct->length = (u32) struct_size;
287 /* Return the final size of the structure */
289 *structure_size = struct_size;
290 return_ACPI_STATUS(AE_OK);
293 /*******************************************************************************
295 * FUNCTION: acpi_rs_fixed_memory32_resource
297 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
299 * bytes_consumed - Pointer to where the number of bytes
300 * consumed the byte_stream_buffer is
302 * output_buffer - Pointer to the return data buffer
303 * structure_size - Pointer to where the number of bytes
304 * in the return data struct is returned
308 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
309 * structure pointed to by the output_buffer. Return the
310 * number of bytes consumed from the byte stream.
312 ******************************************************************************/
315 acpi_rs_fixed_memory32_resource(u8 * byte_stream_buffer,
316 acpi_size * bytes_consumed,
317 u8 ** output_buffer, acpi_size * structure_size)
319 u8 *buffer = byte_stream_buffer;
320 struct acpi_resource *output_struct = (void *)*output_buffer;
323 acpi_size struct_size =
324 ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_mem32);
326 ACPI_FUNCTION_TRACE("rs_fixed_memory32_resource");
328 /* Point past the Descriptor to get the number of bytes consumed */
331 ACPI_MOVE_16_TO_16(&temp16, buffer);
334 *bytes_consumed = (acpi_size) temp16 + 3;
335 output_struct->type = ACPI_RSTYPE_FIXED_MEM32;
337 /* Check Byte 3 the Read/Write bit */
341 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
343 /* Get range_base_address (Bytes 4-7) */
345 ACPI_MOVE_32_TO_32(&output_struct->data.fixed_memory32.
346 range_base_address, buffer);
349 /* Get range_length (Bytes 8-11) */
351 ACPI_MOVE_32_TO_32(&output_struct->data.fixed_memory32.range_length,
354 /* Set the Length parameter */
356 output_struct->length = (u32) struct_size;
358 /* Return the final size of the structure */
360 *structure_size = struct_size;
361 return_ACPI_STATUS(AE_OK);
364 /*******************************************************************************
366 * FUNCTION: acpi_rs_memory32_range_stream
368 * PARAMETERS: Resource - Pointer to the resource linked list
369 * output_buffer - Pointer to the user's return buffer
370 * bytes_consumed - Pointer to where the number of bytes
371 * used in the output_buffer is returned
375 * DESCRIPTION: Take the linked list resource structure and fills in the
376 * the appropriate bytes in a byte stream
378 ******************************************************************************/
381 acpi_rs_memory32_range_stream(struct acpi_resource *resource,
382 u8 ** output_buffer, acpi_size * bytes_consumed)
384 u8 *buffer = *output_buffer;
388 ACPI_FUNCTION_TRACE("rs_memory32_range_stream");
390 /* The Descriptor Type field is static */
392 *buffer = ACPI_RDESC_TYPE_MEMORY_32;
395 /* The length field is static */
399 ACPI_MOVE_16_TO_16(buffer, &temp16);
402 /* Set the Information Byte */
404 temp8 = (u8) (resource->data.memory32.read_write_attribute & 0x01);
408 /* Set the Range minimum base address */
410 ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.min_base_address);
413 /* Set the Range maximum base address */
415 ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.max_base_address);
418 /* Set the base alignment */
420 ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.alignment);
423 /* Set the range length */
425 ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.range_length);
428 /* Return the number of bytes consumed in this operation */
430 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
431 return_ACPI_STATUS(AE_OK);
434 /*******************************************************************************
436 * FUNCTION: acpi_rs_fixed_memory32_stream
438 * PARAMETERS: Resource - Pointer to the resource linked list
439 * output_buffer - Pointer to the user's return buffer
440 * bytes_consumed - Pointer to where the number of bytes
441 * used in the output_buffer is returned
445 * DESCRIPTION: Take the linked list resource structure and fills in the
446 * the appropriate bytes in a byte stream
448 ******************************************************************************/
451 acpi_rs_fixed_memory32_stream(struct acpi_resource *resource,
452 u8 ** output_buffer, acpi_size * bytes_consumed)
454 u8 *buffer = *output_buffer;
458 ACPI_FUNCTION_TRACE("rs_fixed_memory32_stream");
460 /* The Descriptor Type field is static */
462 *buffer = ACPI_RDESC_TYPE_FIXED_MEMORY_32;
465 /* The length field is static */
469 ACPI_MOVE_16_TO_16(buffer, &temp16);
472 /* Set the Information Byte */
475 (u8) (resource->data.fixed_memory32.read_write_attribute & 0x01);
479 /* Set the Range base address */
481 ACPI_MOVE_32_TO_32(buffer,
482 &resource->data.fixed_memory32.range_base_address);
485 /* Set the range length */
487 ACPI_MOVE_32_TO_32(buffer, &resource->data.fixed_memory32.range_length);
490 /* Return the number of bytes consumed in this operation */
492 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
493 return_ACPI_STATUS(AE_OK);