1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/*
* This is the implementation of the kernel DMA interface for the
* AT Class machines using Intel 8237A DMAC.
*
* The following routines in the interface are implemented:
* i_dmae_init()
* _dmae_nxcookie()
* i_dmae_acquire()
* i_dmae_free()
* i_dmae_prog()
* i_dmae_swsetup()
* i_dmae_swstart()
* i_dmae_stop()
* i_dmae_enable()
* i_dmae_disable()
* i_dmae_get_best_mode()
* i_dmae_get_chan_stat()
*
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/kmem.h>
#include <sys/sunddi.h>
#include <sys/cmn_err.h>
#include <sys/dma_engine.h>
#include <sys/dma_i8237A.h>
#ifdef DEBUG
#include <sys/promif.h>
static int dmaedebug = 0;
#define dprintf(x) if (dmaedebug) prom_printf x
#else
#define dprintf(x)
#endif
static struct dmae_chnl dmae_stat[NCHANS];
static uintptr_t dmae_call_list[NCHANS] = {0, 0, 0, 0, 0, 0, 0, 0};
/*
* routine: i_dmae_init()
* purpose: called to initialize the dma interface, the DMAC, and any
* dma data structures. Called during system initialization.
* caller: main()
* calls: d37A_init()
*/
int
i_dmae_init(dev_info_t *dip)
{
int chnl;
dprintf(("i_dmae_init: initializing dma.\n"));
/* initialize semaphore map */
for (chnl = 0; chnl < NCHANS; chnl++) {
sema_init(&dmae_stat[chnl].dch_lock, 1, NULL, SEMA_DRIVER,
(void *)NULL);
}
return (d37A_init(dip));
}
/*
* routine: i_dmae_acquire()
* purpose: Request the semaphore for the indicated channel.
* A call_back function can be passed if caller does/cannot
* wait for the semaphore.
* caller: drivers
* calls: sema_p(), sema_tryp(), ddi_set_callback()
*/
int
i_dmae_acquire(dev_info_t *dip, int chnl, int (*dmae_waitfp)(), caddr_t arg)
{
#if defined(lint)
dip = dip;
#endif
dprintf(("i_dmae_acquire: channel %d, waitfp %p\n",
chnl, (void *)dmae_waitfp));
if (!d37A_dma_valid(chnl))
return (DDI_FAILURE);
if (dmae_waitfp == DDI_DMA_SLEEP) {
sema_p(&dmae_stat[chnl].dch_lock);
} else if (sema_tryp(&dmae_stat[chnl].dch_lock) == 0) {
if (dmae_waitfp == DDI_DMA_DONTWAIT) {
dprintf(("_dma_acquire: channel %d is busy.\n", chnl));
} else {
ddi_set_callback(dmae_waitfp, arg,
&dmae_call_list[chnl]);
}
return (DDI_DMA_NORESOURCES);
}
/*
* XXX - save dip for authentication later ??
*/
dprintf(("_dma_acquire: channel %d now allocated.\n", chnl));
return (DDI_SUCCESS);
}
/*
* routine: i_dmae_free()
* purpose: Release the channel semaphore on chnl. Assumes caller actually
* owns the semaphore (no check made for this).
* caller: drivers
* calls: none
*/
int
i_dmae_free(dev_info_t *dip, int chnl)
{
#if defined(lint)
dip = dip;
#endif
dprintf(("i_dmae_free: channel %d\n", chnl));
d37A_dma_release(chnl);
/*
* XXX - should dip be authenticated as the one that did acquire?
*/
sema_v(&dmae_stat[chnl].dch_lock);
if (dmae_call_list[chnl])
ddi_run_callback(&dmae_call_list[chnl]);
return (DDI_SUCCESS);
}
/*
* routine: i_dmae_get_best_mode()
* purpose: confirm that data is aligned for efficient flyby mode
* caller: driver routines.
* calls: d37A_get_best_mode.
*/
uchar_t
i_dmae_get_best_mode(dev_info_t *dip, struct ddi_dmae_req *dmaereqp)
{
#if defined(lint)
dip = dip;
#endif
return (d37A_get_best_mode(dmaereqp));
}
/*
* routine: _dmae_nxcookie()
* purpose: service the interrupt by calling device driver routine for next
* DMA cookie.
* caller: d37A_intr()
* calls: routine provided in request structure
*/
ddi_dma_cookie_t *
_dmae_nxcookie(int chnl)
{
ddi_dma_cookie_t *cookiep = NULL;
dprintf(("_dmae_nxcookie: chnl %d\n", chnl));
if (dmae_stat[chnl].proc) {
cookiep = dmae_stat[chnl].proc(dmae_stat[chnl].procparms);
/*
* expect a cookie pointer from user's routine;
* null cookie pointer will terminate chaining
*/
}
return (cookiep);
}
/*
* routine: i_dmae_prog()
* purpose: Program channel for the to_be_initiated_by_hardware operation.
* _dma_acquire is called to request the channel semaphore and
* mode is passed as the sleep parameter.
* The channel is enabled after it is setup.
* Note that the ddi_dmae_req pointer can be to NULL if the mode
* registers have already been setup by a prior call; this implements
* a prog_next() to update the address and count registers.
* caller: driver routines
* calls: d37A_prog_chan()
*/
int
i_dmae_prog(dev_info_t *dip, struct ddi_dmae_req *dmaereqp,
ddi_dma_cookie_t *cp, int chnl)
{
struct dmae_chnl *dcp;
int rval;
#if defined(lint)
dip = dip;
#endif
rval = d37A_prog_chan(dmaereqp, cp, chnl);
if (rval != DDI_SUCCESS) {
dprintf(("i_dmae_prog: failure on channel %d dmaereq=%p\n",
chnl, (void *)dmaereqp));
} else {
dprintf(("i_dmae_prog: channel %d dmaereq=%p\n",
chnl, (void *)dmaereqp));
dcp = &dmae_stat[chnl];
dcp->dch_cookiep = cp;
if (dmaereqp) {
dcp->proc = dmaereqp->proc;
dcp->procparms = dmaereqp->procparms;
}
d37A_dma_enable(chnl);
}
return (rval);
}
/*
* routine: i_dmae_swsetup()
* purpose: Setup chan for the operation given in dmacbptr.
* _dma_acquire is first called
* to request the channel semaphore for chnl; mode is
* passed to _dma_acquire().
* caller: driver routines
* calls: d37A_dma_swsetup()
*/
int
i_dmae_swsetup(dev_info_t *dip, struct ddi_dmae_req *dmaereqp,
ddi_dma_cookie_t *cp, int chnl)
{
struct dmae_chnl *dcp;
int rval;
#if defined(lint)
dip = dip;
#endif
rval = d37A_dma_swsetup(dmaereqp, cp, chnl);
if (rval != DDI_SUCCESS) {
dprintf(("i_dmae_swsetup: failure on channel %d dmaereq=%p\n",
chnl, (void *)dmaereqp));
} else {
dprintf(("i_dmae_swsetup: channel %d: dmaereq=%p\n",
chnl, (void *)dmaereqp));
dcp = &dmae_stat[chnl];
dcp->dch_cookiep = cp;
dcp->proc = dmaereqp->proc;
dcp->procparms = dmaereqp->procparms;
}
return (rval);
}
/*
* routine: i_dmae_swstart()
* purpose: Start the operation setup by i_dmae_swsetup().
* caller: driver routines
* calls: d37A_dma_swstart().
*/
void
i_dmae_swstart(dev_info_t *dip, int chnl)
{
#if defined(lint)
dip = dip;
#endif
dprintf(("i_dmae_swstart: channel %d.\n", chnl));
d37A_dma_swstart(chnl);
}
/*
* routine: i_dmae_stop()
* purpose: stop DMA activity on chnl.
* caller: driver routines
* calls: splhi(), _dma_relse(), splx(),
* d37A_dma_stop().
*/
void
i_dmae_stop(dev_info_t *dip, int chnl)
{
#if defined(lint)
dip = dip;
#endif
dprintf(("i_dmae_stop: channel %d\n", chnl));
/* call d37A the stop the channel */
d37A_dma_stop(chnl);
dmae_stat[chnl].dch_cookiep = NULL;
}
/*
* routine: i_dmae_enable()
* purpose: Allow the hardware tied to channel chnl to request service
* from the DMAC. i_dmae_prog() should have been called prior
* to this.
* caller: driver routines.
* calls: d37A_dma_enable()
*/
void
i_dmae_enable(dev_info_t *dip, int chnl)
{
#if defined(lint)
dip = dip;
#endif
dprintf(("i_dmae_enable: channel %d\n", chnl));
d37A_dma_enable(chnl);
}
/*
* routine: i_dmae_disable()
* purpose: Called to mask off hardware requests on channel chnl. Assumes
* the caller owns the channel.
* caller: driver routines.
* calls: d37A_dma_disable()
*/
void
i_dmae_disable(dev_info_t *dip, int chnl)
{
#if defined(lint)
dip = dip;
#endif
/* dprintf(("i_dmae_disable: disable channel %d.\n", chnl)); */
d37A_dma_disable(chnl);
dmae_stat[chnl].dch_cookiep = NULL;
}
/*
* routine: i_dmae_get_chan_stat()
* purpose: Obtain the current channel status from the DMAC
* caller: driver routines.
* calls: d37A_get_chan_stat()
*/
void
i_dmae_get_chan_stat(dev_info_t *dip, int chnl, ulong_t *addressp, int *countp)
{
#if defined(lint)
dip = dip;
#endif
dprintf(("i_dmae_get_chan_stat: channel %d", chnl));
d37A_get_chan_stat(chnl, addressp, countp);
}
|