From nobody Mon Feb 9 15:09:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62661+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62661+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594885604938892.367637785523; Thu, 16 Jul 2020 00:46:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 89EkYY1788612xopDb1x82sM; Thu, 16 Jul 2020 00:46:44 -0700 X-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 X-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 X-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 X-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: [edk2-devel] [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> 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) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-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-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-Message-Info: czJmqaig16kHWCPTR/vsItmL05BxgvmPXwuCCsLAWhJ7SH+5aog2gsivPj5wCURzetKOhuvwrLSruBQUhLGaM7usLYEvXPV+umCYTIMA965gyPlxvGZrH6vzoxf2WxuCQt+o7vORcQGAZYV5IKRxqhu4YZ9DSzN55rYDRWQcLjhrpI+wFB8aXk/eerFN3L4boLDfsJtHLaTzbcZjo768gkQnF+ivuUfxl16+zqvF9GOHp1DeaIaQfO5Jd2bR9Q9pspIyQAyzIch20ItCVu4APCGbPdqclgbzXgDFdLVCoi8DGN0BdRKwm435MkWTYuCVP6yRBd6wlyRYDxARsUDExQ== 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 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,glin@suse.com X-Gm-Message-State: 3ZclDjFQA4cWCXKpXfcwuj9Xx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594885604; bh=Z6Lt6yrcEGXm3cAd87B4iDqnX94HF1MHQKqkFsFsDwk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=JOOeKmlgFDqYnSQAZeaX3ht+J6PJiK4iQrGryaYwDlKK/8O1Z1YJ+qfgi36/p7O1TFO y7mmwDlfWfjsyNlR/gYm8JSzN2Bhf1C4llce+zl7xj/4WTYgE8Zqij4bymR37rV6f/ljd 9NBy/crkjys8UnuT7VQRpQnc89djY+YPrk8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Laszlo Ersek --- 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 #define LSI_53C895A_PCI_DEVICE_ID 0x0012 =20 +// +// LSI 53C895A Registers +// +#define LSI_REG_DSTAT 0x0C +#define LSI_REG_ISTAT0 0x14 +#define LSI_REG_DSP 0x2C +#define LSI_REG_SIST0 0x42 +#define LSI_REG_SIST1 0x43 + +// +// The status bits for Interrupt Status Zero (ISTAT0) +// +#define LSI_ISTAT0_DIP BIT0 +#define LSI_ISTAT0_SIP BIT1 +#define LSI_ISTAT0_INTF BIT2 +#define LSI_ISTAT0_CON BIT3 +#define LSI_ISTAT0_SEM BIT4 +#define LSI_ISTAT0_SIGP BIT5 +#define LSI_ISTAT0_SRST BIT6 +#define LSI_ISTAT0_ABRT BIT7 + #endif // _LSI_SCSI_H_ 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 @@ =20 #include "LsiScsi.h" =20 +STATIC +EFI_STATUS +Out8 ( + IN LSI_SCSI_DEV *Dev, + IN UINT32 Addr, + IN UINT8 Data + ) +{ + return Dev->PciIo->Io.Write ( + Dev->PciIo, + EfiPciIoWidthUint8, + PCI_BAR_IDX0, + Addr, + 1, + &Data + ); +} + +STATIC +EFI_STATUS +LsiScsiReset ( + IN LSI_SCSI_DEV *Dev + ) +{ + return Out8 (Dev, LSI_REG_ISTAT0, LSI_ISTAT0_SRST); +} + // // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL // for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata = C, @@ -243,6 +270,21 @@ LsiScsiGetNextTarget ( return EFI_NOT_FOUND; } =20 +STATIC +VOID +EFIAPI +LsiScsiExitBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + LSI_SCSI_DEV *Dev; + + Dev =3D Context; + DEBUG ((DEBUG_VERBOSE, "%a: Context=3D0x%p\n", __FUNCTION__, Context)); + LsiScsiReset (Dev); +} + // // Probe, start and stop functions of this driver, called by the DXE core = for // specific devices. @@ -333,6 +375,58 @@ LsiScsiControllerStart ( Dev->MaxTarget =3D PcdGet8 (PcdLsiScsiMaxTargetLimit); Dev->MaxLun =3D PcdGet8 (PcdLsiScsiMaxLunLimit); =20 + Status =3D gBS->OpenProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + (VOID **)&Dev->PciIo, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + goto FreePool; + } + + Status =3D Dev->PciIo->Attributes ( + Dev->PciIo, + EfiPciIoAttributeOperationGet, + 0, + &Dev->OrigPciAttrs + ); + if (EFI_ERROR (Status)) { + goto CloseProtocol; + } + + // + // Enable I/O Space & Bus-Mastering + // + Status =3D Dev->PciIo->Attributes ( + Dev->PciIo, + EfiPciIoAttributeOperationEnable, + (EFI_PCI_IO_ATTRIBUTE_IO | + EFI_PCI_IO_ATTRIBUTE_BUS_MASTER), + NULL + ); + if (EFI_ERROR (Status)) { + goto CloseProtocol; + } + + Status =3D LsiScsiReset (Dev); + if (EFI_ERROR (Status)) { + goto RestoreAttributes; + } + + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_CALLBACK, + &LsiScsiExitBoot, + Dev, + &Dev->ExitBoot + ); + if (EFI_ERROR (Status)) { + goto UninitDev; + } + // // Host adapter channel, doesn't exist // @@ -357,11 +451,33 @@ LsiScsiControllerStart ( &Dev->PassThru ); if (EFI_ERROR (Status)) { - goto FreePool; + goto CloseExitBoot; } =20 return EFI_SUCCESS; =20 +CloseExitBoot: + gBS->CloseEvent (Dev->ExitBoot); + +UninitDev: + LsiScsiReset (Dev); + +RestoreAttributes: + Dev->PciIo->Attributes ( + Dev->PciIo, + EfiPciIoAttributeOperationSet, + Dev->OrigPciAttrs, + NULL + ); + +CloseProtocol: + gBS->CloseProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + FreePool: FreePool (Dev); =20 @@ -404,6 +520,24 @@ LsiScsiControllerStop ( return Status; } =20 + gBS->CloseEvent (Dev->ExitBoot); + + LsiScsiReset (Dev); + + Dev->PciIo->Attributes ( + Dev->PciIo, + EfiPciIoAttributeOperationSet, + Dev->OrigPciAttrs, + NULL + ); + + gBS->CloseProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + FreePool (Dev); =20 return Status; 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 @@ =20 typedef struct { UINT32 Signature; + UINT64 OrigPciAttrs; + EFI_EVENT ExitBoot; + EFI_PCI_IO_PROTOCOL *PciIo; UINT8 MaxTarget; UINT8 MaxLun; EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62661): https://edk2.groups.io/g/devel/message/62661 Mute This Topic: https://groups.io/mt/75537211/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-