1 /******************************************************************************
2  *
3  * Module Name: aslrestype2q - Large QWord address resource descriptors
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2021, 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  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
154 
155 #define _COMPONENT          ACPI_COMPILER
156         ACPI_MODULE_NAME    ("aslrestype2q")
157 
158 /*
159  * This module contains the QWord (64-bit) address space descriptors:
160  *
161  * QWordIO
162  * QWordMemory
163  * QWordSpace
164  */
165 
166 /*******************************************************************************
167  *
168  * FUNCTION:    RsDoQwordIoDescriptor
169  *
170  * PARAMETERS:  Info                - Parse Op and resource template offset
171  *
172  * RETURN:      Completed resource node
173  *
174  * DESCRIPTION: Construct a long "QwordIO" descriptor
175  *
176  ******************************************************************************/
177 
178 ASL_RESOURCE_NODE *
179 RsDoQwordIoDescriptor (
180     ASL_RESOURCE_INFO       *Info)
181 {
182     AML_RESOURCE            *Descriptor;
183     ACPI_PARSE_OBJECT       *InitializerOp;
184     ACPI_PARSE_OBJECT       *MinOp = NULL;
185     ACPI_PARSE_OBJECT       *MaxOp = NULL;
186     ACPI_PARSE_OBJECT       *LengthOp = NULL;
187     ACPI_PARSE_OBJECT       *GranOp = NULL;
188     ASL_RESOURCE_NODE       *Rnode;
189     UINT8                   *OptionalFields;
190     UINT16                  StringLength = 0;
191     UINT32                  OptionIndex = 0;
192     UINT32                  CurrentByteOffset;
193     UINT32                  i;
194     BOOLEAN                 ResSourceIndex = FALSE;
195 
196 
197     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
198     StringLength = RsGetStringDataLength (InitializerOp);
199     CurrentByteOffset = Info->CurrentByteOffset;
200 
201     Rnode = RsAllocateResourceNode (
202         sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength);
203 
204     Descriptor = Rnode->Buffer;
205     Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64;
206     Descriptor->Address64.ResourceType = ACPI_ADDRESS_TYPE_IO_RANGE;
207 
208     /*
209      * Initial descriptor length -- may be enlarged if there are
210      * optional fields present
211      */
212     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64);
213     Descriptor->Address64.ResourceLength = (UINT16)
214         (sizeof (AML_RESOURCE_ADDRESS64) -
215          sizeof (AML_RESOURCE_LARGE_HEADER));
216 
217     /* Process all child initialization nodes */
218 
219     for (i = 0; InitializerOp; i++)
220     {
221         switch (i)
222         {
223         case 0: /* Resource Usage */
224 
225             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1);
226             break;
227 
228         case 1: /* MinType */
229 
230             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0);
231             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
232                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2);
233             break;
234 
235         case 2: /* MaxType */
236 
237             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0);
238             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
239                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3);
240             break;
241 
242         case 3: /* DecodeType */
243 
244             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0);
245             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
246                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1);
247             break;
248 
249         case 4: /* Range Type */
250 
251             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 0, 3);
252             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE,
253                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 0, 2);
254             break;
255 
256         case 5: /* Address Granularity */
257 
258             Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer;
259             RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
260                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity));
261             GranOp = InitializerOp;
262             break;
263 
264         case 6: /* Address Min */
265 
266             Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer;
267             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR,
268                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum));
269             MinOp = InitializerOp;
270             break;
271 
272         case 7: /* Address Max */
273 
274             Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer;
275             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
276                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum));
277             MaxOp = InitializerOp;
278             break;
279 
280         case 8: /* Translation Offset */
281 
282             Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer;
283             RsCreateByteField (InitializerOp, ACPI_RESTAG_TRANSLATION,
284                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset));
285             break;
286 
287         case 9: /* Address Length */
288 
289             Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer;
290             RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH,
291                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength));
292             LengthOp = InitializerOp;
293             break;
294 
295         case 10: /* ResSourceIndex [Optional Field - BYTE] */
296 
297             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
298             {
299                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
300                 OptionIndex++;
301                 Descriptor->Address64.ResourceLength++;
302                 ResSourceIndex = TRUE;
303             }
304             break;
305 
306         case 11: /* ResSource [Optional Field - STRING] */
307 
308             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
309                 (InitializerOp->Asl.Value.String))
310             {
311                 if (StringLength)
312                 {
313                     Descriptor->Address64.ResourceLength = (UINT16)
314                         (Descriptor->Address64.ResourceLength + StringLength);
315 
316                     strcpy ((char *)
317                         &OptionalFields[OptionIndex],
318                         InitializerOp->Asl.Value.String);
319 
320                     /* ResourceSourceIndex must also be valid */
321 
322                     if (!ResSourceIndex)
323                     {
324                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
325                             InitializerOp, NULL);
326                     }
327                 }
328             }
329 
330 #if 0
331             /*
332              * Not a valid ResourceSource, ResourceSourceIndex must also
333              * be invalid
334              */
335             else if (ResSourceIndex)
336             {
337                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
338                     InitializerOp, NULL);
339             }
340 #endif
341             break;
342 
343         case 12: /* ResourceTag */
344 
345             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
346             break;
347 
348         case 13: /* Type */
349 
350             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 4, 0);
351             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
352                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 4);
353             break;
354 
355         case 14: /* Translation Type */
356 
357             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 5, 0);
358             RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE,
359                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 5);
360             break;
361 
362         default:
363 
364             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
365             break;
366         }
367 
368         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
369     }
370 
371     /* Validate the Min/Max/Len/Gran values */
372 
373     RsLargeAddressCheck (
374         Descriptor->Address64.Minimum,
375         Descriptor->Address64.Maximum,
376         Descriptor->Address64.AddressLength,
377         Descriptor->Address64.Granularity,
378         Descriptor->Address64.Flags,
379         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
380 
381     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) +
382         OptionIndex + StringLength;
383     return (Rnode);
384 }
385 
386 
387 /*******************************************************************************
388  *
389  * FUNCTION:    RsDoQwordMemoryDescriptor
390  *
391  * PARAMETERS:  Info                - Parse Op and resource template offset
392  *
393  * RETURN:      Completed resource node
394  *
395  * DESCRIPTION: Construct a long "QwordMemory" descriptor
396  *
397  ******************************************************************************/
398 
399 ASL_RESOURCE_NODE *
400 RsDoQwordMemoryDescriptor (
401     ASL_RESOURCE_INFO       *Info)
402 {
403     AML_RESOURCE            *Descriptor;
404     ACPI_PARSE_OBJECT       *InitializerOp;
405     ACPI_PARSE_OBJECT       *MinOp = NULL;
406     ACPI_PARSE_OBJECT       *MaxOp = NULL;
407     ACPI_PARSE_OBJECT       *LengthOp = NULL;
408     ACPI_PARSE_OBJECT       *GranOp = NULL;
409     ASL_RESOURCE_NODE       *Rnode;
410     UINT8                   *OptionalFields;
411     UINT16                  StringLength = 0;
412     UINT32                  OptionIndex = 0;
413     UINT32                  CurrentByteOffset;
414     UINT32                  i;
415     BOOLEAN                 ResSourceIndex = FALSE;
416 
417 
418     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
419     StringLength = RsGetStringDataLength (InitializerOp);
420     CurrentByteOffset = Info->CurrentByteOffset;
421 
422     Rnode = RsAllocateResourceNode (
423         sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength);
424 
425     Descriptor = Rnode->Buffer;
426     Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64;
427     Descriptor->Address64.ResourceType = ACPI_ADDRESS_TYPE_MEMORY_RANGE;
428 
429     /*
430      * Initial descriptor length -- may be enlarged if there are
431      * optional fields present
432      */
433     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64);
434     Descriptor->Address64.ResourceLength = (UINT16)
435         (sizeof (AML_RESOURCE_ADDRESS64) -
436          sizeof (AML_RESOURCE_LARGE_HEADER));
437 
438     /* Process all child initialization nodes */
439 
440     for (i = 0; InitializerOp; i++)
441     {
442         switch (i)
443         {
444         case 0: /* Resource Usage */
445 
446             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1);
447             break;
448 
449         case 1: /* DecodeType */
450 
451             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0);
452             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
453                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1);
454             break;
455 
456         case 2: /* MinType */
457 
458             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0);
459             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
460                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2);
461             break;
462 
463         case 3: /* MaxType */
464 
465             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0);
466             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
467                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3);
468             break;
469 
470         case 4: /* Memory Type */
471 
472             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 1, 0);
473             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE,
474                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 1, 2);
475             break;
476 
477         case 5: /* Read/Write Type */
478 
479             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 0, 1);
480             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
481                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 0);
482             break;
483 
484         case 6: /* Address Granularity */
485 
486             Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer;
487             RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
488                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity));
489             GranOp = InitializerOp;
490             break;
491 
492         case 7: /* Min Address */
493 
494             Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer;
495             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR,
496                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum));
497             MinOp = InitializerOp;
498             break;
499 
500         case 8: /* Max Address */
501 
502             Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer;
503             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
504                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum));
505             MaxOp = InitializerOp;
506             break;
507 
508         case 9: /* Translation Offset */
509 
510             Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer;
511             RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
512                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset));
513             break;
514 
515         case 10: /* Address Length */
516 
517             Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer;
518             RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH,
519                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength));
520             LengthOp = InitializerOp;
521             break;
522 
523         case 11: /* ResSourceIndex [Optional Field - BYTE] */
524 
525             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
526             {
527                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
528                 OptionIndex++;
529                 Descriptor->Address64.ResourceLength++;
530                 ResSourceIndex = TRUE;
531             }
532             break;
533 
534         case 12: /* ResSource [Optional Field - STRING] */
535 
536             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
537                 (InitializerOp->Asl.Value.String))
538             {
539                 if (StringLength)
540                 {
541                     Descriptor->Address64.ResourceLength = (UINT16)
542                         (Descriptor->Address64.ResourceLength + StringLength);
543 
544                     strcpy ((char *)
545                         &OptionalFields[OptionIndex],
546                         InitializerOp->Asl.Value.String);
547 
548                     /* ResourceSourceIndex must also be valid */
549 
550                     if (!ResSourceIndex)
551                     {
552                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
553                             InitializerOp, NULL);
554                     }
555                 }
556             }
557 
558 #if 0
559             /*
560              * Not a valid ResourceSource, ResourceSourceIndex must also
561              * be invalid
562              */
563             else if (ResSourceIndex)
564             {
565                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
566                     InitializerOp, NULL);
567             }
568 #endif
569             break;
570 
571         case 13: /* ResourceTag */
572 
573             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
574             break;
575 
576 
577         case 14: /* Address Range */
578 
579             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 3, 0);
580             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES,
581                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 3, 2);
582             break;
583 
584         case 15: /* Type */
585 
586             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 5, 0);
587             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
588                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 5);
589             break;
590 
591         default:
592 
593             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
594             break;
595         }
596 
597         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
598     }
599 
600     /* Validate the Min/Max/Len/Gran values */
601 
602     RsLargeAddressCheck (
603         Descriptor->Address64.Minimum,
604         Descriptor->Address64.Maximum,
605         Descriptor->Address64.AddressLength,
606         Descriptor->Address64.Granularity,
607         Descriptor->Address64.Flags,
608         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
609 
610     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) +
611         OptionIndex + StringLength;
612     return (Rnode);
613 }
614 
615 
616 /*******************************************************************************
617  *
618  * FUNCTION:    RsDoQwordSpaceDescriptor
619  *
620  * PARAMETERS:  Info                - Parse Op and resource template offset
621  *
622  * RETURN:      Completed resource node
623  *
624  * DESCRIPTION: Construct a long "QwordSpace" descriptor
625  *
626  ******************************************************************************/
627 
628 ASL_RESOURCE_NODE *
629 RsDoQwordSpaceDescriptor (
630     ASL_RESOURCE_INFO       *Info)
631 {
632     AML_RESOURCE            *Descriptor;
633     ACPI_PARSE_OBJECT       *InitializerOp;
634     ACPI_PARSE_OBJECT       *MinOp = NULL;
635     ACPI_PARSE_OBJECT       *MaxOp = NULL;
636     ACPI_PARSE_OBJECT       *LengthOp = NULL;
637     ACPI_PARSE_OBJECT       *GranOp = NULL;
638     ASL_RESOURCE_NODE       *Rnode;
639     UINT8                   *OptionalFields;
640     UINT16                  StringLength = 0;
641     UINT32                  OptionIndex = 0;
642     UINT32                  CurrentByteOffset;
643     UINT32                  i;
644     BOOLEAN                 ResSourceIndex = FALSE;
645 
646 
647     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
648     StringLength = RsGetStringDataLength (InitializerOp);
649     CurrentByteOffset = Info->CurrentByteOffset;
650 
651     Rnode = RsAllocateResourceNode (
652         sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength);
653 
654     Descriptor = Rnode->Buffer;
655     Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64;
656 
657     /*
658      * Initial descriptor length -- may be enlarged if there are
659      * optional fields present
660      */
661     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64);
662     Descriptor->Address64.ResourceLength = (UINT16)
663         (sizeof (AML_RESOURCE_ADDRESS64) -
664          sizeof (AML_RESOURCE_LARGE_HEADER));
665 
666     /* Process all child initialization nodes */
667 
668     for (i = 0; InitializerOp; i++)
669     {
670         switch (i)
671         {
672         case 0: /* Resource Type */
673 
674             Descriptor->Address64.ResourceType =
675                 (UINT8) InitializerOp->Asl.Value.Integer;
676             break;
677 
678         case 1: /* Resource Usage */
679 
680             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1);
681             break;
682 
683         case 2: /* DecodeType */
684 
685             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0);
686             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
687                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1);
688             break;
689 
690         case 3: /* MinType */
691 
692             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0);
693             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
694                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2);
695             break;
696 
697         case 4: /* MaxType */
698 
699             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0);
700             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
701                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3);
702             break;
703 
704         case 5: /* Type-Specific flags */
705 
706             Descriptor->Address64.SpecificFlags =
707                 (UINT8) InitializerOp->Asl.Value.Integer;
708             break;
709 
710         case 6: /* Address Granularity */
711 
712             Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer;
713             RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
714                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity));
715             GranOp = InitializerOp;
716             break;
717 
718         case 7: /* Min Address */
719 
720             Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer;
721             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR,
722                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum));
723             MinOp = InitializerOp;
724             break;
725 
726         case 8: /* Max Address */
727 
728             Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer;
729             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
730                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum));
731             MaxOp = InitializerOp;
732             break;
733 
734         case 9: /* Translation Offset */
735 
736             Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer;
737             RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
738                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset));
739             break;
740 
741         case 10: /* Address Length */
742 
743             Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer;
744             RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH,
745                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength));
746             LengthOp = InitializerOp;
747             break;
748 
749         case 11: /* ResSourceIndex [Optional Field - BYTE] */
750 
751             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
752             {
753                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
754                 OptionIndex++;
755                 Descriptor->Address64.ResourceLength++;
756                 ResSourceIndex = TRUE;
757             }
758             break;
759 
760         case 12: /* ResSource [Optional Field - STRING] */
761 
762             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
763                 (InitializerOp->Asl.Value.String))
764             {
765                 if (StringLength)
766                 {
767                     Descriptor->Address64.ResourceLength = (UINT16)
768                         (Descriptor->Address64.ResourceLength + StringLength);
769 
770                     strcpy ((char *)
771                         &OptionalFields[OptionIndex],
772                         InitializerOp->Asl.Value.String);
773 
774                     /* ResourceSourceIndex must also be valid */
775 
776                     if (!ResSourceIndex)
777                     {
778                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
779                             InitializerOp, NULL);
780                     }
781                 }
782             }
783 
784 #if 0
785             /*
786              * Not a valid ResourceSource, ResourceSourceIndex must also
787              * be invalid
788              */
789             else if (ResSourceIndex)
790             {
791                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
792                     InitializerOp, NULL);
793             }
794 #endif
795             break;
796 
797         case 13: /* ResourceTag */
798 
799             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
800             break;
801 
802         default:
803 
804             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
805             break;
806         }
807 
808         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
809     }
810 
811     /* Validate the Min/Max/Len/Gran values */
812 
813     RsLargeAddressCheck (
814         Descriptor->Address64.Minimum,
815         Descriptor->Address64.Maximum,
816         Descriptor->Address64.AddressLength,
817         Descriptor->Address64.Granularity,
818         Descriptor->Address64.Flags,
819         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
820 
821     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) +
822         OptionIndex + StringLength;
823     return (Rnode);
824 }
825