From patchwork Thu Jun 2 15:55:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9150843 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 EA37360221 for ; Thu, 2 Jun 2016 16:07:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB31220410 for ; Thu, 2 Jun 2016 16:07:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D02C326490; Thu, 2 Jun 2016 16:07:19 +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 323E020410 for ; Thu, 2 Jun 2016 16:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933063AbcFBQGR (ORCPT ); Thu, 2 Jun 2016 12:06:17 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:35793 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933062AbcFBQGP (ORCPT ); Thu, 2 Jun 2016 12:06:15 -0400 Received: by mail-pa0-f66.google.com with SMTP id gp3so3654329pac.2; Thu, 02 Jun 2016 09:06:15 -0700 (PDT) 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=9ZVjp1y8vIf1Z+1yfEqDv38bPQ1g6oUVTpv2bzHGrU4=; b=rC6vk58o0dDueiV157UHPjYQZFaReimYCguUOwhzH8qAdyJvTV/ZH+IYKSS+tyRqLy mQy/232yRHyoRseefJOfBWASvQGua0imaJpboiqXN71TtvSy0VG4d/x5AFUSSR9a97hd dEoP9kgiKi+G3sjd5SNahgX+dPUBMxFPB4RDI9QJxv0uXSnc0nenGwBxMjG1TVQMTJI6 Sthdu9gCrsOHEXIWy+6dP4x1Yg+wc00mzkPC/op/YAl7sueYpR+uk9wffM/0/rSaz0O1 JN1KJzSGnn1iitNrabs0NVHfBERf+Ivzhvi6IiWd0h+rnLDw0NebnhgsVdmNezeqs62n m41w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:date:message-id:in-reply-to :references:subject; bh=9ZVjp1y8vIf1Z+1yfEqDv38bPQ1g6oUVTpv2bzHGrU4=; b=LOkQNheinFQWa7hDf6G2NZZcPdVR0X+9XWsiKEI4t1peMNLPCNUAAQTa/N6Oj0oIC4 a9DpH971C/N7KWv8UHH6kMq/OpqvufKXCzbNMfirbzNNikpl1ETj3WDMgEOcuPBlDij5 qph60d3gmbjN1AhsoOwLZMuq47esL4suBk5lfnz4tejsCJCuUDVUHqQ1+sGF6JmDbkWz hu4oM5JlzB912JRflfHsC3lgbBXrmf5ggoYeKN4Kn2YkluBi0jTvLdCyJWcAMN0twYr5 O2nnrlSFXkE4KO8CoiWE2TqfndF3C0xOfrSViYIShzazzU+AyeBAGbRz5cejpAcNlSf4 Pr2w== X-Gm-Message-State: ALyK8tIVKYnYqrHESOWLAltE3gdy6NZ65+aJGKk/37eWUxWrxeFkatRakKMmkPoY4OCuxg== X-Received: by 10.66.132.11 with SMTP id oq11mr4671057pab.59.1464883574660; Thu, 02 Jun 2016 09:06:14 -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 w2sm1701760pfb.46.2016.06.02.09.06.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2016 09:06:13 -0700 (PDT) From: Magnus Damm To: iommu@lists.linux-foundation.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, joro@8bytes.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm , robin.murphy@arm.com, m.szyprowski@samsung.com Date: Fri, 03 Jun 2016 00:55:50 +0900 Message-Id: <20160602155550.31018.5799.sendpatchset@little-apple> In-Reply-To: <20160602155519.31018.59925.sendpatchset@little-apple> References: <20160602155519.31018.59925.sendpatchset@little-apple> Subject: [PATCH v3 03/06] iommu/ipmmu-vmsa: Break out utlb parsing code 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 Break out the utlb parsing code and dev_data allocation into a separate function. This is preparation for future code sharing. Signed-off-by: Magnus Damm --- Changes since V2: - Included this new patch from the following series: [PATCH 00/04] iommu/ipmmu-vmsa: IPMMU CONFIG_IOMMU_DMA update - Reworked code to fit on top on previous two patches in current series. drivers/iommu/ipmmu-vmsa.c | 58 ++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) --- 0004/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2016-06-02 21:23:51.700607110 +0900 @@ -647,22 +647,16 @@ static int ipmmu_find_utlbs(struct ipmmu return 0; } -static int ipmmu_add_device(struct device *dev) +static int ipmmu_init_platform_device(struct device *dev, + struct iommu_group *group) { struct ipmmu_vmsa_archdata *archdata; struct ipmmu_vmsa_device *mmu; - struct iommu_group *group = NULL; unsigned int *utlbs; unsigned int i; int num_utlbs; int ret = -ENODEV; - if (dev->archdata.iommu) { - dev_warn(dev, "IOMMU driver already assigned to device %s\n", - dev_name(dev)); - return -EINVAL; - } - /* Find the master corresponding to the device. */ num_utlbs = of_count_phandle_with_args(dev->of_node, "iommus", @@ -690,7 +684,7 @@ static int ipmmu_add_device(struct devic spin_unlock(&ipmmu_devices_lock); if (ret < 0) - return -ENODEV; + goto error; for (i = 0; i < num_utlbs; ++i) { if (utlbs[i] >= mmu->num_utlbs) { @@ -699,6 +693,36 @@ static int ipmmu_add_device(struct devic } } + archdata = kzalloc(sizeof(*archdata), GFP_KERNEL); + if (!archdata) { + ret = -ENOMEM; + goto error; + } + + archdata->mmu = mmu; + archdata->utlbs = utlbs; + archdata->num_utlbs = num_utlbs; + dev->archdata.iommu = archdata; + return 0; + +error: + kfree(utlbs); + return ret; +} + +static int ipmmu_add_device(struct device *dev) +{ + struct ipmmu_vmsa_archdata *archdata; + struct ipmmu_vmsa_device *mmu; + struct iommu_group *group; + int ret; + + if (dev->archdata.iommu) { + dev_warn(dev, "IOMMU driver already assigned to device %s\n", + dev_name(dev)); + return -EINVAL; + } + /* Create a device group and add the device to it. */ group = iommu_group_alloc(); if (IS_ERR(group)) { @@ -716,17 +740,12 @@ static int ipmmu_add_device(struct devic goto error; } - archdata = kzalloc(sizeof(*archdata), GFP_KERNEL); - if (!archdata) { - ret = -ENOMEM; + ret = ipmmu_init_platform_device(dev, group); + if (ret < 0) { + dev_err(dev, "Failed to init platform device\n"); goto error; } - archdata->mmu = mmu; - archdata->utlbs = utlbs; - archdata->num_utlbs = num_utlbs; - dev->archdata.iommu = archdata; - /* * Create the ARM mapping, used by the ARM DMA mapping core to allocate * VAs. This will allocate a corresponding IOMMU domain. @@ -736,6 +755,8 @@ 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; if (!mmu->mapping) { struct dma_iommu_mapping *mapping; @@ -762,9 +783,6 @@ static int ipmmu_add_device(struct devic error: arm_iommu_release_mapping(mmu->mapping); - kfree(dev->archdata.iommu); - kfree(utlbs); - dev->archdata.iommu = NULL; if (!IS_ERR_OR_NULL(group))