From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [62.140.7.102]) by mx.groups.io with SMTP id smtpd.web10.2915.1594176082137906483 for ; Tue, 07 Jul 2020 19:41:22 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=I/WGSwdf; spf=pass (domain: suse.com, ip: 62.140.7.102, mailfrom: glin@suse.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1594176080; 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: in-reply-to:in-reply-to:references:references; bh=iGfXYII1FySUq3qsGE1oh1xGp2PcMj1gbA2yT+ZXBX4=; b=I/WGSwdf3lUtPkltFT4Ajimf9xvlI6Hm8TOS80mOcogRiz1fQV07hCL6GbFhqoPeBoCZ6C GM0QGLZHAyz5rz/ZROVO6c4VeOkJ57JgTrfsWW+NUB9pKT6MzcQNQIdAa4dJP9wS7LhL3r BMsBlVRh1rfty8C7pSIsTb4dH1wJwuU= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2055.outbound.protection.outlook.com [104.47.13.55]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-12-vxp8HZTSM8KN_B7HHG7x8w-1; Wed, 08 Jul 2020 04:41:19 +0200 X-MC-Unique: vxp8HZTSM8KN_B7HHG7x8w-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uv8GHJh/0L8FWDJy0o72s2UUSYv5mOO+j9jzN/BZh3ak+w7CDtufUqWNKtGQNOCM/holKRApT8mFTp1EaPlw1B56tkmJ50Fpul3juE87/6+ExDccmNQZH53NuD/Hotc+ZB8G323IAMalsqax8V8uM1/azqIq+1YqKIWC5zgjhUsx1yNCD6ATroXOUbG3tiOWzpsSVyW6e+ZW3agk6YrnWWvgV/UtRElEQ0fCzxq8A54Ox0Oh/mNSBR6mgzqoBm64OvaS1rWolt1+UGmoG6A0NuMuFt5tdSxNp3keiuiO2RVxjPjI1no8uG333XGjyVBoD8Rc3NHTGM5rwqzcnePJww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iGfXYII1FySUq3qsGE1oh1xGp2PcMj1gbA2yT+ZXBX4=; b=K5f6jelYiIWO9y0R1HJpFN5Uk5iLbCFB5CwTKH1SlIrEsb8b2QMBwPV4nvVt7gjFneBFY0A5dR2mfHv9eb+sHNW65MrAaV/QfGgY3hU3lGKTxjmudHBN//LEecmxKYeImxzzaSFgjLc1CS0ihLKNCuRveDo8fFmu5HzaKiVke+jfY1G4BNHQgMnfnzTZXnGdAZ27nrqejUIYyQNIab+Y/wtpkvJf5/nCm0BpICjVe+xaudRV9qmVayF6b1Xr/QXXjfI+YNLepjyWCeuhGUZQr0op+rFDHicg4Bemk8t9ASZneIG3KlYV3sdnw/sY+TKoo/DNiRIwYTIN6E/7Tg/loA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3824.eurprd04.prod.outlook.com (2603:10a6:803:22::18) by VI1PR0401MB2253.eurprd04.prod.outlook.com (2603:10a6:800:26::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.27; Wed, 8 Jul 2020 02:41:17 +0000 Received: from VI1PR0402MB3824.eurprd04.prod.outlook.com ([fe80::3854:92a5:f662:2def]) by VI1PR0402MB3824.eurprd04.prod.outlook.com ([fe80::3854:92a5:f662:2def%6]) with mapi id 15.20.3153.029; Wed, 8 Jul 2020 02:41:17 +0000 Date: Wed, 8 Jul 2020 10:41:07 +0800 From: "Gary Lin" To: Laszlo Ersek Cc: devel@edk2.groups.io, Jordan Justen , Ard Biesheuvel Subject: Re: [PATCH 08/11] OvmfPkg/LsiScsiDxe: Map DMA buffer Message-ID: <20200708024107.GR18504@GaryWorkstation> References: <20200701040448.14871-1-glin@suse.com> <20200701040448.14871-9-glin@suse.com> In-Reply-To: X-ClientProxiedBy: FR2P281CA0013.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::23) To VI1PR0402MB3824.eurprd04.prod.outlook.com (2603:10a6:803:22::18) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation (60.251.47.115) by FR2P281CA0013.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.14 via Frontend Transport; Wed, 8 Jul 2020 02:41:14 +0000 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: edc31623-675a-40cf-051f-08d822e86304 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2253: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PMN1PKJZN+HL12IPuBEvv2f8vtDBuIkgAyj+qoqXejCVMACL87ZxKwjs7HzYM8sTMTMT5jLj8oP3T4BhqrihFtfQG+FT8P05NMJpK870QTodfqcdvGEpwiyQC7e5DBxiyRrvcK67glTZlyjGIPHRr+0fm79c8rPMuClFvI6qAhU0I0nmgE1/SR333oNAMkFZxO5/EejpUB7Q+e798Cj3Uj+dKWqHSXGV3X9mXeK1f7B+ekMi2yyOS39stcKB8Ldzf/wUJbz0gTZtVmXcoqCc+9Ek+Oc1yYh1TYazJELWk5dmSj8zXwHFjQ40964r3kmadDN+lq4yZTEqQXKeh6FmFg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3824.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(376002)(396003)(39850400004)(366004)(346002)(136003)(9686003)(54906003)(6916009)(316002)(1076003)(8676002)(6666004)(33656002)(5660300002)(2906002)(83380400001)(6496006)(66946007)(52116002)(16526019)(55236004)(53546011)(66556008)(66476007)(26005)(4326008)(186003)(8936002)(478600001)(55016002)(956004)(86362001)(33716001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uFxK7AJIpG7T7IeyuyBLv73pbRWrG8byZWiyqIVNxTa9kPNIALeq5QDqujsW3c5i0Rd/Uf+smUgfY+jz8FM6M3LtwzNPqRIIqRWuQtFtjxgklowHkdDeLMB945O0MRrsOunjQc+m8Xs8EDIgzukoCLRW4VZe7iiI26yO7yzRj7sekoyzMDWZsD+xLtdR1F1xtpUrsjMQsOKRJuPQaeaPxCHTuA4O3YIOhXI1VClqE/BBlONa969dxUS9IFFuHSRkP/HVAZnPmnGBkLzb59bnWzNkFMBzRgaERtUYX7McIR+/qtqeuwYC/0UX+IVeCnSNg1huRHlm657X/b5wi8Vox68KyXCx9EdurK8naR2Qd2+dBppDSXDirOsEung4IBYKlQo0FtuignitlHachvQAXumNdF0nopsNR3pyzHP3MRT38xr+5w+/zXD2r7Wd18w9NfyaH36xt1oix71SPGlzmwm4sIogTjh9M9h7I+ZgqGA= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: edc31623-675a-40cf-051f-08d822e86304 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3824.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 02:41:16.8911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iKtHl2h8Xc2pdea61YXiUxUxZdYHFYfUjyUl1QQi+BhDDVqTgKSX8Q+5X1imX9vf X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2253 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jul 07, 2020 at 11:59:57AM +0200, Laszlo Ersek wrote: > 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 > Will update the commit in v2. Thanks, Gary Lin > 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; > > >