From patchwork Tue Mar 7 03:17:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9608031 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 89BFC60414 for ; Tue, 7 Mar 2017 03:26:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77EA327DC2 for ; Tue, 7 Mar 2017 03:26:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C48A2846D; Tue, 7 Mar 2017 03:26:44 +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=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 D27C327DC2 for ; Tue, 7 Mar 2017 03:26:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754797AbdCGD02 (ORCPT ); Mon, 6 Mar 2017 22:26:28 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35630 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754827AbdCGDZK (ORCPT ); Mon, 6 Mar 2017 22:25:10 -0500 Received: by mail-pf0-f193.google.com with SMTP id 67so15134911pfg.2; Mon, 06 Mar 2017 19:22:57 -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=N+twRCsXEhftvn/iqg3ZvO2b6kKFWlWLGKeoJ6pzrwg=; b=ueLET3CuOJkCn8cZWfo6opAzunsd4T3BNFTNDq9b+rC+hoB1ZvpFnH9rPVYkuU7sBP ijjsn5fW2OtPKHiqAqB1+egLp7bn/ljHlai0RtxCN4aDBO2puB1MxeR+NeDfY7KUSk2h FH1divdVylsRWyJ3cf2kv8yAVJ6QkQSh4ql5oF1AKuHk30saFY0SNcbTUYNrYy2xxi3z kMtTdoK5lrGGM5MhoBxQUHg+054x3ckGZ3G5/a+0H50NDtWHApCCZ5TSKJNFj2Jh6uwC 8/Oj06BUzHOPsJYa+M0cj3e5C74PCPAzdx2XCUXJysk0ymC9S70ZngE6CQKq7g9dGZrP 1QOg== 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=N+twRCsXEhftvn/iqg3ZvO2b6kKFWlWLGKeoJ6pzrwg=; b=t1EACwqMYl3Dq9Hj+YfviKL4nNVqevuyKi3IFogi+OHYF7wsjRjio3iK52AL7MUVIm GkTUS8Ed3f++3v+ji/P3LifLI8M2J3bQgreaGQf4UmmkYKHjnbUCvHC78yTTFvT/BR20 wx7uVCh7NDF8FL/SynZ/5W10rVZOsDS4KJy56UO++gUdvnXhHHu92U1WhhEjLNqW+iS/ z/WDSjPKqnHAfvXbpZMPp8COrgrjhuCYQHqRsbyqibxqwabLA0rx4KRI0mPJN9IM49fY Qamzo/Xh3FSY2L/x8x4AtTWAzjZea2OUTX0mpgoi5bz2mrzHQFMs20sjC7WhdHUpJ1dX /LLA== X-Gm-Message-State: AMke39nvVHrDKy88qiwHnuS0BP0daScwFT3Sy8BipYqn6cF5EnzbadLFG+qHFCfpo2+z7w== X-Received: by 10.99.136.74 with SMTP id l71mr24535209pgd.143.1488856977012; Mon, 06 Mar 2017 19:22:57 -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 x65sm42071247pfx.115.2017.03.06.19.22.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 19:22:55 -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:13 +0900 Message-Id: <148885663361.28553.16605169682314363447.sendpatchset@little-apple> In-Reply-To: <148885660307.28553.995847796823338863.sendpatchset@little-apple> References: <148885660307.28553.995847796823338863.sendpatchset@little-apple> Subject: [PATCH v7 03/07] 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 Reviewed-by: Joerg Roedel --- Changes since V6: - None drivers/iommu/ipmmu-vmsa.c | 58 ++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) --- 0004/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-03-06 18:33:38.600607110 +0900 @@ -649,22 +649,15 @@ 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 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", @@ -701,6 +694,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 = NULL; + 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)) { @@ -718,16 +741,9 @@ 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); + if (ret < 0) 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 @@ -738,6 +754,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,10 +780,8 @@ static int ipmmu_add_device(struct devic return 0; error: - arm_iommu_release_mapping(mmu->mapping); - - kfree(dev->archdata.iommu); - kfree(utlbs); + if (mmu) + arm_iommu_release_mapping(mmu->mapping); dev->archdata.iommu = NULL;