1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4 5.0 */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/nexusintr_impl.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/promif.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/ddi_intr_impl.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/hypervisor_api.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/intr.h> 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #define SUN4V_REG_SPEC2CFG_HDL(x) ((x >> 32) & ~(0xfull << 28)) 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate static kmutex_t vnex_id_lock; 49*7c478bd9Sstevel@tonic-gate /* 50*7c478bd9Sstevel@tonic-gate * Vnex name to pil map 51*7c478bd9Sstevel@tonic-gate */ 52*7c478bd9Sstevel@tonic-gate typedef struct vnex_regspec { 53*7c478bd9Sstevel@tonic-gate uint64_t physaddr; 54*7c478bd9Sstevel@tonic-gate uint64_t size; 55*7c478bd9Sstevel@tonic-gate } vnex_regspec_t; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate struct vnex_pil_map { 58*7c478bd9Sstevel@tonic-gate caddr_t name; 59*7c478bd9Sstevel@tonic-gate uint32_t pil; 60*7c478bd9Sstevel@tonic-gate }; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* vnex interrupt descriptor */ 63*7c478bd9Sstevel@tonic-gate typedef struct vnex_id { 64*7c478bd9Sstevel@tonic-gate dev_info_t *vid_dip; 65*7c478bd9Sstevel@tonic-gate uint32_t vid_ino; 66*7c478bd9Sstevel@tonic-gate uint64_t vid_ihdl; 67*7c478bd9Sstevel@tonic-gate uint_t (*vid_handler)(); 68*7c478bd9Sstevel@tonic-gate caddr_t vid_arg1; 69*7c478bd9Sstevel@tonic-gate caddr_t vid_arg2; 70*7c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *vid_ddi_hdlp; 71*7c478bd9Sstevel@tonic-gate uint64_t vid_cfg_hdl; 72*7c478bd9Sstevel@tonic-gate struct vnex_id *vid_next; 73*7c478bd9Sstevel@tonic-gate struct vnex_id *vid_prev; 74*7c478bd9Sstevel@tonic-gate } vnex_id_t; 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* vnex interrupt descriptor list */ 77*7c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_id_list; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* 80*7c478bd9Sstevel@tonic-gate * vnex interrupt descriptor list manipulation functions 81*7c478bd9Sstevel@tonic-gate */ 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_locate_id(dev_info_t *dip, uint32_t ino); 84*7c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_alloc_id(dev_info_t *dip, uint32_t ino, 85*7c478bd9Sstevel@tonic-gate uint64_t dhdl); 86*7c478bd9Sstevel@tonic-gate static void vnex_add_id(vnex_id_t *vid_p); 87*7c478bd9Sstevel@tonic-gate static void vnex_rem_id(vnex_id_t *vid_p); 88*7c478bd9Sstevel@tonic-gate static void vnex_free_id(vnex_id_t *vid_p); 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate uint_t vnex_intr_wrapper(caddr_t arg); 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate static struct vnex_pil_map vnex_name_to_pil[] = { 93*7c478bd9Sstevel@tonic-gate {"console", PIL_12}, 94*7c478bd9Sstevel@tonic-gate {"fma", PIL_5}, 95*7c478bd9Sstevel@tonic-gate {"echo", PIL_3}, 96*7c478bd9Sstevel@tonic-gate {"loop", PIL_3}, 97*7c478bd9Sstevel@tonic-gate {"sunmc", PIL_3}, 98*7c478bd9Sstevel@tonic-gate {"sunvts", PIL_3}, 99*7c478bd9Sstevel@tonic-gate {"explorer", PIL_3} 100*7c478bd9Sstevel@tonic-gate }; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate #define VNEX_MAX_DEVS (sizeof (vnex_name_to_pil) / \ 103*7c478bd9Sstevel@tonic-gate sizeof (struct vnex_pil_map)) 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate /* 106*7c478bd9Sstevel@tonic-gate * Config information 107*7c478bd9Sstevel@tonic-gate */ 108*7c478bd9Sstevel@tonic-gate static int vnex_intr_ops(dev_info_t *dip, dev_info_t *rdip, 109*7c478bd9Sstevel@tonic-gate ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result); 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate static int 112*7c478bd9Sstevel@tonic-gate vnex_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate static struct bus_ops vnex_bus_ops = { 115*7c478bd9Sstevel@tonic-gate BUSO_REV, 116*7c478bd9Sstevel@tonic-gate nullbusmap, 117*7c478bd9Sstevel@tonic-gate NULL, /* NO OP */ 118*7c478bd9Sstevel@tonic-gate NULL, /* NO OP */ 119*7c478bd9Sstevel@tonic-gate NULL, /* NO OP */ 120*7c478bd9Sstevel@tonic-gate i_ddi_map_fault, 121*7c478bd9Sstevel@tonic-gate ddi_no_dma_map, 122*7c478bd9Sstevel@tonic-gate ddi_no_dma_allochdl, 123*7c478bd9Sstevel@tonic-gate NULL, 124*7c478bd9Sstevel@tonic-gate NULL, 125*7c478bd9Sstevel@tonic-gate NULL, 126*7c478bd9Sstevel@tonic-gate NULL, 127*7c478bd9Sstevel@tonic-gate NULL, 128*7c478bd9Sstevel@tonic-gate NULL, 129*7c478bd9Sstevel@tonic-gate vnex_ctl, 130*7c478bd9Sstevel@tonic-gate ddi_bus_prop_op, 131*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_get_eventcookie)(); */ 132*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_add_eventcall)(); */ 133*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_remove_eventcall)(); */ 134*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_post_event)(); */ 135*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_intr_ctl)(); */ 136*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_config)(); */ 137*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_unconfig)(); */ 138*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_fm_init)(); */ 139*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 140*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_fm_access_enter)(); */ 141*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_fm_access_fini)(); */ 142*7c478bd9Sstevel@tonic-gate NULL, /* (*bus_power)(); */ 143*7c478bd9Sstevel@tonic-gate vnex_intr_ops /* (*bus_intr_op)(); */ 144*7c478bd9Sstevel@tonic-gate }; 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate static int vnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 147*7c478bd9Sstevel@tonic-gate static int vnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate static struct dev_ops pseudo_ops = { 150*7c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 151*7c478bd9Sstevel@tonic-gate 0, /* refcnt */ 152*7c478bd9Sstevel@tonic-gate ddi_no_info, /* info */ 153*7c478bd9Sstevel@tonic-gate nulldev, /* identify */ 154*7c478bd9Sstevel@tonic-gate nulldev, /* probe */ 155*7c478bd9Sstevel@tonic-gate vnex_attach, /* attach */ 156*7c478bd9Sstevel@tonic-gate vnex_detach, /* detach */ 157*7c478bd9Sstevel@tonic-gate nodev, /* reset */ 158*7c478bd9Sstevel@tonic-gate (struct cb_ops *)0, /* driver operations */ 159*7c478bd9Sstevel@tonic-gate &vnex_bus_ops, /* bus operations */ 160*7c478bd9Sstevel@tonic-gate nulldev /* power */ 161*7c478bd9Sstevel@tonic-gate }; 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate /* 164*7c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 165*7c478bd9Sstevel@tonic-gate */ 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 168*7c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */ 169*7c478bd9Sstevel@tonic-gate "sun4v virtual-devices nexus driver v%I%", 170*7c478bd9Sstevel@tonic-gate &pseudo_ops, /* driver ops */ 171*7c478bd9Sstevel@tonic-gate }; 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 174*7c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 175*7c478bd9Sstevel@tonic-gate }; 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate int 178*7c478bd9Sstevel@tonic-gate _init(void) 179*7c478bd9Sstevel@tonic-gate { 180*7c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate int 184*7c478bd9Sstevel@tonic-gate _fini(void) 185*7c478bd9Sstevel@tonic-gate { 186*7c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 187*7c478bd9Sstevel@tonic-gate } 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate int 190*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 191*7c478bd9Sstevel@tonic-gate { 192*7c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 196*7c478bd9Sstevel@tonic-gate static int 197*7c478bd9Sstevel@tonic-gate vnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 198*7c478bd9Sstevel@tonic-gate { 199*7c478bd9Sstevel@tonic-gate switch (cmd) { 200*7c478bd9Sstevel@tonic-gate case DDI_ATTACH: 201*7c478bd9Sstevel@tonic-gate /* 202*7c478bd9Sstevel@tonic-gate * Intitialize interrupt descriptor list 203*7c478bd9Sstevel@tonic-gate * and mutex. 204*7c478bd9Sstevel@tonic-gate */ 205*7c478bd9Sstevel@tonic-gate vnex_id_list = NULL; 206*7c478bd9Sstevel@tonic-gate mutex_init(&vnex_id_lock, NULL, MUTEX_DRIVER, NULL); 207*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate case DDI_RESUME: 210*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate default: 213*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 218*7c478bd9Sstevel@tonic-gate static int 219*7c478bd9Sstevel@tonic-gate vnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 220*7c478bd9Sstevel@tonic-gate { 221*7c478bd9Sstevel@tonic-gate switch (cmd) { 222*7c478bd9Sstevel@tonic-gate case DDI_DETACH: 223*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 226*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate default: 229*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate static int 234*7c478bd9Sstevel@tonic-gate vnex_ctl(dev_info_t *dip, dev_info_t *rdip, 235*7c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 236*7c478bd9Sstevel@tonic-gate { 237*7c478bd9Sstevel@tonic-gate char name[12]; /* enough for a decimal integer */ 238*7c478bd9Sstevel@tonic-gate int reglen; 239*7c478bd9Sstevel@tonic-gate uint32_t *vnex_regspec; 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate switch (ctlop) { 242*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 243*7c478bd9Sstevel@tonic-gate if (rdip == NULL) 244*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 245*7c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?virtual-device: %s%d\n", 246*7c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 247*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 250*7c478bd9Sstevel@tonic-gate { 251*7c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_NONE, child, DDI_PROP_DONTPASS, 254*7c478bd9Sstevel@tonic-gate "reg", (caddr_t)&vnex_regspec, ®len) != DDI_SUCCESS) 255*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate (void) sprintf(name, "%x", *vnex_regspec); 258*7c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 259*7c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 260*7c478bd9Sstevel@tonic-gate kmem_free((caddr_t)vnex_regspec, reglen); 261*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 266*7c478bd9Sstevel@tonic-gate { 267*7c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 270*7c478bd9Sstevel@tonic-gate ddi_remove_minor_node(arg, NULL); 271*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate /* 275*7c478bd9Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be called 276*7c478bd9Sstevel@tonic-gate * by a pseudo driver. So we whinge when we're called. 277*7c478bd9Sstevel@tonic-gate */ 278*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 279*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 280*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 281*7c478bd9Sstevel@tonic-gate { 282*7c478bd9Sstevel@tonic-gate *((off_t *)result) = 0; 283*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 284*7c478bd9Sstevel@tonic-gate } 285*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 286*7c478bd9Sstevel@tonic-gate { 287*7c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 288*7c478bd9Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_NONE, child, DDI_PROP_DONTPASS, 289*7c478bd9Sstevel@tonic-gate "reg", (caddr_t)&vnex_regspec, ®len) != DDI_SUCCESS) 290*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 291*7c478bd9Sstevel@tonic-gate *((uint_t *)result) = reglen / sizeof (uint32_t); 292*7c478bd9Sstevel@tonic-gate kmem_free((caddr_t)vnex_regspec, reglen); 293*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NINTRS: 296*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 297*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 298*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 299*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 300*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE: 301*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 302*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INTR_HILEVEL: 303*7c478bd9Sstevel@tonic-gate case DDI_CTLOPS_XLATE_INTRS: 304*7c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n", 305*7c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 306*7c478bd9Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 307*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate /* 310*7c478bd9Sstevel@tonic-gate * Everything else (e.g. PTOB/BTOP/BTOPR requests) we pass up 311*7c478bd9Sstevel@tonic-gate */ 312*7c478bd9Sstevel@tonic-gate default: 313*7c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 314*7c478bd9Sstevel@tonic-gate } 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate static int 318*7c478bd9Sstevel@tonic-gate vnex_get_pil(dev_info_t *rdip) 319*7c478bd9Sstevel@tonic-gate { 320*7c478bd9Sstevel@tonic-gate int i; 321*7c478bd9Sstevel@tonic-gate caddr_t name; 322*7c478bd9Sstevel@tonic-gate 323*7c478bd9Sstevel@tonic-gate name = ddi_node_name(rdip); 324*7c478bd9Sstevel@tonic-gate for (i = 0; i < VNEX_MAX_DEVS; i++) { 325*7c478bd9Sstevel@tonic-gate if (strcmp(vnex_name_to_pil[i].name, 326*7c478bd9Sstevel@tonic-gate name) == 0) { 327*7c478bd9Sstevel@tonic-gate return (vnex_name_to_pil[i].pil); 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate /* 331*7c478bd9Sstevel@tonic-gate * if not found pil is 0 332*7c478bd9Sstevel@tonic-gate */ 333*7c478bd9Sstevel@tonic-gate return (0); 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate static int 337*7c478bd9Sstevel@tonic-gate vnex_enable_intr(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp) 338*7c478bd9Sstevel@tonic-gate { 339*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p; 340*7c478bd9Sstevel@tonic-gate uint32_t cpuid; 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate vid_p = vnex_locate_id(rdip, hdlp->ih_vector); 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate ASSERT(vid_p != NULL); 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate cpuid = intr_dist_cpuid(); 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate if ((hvio_intr_settarget(vid_p->vid_ihdl, cpuid)) != H_EOK) { 349*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 350*7c478bd9Sstevel@tonic-gate } 351*7c478bd9Sstevel@tonic-gate 352*7c478bd9Sstevel@tonic-gate if (hvio_intr_setstate(vid_p->vid_ihdl, HV_INTR_IDLE_STATE) != H_EOK) { 353*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate if ((hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_VALID)) != H_EOK) { 357*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 358*7c478bd9Sstevel@tonic-gate } 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 361*7c478bd9Sstevel@tonic-gate } 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate static int 364*7c478bd9Sstevel@tonic-gate vnex_disable_intr(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp) 365*7c478bd9Sstevel@tonic-gate { 366*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p; 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate vid_p = vnex_locate_id(rdip, hdlp->ih_vector); 369*7c478bd9Sstevel@tonic-gate 370*7c478bd9Sstevel@tonic-gate ASSERT(vid_p != NULL); 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate if (hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_NOTVALID) != H_EOK) { 373*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 377*7c478bd9Sstevel@tonic-gate } 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate static int 380*7c478bd9Sstevel@tonic-gate vnex_add_intr(dev_info_t *dip, dev_info_t *rdip, 381*7c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 382*7c478bd9Sstevel@tonic-gate { 383*7c478bd9Sstevel@tonic-gate int reglen, ret = DDI_SUCCESS; 384*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p; 385*7c478bd9Sstevel@tonic-gate uint64_t cfg; 386*7c478bd9Sstevel@tonic-gate uint32_t ino; 387*7c478bd9Sstevel@tonic-gate uint64_t ihdl; 388*7c478bd9Sstevel@tonic-gate vnex_regspec_t *reg_p; 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_NONE, dip, 391*7c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", (caddr_t)®_p, 392*7c478bd9Sstevel@tonic-gate ®len) != DDI_SUCCESS) { 393*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 394*7c478bd9Sstevel@tonic-gate } 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate /* 397*7c478bd9Sstevel@tonic-gate * get the sun4v config handle for this device 398*7c478bd9Sstevel@tonic-gate */ 399*7c478bd9Sstevel@tonic-gate 400*7c478bd9Sstevel@tonic-gate cfg = SUN4V_REG_SPEC2CFG_HDL(reg_p->physaddr); 401*7c478bd9Sstevel@tonic-gate ino = hdlp->ih_vector; 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate /* 404*7c478bd9Sstevel@tonic-gate * call hv to get vihdl 405*7c478bd9Sstevel@tonic-gate */ 406*7c478bd9Sstevel@tonic-gate if (hvio_intr_devino_to_sysino(cfg, ino, &ihdl) != H_EOK) 407*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate hdlp->ih_vector = ihdl; 410*7c478bd9Sstevel@tonic-gate /* 411*7c478bd9Sstevel@tonic-gate * Allocate a interrupt descriptor (id) with the 412*7c478bd9Sstevel@tonic-gate * the interrupt handler and append it to 413*7c478bd9Sstevel@tonic-gate * the id list. 414*7c478bd9Sstevel@tonic-gate */ 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate vid_p = vnex_alloc_id(rdip, ino, cfg); 417*7c478bd9Sstevel@tonic-gate vid_p->vid_ihdl = ihdl; 418*7c478bd9Sstevel@tonic-gate vid_p->vid_handler = hdlp->ih_cb_func; 419*7c478bd9Sstevel@tonic-gate vid_p->vid_arg1 = hdlp->ih_cb_arg1; 420*7c478bd9Sstevel@tonic-gate vid_p->vid_arg2 = hdlp->ih_cb_arg2; 421*7c478bd9Sstevel@tonic-gate vid_p->vid_ddi_hdlp = hdlp; 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 424*7c478bd9Sstevel@tonic-gate (ddi_intr_handler_t *)vnex_intr_wrapper, (caddr_t)vid_p, NULL); 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate if (hdlp->ih_pri == 0) { 427*7c478bd9Sstevel@tonic-gate hdlp->ih_pri = vnex_get_pil(rdip); 428*7c478bd9Sstevel@tonic-gate } 429*7c478bd9Sstevel@tonic-gate 430*7c478bd9Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 431*7c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) { 432*7c478bd9Sstevel@tonic-gate return (ret); 433*7c478bd9Sstevel@tonic-gate } 434*7c478bd9Sstevel@tonic-gate 435*7c478bd9Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, vid_p->vid_handler, 436*7c478bd9Sstevel@tonic-gate vid_p->vid_arg1, vid_p->vid_arg2); 437*7c478bd9Sstevel@tonic-gate 438*7c478bd9Sstevel@tonic-gate return (ret); 439*7c478bd9Sstevel@tonic-gate } 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate static int 442*7c478bd9Sstevel@tonic-gate vnex_remove_intr(dev_info_t *rdip, 443*7c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 444*7c478bd9Sstevel@tonic-gate { 445*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p; 446*7c478bd9Sstevel@tonic-gate uint32_t ino; 447*7c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 448*7c478bd9Sstevel@tonic-gate 449*7c478bd9Sstevel@tonic-gate ino = hdlp->ih_vector; 450*7c478bd9Sstevel@tonic-gate vid_p = vnex_locate_id(rdip, ino); 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate hdlp->ih_vector = vid_p->vid_ihdl; 453*7c478bd9Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate vnex_free_id(vid_p); 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate return (ret); 458*7c478bd9Sstevel@tonic-gate } 459*7c478bd9Sstevel@tonic-gate 460*7c478bd9Sstevel@tonic-gate static int 461*7c478bd9Sstevel@tonic-gate vnex_intr_ops(dev_info_t *dip, dev_info_t *rdip, 462*7c478bd9Sstevel@tonic-gate ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result) 463*7c478bd9Sstevel@tonic-gate { 464*7c478bd9Sstevel@tonic-gate ddi_ispec_t *ispecp = (ddi_ispec_t *)hdlp->ih_private; 465*7c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 466*7c478bd9Sstevel@tonic-gate 467*7c478bd9Sstevel@tonic-gate switch (intr_op) { 468*7c478bd9Sstevel@tonic-gate case DDI_INTROP_GETCAP: 469*7c478bd9Sstevel@tonic-gate *(int *)result = 0; 470*7c478bd9Sstevel@tonic-gate break; 471*7c478bd9Sstevel@tonic-gate case DDI_INTROP_ALLOC: 472*7c478bd9Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 473*7c478bd9Sstevel@tonic-gate break; 474*7c478bd9Sstevel@tonic-gate case DDI_INTROP_GETPRI: 475*7c478bd9Sstevel@tonic-gate *(int *)result = ispecp->is_pil ? 476*7c478bd9Sstevel@tonic-gate ispecp->is_pil : vnex_get_pil(rdip); 477*7c478bd9Sstevel@tonic-gate break; 478*7c478bd9Sstevel@tonic-gate case DDI_INTROP_FREE: 479*7c478bd9Sstevel@tonic-gate break; 480*7c478bd9Sstevel@tonic-gate case DDI_INTROP_SETPRI: 481*7c478bd9Sstevel@tonic-gate ispecp->is_pil = (*(int *)result); 482*7c478bd9Sstevel@tonic-gate break; 483*7c478bd9Sstevel@tonic-gate case DDI_INTROP_ADDISR: 484*7c478bd9Sstevel@tonic-gate hdlp->ih_vector = *ispecp->is_intr; 485*7c478bd9Sstevel@tonic-gate ret = vnex_add_intr(dip, rdip, hdlp); 486*7c478bd9Sstevel@tonic-gate break; 487*7c478bd9Sstevel@tonic-gate case DDI_INTROP_REMISR: 488*7c478bd9Sstevel@tonic-gate hdlp->ih_vector = *ispecp->is_intr; 489*7c478bd9Sstevel@tonic-gate ret = vnex_remove_intr(rdip, hdlp); 490*7c478bd9Sstevel@tonic-gate break; 491*7c478bd9Sstevel@tonic-gate case DDI_INTROP_ENABLE: 492*7c478bd9Sstevel@tonic-gate hdlp->ih_vector = *ispecp->is_intr; 493*7c478bd9Sstevel@tonic-gate ret = vnex_enable_intr(rdip, hdlp); 494*7c478bd9Sstevel@tonic-gate break; 495*7c478bd9Sstevel@tonic-gate case DDI_INTROP_DISABLE: 496*7c478bd9Sstevel@tonic-gate hdlp->ih_vector = *ispecp->is_intr; 497*7c478bd9Sstevel@tonic-gate ret = vnex_disable_intr(rdip, hdlp); 498*7c478bd9Sstevel@tonic-gate break; 499*7c478bd9Sstevel@tonic-gate case DDI_INTROP_NINTRS: 500*7c478bd9Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 501*7c478bd9Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip); 502*7c478bd9Sstevel@tonic-gate break; 503*7c478bd9Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 504*7c478bd9Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip) ? 505*7c478bd9Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0; 506*7c478bd9Sstevel@tonic-gate break; 507*7c478bd9Sstevel@tonic-gate default: 508*7c478bd9Sstevel@tonic-gate ret = DDI_ENOTSUP; 509*7c478bd9Sstevel@tonic-gate break; 510*7c478bd9Sstevel@tonic-gate } 511*7c478bd9Sstevel@tonic-gate 512*7c478bd9Sstevel@tonic-gate return (ret); 513*7c478bd9Sstevel@tonic-gate } 514*7c478bd9Sstevel@tonic-gate 515*7c478bd9Sstevel@tonic-gate vnex_id_t * 516*7c478bd9Sstevel@tonic-gate vnex_alloc_id(dev_info_t *dip, uint32_t ino, uint64_t dhdl) 517*7c478bd9Sstevel@tonic-gate { 518*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p = kmem_alloc(sizeof (vnex_id_t), KM_SLEEP); 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate vid_p->vid_dip = dip; 521*7c478bd9Sstevel@tonic-gate vid_p->vid_ino = ino; 522*7c478bd9Sstevel@tonic-gate vid_p->vid_cfg_hdl = dhdl; 523*7c478bd9Sstevel@tonic-gate 524*7c478bd9Sstevel@tonic-gate mutex_enter(&vnex_id_lock); 525*7c478bd9Sstevel@tonic-gate vnex_add_id(vid_p); 526*7c478bd9Sstevel@tonic-gate mutex_exit(&vnex_id_lock); 527*7c478bd9Sstevel@tonic-gate 528*7c478bd9Sstevel@tonic-gate return (vid_p); 529*7c478bd9Sstevel@tonic-gate } 530*7c478bd9Sstevel@tonic-gate 531*7c478bd9Sstevel@tonic-gate vnex_id_t * 532*7c478bd9Sstevel@tonic-gate vnex_locate_id(dev_info_t *dip, uint32_t ino) 533*7c478bd9Sstevel@tonic-gate { 534*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p; 535*7c478bd9Sstevel@tonic-gate 536*7c478bd9Sstevel@tonic-gate mutex_enter(&vnex_id_lock); 537*7c478bd9Sstevel@tonic-gate vid_p = vnex_id_list; 538*7c478bd9Sstevel@tonic-gate 539*7c478bd9Sstevel@tonic-gate while (vid_p != NULL) { 540*7c478bd9Sstevel@tonic-gate if (vid_p->vid_dip == dip && vid_p->vid_ino == ino) { 541*7c478bd9Sstevel@tonic-gate mutex_exit(&vnex_id_lock); 542*7c478bd9Sstevel@tonic-gate return (vid_p); 543*7c478bd9Sstevel@tonic-gate } 544*7c478bd9Sstevel@tonic-gate vid_p = vid_p->vid_next; 545*7c478bd9Sstevel@tonic-gate } 546*7c478bd9Sstevel@tonic-gate mutex_exit(&vnex_id_lock); 547*7c478bd9Sstevel@tonic-gate return (NULL); 548*7c478bd9Sstevel@tonic-gate } 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate static void 551*7c478bd9Sstevel@tonic-gate vnex_free_id(vnex_id_t *vid_p) 552*7c478bd9Sstevel@tonic-gate { 553*7c478bd9Sstevel@tonic-gate mutex_enter(&vnex_id_lock); 554*7c478bd9Sstevel@tonic-gate vnex_rem_id(vid_p); 555*7c478bd9Sstevel@tonic-gate mutex_exit(&vnex_id_lock); 556*7c478bd9Sstevel@tonic-gate 557*7c478bd9Sstevel@tonic-gate kmem_free(vid_p, sizeof (*vid_p)); 558*7c478bd9Sstevel@tonic-gate } 559*7c478bd9Sstevel@tonic-gate 560*7c478bd9Sstevel@tonic-gate static void 561*7c478bd9Sstevel@tonic-gate vnex_rem_id(vnex_id_t *vid_p) 562*7c478bd9Sstevel@tonic-gate { 563*7c478bd9Sstevel@tonic-gate if (vid_p->vid_prev == NULL) { 564*7c478bd9Sstevel@tonic-gate vnex_id_list = vid_p->vid_next; 565*7c478bd9Sstevel@tonic-gate vid_p->vid_prev = NULL; 566*7c478bd9Sstevel@tonic-gate } else if (vid_p->vid_next == NULL) { 567*7c478bd9Sstevel@tonic-gate vid_p->vid_prev->vid_next = NULL; 568*7c478bd9Sstevel@tonic-gate } else { 569*7c478bd9Sstevel@tonic-gate vid_p->vid_prev->vid_next = vid_p->vid_next; 570*7c478bd9Sstevel@tonic-gate vid_p->vid_next->vid_prev = vid_p->vid_prev; 571*7c478bd9Sstevel@tonic-gate } 572*7c478bd9Sstevel@tonic-gate } 573*7c478bd9Sstevel@tonic-gate 574*7c478bd9Sstevel@tonic-gate static void 575*7c478bd9Sstevel@tonic-gate vnex_add_id(vnex_id_t *vid_p) 576*7c478bd9Sstevel@tonic-gate { 577*7c478bd9Sstevel@tonic-gate if (vnex_id_list == NULL) { 578*7c478bd9Sstevel@tonic-gate vnex_id_list = vid_p; 579*7c478bd9Sstevel@tonic-gate vid_p->vid_next = NULL; 580*7c478bd9Sstevel@tonic-gate vid_p->vid_prev = NULL; 581*7c478bd9Sstevel@tonic-gate return; 582*7c478bd9Sstevel@tonic-gate } 583*7c478bd9Sstevel@tonic-gate /* 584*7c478bd9Sstevel@tonic-gate * We always just add to the front of the list 585*7c478bd9Sstevel@tonic-gate */ 586*7c478bd9Sstevel@tonic-gate vnex_id_list->vid_prev = vid_p; 587*7c478bd9Sstevel@tonic-gate vid_p->vid_next = vnex_id_list; 588*7c478bd9Sstevel@tonic-gate vid_p->vid_prev = NULL; 589*7c478bd9Sstevel@tonic-gate vnex_id_list = vid_p; 590*7c478bd9Sstevel@tonic-gate } 591*7c478bd9Sstevel@tonic-gate 592*7c478bd9Sstevel@tonic-gate uint_t 593*7c478bd9Sstevel@tonic-gate vnex_intr_wrapper(caddr_t arg) 594*7c478bd9Sstevel@tonic-gate { 595*7c478bd9Sstevel@tonic-gate vnex_id_t *vid_p = (vnex_id_t *)arg; 596*7c478bd9Sstevel@tonic-gate int res; 597*7c478bd9Sstevel@tonic-gate uint_t (*handler)(); 598*7c478bd9Sstevel@tonic-gate caddr_t handler_arg1; 599*7c478bd9Sstevel@tonic-gate caddr_t handler_arg2; 600*7c478bd9Sstevel@tonic-gate 601*7c478bd9Sstevel@tonic-gate handler = vid_p->vid_handler; 602*7c478bd9Sstevel@tonic-gate handler_arg1 = vid_p->vid_arg1; 603*7c478bd9Sstevel@tonic-gate handler_arg2 = vid_p->vid_arg2; 604*7c478bd9Sstevel@tonic-gate 605*7c478bd9Sstevel@tonic-gate res = (*handler)(handler_arg1, handler_arg2); 606*7c478bd9Sstevel@tonic-gate 607*7c478bd9Sstevel@tonic-gate (void) hvio_intr_setstate(vid_p->vid_ihdl, HV_INTR_IDLE_STATE); 608*7c478bd9Sstevel@tonic-gate 609*7c478bd9Sstevel@tonic-gate return (res); 610*7c478bd9Sstevel@tonic-gate } 611