stdma.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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/sched.h>
  30. #include <linux/init.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/wait.h>
  33. #include <linux/module.h>
  34. #include <asm/atari_stdma.h>
  35. #include <asm/atariints.h>
  36. #include <asm/atarihw.h>
  37. #include <asm/io.h>
  38. #include <asm/irq.h>
  39. static int stdma_locked; /* the semaphore */
  40. /* int func to be called */
  41. static irq_handler_t stdma_isr;
  42. static void *stdma_isr_data; /* data passed to isr */
  43. static DECLARE_WAIT_QUEUE_HEAD(stdma_wait); /* wait queue for ST-DMA */
  44. /***************************** Prototypes *****************************/
  45. static irqreturn_t stdma_int (int irq, void *dummy);
  46. /************************* End of Prototypes **************************/
  47. /**
  48. * stdma_try_lock - attempt to acquire ST DMA interrupt "lock"
  49. * @handler: interrupt handler to use after acquisition
  50. *
  51. * Returns !0 if lock was acquired; otherwise 0.
  52. */
  53. int stdma_try_lock(irq_handler_t handler, void *data)
  54. {
  55. unsigned long flags;
  56. local_irq_save(flags);
  57. if (stdma_locked) {
  58. local_irq_restore(flags);
  59. return 0;
  60. }
  61. stdma_locked = 1;
  62. stdma_isr = handler;
  63. stdma_isr_data = data;
  64. local_irq_restore(flags);
  65. return 1;
  66. }
  67. EXPORT_SYMBOL(stdma_try_lock);
  68. /*
  69. * Function: void stdma_lock( isrfunc isr, void *data )
  70. *
  71. * Purpose: Tries to get a lock on the ST-DMA chip that is used by more
  72. * then one device driver. Waits on stdma_wait until lock is free.
  73. * stdma_lock() may not be called from an interrupt! You have to
  74. * get the lock in your main routine and release it when your
  75. * request is finished.
  76. *
  77. * Inputs: A interrupt function that is called until the lock is
  78. * released.
  79. *
  80. * Returns: nothing
  81. *
  82. */
  83. void stdma_lock(irq_handler_t handler, void *data)
  84. {
  85. /* Since the DMA is used for file system purposes, we
  86. have to sleep uninterruptible (there may be locked
  87. buffers) */
  88. wait_event(stdma_wait, stdma_try_lock(handler, data));
  89. }
  90. EXPORT_SYMBOL(stdma_lock);
  91. /*
  92. * Function: void stdma_release( void )
  93. *
  94. * Purpose: Releases the lock on the ST-DMA chip.
  95. *
  96. * Inputs: none
  97. *
  98. * Returns: nothing
  99. *
  100. */
  101. void stdma_release(void)
  102. {
  103. unsigned long flags;
  104. local_irq_save(flags);
  105. stdma_locked = 0;
  106. stdma_isr = NULL;
  107. stdma_isr_data = NULL;
  108. wake_up(&stdma_wait);
  109. local_irq_restore(flags);
  110. }
  111. EXPORT_SYMBOL(stdma_release);
  112. /**
  113. * stdma_is_locked_by - allow lock holder to check whether it needs to release.
  114. * @handler: interrupt handler previously used to acquire lock.
  115. *
  116. * Returns !0 if locked for the given handler; 0 otherwise.
  117. */
  118. int stdma_is_locked_by(irq_handler_t handler)
  119. {
  120. unsigned long flags;
  121. int result;
  122. local_irq_save(flags);
  123. result = stdma_locked && (stdma_isr == handler);
  124. local_irq_restore(flags);
  125. return result;
  126. }
  127. EXPORT_SYMBOL(stdma_is_locked_by);
  128. /*
  129. * Function: int stdma_islocked( void )
  130. *
  131. * Purpose: Check if the ST-DMA is currently locked.
  132. * Note: Returned status is only valid if ints are disabled while calling and
  133. * as long as they remain disabled.
  134. * If called with ints enabled, status can change only from locked to
  135. * unlocked, because ints may not lock the ST-DMA.
  136. *
  137. * Inputs: none
  138. *
  139. * Returns: != 0 if locked, 0 otherwise
  140. *
  141. */
  142. int stdma_islocked(void)
  143. {
  144. return stdma_locked;
  145. }
  146. EXPORT_SYMBOL(stdma_islocked);
  147. /*
  148. * Function: void stdma_init( void )
  149. *
  150. * Purpose: Initialize the ST-DMA chip access controlling.
  151. * It sets up the interrupt and its service routine. The int is registered
  152. * as slow int, client devices have to live with that (no problem
  153. * currently).
  154. *
  155. * Inputs: none
  156. *
  157. * Return: nothing
  158. *
  159. */
  160. void __init stdma_init(void)
  161. {
  162. stdma_isr = NULL;
  163. if (request_irq(IRQ_MFP_FDC, stdma_int, IRQF_SHARED,
  164. "ST-DMA floppy,ACSI,IDE,Falcon-SCSI", stdma_int))
  165. pr_err("Couldn't register ST-DMA interrupt\n");
  166. }
  167. /*
  168. * Function: void stdma_int()
  169. *
  170. * Purpose: The interrupt routine for the ST-DMA. It calls the isr
  171. * registered by stdma_lock().
  172. *
  173. */
  174. static irqreturn_t stdma_int(int irq, void *dummy)
  175. {
  176. if (stdma_isr)
  177. (*stdma_isr)(irq, stdma_isr_data);
  178. return IRQ_HANDLED;
  179. }