1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
|
/** @file
RISC-V IO Mapping Table (RIMT) parser
Copyright (c) 2025, Plasteli.net. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Reference(s):
- ACPI 6.6 Specification
- RISC-V IO Mapping Table (RIMT) Specification Version v1.0, 2025-03-31: Ratified
**/
#include <IndustryStandard/RiscVIoMappingTable.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiTableParser.h"
#define SIZE_OF_T(TYPE, Field) ((UINTN)sizeof(((TYPE *)0)->Field))
// Local variables
STATIC UINT8 *mRimtNodeType;
STATIC UINT16 *mRimtNodeLength;
STATIC EFI_ACPI_6_6_RIMT_STRUCTURE mRimtInfo;
STATIC CONST UINT32 *mNumberOfRimtNodes;
STATIC CONST UINT32 *mOffsetToRimtNodeArray;
STATIC CONST UINT16 *mNumberOfIdMappings;
STATIC UINT8 *mIdMappingArrayOffset;
/**
This function validates RIMT Node type.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Length Length of the field.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
RimtValidateNodeType (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 NodeType = *(UINT8 *)Ptr;
if (NodeType >= RimtNodeUnsupported) {
IncrementErrorCount ();
Print (L"\nERROR: Unrecognized RIMT node type. Type value must be less than %d but got %d", RimtNodeUnsupported, NodeType);
}
}
/**
This function traces RIMT IOMMU Node Type field and presents in
human-readable form.
@param [in] Format Optional format string for tracing the data.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the field.
**/
STATIC
VOID
EFIAPI
RimtNodeTypeToStr (
CONST CHAR16 *Format,
UINT8 *Ptr,
UINT32 Length
)
{
CHAR8 *Str;
UINT8 NodeType;
NodeType = *(UINT8 *)Ptr;
if (NodeType == RimtNodeIommu) {
Str = "IOMMU";
} else if (NodeType == RimtNodePcieRc) {
Str = "PCIe Root Complex";
} else if (NodeType == RimtNodePlatform) {
Str = "Platform Device";
} else {
Str = "Unknown";
}
AsciiPrint (Str);
}
/**
Helper Macro for populating the RIMT Node header in the ACPI_PARSER array.
Every RIMT Node (IOMMU, PCIe Root Complex, PLatform Device) has this header
common
**/
#define RIMT_PARSE_NODE_HEADER \
{ L"Type", \
SIZE_OF_T(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Type), \
OFFSET_OF(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Type), \
NULL, \
RimtNodeTypeToStr, \
(VOID**)&mRimtNodeType, \
RimtValidateNodeType, \
NULL \
}, \
{ L"Revision", \
SIZE_OF_T(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Revision),\
OFFSET_OF(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Revision),\
L"%d", \
NULL, \
NULL, \
NULL, \
NULL \
}, \
{ L"Length", \
SIZE_OF_T(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Length), \
OFFSET_OF(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Length), \
L"%d", \
NULL, \
(VOID**)&mRimtNodeLength, \
NULL, \
NULL \
}, \
{ L"Reserved", \
SIZE_OF_T(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Reserved),\
OFFSET_OF(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Reserved),\
L"0x%x", \
NULL, \
NULL, \
NULL, \
NULL \
}, \
{ L"Id", \
SIZE_OF_T(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Id), \
OFFSET_OF(EFI_ACPI_6_6_RIMT_NODE_HEADER_STRUCTURE, Id), \
L"%d", \
NULL, \
NULL, \
NULL, \
NULL \
} \
/**
An ACPI_PARSER array describing Parser for the RIMT node header structure.
**/
STATIC CONST ACPI_PARSER mRimtNodeHeaderParser[] = {
RIMT_PARSE_NODE_HEADER
};
/**
This function validates number of RIMT nodes.
According to RIMT spec, Chapter 2.1, system with a single IOMMU,
should have at least two RIMT nodes
@param [in] Ptr Pointer to the start of the field data.
@param [in] Length Length of the field.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
RimtValidateNumberOfNodes (
UINT8 *Ptr,
UINT32 Length,
VOID *Context
)
{
UINT32 NumNodes;
NumNodes = *(UINT32 *)Ptr;
if (NumNodes < RIMT_MINIMAL_NUMBER_OF_NODES_ALLOWED) {
IncrementErrorCount ();
Print (L"\nERROR: Minimal Number of RIMT nodes must be at least %d.", RIMT_MINIMAL_NUMBER_OF_NODES_ALLOWED);
}
}
/**
An ACPI_PARSER array describing the RIMT (RISC-V IO Mapping Table).
**/
STATIC CONST ACPI_PARSER mRimtParser[] = {
PARSE_ACPI_HEADER (&mRimtInfo.Header),
{
L"Number of RIMT Nodes",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_STRUCTURE,NumberOfRimtNodes),
OFFSET_OF (EFI_ACPI_6_6_RIMT_STRUCTURE,NumberOfRimtNodes),
L"%d",
NULL,
(VOID **)&mNumberOfRimtNodes,
RimtValidateNumberOfNodes,
NULL
},
{
L"Offset to RIMT Node Array",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_STRUCTURE,OffsetToRimtNodeArray),
OFFSET_OF (EFI_ACPI_6_6_RIMT_STRUCTURE,OffsetToRimtNodeArray),
L"0x%x",
NULL,
(VOID **)&mOffsetToRimtNodeArray,
NULL,
NULL
},
{
L"Reserved",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_STRUCTURE,Reserved),
OFFSET_OF (EFI_ACPI_6_6_RIMT_STRUCTURE,Reserved),
L"0x%x",
NULL,
NULL,
NULL,
NULL
}
};
/**
This macro generates function definition for parser tracing
Flags field of RIMT Node.
@param [in] Parser An ACPI_PARSER for tracing the data.
**/
#define RIMT_DECLARE_NODE_FLAGS_PARSER_FUNC(Parser) \
STATIC \
VOID \
EFIAPI \
_RimtNodeFlagsParser ## Parser ( \
CONST CHAR16 *Format, \
UINT8 *Ptr, \
UINT32 Length \
) \
{ \
UINT32* Flags; \
\
Flags = (UINT32 *)Ptr; \
Print (L"0x%X\n", *Flags); \
ParseAcpiBitFields ( \
TRUE, \
2, \
NULL, \
(UINT8 *)Flags, \
sizeof(Flags), \
PARSER_PARAMS (Parser) \
); \
} \
#define RIMT_GET_NODE_FLAGS_PARSER_FUNC(Parser) _RimtNodeFlagsParser ## Parser
/**
This macro generates function definition which traces bits in Flags field.
@param [in] Parser Optional format string for tracing the data.
@param [in] Active String to display if interpreted bit is active.
@param [in] Inactive String to display if interpreted bit is inactive.
**/
#define RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC(Parser, Active, Inactive) \
STATIC \
VOID \
EFIAPI \
_RimtFlagsToStr ## Parser ( \
CONST CHAR16 *Format OPTIONAL, \
UINT8 *Ptr, \
UINT32 Length \
) \
{ \
CHAR8 *Str; \
\
if ((*(UINT32 *)Ptr & 0x1) == 1) \
Str = #Active ; \
else \
Str = #Inactive ; \
AsciiPrint (Str); \
} \
/**
This macro gets generated function name which traces bits in Flags field
defined by DECLARE_FLAG_INTERPRETER()
**/
#define RIMT_GET_FLAGS_BIT_PARSER_FUNC(interpreter) _RimtFlagsToStr ## interpreter
/**
This function prints Hardwareld field.
If no format string is specified the Format must be NULL.
@param [in] Format Optional format string for tracing the data.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the field.
**/
STATIC
VOID
EFIAPI
RimtHardwareIdToStr (
CONST CHAR16 *Format,
UINT8 *Ptr,
UINT32 Length
)
{
UINT64 *HardwareId; // RIMT specifies HardwareId field as 8-byte long
CHAR8 Buffer[9];
HardwareId = (UINT64 *)Ptr;
AsciiStrnCpyS (Buffer, sizeof (Buffer), (CHAR8 *)HardwareId, sizeof (*HardwareId));
AsciiPrint (Buffer);
Print (L" (0x%lx)", *HardwareId);
}
RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC (IommuType, "PCIe", "Platform");
RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC (ProximityDomain, "Valid", "Invalid");
STATIC CONST ACPI_PARSER RimtIommuFlagParser[] = {
{
L"Device Type",
RIMT_IOMMU_FLAGS_TYPE_BIT_COUNT,
RIMT_IOMMU_FLAGS_TYPE_BIT_OFFSET,
NULL,
RIMT_GET_FLAGS_BIT_PARSER_FUNC (IommuType),
NULL, NULL, NULL
},
{
L"Proximity Domain",
RIMT_IOMMU_FLAGS_PROXIMITY_DOMAIN_BIT_COUNT,
RIMT_IOMMU_FLAGS_PROXIMITY_DOMAIN_BIT_OFFSET,
NULL,
RIMT_GET_FLAGS_BIT_PARSER_FUNC (ProximityDomain),
NULL, NULL, NULL
},
{
L"Reserved",
30,
2,
L"0x%x",
NULL,
NULL, NULL, NULL
}
};
RIMT_DECLARE_NODE_FLAGS_PARSER_FUNC (RimtIommuFlagParser);
/**
An ACPI_PARSER array describing the IOMMU Node.
**/
STATIC CONST ACPI_PARSER RimtIommuNodeParser[] = {
RIMT_PARSE_NODE_HEADER,
{
L"Hardware ID",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, HardwareId),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, HardwareId),
NULL,
RimtHardwareIdToStr,
NULL,
NULL,
NULL
},
{
L"Base Address",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, BaseAddress),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, BaseAddress),
L"0x%lx",
NULL,
NULL,
NULL,
NULL
},
{
L"Flags",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, Flags),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, Flags),
NULL,
RIMT_GET_NODE_FLAGS_PARSER_FUNC (RimtIommuFlagParser),
NULL,
NULL,
NULL
},
{
L"Proximity Domain",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, ProximityDomain),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, ProximityDomain),
L"%d",
NULL,
NULL,
NULL,
NULL
},
{
L"PCIe Segment number",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, PcieSegmentNumber),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, PcieSegmentNumber),
L"0x%x",
NULL,
NULL,
NULL,
NULL
},
{
L"PCIe B/D/F",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, PcieBdf),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, PcieBdf),
L"%d",
NULL,
NULL,
NULL,
NULL
},
{
L"Number of interrupt wires",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, NumberOfInterruptWires),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, NumberOfInterruptWires),
L"0x%x",
NULL,
NULL,
NULL,
NULL
},
{
L"Interrupt wire array offset",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, InterruptWireArrayOffset),
OFFSET_OF (EFI_ACPI_6_6_RIMT_IOMMU_NODE_STRUCTURE, InterruptWireArrayOffset),
L"0x%x",
NULL,
NULL,
NULL,
NULL
}
};
/**
This function parses the RIMT IOMMU node.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the buffer.
**/
STATIC
VOID
EFIAPI
RimtParseIommuNode (
IN UINT8 *Ptr,
IN UINT16 Length,
IN UINT32 Index
)
{
CHAR8 Buffer[32];
AsciiSPrint (
Buffer,
sizeof (Buffer),
"RIMT Node [%d]",
Index
);
ParseAcpi (
TRUE,
2,
Buffer,
Ptr,
Length,
PARSER_PARAMS (RimtIommuNodeParser)
);
}
RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC (IdMappingAtsSupport, "Required", "Not Required");
RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC (IdMappingPriSupport, "Required", "Not Required");
STATIC CONST ACPI_PARSER RimtIdMappingFlagParser[] = {
{
L"ATS",
RIMT_ID_MAPPING_FLAGS_ATS_BIT_COUNT,
RIMT_ID_MAPPING_FLAGS_ATS_BIT_OFFSET,
NULL,
RIMT_GET_FLAGS_BIT_PARSER_FUNC (IdMappingAtsSupport),
NULL, NULL, NULL
},
{
L"PRI",
RIMT_ID_MAPPING_FLAGS_PRI_BIT_COUNT,
RIMT_ID_MAPPING_FLAGS_PRI_BIT_OFFSET,
NULL,
RIMT_GET_FLAGS_BIT_PARSER_FUNC (IdMappingPriSupport),
NULL, NULL, NULL
},
{
L"Reserved",
30,
2,
L"0x%x",
NULL,
NULL, NULL, NULL
}
};
RIMT_DECLARE_NODE_FLAGS_PARSER_FUNC (RimtIdMappingFlagParser);
/**
An ACPI_PARSER array describing the ID Mapping Node.
**/
STATIC CONST ACPI_PARSER RimtIdMappingNodeParser[] = {
{
L"Source ID Base",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, SourceIdBase),
OFFSET_OF (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, SourceIdBase),
L"0x%x",
NULL,
NULL, NULL, NULL
},
{
L"Number of IDs",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, NumberOfIDs),
OFFSET_OF (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, NumberOfIDs),
L"%d",
NULL,
NULL, NULL, NULL
},
{
L"Destination Device ID Base",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, DestinationDeviceIdBase),
OFFSET_OF (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, DestinationDeviceIdBase),
L"%d",
NULL,
NULL, NULL, NULL
},
{
L"Destination IOMMU Offset",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, DestinationIommuOffset),
OFFSET_OF (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, DestinationIommuOffset),
L"0x%x",
NULL,
NULL, NULL, NULL
},
{
L"Flags",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, Flags),
OFFSET_OF (EFI_ACPI_6_6_RIMT_ID_MAPPING_STRUCTURE, Flags),
NULL,
RIMT_GET_NODE_FLAGS_PARSER_FUNC (RimtIdMappingFlagParser),
NULL, NULL, NULL
},
};
/**
This function parses the RIMT ID Mapping node.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the buffer.
@retval Number of bytes parsed.
**/
STATIC
VOID
EFIAPI
RimtParseIdMappingArray (
IN UINT8 *Node,
IN UINT16 Length,
IN UINT32 NumberOfIdMappings
)
{
UINT32 Index;
UINT32 Offset;
CHAR8 Buffer[32];
Index = 0;
Offset = 0;
while ((Index < NumberOfIdMappings) &&
(Offset < Length))
{
AsciiSPrint (
Buffer,
sizeof (Buffer),
"ID Mapping [%d]",
Index
);
Offset += ParseAcpi (
TRUE,
4,
Buffer,
Node + Offset,
Length - Offset,
PARSER_PARAMS (RimtIdMappingNodeParser)
);
++Index;
}
}
RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC (PcieRcAtsSupport, "Supported", "Not Supported");
RIMT_DECLARE_FLAGS_BIT_PARSER_FUNC (PcieRcPriSupport, "Supported", "Not Supported");
STATIC CONST ACPI_PARSER RimtPcieRcFlagParser[] = {
{
L"ATS",
RIMT_PCIERC_FLAGS_ATS_BIT_COUNT, RIMT_PCIERC_FLAGS_ATS_BIT_OFFSET,
NULL,
RIMT_GET_FLAGS_BIT_PARSER_FUNC (PcieRcAtsSupport),
NULL, NULL, NULL
},
{
L"PRI",
RIMT_PCIERC_FLAGS_PRI_BIT_COUNT, RIMT_PCIERC_FLAGS_PRI_BIT_OFFSET,
NULL,
RIMT_GET_FLAGS_BIT_PARSER_FUNC (PcieRcPriSupport),
NULL, NULL, NULL
},
{
L"Reserved",
30,
2,
L"0x%x",
NULL,
NULL, NULL, NULL
}
};
RIMT_DECLARE_NODE_FLAGS_PARSER_FUNC (RimtPcieRcFlagParser);
/**
An ACPI_PARSER array describing the Pcie Root Complex Node.
**/
STATIC CONST ACPI_PARSER RimtPcieRcNodeParser[] = {
RIMT_PARSE_NODE_HEADER,
{
L"Flags",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,Flags),
OFFSET_OF (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,Flags),
NULL,
RIMT_GET_NODE_FLAGS_PARSER_FUNC (RimtPcieRcFlagParser),
NULL,
NULL,
NULL
},
{
L"Reserved",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,Reserved),
OFFSET_OF (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,Reserved),
L"0x%lx",
NULL,
NULL,
NULL,
NULL
},
{
L"PCIe Segment Number",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,PcieSegmentNumber),
OFFSET_OF (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,PcieSegmentNumber),
L"%d",
NULL,
NULL,
NULL,
NULL
},
{
L"Id Mapping Array Offset",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,IdMappingArrayOffset),
OFFSET_OF (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,IdMappingArrayOffset),
L"0x%x",
NULL,
(VOID **)&mIdMappingArrayOffset,
NULL,
NULL
},
{
L"Number Of Id Mappings",
SIZE_OF_T (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,NumberOfIdMappings),
OFFSET_OF (EFI_ACPI_6_6_RIMT_PCIE_ROOT_COMPLEX_NODE_STRUCTURE,NumberOfIdMappings),
L"%d",
NULL,
(VOID **)&mNumberOfIdMappings,
NULL,
NULL
},
};
/**
This function parses the RIMT Pcie Root Complex node.
This function parses also Id Mappings related to this PCIe Root Complex
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the buffer.
**/
STATIC
VOID
EFIAPI
RimtParsePcieRcNode (
IN UINT8 *Ptr,
IN UINT16 Length,
IN UINT32 Index
)
{
UINT8 *IdMappingArray;
UINT8 *PcieRootComplexNode;
CHAR8 Buffer[32];
PcieRootComplexNode = Ptr;
AsciiSPrint (
Buffer,
sizeof (Buffer),
"RIMT Node [%d]",
Index
);
ParseAcpi (
TRUE,
2,
Buffer,
PcieRootComplexNode,
Length,
PARSER_PARAMS (RimtPcieRcNodeParser)
);
IdMappingArray = PcieRootComplexNode + *mIdMappingArrayOffset;
RimtParseIdMappingArray (
IdMappingArray,
Length - *mIdMappingArrayOffset,
*mNumberOfIdMappings
);
}
/**
This function parses the RIMT Platform Device node.
TODO: Add parsers when PLatform Device node generator in Qemu is ready.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the buffer.
**/
STATIC
VOID
EFIAPI
RimtParsePlatformDeviceNode (
IN UINT8 *Ptr,
IN UINT16 Length,
IN UINT32 Index
)
{
Print (L"WARNING: Platform type of RIMT Node not supported yet.\n");
}
/**
This function parses the ACPI RIMT table.
When trace is enabled this function parses the RIMT table and
traces the ACPI table fields.
@param [in] Trace If TRUE, trace the ACPI fields.
@param [in] Rimt Pointer to the start of the RIMT buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in] AcpiTableRevision Revision of the ACPI table.
**/
VOID
EFIAPI
ParseAcpiRimt (
IN BOOLEAN Trace,
IN UINT8 *Rimt,
IN UINT32 AcpiTableLength,
IN UINT8 AcpiTableRevision
)
{
UINT8 *NodePtr;
UINT32 Offset;
UINT32 Index;
if (!Trace) {
return;
}
ParseAcpi (
Trace,
0,
"RIMT",
Rimt,
AcpiTableLength,
PARSER_PARAMS (mRimtParser)
);
// Check if the values used to control the parsing logic have been
// successfully read.
if ((mNumberOfRimtNodes == NULL) ||
(mOffsetToRimtNodeArray == NULL))
{
IncrementErrorCount ();
Print (
L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
AcpiTableLength
);
return;
}
Offset = *mOffsetToRimtNodeArray;
NodePtr = Rimt + Offset;
Index = 0;
while ((Index < *mNumberOfRimtNodes) &&
(Offset < AcpiTableLength))
{
// Parse the RIMT Node Header
ParseAcpi (
FALSE,
0,
"RIMT Node Header",
NodePtr,
AcpiTableLength - Offset,
PARSER_PARAMS (mRimtNodeHeaderParser)
);
// Check if the values used to control the parsing logic have been
// successfully read.
if ((mRimtNodeType == NULL) ||
(mRimtNodeLength == NULL))
{
IncrementErrorCount ();
Print (
L"ERROR: Insufficient remaining table buffer length to read the " \
L"RIMT node header. Length = %d.\n",
AcpiTableLength - Offset
);
return;
}
// Validate RIMT Node length
if ((*mRimtNodeLength == 0) ||
((Offset + (*mRimtNodeLength)) > AcpiTableLength))
{
IncrementErrorCount ();
Print (
L"ERROR: Invalid RIMT Node length. " \
L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
*mRimtNodeLength,
Offset,
AcpiTableLength
);
return;
}
switch (*mRimtNodeType) {
case RimtNodeIommu:
RimtParseIommuNode (
NodePtr,
*mRimtNodeLength,
Index
);
break;
case RimtNodePcieRc:
RimtParsePcieRcNode (
NodePtr,
*mRimtNodeLength,
Index
);
break;
case RimtNodePlatform:
RimtParsePlatformDeviceNode (
NodePtr,
*mRimtNodeLength,
Index
);
break;
default:
IncrementErrorCount ();
Print (L"ERROR: Unsupported RIMT Node type = %d\n", *mRimtNodeType);
} // switch
Index++;
NodePtr += (*mRimtNodeLength);
Offset += (*mRimtNodeLength);
}
}
|