/** @file\r
SCSI disk driver that layers on every SCSI IO protocol in the system.\r
\r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
\r
The user code starts with this function.\r
\r
- @param ImageHandle The firmware allocated handle for the EFI image. \r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
@param SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The entry point is executed successfully.\r
@retval other Some error occurs when executing this entry point.\r
\r
);\r
return EFI_SUCCESS;\r
}\r
- } \r
+ }\r
}\r
\r
gBS->FreePool (ScsiDiskDevice->SenseData);\r
Controller\r
);\r
return Status;\r
- \r
+\r
}\r
\r
\r
restrictions for this service. DisconnectController() must follow these\r
calling restrictions. If any other agent wishes to call Stop() it must\r
also follow these calling restrictions.\r
- \r
+\r
@param This Protocol instance pointer.\r
@param ControllerHandle Handle of device to stop driver on\r
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo.Media;\r
BlockSize = Media->BlockSize;\r
\r
NumberOfBlocks = BufferSize / BlockSize;\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo.Media;\r
BlockSize = Media->BlockSize;\r
\r
NumberOfBlocks = BufferSize / BlockSize;\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo2.Media;\r
BlockSize = Media->BlockSize;\r
\r
NumberOfBlocks = BufferSize / BlockSize;\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo2.Media;\r
BlockSize = Media->BlockSize;\r
\r
NumberOfBlocks = BufferSize / BlockSize;\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
\r
- Media = ScsiDiskDevice->BlkIo2.Media;\r
-\r
if (!(Media->MediaPresent)) {\r
Status = EFI_NO_MEDIA;\r
goto Done;\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
@param MustReadCapacity The flag about reading device capacity\r
- @param MediaChange The pointer of flag indicates if media has changed \r
+ @param MediaChange The pointer of flag indicates if media has changed\r
\r
@retval EFI_DEVICE_ERROR Indicates that error occurs\r
@retval EFI_SUCCESS Successfully to detect media\r
} else {\r
break;\r
}\r
- } else { \r
+ } else {\r
Retry++;\r
if (!NeedRetry || (Retry >= MaxRetry)) {\r
goto EXIT;\r
EFI_SCSI_PAGE_CODE_BLOCK_LIMITS_VPD\r
);\r
if (!EFI_ERROR (Status)) {\r
- ScsiDiskDevice->BlkIo.Media->OptimalTransferLengthGranularity = \r
+ ScsiDiskDevice->BlkIo.Media->OptimalTransferLengthGranularity =\r
(BlockLimits->OptimalTransferLengthGranularity2 << 8) |\r
BlockLimits->OptimalTransferLengthGranularity1;\r
\r
} else if (Status == EFI_NOT_READY) {\r
*NeedRetry = TRUE;\r
return EFI_DEVICE_ERROR;\r
- \r
+\r
} else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
*NeedRetry = FALSE;\r
return EFI_DEVICE_ERROR;\r
*NeedRetry = FALSE;\r
return EFI_DEVICE_ERROR;\r
}\r
- \r
+\r
//\r
// if goes here, meant ScsiInquiryCommand() failed.\r
// if ScsiDiskRequestSenseKeys() succeeds at last,\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
@param SenseData The pointer of EFI_SCSI_SENSE_DATA\r
- @param NumberOfSenseKeys The number of sense key \r
+ @param NumberOfSenseKeys The number of sense key\r
@param Action The pointer of action which indicates what is need to do next\r
\r
@retval EFI_DEVICE_ERROR Indicates that error occurs\r
*NeedRetry = FALSE;\r
\r
//\r
- // submit Read Capacity(10) Command. If it returns capacity of FFFFFFFFh, \r
+ // submit Read Capacity(10) Command. If it returns capacity of FFFFFFFFh,\r
// 16 byte command should be used to access large hard disk >2TB\r
//\r
CommandStatus = ScsiReadCapacityCommand (\r
// go ahead to check HostAdapterStatus and TargetStatus\r
// (EFI_TIMEOUT, EFI_DEVICE_ERROR, EFI_WARN_BUFFER_TOO_SMALL)\r
//\r
- \r
+\r
Status = CheckHostAdapterStatus (HostAdapterStatus);\r
if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
*NeedRetry = TRUE;\r
return EFI_DEVICE_ERROR;\r
- \r
+\r
} else if (Status == EFI_DEVICE_ERROR) {\r
//\r
// reset the scsi channel\r
*NeedRetry = FALSE;\r
return EFI_DEVICE_ERROR;\r
}\r
- \r
+\r
//\r
// if goes here, meant ScsiReadCapacityCommand() failed.\r
// if ScsiDiskRequestSenseKeys() succeeds at last,\r
@param TargetStatus Target status\r
\r
@retval EFI_NOT_READY Device is NOT ready.\r
- @retval EFI_DEVICE_ERROR \r
+ @retval EFI_DEVICE_ERROR\r
@retval EFI_SUCCESS\r
\r
**/\r
);\r
if ((Status == EFI_SUCCESS) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) {\r
FallStatus = EFI_SUCCESS;\r
- \r
+\r
} else if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
*NeedRetry = TRUE;\r
FallStatus = EFI_DEVICE_ERROR;\r
- \r
+\r
} else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
*NeedRetry = FALSE;\r
FallStatus = EFI_DEVICE_ERROR;\r
- \r
+\r
} else if (Status == EFI_DEVICE_ERROR) {\r
if (AskResetIfError) {\r
ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);\r
}\r
- \r
+\r
FallStatus = EFI_DEVICE_ERROR;\r
}\r
\r
// no more sense key or number of sense keys exceeds predefined,\r
// skip the loop.\r
//\r
- if ((PtrSenseData->Sense_Key == EFI_SCSI_SK_NO_SENSE) || \r
+ if ((PtrSenseData->Sense_Key == EFI_SCSI_SK_NO_SENSE) ||\r
(*NumberOfSenseKeys == ScsiDiskDevice->SenseDataNumber)) {\r
SenseReq = FALSE;\r
}\r
UINT8 *Ptr;\r
\r
if (!ScsiDiskDevice->Cdb16Byte) {\r
- ScsiDiskDevice->BlkIo.Media->LastBlock = (Capacity10->LastLba3 << 24) |\r
+ ScsiDiskDevice->BlkIo.Media->LastBlock = ((UINT32) Capacity10->LastLba3 << 24) |\r
(Capacity10->LastLba2 << 16) |\r
(Capacity10->LastLba1 << 8) |\r
Capacity10->LastLba0;\r
- \r
+\r
ScsiDiskDevice->BlkIo.Media->BlockSize = (Capacity10->BlockSize3 << 24) |\r
- (Capacity10->BlockSize2 << 16) | \r
+ (Capacity10->BlockSize2 << 16) |\r
(Capacity10->BlockSize1 << 8) |\r
Capacity10->BlockSize0;\r
ScsiDiskDevice->BlkIo.Media->LowestAlignedLba = 0;\r
*Ptr = Capacity16->LastLba7;\r
\r
ScsiDiskDevice->BlkIo.Media->BlockSize = (Capacity16->BlockSize3 << 24) |\r
- (Capacity16->BlockSize2 << 16) | \r
+ (Capacity16->BlockSize2 << 16) |\r
(Capacity16->BlockSize1 << 8) |\r
Capacity16->BlockSize0;\r
\r
\r
BlocksRemaining = NumberOfBlocks;\r
BlockSize = ScsiDiskDevice->BlkIo.Media->BlockSize;\r
- \r
+\r
//\r
// limit the data bytes that can be transferred by one Read(10) or Read(16) Command\r
//\r
&ByteCount,\r
Lba,\r
SectorCount\r
- ); \r
+ );\r
}\r
if (!EFI_ERROR (Status)) {\r
break;\r
SensePtr = SenseData;\r
\r
for (Index = 0; Index < SenseCounts; Index++) {\r
- \r
+\r
//\r
// Sense Key is EFI_SCSI_SK_HARDWARE_ERROR (0x4)\r
//\r
SensePtr = SenseData;\r
\r
for (Index = 0; Index < SenseCounts; Index++) {\r
- \r
+\r
//\r
// Sense Key is EFI_SCSI_SK_UNIT_ATTENTION (0x6)\r
// Additional Sense Code is EFI_SCSI_ASC_RESET (0x29)\r
\r
@param SenseData The pointer of EFI_SCSI_SENSE_DATA\r
@param SenseCounts The number of sense key\r
- @param RetryLater The flag means if need a retry \r
+ @param RetryLater The flag means if need a retry\r
\r
@retval TRUE Drive is ready.\r
@retval FALSE Drive is NOT ready.\r
SensePtr = SenseData;\r
\r
for (Index = 0; Index < SenseCounts; Index++) {\r
- \r
+\r
//\r
// Sense Key is SK_NO_SENSE (0x0)\r
//\r
\r
/**\r
Determine if Block Io & Block Io2 should be produced.\r
- \r
+\r
\r
@param ChildHandle Child Handle to retrieve Parent information.\r
- \r
+\r
@retval TRUE Should produce Block Io & Block Io2.\r
@retval FALSE Should not produce Block Io & Block Io2.\r
\r
-**/ \r
+**/\r
BOOLEAN\r
DetermineInstallBlockIo (\r
IN EFI_HANDLE ChildHandle\r
- ) \r
+ )\r
{\r
EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
return TRUE;\r
}\r
}\r
- \r
+\r
return FALSE;\r
}\r
\r
specified by ProtocolGuid is present on a ControllerHandle and opened by\r
ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
If the ControllerHandle is found, then the protocol specified by ProtocolGuid\r
- will be opened on it. \r
- \r
+ will be opened on it.\r
+\r
\r
@param ProtocolGuid ProtocolGuid pointer.\r
@param ChildHandle Child Handle to retrieve Parent information.\r
- \r
-**/ \r
+\r
+**/\r
VOID *\r
EFIAPI\r
GetParentProtocol (\r
IN EFI_GUID *ProtocolGuid,\r
IN EFI_HANDLE ChildHandle\r
- ) \r
+ )\r
{\r
UINTN Index;\r
UINTN HandleCount;\r
- VOID *Interface; \r
+ VOID *Interface;\r
EFI_STATUS Status;\r
EFI_HANDLE *HandleBuffer;\r
\r
}\r
\r
//\r
- // Iterate to find who is parent handle that is opened with ProtocolGuid by ChildHandle \r
+ // Iterate to find who is parent handle that is opened with ProtocolGuid by ChildHandle\r
//\r
for (Index = 0; Index < HandleCount; Index++) {\r
Status = EfiTestChildHandle (HandleBuffer[Index], ChildHandle, ProtocolGuid);\r
\r
gBS->FreePool (HandleBuffer);\r
return NULL;\r
-} \r
+}\r
\r
/**\r
Determine if EFI Erase Block Protocol should be produced.\r
\r
/**\r
Provides inquiry information for the controller type.\r
- \r
+\r
This function is used by the IDE bus driver to get inquiry data. Data format\r
of Identify data is defined by the Interface GUID.\r
\r
@param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.\r
\r
@retval EFI_SUCCESS The command was accepted without any errors.\r
- @retval EFI_NOT_FOUND Device does not support this data class \r
- @retval EFI_DEVICE_ERROR Error reading InquiryData from device \r
- @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough \r
+ @retval EFI_NOT_FOUND Device does not support this data class\r
+ @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r
+ @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough\r
\r
**/\r
EFI_STATUS\r
This function is used by the IDE bus driver to get identify data. Data format\r
of Identify data is defined by the Interface GUID.\r
\r
- @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL \r
+ @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL\r
instance.\r
@param[in, out] IdentifyData Pointer to a buffer for the identify data.\r
@param[in, out] IdentifyDataSize Pointer to the value for the identify data\r
size.\r
\r
@retval EFI_SUCCESS The command was accepted without any errors.\r
- @retval EFI_NOT_FOUND Device does not support this data class \r
- @retval EFI_DEVICE_ERROR Error reading IdentifyData from device \r
- @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough \r
+ @retval EFI_NOT_FOUND Device does not support this data class\r
+ @retval EFI_DEVICE_ERROR Error reading IdentifyData from device\r
+ @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough\r
\r
**/\r
EFI_STATUS\r
\r
if (CompareGuid (&This->Interface, &gEfiDiskInfoScsiInterfaceGuid) || CompareGuid (&This->Interface, &gEfiDiskInfoUfsInterfaceGuid)) {\r
//\r
- // Physical SCSI bus does not support this data class. \r
+ // Physical SCSI bus does not support this data class.\r
//\r
return EFI_NOT_FOUND;\r
}\r
\r
/**\r
Provides sense data information for the controller type.\r
- \r
- This function is used by the IDE bus driver to get sense data. \r
+\r
+ This function is used by the IDE bus driver to get sense data.\r
Data format of Sense data is defined by the Interface GUID.\r
\r
@param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
/**\r
This function is used by the IDE bus driver to get controller information.\r
\r
- @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance. \r
+ @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
@param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.\r
@param[out] IdeDevice Pointer to the Ide Device number. Master or slave.\r
\r
via SCSI Request Packet.\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
- \r
+\r
@retval EFI_SUCCESS The ATAPI device identify data were retrieved successfully.\r
@retval others Some error occurred during the identification that ATAPI device.\r
\r
-**/ \r
+**/\r
EFI_STATUS\r
AtapiIdentifyDevice (\r
IN OUT SCSI_DISK_DEV *ScsiDiskDevice\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV.\r
@param ChildHandle Child handle to install DiskInfo protocol.\r
- \r
-**/ \r
+\r
+**/\r
VOID\r
InitializeInstallDiskInfo (\r
IN SCSI_DISK_DEV *ScsiDiskDevice,\r
\r
Status = gBS->HandleProtocol (ChildHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePathNode);\r
//\r
- // Device Path protocol must be installed on the device handle. \r
+ // Device Path protocol must be installed on the device handle.\r
//\r
ASSERT_EFI_ERROR (Status);\r
//\r
ScsiDiskDevice->Channel = AtapiDevicePath->PrimarySecondary;\r
ScsiDiskDevice->Device = AtapiDevicePath->SlaveMaster;\r
//\r
- // Update the DiskInfo.Interface to IDE interface GUID for the physical ATAPI device. \r
+ // Update the DiskInfo.Interface to IDE interface GUID for the physical ATAPI device.\r
//\r
CopyGuid (&ScsiDiskDevice->DiskInfo.Interface, &gEfiDiskInfoIdeInterfaceGuid);\r
} else {\r
ScsiDiskDevice->Channel = SataDevicePath->HBAPortNumber;\r
ScsiDiskDevice->Device = SataDevicePath->PortMultiplierPortNumber;\r
//\r
- // Update the DiskInfo.Interface to AHCI interface GUID for the physical AHCI device. \r
+ // Update the DiskInfo.Interface to AHCI interface GUID for the physical AHCI device.\r
//\r
CopyGuid (&ScsiDiskDevice->DiskInfo.Interface, &gEfiDiskInfoAhciInterfaceGuid);\r
}\r