2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2025-01-12 15:44:01 +08:00

[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 <rmk+kernel@arm.linux.org.uk>
This commit is contained in:
Russell King 2008-12-08 16:08:48 +00:00 committed by Russell King
parent 1df8130278
commit 3afb6e9c63

View File

@ -25,6 +25,16 @@ 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)
return NULL;
return dma;
}
/* /*
* Request DMA channel * 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) int request_dma(unsigned int chan, const char *device_id)
{ {
dma_t *dma = dma_chan + chan; dma_t *dma = dma_channel(chan);
int ret; int ret;
if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) if (!dma)
goto bad_dma; goto bad_dma;
if (xchg(&dma->lock, 1) != 0) if (xchg(&dma->lock, 1) != 0)
@ -70,9 +80,9 @@ EXPORT_SYMBOL(request_dma);
*/ */
void free_dma(unsigned int chan) 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; goto bad_dma;
if (dma->active) { if (dma->active) {
@ -99,7 +109,7 @@ EXPORT_SYMBOL(free_dma);
*/ */
void set_dma_sg (unsigned int chan, struct scatterlist *sg, int nr_sg) 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) if (dma->active)
printk(KERN_ERR "dma%d: altering DMA SG while " 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) void __set_dma_addr (unsigned int chan, void *addr)
{ {
dma_t *dma = dma_chan + chan; dma_t *dma = dma_channel(chan);
if (dma->active) if (dma->active)
printk(KERN_ERR "dma%d: altering DMA address while " 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) 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) if (dma->active)
printk(KERN_ERR "dma%d: altering DMA count while " 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) 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) if (dma->active)
printk(KERN_ERR "dma%d: altering DMA mode while " printk(KERN_ERR "dma%d: altering DMA mode while "
@ -166,7 +176,7 @@ EXPORT_SYMBOL(set_dma_mode);
*/ */
void enable_dma (unsigned int chan) void enable_dma (unsigned int chan)
{ {
dma_t *dma = dma_chan + chan; dma_t *dma = dma_channel(chan);
if (!dma->lock) if (!dma->lock)
goto free_dma; goto free_dma;
@ -187,7 +197,7 @@ EXPORT_SYMBOL(enable_dma);
*/ */
void disable_dma (unsigned int chan) void disable_dma (unsigned int chan)
{ {
dma_t *dma = dma_chan + chan; dma_t *dma = dma_channel(chan);
if (!dma->lock) if (!dma->lock)
goto free_dma; goto free_dma;
@ -209,7 +219,8 @@ EXPORT_SYMBOL(disable_dma);
*/ */
int dma_channel_active(unsigned int chan) 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); EXPORT_SYMBOL(dma_channel_active);
@ -221,7 +232,7 @@ EXPORT_SYMBOL(set_dma_page);
void set_dma_speed(unsigned int chan, int cycle_ns) 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; int ret = 0;
if (dma->d_ops->setspeed) if (dma->d_ops->setspeed)
@ -232,7 +243,7 @@ EXPORT_SYMBOL(set_dma_speed);
int get_dma_residue(unsigned int chan) int get_dma_residue(unsigned int chan)
{ {
dma_t *dma = dma_chan + chan; dma_t *dma = dma_channel(chan);
int ret = 0; int ret = 0;
if (dma->d_ops->residue) if (dma->d_ops->residue)
@ -247,5 +258,4 @@ static int __init init_dma(void)
arch_dma_init(dma_chan); arch_dma_init(dma_chan);
return 0; return 0;
} }
core_initcall(init_dma); core_initcall(init_dma);