From: "Laszlo Ersek" <lersek@redhat.com>
To: Gary Lin <glin@suse.com>, devel@edk2.groups.io
Cc: Jordan Justen <jordan.l.justen@intel.com>,
Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: Re: [PATCH 07/11] OvmfPkg/LsiScsiDxe: Open PciIo protocol and initialize the device
Date: Tue, 7 Jul 2020 11:46:28 +0200 [thread overview]
Message-ID: <9c8fdc1c-998d-9817-db4e-31bffdc0fb50@redhat.com> (raw)
In-Reply-To: <20200701040448.14871-8-glin@suse.com>
On 07/01/20 06:04, Gary Lin wrote:
> Open PciIo protocol and use it to initialize the device. The
> initialization of LSI 53C895A is simple: just set the SRST bit in
> Interrupt Status Zero register to reset the device.
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Gary Lin <glin@suse.com>
> ---
> OvmfPkg/Include/IndustryStandard/LsiScsi.h | 21 ++++
> OvmfPkg/LsiScsiDxe/LsiScsi.c | 129 ++++++++++++++++++++-
> OvmfPkg/LsiScsiDxe/LsiScsi.h | 3 +
> 3 files changed, 152 insertions(+), 1 deletion(-)
>
> diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/IndustryStandard/LsiScsi.h
> index c09e864a1f39..60e527f1c6a7 100644
> --- a/OvmfPkg/Include/IndustryStandard/LsiScsi.h
> +++ b/OvmfPkg/Include/IndustryStandard/LsiScsi.h
> @@ -17,4 +17,25 @@
> #define LSI_LOGIC_PCI_VENDOR_ID 0x1000
> #define LSI_53C895A_PCI_DEVICE_ID 0x0012
>
> +//
> +// LSI 53C895A Registers
> +//
> +#define LSI_REG_DSTAT 0x0C
> +#define LSI_REG_ISTAT0 0x14
> +#define LSI_REG_DSP 0x2C
> +#define LSI_REG_SIST0 0x42
> +#define LSI_REG_SIST1 0x43
> +
> +//
> +// The status bits for Interrupt Status Zero (ISTAT0)
> +//
> +#define LSI_ISTAT0_DIP 0x01
> +#define LSI_ISTAT0_SIP 0x02
> +#define LSI_ISTAT0_INTF 0x04
> +#define LSI_ISTAT0_CON 0x08
> +#define LSI_ISTAT0_SEM 0x10
> +#define LSI_ISTAT0_SIGP 0x20
> +#define LSI_ISTAT0_SRST 0x40
> +#define LSI_ISTAT0_ABRT 0x80
(1) Please use the BIT0, BIT1, ... etc macros, which are more idiomatic
in edk2 than open-coded constants like 0x01, 0x02, ...
> +
> #endif // _LSI_SCSI_H_
> diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c
> index e10a81a5f9f7..f03774cc4ced 100644
> --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c
> +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c
> @@ -25,6 +25,33 @@
>
> #include "LsiScsi.h"
>
> +STATIC
> +EFI_STATUS
> +Out8 (
> + IN LSI_SCSI_DEV *Dev,
> + IN UINT32 Addr,
> + IN UINT8 Data
> + )
> +{
> + return Dev->PciIo->Io.Write (
> + Dev->PciIo,
> + EfiPciIoWidthUint8,
> + PCI_BAR_IDX0,
> + Addr,
> + 1,
> + &Data
> + );
> +}
> +
> +STATIC
> +EFI_STATUS
> +LsiScsiReset (
> + IN LSI_SCSI_DEV *Dev
> + )
> +{
> + return Out8 (Dev, LSI_REG_ISTAT0, LSI_ISTAT0_SRST);
> +}
> +
> //
> // 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,
> @@ -246,6 +273,21 @@ LsiScsiGetNextTarget (
> return EFI_NOT_FOUND;
> }
>
> +STATIC
> +VOID
> +EFIAPI
> +LsiScsiExitBoot (
> + IN EFI_EVENT Event,
> + IN VOID *Context
> + )
> +{
> + LSI_SCSI_DEV *Dev;
> +
> + Dev = Context;
> + DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));
> + LsiScsiReset (Dev);
> +}
> +
> //
> // Probe, start and stop functions of this driver, called by the DXE core for
> // specific devices.
> @@ -328,6 +370,58 @@ LsiScsiControllerStart (
> Dev->MaxTarget = PcdGet8 (PcdLsiScsiMaxTargetLimit);
> Dev->MaxLun = PcdGet8 (PcdLsiScsiMaxLunLimit);
>
> + Status = gBS->OpenProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + (VOID **)&Dev->PciIo,
> + This->DriverBindingHandle,
> + ControllerHandle,
> + EFI_OPEN_PROTOCOL_BY_DRIVER
> + );
> + if (EFI_ERROR (Status)) {
> + goto FreePool;
> + }
> +
> + Status = Dev->PciIo->Attributes (
> + Dev->PciIo,
> + EfiPciIoAttributeOperationGet,
> + 0,
> + &Dev->OrigPciAttrs
> + );
> + if (EFI_ERROR (Status)) {
> + goto CloseProtocol;
> + }
> +
> + //
> + // Enable I/O Space & Bus-Mastering
> + //
> + Status = Dev->PciIo->Attributes (
> + Dev->PciIo,
> + EfiPciIoAttributeOperationEnable,
> + (EFI_PCI_IO_ATTRIBUTE_IO |
> + EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),
> + NULL
> + );
> + if (EFI_ERROR (Status)) {
> + goto CloseProtocol;
> + }
> +
> + Status = LsiScsiReset (Dev);
> + if (EFI_ERROR (Status)) {
> + goto RestoreAttributes;
> + }
> +
> + Status = gBS->CreateEvent (
> + EVT_SIGNAL_EXIT_BOOT_SERVICES,
> + TPL_CALLBACK,
> + &LsiScsiExitBoot,
> + Dev,
> + &Dev->ExitBoot
> + );
> + if (EFI_ERROR (Status)) {
> + goto UninitDev;
> + }
> +
> //
> // Host adapter channel, doesn't exist
> //
> @@ -352,11 +446,33 @@ LsiScsiControllerStart (
> &Dev->PassThru
> );
> if (EFI_ERROR (Status)) {
> - goto FreePool;
> + goto CloseExitBoot;
> }
>
> return EFI_SUCCESS;
>
> +CloseExitBoot:
> + gBS->CloseEvent (Dev->ExitBoot);
> +
> +UninitDev:
> + LsiScsiReset (Dev);
> +
> +RestoreAttributes:
> + Dev->PciIo->Attributes (
> + Dev->PciIo,
> + EfiPciIoAttributeOperationSet,
> + Dev->OrigPciAttrs,
> + NULL
> + );
> +
> +CloseProtocol:
> + gBS->CloseProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + This->DriverBindingHandle,
> + ControllerHandle
> + );
> +
> FreePool:
> FreePool (Dev);
>
> @@ -399,6 +515,17 @@ LsiScsiControllerStop (
> return Status;
> }
>
> + gBS->CloseEvent (Dev->ExitBoot);
> +
> + LsiScsiReset (Dev);
> +
> + Dev->PciIo->Attributes (
> + Dev->PciIo,
> + EfiPciIoAttributeOperationSet,
> + Dev->OrigPciAttrs,
> + NULL
> + );
> +
> gBS->CloseProtocol (
> ControllerHandle,
> &gEfiPciIoProtocolGuid,
(2) So as I said under "[PATCH 05/11] OvmfPkg/LsiScsiDxe: Install
stubbed EXT_SCSI_PASS_THRU", this CloseProtocol() call should not be
"context" here (from patch 05/11); it should be introduced here,
reflecting the operations in LsiScsiControllerStart() that are also
introduced in this patch.
> diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h
> index a3d51d8f2386..ffaee6188536 100644
> --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h
> +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h
> @@ -14,6 +14,9 @@
>
> typedef struct {
> UINT32 Signature;
> + UINT64 OrigPciAttrs;
> + EFI_EVENT ExitBoot;
> + EFI_PCI_IO_PROTOCOL *PciIo;
> UINT8 MaxTarget;
> UINT8 MaxLun;
> EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
>
Thanks
Laszlo
next prev parent reply other threads:[~2020-07-07 9:46 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-01 4:04 [PATCH 00/11] Introduce LsiScsi driver to OvmfPkg Gary Lin
2020-07-01 4:04 ` [PATCH 01/11] OvmfPkg/LsiScsiDxe: Create the empty driver Gary Lin
2020-07-07 7:59 ` Laszlo Ersek
2020-07-07 8:24 ` Gary Lin
2020-07-01 4:04 ` [PATCH 02/11] OvmfPkg/LsiScsiDxe: Install the skeleton of driver binding Gary Lin
2020-07-07 8:06 ` Laszlo Ersek
2020-07-07 8:34 ` Gary Lin
2020-07-01 4:04 ` [PATCH 03/11] OvmfPkg/LsiScsiDxe: Report the name of the driver Gary Lin
2020-07-07 8:09 ` Laszlo Ersek
2020-07-01 4:04 ` [PATCH 04/11] OvmfPkg/LsiScsiDxe: Probe PCI devices and look for LsiScsi Gary Lin
2020-07-07 8:15 ` Laszlo Ersek
2020-07-07 8:16 ` Laszlo Ersek
2020-07-01 4:04 ` [PATCH 05/11] OvmfPkg/LsiScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Gary Lin
2020-07-07 8:28 ` Laszlo Ersek
2020-07-01 4:04 ` [PATCH 06/11] OvmfPkg/LsiScsiDxe: Report Targets and LUNs Gary Lin
2020-07-07 9:04 ` Laszlo Ersek
2020-07-08 2:34 ` Gary Lin
2020-07-08 15:26 ` Laszlo Ersek
2020-07-01 4:04 ` [PATCH 07/11] OvmfPkg/LsiScsiDxe: Open PciIo protocol and initialize the device Gary Lin
2020-07-07 9:46 ` Laszlo Ersek [this message]
2020-07-08 2:37 ` Gary Lin
2020-07-01 4:04 ` [PATCH 08/11] OvmfPkg/LsiScsiDxe: Map DMA buffer Gary Lin
2020-07-07 9:59 ` Laszlo Ersek
2020-07-08 2:41 ` Gary Lin
2020-07-01 4:04 ` [PATCH 09/11] OvmfPkg/LsiScsiDxe: Examine the incoming SCSI Request Packet Gary Lin
2020-07-07 10:17 ` Laszlo Ersek
2020-07-08 2:43 ` Gary Lin
2020-07-01 4:04 ` [PATCH 10/11] OvmfPkg/LsiScsiDxe: Process the " Gary Lin
2020-07-07 12:46 ` Laszlo Ersek
2020-07-08 6:02 ` Gary Lin
[not found] ` <161FB1B03BD2D339.11266@groups.io>
2020-07-14 8:19 ` [edk2-devel] " Gary Lin
2020-07-01 4:04 ` [PATCH 11/11] Maintainers.txt: Add myself as the reviewer for LsiScsi driver Gary Lin
2020-07-07 12:49 ` Laszlo Ersek
2020-07-08 6:03 ` Gary Lin
2020-07-03 14:08 ` [edk2-devel] [PATCH 00/11] Introduce LsiScsi driver to OvmfPkg Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9c8fdc1c-998d-9817-db4e-31bffdc0fb50@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox