floppy.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Architecture specific parts of the Floppy driver
  3. *
  4. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  5. * Copyright (C) 2000 Matthew Wilcox (willy a debian . org)
  6. * Copyright (C) 2000 Dave Kennedy
  7. */
  8. #ifndef __ASM_PARISC_FLOPPY_H
  9. #define __ASM_PARISC_FLOPPY_H
  10. #include <linux/vmalloc.h>
  11. /*
  12. * The DMA channel used by the floppy controller cannot access data at
  13. * addresses >= 16MB
  14. *
  15. * Went back to the 1MB limit, as some people had problems with the floppy
  16. * driver otherwise. It doesn't matter much for performance anyway, as most
  17. * floppy accesses go through the track buffer.
  18. */
  19. #define _CROSS_64KB(a,s,vdma) \
  20. (!(vdma) && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
  21. #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
  22. #define SW fd_routine[use_virtual_dma&1]
  23. #define CSW fd_routine[can_use_virtual_dma & 1]
  24. #define fd_inb(base, reg) readb((base) + (reg))
  25. #define fd_outb(value, base, reg) writeb(value, (base) + (reg))
  26. #define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
  27. #define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
  28. #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
  29. #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
  30. #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
  31. #define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
  32. #define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
  33. #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
  34. #define FLOPPY_CAN_FALLBACK_ON_NODMA
  35. static int virtual_dma_count=0;
  36. static int virtual_dma_residue=0;
  37. static char *virtual_dma_addr=0;
  38. static int virtual_dma_mode=0;
  39. static int doing_pdma=0;
  40. static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
  41. {
  42. register unsigned char st;
  43. #undef TRACE_FLPY_INT
  44. #ifdef TRACE_FLPY_INT
  45. static int calls=0;
  46. static int bytes=0;
  47. static int dma_wait=0;
  48. #endif
  49. if (!doing_pdma) {
  50. floppy_interrupt(irq, dev_id, regs);
  51. return;
  52. }
  53. #ifdef TRACE_FLPY_INT
  54. if(!calls)
  55. bytes = virtual_dma_count;
  56. #endif
  57. {
  58. register int lcount;
  59. register char *lptr = virtual_dma_addr;
  60. for (lcount = virtual_dma_count; lcount; lcount--) {
  61. st = fd_inb(virtual_dma_port, FD_STATUS);
  62. st &= STATUS_DMA | STATUS_READY;
  63. if (st != (STATUS_DMA | STATUS_READY))
  64. break;
  65. if (virtual_dma_mode) {
  66. fd_outb(*lptr, virtual_dma_port, FD_DATA);
  67. } else {
  68. *lptr = fd_inb(virtual_dma_port, FD_DATA);
  69. }
  70. lptr++;
  71. }
  72. virtual_dma_count = lcount;
  73. virtual_dma_addr = lptr;
  74. st = fd_inb(virtual_dma_port, FD_STATUS);
  75. }
  76. #ifdef TRACE_FLPY_INT
  77. calls++;
  78. #endif
  79. if (st == STATUS_DMA)
  80. return;
  81. if (!(st & STATUS_DMA)) {
  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, regs);
  93. return;
  94. }
  95. #ifdef TRACE_FLPY_INT
  96. if (!virtual_dma_count)
  97. dma_wait++;
  98. #endif
  99. }
  100. static void fd_disable_dma(void)
  101. {
  102. if(! (can_use_virtual_dma & 1))
  103. disable_dma(FLOPPY_DMA);
  104. doing_pdma = 0;
  105. virtual_dma_residue += virtual_dma_count;
  106. virtual_dma_count=0;
  107. }
  108. static int vdma_request_dma(unsigned int dmanr, const char * device_id)
  109. {
  110. return 0;
  111. }
  112. static void vdma_nop(unsigned int dummy)
  113. {
  114. }
  115. static int vdma_get_dma_residue(unsigned int dummy)
  116. {
  117. return virtual_dma_count + virtual_dma_residue;
  118. }
  119. static int fd_request_irq(void)
  120. {
  121. if(can_use_virtual_dma)
  122. return request_irq(FLOPPY_IRQ, floppy_hardint,
  123. 0, "floppy", NULL);
  124. else
  125. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  126. 0, "floppy", NULL);
  127. }
  128. static unsigned long dma_mem_alloc(unsigned long size)
  129. {
  130. return __get_dma_pages(GFP_KERNEL, get_order(size));
  131. }
  132. static unsigned long vdma_mem_alloc(unsigned long size)
  133. {
  134. return (unsigned long) vmalloc(size);
  135. }
  136. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  137. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  138. {
  139. if((unsigned int) addr >= (unsigned int) high_memory)
  140. return vfree((void *)addr);
  141. else
  142. free_pages(addr, get_order(size));
  143. }
  144. #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
  145. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  146. {
  147. if(can_use_virtual_dma == 2) {
  148. if((unsigned int) addr >= (unsigned int) high_memory ||
  149. virt_to_phys(addr) >= 0x1000000 ||
  150. _CROSS_64KB(addr, size, 0))
  151. use_virtual_dma = 1;
  152. else
  153. use_virtual_dma = 0;
  154. } else {
  155. use_virtual_dma = can_use_virtual_dma & 1;
  156. }
  157. }
  158. #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
  159. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  160. {
  161. doing_pdma = 1;
  162. virtual_dma_port = io;
  163. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  164. virtual_dma_addr = addr;
  165. virtual_dma_count = size;
  166. virtual_dma_residue = 0;
  167. return 0;
  168. }
  169. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  170. {
  171. #ifdef FLOPPY_SANITY_CHECK
  172. if (CROSS_64KB(addr, size)) {
  173. printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
  174. return -1;
  175. }
  176. #endif
  177. /* actual, physical DMA */
  178. doing_pdma = 0;
  179. clear_dma_ff(FLOPPY_DMA);
  180. set_dma_mode(FLOPPY_DMA,mode);
  181. set_dma_addr(FLOPPY_DMA,virt_to_phys(addr));
  182. set_dma_count(FLOPPY_DMA,size);
  183. enable_dma(FLOPPY_DMA);
  184. return 0;
  185. }
  186. static struct fd_routine_l {
  187. int (*_request_dma)(unsigned int dmanr, const char * device_id);
  188. void (*_free_dma)(unsigned int dmanr);
  189. int (*_get_dma_residue)(unsigned int dummy);
  190. unsigned long (*_dma_mem_alloc) (unsigned long size);
  191. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  192. } fd_routine[] = {
  193. {
  194. request_dma,
  195. free_dma,
  196. get_dma_residue,
  197. dma_mem_alloc,
  198. hard_dma_setup
  199. },
  200. {
  201. vdma_request_dma,
  202. vdma_nop,
  203. vdma_get_dma_residue,
  204. vdma_mem_alloc,
  205. vdma_dma_setup
  206. }
  207. };
  208. static int FDC1 = 0x3f0; /* Lies. Floppy controller is memory mapped, not io mapped */
  209. static int FDC2 = -1;
  210. #define FLOPPY0_TYPE 0
  211. #define FLOPPY1_TYPE 0
  212. #define N_FDC 1
  213. #define N_DRIVE 8
  214. #define EXTRA_FLOPPY_PARAMS
  215. #endif /* __ASM_PARISC_FLOPPY_H */