aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/atari/stdma.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/m68k/atari/stdma.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/m68k/atari/stdma.c')
-rw-r--r--arch/m68k/atari/stdma.c196
1 files changed, 196 insertions, 0 deletions
diff --git a/arch/m68k/atari/stdma.c b/arch/m68k/atari/stdma.c
new file mode 100644
index 000000000000..288f5e6a124e
--- /dev/null
+++ b/arch/m68k/atari/stdma.c
@@ -0,0 +1,196 @@
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
12
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). */
29
30
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>
36#include <linux/interrupt.h>
37#include <linux/wait.h>
38
39#include <asm/atari_stdma.h>
40#include <asm/atariints.h>
41#include <asm/atarihw.h>
42#include <asm/io.h>
43#include <asm/irq.h>
44
45static int stdma_locked; /* the semaphore */
46 /* int func to be called */
47static irqreturn_t (*stdma_isr)(int, void *, struct pt_regs *);
48static void *stdma_isr_data; /* data passed to isr */
49static DECLARE_WAIT_QUEUE_HEAD(stdma_wait); /* wait queue for ST-DMA */
50
51
52
53
54/***************************** Prototypes *****************************/
55
56static irqreturn_t stdma_int (int irq, void *dummy, struct pt_regs *fp);
57
58/************************* End of Prototypes **************************/
59
60
61
62/*
63 * Function: void stdma_lock( isrfunc isr, void *data )
64 *
65 * Purpose: Tries to get a lock on the ST-DMA chip that is used by more
66 * then one device driver. Waits on stdma_wait until lock is free.
67 * stdma_lock() may not be called from an interrupt! You have to
68 * get the lock in your main routine and release it when your
69 * request is finished.
70 *
71 * Inputs: A interrupt function that is called until the lock is
72 * released.
73 *
74 * Returns: nothing
75 *
76 */
77
78void stdma_lock(irqreturn_t (*handler)(int, void *, struct pt_regs *),
79 void *data)
80{
81 unsigned long flags;
82
83 local_irq_save(flags); /* protect lock */
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_locked);
89
90 stdma_locked = 1;
91 stdma_isr = handler;
92 stdma_isr_data = data;
93 local_irq_restore(flags);
94}
95
96
97/*
98 * Function: void stdma_release( void )
99 *
100 * Purpose: Releases the lock on the ST-DMA chip.
101 *
102 * Inputs: none
103 *
104 * Returns: nothing
105 *
106 */
107
108void stdma_release(void)
109{
110 unsigned long flags;
111
112 local_irq_save(flags);
113
114 stdma_locked = 0;
115 stdma_isr = NULL;
116 stdma_isr_data = NULL;
117 wake_up(&stdma_wait);
118
119 local_irq_restore(flags);
120}
121
122
123/*
124 * Function: int stdma_others_waiting( void )
125 *
126 * Purpose: Check if someone waits for the ST-DMA lock.
127 *
128 * Inputs: none
129 *
130 * Returns: 0 if no one is waiting, != 0 otherwise
131 *
132 */
133
134int stdma_others_waiting(void)
135{
136 return waitqueue_active(&stdma_wait);
137}
138
139
140/*
141 * Function: int stdma_islocked( void )
142 *
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.
148 *
149 * Inputs: none
150 *
151 * Returns: != 0 if locked, 0 otherwise
152 *
153 */
154
155int stdma_islocked(void)
156{
157 return stdma_locked;
158}
159
160
161/*
162 * Function: void stdma_init( void )
163 *
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).
168 *
169 * Inputs: none
170 *
171 * Return: nothing
172 *
173 */
174
175void __init stdma_init(void)
176{
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);
180}
181
182
183/*
184 * Function: void stdma_int()
185 *
186 * Purpose: The interrupt routine for the ST-DMA. It calls the isr
187 * registered by stdma_lock().
188 *
189 */
190
191static irqreturn_t stdma_int(int irq, void *dummy, struct pt_regs *fp)
192{
193 if (stdma_isr)
194 (*stdma_isr)(irq, stdma_isr_data, fp);
195 return IRQ_HANDLED;
196}