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.6001.1594966329191921424 for ; Thu, 16 Jul 2020 23:12:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=FQYkXS2B; 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=1594966327; 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=1NOGBTCX6qF++qENzCsiMiVBpRPOcu92a+DtoEpI4cU=; b=FQYkXS2BR8iz+7qlWFxuQDbI0Uhbvcyz7bIWJK/mJoE3fxwRbjxoCWePpzFHXb4BQFkPiQ J/lUzb9qyhpSMAhp7BghE+p+gKhCngQhCQ/YHIKsdnghL2DEMmSG/JrwvH/Gxh6tu5m4QO bSE49XbNxAW+W7vokMr7Yl058LF9Fpw= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2110.outbound.protection.outlook.com [104.47.17.110]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-16-OgIQvlnxN-KRveZcAwx24w-1; Fri, 17 Jul 2020 08:12:06 +0200 X-MC-Unique: OgIQvlnxN-KRveZcAwx24w-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VBHiwjyBl07IphcIrRjOeIEExM2giQdgL9qIhnkqM8wACFyevyI7GMuzj8t6uiyWrwZCOiYyu5tvsPDmksIYlixEoX4CT76H+bSB8nRk3+B1BED5y1WN/Zrtdx2BSLpQVKUq/7d8q/y8tdK57pdQhUGWM62QHQWleglpDUIebPseIE7yj0YEwN6bHpbCfhNUiee/Kl5Vy8ZwjbzSrYoyv4+O8+cxqzmU0sbRYYCofFxjKBnYaxtELviwW9kE3ZIBWoGLLKFa1K0t1x9kI6YUnW9jxE5wmRNLDJPNjmeo9iGuEn09O/TI0dVr/WEol7fjHvRoelL+9bhRt4Q6HTq5qA== 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=1NOGBTCX6qF++qENzCsiMiVBpRPOcu92a+DtoEpI4cU=; b=JiDWg/OxS6/eXdcxUswfL2lel7DmQlougxfEgO2ykrLsDyGUsGiVC0Hzc5nhUn/YFQso2JtF9L7jB+r6BdEB26kZlxIcSwyNXaKPAT5ciLrJfLJQ+62ZA5WV5+yU7Rkzgn/gyz0f4UYtPeKxE64uIxN01beJPWGD1EHWJ/T2YrCHVjYfwZHIozrmGtcHtmpisRlLDGZ0IKnHDcj+Ez5YJjoqE+ID0JMVbDxROyi+ul3JF/VIInFvre5hYr0QAO6Ably717ErdxgkVcdP0y3+nWCJAyqKt+yRzEE7D1eoheMECIHNbNaKQqxc7/PCJFWnDv67nOgTvTHv+b0lnwnH8Q== 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: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=suse.com; Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) by AM0PR04MB4740.eurprd04.prod.outlook.com (2603:10a6:208:c8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Fri, 17 Jul 2020 06:12:05 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba%6]) with mapi id 15.20.3174.026; Fri, 17 Jul 2020 06:12:05 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v3 08/11] OvmfPkg/LsiScsiDxe: Map DMA buffer Date: Fri, 17 Jul 2020 14:11:27 +0800 Message-Id: <20200717061130.8881-9-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717061130.8881-1-glin@suse.com> References: <20200717061130.8881-1-glin@suse.com> X-ClientProxiedBy: AM0PR04CA0138.eurprd04.prod.outlook.com (2603:10a6:208:55::43) To AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation.suse.cz (60.251.47.115) by AM0PR04CA0138.eurprd04.prod.outlook.com (2603:10a6:208:55::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Fri, 17 Jul 2020 06:12:03 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8592de82-8402-4928-7737-08d82a1853f0 X-MS-TrafficTypeDiagnostic: AM0PR04MB4740: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ndxVlE+IxaOR6FV2EHNjKA2XvMz3aucYoFESobaYNECWr0sX9XpW933NKmNHSSdc7yfD8VbYuxoxmJOAaDc+xPW4bIc98cxYMQf+9V3AcmT0RxeSoJU9Hvrn6W8YJRauB9MC9on3AUeQ06ZCsjuq2NybC3ssxzvQdYYTYOMFj/rKH1vjFwXXZ8TOS/eH3mzpEYZkIBa3vT4/X3pKRcnehiIS+NjiyIYMkA97c62MHANacm4KrCpgKvkX4gBDnohJw7xr57xwrlke3y2u1Zn/FgRl4rKRuuzXUvJV+F4B9ME1PA1oM+HyHAHiUARKndJTupQKdRIqlkGDVYqvtDqoNQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR0402MB3809.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(39860400002)(136003)(396003)(376002)(346002)(366004)(55236004)(2906002)(186003)(1076003)(16526019)(66556008)(6506007)(66946007)(6486002)(8936002)(66476007)(54906003)(86362001)(6916009)(8676002)(26005)(83380400001)(5660300002)(6512007)(316002)(6666004)(52116002)(478600001)(956004)(36756003)(2616005)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: oNBeChtFy1wfc7W/v4IHieTLve14jvBp6wNO/n6Q/yt4I0dqdXxQBrKDZ1bCK7OPMVSOAbytaY51V+iXHodym0roM07zCH1oYflLsYnzLrDf05w/hc0R8+MZvLKyb3WyNbGT08SQmGAo1f9c18xQH9xSaaA1NmdNW9pVs0/BBfOppM0eDPIIZibl22AJK9puIUCB+fB4n0M1Zt/ClHRcoZFIk7xqoQ7Qte/yoRvOQzTis6VH18MpTiaH3NWpJATyCiD1ynieuuxDBbpIcRXBQHB2uvqdTtsRxaz/WZATqEnN/gn4D8bT92TuRR3M75NBkFQuQgnHMVO3Uj9mp0tiv9X3FydiF6ZkTspfXLJQKxYZTrVU+cMbbfFzElSDym096XjmbPhVbr6fxVccAd4isQEXdtyr+hY0Kf4GsD0s8j6JzzPuEXdR5D0gcVAJt+oifxeP42uxSOXvUH626fIfYobiVe5lsbBvbJS17chX+0k= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8592de82-8402-4928-7737-08d82a1853f0 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2020 06:12:05.2442 (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: 35o63UFFPC0SopYAwqu+tYSMEBCGgLehkbHVn4mXheo77MH6DFWNCEbIOqihyA60 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4740 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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 Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin Reviewed-by: Laszlo Ersek --- 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 a9c107c04ef1..52c224aad9a5 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -356,6 +356,8 @@ LsiScsiControllerStart ( {=0D EFI_STATUS Status;=0D LSI_SCSI_DEV *Dev;=0D + UINTN Pages;=0D + UINTN BytesMapped;=0D =0D Dev =3D AllocateZeroPool (sizeof (*Dev));=0D if (Dev =3D=3D NULL) {=0D @@ -411,11 +413,45 @@ LsiScsiControllerStart ( goto CloseProtocol;=0D }=0D =0D - Status =3D LsiScsiReset (Dev);=0D + //=0D + // Create buffers for data transfer=0D + //=0D + Pages =3D EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma));=0D + Status =3D Dev->PciIo->AllocateBuffer (=0D + Dev->PciIo,=0D + AllocateAnyPages,=0D + EfiBootServicesData,=0D + Pages,=0D + (VOID **)&Dev->Dma,=0D + EFI_PCI_ATTRIBUTE_MEMORY_CACHED=0D + );=0D if (EFI_ERROR (Status)) {=0D goto RestoreAttributes;=0D }=0D =0D + BytesMapped =3D EFI_PAGES_TO_SIZE (Pages);=0D + Status =3D Dev->PciIo->Map (=0D + Dev->PciIo,=0D + EfiPciIoOperationBusMasterCommonBuffer,=0D + Dev->Dma,=0D + &BytesMapped,=0D + &Dev->DmaPhysical,=0D + &Dev->DmaMapping=0D + );=0D + if (EFI_ERROR (Status)) {=0D + goto FreeBuffer;=0D + }=0D +=0D + if (BytesMapped !=3D EFI_PAGES_TO_SIZE (Pages)) {=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + goto Unmap;=0D + }=0D +=0D + Status =3D LsiScsiReset (Dev);=0D + if (EFI_ERROR (Status)) {=0D + goto Unmap;=0D + }=0D +=0D Status =3D gBS->CreateEvent (=0D EVT_SIGNAL_EXIT_BOOT_SERVICES,=0D TPL_CALLBACK,=0D @@ -462,6 +498,19 @@ CloseExitBoot: UninitDev:=0D LsiScsiReset (Dev);=0D =0D +Unmap:=0D + Dev->PciIo->Unmap (=0D + Dev->PciIo,=0D + Dev->DmaMapping=0D + );=0D +=0D +FreeBuffer:=0D + Dev->PciIo->FreeBuffer (=0D + Dev->PciIo,=0D + Pages,=0D + Dev->Dma=0D + );=0D +=0D RestoreAttributes:=0D Dev->PciIo->Attributes (=0D Dev->PciIo,=0D @@ -524,6 +573,17 @@ LsiScsiControllerStop ( =0D LsiScsiReset (Dev);=0D =0D + Dev->PciIo->Unmap (=0D + Dev->PciIo,=0D + Dev->DmaMapping=0D + );=0D +=0D + Dev->PciIo->FreeBuffer (=0D + Dev->PciIo,=0D + EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma)),=0D + Dev->Dma=0D + );=0D +=0D Dev->PciIo->Attributes (=0D Dev->PciIo,=0D EfiPciIoAttributeOperationSet,=0D 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_=0D #define _LSI_SCSI_DXE_H_=0D =0D +typedef struct {=0D + //=0D + // Allocate 64KB for read/write buffer. It seems sufficient for the comm= on=0D + // boot scenarios.=0D + //=0D + // NOTE: The number of bytes for data transmission is bounded by DMA Byt= e=0D + // Count (DBC), a 24-bit register, so the maximum is 0xFFFFFF (16M= B-1).=0D + //=0D + UINT8 Data[SIZE_64KB];=0D +} LSI_SCSI_DMA_BUFFER;=0D +=0D typedef struct {=0D UINT32 Signature;=0D UINT64 OrigPciAttrs;=0D @@ -19,6 +30,9 @@ typedef struct { EFI_PCI_IO_PROTOCOL *PciIo;=0D UINT8 MaxTarget;=0D UINT8 MaxLun;=0D + LSI_SCSI_DMA_BUFFER *Dma;=0D + EFI_PHYSICAL_ADDRESS DmaPhysical;=0D + VOID *DmaMapping;=0D EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;=0D EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;=0D } LSI_SCSI_DEV;=0D --=20 2.25.1