xref: /onnv-gate/usr/src/uts/sun4u/sys/pci/pci_dma.h (revision 2251:99824a0e7def)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2251Selowe  * Common Development and Distribution License (the "License").
6*2251Selowe  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2251Selowe  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_PCI_DMA_H
270Sstevel@tonic-gate #define	_SYS_PCI_DMA_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate typedef	pfn_t iopfn_t;
360Sstevel@tonic-gate #define	MAKE_DMA_COOKIE(cp, address, size)	\
370Sstevel@tonic-gate 	{					\
380Sstevel@tonic-gate 		(cp)->dmac_notused = 0;		\
390Sstevel@tonic-gate 		(cp)->dmac_type = 0;		\
400Sstevel@tonic-gate 		(cp)->dmac_laddress = (address);	\
410Sstevel@tonic-gate 		(cp)->dmac_size = (size);	\
420Sstevel@tonic-gate 	}
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	HAS_REDZONE(mp)	(((mp)->dmai_rflags & DDI_DMA_REDZONE) ? 1 : 0)
450Sstevel@tonic-gate 
46*2251Selowe #define	PCI_DMA_HAT_NUM_CB_COOKIES	5
47*2251Selowe 
480Sstevel@tonic-gate typedef struct pci_dma_hdl {
490Sstevel@tonic-gate 	ddi_dma_impl_t	pdh_ddi_hdl;
500Sstevel@tonic-gate 	ddi_dma_attr_t	pdh_attr_dev;
510Sstevel@tonic-gate 	uint64_t	pdh_sync_buf_pa;
52*2251Selowe 	void		*pdh_cbcookie[PCI_DMA_HAT_NUM_CB_COOKIES];
530Sstevel@tonic-gate } pci_dma_hdl_t;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate struct pci_dma_impl { /* forthdebug only, keep in sync with ddi_dma_impl_t */
560Sstevel@tonic-gate 	ulong_t		dmai_mapping;
570Sstevel@tonic-gate 	uint_t		dmai_size;
580Sstevel@tonic-gate 	off_t		dmai_offset;
590Sstevel@tonic-gate 	uint_t		dmai_minxfer;
600Sstevel@tonic-gate 	uint_t		dmai_burstsizes;
610Sstevel@tonic-gate 	uint_t		dmai_ndvmapages;
620Sstevel@tonic-gate 	uint_t		dmai_roffset;
630Sstevel@tonic-gate 	uint_t		dmai_rflags;
640Sstevel@tonic-gate 	uint_t		dmai_flags;
650Sstevel@tonic-gate 	uint_t		dmai_nwin;
660Sstevel@tonic-gate 	uint_t		dmai_winsize;
670Sstevel@tonic-gate 	caddr_t		dmai_tte_fdvma;
680Sstevel@tonic-gate 	void		*dmai_pfnlst;
690Sstevel@tonic-gate 	uint_t		*dmai_pfn0;
700Sstevel@tonic-gate 	void		*dmai_winlst;
710Sstevel@tonic-gate 	dev_info_t	*dmai_rdip;
720Sstevel@tonic-gate 	ddi_dma_obj_t	dmai_object;
730Sstevel@tonic-gate 	ddi_dma_attr_t	dmai_attr_aug;
740Sstevel@tonic-gate 	ddi_dma_cookie_t *dmai_cookie;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	int		(*dmai_fault_check)(struct ddi_dma_impl *handle);
770Sstevel@tonic-gate 	void		(*dmai_fault_notify)(struct ddi_dma_impl *handle);
780Sstevel@tonic-gate 	int		dmai_fault;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	ddi_dma_attr_t	pdh_attr_dev;
810Sstevel@tonic-gate 	uint64_t	pdh_sync_buf_pa;
82*2251Selowe 	void		*pdh_cbcookie[PCI_DMA_HAT_NUM_CB_COOKIES];
830Sstevel@tonic-gate };
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * flags for overloading dmai_inuse field of the dma request
870Sstevel@tonic-gate  * structure:
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate #define	dmai_flags		dmai_inuse
900Sstevel@tonic-gate #define	dmai_tte		dmai_nexus_private
910Sstevel@tonic-gate #define	dmai_fdvma		dmai_nexus_private
920Sstevel@tonic-gate #define	dmai_pfnlst		dmai_iopte
930Sstevel@tonic-gate #define	dmai_winlst		dmai_minfo
940Sstevel@tonic-gate #define	dmai_pfn0		dmai_sbi
950Sstevel@tonic-gate #define	dmai_roffset		dmai_pool
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	MP_PFN0(mp)		((iopfn_t)(mp)->dmai_pfn0)
98*2251Selowe #define	MP_HAT_CB_COOKIE(mp, i)	((i < PCI_DMA_HAT_NUM_CB_COOKIES)? \
99*2251Selowe 	(((pci_dma_hdl_t *)(mp))->pdh_cbcookie[i]) : NULL)
100*2251Selowe #define	MP_HAT_CB_COOKIE_PTR(mp, i) \
101*2251Selowe 	((i < PCI_DMA_HAT_NUM_CB_COOKIES)? \
102*2251Selowe 	&(((pci_dma_hdl_t *)(mp))->pdh_cbcookie[i]) : NULL)
1030Sstevel@tonic-gate #define	WINLST(mp)		((pci_dma_win_t *)(mp)->dmai_winlst)
1040Sstevel@tonic-gate #define	DEV_ATTR(mp)		(&((pci_dma_hdl_t *)(mp))->pdh_attr_dev)
1050Sstevel@tonic-gate #define	SYNC_BUF_PA(mp)		(((pci_dma_hdl_t *)(mp))->pdh_sync_buf_pa)
1060Sstevel@tonic-gate #define	SET_DMAATTR(p, lo, hi, nocross, cntmax)	\
1070Sstevel@tonic-gate 	(p)->dma_attr_addr_lo	= (lo); \
1080Sstevel@tonic-gate 	(p)->dma_attr_addr_hi	= (hi); \
1090Sstevel@tonic-gate 	(p)->dma_attr_seg	= (nocross); \
1100Sstevel@tonic-gate 	(p)->dma_attr_count_max	= (cntmax);
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate #define	SET_DMAALIGN(p, align) \
1130Sstevel@tonic-gate 	(p)->dma_attr_align = (align);
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #define	DMAI_FLAGS_INUSE	0x1
1160Sstevel@tonic-gate #define	DMAI_FLAGS_BYPASSREQ	0x2
1170Sstevel@tonic-gate #define	DMAI_FLAGS_PEER_ONLY	0x4
1180Sstevel@tonic-gate #define	DMAI_FLAGS_NOCTX	0x8
1190Sstevel@tonic-gate #define	DMAI_FLAGS_DVMA		0x10
1200Sstevel@tonic-gate #define	DMAI_FLAGS_BYPASS	0x20
1210Sstevel@tonic-gate #define	DMAI_FLAGS_PEER_TO_PEER	0x40
1220Sstevel@tonic-gate #define	DMAI_FLAGS_DMA		(DMAI_FLAGS_BYPASS | DMAI_FLAGS_PEER_TO_PEER)
1230Sstevel@tonic-gate #define	DMAI_FLAGS_DMA_TYPE	(DMAI_FLAGS_DMA | DMAI_FLAGS_DVMA)
1240Sstevel@tonic-gate #define	DMAI_FLAGS_CONTEXT	0x100
1250Sstevel@tonic-gate #define	DMAI_FLAGS_FASTTRACK	0x200
1260Sstevel@tonic-gate #define	DMAI_FLAGS_VMEMCACHE	0x400
1270Sstevel@tonic-gate #define	DMAI_FLAGS_PGPFN	0x800
1280Sstevel@tonic-gate #define	DMAI_FLAGS_NOSYSLIMIT	0x1000
1290Sstevel@tonic-gate #define	DMAI_FLAGS_NOFASTLIMIT	0x2000
1300Sstevel@tonic-gate #define	DMAI_FLAGS_NOSYNC	0x4000
1310Sstevel@tonic-gate #define	DMAI_FLAGS_RELOC	0x8000
1320Sstevel@tonic-gate #define	DMAI_FLAGS_MAPPED	0x10000
1330Sstevel@tonic-gate #define	DMAI_FLAGS_PRESERVE	(DMAI_FLAGS_PEER_ONLY | DMAI_FLAGS_BYPASSREQ | \
1340Sstevel@tonic-gate 	DMAI_FLAGS_NOSYSLIMIT | DMAI_FLAGS_NOFASTLIMIT | DMAI_FLAGS_NOCTX)
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate #define	HAS_NOFASTLIMIT(mp)	((mp)->dmai_flags & DMAI_FLAGS_NOFASTLIMIT)
1370Sstevel@tonic-gate #define	HAS_NOSYSLIMIT(mp)	((mp)->dmai_flags & DMAI_FLAGS_NOSYSLIMIT)
1380Sstevel@tonic-gate #define	PCI_DMA_ISPEERONLY(mp)	((mp)->dmai_flags & DMAI_FLAGS_PEER_ONLY)
1390Sstevel@tonic-gate #define	PCI_DMA_ISPGPFN(mp)	((mp)->dmai_flags & DMAI_FLAGS_PGPFN)
1400Sstevel@tonic-gate #define	PCI_DMA_TYPE(mp)	((mp)->dmai_flags & DMAI_FLAGS_DMA_TYPE)
1410Sstevel@tonic-gate #define	PCI_DMA_ISDVMA(mp)	(PCI_DMA_TYPE(mp) == DMAI_FLAGS_DVMA)
1420Sstevel@tonic-gate #define	PCI_DMA_ISBYPASS(mp)	(PCI_DMA_TYPE(mp) == DMAI_FLAGS_BYPASS)
1430Sstevel@tonic-gate #define	PCI_DMA_ISPTP(mp)	(PCI_DMA_TYPE(mp) == DMAI_FLAGS_PEER_TO_PEER)
1440Sstevel@tonic-gate #define	PCI_DMA_CANFAST(mp)	(((mp)->dmai_ndvmapages + HAS_REDZONE(mp) \
1450Sstevel@tonic-gate 		<= pci_dvma_page_cache_clustsz) && HAS_NOFASTLIMIT(mp))
1460Sstevel@tonic-gate #define	PCI_DMA_WINNPGS(mp)	IOMMU_BTOP((mp)->dmai_winsize)
1470Sstevel@tonic-gate #define	PCI_DMA_CANCACHE(mp)	(!HAS_REDZONE(mp) && \
1480Sstevel@tonic-gate 		(PCI_DMA_WINNPGS(mp) == 1) && HAS_NOSYSLIMIT(mp))
1490Sstevel@tonic-gate #define	PCI_DMA_CANRELOC(mp)	((mp)->dmai_flags & DMAI_FLAGS_RELOC)
1500Sstevel@tonic-gate #define	PCI_DMA_ISMAPPED(mp)	((mp)->dmai_flags & DMAI_FLAGS_MAPPED)
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	PCI_SYNC_FLAG_SZSHIFT	6
1530Sstevel@tonic-gate #define	PCI_SYNC_FLAG_SIZE	(1 << PCI_SYNC_FLAG_SZSHIFT)
1540Sstevel@tonic-gate #define	PCI_SYNC_FLAG_FAILED	1
1550Sstevel@tonic-gate #define	PCI_SYNC_FLAG_LOCKED	2
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate #define	PCI_DMA_SYNC_DDI_FLAGS	((1 << 16) - 1)	/* Look for only DDI flags  */
1580Sstevel@tonic-gate #define	PCI_DMA_SYNC_EXT	(1 << 30)	/* enable/disable extension */
1590Sstevel@tonic-gate #define	PCI_DMA_SYNC_UNBIND	(1 << 28)	/* internal: part of unbind */
1600Sstevel@tonic-gate #define	PCI_DMA_SYNC_BAR	(1 << 26)	/* wait for all posted sync  */
1610Sstevel@tonic-gate #define	PCI_DMA_SYNC_POST	(1 << 25)	/* post request and return   */
1620Sstevel@tonic-gate #define	PCI_DMA_SYNC_PRIVATE	(1 << 24)	/* alloc private sync buffer */
1630Sstevel@tonic-gate #define	PCI_DMA_SYNC_DURING	(1 << 22)	/* sync in-progress dma */
1640Sstevel@tonic-gate #define	PCI_DMA_SYNC_BEFORE	(1 << 21)	/* before read or write */
1650Sstevel@tonic-gate #define	PCI_DMA_SYNC_AFTER	(1 << 20)	/* after read or write  */
1660Sstevel@tonic-gate #define	PCI_DMA_SYNC_WRITE	(1 << 17)	/* data from device to mem */
1670Sstevel@tonic-gate #define	PCI_DMA_SYNC_READ	(1 << 16)	/* data from memory to dev */
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #define	PCI_FLOW_ID_TO_PA(flow_p, flow_id) \
1700Sstevel@tonic-gate 	((flow_p)->flow_buf_pa + ((flow_id) << PCI_SYNC_FLAG_SZSHIFT))
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate #define	DEV_NOFASTLIMIT(lo, hi, fastlo, fasthi, align_pg) \
1730Sstevel@tonic-gate 	(((lo) <= (fastlo)) && ((hi) >= (fasthi)) && \
1740Sstevel@tonic-gate 	((align_pg) <= pci_dvma_page_cache_clustsz))
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate #define	DEV_NOSYSLIMIT(lo, hi, syslo, syshi, align_pg) \
1770Sstevel@tonic-gate 	(((lo) <= (syslo)) && ((hi) >= (syshi)) && (align_pg == 1))
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate #define	PCI_DMA_NOCTX(rdip) (!pci_use_contexts || (pci_ctx_no_active_flush && \
1800Sstevel@tonic-gate 	ddi_prop_exists(DDI_DEV_T_ANY, rdip, \
1810Sstevel@tonic-gate 		DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "active-dma-flush")))
1820Sstevel@tonic-gate #define	PCI_DMA_USECTX(mp)	(!(mp->dmai_flags & DMAI_FLAGS_NOCTX))
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate #define	PCI_DMA_BYPASS_PREFIX(mp, pfn) \
1850Sstevel@tonic-gate 	(PCI_DMA_ISBYPASS(mp) ? COMMON_IOMMU_BYPASS_BASE | \
1860Sstevel@tonic-gate 	(pf_is_memory(pfn) ? 0 : COMMON_IOMMU_BYPASS_NONCACHE) : 0)
1870Sstevel@tonic-gate #define	PCI_DMA_BADPTP(pfn, attrp) \
1880Sstevel@tonic-gate 	((IOMMU_PTOB(pfn) < attrp->dma_attr_addr_lo) || \
1890Sstevel@tonic-gate 	(IOMMU_PTOB(pfn) > attrp->dma_attr_addr_hi))
1900Sstevel@tonic-gate #define	PCI_DMA_CURWIN(mp) \
1910Sstevel@tonic-gate 	(((mp)->dmai_offset + (mp)->dmai_roffset) / (mp)->dmai_winsize)
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #ifdef PCI_DMA_PROF
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate /* collect fast track failure statistics */
1960Sstevel@tonic-gate #define	PCI_DVMA_FASTTRAK_PROF(mp) { \
1970Sstevel@tonic-gate if ((mp->dmai_ndvmapages + HAS_REDZONE(mp)) > pci_dvma_page_cache_clustsz) \
1980Sstevel@tonic-gate 	pci_dvmaft_npages++; \
1990Sstevel@tonic-gate else if (!HAS_NOFASTLIMIT(mp)) \
2000Sstevel@tonic-gate 	pci_dvmaft_limit++; \
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate #else /* !PCI_DMA_PROF */
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate #define	PCI_DVMA_FASTTRAK_PROF(mp)
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #endif	/* PCI_DMA_PROF */
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate typedef struct pci_dma_win {
2100Sstevel@tonic-gate 	struct pci_dma_win *win_next;
2110Sstevel@tonic-gate 	uint32_t win_ncookies;
2120Sstevel@tonic-gate 	uint32_t win_curseg;
2130Sstevel@tonic-gate 	uint64_t win_size;
2140Sstevel@tonic-gate 	uint64_t win_offset;
2150Sstevel@tonic-gate 	/* cookie table: sizeof (ddi_dma_cookie_t) * win_ncookies */
2160Sstevel@tonic-gate } pci_dma_win_t;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /* dvma debug records */
2190Sstevel@tonic-gate struct dvma_rec {
2200Sstevel@tonic-gate 	char *dvma_addr;
2210Sstevel@tonic-gate 	uint_t len;
2220Sstevel@tonic-gate 	ddi_dma_impl_t *mp;
2230Sstevel@tonic-gate 	struct dvma_rec *next;
2240Sstevel@tonic-gate };
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate typedef struct pbm pbm_t;
2270Sstevel@tonic-gate extern int pci_dma_sync(dev_info_t *dip, dev_info_t *rdip,
2280Sstevel@tonic-gate 	ddi_dma_handle_t handle, off_t off, size_t len, uint32_t sync_flags);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate extern int pci_dma_win(dev_info_t *dip, dev_info_t *rdip,
2310Sstevel@tonic-gate 	ddi_dma_handle_t handle, uint_t win, off_t *offp,
2320Sstevel@tonic-gate 	size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp);
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate extern ddi_dma_impl_t *pci_dma_allocmp(dev_info_t *dip, dev_info_t *rdip,
2350Sstevel@tonic-gate 	int (*waitfp)(caddr_t), caddr_t arg);
2360Sstevel@tonic-gate extern void pci_dma_freemp(ddi_dma_impl_t *mp);
2370Sstevel@tonic-gate extern void pci_dma_freepfn(ddi_dma_impl_t *mp);
2380Sstevel@tonic-gate extern ddi_dma_impl_t *pci_dma_lmts2hdl(dev_info_t *dip, dev_info_t *rdip,
2390Sstevel@tonic-gate 	iommu_t *iommu_p, ddi_dma_req_t *dmareq);
2400Sstevel@tonic-gate extern int pci_dma_attr2hdl(pci_t *pci_p, ddi_dma_impl_t *mp);
2410Sstevel@tonic-gate extern uint32_t pci_dma_consist_check(uint32_t req_flags, pbm_t *pbm_p);
2420Sstevel@tonic-gate extern int pci_dma_type(pci_t *pci_p, ddi_dma_req_t *req, ddi_dma_impl_t *mp);
2430Sstevel@tonic-gate extern int pci_dma_pfn(pci_t *pci_p, ddi_dma_req_t *req, ddi_dma_impl_t *mp);
2440Sstevel@tonic-gate extern int pci_dvma_win(pci_t *pci_p, ddi_dma_req_t *r, ddi_dma_impl_t *mp);
2450Sstevel@tonic-gate extern void pci_dma_freewin(ddi_dma_impl_t *mp);
2460Sstevel@tonic-gate extern int pci_dvma_map_fast(iommu_t *iommu_p, ddi_dma_impl_t *mp);
2470Sstevel@tonic-gate extern int pci_dvma_map(ddi_dma_impl_t *mp, ddi_dma_req_t *dmareq,
2480Sstevel@tonic-gate 	iommu_t *iommu_p);
2490Sstevel@tonic-gate extern void pci_dvma_unmap(iommu_t *iommu_p, ddi_dma_impl_t *mp);
2500Sstevel@tonic-gate extern void pci_dma_sync_unmap(dev_info_t *dip, dev_info_t *rdip,
2510Sstevel@tonic-gate 	ddi_dma_impl_t *mp);
2520Sstevel@tonic-gate extern int pci_dma_physwin(pci_t *pci_p, ddi_dma_req_t *dmareq,
2530Sstevel@tonic-gate 	ddi_dma_impl_t *mp);
2540Sstevel@tonic-gate extern int pci_dvma_ctl(dev_info_t *dip, dev_info_t *rdip,
2550Sstevel@tonic-gate 	ddi_dma_impl_t *mp, enum ddi_dma_ctlops cmd, off_t *offp,
2560Sstevel@tonic-gate 	size_t *lenp, caddr_t *objp, uint_t cache_flags);
2570Sstevel@tonic-gate extern int pci_dma_ctl(dev_info_t *dip, dev_info_t *rdip,
2580Sstevel@tonic-gate 	ddi_dma_impl_t *mp, enum ddi_dma_ctlops cmd, off_t *offp,
2590Sstevel@tonic-gate 	size_t *lenp, caddr_t *objp, uint_t cache_flags);
2600Sstevel@tonic-gate extern void pci_vmem_do_free(iommu_t *iommu_p, void *base_addr, size_t npages,
2610Sstevel@tonic-gate 	int vmemcache);
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate #define	PCI_GET_MP_NCOOKIES(mp)		((mp)->dmai_ncookies)
2640Sstevel@tonic-gate #define	PCI_SET_MP_NCOOKIES(mp, nc)	((mp)->dmai_ncookies = (nc))
2650Sstevel@tonic-gate #define	PCI_GET_MP_PFN1_ADDR(mp)	(((iopfn_t *)(mp)->dmai_pfnlst) + 1)
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate #define	PCI_GET_MP_TTE(tte) \
268946Smathue 	(((uint64_t)(uintptr_t)(tte) >> 5) << (32 + 5) | \
269946Smathue 	    ((uint32_t)(uintptr_t)(tte)) & 0x12)
2700Sstevel@tonic-gate #define	PCI_SAVE_MP_TTE(mp, tte)	\
2710Sstevel@tonic-gate 	(mp)->dmai_tte = (caddr_t)(HI32(tte) | ((tte) & 0x12))
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate #define	PCI_GET_MP_PFN1(mp, page_no) (((iopfn_t *)(mp)->dmai_pfnlst)[page_no])
2740Sstevel@tonic-gate #define	PCI_GET_MP_PFN(mp, page_no)	((mp)->dmai_ndvmapages == 1 ? \
2750Sstevel@tonic-gate 	(iopfn_t)(mp)->dmai_pfnlst : PCI_GET_MP_PFN1(mp, page_no))
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate #define	PCI_SET_MP_PFN(mp, page_no, pfn) { \
2780Sstevel@tonic-gate 	if ((mp)->dmai_ndvmapages == 1) { \
2790Sstevel@tonic-gate 		ASSERT(!((page_no) || (mp)->dmai_pfnlst)); \
2800Sstevel@tonic-gate 		(mp)->dmai_pfnlst = (void *)(pfn); \
2810Sstevel@tonic-gate 	} else \
2820Sstevel@tonic-gate 		((iopfn_t *)(mp)->dmai_pfnlst)[page_no] = (iopfn_t)(pfn); \
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate #define	PCI_SET_MP_PFN1(mp, page_no, pfn) { \
2850Sstevel@tonic-gate 	((iopfn_t *)(mp)->dmai_pfnlst)[page_no] = (pfn); \
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate #define	GET_TTE_TEMPLATE(mp) MAKE_TTE_TEMPLATE(PCI_GET_MP_PFN((mp), 0), (mp))
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate extern int pci_dma_freehdl(dev_info_t *dip, dev_info_t *rdip,
2910Sstevel@tonic-gate 	ddi_dma_handle_t handle);
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate int pci_dma_handle_clean(dev_info_t *rdip, ddi_dma_handle_t handle);
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate #if defined(DEBUG)
2960Sstevel@tonic-gate extern void dump_dma_handle(uint64_t flag, dev_info_t *dip, ddi_dma_impl_t *hp);
2970Sstevel@tonic-gate #else
2980Sstevel@tonic-gate #define	dump_dma_handle(flag, dip, hp)
2990Sstevel@tonic-gate #endif
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate #ifdef	__cplusplus
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate #endif
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate #endif	/* _SYS_PCI_DMA_H */
306