Import acpica-unix-20061109 from Intel.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / compiler / aslrestype1.c
1
2 /******************************************************************************
3  *
4  * Module Name: aslrestype1 - Short (type1) resource templates and descriptors
5  *              $Revision: 1.39 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
18  * 2.1. This is your license from Intel Corp. under its intellectual property
19  * rights.  You may have additional license terms from the party that provided
20  * you this software, covering your right to use that party's intellectual
21  * property rights.
22  *
23  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24  * copy of the source code appearing in this file ("Covered Code") an
25  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26  * base code distributed originally by Intel ("Original Intel Code") to copy,
27  * make derivatives, distribute, use and display any portion of the Covered
28  * Code in any form, with the right to sublicense such rights; and
29  *
30  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31  * license (with the right to sublicense), under only those claims of Intel
32  * patents that are infringed by the Original Intel Code, to make, use, sell,
33  * offer to sell, and import the Covered Code and derivative works thereof
34  * solely to the minimum extent necessary to exercise the above copyright
35  * license, and in no event shall the patent license extend to any additions
36  * to or modifications of the Original Intel Code.  No other license or right
37  * is granted directly or by implication, estoppel or otherwise;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
44  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45  * Redistribution of source code of any substantial portion of the Covered
46  * Code or modification with rights to further distribute source must include
47  * the above Copyright Notice, the above License, this list of Conditions,
48  * and the following Disclaimer and Export Compliance provision.  In addition,
49  * Licensee must cause all Covered Code to which Licensee contributes to
50  * contain a file documenting the changes Licensee made to create that Covered
51  * Code and the date of any change.  Licensee must include in that file the
52  * documentation of any changes made by any predecessor Licensee.  Licensee
53  * must include a prominent statement that the modification is derived,
54  * directly or indirectly, from Original Intel Code.
55  *
56  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57  * Redistribution of source code of any substantial portion of the Covered
58  * Code or modification without rights to further distribute source must
59  * include the following Disclaimer and Export Compliance provision in the
60  * documentation and/or other materials provided with distribution.  In
61  * addition, Licensee may not authorize further sublicense of source of any
62  * portion of the Covered Code, and must include terms to the effect that the
63  * license from Licensee to its licensee is limited to the intellectual
64  * property embodied in the software Licensee provides to its licensee, and
65  * not to intellectual property embodied in modifications its licensee may
66  * make.
67  *
68  * 3.3. Redistribution of Executable. Redistribution in executable form of any
69  * substantial portion of the Covered Code or modification must reproduce the
70  * above Copyright Notice, and the following Disclaimer and Export Compliance
71  * provision in the documentation and/or other materials provided with the
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
77  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78  * Intel shall be used in advertising or otherwise to promote the sale, use or
79  * other dealings in products derived from or relating to the Covered Code
80  * without prior written authorization from Intel.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
84  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90  * PARTICULAR PURPOSE.
91  *
92  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99  * LIMITED REMEDY.
100  *
101  * 4.3. Licensee shall not export, either directly or indirectly, any of this
102  * software or system incorporating such software without first obtaining any
103  * required license or other approval from the U. S. Department of Commerce or
104  * any other agency or department of the United States Government.  In the
105  * event Licensee exports any such software from the United States or
106  * re-exports any such software from a foreign destination, Licensee shall
107  * ensure that the distribution and export/re-export of the software is in
108  * compliance with all laws, regulations, orders, or other restrictions of the
109  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110  * any of its subsidiaries will export/re-export any technical data, process,
111  * software, or service, directly or indirectly, to any country for which the
112  * United States government or any agency thereof requires an export license,
113  * other governmental approval, or letter of assurance, without first obtaining
114  * such license, approval or letter.
115  *
116  *****************************************************************************/
117
118
119 #include "aslcompiler.h"
120 #include "aslcompiler.y.h"
121
122 #define _COMPONENT          ACPI_COMPILER
123         ACPI_MODULE_NAME    ("aslrestype1")
124
125
126 /*******************************************************************************
127  *
128  * FUNCTION:    RsDoEndTagDescriptor
129  *
130  * PARAMETERS:  Op                  - Parent resource descriptor parse node
131  *              CurrentByteOffset   - Offset into the resource template AML
132  *                                    buffer (to track references to the desc)
133  *
134  * RETURN:      Completed resource node
135  *
136  * DESCRIPTION: Construct a short "EndDependentFn" descriptor
137  *
138  ******************************************************************************/
139
140 ASL_RESOURCE_NODE *
141 RsDoEndTagDescriptor (
142     ACPI_PARSE_OBJECT       *Op,
143     UINT32                  CurrentByteOffset)
144 {
145     AML_RESOURCE            *Descriptor;
146     ASL_RESOURCE_NODE       *Rnode;
147
148
149     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_END_TAG));
150
151     Descriptor = Rnode->Buffer;
152     Descriptor->EndTag.DescriptorType = ACPI_RESOURCE_NAME_END_TAG |
153                                         ASL_RDESC_END_TAG_SIZE;
154     Descriptor->EndTag.Checksum = 0;
155
156     return (Rnode);
157 }
158
159
160 /*******************************************************************************
161  *
162  * FUNCTION:    RsDoDmaDescriptor
163  *
164  * PARAMETERS:  Op                  - Parent resource descriptor parse node
165  *              CurrentByteOffset   - Offset into the resource template AML
166  *                                    buffer (to track references to the desc)
167  *
168  * RETURN:      Completed resource node
169  *
170  * DESCRIPTION: Construct a short "DMA" descriptor
171  *
172  ******************************************************************************/
173
174 ASL_RESOURCE_NODE *
175 RsDoDmaDescriptor (
176     ACPI_PARSE_OBJECT       *Op,
177     UINT32                  CurrentByteOffset)
178 {
179     AML_RESOURCE            *Descriptor;
180     ACPI_PARSE_OBJECT       *InitializerOp;
181     ASL_RESOURCE_NODE       *Rnode;
182     UINT32                  i;
183     UINT8                   DmaChannelMask = 0;
184     UINT8                   DmaChannels = 0;
185
186
187     InitializerOp = Op->Asl.Child;
188     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_DMA));
189
190     Descriptor = Rnode->Buffer;
191     Descriptor->Dma.DescriptorType  = ACPI_RESOURCE_NAME_DMA |
192                                         ASL_RDESC_DMA_SIZE;
193
194     /* Process all child initialization nodes */
195
196     for (i = 0; InitializerOp; i++)
197     {
198         switch (i)
199         {
200         case 0: /* DMA type */
201
202             RsSetFlagBits (&Descriptor->Dma.Flags, InitializerOp, 5, 0);
203             RsCreateBitField (InitializerOp, ACPI_RESTAG_DMATYPE,
204                 CurrentByteOffset + ASL_RESDESC_OFFSET (Dma.Flags), 5);
205             break;
206
207         case 1: /* Bus Master */
208
209             RsSetFlagBits (&Descriptor->Dma.Flags, InitializerOp, 2, 0);
210             RsCreateBitField (InitializerOp, ACPI_RESTAG_BUSMASTER,
211                 CurrentByteOffset + ASL_RESDESC_OFFSET (Dma.Flags), 2);
212             break;
213
214         case 2: /* Xfer Type (transfer width) */
215
216             RsSetFlagBits (&Descriptor->Dma.Flags, InitializerOp, 0, 0);
217             RsCreateBitField (InitializerOp, ACPI_RESTAG_XFERTYPE,
218                 CurrentByteOffset + ASL_RESDESC_OFFSET (Dma.Flags), 0);
219             break;
220
221         case 3: /* Name */
222
223             UtAttachNamepathToOwner (Op, InitializerOp);
224             break;
225
226         default:
227
228             /* All DMA channel bytes are handled here, after flags and name */
229
230             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
231             {
232                 /* Up to 8 channels can be specified in the list */
233
234                 DmaChannels++;
235                 if (DmaChannels > 8)
236                 {
237                     AslError (ASL_ERROR, ASL_MSG_DMA_LIST,
238                         InitializerOp, NULL);
239                     return (Rnode);
240                 }
241
242                 /* Only DMA channels 0-7 are allowed (mask is 8 bits) */
243
244                 if (InitializerOp->Asl.Value.Integer > 7)
245                 {
246                     AslError (ASL_ERROR, ASL_MSG_DMA_CHANNEL,
247                         InitializerOp, NULL);
248                 }
249
250                 /* Build the mask */
251
252                 DmaChannelMask |=
253                     (1 << ((UINT8) InitializerOp->Asl.Value.Integer));
254             }
255
256             if (i == 4) /* case 4: First DMA byte */
257             {
258                 /* Check now for duplicates in list */
259
260                 RsCheckListForDuplicates (InitializerOp);
261
262                 /* Create a named field at the start of the list */
263
264                 RsCreateByteField (InitializerOp, ACPI_RESTAG_DMA,
265                     CurrentByteOffset +
266                     ASL_RESDESC_OFFSET (Dma.DmaChannelMask));
267             }
268             break;
269         }
270
271         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
272     }
273
274     /* Now we can set the channel mask */
275
276     Descriptor->Dma.DmaChannelMask = DmaChannelMask;
277     return (Rnode);
278 }
279
280
281 /*******************************************************************************
282  *
283  * FUNCTION:    RsDoEndDependentDescriptor
284  *
285  * PARAMETERS:  Op                  - Parent resource descriptor parse node
286  *              CurrentByteOffset   - Offset into the resource template AML
287  *                                    buffer (to track references to the desc)
288  *
289  * RETURN:      Completed resource node
290  *
291  * DESCRIPTION: Construct a short "EndDependentFn" descriptor
292  *
293  ******************************************************************************/
294
295 ASL_RESOURCE_NODE *
296 RsDoEndDependentDescriptor (
297     ACPI_PARSE_OBJECT       *Op,
298     UINT32                  CurrentByteOffset)
299 {
300     AML_RESOURCE            *Descriptor;
301     ASL_RESOURCE_NODE       *Rnode;
302
303
304     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_END_DEPENDENT));
305
306     Descriptor = Rnode->Buffer;
307     Descriptor->EndDpf.DescriptorType  = ACPI_RESOURCE_NAME_END_DEPENDENT |
308                                       ASL_RDESC_END_DEPEND_SIZE;
309     return (Rnode);
310 }
311
312
313 /*******************************************************************************
314  *
315  * FUNCTION:    RsDoFixedIoDescriptor
316  *
317  * PARAMETERS:  Op                  - Parent resource descriptor parse node
318  *              CurrentByteOffset   - Offset into the resource template AML
319  *                                    buffer (to track references to the desc)
320  *
321  * RETURN:      Completed resource node
322  *
323  * DESCRIPTION: Construct a short "FixedIO" descriptor
324  *
325  ******************************************************************************/
326
327 ASL_RESOURCE_NODE *
328 RsDoFixedIoDescriptor (
329     ACPI_PARSE_OBJECT       *Op,
330     UINT32                  CurrentByteOffset)
331 {
332     AML_RESOURCE            *Descriptor;
333     ACPI_PARSE_OBJECT       *InitializerOp;
334     ASL_RESOURCE_NODE       *Rnode;
335     UINT32                  i;
336
337
338     InitializerOp = Op->Asl.Child;
339     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_FIXED_IO));
340
341     Descriptor = Rnode->Buffer;
342     Descriptor->Io.DescriptorType  = ACPI_RESOURCE_NAME_FIXED_IO |
343                                       ASL_RDESC_FIXED_IO_SIZE;
344
345     /* Process all child initialization nodes */
346
347     for (i = 0; InitializerOp; i++)
348     {
349         switch (i)
350         {
351         case 0: /* Base Address */
352
353             Descriptor->FixedIo.Address =
354                 (UINT16) InitializerOp->Asl.Value.Integer;
355             RsCreateByteField (InitializerOp, ACPI_RESTAG_BASEADDRESS,
356                 CurrentByteOffset + ASL_RESDESC_OFFSET (FixedIo.Address));
357             break;
358
359         case 1: /* Length */
360
361             Descriptor->FixedIo.AddressLength =
362                 (UINT8) InitializerOp->Asl.Value.Integer;
363             RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH,
364                 CurrentByteOffset + ASL_RESDESC_OFFSET (FixedIo.AddressLength));
365             break;
366
367         case 2: /* Name */
368
369             UtAttachNamepathToOwner (Op, InitializerOp);
370             break;
371
372         default:
373
374             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
375             break;
376         }
377
378         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
379     }
380
381     return (Rnode);
382 }
383
384
385 /*******************************************************************************
386  *
387  * FUNCTION:    RsDoIoDescriptor
388  *
389  * PARAMETERS:  Op                  - Parent resource descriptor parse node
390  *              CurrentByteOffset   - Offset into the resource template AML
391  *                                    buffer (to track references to the desc)
392  *
393  * RETURN:      Completed resource node
394  *
395  * DESCRIPTION: Construct a short "IO" descriptor
396  *
397  ******************************************************************************/
398
399 ASL_RESOURCE_NODE *
400 RsDoIoDescriptor (
401     ACPI_PARSE_OBJECT       *Op,
402     UINT32                  CurrentByteOffset)
403 {
404     AML_RESOURCE            *Descriptor;
405     ACPI_PARSE_OBJECT       *InitializerOp;
406     ASL_RESOURCE_NODE       *Rnode;
407     UINT32                  i;
408
409
410     InitializerOp = Op->Asl.Child;
411     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_IO));
412
413     Descriptor = Rnode->Buffer;
414     Descriptor->Io.DescriptorType  = ACPI_RESOURCE_NAME_IO |
415                                       ASL_RDESC_IO_SIZE;
416
417     /* Process all child initialization nodes */
418
419     for (i = 0; InitializerOp; i++)
420     {
421         switch (i)
422         {
423         case 0: /* Decode size */
424
425             RsSetFlagBits (&Descriptor->Io.Flags, InitializerOp, 0, 1);
426             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
427                 CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Flags), 0);
428             break;
429
430         case 1:  /* Min Address */
431
432             Descriptor->Io.Minimum =
433                 (UINT16) InitializerOp->Asl.Value.Integer;
434             RsCreateByteField (InitializerOp, ACPI_RESTAG_MINADDR,
435                 CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Minimum));
436             break;
437
438         case 2: /* Max Address */
439
440             Descriptor->Io.Maximum =
441                 (UINT16) InitializerOp->Asl.Value.Integer;
442             RsCreateByteField (InitializerOp, ACPI_RESTAG_MAXADDR,
443                 CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Maximum));
444             break;
445
446         case 3: /* Alignment */
447
448             Descriptor->Io.Alignment =
449                 (UINT8) InitializerOp->Asl.Value.Integer;
450             RsCreateByteField (InitializerOp, ACPI_RESTAG_ALIGNMENT,
451                 CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Alignment));
452             break;
453
454         case 4: /* Length */
455
456             Descriptor->Io.AddressLength =
457                 (UINT8) InitializerOp->Asl.Value.Integer;
458             RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH,
459                 CurrentByteOffset + ASL_RESDESC_OFFSET (Io.AddressLength));
460             break;
461
462         case 5: /* Name */
463
464             UtAttachNamepathToOwner (Op, InitializerOp);
465             break;
466
467         default:
468
469             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
470             break;
471         }
472
473         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
474     }
475
476     return (Rnode);
477 }
478
479
480 /*******************************************************************************
481  *
482  * FUNCTION:    RsDoIrqDescriptor
483  *
484  * PARAMETERS:  Op                  - Parent resource descriptor parse node
485  *              CurrentByteOffset   - Offset into the resource template AML
486  *                                    buffer (to track references to the desc)
487  *
488  * RETURN:      Completed resource node
489  *
490  * DESCRIPTION: Construct a short "IRQ" descriptor
491  *
492  ******************************************************************************/
493
494 ASL_RESOURCE_NODE *
495 RsDoIrqDescriptor (
496     ACPI_PARSE_OBJECT       *Op,
497     UINT32                  CurrentByteOffset)
498 {
499     AML_RESOURCE            *Descriptor;
500     ACPI_PARSE_OBJECT       *InitializerOp;
501     ASL_RESOURCE_NODE       *Rnode;
502     UINT32                  Interrupts = 0;
503     UINT16                  IrqMask = 0;
504     UINT32                  i;
505
506
507     InitializerOp = Op->Asl.Child;
508     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_IRQ));
509
510     /* Length = 3 (with flag byte) */
511
512     Descriptor = Rnode->Buffer;
513     Descriptor->Irq.DescriptorType  = ACPI_RESOURCE_NAME_IRQ |
514                                       (ASL_RDESC_IRQ_SIZE + 0x01);
515
516     /* Process all child initialization nodes */
517
518     for (i = 0; InitializerOp; i++)
519     {
520         switch (i)
521         {
522         case 0: /* Interrupt Type (or Mode - edge/level) */
523
524             RsSetFlagBits (&Descriptor->Irq.Flags, InitializerOp, 0, 1);
525             RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTTYPE,
526                 CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.Flags), 0);
527             break;
528
529         case 1: /* Interrupt Level (or Polarity - Active high/low) */
530
531             RsSetFlagBits (&Descriptor->Irq.Flags, InitializerOp, 3, 0);
532             RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTLEVEL,
533                 CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.Flags), 3);
534             break;
535
536         case 2: /* Share Type - Default: exclusive (0) */
537
538             RsSetFlagBits (&Descriptor->Irq.Flags, InitializerOp, 4, 0);
539             RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE,
540                 CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.Flags), 4);
541             break;
542
543         case 3: /* Name */
544
545             UtAttachNamepathToOwner (Op, InitializerOp);
546             break;
547
548         default:
549
550             /* All IRQ bytes are handled here, after the flags and name */
551
552             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
553             {
554                 /* Up to 16 interrupts can be specified in the list */
555
556                 Interrupts++;
557                 if (Interrupts > 16)
558                 {
559                     AslError (ASL_ERROR, ASL_MSG_INTERRUPT_LIST,
560                         InitializerOp, NULL);
561                     return (Rnode);
562                 }
563
564                 /* Only interrupts 0-15 are allowed (mask is 16 bits) */
565
566                 if (InitializerOp->Asl.Value.Integer > 15)
567                 {
568                     AslError (ASL_ERROR, ASL_MSG_INTERRUPT_NUMBER,
569                         InitializerOp, NULL);
570                 }
571                 else
572                 {
573                     IrqMask |= (1 << (UINT8) InitializerOp->Asl.Value.Integer);
574                 }
575             }
576
577             /* Case 4: First IRQ value in list */
578
579             if (i == 4)
580             {
581                 /* Check now for duplicates in list */
582
583                 RsCheckListForDuplicates (InitializerOp);
584
585                 /* Create a named field at the start of the list */
586
587                 RsCreateByteField (InitializerOp, ACPI_RESTAG_INTERRUPT,
588                     CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.IrqMask));
589             }
590             break;
591         }
592
593         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
594     }
595
596     /* Now we can set the channel mask */
597
598     Descriptor->Irq.IrqMask = IrqMask;
599     return (Rnode);
600 }
601
602
603 /*******************************************************************************
604  *
605  * FUNCTION:    RsDoIrqNoFlagsDescriptor
606  *
607  * PARAMETERS:  Op                  - Parent resource descriptor parse node
608  *              CurrentByteOffset   - Offset into the resource template AML
609  *                                    buffer (to track references to the desc)
610  *
611  * RETURN:      Completed resource node
612  *
613  * DESCRIPTION: Construct a short "IRQNoFlags" descriptor
614  *
615  ******************************************************************************/
616
617 ASL_RESOURCE_NODE *
618 RsDoIrqNoFlagsDescriptor (
619     ACPI_PARSE_OBJECT       *Op,
620     UINT32                  CurrentByteOffset)
621 {
622     AML_RESOURCE            *Descriptor;
623     ACPI_PARSE_OBJECT       *InitializerOp;
624     ASL_RESOURCE_NODE       *Rnode;
625     UINT16                  IrqMask = 0;
626     UINT32                  Interrupts = 0;
627     UINT32                  i;
628
629
630     InitializerOp = Op->Asl.Child;
631     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_IRQ_NOFLAGS));
632
633     Descriptor = Rnode->Buffer;
634     Descriptor->Irq.DescriptorType  = ACPI_RESOURCE_NAME_IRQ |
635                                       ASL_RDESC_IRQ_SIZE;
636
637     /* Process all child initialization nodes */
638
639     for (i = 0; InitializerOp; i++)
640     {
641         switch (i)
642         {
643         case 0: /* Name */
644
645             UtAttachNamepathToOwner (Op, InitializerOp);
646             break;
647
648         default:
649
650             /* IRQ bytes are handled here, after the flags and name */
651
652             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
653             {
654                 /* Up to 16 interrupts can be specified in the list */
655
656                 Interrupts++;
657                 if (Interrupts > 16)
658                 {
659                     AslError (ASL_ERROR, ASL_MSG_INTERRUPT_LIST,
660                         InitializerOp, NULL);
661                     return (Rnode);
662                 }
663
664                 /* Only interrupts 0-15 are allowed (mask is 16 bits) */
665
666                 if (InitializerOp->Asl.Value.Integer > 15)
667                 {
668                     AslError (ASL_ERROR, ASL_MSG_INTERRUPT_NUMBER,
669                         InitializerOp, NULL);
670                 }
671                 else
672                 {
673                     IrqMask |= (1 << ((UINT8) InitializerOp->Asl.Value.Integer));
674                 }
675             }
676
677             /* Case 1: First IRQ value in list */
678
679             if (i == 1)
680             {
681                 /* Check now for duplicates in list */
682
683                 RsCheckListForDuplicates (InitializerOp);
684
685                 /* Create a named field at the start of the list */
686
687                 RsCreateByteField (InitializerOp, ACPI_RESTAG_INTERRUPT,
688                     CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.IrqMask));
689             }
690             break;
691         }
692
693         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
694     }
695
696     /* Now we can set the interrupt mask */
697
698     Descriptor->Irq.IrqMask = IrqMask;
699     return (Rnode);
700 }
701
702
703 /*******************************************************************************
704  *
705  * FUNCTION:    RsDoMemory24Descriptor
706  *
707  * PARAMETERS:  Op                  - Parent resource descriptor parse node
708  *              CurrentByteOffset   - Offset into the resource template AML
709  *                                    buffer (to track references to the desc)
710  *
711  * RETURN:      Completed resource node
712  *
713  * DESCRIPTION: Construct a short "Memory24" descriptor
714  *
715  ******************************************************************************/
716
717 ASL_RESOURCE_NODE *
718 RsDoMemory24Descriptor (
719     ACPI_PARSE_OBJECT       *Op,
720     UINT32                  CurrentByteOffset)
721 {
722     AML_RESOURCE            *Descriptor;
723     ACPI_PARSE_OBJECT       *InitializerOp;
724     ASL_RESOURCE_NODE       *Rnode;
725     UINT32                  i;
726
727
728     InitializerOp = Op->Asl.Child;
729     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_MEMORY24));
730
731     Descriptor = Rnode->Buffer;
732     Descriptor->Memory24.DescriptorType  = ACPI_RESOURCE_NAME_MEMORY24;
733     Descriptor->Memory24.ResourceLength = 9;
734
735     /* Process all child initialization nodes */
736
737     for (i = 0; InitializerOp; i++)
738     {
739         switch (i)
740         {
741         case 0: /* Read/Write type */
742
743             RsSetFlagBits (&Descriptor->Memory24.Flags, InitializerOp, 0, 1);
744             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
745                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Flags), 0);
746             break;
747
748         case 1: /* Min Address */
749
750             Descriptor->Memory24.Minimum = (UINT16) InitializerOp->Asl.Value.Integer;
751             RsCreateByteField (InitializerOp, ACPI_RESTAG_MINADDR,
752                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Minimum));
753             break;
754
755         case 2: /* Max Address */
756
757             Descriptor->Memory24.Maximum = (UINT16) InitializerOp->Asl.Value.Integer;
758             RsCreateByteField (InitializerOp, ACPI_RESTAG_MAXADDR,
759                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Maximum));
760             break;
761
762         case 3: /* Alignment */
763
764             Descriptor->Memory24.Alignment = (UINT16) InitializerOp->Asl.Value.Integer;
765             RsCreateByteField (InitializerOp, ACPI_RESTAG_ALIGNMENT,
766                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Alignment));
767             break;
768
769         case 4: /* Length */
770
771             Descriptor->Memory24.AddressLength = (UINT16) InitializerOp->Asl.Value.Integer;
772             RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH,
773                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.AddressLength));
774             break;
775
776         case 5: /* Name */
777
778             UtAttachNamepathToOwner (Op, InitializerOp);
779             break;
780
781         default:
782
783             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
784             break;
785         }
786
787         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
788     }
789
790     return (Rnode);
791 }
792
793
794 /*******************************************************************************
795  *
796  * FUNCTION:    RsDoMemory32Descriptor
797  *
798  * PARAMETERS:  Op                  - Parent resource descriptor parse node
799  *              CurrentByteOffset   - Offset into the resource template AML
800  *                                    buffer (to track references to the desc)
801  *
802  * RETURN:      Completed resource node
803  *
804  * DESCRIPTION: Construct a short "Memory32" descriptor
805  *
806  ******************************************************************************/
807
808 ASL_RESOURCE_NODE *
809 RsDoMemory32Descriptor (
810     ACPI_PARSE_OBJECT       *Op,
811     UINT32                  CurrentByteOffset)
812 {
813     AML_RESOURCE            *Descriptor;
814     ACPI_PARSE_OBJECT       *InitializerOp;
815     ASL_RESOURCE_NODE       *Rnode;
816     UINT32                  i;
817
818
819     InitializerOp = Op->Asl.Child;
820     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_MEMORY32));
821
822     Descriptor = Rnode->Buffer;
823     Descriptor->Memory32.DescriptorType  = ACPI_RESOURCE_NAME_MEMORY32;
824     Descriptor->Memory32.ResourceLength = 17;
825
826     /* Process all child initialization nodes */
827
828     for (i = 0; InitializerOp; i++)
829     {
830         switch (i)
831         {
832         case 0: /* Read/Write type */
833
834             RsSetFlagBits (&Descriptor->Memory32.Flags, InitializerOp, 0, 1);
835             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
836                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Flags), 0);
837             break;
838
839         case 1:  /* Min Address */
840
841             Descriptor->Memory32.Minimum = (UINT32) InitializerOp->Asl.Value.Integer;
842             RsCreateByteField (InitializerOp, ACPI_RESTAG_MINADDR,
843                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Minimum));
844             break;
845
846         case 2: /* Max Address */
847
848             Descriptor->Memory32.Maximum = (UINT32) InitializerOp->Asl.Value.Integer;
849             RsCreateByteField (InitializerOp, ACPI_RESTAG_MAXADDR,
850                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Maximum));
851             break;
852
853         case 3: /* Alignment */
854
855             Descriptor->Memory32.Alignment = (UINT32) InitializerOp->Asl.Value.Integer;
856             RsCreateByteField (InitializerOp, ACPI_RESTAG_ALIGNMENT,
857                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Alignment));
858             break;
859
860         case 4: /* Length */
861
862             Descriptor->Memory32.AddressLength = (UINT32) InitializerOp->Asl.Value.Integer;
863             RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH,
864                 CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.AddressLength));
865             break;
866
867         case 5: /* Name */
868
869             UtAttachNamepathToOwner (Op, InitializerOp);
870             break;
871
872         default:
873
874             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
875             break;
876         }
877
878         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
879     }
880
881     return (Rnode);
882 }
883
884
885 /*******************************************************************************
886  *
887  * FUNCTION:    RsDoMemory32FixedDescriptor
888  *
889  * PARAMETERS:  Op                  - Parent resource descriptor parse node
890  *              CurrentByteOffset   - Offset into the resource template AML
891  *                                    buffer (to track references to the desc)
892  *
893  * RETURN:      Completed resource node
894  *
895  * DESCRIPTION: Construct a short "Memory32Fixed" descriptor
896  *
897  ******************************************************************************/
898
899 ASL_RESOURCE_NODE *
900 RsDoMemory32FixedDescriptor (
901     ACPI_PARSE_OBJECT       *Op,
902     UINT32                  CurrentByteOffset)
903 {
904     AML_RESOURCE            *Descriptor;
905     ACPI_PARSE_OBJECT       *InitializerOp;
906     ASL_RESOURCE_NODE       *Rnode;
907     UINT32                  i;
908
909
910     InitializerOp = Op->Asl.Child;
911     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_FIXED_MEMORY32));
912
913     Descriptor = Rnode->Buffer;
914     Descriptor->FixedMemory32.DescriptorType  = ACPI_RESOURCE_NAME_FIXED_MEMORY32;
915     Descriptor->FixedMemory32.ResourceLength = 9;
916
917     /* Process all child initialization nodes */
918
919     for (i = 0; InitializerOp; i++)
920     {
921         switch (i)
922         {
923         case 0: /* Read/Write type */
924
925             RsSetFlagBits (&Descriptor->FixedMemory32.Flags, InitializerOp, 0, 1);
926             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
927                 CurrentByteOffset + ASL_RESDESC_OFFSET (FixedMemory32.Flags), 0);
928             break;
929
930         case 1: /* Address */
931
932             Descriptor->FixedMemory32.Address = (UINT32) InitializerOp->Asl.Value.Integer;
933             RsCreateByteField (InitializerOp, ACPI_RESTAG_BASEADDRESS,
934                 CurrentByteOffset + ASL_RESDESC_OFFSET (FixedMemory32.Address));
935             break;
936
937         case 2: /* Length */
938
939             Descriptor->FixedMemory32.AddressLength = (UINT32) InitializerOp->Asl.Value.Integer;
940             RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH,
941                 CurrentByteOffset + ASL_RESDESC_OFFSET (FixedMemory32.AddressLength));
942             break;
943
944         case 3: /* Name */
945
946             UtAttachNamepathToOwner (Op, InitializerOp);
947             break;
948
949         default:
950
951             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
952             break;
953         }
954
955         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
956     }
957
958     return (Rnode);
959 }
960
961
962 /*******************************************************************************
963  *
964  * FUNCTION:    RsDoStartDependentDescriptor
965  *
966  * PARAMETERS:  Op                  - Parent resource descriptor parse node
967  *              CurrentByteOffset   - Offset into the resource template AML
968  *                                    buffer (to track references to the desc)
969  *
970  * RETURN:      Completed resource node
971  *
972  * DESCRIPTION: Construct a short "StartDependentFn" descriptor
973  *
974  ******************************************************************************/
975
976 ASL_RESOURCE_NODE *
977 RsDoStartDependentDescriptor (
978     ACPI_PARSE_OBJECT       *Op,
979     UINT32                  CurrentByteOffset)
980 {
981     AML_RESOURCE            *Descriptor;
982     ACPI_PARSE_OBJECT       *InitializerOp;
983     ASL_RESOURCE_NODE       *Rnode;
984     ASL_RESOURCE_NODE       *PreviousRnode;
985     ASL_RESOURCE_NODE       *NextRnode;
986     UINT32                  i;
987     UINT8                   State;
988
989
990     InitializerOp = Op->Asl.Child;
991     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_START_DEPENDENT));
992
993     PreviousRnode = Rnode;
994     Descriptor = Rnode->Buffer;
995
996     /* Descriptor has priority byte */
997
998     Descriptor->StartDpf.DescriptorType  = ACPI_RESOURCE_NAME_START_DEPENDENT |
999                                       (ASL_RDESC_ST_DEPEND_SIZE + 0x01);
1000
1001     /* Process all child initialization nodes */
1002
1003     State = ACPI_RSTATE_START_DEPENDENT;
1004     for (i = 0; InitializerOp; i++)
1005     {
1006         switch (i)
1007         {
1008         case 0: /* Compatibility Priority */
1009
1010             if ((UINT8) InitializerOp->Asl.Value.Integer > 2)
1011             {
1012                 AslError (ASL_ERROR, ASL_MSG_INVALID_PRIORITY,
1013                     InitializerOp, NULL);
1014             }
1015
1016             RsSetFlagBits (&Descriptor->StartDpf.Flags, InitializerOp, 0, 0);
1017             break;
1018
1019         case 1: /* Performance/Robustness Priority */
1020
1021             if ((UINT8) InitializerOp->Asl.Value.Integer > 2)
1022             {
1023                 AslError (ASL_ERROR, ASL_MSG_INVALID_PERFORMANCE,
1024                     InitializerOp, NULL);
1025             }
1026
1027             RsSetFlagBits (&Descriptor->StartDpf.Flags, InitializerOp, 2, 0);
1028             break;
1029
1030         default:
1031             NextRnode = RsDoOneResourceDescriptor  (InitializerOp,
1032                         CurrentByteOffset, &State);
1033
1034             /*
1035              * Update current byte offset to indicate the number of bytes from the
1036              * start of the buffer.  Buffer can include multiple descriptors, we
1037              * must keep track of the offset of not only each descriptor, but each
1038              * element (field) within each descriptor as well.
1039              */
1040
1041             CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode,
1042                                     NextRnode);
1043             break;
1044         }
1045
1046         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
1047     }
1048
1049     return (Rnode);
1050 }
1051
1052
1053 /*******************************************************************************
1054  *
1055  * FUNCTION:    RsDoStartDependentNoPriDescriptor
1056  *
1057  * PARAMETERS:  Op                  - Parent resource descriptor parse node
1058  *              CurrentByteOffset   - Offset into the resource template AML
1059  *                                    buffer (to track references to the desc)
1060  *
1061  * RETURN:      Completed resource node
1062  *
1063  * DESCRIPTION: Construct a short "StartDependentNoPri" descriptor
1064  *
1065  ******************************************************************************/
1066
1067 ASL_RESOURCE_NODE *
1068 RsDoStartDependentNoPriDescriptor (
1069     ACPI_PARSE_OBJECT       *Op,
1070     UINT32                  CurrentByteOffset)
1071 {
1072     AML_RESOURCE            *Descriptor;
1073     ACPI_PARSE_OBJECT       *InitializerOp;
1074     ASL_RESOURCE_NODE       *Rnode;
1075     ASL_RESOURCE_NODE       *PreviousRnode;
1076     ASL_RESOURCE_NODE       *NextRnode;
1077     UINT8                   State;
1078
1079
1080     InitializerOp = Op->Asl.Child;
1081     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_START_DEPENDENT_NOPRIO));
1082
1083     Descriptor = Rnode->Buffer;
1084     Descriptor->StartDpf.DescriptorType  = ACPI_RESOURCE_NAME_START_DEPENDENT |
1085                                       ASL_RDESC_ST_DEPEND_SIZE;
1086     PreviousRnode = Rnode;
1087
1088     /* Process all child initialization nodes */
1089
1090     State = ACPI_RSTATE_START_DEPENDENT;
1091     while (InitializerOp)
1092     {
1093         NextRnode = RsDoOneResourceDescriptor  (InitializerOp,
1094                         CurrentByteOffset, &State);
1095
1096         /*
1097          * Update current byte offset to indicate the number of bytes from the
1098          * start of the buffer.  Buffer can include multiple descriptors, we
1099          * must keep track of the offset of not only each descriptor, but each
1100          * element (field) within each descriptor as well.
1101          */
1102         CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, NextRnode);
1103
1104         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
1105     }
1106
1107     return (Rnode);
1108 }
1109
1110
1111 /*******************************************************************************
1112  *
1113  * FUNCTION:    RsDoVendorSmallDescriptor
1114  *
1115  * PARAMETERS:  Op                  - Parent resource descriptor parse node
1116  *              CurrentByteOffset   - Offset into the resource template AML
1117  *                                    buffer (to track references to the desc)
1118  *
1119  * RETURN:      Completed resource node
1120  *
1121  * DESCRIPTION: Construct a short "VendorShort" descriptor
1122  *
1123  ******************************************************************************/
1124
1125 ASL_RESOURCE_NODE *
1126 RsDoVendorSmallDescriptor (
1127     ACPI_PARSE_OBJECT       *Op,
1128     UINT32                  CurrentByteOffset)
1129 {
1130     AML_RESOURCE            *Descriptor;
1131     ACPI_PARSE_OBJECT       *InitializerOp;
1132     ASL_RESOURCE_NODE       *Rnode;
1133     UINT8                   *VendorData;
1134     UINT32                  i;
1135
1136
1137     InitializerOp = Op->Asl.Child;
1138
1139     /* Allocate worst case - 7 vendor bytes */
1140
1141     Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_VENDOR_SMALL) + 7);
1142
1143     Descriptor = Rnode->Buffer;
1144     Descriptor->VendorSmall.DescriptorType  = ACPI_RESOURCE_NAME_VENDOR_SMALL;
1145     VendorData = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_SMALL_HEADER);
1146
1147     /* Process all child initialization nodes */
1148
1149     InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
1150     for (i = 0; InitializerOp; i++)
1151     {
1152         if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
1153         {
1154             break;
1155         }
1156
1157         /* Maximum 7 vendor data bytes allowed (0-6) */
1158
1159         if (i >= 7)
1160         {
1161             AslError (ASL_ERROR, ASL_MSG_VENDOR_LIST, InitializerOp, NULL);
1162
1163             /* Eat the excess initializers */
1164
1165             while (InitializerOp)
1166             {
1167                 InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
1168             }
1169             break;
1170         }
1171
1172         VendorData[i] = (UINT8) InitializerOp->Asl.Value.Integer;
1173         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
1174     }
1175
1176     /* Adjust the Rnode buffer size, so correct number of bytes are emitted */
1177
1178     Rnode->BufferLength -= (7 - i);
1179
1180     /* Set the length in the Type Tag */
1181
1182     Descriptor->VendorSmall.DescriptorType |= (UINT8) i;
1183     return (Rnode);
1184 }
1185
1186