2 * Architecture specific parts of the Floppy driver
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
10 #ifndef __ASM_I386_FLOPPY_H
11 #define __ASM_I386_FLOPPY_H
13 #include <linux/vmalloc.h>
17 * The DMA channel used by the floppy controller cannot access data at
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.
24 #define _CROSS_64KB(a,s,vdma) \
25 (!(vdma) && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
27 #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
30 #define SW fd_routine[use_virtual_dma&1]
31 #define CSW fd_routine[can_use_virtual_dma & 1]
34 #define fd_inb(port) inb_p(port)
35 #define fd_outb(value,port) outb_p(value,port)
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)
46 #define FLOPPY_CAN_FALLBACK_ON_NODMA
48 static int virtual_dma_count
;
49 static int virtual_dma_residue
;
50 static char *virtual_dma_addr
;
51 static int virtual_dma_mode
;
52 static int doing_pdma
;
54 static irqreturn_t
floppy_hardint(int irq
, void *dev_id
, struct pt_regs
* regs
)
56 register unsigned char st
;
59 #define NO_FLOPPY_ASSEMBLER
64 static int dma_wait
=0;
67 return floppy_interrupt(irq
, dev_id
, regs
);
71 bytes
= virtual_dma_count
;
74 #ifndef NO_FLOPPY_ASSEMBLER
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
));
111 for(lcount
=virtual_dma_count
, lptr
=virtual_dma_addr
;
112 lcount
; lcount
--, lptr
++) {
113 st
=inb(virtual_dma_port
+4) & 0xa0 ;
117 outb_p(*lptr
, virtual_dma_port
+5);
119 *lptr
= inb_p(virtual_dma_port
+5);
121 virtual_dma_count
= lcount
;
122 virtual_dma_addr
= lptr
;
123 st
= inb(virtual_dma_port
+4);
127 #ifdef TRACE_FLPY_INT
133 virtual_dma_residue
+= virtual_dma_count
;
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
,
143 floppy_interrupt(irq
, dev_id
, regs
);
146 #ifdef TRACE_FLPY_INT
147 if(!virtual_dma_count
)
153 static void fd_disable_dma(void)
155 if(! (can_use_virtual_dma
& 1))
156 disable_dma(FLOPPY_DMA
);
158 virtual_dma_residue
+= virtual_dma_count
;
162 static int vdma_request_dma(unsigned int dmanr
, const char * device_id
)
167 static void vdma_nop(unsigned int dummy
)
172 static int vdma_get_dma_residue(unsigned int dummy
)
174 return virtual_dma_count
+ virtual_dma_residue
;
178 static int fd_request_irq(void)
180 if(can_use_virtual_dma
)
181 return request_irq(FLOPPY_IRQ
, floppy_hardint
,SA_INTERRUPT
,
184 return request_irq(FLOPPY_IRQ
, floppy_interrupt
,
185 SA_INTERRUPT
|SA_SAMPLE_RANDOM
,
190 static unsigned long dma_mem_alloc(unsigned long size
)
192 return __get_dma_pages(GFP_KERNEL
,get_order(size
));
196 static unsigned long vdma_mem_alloc(unsigned long size
)
198 return (unsigned long) vmalloc(size
);
202 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
204 static void _fd_dma_mem_free(unsigned long addr
, unsigned long size
)
206 if((unsigned int) addr
>= (unsigned int) high_memory
)
209 free_pages(addr
, get_order(size
));
212 #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
214 static void _fd_chose_dma_mode(char *addr
, unsigned long size
)
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))
224 use_virtual_dma
= can_use_virtual_dma
& 1;
228 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
231 static int vdma_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
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;
242 static int hard_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
244 #ifdef FLOPPY_SANITY_CHECK
245 if (CROSS_64KB(addr
, size
)) {
246 printk("DMA crossing 64-K boundary %p-%p\n", addr
, addr
+size
);
250 /* actual, physical DMA */
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
);
260 static struct 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
);
277 vdma_get_dma_residue
,
284 static int FDC1
= 0x3f0;
285 static int FDC2
= -1;
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.
292 #define FLOPPY0_TYPE ({ \
293 unsigned long flags; \
295 spin_lock_irqsave(&rtc_lock, flags); \
296 val = (CMOS_READ(0x10) >> 4) & 15; \
297 spin_unlock_irqrestore(&rtc_lock, flags); \
301 #define FLOPPY1_TYPE ({ \
302 unsigned long flags; \
304 spin_lock_irqsave(&rtc_lock, flags); \
305 val = CMOS_READ(0x10) & 15; \
306 spin_unlock_irqrestore(&rtc_lock, flags); \
313 #define FLOPPY_MOTOR_MASK 0xf0
317 #define EXTRA_FLOPPY_PARAMS
319 #endif /* __ASM_I386_FLOPPY_H */