More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / arch / m68k / atari / stdma.c
blob1aff226be34b91502040bc1412feb321c7ba9803
1 /*
2 * linux/arch/m68k/atari/stmda.c
4 * Copyright (C) 1994 Roman Hodek
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.
13 /* This file contains some function for controlling the access to the */
14 /* ST-DMA chip that may be shared between devices. Currently we have: */
15 /* TT: Floppy and ACSI bus */
16 /* Falcon: Floppy and SCSI */
17 /* */
18 /* The controlling functions set up a wait queue for access to the */
19 /* ST-DMA chip. Callers to stdma_lock() that cannot granted access are */
20 /* put onto a queue and waked up later if the owner calls */
21 /* stdma_release(). Additionally, the caller gives his interrupt */
22 /* service routine to stdma_lock(). */
23 /* */
24 /* On the Falcon, the IDE bus uses just the ACSI/Floppy interrupt, but */
25 /* not the ST-DMA chip itself. So falhd.c needs not to lock the */
26 /* chip. The interrupt is routed to falhd.c if IDE is configured, the */
27 /* model is a Falcon and the interrupt was caused by the HD controller */
28 /* (can be determined by looking at its status register). */
31 #include <linux/types.h>
32 #include <linux/kdev_t.h>
33 #include <linux/genhd.h>
34 #include <linux/sched.h>
35 #include <linux/init.h>
37 #include <asm/atari_stdma.h>
38 #include <asm/atariints.h>
39 #include <asm/atarihw.h>
40 #include <asm/io.h>
41 #include <asm/irq.h>
43 static int stdma_locked = 0; /* the semaphore */
44 /* int func to be called */
45 static void (*stdma_isr)(int, void *, struct pt_regs *) = NULL;
46 static void *stdma_isr_data = NULL; /* data passed to isr */
47 static DECLARE_WAIT_QUEUE_HEAD(stdma_wait); /* wait queue for ST-DMA */
52 /***************************** Prototypes *****************************/
54 static void stdma_int (int irq, void *dummy, struct pt_regs *fp);
56 /************************* End of Prototypes **************************/
61 * Function: void stdma_lock( isrfunc isr, void *data )
63 * Purpose: Tries to get a lock on the ST-DMA chip that is used by more
64 * then one device driver. Waits on stdma_wait until lock is free.
65 * stdma_lock() may not be called from an interrupt! You have to
66 * get the lock in your main routine and release it when your
67 * request is finished.
69 * Inputs: A interrupt function that is called until the lock is
70 * released.
72 * Returns: nothing
76 void stdma_lock(void (*handler)(int, void *, struct pt_regs *), void *data)
78 unsigned long oldflags;
80 save_flags(oldflags);
81 cli(); /* protect lock */
83 while(stdma_locked)
84 /* Since the DMA is used for file system purposes, we
85 have to sleep uninterruptible (there may be locked
86 buffers) */
87 sleep_on(&stdma_wait);
89 stdma_locked = 1;
90 stdma_isr = handler;
91 stdma_isr_data = data;
92 restore_flags(oldflags);
97 * Function: void stdma_release( void )
99 * Purpose: Releases the lock on the ST-DMA chip.
101 * Inputs: none
103 * Returns: nothing
107 void stdma_release(void)
109 unsigned long oldflags;
111 save_flags(oldflags);
112 cli();
114 stdma_locked = 0;
115 stdma_isr = NULL;
116 stdma_isr_data = NULL;
117 wake_up(&stdma_wait);
119 restore_flags(oldflags);
124 * Function: int stdma_others_waiting( void )
126 * Purpose: Check if someone waits for the ST-DMA lock.
128 * Inputs: none
130 * Returns: 0 if no one is waiting, != 0 otherwise
134 int stdma_others_waiting(void)
136 return waitqueue_active(&stdma_wait);
141 * Function: int stdma_islocked( void )
143 * Purpose: Check if the ST-DMA is currently locked.
144 * Note: Returned status is only valid if ints are disabled while calling and
145 * as long as they remain disabled.
146 * If called with ints enabled, status can change only from locked to
147 * unlocked, because ints may not lock the ST-DMA.
149 * Inputs: none
151 * Returns: != 0 if locked, 0 otherwise
155 int stdma_islocked(void)
157 return stdma_locked;
162 * Function: void stdma_init( void )
164 * Purpose: Initialize the ST-DMA chip access controlling.
165 * It sets up the interrupt and its service routine. The int is registered
166 * as slow int, client devices have to live with that (no problem
167 * currently).
169 * Inputs: none
171 * Return: nothing
175 void __init stdma_init(void)
177 stdma_isr = NULL;
178 request_irq(IRQ_MFP_FDC, stdma_int, IRQ_TYPE_SLOW,
179 "ST-DMA: floppy/ACSI/IDE/Falcon-SCSI", stdma_int);
184 * Function: void stdma_int()
186 * Purpose: The interrupt routine for the ST-DMA. It calls the isr
187 * registered by stdma_lock().
191 static void stdma_int(int irq, void *dummy, struct pt_regs *fp)
193 if (stdma_isr)
194 (*stdma_isr)(irq, stdma_isr_data, fp);