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