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
)
109 dprintf(("i_dmae_acquire: channel %d, waitfp %p\n",
110 chnl
, (void *)dmae_waitfp
));
112 if (!d37A_dma_valid(chnl
))
113 return (DDI_FAILURE
);
115 if (dmae_waitfp
== DDI_DMA_SLEEP
) {
116 sema_p(&dmae_stat
[chnl
].dch_lock
);
117 } else if (sema_tryp(&dmae_stat
[chnl
].dch_lock
) == 0) {
118 if (dmae_waitfp
== DDI_DMA_DONTWAIT
) {
119 dprintf(("_dma_acquire: channel %d is busy.\n", chnl
));
121 ddi_set_callback(dmae_waitfp
, arg
,
122 &dmae_call_list
[chnl
]);
124 return (DDI_DMA_NORESOURCES
);
128 * XXX - save dip for authentication later ??
130 dprintf(("_dma_acquire: channel %d now allocated.\n", chnl
));
131 return (DDI_SUCCESS
);
136 * routine: i_dmae_free()
137 * purpose: Release the channel semaphore on chnl. Assumes caller actually
138 * owns the semaphore (no check made for this).
144 i_dmae_free(dev_info_t
*dip
, int chnl
)
146 dprintf(("i_dmae_free: channel %d\n", chnl
));
148 d37A_dma_release(chnl
);
150 * XXX - should dip be authenticated as the one that did acquire?
152 sema_v(&dmae_stat
[chnl
].dch_lock
);
154 if (dmae_call_list
[chnl
])
155 ddi_run_callback(&dmae_call_list
[chnl
]);
156 return (DDI_SUCCESS
);
160 * routine: i_dmae_get_best_mode()
161 * purpose: confirm that data is aligned for efficient flyby mode
162 * caller: driver routines.
163 * calls: d37A_get_best_mode.
167 i_dmae_get_best_mode(dev_info_t
*dip
, struct ddi_dmae_req
*dmaereqp
)
169 return (d37A_get_best_mode(dmaereqp
));
173 * routine: _dmae_nxcookie()
174 * purpose: service the interrupt by calling device driver routine for next
176 * caller: d37A_intr()
177 * calls: routine provided in request structure
181 _dmae_nxcookie(int chnl
)
183 ddi_dma_cookie_t
*cookiep
= NULL
;
185 dprintf(("_dmae_nxcookie: chnl %d\n", chnl
));
187 if (dmae_stat
[chnl
].proc
) {
189 cookiep
= dmae_stat
[chnl
].proc(dmae_stat
[chnl
].procparms
);
191 * expect a cookie pointer from user's routine;
192 * null cookie pointer will terminate chaining
200 * routine: i_dmae_prog()
201 * purpose: Program channel for the to_be_initiated_by_hardware operation.
202 * _dma_acquire is called to request the channel semaphore and
203 * mode is passed as the sleep parameter.
204 * The channel is enabled after it is setup.
205 * Note that the ddi_dmae_req pointer can be to NULL if the mode
206 * registers have already been setup by a prior call; this implements
207 * a prog_next() to update the address and count registers.
208 * caller: driver routines
209 * calls: d37A_prog_chan()
213 i_dmae_prog(dev_info_t
*dip
, struct ddi_dmae_req
*dmaereqp
,
214 ddi_dma_cookie_t
*cp
, int chnl
)
216 struct dmae_chnl
*dcp
;
219 rval
= d37A_prog_chan(dmaereqp
, cp
, chnl
);
220 if (rval
!= DDI_SUCCESS
) {
221 dprintf(("i_dmae_prog: failure on channel %d dmaereq=%p\n",
222 chnl
, (void *)dmaereqp
));
224 dprintf(("i_dmae_prog: channel %d dmaereq=%p\n",
225 chnl
, (void *)dmaereqp
));
226 dcp
= &dmae_stat
[chnl
];
227 dcp
->dch_cookiep
= cp
;
229 dcp
->proc
= dmaereqp
->proc
;
230 dcp
->procparms
= dmaereqp
->procparms
;
232 d37A_dma_enable(chnl
);
239 * routine: i_dmae_swsetup()
240 * purpose: Setup chan for the operation given in dmacbptr.
241 * _dma_acquire is first called
242 * to request the channel semaphore for chnl; mode is
243 * passed to _dma_acquire().
244 * caller: driver routines
245 * calls: d37A_dma_swsetup()
249 i_dmae_swsetup(dev_info_t
*dip
, struct ddi_dmae_req
*dmaereqp
,
250 ddi_dma_cookie_t
*cp
, int chnl
)
252 struct dmae_chnl
*dcp
;
255 rval
= d37A_dma_swsetup(dmaereqp
, cp
, chnl
);
256 if (rval
!= DDI_SUCCESS
) {
257 dprintf(("i_dmae_swsetup: failure on channel %d dmaereq=%p\n",
258 chnl
, (void *)dmaereqp
));
260 dprintf(("i_dmae_swsetup: channel %d: dmaereq=%p\n",
261 chnl
, (void *)dmaereqp
));
262 dcp
= &dmae_stat
[chnl
];
263 dcp
->dch_cookiep
= cp
;
264 dcp
->proc
= dmaereqp
->proc
;
265 dcp
->procparms
= dmaereqp
->procparms
;
272 * routine: i_dmae_swstart()
273 * purpose: Start the operation setup by i_dmae_swsetup().
274 * caller: driver routines
275 * calls: d37A_dma_swstart().
279 i_dmae_swstart(dev_info_t
*dip
, int chnl
)
281 dprintf(("i_dmae_swstart: channel %d.\n", chnl
));
283 d37A_dma_swstart(chnl
);
288 * routine: i_dmae_stop()
289 * purpose: stop DMA activity on chnl.
290 * caller: driver routines
291 * calls: splhi(), _dma_relse(), splx(),
296 i_dmae_stop(dev_info_t
*dip
, int chnl
)
298 dprintf(("i_dmae_stop: channel %d\n", chnl
));
300 /* call d37A the stop the channel */
303 dmae_stat
[chnl
].dch_cookiep
= NULL
;
308 * routine: i_dmae_enable()
309 * purpose: Allow the hardware tied to channel chnl to request service
310 * from the DMAC. i_dmae_prog() should have been called prior
312 * caller: driver routines.
313 * calls: d37A_dma_enable()
317 i_dmae_enable(dev_info_t
*dip
, int chnl
)
319 dprintf(("i_dmae_enable: channel %d\n", chnl
));
321 d37A_dma_enable(chnl
);
326 * routine: i_dmae_disable()
327 * purpose: Called to mask off hardware requests on channel chnl. Assumes
328 * the caller owns the channel.
329 * caller: driver routines.
330 * calls: d37A_dma_disable()
334 i_dmae_disable(dev_info_t
*dip
, int chnl
)
336 /* dprintf(("i_dmae_disable: disable channel %d.\n", chnl)); */
338 d37A_dma_disable(chnl
);
340 dmae_stat
[chnl
].dch_cookiep
= NULL
;
345 * routine: i_dmae_get_chan_stat()
346 * purpose: Obtain the current channel status from the DMAC
347 * caller: driver routines.
348 * calls: d37A_get_chan_stat()
352 i_dmae_get_chan_stat(dev_info_t
*dip
, int chnl
, ulong_t
*addressp
, int *countp
)
354 dprintf(("i_dmae_get_chan_stat: channel %d", chnl
));
356 d37A_get_chan_stat(chnl
, addressp
, countp
);