[PATCH 2/9] x86/iommu: add stackable dma_ops registration interface

From: Joerg Roedel
Date: Mon Sep 22 2008 - 14:22:25 EST


This patch adds the function x86_register_dma_ops which drivers can use
to register their specific dma_ops implementations. The patch also adds
the data structures necessary for registration and the initializtion of
them.

Signed-off-by: Joerg Roedel <joerg.roedel@xxxxxxx>
---
arch/x86/kernel/pci-dma.c | 31 +++++++++++++++++++++++++++++++
include/asm-x86/dma-mapping.h | 3 +++
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index d2f2c01..c783b73 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -47,6 +47,11 @@ EXPORT_SYMBOL(iommu_bio_merge);
dma_addr_t bad_dma_address __read_mostly = 0;
EXPORT_SYMBOL(bad_dma_address);

+/* The lists for stacking dma_ops and its lock */
+static DEFINE_RWLOCK(dma_ops_list_lock);
+
+static struct list_head dma_ops_list[DMA_OPS_TYPE_MAX];
+
/* Dummy device used for NULL arguments (normally ISA). Better would
be probably a smaller DMA mask, but this is bug-to-bug compatible
to older i386. */
@@ -57,6 +62,26 @@ struct device x86_dma_fallback_dev = {
};
EXPORT_SYMBOL(x86_dma_fallback_dev);

+static void __init init_dma_ops_list(void)
+{
+ int i;
+
+ for (i = 0; i < DMA_OPS_TYPE_MAX; ++i)
+ INIT_LIST_HEAD(&dma_ops_list[i]);
+}
+
+void x86_register_dma_ops(struct dma_mapping_ops *ops,
+ enum dma_ops_driver_type type)
+{
+ unsigned long flags;
+
+ BUG_ON(type < DMA_OPS_TYPE_PV || type >= DMA_OPS_TYPE_MAX);
+
+ write_lock_irqsave(&dma_ops_list_lock, flags);
+ list_add_tail(&ops->list, &dma_ops_list[type]);
+ write_unlock_irqrestore(&dma_ops_list_lock, flags);
+}
+
int dma_set_mask(struct device *dev, u64 mask)
{
if (!dev->dma_mask || !dma_supported(dev, mask))
@@ -257,6 +282,12 @@ EXPORT_SYMBOL(dma_supported);

static int __init pci_iommu_init(void)
{
+ /*
+ * initialize dma_ops_list so that drivers can register their
+ * implementations
+ */
+ init_dma_ops_list();
+
calgary_iommu_init();

intel_iommu_init();
diff --git a/include/asm-x86/dma-mapping.h b/include/asm-x86/dma-mapping.h
index 59d1101..128786b 100644
--- a/include/asm-x86/dma-mapping.h
+++ b/include/asm-x86/dma-mapping.h
@@ -80,6 +80,9 @@ enum dma_ops_driver_type {
DMA_OPS_TYPE_MAX,
};

+extern void x86_register_dma_ops(struct dma_mapping_ops *ops,
+ enum dma_ops_driver_type type);
+
extern struct dma_mapping_ops *dma_ops;

static inline struct dma_mapping_ops *get_dma_ops(struct device *dev)
--
1.5.6.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/