Update ACPI build wrappers to use new ACPICA(20050309) code.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050211 / resources / rsmisc.c
blob5c994a0684ab8fe3c56fdb4718d311750f8485cb
1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous resource descriptors
4 * $Revision: 28 $
6 ******************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #define __RSMISC_C__
119 #include "acpi.h"
120 #include "acresrc.h"
122 #define _COMPONENT ACPI_RESOURCES
123 ACPI_MODULE_NAME ("rsmisc")
126 /*******************************************************************************
128 * FUNCTION: AcpiRsEndTagResource
130 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
131 * stream
132 * BytesConsumed - Pointer to where the number of bytes
133 * consumed the ByteStreamBuffer is
134 * returned
135 * OutputBuffer - Pointer to the return data buffer
136 * StructureSize - Pointer to where the number of bytes
137 * in the return data struct is returned
139 * RETURN: Status
141 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
142 * structure pointed to by the OutputBuffer. Return the
143 * number of bytes consumed from the byte stream.
145 ******************************************************************************/
147 ACPI_STATUS
148 AcpiRsEndTagResource (
149 UINT8 *ByteStreamBuffer,
150 ACPI_SIZE *BytesConsumed,
151 UINT8 **OutputBuffer,
152 ACPI_SIZE *StructureSize)
154 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer;
155 ACPI_SIZE StructSize = ACPI_RESOURCE_LENGTH;
158 ACPI_FUNCTION_TRACE ("RsEndTagResource");
162 * The number of bytes consumed is static
164 *BytesConsumed = 2;
167 * Fill out the structure
169 OutputStruct->Id = ACPI_RSTYPE_END_TAG;
172 * Set the Length parameter
174 OutputStruct->Length = 0;
177 * Return the final size of the structure
179 *StructureSize = StructSize;
180 return_ACPI_STATUS (AE_OK);
184 /*******************************************************************************
186 * FUNCTION: AcpiRsEndTagStream
188 * PARAMETERS: LinkedList - Pointer to the resource linked list
189 * OutputBuffer - Pointer to the user's return buffer
190 * BytesConsumed - Pointer to where the number of bytes
191 * used in the OutputBuffer is returned
193 * RETURN: Status
195 * DESCRIPTION: Take the linked list resource structure and fills in the
196 * the appropriate bytes in a byte stream
198 ******************************************************************************/
200 ACPI_STATUS
201 AcpiRsEndTagStream (
202 ACPI_RESOURCE *LinkedList,
203 UINT8 **OutputBuffer,
204 ACPI_SIZE *BytesConsumed)
206 UINT8 *Buffer = *OutputBuffer;
207 UINT8 Temp8 = 0;
210 ACPI_FUNCTION_TRACE ("RsEndTagStream");
214 * The descriptor field is static
216 *Buffer = 0x79;
217 Buffer += 1;
220 * Set the Checksum - zero means that the resource data is treated as if
221 * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
223 Temp8 = 0;
225 *Buffer = Temp8;
226 Buffer += 1;
229 * Return the number of bytes consumed in this operation
231 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
232 return_ACPI_STATUS (AE_OK);
236 /*******************************************************************************
238 * FUNCTION: AcpiRsVendorResource
240 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
241 * stream
242 * BytesConsumed - Pointer to where the number of bytes
243 * consumed the ByteStreamBuffer is
244 * returned
245 * OutputBuffer - Pointer to the return data buffer
246 * StructureSize - Pointer to where the number of bytes
247 * in the return data struct is returned
249 * RETURN: Status
251 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
252 * structure pointed to by the OutputBuffer. Return the
253 * number of bytes consumed from the byte stream.
255 ******************************************************************************/
257 ACPI_STATUS
258 AcpiRsVendorResource (
259 UINT8 *ByteStreamBuffer,
260 ACPI_SIZE *BytesConsumed,
261 UINT8 **OutputBuffer,
262 ACPI_SIZE *StructureSize)
264 UINT8 *Buffer = ByteStreamBuffer;
265 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer;
266 UINT16 Temp16 = 0;
267 UINT8 Temp8 = 0;
268 UINT8 Index;
269 ACPI_SIZE StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_VENDOR);
272 ACPI_FUNCTION_TRACE ("RsVendorResource");
276 * Dereference the Descriptor to find if this is a large or small item.
278 Temp8 = *Buffer;
280 if (Temp8 & 0x80)
283 * Large Item, point to the length field
285 Buffer += 1;
287 /* Dereference */
289 ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
291 /* Calculate bytes consumed */
293 *BytesConsumed = (ACPI_SIZE) Temp16 + 3;
295 /* Point to the first vendor byte */
297 Buffer += 2;
299 else
302 * Small Item, dereference the size
304 Temp16 = (UINT8)(*Buffer & 0x07);
306 /* Calculate bytes consumed */
308 *BytesConsumed = (ACPI_SIZE) Temp16 + 1;
310 /* Point to the first vendor byte */
312 Buffer += 1;
315 OutputStruct->Id = ACPI_RSTYPE_VENDOR;
316 OutputStruct->Data.VendorSpecific.Length = Temp16;
318 for (Index = 0; Index < Temp16; Index++)
320 OutputStruct->Data.VendorSpecific.Reserved[Index] = *Buffer;
321 Buffer += 1;
325 * In order for the StructSize to fall on a 32-bit boundary,
326 * calculate the length of the vendor string and expand the
327 * StructSize to the next 32-bit boundary.
329 StructSize += ACPI_ROUND_UP_TO_32BITS (Temp16);
332 * Set the Length parameter
334 OutputStruct->Length = (UINT32) StructSize;
337 * Return the final size of the structure
339 *StructureSize = StructSize;
340 return_ACPI_STATUS (AE_OK);
344 /*******************************************************************************
346 * FUNCTION: AcpiRsVendorStream
348 * PARAMETERS: LinkedList - Pointer to the resource linked list
349 * OutputBuffer - Pointer to the user's return buffer
350 * BytesConsumed - Pointer to where the number of bytes
351 * used in the OutputBuffer is returned
353 * RETURN: Status
355 * DESCRIPTION: Take the linked list resource structure and fills in the
356 * the appropriate bytes in a byte stream
358 ******************************************************************************/
360 ACPI_STATUS
361 AcpiRsVendorStream (
362 ACPI_RESOURCE *LinkedList,
363 UINT8 **OutputBuffer,
364 ACPI_SIZE *BytesConsumed)
366 UINT8 *Buffer = *OutputBuffer;
367 UINT16 Temp16 = 0;
368 UINT8 Temp8 = 0;
369 UINT8 Index;
372 ACPI_FUNCTION_TRACE ("RsVendorStream");
376 * Dereference the length to find if this is a large or small item.
378 if(LinkedList->Data.VendorSpecific.Length > 7)
381 * Large Item, Set the descriptor field and length bytes
383 *Buffer = 0x84;
384 Buffer += 1;
386 Temp16 = (UINT16) LinkedList->Data.VendorSpecific.Length;
388 ACPI_MOVE_16_TO_16 (Buffer, &Temp16);
389 Buffer += 2;
391 else
394 * Small Item, Set the descriptor field
396 Temp8 = 0x70;
397 Temp8 |= (UINT8) LinkedList->Data.VendorSpecific.Length;
399 *Buffer = Temp8;
400 Buffer += 1;
404 * Loop through all of the Vendor Specific fields
406 for (Index = 0; Index < LinkedList->Data.VendorSpecific.Length; Index++)
408 Temp8 = LinkedList->Data.VendorSpecific.Reserved[Index];
410 *Buffer = Temp8;
411 Buffer += 1;
415 * Return the number of bytes consumed in this operation
417 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
418 return_ACPI_STATUS (AE_OK);
422 /*******************************************************************************
424 * FUNCTION: AcpiRsStartDependFnsResource
426 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
427 * stream
428 * BytesConsumed - Pointer to where the number of bytes
429 * consumed the ByteStreamBuffer is
430 * returned
431 * OutputBuffer - Pointer to the return data buffer
432 * StructureSize - Pointer to where the number of bytes
433 * in the return data struct is returned
435 * RETURN: Status
437 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
438 * structure pointed to by the OutputBuffer. Return the
439 * number of bytes consumed from the byte stream.
441 ******************************************************************************/
443 ACPI_STATUS
444 AcpiRsStartDependFnsResource (
445 UINT8 *ByteStreamBuffer,
446 ACPI_SIZE *BytesConsumed,
447 UINT8 **OutputBuffer,
448 ACPI_SIZE *StructureSize)
450 UINT8 *Buffer = ByteStreamBuffer;
451 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer;
452 UINT8 Temp8 = 0;
453 ACPI_SIZE StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_START_DPF);
456 ACPI_FUNCTION_TRACE ("RsStartDependFnsResource");
460 * The number of bytes consumed are contained in the descriptor (Bits:0-1)
462 Temp8 = *Buffer;
464 *BytesConsumed = (Temp8 & 0x01) + 1;
466 OutputStruct->Id = ACPI_RSTYPE_START_DPF;
469 * Point to Byte 1 if it is used
471 if (2 == *BytesConsumed)
473 Buffer += 1;
474 Temp8 = *Buffer;
477 * Check Compatibility priority
479 OutputStruct->Data.StartDpf.CompatibilityPriority = Temp8 & 0x03;
481 if (3 == OutputStruct->Data.StartDpf.CompatibilityPriority)
483 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
487 * Check Performance/Robustness preference
489 OutputStruct->Data.StartDpf.PerformanceRobustness = (Temp8 >> 2) & 0x03;
491 if (3 == OutputStruct->Data.StartDpf.PerformanceRobustness)
493 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
496 else
498 OutputStruct->Data.StartDpf.CompatibilityPriority =
499 ACPI_ACCEPTABLE_CONFIGURATION;
501 OutputStruct->Data.StartDpf.PerformanceRobustness =
502 ACPI_ACCEPTABLE_CONFIGURATION;
506 * Set the Length parameter
508 OutputStruct->Length = (UINT32) StructSize;
511 * Return the final size of the structure
513 *StructureSize = StructSize;
514 return_ACPI_STATUS (AE_OK);
518 /*******************************************************************************
520 * FUNCTION: AcpiRsEndDependFnsResource
522 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
523 * stream
524 * BytesConsumed - Pointer to where the number of bytes
525 * consumed the ByteStreamBuffer is
526 * returned
527 * OutputBuffer - Pointer to the return data buffer
528 * StructureSize - Pointer to where the number of bytes
529 * in the return data struct is returned
531 * RETURN: Status
533 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
534 * structure pointed to by the OutputBuffer. Return the
535 * number of bytes consumed from the byte stream.
537 ******************************************************************************/
539 ACPI_STATUS
540 AcpiRsEndDependFnsResource (
541 UINT8 *ByteStreamBuffer,
542 ACPI_SIZE *BytesConsumed,
543 UINT8 **OutputBuffer,
544 ACPI_SIZE *StructureSize)
546 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer;
547 ACPI_SIZE StructSize = ACPI_RESOURCE_LENGTH;
550 ACPI_FUNCTION_TRACE ("RsEndDependFnsResource");
554 * The number of bytes consumed is static
556 *BytesConsumed = 1;
559 * Fill out the structure
561 OutputStruct->Id = ACPI_RSTYPE_END_DPF;
564 * Set the Length parameter
566 OutputStruct->Length = (UINT32) StructSize;
569 * Return the final size of the structure
571 *StructureSize = StructSize;
572 return_ACPI_STATUS (AE_OK);
576 /*******************************************************************************
578 * FUNCTION: AcpiRsStartDependFnsStream
580 * PARAMETERS: LinkedList - Pointer to the resource linked list
581 * OutputBuffer - Pointer to the user's return buffer
582 * BytesConsumed - UINT32 pointer that is filled with
583 * the number of bytes of the
584 * OutputBuffer used
586 * RETURN: Status
588 * DESCRIPTION: Take the linked list resource structure and fills in the
589 * the appropriate bytes in a byte stream
591 ******************************************************************************/
593 ACPI_STATUS
594 AcpiRsStartDependFnsStream (
595 ACPI_RESOURCE *LinkedList,
596 UINT8 **OutputBuffer,
597 ACPI_SIZE *BytesConsumed)
599 UINT8 *Buffer = *OutputBuffer;
600 UINT8 Temp8 = 0;
603 ACPI_FUNCTION_TRACE ("RsStartDependFnsStream");
607 * The descriptor field is set based upon whether a byte is needed
608 * to contain Priority data.
610 if (ACPI_ACCEPTABLE_CONFIGURATION ==
611 LinkedList->Data.StartDpf.CompatibilityPriority &&
612 ACPI_ACCEPTABLE_CONFIGURATION ==
613 LinkedList->Data.StartDpf.PerformanceRobustness)
615 *Buffer = 0x30;
617 else
619 *Buffer = 0x31;
620 Buffer += 1;
623 * Set the Priority Byte Definition
625 Temp8 = 0;
626 Temp8 = (UINT8) ((LinkedList->Data.StartDpf.PerformanceRobustness &
627 0x03) << 2);
628 Temp8 |= (LinkedList->Data.StartDpf.CompatibilityPriority &
629 0x03);
630 *Buffer = Temp8;
633 Buffer += 1;
636 * Return the number of bytes consumed in this operation
638 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
639 return_ACPI_STATUS (AE_OK);
643 /*******************************************************************************
645 * FUNCTION: AcpiRsEndDependFnsStream
647 * PARAMETERS: LinkedList - Pointer to the resource linked list
648 * OutputBuffer - Pointer to the user's return buffer
649 * BytesConsumed - Pointer to where the number of bytes
650 * used in the OutputBuffer is returned
652 * RETURN: Status
654 * DESCRIPTION: Take the linked list resource structure and fills in the
655 * the appropriate bytes in a byte stream
657 ******************************************************************************/
659 ACPI_STATUS
660 AcpiRsEndDependFnsStream (
661 ACPI_RESOURCE *LinkedList,
662 UINT8 **OutputBuffer,
663 ACPI_SIZE *BytesConsumed)
665 UINT8 *Buffer = *OutputBuffer;
668 ACPI_FUNCTION_TRACE ("RsEndDependFnsStream");
672 * The descriptor field is static
674 *Buffer = 0x38;
675 Buffer += 1;
678 * Return the number of bytes consumed in this operation
680 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
681 return_ACPI_STATUS (AE_OK);