From patchwork Mon Jan 26 23:51:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 433074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 6524514028E for ; Tue, 27 Jan 2015 10:51:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757398AbbAZXvv (ORCPT ); Mon, 26 Jan 2015 18:51:51 -0500 Received: from 8bytes.org ([81.169.241.247]:50760 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757172AbbAZXvs (ORCPT ); Mon, 26 Jan 2015 18:51:48 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 840591F7; Tue, 27 Jan 2015 00:51:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1422316306; bh=63cbMMZEPLk3ifcCetw7QWu97kTipd7Y2ZmQg6CTdVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RzFEygCWahAwKeLL2Pki5Q64yjOeMbCuvE9giL6d3YFVP0R4uWV1cEwPeGiZm2tVI ILLQKFewKVCWzxZRUZUpBxwhZKztUCqzCKPhZWlji0lTQBSbO6UkE8B73C2uE5iNPU /vmr0cRvldypNr1GrqzLM808GgYi0ncn+sQNOEz/KtP2O2/ycdvusDdO3WkmKtgxsu aJ9Ea9lqjHdTpwSp8RdfDgVruEBbfDNOHElzWIXGSA+5lHMnNuKq6cDHuP1qWIfTLV sVZsUS6aiYG4IaeSHQ1TrzEPMsdnXVTGj19VxwoFRTANJpE65s3p+GaeuRtj2uuVSU wwY50XX9tFHlQ== From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: Will Deacon , Kukjin Kim , David Woodhouse , Heiko Stuebner , Hiroshi Doyu , Stephen Warren , Thierry Reding , Alexandre Courbot , Alex Williamson , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-tegra@vger.kernel.org, Joerg Roedel , jroedel@suse.de Subject: [PATCH 01/15] iommu: Introduce domain_alloc and domain_free iommu_ops Date: Tue, 27 Jan 2015 00:51:31 +0100 Message-Id: <1422316305-19216-2-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422316305-19216-1-git-send-email-joro@8bytes.org> References: <1422316305-19216-1-git-send-email-joro@8bytes.org> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Joerg Roedel These new call-backs defer the allocation and destruction of 'struct iommu_domain' to the iommu driver. This allows drivers to embed this struct into their private domain structures and to get rid of the domain_init and domain_destroy call-backs when all drivers have been converted. Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 29 +++++++++++++++++++++-------- include/linux/iommu.h | 5 +++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f7718d7..684efc0 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -900,26 +900,34 @@ EXPORT_SYMBOL_GPL(iommu_set_fault_handler); struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) { + const struct iommu_ops *ops; struct iommu_domain *domain; - int ret; if (bus == NULL || bus->iommu_ops == NULL) return NULL; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); + ops = bus->iommu_ops; + + if (ops->domain_alloc) + domain = ops->domain_alloc(); + else + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (!domain) return NULL; domain->ops = bus->iommu_ops; - ret = domain->ops->domain_init(domain); - if (ret) + if (ops->domain_init && domain->ops->domain_init(domain)) goto out_free; return domain; out_free: - kfree(domain); + if (ops->domain_free) + ops->domain_free(domain); + else + kfree(domain); return NULL; } @@ -927,10 +935,15 @@ EXPORT_SYMBOL_GPL(iommu_domain_alloc); void iommu_domain_free(struct iommu_domain *domain) { - if (likely(domain->ops->domain_destroy != NULL)) - domain->ops->domain_destroy(domain); + const struct iommu_ops *ops = domain->ops; - kfree(domain); + if (likely(ops->domain_destroy != NULL)) + ops->domain_destroy(domain); + + if (ops->domain_free) + ops->domain_free(domain); + else + kfree(domain); } EXPORT_SYMBOL_GPL(iommu_domain_free); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 38daa45..69d1d12 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -115,6 +115,11 @@ struct iommu_ops { bool (*capable)(enum iommu_cap); int (*domain_init)(struct iommu_domain *domain); void (*domain_destroy)(struct iommu_domain *domain); + + /* Domain allocation and freeing by the iommu driver */ + struct iommu_domain *(*domain_alloc)(void); + void (*domain_free)(struct iommu_domain *); + int (*attach_dev)(struct iommu_domain *domain, struct device *dev); void (*detach_dev)(struct iommu_domain *domain, struct device *dev); int (*map)(struct iommu_domain *domain, unsigned long iova,