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_X86_64_FLOPPY_H
  11. #define __ASM_X86_64_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;
  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 void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
  43. {
  44. register unsigned char st;
  45. #undef TRACE_FLPY_INT
  46. #ifdef TRACE_FLPY_INT
  47. static int calls=0;
  48. static int bytes=0;
  49. static int dma_wait=0;
  50. #endif
  51. if(!doing_pdma) {
  52. floppy_interrupt(irq, dev_id, regs);
  53. return;
  54. }
  55. #ifdef TRACE_FLPY_INT
  56. if(!calls)
  57. bytes = virtual_dma_count;
  58. #endif
  59. {
  60. register int lcount;
  61. register char *lptr;
  62. st = 1;
  63. for(lcount=virtual_dma_count, lptr=virtual_dma_addr; 
  64.     lcount; lcount--, lptr++) {
  65. st=inb(virtual_dma_port+4) & 0xa0 ;
  66. if(st != 0xa0) 
  67. break;
  68. if(virtual_dma_mode)
  69. outb_p(*lptr, virtual_dma_port+5);
  70. else
  71. *lptr = inb_p(virtual_dma_port+5);
  72. }
  73. virtual_dma_count = lcount;
  74. virtual_dma_addr = lptr;
  75. st = inb(virtual_dma_port+4);
  76. }
  77. #ifdef TRACE_FLPY_INT
  78. calls++;
  79. #endif
  80. if(st == 0x20)
  81. return;
  82. if(!(st & 0x20)) {
  83. virtual_dma_residue += virtual_dma_count;
  84. virtual_dma_count=0;
  85. #ifdef TRACE_FLPY_INT
  86. printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%dn", 
  87.        virtual_dma_count, virtual_dma_residue, calls, bytes,
  88.        dma_wait);
  89. calls = 0;
  90. dma_wait=0;
  91. #endif
  92. doing_pdma = 0;
  93. floppy_interrupt(irq, dev_id, regs);
  94. return;
  95. }
  96. #ifdef TRACE_FLPY_INT
  97. if(!virtual_dma_count)
  98. dma_wait++;
  99. #endif
  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,SA_INTERRUPT,
  124.    "floppy", NULL);
  125. else
  126. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  127.    SA_INTERRUPT|SA_SAMPLE_RANDOM,
  128.    "floppy", NULL);
  129. }
  130. static unsigned long dma_mem_alloc(unsigned long size)
  131. {
  132. return __get_dma_pages(GFP_KERNEL,get_order(size));
  133. }
  134. static unsigned long vdma_mem_alloc(unsigned long size)
  135. {
  136. return (unsigned long) vmalloc(size);
  137. }
  138. #define nodma_mem_alloc(size) vdma_mem_alloc(size)
  139. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  140. {
  141. if((unsigned long) addr >= (unsigned long) high_memory)
  142. return vfree((void *)addr);
  143. else
  144. free_pages(addr, get_order(size));
  145. }
  146. #define fd_dma_mem_free(addr, size)  _fd_dma_mem_free(addr, size) 
  147. static void _fd_chose_dma_mode(char *addr, unsigned long size)
  148. {
  149. if(can_use_virtual_dma == 2) {
  150. if((unsigned long) addr >= (unsigned long) high_memory ||
  151.    virt_to_bus(addr) >= 0x1000000 ||
  152.    _CROSS_64KB(addr, size, 0))
  153. use_virtual_dma = 1;
  154. else
  155. use_virtual_dma = 0;
  156. } else {
  157. use_virtual_dma = can_use_virtual_dma & 1;
  158. }
  159. }
  160. #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
  161. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  162. {
  163. doing_pdma = 1;
  164. virtual_dma_port = io;
  165. virtual_dma_mode = (mode  == DMA_MODE_WRITE);
  166. virtual_dma_addr = addr;
  167. virtual_dma_count = size;
  168. virtual_dma_residue = 0;
  169. return 0;
  170. }
  171. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  172. {
  173. #ifdef FLOPPY_SANITY_CHECK
  174. if (CROSS_64KB(addr, size)) {
  175. printk("DMA crossing 64-K boundary %p-%pn", addr, addr+size);
  176. return -1;
  177. }
  178. #endif
  179. /* actual, physical DMA */
  180. doing_pdma = 0;
  181. clear_dma_ff(FLOPPY_DMA);
  182. set_dma_mode(FLOPPY_DMA,mode);
  183. set_dma_addr(FLOPPY_DMA,virt_to_bus(addr));
  184. set_dma_count(FLOPPY_DMA,size);
  185. enable_dma(FLOPPY_DMA);
  186. return 0;
  187. }
  188. struct fd_routine_l {
  189. int (*_request_dma)(unsigned int dmanr, const char * device_id);
  190. void (*_free_dma)(unsigned int dmanr);
  191. int (*_get_dma_residue)(unsigned int dummy);
  192. unsigned long (*_dma_mem_alloc) (unsigned long size);
  193. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  194. } fd_routine[] = {
  195. {
  196. request_dma,
  197. free_dma,
  198. get_dma_residue,
  199. dma_mem_alloc,
  200. hard_dma_setup
  201. },
  202. {
  203. vdma_request_dma,
  204. vdma_nop,
  205. vdma_get_dma_residue,
  206. vdma_mem_alloc,
  207. vdma_dma_setup
  208. }
  209. };
  210. static int FDC1 = 0x3f0;
  211. static int FDC2 = -1;
  212. /*
  213.  * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
  214.  * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
  215.  * coincides with another rtc CMOS user. Paul G.
  216.  */
  217. #define FLOPPY0_TYPE ({
  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. unsigned long flags;
  227. unsigned char val;
  228. spin_lock_irqsave(&rtc_lock, flags);
  229. val = CMOS_READ(0x10) & 15;
  230. spin_unlock_irqrestore(&rtc_lock, flags);
  231. val;
  232. })
  233. #define N_FDC 2
  234. #define N_DRIVE 8
  235. #define FLOPPY_MOTOR_MASK 0xf0
  236. #define AUTO_DMA
  237. #define EXTRA_FLOPPY_PARAMS
  238. #endif /* __ASM_X86_64_FLOPPY_H */