From patchwork Tue Dec 15 12:02:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 7854031 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 6C6C9BEEE1 for ; Tue, 15 Dec 2015 12:01:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 73BBB20304 for ; Tue, 15 Dec 2015 12:01:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3731202FE for ; Tue, 15 Dec 2015 12:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964955AbbLOMAx (ORCPT ); Tue, 15 Dec 2015 07:00:53 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35010 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964921AbbLOMAv (ORCPT ); Tue, 15 Dec 2015 07:00:51 -0500 Received: by mail-pf0-f172.google.com with SMTP id 63so3896661pff.2; Tue, 15 Dec 2015 04:00:51 -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=9rvuJbXojG8vxnpTcc7rITnup6aKPsxlYADHrghdLC0=; b=vp4lDvCJUw4L6/NFn/lWLyR/OUWZ+8d3QqVIPPXO+bBIqsD0KkerhDkSNhvwwBF/Ji y7T1jAR90CNSP913v3VEDyl79layHdqZCjFCWTIUKkSeUPKl5EsueeTcUL2Yhht97urG McwbL45hqteQoNJPVZBKjnBf8rSsY/gfIhuLb6Md2w9Hvw9HP0RKcitngST6geICTn+Z F387TyMSmza8nTySMaUEEBiBRlgnelcjIHBe4Im9pfemltf4B5poL+KE0wHI1fCfix3a 1Cs8cABflvVwOxGlSs63hlqCfp/oq9aT815N3etgOfBU1FaB4QbIqcDy+7+XCtfMtuXk dBvQ== X-Received: by 10.98.8.68 with SMTP id c65mr17079009pfd.89.1450180851298; Tue, 15 Dec 2015 04:00:51 -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 fe6sm1900742pab.40.2015.12.15.04.00.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Dec 2015 04:00:50 -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 21:02:30 +0900 Message-Id: <20151215120230.26216.8126.sendpatchset@little-apple> In-Reply-To: <20151215120212.26216.61530.sendpatchset@little-apple> References: <20151215120212.26216.61530.sendpatchset@little-apple> Subject: [PATCH 02/06] iommu/ipmmu-vmsa: Convert to dev_data 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 Rename ipmmu_vmsa_archdata to ipmmu_vmsa_dev_data to avoid confusion when using the driver on multiple architectures. The data now stored in ipmmu_vmsa_dev_data is used to point various on-chip devices to the actual IPMMU instances. Signed-off-by: Magnus Damm --- drivers/iommu/ipmmu-vmsa.c | 58 +++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 22 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 --- 0003/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2015-12-15 13:16:27.160513000 +0900 @@ -47,7 +47,7 @@ struct ipmmu_vmsa_domain { spinlock_t lock; /* Protects mappings */ }; -struct ipmmu_vmsa_archdata { +struct ipmmu_vmsa_dev_data { struct ipmmu_vmsa_device *mmu; unsigned int *utlbs; unsigned int num_utlbs; @@ -182,6 +182,20 @@ static struct ipmmu_vmsa_domain *to_vmsa #define IMUASID_ASID0_SHIFT 0 /* ----------------------------------------------------------------------------- + * Consumer device side private data handling + */ + +static struct ipmmu_vmsa_dev_data *get_dev_data(struct device *dev) +{ + return dev->archdata.iommu; +} + +static void set_dev_data(struct device *dev, struct ipmmu_vmsa_dev_data *data) +{ + dev->archdata.iommu = data; +} + +/* ----------------------------------------------------------------------------- * Read/Write Access */ @@ -485,8 +499,8 @@ 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_device *mmu = archdata->mmu; + struct ipmmu_vmsa_dev_data *dev_data = get_dev_data(dev); + struct ipmmu_vmsa_device *mmu = dev_data->mmu; struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned long flags; unsigned int i; @@ -518,8 +532,8 @@ static int ipmmu_attach_device(struct io if (ret < 0) return ret; - for (i = 0; i < archdata->num_utlbs; ++i) - ipmmu_utlb_enable(domain, archdata->utlbs[i]); + for (i = 0; i < dev_data->num_utlbs; ++i) + ipmmu_utlb_enable(domain, dev_data->utlbs[i]); return 0; } @@ -527,12 +541,12 @@ 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_dev_data *dev_data = get_dev_data(dev); struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); unsigned int i; - for (i = 0; i < archdata->num_utlbs; ++i) - ipmmu_utlb_disable(domain, archdata->utlbs[i]); + for (i = 0; i < dev_data->num_utlbs; ++i) + ipmmu_utlb_disable(domain, dev_data->utlbs[i]); /* * TODO: Optimize by disabling the context when no device is attached. @@ -595,7 +609,7 @@ static int ipmmu_find_utlbs(struct ipmmu static int ipmmu_add_device(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata; + struct ipmmu_vmsa_dev_data *dev_data = get_dev_data(dev); struct ipmmu_vmsa_device *mmu; struct iommu_group *group = NULL; unsigned int *utlbs; @@ -603,7 +617,7 @@ static int ipmmu_add_device(struct devic int num_utlbs; int ret = -ENODEV; - if (dev->archdata.iommu) { + if (dev_data) { dev_warn(dev, "IOMMU driver already assigned to device %s\n", dev_name(dev)); return -EINVAL; @@ -662,16 +676,16 @@ static int ipmmu_add_device(struct devic goto error; } - archdata = kzalloc(sizeof(*archdata), GFP_KERNEL); - if (!archdata) { + dev_data = kzalloc(sizeof(*dev_data), GFP_KERNEL); + if (!dev_data) { ret = -ENOMEM; goto error; } - archdata->mmu = mmu; - archdata->utlbs = utlbs; - archdata->num_utlbs = num_utlbs; - dev->archdata.iommu = archdata; + dev_data->mmu = mmu; + dev_data->utlbs = utlbs; + dev_data->num_utlbs = num_utlbs; + set_dev_data(dev, dev_data); /* * Create the ARM mapping, used by the ARM DMA mapping core to allocate @@ -708,10 +722,10 @@ static int ipmmu_add_device(struct devic error: arm_iommu_release_mapping(mmu->mapping); - kfree(dev->archdata.iommu); + kfree(dev_data); kfree(utlbs); - dev->archdata.iommu = NULL; + set_dev_data(dev, NULL); if (!IS_ERR_OR_NULL(group)) iommu_group_remove_device(dev); @@ -721,15 +735,15 @@ error: static void ipmmu_remove_device(struct device *dev) { - struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; + struct ipmmu_vmsa_dev_data *dev_data = get_dev_data(dev); arm_iommu_detach_device(dev); iommu_group_remove_device(dev); - kfree(archdata->utlbs); - kfree(archdata); + kfree(dev_data->utlbs); + kfree(dev_data); - dev->archdata.iommu = NULL; + set_dev_data(dev, NULL); } static const struct iommu_ops ipmmu_ops = {