2  *  linux/arch/arm/kernel/dma.c
 
   4  *  Copyright (C) 1995-2000 Russell King
 
   6  * This program is free software; you can redistribute it and/or modify
 
   7  * it under the terms of the GNU General Public License version 2 as
 
   8  * published by the Free Software Foundation.
 
  10  *  Front-end to the DMA handling.  This handles the allocation/freeing
 
  11  *  of DMA channels, and provides a unified interface to the machines
 
  14 #include <linux/module.h>
 
  15 #include <linux/slab.h>
 
  16 #include <linux/mman.h>
 
  17 #include <linux/init.h>
 
  18 #include <linux/spinlock.h>
 
  19 #include <linux/errno.h>
 
  23 #include <asm/mach/dma.h>
 
  25 DEFINE_SPINLOCK(dma_spin_lock);
 
  27 #if MAX_DMA_CHANNELS > 0
 
  29 static dma_t dma_chan[MAX_DMA_CHANNELS];
 
  32  * Get dma list for /proc/dma
 
  34 int get_dma_list(char *buf)
 
  40         for (i = 0, dma = dma_chan; i < MAX_DMA_CHANNELS; i++, dma++)
 
  42                         p += sprintf(p, "%2d: %14s %s\n", i,
 
  43                                      dma->d_ops->type, dma->device_id);
 
  51  * On certain platforms, we have to allocate an interrupt as well...
 
  53 int request_dma(dmach_t channel, const char *device_id)
 
  55         dma_t *dma = dma_chan + channel;
 
  58         if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
 
  61         if (xchg(&dma->lock, 1) != 0)
 
  64         dma->device_id = device_id;
 
  69         if (dma->d_ops->request)
 
  70                 ret = dma->d_ops->request(channel, dma);
 
  78         printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel);
 
  88  * On certain platforms, we have to free interrupt as well...
 
  90 void free_dma(dmach_t channel)
 
  92         dma_t *dma = dma_chan + channel;
 
  94         if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
 
  98                 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
 
  99                 dma->d_ops->disable(channel, dma);
 
 103         if (xchg(&dma->lock, 0) != 0) {
 
 104                 if (dma->d_ops->free)
 
 105                         dma->d_ops->free(channel, dma);
 
 109         printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
 
 113         printk(KERN_ERR "dma: trying to free DMA%d\n", channel);
 
 116 /* Set DMA Scatter-Gather list
 
 118 void set_dma_sg (dmach_t channel, struct scatterlist *sg, int nr_sg)
 
 120         dma_t *dma = dma_chan + channel;
 
 123                 printk(KERN_ERR "dma%d: altering DMA SG while "
 
 124                        "DMA active\n", channel);
 
 127         dma->sgcount = nr_sg;
 
 134  * Copy address to the structure, and set the invalid bit
 
 136 void set_dma_addr (dmach_t channel, unsigned long physaddr)
 
 138         dma_t *dma = dma_chan + channel;
 
 141                 printk(KERN_ERR "dma%d: altering DMA address while "
 
 142                        "DMA active\n", channel);
 
 146         dma->buf.__address = bus_to_virt(physaddr);
 
 151 /* Set DMA byte count
 
 153  * Copy address to the structure, and set the invalid bit
 
 155 void set_dma_count (dmach_t channel, unsigned long count)
 
 157         dma_t *dma = dma_chan + channel;
 
 160                 printk(KERN_ERR "dma%d: altering DMA count while "
 
 161                        "DMA active\n", channel);
 
 165         dma->buf.length = count;
 
 170 /* Set DMA direction mode
 
 172 void set_dma_mode (dmach_t channel, dmamode_t mode)
 
 174         dma_t *dma = dma_chan + channel;
 
 177                 printk(KERN_ERR "dma%d: altering DMA mode while "
 
 178                        "DMA active\n", channel);
 
 180         dma->dma_mode = mode;
 
 184 /* Enable DMA channel
 
 186 void enable_dma (dmach_t channel)
 
 188         dma_t *dma = dma_chan + channel;
 
 193         if (dma->active == 0) {
 
 195                 dma->d_ops->enable(channel, dma);
 
 200         printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
 
 204 /* Disable DMA channel
 
 206 void disable_dma (dmach_t channel)
 
 208         dma_t *dma = dma_chan + channel;
 
 213         if (dma->active == 1) {
 
 215                 dma->d_ops->disable(channel, dma);
 
 220         printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
 
 225  * Is the specified DMA channel active?
 
 227 int dma_channel_active(dmach_t channel)
 
 229         return dma_chan[channel].active;
 
 232 void set_dma_page(dmach_t channel, char pagenr)
 
 234         printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
 
 237 void set_dma_speed(dmach_t channel, int cycle_ns)
 
 239         dma_t *dma = dma_chan + channel;
 
 242         if (dma->d_ops->setspeed)
 
 243                 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
 
 247 int get_dma_residue(dmach_t channel)
 
 249         dma_t *dma = dma_chan + channel;
 
 252         if (dma->d_ops->residue)
 
 253                 ret = dma->d_ops->residue(channel, dma);
 
 258 void __init init_dma(void)
 
 260         arch_dma_init(dma_chan);
 
 265 int request_dma(dmach_t channel, const char *device_id)
 
 270 int get_dma_residue(dmach_t channel)
 
 275 #define GLOBAL_ALIAS(_a,_b) asm (".set " #_a "," #_b "; .globl " #_a)
 
 276 GLOBAL_ALIAS(disable_dma, get_dma_residue);
 
 277 GLOBAL_ALIAS(enable_dma, get_dma_residue);
 
 278 GLOBAL_ALIAS(free_dma, get_dma_residue);
 
 279 GLOBAL_ALIAS(get_dma_list, get_dma_residue);
 
 280 GLOBAL_ALIAS(set_dma_mode, get_dma_residue);
 
 281 GLOBAL_ALIAS(set_dma_page, get_dma_residue);
 
 282 GLOBAL_ALIAS(set_dma_count, get_dma_residue);
 
 283 GLOBAL_ALIAS(set_dma_addr, get_dma_residue);
 
 284 GLOBAL_ALIAS(set_dma_sg, get_dma_residue);
 
 285 GLOBAL_ALIAS(set_dma_speed, get_dma_residue);
 
 286 GLOBAL_ALIAS(init_dma, get_dma_residue);
 
 290 EXPORT_SYMBOL(request_dma);
 
 291 EXPORT_SYMBOL(free_dma);
 
 292 EXPORT_SYMBOL(enable_dma);
 
 293 EXPORT_SYMBOL(disable_dma);
 
 294 EXPORT_SYMBOL(set_dma_addr);
 
 295 EXPORT_SYMBOL(set_dma_count);
 
 296 EXPORT_SYMBOL(set_dma_mode);
 
 297 EXPORT_SYMBOL(set_dma_page);
 
 298 EXPORT_SYMBOL(get_dma_residue);
 
 299 EXPORT_SYMBOL(set_dma_sg);
 
 300 EXPORT_SYMBOL(set_dma_speed);
 
 302 EXPORT_SYMBOL(dma_spin_lock);