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_X86_FLOPPY_H
11 #define _ASM_X86_FLOPPY_H
13 #include <linux/vmalloc.h>
16 * The DMA channel used by the floppy controller cannot access data at
19 * Went back to the 1MB limit, as some people had problems with the floppy
20 * driver otherwise. It doesn't matter much for performance anyway, as most
21 * floppy accesses go through the track buffer.
23 #define _CROSS_64KB(a, s, vdma) \
25 ((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(base, reg) inb_p((base) + (reg))
35 #define fd_outb(value, base, reg) outb_p(value, (base) + (reg))
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)
66 return floppy_interrupt(irq, dev_id);
70 bytes = virtual_dma_count;
78 for (lcount = virtual_dma_count, lptr = virtual_dma_addr;
79 lcount; lcount--, lptr++) {
80 st = inb(virtual_dma_port + FD_STATUS);
81 st &= STATUS_DMA | STATUS_READY;
82 if (st != (STATUS_DMA | STATUS_READY))
85 outb_p(*lptr, virtual_dma_port + FD_DATA);
87 *lptr = inb_p(virtual_dma_port + FD_DATA);
89 virtual_dma_count = lcount;
90 virtual_dma_addr = lptr;
91 st = inb(virtual_dma_port + FD_STATUS);
99 if (!(st & STATUS_DMA)) {
100 virtual_dma_residue += virtual_dma_count;
101 virtual_dma_count = 0;
102 #ifdef TRACE_FLPY_INT
103 printk(KERN_DEBUG "count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
104 virtual_dma_count, virtual_dma_residue, calls, bytes,
110 floppy_interrupt(irq, dev_id);
113 #ifdef TRACE_FLPY_INT
114 if (!virtual_dma_count)
120 static void fd_disable_dma(void)
122 if (!(can_use_virtual_dma & 1))
123 disable_dma(FLOPPY_DMA);
125 virtual_dma_residue += virtual_dma_count;
126 virtual_dma_count = 0;
129 static int vdma_request_dma(unsigned int dmanr, const char *device_id)
134 static void vdma_nop(unsigned int dummy)
139 static int vdma_get_dma_residue(unsigned int dummy)
141 return virtual_dma_count + virtual_dma_residue;
145 static int fd_request_irq(void)
147 if (can_use_virtual_dma)
148 return request_irq(FLOPPY_IRQ, floppy_hardint,
151 return request_irq(FLOPPY_IRQ, floppy_interrupt,
155 static unsigned long dma_mem_alloc(unsigned long size)
157 return __get_dma_pages(GFP_KERNEL|__GFP_NORETRY, get_order(size));
161 static unsigned long vdma_mem_alloc(unsigned long size)
163 return (unsigned long)vmalloc(size);
167 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
169 static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
171 if ((unsigned long)addr >= (unsigned long)high_memory)
174 free_pages(addr, get_order(size));
177 #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
179 static void _fd_chose_dma_mode(char *addr, unsigned long size)
181 if (can_use_virtual_dma == 2) {
182 if ((unsigned long)addr >= (unsigned long)high_memory ||
183 isa_virt_to_bus(addr) >= 0x1000000 ||
184 _CROSS_64KB(addr, size, 0))
189 use_virtual_dma = can_use_virtual_dma & 1;
193 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
196 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
199 virtual_dma_port = io;
200 virtual_dma_mode = (mode == DMA_MODE_WRITE);
201 virtual_dma_addr = addr;
202 virtual_dma_count = size;
203 virtual_dma_residue = 0;
207 static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
209 #ifdef FLOPPY_SANITY_CHECK
210 if (CROSS_64KB(addr, size)) {
211 printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
215 /* actual, physical DMA */
217 clear_dma_ff(FLOPPY_DMA);
218 set_dma_mode(FLOPPY_DMA, mode);
219 set_dma_addr(FLOPPY_DMA, isa_virt_to_bus(addr));
220 set_dma_count(FLOPPY_DMA, size);
221 enable_dma(FLOPPY_DMA);
225 static struct fd_routine_l {
226 int (*_request_dma)(unsigned int dmanr, const char *device_id);
227 void (*_free_dma)(unsigned int dmanr);
228 int (*_get_dma_residue)(unsigned int dummy);
229 unsigned long (*_dma_mem_alloc)(unsigned long size);
230 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
233 ._request_dma = request_dma,
234 ._free_dma = free_dma,
235 ._get_dma_residue = get_dma_residue,
236 ._dma_mem_alloc = dma_mem_alloc,
237 ._dma_setup = hard_dma_setup
240 ._request_dma = vdma_request_dma,
241 ._free_dma = vdma_nop,
242 ._get_dma_residue = vdma_get_dma_residue,
243 ._dma_mem_alloc = vdma_mem_alloc,
244 ._dma_setup = vdma_dma_setup
249 static int FDC1 = 0x3f0;
250 static int FDC2 = -1;
253 * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
254 * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
255 * coincides with another rtc CMOS user. Paul G.
257 #define FLOPPY0_TYPE \
259 unsigned long flags; \
261 spin_lock_irqsave(&rtc_lock, flags); \
262 val = (CMOS_READ(0x10) >> 4) & 15; \
263 spin_unlock_irqrestore(&rtc_lock, flags); \
267 #define FLOPPY1_TYPE \
269 unsigned long flags; \
271 spin_lock_irqsave(&rtc_lock, flags); \
272 val = CMOS_READ(0x10) & 15; \
273 spin_unlock_irqrestore(&rtc_lock, flags); \
280 #define EXTRA_FLOPPY_PARAMS
282 #endif /* _ASM_X86_FLOPPY_H */