dtfield.c revision 1.1.1.3 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.1.1.2 jruoho /*
8 1.1.1.2 jruoho * Copyright (C) 2000 - 2011, 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 #define __DTFIELD_C__
45 1.1 jruoho
46 1.1 jruoho #include "aslcompiler.h"
47 1.1 jruoho #include "dtcompiler.h"
48 1.1 jruoho
49 1.1 jruoho #define _COMPONENT DT_COMPILER
50 1.1 jruoho ACPI_MODULE_NAME ("dtfield")
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho /* Local prototypes */
54 1.1 jruoho
55 1.1 jruoho static void
56 1.1 jruoho DtCompileString (
57 1.1 jruoho UINT8 *Buffer,
58 1.1 jruoho DT_FIELD *Field,
59 1.1 jruoho UINT32 ByteLength);
60 1.1 jruoho
61 1.1 jruoho static void
62 1.1.1.2 jruoho DtCompileUnicode (
63 1.1 jruoho UINT8 *Buffer,
64 1.1 jruoho DT_FIELD *Field,
65 1.1 jruoho UINT32 ByteLength);
66 1.1 jruoho
67 1.1.1.2 jruoho static ACPI_STATUS
68 1.1.1.2 jruoho DtCompileUuid (
69 1.1.1.2 jruoho UINT8 *Buffer,
70 1.1.1.2 jruoho DT_FIELD *Field,
71 1.1.1.2 jruoho UINT32 ByteLength);
72 1.1.1.2 jruoho
73 1.1.1.2 jruoho static char *
74 1.1.1.2 jruoho DtNormalizeBuffer (
75 1.1.1.2 jruoho char *Buffer,
76 1.1.1.2 jruoho UINT32 *Count);
77 1.1.1.2 jruoho
78 1.1 jruoho
79 1.1 jruoho /******************************************************************************
80 1.1 jruoho *
81 1.1 jruoho * FUNCTION: DtCompileOneField
82 1.1 jruoho *
83 1.1 jruoho * PARAMETERS: Buffer - Output buffer
84 1.1 jruoho * Field - Field to be compiled
85 1.1 jruoho * ByteLength - Byte length of the field
86 1.1 jruoho * Type - Field type
87 1.1 jruoho *
88 1.1 jruoho * RETURN: None
89 1.1 jruoho *
90 1.1 jruoho * DESCRIPTION: Compile a field value to binary
91 1.1 jruoho *
92 1.1 jruoho *****************************************************************************/
93 1.1 jruoho
94 1.1 jruoho void
95 1.1 jruoho DtCompileOneField (
96 1.1 jruoho UINT8 *Buffer,
97 1.1 jruoho DT_FIELD *Field,
98 1.1 jruoho UINT32 ByteLength,
99 1.1 jruoho UINT8 Type,
100 1.1 jruoho UINT8 Flags)
101 1.1 jruoho {
102 1.1.1.2 jruoho ACPI_STATUS Status;
103 1.1 jruoho
104 1.1 jruoho switch (Type)
105 1.1 jruoho {
106 1.1 jruoho case DT_FIELD_TYPE_INTEGER:
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.1 jruoho DtCompileString (Buffer, Field, ByteLength);
112 1.1 jruoho break;
113 1.1 jruoho
114 1.1.1.2 jruoho case DT_FIELD_TYPE_UUID:
115 1.1.1.2 jruoho Status = DtCompileUuid (Buffer, Field, ByteLength);
116 1.1.1.2 jruoho if (ACPI_SUCCESS (Status))
117 1.1.1.2 jruoho {
118 1.1.1.2 jruoho break;
119 1.1.1.2 jruoho }
120 1.1.1.2 jruoho
121 1.1.1.2 jruoho /* Fall through. */
122 1.1.1.2 jruoho
123 1.1 jruoho case DT_FIELD_TYPE_BUFFER:
124 1.1 jruoho DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
125 1.1 jruoho break;
126 1.1 jruoho
127 1.1.1.2 jruoho case DT_FIELD_TYPE_UNICODE:
128 1.1.1.2 jruoho DtCompileUnicode (Buffer, Field, ByteLength);
129 1.1.1.2 jruoho break;
130 1.1.1.2 jruoho
131 1.1.1.2 jruoho case DT_FIELD_TYPE_DEVICE_PATH:
132 1.1 jruoho break;
133 1.1 jruoho
134 1.1 jruoho default:
135 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type");
136 1.1 jruoho break;
137 1.1 jruoho }
138 1.1 jruoho }
139 1.1 jruoho
140 1.1 jruoho
141 1.1 jruoho /******************************************************************************
142 1.1 jruoho *
143 1.1 jruoho * FUNCTION: DtCompileString
144 1.1 jruoho *
145 1.1 jruoho * PARAMETERS: Buffer - Output buffer
146 1.1 jruoho * Field - String to be copied to buffer
147 1.1 jruoho * ByteLength - Maximum length of string
148 1.1 jruoho *
149 1.1 jruoho * RETURN: None
150 1.1 jruoho *
151 1.1 jruoho * DESCRIPTION: Copy string to the buffer
152 1.1 jruoho *
153 1.1 jruoho *****************************************************************************/
154 1.1 jruoho
155 1.1 jruoho static void
156 1.1 jruoho DtCompileString (
157 1.1 jruoho UINT8 *Buffer,
158 1.1 jruoho DT_FIELD *Field,
159 1.1 jruoho UINT32 ByteLength)
160 1.1 jruoho {
161 1.1 jruoho UINT32 Length;
162 1.1 jruoho
163 1.1 jruoho
164 1.1 jruoho Length = ACPI_STRLEN (Field->Value);
165 1.1 jruoho
166 1.1 jruoho /* Check if the string is too long for the field */
167 1.1 jruoho
168 1.1 jruoho if (Length > ByteLength)
169 1.1 jruoho {
170 1.1 jruoho sprintf (MsgBuffer, "Maximum %u characters", ByteLength);
171 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
172 1.1 jruoho Length = ByteLength;
173 1.1 jruoho }
174 1.1 jruoho
175 1.1 jruoho ACPI_MEMCPY (Buffer, Field->Value, Length);
176 1.1 jruoho }
177 1.1 jruoho
178 1.1 jruoho
179 1.1 jruoho /******************************************************************************
180 1.1 jruoho *
181 1.1.1.2 jruoho * FUNCTION: DtCompileUnicode
182 1.1.1.2 jruoho *
183 1.1.1.2 jruoho * PARAMETERS: Buffer - Output buffer
184 1.1.1.2 jruoho * Field - String to be copied to buffer
185 1.1.1.2 jruoho * ByteLength - Maximum length of string
186 1.1.1.2 jruoho *
187 1.1.1.2 jruoho * RETURN: None
188 1.1.1.2 jruoho *
189 1.1.1.2 jruoho * DESCRIPTION: Convert ASCII string to Unicode string
190 1.1.1.2 jruoho *
191 1.1.1.2 jruoho * Note: The Unicode string is 16 bits per character, no leading signature,
192 1.1.1.2 jruoho * with a 16-bit terminating NULL.
193 1.1.1.2 jruoho *
194 1.1.1.2 jruoho *****************************************************************************/
195 1.1.1.2 jruoho
196 1.1.1.2 jruoho static void
197 1.1.1.2 jruoho DtCompileUnicode (
198 1.1.1.2 jruoho UINT8 *Buffer,
199 1.1.1.2 jruoho DT_FIELD *Field,
200 1.1.1.2 jruoho UINT32 ByteLength)
201 1.1.1.2 jruoho {
202 1.1.1.2 jruoho UINT32 Count;
203 1.1.1.2 jruoho UINT32 i;
204 1.1.1.2 jruoho char *AsciiString;
205 1.1.1.2 jruoho UINT16 *UnicodeString;
206 1.1.1.2 jruoho
207 1.1.1.2 jruoho
208 1.1.1.2 jruoho AsciiString = Field->Value;
209 1.1.1.2 jruoho UnicodeString = (UINT16 *) Buffer;
210 1.1.1.2 jruoho Count = ACPI_STRLEN (AsciiString) + 1;
211 1.1.1.2 jruoho
212 1.1.1.2 jruoho /* Convert to Unicode string (including null terminator) */
213 1.1.1.2 jruoho
214 1.1.1.2 jruoho for (i = 0; i < Count; i++)
215 1.1.1.2 jruoho {
216 1.1.1.2 jruoho UnicodeString[i] = (UINT16) AsciiString[i];
217 1.1.1.2 jruoho }
218 1.1.1.2 jruoho }
219 1.1.1.2 jruoho
220 1.1.1.2 jruoho
221 1.1.1.2 jruoho /*******************************************************************************
222 1.1.1.2 jruoho *
223 1.1.1.2 jruoho * FUNCTION: DtCompileUuid
224 1.1.1.2 jruoho *
225 1.1.1.2 jruoho * PARAMETERS: Buffer - Output buffer
226 1.1.1.2 jruoho * Field - String to be copied to buffer
227 1.1.1.2 jruoho * ByteLength - Maximum length of string
228 1.1.1.2 jruoho *
229 1.1.1.2 jruoho * RETURN: None
230 1.1.1.2 jruoho *
231 1.1.1.2 jruoho * DESCRIPTION: Convert UUID string to 16-byte buffer
232 1.1.1.2 jruoho *
233 1.1.1.2 jruoho ******************************************************************************/
234 1.1.1.2 jruoho
235 1.1.1.2 jruoho static ACPI_STATUS
236 1.1.1.2 jruoho DtCompileUuid (
237 1.1.1.2 jruoho UINT8 *Buffer,
238 1.1.1.2 jruoho DT_FIELD *Field,
239 1.1.1.2 jruoho UINT32 ByteLength)
240 1.1.1.2 jruoho {
241 1.1.1.2 jruoho char *InString;
242 1.1.1.2 jruoho ACPI_STATUS Status;
243 1.1.1.2 jruoho
244 1.1.1.2 jruoho
245 1.1.1.2 jruoho InString = Field->Value;
246 1.1.1.2 jruoho
247 1.1.1.2 jruoho Status = AuValidateUuid (InString);
248 1.1.1.2 jruoho if (ACPI_FAILURE (Status))
249 1.1.1.2 jruoho {
250 1.1.1.2 jruoho sprintf (MsgBuffer, "%s", Field->Value);
251 1.1.1.2 jruoho DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer);
252 1.1.1.2 jruoho }
253 1.1.1.2 jruoho else
254 1.1.1.2 jruoho {
255 1.1.1.2 jruoho Status = AuConvertStringToUuid (InString, (char *) Buffer);
256 1.1.1.2 jruoho }
257 1.1.1.2 jruoho
258 1.1.1.2 jruoho return (Status);
259 1.1.1.2 jruoho }
260 1.1.1.2 jruoho
261 1.1.1.2 jruoho
262 1.1.1.2 jruoho /******************************************************************************
263 1.1.1.2 jruoho *
264 1.1 jruoho * FUNCTION: DtCompileInteger
265 1.1 jruoho *
266 1.1 jruoho * PARAMETERS: Buffer - Output buffer
267 1.1 jruoho * Field - Field obj with Integer to be compiled
268 1.1 jruoho * ByteLength - Byte length of the integer
269 1.1.1.2 jruoho * Flags - Additional compile info
270 1.1 jruoho *
271 1.1 jruoho * RETURN: None
272 1.1 jruoho *
273 1.1.1.2 jruoho * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
274 1.1.1.2 jruoho * operators.
275 1.1 jruoho *
276 1.1 jruoho *****************************************************************************/
277 1.1 jruoho
278 1.1 jruoho void
279 1.1 jruoho DtCompileInteger (
280 1.1 jruoho UINT8 *Buffer,
281 1.1 jruoho DT_FIELD *Field,
282 1.1 jruoho UINT32 ByteLength,
283 1.1 jruoho UINT8 Flags)
284 1.1 jruoho {
285 1.1.1.2 jruoho UINT64 Value;
286 1.1 jruoho UINT64 MaxValue;
287 1.1.1.3 jruoho ACPI_STATUS Status;
288 1.1 jruoho
289 1.1 jruoho
290 1.1.1.2 jruoho /* Output buffer byte length must be in range 1-8 */
291 1.1 jruoho
292 1.1 jruoho if ((ByteLength > 8) || (ByteLength == 0))
293 1.1 jruoho {
294 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
295 1.1 jruoho "Invalid internal Byte length");
296 1.1 jruoho return;
297 1.1 jruoho }
298 1.1 jruoho
299 1.1.1.2 jruoho /* Resolve integer expression to a single integer value */
300 1.1 jruoho
301 1.1.1.3 jruoho Status = DtResolveIntegerExpression (Field, &Value);
302 1.1.1.3 jruoho if (ACPI_FAILURE (Status))
303 1.1.1.3 jruoho {
304 1.1.1.3 jruoho return;
305 1.1.1.3 jruoho }
306 1.1 jruoho
307 1.1 jruoho /* Ensure that reserved fields are set to zero */
308 1.1 jruoho /* TBD: should we set to zero, or just make this an ERROR? */
309 1.1 jruoho /* TBD: Probably better to use a flag */
310 1.1 jruoho
311 1.1 jruoho if (!ACPI_STRCMP (Field->Name, "Reserved") &&
312 1.1 jruoho (Value != 0))
313 1.1 jruoho {
314 1.1 jruoho DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
315 1.1 jruoho "Setting to zero");
316 1.1 jruoho Value = 0;
317 1.1 jruoho }
318 1.1 jruoho
319 1.1 jruoho /* Check if the value must be non-zero */
320 1.1 jruoho
321 1.1 jruoho if ((Value == 0) && (Flags & DT_NON_ZERO))
322 1.1 jruoho {
323 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
324 1.1 jruoho }
325 1.1 jruoho
326 1.1 jruoho /*
327 1.1 jruoho * Generate the maximum value for the data type (ByteLength)
328 1.1 jruoho * Note: construct chosen for maximum portability
329 1.1 jruoho */
330 1.1 jruoho MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));
331 1.1 jruoho
332 1.1 jruoho /* Validate that the input value is within range of the target */
333 1.1 jruoho
334 1.1 jruoho if (Value > MaxValue)
335 1.1 jruoho {
336 1.1.1.2 jruoho sprintf (MsgBuffer, "%8.8X%8.8X", ACPI_FORMAT_UINT64 (Value));
337 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
338 1.1 jruoho }
339 1.1 jruoho
340 1.1 jruoho ACPI_MEMCPY (Buffer, &Value, ByteLength);
341 1.1 jruoho return;
342 1.1 jruoho }
343 1.1 jruoho
344 1.1 jruoho
345 1.1 jruoho /******************************************************************************
346 1.1 jruoho *
347 1.1.1.2 jruoho * FUNCTION: DtNormalizeBuffer
348 1.1 jruoho *
349 1.1.1.2 jruoho * PARAMETERS: Buffer - Input buffer
350 1.1.1.2 jruoho * Count - Output the count of hex number in
351 1.1.1.2 jruoho * the Buffer
352 1.1 jruoho *
353 1.1.1.2 jruoho * RETURN: The normalized buffer, freed by caller
354 1.1 jruoho *
355 1.1.1.2 jruoho * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized
356 1.1.1.2 jruoho * to 1A 2B 3C 4D
357 1.1 jruoho *
358 1.1 jruoho *****************************************************************************/
359 1.1 jruoho
360 1.1 jruoho static char *
361 1.1.1.2 jruoho DtNormalizeBuffer (
362 1.1.1.2 jruoho char *Buffer,
363 1.1.1.2 jruoho UINT32 *Count)
364 1.1 jruoho {
365 1.1.1.2 jruoho char *NewBuffer;
366 1.1.1.2 jruoho char *TmpBuffer;
367 1.1.1.2 jruoho UINT32 BufferCount = 0;
368 1.1.1.2 jruoho BOOLEAN Separator = TRUE;
369 1.1.1.2 jruoho char c;
370 1.1.1.2 jruoho
371 1.1.1.2 jruoho
372 1.1.1.2 jruoho NewBuffer = UtLocalCalloc (ACPI_STRLEN (Buffer) + 1);
373 1.1.1.2 jruoho TmpBuffer = NewBuffer;
374 1.1 jruoho
375 1.1.1.2 jruoho while ((c = *Buffer++))
376 1.1.1.2 jruoho {
377 1.1.1.2 jruoho switch (c)
378 1.1.1.2 jruoho {
379 1.1.1.2 jruoho /* Valid separators */
380 1.1 jruoho
381 1.1.1.2 jruoho case '[':
382 1.1.1.2 jruoho case ']':
383 1.1.1.2 jruoho case ' ':
384 1.1.1.2 jruoho case ',':
385 1.1.1.2 jruoho Separator = TRUE;
386 1.1.1.2 jruoho break;
387 1.1.1.2 jruoho
388 1.1.1.2 jruoho default:
389 1.1.1.2 jruoho if (Separator)
390 1.1.1.2 jruoho {
391 1.1.1.2 jruoho /* Insert blank as the standard separator */
392 1.1.1.2 jruoho
393 1.1.1.2 jruoho if (NewBuffer[0])
394 1.1.1.2 jruoho {
395 1.1.1.2 jruoho *TmpBuffer++ = ' ';
396 1.1.1.2 jruoho BufferCount++;
397 1.1.1.2 jruoho }
398 1.1 jruoho
399 1.1.1.2 jruoho Separator = FALSE;
400 1.1.1.2 jruoho }
401 1.1.1.2 jruoho
402 1.1.1.2 jruoho *TmpBuffer++ = c;
403 1.1.1.2 jruoho break;
404 1.1.1.2 jruoho }
405 1.1.1.2 jruoho }
406 1.1 jruoho
407 1.1.1.2 jruoho *Count = BufferCount + 1;
408 1.1.1.2 jruoho return (NewBuffer);
409 1.1 jruoho }
410 1.1 jruoho
411 1.1 jruoho
412 1.1 jruoho /******************************************************************************
413 1.1 jruoho *
414 1.1 jruoho * FUNCTION: DtCompileBuffer
415 1.1 jruoho *
416 1.1 jruoho * PARAMETERS: Buffer - Output buffer
417 1.1 jruoho * StringValue - Integer list to be compiled
418 1.1 jruoho * Field - Current field object
419 1.1 jruoho * ByteLength - Byte length of the integer list
420 1.1 jruoho *
421 1.1 jruoho * RETURN: Count of remaining data in the input list
422 1.1 jruoho *
423 1.1 jruoho * DESCRIPTION: Compile and pack an integer list, for example
424 1.1 jruoho * "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B}
425 1.1 jruoho *
426 1.1 jruoho *****************************************************************************/
427 1.1 jruoho
428 1.1 jruoho UINT32
429 1.1 jruoho DtCompileBuffer (
430 1.1 jruoho UINT8 *Buffer,
431 1.1 jruoho char *StringValue,
432 1.1 jruoho DT_FIELD *Field,
433 1.1 jruoho UINT32 ByteLength)
434 1.1 jruoho {
435 1.1 jruoho ACPI_STATUS Status;
436 1.1 jruoho char Hex[3];
437 1.1 jruoho UINT64 Value;
438 1.1 jruoho UINT32 i;
439 1.1 jruoho UINT32 Count;
440 1.1 jruoho
441 1.1 jruoho
442 1.1.1.2 jruoho /* Allow several different types of value separators */
443 1.1.1.2 jruoho
444 1.1.1.2 jruoho StringValue = DtNormalizeBuffer (StringValue, &Count);
445 1.1 jruoho
446 1.1 jruoho Hex[2] = 0;
447 1.1 jruoho for (i = 0; i < Count; i++)
448 1.1 jruoho {
449 1.1.1.2 jruoho /* Each element of StringValue is three chars */
450 1.1.1.2 jruoho
451 1.1.1.2 jruoho Hex[0] = StringValue[(3 * i)];
452 1.1.1.2 jruoho Hex[1] = StringValue[(3 * i) + 1];
453 1.1 jruoho
454 1.1 jruoho /* Convert one hex byte */
455 1.1 jruoho
456 1.1 jruoho Value = 0;
457 1.1 jruoho Status = DtStrtoul64 (Hex, &Value);
458 1.1 jruoho if (ACPI_FAILURE (Status))
459 1.1 jruoho {
460 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer);
461 1.1 jruoho return (ByteLength - Count);
462 1.1 jruoho }
463 1.1 jruoho
464 1.1 jruoho Buffer[i] = (UINT8) Value;
465 1.1 jruoho }
466 1.1 jruoho
467 1.1.1.2 jruoho ACPI_FREE (StringValue);
468 1.1 jruoho return (ByteLength - Count);
469 1.1 jruoho }
470 1.1 jruoho
471 1.1 jruoho
472 1.1 jruoho /******************************************************************************
473 1.1 jruoho *
474 1.1 jruoho * FUNCTION: DtCompileFlag
475 1.1 jruoho *
476 1.1 jruoho * PARAMETERS: Buffer - Output buffer
477 1.1 jruoho * Field - Field to be compiled
478 1.1 jruoho * Info - Flag info
479 1.1 jruoho *
480 1.1.1.2 jruoho * RETURN:
481 1.1 jruoho *
482 1.1 jruoho * DESCRIPTION: Compile a flag
483 1.1 jruoho *
484 1.1 jruoho *****************************************************************************/
485 1.1 jruoho
486 1.1.1.2 jruoho void
487 1.1 jruoho DtCompileFlag (
488 1.1 jruoho UINT8 *Buffer,
489 1.1 jruoho DT_FIELD *Field,
490 1.1.1.2 jruoho ACPI_DMTABLE_INFO *Info)
491 1.1 jruoho {
492 1.1 jruoho UINT64 Value = 0;
493 1.1 jruoho UINT32 BitLength = 1;
494 1.1.1.2 jruoho UINT8 BitPosition = 0;
495 1.1 jruoho ACPI_STATUS Status;
496 1.1 jruoho
497 1.1 jruoho
498 1.1 jruoho Status = DtStrtoul64 (Field->Value, &Value);
499 1.1 jruoho if (ACPI_FAILURE (Status))
500 1.1 jruoho {
501 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, NULL);
502 1.1 jruoho }
503 1.1 jruoho
504 1.1 jruoho switch (Info->Opcode)
505 1.1 jruoho {
506 1.1 jruoho case ACPI_DMT_FLAG0:
507 1.1 jruoho case ACPI_DMT_FLAG1:
508 1.1 jruoho case ACPI_DMT_FLAG2:
509 1.1 jruoho case ACPI_DMT_FLAG3:
510 1.1 jruoho case ACPI_DMT_FLAG4:
511 1.1 jruoho case ACPI_DMT_FLAG5:
512 1.1 jruoho case ACPI_DMT_FLAG6:
513 1.1 jruoho case ACPI_DMT_FLAG7:
514 1.1 jruoho
515 1.1.1.2 jruoho BitPosition = Info->Opcode;
516 1.1 jruoho BitLength = 1;
517 1.1 jruoho break;
518 1.1 jruoho
519 1.1 jruoho case ACPI_DMT_FLAGS0:
520 1.1.1.2 jruoho
521 1.1.1.2 jruoho BitPosition = 0;
522 1.1.1.2 jruoho BitLength = 2;
523 1.1.1.2 jruoho break;
524 1.1.1.2 jruoho
525 1.1.1.2 jruoho
526 1.1 jruoho case ACPI_DMT_FLAGS2:
527 1.1 jruoho
528 1.1.1.2 jruoho BitPosition = 2;
529 1.1 jruoho BitLength = 2;
530 1.1 jruoho break;
531 1.1 jruoho
532 1.1 jruoho default:
533 1.1 jruoho
534 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
535 1.1 jruoho break;
536 1.1 jruoho }
537 1.1 jruoho
538 1.1 jruoho /* Check range of the input flag value */
539 1.1 jruoho
540 1.1 jruoho if (Value >= ((UINT64) 1 << BitLength))
541 1.1 jruoho {
542 1.1 jruoho sprintf (MsgBuffer, "Maximum %u bit", BitLength);
543 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
544 1.1 jruoho Value = 0;
545 1.1 jruoho }
546 1.1 jruoho
547 1.1.1.2 jruoho *Buffer |= (UINT8) (Value << BitPosition);
548 1.1 jruoho }
549