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
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
|
/** @file
RISC-V Interrupt Controllers parser.
Copyright (c) 2024, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
- linux/Documentation/devicetree/bindings/riscv/cpus.yaml
**/
#include <IndustryStandard/Acpi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/FdtLib.h>
#include "FdtHwInfoParser.h"
#include "CmObjectDescUtility.h"
#include "RiscV/Intc/RiscVIntcParser.h"
#define ACPI_BUILD_EXT_INTC_ID(PlicAplicId, CtxIdcId) \
((PlicAplicId << 24) | (CtxIdcId))
/** List of "compatible" property values for CPU nodes.
Any other "compatible" value is not supported by this module.
*/
STATIC CONST COMPATIBILITY_STR CpuCompatibleStr[] = {
{ "riscv" }
};
/** COMPATIBILITY_INFO structure for CPU nodes.
*/
STATIC CONST COMPATIBILITY_INFO CpuCompatibleInfo = {
ARRAY_SIZE (CpuCompatibleStr),
CpuCompatibleStr
};
/** List of "compatible" property values for IMSIC node.
Any other "compatible" value is not supported by this module.
*/
STATIC CONST COMPATIBILITY_STR ImsicCompatibleStr[] = {
{ "riscv,imsics" }
};
/** COMPATIBILITY_INFO structure for IMSIC node.
*/
STATIC CONST COMPATIBILITY_INFO ImsicCompatibleInfo = {
ARRAY_SIZE (ImsicCompatibleStr),
ImsicCompatibleStr
};
/** List of "compatible" property values for APLIC node.
Any other "compatible" value is not supported by this module.
*/
STATIC CONST COMPATIBILITY_STR AplicCompatibleStr[] = {
{ "riscv,aplic" }
};
/** COMPATIBILITY_INFO structure for APLIC node.
*/
STATIC CONST COMPATIBILITY_INFO AplicCompatibleInfo = {
ARRAY_SIZE (AplicCompatibleStr),
AplicCompatibleStr
};
/** List of "compatible" property values for PLIC node.
Any other "compatible" value is not supported by this module.
*/
STATIC CONST COMPATIBILITY_STR PlicCompatibleStr[] = {
{ "riscv,plic0" }
};
/** COMPATIBILITY_INFO structure for IMSIC node.
*/
STATIC CONST COMPATIBILITY_INFO PlicCompatibleInfo = {
ARRAY_SIZE (PlicCompatibleStr),
PlicCompatibleStr
};
/** Create MMU info structure
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] CpuNode cpu node.
**/
STATIC
EFI_STATUS
EFIAPI
MmuInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 CpuNode,
OUT CM_OBJECT_TOKEN *Token
)
{
CM_RISCV_MMU_NODE MmuInfo;
CONST VOID *Prop;
EFI_STATUS Status;
INT32 PropSize;
VOID *Fdt;
Fdt = FdtParserHandle->Fdt;
ZeroMem (&MmuInfo, sizeof (CM_RISCV_MMU_NODE));
Prop = FdtGetProp (Fdt, CpuNode, "mmu-type", &PropSize);
if (!Prop) {
return EFI_NOT_FOUND;
}
if (AsciiStrnCmp (Prop, "riscv,sv39", 10) == 0) {
MmuInfo.MmuType = EFI_ACPI_6_6_RHCT_MMU_TYPE_SV39;
} else if (AsciiStrnCmp (Prop, "riscv,sv48", 10) == 0) {
MmuInfo.MmuType = EFI_ACPI_6_6_RHCT_MMU_TYPE_SV48;
} else if (AsciiStrnCmp (Prop, "riscv,sv57", 10) == 0) {
MmuInfo.MmuType = EFI_ACPI_6_6_RHCT_MMU_TYPE_SV57;
}
// Add the CmObj to the Configuration Manager.
Status = AddSingleCmObj (
FdtParserHandle,
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjMmuInfo),
&MmuInfo,
sizeof (CM_RISCV_MMU_NODE),
Token
);
if (EFI_ERROR (Status)) {
ASSERT (0);
}
return Status;
}
/** Create CMO info structure if CMO extension present
Create CMO structure with CBOM, CBOP and CBOZ sizes.
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] CpusNode cpus node.
**/
STATIC
EFI_STATUS
EFIAPI
CmoInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 CpuNode,
OUT CM_OBJECT_TOKEN *Token
)
{
CM_RISCV_CMO_NODE CmoInfo;
EFI_STATUS Status;
CONST VOID *Prop;
BOOLEAN CmoSupported;
INT32 PropSize;
VOID *Fdt;
Fdt = FdtParserHandle->Fdt;
ZeroMem (&CmoInfo, sizeof (CM_RISCV_CMO_NODE));
CmoSupported = FALSE;
Prop = FdtGetProp (Fdt, CpuNode, "riscv,cbom-block-size", &PropSize);
if (Prop) {
CmoSupported = TRUE;
CmoInfo.CbomBlockSize = LowBitSet32 (Fdt32ToCpu (*(const UINT32 *)Prop));
}
Prop = FdtGetProp (Fdt, CpuNode, "riscv,cboz-block-size", &PropSize);
if (Prop) {
CmoSupported = TRUE;
CmoInfo.CbozBlockSize = LowBitSet32 (Fdt32ToCpu (*(const UINT32 *)Prop));
}
Prop = FdtGetProp (Fdt, CpuNode, "riscv,cbop-block-size", &PropSize);
if (Prop) {
CmoSupported = TRUE;
CmoInfo.CbopBlockSize = LowBitSet32 (Fdt32ToCpu (*(const UINT32 *)Prop));
}
if (CmoSupported == TRUE) {
// Add the CmObj to the Configuration Manager.
Status = AddSingleCmObj (
FdtParserHandle,
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjCmoInfo),
&CmoInfo,
sizeof (CM_RISCV_CMO_NODE),
Token
);
if (EFI_ERROR (Status)) {
ASSERT (0);
}
return Status;
}
return EFI_NOT_FOUND;
}
/** Create ISA string Info structure
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] CpusNode cpus node.
**/
STATIC
EFI_STATUS
EFIAPI
IsaStringInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 CpuNode,
OUT CM_OBJECT_TOKEN *Token
)
{
CM_RISCV_ISA_STRING_NODE IsaStringInfo;
CONST VOID *Prop;
EFI_STATUS Status;
INT32 PropSize;
VOID *Fdt;
Fdt = FdtParserHandle->Fdt;
ZeroMem (&IsaStringInfo, sizeof (CM_RISCV_ISA_STRING_NODE));
Prop = FdtGetProp (Fdt, CpuNode, "riscv,isa", &PropSize);
if (!Prop) {
DEBUG ((DEBUG_ERROR, "Failed to parse cpu node: riscv,isa\n"));
ASSERT (0);
return EFI_ABORTED;
}
IsaStringInfo.Length = PropSize;
Status = AsciiStrCpyS (IsaStringInfo.IsaString, MAX_ISA_STRING_LENGTH, (CHAR8 *)Prop);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to copy ISA string\n"));
ASSERT (0);
return EFI_ABORTED;
}
// Add the CmObj to the Configuration Manager.
Status = AddSingleCmObj (
FdtParserHandle,
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjIsaStringInfo),
&IsaStringInfo,
sizeof (CM_RISCV_ISA_STRING_NODE),
Token
);
if (EFI_ERROR (Status)) {
ASSERT (0);
}
return Status;
}
/** Parse a "cpu" node.
CPU node parser.
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] CpuNode cpu node.
@param [in] AddressCells AddressCells info.
@param [out] RintcInfo Pointer to RINTC Info structure.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
CpuNodeParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 CpuNode,
IN UINT32 AddressCells,
OUT CM_RISCV_RINTC_INFO *RintcInfo
)
{
CONST CHAR8 *CpuName;
CONST VOID *Prop;
EFI_STATUS Status;
UINT64 HartId;
INT32 PropSize;
INT32 IntcNode;
UINTN ProcUid;
VOID *Fdt;
if (RintcInfo == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
Prop = FdtGetProp (Fdt, CpuNode, "reg", &PropSize);
if ((Prop == NULL) ||
((PropSize != sizeof (UINT32)) &&
(PropSize != sizeof (UINT64))))
{
ASSERT (0);
return EFI_ABORTED;
}
IntcNode = CpuNode;
Status = FdtGetNextNamedNodeInBranch (Fdt, CpuNode, "interrupt-controller", &IntcNode);
if (EFI_ERROR (Status)) {
ASSERT (0);
if (Status == EFI_NOT_FOUND) {
// Should have found the node.
Status = EFI_ABORTED;
}
}
CpuName = FdtGetName (Fdt, CpuNode, &PropSize);
ProcUid = AsciiStrDecimalToUintn (&CpuName[4]);
Status = ReadFdtCells64 ((UINT32 *)Prop, AddressCells, &HartId);
if (EFI_ERROR (Status)) {
ASSERT (FALSE);
return EFI_ABORTED;
}
/*
* Check for disabled cpu and mark appropriately in MADT.
*/
Prop = FdtGetProp (Fdt, CpuNode, "status", &PropSize);
if (!Prop || (Prop &&
((AsciiStrnCmp ((const CHAR8 *)Prop, "okay", PropSize) == 0) ||
(AsciiStrnCmp ((const CHAR8 *)Prop, "ok", PropSize) == 0))))
{
RintcInfo->Flags = EFI_ACPI_6_6_RINTC_FLAG_ENABLE;
} else {
RintcInfo->Flags = 0;
}
RintcInfo->HartId = HartId;
RintcInfo->Version = EFI_ACPI_6_6_RINTC_STRUCTURE_VERSION;
RintcInfo->AcpiProcessorUid = ProcUid;
RintcInfo->ExtIntcId = 0; // Will be updated later
Status = IsaStringInfoParser (FdtParserHandle, CpuNode, &RintcInfo->IsaStringInfoToken);
if (EFI_ERROR (Status)) {
ASSERT (0);
if (Status == EFI_NOT_FOUND) {
// Should have found the node.
Status = EFI_ABORTED;
}
return Status;
}
Status = CmoInfoParser (FdtParserHandle, CpuNode, &RintcInfo->CmoInfoToken);
if (EFI_ERROR (Status)) {
if (Status != EFI_NOT_FOUND) {
ASSERT (0);
return Status;
}
}
Status = MmuInfoParser (FdtParserHandle, CpuNode, &RintcInfo->MmuInfoToken);
if (EFI_ERROR (Status)) {
if (Status != EFI_NOT_FOUND) {
ASSERT (0);
}
}
return Status;
}
/** CPU node parser
CPU node parser.
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] CpusNode cpus node.
@param [out] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
CpusNodeParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 CpusNode,
OUT CM_OBJ_DESCRIPTOR **NewRintcCmObjDesc
)
{
EFI_STATUS Status;
UINT32 CpuNodeCount;
INT32 CpuNode;
INT32 AddressCells;
UINT32 Index;
CM_RISCV_RINTC_INFO *RintcInfoBuffer;
UINT32 RintcInfoBufferSize;
VOID *Fdt;
if (NewRintcCmObjDesc == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
AddressCells = FdtAddressCells (Fdt, CpusNode);
if (AddressCells < 0) {
ASSERT (0);
return EFI_ABORTED;
}
// Count the number of "cpu" nodes under the "cpus" node.
Status = FdtCountNamedNodeInBranch (Fdt, CpusNode, "cpu", &CpuNodeCount);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
if (CpuNodeCount == 0) {
ASSERT (0);
return EFI_NOT_FOUND;
}
RintcInfoBufferSize = CpuNodeCount * sizeof (CM_RISCV_RINTC_INFO);
RintcInfoBuffer = AllocateZeroPool (RintcInfoBufferSize);
if (RintcInfoBuffer == NULL) {
ASSERT (0);
return EFI_OUT_OF_RESOURCES;
}
CpuNode = CpusNode;
for (Index = 0; Index < CpuNodeCount; Index++) {
Status = FdtGetNextNamedNodeInBranch (Fdt, CpusNode, "cpu", &CpuNode);
if (EFI_ERROR (Status)) {
ASSERT (0);
if (Status == EFI_NOT_FOUND) {
// Should have found the node.
Status = EFI_ABORTED;
}
goto exit_handler;
}
// Parse the "cpu" node.
if (!FdtNodeIsCompatible (Fdt, CpuNode, &CpuCompatibleInfo)) {
ASSERT (0);
Status = EFI_UNSUPPORTED;
goto exit_handler;
}
Status = CpuNodeParser (
FdtParserHandle,
CpuNode,
AddressCells,
&RintcInfoBuffer[Index]
);
if (EFI_ERROR (Status)) {
ASSERT (0);
goto exit_handler;
}
} // for
Status = CreateCmObjDesc (
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjRintcInfo),
CpuNodeCount,
RintcInfoBuffer,
RintcInfoBufferSize,
NewRintcCmObjDesc
);
ASSERT_EFI_ERROR (Status);
exit_handler:
FreePool (RintcInfoBuffer);
return Status;
}
/** Find the RINTC structure for a phandle
@param [in] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@param [in] Phandle Phandle to search
**/
STATIC
CM_RISCV_RINTC_INFO *
RiscVFindRintc (
IN CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc,
IN UINT64 HartId
)
{
CM_RISCV_RINTC_INFO *RintcInfo;
INT32 Idx;
RintcInfo = (CM_RISCV_RINTC_INFO *)NewRintcCmObjDesc->Data;
for (Idx = 0; Idx < NewRintcCmObjDesc->Count; Idx++) {
if (RintcInfo[Idx].HartId == HartId) {
return &RintcInfo[Idx];
}
}
return NULL;
}
/** Check if it is a PLIC
@param [in] Fdt Pointer to device tree.
@param [in] AplicNode Node with APLIC compatible property.
@retval TRUE The AplicNode is S-mode APLIC
@retval FALSE The AplicNode is not S-mode APLIC
**/
STATIC
BOOLEAN
IsPlicNode (
IN VOID *Fdt,
IN INT32 ExtIntcNode
)
{
return FdtNodeIsCompatible (Fdt, ExtIntcNode, &PlicCompatibleInfo);
}
/** Check if it is S-mode IMSIC
FDT will have entries for both M-mode and S-mode IMSIC. We
need only S-mode IMSIC.
@param [in] Fdt Pointer to device tree.
@param [in] Node Node with IMSIC compatible property.
@retval TRUE The Node is S-mode IMSIC
@retval FALSE The Node is not S-mode IMSIC
**/
STATIC
BOOLEAN
IsImsicNode (
IN VOID *Fdt,
IN INT32 Node
)
{
INT32 *IrqProp;
INT32 Len;
if (!FdtNodeIsCompatible (Fdt, Node, &ImsicCompatibleInfo)) {
return FALSE;
}
IrqProp = (INT32 *)FdtGetProp (Fdt, Node, "interrupts-extended", &Len);
if (!IrqProp || (Len < 4) ||
(Fdt32ToCpu (IrqProp[1]) != IRQ_S_EXT))
{
return FALSE;
}
return TRUE;
}
/** Check if it is S-mode APLIC
FDT will have entries for both M-mode and S-mode APLIC. We
need only S-mode APLIC.
@param [in] Fdt Pointer to device tree.
@param [in] AplicNode Node with APLIC compatible property.
@retval TRUE The AplicNode is S-mode APLIC
@retval FALSE The AplicNode is not S-mode APLIC
**/
STATIC
BOOLEAN
IsAplicNode (
IN VOID *Fdt,
IN INT32 ExtIntcNode
)
{
INT32 *IrqProp;
INT32 *MsiProp;
INT32 ImsicNode;
INT32 Len;
if (!FdtNodeIsCompatible (Fdt, ExtIntcNode, &AplicCompatibleInfo)) {
return FALSE;
}
IrqProp = (INT32 *)FdtGetProp (Fdt, ExtIntcNode, "interrupts-extended", &Len);
if ((IrqProp > 0) && (Len >= 4) &&
(Fdt32ToCpu (IrqProp[1]) == IRQ_S_EXT))
{
return TRUE;
}
MsiProp = (INT32 *)FdtGetProp (Fdt, ExtIntcNode, "msi-parent", &Len);
if (!MsiProp || (Len < sizeof (INT32))) {
return FALSE;
}
ImsicNode = FdtNodeOffsetByPhandle (Fdt, Fdt32ToCpu (*MsiProp));
if (ImsicNode < 0) {
return FALSE;
}
IrqProp = (INT32 *)FdtGetProp (Fdt, ImsicNode, "interrupts-extended", &Len);
if ((!IrqProp) || (Len < 4) ||
(Fdt32ToCpu (IrqProp[1]) != IRQ_S_EXT))
{
return FALSE;
}
return TRUE;
}
/** Update Rintc Info CM object
Find the RINTC CM object of the CPU and update the
External Interrupt controller ID.
@param [in] Fdt Pointer to device tree.
@param [in] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@param [in] CpuNode Node with APLIC compatible property.
@param [in] ExtIntcId External Interrupt controller (PLIC/APLIC) ID
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_NOT_FOUND Not found.
**/
STATIC
EFI_STATUS
RiscVUpdateRintc (
IN CONST VOID *Fdt,
IN OUT CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc,
IN INT32 CpuNode,
IN UINT32 ExtIntcId
)
{
CM_RISCV_RINTC_INFO *RintcInfo;
CONST INT32 *Data;
UINT32 AddressCells;
INT32 DataSize;
UINT64 HartId;
INT32 CpusNode;
EFI_STATUS Status;
CpusNode = FdtParentOffset (Fdt, CpuNode);
AddressCells = FdtAddressCells (Fdt, CpusNode);
if (AddressCells < 0) {
ASSERT (0);
return EFI_ABORTED;
}
Data = FdtGetProp (Fdt, CpuNode, "reg", &DataSize);
if ((Data == NULL) ||
((DataSize != sizeof (UINT32)) &&
(DataSize != sizeof (UINT64))))
{
ASSERT (0);
return EFI_ABORTED;
}
Status = ReadFdtCells64 (Data, AddressCells, &HartId);
if (EFI_ERROR (Status)) {
ASSERT (FALSE);
return EFI_ABORTED;
}
RintcInfo = RiscVFindRintc (NewRintcCmObjDesc, HartId);
if (RintcInfo == NULL) {
ASSERT (0);
return EFI_NOT_FOUND;
}
/* Update RINTC EXT INTC ID */
RintcInfo->ExtIntcId = ExtIntcId;
return EFI_SUCCESS;
}
/**
PLIC parser and update RINTC
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] ExtIntcNode PLIC node.
@param [in] Id PLIC ID.
@param [in] PlicAplicCommonInfo Common information for PLIC and APLIC.
@param [in] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
PlicInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 ExtIntcNode,
IN UINT32 *Id,
IN PLIC_APLIC_COMMON_INFO *PlicAplicCommonInfo,
IN CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc
)
{
CM_RISCV_PLIC_INFO *PlicInfo;
CONST UINT32 *IntExtProp;
EFI_STATUS Status;
INT32 LocalCpuId;
INT32 ExtIntcId;
INT32 IntcNode;
INT32 CpuNode;
INT32 Phandle;
INT32 Len;
INT32 Idx1;
INT32 Idx2;
VOID *Fdt;
ASSERT (Id != NULL);
ASSERT (PlicAplicCommonInfo != NULL);
if (FdtParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
IntExtProp = FdtGetProp (Fdt, ExtIntcNode, "interrupts-extended", &Len);
if ((IntExtProp == NULL) || (Len < 4)) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
} else {
PlicInfo = AllocateZeroPool (sizeof (CM_RISCV_PLIC_INFO));
if (PlicInfo == NULL) {
ASSERT (0);
return EFI_OUT_OF_RESOURCES;
}
Len = Len / 4;
for (Idx1 = 0, Idx2 = 0; Idx1 < Len; Idx1 += 2, Idx2++) {
if (Fdt32ToCpu (IntExtProp[Idx1 + 1]) == IRQ_S_EXT) {
Phandle = Fdt32ToCpu (IntExtProp[Idx1]);
IntcNode = FdtNodeOffsetByPhandle (Fdt, Phandle);
CpuNode = FdtParentOffset (Fdt, IntcNode);
LocalCpuId = Idx2 / 2;
ExtIntcId = ACPI_BUILD_EXT_INTC_ID (*Id, 2 * LocalCpuId + 1);
Status = RiscVUpdateRintc (Fdt, NewRintcCmObjDesc, CpuNode, ExtIntcId);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
return Status;
}
}
}
CopyMem (&PlicAplicCommonInfo->Hid, "RSCV0001", RISCV_HWID_LENGTH);
CopyMem (&PlicInfo->PlicAplicCommonInfo, PlicAplicCommonInfo, sizeof (PLIC_APLIC_COMMON_INFO));
// Add the CmObj to the Configuration Manager.
Status = AddSingleCmObj (
FdtParserHandle,
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjPlicInfo),
PlicInfo,
sizeof (CM_RISCV_PLIC_INFO),
NULL
);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
}
return EFI_SUCCESS;
}
/**
APLIC parser and update RINTC
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] ExtIntcNode APLIC node.
@param [in] Id APLIC ID.
@param [in] PlicAplicCommonInfo Common information for PLIC and APLIC.
@param [in, out] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
AplicInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 ExtIntcNode,
IN UINT32 *Id,
IN PLIC_APLIC_COMMON_INFO *PlicAplicCommonInfo,
IN OUT CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc
)
{
CM_RISCV_APLIC_INFO *AplicInfo;
CONST UINT32 *IntExtProp;
EFI_STATUS Status;
INT32 ExtIntcId;
INT32 IntcNode;
INT32 CpuNode;
INT32 Phandle;
INT32 Len;
INT32 Idx;
VOID *Fdt;
ASSERT (Id != NULL);
ASSERT (PlicAplicCommonInfo != NULL);
if (FdtParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
AplicInfo = AllocateZeroPool (sizeof (CM_RISCV_APLIC_INFO));
if (AplicInfo == NULL) {
ASSERT (0);
return EFI_OUT_OF_RESOURCES;
}
IntExtProp = FdtGetProp (Fdt, ExtIntcNode, "interrupts-extended", &Len);
if ((IntExtProp != 0) && ((Len / sizeof (UINT32)) % 2 == 0)) {
Len = Len / 4;
AplicInfo->NumIdcs = Len / 2;
for (Idx = 0; Idx < Len; Idx += 2) {
Phandle = Fdt32ToCpu (IntExtProp[Idx]);
IntcNode = FdtNodeOffsetByPhandle (Fdt, Phandle);
CpuNode = FdtParentOffset (Fdt, IntcNode);
ExtIntcId = ACPI_BUILD_EXT_INTC_ID (*Id, Idx / 2);
Status = RiscVUpdateRintc (Fdt, NewRintcCmObjDesc, CpuNode, ExtIntcId);
if (EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
return Status;
}
}
}
CopyMem (&PlicAplicCommonInfo->Hid, "RSCV0002", RISCV_HWID_LENGTH);
CopyMem (&AplicInfo->PlicAplicCommonInfo, PlicAplicCommonInfo, sizeof (PLIC_APLIC_COMMON_INFO));
// Add the CmObj to the Configuration Manager.
Status = AddSingleCmObj (
FdtParserHandle,
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjAplicInfo),
AplicInfo,
sizeof (CM_RISCV_APLIC_INFO),
NULL
);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
return EFI_SUCCESS;
}
/**
PLIC/APLIC parser and update RINTC
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
PlicAplicInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc
)
{
PLIC_APLIC_COMMON_INFO PlicAplicCommonInfo;
CONST UINT32 *Prop;
EFI_STATUS Status;
UINT32 Id;
UINT32 GsiBase;
INT32 Len;
INT32 Prev;
INT32 ExtIntcNode;
VOID *Fdt;
if (FdtParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
GsiBase = 0;
Id = 0;
for (Prev = 0; ; Prev = ExtIntcNode) {
ExtIntcNode = FdtNextNode (Fdt, Prev, NULL);
if (ExtIntcNode < 0) {
return EFI_SUCCESS;
}
if (!(IsPlicNode (Fdt, ExtIntcNode) || IsAplicNode (Fdt, ExtIntcNode))) {
continue;
}
FdtCreateExtIntcList (ExtIntcNode, GsiBase);
PlicAplicCommonInfo.Version = 1;
PlicAplicCommonInfo.Id = Id;
Prop = FdtGetProp (Fdt, ExtIntcNode, "riscv,num-sources", &Len);
if (!Prop) {
Prop = FdtGetProp (Fdt, ExtIntcNode, "riscv,ndev", &Len);
if (!Prop) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
}
PlicAplicCommonInfo.NumSources = Fdt32ToCpu (*(const UINT32 *)Prop);
Prop = FdtGetProp (Fdt, ExtIntcNode, "reg", &Len);
if ((Prop == NULL) || (Len % 4 > 0)) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
PlicAplicCommonInfo.BaseAddress = Fdt64ToCpu (*(const UINT64 *)Prop);
PlicAplicCommonInfo.Size = Fdt64ToCpu (*((const UINT64 *)Prop + 1));
PlicAplicCommonInfo.GsiBase = GsiBase;
GsiBase += PlicAplicCommonInfo.NumSources;
if (FdtNodeIsCompatible (Fdt, ExtIntcNode, &PlicCompatibleInfo)) {
Status = PlicInfoParser (
FdtParserHandle,
ExtIntcNode,
&Id,
&PlicAplicCommonInfo,
NewRintcCmObjDesc
);
} else if (FdtNodeIsCompatible (Fdt, ExtIntcNode, &AplicCompatibleInfo)) {
Status = AplicInfoParser (
FdtParserHandle,
ExtIntcNode,
&Id,
&PlicAplicCommonInfo,
NewRintcCmObjDesc
);
}
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
Id++;
}
return EFI_SUCCESS;
}
/**
RINTC parser using IMSIC node
Parse RINTC information using IMSIC.
@param [in] FdtParserHandle A handle to the parser instance.
@param [in, out] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
UpdateRintcInfo (
IN CONST VOID *Fdt,
IN CONST INT32 ImsicNode,
IN OUT CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc
)
{
CM_RISCV_RINTC_INFO *RintcInfoBuffer;
CONST UINT32 *IntExtProp;
CONST UINT64 *ImsicRegProp;
CONST INT32 *Data;
UINT64 ImsicBaseAddr;
UINT64 ImsicBaseLen;
UINT64 ImsicCpuBaseAddr;
UINT64 ImsicCpuBaseLen;
INT32 NumPhandle;
INT32 Len;
INT32 AddressCells;
INT32 CpusNode;
INT32 CpuNode;
INT32 DataSize;
INT32 IntcNode;
INT32 Phandle;
UINT64 HartId;
UINTN NumImsicBase;
INTN Limit;
INTN Idx;
INTN Idx1;
INTN Idx2;
IntExtProp = (UINT32 *)FdtGetProp (Fdt, ImsicNode, "interrupts-extended", &Len);
if ((IntExtProp == 0) || ((Len / sizeof (UINT32)) % 2 != 0)) {
/* interrupts-extended: <phandle>, <flag> */
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
NumPhandle = (Len / sizeof (UINT32)) / 2;
if (NumPhandle == 0) {
ASSERT (0);
return EFI_NOT_FOUND;
}
ImsicRegProp = FdtGetProp (Fdt, ImsicNode, "reg", &Len);
if ((ImsicRegProp == 0) || (((Len / sizeof (UINT32)) % 4) != 0)) {
// address-cells and size-cells are always 2
DEBUG ((DEBUG_ERROR, "Failed to parse imsic node: reg\n"));
return EFI_INVALID_PARAMETER;
}
NumImsicBase = (Len / sizeof (UINT32)) / 4;
Idx2 = 0;
for (Idx = 0; Idx < NumImsicBase; Idx++) {
ImsicBaseAddr = Fdt64ToCpu (ImsicRegProp[Idx * 2]);
ImsicBaseLen = Fdt64ToCpu (ImsicRegProp[Idx * 2 + 1]);
// Calculate the limit of number of cpu nodes this imsic can handle
Limit = ImsicBaseLen / IMSIC_MMIO_PAGE_SZ;
for (Idx1 = 0; Idx1 < Limit && Idx2 < NumPhandle; Idx1++, Idx2++) {
Phandle = Fdt32ToCpu (IntExtProp[Idx2 * 2]);
IntcNode = FdtNodeOffsetByPhandle (Fdt, Phandle);
CpuNode = FdtParentOffset (Fdt, IntcNode);
CpusNode = FdtParentOffset (Fdt, CpuNode);
AddressCells = FdtAddressCells (Fdt, CpusNode);
if (AddressCells < 0) {
ASSERT (0);
return EFI_ABORTED;
}
Data = FdtGetProp (Fdt, CpuNode, "reg", &DataSize);
if (Data == NULL) {
ASSERT (0);
}
if ((Data == NULL) ||
((DataSize != sizeof (UINT32)) &&
(DataSize != sizeof (UINT64))))
{
ASSERT (0);
return EFI_ABORTED;
}
Status = ReadFdtCells64 (Data, AddressCells, &HartId);
if (EFI_ERROR (Status)) {
ASSERT (FALSE);
return EFI_ABORTED;
}
RintcInfoBuffer = RiscVFindRintc (NewRintcCmObjDesc, HartId);
if (RintcInfoBuffer == NULL) {
return EFI_NOT_FOUND;
}
ImsicCpuBaseAddr = ImsicBaseAddr + Idx1 * IMSIC_MMIO_PAGE_SZ;
ImsicCpuBaseLen = IMSIC_MMIO_PAGE_SZ;
RintcInfoBuffer->ImsicBaseAddress = ImsicCpuBaseAddr;
RintcInfoBuffer->ImsicSize = ImsicCpuBaseLen;
}
}
return EFI_SUCCESS;
}
/**
Get IMSIC information
@param [in] Fdt FDT Base pointer.
@param [in] ImsicNode IMSIC node in FDT.
@param [in, out] ImsicInfo Pointer to IMSIC info structure.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
ImsicGetInfo (
IN CONST VOID *Fdt,
IN CONST INT32 ImsicNode,
IN OUT CM_RISCV_IMSIC_INFO *ImsicInfo
)
{
CONST UINT32 *IntExtProp;
CONST UINT64 *Prop;
INT32 Len;
INT32 NumPhandle;
if (ImsicInfo == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
IntExtProp = FdtGetProp (Fdt, ImsicNode, "interrupts-extended", &Len);
if ((IntExtProp == 0) || ((Len / sizeof (UINT32)) % 2 != 0)) {
/* interrupts-extended: <phandle>, <flag> */
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
/* There can be M-mode IMSIC in DT. Consider only S-mode */
if (Fdt32ToCpu (IntExtProp[1]) != IRQ_S_EXT) {
ASSERT (0);
return EFI_NOT_FOUND;
}
NumPhandle = (Len / sizeof (UINT32)) / 2;
if (NumPhandle == 0) {
ASSERT (0);
return EFI_NOT_FOUND;
}
Prop = FdtGetProp (Fdt, ImsicNode, "riscv,num-ids", &Len);
if (Prop == 0) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
ImsicInfo->NumIds = Fdt32ToCpu (*(const UINT32 *)Prop);
Prop = FdtGetProp (Fdt, ImsicNode, "riscv,num-guest-ids", &Len);
if (Prop == 0) {
ImsicInfo->NumGuestIds = ImsicInfo->NumIds;
} else {
ImsicInfo->NumGuestIds = Fdt32ToCpu (*(const UINT32 *)Prop);
}
Prop = FdtGetProp (Fdt, ImsicNode, "riscv,guest-index-bits", &Len);
if (Prop == 0) {
ImsicInfo->GuestIndexBits = 0;
} else {
ImsicInfo->GuestIndexBits = Fdt32ToCpu (*(const UINT32 *)Prop);
}
Prop = FdtGetProp (Fdt, ImsicNode, "riscv,hart-index-bits", &Len);
if (Prop == 0) {
ImsicInfo->HartIndexBits = 0; // update default value later
} else {
ImsicInfo->HartIndexBits = Fdt32ToCpu (*(const UINT32 *)Prop);
}
Prop = FdtGetProp (Fdt, ImsicNode, "riscv,group-index-bits", &Len);
if (Prop == 0) {
ImsicInfo->GroupIndexBits = 0;
} else {
ImsicInfo->GroupIndexBits = Fdt32ToCpu (*(const UINT32 *)Prop);
}
Prop = FdtGetProp (Fdt, ImsicNode, "riscv,group-index-shift", &Len);
if (Prop == 0) {
ImsicInfo->GroupIndexShift = IMSIC_MMIO_PAGE_SHIFT * 2;
} else {
ImsicInfo->GroupIndexShift = Fdt32ToCpu (*(const UINT32 *)Prop);
}
ImsicInfo->Version = 1;
ImsicInfo->Flags = 0;
Prop = FdtGetProp (Fdt, ImsicNode, "reg", &Len);
if ((Prop == 0) || (((Len / sizeof (UINT32)) % 4) != 0)) {
// address-cells and size-cells are always 2
DEBUG ((DEBUG_ERROR, "Failed to parse imsic node: reg\n"));
return EFI_INVALID_PARAMETER;
}
if (ImsicInfo->HartIndexBits == 0) {
Len = NumPhandle;
while (Len > 0) {
ImsicInfo->HartIndexBits++;
Len = Len >> 1;
}
}
return EFI_SUCCESS;
}
/**
IMSIC parser using IMSIC node
@param [in] FdtParserHandle A handle to the parser instance.
@param [in, out] NewRintcCmObjDesc Pointer to array of RINTC CM objects.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
ImsicInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN OUT CM_OBJ_DESCRIPTOR *NewRintcCmObjDesc
)
{
CM_RISCV_IMSIC_INFO ImsicInfo;
EFI_STATUS Status;
INT32 Prev;
INT32 ImsicNode;
VOID *Fdt;
if (NewRintcCmObjDesc == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
ZeroMem (&ImsicInfo, sizeof (CM_RISCV_IMSIC_INFO));
for (Prev = 0; ; Prev = ImsicNode) {
ImsicNode = FdtNextNode (Fdt, Prev, NULL);
if (ImsicNode < 0) {
return EFI_NOT_FOUND;
}
if (IsImsicNode (Fdt, ImsicNode) == FALSE) {
continue;
}
Status = ImsicGetInfo (Fdt, ImsicNode, &ImsicInfo);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
Status = UpdateRintcInfo (Fdt, ImsicNode, NewRintcCmObjDesc);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
// Add the CmObj to the Configuration Manager.
Status = AddSingleCmObj (
FdtParserHandle,
CREATE_CM_RISCV_OBJECT_ID (ERiscVObjImsicInfo),
&ImsicInfo,
sizeof (CM_RISCV_IMSIC_INFO),
NULL
);
if (EFI_ERROR (Status)) {
ASSERT (0);
}
return Status;
}
}
/** CM_RISCV_RINTC_INFO and CM_RISCV_IMSIC_INFO parser function.
A parser parses a Device Tree to populate a specific CmObj type. None,
one or many CmObj can be created by the parser.
The created CmObj are then handed to the parser's caller through the
HW_INFO_ADD_OBJECT interface.
This can also be a dispatcher. I.e. a function that not parsing a
Device Tree but calling other parsers.
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] FdtBranch When searching for DT node name, restrict
the search to this Device Tree branch.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
STATIC
EFI_STATUS
EFIAPI
RiscVIntcInfoParser (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 FdtBranch
)
{
CM_OBJ_DESCRIPTOR *NewCmObjDesc;
EFI_STATUS Status;
if (FdtParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
NewCmObjDesc = NULL;
// Parse the "cpus" nodes and its children "cpu" nodes,
// and create a CM_OBJ_DESCRIPTOR.
Status = CpusNodeParser (FdtParserHandle, FdtBranch, &NewCmObjDesc);
if (EFI_ERROR (Status)) {
ASSERT (0);
return Status;
}
/* Search for IMSIC presence and update RINTC structures if so */
Status = ImsicInfoParser (FdtParserHandle, NewCmObjDesc);
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
ASSERT_EFI_ERROR (Status);
goto exit_handler;
}
/* Search for APLIC/PLIC presence and update RINTC structures if so */
Status = PlicAplicInfoParser (FdtParserHandle, NewCmObjDesc);
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
ASSERT_EFI_ERROR (Status);
goto exit_handler;
}
// Finally, add all the RINTC CmObjs to the Configuration Manager.
Status = AddMultipleCmObj (FdtParserHandle, NewCmObjDesc, 0, NULL);
if (EFI_ERROR (Status)) {
ASSERT (0);
goto exit_handler;
}
exit_handler:
FreeCmObjDesc (NewCmObjDesc);
return Status;
}
/** MADT dispatcher.
A parser parses a Device Tree to populate a specific CmObj type. None,
one or many CmObj can be created by the parser.
The created CmObj are then handed to the parser's caller through the
HW_INFO_ADD_OBJECT interface.
This can also be a dispatcher. I.e. a function that not parsing a
Device Tree but calling other parsers.
@param [in] FdtParserHandle A handle to the parser instance.
@param [in] FdtBranch When searching for DT node name, restrict
the search to this Device Tree branch.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_ABORTED An error occurred.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_NOT_FOUND Not found.
@retval EFI_UNSUPPORTED Unsupported.
**/
EFI_STATUS
EFIAPI
RiscVIntcDispatcher (
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
IN INT32 FdtBranch
)
{
EFI_STATUS Status;
INT32 CpusNode;
VOID *Fdt;
if (FdtParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
Fdt = FdtParserHandle->Fdt;
// The "cpus" node resides at the root of the DT. Fetch it.
CpusNode = FdtPathOffset (Fdt, "/cpus");
if (CpusNode < 0) {
return EFI_NOT_FOUND;
}
Status = RiscVIntcInfoParser (FdtParserHandle, CpusNode);
if (EFI_ERROR (Status)) {
// EFI_NOT_FOUND is not tolerated at this point.
ASSERT (0);
return Status;
}
return EFI_SUCCESS;
}
|