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.2927.1594175878160284498 for ; Tue, 07 Jul 2020 19:37:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=OlOHceaO; 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=1594175876; 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: in-reply-to:in-reply-to:references:references; bh=XsvWyPTJ4A2lgDHg/+UFr/9HLc21BacXtjvQdo+oMJk=; b=OlOHceaOAoyTAYLUi9O4EEWFN05B0W/w1NRrIbc64OL1CQ66sCssMZlpLO/sJViDGiBTRO p5s5hgv4h+qrV30iwMBg9ftd5zR3w9kV3wu2KRpmIQ+Ds7iThPTbmyoNSO/yQSNOh6Feux aZ+VZu8lT/+XqW8+rXWfY9LvP2IeOqI= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2106.outbound.protection.outlook.com [104.47.17.106]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-6-EwsMOQhmNoGzjtrmLijhQQ-1; Wed, 08 Jul 2020 04:37:54 +0200 X-MC-Unique: EwsMOQhmNoGzjtrmLijhQQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VIjOhI+6MlNJSeSkDZGsteeaiyez2FNJ1QC2zVxygS6WYhO91sgj8SSBWAEQxcsb9Jnfm1vbd0x4G44+kO9/Q6ZOBfnpKOEWmHsQHGpIjHjiWsXEYc/d7Zl5Vq5Nr4xDh+zPogohgJDnfYgqmZ/eoHAdYF7+WkZJSFLHLSqLifZfK9aRODWDqg34NqxpKyDgjeLI84M02bhh1Iz/dxTPHzZSiqIqOWGDE+4UEtIfOqk3vM6yM8s3og+awoR1pGQshFq/a7rEX155bFx3rjITUbLmXOHe4QcVsnA8Wl0eNIdu0iXeypwsEFYZTIu/E4FDSIMXnLy2+BLbn+MlbCfyHA== 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=XsvWyPTJ4A2lgDHg/+UFr/9HLc21BacXtjvQdo+oMJk=; b=KXeFplNL0FKcdyo+MGLbB3CaOiuAElEFyKUwkkmx87gUwlQKwy3Wb9d2NDzEeNL0YqZal22zDBIFeBN+nvr2PWZ2NDIWOJgkJe3PvkYnBWKKk/oxNBO044NjVyogp45yC61RqmO4W2ImAo29ELmyeFSxTRwd+N6BymtpUoImO5PohJySo7KmfGFVJVbh9DrrCxYWWHpuXeO842NvwRNY8hTY+dbf6jE0zm86QeblJHf79hbb8Q2KfYOt3bc0lL+9lSHsIgM0TwE1IPNKn0hcnzrWzePgrcAnHS6Ff6iH6PXtd+i758IjxhA0j9xCjfkLDc3RyhefQR9E1Zx0dXi7nA== 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: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3824.eurprd04.prod.outlook.com (2603:10a6:803:22::18) by VE1PR04MB6464.eurprd04.prod.outlook.com (2603:10a6:803:11f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.28; Wed, 8 Jul 2020 02:37:51 +0000 Received: from VI1PR0402MB3824.eurprd04.prod.outlook.com ([fe80::3854:92a5:f662:2def]) by VI1PR0402MB3824.eurprd04.prod.outlook.com ([fe80::3854:92a5:f662:2def%6]) with mapi id 15.20.3153.029; Wed, 8 Jul 2020 02:37:51 +0000 Date: Wed, 8 Jul 2020 10:37:42 +0800 From: "Gary Lin" To: Laszlo Ersek Cc: devel@edk2.groups.io, Jordan Justen , Ard Biesheuvel Subject: Re: [PATCH 07/11] OvmfPkg/LsiScsiDxe: Open PciIo protocol and initialize the device Message-ID: <20200708023742.GQ18504@GaryWorkstation> References: <20200701040448.14871-1-glin@suse.com> <20200701040448.14871-8-glin@suse.com> <9c8fdc1c-998d-9817-db4e-31bffdc0fb50@redhat.com> In-Reply-To: <9c8fdc1c-998d-9817-db4e-31bffdc0fb50@redhat.com> X-ClientProxiedBy: AM0PR10CA0088.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::41) To VI1PR0402MB3824.eurprd04.prod.outlook.com (2603:10a6:803:22::18) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation (60.251.47.115) by AM0PR10CA0088.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 02:37:48 +0000 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8d4f787-0097-47df-792a-08d822e7e872 X-MS-TrafficTypeDiagnostic: VE1PR04MB6464: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iKXKL+yJJWJ2SgUSeBa5Vil46iR2Nhb50OX7V2M5QWlP9TNrbsX4MOxXTIRMGa2jyDnxqEwFQ1lqlb4fALjHlEMdRXcBeX/N30+CBxbLP8gO3LGK044fHx5u0LqcwdcwAU3AZ3GVmDPqKv1KiDmRf5TonoXoN0yAQx9pfvZGrrFFpGRchhOmczC+4eLASa1KJ0ffvaj+pjzPvHhpcF26sJtu6vEpXAbW6otan5v5cIArDxmlvafpFfMvK2aCDiJJyfSYSsvICe0ldgIOjNwvqYeSOyskxbBO9X6khy78FHvFoYce9+pJKeGxbT66AnN+EYCrO877yCiw3jcNMK4V3A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3824.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(39850400004)(396003)(136003)(366004)(376002)(346002)(55016002)(8676002)(478600001)(54906003)(6916009)(316002)(1076003)(6496006)(52116002)(956004)(86362001)(53546011)(2906002)(6666004)(55236004)(33716001)(9686003)(66946007)(5660300002)(8936002)(66556008)(33656002)(66476007)(26005)(4326008)(16526019)(186003)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cciD93pcBGhzr7JXcCAcDhCEQh4RBCMdumIn2tAImQ1S2L6wWrh4J14o7MA+9gedY22br74f02ZejMEQGVHnM3PnHdHCzw2cUyk1/7CespPsIW29nJvESfXsbjBZg9zcyDHsCxhewTn8NRYLa5ls7GCRzlzCMftOc648R6uX+ecfSEtXKiy09NXghlCplwurz6ZwDDWlJid9ACPQH1/EtmhrOvtNSGzccu/hKHej9KIfvxaGG/R8Wf/hJStxBjT4l6KkIASIqjKZZ7NUkYyZ4K4AcF/PY2e8ZX7NjIi/nE+NHaB0tis3sKCHIj3veiVF3epApvYRt9a6/1oKg023SQTaMnqxpN8sASvFJ2qN69ta0VwHF40lPX+WQTC/FhdcakyVygFsK8fLE0GtQhZzs9tts7DDMujb3DgdcJssiMppdFCnsguosQ6w0zNKLKxbVu+7/iaQzPdGovd9lwIb3C7hZ9A12kIfDaAHAFx0RrE= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8d4f787-0097-47df-792a-08d822e7e872 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3824.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 02:37:51.3236 (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: JYqdB8iBAvdNV9eh6ehgX5MH/GiNJ5ot9fQ2+ihhCfjFsi2MJgHGxdvXVOtbwhfa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6464 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jul 07, 2020 at 11:46:28AM +0200, Laszlo Ersek wrote: > On 07/01/20 06:04, Gary Lin wrote: > > 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/IndustryStandard/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 > > #define LSI_53C895A_PCI_DEVICE_ID 0x0012 > > > > +// > > +// 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 0x01 > > +#define LSI_ISTAT0_SIP 0x02 > > +#define LSI_ISTAT0_INTF 0x04 > > +#define LSI_ISTAT0_CON 0x08 > > +#define LSI_ISTAT0_SEM 0x10 > > +#define LSI_ISTAT0_SIGP 0x20 > > +#define LSI_ISTAT0_SRST 0x40 > > +#define LSI_ISTAT0_ABRT 0x80 > > (1) Please use the BIT0, BIT1, ... etc macros, which are more idiomatic > in edk2 than open-coded constants like 0x01, 0x02, ... > Got it. Will do it to improve the readability. > > + > > #endif // _LSI_SCSI_H_ > > 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 @@ > > > > #include "LsiScsi.h" > > > > +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, > > @@ -246,6 +273,21 @@ LsiScsiGetNextTarget ( > > return EFI_NOT_FOUND; > > } > > > > +STATIC > > +VOID > > +EFIAPI > > +LsiScsiExitBoot ( > > + IN EFI_EVENT Event, > > + IN VOID *Context > > + ) > > +{ > > + LSI_SCSI_DEV *Dev; > > + > > + Dev = Context; > > + DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context)); > > + LsiScsiReset (Dev); > > +} > > + > > // > > // Probe, start and stop functions of this driver, called by the DXE core for > > // specific devices. > > @@ -328,6 +370,58 @@ LsiScsiControllerStart ( > > Dev->MaxTarget = PcdGet8 (PcdLsiScsiMaxTargetLimit); > > Dev->MaxLun = PcdGet8 (PcdLsiScsiMaxLunLimit); > > > > + Status = gBS->OpenProtocol ( > > + ControllerHandle, > > + &gEfiPciIoProtocolGuid, > > + (VOID **)&Dev->PciIo, > > + This->DriverBindingHandle, > > + ControllerHandle, > > + EFI_OPEN_PROTOCOL_BY_DRIVER > > + ); > > + if (EFI_ERROR (Status)) { > > + goto FreePool; > > + } > > + > > + Status = Dev->PciIo->Attributes ( > > + Dev->PciIo, > > + EfiPciIoAttributeOperationGet, > > + 0, > > + &Dev->OrigPciAttrs > > + ); > > + if (EFI_ERROR (Status)) { > > + goto CloseProtocol; > > + } > > + > > + // > > + // Enable I/O Space & Bus-Mastering > > + // > > + Status = 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 = LsiScsiReset (Dev); > > + if (EFI_ERROR (Status)) { > > + goto RestoreAttributes; > > + } > > + > > + Status = 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 > > // > > @@ -352,11 +446,33 @@ LsiScsiControllerStart ( > > &Dev->PassThru > > ); > > if (EFI_ERROR (Status)) { > > - goto FreePool; > > + goto CloseExitBoot; > > } > > > > return EFI_SUCCESS; > > > > +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); > > > > @@ -399,6 +515,17 @@ LsiScsiControllerStop ( > > return Status; > > } > > > > + gBS->CloseEvent (Dev->ExitBoot); > > + > > + LsiScsiReset (Dev); > > + > > + Dev->PciIo->Attributes ( > > + Dev->PciIo, > > + EfiPciIoAttributeOperationSet, > > + Dev->OrigPciAttrs, > > + NULL > > + ); > > + > > gBS->CloseProtocol ( > > ControllerHandle, > > &gEfiPciIoProtocolGuid, > > (2) So as I said under "[PATCH 05/11] OvmfPkg/LsiScsiDxe: Install > stubbed EXT_SCSI_PASS_THRU", this CloseProtocol() call should not be > "context" here (from patch 05/11); it should be introduced here, > reflecting the operations in LsiScsiControllerStart() that are also > introduced in this patch. > Will move the code snippet here. Thanks, Gary Lin > > 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 @@ > > > > 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; > > > > Thanks > Laszlo >