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 51501Sgovinda * Common Development and Distribution License (the "License"). 61501Sgovinda * 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*9707SDaniel.Ice@Sun.COM * Copyright 2009 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_PX_DMA_H 270Sstevel@tonic-gate #define _SYS_PX_DMA_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate typedef pfn_t px_iopfn_t; 340Sstevel@tonic-gate 350Sstevel@tonic-gate #define MAKE_DMA_COOKIE(cp, address, size) \ 360Sstevel@tonic-gate { \ 370Sstevel@tonic-gate (cp)->dmac_notused = 0; \ 380Sstevel@tonic-gate (cp)->dmac_type = 0; \ 390Sstevel@tonic-gate (cp)->dmac_laddress = (address); \ 400Sstevel@tonic-gate (cp)->dmac_size = (size); \ 410Sstevel@tonic-gate } 420Sstevel@tonic-gate 431501Sgovinda #define PX_HAS_REDZONE(mp) \ 441501Sgovinda (((mp)->dmai_flags & PX_DMAI_FLAGS_REDZONE) ? 1 : 0) 451501Sgovinda #define PX_MAP_BUFZONE(mp) \ 461501Sgovinda (((mp)->dmai_flags & PX_DMAI_FLAGS_MAP_BUFZONE) ? 1 :0) 470Sstevel@tonic-gate 480Sstevel@tonic-gate typedef struct px_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 } px_dma_hdl_t; 520Sstevel@tonic-gate 530Sstevel@tonic-gate struct px_dma_impl { /* forthdebug only, keep in sync with ddi_dma_impl_t */ 540Sstevel@tonic-gate ulong_t dmai_mapping; 550Sstevel@tonic-gate uint_t dmai_size; 560Sstevel@tonic-gate off_t dmai_offset; 570Sstevel@tonic-gate uint_t dmai_minxfer; 580Sstevel@tonic-gate uint_t dmai_burstsizes; 590Sstevel@tonic-gate uint_t dmai_ndvmapages; 600Sstevel@tonic-gate uint_t dmai_roffset; 610Sstevel@tonic-gate uint_t dmai_rflags; 620Sstevel@tonic-gate uint_t dmai_flags; 630Sstevel@tonic-gate uint_t dmai_nwin; 640Sstevel@tonic-gate uint_t dmai_winsize; 650Sstevel@tonic-gate caddr_t dmai_tte; 660Sstevel@tonic-gate void *dmai_pfnlst; 670Sstevel@tonic-gate uint_t *dmai_pfn0; 680Sstevel@tonic-gate void *dmai_winlst; 690Sstevel@tonic-gate dev_info_t *dmai_rdip; 700Sstevel@tonic-gate ddi_dma_obj_t dmai_object; 710Sstevel@tonic-gate ddi_dma_attr_t dmai_attr_aug; 720Sstevel@tonic-gate ddi_dma_cookie_t *dmai_cookie; 730Sstevel@tonic-gate 740Sstevel@tonic-gate int (*dmai_fault_check)(struct ddi_dma_impl *handle); 750Sstevel@tonic-gate void (*dmai_fault_notify)(struct ddi_dma_impl *handle); 760Sstevel@tonic-gate int dmai_fault; 770Sstevel@tonic-gate 780Sstevel@tonic-gate ddi_dma_attr_t dmai_attr_dev; 790Sstevel@tonic-gate }; 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* Included in case other px-specific flags are added later. */ 820Sstevel@tonic-gate #define PX_DMA_SYNC_DDI_FLAGS ((1 << 16) - 1) /* Look for only DDI flags */ 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * flags for overloading dmai_inuse field of the dma request 860Sstevel@tonic-gate * structure: 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate #define dmai_flags dmai_inuse 890Sstevel@tonic-gate #define dmai_tte dmai_nexus_private 900Sstevel@tonic-gate #define dmai_fdvma dmai_nexus_private 910Sstevel@tonic-gate #define dmai_pfnlst dmai_iopte 920Sstevel@tonic-gate #define dmai_winlst dmai_minfo 930Sstevel@tonic-gate #define dmai_pfn0 dmai_sbi 940Sstevel@tonic-gate #define dmai_roffset dmai_pool 953156Sgirish #define dmai_bdf dmai_minxfer 96909Segillett #define PX_MP_PFN0(mp) ((px_iopfn_t)(mp)->dmai_pfn0) 97909Segillett #define PX_WINLST(mp) ((px_dma_win_t *)(mp)->dmai_winlst) 98909Segillett #define PX_DEV_ATTR(mp) ((ddi_dma_attr_t *)(mp + 1)) 990Sstevel@tonic-gate #define SET_DMAATTR(p, lo, hi, nocross, cntmax) \ 1000Sstevel@tonic-gate (p)->dma_attr_addr_lo = (lo); \ 1010Sstevel@tonic-gate (p)->dma_attr_addr_hi = (hi); \ 1020Sstevel@tonic-gate (p)->dma_attr_seg = (nocross); \ 1030Sstevel@tonic-gate (p)->dma_attr_count_max = (cntmax); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate #define SET_DMAALIGN(p, align) \ 1060Sstevel@tonic-gate (p)->dma_attr_align = (align); 1070Sstevel@tonic-gate 108909Segillett #define PX_DMAI_FLAGS_INUSE 0x1 109909Segillett #define PX_DMAI_FLAGS_BYPASSREQ 0x2 110909Segillett #define PX_DMAI_FLAGS_PEER_ONLY 0x4 111909Segillett #define PX_DMAI_FLAGS_NOCTX 0x8 112909Segillett #define PX_DMAI_FLAGS_DVMA 0x10 113909Segillett #define PX_DMAI_FLAGS_BYPASS 0x20 114909Segillett #define PX_DMAI_FLAGS_PTP 0x40 115909Segillett #define PX_DMAI_FLAGS_DMA (PX_DMAI_FLAGS_BYPASS | PX_DMAI_FLAGS_PTP) 116909Segillett #define PX_DMAI_FLAGS_DMA_TYPE (PX_DMAI_FLAGS_DMA | PX_DMAI_FLAGS_DVMA) 117909Segillett #define PX_DMAI_FLAGS_CONTEXT 0x100 118909Segillett #define PX_DMAI_FLAGS_FASTTRACK 0x200 119909Segillett #define PX_DMAI_FLAGS_VMEMCACHE 0x400 120909Segillett #define PX_DMAI_FLAGS_PGPFN 0x800 121909Segillett #define PX_DMAI_FLAGS_NOSYSLIMIT 0x1000 122909Segillett #define PX_DMAI_FLAGS_NOFASTLIMIT 0x2000 123909Segillett #define PX_DMAI_FLAGS_NOSYNC 0x4000 124909Segillett #define PX_DMAI_FLAGS_PTP32 0x10000 125909Segillett #define PX_DMAI_FLAGS_PTP64 0x20000 1262549Sgovinda /* 1272549Sgovinda * #define PX_DMAI_FLAGS_MAP_BUFZONE 0x40000 1282549Sgovinda * See pcie_impl.h 1292549Sgovinda */ 1301501Sgovinda #define PX_DMAI_FLAGS_REDZONE 0x80000 131909Segillett #define PX_DMAI_FLAGS_PRESERVE (PX_DMAI_FLAGS_PEER_ONLY | \ 132909Segillett PX_DMAI_FLAGS_BYPASSREQ | PX_DMAI_FLAGS_NOSYSLIMIT | \ 1331501Sgovinda PX_DMAI_FLAGS_NOFASTLIMIT | PX_DMAI_FLAGS_NOCTX | \ 1341501Sgovinda PX_DMAI_FLAGS_MAP_BUFZONE | PX_DMAI_FLAGS_REDZONE) 1350Sstevel@tonic-gate 136909Segillett #define PX_HAS_NOFASTLIMIT(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_NOFASTLIMIT) 137909Segillett #define PX_HAS_NOSYSLIMIT(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_NOSYSLIMIT) 138909Segillett #define PX_DMA_ISPEERONLY(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_PEER_ONLY) 139909Segillett #define PX_DMA_ISPGPFN(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_PGPFN) 140909Segillett #define PX_DMA_TYPE(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_DMA_TYPE) 141909Segillett #define PX_DMA_ISDVMA(mp) (PX_DMA_TYPE(mp) == PX_DMAI_FLAGS_DVMA) 142909Segillett #define PX_DMA_ISBYPASS(mp) (PX_DMA_TYPE(mp) == PX_DMAI_FLAGS_BYPASS) 143909Segillett #define PX_DMA_ISPTP(mp) (PX_DMA_TYPE(mp) == PX_DMAI_FLAGS_PTP) 144909Segillett #define PX_DMA_ISPTP32(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_PTP32) 145909Segillett #define PX_DMA_ISPTP64(mp) ((mp)->dmai_flags & PX_DMAI_FLAGS_PTP64) 1461501Sgovinda #define PX_DMA_CANFAST(mp) (((mp)->dmai_ndvmapages + PX_HAS_REDZONE(mp) \ 147909Segillett <= px_dvma_page_cache_clustsz) && PX_HAS_NOFASTLIMIT(mp)) 1480Sstevel@tonic-gate #define PX_DMA_WINNPGS(mp) MMU_BTOP((mp)->dmai_winsize) 1491501Sgovinda #define PX_DMA_CANCACHE(mp) (!PX_HAS_REDZONE(mp) && \ 150909Segillett (PX_DMA_WINNPGS(mp) == 1) && PX_HAS_NOSYSLIMIT(mp)) 1510Sstevel@tonic-gate 152909Segillett #define PX_DEV_NOFASTLIMIT(lo, hi, fastlo, fasthi, align_pg) \ 1530Sstevel@tonic-gate (((lo) <= (fastlo)) && ((hi) >= (fasthi)) && \ 1540Sstevel@tonic-gate ((align_pg) <= px_dvma_page_cache_clustsz)) 1550Sstevel@tonic-gate 156909Segillett #define PX_DEV_NOSYSLIMIT(lo, hi, syslo, syshi, align_pg) \ 1570Sstevel@tonic-gate (((lo) <= (syslo)) && ((hi) >= (syshi)) && (align_pg == 1)) 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate #define PX_DMA_NOCTX(rdip) (!px_use_contexts || (px_ctx_no_active_flush && \ 1600Sstevel@tonic-gate ddi_prop_exists(DDI_DEV_T_ANY, rdip, \ 1610Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "active-dma-flush"))) 1620Sstevel@tonic-gate #define PX_DMA_USECTX(mp) (!(mp->dmai_flags & DMAI_FLAGS_NOCTX)) 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #define PX_DMA_BADPTP(pfn, attrp) \ 1650Sstevel@tonic-gate ((IOMMU_PTOB(pfn) < attrp->dma_attr_addr_lo) || \ 1660Sstevel@tonic-gate (IOMMU_PTOB(pfn) > attrp->dma_attr_addr_hi)) 1670Sstevel@tonic-gate #define PX_DMA_CURWIN(mp) \ 1680Sstevel@tonic-gate (((mp)->dmai_offset + (mp)->dmai_roffset) / (mp)->dmai_winsize) 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate #ifdef PX_DMA_PROF 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /* collect fast track failure statistics */ 1730Sstevel@tonic-gate #define PX_DVMA_FASTTRAK_PROF(mp) { \ 1741501Sgovinda if ((mp->dmai_ndvmapages + PX_HAS_REDZONE(mp)) > px_dvma_page_cache_clustsz) \ 1750Sstevel@tonic-gate px_dvmaft_npages++; \ 1761501Sgovinda else if (!PX_HAS_NOFASTLIMIT(mp)) \ 1770Sstevel@tonic-gate px_dvmaft_limit++; \ 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate #else /* !PX_DMA_PROF */ 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate #define PX_DVMA_FASTTRAK_PROF(mp) 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate #endif /* PX_DMA_PROF */ 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate typedef struct px_dma_win { 1870Sstevel@tonic-gate struct px_dma_win *win_next; 1880Sstevel@tonic-gate uint32_t win_ncookies; 1890Sstevel@tonic-gate uint32_t win_curseg; 1900Sstevel@tonic-gate uint64_t win_size; 1910Sstevel@tonic-gate uint64_t win_offset; 1920Sstevel@tonic-gate /* cookie table: sizeof (ddi_dma_cookie_t) * win_ncookies */ 1930Sstevel@tonic-gate } px_dma_win_t; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* dvma debug records */ 1960Sstevel@tonic-gate struct px_dvma_rec { 1970Sstevel@tonic-gate char *dvma_addr; 1980Sstevel@tonic-gate uint_t len; 1990Sstevel@tonic-gate ddi_dma_impl_t *mp; 2000Sstevel@tonic-gate struct px_dvma_rec *next; 2010Sstevel@tonic-gate }; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate extern int px_dma_attach(px_t *px_p); 2040Sstevel@tonic-gate extern int px_dma_win(dev_info_t *dip, dev_info_t *rdip, 2050Sstevel@tonic-gate ddi_dma_handle_t handle, uint_t win, off_t *offp, 2060Sstevel@tonic-gate size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate extern ddi_dma_impl_t *px_dma_allocmp(dev_info_t *dip, dev_info_t *rdip, 2090Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg); 2100Sstevel@tonic-gate extern void px_dma_freemp(ddi_dma_impl_t *mp); 2110Sstevel@tonic-gate extern void px_dma_freepfn(ddi_dma_impl_t *mp); 2120Sstevel@tonic-gate extern ddi_dma_impl_t *px_dma_lmts2hdl(dev_info_t *dip, dev_info_t *rdip, 2130Sstevel@tonic-gate px_mmu_t *mmu_p, ddi_dma_req_t *dmareq); 2140Sstevel@tonic-gate extern int px_dma_attr2hdl(px_t *px_p, ddi_dma_impl_t *mp); 2150Sstevel@tonic-gate extern int px_dma_type(px_t *px_p, ddi_dma_req_t *req, ddi_dma_impl_t *mp); 2160Sstevel@tonic-gate extern int px_dma_pfn(px_t *px_p, ddi_dma_req_t *req, ddi_dma_impl_t *mp); 2170Sstevel@tonic-gate extern int px_dvma_win(px_t *px_p, ddi_dma_req_t *r, ddi_dma_impl_t *mp); 2180Sstevel@tonic-gate extern void px_dma_freewin(ddi_dma_impl_t *mp); 2190Sstevel@tonic-gate extern int px_dvma_map_fast(px_mmu_t *mmu_p, ddi_dma_impl_t *mp); 2200Sstevel@tonic-gate extern int px_dvma_map(ddi_dma_impl_t *mp, ddi_dma_req_t *dmareq, 2210Sstevel@tonic-gate px_mmu_t *mmu_p); 2220Sstevel@tonic-gate extern void px_dvma_unmap(px_mmu_t *mmu_p, ddi_dma_impl_t *mp); 2230Sstevel@tonic-gate extern int px_dma_physwin(px_t *px_p, ddi_dma_req_t *dmareq, 2240Sstevel@tonic-gate ddi_dma_impl_t *mp); 2250Sstevel@tonic-gate extern int px_dvma_ctl(dev_info_t *dip, dev_info_t *rdip, 2260Sstevel@tonic-gate ddi_dma_impl_t *mp, enum ddi_dma_ctlops cmd, off_t *offp, 2270Sstevel@tonic-gate size_t *lenp, caddr_t *objp, uint_t cache_flags); 2280Sstevel@tonic-gate extern int px_dma_ctl(dev_info_t *dip, dev_info_t *rdip, 2290Sstevel@tonic-gate ddi_dma_impl_t *mp, enum ddi_dma_ctlops cmd, off_t *offp, 2300Sstevel@tonic-gate size_t *lenp, caddr_t *objp, uint_t cache_flags); 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate #define PX_GET_MP_NCOOKIES(mp) ((mp)->dmai_ncookies) 2330Sstevel@tonic-gate #define PX_SET_MP_NCOOKIES(mp, nc) ((mp)->dmai_ncookies = (nc)) 2340Sstevel@tonic-gate #define PX_GET_MP_PFN1_ADDR(mp) (((px_iopfn_t *)(mp)->dmai_pfnlst) + 1) 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate #define PX_GET_MP_TTE(tte) \ 237671Skrishnae (((uint64_t)(uintptr_t)(tte) >> 5) << (32 + 5) | \ 238*9707SDaniel.Ice@Sun.COM ((uint32_t)(uintptr_t)(tte)) & (PCI_MAP_ATTR_READ | \ 239*9707SDaniel.Ice@Sun.COM PCI_MAP_ATTR_WRITE | PCI_MAP_ATTR_RO | \ 240*9707SDaniel.Ice@Sun.COM PCI_MAP_ATTR_PHFUN_MASK)) 241*9707SDaniel.Ice@Sun.COM 2420Sstevel@tonic-gate #define PX_SAVE_MP_TTE(mp, tte) \ 243*9707SDaniel.Ice@Sun.COM (mp)->dmai_tte = (caddr_t)((uintptr_t)HI32(tte) | ((tte) & \ 244*9707SDaniel.Ice@Sun.COM (PCI_MAP_ATTR_READ | PCI_MAP_ATTR_WRITE | \ 245*9707SDaniel.Ice@Sun.COM PCI_MAP_ATTR_RO | PCI_MAP_ATTR_PHFUN_MASK))) 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate #define PX_GET_MP_PFN1(mp, page_no) \ 2480Sstevel@tonic-gate (((px_iopfn_t *)(mp)->dmai_pfnlst)[page_no]) 2490Sstevel@tonic-gate #define PX_GET_MP_PFN(mp, page_no) ((mp)->dmai_ndvmapages == 1 ? \ 2500Sstevel@tonic-gate (px_iopfn_t)(mp)->dmai_pfnlst : PX_GET_MP_PFN1(mp, page_no)) 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate #define PX_SET_MP_PFN(mp, page_no, pfn) { \ 2530Sstevel@tonic-gate if ((mp)->dmai_ndvmapages == 1) { \ 2540Sstevel@tonic-gate ASSERT(!((page_no) || (mp)->dmai_pfnlst)); \ 2550Sstevel@tonic-gate (mp)->dmai_pfnlst = (void *)(pfn); \ 2560Sstevel@tonic-gate } else \ 2570Sstevel@tonic-gate ((px_iopfn_t *)(mp)->dmai_pfnlst)[page_no] = \ 2580Sstevel@tonic-gate (px_iopfn_t)(pfn); \ 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate #define PX_SET_MP_PFN1(mp, page_no, pfn) { \ 2610Sstevel@tonic-gate ((px_iopfn_t *)(mp)->dmai_pfnlst)[page_no] = (pfn); \ 2620Sstevel@tonic-gate } 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate extern int px_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, 2650Sstevel@tonic-gate ddi_dma_handle_t handle); 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate #if defined(DEBUG) 2680Sstevel@tonic-gate extern void px_dump_dma_handle(uint64_t flag, dev_info_t *dip, 2690Sstevel@tonic-gate ddi_dma_impl_t *hp); 2700Sstevel@tonic-gate #else 2710Sstevel@tonic-gate #define px_dump_dma_handle(flag, dip, hp) 2720Sstevel@tonic-gate #endif 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate #ifdef __cplusplus 2750Sstevel@tonic-gate } 2760Sstevel@tonic-gate #endif 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate #endif /* _SYS_PX_DMA_H */ 279