floppy.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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_PARISC_FLOPPY_H
  11. #define __ASM_PARISC_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(port,value) outb_p(port,value)
  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=0;
  38. static int virtual_dma_residue=0;
  39. static char *virtual_dma_addr=0;
  40. static int virtual_dma_mode=0;
  41. static int doing_pdma=0;
  42. static void 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. 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=%dn", 
  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,SA_INTERRUPT,
  125.    "floppy", NULL);
  126. else
  127. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  128.    SA_INTERRUPT|SA_SAMPLE_RANDOM,
  129.    "floppy", NULL);
  130. }
  131. static unsigned long dma_mem_alloc(unsigned long size)
  132. {
  133. return __get_dma_pages(GFP_KERNEL,__get_order(size));
  134. }
  135. static unsigned long vdma_mem_alloc(unsigned long size)
  136. {
  137. return (unsigned long) vmalloc(size);
  138. }
  139. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  140. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  141. {
  142. if((unsigned int) addr >= (unsigned int) high_memory)
  143. return vfree((void *)addr);
  144. else
  145. free_pages(addr, __get_order(size));
  146. }
  147. #define fd_dma_mem_free(addr, size)  _fd_dma_mem_free(addr, size) 
  148. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  149. {
  150. if(can_use_virtual_dma == 2) {
  151. if((unsigned int) addr >= (unsigned int) high_memory ||
  152.    virt_to_bus(addr) >= 0x1000000 ||
  153.    _CROSS_64KB(addr, size, 0))
  154. use_virtual_dma = 1;
  155. else
  156. use_virtual_dma = 0;
  157. } else {
  158. use_virtual_dma = can_use_virtual_dma & 1;
  159. }
  160. }
  161. #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
  162. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  163. {
  164. doing_pdma = 1;
  165. virtual_dma_port = io;
  166. virtual_dma_mode = (mode  == DMA_MODE_WRITE);
  167. virtual_dma_addr = addr;
  168. virtual_dma_count = size;
  169. virtual_dma_residue = 0;
  170. return 0;
  171. }
  172. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  173. {
  174. #ifdef FLOPPY_SANITY_CHECK
  175. if (CROSS_64KB(addr, size)) {
  176. printk("DMA crossing 64-K boundary %p-%pn", addr, addr+size);
  177. return -1;
  178. }
  179. #endif
  180. /* actual, physical DMA */
  181. doing_pdma = 0;
  182. clear_dma_ff(FLOPPY_DMA);
  183. set_dma_mode(FLOPPY_DMA,mode);
  184. set_dma_addr(FLOPPY_DMA,virt_to_bus(addr));
  185. set_dma_count(FLOPPY_DMA,size);
  186. enable_dma(FLOPPY_DMA);
  187. return 0;
  188. }
  189. struct fd_routine_l {
  190. int (*_request_dma)(unsigned int dmanr, const char * device_id);
  191. void (*_free_dma)(unsigned int dmanr);
  192. int (*_get_dma_residue)(unsigned int dummy);
  193. unsigned long (*_dma_mem_alloc) (unsigned long size);
  194. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  195. } fd_routine[] = {
  196. {
  197. request_dma,
  198. free_dma,
  199. get_dma_residue,
  200. dma_mem_alloc,
  201. hard_dma_setup
  202. },
  203. {
  204. vdma_request_dma,
  205. vdma_nop,
  206. vdma_get_dma_residue,
  207. vdma_mem_alloc,
  208. vdma_dma_setup
  209. }
  210. };
  211. static int FDC1 = 0x3f0;
  212. static int FDC2 = -1;
  213. #define FLOPPY0_TYPE ((CMOS_READ(0x10) >> 4) & 15)
  214. #define FLOPPY1_TYPE (CMOS_READ(0x10) & 15)
  215. #define N_FDC 1
  216. #define N_DRIVE 8
  217. #define FLOPPY_MOTOR_MASK 0xf0
  218. #define AUTO_DMA
  219. #endif /* __ASM_PARISC_FLOPPY_H */