blob: c5557a650d1d83cdf27514db3a9469e1b028de9e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_ARM_DMA_H
2#define __ASM_ARM_DMA_H
3
Russell Kingb9c78022008-11-29 10:50:22 +00004#include <asm/memory.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6/*
Russell Kingd4c6fc92006-01-04 15:30:48 +00007 * This is the maximum virtual address which can be DMA'd from.
8 */
9#ifndef MAX_DMA_ADDRESS
10#define MAX_DMA_ADDRESS 0xffffffff
11#endif
12
Russell Kingdcea83a2008-11-29 11:40:28 +000013#ifdef CONFIG_ISA_DMA_API
14/*
15 * This is used to support drivers written for the x86 ISA DMA API.
16 * It should not be re-used except for that purpose.
17 */
18#include <linux/spinlock.h>
19#include <asm/system.h>
20#include <asm/scatterlist.h>
21
Russell Kingf40b1212008-11-29 18:48:07 +000022#include <mach/isa-dma.h>
Russell Kingdcea83a2008-11-29 11:40:28 +000023
Russell Kingd4c6fc92006-01-04 15:30:48 +000024/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * DMA modes
26 */
27typedef unsigned int dmamode_t;
28
29#define DMA_MODE_MASK 3
30
31#define DMA_MODE_READ 0
32#define DMA_MODE_WRITE 1
33#define DMA_MODE_CASCADE 2
34#define DMA_AUTOINIT 4
35
36extern spinlock_t dma_spin_lock;
37
38static inline unsigned long claim_dma_lock(void)
39{
40 unsigned long flags;
41 spin_lock_irqsave(&dma_spin_lock, flags);
42 return flags;
43}
44
45static inline void release_dma_lock(unsigned long flags)
46{
47 spin_unlock_irqrestore(&dma_spin_lock, flags);
48}
49
50/* Clear the 'DMA Pointer Flip Flop'.
51 * Write 0 for LSB/MSB, 1 for MSB/LSB access.
52 */
Russell King1df81302008-12-08 15:58:50 +000053#define clear_dma_ff(chan)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* Set only the page register bits of the transfer address.
56 *
57 * NOTE: This is an architecture specific function, and should
58 * be hidden from the drivers
59 */
Russell King1df81302008-12-08 15:58:50 +000060extern void set_dma_page(unsigned int chan, char pagenr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/* Request a DMA channel
63 *
64 * Some architectures may need to do allocate an interrupt
65 */
Russell King1df81302008-12-08 15:58:50 +000066extern int request_dma(unsigned int chan, const char * device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/* Free a DMA channel
69 *
70 * Some architectures may need to do free an interrupt
71 */
Russell King1df81302008-12-08 15:58:50 +000072extern void free_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/* Enable DMA for this channel
75 *
76 * On some architectures, this may have other side effects like
77 * enabling an interrupt and setting the DMA registers.
78 */
Russell King1df81302008-12-08 15:58:50 +000079extern void enable_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/* Disable DMA for this channel
82 *
83 * On some architectures, this may have other side effects like
84 * disabling an interrupt or whatever.
85 */
Russell King1df81302008-12-08 15:58:50 +000086extern void disable_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/* Test whether the specified channel has an active DMA transfer
89 */
Russell King1df81302008-12-08 15:58:50 +000090extern int dma_channel_active(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/* Set the DMA scatter gather list for this channel
93 *
94 * This should not be called if a DMA channel is enabled,
95 * especially since some DMA architectures don't update the
96 * DMA address immediately, but defer it to the enable_dma().
97 */
Russell King1df81302008-12-08 15:58:50 +000098extern void set_dma_sg(unsigned int chan, struct scatterlist *sg, int nr_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100/* Set the DMA address for this channel
101 *
102 * This should not be called if a DMA channel is enabled,
103 * especially since some DMA architectures don't update the
104 * DMA address immediately, but defer it to the enable_dma().
105 */
Russell King1df81302008-12-08 15:58:50 +0000106extern void __set_dma_addr(unsigned int chan, void *addr);
107#define set_dma_addr(chan, addr) \
108 __set_dma_addr(chan, bus_to_virt(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110/* Set the DMA byte count for this channel
111 *
112 * This should not be called if a DMA channel is enabled,
113 * especially since some DMA architectures don't update the
114 * DMA count immediately, but defer it to the enable_dma().
115 */
Russell King1df81302008-12-08 15:58:50 +0000116extern void set_dma_count(unsigned int chan, unsigned long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/* Set the transfer direction for this channel
119 *
120 * This should not be called if a DMA channel is enabled,
121 * especially since some DMA architectures don't update the
122 * DMA transfer direction immediately, but defer it to the
123 * enable_dma().
124 */
Russell King1df81302008-12-08 15:58:50 +0000125extern void set_dma_mode(unsigned int chan, dmamode_t mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127/* Set the transfer speed for this channel
128 */
Russell King1df81302008-12-08 15:58:50 +0000129extern void set_dma_speed(unsigned int chan, int cycle_ns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/* Get DMA residue count. After a DMA transfer, this
132 * should return zero. Reading this while a DMA transfer is
133 * still in progress will return unpredictable results.
134 * If called before the channel has been used, it may return 1.
135 * Otherwise, it returns the number of _bytes_ left to transfer.
136 */
Russell King1df81302008-12-08 15:58:50 +0000137extern int get_dma_residue(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139#ifndef NO_DMA
140#define NO_DMA 255
141#endif
142
143#ifdef CONFIG_PCI
144extern int isa_dma_bridge_buggy;
145#else
146#define isa_dma_bridge_buggy (0)
147#endif
148
Russell Kingdcea83a2008-11-29 11:40:28 +0000149#endif /* CONFIG_ISA_DMA_API */
150
151#endif /* __ASM_ARM_DMA_H */