From patchwork Mon Jan 23 11:52:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9532335 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 D1E1C60434 for ; Mon, 23 Jan 2017 12:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9A1D282F5 for ; Mon, 23 Jan 2017 12:00:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE7312831B; Mon, 23 Jan 2017 12:00:23 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 BB28A282F5 for ; Mon, 23 Jan 2017 12:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751101AbdAWMAV (ORCPT ); Mon, 23 Jan 2017 07:00:21 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33932 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbdAWMAU (ORCPT ); Mon, 23 Jan 2017 07:00:20 -0500 Received: by mail-pg0-f66.google.com with SMTP id t6so13612506pgt.1 for ; Mon, 23 Jan 2017 03:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:date:message-id:subject; bh=Nx0RNn9OhDIX8zaxzu5921+aI0udpLmlrnU0NjriZtE=; b=PLZ+95aO4ZFg24/3rBPMEawhim3lk+bVVSHZTJwyUmVgeMafXFBleYgkaIvbVn0+eX pJKdtA2LIhCaAubj2aCP1Qj/33lerUOEaz8X4UWpc7FPjw4k7No1aNg4LG7YOgvA2uRC Qp3mb0L8mL6VrSXPV69egBpUz4H46fHQIqYUNumF6MMJRoy9325OjUvuoWqg+NlyBlpT x+y/1UnP9p/yylrLCxC7qhXwVVPSBZBLArZig1SXWK6LC0YUuXlYZlN2aYUtnCl6muHX 7988zXRXLexvcbbFFzGJPEPSNGB8ryDOVfhRfIFrrVETeSeT7DYcafolqFBx7hTUhCGf T9oQ== 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:subject; bh=Nx0RNn9OhDIX8zaxzu5921+aI0udpLmlrnU0NjriZtE=; b=fM9BYVdyIZxNjMNys0oXUffFa30KOI7VJZcBDKlbN4sAlq8rAGAO1my5Pi0sERqd2N h68te0PbMoVsTziL4Q5+EaUAFRtov41PSnJhKW7VY3vfWWt3pHuZ6Jmv+p9eGDafN8sW TMyB/u6mRsrEJjePknzK2FSxiz29OHl3o29RMYtz2wtiXjRhoB2t/Woop3ztdHAYPwGT mbafobY6u/kP10toTzoKwJilp7lBmNeaZZ47xACETGCKW/Zc+Qw+3ic4bCaLlRlUE/Nk t+fF3GoqTrqtWVH0fhWBZQMRjzTeXCLhvLiT1UwSVmg78YtCXnlBejLgOgDwwfR1HUXo h9bw== X-Gm-Message-State: AIkVDXIaUjCKIguYRffBPhWg5aZZYXPKHahjQ+vOt6dn+wXxselAYDitUZJupsyn9r7pKg== X-Received: by 10.84.141.164 with SMTP id 33mr42574403plv.86.1485172745339; Mon, 23 Jan 2017 03:59:05 -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 184sm34478327pgj.5.2017.01.23.03.59.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jan 2017 03:59:04 -0800 (PST) From: Magnus Damm To: linux-renesas-soc@vger.kernel.org Cc: horms+renesas@verge.net.au, Magnus Damm , laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be Date: Mon, 23 Jan 2017 20:52:43 +0900 Message-Id: <148517236353.14544.12595546402748556370.sendpatchset@little-apple> Subject: [PATCH/RFC] iommu/ipmmu-vmsa: Initial R-Car Gen3 VA64 mode support 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 Here's a prototype that enables IMCTR_VA64 support for the IPMMU driver on R-Car Gen3 platforms. I've tested it lightly on r8a7796 Salvator-X with local second serial port code and SYS-DMAC support via DMA Engine. My goal has been to enable 40 bits or more of IOVA space, but it turns out that it requires either 64K page size support or support for 4K pages starting from level 0. For now this keeps 32-bit IOVA space however the hardware gets configured to enable IMCTR_VA64 which also seems to require setting up TSZ0[5:0]. Signed-off-by: Magnus Damm --- Developed on top of renesas-drivers-2017-01-10-v4.10-rc3 drivers/iommu/ipmmu-vmsa.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) --- 0001/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-01-23 20:43:31.200607110 +0900 @@ -39,6 +39,7 @@ struct ipmmu_features { bool has_eight_ctx; bool setup_imbuscr; bool twobit_imttbcr_sl0; + bool imctr_va64; }; struct ipmmu_vmsa_device { @@ -117,6 +118,7 @@ static void set_archdata(struct device * #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) @@ -430,8 +432,9 @@ static int ipmmu_domain_init_context(str */ domain->cfg.iommu_dev = domain->root->dev; - domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, - domain); + domain->iop = alloc_io_pgtable_ops(domain->root->features->imctr_va64 ? + ARM_64_LPAE_S1 : ARM_32_LPAE_S1, + &domain->cfg, domain); if (!domain->iop) return -EINVAL; @@ -462,6 +465,12 @@ static int ipmmu_domain_init_context(str else tmp = IMTTBCR_SL0_LVL_1; + /* + * For IMCTR_VA64 and ARM_64_LPAE_S1 we need lowest bits of TTBCR + */ + if (domain->root->features->imctr_va64) + tmp |= 32; + ipmmu_ctx_write(domain, IMTTBCR, IMTTBCR_EAE | IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA | IMTTBCR_IRGN0_WB_WA | tmp); @@ -488,7 +497,8 @@ static int ipmmu_domain_init_context(str * required when modifying the context registers. */ ipmmu_ctx_write2(domain, IMCTR, - IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); + (domain->root->features->imctr_va64 ? IMCTR_VA64 : 0) + | IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); return 0; } @@ -1098,6 +1108,7 @@ static const struct ipmmu_features ipmmu .has_eight_ctx = false, .setup_imbuscr = true, .twobit_imttbcr_sl0 = false, + .imctr_va64 = false, }; static const struct ipmmu_features ipmmu_features_rcar_gen3 = { @@ -1106,6 +1117,7 @@ static const struct ipmmu_features ipmmu .has_eight_ctx = true, .setup_imbuscr = false, .twobit_imttbcr_sl0 = true, + .imctr_va64 = true, }; static const struct of_device_id ipmmu_of_ids[] = {