From patchwork Sat Nov 18 04:26:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 10064329 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCC4B6023A for ; Sat, 18 Nov 2017 04:27:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C84312924C for ; Sat, 18 Nov 2017 04:27:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD3482AD54; Sat, 18 Nov 2017 04:27:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DB502924C for ; Sat, 18 Nov 2017 04:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161510AbdKRE1t (ORCPT ); Fri, 17 Nov 2017 23:27:49 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:38253 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161502AbdKRE1s (ORCPT ); Fri, 17 Nov 2017 23:27:48 -0500 Received: by mail-pf0-f194.google.com with SMTP id r62so3387247pfd.5 for ; Fri, 17 Nov 2017 20:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=hBKKEo2RGU8U9RQlAycVFTN0kw0zA9UOwFTpzP3snfE=; b=WFoo0NwVFtZd+a3EZdBfpciriv4Herwf8hilfJfQsbEFdJiW9nIbK+KYmNEVZPKKUt TR/R7Vw3iE6RViKhExexdhxY9bnRtren+42x9LXlEuqXsAk7iQg54NBQaHSirSvhskvX I7oy4lhhlMhVCMV0PWdXrTRrMrVcdY2/JAZMWzsXqm1LsTgFBgAYAKh3fMj4U7d5mRM7 3xyzx7Qzj79oGqMXDhFpD4u8deJJBlrdAZhe+OkhUPx5bbR7dDua0CEdiqPrA/3oEodF HEcBQGQVPbu+KKWjzWHY43xHfw89ExnlBNPrvLFiJwmp/Ur8E8DndDRy4sSUlJf4lVuT vNfg== 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:date:message-id:in-reply-to :references:subject; bh=hBKKEo2RGU8U9RQlAycVFTN0kw0zA9UOwFTpzP3snfE=; b=M6BFID0cCIJkHOAEsuxGfC2+k/vTHxTOsxfu0+NRXhwXChNXHpK7qvkoH7ir8BUfBP b/4OcmB8+Rxfkh3Sim01wtDLWmYUrgQVCac7H7LCWWNZNrAupUq58qX0BzmEcOJzKrs7 VjnYFG1uUW133dwYz9cybF6/4mcaOBgabxNdcffaBdWf2xpKZp1nozsfnjhmQ/7xVt2w RXvjoJUVs4Y0tPQVxRU3X9bRn/3DQe2F/AprEf6/rL6erhJPGJcl9pgNzjlhFeRGz6cs O/1lI6w7UWhZhbIzz5IAae3NYQUSHu/Ra438L9oLOBoZdQJSCr0O+kBhCxg2/dAZanYR Zgbw== X-Gm-Message-State: AJaThX48TAI/hvNUJ8N0a/4JHW3vk5ddyDCaXmtarL+i/4s7MMwMULTQ 4C71T28T5fMr3QShwMLl2o9QYZth X-Google-Smtp-Source: AGs4zMbm3jK6z3WyNI/slDVhxT8OmR8upebL/ZDknn/Uhczc+EGO3MT5hIYHWYWYxzR8tg6ktAvnyw== X-Received: by 10.98.129.4 with SMTP id t4mr4281206pfd.125.1510979267345; Fri, 17 Nov 2017 20:27:47 -0800 (PST) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id c11sm7459608pgv.42.2017.11.17.20.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Nov 2017 20:27:45 -0800 (PST) From: Magnus Damm To: linux-renesas-soc@vger.kernel.org Cc: Magnus Damm Date: Sat, 18 Nov 2017 13:26:17 +0900 Message-Id: <151097917767.24365.455036878830340615.sendpatchset@little-apple> In-Reply-To: <151097915979.24365.675151091819205104.sendpatchset@little-apple> References: <151097915979.24365.675151091819205104.sendpatchset@little-apple> Subject: [PATCH/RFC 02/04] iommu/ipmmu-vmsa: VA64 mode with 32-bit IOVA Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm Hack up the IPMMU driver to enable VM64 mode with 32-bit IOVA. For this configuration the IPMMU hardware is configured with IMTTBCR.SL=1 and TSZ0 bits set to 0x20. This will enable a 32-bit IOVA space and use "Initial lookup level 1" (in Table D4-13 of armv8_arm.pdf) also known as "Start at first level" in IPMMU documentation. Not for upstream merge. Tested on ULCB with r8a7796 ES1.0. Earlier version posted as: [PATCH/RFC] iommu/ipmmu-vmsa: Initial R-Car Gen3 VA64 mode support The SL bit position has since then been updated to match more recent IPMMU hardware documentation. Not-Yet-Signed-off-by: Magnus Damm --- drivers/iommu/ipmmu-vmsa.c | 36 +++++++++++++++++++++++++----------- 1 files changed, 25 insertions(+), 11 deletions(-) --- 0009/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-11-17 13:17:33.510607110 +0900 @@ -42,6 +42,7 @@ struct ipmmu_features { unsigned int number_of_contexts; bool setup_imbuscr; bool twobit_imttbcr_sl0; + bool imctr_va64; }; struct ipmmu_vmsa_device { @@ -97,6 +98,7 @@ static struct ipmmu_vmsa_iommu_priv *to_ #define IM_CTX_SIZE 0x40 #define IMCTR 0x0000 +#define IMCTR_VA64 (1 << 29) #define IMCTR_TRE (1 << 17) #define IMCTR_AFE (1 << 16) #define IMCTR_RTSEL_MASK (3 << 4) @@ -442,8 +444,9 @@ static int ipmmu_domain_init_context(str domain->context_id = ret; - domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, - domain); + domain->iop = alloc_io_pgtable_ops(domain->mmu->features->imctr_va64 ? + ARM_64_LPAE_S1 : ARM_32_LPAE_S1, + &domain->cfg, domain); if (!domain->iop) { ipmmu_domain_free_context(domain->mmu->root, domain->context_id); @@ -456,14 +459,22 @@ static int ipmmu_domain_init_context(str ipmmu_ctx_write_root(domain, IMTTUBR0, ttbr >> 32); /* - * TTBCR - * We use long descriptors with inner-shareable WBWA tables and allocate - * the whole 32-bit VA space to TTBR0. - */ - if (domain->mmu->features->twobit_imttbcr_sl0) - tmp = IMTTBCR_SL0_TWOBIT_LVL_1; - else - tmp = IMTTBCR_SL0_LVL_1; + * For IMCTR_VA64 and ARM_64_LPAE_S1 we need lowest bits of TTBCR + */ + if (domain->mmu->features->imctr_va64) { + tmp = (1 << 6) | 0x20; + } else { + /* + * TTBCR + * We use long descriptors with inner-shareable WBWA tables + * and allocate the whole 32-bit VA space to TTBR0. + */ + + if (domain->mmu->features->twobit_imttbcr_sl0) + tmp = IMTTBCR_SL0_TWOBIT_LVL_1; + else + tmp = IMTTBCR_SL0_LVL_1; + } ipmmu_ctx_write_root(domain, IMTTBCR, IMTTBCR_EAE | IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA | @@ -493,7 +504,8 @@ static int ipmmu_domain_init_context(str * required when modifying the context registers. */ ipmmu_ctx_write_all(domain, IMCTR, - IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); + (domain->mmu->features->imctr_va64 ? IMCTR_VA64 : 0) + | IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); return 0; } @@ -1018,6 +1030,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 1, /* software only tested with one context */ .setup_imbuscr = true, .twobit_imttbcr_sl0 = false, + .imctr_va64 = false, }; static const struct ipmmu_features ipmmu_features_rcar_gen3 = { @@ -1026,6 +1039,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 8, .setup_imbuscr = false, .twobit_imttbcr_sl0 = true, + .imctr_va64 = true, }; static const struct of_device_id ipmmu_of_ids[] = {