]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/dev/acpica/compiler/aslbtypes.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.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 - 2011, 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
45 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include "aslcompiler.y.h"
47 #include <contrib/dev/acpica/include/amlcode.h>
48
49
50 #define _COMPONENT          ACPI_COMPILER
51         ACPI_MODULE_NAME    ("aslbtypes")
52
53 /* Local prototypes */
54
55 static UINT32
56 AnMapEtypeToBtype (
57     UINT32                  Etype);
58
59
60 /*******************************************************************************
61  *
62  * FUNCTION:    AnMapArgTypeToBtype
63  *
64  * PARAMETERS:  ArgType             - The ARGI required type(s) for this
65  *                                    argument, from the opcode info table
66  *
67  * RETURN:      The corresponding Bit-encoded types
68  *
69  * DESCRIPTION: Convert an encoded ARGI required argument type code into a
70  *              bitfield type code. Implements the implicit source conversion
71  *              rules.
72  *
73  ******************************************************************************/
74
75 UINT32
76 AnMapArgTypeToBtype (
77     UINT32                  ArgType)
78 {
79
80     switch (ArgType)
81     {
82
83     /* Simple types */
84
85     case ARGI_ANYTYPE:
86         return (ACPI_BTYPE_OBJECTS_AND_REFS);
87
88     case ARGI_PACKAGE:
89         return (ACPI_BTYPE_PACKAGE);
90
91     case ARGI_EVENT:
92         return (ACPI_BTYPE_EVENT);
93
94     case ARGI_MUTEX:
95         return (ACPI_BTYPE_MUTEX);
96
97     case ARGI_DDBHANDLE:
98         /*
99          * DDBHandleObject := SuperName
100          * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
101          */
102         return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
103
104     /* Interchangeable types */
105     /*
106      * Source conversion rules:
107      * Integer, String, and Buffer are all interchangeable
108      */
109     case ARGI_INTEGER:
110     case ARGI_STRING:
111     case ARGI_BUFFER:
112     case ARGI_BUFFER_OR_STRING:
113     case ARGI_COMPUTEDATA:
114         return (ACPI_BTYPE_COMPUTE_DATA);
115
116     /* References */
117
118     case ARGI_INTEGER_REF:
119         return (ACPI_BTYPE_INTEGER);
120
121     case ARGI_OBJECT_REF:
122         return (ACPI_BTYPE_ALL_OBJECTS);
123
124     case ARGI_DEVICE_REF:
125         return (ACPI_BTYPE_DEVICE_OBJECTS);
126
127     case ARGI_REFERENCE:
128         return (ACPI_BTYPE_REFERENCE);
129
130     case ARGI_TARGETREF:
131     case ARGI_FIXED_TARGET:
132     case ARGI_SIMPLE_TARGET:
133         return (ACPI_BTYPE_OBJECTS_AND_REFS);
134
135     /* Complex types */
136
137     case ARGI_DATAOBJECT:
138
139         /*
140          * Buffer, string, package or reference to a Op -
141          * Used only by SizeOf operator
142          */
143         return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
144             ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
145
146     case ARGI_COMPLEXOBJ:
147
148         /* Buffer, String, or package */
149
150         return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
151
152     case ARGI_REF_OR_STRING:
153         return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
154
155     case ARGI_REGION_OR_BUFFER:
156
157         /* Used by Load() only. Allow buffers in addition to regions/fields */
158
159         return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
160
161     case ARGI_DATAREFOBJ:
162         return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
163             ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
164
165     default:
166         break;
167     }
168
169     return (ACPI_BTYPE_OBJECTS_AND_REFS);
170 }
171
172
173 /*******************************************************************************
174  *
175  * FUNCTION:    AnMapEtypeToBtype
176  *
177  * PARAMETERS:  Etype               - Encoded ACPI Type
178  *
179  * RETURN:      Btype corresponding to the Etype
180  *
181  * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
182  *              operand conversion rules. In other words, returns the type(s)
183  *              this Etype is implicitly converted to during interpretation.
184  *
185  ******************************************************************************/
186
187 static UINT32
188 AnMapEtypeToBtype (
189     UINT32                  Etype)
190 {
191
192
193     if (Etype == ACPI_TYPE_ANY)
194     {
195         return (ACPI_BTYPE_OBJECTS_AND_REFS);
196     }
197
198     /* Try the standard ACPI data types */
199
200     if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
201     {
202         /*
203          * This switch statement implements the allowed operand conversion
204          * rules as per the "ASL Data Types" section of the ACPI
205          * specification.
206          */
207         switch (Etype)
208         {
209         case ACPI_TYPE_INTEGER:
210             return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
211
212         case ACPI_TYPE_STRING:
213         case ACPI_TYPE_BUFFER:
214             return (ACPI_BTYPE_COMPUTE_DATA);
215
216         case ACPI_TYPE_PACKAGE:
217             return (ACPI_BTYPE_PACKAGE);
218
219         case ACPI_TYPE_FIELD_UNIT:
220             return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
221
222         case ACPI_TYPE_BUFFER_FIELD:
223             return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
224
225         case ACPI_TYPE_DDB_HANDLE:
226             return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
227
228         case ACPI_BTYPE_DEBUG_OBJECT:
229
230             /* Cannot be used as a source operand */
231
232             return (0);
233
234         default:
235             return (1 << (Etype - 1));
236         }
237     }
238
239     /* Try the internal data types */
240
241     switch (Etype)
242     {
243     case ACPI_TYPE_LOCAL_REGION_FIELD:
244     case ACPI_TYPE_LOCAL_BANK_FIELD:
245     case ACPI_TYPE_LOCAL_INDEX_FIELD:
246
247         /* Named fields can be either Integer/Buffer/String */
248
249         return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
250
251     case ACPI_TYPE_LOCAL_ALIAS:
252
253         return (ACPI_BTYPE_INTEGER);
254
255
256     case ACPI_TYPE_LOCAL_RESOURCE:
257     case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
258
259         return (ACPI_BTYPE_REFERENCE);
260
261     default:
262         printf ("Unhandled encoded type: %X\n", Etype);
263         return (0);
264     }
265 }
266
267
268 /*******************************************************************************
269  *
270  * FUNCTION:    AnFormatBtype
271  *
272  * PARAMETERS:  Btype               - Bitfield of ACPI types
273  *              Buffer              - Where to put the ascii string
274  *
275  * RETURN:      None.
276  *
277  * DESCRIPTION: Convert a Btype to a string of ACPI types
278  *
279  ******************************************************************************/
280
281 void
282 AnFormatBtype (
283     char                    *Buffer,
284     UINT32                  Btype)
285 {
286     UINT32                  Type;
287     BOOLEAN                 First = TRUE;
288
289
290     *Buffer = 0;
291
292     if (Btype == 0)
293     {
294         strcat (Buffer, "NoReturnValue");
295         return;
296     }
297
298     for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
299     {
300         if (Btype & 0x00000001)
301         {
302             if (!First)
303             {
304                 strcat (Buffer, "|");
305             }
306             First = FALSE;
307             strcat (Buffer, AcpiUtGetTypeName (Type));
308         }
309         Btype >>= 1;
310     }
311
312     if (Btype & 0x00000001)
313     {
314         if (!First)
315         {
316             strcat (Buffer, "|");
317         }
318         First = FALSE;
319         strcat (Buffer, "Reference");
320     }
321
322     Btype >>= 1;
323     if (Btype & 0x00000001)
324     {
325         if (!First)
326         {
327             strcat (Buffer, "|");
328         }
329         First = FALSE;
330         strcat (Buffer, "Resource");
331     }
332 }
333
334
335 /*******************************************************************************
336  *
337  * FUNCTION:    AnGetBtype
338  *
339  * PARAMETERS:  Op                  - Parse node whose type will be returned.
340  *
341  * RETURN:      The Btype associated with the Op.
342  *
343  * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
344  *              Handles the case where the node is a name or method call and
345  *              the actual type must be obtained from the namespace node.
346  *
347  ******************************************************************************/
348
349 UINT32
350 AnGetBtype (
351     ACPI_PARSE_OBJECT       *Op)
352 {
353     ACPI_NAMESPACE_NODE     *Node;
354     ACPI_PARSE_OBJECT       *ReferencedNode;
355     UINT32                  ThisNodeBtype = 0;
356
357
358     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)     ||
359         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)  ||
360         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
361     {
362         Node = Op->Asl.Node;
363         if (!Node)
364         {
365             DbgPrint (ASL_DEBUG_OUTPUT,
366                 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
367                 Op->Asl.ParseOpName, Op->Asl.LineNumber,
368                 Op->Asl.ExternalName);
369             return (ACPI_UINT32_MAX);
370         }
371
372         ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
373         if (!ThisNodeBtype)
374         {
375             AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
376                 "could not map type");
377         }
378
379         /*
380          * Since it was a named reference, enable the
381          * reference bit also
382          */
383         ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
384
385         if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
386         {
387             ReferencedNode = Node->Op;
388             if (!ReferencedNode)
389             {
390                 /* Check for an internal method */
391
392                 if (AnIsInternalMethod (Op))
393                 {
394                     return (AnGetInternalMethodReturnType (Op));
395                 }
396
397                 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
398                     "null Op pointer");
399                 return (ACPI_UINT32_MAX);
400             }
401
402             if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
403             {
404                 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
405             }
406             else
407             {
408                 return (ACPI_UINT32_MAX -1);
409             }
410         }
411     }
412     else
413     {
414         ThisNodeBtype = Op->Asl.AcpiBtype;
415     }
416
417     return (ThisNodeBtype);
418 }
419
420
421 /*******************************************************************************
422  *
423  * FUNCTION:    AnMapObjTypeToBtype
424  *
425  * PARAMETERS:  Op                  - A parse node
426  *
427  * RETURN:      A Btype
428  *
429  * DESCRIPTION: Map object to the associated "Btype"
430  *
431  ******************************************************************************/
432
433 UINT32
434 AnMapObjTypeToBtype (
435     ACPI_PARSE_OBJECT       *Op)
436 {
437
438     switch (Op->Asl.ParseOpcode)
439     {
440     case PARSEOP_OBJECTTYPE_BFF:        /* "BuffFieldObj" */
441         return (ACPI_BTYPE_BUFFER_FIELD);
442
443     case PARSEOP_OBJECTTYPE_BUF:        /* "BuffObj" */
444         return (ACPI_BTYPE_BUFFER);
445
446     case PARSEOP_OBJECTTYPE_DDB:        /* "DDBHandleObj" */
447         return (ACPI_BTYPE_DDB_HANDLE);
448
449     case PARSEOP_OBJECTTYPE_DEV:        /* "DeviceObj" */
450         return (ACPI_BTYPE_DEVICE);
451
452     case PARSEOP_OBJECTTYPE_EVT:        /* "EventObj" */
453         return (ACPI_BTYPE_EVENT);
454
455     case PARSEOP_OBJECTTYPE_FLD:        /* "FieldUnitObj" */
456         return (ACPI_BTYPE_FIELD_UNIT);
457
458     case PARSEOP_OBJECTTYPE_INT:        /* "IntObj" */
459         return (ACPI_BTYPE_INTEGER);
460
461     case PARSEOP_OBJECTTYPE_MTH:        /* "MethodObj" */
462         return (ACPI_BTYPE_METHOD);
463
464     case PARSEOP_OBJECTTYPE_MTX:        /* "MutexObj" */
465         return (ACPI_BTYPE_MUTEX);
466
467     case PARSEOP_OBJECTTYPE_OPR:        /* "OpRegionObj" */
468         return (ACPI_BTYPE_REGION);
469
470     case PARSEOP_OBJECTTYPE_PKG:        /* "PkgObj" */
471         return (ACPI_BTYPE_PACKAGE);
472
473     case PARSEOP_OBJECTTYPE_POW:        /* "PowerResObj" */
474         return (ACPI_BTYPE_POWER);
475
476     case PARSEOP_OBJECTTYPE_STR:        /* "StrObj" */
477         return (ACPI_BTYPE_STRING);
478
479     case PARSEOP_OBJECTTYPE_THZ:        /* "ThermalZoneObj" */
480         return (ACPI_BTYPE_THERMAL);
481
482     case PARSEOP_OBJECTTYPE_UNK:        /* "UnknownObj" */
483         return (ACPI_BTYPE_OBJECTS_AND_REFS);
484
485     default:
486         return (0);
487     }
488 }
489
490
491 #ifdef ACPI_OBSOLETE_FUNCTIONS
492 /*******************************************************************************
493  *
494  * FUNCTION:    AnMapBtypeToEtype
495  *
496  * PARAMETERS:  Btype               - Bitfield of ACPI types
497  *
498  * RETURN:      The Etype corresponding the the Btype
499  *
500  * DESCRIPTION: Convert a bitfield type to an encoded type
501  *
502  ******************************************************************************/
503
504 UINT32
505 AnMapBtypeToEtype (
506     UINT32              Btype)
507 {
508     UINT32              i;
509     UINT32              Etype;
510
511
512     if (Btype == 0)
513     {
514         return (0);
515     }
516
517     Etype = 1;
518     for (i = 1; i < Btype; i *= 2)
519     {
520         Etype++;
521     }
522
523     return (Etype);
524 }
525 #endif