From patchwork Thu Dec 19 16:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 182144 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702613iln; Thu, 19 Dec 2019 08:31:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxxQ1ZMQ30a7uNKufrKJzWpLfwxrllU532w7qavCRxnP3VVVYk276zNteXJh/BRKWBxlGE1 X-Received: by 2002:aca:aa81:: with SMTP id t123mr2476380oie.92.1576773101506; Thu, 19 Dec 2019 08:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773101; cv=none; d=google.com; s=arc-20160816; b=sDfDk7etd6WSLVLW50Mop+n5j2epj0oZifQOh4nzwfIpYdEx1ZjJfS/U9SuYOMdw65 LlAficWltjuRY0npW71zKLrjQqjRGpY3NpKsoyMj6XtiruSHXAi9qymXf1e302tdqgKY mq7Zvo8f6o5cyUPo16cqX4Jc4c9iIJcWyGPZF1t/D6kwaW4Rn0oj75t2+/sJc496ssro KQ/TMMF1ZR2NvlwHXmQFJ1PGMool5Qr5XzJxGnSNWV1Pet3BVWAsVklYvPgNgMRrhPxO KEAIe2gKrWzNRHae2PGtm4hKc+gWkvn9Bg9J0VtQrDcRuXo0w0qdQgDsp1TNb2CxCS8F 9PtA== 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 :dkim-signature; bh=DFKSWV5x7hWib4ywLyYZ2Xpzoe8h6HBPQg/y9idEIyA=; b=ccxo9ljaCx0esXBzSbNnU6qkDUjtg0S1Pr2nHdaa5Fd7e48w7o7UwzjlBTKOaAKJ1Y fwa1DNL5grdAKgf4maKE3/aQLWqwaX6Wjiyo6DV4s8zjc04WrL9cijpWYIR/SRwbJRDM gt8ZS9NUb34z6G3NsPt9gLnfrIW6tKwr9STzAUmRADloeHL1eSHzErMK3zScg9Y+7ue3 KXiNQZHjSvAyZ7SWFX4oqbPvDBm1d9h5N9MdoypRW/cTcC/l98hEM5YhFHexZtFmmBMT o+OFDIskPUbJ5T2SVbCKwMrgCMzvDGANvwOD8tm/Dq1Iy3f/ohpJggOYvt3CDM/vCcbw xdRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hH3b80Wj; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25si2200080oij.175.2019.12.19.08.31.41; Thu, 19 Dec 2019 08:31:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hH3b80Wj; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726965AbfLSQbj (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:39 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42939 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbfLSQbi (ORCPT ); Thu, 19 Dec 2019 11:31:38 -0500 Received: by mail-wr1-f65.google.com with SMTP id q6so6597089wro.9 for ; Thu, 19 Dec 2019 08:31:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DFKSWV5x7hWib4ywLyYZ2Xpzoe8h6HBPQg/y9idEIyA=; b=hH3b80WjL1UfLkeRj1KaYK2xXE9kCJqYv3IfxG/t0piRVkIEPEUriaWxmUbpRUG4Fq 1k4YH7bs2VDmawOY4Ebix453yuxAxC2sbnROIZRwLQvY7OvLOXgFy/TmXEfK8P7l47eN dX7k8lSRFzJO+MKenvWY8EegeAUWz+s7gbOrYX00KG2aT3ygF3N+B7D30eheZ3koHxzj uDhVQVW0qwmeuvx00tfSyjjW4lZx7I/dbMTo3eCCRLmzgO3m1oH86DGHt1HFdggdqAHd DzIYrIar+5lr7sDIBSRuf4W1WoYmC8U0q2tRT6n3rfDQY1FOLTQqyNkw6XyKGZTogK8O 81MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DFKSWV5x7hWib4ywLyYZ2Xpzoe8h6HBPQg/y9idEIyA=; b=Evc04BnSex8fuQXLJnFYA7UbEfnNFp4A98eEFUAIpUEbMaNyjpuLjcWB0ToKjyKtUt WDPMbhE3g2C4kbbG+i0prSuPPk+9Gkvxji327j4lyTcVHQmnxDXNMuQ3uLg76y2e596X 5P9ITMy84m5zV9psXP7TSRamMz0g2lYvCPlERuVZJwaBcO+YC0r3w+l+63KKK9sR67BB U3z/PcgRVj2Fv5/yL6JzL42LgxTIWwmJTLVI5IBx5c5nOcXpETHfcw6mNFcr61hgLjYN 4ixkAVe2LHFOzm2wlhSAIcgmr/O7QarxBWXKAhDOo/92ctnvEqQm8PbYDxDmtX8hCqXv 4Z9Q== X-Gm-Message-State: APjAAAVnIJhgJcQYB2U8KqaXJR2GBOl6d9B/tzU/qruTpuRKO0eW1MTX bjf6RPtyqroXedCXk4D5v/2rZQ== X-Received: by 2002:a5d:640d:: with SMTP id z13mr10506261wru.181.1576773096482; Thu, 19 Dec 2019 08:31:36 -0800 (PST) Received: from localhost.localdomain (adsl-84-227-176-239.adslplus.ch. [84.227.176.239]) by smtp.gmail.com with ESMTPSA id u22sm7092068wru.30.2019.12.19.08.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:36 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org, will@kernel.org, robin.murphy@arm.com, bhelgaas@google.com, eric.auger@redhat.com, jonathan.cameron@huawei.com, zhangfei.gao@linaro.org Subject: [PATCH v4 13/13] iommu/arm-smmu-v3: Add support for PCI PASID Date: Thu, 19 Dec 2019 17:30:33 +0100 Message-Id: <20191219163033.2608177-14-jean-philippe@linaro.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219163033.2608177-1-jean-philippe@linaro.org> References: <20191219163033.2608177-1-jean-philippe@linaro.org> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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. Tested-by: Zhangfei Gao Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index e62ca80f2f76..8e95ecad4c9a 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2644,6 +2644,53 @@ static void arm_smmu_disable_ats(struct arm_smmu_master *master) atomic_dec(&smmu_domain->nr_ats_masters); } +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 -ENODEV; + + pdev = to_pci_dev(master->dev); + + features = pci_pasid_features(pdev); + if (features < 0) + return features; + + num_pasids = pci_max_pasids(pdev); + if (num_pasids <= 0) + return num_pasids; + + ret = pci_enable_pasid(pdev, features); + if (ret) { + dev_err(&pdev->dev, "Failed to enable PASID\n"); + return ret; + } + + master->ssid_bits = min_t(u8, ilog2(num_pasids), + master->smmu->ssid_bits); + return 0; +} + +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; + + master->ssid_bits = 0; + pci_disable_pasid(pdev); +} + static void arm_smmu_detach_dev(struct arm_smmu_master *master) { unsigned long flags; @@ -2852,13 +2899,16 @@ 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 (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB)) master->ssid_bits = min_t(u8, master->ssid_bits, CTXDESC_LINEAR_CDMAX); 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)) { @@ -2871,6 +2921,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; @@ -2891,6 +2943,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); }