stdma.c 4.8 KB

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