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
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
|
/** @file
MPAM table parser
Copyright (c) 2024, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Specification Reference:
- [1] ACPI for Memory System Resource Partitioning and Monitoring 2.0
(https://developer.arm.com/documentation/den0065/latest)
@par Glossary:
- MPAM - Memory System Resource Partitioning And Monitoring
- MSC - Memory System Component
- PCC - Platform Communication Channel
- RIS - Resource Instance Selection
- SMMU - Arm System Memory Management Unit
**/
#include <IndustryStandard/Mpam.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiView.h"
#include "AcpiViewConfig.h"
// Local variables
STATIC CONST UINT8 *MscInterfaceType;
STATIC CONST UINT8 *ResourceLocatorType;
STATIC UINT32 MpamMscNodeStart;
STATIC CONST UINT16 *MpamMscNodeLength;
STATIC CONST UINT32 *NumberOfMscResources;
STATIC CONST UINT32 *NumberOfFunctionalDependencies;
STATIC CONST UINT32 *NumberOfInterconnectDescriptors;
STATIC CONST UINT64 *InterconnectTableOffset;
STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
// Array of locator type names. New types should be added keeping the order
// preserved as locator type is used to index into the array while parsing.
STATIC CONST CHAR16 *MpamMscLocatorTitles[] = {
L"Processor cache",
L"Memory",
L"SMMU",
L"Memory cache",
L"ACPI device",
L"Interconnect"
};
/**
When the length of the table is insufficient to be parsed, this function could
be used to display an appropriate error message.
@param [in] ErrorMsg Error message string that has to be appended to the
main error log. This string could explain the reason
why a insufficient length error was encountered in
the first place.
**/
STATIC
VOID
EFIAPI
MpamLengthError (
IN CONST CHAR16 *ErrorMsg
)
{
IncrementErrorCount ();
Print (L"\nERROR : ");
Print (ErrorMsg);
Print (
L"\nError : Insufficient MPAM MSC Node length. Table length : %u.\n",
*(AcpiHdrInfo.Length)
);
}
/**
This function validates the MMIO size within the MSC node body for MPAM ACPI
table. MPAM ACPI specification states that the MMIO size for an MSC having PCC
type interface should be zero.
@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. For this
function, context holds the parent/double pointer to a
variable holding the interface type. Make sure to call
the function accordingly.
**/
STATIC
VOID
EFIAPI
ValidateMmioSize (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InterfaceType;
UINT32 MmioSize;
InterfaceType = *MscInterfaceType;
if (InterfaceType == EFI_ACPI_MPAM_INTERFACE_PCC) {
MmioSize = *((UINT32 *)Ptr);
if (MmioSize > 1) {
IncrementErrorCount ();
Print (
L"\nERROR: MMIO size must be 0 or 1 for PCC interface type. Size - %u\n",
MmioSize
);
}
}
}
/**
This function decodes and validates the link type for MPAM's interconnect
descriptor. Valid links are of NUMA and PROC 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. For this
function, context is ignored.
**/
STATIC
VOID
EFIAPI
DecodeLinkType (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 LinkType;
LinkType = *Ptr;
if (LinkType == EFI_ACPI_MPAM_LINK_TYPE_NUMA) {
Print (
L" (NUMA)"
);
} else if (LinkType == EFI_ACPI_MPAM_LINK_TYPE_PROC) {
Print (
L" (PROC)"
);
} else {
IncrementErrorCount ();
Print (
L"\nERROR: Invalid link type - %u\n",
(UINT32)LinkType
);
}
}
/**
This function decodes the hardware ID field present within MPAM ACPI table.
The specification states that the hardware ID has to be set to zero if not
being used.
@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. For this
function, context is ignored.
**/
STATIC
VOID
EFIAPI
DecodeHardwareId (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT64 HardwareId;
HardwareId = *((UINT64 *)Ptr);
if (HardwareId != 0) {
Print (L" (");
Dump8Chars (NULL, Ptr, Length);
Print (L")");
}
}
/**
This function decodes and validates the interface type for MPAM. Valid
interfaces are of MMIO and PCC 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. For this
function, context is ignored.
**/
STATIC
VOID
EFIAPI
DecodeInterfaceType (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InterfaceType;
InterfaceType = *Ptr;
if (InterfaceType == EFI_ACPI_MPAM_INTERFACE_MMIO) {
Print (L" (MMIO)");
} else if (InterfaceType == EFI_ACPI_MPAM_INTERFACE_PCC) {
Print (L" (PCC)");
} else {
IncrementErrorCount ();
Print (
L"\nERROR: Invalid interface type - %u\n",
(UINT32)InterfaceType
);
}
}
/**
This function decodes the interrupt mode flag for MPAM. Interrupt mode could
either be "edge triggered" or "level triggered".
@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. For this
function, context holds the parent/double pointer to a
variable holding the interrupt gsiv. Make sure to call
the function accordingly.
**/
STATIC
VOID
EFIAPI
DecodeInterruptMode (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InterruptMode;
InterruptMode = *Ptr;
if (InterruptMode == EFI_ACPI_MPAM_INTERRUPT_LEVEL_TRIGGERED) {
Print (L" (Level triggered)");
} else {
Print (L" (Edge triggered)");
}
}
/**
This function decodes the interrupt type flag for MPAM. Interrupt type could
be "wired interrupt". Other values are reserved at this point.
@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. For this
function, context holds the parent/double pointer to a
variable holding the interrupt gsiv. Make sure to call
the function accordingly.
**/
STATIC
VOID
EFIAPI
DecodeInterruptType (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InterruptType;
InterruptType = *Ptr;
if (InterruptType == EFI_ACPI_MPAM_INTERRUPT_WIRED) {
Print (L" (Wired interrupt)");
} else {
IncrementWarningCount ();
Print (L" (Reserved value!)");
}
}
/**
This function decodes the interrupt affinity valid flag for MPAM. Interrupt
affinity could be either be valid or not.
@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. For this
function, context holds the parent/double pointer to a
variable holding the interrupt gsiv. Make sure to call
the function accordingly.
**/
STATIC
VOID
EFIAPI
DecodeInterruptAffinityValid (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InterruptAffinityValid;
InterruptAffinityValid = *Ptr;
if (InterruptAffinityValid != EFI_ACPI_MPAM_INTERRUPT_AFFINITY_VALID) {
Print (L" (Affinity not valid)");
} else {
Print (L" (Affinity valid)");
}
}
/**
This function decodes the interrupt affinity type flag for MPAM. Interrupt
affinity type could either be "Processor affinity" or "Processor container
affinity"
@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. For this
function, context holds the parent/double pointer to a
variable holding the interrupt gsiv. Make sure to call
the function accordingly.
**/
STATIC
VOID
EFIAPI
DecodeInterruptAffinityType (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InterruptAffinityType;
InterruptAffinityType = *Ptr;
if (InterruptAffinityType == EFI_ACPI_MPAM_INTERRUPT_PROCESSOR_AFFINITY) {
Print (L" (Processor affinity)");
} else {
Print (L" (Processor container affinity)");
}
}
/**
This function decodes the locator type for a particular MPAM MSC resource.
@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. For this
function, context holds the parent/double pointer to a
variable holding the interrupt gsiv. Make sure to call
the function accordingly.
**/
STATIC
VOID
EFIAPI
DecodeLocatorType (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 LocatorType;
LocatorType = *Ptr;
if (LocatorType <= EFI_ACPI_MPAM_LOCATION_INTERCONNECT) {
Print (L" (%s)", MpamMscLocatorTitles[LocatorType]);
} else if (LocatorType == EFI_ACPI_MPAM_LOCATION_UNKNOWN) {
Print (L" (Unknown)");
} else {
Print (L" (Reserved)");
}
}
/**
ACPI_PARSER array describing MPAM MSC interrupt flags.
**/
STATIC CONST ACPI_PARSER MpamMscInterruptFlagParser[] = {
{ L"Interrupt Mode", 1, 0, L"%u", NULL, NULL,
DecodeInterruptMode, NULL },
{ L"Interrupt Type", 2, 1, L"%u", NULL, NULL,
DecodeInterruptType, NULL },
{ L"Affinity Type", 1, 3, L"%u", NULL, NULL,
DecodeInterruptAffinityType, NULL },
{ L"Affinity Valid", 1, 4, L"%u", NULL, NULL,
DecodeInterruptAffinityValid, NULL },
{ L"Reserved", 27, 5, NULL, DumpReservedBits, NULL,
ValidateReservedBits, NULL }
};
/**
This function traces MPAM MSC Interrupt Flags.
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
DumpMpamMscInterruptFlags (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr,
IN UINT32 Length
)
{
Print (L"%u\n", *(UINT32 *)Ptr);
ParseAcpiBitFields (
TRUE,
2,
NULL,
Ptr,
4,
PARSER_PARAMS (MpamMscInterruptFlagParser)
);
}
/**
ACPI_PARSER array describing the MPAM MSC processor cache locator field.
**/
STATIC CONST ACPI_PARSER MpamMscProcessorCacheLocatorParser[] = {
{ L"Cache reference", 8, 0, L"%lu", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 8, NULL, DumpReserved, NULL,
ValidateReserved, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC memory locator field.
**/
STATIC CONST ACPI_PARSER MpamMscMemoryLocatorParser[] = {
{ L"Proximity domain", 8, 0, L"%lu", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 8, NULL, DumpReserved, NULL,
ValidateReserved, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC SMMU locator field.
**/
STATIC CONST ACPI_PARSER MpamMscSMMULocatorParser[] = {
{ L"SMMU interface", 8, 0, L"%lu", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 8, NULL, DumpReserved, NULL,
ValidateReserved, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC memory cache locator field.
**/
STATIC CONST ACPI_PARSER MpamMscMemoryCacheLocatorParser[] = {
{ L"Reserved", 7, 0, NULL, DumpReserved, NULL,
ValidateReserved, NULL },
{ L"Level", 1, 7, L"%u", NULL, NULL,NULL, NULL },
{ L"Reference", 4, 8, L"%u", NULL, NULL,NULL, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC ACPI device locator field.
**/
STATIC CONST ACPI_PARSER MpamMscAcpiDeviceLocatorParser[] = {
{ L"ACPI hardware ID", 8, 0, L"0x%lx", NULL, NULL,
DecodeHardwareId, NULL },
{ L"ACPI unique ID", 4, 8, L"%u", NULL, NULL,NULL,NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC interconnect locator field.
**/
STATIC CONST ACPI_PARSER MpamMscInterconnectLocatorParser[] = {
{ L"Interconnect desc tbl offset", 8, 0, L"%lu", NULL,
(VOID **)&InterconnectTableOffset, NULL, NULL },
{ L"Reserved", 4, 8, NULL, DumpReserved,
NULL, ValidateReserved, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC generic resource locator field.
**/
STATIC CONST ACPI_PARSER MpamMscGenericLocatorParser[] = {
{ L"Descriptor1", 8, 0, L"%lu", NULL, NULL, NULL, NULL },
{ L"Descriptor2", 4, 8, L"%u", NULL, NULL, NULL, NULL }
};
/**
This function parses the locator field within the resource node for ACPI MPAM
table. The parsing is based on the locator type field.
@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
ParseLocator (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr,
IN UINT32 Length
)
{
Print (L"\n");
switch (*ResourceLocatorType) {
case EFI_ACPI_MPAM_LOCATION_PROCESSOR_CACHE:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscProcessorCacheLocatorParser)
);
break;
case EFI_ACPI_MPAM_LOCATION_MEMORY:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscMemoryLocatorParser)
);
break;
case EFI_ACPI_MPAM_LOCATION_SMMU:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscSMMULocatorParser)
);
break;
case EFI_ACPI_MPAM_LOCATION_MEMORY_CACHE:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscMemoryCacheLocatorParser)
);
break;
case EFI_ACPI_MPAM_LOCATION_ACPI_DEVICE:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscAcpiDeviceLocatorParser)
);
break;
case EFI_ACPI_MPAM_LOCATION_INTERCONNECT:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscInterconnectLocatorParser)
);
break;
// For both UNKNOWN and RESERVED locator types, the locator is parsed using
// the generic locator parser as the spec does not define any format.
case EFI_ACPI_MPAM_LOCATION_UNKNOWN:
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscGenericLocatorParser)
);
break;
default:
Print (L"\nWARNING : Reserved locator type\n");
ParseAcpi (
TRUE,
2,
NULL,
Ptr,
12,
PARSER_PARAMS (MpamMscGenericLocatorParser)
);
IncrementWarningCount ();
break;
} // switch
}
/**
ACPI_PARSER array describing the Generic ACPI MPAM table header.
**/
STATIC CONST ACPI_PARSER MpamParser[] = {
PARSE_ACPI_HEADER (&AcpiHdrInfo)
};
/**
ACPI_PARSER array describing the MPAM MSC node object.
**/
STATIC CONST ACPI_PARSER MpamMscNodeParser[] = {
{ L"Length", 2, 0, L"%u", NULL,
(VOID **)&MpamMscNodeLength, NULL, NULL },
// Once Interface type is decoded, the address of interface type field is
// captured into InterfaceType pointer so that it could be used to check if
// MMIO Size field is set as per the specification.
{ L"Interface type", 1, 2, L"0x%x", NULL,
(VOID **)&MscInterfaceType, DecodeInterfaceType, NULL },
{ L"Reserved", 1, 3, NULL, DumpReserved,
NULL, ValidateReserved, NULL },
{ L"Identifier", 4, 4, L"%u", NULL,
NULL, NULL, NULL },
{ L"Base address", 8, 8, L"0x%lx", NULL,
NULL, NULL, NULL },
{ L"MMIO Size", 4, 16, L"0x%x", NULL,
NULL, ValidateMmioSize, (VOID **)&MscInterfaceType },
{ L"Overflow interrupt", 4, 20, L"%u", NULL,
NULL, NULL, NULL },
{ L"Overflow interrupt flags", 4, 24, NULL, DumpMpamMscInterruptFlags,
NULL, NULL, NULL },
{ L"Reserved1", 4, 28, NULL, DumpReserved,
NULL, ValidateReserved, NULL },
{ L"Overflow interrupt affinity", 4, 32, L"0x%x", NULL,
NULL, NULL, NULL },
{ L"Error interrupt", 4, 36, L"%u", NULL,
NULL, NULL, NULL },
{ L"Error interrupt flags", 4, 40, NULL, DumpMpamMscInterruptFlags,
NULL, NULL, NULL },
{ L"Reserved2", 4, 44, NULL, DumpReserved,
NULL, ValidateReserved, NULL },
{ L"Error interrupt affinity", 4, 48, L"0x%x", NULL,
NULL, NULL, NULL },
{ L"MAX_NRDY_USEC", 4, 52, L"0x%x", NULL,
NULL, NULL, NULL },
{ L"Hardware ID of linked device", 8, 56, L"0x%lx", NULL,
NULL, DecodeHardwareId, NULL },
{ L"Instance ID of linked device", 4, 64, L"0x%x", NULL,
NULL, NULL, NULL },
{ L"Number of resource nodes", 4, 68, L"%u", NULL,
(VOID **)&NumberOfMscResources, NULL, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC resource.
**/
STATIC CONST ACPI_PARSER MpamMscResourceParser[] = {
{ L"Identifier", 4, 0, L"%u", NULL,
NULL, NULL, NULL },
{ L"RIS index", 1, 4, L"%u", NULL,
NULL, NULL, NULL },
{ L"Reserved1", 2, 5, NULL, DumpReserved,
NULL, ValidateReserved, NULL },
{ L"Locator type", 1, 7, L"0x%x", NULL,
(VOID **)&ResourceLocatorType,
DecodeLocatorType, NULL },
{ L"Locator", 12, 8, NULL, ParseLocator,
NULL, NULL, NULL },
{ L"Number of func dependencies", 4, 20, L"%u", NULL,
(VOID **)&NumberOfFunctionalDependencies, NULL, NULL }
};
/**
ACPI_PARSER array describing the MPAM MSC resource's functional dependencies.
**/
STATIC CONST ACPI_PARSER MpamMscFunctionalDependencyParser[] = {
{ L"Producer", 4, 0, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 4, NULL, DumpReserved,
NULL, ValidateReserved, NULL },
};
/**
ACPI_PARSER array describing the interconnect descriptor table associated with
the interconnect locator type.
**/
STATIC CONST ACPI_PARSER MpamInterconnectDescriptorTableParser[] = {
{ L"Signature", 16, 0,
L"%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x", Dump16Chars, NULL, NULL, NULL },
{ L"Number of Interconnect desc", 4, 16,L"0x%x", NULL,
(VOID **)&NumberOfInterconnectDescriptors, NULL, NULL }
};
/**
ACPI_PARSER array describing the interconnect descriptor associated with the
interconnect locator type.
**/
STATIC CONST ACPI_PARSER MpamInterconnectDescriptorParser[] = {
{ L"Source ID", 4, 0, L"%u", NULL, NULL, NULL, NULL },
{ L"Destination ID", 4, 4, L"%u", NULL, NULL, NULL, NULL },
{ L"Link type", 1, 8, L"0x%x", NULL,
NULL, DecodeLinkType, NULL },
{ L"Reserved", 3, 9, NULL, DumpReserved, NULL,
ValidateReserved, NULL }
};
/**
PrintBlockTitle could be used to print the title of blocks that
appear more than once in the MPAM ACPI table.
@param [in] Indent Number of spaces to add to the global table
indent. The global table indent is 0 by
default; however this value is updated on
entry to the ParseAcpi() by adding the indent
value provided to ParseAcpi() and restored
back on exit. Therefore the total indent in
the output is dependent on from where this
function is called.
@param [in] Title Title string to be used for the block.
@param [in] Index Index of the block.
**/
STATIC
VOID
EFIAPI
PrintBlockTitle (
IN UINT32 Indent,
IN CONST CHAR16 *Title,
IN CONST UINT32 Index
)
{
Print (L"\n");
PrintFieldName (Indent, Title);
Print (L"%u\n\n", Index);
}
/**
This function parses the interconnect descriptor(s) associated with
an interconnect type locator object.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in, out] Offset Pointer to current offset within Ptr.
Returns:
Status
EFI_SUCCESS MPAM MSC nodes were parsed properly.
EFI_BAD_BUFFER_SIZE The buffer pointer provided as input is not
long enough to be parsed correctly.
**/
STATIC
EFI_STATUS
EFIAPI
ParseInterconnectDescriptors (
IN UINT8 *CONST Ptr,
IN CONST UINT32 AcpiTableLength,
IN OUT UINT32 *CONST Offset
)
{
UINT32 InterconnectDescriptorIndex;
InterconnectDescriptorIndex = 0;
if (NumberOfInterconnectDescriptors == NULL) {
MpamLengthError (L"Number of interconnect descriptors not set!");
return EFI_BAD_BUFFER_SIZE;
}
while (InterconnectDescriptorIndex < *NumberOfInterconnectDescriptors) {
PrintBlockTitle (
6,
L"* Interconnect descriptor *",
InterconnectDescriptorIndex
);
// Parse interconnect descriptor
*Offset += ParseAcpi (
TRUE,
4,
NULL,
Ptr + *Offset,
AcpiTableLength - *Offset,
PARSER_PARAMS (MpamInterconnectDescriptorParser)
);
InterconnectDescriptorIndex++;
}
return EFI_SUCCESS;
}
/**
This function parses the interconnect descriptor table associated with an
interconnect type locator object. It also performs necessary validation to
make sure the interconnect descriptor is at a valid location.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in] Offset Pointer to current offset within Ptr.
@param [in] InterconnectOffset Offset to the interconnect descriptor table.
Returns:
Status
EFI_SUCCESS MPAM MSC nodes were parsed properly.
EFI_BAD_BUFFER_SIZE The buffer pointer provided as input is not
long enough to be parsed correctly.
EFI_INVALID_PARAMETER The Offset parameter encoded within the Ptr
buffer is not valid.
**/
STATIC
EFI_STATUS
EFIAPI
ParseInterconnectDescriptorTable (
IN UINT8 *CONST Ptr,
IN CONST UINT32 AcpiTableLength,
IN UINT32 Offset,
IN CONST UINT64 InterconnectOffset
)
{
EFI_STATUS Status;
// Lower bound check
if (Offset > (MpamMscNodeStart + InterconnectOffset)) {
IncrementErrorCount ();
Print (L"\nERROR : Parsing Interconnect descriptor table failed!\n");
Print (
L"ERROR : Offset overlaps with other objects within the MSC. Offset %u.\n",
InterconnectOffset
);
return EFI_INVALID_PARAMETER;
}
// Upper bound check
if (InterconnectOffset > (*MpamMscNodeLength)) {
IncrementErrorCount ();
Print (L"\nERROR : Parsing Interconnect descriptor table failed!\n");
Print (
L"ERROR : Offset falls outside MSC's space. Offset %u.\n",
InterconnectOffset
);
return EFI_INVALID_PARAMETER;
}
// It is safe to cast InterconnectOffset to UINT32 as IntercconnectOffset can
// never exceed the MPAM table length which is at max 2 bytes.
Offset = MpamMscNodeStart + (UINT32)InterconnectOffset;
Print (L"\n");
PrintFieldName (6, L"* Interconnect desc table *");
Print (L"\n\n");
// Parse interconnect descriptor table
Offset += ParseAcpi (
TRUE,
4,
NULL,
Ptr + Offset,
AcpiTableLength - Offset,
PARSER_PARAMS (MpamInterconnectDescriptorTableParser)
);
Status = ParseInterconnectDescriptors (
Ptr,
AcpiTableLength,
&Offset
);
return Status;
}
/**
This function parses all the MPAM functional dependency nodes within a
single resource node.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in, out] Offset Pointer to current offset within Ptr.
Returns:
Status
EFI_SUCCESS MPAM MSC nodes were parsed properly.
EFI_BAD_BUFFER_SIZE The buffer pointer provided as input is not
long enough to be parsed correctly.
**/
STATIC
EFI_STATUS
EFIAPI
ParseMpamMscFunctionalDependencies (
IN UINT8 *CONST Ptr,
IN CONST UINT32 AcpiTableLength,
IN OUT UINT32 *CONST Offset
)
{
UINT32 FunctionalDependencyIndex;
FunctionalDependencyIndex = 0;
if (NumberOfFunctionalDependencies == NULL) {
MpamLengthError (L"Number of functional dependencies not set!");
return EFI_BAD_BUFFER_SIZE;
}
while (FunctionalDependencyIndex < *NumberOfFunctionalDependencies) {
PrintBlockTitle (
6,
L"* Functional dependency *",
FunctionalDependencyIndex
);
// Parse functional dependency
*Offset += ParseAcpi (
TRUE,
4,
NULL,
Ptr + *Offset,
AcpiTableLength - *Offset,
PARSER_PARAMS (MpamMscFunctionalDependencyParser)
);
FunctionalDependencyIndex++;
}
return EFI_SUCCESS;
}
/**
This function parses all the MPAM resource nodes within a single MSC
node within the MPAM ACPI table. It also invokes helper functions to
validate and parse locators and functional dependency descriptors.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in] Offset Pointer to current offset within Ptr.
Returns:
Status
EFI_SUCCESS MPAM MSC nodes were parsed properly.
EFI_BAD_BUFFER_SIZE The buffer pointer provided as input is not
long enough to be parsed correctly.
**/
STATIC
EFI_STATUS
EFIAPI
ParseMpamMscResources (
IN UINT8 *CONST Ptr,
IN CONST UINT32 AcpiTableLength,
IN UINT32 Offset
)
{
EFI_STATUS Status;
UINT32 ResourceIndex;
ResourceIndex = 0;
if (NumberOfMscResources == NULL) {
MpamLengthError (L"Number of MSC resource not set!");
return EFI_BAD_BUFFER_SIZE;
}
while (ResourceIndex < *NumberOfMscResources) {
PrintBlockTitle (
4,
L"* Resource *",
ResourceIndex
);
// Parse MPAM MSC resources within the MSC body.
Offset += ParseAcpi (
TRUE,
2,
NULL,
Ptr + Offset,
AcpiTableLength - Offset,
PARSER_PARAMS (MpamMscResourceParser)
);
Status = ParseMpamMscFunctionalDependencies (Ptr, AcpiTableLength, &Offset);
if (Status != EFI_SUCCESS) {
return Status;
}
// If the InterconnectTableOffset field has been set, proceed to parse the
// interconnect descriptor table. Please note that the interconnect
// descriptors are placed within the MSC node body in the resource specific
// region. However since its easier to map an interconnect descriptor to
// its corresponding resource, proceed to parse it along with its parent
// resource. This design choice is made to keep the trace view as intuitive
// as possible.
//
// +---------------------+
// | MPAM ACPI Header |
// +---------------------+-------
// | MSC Node 0 Hdr | ^
// | +-----------------+ | |
// | | Res Node 0 | | |
// | | +-------------+ | | |
// | | | Res Node Hdr| | | |
// | | +-------------+ | | |
// | | | Res Data | | | |
// | | | | | | |
// | | | +---------+ | | | | +---------------------------+
// | | | | Locator | | | | ..|..| Interconnect locator desc |
// | | | | | | | | | | Descriptor Table Offset |--points-to->+
// | | | | | | | | | | Reserved [4] | |
// | | | +---------+ | | | | +---------------------------+ |
// | | | |FnDep Cnt| | | | | |
// | | | +---------+ | | | | |
// | | | |FnDep 1 | | | | | |
// | | | +---------+ | | | Interconnect |
// | | | |FnDep 2 | | | | descriptor |
// | | | +---------+ | | | table |
// | | | |FnDep n | | | | offset |
// | | | +---------+ | | | value |
// | | +-------------+ | | | |
// | +-----------------+ | | |
// | ... | | |
// | +-----------------+ | | |
// | | Res Node N | | | |
// | | +-------------+ | | | |
// | | | Res Node Hdr| | | | |
// | | +-------------+ | | | |
// | | | Res Data | | | | |
// | | | | | | | |
// | | | +---------+ | | | | |
// | | | | Locator | | | | | |
// | | | | | | | | | |
// | | | | | | | | | |
// | | | +---------+ | | | | |
// | | | |FnDep Cnt| | | | | |
// | | | +---------+ | | | | |
// | | | |FnDep 1 | | | | | |
// | | | +---------+ | | | | |
// | | | |FnDep 2 | | | | | |
// | | | +---------+ | | | | |
// | | | |FnDep n | | | | | |
// | | | +---------+ | | | | |
// | | +-------------+ | | | |
// | +-----------------+ | | |
// \ Resource-specific / v |
// / data region. \<-----------------------------------------------+
// \ /
// +---------------------+
// | MSC Node 1 Hdr |
// | ... |
// +---------------------+
if ( (*ResourceLocatorType == EFI_ACPI_MPAM_LOCATION_INTERCONNECT)
&& (InterconnectTableOffset != NULL))
{
Status = ParseInterconnectDescriptorTable (
Ptr,
AcpiTableLength,
Offset,
*InterconnectTableOffset
);
if (Status != EFI_SUCCESS) {
return Status;
}
}
ResourceIndex++;
}
return EFI_SUCCESS;
}
/**
This function parses all the MPAM MSC nodes within the MPAM ACPI table. It
also invokes a helper function to detect and parse resource nodes that maybe
present.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in, out] Offset Pointer to the current offset within Ptr.
Returns:
Status
EFI_SUCCESS MPAM MSC nodes were parsed properly.
EFI_BAD_BUFFER_SIZE The buffer pointer provided as input is not
long enough to be parsed correctly.
**/
STATIC
EFI_STATUS
EFIAPI
ParseMpamMscNodes (
IN UINT8 *CONST Ptr,
IN CONST UINT32 AcpiTableLength,
IN OUT UINT32 *CONST Offset
)
{
EFI_STATUS Status;
UINT32 MscIndex;
MscIndex = 0;
while (*Offset < AcpiTableLength) {
MpamMscNodeStart = *Offset;
PrintBlockTitle (2, L"* MSC *", MscIndex);
// Parse MPAM MSC node
*Offset += ParseAcpi (
TRUE,
0,
NULL,
Ptr + *Offset,
AcpiTableLength - *Offset,
PARSER_PARAMS (MpamMscNodeParser)
);
if (MpamMscNodeLength == NULL) {
MpamLengthError (L"MPAM MSC node length not set!");
return EFI_BAD_BUFFER_SIZE;
}
if (*MpamMscNodeLength < sizeof (EFI_ACPI_MPAM_MSC_NODE)) {
IncrementErrorCount ();
Print (L"\nERROR: MSC length should be at least the size of node body! ");
Print (L"MSC Length %u\n", *MpamMscNodeLength);
return EFI_BAD_BUFFER_SIZE;
}
// Parse MPAM MSC resources within the MSC body
Status = ParseMpamMscResources (Ptr, AcpiTableLength, *Offset);
if (Status != EFI_SUCCESS) {
return Status;
}
*Offset = MpamMscNodeStart + *MpamMscNodeLength;
MscIndex++;
}
return EFI_SUCCESS;
}
/**
This function parses the MPAM ACPI table's generic header. It also invokes a
sub routine that would help with parsing rest of the table.
@param [in] Trace If TRUE, trace the ACPI fields.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in] AcpiTableRevision Revision of the ACPI table.
**/
VOID
EFIAPI
ParseAcpiMpam (
IN BOOLEAN Trace,
IN UINT8 *Ptr,
IN UINT32 AcpiTableLength,
IN UINT8 AcpiTableRevision
)
{
EFI_STATUS Status;
UINT32 Offset;
if (!Trace) {
return;
}
// Parse generic table header
Offset = ParseAcpi (
TRUE,
0,
"MPAM",
Ptr,
AcpiTableLength,
PARSER_PARAMS (MpamParser)
);
Status = ParseMpamMscNodes (
Ptr,
AcpiTableLength,
&Offset
);
if (Status == EFI_SUCCESS) {
// Check if the length of all MPAM MSCs with the header, matches with the
// ACPI table's length field.
if (*(AcpiHdrInfo.Length) != Offset) {
IncrementErrorCount ();
Print (L"\nERROR: Length mismatch! : ");
Print (L"MSC Length total != MPAM table length.");
Print (
L"Table length : %u MSC total : %u\n",
*(AcpiHdrInfo.Length),
Offset
);
}
}
}
|