From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web10.69835.1584370836341176802 for ; Mon, 16 Mar 2020 08:00:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=E4H4W3XG; spf=pass (domain: oracle.com, ip: 156.151.31.85, mailfrom: liran.alon@oracle.com) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02GErlIo156949; Mon, 16 Mar 2020 15:00:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=xFSs3M8mTp8Nb2uyS8dLEEkgCRvX/3IiPQUJEDLcjdA=; b=E4H4W3XGGJNu+gYC+u8BJxhDzOSbRNTwhNVN62Uyq3PTJ+30uRHyhmKrXjSJESF/tPxh FeJDBLS6w3VTSs6HQ47cKxKSW0udj90gOhyQ6mlipjvFHjDuzUKW+YKHI2wTAnuYcG1E USDbZpy6bJ8b3ndHN/vny5VG5HmBloWvAEZpsbh932xwqKDuQdLCalwB8v+morjA0PQM O++l/gc8woe5EFnGJL11s4Yn+sLvjt4JEPjZhZepJPtBUv3Y3JWKUciGypl0tc112X1K PhNT2Y1reO3g2k8MBbR3Cfx9M3EjUpUGiJZxJB1WfdH0rqTAxqOLZ3lXHGR2iApKiDFJ LA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2yrqwmyacm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 15:00:36 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02GEqM1J172706; Mon, 16 Mar 2020 15:00:35 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2ys8yvyjev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 15:00:34 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 02GF0XcM009070; Mon, 16 Mar 2020 15:00:33 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Mar 2020 08:00:33 -0700 From: "Liran Alon" To: devel@edk2.groups.io, lersek@redhat.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, Liran Alon Subject: [PATCH 12/17] OvmfPkg/PvScsiDxe: Reset adapter on init Date: Mon, 16 Mar 2020 17:01:08 +0200 Message-Id: <20200316150113.104630-13-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200316150113.104630-1-liran.alon@oracle.com> References: <20200316150113.104630-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9561 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160072 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9561 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160072 Content-Transfer-Encoding: 8bit The following commits will complete the implementation of device initialization. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 Reviewed-by: Nikita Leshenko Signed-off-by: Liran Alon --- OvmfPkg/PvScsiDxe/PvScsi.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index ff6b50b7020f..fb2407d2adb2 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -29,6 +29,76 @@ // Ext SCSI Pass Thru utilities // + +// +// Writes a 32-bit value into BAR0 using MMIO +// +STATIC +EFI_STATUS +PvScsiMmioWrite32 ( + IN CONST PVSCSI_DEV *Dev, + IN UINT64 Offset, + IN UINT32 Value + ) +{ + return Dev->PciIo->Mem.Write( + Dev->PciIo, + EfiPciIoWidthUint32, + 0, // BarIndex + Offset, + 1, // Count + &Value + ); +} + +// +// Send PVSCSI command to device +// +STATIC +EFI_STATUS +PvScsiWriteCmdDesc ( + IN CONST PVSCSI_DEV *Dev, + IN UINT32 Cmd, + IN VOID *Desc, + IN UINTN Length + ) +{ + EFI_STATUS Status; + UINTN LengthInWords; + UINT8 *WordPtr; + UINT8 *DescEndPtr; + UINT32 Word; + + LengthInWords = Length / sizeof (UINT32); + + if (LengthInWords > PVSCSI_MAX_CMD_DATA_WORDS) { + return EFI_INVALID_PARAMETER; + } + + Status = PvScsiMmioWrite32 (Dev, PVSCSI_REG_OFFSET_COMMAND, Cmd); + if (EFI_ERROR (Status)) { + return Status; + } + + WordPtr = Desc; + DescEndPtr = WordPtr + Length; + + while (WordPtr != DescEndPtr) { + // + // CopyMem() is used to avoid strict-aliasing issues + // + CopyMem (&Word, WordPtr, sizeof (UINT32)); + + Status = PvScsiMmioWrite32 (Dev, PVSCSI_REG_OFFSET_COMMAND_DATA, Word); + if (EFI_ERROR (Status)) { + return Status; + } + + WordPtr += sizeof (UINT32); + } + + return EFI_SUCCESS; +} // // Check if Target argument to EXT_SCSI_PASS_THRU.GetNextTarget() and // EXT_SCSI_PASS_THRU.GetNextTargetLun() is initialized @@ -348,6 +418,13 @@ PvScsiInit ( return Status; } + // + // Reset adapter + // + Status = PvScsiWriteCmdDesc (Dev, PVSCSI_CMD_ADAPTER_RESET, NULL, 0); + if (EFI_ERROR (Status)) { + return Status; + } // // Populate the exported interface's attributes // -- 2.20.1