aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-i386/floppy.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-i386/floppy.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-i386/floppy.h')
-rw-r--r--include/asm-i386/floppy.h319
1 files changed, 319 insertions, 0 deletions
diff --git a/include/asm-i386/floppy.h b/include/asm-i386/floppy.h
new file mode 100644
index 000000000000..f4782284807a
--- /dev/null
+++ b/include/asm-i386/floppy.h
@@ -0,0 +1,319 @@
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_I386_FLOPPY_H
11#define __ASM_I386_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(value,port) outb_p(value,port)
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
48static int virtual_dma_count;
49static int virtual_dma_residue;
50static char *virtual_dma_addr;
51static int virtual_dma_mode;
52static int doing_pdma;
53
54static irqreturn_t 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 return floppy_interrupt(irq, dev_id, regs);
68
69#ifdef TRACE_FLPY_INT
70 if(!calls)
71 bytes = virtual_dma_count;
72#endif
73
74#ifndef NO_FLOPPY_ASSEMBLER
75 __asm__ (
76 "testl %1,%1"
77 "je 3f"
78"1: inb %w4,%b0"
79 "andb $160,%b0"
80 "cmpb $160,%b0"
81 "jne 2f"
82 "incw %w4"
83 "testl %3,%3"
84 "jne 4f"
85 "inb %w4,%b0"
86 "movb %0,(%2)"
87 "jmp 5f"
88"4: movb (%2),%0"
89 "outb %b0,%w4"
90"5: decw %w4"
91 "outb %0,$0x80"
92 "decl %1"
93 "incl %2"
94 "testl %1,%1"
95 "jne 1b"
96"3: inb %w4,%b0"
97"2: "
98 : "=a" ((char) st),
99 "=c" ((long) virtual_dma_count),
100 "=S" ((long) virtual_dma_addr)
101 : "b" ((long) virtual_dma_mode),
102 "d" ((short) virtual_dma_port+4),
103 "1" ((long) virtual_dma_count),
104 "2" ((long) virtual_dma_addr));
105#else
106 {
107 register int lcount;
108 register char *lptr;
109
110 st = 1;
111 for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
112 lcount; lcount--, lptr++) {
113 st=inb(virtual_dma_port+4) & 0xa0 ;
114 if(st != 0xa0)
115 break;
116 if(virtual_dma_mode)
117 outb_p(*lptr, virtual_dma_port+5);
118 else
119 *lptr = inb_p(virtual_dma_port+5);
120 }
121 virtual_dma_count = lcount;
122 virtual_dma_addr = lptr;
123 st = inb(virtual_dma_port+4);
124 }
125#endif
126
127#ifdef TRACE_FLPY_INT
128 calls++;
129#endif
130 if(st == 0x20)
131 return IRQ_HANDLED;
132 if(!(st & 0x20)) {
133 virtual_dma_residue += virtual_dma_count;
134 virtual_dma_count=0;
135#ifdef TRACE_FLPY_INT
136 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
137 virtual_dma_count, virtual_dma_residue, calls, bytes,
138 dma_wait);
139 calls = 0;
140 dma_wait=0;
141#endif
142 doing_pdma = 0;
143 floppy_interrupt(irq, dev_id, regs);
144 return IRQ_HANDLED;
145 }
146#ifdef TRACE_FLPY_INT
147 if(!virtual_dma_count)
148 dma_wait++;
149#endif
150 return IRQ_HANDLED;
151}
152
153static void fd_disable_dma(void)
154{
155 if(! (can_use_virtual_dma & 1))
156 disable_dma(FLOPPY_DMA);
157 doing_pdma = 0;
158 virtual_dma_residue += virtual_dma_count;
159 virtual_dma_count=0;
160}
161
162static int vdma_request_dma(unsigned int dmanr, const char * device_id)
163{
164 return 0;
165}
166
167static void vdma_nop(unsigned int dummy)
168{
169}
170
171
172static int vdma_get_dma_residue(unsigned int dummy)
173{
174 return virtual_dma_count + virtual_dma_residue;
175}
176
177
178static int fd_request_irq(void)
179{
180 if(can_use_virtual_dma)
181 return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
182 "floppy", NULL);
183 else
184 return request_irq(FLOPPY_IRQ, floppy_interrupt,
185 SA_INTERRUPT|SA_SAMPLE_RANDOM,
186 "floppy", NULL);
187
188}
189
190static unsigned long dma_mem_alloc(unsigned long size)
191{
192 return __get_dma_pages(GFP_KERNEL,get_order(size));
193}
194
195
196static unsigned long vdma_mem_alloc(unsigned long size)
197{
198 return (unsigned long) vmalloc(size);
199
200}
201
202#define nodma_mem_alloc(size) vdma_mem_alloc(size)
203
204static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
205{
206 if((unsigned int) addr >= (unsigned int) high_memory)
207 vfree((void *)addr);
208 else
209 free_pages(addr, get_order(size));
210}
211
212#define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
213
214static void _fd_chose_dma_mode(char *addr, unsigned long size)
215{
216 if(can_use_virtual_dma == 2) {
217 if((unsigned int) addr >= (unsigned int) high_memory ||
218 isa_virt_to_bus(addr) >= 0x1000000 ||
219 _CROSS_64KB(addr, size, 0))
220 use_virtual_dma = 1;
221 else
222 use_virtual_dma = 0;
223 } else {
224 use_virtual_dma = can_use_virtual_dma & 1;
225 }
226}
227
228#define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
229
230
231static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
232{
233 doing_pdma = 1;
234 virtual_dma_port = io;
235 virtual_dma_mode = (mode == DMA_MODE_WRITE);
236 virtual_dma_addr = addr;
237 virtual_dma_count = size;
238 virtual_dma_residue = 0;
239 return 0;
240}
241
242static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
243{
244#ifdef FLOPPY_SANITY_CHECK
245 if (CROSS_64KB(addr, size)) {
246 printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
247 return -1;
248 }
249#endif
250 /* actual, physical DMA */
251 doing_pdma = 0;
252 clear_dma_ff(FLOPPY_DMA);
253 set_dma_mode(FLOPPY_DMA,mode);
254 set_dma_addr(FLOPPY_DMA,isa_virt_to_bus(addr));
255 set_dma_count(FLOPPY_DMA,size);
256 enable_dma(FLOPPY_DMA);
257 return 0;
258}
259
260struct fd_routine_l {
261 int (*_request_dma)(unsigned int dmanr, const char * device_id);
262 void (*_free_dma)(unsigned int dmanr);
263 int (*_get_dma_residue)(unsigned int dummy);
264 unsigned long (*_dma_mem_alloc) (unsigned long size);
265 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
266} fd_routine[] = {
267 {
268 request_dma,
269 free_dma,
270 get_dma_residue,
271 dma_mem_alloc,
272 hard_dma_setup
273 },
274 {
275 vdma_request_dma,
276 vdma_nop,
277 vdma_get_dma_residue,
278 vdma_mem_alloc,
279 vdma_dma_setup
280 }
281};
282
283
284static int FDC1 = 0x3f0;
285static int FDC2 = -1;
286
287/*
288 * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
289 * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
290 * coincides with another rtc CMOS user. Paul G.
291 */
292#define FLOPPY0_TYPE ({ \
293 unsigned long flags; \
294 unsigned char val; \
295 spin_lock_irqsave(&rtc_lock, flags); \
296 val = (CMOS_READ(0x10) >> 4) & 15; \
297 spin_unlock_irqrestore(&rtc_lock, flags); \
298 val; \
299})
300
301#define FLOPPY1_TYPE ({ \
302 unsigned long flags; \
303 unsigned char val; \
304 spin_lock_irqsave(&rtc_lock, flags); \
305 val = CMOS_READ(0x10) & 15; \
306 spin_unlock_irqrestore(&rtc_lock, flags); \
307 val; \
308})
309
310#define N_FDC 2
311#define N_DRIVE 8
312
313#define FLOPPY_MOTOR_MASK 0xf0
314
315#define AUTO_DMA
316
317#define EXTRA_FLOPPY_PARAMS
318
319#endif /* __ASM_I386_FLOPPY_H */