stdma.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 irqreturn_t (*stdma_isr)(int, void *, struct pt_regs *);
  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, struct pt_regs *fp);
  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(irqreturn_t (*handler)(int, void *, struct pt_regs *),
  63. 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. /*
  77. * Function: void stdma_release( void )
  78. *
  79. * Purpose: Releases the lock on the ST-DMA chip.
  80. *
  81. * Inputs: none
  82. *
  83. * Returns: nothing
  84. *
  85. */
  86. void stdma_release(void)
  87. {
  88. unsigned long flags;
  89. local_irq_save(flags);
  90. stdma_locked = 0;
  91. stdma_isr = NULL;
  92. stdma_isr_data = NULL;
  93. wake_up(&stdma_wait);
  94. local_irq_restore(flags);
  95. }
  96. /*
  97. * Function: int stdma_others_waiting( void )
  98. *
  99. * Purpose: Check if someone waits for the ST-DMA lock.
  100. *
  101. * Inputs: none
  102. *
  103. * Returns: 0 if no one is waiting, != 0 otherwise
  104. *
  105. */
  106. int stdma_others_waiting(void)
  107. {
  108. return waitqueue_active(&stdma_wait);
  109. }
  110. /*
  111. * Function: int stdma_islocked( void )
  112. *
  113. * Purpose: Check if the ST-DMA is currently locked.
  114. * Note: Returned status is only valid if ints are disabled while calling and
  115. * as long as they remain disabled.
  116. * If called with ints enabled, status can change only from locked to
  117. * unlocked, because ints may not lock the ST-DMA.
  118. *
  119. * Inputs: none
  120. *
  121. * Returns: != 0 if locked, 0 otherwise
  122. *
  123. */
  124. int stdma_islocked(void)
  125. {
  126. return stdma_locked;
  127. }
  128. /*
  129. * Function: void stdma_init( void )
  130. *
  131. * Purpose: Initialize the ST-DMA chip access controlling.
  132. * It sets up the interrupt and its service routine. The int is registered
  133. * as slow int, client devices have to live with that (no problem
  134. * currently).
  135. *
  136. * Inputs: none
  137. *
  138. * Return: nothing
  139. *
  140. */
  141. void __init stdma_init(void)
  142. {
  143. stdma_isr = NULL;
  144. request_irq(IRQ_MFP_FDC, stdma_int, IRQ_TYPE_SLOW,
  145. "ST-DMA: floppy/ACSI/IDE/Falcon-SCSI", stdma_int);
  146. }
  147. /*
  148. * Function: void stdma_int()
  149. *
  150. * Purpose: The interrupt routine for the ST-DMA. It calls the isr
  151. * registered by stdma_lock().
  152. *
  153. */
  154. static irqreturn_t stdma_int(int irq, void *dummy, struct pt_regs *fp)
  155. {
  156. if (stdma_isr)
  157. (*stdma_isr)(irq, stdma_isr_data, fp);
  158. return IRQ_HANDLED;
  159. }