floppy.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* Architecture specific parts of the Floppy driver
  2. *
  3. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  4. * Copyright (C) 2000 Matthew Wilcox (willy a debian . org)
  5. * Copyright (C) 2000 Dave Kennedy
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __ASM_PARISC_FLOPPY_H
  22. #define __ASM_PARISC_FLOPPY_H
  23. #include <linux/vmalloc.h>
  24. /*
  25. * The DMA channel used by the floppy controller cannot access data at
  26. * addresses >= 16MB
  27. *
  28. * Went back to the 1MB limit, as some people had problems with the floppy
  29. * driver otherwise. It doesn't matter much for performance anyway, as most
  30. * floppy accesses go through the track buffer.
  31. */
  32. #define _CROSS_64KB(a,s,vdma) \
  33. (!vdma && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
  34. #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
  35. #define SW fd_routine[use_virtual_dma&1]
  36. #define CSW fd_routine[can_use_virtual_dma & 1]
  37. #define fd_inb(port) readb(port)
  38. #define fd_outb(value, port) writeb(value, port)
  39. #define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
  40. #define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
  41. #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
  42. #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
  43. #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
  44. #define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
  45. #define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
  46. #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
  47. #define FLOPPY_CAN_FALLBACK_ON_NODMA
  48. static int virtual_dma_count=0;
  49. static int virtual_dma_residue=0;
  50. static char *virtual_dma_addr=0;
  51. static int virtual_dma_mode=0;
  52. static int doing_pdma=0;
  53. static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
  54. {
  55. register unsigned char st;
  56. #undef TRACE_FLPY_INT
  57. #ifdef TRACE_FLPY_INT
  58. static int calls=0;
  59. static int bytes=0;
  60. static int dma_wait=0;
  61. #endif
  62. if (!doing_pdma) {
  63. floppy_interrupt(irq, dev_id, regs);
  64. return;
  65. }
  66. #ifdef TRACE_FLPY_INT
  67. if(!calls)
  68. bytes = virtual_dma_count;
  69. #endif
  70. {
  71. register int lcount;
  72. register char *lptr = virtual_dma_addr;
  73. for (lcount = virtual_dma_count; lcount; lcount--) {
  74. st = fd_inb(virtual_dma_port+4) & 0xa0 ;
  75. if (st != 0xa0)
  76. break;
  77. if (virtual_dma_mode) {
  78. fd_outb(*lptr, virtual_dma_port+5);
  79. } else {
  80. *lptr = fd_inb(virtual_dma_port+5);
  81. }
  82. lptr++;
  83. }
  84. virtual_dma_count = lcount;
  85. virtual_dma_addr = lptr;
  86. st = fd_inb(virtual_dma_port+4);
  87. }
  88. #ifdef TRACE_FLPY_INT
  89. calls++;
  90. #endif
  91. if (st == 0x20)
  92. return;
  93. if (!(st & 0x20)) {
  94. virtual_dma_residue += virtual_dma_count;
  95. virtual_dma_count = 0;
  96. #ifdef TRACE_FLPY_INT
  97. printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
  98. virtual_dma_count, virtual_dma_residue, calls, bytes,
  99. dma_wait);
  100. calls = 0;
  101. dma_wait=0;
  102. #endif
  103. doing_pdma = 0;
  104. floppy_interrupt(irq, dev_id, regs);
  105. return;
  106. }
  107. #ifdef TRACE_FLPY_INT
  108. if (!virtual_dma_count)
  109. dma_wait++;
  110. #endif
  111. }
  112. static void fd_disable_dma(void)
  113. {
  114. if(! (can_use_virtual_dma & 1))
  115. disable_dma(FLOPPY_DMA);
  116. doing_pdma = 0;
  117. virtual_dma_residue += virtual_dma_count;
  118. virtual_dma_count=0;
  119. }
  120. static int vdma_request_dma(unsigned int dmanr, const char * device_id)
  121. {
  122. return 0;
  123. }
  124. static void vdma_nop(unsigned int dummy)
  125. {
  126. }
  127. static int vdma_get_dma_residue(unsigned int dummy)
  128. {
  129. return virtual_dma_count + virtual_dma_residue;
  130. }
  131. static int fd_request_irq(void)
  132. {
  133. if(can_use_virtual_dma)
  134. return request_irq(FLOPPY_IRQ, floppy_hardint,
  135. 0, "floppy", NULL);
  136. else
  137. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  138. 0, "floppy", NULL);
  139. }
  140. static unsigned long dma_mem_alloc(unsigned long size)
  141. {
  142. return __get_dma_pages(GFP_KERNEL, get_order(size));
  143. }
  144. static unsigned long vdma_mem_alloc(unsigned long size)
  145. {
  146. return (unsigned long) vmalloc(size);
  147. }
  148. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  149. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  150. {
  151. if((unsigned int) addr >= (unsigned int) high_memory)
  152. return vfree((void *)addr);
  153. else
  154. free_pages(addr, get_order(size));
  155. }
  156. #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
  157. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  158. {
  159. if(can_use_virtual_dma == 2) {
  160. if((unsigned int) addr >= (unsigned int) high_memory ||
  161. virt_to_bus(addr) >= 0x1000000 ||
  162. _CROSS_64KB(addr, size, 0))
  163. use_virtual_dma = 1;
  164. else
  165. use_virtual_dma = 0;
  166. } else {
  167. use_virtual_dma = can_use_virtual_dma & 1;
  168. }
  169. }
  170. #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
  171. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  172. {
  173. doing_pdma = 1;
  174. virtual_dma_port = io;
  175. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  176. virtual_dma_addr = addr;
  177. virtual_dma_count = size;
  178. virtual_dma_residue = 0;
  179. return 0;
  180. }
  181. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  182. {
  183. #ifdef FLOPPY_SANITY_CHECK
  184. if (CROSS_64KB(addr, size)) {
  185. printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
  186. return -1;
  187. }
  188. #endif
  189. /* actual, physical DMA */
  190. doing_pdma = 0;
  191. clear_dma_ff(FLOPPY_DMA);
  192. set_dma_mode(FLOPPY_DMA,mode);
  193. set_dma_addr(FLOPPY_DMA,virt_to_bus(addr));
  194. set_dma_count(FLOPPY_DMA,size);
  195. enable_dma(FLOPPY_DMA);
  196. return 0;
  197. }
  198. static struct fd_routine_l {
  199. int (*_request_dma)(unsigned int dmanr, const char * device_id);
  200. void (*_free_dma)(unsigned int dmanr);
  201. int (*_get_dma_residue)(unsigned int dummy);
  202. unsigned long (*_dma_mem_alloc) (unsigned long size);
  203. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  204. } fd_routine[] = {
  205. {
  206. request_dma,
  207. free_dma,
  208. get_dma_residue,
  209. dma_mem_alloc,
  210. hard_dma_setup
  211. },
  212. {
  213. vdma_request_dma,
  214. vdma_nop,
  215. vdma_get_dma_residue,
  216. vdma_mem_alloc,
  217. vdma_dma_setup
  218. }
  219. };
  220. static int FDC1 = 0x3f0; /* Lies. Floppy controller is memory mapped, not io mapped */
  221. static int FDC2 = -1;
  222. #define FLOPPY0_TYPE 0
  223. #define FLOPPY1_TYPE 0
  224. #define N_FDC 1
  225. #define N_DRIVE 8
  226. #define EXTRA_FLOPPY_PARAMS
  227. #endif /* __ASM_PARISC_FLOPPY_H */