xref: /titanic_54/usr/src/uts/common/sys/ddidmareq.h (revision 50200e773f0242e336d032a7b43485e1bcfc9bfe)
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
525cf1a30Sjl139090  * Common Development and Distribution License (the "License").
625cf1a30Sjl139090  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*50200e77SFrank Van Der Linden  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_SYS_DDIDMAREQ_H
267c478bd9Sstevel@tonic-gate #define	_SYS_DDIDMAREQ_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * Memory Objects
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * Definitions of structures that can describe
367c478bd9Sstevel@tonic-gate  * an object that can be mapped for DMA.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Structure describing a virtual address
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate struct v_address {
437c478bd9Sstevel@tonic-gate 	caddr_t		v_addr;		/* base virtual address */
447c478bd9Sstevel@tonic-gate 	struct	as	*v_as;		/* pointer to address space */
457c478bd9Sstevel@tonic-gate 	void 		*v_priv;	/* priv data for shadow I/O */
467c478bd9Sstevel@tonic-gate };
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Structure describing a page-based address
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate struct pp_address {
527c478bd9Sstevel@tonic-gate 	/*
537c478bd9Sstevel@tonic-gate 	 * A pointer to a circularly linked list of page structures.
547c478bd9Sstevel@tonic-gate 	 */
557c478bd9Sstevel@tonic-gate 	struct page *pp_pp;
567c478bd9Sstevel@tonic-gate 	uint_t pp_offset;	/* offset within first page */
577c478bd9Sstevel@tonic-gate };
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Structure to describe a physical memory address.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate struct phy_address {
637c478bd9Sstevel@tonic-gate 	ulong_t	p_addr;		/* base physical address */
647c478bd9Sstevel@tonic-gate 	ulong_t	p_memtype;	/* memory type */
657c478bd9Sstevel@tonic-gate };
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
68*50200e77SFrank Van Der Linden  * Structure to describe an array DVMA addresses.
69*50200e77SFrank Van Der Linden  * Under normal circumstances, dv_nseg will be 1.
70*50200e77SFrank Van Der Linden  * dvs_start is always page aligned.
71*50200e77SFrank Van Der Linden  */
72*50200e77SFrank Van Der Linden struct dvma_address {
73*50200e77SFrank Van Der Linden 	size_t dv_off;
74*50200e77SFrank Van Der Linden 	size_t dv_nseg;
75*50200e77SFrank Van Der Linden 	struct dvmaseg {
76*50200e77SFrank Van Der Linden 		uint64_t dvs_start;
77*50200e77SFrank Van Der Linden 		size_t dvs_len;
78*50200e77SFrank Van Der Linden 	} *dv_seg;
79*50200e77SFrank Van Der Linden };
80*50200e77SFrank Van Der Linden 
81*50200e77SFrank Van Der Linden /*
827c478bd9Sstevel@tonic-gate  * A union of all of the above structures.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * This union describes the relationship between
857c478bd9Sstevel@tonic-gate  * the kind of an address description and an object.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate typedef union {
887c478bd9Sstevel@tonic-gate 	struct v_address virt_obj;	/* Some virtual address		*/
897c478bd9Sstevel@tonic-gate 	struct pp_address pp_obj;	/* Some page-based address	*/
907c478bd9Sstevel@tonic-gate 	struct phy_address phys_obj;	/* Some physical address	*/
91*50200e77SFrank Van Der Linden 	struct dvma_address dvma_obj;
927c478bd9Sstevel@tonic-gate } ddi_dma_aobj_t;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * DMA object types - used to select how the object
967c478bd9Sstevel@tonic-gate  * being mapped is being addressed by the IU.
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate typedef enum {
997c478bd9Sstevel@tonic-gate 	DMA_OTYP_VADDR = 0,	/* enforce starting value of zero */
1007c478bd9Sstevel@tonic-gate 	DMA_OTYP_PAGES,
1017c478bd9Sstevel@tonic-gate 	DMA_OTYP_PADDR,
102*50200e77SFrank Van Der Linden 	DMA_OTYP_BUFVADDR,
103*50200e77SFrank Van Der Linden 	DMA_OTYP_DVADDR
1047c478bd9Sstevel@tonic-gate } ddi_dma_atyp_t;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * A compact package to describe an object that is to be mapped for DMA.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate typedef struct {
1107c478bd9Sstevel@tonic-gate 	uint_t		dmao_size;	/* size, in bytes, of the object */
1117c478bd9Sstevel@tonic-gate 	ddi_dma_atyp_t	dmao_type;	/* type of object */
1127c478bd9Sstevel@tonic-gate 	ddi_dma_aobj_t	dmao_obj;	/* the object described */
1137c478bd9Sstevel@tonic-gate } ddi_dma_obj_t;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * DMA addressing limits.
1177c478bd9Sstevel@tonic-gate  *
1187c478bd9Sstevel@tonic-gate  * This structure describes the constraints that a particular device's
1197c478bd9Sstevel@tonic-gate  * DMA engine has to its parent so that the parent may correctly set
1207c478bd9Sstevel@tonic-gate  * things up for a DMA mapping. Each parent may in turn modify the
1217c478bd9Sstevel@tonic-gate  * constraints listed in a DMA request structure in order to describe
1227c478bd9Sstevel@tonic-gate  * to its parent any changed or additional constraints. The rules
1237c478bd9Sstevel@tonic-gate  * are that each parent may modify a constraint in order to further
1247c478bd9Sstevel@tonic-gate  * constrain things (e.g., picking a more limited address range than
1257c478bd9Sstevel@tonic-gate  * that permitted by the child), but that the parent may not ignore
1267c478bd9Sstevel@tonic-gate  * a child's constraints.
1277c478bd9Sstevel@tonic-gate  *
1287c478bd9Sstevel@tonic-gate  * A particular constraint that we do *not* address is whether or not
1297c478bd9Sstevel@tonic-gate  * a requested mapping is too large for a DMA engine's counter to
1307c478bd9Sstevel@tonic-gate  * correctly track. It is still up to each driver to explicitly handle
1317c478bd9Sstevel@tonic-gate  * transfers that are too large for its own hardware to deal with directly.
1327c478bd9Sstevel@tonic-gate  *
1337c478bd9Sstevel@tonic-gate  * The mapping routines that are cognizant of this structure will
1347c478bd9Sstevel@tonic-gate  * copy any user defined limits structure if they need to modify
1357c478bd9Sstevel@tonic-gate  * the fields (as alluded to above).
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  * A note as to how to define constraints:
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  * How you define the constraints for your device depends on how you
1407c478bd9Sstevel@tonic-gate  * define your device. For example, you may have an SBus card with a
1417c478bd9Sstevel@tonic-gate  * device on it that address only the bottom 16mb of virtual DMA space.
1427c478bd9Sstevel@tonic-gate  * However, if the card also has ancillary circuitry that pulls the high 8
1437c478bd9Sstevel@tonic-gate  * bits of address lines high, the more correct expression for your device
1447c478bd9Sstevel@tonic-gate  * is that it address [0xff000000..0xffffffff] rather than [0..0x00ffffff].
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate #if defined(__sparc)
1477c478bd9Sstevel@tonic-gate typedef struct ddi_dma_lim {
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	/*
1507c478bd9Sstevel@tonic-gate 	 * Low range of 32 bit addressing capability.
1517c478bd9Sstevel@tonic-gate 	 */
1527c478bd9Sstevel@tonic-gate 	uint_t	dlim_addr_lo;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	/*
1557c478bd9Sstevel@tonic-gate 	 * Upper inclusive bound of addressing capability. It is an
1567c478bd9Sstevel@tonic-gate 	 * inclusive boundary limit to allow for the addressing range
1577c478bd9Sstevel@tonic-gate 	 * [0..0xffffffff] to be specified in preference to [0..0].
1587c478bd9Sstevel@tonic-gate 	 */
1597c478bd9Sstevel@tonic-gate 	uint_t	dlim_addr_hi;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	/*
1627c478bd9Sstevel@tonic-gate 	 * Inclusive upper bound with which The DMA engine's counter acts as
1637c478bd9Sstevel@tonic-gate 	 * a register.
1647c478bd9Sstevel@tonic-gate 	 *
1657c478bd9Sstevel@tonic-gate 	 * This handles the case where an upper portion of a DMA address
1667c478bd9Sstevel@tonic-gate 	 * register is a latch instead of being a full 32 bit register
1677c478bd9Sstevel@tonic-gate 	 * (e.g., the upper 8 bits may remain constant while the lower
1687c478bd9Sstevel@tonic-gate 	 * 24 bits are the real address register).
1697c478bd9Sstevel@tonic-gate 	 *
1707c478bd9Sstevel@tonic-gate 	 * This essentially gives a hint about segment limitations
1717c478bd9Sstevel@tonic-gate 	 * to the mapping routines.
1727c478bd9Sstevel@tonic-gate 	 */
1737c478bd9Sstevel@tonic-gate 	uint_t	dlim_cntr_max;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/*
1767c478bd9Sstevel@tonic-gate 	 * DMA burst sizes.
1777c478bd9Sstevel@tonic-gate 	 *
1787c478bd9Sstevel@tonic-gate 	 * At the time of a mapping request, this tag defines the possible
1797c478bd9Sstevel@tonic-gate 	 * DMA burst cycle sizes that the requestor's DMA engine can
1807c478bd9Sstevel@tonic-gate 	 * emit. The format of the data is binary encoding of burst sizes
1817c478bd9Sstevel@tonic-gate 	 * assumed to be powers of two. That is, if a DMA engine is capable
1827c478bd9Sstevel@tonic-gate 	 * of doing 1, 2, 4 and 16 byte transfers, the encoding would be 0x17.
1837c478bd9Sstevel@tonic-gate 	 *
1847c478bd9Sstevel@tonic-gate 	 * As the mapping request is handled by intervening nexi, the
1857c478bd9Sstevel@tonic-gate 	 * burstsizes value may be modified. Prior to enabling DMA for
1867c478bd9Sstevel@tonic-gate 	 * the specific device, the driver that owns the DMA engine should
1877c478bd9Sstevel@tonic-gate 	 * check (via ddi_dma_burstsizes(9F)) what the allowed burstsizes
1887c478bd9Sstevel@tonic-gate 	 * have become and program their DMA engine appropriately.
1897c478bd9Sstevel@tonic-gate 	 */
1907c478bd9Sstevel@tonic-gate 	uint_t	dlim_burstsizes;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	/*
1937c478bd9Sstevel@tonic-gate 	 * Minimum effective DMA transfer size, in units of bytes.
1947c478bd9Sstevel@tonic-gate 	 *
1957c478bd9Sstevel@tonic-gate 	 * This value specifies the minimum effective granularity of the
1967c478bd9Sstevel@tonic-gate 	 * DMA engine. It is distinct from dlim_burtsizes in that it
1977c478bd9Sstevel@tonic-gate 	 * describes the minimum amount of access a DMA transfer will
1987c478bd9Sstevel@tonic-gate 	 * effect. dlim_burtsizes describes in what electrical fashion
1997c478bd9Sstevel@tonic-gate 	 * the DMA engine might perform its accesses, while dlim_minxfer
2007c478bd9Sstevel@tonic-gate 	 * describes the minimum amount of memory that can be touched by
2017c478bd9Sstevel@tonic-gate 	 * the DMA transfer.
2027c478bd9Sstevel@tonic-gate 	 *
2037c478bd9Sstevel@tonic-gate 	 * As the mapping request is handled by intervening nexi, the
2047c478bd9Sstevel@tonic-gate 	 * dlim_minxfer value may be modifed contingent upon the presence
2057c478bd9Sstevel@tonic-gate 	 * (and use) of I/O caches and DMA write buffers in between the
2067c478bd9Sstevel@tonic-gate 	 * DMA engine and the object that DMA is being performed on.
2077c478bd9Sstevel@tonic-gate 	 *
2087c478bd9Sstevel@tonic-gate 	 */
2097c478bd9Sstevel@tonic-gate 	uint_t	dlim_minxfer;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	/*
2127c478bd9Sstevel@tonic-gate 	 * Expected average data rate for this DMA engine
2137c478bd9Sstevel@tonic-gate 	 * while transferring data.
2147c478bd9Sstevel@tonic-gate 	 *
2157c478bd9Sstevel@tonic-gate 	 * This is used as a hint for a number of operations that might
2167c478bd9Sstevel@tonic-gate 	 * want to know the possible optimal latency requirements of this
2177c478bd9Sstevel@tonic-gate 	 * device. A value of zero will be interpreted as a 'do not care'.
2187c478bd9Sstevel@tonic-gate 	 */
2197c478bd9Sstevel@tonic-gate 	uint_t	dlim_dmaspeed;
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate } ddi_dma_lim_t;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #elif defined(__x86)
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * values for dlim_minxfer
2277c478bd9Sstevel@tonic-gate  */
2287c478bd9Sstevel@tonic-gate #define	DMA_UNIT_8  1
2297c478bd9Sstevel@tonic-gate #define	DMA_UNIT_16 2
2307c478bd9Sstevel@tonic-gate #define	DMA_UNIT_32 4
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * Version number
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate #define	DMALIM_VER0	((0x86000000) + 0)
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate typedef struct ddi_dma_lim {
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	/*
2407c478bd9Sstevel@tonic-gate 	 * Low range of 32 bit addressing capability.
2417c478bd9Sstevel@tonic-gate 	 */
2427c478bd9Sstevel@tonic-gate 	uint_t	dlim_addr_lo;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	/*
2457c478bd9Sstevel@tonic-gate 	 * Upper Inclusive bound of 32 bit addressing capability.
2467c478bd9Sstevel@tonic-gate 	 *
2477c478bd9Sstevel@tonic-gate 	 * The ISA nexus restricts this to 0x00ffffff, since this bus has
2487c478bd9Sstevel@tonic-gate 	 * only 24 address lines.  This enforces the 16 Mb address limitation.
2497c478bd9Sstevel@tonic-gate 	 * The EISA nexus restricts this to 0xffffffff.
2507c478bd9Sstevel@tonic-gate 	 */
2517c478bd9Sstevel@tonic-gate 	uint_t	dlim_addr_hi;
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	/*
2547c478bd9Sstevel@tonic-gate 	 * DMA engine counter not used; set to 0
2557c478bd9Sstevel@tonic-gate 	 */
2567c478bd9Sstevel@tonic-gate 	uint_t	dlim_cntr_max;
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	/*
2597c478bd9Sstevel@tonic-gate 	 *  DMA burst sizes not used; set to 1
2607c478bd9Sstevel@tonic-gate 	 */
2617c478bd9Sstevel@tonic-gate 	uint_t	dlim_burstsizes;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	/*
2647c478bd9Sstevel@tonic-gate 	 * Minimum effective DMA transfer size.
2657c478bd9Sstevel@tonic-gate 	 *
2667c478bd9Sstevel@tonic-gate 	 * This value specifies the minimum effective granularity of the
2677c478bd9Sstevel@tonic-gate 	 * DMA engine. It is distinct from dlim_burstsizes in that it
2687c478bd9Sstevel@tonic-gate 	 * describes the minimum amount of access a DMA transfer will
2697c478bd9Sstevel@tonic-gate 	 * effect. dlim_burstsizes describes in what electrical fashion
2707c478bd9Sstevel@tonic-gate 	 * the DMA engine might perform its accesses, while dlim_minxfer
2717c478bd9Sstevel@tonic-gate 	 * describes the minimum amount of memory that can be touched by
2727c478bd9Sstevel@tonic-gate 	 * the DMA transfer.
2737c478bd9Sstevel@tonic-gate 	 *
2747c478bd9Sstevel@tonic-gate 	 * This value also implies the required address alignment.
2757c478bd9Sstevel@tonic-gate 	 * The number of bytes transferred is assumed to be
2767c478bd9Sstevel@tonic-gate 	 * 	dlim_minxfer * (DMA engine count)
2777c478bd9Sstevel@tonic-gate 	 *
2787c478bd9Sstevel@tonic-gate 	 * It should be set to DMA_UNIT_8, DMA_UNIT_16, or DMA_UNIT_32.
2797c478bd9Sstevel@tonic-gate 	 */
2807c478bd9Sstevel@tonic-gate 	uint_t	dlim_minxfer;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	/*
2837c478bd9Sstevel@tonic-gate 	 * Expected average data rate for this DMA engine
2847c478bd9Sstevel@tonic-gate 	 * while transferring data.
2857c478bd9Sstevel@tonic-gate 	 *
2867c478bd9Sstevel@tonic-gate 	 * This is used as a hint for a number of operations that might
2877c478bd9Sstevel@tonic-gate 	 * want to know the possible optimal latency requirements of this
2887c478bd9Sstevel@tonic-gate 	 * device. A value of zero will be interpreted as a 'do not care'.
2897c478bd9Sstevel@tonic-gate 	 */
2907c478bd9Sstevel@tonic-gate 	uint_t	dlim_dmaspeed;
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	/*
2947c478bd9Sstevel@tonic-gate 	 * Version number of this structure
2957c478bd9Sstevel@tonic-gate 	 */
2967c478bd9Sstevel@tonic-gate 	uint_t	dlim_version;	/* = 0x86 << 24 + 0 */
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	/*
2997c478bd9Sstevel@tonic-gate 	 * Inclusive upper bound with which the DMA engine's Address acts as
3007c478bd9Sstevel@tonic-gate 	 * a register.
3017c478bd9Sstevel@tonic-gate 	 * This handles the case where an upper portion of a DMA address
3027c478bd9Sstevel@tonic-gate 	 * register is a latch instead of being a full 32 bit register
3037c478bd9Sstevel@tonic-gate 	 * (e.g., the upper 16 bits remain constant while the lower 16 bits
3047c478bd9Sstevel@tonic-gate 	 * are incremented for each DMA transfer).
3057c478bd9Sstevel@tonic-gate 	 *
3067c478bd9Sstevel@tonic-gate 	 * The ISA nexus restricts only 3rd-party DMA requests to 0x0000ffff,
3077c478bd9Sstevel@tonic-gate 	 * since the ISA DMA engine has a 16-bit register for low address and
3087c478bd9Sstevel@tonic-gate 	 * an 8-bit latch for high address.  This enforces the first 64 Kb
3097c478bd9Sstevel@tonic-gate 	 * limitation (address boundary).
3107c478bd9Sstevel@tonic-gate 	 * The EISA nexus restricts only 3rd-party DMA requests to 0xffffffff.
3117c478bd9Sstevel@tonic-gate 	 */
3127c478bd9Sstevel@tonic-gate 	uint_t	dlim_adreg_max;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	/*
3157c478bd9Sstevel@tonic-gate 	 * Maximum transfer count that the DMA engine can handle.
3167c478bd9Sstevel@tonic-gate 	 *
3177c478bd9Sstevel@tonic-gate 	 * The ISA nexus restricts only 3rd-party DMA requests to 0x0000ffff,
3187c478bd9Sstevel@tonic-gate 	 * since the ISA DMA engine has a 16-bit register for counting.
3197c478bd9Sstevel@tonic-gate 	 * This enforces the other 64 Kb limitation (count size).
3207c478bd9Sstevel@tonic-gate 	 * The EISA nexus restricts only 3rd-party DMA requests to 0x00ffffff,
3217c478bd9Sstevel@tonic-gate 	 * since the EISA DMA engine has a 24-bit register for counting.
3227c478bd9Sstevel@tonic-gate 	 *
3237c478bd9Sstevel@tonic-gate 	 * This transfer count limitation is a per segment limitation.
3247c478bd9Sstevel@tonic-gate 	 * It can also be used to restrict the size of segments.
3257c478bd9Sstevel@tonic-gate 	 *
3267c478bd9Sstevel@tonic-gate 	 * This is used as a bit mask, so it must be a power of 2, minus 1.
3277c478bd9Sstevel@tonic-gate 	 */
3287c478bd9Sstevel@tonic-gate 	uint_t	dlim_ctreg_max;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	/*
3317c478bd9Sstevel@tonic-gate 	 * Granularity of DMA transfer, in units of bytes.
3327c478bd9Sstevel@tonic-gate 	 *
3337c478bd9Sstevel@tonic-gate 	 * Breakup sizes must be multiples of this value.
3347c478bd9Sstevel@tonic-gate 	 * If no scatter/gather capabilty is specified, then the size of
3357c478bd9Sstevel@tonic-gate 	 * each DMA transfer must be a multiple of this value.
3367c478bd9Sstevel@tonic-gate 	 *
3377c478bd9Sstevel@tonic-gate 	 * If there is scatter/gather capability, then a single cookie cannot
3387c478bd9Sstevel@tonic-gate 	 * be smaller in size than the minimum xfer value, and may be less
3397c478bd9Sstevel@tonic-gate 	 * than the granularity value.  The total transfer length of the
3407c478bd9Sstevel@tonic-gate 	 * scatter/gather list should be a multiple of the granularity value;
3417c478bd9Sstevel@tonic-gate 	 * use dlim_sgllen to specify the length of the scatter/gather list.
3427c478bd9Sstevel@tonic-gate 	 *
3437c478bd9Sstevel@tonic-gate 	 * This value should be equal to the sector size of the device.
3447c478bd9Sstevel@tonic-gate 	 */
3457c478bd9Sstevel@tonic-gate 	uint_t	dlim_granular;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	/*
3487c478bd9Sstevel@tonic-gate 	 * Length of scatter/gather list
3497c478bd9Sstevel@tonic-gate 	 *
3507c478bd9Sstevel@tonic-gate 	 * This value specifies the number of segments or cookies that a DMA
3517c478bd9Sstevel@tonic-gate 	 * engine can consume in one i/o request to the device.  For 3rd-party
3527c478bd9Sstevel@tonic-gate 	 * DMA that uses the bus nexus this should be set to 1.  Devices with
3537c478bd9Sstevel@tonic-gate 	 * 1st-party DMA capability should specify the number of entries in
3547c478bd9Sstevel@tonic-gate 	 * its scatter/gather list.  The breakup routine will ensure that each
3557c478bd9Sstevel@tonic-gate 	 * group of dlim_sgllen cookies (within a DMA window) will have a
3567c478bd9Sstevel@tonic-gate 	 * total transfer length that is a multiple of dlim_granular.
3577c478bd9Sstevel@tonic-gate 	 *
3587c478bd9Sstevel@tonic-gate 	 *	< 0  :  tbd
3597c478bd9Sstevel@tonic-gate 	 *	= 0  :  breakup is for PIO.
3607c478bd9Sstevel@tonic-gate 	 *	= 1  :  breakup is for DMA engine with no scatter/gather
3617c478bd9Sstevel@tonic-gate 	 *		capability.
3627c478bd9Sstevel@tonic-gate 	 *	>= 2 :  breakup is for DMA engine with scatter/gather
3637c478bd9Sstevel@tonic-gate 	 *		capability; value is max number of entries in list.
3647c478bd9Sstevel@tonic-gate 	 *
3657c478bd9Sstevel@tonic-gate 	 * Note that this list length is not dependent on the DMA window
3667c478bd9Sstevel@tonic-gate 	 * size.  The size of the DMA window is based on resources consumed,
3677c478bd9Sstevel@tonic-gate 	 * such as intermediate buffers.  Several s/g lists may exist within
3687c478bd9Sstevel@tonic-gate 	 * a window.  But the end of a window does imply the end of the s/g
3697c478bd9Sstevel@tonic-gate 	 * list.
3707c478bd9Sstevel@tonic-gate 	 */
3717c478bd9Sstevel@tonic-gate 	short	dlim_sgllen;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	/*
3747c478bd9Sstevel@tonic-gate 	 * Size of device i/o request
3757c478bd9Sstevel@tonic-gate 	 *
3767c478bd9Sstevel@tonic-gate 	 * This value indicates the maximum number of bytes the device
3777c478bd9Sstevel@tonic-gate 	 * can transmit/receive for one i/o command.  This limitation is
3787c478bd9Sstevel@tonic-gate 	 * significant ony if it is less than (dlim_ctreg_max * dlim_sgllen).
3797c478bd9Sstevel@tonic-gate 	 */
3807c478bd9Sstevel@tonic-gate 	uint_t	dlim_reqsize;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate } ddi_dma_lim_t;
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate #else
3857c478bd9Sstevel@tonic-gate #error "struct ddi_dma_lim not defined for this architecture"
3867c478bd9Sstevel@tonic-gate #endif	/* defined(__sparc) */
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate  * Flags definition for dma_attr_flags
3907c478bd9Sstevel@tonic-gate  */
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate  * return physical DMA address on platforms
3947c478bd9Sstevel@tonic-gate  * which support DVMA
3957c478bd9Sstevel@tonic-gate  */
3967c478bd9Sstevel@tonic-gate #define	DDI_DMA_FORCE_PHYSICAL		0x0100
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  * An error will be flagged for DMA data path errors
4007c478bd9Sstevel@tonic-gate  */
4017c478bd9Sstevel@tonic-gate #define	DDI_DMA_FLAGERR			0x200
4027c478bd9Sstevel@tonic-gate 
40325cf1a30Sjl139090 /*
40425cf1a30Sjl139090  * Enable relaxed ordering
40525cf1a30Sjl139090  */
40625cf1a30Sjl139090 #define	DDI_DMA_RELAXED_ORDERING	0x400
40725cf1a30Sjl139090 
40807c6692fSMark Johnson 
40907c6692fSMark Johnson /*
41007c6692fSMark Johnson  * Consolidation private x86 only flag which will cause a bounce buffer
41107c6692fSMark Johnson  * (paddr < dma_attr_seg) to be used if the buffer passed to the bind
41207c6692fSMark Johnson  * operation contains pages both above and below dma_attr_seg. If this flag
41307c6692fSMark Johnson  * is set, dma_attr_seg must be <= dma_attr_addr_hi.
41407c6692fSMark Johnson  */
41507c6692fSMark Johnson #define	_DDI_DMA_BOUNCE_ON_SEG		0x8000
41607c6692fSMark Johnson 
4177c478bd9Sstevel@tonic-gate #define	DMA_ATTR_V0		0
4187c478bd9Sstevel@tonic-gate #define	DMA_ATTR_VERSION	DMA_ATTR_V0
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate typedef struct ddi_dma_attr {
4217c478bd9Sstevel@tonic-gate 	uint_t		dma_attr_version;	/* version number */
4227c478bd9Sstevel@tonic-gate 	uint64_t	dma_attr_addr_lo;	/* low DMA address range */
4237c478bd9Sstevel@tonic-gate 	uint64_t	dma_attr_addr_hi;	/* high DMA address range */
4247c478bd9Sstevel@tonic-gate 	uint64_t	dma_attr_count_max;	/* DMA counter register */
4257c478bd9Sstevel@tonic-gate 	uint64_t	dma_attr_align;		/* DMA address alignment */
4267c478bd9Sstevel@tonic-gate 	uint_t		dma_attr_burstsizes;	/* DMA burstsizes */
4277c478bd9Sstevel@tonic-gate 	uint32_t	dma_attr_minxfer;	/* min effective DMA size */
4287c478bd9Sstevel@tonic-gate 	uint64_t 	dma_attr_maxxfer;	/* max DMA xfer size */
4297c478bd9Sstevel@tonic-gate 	uint64_t 	dma_attr_seg;		/* segment boundary */
4307c478bd9Sstevel@tonic-gate 	int		dma_attr_sgllen;	/* s/g length */
4317c478bd9Sstevel@tonic-gate 	uint32_t	dma_attr_granular;	/* granularity of device */
4327c478bd9Sstevel@tonic-gate 	uint_t		dma_attr_flags;		/* Bus specific DMA flags */
4337c478bd9Sstevel@tonic-gate } ddi_dma_attr_t;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate /*
4367c478bd9Sstevel@tonic-gate  * Handy macro to set a maximum bit value (should be elsewhere)
4377c478bd9Sstevel@tonic-gate  *
4387c478bd9Sstevel@tonic-gate  * Clear off all bits lower then 'mybit' in val; if there are no
4397c478bd9Sstevel@tonic-gate  * bits higher than or equal to mybit in val then set mybit. Assumes
4407c478bd9Sstevel@tonic-gate  * mybit equals some power of 2 and is not zero.
4417c478bd9Sstevel@tonic-gate  */
4427c478bd9Sstevel@tonic-gate #define	maxbit(val, mybit)	\
4437c478bd9Sstevel@tonic-gate 	((val) & ~((mybit)-1)) | ((((val) & ~((mybit)-1)) == 0) ? (mybit) : 0)
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate /*
4467c478bd9Sstevel@tonic-gate  * Handy macro to set a minimum bit value (should be elsewhere)
4477c478bd9Sstevel@tonic-gate  *
4487c478bd9Sstevel@tonic-gate  * Clear off all bits higher then 'mybit' in val; if there are no
4497c478bd9Sstevel@tonic-gate  * bits lower than or equal to mybit in val then set mybit. Assumes
4507c478bd9Sstevel@tonic-gate  * mybit equals some pow2 and is not zero.
4517c478bd9Sstevel@tonic-gate  */
4527c478bd9Sstevel@tonic-gate #define	minbit(val, mybit)	\
4537c478bd9Sstevel@tonic-gate 	(((val)&((mybit)|((mybit)-1))) | \
4547c478bd9Sstevel@tonic-gate 	((((val) & ((mybit)-1)) == 0) ? (mybit) : 0))
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate  * Structure of a request to map an object for DMA.
4587c478bd9Sstevel@tonic-gate  */
4597c478bd9Sstevel@tonic-gate typedef struct ddi_dma_req {
4607c478bd9Sstevel@tonic-gate 	/*
4617c478bd9Sstevel@tonic-gate 	 * Caller's DMA engine constraints.
4627c478bd9Sstevel@tonic-gate 	 *
4637c478bd9Sstevel@tonic-gate 	 * If there are no particular constraints to the caller's DMA
4647c478bd9Sstevel@tonic-gate 	 * engine, this field may be set to NULL. The implementation DMA
4657c478bd9Sstevel@tonic-gate 	 * setup functions will then select a set of standard beginning
4667c478bd9Sstevel@tonic-gate 	 * constraints.
4677c478bd9Sstevel@tonic-gate 	 *
4687c478bd9Sstevel@tonic-gate 	 * In either case, as the mapping proceeds, the initial DMA
4697c478bd9Sstevel@tonic-gate 	 * constraints may become more restrictive as each intervening
4707c478bd9Sstevel@tonic-gate 	 * nexus might add further restrictions.
4717c478bd9Sstevel@tonic-gate 	 */
4727c478bd9Sstevel@tonic-gate 	ddi_dma_lim_t	*dmar_limits;
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	/*
4757c478bd9Sstevel@tonic-gate 	 * Contains the information passed to the DMA mapping allocation
4767c478bd9Sstevel@tonic-gate 	 * routine(s).
4777c478bd9Sstevel@tonic-gate 	 */
4787c478bd9Sstevel@tonic-gate 	uint_t		dmar_flags;
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	/*
4817c478bd9Sstevel@tonic-gate 	 * Callback function. A caller of the DMA mapping functions must
4827c478bd9Sstevel@tonic-gate 	 * specify by filling in this field whether the allocation routines
4837c478bd9Sstevel@tonic-gate 	 * can sleep awaiting mapping resources, must *not* sleep awaiting
4847c478bd9Sstevel@tonic-gate 	 * resources, or may *not* sleep awaiting any resources and must
4857c478bd9Sstevel@tonic-gate 	 * call the function specified by dmar_fp with the the argument
4867c478bd9Sstevel@tonic-gate 	 * dmar_arg when resources might have become available at a future
4877c478bd9Sstevel@tonic-gate 	 * time.
4887c478bd9Sstevel@tonic-gate 	 */
4897c478bd9Sstevel@tonic-gate 	int		(*dmar_fp)();
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	caddr_t		dmar_arg;	/* Callback function argument */
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	/*
4947c478bd9Sstevel@tonic-gate 	 * Description of the object to be mapped for DMA.
4957c478bd9Sstevel@tonic-gate 	 * Must be last in this structure in case that the
4967c478bd9Sstevel@tonic-gate 	 * union ddi_dma_obj_t changes in the future.
4977c478bd9Sstevel@tonic-gate 	 */
4987c478bd9Sstevel@tonic-gate 	ddi_dma_obj_t	dmar_object;
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate } ddi_dma_req_t;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate  * Defines for the DMA mapping allocation functions
5047c478bd9Sstevel@tonic-gate  *
5057c478bd9Sstevel@tonic-gate  * If a DMA callback funtion is set to anything other than the following
5067c478bd9Sstevel@tonic-gate  * defines then it is assumed that one wishes a callback and is providing
5077c478bd9Sstevel@tonic-gate  * a function address.
5087c478bd9Sstevel@tonic-gate  */
5097c478bd9Sstevel@tonic-gate #ifdef __STDC__
5107c478bd9Sstevel@tonic-gate #define	DDI_DMA_DONTWAIT	((int (*)(caddr_t))0)
5117c478bd9Sstevel@tonic-gate #define	DDI_DMA_SLEEP		((int (*)(caddr_t))1)
5127c478bd9Sstevel@tonic-gate #else
5137c478bd9Sstevel@tonic-gate #define	DDI_DMA_DONTWAIT	((int (*)())0)
5147c478bd9Sstevel@tonic-gate #define	DDI_DMA_SLEEP		((int (*)())1)
5157c478bd9Sstevel@tonic-gate #endif
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate /*
5187c478bd9Sstevel@tonic-gate  * Return values from callback functions.
5197c478bd9Sstevel@tonic-gate  */
5207c478bd9Sstevel@tonic-gate #define	DDI_DMA_CALLBACK_RUNOUT	0
5217c478bd9Sstevel@tonic-gate #define	DDI_DMA_CALLBACK_DONE	1
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /*
5247c478bd9Sstevel@tonic-gate  * Flag definitions for the allocation functions.
5257c478bd9Sstevel@tonic-gate  */
5267c478bd9Sstevel@tonic-gate #define	DDI_DMA_WRITE		0x0001	/* Direction memory --> IO 	*/
5277c478bd9Sstevel@tonic-gate #define	DDI_DMA_READ		0x0002	/* Direction IO --> memory	*/
5287c478bd9Sstevel@tonic-gate #define	DDI_DMA_RDWR		(DDI_DMA_READ | DDI_DMA_WRITE)
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate /*
5317c478bd9Sstevel@tonic-gate  * If possible, establish a MMU redzone after the mapping (to protect
5327c478bd9Sstevel@tonic-gate  * against cheap DMA hardware that might get out of control).
5337c478bd9Sstevel@tonic-gate  */
5347c478bd9Sstevel@tonic-gate #define	DDI_DMA_REDZONE		0x0004
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate /*
5377c478bd9Sstevel@tonic-gate  * A partial allocation is allowed. That is, if the size of the object
5387c478bd9Sstevel@tonic-gate  * exceeds the mapping resources available, only map a portion of the
5397c478bd9Sstevel@tonic-gate  * object and return status indicating that this took place. The caller
5407c478bd9Sstevel@tonic-gate  * can use the functions ddi_dma_numwin(9F) and ddi_dma_getwin(9F) to
5417c478bd9Sstevel@tonic-gate  * change, at a later point, the actual mapped portion of the object.
5427c478bd9Sstevel@tonic-gate  *
5437c478bd9Sstevel@tonic-gate  * The mapped portion begins at offset 0 of the object.
5447c478bd9Sstevel@tonic-gate  *
5457c478bd9Sstevel@tonic-gate  */
5467c478bd9Sstevel@tonic-gate #define	DDI_DMA_PARTIAL		0x0008
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate /*
5497c478bd9Sstevel@tonic-gate  * Map the object for byte consistent access. Note that explicit
5507c478bd9Sstevel@tonic-gate  * synchronization (via ddi_dma_sync(9F)) will still be required.
5517c478bd9Sstevel@tonic-gate  * Consider this flag to be a hint to the mapping routines as to
5527c478bd9Sstevel@tonic-gate  * the intended use of the mapping.
5537c478bd9Sstevel@tonic-gate  *
5547c478bd9Sstevel@tonic-gate  * Normal data transfers can be usually consider to use 'streaming'
5557c478bd9Sstevel@tonic-gate  * modes of operations. They start at a specific point, transfer a
5567c478bd9Sstevel@tonic-gate  * fairly large amount of data sequentially, and then stop (usually
5577c478bd9Sstevel@tonic-gate  * on a well aligned boundary).
5587c478bd9Sstevel@tonic-gate  *
5597c478bd9Sstevel@tonic-gate  * Control mode data transfers (for memory resident device control blocks,
5607c478bd9Sstevel@tonic-gate  * e.g., ethernet message descriptors) do not access memory in such
5617c478bd9Sstevel@tonic-gate  * a streaming sequential fashion. Instead, they tend to modify a few
5627c478bd9Sstevel@tonic-gate  * words or bytes, move around and maybe modify a few more.
5637c478bd9Sstevel@tonic-gate  *
5647c478bd9Sstevel@tonic-gate  * There are many machine implementations that make this difficult to
5657c478bd9Sstevel@tonic-gate  * control in a generic and seamless fashion. Therefore, explicit synch-
5667c478bd9Sstevel@tonic-gate  * ronization steps (via ddi_dma_sync(9F)) are still required (even if you
5677c478bd9Sstevel@tonic-gate  * ask for a byte-consistent mapping) in order to make the view of the
5687c478bd9Sstevel@tonic-gate  * memory object shared between a CPU and a DMA master in consistent.
5697c478bd9Sstevel@tonic-gate  * However, judicious use of this flag can give sufficient hints to
5707c478bd9Sstevel@tonic-gate  * the mapping routines to attempt to pick the most efficacious mapping
5717c478bd9Sstevel@tonic-gate  * such that the synchronization steps are as efficient as possible.
5727c478bd9Sstevel@tonic-gate  *
5737c478bd9Sstevel@tonic-gate  */
5747c478bd9Sstevel@tonic-gate #define	DDI_DMA_CONSISTENT	0x0010
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate /*
5777c478bd9Sstevel@tonic-gate  * Some DMA mappings have to be 'exclusive' access.
5787c478bd9Sstevel@tonic-gate  */
5797c478bd9Sstevel@tonic-gate #define	DDI_DMA_EXCLUSIVE	0x0020
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate /*
5827c478bd9Sstevel@tonic-gate  * Sequential, unidirectional, block-sized and block aligned transfers
5837c478bd9Sstevel@tonic-gate  */
5847c478bd9Sstevel@tonic-gate #define	DDI_DMA_STREAMING	0x0040
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate /*
5877c478bd9Sstevel@tonic-gate  * Support for 64-bit SBus devices
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate #define	DDI_DMA_SBUS_64BIT	0x2000
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate /*
5927c478bd9Sstevel@tonic-gate  * Return values from the mapping allocation functions.
5937c478bd9Sstevel@tonic-gate  */
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate /*
5967c478bd9Sstevel@tonic-gate  * succeeded in satisfying request
5977c478bd9Sstevel@tonic-gate  */
5987c478bd9Sstevel@tonic-gate #define	DDI_DMA_MAPPED		0
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate  * Mapping is legitimate (for advisory calls).
6027c478bd9Sstevel@tonic-gate  */
6037c478bd9Sstevel@tonic-gate #define	DDI_DMA_MAPOK		0
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate /*
6067c478bd9Sstevel@tonic-gate  * Succeeded in mapping a portion of the request.
6077c478bd9Sstevel@tonic-gate  */
6087c478bd9Sstevel@tonic-gate #define	DDI_DMA_PARTIAL_MAP	1
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /*
6117c478bd9Sstevel@tonic-gate  * indicates end of window/segment list
6127c478bd9Sstevel@tonic-gate  */
6137c478bd9Sstevel@tonic-gate #define	DDI_DMA_DONE		2
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate /*
6167c478bd9Sstevel@tonic-gate  * No resources to map request.
6177c478bd9Sstevel@tonic-gate  */
6187c478bd9Sstevel@tonic-gate #define	DDI_DMA_NORESOURCES	-1
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate /*
6217c478bd9Sstevel@tonic-gate  * Can't establish a mapping to the specified object
6227c478bd9Sstevel@tonic-gate  * (no specific reason).
6237c478bd9Sstevel@tonic-gate  */
6247c478bd9Sstevel@tonic-gate #define	DDI_DMA_NOMAPPING	-2
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate /*
6277c478bd9Sstevel@tonic-gate  * The request is too big to be mapped.
6287c478bd9Sstevel@tonic-gate  */
6297c478bd9Sstevel@tonic-gate #define	DDI_DMA_TOOBIG		-3
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate /*
6327c478bd9Sstevel@tonic-gate  * The request is too small to be mapped.
6337c478bd9Sstevel@tonic-gate  */
6347c478bd9Sstevel@tonic-gate #define	DDI_DMA_TOOSMALL	-4
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate /*
6377c478bd9Sstevel@tonic-gate  * The request cannot be mapped because the object
6387c478bd9Sstevel@tonic-gate  * is locked against mapping by another DMA master.
6397c478bd9Sstevel@tonic-gate  */
6407c478bd9Sstevel@tonic-gate #define	DDI_DMA_LOCKED		-5
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate /*
6437c478bd9Sstevel@tonic-gate  * The request cannot be mapped because the limits
6447c478bd9Sstevel@tonic-gate  * structure has bogus values.
6457c478bd9Sstevel@tonic-gate  */
6467c478bd9Sstevel@tonic-gate #define	DDI_DMA_BADLIMITS	-6
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate  * the segment/window pointer is stale
6507c478bd9Sstevel@tonic-gate  */
6517c478bd9Sstevel@tonic-gate #define	DDI_DMA_STALE		-7
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate /*
6547c478bd9Sstevel@tonic-gate  * The system can't allocate DMA resources using
6557c478bd9Sstevel@tonic-gate  * the given DMA attributes
6567c478bd9Sstevel@tonic-gate  */
6577c478bd9Sstevel@tonic-gate #define	DDI_DMA_BADATTR		-8
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate /*
6607c478bd9Sstevel@tonic-gate  * A DMA handle is already used for a DMA
6617c478bd9Sstevel@tonic-gate  */
6627c478bd9Sstevel@tonic-gate #define	DDI_DMA_INUSE		-9
6637c478bd9Sstevel@tonic-gate 
6643a634bfcSVikram Hegde 
6653a634bfcSVikram Hegde /*
6663a634bfcSVikram Hegde  * DVMA disabled or not supported. use physical DMA
6673a634bfcSVikram Hegde  */
6683a634bfcSVikram Hegde #define	DDI_DMA_USE_PHYSICAL		-10
6693a634bfcSVikram Hegde 
6703a634bfcSVikram Hegde 
6717c478bd9Sstevel@tonic-gate /*
6727c478bd9Sstevel@tonic-gate  * In order for the access to a memory object to be consistent
6737c478bd9Sstevel@tonic-gate  * between a device and a CPU, the function ddi_dma_sync(9F)
6747c478bd9Sstevel@tonic-gate  * must be called upon the DMA handle. The following flags
6757c478bd9Sstevel@tonic-gate  * define whose view of the object should be made consistent.
6767c478bd9Sstevel@tonic-gate  * There are different flags here because on different machines
6777c478bd9Sstevel@tonic-gate  * there are definite performance implications of how long
6787c478bd9Sstevel@tonic-gate  * such synchronization takes.
6797c478bd9Sstevel@tonic-gate  *
6807c478bd9Sstevel@tonic-gate  * DDI_DMA_SYNC_FORDEV makes all device references to the object
6817c478bd9Sstevel@tonic-gate  * mapped by the DMA handle up to date. It should be used by a
6827c478bd9Sstevel@tonic-gate  * driver after a cpu modifies the memory object (over the range
6837c478bd9Sstevel@tonic-gate  * specified by the other arguments to the ddi_dma_sync(9F) call).
6847c478bd9Sstevel@tonic-gate  *
6857c478bd9Sstevel@tonic-gate  * DDI_DMA_SYNC_FORCPU makes all cpu references to the object
6867c478bd9Sstevel@tonic-gate  * mapped by the DMA handle up to date. It should be used
6877c478bd9Sstevel@tonic-gate  * by a driver after the receipt of data from the device to
6887c478bd9Sstevel@tonic-gate  * the memory object is done (over the range specified by
6897c478bd9Sstevel@tonic-gate  * the other arguments to the ddi_dma_sync(9F) call).
6907c478bd9Sstevel@tonic-gate  *
6917c478bd9Sstevel@tonic-gate  * If the only mapping that concerns the driver is one for the
6927c478bd9Sstevel@tonic-gate  * kernel (such as memory allocated by ddi_iopb_alloc(9F)), the
6937c478bd9Sstevel@tonic-gate  * flag DDI_DMA_SYNC_FORKERNEL can be used. This is a hint to the
6947c478bd9Sstevel@tonic-gate  * system that if it can synchronize the kernel's view faster
6957c478bd9Sstevel@tonic-gate  * that the CPU's view, it can do so, otherwise it acts the
6967c478bd9Sstevel@tonic-gate  * same as DDI_DMA_SYNC_FORCPU. DDI_DMA_SYNC_FORKERNEL might
6977c478bd9Sstevel@tonic-gate  * speed up the synchronization of kernel mappings in case of
6987c478bd9Sstevel@tonic-gate  * non IO-coherent CPU caches.
6997c478bd9Sstevel@tonic-gate  */
7007c478bd9Sstevel@tonic-gate #define	DDI_DMA_SYNC_FORDEV	0x0
7017c478bd9Sstevel@tonic-gate #define	DDI_DMA_SYNC_FORCPU	0x1
7027c478bd9Sstevel@tonic-gate #define	DDI_DMA_SYNC_FORKERNEL	0x2
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate /*
7057c478bd9Sstevel@tonic-gate  * Bus nexus control functions for DMA
7067c478bd9Sstevel@tonic-gate  */
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate /*
7097c478bd9Sstevel@tonic-gate  * Control operations, defined here so that devops.h can be included
7107c478bd9Sstevel@tonic-gate  * by drivers without having to include a specific SYSDDI implementation
7117c478bd9Sstevel@tonic-gate  * header file.
7127c478bd9Sstevel@tonic-gate  */
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate enum ddi_dma_ctlops {
7157c478bd9Sstevel@tonic-gate 	DDI_DMA_FREE,		/* free reference to object		*/
7167c478bd9Sstevel@tonic-gate 	DDI_DMA_SYNC,		/* synchronize cache references		*/
7177c478bd9Sstevel@tonic-gate 	DDI_DMA_HTOC,		/* return DMA cookie for handle		*/
7187c478bd9Sstevel@tonic-gate 	DDI_DMA_KVADDR,		/* return kernel virtual address	*/
7197c478bd9Sstevel@tonic-gate 	DDI_DMA_MOVWIN,		/* change mapped DMA window on object	*/
7207c478bd9Sstevel@tonic-gate 	DDI_DMA_REPWIN,		/* report current window on DMA object	*/
7217c478bd9Sstevel@tonic-gate 	DDI_DMA_GETERR,		/* report any post-transfer DMA errors	*/
7227c478bd9Sstevel@tonic-gate 	DDI_DMA_COFF,		/* convert a DMA cookie to an offset	*/
7237c478bd9Sstevel@tonic-gate 	DDI_DMA_NEXTWIN,	/* get next window within object	*/
7247c478bd9Sstevel@tonic-gate 	DDI_DMA_NEXTSEG,	/* get next segment within window	*/
7257c478bd9Sstevel@tonic-gate 	DDI_DMA_SEGTOC,		/* return segment DMA cookie		*/
7267c478bd9Sstevel@tonic-gate 	DDI_DMA_RESERVE,	/* reserve some DVMA range		*/
7277c478bd9Sstevel@tonic-gate 	DDI_DMA_RELEASE,	/* free preallocated DVMA range		*/
7287c478bd9Sstevel@tonic-gate 	DDI_DMA_RESETH,		/* reset next cookie ptr in handle	*/
7297c478bd9Sstevel@tonic-gate 	DDI_DMA_CKSYNC,		/* sync intermediate buffer to cookies	*/
7307c478bd9Sstevel@tonic-gate 	DDI_DMA_IOPB_ALLOC,	/* get contiguous DMA-able memory	*/
7317c478bd9Sstevel@tonic-gate 	DDI_DMA_IOPB_FREE,	/* return contiguous DMA-able memory	*/
7327c478bd9Sstevel@tonic-gate 	DDI_DMA_SMEM_ALLOC,	/* get contiguous DMA-able memory	*/
7337c478bd9Sstevel@tonic-gate 	DDI_DMA_SMEM_FREE,	/* return contiguous DMA-able memory	*/
7347c478bd9Sstevel@tonic-gate 	DDI_DMA_SET_SBUS64,	/* 64 bit SBus support			*/
7357c478bd9Sstevel@tonic-gate 	DDI_DMA_REMAP,		/* remap DMA buffers after relocation	*/
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 		/*
7387c478bd9Sstevel@tonic-gate 		 * control ops for DMA engine on motherboard
7397c478bd9Sstevel@tonic-gate 		 */
7407c478bd9Sstevel@tonic-gate 	DDI_DMA_E_ACQUIRE,	/* get channel for exclusive use	*/
7417c478bd9Sstevel@tonic-gate 	DDI_DMA_E_FREE,		/* release channel			*/
7427c478bd9Sstevel@tonic-gate 	DDI_DMA_E_1STPTY,	/* setup channel for 1st party DMA	*/
7437c478bd9Sstevel@tonic-gate 	DDI_DMA_E_GETCB,	/* get control block for DMA engine	*/
7447c478bd9Sstevel@tonic-gate 	DDI_DMA_E_FREECB,	/* free control blk for DMA engine	*/
7457c478bd9Sstevel@tonic-gate 	DDI_DMA_E_PROG,		/* program channel of DMA engine	*/
7467c478bd9Sstevel@tonic-gate 	DDI_DMA_E_SWSETUP,	/* setup channel for software control	*/
7477c478bd9Sstevel@tonic-gate 	DDI_DMA_E_SWSTART,	/* software operation of DMA channel	*/
7487c478bd9Sstevel@tonic-gate 	DDI_DMA_E_ENABLE,	/* enable channel of DMA engine		*/
7497c478bd9Sstevel@tonic-gate 	DDI_DMA_E_STOP,		/* stop a channel of DMA engine		*/
7507c478bd9Sstevel@tonic-gate 	DDI_DMA_E_DISABLE,	/* disable channel of DMA engine	*/
7517c478bd9Sstevel@tonic-gate 	DDI_DMA_E_GETCNT,	/* get remaining xfer count		*/
7527c478bd9Sstevel@tonic-gate 	DDI_DMA_E_GETLIM,	/* get DMA engine limits		*/
7537c478bd9Sstevel@tonic-gate 	DDI_DMA_E_GETATTR	/* get DMA engine attributes		*/
7547c478bd9Sstevel@tonic-gate };
7557c478bd9Sstevel@tonic-gate 
7567b93957cSeota /*
7577b93957cSeota  * Cache attribute flags:
7587b93957cSeota  *
7597b93957cSeota  * IOMEM_DATA_CACHED
7607b93957cSeota  *   The CPU can cache the data it fetches and push it to memory at a later
7617b93957cSeota  *   time. This is the default attribute and used if no cache attributes is
7627b93957cSeota  *   specified.
7637b93957cSeota  *
7647b93957cSeota  * IOMEM_DATA_UC_WR_COMBINE
7657b93957cSeota  *   The CPU never caches the data but writes may occur out of order or be
7667b93957cSeota  *   combined. It implies re-ordering.
7677b93957cSeota  *
7687b93957cSeota  * IOMEM_DATA_UNCACHED
7697b93957cSeota  *   The CPU never caches the data and has uncacheable access to memory.
7707b93957cSeota  *   It also implies strict ordering.
7717b93957cSeota  *
7727b93957cSeota  * The cache attributes are mutually exclusive, and any combination of the
7737b93957cSeota  * values leads to a failure. On the sparc architecture, only IOMEM_DATA_CACHED
7747b93957cSeota  * is meaningful, but others lead to a failure.
7757b93957cSeota  */
7767b93957cSeota #define	IOMEM_DATA_CACHED		0x10000 /* data is cached */
7777b93957cSeota #define	IOMEM_DATA_UC_WR_COMBINE	0x20000 /* data is not cached, but */
7787b93957cSeota 						/* writes might be combined */
7797b93957cSeota #define	IOMEM_DATA_UNCACHED		0x40000 /* data is not cached. */
7807b93957cSeota #define	IOMEM_DATA_MASK			0xF0000	/* cache attrs mask */
7817b93957cSeota 
7827b93957cSeota /*
7837b93957cSeota  * Check if either uncacheable or write-combining specified. (those flags are
7847b93957cSeota  * mutually exclusive) This macro is used to override hat attributes if either
7857b93957cSeota  * one is set.
7867b93957cSeota  */
7877b93957cSeota #define	OVERRIDE_CACHE_ATTR(attr)	\
7887b93957cSeota 	(attr & (IOMEM_DATA_UNCACHED | IOMEM_DATA_UC_WR_COMBINE))
7897b93957cSeota 
7907b93957cSeota /*
7917b93957cSeota  * Get the cache attribute from flags. If there is no attributes,
7927b93957cSeota  * return IOMEM_DATA_CACHED (default attribute).
7937b93957cSeota  */
7947b93957cSeota #define	IOMEM_CACHE_ATTR(flags)	\
7957b93957cSeota 	((flags & IOMEM_DATA_MASK) ? (flags & IOMEM_DATA_MASK) : \
7967b93957cSeota 	    IOMEM_DATA_CACHED)
7977b93957cSeota 
7987c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate #endif
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate #endif	/* _SYS_DDIDMAREQ_H */
803