From patchwork Fri Mar 4 18:39:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tirumalesh Chalamarla X-Patchwork-Id: 8507031 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 10733C0553 for ; Fri, 4 Mar 2016 18:41:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E36BC201FE for ; Fri, 4 Mar 2016 18:41:52 +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 C0DA520138 for ; Fri, 4 Mar 2016 18:41:51 +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 1abueD-0004tA-Mj; Fri, 04 Mar 2016 18:40:21 +0000 Received: from mail-bn1on0623.outbound.protection.outlook.com ([2a01:111:f400:fc10::623] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1abue9-0003d4-CX for linux-arm-kernel@lists.infradead.org; Fri, 04 Mar 2016 18:40:19 +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=upoejaaehPoltyth3Jc2RmTHg3JNFmijxVSejyx4m9I=; b=YjVJLWiGiZDh3/+OtWdwrRjAtaaVo8UfadaDdou55yKb7ERmKAZzrf/jE0F8ZktiDQTPNmnGLYTxst9JkMwPhG6xza92bg3Rf4ky9A6x6HPUARed/O4gO3/YWztjvGba8Hy8bSiWc6Bf575m6WgprCogfc2oRemZDRWYkdKx7ZA= 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 BY1PR0701MB1784.namprd07.prod.outlook.com (10.162.141.22) with Microsoft SMTP Server (TLS) id 15.1.415.20; Fri, 4 Mar 2016 18:39:54 +0000 From: Tirumalesh Chalamarla To: , , Subject: [PATCH V4] iommu/arm-smmu-v2: Workaround for ThunderX errata#27704 Date: Fri, 4 Mar 2016 10:39:44 -0800 Message-ID: <1457116784-13287-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: CO2PR06CA012.namprd06.prod.outlook.com (10.141.242.12) To BY1PR0701MB1784.namprd07.prod.outlook.com (25.162.141.22) X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1784; 2:PZTIAgHftury30KOTOSyQfOHf3qXJMCTYxjJ0maF2yGx7JkXN8zHupOgFuigWaOuUfJ2sdcBpFeAjU48UeiEEz5MFUypHWkwJYjwhBWHzNq/TkMvu33Bqh5gVu/fwZTSOen70x1z4yXb+AGCzGmgcw==; 3:p5ZjHyR2wSxc8HV8H1577Sb2ul+Auo0wv7+MK/JeLRWBaoOoMfNpYjYp8hM0QtK8LDgtbP3E/BjPiUfhIxQj0+lojn8Lm3xyNomeSUt4cMTX+na2zofK8ENKl7h/f285; 25:HVwIXlBha4H+ajbS2Zbz9TpQo56L/g7d3i12zy55MfTROlZVIWwI8ZIu/0UMEopXAGa2F2Zsr17Ekiajn3UocdfgUfPJDZTK6QE5vUxtYe0yzJRedJKwsLfHWDra+70+OGqmsYTho/UHUAGS9pKKxmhNkrHtPdyZeDTRAled2dfvwvsTAhtT6Mw1MaX4tc+udAcRn3Beu4t67sS4f7Lr9it7VlWxS1paFyFsXGEvQ42rFyrDByrOnzV22iwUmw6krKQKNSAS/FkoLhJf4Yq23V9cbmXXaEYdYExuOJf+/K0KWSyfzwyvXrdTIZ6rybN1BL8yu314LnvU19DKSfWlbg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1784; X-MS-Office365-Filtering-Correlation-Id: 6cc9eda9-8802-47da-e6f8-08d3445c6118 X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1784; 20:bjgZflNEBpnLd7nt3gozP4GlAjCF/k9QQZ03MLe/cvuppat58iCV9rBhhWS6S6iD+ND3w6y/MVfd4+zDHXeMm0Xq24YGaWGkM/FXCeyYU7D/0gxrqpER2h4n1HTeTO+kGahCGWemX9+HHBCrx22Lp+JuKhZss9+mNasF2p37oQwu0WADxZWvdLGvMvrDBUxoDHdnW4J/BriL05w7M5mzjvGKpKQQzCoa1IH280erT0Qdw2YVeRm4AHJUSTkBV7hxZ9AsmgQuT31FKNqUmLURkEwI3po8RTJrHTBd/RijsZdtls68GXZbnhY9LNcV7fO9NBYLGocCS8uKRQrYHiQDFnlzH6kQDiVYa87179ARfeQNvO82Tby/+3th5kSQU3wuaPtmwTVFn9XaIeqZm83M/EGqMLW7w4FPVroE4CU6P4dSPfWIHOsiGIks/GQ6B54e27XxHyGODHd5urM2S5bT+5QD2YWy2Kxr4ks8UaojI2oMMmIlgxR3HtEz0NV7ss/XHyEzbjXz7pnDD5i3klxvi2NGW3uS+OsZdNEb96jBA7Srx8sTebxb4NKX4aUGyj0N4KdcByyJZ3I4tpFFJsnETMWBOR8ZKssW/WNPwdogN+E= 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:BY1PR0701MB1784; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0701MB1784; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1784; 4:Kdv5gzfT07uWF3reWNO27/YIm5VAXPtRe4W8QtvJpY3uDpJlCEsADRF/Zqvb5pHRWl2fD8Wlg3JJvileCrSzYUaZE+piBXvA5iY8ffK6cHkLV6FsGGtRZIucm3W1cjwid1yiN1nOIt8EEh9efICDRnDH8ezcrsNNGYftK2sorfJ+iUWx2VlqPec95+Ty/3f6d4P1f1xQGgyYalX+kM0MN0gyz0xo/Mye3wS8hjqT2jWgn+Qswk7d6LcvFpm1U+nI8WQPco5T0HEle2p8HzJ6j+SNnhIfU1boDyc828CDWBo1dvWoTuTej5ZpCcP5cVBdOUfiyyomqIhlZ4O321koadoqpv4xe+pv8ENHQJqDpuNPJl2SEJh544/Amjg0o95q X-Forefront-PRVS: 0871917CDA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(575784001)(5008740100001)(81166005)(4326007)(230783001)(19580395003)(19580405001)(189998001)(3846002)(6116002)(77096005)(586003)(5003940100001)(1096002)(5004730100002)(5001770100001)(2201001)(229853001)(66066001)(33646002)(48376002)(40100003)(36756003)(122386002)(92566002)(2906002)(53416004)(42186005)(50466002)(47776003)(107886002)(50986999)(50226001)(87976001)(16060500001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0701MB1784; H:tiru-pc.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR0701MB1784; 23:t/WR7AHpZYn1HNwlg37hnWuxNANYc40Rnmi//Na?= =?us-ascii?Q?o938ubVskzkjmIH3Ibmj7nG9RK7LxKVXN6JB3zEz+f6I0Pn10iMpvTP4YiM/?= =?us-ascii?Q?5i0wYTzPCU/RVDVIpLzuc7gh75UKgabUHX54bLqJALpWJO2z50259FIpIxbm?= =?us-ascii?Q?Gs+2nLucw2ZpGeXVsW5MICsItcUHRbxfL8SwY7wCzeSnDvYW3E+xEuPijSIw?= =?us-ascii?Q?WauS/uAojcGpCTm6+w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Gs02W6DcfuOQq7klag8RyjFlcBie+YCvhsSW4p8KZPxrZsl4XbSENZJxZG52lE/sXCONp67oUdUjrAmA==; 24:abTizGST5uV+pm1HVsquGq+/lIAmGYe0VVAi8cUWNv+Przr/QCWjym+sRuNg9aXfOcwyoFW0my3gR3dYuLEH4LP73NjXlM7854y7navXeGA= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2016 18:39:54.1698 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1784 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160304_104018_186059_9E24B3F3 X-CRM114-Status: GOOD ( 12.74 ) 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(-) 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 /* if 16bit VMID supported set VMID 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)) { /*16 bit VMID is not supported set 8 bit VMID here */ - 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);