1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous 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.
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsmisc")
52 /*******************************************************************************
54 * FUNCTION: acpi_rs_end_tag_resource
56 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
58 * bytes_consumed - Pointer to where the number of bytes
59 * consumed the byte_stream_buffer is
61 * output_buffer - Pointer to the return data buffer
62 * structure_size - Pointer to where the number of bytes
63 * in the return data struct is returned
67 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
68 * structure pointed to by the output_buffer. Return the
69 * number of bytes consumed from the byte stream.
71 ******************************************************************************/
74 acpi_rs_end_tag_resource (
75 u8 *byte_stream_buffer,
76 acpi_size *bytes_consumed,
78 acpi_size *structure_size)
80 struct acpi_resource *output_struct = (void *) *output_buffer;
81 acpi_size struct_size = ACPI_RESOURCE_LENGTH;
84 ACPI_FUNCTION_TRACE ("rs_end_tag_resource");
87 /* The number of bytes consumed is static */
91 /* Fill out the structure */
93 output_struct->id = ACPI_RSTYPE_END_TAG;
95 /* Set the Length parameter */
97 output_struct->length = 0;
99 /* Return the final size of the structure */
101 *structure_size = struct_size;
102 return_ACPI_STATUS (AE_OK);
106 /*******************************************************************************
108 * FUNCTION: acpi_rs_end_tag_stream
110 * PARAMETERS: linked_list - Pointer to the resource linked list
111 * output_buffer - Pointer to the user's return buffer
112 * bytes_consumed - Pointer to where the number of bytes
113 * used in the output_buffer is returned
117 * DESCRIPTION: Take the linked list resource structure and fills in the
118 * the appropriate bytes in a byte stream
120 ******************************************************************************/
123 acpi_rs_end_tag_stream (
124 struct acpi_resource *linked_list,
126 acpi_size *bytes_consumed)
128 u8 *buffer = *output_buffer;
132 ACPI_FUNCTION_TRACE ("rs_end_tag_stream");
135 /* The descriptor field is static */
141 * Set the Checksum - zero means that the resource data is treated as if
142 * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
149 /* Return the number of bytes consumed in this operation */
151 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
152 return_ACPI_STATUS (AE_OK);
156 /*******************************************************************************
158 * FUNCTION: acpi_rs_vendor_resource
160 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
162 * bytes_consumed - Pointer to where the number of bytes
163 * consumed the byte_stream_buffer is
165 * output_buffer - Pointer to the return data buffer
166 * structure_size - Pointer to where the number of bytes
167 * in the return data struct is returned
171 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
172 * structure pointed to by the output_buffer. Return the
173 * number of bytes consumed from the byte stream.
175 ******************************************************************************/
178 acpi_rs_vendor_resource (
179 u8 *byte_stream_buffer,
180 acpi_size *bytes_consumed,
182 acpi_size *structure_size)
184 u8 *buffer = byte_stream_buffer;
185 struct acpi_resource *output_struct = (void *) *output_buffer;
189 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
190 struct acpi_resource_vendor);
193 ACPI_FUNCTION_TRACE ("rs_vendor_resource");
196 /* Dereference the Descriptor to find if this is a large or small item. */
201 /* Large Item, point to the length field */
207 ACPI_MOVE_16_TO_16 (&temp16, buffer);
209 /* Calculate bytes consumed */
211 *bytes_consumed = (acpi_size) temp16 + 3;
213 /* Point to the first vendor byte */
218 /* Small Item, dereference the size */
220 temp16 = (u8)(*buffer & 0x07);
222 /* Calculate bytes consumed */
224 *bytes_consumed = (acpi_size) temp16 + 1;
226 /* Point to the first vendor byte */
231 output_struct->id = ACPI_RSTYPE_VENDOR;
232 output_struct->data.vendor_specific.length = temp16;
234 for (index = 0; index < temp16; index++) {
235 output_struct->data.vendor_specific.reserved[index] = *buffer;
240 * In order for the struct_size to fall on a 32-bit boundary,
241 * calculate the length of the vendor string and expand the
242 * struct_size to the next 32-bit boundary.
244 struct_size += ACPI_ROUND_UP_to_32_bITS (temp16);
246 /* Set the Length parameter */
248 output_struct->length = (u32) struct_size;
250 /* Return the final size of the structure */
252 *structure_size = struct_size;
253 return_ACPI_STATUS (AE_OK);
257 /*******************************************************************************
259 * FUNCTION: acpi_rs_vendor_stream
261 * PARAMETERS: linked_list - Pointer to the resource linked list
262 * output_buffer - Pointer to the user's return buffer
263 * bytes_consumed - Pointer to where the number of bytes
264 * used in the output_buffer is returned
268 * DESCRIPTION: Take the linked list resource structure and fills in the
269 * the appropriate bytes in a byte stream
271 ******************************************************************************/
274 acpi_rs_vendor_stream (
275 struct acpi_resource *linked_list,
277 acpi_size *bytes_consumed)
279 u8 *buffer = *output_buffer;
285 ACPI_FUNCTION_TRACE ("rs_vendor_stream");
288 /* Dereference the length to find if this is a large or small item. */
290 if(linked_list->data.vendor_specific.length > 7) {
291 /* Large Item, Set the descriptor field and length bytes */
296 temp16 = (u16) linked_list->data.vendor_specific.length;
298 ACPI_MOVE_16_TO_16 (buffer, &temp16);
302 /* Small Item, Set the descriptor field */
305 temp8 |= (u8) linked_list->data.vendor_specific.length;
311 /* Loop through all of the Vendor Specific fields */
313 for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
314 temp8 = linked_list->data.vendor_specific.reserved[index];
320 /* Return the number of bytes consumed in this operation */
322 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
323 return_ACPI_STATUS (AE_OK);
327 /*******************************************************************************
329 * FUNCTION: acpi_rs_start_depend_fns_resource
331 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
333 * bytes_consumed - Pointer to where the number of bytes
334 * consumed the byte_stream_buffer is
336 * output_buffer - Pointer to the return data buffer
337 * structure_size - Pointer to where the number of bytes
338 * in the return data struct is returned
342 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
343 * structure pointed to by the output_buffer. Return the
344 * number of bytes consumed from the byte stream.
346 ******************************************************************************/
349 acpi_rs_start_depend_fns_resource (
350 u8 *byte_stream_buffer,
351 acpi_size *bytes_consumed,
353 acpi_size *structure_size)
355 u8 *buffer = byte_stream_buffer;
356 struct acpi_resource *output_struct = (void *) *output_buffer;
358 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
359 struct acpi_resource_start_dpf);
362 ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource");
365 /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
369 *bytes_consumed = (temp8 & 0x01) + 1;
371 output_struct->id = ACPI_RSTYPE_START_DPF;
373 /* Point to Byte 1 if it is used */
375 if (2 == *bytes_consumed) {
379 /* Check Compatibility priority */
381 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03;
383 if (3 == output_struct->data.start_dpf.compatibility_priority) {
384 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
387 /* Check Performance/Robustness preference */
389 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03;
391 if (3 == output_struct->data.start_dpf.performance_robustness) {
392 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
396 output_struct->data.start_dpf.compatibility_priority =
397 ACPI_ACCEPTABLE_CONFIGURATION;
399 output_struct->data.start_dpf.performance_robustness =
400 ACPI_ACCEPTABLE_CONFIGURATION;
403 /* Set the Length parameter */
405 output_struct->length = (u32) struct_size;
407 /* Return the final size of the structure */
409 *structure_size = struct_size;
410 return_ACPI_STATUS (AE_OK);
414 /*******************************************************************************
416 * FUNCTION: acpi_rs_end_depend_fns_resource
418 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
420 * bytes_consumed - Pointer to where the number of bytes
421 * consumed the byte_stream_buffer is
423 * output_buffer - Pointer to the return data buffer
424 * structure_size - Pointer to where the number of bytes
425 * in the return data struct is returned
429 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
430 * structure pointed to by the output_buffer. Return the
431 * number of bytes consumed from the byte stream.
433 ******************************************************************************/
436 acpi_rs_end_depend_fns_resource (
437 u8 *byte_stream_buffer,
438 acpi_size *bytes_consumed,
440 acpi_size *structure_size)
442 struct acpi_resource *output_struct = (void *) *output_buffer;
443 acpi_size struct_size = ACPI_RESOURCE_LENGTH;
446 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource");
449 /* The number of bytes consumed is static */
453 /* Fill out the structure */
455 output_struct->id = ACPI_RSTYPE_END_DPF;
457 /* Set the Length parameter */
459 output_struct->length = (u32) struct_size;
461 /* Return the final size of the structure */
463 *structure_size = struct_size;
464 return_ACPI_STATUS (AE_OK);
468 /*******************************************************************************
470 * FUNCTION: acpi_rs_start_depend_fns_stream
472 * PARAMETERS: linked_list - Pointer to the resource linked list
473 * output_buffer - Pointer to the user's return buffer
474 * bytes_consumed - u32 pointer that is filled with
475 * the number of bytes of the
480 * DESCRIPTION: Take the linked list resource structure and fills in the
481 * the appropriate bytes in a byte stream
483 ******************************************************************************/
486 acpi_rs_start_depend_fns_stream (
487 struct acpi_resource *linked_list,
489 acpi_size *bytes_consumed)
491 u8 *buffer = *output_buffer;
495 ACPI_FUNCTION_TRACE ("rs_start_depend_fns_stream");
499 * The descriptor field is set based upon whether a byte is needed
500 * to contain Priority data.
502 if (ACPI_ACCEPTABLE_CONFIGURATION ==
503 linked_list->data.start_dpf.compatibility_priority &&
504 ACPI_ACCEPTABLE_CONFIGURATION ==
505 linked_list->data.start_dpf.performance_robustness) {
512 /* Set the Priority Byte Definition */
515 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness &
517 temp8 |= (linked_list->data.start_dpf.compatibility_priority &
524 /* Return the number of bytes consumed in this operation */
526 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
527 return_ACPI_STATUS (AE_OK);
531 /*******************************************************************************
533 * FUNCTION: acpi_rs_end_depend_fns_stream
535 * PARAMETERS: linked_list - Pointer to the resource linked list
536 * output_buffer - Pointer to the user's return buffer
537 * bytes_consumed - Pointer to where the number of bytes
538 * used in the output_buffer is returned
542 * DESCRIPTION: Take the linked list resource structure and fills in the
543 * the appropriate bytes in a byte stream
545 ******************************************************************************/
548 acpi_rs_end_depend_fns_stream (
549 struct acpi_resource *linked_list,
551 acpi_size *bytes_consumed)
553 u8 *buffer = *output_buffer;
556 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream");
559 /* The descriptor field is static */
564 /* Return the number of bytes consumed in this operation */
566 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
567 return_ACPI_STATUS (AE_OK);