floppy.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #ifndef __ASM_POWERPC_FLOPPY_H
  11. #define __ASM_POWERPC_FLOPPY_H
  12. #ifdef __KERNEL__
  13. #include <asm/machdep.h>
  14. #define fd_inb(port) inb_p(port)
  15. #define fd_outb(value,port) outb_p(value,port)
  16. #define fd_enable_dma() enable_dma(FLOPPY_DMA)
  17. #define fd_disable_dma() fd_ops->_disable_dma(FLOPPY_DMA)
  18. #define fd_free_dma() fd_ops->_free_dma(FLOPPY_DMA)
  19. #define fd_clear_dma_ff() clear_dma_ff(FLOPPY_DMA)
  20. #define fd_set_dma_mode(mode) set_dma_mode(FLOPPY_DMA, mode)
  21. #define fd_set_dma_count(count) set_dma_count(FLOPPY_DMA, count)
  22. #define fd_get_dma_residue() fd_ops->_get_dma_residue(FLOPPY_DMA)
  23. #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
  24. #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
  25. #define fd_cacheflush(addr,size) /* nothing */
  26. #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL);
  27. #include <linux/pci.h>
  28. #include <asm/ppc-pci.h> /* for isa_bridge_pcidev */
  29. #define fd_dma_setup(addr,size,mode,io) fd_ops->_dma_setup(addr,size,mode,io)
  30. static int fd_request_dma(void);
  31. struct fd_dma_ops {
  32. void (*_disable_dma)(unsigned int dmanr);
  33. void (*_free_dma)(unsigned int dmanr);
  34. int (*_get_dma_residue)(unsigned int dummy);
  35. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  36. };
  37. static int virtual_dma_count;
  38. static int virtual_dma_residue;
  39. static char *virtual_dma_addr;
  40. static int virtual_dma_mode;
  41. static int doing_vdma;
  42. static struct fd_dma_ops *fd_ops;
  43. static irqreturn_t floppy_hardint(int irq, void *dev_id)
  44. {
  45. unsigned char st;
  46. int lcount;
  47. char *lptr;
  48. if (!doing_vdma)
  49. return floppy_interrupt(irq, dev_id);
  50. st = 1;
  51. for (lcount=virtual_dma_count, lptr=virtual_dma_addr;
  52. lcount; lcount--, lptr++) {
  53. st=inb(virtual_dma_port+4) & 0xa0 ;
  54. if (st != 0xa0)
  55. break;
  56. if (virtual_dma_mode)
  57. outb_p(*lptr, virtual_dma_port+5);
  58. else
  59. *lptr = inb_p(virtual_dma_port+5);
  60. }
  61. virtual_dma_count = lcount;
  62. virtual_dma_addr = lptr;
  63. st = inb(virtual_dma_port+4);
  64. if (st == 0x20)
  65. return IRQ_HANDLED;
  66. if (!(st & 0x20)) {
  67. virtual_dma_residue += virtual_dma_count;
  68. virtual_dma_count=0;
  69. doing_vdma = 0;
  70. floppy_interrupt(irq, dev_id);
  71. return IRQ_HANDLED;
  72. }
  73. return IRQ_HANDLED;
  74. }
  75. static void vdma_disable_dma(unsigned int dummy)
  76. {
  77. doing_vdma = 0;
  78. virtual_dma_residue += virtual_dma_count;
  79. virtual_dma_count=0;
  80. }
  81. static void vdma_nop(unsigned int dummy)
  82. {
  83. }
  84. static int vdma_get_dma_residue(unsigned int dummy)
  85. {
  86. return virtual_dma_count + virtual_dma_residue;
  87. }
  88. static int fd_request_irq(void)
  89. {
  90. if (can_use_virtual_dma)
  91. return request_irq(FLOPPY_IRQ, floppy_hardint,
  92. 0, "floppy", NULL);
  93. else
  94. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  95. 0, "floppy", NULL);
  96. }
  97. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  98. {
  99. doing_vdma = 1;
  100. virtual_dma_port = io;
  101. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  102. virtual_dma_addr = addr;
  103. virtual_dma_count = size;
  104. virtual_dma_residue = 0;
  105. return 0;
  106. }
  107. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  108. {
  109. static unsigned long prev_size;
  110. static dma_addr_t bus_addr = 0;
  111. static char *prev_addr;
  112. static int prev_dir;
  113. int dir;
  114. doing_vdma = 0;
  115. dir = (mode == DMA_MODE_READ) ? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE;
  116. if (bus_addr
  117. && (addr != prev_addr || size != prev_size || dir != prev_dir)) {
  118. /* different from last time -- unmap prev */
  119. pci_unmap_single(isa_bridge_pcidev, bus_addr, prev_size, prev_dir);
  120. bus_addr = 0;
  121. }
  122. if (!bus_addr) /* need to map it */
  123. bus_addr = pci_map_single(isa_bridge_pcidev, addr, size, dir);
  124. /* remember this one as prev */
  125. prev_addr = addr;
  126. prev_size = size;
  127. prev_dir = dir;
  128. fd_clear_dma_ff();
  129. fd_cacheflush(addr, size);
  130. fd_set_dma_mode(mode);
  131. set_dma_addr(FLOPPY_DMA, bus_addr);
  132. fd_set_dma_count(size);
  133. virtual_dma_port = io;
  134. fd_enable_dma();
  135. return 0;
  136. }
  137. static struct fd_dma_ops real_dma_ops =
  138. {
  139. ._disable_dma = disable_dma,
  140. ._free_dma = free_dma,
  141. ._get_dma_residue = get_dma_residue,
  142. ._dma_setup = hard_dma_setup
  143. };
  144. static struct fd_dma_ops virt_dma_ops =
  145. {
  146. ._disable_dma = vdma_disable_dma,
  147. ._free_dma = vdma_nop,
  148. ._get_dma_residue = vdma_get_dma_residue,
  149. ._dma_setup = vdma_dma_setup
  150. };
  151. static int fd_request_dma(void)
  152. {
  153. if (can_use_virtual_dma & 1) {
  154. fd_ops = &virt_dma_ops;
  155. return 0;
  156. }
  157. else {
  158. fd_ops = &real_dma_ops;
  159. return request_dma(FLOPPY_DMA, "floppy");
  160. }
  161. }
  162. static int FDC1 = 0x3f0;
  163. static int FDC2 = -1;
  164. /*
  165. * Again, the CMOS information not available
  166. */
  167. #define FLOPPY0_TYPE 6
  168. #define FLOPPY1_TYPE 0
  169. #define N_FDC 2 /* Don't change this! */
  170. #define N_DRIVE 8
  171. /*
  172. * The PowerPC has no problems with floppy DMA crossing 64k borders.
  173. */
  174. #define CROSS_64KB(a,s) (0)
  175. #define EXTRA_FLOPPY_PARAMS
  176. #endif /* __KERNEL__ */
  177. #endif /* __ASM_POWERPC_FLOPPY_H */