public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
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 08/11] OvmfPkg/LsiScsiDxe: Map DMA buffer
Date: Tue, 7 Jul 2020 11:59:57 +0200	[thread overview]
Message-ID: <e551ffa1-2e41-38f7-fa1a-2dcb1ac2f002@redhat.com> (raw)
In-Reply-To: <20200701040448.14871-9-glin@suse.com>

On 07/01/20 06:04, Gary Lin wrote:
> Map DMA buffer and perpare for the implementation of LsiScsiPassThru().
> 
> 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/LsiScsiDxe/LsiScsi.c | 85 +++++++++++++++++++++++++++++++++++-
>  OvmfPkg/LsiScsiDxe/LsiScsi.h | 10 +++++
>  2 files changed, 94 insertions(+), 1 deletion(-)
> 
> diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c
> index f03774cc4ced..b728d18d51df 100644
> --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c
> +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c
> @@ -359,6 +359,8 @@ LsiScsiControllerStart (
>  {
>    EFI_STATUS           Status;
>    LSI_SCSI_DEV         *Dev;
> +  UINTN                Pages;
> +  UINTN                BytesMapped;
>  
>    Dev = AllocateZeroPool (sizeof (*Dev));
>    if (Dev == NULL) {
> @@ -406,11 +408,68 @@ LsiScsiControllerStart (
>      goto CloseProtocol;
>    }
>  
> -  Status = LsiScsiReset (Dev);
> +  //
> +  // Signal device supports 64-bit DMA addresses
> +  //
> +  Status = Dev->PciIo->Attributes (
> +                         Dev->PciIo,
> +                         EfiPciIoAttributeOperationEnable,
> +                         EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
> +                         NULL
> +                         );
> +  if (EFI_ERROR (Status)) {
> +    //
> +    // Warn user that device will only be using 32-bit DMA addresses.
> +    //
> +    // Note that this does not prevent the device/driver from working
> +    // and therefore we only warn and continue as usual.
> +    //
> +    DEBUG ((
> +      DEBUG_WARN,
> +      "%a: failed to enable 64-bit DMA addresses\n",
> +      __FUNCTION__
> +      ));
> +  }
> +
> +  //
> +  // Create buffers for data transfer
> +  //
> +  Pages = EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma));
> +  Status = Dev->PciIo->AllocateBuffer (
> +                         Dev->PciIo,
> +                         AllocateAnyPages,
> +                         EfiBootServicesData,
> +                         Pages,
> +                         (VOID **)&Dev->Dma,
> +                         EFI_PCI_ATTRIBUTE_MEMORY_CACHED
> +                         );
>    if (EFI_ERROR (Status)) {
>      goto RestoreAttributes;
>    }
>  
> +  BytesMapped = EFI_PAGES_TO_SIZE (Pages);
> +  Status = Dev->PciIo->Map (
> +                         Dev->PciIo,
> +                         EfiPciIoOperationBusMasterCommonBuffer,
> +                         Dev->Dma,
> +                         &BytesMapped,
> +                         &Dev->DmaPhysical,
> +                         &Dev->DmaMapping
> +                         );
> +  if (EFI_ERROR (Status)) {
> +    goto FreeBuffer;
> +  }
> +
> +  if (BytesMapped != EFI_PAGES_TO_SIZE (Pages)) {
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto Unmap;
> +  }
> +
> +  Status = LsiScsiReset (Dev);
> +  if (EFI_ERROR (Status)) {
> +    goto Unmap;
> +  }
> +
>    Status = gBS->CreateEvent (
>                    EVT_SIGNAL_EXIT_BOOT_SERVICES,
>                    TPL_CALLBACK,
> @@ -457,6 +516,19 @@ CloseExitBoot:
>  UninitDev:
>    LsiScsiReset (Dev);
>  
> +Unmap:
> +  Dev->PciIo->Unmap (
> +                Dev->PciIo,
> +                Dev->DmaMapping
> +                );
> +
> +FreeBuffer:
> +  Dev->PciIo->FreeBuffer (
> +                Dev->PciIo,
> +                Pages,
> +                Dev->Dma
> +                );
> +
>  RestoreAttributes:
>    Dev->PciIo->Attributes (
>                  Dev->PciIo,
> @@ -519,6 +591,17 @@ LsiScsiControllerStop (
>  
>    LsiScsiReset (Dev);
>  
> +  Dev->PciIo->Unmap (
> +                Dev->PciIo,
> +                Dev->DmaMapping
> +                );
> +
> +  Dev->PciIo->FreeBuffer (
> +                Dev->PciIo,
> +                EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma)),
> +                Dev->Dma
> +                );
> +
>    Dev->PciIo->Attributes (
>                  Dev->PciIo,
>                  EfiPciIoAttributeOperationSet,
> diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h
> index ffaee6188536..1e4bbc56f933 100644
> --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h
> +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h
> @@ -12,6 +12,13 @@
>  #ifndef _LSI_SCSI_DXE_H_
>  #define _LSI_SCSI_DXE_H_
>  
> +typedef struct {
> +  //
> +  // Allocate 64KB for read/write buffer.
> +  //
> +  UINT8                           Data[0x10000];

(1) Using SIZE_64KB for the size would be more idiomatic.

(2) Please add a comment that limiting the transfer size to 64KB seems
OK in practice.

With those updates:

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

Thanks
Laszlo

> +} LSI_SCSI_DMA_BUFFER;
> +
>  typedef struct {
>    UINT32                          Signature;
>    UINT64                          OrigPciAttrs;
> @@ -19,6 +26,9 @@ typedef struct {
>    EFI_PCI_IO_PROTOCOL             *PciIo;
>    UINT8                           MaxTarget;
>    UINT8                           MaxLun;
> +  LSI_SCSI_DMA_BUFFER             *Dma;
> +  EFI_PHYSICAL_ADDRESS            DmaPhysical;
> +  VOID                            *DmaMapping;
>    EFI_EXT_SCSI_PASS_THRU_MODE     PassThruMode;
>    EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
>  } LSI_SCSI_DEV;
> 


  reply	other threads:[~2020-07-07 10:00 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
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 [this message]
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=e551ffa1-2e41-38f7-fa1a-2dcb1ac2f002@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