]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/compiler/aslbtypes.c
Merge llvm 3.5.0 release from ^/vendor/llvm/dist, resolve conflicts, and
[FreeBSD/FreeBSD.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 - 2014, 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->Asl.ParseOpcode == PARSEOP_NAMESEG)     ||
378         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)  ||
379         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
380     {
381         Node = Op->Asl.Node;
382         if (!Node)
383         {
384             DbgPrint (ASL_DEBUG_OUTPUT,
385                 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
386                 Op->Asl.ParseOpName, Op->Asl.LineNumber,
387                 Op->Asl.ExternalName);
388             return (ACPI_UINT32_MAX);
389         }
390
391         ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
392         if (!ThisNodeBtype)
393         {
394             AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
395                 "could not map type");
396         }
397
398         /*
399          * Since it was a named reference, enable the
400          * reference bit also
401          */
402         ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
403
404         if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
405         {
406             ReferencedNode = Node->Op;
407             if (!ReferencedNode)
408             {
409                 /* Check for an internal method */
410
411                 if (AnIsInternalMethod (Op))
412                 {
413                     return (AnGetInternalMethodReturnType (Op));
414                 }
415
416                 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
417                     "null Op pointer");
418                 return (ACPI_UINT32_MAX);
419             }
420
421             if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
422             {
423                 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
424             }
425             else
426             {
427                 return (ACPI_UINT32_MAX -1);
428             }
429         }
430     }
431     else
432     {
433         ThisNodeBtype = Op->Asl.AcpiBtype;
434     }
435
436     return (ThisNodeBtype);
437 }
438
439
440 /*******************************************************************************
441  *
442  * FUNCTION:    AnMapObjTypeToBtype
443  *
444  * PARAMETERS:  Op                  - A parse node
445  *
446  * RETURN:      A Btype
447  *
448  * DESCRIPTION: Map object to the associated "Btype"
449  *
450  ******************************************************************************/
451
452 UINT32
453 AnMapObjTypeToBtype (
454     ACPI_PARSE_OBJECT       *Op)
455 {
456
457     switch (Op->Asl.ParseOpcode)
458     {
459     case PARSEOP_OBJECTTYPE_BFF:        /* "BuffFieldObj" */
460
461         return (ACPI_BTYPE_BUFFER_FIELD);
462
463     case PARSEOP_OBJECTTYPE_BUF:        /* "BuffObj" */
464
465         return (ACPI_BTYPE_BUFFER);
466
467     case PARSEOP_OBJECTTYPE_DDB:        /* "DDBHandleObj" */
468
469         return (ACPI_BTYPE_DDB_HANDLE);
470
471     case PARSEOP_OBJECTTYPE_DEV:        /* "DeviceObj" */
472
473         return (ACPI_BTYPE_DEVICE);
474
475     case PARSEOP_OBJECTTYPE_EVT:        /* "EventObj" */
476
477         return (ACPI_BTYPE_EVENT);
478
479     case PARSEOP_OBJECTTYPE_FLD:        /* "FieldUnitObj" */
480
481         return (ACPI_BTYPE_FIELD_UNIT);
482
483     case PARSEOP_OBJECTTYPE_INT:        /* "IntObj" */
484
485         return (ACPI_BTYPE_INTEGER);
486
487     case PARSEOP_OBJECTTYPE_MTH:        /* "MethodObj" */
488
489         return (ACPI_BTYPE_METHOD);
490
491     case PARSEOP_OBJECTTYPE_MTX:        /* "MutexObj" */
492
493         return (ACPI_BTYPE_MUTEX);
494
495     case PARSEOP_OBJECTTYPE_OPR:        /* "OpRegionObj" */
496
497         return (ACPI_BTYPE_REGION);
498
499     case PARSEOP_OBJECTTYPE_PKG:        /* "PkgObj" */
500
501         return (ACPI_BTYPE_PACKAGE);
502
503     case PARSEOP_OBJECTTYPE_POW:        /* "PowerResObj" */
504
505         return (ACPI_BTYPE_POWER);
506
507     case PARSEOP_OBJECTTYPE_STR:        /* "StrObj" */
508
509         return (ACPI_BTYPE_STRING);
510
511     case PARSEOP_OBJECTTYPE_THZ:        /* "ThermalZoneObj" */
512
513         return (ACPI_BTYPE_THERMAL);
514
515     case PARSEOP_OBJECTTYPE_UNK:        /* "UnknownObj" */
516
517         return (ACPI_BTYPE_OBJECTS_AND_REFS);
518
519     default:
520
521         return (0);
522     }
523 }
524
525
526 #ifdef ACPI_OBSOLETE_FUNCTIONS
527 /*******************************************************************************
528  *
529  * FUNCTION:    AnMapBtypeToEtype
530  *
531  * PARAMETERS:  Btype               - Bitfield of ACPI types
532  *
533  * RETURN:      The Etype corresponding the the Btype
534  *
535  * DESCRIPTION: Convert a bitfield type to an encoded type
536  *
537  ******************************************************************************/
538
539 UINT32
540 AnMapBtypeToEtype (
541     UINT32              Btype)
542 {
543     UINT32              i;
544     UINT32              Etype;
545
546
547     if (Btype == 0)
548     {
549         return (0);
550     }
551
552     Etype = 1;
553     for (i = 1; i < Btype; i *= 2)
554     {
555         Etype++;
556     }
557
558     return (Etype);
559 }
560 #endif