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
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
|
/** @file
This driver produces Extended SCSI Pass Thru Protocol instances for
pvscsi devices.
Copyright (C) 2020, Oracle and/or its affiliates.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <IndustryStandard/Pci.h>
#include <IndustryStandard/PvScsi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/PciIo.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Uefi/UefiSpec.h>
#include "PvScsi.h"
//
// Higher versions will be used before lower, 0x10-0xffffffef is the version
// range for IHV (Indie Hardware Vendors)
//
#define PVSCSI_BINDING_VERSION 0x10
//
// Ext SCSI Pass Thru utilities
//
/**
Reads a 32-bit value into BAR0 using MMIO
**/
STATIC
EFI_STATUS
PvScsiMmioRead32 (
IN CONST PVSCSI_DEV *Dev,
IN UINT64 Offset,
OUT UINT32 *Value
)
{
return Dev->PciIo->Mem.Read (
Dev->PciIo,
EfiPciIoWidthUint32,
PCI_BAR_IDX0,
Offset,
1, // Count
Value
);
}
/**
Writes a 32-bit value into BAR0 using MMIO
**/
STATIC
EFI_STATUS
PvScsiMmioWrite32 (
IN CONST PVSCSI_DEV *Dev,
IN UINT64 Offset,
IN UINT32 Value
)
{
return Dev->PciIo->Mem.Write (
Dev->PciIo,
EfiPciIoWidthUint32,
PCI_BAR_IDX0,
Offset,
1, // Count
&Value
);
}
/**
Writes multiple words of data into BAR0 using MMIO
**/
STATIC
EFI_STATUS
PvScsiMmioWrite32Multiple (
IN CONST PVSCSI_DEV *Dev,
IN UINT64 Offset,
IN UINTN Count,
IN UINT32 *Words
)
{
return Dev->PciIo->Mem.Write (
Dev->PciIo,
EfiPciIoWidthFifoUint32,
PCI_BAR_IDX0,
Offset,
Count,
Words
);
}
/**
Send a PVSCSI command to device.
@param[in] Dev The pvscsi host device.
@param[in] Cmd The command to send to device.
@param[in] OPTIONAL DescWords An optional command descriptor (If command
have a descriptor). The descriptor is
provided as an array of UINT32 words and
is must be 32-bit aligned.
@param[in] DescWordsCount The number of words in command descriptor.
Caller must specify here 0 if DescWords
is not supplied (It is optional). In that
case, DescWords is ignored.
@return Status codes returned by Dev->PciIo->Mem.Write().
**/
STATIC
EFI_STATUS
PvScsiWriteCmdDesc (
IN CONST PVSCSI_DEV *Dev,
IN UINT32 Cmd,
IN UINT32 *DescWords OPTIONAL,
IN UINTN DescWordsCount
)
{
EFI_STATUS Status;
if (DescWordsCount > PVSCSI_MAX_CMD_DATA_WORDS) {
return EFI_INVALID_PARAMETER;
}
Status = PvScsiMmioWrite32 (Dev, PvScsiRegOffsetCommand, Cmd);
if (EFI_ERROR (Status)) {
return Status;
}
if (DescWordsCount > 0) {
return PvScsiMmioWrite32Multiple (
Dev,
PvScsiRegOffsetCommandData,
DescWordsCount,
DescWords
);
}
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
PvScsiResetAdapter (
IN CONST PVSCSI_DEV *Dev
)
{
return PvScsiWriteCmdDesc (Dev, PvScsiCmdAdapterReset, NULL, 0);
}
/**
Returns if PVSCSI request ring is full
**/
STATIC
BOOLEAN
PvScsiIsReqRingFull (
IN CONST PVSCSI_DEV *Dev
)
{
PVSCSI_RINGS_STATE *RingsState;
UINT32 ReqNumEntries;
RingsState = Dev->RingDesc.RingState;
ReqNumEntries = 1U << RingsState->ReqNumEntriesLog2;
return (RingsState->ReqProdIdx - RingsState->CmpConsIdx) >= ReqNumEntries;
}
/**
Returns pointer to current request descriptor to produce
**/
STATIC
PVSCSI_RING_REQ_DESC *
PvScsiGetCurrentRequest (
IN CONST PVSCSI_DEV *Dev
)
{
PVSCSI_RINGS_STATE *RingState;
UINT32 ReqNumEntries;
RingState = Dev->RingDesc.RingState;
ReqNumEntries = 1U << RingState->ReqNumEntriesLog2;
return Dev->RingDesc.RingReqs +
(RingState->ReqProdIdx & (ReqNumEntries - 1));
}
/**
Returns pointer to current completion descriptor to consume
**/
STATIC
PVSCSI_RING_CMP_DESC *
PvScsiGetCurrentResponse (
IN CONST PVSCSI_DEV *Dev
)
{
PVSCSI_RINGS_STATE *RingState;
UINT32 CmpNumEntries;
RingState = Dev->RingDesc.RingState;
CmpNumEntries = 1U << RingState->CmpNumEntriesLog2;
return Dev->RingDesc.RingCmps +
(RingState->CmpConsIdx & (CmpNumEntries - 1));
}
/**
Wait for device to signal completion of submitted requests
**/
STATIC
EFI_STATUS
PvScsiWaitForRequestCompletion (
IN CONST PVSCSI_DEV *Dev
)
{
EFI_STATUS Status;
UINT32 IntrStatus;
//
// Note: We don't yet support Timeout according to
// EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET.Timeout.
//
// This is consistent with some other Scsi PassThru drivers
// such as VirtioScsi.
//
for (;;) {
Status = PvScsiMmioRead32 (Dev, PvScsiRegOffsetIntrStatus, &IntrStatus);
if (EFI_ERROR (Status)) {
return Status;
}
//
// PVSCSI_INTR_CMPL_MASK is set if device completed submitted requests
//
if ((IntrStatus & PVSCSI_INTR_CMPL_MASK) != 0) {
break;
}
gBS->Stall (Dev->WaitForCmpStallInUsecs);
}
//
// Acknowledge PVSCSI_INTR_CMPL_MASK in device interrupt-status register
//
return PvScsiMmioWrite32 (
Dev,
PvScsiRegOffsetIntrStatus,
PVSCSI_INTR_CMPL_MASK
);
}
/**
Create a fake host adapter error
**/
STATIC
EFI_STATUS
ReportHostAdapterError (
OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
)
{
Packet->InTransferLength = 0;
Packet->OutTransferLength = 0;
Packet->SenseDataLength = 0;
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;
Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD;
return EFI_DEVICE_ERROR;
}
/**
Create a fake host adapter overrun error
**/
STATIC
EFI_STATUS
ReportHostAdapterOverrunError (
OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
)
{
Packet->SenseDataLength = 0;
Packet->HostAdapterStatus =
EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OVERRUN_UNDERRUN;
Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD;
return EFI_BAD_BUFFER_SIZE;
}
/**
Populate a PVSCSI request descriptor from the Extended SCSI Pass Thru
Protocol packet.
**/
STATIC
EFI_STATUS
PopulateRequest (
IN CONST PVSCSI_DEV *Dev,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
OUT PVSCSI_RING_REQ_DESC *Request
)
{
UINT8 TargetValue;
//
// We only use first byte of target identifer
//
TargetValue = *Target;
//
// Check for unsupported requests
//
if (
//
// Bidirectional transfer was requested
//
(Packet->InTransferLength > 0 && Packet->OutTransferLength > 0) ||
(Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL) ||
//
// Command Descriptor Block bigger than this constant should be considered
// out-of-band. We currently don't support these CDBs.
//
(Packet->CdbLength > PVSCSI_CDB_MAX_SIZE)
) {
//
// This error code doesn't require updates to the Packet output fields
//
return EFI_UNSUPPORTED;
}
//
// Check for invalid parameters
//
if (
//
// Addressed invalid device
//
(TargetValue > Dev->MaxTarget) || (Lun > Dev->MaxLun) ||
//
// Invalid direction (there doesn't seem to be a macro for the "no data
// transferred" "direction", eg. for TEST UNIT READY)
//
(Packet->DataDirection > EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL) ||
//
// Trying to receive, but destination pointer is NULL, or contradicting
// transfer direction
//
((Packet->InTransferLength > 0) &&
((Packet->InDataBuffer == NULL) ||
(Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_WRITE)
)
) ||
//
// Trying to send, but source pointer is NULL, or contradicting
// transfer direction
//
((Packet->OutTransferLength > 0) &&
((Packet->OutDataBuffer == NULL) ||
(Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ)
)
)
) {
//
// This error code doesn't require updates to the Packet output fields
//
return EFI_INVALID_PARAMETER;
}
//
// Check for input/output buffer too large for DMA communication buffer
//
if (Packet->InTransferLength > sizeof (Dev->DmaBuf->Data)) {
Packet->InTransferLength = sizeof (Dev->DmaBuf->Data);
return ReportHostAdapterOverrunError (Packet);
}
if (Packet->OutTransferLength > sizeof (Dev->DmaBuf->Data)) {
Packet->OutTransferLength = sizeof (Dev->DmaBuf->Data);
return ReportHostAdapterOverrunError (Packet);
}
//
// Encode PVSCSI request
//
ZeroMem (Request, sizeof (*Request));
Request->Bus = 0;
Request->Target = TargetValue;
//
// This cast is safe as PVSCSI_DEV.MaxLun is defined as UINT8
//
Request->Lun[1] = (UINT8)Lun;
Request->SenseLen = Packet->SenseDataLength;
//
// DMA communication buffer SenseData overflow is not possible
// due to Packet->SenseDataLength defined as UINT8
//
Request->SenseAddr = PVSCSI_DMA_BUF_DEV_ADDR (Dev, SenseData);
Request->CdbLen = Packet->CdbLength;
CopyMem (Request->Cdb, Packet->Cdb, Packet->CdbLength);
Request->VcpuHint = 0;
Request->Tag = PVSCSI_SIMPLE_QUEUE_TAG;
if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ) {
Request->Flags = PVSCSI_FLAG_CMD_DIR_TOHOST;
Request->DataLen = Packet->InTransferLength;
} else {
Request->Flags = PVSCSI_FLAG_CMD_DIR_TODEVICE;
Request->DataLen = Packet->OutTransferLength;
CopyMem (
Dev->DmaBuf->Data,
Packet->OutDataBuffer,
Packet->OutTransferLength
);
}
Request->DataAddr = PVSCSI_DMA_BUF_DEV_ADDR (Dev, Data);
return EFI_SUCCESS;
}
/**
Handle the PVSCSI device response:
- Copy returned data from DMA communication buffer.
- Update fields in Extended SCSI Pass Thru Protocol packet as required.
- Translate response code to EFI status code and host adapter status.
**/
STATIC
EFI_STATUS
HandleResponse (
IN PVSCSI_DEV *Dev,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
IN CONST PVSCSI_RING_CMP_DESC *Response
)
{
//
// Fix SenseDataLength to amount of data returned
//
if (Packet->SenseDataLength > Response->SenseLen) {
Packet->SenseDataLength = (UINT8)Response->SenseLen;
}
//
// Copy sense data from DMA communication buffer
//
CopyMem (
Packet->SenseData,
Dev->DmaBuf->SenseData,
Packet->SenseDataLength
);
//
// Copy device output from DMA communication buffer
//
if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ) {
CopyMem (Packet->InDataBuffer, Dev->DmaBuf->Data, Packet->InTransferLength);
}
//
// Report target status
//
Packet->TargetStatus = Response->ScsiStatus;
//
// Host adapter status and function return value depend on
// device response's host status
//
switch (Response->HostStatus) {
case PvScsiBtStatSuccess:
case PvScsiBtStatLinkedCommandCompleted:
case PvScsiBtStatLinkedCommandCompletedWithFlag:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OK;
return EFI_SUCCESS;
case PvScsiBtStatDataUnderrun:
//
// Report transferred amount in underrun
//
if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ) {
Packet->InTransferLength = (UINT32)Response->DataLen;
} else {
Packet->OutTransferLength = (UINT32)Response->DataLen;
}
Packet->HostAdapterStatus =
EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OVERRUN_UNDERRUN;
return EFI_SUCCESS;
case PvScsiBtStatDatarun:
Packet->HostAdapterStatus =
EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OVERRUN_UNDERRUN;
return EFI_SUCCESS;
case PvScsiBtStatSelTimeout:
Packet->HostAdapterStatus =
EFI_EXT_SCSI_STATUS_HOST_ADAPTER_SELECTION_TIMEOUT;
return EFI_TIMEOUT;
case PvScsiBtStatBusFree:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_BUS_FREE;
break;
case PvScsiBtStatInvPhase:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_PHASE_ERROR;
break;
case PvScsiBtStatSensFailed:
Packet->HostAdapterStatus =
EFI_EXT_SCSI_STATUS_HOST_ADAPTER_REQUEST_SENSE_FAILED;
break;
case PvScsiBtStatTagReject:
case PvScsiBtStatBadMsg:
Packet->HostAdapterStatus =
EFI_EXT_SCSI_STATUS_HOST_ADAPTER_MESSAGE_REJECT;
break;
case PvScsiBtStatBusReset:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_BUS_RESET;
break;
case PvScsiBtStatHaTimeout:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT;
return EFI_TIMEOUT;
case PvScsiBtStatScsiParity:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_PARITY_ERROR;
break;
default:
Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;
break;
}
return EFI_DEVICE_ERROR;
}
/**
Check if Target argument to EXT_SCSI_PASS_THRU.GetNextTarget() and
EXT_SCSI_PASS_THRU.GetNextTargetLun() is initialized
**/
STATIC
BOOLEAN
IsTargetInitialized (
IN UINT8 *Target
)
{
UINTN Idx;
for (Idx = 0; Idx < TARGET_MAX_BYTES; ++Idx) {
if (Target[Idx] != 0xFF) {
return TRUE;
}
}
return FALSE;
}
//
// Ext SCSI Pass Thru
//
STATIC
EFI_STATUS
EFIAPI
PvScsiPassThru (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
IN EFI_EVENT Event OPTIONAL
)
{
PVSCSI_DEV *Dev;
EFI_STATUS Status;
PVSCSI_RING_REQ_DESC *Request;
PVSCSI_RING_CMP_DESC *Response;
Dev = PVSCSI_FROM_PASS_THRU (This);
if (PvScsiIsReqRingFull (Dev)) {
return EFI_NOT_READY;
}
Request = PvScsiGetCurrentRequest (Dev);
Status = PopulateRequest (Dev, Target, Lun, Packet, Request);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Writes to Request must be globally visible before making request
// available to device
//
MemoryFence ();
Dev->RingDesc.RingState->ReqProdIdx++;
Status = PvScsiMmioWrite32 (Dev, PvScsiRegOffsetKickRwIo, 0);
if (EFI_ERROR (Status)) {
//
// If kicking the host fails, we must fake a host adapter error.
// EFI_NOT_READY would save us the effort, but it would also suggest that
// the caller retry.
//
return ReportHostAdapterError (Packet);
}
Status = PvScsiWaitForRequestCompletion (Dev);
if (EFI_ERROR (Status)) {
//
// If waiting for request completion fails, we must fake a host adapter
// error. EFI_NOT_READY would save us the effort, but it would also suggest
// that the caller retry.
//
return ReportHostAdapterError (Packet);
}
Response = PvScsiGetCurrentResponse (Dev);
Status = HandleResponse (Dev, Packet, Response);
//
// Reads from response must complete before releasing completion entry
// to device
//
MemoryFence ();
Dev->RingDesc.RingState->CmpConsIdx++;
return Status;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiGetNextTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN OUT UINT8 **Target,
IN OUT UINT64 *Lun
)
{
UINT8 *TargetPtr;
UINT8 LastTarget;
PVSCSI_DEV *Dev;
if (Target == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// The Target input parameter is unnecessarily a pointer-to-pointer
//
TargetPtr = *Target;
//
// If target not initialized, return first target & LUN
//
if (!IsTargetInitialized (TargetPtr)) {
ZeroMem (TargetPtr, TARGET_MAX_BYTES);
*Lun = 0;
return EFI_SUCCESS;
}
//
// We only use first byte of target identifer
//
LastTarget = *TargetPtr;
//
// Increment (target, LUN) pair if valid on input
//
Dev = PVSCSI_FROM_PASS_THRU (This);
if (LastTarget > Dev->MaxTarget || *Lun > Dev->MaxLun) {
return EFI_INVALID_PARAMETER;
}
if (*Lun < Dev->MaxLun) {
++*Lun;
return EFI_SUCCESS;
}
if (LastTarget < Dev->MaxTarget) {
*Lun = 0;
++LastTarget;
*TargetPtr = LastTarget;
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiBuildDevicePath (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
)
{
UINT8 TargetValue;
PVSCSI_DEV *Dev;
SCSI_DEVICE_PATH *ScsiDevicePath;
if (DevicePath == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// We only use first byte of target identifer
//
TargetValue = *Target;
Dev = PVSCSI_FROM_PASS_THRU (This);
if (TargetValue > Dev->MaxTarget || Lun > Dev->MaxLun) {
return EFI_NOT_FOUND;
}
ScsiDevicePath = AllocatePool (sizeof (*ScsiDevicePath));
if (ScsiDevicePath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
ScsiDevicePath->Header.Type = MESSAGING_DEVICE_PATH;
ScsiDevicePath->Header.SubType = MSG_SCSI_DP;
ScsiDevicePath->Header.Length[0] = (UINT8)sizeof (*ScsiDevicePath);
ScsiDevicePath->Header.Length[1] = (UINT8)(sizeof (*ScsiDevicePath) >> 8);
ScsiDevicePath->Pun = TargetValue;
ScsiDevicePath->Lun = (UINT16)Lun;
*DevicePath = &ScsiDevicePath->Header;
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiGetTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT UINT8 **Target,
OUT UINT64 *Lun
)
{
SCSI_DEVICE_PATH *ScsiDevicePath;
PVSCSI_DEV *Dev;
if (DevicePath == NULL || Target == NULL || *Target == NULL || Lun == NULL) {
return EFI_INVALID_PARAMETER;
}
if (DevicePath->Type != MESSAGING_DEVICE_PATH ||
DevicePath->SubType != MSG_SCSI_DP) {
return EFI_UNSUPPORTED;
}
ScsiDevicePath = (SCSI_DEVICE_PATH *)DevicePath;
Dev = PVSCSI_FROM_PASS_THRU (This);
if (ScsiDevicePath->Pun > Dev->MaxTarget ||
ScsiDevicePath->Lun > Dev->MaxLun) {
return EFI_NOT_FOUND;
}
//
// We only use first byte of target identifer
//
**Target = (UINT8)ScsiDevicePath->Pun;
ZeroMem (*Target + 1, TARGET_MAX_BYTES - 1);
*Lun = ScsiDevicePath->Lun;
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiResetChannel (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
)
{
return EFI_UNSUPPORTED;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiResetTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun
)
{
return EFI_UNSUPPORTED;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiGetNextTarget (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN OUT UINT8 **Target
)
{
UINT8 *TargetPtr;
UINT8 LastTarget;
PVSCSI_DEV *Dev;
if (Target == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// The Target input parameter is unnecessarily a pointer-to-pointer
//
TargetPtr = *Target;
//
// If target not initialized, return first target
//
if (!IsTargetInitialized (TargetPtr)) {
ZeroMem (TargetPtr, TARGET_MAX_BYTES);
return EFI_SUCCESS;
}
//
// We only use first byte of target identifer
//
LastTarget = *TargetPtr;
//
// Increment target if valid on input
//
Dev = PVSCSI_FROM_PASS_THRU (This);
if (LastTarget > Dev->MaxTarget) {
return EFI_INVALID_PARAMETER;
}
if (LastTarget < Dev->MaxTarget) {
++LastTarget;
*TargetPtr = LastTarget;
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}
STATIC
EFI_STATUS
PvScsiSetPciAttributes (
IN OUT PVSCSI_DEV *Dev
)
{
EFI_STATUS Status;
//
// Backup original PCI Attributes
//
Status = Dev->PciIo->Attributes (
Dev->PciIo,
EfiPciIoAttributeOperationGet,
0,
&Dev->OriginalPciAttributes
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Enable MMIO-Space & Bus-Mastering
//
Status = Dev->PciIo->Attributes (
Dev->PciIo,
EfiPciIoAttributeOperationEnable,
(EFI_PCI_IO_ATTRIBUTE_MEMORY |
EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
STATIC
VOID
PvScsiRestorePciAttributes (
IN PVSCSI_DEV *Dev
)
{
Dev->PciIo->Attributes (
Dev->PciIo,
EfiPciIoAttributeOperationSet,
Dev->OriginalPciAttributes,
NULL
);
}
STATIC
EFI_STATUS
PvScsiAllocateSharedPages (
IN PVSCSI_DEV *Dev,
IN UINTN Pages,
OUT VOID **HostAddress,
OUT PVSCSI_DMA_DESC *DmaDesc
)
{
EFI_STATUS Status;
UINTN NumberOfBytes;
Status = Dev->PciIo->AllocateBuffer (
Dev->PciIo,
AllocateAnyPages,
EfiBootServicesData,
Pages,
HostAddress,
EFI_PCI_ATTRIBUTE_MEMORY_CACHED
);
if (EFI_ERROR (Status)) {
return Status;
}
NumberOfBytes = EFI_PAGES_TO_SIZE (Pages);
Status = Dev->PciIo->Map (
Dev->PciIo,
EfiPciIoOperationBusMasterCommonBuffer,
*HostAddress,
&NumberOfBytes,
&DmaDesc->DeviceAddress,
&DmaDesc->Mapping
);
if (EFI_ERROR (Status)) {
goto FreeBuffer;
}
if (NumberOfBytes != EFI_PAGES_TO_SIZE (Pages)) {
Status = EFI_OUT_OF_RESOURCES;
goto Unmap;
}
return EFI_SUCCESS;
Unmap:
Dev->PciIo->Unmap (Dev->PciIo, DmaDesc->Mapping);
FreeBuffer:
Dev->PciIo->FreeBuffer (Dev->PciIo, Pages, *HostAddress);
return Status;
}
STATIC
VOID
PvScsiFreeSharedPages (
IN PVSCSI_DEV *Dev,
IN UINTN Pages,
IN VOID *HostAddress,
IN PVSCSI_DMA_DESC *DmaDesc
)
{
Dev->PciIo->Unmap (Dev->PciIo, DmaDesc->Mapping);
Dev->PciIo->FreeBuffer (Dev->PciIo, Pages, HostAddress);
}
STATIC
EFI_STATUS
PvScsiInitRings (
IN OUT PVSCSI_DEV *Dev
)
{
EFI_STATUS Status;
union {
PVSCSI_CMD_DESC_SETUP_RINGS Cmd;
UINT32 Uint32;
} AlignedCmd;
PVSCSI_CMD_DESC_SETUP_RINGS *Cmd;
Cmd = &AlignedCmd.Cmd;
Status = PvScsiAllocateSharedPages (
Dev,
1,
(VOID **)&Dev->RingDesc.RingState,
&Dev->RingDesc.RingStateDmaDesc
);
if (EFI_ERROR (Status)) {
return Status;
}
ZeroMem (Dev->RingDesc.RingState, EFI_PAGE_SIZE);
Status = PvScsiAllocateSharedPages (
Dev,
1,
(VOID **)&Dev->RingDesc.RingReqs,
&Dev->RingDesc.RingReqsDmaDesc
);
if (EFI_ERROR (Status)) {
goto FreeRingState;
}
ZeroMem (Dev->RingDesc.RingReqs, EFI_PAGE_SIZE);
Status = PvScsiAllocateSharedPages (
Dev,
1,
(VOID **)&Dev->RingDesc.RingCmps,
&Dev->RingDesc.RingCmpsDmaDesc
);
if (EFI_ERROR (Status)) {
goto FreeRingReqs;
}
ZeroMem (Dev->RingDesc.RingCmps, EFI_PAGE_SIZE);
ZeroMem (Cmd, sizeof (*Cmd));
Cmd->ReqRingNumPages = 1;
Cmd->CmpRingNumPages = 1;
Cmd->RingsStatePPN = RShiftU64 (
Dev->RingDesc.RingStateDmaDesc.DeviceAddress,
EFI_PAGE_SHIFT
);
Cmd->ReqRingPPNs[0] = RShiftU64 (
Dev->RingDesc.RingReqsDmaDesc.DeviceAddress,
EFI_PAGE_SHIFT
);
Cmd->CmpRingPPNs[0] = RShiftU64 (
Dev->RingDesc.RingCmpsDmaDesc.DeviceAddress,
EFI_PAGE_SHIFT
);
STATIC_ASSERT (
sizeof (*Cmd) % sizeof (UINT32) == 0,
"Cmd must be multiple of 32-bit words"
);
Status = PvScsiWriteCmdDesc (
Dev,
PvScsiCmdSetupRings,
(UINT32 *)Cmd,
sizeof (*Cmd) / sizeof (UINT32)
);
if (EFI_ERROR (Status)) {
goto FreeRingCmps;
}
return EFI_SUCCESS;
FreeRingCmps:
PvScsiFreeSharedPages (
Dev,
1,
Dev->RingDesc.RingCmps,
&Dev->RingDesc.RingCmpsDmaDesc
);
FreeRingReqs:
PvScsiFreeSharedPages (
Dev,
1,
Dev->RingDesc.RingReqs,
&Dev->RingDesc.RingReqsDmaDesc
);
FreeRingState:
PvScsiFreeSharedPages (
Dev,
1,
Dev->RingDesc.RingState,
&Dev->RingDesc.RingStateDmaDesc
);
return Status;
}
STATIC
VOID
PvScsiFreeRings (
IN OUT PVSCSI_DEV *Dev
)
{
PvScsiFreeSharedPages (
Dev,
1,
Dev->RingDesc.RingCmps,
&Dev->RingDesc.RingCmpsDmaDesc
);
PvScsiFreeSharedPages (
Dev,
1,
Dev->RingDesc.RingReqs,
&Dev->RingDesc.RingReqsDmaDesc
);
PvScsiFreeSharedPages (
Dev,
1,
Dev->RingDesc.RingState,
&Dev->RingDesc.RingStateDmaDesc
);
}
STATIC
EFI_STATUS
PvScsiInit (
IN OUT PVSCSI_DEV *Dev
)
{
EFI_STATUS Status;
//
// Init configuration
//
Dev->MaxTarget = PcdGet8 (PcdPvScsiMaxTargetLimit);
Dev->MaxLun = PcdGet8 (PcdPvScsiMaxLunLimit);
Dev->WaitForCmpStallInUsecs = PcdGet32 (PcdPvScsiWaitForCmpStallInUsecs);
//
// Set PCI Attributes
//
Status = PvScsiSetPciAttributes (Dev);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Reset adapter
//
Status = PvScsiResetAdapter (Dev);
if (EFI_ERROR (Status)) {
goto RestorePciAttributes;
}
//
// Init PVSCSI rings
//
Status = PvScsiInitRings (Dev);
if (EFI_ERROR (Status)) {
goto RestorePciAttributes;
}
//
// Allocate DMA communication buffer
//
Status = PvScsiAllocateSharedPages (
Dev,
EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)),
(VOID **)&Dev->DmaBuf,
&Dev->DmaBufDmaDesc
);
if (EFI_ERROR (Status)) {
goto FreeRings;
}
//
// Populate the exported interface's attributes
//
Dev->PassThru.Mode = &Dev->PassThruMode;
Dev->PassThru.PassThru = &PvScsiPassThru;
Dev->PassThru.GetNextTargetLun = &PvScsiGetNextTargetLun;
Dev->PassThru.BuildDevicePath = &PvScsiBuildDevicePath;
Dev->PassThru.GetTargetLun = &PvScsiGetTargetLun;
Dev->PassThru.ResetChannel = &PvScsiResetChannel;
Dev->PassThru.ResetTargetLun = &PvScsiResetTargetLun;
Dev->PassThru.GetNextTarget = &PvScsiGetNextTarget;
//
// AdapterId is a target for which no handle will be created during bus scan.
// Prevent any conflict with real devices.
//
Dev->PassThruMode.AdapterId = MAX_UINT32;
//
// Set both physical and logical attributes for non-RAID SCSI channel
//
Dev->PassThruMode.Attributes = EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL |
EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;
//
// No restriction on transfer buffer alignment
//
Dev->PassThruMode.IoAlign = 0;
return EFI_SUCCESS;
FreeRings:
//
// Reset device to stop device usage of the rings.
// This is required to safely free the rings.
//
PvScsiResetAdapter (Dev);
PvScsiFreeRings (Dev);
RestorePciAttributes:
PvScsiRestorePciAttributes (Dev);
return Status;
}
STATIC
VOID
PvScsiUninit (
IN OUT PVSCSI_DEV *Dev
)
{
//
// Reset device to:
// - Make device stop processing all requests.
// - Stop device usage of the rings.
//
// This is required to safely free the DMA communication buffer
// and the rings.
//
PvScsiResetAdapter (Dev);
//
// Free DMA communication buffer
//
PvScsiFreeSharedPages (
Dev,
EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)),
Dev->DmaBuf,
&Dev->DmaBufDmaDesc
);
PvScsiFreeRings (Dev);
PvScsiRestorePciAttributes (Dev);
}
/**
Event notification called by ExitBootServices()
**/
STATIC
VOID
EFIAPI
PvScsiExitBoot (
IN EFI_EVENT Event,
IN VOID *Context
)
{
PVSCSI_DEV *Dev;
Dev = Context;
DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));
//
// Reset the device to stop device usage of the rings.
//
// We allocated said rings in EfiBootServicesData type memory, and code
// executing after ExitBootServices() is permitted to overwrite it.
//
PvScsiResetAdapter (Dev);
}
//
// Driver Binding
//
STATIC
EFI_STATUS
EFIAPI
PvScsiDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci;
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
(VOID **)&PciIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = PciIo->Pci.Read (
PciIo,
EfiPciIoWidthUint32,
0,
sizeof (Pci) / sizeof (UINT32),
&Pci
);
if (EFI_ERROR (Status)) {
goto Done;
}
if ((Pci.Hdr.VendorId != PCI_VENDOR_ID_VMWARE) ||
(Pci.Hdr.DeviceId != PCI_DEVICE_ID_VMWARE_PVSCSI)) {
Status = EFI_UNSUPPORTED;
goto Done;
}
Status = EFI_SUCCESS;
Done:
gBS->CloseProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
PVSCSI_DEV *Dev;
EFI_STATUS Status;
Dev = (PVSCSI_DEV *) AllocateZeroPool (sizeof (*Dev));
if (Dev == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
(VOID **)&Dev->PciIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
goto FreePvScsi;
}
Status = PvScsiInit (Dev);
if (EFI_ERROR (Status)) {
goto ClosePciIo;
}
Status = gBS->CreateEvent (
EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_CALLBACK,
&PvScsiExitBoot,
Dev,
&Dev->ExitBoot
);
if (EFI_ERROR (Status)) {
goto UninitDev;
}
//
// Setup complete, attempt to export the driver instance's PassThru interface
//
Dev->Signature = PVSCSI_SIG;
Status = gBS->InstallProtocolInterface (
&ControllerHandle,
&gEfiExtScsiPassThruProtocolGuid,
EFI_NATIVE_INTERFACE,
&Dev->PassThru
);
if (EFI_ERROR (Status)) {
goto CloseExitBoot;
}
return EFI_SUCCESS;
CloseExitBoot:
gBS->CloseEvent (Dev->ExitBoot);
UninitDev:
PvScsiUninit (Dev);
ClosePciIo:
gBS->CloseProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
FreePvScsi:
FreePool (Dev);
return Status;
}
STATIC
EFI_STATUS
EFIAPI
PvScsiDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;
PVSCSI_DEV *Dev;
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiExtScsiPassThruProtocolGuid,
(VOID **)&PassThru,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL // Lookup only
);
if (EFI_ERROR (Status)) {
return Status;
}
Dev = PVSCSI_FROM_PASS_THRU (PassThru);
Status = gBS->UninstallProtocolInterface (
ControllerHandle,
&gEfiExtScsiPassThruProtocolGuid,
&Dev->PassThru
);
if (EFI_ERROR (Status)) {
return Status;
}
gBS->CloseEvent (Dev->ExitBoot);
PvScsiUninit (Dev);
gBS->CloseProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
FreePool (Dev);
return EFI_SUCCESS;
}
STATIC EFI_DRIVER_BINDING_PROTOCOL mPvScsiDriverBinding = {
&PvScsiDriverBindingSupported,
&PvScsiDriverBindingStart,
&PvScsiDriverBindingStop,
PVSCSI_BINDING_VERSION,
NULL, // ImageHandle, filled by EfiLibInstallDriverBindingComponentName2()
NULL // DriverBindingHandle, filled as well
};
//
// Component Name
//
STATIC EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {
{ "eng;en", L"PVSCSI Host Driver" },
{ NULL, NULL }
};
STATIC EFI_COMPONENT_NAME_PROTOCOL mComponentName;
STATIC
EFI_STATUS
EFIAPI
PvScsiGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mDriverNameTable,
DriverName,
(BOOLEAN)(This == &mComponentName) // Iso639Language
);
}
STATIC
EFI_STATUS
EFIAPI
PvScsiGetDeviceName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE DeviceHandle,
IN EFI_HANDLE ChildHandle,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
return EFI_UNSUPPORTED;
}
STATIC EFI_COMPONENT_NAME_PROTOCOL mComponentName = {
&PvScsiGetDriverName,
&PvScsiGetDeviceName,
"eng" // SupportedLanguages, ISO 639-2 language codes
};
STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &PvScsiGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &PvScsiGetDeviceName,
"en" // SupportedLanguages, RFC 4646 language codes
};
//
// Entry Point
//
EFI_STATUS
EFIAPI
PvScsiEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&mPvScsiDriverBinding,
ImageHandle,
&mComponentName,
&mComponentName2
);
}
|