From 79f802a50ee942e297c86138e6c19cab77a3a2eb Mon Sep 17 00:00:00 2001 From: Gary Lin Date: Fri, 17 Jul 2020 14:11:23 +0800 Subject: [PATCH] OvmfPkg/LsiScsiDxe: Probe PCI devices and look for LsiScsi Implement LsiScsiControllerSupported() to probe the PCI ID and look for LSI 53C895A. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin Reviewed-by: Laszlo Ersek Message-Id: <20200717061130.8881-5-glin@suse.com> --- OvmfPkg/Include/IndustryStandard/LsiScsi.h | 20 +++++++++ OvmfPkg/LsiScsiDxe/LsiScsi.c | 48 +++++++++++++++++++++- OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf | 6 +++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Include/IndustryStandard/LsiScsi.h diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/IndustryStandard/LsiScsi.h new file mode 100644 index 0000000000..c09e864a1f --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/LsiScsi.h @@ -0,0 +1,20 @@ +/** @file + + Macros and type definitions for LSI 53C895A SCSI devices. + + Copyright (C) 2020, SUSE LLC. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _LSI_SCSI_H_ +#define _LSI_SCSI_H_ + +// +// Device ID +// +#define LSI_LOGIC_PCI_VENDOR_ID 0x1000 +#define LSI_53C895A_PCI_DEVICE_ID 0x0012 + +#endif // _LSI_SCSI_H_ diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index 62daa3ab99..5bca85bd75 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -9,7 +9,12 @@ **/ +#include +#include +#include #include +#include +#include #include #include "LsiScsi.h" @@ -31,7 +36,48 @@ LsiScsiControllerSupported ( 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_53C895A_PCI_DEVICE_ID) { + Status = EFI_SUCCESS; + } else { + Status = EFI_UNSUPPORTED; + } + +Done: + gBS->CloseProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + return Status; } EFI_STATUS diff --git a/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf b/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf index 5cb15c4565..7ce11fcc6a 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf +++ b/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf @@ -22,7 +22,13 @@ [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [LibraryClasses] + BaseLib + UefiBootServicesTableLib UefiDriverEntryPoint UefiLib + +[Protocols] + gEfiPciIoProtocolGuid ## TO_START -- 2.39.2