Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
 
2
 *
3
 * Module Name: aslresource - Resource template/descriptor utilities
4
 *
5
 *****************************************************************************/
6
7
 
8
 *
9
 * 1. Copyright Notice
10
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12
 * All rights reserved.
13
 *
14
 * 2. License
15
 *
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.
20
 *
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
27
 *
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;
36
 *
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
39
 *
40
 * 3. Conditions
41
 *
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.
53
 *
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.
65
 *
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.
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
74
 *
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.
79
 *
80
 * 4. Disclaimer and Export Compliance
81
 *
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.
89
 *
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.
98
 *
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.
113
 *
114
 *****************************************************************************/
115
116
 
117
 
118
#include "aslcompiler.y.h"
119
#include "amlcode.h"
120
121
 
122
 
123
        ACPI_MODULE_NAME    ("aslresource")
124
125
 
126
 
127
 *
128
 * FUNCTION:    RsSmallAddressCheck
129
 *
130
 * PARAMETERS:  Minimum             - Address Min value
131
 *              Maximum             - Address Max value
132
 *              Length              - Address range value
133
 *              Alignment           - Address alignment value
134
 *              MinOp               - Original Op for Address Min
135
 *              MaxOp               - Original Op for Address Max
136
 *              LengthOp            - Original Op for address range
137
 *              AlignOp             - Original Op for address alignment. If
138
 *                                    NULL, means "zero value for alignment is
139
 *                                    OK, and means 64K alignment" (for
140
 *                                    Memory24 descriptor)
141
 *
142
 * RETURN:      None. Adds error messages to error log if necessary
143
 *
144
 * DESCRIPTION: Perform common value checks for "small" address descriptors.
145
 *              Currently:
146
 *                  Io, Memory24, Memory32
147
 *
148
 ******************************************************************************/
149
150
 
151
RsSmallAddressCheck (
152
    UINT8                   Type,
153
    UINT32                  Minimum,
154
    UINT32                  Maximum,
155
    UINT32                  Length,
156
    UINT32                  Alignment,
157
    ACPI_PARSE_OBJECT       *MinOp,
158
    ACPI_PARSE_OBJECT       *MaxOp,
159
    ACPI_PARSE_OBJECT       *LengthOp,
160
    ACPI_PARSE_OBJECT       *AlignOp)
161
{
162
163
 
164
    {
165
        return;
166
    }
167
168
 
169
170
 
171
    {
172
        if (!Alignment) /* Alignment==0 means 64K - no invalid alignment */
173
        {
174
            Alignment = ACPI_UINT16_MAX + 1;
175
        }
176
177
 
178
        Maximum <<= 8;
179
        Length *= 256;
180
    }
181
182
 
183
184
 
185
    {
186
        /* Basic checks on Min/Max/Length */
187
188
 
189
        {
190
            AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
191
        }
192
        else if (Length > (Maximum - Minimum + 1))
193
        {
194
            AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
195
        }
196
    }
197
198
 
199
200
 
201
    {
202
        Alignment = 1;
203
    }
204
205
 
206
207
 
208
    {
209
        AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
210
    }
211
    if (Maximum % Alignment)
212
    {
213
        AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
214
    }
215
}
216
217
 
218
 
219
 *
220
 * FUNCTION:    RsLargeAddressCheck
221
 *
222
 * PARAMETERS:  Minimum             - Address Min value
223
 *              Maximum             - Address Max value
224
 *              Length              - Address range value
225
 *              Granularity         - Address granularity value
226
 *              Flags               - General flags for address descriptors:
227
 *                                    _MIF, _MAF, _DEC
228
 *              MinOp               - Original Op for Address Min
229
 *              MaxOp               - Original Op for Address Max
230
 *              LengthOp            - Original Op for address range
231
 *              GranOp              - Original Op for address granularity
232
 *
233
 * RETURN:      None. Adds error messages to error log if necessary
234
 *
235
 * DESCRIPTION: Perform common value checks for "large" address descriptors.
236
 *              Currently:
237
 *                  WordIo,     WordBusNumber,  WordSpace
238
 *                  DWordIo,    DWordMemory,    DWordSpace
239
 *                  QWordIo,    QWordMemory,    QWordSpace
240
 *                  ExtendedIo, ExtendedMemory, ExtendedSpace
241
 *
242
 * _MIF flag set means that the minimum address is fixed and is not relocatable
243
 * _MAF flag set means that the maximum address is fixed and is not relocatable
244
 * Length of zero means that the record size is variable
245
 *
246
 * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
247
 * of the ACPI 4.0a specification. Added 04/2010.
248
 *
249
 ******************************************************************************/
250
251
 
252
RsLargeAddressCheck (
253
    UINT64                  Minimum,
254
    UINT64                  Maximum,
255
    UINT64                  Length,
256
    UINT64                  Granularity,
257
    UINT8                   Flags,
258
    ACPI_PARSE_OBJECT       *MinOp,
259
    ACPI_PARSE_OBJECT       *MaxOp,
260
    ACPI_PARSE_OBJECT       *LengthOp,
261
    ACPI_PARSE_OBJECT       *GranOp)
262
{
263
264
 
265
    {
266
        return;
267
    }
268
269
 
270
271
 
272
    {
273
        AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
274
        return;
275
    }
276
    else if (Length > (Maximum - Minimum + 1))
277
    {
278
        AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
279
        return;
280
    }
281
282
 
283
284
 
285
    {
286
        if ((Granularity + 1) &
287
             Granularity)
288
        {
289
            AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
290
            return;
291
        }
292
    }
293
294
 
295
     * Check the various combinations of Length, MinFixed, and MaxFixed
296
     */
297
    if (Length)
298
    {
299
        /* Fixed non-zero length */
300
301
 
302
        {
303
        case 0:
304
            /*
305
             * Fixed length, variable locations (both _MIN and _MAX).
306
             * Length must be a multiple of granularity
307
             */
308
            if (Granularity & Length)
309
            {
310
                AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
311
            }
312
            break;
313
314
 
315
316
 
317
318
 
319
            {
320
                AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
321
            }
322
323
 
324
325
 
326
            {
327
                AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
328
            }
329
            break;
330
331
 
332
333
 
334
        case ACPI_RESOURCE_FLAG_MAF:
335
        default:
336
            AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
337
        }
338
    }
339
    else
340
    {
341
        /* Variable length (length==0) */
342
343
 
344
        {
345
        case 0:
346
            /*
347
             * Both _MIN and _MAX are variable.
348
             * No additional requirements, just exit
349
             */
350
            break;
351
352
 
353
354
 
355
356
 
357
             * The granularity is defined by the ACPI specification to be a
358
             * power-of-two minus one, therefore the granularity is a
359
             * bitmask which can be used to easily validate the addresses.
360
             */
361
            if (Granularity & Minimum)
362
            {
363
                AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
364
            }
365
            break;
366
367
 
368
369
 
370
371
 
372
            {
373
                AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
374
            }
375
            break;
376
377
 
378
379
 
380
        default:
381
            AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
382
        }
383
    }
384
}
385
386
 
387
 
388
 *
389
 * FUNCTION:    RsGetStringDataLength
390
 *
391
 * PARAMETERS:  InitializerOp     - Start of a subtree of init nodes
392
 *
393
 * RETURN:      Valid string length if a string node is found (otherwise 0)
394
 *
395
 * DESCRIPTION: In a list of peer nodes, find the first one that contains a
396
 *              string and return the length of the string.
397
 *
398
 ******************************************************************************/
399
400
 
401
RsGetStringDataLength (
402
    ACPI_PARSE_OBJECT       *InitializerOp)
403
{
404
405
 
406
    {
407
        if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
408
        {
409
            return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
410
        }
411
        InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
412
    }
413
414
 
415
}
416
417
 
418
 
419
 *
420
 * FUNCTION:    RsAllocateResourceNode
421
 *
422
 * PARAMETERS:  Size        - Size of node in bytes
423
 *
424
 * RETURN:      The allocated node - aborts on allocation failure
425
 *
426
 * DESCRIPTION: Allocate a resource description node and the resource
427
 *              descriptor itself (the nodes are used to link descriptors).
428
 *
429
 ******************************************************************************/
430
431
 
432
RsAllocateResourceNode (
433
    UINT32                  Size)
434
{
435
    ASL_RESOURCE_NODE       *Rnode;
436
437
 
438
 
439
440
 
441
442
 
443
444
 
445
    Rnode->BufferLength = Size;
446
447
 
448
}
449
450
 
451
 
452
 *
453
 * FUNCTION:    RsCreateBitField
454
 *
455
 * PARAMETERS:  Op              - Resource field node
456
 *              Name            - Name of the field (Used only to reference
457
 *                                the field in the ASL, not in the AML)
458
 *              ByteOffset      - Offset from the field start
459
 *              BitOffset       - Additional bit offset
460
 *
461
 * RETURN:      None, sets fields within the input node
462
 *
463
 * DESCRIPTION: Utility function to generate a named bit field within a
464
 *              resource descriptor.  Mark a node as 1) a field in a resource
465
 *              descriptor, and 2) set the value to be a BIT offset
466
 *
467
 ******************************************************************************/
468
469
 
470
RsCreateBitField (
471
    ACPI_PARSE_OBJECT       *Op,
472
    char                    *Name,
473
    UINT32                  ByteOffset,
474
    UINT32                  BitOffset)
475
{
476
477
 
478
    Op->Asl.Value.Integer     = ((UINT64) ByteOffset * 8) + BitOffset;
479
    Op->Asl.CompileFlags     |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
480
}
481
482
 
483
 
484
 *
485
 * FUNCTION:    RsCreateByteField
486
 *
487
 * PARAMETERS:  Op              - Resource field node
488
 *              Name            - Name of the field (Used only to reference
489
 *                                the field in the ASL, not in the AML)
490
 *              ByteOffset      - Offset from the field start
491
 *
492
 * RETURN:      None, sets fields within the input node
493
 *
494
 * DESCRIPTION: Utility function to generate a named byte field within a
495
 *              resource descriptor.  Mark a node as 1) a field in a resource
496
 *              descriptor, and 2) set the value to be a BYTE offset
497
 *
498
 ******************************************************************************/
499
500
 
501
RsCreateByteField (
502
    ACPI_PARSE_OBJECT       *Op,
503
    char                    *Name,
504
    UINT32                  ByteOffset)
505
{
506
507
 
508
    Op->Asl.Value.Integer     = ByteOffset;
509
    Op->Asl.CompileFlags     |= NODE_IS_RESOURCE_FIELD;
510
}
511
512
 
513
 
514
 *
515
 * FUNCTION:    RsSetFlagBits
516
 *
517
 * PARAMETERS:  *Flags          - Pointer to the flag byte
518
 *              Op              - Flag initialization node
519
 *              Position        - Bit position within the flag byte
520
 *              Default         - Used if the node is DEFAULT.
521
 *
522
 * RETURN:      Sets bits within the *Flags output byte.
523
 *
524
 * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
525
 *              node.  Will use a default value if the node is DEFAULT, meaning
526
 *              that no value was specified in the ASL.  Used to merge multiple
527
 *              keywords into a single flags byte.
528
 *
529
 ******************************************************************************/
530
531
 
532
RsSetFlagBits (
533
    UINT8                   *Flags,
534
    ACPI_PARSE_OBJECT       *Op,
535
    UINT8                   Position,
536
    UINT8                   DefaultBit)
537
{
538
539
 
540
    {
541
        /* Use the default bit */
542
543
 
544
    }
545
    else
546
    {
547
        /* Use the bit specified in the initialization node */
548
549
 
550
    }
551
}
552
553
 
554
 
555
 *
556
 * FUNCTION:    RsCompleteNodeAndGetNext
557
 *
558
 * PARAMETERS:  Op            - Resource node to be completed
559
 *
560
 * RETURN:      The next peer to the input node.
561
 *
562
 * DESCRIPTION: Mark the current node completed and return the next peer.
563
 *              The node ParseOpcode is set to DEFAULT_ARG, meaning that
564
 *              this node is to be ignored from now on.
565
 *
566
 ******************************************************************************/
567
568
 
569
RsCompleteNodeAndGetNext (
570
    ACPI_PARSE_OBJECT       *Op)
571
{
572
573
 
574
575
 
576
577
 
578
579
 
580
}
581
582
 
583
 
584
 *
585
 * FUNCTION:    RsCheckListForDuplicates
586
 *
587
 * PARAMETERS:  Op                  - First op in the initializer list
588
 *
589
 * RETURN:      None
590
 *
591
 * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
592
 *              if any duplicates are found.
593
 *
594
 ******************************************************************************/
595
596
 
597
RsCheckListForDuplicates (
598
    ACPI_PARSE_OBJECT       *Op)
599
{
600
    ACPI_PARSE_OBJECT       *NextValueOp = Op;
601
    ACPI_PARSE_OBJECT       *NextOp;
602
    UINT32                  Value;
603
604
 
605
 
606
    {
607
        return;
608
    }
609
610
 
611
612
 
613
    {
614
        Value = (UINT32) NextValueOp->Asl.Value.Integer;
615
616
 
617
618
 
619
        while (NextOp)
620
        {
621
            if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
622
            {
623
                /* Compare values */
624
625
 
626
                {
627
                    /* Emit error only once per duplicate node */
628
629
 
630
                    {
631
                        NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
632
                        AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
633
                            NextOp, NULL);
634
                    }
635
                }
636
            }
637
638
 
639
        }
640
641
 
642
    }
643
}
644
645
 
646
 
647
 *
648
 * FUNCTION:    RsDoOneResourceDescriptor
649
 *
650
 * PARAMETERS:  DescriptorTypeOp    - Parent parse node of the descriptor
651
 *              CurrentByteOffset   - Offset in the resource descriptor
652
 *                                    buffer.
653
 *
654
 * RETURN:      A valid resource node for the descriptor
655
 *
656
 * DESCRIPTION: Dispatches the processing of one resource descriptor
657
 *
658
 ******************************************************************************/
659
660
 
661
RsDoOneResourceDescriptor (
662
    ACPI_PARSE_OBJECT       *DescriptorTypeOp,
663
    UINT32                  CurrentByteOffset,
664
    UINT8                   *State)
665
{
666
    ASL_RESOURCE_NODE       *Rnode = NULL;
667
668
 
669
 
670
671
 
672
    {
673
    case PARSEOP_DMA:
674
        Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
675
                    CurrentByteOffset);
676
        break;
677
678
 
679
        Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
680
                    CurrentByteOffset);
681
        break;
682
683
 
684
        Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
685
                    CurrentByteOffset);
686
        break;
687
688
 
689
        Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
690
                    CurrentByteOffset);
691
        break;
692
693
 
694
        switch (*State)
695
        {
696
        case ACPI_RSTATE_NORMAL:
697
            AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
698
                DescriptorTypeOp, NULL);
699
            break;
700
701
 
702
            AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
703
                DescriptorTypeOp, NULL);
704
            break;
705
706
 
707
        default:
708
            break;
709
        }
710
711
 
712
        Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
713
                    CurrentByteOffset);
714
        break;
715
716
 
717
        Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
718
                    CurrentByteOffset);
719
        break;
720
721
 
722
        Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
723
                    CurrentByteOffset);
724
        break;
725
726
 
727
        Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
728
                    CurrentByteOffset);
729
        break;
730
731
 
732
        Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
733
                    CurrentByteOffset);
734
        break;
735
736
 
737
        Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
738
                    CurrentByteOffset);
739
        break;
740
741
 
742
        Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
743
                    CurrentByteOffset);
744
        break;
745
746
 
747
        Rnode = RsDoIoDescriptor (DescriptorTypeOp,
748
                    CurrentByteOffset);
749
        break;
750
751
 
752
        Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
753
                    CurrentByteOffset);
754
        break;
755
756
 
757
        Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
758
                    CurrentByteOffset);
759
        break;
760
761
 
762
        Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
763
                    CurrentByteOffset);
764
        break;
765
766
 
767
        Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
768
                    CurrentByteOffset);
769
        break;
770
771
 
772
        Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
773
                    CurrentByteOffset);
774
        break;
775
776
 
777
        Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
778
                    CurrentByteOffset);
779
        break;
780
781
 
782
        Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
783
                    CurrentByteOffset);
784
        break;
785
786
 
787
        Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
788
                    CurrentByteOffset);
789
        break;
790
791
 
792
        Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
793
                    CurrentByteOffset);
794
        break;
795
796
 
797
        switch (*State)
798
        {
799
        case ACPI_RSTATE_START_DEPENDENT:
800
            AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
801
                DescriptorTypeOp, NULL);
802
            break;
803
804
 
805
        case ACPI_RSTATE_DEPENDENT_LIST:
806
        default:
807
            break;
808
        }
809
810
 
811
        Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
812
                    CurrentByteOffset);
813
        *State = ACPI_RSTATE_DEPENDENT_LIST;
814
        break;
815
816
 
817
        switch (*State)
818
        {
819
        case ACPI_RSTATE_START_DEPENDENT:
820
            AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
821
                DescriptorTypeOp, NULL);
822
            break;
823
824
 
825
        case ACPI_RSTATE_DEPENDENT_LIST:
826
        default:
827
            break;
828
        }
829
830
 
831
        Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
832
                    CurrentByteOffset);
833
        *State = ACPI_RSTATE_DEPENDENT_LIST;
834
        break;
835
836
 
837
        Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
838
                    CurrentByteOffset);
839
        break;
840
841
 
842
        Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
843
                    CurrentByteOffset);
844
        break;
845
846
 
847
        Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
848
                    CurrentByteOffset);
849
        break;
850
851
 
852
        Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
853
                    CurrentByteOffset);
854
        break;
855
856
 
857
        Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
858
                    CurrentByteOffset);
859
        break;
860
861
 
862
        /* Just ignore any of these, they are used as fillers/placeholders */
863
        break;
864
865
 
866
        printf ("Unknown resource descriptor type [%s]\n",
867
                    DescriptorTypeOp->Asl.ParseOpName);
868
        break;
869
    }
870
871
 
872
     * Mark original node as unused, but head of a resource descriptor.
873
     * This allows the resource to be installed in the namespace so that
874
     * references to the descriptor can be resolved.
875
     */
876
    DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
877
    DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
878
    DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
879
880
 
881
    {
882
        DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
883
    }
884
885
 
886
}
887
888
 
889
 
890
 *
891
 * FUNCTION:    RsLinkDescriptorChain
892
 *
893
 * PARAMETERS:  PreviousRnode       - Pointer to the node that will be previous
894
 *                                    to the linked node,  At exit, set to the
895
 *                                    last node in the new chain.
896
 *              Rnode               - Resource node to link into the list
897
 *
898
 * RETURN:      Cumulative buffer byte offset of the new segment of chain
899
 *
900
 * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
901
 *
902
 ******************************************************************************/
903
904
 
905
RsLinkDescriptorChain (
906
    ASL_RESOURCE_NODE       **PreviousRnode,
907
    ASL_RESOURCE_NODE       *Rnode)
908
{
909
    ASL_RESOURCE_NODE       *LastRnode;
910
    UINT32                  CurrentByteOffset;
911
912
 
913
 
914
915
 
916
    {
917
        return 0;
918
    }
919
920
 
921
922
 
923
    CurrentByteOffset = Rnode->BufferLength;
924
925
 
926
927
 
928
    while (LastRnode->Next)
929
    {
930
        LastRnode = LastRnode->Next;
931
        CurrentByteOffset += LastRnode->BufferLength;
932
    }
933
934
 
935
936
 
937
    return CurrentByteOffset;
938
}
939
940
 
941
 
942
 *
943
 * FUNCTION:    RsDoResourceTemplate
944
 *
945
 * PARAMETERS:  Op        - Parent of a resource template list
946
 *
947
 * RETURN:      None.  Sets input node to point to a list of AML code
948
 *
949
 * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
950
 *              in preparation for output to the AML output file.
951
 *
952
 ******************************************************************************/
953
954
 
955
RsDoResourceTemplate (
956
    ACPI_PARSE_OBJECT       *Op)
957
{
958
    ACPI_PARSE_OBJECT       *BufferLengthOp;
959
    ACPI_PARSE_OBJECT       *BufferOp;
960
    ACPI_PARSE_OBJECT       *DescriptorTypeOp;
961
    ACPI_PARSE_OBJECT       *LastOp = NULL;
962
    UINT32                  CurrentByteOffset = 0;
963
    ASL_RESOURCE_NODE       HeadRnode;
964
    ASL_RESOURCE_NODE       *PreviousRnode;
965
    ASL_RESOURCE_NODE       *Rnode;
966
    UINT8                   State;
967
968
 
969
 
970
971
 
972
    {
973
        Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
974
    }
975
976
 
977
    /* Buffer Length node is first child */
978
979
 
980
981
 
982
983
 
984
985
 
986
987
 
988
989
 
990
     * Process all resource descriptors in the list
991
     * Note: It is assumed that the EndTag node has been automatically
992
     * inserted at the end of the template by the parser.
993
     */
994
    State = ACPI_RSTATE_NORMAL;
995
    PreviousRnode = &HeadRnode;
996
    while (DescriptorTypeOp)
997
    {
998
        DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
999
        Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
1000
                    &State);
1001
1002
 
1003
         * Update current byte offset to indicate the number of bytes from the
1004
         * start of the buffer.  Buffer can include multiple descriptors, we
1005
         * must keep track of the offset of not only each descriptor, but each
1006
         * element (field) within each descriptor as well.
1007
         */
1008
        CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
1009
1010
 
1011
1012
 
1013
        DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
1014
    }
1015
1016
 
1017
    {
1018
        if (LastOp)
1019
        {
1020
            LastOp = LastOp->Asl.Parent;
1021
        }
1022
        AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
1023
    }
1024
1025
 
1026
     * Transform the nodes into the following
1027
     *
1028
     * Op           -> AML_BUFFER_OP
1029
     * First Child  -> BufferLength
1030
     * Second Child -> Descriptor Buffer (raw byte data)
1031
     */
1032
    Op->Asl.ParseOpcode               = PARSEOP_BUFFER;
1033
    Op->Asl.AmlOpcode                 = AML_BUFFER_OP;
1034
    Op->Asl.CompileFlags              = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
1035
1036
 
1037
    BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
1038
    (void) OpcSetOptimalIntegerSize (BufferLengthOp);
1039
1040
 
1041
    BufferOp->Asl.AmlOpcode           = AML_RAW_DATA_CHAIN;
1042
    BufferOp->Asl.AmlOpcodeLength     = 0;
1043
    BufferOp->Asl.AmlLength           = CurrentByteOffset;
1044
    BufferOp->Asl.Value.Buffer        = (UINT8 *) HeadRnode.Next;
1045
    BufferOp->Asl.CompileFlags       |= NODE_IS_RESOURCE_DATA;
1046
1047
 
1048
}
1049