From patchwork Fri Oct 6 13:32:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 9989485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C44E6603FA for ; Fri, 6 Oct 2017 13:46:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A175E283AE for ; Fri, 6 Oct 2017 13:46:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95AD7283D9; Fri, 6 Oct 2017 13:46:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 51B06283D9 for ; Fri, 6 Oct 2017 13:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Ip4VchlstHXAAxWeYkNAsBDQmONhhlvMGNdYQSyyqU0=; b=WCa7iitCNnKCcdQhgzqZj10l+3 67WKY0Iw+lLE+yjlPBCj76NzS+nuIaoDdphrPz/Qucz6yrg+9/VuQsYItbMONyQi1ed/GN+pcYTFF UmOpOdOf/s+K4u4K0LaKCmBS66nJIorIxkRIbltdtmj/fwKKFZfImtCy9dWDkzc2N98hAbR2perF0 2VPFtnK2aa0wLHFfmevt6D15iiqj6Bia/YdYChrSSUF10NRPJyxuahY3rN9ASg5ox13Ft9Yl3I9RD q1e7/qkzEQbxkBXsAww5NT71Y0Ff7vSt7JN+WFtxLIK5Jgeo2WnVmAM6jXs2mC16SA4QoNhcv5Xje ThWOQ/+A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e0SxL-0007sO-Ar; Fri, 06 Oct 2017 13:46:23 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e0SwH-00053q-MD for linux-arm-kernel@bombadil.infradead.org; Fri, 06 Oct 2017 13:45:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Pr2D5Knq6jinXE66gLdwux09Qc54VaqY0t/wQYHo9Q0=; b=j7zD9M7LSy58Cm4FwRrNNnyv6 E1m+Bc/WgBAY7NqUZ/o6DVgOynk0QRyDrzzPAUn6TEsjksIGalSNDw17FHmajakxsVuBgt+d2LZFv Mtvsb7u6qbNKHqmNATIDE9TIBt9JqCOjCdEPjQkjuKbWhKsWSpA9Uoqmt4EBZZUqWnBE5bx1vybXP 2enWtv1drT/QQgxRNOJ8fnllctZWHsuu81t9qavx3cdze7pMwPBjLI21H1oXjO2nXuqwEFbSR72PZ xLZ7r9sVIi+h2fMv9TM7f5tX8ubgZiuoUMZ3phjP74FK6Y8qpO3GmfQaG1ZM3YTtSGm+s9pqInq12 OK4cQBK5g==; Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by casper.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e0SiO-0007Db-IB for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2017 13:30:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3028B169F; Fri, 6 Oct 2017 06:30:56 -0700 (PDT) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.211.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 570163F578; Fri, 6 Oct 2017 06:30:51 -0700 (PDT) From: Jean-Philippe Brucker To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org Subject: [RFCv2 PATCH 36/36] iommu/arm-smmu-v3: Add support for PCI PASID Date: Fri, 6 Oct 2017 14:32:03 +0100 Message-Id: <20171006133203.22803-37-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171006133203.22803-1-jean-philippe.brucker@arm.com> References: <20171006133203.22803-1-jean-philippe.brucker@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171006_143056_917479_332EF022 X-CRM114-Status: UNSURE ( 9.25 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, xieyisheng1@huawei.com, gabriele.paoloni@huawei.com, catalin.marinas@arm.com, will.deacon@arm.com, okaya@codeaurora.org, yi.l.liu@intel.com, lorenzo.pieralisi@arm.com, ashok.raj@intel.com, tn@semihalf.com, joro@8bytes.org, rfranz@cavium.com, lenb@kernel.org, jacob.jun.pan@linux.intel.com, alex.williamson@redhat.com, robh+dt@kernel.org, thunder.leizhen@huawei.com, bhelgaas@google.com, dwmw2@infradead.org, liubo95@huawei.com, rjw@rjwysocki.net, robdclark@gmail.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, robin.murphy@arm.com, nwatters@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Enable PASID for PCI devices that support it. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 852714f35010..42c8378624ed 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -3012,6 +3012,50 @@ static void arm_smmu_disable_pri(struct arm_smmu_master_data *master) master->can_fault = false; } +static int arm_smmu_enable_pasid(struct arm_smmu_master_data *master) +{ + int ret; + int features; + int num_ssids; + struct pci_dev *pdev; + + if (!dev_is_pci(master->dev)) + return -ENOSYS; + + pdev = to_pci_dev(master->dev); + + features = pci_pasid_features(pdev); + if (features < 0) + return -ENOSYS; + + num_ssids = pci_max_pasids(pdev); + + dev_dbg(&pdev->dev, "device supports %#x SSIDs [%s%s]\n", num_ssids, + (features & PCI_PASID_CAP_EXEC) ? "x" : "", + (features & PCI_PASID_CAP_PRIV) ? "p" : ""); + + num_ssids = clamp_val(num_ssids, 1, 1 << master->smmu->ssid_bits); + num_ssids = rounddown_pow_of_two(num_ssids); + + ret = pci_enable_pasid(pdev, features); + return ret ? ret : num_ssids; +} + +static void arm_smmu_disable_pasid(struct arm_smmu_master_data *master) +{ + struct pci_dev *pdev; + + if (!dev_is_pci(master->dev)) + return; + + pdev = to_pci_dev(master->dev); + + if (!pdev->pasid_enabled) + return; + + pci_disable_pasid(pdev); +} + static int arm_smmu_insert_master(struct arm_smmu_device *smmu, struct arm_smmu_master_data *master) { @@ -3134,6 +3178,11 @@ static int arm_smmu_add_device(struct device *dev) master->ste.can_stall = true; } + /* PASID must be enabled before ATS */ + ret = arm_smmu_enable_pasid(master); + if (ret > 0) + master->num_ssids = ret; + if (!arm_smmu_enable_ats(master)) arm_smmu_enable_pri(master); @@ -3152,6 +3201,7 @@ static int arm_smmu_add_device(struct device *dev) err_disable_pri: arm_smmu_disable_pri(master); arm_smmu_disable_ats(master); + arm_smmu_disable_pasid(master); return ret; } @@ -3172,7 +3222,9 @@ static void arm_smmu_remove_device(struct device *dev) arm_smmu_remove_master(smmu, master); arm_smmu_disable_pri(master); + /* PASID must be disabled after ATS */ arm_smmu_disable_ats(master); + arm_smmu_disable_pasid(master); iommu_group_remove_device(dev); iommu_device_unlink(&smmu->iommu, dev);