fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / asm-x86_64 / mach-xen / asm / 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 /* XEN: Hit DMA paths on the head. This trick from asm-m68k/floppy.h. */
30 #include <asm/dma.h>
31 #undef MAX_DMA_ADDRESS
32 #define MAX_DMA_ADDRESS 0
33 #define CROSS_64KB(a,s) (0)
34
35 #define fd_inb(port)                    inb_p(port)
36 #define fd_outb(value,port)             outb_p(value,port)
37
38 #define fd_request_dma()        (0)
39 #define fd_free_dma()           ((void)0)
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()    vdma_get_dma_residue(FLOPPY_DMA)
44 /*
45  * Do not use vmalloc/vfree: floppy_release_irq_and_dma() gets called from
46  * softirq context via motor_off_callback. A generic bug we happen to trigger.
47  */
48 #define fd_dma_mem_alloc(size)  __get_free_pages(GFP_KERNEL|__GFP_NORETRY, get_order(size))
49 #define fd_dma_mem_free(addr, size) free_pages(addr, get_order(size))
50 #define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
51
52 static int virtual_dma_count;
53 static int virtual_dma_residue;
54 static char *virtual_dma_addr;
55 static int virtual_dma_mode;
56 static int doing_pdma;
57
58 static irqreturn_t floppy_hardint(int irq, void *dev_id)
59 {
60         register unsigned char st;
61
62 #undef TRACE_FLPY_INT
63
64 #ifdef TRACE_FLPY_INT
65         static int calls=0;
66         static int bytes=0;
67         static int dma_wait=0;
68 #endif
69         if (!doing_pdma)
70                 return floppy_interrupt(irq, dev_id);
71
72 #ifdef TRACE_FLPY_INT
73         if(!calls)
74                 bytes = virtual_dma_count;
75 #endif
76
77         {
78                 register int lcount;
79                 register char *lptr;
80
81                 st = 1;
82                 for(lcount=virtual_dma_count, lptr=virtual_dma_addr; 
83                     lcount; lcount--, lptr++) {
84                         st=inb(virtual_dma_port+4) & 0xa0 ;
85                         if(st != 0xa0) 
86                                 break;
87                         if(virtual_dma_mode)
88                                 outb_p(*lptr, virtual_dma_port+5);
89                         else
90                                 *lptr = inb_p(virtual_dma_port+5);
91                 }
92                 virtual_dma_count = lcount;
93                 virtual_dma_addr = lptr;
94                 st = inb(virtual_dma_port+4);
95         }
96
97 #ifdef TRACE_FLPY_INT
98         calls++;
99 #endif
100         if(st == 0x20)
101                 return IRQ_HANDLED;
102         if(!(st & 0x20)) {
103                 virtual_dma_residue += virtual_dma_count;
104                 virtual_dma_count=0;
105 #ifdef TRACE_FLPY_INT
106                 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n", 
107                        virtual_dma_count, virtual_dma_residue, calls, bytes,
108                        dma_wait);
109                 calls = 0;
110                 dma_wait=0;
111 #endif
112                 doing_pdma = 0;
113                 floppy_interrupt(irq, dev_id);
114                 return IRQ_HANDLED;
115         }
116 #ifdef TRACE_FLPY_INT
117         if(!virtual_dma_count)
118                 dma_wait++;
119 #endif
120         return IRQ_HANDLED;
121 }
122
123 static void fd_disable_dma(void)
124 {
125         doing_pdma = 0;
126         virtual_dma_residue += virtual_dma_count;
127         virtual_dma_count=0;
128 }
129
130 static int vdma_get_dma_residue(unsigned int dummy)
131 {
132         return virtual_dma_count + virtual_dma_residue;
133 }
134
135
136 static int fd_request_irq(void)
137 {
138         return request_irq(FLOPPY_IRQ, floppy_hardint,
139                            IRQF_DISABLED, "floppy", NULL);
140 }
141
142 #if 0
143 static unsigned long vdma_mem_alloc(unsigned long size)
144 {
145         return (unsigned long) vmalloc(size);
146
147 }
148
149 static void vdma_mem_free(unsigned long addr, unsigned long size)
150 {
151         vfree((void *)addr);
152 }
153 #endif
154
155 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
156 {
157         doing_pdma = 1;
158         virtual_dma_port = io;
159         virtual_dma_mode = (mode  == DMA_MODE_WRITE);
160         virtual_dma_addr = addr;
161         virtual_dma_count = size;
162         virtual_dma_residue = 0;
163         return 0;
164 }
165
166 /* XEN: This trick to force 'virtual DMA' is from include/asm-m68k/floppy.h. */
167 #define FDC1 xen_floppy_init()
168 static int FDC2 = -1;
169
170 static int xen_floppy_init(void)
171 {
172         use_virtual_dma = 1;
173         can_use_virtual_dma = 1;
174         return 0x3f0;
175 }
176
177 /*
178  * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
179  * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
180  * coincides with another rtc CMOS user.                Paul G.
181  */
182 #define FLOPPY0_TYPE    ({                              \
183         unsigned long flags;                            \
184         unsigned char val;                              \
185         spin_lock_irqsave(&rtc_lock, flags);            \
186         val = (CMOS_READ(0x10) >> 4) & 15;              \
187         spin_unlock_irqrestore(&rtc_lock, flags);       \
188         val;                                            \
189 })
190
191 #define FLOPPY1_TYPE    ({                              \
192         unsigned long flags;                            \
193         unsigned char val;                              \
194         spin_lock_irqsave(&rtc_lock, flags);            \
195         val = CMOS_READ(0x10) & 15;                     \
196         spin_unlock_irqrestore(&rtc_lock, flags);       \
197         val;                                            \
198 })
199
200 #define N_FDC 2
201 #define N_DRIVE 8
202
203 #define FLOPPY_MOTOR_MASK 0xf0
204
205 #define EXTRA_FLOPPY_PARAMS
206
207 #endif /* __ASM_XEN_X86_64_FLOPPY_H */