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.13910.1593576347376768326 for ; Tue, 30 Jun 2020 21:05:47 -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-am5eur02lp2050.outbound.protection.outlook.com [104.47.4.50]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-QWBQyyT6OaOIXDjBfpzAug-1; Wed, 01 Jul 2020 06:05:44 +0200 X-MC-Unique: QWBQyyT6OaOIXDjBfpzAug-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cMi0ru1oaJ2muBj0Pa6/BQ5XWm5yUSGouGuEhAgTZ7o3Blp4Rh8oPxGlH8mZDCB6HY/l7PFB+26xozQ9v/3LzpG1A1cpdXHGa84AESPzy6dwoz8CkmGIqD/5Ka2KIluKAsaUkFa94QG1F15ylkBRjTGYI4FFmf2ElUNQrx2AnV3o+t2qjxPcLKBA9eLxZ/Ypv6HtvjrA8DxPyEyfmIpfFBJvr3yJ7dsBmqaNO8g05L2EZHxfYgthuoZ//YGsI9/aF6yU0sfuilbAeiJhk8YPD1m+Rkas/ybr+T3ax7DfcSV6SE6O/XoG0ThKtKLOFQP746dSIJ5OqepaN2baV8QVig== 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=qIYbEn4mGIdaV1ckz2lk4qmFvEpUHwrI3BXcRn2wKd0=; b=FXhw2fNz0WXEREK9Uq+V8dRJIXHOoktK1e1e2nvjiDiQvos87KzhKqeJFi9JLFadruRgg37AE/awUYdejoCRRObh6U/9TGgtR/zWFQGAFYkE/CHi252L9otxXeh+4VEtv/C+u7G3cmG66pmOHHU25aG8ZnvXnYwZkGq14u01WItISSiN7rRyxML8vpQ1pX4SkCCkWnnn5+FLGC9pZwrnzjUitZKup1C0W+QbgdELrfSwcM7CoSwTwtJDdVXHkxPtcSdrMrTfnnFYY1Ih/9xSNBivQOG/L5m2hZ3IRMHp1bwQz3q8yPJgc0Zj6y2BP8yv2E/b2enxTXRQk2c5wRgITQ== 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:43 +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:43 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH 07/11] OvmfPkg/LsiScsiDxe: Open PciIo protocol and initialize the device Date: Wed, 1 Jul 2020 12:04:44 +0800 Message-Id: <20200701040448.14871-8-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:42 +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: 8f76b4fd-dcdd-4509-334e-08d81d740664 X-MS-TrafficTypeDiagnostic: AM0PR04MB4481: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-Forefront-PRVS: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ADKrf1pEKPYmYqKDmc6F+SLqN0GJyJigLX8H/9uFgDS8m3adcvNqJZlQZIrnoFjeJn9DHWhW8nvkGmpDqb6lvpH1+VvTM4fiWESnZlUdI61MkD0Gsycz0l1DatQx+/AFgeDaLnf8zFAvAKxRoDClSBBBecRHcgfsPK6VTUjAwtYjtJXRwG+TOo0IFpOkL20+nMOQzKO9mT2CMlinTZPRqHs/6Q6jIpeMUYyentiD4vb76XS0JK4ok6UvlIS8+BHCmMG/zrP0kjPlEwj7UuRywpT8qETNv7PCdUIRgYIcNkJbSMnd012EIpAZolJJVzb8cePqkgCxRlnfjCfwXtnq7A== 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: hgRthlEPMU6Fm8gGa4o8HeOmmh0sKzWIMLACHH6MroBXhAyXchLfKoOG3nSrLok//glDhqz+qzCkYf13WRBGjRziZB+VIfppW1TfEacP2kCdE+v/NuTwvWOJvWr/hOlosKB+7drn2dHgFkrM/QLXfhKUkdlnM6PCl269CbXWhURvG0s9W8VnLuy6JgpEQ1ueewOU4912vC22BbIYxoQ7c9MC9MtCbHyysmwAdzpvZtKZAQKa+qLXJKBGym7NAb4NuVc+d24IrSLBrrIvZX4Sl/lIMy0KL9BvXJ/VOcQblSd4i6EJ9p6pXdjOkgWnvJwV7CRPF7nYGH2T5VtTqIDzmGVInZy+ngrlPMDl10FsliFtjaUwzlgxQGaQt3sUMnsM1tkxR5LhbSot5OnOcB1oh1kNnlIWCpWy6KsFg+J/wQsjPL5jFeIIxNT2s0lG0hRB3vxmou38ecq4GA0sAr39SM7d9MH2QqXXKG6R3sxlDgM= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f76b4fd-dcdd-4509-334e-08d81d740664 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:43.7244 (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: 6M2eV7Qkwvl0ETC64RGufzOPmqF/B6nsINNZobeH/oV5PFJc80bN4lRDcfMrPauf X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4481 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Open PciIo protocol and use it to initialize the device. The initialization of LSI 53C895A is simple: just set the SRST bit in Interrupt Status Zero register to reset the device. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/Include/IndustryStandard/LsiScsi.h | 21 ++++ OvmfPkg/LsiScsiDxe/LsiScsi.c | 129 ++++++++++++++++++++- OvmfPkg/LsiScsiDxe/LsiScsi.h | 3 + 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/I= ndustryStandard/LsiScsi.h index c09e864a1f39..60e527f1c6a7 100644 --- a/OvmfPkg/Include/IndustryStandard/LsiScsi.h +++ b/OvmfPkg/Include/IndustryStandard/LsiScsi.h @@ -17,4 +17,25 @@ #define LSI_LOGIC_PCI_VENDOR_ID 0x1000=0D #define LSI_53C895A_PCI_DEVICE_ID 0x0012=0D =0D +//=0D +// LSI 53C895A Registers=0D +//=0D +#define LSI_REG_DSTAT 0x0C=0D +#define LSI_REG_ISTAT0 0x14=0D +#define LSI_REG_DSP 0x2C=0D +#define LSI_REG_SIST0 0x42=0D +#define LSI_REG_SIST1 0x43=0D +=0D +//=0D +// The status bits for Interrupt Status Zero (ISTAT0)=0D +//=0D +#define LSI_ISTAT0_DIP 0x01=0D +#define LSI_ISTAT0_SIP 0x02=0D +#define LSI_ISTAT0_INTF 0x04=0D +#define LSI_ISTAT0_CON 0x08=0D +#define LSI_ISTAT0_SEM 0x10=0D +#define LSI_ISTAT0_SIGP 0x20=0D +#define LSI_ISTAT0_SRST 0x40=0D +#define LSI_ISTAT0_ABRT 0x80=0D +=0D #endif // _LSI_SCSI_H_=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index e10a81a5f9f7..f03774cc4ced 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -25,6 +25,33 @@ =0D #include "LsiScsi.h"=0D =0D +STATIC=0D +EFI_STATUS=0D +Out8 (=0D + IN LSI_SCSI_DEV *Dev,=0D + IN UINT32 Addr,=0D + IN UINT8 Data=0D + )=0D +{=0D + return Dev->PciIo->Io.Write (=0D + Dev->PciIo,=0D + EfiPciIoWidthUint8,=0D + PCI_BAR_IDX0,=0D + Addr,=0D + 1,=0D + &Data=0D + );=0D +}=0D +=0D +STATIC=0D +EFI_STATUS=0D +LsiScsiReset (=0D + IN LSI_SCSI_DEV *Dev=0D + )=0D +{=0D + return Out8 (Dev, LSI_REG_ISTAT0, LSI_ISTAT0_SRST);=0D +}=0D +=0D //=0D // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL=0D // for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata = C,=0D @@ -246,6 +273,21 @@ LsiScsiGetNextTarget ( return EFI_NOT_FOUND;=0D }=0D =0D +STATIC=0D +VOID=0D +EFIAPI=0D +LsiScsiExitBoot (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + LSI_SCSI_DEV *Dev;=0D +=0D + Dev =3D Context;=0D + DEBUG ((DEBUG_VERBOSE, "%a: Context=3D0x%p\n", __FUNCTION__, Context));= =0D + LsiScsiReset (Dev);=0D +}=0D +=0D //=0D // Probe, start and stop functions of this driver, called by the DXE core = for=0D // specific devices.=0D @@ -328,6 +370,58 @@ LsiScsiControllerStart ( Dev->MaxTarget =3D PcdGet8 (PcdLsiScsiMaxTargetLimit);=0D Dev->MaxLun =3D PcdGet8 (PcdLsiScsiMaxLunLimit);=0D =0D + Status =3D gBS->OpenProtocol (=0D + ControllerHandle,=0D + &gEfiPciIoProtocolGuid,=0D + (VOID **)&Dev->PciIo,=0D + This->DriverBindingHandle,=0D + ControllerHandle,=0D + EFI_OPEN_PROTOCOL_BY_DRIVER=0D + );=0D + if (EFI_ERROR (Status)) {=0D + goto FreePool;=0D + }=0D +=0D + Status =3D Dev->PciIo->Attributes (=0D + Dev->PciIo,=0D + EfiPciIoAttributeOperationGet,=0D + 0,=0D + &Dev->OrigPciAttrs=0D + );=0D + if (EFI_ERROR (Status)) {=0D + goto CloseProtocol;=0D + }=0D +=0D + //=0D + // Enable I/O Space & Bus-Mastering=0D + //=0D + Status =3D Dev->PciIo->Attributes (=0D + Dev->PciIo,=0D + EfiPciIoAttributeOperationEnable,=0D + (EFI_PCI_IO_ATTRIBUTE_IO |=0D + EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),=0D + NULL=0D + );=0D + if (EFI_ERROR (Status)) {=0D + goto CloseProtocol;=0D + }=0D +=0D + Status =3D LsiScsiReset (Dev);=0D + if (EFI_ERROR (Status)) {=0D + goto RestoreAttributes;=0D + }=0D +=0D + Status =3D gBS->CreateEvent (=0D + EVT_SIGNAL_EXIT_BOOT_SERVICES,=0D + TPL_CALLBACK,=0D + &LsiScsiExitBoot,=0D + Dev,=0D + &Dev->ExitBoot=0D + );=0D + if (EFI_ERROR (Status)) {=0D + goto UninitDev;=0D + }=0D +=0D //=0D // Host adapter channel, doesn't exist=0D //=0D @@ -352,11 +446,33 @@ LsiScsiControllerStart ( &Dev->PassThru=0D );=0D if (EFI_ERROR (Status)) {=0D - goto FreePool;=0D + goto CloseExitBoot;=0D }=0D =0D return EFI_SUCCESS;=0D =0D +CloseExitBoot:=0D + gBS->CloseEvent (Dev->ExitBoot);=0D +=0D +UninitDev:=0D + LsiScsiReset (Dev);=0D +=0D +RestoreAttributes:=0D + Dev->PciIo->Attributes (=0D + Dev->PciIo,=0D + EfiPciIoAttributeOperationSet,=0D + Dev->OrigPciAttrs,=0D + NULL=0D + );=0D +=0D +CloseProtocol:=0D + gBS->CloseProtocol (=0D + ControllerHandle,=0D + &gEfiPciIoProtocolGuid,=0D + This->DriverBindingHandle,=0D + ControllerHandle=0D + );=0D +=0D FreePool:=0D FreePool (Dev);=0D =0D @@ -399,6 +515,17 @@ LsiScsiControllerStop ( return Status;=0D }=0D =0D + gBS->CloseEvent (Dev->ExitBoot);=0D +=0D + LsiScsiReset (Dev);=0D +=0D + Dev->PciIo->Attributes (=0D + Dev->PciIo,=0D + EfiPciIoAttributeOperationSet,=0D + Dev->OrigPciAttrs,=0D + NULL=0D + );=0D +=0D gBS->CloseProtocol (=0D ControllerHandle,=0D &gEfiPciIoProtocolGuid,=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h index a3d51d8f2386..ffaee6188536 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h @@ -14,6 +14,9 @@ =0D typedef struct {=0D UINT32 Signature;=0D + UINT64 OrigPciAttrs;=0D + EFI_EVENT ExitBoot;=0D + EFI_PCI_IO_PROTOCOL *PciIo;=0D UINT8 MaxTarget;=0D UINT8 MaxLun;=0D EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;=0D --=20 2.25.1