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*1106Smrj * Common Development and Distribution License (the "License"). 6*1106Smrj * 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 */ 21*1106Smrj 220Sstevel@tonic-gate /* 23*1106Smrj * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/kmem.h> 310Sstevel@tonic-gate #include <sys/systm.h> 320Sstevel@tonic-gate #include <sys/ddi.h> 330Sstevel@tonic-gate #include <sys/sunddi.h> 340Sstevel@tonic-gate #include <sys/sunndi.h> 350Sstevel@tonic-gate #include <sys/ddidmareq.h> 360Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 370Sstevel@tonic-gate #include <sys/ndi_impldefs.h> 380Sstevel@tonic-gate #include <sys/fcode.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * We want to call the attachment point's dma ctl op, not his parent's 42*1106Smrj * dma ctl op, so we have to code this ourselves. 430Sstevel@tonic-gate */ 44*1106Smrj 450Sstevel@tonic-gate int 46*1106Smrj fc_ddi_dma_alloc_handle(dev_info_t *dip, ddi_dma_attr_t *attr, 47*1106Smrj int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 480Sstevel@tonic-gate { 49*1106Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, 50*1106Smrj int (*)(caddr_t), caddr_t, ddi_dma_handle_t *); 510Sstevel@tonic-gate 52*1106Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_allochdl; 53*1106Smrj return ((*funcp)(dip, dip, attr, waitfp, arg, handlep)); 540Sstevel@tonic-gate } 550Sstevel@tonic-gate 560Sstevel@tonic-gate int 57*1106Smrj fc_ddi_dma_buf_bind_handle(ddi_dma_handle_t handle, struct buf *bp, 58*1106Smrj uint_t flags, int (*waitfp)(caddr_t), caddr_t arg, 59*1106Smrj ddi_dma_cookie_t *cookiep, uint_t *ccountp) 600Sstevel@tonic-gate { 61*1106Smrj struct ddi_dma_req dmareq; 62*1106Smrj ddi_dma_impl_t *hp; 63*1106Smrj dev_info_t *dip; 64*1106Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t, 65*1106Smrj struct ddi_dma_req *, ddi_dma_cookie_t *, uint_t *); 66*1106Smrj 67*1106Smrj hp = (ddi_dma_impl_t *)handle; 68*1106Smrj dip = hp->dmai_rdip; 69*1106Smrj 70*1106Smrj dmareq.dmar_flags = flags; 71*1106Smrj dmareq.dmar_fp = waitfp; 72*1106Smrj dmareq.dmar_arg = arg; 73*1106Smrj dmareq.dmar_object.dmao_size = (uint_t)bp->b_bcount; 74*1106Smrj 75*1106Smrj if ((bp->b_flags & (B_PAGEIO|B_REMAPPED)) == B_PAGEIO) { 76*1106Smrj dmareq.dmar_object.dmao_type = DMA_OTYP_PAGES; 77*1106Smrj dmareq.dmar_object.dmao_obj.pp_obj.pp_pp = bp->b_pages; 78*1106Smrj dmareq.dmar_object.dmao_obj.pp_obj.pp_offset = 79*1106Smrj (uint_t)(((uintptr_t)bp->b_un.b_addr) & MMU_PAGEOFFSET); 80*1106Smrj } else { 81*1106Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_addr = bp->b_un.b_addr; 82*1106Smrj if ((bp->b_flags & (B_SHADOW|B_REMAPPED)) == B_SHADOW) { 83*1106Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_priv = 84*1106Smrj bp->b_shadow; 85*1106Smrj dmareq.dmar_object.dmao_type = DMA_OTYP_BUFVADDR; 86*1106Smrj } else { 87*1106Smrj dmareq.dmar_object.dmao_type = 88*1106Smrj (bp->b_flags & (B_PHYS | B_REMAPPED))? 89*1106Smrj DMA_OTYP_BUFVADDR : DMA_OTYP_VADDR; 90*1106Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_priv = NULL; 91*1106Smrj } 920Sstevel@tonic-gate 93*1106Smrj /* 94*1106Smrj * If the buffer has no proc pointer, or the proc 95*1106Smrj * struct has the kernel address space, or the buffer has 96*1106Smrj * been marked B_REMAPPED (meaning that it is now 97*1106Smrj * mapped into the kernel's address space), then 98*1106Smrj * the address space is kas (kernel address space). 99*1106Smrj */ 100*1106Smrj if (bp->b_proc == NULL || bp->b_proc->p_as == &kas || 101*1106Smrj (bp->b_flags & B_REMAPPED) != 0) { 102*1106Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_as = 0; 103*1106Smrj } else { 104*1106Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_as = 105*1106Smrj bp->b_proc->p_as; 106*1106Smrj } 107*1106Smrj } 108*1106Smrj 109*1106Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_bindhdl; 110*1106Smrj return ((*funcp)(dip, dip, handle, &dmareq, cookiep, ccountp)); 111*1106Smrj } 112*1106Smrj 113*1106Smrj int 114*1106Smrj fc_ddi_dma_unbind_handle(ddi_dma_handle_t handle) 115*1106Smrj { 116*1106Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t); 117*1106Smrj ddi_dma_impl_t *hp; 118*1106Smrj dev_info_t *dip; 119*1106Smrj 120*1106Smrj hp = (ddi_dma_impl_t *)handle; 121*1106Smrj dip = hp->dmai_rdip; 122*1106Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_unbindhdl; 123*1106Smrj return ((*funcp)(dip, dip, handle)); 124*1106Smrj } 125*1106Smrj 126*1106Smrj void 127*1106Smrj fc_ddi_dma_free_handle(ddi_dma_handle_t *handlep) 128*1106Smrj { 129*1106Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t); 130*1106Smrj ddi_dma_impl_t *hp; 131*1106Smrj dev_info_t *dip; 132*1106Smrj 133*1106Smrj hp = (ddi_dma_impl_t *)*handlep; 134*1106Smrj dip = hp->dmai_rdip; 135*1106Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_freehdl; 136*1106Smrj (void) (*funcp)(dip, dip, *handlep); 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate int 1400Sstevel@tonic-gate fc_ddi_dma_sync(ddi_dma_handle_t h, off_t o, size_t l, uint_t whom) 1410Sstevel@tonic-gate { 1420Sstevel@tonic-gate ddi_dma_impl_t *hp = (ddi_dma_impl_t *)h; 1430Sstevel@tonic-gate dev_info_t *dip; 1440Sstevel@tonic-gate int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t, off_t, 1450Sstevel@tonic-gate size_t, uint_t); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * the DMA nexus driver will set DMP_NOSYNC if the 1490Sstevel@tonic-gate * platform does not require any sync operation. For 1500Sstevel@tonic-gate * example if the memory is uncached or consistent 1510Sstevel@tonic-gate * and without any I/O write buffers involved. 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate if ((hp->dmai_rflags & DMP_NOSYNC) == DMP_NOSYNC) 1540Sstevel@tonic-gate return (DDI_SUCCESS); 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate dip = hp->dmai_rdip; 1570Sstevel@tonic-gate funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_flush; 1580Sstevel@tonic-gate return ((*funcp)(dip, dip, h, o, l, whom)); 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 1620Sstevel@tonic-gate * Create untyped properties, just like 1275 properties. 1630Sstevel@tonic-gate * XXX: Assumes property encoding is the natural byte order. 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate int 1660Sstevel@tonic-gate fc_ndi_prop_update(dev_t match_dev, dev_info_t *dip, 1670Sstevel@tonic-gate char *name, uchar_t *data, uint_t nelements) 1680Sstevel@tonic-gate { 1690Sstevel@tonic-gate return (ddi_prop_update_common(match_dev, dip, 1700Sstevel@tonic-gate DDI_PROP_HW_DEF | DDI_PROP_TYPE_ANY, 1710Sstevel@tonic-gate name, data, nelements, ddi_prop_fm_encode_bytes)); 1720Sstevel@tonic-gate } 173