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