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 * Modifications for Xen are Copyright (c) 2004, Keir Fraser.
12 #ifndef __ASM_XEN_X86_64_FLOPPY_H
13 #define __ASM_XEN_X86_64_FLOPPY_H
15 #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 /* XEN: Hit DMA paths on the head. This trick from asm-m68k/floppy.h. */
30 #undef MAX_DMA_ADDRESS
31 #define MAX_DMA_ADDRESS 0
32 #define CROSS_64KB(a,s) (0)
34 #define fd_inb(port) inb_p(port)
35 #define fd_outb(value,port) outb_p(value,port)
37 #define fd_request_dma() (0)
38 #define fd_free_dma() ((void)0)
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() vdma_get_dma_residue(FLOPPY_DMA)
44 * Do not use vmalloc/vfree: floppy_release_irq_and_dma() gets called from
45 * softirq context via motor_off_callback. A generic bug we happen to trigger.
47 #define fd_dma_mem_alloc(size) __get_free_pages(GFP_KERNEL|__GFP_NORETRY, get_order(size))
48 #define fd_dma_mem_free(addr, size) free_pages(addr, get_order(size))
49 #define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
51 static int virtual_dma_count;
52 static int virtual_dma_residue;
53 static char *virtual_dma_addr;
54 static int virtual_dma_mode;
55 static int doing_pdma;
57 static irqreturn_t floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
59 register unsigned char st;
66 static int dma_wait=0;
69 return 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)
122 static void fd_disable_dma(void)
125 virtual_dma_residue += virtual_dma_count;
129 static int vdma_get_dma_residue(unsigned int dummy)
131 return virtual_dma_count + virtual_dma_residue;
135 static int fd_request_irq(void)
137 return request_irq(FLOPPY_IRQ, floppy_hardint,
138 IRQF_DISABLED, "floppy", NULL);
142 static unsigned long vdma_mem_alloc(unsigned long size)
144 return (unsigned long) vmalloc(size);
148 static void vdma_mem_free(unsigned long addr, unsigned long size)
154 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
157 virtual_dma_port = io;
158 virtual_dma_mode = (mode == DMA_MODE_WRITE);
159 virtual_dma_addr = addr;
160 virtual_dma_count = size;
161 virtual_dma_residue = 0;
165 /* XEN: This trick to force 'virtual DMA' is from include/asm-m68k/floppy.h. */
166 #define FDC1 xen_floppy_init()
167 static int FDC2 = -1;
169 static int xen_floppy_init(void)
172 can_use_virtual_dma = 1;
177 * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
178 * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
179 * coincides with another rtc CMOS user. Paul G.
181 #define FLOPPY0_TYPE ({ \
182 unsigned long flags; \
184 spin_lock_irqsave(&rtc_lock, flags); \
185 val = (CMOS_READ(0x10) >> 4) & 15; \
186 spin_unlock_irqrestore(&rtc_lock, flags); \
190 #define FLOPPY1_TYPE ({ \
191 unsigned long flags; \
193 spin_lock_irqsave(&rtc_lock, flags); \
194 val = CMOS_READ(0x10) & 15; \
195 spin_unlock_irqrestore(&rtc_lock, flags); \
202 #define FLOPPY_MOTOR_MASK 0xf0
204 #define EXTRA_FLOPPY_PARAMS
206 #endif /* __ASM_XEN_X86_64_FLOPPY_H */