1 /* Architecture specific parts of the Floppy driver
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
4 * Copyright (C) 2000 Matthew Wilcox (willy a debian . org)
5 * Copyright (C) 2000 Dave Kennedy
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __ASM_PARISC_FLOPPY_H
22 #define __ASM_PARISC_FLOPPY_H
24 #include <linux/vmalloc.h>
28 * The DMA channel used by the floppy controller cannot access data at
31 * Went back to the 1MB limit, as some people had problems with the floppy
32 * driver otherwise. It doesn't matter much for performance anyway, as most
33 * floppy accesses go through the track buffer.
35 #define _CROSS_64KB(a,s,vdma) \
36 (!vdma && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
38 #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
41 #define SW fd_routine[use_virtual_dma&1]
42 #define CSW fd_routine[can_use_virtual_dma & 1]
45 #define fd_inb(port) readb(port)
46 #define fd_outb(value, port) writeb(value, port)
48 #define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
49 #define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
50 #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
51 #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
52 #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
53 #define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
54 #define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
55 #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
57 #define FLOPPY_CAN_FALLBACK_ON_NODMA
59 static int virtual_dma_count=0;
60 static int virtual_dma_residue=0;
61 static char *virtual_dma_addr=0;
62 static int virtual_dma_mode=0;
63 static int doing_pdma=0;
65 static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
67 register unsigned char st;
74 static int dma_wait=0;
77 floppy_interrupt(irq, dev_id, regs);
83 bytes = virtual_dma_count;
88 register char *lptr = virtual_dma_addr;
90 for (lcount = virtual_dma_count; lcount; lcount--) {
91 st = fd_inb(virtual_dma_port+4) & 0xa0 ;
94 if (virtual_dma_mode) {
95 fd_outb(*lptr, virtual_dma_port+5);
97 *lptr = fd_inb(virtual_dma_port+5);
101 virtual_dma_count = lcount;
102 virtual_dma_addr = lptr;
103 st = fd_inb(virtual_dma_port+4);
106 #ifdef TRACE_FLPY_INT
112 virtual_dma_residue += virtual_dma_count;
113 virtual_dma_count = 0;
114 #ifdef TRACE_FLPY_INT
115 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
116 virtual_dma_count, virtual_dma_residue, calls, bytes,
122 floppy_interrupt(irq, dev_id, regs);
125 #ifdef TRACE_FLPY_INT
126 if (!virtual_dma_count)
131 static void fd_disable_dma(void)
133 if(! (can_use_virtual_dma & 1))
134 disable_dma(FLOPPY_DMA);
136 virtual_dma_residue += virtual_dma_count;
140 static int vdma_request_dma(unsigned int dmanr, const char * device_id)
145 static void vdma_nop(unsigned int dummy)
150 static int vdma_get_dma_residue(unsigned int dummy)
152 return virtual_dma_count + virtual_dma_residue;
156 static int fd_request_irq(void)
158 if(can_use_virtual_dma)
159 return request_irq(FLOPPY_IRQ, floppy_hardint,
160 IRQF_DISABLED, "floppy", NULL);
162 return request_irq(FLOPPY_IRQ, floppy_interrupt,
163 IRQF_DISABLED, "floppy", NULL);
166 static unsigned long dma_mem_alloc(unsigned long size)
168 return __get_dma_pages(GFP_KERNEL, get_order(size));
172 static unsigned long vdma_mem_alloc(unsigned long size)
174 return (unsigned long) vmalloc(size);
178 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
180 static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
182 if((unsigned int) addr >= (unsigned int) high_memory)
183 return vfree((void *)addr);
185 free_pages(addr, get_order(size));
188 #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
190 static void _fd_chose_dma_mode(char *addr, unsigned long size)
192 if(can_use_virtual_dma == 2) {
193 if((unsigned int) addr >= (unsigned int) high_memory ||
194 virt_to_bus(addr) >= 0x1000000 ||
195 _CROSS_64KB(addr, size, 0))
200 use_virtual_dma = can_use_virtual_dma & 1;
204 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
207 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
210 virtual_dma_port = io;
211 virtual_dma_mode = (mode == DMA_MODE_WRITE);
212 virtual_dma_addr = addr;
213 virtual_dma_count = size;
214 virtual_dma_residue = 0;
218 static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
220 #ifdef FLOPPY_SANITY_CHECK
221 if (CROSS_64KB(addr, size)) {
222 printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
226 /* actual, physical DMA */
228 clear_dma_ff(FLOPPY_DMA);
229 set_dma_mode(FLOPPY_DMA,mode);
230 set_dma_addr(FLOPPY_DMA,virt_to_bus(addr));
231 set_dma_count(FLOPPY_DMA,size);
232 enable_dma(FLOPPY_DMA);
236 static struct fd_routine_l {
237 int (*_request_dma)(unsigned int dmanr, const char * device_id);
238 void (*_free_dma)(unsigned int dmanr);
239 int (*_get_dma_residue)(unsigned int dummy);
240 unsigned long (*_dma_mem_alloc) (unsigned long size);
241 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
253 vdma_get_dma_residue,
260 static int FDC1 = 0x3f0; /* Lies. Floppy controller is memory mapped, not io mapped */
261 static int FDC2 = -1;
263 #define FLOPPY0_TYPE 0
264 #define FLOPPY1_TYPE 0
269 #define EXTRA_FLOPPY_PARAMS
271 #endif /* __ASM_PARISC_FLOPPY_H */