kernel: scheduling fix for ARM
[minix.git] / drivers / acpi / resources / rsmisc.c
blob191c7a91c9ca962f9a41772be04cb1532581e1cf
1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous resource descriptors
5 ******************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __RSMISC_C__
118 #include "acpi.h"
119 #include "accommon.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_SIZE) 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 0x%2.2X Length %u",
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 case ACPI_RSC_EXIT_EQ:
615 * Control - Exit conversion if equal
617 if (*ACPI_ADD_PTR (UINT8, Resource,
618 COMPARE_TARGET (Info)) == COMPARE_VALUE (Info))
620 goto Exit;
622 break;
625 default:
627 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
628 return_ACPI_STATUS (AE_BAD_PARAMETER);
631 Count--;
632 Info++;
635 Exit:
636 return_ACPI_STATUS (AE_OK);
640 #if 0
641 /* Previous resource validations */
643 if (Aml->ExtAddress64.RevisionID != AML_RESOURCE_EXTENDED_ADDRESS_REVISION)
645 return_ACPI_STATUS (AE_SUPPORT);
648 if (Resource->Data.StartDpf.PerformanceRobustness >= 3)
650 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
653 if (((Aml->Irq.Flags & 0x09) == 0x00) ||
654 ((Aml->Irq.Flags & 0x09) == 0x09))
657 * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive]
658 * polarity/trigger interrupts are allowed (ACPI spec, section
659 * "IRQ Format"), so 0x00 and 0x09 are illegal.
661 ACPI_ERROR ((AE_INFO,
662 "Invalid interrupt polarity/trigger in resource list, 0x%X",
663 Aml->Irq.Flags));
664 return_ACPI_STATUS (AE_BAD_DATA);
667 Resource->Data.ExtendedIrq.InterruptCount = Temp8;
668 if (Temp8 < 1)
670 /* Must have at least one IRQ */
672 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
675 if (Resource->Data.Dma.Transfer == 0x03)
677 ACPI_ERROR ((AE_INFO,
678 "Invalid DMA.Transfer preference (3)"));
679 return_ACPI_STATUS (AE_BAD_DATA);
681 #endif