2008-04-09 07:34:50 +02:00
|
|
|
/** @file
|
|
|
|
SCSI Bus driver that layers on every SCSI Pass Thru and
|
|
|
|
Extended SCSI Pass Thru protocol in the system.
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-04-09 07:34:50 +02:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation. <BR>
|
2007-07-17 03:48:09 +02:00
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-04-09 07:34:50 +02:00
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2007-07-20 08:10:09 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
#include "ScsiBus.h"
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_DRIVER_BINDING_PROTOCOL gSCSIBusDriverBinding = {
|
|
|
|
SCSIBusDriverBindingSupported,
|
|
|
|
SCSIBusDriverBindingStart,
|
|
|
|
SCSIBusDriverBindingStop,
|
|
|
|
0xa,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The ScsiBusProtocol is just used to locate ScsiBusDev
|
|
|
|
// structure in the SCSIBusDriverBindingStop(). Then we can
|
|
|
|
// Close all opened protocols and release this structure.
|
|
|
|
//
|
2008-10-30 07:05:06 +01:00
|
|
|
EFI_GUID mScsiBusProtocolGuid = EFI_SCSI_BUS_PROTOCOL_GUID;
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
VOID *mWorkingBuffer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Convert EFI_SCSI_IO_SCSI_REQUEST_PACKET packet to EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet.
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
|
|
|
|
@param CommandPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
|
|
|
|
|
|
|
|
**/
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiioToPassThruPacket (
|
|
|
|
IN EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet,
|
2008-11-12 02:30:58 +01:00
|
|
|
OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *CommandPacket
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
|
|
|
Convert EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet to EFI_SCSI_IO_SCSI_REQUEST_PACKET packet.
|
|
|
|
|
|
|
|
@param ScsiPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
|
|
|
|
@param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
**/
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PassThruToScsiioPacket (
|
|
|
|
IN EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ScsiPacket,
|
2008-11-12 02:30:58 +01:00
|
|
|
OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Notify Function in which convert EFI1.0 PassThru Packet back to UEF2.0
|
|
|
|
SCSI IO Packet.
|
|
|
|
|
|
|
|
@param Event The instance of EFI_EVENT.
|
|
|
|
@param Context The parameter passed in.
|
|
|
|
|
|
|
|
**/
|
2007-07-02 04:40:39 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
NotifyFunction (
|
2008-11-12 02:30:58 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
/**
|
|
|
|
The user Entry Point for module ScsiBus. The user code starts with this function.
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@param ImageHandle The firmware allocated handle for the EFI image.
|
|
|
|
@param SystemTable A pointer to the EFI System Table.
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@retval EFI_SUCCESS The entry point is executed successfully.
|
|
|
|
@retval other Some error occurs when executing this entry point.
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InitializeScsiBus(
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install driver model protocol(s).
|
|
|
|
//
|
2007-09-30 04:45:18 +02:00
|
|
|
Status = EfiLibInstallDriverBindingComponentName2 (
|
2007-06-29 05:33:17 +02:00
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&gSCSIBusDriverBinding,
|
|
|
|
ImageHandle,
|
|
|
|
&gScsiBusComponentName,
|
2007-09-30 04:45:18 +02:00
|
|
|
&gScsiBusComponentName2
|
2007-06-29 05:33:17 +02:00
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Test to see if this driver supports ControllerHandle.
|
|
|
|
|
|
|
|
This service is called by the EFI boot service ConnectController(). In order
|
|
|
|
to make drivers as small as possible, there are a few calling restrictions for
|
|
|
|
this service. ConnectController() must follow these calling restrictions. If
|
|
|
|
any other agent wishes to call Supported() it must also follow these calling
|
|
|
|
restrictions.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to test
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver supports this device
|
|
|
|
@retval EFI_ALREADY_STARTED This driver is already running on this device
|
|
|
|
@retval other This driver does not support this device
|
|
|
|
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SCSIBusDriverBindingSupported (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_SCSI_PASS_THRU_PROTOCOL *PassThru;
|
|
|
|
EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtPassThru;
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
2007-07-02 04:40:39 +02:00
|
|
|
// Check for the existence of Extended SCSI Pass Thru Protocol and SCSI Pass Thru Protocol
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
2007-07-02 04:40:39 +02:00
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
|
|
|
(VOID **)&ExtPassThru,
|
2007-06-29 05:33:17 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
2007-06-29 05:33:17 +02:00
|
|
|
);
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (Status == EFI_ALREADY_STARTED) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
(VOID **)&PassThru,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (Status == EFI_ALREADY_STARTED) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
return EFI_SUCCESS;
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Start this driver on ControllerHandle.
|
|
|
|
|
|
|
|
This service is called by the EFI boot service ConnectController(). In order
|
|
|
|
to make drivers as small as possible, there are a few calling restrictions for
|
|
|
|
this service. ConnectController() must follow these calling restrictions. If
|
|
|
|
any other agent wishes to call Start() it must also follow these calling
|
|
|
|
restrictions.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to bind driver to
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is added to ControllerHandle
|
|
|
|
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
|
|
|
|
@retval other This driver does not support this device
|
|
|
|
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SCSIBusDriverBindingStart (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
2007-09-20 12:06:50 +02:00
|
|
|
UINT64 Lun;
|
|
|
|
UINT8 *TargetId;
|
|
|
|
BOOLEAN ScanOtherPuns;
|
|
|
|
BOOLEAN FromFirstTarget;
|
|
|
|
BOOLEAN ExtScsiSupport;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_STATUS DevicePathStatus;
|
|
|
|
EFI_STATUS PassThruStatus;
|
|
|
|
SCSI_BUS_DEVICE *ScsiBusDev;
|
|
|
|
SCSI_TARGET_ID *ScsiTargetId;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
|
|
|
|
EFI_SCSI_PASS_THRU_PROTOCOL *ScsiInterface;
|
|
|
|
EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiInterface;
|
|
|
|
EFI_SCSI_BUS_PROTOCOL *BusIdentify;
|
|
|
|
|
|
|
|
TargetId = NULL;
|
|
|
|
ScsiTargetId = NULL;
|
|
|
|
ScanOtherPuns = TRUE;
|
2007-07-02 04:40:39 +02:00
|
|
|
FromFirstTarget = FALSE;
|
2007-09-20 12:06:50 +02:00
|
|
|
ExtScsiSupport = FALSE;
|
|
|
|
PassThruStatus = EFI_SUCCESS;
|
2008-11-12 02:30:58 +01:00
|
|
|
|
2007-09-20 12:06:50 +02:00
|
|
|
ScsiTargetId = AllocateZeroPool(sizeof(SCSI_TARGET_ID));
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiTargetId == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetId = &ScsiTargetId->ScsiId.ExtScsi[0];
|
2007-09-20 12:06:50 +02:00
|
|
|
|
|
|
|
DevicePathStatus = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
(VOID **) &ParentDevicePath,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (DevicePathStatus) && (DevicePathStatus != EFI_ALREADY_STARTED)) {
|
|
|
|
return DevicePathStatus;
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2007-09-20 12:06:50 +02:00
|
|
|
// To keep backward compatibility, UEFI ExtPassThru Protocol is supported as well as
|
|
|
|
// EFI PassThru Protocol. From priority perspective, ExtPassThru Protocol is firstly
|
|
|
|
// tried to open on host controller handle. If fails, then PassThru Protocol is tried instead.
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
2007-07-02 04:40:39 +02:00
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
2007-09-20 12:06:50 +02:00
|
|
|
(VOID **) &ExtScsiInterface,
|
2007-06-29 05:33:17 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
2007-09-20 12:06:50 +02:00
|
|
|
//
|
|
|
|
// Fail to open UEFI ExtendPassThru Protocol, then try to open EFI PassThru Protocol instead.
|
|
|
|
//
|
|
|
|
if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {
|
2007-07-02 04:40:39 +02:00
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
2007-09-20 12:06:50 +02:00
|
|
|
(VOID **) &ScsiInterface,
|
2007-07-02 04:40:39 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
2007-09-20 12:06:50 +02:00
|
|
|
//
|
|
|
|
// Fail to open EFI PassThru Protocol, Close the DevicePathProtocol if it is opened by this time.
|
|
|
|
//
|
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
|
|
|
|
if (!EFI_ERROR(DevicePathStatus)) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
}
|
2007-07-02 04:40:39 +02:00
|
|
|
return Status;
|
2007-09-20 12:06:50 +02:00
|
|
|
}
|
2007-07-02 04:40:39 +02:00
|
|
|
} else {
|
2007-09-20 12:06:50 +02:00
|
|
|
//
|
|
|
|
// Succeed to open ExtPassThru Protocol, and meanwhile open PassThru Protocol
|
|
|
|
// with BY_DRIVER if it is also present on the handle. The intent is to prevent
|
|
|
|
// another SCSI Bus Driver to work on the same host handle.
|
|
|
|
//
|
|
|
|
ExtScsiSupport = TRUE;
|
|
|
|
PassThruStatus = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
(VOID **) &ScsiInterface,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
2007-07-02 04:40:39 +02:00
|
|
|
}
|
2007-09-20 12:06:50 +02:00
|
|
|
|
|
|
|
if (Status != EFI_ALREADY_STARTED) {
|
|
|
|
//
|
|
|
|
// Go through here means either ExtPassThru or PassThru Protocol is successfully opened
|
|
|
|
// on this handle for this time. Then construct Host controller private data.
|
|
|
|
//
|
|
|
|
ScsiBusDev = NULL;
|
|
|
|
ScsiBusDev = AllocateZeroPool(sizeof(SCSI_BUS_DEVICE));
|
|
|
|
if (ScsiBusDev == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
ScsiBusDev->Signature = SCSI_BUS_DEVICE_SIGNATURE;
|
|
|
|
ScsiBusDev->ExtScsiSupport = ExtScsiSupport;
|
|
|
|
ScsiBusDev->DevicePath = ParentDevicePath;
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
2007-09-20 12:06:50 +02:00
|
|
|
ScsiBusDev->ExtScsiInterface = ExtScsiInterface;
|
2007-07-02 04:40:39 +02:00
|
|
|
} else {
|
2007-09-20 12:06:50 +02:00
|
|
|
ScsiBusDev->ScsiInterface = ScsiInterface;
|
2007-07-02 04:40:39 +02:00
|
|
|
}
|
2007-09-20 12:06:50 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install EFI_SCSI_BUS_PROTOCOL to the controller handle, So ScsiBusDev could be
|
|
|
|
// retrieved on this controller handle. With ScsiBusDev, we can know which PassThru
|
|
|
|
// Protocol is present on the handle, UEFI ExtPassThru Protocol or EFI PassThru Protocol.
|
|
|
|
//
|
|
|
|
Status = gBS->InstallProtocolInterface (
|
|
|
|
&Controller,
|
|
|
|
&mScsiBusProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
&ScsiBusDev->BusIdentify
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Go through here means Start() is re-invoked again, nothing special is required to do except
|
|
|
|
// picking up Host controller private information.
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&mScsiBusProtocolGuid,
|
|
|
|
(VOID **) &BusIdentify,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (BusIdentify);
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (RemainingDevicePath == NULL) {
|
2007-07-02 04:40:39 +02:00
|
|
|
SetMem (ScsiTargetId, TARGET_MAX_BYTES,0xFF);
|
|
|
|
Lun = 0;
|
|
|
|
FromFirstTarget = TRUE;
|
2007-06-29 05:33:17 +02:00
|
|
|
} else {
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
2007-09-20 12:06:50 +02:00
|
|
|
ScsiBusDev->ExtScsiInterface->GetTargetLun (ScsiBusDev->ExtScsiInterface, RemainingDevicePath, &TargetId, &Lun);
|
2007-07-02 04:40:39 +02:00
|
|
|
} else {
|
|
|
|
ScsiBusDev->ScsiInterface->GetTargetLun (ScsiBusDev->ScsiInterface, RemainingDevicePath, &ScsiTargetId->ScsiId.Scsi, &Lun);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
while(ScanOtherPuns) {
|
|
|
|
if (FromFirstTarget) {
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
|
|
|
// Remaining Device Path is NULL, scan all the possible Puns in the
|
|
|
|
// SCSI Channel.
|
|
|
|
//
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
|
|
|
Status = ScsiBusDev->ExtScsiInterface->GetNextTargetLun (ScsiBusDev->ExtScsiInterface, &TargetId, &Lun);
|
|
|
|
} else {
|
|
|
|
Status = ScsiBusDev->ScsiInterface->GetNextDevice (ScsiBusDev->ScsiInterface, &ScsiTargetId->ScsiId.Scsi, &Lun);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// no legal Pun and Lun found any more
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ScanOtherPuns = FALSE;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Avoid creating handle for the host adapter.
|
|
|
|
//
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
|
|
|
if ((ScsiTargetId->ScsiId.Scsi) == ScsiBusDev->ExtScsiInterface->Mode->AdapterId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((ScsiTargetId->ScsiId.Scsi) == ScsiBusDev->ScsiInterface->Mode->AdapterId) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// Scan for the scsi device, if it attaches to the scsi bus,
|
|
|
|
// then create handle and install scsi i/o protocol.
|
|
|
|
//
|
2007-07-02 04:40:39 +02:00
|
|
|
Status = ScsiScanCreateDevice (This, Controller, ScsiTargetId, Lun, ScsiBusDev);
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool (ScsiTargetId);
|
2007-09-20 12:06:50 +02:00
|
|
|
return EFI_SUCCESS;
|
2008-12-18 06:28:26 +01:00
|
|
|
|
2007-09-20 12:06:50 +02:00
|
|
|
ErrorExit:
|
|
|
|
|
|
|
|
if (ScsiBusDev != NULL) {
|
2008-12-18 06:28:26 +01:00
|
|
|
FreePool (ScsiBusDev);
|
2007-09-20 12:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ExtScsiSupport) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (PassThruStatus)) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
|
|
|
Stop this driver on ControllerHandle.
|
|
|
|
|
|
|
|
This service is called by the EFI boot service DisconnectController().
|
|
|
|
In order to make drivers as small as possible, there are a few calling
|
|
|
|
restrictions for this service. DisconnectController() must follow these
|
|
|
|
calling restrictions. If any other agent wishes to call Stop() it must also
|
|
|
|
follow these calling restrictions.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to stop driver on
|
|
|
|
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
|
|
|
|
children is zero stop the entire bus driver.
|
|
|
|
@param ChildHandleBuffer List of Child Handles to Stop.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is removed ControllerHandle
|
|
|
|
@retval other This driver was not removed from this device
|
|
|
|
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SCSIBusDriverBindingStop (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN UINTN NumberOfChildren,
|
|
|
|
IN EFI_HANDLE *ChildHandleBuffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
BOOLEAN AllChildrenStopped;
|
|
|
|
UINTN Index;
|
|
|
|
EFI_SCSI_IO_PROTOCOL *ScsiIo;
|
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
2007-07-02 04:40:39 +02:00
|
|
|
VOID *ScsiPassThru;
|
|
|
|
EFI_SCSI_BUS_PROTOCOL *Scsidentifier;
|
|
|
|
SCSI_BUS_DEVICE *ScsiBusDev;
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
if (NumberOfChildren == 0) {
|
2007-07-02 04:40:39 +02:00
|
|
|
//
|
|
|
|
// Get the SCSI_BUS_DEVICE
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&mScsiBusProtocolGuid,
|
|
|
|
(VOID **) &Scsidentifier,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (Scsidentifier);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Uninstall SCSI Bus Protocol
|
|
|
|
//
|
|
|
|
gBS->UninstallProtocolInterface (
|
|
|
|
Controller,
|
|
|
|
&mScsiBusProtocolGuid,
|
|
|
|
&ScsiBusDev->BusIdentify
|
|
|
|
);
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
|
|
|
// Close the bus driver
|
|
|
|
//
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
2008-12-17 10:20:16 +01:00
|
|
|
FreePool (ScsiBusDev);
|
2007-06-29 05:33:17 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AllChildrenStopped = TRUE;
|
|
|
|
|
|
|
|
for (Index = 0; Index < NumberOfChildren; Index++) {
|
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
ChildHandleBuffer[Index],
|
|
|
|
&gEfiScsiIoProtocolGuid,
|
|
|
|
(VOID **) &ScsiIo,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
AllChildrenStopped = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (ScsiIo);
|
|
|
|
//
|
|
|
|
// Close the child handle
|
|
|
|
//
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiIoDevice->ExtScsiSupport) {
|
|
|
|
Status = gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ChildHandleBuffer[Index]
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Status = gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ChildHandleBuffer[Index]
|
|
|
|
);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
ChildHandleBuffer[Index],
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
ScsiIoDevice->DevicePath,
|
|
|
|
&gEfiScsiIoProtocolGuid,
|
|
|
|
&ScsiIoDevice->ScsiIo,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
AllChildrenStopped = FALSE;
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiIoDevice->ExtScsiSupport) {
|
|
|
|
gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
2007-08-27 05:33:51 +02:00
|
|
|
&ScsiPassThru,
|
2007-07-02 04:40:39 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
ChildHandleBuffer[Index],
|
|
|
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
2007-08-27 05:33:51 +02:00
|
|
|
&ScsiPassThru,
|
2007-07-02 04:40:39 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
ChildHandleBuffer[Index],
|
|
|
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
|
|
|
);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
} else {
|
2008-12-17 10:20:16 +01:00
|
|
|
FreePool (ScsiIoDevice);
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AllChildrenStopped) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the device type information of the SCSI Controller.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param DeviceType A pointer to the device type information retrieved from
|
|
|
|
the SCSI Controller.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Retrieves the device type information successfully.
|
|
|
|
@retval EFI_INVALID_PARAMETER The DeviceType is NULL.
|
|
|
|
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiGetDeviceType (
|
|
|
|
IN EFI_SCSI_IO_PROTOCOL *This,
|
|
|
|
OUT UINT8 *DeviceType
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
|
|
|
|
|
|
|
if (DeviceType == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
|
|
|
|
*DeviceType = ScsiIoDevice->ScsiDeviceType;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the device location in the SCSI channel.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param Target A pointer to the Target ID of a SCSI device
|
|
|
|
on the SCSI channel.
|
|
|
|
@param Lun A pointer to the LUN of the SCSI device on
|
|
|
|
the SCSI channel.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Retrieves the device location successfully.
|
|
|
|
@retval EFI_INVALID_PARAMETER The Target or Lun is NULL.
|
|
|
|
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiGetDeviceLocation (
|
|
|
|
IN EFI_SCSI_IO_PROTOCOL *This,
|
2007-07-02 04:40:39 +02:00
|
|
|
IN OUT UINT8 **Target,
|
2007-06-29 05:33:17 +02:00
|
|
|
OUT UINT64 *Lun
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
|
|
|
|
|
|
|
if (Target == NULL || Lun == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2007-09-20 12:06:50 +02:00
|
|
|
ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
CopyMem (*Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);
|
|
|
|
|
2007-09-20 12:06:50 +02:00
|
|
|
*Lun = ScsiIoDevice->Lun;
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
|
|
|
Resets the SCSI Bus that the SCSI Controller is attached to.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The SCSI bus is reset successfully.
|
|
|
|
@retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.
|
|
|
|
@retval EFI_UNSUPPORTED The bus reset operation is not supported by the
|
|
|
|
SCSI Host Controller.
|
|
|
|
@retval EFI_TIMEOUT A timeout occurred while attempting to reset
|
|
|
|
the SCSI bus.
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiResetBus (
|
|
|
|
IN EFI_SCSI_IO_PROTOCOL *This
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
|
|
|
|
|
|
|
ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
|
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiIoDevice->ExtScsiSupport){
|
|
|
|
return ScsiIoDevice->ExtScsiPassThru->ResetChannel (ScsiIoDevice->ExtScsiPassThru);
|
|
|
|
} else {
|
|
|
|
return ScsiIoDevice->ScsiPassThru->ResetChannel (ScsiIoDevice->ScsiPassThru);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Resets the SCSI Controller that the device handle specifies.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Reset the SCSI controller successfully.
|
|
|
|
@retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.
|
|
|
|
@retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.
|
|
|
|
@retval EFI_TIMEOUT A timeout occurred while attempting to reset the
|
|
|
|
SCSI Controller.
|
|
|
|
**/
|
2007-06-29 05:33:17 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiResetDevice (
|
|
|
|
IN EFI_SCSI_IO_PROTOCOL *This
|
|
|
|
)
|
|
|
|
{
|
2007-09-20 12:06:50 +02:00
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
2007-07-02 04:40:39 +02:00
|
|
|
UINT8 Target[TARGET_MAX_BYTES];
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
|
2007-07-02 04:40:39 +02:00
|
|
|
CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);
|
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiIoDevice->ExtScsiSupport) {
|
|
|
|
return ScsiIoDevice->ExtScsiPassThru->ResetTargetLun (
|
|
|
|
ScsiIoDevice->ExtScsiPassThru,
|
|
|
|
Target,
|
|
|
|
ScsiIoDevice->Lun
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return ScsiIoDevice->ScsiPassThru->ResetTarget (
|
|
|
|
ScsiIoDevice->ScsiPassThru,
|
|
|
|
ScsiIoDevice->Pun.ScsiId.Scsi,
|
|
|
|
ScsiIoDevice->Lun
|
|
|
|
);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
|
2007-09-20 12:06:50 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
2007-09-20 12:06:50 +02:00
|
|
|
Sends a SCSI Request Packet to the SCSI Controller for execution.
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param CommandPacket The SCSI request packet to send to the SCSI
|
2007-09-20 12:06:50 +02:00
|
|
|
Controller specified by the device handle.
|
2008-11-12 02:30:58 +01:00
|
|
|
@param Event If the SCSI bus where the SCSI device is attached
|
2007-09-20 12:06:50 +02:00
|
|
|
does not support non-blocking I/O, then Event is
|
|
|
|
ignored, and blocking I/O is performed.
|
|
|
|
If Event is NULL, then blocking I/O is performed.
|
|
|
|
If Event is not NULL and non-blocking I/O is
|
|
|
|
supported, then non-blocking I/O is performed,
|
|
|
|
and Event will be signaled when the SCSI Request
|
|
|
|
Packet completes.
|
2008-11-12 02:30:58 +01:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The SCSI Request Packet was sent by the host
|
|
|
|
successfully, and TransferLength bytes were
|
|
|
|
transferred to/from DataBuffer.See
|
|
|
|
HostAdapterStatus, TargetStatus,
|
|
|
|
SenseDataLength, and SenseData in that order
|
|
|
|
for additional status information.
|
|
|
|
@retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
|
|
|
|
but the entire DataBuffer could not be transferred.
|
|
|
|
The actual number of bytes transferred is returned
|
|
|
|
in TransferLength. See HostAdapterStatus,
|
|
|
|
TargetStatus, SenseDataLength, and SenseData in
|
|
|
|
that order for additional status information.
|
|
|
|
@retval EFI_NOT_READY The SCSI Request Packet could not be sent because
|
|
|
|
there are too many SCSI Command Packets already
|
|
|
|
queued.The caller may retry again later.
|
|
|
|
@retval EFI_DEVICE_ERROR A device error occurred while attempting to send
|
|
|
|
the SCSI Request Packet. See HostAdapterStatus,
|
|
|
|
TargetStatus, SenseDataLength, and SenseData in
|
|
|
|
that order for additional status information.
|
|
|
|
@retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.
|
|
|
|
The SCSI Request Packet was not sent, so no
|
|
|
|
additional status information is available.
|
|
|
|
@retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
|
|
|
|
is not supported by the SCSI initiator(i.e., SCSI
|
|
|
|
Host Controller). The SCSI Request Packet was not
|
|
|
|
sent, so no additional status information is
|
|
|
|
available.
|
|
|
|
@retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
|
|
|
|
Request Packet to execute. See HostAdapterStatus,
|
|
|
|
TargetStatus, SenseDataLength, and SenseData in
|
|
|
|
that order for additional status information.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiExecuteSCSICommand (
|
|
|
|
IN EFI_SCSI_IO_PROTOCOL *This,
|
|
|
|
IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet,
|
|
|
|
IN EFI_EVENT Event OPTIONAL
|
|
|
|
)
|
2007-06-29 05:33:17 +02:00
|
|
|
{
|
2007-09-20 12:06:50 +02:00
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
|
|
|
EFI_STATUS Status;
|
2007-07-02 04:40:39 +02:00
|
|
|
UINT8 Target[TARGET_MAX_BYTES];
|
|
|
|
EFI_EVENT PacketEvent;
|
|
|
|
EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ExtRequestPacket;
|
2007-09-20 12:06:50 +02:00
|
|
|
SCSI_EVENT_DATA EventData;
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
PacketEvent = NULL;
|
2007-09-20 12:06:50 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
if (Packet == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
|
2007-07-02 04:40:39 +02:00
|
|
|
CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiIoDevice->ExtScsiSupport) {
|
|
|
|
ExtRequestPacket = (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *) Packet;
|
|
|
|
Status = ScsiIoDevice->ExtScsiPassThru->PassThru (
|
|
|
|
ScsiIoDevice->ExtScsiPassThru,
|
|
|
|
Target,
|
|
|
|
ScsiIoDevice->Lun,
|
|
|
|
ExtRequestPacket,
|
|
|
|
Event
|
|
|
|
);
|
|
|
|
} else {
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-12-18 06:28:26 +01:00
|
|
|
mWorkingBuffer = AllocatePool (sizeof(EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-12-18 06:28:26 +01:00
|
|
|
if (mWorkingBuffer == NULL) {
|
2007-07-02 04:40:39 +02:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2007-07-17 03:48:09 +02:00
|
|
|
// Convert package into EFI1.0, EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET.
|
2007-07-02 04:40:39 +02:00
|
|
|
//
|
2008-11-12 02:30:58 +01:00
|
|
|
Status = ScsiioToPassThruPacket(Packet, (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool(mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-14 03:49:25 +01:00
|
|
|
if (((ScsiIoDevice->ScsiPassThru->Mode->Attributes & EFI_SCSI_PASS_THRU_ATTRIBUTES_NONBLOCKIO) != 0) && (Event != NULL)) {
|
2007-07-02 04:40:39 +02:00
|
|
|
EventData.Data1 = (VOID*)Packet;
|
|
|
|
EventData.Data2 = Event;
|
|
|
|
//
|
|
|
|
// Create Event
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_CALLBACK,
|
|
|
|
NotifyFunction,
|
|
|
|
&EventData,
|
|
|
|
&PacketEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool(mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
Status = ScsiIoDevice->ScsiPassThru->PassThru (
|
|
|
|
ScsiIoDevice->ScsiPassThru,
|
|
|
|
ScsiIoDevice->Pun.ScsiId.Scsi,
|
|
|
|
ScsiIoDevice->Lun,
|
2008-11-12 02:30:58 +01:00
|
|
|
mWorkingBuffer,
|
2007-07-02 04:40:39 +02:00
|
|
|
PacketEvent
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR(Status)) {
|
2008-12-18 06:28:26 +01:00
|
|
|
FreePool(mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
gBS->CloseEvent(PacketEvent);
|
|
|
|
return Status;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// If there's no event or SCSI Device doesn't support NON-BLOCKING, just convert
|
|
|
|
// EFI1.0 PassThru packet back to UEFI2.0 SCSI IO Packet.
|
|
|
|
//
|
|
|
|
Status = ScsiIoDevice->ScsiPassThru->PassThru (
|
|
|
|
ScsiIoDevice->ScsiPassThru,
|
|
|
|
ScsiIoDevice->Pun.ScsiId.Scsi,
|
|
|
|
ScsiIoDevice->Lun,
|
2008-11-12 02:30:58 +01:00
|
|
|
mWorkingBuffer,
|
2007-07-02 04:40:39 +02:00
|
|
|
Event
|
|
|
|
);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool(mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
PassThruToScsiioPacket((EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer,Packet);
|
2007-07-02 04:40:39 +02:00
|
|
|
//
|
|
|
|
// After converting EFI1.0 PassThru Packet back to UEFI2.0 SCSI IO Packet,
|
2008-11-12 02:30:58 +01:00
|
|
|
// free mWorkingBuffer.
|
2007-07-02 04:40:39 +02:00
|
|
|
//
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool(mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
2007-07-02 04:40:39 +02:00
|
|
|
Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@param This Protocol instance pointer
|
|
|
|
@param Controller Controller handle
|
|
|
|
@param TargetId Tartget to be scanned
|
|
|
|
@param Lun The Lun of the SCSI device on the SCSI channel.
|
|
|
|
@param ScsiBusDev The pointer of SCSI_BUS_DEVICE
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@retval EFI_SUCCESS Successfully to discover the device and attach
|
|
|
|
ScsiIoProtocol to it.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Fail to discover the device.
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiScanCreateDevice (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN SCSI_TARGET_ID *TargetId,
|
|
|
|
IN UINT64 Lun,
|
|
|
|
IN OUT SCSI_BUS_DEVICE *ScsiBusDev
|
|
|
|
)
|
2007-06-29 05:33:17 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
SCSI_IO_DEV *ScsiIoDevice;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *ScsiDevicePath;
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
ScsiIoDevice = AllocateZeroPool (sizeof (SCSI_IO_DEV));
|
|
|
|
if (ScsiIoDevice == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ScsiIoDevice->Signature = SCSI_IO_DEV_SIGNATURE;
|
2007-07-02 04:40:39 +02:00
|
|
|
CopyMem(&ScsiIoDevice->Pun, TargetId, TARGET_MAX_BYTES);
|
2007-06-29 05:33:17 +02:00
|
|
|
ScsiIoDevice->Lun = Lun;
|
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
|
|
|
ScsiIoDevice->ExtScsiPassThru = ScsiBusDev->ExtScsiInterface;
|
|
|
|
ScsiIoDevice->ExtScsiSupport = TRUE;
|
|
|
|
ScsiIoDevice->ScsiIo.IoAlign = ScsiIoDevice->ExtScsiPassThru->Mode->IoAlign;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ScsiIoDevice->ScsiPassThru = ScsiBusDev->ScsiInterface;
|
|
|
|
ScsiIoDevice->ExtScsiSupport = FALSE;
|
|
|
|
ScsiIoDevice->ScsiIo.IoAlign = ScsiIoDevice->ScsiPassThru->Mode->IoAlign;
|
|
|
|
}
|
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
ScsiIoDevice->ScsiIo.GetDeviceType = ScsiGetDeviceType;
|
2007-07-02 04:40:39 +02:00
|
|
|
ScsiIoDevice->ScsiIo.GetDeviceLocation = ScsiGetDeviceLocation;
|
2007-06-29 05:33:17 +02:00
|
|
|
ScsiIoDevice->ScsiIo.ResetBus = ScsiResetBus;
|
|
|
|
ScsiIoDevice->ScsiIo.ResetDevice = ScsiResetDevice;
|
2007-06-29 18:40:17 +02:00
|
|
|
ScsiIoDevice->ScsiIo.ExecuteScsiCommand = ScsiExecuteSCSICommand;
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
if (!DiscoverScsiDevice (ScsiIoDevice)) {
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool (ScsiIoDevice);
|
2007-07-02 04:40:39 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
|
|
|
// Set Device Path
|
|
|
|
//
|
2008-12-17 10:20:16 +01:00
|
|
|
ScsiDevicePath = NULL;
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiIoDevice->ExtScsiSupport){
|
|
|
|
Status = ScsiIoDevice->ExtScsiPassThru->BuildDevicePath (
|
|
|
|
ScsiIoDevice->ExtScsiPassThru,
|
|
|
|
&ScsiIoDevice->Pun.ScsiId.ExtScsi[0],
|
|
|
|
ScsiIoDevice->Lun,
|
|
|
|
&ScsiDevicePath
|
|
|
|
);
|
|
|
|
if (Status == EFI_OUT_OF_RESOURCES) {
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool (ScsiIoDevice);
|
2007-07-02 04:40:39 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Status = ScsiIoDevice->ScsiPassThru->BuildDevicePath (
|
|
|
|
ScsiIoDevice->ScsiPassThru,
|
|
|
|
ScsiIoDevice->Pun.ScsiId.Scsi,
|
|
|
|
ScsiIoDevice->Lun,
|
|
|
|
&ScsiDevicePath
|
|
|
|
);
|
|
|
|
if (Status == EFI_OUT_OF_RESOURCES) {
|
2008-11-12 02:30:58 +01:00
|
|
|
FreePool (ScsiIoDevice);
|
2007-07-02 04:40:39 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
ScsiIoDevice->DevicePath = AppendDevicePathNode (
|
2007-07-02 04:40:39 +02:00
|
|
|
ScsiBusDev->DevicePath,
|
2007-06-29 05:33:17 +02:00
|
|
|
ScsiDevicePath
|
|
|
|
);
|
|
|
|
//
|
|
|
|
// The memory space for ScsiDevicePath is allocated in
|
|
|
|
// ScsiPassThru->BuildDevicePath() function; It is no longer used
|
|
|
|
// after EfiAppendDevicePathNode,so free the memory it occupies.
|
|
|
|
//
|
2008-12-17 10:20:16 +01:00
|
|
|
FreePool (ScsiDevicePath);
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
if (ScsiIoDevice->DevicePath == NULL) {
|
2008-12-17 10:20:16 +01:00
|
|
|
FreePool (ScsiIoDevice);
|
2007-06-29 05:33:17 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&ScsiIoDevice->Handle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
ScsiIoDevice->DevicePath,
|
|
|
|
&gEfiScsiIoProtocolGuid,
|
|
|
|
&ScsiIoDevice->ScsiIo,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-12-18 06:28:26 +01:00
|
|
|
FreePool (ScsiIoDevice);
|
2007-07-02 04:40:39 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
2007-06-29 05:33:17 +02:00
|
|
|
} else {
|
2007-07-02 04:40:39 +02:00
|
|
|
if (ScsiBusDev->ExtScsiSupport) {
|
|
|
|
gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiExtScsiPassThruProtocolGuid,
|
|
|
|
(VOID **) &(ScsiBusDev->ExtScsiInterface),
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ScsiIoDevice->Handle,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiScsiPassThruProtocolGuid,
|
|
|
|
(VOID **) &(ScsiBusDev->ScsiInterface),
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
ScsiIoDevice->Handle,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
|
|
|
);
|
|
|
|
}
|
2007-06-29 05:33:17 +02:00
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
2007-07-02 04:40:39 +02:00
|
|
|
Discovery SCSI Device
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@param ScsiIoDevice The pointer of SCSI_IO_DEV
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@retval TRUE Find SCSI Device and verify it.
|
|
|
|
@retval FALSE Unable to find SCSI Device.
|
2007-06-29 05:33:17 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
DiscoverScsiDevice (
|
|
|
|
IN OUT SCSI_IO_DEV *ScsiIoDevice
|
|
|
|
)
|
2007-06-29 05:33:17 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 InquiryDataLength;
|
|
|
|
UINT8 SenseDataLength;
|
|
|
|
UINT8 HostAdapterStatus;
|
|
|
|
UINT8 TargetStatus;
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_SCSI_SENSE_DATA SenseData;
|
|
|
|
EFI_SCSI_INQUIRY_DATA InquiryData;
|
2007-06-29 05:33:17 +02:00
|
|
|
|
|
|
|
HostAdapterStatus = 0;
|
|
|
|
TargetStatus = 0;
|
|
|
|
//
|
|
|
|
// Using Inquiry command to scan for the device
|
|
|
|
//
|
|
|
|
InquiryDataLength = sizeof (EFI_SCSI_INQUIRY_DATA);
|
|
|
|
SenseDataLength = sizeof (EFI_SCSI_SENSE_DATA);
|
|
|
|
|
2007-08-14 09:58:32 +02:00
|
|
|
Status = ScsiInquiryCommand (
|
2007-06-29 05:33:17 +02:00
|
|
|
&ScsiIoDevice->ScsiIo,
|
2008-11-17 15:22:23 +01:00
|
|
|
EFI_TIMER_PERIOD_SECONDS (1),
|
2007-06-29 05:33:17 +02:00
|
|
|
(VOID *) &SenseData,
|
|
|
|
&SenseDataLength,
|
|
|
|
&HostAdapterStatus,
|
|
|
|
&TargetStatus,
|
|
|
|
(VOID *) &InquiryData,
|
|
|
|
&InquiryDataLength,
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Retrieved inquiry data successfully
|
|
|
|
//
|
|
|
|
if ((InquiryData.Peripheral_Qualifier != 0) &&
|
|
|
|
(InquiryData.Peripheral_Qualifier != 3)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InquiryData.Peripheral_Qualifier == 3) {
|
|
|
|
if (InquiryData.Peripheral_Type != 0x1f) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-09 11:30:52 +02:00
|
|
|
if (0x1e >= InquiryData.Peripheral_Type && InquiryData.Peripheral_Type >= 0xa) {
|
2007-06-29 05:33:17 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-06-29 05:33:17 +02:00
|
|
|
//
|
|
|
|
// valid device type and peripheral qualifier combination.
|
|
|
|
//
|
|
|
|
ScsiIoDevice->ScsiDeviceType = InquiryData.Peripheral_Type;
|
|
|
|
ScsiIoDevice->RemovableDevice = InquiryData.RMB;
|
|
|
|
if (InquiryData.Version == 0) {
|
|
|
|
ScsiIoDevice->ScsiVersion = 0;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// ANSI-approved version
|
|
|
|
//
|
|
|
|
ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData.Version & 0x03);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-07-02 04:40:39 +02:00
|
|
|
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
|
|
|
Convert EFI_SCSI_IO_SCSI_REQUEST_PACKET packet to EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet.
|
|
|
|
|
|
|
|
@param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
|
|
|
|
@param CommandPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
|
|
|
|
|
|
|
|
**/
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ScsiioToPassThruPacket (
|
|
|
|
IN EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet,
|
2008-11-12 02:30:58 +01:00
|
|
|
OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *CommandPacket
|
2007-07-02 04:40:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
//EFI 1.10 doesn't support Bi-Direction Command.
|
|
|
|
//
|
|
|
|
if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_BIDIRECTIONAL) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
ZeroMem (CommandPacket, sizeof (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));
|
|
|
|
|
|
|
|
CommandPacket->Timeout = Packet->Timeout;
|
|
|
|
CommandPacket->Cdb = Packet->Cdb;
|
|
|
|
CommandPacket->CdbLength = Packet->CdbLength;
|
|
|
|
CommandPacket->DataDirection = Packet->DataDirection;
|
|
|
|
CommandPacket->HostAdapterStatus = Packet->HostAdapterStatus;
|
|
|
|
CommandPacket->TargetStatus = Packet->TargetStatus;
|
|
|
|
CommandPacket->SenseData = Packet->SenseData;
|
|
|
|
CommandPacket->SenseDataLength = Packet->SenseDataLength;
|
|
|
|
|
|
|
|
if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_READ) {
|
|
|
|
CommandPacket->DataBuffer = Packet->InDataBuffer;
|
|
|
|
CommandPacket->TransferLength = Packet->InTransferLength;
|
|
|
|
} else if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_WRITE) {
|
|
|
|
CommandPacket->DataBuffer = Packet->OutDataBuffer;
|
|
|
|
CommandPacket->TransferLength = Packet->OutTransferLength;
|
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
|
|
|
Convert EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet to EFI_SCSI_IO_SCSI_REQUEST_PACKET packet.
|
|
|
|
|
|
|
|
@param ScsiPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
|
|
|
|
@param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
|
|
|
|
|
|
|
|
**/
|
2007-07-02 04:40:39 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PassThruToScsiioPacket (
|
|
|
|
IN EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ScsiPacket,
|
2008-11-12 02:30:58 +01:00
|
|
|
OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet
|
2007-07-02 04:40:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
Packet->Timeout = ScsiPacket->Timeout;
|
|
|
|
Packet->Cdb = ScsiPacket->Cdb;
|
|
|
|
Packet->CdbLength = ScsiPacket->CdbLength;
|
|
|
|
Packet->DataDirection = ScsiPacket->DataDirection;
|
|
|
|
Packet->HostAdapterStatus = ScsiPacket->HostAdapterStatus;
|
|
|
|
Packet->TargetStatus = ScsiPacket->TargetStatus;
|
|
|
|
Packet->SenseData = ScsiPacket->SenseData;
|
|
|
|
Packet->SenseDataLength = ScsiPacket->SenseDataLength;
|
|
|
|
|
|
|
|
if (ScsiPacket->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_READ) {
|
|
|
|
Packet->InDataBuffer = ScsiPacket->DataBuffer;
|
|
|
|
Packet->InTransferLength = ScsiPacket->TransferLength;
|
|
|
|
} else if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_WRITE) {
|
|
|
|
Packet->OutDataBuffer = ScsiPacket->DataBuffer;
|
|
|
|
Packet->OutTransferLength = ScsiPacket->TransferLength;
|
|
|
|
}
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
/**
|
|
|
|
Notify Function in which convert EFI1.0 PassThru Packet back to UEF2.0
|
|
|
|
SCSI IO Packet.
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
@param Event The instance of EFI_EVENT.
|
|
|
|
@param Context The parameter passed in.
|
2007-07-02 04:40:39 +02:00
|
|
|
|
2008-11-12 02:30:58 +01:00
|
|
|
**/
|
2007-07-02 04:40:39 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
NotifyFunction (
|
2008-11-12 02:30:58 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2007-07-02 04:40:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet;
|
|
|
|
EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ScsiPacket;
|
|
|
|
EFI_EVENT CallerEvent;
|
2007-07-17 03:48:09 +02:00
|
|
|
SCSI_EVENT_DATA *PassData;
|
2007-07-02 04:40:39 +02:00
|
|
|
|
|
|
|
PassData = (SCSI_EVENT_DATA*)Context;
|
|
|
|
Packet = (EFI_SCSI_IO_SCSI_REQUEST_PACKET *)PassData->Data1;
|
2008-11-12 02:30:58 +01:00
|
|
|
ScsiPacket = (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer;
|
2007-07-02 04:40:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Convert EFI1.0 PassThru packet to UEFI2.0 SCSI IO Packet.
|
|
|
|
//
|
|
|
|
PassThruToScsiioPacket(ScsiPacket, Packet);
|
2007-07-17 03:48:09 +02:00
|
|
|
|
2007-07-02 04:40:39 +02:00
|
|
|
//
|
|
|
|
// After converting EFI1.0 PassThru Packet back to UEFI2.0 SCSI IO Packet,
|
2008-11-12 02:30:58 +01:00
|
|
|
// free mWorkingBuffer.
|
2007-07-02 04:40:39 +02:00
|
|
|
//
|
2008-11-12 02:30:58 +01:00
|
|
|
gBS->FreePool(mWorkingBuffer);
|
2007-07-02 04:40:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Signal Event to tell caller to pick up UEFI2.0 SCSI IO Packet.
|
|
|
|
//
|
|
|
|
CallerEvent = PassData->Data2;
|
|
|
|
gBS->CloseEvent(Event);
|
|
|
|
gBS->SignalEvent(CallerEvent);
|
|
|
|
}
|
2008-11-12 02:30:58 +01:00
|
|
|
|