From patchwork Mon Aug 15 15:23:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 659309 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 3sCfW96wW9z9t2Y for ; Tue, 16 Aug 2016 01:27:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753182AbcHOPXy (ORCPT ); Mon, 15 Aug 2016 11:23:54 -0400 Received: from foss.arm.com ([217.140.101.70]:41157 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753208AbcHOPXw (ORCPT ); Mon, 15 Aug 2016 11:23:52 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 45DE8BB4; Mon, 15 Aug 2016 08:25:24 -0700 (PDT) Received: from red-moon.cambridge.arm.com (red-moon.cambridge.arm.com [10.1.206.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 755F03F32C; Mon, 15 Aug 2016 08:23:49 -0700 (PDT) From: Lorenzo Pieralisi To: iommu@lists.linux-foundation.org Cc: Lorenzo Pieralisi , Will Deacon , Rob Herring , Robin Murphy , Joerg Roedel , "Rafael J. Wysocki" , Marc Zyngier , Tomasz Nowicki , Hanjun Guo , Jon Masters , Sinan Kaya , Nate Watterson , Dennis Chen , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 02/15] drivers: iommu: implement arch_{set/get}_iommu_fwspec API Date: Mon, 15 Aug 2016 16:23:27 +0100 Message-Id: <1471274620-20754-3-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1471274620-20754-1-git-send-email-lorenzo.pieralisi@arm.com> References: <1471274620-20754-1-git-send-email-lorenzo.pieralisi@arm.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The iommu fwspec configuration mechanism currently relies on the arch specific struct dev_archdata.iommu member to stash the struct iommu_fwspec pointer set-up for streamid translation. The struct dev_archdata.iommu member is arch specific and is not present on all arches that make use of the struct iommu_fwspec infrastructure, hence an arch specific kernel API is required to set-up and retrieve struct iommu_fwspec pointers safely from generic iommu code, hiding the arch specific details. Implement the arch_{set/get}_iommu_fwspec() generic kernel infrastructure and add the ARM/ARM64 back-end implementations. Signed-off-by: Lorenzo Pieralisi Cc: Will Deacon Cc: Rob Herring Cc: Robin Murphy Cc: Joerg Roedel Cc: "Rafael J. Wysocki" --- arch/arm/Kconfig | 1 + arch/arm/include/asm/iommu-fwspec.h | 30 ++++++++++++++++++++++++++++++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/iommu-fwspec.h | 30 ++++++++++++++++++++++++++++++ drivers/iommu/Kconfig | 3 +++ drivers/iommu/of_iommu.c | 12 ++++++------ include/linux/of_iommu.h | 10 ++++++++++ 7 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 arch/arm/include/asm/iommu-fwspec.h create mode 100644 arch/arm64/include/asm/iommu-fwspec.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index a9c4e48..e84f62e 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -59,6 +59,7 @@ config ARM select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)) select HAVE_IDE if PCI || ISA || PCMCIA + select HAVE_IOMMU_FWSPEC if IOMMU_API select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4 diff --git a/arch/arm/include/asm/iommu-fwspec.h b/arch/arm/include/asm/iommu-fwspec.h new file mode 100644 index 0000000..2e87d8b --- /dev/null +++ b/arch/arm/include/asm/iommu-fwspec.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __ASM_IOMMU_FWSPEC_H +#define __ASM_IOMMU_FWSPEC_H + +static inline void arch_set_iommu_fwspec(struct device *dev, + struct iommu_fwspec *fwspec) +{ + dev->archdata.iommu = fwspec; +} + +static inline struct iommu_fwspec *arch_get_iommu_fwspec(struct device *dev) +{ + return dev->archdata.iommu; +} +#endif + diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index bc3f00f..10c9b3d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -83,6 +83,7 @@ config ARM64 select HAVE_GCC_PLUGINS select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS + select HAVE_IOMMU_FWSPEC if IOMMU_API select HAVE_IRQ_TIME_ACCOUNTING select HAVE_MEMBLOCK select HAVE_MEMBLOCK_NODE_MAP if NUMA diff --git a/arch/arm64/include/asm/iommu-fwspec.h b/arch/arm64/include/asm/iommu-fwspec.h new file mode 100644 index 0000000..2e87d8b --- /dev/null +++ b/arch/arm64/include/asm/iommu-fwspec.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __ASM_IOMMU_FWSPEC_H +#define __ASM_IOMMU_FWSPEC_H + +static inline void arch_set_iommu_fwspec(struct device *dev, + struct iommu_fwspec *fwspec) +{ + dev->archdata.iommu = fwspec; +} + +static inline struct iommu_fwspec *arch_get_iommu_fwspec(struct device *dev) +{ + return dev->archdata.iommu; +} +#endif + diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 8ee54d7..101cb17 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -67,6 +67,9 @@ config OF_IOMMU def_bool y depends on OF && IOMMU_API +config HAVE_IOMMU_FWSPEC + bool + # IOMMU-agnostic DMA-mapping layer config IOMMU_DMA bool diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index bec51eb..e30f860 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -222,7 +222,7 @@ postcore_initcall_sync(of_iommu_init); int iommu_fwspec_init(struct device *dev, struct device_node *iommu_np) { - struct iommu_fwspec *fwspec = dev->archdata.iommu; + struct iommu_fwspec *fwspec = arch_get_iommu_fwspec(dev); if (fwspec) return 0; @@ -233,13 +233,13 @@ int iommu_fwspec_init(struct device *dev, struct device_node *iommu_np) fwspec->iommu_np = of_node_get(iommu_np); fwspec->iommu_ops = of_iommu_get_ops(iommu_np); - dev->archdata.iommu = fwspec; + arch_set_iommu_fwspec(dev, fwspec); return 0; } void iommu_fwspec_free(struct device *dev) { - struct iommu_fwspec *fwspec = dev->archdata.iommu; + struct iommu_fwspec *fwspec = arch_get_iommu_fwspec(dev); if (fwspec) { of_node_put(fwspec->iommu_np); @@ -249,7 +249,7 @@ void iommu_fwspec_free(struct device *dev) int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) { - struct iommu_fwspec *fwspec = dev->archdata.iommu; + struct iommu_fwspec *fwspec = arch_get_iommu_fwspec(dev); size_t size; if (!fwspec) @@ -263,11 +263,11 @@ int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) while (num_ids--) fwspec->ids[fwspec->num_ids++] = *ids++; - dev->archdata.iommu = fwspec; + arch_set_iommu_fwspec(dev, fwspec); return 0; } inline struct iommu_fwspec *dev_iommu_fwspec(struct device *dev) { - return dev->archdata.iommu; + return arch_get_iommu_fwspec(dev); } diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h index accdc05..358db49 100644 --- a/include/linux/of_iommu.h +++ b/include/linux/of_iommu.h @@ -46,6 +46,16 @@ void iommu_fwspec_free(struct device *dev); int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); struct iommu_fwspec *dev_iommu_fwspec(struct device *dev); +#ifdef CONFIG_HAVE_IOMMU_FWSPEC +#include +#else /* !CONFIG_HAVE_IOMMU_FWSPEC */ +static inline void arch_set_iommu_fwspec(struct device *dev, + struct iommu_fwspec *fwspec) {} + +static inline struct iommu_fwspec * +arch_get_iommu_fwspec(struct device *dev) { return NULL; } +#endif + void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops); const struct iommu_ops *of_iommu_get_ops(struct device_node *np);