2 * Architecture specific parts of the Floppy driver
3 * include/asm-i386/floppy.h
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
11 #ifndef __ASM_SH_FLOPPY_H
12 #define __ASM_SH_FLOPPY_H
14 #include <linux/vmalloc.h>
18 * The DMA channel used by the floppy controller cannot access data at
21 * Went back to the 1MB limit, as some people had problems with the floppy
22 * driver otherwise. It doesn't matter much for performance anyway, as most
23 * floppy accesses go through the track buffer.
25 #define _CROSS_64KB(a,s,vdma) \
26 (!vdma && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
28 #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
31 #define SW fd_routine[use_virtual_dma&1]
32 #define CSW fd_routine[can_use_virtual_dma & 1]
35 #define fd_inb(port) inb_p(port)
36 #define fd_outb(value,port) outb_p(value,port)
38 #define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
39 #define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
40 #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
41 #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
42 #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
43 #define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
44 #define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
45 #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
47 #define FLOPPY_CAN_FALLBACK_ON_NODMA
49 static int virtual_dma_count
;
50 static int virtual_dma_residue
;
51 static char *virtual_dma_addr
;
52 static int virtual_dma_mode
;
53 static int doing_pdma
;
55 static void floppy_hardint(int irq
, void *dev_id
, struct pt_regs
* regs
)
57 register unsigned char st
;
64 static int dma_wait
=0;
67 floppy_interrupt(irq
, dev_id
, regs
);
73 bytes
= virtual_dma_count
;
81 for(lcount
=virtual_dma_count
, lptr
=virtual_dma_addr
;
82 lcount
; lcount
--, lptr
++) {
83 st
=inb(virtual_dma_port
+4) & 0xa0 ;
87 outb_p(*lptr
, virtual_dma_port
+5);
89 *lptr
= inb_p(virtual_dma_port
+5);
91 virtual_dma_count
= lcount
;
92 virtual_dma_addr
= lptr
;
93 st
= inb(virtual_dma_port
+4);
102 virtual_dma_residue
+= virtual_dma_count
;
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
,
112 floppy_interrupt(irq
, dev_id
, regs
);
115 #ifdef TRACE_FLPY_INT
116 if(!virtual_dma_count
)
121 static void fd_disable_dma(void)
123 if(! (can_use_virtual_dma
& 1))
124 disable_dma(FLOPPY_DMA
);
126 virtual_dma_residue
+= virtual_dma_count
;
130 static int vdma_request_dma(unsigned int dmanr
, const char * device_id
)
135 static void vdma_nop(unsigned int dummy
)
140 static int vdma_get_dma_residue(unsigned int dummy
)
142 return virtual_dma_count
+ virtual_dma_residue
;
146 static int fd_request_irq(void)
148 if(can_use_virtual_dma
)
149 return request_irq(FLOPPY_IRQ
, floppy_hardint
,SA_INTERRUPT
,
152 return request_irq(FLOPPY_IRQ
, floppy_interrupt
,
153 SA_INTERRUPT
|SA_SAMPLE_RANDOM
,
158 static unsigned long dma_mem_alloc(unsigned long size
)
160 return __get_dma_pages(GFP_KERNEL
,get_order(size
));
164 static unsigned long vdma_mem_alloc(unsigned long size
)
166 return (unsigned long) vmalloc(size
);
170 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
172 static void _fd_dma_mem_free(unsigned long addr
, unsigned long size
)
174 if((unsigned int) addr
>= (unsigned int) high_memory
)
175 return vfree((void *)addr
);
177 free_pages(addr
, get_order(size
));
180 #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
182 static void _fd_chose_dma_mode(char *addr
, unsigned long size
)
184 if(can_use_virtual_dma
== 2) {
185 if((unsigned int) addr
>= (unsigned int) high_memory
||
186 virt_to_bus(addr
) >= 0x10000000)
191 use_virtual_dma
= can_use_virtual_dma
& 1;
195 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
198 static int vdma_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
201 virtual_dma_port
= io
;
202 virtual_dma_mode
= (mode
== DMA_MODE_WRITE
);
203 virtual_dma_addr
= addr
;
204 virtual_dma_count
= size
;
205 virtual_dma_residue
= 0;
209 static int hard_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
211 #ifdef FLOPPY_SANITY_CHECK
212 if (CROSS_64KB(addr
, size
)) {
213 printk("DMA crossing 64-K boundary %p-%p\n", addr
, addr
+size
);
218 dma_cache_wback_inv(addr
, size
);
220 /* actual, physical DMA */
222 clear_dma_ff(FLOPPY_DMA
);
223 set_dma_mode(FLOPPY_DMA
,mode
);
224 set_dma_addr(FLOPPY_DMA
,virt_to_bus(addr
));
225 set_dma_count(FLOPPY_DMA
,size
);
226 enable_dma(FLOPPY_DMA
);
230 static struct fd_routine_l
{
231 int (*_request_dma
)(unsigned int dmanr
, const char * device_id
);
232 void (*_free_dma
)(unsigned int dmanr
);
233 int (*_get_dma_residue
)(unsigned int dummy
);
234 unsigned long (*_dma_mem_alloc
) (unsigned long size
);
235 int (*_dma_setup
)(char *addr
, unsigned long size
, int mode
, int io
);
247 vdma_get_dma_residue
,
254 static int FDC1
= 0x3f0;
255 static int FDC2
= -1;
258 * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
259 * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
260 * coincides with another rtc CMOS user. Paul G.
262 #define FLOPPY0_TYPE (4)
263 #define FLOPPY1_TYPE (0)
268 #define FLOPPY_MOTOR_MASK 0xf0
272 #define EXTRA_FLOPPY_PARAMS
274 #endif /* __ASM_SH_FLOPPY_H */