SCSI Bus driver that layers on every SCSI Pass Thru and\r
Extended SCSI Pass Thru protocol in the system.\r
\r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
IN VOID *Context\r
);\r
\r
+/**\r
+ Allocates an aligned buffer for SCSI device.\r
+\r
+ This function allocates an aligned buffer for the SCSI device to perform\r
+ SCSI pass through operations. The alignment requirement is from SCSI pass\r
+ through interface.\r
+\r
+ @param ScsiIoDevice The SCSI child device involved for the operation.\r
+ @param BufferSize The request buffer size.\r
+\r
+ @return A pointer to the aligned buffer or NULL if the allocation fails.\r
+\r
+**/\r
+VOID *\r
+AllocateAlignedBuffer (\r
+ IN SCSI_IO_DEV *ScsiIoDevice,\r
+ IN UINTN BufferSize\r
+ )\r
+{\r
+ return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), ScsiIoDevice->ScsiIo.IoAlign);\r
+}\r
+\r
+/**\r
+ Frees an aligned buffer for SCSI device.\r
+\r
+ This function frees an aligned buffer for the SCSI device to perform\r
+ SCSI pass through operations.\r
+\r
+ @param Buffer The aligned buffer to be freed.\r
+ @param BufferSize The request buffer size.\r
+\r
+**/\r
+VOID\r
+FreeAlignedBuffer (\r
+ IN VOID *Buffer,\r
+ IN UINTN BufferSize\r
+ )\r
+{\r
+ if (Buffer != NULL) {\r
+ FreeAlignedPages (Buffer, EFI_SIZE_TO_PAGES (BufferSize));\r
+ }\r
+}\r
+\r
/**\r
The user Entry Point for module ScsiBus. The user code starts with this function.\r
\r
UINT8 SenseDataLength;\r
UINT8 HostAdapterStatus;\r
UINT8 TargetStatus;\r
- EFI_SCSI_SENSE_DATA SenseData;\r
- EFI_SCSI_INQUIRY_DATA InquiryData;\r
+ EFI_SCSI_INQUIRY_DATA *InquiryData;\r
UINT8 MaxRetry;\r
UINT8 Index;\r
+ BOOLEAN ScsiDeviceFound;\r
\r
HostAdapterStatus = 0;\r
TargetStatus = 0;\r
+\r
+ InquiryData = AllocateAlignedBuffer (ScsiIoDevice, sizeof (EFI_SCSI_INQUIRY_DATA));\r
+ if (InquiryData == NULL) {\r
+ ScsiDeviceFound = FALSE;\r
+ goto Done;\r
+ }\r
+\r
//\r
// Using Inquiry command to scan for the device\r
//\r
InquiryDataLength = sizeof (EFI_SCSI_INQUIRY_DATA);\r
- SenseDataLength = (UINT8) sizeof (EFI_SCSI_SENSE_DATA);\r
- ZeroMem (&InquiryData, InquiryDataLength);\r
+ SenseDataLength = 0;\r
+ ZeroMem (InquiryData, InquiryDataLength);\r
\r
MaxRetry = 2;\r
for (Index = 0; Index < MaxRetry; Index++) {\r
Status = ScsiInquiryCommand (\r
&ScsiIoDevice->ScsiIo,\r
EFI_TIMER_PERIOD_SECONDS (1),\r
- (VOID *) &SenseData,\r
+ NULL,\r
&SenseDataLength,\r
&HostAdapterStatus,\r
&TargetStatus,\r
- (VOID *) &InquiryData,\r
+ (VOID *) InquiryData,\r
&InquiryDataLength,\r
FALSE\r
);\r
} else if ((Status == EFI_BAD_BUFFER_SIZE) || \r
(Status == EFI_INVALID_PARAMETER) ||\r
(Status == EFI_UNSUPPORTED)) {\r
- return FALSE;\r
+ ScsiDeviceFound = FALSE;\r
+ goto Done;\r
}\r
}\r
\r
if (Index == MaxRetry) {\r
- return FALSE;\r
+ ScsiDeviceFound = FALSE;\r
+ goto Done;\r
}\r
\r
//\r
// Retrieved inquiry data successfully\r
//\r
- if ((InquiryData.Peripheral_Qualifier != 0) &&\r
- (InquiryData.Peripheral_Qualifier != 3)) {\r
- return FALSE;\r
+ if ((InquiryData->Peripheral_Qualifier != 0) &&\r
+ (InquiryData->Peripheral_Qualifier != 3)) {\r
+ ScsiDeviceFound = FALSE;\r
+ goto Done;\r
}\r
\r
- if (InquiryData.Peripheral_Qualifier == 3) {\r
- if (InquiryData.Peripheral_Type != 0x1f) {\r
- return FALSE;\r
+ if (InquiryData->Peripheral_Qualifier == 3) {\r
+ if (InquiryData->Peripheral_Type != 0x1f) {\r
+ ScsiDeviceFound = FALSE;\r
+ goto Done;\r
}\r
}\r
\r
- if (0x1e >= InquiryData.Peripheral_Type && InquiryData.Peripheral_Type >= 0xa) {\r
- return FALSE;\r
+ if (0x1e >= InquiryData->Peripheral_Type && InquiryData->Peripheral_Type >= 0xa) {\r
+ ScsiDeviceFound = FALSE;\r
+ goto Done;\r
}\r
\r
//\r
// valid device type and peripheral qualifier combination.\r
//\r
- ScsiIoDevice->ScsiDeviceType = InquiryData.Peripheral_Type;\r
- ScsiIoDevice->RemovableDevice = InquiryData.Rmb;\r
- if (InquiryData.Version == 0) {\r
+ ScsiIoDevice->ScsiDeviceType = InquiryData->Peripheral_Type;\r
+ ScsiIoDevice->RemovableDevice = InquiryData->Rmb;\r
+ if (InquiryData->Version == 0) {\r
ScsiIoDevice->ScsiVersion = 0;\r
} else {\r
//\r
// ANSI-approved version\r
//\r
- ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData.Version & 0x07);\r
+ ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData->Version & 0x07);\r
}\r
\r
- return TRUE;\r
+ ScsiDeviceFound = TRUE;\r
+\r
+Done:\r
+ FreeAlignedBuffer (InquiryData, sizeof (EFI_SCSI_INQUIRY_DATA));\r
+\r
+ return ScsiDeviceFound;\r
}\r
\r
\r