xref: /OK3568_Linux_fs/kernel/arch/parisc/include/asm/dma.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* asm/dma.h: Defines for using and allocating dma channels.
3*4882a593Smuzhiyun  * Written by Hennus Bergman, 1992.
4*4882a593Smuzhiyun  * High DMA channel support & info by Hannu Savolainen
5*4882a593Smuzhiyun  * and John Boyd, Nov. 1992.
6*4882a593Smuzhiyun  * (c) Copyright 2000, Grant Grundler
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _ASM_DMA_H
10*4882a593Smuzhiyun #define _ASM_DMA_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <asm/io.h>		/* need byte IO */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #define dma_outb	outb
15*4882a593Smuzhiyun #define dma_inb		inb
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun ** DMA_CHUNK_SIZE is used by the SCSI mid-layer to break up
19*4882a593Smuzhiyun ** (or rather not merge) DMAs into manageable chunks.
20*4882a593Smuzhiyun ** On parisc, this is more of the software/tuning constraint
21*4882a593Smuzhiyun ** rather than the HW. I/O MMU allocation algorithms can be
22*4882a593Smuzhiyun ** faster with smaller sizes (to some degree).
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun #define DMA_CHUNK_SIZE	(BITS_PER_LONG*PAGE_SIZE)
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /* The maximum address that we can perform a DMA transfer to on this platform
27*4882a593Smuzhiyun ** New dynamic DMA interfaces should obsolete this....
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun #define MAX_DMA_ADDRESS (~0UL)
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun ** We don't have DMA channels... well V-class does but the
33*4882a593Smuzhiyun ** Dynamic DMA Mapping interface will support them... right? :^)
34*4882a593Smuzhiyun ** Note: this is not relevant right now for PA-RISC, but we cannot
35*4882a593Smuzhiyun ** leave this as undefined because some things (e.g. sound)
36*4882a593Smuzhiyun ** won't compile :-(
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun #define MAX_DMA_CHANNELS 8
39*4882a593Smuzhiyun #define DMA_MODE_READ	0x44	/* I/O to memory, no autoinit, increment, single mode */
40*4882a593Smuzhiyun #define DMA_MODE_WRITE	0x48	/* memory to I/O, no autoinit, increment, single mode */
41*4882a593Smuzhiyun #define DMA_MODE_CASCADE 0xC0	/* pass thru DREQ->HRQ, DACK<-HLDA only */
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #define DMA_AUTOINIT	0x10
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* 8237 DMA controllers */
46*4882a593Smuzhiyun #define IO_DMA1_BASE	0x00	/* 8 bit slave DMA, channels 0..3 */
47*4882a593Smuzhiyun #define IO_DMA2_BASE	0xC0	/* 16 bit master DMA, ch 4(=slave input)..7 */
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* DMA controller registers */
50*4882a593Smuzhiyun #define DMA1_CMD_REG		0x08	/* command register (w) */
51*4882a593Smuzhiyun #define DMA1_STAT_REG		0x08	/* status register (r) */
52*4882a593Smuzhiyun #define DMA1_REQ_REG            0x09    /* request register (w) */
53*4882a593Smuzhiyun #define DMA1_MASK_REG		0x0A	/* single-channel mask (w) */
54*4882a593Smuzhiyun #define DMA1_MODE_REG		0x0B	/* mode register (w) */
55*4882a593Smuzhiyun #define DMA1_CLEAR_FF_REG	0x0C	/* clear pointer flip-flop (w) */
56*4882a593Smuzhiyun #define DMA1_TEMP_REG           0x0D    /* Temporary Register (r) */
57*4882a593Smuzhiyun #define DMA1_RESET_REG		0x0D	/* Master Clear (w) */
58*4882a593Smuzhiyun #define DMA1_CLR_MASK_REG       0x0E    /* Clear Mask */
59*4882a593Smuzhiyun #define DMA1_MASK_ALL_REG       0x0F    /* all-channels mask (w) */
60*4882a593Smuzhiyun #define DMA1_EXT_MODE_REG	(0x400 | DMA1_MODE_REG)
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun #define DMA2_CMD_REG		0xD0	/* command register (w) */
63*4882a593Smuzhiyun #define DMA2_STAT_REG		0xD0	/* status register (r) */
64*4882a593Smuzhiyun #define DMA2_REQ_REG            0xD2    /* request register (w) */
65*4882a593Smuzhiyun #define DMA2_MASK_REG		0xD4	/* single-channel mask (w) */
66*4882a593Smuzhiyun #define DMA2_MODE_REG		0xD6	/* mode register (w) */
67*4882a593Smuzhiyun #define DMA2_CLEAR_FF_REG	0xD8	/* clear pointer flip-flop (w) */
68*4882a593Smuzhiyun #define DMA2_TEMP_REG           0xDA    /* Temporary Register (r) */
69*4882a593Smuzhiyun #define DMA2_RESET_REG		0xDA	/* Master Clear (w) */
70*4882a593Smuzhiyun #define DMA2_CLR_MASK_REG       0xDC    /* Clear Mask */
71*4882a593Smuzhiyun #define DMA2_MASK_ALL_REG       0xDE    /* all-channels mask (w) */
72*4882a593Smuzhiyun #define DMA2_EXT_MODE_REG	(0x400 | DMA2_MODE_REG)
73*4882a593Smuzhiyun 
claim_dma_lock(void)74*4882a593Smuzhiyun static __inline__ unsigned long claim_dma_lock(void)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun 	return 0;
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
release_dma_lock(unsigned long flags)79*4882a593Smuzhiyun static __inline__ void release_dma_lock(unsigned long flags)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /* Get DMA residue count. After a DMA transfer, this
85*4882a593Smuzhiyun  * should return zero. Reading this while a DMA transfer is
86*4882a593Smuzhiyun  * still in progress will return unpredictable results.
87*4882a593Smuzhiyun  * If called before the channel has been used, it may return 1.
88*4882a593Smuzhiyun  * Otherwise, it returns the number of _bytes_ left to transfer.
89*4882a593Smuzhiyun  *
90*4882a593Smuzhiyun  * Assumes DMA flip-flop is clear.
91*4882a593Smuzhiyun  */
get_dma_residue(unsigned int dmanr)92*4882a593Smuzhiyun static __inline__ int get_dma_residue(unsigned int dmanr)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun 	unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE
95*4882a593Smuzhiyun 					 : ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	/* using short to get 16-bit wrap around */
98*4882a593Smuzhiyun 	unsigned short count;
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun 	count = 1 + dma_inb(io_port);
101*4882a593Smuzhiyun 	count += dma_inb(io_port) << 8;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	return (dmanr<=3)? count : (count<<1);
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* enable/disable a specific DMA channel */
enable_dma(unsigned int dmanr)107*4882a593Smuzhiyun static __inline__ void enable_dma(unsigned int dmanr)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun #ifdef CONFIG_SUPERIO
110*4882a593Smuzhiyun 	if (dmanr<=3)
111*4882a593Smuzhiyun 		dma_outb(dmanr,  DMA1_MASK_REG);
112*4882a593Smuzhiyun 	else
113*4882a593Smuzhiyun 		dma_outb(dmanr & 3,  DMA2_MASK_REG);
114*4882a593Smuzhiyun #endif
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun 
disable_dma(unsigned int dmanr)117*4882a593Smuzhiyun static __inline__ void disable_dma(unsigned int dmanr)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun #ifdef CONFIG_SUPERIO
120*4882a593Smuzhiyun 	if (dmanr<=3)
121*4882a593Smuzhiyun 		dma_outb(dmanr | 4,  DMA1_MASK_REG);
122*4882a593Smuzhiyun 	else
123*4882a593Smuzhiyun 		dma_outb((dmanr & 3) | 4,  DMA2_MASK_REG);
124*4882a593Smuzhiyun #endif
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /* reserve a DMA channel */
128*4882a593Smuzhiyun #define request_dma(dmanr, device_id)	(0)
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun /* Clear the 'DMA Pointer Flip Flop'.
131*4882a593Smuzhiyun  * Write 0 for LSB/MSB, 1 for MSB/LSB access.
132*4882a593Smuzhiyun  * Use this once to initialize the FF to a known state.
133*4882a593Smuzhiyun  * After that, keep track of it. :-)
134*4882a593Smuzhiyun  * --- In order to do that, the DMA routines below should ---
135*4882a593Smuzhiyun  * --- only be used while holding the DMA lock ! ---
136*4882a593Smuzhiyun  */
clear_dma_ff(unsigned int dmanr)137*4882a593Smuzhiyun static __inline__ void clear_dma_ff(unsigned int dmanr)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /* set mode (above) for a specific DMA channel */
set_dma_mode(unsigned int dmanr,char mode)142*4882a593Smuzhiyun static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun /* Set only the page register bits of the transfer address.
147*4882a593Smuzhiyun  * This is used for successive transfers when we know the contents of
148*4882a593Smuzhiyun  * the lower 16 bits of the DMA current address register, but a 64k boundary
149*4882a593Smuzhiyun  * may have been crossed.
150*4882a593Smuzhiyun  */
set_dma_page(unsigned int dmanr,char pagenr)151*4882a593Smuzhiyun static __inline__ void set_dma_page(unsigned int dmanr, char pagenr)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /* Set transfer address & page bits for specific DMA channel.
157*4882a593Smuzhiyun  * Assumes dma flipflop is clear.
158*4882a593Smuzhiyun  */
set_dma_addr(unsigned int dmanr,unsigned int a)159*4882a593Smuzhiyun static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun /* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for
165*4882a593Smuzhiyun  * a specific DMA channel.
166*4882a593Smuzhiyun  * You must ensure the parameters are valid.
167*4882a593Smuzhiyun  * NOTE: from a manual: "the number of transfers is one more
168*4882a593Smuzhiyun  * than the initial word count"! This is taken into account.
169*4882a593Smuzhiyun  * Assumes dma flip-flop is clear.
170*4882a593Smuzhiyun  * NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.
171*4882a593Smuzhiyun  */
set_dma_count(unsigned int dmanr,unsigned int count)172*4882a593Smuzhiyun static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun #define free_dma(dmanr)
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun #ifdef CONFIG_PCI
180*4882a593Smuzhiyun extern int isa_dma_bridge_buggy;
181*4882a593Smuzhiyun #else
182*4882a593Smuzhiyun #define isa_dma_bridge_buggy 	(0)
183*4882a593Smuzhiyun #endif
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun #endif /* _ASM_DMA_H */
186