]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/powerpc/platforms/iseries/iommu.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[linux-2.6-omap-h63xx.git] / arch / powerpc / platforms / iseries / iommu.c
index 3b6a9666c2c07c0407989a5a17d98e2cdcdf4179..11fa3c772ed567f8ba907b024dc3ef8010713777 100644 (file)
 #include <linux/dma-mapping.h>
 #include <linux/list.h>
 #include <linux/pci.h>
+#include <linux/module.h>
 
 #include <asm/iommu.h>
+#include <asm/vio.h>
 #include <asm/tce.h>
 #include <asm/machdep.h>
 #include <asm/abs_addr.h>
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
 #include <asm/iseries/hv_call_xm.h>
+#include <asm/iseries/hv_call_event.h>
 #include <asm/iseries/iommu.h>
 
 static void tce_build_iSeries(struct iommu_table *tbl, long index, long npages,
@@ -160,8 +163,10 @@ static struct iommu_table *iommu_table_find(struct iommu_table * tbl)
                    (it->it_type == TCE_PCI) &&
                    (it->it_offset == tbl->it_offset) &&
                    (it->it_index == tbl->it_index) &&
-                   (it->it_size == tbl->it_size))
+                   (it->it_size == tbl->it_size)) {
+                       of_node_put(node);
                        return it;
+               }
        }
        return NULL;
 }
@@ -189,6 +194,55 @@ void iommu_devnode_init_iSeries(struct pci_dev *pdev, struct device_node *dn)
 }
 #endif
 
+static struct iommu_table veth_iommu_table;
+static struct iommu_table vio_iommu_table;
+
+void *iseries_hv_alloc(size_t size, dma_addr_t *dma_handle, gfp_t flag)
+{
+       return iommu_alloc_coherent(NULL, &vio_iommu_table, size, dma_handle,
+                               DMA_32BIT_MASK, flag, -1);
+}
+EXPORT_SYMBOL_GPL(iseries_hv_alloc);
+
+void iseries_hv_free(size_t size, void *vaddr, dma_addr_t dma_handle)
+{
+       iommu_free_coherent(&vio_iommu_table, size, vaddr, dma_handle);
+}
+EXPORT_SYMBOL_GPL(iseries_hv_free);
+
+dma_addr_t iseries_hv_map(void *vaddr, size_t size,
+                       enum dma_data_direction direction)
+{
+       return iommu_map_single(NULL, &vio_iommu_table, vaddr, size,
+                               DMA_32BIT_MASK, direction);
+}
+
+void iseries_hv_unmap(dma_addr_t dma_handle, size_t size,
+                       enum dma_data_direction direction)
+{
+       iommu_unmap_single(&vio_iommu_table, dma_handle, size, direction);
+}
+
+void __init iommu_vio_init(void)
+{
+       iommu_table_getparms_iSeries(255, 0, 0xff, &veth_iommu_table);
+       veth_iommu_table.it_size /= 2;
+       vio_iommu_table = veth_iommu_table;
+       vio_iommu_table.it_offset += veth_iommu_table.it_size;
+
+       if (!iommu_init_table(&veth_iommu_table, -1))
+               printk("Virtual Bus VETH TCE table failed.\n");
+       if (!iommu_init_table(&vio_iommu_table, -1))
+               printk("Virtual Bus VIO TCE table failed.\n");
+}
+
+struct iommu_table *vio_build_iommu_table_iseries(struct vio_dev *dev)
+{
+       if (strcmp(dev->type, "network") == 0)
+               return &veth_iommu_table;
+       return &vio_iommu_table;
+}
+
 void iommu_init_early_iSeries(void)
 {
        ppc_md.tce_build = tce_build_iSeries;