Skip to contentSkip to conversation

Replace pci_pool with generic dma_pool

PATCH In review Deepak Saxena 2 participants 6 messages Jan 31, 2004 – Feb 2, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Replace pci_pool with generic dma_pool

All,

This set of patches against 2.6.2-rc2 removes the PCI-specific pci_pool structure and replaces it with a generic dma_pool. For compatibility with existing PCI drivers, macros are provided that map pci_pool_* to dma_pool_*. This is extremely useful for architecture that have non-PCI devices but require DMA buffer pools. A good example is USB, where we've had to make some hacks in the ARM implementation of the DMA API to get around the USB's usage of the PCI DMA API and pci_pools with non-PCI device. The patch has been tested on x86, ppc, and xscale (ARM).

Patch portions are posted as replies to this email.

If this patch is accepted, I'll post a follow-on patch to the USB list to clean up the USB layer to only use the generic DMA functions instead of the PCI functions.

~Deepak

diffstat:

 linux/drivers/base/Makefile   |    2 
 linux/drivers/base/core.c     |    1 
 linux/drivers/base/dmapool.c  |  409 ++++++++++++++++++++++++++++++++++++++++++++++
 linux/drivers/pci/Makefile    |    2 
 linux/drivers/pci/probe.c     |    2 
 linux/include/linux/device.h  |    1 
 linux/include/linux/dmapool.h |   27 +++
 linux/include/linux/pci.h     |   14 -
 linux/drivers/pci/pool.c      |  404 ---------------------------------------------
 9 files changed, 448 insertions(+), 414 deletions(-)
Signature · 1 line
Deepak Saxena - [email protected]
#1 lore raw

PATCH 1/3 Replace pci_pool with generic dma_pool

- Add dmapool.c to drivers/base
- Initialize struct device.dma_pools in device_initialize()

drivers/base/Makefile +1 -1
diff -Nru a/drivers/base/Makefile b/drivers/base/Makefile
@@ -2,7 +2,7 @@
 
 obj-y			:= core.o sys.o interface.o bus.o \
 			   driver.o class.o class_simple.o platform.o \
-			   cpu.o firmware.o init.o map.o
+			   cpu.o firmware.o init.o map.o dmapool.o
 obj-y			+= power/
 obj-$(CONFIG_FW_LOADER)	+= firmware_class.o
 obj-$(CONFIG_NUMA)	+= node.o  memblk.o
drivers/base/core.c +1 -0
diff -Nru a/drivers/base/core.c b/drivers/base/core.c
@@ -197,6 +197,7 @@
 	INIT_LIST_HEAD(&dev->children);
 	INIT_LIST_HEAD(&dev->driver_list);
 	INIT_LIST_HEAD(&dev->bus_list);
+	INIT_LIST_HEAD(&dev->dma_pools);
 }
 
 /**
drivers/base/dmapool.c new file +409 -0

409 lines not on this page · raw message

Signature · 1 line
Deepak Saxena - [email protected]
#2 lore raw

PATCH 2/3 Replace pci_pool with generic dma_pool

In reply to Deepak Saxena

- Remove drivers/pci/pool.c
- Remove initialization of struct pci_dev.pools from pci_setup_device()

drivers/pci/Makefile +1 -1
diff -Nru a/drivers/pci/Makefile b/drivers/pci/Makefile
@@ -2,7 +2,7 @@
 # Makefile for the PCI bus specific drivers.
 #
 
-obj-y		+= access.o bus.o probe.o remove.o pci.o pool.o quirks.o \
+obj-y		+= access.o bus.o probe.o remove.o pci.o quirks.o \
 			names.o pci-driver.o search.o pci-sysfs.o
 obj-$(CONFIG_PROC_FS) += proc.o
 
drivers/pci/pool.c deleted +0 -404

404 lines not on this page · raw message

drivers/pci/probe.c +0 -2
diff -Nru a/drivers/pci/probe.c b/drivers/pci/probe.c
@@ -407,8 +407,6 @@
 	sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
 		dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
 
-	INIT_LIST_HEAD(&dev->pools);
-
 	pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
 	class >>= 8;				    /* upper 3 bytes */
 	dev->class = class;
Signature · 1 line
Deepak Saxena - [email protected]
#3 lore raw

PATCH 3/3 Replace pci_pool with generic dma_pool

In reply to Deepak Saxena

include/linux changes:

- Add dma_pools member to struct device
- Add include/linux/dmapool.h
- Remove pools memober from struct pci_dev
- Replace pci_pool_* functions with macros that map to dma_pool_* functions

include/linux/device.h +1 -0
diff -Nru a/include/linux/device.h b/include/linux/device.h
@@ -284,6 +284,7 @@
 					   detached from its driver. */
 
 	u64		*dma_mask;	/* dma mask (if dma'able device) */
+	struct list_head	dma_pools;	/* dma pools (if dma'ble) */
 
 	void	(*release)(struct device * dev);
 };
include/linux/dmapool.h new file +27 -0
diff -Nru a/include/linux/dmapool.h b/include/linux/dmapool.h
@@ -0,0 +1,27 @@
+/*
+ * include/linux/dmapool.h
+ *
+ * Allocation pools for DMAable (coherent) memory.
+ *
+ * This file is licensed under  the terms of the GNU General Public 
+ * License version 2. This program is licensed "as is" without any 
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef LINUX_DMAPOOL_H
+#define	LINUX_DMAPOOL_H
+
+#include <asm/io.h>
+#include <asm/scatterlist.h>
+
+struct dma_pool *dma_pool_create(const char *name, struct device *dev, 
+			size_t size, size_t align, size_t allocation);
+
+void dma_pool_destroy(struct dma_pool *pool);
+
+void *dma_pool_alloc(struct dma_pool *pool, int mem_flags, dma_addr_t *handle);
+
+void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr);
+
+#endif
+
include/linux/pci.h +8 -6
diff -Nru a/include/linux/pci.h b/include/linux/pci.h
@@ -393,7 +393,6 @@
 					   0xffffffff.  You only need to change
 					   this if your device has broken DMA
 					   or supports 64-bit transfers.  */
-	struct list_head pools;		/* pci_pools tied to this device */
 
 	u64		consistent_dma_mask;/* Like dma_mask, but for
 					       pci_alloc_consistent mappings as
@@ -689,12 +688,15 @@
 int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass);
 
 /* kmem_cache style wrapper around pci_alloc_consistent() */
-struct pci_pool *pci_pool_create (const char *name, struct pci_dev *dev,
-		size_t size, size_t align, size_t allocation);
-void pci_pool_destroy (struct pci_pool *pool);
 
-void *pci_pool_alloc (struct pci_pool *pool, int flags, dma_addr_t *handle);
-void pci_pool_free (struct pci_pool *pool, void *vaddr, dma_addr_t addr);
+#include <linux/dmapool.h>
+
+#define	pci_pool dma_pool
+#define pci_pool_create(name, pdev, size, align, allocation) \
+		dma_pool_create(name, &pdev->dev, size, align, allocation)
+#define	pci_pool_destroy(pool) dma_pool_destroy(pool)
+#define	pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
+#define	pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
 
 #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
 extern struct pci_dev *isa_bridge;
Signature · 1 line
Deepak Saxena - [email protected]
#4 lore raw
In reply to Deepak Saxena
Quoted 12 lines · Deepak Saxena

All,

This set of patches against 2.6.2-rc2 removes the PCI-specific pci_pool structure and replaces it with a generic dma_pool. For compatibility with existing PCI drivers, macros are provided that map pci_pool_* to dma_pool_*. This is extremely useful for architecture that have non-PCI devices but require DMA buffer pools. A good example is USB, where we've had to make some hacks in the ARM implementation of the DMA API to get around the USB's usage of the PCI DMA API and pci_pools with non-PCI device. The patch has been tested on x86, ppc, and xscale (ARM).

Quoted 5 lines

Patch portions are posted as replies to this email.

If this patch is accepted, I'll post a follow-on patch to the USB list to clean up the USB layer to only use the generic DMA functions instead of the PCI functions.

These patches look sane. I'll apply them to my PCI tree this weekend, which will propagate to the -mm tree. If nothing breaks there, I'll send them on to Linus after 2.6.2 comes out.

thanks a lot for this.

greg k-h

#5 lore raw
In reply to Deepak Saxena
Quoted 12 lines · Deepak Saxena

All,

This set of patches against 2.6.2-rc2 removes the PCI-specific pci_pool structure and replaces it with a generic dma_pool. For compatibility with existing PCI drivers, macros are provided that map pci_pool_* to dma_pool_*. This is extremely useful for architecture that have non-PCI devices but require DMA buffer pools. A good example is USB, where we've had to make some hacks in the ARM implementation of the DMA API to get around the USB's usage of the PCI DMA API and pci_pools with non-PCI device. The patch has been tested on x86, ppc, and xscale (ARM).

Quoted 5 lines

Patch portions are posted as replies to this email.

If this patch is accepted, I'll post a follow-on patch to the USB list to clean up the USB layer to only use the generic DMA functions instead of the PCI functions.

Ok, I've applied these patches to my trees. I did merge your first and second patches into 1 patch so bitkeeper would show that you just moved the pool.c file from one directory to another, which keeps the file history correct.

I'll forward them off to Linus after 2.6.2 comes out.

thanks,

greg k-h