xref: /freebsd/sys/contrib/dev/acpica/compiler/aslrestype2q.c (revision 92f570c32e9b9b9b4db9b6921c4ab79be686a498)
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 - 2024, 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 <contrib/dev/acpica/compiler/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  * QwordPcc
164  * QWordSpace
165  */
166 
167 /*******************************************************************************
168  *
169  * FUNCTION:    RsDoQwordIoDescriptor
170  *
171  * PARAMETERS:  Info                - Parse Op and resource template offset
172  *
173  * RETURN:      Completed resource node
174  *
175  * DESCRIPTION: Construct a long "QwordIO" descriptor
176  *
177  ******************************************************************************/
178 
179 ASL_RESOURCE_NODE *
RsDoQwordIoDescriptor(ASL_RESOURCE_INFO * Info)180 RsDoQwordIoDescriptor (
181     ASL_RESOURCE_INFO       *Info)
182 {
183     AML_RESOURCE            *Descriptor;
184     ACPI_PARSE_OBJECT       *InitializerOp;
185     ACPI_PARSE_OBJECT       *MinOp = NULL;
186     ACPI_PARSE_OBJECT       *MaxOp = NULL;
187     ACPI_PARSE_OBJECT       *LengthOp = NULL;
188     ACPI_PARSE_OBJECT       *GranOp = NULL;
189     ASL_RESOURCE_NODE       *Rnode;
190     UINT8                   *OptionalFields;
191     UINT16                  StringLength = 0;
192     UINT32                  OptionIndex = 0;
193     UINT32                  CurrentByteOffset;
194     UINT32                  i;
195     BOOLEAN                 ResSourceIndex = FALSE;
196 
197 
198     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
199     StringLength = RsGetStringDataLength (InitializerOp);
200     CurrentByteOffset = Info->CurrentByteOffset;
201 
202     Rnode = RsAllocateResourceNode (
203         sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength);
204 
205     Descriptor = Rnode->Buffer;
206     Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64;
207     Descriptor->Address64.ResourceType = ACPI_ADDRESS_TYPE_IO_RANGE;
208 
209     /*
210      * Initial descriptor length -- may be enlarged if there are
211      * optional fields present
212      */
213     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64);
214     Descriptor->Address64.ResourceLength = (UINT16)
215         (sizeof (AML_RESOURCE_ADDRESS64) -
216          sizeof (AML_RESOURCE_LARGE_HEADER));
217 
218     /* Process all child initialization nodes */
219 
220     for (i = 0; InitializerOp; i++)
221     {
222         switch (i)
223         {
224         case 0: /* Resource Usage */
225 
226             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1);
227             break;
228 
229         case 1: /* MinType */
230 
231             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0);
232             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
233                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2);
234             break;
235 
236         case 2: /* MaxType */
237 
238             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0);
239             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
240                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3);
241             break;
242 
243         case 3: /* DecodeType */
244 
245             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0);
246             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
247                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1);
248             break;
249 
250         case 4: /* Range Type */
251 
252             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 0, 3);
253             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE,
254                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 0, 2);
255             break;
256 
257         case 5: /* Address Granularity */
258 
259             Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer;
260             RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
261                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity));
262             GranOp = InitializerOp;
263             break;
264 
265         case 6: /* Address Min */
266 
267             Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer;
268             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR,
269                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum));
270             MinOp = InitializerOp;
271             break;
272 
273         case 7: /* Address Max */
274 
275             Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer;
276             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
277                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum));
278             MaxOp = InitializerOp;
279             break;
280 
281         case 8: /* Translation Offset */
282 
283             Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer;
284             RsCreateByteField (InitializerOp, ACPI_RESTAG_TRANSLATION,
285                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset));
286             break;
287 
288         case 9: /* Address Length */
289 
290             Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer;
291             RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH,
292                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength));
293             LengthOp = InitializerOp;
294             break;
295 
296         case 10: /* ResSourceIndex [Optional Field - BYTE] */
297 
298             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
299             {
300                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
301                 OptionIndex++;
302                 Descriptor->Address64.ResourceLength++;
303                 ResSourceIndex = TRUE;
304             }
305             break;
306 
307         case 11: /* ResSource [Optional Field - STRING] */
308 
309             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
310                 (InitializerOp->Asl.Value.String))
311             {
312                 if (StringLength)
313                 {
314                     Descriptor->Address64.ResourceLength = (UINT16)
315                         (Descriptor->Address64.ResourceLength + StringLength);
316 
317                     strcpy ((char *)
318                         &OptionalFields[OptionIndex],
319                         InitializerOp->Asl.Value.String);
320 
321                     /* ResourceSourceIndex must also be valid */
322 
323                     if (!ResSourceIndex)
324                     {
325                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
326                             InitializerOp, NULL);
327                     }
328                 }
329             }
330 
331 #if 0
332             /*
333              * Not a valid ResourceSource, ResourceSourceIndex must also
334              * be invalid
335              */
336             else if (ResSourceIndex)
337             {
338                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
339                     InitializerOp, NULL);
340             }
341 #endif
342             break;
343 
344         case 12: /* ResourceTag */
345 
346             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
347             break;
348 
349         case 13: /* Type */
350 
351             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 4, 0);
352             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
353                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 4);
354             break;
355 
356         case 14: /* Translation Type */
357 
358             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 5, 0);
359             RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE,
360                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 5);
361             break;
362 
363         default:
364 
365             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
366             break;
367         }
368 
369         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
370     }
371 
372     /* Validate the Min/Max/Len/Gran values */
373 
374     RsLargeAddressCheck (
375         Descriptor->Address64.Minimum,
376         Descriptor->Address64.Maximum,
377         Descriptor->Address64.AddressLength,
378         Descriptor->Address64.Granularity,
379         Descriptor->Address64.Flags,
380         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
381 
382     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) +
383         OptionIndex + StringLength;
384     return (Rnode);
385 }
386 
387 
388 /*******************************************************************************
389  *
390  * FUNCTION:    RsDoQwordMemoryDescriptor
391  *
392  * PARAMETERS:  Info                - Parse Op and resource template offset
393  *
394  * RETURN:      Completed resource node
395  *
396  * DESCRIPTION: Construct a long "QwordMemory" descriptor
397  *
398  ******************************************************************************/
399 
400 ASL_RESOURCE_NODE *
RsDoQwordMemoryDescriptor(ASL_RESOURCE_INFO * Info)401 RsDoQwordMemoryDescriptor (
402     ASL_RESOURCE_INFO       *Info)
403 {
404     AML_RESOURCE            *Descriptor;
405     ACPI_PARSE_OBJECT       *InitializerOp;
406     ACPI_PARSE_OBJECT       *MinOp = NULL;
407     ACPI_PARSE_OBJECT       *MaxOp = NULL;
408     ACPI_PARSE_OBJECT       *LengthOp = NULL;
409     ACPI_PARSE_OBJECT       *GranOp = NULL;
410     ASL_RESOURCE_NODE       *Rnode;
411     UINT8                   *OptionalFields;
412     UINT16                  StringLength = 0;
413     UINT32                  OptionIndex = 0;
414     UINT32                  CurrentByteOffset;
415     UINT32                  i;
416     BOOLEAN                 ResSourceIndex = FALSE;
417 
418 
419     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
420     StringLength = RsGetStringDataLength (InitializerOp);
421     CurrentByteOffset = Info->CurrentByteOffset;
422 
423     Rnode = RsAllocateResourceNode (
424         sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength);
425 
426     Descriptor = Rnode->Buffer;
427     Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64;
428     Descriptor->Address64.ResourceType = ACPI_ADDRESS_TYPE_MEMORY_RANGE;
429 
430     /*
431      * Initial descriptor length -- may be enlarged if there are
432      * optional fields present
433      */
434     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64);
435     Descriptor->Address64.ResourceLength = (UINT16)
436         (sizeof (AML_RESOURCE_ADDRESS64) -
437          sizeof (AML_RESOURCE_LARGE_HEADER));
438 
439     /* Process all child initialization nodes */
440 
441     for (i = 0; InitializerOp; i++)
442     {
443         switch (i)
444         {
445         case 0: /* Resource Usage */
446 
447             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1);
448             break;
449 
450         case 1: /* DecodeType */
451 
452             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0);
453             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
454                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1);
455             break;
456 
457         case 2: /* MinType */
458 
459             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0);
460             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
461                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2);
462             break;
463 
464         case 3: /* MaxType */
465 
466             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0);
467             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
468                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3);
469             break;
470 
471         case 4: /* Memory Type */
472 
473             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 1, 0);
474             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE,
475                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 1, 2);
476             break;
477 
478         case 5: /* Read/Write Type */
479 
480             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 0, 1);
481             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
482                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 0);
483             break;
484 
485         case 6: /* Address Granularity */
486 
487             Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer;
488             RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
489                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity));
490             GranOp = InitializerOp;
491             break;
492 
493         case 7: /* Min Address */
494 
495             Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer;
496             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR,
497                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum));
498             MinOp = InitializerOp;
499             break;
500 
501         case 8: /* Max Address */
502 
503             Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer;
504             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
505                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum));
506             MaxOp = InitializerOp;
507             break;
508 
509         case 9: /* Translation Offset */
510 
511             Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer;
512             RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
513                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset));
514             break;
515 
516         case 10: /* Address Length */
517 
518             Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer;
519             RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH,
520                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength));
521             LengthOp = InitializerOp;
522             break;
523 
524         case 11: /* ResSourceIndex [Optional Field - BYTE] */
525 
526             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
527             {
528                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
529                 OptionIndex++;
530                 Descriptor->Address64.ResourceLength++;
531                 ResSourceIndex = TRUE;
532             }
533             break;
534 
535         case 12: /* ResSource [Optional Field - STRING] */
536 
537             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
538                 (InitializerOp->Asl.Value.String))
539             {
540                 if (StringLength)
541                 {
542                     Descriptor->Address64.ResourceLength = (UINT16)
543                         (Descriptor->Address64.ResourceLength + StringLength);
544 
545                     strcpy ((char *)
546                         &OptionalFields[OptionIndex],
547                         InitializerOp->Asl.Value.String);
548 
549                     /* ResourceSourceIndex must also be valid */
550 
551                     if (!ResSourceIndex)
552                     {
553                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
554                             InitializerOp, NULL);
555                     }
556                 }
557             }
558 
559 #if 0
560             /*
561              * Not a valid ResourceSource, ResourceSourceIndex must also
562              * be invalid
563              */
564             else if (ResSourceIndex)
565             {
566                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
567                     InitializerOp, NULL);
568             }
569 #endif
570             break;
571 
572         case 13: /* ResourceTag */
573 
574             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
575             break;
576 
577 
578         case 14: /* Address Range */
579 
580             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 3, 0);
581             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES,
582                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 3, 2);
583             break;
584 
585         case 15: /* Type */
586 
587             RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 5, 0);
588             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
589                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 5);
590             break;
591 
592         default:
593 
594             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
595             break;
596         }
597 
598         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
599     }
600 
601     /* Validate the Min/Max/Len/Gran values */
602 
603     RsLargeAddressCheck (
604         Descriptor->Address64.Minimum,
605         Descriptor->Address64.Maximum,
606         Descriptor->Address64.AddressLength,
607         Descriptor->Address64.Granularity,
608         Descriptor->Address64.Flags,
609         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
610 
611     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) +
612         OptionIndex + StringLength;
613     return (Rnode);
614 }
615 
616 
617 /*******************************************************************************
618  *
619  * FUNCTION:    RsDoQwordPccDescriptor
620  *
621  * PARAMETERS:  Info                - Parse Op and resource template offset
622  *
623  * RETURN:      Completed resource node
624  *
625  * DESCRIPTION: Construct a long "QWordPcc" descriptor
626  *
627  ******************************************************************************/
628 
629 ASL_RESOURCE_NODE *
RsDoQwordPccDescriptor(ASL_RESOURCE_INFO * Info)630 RsDoQwordPccDescriptor (
631     ASL_RESOURCE_INFO       *Info)
632 {
633     AML_RESOURCE            *Descriptor;
634     ACPI_PARSE_OBJECT       *InitializerOp;
635     ACPI_PARSE_OBJECT       *MinOp = NULL;
636     ACPI_PARSE_OBJECT       *MaxOp = NULL;
637     ACPI_PARSE_OBJECT       *LengthOp = NULL;
638     ACPI_PARSE_OBJECT       *GranOp = NULL;
639     ASL_RESOURCE_NODE       *Rnode;
640     UINT16                  StringLength = 0;
641     UINT32                  OptionIndex = 0;
642     UINT8                   *OptionalFields;
643     UINT32                  i;
644     BOOLEAN                 ResSourceIndex = FALSE;
645 
646 
647     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
648     StringLength = RsGetStringDataLength (InitializerOp);
649 
650     Rnode = RsAllocateResourceNode (
651         sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength);
652 
653     Descriptor = Rnode->Buffer;
654     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
655     Descriptor->Address32.ResourceType  = ACPI_ADDRESS_TYPE_PCC_NUMBER;
656 
657     /*
658      * Initial descriptor length -- may be enlarged if there are
659      * optional fields present
660      */
661     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32);
662     Descriptor->Address32.ResourceLength = (UINT16)
663         (sizeof (AML_RESOURCE_ADDRESS32) -
664          sizeof (AML_RESOURCE_LARGE_HEADER));
665 
666 
667     /*
668     * Bit [3] Max Address Fixed, _MAF: 1 (max address is fixed)
669     * Bit [2] Min Address Fixed,_MIF: 1 (min address is fixed)
670     * Bit [1] Decode Type, _DEC: 0 (do not care)
671     * BIT [0] Ignored (must be zero)
672     */
673     Descriptor->Address32.Flags = 0b1100;
674 
675     // No type specific flags. Set to 0.
676     Descriptor->Address32.SpecificFlags = 0;
677 
678     // must be set to zero if _MAX == _MIN.
679     Descriptor->Address32.Granularity = 0x0;
680     /* Process all child initialization nodes */
681 
682     // No translation offset.
683     Descriptor->Address32.TranslationOffset = 0;
684 
685     // Pcc is unique address.
686     Descriptor->Address32.AddressLength = 1;
687 
688     for (i = 0; InitializerOp; i++)
689     {
690         switch (i)
691         {
692 
693         case 0: /* Address Min = Max */
694 
695             Descriptor->Address32.Minimum =
696                 (UINT32) InitializerOp->Asl.Value.Integer;
697             Descriptor->Address32.Maximum =
698                 (UINT32) InitializerOp->Asl.Value.Integer;
699 
700             break;
701 
702         case 1: /* ResSourceIndex [Optional Field - BYTE] */
703 
704             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
705             {
706                 /* Found a valid ResourceSourceIndex */
707 
708                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
709                 OptionIndex++;
710                 Descriptor->Address32.ResourceLength++;
711                 ResSourceIndex = TRUE;
712             }
713             break;
714 
715         case 2: /* ResSource [Optional Field - STRING] */
716 
717             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
718                 (InitializerOp->Asl.Value.String))
719             {
720                 if (StringLength)
721                 {
722                     /* Found a valid ResourceSource */
723 
724                     Descriptor->Address32.ResourceLength = (UINT16)
725                         (Descriptor->Address32.ResourceLength + StringLength);
726 
727                     strcpy ((char *)
728                         &OptionalFields[OptionIndex],
729                         InitializerOp->Asl.Value.String);
730 
731                     /* ResourceSourceIndex must also be valid */
732 
733                     if (!ResSourceIndex)
734                     {
735                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
736                             InitializerOp, NULL);
737                     }
738                 }
739             }
740 
741             break;
742 
743         case 3: // DescriptorName
744             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
745             break;
746 
747         default:
748 
749             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
750             break;
751         }
752 
753         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
754     }
755 
756     /* Validate the Min/Max/Len/Gran values */
757 
758     RsLargeAddressCheck (
759         (UINT64) Descriptor->Address32.Minimum,
760         (UINT64) Descriptor->Address32.Maximum,
761         (UINT64) Descriptor->Address32.AddressLength,
762         (UINT64) Descriptor->Address32.Granularity,
763         Descriptor->Address32.Flags,
764         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
765 
766     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
767         OptionIndex + StringLength;
768     return (Rnode);
769 }
770 
771 
772 /*******************************************************************************
773  *
774  * FUNCTION:    RsDoQwordSpaceDescriptor
775  *
776  * PARAMETERS:  Info                - Parse Op and resource template offset
777  *
778  * RETURN:      Completed resource node
779  *
780  * DESCRIPTION: Construct a long "QwordSpace" descriptor
781  *
782  ******************************************************************************/
783 
784 ASL_RESOURCE_NODE *
RsDoQwordSpaceDescriptor(ASL_RESOURCE_INFO * Info)785 RsDoQwordSpaceDescriptor (
786     ASL_RESOURCE_INFO       *Info)
787 {
788     AML_RESOURCE            *Descriptor;
789     ACPI_PARSE_OBJECT       *InitializerOp;
790     ACPI_PARSE_OBJECT       *MinOp = NULL;
791     ACPI_PARSE_OBJECT       *MaxOp = NULL;
792     ACPI_PARSE_OBJECT       *LengthOp = NULL;
793     ACPI_PARSE_OBJECT       *GranOp = NULL;
794     ASL_RESOURCE_NODE       *Rnode;
795     UINT8                   *OptionalFields;
796     UINT16                  StringLength = 0;
797     UINT32                  OptionIndex = 0;
798     UINT32                  CurrentByteOffset;
799     UINT32                  i;
800     BOOLEAN                 ResSourceIndex = FALSE;
801 
802 
803     InitializerOp = Info->DescriptorTypeOp->Asl.Child;
804     StringLength = RsGetStringDataLength (InitializerOp);
805     CurrentByteOffset = Info->CurrentByteOffset;
806 
807     Rnode = RsAllocateResourceNode (
808         sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength);
809 
810     Descriptor = Rnode->Buffer;
811     Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64;
812 
813     /*
814      * Initial descriptor length -- may be enlarged if there are
815      * optional fields present
816      */
817     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64);
818     Descriptor->Address64.ResourceLength = (UINT16)
819         (sizeof (AML_RESOURCE_ADDRESS64) -
820          sizeof (AML_RESOURCE_LARGE_HEADER));
821 
822     /* Process all child initialization nodes */
823 
824     for (i = 0; InitializerOp; i++)
825     {
826         switch (i)
827         {
828         case 0: /* Resource Type */
829 
830             Descriptor->Address64.ResourceType =
831                 (UINT8) InitializerOp->Asl.Value.Integer;
832             break;
833 
834         case 1: /* Resource Usage */
835 
836             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1);
837             break;
838 
839         case 2: /* DecodeType */
840 
841             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0);
842             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
843                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1);
844             break;
845 
846         case 3: /* MinType */
847 
848             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0);
849             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
850                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2);
851             break;
852 
853         case 4: /* MaxType */
854 
855             RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0);
856             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
857                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3);
858             break;
859 
860         case 5: /* Type-Specific flags */
861 
862             Descriptor->Address64.SpecificFlags =
863                 (UINT8) InitializerOp->Asl.Value.Integer;
864             break;
865 
866         case 6: /* Address Granularity */
867 
868             Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer;
869             RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
870                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity));
871             GranOp = InitializerOp;
872             break;
873 
874         case 7: /* Min Address */
875 
876             Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer;
877             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR,
878                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum));
879             MinOp = InitializerOp;
880             break;
881 
882         case 8: /* Max Address */
883 
884             Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer;
885             RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
886                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum));
887             MaxOp = InitializerOp;
888             break;
889 
890         case 9: /* Translation Offset */
891 
892             Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer;
893             RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
894                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset));
895             break;
896 
897         case 10: /* Address Length */
898 
899             Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer;
900             RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH,
901                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength));
902             LengthOp = InitializerOp;
903             break;
904 
905         case 11: /* ResSourceIndex [Optional Field - BYTE] */
906 
907             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
908             {
909                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
910                 OptionIndex++;
911                 Descriptor->Address64.ResourceLength++;
912                 ResSourceIndex = TRUE;
913             }
914             break;
915 
916         case 12: /* ResSource [Optional Field - STRING] */
917 
918             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
919                 (InitializerOp->Asl.Value.String))
920             {
921                 if (StringLength)
922                 {
923                     Descriptor->Address64.ResourceLength = (UINT16)
924                         (Descriptor->Address64.ResourceLength + StringLength);
925 
926                     strcpy ((char *)
927                         &OptionalFields[OptionIndex],
928                         InitializerOp->Asl.Value.String);
929 
930                     /* ResourceSourceIndex must also be valid */
931 
932                     if (!ResSourceIndex)
933                     {
934                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
935                             InitializerOp, NULL);
936                     }
937                 }
938             }
939 
940 #if 0
941             /*
942              * Not a valid ResourceSource, ResourceSourceIndex must also
943              * be invalid
944              */
945             else if (ResSourceIndex)
946             {
947                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
948                     InitializerOp, NULL);
949             }
950 #endif
951             break;
952 
953         case 13: /* ResourceTag */
954 
955             UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
956             break;
957 
958         default:
959 
960             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
961             break;
962         }
963 
964         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
965     }
966 
967     /* Validate the Min/Max/Len/Gran values */
968 
969     RsLargeAddressCheck (
970         Descriptor->Address64.Minimum,
971         Descriptor->Address64.Maximum,
972         Descriptor->Address64.AddressLength,
973         Descriptor->Address64.Granularity,
974         Descriptor->Address64.Flags,
975         MinOp, MaxOp, LengthOp, GranOp, Info->DescriptorTypeOp);
976 
977     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) +
978         OptionIndex + StringLength;
979     return (Rnode);
980 }
981