From patchwork Fri Mar 4 21:56:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tirumalesh Chalamarla X-Patchwork-Id: 8507951 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 B034DC0553 for ; Fri, 4 Mar 2016 21:58:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A01420268 for ; Fri, 4 Mar 2016 21:58:57 +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 6D76120260 for ; Fri, 4 Mar 2016 21:58:56 +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 1abxiH-0005uB-RE; Fri, 04 Mar 2016 21:56:45 +0000 Received: from mail-bl2on0089.outbound.protection.outlook.com ([65.55.169.89] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1abxiD-0005r3-5x for linux-arm-kernel@lists.infradead.org; Fri, 04 Mar 2016 21:56:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3VsSCLDdKfMNkIaVibW9LgL5R3Rr5TLpKCQs872YV1k=; b=udBNZe8GhVMj59SZN5FPzS/JujQZMXQ5NLop2nLyokFAKDVzqRsLQ0504GeSpsAqVCZ1QDpcePbRgxn8+EwBMf2t8jpzQo/OzeBjTdwPqMH1bszugtdLmYeoohd4uA9MRvi7yKTZP7lZdVaVQ7dxHyce+bj06uqBDKr2FlwN4ko= 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.415.20; Fri, 4 Mar 2016 21:56:17 +0000 From: Tirumalesh Chalamarla To: , , Subject: [PATCH V4] iommu/arm-smmu-v2: Workaround for ThunderX errata#27704 Date: Fri, 4 Mar 2016 13:56:09 -0800 Message-ID: <1457128569-13878-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: BY2PR11CA0052.namprd11.prod.outlook.com (25.163.150.148) To BY1PR0701MB1783.namprd07.prod.outlook.com (25.162.141.21) X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 2:3FGyKYrUbE324YdIwWrcTQhL8zfEnQ/IJzIHKwiIOPgIJOcTZeqWpqkUTk7AHOLyMApZE+Mra2XQ5NY6ZmuczUTnODSJFzuBQMNIAMM4/U9YfLCK15RmOaeklWvpT7yES2w9D5SbdnD4OyQJRr3yqg==; 3:dtPDqUA91Ddiio3KV5KuofQSfjncrwwGlAo3UwQ+W8PZGEbplu0m0hwTyZT5hzVZBClVVYOOZH2WUXg6D3CYMYxSkX8FH/edpXb9QnEpQ/7sYWu0t6Fb/0v7Te8/cfM6; 25:QcvMnRLmT5Ycas42s7LbyYfEHqFFzgHjGK7tvThTgsdOr2oFKGt8JAI0WRMrolfRTVCGngTKAPChd3Ltf+IYwpVdOo6EjA66/L+w2xw6utYKQWhWHuaTZzIwCn/2eq7f/i0eKzme5uOvMMz472u3rlf3fURiTolCi0cPNu8VvyIG6oLVaSyUkaQEYzX8mLDFyWsRjJnu3tok0bkAZOAaEEgqEaL7D9fnxzwpCH61qXcIfz2N95WvL3mfoKUsBGlXXJ/4YHc/irWk20oyDjH29/PJF3KVXW11v1bLHmM8IgkoNPRgeQ7RB//YO+dbTxnWmDh2YQ/dRe1G8PxcIpOmnA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1783; X-MS-Office365-Filtering-Correlation-Id: c38ad71e-d6ab-4e0d-fe57-08d34477d08a X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 20:IbZBdmRI0uFGOqzqUrIc0Ckskjhy5oFGvwaK/z8j02j3rC5qYfgzhFzfXxbxci9jzVEIKq57REIT47u3fcffxhn+MpCKC1NzqJ/S0Yo9qUJNVUyk+CLGeC+CiKAskTmuen2wgJVB84hos9qaHAWas+V0JE6wz5X1J7WsqKtMZcS/R0S7T95qh+0yAHaGQbR/y0rkVqt5QgxeL5vJBQMO1OV2LnMHaxGNNF+OB6IK3lfaJlujHX1jhkHY4CET3pp0wPKabbCA7+03xQrYCssiPK1GFNu0oPPix+iAdTsc9zxFHcxgOrmqbWP33NFwSPZA2rAnEfkPpQ/4yqrQZGep268mA85Y6NO4YqOvVeU/DMW/u0BmwlaHHorIMze/P68PNRwPj2p/Z7g3kFKiUL3eMTgtKAg/sc6jlXp0F1+3tAH2nC7vIimt2YLG40cunZeJ5BBIumCxUU0g/qvoVo5VliGPSJhYsoRZbBJFvAzuw52yYIJsNhEkBTYU8R7PyNBCznQpnFSVKLyR8FugPuq+H8G8Qa2Iwz+A6lfBhd5+06QRdHSMzGfAjTjwdXz04b7+bE9P7rloAP5L8v74Cd88m+n3jombBrGUJ9zI8BkagEM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BY1PR0701MB1783; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0701MB1783; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 4:r6u3ikh4FFjq+Yn0lDBNqdhN/g4y8LKWONefqbyb5AJ/VLCjAKI9q3ZiVi+XHsL2RmArQMTEzt//iSMGHSWKEQL3HkK7VOoU30e4CfEtzV0XOaqPU7IBPdjs2W8SGx6b8CD1XUElreZPj5DX6eqrUAlwkpe2tQVeXUwmJB+KGwlHzF6c50oX8rQIP9h+wZt3vqAHGK75DkVc5Z0f++yDgiHyyqJ0WkN9hmibPVQ/WnVFIQC1f4rZESFHG/5L9ra3VZx5o+FVuWvcJJU0jQrXJi7goKtB7o3qKKYt632ET9M6tlFO5X8dumUe6M13c2eUX3B9jEW05+yzZVN5KpfCrMDXZ7UPlDJUC6/IM3YNmPkx8fXDfJyWKRklE+xmslGr X-Forefront-PRVS: 0871917CDA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(42186005)(5008740100001)(107886002)(5001770100001)(53416004)(122386002)(48376002)(19580405001)(19580395003)(50226001)(4326007)(230783001)(3846002)(6116002)(47776003)(2906002)(2201001)(586003)(50986999)(66066001)(1096002)(229853001)(81166005)(36756003)(5004730100002)(87976001)(5003940100001)(189998001)(92566002)(575784001)(50466002)(33646002)(40100003)(4001430100002)(77096005)(16060500001); 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:NzTX/o4KbwO/tE6NcWeFP3XnSzbKvaS3TvbZ647?= =?us-ascii?Q?vtqfU7Kf/+PAqdXpbQiGu0K4n3+So3S9k2SAfe1QY7hCVXjbQ1fMFxn1+Lde?= =?us-ascii?Q?PpcWZdN2wyflLqiraJOLTSJwTVgPjbZi8VmxIqBz4WPj/3W4m+7NM4dI3tGH?= =?us-ascii?Q?7NCtH2Rrp4Rj4E4lzySoQmG4F4fXztDoxFpaGOViEauFik+3LKjdB7wDEwWj?= =?us-ascii?Q?pP5FGJ/VHBJ+2/Gr9PwhcNh50rJsCVrkUaaZttvCeHZ9WC/TRheKXRvMWG0g?= =?us-ascii?Q?GVZosZNkseDzmW2iQYgvadblOmUerophysRjZbRl8btilf0zpG//wfIBcUlW?= =?us-ascii?Q?pNRTnPOCojrAoDuueCY3G1ZA6xsumacZTS2fqQXkOk8C01MqYGHz6sME1tYR?= =?us-ascii?Q?ExIk4PAp0idEY9jOIrNVv6Od8A7BcVFB5yn7au0yyuc0QN3UGbJJkSA4pFtn?= =?us-ascii?Q?kSZsGfwdxQaEqy20NDb4EBJVtzT9g6B7rbtobbX/KssI7ayI8zlHua1EQbDX?= =?us-ascii?Q?tesM+p2nvBPK8I5IYeY3yr2BEQyvfWd/vAUZU8Q9UjVD87CN1k7UfSVOExn7?= =?us-ascii?Q?L0FWjuJbJ2yYyhvngrJqS0WoiYqF517N0jA7ItW3bLjg4tHztfUOELrQdNr0?= =?us-ascii?Q?olZCGuZ3eKmiityJ5dMRDiyCMdGK4LBxDuW58QR6Sgxv/ADzo31qUlaC+mMv?= =?us-ascii?Q?yM7xbUGoNcsifWQ28X6oTpMZ6lU4qNVeJzBx7V03A5yGNJAKWsFdvkAfCDQg?= =?us-ascii?Q?cvymBGjuIri60BEuZgCeC07OvseiRVl7LPXu4zS37pzsaQS9mUFr1ikPJax5?= =?us-ascii?Q?SR35VFCeVS9qpxEYcxf8A+tgopwQRvnRM9770XJ5dOZYsrRP5qhrDkGyXe69?= =?us-ascii?Q?QHHlo7bkcWLz+ZVoM04fAyWmljsLb2+AQVeu5uO7Yd8c0Ec44HTzt/oImHIA?= =?us-ascii?Q?FTPTc0GxOy56Rj70mhwFpy8Qkn6fe35AE6qEygOaDD24FHM55ihPAleI3nho?= =?us-ascii?Q?HYENgwwZOoueInIgdMBQ5d3xz4Hbx8b97vMxsfuC+DAA073OPscz/K+TsL4Z?= =?us-ascii?Q?qpDKT18I=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1783; 5:eE/7Xl4vy/wKuuCauzW7xFzLCC95Khq7o70f0N5OPih+8Ryg+LLW4W8/VXPPVZ/ex9By/uZSgou7NHfdEbdXtfXSimm3wGlq/UUTHGCiUzrelm1RHZyUU8nR+4T6/bDWFLCzxQKEGQuThWgO2Nfatw==; 24:c1ZZVuEKTj/FrCTpCDcVb79+baz8XPO48QMhlMDN3dIgU/Yj8s9ha3m9B5oyPMnzwE7MGBAzCZ++0KMpqgtrRJf47+OdK1rFoh4gNO3BZIw= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2016 21:56:17.9157 (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-20160304_135642_004210_FE4B6CFF X-CRM114-Status: GOOD ( 13.69 ) 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.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, 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 Due to Errata#27704 CN88xx SMMUv2,supports only shared ASID and VMID namespaces; specifically within a given node SMMU0 and SMMU1 share, as does SMMU2 and SMMU3. This patch make sure ASID and VMID space is unique across cavium SMMUv2. changes from V3: - Removed redundent variable. - Used atomic_t for maintaining running total changes from V2: - removed *_base from DT, and replaced with compatible string changes from V1: - rebased on top of 16 bit VMID patch - removed redundent options from DT - insted of transform, DT now supplies starting ASID/VMID Signed-off-by: Tirumalesh Chalamarla Signed-off-by: Akula Geethasowjanya --- Documentation/arm64/silicon-errata.txt | 1 + .../devicetree/bindings/iommu/arm,smmu.txt | 1 + drivers/iommu/arm-smmu.c | 42 ++++++++++++++++------ 3 files changed, 33 insertions(+), 11 deletions(-) -- 2.1.0 diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt index 58b71dd..3747a4b 100644 --- a/Documentation/arm64/silicon-errata.txt +++ b/Documentation/arm64/silicon-errata.txt @@ -56,3 +56,4 @@ stable kernels. | | | | | | Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 | | Cavium | ThunderX GICv3 | #23154 | CAVIUM_ERRATUM_23154 | +| Cavium | ThunderX SMMUv2 | #27704 | N/A | diff --git a/Documentation/devicetree/bindings/iommu/arm,smmu.txt b/Documentation/devicetree/bindings/iommu/arm,smmu.txt index 7180745..19fe6f2 100644 --- a/Documentation/devicetree/bindings/iommu/arm,smmu.txt +++ b/Documentation/devicetree/bindings/iommu/arm,smmu.txt @@ -16,6 +16,7 @@ conditions. "arm,mmu-400" "arm,mmu-401" "arm,mmu-500" + "cavium,smmu-v2" depending on the particular implementation and/or the version of the architecture implemented. diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 247a469..e793b0a 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -326,6 +326,11 @@ struct arm_smmu_device { struct list_head list; struct rb_root masters; + /* + *The following fields are specific to Cavium, Thunder + */ + u32 cavium_id_base; + }; struct arm_smmu_cfg { @@ -335,8 +340,8 @@ 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) +#define ARM_SMMU_CB_ASID(smmu, cfg) ((u16)(smmu)->cavium_id_base + (cfg)->cbndx) +#define ARM_SMMU_CB_VMID(smmu, cfg) ((u16)(smmu)->cavium_id_base + (cfg)->cbndx + 1) enum arm_smmu_domain_stage { ARM_SMMU_DOMAIN_S1 = 0, @@ -364,6 +369,8 @@ struct arm_smmu_option_prop { const char *prop; }; +static atomic_t cavium_smmu_context_count = ATOMIC_INIT(0); + static struct arm_smmu_option_prop arm_smmu_options[] = { { ARM_SMMU_OPT_SECURE_CFG_ACCESS, "calxeda,smmu-secure-config-access" }, { 0, NULL}, @@ -575,11 +582,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); } @@ -601,7 +608,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; @@ -609,7 +616,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; @@ -629,7 +636,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); } } @@ -738,7 +745,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, #endif /* 16-bit VMIDs live in CBA2R */ if (smmu->features & ARM_SMMU_FEAT_VMID16) - reg |= ARM_SMMU_CB_VMID(cfg) << CBA2R_VMID_SHIFT; + reg |= ARM_SMMU_CB_VMID(smmu, cfg) << CBA2R_VMID_SHIFT; writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBA2R(cfg->cbndx)); } @@ -757,7 +764,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT); } else if (!(smmu->features & ARM_SMMU_FEAT_VMID16)) { /* 8-bit VMIDs live in CBAR */ - 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)); @@ -765,11 +772,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; @@ -1717,6 +1724,7 @@ static const struct of_device_id arm_smmu_of_match[] = { { .compatible = "arm,mmu-400", .data = (void *)ARM_SMMU_V1 }, { .compatible = "arm,mmu-401", .data = (void *)ARM_SMMU_V1 }, { .compatible = "arm,mmu-500", .data = (void *)ARM_SMMU_V2 }, + { .compatible = "cavium,smmu-v2", .data = (void *)ARM_SMMU_V2 }, { }, }; MODULE_DEVICE_TABLE(of, arm_smmu_of_match); @@ -1826,6 +1834,18 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev) goto out_free_irqs; } } + /* + * Due to Errata#27704 CN88xx SMMUv2,supports only shared ASID and VMID + * namespaces; specifically within a given node SMMU0 and SMMU1 share, + * as does SMMU2 and SMMU3. see if this is a Cavium SMMU, if so + * set asid and vmid base such that each SMMU gets unique + * asid/vmid space. + */ + if (of_device_is_compatible(dev->of_node, "cavium,smmu-v2")) { + smmu->cavium_id_base = atomic_add_return(smmu->num_context_banks, + &cavium_smmu_context_count); + smmu->cavium_id_base -= smmu->num_context_banks; + } INIT_LIST_HEAD(&smmu->list); spin_lock(&arm_smmu_devices_lock);