xref: /titanic_51/usr/src/uts/common/sys/dma_engine.h (revision b89e420ae1290e425c29db875ec0c0546006eec7)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22cd21e7c5SGarrett D'Amore 
23cd21e7c5SGarrett D'Amore /*
24*b89e420aSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25cd21e7c5SGarrett D'Amore  */
26cd21e7c5SGarrett D'Amore 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
297c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
337c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
347c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988, 1989 Intel Corp.			*/
377c478bd9Sstevel@tonic-gate /*		All Rights Reserved   				*/
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifndef	_SYS_DMAENGINE_H
407c478bd9Sstevel@tonic-gate #define	_SYS_DMAENGINE_H
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
467c478bd9Sstevel@tonic-gate extern "C" {
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	NCHANS	8
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * the DMA Engine Request structure
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate struct ddi_dmae_req {
557c478bd9Sstevel@tonic-gate 	dev_info_t *der_rdip;	/* original requester's dev_info_t */
567c478bd9Sstevel@tonic-gate 	uchar_t der_command;	/* Read/Write/Translate/Verify */
577c478bd9Sstevel@tonic-gate 	uchar_t der_bufprocess;	/* NoAuto_init/Chain/Auto_init */
587c478bd9Sstevel@tonic-gate 	uchar_t der_step;	/* Inc / Dec / Hold */
597c478bd9Sstevel@tonic-gate 	uchar_t der_trans;	/* Single/Demand/Block/Cascade */
607c478bd9Sstevel@tonic-gate 	uchar_t der_path;	/* 8/16/32 */
617c478bd9Sstevel@tonic-gate 	uchar_t der_cycles;	/* 1 or 2 */
627c478bd9Sstevel@tonic-gate 	uchar_t der_dest;	/* Memory / IO */
637c478bd9Sstevel@tonic-gate 	uchar_t der_arbus;	/* MicroChannel arbitration reg */
647c478bd9Sstevel@tonic-gate 	ushort_t der_ioadr;	/* MicroChannel i/o address reg */
657c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *(*proc)(); /* address of application call routine */
667c478bd9Sstevel@tonic-gate 	void *procparms;	/* parameter buffer for appl call */
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	DMAE_CMD_VRFY    0
707c478bd9Sstevel@tonic-gate #define	DMAE_CMD_WRITE   1	/* from memory to device */
717c478bd9Sstevel@tonic-gate #define	DMAE_CMD_READ    2	/* from device to memory */
727c478bd9Sstevel@tonic-gate #define	DMAE_CMD_TRAN    3
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	DMAE_BUF_NOAUTO  0	/* default */
757c478bd9Sstevel@tonic-gate #define	DMAE_BUF_CHAIN   0x1
767c478bd9Sstevel@tonic-gate #define	DMAE_BUF_AUTO    0x2
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	DMAE_STEP_INC    0	/* default */
797c478bd9Sstevel@tonic-gate #define	DMAE_STEP_DEC    1
807c478bd9Sstevel@tonic-gate #define	DMAE_STEP_HOLD   2
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	DMAE_TRANS_SNGL  0	/* default */
837c478bd9Sstevel@tonic-gate #define	DMAE_TRANS_BLCK  1
847c478bd9Sstevel@tonic-gate #define	DMAE_TRANS_DMND  2
857c478bd9Sstevel@tonic-gate #define	DMAE_TRANS_CSCD  3
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * For the EISA bus
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate #define	DMAE_PATH_DEF	0	/* default to ISA xfer width */
927c478bd9Sstevel@tonic-gate #define	DMAE_PATH_8	1	/* ISA default for chnl 0..3 */
937c478bd9Sstevel@tonic-gate #define	DMAE_PATH_16	2	/* ISA default for chnl 5..7 */
947c478bd9Sstevel@tonic-gate #define	DMAE_PATH_32	3
957c478bd9Sstevel@tonic-gate #define	DMAE_PATH_64	4
967c478bd9Sstevel@tonic-gate #define	DMAE_PATH_16B	5	/* 16-bit path but byte count */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	DMAE_CYCLES_1	0	/* Compatible timing */
997c478bd9Sstevel@tonic-gate #define	DMAE_CYCLES_2	1	/* Type "A" timing */
1007c478bd9Sstevel@tonic-gate #define	DMAE_CYCLES_3	2	/* Type "B" timing */
1017c478bd9Sstevel@tonic-gate #define	DMAE_CYCLES_4	3	/* Burst timing */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	DMAE_DEST_IO	0	/* default */
1047c478bd9Sstevel@tonic-gate #define	DMAE_DEST_MEM	1
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /* public function routines */
1097c478bd9Sstevel@tonic-gate extern int i_dmae_init(dev_info_t *);
1107c478bd9Sstevel@tonic-gate extern ddi_dma_cookie_t *_dmae_nxcookie(int);
1117c478bd9Sstevel@tonic-gate extern int i_dmae_acquire(dev_info_t *, int, int (*)(), caddr_t);
1127c478bd9Sstevel@tonic-gate extern int i_dmae_free(dev_info_t *, int);
1137c478bd9Sstevel@tonic-gate extern int i_dmae_prog(dev_info_t *, struct ddi_dmae_req *,
1147c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *, int);
1157c478bd9Sstevel@tonic-gate extern int i_dmae_swsetup(dev_info_t *, struct ddi_dmae_req *,
1167c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *, int);
1177c478bd9Sstevel@tonic-gate extern void i_dmae_swstart(dev_info_t *, int);
1187c478bd9Sstevel@tonic-gate extern void i_dmae_stop(dev_info_t *, int);
1197c478bd9Sstevel@tonic-gate extern void i_dmae_enable(dev_info_t *, int);
1207c478bd9Sstevel@tonic-gate extern void i_dmae_disable(dev_info_t *, int);
1217c478bd9Sstevel@tonic-gate extern void i_dmae_get_chan_stat(dev_info_t *dip, int chnl,
1227c478bd9Sstevel@tonic-gate 	ulong_t *addressp, int *countp);
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * the DMA Channel Block structure
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate struct dmae_chnl {
1287c478bd9Sstevel@tonic-gate 	ksema_t dch_lock;		/* semaphore for this channel */
1297c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *dch_cookiep;	/* current dma mapping cookie */
1307c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *(*proc)();	/* address of application call */
1317c478bd9Sstevel@tonic-gate 					/* routine */
1327c478bd9Sstevel@tonic-gate 	void *procparms;		/* parameter buffer for appl call */
1337c478bd9Sstevel@tonic-gate };
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * DMA Engine DDI functions
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * Get DMA engine attributes
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * The attributes of the DMA engine of the parent bus-nexus are copied into
1447c478bd9Sstevel@tonic-gate  * the provided structure. This should be called at driver attach time,
1457c478bd9Sstevel@tonic-gate  * rather than for each DMA bind.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate int ddi_dmae_getattr(dev_info_t *dip, ddi_dma_attr_t *attrp);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * DMA channel allocation
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  * The allocation function must be called prior to any other DMA engine
1547c478bd9Sstevel@tonic-gate  * function on a channel.  The channel should be freed after completion of the
1557c478bd9Sstevel@tonic-gate  * DMA / device operation if the channel is to be shared.
1567c478bd9Sstevel@tonic-gate  *
1577c478bd9Sstevel@tonic-gate  * Specifics of arguments to ddi_dmae_alloc:
1587c478bd9Sstevel@tonic-gate  *
1597c478bd9Sstevel@tonic-gate  * dip - dev_info pointer, which identifies the base device that wishes
1607c478bd9Sstevel@tonic-gate  * to use the DMA channel.
1617c478bd9Sstevel@tonic-gate  *
1627c478bd9Sstevel@tonic-gate  * chnl - a DMA channel number.
1637c478bd9Sstevel@tonic-gate  *
1647c478bd9Sstevel@tonic-gate  * dmae_waitfp - wait/callback_function pointer, which operates in the same
1657c478bd9Sstevel@tonic-gate  * manner as in ddi_dma_setup().  The value DDI_DMA_DONTWAIT will cause an
1667c478bd9Sstevel@tonic-gate  * immediate return if the channel cannot be acquired.  The value
1677c478bd9Sstevel@tonic-gate  * DDI_DMA_SLEEP will will cause the thread to sleep and not return until
1687c478bd9Sstevel@tonic-gate  * the channel has been acquired.  Any other value is assumed to be a
1697c478bd9Sstevel@tonic-gate  * callback function address.
1707c478bd9Sstevel@tonic-gate  *
1717c478bd9Sstevel@tonic-gate  * When resources might be available, the callback function is called
1727c478bd9Sstevel@tonic-gate  * (with the argument specified in arg) from interrupt context.
1737c478bd9Sstevel@tonic-gate  *
1747c478bd9Sstevel@tonic-gate  * When the callback function dmae_waitfp() is called, it should attempt to
1757c478bd9Sstevel@tonic-gate  * allocate the DMA channel again. If it succeeds or does not need the
1767c478bd9Sstevel@tonic-gate  * channel any more, it must return the value DDI_DMA_CALLBACK_DONE.
1777c478bd9Sstevel@tonic-gate  * If it does not want to allocate the channel, but instead wishes to be
1787c478bd9Sstevel@tonic-gate  * called back again later, it must return the value DDI_DMA_CALLBACK_LATER.
1797c478bd9Sstevel@tonic-gate  * If it tries to allocate the channel, but fails to do so, it must return the
1807c478bd9Sstevel@tonic-gate  * value DDI_DMA_CALLBACK_RUNOUT.
1817c478bd9Sstevel@tonic-gate  *
1827c478bd9Sstevel@tonic-gate  * Failure to observe this protocol will have unpredictable results.
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  * The callback function must provide its own data structure integrity
1857c478bd9Sstevel@tonic-gate  * when it is invoked.
1867c478bd9Sstevel@tonic-gate  */
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate int ddi_dmae_alloc(dev_info_t *dip, int chnl, int (*dmae_waitfp)(),
1897c478bd9Sstevel@tonic-gate     caddr_t arg);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * DMA channel deallocation
1937c478bd9Sstevel@tonic-gate  *
1947c478bd9Sstevel@tonic-gate  * The deallocation function should be called after completion of the
1957c478bd9Sstevel@tonic-gate  * DMA / device operation if the channel is to be shared.
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate int ddi_dmae_release(dev_info_t *dip, int chnl);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * DMA channel used in 1st party DMA scheme
2027c478bd9Sstevel@tonic-gate  *
2037c478bd9Sstevel@tonic-gate  * The specified channel will be configured to operate in a "slave" mode
2047c478bd9Sstevel@tonic-gate  * to a first_party DMA engine that also uses the channel.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate int ddi_dmae_1stparty(dev_info_t *dip, int chnl);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * Program DMA channel
2117c478bd9Sstevel@tonic-gate  *
2127c478bd9Sstevel@tonic-gate  * The DMA channel is setup for an operation using ddi_dmae_prog().
2137c478bd9Sstevel@tonic-gate  * This function is implemented to access all capabilities of the DMA engine
2147c478bd9Sstevel@tonic-gate  * hardware.  This function disables the channel prior to setup, and enables
2157c478bd9Sstevel@tonic-gate  * the channel before returning.
2167c478bd9Sstevel@tonic-gate  *
2177c478bd9Sstevel@tonic-gate  * Specifics of arguments to ddi_dmae_prog:
2187c478bd9Sstevel@tonic-gate  *
2197c478bd9Sstevel@tonic-gate  * dmaereqp - pointer to a DMA engine request structure. This structure
2207c478bd9Sstevel@tonic-gate  * is implementation specific and contains all the info necessary to
2217c478bd9Sstevel@tonic-gate  * setup the channel, except for the memory address and count.
2227c478bd9Sstevel@tonic-gate  * This structure is implemented with default values equal to zero,
2237c478bd9Sstevel@tonic-gate  * so that normally only der_command has to be set with a read or write
2247c478bd9Sstevel@tonic-gate  * command value.  Once the channel has been setup, subsequent calls to
2257c478bd9Sstevel@tonic-gate  * ddi_dmae_prog() can have dmaereqp set to NULL if only the address and
2267c478bd9Sstevel@tonic-gate  * count have to be updated.
2277c478bd9Sstevel@tonic-gate  *
228cd21e7c5SGarrett D'Amore  * cookiep - pointer to a ddi_dma_cookie object which contains address,
229cd21e7c5SGarrett D'Amore  * count and intermediate memory mapping information.
2307c478bd9Sstevel@tonic-gate  */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate int ddi_dmae_prog(dev_info_t *dip, struct ddi_dmae_req *dmaereqp,
2337c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *cookiep, int chnl);
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate int ddi_dmae_swsetup(dev_info_t *dip, struct ddi_dmae_req *dmaereqp,
2367c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *cookiep, int chnl);
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate int ddi_dmae_swstart(dev_info_t *dip, int chnl);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate  * Stop DMA channel
2427c478bd9Sstevel@tonic-gate  *
2437c478bd9Sstevel@tonic-gate  * The DMA channel is disabled and any active operation is terminated.
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate int ddi_dmae_stop(dev_info_t *dip, int chnl);
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate  * Enable DMA channel
2507c478bd9Sstevel@tonic-gate  *
2517c478bd9Sstevel@tonic-gate  * The DMA channel is enabled for operation.  The channel is also enabled
2527c478bd9Sstevel@tonic-gate  * after successful setup in ddi_dmae_prog().
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate int ddi_dmae_enable(dev_info_t *dip, int chnl);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * Disable DMA channel
2597c478bd9Sstevel@tonic-gate  *
2607c478bd9Sstevel@tonic-gate  * The DMA channel is disabled so that transfers cannot continue.
2617c478bd9Sstevel@tonic-gate  */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate int ddi_dmae_disable(dev_info_t *dip, int chnl);
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * Get remaining xfer count
2677c478bd9Sstevel@tonic-gate  *
2687c478bd9Sstevel@tonic-gate  * The count register of the DMA channel is read.  The channel is assumed
2697c478bd9Sstevel@tonic-gate  * to be stopped.
2707c478bd9Sstevel@tonic-gate  */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate int ddi_dmae_getcnt(dev_info_t *dip, int chnl, int *count);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate #endif
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate #endif	/* !_SYS_DMAENGINE_H */
279