blob: 69a5b0b6455c72af47fe8df6db36e310cc97b8f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_ARM_DMA_H
2#define __ASM_ARM_DMA_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004/*
Russell Kingd4c6fc92006-01-04 15:30:48 +00005 * This is the maximum virtual address which can be DMA'd from.
6 */
Nicolas Pitre65032012011-07-18 15:05:10 -04007#ifndef CONFIG_ZONE_DMA
8#define MAX_DMA_ADDRESS 0xffffffffUL
Russell King2fb3ec52011-05-11 16:06:29 +01009#else
Nicolas Pitre65032012011-07-18 15:05:10 -040010#define MAX_DMA_ADDRESS ({ \
11 extern unsigned long arm_dma_zone_size; \
12 arm_dma_zone_size ? \
13 (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })
Russell Kingd4c6fc92006-01-04 15:30:48 +000014#endif
15
Russell Kingdcea83a2008-11-29 11:40:28 +000016#ifdef CONFIG_ISA_DMA_API
17/*
18 * This is used to support drivers written for the x86 ISA DMA API.
19 * It should not be re-used except for that purpose.
20 */
21#include <linux/spinlock.h>
22#include <asm/system.h>
23#include <asm/scatterlist.h>
24
Russell Kingf40b1212008-11-29 18:48:07 +000025#include <mach/isa-dma.h>
Russell Kingdcea83a2008-11-29 11:40:28 +000026
Russell Kingd4c6fc92006-01-04 15:30:48 +000027/*
Russell Kingbc6447b2009-01-02 12:18:53 +000028 * The DMA modes reflect the settings for the ISA DMA controller
29 */
30#define DMA_MODE_MASK 0xcc
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Russell Kingbc6447b2009-01-02 12:18:53 +000032#define DMA_MODE_READ 0x44
33#define DMA_MODE_WRITE 0x48
34#define DMA_MODE_CASCADE 0xc0
35#define DMA_AUTOINIT 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050037extern raw_spinlock_t dma_spin_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39static inline unsigned long claim_dma_lock(void)
40{
41 unsigned long flags;
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050042 raw_spin_lock_irqsave(&dma_spin_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 return flags;
44}
45
46static inline void release_dma_lock(unsigned long flags)
47{
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050048 raw_spin_unlock_irqrestore(&dma_spin_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51/* Clear the 'DMA Pointer Flip Flop'.
52 * Write 0 for LSB/MSB, 1 for MSB/LSB access.
53 */
Russell King1df81302008-12-08 15:58:50 +000054#define clear_dma_ff(chan)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/* Set only the page register bits of the transfer address.
57 *
58 * NOTE: This is an architecture specific function, and should
59 * be hidden from the drivers
60 */
Russell King1df81302008-12-08 15:58:50 +000061extern void set_dma_page(unsigned int chan, char pagenr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* Request a DMA channel
64 *
65 * Some architectures may need to do allocate an interrupt
66 */
Russell King1df81302008-12-08 15:58:50 +000067extern int request_dma(unsigned int chan, const char * device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* Free a DMA channel
70 *
71 * Some architectures may need to do free an interrupt
72 */
Russell King1df81302008-12-08 15:58:50 +000073extern void free_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/* Enable DMA for this channel
76 *
77 * On some architectures, this may have other side effects like
78 * enabling an interrupt and setting the DMA registers.
79 */
Russell King1df81302008-12-08 15:58:50 +000080extern void enable_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/* Disable DMA for this channel
83 *
84 * On some architectures, this may have other side effects like
85 * disabling an interrupt or whatever.
86 */
Russell King1df81302008-12-08 15:58:50 +000087extern void disable_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89/* Test whether the specified channel has an active DMA transfer
90 */
Russell King1df81302008-12-08 15:58:50 +000091extern int dma_channel_active(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/* Set the DMA scatter gather list for this channel
94 *
95 * This should not be called if a DMA channel is enabled,
96 * especially since some DMA architectures don't update the
97 * DMA address immediately, but defer it to the enable_dma().
98 */
Russell King1df81302008-12-08 15:58:50 +000099extern void set_dma_sg(unsigned int chan, struct scatterlist *sg, int nr_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101/* Set the DMA address for this channel
102 *
103 * This should not be called if a DMA channel is enabled,
104 * especially since some DMA architectures don't update the
105 * DMA address immediately, but defer it to the enable_dma().
106 */
Russell King1df81302008-12-08 15:58:50 +0000107extern void __set_dma_addr(unsigned int chan, void *addr);
108#define set_dma_addr(chan, addr) \
109 __set_dma_addr(chan, bus_to_virt(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/* Set the DMA byte count for this channel
112 *
113 * This should not be called if a DMA channel is enabled,
114 * especially since some DMA architectures don't update the
115 * DMA count immediately, but defer it to the enable_dma().
116 */
Russell King1df81302008-12-08 15:58:50 +0000117extern void set_dma_count(unsigned int chan, unsigned long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119/* Set the transfer direction for this channel
120 *
121 * This should not be called if a DMA channel is enabled,
122 * especially since some DMA architectures don't update the
123 * DMA transfer direction immediately, but defer it to the
124 * enable_dma().
125 */
Russell Kingf0ffc812009-01-02 12:34:55 +0000126extern void set_dma_mode(unsigned int chan, unsigned int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/* Set the transfer speed for this channel
129 */
Russell King1df81302008-12-08 15:58:50 +0000130extern void set_dma_speed(unsigned int chan, int cycle_ns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132/* Get DMA residue count. After a DMA transfer, this
133 * should return zero. Reading this while a DMA transfer is
134 * still in progress will return unpredictable results.
135 * If called before the channel has been used, it may return 1.
136 * Otherwise, it returns the number of _bytes_ left to transfer.
137 */
Russell King1df81302008-12-08 15:58:50 +0000138extern int get_dma_residue(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140#ifndef NO_DMA
141#define NO_DMA 255
142#endif
143
Peter Hüwef8920272010-01-09 13:46:08 +0100144#endif /* CONFIG_ISA_DMA_API */
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_PCI
147extern int isa_dma_bridge_buggy;
148#else
149#define isa_dma_bridge_buggy (0)
150#endif
151
Russell Kingdcea83a2008-11-29 11:40:28 +0000152#endif /* __ASM_ARM_DMA_H */