]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/contrib/dev/acpica/compiler/aslbtypes.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / contrib / dev / acpica / compiler / aslbtypes.c
1 /******************************************************************************
2  *
3  * Module Name: aslbtypes - Support for bitfield types
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/amlcode.h>
47
48
49 #define _COMPONENT          ACPI_COMPILER
50         ACPI_MODULE_NAME    ("aslbtypes")
51
52 /* Local prototypes */
53
54 static UINT32
55 AnMapEtypeToBtype (
56     UINT32                  Etype);
57
58
59 /*******************************************************************************
60  *
61  * FUNCTION:    AnMapArgTypeToBtype
62  *
63  * PARAMETERS:  ArgType             - The ARGI required type(s) for this
64  *                                    argument, from the opcode info table
65  *
66  * RETURN:      The corresponding Bit-encoded types
67  *
68  * DESCRIPTION: Convert an encoded ARGI required argument type code into a
69  *              bitfield type code. Implements the implicit source conversion
70  *              rules.
71  *
72  ******************************************************************************/
73
74 UINT32
75 AnMapArgTypeToBtype (
76     UINT32                  ArgType)
77 {
78
79     switch (ArgType)
80     {
81
82     /* Simple types */
83
84     case ARGI_ANYTYPE:
85
86         return (ACPI_BTYPE_OBJECTS_AND_REFS);
87
88     case ARGI_PACKAGE:
89
90         return (ACPI_BTYPE_PACKAGE);
91
92     case ARGI_EVENT:
93
94         return (ACPI_BTYPE_EVENT);
95
96     case ARGI_MUTEX:
97
98         return (ACPI_BTYPE_MUTEX);
99
100     case ARGI_DDBHANDLE:
101         /*
102          * DDBHandleObject := SuperName
103          * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
104          */
105         return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
106
107     /* Interchangeable types */
108     /*
109      * Source conversion rules:
110      * Integer, String, and Buffer are all interchangeable
111      */
112     case ARGI_INTEGER:
113     case ARGI_STRING:
114     case ARGI_BUFFER:
115     case ARGI_BUFFER_OR_STRING:
116     case ARGI_COMPUTEDATA:
117
118         return (ACPI_BTYPE_COMPUTE_DATA);
119
120     /* References */
121
122     case ARGI_INTEGER_REF:
123
124         return (ACPI_BTYPE_INTEGER);
125
126     case ARGI_OBJECT_REF:
127
128         return (ACPI_BTYPE_ALL_OBJECTS);
129
130     case ARGI_DEVICE_REF:
131
132         return (ACPI_BTYPE_DEVICE_OBJECTS);
133
134     case ARGI_REFERENCE:
135
136         return (ACPI_BTYPE_REFERENCE);
137
138     case ARGI_TARGETREF:
139     case ARGI_FIXED_TARGET:
140     case ARGI_SIMPLE_TARGET:
141
142         return (ACPI_BTYPE_OBJECTS_AND_REFS);
143
144     /* Complex types */
145
146     case ARGI_DATAOBJECT:
147         /*
148          * Buffer, string, package or reference to a Op -
149          * Used only by SizeOf operator
150          */
151         return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
152             ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
153
154     case ARGI_COMPLEXOBJ:
155
156         /* Buffer, String, or package */
157
158         return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
159
160     case ARGI_REF_OR_STRING:
161
162         return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
163
164     case ARGI_REGION_OR_BUFFER:
165
166         /* Used by Load() only. Allow buffers in addition to regions/fields */
167
168         return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
169
170     case ARGI_DATAREFOBJ:
171
172         return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
173             ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
174
175     default:
176
177         break;
178     }
179
180     return (ACPI_BTYPE_OBJECTS_AND_REFS);
181 }
182
183
184 /*******************************************************************************
185  *
186  * FUNCTION:    AnMapEtypeToBtype
187  *
188  * PARAMETERS:  Etype               - Encoded ACPI Type
189  *
190  * RETURN:      Btype corresponding to the Etype
191  *
192  * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
193  *              operand conversion rules. In other words, returns the type(s)
194  *              this Etype is implicitly converted to during interpretation.
195  *
196  ******************************************************************************/
197
198 static UINT32
199 AnMapEtypeToBtype (
200     UINT32                  Etype)
201 {
202
203
204     if (Etype == ACPI_TYPE_ANY)
205     {
206         return (ACPI_BTYPE_OBJECTS_AND_REFS);
207     }
208
209     /* Try the standard ACPI data types */
210
211     if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
212     {
213         /*
214          * This switch statement implements the allowed operand conversion
215          * rules as per the "ASL Data Types" section of the ACPI
216          * specification.
217          */
218         switch (Etype)
219         {
220         case ACPI_TYPE_INTEGER:
221
222             return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
223
224         case ACPI_TYPE_STRING:
225         case ACPI_TYPE_BUFFER:
226
227             return (ACPI_BTYPE_COMPUTE_DATA);
228
229         case ACPI_TYPE_PACKAGE:
230
231             return (ACPI_BTYPE_PACKAGE);
232
233         case ACPI_TYPE_FIELD_UNIT:
234
235             return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
236
237         case ACPI_TYPE_BUFFER_FIELD:
238
239             return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
240
241         case ACPI_TYPE_DDB_HANDLE:
242
243             return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
244
245         case ACPI_TYPE_DEBUG_OBJECT:
246
247             /* Cannot be used as a source operand */
248
249             return (0);
250
251         default:
252
253             return (1 << (Etype - 1));
254         }
255     }
256
257     /* Try the internal data types */
258
259     switch (Etype)
260     {
261     case ACPI_TYPE_LOCAL_REGION_FIELD:
262     case ACPI_TYPE_LOCAL_BANK_FIELD:
263     case ACPI_TYPE_LOCAL_INDEX_FIELD:
264
265         /* Named fields can be either Integer/Buffer/String */
266
267         return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
268
269     case ACPI_TYPE_LOCAL_ALIAS:
270
271         return (ACPI_BTYPE_INTEGER);
272
273
274     case ACPI_TYPE_LOCAL_RESOURCE:
275     case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
276
277         return (ACPI_BTYPE_REFERENCE);
278
279     default:
280
281         printf ("Unhandled encoded type: %X\n", Etype);
282         return (0);
283     }
284 }
285
286
287 /*******************************************************************************
288  *
289  * FUNCTION:    AnFormatBtype
290  *
291  * PARAMETERS:  Btype               - Bitfield of ACPI types
292  *              Buffer              - Where to put the ascii string
293  *
294  * RETURN:      None.
295  *
296  * DESCRIPTION: Convert a Btype to a string of ACPI types
297  *
298  ******************************************************************************/
299
300 void
301 AnFormatBtype (
302     char                    *Buffer,
303     UINT32                  Btype)
304 {
305     UINT32                  Type;
306     BOOLEAN                 First = TRUE;
307
308
309     *Buffer = 0;
310
311     if (Btype == 0)
312     {
313         strcat (Buffer, "NoReturnValue");
314         return;
315     }
316
317     for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
318     {
319         if (Btype & 0x00000001)
320         {
321             if (!First)
322             {
323                 strcat (Buffer, "|");
324             }
325             First = FALSE;
326             strcat (Buffer, AcpiUtGetTypeName (Type));
327         }
328         Btype >>= 1;
329     }
330
331     if (Btype & 0x00000001)
332     {
333         if (!First)
334         {
335             strcat (Buffer, "|");
336         }
337         First = FALSE;
338         strcat (Buffer, "Reference");
339     }
340
341     Btype >>= 1;
342     if (Btype & 0x00000001)
343     {
344         if (!First)
345         {
346             strcat (Buffer, "|");
347         }
348         First = FALSE;
349         strcat (Buffer, "Resource");
350     }
351 }
352
353
354 /*******************************************************************************
355  *
356  * FUNCTION:    AnGetBtype
357  *
358  * PARAMETERS:  Op                  - Parse node whose type will be returned.
359  *
360  * RETURN:      The Btype associated with the Op.
361  *
362  * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
363  *              Handles the case where the node is a name or method call and
364  *              the actual type must be obtained from the namespace node.
365  *
366  ******************************************************************************/
367
368 UINT32
369 AnGetBtype (
370     ACPI_PARSE_OBJECT       *Op)
371 {
372     ACPI_NAMESPACE_NODE     *Node;
373     ACPI_PARSE_OBJECT       *ReferencedNode;
374     UINT32                  ThisNodeBtype = 0;
375
376
377     if (!Op)
378     {
379         AcpiOsPrintf ("Null Op in AnGetBtype\n");
380         return (ACPI_UINT32_MAX);
381     }
382
383     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)     ||
384         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)  ||
385         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
386     {
387         Node = Op->Asl.Node;
388         if (!Node)
389         {
390             DbgPrint (ASL_DEBUG_OUTPUT,
391                 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
392                 Op->Asl.ParseOpName, Op->Asl.LineNumber,
393                 Op->Asl.ExternalName);
394             return (ACPI_UINT32_MAX);
395         }
396
397         ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
398         if (!ThisNodeBtype)
399         {
400             AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
401                 "could not map type");
402         }
403
404         /*
405          * Since it was a named reference, enable the
406          * reference bit also
407          */
408         ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
409
410         if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
411         {
412             ReferencedNode = Node->Op;
413             if (!ReferencedNode)
414             {
415                 /* Check for an internal method */
416
417                 if (AnIsInternalMethod (Op))
418                 {
419                     return (AnGetInternalMethodReturnType (Op));
420                 }
421
422                 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
423                     "null Op pointer");
424                 return (ACPI_UINT32_MAX);
425             }
426
427             if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
428             {
429                 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
430             }
431             else
432             {
433                 return (ACPI_UINT32_MAX -1);
434             }
435         }
436     }
437     else
438     {
439         ThisNodeBtype = Op->Asl.AcpiBtype;
440     }
441
442     return (ThisNodeBtype);
443 }
444
445
446 /*******************************************************************************
447  *
448  * FUNCTION:    AnMapObjTypeToBtype
449  *
450  * PARAMETERS:  Op                  - A parse node
451  *
452  * RETURN:      A Btype
453  *
454  * DESCRIPTION: Map object to the associated "Btype"
455  *
456  ******************************************************************************/
457
458 UINT32
459 AnMapObjTypeToBtype (
460     ACPI_PARSE_OBJECT       *Op)
461 {
462
463     switch (Op->Asl.ParseOpcode)
464     {
465     case PARSEOP_OBJECTTYPE_BFF:        /* "BuffFieldObj" */
466
467         return (ACPI_BTYPE_BUFFER_FIELD);
468
469     case PARSEOP_OBJECTTYPE_BUF:        /* "BuffObj" */
470
471         return (ACPI_BTYPE_BUFFER);
472
473     case PARSEOP_OBJECTTYPE_DDB:        /* "DDBHandleObj" */
474
475         return (ACPI_BTYPE_DDB_HANDLE);
476
477     case PARSEOP_OBJECTTYPE_DEV:        /* "DeviceObj" */
478
479         return (ACPI_BTYPE_DEVICE);
480
481     case PARSEOP_OBJECTTYPE_EVT:        /* "EventObj" */
482
483         return (ACPI_BTYPE_EVENT);
484
485     case PARSEOP_OBJECTTYPE_FLD:        /* "FieldUnitObj" */
486
487         return (ACPI_BTYPE_FIELD_UNIT);
488
489     case PARSEOP_OBJECTTYPE_INT:        /* "IntObj" */
490
491         return (ACPI_BTYPE_INTEGER);
492
493     case PARSEOP_OBJECTTYPE_MTH:        /* "MethodObj" */
494
495         return (ACPI_BTYPE_METHOD);
496
497     case PARSEOP_OBJECTTYPE_MTX:        /* "MutexObj" */
498
499         return (ACPI_BTYPE_MUTEX);
500
501     case PARSEOP_OBJECTTYPE_OPR:        /* "OpRegionObj" */
502
503         return (ACPI_BTYPE_REGION);
504
505     case PARSEOP_OBJECTTYPE_PKG:        /* "PkgObj" */
506
507         return (ACPI_BTYPE_PACKAGE);
508
509     case PARSEOP_OBJECTTYPE_POW:        /* "PowerResObj" */
510
511         return (ACPI_BTYPE_POWER);
512
513     case PARSEOP_OBJECTTYPE_STR:        /* "StrObj" */
514
515         return (ACPI_BTYPE_STRING);
516
517     case PARSEOP_OBJECTTYPE_THZ:        /* "ThermalZoneObj" */
518
519         return (ACPI_BTYPE_THERMAL);
520
521     case PARSEOP_OBJECTTYPE_UNK:        /* "UnknownObj" */
522
523         return (ACPI_BTYPE_OBJECTS_AND_REFS);
524
525     default:
526
527         return (0);
528     }
529 }
530
531
532 #ifdef ACPI_OBSOLETE_FUNCTIONS
533 /*******************************************************************************
534  *
535  * FUNCTION:    AnMapBtypeToEtype
536  *
537  * PARAMETERS:  Btype               - Bitfield of ACPI types
538  *
539  * RETURN:      The Etype corresponding the the Btype
540  *
541  * DESCRIPTION: Convert a bitfield type to an encoded type
542  *
543  ******************************************************************************/
544
545 UINT32
546 AnMapBtypeToEtype (
547     UINT32              Btype)
548 {
549     UINT32              i;
550     UINT32              Etype;
551
552
553     if (Btype == 0)
554     {
555         return (0);
556     }
557
558     Etype = 1;
559     for (i = 1; i < Btype; i *= 2)
560     {
561         Etype++;
562     }
563
564     return (Etype);
565 }
566 #endif