From patchwork Fri Feb 5 18:47:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tirumalesh Chalamarla X-Patchwork-Id: 8238431 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1ADAABEEE5 for ; Fri, 5 Feb 2016 18:49:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F297320375 for ; Fri, 5 Feb 2016 18:49:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9E742034A for ; Fri, 5 Feb 2016 18:49:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aRlQ1-0000VP-KM; Fri, 05 Feb 2016 18:47:45 +0000 Received: from mail-bn1on0084.outbound.protection.outlook.com ([157.56.110.84] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aRlPx-0000KY-Tm for linux-arm-kernel@lists.infradead.org; Fri, 05 Feb 2016 18:47:43 +0000 Authentication-Results: arm.com; dkim=none (message not signed) header.d=none; arm.com; dmarc=none action=none header.from=caviumnetworks.com; Received: from tiru-pc.caveonetworks.com (64.2.3.194) by BY1PR0701MB1783.namprd07.prod.outlook.com (10.162.141.21) with Microsoft SMTP Server (TLS) id 15.1.396.15; Fri, 5 Feb 2016 18:47:18 +0000 From: To: , Subject: [PATCH] iommu/arm-smmu-v2: Workaround for ThunderX errata#27704 Date: Fri, 5 Feb 2016 10:47:07 -0800 Message-ID: <1454698027-20911-1-git-send-email-tchalamarla@caviumnetworks.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-Originating-IP: [64.2.3.194] X-ClientProxiedBy: CO2PR11CA0020.namprd11.prod.outlook.com (10.141.242.158) To BY1PR0701MB1783.namprd07.prod.outlook.com (25.162.141.21) X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 2:2S/sh8Kfq420hDR5yAAu3x/tLZZ2qA1ssEHBfPPwv3FTq+RdIe+1StjVN8YW7ozTlRvfixtUn2DdiZ4xZwLb4GQOq6MrN19RrUZpajhNfRCOwLEzCF6n34Wm3J1t0LPOefb4RHpvOl6gzV8xORILkA==; 3:9U1I5FneKc47ZGDOj+i4PTte2rcs64x5ZM3fRvcCx5M1+fEfPmMSEk3XM+b6q0jBnEl0I8NLFUXYq3HKmzliU+Bzn/NATVKz4DJJCauyMBgCEwh+B0Fb57vapsa7BLAQ; 25:UBhNNik+MfSKzFsG6oXYQVPUIRtmrxB0jPrYpkQlgM9OmGNsBRrATRUw7FgmD+RXaE9sD9kYMbemfB44wBCJsqtO6s7vrRj6OXJRsmY8WYCZp3wLItZrwKTJZTRnsQgkQv7jLn7eRIwgM/aedHL8otFw+UBiuqBaOoVpvD840W80CK4KsEeth/yyoGVJisKnwVrS0AtbmxpjFXZbjfFTDiFCv9mxwIIYLTKVZIW6dUzlYw9+Dy9w3Hn2XEnOplM5JEZztYRl5wPmFi/9DU1+uOcuSwwfRpEv+ibH0nfdGHZbrub5LBd+hqlZfx/qhKHU X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1783; X-MS-Office365-Filtering-Correlation-Id: 5c5972b4-89af-4630-8a2e-08d32e5cc67f X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 20:EV38kM38La+dusJoPbjgy1LapeHAhnyRumzi2h9aID3ziTTMt99LguE40Fv7znbd6A6y5Qlg5S4eyrjWQXjOyNpZ/i3bo3bDO6lgJ21o8dr4c1pIQSOkQsKuRNfP51bvW72nsJ6f6Ma8hZJyY+E0UHKmJ1Ct8CTlnxJ8NnIdJ7odKZyFJzz3lggBNZGy0HB+o5De5Hct2tvd0yqJ1KRR0idyJYvoJiab4btv2MvGzedu8+2DF/qf3BxbUIy2/xUzweyjlJylKIt52YXkfCAbOZTVjRp74VMuZGCAiPY1ME0hIORRCiS3bfFDHZ2Lop+RGmAmdAi7nUS0YoyjU/y65SDHBYU37knJuV3k1Xlsh9l7Ojc7nm4Mx6XUFPqgOcpFoiNyLEiRdv+QEnqZmgknIlT4Wxxkf7kToLO63E4d95RoeAXpBG2s98eGH5+q9czgsvLQqZyOYH0ayuyyYmqt8qxhEibDi4S8JnEEMI4TpK+MEc7bbs9gafYi6OEetdVKeEvt7Z6vJUQsYBG25kUM7qSkYW7DKArG9E42Ho3KK8+Yq09PVAPHM4+MZtEMnSLOZZKBFm0QKvTJxWnGBNZoknVbaY6FikJeLMQsPE1/pak= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:BY1PR0701MB1783; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0701MB1783; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 4:Rv263Kv57/svd4S+2wOzr68ksJ30MP9iM62a42NTC4a+XCqcG/fIb4XX3zRio34UB/7jaH7Ejut2zZtVGpE/mdCVsuZuESn5cLtVOZDlOQVsc1UE9i1tQxZAR/CBKhlmnC1GnkW1OorOsrt92orPLM64rBWAmc98M7br/ecJypGCFE1sLyNptqbodFcdgIZxQM/xuXO3eCdQTueTsbw9r7CA7ulAFSK6Ozi5Bvx4W/DTbrCk66oCtullp3FwoHfSRBMw0v2IsYEmd6cseimXPS53NCYLWzffTUsRANUL5JmyQRiR0jYFBdiKijVVSKK9i0MrPV6u6VhsKvycyVOh4qPvO6givYNnGkzfr+/vd7iPSVtAU8PHiwKWrqCGtJow X-Forefront-PRVS: 0843C17679 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(586003)(6116002)(36756003)(77096005)(50226001)(3846002)(50466002)(5008740100001)(5001960100002)(40100003)(229853001)(33646002)(92566002)(47776003)(5001770100001)(4326007)(2906002)(42186005)(5004730100002)(86152002)(66066001)(4001430100002)(5003940100001)(230783001)(2876002)(122386002)(50986999)(19580405001)(189998001)(107886002)(19580395003)(53416004)(87976001)(1096002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0701MB1783; H:tiru-pc.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR0701MB1783; 23:T6MNTeToHKN0AqnmIWIX4ftx6NPX5+dvoQYXvCD?= =?us-ascii?Q?ivweeCkDLzIs9t45hPu3nvHXfNu9PLA6e5pSW/hn/5KQ12t76qq5wJhQTH/p?= =?us-ascii?Q?KcLLHN5nCqSeoBGbWru2X1EAt8H1a4QoAGiSr1x3zHU0KRNVPshUint9KebH?= =?us-ascii?Q?Q5ji/onj0f/AL+JTJcePdSMjdl+PAz6xlfwWfUlhMm5omOQUQRScvUoRCDk2?= =?us-ascii?Q?pQsrCZcPs3qE3zr2ZAOfwayJ6lp+Xel900qfUdjzumNLB+Wr9wNOspSLnQEM?= =?us-ascii?Q?sxj1kGl0TqClVhyWRpq3SDi4FhFUgIcFZobbBYIRCOIHuhXKjtUErun7lskU?= =?us-ascii?Q?6zFALS7VlUxAL1+CBYmWP1XrTq+sk/tyhJTmct7QtdN6S1bMxOmN1yNers+M?= =?us-ascii?Q?GXl+FWbzYIu/cs3dEN5PceWi+oVZOG7mfk0hV8DEzvUb4V6spjiI68cKcs2y?= =?us-ascii?Q?FgFch3aETaB3KchT6CgW1ipKujVtUtuRs1uo6RLmOyl03/RRi+ozDelJG0xF?= =?us-ascii?Q?dlrQUtA/Bl0JqxxAYzLvCVrtv+XPYhJuaLg3hD5zuNOAMF6DRc453e2F9cmK?= =?us-ascii?Q?8/I1IcPJcmPW26x19WeBmVZTeKr8k7zISQpyU0R9osYp+6AMflcVbROwRqBQ?= =?us-ascii?Q?w+PCbSFJqupye8EVH4/WPlVUZ1gBryFultBDpqn5OjuCNhbtKDjxctpI9VBD?= =?us-ascii?Q?VvP/Vn+mFqVZuFoCruuP2OTMAtIZdl70BZWID9eNwTfpleTHpq1ixv3d+Z3+?= =?us-ascii?Q?SgFzNjD1XzDmZtD1MjBDeCsHgroYTWOQAXEnMyavl4n+aRHAMBBYDkN74tTZ?= =?us-ascii?Q?GFpFFhUFVar1xbIbUubJlPJFy++jYvQoX9EqTEzYp2Bnz2fGqQ5p2lphcNBB?= =?us-ascii?Q?xeWVy51b239zv4+TCG9rmF6SldmVh4IcR+a5eX34zzEJXcFG7XuBqVvehOSX?= =?us-ascii?Q?qO6ChPwwbpbD0gXnwZXdqmyOwNOkyj8WBqlXPQ7zKGg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 5:2PiJEeSyeUXFPpymop3YwbMCH3UX2lVz+Gq9M/T7okvvZtnhOb0NCQr59wpjWzqXJDjtffjBLd3yLdj2DE873+na34jkIqTUeaegH9t+30zcxVFjxjnMUTpfXHmGa/HujT7cLK2PQyG1uA9HsKJ9vA==; 24:f9NX3FFDkgGxTeg+tybQE0dB7qJOikmt7QemAL6bZXWd1/t01g1pgIKsruScS+rwklqGtqyWvBkyTQ3FjOkHhNYpyxUFZRqv5J+t5OzvYG4= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2016 18:47:18.7581 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1783 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160205_104742_256966_43E3C023 X-CRM114-Status: UNSURE ( 9.46 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: iommu@lists.linux-foundation.org, Geethasowjanya.Akula@caviumnetworks.com, linux-arm-kernel@lists.infradead.org, tchalamarla@caviumnetworks.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tirumalesh Chalamarla An issue exists whereby the Linux kernel requires that ASIDs are a unique namespace per SMMU. That ASID-local choice conflicts with the CN88xx SMMU, where only shared ASID namespaces are supported; specifically within a given node SMMU0 and SMMU1 share, as does SMMU2 and SMMU3. CN88xx SMMU also requires global VMIDs. This patch tries to address these issuee by supplying asid and vmid transformations from devicetree. Signed-off-by: Akula Geethasowjanya Signed-off-by: Tirumalesh Chalamarla --- .../devicetree/bindings/iommu/arm,smmu.txt | 16 ++++++ drivers/iommu/arm-smmu.c | 59 ++++++++++++++++++---- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/arm,smmu.txt b/Documentation/devicetree/bindings/iommu/arm,smmu.txt index 7180745..eef06d0 100644 --- a/Documentation/devicetree/bindings/iommu/arm,smmu.txt +++ b/Documentation/devicetree/bindings/iommu/arm,smmu.txt @@ -55,6 +55,22 @@ conditions. aliases of secure registers have to be used during SMMU configuration. +- thunderx,smmu-asid-transform : Enable proper handling for buggy + implementations that require special transformations + for smmu asid. if this property exists asid-transform + property must be present. + +- thunderx,smmu-vmid-transform : Enable proper handling for buggy + implementations that require special transformations + for smmu vmid. if this property exists vmid-transform + property must be present. + +- asid-transform : Transform mask that needs to be applied to asid. + This property has to be specified as '/bits/ 8' value. + +- vmid-transform : Transform mask that needs to be applied to vmid. + This property has to be specified as '/bits/ 8' value. + Example: smmu { diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 59ee4b8..8047834 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -300,8 +300,12 @@ struct arm_smmu_device { u32 features; #define ARM_SMMU_OPT_SECURE_CFG_ACCESS (1 << 0) +#define ARM_SMMU_OPT_TRANSFORM_ASID (1 << 1) +#define ARM_SMMU_OPT_TRANSFORM_VMID (1 << 2) u32 options; enum arm_smmu_arch_version version; + u8 asid_transform; + u8 vmid_transform; u32 num_context_banks; u32 num_s2_context_banks; @@ -330,8 +334,25 @@ struct arm_smmu_cfg { }; #define INVALID_IRPTNDX 0xff -#define ARM_SMMU_CB_ASID(cfg) ((cfg)->cbndx) -#define ARM_SMMU_CB_VMID(cfg) ((cfg)->cbndx + 1) +/* + * ThunderX has a unique requirement because of ERRATA#27704 + * An issue exists whereby the Linux kernel requires that ASIDs are a + * unique namespace per SMMU. That ASID-local choice conflicts with the + * CN88xx SMMU, where only shared ASID namespaces are supported; + * specifically within a given node SMMU0 and SMMU1 share, as does SMMU2 + * and SMMU3. + * CN88xx SMMU also requires global VMIDs. + */ + +#define ARM_SMMU_CB_ASID(smmu, cfg) \ + (((smmu)->options & ARM_SMMU_OPT_TRANSFORM_ASID) \ + ? ((cfg)->cbndx | (smmu)->asid_transform) \ + : ((cfg)->cbndx)) + +#define ARM_SMMU_CB_VMID(smmu, cfg) \ + (((smmu)->options & ARM_SMMU_OPT_TRANSFORM_VMID) \ + ? (((cfg)->cbndx + 1) | (smmu)->vmid_transform) \ + : ((cfg)->cbndx + 1)) enum arm_smmu_domain_stage { ARM_SMMU_DOMAIN_S1 = 0, @@ -361,6 +382,8 @@ struct arm_smmu_option_prop { static struct arm_smmu_option_prop arm_smmu_options[] = { { ARM_SMMU_OPT_SECURE_CFG_ACCESS, "calxeda,smmu-secure-config-access" }, + { ARM_SMMU_OPT_TRANSFORM_ASID, "thunderx,smmu-asid-transform" }, + { ARM_SMMU_OPT_TRANSFORM_VMID, "thunderx,smmu-vmid-transform" }, { 0, NULL}, }; @@ -570,11 +593,11 @@ static void arm_smmu_tlb_inv_context(void *cookie) if (stage1) { base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); - writel_relaxed(ARM_SMMU_CB_ASID(cfg), + writel_relaxed(ARM_SMMU_CB_ASID(smmu, cfg), base + ARM_SMMU_CB_S1_TLBIASID); } else { base = ARM_SMMU_GR0(smmu); - writel_relaxed(ARM_SMMU_CB_VMID(cfg), + writel_relaxed(ARM_SMMU_CB_VMID(smmu, cfg), base + ARM_SMMU_GR0_TLBIVMID); } @@ -596,7 +619,7 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned long iova, size_t size, if (!IS_ENABLED(CONFIG_64BIT) || smmu->version == ARM_SMMU_V1) { iova &= ~12UL; - iova |= ARM_SMMU_CB_ASID(cfg); + iova |= ARM_SMMU_CB_ASID(smmu, cfg); do { writel_relaxed(iova, reg); iova += granule; @@ -604,7 +627,7 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned long iova, size_t size, #ifdef CONFIG_64BIT } else { iova >>= 12; - iova |= (u64)ARM_SMMU_CB_ASID(cfg) << 48; + iova |= (u64)ARM_SMMU_CB_ASID(smmu, cfg) << 48; do { writeq_relaxed(iova, reg); iova += granule >> 12; @@ -624,7 +647,7 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned long iova, size_t size, #endif } else { reg = ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_TLBIVMID; - writel_relaxed(ARM_SMMU_CB_VMID(cfg), reg); + writel_relaxed(ARM_SMMU_CB_VMID(smmu, cfg), reg); } } @@ -752,7 +775,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, reg |= (CBAR_S1_BPSHCFG_NSH << CBAR_S1_BPSHCFG_SHIFT) | (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT); } else { - reg |= ARM_SMMU_CB_VMID(cfg) << CBAR_VMID_SHIFT; + reg |= ARM_SMMU_CB_VMID(smmu, cfg) << CBAR_VMID_SHIFT; } writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBAR(cfg->cbndx)); @@ -760,11 +783,11 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, if (stage1) { reg64 = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[0]; - reg64 |= ((u64)ARM_SMMU_CB_ASID(cfg)) << TTBRn_ASID_SHIFT; + reg64 |= ((u64)ARM_SMMU_CB_ASID(smmu, cfg)) << TTBRn_ASID_SHIFT; smmu_writeq(reg64, cb_base + ARM_SMMU_CB_TTBR0); reg64 = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[1]; - reg64 |= ((u64)ARM_SMMU_CB_ASID(cfg)) << TTBRn_ASID_SHIFT; + reg64 |= ((u64)ARM_SMMU_CB_ASID(smmu, cfg)) << TTBRn_ASID_SHIFT; smmu_writeq(reg64, cb_base + ARM_SMMU_CB_TTBR1); } else { reg64 = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; @@ -1793,6 +1816,22 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev) parse_driver_options(smmu); + if (smmu->options & ARM_SMMU_OPT_TRANSFORM_ASID) { + if (of_property_read_u8(dev->of_node, "#asid-transform", + &smmu->asid_transform)) { + dev_err(dev, "missing #asid-transform property\n"); + return -ENODEV; + } + } + + if (smmu->options & ARM_SMMU_OPT_TRANSFORM_VMID) { + if (of_property_read_u8(dev->of_node, "#vmid-transform", + &smmu->vmid_transform)) { + dev_err(dev, "missing #vmid-transform property\n"); + return -ENODEV; + } + } + if (smmu->version > ARM_SMMU_V1 && smmu->num_context_banks != smmu->num_context_irqs) { dev_err(dev,