floppy.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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_X86_FLOPPY_H
  11. #define _ASM_X86_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) && \
  23. ((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 irqreturn_t floppy_hardint(int irq, void *dev_id)
  44. {
  45. unsigned char st;
  46. #undef TRACE_FLPY_INT
  47. #ifdef TRACE_FLPY_INT
  48. static int calls;
  49. static int bytes;
  50. static int dma_wait;
  51. #endif
  52. if (!doing_pdma)
  53. return floppy_interrupt(irq, dev_id);
  54. #ifdef TRACE_FLPY_INT
  55. if (!calls)
  56. bytes = virtual_dma_count;
  57. #endif
  58. {
  59. int lcount;
  60. char *lptr;
  61. st = 1;
  62. for (lcount = virtual_dma_count, lptr = virtual_dma_addr;
  63. lcount; lcount--, lptr++) {
  64. st = inb(virtual_dma_port + 4) & 0xa0;
  65. if (st != 0xa0)
  66. break;
  67. if (virtual_dma_mode)
  68. outb_p(*lptr, virtual_dma_port + 5);
  69. else
  70. *lptr = inb_p(virtual_dma_port + 5);
  71. }
  72. virtual_dma_count = lcount;
  73. virtual_dma_addr = lptr;
  74. st = inb(virtual_dma_port + 4);
  75. }
  76. #ifdef TRACE_FLPY_INT
  77. calls++;
  78. #endif
  79. if (st == 0x20)
  80. return IRQ_HANDLED;
  81. if (!(st & 0x20)) {
  82. virtual_dma_residue += virtual_dma_count;
  83. virtual_dma_count = 0;
  84. #ifdef TRACE_FLPY_INT
  85. printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
  86. virtual_dma_count, virtual_dma_residue, calls, bytes,
  87. dma_wait);
  88. calls = 0;
  89. dma_wait = 0;
  90. #endif
  91. doing_pdma = 0;
  92. floppy_interrupt(irq, dev_id);
  93. return IRQ_HANDLED;
  94. }
  95. #ifdef TRACE_FLPY_INT
  96. if (!virtual_dma_count)
  97. dma_wait++;
  98. #endif
  99. return IRQ_HANDLED;
  100. }
  101. static void fd_disable_dma(void)
  102. {
  103. if (!(can_use_virtual_dma & 1))
  104. disable_dma(FLOPPY_DMA);
  105. doing_pdma = 0;
  106. virtual_dma_residue += virtual_dma_count;
  107. virtual_dma_count = 0;
  108. }
  109. static int vdma_request_dma(unsigned int dmanr, const char *device_id)
  110. {
  111. return 0;
  112. }
  113. static void vdma_nop(unsigned int dummy)
  114. {
  115. }
  116. static int vdma_get_dma_residue(unsigned int dummy)
  117. {
  118. return virtual_dma_count + virtual_dma_residue;
  119. }
  120. static int fd_request_irq(void)
  121. {
  122. if (can_use_virtual_dma)
  123. return request_irq(FLOPPY_IRQ, floppy_hardint,
  124. IRQF_DISABLED, "floppy", NULL);
  125. else
  126. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  127. IRQF_DISABLED, "floppy", NULL);
  128. }
  129. static unsigned long dma_mem_alloc(unsigned long size)
  130. {
  131. return __get_dma_pages(GFP_KERNEL|__GFP_NORETRY, get_order(size));
  132. }
  133. static unsigned long vdma_mem_alloc(unsigned long size)
  134. {
  135. return (unsigned long)vmalloc(size);
  136. }
  137. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  138. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  139. {
  140. if ((unsigned long)addr >= (unsigned long)high_memory)
  141. vfree((void *)addr);
  142. else
  143. free_pages(addr, get_order(size));
  144. }
  145. #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
  146. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  147. {
  148. if (can_use_virtual_dma == 2) {
  149. if ((unsigned long)addr >= (unsigned long)high_memory ||
  150. isa_virt_to_bus(addr) >= 0x1000000 ||
  151. _CROSS_64KB(addr, size, 0))
  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. /* actual, physical DMA */
  179. doing_pdma = 0;
  180. clear_dma_ff(FLOPPY_DMA);
  181. set_dma_mode(FLOPPY_DMA, mode);
  182. set_dma_addr(FLOPPY_DMA, isa_virt_to_bus(addr));
  183. set_dma_count(FLOPPY_DMA, size);
  184. enable_dma(FLOPPY_DMA);
  185. return 0;
  186. }
  187. static struct fd_routine_l {
  188. int (*_request_dma)(unsigned int dmanr, const char *device_id);
  189. void (*_free_dma)(unsigned int dmanr);
  190. int (*_get_dma_residue)(unsigned int dummy);
  191. unsigned long (*_dma_mem_alloc)(unsigned long size);
  192. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  193. } fd_routine[] = {
  194. {
  195. request_dma,
  196. free_dma,
  197. get_dma_residue,
  198. dma_mem_alloc,
  199. hard_dma_setup
  200. },
  201. {
  202. vdma_request_dma,
  203. vdma_nop,
  204. vdma_get_dma_residue,
  205. vdma_mem_alloc,
  206. vdma_dma_setup
  207. }
  208. };
  209. static int FDC1 = 0x3f0;
  210. static int FDC2 = -1;
  211. /*
  212. * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
  213. * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
  214. * coincides with another rtc CMOS user. Paul G.
  215. */
  216. #define FLOPPY0_TYPE \
  217. ({ \
  218. unsigned long flags; \
  219. unsigned char val; \
  220. spin_lock_irqsave(&rtc_lock, flags); \
  221. val = (CMOS_READ(0x10) >> 4) & 15; \
  222. spin_unlock_irqrestore(&rtc_lock, flags); \
  223. val; \
  224. })
  225. #define FLOPPY1_TYPE \
  226. ({ \
  227. unsigned long flags; \
  228. unsigned char val; \
  229. spin_lock_irqsave(&rtc_lock, flags); \
  230. val = CMOS_READ(0x10) & 15; \
  231. spin_unlock_irqrestore(&rtc_lock, flags); \
  232. val; \
  233. })
  234. #define N_FDC 2
  235. #define N_DRIVE 8
  236. #define EXTRA_FLOPPY_PARAMS
  237. #endif /* _ASM_X86_FLOPPY_H */