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