From patchwork Mon Oct 16 12:29:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 10008211 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 152D860230 for ; Mon, 16 Oct 2017 12:33:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B76C23794 for ; Mon, 16 Oct 2017 12:33:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0046E2841C; Mon, 16 Oct 2017 12:33:55 +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 A0C7C23794 for ; Mon, 16 Oct 2017 12:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752371AbdJPMbs (ORCPT ); Mon, 16 Oct 2017 08:31:48 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:43951 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752362AbdJPMbr (ORCPT ); Mon, 16 Oct 2017 08:31:47 -0400 Received: by mail-pf0-f195.google.com with SMTP id a8so15263638pfc.0; Mon, 16 Oct 2017 05:31:47 -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=Gl+6XZFCXFobg6YQz9oimxUtjhaBYNnA0n5x4C38LEE=; b=O2A2433Wf0cBSnG2PuJXc6IKSOQpzrGHBboMUYjYoLppgNylMaLWWRhhHOJ95+2Wzz Of9zw6dPbdOdr9CZ+WHrkNtS2jw0TlZa6Va13jjhzBdiaBvkanNdmntla2dEC+fPr/25 kqQzNPx4F+oVwDITSEt1p0BnIpL0Vnv7TTXsHdq3jInG/CeOtzESIfIpXHyGM1iiFTmg mnJyC2VKGOt+b+5W2KFIZkvTcqpfpm0ErCvLEOhYlkYOMDuLP2ikUO+ST3WN7XnyNhx6 1mzYnQPuOQOO55DS/fRdvxFv5Bxo4T1sLxxEGiIzC+dByRnLxYhuJ9bgEwQl0KHB1pQd 2VtQ== 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=Gl+6XZFCXFobg6YQz9oimxUtjhaBYNnA0n5x4C38LEE=; b=fAAgPmgClBQB141WQ6DvOv3I1JxP/PR1mfv+o2NyE+Vl87SWf7kGAaFIUa8eRuxwjl rIYIg1dO1bLeMu04iH2zGOQ36wJ7otnpLjxnFG5keQdevUaCTYlfjTPmBOw7RObdtXcP GD2HwobGnagRI+sFBGQn6f9iChIJfj/7+TcUVo6rY+LxqFa+lcAewK4R/0dAzx63yCQl oLjOliLqOKgn3VfWRjauTYb3tWWElBLOnsFxKlswwEErbKexbtZd7SpoLC27d+2R/J1+ VdQhGsyTpfD0xlLoZQyyN3rllEDBzHAu5JThZrqtTMIFvRk1CA1sqXKArC2iP6/iuEyb fC5w== X-Gm-Message-State: AMCzsaWF2tgOTUqanBcdDtghZ9SJhOfXtkZDXjQOI4kc8nMLgjYxhy+3 NRU2KwlIHTQpL3T0aPJ0PYvlKAAl X-Google-Smtp-Source: AOwi7QD7NynYFQcFfkUpTA30WI04SpU6ETEapRuIgLeVtrSH1j/lUX38IcXpvD35zNn2parBGCrb3w== X-Received: by 10.98.220.220 with SMTP id c89mr8517404pfl.167.1508157106781; Mon, 16 Oct 2017 05:31:46 -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 f24sm16100125pfk.183.2017.10.16.05.31.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Oct 2017 05:31:45 -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, 16 Oct 2017 21:29:46 +0900 Message-Id: <150815698669.32763.16753019201670130250.sendpatchset@little-apple> In-Reply-To: <150815695455.32763.1660214306749693609.sendpatchset@little-apple> References: <150815695455.32763.1660214306749693609.sendpatchset@little-apple> Subject: [PATCH v5 03/09] iommu/ipmmu-vmsa: Enable multi context 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 Add support for up to 8 contexts. Each context is mapped to one domain. One domain is assigned one or more slave devices. Contexts are allocated dynamically and slave devices are grouped together based on which IPMMU device they are connected to. This makes slave devices tied to the same IPMMU device share the same IOVA space. Signed-off-by: Magnus Damm --- Changes since V4: - None Changes since V3: - Use number_of_contexts unsigned int, drop WARN_ON() - Thanks Robin! Changes since V2: - Updated patch description to reflect code included in: [PATCH v7 00/07] iommu/ipmmu-vmsa: IPMMU multi-arch update V7 Changes since V1: - Support up to 8 contexts instead of 4 - Use feature flag and runtime handling - Default to single context drivers/iommu/ipmmu-vmsa.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) --- 0011/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-10-16 19:46:09.900607110 +0900 @@ -32,11 +32,12 @@ #include "io-pgtable.h" -#define IPMMU_CTX_MAX 1 +#define IPMMU_CTX_MAX 8 struct ipmmu_features { bool use_ns_alias_offset; bool has_cache_leaf_nodes; + unsigned int number_of_contexts; }; struct ipmmu_vmsa_device { @@ -46,6 +47,7 @@ struct ipmmu_vmsa_device { struct ipmmu_vmsa_device *root; const struct ipmmu_features *features; unsigned int num_utlbs; + unsigned int num_ctx; spinlock_t lock; /* Protects ctx and domains[] */ DECLARE_BITMAP(ctx, IPMMU_CTX_MAX); struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; @@ -352,11 +354,12 @@ static int ipmmu_domain_allocate_context spin_lock_irqsave(&mmu->lock, flags); - ret = find_first_zero_bit(mmu->ctx, IPMMU_CTX_MAX); - if (ret != IPMMU_CTX_MAX) { + ret = find_first_zero_bit(mmu->ctx, mmu->num_ctx); + if (ret != mmu->num_ctx) { mmu->domains[ret] = domain; set_bit(ret, mmu->ctx); - } + } else + ret = -EBUSY; spin_unlock_irqrestore(&mmu->lock, flags); @@ -409,8 +412,8 @@ static int ipmmu_domain_init_context(str * Find an unused context. */ ret = ipmmu_domain_allocate_context(domain->mmu->root, domain); - if (ret == IPMMU_CTX_MAX) - return -EBUSY; + if (ret < 0) + return ret; domain->context_id = ret; @@ -539,7 +542,7 @@ static irqreturn_t ipmmu_irq(int irq, vo /* * Check interrupts for all active contexts. */ - for (i = 0; i < IPMMU_CTX_MAX; i++) { + for (i = 0; i < mmu->num_ctx; i++) { if (!mmu->domains[i]) continue; if (ipmmu_domain_irq(mmu->domains[i]) == IRQ_HANDLED) @@ -603,6 +606,13 @@ static int ipmmu_attach_device(struct io /* The domain hasn't been used yet, initialize it. */ domain->mmu = mmu; ret = ipmmu_domain_init_context(domain); + if (ret < 0) { + dev_err(dev, "Unable to initialize IPMMU context\n"); + domain->mmu = NULL; + } else { + dev_info(dev, "Using IPMMU context %u\n", + domain->context_id); + } } else if (domain->mmu != mmu) { /* * Something is wrong, we can't attach two devices using @@ -946,13 +956,14 @@ static void ipmmu_device_reset(struct ip unsigned int i; /* Disable all contexts. */ - for (i = 0; i < 4; ++i) + for (i = 0; i < mmu->num_ctx; ++i) ipmmu_write(mmu, i * IM_CTX_SIZE + IMCTR, 0); } static const struct ipmmu_features ipmmu_features_default = { .use_ns_alias_offset = true, .has_cache_leaf_nodes = false, + .number_of_contexts = 1, /* software only tested with one context */ }; static const struct of_device_id ipmmu_of_ids[] = { @@ -1006,6 +1017,9 @@ static int ipmmu_probe(struct platform_d if (mmu->features->use_ns_alias_offset) mmu->base += IM_NS_ALIAS_OFFSET; + mmu->num_ctx = min_t(unsigned int, IPMMU_CTX_MAX, + mmu->features->number_of_contexts); + irq = platform_get_irq(pdev, 0); /*