asloperands.c revision 1.1.1.17 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: asloperands - AML operand processing
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.16 christos * Copyright (C) 2000 - 2019, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho #include "aslcompiler.y.h"
46 1.1 jruoho #include "amlcode.h"
47 1.1 jruoho
48 1.1 jruoho #define _COMPONENT ACPI_COMPILER
49 1.1 jruoho ACPI_MODULE_NAME ("asloperands")
50 1.1 jruoho
51 1.1 jruoho /* Local prototypes */
52 1.1 jruoho
53 1.1 jruoho static void
54 1.1 jruoho OpnDoField (
55 1.1 jruoho ACPI_PARSE_OBJECT *Op);
56 1.1 jruoho
57 1.1 jruoho static void
58 1.1 jruoho OpnDoBankField (
59 1.1 jruoho ACPI_PARSE_OBJECT *Op);
60 1.1 jruoho
61 1.1 jruoho static void
62 1.1 jruoho OpnDoBuffer (
63 1.1 jruoho ACPI_PARSE_OBJECT *Op);
64 1.1 jruoho
65 1.1 jruoho static void
66 1.1 jruoho OpnDoDefinitionBlock (
67 1.1 jruoho ACPI_PARSE_OBJECT *Op);
68 1.1 jruoho
69 1.1 jruoho static void
70 1.1 jruoho OpnDoFieldCommon (
71 1.1 jruoho ACPI_PARSE_OBJECT *FieldOp,
72 1.1 jruoho ACPI_PARSE_OBJECT *Op);
73 1.1 jruoho
74 1.1 jruoho static void
75 1.1 jruoho OpnDoIndexField (
76 1.1 jruoho ACPI_PARSE_OBJECT *Op);
77 1.1 jruoho
78 1.1 jruoho static void
79 1.1 jruoho OpnDoLoadTable (
80 1.1 jruoho ACPI_PARSE_OBJECT *Op);
81 1.1 jruoho
82 1.1 jruoho static void
83 1.1 jruoho OpnDoMethod (
84 1.1 jruoho ACPI_PARSE_OBJECT *Op);
85 1.1 jruoho
86 1.1 jruoho static void
87 1.1 jruoho OpnDoMutex (
88 1.1 jruoho ACPI_PARSE_OBJECT *Op);
89 1.1 jruoho
90 1.1 jruoho static void
91 1.1 jruoho OpnDoRegion (
92 1.1 jruoho ACPI_PARSE_OBJECT *Op);
93 1.1 jruoho
94 1.1 jruoho static void
95 1.1 jruoho OpnAttachNameToNode (
96 1.1 jruoho ACPI_PARSE_OBJECT *Op);
97 1.1 jruoho
98 1.1 jruoho
99 1.1 jruoho /*******************************************************************************
100 1.1 jruoho *
101 1.1 jruoho * FUNCTION: OpnDoMutex
102 1.1 jruoho *
103 1.1 jruoho * PARAMETERS: Op - The parent parse node
104 1.1 jruoho *
105 1.1 jruoho * RETURN: None
106 1.1 jruoho *
107 1.1 jruoho * DESCRIPTION: Construct the operands for the MUTEX ASL keyword.
108 1.1 jruoho *
109 1.1 jruoho ******************************************************************************/
110 1.1 jruoho
111 1.1 jruoho static void
112 1.1 jruoho OpnDoMutex (
113 1.1 jruoho ACPI_PARSE_OBJECT *Op)
114 1.1 jruoho {
115 1.1 jruoho ACPI_PARSE_OBJECT *Next;
116 1.1 jruoho
117 1.1 jruoho
118 1.1 jruoho Next = Op->Asl.Child;
119 1.1 jruoho Next = Next->Asl.Next;
120 1.1 jruoho
121 1.1 jruoho if (Next->Asl.Value.Integer > 15)
122 1.1 jruoho {
123 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
124 1.1 jruoho }
125 1.1 jruoho return;
126 1.1 jruoho }
127 1.1 jruoho
128 1.1 jruoho
129 1.1 jruoho /*******************************************************************************
130 1.1 jruoho *
131 1.1 jruoho * FUNCTION: OpnDoMethod
132 1.1 jruoho *
133 1.1 jruoho * PARAMETERS: Op - The parent parse node
134 1.1 jruoho *
135 1.1 jruoho * RETURN: None
136 1.1 jruoho *
137 1.1 jruoho * DESCRIPTION: Construct the operands for the METHOD ASL keyword.
138 1.1 jruoho *
139 1.1 jruoho ******************************************************************************/
140 1.1 jruoho
141 1.1 jruoho static void
142 1.1 jruoho OpnDoMethod (
143 1.1 jruoho ACPI_PARSE_OBJECT *Op)
144 1.1 jruoho {
145 1.1 jruoho ACPI_PARSE_OBJECT *Next;
146 1.1 jruoho
147 1.1 jruoho /* Optional arguments for this opcode with defaults */
148 1.1 jruoho
149 1.1 jruoho UINT8 NumArgs = 0;
150 1.1 jruoho UINT8 Serialized = 0;
151 1.1 jruoho UINT8 Concurrency = 0;
152 1.1 jruoho UINT8 MethodFlags;
153 1.1 jruoho
154 1.1 jruoho
155 1.1 jruoho /* Opcode and package length first */
156 1.1 jruoho /* Method name */
157 1.1 jruoho
158 1.1 jruoho Next = Op->Asl.Child;
159 1.1 jruoho
160 1.1 jruoho /* Num args */
161 1.1 jruoho
162 1.1 jruoho Next = Next->Asl.Next;
163 1.1 jruoho if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
164 1.1 jruoho {
165 1.1 jruoho NumArgs = (UINT8) Next->Asl.Value.Integer;
166 1.1 jruoho Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
167 1.1 jruoho }
168 1.1 jruoho
169 1.1 jruoho /* Serialized Flag */
170 1.1 jruoho
171 1.1 jruoho Next = Next->Asl.Next;
172 1.1 jruoho if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
173 1.1 jruoho {
174 1.1 jruoho Serialized = (UINT8) Next->Asl.Value.Integer;
175 1.1 jruoho Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
176 1.1 jruoho }
177 1.1 jruoho
178 1.1 jruoho /* Concurrency value (valid values are 0-15) */
179 1.1 jruoho
180 1.1 jruoho Next = Next->Asl.Next;
181 1.1 jruoho if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
182 1.1 jruoho {
183 1.1.1.3 christos /* This is a ByteConstExpr, so eval the constant now */
184 1.1.1.3 christos
185 1.1.1.3 christos OpcAmlConstantWalk (Next, 0, NULL);
186 1.1.1.3 christos
187 1.1 jruoho if (Next->Asl.Value.Integer > 15)
188 1.1 jruoho {
189 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
190 1.1 jruoho }
191 1.1.1.7 christos
192 1.1 jruoho Concurrency = (UINT8) Next->Asl.Value.Integer;
193 1.1 jruoho }
194 1.1 jruoho
195 1.1 jruoho /* Put the bits in their proper places */
196 1.1 jruoho
197 1.1.1.7 christos MethodFlags = (UINT8)
198 1.1.1.7 christos ((NumArgs & 0x7) |
199 1.1.1.7 christos ((Serialized & 0x1) << 3) |
200 1.1.1.7 christos ((Concurrency & 0xF) << 4));
201 1.1 jruoho
202 1.1 jruoho /* Use the last node for the combined flags byte */
203 1.1 jruoho
204 1.1 jruoho Next->Asl.Value.Integer = MethodFlags;
205 1.1 jruoho Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
206 1.1 jruoho Next->Asl.AmlLength = 1;
207 1.1 jruoho Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
208 1.1 jruoho
209 1.1 jruoho /* Save the arg count in the first node */
210 1.1 jruoho
211 1.1 jruoho Op->Asl.Extra = NumArgs;
212 1.1 jruoho }
213 1.1 jruoho
214 1.1 jruoho
215 1.1 jruoho /*******************************************************************************
216 1.1 jruoho *
217 1.1 jruoho * FUNCTION: OpnDoFieldCommon
218 1.1 jruoho *
219 1.1 jruoho * PARAMETERS: FieldOp - Node for an ASL field
220 1.1 jruoho * Op - The parent parse node
221 1.1 jruoho *
222 1.1 jruoho * RETURN: None
223 1.1 jruoho *
224 1.1 jruoho * DESCRIPTION: Construct the AML operands for the various field keywords,
225 1.1 jruoho * FIELD, BANKFIELD, INDEXFIELD
226 1.1 jruoho *
227 1.1 jruoho ******************************************************************************/
228 1.1 jruoho
229 1.1 jruoho static void
230 1.1 jruoho OpnDoFieldCommon (
231 1.1 jruoho ACPI_PARSE_OBJECT *FieldOp,
232 1.1 jruoho ACPI_PARSE_OBJECT *Op)
233 1.1 jruoho {
234 1.1 jruoho ACPI_PARSE_OBJECT *Next;
235 1.1 jruoho ACPI_PARSE_OBJECT *PkgLengthNode;
236 1.1 jruoho UINT32 CurrentBitOffset;
237 1.1 jruoho UINT32 NewBitOffset;
238 1.1 jruoho UINT8 AccessType;
239 1.1 jruoho UINT8 LockRule;
240 1.1 jruoho UINT8 UpdateRule;
241 1.1 jruoho UINT8 FieldFlags;
242 1.1 jruoho UINT32 MinimumLength;
243 1.1 jruoho
244 1.1 jruoho
245 1.1 jruoho /* AccessType -- not optional, so no need to check for DEFAULT_ARG */
246 1.1 jruoho
247 1.1 jruoho AccessType = (UINT8) Op->Asl.Value.Integer;
248 1.1 jruoho Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
249 1.1 jruoho
250 1.1 jruoho /* Set the access type in the parent (field) node for use later */
251 1.1 jruoho
252 1.1 jruoho FieldOp->Asl.Value.Integer = AccessType;
253 1.1 jruoho
254 1.1 jruoho /* LockRule -- not optional, so no need to check for DEFAULT_ARG */
255 1.1 jruoho
256 1.1 jruoho Next = Op->Asl.Next;
257 1.1 jruoho LockRule = (UINT8) Next->Asl.Value.Integer;
258 1.1 jruoho Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
259 1.1 jruoho
260 1.1 jruoho /* UpdateRule -- not optional, so no need to check for DEFAULT_ARG */
261 1.1 jruoho
262 1.1 jruoho Next = Next->Asl.Next;
263 1.1 jruoho UpdateRule = (UINT8) Next->Asl.Value.Integer;
264 1.1 jruoho
265 1.1 jruoho /*
266 1.1.1.3 christos * Generate the flags byte. The various fields are already
267 1.1 jruoho * in the right bit position via translation from the
268 1.1 jruoho * keywords by the parser.
269 1.1 jruoho */
270 1.1 jruoho FieldFlags = (UINT8) (AccessType | LockRule | UpdateRule);
271 1.1 jruoho
272 1.1 jruoho /* Use the previous node to be the FieldFlags node */
273 1.1 jruoho
274 1.1 jruoho /* Set the node to RAW_DATA */
275 1.1 jruoho
276 1.1 jruoho Next->Asl.Value.Integer = FieldFlags;
277 1.1.1.7 christos Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
278 1.1.1.7 christos Next->Asl.AmlLength = 1;
279 1.1.1.7 christos Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
280 1.1 jruoho
281 1.1 jruoho /* Process the FieldUnitList */
282 1.1 jruoho
283 1.1 jruoho Next = Next->Asl.Next;
284 1.1 jruoho CurrentBitOffset = 0;
285 1.1 jruoho
286 1.1 jruoho while (Next)
287 1.1 jruoho {
288 1.1 jruoho /* Save the offset of this field unit */
289 1.1 jruoho
290 1.1 jruoho Next->Asl.ExtraValue = CurrentBitOffset;
291 1.1 jruoho
292 1.1 jruoho switch (Next->Asl.ParseOpcode)
293 1.1 jruoho {
294 1.1 jruoho case PARSEOP_ACCESSAS:
295 1.1 jruoho
296 1.1 jruoho PkgLengthNode = Next->Asl.Child;
297 1.1 jruoho AccessType = (UINT8) PkgLengthNode->Asl.Value.Integer;
298 1.1 jruoho
299 1.1 jruoho /* Nothing additional to do */
300 1.1 jruoho break;
301 1.1 jruoho
302 1.1 jruoho case PARSEOP_OFFSET:
303 1.1 jruoho
304 1.1 jruoho /* New offset into the field */
305 1.1 jruoho
306 1.1 jruoho PkgLengthNode = Next->Asl.Child;
307 1.1 jruoho NewBitOffset = ((UINT32) PkgLengthNode->Asl.Value.Integer) * 8;
308 1.1 jruoho
309 1.1 jruoho /*
310 1.1 jruoho * Examine the specified offset in relation to the
311 1.1 jruoho * current offset counter.
312 1.1 jruoho */
313 1.1 jruoho if (NewBitOffset < CurrentBitOffset)
314 1.1 jruoho {
315 1.1 jruoho /*
316 1.1 jruoho * Not allowed to specify a backwards offset!
317 1.1 jruoho * Issue error and ignore this node.
318 1.1 jruoho */
319 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_BACKWARDS_OFFSET, PkgLengthNode,
320 1.1 jruoho NULL);
321 1.1 jruoho Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
322 1.1 jruoho PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
323 1.1 jruoho }
324 1.1.1.15 christos else if (NewBitOffset == CurrentBitOffset)
325 1.1 jruoho {
326 1.1 jruoho /*
327 1.1.1.15 christos * This Offset() operator is redundant and not needed,
328 1.1.1.15 christos * because the offset value is the same as the current
329 1.1.1.15 christos * offset.
330 1.1 jruoho */
331 1.1.1.15 christos AslError (ASL_REMARK, ASL_MSG_OFFSET, PkgLengthNode, NULL);
332 1.1.1.15 christos
333 1.1.1.15 christos if (AslGbl_OptimizeTrivialParseNodes)
334 1.1.1.15 christos {
335 1.1.1.15 christos /*
336 1.1.1.15 christos * Optimize this Offset() operator by removing/ignoring
337 1.1.1.15 christos * it. Set the related nodes to default.
338 1.1.1.15 christos */
339 1.1.1.15 christos Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
340 1.1.1.15 christos PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
341 1.1.1.15 christos
342 1.1.1.15 christos AslError (ASL_OPTIMIZATION, ASL_MSG_OFFSET, PkgLengthNode,
343 1.1.1.15 christos "Optimizer has removed statement");
344 1.1.1.15 christos }
345 1.1.1.15 christos else
346 1.1.1.15 christos {
347 1.1.1.15 christos /* Optimization is disabled, treat as a valid Offset */
348 1.1.1.15 christos
349 1.1.1.15 christos PkgLengthNode->Asl.Value.Integer =
350 1.1.1.15 christos NewBitOffset - CurrentBitOffset;
351 1.1.1.15 christos CurrentBitOffset = NewBitOffset;
352 1.1.1.15 christos }
353 1.1 jruoho }
354 1.1 jruoho else
355 1.1 jruoho {
356 1.1 jruoho /*
357 1.1 jruoho * Valid new offset - set the value to be inserted into the AML
358 1.1 jruoho * and update the offset counter.
359 1.1 jruoho */
360 1.1 jruoho PkgLengthNode->Asl.Value.Integer =
361 1.1 jruoho NewBitOffset - CurrentBitOffset;
362 1.1 jruoho CurrentBitOffset = NewBitOffset;
363 1.1 jruoho }
364 1.1 jruoho break;
365 1.1 jruoho
366 1.1 jruoho case PARSEOP_NAMESEG:
367 1.1 jruoho case PARSEOP_RESERVED_BYTES:
368 1.1 jruoho
369 1.1 jruoho /* Named or reserved field entry */
370 1.1 jruoho
371 1.1.1.7 christos PkgLengthNode = Next->Asl.Child;
372 1.1.1.7 christos NewBitOffset = (UINT32) PkgLengthNode->Asl.Value.Integer;
373 1.1 jruoho CurrentBitOffset += NewBitOffset;
374 1.1 jruoho
375 1.1.1.9 christos if ((NewBitOffset == 0) &&
376 1.1.1.11 christos (Next->Asl.ParseOpcode == PARSEOP_RESERVED_BYTES) &&
377 1.1.1.15 christos AslGbl_OptimizeTrivialParseNodes)
378 1.1.1.9 christos {
379 1.1.1.9 christos /*
380 1.1.1.9 christos * Unnamed field with a bit length of zero. We can
381 1.1.1.9 christos * safely just ignore this. However, we will not ignore
382 1.1.1.9 christos * a named field of zero length, we don't want to just
383 1.1.1.9 christos * toss out a name.
384 1.1.1.9 christos */
385 1.1.1.9 christos Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
386 1.1.1.9 christos PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
387 1.1.1.9 christos break;
388 1.1.1.9 christos }
389 1.1.1.9 christos
390 1.1 jruoho /* Save the current AccessAs value for error checking later */
391 1.1 jruoho
392 1.1 jruoho switch (AccessType)
393 1.1 jruoho {
394 1.1 jruoho case AML_FIELD_ACCESS_ANY:
395 1.1 jruoho case AML_FIELD_ACCESS_BYTE:
396 1.1 jruoho case AML_FIELD_ACCESS_BUFFER:
397 1.1 jruoho default:
398 1.1.1.3 christos
399 1.1 jruoho MinimumLength = 8;
400 1.1 jruoho break;
401 1.1 jruoho
402 1.1 jruoho case AML_FIELD_ACCESS_WORD:
403 1.1 jruoho MinimumLength = 16;
404 1.1 jruoho break;
405 1.1 jruoho
406 1.1 jruoho case AML_FIELD_ACCESS_DWORD:
407 1.1 jruoho MinimumLength = 32;
408 1.1 jruoho break;
409 1.1 jruoho
410 1.1 jruoho case AML_FIELD_ACCESS_QWORD:
411 1.1 jruoho MinimumLength = 64;
412 1.1 jruoho break;
413 1.1 jruoho }
414 1.1 jruoho
415 1.1 jruoho PkgLengthNode->Asl.ExtraValue = MinimumLength;
416 1.1 jruoho break;
417 1.1 jruoho
418 1.1 jruoho default:
419 1.1.1.3 christos
420 1.1 jruoho /* All supported field opcodes must appear above */
421 1.1.1.3 christos
422 1.1 jruoho break;
423 1.1 jruoho }
424 1.1 jruoho
425 1.1 jruoho /* Move on to next entry in the field list */
426 1.1 jruoho
427 1.1 jruoho Next = Next->Asl.Next;
428 1.1 jruoho }
429 1.1 jruoho }
430 1.1 jruoho
431 1.1 jruoho
432 1.1 jruoho /*******************************************************************************
433 1.1 jruoho *
434 1.1 jruoho * FUNCTION: OpnDoField
435 1.1 jruoho *
436 1.1 jruoho * PARAMETERS: Op - The parent parse node
437 1.1 jruoho *
438 1.1 jruoho * RETURN: None
439 1.1 jruoho *
440 1.1 jruoho * DESCRIPTION: Construct the AML operands for the FIELD ASL keyword
441 1.1 jruoho *
442 1.1 jruoho ******************************************************************************/
443 1.1 jruoho
444 1.1 jruoho static void
445 1.1 jruoho OpnDoField (
446 1.1 jruoho ACPI_PARSE_OBJECT *Op)
447 1.1 jruoho {
448 1.1 jruoho ACPI_PARSE_OBJECT *Next;
449 1.1 jruoho
450 1.1 jruoho
451 1.1 jruoho /* Opcode is parent node */
452 1.1 jruoho /* First child is field name */
453 1.1 jruoho
454 1.1 jruoho Next = Op->Asl.Child;
455 1.1 jruoho
456 1.1 jruoho /* Second child is the AccessType */
457 1.1 jruoho
458 1.1 jruoho OpnDoFieldCommon (Op, Next->Asl.Next);
459 1.1 jruoho }
460 1.1 jruoho
461 1.1 jruoho
462 1.1 jruoho /*******************************************************************************
463 1.1 jruoho *
464 1.1 jruoho * FUNCTION: OpnDoIndexField
465 1.1 jruoho *
466 1.1 jruoho * PARAMETERS: Op - The parent parse node
467 1.1 jruoho *
468 1.1 jruoho * RETURN: None
469 1.1 jruoho *
470 1.1 jruoho * DESCRIPTION: Construct the AML operands for the INDEXFIELD ASL keyword
471 1.1 jruoho *
472 1.1 jruoho ******************************************************************************/
473 1.1 jruoho
474 1.1 jruoho static void
475 1.1 jruoho OpnDoIndexField (
476 1.1 jruoho ACPI_PARSE_OBJECT *Op)
477 1.1 jruoho {
478 1.1 jruoho ACPI_PARSE_OBJECT *Next;
479 1.1 jruoho
480 1.1 jruoho
481 1.1 jruoho /* Opcode is parent node */
482 1.1 jruoho /* First child is the index name */
483 1.1 jruoho
484 1.1 jruoho Next = Op->Asl.Child;
485 1.1 jruoho
486 1.1 jruoho /* Second child is the data name */
487 1.1 jruoho
488 1.1 jruoho Next = Next->Asl.Next;
489 1.1 jruoho
490 1.1 jruoho /* Third child is the AccessType */
491 1.1 jruoho
492 1.1 jruoho OpnDoFieldCommon (Op, Next->Asl.Next);
493 1.1 jruoho }
494 1.1 jruoho
495 1.1 jruoho
496 1.1 jruoho /*******************************************************************************
497 1.1 jruoho *
498 1.1 jruoho * FUNCTION: OpnDoBankField
499 1.1 jruoho *
500 1.1 jruoho * PARAMETERS: Op - The parent parse node
501 1.1 jruoho *
502 1.1 jruoho * RETURN: None
503 1.1 jruoho *
504 1.1 jruoho * DESCRIPTION: Construct the AML operands for the BANKFIELD ASL keyword
505 1.1 jruoho *
506 1.1 jruoho ******************************************************************************/
507 1.1 jruoho
508 1.1 jruoho static void
509 1.1 jruoho OpnDoBankField (
510 1.1 jruoho ACPI_PARSE_OBJECT *Op)
511 1.1 jruoho {
512 1.1 jruoho ACPI_PARSE_OBJECT *Next;
513 1.1 jruoho
514 1.1 jruoho
515 1.1 jruoho /* Opcode is parent node */
516 1.1 jruoho /* First child is the region name */
517 1.1 jruoho
518 1.1 jruoho Next = Op->Asl.Child;
519 1.1 jruoho
520 1.1 jruoho /* Second child is the bank name */
521 1.1 jruoho
522 1.1 jruoho Next = Next->Asl.Next;
523 1.1 jruoho
524 1.1 jruoho /* Third child is the bank value */
525 1.1 jruoho
526 1.1 jruoho Next = Next->Asl.Next;
527 1.1 jruoho
528 1.1 jruoho /* Fourth child is the AccessType */
529 1.1 jruoho
530 1.1 jruoho OpnDoFieldCommon (Op, Next->Asl.Next);
531 1.1 jruoho }
532 1.1 jruoho
533 1.1 jruoho
534 1.1 jruoho /*******************************************************************************
535 1.1 jruoho *
536 1.1 jruoho * FUNCTION: OpnDoRegion
537 1.1 jruoho *
538 1.1 jruoho * PARAMETERS: Op - The parent parse node
539 1.1 jruoho *
540 1.1 jruoho * RETURN: None
541 1.1 jruoho *
542 1.1.1.3 christos * DESCRIPTION: Tries to get the length of the region. Can only do this at
543 1.1 jruoho * compile time if the length is a constant.
544 1.1 jruoho *
545 1.1 jruoho ******************************************************************************/
546 1.1 jruoho
547 1.1 jruoho static void
548 1.1 jruoho OpnDoRegion (
549 1.1 jruoho ACPI_PARSE_OBJECT *Op)
550 1.1 jruoho {
551 1.1 jruoho ACPI_PARSE_OBJECT *Next;
552 1.1.1.16 christos ACPI_ADR_SPACE_TYPE SpaceId;
553 1.1 jruoho
554 1.1 jruoho
555 1.1 jruoho /* Opcode is parent node */
556 1.1 jruoho /* First child is the region name */
557 1.1 jruoho
558 1.1 jruoho Next = Op->Asl.Child;
559 1.1 jruoho
560 1.1.1.16 christos /* Second child is the space ID */
561 1.1 jruoho
562 1.1 jruoho Next = Next->Asl.Next;
563 1.1.1.16 christos SpaceId = (ACPI_ADR_SPACE_TYPE) Next->Common.Value.Integer;
564 1.1 jruoho
565 1.1 jruoho /* Third child is the region offset */
566 1.1 jruoho
567 1.1 jruoho Next = Next->Asl.Next;
568 1.1 jruoho
569 1.1 jruoho /* Fourth child is the region length */
570 1.1 jruoho
571 1.1 jruoho Next = Next->Asl.Next;
572 1.1 jruoho if (Next->Asl.ParseOpcode == PARSEOP_INTEGER)
573 1.1 jruoho {
574 1.1.1.16 christos /* Check for zero length */
575 1.1.1.16 christos
576 1.1 jruoho Op->Asl.Value.Integer = Next->Asl.Value.Integer;
577 1.1.1.16 christos if (!Op->Asl.Value.Integer && (SpaceId < ACPI_NUM_PREDEFINED_REGIONS))
578 1.1.1.16 christos {
579 1.1.1.16 christos AslError (ASL_ERROR, ASL_MSG_REGION_LENGTH, Op, NULL);
580 1.1.1.16 christos }
581 1.1 jruoho }
582 1.1 jruoho else
583 1.1 jruoho {
584 1.1 jruoho Op->Asl.Value.Integer = ACPI_UINT64_MAX;
585 1.1 jruoho }
586 1.1 jruoho }
587 1.1 jruoho
588 1.1 jruoho
589 1.1 jruoho /*******************************************************************************
590 1.1 jruoho *
591 1.1 jruoho * FUNCTION: OpnDoBuffer
592 1.1 jruoho *
593 1.1 jruoho * PARAMETERS: Op - The parent parse node
594 1.1 jruoho *
595 1.1 jruoho * RETURN: None
596 1.1 jruoho *
597 1.1.1.3 christos * DESCRIPTION: Construct the AML operands for the BUFFER ASL keyword. We
598 1.1 jruoho * build a single raw byte buffer from the initialization nodes,
599 1.1 jruoho * each parse node contains a buffer byte.
600 1.1 jruoho *
601 1.1 jruoho ******************************************************************************/
602 1.1 jruoho
603 1.1 jruoho static void
604 1.1 jruoho OpnDoBuffer (
605 1.1 jruoho ACPI_PARSE_OBJECT *Op)
606 1.1 jruoho {
607 1.1 jruoho ACPI_PARSE_OBJECT *InitializerOp;
608 1.1 jruoho ACPI_PARSE_OBJECT *BufferLengthOp;
609 1.1 jruoho
610 1.1 jruoho /* Optional arguments for this opcode with defaults */
611 1.1 jruoho
612 1.1 jruoho UINT32 BufferLength = 0;
613 1.1 jruoho
614 1.1 jruoho
615 1.1 jruoho /* Opcode and package length first */
616 1.1 jruoho /* Buffer Length is next, followed by the initializer list */
617 1.1 jruoho
618 1.1 jruoho BufferLengthOp = Op->Asl.Child;
619 1.1 jruoho InitializerOp = BufferLengthOp->Asl.Next;
620 1.1 jruoho
621 1.1 jruoho /*
622 1.1 jruoho * If the BufferLength is not an INTEGER or was not specified in the ASL
623 1.1 jruoho * (DEFAULT_ARG), it is a TermArg that is
624 1.1 jruoho * evaluated at run-time, and we are therefore finished.
625 1.1 jruoho */
626 1.1 jruoho if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) &&
627 1.1 jruoho (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
628 1.1 jruoho {
629 1.1 jruoho return;
630 1.1 jruoho }
631 1.1 jruoho
632 1.1 jruoho /*
633 1.1 jruoho * We want to count the number of items in the initializer list, because if
634 1.1 jruoho * it is larger than the buffer length, we will define the buffer size
635 1.1 jruoho * to be the size of the initializer list (as per the ACPI Specification)
636 1.1 jruoho */
637 1.1 jruoho switch (InitializerOp->Asl.ParseOpcode)
638 1.1 jruoho {
639 1.1 jruoho case PARSEOP_INTEGER:
640 1.1 jruoho case PARSEOP_BYTECONST:
641 1.1 jruoho case PARSEOP_WORDCONST:
642 1.1 jruoho case PARSEOP_DWORDCONST:
643 1.1 jruoho
644 1.1 jruoho /* The peer list contains the byte list (if any...) */
645 1.1 jruoho
646 1.1 jruoho while (InitializerOp)
647 1.1 jruoho {
648 1.1 jruoho /* For buffers, this is a list of raw bytes */
649 1.1 jruoho
650 1.1.1.7 christos InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
651 1.1.1.7 christos InitializerOp->Asl.AmlLength = 1;
652 1.1.1.7 christos InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
653 1.1 jruoho
654 1.1 jruoho BufferLength++;
655 1.1 jruoho InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
656 1.1 jruoho }
657 1.1 jruoho break;
658 1.1 jruoho
659 1.1 jruoho case PARSEOP_STRING_LITERAL:
660 1.1 jruoho
661 1.1 jruoho /*
662 1.1.1.3 christos * Only one initializer, the string. Buffer must be big enough to hold
663 1.1 jruoho * the string plus the null termination byte
664 1.1 jruoho */
665 1.1 jruoho BufferLength = strlen (InitializerOp->Asl.Value.String) + 1;
666 1.1 jruoho
667 1.1.1.7 christos InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
668 1.1.1.7 christos InitializerOp->Asl.AmlLength = BufferLength;
669 1.1.1.7 christos InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
670 1.1 jruoho break;
671 1.1 jruoho
672 1.1 jruoho case PARSEOP_RAW_DATA:
673 1.1 jruoho
674 1.1 jruoho /* Buffer nodes are already initialized (e.g. Unicode operator) */
675 1.1 jruoho return;
676 1.1 jruoho
677 1.1 jruoho case PARSEOP_DEFAULT_ARG:
678 1.1 jruoho break;
679 1.1 jruoho
680 1.1 jruoho default:
681 1.1.1.3 christos
682 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp,
683 1.1 jruoho "Unknown buffer initializer opcode");
684 1.1 jruoho printf ("Unknown buffer initializer opcode [%s]\n",
685 1.1.1.7 christos UtGetOpName (InitializerOp->Asl.ParseOpcode));
686 1.1 jruoho return;
687 1.1 jruoho }
688 1.1 jruoho
689 1.1 jruoho /* Check if initializer list is longer than the buffer length */
690 1.1 jruoho
691 1.1 jruoho if (BufferLengthOp->Asl.Value.Integer > BufferLength)
692 1.1 jruoho {
693 1.1 jruoho BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer;
694 1.1 jruoho }
695 1.1 jruoho
696 1.1 jruoho if (!BufferLength)
697 1.1 jruoho {
698 1.1 jruoho /* No length AND no items -- issue notice */
699 1.1 jruoho
700 1.1 jruoho AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL);
701 1.1 jruoho
702 1.1 jruoho /* But go ahead and put the buffer length of zero into the AML */
703 1.1 jruoho }
704 1.1 jruoho
705 1.1 jruoho /*
706 1.1 jruoho * Just set the buffer size node to be the buffer length, regardless
707 1.1 jruoho * of whether it was previously an integer or a default_arg placeholder
708 1.1 jruoho */
709 1.1.1.7 christos BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
710 1.1.1.7 christos BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
711 1.1 jruoho BufferLengthOp->Asl.Value.Integer = BufferLength;
712 1.1 jruoho
713 1.1 jruoho (void) OpcSetOptimalIntegerSize (BufferLengthOp);
714 1.1.1.17 christos UtSetParseOpName (BufferLengthOp);
715 1.1 jruoho
716 1.1 jruoho /* Remaining nodes are handled via the tree walk */
717 1.1 jruoho }
718 1.1 jruoho
719 1.1 jruoho
720 1.1 jruoho /*******************************************************************************
721 1.1 jruoho *
722 1.1 jruoho * FUNCTION: OpnDoPackage
723 1.1 jruoho *
724 1.1 jruoho * PARAMETERS: Op - The parent parse node
725 1.1 jruoho *
726 1.1 jruoho * RETURN: None
727 1.1 jruoho *
728 1.1.1.3 christos * DESCRIPTION: Construct the AML operands for the PACKAGE ASL keyword. NOTE:
729 1.1 jruoho * can only be called after constants have been folded, to ensure
730 1.1 jruoho * that the PackageLength operand has been fully reduced.
731 1.1 jruoho *
732 1.1 jruoho ******************************************************************************/
733 1.1 jruoho
734 1.1 jruoho void
735 1.1 jruoho OpnDoPackage (
736 1.1 jruoho ACPI_PARSE_OBJECT *Op)
737 1.1 jruoho {
738 1.1 jruoho ACPI_PARSE_OBJECT *InitializerOp;
739 1.1 jruoho ACPI_PARSE_OBJECT *PackageLengthOp;
740 1.1 jruoho UINT32 PackageLength = 0;
741 1.1 jruoho
742 1.1 jruoho
743 1.1 jruoho /* Opcode and package length first, followed by the initializer list */
744 1.1 jruoho
745 1.1 jruoho PackageLengthOp = Op->Asl.Child;
746 1.1 jruoho InitializerOp = PackageLengthOp->Asl.Next;
747 1.1 jruoho
748 1.1 jruoho /* Count the number of items in the initializer list */
749 1.1 jruoho
750 1.1 jruoho if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
751 1.1 jruoho {
752 1.1 jruoho /* The peer list contains the byte list (if any...) */
753 1.1 jruoho
754 1.1 jruoho while (InitializerOp)
755 1.1 jruoho {
756 1.1 jruoho PackageLength++;
757 1.1 jruoho InitializerOp = InitializerOp->Asl.Next;
758 1.1 jruoho }
759 1.1 jruoho }
760 1.1 jruoho
761 1.1 jruoho /* If package length is a constant, compare to the initializer list */
762 1.1 jruoho
763 1.1 jruoho if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
764 1.1 jruoho (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST))
765 1.1 jruoho {
766 1.1 jruoho if (PackageLengthOp->Asl.Value.Integer > PackageLength)
767 1.1 jruoho {
768 1.1 jruoho /*
769 1.1 jruoho * Allow package length to be longer than the initializer
770 1.1 jruoho * list -- but if the length of initializer list is nonzero,
771 1.1 jruoho * issue a message since this is probably a coding error,
772 1.1 jruoho * even though technically legal.
773 1.1 jruoho */
774 1.1 jruoho if (PackageLength > 0)
775 1.1 jruoho {
776 1.1 jruoho AslError (ASL_REMARK, ASL_MSG_LIST_LENGTH_SHORT,
777 1.1 jruoho PackageLengthOp, NULL);
778 1.1 jruoho }
779 1.1 jruoho
780 1.1 jruoho PackageLength = (UINT32) PackageLengthOp->Asl.Value.Integer;
781 1.1 jruoho }
782 1.1 jruoho else if (PackageLengthOp->Asl.Value.Integer < PackageLength)
783 1.1 jruoho {
784 1.1 jruoho /*
785 1.1 jruoho * The package length is smaller than the length of the
786 1.1 jruoho * initializer list. This is an error as per the ACPI spec.
787 1.1 jruoho */
788 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH_LONG,
789 1.1 jruoho PackageLengthOp, NULL);
790 1.1 jruoho }
791 1.1 jruoho }
792 1.1 jruoho
793 1.1 jruoho if (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
794 1.1 jruoho {
795 1.1 jruoho /*
796 1.1 jruoho * This is the case if the PackageLength was left empty - Package()
797 1.1 jruoho * The package length becomes the length of the initializer list
798 1.1 jruoho */
799 1.1 jruoho Op->Asl.Child->Asl.ParseOpcode = PARSEOP_INTEGER;
800 1.1 jruoho Op->Asl.Child->Asl.Value.Integer = PackageLength;
801 1.1.1.17 christos UtSetParseOpName (Op);
802 1.1 jruoho
803 1.1 jruoho /* Set the AML opcode */
804 1.1 jruoho
805 1.1 jruoho (void) OpcSetOptimalIntegerSize (Op->Asl.Child);
806 1.1 jruoho }
807 1.1 jruoho
808 1.1 jruoho /* If not a variable-length package, check for a zero package length */
809 1.1 jruoho
810 1.1 jruoho if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
811 1.1 jruoho (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST) ||
812 1.1.1.3 christos (PackageLengthOp->Asl.ParseOpcode == PARSEOP_ZERO) ||
813 1.1 jruoho (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG))
814 1.1 jruoho {
815 1.1 jruoho if (!PackageLength)
816 1.1 jruoho {
817 1.1 jruoho /* No length AND no initializer list -- issue a remark */
818 1.1 jruoho
819 1.1 jruoho AslError (ASL_REMARK, ASL_MSG_PACKAGE_LENGTH,
820 1.1 jruoho PackageLengthOp, NULL);
821 1.1 jruoho
822 1.1 jruoho /* But go ahead and put the buffer length of zero into the AML */
823 1.1 jruoho }
824 1.1 jruoho }
825 1.1 jruoho
826 1.1 jruoho /*
827 1.1 jruoho * If the PackageLength is a constant <= 255, we can change the
828 1.1 jruoho * AML opcode from VarPackage to a simple (ACPI 1.0) Package opcode.
829 1.1 jruoho */
830 1.1.1.3 christos if (((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
831 1.1.1.3 christos (Op->Asl.Child->Asl.Value.Integer <= 255)) ||
832 1.1.1.3 christos (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ONE) ||
833 1.1.1.3 christos (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ONES)||
834 1.1.1.3 christos (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ZERO))
835 1.1 jruoho {
836 1.1 jruoho Op->Asl.AmlOpcode = AML_PACKAGE_OP;
837 1.1 jruoho Op->Asl.ParseOpcode = PARSEOP_PACKAGE;
838 1.1 jruoho
839 1.1 jruoho /*
840 1.1 jruoho * Just set the package size node to be the package length, regardless
841 1.1 jruoho * of whether it was previously an integer or a default_arg placeholder
842 1.1 jruoho */
843 1.1 jruoho PackageLengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
844 1.1 jruoho PackageLengthOp->Asl.AmlLength = 1;
845 1.1 jruoho PackageLengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
846 1.1 jruoho PackageLengthOp->Asl.Value.Integer = PackageLength;
847 1.1 jruoho }
848 1.1 jruoho
849 1.1 jruoho /* Remaining nodes are handled via the tree walk */
850 1.1 jruoho }
851 1.1 jruoho
852 1.1 jruoho
853 1.1 jruoho /*******************************************************************************
854 1.1 jruoho *
855 1.1 jruoho * FUNCTION: OpnDoLoadTable
856 1.1 jruoho *
857 1.1 jruoho * PARAMETERS: Op - The parent parse node
858 1.1 jruoho *
859 1.1 jruoho * RETURN: None
860 1.1 jruoho *
861 1.1 jruoho * DESCRIPTION: Construct the AML operands for the LOADTABLE ASL keyword.
862 1.1 jruoho *
863 1.1 jruoho ******************************************************************************/
864 1.1 jruoho
865 1.1 jruoho static void
866 1.1 jruoho OpnDoLoadTable (
867 1.1 jruoho ACPI_PARSE_OBJECT *Op)
868 1.1 jruoho {
869 1.1 jruoho ACPI_PARSE_OBJECT *Next;
870 1.1 jruoho
871 1.1 jruoho
872 1.1 jruoho /* Opcode is parent node */
873 1.1 jruoho /* First child is the table signature */
874 1.1 jruoho
875 1.1 jruoho Next = Op->Asl.Child;
876 1.1 jruoho
877 1.1 jruoho /* Second child is the OEM ID*/
878 1.1 jruoho
879 1.1 jruoho Next = Next->Asl.Next;
880 1.1 jruoho
881 1.1 jruoho /* Third child is the OEM table ID */
882 1.1 jruoho
883 1.1 jruoho Next = Next->Asl.Next;
884 1.1 jruoho
885 1.1 jruoho /* Fourth child is the RootPath string */
886 1.1 jruoho
887 1.1 jruoho Next = Next->Asl.Next;
888 1.1 jruoho if (Next->Asl.ParseOpcode == PARSEOP_ZERO)
889 1.1 jruoho {
890 1.1.1.7 christos Next->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
891 1.1.1.7 christos Next->Asl.Value.String = "\\";
892 1.1.1.7 christos Next->Asl.AmlLength = 2;
893 1.1 jruoho OpcGenerateAmlOpcode (Next);
894 1.1 jruoho }
895 1.1 jruoho
896 1.1 jruoho #ifdef ASL_FUTURE_IMPLEMENTATION
897 1.1 jruoho
898 1.1 jruoho /* TBD: NOT IMPLEMENTED */
899 1.1 jruoho /* Fifth child is the [optional] ParameterPathString */
900 1.1 jruoho /* Sixth child is the [optional] ParameterData */
901 1.1 jruoho
902 1.1 jruoho Next = Next->Asl.Next;
903 1.1 jruoho if (Next->Asl.ParseOpcode == DEFAULT_ARG)
904 1.1 jruoho {
905 1.1 jruoho Next->Asl.AmlLength = 1;
906 1.1 jruoho Next->Asl.ParseOpcode = ZERO;
907 1.1 jruoho OpcGenerateAmlOpcode (Next);
908 1.1 jruoho }
909 1.1 jruoho
910 1.1 jruoho
911 1.1 jruoho Next = Next->Asl.Next;
912 1.1 jruoho if (Next->Asl.ParseOpcode == DEFAULT_ARG)
913 1.1 jruoho {
914 1.1 jruoho Next->Asl.AmlLength = 1;
915 1.1 jruoho Next->Asl.ParseOpcode = ZERO;
916 1.1 jruoho OpcGenerateAmlOpcode (Next);
917 1.1 jruoho }
918 1.1 jruoho #endif
919 1.1 jruoho }
920 1.1 jruoho
921 1.1 jruoho
922 1.1 jruoho /*******************************************************************************
923 1.1 jruoho *
924 1.1 jruoho * FUNCTION: OpnDoDefinitionBlock
925 1.1 jruoho *
926 1.1 jruoho * PARAMETERS: Op - The parent parse node
927 1.1 jruoho *
928 1.1 jruoho * RETURN: None
929 1.1 jruoho *
930 1.1 jruoho * DESCRIPTION: Construct the AML operands for the DEFINITIONBLOCK ASL keyword
931 1.1 jruoho *
932 1.1 jruoho ******************************************************************************/
933 1.1 jruoho
934 1.1 jruoho static void
935 1.1 jruoho OpnDoDefinitionBlock (
936 1.1 jruoho ACPI_PARSE_OBJECT *Op)
937 1.1 jruoho {
938 1.1 jruoho ACPI_PARSE_OBJECT *Child;
939 1.1 jruoho ACPI_SIZE Length;
940 1.1 jruoho UINT32 i;
941 1.1 jruoho char *Filename;
942 1.1.1.16 christos ACPI_STATUS Status;
943 1.1 jruoho
944 1.1 jruoho
945 1.1 jruoho /*
946 1.1.1.3 christos * These nodes get stuffed into the table header. They are special
947 1.1 jruoho * cased when the table is written to the output file.
948 1.1 jruoho *
949 1.1 jruoho * Mark all of these nodes as non-usable so they won't get output
950 1.1 jruoho * as AML opcodes!
951 1.1 jruoho */
952 1.1 jruoho
953 1.1 jruoho /* Get AML filename. Use it if non-null */
954 1.1 jruoho
955 1.1 jruoho Child = Op->Asl.Child;
956 1.1 jruoho if (Child->Asl.Value.Buffer &&
957 1.1 jruoho *Child->Asl.Value.Buffer &&
958 1.1.1.15 christos (AslGbl_UseDefaultAmlFilename))
959 1.1 jruoho {
960 1.1 jruoho /*
961 1.1.1.16 christos * The walk may traverse multiple definition blocks. Switch files
962 1.1.1.16 christos * to ensure that the correct files are manipulated.
963 1.1.1.16 christos */
964 1.1.1.16 christos FlSwitchFileSet (Op->Asl.Filename);
965 1.1.1.16 christos
966 1.1.1.16 christos /*
967 1.1 jruoho * We will use the AML filename that is embedded in the source file
968 1.1 jruoho * for the output filename.
969 1.1 jruoho */
970 1.1.1.15 christos Filename = UtLocalCacheCalloc (strlen (AslGbl_DirectoryPath) +
971 1.1.1.4 christos strlen ((char *) Child->Asl.Value.Buffer) + 1);
972 1.1 jruoho
973 1.1 jruoho /* Prepend the current directory path */
974 1.1 jruoho
975 1.1.1.15 christos strcpy (Filename, AslGbl_DirectoryPath);
976 1.1 jruoho strcat (Filename, (char *) Child->Asl.Value.Buffer);
977 1.1 jruoho
978 1.1.1.15 christos AslGbl_OutputFilenamePrefix = Filename;
979 1.1.1.15 christos UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
980 1.1.1.16 christos
981 1.1.1.16 christos /*
982 1.1.1.16 christos * Use the definition block file parameter instead of the input
983 1.1.1.16 christos * filename. Since all files were opened previously, remove the
984 1.1.1.16 christos * existing file and open a new file with the name of this
985 1.1.1.16 christos * definiton block parameter. Since AML code generation has yet
986 1.1.1.16 christos * to happen, the previous file can be removed without any impacts.
987 1.1.1.16 christos */
988 1.1.1.16 christos FlCloseFile (ASL_FILE_AML_OUTPUT);
989 1.1.1.16 christos FlDeleteFile (ASL_FILE_AML_OUTPUT);
990 1.1.1.16 christos Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
991 1.1.1.16 christos if (ACPI_FAILURE (Status))
992 1.1.1.16 christos {
993 1.1.1.16 christos AslError (ASL_ERROR, ASL_MSG_OUTPUT_FILE_OPEN, NULL, NULL);
994 1.1.1.16 christos return;
995 1.1.1.16 christos }
996 1.1 jruoho }
997 1.1.1.7 christos
998 1.1 jruoho Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
999 1.1 jruoho
1000 1.1 jruoho /* Signature */
1001 1.1 jruoho
1002 1.1 jruoho Child = Child->Asl.Next;
1003 1.1 jruoho Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1004 1.1 jruoho if (Child->Asl.Value.String)
1005 1.1 jruoho {
1006 1.1.1.16 christos AslGbl_FilesList->TableSignature = Child->Asl.Value.String;
1007 1.1.1.15 christos AslGbl_TableSignature = Child->Asl.Value.String;
1008 1.1.1.16 christos if (strlen (AslGbl_TableSignature) != ACPI_NAMESEG_SIZE)
1009 1.1 jruoho {
1010 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
1011 1.1.1.14 christos "Length must be exactly 4 characters");
1012 1.1 jruoho }
1013 1.1 jruoho
1014 1.1.1.16 christos for (i = 0; i < ACPI_NAMESEG_SIZE; i++)
1015 1.1 jruoho {
1016 1.1.1.15 christos if (!isalnum ((int) AslGbl_TableSignature[i]))
1017 1.1 jruoho {
1018 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
1019 1.1 jruoho "Contains non-alphanumeric characters");
1020 1.1 jruoho }
1021 1.1 jruoho }
1022 1.1 jruoho }
1023 1.1 jruoho
1024 1.1 jruoho /* Revision */
1025 1.1 jruoho
1026 1.1 jruoho Child = Child->Asl.Next;
1027 1.1 jruoho Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1028 1.1.1.14 christos
1029 1.1 jruoho /*
1030 1.1 jruoho * We used the revision to set the integer width earlier
1031 1.1 jruoho */
1032 1.1 jruoho
1033 1.1 jruoho /* OEMID */
1034 1.1 jruoho
1035 1.1 jruoho Child = Child->Asl.Next;
1036 1.1 jruoho Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1037 1.1.1.14 christos if (Child->Asl.Value.String &&
1038 1.1.1.14 christos strlen (Child->Asl.Value.String) > ACPI_OEM_ID_SIZE)
1039 1.1.1.14 christos {
1040 1.1.1.14 christos AslError (ASL_ERROR, ASL_MSG_OEM_ID, Child,
1041 1.1.1.14 christos "Length cannot exceed 6 characters");
1042 1.1.1.14 christos }
1043 1.1 jruoho
1044 1.1 jruoho /* OEM TableID */
1045 1.1 jruoho
1046 1.1 jruoho Child = Child->Asl.Next;
1047 1.1 jruoho Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1048 1.1 jruoho if (Child->Asl.Value.String)
1049 1.1 jruoho {
1050 1.1.1.6 christos Length = strlen (Child->Asl.Value.String);
1051 1.1.1.14 christos if (Length > ACPI_OEM_TABLE_ID_SIZE)
1052 1.1.1.14 christos {
1053 1.1.1.14 christos AslError (ASL_ERROR, ASL_MSG_OEM_TABLE_ID, Child,
1054 1.1.1.14 christos "Length cannot exceed 8 characters");
1055 1.1.1.14 christos }
1056 1.1.1.14 christos
1057 1.1.1.15 christos AslGbl_TableId = UtLocalCacheCalloc (Length + 1);
1058 1.1.1.15 christos strcpy (AslGbl_TableId, Child->Asl.Value.String);
1059 1.1.1.16 christos AslGbl_FilesList->TableId = AslGbl_TableId;
1060 1.1 jruoho
1061 1.1.1.3 christos /*
1062 1.1.1.3 christos * Convert anything non-alphanumeric to an underscore. This
1063 1.1.1.3 christos * allows us to use the TableID to generate unique C symbols.
1064 1.1.1.3 christos */
1065 1.1 jruoho for (i = 0; i < Length; i++)
1066 1.1 jruoho {
1067 1.1.1.15 christos if (!isalnum ((int) AslGbl_TableId[i]))
1068 1.1 jruoho {
1069 1.1.1.15 christos AslGbl_TableId[i] = '_';
1070 1.1 jruoho }
1071 1.1 jruoho }
1072 1.1 jruoho }
1073 1.1 jruoho
1074 1.1 jruoho /* OEM Revision */
1075 1.1 jruoho
1076 1.1 jruoho Child = Child->Asl.Next;
1077 1.1 jruoho Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1078 1.1 jruoho }
1079 1.1 jruoho
1080 1.1 jruoho
1081 1.1 jruoho /*******************************************************************************
1082 1.1 jruoho *
1083 1.1 jruoho * FUNCTION: UtGetArg
1084 1.1 jruoho *
1085 1.1 jruoho * PARAMETERS: Op - Get an argument for this op
1086 1.1 jruoho * Argn - Nth argument to get
1087 1.1 jruoho *
1088 1.1.1.3 christos * RETURN: The argument (as an Op object). NULL if argument does not exist
1089 1.1 jruoho *
1090 1.1 jruoho * DESCRIPTION: Get the specified op's argument (peer)
1091 1.1 jruoho *
1092 1.1 jruoho ******************************************************************************/
1093 1.1 jruoho
1094 1.1 jruoho ACPI_PARSE_OBJECT *
1095 1.1 jruoho UtGetArg (
1096 1.1 jruoho ACPI_PARSE_OBJECT *Op,
1097 1.1 jruoho UINT32 Argn)
1098 1.1 jruoho {
1099 1.1 jruoho ACPI_PARSE_OBJECT *Arg = NULL;
1100 1.1 jruoho
1101 1.1 jruoho
1102 1.1 jruoho /* Get the requested argument object */
1103 1.1 jruoho
1104 1.1 jruoho Arg = Op->Asl.Child;
1105 1.1 jruoho while (Arg && Argn)
1106 1.1 jruoho {
1107 1.1 jruoho Argn--;
1108 1.1 jruoho Arg = Arg->Asl.Next;
1109 1.1 jruoho }
1110 1.1 jruoho
1111 1.1 jruoho return (Arg);
1112 1.1 jruoho }
1113 1.1 jruoho
1114 1.1 jruoho
1115 1.1 jruoho /*******************************************************************************
1116 1.1 jruoho *
1117 1.1 jruoho * FUNCTION: OpnAttachNameToNode
1118 1.1 jruoho *
1119 1.1 jruoho * PARAMETERS: Op - The parent parse node
1120 1.1 jruoho *
1121 1.1 jruoho * RETURN: None
1122 1.1 jruoho *
1123 1.1 jruoho * DESCRIPTION: For the named ASL/AML operators, get the actual name from the
1124 1.1 jruoho * argument list and attach it to the parent node so that we
1125 1.1 jruoho * can get to it quickly later.
1126 1.1 jruoho *
1127 1.1 jruoho ******************************************************************************/
1128 1.1 jruoho
1129 1.1 jruoho static void
1130 1.1 jruoho OpnAttachNameToNode (
1131 1.1 jruoho ACPI_PARSE_OBJECT *Op)
1132 1.1 jruoho {
1133 1.1 jruoho ACPI_PARSE_OBJECT *Child = NULL;
1134 1.1 jruoho
1135 1.1 jruoho
1136 1.1.1.8 christos switch (Op->Asl.AmlOpcode)
1137 1.1 jruoho {
1138 1.1 jruoho case AML_DATA_REGION_OP:
1139 1.1 jruoho case AML_DEVICE_OP:
1140 1.1 jruoho case AML_EVENT_OP:
1141 1.1.1.8 christos case AML_EXTERNAL_OP:
1142 1.1 jruoho case AML_METHOD_OP:
1143 1.1 jruoho case AML_MUTEX_OP:
1144 1.1 jruoho case AML_REGION_OP:
1145 1.1.1.11 christos case AML_POWER_RESOURCE_OP:
1146 1.1 jruoho case AML_PROCESSOR_OP:
1147 1.1 jruoho case AML_THERMAL_ZONE_OP:
1148 1.1 jruoho case AML_NAME_OP:
1149 1.1 jruoho case AML_SCOPE_OP:
1150 1.1 jruoho
1151 1.1 jruoho Child = UtGetArg (Op, 0);
1152 1.1 jruoho break;
1153 1.1 jruoho
1154 1.1 jruoho case AML_ALIAS_OP:
1155 1.1 jruoho
1156 1.1 jruoho Child = UtGetArg (Op, 1);
1157 1.1 jruoho break;
1158 1.1 jruoho
1159 1.1 jruoho case AML_CREATE_BIT_FIELD_OP:
1160 1.1 jruoho case AML_CREATE_BYTE_FIELD_OP:
1161 1.1 jruoho case AML_CREATE_WORD_FIELD_OP:
1162 1.1 jruoho case AML_CREATE_DWORD_FIELD_OP:
1163 1.1 jruoho case AML_CREATE_QWORD_FIELD_OP:
1164 1.1 jruoho
1165 1.1 jruoho Child = UtGetArg (Op, 2);
1166 1.1 jruoho break;
1167 1.1 jruoho
1168 1.1 jruoho case AML_CREATE_FIELD_OP:
1169 1.1 jruoho
1170 1.1 jruoho Child = UtGetArg (Op, 3);
1171 1.1 jruoho break;
1172 1.1 jruoho
1173 1.1 jruoho case AML_BANK_FIELD_OP:
1174 1.1 jruoho case AML_INDEX_FIELD_OP:
1175 1.1 jruoho case AML_FIELD_OP:
1176 1.1 jruoho
1177 1.1 jruoho return;
1178 1.1 jruoho
1179 1.1 jruoho default:
1180 1.1.1.3 christos
1181 1.1 jruoho return;
1182 1.1 jruoho }
1183 1.1 jruoho
1184 1.1 jruoho if (Child)
1185 1.1 jruoho {
1186 1.1 jruoho UtAttachNamepathToOwner (Op, Child);
1187 1.1 jruoho }
1188 1.1 jruoho }
1189 1.1 jruoho
1190 1.1 jruoho
1191 1.1 jruoho /*******************************************************************************
1192 1.1 jruoho *
1193 1.1 jruoho * FUNCTION: OpnGenerateAmlOperands
1194 1.1 jruoho *
1195 1.1 jruoho * PARAMETERS: Op - The parent parse node
1196 1.1 jruoho *
1197 1.1 jruoho * RETURN: None
1198 1.1 jruoho *
1199 1.1.1.3 christos * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
1200 1.1 jruoho * complex AML opcodes require processing of the child nodes
1201 1.1 jruoho * (arguments/operands).
1202 1.1 jruoho *
1203 1.1 jruoho ******************************************************************************/
1204 1.1 jruoho
1205 1.1 jruoho void
1206 1.1 jruoho OpnGenerateAmlOperands (
1207 1.1 jruoho ACPI_PARSE_OBJECT *Op)
1208 1.1 jruoho {
1209 1.1 jruoho
1210 1.1 jruoho
1211 1.1 jruoho if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
1212 1.1 jruoho {
1213 1.1 jruoho return;
1214 1.1 jruoho }
1215 1.1 jruoho
1216 1.1 jruoho switch (Op->Asl.ParseOpcode)
1217 1.1 jruoho {
1218 1.1.1.7 christos case PARSEOP_DEFINITION_BLOCK:
1219 1.1.1.3 christos
1220 1.1 jruoho OpnDoDefinitionBlock (Op);
1221 1.1 jruoho break;
1222 1.1 jruoho
1223 1.1 jruoho case PARSEOP_METHOD:
1224 1.1.1.3 christos
1225 1.1 jruoho OpnDoMethod (Op);
1226 1.1 jruoho break;
1227 1.1 jruoho
1228 1.1 jruoho case PARSEOP_MUTEX:
1229 1.1.1.3 christos
1230 1.1 jruoho OpnDoMutex (Op);
1231 1.1 jruoho break;
1232 1.1 jruoho
1233 1.1 jruoho case PARSEOP_FIELD:
1234 1.1.1.3 christos
1235 1.1 jruoho OpnDoField (Op);
1236 1.1 jruoho break;
1237 1.1 jruoho
1238 1.1 jruoho case PARSEOP_INDEXFIELD:
1239 1.1.1.3 christos
1240 1.1 jruoho OpnDoIndexField (Op);
1241 1.1 jruoho break;
1242 1.1 jruoho
1243 1.1 jruoho case PARSEOP_BANKFIELD:
1244 1.1.1.3 christos
1245 1.1 jruoho OpnDoBankField (Op);
1246 1.1 jruoho break;
1247 1.1 jruoho
1248 1.1 jruoho case PARSEOP_BUFFER:
1249 1.1.1.3 christos
1250 1.1 jruoho OpnDoBuffer (Op);
1251 1.1 jruoho break;
1252 1.1 jruoho
1253 1.1 jruoho case PARSEOP_LOADTABLE:
1254 1.1.1.3 christos
1255 1.1 jruoho OpnDoLoadTable (Op);
1256 1.1 jruoho break;
1257 1.1 jruoho
1258 1.1 jruoho case PARSEOP_OPERATIONREGION:
1259 1.1.1.3 christos
1260 1.1 jruoho OpnDoRegion (Op);
1261 1.1 jruoho break;
1262 1.1 jruoho
1263 1.1 jruoho case PARSEOP_RESOURCETEMPLATE:
1264 1.1.1.3 christos
1265 1.1 jruoho RsDoResourceTemplate (Op);
1266 1.1 jruoho break;
1267 1.1 jruoho
1268 1.1 jruoho case PARSEOP_NAMESEG:
1269 1.1 jruoho case PARSEOP_NAMESTRING:
1270 1.1 jruoho case PARSEOP_METHODCALL:
1271 1.1 jruoho case PARSEOP_STRING_LITERAL:
1272 1.1 jruoho default:
1273 1.1.1.3 christos
1274 1.1 jruoho break;
1275 1.1 jruoho }
1276 1.1 jruoho
1277 1.1 jruoho /* TBD: move */
1278 1.1 jruoho
1279 1.1 jruoho OpnAttachNameToNode (Op);
1280 1.1 jruoho }
1281