1*7613SVikram.Hegde@Sun.COM /* 2*7613SVikram.Hegde@Sun.COM * CDDL HEADER START 3*7613SVikram.Hegde@Sun.COM * 4*7613SVikram.Hegde@Sun.COM * The contents of this file are subject to the terms of the 5*7613SVikram.Hegde@Sun.COM * Common Development and Distribution License (the "License"). 6*7613SVikram.Hegde@Sun.COM * You may not use this file except in compliance with the License. 7*7613SVikram.Hegde@Sun.COM * 8*7613SVikram.Hegde@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*7613SVikram.Hegde@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*7613SVikram.Hegde@Sun.COM * See the License for the specific language governing permissions 11*7613SVikram.Hegde@Sun.COM * and limitations under the License. 12*7613SVikram.Hegde@Sun.COM * 13*7613SVikram.Hegde@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*7613SVikram.Hegde@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*7613SVikram.Hegde@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*7613SVikram.Hegde@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*7613SVikram.Hegde@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*7613SVikram.Hegde@Sun.COM * 19*7613SVikram.Hegde@Sun.COM * CDDL HEADER END 20*7613SVikram.Hegde@Sun.COM */ 21*7613SVikram.Hegde@Sun.COM /* 22*7613SVikram.Hegde@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23*7613SVikram.Hegde@Sun.COM * Use is subject to license terms. 24*7613SVikram.Hegde@Sun.COM */ 25*7613SVikram.Hegde@Sun.COM 26*7613SVikram.Hegde@Sun.COM #ifndef _SYS_IOMMULIB_H 27*7613SVikram.Hegde@Sun.COM #define _SYS_IOMMULIB_H 28*7613SVikram.Hegde@Sun.COM 29*7613SVikram.Hegde@Sun.COM #pragma ident "@(#)iommulib.h 1.3 08/08/31 SMI" 30*7613SVikram.Hegde@Sun.COM 31*7613SVikram.Hegde@Sun.COM #ifdef __cplusplus 32*7613SVikram.Hegde@Sun.COM extern "C" { 33*7613SVikram.Hegde@Sun.COM #endif 34*7613SVikram.Hegde@Sun.COM 35*7613SVikram.Hegde@Sun.COM #include <sys/ddi_impldefs.h> 36*7613SVikram.Hegde@Sun.COM 37*7613SVikram.Hegde@Sun.COM #ifdef _KERNEL 38*7613SVikram.Hegde@Sun.COM 39*7613SVikram.Hegde@Sun.COM typedef enum { 40*7613SVikram.Hegde@Sun.COM INVALID_VENDOR = 0, 41*7613SVikram.Hegde@Sun.COM AMD_IOMMU, 42*7613SVikram.Hegde@Sun.COM INTEL_IOMMU 43*7613SVikram.Hegde@Sun.COM } iommulib_vendor_t; 44*7613SVikram.Hegde@Sun.COM 45*7613SVikram.Hegde@Sun.COM typedef enum { 46*7613SVikram.Hegde@Sun.COM IOMMU_OPS_VERSION_INVALID = 0, 47*7613SVikram.Hegde@Sun.COM IOMMU_OPS_VERSION_1 = 1 48*7613SVikram.Hegde@Sun.COM } iommulib_opsversion_t; 49*7613SVikram.Hegde@Sun.COM 50*7613SVikram.Hegde@Sun.COM #define IOMMU_OPS_VERSION IOMMU_OPS_VERSION_1 51*7613SVikram.Hegde@Sun.COM 52*7613SVikram.Hegde@Sun.COM typedef struct iommulib_ops { 53*7613SVikram.Hegde@Sun.COM iommulib_opsversion_t ilops_vers; 54*7613SVikram.Hegde@Sun.COM iommulib_vendor_t ilops_vendor; 55*7613SVikram.Hegde@Sun.COM char *ilops_id; 56*7613SVikram.Hegde@Sun.COM void *ilops_data; 57*7613SVikram.Hegde@Sun.COM 58*7613SVikram.Hegde@Sun.COM int (*ilops_probe)(dev_info_t *rdip); 59*7613SVikram.Hegde@Sun.COM 60*7613SVikram.Hegde@Sun.COM int (*ilops_dma_allochdl)(iommulib_handle_t handle, 61*7613SVikram.Hegde@Sun.COM dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, 62*7613SVikram.Hegde@Sun.COM int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *dma_handlep); 63*7613SVikram.Hegde@Sun.COM 64*7613SVikram.Hegde@Sun.COM int (*ilops_dma_freehdl)(iommulib_handle_t handle, 65*7613SVikram.Hegde@Sun.COM dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle); 66*7613SVikram.Hegde@Sun.COM 67*7613SVikram.Hegde@Sun.COM int (*ilops_dma_bindhdl)(iommulib_handle_t handle, dev_info_t *dip, 68*7613SVikram.Hegde@Sun.COM dev_info_t *rdip, ddi_dma_handle_t dma_handle, 69*7613SVikram.Hegde@Sun.COM struct ddi_dma_req *dmareq, ddi_dma_cookie_t *cookiep, 70*7613SVikram.Hegde@Sun.COM uint_t *ccountp); 71*7613SVikram.Hegde@Sun.COM 72*7613SVikram.Hegde@Sun.COM int (*ilops_dma_unbindhdl)(iommulib_handle_t handle, 73*7613SVikram.Hegde@Sun.COM dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle); 74*7613SVikram.Hegde@Sun.COM 75*7613SVikram.Hegde@Sun.COM int (*ilops_dma_sync)(iommulib_handle_t handle, dev_info_t *dip, 76*7613SVikram.Hegde@Sun.COM dev_info_t *rdip, ddi_dma_handle_t dma_handle, off_t off, 77*7613SVikram.Hegde@Sun.COM size_t len, uint_t cache_flags); 78*7613SVikram.Hegde@Sun.COM 79*7613SVikram.Hegde@Sun.COM int (*ilops_dma_win)(iommulib_handle_t handle, dev_info_t *dip, 80*7613SVikram.Hegde@Sun.COM dev_info_t *rdip, ddi_dma_handle_t dma_handle, uint_t win, 81*7613SVikram.Hegde@Sun.COM off_t *offp, size_t *lenp, ddi_dma_cookie_t *cookiep, 82*7613SVikram.Hegde@Sun.COM uint_t *ccountp); 83*7613SVikram.Hegde@Sun.COM 84*7613SVikram.Hegde@Sun.COM 85*7613SVikram.Hegde@Sun.COM /* Obsolete DMA routines */ 86*7613SVikram.Hegde@Sun.COM 87*7613SVikram.Hegde@Sun.COM int (*ilops_dma_map)(iommulib_handle_t handle, dev_info_t *dip, 88*7613SVikram.Hegde@Sun.COM dev_info_t *rdip, struct ddi_dma_req *dmareq, 89*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t *dma_handle); 90*7613SVikram.Hegde@Sun.COM 91*7613SVikram.Hegde@Sun.COM int (*ilops_dma_mctl)(iommulib_handle_t handle, dev_info_t *dip, 92*7613SVikram.Hegde@Sun.COM dev_info_t *rdip, ddi_dma_handle_t dma_handle, 93*7613SVikram.Hegde@Sun.COM enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, 94*7613SVikram.Hegde@Sun.COM caddr_t *objpp, uint_t cache_flags); 95*7613SVikram.Hegde@Sun.COM 96*7613SVikram.Hegde@Sun.COM } iommulib_ops_t; 97*7613SVikram.Hegde@Sun.COM 98*7613SVikram.Hegde@Sun.COM #define IOMMU_USED(dip) (DEVI(dip)->devi_iommulib_handle != NULL) 99*7613SVikram.Hegde@Sun.COM 100*7613SVikram.Hegde@Sun.COM typedef enum { 101*7613SVikram.Hegde@Sun.COM IOMMU_NEXOPS_VERSION_INVALID = 0, 102*7613SVikram.Hegde@Sun.COM IOMMU_NEXOPS_VERSION_1 = 1 103*7613SVikram.Hegde@Sun.COM } iommulib_nexops_version_t; 104*7613SVikram.Hegde@Sun.COM 105*7613SVikram.Hegde@Sun.COM #define IOMMU_NEXOPS_VERSION IOMMU_NEXOPS_VERSION_1 106*7613SVikram.Hegde@Sun.COM 107*7613SVikram.Hegde@Sun.COM typedef struct iommulib_nexops { 108*7613SVikram.Hegde@Sun.COM iommulib_nexops_version_t nops_vers; 109*7613SVikram.Hegde@Sun.COM char *nops_id; 110*7613SVikram.Hegde@Sun.COM void *nops_data; 111*7613SVikram.Hegde@Sun.COM 112*7613SVikram.Hegde@Sun.COM int (*nops_dma_allochdl)(dev_info_t *dip, dev_info_t *rdip, 113*7613SVikram.Hegde@Sun.COM ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg, 114*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t *handlep); 115*7613SVikram.Hegde@Sun.COM 116*7613SVikram.Hegde@Sun.COM int (*nops_dma_freehdl)(dev_info_t *dip, dev_info_t *rdip, 117*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle); 118*7613SVikram.Hegde@Sun.COM 119*7613SVikram.Hegde@Sun.COM int (*nops_dma_bindhdl)(dev_info_t *dip, dev_info_t *rdip, 120*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, struct ddi_dma_req *dmareq, 121*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 122*7613SVikram.Hegde@Sun.COM 123*7613SVikram.Hegde@Sun.COM int (*nops_dma_unbindhdl)(dev_info_t *dip, dev_info_t *rdip, 124*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle); 125*7613SVikram.Hegde@Sun.COM 126*7613SVikram.Hegde@Sun.COM void (*nops_dma_reset_cookies)(dev_info_t *dip, 127*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle); 128*7613SVikram.Hegde@Sun.COM 129*7613SVikram.Hegde@Sun.COM int (*nops_dma_get_cookies)(dev_info_t *dip, ddi_dma_handle_t handle, 130*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 131*7613SVikram.Hegde@Sun.COM 132*7613SVikram.Hegde@Sun.COM int (*nops_dma_sync)(dev_info_t *dip, dev_info_t *rdip, 133*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags); 134*7613SVikram.Hegde@Sun.COM 135*7613SVikram.Hegde@Sun.COM int (*nops_dma_win)(dev_info_t *dip, dev_info_t *rdip, 136*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, uint_t win, off_t *offp, size_t *lenp, 137*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 138*7613SVikram.Hegde@Sun.COM 139*7613SVikram.Hegde@Sun.COM int (*nops_dma_map)(dev_info_t *dip, dev_info_t *rdip, 140*7613SVikram.Hegde@Sun.COM struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep); 141*7613SVikram.Hegde@Sun.COM 142*7613SVikram.Hegde@Sun.COM int (*nops_dma_mctl)(dev_info_t *dip, dev_info_t *rdip, 143*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, 144*7613SVikram.Hegde@Sun.COM size_t *lenp, caddr_t *objpp, uint_t cache_flags); 145*7613SVikram.Hegde@Sun.COM } iommulib_nexops_t; 146*7613SVikram.Hegde@Sun.COM 147*7613SVikram.Hegde@Sun.COM struct iommulib_nex; 148*7613SVikram.Hegde@Sun.COM typedef struct iommulib_nex *iommulib_nexhandle_t; 149*7613SVikram.Hegde@Sun.COM 150*7613SVikram.Hegde@Sun.COM /* 151*7613SVikram.Hegde@Sun.COM * Interfaces for nexus drivers - typically rootnex 152*7613SVikram.Hegde@Sun.COM */ 153*7613SVikram.Hegde@Sun.COM 154*7613SVikram.Hegde@Sun.COM int iommulib_nexus_register(dev_info_t *dip, iommulib_nexops_t *nexops, 155*7613SVikram.Hegde@Sun.COM iommulib_nexhandle_t *handle); 156*7613SVikram.Hegde@Sun.COM 157*7613SVikram.Hegde@Sun.COM int iommulib_nexus_unregister(iommulib_nexhandle_t handle); 158*7613SVikram.Hegde@Sun.COM 159*7613SVikram.Hegde@Sun.COM int iommulib_nex_open(dev_info_t *rdip, uint_t *errorp); 160*7613SVikram.Hegde@Sun.COM void iommulib_nex_close(dev_info_t *rdip); 161*7613SVikram.Hegde@Sun.COM 162*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_allochdl(dev_info_t *dip, dev_info_t *rdip, 163*7613SVikram.Hegde@Sun.COM ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), 164*7613SVikram.Hegde@Sun.COM caddr_t arg, ddi_dma_handle_t *dma_handlep); 165*7613SVikram.Hegde@Sun.COM 166*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_freehdl(dev_info_t *dip, dev_info_t *rdip, 167*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t dma_handle); 168*7613SVikram.Hegde@Sun.COM 169*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_bindhdl(dev_info_t *dip, dev_info_t *rdip, 170*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t dma_handle, struct ddi_dma_req *dmareq, 171*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 172*7613SVikram.Hegde@Sun.COM 173*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, 174*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t dma_handle); 175*7613SVikram.Hegde@Sun.COM 176*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_sync(dev_info_t *dip, dev_info_t *rdip, 177*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t dma_handle, off_t off, size_t len, 178*7613SVikram.Hegde@Sun.COM uint_t cache_flags); 179*7613SVikram.Hegde@Sun.COM 180*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_win(dev_info_t *dip, dev_info_t *rdip, 181*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t dma_handle, uint_t win, off_t *offp, size_t *lenp, 182*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 183*7613SVikram.Hegde@Sun.COM 184*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_map(dev_info_t *dip, dev_info_t *rdip, 185*7613SVikram.Hegde@Sun.COM struct ddi_dma_req *dmareq, ddi_dma_handle_t *dma_handle); 186*7613SVikram.Hegde@Sun.COM 187*7613SVikram.Hegde@Sun.COM int iommulib_nexdma_mctl(dev_info_t *dip, dev_info_t *rdip, 188*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t dma_handle, enum ddi_dma_ctlops request, 189*7613SVikram.Hegde@Sun.COM off_t *offp, size_t *lenp, caddr_t *objpp, uint_t cache_flags); 190*7613SVikram.Hegde@Sun.COM 191*7613SVikram.Hegde@Sun.COM /* 192*7613SVikram.Hegde@Sun.COM * Interfaces for IOMMU drivers provided by IOMMULIB 193*7613SVikram.Hegde@Sun.COM */ 194*7613SVikram.Hegde@Sun.COM 195*7613SVikram.Hegde@Sun.COM int iommulib_iommu_register(dev_info_t *dip, iommulib_ops_t *ops, 196*7613SVikram.Hegde@Sun.COM iommulib_handle_t *handle); 197*7613SVikram.Hegde@Sun.COM 198*7613SVikram.Hegde@Sun.COM int iommulib_iommu_unregister(iommulib_handle_t handle); 199*7613SVikram.Hegde@Sun.COM 200*7613SVikram.Hegde@Sun.COM int iommulib_iommu_getunitid(iommulib_handle_t handle, uint64_t *unitidp); 201*7613SVikram.Hegde@Sun.COM 202*7613SVikram.Hegde@Sun.COM dev_info_t *iommulib_iommu_getdip(iommulib_handle_t handle); 203*7613SVikram.Hegde@Sun.COM 204*7613SVikram.Hegde@Sun.COM iommulib_ops_t *iommulib_iommu_getops(iommulib_handle_t handle); 205*7613SVikram.Hegde@Sun.COM 206*7613SVikram.Hegde@Sun.COM void *iommulib_iommu_getdata(iommulib_handle_t handle); 207*7613SVikram.Hegde@Sun.COM 208*7613SVikram.Hegde@Sun.COM 209*7613SVikram.Hegde@Sun.COM /* Interfaces for IOMMU drivers provided by NEXUS drivers (typically rootnex) */ 210*7613SVikram.Hegde@Sun.COM 211*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, 212*7613SVikram.Hegde@Sun.COM ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg, 213*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t *handlep); 214*7613SVikram.Hegde@Sun.COM 215*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, 216*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle); 217*7613SVikram.Hegde@Sun.COM 218*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip, 219*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, struct ddi_dma_req *dmareq, 220*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 221*7613SVikram.Hegde@Sun.COM 222*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, 223*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle); 224*7613SVikram.Hegde@Sun.COM 225*7613SVikram.Hegde@Sun.COM void iommulib_iommu_dma_reset_cookies(dev_info_t *dip, ddi_dma_handle_t handle); 226*7613SVikram.Hegde@Sun.COM 227*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_get_cookies(dev_info_t *dip, ddi_dma_handle_t handle, 228*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 229*7613SVikram.Hegde@Sun.COM 230*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_sync(dev_info_t *dip, dev_info_t *rdip, 231*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags); 232*7613SVikram.Hegde@Sun.COM 233*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_win(dev_info_t *dip, dev_info_t *rdip, 234*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, uint_t win, off_t *offp, size_t *lenp, 235*7613SVikram.Hegde@Sun.COM ddi_dma_cookie_t *cookiep, uint_t *ccountp); 236*7613SVikram.Hegde@Sun.COM 237*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_map(dev_info_t *dip, dev_info_t *rdip, 238*7613SVikram.Hegde@Sun.COM struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep); 239*7613SVikram.Hegde@Sun.COM 240*7613SVikram.Hegde@Sun.COM int iommulib_iommu_dma_mctl(dev_info_t *dip, dev_info_t *rdip, 241*7613SVikram.Hegde@Sun.COM ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, 242*7613SVikram.Hegde@Sun.COM size_t *lenp, caddr_t *objpp, uint_t cache_flags); 243*7613SVikram.Hegde@Sun.COM 244*7613SVikram.Hegde@Sun.COM #endif /* _KERNEL */ 245*7613SVikram.Hegde@Sun.COM 246*7613SVikram.Hegde@Sun.COM #ifdef __cplusplus 247*7613SVikram.Hegde@Sun.COM } 248*7613SVikram.Hegde@Sun.COM #endif 249*7613SVikram.Hegde@Sun.COM 250*7613SVikram.Hegde@Sun.COM #endif /* _SYS_IOMMULIB_H */ 251