Subversion Repositories Kolibri OS

Rev

Rev 1498 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1498 Rev 2216
Line 6... Line 6...
6
 
6
 
7
/******************************************************************************
7
/******************************************************************************
8
 *
8
 *
9
 * 1. Copyright Notice
9
 * 1. Copyright Notice
10
 *
10
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
11
 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
12
 * All rights reserved.
12
 * All rights reserved.
13
 *
13
 *
14
 * 2. License
14
 * 2. License
15
 *
15
 *
Line 128... Line 128...
128
DtCompileString (
128
DtCompileString (
129
    UINT8                   *Buffer,
129
    UINT8                   *Buffer,
130
    DT_FIELD                *Field,
130
    DT_FIELD                *Field,
131
    UINT32                  ByteLength);
131
    UINT32                  ByteLength);
Line 132... Line -...
132
 
-
 
133
static char *
-
 
134
DtPciPathToBuffer (
-
 
135
    char                    *PciPath);
-
 
136
 
132
 
137
static void
133
static void
138
DtCompilePciPath (
134
DtCompileUnicode (
139
    UINT8                   *Buffer,
-
 
140
    char                    *StringValue,
135
    UINT8                   *Buffer,
141
    DT_FIELD                *Field,
136
    DT_FIELD                *Field,
Line -... Line 137...
-
 
137
    UINT32                  ByteLength);
-
 
138
 
-
 
139
static ACPI_STATUS
-
 
140
DtCompileUuid (
-
 
141
    UINT8                   *Buffer,
-
 
142
    DT_FIELD                *Field,
-
 
143
    UINT32                  ByteLength);
-
 
144
 
-
 
145
static char *
-
 
146
DtNormalizeBuffer (
-
 
147
    char                    *Buffer,
Line 142... Line 148...
142
    UINT32                  ByteLength);
148
    UINT32                  *Count);
143
 
149
 
144
 
150
 
145
/******************************************************************************
151
/******************************************************************************
Line 163... Line 169...
163
    DT_FIELD                *Field,
169
    DT_FIELD                *Field,
164
    UINT32                  ByteLength,
170
    UINT32                  ByteLength,
165
    UINT8                   Type,
171
    UINT8                   Type,
166
    UINT8                   Flags)
172
    UINT8                   Flags)
167
{
173
{
-
 
174
    ACPI_STATUS             Status;
Line 168... Line 175...
168
 
175
 
169
    switch (Type)
176
    switch (Type)
170
    {
177
    {
171
    case DT_FIELD_TYPE_INTEGER:
178
    case DT_FIELD_TYPE_INTEGER:
Line 174... Line 181...
174
 
181
 
175
    case DT_FIELD_TYPE_STRING:
182
    case DT_FIELD_TYPE_STRING:
176
        DtCompileString (Buffer, Field, ByteLength);
183
        DtCompileString (Buffer, Field, ByteLength);
Line -... Line 184...
-
 
184
        break;
-
 
185
 
-
 
186
    case DT_FIELD_TYPE_UUID:
-
 
187
        Status = DtCompileUuid (Buffer, Field, ByteLength);
-
 
188
        if (ACPI_SUCCESS (Status))
-
 
189
        {
-
 
190
            break;
-
 
191
        }
-
 
192
 
177
        break;
193
        /* Fall through. */
178
 
194
 
179
    case DT_FIELD_TYPE_BUFFER:
195
    case DT_FIELD_TYPE_BUFFER:
Line 180... Line 196...
180
        DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
196
        DtCompileBuffer (Buffer, Field->Value, Field, ByteLength);
181
        break;
197
        break;
-
 
198
 
-
 
199
    case DT_FIELD_TYPE_UNICODE:
-
 
200
        DtCompileUnicode (Buffer, Field, ByteLength);
182
 
201
        break;
Line 183... Line 202...
183
    case DT_FIELD_TYPE_PCI_PATH:
202
 
184
        DtCompilePciPath (Buffer, Field->Value, Field, ByteLength);
203
    case DT_FIELD_TYPE_DEVICE_PATH:
185
        break;
204
        break;
Line 223... Line 242...
223
        sprintf (MsgBuffer, "Maximum %u characters", ByteLength);
242
        sprintf (MsgBuffer, "Maximum %u characters", ByteLength);
224
        DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
243
        DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
225
        Length = ByteLength;
244
        Length = ByteLength;
226
    }
245
    }
Line 227... Line -...
227
 
-
 
228
    /* If input string is shorter than ByteLength, pad with blanks */
-
 
229
 
-
 
230
    ACPI_MEMSET (Buffer, 0x20, ByteLength);
246
 
231
    ACPI_MEMCPY (Buffer, Field->Value, Length);
247
    ACPI_MEMCPY (Buffer, Field->Value, Length);
Line 232... Line 248...
232
}
248
}
233
 
249
 
-
 
250
 
-
 
251
/******************************************************************************
-
 
252
 *
-
 
253
 * FUNCTION:    DtCompileUnicode
-
 
254
 *
-
 
255
 * PARAMETERS:  Buffer              - Output buffer
-
 
256
 *              Field               - String to be copied to buffer
-
 
257
 *              ByteLength          - Maximum length of string
-
 
258
 *
-
 
259
 * RETURN:      None
-
 
260
 *
-
 
261
 * DESCRIPTION: Convert ASCII string to Unicode string
-
 
262
 *
-
 
263
 * Note:  The Unicode string is 16 bits per character, no leading signature,
-
 
264
 *        with a 16-bit terminating NULL.
-
 
265
 *
-
 
266
 *****************************************************************************/
-
 
267
 
-
 
268
static void
-
 
269
DtCompileUnicode (
-
 
270
    UINT8                   *Buffer,
-
 
271
    DT_FIELD                *Field,
-
 
272
    UINT32                  ByteLength)
-
 
273
{
-
 
274
    UINT32                  Count;
-
 
275
    UINT32                  i;
-
 
276
    char                    *AsciiString;
-
 
277
    UINT16                  *UnicodeString;
-
 
278
 
-
 
279
 
-
 
280
    AsciiString = Field->Value;
-
 
281
    UnicodeString = (UINT16 *) Buffer;
-
 
282
    Count = ACPI_STRLEN (AsciiString) + 1;
-
 
283
 
-
 
284
    /* Convert to Unicode string (including null terminator) */
-
 
285
 
-
 
286
    for (i = 0; i < Count; i++)
-
 
287
    {
-
 
288
        UnicodeString[i] = (UINT16) AsciiString[i];
-
 
289
    }
-
 
290
}
-
 
291
 
-
 
292
 
-
 
293
/*******************************************************************************
-
 
294
 *
-
 
295
 * FUNCTION:    DtCompileUuid
-
 
296
 *
-
 
297
 * PARAMETERS:  Buffer              - Output buffer
-
 
298
 *              Field               - String to be copied to buffer
-
 
299
 *              ByteLength          - Maximum length of string
-
 
300
 *
-
 
301
 * RETURN:      None
-
 
302
 *
-
 
303
 * DESCRIPTION: Convert UUID string to 16-byte buffer
-
 
304
 *
-
 
305
 ******************************************************************************/
-
 
306
 
-
 
307
static ACPI_STATUS
-
 
308
DtCompileUuid (
-
 
309
    UINT8                   *Buffer,
-
 
310
    DT_FIELD                *Field,
-
 
311
    UINT32                  ByteLength)
-
 
312
{
-
 
313
    char                    *InString;
-
 
314
    ACPI_STATUS             Status;
-
 
315
 
-
 
316
 
-
 
317
    InString = Field->Value;
-
 
318
 
-
 
319
    Status = AuValidateUuid (InString);
-
 
320
    if (ACPI_FAILURE (Status))
-
 
321
    {
-
 
322
        sprintf (MsgBuffer, "%s", Field->Value);
-
 
323
        DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer);
-
 
324
    }
-
 
325
    else
-
 
326
    {
-
 
327
        Status = AuConvertStringToUuid (InString, (char *) Buffer);
-
 
328
    }
-
 
329
 
-
 
330
    return (Status);
-
 
331
}
-
 
332
 
234
 
333
 
235
/******************************************************************************
334
/******************************************************************************
236
 *
335
 *
237
 * FUNCTION:    DtCompileInteger
336
 * FUNCTION:    DtCompileInteger
238
 *
337
 *
-
 
338
 * PARAMETERS:  Buffer              - Output buffer
239
 * PARAMETERS:  Buffer              - Output buffer
339
 *              Field               - Field obj with Integer to be compiled
240
 *              Field               - Field obj with Integer to be compiled
340
 *              ByteLength          - Byte length of the integer
241
 *              ByteLength          - Byte length of the integer
341
 *              Flags               - Additional compile info
242
 *
342
 *
-
 
343
 * RETURN:      None
243
 * RETURN:      None
344
 *
244
 *
345
 * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
Line 245... Line 346...
245
 * DESCRIPTION: Compile an integer
346
 *              operators.
246
 *
347
 *
247
 *****************************************************************************/
348
 *****************************************************************************/
248
 
349
 
249
void
350
void
250
DtCompileInteger (
351
DtCompileInteger (
251
    UINT8                   *Buffer,
352
    UINT8                   *Buffer,
252
    DT_FIELD                *Field,
353
    DT_FIELD                *Field,
253
    UINT32                  ByteLength,
354
    UINT32                  ByteLength,
254
    UINT8                   Flags)
-
 
255
{
-
 
256
    UINT64                  Value = 0;
355
    UINT8                   Flags)
257
    UINT64                  MaxValue;
-
 
Line 258... Line 356...
258
    UINT8                   *Hex;
356
{
Line 259... Line 357...
259
    char                    *Message = NULL;
357
    UINT64                  Value;
260
    ACPI_STATUS             Status;
358
    UINT64                  MaxValue;
261
    int                     i;
359
    ACPI_STATUS             Status;
262
 
360
 
263
 
361
 
264
    /* Byte length must be in range 1-8 */
362
    /* Output buffer byte length must be in range 1-8 */
Line 265... Line 363...
265
 
363
 
Line 266... Line 364...
266
    if ((ByteLength > 8) || (ByteLength == 0))
364
    if ((ByteLength > 8) || (ByteLength == 0))
267
    {
365
    {
268
        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
366
        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
269
            "Invalid internal Byte length");
-
 
270
        return;
-
 
271
    }
-
 
272
 
-
 
273
    /* Convert string to an actual integer */
-
 
274
 
-
 
275
    Status = DtStrtoul64 (Field->Value, &Value);
-
 
276
    if (ACPI_FAILURE (Status))
-
 
277
    {
-
 
278
        if (Status == AE_LIMIT)
-
 
279
        {
367
            "Invalid internal Byte length");
280
            Message = "Constant larger than 64 bits";
368
        return;
Line 281... Line 369...
281
        }
369
    }
282
        else if (Status == AE_BAD_CHARACTER)
370
 
283
        {
371
    /* Resolve integer expression to a single integer value */
Line 315... Line 403...
315
 
403
 
Line 316... Line 404...
316
    /* Validate that the input value is within range of the target */
404
    /* Validate that the input value is within range of the target */
317
 
405
 
318
    if (Value > MaxValue)
406
    if (Value > MaxValue)
319
    {
407
    {
320
        sprintf (MsgBuffer, "Maximum %u bytes", ByteLength);
408
        sprintf (MsgBuffer, "%8.8X%8.8X", ACPI_FORMAT_UINT64 (Value));
Line 321... Line -...
321
        DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
-
 
322
    }
-
 
323
 
-
 
324
    /*
-
 
325
     * TBD: hard code for ASF! Capabilites field.
-
 
326
     *
-
 
327
     * This field is actually a buffer, not a 56-bit integer --
-
 
328
     * so, the ordering is reversed. Something should be fixed
-
 
329
     * so we don't need this code.
-
 
330
     */
-
 
331
    if (ByteLength == 7)
-
 
332
    {
-
 
333
        Hex = ACPI_CAST_PTR (UINT8, &Value);
-
 
334
        for (i = 6; i >= 0; i--)
-
 
335
        {
-
 
336
            Buffer[i] = *Hex;
-
 
337
            Hex++;
-
 
338
        }
-
 
339
        return;
-
 
340
    }
409
        DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
341
 
410
    }
342
Exit:
411
 
Line 343... Line 412...
343
    ACPI_MEMCPY (Buffer, &Value, ByteLength);
412
    ACPI_MEMCPY (Buffer, &Value, ByteLength);
344
    return;
413
    return;
345
}
414
}
346
 
415
 
347
 
416
 
-
 
417
/******************************************************************************
-
 
418
 *
348
/******************************************************************************
419
 * FUNCTION:    DtNormalizeBuffer
349
 *
420
 *
350
 * FUNCTION:    DtPciPathToBuffer
421
 * PARAMETERS:  Buffer              - Input buffer
351
 *
422
 *              Count               - Output the count of hex number in
352
 * PARAMETERS:  PciPath             - DMAR "PCI Path" field
423
 *                                    the Buffer
353
 *
424
 *
354
 * RETURN:      Strings of PCI path
425
 * RETURN:      The normalized buffer, freed by caller
Line 355... Line 426...
355
 *
426
 *
356
 * DESCRIPTION: Remove brackets and comma from DMAR "PCI Path" string, for
427
 * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized
357
 *              example: [1D, 01] ==> 1D 01
428
 *              to 1A 2B 3C 4D
-
 
429
 *
358
 *
430
 *****************************************************************************/
-
 
431
 
359
 *****************************************************************************/
432
static char *
-
 
433
DtNormalizeBuffer (
-
 
434
    char                    *Buffer,
-
 
435
    UINT32                  *Count)
-
 
436
{
-
 
437
    char                    *NewBuffer;
-
 
438
    char                    *TmpBuffer;
-
 
439
    UINT32                  BufferCount = 0;
-
 
440
    BOOLEAN                 Separator = TRUE;
-
 
441
    char                    c;
-
 
442
 
-
 
443
 
-
 
444
    NewBuffer = UtLocalCalloc (ACPI_STRLEN (Buffer) + 1);
-
 
445
    TmpBuffer = NewBuffer;
-
 
446
 
-
 
447
    while ((c = *Buffer++))
-
 
448
    {
-
 
449
        switch (c)
-
 
450
        {
-
 
451
        /* Valid separators */
-
 
452
 
Line -... Line 453...
-
 
453
        case '[':
-
 
454
        case ']':
-
 
455
        case ' ':
-
 
456
        case ',':
Line -... Line 457...
-
 
457
            Separator = TRUE;
-
 
458
            break;
-
 
459
 
360
 
460
        default:
-
 
461
            if (Separator)
Line 361... Line -...
361
static char *
-
 
362
DtPciPathToBuffer (
462
            {
363
    char                    *PciPath)
463
                /* Insert blank as the standard separator */
364
{
-
 
365
    char                    *Buffer;
-
 
Line -... Line 464...
-
 
464
 
-
 
465
                if (NewBuffer[0])
-
 
466
                {
-
 
467
                    *TmpBuffer++ = ' ';
-
 
468
                    BufferCount++;
-
 
469
                }
366
 
470
 
367
 
471
                Separator = FALSE;
Line 368... Line 472...
368
    Buffer = UtLocalCalloc (6);
472
            }
369
 
473
 
Line 405... Line 509...
405
    UINT64                  Value;
509
    UINT64                  Value;
406
    UINT32                  i;
510
    UINT32                  i;
407
    UINT32                  Count;
511
    UINT32                  Count;
Line -... Line 512...
-
 
512
 
-
 
513
 
408
 
514
    /* Allow several different types of value separators */
Line 409... Line 515...
409
 
515
 
410
    Count = ACPI_STRLEN (StringValue) / 3 + 1;
516
    StringValue = DtNormalizeBuffer (StringValue, &Count);
411
 
517
 
-
 
518
    Hex[2] = 0;
-
 
519
    for (i = 0; i < Count; i++)
412
    Hex[2] = 0;
520
    {
413
    for (i = 0; i < Count; i++)
521
        /* Each element of StringValue is three chars */
Line 414... Line 522...
414
    {
522
 
Line 415... Line 523...
415
        Hex[0] = StringValue[0];
523
        Hex[0] = StringValue[(3 * i)];
416
        Hex[1] = StringValue[1];
524
        Hex[1] = StringValue[(3 * i) + 1];
Line 424... Line 532...
424
            DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer);
532
            DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer);
425
            return (ByteLength - Count);
533
            return (ByteLength - Count);
426
        }
534
        }
Line 427... Line 535...
427
 
535
 
428
        Buffer[i] = (UINT8) Value;
-
 
429
        StringValue += 3;
536
        Buffer[i] = (UINT8) Value;
Line -... Line 537...
-
 
537
    }
430
    }
538
 
431
 
539
    ACPI_FREE (StringValue);
Line 432... Line 540...
432
    return (ByteLength - Count);
540
    return (ByteLength - Count);
433
}
541
}
434
 
-
 
435
 
-
 
436
/******************************************************************************
-
 
437
 *
-
 
438
 * FUNCTION:    DtCompilePciPath
-
 
439
 *
-
 
440
 * PARAMETERS:  Buffer              - Output buffer
-
 
441
 *              StringValue         - DMAR pci path string
-
 
442
 *              ByteLength          - Byte length of DMAR pci path string, 2
-
 
443
 *
-
 
444
 * RETURN:      None
-
 
445
 *
-
 
446
 * DESCRIPTION: Compile DMAR PCI path string to binary
-
 
447
 *
-
 
448
 *****************************************************************************/
-
 
449
 
-
 
450
static void
-
 
451
DtCompilePciPath (
-
 
452
    UINT8                   *Buffer,
-
 
453
    char                    *StringValue,
-
 
454
    DT_FIELD                *Field,
-
 
455
    UINT32                  ByteLength)
-
 
456
{
-
 
457
    char                    *PciPathBuffer;
-
 
458
 
-
 
459
 
-
 
460
    /* Parse path to simple hex digits, then convert to binary */
-
 
461
 
-
 
462
    PciPathBuffer = DtPciPathToBuffer (StringValue);
-
 
463
 
-
 
464
    DtCompileBuffer (Buffer, PciPathBuffer, Field, ByteLength);
-
 
465
    ACPI_FREE (PciPathBuffer);
-
 
466
}
-
 
467
 
542
 
468
 
543
 
469
/******************************************************************************
544
/******************************************************************************
470
 *
545
 *
471
 * FUNCTION:    DtCompileFlag
546
 * FUNCTION:    DtCompileFlag
472
 *
-
 
473
 * PARAMETERS:  Buffer              - Output buffer
547
 *
474
 *              Field               - Field to be compiled
548
 * PARAMETERS:  Buffer              - Output buffer
475
 *              Info                - Flag info
549
 *              Field               - Field to be compiled
476
 *              BitPosition         - Flag bit position
550
 *              Info                - Flag info
477
 *
551
 *
478
 * RETURN:      Next flag bit position
552
 * RETURN:
Line 479... Line 553...
479
 *
553
 *
480
 * DESCRIPTION: Compile a flag
554
 * DESCRIPTION: Compile a flag
481
 *
555
 *
482
 *****************************************************************************/
556
 *****************************************************************************/
483
 
557
 
484
UINT32
-
 
485
DtCompileFlag (
558
void
486
    UINT8                   *Buffer,
559
DtCompileFlag (
487
    DT_FIELD                *Field,
560
    UINT8                   *Buffer,
-
 
561
    DT_FIELD                *Field,
488
    ACPI_DMTABLE_INFO       *Info,
562
    ACPI_DMTABLE_INFO       *Info)
Line 489... Line 563...
489
    UINT32                  BitPosition)
563
{
490
{
564
    UINT64                  Value = 0;
Line 508... Line 582...
508
    case ACPI_DMT_FLAG4:
582
    case ACPI_DMT_FLAG4:
509
    case ACPI_DMT_FLAG5:
583
    case ACPI_DMT_FLAG5:
510
    case ACPI_DMT_FLAG6:
584
    case ACPI_DMT_FLAG6:
511
    case ACPI_DMT_FLAG7:
585
    case ACPI_DMT_FLAG7:
Line -... Line 586...
-
 
586
 
512
 
587
        BitPosition = Info->Opcode;
513
        BitLength = 1;
588
        BitLength = 1;
Line 514... Line 589...
514
        break;
589
        break;
-
 
590
 
-
 
591
    case ACPI_DMT_FLAGS0:
-
 
592
 
-
 
593
        BitPosition = 0;
-
 
594
        BitLength = 2;
-
 
595
        break;
515
 
596
 
Line -... Line 597...
-
 
597
 
516
    case ACPI_DMT_FLAGS0:
598
    case ACPI_DMT_FLAGS2:
517
    case ACPI_DMT_FLAGS2:
599
 
Line 518... Line 600...
518
 
600
        BitPosition = 2;
Line 532... Line 614...
532
        sprintf (MsgBuffer, "Maximum %u bit", BitLength);
614
        sprintf (MsgBuffer, "Maximum %u bit", BitLength);
533
        DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
615
        DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
534
        Value = 0;
616
        Value = 0;
535
    }
617
    }
Line 536... Line -...
536
 
-
 
537
    /* Insert the flag, return next flag bit position */
-
 
538
 
-
 
539
    Buffer += ACPI_DIV_8 (BitPosition);
618
 
540
    *Buffer |= (UINT8) (Value << ACPI_MOD_8 (BitPosition));
-
 
541
 
-
 
542
    return (BitPosition + BitLength);
619
    *Buffer |= (UINT8) (Value << BitPosition);