72 if ((This ==
NULL) || (RNGAlgorithmListSize ==
NULL)) {
73 return EFI_INVALID_PARAMETER;
78 return EFI_BUFFER_TOO_SMALL;
81 if (RNGAlgorithmList ==
NULL) {
82 return EFI_INVALID_PARAMETER;
86 CopyGuid (RNGAlgorithmList, &gEfiRngAlgorithmRaw);
132 volatile UINT8 *Buffer;
140 if ((This ==
NULL) || (RNGValueLength == 0) || (RNGValue ==
NULL)) {
141 return EFI_INVALID_PARAMETER;
147 if ((RNGAlgorithm !=
NULL) &&
150 return EFI_UNSUPPORTED;
153 Buffer = (
volatile UINT8 *)
AllocatePool (RNGValueLength);
154 if (Buffer ==
NULL) {
155 return EFI_DEVICE_ERROR;
158 Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (This);
160 DEBUG ((DEBUG_INFO,
"%a: not ready\n", __func__));
161 return EFI_DEVICE_ERROR;
169 VirtioOperationBusMasterWrite,
175 if (EFI_ERROR (Status)) {
176 Status = EFI_DEVICE_ERROR;
185 for (Index = 0; Index < RNGValueLength; Index += Len) {
186 BufferSize = (UINT32)
MIN (RNGValueLength - Index, (
UINTN)MAX_UINT32);
191 DeviceAddress + Index,
197 if (
VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices, &Len) !=
200 Status = EFI_DEVICE_ERROR;
205 ASSERT (Len <= BufferSize);
211 Status = Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping);
212 if (EFI_ERROR (Status)) {
213 Status = EFI_DEVICE_ERROR;
217 for (Index = 0; Index < RNGValueLength; Index++) {
218 RNGValue[Index] = Buffer[Index];
228 if (EFI_ERROR (Status)) {
229 Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping);
248 UINT64 RingBaseShift;
254 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
255 if (EFI_ERROR (Status)) {
259 NextDevStat |= VSTAT_ACK;
260 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
261 if (EFI_ERROR (Status)) {
265 NextDevStat |= VSTAT_DRIVER;
266 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
267 if (EFI_ERROR (Status)) {
274 Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
275 if (EFI_ERROR (Status)) {
282 Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
283 if (EFI_ERROR (Status)) {
287 Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
293 if (Dev->VirtIo->Revision >= VIRTIO_SPEC_REVISION (1, 0, 0)) {
295 if (EFI_ERROR (Status)) {
303 Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, 0);
304 if (EFI_ERROR (Status)) {
308 Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
309 if (EFI_ERROR (Status)) {
317 Status = EFI_UNSUPPORTED;
322 if (EFI_ERROR (Status)) {
335 if (EFI_ERROR (Status)) {
343 Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize);
344 if (EFI_ERROR (Status)) {
348 Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE);
349 if (EFI_ERROR (Status)) {
356 Status = Dev->VirtIo->SetQueueAddress (
361 if (EFI_ERROR (Status)) {
368 if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) {
369 Features &= ~(UINT64)(VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM);
370 Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);
371 if (EFI_ERROR (Status)) {
379 NextDevStat |= VSTAT_DRIVER_OK;
380 Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
381 if (EFI_ERROR (Status)) {
395 Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap);
405 NextDevStat |= VSTAT_FAILED;
406 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
424 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
425 Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap);
444 DEBUG ((DEBUG_INFO,
"%a: Context=0x%p\n", __func__, Context));
454 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
475VirtioRngDriverBindingSupported (
489 Status =
gBS->OpenProtocol (
491 &gVirtioDeviceProtocolGuid,
493 This->DriverBindingHandle,
496 EFI_OPEN_PROTOCOL_BY_DRIVER
499 if (EFI_ERROR (Status)) {
503 if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_ENTROPY_SOURCE) {
504 Status = EFI_UNSUPPORTED;
513 &gVirtioDeviceProtocolGuid,
514 This->DriverBindingHandle,
523VirtioRngDriverBindingStart (
534 return EFI_OUT_OF_RESOURCES;
537 Status =
gBS->OpenProtocol (
539 &gVirtioDeviceProtocolGuid,
540 (VOID **)&Dev->VirtIo,
541 This->DriverBindingHandle,
543 EFI_OPEN_PROTOCOL_BY_DRIVER
545 if (EFI_ERROR (Status)) {
552 Status = VirtioRngInit (Dev);
553 if (EFI_ERROR (Status)) {
557 Status =
gBS->CreateEvent (
558 EVT_SIGNAL_EXIT_BOOT_SERVICES,
564 if (EFI_ERROR (Status)) {
572 Dev->Signature = VIRTIO_RNG_SIG;
573 Status =
gBS->InstallProtocolInterface (
575 &gEfiRngProtocolGuid,
579 if (EFI_ERROR (Status)) {
586 gBS->CloseEvent (Dev->ExitBoot);
589 VirtioRngUninit (Dev);
594 &gVirtioDeviceProtocolGuid,
595 This->DriverBindingHandle,
608VirtioRngDriverBindingStop (
619 Status =
gBS->OpenProtocol (
621 &gEfiRngProtocolGuid,
623 This->DriverBindingHandle,
625 EFI_OPEN_PROTOCOL_GET_PROTOCOL
627 if (EFI_ERROR (Status)) {
631 Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (Rng);
636 Status =
gBS->UninstallProtocolInterface (
638 &gEfiRngProtocolGuid,
641 if (EFI_ERROR (Status)) {
645 gBS->CloseEvent (Dev->ExitBoot);
647 VirtioRngUninit (Dev);
651 &gVirtioDeviceProtocolGuid,
652 This->DriverBindingHandle,
667 &VirtioRngDriverBindingSupported,
668 &VirtioRngDriverBindingStart,
669 &VirtioRngDriverBindingStop,
686 {
"eng;en", L
"Virtio Random Number Generator Driver" },
696VirtioRngGetDriverName (
699 OUT CHAR16 **DriverName
704 This->SupportedLanguages,
707 (BOOLEAN)(This == &gComponentName)
714VirtioRngGetDeviceName (
719 OUT CHAR16 **ControllerName
722 return EFI_UNSUPPORTED;
727 &VirtioRngGetDriverName,
728 &VirtioRngGetDeviceName,
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME2_GET_DRIVER_NAME)(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_GUID EFI_RNG_ALGORITHM
UINT64 EFI_PHYSICAL_ADDRESS
EFI_STATUS EFIAPI LookupUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable, OUT CHAR16 **UnicodeString, IN BOOLEAN Iso639Language)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI VirtioMapAllBytesInSharedBuffer(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN VIRTIO_MAP_OPERATION Operation, IN VOID *HostAddress, IN UINTN NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
VOID EFIAPI VirtioAppendDesc(IN OUT VRING *Ring, IN UINT64 BufferDeviceAddress, IN UINT32 BufferSize, IN UINT16 Flags, IN OUT DESC_INDICES *Indices)
EFI_STATUS EFIAPI VirtioFlush(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 VirtQueueId, IN OUT VRING *Ring, IN DESC_INDICES *Indices, OUT UINT32 *UsedLen OPTIONAL)
EFI_STATUS EFIAPI VirtioRingMap(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN VRING *Ring, OUT UINT64 *RingBaseShift, OUT VOID **Mapping)
EFI_STATUS EFIAPI Virtio10WriteFeatures(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT64 Features, IN OUT UINT8 *DeviceStatus)
VOID EFIAPI VirtioPrepare(IN OUT VRING *Ring, OUT DESC_INDICES *Indices)
EFI_STATUS EFIAPI VirtioRingInit(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 QueueSize, OUT VRING *Ring)
VOID EFIAPI VirtioRingUninit(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN OUT VRING *Ring)
STATIC EFI_STATUS EFIAPI VirtioRngGetInfo(IN EFI_RNG_PROTOCOL *This, IN OUT UINTN *RNGAlgorithmListSize, OUT EFI_RNG_ALGORITHM *RNGAlgorithmList)
STATIC EFI_STATUS EFIAPI VirtioRngGetRNG(IN EFI_RNG_PROTOCOL *This, IN EFI_RNG_ALGORITHM *RNGAlgorithm OPTIONAL, IN UINTN RNGValueLength, OUT UINT8 *RNGValue)