Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3531971ybi; Mon, 10 Jun 2019 11:52:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxx+a+eaY2hkmj3/8VReIxFgNzb9OHL0TrKYoCtfpxwRe7UIHl2YolvXL2ip1bXJQDlIkGt X-Received: by 2002:a62:cdc8:: with SMTP id o191mr6343239pfg.74.1560192754927; Mon, 10 Jun 2019 11:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560192754; cv=none; d=google.com; s=arc-20160816; b=Qtr2mxt96amlboWSGkA4hduzZRhua7l4xsvHpBw/ahNGu6Qc9vW3JbYZNDYSW4YWqp iLHOwi5DRmkOEkcVTCeNYgs3y0mXMKiSdm2Bem04vcYYSObiwADEmBoXWiYWsEAQzfCm azHbEH2ukNyGdYm0T/WEpJ9oZUdDU8J8+PqbnrKGOY+H7g2sieJpwcrmxhJy1nLaIlZ5 NT+n73j8iRMBcLvCI22mKwyRvTXTNAfdTyG+Dg9iwpEUlgIlMTgeFuVNyXZoz3BLSZNp 54RPJhSG9KbupCL9O05z64IWNmUwUAacQntJHYZCX61wl84pgFNmAZQlmAJIvT/jQp0U iLqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SSNMpXw+CMKJNEspryBlFlp5+pnIfifJQ9sPn03OJ6s=; b=Y6PMEblwuz77LA/kyzHRx6a7eVatefxJP8W9nsIqvItnkSPUz7WoHpy9LUsej4Vv95 8rcnn4KLM76rjI5vKjag9jcnCeeQiAthUukCLFBJ00k7PlKSgjgUVaYOMbdYOsIIRH9U N/qnGn8jGBmUwxHJz9RJVzYtRkIrJmSbSp/B0n825VEK4Buny3CV8Fd9X5dnTdC0vIoE XJSf5N4SIJ0mfxGRR5ZokPMetptCfb1RPuW+FPPat/OMb6vVgYq6AAvBeQclTmlyr7hU Zb4iNdxpnGnr6Mef7NV8QFKJ6o2vCqXPIqrK/Mcw2r+Knj9d0vEfEEFQfnvACI09/GmF 9rxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si9627533pgv.229.2019.06.10.11.52.20; Mon, 10 Jun 2019 11:52:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388977AbfFJSwF (ORCPT + 99 others); Mon, 10 Jun 2019 14:52:05 -0400 Received: from foss.arm.com ([217.140.110.172]:47632 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388931AbfFJSwC (ORCPT ); Mon, 10 Jun 2019 14:52:02 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 334D6FEC; Mon, 10 Jun 2019 11:52:02 -0700 (PDT) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.196.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B7F193F246; Mon, 10 Jun 2019 11:52:00 -0700 (PDT) From: Jean-Philippe Brucker To: will.deacon@arm.com Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, robin.murphy@arm.com, jacob.jun.pan@linux.intel.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eric.auger@redhat.com Subject: [PATCH 8/8] iommu/arm-smmu-v3: Add support for PCI PASID Date: Mon, 10 Jun 2019 19:47:14 +0100 Message-Id: <20190610184714.6786-9-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190610184714.6786-1-jean-philippe.brucker@arm.com> References: <20190610184714.6786-1-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable PASID for PCI devices that support it. Since the SSID tables are allocated by arm_smmu_attach_dev(), PASID has to be enabled early enough. arm_smmu_dev_feature_enable() would be too late, since by that time the main DMA domain has already been attached. Do it in add_device() instead. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 51 ++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 972bfb80f964..a8a516d9ff10 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2197,6 +2197,49 @@ static void arm_smmu_disable_ats(struct arm_smmu_master *master) master->ats_enabled = false; } +static int arm_smmu_enable_pasid(struct arm_smmu_master *master) +{ + int ret; + int features; + int num_pasids; + 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_pasids = pci_max_pasids(pdev); + if (num_pasids <= 0) + return -ENOSYS; + + ret = pci_enable_pasid(pdev, features); + if (!ret) + master->ssid_bits = min_t(u8, ilog2(num_pasids), + master->smmu->ssid_bits); + return ret; +} + +static void arm_smmu_disable_pasid(struct arm_smmu_master *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); + master->ssid_bits = 0; +} + static void arm_smmu_detach_dev(struct arm_smmu_master *master) { unsigned long flags; @@ -2413,6 +2456,9 @@ static int arm_smmu_add_device(struct device *dev) master->ssid_bits = min(smmu->ssid_bits, fwspec->num_pasid_bits); + /* Note that PASID must be enabled before, and disabled after ATS */ + arm_smmu_enable_pasid(master); + /* * If the SMMU doesn't support 2-stage CD, limit the linear * tables to a reasonable number of contexts, let's say @@ -2423,7 +2469,7 @@ static int arm_smmu_add_device(struct device *dev) ret = iommu_device_link(&smmu->iommu, dev); if (ret) - goto err_free_master; + goto err_disable_pasid; group = iommu_group_get_for_dev(dev); if (IS_ERR(group)) { @@ -2436,6 +2482,8 @@ static int arm_smmu_add_device(struct device *dev) err_unlink: iommu_device_unlink(&smmu->iommu, dev); +err_disable_pasid: + arm_smmu_disable_pasid(master); err_free_master: kfree(master); fwspec->iommu_priv = NULL; @@ -2456,6 +2504,7 @@ static void arm_smmu_remove_device(struct device *dev) arm_smmu_detach_dev(master); iommu_group_remove_device(dev); iommu_device_unlink(&smmu->iommu, dev); + arm_smmu_disable_pasid(master); kfree(master); iommu_fwspec_free(dev); } -- 2.21.0