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*4ab75253Smrj * Common Development and Distribution License (the "License"). 6*4ab75253Smrj * 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 */ 21*4ab75253Smrj 227c478bd9Sstevel@tonic-gate /* 23*4ab75253Smrj * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 317c478bd9Sstevel@tonic-gate #include <sys/systm.h> 327c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 347c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 357c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h> 367c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 377c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h> 387c478bd9Sstevel@tonic-gate #include <sys/fcode.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * We want to call the attachment point's dma ctl op, not his parent's 42*4ab75253Smrj * dma ctl op, so we have to code this ourselves. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 45*4ab75253Smrj int 46*4ab75253Smrj fc_ddi_dma_alloc_handle(dev_info_t *dip, ddi_dma_attr_t *attr, 47*4ab75253Smrj int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 48*4ab75253Smrj { 49*4ab75253Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, 50*4ab75253Smrj int (*)(caddr_t), caddr_t, ddi_dma_handle_t *); 51*4ab75253Smrj 52*4ab75253Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_allochdl; 53*4ab75253Smrj return ((*funcp)(dip, dip, attr, waitfp, arg, handlep)); 547c478bd9Sstevel@tonic-gate } 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate int 57*4ab75253Smrj fc_ddi_dma_buf_bind_handle(ddi_dma_handle_t handle, struct buf *bp, 58*4ab75253Smrj uint_t flags, int (*waitfp)(caddr_t), caddr_t arg, 59*4ab75253Smrj ddi_dma_cookie_t *cookiep, uint_t *ccountp) 607c478bd9Sstevel@tonic-gate { 61*4ab75253Smrj struct ddi_dma_req dmareq; 62*4ab75253Smrj ddi_dma_impl_t *hp; 63*4ab75253Smrj dev_info_t *dip; 64*4ab75253Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t, 65*4ab75253Smrj struct ddi_dma_req *, ddi_dma_cookie_t *, uint_t *); 667c478bd9Sstevel@tonic-gate 67*4ab75253Smrj hp = (ddi_dma_impl_t *)handle; 68*4ab75253Smrj dip = hp->dmai_rdip; 69*4ab75253Smrj 70*4ab75253Smrj dmareq.dmar_flags = flags; 71*4ab75253Smrj dmareq.dmar_fp = waitfp; 72*4ab75253Smrj dmareq.dmar_arg = arg; 73*4ab75253Smrj dmareq.dmar_object.dmao_size = (uint_t)bp->b_bcount; 74*4ab75253Smrj 75*4ab75253Smrj if ((bp->b_flags & (B_PAGEIO|B_REMAPPED)) == B_PAGEIO) { 76*4ab75253Smrj dmareq.dmar_object.dmao_type = DMA_OTYP_PAGES; 77*4ab75253Smrj dmareq.dmar_object.dmao_obj.pp_obj.pp_pp = bp->b_pages; 78*4ab75253Smrj dmareq.dmar_object.dmao_obj.pp_obj.pp_offset = 79*4ab75253Smrj (uint_t)(((uintptr_t)bp->b_un.b_addr) & MMU_PAGEOFFSET); 80*4ab75253Smrj } else { 81*4ab75253Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_addr = bp->b_un.b_addr; 82*4ab75253Smrj if ((bp->b_flags & (B_SHADOW|B_REMAPPED)) == B_SHADOW) { 83*4ab75253Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_priv = 84*4ab75253Smrj bp->b_shadow; 85*4ab75253Smrj dmareq.dmar_object.dmao_type = DMA_OTYP_BUFVADDR; 86*4ab75253Smrj } else { 87*4ab75253Smrj dmareq.dmar_object.dmao_type = 88*4ab75253Smrj (bp->b_flags & (B_PHYS | B_REMAPPED))? 89*4ab75253Smrj DMA_OTYP_BUFVADDR : DMA_OTYP_VADDR; 90*4ab75253Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_priv = NULL; 91*4ab75253Smrj } 92*4ab75253Smrj 93*4ab75253Smrj /* 94*4ab75253Smrj * If the buffer has no proc pointer, or the proc 95*4ab75253Smrj * struct has the kernel address space, or the buffer has 96*4ab75253Smrj * been marked B_REMAPPED (meaning that it is now 97*4ab75253Smrj * mapped into the kernel's address space), then 98*4ab75253Smrj * the address space is kas (kernel address space). 99*4ab75253Smrj */ 100*4ab75253Smrj if (bp->b_proc == NULL || bp->b_proc->p_as == &kas || 101*4ab75253Smrj (bp->b_flags & B_REMAPPED) != 0) { 102*4ab75253Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_as = 0; 103*4ab75253Smrj } else { 104*4ab75253Smrj dmareq.dmar_object.dmao_obj.virt_obj.v_as = 105*4ab75253Smrj bp->b_proc->p_as; 106*4ab75253Smrj } 107*4ab75253Smrj } 108*4ab75253Smrj 109*4ab75253Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_bindhdl; 110*4ab75253Smrj return ((*funcp)(dip, dip, handle, &dmareq, cookiep, ccountp)); 111*4ab75253Smrj } 112*4ab75253Smrj 113*4ab75253Smrj int 114*4ab75253Smrj fc_ddi_dma_unbind_handle(ddi_dma_handle_t handle) 115*4ab75253Smrj { 116*4ab75253Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t); 117*4ab75253Smrj ddi_dma_impl_t *hp; 118*4ab75253Smrj dev_info_t *dip; 119*4ab75253Smrj 120*4ab75253Smrj hp = (ddi_dma_impl_t *)handle; 121*4ab75253Smrj dip = hp->dmai_rdip; 122*4ab75253Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_unbindhdl; 123*4ab75253Smrj return ((*funcp)(dip, dip, handle)); 124*4ab75253Smrj } 125*4ab75253Smrj 126*4ab75253Smrj void 127*4ab75253Smrj fc_ddi_dma_free_handle(ddi_dma_handle_t *handlep) 128*4ab75253Smrj { 129*4ab75253Smrj int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t); 130*4ab75253Smrj ddi_dma_impl_t *hp; 131*4ab75253Smrj dev_info_t *dip; 132*4ab75253Smrj 133*4ab75253Smrj hp = (ddi_dma_impl_t *)*handlep; 134*4ab75253Smrj dip = hp->dmai_rdip; 135*4ab75253Smrj funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_freehdl; 136*4ab75253Smrj (void) (*funcp)(dip, dip, *handlep); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate int 1407c478bd9Sstevel@tonic-gate fc_ddi_dma_sync(ddi_dma_handle_t h, off_t o, size_t l, uint_t whom) 1417c478bd9Sstevel@tonic-gate { 1427c478bd9Sstevel@tonic-gate ddi_dma_impl_t *hp = (ddi_dma_impl_t *)h; 1437c478bd9Sstevel@tonic-gate dev_info_t *dip; 1447c478bd9Sstevel@tonic-gate int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t, off_t, 1457c478bd9Sstevel@tonic-gate size_t, uint_t); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * the DMA nexus driver will set DMP_NOSYNC if the 1497c478bd9Sstevel@tonic-gate * platform does not require any sync operation. For 1507c478bd9Sstevel@tonic-gate * example if the memory is uncached or consistent 1517c478bd9Sstevel@tonic-gate * and without any I/O write buffers involved. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate if ((hp->dmai_rflags & DMP_NOSYNC) == DMP_NOSYNC) 1547c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate dip = hp->dmai_rdip; 1577c478bd9Sstevel@tonic-gate funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_flush; 1587c478bd9Sstevel@tonic-gate return ((*funcp)(dip, dip, h, o, l, whom)); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * Create untyped properties, just like 1275 properties. 1637c478bd9Sstevel@tonic-gate * XXX: Assumes property encoding is the natural byte order. 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate int 1667c478bd9Sstevel@tonic-gate fc_ndi_prop_update(dev_t match_dev, dev_info_t *dip, 1677c478bd9Sstevel@tonic-gate char *name, uchar_t *data, uint_t nelements) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate return (ddi_prop_update_common(match_dev, dip, 1707c478bd9Sstevel@tonic-gate DDI_PROP_HW_DEF | DDI_PROP_TYPE_ANY, 1717c478bd9Sstevel@tonic-gate name, data, nelements, ddi_prop_fm_encode_bytes)); 1727c478bd9Sstevel@tonic-gate } 173