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.web11.10940.1594885603920017673 for ; Thu, 16 Jul 2020 00:46:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=h2O0ygvn; 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=1594885602; 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=AXbnTCdtjYnPoFcBA5MIiVboFxcrZh4U8WHd2V64pOo=; b=h2O0ygvneTs5chbB0qRpm6yxBrKcqEI5kCnKLHqWqSmaxWH0n47tuFzDPWimcXrVosWr0s bBb9TZuGZkbaep5KCQUkmoEt7D3K1w35A3MFr+ygGMv6/j+N1SRVmIJCCkmzVcXwLoWc99 LRHexPnc1MnUxo+WQqSUEYYv7qQwt00= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2173.outbound.protection.outlook.com [104.47.17.173]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-16-j0ZeRZikOWqrX-Sk1fUaFQ-1; Thu, 16 Jul 2020 09:46:41 +0200 X-MC-Unique: j0ZeRZikOWqrX-Sk1fUaFQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vyyt36h5TrfCbHhKi7ZKcf9SBI1GJs+Gz/x2vO9gon3jFxZ6vKzTy6EG9ll+j1XAvJqNJ/fc+Z805vS7OQAFnKPDHi+gkMYNm7k5OAK0tXOeuAjLIw5pt4v/QnWsS5FzpWyFd2mgLoaaVetdfAx8deTOOekq+yx9Z46UriazrroRQnEWYrY4wH380tbmy5yvVYTey5b4Wg1IaOgbT7nhwlLRkvJIctAdf53P7of/pv+vuKyQLjoZ/1VWREpTeFU6+ftoFVrsDUmhhiPK7uT5Jy7cjkvpdHt3h83w5LLcIHbT4pGZV7V+rESz8G22mrEqCDKfmbdLsz5HE8/ndtNJ8g== 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=AXbnTCdtjYnPoFcBA5MIiVboFxcrZh4U8WHd2V64pOo=; b=bmtXG4fymrEdgyeJSescs8R/fm+GGPWlaeYelkiuIh7d1IveJ1nOUNwdykLVvrquNtgg5ag3Sixjtycybn8X+L3BWoreFmUmTF84mlkAEzdRCEf0OyAz53RdN/p9sf9NYtW1YTFQJGhuR20UIDBc6b2cbM28yh1F65eQRfd7Ly1gmpAggebv9wS1TaZ21fXA8QvL7sGU/hzqWgFGwNXepAHXaq5jFarzUCDqRAcy/Lk8Ov6yhHHrETZes5yPQkowSwTWFyxyn+nXjSFUjI1jyrnOQ+yAyG+yc55gsZrNGngVEaI5BJK3uTHraH+g5O6o5Z7jgCelEZ4n57guXKKEiw== 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; Thu, 16 Jul 2020 07:46:40 +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; Thu, 16 Jul 2020 07:46:40 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v2 07/12] OvmfPkg/LsiScsiDxe: Open PciIo protocol and initialize the device Date: Thu, 16 Jul 2020 15:46:02 +0800 Message-Id: <20200716074607.18048-8-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200716074607.18048-1-glin@suse.com> References: <20200716074607.18048-1-glin@suse.com> X-ClientProxiedBy: AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) 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 AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Thu, 16 Jul 2020 07:46:38 +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: b702cfd2-574d-4895-f13d-08d8295c5ffe X-MS-TrafficTypeDiagnostic: AM0PR04MB4740: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: czJmqaig16kHWCPTR/vsItmL05BxgvmPXwuCCsLAWhJ7SH+5aog2gsivPj5wCURzetKOhuvwrLSruBQUhLGaM7usLYEvXPV+umCYTIMA965gyPlxvGZrH6vzoxf2WxuCQt+o7vORcQGAZYV5IKRxqhu4YZ9DSzN55rYDRWQcLjhrpI+wFB8aXk/eerFN3L4boLDfsJtHLaTzbcZjo768gkQnF+ivuUfxl16+zqvF9GOHp1DeaIaQfO5Jd2bR9Q9pspIyQAyzIch20ItCVu4APCGbPdqclgbzXgDFdLVCoi8DGN0BdRKwm435MkWTYuCVP6yRBd6wlyRYDxARsUDExQ== 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:(136003)(376002)(346002)(39860400002)(366004)(396003)(2616005)(956004)(26005)(478600001)(8936002)(36756003)(2906002)(54906003)(8676002)(52116002)(6916009)(316002)(6512007)(186003)(16526019)(1076003)(6486002)(5660300002)(66556008)(66476007)(66946007)(6666004)(83380400001)(86362001)(6506007)(55236004)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: VeXM1hPbG3xmdCnDnPEFc0vIboyf9UF6GM9Ynx4n1lNfh1NSlMnHmHeMI3dmGzYZAePeOZcFxS+kXCHXtrQ1F2+yV0fpC/ZW1K3I9RsX2RK1XVJ4cAzHAUUGIZccRTdutSsfHS6T472gYr9VPSFuBrF26+u2AXpweKqM7V15FpvE3EHJmbXEvjtw4mfa3lZvJ91FVS0oNvxvg8y6D6WLP5Kn/bxGwdp3+Neq92zXnifyk9BuehiIfNheOnh0hZ2pyKFhTL3skXyreP2dXCAYKiMK2l8KuSWJ/KFL5xbg1f0n16Nsu50VP6YnLbwcBVJ46ujOBqKxHBdV+jCaU4HatzbyLmdUn9xNFyr5msTpwbP/FsXbbIA7xy8BqvpTvb+cvX2/HoDbz8MBgIIAuOSgsDC54GRPDQ2rfvBG9IdfeNK0Q8zbMMwJF22Us+UR5ERTS2XoqJZMoaXZOM/2lY/kDOij9tRHicuhkKpt9uDVtbY= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: b702cfd2-574d-4895-f13d-08d8295c5ffe X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2020 07:46:40.1646 (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: w9Td8tZ+9bYz2VoViuVqctdw9v487144greWzqthuGhv8GntpBlFybj/xwQgkS6V X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4740 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. v2: - Use the BITx macros for the bit constants - Add the closing of PciIo protocol in LsiScsiControllerStop() Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/Include/IndustryStandard/LsiScsi.h | 21 ++++ OvmfPkg/LsiScsiDxe/LsiScsi.c | 136 ++++++++++++++++++++- OvmfPkg/LsiScsiDxe/LsiScsi.h | 3 + 3 files changed, 159 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/I= ndustryStandard/LsiScsi.h index c09e864a1f39..185e553c8eb4 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 BIT0=0D +#define LSI_ISTAT0_SIP BIT1=0D +#define LSI_ISTAT0_INTF BIT2=0D +#define LSI_ISTAT0_CON BIT3=0D +#define LSI_ISTAT0_SEM BIT4=0D +#define LSI_ISTAT0_SIGP BIT5=0D +#define LSI_ISTAT0_SRST BIT6=0D +#define LSI_ISTAT0_ABRT BIT7=0D +=0D #endif // _LSI_SCSI_H_=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index 989bda88d209..b21387db6e5a 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 @@ -243,6 +270,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 @@ -333,6 +375,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 @@ -357,11 +451,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 @@ -404,6 +520,24 @@ 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 + This->DriverBindingHandle,=0D + ControllerHandle=0D + );=0D +=0D FreePool (Dev);=0D =0D return Status;=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h index 6c6ed25f1c33..8c2acff6e86f 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