On 02/26/20 17:41, Nikita Leshenko wrote:
> 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
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshche...@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.w...@oracle.com>
> Reviewed-by: Aaron Young <aaron.yo...@oracle.com>
> Reviewed-by: Liran Alon <liran.a...@oracle.com>
> ---
>  .../Include/IndustryStandard/FusionMptScsi.h  | 24 +++++++++
>  OvmfPkg/MptScsiDxe/MptScsi.c                  | 50 ++++++++++++++++++-
>  OvmfPkg/MptScsiDxe/MptScsiDxe.inf             |  6 +++
>  3 files changed, 79 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 0000000000..3b911bdb5b
> --- /dev/null
> +++ b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
> @@ -0,0 +1,24 @@
> +/** @file
> +
> +    Macros and type definitions for LSI Fusion MPT SCSI devices.
> +
> +    Copyright (C) 2020, Oracle and/or its affiliates. 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.
> +
> +**/
> +
> +//
> +// Device offsets and constants
> +//
> +
> +#define LSI_LOGIC_PCI_VENDOR_ID 0x1000

Matches PCI_VENDOR_ID_LSI_LOGIC from QEMU's "include/hw/pci/pci_ids.h". OK.

> +#define LSI_53C1030_PCI_DEVICE_ID 0x0030

Not sure about this one; possibly implemented by a different hypervisor.
But that should be OK.

> +#define LSI_SAS1068_PCI_DEVICE_ID 0x0054

matches PCI_DEVICE_ID_LSI_SAS1068

> +#define LSI_SAS1068E_PCI_DEVICE_ID 0x0058

Also from another hypervisor, I'd guess; OK.

> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index 40194b5ead..6dc6257eba 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -15,7 +15,12 @@
>  
>  **/
>  
> +#include <IndustryStandard/Pci.h>
> +#include <IndustryStandard/FusionMptScsi.h>
> +#include <Library/DebugLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
>  #include <Library/UefiLib.h>
> +#include <Protocol/PciIo.h>

(1) Please keep #include directives sorted.

>  
>  //
>  // Higher versions will be used before lower, 0x10-0xffffffef is the version
> @@ -36,7 +41,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 4b1a23c33a..dc3795c867 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> +++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> @@ -27,7 +27,13 @@
>  
>  [Packages]
>    MdePkg/MdePkg.dec
> +  OvmfPkg/OvmfPkg.dec
>  
>  [LibraryClasses]
> +  DebugLib
> +  UefiBootServicesTableLib
>    UefiDriverEntryPoint
>    UefiLib
> +
> +[Protocols]
> +  gEfiPciIoProtocolGuid        ## TO_START
> 

We don't necessarily have to pull in DebugLib in this patch, but it's
also harmless.

With (1) addressed:

Reviewed-by: Laszlo Ersek <ler...@redhat.com>

Thanks
Laszlo


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55055): https://edk2.groups.io/g/devel/message/55055
Mute This Topic: https://groups.io/mt/71570011/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to