i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / resources / rsmisc.c
blobe7da574321a6c795de6c2f6cba60e52350816bc8
1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous resource descriptors
4 * $Revision: 1.45 $
6 ******************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2006, 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 #define INIT_RESOURCE_TYPE(i) i->ResourceOffset
127 #define INIT_RESOURCE_LENGTH(i) i->AmlOffset
128 #define INIT_TABLE_LENGTH(i) i->Value
130 #define COMPARE_OPCODE(i) i->ResourceOffset
131 #define COMPARE_TARGET(i) i->AmlOffset
132 #define COMPARE_VALUE(i) i->Value
135 /*******************************************************************************
137 * FUNCTION: AcpiRsConvertAmlToResource
139 * PARAMETERS: Resource - Pointer to the resource descriptor
140 * Aml - Where the AML descriptor is returned
141 * Info - Pointer to appropriate conversion table
143 * RETURN: Status
145 * DESCRIPTION: Convert an external AML resource descriptor to the corresponding
146 * internal resource descriptor
148 ******************************************************************************/
150 ACPI_STATUS
151 AcpiRsConvertAmlToResource (
152 ACPI_RESOURCE *Resource,
153 AML_RESOURCE *Aml,
154 ACPI_RSCONVERT_INFO *Info)
156 ACPI_RS_LENGTH AmlResourceLength;
157 void *Source;
158 void *Destination;
159 char *Target;
160 UINT8 Count;
161 UINT8 FlagsMode = FALSE;
162 UINT16 ItemCount = 0;
163 UINT16 Temp16 = 0;
166 ACPI_FUNCTION_TRACE (RsConvertAmlToResource);
169 if (((ACPI_NATIVE_UINT) Resource) & 0x3)
171 /* Each internal resource struct is expected to be 32-bit aligned */
173 ACPI_WARNING ((AE_INFO,
174 "Misaligned resource pointer (get): %p Type %2.2X Len %X",
175 Resource, Resource->Type, Resource->Length));
178 /* Extract the resource Length field (does not include header length) */
180 AmlResourceLength = AcpiUtGetResourceLength (Aml);
183 * First table entry must be ACPI_RSC_INITxxx and must contain the
184 * table length (# of table entries)
186 Count = INIT_TABLE_LENGTH (Info);
188 while (Count)
191 * Source is the external AML byte stream buffer,
192 * destination is the internal resource descriptor
194 Source = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
195 Destination = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
197 switch (Info->Opcode)
199 case ACPI_RSC_INITGET:
201 * Get the resource type and the initial (minimum) length
203 ACPI_MEMSET (Resource, 0, INIT_RESOURCE_LENGTH (Info));
204 Resource->Type = INIT_RESOURCE_TYPE (Info);
205 Resource->Length = INIT_RESOURCE_LENGTH (Info);
206 break;
209 case ACPI_RSC_INITSET:
210 break;
213 case ACPI_RSC_FLAGINIT:
215 FlagsMode = TRUE;
216 break;
219 case ACPI_RSC_1BITFLAG:
221 * Mask and shift the flag bit
223 ACPI_SET8 (Destination) = (UINT8)
224 ((ACPI_GET8 (Source) >> Info->Value) & 0x01);
225 break;
228 case ACPI_RSC_2BITFLAG:
230 * Mask and shift the flag bits
232 ACPI_SET8 (Destination) = (UINT8)
233 ((ACPI_GET8 (Source) >> Info->Value) & 0x03);
234 break;
237 case ACPI_RSC_COUNT:
239 ItemCount = ACPI_GET8 (Source);
240 ACPI_SET8 (Destination) = (UINT8) ItemCount;
242 Resource->Length = Resource->Length +
243 (Info->Value * (ItemCount - 1));
244 break;
247 case ACPI_RSC_COUNT16:
249 ItemCount = AmlResourceLength;
250 ACPI_SET16 (Destination) = ItemCount;
252 Resource->Length = Resource->Length +
253 (Info->Value * (ItemCount - 1));
254 break;
257 case ACPI_RSC_LENGTH:
259 Resource->Length = Resource->Length + Info->Value;
260 break;
263 case ACPI_RSC_MOVE8:
264 case ACPI_RSC_MOVE16:
265 case ACPI_RSC_MOVE32:
266 case ACPI_RSC_MOVE64:
268 * Raw data move. Use the Info value field unless ItemCount has
269 * been previously initialized via a COUNT opcode
271 if (Info->Value)
273 ItemCount = Info->Value;
275 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
276 break;
279 case ACPI_RSC_SET8:
281 ACPI_MEMSET (Destination, Info->AmlOffset, Info->Value);
282 break;
285 case ACPI_RSC_DATA8:
287 Target = ACPI_ADD_PTR (char, Resource, Info->Value);
288 ACPI_MEMCPY (Destination, Source, ACPI_GET16 (Target));
289 break;
292 case ACPI_RSC_ADDRESS:
294 * Common handler for address descriptor flags
296 if (!AcpiRsGetAddressCommon (Resource, Aml))
298 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
300 break;
303 case ACPI_RSC_SOURCE:
305 * Optional ResourceSource (Index and String)
307 Resource->Length +=
308 AcpiRsGetResourceSource (AmlResourceLength, Info->Value,
309 Destination, Aml, NULL);
310 break;
313 case ACPI_RSC_SOURCEX:
315 * Optional ResourceSource (Index and String). This is the more
316 * complicated case used by the Interrupt() macro
318 Target = ACPI_ADD_PTR (char, Resource, Info->AmlOffset + (ItemCount * 4));
320 Resource->Length +=
321 AcpiRsGetResourceSource (AmlResourceLength,
322 (ACPI_RS_LENGTH) (((ItemCount - 1) * sizeof (UINT32)) + Info->Value),
323 Destination, Aml, Target);
324 break;
327 case ACPI_RSC_BITMASK:
329 * 8-bit encoded bitmask (DMA macro)
331 ItemCount = AcpiRsDecodeBitmask (ACPI_GET8 (Source), Destination);
332 if (ItemCount)
334 Resource->Length += (ItemCount - 1);
337 Target = ACPI_ADD_PTR (char, Resource, Info->Value);
338 ACPI_SET8 (Target) = (UINT8) ItemCount;
339 break;
342 case ACPI_RSC_BITMASK16:
344 * 16-bit encoded bitmask (IRQ macro)
346 ACPI_MOVE_16_TO_16 (&Temp16, Source);
348 ItemCount = AcpiRsDecodeBitmask (Temp16, Destination);
349 if (ItemCount)
351 Resource->Length += (ItemCount - 1);
354 Target = ACPI_ADD_PTR (char, Resource, Info->Value);
355 ACPI_SET8 (Target) = (UINT8) ItemCount;
356 break;
359 case ACPI_RSC_EXIT_NE:
361 * Control - Exit conversion if not equal
363 switch (Info->ResourceOffset)
365 case ACPI_RSC_COMPARE_AML_LENGTH:
366 if (AmlResourceLength != Info->Value)
368 goto Exit;
370 break;
372 case ACPI_RSC_COMPARE_VALUE:
373 if (ACPI_GET8 (Source) != Info->Value)
375 goto Exit;
377 break;
379 default:
381 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
382 return_ACPI_STATUS (AE_BAD_PARAMETER);
384 break;
387 default:
389 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
390 return_ACPI_STATUS (AE_BAD_PARAMETER);
393 Count--;
394 Info++;
397 Exit:
398 if (!FlagsMode)
400 /* Round the resource struct length up to the next boundary (32 or 64) */
402 Resource->Length = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length);
404 return_ACPI_STATUS (AE_OK);
408 /*******************************************************************************
410 * FUNCTION: AcpiRsConvertResourceToAml
412 * PARAMETERS: Resource - Pointer to the resource descriptor
413 * Aml - Where the AML descriptor is returned
414 * Info - Pointer to appropriate conversion table
416 * RETURN: Status
418 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
419 * external AML resource descriptor.
421 ******************************************************************************/
423 ACPI_STATUS
424 AcpiRsConvertResourceToAml (
425 ACPI_RESOURCE *Resource,
426 AML_RESOURCE *Aml,
427 ACPI_RSCONVERT_INFO *Info)
429 void *Source = NULL;
430 void *Destination;
431 ACPI_RSDESC_SIZE AmlLength = 0;
432 UINT8 Count;
433 UINT16 Temp16 = 0;
434 UINT16 ItemCount = 0;
437 ACPI_FUNCTION_TRACE (RsConvertResourceToAml);
441 * First table entry must be ACPI_RSC_INITxxx and must contain the
442 * table length (# of table entries)
444 Count = INIT_TABLE_LENGTH (Info);
446 while (Count)
449 * Source is the internal resource descriptor,
450 * destination is the external AML byte stream buffer
452 Source = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
453 Destination = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
455 switch (Info->Opcode)
457 case ACPI_RSC_INITSET:
459 ACPI_MEMSET (Aml, 0, INIT_RESOURCE_LENGTH (Info));
460 AmlLength = INIT_RESOURCE_LENGTH (Info);
461 AcpiRsSetResourceHeader (INIT_RESOURCE_TYPE (Info), AmlLength, Aml);
462 break;
465 case ACPI_RSC_INITGET:
466 break;
469 case ACPI_RSC_FLAGINIT:
471 * Clear the flag byte
473 ACPI_SET8 (Destination) = 0;
474 break;
477 case ACPI_RSC_1BITFLAG:
479 * Mask and shift the flag bit
481 ACPI_SET8 (Destination) |= (UINT8)
482 ((ACPI_GET8 (Source) & 0x01) << Info->Value);
483 break;
486 case ACPI_RSC_2BITFLAG:
488 * Mask and shift the flag bits
490 ACPI_SET8 (Destination) |= (UINT8)
491 ((ACPI_GET8 (Source) & 0x03) << Info->Value);
492 break;
495 case ACPI_RSC_COUNT:
497 ItemCount = ACPI_GET8 (Source);
498 ACPI_SET8 (Destination) = (UINT8) ItemCount;
500 AmlLength = (UINT16) (AmlLength + (Info->Value * (ItemCount - 1)));
501 break;
504 case ACPI_RSC_COUNT16:
506 ItemCount = ACPI_GET16 (Source);
507 AmlLength = (UINT16) (AmlLength + ItemCount);
508 AcpiRsSetResourceLength (AmlLength, Aml);
509 break;
512 case ACPI_RSC_LENGTH:
514 AcpiRsSetResourceLength (Info->Value, Aml);
515 break;
518 case ACPI_RSC_MOVE8:
519 case ACPI_RSC_MOVE16:
520 case ACPI_RSC_MOVE32:
521 case ACPI_RSC_MOVE64:
523 if (Info->Value)
525 ItemCount = Info->Value;
527 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
528 break;
531 case ACPI_RSC_ADDRESS:
533 /* Set the Resource Type, General Flags, and Type-Specific Flags */
535 AcpiRsSetAddressCommon (Aml, Resource);
536 break;
539 case ACPI_RSC_SOURCEX:
541 * Optional ResourceSource (Index and String)
543 AmlLength = AcpiRsSetResourceSource (
544 Aml, (ACPI_RS_LENGTH) AmlLength, Source);
545 AcpiRsSetResourceLength (AmlLength, Aml);
546 break;
549 case ACPI_RSC_SOURCE:
551 * Optional ResourceSource (Index and String). This is the more
552 * complicated case used by the Interrupt() macro
554 AmlLength = AcpiRsSetResourceSource (Aml, Info->Value, Source);
555 AcpiRsSetResourceLength (AmlLength, Aml);
556 break;
559 case ACPI_RSC_BITMASK:
561 * 8-bit encoded bitmask (DMA macro)
563 ACPI_SET8 (Destination) = (UINT8)
564 AcpiRsEncodeBitmask (Source,
565 *ACPI_ADD_PTR (UINT8, Resource, Info->Value));
566 break;
569 case ACPI_RSC_BITMASK16:
571 * 16-bit encoded bitmask (IRQ macro)
573 Temp16 = AcpiRsEncodeBitmask (Source,
574 *ACPI_ADD_PTR (UINT8, Resource, Info->Value));
575 ACPI_MOVE_16_TO_16 (Destination, &Temp16);
576 break;
579 case ACPI_RSC_EXIT_LE:
581 * Control - Exit conversion if less than or equal
583 if (ItemCount <= Info->Value)
585 goto Exit;
587 break;
590 case ACPI_RSC_EXIT_NE:
592 * Control - Exit conversion if not equal
594 switch (COMPARE_OPCODE (Info))
596 case ACPI_RSC_COMPARE_VALUE:
598 if (*ACPI_ADD_PTR (UINT8, Resource,
599 COMPARE_TARGET (Info)) != COMPARE_VALUE (Info))
601 goto Exit;
603 break;
605 default:
607 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
608 return_ACPI_STATUS (AE_BAD_PARAMETER);
610 break;
613 default:
615 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
616 return_ACPI_STATUS (AE_BAD_PARAMETER);
619 Count--;
620 Info++;
623 Exit:
624 return_ACPI_STATUS (AE_OK);
628 #if 0
629 /* Previous resource validations */
631 if (Aml->ExtAddress64.RevisionID != AML_RESOURCE_EXTENDED_ADDRESS_REVISION)
633 return_ACPI_STATUS (AE_SUPPORT);
636 if (Resource->Data.StartDpf.PerformanceRobustness >= 3)
638 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
641 if (((Aml->Irq.Flags & 0x09) == 0x00) ||
642 ((Aml->Irq.Flags & 0x09) == 0x09))
645 * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive]
646 * polarity/trigger interrupts are allowed (ACPI spec, section
647 * "IRQ Format"), so 0x00 and 0x09 are illegal.
649 ACPI_ERROR ((AE_INFO,
650 "Invalid interrupt polarity/trigger in resource list, %X",
651 Aml->Irq.Flags));
652 return_ACPI_STATUS (AE_BAD_DATA);
655 Resource->Data.ExtendedIrq.InterruptCount = Temp8;
656 if (Temp8 < 1)
658 /* Must have at least one IRQ */
660 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
663 if (Resource->Data.Dma.Transfer == 0x03)
665 ACPI_ERROR ((AE_INFO,
666 "Invalid DMA.Transfer preference (3)"));
667 return_ACPI_STATUS (AE_BAD_DATA);
669 #endif