dtfield.c revision 1.9 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dtfield.c - Code generation for individual source fields
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.2 christos /*
8 1.8 christos * Copyright (C) 2000 - 2017, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.2 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho #include "dtcompiler.h"
46 1.1 jruoho
47 1.1 jruoho #define _COMPONENT DT_COMPILER
48 1.1 jruoho ACPI_MODULE_NAME ("dtfield")
49 1.1 jruoho
50 1.1 jruoho
51 1.1 jruoho /* Local prototypes */
52 1.1 jruoho
53 1.1 jruoho static void
54 1.1 jruoho DtCompileString (
55 1.1 jruoho UINT8 *Buffer,
56 1.1 jruoho DT_FIELD *Field,
57 1.1 jruoho UINT32 ByteLength);
58 1.1 jruoho
59 1.2 christos static void
60 1.2 christos DtCompileUnicode (
61 1.2 christos UINT8 *Buffer,
62 1.2 christos DT_FIELD *Field,
63 1.2 christos UINT32 ByteLength);
64 1.1 jruoho
65 1.2 christos static ACPI_STATUS
66 1.2 christos DtCompileUuid (
67 1.1 jruoho UINT8 *Buffer,
68 1.1 jruoho DT_FIELD *Field,
69 1.1 jruoho UINT32 ByteLength);
70 1.1 jruoho
71 1.2 christos static char *
72 1.2 christos DtNormalizeBuffer (
73 1.2 christos char *Buffer,
74 1.2 christos UINT32 *Count);
75 1.2 christos
76 1.1 jruoho
77 1.1 jruoho /******************************************************************************
78 1.1 jruoho *
79 1.1 jruoho * FUNCTION: DtCompileOneField
80 1.1 jruoho *
81 1.1 jruoho * PARAMETERS: Buffer - Output buffer
82 1.1 jruoho * Field - Field to be compiled
83 1.1 jruoho * ByteLength - Byte length of the field
84 1.1 jruoho * Type - Field type
85 1.1 jruoho *
86 1.1 jruoho * RETURN: None
87 1.1 jruoho *
88 1.1 jruoho * DESCRIPTION: Compile a field value to binary
89 1.1 jruoho *
90 1.1 jruoho *****************************************************************************/
91 1.1 jruoho
92 1.1 jruoho void
93 1.1 jruoho DtCompileOneField (
94 1.1 jruoho UINT8 *Buffer,
95 1.1 jruoho DT_FIELD *Field,
96 1.1 jruoho UINT32 ByteLength,
97 1.1 jruoho UINT8 Type,
98 1.1 jruoho UINT8 Flags)
99 1.1 jruoho {
100 1.2 christos ACPI_STATUS Status;
101 1.1 jruoho
102 1.6 christos
103 1.1 jruoho switch (Type)
104 1.1 jruoho {
105 1.1 jruoho case DT_FIELD_TYPE_INTEGER:
106 1.2 christos
107 1.1 jruoho DtCompileInteger (Buffer, Field, ByteLength, Flags);
108 1.1 jruoho break;
109 1.1 jruoho
110 1.1 jruoho case DT_FIELD_TYPE_STRING:
111 1.2 christos
112 1.1 jruoho DtCompileString (Buffer, Field, ByteLength);
113 1.1 jruoho break;
114 1.1 jruoho
115 1.2 christos case DT_FIELD_TYPE_UUID:
116 1.2 christos
117 1.2 christos Status = DtCompileUuid (Buffer, Field, ByteLength);
118 1.2 christos if (ACPI_SUCCESS (Status))
119 1.2 christos {
120 1.2 christos break;
121 1.2 christos }
122 1.2 christos
123 1.2 christos /* Fall through. */
124 1.2 christos
125 1.1 jruoho case DT_FIELD_TYPE_BUFFER:
126 1.2 christos
127 1.1 jruoho DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
128 1.1 jruoho break;
129 1.1 jruoho
130 1.2 christos case DT_FIELD_TYPE_UNICODE:
131 1.2 christos
132 1.2 christos DtCompileUnicode (Buffer, Field, ByteLength);
133 1.2 christos break;
134 1.2 christos
135 1.2 christos case DT_FIELD_TYPE_DEVICE_PATH:
136 1.2 christos
137 1.1 jruoho break;
138 1.1 jruoho
139 1.1 jruoho default:
140 1.2 christos
141 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type");
142 1.1 jruoho break;
143 1.1 jruoho }
144 1.1 jruoho }
145 1.1 jruoho
146 1.1 jruoho
147 1.1 jruoho /******************************************************************************
148 1.1 jruoho *
149 1.1 jruoho * FUNCTION: DtCompileString
150 1.1 jruoho *
151 1.1 jruoho * PARAMETERS: Buffer - Output buffer
152 1.1 jruoho * Field - String to be copied to buffer
153 1.1 jruoho * ByteLength - Maximum length of string
154 1.1 jruoho *
155 1.1 jruoho * RETURN: None
156 1.1 jruoho *
157 1.1 jruoho * DESCRIPTION: Copy string to the buffer
158 1.1 jruoho *
159 1.1 jruoho *****************************************************************************/
160 1.1 jruoho
161 1.1 jruoho static void
162 1.1 jruoho DtCompileString (
163 1.1 jruoho UINT8 *Buffer,
164 1.1 jruoho DT_FIELD *Field,
165 1.1 jruoho UINT32 ByteLength)
166 1.1 jruoho {
167 1.1 jruoho UINT32 Length;
168 1.1 jruoho
169 1.1 jruoho
170 1.5 christos Length = strlen (Field->Value);
171 1.1 jruoho
172 1.1 jruoho /* Check if the string is too long for the field */
173 1.1 jruoho
174 1.1 jruoho if (Length > ByteLength)
175 1.1 jruoho {
176 1.2 christos snprintf (MsgBuffer, sizeof(MsgBuffer), "Maximum %u characters", ByteLength);
177 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
178 1.1 jruoho Length = ByteLength;
179 1.1 jruoho }
180 1.1 jruoho
181 1.5 christos memcpy (Buffer, Field->Value, Length);
182 1.2 christos }
183 1.2 christos
184 1.2 christos
185 1.2 christos /******************************************************************************
186 1.2 christos *
187 1.2 christos * FUNCTION: DtCompileUnicode
188 1.2 christos *
189 1.2 christos * PARAMETERS: Buffer - Output buffer
190 1.2 christos * Field - String to be copied to buffer
191 1.2 christos * ByteLength - Maximum length of string
192 1.2 christos *
193 1.2 christos * RETURN: None
194 1.2 christos *
195 1.2 christos * DESCRIPTION: Convert ASCII string to Unicode string
196 1.2 christos *
197 1.2 christos * Note: The Unicode string is 16 bits per character, no leading signature,
198 1.2 christos * with a 16-bit terminating NULL.
199 1.2 christos *
200 1.2 christos *****************************************************************************/
201 1.2 christos
202 1.2 christos static void
203 1.2 christos DtCompileUnicode (
204 1.2 christos UINT8 *Buffer,
205 1.2 christos DT_FIELD *Field,
206 1.2 christos UINT32 ByteLength)
207 1.2 christos {
208 1.2 christos UINT32 Count;
209 1.2 christos UINT32 i;
210 1.2 christos char *AsciiString;
211 1.2 christos UINT16 *UnicodeString;
212 1.2 christos
213 1.2 christos
214 1.2 christos AsciiString = Field->Value;
215 1.2 christos UnicodeString = (UINT16 *) Buffer;
216 1.5 christos Count = strlen (AsciiString) + 1;
217 1.2 christos
218 1.2 christos /* Convert to Unicode string (including null terminator) */
219 1.2 christos
220 1.2 christos for (i = 0; i < Count; i++)
221 1.2 christos {
222 1.2 christos UnicodeString[i] = (UINT16) AsciiString[i];
223 1.2 christos }
224 1.2 christos }
225 1.2 christos
226 1.2 christos
227 1.2 christos /*******************************************************************************
228 1.2 christos *
229 1.2 christos * FUNCTION: DtCompileUuid
230 1.2 christos *
231 1.2 christos * PARAMETERS: Buffer - Output buffer
232 1.2 christos * Field - String to be copied to buffer
233 1.2 christos * ByteLength - Maximum length of string
234 1.2 christos *
235 1.2 christos * RETURN: None
236 1.2 christos *
237 1.2 christos * DESCRIPTION: Convert UUID string to 16-byte buffer
238 1.2 christos *
239 1.2 christos ******************************************************************************/
240 1.2 christos
241 1.2 christos static ACPI_STATUS
242 1.2 christos DtCompileUuid (
243 1.2 christos UINT8 *Buffer,
244 1.2 christos DT_FIELD *Field,
245 1.2 christos UINT32 ByteLength)
246 1.2 christos {
247 1.2 christos char *InString;
248 1.2 christos ACPI_STATUS Status;
249 1.2 christos
250 1.2 christos
251 1.2 christos InString = Field->Value;
252 1.1 jruoho
253 1.2 christos Status = AuValidateUuid (InString);
254 1.2 christos if (ACPI_FAILURE (Status))
255 1.2 christos {
256 1.2 christos snprintf (MsgBuffer, sizeof(MsgBuffer), "%s", Field->Value);
257 1.2 christos DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer);
258 1.2 christos }
259 1.2 christos else
260 1.2 christos {
261 1.3 christos AcpiUtConvertStringToUuid (InString, Buffer);
262 1.2 christos }
263 1.2 christos
264 1.2 christos return (Status);
265 1.1 jruoho }
266 1.1 jruoho
267 1.1 jruoho
268 1.1 jruoho /******************************************************************************
269 1.1 jruoho *
270 1.1 jruoho * FUNCTION: DtCompileInteger
271 1.1 jruoho *
272 1.1 jruoho * PARAMETERS: Buffer - Output buffer
273 1.1 jruoho * Field - Field obj with Integer to be compiled
274 1.1 jruoho * ByteLength - Byte length of the integer
275 1.2 christos * Flags - Additional compile info
276 1.1 jruoho *
277 1.1 jruoho * RETURN: None
278 1.1 jruoho *
279 1.2 christos * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
280 1.2 christos * operators.
281 1.1 jruoho *
282 1.1 jruoho *****************************************************************************/
283 1.1 jruoho
284 1.1 jruoho void
285 1.1 jruoho DtCompileInteger (
286 1.1 jruoho UINT8 *Buffer,
287 1.1 jruoho DT_FIELD *Field,
288 1.1 jruoho UINT32 ByteLength,
289 1.1 jruoho UINT8 Flags)
290 1.1 jruoho {
291 1.2 christos UINT64 Value;
292 1.1 jruoho UINT64 MaxValue;
293 1.1 jruoho ACPI_STATUS Status;
294 1.1 jruoho
295 1.1 jruoho
296 1.2 christos /* Output buffer byte length must be in range 1-8 */
297 1.1 jruoho
298 1.1 jruoho if ((ByteLength > 8) || (ByteLength == 0))
299 1.1 jruoho {
300 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
301 1.1 jruoho "Invalid internal Byte length");
302 1.1 jruoho return;
303 1.1 jruoho }
304 1.1 jruoho
305 1.2 christos /* Resolve integer expression to a single integer value */
306 1.1 jruoho
307 1.2 christos Status = DtResolveIntegerExpression (Field, &Value);
308 1.1 jruoho if (ACPI_FAILURE (Status))
309 1.1 jruoho {
310 1.2 christos return;
311 1.1 jruoho }
312 1.1 jruoho
313 1.3 christos /*
314 1.3 christos * Ensure that reserved fields are set properly. Note: uses
315 1.3 christos * the DT_NON_ZERO flag to indicate that the reserved value
316 1.3 christos * must be exactly one. Otherwise, the value must be zero.
317 1.3 christos * This is sufficient for now.
318 1.3 christos */
319 1.3 christos
320 1.3 christos /* TBD: Should use a flag rather than compare "Reserved" */
321 1.1 jruoho
322 1.5 christos if (!strcmp (Field->Name, "Reserved"))
323 1.1 jruoho {
324 1.3 christos if (Flags & DT_NON_ZERO)
325 1.3 christos {
326 1.3 christos if (Value != 1)
327 1.3 christos {
328 1.3 christos DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
329 1.3 christos "Must be one, setting to one");
330 1.3 christos Value = 1;
331 1.3 christos }
332 1.3 christos }
333 1.3 christos else if (Value != 0)
334 1.3 christos {
335 1.3 christos DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
336 1.3 christos "Must be zero, setting to zero");
337 1.3 christos Value = 0;
338 1.3 christos }
339 1.1 jruoho }
340 1.1 jruoho
341 1.1 jruoho /* Check if the value must be non-zero */
342 1.1 jruoho
343 1.3 christos else if ((Flags & DT_NON_ZERO) && (Value == 0))
344 1.1 jruoho {
345 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
346 1.1 jruoho }
347 1.1 jruoho
348 1.1 jruoho /*
349 1.1 jruoho * Generate the maximum value for the data type (ByteLength)
350 1.1 jruoho * Note: construct chosen for maximum portability
351 1.1 jruoho */
352 1.1 jruoho MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));
353 1.1 jruoho
354 1.1 jruoho /* Validate that the input value is within range of the target */
355 1.1 jruoho
356 1.1 jruoho if (Value > MaxValue)
357 1.1 jruoho {
358 1.2 christos snprintf (MsgBuffer, sizeof(MsgBuffer), "%8.8X%8.8X - max %u bytes",
359 1.2 christos ACPI_FORMAT_UINT64 (Value), ByteLength);
360 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
361 1.1 jruoho }
362 1.1 jruoho
363 1.5 christos memcpy (Buffer, &Value, ByteLength);
364 1.1 jruoho return;
365 1.1 jruoho }
366 1.1 jruoho
367 1.1 jruoho
368 1.1 jruoho /******************************************************************************
369 1.1 jruoho *
370 1.2 christos * FUNCTION: DtNormalizeBuffer
371 1.1 jruoho *
372 1.2 christos * PARAMETERS: Buffer - Input buffer
373 1.7 christos * Count - Output the count of hex numbers in
374 1.2 christos * the Buffer
375 1.1 jruoho *
376 1.7 christos * RETURN: The normalized buffer, must be freed by caller
377 1.1 jruoho *
378 1.2 christos * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized
379 1.2 christos * to 1A 2B 3C 4D
380 1.1 jruoho *
381 1.1 jruoho *****************************************************************************/
382 1.1 jruoho
383 1.1 jruoho static char *
384 1.2 christos DtNormalizeBuffer (
385 1.2 christos char *Buffer,
386 1.2 christos UINT32 *Count)
387 1.1 jruoho {
388 1.2 christos char *NewBuffer;
389 1.2 christos char *TmpBuffer;
390 1.2 christos UINT32 BufferCount = 0;
391 1.2 christos BOOLEAN Separator = TRUE;
392 1.2 christos char c;
393 1.2 christos
394 1.2 christos
395 1.5 christos NewBuffer = UtLocalCalloc (strlen (Buffer) + 1);
396 1.2 christos TmpBuffer = NewBuffer;
397 1.2 christos
398 1.2 christos while ((c = *Buffer++))
399 1.2 christos {
400 1.2 christos switch (c)
401 1.2 christos {
402 1.2 christos /* Valid separators */
403 1.1 jruoho
404 1.2 christos case '[':
405 1.2 christos case ']':
406 1.2 christos case ' ':
407 1.2 christos case ',':
408 1.1 jruoho
409 1.2 christos Separator = TRUE;
410 1.2 christos break;
411 1.1 jruoho
412 1.2 christos default:
413 1.1 jruoho
414 1.2 christos if (Separator)
415 1.2 christos {
416 1.2 christos /* Insert blank as the standard separator */
417 1.2 christos
418 1.2 christos if (NewBuffer[0])
419 1.2 christos {
420 1.2 christos *TmpBuffer++ = ' ';
421 1.2 christos BufferCount++;
422 1.2 christos }
423 1.2 christos
424 1.2 christos Separator = FALSE;
425 1.2 christos }
426 1.2 christos
427 1.2 christos *TmpBuffer++ = c;
428 1.2 christos break;
429 1.2 christos }
430 1.2 christos }
431 1.2 christos
432 1.2 christos *Count = BufferCount + 1;
433 1.2 christos return (NewBuffer);
434 1.1 jruoho }
435 1.1 jruoho
436 1.1 jruoho
437 1.1 jruoho /******************************************************************************
438 1.1 jruoho *
439 1.1 jruoho * FUNCTION: DtCompileBuffer
440 1.1 jruoho *
441 1.1 jruoho * PARAMETERS: Buffer - Output buffer
442 1.1 jruoho * StringValue - Integer list to be compiled
443 1.1 jruoho * Field - Current field object
444 1.1 jruoho * ByteLength - Byte length of the integer list
445 1.1 jruoho *
446 1.1 jruoho * RETURN: Count of remaining data in the input list
447 1.1 jruoho *
448 1.1 jruoho * DESCRIPTION: Compile and pack an integer list, for example
449 1.1 jruoho * "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B}
450 1.1 jruoho *
451 1.1 jruoho *****************************************************************************/
452 1.1 jruoho
453 1.1 jruoho UINT32
454 1.1 jruoho DtCompileBuffer (
455 1.1 jruoho UINT8 *Buffer,
456 1.1 jruoho char *StringValue,
457 1.1 jruoho DT_FIELD *Field,
458 1.1 jruoho UINT32 ByteLength)
459 1.1 jruoho {
460 1.7 christos char *Substring;
461 1.1 jruoho ACPI_STATUS Status;
462 1.7 christos UINT32 Count;
463 1.1 jruoho UINT32 i;
464 1.1 jruoho
465 1.1 jruoho
466 1.2 christos /* Allow several different types of value separators */
467 1.2 christos
468 1.2 christos StringValue = DtNormalizeBuffer (StringValue, &Count);
469 1.7 christos Substring = StringValue;
470 1.7 christos
471 1.7 christos /* Each element of StringValue is now three chars (2 hex + 1 space) */
472 1.1 jruoho
473 1.7 christos for (i = 0; i < Count; i++, Substring += 3)
474 1.1 jruoho {
475 1.7 christos /* Check for byte value too long */
476 1.2 christos
477 1.7 christos if (*(&Substring[2]) &&
478 1.7 christos (*(&Substring[2]) != ' '))
479 1.7 christos {
480 1.7 christos DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, Substring);
481 1.7 christos goto Exit;
482 1.7 christos }
483 1.1 jruoho
484 1.7 christos /* Convert two ASCII characters to one hex byte */
485 1.1 jruoho
486 1.7 christos Status = AcpiUtAsciiToHexByte (Substring, &Buffer[i]);
487 1.1 jruoho if (ACPI_FAILURE (Status))
488 1.1 jruoho {
489 1.7 christos DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, Substring);
490 1.2 christos goto Exit;
491 1.1 jruoho }
492 1.1 jruoho }
493 1.1 jruoho
494 1.2 christos Exit:
495 1.2 christos ACPI_FREE (StringValue);
496 1.1 jruoho return (ByteLength - Count);
497 1.1 jruoho }
498 1.1 jruoho
499 1.1 jruoho
500 1.1 jruoho /******************************************************************************
501 1.1 jruoho *
502 1.1 jruoho * FUNCTION: DtCompileFlag
503 1.1 jruoho *
504 1.7 christos * PARAMETERS: Buffer - Output buffer
505 1.7 christos * Field - Field to be compiled
506 1.7 christos * Info - Flag info
507 1.1 jruoho *
508 1.7 christos * RETURN: None
509 1.1 jruoho *
510 1.7 christos * DESCRIPTION: Compile a flag field. Handles flags up to 64 bits.
511 1.1 jruoho *
512 1.1 jruoho *****************************************************************************/
513 1.1 jruoho
514 1.2 christos void
515 1.1 jruoho DtCompileFlag (
516 1.1 jruoho UINT8 *Buffer,
517 1.1 jruoho DT_FIELD *Field,
518 1.2 christos ACPI_DMTABLE_INFO *Info)
519 1.1 jruoho {
520 1.1 jruoho UINT64 Value = 0;
521 1.1 jruoho UINT32 BitLength = 1;
522 1.2 christos UINT8 BitPosition = 0;
523 1.1 jruoho
524 1.1 jruoho
525 1.9 christos Value = AcpiUtImplicitStrtoul64 (Field->Value);
526 1.1 jruoho
527 1.1 jruoho switch (Info->Opcode)
528 1.1 jruoho {
529 1.1 jruoho case ACPI_DMT_FLAG0:
530 1.1 jruoho case ACPI_DMT_FLAG1:
531 1.1 jruoho case ACPI_DMT_FLAG2:
532 1.1 jruoho case ACPI_DMT_FLAG3:
533 1.1 jruoho case ACPI_DMT_FLAG4:
534 1.1 jruoho case ACPI_DMT_FLAG5:
535 1.1 jruoho case ACPI_DMT_FLAG6:
536 1.1 jruoho case ACPI_DMT_FLAG7:
537 1.1 jruoho
538 1.2 christos BitPosition = Info->Opcode;
539 1.1 jruoho BitLength = 1;
540 1.1 jruoho break;
541 1.1 jruoho
542 1.1 jruoho case ACPI_DMT_FLAGS0:
543 1.2 christos
544 1.2 christos BitPosition = 0;
545 1.2 christos BitLength = 2;
546 1.2 christos break;
547 1.2 christos
548 1.2 christos
549 1.2 christos case ACPI_DMT_FLAGS1:
550 1.2 christos
551 1.2 christos BitPosition = 1;
552 1.2 christos BitLength = 2;
553 1.2 christos break;
554 1.2 christos
555 1.2 christos
556 1.1 jruoho case ACPI_DMT_FLAGS2:
557 1.1 jruoho
558 1.2 christos BitPosition = 2;
559 1.2 christos BitLength = 2;
560 1.2 christos break;
561 1.2 christos
562 1.2 christos case ACPI_DMT_FLAGS4:
563 1.2 christos
564 1.2 christos BitPosition = 4;
565 1.1 jruoho BitLength = 2;
566 1.1 jruoho break;
567 1.1 jruoho
568 1.9 christos case ACPI_DMT_FLAGS4_0:
569 1.9 christos
570 1.9 christos BitPosition = 0;
571 1.9 christos BitLength = 4;
572 1.9 christos break;
573 1.9 christos
574 1.9 christos case ACPI_DMT_FLAGS4_4:
575 1.9 christos
576 1.9 christos BitPosition = 4;
577 1.9 christos BitLength = 4;
578 1.9 christos break;
579 1.9 christos
580 1.9 christos case ACPI_DMT_FLAGS4_8:
581 1.9 christos
582 1.9 christos BitPosition = 8;
583 1.9 christos BitLength = 4;
584 1.9 christos break;
585 1.9 christos
586 1.9 christos case ACPI_DMT_FLAGS4_12:
587 1.9 christos
588 1.9 christos BitPosition = 12;
589 1.9 christos BitLength = 4;
590 1.9 christos break;
591 1.9 christos
592 1.9 christos case ACPI_DMT_FLAGS16_16:
593 1.9 christos
594 1.9 christos BitPosition = 16;
595 1.9 christos BitLength = 16;
596 1.9 christos break;
597 1.9 christos
598 1.1 jruoho default:
599 1.1 jruoho
600 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
601 1.1 jruoho break;
602 1.1 jruoho }
603 1.1 jruoho
604 1.1 jruoho /* Check range of the input flag value */
605 1.1 jruoho
606 1.1 jruoho if (Value >= ((UINT64) 1 << BitLength))
607 1.1 jruoho {
608 1.2 christos snprintf (MsgBuffer, sizeof(MsgBuffer), "Maximum %u bit", BitLength);
609 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
610 1.1 jruoho Value = 0;
611 1.1 jruoho }
612 1.1 jruoho
613 1.2 christos *Buffer |= (UINT8) (Value << BitPosition);
614 1.1 jruoho }
615