From patchwork Fri Nov 11 02:01:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9422359 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 C132060484 for ; Fri, 11 Nov 2016 02:01:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2D662945B for ; Fri, 11 Nov 2016 02:01:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93D442985A; Fri, 11 Nov 2016 02:01:05 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 D6A072945B for ; Fri, 11 Nov 2016 02:01:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965911AbcKKCBE (ORCPT ); Thu, 10 Nov 2016 21:01:04 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:55544 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964913AbcKKCBD (ORCPT ); Thu, 10 Nov 2016 21:01:03 -0500 Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 245A220051; Fri, 11 Nov 2016 02:59:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1478829599; bh=gcOyOzOtcHT3vy0ugDIcte+wTYbQqPDbZoH9W9ujpp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lNqW1PZNv8dKolZcnvfvtslw5cKuS2hnvP77VihA9O3BsuRwmYaqp/6yY9zEeI9HX pQrkK7pBCT2vMKOrDsrmD4R91GPoFOJUumG7P6pXykkPfQCrX6AVNsJu7+3SjFvOB2 58XA5JgkdsmHRMokWxcap2QxwYQkXwZ4mf12lZXI= From: Laurent Pinchart To: iommu@lists.linux-foundation.org Cc: 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 Subject: [PATCH] iommu/ipmmu-vmsa: Unify domain alloc/free implementations Date: Fri, 11 Nov 2016 04:01:02 +0200 Message-Id: <1478829662-19689-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <20161019233623.10506.49016.sendpatchset@little-apple> References: <20161019233623.10506.49016.sendpatchset@little-apple> 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 The ARM and ARM64 implementations of the IOMMU domain alloc/free operations can be unified with the correct combination of type checking, as the domain type can never be IOMMU_DOMAIN_DMA on 32-bit ARM due to the driver calling iommu_group_get_for_dev() on ARM64 only. Do so. Signed-off-by: Laurent Pinchart --- drivers/iommu/ipmmu-vmsa.c | 58 +++++++++++----------------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) Hi Magnus, This cleans up patch 5/7, making patch 4/7 unnecessary. I proposed squashing 4/7, 5/7 and this one in v7. diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 11550ac90d65..827aa72aaf28 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -529,16 +529,22 @@ static irqreturn_t ipmmu_irq(int irq, void *dev) * IOMMU Operations */ -static struct iommu_domain *__ipmmu_domain_alloc(unsigned type) +static struct iommu_domain *ipmmu_domain_alloc(unsigned int type) { struct ipmmu_vmsa_domain *domain; + if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) + return NULL; + domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return NULL; spin_lock_init(&domain->lock); + if (type == IOMMU_DOMAIN_DMA) + iommu_get_dma_cookie(&domain->io_domain); + return &domain->io_domain; } @@ -546,6 +552,9 @@ static void ipmmu_domain_free(struct iommu_domain *io_domain) { struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); + if (io_domain->type) + iommu_put_dma_cookie(io_domain); + /* * Free the domain resources. We assume that all devices have already * been detached. @@ -821,14 +830,6 @@ static void ipmmu_remove_device(struct device *dev) set_archdata(dev, NULL); } -static struct iommu_domain *ipmmu_domain_alloc(unsigned type) -{ - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - - return __ipmmu_domain_alloc(type); -} - static const struct iommu_ops ipmmu_ops = { .domain_alloc = ipmmu_domain_alloc, .domain_free = ipmmu_domain_free, @@ -847,42 +848,11 @@ static const struct iommu_ops ipmmu_ops = { #ifdef CONFIG_IOMMU_DMA -static struct iommu_domain *ipmmu_domain_alloc_dma(unsigned type) -{ - struct iommu_domain *io_domain = NULL; - - switch (type) { - case IOMMU_DOMAIN_UNMANAGED: - io_domain = __ipmmu_domain_alloc(type); - break; - - case IOMMU_DOMAIN_DMA: - io_domain = __ipmmu_domain_alloc(type); - if (io_domain) - iommu_get_dma_cookie(io_domain); - break; - } - - return io_domain; -} - -static void ipmmu_domain_free_dma(struct iommu_domain *io_domain) -{ - switch (io_domain->type) { - case IOMMU_DOMAIN_DMA: - iommu_put_dma_cookie(io_domain); - /* fall-through */ - default: - ipmmu_domain_free(io_domain); - break; - } -} - static int ipmmu_add_device_dma(struct device *dev) { struct iommu_group *group; - /* only accept devices with iommus property */ + /* Only accept devices with an iommus property. */ if (of_count_phandle_with_args(dev->of_node, "iommus", "#iommu-cells") < 0) return -ENODEV; @@ -920,13 +890,13 @@ static struct iommu_group *ipmmu_device_group_dma(struct device *dev) static int ipmmu_of_xlate_dma(struct device *dev, struct of_phandle_args *spec) { - /* dummy callback to satisfy of_iommu_configure() */ + /* Dummy callback to satisfy of_iommu_configure(). */ return 0; } static const struct iommu_ops ipmmu_ops = { - .domain_alloc = ipmmu_domain_alloc_dma, - .domain_free = ipmmu_domain_free_dma, + .domain_alloc = ipmmu_domain_alloc, + .domain_free = ipmmu_domain_free, .attach_dev = ipmmu_attach_device, .detach_dev = ipmmu_detach_device, .map = ipmmu_map,