From 1df8130278c4543555fea697e5714fbac300b899 Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 15:58:50 +0000 Subject: [ARM] dma: remove dmach_t typedef Remove a pointless integer typedef. Signed-off-by: Russell King --- arch/arm/include/asm/dma.h | 32 +++++++-------- arch/arm/include/asm/mach/dma.h | 12 +++--- arch/arm/kernel/dma-isa.c | 42 ++++++++++---------- arch/arm/kernel/dma.c | 86 ++++++++++++++++++++--------------------- arch/arm/mach-footbridge/dma.c | 6 +-- arch/arm/mach-rpc/dma.c | 20 +++++----- 6 files changed, 98 insertions(+), 100 deletions(-) diff --git a/arch/arm/include/asm/dma.h b/arch/arm/include/asm/dma.h index df5638f3643..c5557a650d1 100644 --- a/arch/arm/include/asm/dma.h +++ b/arch/arm/include/asm/dma.h @@ -19,8 +19,6 @@ #include #include -typedef unsigned int dmach_t; - #include /* @@ -52,44 +50,44 @@ static inline void release_dma_lock(unsigned long flags) /* Clear the 'DMA Pointer Flip Flop'. * Write 0 for LSB/MSB, 1 for MSB/LSB access. */ -#define clear_dma_ff(channel) +#define clear_dma_ff(chan) /* Set only the page register bits of the transfer address. * * NOTE: This is an architecture specific function, and should * be hidden from the drivers */ -extern void set_dma_page(dmach_t channel, char pagenr); +extern void set_dma_page(unsigned int chan, char pagenr); /* Request a DMA channel * * Some architectures may need to do allocate an interrupt */ -extern int request_dma(dmach_t channel, const char * device_id); +extern int request_dma(unsigned int chan, const char * device_id); /* Free a DMA channel * * Some architectures may need to do free an interrupt */ -extern void free_dma(dmach_t channel); +extern void free_dma(unsigned int chan); /* Enable DMA for this channel * * On some architectures, this may have other side effects like * enabling an interrupt and setting the DMA registers. */ -extern void enable_dma(dmach_t channel); +extern void enable_dma(unsigned int chan); /* Disable DMA for this channel * * On some architectures, this may have other side effects like * disabling an interrupt or whatever. */ -extern void disable_dma(dmach_t channel); +extern void disable_dma(unsigned int chan); /* Test whether the specified channel has an active DMA transfer */ -extern int dma_channel_active(dmach_t channel); +extern int dma_channel_active(unsigned int chan); /* Set the DMA scatter gather list for this channel * @@ -97,7 +95,7 @@ extern int dma_channel_active(dmach_t channel); * especially since some DMA architectures don't update the * DMA address immediately, but defer it to the enable_dma(). */ -extern void set_dma_sg(dmach_t channel, struct scatterlist *sg, int nr_sg); +extern void set_dma_sg(unsigned int chan, struct scatterlist *sg, int nr_sg); /* Set the DMA address for this channel * @@ -105,9 +103,9 @@ extern void set_dma_sg(dmach_t channel, struct scatterlist *sg, int nr_sg); * especially since some DMA architectures don't update the * DMA address immediately, but defer it to the enable_dma(). */ -extern void __set_dma_addr(dmach_t channel, void *addr); -#define set_dma_addr(channel, addr) \ - __set_dma_addr(channel, bus_to_virt(addr)) +extern void __set_dma_addr(unsigned int chan, void *addr); +#define set_dma_addr(chan, addr) \ + __set_dma_addr(chan, bus_to_virt(addr)) /* Set the DMA byte count for this channel * @@ -115,7 +113,7 @@ extern void __set_dma_addr(dmach_t channel, void *addr); * especially since some DMA architectures don't update the * DMA count immediately, but defer it to the enable_dma(). */ -extern void set_dma_count(dmach_t channel, unsigned long count); +extern void set_dma_count(unsigned int chan, unsigned long count); /* Set the transfer direction for this channel * @@ -124,11 +122,11 @@ extern void set_dma_count(dmach_t channel, unsigned long count); * DMA transfer direction immediately, but defer it to the * enable_dma(). */ -extern void set_dma_mode(dmach_t channel, dmamode_t mode); +extern void set_dma_mode(unsigned int chan, dmamode_t mode); /* Set the transfer speed for this channel */ -extern void set_dma_speed(dmach_t channel, int cycle_ns); +extern void set_dma_speed(unsigned int chan, int cycle_ns); /* Get DMA residue count. After a DMA transfer, this * should return zero. Reading this while a DMA transfer is @@ -136,7 +134,7 @@ extern void set_dma_speed(dmach_t channel, int cycle_ns); * If called before the channel has been used, it may return 1. * Otherwise, it returns the number of _bytes_ left to transfer. */ -extern int get_dma_residue(dmach_t channel); +extern int get_dma_residue(unsigned int chan); #ifndef NO_DMA #define NO_DMA 255 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h index fc7278ea714..281ae7e40a9 100644 --- a/arch/arm/include/asm/mach/dma.h +++ b/arch/arm/include/asm/mach/dma.h @@ -15,12 +15,12 @@ struct dma_struct; typedef struct dma_struct dma_t; struct dma_ops { - int (*request)(dmach_t, dma_t *); /* optional */ - void (*free)(dmach_t, dma_t *); /* optional */ - void (*enable)(dmach_t, dma_t *); /* mandatory */ - void (*disable)(dmach_t, dma_t *); /* mandatory */ - int (*residue)(dmach_t, dma_t *); /* optional */ - int (*setspeed)(dmach_t, dma_t *, int); /* optional */ + int (*request)(unsigned int, dma_t *); /* optional */ + void (*free)(unsigned int, dma_t *); /* optional */ + void (*enable)(unsigned int, dma_t *); /* mandatory */ + void (*disable)(unsigned int, dma_t *); /* mandatory */ + int (*residue)(unsigned int, dma_t *); /* optional */ + int (*setspeed)(unsigned int, dma_t *, int); /* optional */ char *type; }; diff --git a/arch/arm/kernel/dma-isa.c b/arch/arm/kernel/dma-isa.c index 4a3a50495c6..29eca48925d 100644 --- a/arch/arm/kernel/dma-isa.c +++ b/arch/arm/kernel/dma-isa.c @@ -49,25 +49,25 @@ static unsigned int isa_dma_port[8][7] = { { 0xd4, 0xd6, 0xd8, 0x48a, 0x08a, 0xcc, 0xce } }; -static int isa_get_dma_residue(dmach_t channel, dma_t *dma) +static int isa_get_dma_residue(unsigned int chan, dma_t *dma) { - unsigned int io_port = isa_dma_port[channel][ISA_DMA_COUNT]; + unsigned int io_port = isa_dma_port[chan][ISA_DMA_COUNT]; int count; count = 1 + inb(io_port); count |= inb(io_port) << 8; - return channel < 4 ? count : (count << 1); + return chan < 4 ? count : (count << 1); } -static void isa_enable_dma(dmach_t channel, dma_t *dma) +static void isa_enable_dma(unsigned int chan, dma_t *dma) { if (dma->invalid) { unsigned long address, length; unsigned int mode; enum dma_data_direction direction; - mode = channel & 3; + mode = chan & 3; switch (dma->dma_mode & DMA_MODE_MASK) { case DMA_MODE_READ: mode |= ISA_DMA_MODE_READ; @@ -105,34 +105,34 @@ static void isa_enable_dma(dmach_t channel, dma_t *dma) address = dma->buf.dma_address; length = dma->buf.length - 1; - outb(address >> 16, isa_dma_port[channel][ISA_DMA_PGLO]); - outb(address >> 24, isa_dma_port[channel][ISA_DMA_PGHI]); + outb(address >> 16, isa_dma_port[chan][ISA_DMA_PGLO]); + outb(address >> 24, isa_dma_port[chan][ISA_DMA_PGHI]); - if (channel >= 4) { + if (chan >= 4) { address >>= 1; length >>= 1; } - outb(0, isa_dma_port[channel][ISA_DMA_CLRFF]); + outb(0, isa_dma_port[chan][ISA_DMA_CLRFF]); - outb(address, isa_dma_port[channel][ISA_DMA_ADDR]); - outb(address >> 8, isa_dma_port[channel][ISA_DMA_ADDR]); + outb(address, isa_dma_port[chan][ISA_DMA_ADDR]); + outb(address >> 8, isa_dma_port[chan][ISA_DMA_ADDR]); - outb(length, isa_dma_port[channel][ISA_DMA_COUNT]); - outb(length >> 8, isa_dma_port[channel][ISA_DMA_COUNT]); + outb(length, isa_dma_port[chan][ISA_DMA_COUNT]); + outb(length >> 8, isa_dma_port[chan][ISA_DMA_COUNT]); if (dma->dma_mode & DMA_AUTOINIT) mode |= ISA_DMA_AUTOINIT; - outb(mode, isa_dma_port[channel][ISA_DMA_MODE]); + outb(mode, isa_dma_port[chan][ISA_DMA_MODE]); dma->invalid = 0; } - outb(channel & 3, isa_dma_port[channel][ISA_DMA_MASK]); + outb(chan & 3, isa_dma_port[chan][ISA_DMA_MASK]); } -static void isa_disable_dma(dmach_t channel, dma_t *dma) +static void isa_disable_dma(unsigned int chan, dma_t *dma) { - outb(channel | 4, isa_dma_port[channel][ISA_DMA_MASK]); + outb(chan | 4, isa_dma_port[chan][ISA_DMA_MASK]); } static struct dma_ops isa_dma_ops = { @@ -178,11 +178,11 @@ void __init isa_init_dma(dma_t *dma) outb(0xaa, 0x00); if (inb(0) == 0x55 && inb(0) == 0xaa) { - int channel, i; + int chan, i; - for (channel = 0; channel < 8; channel++) { - dma[channel].d_ops = &isa_dma_ops; - isa_disable_dma(channel, NULL); + for (chan = 0; chan < 8; chan++) { + dma[chan].d_ops = &isa_dma_ops; + isa_disable_dma(chan, NULL); } outb(0x40, 0x0b); diff --git a/arch/arm/kernel/dma.c b/arch/arm/kernel/dma.c index d006085ed7e..c31bf00e5ba 100644 --- a/arch/arm/kernel/dma.c +++ b/arch/arm/kernel/dma.c @@ -30,12 +30,12 @@ static dma_t dma_chan[MAX_DMA_CHANNELS]; * * On certain platforms, we have to allocate an interrupt as well... */ -int request_dma(dmach_t channel, const char *device_id) +int request_dma(unsigned int chan, const char *device_id) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; int ret; - if (channel >= MAX_DMA_CHANNELS || !dma->d_ops) + if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) goto bad_dma; if (xchg(&dma->lock, 1) != 0) @@ -47,7 +47,7 @@ int request_dma(dmach_t channel, const char *device_id) ret = 0; if (dma->d_ops->request) - ret = dma->d_ops->request(channel, dma); + ret = dma->d_ops->request(chan, dma); if (ret) xchg(&dma->lock, 0); @@ -55,7 +55,7 @@ int request_dma(dmach_t channel, const char *device_id) return ret; bad_dma: - printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel); + printk(KERN_ERR "dma: trying to allocate DMA%d\n", chan); return -EINVAL; busy: @@ -68,42 +68,42 @@ EXPORT_SYMBOL(request_dma); * * On certain platforms, we have to free interrupt as well... */ -void free_dma(dmach_t channel) +void free_dma(unsigned int chan) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; - if (channel >= MAX_DMA_CHANNELS || !dma->d_ops) + if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) goto bad_dma; if (dma->active) { - printk(KERN_ERR "dma%d: freeing active DMA\n", channel); - dma->d_ops->disable(channel, dma); + printk(KERN_ERR "dma%d: freeing active DMA\n", chan); + dma->d_ops->disable(chan, dma); dma->active = 0; } if (xchg(&dma->lock, 0) != 0) { if (dma->d_ops->free) - dma->d_ops->free(channel, dma); + dma->d_ops->free(chan, dma); return; } - printk(KERN_ERR "dma%d: trying to free free DMA\n", channel); + printk(KERN_ERR "dma%d: trying to free free DMA\n", chan); return; bad_dma: - printk(KERN_ERR "dma: trying to free DMA%d\n", channel); + printk(KERN_ERR "dma: trying to free DMA%d\n", chan); } EXPORT_SYMBOL(free_dma); /* Set DMA Scatter-Gather list */ -void set_dma_sg (dmach_t channel, struct scatterlist *sg, int nr_sg) +void set_dma_sg (unsigned int chan, struct scatterlist *sg, int nr_sg) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; if (dma->active) printk(KERN_ERR "dma%d: altering DMA SG while " - "DMA active\n", channel); + "DMA active\n", chan); dma->sg = sg; dma->sgcount = nr_sg; @@ -115,13 +115,13 @@ EXPORT_SYMBOL(set_dma_sg); * * Copy address to the structure, and set the invalid bit */ -void __set_dma_addr (dmach_t channel, void *addr) +void __set_dma_addr (unsigned int chan, void *addr) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; if (dma->active) printk(KERN_ERR "dma%d: altering DMA address while " - "DMA active\n", channel); + "DMA active\n", chan); dma->sg = NULL; dma->addr = addr; @@ -133,13 +133,13 @@ EXPORT_SYMBOL(__set_dma_addr); * * Copy address to the structure, and set the invalid bit */ -void set_dma_count (dmach_t channel, unsigned long count) +void set_dma_count (unsigned int chan, unsigned long count) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; if (dma->active) printk(KERN_ERR "dma%d: altering DMA count while " - "DMA active\n", channel); + "DMA active\n", chan); dma->sg = NULL; dma->count = count; @@ -149,13 +149,13 @@ EXPORT_SYMBOL(set_dma_count); /* Set DMA direction mode */ -void set_dma_mode (dmach_t channel, dmamode_t mode) +void set_dma_mode (unsigned int chan, dmamode_t mode) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; if (dma->active) printk(KERN_ERR "dma%d: altering DMA mode while " - "DMA active\n", channel); + "DMA active\n", chan); dma->dma_mode = mode; dma->invalid = 1; @@ -164,42 +164,42 @@ EXPORT_SYMBOL(set_dma_mode); /* Enable DMA channel */ -void enable_dma (dmach_t channel) +void enable_dma (unsigned int chan) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; if (!dma->lock) goto free_dma; if (dma->active == 0) { dma->active = 1; - dma->d_ops->enable(channel, dma); + dma->d_ops->enable(chan, dma); } return; free_dma: - printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel); + printk(KERN_ERR "dma%d: trying to enable free DMA\n", chan); BUG(); } EXPORT_SYMBOL(enable_dma); /* Disable DMA channel */ -void disable_dma (dmach_t channel) +void disable_dma (unsigned int chan) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; if (!dma->lock) goto free_dma; if (dma->active == 1) { dma->active = 0; - dma->d_ops->disable(channel, dma); + dma->d_ops->disable(chan, dma); } return; free_dma: - printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel); + printk(KERN_ERR "dma%d: trying to disable free DMA\n", chan); BUG(); } EXPORT_SYMBOL(disable_dma); @@ -207,36 +207,36 @@ EXPORT_SYMBOL(disable_dma); /* * Is the specified DMA channel active? */ -int dma_channel_active(dmach_t channel) +int dma_channel_active(unsigned int chan) { - return dma_chan[channel].active; + return dma_chan[chan].active; } EXPORT_SYMBOL(dma_channel_active); -void set_dma_page(dmach_t channel, char pagenr) +void set_dma_page(unsigned int chan, char pagenr) { - printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel); + printk(KERN_ERR "dma%d: trying to set_dma_page\n", chan); } EXPORT_SYMBOL(set_dma_page); -void set_dma_speed(dmach_t channel, int cycle_ns) +void set_dma_speed(unsigned int chan, int cycle_ns) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; int ret = 0; if (dma->d_ops->setspeed) - ret = dma->d_ops->setspeed(channel, dma, cycle_ns); + ret = dma->d_ops->setspeed(chan, dma, cycle_ns); dma->speed = ret; } EXPORT_SYMBOL(set_dma_speed); -int get_dma_residue(dmach_t channel) +int get_dma_residue(unsigned int chan) { - dma_t *dma = dma_chan + channel; + dma_t *dma = dma_chan + chan; int ret = 0; if (dma->d_ops->residue) - ret = dma->d_ops->residue(channel, dma); + ret = dma->d_ops->residue(chan, dma); return ret; } diff --git a/arch/arm/mach-footbridge/dma.c b/arch/arm/mach-footbridge/dma.c index b653e9cfa3f..e7b8a6adaf7 100644 --- a/arch/arm/mach-footbridge/dma.c +++ b/arch/arm/mach-footbridge/dma.c @@ -20,16 +20,16 @@ #include #if 0 -static int fb_dma_request(dmach_t channel, dma_t *dma) +static int fb_dma_request(unsigned int chan, dma_t *dma) { return -EINVAL; } -static void fb_dma_enable(dmach_t channel, dma_t *dma) +static void fb_dma_enable(unsigned int chan, dma_t *dma) { } -static void fb_dma_disable(dmach_t channel, dma_t *dma) +static void fb_dma_disable(unsigned int chan, dma_t *dma) { } diff --git a/arch/arm/mach-rpc/dma.c b/arch/arm/mach-rpc/dma.c index 7958a30f893..a86d3ed859a 100644 --- a/arch/arm/mach-rpc/dma.c +++ b/arch/arm/mach-rpc/dma.c @@ -125,18 +125,18 @@ static irqreturn_t iomd_dma_handle(int irq, void *dev_id) return IRQ_HANDLED; } -static int iomd_request_dma(dmach_t channel, dma_t *dma) +static int iomd_request_dma(unsigned int chan, dma_t *dma) { return request_irq(dma->dma_irq, iomd_dma_handle, IRQF_DISABLED, dma->device_id, dma); } -static void iomd_free_dma(dmach_t channel, dma_t *dma) +static void iomd_free_dma(unsigned int chan, dma_t *dma) { free_irq(dma->dma_irq, dma); } -static void iomd_enable_dma(dmach_t channel, dma_t *dma) +static void iomd_enable_dma(unsigned int chan, dma_t *dma) { unsigned long dma_base = dma->dma_base; unsigned int ctrl = TRANSFER_SIZE | DMA_CR_E; @@ -169,7 +169,7 @@ static void iomd_enable_dma(dmach_t channel, dma_t *dma) enable_irq(dma->dma_irq); } -static void iomd_disable_dma(dmach_t channel, dma_t *dma) +static void iomd_disable_dma(unsigned int chan, dma_t *dma) { unsigned long dma_base = dma->dma_base; unsigned long flags; @@ -181,7 +181,7 @@ static void iomd_disable_dma(dmach_t channel, dma_t *dma) local_irq_restore(flags); } -static int iomd_set_dma_speed(dmach_t channel, dma_t *dma, int cycle) +static int iomd_set_dma_speed(unsigned int chan, dma_t *dma, int cycle) { int tcr, speed; @@ -197,7 +197,7 @@ static int iomd_set_dma_speed(dmach_t channel, dma_t *dma, int cycle) tcr = iomd_readb(IOMD_DMATCR); speed &= 3; - switch (channel) { + switch (chan) { case DMA_0: tcr = (tcr & ~0x03) | speed; break; @@ -236,7 +236,7 @@ static struct fiq_handler fh = { .name = "floppydma" }; -static void floppy_enable_dma(dmach_t channel, dma_t *dma) +static void floppy_enable_dma(unsigned int chan, dma_t *dma) { void *fiqhandler_start; unsigned int fiqhandler_length; @@ -269,13 +269,13 @@ static void floppy_enable_dma(dmach_t channel, dma_t *dma) enable_fiq(dma->dma_irq); } -static void floppy_disable_dma(dmach_t channel, dma_t *dma) +static void floppy_disable_dma(unsigned int chan, dma_t *dma) { disable_fiq(dma->dma_irq); release_fiq(&fh); } -static int floppy_get_residue(dmach_t channel, dma_t *dma) +static int floppy_get_residue(unsigned int chan, dma_t *dma) { struct pt_regs regs; get_fiq_regs(®s); @@ -292,7 +292,7 @@ static struct dma_ops floppy_dma_ops = { /* * This is virtual DMA - we don't need anything here. */ -static void sound_enable_disable_dma(dmach_t channel, dma_t *dma) +static void sound_enable_disable_dma(unsigned int chan, dma_t *dma) { } -- cgit v1.2.3 From 3afb6e9c635f735c751148beddc195daec0e35ec Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 16:08:48 +0000 Subject: [ARM] dma: factor out code looking up the DMA channel This is a preparitory patch to allow us to easily change the way we add and lookup DMA channel structures. Signed-off-by: Russell King --- arch/arm/kernel/dma.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/arch/arm/kernel/dma.c b/arch/arm/kernel/dma.c index c31bf00e5ba..0ffea3fc22d 100644 --- a/arch/arm/kernel/dma.c +++ b/arch/arm/kernel/dma.c @@ -25,6 +25,16 @@ EXPORT_SYMBOL(dma_spin_lock); static dma_t dma_chan[MAX_DMA_CHANNELS]; +static inline dma_t *dma_channel(unsigned int chan) +{ + dma_t *dma = dma_chan + chan; + + if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) + return NULL; + + return dma; +} + /* * Request DMA channel * @@ -32,10 +42,10 @@ static dma_t dma_chan[MAX_DMA_CHANNELS]; */ int request_dma(unsigned int chan, const char *device_id) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); int ret; - if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) + if (!dma) goto bad_dma; if (xchg(&dma->lock, 1) != 0) @@ -70,9 +80,9 @@ EXPORT_SYMBOL(request_dma); */ void free_dma(unsigned int chan) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); - if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) + if (!dma) goto bad_dma; if (dma->active) { @@ -99,7 +109,7 @@ EXPORT_SYMBOL(free_dma); */ void set_dma_sg (unsigned int chan, struct scatterlist *sg, int nr_sg) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); if (dma->active) printk(KERN_ERR "dma%d: altering DMA SG while " @@ -117,7 +127,7 @@ EXPORT_SYMBOL(set_dma_sg); */ void __set_dma_addr (unsigned int chan, void *addr) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); if (dma->active) printk(KERN_ERR "dma%d: altering DMA address while " @@ -135,7 +145,7 @@ EXPORT_SYMBOL(__set_dma_addr); */ void set_dma_count (unsigned int chan, unsigned long count) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); if (dma->active) printk(KERN_ERR "dma%d: altering DMA count while " @@ -151,7 +161,7 @@ EXPORT_SYMBOL(set_dma_count); */ void set_dma_mode (unsigned int chan, dmamode_t mode) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); if (dma->active) printk(KERN_ERR "dma%d: altering DMA mode while " @@ -166,7 +176,7 @@ EXPORT_SYMBOL(set_dma_mode); */ void enable_dma (unsigned int chan) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); if (!dma->lock) goto free_dma; @@ -187,7 +197,7 @@ EXPORT_SYMBOL(enable_dma); */ void disable_dma (unsigned int chan) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); if (!dma->lock) goto free_dma; @@ -209,7 +219,8 @@ EXPORT_SYMBOL(disable_dma); */ int dma_channel_active(unsigned int chan) { - return dma_chan[chan].active; + dma_t *dma = dma_channel(chan); + return dma->active; } EXPORT_SYMBOL(dma_channel_active); @@ -221,7 +232,7 @@ EXPORT_SYMBOL(set_dma_page); void set_dma_speed(unsigned int chan, int cycle_ns) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); int ret = 0; if (dma->d_ops->setspeed) @@ -232,7 +243,7 @@ EXPORT_SYMBOL(set_dma_speed); int get_dma_residue(unsigned int chan) { - dma_t *dma = dma_chan + chan; + dma_t *dma = dma_channel(chan); int ret = 0; if (dma->d_ops->residue) @@ -247,5 +258,4 @@ static int __init init_dma(void) arch_dma_init(dma_chan); return 0; } - core_initcall(init_dma); -- cgit v1.2.3 From 2f757f2ab7411cf0e2779012d8cda0cbf2f80d26 Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 16:33:30 +0000 Subject: [ARM] dma: rejig DMA initialization Rather than having the central DMA multiplexer call the architecture specific DMA initialization function, have each architecture DMA initialization function use core_initcall(), and register each DMA channel separately with the multiplexer. This removes the array of dma structures in the central multiplexer, replacing it with an array of pointers instead; this is more flexible since it allows the drivers to wrap the DMA structure (eventually allowing us to transition non-ISA DMA drivers away.) Signed-off-by: Russell King --- arch/arm/include/asm/mach/dma.h | 12 +++++--- arch/arm/kernel/dma-isa.c | 18 +++++++++-- arch/arm/kernel/dma.c | 25 +++++++-------- arch/arm/mach-footbridge/dma.c | 6 ++-- arch/arm/mach-rpc/dma.c | 68 +++++++++++++++++++++++++++-------------- arch/arm/mach-shark/dma.c | 6 ++-- 6 files changed, 88 insertions(+), 47 deletions(-) diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h index 281ae7e40a9..38a3693f125 100644 --- a/arch/arm/include/asm/mach/dma.h +++ b/arch/arm/include/asm/mach/dma.h @@ -48,10 +48,12 @@ struct dma_struct { struct dma_ops *d_ops; }; -/* Prototype: void arch_dma_init(dma) - * Purpose : Initialise architecture specific DMA - * Params : dma - pointer to array of DMA structures +/* + * isa_dma_add - add an ISA-style DMA channel */ -extern void arch_dma_init(dma_t *dma); +extern int isa_dma_add(unsigned int, dma_t *dma); -extern void isa_init_dma(dma_t *dma); +/* + * Add the ISA DMA controller. Always takes channels 0-7. + */ +extern void isa_init_dma(void); diff --git a/arch/arm/kernel/dma-isa.c b/arch/arm/kernel/dma-isa.c index 29eca48925d..da02a7ff341 100644 --- a/arch/arm/kernel/dma-isa.c +++ b/arch/arm/kernel/dma-isa.c @@ -160,7 +160,12 @@ static struct resource dma_resources[] = { { .end = 0x048f } }; -void __init isa_init_dma(dma_t *dma) +static dma_t isa_dma[8]; + +/* + * ISA DMA always starts at channel 0 + */ +void __init isa_init_dma(void) { /* * Try to autodetect presence of an ISA DMA controller. @@ -178,10 +183,10 @@ void __init isa_init_dma(dma_t *dma) outb(0xaa, 0x00); if (inb(0) == 0x55 && inb(0) == 0xaa) { - int chan, i; + unsigned int chan, i; for (chan = 0; chan < 8; chan++) { - dma[chan].d_ops = &isa_dma_ops; + isa_dma[chan].d_ops = &isa_dma_ops; isa_disable_dma(chan, NULL); } @@ -217,5 +222,12 @@ void __init isa_init_dma(dma_t *dma) for (i = 0; i < ARRAY_SIZE(dma_resources); i++) request_resource(&ioport_resource, dma_resources + i); + + for (chan = 0; chan < 8; chan++) { + int ret = isa_dma_add(chan, &isa_dma[chan]); + if (ret) + printk(KERN_ERR "ISADMA%u: unable to register: %d\n", + chan, ret); + } } } diff --git a/arch/arm/kernel/dma.c b/arch/arm/kernel/dma.c index 0ffea3fc22d..aab24f03ea1 100644 --- a/arch/arm/kernel/dma.c +++ b/arch/arm/kernel/dma.c @@ -23,16 +23,24 @@ DEFINE_SPINLOCK(dma_spin_lock); EXPORT_SYMBOL(dma_spin_lock); -static dma_t dma_chan[MAX_DMA_CHANNELS]; +static dma_t *dma_chan[MAX_DMA_CHANNELS]; static inline dma_t *dma_channel(unsigned int chan) { - dma_t *dma = dma_chan + chan; - - if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) + if (chan >= MAX_DMA_CHANNELS) return NULL; - return dma; + return dma_chan[chan]; +} + +int __init isa_dma_add(unsigned int chan, dma_t *dma) +{ + if (!dma->d_ops) + return -EINVAL; + if (dma_chan[chan]) + return -EBUSY; + dma_chan[chan] = dma; + return 0; } /* @@ -252,10 +260,3 @@ int get_dma_residue(unsigned int chan) return ret; } EXPORT_SYMBOL(get_dma_residue); - -static int __init init_dma(void) -{ - arch_dma_init(dma_chan); - return 0; -} -core_initcall(init_dma); diff --git a/arch/arm/mach-footbridge/dma.c b/arch/arm/mach-footbridge/dma.c index e7b8a6adaf7..fdd94b182d7 100644 --- a/arch/arm/mach-footbridge/dma.c +++ b/arch/arm/mach-footbridge/dma.c @@ -41,7 +41,7 @@ static struct dma_ops fb_dma_ops = { }; #endif -void __init arch_dma_init(dma_t *dma) +static int __init fb_dma_init(void) { #if 0 dma[_DC21285_DMA(0)].d_ops = &fb_dma_ops; @@ -49,6 +49,8 @@ void __init arch_dma_init(dma_t *dma) #endif #ifdef CONFIG_ISA_DMA if (footbridge_cfn_mode()) - isa_init_dma(dma + _ISA_DMA(0)); + isa_init_dma(); #endif + return 0; } +core_initcall(fb_dma_init); diff --git a/arch/arm/mach-rpc/dma.c b/arch/arm/mach-rpc/dma.c index a86d3ed859a..efcf6718d1d 100644 --- a/arch/arm/mach-rpc/dma.c +++ b/arch/arm/mach-rpc/dma.c @@ -302,8 +302,22 @@ static struct dma_ops sound_dma_ops = { .disable = sound_enable_disable_dma, }; -void __init arch_dma_init(dma_t *dma) +static dma_t iomd_dma[6]; + +static dma_t floppy_dma = { + .dma_irq = FIQ_FLOPPYDATA, + .d_ops = &floppy_dma_ops, +}; + +static dma_t sound_dma = { + .d_ops = &sound_dma_ops, +}; + +static int __init rpc_dma_init(void) { + unsigned int i; + int ret; + iomd_writeb(0, IOMD_IO0CR); iomd_writeb(0, IOMD_IO1CR); iomd_writeb(0, IOMD_IO2CR); @@ -311,31 +325,39 @@ void __init arch_dma_init(dma_t *dma) iomd_writeb(0xa0, IOMD_DMATCR); - dma[DMA_0].dma_base = IOMD_IO0CURA; - dma[DMA_0].dma_irq = IRQ_DMA0; - dma[DMA_0].d_ops = &iomd_dma_ops; - dma[DMA_1].dma_base = IOMD_IO1CURA; - dma[DMA_1].dma_irq = IRQ_DMA1; - dma[DMA_1].d_ops = &iomd_dma_ops; - dma[DMA_2].dma_base = IOMD_IO2CURA; - dma[DMA_2].dma_irq = IRQ_DMA2; - dma[DMA_2].d_ops = &iomd_dma_ops; - dma[DMA_3].dma_base = IOMD_IO3CURA; - dma[DMA_3].dma_irq = IRQ_DMA3; - dma[DMA_3].d_ops = &iomd_dma_ops; - dma[DMA_S0].dma_base = IOMD_SD0CURA; - dma[DMA_S0].dma_irq = IRQ_DMAS0; - dma[DMA_S0].d_ops = &iomd_dma_ops; - dma[DMA_S1].dma_base = IOMD_SD1CURA; - dma[DMA_S1].dma_irq = IRQ_DMAS1; - dma[DMA_S1].d_ops = &iomd_dma_ops; - dma[DMA_VIRTUAL_FLOPPY].dma_irq = FIQ_FLOPPYDATA; - dma[DMA_VIRTUAL_FLOPPY].d_ops = &floppy_dma_ops; - dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops; - /* * Setup DMA channels 2,3 to be for podules * and channels 0,1 for internal devices */ iomd_writeb(DMA_EXT_IO3|DMA_EXT_IO2, IOMD_DMAEXT); + + iomd_dma[DMA_0].dma_base = IOMD_IO0CURA; + iomd_dma[DMA_0].dma_irq = IRQ_DMA0; + iomd_dma[DMA_1].dma_base = IOMD_IO1CURA; + iomd_dma[DMA_1].dma_irq = IRQ_DMA1; + iomd_dma[DMA_2].dma_base = IOMD_IO2CURA; + iomd_dma[DMA_2].dma_irq = IRQ_DMA2; + iomd_dma[DMA_3].dma_base = IOMD_IO3CURA; + iomd_dma[DMA_3].dma_irq = IRQ_DMA3; + iomd_dma[DMA_S0].dma_base = IOMD_SD0CURA; + iomd_dma[DMA_S0].dma_irq = IRQ_DMAS0; + iomd_dma[DMA_S1].dma_base = IOMD_SD1CURA; + iomd_dma[DMA_S1].dma_irq = IRQ_DMAS1; + + for (i = DMA_0; i <= DMA_S1; i++) { + iomd_dma[i].d_ops = &iomd_dma_ops; + + ret = isa_dma_add(i, &iomd_dma[i]); + if (ret) + printk("IOMDDMA%u: unable to register: %d\n", i, ret); + } + + ret = isa_dma_add(DMA_VIRTUAL_FLOPPY, &floppy_dma); + if (ret) + printk("IOMDFLOPPY: unable to register: %d\n", ret); + ret = isa_dma_add(DMA_VIRTUAL_SOUND, &sound_dma); + if (ret) + printk("IOMDSOUND: unable to register: %d\n", ret); + return 0; } +core_initcall(rpc_dma_init); diff --git a/arch/arm/mach-shark/dma.c b/arch/arm/mach-shark/dma.c index 6774b8d5d13..10b5b8b3272 100644 --- a/arch/arm/mach-shark/dma.c +++ b/arch/arm/mach-shark/dma.c @@ -13,9 +13,11 @@ #include #include -void __init arch_dma_init(dma_t *dma) +static int __init shark_dma_init(void) { #ifdef CONFIG_ISA_DMA - isa_init_dma(dma); + isa_init_dma(); #endif + return 0; } +core_initcall(shark_dma_init); -- cgit v1.2.3 From ad9dd94c384f7ee37b798a9349b8c42da8fa99ab Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 17:35:48 +0000 Subject: [ARM] dma: move RiscPC specific DMA data out of dma_struct Separate the RiscPC specific (IOMD and floppy FIQ) data out of the core DMA structure by making the IOMD and floppy DMA supersets. Signed-off-by: Russell King --- arch/arm/include/asm/mach/dma.h | 18 +++-- arch/arm/mach-rpc/dma.c | 146 +++++++++++++++++++++------------------- 2 files changed, 91 insertions(+), 73 deletions(-) diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h index 38a3693f125..4326738ff36 100644 --- a/arch/arm/include/asm/mach/dma.h +++ b/arch/arm/include/asm/mach/dma.h @@ -40,14 +40,22 @@ struct dma_struct { unsigned int lock; /* Device is allocated */ const char *device_id; /* Device name */ - unsigned int dma_base; /* Controller base address */ - int dma_irq; /* Controller IRQ */ - struct scatterlist cur_sg; /* Current controller buffer */ - unsigned int state; - struct dma_ops *d_ops; }; +struct floppy_dma { + struct dma_struct dma; + unsigned int fiq; +}; + +struct iomd_dma { + struct dma_struct dma; + unsigned int state; + unsigned long base; /* Controller base address */ + int irq; /* Controller IRQ */ + struct scatterlist cur_sg; /* Current controller buffer */ +}; + /* * isa_dma_add - add an ISA-style DMA channel */ diff --git a/arch/arm/mach-rpc/dma.c b/arch/arm/mach-rpc/dma.c index efcf6718d1d..0163592b2af 100644 --- a/arch/arm/mach-rpc/dma.c +++ b/arch/arm/mach-rpc/dma.c @@ -44,15 +44,15 @@ typedef enum { #define CR (IOMD_IO0CR - IOMD_IO0CURA) #define ST (IOMD_IO0ST - IOMD_IO0CURA) -static void iomd_get_next_sg(struct scatterlist *sg, dma_t *dma) +static void iomd_get_next_sg(struct scatterlist *sg, struct iomd_dma *idma) { unsigned long end, offset, flags = 0; - if (dma->sg) { - sg->dma_address = dma->sg->dma_address; + if (idma->dma.sg) { + sg->dma_address = idma->dma.sg->dma_address; offset = sg->dma_address & ~PAGE_MASK; - end = offset + dma->sg->length; + end = offset + idma->dma.sg->length; if (end > PAGE_SIZE) end = PAGE_SIZE; @@ -62,15 +62,15 @@ static void iomd_get_next_sg(struct scatterlist *sg, dma_t *dma) sg->length = end - TRANSFER_SIZE; - dma->sg->length -= end - offset; - dma->sg->dma_address += end - offset; + idma->dma.sg->length -= end - offset; + idma->dma.sg->dma_address += end - offset; - if (dma->sg->length == 0) { - if (dma->sgcount > 1) { - dma->sg++; - dma->sgcount--; + if (idma->dma.sg->length == 0) { + if (idma->dma.sgcount > 1) { + idma->dma.sg++; + idma->dma.sgcount--; } else { - dma->sg = NULL; + idma->dma.sg = NULL; flags |= DMA_END_S; } } @@ -85,8 +85,8 @@ static void iomd_get_next_sg(struct scatterlist *sg, dma_t *dma) static irqreturn_t iomd_dma_handle(int irq, void *dev_id) { - dma_t *dma = (dma_t *)dev_id; - unsigned long base = dma->dma_base; + struct iomd_dma *idma = dev_id; + unsigned long base = idma->base; do { unsigned int status; @@ -95,31 +95,31 @@ static irqreturn_t iomd_dma_handle(int irq, void *dev_id) if (!(status & DMA_ST_INT)) return IRQ_HANDLED; - if ((dma->state ^ status) & DMA_ST_AB) - iomd_get_next_sg(&dma->cur_sg, dma); + if ((idma->state ^ status) & DMA_ST_AB) + iomd_get_next_sg(&idma->cur_sg, idma); switch (status & (DMA_ST_OFL | DMA_ST_AB)) { case DMA_ST_OFL: /* OIA */ case DMA_ST_AB: /* .IB */ - iomd_writel(dma->cur_sg.dma_address, base + CURA); - iomd_writel(dma->cur_sg.length, base + ENDA); - dma->state = DMA_ST_AB; + iomd_writel(idma->cur_sg.dma_address, base + CURA); + iomd_writel(idma->cur_sg.length, base + ENDA); + idma->state = DMA_ST_AB; break; case DMA_ST_OFL | DMA_ST_AB: /* OIB */ case 0: /* .IA */ - iomd_writel(dma->cur_sg.dma_address, base + CURB); - iomd_writel(dma->cur_sg.length, base + ENDB); - dma->state = 0; + iomd_writel(idma->cur_sg.dma_address, base + CURB); + iomd_writel(idma->cur_sg.length, base + ENDB); + idma->state = 0; break; } if (status & DMA_ST_OFL && - dma->cur_sg.length == (DMA_END_S|DMA_END_L)) + idma->cur_sg.length == (DMA_END_S|DMA_END_L)) break; } while (1); - dma->state = ~DMA_ST_AB; + idma->state = ~DMA_ST_AB; disable_irq(irq); return IRQ_HANDLED; @@ -127,56 +127,62 @@ static irqreturn_t iomd_dma_handle(int irq, void *dev_id) static int iomd_request_dma(unsigned int chan, dma_t *dma) { - return request_irq(dma->dma_irq, iomd_dma_handle, - IRQF_DISABLED, dma->device_id, dma); + struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); + + return request_irq(idma->irq, iomd_dma_handle, + IRQF_DISABLED, idma->dma.device_id, idma); } static void iomd_free_dma(unsigned int chan, dma_t *dma) { - free_irq(dma->dma_irq, dma); + struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); + + free_irq(idma->irq, idma); } static void iomd_enable_dma(unsigned int chan, dma_t *dma) { - unsigned long dma_base = dma->dma_base; + struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); + unsigned long dma_base = idma->base; unsigned int ctrl = TRANSFER_SIZE | DMA_CR_E; - if (dma->invalid) { - dma->invalid = 0; + if (idma->dma.invalid) { + idma->dma.invalid = 0; /* * Cope with ISA-style drivers which expect cache * coherence. */ - if (!dma->sg) { - dma->sg = &dma->buf; - dma->sgcount = 1; - dma->buf.length = dma->count; - dma->buf.dma_address = dma_map_single(NULL, - dma->addr, dma->count, - dma->dma_mode == DMA_MODE_READ ? + if (!idma->dma.sg) { + idma->dma.sg = &idma->dma.buf; + idma->dma.sgcount = 1; + idma->dma.buf.length = idma->dma.count; + idma->dma.buf.dma_address = dma_map_single(NULL, + idma->dma.addr, idma->dma.count, + idma->dma.dma_mode == DMA_MODE_READ ? DMA_FROM_DEVICE : DMA_TO_DEVICE); } iomd_writeb(DMA_CR_C, dma_base + CR); - dma->state = DMA_ST_AB; + idma->state = DMA_ST_AB; } - - if (dma->dma_mode == DMA_MODE_READ) + + if (idma->dma.dma_mode == DMA_MODE_READ) ctrl |= DMA_CR_D; iomd_writeb(ctrl, dma_base + CR); - enable_irq(dma->dma_irq); + enable_irq(idma->irq); } static void iomd_disable_dma(unsigned int chan, dma_t *dma) { - unsigned long dma_base = dma->dma_base; + struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); + unsigned long dma_base = idma->base; unsigned long flags; local_irq_save(flags); - if (dma->state != ~DMA_ST_AB) - disable_irq(dma->dma_irq); + if (idma->state != ~DMA_ST_AB) + disable_irq(idma->irq); iomd_writeb(0, dma_base + CR); local_irq_restore(flags); } @@ -238,14 +244,15 @@ static struct fiq_handler fh = { static void floppy_enable_dma(unsigned int chan, dma_t *dma) { + struct floppy_dma *fdma = container_of(dma, struct floppy_dma, dma); void *fiqhandler_start; unsigned int fiqhandler_length; struct pt_regs regs; - if (dma->sg) + if (fdma->dma.sg) BUG(); - if (dma->dma_mode == DMA_MODE_READ) { + if (fdma->dma.dma_mode == DMA_MODE_READ) { extern unsigned char floppy_fiqin_start, floppy_fiqin_end; fiqhandler_start = &floppy_fiqin_start; fiqhandler_length = &floppy_fiqin_end - &floppy_fiqin_start; @@ -255,8 +262,8 @@ static void floppy_enable_dma(unsigned int chan, dma_t *dma) fiqhandler_length = &floppy_fiqout_end - &floppy_fiqout_start; } - regs.ARM_r9 = dma->count; - regs.ARM_r10 = (unsigned long)dma->addr; + regs.ARM_r9 = fdma->dma.count; + regs.ARM_r10 = (unsigned long)fdma->dma.addr; regs.ARM_fp = (unsigned long)FLOPPYDMA_BASE; if (claim_fiq(&fh)) { @@ -266,12 +273,13 @@ static void floppy_enable_dma(unsigned int chan, dma_t *dma) set_fiq_handler(fiqhandler_start, fiqhandler_length); set_fiq_regs(®s); - enable_fiq(dma->dma_irq); + enable_fiq(fdma->fiq); } static void floppy_disable_dma(unsigned int chan, dma_t *dma) { - disable_fiq(dma->dma_irq); + struct floppy_dma *fdma = container_of(dma, struct floppy_dma, dma); + disable_fiq(fdma->fiq); release_fiq(&fh); } @@ -302,11 +310,13 @@ static struct dma_ops sound_dma_ops = { .disable = sound_enable_disable_dma, }; -static dma_t iomd_dma[6]; +static struct iomd_dma iomd_dma[6]; -static dma_t floppy_dma = { - .dma_irq = FIQ_FLOPPYDATA, - .d_ops = &floppy_dma_ops, +static struct floppy_dma floppy_dma = { + .dma = { + .d_ops = &floppy_dma_ops, + }, + .fiq = FIQ_FLOPPYDATA, }; static dma_t sound_dma = { @@ -331,28 +341,28 @@ static int __init rpc_dma_init(void) */ iomd_writeb(DMA_EXT_IO3|DMA_EXT_IO2, IOMD_DMAEXT); - iomd_dma[DMA_0].dma_base = IOMD_IO0CURA; - iomd_dma[DMA_0].dma_irq = IRQ_DMA0; - iomd_dma[DMA_1].dma_base = IOMD_IO1CURA; - iomd_dma[DMA_1].dma_irq = IRQ_DMA1; - iomd_dma[DMA_2].dma_base = IOMD_IO2CURA; - iomd_dma[DMA_2].dma_irq = IRQ_DMA2; - iomd_dma[DMA_3].dma_base = IOMD_IO3CURA; - iomd_dma[DMA_3].dma_irq = IRQ_DMA3; - iomd_dma[DMA_S0].dma_base = IOMD_SD0CURA; - iomd_dma[DMA_S0].dma_irq = IRQ_DMAS0; - iomd_dma[DMA_S1].dma_base = IOMD_SD1CURA; - iomd_dma[DMA_S1].dma_irq = IRQ_DMAS1; + iomd_dma[DMA_0].base = IOMD_IO0CURA; + iomd_dma[DMA_0].irq = IRQ_DMA0; + iomd_dma[DMA_1].base = IOMD_IO1CURA; + iomd_dma[DMA_1].irq = IRQ_DMA1; + iomd_dma[DMA_2].base = IOMD_IO2CURA; + iomd_dma[DMA_2].irq = IRQ_DMA2; + iomd_dma[DMA_3].base = IOMD_IO3CURA; + iomd_dma[DMA_3].irq = IRQ_DMA3; + iomd_dma[DMA_S0].base = IOMD_SD0CURA; + iomd_dma[DMA_S0].irq = IRQ_DMAS0; + iomd_dma[DMA_S1].base = IOMD_SD1CURA; + iomd_dma[DMA_S1].irq = IRQ_DMAS1; for (i = DMA_0; i <= DMA_S1; i++) { - iomd_dma[i].d_ops = &iomd_dma_ops; + iomd_dma[i].dma.d_ops = &iomd_dma_ops; - ret = isa_dma_add(i, &iomd_dma[i]); + ret = isa_dma_add(i, &iomd_dma[i].dma); if (ret) printk("IOMDDMA%u: unable to register: %d\n", i, ret); } - ret = isa_dma_add(DMA_VIRTUAL_FLOPPY, &floppy_dma); + ret = isa_dma_add(DMA_VIRTUAL_FLOPPY, &floppy_dma.dma); if (ret) printk("IOMDFLOPPY: unable to register: %d\n", ret); ret = isa_dma_add(DMA_VIRTUAL_SOUND, &sound_dma); -- cgit v1.2.3 From 8c56afcbea22e472d3bfa8ddf06f23cd6bc56826 Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 11 Dec 2008 14:50:39 +0000 Subject: [ARM] dma: constify dma controller name and dma ops Signed-off-by: Russell King --- arch/arm/include/asm/mach/dma.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h index 4326738ff36..3122adae80b 100644 --- a/arch/arm/include/asm/mach/dma.h +++ b/arch/arm/include/asm/mach/dma.h @@ -21,7 +21,7 @@ struct dma_ops { void (*disable)(unsigned int, dma_t *); /* mandatory */ int (*residue)(unsigned int, dma_t *); /* optional */ int (*setspeed)(unsigned int, dma_t *, int); /* optional */ - char *type; + const char *type; }; struct dma_struct { @@ -40,7 +40,7 @@ struct dma_struct { unsigned int lock; /* Device is allocated */ const char *device_id; /* Device name */ - struct dma_ops *d_ops; + const struct dma_ops *d_ops; }; struct floppy_dma { -- cgit v1.2.3 From d667522fdf637ef1b425518afe11aedba80364b2 Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 17:50:25 +0000 Subject: [ARM] dma: ensure that the single entry sg is properly initialized Signed-off-by: Russell King --- arch/arm/kernel/dma.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/kernel/dma.c b/arch/arm/kernel/dma.c index aab24f03ea1..e7828fcd954 100644 --- a/arch/arm/kernel/dma.c +++ b/arch/arm/kernel/dma.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -37,6 +38,9 @@ int __init isa_dma_add(unsigned int chan, dma_t *dma) { if (!dma->d_ops) return -EINVAL; + + sg_init_table(&dma->buf, 1); + if (dma_chan[chan]) return -EBUSY; dma_chan[chan] = dma; -- cgit v1.2.3 From 9e28d7e8c5422a47db886c4104221ea165595de0 Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 19:03:58 +0000 Subject: [ARM] dma: convert IOMD DMA to use sg_next() ... rather than incrementing the sg pointer. Signed-off-by: Russell King --- arch/arm/mach-rpc/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-rpc/dma.c b/arch/arm/mach-rpc/dma.c index 0163592b2af..a5987bbed60 100644 --- a/arch/arm/mach-rpc/dma.c +++ b/arch/arm/mach-rpc/dma.c @@ -67,7 +67,7 @@ static void iomd_get_next_sg(struct scatterlist *sg, struct iomd_dma *idma) if (idma->dma.sg->length == 0) { if (idma->dma.sgcount > 1) { - idma->dma.sg++; + idma->dma.sg = sg_next(idma->dma.sg); idma->dma.sgcount--; } else { idma->dma.sg = NULL; -- cgit v1.2.3 From f6718653361e8f8a6aac9946822aa2090edf4f37 Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 8 Dec 2008 19:25:28 +0000 Subject: [ARM] dma: pata_icside's contiguous sg array is now redundant Now that the IOMD DMA code walks the scatterlist using sg_next, converting the sg list into a contiguous list is no longer required. Signed-off-by: Russell King --- drivers/ata/pata_icside.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c index cf9e9848f8b..63121f45ba2 100644 --- a/drivers/ata/pata_icside.c +++ b/drivers/ata/pata_icside.c @@ -57,7 +57,6 @@ struct pata_icside_state { u8 disabled; unsigned int speed[ATA_MAX_DEVICES]; } port[2]; - struct scatterlist sg[PATA_ICSIDE_MAX_SG]; }; struct pata_icside_info { @@ -222,9 +221,7 @@ static void pata_icside_bmdma_setup(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; struct pata_icside_state *state = ap->host->private_data; - struct scatterlist *sg, *rsg = state->sg; unsigned int write = qc->tf.flags & ATA_TFLAG_WRITE; - unsigned int si; /* * We are simplex; BUG if we try to fiddle with DMA @@ -232,21 +229,13 @@ static void pata_icside_bmdma_setup(struct ata_queued_cmd *qc) */ BUG_ON(dma_channel_active(state->dma)); - /* - * Copy ATAs scattered sg list into a contiguous array of sg - */ - for_each_sg(qc->sg, sg, qc->n_elem, si) { - memcpy(rsg, sg, sizeof(*sg)); - rsg++; - } - /* * Route the DMA signals to the correct interface */ writeb(state->port[ap->port_no].port_sel, state->ioc_base); set_dma_speed(state->dma, state->port[ap->port_no].speed[qc->dev->devno]); - set_dma_sg(state->dma, state->sg, rsg - state->sg); + set_dma_sg(state->dma, qc->sg, qc->n_elem); set_dma_mode(state->dma, write ? DMA_MODE_WRITE : DMA_MODE_READ); /* issue r/w command */ -- cgit v1.2.3 From 5369bea7d7db1d95f63907f3470e23d32930be98 Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 11 Dec 2008 16:37:06 +0000 Subject: [ARM] dma: Use sensible DMA parameters for Acorn drivers The hardware supports transfers up to a page boundary per buffer. Currently, we work around that in the DMA code by splitting each buffer up as we run through the scatterlist. Avoid this by telling the block layers about the hardware restriction. Eventually, this will allow us to phase out the splitting code, but not until the old IDE layer allows us to control the value it gives to blk_queue_segment_boundary(). Signed-off-by: Russell King --- arch/arm/mach-rpc/include/mach/isa-dma.h | 2 ++ drivers/ata/pata_icside.c | 6 ++---- drivers/scsi/arm/cumana_2.c | 3 ++- drivers/scsi/arm/eesox.c | 3 ++- drivers/scsi/arm/powertec.c | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/arm/mach-rpc/include/mach/isa-dma.h b/arch/arm/mach-rpc/include/mach/isa-dma.h index bad72054858..67bfc6719c3 100644 --- a/arch/arm/mach-rpc/include/mach/isa-dma.h +++ b/arch/arm/mach-rpc/include/mach/isa-dma.h @@ -23,5 +23,7 @@ #define DMA_FLOPPY DMA_VIRTUAL_FLOPPY +#define IOMD_DMA_BOUNDARY (PAGE_SIZE - 1) + #endif /* _ASM_ARCH_DMA_H */ diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c index 63121f45ba2..d7bc925c524 100644 --- a/drivers/ata/pata_icside.c +++ b/drivers/ata/pata_icside.c @@ -45,8 +45,6 @@ static const struct portinfo pata_icside_portinfo_v6_2 = { .stepping = 6, }; -#define PATA_ICSIDE_MAX_SG 128 - struct pata_icside_state { void __iomem *irq_port; void __iomem *ioc_base; @@ -295,8 +293,8 @@ static int icside_dma_init(struct pata_icside_info *info) static struct scsi_host_template pata_icside_sht = { ATA_BASE_SHT(DRV_NAME), - .sg_tablesize = PATA_ICSIDE_MAX_SG, - .dma_boundary = ~0, /* no dma boundaries */ + .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS, + .dma_boundary = IOMD_DMA_BOUNDARY, }; static void pata_icside_postreset(struct ata_link *link, unsigned int *classes) diff --git a/drivers/scsi/arm/cumana_2.c b/drivers/scsi/arm/cumana_2.c index 68a64123af8..8ee01b90733 100644 --- a/drivers/scsi/arm/cumana_2.c +++ b/drivers/scsi/arm/cumana_2.c @@ -390,7 +390,8 @@ static struct scsi_host_template cumanascsi2_template = { .eh_abort_handler = fas216_eh_abort, .can_queue = 1, .this_id = 7, - .sg_tablesize = SG_ALL, + .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS, + .dma_boundary = IOMD_DMA_BOUNDARY, .cmd_per_lun = 1, .use_clustering = DISABLE_CLUSTERING, .proc_name = "cumanascsi2", diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c index bb2477b3fb0..d8435132f46 100644 --- a/drivers/scsi/arm/eesox.c +++ b/drivers/scsi/arm/eesox.c @@ -508,7 +508,8 @@ static struct scsi_host_template eesox_template = { .eh_abort_handler = fas216_eh_abort, .can_queue = 1, .this_id = 7, - .sg_tablesize = SG_ALL, + .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS, + .dma_boundary = IOMD_DMA_BOUNDARY, .cmd_per_lun = 1, .use_clustering = DISABLE_CLUSTERING, .proc_name = "eesox", diff --git a/drivers/scsi/arm/powertec.c b/drivers/scsi/arm/powertec.c index d9a546d1917..e2297b4c1b9 100644 --- a/drivers/scsi/arm/powertec.c +++ b/drivers/scsi/arm/powertec.c @@ -302,7 +302,8 @@ static struct scsi_host_template powertecscsi_template = { .can_queue = 8, .this_id = 7, - .sg_tablesize = SG_ALL, + .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS, + .dma_boundary = IOMD_DMA_BOUNDARY, .cmd_per_lun = 2, .use_clustering = ENABLE_CLUSTERING, .proc_name = "powertec", -- cgit v1.2.3 From bc6447b8e4fdb3306ee6381df9650a1a8aa57c5b Mon Sep 17 00:00:00 2001 From: Russell King Date: Fri, 2 Jan 2009 12:18:53 +0000 Subject: [ARM] dma: make DMA_MODE_xxx reflect ISA DMA settings Signed-off-by: Russell King --- arch/arm/include/asm/dma.h | 13 ++++++++----- arch/arm/kernel/dma-isa.c | 13 +------------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/arm/include/asm/dma.h b/arch/arm/include/asm/dma.h index c5557a650d1..59f59c6c79f 100644 --- a/arch/arm/include/asm/dma.h +++ b/arch/arm/include/asm/dma.h @@ -26,12 +26,15 @@ */ typedef unsigned int dmamode_t; -#define DMA_MODE_MASK 3 +/* + * The DMA modes reflect the settings for the ISA DMA controller + */ +#define DMA_MODE_MASK 0xcc -#define DMA_MODE_READ 0 -#define DMA_MODE_WRITE 1 -#define DMA_MODE_CASCADE 2 -#define DMA_AUTOINIT 4 +#define DMA_MODE_READ 0x44 +#define DMA_MODE_WRITE 0x48 +#define DMA_MODE_CASCADE 0xc0 +#define DMA_AUTOINIT 0x10 extern spinlock_t dma_spin_lock; diff --git a/arch/arm/kernel/dma-isa.c b/arch/arm/kernel/dma-isa.c index da02a7ff341..0e88e46fc73 100644 --- a/arch/arm/kernel/dma-isa.c +++ b/arch/arm/kernel/dma-isa.c @@ -24,11 +24,6 @@ #include #include -#define ISA_DMA_MODE_READ 0x44 -#define ISA_DMA_MODE_WRITE 0x48 -#define ISA_DMA_MODE_CASCADE 0xc0 -#define ISA_DMA_AUTOINIT 0x10 - #define ISA_DMA_MASK 0 #define ISA_DMA_MODE 1 #define ISA_DMA_CLRFF 2 @@ -67,20 +62,17 @@ static void isa_enable_dma(unsigned int chan, dma_t *dma) unsigned int mode; enum dma_data_direction direction; - mode = chan & 3; + mode = (chan & 3) | dma->dma_mode; switch (dma->dma_mode & DMA_MODE_MASK) { case DMA_MODE_READ: - mode |= ISA_DMA_MODE_READ; direction = DMA_FROM_DEVICE; break; case DMA_MODE_WRITE: - mode |= ISA_DMA_MODE_WRITE; direction = DMA_TO_DEVICE; break; case DMA_MODE_CASCADE: - mode |= ISA_DMA_MODE_CASCADE; direction = DMA_BIDIRECTIONAL; break; @@ -121,9 +113,6 @@ static void isa_enable_dma(unsigned int chan, dma_t *dma) outb(length, isa_dma_port[chan][ISA_DMA_COUNT]); outb(length >> 8, isa_dma_port[chan][ISA_DMA_COUNT]); - if (dma->dma_mode & DMA_AUTOINIT) - mode |= ISA_DMA_AUTOINIT; - outb(mode, isa_dma_port[chan][ISA_DMA_MODE]); dma->invalid = 0; } -- cgit v1.2.3 From 4e57ea9a2e8e807e20f64d5b53fbee2c7c9e87ae Mon Sep 17 00:00:00 2001 From: Russell King Date: Fri, 2 Jan 2009 12:34:31 +0000 Subject: [ARM] dma: remove usage of dmamode_t from MXC platform support Signed-off-by: Russell King --- arch/arm/plat-mxc/dma-mx1-mx2.c | 6 +++--- arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm/plat-mxc/dma-mx1-mx2.c b/arch/arm/plat-mxc/dma-mx1-mx2.c index 21427434444..92bc4f6bd01 100644 --- a/arch/arm/plat-mxc/dma-mx1-mx2.c +++ b/arch/arm/plat-mxc/dma-mx1-mx2.c @@ -114,7 +114,7 @@ struct imx_dma_channel { void (*err_handler) (int, void *, int errcode); void (*prog_handler) (int, void *, struct scatterlist *); void *data; - dmamode_t dma_mode; + unsigned int dma_mode; struct scatterlist *sg; unsigned int resbytes; int dma_num; @@ -193,7 +193,7 @@ static inline int imx_dma_sg_next(int channel, struct scatterlist *sg) int imx_dma_setup_single(int channel, dma_addr_t dma_address, unsigned int dma_length, unsigned int dev_addr, - dmamode_t dmamode) + unsigned int dmamode) { struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; @@ -288,7 +288,7 @@ int imx_dma_setup_sg(int channel, struct scatterlist *sg, unsigned int sgcount, unsigned int dma_length, unsigned int dev_addr, - dmamode_t dmamode) + unsigned int dmamode) { struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; diff --git a/arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h b/arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h index 6cc6f0c8cb2..c162920b13a 100644 --- a/arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h +++ b/arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h @@ -54,12 +54,12 @@ imx_dma_config_burstlen(int channel, unsigned int burstlen); int imx_dma_setup_single(int channel, dma_addr_t dma_address, unsigned int dma_length, unsigned int dev_addr, - dmamode_t dmamode); + unsigned int dmamode); int imx_dma_setup_sg(int channel, struct scatterlist *sg, unsigned int sgcount, unsigned int dma_length, - unsigned int dev_addr, dmamode_t dmamode); + unsigned int dev_addr, unsigned int dmamode); int imx_dma_setup_handlers(int channel, -- cgit v1.2.3 From f0ffc816250a8cc28e6824326e2d58333e058eca Mon Sep 17 00:00:00 2001 From: Russell King Date: Fri, 2 Jan 2009 12:34:55 +0000 Subject: [ARM] dma: remove dmamode_t typedef Signed-off-by: Russell King --- arch/arm/include/asm/dma.h | 7 +------ arch/arm/include/asm/mach/dma.h | 2 +- arch/arm/kernel/dma.c | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/arm/include/asm/dma.h b/arch/arm/include/asm/dma.h index 59f59c6c79f..7edf3536df2 100644 --- a/arch/arm/include/asm/dma.h +++ b/arch/arm/include/asm/dma.h @@ -21,11 +21,6 @@ #include -/* - * DMA modes - */ -typedef unsigned int dmamode_t; - /* * The DMA modes reflect the settings for the ISA DMA controller */ @@ -125,7 +120,7 @@ extern void set_dma_count(unsigned int chan, unsigned long count); * DMA transfer direction immediately, but defer it to the * enable_dma(). */ -extern void set_dma_mode(unsigned int chan, dmamode_t mode); +extern void set_dma_mode(unsigned int chan, unsigned int mode); /* Set the transfer speed for this channel */ diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h index 3122adae80b..5166145d8a3 100644 --- a/arch/arm/include/asm/mach/dma.h +++ b/arch/arm/include/asm/mach/dma.h @@ -34,7 +34,7 @@ struct dma_struct { unsigned int active:1; /* Transfer active */ unsigned int invalid:1; /* Address/Count changed */ - dmamode_t dma_mode; /* DMA mode */ + unsigned int dma_mode; /* DMA mode */ int speed; /* DMA speed */ unsigned int lock; /* Device is allocated */ diff --git a/arch/arm/kernel/dma.c b/arch/arm/kernel/dma.c index e7828fcd954..7d5b9fb01e7 100644 --- a/arch/arm/kernel/dma.c +++ b/arch/arm/kernel/dma.c @@ -171,7 +171,7 @@ EXPORT_SYMBOL(set_dma_count); /* Set DMA direction mode */ -void set_dma_mode (unsigned int chan, dmamode_t mode) +void set_dma_mode (unsigned int chan, unsigned int mode) { dma_t *dma = dma_channel(chan); -- cgit v1.2.3 From 308d333ad6cc12e39adaed22dc10bac48e17742a Mon Sep 17 00:00:00 2001 From: Russell King Date: Sat, 21 Feb 2009 21:36:22 +0000 Subject: [ARM] dma: move IOMD and floppy DMA structures to RiscPC DMA code There's no point these being in a generic include file when they're only used in arch/arm/mach-rpc/dma.c. Signed-off-by: Russell King --- arch/arm/include/asm/mach/dma.h | 13 ------------- arch/arm/mach-rpc/dma.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h index 5166145d8a3..9e614a18e68 100644 --- a/arch/arm/include/asm/mach/dma.h +++ b/arch/arm/include/asm/mach/dma.h @@ -43,19 +43,6 @@ struct dma_struct { const struct dma_ops *d_ops; }; -struct floppy_dma { - struct dma_struct dma; - unsigned int fiq; -}; - -struct iomd_dma { - struct dma_struct dma; - unsigned int state; - unsigned long base; /* Controller base address */ - int irq; /* Controller IRQ */ - struct scatterlist cur_sg; /* Current controller buffer */ -}; - /* * isa_dma_add - add an ISA-style DMA channel */ diff --git a/arch/arm/mach-rpc/dma.c b/arch/arm/mach-rpc/dma.c index a5987bbed60..1f77cdca26e 100644 --- a/arch/arm/mach-rpc/dma.c +++ b/arch/arm/mach-rpc/dma.c @@ -26,6 +26,14 @@ #include #include +struct iomd_dma { + struct dma_struct dma; + unsigned int state; + unsigned long base; /* Controller base address */ + int irq; /* Controller IRQ */ + struct scatterlist cur_sg; /* Current controller buffer */ +}; + #if 0 typedef enum { dma_size_8 = 1, @@ -242,6 +250,11 @@ static struct fiq_handler fh = { .name = "floppydma" }; +struct floppy_dma { + struct dma_struct dma; + unsigned int fiq; +}; + static void floppy_enable_dma(unsigned int chan, dma_t *dma) { struct floppy_dma *fdma = container_of(dma, struct floppy_dma, dma); -- cgit v1.2.3 From fa4e998999322bc1b11d2c8b19b9fa2016fd1548 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sat, 21 Feb 2009 21:38:56 +0000 Subject: [ARM] dma: RiscPC: don't modify DMA SG entries We should not be modifying the scatterlist passed to us from the driver code; doing so breaks assumptions made by the DMA API code, and could cause problems if the driver retries a transfer using an old scatterlist. Signed-off-by: Russell King --- arch/arm/mach-rpc/dma.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-rpc/dma.c b/arch/arm/mach-rpc/dma.c index 1f77cdca26e..c47d974d52b 100644 --- a/arch/arm/mach-rpc/dma.c +++ b/arch/arm/mach-rpc/dma.c @@ -32,6 +32,8 @@ struct iomd_dma { unsigned long base; /* Controller base address */ int irq; /* Controller IRQ */ struct scatterlist cur_sg; /* Current controller buffer */ + dma_addr_t dma_addr; + unsigned int dma_len; }; #if 0 @@ -57,10 +59,10 @@ static void iomd_get_next_sg(struct scatterlist *sg, struct iomd_dma *idma) unsigned long end, offset, flags = 0; if (idma->dma.sg) { - sg->dma_address = idma->dma.sg->dma_address; + sg->dma_address = idma->dma_addr; offset = sg->dma_address & ~PAGE_MASK; - end = offset + idma->dma.sg->length; + end = offset + idma->dma_len; if (end > PAGE_SIZE) end = PAGE_SIZE; @@ -70,12 +72,14 @@ static void iomd_get_next_sg(struct scatterlist *sg, struct iomd_dma *idma) sg->length = end - TRANSFER_SIZE; - idma->dma.sg->length -= end - offset; - idma->dma.sg->dma_address += end - offset; + idma->dma_len -= end - offset; + idma->dma_addr += end - offset; - if (idma->dma.sg->length == 0) { + if (idma->dma_len == 0) { if (idma->dma.sgcount > 1) { idma->dma.sg = sg_next(idma->dma.sg); + idma->dma_addr = idma->dma.sg->dma_address; + idma->dma_len = idma->dma.sg->length; idma->dma.sgcount--; } else { idma->dma.sg = NULL; -- cgit v1.2.3