powerpc: Refactor 64 bits DMA operations
Subsystems (2)
This is also something I'll need in 2.6.20. Right now posted only for comments though. It's known to "miss" fixup of at least pasemi and maybe a few other things and I've not tested if I break 32 bits build yet :)
This patch completely refactors DMA operations for 64 bits powerpc. 32 bits is untouched for now.
It depends on the patches previously posted (and now in gregkh tree) to add a notifier to the bus types for addition/removal of devices.
The basic idea is to define an auxilliary structure (struct device_ext) that can be attached to any struct device in the system. We use the "firmware_data" pointer to reference it for now, though I kept that very isolated so I can change it in the future, especially if I get my way with Greg KH and add a sysdata pointer to struct device instead or even better, embed it inside struct device to limit the number of pointer indirections.
This structure holds the optional OF device node pointer, the DMA ops and associated void *data (to be used by the ops, typically, the iommu table pointer for machines with more than one), and a numa node id (if useful) to constraint consistent memory allocs. In the future, I might also merge the current pci_dn into it for PCI.
The old vio, pci-iommu and pci-direct DMA ops are gone. They are now replaced by a set of generic iommu and direct DMA ops (non PCI specific) that can be used by bus types. The toplevel implementation is now inline.
In the case of busses we control completely, like vio, the bus layer will create and fill this structure and all is easy (see the changes to vio.c or ebus).
In the case of "foreign" busses like PCI, what I've done is that I create the data structure in the PCI fixup code (which is run after discovery but before the struct device is actually registered with the core, as PCI keeps those two steps separate) and use the old ppc_md. callbacks that I renamed for consistency, to setup the iommu table pointer if necessary. By default the dma_ops are set to the content of a global pci_dma_ops that your platform can set. So if you have no iommu, you can just set that dma_direct_ops and not implement any of the callbacks.
I do have plans to move away from that model for PCI, and consolidate this with pci_dn, while make everybody use the platform notifiers provided by the device core upon device registration but this goes beyond the goal of this patch.
The cool thing is that the diffstat is also negative:
arch/powerpc/kernel/pci_direct_iommu.c | 98 ------- arch/powerpc/kernel/pci_iommu.c | 164 ----------- linux-cell/arch/powerpc/kernel/Makefile | 3 linux-cell/arch/powerpc/kernel/dma_64.c | 251 ++++++++++-------- linux-cell/arch/powerpc/kernel/ibmebus.c | 6 linux-cell/arch/powerpc/kernel/iommu.c | 6 linux-cell/arch/powerpc/kernel/of_platform.c | 10 linux-cell/arch/powerpc/kernel/pci_64.c | 56 +++- linux-cell/arch/powerpc/kernel/setup_64.c | 5 linux-cell/arch/powerpc/kernel/vio.c | 103 ++----- linux-cell/arch/powerpc/platforms/cell/iommu.c | 21 - linux-cell/arch/powerpc/platforms/iseries/iommu.c | 20 - linux-cell/arch/powerpc/platforms/iseries/pci.c | 2 linux-cell/arch/powerpc/platforms/pseries/iommu.c | 105 ++++--- linux-cell/arch/powerpc/platforms/pseries/pci_dlpar.c | 4 linux-cell/arch/powerpc/sysdev/dart_iommu.c | 38 +- linux-cell/include/asm-powerpc/device_ext.h | 43 +++ linux-cell/include/asm-powerpc/dma-mapping.h | 185 ++++++++++--- linux-cell/include/asm-powerpc/ibmebus.h | 3 linux-cell/include/asm-powerpc/iommu.h | 20 - linux-cell/include/asm-powerpc/iseries/iommu.h | 4 linux-cell/include/asm-powerpc/machdep.h | 4 linux-cell/include/asm-powerpc/of_device.h | 4 linux-cell/include/asm-powerpc/pci-bridge.h | 3 linux-cell/include/asm-powerpc/pci.h | 8 linux-cell/include/asm-powerpc/vio.h | 3 26 files changed, 577 insertions(+), 592 deletions(-)
include/asm-powerpc/device_ext.h new file +43 -0
@@ -0,0 +1,43 @@ +#ifndef _POWERPC_DEVICE_EXT_H +#define _POWERPC_DEVICE_EXT_H +#ifdef __KERNEL__ + +struct dma_mapping_ops ; +struct device_node ; + +/* +* Auxilliary data structure that can be attached to any struct device +* in the system. (Currently using firmware_data, though I'd like to +* see a system_data in there instead). +* +* The structure can be wrapped within a bus-type specific data structure. +* +* There are no strict lifetime rules for this structure, it's entirely up +* to the bus to manage it's lifetime. +*/ +struct device_ext { +/* Optional pointer to an OF device node */ +struct device_node *of_node; + +/* DMA operations on that device */ +struct dma_mapping_ops *dma_ops; +void *dma_data; + +/* NUMA node if applicable */ +int numa_node; +}; + +/* Provide accessors in case we move it to some other field */ +static inline struct device_ext *device_get_ext (const struct device *dev) +{ +return dev->firmware_data; +} + +static inline void device_set_ext (struct device *dev,struct device_ext *ext) +{ + dev->firmware_data = ext; +} + + +#endif /* __KERNEL__ */ +#endif /* _POWERPC_DEVICE_EXT_H */
arch/powerpc/kernel/dma_64.c +152 -99
303 lines not on this page · raw message
arch/powerpc/kernel/iommu.c +3 -3
@@ -258,9 +258,9 @@ static void iommu_free(struct iommu_tablspin_unlock_irqrestore (&(tbl->it_lock), flags); } -int iommu_map_sg (struct device *dev,struct iommu_table *tbl, -struct scatterlist *sglist,int nelems, -unsigned long mask,enum dma_data_direction direction) +int iommu_map_sg (struct iommu_table *tbl,struct scatterlist *sglist, +int nelems,unsigned long mask, +enum dma_data_direction direction) {dma_addr_t dma_next =0 , dma_addr;unsigned long flags;
arch/powerpc/kernel/pci_direct_iommu.c deleted +0 -98
98 lines not on this page · raw message
arch/powerpc/kernel/pci_iommu.c deleted +0 -164
164 lines not on this page · raw message
include/asm-powerpc/dma-mapping.h +146 -39
203 lines not on this page · raw message
include/asm-powerpc/iommu.h +10 -10
@@ -87,22 +87,22 @@ extern void iommu_free_table(struct deviextern struct iommu_table *iommu_init_table (struct iommu_table * tbl,int nid); -extern int iommu_map_sg (struct device *dev,struct iommu_table *tbl, -struct scatterlist *sglist,int nelems,unsigned long mask, -enum dma_data_direction direction); +extern int iommu_map_sg (struct iommu_table *tbl,struct scatterlist *sglist, +int nelems,unsigned long mask, +enum dma_data_direction direction);extern void iommu_unmap_sg (struct iommu_table *tbl,struct scatterlist *sglist, -int nelems,enum dma_data_direction direction); +int nelems,enum dma_data_direction direction);extern void *iommu_alloc_coherent (struct iommu_table *tbl,size_t size, -dma_addr_t *dma_handle,unsigned long mask, -gfp_t flag,int node); +dma_addr_t *dma_handle,unsigned long mask, +gfp_t flag,int node);extern void iommu_free_coherent (struct iommu_table *tbl,size_t size, -void *vaddr,dma_addr_t dma_handle); +void *vaddr,dma_addr_t dma_handle);extern dma_addr_t iommu_map_single (struct iommu_table *tbl,void *vaddr, -size_t size,unsigned long mask, -enum dma_data_direction direction); +size_t size,unsigned long mask, +enum dma_data_direction direction);extern void iommu_unmap_single (struct iommu_table *tbl,dma_addr_t dma_handle, -size_t size,enum dma_data_direction direction); +size_t size,enum dma_data_direction direction);extern void iommu_init_early_pSeries (void );extern void iommu_init_early_iSeries (void );
arch/powerpc/kernel/vio.c +31 -72
188 lines not on this page · raw message
include/asm-powerpc/vio.h +2 -1
@@ -23,6 +23,7 @@#include <asm/hvcall.h> #include <asm/scatterlist.h> +#include <asm/device_ext.h> /* * Architecture-specific constants for drivers to
@@ -45,12 +46,12 @@ struct iommu_table;* The vio_dev structure is used to describe virtual I/O devices. */ struct vio_dev { -struct iommu_table *iommu_table;/* vio_map_* uses this */ const char *name;const char *type;uint32_t unit_address;unsigned int irq;struct device dev; +struct device_ext dext; };struct vio_driver {
arch/powerpc/kernel/pci_64.c +53 -3
84 lines not on this page · raw message
arch/powerpc/kernel/setup_64.c +5 -0
@@ -33,6 +33,7 @@#include <linux/serial.h> #include <linux/serial_8250.h> #include <linux/bootmem.h> +#include <linux/pci.h> #include <asm/io.h> #include <asm/kdump.h> #include <asm/prom.h>
@@ -530,6 +531,10 @@ void __init setup_arch(char **cmdline_p) conswitchp = &dummy_con;#endif +#ifdef CONFIG_PCI + platform_notify = pci_platform_notify; + platform_notify_remove = pci_platform_notify_remove; +#endif ppc_md.setup_arch ();paging_init ();
arch/powerpc/platforms/pseries/iommu.c +61 -44
243 lines not on this page · raw message
arch/powerpc/platforms/pseries/pci_dlpar.c +2 -2
@@ -93,8 +93,8 @@ pcibios_fixup_new_pci_devices(struct pciif (list_empty (&dev->global_list)) {int i; -/* Need to setup IOMMU tables */ - ppc_md.iommu_dev_setup (dev); +/* Create device extension and setup iommu table */ +pcibios_setup_new_device (dev);if (fix_bus)pcibios_fixup_device_resources (dev, bus);
arch/powerpc/sysdev/dart_iommu.c +17 -21
@@ -45,6 +45,7 @@#include <asm/cacheflush.h> #include <asm/lmb.h> #include <asm/ppc-pci.h> +#include <asm/device_ext.h> #include "dart.h"
@@ -289,24 +290,23 @@ static void iommu_table_dart_setup(void)set_bit (iommu_table_dart.it_size -1 , iommu_table_dart.it_map); } -static void iommu_dev_setup_dart (struct pci_dev *dev) +static void pci_dma_dev_setup_dart (struct pci_dev *dev) { -struct device_node *dn; +struct device_ext *dext =device_get_ext (&dev->dev); + +if (dext ==NULL ) { +printk (KERN_ERR "dart: Attempt to setup PCI dev %s " +"with no device extension !" ,pci_name (dev)); +return ; + }/* We only have one iommu table on the mac for now, which makes * things simple. Setup all PCI devices to point to this table -* -* We must use pci_device_to_OF_node() to make sure that -* we get the real "final" pointer to the device in the -* pci_dev sysdata and not the temporary PHB one */ - dn =pci_device_to_OF_node (dev); - -if (dn) -PCI_DN (dn)->iommu_table = &iommu_table_dart; + dext->dma_data = &iommu_table_dart; } -static void iommu_bus_setup_dart (struct pci_bus *bus) +static void pci_dma_bus_setup_dart (struct pci_bus *bus) {struct device_node *dn;
@@ -321,9 +321,6 @@ static void iommu_bus_setup_dart(structPCI_DN (dn)->iommu_table = &iommu_table_dart; } -static void iommu_dev_setup_null (struct pci_dev *dev) { } -static void iommu_bus_setup_null (struct pci_bus *bus) { } -void iommu_init_early_dart (void ) {struct device_node *dn;
@@ -344,22 +341,21 @@ void iommu_init_early_dart(void)/* Initialize the DART HW */ if (dart_init (dn) ==0 ) { - ppc_md.iommu_dev_setup = iommu_dev_setup_dart; - ppc_md.iommu_bus_setup = iommu_bus_setup_dart; + ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_dart; + ppc_md.pci_dma_bus_setup = pci_dma_bus_setup_dart;/* Setup pci_dma ops */ -pci_iommu_init (); - + pci_dma_ops = &dma_iommu_ops;return ; } bail:/* If init failed, use direct iommu and null setup functions */ - ppc_md.iommu_dev_setup = iommu_dev_setup_null; - ppc_md.iommu_bus_setup = iommu_bus_setup_null; + ppc_md.pci_dma_dev_setup =NULL ; + ppc_md.pci_dma_bus_setup =NULL ;/* Setup pci_dma ops */ -pci_direct_iommu_init (); + pci_dma_ops = &dma_direct_ops; }
include/asm-powerpc/machdep.h +2 -2
@@ -84,8 +84,8 @@ struct machdep_calls {unsigned long (*tce_get)(struct iommu_table *tbl,long index);void (*tce_flush)(struct iommu_table *tbl); -void (*iommu_dev_setup)(struct pci_dev *dev); -void (*iommu_bus_setup)(struct pci_bus *bus); +void (*pci_dma_dev_setup)(struct pci_dev *dev); +void (*pci_dma_bus_setup)(struct pci_bus *bus);#endif /* CONFIG_PPC64 */ int (*probe)(void );
include/asm-powerpc/pci-bridge.h +3 -0
@@ -161,6 +161,9 @@ static inline unsigned long pci_address_ }#endif +extern int pci_platform_notify (struct device * dev); +extern int pci_platform_notify_remove (struct device * dev); +/* Return values for ppc_md.pci_probe_mode function */ #define PCI_PROBE_NONE -1/* Don't look at this bus at all */ #define PCI_PROBE_NORMAL 0/* Do normal PCI probing */
include/asm-powerpc/pci.h +5 -3
@@ -76,15 +76,15 @@ static inline int pcibios_prep_mwi(strucreturn 0 ; } -extern struct dma_mapping_ops pci_dma_ops; +extern struct dma_mapping_ops *pci_dma_ops;/* For DAC DMA, we currently don't support it by default, but * we let 64-bit platforms override this. */ static inline int pci_dac_dma_supported (struct pci_dev *hwdev,u64 mask) { -if (pci_dma_ops.dac_dma_supported) -return pci_dma_ops.dac_dma_supported (&hwdev->dev, mask); +if (pci_dma_ops && pci_dma_ops->dac_dma_supported) +return pci_dma_ops->dac_dma_supported (&hwdev->dev, mask);return 0 ; }
@@ -216,6 +216,8 @@ extern int remap_bus_range(struct pci_buextern void pcibios_fixup_device_resources (struct pci_dev *dev,struct pci_bus *bus); +extern void pcibios_setup_new_device (struct pci_dev *dev); +extern void pcibios_claim_one_bus (struct pci_bus *b);extern struct pci_controller *init_phb_dynamic (struct device_node *dn);
arch/powerpc/kernel/Makefile +1 -2
@@ -63,8 +63,7 @@ obj-$(CONFIG_PPC_UDBG_16550) += legacy_s module-$(CONFIG_PPC64) += module_64.o obj-$(CONFIG_MODULES) += $(module-y) -pci64-$(CONFIG_PPC64) += pci_64.o pci_dn.o pci_iommu.o \ - pci_direct_iommu.o iomap.o +pci64-$(CONFIG_PPC64) += pci_64.o pci_dn.o iomap.o pci32-$(CONFIG_PPC32) := pci_32.o obj-$(CONFIG_PCI) += $(pci64-y) $(pci32-y) kexec-$(CONFIG_PPC64) := machine_kexec_64.o
arch/powerpc/kernel/ibmebus.c +5 -1
@@ -112,7 +112,7 @@ static int ibmebus_dma_supported(structreturn 1 ; } -struct dma_mapping_ops ibmebus_dma_ops = { +static struct dma_mapping_ops ibmebus_dma_ops = { .alloc_coherent = ibmebus_alloc_coherent, .free_coherent = ibmebus_free_coherent, .map_single = ibmebus_map_single,
@@ -176,6 +176,10 @@ static struct ibmebus_dev* __devinit ibm dev->ofdev.dev.bus = &ibmebus_bus_type; dev->ofdev.dev.release = ibmebus_dev_release; +device_set_ext (&dev->ofdev.dev, &dev->dext); + dev->dext.of_node = dev->ofdev.node; + dev->dext.dma_ops = &ibmebus_dma_ops; +/* An ibmebusdev is based on a of_device. We have to change the * bus type to use our own DMA mapping operations. */
arch/powerpc/platforms/cell/iommu.c +6 -15
@@ -255,9 +255,6 @@ static void enable_mapping(void __iomemset_iost_origin (mmio_base); } -static void iommu_dev_setup_null (struct pci_dev *d) { } -static void iommu_bus_setup_null (struct pci_bus *b) { } -struct cell_iommu {unsigned long base;unsigned long mmio_base;
@@ -306,12 +303,15 @@ static void cell_do_map_iommu(struct cel } } -static void iommu_devnode_setup (struct device_node *d) +static void pci_dma_cell_bus_setup (struct pci_bus *b) {const unsigned int *ioid;unsigned long map_start, map_size, token;const unsigned long *dma_window;struct cell_iommu *iommu; +struct device_node *d; + + d =pci_bus_to_OF_node (b); ioid =get_property (d,"ioid" ,NULL );if (!ioid)
@@ -330,12 +330,6 @@ static void iommu_devnode_setup(struct dcell_do_map_iommu (iommu, *ioid, map_start, map_size); } -static void iommu_bus_setup (struct pci_bus *b) -{ -struct device_node *d = (struct device_node *)b->sysdata; -iommu_devnode_setup (d); -} -static int cell_map_iommu_hardcoded (int num_nodes) {
@@ -499,16 +493,13 @@ void cell_init_iommu(void)if (setup_bus) {pr_debug ("%s: IOMMU mapping activated\n" , __FUNCTION__); - ppc_md.iommu_dev_setup = iommu_dev_setup_null; - ppc_md.iommu_bus_setup = iommu_bus_setup; + ppc_md.pci_dma_bus_setup = pci_dma_cell_bus_setup; }else {pr_debug ("%s: IOMMU mapping activated, " "no device action necessary\n" , __FUNCTION__);/* Direct I/O, IOMMU off */ - ppc_md.iommu_dev_setup = iommu_dev_setup_null; - ppc_md.iommu_bus_setup = iommu_bus_setup_null; } } - pci_dma_ops = cell_iommu_ops; + pci_dma_ops = &cell_iommu_ops; }
include/asm-powerpc/ibmebus.h +2 -1
@@ -43,12 +43,13 @@#include <linux/interrupt.h> #include <linux/mod_devicetable.h> #include <asm/of_device.h> +#include <asm/device_ext.h> -extern struct dma_mapping_ops ibmebus_dma_ops;extern struct bus_type ibmebus_bus_type;struct ibmebus_dev {const char *name; +struct device_ext dext;struct of_device ofdev; };
include/asm-powerpc/of_device.h +3 -1
@@ -5,6 +5,7 @@#include <linux/device.h> #include <linux/mod_devicetable.h> #include <asm/prom.h> +#include <asm/device_ext.h> /*
@@ -14,8 +15,9 @@*/ struct of_device { -struct device_node *node;/* OF device node */ +struct device_node *node;/* to be obsoleted */ u64 dma_mask;/* DMA mask */ +struct device_ext dext;struct device dev;/* Generic device interface */ };#define to_of_device (d) container_of(d, struct of_device, dev)
arch/powerpc/kernel/of_platform.c +9 -1
@@ -22,7 +22,7 @@#include <asm/dcr.h> #include <asm/of_device.h> #include <asm/of_platform.h> - +#include <asm/topology.h> /* * The list of OF IDs below is used for matching bus types in the
@@ -220,6 +220,14 @@ struct of_device* of_platform_device_cre dev->dev.parent = parent; dev->dev.bus = &of_platform_bus_type; dev->dev.release = of_release_dev; +device_set_ext (&dev->dev, &dev->dext); + dev->dext.of_node = np; + dev->dext.numa_node =of_node_to_nid (np); + +/* We do not fill the DMA ops for platform devices by default. +* This is currently the responsibility of the platform code +* to do such, possibly using a device notifier +*/ if (bus_id)strlcpy (dev->dev.bus_id, bus_id,BUS_ID_SIZE );
arch/powerpc/platforms/iseries/iommu.c +12 -8
@@ -27,6 +27,7 @@#include <linux/types.h> #include <linux/dma-mapping.h> #include <linux/list.h> +#include <linux/pci.h> #include <asm/iommu.h> #include <asm/tce.h>
@@ -36,6 +37,7 @@#include <asm/pci-bridge.h> #include <asm/iseries/hv_call_xm.h> #include <asm/iseries/iommu.h> +#include <asm/device_ext.h> static void tce_build_iSeries (struct iommu_table *tbl,long index,long npages,unsigned long uaddr,enum dma_data_direction direction)
@@ -168,14 +170,21 @@ static struct iommu_table *iommu_table_f } -void iommu_devnode_init_iSeries (struct device_node *dn) +void iommu_devnode_init_iSeries (struct pci_dev *pdev,struct device_node *dn) {struct iommu_table *tbl; +struct device_ext *dext =device_get_ext (&pdev->dev);struct pci_dn *pdn =PCI_DN (dn);const u32 *lsn =get_property (dn,"linux,logical-slot-number" ,NULL );BUG_ON (lsn ==NULL ); +if (dext ==NULL ) { +printk (KERN_ERR "iommu: Attempt to setup PCI dev %s " +"with no device extension !" ,pci_name (pdev)); +return ; + } + tbl =kmalloc (sizeof (struct iommu_table ),GFP_KERNEL );iommu_table_getparms_iSeries (pdn->busno, *lsn,0 , tbl);
@@ -186,19 +195,14 @@ void iommu_devnode_init_iSeries(struct d pdn->iommu_table =iommu_init_table (tbl,-1 ); elsekfree (tbl ); + dext->dma_data = pdn->iommu_table; }#endif -static void iommu_dev_setup_iSeries (struct pci_dev *dev) { } -static void iommu_bus_setup_iSeries (struct pci_bus *bus) { } -void iommu_init_early_iSeries (void ) { ppc_md.tce_build = tce_build_iSeries; ppc_md.tce_free = tce_free_iSeries; - ppc_md.iommu_dev_setup = iommu_dev_setup_iSeries; - ppc_md.iommu_bus_setup = iommu_bus_setup_iSeries; - -pci_iommu_init (); + pci_dma_ops = &dma_iommu_ops; }
arch/powerpc/platforms/iseries/pci.c +1 -1
@@ -253,7 +253,7 @@ void __init iSeries_pci_final_fixup(voidPCI_DN (node)->pcidev = pdev;allocate_device_bars (pdev);iSeries_Device_Information (pdev, DeviceCount); -iommu_devnode_init_iSeries (node); +iommu_devnode_init_iSeries (pdev, node); }else printk ("PCI: Device Tree not found for 0x%016lX\n" , (unsigned long )pdev);
include/asm-powerpc/iseries/iommu.h +3 -1
@@ -21,11 +21,13 @@* Boston, MA 02111-1307 USA */ +struct pci_dev ;struct device_node ;struct iommu_table ;/* Creates table for an individual device node */ -extern void iommu_devnode_init_iSeries (struct device_node *dn); +extern void iommu_devnode_init_iSeries (struct pci_dev *pdev, +struct device_node *dn);/* Get table parameters from HV */ extern void iommu_table_getparms_iSeries(unsigned long busno,
Quoted 6 lines · Benjamin Herrenschmidt
This is also something I'll need in 2.6.20. Right now posted only for comments though. It's known to "miss" fixup of at least pasemi and maybe a few other things and I've not tested if I break 32 bits build yet :)
This patch completely refactors DMA operations for 64 bits powerpc. 32 bits is untouched for now.
Can we please make 32bit use the same scheme for consistancy? It would just plug in a set of dummy direct mapped ops, quite similar to what we do in Cell (just without setting the magic bit)
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Benjamin Herrenschmidt
This is also something I'll need in 2.6.20. Right now posted only for comments though. It's known to "miss" fixup of at least pasemi and maybe a few other things and I've not tested if I break 32 bits build yet :)
This patch completely refactors DMA operations for 64 bits powerpc. 32 bits is untouched for now.
Can we please make 32bit use the same scheme for consistancy? It would just plug in a set of dummy direct mapped ops, quite similar to what we do in Cell (just without setting the magic bit)
dma_64.c has a set of generic direct ops that could be used for 32 bits as well. It's just that in addition to fairly different PCI code, 32 bits code use a wider variety of bus types and platform devices and does DMA from them. All those would need to be updated to get the device extension with the dma ops pointers.
That's why right now, I prefer leaving 32 bits alone. I do plan to converge 32 and 64 bits PCI code, don't worry about that :-) At which point I'll also tackle that issue.
Right now, 64 bits DMA is different, I'm not making it more or less different, just differently different :-). Merging 32 bits here is just not something I can do for 2.6.20 timeframe.
Ben