MdeModulePkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the MdeModulePkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:02 -08:00
committed by mergify[bot]
parent 7c7184e201
commit 1436aea4d5
994 changed files with 107608 additions and 101311 deletions

View File

@@ -20,17 +20,16 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbMassStorageCompon
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbMassStorageComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) UsbMassStorageGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) UsbMassStorageGetControllerName,
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbMassStorageComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)UsbMassStorageGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)UsbMassStorageGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
mUsbMassStorageDriverNameTable[] = {
{"eng;en", L"Usb Mass Storage Driver"},
{NULL, NULL}
mUsbMassStorageDriverNameTable[] = {
{ "eng;en", L"Usb Mass Storage Driver" },
{ NULL, NULL }
};
/**
@@ -145,11 +144,11 @@ UsbMassStorageGetDriverName (
EFI_STATUS
EFIAPI
UsbMassStorageGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
return EFI_UNSUPPORTED;

View File

@@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_USBMASS_H_
#define _EFI_USBMASS_H_
#include <Uefi.h>
#include <IndustryStandard/Scsi.h>
#include <Protocol/BlockIo.h>
@@ -26,8 +25,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Library/DevicePathLib.h>
typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT;
typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;
typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT;
typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;
#include "UsbMassBot.h"
#include "UsbMassCbi.h"
@@ -44,9 +43,9 @@ typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;
#define USB_MASS_1_MILLISECOND 1000
#define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)
#define USB_MASS_CMD_SUCCESS 0
#define USB_MASS_CMD_FAIL 1
#define USB_MASS_CMD_PERSISTENT 2
#define USB_MASS_CMD_SUCCESS 0
#define USB_MASS_CMD_FAIL 1
#define USB_MASS_CMD_PERSISTENT 2
/**
Initializes USB transport protocol.
@@ -65,8 +64,8 @@ typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;
typedef
EFI_STATUS
(*USB_MASS_INIT_TRANSPORT) (
IN EFI_USB_IO_PROTOCOL *Usb,
OUT VOID **Context OPTIONAL
IN EFI_USB_IO_PROTOCOL *Usb,
OUT VOID **Context OPTIONAL
);
/**
@@ -114,8 +113,8 @@ EFI_STATUS
typedef
EFI_STATUS
(*USB_MASS_RESET) (
IN VOID *Context,
IN BOOLEAN ExtendedVerification
IN VOID *Context,
IN BOOLEAN ExtendedVerification
);
/**
@@ -132,8 +131,8 @@ EFI_STATUS
typedef
EFI_STATUS
(*USB_MASS_GET_MAX_LUN) (
IN VOID *Context,
IN UINT8 *MaxLun
IN VOID *Context,
IN UINT8 *MaxLun
);
/**
@@ -147,7 +146,7 @@ EFI_STATUS
typedef
EFI_STATUS
(*USB_MASS_CLEAN_UP) (
IN VOID *Context
IN VOID *Context
);
///
@@ -159,29 +158,29 @@ EFI_STATUS
/// it is no longer necessary.
///
struct _USB_MASS_TRANSPORT {
UINT8 Protocol;
USB_MASS_INIT_TRANSPORT Init; ///< Initialize the mass storage transport protocol
USB_MASS_EXEC_COMMAND ExecCommand; ///< Transport command to the device then get result
USB_MASS_RESET Reset; ///< Reset the device
USB_MASS_GET_MAX_LUN GetMaxLun; ///< Get max lun, only for bot
USB_MASS_CLEAN_UP CleanUp; ///< Clean up the resources.
UINT8 Protocol;
USB_MASS_INIT_TRANSPORT Init; ///< Initialize the mass storage transport protocol
USB_MASS_EXEC_COMMAND ExecCommand; ///< Transport command to the device then get result
USB_MASS_RESET Reset; ///< Reset the device
USB_MASS_GET_MAX_LUN GetMaxLun; ///< Get max lun, only for bot
USB_MASS_CLEAN_UP CleanUp; ///< Clean up the resources.
};
struct _USB_MASS_DEVICE {
UINT32 Signature;
EFI_HANDLE Controller;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_BLOCK_IO_PROTOCOL BlockIo;
EFI_BLOCK_IO_MEDIA BlockIoMedia;
BOOLEAN OpticalStorage;
UINT8 Lun; ///< Logical Unit Number
UINT8 Pdt; ///< Peripheral Device Type
USB_MASS_TRANSPORT *Transport; ///< USB mass storage transport protocol
VOID *Context;
EFI_DISK_INFO_PROTOCOL DiskInfo;
USB_BOOT_INQUIRY_DATA InquiryData;
BOOLEAN Cdb16Byte;
UINT32 Signature;
EFI_HANDLE Controller;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_BLOCK_IO_PROTOCOL BlockIo;
EFI_BLOCK_IO_MEDIA BlockIoMedia;
BOOLEAN OpticalStorage;
UINT8 Lun; ///< Logical Unit Number
UINT8 Pdt; ///< Peripheral Device Type
USB_MASS_TRANSPORT *Transport; ///< USB mass storage transport protocol
VOID *Context;
EFI_DISK_INFO_PROTOCOL DiskInfo;
USB_BOOT_INQUIRY_DATA InquiryData;
BOOLEAN Cdb16Byte;
};
#endif

View File

@@ -24,15 +24,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
UsbBootRequestSense (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
USB_BOOT_REQUEST_SENSE_CMD SenseCmd;
USB_BOOT_REQUEST_SENSE_DATA SenseData;
EFI_BLOCK_IO_MEDIA *Media;
USB_MASS_TRANSPORT *Transport;
EFI_STATUS Status;
UINT32 CmdResult;
USB_BOOT_REQUEST_SENSE_CMD SenseCmd;
USB_BOOT_REQUEST_SENSE_DATA SenseData;
EFI_BLOCK_IO_MEDIA *Media;
USB_MASS_TRANSPORT *Transport;
EFI_STATUS Status;
UINT32 CmdResult;
Transport = UsbMass->Transport;
@@ -43,8 +43,8 @@ UsbBootRequestSense (
ZeroMem (&SenseData, sizeof (USB_BOOT_REQUEST_SENSE_DATA));
SenseCmd.OpCode = USB_BOOT_REQUEST_SENSE_OPCODE;
SenseCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));
SenseCmd.AllocLen = (UINT8) sizeof (USB_BOOT_REQUEST_SENSE_DATA);
SenseCmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
SenseCmd.AllocLen = (UINT8)sizeof (USB_BOOT_REQUEST_SENSE_DATA);
Status = Transport->ExecCommand (
UsbMass->Context,
@@ -57,11 +57,12 @@ UsbBootRequestSense (
USB_BOOT_GENERAL_CMD_TIMEOUT,
&CmdResult
);
if (EFI_ERROR (Status) || CmdResult != USB_MASS_CMD_SUCCESS) {
if (EFI_ERROR (Status) || (CmdResult != USB_MASS_CMD_SUCCESS)) {
DEBUG ((DEBUG_ERROR, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult));
if (!EFI_ERROR (Status)) {
Status = EFI_DEVICE_ERROR;
}
return Status;
}
@@ -72,77 +73,80 @@ UsbBootRequestSense (
Media = &UsbMass->BlockIoMedia;
switch (USB_BOOT_SENSE_KEY (SenseData.SenseKey)) {
case USB_BOOT_SENSE_NO_SENSE:
if (SenseData.Asc == USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION) {
//
// It is not an error if a device does not have additional sense information
//
Status = EFI_SUCCESS;
} else {
Status = EFI_NO_RESPONSE;
}
case USB_BOOT_SENSE_NO_SENSE:
if (SenseData.Asc == USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION) {
break;
case USB_BOOT_SENSE_RECOVERED:
//
// It is not an error if a device does not have additional sense information
// Suppose hardware can handle this case, and recover later by itself
//
Status = EFI_SUCCESS;
} else {
Status = EFI_NO_RESPONSE;
}
break;
case USB_BOOT_SENSE_RECOVERED:
//
// Suppose hardware can handle this case, and recover later by itself
//
Status = EFI_NOT_READY;
break;
case USB_BOOT_SENSE_NOT_READY:
Status = EFI_DEVICE_ERROR;
if (SenseData.Asc == USB_BOOT_ASC_NO_MEDIA) {
Media->MediaPresent = FALSE;
Status = EFI_NO_MEDIA;
} else if (SenseData.Asc == USB_BOOT_ASC_NOT_READY) {
Status = EFI_NOT_READY;
}
break;
break;
case USB_BOOT_SENSE_ILLEGAL_REQUEST:
Status = EFI_INVALID_PARAMETER;
break;
case USB_BOOT_SENSE_NOT_READY:
Status = EFI_DEVICE_ERROR;
if (SenseData.Asc == USB_BOOT_ASC_NO_MEDIA) {
Media->MediaPresent = FALSE;
Status = EFI_NO_MEDIA;
} else if (SenseData.Asc == USB_BOOT_ASC_NOT_READY) {
Status = EFI_NOT_READY;
}
case USB_BOOT_SENSE_UNIT_ATTENTION:
Status = EFI_DEVICE_ERROR;
if (SenseData.Asc == USB_BOOT_ASC_MEDIA_CHANGE) {
//
// If MediaChange, reset ReadOnly and new MediaId
//
Status = EFI_MEDIA_CHANGED;
Media->ReadOnly = FALSE;
Media->MediaId++;
} else if (SenseData.Asc == USB_BOOT_ASC_NOT_READY) {
Status = EFI_NOT_READY;
} else if (SenseData.Asc == USB_BOOT_ASC_NO_MEDIA) {
Status = EFI_NOT_READY;
}
break;
break;
case USB_BOOT_SENSE_DATA_PROTECT:
Status = EFI_WRITE_PROTECTED;
Media->ReadOnly = TRUE;
break;
case USB_BOOT_SENSE_ILLEGAL_REQUEST:
Status = EFI_INVALID_PARAMETER;
break;
default:
Status = EFI_DEVICE_ERROR;
break;
case USB_BOOT_SENSE_UNIT_ATTENTION:
Status = EFI_DEVICE_ERROR;
if (SenseData.Asc == USB_BOOT_ASC_MEDIA_CHANGE) {
//
// If MediaChange, reset ReadOnly and new MediaId
//
Status = EFI_MEDIA_CHANGED;
Media->ReadOnly = FALSE;
Media->MediaId++;
} else if (SenseData.Asc == USB_BOOT_ASC_NOT_READY) {
Status = EFI_NOT_READY;
} else if (SenseData.Asc == USB_BOOT_ASC_NO_MEDIA) {
Status = EFI_NOT_READY;
}
break;
case USB_BOOT_SENSE_DATA_PROTECT:
Status = EFI_WRITE_PROTECTED;
Media->ReadOnly = TRUE;
break;
default:
Status = EFI_DEVICE_ERROR;
break;
}
DEBUG ((DEBUG_INFO, "UsbBootRequestSense: (%r) with error code (%x) sense key %x/%x/%x\n",
Status,
SenseData.ErrorCode,
USB_BOOT_SENSE_KEY (SenseData.SenseKey),
SenseData.Asc,
SenseData.Ascq
));
DEBUG ((
DEBUG_INFO,
"UsbBootRequestSense: (%r) with error code (%x) sense key %x/%x/%x\n",
Status,
SenseData.ErrorCode,
USB_BOOT_SENSE_KEY (SenseData.SenseKey),
SenseData.Asc,
SenseData.Ascq
));
return Status;
}
/**
Execute the USB mass storage bootability commands.
@@ -164,18 +168,18 @@ UsbBootRequestSense (
**/
EFI_STATUS
UsbBootExecCmd (
IN USB_MASS_DEVICE *UsbMass,
IN VOID *Cmd,
IN UINT8 CmdLen,
IN EFI_USB_DATA_DIRECTION DataDir,
IN VOID *Data,
IN UINT32 DataLen,
IN UINT32 Timeout
IN USB_MASS_DEVICE *UsbMass,
IN VOID *Cmd,
IN UINT8 CmdLen,
IN EFI_USB_DATA_DIRECTION DataDir,
IN VOID *Data,
IN UINT32 DataLen,
IN UINT32 Timeout
)
{
USB_MASS_TRANSPORT *Transport;
EFI_STATUS Status;
UINT32 CmdResult;
USB_MASS_TRANSPORT *Transport;
EFI_STATUS Status;
UINT32 CmdResult;
Transport = UsbMass->Transport;
Status = Transport->ExecCommand (
@@ -210,7 +214,6 @@ UsbBootExecCmd (
return UsbBootRequestSense (UsbMass);
}
/**
Execute the USB mass storage bootability commands with retrial.
@@ -234,18 +237,18 @@ UsbBootExecCmd (
**/
EFI_STATUS
UsbBootExecCmdWithRetry (
IN USB_MASS_DEVICE *UsbMass,
IN VOID *Cmd,
IN UINT8 CmdLen,
IN EFI_USB_DATA_DIRECTION DataDir,
IN VOID *Data,
IN UINT32 DataLen,
IN UINT32 Timeout
IN USB_MASS_DEVICE *UsbMass,
IN VOID *Cmd,
IN UINT8 CmdLen,
IN EFI_USB_DATA_DIRECTION DataDir,
IN VOID *Data,
IN UINT32 DataLen,
IN UINT32 Timeout
)
{
EFI_STATUS Status;
UINTN Retry;
EFI_EVENT TimeoutEvt;
EFI_STATUS Status;
UINTN Retry;
EFI_EVENT TimeoutEvt;
Retry = 0;
Status = EFI_SUCCESS;
@@ -260,7 +263,7 @@ UsbBootExecCmdWithRetry (
return Status;
}
Status = gBS->SetTimer (TimeoutEvt, TimerRelative, EFI_TIMER_PERIOD_SECONDS(60));
Status = gBS->SetTimer (TimeoutEvt, TimerRelative, EFI_TIMER_PERIOD_SECONDS (60));
if (EFI_ERROR (Status)) {
goto EXIT;
}
@@ -278,9 +281,10 @@ UsbBootExecCmdWithRetry (
DataLen,
Timeout
);
if (Status == EFI_SUCCESS || Status == EFI_NO_MEDIA) {
if ((Status == EFI_SUCCESS) || (Status == EFI_NO_MEDIA)) {
break;
}
//
// If the sense data shows the drive is not ready, we need execute the cmd again.
// We limit the upper boundary to 60 seconds.
@@ -288,6 +292,7 @@ UsbBootExecCmdWithRetry (
if (Status == EFI_NOT_READY) {
continue;
}
//
// If the status is other error, then just retry 5 times.
//
@@ -304,7 +309,6 @@ EXIT:
return Status;
}
/**
Execute TEST UNIT READY command to check if the device is ready.
@@ -316,20 +320,20 @@ EXIT:
**/
EFI_STATUS
UsbBootIsUnitReady (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
USB_BOOT_TEST_UNIT_READY_CMD TestCmd;
ZeroMem (&TestCmd, sizeof (USB_BOOT_TEST_UNIT_READY_CMD));
TestCmd.OpCode = USB_BOOT_TEST_UNIT_READY_OPCODE;
TestCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));
TestCmd.OpCode = USB_BOOT_TEST_UNIT_READY_OPCODE;
TestCmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
return UsbBootExecCmdWithRetry (
UsbMass,
&TestCmd,
(UINT8) sizeof (USB_BOOT_TEST_UNIT_READY_CMD),
(UINT8)sizeof (USB_BOOT_TEST_UNIT_READY_CMD),
EfiUsbNoData,
NULL,
0,
@@ -337,7 +341,6 @@ UsbBootIsUnitReady (
);
}
/**
Execute INQUIRY Command to request information regarding parameters of
the device be sent to the host computer.
@@ -350,12 +353,12 @@ UsbBootIsUnitReady (
**/
EFI_STATUS
UsbBootInquiry (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
USB_BOOT_INQUIRY_CMD InquiryCmd;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
USB_BOOT_INQUIRY_CMD InquiryCmd;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
Media = &(UsbMass->BlockIoMedia);
@@ -363,13 +366,13 @@ UsbBootInquiry (
ZeroMem (&UsbMass->InquiryData, sizeof (USB_BOOT_INQUIRY_DATA));
InquiryCmd.OpCode = USB_BOOT_INQUIRY_OPCODE;
InquiryCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));
InquiryCmd.AllocLen = (UINT8) sizeof (USB_BOOT_INQUIRY_DATA);
InquiryCmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
InquiryCmd.AllocLen = (UINT8)sizeof (USB_BOOT_INQUIRY_DATA);
Status = UsbBootExecCmdWithRetry (
UsbMass,
&InquiryCmd,
(UINT8) sizeof (USB_BOOT_INQUIRY_CMD),
(UINT8)sizeof (USB_BOOT_INQUIRY_CMD),
EfiUsbDataIn,
&UsbMass->InquiryData,
sizeof (USB_BOOT_INQUIRY_DATA),
@@ -383,12 +386,12 @@ UsbBootInquiry (
// Get information from PDT (Peripheral Device Type) field and Removable Medium Bit
// from the inquiry data.
//
UsbMass->Pdt = (UINT8) (USB_BOOT_PDT (UsbMass->InquiryData.Pdt));
Media->RemovableMedia = (BOOLEAN) (USB_BOOT_REMOVABLE (UsbMass->InquiryData.Removable));
UsbMass->Pdt = (UINT8)(USB_BOOT_PDT (UsbMass->InquiryData.Pdt));
Media->RemovableMedia = (BOOLEAN)(USB_BOOT_REMOVABLE (UsbMass->InquiryData.Removable));
//
// Set block size to the default value of 512 Bytes, in case no media is present at first time.
//
Media->BlockSize = 0x0200;
Media->BlockSize = 0x0200;
return Status;
}
@@ -410,16 +413,16 @@ UsbBootInquiry (
**/
EFI_STATUS
UsbBootReadCapacity16 (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
UINT8 CapacityCmd[16];
EFI_SCSI_DISK_CAPACITY_DATA16 CapacityData;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
UINT32 BlockSize;
UINT8 CapacityCmd[16];
EFI_SCSI_DISK_CAPACITY_DATA16 CapacityData;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
UINT32 BlockSize;
Media = &UsbMass->BlockIoMedia;
Media = &UsbMass->BlockIoMedia;
Media->MediaPresent = FALSE;
Media->LastBlock = 0;
@@ -428,8 +431,8 @@ UsbBootReadCapacity16 (
ZeroMem (CapacityCmd, sizeof (CapacityCmd));
ZeroMem (&CapacityData, sizeof (CapacityData));
CapacityCmd[0] = EFI_SCSI_OP_READ_CAPACITY16;
CapacityCmd[1] = 0x10;
CapacityCmd[0] = EFI_SCSI_OP_READ_CAPACITY16;
CapacityCmd[1] = 0x10;
//
// Partial medium indicator, set the bytes 2 ~ 9 of the Cdb as ZERO.
//
@@ -440,7 +443,7 @@ UsbBootReadCapacity16 (
Status = UsbBootExecCmdWithRetry (
UsbMass,
CapacityCmd,
(UINT8) sizeof (CapacityCmd),
(UINT8)sizeof (CapacityCmd),
EfiUsbDataIn,
&CapacityData,
sizeof (CapacityData),
@@ -455,13 +458,13 @@ UsbBootReadCapacity16 (
// from READ CAPACITY data.
//
Media->MediaPresent = TRUE;
Media->LastBlock = SwapBytes64 (ReadUnaligned64 ((CONST UINT64 *) &(CapacityData.LastLba7)));
Media->LastBlock = SwapBytes64 (ReadUnaligned64 ((CONST UINT64 *)&(CapacityData.LastLba7)));
BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) &(CapacityData.BlockSize3)));
BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *)&(CapacityData.BlockSize3)));
Media->LowestAlignedLba = (CapacityData.LowestAlignLogic2 << 8) |
CapacityData.LowestAlignLogic1;
Media->LogicalBlocksPerPhysicalBlock = (1 << CapacityData.LogicPerPhysical);
CapacityData.LowestAlignLogic1;
Media->LogicalBlocksPerPhysicalBlock = (1 << CapacityData.LogicPerPhysical);
if (BlockSize == 0) {
//
// Get sense data
@@ -474,7 +477,6 @@ UsbBootReadCapacity16 (
return Status;
}
/**
Execute READ CAPACITY command to request information regarding
the capacity of the installed medium of the device.
@@ -492,27 +494,27 @@ UsbBootReadCapacity16 (
**/
EFI_STATUS
UsbBootReadCapacity (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
USB_BOOT_READ_CAPACITY_CMD CapacityCmd;
USB_BOOT_READ_CAPACITY_DATA CapacityData;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
UINT32 BlockSize;
USB_BOOT_READ_CAPACITY_CMD CapacityCmd;
USB_BOOT_READ_CAPACITY_DATA CapacityData;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
UINT32 BlockSize;
Media = &UsbMass->BlockIoMedia;
Media = &UsbMass->BlockIoMedia;
ZeroMem (&CapacityCmd, sizeof (USB_BOOT_READ_CAPACITY_CMD));
ZeroMem (&CapacityData, sizeof (USB_BOOT_READ_CAPACITY_DATA));
CapacityCmd.OpCode = USB_BOOT_READ_CAPACITY_OPCODE;
CapacityCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));
CapacityCmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
Status = UsbBootExecCmdWithRetry (
UsbMass,
&CapacityCmd,
(UINT8) sizeof (USB_BOOT_READ_CAPACITY_CMD),
(UINT8)sizeof (USB_BOOT_READ_CAPACITY_CMD),
EfiUsbDataIn,
&CapacityData,
sizeof (USB_BOOT_READ_CAPACITY_DATA),
@@ -527,9 +529,9 @@ UsbBootReadCapacity (
// from READ CAPACITY data.
//
Media->MediaPresent = TRUE;
Media->LastBlock = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.LastLba));
Media->LastBlock = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *)CapacityData.LastLba));
BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.BlockLen));
BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *)CapacityData.BlockLen));
if (BlockSize == 0) {
//
// Get sense data
@@ -560,15 +562,15 @@ UsbBootReadCapacity (
**/
EFI_STATUS
UsbScsiModeSense (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
EFI_STATUS Status;
USB_SCSI_MODE_SENSE6_CMD ModeSenseCmd;
USB_SCSI_MODE_SENSE6_PARA_HEADER ModeParaHeader;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
USB_SCSI_MODE_SENSE6_CMD ModeSenseCmd;
USB_SCSI_MODE_SENSE6_PARA_HEADER ModeParaHeader;
EFI_BLOCK_IO_MEDIA *Media;
Media = &UsbMass->BlockIoMedia;
Media = &UsbMass->BlockIoMedia;
ZeroMem (&ModeSenseCmd, sizeof (USB_SCSI_MODE_SENSE6_CMD));
ZeroMem (&ModeParaHeader, sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER));
@@ -576,15 +578,15 @@ UsbScsiModeSense (
//
// MODE SENSE(6) command is defined in Section 8.2.10 of SCSI-2 Spec
//
ModeSenseCmd.OpCode = USB_SCSI_MODE_SENSE6_OPCODE;
ModeSenseCmd.Lun = (UINT8) USB_BOOT_LUN (UsbMass->Lun);
ModeSenseCmd.PageCode = 0x3F;
ModeSenseCmd.AllocateLen = (UINT8) sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER);
ModeSenseCmd.OpCode = USB_SCSI_MODE_SENSE6_OPCODE;
ModeSenseCmd.Lun = (UINT8)USB_BOOT_LUN (UsbMass->Lun);
ModeSenseCmd.PageCode = 0x3F;
ModeSenseCmd.AllocateLen = (UINT8)sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER);
Status = UsbBootExecCmdWithRetry (
UsbMass,
&ModeSenseCmd,
(UINT8) sizeof (USB_SCSI_MODE_SENSE6_CMD),
(UINT8)sizeof (USB_SCSI_MODE_SENSE6_CMD),
EfiUsbDataIn,
&ModeParaHeader,
sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER),
@@ -597,13 +599,12 @@ UsbScsiModeSense (
// BIT7 of this byte is indicates whether the medium is write protected.
//
if (!EFI_ERROR (Status)) {
Media->ReadOnly = (BOOLEAN) ((ModeParaHeader.DevicePara & BIT7) != 0);
Media->ReadOnly = (BOOLEAN)((ModeParaHeader.DevicePara & BIT7) != 0);
}
return Status;
}
/**
Get the parameters for the USB mass storage media.
@@ -621,13 +622,13 @@ UsbScsiModeSense (
**/
EFI_STATUS
UsbBootGetParams (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
Media = &(UsbMass->BlockIoMedia);
Media = &(UsbMass->BlockIoMedia);
Status = UsbBootInquiry (UsbMass);
if (EFI_ERROR (Status)) {
@@ -640,9 +641,10 @@ UsbBootGetParams (
// 4 Peripheral Device Types are in spec.
//
if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) &&
(UsbMass->Pdt != USB_PDT_CDROM) &&
(UsbMass->Pdt != USB_PDT_OPTICAL) &&
(UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {
(UsbMass->Pdt != USB_PDT_CDROM) &&
(UsbMass->Pdt != USB_PDT_OPTICAL) &&
(UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT))
{
DEBUG ((DEBUG_ERROR, "UsbBootGetParams: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));
return EFI_UNSUPPORTED;
}
@@ -659,7 +661,7 @@ UsbBootGetParams (
//
// Default value 2048 Bytes, in case no media present at first time
//
Media->BlockSize = 0x0800;
Media->BlockSize = 0x0800;
}
Status = UsbBootDetectMedia (UsbMass);
@@ -667,7 +669,6 @@ UsbBootGetParams (
return Status;
}
/**
Detect whether the removable media is present and whether it has changed.
@@ -679,19 +680,19 @@ UsbBootGetParams (
**/
EFI_STATUS
UsbBootDetectMedia (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
EFI_BLOCK_IO_MEDIA OldMedia;
EFI_BLOCK_IO_MEDIA *Media;
UINT8 CmdSet;
EFI_STATUS Status;
EFI_BLOCK_IO_MEDIA OldMedia;
EFI_BLOCK_IO_MEDIA *Media;
UINT8 CmdSet;
EFI_STATUS Status;
Media = &UsbMass->BlockIoMedia;
Media = &UsbMass->BlockIoMedia;
CopyMem (&OldMedia, &(UsbMass->BlockIoMedia), sizeof (EFI_BLOCK_IO_MEDIA));
CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;
CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *)(UsbMass->Context))->InterfaceSubClass;
Status = UsbBootIsUnitReady (UsbMass);
if (EFI_ERROR (Status)) {
@@ -723,7 +724,7 @@ UsbBootDetectMedia (
}
}
if (EFI_ERROR (Status) && Status != EFI_NO_MEDIA) {
if (EFI_ERROR (Status) && (Status != EFI_NO_MEDIA)) {
//
// For NoMedia, BlockIo is still needed.
//
@@ -749,8 +750,8 @@ UsbBootDetectMedia (
(Media->MediaPresent != OldMedia.MediaPresent) ||
(Media->ReadOnly != OldMedia.ReadOnly) ||
(Media->BlockSize != OldMedia.BlockSize) ||
(Media->LastBlock != OldMedia.LastBlock)) {
(Media->LastBlock != OldMedia.LastBlock))
{
//
// This function is called from:
// Block I/O Protocol APIs, which run at TPL_CALLBACK.
@@ -781,7 +782,8 @@ UsbBootDetectMedia (
if ((Media->ReadOnly != OldMedia.ReadOnly) ||
(Media->BlockSize != OldMedia.BlockSize) ||
(Media->LastBlock != OldMedia.LastBlock)) {
(Media->LastBlock != OldMedia.LastBlock))
{
Media->MediaId++;
}
@@ -791,7 +793,6 @@ UsbBootDetectMedia (
return Status;
}
/**
Read or write some blocks from the device.
@@ -807,20 +808,20 @@ UsbBootDetectMedia (
**/
EFI_STATUS
UsbBootReadWriteBlocks (
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT32 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT32 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
)
{
USB_BOOT_READ_WRITE_10_CMD Cmd;
EFI_STATUS Status;
UINT32 Count;
UINT32 CountMax;
UINT32 BlockSize;
UINT32 ByteSize;
UINT32 Timeout;
USB_BOOT_READ_WRITE_10_CMD Cmd;
EFI_STATUS Status;
UINT32 Count;
UINT32 CountMax;
UINT32 BlockSize;
UINT32 ByteSize;
UINT32 Timeout;
BlockSize = UsbMass->BlockIoMedia.BlockSize;
CountMax = USB_BOOT_MAX_CARRY_SIZE / BlockSize;
@@ -839,22 +840,22 @@ UsbBootReadWriteBlocks (
//
// USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]
//
Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;
Timeout = (UINT32)USB_BOOT_GENERAL_CMD_TIMEOUT;
//
// Fill in the command then execute
//
ZeroMem (&Cmd, sizeof (USB_BOOT_READ_WRITE_10_CMD));
Cmd.OpCode = Write ? USB_BOOT_WRITE10_OPCODE : USB_BOOT_READ10_OPCODE;
Cmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));
WriteUnaligned32 ((UINT32 *) Cmd.Lba, SwapBytes32 (Lba));
WriteUnaligned16 ((UINT16 *) Cmd.TransferLen, SwapBytes16 ((UINT16)Count));
Cmd.OpCode = Write ? USB_BOOT_WRITE10_OPCODE : USB_BOOT_READ10_OPCODE;
Cmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
WriteUnaligned32 ((UINT32 *)Cmd.Lba, SwapBytes32 (Lba));
WriteUnaligned16 ((UINT16 *)Cmd.TransferLen, SwapBytes16 ((UINT16)Count));
Status = UsbBootExecCmdWithRetry (
UsbMass,
&Cmd,
(UINT8) sizeof (USB_BOOT_READ_WRITE_10_CMD),
(UINT8)sizeof (USB_BOOT_READ_WRITE_10_CMD),
Write ? EfiUsbDataOut : EfiUsbDataIn,
Buffer,
ByteSize,
@@ -863,10 +864,13 @@ UsbBootReadWriteBlocks (
if (EFI_ERROR (Status)) {
return Status;
}
DEBUG ((
DEBUG_BLKIO, "UsbBoot%sBlocks: LBA (0x%lx), Blk (0x%x)\n",
DEBUG_BLKIO,
"UsbBoot%sBlocks: LBA (0x%lx), Blk (0x%x)\n",
Write ? L"Write" : L"Read",
Lba, Count
Lba,
Count
));
Lba += Count;
Buffer += ByteSize;
@@ -890,20 +894,20 @@ UsbBootReadWriteBlocks (
**/
EFI_STATUS
UsbBootReadWriteBlocks16 (
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT64 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT64 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
)
{
UINT8 Cmd[16];
EFI_STATUS Status;
UINT32 Count;
UINT32 CountMax;
UINT32 BlockSize;
UINT32 ByteSize;
UINT32 Timeout;
UINT8 Cmd[16];
EFI_STATUS Status;
UINT32 Count;
UINT32 CountMax;
UINT32 BlockSize;
UINT32 ByteSize;
UINT32 Timeout;
BlockSize = UsbMass->BlockIoMedia.BlockSize;
CountMax = USB_BOOT_MAX_CARRY_SIZE / BlockSize;
@@ -919,22 +923,22 @@ UsbBootReadWriteBlocks16 (
//
// USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]
//
Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;
Timeout = (UINT32)USB_BOOT_GENERAL_CMD_TIMEOUT;
//
// Fill in the command then execute
//
ZeroMem (Cmd, sizeof (Cmd));
Cmd[0] = Write ? EFI_SCSI_OP_WRITE16 : EFI_SCSI_OP_READ16;
Cmd[1] = (UINT8) ((USB_BOOT_LUN (UsbMass->Lun) & 0xE0));
WriteUnaligned64 ((UINT64 *) &Cmd[2], SwapBytes64 (Lba));
WriteUnaligned32 ((UINT32 *) &Cmd[10], SwapBytes32 (Count));
Cmd[0] = Write ? EFI_SCSI_OP_WRITE16 : EFI_SCSI_OP_READ16;
Cmd[1] = (UINT8)((USB_BOOT_LUN (UsbMass->Lun) & 0xE0));
WriteUnaligned64 ((UINT64 *)&Cmd[2], SwapBytes64 (Lba));
WriteUnaligned32 ((UINT32 *)&Cmd[10], SwapBytes32 (Count));
Status = UsbBootExecCmdWithRetry (
UsbMass,
Cmd,
(UINT8) sizeof (Cmd),
(UINT8)sizeof (Cmd),
Write ? EfiUsbDataOut : EfiUsbDataIn,
Buffer,
ByteSize,
@@ -943,10 +947,13 @@ UsbBootReadWriteBlocks16 (
if (EFI_ERROR (Status)) {
return Status;
}
DEBUG ((
DEBUG_BLKIO, "UsbBoot%sBlocks16: LBA (0x%lx), Blk (0x%x)\n",
DEBUG_BLKIO,
"UsbBoot%sBlocks16: LBA (0x%lx), Blk (0x%x)\n",
Write ? L"Write" : L"Read",
Lba, Count
Lba,
Count
));
Lba += Count;
Buffer += ByteSize;
@@ -968,14 +975,14 @@ UsbBootReadWriteBlocks16 (
**/
EFI_STATUS
UsbClearEndpointStall (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr
)
{
EFI_USB_DEVICE_REQUEST Request;
EFI_STATUS Status;
UINT32 CmdResult;
UINT32 Timeout;
EFI_USB_DEVICE_REQUEST Request;
EFI_STATUS Status;
UINT32 CmdResult;
UINT32 Timeout;
Request.RequestType = 0x02;
Request.Request = USB_REQ_CLEAR_FEATURE;

View File

@@ -17,15 +17,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Others are "Group 1 Timeout Commands". That is,
// they should be retried if driver is ready.
//
#define USB_BOOT_INQUIRY_OPCODE 0x12
#define USB_BOOT_REQUEST_SENSE_OPCODE 0x03
#define USB_BOOT_MODE_SENSE10_OPCODE 0x5A
#define USB_BOOT_READ_CAPACITY_OPCODE 0x25
#define USB_BOOT_TEST_UNIT_READY_OPCODE 0x00
#define USB_BOOT_READ10_OPCODE 0x28
#define USB_BOOT_WRITE10_OPCODE 0x2A
#define USB_BOOT_INQUIRY_OPCODE 0x12
#define USB_BOOT_REQUEST_SENSE_OPCODE 0x03
#define USB_BOOT_MODE_SENSE10_OPCODE 0x5A
#define USB_BOOT_READ_CAPACITY_OPCODE 0x25
#define USB_BOOT_TEST_UNIT_READY_OPCODE 0x00
#define USB_BOOT_READ10_OPCODE 0x28
#define USB_BOOT_WRITE10_OPCODE 0x2A
#define USB_SCSI_MODE_SENSE6_OPCODE 0x1A
#define USB_SCSI_MODE_SENSE6_OPCODE 0x1A
//
// The Sense Key part of the sense data. Sense data has three levels:
@@ -53,25 +53,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Supported PDT codes, or Peripheral Device Type
//
#define USB_PDT_DIRECT_ACCESS 0x00 ///< Direct access device
#define USB_PDT_CDROM 0x05 ///< CDROM
#define USB_PDT_OPTICAL 0x07 ///< Non-CD optical disks
#define USB_PDT_SIMPLE_DIRECT 0x0E ///< Simplified direct access device
#define USB_PDT_DIRECT_ACCESS 0x00 ///< Direct access device
#define USB_PDT_CDROM 0x05 ///< CDROM
#define USB_PDT_OPTICAL 0x07 ///< Non-CD optical disks
#define USB_PDT_SIMPLE_DIRECT 0x0E ///< Simplified direct access device
//
// Other parameters, Max carried size is 64KB.
//
#define USB_BOOT_MAX_CARRY_SIZE SIZE_64KB
#define USB_BOOT_MAX_CARRY_SIZE SIZE_64KB
//
// Retry mass command times, set by experience
//
#define USB_BOOT_COMMAND_RETRY 5
#define USB_BOOT_COMMAND_RETRY 5
//
// Wait for unit ready command, set by experience
//
#define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)
#define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)
//
// Mass command timeout, refers to specification[USB20-9.2.6.1]
@@ -80,7 +80,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// USB CD-Rom and iPod devices are much slower than USB key when response
// most of commands, So we set 5s as timeout here.
//
#define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)
#define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)
//
// The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,
@@ -90,122 +90,122 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
#pragma pack(1)
typedef struct {
UINT8 OpCode;
UINT8 Lun; ///< Lun (high 3 bits)
UINT8 Reserved0[2];
UINT8 AllocLen;
UINT8 Reserved1;
UINT8 Pad[6];
UINT8 OpCode;
UINT8 Lun; ///< Lun (high 3 bits)
UINT8 Reserved0[2];
UINT8 AllocLen;
UINT8 Reserved1;
UINT8 Pad[6];
} USB_BOOT_INQUIRY_CMD;
typedef struct {
UINT8 Pdt; ///< Peripheral Device Type (low 5 bits)
UINT8 Removable; ///< Removable Media (highest bit)
UINT8 Reserved0[2];
UINT8 AddLen; ///< Additional length
UINT8 Reserved1[3];
UINT8 VendorID[8];
UINT8 ProductID[16];
UINT8 ProductRevision[4];
UINT8 Pdt; ///< Peripheral Device Type (low 5 bits)
UINT8 Removable; ///< Removable Media (highest bit)
UINT8 Reserved0[2];
UINT8 AddLen; ///< Additional length
UINT8 Reserved1[3];
UINT8 VendorID[8];
UINT8 ProductID[16];
UINT8 ProductRevision[4];
} USB_BOOT_INQUIRY_DATA;
typedef struct {
UINT8 OpCode;
UINT8 Lun;
UINT8 Reserved0[8];
UINT8 Pad[2];
UINT8 OpCode;
UINT8 Lun;
UINT8 Reserved0[8];
UINT8 Pad[2];
} USB_BOOT_READ_CAPACITY_CMD;
typedef struct {
UINT8 LastLba[4];
UINT8 BlockLen[4];
UINT8 LastLba[4];
UINT8 BlockLen[4];
} USB_BOOT_READ_CAPACITY_DATA;
typedef struct {
UINT8 OpCode;
UINT8 Lun;
UINT8 Reserved[4];
UINT8 Pad[6];
UINT8 OpCode;
UINT8 Lun;
UINT8 Reserved[4];
UINT8 Pad[6];
} USB_BOOT_TEST_UNIT_READY_CMD;
typedef struct {
UINT8 OpCode;
UINT8 Lun;
UINT8 PageCode;
UINT8 Reserved0[4];
UINT8 ParaListLenMsb;
UINT8 ParaListLenLsb;
UINT8 Reserved1;
UINT8 Pad[2];
UINT8 OpCode;
UINT8 Lun;
UINT8 PageCode;
UINT8 Reserved0[4];
UINT8 ParaListLenMsb;
UINT8 ParaListLenLsb;
UINT8 Reserved1;
UINT8 Pad[2];
} USB_BOOT_MODE_SENSE10_CMD;
typedef struct {
UINT8 ModeDataLenMsb;
UINT8 ModeDataLenLsb;
UINT8 Reserved0[4];
UINT8 BlkDesLenMsb;
UINT8 BlkDesLenLsb;
UINT8 ModeDataLenMsb;
UINT8 ModeDataLenLsb;
UINT8 Reserved0[4];
UINT8 BlkDesLenMsb;
UINT8 BlkDesLenLsb;
} USB_BOOT_MODE_SENSE10_PARA_HEADER;
typedef struct {
UINT8 OpCode;
UINT8 Lun; ///< Lun (High 3 bits)
UINT8 Lba[4]; ///< Logical block address
UINT8 Reserved0;
UINT8 TransferLen[2]; ///< Transfer length
UINT8 Reserverd1;
UINT8 Pad[2];
UINT8 OpCode;
UINT8 Lun; ///< Lun (High 3 bits)
UINT8 Lba[4]; ///< Logical block address
UINT8 Reserved0;
UINT8 TransferLen[2]; ///< Transfer length
UINT8 Reserverd1;
UINT8 Pad[2];
} USB_BOOT_READ_WRITE_10_CMD;
typedef struct {
UINT8 OpCode;
UINT8 Lun; ///< Lun (High 3 bits)
UINT8 Reserved0[2];
UINT8 AllocLen; ///< Allocation length
UINT8 Reserved1;
UINT8 Pad[6];
UINT8 OpCode;
UINT8 Lun; ///< Lun (High 3 bits)
UINT8 Reserved0[2];
UINT8 AllocLen; ///< Allocation length
UINT8 Reserved1;
UINT8 Pad[6];
} USB_BOOT_REQUEST_SENSE_CMD;
typedef struct {
UINT8 ErrorCode;
UINT8 Reserved0;
UINT8 SenseKey; ///< Sense key (low 4 bits)
UINT8 Infor[4];
UINT8 AddLen; ///< Additional Sense length, 10
UINT8 Reserved1[4];
UINT8 Asc; ///< Additional Sense Code
UINT8 Ascq; ///< Additional Sense Code Qualifier
UINT8 Reserverd2[4];
UINT8 ErrorCode;
UINT8 Reserved0;
UINT8 SenseKey; ///< Sense key (low 4 bits)
UINT8 Infor[4];
UINT8 AddLen; ///< Additional Sense length, 10
UINT8 Reserved1[4];
UINT8 Asc; ///< Additional Sense Code
UINT8 Ascq; ///< Additional Sense Code Qualifier
UINT8 Reserverd2[4];
} USB_BOOT_REQUEST_SENSE_DATA;
typedef struct {
UINT8 OpCode;
UINT8 Lun;
UINT8 PageCode;
UINT8 Reserved0;
UINT8 AllocateLen;
UINT8 Control;
UINT8 OpCode;
UINT8 Lun;
UINT8 PageCode;
UINT8 Reserved0;
UINT8 AllocateLen;
UINT8 Control;
} USB_SCSI_MODE_SENSE6_CMD;
typedef struct {
UINT8 ModeDataLen;
UINT8 MediumType;
UINT8 DevicePara;
UINT8 BlkDesLen;
UINT8 ModeDataLen;
UINT8 MediumType;
UINT8 DevicePara;
UINT8 BlkDesLen;
} USB_SCSI_MODE_SENSE6_PARA_HEADER;
#pragma pack()
//
// Convert a LUN number to that in the command
//
#define USB_BOOT_LUN(Lun) ((Lun) << 5)
#define USB_BOOT_LUN(Lun) ((Lun) << 5)
//
// Get the removable, PDT, and sense key bits from the command data
//
#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)
#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)
#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)
#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)
#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)
#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)
/**
Get the parameters for the USB mass storage media.
@@ -224,7 +224,7 @@ typedef struct {
**/
EFI_STATUS
UsbBootGetParams (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
);
/**
@@ -238,7 +238,7 @@ UsbBootGetParams (
**/
EFI_STATUS
UsbBootIsUnitReady (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
);
/**
@@ -252,7 +252,7 @@ UsbBootIsUnitReady (
**/
EFI_STATUS
UsbBootDetectMedia (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
);
/**
@@ -269,10 +269,10 @@ UsbBootDetectMedia (
**/
EFI_STATUS
UsbBootReadBlocks (
IN USB_MASS_DEVICE *UsbMass,
IN UINT32 Lba,
IN UINTN TotalBlock,
OUT UINT8 *Buffer
IN USB_MASS_DEVICE *UsbMass,
IN UINT32 Lba,
IN UINTN TotalBlock,
OUT UINT8 *Buffer
);
/**
@@ -290,11 +290,11 @@ UsbBootReadBlocks (
**/
EFI_STATUS
UsbBootReadWriteBlocks (
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT32 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT32 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
);
/**
@@ -311,11 +311,11 @@ UsbBootReadWriteBlocks (
**/
EFI_STATUS
UsbBootReadWriteBlocks16 (
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT64 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
IN USB_MASS_DEVICE *UsbMass,
IN BOOLEAN Write,
IN UINT64 Lba,
IN UINTN TotalBlock,
IN OUT UINT8 *Buffer
);
/**
@@ -330,9 +330,8 @@ UsbBootReadWriteBlocks16 (
**/
EFI_STATUS
UsbClearEndpointStall (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr
);
#endif

View File

@@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Definition of USB BOT Transport Protocol
//
USB_MASS_TRANSPORT mUsbBotTransport = {
USB_MASS_TRANSPORT mUsbBotTransport = {
USB_MASS_STORE_BOT,
UsbBotInit,
UsbBotExecCommand,
@@ -38,8 +38,8 @@ USB_MASS_TRANSPORT mUsbBotTransport = {
**/
EFI_STATUS
UsbBotInit (
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
)
{
USB_BOT_PROTOCOL *UsbBot;
@@ -84,17 +84,17 @@ UsbBotInit (
}
if (USB_IS_IN_ENDPOINT (EndPoint.EndpointAddress) &&
(UsbBot->BulkInEndpoint == NULL)) {
UsbBot->BulkInEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbBot + 1);
CopyMem(UsbBot->BulkInEndpoint, &EndPoint, sizeof (EndPoint));
(UsbBot->BulkInEndpoint == NULL))
{
UsbBot->BulkInEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *)(UsbBot + 1);
CopyMem (UsbBot->BulkInEndpoint, &EndPoint, sizeof (EndPoint));
}
if (USB_IS_OUT_ENDPOINT (EndPoint.EndpointAddress) &&
(UsbBot->BulkOutEndpoint == NULL)) {
UsbBot->BulkOutEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbBot + 1) + 1;
CopyMem (UsbBot->BulkOutEndpoint, &EndPoint, sizeof(EndPoint));
(UsbBot->BulkOutEndpoint == NULL))
{
UsbBot->BulkOutEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *)(UsbBot + 1) + 1;
CopyMem (UsbBot->BulkOutEndpoint, &EndPoint, sizeof (EndPoint));
}
}
@@ -145,19 +145,19 @@ ON_ERROR:
**/
EFI_STATUS
UsbBotSendCommand (
IN USB_BOT_PROTOCOL *UsbBot,
IN UINT8 *Cmd,
IN UINT8 CmdLen,
IN EFI_USB_DATA_DIRECTION DataDir,
IN UINT32 TransLen,
IN UINT8 Lun
IN USB_BOT_PROTOCOL *UsbBot,
IN UINT8 *Cmd,
IN UINT8 CmdLen,
IN EFI_USB_DATA_DIRECTION DataDir,
IN UINT32 TransLen,
IN UINT8 Lun
)
{
USB_BOT_CBW Cbw;
EFI_STATUS Status;
UINT32 Result;
UINTN DataLen;
UINTN Timeout;
USB_BOT_CBW Cbw;
EFI_STATUS Status;
UINT32 Result;
UINTN DataLen;
UINTN Timeout;
ASSERT ((CmdLen > 0) && (CmdLen <= USB_BOT_MAX_CMDLEN));
@@ -167,7 +167,7 @@ UsbBotSendCommand (
Cbw.Signature = USB_BOT_CBW_SIGNATURE;
Cbw.Tag = UsbBot->CbwTag;
Cbw.DataLen = TransLen;
Cbw.Flag = (UINT8) ((DataDir == EfiUsbDataIn) ? BIT7 : 0);
Cbw.Flag = (UINT8)((DataDir == EfiUsbDataIn) ? BIT7 : 0);
Cbw.Lun = Lun;
Cbw.CmdLen = CmdLen;
@@ -190,7 +190,7 @@ UsbBotSendCommand (
&Result
);
if (EFI_ERROR (Status)) {
if (USB_IS_ERROR (Result, EFI_USB_ERR_STALL) && DataDir == EfiUsbDataOut) {
if (USB_IS_ERROR (Result, EFI_USB_ERR_STALL) && (DataDir == EfiUsbDataOut)) {
//
// Respond to Bulk-Out endpoint stall with a Reset Recovery,
// according to section 5.3.1 of USB Mass Storage Class Bulk-Only Transport Spec, v1.0.
@@ -204,7 +204,6 @@ UsbBotSendCommand (
return Status;
}
/**
Transfer the data between the device and host.
@@ -226,16 +225,16 @@ UsbBotSendCommand (
**/
EFI_STATUS
UsbBotDataTransfer (
IN USB_BOT_PROTOCOL *UsbBot,
IN EFI_USB_DATA_DIRECTION DataDir,
IN OUT UINT8 *Data,
IN OUT UINTN *TransLen,
IN UINT32 Timeout
IN USB_BOT_PROTOCOL *UsbBot,
IN EFI_USB_DATA_DIRECTION DataDir,
IN OUT UINT8 *Data,
IN OUT UINTN *TransLen,
IN UINT32 Timeout
)
{
EFI_USB_ENDPOINT_DESCRIPTOR *Endpoint;
EFI_STATUS Status;
UINT32 Result;
EFI_USB_ENDPOINT_DESCRIPTOR *Endpoint;
EFI_STATUS Status;
UINT32 Result;
//
// If no data to transfer, just return EFI_SUCCESS.
@@ -274,15 +273,15 @@ UsbBotDataTransfer (
} else {
DEBUG ((DEBUG_ERROR, "UsbBotDataTransfer: (%r)\n", Status));
}
if(Status == EFI_TIMEOUT){
UsbBotResetDevice(UsbBot, FALSE);
if (Status == EFI_TIMEOUT) {
UsbBotResetDevice (UsbBot, FALSE);
}
}
return Status;
}
/**
Get the command execution status from device.
@@ -304,19 +303,19 @@ UsbBotDataTransfer (
**/
EFI_STATUS
UsbBotGetStatus (
IN USB_BOT_PROTOCOL *UsbBot,
IN UINT32 TransLen,
OUT UINT8 *CmdStatus
IN USB_BOT_PROTOCOL *UsbBot,
IN UINT32 TransLen,
OUT UINT8 *CmdStatus
)
{
USB_BOT_CSW Csw;
UINTN Len;
UINT8 Endpoint;
EFI_STATUS Status;
UINT32 Result;
EFI_USB_IO_PROTOCOL *UsbIo;
UINT32 Index;
UINTN Timeout;
USB_BOT_CSW Csw;
UINTN Len;
UINT8 Endpoint;
EFI_STATUS Status;
UINT32 Result;
EFI_USB_IO_PROTOCOL *UsbIo;
UINT32 Index;
UINTN Timeout;
*CmdStatus = USB_BOT_COMMAND_ERROR;
Status = EFI_DEVICE_ERROR;
@@ -339,10 +338,11 @@ UsbBotGetStatus (
Timeout,
&Result
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
if (USB_IS_ERROR (Result, EFI_USB_ERR_STALL)) {
UsbClearEndpointStall (UsbIo, Endpoint);
}
continue;
}
@@ -361,15 +361,15 @@ UsbBotGetStatus (
break;
}
}
//
//The tag is increased even if there is an error.
// The tag is increased even if there is an error.
//
UsbBot->CbwTag++;
return Status;
}
/**
Call the USB Mass Storage Class BOT protocol to issue
the command/data/status circle to execute the commands.
@@ -402,13 +402,13 @@ UsbBotExecCommand (
OUT UINT32 *CmdStatus
)
{
USB_BOT_PROTOCOL *UsbBot;
EFI_STATUS Status;
UINTN TransLen;
UINT8 Result;
USB_BOT_PROTOCOL *UsbBot;
EFI_STATUS Status;
UINTN TransLen;
UINT8 Result;
*CmdStatus = USB_MASS_CMD_FAIL;
UsbBot = (USB_BOT_PROTOCOL *) Context;
*CmdStatus = USB_MASS_CMD_FAIL;
UsbBot = (USB_BOT_PROTOCOL *)Context;
//
// Send the command to the device. Return immediately if device
@@ -425,7 +425,7 @@ UsbBotExecCommand (
// failed. The host should attempt to receive the CSW no matter
// whether it succeeds or fails.
//
TransLen = (UINTN) DataLen;
TransLen = (UINTN)DataLen;
UsbBotDataTransfer (UsbBot, DataDir, Data, &TransLen, Timeout);
//
@@ -444,7 +444,6 @@ UsbBotExecCommand (
return EFI_SUCCESS;
}
/**
Reset the USB mass storage device by BOT protocol.
@@ -459,8 +458,8 @@ UsbBotExecCommand (
**/
EFI_STATUS
UsbBotResetDevice (
IN VOID *Context,
IN BOOLEAN ExtendedVerification
IN VOID *Context,
IN BOOLEAN ExtendedVerification
)
{
USB_BOT_PROTOCOL *UsbBot;
@@ -469,7 +468,7 @@ UsbBotResetDevice (
UINT32 Result;
UINT32 Timeout;
UsbBot = (USB_BOT_PROTOCOL *) Context;
UsbBot = (USB_BOT_PROTOCOL *)Context;
if (ExtendedVerification) {
//
@@ -522,7 +521,6 @@ UsbBotResetDevice (
return Status;
}
/**
Get the max LUN (Logical Unit Number) of USB mass storage device.
@@ -536,8 +534,8 @@ UsbBotResetDevice (
**/
EFI_STATUS
UsbBotGetMaxLun (
IN VOID *Context,
OUT UINT8 *MaxLun
IN VOID *Context,
OUT UINT8 *MaxLun
)
{
USB_BOT_PROTOCOL *UsbBot;
@@ -546,11 +544,11 @@ UsbBotGetMaxLun (
UINT32 Result;
UINT32 Timeout;
if (Context == NULL || MaxLun == NULL) {
if ((Context == NULL) || (MaxLun == NULL)) {
return EFI_INVALID_PARAMETER;
}
UsbBot = (USB_BOT_PROTOCOL *) Context;
UsbBot = (USB_BOT_PROTOCOL *)Context;
//
// Issue a class specific Bulk-Only Mass Storage get max lun request.
@@ -568,11 +566,11 @@ UsbBotGetMaxLun (
&Request,
EfiUsbDataIn,
Timeout,
(VOID *) MaxLun,
(VOID *)MaxLun,
1,
&Result
);
if (EFI_ERROR (Status) || *MaxLun > USB_BOT_MAX_LUN) {
if (EFI_ERROR (Status) || (*MaxLun > USB_BOT_MAX_LUN)) {
//
// If the Get LUN request returns an error or the MaxLun is larger than
// the maximum LUN value (0x0f) supported by the USB Mass Storage Class
@@ -598,7 +596,7 @@ UsbBotGetMaxLun (
**/
EFI_STATUS
UsbBotCleanUp (
IN VOID *Context
IN VOID *Context
)
{
FreePool (Context);

View File

@@ -11,29 +11,29 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_USBMASS_BOT_H_
#define _EFI_USBMASS_BOT_H_
extern USB_MASS_TRANSPORT mUsbBotTransport;
extern USB_MASS_TRANSPORT mUsbBotTransport;
//
// Usb Bulk-Only class specific request
//
#define USB_BOT_RESET_REQUEST 0xFF ///< Bulk-Only Mass Storage Reset
#define USB_BOT_GETLUN_REQUEST 0xFE ///< Get Max Lun
#define USB_BOT_CBW_SIGNATURE 0x43425355 ///< dCBWSignature, tag the packet as CBW
#define USB_BOT_CSW_SIGNATURE 0x53425355 ///< dCSWSignature, tag the packet as CSW
#define USB_BOT_MAX_LUN 0x0F ///< Lun number is from 0 to 15
#define USB_BOT_MAX_CMDLEN 16 ///< Maximum number of command from command set
#define USB_BOT_RESET_REQUEST 0xFF ///< Bulk-Only Mass Storage Reset
#define USB_BOT_GETLUN_REQUEST 0xFE ///< Get Max Lun
#define USB_BOT_CBW_SIGNATURE 0x43425355 ///< dCBWSignature, tag the packet as CBW
#define USB_BOT_CSW_SIGNATURE 0x53425355 ///< dCSWSignature, tag the packet as CSW
#define USB_BOT_MAX_LUN 0x0F ///< Lun number is from 0 to 15
#define USB_BOT_MAX_CMDLEN 16 ///< Maximum number of command from command set
//
// Usb BOT command block status values
//
#define USB_BOT_COMMAND_OK 0x00 ///< Command passed, good status
#define USB_BOT_COMMAND_FAILED 0x01 ///< Command failed
#define USB_BOT_COMMAND_ERROR 0x02 ///< Phase error, need to reset the device
#define USB_BOT_COMMAND_OK 0x00 ///< Command passed, good status
#define USB_BOT_COMMAND_FAILED 0x01 ///< Command failed
#define USB_BOT_COMMAND_ERROR 0x02 ///< Phase error, need to reset the device
//
// Usb Bot retry to get CSW, refers to specification[BOT10-5.3, it says 2 times]
//
#define USB_BOT_RECV_CSW_RETRY 3
#define USB_BOT_RECV_CSW_RETRY 3
//
// Usb Bot wait device reset complete, set by experience
@@ -43,32 +43,32 @@ extern USB_MASS_TRANSPORT mUsbBotTransport;
//
// Usb Bot transport timeout, set by experience
//
#define USB_BOT_SEND_CBW_TIMEOUT (3 * USB_MASS_1_SECOND)
#define USB_BOT_RECV_CSW_TIMEOUT (3 * USB_MASS_1_SECOND)
#define USB_BOT_RESET_DEVICE_TIMEOUT (3 * USB_MASS_1_SECOND)
#define USB_BOT_SEND_CBW_TIMEOUT (3 * USB_MASS_1_SECOND)
#define USB_BOT_RECV_CSW_TIMEOUT (3 * USB_MASS_1_SECOND)
#define USB_BOT_RESET_DEVICE_TIMEOUT (3 * USB_MASS_1_SECOND)
#pragma pack(1)
///
/// The CBW (Command Block Wrapper) structures used by the USB BOT protocol.
///
typedef struct {
UINT32 Signature;
UINT32 Tag;
UINT32 DataLen; ///< Length of data between CBW and CSW
UINT8 Flag; ///< Bit 7, 0 ~ Data-Out, 1 ~ Data-In
UINT8 Lun; ///< Lun number. Bits 0~3 are used
UINT8 CmdLen; ///< Length of the command. Bits 0~4 are used
UINT8 CmdBlock[USB_BOT_MAX_CMDLEN];
UINT32 Signature;
UINT32 Tag;
UINT32 DataLen; ///< Length of data between CBW and CSW
UINT8 Flag; ///< Bit 7, 0 ~ Data-Out, 1 ~ Data-In
UINT8 Lun; ///< Lun number. Bits 0~3 are used
UINT8 CmdLen; ///< Length of the command. Bits 0~4 are used
UINT8 CmdBlock[USB_BOT_MAX_CMDLEN];
} USB_BOT_CBW;
///
/// The and CSW (Command Status Wrapper) structures used by the USB BOT protocol.
///
typedef struct {
UINT32 Signature;
UINT32 Tag;
UINT32 DataResidue;
UINT8 CmdStatus;
UINT32 Signature;
UINT32 Tag;
UINT32 DataResidue;
UINT8 CmdStatus;
} USB_BOT_CSW;
#pragma pack()
@@ -76,11 +76,11 @@ typedef struct {
//
// Put Interface at the first field to make it easy to distinguish BOT/CBI Protocol instance
//
EFI_USB_INTERFACE_DESCRIPTOR Interface;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpoint;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpoint;
UINT32 CbwTag;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR Interface;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpoint;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpoint;
UINT32 CbwTag;
EFI_USB_IO_PROTOCOL *UsbIo;
} USB_BOT_PROTOCOL;
/**
@@ -100,8 +100,8 @@ typedef struct {
**/
EFI_STATUS
UsbBotInit (
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
);
/**
@@ -150,8 +150,8 @@ UsbBotExecCommand (
**/
EFI_STATUS
UsbBotResetDevice (
IN VOID *Context,
IN BOOLEAN ExtendedVerification
IN VOID *Context,
IN BOOLEAN ExtendedVerification
);
/**
@@ -167,8 +167,8 @@ UsbBotResetDevice (
**/
EFI_STATUS
UsbBotGetMaxLun (
IN VOID *Context,
OUT UINT8 *MaxLun
IN VOID *Context,
OUT UINT8 *MaxLun
);
/**
@@ -181,7 +181,7 @@ UsbBotGetMaxLun (
**/
EFI_STATUS
UsbBotCleanUp (
IN VOID *Context
IN VOID *Context
);
#endif

View File

@@ -14,7 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Definition of USB CBI0 Transport Protocol
//
USB_MASS_TRANSPORT mUsbCbi0Transport = {
USB_MASS_TRANSPORT mUsbCbi0Transport = {
USB_MASS_STORE_CBI0,
UsbCbiInit,
UsbCbiExecCommand,
@@ -26,7 +26,7 @@ USB_MASS_TRANSPORT mUsbCbi0Transport = {
//
// Definition of USB CBI1 Transport Protocol
//
USB_MASS_TRANSPORT mUsbCbi1Transport = {
USB_MASS_TRANSPORT mUsbCbi1Transport = {
USB_MASS_STORE_CBI1,
UsbCbiInit,
UsbCbiExecCommand,
@@ -52,8 +52,8 @@ USB_MASS_TRANSPORT mUsbCbi1Transport = {
**/
EFI_STATUS
UsbCbiInit (
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
)
{
USB_CBI_PROTOCOL *UsbCbi;
@@ -82,8 +82,9 @@ UsbCbiInit (
}
Interface = &UsbCbi->Interface;
if ((Interface->InterfaceProtocol != USB_MASS_STORE_CBI0)
&& (Interface->InterfaceProtocol != USB_MASS_STORE_CBI1)) {
if ( (Interface->InterfaceProtocol != USB_MASS_STORE_CBI0)
&& (Interface->InterfaceProtocol != USB_MASS_STORE_CBI1))
{
Status = EFI_UNSUPPORTED;
goto ON_ERROR;
}
@@ -102,27 +103,27 @@ UsbCbiInit (
// Use the first Bulk-In and Bulk-Out endpoints
//
if (USB_IS_IN_ENDPOINT (EndPoint.EndpointAddress) &&
(UsbCbi->BulkInEndpoint == NULL)) {
UsbCbi->BulkInEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbCbi + 1);
CopyMem(UsbCbi->BulkInEndpoint, &EndPoint, sizeof (EndPoint));;
(UsbCbi->BulkInEndpoint == NULL))
{
UsbCbi->BulkInEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *)(UsbCbi + 1);
CopyMem (UsbCbi->BulkInEndpoint, &EndPoint, sizeof (EndPoint));
}
if (USB_IS_OUT_ENDPOINT (EndPoint.EndpointAddress) &&
(UsbCbi->BulkOutEndpoint == NULL)) {
UsbCbi->BulkOutEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbCbi + 1) + 1;
CopyMem(UsbCbi->BulkOutEndpoint, &EndPoint, sizeof (EndPoint));
(UsbCbi->BulkOutEndpoint == NULL))
{
UsbCbi->BulkOutEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *)(UsbCbi + 1) + 1;
CopyMem (UsbCbi->BulkOutEndpoint, &EndPoint, sizeof (EndPoint));
}
} else if (USB_IS_INTERRUPT_ENDPOINT (EndPoint.Attributes)) {
//
// Use the first interrupt endpoint if it is CBI0
//
if ((Interface->InterfaceProtocol == USB_MASS_STORE_CBI0) &&
(UsbCbi->InterruptEndpoint == NULL)) {
UsbCbi->InterruptEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbCbi + 1) + 2;
CopyMem(UsbCbi->InterruptEndpoint, &EndPoint, sizeof (EndPoint));
(UsbCbi->InterruptEndpoint == NULL))
{
UsbCbi->InterruptEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *)(UsbCbi + 1) + 2;
CopyMem (UsbCbi->InterruptEndpoint, &EndPoint, sizeof (EndPoint));
}
}
}
@@ -131,6 +132,7 @@ UsbCbiInit (
Status = EFI_UNSUPPORTED;
goto ON_ERROR;
}
if ((Interface->InterfaceProtocol == USB_MASS_STORE_CBI0) && (UsbCbi->InterruptEndpoint == NULL)) {
Status = EFI_UNSUPPORTED;
goto ON_ERROR;
@@ -166,10 +168,10 @@ ON_ERROR:
**/
EFI_STATUS
UsbCbiSendCommand (
IN USB_CBI_PROTOCOL *UsbCbi,
IN UINT8 *Cmd,
IN UINT8 CmdLen,
IN UINT32 Timeout
IN USB_CBI_PROTOCOL *UsbCbi,
IN UINT8 *Cmd,
IN UINT8 CmdLen,
IN UINT32 Timeout
)
{
EFI_USB_DEVICE_REQUEST Request;
@@ -188,8 +190,8 @@ UsbCbiSendCommand (
Request.Index = UsbCbi->Interface.InterfaceNumber;
Request.Length = CmdLen;
Status = EFI_SUCCESS;
Timeout = Timeout / USB_MASS_1_MILLISECOND;
Status = EFI_SUCCESS;
Timeout = Timeout / USB_MASS_1_MILLISECOND;
for (Retry = 0; Retry < USB_CBI_MAX_RETRY; Retry++) {
//
@@ -223,7 +225,6 @@ UsbCbiSendCommand (
return Status;
}
/**
Transfer data between the device and host.
@@ -244,20 +245,20 @@ UsbCbiSendCommand (
**/
EFI_STATUS
UsbCbiDataTransfer (
IN USB_CBI_PROTOCOL *UsbCbi,
IN EFI_USB_DATA_DIRECTION DataDir,
IN OUT UINT8 *Data,
IN OUT UINTN *TransLen,
IN UINT32 Timeout
IN USB_CBI_PROTOCOL *UsbCbi,
IN EFI_USB_DATA_DIRECTION DataDir,
IN OUT UINT8 *Data,
IN OUT UINTN *TransLen,
IN UINT32 Timeout
)
{
EFI_USB_ENDPOINT_DESCRIPTOR *Endpoint;
EFI_STATUS Status;
UINT32 TransStatus;
UINTN Remain;
UINTN Increment;
UINT8 *Next;
UINTN Retry;
EFI_USB_ENDPOINT_DESCRIPTOR *Endpoint;
EFI_STATUS Status;
UINT32 TransStatus;
UINTN Remain;
UINTN Increment;
UINT8 *Next;
UINTN Retry;
//
// If no data to transfer, just return EFI_SUCCESS.
@@ -287,7 +288,7 @@ UsbCbiDataTransfer (
while (Remain > 0) {
TransStatus = 0;
if (Remain > (UINTN) USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize) {
if (Remain > (UINTN)USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize) {
Increment = USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize;
} else {
Increment = Remain;
@@ -334,7 +335,7 @@ UsbCbiDataTransfer (
goto ON_EXIT;
}
Next += Increment;
Next += Increment;
Remain -= Increment;
}
@@ -343,7 +344,6 @@ ON_EXIT:
return Status;
}
/**
Gets the result of high level command execution from interrupt endpoint.
@@ -362,20 +362,20 @@ ON_EXIT:
**/
EFI_STATUS
UsbCbiGetStatus (
IN USB_CBI_PROTOCOL *UsbCbi,
IN UINT32 Timeout,
OUT USB_CBI_STATUS *Result
IN USB_CBI_PROTOCOL *UsbCbi,
IN UINT32 Timeout,
OUT USB_CBI_STATUS *Result
)
{
UINTN Len;
UINT8 Endpoint;
EFI_STATUS Status;
UINT32 TransStatus;
INTN Retry;
UINTN Len;
UINT8 Endpoint;
EFI_STATUS Status;
UINT32 TransStatus;
INTN Retry;
Endpoint = UsbCbi->InterruptEndpoint->EndpointAddress;
Status = EFI_SUCCESS;
Timeout = Timeout / USB_MASS_1_MILLISECOND;
Endpoint = UsbCbi->InterruptEndpoint->EndpointAddress;
Status = EFI_SUCCESS;
Timeout = Timeout / USB_MASS_1_MILLISECOND;
//
// Attempt to the read the result from interrupt endpoint
@@ -405,7 +405,6 @@ UsbCbiGetStatus (
return Status;
}
/**
Execute USB mass storage command through the CBI0/CBI1 transport protocol.
@@ -436,13 +435,13 @@ UsbCbiExecCommand (
OUT UINT32 *CmdStatus
)
{
USB_CBI_PROTOCOL *UsbCbi;
USB_CBI_STATUS Result;
EFI_STATUS Status;
UINTN TransLen;
USB_CBI_PROTOCOL *UsbCbi;
USB_CBI_STATUS Result;
EFI_STATUS Status;
UINTN TransLen;
*CmdStatus = USB_MASS_CMD_SUCCESS;
UsbCbi = (USB_CBI_PROTOCOL *) Context;
*CmdStatus = USB_MASS_CMD_SUCCESS;
UsbCbi = (USB_CBI_PROTOCOL *)Context;
//
// Send the command to the device. Return immediately if device
@@ -450,8 +449,8 @@ UsbCbiExecCommand (
//
Status = UsbCbiSendCommand (UsbCbi, Cmd, CmdLen, Timeout);
if (EFI_ERROR (Status)) {
gBS->Stall(10 * USB_MASS_1_MILLISECOND);
DEBUG ((DEBUG_ERROR, "UsbCbiExecCommand: UsbCbiSendCommand (%r)\n",Status));
gBS->Stall (10 * USB_MASS_1_MILLISECOND);
DEBUG ((DEBUG_ERROR, "UsbCbiExecCommand: UsbCbiSendCommand (%r)\n", Status));
return Status;
}
@@ -459,11 +458,11 @@ UsbCbiExecCommand (
// Transfer the data. Return this status if no interrupt endpoint
// is used to report the transfer status.
//
TransLen = (UINTN) DataLen;
TransLen = (UINTN)DataLen;
Status = UsbCbiDataTransfer (UsbCbi, DataDir, Data, &TransLen, Timeout);
Status = UsbCbiDataTransfer (UsbCbi, DataDir, Data, &TransLen, Timeout);
if (UsbCbi->InterruptEndpoint == NULL) {
DEBUG ((DEBUG_ERROR, "UsbCbiExecCommand: UsbCbiDataTransfer (%r)\n",Status));
DEBUG ((DEBUG_ERROR, "UsbCbiExecCommand: UsbCbiDataTransfer (%r)\n", Status));
return Status;
}
@@ -472,7 +471,7 @@ UsbCbiExecCommand (
//
Status = UsbCbiGetStatus (UsbCbi, Timeout, &Result);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UsbCbiExecCommand: UsbCbiGetStatus (%r)\n",Status));
DEBUG ((DEBUG_ERROR, "UsbCbiExecCommand: UsbCbiGetStatus (%r)\n", Status));
return Status;
}
@@ -483,7 +482,7 @@ UsbCbiExecCommand (
// Do not set the USB_MASS_CMD_FAIL for a request sense command
// as a bad result type doesn't mean a cmd failure
//
if (Result.Type != 0 && *(UINT8*)Cmd != 0x03) {
if ((Result.Type != 0) && (*(UINT8 *)Cmd != 0x03)) {
*CmdStatus = USB_MASS_CMD_FAIL;
}
} else {
@@ -491,40 +490,39 @@ UsbCbiExecCommand (
// Check page 27, CBI spec 1.1 for vaious reture status.
//
switch (Result.Value & 0x03) {
case 0x00:
//
// Pass
//
*CmdStatus = USB_MASS_CMD_SUCCESS;
break;
case 0x00:
//
// Pass
//
*CmdStatus = USB_MASS_CMD_SUCCESS;
break;
case 0x02:
//
// Phase Error, response with reset.
// No break here to fall through to "Fail".
//
UsbCbiResetDevice (UsbCbi, FALSE);
case 0x02:
//
// Phase Error, response with reset.
// No break here to fall through to "Fail".
//
UsbCbiResetDevice (UsbCbi, FALSE);
case 0x01:
//
// Fail
//
*CmdStatus = USB_MASS_CMD_FAIL;
break;
case 0x01:
//
// Fail
//
*CmdStatus = USB_MASS_CMD_FAIL;
break;
case 0x03:
//
// Persistent Fail. Need to send REQUEST SENSE.
//
*CmdStatus = USB_MASS_CMD_PERSISTENT;
break;
case 0x03:
//
// Persistent Fail. Need to send REQUEST SENSE.
//
*CmdStatus = USB_MASS_CMD_PERSISTENT;
break;
}
}
return EFI_SUCCESS;
}
/**
Reset the USB mass storage device by CBI protocol.
@@ -542,17 +540,17 @@ UsbCbiExecCommand (
**/
EFI_STATUS
UsbCbiResetDevice (
IN VOID *Context,
IN BOOLEAN ExtendedVerification
IN VOID *Context,
IN BOOLEAN ExtendedVerification
)
{
UINT8 ResetCmd[USB_CBI_RESET_CMD_LEN];
USB_CBI_PROTOCOL *UsbCbi;
USB_CBI_STATUS Result;
EFI_STATUS Status;
UINT32 Timeout;
UINT8 ResetCmd[USB_CBI_RESET_CMD_LEN];
USB_CBI_PROTOCOL *UsbCbi;
USB_CBI_STATUS Result;
EFI_STATUS Status;
UINT32 Timeout;
UsbCbi = (USB_CBI_PROTOCOL *) Context;
UsbCbi = (USB_CBI_PROTOCOL *)Context;
//
// Fill in the reset command.
@@ -587,7 +585,6 @@ UsbCbiResetDevice (
return Status;
}
/**
Clean up the CBI protocol's resource.
@@ -598,7 +595,7 @@ UsbCbiResetDevice (
**/
EFI_STATUS
UsbCbiCleanUp (
IN VOID *Context
IN VOID *Context
)
{
FreePool (Context);

View File

@@ -10,19 +10,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_USBMASS_CBI_H_
#define _EFI_USBMASS_CBI_H_
extern USB_MASS_TRANSPORT mUsbCbi0Transport;
extern USB_MASS_TRANSPORT mUsbCbi1Transport;
extern USB_MASS_TRANSPORT mUsbCbi0Transport;
extern USB_MASS_TRANSPORT mUsbCbi1Transport;
#define USB_CBI_MAX_PACKET_NUM 16
#define USB_CBI_RESET_CMD_LEN 12
#define USB_CBI_MAX_PACKET_NUM 16
#define USB_CBI_RESET_CMD_LEN 12
//
// USB CBI retry C/B/I transport times, set by experience
//
#define USB_CBI_MAX_RETRY 3
#define USB_CBI_MAX_RETRY 3
//
// Time to wait for USB CBI reset to complete, set by experience
//
#define USB_CBI_RESET_DEVICE_STALL (50 * USB_MASS_1_MILLISECOND)
#define USB_CBI_RESET_DEVICE_STALL (50 * USB_MASS_1_MILLISECOND)
//
// USB CBI transport timeout, set by experience
//
@@ -32,17 +32,17 @@ typedef struct {
//
// Put Interface at the first field to make it easy to distinguish BOT/CBI Protocol instance
//
EFI_USB_INTERFACE_DESCRIPTOR Interface;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpoint;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpoint;
EFI_USB_ENDPOINT_DESCRIPTOR *InterruptEndpoint;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR Interface;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpoint;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpoint;
EFI_USB_ENDPOINT_DESCRIPTOR *InterruptEndpoint;
EFI_USB_IO_PROTOCOL *UsbIo;
} USB_CBI_PROTOCOL;
#pragma pack(1)
typedef struct {
UINT8 Type;
UINT8 Value;
UINT8 Type;
UINT8 Value;
} USB_CBI_STATUS;
#pragma pack()
@@ -63,8 +63,8 @@ typedef struct {
**/
EFI_STATUS
UsbCbiInit (
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
IN EFI_USB_IO_PROTOCOL *UsbIo,
OUT VOID **Context OPTIONAL
);
/**
@@ -114,8 +114,8 @@ UsbCbiExecCommand (
**/
EFI_STATUS
UsbCbiResetDevice (
IN VOID *Context,
IN BOOLEAN ExtendedVerification
IN VOID *Context,
IN BOOLEAN ExtendedVerification
);
/**
@@ -128,7 +128,7 @@ UsbCbiResetDevice (
**/
EFI_STATUS
UsbCbiCleanUp (
IN VOID *Context
IN VOID *Context
);
#endif

View File

@@ -8,7 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "UsbMass.h"
EFI_DISK_INFO_PROTOCOL gUsbDiskInfoProtocolTemplate = {
EFI_DISK_INFO_PROTOCOL gUsbDiskInfoProtocolTemplate = {
EFI_DISK_INFO_USB_INTERFACE_GUID,
UsbDiskInfoInquiry,
UsbDiskInfoIdentify,
@@ -27,13 +27,12 @@ EFI_DISK_INFO_PROTOCOL gUsbDiskInfoProtocolTemplate = {
**/
VOID
InitializeDiskInfo (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
CopyMem (&UsbMass->DiskInfo, &gUsbDiskInfoProtocolTemplate, sizeof (gUsbDiskInfoProtocolTemplate));
}
/**
Provides inquiry information for the controller type.
@@ -53,26 +52,26 @@ InitializeDiskInfo (
EFI_STATUS
EFIAPI
UsbDiskInfoInquiry (
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *InquiryData,
IN OUT UINT32 *InquiryDataSize
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *InquiryData,
IN OUT UINT32 *InquiryDataSize
)
{
EFI_STATUS Status;
USB_MASS_DEVICE *UsbMass;
EFI_STATUS Status;
USB_MASS_DEVICE *UsbMass;
UsbMass = USB_MASS_DEVICE_FROM_DISK_INFO (This);
UsbMass = USB_MASS_DEVICE_FROM_DISK_INFO (This);
Status = EFI_BUFFER_TOO_SMALL;
if (*InquiryDataSize >= sizeof (UsbMass->InquiryData)) {
Status = EFI_SUCCESS;
CopyMem (InquiryData, &UsbMass->InquiryData, sizeof (UsbMass->InquiryData));
}
*InquiryDataSize = sizeof (UsbMass->InquiryData);
return Status;
}
/**
Provides identify information for the controller type.
@@ -94,9 +93,9 @@ UsbDiskInfoInquiry (
EFI_STATUS
EFIAPI
UsbDiskInfoIdentify (
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *IdentifyData,
IN OUT UINT32 *IdentifyDataSize
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *IdentifyData,
IN OUT UINT32 *IdentifyDataSize
)
{
return EFI_NOT_FOUND;
@@ -122,16 +121,15 @@ UsbDiskInfoIdentify (
EFI_STATUS
EFIAPI
UsbDiskInfoSenseData (
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *SenseData,
IN OUT UINT32 *SenseDataSize,
OUT UINT8 *SenseDataNumber
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *SenseData,
IN OUT UINT32 *SenseDataSize,
OUT UINT8 *SenseDataNumber
)
{
return EFI_NOT_FOUND;
}
/**
This function is used to get controller information.
@@ -146,11 +144,10 @@ UsbDiskInfoSenseData (
EFI_STATUS
EFIAPI
UsbDiskInfoWhichIde (
IN EFI_DISK_INFO_PROTOCOL *This,
OUT UINT32 *IdeChannel,
OUT UINT32 *IdeDevice
IN EFI_DISK_INFO_PROTOCOL *This,
OUT UINT32 *IdeChannel,
OUT UINT32 *IdeDevice
)
{
return EFI_UNSUPPORTED;
}

View File

@@ -20,10 +20,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
InitializeDiskInfo (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
);
/**
Provides inquiry information for the controller type.
@@ -43,9 +42,9 @@ InitializeDiskInfo (
EFI_STATUS
EFIAPI
UsbDiskInfoInquiry (
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *InquiryData,
IN OUT UINT32 *InquiryDataSize
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *InquiryData,
IN OUT UINT32 *InquiryDataSize
);
/**
@@ -69,9 +68,9 @@ UsbDiskInfoInquiry (
EFI_STATUS
EFIAPI
UsbDiskInfoIdentify (
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *IdentifyData,
IN OUT UINT32 *IdentifyDataSize
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *IdentifyData,
IN OUT UINT32 *IdentifyDataSize
);
/**
@@ -94,13 +93,12 @@ UsbDiskInfoIdentify (
EFI_STATUS
EFIAPI
UsbDiskInfoSenseData (
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *SenseData,
IN OUT UINT32 *SenseDataSize,
OUT UINT8 *SenseDataNumber
IN EFI_DISK_INFO_PROTOCOL *This,
IN OUT VOID *SenseData,
IN OUT UINT32 *SenseDataSize,
OUT UINT8 *SenseDataNumber
);
/**
This function is used to get controller information.
@@ -115,9 +113,9 @@ UsbDiskInfoSenseData (
EFI_STATUS
EFIAPI
UsbDiskInfoWhichIde (
IN EFI_DISK_INFO_PROTOCOL *This,
OUT UINT32 *IdeChannel,
OUT UINT32 *IdeDevice
IN EFI_DISK_INFO_PROTOCOL *This,
OUT UINT32 *IdeChannel,
OUT UINT32 *IdeDevice
);
#endif

View File

@@ -8,17 +8,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "UsbMass.h"
#define USB_MASS_TRANSPORT_COUNT 3
#define USB_MASS_TRANSPORT_COUNT 3
//
// Array of USB transport interfaces.
//
USB_MASS_TRANSPORT *mUsbMassTransport[USB_MASS_TRANSPORT_COUNT] = {
USB_MASS_TRANSPORT *mUsbMassTransport[USB_MASS_TRANSPORT_COUNT] = {
&mUsbCbi0Transport,
&mUsbCbi1Transport,
&mUsbBotTransport,
};
EFI_DRIVER_BINDING_PROTOCOL gUSBMassDriverBinding = {
EFI_DRIVER_BINDING_PROTOCOL gUSBMassDriverBinding = {
USBMassDriverBindingSupported,
USBMassDriverBindingStart,
USBMassDriverBindingStop,
@@ -45,19 +45,19 @@ EFI_DRIVER_BINDING_PROTOCOL gUSBMassDriverBinding = {
EFI_STATUS
EFIAPI
UsbMassReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
USB_MASS_DEVICE *UsbMass;
EFI_TPL OldTpl;
EFI_STATUS Status;
USB_MASS_DEVICE *UsbMass;
EFI_TPL OldTpl;
EFI_STATUS Status;
//
// Raise TPL to TPL_CALLBACK to serialize all its operations
// to protect shared data structures.
//
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);
Status = UsbMass->Transport->Reset (UsbMass->Context, ExtendedVerification);
@@ -94,11 +94,11 @@ UsbMassReset (
EFI_STATUS
EFIAPI
UsbMassReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
USB_MASS_DEVICE *UsbMass;
@@ -168,7 +168,7 @@ UsbMassReadBlocks (
if (UsbMass->Cdb16Byte) {
Status = UsbBootReadWriteBlocks16 (UsbMass, FALSE, Lba, TotalBlock, Buffer);
} else {
Status = UsbBootReadWriteBlocks (UsbMass, FALSE, (UINT32) Lba, TotalBlock, Buffer);
Status = UsbBootReadWriteBlocks (UsbMass, FALSE, (UINT32)Lba, TotalBlock, Buffer);
}
if (EFI_ERROR (Status)) {
@@ -181,7 +181,6 @@ ON_EXIT:
return Status;
}
/**
Writes a specified number of blocks to the device.
@@ -210,11 +209,11 @@ ON_EXIT:
EFI_STATUS
EFIAPI
UsbMassWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
USB_MASS_DEVICE *UsbMass;
@@ -288,7 +287,7 @@ UsbMassWriteBlocks (
if (UsbMass->Cdb16Byte) {
Status = UsbBootReadWriteBlocks16 (UsbMass, TRUE, Lba, TotalBlock, Buffer);
} else {
Status = UsbBootReadWriteBlocks (UsbMass, TRUE, (UINT32) Lba, TotalBlock, Buffer);
Status = UsbBootReadWriteBlocks (UsbMass, TRUE, (UINT32)Lba, TotalBlock, Buffer);
}
if (EFI_ERROR (Status)) {
@@ -335,11 +334,11 @@ UsbMassFlushBlocks (
**/
EFI_STATUS
UsbMassInitMedia (
IN USB_MASS_DEVICE *UsbMass
IN USB_MASS_DEVICE *UsbMass
)
{
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
Media = &UsbMass->BlockIoMedia;
@@ -363,6 +362,7 @@ UsbMassInitMedia (
//
Status = EFI_SUCCESS;
}
return Status;
}
@@ -400,7 +400,7 @@ UsbMassInitTransport (
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
(VOID **)&UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -427,7 +427,7 @@ UsbMassInitTransport (
*Transport = mUsbMassTransport[Index];
if (Interface.InterfaceProtocol == (*Transport)->Protocol) {
Status = (*Transport)->Init (UsbIo, Context);
Status = (*Transport)->Init (UsbIo, Context);
break;
}
}
@@ -471,12 +471,12 @@ ON_EXIT:
**/
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
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
)
{
USB_MASS_DEVICE *UsbMass;
@@ -490,24 +490,23 @@ UsbMassInitMultiLun (
ReturnStatus = EFI_NOT_FOUND;
for (Index = 0; Index <= MaxLun; Index++) {
DEBUG ((DEBUG_INFO, "UsbMassInitMultiLun: Start to initialize No.%d logic unit\n", Index));
UsbIo = NULL;
UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));
ASSERT (UsbMass != NULL);
UsbMass->Signature = USB_MASS_SIGNATURE;
UsbMass->UsbIo = UsbIo;
UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia;
UsbMass->BlockIo.Reset = UsbMassReset;
UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks;
UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks;
UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks;
UsbMass->OpticalStorage = FALSE;
UsbMass->Transport = Transport;
UsbMass->Context = Context;
UsbMass->Lun = Index;
UsbMass->Signature = USB_MASS_SIGNATURE;
UsbMass->UsbIo = UsbIo;
UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia;
UsbMass->BlockIo.Reset = UsbMassReset;
UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks;
UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks;
UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks;
UsbMass->OpticalStorage = FALSE;
UsbMass->Transport = Transport;
UsbMass->Context = Context;
UsbMass->Lun = Index;
//
// Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.
@@ -566,7 +565,7 @@ UsbMassInitMultiLun (
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
(VOID **)&UsbIo,
This->DriverBindingHandle,
UsbMass->Controller,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -588,6 +587,7 @@ UsbMassInitMultiLun (
FreePool (UsbMass);
continue;
}
ReturnStatus = EFI_SUCCESS;
DEBUG ((DEBUG_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));
}
@@ -609,15 +609,15 @@ UsbMassInitMultiLun (
**/
EFI_STATUS
UsbMassInitNonLun (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN USB_MASS_TRANSPORT *Transport,
IN VOID *Context
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN USB_MASS_TRANSPORT *Transport,
IN VOID *Context
)
{
USB_MASS_DEVICE *UsbMass;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_STATUS Status;
USB_MASS_DEVICE *UsbMass;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_STATUS Status;
UsbIo = NULL;
UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));
@@ -626,7 +626,7 @@ UsbMassInitNonLun (
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
(VOID **)&UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -637,17 +637,17 @@ UsbMassInitNonLun (
goto ON_ERROR;
}
UsbMass->Signature = USB_MASS_SIGNATURE;
UsbMass->Controller = Controller;
UsbMass->UsbIo = UsbIo;
UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia;
UsbMass->BlockIo.Reset = UsbMassReset;
UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks;
UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks;
UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks;
UsbMass->OpticalStorage = FALSE;
UsbMass->Transport = Transport;
UsbMass->Context = Context;
UsbMass->Signature = USB_MASS_SIGNATURE;
UsbMass->Controller = Controller;
UsbMass->UsbIo = UsbIo;
UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia;
UsbMass->BlockIo.Reset = UsbMassReset;
UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks;
UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks;
UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks;
UsbMass->OpticalStorage = FALSE;
UsbMass->Transport = Transport;
UsbMass->Context = Context;
//
// Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.
@@ -678,6 +678,7 @@ ON_ERROR:
if (UsbMass != NULL) {
FreePool (UsbMass);
}
if (UsbIo != NULL) {
gBS->CloseProtocol (
Controller,
@@ -686,10 +687,10 @@ ON_ERROR:
Controller
);
}
return Status;
}
/**
Check whether the controller is a supported USB mass storage.
@@ -718,7 +719,7 @@ USBMassDriverBindingSupported (
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
(VOID **)&UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -793,13 +794,13 @@ USBMassDriverBindingStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
USB_MASS_TRANSPORT *Transport;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
VOID *Context;
UINT8 MaxLun;
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_TPL OldTpl;
USB_MASS_TRANSPORT *Transport;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
VOID *Context;
UINT8 MaxLun;
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
@@ -813,6 +814,7 @@ USBMassDriverBindingStart (
DEBUG ((DEBUG_ERROR, "USBMassDriverBindingStart: UsbMassInitTransport (%r)\n", Status));
goto Exit;
}
if (MaxLun == 0) {
//
// Initialize data for device that does not support multiple LUNSs.
@@ -828,7 +830,7 @@ USBMassDriverBindingStart (
Status = gBS->OpenProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
(VOID **) &DevicePath,
(VOID **)&DevicePath,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -842,7 +844,7 @@ USBMassDriverBindingStart (
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
(VOID **)&UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -866,26 +868,26 @@ USBMassDriverBindingStart (
Status = UsbMassInitMultiLun (This, Controller, Transport, Context, DevicePath, MaxLun);
if (EFI_ERROR (Status)) {
gBS->CloseProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
DEBUG ((DEBUG_ERROR, "USBMassDriverBindingStart: UsbMassInitMultiLun (%r) with Maxlun=%d\n", Status, MaxLun));
}
}
Exit:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Stop controlling the device.
@@ -903,18 +905,18 @@ Exit:
EFI_STATUS
EFIAPI
USBMassDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
USB_MASS_DEVICE *UsbMass;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
UINTN Index;
BOOLEAN AllChildrenStopped;
EFI_STATUS Status;
USB_MASS_DEVICE *UsbMass;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
UINTN Index;
BOOLEAN AllChildrenStopped;
//
// This is a bus driver stop function since multi-lun is supported.
@@ -930,29 +932,29 @@ USBMassDriverBindingStop (
Status = gBS->OpenProtocol (
Controller,
&gEfiBlockIoProtocolGuid,
(VOID **) &BlockIo,
(VOID **)&BlockIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
//
// This is a 2nd type handle(multi-lun root), it needs to close devicepath
// and usbio protocol.
//
gBS->CloseProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
DEBUG ((DEBUG_INFO, "Success to stop multi-lun root handle\n"));
return EFI_SUCCESS;
}
@@ -980,11 +982,11 @@ USBMassDriverBindingStop (
}
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
UsbMass->Transport->CleanUp (UsbMass->Context);
FreePool (UsbMass);
@@ -1001,11 +1003,10 @@ USBMassDriverBindingStop (
AllChildrenStopped = TRUE;
for (Index = 0; Index < NumberOfChildren; Index++) {
Status = gBS->OpenProtocol (
ChildHandleBuffer[Index],
&gEfiBlockIoProtocolGuid,
(VOID **) &BlockIo,
(VOID **)&BlockIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -1046,7 +1047,7 @@ USBMassDriverBindingStop (
gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
(VOID **)&UsbIo,
This->DriverBindingHandle,
ChildHandleBuffer[Index],
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -1058,6 +1059,7 @@ USBMassDriverBindingStop (
if (((Index + 1) == NumberOfChildren) && AllChildrenStopped) {
UsbMass->Transport->CleanUp (UsbMass->Context);
}
FreePool (UsbMass);
}
}
@@ -1066,7 +1068,7 @@ USBMassDriverBindingStop (
return EFI_DEVICE_ERROR;
}
DEBUG ((DEBUG_INFO, "Success to stop all %d multi-lun children handles\n", (UINT32) NumberOfChildren));
DEBUG ((DEBUG_INFO, "Success to stop all %d multi-lun children handles\n", (UINT32)NumberOfChildren));
return EFI_SUCCESS;
}
@@ -1085,8 +1087,8 @@ USBMassDriverBindingStop (
EFI_STATUS
EFIAPI
USBMassStorageEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;

View File

@@ -10,7 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_USBMASS_IMPL_H_
#define _EFI_USBMASS_IMPL_H_
#define USB_MASS_SIGNATURE SIGNATURE_32 ('U', 's', 'b', 'M')
#define USB_MASS_SIGNATURE SIGNATURE_32 ('U', 's', 'b', 'M')
#define USB_MASS_DEVICE_FROM_BLOCK_IO(a) \
CR (a, USB_MASS_DEVICE, BlockIo, USB_MASS_SIGNATURE)
@@ -18,7 +18,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define USB_MASS_DEVICE_FROM_DISK_INFO(a) \
CR (a, USB_MASS_DEVICE, DiskInfo, USB_MASS_SIGNATURE)
extern EFI_COMPONENT_NAME_PROTOCOL gUsbMassStorageComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMassStorageComponentName2;
@@ -88,10 +87,10 @@ USBMassDriverBindingStart (
EFI_STATUS
EFIAPI
USBMassDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
@@ -116,8 +115,8 @@ USBMassDriverBindingStop (
EFI_STATUS
EFIAPI
UsbMassReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
/**
@@ -147,11 +146,11 @@ UsbMassReset (
EFI_STATUS
EFIAPI
UsbMassReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
);
/**
@@ -182,11 +181,11 @@ UsbMassReadBlocks (
EFI_STATUS
EFIAPI
UsbMassWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
);
/**
@@ -255,7 +254,6 @@ UsbMassStorageGetDriverName (
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
@@ -317,11 +315,11 @@ UsbMassStorageGetDriverName (
EFI_STATUS
EFIAPI
UsbMassStorageGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
#endif