stdma.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * Function: void stdma_lock( isrfunc isr, void *data )
  50. *
  51. * Purpose: Tries to get a lock on the ST-DMA chip that is used by more
  52. * then one device driver. Waits on stdma_wait until lock is free.
  53. * stdma_lock() may not be called from an interrupt! You have to
  54. * get the lock in your main routine and release it when your
  55. * request is finished.
  56. *
  57. * Inputs: A interrupt function that is called until the lock is
  58. * released.
  59. *
  60. * Returns: nothing
  61. *
  62. */
  63. void stdma_lock(irq_handler_t handler, void *data)
  64. {
  65. unsigned long flags;
  66. local_irq_save(flags); /* protect lock */
  67. /* Since the DMA is used for file system purposes, we
  68. have to sleep uninterruptible (there may be locked
  69. buffers) */
  70. wait_event(stdma_wait, !stdma_locked);
  71. stdma_locked = 1;
  72. stdma_isr = handler;
  73. stdma_isr_data = data;
  74. local_irq_restore(flags);
  75. }
  76. EXPORT_SYMBOL(stdma_lock);
  77. /*
  78. * Function: void stdma_release( void )
  79. *
  80. * Purpose: Releases the lock on the ST-DMA chip.
  81. *
  82. * Inputs: none
  83. *
  84. * Returns: nothing
  85. *
  86. */
  87. void stdma_release(void)
  88. {
  89. unsigned long flags;
  90. local_irq_save(flags);
  91. stdma_locked = 0;
  92. stdma_isr = NULL;
  93. stdma_isr_data = NULL;
  94. wake_up(&stdma_wait);
  95. local_irq_restore(flags);
  96. }
  97. EXPORT_SYMBOL(stdma_release);
  98. /*
  99. * Function: int stdma_others_waiting( void )
  100. *
  101. * Purpose: Check if someone waits for the ST-DMA lock.
  102. *
  103. * Inputs: none
  104. *
  105. * Returns: 0 if no one is waiting, != 0 otherwise
  106. *
  107. */
  108. int stdma_others_waiting(void)
  109. {
  110. return waitqueue_active(&stdma_wait);
  111. }
  112. EXPORT_SYMBOL(stdma_others_waiting);
  113. /*
  114. * Function: int stdma_islocked( void )
  115. *
  116. * Purpose: Check if the ST-DMA is currently locked.
  117. * Note: Returned status is only valid if ints are disabled while calling and
  118. * as long as they remain disabled.
  119. * If called with ints enabled, status can change only from locked to
  120. * unlocked, because ints may not lock the ST-DMA.
  121. *
  122. * Inputs: none
  123. *
  124. * Returns: != 0 if locked, 0 otherwise
  125. *
  126. */
  127. int stdma_islocked(void)
  128. {
  129. return stdma_locked;
  130. }
  131. EXPORT_SYMBOL(stdma_islocked);
  132. /*
  133. * Function: void stdma_init( void )
  134. *
  135. * Purpose: Initialize the ST-DMA chip access controlling.
  136. * It sets up the interrupt and its service routine. The int is registered
  137. * as slow int, client devices have to live with that (no problem
  138. * currently).
  139. *
  140. * Inputs: none
  141. *
  142. * Return: nothing
  143. *
  144. */
  145. void __init stdma_init(void)
  146. {
  147. stdma_isr = NULL;
  148. if (request_irq(IRQ_MFP_FDC, stdma_int, IRQ_TYPE_SLOW | IRQF_SHARED,
  149. "ST-DMA floppy,ACSI,IDE,Falcon-SCSI", stdma_int))
  150. pr_err("Couldn't register ST-DMA interrupt\n");
  151. }
  152. /*
  153. * Function: void stdma_int()
  154. *
  155. * Purpose: The interrupt routine for the ST-DMA. It calls the isr
  156. * registered by stdma_lock().
  157. *
  158. */
  159. static irqreturn_t stdma_int(int irq, void *dummy)
  160. {
  161. if (stdma_isr)
  162. (*stdma_isr)(irq, stdma_isr_data);
  163. return IRQ_HANDLED;
  164. }