Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[POWERPC] Virtual DMA support for floppy driver for new powerpc architecture

During ppc64+ppc merge virtual DMA code for floppy driver was not
ported. This patch restores virtual DMA support for floppy in new
powerpc target.

It is necessary at least on Pegasos and AmigaOne machines for the
floppy drive to function. ISA DMA controller works incorrectly there
due to its addressing limitations.

Virtual DMA mode is activated by floppy=nodma option passed to the
kernel (or module). There's no automatic switch like on i386.

Signed-off-by: Pavel Fedin <sonic_amiga@rambler.ru>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Pavel Fedin and committed by
Paul Mackerras
9ea8b7c9 cbca567e

+123 -14
+123 -14
include/asm-powerpc/floppy.h
··· 17 17 #define fd_outb(value,port) outb_p(value,port) 18 18 19 19 #define fd_enable_dma() enable_dma(FLOPPY_DMA) 20 - #define fd_disable_dma() disable_dma(FLOPPY_DMA) 21 - #define fd_request_dma() request_dma(FLOPPY_DMA, "floppy") 22 - #define fd_free_dma() free_dma(FLOPPY_DMA) 20 + #define fd_disable_dma() fd_ops->_disable_dma(FLOPPY_DMA) 21 + #define fd_free_dma() fd_ops->_free_dma(FLOPPY_DMA) 23 22 #define fd_clear_dma_ff() clear_dma_ff(FLOPPY_DMA) 24 23 #define fd_set_dma_mode(mode) set_dma_mode(FLOPPY_DMA, mode) 25 24 #define fd_set_dma_count(count) set_dma_count(FLOPPY_DMA, count) 25 + #define fd_get_dma_residue() fd_ops->_get_dma_residue(FLOPPY_DMA) 26 26 #define fd_enable_irq() enable_irq(FLOPPY_IRQ) 27 27 #define fd_disable_irq() disable_irq(FLOPPY_IRQ) 28 28 #define fd_cacheflush(addr,size) /* nothing */ 29 - #define fd_request_irq() request_irq(FLOPPY_IRQ, floppy_interrupt, \ 30 - IRQF_DISABLED, "floppy", NULL) 31 29 #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL); 32 - 33 - #ifdef CONFIG_PCI 34 30 35 31 #include <linux/pci.h> 36 32 #include <asm/ppc-pci.h> /* for ppc64_isabridge_dev */ 37 33 38 - #define fd_dma_setup(addr,size,mode,io) powerpc_fd_dma_setup(addr,size,mode,io) 34 + #define fd_dma_setup(addr,size,mode,io) fd_ops->_dma_setup(addr,size,mode,io) 39 35 40 - static __inline__ int powerpc_fd_dma_setup(char *addr, unsigned long size, 41 - int mode, int io) 36 + static int fd_request_dma(void); 37 + 38 + struct fd_dma_ops { 39 + void (*_disable_dma)(unsigned int dmanr); 40 + void (*_free_dma)(unsigned int dmanr); 41 + int (*_get_dma_residue)(unsigned int dummy); 42 + int (*_dma_setup)(char *addr, unsigned long size, int mode, int io); 43 + }; 44 + 45 + static int virtual_dma_count; 46 + static int virtual_dma_residue; 47 + static char *virtual_dma_addr; 48 + static int virtual_dma_mode; 49 + static int doing_vdma; 50 + static struct fd_dma_ops *fd_ops; 51 + 52 + static irqreturn_t floppy_hardint(int irq, void *dev_id) 53 + { 54 + unsigned char st; 55 + int lcount; 56 + char *lptr; 57 + 58 + if (!doing_vdma) 59 + return floppy_interrupt(irq, dev_id); 60 + 61 + 62 + st = 1; 63 + for (lcount=virtual_dma_count, lptr=virtual_dma_addr; 64 + lcount; lcount--, lptr++) { 65 + st=inb(virtual_dma_port+4) & 0xa0 ; 66 + if (st != 0xa0) 67 + break; 68 + if (virtual_dma_mode) 69 + outb_p(*lptr, virtual_dma_port+5); 70 + else 71 + *lptr = inb_p(virtual_dma_port+5); 72 + } 73 + virtual_dma_count = lcount; 74 + virtual_dma_addr = lptr; 75 + st = inb(virtual_dma_port+4); 76 + 77 + if (st == 0x20) 78 + return IRQ_HANDLED; 79 + if (!(st & 0x20)) { 80 + virtual_dma_residue += virtual_dma_count; 81 + virtual_dma_count=0; 82 + doing_vdma = 0; 83 + floppy_interrupt(irq, dev_id); 84 + return IRQ_HANDLED; 85 + } 86 + return IRQ_HANDLED; 87 + } 88 + 89 + static void vdma_disable_dma(unsigned int dummy) 90 + { 91 + doing_vdma = 0; 92 + virtual_dma_residue += virtual_dma_count; 93 + virtual_dma_count=0; 94 + } 95 + 96 + static void vdma_nop(unsigned int dummy) 97 + { 98 + } 99 + 100 + 101 + static int vdma_get_dma_residue(unsigned int dummy) 102 + { 103 + return virtual_dma_count + virtual_dma_residue; 104 + } 105 + 106 + 107 + static int fd_request_irq(void) 108 + { 109 + if (can_use_virtual_dma) 110 + return request_irq(FLOPPY_IRQ, floppy_hardint, 111 + IRQF_DISABLED, "floppy", NULL); 112 + else 113 + return request_irq(FLOPPY_IRQ, floppy_interrupt, 114 + IRQF_DISABLED, "floppy", NULL); 115 + } 116 + 117 + static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io) 118 + { 119 + doing_vdma = 1; 120 + virtual_dma_port = io; 121 + virtual_dma_mode = (mode == DMA_MODE_WRITE); 122 + virtual_dma_addr = addr; 123 + virtual_dma_count = size; 124 + virtual_dma_residue = 0; 125 + return 0; 126 + } 127 + 128 + static int hard_dma_setup(char *addr, unsigned long size, int mode, int io) 42 129 { 43 130 static unsigned long prev_size; 44 131 static dma_addr_t bus_addr = 0; ··· 133 46 static int prev_dir; 134 47 int dir; 135 48 49 + doing_vdma = 0; 136 50 dir = (mode == DMA_MODE_READ) ? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE; 137 51 138 52 if (bus_addr ··· 162 74 return 0; 163 75 } 164 76 165 - #endif /* CONFIG_PCI */ 166 - 167 - __inline__ void virtual_dma_init(void) 77 + static struct fd_dma_ops real_dma_ops = 168 78 { 169 - /* Nothing to do on PowerPC */ 79 + ._disable_dma = disable_dma, 80 + ._free_dma = free_dma, 81 + ._get_dma_residue = get_dma_residue, 82 + ._dma_setup = hard_dma_setup 83 + }; 84 + 85 + static struct fd_dma_ops virt_dma_ops = 86 + { 87 + ._disable_dma = vdma_disable_dma, 88 + ._free_dma = vdma_nop, 89 + ._get_dma_residue = vdma_get_dma_residue, 90 + ._dma_setup = vdma_dma_setup 91 + }; 92 + 93 + static int fd_request_dma() 94 + { 95 + if (can_use_virtual_dma & 1) { 96 + fd_ops = &virt_dma_ops; 97 + return 0; 98 + } 99 + else { 100 + fd_ops = &real_dma_ops; 101 + return request_dma(FLOPPY_DMA, "floppy"); 102 + } 170 103 } 171 104 172 105 static int FDC1 = 0x3f0;