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 5*d0662dbfSelowe * Common Development and Distribution License (the "License"). 6*d0662dbfSelowe * 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*d0662dbfSelowe * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_PCI_DMA_H 277c478bd9Sstevel@tonic-gate #define _SYS_PCI_DMA_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate typedef pfn_t iopfn_t; 367c478bd9Sstevel@tonic-gate #define MAKE_DMA_COOKIE(cp, address, size) \ 377c478bd9Sstevel@tonic-gate { \ 387c478bd9Sstevel@tonic-gate (cp)->dmac_notused = 0; \ 397c478bd9Sstevel@tonic-gate (cp)->dmac_type = 0; \ 407c478bd9Sstevel@tonic-gate (cp)->dmac_laddress = (address); \ 417c478bd9Sstevel@tonic-gate (cp)->dmac_size = (size); \ 427c478bd9Sstevel@tonic-gate } 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define HAS_REDZONE(mp) (((mp)->dmai_rflags & DDI_DMA_REDZONE) ? 1 : 0) 457c478bd9Sstevel@tonic-gate 46*d0662dbfSelowe #define PCI_DMA_HAT_NUM_CB_COOKIES 5 47*d0662dbfSelowe 487c478bd9Sstevel@tonic-gate typedef struct pci_dma_hdl { 497c478bd9Sstevel@tonic-gate ddi_dma_impl_t pdh_ddi_hdl; 507c478bd9Sstevel@tonic-gate ddi_dma_attr_t pdh_attr_dev; 517c478bd9Sstevel@tonic-gate uint64_t pdh_sync_buf_pa; 52*d0662dbfSelowe void *pdh_cbcookie[PCI_DMA_HAT_NUM_CB_COOKIES]; 537c478bd9Sstevel@tonic-gate } pci_dma_hdl_t; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate struct pci_dma_impl { /* forthdebug only, keep in sync with ddi_dma_impl_t */ 567c478bd9Sstevel@tonic-gate ulong_t dmai_mapping; 577c478bd9Sstevel@tonic-gate uint_t dmai_size; 587c478bd9Sstevel@tonic-gate off_t dmai_offset; 597c478bd9Sstevel@tonic-gate uint_t dmai_minxfer; 607c478bd9Sstevel@tonic-gate uint_t dmai_burstsizes; 617c478bd9Sstevel@tonic-gate uint_t dmai_ndvmapages; 627c478bd9Sstevel@tonic-gate uint_t dmai_roffset; 637c478bd9Sstevel@tonic-gate uint_t dmai_rflags; 647c478bd9Sstevel@tonic-gate uint_t dmai_flags; 657c478bd9Sstevel@tonic-gate uint_t dmai_nwin; 667c478bd9Sstevel@tonic-gate uint_t dmai_winsize; 677c478bd9Sstevel@tonic-gate caddr_t dmai_tte_fdvma; 687c478bd9Sstevel@tonic-gate void *dmai_pfnlst; 697c478bd9Sstevel@tonic-gate uint_t *dmai_pfn0; 707c478bd9Sstevel@tonic-gate void *dmai_winlst; 717c478bd9Sstevel@tonic-gate dev_info_t *dmai_rdip; 727c478bd9Sstevel@tonic-gate ddi_dma_obj_t dmai_object; 737c478bd9Sstevel@tonic-gate ddi_dma_attr_t dmai_attr_aug; 747c478bd9Sstevel@tonic-gate ddi_dma_cookie_t *dmai_cookie; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate int (*dmai_fault_check)(struct ddi_dma_impl *handle); 777c478bd9Sstevel@tonic-gate void (*dmai_fault_notify)(struct ddi_dma_impl *handle); 787c478bd9Sstevel@tonic-gate int dmai_fault; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate ddi_dma_attr_t pdh_attr_dev; 817c478bd9Sstevel@tonic-gate uint64_t pdh_sync_buf_pa; 82*d0662dbfSelowe void *pdh_cbcookie[PCI_DMA_HAT_NUM_CB_COOKIES]; 837c478bd9Sstevel@tonic-gate }; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * flags for overloading dmai_inuse field of the dma request 877c478bd9Sstevel@tonic-gate * structure: 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate #define dmai_flags dmai_inuse 907c478bd9Sstevel@tonic-gate #define dmai_tte dmai_nexus_private 917c478bd9Sstevel@tonic-gate #define dmai_fdvma dmai_nexus_private 927c478bd9Sstevel@tonic-gate #define dmai_pfnlst dmai_iopte 937c478bd9Sstevel@tonic-gate #define dmai_winlst dmai_minfo 947c478bd9Sstevel@tonic-gate #define dmai_pfn0 dmai_sbi 957c478bd9Sstevel@tonic-gate #define dmai_roffset dmai_pool 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define MP_PFN0(mp) ((iopfn_t)(mp)->dmai_pfn0) 98*d0662dbfSelowe #define MP_HAT_CB_COOKIE(mp, i) ((i < PCI_DMA_HAT_NUM_CB_COOKIES)? \ 99*d0662dbfSelowe (((pci_dma_hdl_t *)(mp))->pdh_cbcookie[i]) : NULL) 100*d0662dbfSelowe #define MP_HAT_CB_COOKIE_PTR(mp, i) \ 101*d0662dbfSelowe ((i < PCI_DMA_HAT_NUM_CB_COOKIES)? \ 102*d0662dbfSelowe &(((pci_dma_hdl_t *)(mp))->pdh_cbcookie[i]) : NULL) 1037c478bd9Sstevel@tonic-gate #define WINLST(mp) ((pci_dma_win_t *)(mp)->dmai_winlst) 1047c478bd9Sstevel@tonic-gate #define DEV_ATTR(mp) (&((pci_dma_hdl_t *)(mp))->pdh_attr_dev) 1057c478bd9Sstevel@tonic-gate #define SYNC_BUF_PA(mp) (((pci_dma_hdl_t *)(mp))->pdh_sync_buf_pa) 1067c478bd9Sstevel@tonic-gate #define SET_DMAATTR(p, lo, hi, nocross, cntmax) \ 1077c478bd9Sstevel@tonic-gate (p)->dma_attr_addr_lo = (lo); \ 1087c478bd9Sstevel@tonic-gate (p)->dma_attr_addr_hi = (hi); \ 1097c478bd9Sstevel@tonic-gate (p)->dma_attr_seg = (nocross); \ 1107c478bd9Sstevel@tonic-gate (p)->dma_attr_count_max = (cntmax); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate #define SET_DMAALIGN(p, align) \ 1137c478bd9Sstevel@tonic-gate (p)->dma_attr_align = (align); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_INUSE 0x1 1167c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_BYPASSREQ 0x2 1177c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_PEER_ONLY 0x4 1187c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_NOCTX 0x8 1197c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_DVMA 0x10 1207c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_BYPASS 0x20 1217c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_PEER_TO_PEER 0x40 1227c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_DMA (DMAI_FLAGS_BYPASS | DMAI_FLAGS_PEER_TO_PEER) 1237c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_DMA_TYPE (DMAI_FLAGS_DMA | DMAI_FLAGS_DVMA) 1247c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_CONTEXT 0x100 1257c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_FASTTRACK 0x200 1267c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_VMEMCACHE 0x400 1277c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_PGPFN 0x800 1287c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_NOSYSLIMIT 0x1000 1297c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_NOFASTLIMIT 0x2000 1307c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_NOSYNC 0x4000 1317c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_RELOC 0x8000 1327c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_MAPPED 0x10000 1337c478bd9Sstevel@tonic-gate #define DMAI_FLAGS_PRESERVE (DMAI_FLAGS_PEER_ONLY | DMAI_FLAGS_BYPASSREQ | \ 1347c478bd9Sstevel@tonic-gate DMAI_FLAGS_NOSYSLIMIT | DMAI_FLAGS_NOFASTLIMIT | DMAI_FLAGS_NOCTX) 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #define HAS_NOFASTLIMIT(mp) ((mp)->dmai_flags & DMAI_FLAGS_NOFASTLIMIT) 1377c478bd9Sstevel@tonic-gate #define HAS_NOSYSLIMIT(mp) ((mp)->dmai_flags & DMAI_FLAGS_NOSYSLIMIT) 1387c478bd9Sstevel@tonic-gate #define PCI_DMA_ISPEERONLY(mp) ((mp)->dmai_flags & DMAI_FLAGS_PEER_ONLY) 1397c478bd9Sstevel@tonic-gate #define PCI_DMA_ISPGPFN(mp) ((mp)->dmai_flags & DMAI_FLAGS_PGPFN) 1407c478bd9Sstevel@tonic-gate #define PCI_DMA_TYPE(mp) ((mp)->dmai_flags & DMAI_FLAGS_DMA_TYPE) 1417c478bd9Sstevel@tonic-gate #define PCI_DMA_ISDVMA(mp) (PCI_DMA_TYPE(mp) == DMAI_FLAGS_DVMA) 1427c478bd9Sstevel@tonic-gate #define PCI_DMA_ISBYPASS(mp) (PCI_DMA_TYPE(mp) == DMAI_FLAGS_BYPASS) 1437c478bd9Sstevel@tonic-gate #define PCI_DMA_ISPTP(mp) (PCI_DMA_TYPE(mp) == DMAI_FLAGS_PEER_TO_PEER) 1447c478bd9Sstevel@tonic-gate #define PCI_DMA_CANFAST(mp) (((mp)->dmai_ndvmapages + HAS_REDZONE(mp) \ 1457c478bd9Sstevel@tonic-gate <= pci_dvma_page_cache_clustsz) && HAS_NOFASTLIMIT(mp)) 1467c478bd9Sstevel@tonic-gate #define PCI_DMA_WINNPGS(mp) IOMMU_BTOP((mp)->dmai_winsize) 1477c478bd9Sstevel@tonic-gate #define PCI_DMA_CANCACHE(mp) (!HAS_REDZONE(mp) && \ 1487c478bd9Sstevel@tonic-gate (PCI_DMA_WINNPGS(mp) == 1) && HAS_NOSYSLIMIT(mp)) 1497c478bd9Sstevel@tonic-gate #define PCI_DMA_CANRELOC(mp) ((mp)->dmai_flags & DMAI_FLAGS_RELOC) 1507c478bd9Sstevel@tonic-gate #define PCI_DMA_ISMAPPED(mp) ((mp)->dmai_flags & DMAI_FLAGS_MAPPED) 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #define PCI_SYNC_FLAG_SZSHIFT 6 1537c478bd9Sstevel@tonic-gate #define PCI_SYNC_FLAG_SIZE (1 << PCI_SYNC_FLAG_SZSHIFT) 1547c478bd9Sstevel@tonic-gate #define PCI_SYNC_FLAG_FAILED 1 1557c478bd9Sstevel@tonic-gate #define PCI_SYNC_FLAG_LOCKED 2 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_DDI_FLAGS ((1 << 16) - 1) /* Look for only DDI flags */ 1587c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_EXT (1 << 30) /* enable/disable extension */ 1597c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_UNBIND (1 << 28) /* internal: part of unbind */ 1607c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_BAR (1 << 26) /* wait for all posted sync */ 1617c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_POST (1 << 25) /* post request and return */ 1627c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_PRIVATE (1 << 24) /* alloc private sync buffer */ 1637c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_DURING (1 << 22) /* sync in-progress dma */ 1647c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_BEFORE (1 << 21) /* before read or write */ 1657c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_AFTER (1 << 20) /* after read or write */ 1667c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_WRITE (1 << 17) /* data from device to mem */ 1677c478bd9Sstevel@tonic-gate #define PCI_DMA_SYNC_READ (1 << 16) /* data from memory to dev */ 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate #define PCI_FLOW_ID_TO_PA(flow_p, flow_id) \ 1707c478bd9Sstevel@tonic-gate ((flow_p)->flow_buf_pa + ((flow_id) << PCI_SYNC_FLAG_SZSHIFT)) 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #define DEV_NOFASTLIMIT(lo, hi, fastlo, fasthi, align_pg) \ 1737c478bd9Sstevel@tonic-gate (((lo) <= (fastlo)) && ((hi) >= (fasthi)) && \ 1747c478bd9Sstevel@tonic-gate ((align_pg) <= pci_dvma_page_cache_clustsz)) 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate #define DEV_NOSYSLIMIT(lo, hi, syslo, syshi, align_pg) \ 1777c478bd9Sstevel@tonic-gate (((lo) <= (syslo)) && ((hi) >= (syshi)) && (align_pg == 1)) 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #define PCI_DMA_NOCTX(rdip) (!pci_use_contexts || (pci_ctx_no_active_flush && \ 1807c478bd9Sstevel@tonic-gate ddi_prop_exists(DDI_DEV_T_ANY, rdip, \ 1817c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "active-dma-flush"))) 1827c478bd9Sstevel@tonic-gate #define PCI_DMA_USECTX(mp) (!(mp->dmai_flags & DMAI_FLAGS_NOCTX)) 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #define PCI_DMA_BYPASS_PREFIX(mp, pfn) \ 1857c478bd9Sstevel@tonic-gate (PCI_DMA_ISBYPASS(mp) ? COMMON_IOMMU_BYPASS_BASE | \ 1867c478bd9Sstevel@tonic-gate (pf_is_memory(pfn) ? 0 : COMMON_IOMMU_BYPASS_NONCACHE) : 0) 1877c478bd9Sstevel@tonic-gate #define PCI_DMA_BADPTP(pfn, attrp) \ 1887c478bd9Sstevel@tonic-gate ((IOMMU_PTOB(pfn) < attrp->dma_attr_addr_lo) || \ 1897c478bd9Sstevel@tonic-gate (IOMMU_PTOB(pfn) > attrp->dma_attr_addr_hi)) 1907c478bd9Sstevel@tonic-gate #define PCI_DMA_CURWIN(mp) \ 1917c478bd9Sstevel@tonic-gate (((mp)->dmai_offset + (mp)->dmai_roffset) / (mp)->dmai_winsize) 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #ifdef PCI_DMA_PROF 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* collect fast track failure statistics */ 1967c478bd9Sstevel@tonic-gate #define PCI_DVMA_FASTTRAK_PROF(mp) { \ 1977c478bd9Sstevel@tonic-gate if ((mp->dmai_ndvmapages + HAS_REDZONE(mp)) > pci_dvma_page_cache_clustsz) \ 1987c478bd9Sstevel@tonic-gate pci_dvmaft_npages++; \ 1997c478bd9Sstevel@tonic-gate else if (!HAS_NOFASTLIMIT(mp)) \ 2007c478bd9Sstevel@tonic-gate pci_dvmaft_limit++; \ 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate #else /* !PCI_DMA_PROF */ 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #define PCI_DVMA_FASTTRAK_PROF(mp) 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #endif /* PCI_DMA_PROF */ 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate typedef struct pci_dma_win { 2107c478bd9Sstevel@tonic-gate struct pci_dma_win *win_next; 2117c478bd9Sstevel@tonic-gate uint32_t win_ncookies; 2127c478bd9Sstevel@tonic-gate uint32_t win_curseg; 2137c478bd9Sstevel@tonic-gate uint64_t win_size; 2147c478bd9Sstevel@tonic-gate uint64_t win_offset; 2157c478bd9Sstevel@tonic-gate /* cookie table: sizeof (ddi_dma_cookie_t) * win_ncookies */ 2167c478bd9Sstevel@tonic-gate } pci_dma_win_t; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate /* dvma debug records */ 2197c478bd9Sstevel@tonic-gate struct dvma_rec { 2207c478bd9Sstevel@tonic-gate char *dvma_addr; 2217c478bd9Sstevel@tonic-gate uint_t len; 2227c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp; 2237c478bd9Sstevel@tonic-gate struct dvma_rec *next; 2247c478bd9Sstevel@tonic-gate }; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate typedef struct pbm pbm_t; 2277c478bd9Sstevel@tonic-gate extern int pci_dma_sync(dev_info_t *dip, dev_info_t *rdip, 2287c478bd9Sstevel@tonic-gate ddi_dma_handle_t handle, off_t off, size_t len, uint32_t sync_flags); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate extern int pci_dma_win(dev_info_t *dip, dev_info_t *rdip, 2317c478bd9Sstevel@tonic-gate ddi_dma_handle_t handle, uint_t win, off_t *offp, 2327c478bd9Sstevel@tonic-gate size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate extern ddi_dma_impl_t *pci_dma_allocmp(dev_info_t *dip, dev_info_t *rdip, 2357c478bd9Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg); 2367c478bd9Sstevel@tonic-gate extern void pci_dma_freemp(ddi_dma_impl_t *mp); 2377c478bd9Sstevel@tonic-gate extern void pci_dma_freepfn(ddi_dma_impl_t *mp); 2387c478bd9Sstevel@tonic-gate extern ddi_dma_impl_t *pci_dma_lmts2hdl(dev_info_t *dip, dev_info_t *rdip, 2397c478bd9Sstevel@tonic-gate iommu_t *iommu_p, ddi_dma_req_t *dmareq); 2407c478bd9Sstevel@tonic-gate extern int pci_dma_attr2hdl(pci_t *pci_p, ddi_dma_impl_t *mp); 2417c478bd9Sstevel@tonic-gate extern uint32_t pci_dma_consist_check(uint32_t req_flags, pbm_t *pbm_p); 2427c478bd9Sstevel@tonic-gate extern int pci_dma_type(pci_t *pci_p, ddi_dma_req_t *req, ddi_dma_impl_t *mp); 2437c478bd9Sstevel@tonic-gate extern int pci_dma_pfn(pci_t *pci_p, ddi_dma_req_t *req, ddi_dma_impl_t *mp); 2447c478bd9Sstevel@tonic-gate extern int pci_dvma_win(pci_t *pci_p, ddi_dma_req_t *r, ddi_dma_impl_t *mp); 2457c478bd9Sstevel@tonic-gate extern void pci_dma_freewin(ddi_dma_impl_t *mp); 2467c478bd9Sstevel@tonic-gate extern int pci_dvma_map_fast(iommu_t *iommu_p, ddi_dma_impl_t *mp); 2477c478bd9Sstevel@tonic-gate extern int pci_dvma_map(ddi_dma_impl_t *mp, ddi_dma_req_t *dmareq, 2487c478bd9Sstevel@tonic-gate iommu_t *iommu_p); 2497c478bd9Sstevel@tonic-gate extern void pci_dvma_unmap(iommu_t *iommu_p, ddi_dma_impl_t *mp); 2507c478bd9Sstevel@tonic-gate extern void pci_dma_sync_unmap(dev_info_t *dip, dev_info_t *rdip, 2517c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp); 2527c478bd9Sstevel@tonic-gate extern int pci_dma_physwin(pci_t *pci_p, ddi_dma_req_t *dmareq, 2537c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp); 2547c478bd9Sstevel@tonic-gate extern int pci_dvma_ctl(dev_info_t *dip, dev_info_t *rdip, 2557c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp, enum ddi_dma_ctlops cmd, off_t *offp, 2567c478bd9Sstevel@tonic-gate size_t *lenp, caddr_t *objp, uint_t cache_flags); 2577c478bd9Sstevel@tonic-gate extern int pci_dma_ctl(dev_info_t *dip, dev_info_t *rdip, 2587c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp, enum ddi_dma_ctlops cmd, off_t *offp, 2597c478bd9Sstevel@tonic-gate size_t *lenp, caddr_t *objp, uint_t cache_flags); 2607c478bd9Sstevel@tonic-gate extern void pci_vmem_do_free(iommu_t *iommu_p, void *base_addr, size_t npages, 2617c478bd9Sstevel@tonic-gate int vmemcache); 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate #define PCI_GET_MP_NCOOKIES(mp) ((mp)->dmai_ncookies) 2647c478bd9Sstevel@tonic-gate #define PCI_SET_MP_NCOOKIES(mp, nc) ((mp)->dmai_ncookies = (nc)) 2657c478bd9Sstevel@tonic-gate #define PCI_GET_MP_PFN1_ADDR(mp) (((iopfn_t *)(mp)->dmai_pfnlst) + 1) 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate #define PCI_GET_MP_TTE(tte) \ 268f47a9c50Smathue (((uint64_t)(uintptr_t)(tte) >> 5) << (32 + 5) | \ 269f47a9c50Smathue ((uint32_t)(uintptr_t)(tte)) & 0x12) 2707c478bd9Sstevel@tonic-gate #define PCI_SAVE_MP_TTE(mp, tte) \ 2717c478bd9Sstevel@tonic-gate (mp)->dmai_tte = (caddr_t)(HI32(tte) | ((tte) & 0x12)) 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #define PCI_GET_MP_PFN1(mp, page_no) (((iopfn_t *)(mp)->dmai_pfnlst)[page_no]) 2747c478bd9Sstevel@tonic-gate #define PCI_GET_MP_PFN(mp, page_no) ((mp)->dmai_ndvmapages == 1 ? \ 2757c478bd9Sstevel@tonic-gate (iopfn_t)(mp)->dmai_pfnlst : PCI_GET_MP_PFN1(mp, page_no)) 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate #define PCI_SET_MP_PFN(mp, page_no, pfn) { \ 2787c478bd9Sstevel@tonic-gate if ((mp)->dmai_ndvmapages == 1) { \ 2797c478bd9Sstevel@tonic-gate ASSERT(!((page_no) || (mp)->dmai_pfnlst)); \ 2807c478bd9Sstevel@tonic-gate (mp)->dmai_pfnlst = (void *)(pfn); \ 2817c478bd9Sstevel@tonic-gate } else \ 2827c478bd9Sstevel@tonic-gate ((iopfn_t *)(mp)->dmai_pfnlst)[page_no] = (iopfn_t)(pfn); \ 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate #define PCI_SET_MP_PFN1(mp, page_no, pfn) { \ 2857c478bd9Sstevel@tonic-gate ((iopfn_t *)(mp)->dmai_pfnlst)[page_no] = (pfn); \ 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate #define GET_TTE_TEMPLATE(mp) MAKE_TTE_TEMPLATE(PCI_GET_MP_PFN((mp), 0), (mp)) 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate extern int pci_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, 2917c478bd9Sstevel@tonic-gate ddi_dma_handle_t handle); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate int pci_dma_handle_clean(dev_info_t *rdip, ddi_dma_handle_t handle); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate #if defined(DEBUG) 2967c478bd9Sstevel@tonic-gate extern void dump_dma_handle(uint64_t flag, dev_info_t *dip, ddi_dma_impl_t *hp); 2977c478bd9Sstevel@tonic-gate #else 2987c478bd9Sstevel@tonic-gate #define dump_dma_handle(flag, dip, hp) 2997c478bd9Sstevel@tonic-gate #endif 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate #ifdef __cplusplus 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate #endif 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate #endif /* _SYS_PCI_DMA_H */ 306