From patchwork Mon Jun 19 09:14:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9795563 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 BBE7E600C5 for ; Mon, 19 Jun 2017 09:19:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB93727C05 for ; Mon, 19 Jun 2017 09:19:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFED7283E7; Mon, 19 Jun 2017 09:19:06 +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=unavailable 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 399CE27C05 for ; Mon, 19 Jun 2017 09:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753960AbdFSJSs (ORCPT ); Mon, 19 Jun 2017 05:18:48 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35917 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752339AbdFSJSq (ORCPT ); Mon, 19 Jun 2017 05:18:46 -0400 Received: by mail-pf0-f194.google.com with SMTP id y7so15524878pfd.3; Mon, 19 Jun 2017 02:18:41 -0700 (PDT) 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=ScGy1LAPLWoqEIp9UYv303/8bWMI47Gdp4OH65OypXs=; b=ZO7Vjz0aNEvqiW22aO5Q/KS6qwvloBJ6VXsMden6kqjqYWJz6vxjKRx7TPTpoh2MJJ oXIlq948CmWM6FztfD2HgDzSsVtLUttY7qFf8qQQ+CWbq/0YtKYJBwiFM7Zz3rkSoAAT 5i8IjYDIUC1dmORuelbtZlAfXY1+awcyJBvB6sz5Nw6ZmKCPvoUkY3G20CnHK0WpXYpr 5F2zFOqpzlNMvOkVM2nP6fAL+jq+O5jaBeEcOSxpGc8+Y6k4+/VTvPPKA12BbUA0lvPp JJm5IuUrMrLCOyjL+0m6e9yrAH8OIuYdDqd0dNwptSixDp8FOnHkWlMtIuFuNVFZnypj 1cRQ== 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=ScGy1LAPLWoqEIp9UYv303/8bWMI47Gdp4OH65OypXs=; b=ZGEfeeLhUDyz1vEmHLAorL+ji8JSax36fUmOtpBtf9RZusUxblRRadcrd9GyxD3Coc GbzML7J6xmNOg0CePZjMHEG7CcetX8N0nVcy1o2HbjsCXGLOVJYvzjkt9E4XHPy3o2qb b83+Re2QdBJruEE27oJzMY+n6+pAMbshiTXbss5rRcmUn/f2vuyO/vEVsAn6McD7Q28Q NV0IP688RZ+pbEg33f6kp3IVmq5PmIWiPmQkePlYgiXBC4ngVlcYq+0sKSTuIo2xiZC8 1ko/VtwgBdBPzQdX+AI2K6rUArBY5XCl88Z9aevM8aJtVkJ/68gOzXHPLNHlooKBgzXI m2EA== X-Gm-Message-State: AKS2vOzK2fhVI+vbyYqHbdJ7WGKVeY4PAO0W4OY4A4VsI9xMUKYteG+C ZlxWygPu2NziFw== X-Received: by 10.99.126.67 with SMTP id o3mr24734462pgn.36.1497863915743; Mon, 19 Jun 2017 02:18:35 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id y9sm18279334pgc.27.2017.06.19.02.18.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 02:18:34 -0700 (PDT) From: Magnus Damm To: joro@8bytes.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, iommu@lists.linux-foundation.org, horms+renesas@verge.net.au, Magnus Damm , robin.murphy@arm.com, m.szyprowski@samsung.com Date: Mon, 19 Jun 2017 18:14:48 +0900 Message-Id: <149786368825.14868.10471030796615221922.sendpatchset@little-apple> In-Reply-To: <149786362527.14868.2143461703972595839.sendpatchset@little-apple> References: <149786362527.14868.2143461703972595839.sendpatchset@little-apple> Subject: [PATCH v4 06/09] iommu/ipmmu-vmsa: Write IMCTR twice 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 Write IMCTR both in the root device and the leaf node. To allow access of IMCTR introduce the following function: - ipmmu_ctx_write_all() While at it also rename context functions: - ipmmu_ctx_read() -> ipmmu_ctx_read_root() - ipmmu_ctx_write() -> ipmmu_ctx_write_root() Signed-off-by: Magnus Damm --- Changes since V3: - Changed function names to improve code readability - Thanks Robin! Changes since V2: - None Changes since V1: - None drivers/iommu/ipmmu-vmsa.c | 55 +++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) --- 0023/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-06-19 14:06:16.770607110 +0900 @@ -261,17 +261,28 @@ static void ipmmu_write(struct ipmmu_vms iowrite32(data, mmu->base + offset); } -static u32 ipmmu_ctx_read(struct ipmmu_vmsa_domain *domain, unsigned int reg) +static u32 ipmmu_ctx_read_root(struct ipmmu_vmsa_domain *domain, + unsigned int reg) { return ipmmu_read(domain->root, domain->context_id * IM_CTX_SIZE + reg); } -static void ipmmu_ctx_write(struct ipmmu_vmsa_domain *domain, unsigned int reg, - u32 data) +static void ipmmu_ctx_write_root(struct ipmmu_vmsa_domain *domain, + unsigned int reg, u32 data) { ipmmu_write(domain->root, domain->context_id * IM_CTX_SIZE + reg, data); } +static void ipmmu_ctx_write_all(struct ipmmu_vmsa_domain *domain, + unsigned int reg, u32 data) +{ + if (domain->mmu != domain->root) + ipmmu_write(domain->mmu, + domain->context_id * IM_CTX_SIZE + reg, data); + + ipmmu_write(domain->root, domain->context_id * IM_CTX_SIZE + reg, data); +} + /* ----------------------------------------------------------------------------- * TLB and microTLB Management */ @@ -281,7 +292,7 @@ static void ipmmu_tlb_sync(struct ipmmu_ { unsigned int count = 0; - while (ipmmu_ctx_read(domain, IMCTR) & IMCTR_FLUSH) { + while (ipmmu_ctx_read_root(domain, IMCTR) & IMCTR_FLUSH) { cpu_relax(); if (++count == TLB_LOOP_TIMEOUT) { dev_err_ratelimited(domain->mmu->dev, @@ -296,9 +307,9 @@ static void ipmmu_tlb_invalidate(struct { u32 reg; - reg = ipmmu_ctx_read(domain, IMCTR); + reg = ipmmu_ctx_read_root(domain, IMCTR); reg |= IMCTR_FLUSH; - ipmmu_ctx_write(domain, IMCTR, reg); + ipmmu_ctx_write_all(domain, IMCTR, reg); ipmmu_tlb_sync(domain); } @@ -425,31 +436,32 @@ static int ipmmu_domain_init_context(str /* TTBR0 */ ttbr = domain->cfg.arm_lpae_s1_cfg.ttbr[0]; - ipmmu_ctx_write(domain, IMTTLBR0, ttbr); - ipmmu_ctx_write(domain, IMTTUBR0, ttbr >> 32); + ipmmu_ctx_write_root(domain, IMTTLBR0, ttbr); + 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. */ - ipmmu_ctx_write(domain, IMTTBCR, IMTTBCR_EAE | - IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA | - IMTTBCR_IRGN0_WB_WA | IMTTBCR_SL0_LVL_1); + ipmmu_ctx_write_root(domain, IMTTBCR, IMTTBCR_EAE | + IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA | + IMTTBCR_IRGN0_WB_WA | IMTTBCR_SL0_LVL_1); /* MAIR0 */ - ipmmu_ctx_write(domain, IMMAIR0, domain->cfg.arm_lpae_s1_cfg.mair[0]); + ipmmu_ctx_write_root(domain, IMMAIR0, + domain->cfg.arm_lpae_s1_cfg.mair[0]); /* IMBUSCR */ - ipmmu_ctx_write(domain, IMBUSCR, - ipmmu_ctx_read(domain, IMBUSCR) & - ~(IMBUSCR_DVM | IMBUSCR_BUSSEL_MASK)); + ipmmu_ctx_write_root(domain, IMBUSCR, + ipmmu_ctx_read_root(domain, IMBUSCR) & + ~(IMBUSCR_DVM | IMBUSCR_BUSSEL_MASK)); /* * IMSTR * Clear all interrupt flags. */ - ipmmu_ctx_write(domain, IMSTR, ipmmu_ctx_read(domain, IMSTR)); + ipmmu_ctx_write_root(domain, IMSTR, ipmmu_ctx_read_root(domain, IMSTR)); /* * IMCTR @@ -458,7 +470,8 @@ static int ipmmu_domain_init_context(str * software management as we have no use for it. Flush the TLB as * required when modifying the context registers. */ - ipmmu_ctx_write(domain, IMCTR, IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); + ipmmu_ctx_write_all(domain, IMCTR, + IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); return 0; } @@ -484,7 +497,7 @@ static void ipmmu_domain_destroy_context * * TODO: Is TLB flush really needed ? */ - ipmmu_ctx_write(domain, IMCTR, IMCTR_FLUSH); + ipmmu_ctx_write_all(domain, IMCTR, IMCTR_FLUSH); ipmmu_tlb_sync(domain); ipmmu_domain_free_context(domain->root, domain->context_id); } @@ -500,11 +513,11 @@ static irqreturn_t ipmmu_domain_irq(stru u32 status; u32 iova; - status = ipmmu_ctx_read(domain, IMSTR); + status = ipmmu_ctx_read_root(domain, IMSTR); if (!(status & err_mask)) return IRQ_NONE; - iova = ipmmu_ctx_read(domain, IMEAR); + iova = ipmmu_ctx_read_root(domain, IMEAR); /* * Clear the error status flags. Unlike traditional interrupt flag @@ -512,7 +525,7 @@ static irqreturn_t ipmmu_domain_irq(stru * seems to require 0. The error address register must be read before, * otherwise its value will be 0. */ - ipmmu_ctx_write(domain, IMSTR, 0); + ipmmu_ctx_write_root(domain, IMSTR, 0); /* Log fatal errors. */ if (status & IMSTR_MHIT)