From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web10.13146.1594116011792544876 for ; Tue, 07 Jul 2020 03:00:11 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AOJz6DVd; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594116011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OSRmB92lKt9I91up+24GgMqSZrf0A71ALE1tqOcg7WU=; b=AOJz6DVd12IgcJmnCxvWTBd3lWomScvG+17sFm/EEejp1r5jtrXC67m9aWgkjWghpl527r uBRPkGmZIiWS6FU+qSzg89Lz+6VofkpbybL2WQXl+dykvR+n0anXIPlmrviKoihn8jsWTF jQyrTad8f9tLz1NjdiynkM1QZrPTIts= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338--kApqGjgPT-N8ROz2JjGQQ-1; Tue, 07 Jul 2020 06:00:07 -0400 X-MC-Unique: -kApqGjgPT-N8ROz2JjGQQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A0E918FE873; Tue, 7 Jul 2020 09:59:59 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-90.ams2.redhat.com [10.36.114.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 461EF60C87; Tue, 7 Jul 2020 09:59:58 +0000 (UTC) Subject: Re: [PATCH 08/11] OvmfPkg/LsiScsiDxe: Map DMA buffer To: Gary Lin , devel@edk2.groups.io Cc: Jordan Justen , Ard Biesheuvel References: <20200701040448.14871-1-glin@suse.com> <20200701040448.14871-9-glin@suse.com> From: "Laszlo Ersek" Message-ID: Date: Tue, 7 Jul 2020 11:59:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200701040448.14871-9-glin@suse.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 07/01/20 06:04, Gary Lin wrote: > Map DMA buffer and perpare for the implementation of LsiScsiPassThru(). > > Cc: Jordan Justen > Cc: Laszlo Ersek > Cc: Ard Biesheuvel > Signed-off-by: Gary Lin > --- > 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 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; >