Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Architecture specific parts of the Floppy driver
0003  *
0004  * This file is subject to the terms and conditions of the GNU General Public
0005  * License.  See the file "COPYING" in the main directory of this archive
0006  * for more details.
0007  *
0008  * Copyright (C) 1995
0009  */
0010 #ifndef _ASM_X86_FLOPPY_H
0011 #define _ASM_X86_FLOPPY_H
0012 
0013 #include <linux/vmalloc.h>
0014 
0015 /*
0016  * The DMA channel used by the floppy controller cannot access data at
0017  * addresses >= 16MB
0018  *
0019  * Went back to the 1MB limit, as some people had problems with the floppy
0020  * driver otherwise. It doesn't matter much for performance anyway, as most
0021  * floppy accesses go through the track buffer.
0022  */
0023 #define _CROSS_64KB(a, s, vdma)                     \
0024     (!(vdma) &&                         \
0025      ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
0026 
0027 #define CROSS_64KB(a, s) _CROSS_64KB(a, s, use_virtual_dma & 1)
0028 
0029 
0030 #define SW fd_routine[use_virtual_dma & 1]
0031 #define CSW fd_routine[can_use_virtual_dma & 1]
0032 
0033 
0034 #define fd_inb(base, reg)       inb_p((base) + (reg))
0035 #define fd_outb(value, base, reg)   outb_p(value, (base) + (reg))
0036 
0037 #define fd_request_dma()    CSW._request_dma(FLOPPY_DMA, "floppy")
0038 #define fd_free_dma()       CSW._free_dma(FLOPPY_DMA)
0039 #define fd_enable_irq()     enable_irq(FLOPPY_IRQ)
0040 #define fd_disable_irq()    disable_irq(FLOPPY_IRQ)
0041 #define fd_free_irq()       free_irq(FLOPPY_IRQ, NULL)
0042 #define fd_get_dma_residue()    SW._get_dma_residue(FLOPPY_DMA)
0043 #define fd_dma_mem_alloc(size)  SW._dma_mem_alloc(size)
0044 #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
0045 
0046 #define FLOPPY_CAN_FALLBACK_ON_NODMA
0047 
0048 static int virtual_dma_count;
0049 static int virtual_dma_residue;
0050 static char *virtual_dma_addr;
0051 static int virtual_dma_mode;
0052 static int doing_pdma;
0053 
0054 static irqreturn_t floppy_hardint(int irq, void *dev_id)
0055 {
0056     unsigned char st;
0057 
0058 #undef TRACE_FLPY_INT
0059 
0060 #ifdef TRACE_FLPY_INT
0061     static int calls;
0062     static int bytes;
0063     static int dma_wait;
0064 #endif
0065     if (!doing_pdma)
0066         return floppy_interrupt(irq, dev_id);
0067 
0068 #ifdef TRACE_FLPY_INT
0069     if (!calls)
0070         bytes = virtual_dma_count;
0071 #endif
0072 
0073     {
0074         int lcount;
0075         char *lptr;
0076 
0077         for (lcount = virtual_dma_count, lptr = virtual_dma_addr;
0078              lcount; lcount--, lptr++) {
0079             st = inb(virtual_dma_port + FD_STATUS);
0080             st &= STATUS_DMA | STATUS_READY;
0081             if (st != (STATUS_DMA | STATUS_READY))
0082                 break;
0083             if (virtual_dma_mode)
0084                 outb_p(*lptr, virtual_dma_port + FD_DATA);
0085             else
0086                 *lptr = inb_p(virtual_dma_port + FD_DATA);
0087         }
0088         virtual_dma_count = lcount;
0089         virtual_dma_addr = lptr;
0090         st = inb(virtual_dma_port + FD_STATUS);
0091     }
0092 
0093 #ifdef TRACE_FLPY_INT
0094     calls++;
0095 #endif
0096     if (st == STATUS_DMA)
0097         return IRQ_HANDLED;
0098     if (!(st & STATUS_DMA)) {
0099         virtual_dma_residue += virtual_dma_count;
0100         virtual_dma_count = 0;
0101 #ifdef TRACE_FLPY_INT
0102         printk(KERN_DEBUG "count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
0103                virtual_dma_count, virtual_dma_residue, calls, bytes,
0104                dma_wait);
0105         calls = 0;
0106         dma_wait = 0;
0107 #endif
0108         doing_pdma = 0;
0109         floppy_interrupt(irq, dev_id);
0110         return IRQ_HANDLED;
0111     }
0112 #ifdef TRACE_FLPY_INT
0113     if (!virtual_dma_count)
0114         dma_wait++;
0115 #endif
0116     return IRQ_HANDLED;
0117 }
0118 
0119 static void fd_disable_dma(void)
0120 {
0121     if (!(can_use_virtual_dma & 1))
0122         disable_dma(FLOPPY_DMA);
0123     doing_pdma = 0;
0124     virtual_dma_residue += virtual_dma_count;
0125     virtual_dma_count = 0;
0126 }
0127 
0128 static int vdma_request_dma(unsigned int dmanr, const char *device_id)
0129 {
0130     return 0;
0131 }
0132 
0133 static void vdma_nop(unsigned int dummy)
0134 {
0135 }
0136 
0137 
0138 static int vdma_get_dma_residue(unsigned int dummy)
0139 {
0140     return virtual_dma_count + virtual_dma_residue;
0141 }
0142 
0143 
0144 static int fd_request_irq(void)
0145 {
0146     if (can_use_virtual_dma)
0147         return request_irq(FLOPPY_IRQ, floppy_hardint,
0148                    0, "floppy", NULL);
0149     else
0150         return request_irq(FLOPPY_IRQ, floppy_interrupt,
0151                    0, "floppy", NULL);
0152 }
0153 
0154 static unsigned long dma_mem_alloc(unsigned long size)
0155 {
0156     return __get_dma_pages(GFP_KERNEL|__GFP_NORETRY, get_order(size));
0157 }
0158 
0159 
0160 static unsigned long vdma_mem_alloc(unsigned long size)
0161 {
0162     return (unsigned long)vmalloc(size);
0163 
0164 }
0165 
0166 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
0167 
0168 static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
0169 {
0170     if ((unsigned long)addr >= (unsigned long)high_memory)
0171         vfree((void *)addr);
0172     else
0173         free_pages(addr, get_order(size));
0174 }
0175 
0176 #define fd_dma_mem_free(addr, size)  _fd_dma_mem_free(addr, size)
0177 
0178 static void _fd_chose_dma_mode(char *addr, unsigned long size)
0179 {
0180     if (can_use_virtual_dma == 2) {
0181         if ((unsigned long)addr >= (unsigned long)high_memory ||
0182             isa_virt_to_bus(addr) >= 0x1000000 ||
0183             _CROSS_64KB(addr, size, 0))
0184             use_virtual_dma = 1;
0185         else
0186             use_virtual_dma = 0;
0187     } else {
0188         use_virtual_dma = can_use_virtual_dma & 1;
0189     }
0190 }
0191 
0192 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
0193 
0194 
0195 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
0196 {
0197     doing_pdma = 1;
0198     virtual_dma_port = io;
0199     virtual_dma_mode = (mode == DMA_MODE_WRITE);
0200     virtual_dma_addr = addr;
0201     virtual_dma_count = size;
0202     virtual_dma_residue = 0;
0203     return 0;
0204 }
0205 
0206 static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
0207 {
0208 #ifdef FLOPPY_SANITY_CHECK
0209     if (CROSS_64KB(addr, size)) {
0210         printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
0211         return -1;
0212     }
0213 #endif
0214     /* actual, physical DMA */
0215     doing_pdma = 0;
0216     clear_dma_ff(FLOPPY_DMA);
0217     set_dma_mode(FLOPPY_DMA, mode);
0218     set_dma_addr(FLOPPY_DMA, isa_virt_to_bus(addr));
0219     set_dma_count(FLOPPY_DMA, size);
0220     enable_dma(FLOPPY_DMA);
0221     return 0;
0222 }
0223 
0224 static struct fd_routine_l {
0225     int (*_request_dma)(unsigned int dmanr, const char *device_id);
0226     void (*_free_dma)(unsigned int dmanr);
0227     int (*_get_dma_residue)(unsigned int dummy);
0228     unsigned long (*_dma_mem_alloc)(unsigned long size);
0229     int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
0230 } fd_routine[] = {
0231     {
0232         ._request_dma       = request_dma,
0233         ._free_dma      = free_dma,
0234         ._get_dma_residue   = get_dma_residue,
0235         ._dma_mem_alloc     = dma_mem_alloc,
0236         ._dma_setup     = hard_dma_setup
0237     },
0238     {
0239         ._request_dma       = vdma_request_dma,
0240         ._free_dma      = vdma_nop,
0241         ._get_dma_residue   = vdma_get_dma_residue,
0242         ._dma_mem_alloc     = vdma_mem_alloc,
0243         ._dma_setup     = vdma_dma_setup
0244     }
0245 };
0246 
0247 
0248 static int FDC1 = 0x3f0;
0249 static int FDC2 = -1;
0250 
0251 /*
0252  * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
0253  * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
0254  * coincides with another rtc CMOS user.        Paul G.
0255  */
0256 #define FLOPPY0_TYPE                    \
0257 ({                          \
0258     unsigned long flags;                \
0259     unsigned char val;              \
0260     spin_lock_irqsave(&rtc_lock, flags);        \
0261     val = (CMOS_READ(0x10) >> 4) & 15;      \
0262     spin_unlock_irqrestore(&rtc_lock, flags);   \
0263     val;                        \
0264 })
0265 
0266 #define FLOPPY1_TYPE                    \
0267 ({                          \
0268     unsigned long flags;                \
0269     unsigned char val;              \
0270     spin_lock_irqsave(&rtc_lock, flags);        \
0271     val = CMOS_READ(0x10) & 15;         \
0272     spin_unlock_irqrestore(&rtc_lock, flags);   \
0273     val;                        \
0274 })
0275 
0276 #define N_FDC 2
0277 #define N_DRIVE 8
0278 
0279 #define EXTRA_FLOPPY_PARAMS
0280 
0281 #endif /* _ASM_X86_FLOPPY_H */