Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / tests / misc / badcode.asl
1 /*
2  * badcode.asl
3  *
4  * This file contains examples of the extended error checking and
5  * typechecking capabilities of the iASL compiler. Other ASL compilers
6  * may ignore these errors completely. Note - this is not an exhaustive
7  * list of errors detected by iASL, it shows many of the errors that
8  * are not detected by other ASL compilers.
9  *
10  * To compile, use:
11  * iasl badcode.asl
12  *
13  * Output:
14  * Compilation complete. 45 Errors, 22 Warnings, 3 Remarks, 16 Optimizations
15  *
16  */
17 DefinitionBlock ("badcode.aml", "DSDT", 1, "Intel", "Example", 0x00000001)
18 {
19     Name (INT1, 0)
20     Name (BUF1, Buffer() {0,1,2,3})
21     Event (EVT1)
22
23     // Invalid SyncLevel in Mutex declaration
24
25     Mutex (MTX1, 32)
26
27     // Integer beyond the table integer size (32 bits)
28
29     Name (BIG, 0x1234567887654321)
30
31     // CPackage length does not match initializer list length
32
33     Name (PKG1, Package(5) {0,1})
34
35     // Inadvertent use of single backslash in a string
36
37     Name (PATH, Buffer() {"\_SB_.PCI2._CRS"})
38
39     // Invalid hex escape sequence
40
41     Name (ESC1, "abcdefg\x00hijklmn")
42
43     // Field access beyond region bounds
44
45     OperationRegion (OPR1, SystemMemory, 0x2000, 6)
46     Field (OPR1, DWordAcc, NoLock, Preserve)
47     {
48         Offset (4),
49         FLD1, 8
50     }
51
52     // Some address spaces support only ByteAcc or BufferAcc
53
54     OperationRegion (OPR2, EmbeddedControl, 0x4000, 8)
55     Field (OPR2, DWordAcc, NoLock, Preserve)
56     {
57         FLD2, 8
58     }
59     OperationRegion (OPR3, SMBus, 0x8000, 16)
60     Field (OPR3, WordAcc, NoLock, Preserve)
61     {
62         FLD3, 8
63     }
64
65     // Invalid SyncLevel in method declaration
66
67     Method (MTH1, 0, NotSerialized, 32)
68     {
69         // Invalid arguments and uninitialized locals
70
71         Store (Arg3, Local0)
72         Store (Local1, Local2)
73
74         // Parameter typechecking (MTX1 is invalid type)
75
76         Subtract (MTX1, 4, Local3)
77
78         // Various invalid parameters
79
80         CreateField (BUF1, 0, Subtract (4, 4), FLD1)
81
82         // Unchecked mutex and event timeouts
83
84         Acquire (MTX1, 100)
85         Wait (EVT1, 1)
86
87         // Result from operation is not used - statement has no effect
88
89         Add (INT1, 8)
90
91         // Unreachable code
92
93         Return (0)
94         Store (5, INT1)
95     }
96
97     Method (MTH2)
98     {
99         // Switch with no Case statements
100
101         Switch (ToInteger (INT1))
102         {
103             Default
104             {
105             }
106         }
107
108         if (LEqual (INT1, 0))
109         {
110             Return (INT1)
111         }
112
113         // Fallthrough exit path does not return a value
114     }
115
116     Method (MTH3)
117     {
118         // Method MTH2 above does not always return a value
119
120         Store (MTH2 (), Local0)
121     }
122
123     // Method MTH4 does not explicitly return a value
124
125     Method (MTH4) {}
126     Method (MTH5) {Store (MTH4(), Local0)}
127
128     // Invalid _HID values
129
130     Device (H1)
131     {
132         Name (_HID, "*PNP0C0A")     // Illegal leading asterisk
133     }
134     Device (H2)
135     {
136         Name (_HID, "PNP")          // Too short, must be 7 or 8 chars
137     }
138     Device (H3)
139     {
140         Name (_HID, "MYDEVICE01")   // Too long, must be 7 or 8 chars
141     }
142     Device (H4)
143     {
144         Name (_HID, "acpi0001")     // non-hex chars must be uppercase
145     }
146     Device (H5)
147     {
148         Name (_HID, "PNP-123")      // HID must be alphanumeric
149     }
150     Device (H6)
151     {
152         Name (_HID, "")             // Illegal Null HID
153         Name (_CID, "")             // Illegal Null CID
154     }
155
156     // Predefined Name typechecking
157
158     Name (_PRW, 4)
159     Name (_FDI, Buffer () {0})
160
161     // Predefined Name argument count validation
162     // and return value validation
163
164     Method (_OSC, 5)
165     {
166     }
167
168     // Predefined Names that must be implemented as control methods
169
170     Name (_L01, 1)
171     Name (_E02, 2)
172     Name (_Q03, 3)
173     Name (_ON,  0)
174     Name (_INI, 1)
175     Name (_PTP, 2)
176
177     // GPE methods that cause type collision (L vs. E)
178
179     Scope (\_GPE)
180     {
181         Method (_L1D)
182         {
183         }
184         Method (_E1D)
185         {
186         }
187     }
188
189     // Predefined names that should not have a return value
190
191     Method (_FDM, 1)
192     {
193         Return (Buffer(1){0x33})
194     }
195     Method (_Q22)
196     {
197         Return ("Unexpected Return Value")
198     }
199
200     // _REG must have a corresponding Operation Region declaration
201     // within the same scope
202
203     Device (EC)
204     {
205         Method (_REG, 2)
206         {
207         }
208     }
209
210     /*
211      * Resource Descriptor error checking
212      */
213     Name (RSC1, ResourceTemplate ()
214     {
215         // Illegal nested StartDependent macros
216
217         StartDependentFn (0, 0)
218         {
219             StartDependentFn (0, 0)
220             {
221             }
222         }
223
224         // Missing EndDependentFn macro
225     })
226
227     Name (RSC2, ResourceTemplate ()
228     {
229         // AddressMin is larger than AddressMax
230         IO (Decode16,
231             0x07D0,             // Range Minimum
232             0x03E8,             // Range Maximum
233             0x01,               // Alignment
234             0x20,               // Length
235             )
236
237         // Length larger than Min/Max window size
238         Memory32 (ReadOnly,
239             0x00001000,         // Range Minimum
240             0x00002000,         // Range Maximum
241             0x00000004,         // Alignment
242             0x00002000,         // Length
243             )
244
245         // Min and Max not multiples of alignment value
246         Memory32 (ReadOnly,
247             0x00001001,         // Range Minimum
248             0x00002002,         // Range Maximum
249             0x00000004,         // Alignment
250             0x00000200,         // Length
251             )
252
253         // 10-bit ISA I/O address has a max of 0x3FF
254         FixedIO (
255             0xFFFF,             // Address
256             0x20,               // Length
257             )
258
259         // Invalid AccessSize parameter
260         Register (SystemIO,
261             0x08,               // Bit Width
262             0x00,               // Bit Offset
263             0x0000000000000100, // Address
264             0x05                // Access Size
265             )
266
267         // Invalid ResourceType (0xB0)
268         QWordSpace (0xB0, ResourceConsumer, PosDecode, MinFixed, MaxFixed, 0xA5,
269             0x0000,             // Granularity
270             0xA000,             // Range Minimum
271             0xBFFF,             // Range Maximum
272             0x0000,             // Translation Offset
273             0x2000,             // Length
274             ,, )
275
276         // AddressMin is larger than AddressMax
277         WordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
278             0x0000,             // Granularity
279             0x0200,             // Range Minimum
280             0x0100,             // Range Maximum
281             0x0000,             // Translation Offset
282             0x0100,             // Length
283             ,, , TypeStatic)
284
285         // Length larger than Min/Max window size
286         DWordSpace (0xC3, ResourceConsumer, PosDecode, MinFixed, MaxFixed, 0xA5,
287             0x00000000,         // Granularity
288             0x000C8000,         // Range Minimum
289             0x000C9000,         // Range Maximum
290             0x00000000,         // Translation Offset
291             0x00001002,         // Length
292             ,, )
293
294         // Granularity must be (power-of-two -1)
295         DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxNotFixed, NonCacheable, ReadWrite,
296             0x00000010,
297             0x40000000,
298             0xFED9FFFF,
299             0x00000000,
300             0xBECA0000)
301
302         // Address Min (with zero length) not on granularity boundary
303         QWordIO (ResourceProducer, MinFixed, MaxNotFixed, PosDecode, EntireRange,
304             0x0000000000000003, // Granularity
305             0x0000000000000B02, // Range Minimum
306             0x0000000000000C00, // Range Maximum
307             0x0000000000000000, // Translation Offset
308             0x0000000000000000, // Length
309             ,, , TypeStatic)
310
311         // Address Max (with zero length) not on (granularity boundary -1)
312         QWordMemory (ResourceProducer, PosDecode, MinNotFixed, MaxFixed, Cacheable, ReadWrite,
313             0x0000000000000001, // Granularity
314             0x0000000000100000, // Range Minimum
315             0x00000000002FFFFE, // Range Maximum
316             0x0000000000000000, // Translation Offset
317             0x0000000000000000, // Length
318             ,, , AddressRangeMemory, TypeStatic)
319
320         // Invalid combination: zero length, both Min and Max are fixed
321         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
322             0x00000000,         // Granularity
323             0x000C8000,         // Range Minimum
324             0x000C8FFF,         // Range Maximum
325             0x00000000,         // Translation Offset
326             0x00000000,         // Length
327             ,, )
328
329         // Invalid combination: non-zero length, Min Fixed, Max not fixed
330         DWordIO (ResourceProducer, MinFixed, MaxNotFixed, PosDecode, EntireRange,
331             0x00000001,         // Granularity
332             0x000C8000,         // Range Minimum
333             0x000C8FFF,         // Range Maximum
334             0x00000000,         // Translation Offset
335             0x00000100,         // Length
336             ,, )
337
338         // Invalid combination: non-zero length, Min not Fixed, Max fixed
339         DWordIO (ResourceProducer, MinNotFixed, MaxFixed, PosDecode, EntireRange,
340             0x00000001,         // Granularity
341             0x000C8000,         // Range Minimum
342             0x000C8FFF,         // Range Maximum
343             0x00000000,         // Translation Offset
344             0x00000200,         // Length
345             ,, )
346
347         // Granularity must be zero if non-zero length, min/max fixed
348         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
349             0x0000000F,         // Granularity
350             0x000C8000,         // Range Minimum
351             0x000C8FFF,         // Range Maximum
352             0x00000000,         // Translation Offset
353             0x00001000,         // Length
354             ,, )
355
356         // Null descriptor (intended to be modified at runtime) must
357         // have a resource tag (to allow it to be modified at runtime)
358         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
359             0x00000000,         // Granularity
360             0x00000000,         // Range Minimum
361             0x00000000,         // Range Maximum
362             0x00000000,         // Translation Offset
363             0x00000000,         // Length
364             ,, )
365
366         // Missing StartDependentFn macro
367
368         EndDependentFn ()
369     })
370
371     // Test descriptor for CreateXxxxField operators in REM1 below
372
373     Name (RSC3, ResourceTemplate ()
374     {
375         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
376             0x00000000,         // Granularity
377             0x000C8000,         // Range Minimum
378             0x000C8FFF,         // Range Maximum
379             0x00000000,         // Translation Offset
380             0x00001000,         // Length
381             ,, DWI1)
382     })
383
384     Method (REM1)
385     {
386         // Tagged resource field larger than field being created
387
388         CreateWordField (RSC3, \DWI1._LEN, LEN)
389         CreateByteField (RSC3, \DWI1._MIN, MIN)
390         CreateBitField (RSC3, \DWI1._RNG, RNG1)
391
392         // Tagged resource field smaller than field being created
393
394         CreateQWordField (RSC3, \DWI1._MAX, MAX)
395         CreateBitField (RSC3, \DWI1._GRA, GRA)
396         CreateField (RSC3, \DWI1._MIF, 5, MIF)
397         CreateField (RSC3, \DWI1._RNG, 3, RNG2)
398     }
399
400     Method (L100)
401     {
402         /* Method Local is set but never used */
403
404         Store (40, Local0)
405     }
406 }