4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
30 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
31 /* All Rights Reserved */
34 * This is the implementation of the kernel DMA interface for the
35 * AT Class machines using Intel 8237A DMAC.
37 * The following routines in the interface are implemented:
48 * i_dmae_get_best_mode()
49 * i_dmae_get_chan_stat()
53 #include <sys/types.h>
54 #include <sys/param.h>
57 #include <sys/sunddi.h>
58 #include <sys/cmn_err.h>
59 #include <sys/dma_engine.h>
60 #include <sys/dma_i8237A.h>
63 #include <sys/promif.h>
64 static int dmaedebug
= 0;
65 #define dprintf(x) if (dmaedebug) prom_printf x
71 static struct dmae_chnl dmae_stat
[NCHANS
];
72 static uintptr_t dmae_call_list
[NCHANS
] = {0, 0, 0, 0, 0, 0, 0, 0};
75 * routine: i_dmae_init()
76 * purpose: called to initialize the dma interface, the DMAC, and any
77 * dma data structures. Called during system initialization.
83 i_dmae_init(dev_info_t
*dip
)
87 dprintf(("i_dmae_init: initializing dma.\n"));
89 /* initialize semaphore map */
90 for (chnl
= 0; chnl
< NCHANS
; chnl
++) {
91 sema_init(&dmae_stat
[chnl
].dch_lock
, 1, NULL
, SEMA_DRIVER
,
94 return (d37A_init(dip
));
99 * routine: i_dmae_acquire()
100 * purpose: Request the semaphore for the indicated channel.
101 * A call_back function can be passed if caller does/cannot
102 * wait for the semaphore.
104 * calls: sema_p(), sema_tryp(), ddi_set_callback()
107 i_dmae_acquire(dev_info_t
*dip
, int chnl
, int (*dmae_waitfp
)(), caddr_t arg
)
112 dprintf(("i_dmae_acquire: channel %d, waitfp %p\n",
113 chnl
, (void *)dmae_waitfp
));
115 if (!d37A_dma_valid(chnl
))
116 return (DDI_FAILURE
);
118 if (dmae_waitfp
== DDI_DMA_SLEEP
) {
119 sema_p(&dmae_stat
[chnl
].dch_lock
);
120 } else if (sema_tryp(&dmae_stat
[chnl
].dch_lock
) == 0) {
121 if (dmae_waitfp
== DDI_DMA_DONTWAIT
) {
122 dprintf(("_dma_acquire: channel %d is busy.\n", chnl
));
124 ddi_set_callback(dmae_waitfp
, arg
,
125 &dmae_call_list
[chnl
]);
127 return (DDI_DMA_NORESOURCES
);
131 * XXX - save dip for authentication later ??
133 dprintf(("_dma_acquire: channel %d now allocated.\n", chnl
));
134 return (DDI_SUCCESS
);
139 * routine: i_dmae_free()
140 * purpose: Release the channel semaphore on chnl. Assumes caller actually
141 * owns the semaphore (no check made for this).
147 i_dmae_free(dev_info_t
*dip
, int chnl
)
152 dprintf(("i_dmae_free: channel %d\n", chnl
));
154 d37A_dma_release(chnl
);
156 * XXX - should dip be authenticated as the one that did acquire?
158 sema_v(&dmae_stat
[chnl
].dch_lock
);
160 if (dmae_call_list
[chnl
])
161 ddi_run_callback(&dmae_call_list
[chnl
]);
162 return (DDI_SUCCESS
);
166 * routine: i_dmae_get_best_mode()
167 * purpose: confirm that data is aligned for efficient flyby mode
168 * caller: driver routines.
169 * calls: d37A_get_best_mode.
173 i_dmae_get_best_mode(dev_info_t
*dip
, struct ddi_dmae_req
*dmaereqp
)
178 return (d37A_get_best_mode(dmaereqp
));
182 * routine: _dmae_nxcookie()
183 * purpose: service the interrupt by calling device driver routine for next
185 * caller: d37A_intr()
186 * calls: routine provided in request structure
190 _dmae_nxcookie(int chnl
)
192 ddi_dma_cookie_t
*cookiep
= NULL
;
194 dprintf(("_dmae_nxcookie: chnl %d\n", chnl
));
196 if (dmae_stat
[chnl
].proc
) {
198 cookiep
= dmae_stat
[chnl
].proc(dmae_stat
[chnl
].procparms
);
200 * expect a cookie pointer from user's routine;
201 * null cookie pointer will terminate chaining
209 * routine: i_dmae_prog()
210 * purpose: Program channel for the to_be_initiated_by_hardware operation.
211 * _dma_acquire is called to request the channel semaphore and
212 * mode is passed as the sleep parameter.
213 * The channel is enabled after it is setup.
214 * Note that the ddi_dmae_req pointer can be to NULL if the mode
215 * registers have already been setup by a prior call; this implements
216 * a prog_next() to update the address and count registers.
217 * caller: driver routines
218 * calls: d37A_prog_chan()
222 i_dmae_prog(dev_info_t
*dip
, struct ddi_dmae_req
*dmaereqp
,
223 ddi_dma_cookie_t
*cp
, int chnl
)
225 struct dmae_chnl
*dcp
;
231 rval
= d37A_prog_chan(dmaereqp
, cp
, chnl
);
232 if (rval
!= DDI_SUCCESS
) {
233 dprintf(("i_dmae_prog: failure on channel %d dmaereq=%p\n",
234 chnl
, (void *)dmaereqp
));
236 dprintf(("i_dmae_prog: channel %d dmaereq=%p\n",
237 chnl
, (void *)dmaereqp
));
238 dcp
= &dmae_stat
[chnl
];
239 dcp
->dch_cookiep
= cp
;
241 dcp
->proc
= dmaereqp
->proc
;
242 dcp
->procparms
= dmaereqp
->procparms
;
244 d37A_dma_enable(chnl
);
251 * routine: i_dmae_swsetup()
252 * purpose: Setup chan for the operation given in dmacbptr.
253 * _dma_acquire is first called
254 * to request the channel semaphore for chnl; mode is
255 * passed to _dma_acquire().
256 * caller: driver routines
257 * calls: d37A_dma_swsetup()
261 i_dmae_swsetup(dev_info_t
*dip
, struct ddi_dmae_req
*dmaereqp
,
262 ddi_dma_cookie_t
*cp
, int chnl
)
264 struct dmae_chnl
*dcp
;
270 rval
= d37A_dma_swsetup(dmaereqp
, cp
, chnl
);
271 if (rval
!= DDI_SUCCESS
) {
272 dprintf(("i_dmae_swsetup: failure on channel %d dmaereq=%p\n",
273 chnl
, (void *)dmaereqp
));
275 dprintf(("i_dmae_swsetup: channel %d: dmaereq=%p\n",
276 chnl
, (void *)dmaereqp
));
277 dcp
= &dmae_stat
[chnl
];
278 dcp
->dch_cookiep
= cp
;
279 dcp
->proc
= dmaereqp
->proc
;
280 dcp
->procparms
= dmaereqp
->procparms
;
287 * routine: i_dmae_swstart()
288 * purpose: Start the operation setup by i_dmae_swsetup().
289 * caller: driver routines
290 * calls: d37A_dma_swstart().
294 i_dmae_swstart(dev_info_t
*dip
, int chnl
)
299 dprintf(("i_dmae_swstart: channel %d.\n", chnl
));
301 d37A_dma_swstart(chnl
);
306 * routine: i_dmae_stop()
307 * purpose: stop DMA activity on chnl.
308 * caller: driver routines
309 * calls: splhi(), _dma_relse(), splx(),
314 i_dmae_stop(dev_info_t
*dip
, int chnl
)
319 dprintf(("i_dmae_stop: channel %d\n", chnl
));
321 /* call d37A the stop the channel */
324 dmae_stat
[chnl
].dch_cookiep
= NULL
;
329 * routine: i_dmae_enable()
330 * purpose: Allow the hardware tied to channel chnl to request service
331 * from the DMAC. i_dmae_prog() should have been called prior
333 * caller: driver routines.
334 * calls: d37A_dma_enable()
338 i_dmae_enable(dev_info_t
*dip
, int chnl
)
343 dprintf(("i_dmae_enable: channel %d\n", chnl
));
345 d37A_dma_enable(chnl
);
350 * routine: i_dmae_disable()
351 * purpose: Called to mask off hardware requests on channel chnl. Assumes
352 * the caller owns the channel.
353 * caller: driver routines.
354 * calls: d37A_dma_disable()
358 i_dmae_disable(dev_info_t
*dip
, int chnl
)
363 /* dprintf(("i_dmae_disable: disable channel %d.\n", chnl)); */
365 d37A_dma_disable(chnl
);
367 dmae_stat
[chnl
].dch_cookiep
= NULL
;
372 * routine: i_dmae_get_chan_stat()
373 * purpose: Obtain the current channel status from the DMAC
374 * caller: driver routines.
375 * calls: d37A_get_chan_stat()
379 i_dmae_get_chan_stat(dev_info_t
*dip
, int chnl
, ulong_t
*addressp
, int *countp
)
384 dprintf(("i_dmae_get_chan_stat: channel %d", chnl
));
386 d37A_get_chan_stat(chnl
, addressp
, countp
);