floppy.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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_I386_FLOPPY_H
  11. #define __ASM_I386_FLOPPY_H
  12. #include <linux/vmalloc.h>
  13. /*
  14. * The DMA channel used by the floppy controller cannot access data at
  15. * addresses >= 16MB
  16. *
  17. * Went back to the 1MB limit, as some people had problems with the floppy
  18. * driver otherwise. It doesn't matter much for performance anyway, as most
  19. * floppy accesses go through the track buffer.
  20. */
  21. #define _CROSS_64KB(a,s,vdma) \
  22. (!(vdma) && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
  23. #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
  24. #define SW fd_routine[use_virtual_dma&1]
  25. #define CSW fd_routine[can_use_virtual_dma & 1]
  26. #define fd_inb(port) inb_p(port)
  27. #define fd_outb(value,port) outb_p(value,port)
  28. #define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
  29. #define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
  30. #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
  31. #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
  32. #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
  33. #define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
  34. #define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
  35. #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
  36. #define FLOPPY_CAN_FALLBACK_ON_NODMA
  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_pdma;
  42. static irqreturn_t floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
  43. {
  44. register unsigned char st;
  45. #undef TRACE_FLPY_INT
  46. #define NO_FLOPPY_ASSEMBLER
  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. return floppy_interrupt(irq, dev_id, regs);
  54. #ifdef TRACE_FLPY_INT
  55. if(!calls)
  56. bytes = virtual_dma_count;
  57. #endif
  58. #ifndef NO_FLOPPY_ASSEMBLER
  59. __asm__ (
  60. "testl %1,%1"
  61. "je 3f"
  62. "1: inb %w4,%b0"
  63. "andb $160,%b0"
  64. "cmpb $160,%b0"
  65. "jne 2f"
  66. "incw %w4"
  67. "testl %3,%3"
  68. "jne 4f"
  69. "inb %w4,%b0"
  70. "movb %0,(%2)"
  71. "jmp 5f"
  72. "4: movb (%2),%0"
  73. "outb %b0,%w4"
  74. "5: decw %w4"
  75. "outb %0,$0x80"
  76. "decl %1"
  77. "incl %2"
  78. "testl %1,%1"
  79. "jne 1b"
  80. "3: inb %w4,%b0"
  81. "2: "
  82. : "=a" ((char) st),
  83. "=c" ((long) virtual_dma_count),
  84. "=S" ((long) virtual_dma_addr)
  85. : "b" ((long) virtual_dma_mode),
  86. "d" ((short) virtual_dma_port+4),
  87. "1" ((long) virtual_dma_count),
  88. "2" ((long) virtual_dma_addr));
  89. #else
  90. {
  91. register int lcount;
  92. register char *lptr;
  93. st = 1;
  94. for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
  95. lcount; lcount--, lptr++) {
  96. st=inb(virtual_dma_port+4) & 0xa0 ;
  97. if(st != 0xa0)
  98. break;
  99. if(virtual_dma_mode)
  100. outb_p(*lptr, virtual_dma_port+5);
  101. else
  102. *lptr = inb_p(virtual_dma_port+5);
  103. }
  104. virtual_dma_count = lcount;
  105. virtual_dma_addr = lptr;
  106. st = inb(virtual_dma_port+4);
  107. }
  108. #endif
  109. #ifdef TRACE_FLPY_INT
  110. calls++;
  111. #endif
  112. if(st == 0x20)
  113. return IRQ_HANDLED;
  114. if(!(st & 0x20)) {
  115. virtual_dma_residue += virtual_dma_count;
  116. virtual_dma_count=0;
  117. #ifdef TRACE_FLPY_INT
  118. printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
  119. virtual_dma_count, virtual_dma_residue, calls, bytes,
  120. dma_wait);
  121. calls = 0;
  122. dma_wait=0;
  123. #endif
  124. doing_pdma = 0;
  125. floppy_interrupt(irq, dev_id, regs);
  126. return IRQ_HANDLED;
  127. }
  128. #ifdef TRACE_FLPY_INT
  129. if(!virtual_dma_count)
  130. dma_wait++;
  131. #endif
  132. return IRQ_HANDLED;
  133. }
  134. static void fd_disable_dma(void)
  135. {
  136. if(! (can_use_virtual_dma & 1))
  137. disable_dma(FLOPPY_DMA);
  138. doing_pdma = 0;
  139. virtual_dma_residue += virtual_dma_count;
  140. virtual_dma_count=0;
  141. }
  142. static int vdma_request_dma(unsigned int dmanr, const char * device_id)
  143. {
  144. return 0;
  145. }
  146. static void vdma_nop(unsigned int dummy)
  147. {
  148. }
  149. static int vdma_get_dma_residue(unsigned int dummy)
  150. {
  151. return virtual_dma_count + virtual_dma_residue;
  152. }
  153. static int fd_request_irq(void)
  154. {
  155. if(can_use_virtual_dma)
  156. return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
  157. "floppy", NULL);
  158. else
  159. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  160. SA_INTERRUPT|SA_SAMPLE_RANDOM,
  161. "floppy", NULL);
  162. }
  163. static unsigned long dma_mem_alloc(unsigned long size)
  164. {
  165. return __get_dma_pages(GFP_KERNEL,get_order(size));
  166. }
  167. static unsigned long vdma_mem_alloc(unsigned long size)
  168. {
  169. return (unsigned long) vmalloc(size);
  170. }
  171. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  172. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  173. {
  174. if((unsigned int) addr >= (unsigned int) high_memory)
  175. vfree((void *)addr);
  176. else
  177. free_pages(addr, get_order(size));
  178. }
  179. #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
  180. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  181. {
  182. if(can_use_virtual_dma == 2) {
  183. if((unsigned int) addr >= (unsigned int) high_memory ||
  184. isa_virt_to_bus(addr) >= 0x1000000 ||
  185. _CROSS_64KB(addr, size, 0))
  186. use_virtual_dma = 1;
  187. else
  188. use_virtual_dma = 0;
  189. } else {
  190. use_virtual_dma = can_use_virtual_dma & 1;
  191. }
  192. }
  193. #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
  194. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  195. {
  196. doing_pdma = 1;
  197. virtual_dma_port = io;
  198. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  199. virtual_dma_addr = addr;
  200. virtual_dma_count = size;
  201. virtual_dma_residue = 0;
  202. return 0;
  203. }
  204. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  205. {
  206. #ifdef FLOPPY_SANITY_CHECK
  207. if (CROSS_64KB(addr, size)) {
  208. printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
  209. return -1;
  210. }
  211. #endif
  212. /* actual, physical DMA */
  213. doing_pdma = 0;
  214. clear_dma_ff(FLOPPY_DMA);
  215. set_dma_mode(FLOPPY_DMA,mode);
  216. set_dma_addr(FLOPPY_DMA,isa_virt_to_bus(addr));
  217. set_dma_count(FLOPPY_DMA,size);
  218. enable_dma(FLOPPY_DMA);
  219. return 0;
  220. }
  221. static struct fd_routine_l {
  222. int (*_request_dma)(unsigned int dmanr, const char * device_id);
  223. void (*_free_dma)(unsigned int dmanr);
  224. int (*_get_dma_residue)(unsigned int dummy);
  225. unsigned long (*_dma_mem_alloc) (unsigned long size);
  226. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  227. } fd_routine[] = {
  228. {
  229. request_dma,
  230. free_dma,
  231. get_dma_residue,
  232. dma_mem_alloc,
  233. hard_dma_setup
  234. },
  235. {
  236. vdma_request_dma,
  237. vdma_nop,
  238. vdma_get_dma_residue,
  239. vdma_mem_alloc,
  240. vdma_dma_setup
  241. }
  242. };
  243. static int FDC1 = 0x3f0;
  244. static int FDC2 = -1;
  245. /*
  246. * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
  247. * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
  248. * coincides with another rtc CMOS user. Paul G.
  249. */
  250. #define FLOPPY0_TYPE ({ \
  251. unsigned long flags; \
  252. unsigned char val; \
  253. spin_lock_irqsave(&rtc_lock, flags); \
  254. val = (CMOS_READ(0x10) >> 4) & 15; \
  255. spin_unlock_irqrestore(&rtc_lock, flags); \
  256. val; \
  257. })
  258. #define FLOPPY1_TYPE ({ \
  259. unsigned long flags; \
  260. unsigned char val; \
  261. spin_lock_irqsave(&rtc_lock, flags); \
  262. val = CMOS_READ(0x10) & 15; \
  263. spin_unlock_irqrestore(&rtc_lock, flags); \
  264. val; \
  265. })
  266. #define N_FDC 2
  267. #define N_DRIVE 8
  268. #define FLOPPY_MOTOR_MASK 0xf0
  269. #define AUTO_DMA
  270. #define EXTRA_FLOPPY_PARAMS
  271. #endif /* __ASM_I386_FLOPPY_H */