11#define USB_MASS_TRANSPORT_COUNT 3
49 IN BOOLEAN ExtendedVerification
60 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
62 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);
63 Status = UsbMass->
Transport->
Reset (UsbMass->Context, ExtendedVerification);
65 gBS->RestoreTPL (OldTpl);
114 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
115 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);
116 Media = &UsbMass->BlockIoMedia;
125 if (EFI_ERROR (Status)) {
131 Status = EFI_NO_MEDIA;
135 if (MediaId != Media->
MediaId) {
136 Status = EFI_MEDIA_CHANGED;
140 if (BufferSize == 0) {
145 if (Buffer ==
NULL) {
146 Status = EFI_INVALID_PARAMETER;
153 if ((BufferSize % Media->
BlockSize) != 0) {
154 Status = EFI_BAD_BUFFER_SIZE;
158 TotalBlock = BufferSize / Media->
BlockSize;
163 if (Lba + TotalBlock - 1 > Media->
LastBlock) {
164 Status = EFI_INVALID_PARAMETER;
168 if (UsbMass->Cdb16Byte) {
174 if (EFI_ERROR (Status)) {
175 DEBUG ((DEBUG_ERROR,
"UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status));
180 gBS->RestoreTPL (OldTpl);
229 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
230 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);
231 Media = &UsbMass->BlockIoMedia;
240 if (EFI_ERROR (Status)) {
246 Status = EFI_NO_MEDIA;
250 if (MediaId != Media->
MediaId) {
251 Status = EFI_MEDIA_CHANGED;
255 if (BufferSize == 0) {
260 if (Buffer ==
NULL) {
261 Status = EFI_INVALID_PARAMETER;
268 if ((BufferSize % Media->
BlockSize) != 0) {
269 Status = EFI_BAD_BUFFER_SIZE;
273 TotalBlock = BufferSize / Media->
BlockSize;
278 if (Lba + TotalBlock - 1 > Media->
LastBlock) {
279 Status = EFI_INVALID_PARAMETER;
287 if (UsbMass->Cdb16Byte) {
293 if (EFI_ERROR (Status)) {
294 DEBUG ((DEBUG_ERROR,
"UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status));
299 gBS->RestoreTPL (OldTpl);
343 Media = &UsbMass->BlockIoMedia;
357 DEBUG ((DEBUG_INFO,
"UsbMassInitMedia: UsbBootGetParams (%r)\n", Status));
358 if (Status == EFI_MEDIA_CHANGED) {
400 Status =
gBS->OpenProtocol (
402 &gEfiUsbIoProtocolGuid,
404 This->DriverBindingHandle,
406 EFI_OPEN_PROTOCOL_BY_DRIVER
409 if (EFI_ERROR (Status)) {
413 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
414 if (EFI_ERROR (Status)) {
418 Status = EFI_UNSUPPORTED;
426 for (Index = 0; Index < USB_MASS_TRANSPORT_COUNT; Index++) {
427 *Transport = mUsbMassTransport[Index];
429 if (Interface.InterfaceProtocol == (*Transport)->Protocol) {
430 Status = (*Transport)->
Init (UsbIo, Context);
435 if (EFI_ERROR (Status)) {
445 (*Transport)->GetMaxLun (*Context, MaxLun);
451 &gEfiUsbIoProtocolGuid,
452 This->DriverBindingHandle,
490 ReturnStatus = EFI_NOT_FOUND;
492 for (Index = 0; Index <= MaxLun; Index++) {
493 DEBUG ((DEBUG_INFO,
"UsbMassInitMultiLun: Start to initialize No.%d logic unit\n", Index));
497 ASSERT (UsbMass !=
NULL);
499 UsbMass->Signature = USB_MASS_SIGNATURE;
500 UsbMass->UsbIo = UsbIo;
501 UsbMass->BlockIo.
Media = &UsbMass->BlockIoMedia;
506 UsbMass->OpticalStorage =
FALSE;
508 UsbMass->Context = Context;
509 UsbMass->
Lun = Index;
515 if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) {
516 DEBUG ((DEBUG_ERROR,
"UsbMassInitMultiLun: UsbMassInitMedia (%r)\n", Status));
526 LunNode.
Lun = UsbMass->
Lun;
532 if (UsbMass->DevicePath ==
NULL) {
533 DEBUG ((DEBUG_ERROR,
"UsbMassInitMultiLun: failed to create device logic unit device path\n"));
534 Status = EFI_OUT_OF_RESOURCES;
544 Status =
gBS->InstallMultipleProtocolInterfaces (
545 &UsbMass->Controller,
546 &gEfiDevicePathProtocolGuid,
548 &gEfiBlockIoProtocolGuid,
550 &gEfiDiskInfoProtocolGuid,
555 if (EFI_ERROR (Status)) {
556 DEBUG ((DEBUG_ERROR,
"UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status));
565 Status =
gBS->OpenProtocol (
567 &gEfiUsbIoProtocolGuid,
569 This->DriverBindingHandle,
571 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
574 if (EFI_ERROR (Status)) {
575 DEBUG ((DEBUG_ERROR,
"UsbMassInitMultiLun: OpenUsbIoProtocol By Child (%r)\n", Status));
576 gBS->UninstallMultipleProtocolInterfaces (
578 &gEfiDevicePathProtocolGuid,
580 &gEfiBlockIoProtocolGuid,
582 &gEfiDiskInfoProtocolGuid,
592 DEBUG ((DEBUG_INFO,
"UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));
624 ASSERT (UsbMass !=
NULL);
626 Status =
gBS->OpenProtocol (
628 &gEfiUsbIoProtocolGuid,
630 This->DriverBindingHandle,
632 EFI_OPEN_PROTOCOL_BY_DRIVER
635 if (EFI_ERROR (Status)) {
636 DEBUG ((DEBUG_ERROR,
"UsbMassInitNonLun: OpenUsbIoProtocol By Driver (%r)\n", Status));
640 UsbMass->Signature = USB_MASS_SIGNATURE;
641 UsbMass->Controller = Controller;
642 UsbMass->UsbIo = UsbIo;
643 UsbMass->BlockIo.
Media = &UsbMass->BlockIoMedia;
648 UsbMass->OpticalStorage =
FALSE;
650 UsbMass->Context = Context;
656 if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) {
657 DEBUG ((DEBUG_ERROR,
"UsbMassInitNonLun: UsbMassInitMedia (%r)\n", Status));
663 Status =
gBS->InstallMultipleProtocolInterfaces (
665 &gEfiBlockIoProtocolGuid,
667 &gEfiDiskInfoProtocolGuid,
671 if (EFI_ERROR (Status)) {
678 if (UsbMass !=
NULL) {
685 &gEfiUsbIoProtocolGuid,
686 This->DriverBindingHandle,
719 Status =
gBS->OpenProtocol (
721 &gEfiUsbIoProtocolGuid,
723 This->DriverBindingHandle,
725 EFI_OPEN_PROTOCOL_BY_DRIVER
727 if (EFI_ERROR (Status)) {
735 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
736 if (EFI_ERROR (Status)) {
740 Status = EFI_UNSUPPORTED;
742 if (Interface.InterfaceClass != USB_MASS_STORE_CLASS) {
752 for (Index = 0; Index < USB_MASS_TRANSPORT_COUNT; Index++) {
753 Transport = mUsbMassTransport[Index];
754 if (Interface.InterfaceProtocol == Transport->Protocol) {
755 Status = Transport->
Init (UsbIo,
NULL);
763 &gEfiUsbIoProtocolGuid,
764 This->DriverBindingHandle,
805 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
813 if (EFI_ERROR (Status)) {
814 DEBUG ((DEBUG_ERROR,
"USBMassDriverBindingStart: UsbMassInitTransport (%r)\n", Status));
823 if (EFI_ERROR (Status)) {
824 DEBUG ((DEBUG_ERROR,
"USBMassDriverBindingStart: UsbMassInitNonLun (%r)\n", Status));
830 Status =
gBS->OpenProtocol (
832 &gEfiDevicePathProtocolGuid,
833 (VOID **)&DevicePath,
834 This->DriverBindingHandle,
836 EFI_OPEN_PROTOCOL_BY_DRIVER
839 if (EFI_ERROR (Status)) {
840 DEBUG ((DEBUG_ERROR,
"USBMassDriverBindingStart: OpenDevicePathProtocol By Driver (%r)\n", Status));
844 Status =
gBS->OpenProtocol (
846 &gEfiUsbIoProtocolGuid,
848 This->DriverBindingHandle,
850 EFI_OPEN_PROTOCOL_BY_DRIVER
853 if (EFI_ERROR (Status)) {
854 DEBUG ((DEBUG_ERROR,
"USBMassDriverBindingStart: OpenUsbIoProtocol By Driver (%r)\n", Status));
857 &gEfiDevicePathProtocolGuid,
858 This->DriverBindingHandle,
869 if (EFI_ERROR (Status)) {
872 &gEfiDevicePathProtocolGuid,
873 This->DriverBindingHandle,
878 &gEfiUsbIoProtocolGuid,
879 This->DriverBindingHandle,
882 DEBUG ((DEBUG_ERROR,
"USBMassDriverBindingStart: UsbMassInitMultiLun (%r) with Maxlun=%d\n", Status, MaxLun));
887 gBS->RestoreTPL (OldTpl);
919 BOOLEAN AllChildrenStopped;
928 if (NumberOfChildren == 0) {
932 Status =
gBS->OpenProtocol (
934 &gEfiBlockIoProtocolGuid,
936 This->DriverBindingHandle,
938 EFI_OPEN_PROTOCOL_GET_PROTOCOL
941 if (EFI_ERROR (Status)) {
948 &gEfiDevicePathProtocolGuid,
949 This->DriverBindingHandle,
954 &gEfiUsbIoProtocolGuid,
955 This->DriverBindingHandle,
958 DEBUG ((DEBUG_INFO,
"Success to stop multi-lun root handle\n"));
966 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlockIo);
972 Status =
gBS->UninstallMultipleProtocolInterfaces (
974 &gEfiBlockIoProtocolGuid,
976 &gEfiDiskInfoProtocolGuid,
980 if (EFI_ERROR (Status)) {
986 &gEfiUsbIoProtocolGuid,
987 This->DriverBindingHandle,
994 DEBUG ((DEBUG_INFO,
"Success to stop non-multi-lun root handle\n"));
1003 AllChildrenStopped =
TRUE;
1005 for (Index = 0; Index < NumberOfChildren; Index++) {
1006 Status =
gBS->OpenProtocol (
1007 ChildHandleBuffer[Index],
1008 &gEfiBlockIoProtocolGuid,
1010 This->DriverBindingHandle,
1012 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1014 if (EFI_ERROR (Status)) {
1015 AllChildrenStopped =
FALSE;
1016 DEBUG ((DEBUG_ERROR,
"Fail to stop No.%d multi-lun child handle when opening blockio\n", (UINT32)Index));
1020 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlockIo);
1022 gBS->CloseProtocol (
1024 &gEfiUsbIoProtocolGuid,
1025 This->DriverBindingHandle,
1026 ChildHandleBuffer[Index]
1029 Status =
gBS->UninstallMultipleProtocolInterfaces (
1030 ChildHandleBuffer[Index],
1031 &gEfiDevicePathProtocolGuid,
1032 UsbMass->DevicePath,
1033 &gEfiBlockIoProtocolGuid,
1035 &gEfiDiskInfoProtocolGuid,
1040 if (EFI_ERROR (Status)) {
1044 AllChildrenStopped =
FALSE;
1045 DEBUG ((DEBUG_ERROR,
"Fail to stop No.%d multi-lun child handle when uninstalling blockio and devicepath\n", (UINT32)Index));
1049 &gEfiUsbIoProtocolGuid,
1051 This->DriverBindingHandle,
1052 ChildHandleBuffer[Index],
1053 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1059 if (((Index + 1) == NumberOfChildren) && AllChildrenStopped) {
1067 if (!AllChildrenStopped) {
1068 return EFI_DEVICE_ERROR;
1071 DEBUG ((DEBUG_INFO,
"Success to stop all %d multi-lun children handles\n", (UINT32)NumberOfChildren));
1102 &gUSBMassDriverBinding,
1104 &gUsbMassStorageComponentName,
1105 &gUsbMassStorageComponentName2
#define MSG_DEVICE_LOGICAL_UNIT_DP
#define MESSAGING_DEVICE_PATH
UINT16 EFIAPI SetDevicePathNodeLength(IN OUT VOID *Node, IN UINTN Length)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
VOID InitializeDiskInfo(IN NVME_DEVICE_PRIVATE_DATA *Device)
VOID EFIAPI Exit(IN EFI_STATUS Status)
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)
#define USB_MASS_STORE_BOT
Bulk-Only Transport.
EFI_STATUS UsbBootGetParams(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootReadWriteBlocks(IN USB_MASS_DEVICE *UsbMass, IN BOOLEAN Write, IN UINT32 Lba, IN UINTN TotalBlock, IN OUT UINT8 *Buffer)
EFI_STATUS UsbBootReadWriteBlocks16(IN USB_MASS_DEVICE *UsbMass, IN BOOLEAN Write, IN UINT64 Lba, IN UINTN TotalBlock, IN OUT UINT8 *Buffer)
EFI_STATUS UsbBootDetectMedia(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbMassInitMedia(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS EFIAPI UsbMassReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS EFIAPI USBMassDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI USBMassStorageEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS UsbMassInitTransport(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, OUT USB_MASS_TRANSPORT **Transport, OUT VOID **Context, OUT UINT8 *MaxLun)
EFI_STATUS EFIAPI UsbMassReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI USBMassDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS UsbMassInitMultiLun(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN USB_MASS_TRANSPORT *Transport, IN VOID *Context, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINT8 MaxLun)
EFI_STATUS EFIAPI UsbMassFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
EFI_STATUS UsbMassInitNonLun(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN USB_MASS_TRANSPORT *Transport, IN VOID *Context)
EFI_STATUS EFIAPI UsbMassWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI USBMassDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
EFI_BLOCK_IO_MEDIA * Media
UINT8 Lun
Logical Unit Number.
USB_MASS_TRANSPORT * Transport
USB mass storage transport protocol.
USB_MASS_INIT_TRANSPORT Init
Initialize the mass storage transport protocol.
USB_MASS_RESET Reset
Reset the device.
USB_MASS_CLEAN_UP CleanUp
Clean up the resources.