dtfield.c revision 1.16.6.1 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.16.6.1 thorpej * Copyright (C) 2000 - 2021, 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.16.6.1 thorpej * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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
46 1.1 jruoho #define _COMPONENT DT_COMPILER
47 1.1 jruoho ACPI_MODULE_NAME ("dtfield")
48 1.1 jruoho
49 1.1 jruoho
50 1.1 jruoho /* Local prototypes */
51 1.1 jruoho
52 1.1 jruoho static void
53 1.1 jruoho DtCompileString (
54 1.1 jruoho UINT8 *Buffer,
55 1.1 jruoho DT_FIELD *Field,
56 1.1 jruoho UINT32 ByteLength);
57 1.1 jruoho
58 1.2 christos static void
59 1.2 christos DtCompileUnicode (
60 1.2 christos UINT8 *Buffer,
61 1.2 christos DT_FIELD *Field,
62 1.2 christos UINT32 ByteLength);
63 1.1 jruoho
64 1.2 christos static ACPI_STATUS
65 1.2 christos DtCompileUuid (
66 1.1 jruoho UINT8 *Buffer,
67 1.1 jruoho DT_FIELD *Field,
68 1.1 jruoho UINT32 ByteLength);
69 1.1 jruoho
70 1.2 christos static char *
71 1.2 christos DtNormalizeBuffer (
72 1.2 christos char *Buffer,
73 1.2 christos UINT32 *Count);
74 1.2 christos
75 1.1 jruoho
76 1.1 jruoho /******************************************************************************
77 1.1 jruoho *
78 1.1 jruoho * FUNCTION: DtCompileOneField
79 1.1 jruoho *
80 1.1 jruoho * PARAMETERS: Buffer - Output buffer
81 1.1 jruoho * Field - Field to be compiled
82 1.1 jruoho * ByteLength - Byte length of the field
83 1.1 jruoho * Type - Field type
84 1.1 jruoho *
85 1.1 jruoho * RETURN: None
86 1.1 jruoho *
87 1.1 jruoho * DESCRIPTION: Compile a field value to binary
88 1.1 jruoho *
89 1.1 jruoho *****************************************************************************/
90 1.1 jruoho
91 1.1 jruoho void
92 1.1 jruoho DtCompileOneField (
93 1.1 jruoho UINT8 *Buffer,
94 1.1 jruoho DT_FIELD *Field,
95 1.1 jruoho UINT32 ByteLength,
96 1.1 jruoho UINT8 Type,
97 1.1 jruoho UINT8 Flags)
98 1.1 jruoho {
99 1.2 christos ACPI_STATUS Status;
100 1.1 jruoho
101 1.6 christos
102 1.1 jruoho switch (Type)
103 1.1 jruoho {
104 1.1 jruoho case DT_FIELD_TYPE_INTEGER:
105 1.2 christos
106 1.1 jruoho DtCompileInteger (Buffer, Field, ByteLength, Flags);
107 1.1 jruoho break;
108 1.1 jruoho
109 1.1 jruoho case DT_FIELD_TYPE_STRING:
110 1.2 christos
111 1.1 jruoho DtCompileString (Buffer, Field, ByteLength);
112 1.1 jruoho break;
113 1.1 jruoho
114 1.2 christos case DT_FIELD_TYPE_UUID:
115 1.2 christos
116 1.2 christos Status = DtCompileUuid (Buffer, Field, ByteLength);
117 1.2 christos if (ACPI_SUCCESS (Status))
118 1.2 christos {
119 1.2 christos break;
120 1.2 christos }
121 1.2 christos
122 1.16.6.1 thorpej ACPI_FALLTHROUGH;
123 1.2 christos
124 1.1 jruoho case DT_FIELD_TYPE_BUFFER:
125 1.2 christos
126 1.1 jruoho DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
127 1.1 jruoho break;
128 1.1 jruoho
129 1.2 christos case DT_FIELD_TYPE_UNICODE:
130 1.2 christos
131 1.2 christos DtCompileUnicode (Buffer, Field, ByteLength);
132 1.2 christos break;
133 1.2 christos
134 1.2 christos case DT_FIELD_TYPE_DEVICE_PATH:
135 1.2 christos
136 1.1 jruoho break;
137 1.1 jruoho
138 1.1 jruoho default:
139 1.2 christos
140 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type");
141 1.1 jruoho break;
142 1.1 jruoho }
143 1.1 jruoho }
144 1.1 jruoho
145 1.1 jruoho
146 1.1 jruoho /******************************************************************************
147 1.1 jruoho *
148 1.1 jruoho * FUNCTION: DtCompileString
149 1.1 jruoho *
150 1.1 jruoho * PARAMETERS: Buffer - Output buffer
151 1.1 jruoho * Field - String to be copied to buffer
152 1.1 jruoho * ByteLength - Maximum length of string
153 1.1 jruoho *
154 1.1 jruoho * RETURN: None
155 1.1 jruoho *
156 1.1 jruoho * DESCRIPTION: Copy string to the buffer
157 1.1 jruoho *
158 1.1 jruoho *****************************************************************************/
159 1.1 jruoho
160 1.1 jruoho static void
161 1.1 jruoho DtCompileString (
162 1.1 jruoho UINT8 *Buffer,
163 1.1 jruoho DT_FIELD *Field,
164 1.1 jruoho UINT32 ByteLength)
165 1.1 jruoho {
166 1.1 jruoho UINT32 Length;
167 1.1 jruoho
168 1.1 jruoho
169 1.5 christos Length = strlen (Field->Value);
170 1.1 jruoho
171 1.1 jruoho /* Check if the string is too long for the field */
172 1.1 jruoho
173 1.1 jruoho if (Length > ByteLength)
174 1.1 jruoho {
175 1.14 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer),
176 1.14 christos "Maximum %u characters, found %u characters [%s]",
177 1.14 christos ByteLength, Length, Field->Value);
178 1.12 christos DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, AslGbl_MsgBuffer);
179 1.1 jruoho Length = ByteLength;
180 1.1 jruoho }
181 1.1 jruoho
182 1.5 christos memcpy (Buffer, Field->Value, Length);
183 1.2 christos }
184 1.2 christos
185 1.2 christos
186 1.2 christos /******************************************************************************
187 1.2 christos *
188 1.2 christos * FUNCTION: DtCompileUnicode
189 1.2 christos *
190 1.2 christos * PARAMETERS: Buffer - Output buffer
191 1.2 christos * Field - String to be copied to buffer
192 1.2 christos * ByteLength - Maximum length of string
193 1.2 christos *
194 1.2 christos * RETURN: None
195 1.2 christos *
196 1.2 christos * DESCRIPTION: Convert ASCII string to Unicode string
197 1.2 christos *
198 1.2 christos * Note: The Unicode string is 16 bits per character, no leading signature,
199 1.2 christos * with a 16-bit terminating NULL.
200 1.2 christos *
201 1.2 christos *****************************************************************************/
202 1.2 christos
203 1.2 christos static void
204 1.2 christos DtCompileUnicode (
205 1.2 christos UINT8 *Buffer,
206 1.2 christos DT_FIELD *Field,
207 1.2 christos UINT32 ByteLength)
208 1.2 christos {
209 1.2 christos UINT32 Count;
210 1.2 christos UINT32 i;
211 1.2 christos char *AsciiString;
212 1.2 christos UINT16 *UnicodeString;
213 1.2 christos
214 1.2 christos
215 1.2 christos AsciiString = Field->Value;
216 1.2 christos UnicodeString = (UINT16 *) Buffer;
217 1.5 christos Count = strlen (AsciiString) + 1;
218 1.2 christos
219 1.2 christos /* Convert to Unicode string (including null terminator) */
220 1.2 christos
221 1.2 christos for (i = 0; i < Count; i++)
222 1.2 christos {
223 1.2 christos UnicodeString[i] = (UINT16) AsciiString[i];
224 1.2 christos }
225 1.2 christos }
226 1.2 christos
227 1.2 christos
228 1.2 christos /*******************************************************************************
229 1.2 christos *
230 1.2 christos * FUNCTION: DtCompileUuid
231 1.2 christos *
232 1.2 christos * PARAMETERS: Buffer - Output buffer
233 1.2 christos * Field - String to be copied to buffer
234 1.2 christos * ByteLength - Maximum length of string
235 1.2 christos *
236 1.2 christos * RETURN: None
237 1.2 christos *
238 1.2 christos * DESCRIPTION: Convert UUID string to 16-byte buffer
239 1.2 christos *
240 1.2 christos ******************************************************************************/
241 1.2 christos
242 1.2 christos static ACPI_STATUS
243 1.2 christos DtCompileUuid (
244 1.2 christos UINT8 *Buffer,
245 1.2 christos DT_FIELD *Field,
246 1.2 christos UINT32 ByteLength)
247 1.2 christos {
248 1.2 christos char *InString;
249 1.2 christos ACPI_STATUS Status;
250 1.2 christos
251 1.2 christos
252 1.2 christos InString = Field->Value;
253 1.1 jruoho
254 1.2 christos Status = AuValidateUuid (InString);
255 1.2 christos if (ACPI_FAILURE (Status))
256 1.2 christos {
257 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "%s", Field->Value);
258 1.12 christos DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, AslGbl_MsgBuffer);
259 1.2 christos }
260 1.2 christos else
261 1.2 christos {
262 1.3 christos AcpiUtConvertStringToUuid (InString, Buffer);
263 1.2 christos }
264 1.2 christos
265 1.2 christos return (Status);
266 1.1 jruoho }
267 1.1 jruoho
268 1.1 jruoho
269 1.1 jruoho /******************************************************************************
270 1.1 jruoho *
271 1.1 jruoho * FUNCTION: DtCompileInteger
272 1.1 jruoho *
273 1.1 jruoho * PARAMETERS: Buffer - Output buffer
274 1.1 jruoho * Field - Field obj with Integer to be compiled
275 1.1 jruoho * ByteLength - Byte length of the integer
276 1.2 christos * Flags - Additional compile info
277 1.1 jruoho *
278 1.1 jruoho * RETURN: None
279 1.1 jruoho *
280 1.2 christos * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
281 1.2 christos * operators.
282 1.1 jruoho *
283 1.1 jruoho *****************************************************************************/
284 1.1 jruoho
285 1.1 jruoho void
286 1.1 jruoho DtCompileInteger (
287 1.1 jruoho UINT8 *Buffer,
288 1.1 jruoho DT_FIELD *Field,
289 1.1 jruoho UINT32 ByteLength,
290 1.1 jruoho UINT8 Flags)
291 1.1 jruoho {
292 1.2 christos UINT64 Value;
293 1.1 jruoho UINT64 MaxValue;
294 1.1 jruoho ACPI_STATUS Status;
295 1.1 jruoho
296 1.1 jruoho
297 1.2 christos /* Output buffer byte length must be in range 1-8 */
298 1.1 jruoho
299 1.1 jruoho if ((ByteLength > 8) || (ByteLength == 0))
300 1.1 jruoho {
301 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
302 1.1 jruoho "Invalid internal Byte length");
303 1.1 jruoho return;
304 1.1 jruoho }
305 1.1 jruoho
306 1.2 christos /* Resolve integer expression to a single integer value */
307 1.1 jruoho
308 1.2 christos Status = DtResolveIntegerExpression (Field, &Value);
309 1.1 jruoho if (ACPI_FAILURE (Status))
310 1.1 jruoho {
311 1.2 christos return;
312 1.1 jruoho }
313 1.1 jruoho
314 1.3 christos /*
315 1.3 christos * Ensure that reserved fields are set properly. Note: uses
316 1.3 christos * the DT_NON_ZERO flag to indicate that the reserved value
317 1.3 christos * must be exactly one. Otherwise, the value must be zero.
318 1.3 christos * This is sufficient for now.
319 1.3 christos */
320 1.3 christos
321 1.3 christos /* TBD: Should use a flag rather than compare "Reserved" */
322 1.1 jruoho
323 1.5 christos if (!strcmp (Field->Name, "Reserved"))
324 1.1 jruoho {
325 1.3 christos if (Flags & DT_NON_ZERO)
326 1.3 christos {
327 1.3 christos if (Value != 1)
328 1.3 christos {
329 1.3 christos DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
330 1.3 christos "Must be one, setting to one");
331 1.3 christos Value = 1;
332 1.3 christos }
333 1.3 christos }
334 1.3 christos else if (Value != 0)
335 1.3 christos {
336 1.3 christos DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
337 1.3 christos "Must be zero, setting to zero");
338 1.3 christos Value = 0;
339 1.3 christos }
340 1.1 jruoho }
341 1.1 jruoho
342 1.1 jruoho /* Check if the value must be non-zero */
343 1.1 jruoho
344 1.3 christos else if ((Flags & DT_NON_ZERO) && (Value == 0))
345 1.1 jruoho {
346 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
347 1.1 jruoho }
348 1.1 jruoho
349 1.1 jruoho /*
350 1.1 jruoho * Generate the maximum value for the data type (ByteLength)
351 1.1 jruoho * Note: construct chosen for maximum portability
352 1.1 jruoho */
353 1.1 jruoho MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));
354 1.1 jruoho
355 1.1 jruoho /* Validate that the input value is within range of the target */
356 1.1 jruoho
357 1.1 jruoho if (Value > MaxValue)
358 1.1 jruoho {
359 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "%8.8X%8.8X - max %u bytes",
360 1.2 christos ACPI_FORMAT_UINT64 (Value), ByteLength);
361 1.12 christos DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, AslGbl_MsgBuffer);
362 1.1 jruoho }
363 1.1 jruoho
364 1.5 christos memcpy (Buffer, &Value, ByteLength);
365 1.1 jruoho return;
366 1.1 jruoho }
367 1.1 jruoho
368 1.1 jruoho
369 1.1 jruoho /******************************************************************************
370 1.1 jruoho *
371 1.2 christos * FUNCTION: DtNormalizeBuffer
372 1.1 jruoho *
373 1.2 christos * PARAMETERS: Buffer - Input buffer
374 1.7 christos * Count - Output the count of hex numbers in
375 1.2 christos * the Buffer
376 1.1 jruoho *
377 1.7 christos * RETURN: The normalized buffer, must be freed by caller
378 1.1 jruoho *
379 1.2 christos * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized
380 1.2 christos * to 1A 2B 3C 4D
381 1.1 jruoho *
382 1.1 jruoho *****************************************************************************/
383 1.1 jruoho
384 1.1 jruoho static char *
385 1.2 christos DtNormalizeBuffer (
386 1.2 christos char *Buffer,
387 1.2 christos UINT32 *Count)
388 1.1 jruoho {
389 1.2 christos char *NewBuffer;
390 1.2 christos char *TmpBuffer;
391 1.2 christos UINT32 BufferCount = 0;
392 1.2 christos BOOLEAN Separator = TRUE;
393 1.2 christos char c;
394 1.2 christos
395 1.2 christos
396 1.5 christos NewBuffer = UtLocalCalloc (strlen (Buffer) + 1);
397 1.2 christos TmpBuffer = NewBuffer;
398 1.2 christos
399 1.2 christos while ((c = *Buffer++))
400 1.2 christos {
401 1.2 christos switch (c)
402 1.2 christos {
403 1.2 christos /* Valid separators */
404 1.1 jruoho
405 1.2 christos case '[':
406 1.2 christos case ']':
407 1.2 christos case ' ':
408 1.2 christos case ',':
409 1.1 jruoho
410 1.2 christos Separator = TRUE;
411 1.2 christos break;
412 1.1 jruoho
413 1.2 christos default:
414 1.1 jruoho
415 1.2 christos if (Separator)
416 1.2 christos {
417 1.2 christos /* Insert blank as the standard separator */
418 1.2 christos
419 1.2 christos if (NewBuffer[0])
420 1.2 christos {
421 1.2 christos *TmpBuffer++ = ' ';
422 1.2 christos BufferCount++;
423 1.2 christos }
424 1.2 christos
425 1.2 christos Separator = FALSE;
426 1.2 christos }
427 1.2 christos
428 1.2 christos *TmpBuffer++ = c;
429 1.2 christos break;
430 1.2 christos }
431 1.2 christos }
432 1.2 christos
433 1.2 christos *Count = BufferCount + 1;
434 1.2 christos return (NewBuffer);
435 1.1 jruoho }
436 1.1 jruoho
437 1.1 jruoho
438 1.1 jruoho /******************************************************************************
439 1.1 jruoho *
440 1.1 jruoho * FUNCTION: DtCompileBuffer
441 1.1 jruoho *
442 1.1 jruoho * PARAMETERS: Buffer - Output buffer
443 1.1 jruoho * StringValue - Integer list to be compiled
444 1.1 jruoho * Field - Current field object
445 1.1 jruoho * ByteLength - Byte length of the integer list
446 1.1 jruoho *
447 1.1 jruoho * RETURN: Count of remaining data in the input list
448 1.1 jruoho *
449 1.1 jruoho * DESCRIPTION: Compile and pack an integer list, for example
450 1.1 jruoho * "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B}
451 1.1 jruoho *
452 1.1 jruoho *****************************************************************************/
453 1.1 jruoho
454 1.1 jruoho UINT32
455 1.1 jruoho DtCompileBuffer (
456 1.1 jruoho UINT8 *Buffer,
457 1.1 jruoho char *StringValue,
458 1.1 jruoho DT_FIELD *Field,
459 1.1 jruoho UINT32 ByteLength)
460 1.1 jruoho {
461 1.7 christos char *Substring;
462 1.1 jruoho ACPI_STATUS Status;
463 1.7 christos UINT32 Count;
464 1.1 jruoho UINT32 i;
465 1.1 jruoho
466 1.1 jruoho
467 1.2 christos /* Allow several different types of value separators */
468 1.2 christos
469 1.2 christos StringValue = DtNormalizeBuffer (StringValue, &Count);
470 1.7 christos Substring = StringValue;
471 1.15 christos if (Count != ByteLength)
472 1.15 christos {
473 1.15 christos sprintf(AslGbl_MsgBuffer,
474 1.15 christos "Found %u values, must match expected count: %u",
475 1.15 christos Count, ByteLength);
476 1.15 christos DtError (ASL_ERROR, ASL_MSG_BUFFER_LIST, Field, AslGbl_MsgBuffer);
477 1.15 christos goto Exit;
478 1.15 christos }
479 1.7 christos
480 1.7 christos /* Each element of StringValue is now three chars (2 hex + 1 space) */
481 1.1 jruoho
482 1.7 christos for (i = 0; i < Count; i++, Substring += 3)
483 1.1 jruoho {
484 1.7 christos /* Check for byte value too long */
485 1.2 christos
486 1.7 christos if (*(&Substring[2]) &&
487 1.7 christos (*(&Substring[2]) != ' '))
488 1.7 christos {
489 1.7 christos DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, Substring);
490 1.7 christos goto Exit;
491 1.7 christos }
492 1.1 jruoho
493 1.7 christos /* Convert two ASCII characters to one hex byte */
494 1.1 jruoho
495 1.7 christos Status = AcpiUtAsciiToHexByte (Substring, &Buffer[i]);
496 1.1 jruoho if (ACPI_FAILURE (Status))
497 1.1 jruoho {
498 1.7 christos DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, Substring);
499 1.2 christos goto Exit;
500 1.1 jruoho }
501 1.1 jruoho }
502 1.1 jruoho
503 1.2 christos Exit:
504 1.2 christos ACPI_FREE (StringValue);
505 1.1 jruoho return (ByteLength - Count);
506 1.1 jruoho }
507 1.1 jruoho
508 1.1 jruoho
509 1.1 jruoho /******************************************************************************
510 1.1 jruoho *
511 1.1 jruoho * FUNCTION: DtCompileFlag
512 1.1 jruoho *
513 1.7 christos * PARAMETERS: Buffer - Output buffer
514 1.7 christos * Field - Field to be compiled
515 1.7 christos * Info - Flag info
516 1.1 jruoho *
517 1.7 christos * RETURN: None
518 1.1 jruoho *
519 1.7 christos * DESCRIPTION: Compile a flag field. Handles flags up to 64 bits.
520 1.1 jruoho *
521 1.1 jruoho *****************************************************************************/
522 1.1 jruoho
523 1.2 christos void
524 1.1 jruoho DtCompileFlag (
525 1.1 jruoho UINT8 *Buffer,
526 1.1 jruoho DT_FIELD *Field,
527 1.2 christos ACPI_DMTABLE_INFO *Info)
528 1.1 jruoho {
529 1.1 jruoho UINT64 Value = 0;
530 1.1 jruoho UINT32 BitLength = 1;
531 1.2 christos UINT8 BitPosition = 0;
532 1.1 jruoho
533 1.1 jruoho
534 1.9 christos Value = AcpiUtImplicitStrtoul64 (Field->Value);
535 1.1 jruoho
536 1.1 jruoho switch (Info->Opcode)
537 1.1 jruoho {
538 1.1 jruoho case ACPI_DMT_FLAG0:
539 1.1 jruoho case ACPI_DMT_FLAG1:
540 1.1 jruoho case ACPI_DMT_FLAG2:
541 1.1 jruoho case ACPI_DMT_FLAG3:
542 1.1 jruoho case ACPI_DMT_FLAG4:
543 1.1 jruoho case ACPI_DMT_FLAG5:
544 1.1 jruoho case ACPI_DMT_FLAG6:
545 1.1 jruoho case ACPI_DMT_FLAG7:
546 1.1 jruoho
547 1.2 christos BitPosition = Info->Opcode;
548 1.1 jruoho BitLength = 1;
549 1.1 jruoho break;
550 1.1 jruoho
551 1.1 jruoho case ACPI_DMT_FLAGS0:
552 1.2 christos
553 1.2 christos BitPosition = 0;
554 1.2 christos BitLength = 2;
555 1.2 christos break;
556 1.2 christos
557 1.2 christos
558 1.2 christos case ACPI_DMT_FLAGS1:
559 1.2 christos
560 1.2 christos BitPosition = 1;
561 1.2 christos BitLength = 2;
562 1.2 christos break;
563 1.2 christos
564 1.2 christos
565 1.1 jruoho case ACPI_DMT_FLAGS2:
566 1.1 jruoho
567 1.2 christos BitPosition = 2;
568 1.2 christos BitLength = 2;
569 1.2 christos break;
570 1.2 christos
571 1.2 christos case ACPI_DMT_FLAGS4:
572 1.2 christos
573 1.2 christos BitPosition = 4;
574 1.1 jruoho BitLength = 2;
575 1.1 jruoho break;
576 1.1 jruoho
577 1.9 christos case ACPI_DMT_FLAGS4_0:
578 1.9 christos
579 1.9 christos BitPosition = 0;
580 1.9 christos BitLength = 4;
581 1.9 christos break;
582 1.9 christos
583 1.9 christos case ACPI_DMT_FLAGS4_4:
584 1.9 christos
585 1.9 christos BitPosition = 4;
586 1.9 christos BitLength = 4;
587 1.9 christos break;
588 1.9 christos
589 1.9 christos case ACPI_DMT_FLAGS4_8:
590 1.9 christos
591 1.9 christos BitPosition = 8;
592 1.9 christos BitLength = 4;
593 1.9 christos break;
594 1.9 christos
595 1.9 christos case ACPI_DMT_FLAGS4_12:
596 1.9 christos
597 1.9 christos BitPosition = 12;
598 1.9 christos BitLength = 4;
599 1.9 christos break;
600 1.9 christos
601 1.9 christos case ACPI_DMT_FLAGS16_16:
602 1.9 christos
603 1.9 christos BitPosition = 16;
604 1.9 christos BitLength = 16;
605 1.9 christos break;
606 1.9 christos
607 1.1 jruoho default:
608 1.1 jruoho
609 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
610 1.1 jruoho break;
611 1.1 jruoho }
612 1.1 jruoho
613 1.1 jruoho /* Check range of the input flag value */
614 1.1 jruoho
615 1.1 jruoho if (Value >= ((UINT64) 1 << BitLength))
616 1.1 jruoho {
617 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Maximum %u bit", BitLength);
618 1.12 christos DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, AslGbl_MsgBuffer);
619 1.1 jruoho Value = 0;
620 1.1 jruoho }
621 1.1 jruoho
622 1.2 christos *Buffer |= (UINT8) (Value << BitPosition);
623 1.1 jruoho }
624 1.15 christos
625 1.15 christos
626 1.15 christos /******************************************************************************
627 1.15 christos *
628 1.15 christos * FUNCTION: DtCreateField
629 1.15 christos *
630 1.15 christos * PARAMETERS: Name
631 1.15 christos * Value
632 1.15 christos * Line
633 1.15 christos * Offset
634 1.15 christos * Column
635 1.15 christos * NameColumn
636 1.15 christos *
637 1.15 christos * RETURN: None
638 1.15 christos *
639 1.15 christos * DESCRIPTION: Create a field
640 1.15 christos *
641 1.15 christos *****************************************************************************/
642 1.15 christos
643 1.15 christos void
644 1.15 christos DtCreateField (
645 1.15 christos DT_TABLE_UNIT *FieldKey,
646 1.15 christos DT_TABLE_UNIT *FieldValue,
647 1.15 christos UINT32 Offset)
648 1.15 christos {
649 1.15 christos DT_FIELD *Field = UtFieldCacheCalloc ();
650 1.15 christos
651 1.15 christos
652 1.15 christos Field->StringLength = 0;
653 1.15 christos if (FieldKey->Value)
654 1.15 christos {
655 1.15 christos Field->Name =
656 1.15 christos strcpy (UtLocalCacheCalloc (strlen (FieldKey->Value) + 1), FieldKey->Value);
657 1.15 christos }
658 1.15 christos
659 1.15 christos if (FieldValue->Value)
660 1.15 christos {
661 1.15 christos Field->StringLength = strlen (FieldValue->Value);
662 1.15 christos Field->Value =
663 1.15 christos strcpy (UtLocalCacheCalloc (Field->StringLength + 1), FieldValue->Value);
664 1.15 christos }
665 1.15 christos
666 1.15 christos Field->Line = FieldValue->Line;
667 1.15 christos Field->ByteOffset = Offset;
668 1.15 christos Field->NameColumn = FieldKey->Column;
669 1.15 christos Field->Column = FieldValue->Column;
670 1.15 christos DtLinkField (Field);
671 1.15 christos
672 1.15 christos DtDumpFieldList (AslGbl_FieldList);
673 1.15 christos }
674 1.15 christos
675 1.15 christos
676 1.15 christos /******************************************************************************
677 1.15 christos *
678 1.15 christos * FUNCTION: DtCreateTableUnit
679 1.15 christos *
680 1.15 christos * PARAMETERS: Data
681 1.15 christos * Line
682 1.15 christos * Column
683 1.15 christos *
684 1.15 christos * RETURN: a table unit
685 1.15 christos *
686 1.15 christos * DESCRIPTION: Create a table unit
687 1.15 christos *
688 1.15 christos *****************************************************************************/
689 1.15 christos
690 1.15 christos DT_TABLE_UNIT *
691 1.15 christos DtCreateTableUnit (
692 1.15 christos char *Data,
693 1.15 christos UINT32 Line,
694 1.15 christos UINT32 Column)
695 1.15 christos {
696 1.15 christos DT_TABLE_UNIT *Unit = (DT_TABLE_UNIT *) UtFieldCacheCalloc ();
697 1.15 christos
698 1.15 christos
699 1.15 christos Unit->Value = Data;
700 1.15 christos Unit->Line = Line;
701 1.15 christos Unit->Column = Column;
702 1.15 christos return (Unit);
703 1.15 christos }
704 1.15 christos
705 1.15 christos
706 1.15 christos /******************************************************************************
707 1.15 christos *
708 1.15 christos * FUNCTION: DtLinkField
709 1.15 christos *
710 1.15 christos * PARAMETERS: Field - New field object to link
711 1.15 christos *
712 1.15 christos * RETURN: None
713 1.15 christos *
714 1.15 christos * DESCRIPTION: Link one field name and value to the list
715 1.15 christos *
716 1.15 christos *****************************************************************************/
717 1.15 christos
718 1.15 christos void
719 1.15 christos DtLinkField (
720 1.15 christos DT_FIELD *Field)
721 1.15 christos {
722 1.15 christos DT_FIELD *Prev;
723 1.15 christos DT_FIELD *Next;
724 1.15 christos
725 1.15 christos
726 1.15 christos Prev = Next = AslGbl_FieldList;
727 1.15 christos
728 1.15 christos while (Next)
729 1.15 christos {
730 1.15 christos Prev = Next;
731 1.15 christos Next = Next->Next;
732 1.15 christos }
733 1.15 christos
734 1.15 christos if (Prev)
735 1.15 christos {
736 1.15 christos Prev->Next = Field;
737 1.15 christos }
738 1.15 christos else
739 1.15 christos {
740 1.15 christos AslGbl_FieldList = Field;
741 1.15 christos }
742 1.15 christos }
743