From patchwork Tue Mar 7 03:17: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: 9608063 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 94D76604DD for ; Tue, 7 Mar 2017 03:33:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 811882832D for ; Tue, 7 Mar 2017 03:33:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F44A2848D; Tue, 7 Mar 2017 03:33:47 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 538CF2841A for ; Tue, 7 Mar 2017 03:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932297AbdCGDdo (ORCPT ); Mon, 6 Mar 2017 22:33:44 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34140 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932279AbdCGDcD (ORCPT ); Mon, 6 Mar 2017 22:32:03 -0500 Received: by mail-pf0-f196.google.com with SMTP id o126so5437707pfb.1; Mon, 06 Mar 2017 19:31:38 -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=phdBk0Lu2uwvWE+oHdHXonBkE6VQJKLdT6d/tWUrcDE=; b=Qt5ZOMXFyg9NXPi1ZYw2s2n7Ur+FN7Tp1wAWnujPauv48dBzRqakarAgIXLPT6sXIX r+OG7S3M+ZuzonAOLMpNjv4UmN1c771Fu4I43VDOZ0tk6rxJUjWJ623+poyaxHfu1/N1 EFYZxsCb9iMNjSpvA/wQQkPBrGeM2NzhCRJzR6DQ/Dr/puPtIt3WBF/ZU+tGnVbYDR22 BrZN0P9GLWQEGUHTe93BehjkT3tF0Ryhuh8N8WMKuMvSjHdJARiLufM3yixWq4aIwyV+ 1F/kVLmiYHU76cbdhopl33xtQpAizRFj6ESwxpj+RV5Zx5UFSzLND6i6K1xxFSOLx3K0 GHQQ== 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=phdBk0Lu2uwvWE+oHdHXonBkE6VQJKLdT6d/tWUrcDE=; b=tfaxDflptt/q/BYvYiu5NrZQjtFK3A3merD5vIWrP9PFN8aHmUp0x53M8JrmCAf9NM oVlaZ4i9kyAyemaaqPRUBt8+cuiAXqIIceJJ618qTjZ97Y6qX5Fc1snz6tHGfWlNaPfm Ndwj69o9AUSUWzWb8UakDrhFpTWfVs28ugMFMjUf3rQxT3nwnWX4CxvRwsRXAIC1HL+x Zk58apbJBF6mE00iFhYxJzho9dQGOamTORkqp7TX9dWJFRdorjX9Mn/WjyELCjbwtBwQ HPQUIdVspuLJ/wjy8lxhdrrFfTXj9veo4QV/+EOX3CEP8AbTX7BVgjt3jOcRTXvqG8/f w3qw== X-Gm-Message-State: AMke39nHN6QV5NYQ1g43DwRlUiIiRPJGs1g64ySMRtRnNhiCq3DEWSO4+OVH6LONMVZ4Ag== X-Received: by 10.84.216.93 with SMTP id f29mr31747189plj.10.1488857007039; Mon, 06 Mar 2017 19:23:27 -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 y6sm23712163pgc.1.2017.03.06.19.23.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 19:23:25 -0800 (PST) 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: Tue, 07 Mar 2017 12:17:43 +0900 Message-Id: <148885666392.28553.6653211200015255398.sendpatchset@little-apple> In-Reply-To: <148885660307.28553.995847796823338863.sendpatchset@little-apple> References: <148885660307.28553.995847796823338863.sendpatchset@little-apple> Subject: [PATCH v7 06/07] iommu/ipmmu-vmsa: ARM and ARM64 archdata access 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 Not all architectures have an iommu member in their archdata, so use #ifdefs support build with COMPILE_TEST on any architecture. Signed-off-by: Magnus Damm Reviewed-by: Joerg Roedel Reviewed-by: Geert Uytterhoeven --- Changes since V6: - Updated patch to handle newly introduced functions in: [PATCH v7 05/07] iommu/ipmmu-vmsa: Add new IOMMU_DOMAIN_DMA ops drivers/iommu/ipmmu-vmsa.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) --- 0010/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-03-06 19:26:26.070607110 +0900 @@ -72,6 +72,25 @@ static struct ipmmu_vmsa_domain *to_vmsa return container_of(dom, struct ipmmu_vmsa_domain, io_domain); } +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) +static struct ipmmu_vmsa_archdata *to_archdata(struct device *dev) +{ + return dev->archdata.iommu; +} +static void set_archdata(struct device *dev, struct ipmmu_vmsa_archdata *p) +{ + dev->archdata.iommu = p; +} +#else +static struct ipmmu_vmsa_archdata *to_archdata(struct device *dev) +{ + return NULL; +} +static void set_archdata(struct device *dev, struct ipmmu_vmsa_archdata *p) +{ +} +#endif + #define TLB_LOOP_TIMEOUT 100 /* 100us */ /* ----------------------------------------------------------------------------- @@ -543,7 +562,7 @@ static void ipmmu_domain_free(struct iom static int ipmmu_attach_device(struct iommu_domain *io_domain, struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_archdata *archdata = to_archdata(dev); struct ipmmu_vmsa_device *mmu = archdata->mmu; struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned long flags; @@ -588,7 +607,7 @@ static int ipmmu_attach_device(struct io static void ipmmu_detach_device(struct iommu_domain *io_domain, struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_archdata *archdata = to_archdata(dev); struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned int i; @@ -709,7 +728,7 @@ static int ipmmu_init_platform_device(st archdata->utlbs = utlbs; archdata->num_utlbs = num_utlbs; archdata->dev = dev; - dev->archdata.iommu = archdata; + set_archdata(dev, archdata); return 0; error: @@ -729,12 +748,11 @@ static struct iommu_domain *ipmmu_domain static int ipmmu_add_device(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata; struct ipmmu_vmsa_device *mmu = NULL; struct iommu_group *group; int ret; - if (dev->archdata.iommu) { + if (to_archdata(dev)) { dev_warn(dev, "IOMMU driver already assigned to device %s\n", dev_name(dev)); return -EINVAL; @@ -770,8 +788,7 @@ static int ipmmu_add_device(struct devic * - Make the mapping size configurable ? We currently use a 2GB mapping * at a 1GB offset to ensure that NULL VAs will fault. */ - archdata = dev->archdata.iommu; - mmu = archdata->mmu; + mmu = to_archdata(dev)->mmu; if (!mmu->mapping) { struct dma_iommu_mapping *mapping; @@ -799,7 +816,7 @@ error: if (mmu) arm_iommu_release_mapping(mmu->mapping); - dev->archdata.iommu = NULL; + set_archdata(dev, NULL); if (!IS_ERR_OR_NULL(group)) iommu_group_remove_device(dev); @@ -809,7 +826,7 @@ error: static void ipmmu_remove_device(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_archdata *archdata = to_archdata(dev); arm_iommu_detach_device(dev); iommu_group_remove_device(dev); @@ -817,7 +834,7 @@ static void ipmmu_remove_device(struct d kfree(archdata->utlbs); kfree(archdata); - dev->archdata.iommu = NULL; + set_archdata(dev, NULL); } static const struct iommu_ops ipmmu_ops = { @@ -874,7 +891,7 @@ static void ipmmu_domain_free_dma(struct static int ipmmu_add_device_dma(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_archdata *archdata = to_archdata(dev); struct iommu_group *group; /* The device has been verified in xlate() */ @@ -893,7 +910,7 @@ static int ipmmu_add_device_dma(struct d static void ipmmu_remove_device_dma(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_archdata *archdata = to_archdata(dev); spin_lock(&ipmmu_slave_devices_lock); list_del(&archdata->list); @@ -904,7 +921,7 @@ static void ipmmu_remove_device_dma(stru static struct device *ipmmu_find_sibling_device(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_archdata *archdata = to_archdata(dev); struct ipmmu_vmsa_archdata *sibling_archdata = NULL; bool found = false;