From f47074425d2ecdd03cb651cc218b88226ad4a0fb Mon Sep 17 00:00:00 2001 From: Nikita Leshenko Date: Tue, 5 May 2020 00:05:59 +0300 Subject: OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi The MptScsiControllerSupported function is called on handles passed in by the ConnectController() boot service and if the handle is the lsi53c1030 controller the function would return success. A successful return value will attach our driver to the device. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390 Signed-off-by: Nikita Leshenko Reviewed-by: Laszlo Ersek Reviewed-by: Liran Alon Message-Id: <20200504210607.144434-5-nikita.leshchenko@oracle.com> --- OvmfPkg/Include/IndustryStandard/FusionMptScsi.h | 23 +++++++++++ OvmfPkg/MptScsiDxe/MptScsi.c | 49 +++++++++++++++++++++++- OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 5 +++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Include/IndustryStandard/FusionMptScsi.h diff --git a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h new file mode 100644 index 0000000..df9bdc2 --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h @@ -0,0 +1,23 @@ +/** @file + + Macros and type definitions for LSI Fusion MPT SCSI devices. + + Copyright (C) 2020, Oracle and/or its affiliates. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __FUSION_MPT_SCSI_H__ +#define __FUSION_MPT_SCSI_H__ + +// +// Device offsets and constants +// + +#define LSI_LOGIC_PCI_VENDOR_ID 0x1000 +#define LSI_53C1030_PCI_DEVICE_ID 0x0030 +#define LSI_SAS1068_PCI_DEVICE_ID 0x0054 +#define LSI_SAS1068E_PCI_DEVICE_ID 0x0058 + +#endif // __FUSION_MPT_SCSI_H__ diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c index 64949a8..4e2f8f2 100644 --- a/OvmfPkg/MptScsiDxe/MptScsi.c +++ b/OvmfPkg/MptScsiDxe/MptScsi.c @@ -9,7 +9,11 @@ **/ +#include +#include +#include #include +#include #include // @@ -31,7 +35,50 @@ MptScsiControllerSupported ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + EFI_PCI_IO_PROTOCOL *PciIo; + PCI_TYPE00 Pci; + + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + (VOID **)&PciIo, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint32, + 0, + sizeof (Pci) / sizeof (UINT32), + &Pci + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + if (Pci.Hdr.VendorId == LSI_LOGIC_PCI_VENDOR_ID && + (Pci.Hdr.DeviceId == LSI_53C1030_PCI_DEVICE_ID || + Pci.Hdr.DeviceId == LSI_SAS1068_PCI_DEVICE_ID || + Pci.Hdr.DeviceId == LSI_SAS1068E_PCI_DEVICE_ID)) { + Status = EFI_SUCCESS; + } else { + Status = EFI_UNSUPPORTED; + } + +Done: + gBS->CloseProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + return Status; } STATIC diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf index 5358506..414b96e 100644 --- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf +++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf @@ -21,7 +21,12 @@ [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [LibraryClasses] + UefiBootServicesTableLib UefiDriverEntryPoint UefiLib + +[Protocols] + gEfiPciIoProtocolGuid ## TO_START -- cgit v1.1