public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gary Lin" <glin@suse.com>
To: devel@edk2.groups.io
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Laszlo Ersek <lersek@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: [PATCH v2 08/12] OvmfPkg/LsiScsiDxe: Map DMA buffer
Date: Thu, 16 Jul 2020 15:46:03 +0800	[thread overview]
Message-ID: <20200716074607.18048-9-glin@suse.com> (raw)
In-Reply-To: <20200716074607.18048-1-glin@suse.com>

Map DMA buffer and perpare for the implementation of LsiScsiPassThru().

v2:
  - Replace 0x10000 with SIZE_64KB macro for the DMA buffer data array
  - Remove DUAL_ADDRESS_CYCLE from PciIo since we don't really need
    64-bit DMA address

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>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/LsiScsiDxe/LsiScsi.c | 62 +++++++++++++++++++++++++++++++++++-
 OvmfPkg/LsiScsiDxe/LsiScsi.h | 14 ++++++++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c
index b21387db6e5a..4e84afa40085 100644
--- a/OvmfPkg/LsiScsiDxe/LsiScsi.c
+++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c
@@ -356,6 +356,8 @@ LsiScsiControllerStart (
 {
   EFI_STATUS           Status;
   LSI_SCSI_DEV         *Dev;
+  UINTN                Pages;
+  UINTN                BytesMapped;
 
   Dev = AllocateZeroPool (sizeof (*Dev));
   if (Dev == NULL) {
@@ -411,11 +413,45 @@ LsiScsiControllerStart (
     goto CloseProtocol;
   }
 
-  Status = LsiScsiReset (Dev);
+  //
+  // 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,
@@ -462,6 +498,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,
@@ -524,6 +573,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 8c2acff6e86f..9f9e5c7fed00 100644
--- a/OvmfPkg/LsiScsiDxe/LsiScsi.h
+++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h
@@ -12,6 +12,17 @@
 #ifndef _LSI_SCSI_DXE_H_
 #define _LSI_SCSI_DXE_H_
 
+typedef struct {
+  //
+  // Allocate 64KB for read/write buffer. It seems sufficient for the common
+  // boot scenarios.
+  //
+  // NOTE: The number of bytes for data transmission is bounded by DMA Byte
+  //       Count (DBC), a 24-bit register, so the maximum is 0xFFFFFF (16MB-1).
+  //
+  UINT8                           Data[SIZE_64KB];
+} LSI_SCSI_DMA_BUFFER;
+
 typedef struct {
   UINT32                          Signature;
   UINT64                          OrigPciAttrs;
@@ -19,6 +30,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;
-- 
2.25.1


  parent reply	other threads:[~2020-07-16  7:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16  7:45 [PATCH v2 00/12] Introduce LsiScsi driver to OvmfPkg Gary Lin
2020-07-16  7:45 ` [PATCH v2 01/12] OvmfPkg/LsiScsiDxe: Create the empty driver Gary Lin
2020-07-16  7:45 ` [PATCH v2 02/12] OvmfPkg/LsiScsiDxe: Install the skeleton of driver binding Gary Lin
2020-07-16  7:45 ` [PATCH v2 03/12] OvmfPkg/LsiScsiDxe: Report the name of the driver Gary Lin
2020-07-16  7:45 ` [PATCH v2 04/12] OvmfPkg/LsiScsiDxe: Probe PCI devices and look for LsiScsi Gary Lin
2020-07-16  7:46 ` [PATCH v2 05/12] OvmfPkg/LsiScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Gary Lin
2020-07-16  7:46 ` [PATCH v2 06/12] OvmfPkg/LsiScsiDxe: Report Targets and LUNs Gary Lin
2020-07-16 15:04   ` Laszlo Ersek
2020-07-16 16:19     ` Laszlo Ersek
2020-07-16  7:46 ` [PATCH v2 07/12] OvmfPkg/LsiScsiDxe: Open PciIo protocol and initialize the device Gary Lin
2020-07-16 16:07   ` Laszlo Ersek
2020-07-16  7:46 ` Gary Lin [this message]
2020-07-16 16:11   ` [PATCH v2 08/12] OvmfPkg/LsiScsiDxe: Map DMA buffer Laszlo Ersek
2020-07-16  7:46 ` [PATCH v2 09/12] OvmfPkg/LsiScsiDxe: Examine the incoming SCSI Request Packet Gary Lin
2020-07-16  7:46 ` [PATCH v2 10/12] OvmfPkg/LsiScsiDxe: Process the " Gary Lin
2020-07-16 17:37   ` Laszlo Ersek
2020-07-17  2:28     ` Gary Lin
2020-07-16  7:46 ` [PATCH v2 11/12] OvmfPkg/LsiScsiDxe: Calculate the transferred bytes Gary Lin
2020-07-16 18:21   ` Laszlo Ersek
2020-07-17  3:15     ` Gary Lin
2020-07-16  7:46 ` [PATCH v2 12/12] Maintainers.txt: Add Gary Lin as the reviewer for LsiScsi driver Gary Lin

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=20200716074607.18048-9-glin@suse.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