OvmfPkg: VirtioNetDxe: adapt feature negotiation to virtio-1.0
[mirror_edk2.git] / OvmfPkg / VirtioRngDxe / VirtioRng.c
CommitLineData
5528732a
AB
1/** @file\r
2\r
3 This driver produces EFI_RNG_PROTOCOL instances for virtio-rng devices.\r
4\r
5 The implementation is based on OvmfPkg/VirtioScsiDxe/VirtioScsi.c\r
6\r
7 Copyright (C) 2012, Red Hat, Inc.\r
8 Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
9\r
10 This driver:\r
11\r
12 Copyright (C) 2016, Linaro Ltd.\r
13\r
14 This program and the accompanying materials are licensed and made available\r
15 under the terms and conditions of the BSD License which accompanies this\r
16 distribution. The full text of the license may be found at\r
17 http://opensource.org/licenses/bsd-license.php\r
18\r
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
20 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
21\r
22**/\r
23\r
24#include <Library/BaseMemoryLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/UefiLib.h>\r
29#include <Library/VirtioLib.h>\r
30\r
31#include "VirtioRng.h"\r
32\r
33/**\r
34 Returns information about the random number generation implementation.\r
35\r
36 @param[in] This A pointer to the EFI_RNG_PROTOCOL\r
37 instance.\r
38 @param[in,out] RNGAlgorithmListSize On input, the size in bytes of\r
39 RNGAlgorithmList.\r
40 On output with a return code of\r
41 EFI_SUCCESS, the size in bytes of the\r
42 data returned in RNGAlgorithmList. On\r
43 output with a return code of\r
44 EFI_BUFFER_TOO_SMALL, the size of\r
45 RNGAlgorithmList required to obtain the\r
46 list.\r
47 @param[out] RNGAlgorithmList A caller-allocated memory buffer filled\r
48 by the driver with one EFI_RNG_ALGORITHM\r
49 element for each supported RNG algorithm.\r
50 The list must not change across multiple\r
51 calls to the same driver. The first\r
52 algorithm in the list is the default\r
53 algorithm for the driver.\r
54\r
55 @retval EFI_SUCCESS The RNG algorithm list was returned\r
56 successfully.\r
57 @retval EFI_UNSUPPORTED The services is not supported by this\r
58 driver.\r
59 @retval EFI_DEVICE_ERROR The list of algorithms could not be\r
60 retrieved due to a hardware or firmware\r
61 error.\r
62 @retval EFI_INVALID_PARAMETER One or more of the parameters are\r
63 incorrect.\r
64 @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too small\r
65 to hold the result.\r
66\r
67**/\r
68STATIC\r
69EFI_STATUS\r
70EFIAPI\r
71VirtioRngGetInfo (\r
72 IN EFI_RNG_PROTOCOL *This,\r
73 IN OUT UINTN *RNGAlgorithmListSize,\r
74 OUT EFI_RNG_ALGORITHM *RNGAlgorithmList\r
75 )\r
76{\r
77 if (This == NULL || RNGAlgorithmListSize == NULL) {\r
78 return EFI_INVALID_PARAMETER;\r
79 }\r
80\r
81 if (*RNGAlgorithmListSize < sizeof (EFI_RNG_ALGORITHM)) {\r
82 *RNGAlgorithmListSize = sizeof (EFI_RNG_ALGORITHM);\r
83 return EFI_BUFFER_TOO_SMALL;\r
84 }\r
85\r
86 if (RNGAlgorithmList == NULL) {\r
87 return EFI_INVALID_PARAMETER;\r
88 }\r
89\r
90 *RNGAlgorithmListSize = sizeof (EFI_RNG_ALGORITHM);\r
91 CopyGuid (RNGAlgorithmList, &gEfiRngAlgorithmRaw);\r
92\r
93 return EFI_SUCCESS;\r
94}\r
95\r
96/**\r
97 Produces and returns an RNG value using either the default or specified RNG\r
98 algorithm.\r
99\r
100 @param[in] This A pointer to the EFI_RNG_PROTOCOL\r
101 instance.\r
102 @param[in] RNGAlgorithm A pointer to the EFI_RNG_ALGORITHM that\r
103 identifies the RNG algorithm to use. May\r
104 be NULL in which case the function will\r
105 use its default RNG algorithm.\r
106 @param[in] RNGValueLength The length in bytes of the memory buffer\r
107 pointed to by RNGValue. The driver shall\r
108 return exactly this numbers of bytes.\r
109 @param[out] RNGValue A caller-allocated memory buffer filled\r
110 by the driver with the resulting RNG\r
111 value.\r
112\r
113 @retval EFI_SUCCESS The RNG value was returned successfully.\r
114 @retval EFI_UNSUPPORTED The algorithm specified by RNGAlgorithm\r
115 is not supported by this driver.\r
116 @retval EFI_DEVICE_ERROR An RNG value could not be retrieved due\r
117 to a hardware or firmware error.\r
118 @retval EFI_NOT_READY There is not enough random data available\r
119 to satisfy the length requested by\r
120 RNGValueLength.\r
121 @retval EFI_INVALID_PARAMETER RNGValue is NULL or RNGValueLength is\r
122 zero.\r
123\r
124**/\r
125STATIC\r
126EFI_STATUS\r
127EFIAPI\r
128VirtioRngGetRNG (\r
129 IN EFI_RNG_PROTOCOL *This,\r
130 IN EFI_RNG_ALGORITHM *RNGAlgorithm, OPTIONAL\r
131 IN UINTN RNGValueLength,\r
132 OUT UINT8 *RNGValue\r
133 )\r
134{\r
135 VIRTIO_RNG_DEV *Dev;\r
136 DESC_INDICES Indices;\r
137 volatile UINT8 *Buffer;\r
138 UINTN Index;\r
139 UINT32 Len;\r
140 UINT32 BufferSize;\r
141 EFI_STATUS Status;\r
142\r
143 if (This == NULL || RNGValueLength == 0 || RNGValue == NULL) {\r
144 return EFI_INVALID_PARAMETER;\r
145 }\r
146\r
147 //\r
148 // We only support the raw algorithm, so reject requests for anything else\r
149 //\r
150 if (RNGAlgorithm != NULL &&\r
151 !CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) {\r
152 return EFI_UNSUPPORTED;\r
153 }\r
154\r
155 Buffer = (volatile UINT8 *)AllocatePool (RNGValueLength);\r
156 if (Buffer == NULL) {\r
157 return EFI_DEVICE_ERROR;\r
158 }\r
159\r
160 Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (This);\r
161\r
162 //\r
163 // The Virtio RNG device may return less data than we asked it to, and can\r
164 // only return MAX_UINT32 bytes per invocation. So loop as long as needed to\r
165 // get all the entropy we were asked for.\r
166 //\r
167 for (Index = 0; Index < RNGValueLength; Index += Len) {\r
168 BufferSize = (UINT32)MIN (RNGValueLength - Index, (UINTN)MAX_UINT32);\r
169\r
170 VirtioPrepare (&Dev->Ring, &Indices);\r
171 VirtioAppendDesc (&Dev->Ring,\r
172 (UINTN)Buffer + Index,\r
173 BufferSize,\r
174 VRING_DESC_F_WRITE,\r
175 &Indices);\r
176\r
177 if (VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices, &Len) !=\r
178 EFI_SUCCESS) {\r
179 Status = EFI_DEVICE_ERROR;\r
180 goto FreeBuffer;\r
181 }\r
182 ASSERT (Len > 0);\r
183 ASSERT (Len <= BufferSize);\r
184 }\r
185\r
186 for (Index = 0; Index < RNGValueLength; Index++) {\r
187 RNGValue[Index] = Buffer[Index];\r
188 }\r
189 Status = EFI_SUCCESS;\r
190\r
191FreeBuffer:\r
192 FreePool ((VOID *)Buffer);\r
193 return Status;\r
194}\r
195\r
196STATIC\r
197EFI_STATUS\r
198EFIAPI\r
199VirtioRngInit (\r
200 IN OUT VIRTIO_RNG_DEV *Dev\r
201 )\r
202{\r
203 UINT8 NextDevStat;\r
204 EFI_STATUS Status;\r
205 UINT16 QueueSize;\r
bc8fde6f 206 UINT64 Features;\r
5528732a
AB
207\r
208 //\r
209 // Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence.\r
210 //\r
211 NextDevStat = 0; // step 1 -- reset device\r
212 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
213 if (EFI_ERROR (Status)) {\r
214 goto Failed;\r
215 }\r
216\r
217 NextDevStat |= VSTAT_ACK; // step 2 -- acknowledge device presence\r
218 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
219 if (EFI_ERROR (Status)) {\r
220 goto Failed;\r
221 }\r
222\r
223 NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it\r
224 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
225 if (EFI_ERROR (Status)) {\r
226 goto Failed;\r
227 }\r
228\r
229 //\r
230 // Set Page Size - MMIO VirtIo Specific\r
231 //\r
232 Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);\r
233 if (EFI_ERROR (Status)) {\r
234 goto Failed;\r
235 }\r
236\r
237 //\r
238 // step 4a -- retrieve and validate features\r
239 //\r
240 Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);\r
241 if (EFI_ERROR (Status)) {\r
242 goto Failed;\r
243 }\r
244\r
245 //\r
246 // step 4b -- allocate request virtqueue, just use #0\r
247 //\r
248 Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, 0);\r
249 if (EFI_ERROR (Status)) {\r
250 goto Failed;\r
251 }\r
252 Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);\r
253 if (EFI_ERROR (Status)) {\r
254 goto Failed;\r
255 }\r
256\r
257 //\r
258 // VirtioRngGetRNG() uses one descriptor\r
259 //\r
260 if (QueueSize < 1) {\r
261 Status = EFI_UNSUPPORTED;\r
262 goto Failed;\r
263 }\r
264\r
265 Status = VirtioRingInit (QueueSize, &Dev->Ring);\r
266 if (EFI_ERROR (Status)) {\r
267 goto Failed;\r
268 }\r
269\r
270 //\r
271 // Additional steps for MMIO: align the queue appropriately, and set the\r
272 // size. If anything fails from here on, we must release the ring resources.\r
273 //\r
274 Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize);\r
275 if (EFI_ERROR (Status)) {\r
276 goto ReleaseQueue;\r
277 }\r
278\r
279 Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE);\r
280 if (EFI_ERROR (Status)) {\r
281 goto ReleaseQueue;\r
282 }\r
283\r
284 //\r
285 // step 4c -- Report GPFN (guest-physical frame number) of queue.\r
286 //\r
07af4eee 287 Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);\r
5528732a
AB
288 if (EFI_ERROR (Status)) {\r
289 goto ReleaseQueue;\r
290 }\r
291\r
292 //\r
293 // step 5 -- Report understood features and guest-tuneables. None are\r
294 // currently defined for VirtioRng, and no generic features are needed by\r
295 // this driver.\r
296 //\r
28daafe0
LE
297 Features &= 0;\r
298 Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);\r
5528732a
AB
299 if (EFI_ERROR (Status)) {\r
300 goto ReleaseQueue;\r
301 }\r
302\r
303 //\r
304 // step 6 -- initialization complete\r
305 //\r
306 NextDevStat |= VSTAT_DRIVER_OK;\r
307 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
308 if (EFI_ERROR (Status)) {\r
309 goto ReleaseQueue;\r
310 }\r
311\r
312 //\r
313 // populate the exported interface's attributes\r
314 //\r
315 Dev->Rng.GetInfo = VirtioRngGetInfo;\r
316 Dev->Rng.GetRNG = VirtioRngGetRNG;\r
317\r
318 return EFI_SUCCESS;\r
319\r
320ReleaseQueue:\r
321 VirtioRingUninit (&Dev->Ring);\r
322\r
323Failed:\r
324 //\r
325 // Notify the host about our failure to setup: virtio-0.9.5, 2.2.2.1 Device\r
326 // Status. VirtIo access failure here should not mask the original error.\r
327 //\r
328 NextDevStat |= VSTAT_FAILED;\r
329 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
330\r
331 return Status; // reached only via Failed above\r
332}\r
333\r
334\r
335STATIC\r
336VOID\r
337EFIAPI\r
338VirtioRngUninit (\r
339 IN OUT VIRTIO_RNG_DEV *Dev\r
340 )\r
341{\r
342 //\r
343 // Reset the virtual device -- see virtio-0.9.5, 2.2.2.1 Device Status. When\r
344 // VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from\r
345 // the old comms area.\r
346 //\r
347 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);\r
348 VirtioRingUninit (&Dev->Ring);\r
349}\r
350\r
351//\r
352// Event notification function enqueued by ExitBootServices().\r
353//\r
354\r
355STATIC\r
356VOID\r
357EFIAPI\r
358VirtioRngExitBoot (\r
359 IN EFI_EVENT Event,\r
360 IN VOID *Context\r
361 )\r
362{\r
363 VIRTIO_RNG_DEV *Dev;\r
364\r
365 //\r
366 // Reset the device. This causes the hypervisor to forget about the virtio\r
367 // ring.\r
368 //\r
369 // We allocated said ring in EfiBootServicesData type memory, and code\r
370 // executing after ExitBootServices() is permitted to overwrite it.\r
371 //\r
372 Dev = Context;\r
373 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);\r
374}\r
375\r
376\r
377//\r
378// Probe, start and stop functions of this driver, called by the DXE core for\r
379// specific devices.\r
380//\r
381// The following specifications document these interfaces:\r
382// - Driver Writer's Guide for UEFI 2.3.1 v1.01, 9 Driver Binding Protocol\r
383// - UEFI Spec 2.3.1 + Errata C, 10.1 EFI Driver Binding Protocol\r
384//\r
385// The implementation follows:\r
386// - Driver Writer's Guide for UEFI 2.3.1 v1.01\r
387// - 5.1.3.4 OpenProtocol() and CloseProtocol()\r
388// - UEFI Spec 2.3.1 + Errata C\r
389// - 6.3 Protocol Handler Services\r
390//\r
391\r
392STATIC\r
393EFI_STATUS\r
394EFIAPI\r
395VirtioRngDriverBindingSupported (\r
396 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
397 IN EFI_HANDLE DeviceHandle,\r
398 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
399 )\r
400{\r
401 EFI_STATUS Status;\r
402 VIRTIO_DEVICE_PROTOCOL *VirtIo;\r
403\r
404 //\r
405 // Attempt to open the device with the VirtIo set of interfaces. On success,\r
406 // the protocol is "instantiated" for the VirtIo device. Covers duplicate\r
407 // open attempts (EFI_ALREADY_STARTED).\r
408 //\r
409 Status = gBS->OpenProtocol (\r
410 DeviceHandle, // candidate device\r
411 &gVirtioDeviceProtocolGuid, // for generic VirtIo access\r
412 (VOID **)&VirtIo, // handle to instantiate\r
413 This->DriverBindingHandle, // requestor driver identity\r
414 DeviceHandle, // ControllerHandle, according to\r
415 // the UEFI Driver Model\r
416 EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to\r
417 // the device; to be released\r
418 );\r
419 if (EFI_ERROR (Status)) {\r
420 return Status;\r
421 }\r
422\r
423 if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_ENTROPY_SOURCE) {\r
424 Status = EFI_UNSUPPORTED;\r
425 }\r
426\r
427 //\r
428 // We needed VirtIo access only transitorily, to see whether we support the\r
429 // device or not.\r
430 //\r
431 gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,\r
432 This->DriverBindingHandle, DeviceHandle);\r
433 return Status;\r
434}\r
435\r
436STATIC\r
437EFI_STATUS\r
438EFIAPI\r
439VirtioRngDriverBindingStart (\r
440 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
441 IN EFI_HANDLE DeviceHandle,\r
442 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
443 )\r
444{\r
445 VIRTIO_RNG_DEV *Dev;\r
446 EFI_STATUS Status;\r
447\r
448 Dev = (VIRTIO_RNG_DEV *) AllocateZeroPool (sizeof *Dev);\r
449 if (Dev == NULL) {\r
450 return EFI_OUT_OF_RESOURCES;\r
451 }\r
452\r
453 Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,\r
454 (VOID **)&Dev->VirtIo, This->DriverBindingHandle,\r
455 DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);\r
456 if (EFI_ERROR (Status)) {\r
457 goto FreeVirtioRng;\r
458 }\r
459\r
460 //\r
461 // VirtIo access granted, configure virtio-rng device.\r
462 //\r
463 Status = VirtioRngInit (Dev);\r
464 if (EFI_ERROR (Status)) {\r
465 goto CloseVirtIo;\r
466 }\r
467\r
468 Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK,\r
469 &VirtioRngExitBoot, Dev, &Dev->ExitBoot);\r
470 if (EFI_ERROR (Status)) {\r
471 goto UninitDev;\r
472 }\r
473\r
474 //\r
475 // Setup complete, attempt to export the driver instance's EFI_RNG_PROTOCOL\r
476 // interface.\r
477 //\r
478 Dev->Signature = VIRTIO_RNG_SIG;\r
479 Status = gBS->InstallProtocolInterface (&DeviceHandle,\r
480 &gEfiRngProtocolGuid, EFI_NATIVE_INTERFACE,\r
481 &Dev->Rng);\r
482 if (EFI_ERROR (Status)) {\r
483 goto CloseExitBoot;\r
484 }\r
485\r
486 return EFI_SUCCESS;\r
487\r
488CloseExitBoot:\r
489 gBS->CloseEvent (Dev->ExitBoot);\r
490\r
491UninitDev:\r
492 VirtioRngUninit (Dev);\r
493\r
494CloseVirtIo:\r
495 gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,\r
496 This->DriverBindingHandle, DeviceHandle);\r
497\r
498FreeVirtioRng:\r
499 FreePool (Dev);\r
500\r
501 return Status;\r
502}\r
503\r
504\r
505STATIC\r
506EFI_STATUS\r
507EFIAPI\r
508VirtioRngDriverBindingStop (\r
509 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
510 IN EFI_HANDLE DeviceHandle,\r
511 IN UINTN NumberOfChildren,\r
512 IN EFI_HANDLE *ChildHandleBuffer\r
513 )\r
514{\r
515 EFI_STATUS Status;\r
516 EFI_RNG_PROTOCOL *Rng;\r
517 VIRTIO_RNG_DEV *Dev;\r
518\r
519 Status = gBS->OpenProtocol (\r
520 DeviceHandle, // candidate device\r
521 &gEfiRngProtocolGuid, // retrieve the RNG iface\r
522 (VOID **)&Rng, // target pointer\r
523 This->DriverBindingHandle, // requestor driver ident.\r
524 DeviceHandle, // lookup req. for dev.\r
525 EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no new ref.\r
526 );\r
527 if (EFI_ERROR (Status)) {\r
528 return Status;\r
529 }\r
530\r
531 Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (Rng);\r
532\r
533 //\r
534 // Handle Stop() requests for in-use driver instances gracefully.\r
535 //\r
536 Status = gBS->UninstallProtocolInterface (DeviceHandle,\r
537 &gEfiRngProtocolGuid, &Dev->Rng);\r
538 if (EFI_ERROR (Status)) {\r
539 return Status;\r
540 }\r
541\r
542 gBS->CloseEvent (Dev->ExitBoot);\r
543\r
544 VirtioRngUninit (Dev);\r
545\r
546 gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,\r
547 This->DriverBindingHandle, DeviceHandle);\r
548\r
549 FreePool (Dev);\r
550\r
551 return EFI_SUCCESS;\r
552}\r
553\r
554\r
555//\r
556// The static object that groups the Supported() (ie. probe), Start() and\r
557// Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata\r
558// C, 10.1 EFI Driver Binding Protocol.\r
559//\r
560STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {\r
561 &VirtioRngDriverBindingSupported,\r
562 &VirtioRngDriverBindingStart,\r
563 &VirtioRngDriverBindingStop,\r
564 0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers\r
565 NULL, // ImageHandle, to be overwritten by\r
566 // EfiLibInstallDriverBindingComponentName2() in VirtioRngEntryPoint()\r
567 NULL // DriverBindingHandle, ditto\r
568};\r
569\r
570\r
571//\r
572// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and\r
573// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name\r
574// in English, for display on standard console devices. This is recommended for\r
575// UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's\r
576// Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.\r
577//\r
578\r
579STATIC\r
580EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {\r
581 { "eng;en", L"Virtio Random Number Generator Driver" },\r
582 { NULL, NULL }\r
583};\r
584\r
585STATIC\r
586EFI_COMPONENT_NAME_PROTOCOL gComponentName;\r
587\r
588STATIC\r
589EFI_STATUS\r
590EFIAPI\r
591VirtioRngGetDriverName (\r
592 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
593 IN CHAR8 *Language,\r
594 OUT CHAR16 **DriverName\r
595 )\r
596{\r
597 return LookupUnicodeString2 (\r
598 Language,\r
599 This->SupportedLanguages,\r
600 mDriverNameTable,\r
601 DriverName,\r
602 (BOOLEAN)(This == &gComponentName) // Iso639Language\r
603 );\r
604}\r
605\r
606STATIC\r
607EFI_STATUS\r
608EFIAPI\r
609VirtioRngGetDeviceName (\r
610 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
611 IN EFI_HANDLE DeviceHandle,\r
612 IN EFI_HANDLE ChildHandle,\r
613 IN CHAR8 *Language,\r
614 OUT CHAR16 **ControllerName\r
615 )\r
616{\r
617 return EFI_UNSUPPORTED;\r
618}\r
619\r
620STATIC\r
621EFI_COMPONENT_NAME_PROTOCOL gComponentName = {\r
622 &VirtioRngGetDriverName,\r
623 &VirtioRngGetDeviceName,\r
624 "eng" // SupportedLanguages, ISO 639-2 language codes\r
625};\r
626\r
627STATIC\r
628EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {\r
629 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &VirtioRngGetDriverName,\r
630 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &VirtioRngGetDeviceName,\r
631 "en" // SupportedLanguages, RFC 4646 language codes\r
632};\r
633\r
634\r
635//\r
636// Entry point of this driver.\r
637//\r
638EFI_STATUS\r
639EFIAPI\r
640VirtioRngEntryPoint (\r
641 IN EFI_HANDLE ImageHandle,\r
642 IN EFI_SYSTEM_TABLE *SystemTable\r
643 )\r
644{\r
645 return EfiLibInstallDriverBindingComponentName2 (\r
646 ImageHandle,\r
647 SystemTable,\r
648 &gDriverBinding,\r
649 ImageHandle,\r
650 &gComponentName,\r
651 &gComponentName2\r
652 );\r
653}\r