Skip to content

Commit

Permalink
OvmfPkg/LsiScsiDxe: Install stubbed EXT_SCSI_PASS_THRU
Browse files Browse the repository at this point in the history
Partially implement LsiScsiControllerStart() and LsiScsiControllerStop()
to insert the scaffolding of EXT_SCSI_PASS_THRU functions.

v3: Squash the newline below the declaration of LSI_SCSI_FROM_PASS_THRU
v2: Remove the closing of PciIo protocol from LsiScsiControllerStop().

Cc: Jordan Justen <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Signed-off-by: Gary Lin <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
lcp authored and mergify[bot] committed Jul 17, 2020
1 parent 79f802a commit 23d982e
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 1 deletion.
164 changes: 163 additions & 1 deletion OvmfPkg/LsiScsiDxe/LsiScsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,105 @@

#include <IndustryStandard/LsiScsi.h>
#include <IndustryStandard/Pci.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/PciIo.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/ScsiPassThruExt.h>
#include <Uefi/UefiSpec.h>

#include "LsiScsi.h"

//
// The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL
// for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata C,
// sections
// - 14.1 SCSI Driver Model Overview,
// - 14.7 Extended SCSI Pass Thru Protocol.
//

EFI_STATUS
EFIAPI
LsiScsiPassThru (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
IN EFI_EVENT Event OPTIONAL
)
{
return EFI_UNSUPPORTED;
}

EFI_STATUS
EFIAPI
LsiScsiGetNextTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN OUT UINT8 **TargetPointer,
IN OUT UINT64 *Lun
)
{
return EFI_NOT_FOUND;
}

EFI_STATUS
EFIAPI
LsiScsiBuildDevicePath (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
)
{
return EFI_NOT_FOUND;
}

EFI_STATUS
EFIAPI
LsiScsiGetTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT UINT8 **TargetPointer,
OUT UINT64 *Lun
)
{
return EFI_UNSUPPORTED;
}

EFI_STATUS
EFIAPI
LsiScsiResetChannel (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
)
{
return EFI_UNSUPPORTED;
}

EFI_STATUS
EFIAPI
LsiScsiResetTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun
)
{
return EFI_UNSUPPORTED;
}

EFI_STATUS
EFIAPI
LsiScsiGetNextTarget (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN OUT UINT8 **TargetPointer
)
{
return EFI_NOT_FOUND;
}

//
// Probe, start and stop functions of this driver, called by the DXE core for
// specific devices.
Expand Down Expand Up @@ -88,7 +179,49 @@ LsiScsiControllerStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
LSI_SCSI_DEV *Dev;

Dev = AllocateZeroPool (sizeof (*Dev));
if (Dev == NULL) {
return EFI_OUT_OF_RESOURCES;
}

Dev->Signature = LSI_SCSI_DEV_SIGNATURE;

//
// Host adapter channel, doesn't exist
//
Dev->PassThruMode.AdapterId = MAX_UINT32;
Dev->PassThruMode.Attributes =
EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL |
EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;

Dev->PassThru.Mode = &Dev->PassThruMode;
Dev->PassThru.PassThru = &LsiScsiPassThru;
Dev->PassThru.GetNextTargetLun = &LsiScsiGetNextTargetLun;
Dev->PassThru.BuildDevicePath = &LsiScsiBuildDevicePath;
Dev->PassThru.GetTargetLun = &LsiScsiGetTargetLun;
Dev->PassThru.ResetChannel = &LsiScsiResetChannel;
Dev->PassThru.ResetTargetLun = &LsiScsiResetTargetLun;
Dev->PassThru.GetNextTarget = &LsiScsiGetNextTarget;

Status = gBS->InstallProtocolInterface (
&ControllerHandle,
&gEfiExtScsiPassThruProtocolGuid,
EFI_NATIVE_INTERFACE,
&Dev->PassThru
);
if (EFI_ERROR (Status)) {
goto FreePool;
}

return EFI_SUCCESS;

FreePool:
FreePool (Dev);

return Status;
}

EFI_STATUS
Expand All @@ -100,7 +233,36 @@ LsiScsiControllerStop (
IN EFI_HANDLE *ChildHandleBuffer
)
{
return EFI_SUCCESS;
EFI_STATUS Status;
EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;
LSI_SCSI_DEV *Dev;

Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiExtScsiPassThruProtocolGuid,
(VOID **)&PassThru,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL // Lookup only
);
if (EFI_ERROR (Status)) {
return Status;
}

Dev = LSI_SCSI_FROM_PASS_THRU (PassThru);

Status = gBS->UninstallProtocolInterface (
ControllerHandle,
&gEfiExtScsiPassThruProtocolGuid,
&Dev->PassThru
);
if (EFI_ERROR (Status)) {
return Status;
}

FreePool (Dev);

return Status;
}

//
Expand Down
78 changes: 78 additions & 0 deletions OvmfPkg/LsiScsiDxe/LsiScsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
#ifndef _LSI_SCSI_DXE_H_
#define _LSI_SCSI_DXE_H_

typedef struct {
UINT32 Signature;
EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
} LSI_SCSI_DEV;

#define LSI_SCSI_DEV_SIGNATURE SIGNATURE_32 ('L','S','I','S')

#define LSI_SCSI_FROM_PASS_THRU(PassThruPtr) \
CR (PassThruPtr, LSI_SCSI_DEV, PassThru, LSI_SCSI_DEV_SIGNATURE)


//
// Probe, start and stop functions of this driver, called by the DXE core for
// specific devices.
Expand Down Expand Up @@ -47,6 +59,72 @@ LsiScsiControllerStop (
);


//
// The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL
// for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata C,
// sections
// - 14.1 SCSI Driver Model Overview,
// - 14.7 Extended SCSI Pass Thru Protocol.
//

EFI_STATUS
EFIAPI
LsiScsiPassThru (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
IN EFI_EVENT Event OPTIONAL
);

EFI_STATUS
EFIAPI
LsiScsiGetNextTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN OUT UINT8 **TargetPointer,
IN OUT UINT64 *Lun
);

EFI_STATUS
EFIAPI
LsiScsiBuildDevicePath (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
);

EFI_STATUS
EFIAPI
LsiScsiGetTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT UINT8 **TargetPointer,
OUT UINT64 *Lun
);

EFI_STATUS
EFIAPI
LsiScsiResetChannel (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
);

EFI_STATUS
EFIAPI
LsiScsiResetTargetLun (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN UINT8 *Target,
IN UINT64 Lun
);

EFI_STATUS
EFIAPI
LsiScsiGetNextTarget (
IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
IN OUT UINT8 **TargetPointer
);


//
// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
Expand Down
3 changes: 3 additions & 0 deletions OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

[LibraryClasses]
BaseLib
BaseMemoryLib
MemoryAllocationLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib

[Protocols]
gEfiExtScsiPassThruProtocolGuid ## BY_START
gEfiPciIoProtocolGuid ## TO_START

0 comments on commit 23d982e

Please sign in to comment.