floppy.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Architecture specific parts of the Floppy driver
  3. * include/asm-i386/floppy.h
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. *
  9. * Copyright (C) 1995
  10. */
  11. #ifndef __ASM_SH_FLOPPY_H
  12. #define __ASM_SH_FLOPPY_H
  13. #include <linux/vmalloc.h>
  14. /*
  15. * The DMA channel used by the floppy controller cannot access data at
  16. * addresses >= 16MB
  17. *
  18. * Went back to the 1MB limit, as some people had problems with the floppy
  19. * driver otherwise. It doesn't matter much for performance anyway, as most
  20. * floppy accesses go through the track buffer.
  21. */
  22. #define _CROSS_64KB(a,s,vdma) \
  23. (!vdma && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
  24. #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
  25. #define SW fd_routine[use_virtual_dma&1]
  26. #define CSW fd_routine[can_use_virtual_dma & 1]
  27. #define fd_inb(port) inb_p(port)
  28. #define fd_outb(value,port) outb_p(value,port)
  29. #define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
  30. #define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
  31. #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
  32. #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
  33. #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
  34. #define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
  35. #define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
  36. #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
  37. #define FLOPPY_CAN_FALLBACK_ON_NODMA
  38. static int virtual_dma_count;
  39. static int virtual_dma_residue;
  40. static char *virtual_dma_addr;
  41. static int virtual_dma_mode;
  42. static int doing_pdma;
  43. static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
  44. {
  45. register unsigned char st;
  46. #undef TRACE_FLPY_INT
  47. #ifdef TRACE_FLPY_INT
  48. static int calls=0;
  49. static int bytes=0;
  50. static int dma_wait=0;
  51. #endif
  52. if(!doing_pdma) {
  53. floppy_interrupt(irq, dev_id, regs);
  54. return;
  55. }
  56. #ifdef TRACE_FLPY_INT
  57. if(!calls)
  58. bytes = virtual_dma_count;
  59. #endif
  60. {
  61. register int lcount;
  62. register char *lptr;
  63. st = 1;
  64. for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
  65. lcount; lcount--, lptr++) {
  66. st=inb(virtual_dma_port+4) & 0xa0 ;
  67. if(st != 0xa0)
  68. break;
  69. if(virtual_dma_mode)
  70. outb_p(*lptr, virtual_dma_port+5);
  71. else
  72. *lptr = inb_p(virtual_dma_port+5);
  73. }
  74. virtual_dma_count = lcount;
  75. virtual_dma_addr = lptr;
  76. st = inb(virtual_dma_port+4);
  77. }
  78. #ifdef TRACE_FLPY_INT
  79. calls++;
  80. #endif
  81. if(st == 0x20)
  82. return;
  83. if(!(st & 0x20)) {
  84. virtual_dma_residue += virtual_dma_count;
  85. virtual_dma_count=0;
  86. #ifdef TRACE_FLPY_INT
  87. printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
  88. virtual_dma_count, virtual_dma_residue, calls, bytes,
  89. dma_wait);
  90. calls = 0;
  91. dma_wait=0;
  92. #endif
  93. doing_pdma = 0;
  94. floppy_interrupt(irq, dev_id, regs);
  95. return;
  96. }
  97. #ifdef TRACE_FLPY_INT
  98. if(!virtual_dma_count)
  99. dma_wait++;
  100. #endif
  101. }
  102. static void fd_disable_dma(void)
  103. {
  104. if(! (can_use_virtual_dma & 1))
  105. disable_dma(FLOPPY_DMA);
  106. doing_pdma = 0;
  107. virtual_dma_residue += virtual_dma_count;
  108. virtual_dma_count=0;
  109. }
  110. static int vdma_request_dma(unsigned int dmanr, const char * device_id)
  111. {
  112. return 0;
  113. }
  114. static void vdma_nop(unsigned int dummy)
  115. {
  116. }
  117. static int vdma_get_dma_residue(unsigned int dummy)
  118. {
  119. return virtual_dma_count + virtual_dma_residue;
  120. }
  121. static int fd_request_irq(void)
  122. {
  123. if(can_use_virtual_dma)
  124. return request_irq(FLOPPY_IRQ, floppy_hardint,
  125. IRQF_DISABLED, "floppy", NULL);
  126. else
  127. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  128. IRQF_DISABLED, "floppy", NULL);
  129. }
  130. static unsigned long dma_mem_alloc(unsigned long size)
  131. {
  132. return __get_dma_pages(GFP_KERNEL,get_order(size));
  133. }
  134. static unsigned long vdma_mem_alloc(unsigned long size)
  135. {
  136. return (unsigned long) vmalloc(size);
  137. }
  138. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  139. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  140. {
  141. if((unsigned int) addr >= (unsigned int) high_memory)
  142. return vfree((void *)addr);
  143. else
  144. free_pages(addr, get_order(size));
  145. }
  146. #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
  147. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  148. {
  149. if(can_use_virtual_dma == 2) {
  150. if((unsigned int) addr >= (unsigned int) high_memory ||
  151. virt_to_phys(addr) >= 0x10000000)
  152. use_virtual_dma = 1;
  153. else
  154. use_virtual_dma = 0;
  155. } else {
  156. use_virtual_dma = can_use_virtual_dma & 1;
  157. }
  158. }
  159. #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
  160. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  161. {
  162. doing_pdma = 1;
  163. virtual_dma_port = io;
  164. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  165. virtual_dma_addr = addr;
  166. virtual_dma_count = size;
  167. virtual_dma_residue = 0;
  168. return 0;
  169. }
  170. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  171. {
  172. #ifdef FLOPPY_SANITY_CHECK
  173. if (CROSS_64KB(addr, size)) {
  174. printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
  175. return -1;
  176. }
  177. #endif
  178. dma_cache_wback_inv(addr, size);
  179. /* actual, physical DMA */
  180. doing_pdma = 0;
  181. clear_dma_ff(FLOPPY_DMA);
  182. set_dma_mode(FLOPPY_DMA,mode);
  183. set_dma_addr(FLOPPY_DMA,virt_to_phys(addr));
  184. set_dma_count(FLOPPY_DMA,size);
  185. enable_dma(FLOPPY_DMA);
  186. return 0;
  187. }
  188. static struct fd_routine_l {
  189. int (*_request_dma)(unsigned int dmanr, const char * device_id);
  190. void (*_free_dma)(unsigned int dmanr);
  191. int (*_get_dma_residue)(unsigned int dummy);
  192. unsigned long (*_dma_mem_alloc) (unsigned long size);
  193. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  194. } fd_routine[] = {
  195. {
  196. request_dma,
  197. free_dma,
  198. get_dma_residue,
  199. dma_mem_alloc,
  200. hard_dma_setup
  201. },
  202. {
  203. vdma_request_dma,
  204. vdma_nop,
  205. vdma_get_dma_residue,
  206. vdma_mem_alloc,
  207. vdma_dma_setup
  208. }
  209. };
  210. static int FDC1 = 0x3f0;
  211. static int FDC2 = -1;
  212. /*
  213. * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
  214. * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
  215. * coincides with another rtc CMOS user. Paul G.
  216. */
  217. #define FLOPPY0_TYPE (4)
  218. #define FLOPPY1_TYPE (0)
  219. #define N_FDC 2
  220. #define N_DRIVE 8
  221. #define FLOPPY_MOTOR_MASK 0xf0
  222. #define AUTO_DMA
  223. #define EXTRA_FLOPPY_PARAMS
  224. #endif /* __ASM_SH_FLOPPY_H */