blob: fcf15de8cadba151c483aa973ffeb651ddcaac08 [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 */
Nicolas Pitre65032012011-07-18 15:05:10 -04009#ifndef CONFIG_ZONE_DMA
10#define MAX_DMA_ADDRESS 0xffffffffUL
Russell King2fb3ec52011-05-11 16:06:29 +010011#else
Nicolas Pitre65032012011-07-18 15:05:10 -040012#define MAX_DMA_ADDRESS ({ \
13 extern unsigned long arm_dma_zone_size; \
14 arm_dma_zone_size ? \
15 (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })
Russell Kingd4c6fc92006-01-04 15:30:48 +000016#endif
17
Russell Kingdcea83a2008-11-29 11:40:28 +000018#ifdef CONFIG_ISA_DMA_API
19/*
20 * This is used to support drivers written for the x86 ISA DMA API.
21 * It should not be re-used except for that purpose.
22 */
23#include <linux/spinlock.h>
24#include <asm/system.h>
25#include <asm/scatterlist.h>
26
Russell Kingf40b1212008-11-29 18:48:07 +000027#include <mach/isa-dma.h>
Russell Kingdcea83a2008-11-29 11:40:28 +000028
Russell Kingd4c6fc92006-01-04 15:30:48 +000029/*
Russell Kingbc6447b2009-01-02 12:18:53 +000030 * The DMA modes reflect the settings for the ISA DMA controller
31 */
32#define DMA_MODE_MASK 0xcc
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Russell Kingbc6447b2009-01-02 12:18:53 +000034#define DMA_MODE_READ 0x44
35#define DMA_MODE_WRITE 0x48
36#define DMA_MODE_CASCADE 0xc0
37#define DMA_AUTOINIT 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39extern spinlock_t dma_spin_lock;
40
41static inline unsigned long claim_dma_lock(void)
42{
43 unsigned long flags;
44 spin_lock_irqsave(&dma_spin_lock, flags);
45 return flags;
46}
47
48static inline void release_dma_lock(unsigned long flags)
49{
50 spin_unlock_irqrestore(&dma_spin_lock, flags);
51}
52
53/* Clear the 'DMA Pointer Flip Flop'.
54 * Write 0 for LSB/MSB, 1 for MSB/LSB access.
55 */
Russell King1df81302008-12-08 15:58:50 +000056#define clear_dma_ff(chan)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/* Set only the page register bits of the transfer address.
59 *
60 * NOTE: This is an architecture specific function, and should
61 * be hidden from the drivers
62 */
Russell King1df81302008-12-08 15:58:50 +000063extern void set_dma_page(unsigned int chan, char pagenr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* Request a DMA channel
66 *
67 * Some architectures may need to do allocate an interrupt
68 */
Russell King1df81302008-12-08 15:58:50 +000069extern int request_dma(unsigned int chan, const char * device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* Free a DMA channel
72 *
73 * Some architectures may need to do free an interrupt
74 */
Russell King1df81302008-12-08 15:58:50 +000075extern void free_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/* Enable DMA for this channel
78 *
79 * On some architectures, this may have other side effects like
80 * enabling an interrupt and setting the DMA registers.
81 */
Russell King1df81302008-12-08 15:58:50 +000082extern void enable_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/* Disable DMA for this channel
85 *
86 * On some architectures, this may have other side effects like
87 * disabling an interrupt or whatever.
88 */
Russell King1df81302008-12-08 15:58:50 +000089extern void disable_dma(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/* Test whether the specified channel has an active DMA transfer
92 */
Russell King1df81302008-12-08 15:58:50 +000093extern int dma_channel_active(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/* Set the DMA scatter gather list for this channel
96 *
97 * This should not be called if a DMA channel is enabled,
98 * especially since some DMA architectures don't update the
99 * DMA address immediately, but defer it to the enable_dma().
100 */
Russell King1df81302008-12-08 15:58:50 +0000101extern void set_dma_sg(unsigned int chan, struct scatterlist *sg, int nr_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/* Set the DMA address for this channel
104 *
105 * This should not be called if a DMA channel is enabled,
106 * especially since some DMA architectures don't update the
107 * DMA address immediately, but defer it to the enable_dma().
108 */
Russell King1df81302008-12-08 15:58:50 +0000109extern void __set_dma_addr(unsigned int chan, void *addr);
110#define set_dma_addr(chan, addr) \
111 __set_dma_addr(chan, bus_to_virt(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113/* Set the DMA byte count for this channel
114 *
115 * This should not be called if a DMA channel is enabled,
116 * especially since some DMA architectures don't update the
117 * DMA count immediately, but defer it to the enable_dma().
118 */
Russell King1df81302008-12-08 15:58:50 +0000119extern void set_dma_count(unsigned int chan, unsigned long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121/* Set the transfer direction for this channel
122 *
123 * This should not be called if a DMA channel is enabled,
124 * especially since some DMA architectures don't update the
125 * DMA transfer direction immediately, but defer it to the
126 * enable_dma().
127 */
Russell Kingf0ffc812009-01-02 12:34:55 +0000128extern void set_dma_mode(unsigned int chan, unsigned int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130/* Set the transfer speed for this channel
131 */
Russell King1df81302008-12-08 15:58:50 +0000132extern void set_dma_speed(unsigned int chan, int cycle_ns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* Get DMA residue count. After a DMA transfer, this
135 * should return zero. Reading this while a DMA transfer is
136 * still in progress will return unpredictable results.
137 * If called before the channel has been used, it may return 1.
138 * Otherwise, it returns the number of _bytes_ left to transfer.
139 */
Russell King1df81302008-12-08 15:58:50 +0000140extern int get_dma_residue(unsigned int chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142#ifndef NO_DMA
143#define NO_DMA 255
144#endif
145
Peter Hüwef8920272010-01-09 13:46:08 +0100146#endif /* CONFIG_ISA_DMA_API */
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef CONFIG_PCI
149extern int isa_dma_bridge_buggy;
150#else
151#define isa_dma_bridge_buggy (0)
152#endif
153
Russell Kingdcea83a2008-11-29 11:40:28 +0000154#endif /* __ASM_ARM_DMA_H */