This commit was generated by cvs2svn to compensate for changes in r925,
[linux-2.6.git] / include / asm-xen / asm-x86_64 / floppy.h
1 /*
2  * Architecture specific parts of the Floppy driver
3  *
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
6  * for more details.
7  *
8  * Copyright (C) 1995
9  *
10  * Modifications for Xen are Copyright (c) 2004, Keir Fraser.
11  */
12 #ifndef __ASM_XEN_X86_64_FLOPPY_H
13 #define __ASM_XEN_X86_64_FLOPPY_H
14
15 #include <linux/vmalloc.h>
16
17
18 /*
19  * The DMA channel used by the floppy controller cannot access data at
20  * addresses >= 16MB
21  *
22  * Went back to the 1MB limit, as some people had problems with the floppy
23  * driver otherwise. It doesn't matter much for performance anyway, as most
24  * floppy accesses go through the track buffer.
25  */
26 #define _CROSS_64KB(a,s,vdma) \
27 (!(vdma) && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
28
29 #include <linux/vmalloc.h>
30
31 /* XEN: Hit DMA paths on the head. This trick from asm-m68k/floppy.h. */
32 #include <asm/dma.h>
33 #undef MAX_DMA_ADDRESS
34 #define MAX_DMA_ADDRESS 0
35 #define CROSS_64KB(a,s) (0)
36
37 #define fd_inb(port)                    inb_p(port)
38 #define fd_outb(value,port)             outb_p(value,port)
39
40 #define fd_request_dma()        (0)
41 #define fd_free_dma()           ((void)0)
42 #define fd_enable_irq()         enable_irq(FLOPPY_IRQ)
43 #define fd_disable_irq()        disable_irq(FLOPPY_IRQ)
44 #define fd_free_irq()           free_irq(FLOPPY_IRQ, NULL)
45 #define fd_get_dma_residue()    vdma_get_dma_residue(FLOPPY_DMA)
46 #define fd_dma_mem_alloc(size)  vdma_mem_alloc(size)
47 #define fd_dma_mem_free(addr, size) vdma_mem_free(addr, size) 
48 #define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
49
50 static int virtual_dma_count;
51 static int virtual_dma_residue;
52 static char *virtual_dma_addr;
53 static int virtual_dma_mode;
54 static int doing_pdma;
55
56 static irqreturn_t floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
57 {
58         register unsigned char st;
59
60 #undef TRACE_FLPY_INT
61
62 #ifdef TRACE_FLPY_INT
63         static int calls=0;
64         static int bytes=0;
65         static int dma_wait=0;
66 #endif
67         if (!doing_pdma)
68                 return floppy_interrupt(irq, dev_id, regs);
69
70 #ifdef TRACE_FLPY_INT
71         if(!calls)
72                 bytes = virtual_dma_count;
73 #endif
74
75         {
76                 register int lcount;
77                 register char *lptr;
78
79                 st = 1;
80                 for(lcount=virtual_dma_count, lptr=virtual_dma_addr; 
81                     lcount; lcount--, lptr++) {
82                         st=inb(virtual_dma_port+4) & 0xa0 ;
83                         if(st != 0xa0) 
84                                 break;
85                         if(virtual_dma_mode)
86                                 outb_p(*lptr, virtual_dma_port+5);
87                         else
88                                 *lptr = inb_p(virtual_dma_port+5);
89                 }
90                 virtual_dma_count = lcount;
91                 virtual_dma_addr = lptr;
92                 st = inb(virtual_dma_port+4);
93         }
94
95 #ifdef TRACE_FLPY_INT
96         calls++;
97 #endif
98         if(st == 0x20)
99                 return IRQ_HANDLED;
100         if(!(st & 0x20)) {
101                 virtual_dma_residue += virtual_dma_count;
102                 virtual_dma_count=0;
103 #ifdef TRACE_FLPY_INT
104                 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n", 
105                        virtual_dma_count, virtual_dma_residue, calls, bytes,
106                        dma_wait);
107                 calls = 0;
108                 dma_wait=0;
109 #endif
110                 doing_pdma = 0;
111                 floppy_interrupt(irq, dev_id, regs);
112                 return IRQ_HANDLED;
113         }
114 #ifdef TRACE_FLPY_INT
115         if(!virtual_dma_count)
116                 dma_wait++;
117 #endif
118         return IRQ_HANDLED;
119 }
120
121 static void fd_disable_dma(void)
122 {
123         doing_pdma = 0;
124         virtual_dma_residue += virtual_dma_count;
125         virtual_dma_count=0;
126 }
127
128 static int vdma_get_dma_residue(unsigned int dummy)
129 {
130         return virtual_dma_count + virtual_dma_residue;
131 }
132
133
134 static int fd_request_irq(void)
135 {
136         return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
137                                            "floppy", NULL);
138 }
139
140
141 static unsigned long vdma_mem_alloc(unsigned long size)
142 {
143         return (unsigned long) vmalloc(size);
144
145 }
146
147 static void vdma_mem_free(unsigned long addr, unsigned long size)
148 {
149         vfree((void *)addr);
150 }
151
152 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
153 {
154         doing_pdma = 1;
155         virtual_dma_port = io;
156         virtual_dma_mode = (mode  == DMA_MODE_WRITE);
157         virtual_dma_addr = addr;
158         virtual_dma_count = size;
159         virtual_dma_residue = 0;
160         return 0;
161 }
162
163 /* XEN: This trick to force 'virtual DMA' is from include/asm-m68k/floppy.h. */
164 #define FDC1 xen_floppy_init()
165 static int FDC2 = -1;
166
167 static int xen_floppy_init(void)
168 {
169         use_virtual_dma = 1;
170         can_use_virtual_dma = 1;
171         return 0x340;
172 }
173
174 /*
175  * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
176  * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
177  * coincides with another rtc CMOS user.                Paul G.
178  */
179 #define FLOPPY0_TYPE    ({                              \
180         unsigned long flags;                            \
181         unsigned char val;                              \
182         spin_lock_irqsave(&rtc_lock, flags);            \
183         val = (CMOS_READ(0x10) >> 4) & 15;              \
184         spin_unlock_irqrestore(&rtc_lock, flags);       \
185         val;                                            \
186 })
187
188 #define FLOPPY1_TYPE    ({                              \
189         unsigned long flags;                            \
190         unsigned char val;                              \
191         spin_lock_irqsave(&rtc_lock, flags);            \
192         val = CMOS_READ(0x10) & 15;                     \
193         spin_unlock_irqrestore(&rtc_lock, flags);       \
194         val;                                            \
195 })
196
197 #define N_FDC 2
198 #define N_DRIVE 8
199
200 #define FLOPPY_MOTOR_MASK 0xf0
201
202 #define EXTRA_FLOPPY_PARAMS
203
204 #endif /* __ASM_XEN_X86_64_FLOPPY_H */