xref: /onnv-gate/usr/src/uts/sun4u/io/pci/pci_fdvma.c (revision 12112:8425efd4c97b)
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
52251Selowe  * Common Development and Distribution License (the "License").
62251Selowe  * 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*12112Sbhaskar.sarkar@sun.com  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * Internal PCI Fast DVMA implementation
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/kmem.h>
300Sstevel@tonic-gate #include <sys/async.h>
310Sstevel@tonic-gate #include <sys/sysmacros.h>
320Sstevel@tonic-gate #include <sys/sunddi.h>
330Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
340Sstevel@tonic-gate #include <sys/dvma.h>
350Sstevel@tonic-gate #include <vm/hat.h>
360Sstevel@tonic-gate #include <sys/pci/pci_obj.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*LINTLIBRARY*/
390Sstevel@tonic-gate 
400Sstevel@tonic-gate static struct dvma_ops fdvma_ops;
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * The following routines are used to implement the sun4u fast dvma
440Sstevel@tonic-gate  * routines on this bus.
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*ARGSUSED*/
480Sstevel@tonic-gate static void
pci_fdvma_load(ddi_dma_handle_t h,caddr_t a,uint_t len,uint_t index,ddi_dma_cookie_t * cp)490Sstevel@tonic-gate pci_fdvma_load(ddi_dma_handle_t h, caddr_t a, uint_t len, uint_t index,
500Sstevel@tonic-gate 	ddi_dma_cookie_t *cp)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)h;
530Sstevel@tonic-gate 	fdvma_t *fdvma_p = (fdvma_t *)mp->dmai_fdvma;
540Sstevel@tonic-gate 	pci_t *pci_p = (pci_t *)fdvma_p->softsp;
550Sstevel@tonic-gate 	iommu_t *iommu_p = pci_p->pci_iommu_p;
560Sstevel@tonic-gate 	dev_info_t *dip = pci_p->pci_dip;
570Sstevel@tonic-gate 	dvma_addr_t dvma_addr, dvma_pg;
580Sstevel@tonic-gate 	caddr_t baseaddr = (caddr_t)((uintptr_t)a & PAGEMASK);
590Sstevel@tonic-gate 	uint32_t offset;
600Sstevel@tonic-gate 	size_t npages, pg_index;
610Sstevel@tonic-gate 	pfn_t pfn;
620Sstevel@tonic-gate 	int i;
630Sstevel@tonic-gate 	uint64_t tte;
640Sstevel@tonic-gate 
65946Smathue 	offset = (uint32_t)(uintptr_t)a & IOMMU_PAGE_OFFSET;
660Sstevel@tonic-gate 	npages = IOMMU_BTOPR(len + offset);
670Sstevel@tonic-gate 	if (!npages)
680Sstevel@tonic-gate 		return;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/* make sure we don't exceed reserved boundary */
710Sstevel@tonic-gate 	DEBUG3(DBG_FAST_DVMA, dip, "load index=%x: %p+%x ", index, a, len);
720Sstevel@tonic-gate 	if (index + npages > mp->dmai_ndvmapages) {
730Sstevel@tonic-gate 		cmn_err(pci_panic_on_fatal_errors ? CE_PANIC : CE_WARN,
74946Smathue 			"%s%d: kaddr_load index(%x)+pgs(%lx) exceeds limit\n",
750Sstevel@tonic-gate 			ddi_driver_name(dip), ddi_get_instance(dip),
760Sstevel@tonic-gate 			index, npages);
770Sstevel@tonic-gate 		return;
780Sstevel@tonic-gate 	}
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	/* better have not already loaded something at this address */
810Sstevel@tonic-gate 	ASSERT(fdvma_p->kvbase[index] == NULL);
820Sstevel@tonic-gate 	ASSERT(fdvma_p->pagecnt[index] == 0);
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	dvma_addr = mp->dmai_mapping + IOMMU_PTOB(index);
850Sstevel@tonic-gate 	dvma_pg = IOMMU_BTOP(dvma_addr);
860Sstevel@tonic-gate 	pg_index = dvma_pg - iommu_p->dvma_base_pg;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	/* construct the dma cookie to be returned */
890Sstevel@tonic-gate 	MAKE_DMA_COOKIE(cp, dvma_addr | offset, len);
900Sstevel@tonic-gate 	DEBUG2(DBG_FAST_DVMA | DBG_CONT, dip, "cookie: %x+%x\n",
910Sstevel@tonic-gate 		cp->dmac_address, cp->dmac_size);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	for (i = 0, a = baseaddr; i < npages; i++, a += IOMMU_PAGE_SIZE) {
940Sstevel@tonic-gate 		if (pci_dvma_remap_enabled) {
950Sstevel@tonic-gate 			uint_t flags = HAC_NOSLEEP | HAC_PAGELOCK;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 			(void) hat_add_callback(pci_fast_dvma_cbid, a,
982251Selowe 			    IOMMU_PAGE_SIZE, flags, mp, &pfn,
992251Selowe 			    &fdvma_p->cbcookie[index + i]);
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 			mp->dmai_flags |= DMAI_FLAGS_RELOC;
1020Sstevel@tonic-gate 		} else {
1030Sstevel@tonic-gate 			pfn = hat_getpfnum(kas.a_hat, a);
1040Sstevel@tonic-gate 		}
1050Sstevel@tonic-gate 		if (pfn == PFN_INVALID)
1060Sstevel@tonic-gate 			goto bad_pfn;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 		if (i == 0)	/* setup template, all bits except pfn value */
1090Sstevel@tonic-gate 			tte = MAKE_TTE_TEMPLATE((iopfn_t)pfn, mp);
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 		/* XXX assumes iommu and mmu has same page size */
1120Sstevel@tonic-gate 		iommu_p->iommu_tsb_vaddr[pg_index + i] = tte | IOMMU_PTOB(pfn);
1130Sstevel@tonic-gate 		IOMMU_PAGE_FLUSH(iommu_p, (dvma_pg + i));
1140Sstevel@tonic-gate 	}
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	mp->dmai_flags |= DMAI_FLAGS_MAPPED;
1170Sstevel@tonic-gate 	fdvma_p->kvbase[index] = baseaddr;
1180Sstevel@tonic-gate 	fdvma_p->pagecnt[index] = npages;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	return;
1210Sstevel@tonic-gate bad_pfn:
1220Sstevel@tonic-gate 	cmn_err(CE_WARN, "%s%d: kaddr_load can't get page frame for vaddr %x",
123946Smathue 		ddi_driver_name(dip), ddi_get_instance(dip), (int)(uintptr_t)a);
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*ARGSUSED*/
1270Sstevel@tonic-gate static void
pci_fdvma_unload(ddi_dma_handle_t h,uint_t index,uint_t sync_flags)1280Sstevel@tonic-gate pci_fdvma_unload(ddi_dma_handle_t h, uint_t index, uint_t sync_flags)
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)h;
1310Sstevel@tonic-gate 	fdvma_t *fdvma_p = (fdvma_t *)mp->dmai_fdvma;
1320Sstevel@tonic-gate 	pci_t *pci_p = (pci_t *)fdvma_p->softsp;
1330Sstevel@tonic-gate 	size_t npg = fdvma_p->pagecnt[index];
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	dvma_addr_t dvma_pg = IOMMU_BTOP(mp->dmai_mapping + IOMMU_PTOB(index));
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	DEBUG5(DBG_FAST_DVMA, pci_p->pci_dip,
1380Sstevel@tonic-gate 		"unload index=%x flags=%x %x+%x+%x\n", index, sync_flags,
1390Sstevel@tonic-gate 		mp->dmai_mapping, IOMMU_PTOB(index), IOMMU_PTOB(npg));
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	if (!pci_dvma_sync_before_unmap) {
1420Sstevel@tonic-gate 		if (PCI_DMA_CANRELOC(mp))
1430Sstevel@tonic-gate 			pci_fdvma_unregister_callbacks(pci_p, fdvma_p, mp,
1440Sstevel@tonic-gate 				index);
1450Sstevel@tonic-gate 		fdvma_p->kvbase[index] = NULL;
1460Sstevel@tonic-gate 		iommu_unmap_pages(pci_p->pci_iommu_p, dvma_pg, npg);
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 	if (sync_flags != -1)
1490Sstevel@tonic-gate 		pci_dma_sync(pci_p->pci_dip, mp->dmai_rdip, h,
1500Sstevel@tonic-gate 			IOMMU_PTOB(index), IOMMU_PTOB(npg), sync_flags);
1510Sstevel@tonic-gate 	if (pci_dvma_sync_before_unmap) {
1520Sstevel@tonic-gate 		if (PCI_DMA_CANRELOC(mp))
1530Sstevel@tonic-gate 			pci_fdvma_unregister_callbacks(pci_p, fdvma_p, mp,
1540Sstevel@tonic-gate 				index);
1550Sstevel@tonic-gate 		fdvma_p->kvbase[index] = NULL;
1560Sstevel@tonic-gate 		iommu_unmap_pages(pci_p->pci_iommu_p, dvma_pg, npg);
1570Sstevel@tonic-gate 	}
1580Sstevel@tonic-gate 	fdvma_p->pagecnt[index] = 0;
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*ARGSUSED*/
1620Sstevel@tonic-gate static void
pci_fdvma_sync(ddi_dma_handle_t h,uint_t index,uint_t sync_flags)1630Sstevel@tonic-gate pci_fdvma_sync(ddi_dma_handle_t h, uint_t index, uint_t sync_flags)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)h;
1660Sstevel@tonic-gate 	fdvma_t *fdvma_p = (fdvma_t *)mp->dmai_fdvma;
1670Sstevel@tonic-gate 	pci_t *pci_p = (pci_t *)fdvma_p->softsp;
1680Sstevel@tonic-gate 	size_t npg = fdvma_p->pagecnt[index];
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	DEBUG5(DBG_FAST_DVMA, pci_p->pci_dip,
1710Sstevel@tonic-gate 		"sync index=%x flags=%x %x+%x+%x\n", index, sync_flags,
1720Sstevel@tonic-gate 		mp->dmai_mapping, IOMMU_PTOB(index), IOMMU_PTOB(npg));
1730Sstevel@tonic-gate 	pci_dma_sync(pci_p->pci_dip, mp->dmai_rdip, h, IOMMU_PTOB(index),
1740Sstevel@tonic-gate 		IOMMU_PTOB(npg), sync_flags);
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate int
pci_fdvma_reserve(dev_info_t * dip,dev_info_t * rdip,pci_t * pci_p,ddi_dma_req_t * dmareq,ddi_dma_handle_t * handlep)1780Sstevel@tonic-gate pci_fdvma_reserve(dev_info_t *dip, dev_info_t *rdip, pci_t *pci_p,
1790Sstevel@tonic-gate 	ddi_dma_req_t *dmareq, ddi_dma_handle_t *handlep)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate 	fdvma_t *fdvma_p;
1820Sstevel@tonic-gate 	dvma_addr_t dvma_pg;
1830Sstevel@tonic-gate 	iommu_t *iommu_p = pci_p->pci_iommu_p;
1840Sstevel@tonic-gate 	size_t npages;
1850Sstevel@tonic-gate 	ddi_dma_impl_t *mp;
1860Sstevel@tonic-gate 	ddi_dma_lim_t *lim_p = dmareq->dmar_limits;
1870Sstevel@tonic-gate 	ulong_t hi = lim_p->dlim_addr_hi;
1880Sstevel@tonic-gate 	ulong_t lo = lim_p->dlim_addr_lo;
1890Sstevel@tonic-gate 	size_t counter_max = (lim_p->dlim_cntr_max + 1) & IOMMU_PAGE_MASK;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	if (pci_disable_fdvma)
1920Sstevel@tonic-gate 		return (DDI_FAILURE);
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	DEBUG2(DBG_DMA_CTL, dip, "DDI_DMA_RESERVE: rdip=%s%d\n",
1950Sstevel@tonic-gate 		ddi_driver_name(rdip), ddi_get_instance(rdip));
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	/*
1980Sstevel@tonic-gate 	 * Check the limit structure.
1990Sstevel@tonic-gate 	 */
2000Sstevel@tonic-gate 	if ((lo >= hi) || (hi < iommu_p->iommu_dvma_base))
2010Sstevel@tonic-gate 		return (DDI_DMA_BADLIMITS);
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	/*
204*12112Sbhaskar.sarkar@sun.com 	 * Allocate DVMA space from reserve.
2050Sstevel@tonic-gate 	 */
2060Sstevel@tonic-gate 	npages = dmareq->dmar_object.dmao_size;
207*12112Sbhaskar.sarkar@sun.com 	if ((long)atomic_add_long_nv(&iommu_p->iommu_dvma_reserve,
208*12112Sbhaskar.sarkar@sun.com 	    -npages) < 0) {
209*12112Sbhaskar.sarkar@sun.com 		atomic_add_long(&iommu_p->iommu_dvma_reserve, npages);
2100Sstevel@tonic-gate 		return (DDI_DMA_NORESOURCES);
211*12112Sbhaskar.sarkar@sun.com 	}
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	/*
2140Sstevel@tonic-gate 	 * Allocate the dma handle.
2150Sstevel@tonic-gate 	 */
2160Sstevel@tonic-gate 	mp = kmem_zalloc(sizeof (pci_dma_hdl_t), KM_SLEEP);
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	/*
2190Sstevel@tonic-gate 	 * Get entries from dvma space map.
2200Sstevel@tonic-gate 	 * (vmem_t *vmp,
2210Sstevel@tonic-gate 	 *	size_t size, size_t align, size_t phase,
2220Sstevel@tonic-gate 	 *	size_t nocross, void *minaddr, void *maxaddr, int vmflag)
2230Sstevel@tonic-gate 	 */
2240Sstevel@tonic-gate 	dvma_pg = IOMMU_BTOP((ulong_t)vmem_xalloc(iommu_p->iommu_dvma_map,
2250Sstevel@tonic-gate 		IOMMU_PTOB(npages), IOMMU_PAGE_SIZE, 0,
2260Sstevel@tonic-gate 		counter_max, (void *)lo, (void *)(hi + 1),
2270Sstevel@tonic-gate 		dmareq->dmar_fp == DDI_DMA_SLEEP ? VM_SLEEP : VM_NOSLEEP));
2280Sstevel@tonic-gate 	if (dvma_pg == 0) {
229*12112Sbhaskar.sarkar@sun.com 		atomic_add_long(&iommu_p->iommu_dvma_reserve, npages);
2300Sstevel@tonic-gate 		kmem_free(mp, sizeof (pci_dma_hdl_t));
2310Sstevel@tonic-gate 		return (DDI_DMA_NOMAPPING);
2320Sstevel@tonic-gate 	}
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 	/*
2350Sstevel@tonic-gate 	 * Create the fast dvma request structure.
2360Sstevel@tonic-gate 	 */
2370Sstevel@tonic-gate 	fdvma_p = kmem_alloc(sizeof (fdvma_t), KM_SLEEP);
2380Sstevel@tonic-gate 	fdvma_p->kvbase = kmem_zalloc(npages * sizeof (caddr_t), KM_SLEEP);
2390Sstevel@tonic-gate 	fdvma_p->pagecnt = kmem_zalloc(npages * sizeof (uint_t), KM_SLEEP);
2402251Selowe 	fdvma_p->cbcookie = kmem_zalloc(npages * sizeof (void *), KM_SLEEP);
2410Sstevel@tonic-gate 	fdvma_p->ops = &fdvma_ops;
2420Sstevel@tonic-gate 	fdvma_p->softsp = (caddr_t)pci_p;
2430Sstevel@tonic-gate 	fdvma_p->sync_flag = NULL;
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	/*
2460Sstevel@tonic-gate 	 * Initialize the handle.
2470Sstevel@tonic-gate 	 */
2480Sstevel@tonic-gate 	mp->dmai_rdip = rdip;
2490Sstevel@tonic-gate 	mp->dmai_rflags = DMP_BYPASSNEXUS |
2500Sstevel@tonic-gate 		pci_dma_consist_check(dmareq->dmar_flags, pci_p->pci_pbm_p);
2510Sstevel@tonic-gate 	if (!(dmareq->dmar_flags & DDI_DMA_RDWR))
2520Sstevel@tonic-gate 		mp->dmai_rflags |= DDI_DMA_READ;
2530Sstevel@tonic-gate 	mp->dmai_flags = DMAI_FLAGS_INUSE |
2540Sstevel@tonic-gate 		(mp->dmai_rflags & DMP_NOSYNC ? DMAI_FLAGS_NOSYNC : 0);
2550Sstevel@tonic-gate 	mp->dmai_minxfer = dmareq->dmar_limits->dlim_minxfer;
2560Sstevel@tonic-gate 	mp->dmai_burstsizes = dmareq->dmar_limits->dlim_burstsizes;
2570Sstevel@tonic-gate 	mp->dmai_mapping = IOMMU_PTOB(dvma_pg);
2580Sstevel@tonic-gate 	mp->dmai_ndvmapages = npages;
2590Sstevel@tonic-gate 	mp->dmai_size = npages * IOMMU_PAGE_SIZE;
2600Sstevel@tonic-gate 	mp->dmai_nwin = 0;
2610Sstevel@tonic-gate 	mp->dmai_fdvma = (caddr_t)fdvma_p;
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	DEBUG4(DBG_DMA_CTL, dip,
2640Sstevel@tonic-gate 		"PCI_DVMA_RESERVE: mp=%p dvma=%x npages=%x private=%p\n",
2650Sstevel@tonic-gate 		mp, mp->dmai_mapping, npages, fdvma_p);
2660Sstevel@tonic-gate 	*handlep = (ddi_dma_handle_t)mp;
2670Sstevel@tonic-gate 	return (DDI_SUCCESS);
2680Sstevel@tonic-gate }
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate int
pci_fdvma_release(dev_info_t * dip,pci_t * pci_p,ddi_dma_impl_t * mp)2710Sstevel@tonic-gate pci_fdvma_release(dev_info_t *dip, pci_t *pci_p, ddi_dma_impl_t *mp)
2720Sstevel@tonic-gate {
2730Sstevel@tonic-gate 	iommu_t *iommu_p = pci_p->pci_iommu_p;
2740Sstevel@tonic-gate 	size_t npages;
2750Sstevel@tonic-gate 	fdvma_t *fdvma_p = (fdvma_t *)mp->dmai_fdvma;
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	if (pci_disable_fdvma)
2780Sstevel@tonic-gate 		return (DDI_FAILURE);
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 	/* validate fdvma handle */
2810Sstevel@tonic-gate 	if (!(mp->dmai_rflags & DMP_BYPASSNEXUS)) {
2820Sstevel@tonic-gate 		DEBUG0(DBG_DMA_CTL, dip, "DDI_DMA_RELEASE: not fast dma\n");
2830Sstevel@tonic-gate 		return (DDI_FAILURE);
2840Sstevel@tonic-gate 	}
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate 	/* flush all reserved dvma addresses from iommu */
2870Sstevel@tonic-gate 	pci_dma_sync_unmap(dip, mp->dmai_rdip, mp);
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	npages = mp->dmai_ndvmapages;
2900Sstevel@tonic-gate 	pci_vmem_free(iommu_p, mp, (void *)mp->dmai_mapping, npages);
2910Sstevel@tonic-gate 
292*12112Sbhaskar.sarkar@sun.com 	atomic_add_long(&iommu_p->iommu_dvma_reserve, npages);
2930Sstevel@tonic-gate 	mp->dmai_ndvmapages = 0;
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	/* see if there is anyone waiting for dvma space */
2960Sstevel@tonic-gate 	if (iommu_p->iommu_dvma_clid != 0) {
2970Sstevel@tonic-gate 		DEBUG0(DBG_DMA_CTL, dip, "run dvma callback\n");
2980Sstevel@tonic-gate 		ddi_run_callback(&iommu_p->iommu_dvma_clid);
2990Sstevel@tonic-gate 	}
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	/* free data structures */
3020Sstevel@tonic-gate 	kmem_free(fdvma_p->kvbase, npages * sizeof (caddr_t));
3030Sstevel@tonic-gate 	kmem_free(fdvma_p->pagecnt, npages * sizeof (uint_t));
3042251Selowe 	kmem_free(fdvma_p->cbcookie, npages * sizeof (void *));
3050Sstevel@tonic-gate 	kmem_free(fdvma_p, sizeof (fdvma_t));
3060Sstevel@tonic-gate 	kmem_free(mp, sizeof (pci_dma_hdl_t));
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	/* see if there is anyone waiting for kmem */
3090Sstevel@tonic-gate 	if (pci_kmem_clid != 0) {
3100Sstevel@tonic-gate 		DEBUG0(DBG_DMA_CTL, dip, "run handle callback\n");
3110Sstevel@tonic-gate 		ddi_run_callback(&pci_kmem_clid);
3120Sstevel@tonic-gate 	}
3130Sstevel@tonic-gate 	return (DDI_SUCCESS);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate /*
3170Sstevel@tonic-gate  * fast dvma ops structure:
3180Sstevel@tonic-gate  */
3190Sstevel@tonic-gate static struct dvma_ops fdvma_ops = {
3200Sstevel@tonic-gate 	DVMAO_REV,
3210Sstevel@tonic-gate 	pci_fdvma_load,
3220Sstevel@tonic-gate 	pci_fdvma_unload,
3230Sstevel@tonic-gate 	pci_fdvma_sync
3240Sstevel@tonic-gate };
325