more changes on original files
[linux-2.4.git] / include / asm-parisc / floppy.h
1 /*
2  * Architecture specific parts of the Floppy driver
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 1995
9  */
10 #ifndef __ASM_PARISC_FLOPPY_H
11 #define __ASM_PARISC_FLOPPY_H
12
13 #include <linux/vmalloc.h>
14
15
16 /*
17  * The DMA channel used by the floppy controller cannot access data at
18  * addresses >= 16MB
19  *
20  * Went back to the 1MB limit, as some people had problems with the floppy
21  * driver otherwise. It doesn't matter much for performance anyway, as most
22  * floppy accesses go through the track buffer.
23  */
24 #define _CROSS_64KB(a,s,vdma) \
25 (!vdma && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
26
27 #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
28
29
30 #define SW fd_routine[use_virtual_dma&1]
31 #define CSW fd_routine[can_use_virtual_dma & 1]
32
33
34 #define fd_inb(port)                    inb_p(port)
35 #define fd_outb(port,value)             outb_p(port,value)
36
37 #define fd_request_dma()        CSW._request_dma(FLOPPY_DMA,"floppy")
38 #define fd_free_dma()           CSW._free_dma(FLOPPY_DMA)
39 #define fd_enable_irq()         enable_irq(FLOPPY_IRQ)
40 #define fd_disable_irq()        disable_irq(FLOPPY_IRQ)
41 #define fd_free_irq()           free_irq(FLOPPY_IRQ, NULL)
42 #define fd_get_dma_residue()    SW._get_dma_residue(FLOPPY_DMA)
43 #define fd_dma_mem_alloc(size)  SW._dma_mem_alloc(size)
44 #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
45
46 #define FLOPPY_CAN_FALLBACK_ON_NODMA
47
48 static int virtual_dma_count=0;
49 static int virtual_dma_residue=0;
50 static char *virtual_dma_addr=0;
51 static int virtual_dma_mode=0;
52 static int doing_pdma=0;
53
54 static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
55 {
56         register unsigned char st;
57
58 #undef TRACE_FLPY_INT
59 #define NO_FLOPPY_ASSEMBLER
60
61 #ifdef TRACE_FLPY_INT
62         static int calls=0;
63         static int bytes=0;
64         static int dma_wait=0;
65 #endif
66         if(!doing_pdma) {
67                 floppy_interrupt(irq, dev_id, regs);
68                 return;
69         }
70
71 #ifdef TRACE_FLPY_INT
72         if(!calls)
73                 bytes = virtual_dma_count;
74 #endif
75
76         {
77                 register int lcount;
78                 register char *lptr;
79
80                 st = 1;
81                 for(lcount=virtual_dma_count, lptr=virtual_dma_addr; 
82                     lcount; lcount--, lptr++) {
83                         st=inb(virtual_dma_port+4) & 0xa0 ;
84                         if(st != 0xa0) 
85                                 break;
86                         if(virtual_dma_mode)
87                                 outb_p(*lptr, virtual_dma_port+5);
88                         else
89                                 *lptr = inb_p(virtual_dma_port+5);
90                 }
91                 virtual_dma_count = lcount;
92                 virtual_dma_addr = lptr;
93                 st = inb(virtual_dma_port+4);
94         }
95
96 #ifdef TRACE_FLPY_INT
97         calls++;
98 #endif
99         if(st == 0x20)
100                 return;
101         if(!(st & 0x20)) {
102                 virtual_dma_residue += virtual_dma_count;
103                 virtual_dma_count=0;
104 #ifdef TRACE_FLPY_INT
105                 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n", 
106                        virtual_dma_count, virtual_dma_residue, calls, bytes,
107                        dma_wait);
108                 calls = 0;
109                 dma_wait=0;
110 #endif
111                 doing_pdma = 0;
112                 floppy_interrupt(irq, dev_id, regs);
113                 return;
114         }
115 #ifdef TRACE_FLPY_INT
116         if(!virtual_dma_count)
117                 dma_wait++;
118 #endif
119 }
120
121 static void fd_disable_dma(void)
122 {
123         if(! (can_use_virtual_dma & 1))
124                 disable_dma(FLOPPY_DMA);
125         doing_pdma = 0;
126         virtual_dma_residue += virtual_dma_count;
127         virtual_dma_count=0;
128 }
129
130 static int vdma_request_dma(unsigned int dmanr, const char * device_id)
131 {
132         return 0;
133 }
134
135 static void vdma_nop(unsigned int dummy)
136 {
137 }
138
139
140 static int vdma_get_dma_residue(unsigned int dummy)
141 {
142         return virtual_dma_count + virtual_dma_residue;
143 }
144
145
146 static int fd_request_irq(void)
147 {
148         if(can_use_virtual_dma)
149                 return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
150                                                    "floppy", NULL);
151         else
152                 return request_irq(FLOPPY_IRQ, floppy_interrupt,
153                                                    SA_INTERRUPT|SA_SAMPLE_RANDOM,
154                                                    "floppy", NULL);     
155
156 }
157
158 static unsigned long dma_mem_alloc(unsigned long size)
159 {
160         return __get_dma_pages(GFP_KERNEL,__get_order(size));
161 }
162
163
164 static unsigned long vdma_mem_alloc(unsigned long size)
165 {
166         return (unsigned long) vmalloc(size);
167
168 }
169
170 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
171
172 static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
173 {
174         if((unsigned int) addr >= (unsigned int) high_memory)
175                 return vfree((void *)addr);
176         else
177                 free_pages(addr, __get_order(size));            
178 }
179
180 #define fd_dma_mem_free(addr, size)  _fd_dma_mem_free(addr, size) 
181
182 static void _fd_chose_dma_mode(char *addr, unsigned long size)
183 {
184         if(can_use_virtual_dma == 2) {
185                 if((unsigned int) addr >= (unsigned int) high_memory ||
186                    virt_to_bus(addr) >= 0x1000000 ||
187                    _CROSS_64KB(addr, size, 0))
188                         use_virtual_dma = 1;
189                 else
190                         use_virtual_dma = 0;
191         } else {
192                 use_virtual_dma = can_use_virtual_dma & 1;
193         }
194 }
195
196 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
197
198
199 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
200 {
201         doing_pdma = 1;
202         virtual_dma_port = io;
203         virtual_dma_mode = (mode  == DMA_MODE_WRITE);
204         virtual_dma_addr = addr;
205         virtual_dma_count = size;
206         virtual_dma_residue = 0;
207         return 0;
208 }
209
210 static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
211 {
212 #ifdef FLOPPY_SANITY_CHECK
213         if (CROSS_64KB(addr, size)) {
214                 printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
215                 return -1;
216         }
217 #endif
218         /* actual, physical DMA */
219         doing_pdma = 0;
220         clear_dma_ff(FLOPPY_DMA);
221         set_dma_mode(FLOPPY_DMA,mode);
222         set_dma_addr(FLOPPY_DMA,virt_to_bus(addr));
223         set_dma_count(FLOPPY_DMA,size);
224         enable_dma(FLOPPY_DMA);
225         return 0;
226 }
227
228 struct fd_routine_l {
229         int (*_request_dma)(unsigned int dmanr, const char * device_id);
230         void (*_free_dma)(unsigned int dmanr);
231         int (*_get_dma_residue)(unsigned int dummy);
232         unsigned long (*_dma_mem_alloc) (unsigned long size);
233         int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
234 } fd_routine[] = {
235         {
236                 request_dma,
237                 free_dma,
238                 get_dma_residue,
239                 dma_mem_alloc,
240                 hard_dma_setup
241         },
242         {
243                 vdma_request_dma,
244                 vdma_nop,
245                 vdma_get_dma_residue,
246                 vdma_mem_alloc,
247                 vdma_dma_setup
248         }
249 };
250
251
252 static int FDC1 = 0x3f0;
253 static int FDC2 = -1;
254
255 #define FLOPPY0_TYPE    ((CMOS_READ(0x10) >> 4) & 15)
256 #define FLOPPY1_TYPE    (CMOS_READ(0x10) & 15)
257
258 #define N_FDC 1
259 #define N_DRIVE 8
260
261 #define FLOPPY_MOTOR_MASK 0xf0
262
263 #define AUTO_DMA
264
265
266 #endif /* __ASM_PARISC_FLOPPY_H */