1 /******************************************************************************
2  *
3  * Module Name: aslrestype2d - Large DWord address resource descriptors
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, 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    ("aslrestype2d")
157 
158 /*
159  * This module contains the Dword (32-bit) address space descriptors:
160  *
161  * DwordIO
162  * DwordMemory
163  * DwordSpace
164  */
165 
166 /*******************************************************************************
167  *
168  * FUNCTION:    RsDoDwordIoDescriptor
169  *
170  * PARAMETERS:  Info                - Parse Op and resource template offset
171  *
172  * RETURN:      Completed resource node
173  *
174  * DESCRIPTION: Construct a long "DwordIO" descriptor
175  *
176  ******************************************************************************/
177 
178 ASL_RESOURCE_NODE *
RsDoDwordIoDescriptor(ASL_RESOURCE_INFO * Info)179 RsDoDwordIoDescriptor (
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     UINT16                  StringLength = 0;
190     UINT32                  OptionIndex = 0;
191     UINT8                   *OptionalFields;
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_ADDRESS32) + 1 + StringLength);
203 
204     Descriptor = Rnode->Buffer;
205     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
206     Descriptor->Address32.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_ADDRESS32);
213     Descriptor->Address32.ResourceLength = (UINT16)
214         (sizeof (AML_RESOURCE_ADDRESS32) -
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->Address32.Flags, InitializerOp, 0, 1);
226             break;
227 
228         case 1: /* MinType */
229 
230             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0);
231             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
232                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2);
233             break;
234 
235         case 2: /* MaxType */
236 
237             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0);
238             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
239                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3);
240             break;
241 
242         case 3: /* DecodeType */
243 
244             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0);
245             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
246                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1);
247             break;
248 
249         case 4: /* Range Type */
250 
251             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 0, 3);
252             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE,
253                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 0, 2);
254             break;
255 
256         case 5: /* Address Granularity */
257 
258             Descriptor->Address32.Granularity =
259                 (UINT32) InitializerOp->Asl.Value.Integer;
260             RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
261                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity));
262             GranOp = InitializerOp;
263             break;
264 
265         case 6: /* Address Min */
266 
267             Descriptor->Address32.Minimum =
268                 (UINT32) InitializerOp->Asl.Value.Integer;
269             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR,
270                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum));
271             MinOp = InitializerOp;
272             break;
273 
274         case 7: /* Address Max */
275 
276             Descriptor->Address32.Maximum =
277                 (UINT32) InitializerOp->Asl.Value.Integer;
278             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
279                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum));
280             MaxOp = InitializerOp;
281             break;
282 
283         case 8: /* Translation Offset */
284 
285             Descriptor->Address32.TranslationOffset =
286                 (UINT32) InitializerOp->Asl.Value.Integer;
287             RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
288                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset));
289             break;
290 
291         case 9: /* Address Length */
292 
293             Descriptor->Address32.AddressLength =
294                 (UINT32) InitializerOp->Asl.Value.Integer;
295             RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH,
296                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength));
297             LengthOp = InitializerOp;
298             break;
299 
300         case 10: /* ResSourceIndex [Optional Field - BYTE] */
301 
302             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
303             {
304                 /* Found a valid ResourceSourceIndex */
305 
306                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
307                 OptionIndex++;
308                 Descriptor->Address32.ResourceLength++;
309                 ResSourceIndex = TRUE;
310             }
311             break;
312 
313         case 11: /* ResSource [Optional Field - STRING] */
314 
315             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
316                 (InitializerOp->Asl.Value.String))
317             {
318                 if (StringLength)
319                 {
320                     /* Found a valid ResourceSource */
321 
322                     Descriptor->Address32.ResourceLength = (UINT16)
323                         (Descriptor->Address32.ResourceLength + StringLength);
324 
325                     strcpy ((char *)
326                         &OptionalFields[OptionIndex],
327                         InitializerOp->Asl.Value.String);
328 
329                     /* ResourceSourceIndex must also be valid */
330 
331                     if (!ResSourceIndex)
332                     {
333                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
334                             InitializerOp, NULL);
335                     }
336                 }
337             }
338 
339 #if 0
340             /*
341              * Not a valid ResourceSource, ResourceSourceIndex must also
342              * be invalid
343              */
344             else if (ResSourceIndex)
345             {
346                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
347                     InitializerOp, NULL);
348             }
349 #endif
350             break;
351 
352         case 12: /* ResourceTag */
353 
354             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
355             break;
356 
357         case 13: /* Type */
358 
359             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 4, 0);
360             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
361                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 4);
362             break;
363 
364         case 14: /* Translation Type */
365 
366             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 5, 0);
367             RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE,
368                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 5);
369             break;
370 
371         default:
372 
373             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
374             break;
375         }
376 
377         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
378     }
379 
380     /* Validate the Min/Max/Len/Gran values */
381 
382     RsLargeAddressCheck (
383         (UINT64) Descriptor->Address32.Minimum,
384         (UINT64) Descriptor->Address32.Maximum,
385         (UINT64) Descriptor->Address32.AddressLength,
386         (UINT64) Descriptor->Address32.Granularity,
387         Descriptor->Address32.Flags,
388         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
389 
390     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
391         OptionIndex + StringLength;
392     return (Rnode);
393 }
394 
395 
396 /*******************************************************************************
397  *
398  * FUNCTION:    RsDoDwordMemoryDescriptor
399  *
400  * PARAMETERS:  Info                - Parse Op and resource template offset
401  *
402  * RETURN:      Completed resource node
403  *
404  * DESCRIPTION: Construct a long "DwordMemory" descriptor
405  *
406  ******************************************************************************/
407 
408 ASL_RESOURCE_NODE *
RsDoDwordMemoryDescriptor(ASL_RESOURCE_INFO * Info)409 RsDoDwordMemoryDescriptor (
410     ASL_RESOURCE_INFO       *Info)
411 {
412     AML_RESOURCE            *Descriptor;
413     ACPI_PARSE_OBJECT       *InitializerOp;
414     ACPI_PARSE_OBJECT       *MinOp = NULL;
415     ACPI_PARSE_OBJECT       *MaxOp = NULL;
416     ACPI_PARSE_OBJECT       *LengthOp = NULL;
417     ACPI_PARSE_OBJECT       *GranOp = NULL;
418     ASL_RESOURCE_NODE       *Rnode;
419     UINT8                   *OptionalFields;
420     UINT16                  StringLength = 0;
421     UINT32                  OptionIndex = 0;
422     UINT32                  CurrentByteOffset;
423     UINT32                  i;
424     BOOLEAN                 ResSourceIndex = FALSE;
425 
426 
427     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
428     StringLength = RsGetStringDataLength (InitializerOp);
429     CurrentByteOffset = Info->CurrentByteOffset;
430 
431     Rnode = RsAllocateResourceNode (
432                 sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength);
433 
434     Descriptor = Rnode->Buffer;
435     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
436     Descriptor->Address32.ResourceType  = ACPI_ADDRESS_TYPE_MEMORY_RANGE;
437 
438     /*
439      * Initial descriptor length -- may be enlarged if there are
440      * optional fields present
441      */
442     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32);
443     Descriptor->Address32.ResourceLength = (UINT16)
444         (sizeof (AML_RESOURCE_ADDRESS32) -
445          sizeof (AML_RESOURCE_LARGE_HEADER));
446 
447 
448     /* Process all child initialization nodes */
449 
450     for (i = 0; InitializerOp; i++)
451     {
452         switch (i)
453         {
454         case 0: /* Resource Usage */
455 
456             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1);
457             break;
458 
459         case 1: /* DecodeType */
460 
461             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0);
462             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
463                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1);
464             break;
465 
466         case 2: /* MinType */
467 
468             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0);
469             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
470                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2);
471             break;
472 
473         case 3: /* MaxType */
474 
475             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0);
476             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
477                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3);
478             break;
479 
480         case 4: /* Memory Type */
481 
482             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 1, 0);
483             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE,
484                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 1, 2);
485             break;
486 
487         case 5: /* Read/Write Type */
488 
489             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 0, 1);
490             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
491                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 0);
492             break;
493 
494         case 6: /* Address Granularity */
495 
496             Descriptor->Address32.Granularity =
497                 (UINT32) InitializerOp->Asl.Value.Integer;
498             RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
499                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity));
500             GranOp = InitializerOp;
501             break;
502 
503         case 7: /* Min Address */
504 
505             Descriptor->Address32.Minimum =
506                 (UINT32) InitializerOp->Asl.Value.Integer;
507             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR,
508                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum));
509             MinOp = InitializerOp;
510             break;
511 
512         case 8: /* Max Address */
513 
514             Descriptor->Address32.Maximum =
515                 (UINT32) InitializerOp->Asl.Value.Integer;
516             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
517                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum));
518             MaxOp = InitializerOp;
519             break;
520 
521         case 9: /* Translation Offset */
522 
523             Descriptor->Address32.TranslationOffset =
524                 (UINT32) InitializerOp->Asl.Value.Integer;
525             RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
526                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset));
527             break;
528 
529         case 10: /* Address Length */
530 
531             Descriptor->Address32.AddressLength =
532                 (UINT32) InitializerOp->Asl.Value.Integer;
533             RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH,
534                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength));
535             LengthOp = InitializerOp;
536             break;
537 
538         case 11: /* ResSourceIndex [Optional Field - BYTE] */
539 
540             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
541             {
542                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
543                 OptionIndex++;
544                 Descriptor->Address32.ResourceLength++;
545                 ResSourceIndex = TRUE;
546             }
547             break;
548 
549         case 12: /* ResSource [Optional Field - STRING] */
550 
551             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
552                 (InitializerOp->Asl.Value.String))
553             {
554                 if (StringLength)
555                 {
556                     Descriptor->Address32.ResourceLength = (UINT16)
557                         (Descriptor->Address32.ResourceLength + StringLength);
558 
559                     strcpy ((char *)
560                         &OptionalFields[OptionIndex],
561                         InitializerOp->Asl.Value.String);
562 
563                     /* ResourceSourceIndex must also be valid */
564 
565                     if (!ResSourceIndex)
566                     {
567                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
568                             InitializerOp, NULL);
569                     }
570                 }
571             }
572 
573 #if 0
574             /*
575              * Not a valid ResourceSource, ResourceSourceIndex must also
576              * be invalid
577              */
578             else if (ResSourceIndex)
579             {
580                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
581                     InitializerOp, NULL);
582             }
583 #endif
584             break;
585 
586         case 13: /* ResourceTag */
587 
588             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
589             break;
590 
591 
592         case 14: /* Address Range */
593 
594             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 3, 0);
595             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES,
596                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 3, 2);
597             break;
598 
599         case 15: /* Type */
600 
601             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 5, 0);
602             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
603                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 5);
604             break;
605 
606         default:
607 
608             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
609             break;
610         }
611 
612         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
613     }
614 
615     /* Validate the Min/Max/Len/Gran values */
616 
617     RsLargeAddressCheck (
618         (UINT64) Descriptor->Address32.Minimum,
619         (UINT64) Descriptor->Address32.Maximum,
620         (UINT64) Descriptor->Address32.AddressLength,
621         (UINT64) Descriptor->Address32.Granularity,
622         Descriptor->Address32.Flags,
623         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
624 
625     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
626         OptionIndex + StringLength;
627     return (Rnode);
628 }
629 
630 
631 /*******************************************************************************
632  *
633  * FUNCTION:    RsDoDwordSpaceDescriptor
634  *
635  * PARAMETERS:  Info                - Parse Op and resource template offset
636  *
637  * RETURN:      Completed resource node
638  *
639  * DESCRIPTION: Construct a long "DwordSpace" descriptor
640  *
641  ******************************************************************************/
642 
643 ASL_RESOURCE_NODE *
RsDoDwordSpaceDescriptor(ASL_RESOURCE_INFO * Info)644 RsDoDwordSpaceDescriptor (
645     ASL_RESOURCE_INFO       *Info)
646 {
647     AML_RESOURCE            *Descriptor;
648     ACPI_PARSE_OBJECT       *InitializerOp;
649     ACPI_PARSE_OBJECT       *MinOp = NULL;
650     ACPI_PARSE_OBJECT       *MaxOp = NULL;
651     ACPI_PARSE_OBJECT       *LengthOp = NULL;
652     ACPI_PARSE_OBJECT       *GranOp = NULL;
653     ASL_RESOURCE_NODE       *Rnode;
654     UINT8                   *OptionalFields;
655     UINT16                  StringLength = 0;
656     UINT32                  OptionIndex = 0;
657     UINT32                  CurrentByteOffset;
658     UINT32                  i;
659     BOOLEAN                 ResSourceIndex = FALSE;
660 
661 
662     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
663     StringLength = RsGetStringDataLength (InitializerOp);
664     CurrentByteOffset = Info->CurrentByteOffset;
665 
666     Rnode = RsAllocateResourceNode (
667         sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength);
668 
669     Descriptor = Rnode->Buffer;
670     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
671 
672     /*
673      * Initial descriptor length -- may be enlarged if there are
674      * optional fields present
675      */
676     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32);
677     Descriptor->Address32.ResourceLength = (UINT16)
678         (sizeof (AML_RESOURCE_ADDRESS32) -
679          sizeof (AML_RESOURCE_LARGE_HEADER));
680 
681     /* Process all child initialization nodes */
682 
683     for (i = 0; InitializerOp; i++)
684     {
685         switch (i)
686         {
687         case 0: /* Resource Type */
688 
689             Descriptor->Address32.ResourceType =
690                 (UINT8) InitializerOp->Asl.Value.Integer;
691             break;
692 
693         case 1: /* Resource Usage */
694 
695             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1);
696             break;
697 
698         case 2: /* DecodeType */
699 
700             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0);
701             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
702                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1);
703             break;
704 
705         case 3: /* MinType */
706 
707             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0);
708             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
709                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2);
710             break;
711 
712         case 4: /* MaxType */
713 
714             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0);
715             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
716                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3);
717             break;
718 
719         case 5: /* Type-Specific flags */
720 
721             Descriptor->Address32.SpecificFlags =
722                 (UINT8) InitializerOp->Asl.Value.Integer;
723             break;
724 
725         case 6: /* Address Granularity */
726 
727             Descriptor->Address32.Granularity =
728                 (UINT32) InitializerOp->Asl.Value.Integer;
729             RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
730                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity));
731             GranOp = InitializerOp;
732             break;
733 
734         case 7: /* Min Address */
735 
736             Descriptor->Address32.Minimum =
737                 (UINT32) InitializerOp->Asl.Value.Integer;
738             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR,
739                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum));
740             MinOp = InitializerOp;
741             break;
742 
743         case 8: /* Max Address */
744 
745             Descriptor->Address32.Maximum =
746                 (UINT32) InitializerOp->Asl.Value.Integer;
747             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
748                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum));
749             MaxOp = InitializerOp;
750             break;
751 
752         case 9: /* Translation Offset */
753 
754             Descriptor->Address32.TranslationOffset =
755                 (UINT32) InitializerOp->Asl.Value.Integer;
756             RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
757                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset));
758             break;
759 
760         case 10: /* Address Length */
761 
762             Descriptor->Address32.AddressLength =
763                 (UINT32) InitializerOp->Asl.Value.Integer;
764             RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH,
765                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength));
766             LengthOp = InitializerOp;
767             break;
768 
769         case 11: /* ResSourceIndex [Optional Field - BYTE] */
770 
771             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
772             {
773                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
774                 OptionIndex++;
775                 Descriptor->Address32.ResourceLength++;
776                 ResSourceIndex = TRUE;
777             }
778             break;
779 
780         case 12: /* ResSource [Optional Field - STRING] */
781 
782             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
783                 (InitializerOp->Asl.Value.String))
784             {
785                 if (StringLength)
786                 {
787                     Descriptor->Address32.ResourceLength = (UINT16)
788                         (Descriptor->Address32.ResourceLength + StringLength);
789 
790                     strcpy ((char *)
791                         &OptionalFields[OptionIndex],
792                         InitializerOp->Asl.Value.String);
793 
794                     /* ResourceSourceIndex must also be valid */
795 
796                     if (!ResSourceIndex)
797                     {
798                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
799                             InitializerOp, NULL);
800                     }
801                 }
802             }
803 
804 #if 0
805             /*
806              * Not a valid ResourceSource, ResourceSourceIndex must also
807              * be invalid
808              */
809             else if (ResSourceIndex)
810             {
811                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
812                     InitializerOp, NULL);
813             }
814 #endif
815             break;
816 
817         case 13: /* ResourceTag */
818 
819             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
820             break;
821 
822         default:
823 
824             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST,
825                 InitializerOp, NULL);
826             break;
827         }
828 
829         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
830     }
831 
832     /* Validate the Min/Max/Len/Gran values */
833 
834     RsLargeAddressCheck (
835         (UINT64) Descriptor->Address32.Minimum,
836         (UINT64) Descriptor->Address32.Maximum,
837         (UINT64) Descriptor->Address32.AddressLength,
838         (UINT64) Descriptor->Address32.Granularity,
839         Descriptor->Address32.Flags,
840         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
841 
842     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
843         OptionIndex + StringLength;
844     return (Rnode);
845 }
846