From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [51.163.158.102]) by mx.groups.io with SMTP id smtpd.web12.13913.1593576349151336719 for ; Tue, 30 Jun 2020 21:05:49 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: suse.com, ip: 51.163.158.102, mailfrom: glin@suse.com) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2057.outbound.protection.outlook.com [104.47.4.57]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-5EcIry6iMgWOmjQLpcUv6A-1; Wed, 01 Jul 2020 06:05:46 +0200 X-MC-Unique: 5EcIry6iMgWOmjQLpcUv6A-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dBIH/S7jAAC4b6lAM5IIdJtofmh+AHNRYsr3wlad3LYOSciXx9GemRI89QWPsE52RqW5pZZuczIj+oQo1APfHKILdrGWkMGdZLx0yLllr8dDGNFGX+kAi5WJeDq3MCA8PneG+NnLGTxQKZwPGvd2y1VspertLh2frHKXtrdD2R9pMAra2O6JjkITiB0t32vGx1fLkfxYcBCVilARPsPCwVqeTHpmjFNPGcbj00V0xkH9J+vRCUm1tQS1zHyc5MgW01yY/rb/KEUkv6hV5XLhwcb34kl54vcnq6FdOzwYK/bMC5scFtyX1Pl37Xl7ON8yIIygliUi187klg/u1lF01Q== 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=/SrpwCV4WUWvTzh16RjSmO716kNgGxxlaowtiT01QL4=; b=fcrlcjkXRjptLU5fn0yeFndFSmAusYFRbX53/Dr3oaJlUU7l3Z2Om78vyYXPbt/0fQ31EI2tA0scgdkJLbFwr+eBTXfAYM6K+sgCXcSLR64mua7HUJj+ncrPTWcP3hiBxSm8YT325shNDJEiFJhvtXkQvSypuhR67dwG9p/7zbyBN6x4OIC1hFF2zbJioJrdiorSr6+EjYeueVg4qo86dbkUXXxnQ+c5JMuTz+XwgELw0KADjDnue8OuAG9wF+aWHr5Eysav1GeCBRrI+LxR7M94ToreqZ4aooCm5I4OnZTz+2Q5Y6j5tyY8UDKWtWVBfKiCVWsJW+EP1a1XrQqOgw== 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 AM0PR04MB4481.eurprd04.prod.outlook.com (2603:10a6:208:70::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Wed, 1 Jul 2020 04:05:45 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::8806:715f:1409:8c6b]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::8806:715f:1409:8c6b%7]) with mapi id 15.20.3153.021; Wed, 1 Jul 2020 04:05:45 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH 08/11] OvmfPkg/LsiScsiDxe: Map DMA buffer Date: Wed, 1 Jul 2020 12:04:45 +0800 Message-Id: <20200701040448.14871-9-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200701040448.14871-1-glin@suse.com> References: <20200701040448.14871-1-glin@suse.com> X-ClientProxiedBy: AM0PR10CA0047.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::27) 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 AM0PR10CA0047.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21 via Frontend Transport; Wed, 1 Jul 2020 04:05:44 +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: 8dc2290e-4a6f-4fac-826e-08d81d74078c X-MS-TrafficTypeDiagnostic: AM0PR04MB4481: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Lwd7/Byc6OyfnL9Q6DTi+/Adgwc6KeH+i18hzUnJ0OMstxZICnLC6edD9EdKGjsTWv3Hyt0oi5FXFsDEC6sSbJCYqM1OuitOgJnqzxONcJinmOuJZhx/cdRGbhl8WtnWkRo9e83iARgpRrwkcg2EUPhyj8yY+obmGf92JapqZlfSiV9RdPLkpWGXEeu4vlbKt71gfjHBhYBlm8LYMQKB8lkatTn9oEfSfMz/kW3U2/+Xc3hmBi1LaSxKD7vYLk9zDWpkNKqbMgD6tXoO/6H50igSSW0/zQlAEAQgjPurvLzzQU6qX94h3pW/veHaZ10Xj5hJcSp9rlI6LL/xDnGNdw== 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:(366004)(136003)(376002)(39860400002)(396003)(346002)(2616005)(83380400001)(26005)(54906003)(4326008)(16526019)(1076003)(956004)(86362001)(6506007)(186003)(66476007)(66556008)(8936002)(6486002)(52116002)(6916009)(5660300002)(8676002)(36756003)(66946007)(55236004)(316002)(6512007)(478600001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9xDxDDFOCjQYP+Cp4FIf5wQ1K+7VC3XZis8ctyQTAeY7uNYTda/4XtsBcwt7FsPMnjgjGPpMTNkPlXgu3Y3MfgfgzGwpRCu8/tbeNH8XKUUzVCa3Xx3mKTPOZZCwzqFJFyxAbcvXx6ANpXM5IXK4ORtGSKTQQWkCD5n9xd+RghCk2w2xsQPK+ScdyPY6W7FAjWRa0vC8olTmz3/6bgcQPKchBqEBme+HSp2nW2sidSbawJRvBaM+4sIvrKROgpGjAmQl1RvrzznrG77ioKDJZzlOZkIxUKWduPhe0JBDExftzCuB8vI2Rpm5mV6PtD3PpT4Czftzdiu0sl4wflqeoZREDAK3nuYwjJJrKfIoZomCX6rn4KctYIqU4ijdOeCrde6x3Yx7xxnLunrODBk3CtWcHExP2qCJkW9MNsAhV3bIJejQyEi+Fk+iRI/WgB/cmfjA+F+S92w4Zm4MqBTNYYLu02yky28PUG0ckCd3BMg= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dc2290e-4a6f-4fac-826e-08d81d74078c X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 04:05:45.6543 (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: cqcI3Z07WJqGfWJLdBtZyokmaUxkp9Fb/+BqKLVEW52YMEsIC/ogJnDgNy0Oe90c X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4481 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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 ( {=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 @@ -406,11 +408,68 @@ LsiScsiControllerStart ( goto CloseProtocol;=0D }=0D =0D - Status =3D LsiScsiReset (Dev);=0D + //=0D + // Signal device supports 64-bit DMA addresses=0D + //=0D + Status =3D Dev->PciIo->Attributes (=0D + Dev->PciIo,=0D + EfiPciIoAttributeOperationEnable,=0D + EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,=0D + NULL=0D + );=0D + if (EFI_ERROR (Status)) {=0D + //=0D + // Warn user that device will only be using 32-bit DMA addresses.=0D + //=0D + // Note that this does not prevent the device/driver from working=0D + // and therefore we only warn and continue as usual.=0D + //=0D + DEBUG ((=0D + DEBUG_WARN,=0D + "%a: failed to enable 64-bit DMA addresses\n",=0D + __FUNCTION__=0D + ));=0D + }=0D +=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 @@ -457,6 +516,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 @@ -519,6 +591,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 ffaee6188536..1e4bbc56f933 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h @@ -12,6 +12,13 @@ #ifndef _LSI_SCSI_DXE_H_=0D #define _LSI_SCSI_DXE_H_=0D =0D +typedef struct {=0D + //=0D + // Allocate 64KB for read/write buffer.=0D + //=0D + UINT8 Data[0x10000];=0D +} LSI_SCSI_DMA_BUFFER;=0D +=0D typedef struct {=0D UINT32 Signature;=0D UINT64 OrigPciAttrs;=0D @@ -19,6 +26,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