stdma.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * linux/arch/m68k/atari/stmda.c
  3. *
  4. * Copyright (C) 1994 Roman Hodek
  5. *
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive
  9. * for more details.
  10. */
  11. /* This file contains some function for controlling the access to the */
  12. /* ST-DMA chip that may be shared between devices. Currently we have: */
  13. /* TT: Floppy and ACSI bus */
  14. /* Falcon: Floppy and SCSI */
  15. /* */
  16. /* The controlling functions set up a wait queue for access to the */
  17. /* ST-DMA chip. Callers to stdma_lock() that cannot granted access are */
  18. /* put onto a queue and waked up later if the owner calls */
  19. /* stdma_release(). Additionally, the caller gives his interrupt */
  20. /* service routine to stdma_lock(). */
  21. /* */
  22. /* On the Falcon, the IDE bus uses just the ACSI/Floppy interrupt, but */
  23. /* not the ST-DMA chip itself. So falhd.c needs not to lock the */
  24. /* chip. The interrupt is routed to falhd.c if IDE is configured, the */
  25. /* model is a Falcon and the interrupt was caused by the HD controller */
  26. /* (can be determined by looking at its status register). */
  27. #include <linux/types.h>
  28. #include <linux/kdev_t.h>
  29. #include <linux/genhd.h>
  30. #include <linux/sched.h>
  31. #include <linux/init.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/wait.h>
  34. #include <linux/module.h>
  35. #include <asm/atari_stdma.h>
  36. #include <asm/atariints.h>
  37. #include <asm/atarihw.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. static int stdma_locked; /* the semaphore */
  41. /* int func to be called */
  42. static irq_handler_t stdma_isr;
  43. static void *stdma_isr_data; /* data passed to isr */
  44. static DECLARE_WAIT_QUEUE_HEAD(stdma_wait); /* wait queue for ST-DMA */
  45. /***************************** Prototypes *****************************/
  46. static irqreturn_t stdma_int (int irq, void *dummy);
  47. /************************* End of Prototypes **************************/
  48. /**
  49. * stdma_try_lock - attempt to acquire ST DMA interrupt "lock"
  50. * @handler: interrupt handler to use after acquisition
  51. *
  52. * Returns !0 if lock was acquired; otherwise 0.
  53. */
  54. int stdma_try_lock(irq_handler_t handler, void *data)
  55. {
  56. unsigned long flags;
  57. local_irq_save(flags);
  58. if (stdma_locked) {
  59. local_irq_restore(flags);
  60. return 0;
  61. }
  62. stdma_locked = 1;
  63. stdma_isr = handler;
  64. stdma_isr_data = data;
  65. local_irq_restore(flags);
  66. return 1;
  67. }
  68. EXPORT_SYMBOL(stdma_try_lock);
  69. /*
  70. * Function: void stdma_lock( isrfunc isr, void *data )
  71. *
  72. * Purpose: Tries to get a lock on the ST-DMA chip that is used by more
  73. * then one device driver. Waits on stdma_wait until lock is free.
  74. * stdma_lock() may not be called from an interrupt! You have to
  75. * get the lock in your main routine and release it when your
  76. * request is finished.
  77. *
  78. * Inputs: A interrupt function that is called until the lock is
  79. * released.
  80. *
  81. * Returns: nothing
  82. *
  83. */
  84. void stdma_lock(irq_handler_t handler, void *data)
  85. {
  86. /* Since the DMA is used for file system purposes, we
  87. have to sleep uninterruptible (there may be locked
  88. buffers) */
  89. wait_event(stdma_wait, stdma_try_lock(handler, data));
  90. }
  91. EXPORT_SYMBOL(stdma_lock);
  92. /*
  93. * Function: void stdma_release( void )
  94. *
  95. * Purpose: Releases the lock on the ST-DMA chip.
  96. *
  97. * Inputs: none
  98. *
  99. * Returns: nothing
  100. *
  101. */
  102. void stdma_release(void)
  103. {
  104. unsigned long flags;
  105. local_irq_save(flags);
  106. stdma_locked = 0;
  107. stdma_isr = NULL;
  108. stdma_isr_data = NULL;
  109. wake_up(&stdma_wait);
  110. local_irq_restore(flags);
  111. }
  112. EXPORT_SYMBOL(stdma_release);
  113. /**
  114. * stdma_is_locked_by - allow lock holder to check whether it needs to release.
  115. * @handler: interrupt handler previously used to acquire lock.
  116. *
  117. * Returns !0 if locked for the given handler; 0 otherwise.
  118. */
  119. int stdma_is_locked_by(irq_handler_t handler)
  120. {
  121. unsigned long flags;
  122. int result;
  123. local_irq_save(flags);
  124. result = stdma_locked && (stdma_isr == handler);
  125. local_irq_restore(flags);
  126. return result;
  127. }
  128. EXPORT_SYMBOL(stdma_is_locked_by);
  129. /*
  130. * Function: int stdma_islocked( void )
  131. *
  132. * Purpose: Check if the ST-DMA is currently locked.
  133. * Note: Returned status is only valid if ints are disabled while calling and
  134. * as long as they remain disabled.
  135. * If called with ints enabled, status can change only from locked to
  136. * unlocked, because ints may not lock the ST-DMA.
  137. *
  138. * Inputs: none
  139. *
  140. * Returns: != 0 if locked, 0 otherwise
  141. *
  142. */
  143. int stdma_islocked(void)
  144. {
  145. return stdma_locked;
  146. }
  147. EXPORT_SYMBOL(stdma_islocked);
  148. /*
  149. * Function: void stdma_init( void )
  150. *
  151. * Purpose: Initialize the ST-DMA chip access controlling.
  152. * It sets up the interrupt and its service routine. The int is registered
  153. * as slow int, client devices have to live with that (no problem
  154. * currently).
  155. *
  156. * Inputs: none
  157. *
  158. * Return: nothing
  159. *
  160. */
  161. void __init stdma_init(void)
  162. {
  163. stdma_isr = NULL;
  164. if (request_irq(IRQ_MFP_FDC, stdma_int, IRQF_SHARED,
  165. "ST-DMA floppy,ACSI,IDE,Falcon-SCSI", stdma_int))
  166. pr_err("Couldn't register ST-DMA interrupt\n");
  167. }
  168. /*
  169. * Function: void stdma_int()
  170. *
  171. * Purpose: The interrupt routine for the ST-DMA. It calls the isr
  172. * registered by stdma_lock().
  173. *
  174. */
  175. static irqreturn_t stdma_int(int irq, void *dummy)
  176. {
  177. if (stdma_isr)
  178. (*stdma_isr)(irq, stdma_isr_data);
  179. return IRQ_HANDLED;
  180. }