From patchwork Tue Dec 15 13:05:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 7854641 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@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 A7919BEEE1 for ; Tue, 15 Dec 2015 13:06:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB4A220304 for ; Tue, 15 Dec 2015 13:06:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 407ED20389 for ; Tue, 15 Dec 2015 13:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933145AbbLONDu (ORCPT ); Tue, 15 Dec 2015 08:03:50 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:35023 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbbLONDt (ORCPT ); Tue, 15 Dec 2015 08:03:49 -0500 Received: by mail-pa0-f47.google.com with SMTP id hk6so4589539pad.2; Tue, 15 Dec 2015 05:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=5fCxRpwI0FFbL28p8kWGruvp+vJ4ZvJr09tyieWLzmo=; b=TrRschXwlbOqFEdDLau668JYzE5wOrbj0t5Mcv6XxWjOV8ExK7USjqJtnPcvd0cuT/ HErS4CtZSvKGIao96vz+P4tIV377jlheCzgLzDc9NECmw+tOx301x3qMO86DNWvxzye8 v3P/064qgFZPiQR4gPrR6E9nN3AUWr89NopaSxPQ7BxqfkHd05mfafjEwW9BxUckgiwG qlUt3AXKXu42TbIsczJqC9TZSUyyiu/oNuu8ARy08zdUAeKB17Eoh53HYSrT4M0RmkKv 5snLuO9UdDTMW6XJW9SJ/mITVDSl571D8HquvPOqLcRU4d3ayuX7ep+w6ob1I5GG3IX0 uQbg== X-Received: by 10.66.216.73 with SMTP id oo9mr54127966pac.148.1450184628300; Tue, 15 Dec 2015 05:03:48 -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 186sm2356920pfa.24.2015.12.15.05.03.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Dec 2015 05:03:46 -0800 (PST) From: Magnus Damm To: iommu@lists.linux-foundation.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, linux-sh@vger.kernel.org, joro@8bytes.org, linux-kernel@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm Date: Tue, 15 Dec 2015 22:05:27 +0900 Message-Id: <20151215130527.13535.63386.sendpatchset@little-apple> In-Reply-To: <20151215130508.13535.26186.sendpatchset@little-apple> References: <20151215130508.13535.26186.sendpatchset@little-apple> Subject: [PATCH/RFC 02/10] iommu/ipmmu-vmsa: Add optional root device feature Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 From: Magnus Damm Add root device handling to the IPMMU driver by allowing certain DT compat strings to enable had_cache_leaf_nodes that in turn will support both root devices with interrupts and leaf devices that face the actual IPMMU consumer devices. Signed-off-by: Magnus Damm --- drivers/iommu/ipmmu-vmsa.c | 86 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 17 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0010/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2015-12-15 21:13:00.440513000 +0900 @@ -33,6 +33,7 @@ struct ipmmu_features { bool use_ns_alias_offset; + bool has_cache_leaf_nodes; }; struct ipmmu_vmsa_device { @@ -48,10 +49,12 @@ struct ipmmu_vmsa_device { struct dma_iommu_mapping *mapping; #endif const struct ipmmu_features *features; + bool is_leaf; }; struct ipmmu_vmsa_domain { struct ipmmu_vmsa_device *mmu; + struct ipmmu_vmsa_device *root; struct iommu_domain io_domain; struct io_pgtable_cfg cfg; @@ -210,6 +213,36 @@ static void set_dev_data(struct device * } /* ----------------------------------------------------------------------------- + * Root device handling + */ + +static bool ipmmu_is_root(struct ipmmu_vmsa_device *mmu) +{ + if (mmu->features->has_cache_leaf_nodes) + return mmu->is_leaf ? false : true; + else + return true; /* older IPMMU hardware treated as single root */ +} + +static struct ipmmu_vmsa_device *ipmmu_find_root(struct ipmmu_vmsa_device *leaf) +{ + struct ipmmu_vmsa_device *mmu; + + if (ipmmu_is_root(leaf)) + return leaf; + + spin_lock(&ipmmu_devices_lock); + + list_for_each_entry(mmu, &ipmmu_devices, list) { + if (ipmmu_is_root(mmu)) + break; + } + + spin_unlock(&ipmmu_devices_lock); + return mmu; +} + +/* ----------------------------------------------------------------------------- * Read/Write Access */ @@ -226,13 +259,13 @@ static void ipmmu_write(struct ipmmu_vms static u32 ipmmu_ctx_read(struct ipmmu_vmsa_domain *domain, unsigned int reg) { - return ipmmu_read(domain->mmu, domain->context_id * IM_CTX_SIZE + 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) { - ipmmu_write(domain->mmu, domain->context_id * IM_CTX_SIZE + reg, data); + ipmmu_write(domain->root, domain->context_id * IM_CTX_SIZE + reg, data); } /* ----------------------------------------------------------------------------- @@ -355,7 +388,7 @@ static int ipmmu_domain_init_context(str * TODO: Add support for coherent walk through CCI with DVM and remove * cache handling. For now, delegate it to the io-pgtable code. */ - domain->cfg.iommu_dev = domain->mmu->dev; + domain->cfg.iommu_dev = domain->root->dev; domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, domain); @@ -365,14 +398,14 @@ static int ipmmu_domain_init_context(str /* * Find an unused context. */ - ret = bitmap_find_free_region(domain->mmu->ctx, IPMMU_CTX_MAX, 0); + ret = bitmap_find_free_region(domain->root->ctx, IPMMU_CTX_MAX, 0); if (ret < 0) { free_io_pgtable_ops(domain->iop); return ret; } domain->context_id = ret; - domain->mmu->domains[ret] = domain; + domain->root->domains[ret] = domain; /* TTBR0 */ ttbr = domain->cfg.arm_lpae_s1_cfg.ttbr[0]; @@ -532,7 +565,7 @@ static int ipmmu_attach_device(struct io struct device *dev) { struct ipmmu_vmsa_dev_data *dev_data = get_dev_data(dev); - struct ipmmu_vmsa_device *mmu = dev_data->mmu; + struct ipmmu_vmsa_device *root, *mmu = dev_data->mmu; struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned long flags; int ret = 0; @@ -542,11 +575,18 @@ static int ipmmu_attach_device(struct io return -ENXIO; } + root = ipmmu_find_root(dev_data->mmu); + if (!root) { + dev_err(dev, "Unable to locate root IPMMU\n"); + return -EAGAIN; + } + spin_lock_irqsave(&domain->lock, flags); if (!domain->mmu) { /* The domain hasn't been used yet, initialize it. */ domain->mmu = mmu; + domain->root = root; ret = ipmmu_domain_init_context(domain); } else if (domain->mmu != mmu) { /* @@ -824,6 +864,7 @@ static void ipmmu_device_reset(struct ip static const struct ipmmu_features ipmmu_features_default = { .use_ns_alias_offset = true, + .has_cache_leaf_nodes = false, }; static const struct of_device_id ipmmu_of_ids[] = { @@ -882,19 +923,30 @@ static int ipmmu_probe(struct platform_d mmu->base += IM_NS_ALIAS_OFFSET; irq = platform_get_irq(pdev, 0); - if (irq < 0) { - dev_err(&pdev->dev, "no IRQ found\n"); - return irq; - } - ret = devm_request_irq(&pdev->dev, irq, ipmmu_irq, 0, - dev_name(&pdev->dev), mmu); - if (ret < 0) { - dev_err(&pdev->dev, "failed to request IRQ %d\n", irq); - return ret; - } + /* + * Determine if this IPMMU instance is a leaf device by checking + * if an interrupt is availabile or not + */ + if (mmu->features->has_cache_leaf_nodes && irq < 0) + mmu->is_leaf = true; + + /* Root devices have mandatory IRQs */ + if (ipmmu_is_root(mmu)) { + if (irq < 0) { + dev_err(&pdev->dev, "no IRQ found\n"); + return irq; + } - ipmmu_device_reset(mmu); + ret = devm_request_irq(&pdev->dev, irq, ipmmu_irq, 0, + dev_name(&pdev->dev), mmu); + if (ret < 0) { + dev_err(&pdev->dev, "failed to request IRQ %d\n", irq); + return ret; + } + + ipmmu_device_reset(mmu); + } /* * We can't create the ARM mapping here as it requires the bus to have