1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * ISA bus nexus driver 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <sys/types.h> 34*0Sstevel@tonic-gate #include <sys/cmn_err.h> 35*0Sstevel@tonic-gate #include <sys/conf.h> 36*0Sstevel@tonic-gate #include <sys/modctl.h> 37*0Sstevel@tonic-gate #include <sys/autoconf.h> 38*0Sstevel@tonic-gate #include <sys/errno.h> 39*0Sstevel@tonic-gate #include <sys/debug.h> 40*0Sstevel@tonic-gate #include <sys/kmem.h> 41*0Sstevel@tonic-gate #include <sys/ddidmareq.h> 42*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 43*0Sstevel@tonic-gate #include <sys/dma_engine.h> 44*0Sstevel@tonic-gate #include <sys/ddi.h> 45*0Sstevel@tonic-gate #include <sys/sunddi.h> 46*0Sstevel@tonic-gate #include <sys/sunndi.h> 47*0Sstevel@tonic-gate #include <sys/acpi/acpi_enum.h> 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate extern int isa_resource_setup(void); 50*0Sstevel@tonic-gate static char USED_RESOURCES[] = "used-resources"; 51*0Sstevel@tonic-gate static void isa_alloc_nodes(dev_info_t *); 52*0Sstevel@tonic-gate /* 53*0Sstevel@tonic-gate * #define ISA_DEBUG 1 54*0Sstevel@tonic-gate */ 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate /* 57*0Sstevel@tonic-gate * Local data 58*0Sstevel@tonic-gate */ 59*0Sstevel@tonic-gate static ddi_dma_lim_t ISA_dma_limits = { 60*0Sstevel@tonic-gate 0, /* address low */ 61*0Sstevel@tonic-gate 0x00ffffff, /* address high */ 62*0Sstevel@tonic-gate 0, /* counter max */ 63*0Sstevel@tonic-gate 1, /* burstsize */ 64*0Sstevel@tonic-gate DMA_UNIT_8, /* minimum xfer */ 65*0Sstevel@tonic-gate 0, /* dma speed */ 66*0Sstevel@tonic-gate (uint_t)DMALIM_VER0, /* version */ 67*0Sstevel@tonic-gate 0x0000ffff, /* address register */ 68*0Sstevel@tonic-gate 0x0000ffff, /* counter register */ 69*0Sstevel@tonic-gate 1, /* sector size */ 70*0Sstevel@tonic-gate 0x00000001, /* scatter/gather list length */ 71*0Sstevel@tonic-gate (uint_t)0xffffffff /* request size */ 72*0Sstevel@tonic-gate }; 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate static ddi_dma_attr_t ISA_dma_attr = { 75*0Sstevel@tonic-gate DMA_ATTR_V0, 76*0Sstevel@tonic-gate (unsigned long long)0, 77*0Sstevel@tonic-gate (unsigned long long)0x00ffffff, 78*0Sstevel@tonic-gate 0x0000ffff, 79*0Sstevel@tonic-gate 1, 80*0Sstevel@tonic-gate 1, 81*0Sstevel@tonic-gate 1, 82*0Sstevel@tonic-gate (unsigned long long)0xffffffff, 83*0Sstevel@tonic-gate (unsigned long long)0x0000ffff, 84*0Sstevel@tonic-gate 1, 85*0Sstevel@tonic-gate 1, 86*0Sstevel@tonic-gate 0 87*0Sstevel@tonic-gate }; 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate /* 91*0Sstevel@tonic-gate * Config information 92*0Sstevel@tonic-gate */ 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate static int 95*0Sstevel@tonic-gate isa_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, 96*0Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *); 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate static int 99*0Sstevel@tonic-gate isa_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t, enum ddi_dma_ctlops, 100*0Sstevel@tonic-gate off_t *, size_t *, caddr_t *, uint_t); 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate static int 103*0Sstevel@tonic-gate isa_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate struct bus_ops isa_bus_ops = { 106*0Sstevel@tonic-gate BUSO_REV, 107*0Sstevel@tonic-gate i_ddi_bus_map, 108*0Sstevel@tonic-gate NULL, 109*0Sstevel@tonic-gate NULL, 110*0Sstevel@tonic-gate NULL, 111*0Sstevel@tonic-gate i_ddi_map_fault, 112*0Sstevel@tonic-gate ddi_dma_map, 113*0Sstevel@tonic-gate isa_dma_allochdl, 114*0Sstevel@tonic-gate ddi_dma_freehdl, 115*0Sstevel@tonic-gate ddi_dma_bindhdl, 116*0Sstevel@tonic-gate ddi_dma_unbindhdl, 117*0Sstevel@tonic-gate ddi_dma_flush, 118*0Sstevel@tonic-gate ddi_dma_win, 119*0Sstevel@tonic-gate isa_dma_mctl, 120*0Sstevel@tonic-gate isa_ctlops, 121*0Sstevel@tonic-gate ddi_bus_prop_op, 122*0Sstevel@tonic-gate NULL, /* (*bus_get_eventcookie)(); */ 123*0Sstevel@tonic-gate NULL, /* (*bus_add_eventcall)(); */ 124*0Sstevel@tonic-gate NULL, /* (*bus_remove_eventcall)(); */ 125*0Sstevel@tonic-gate NULL, /* (*bus_post_event)(); */ 126*0Sstevel@tonic-gate NULL, /* (*bus_intr_ctl)(); */ 127*0Sstevel@tonic-gate NULL, /* (*bus_config)(); */ 128*0Sstevel@tonic-gate NULL, /* (*bus_unconfig)(); */ 129*0Sstevel@tonic-gate NULL, /* (*bus_fm_init)(); */ 130*0Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 131*0Sstevel@tonic-gate NULL, /* (*bus_fm_access_enter)(); */ 132*0Sstevel@tonic-gate NULL, /* (*bus_fm_access_exit)(); */ 133*0Sstevel@tonic-gate NULL, /* (*bus_power)(); */ 134*0Sstevel@tonic-gate i_ddi_intr_ops /* (*bus_intr_op)(); */ 135*0Sstevel@tonic-gate }; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate static int isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate /* 141*0Sstevel@tonic-gate * Internal isa ctlops support routines 142*0Sstevel@tonic-gate */ 143*0Sstevel@tonic-gate static int isa_initchild(dev_info_t *child); 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate struct dev_ops isa_ops = { 146*0Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 147*0Sstevel@tonic-gate 0, /* refcnt */ 148*0Sstevel@tonic-gate ddi_no_info, /* info */ 149*0Sstevel@tonic-gate nulldev, /* identify */ 150*0Sstevel@tonic-gate nulldev, /* probe */ 151*0Sstevel@tonic-gate isa_attach, /* attach */ 152*0Sstevel@tonic-gate nodev, /* detach */ 153*0Sstevel@tonic-gate nodev, /* reset */ 154*0Sstevel@tonic-gate (struct cb_ops *)0, /* driver operations */ 155*0Sstevel@tonic-gate &isa_bus_ops /* bus operations */ 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate }; 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate /* 160*0Sstevel@tonic-gate * Module linkage information for the kernel. 161*0Sstevel@tonic-gate */ 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate static struct modldrv modldrv = { 164*0Sstevel@tonic-gate &mod_driverops, /* Type of module. This is ISA bus driver */ 165*0Sstevel@tonic-gate "isa nexus driver for 'ISA' %I%", 166*0Sstevel@tonic-gate &isa_ops, /* driver ops */ 167*0Sstevel@tonic-gate }; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 170*0Sstevel@tonic-gate MODREV_1, 171*0Sstevel@tonic-gate &modldrv, 172*0Sstevel@tonic-gate NULL 173*0Sstevel@tonic-gate }; 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate int 176*0Sstevel@tonic-gate _init(void) 177*0Sstevel@tonic-gate { 178*0Sstevel@tonic-gate return (mod_install(&modlinkage)); 179*0Sstevel@tonic-gate } 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate int 182*0Sstevel@tonic-gate _fini(void) 183*0Sstevel@tonic-gate { 184*0Sstevel@tonic-gate return (mod_remove(&modlinkage)); 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate int 188*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 189*0Sstevel@tonic-gate { 190*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 191*0Sstevel@tonic-gate } 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate static int 194*0Sstevel@tonic-gate isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 195*0Sstevel@tonic-gate { 196*0Sstevel@tonic-gate int rval; 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate if (cmd != DDI_ATTACH) 199*0Sstevel@tonic-gate return (DDI_FAILURE); 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate if ((rval = i_dmae_init(devi)) == DDI_SUCCESS) { 202*0Sstevel@tonic-gate ddi_report_dev(devi); 203*0Sstevel@tonic-gate /* 204*0Sstevel@tonic-gate * Enumerate children -- invoking ACPICA 205*0Sstevel@tonic-gate * This is normally in bus_config(), but we need this 206*0Sstevel@tonic-gate * to happen earlier to boot. 207*0Sstevel@tonic-gate */ 208*0Sstevel@tonic-gate isa_alloc_nodes(devi); 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate return (rval); 211*0Sstevel@tonic-gate } 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate static int 214*0Sstevel@tonic-gate isa_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *dma_attr, 215*0Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 216*0Sstevel@tonic-gate { 217*0Sstevel@tonic-gate ddi_dma_attr_merge(dma_attr, &ISA_dma_attr); 218*0Sstevel@tonic-gate return (ddi_dma_allochdl(dip, rdip, dma_attr, waitfp, arg, handlep)); 219*0Sstevel@tonic-gate } 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate static int 222*0Sstevel@tonic-gate isa_dma_mctl(dev_info_t *dip, dev_info_t *rdip, 223*0Sstevel@tonic-gate ddi_dma_handle_t handle, enum ddi_dma_ctlops request, 224*0Sstevel@tonic-gate off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags) 225*0Sstevel@tonic-gate { 226*0Sstevel@tonic-gate int rval; 227*0Sstevel@tonic-gate ddi_dma_lim_t defalt; 228*0Sstevel@tonic-gate int arg = (int)(uintptr_t)objp; 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate switch (request) { 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate case DDI_DMA_E_PROG: 233*0Sstevel@tonic-gate return (i_dmae_prog(rdip, (struct ddi_dmae_req *)offp, 234*0Sstevel@tonic-gate (ddi_dma_cookie_t *)lenp, arg)); 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate case DDI_DMA_E_ACQUIRE: 237*0Sstevel@tonic-gate return (i_dmae_acquire(rdip, arg, (int(*)(caddr_t))offp, 238*0Sstevel@tonic-gate (caddr_t)lenp)); 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate case DDI_DMA_E_FREE: 241*0Sstevel@tonic-gate return (i_dmae_free(rdip, arg)); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate case DDI_DMA_E_STOP: 244*0Sstevel@tonic-gate i_dmae_stop(rdip, arg); 245*0Sstevel@tonic-gate return (DDI_SUCCESS); 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate case DDI_DMA_E_ENABLE: 248*0Sstevel@tonic-gate i_dmae_enable(rdip, arg); 249*0Sstevel@tonic-gate return (DDI_SUCCESS); 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate case DDI_DMA_E_DISABLE: 252*0Sstevel@tonic-gate i_dmae_disable(rdip, arg); 253*0Sstevel@tonic-gate return (DDI_SUCCESS); 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate case DDI_DMA_E_GETCNT: 256*0Sstevel@tonic-gate i_dmae_get_chan_stat(rdip, arg, NULL, (int *)lenp); 257*0Sstevel@tonic-gate return (DDI_SUCCESS); 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate case DDI_DMA_E_SWSETUP: 260*0Sstevel@tonic-gate return (i_dmae_swsetup(rdip, (struct ddi_dmae_req *)offp, 261*0Sstevel@tonic-gate (ddi_dma_cookie_t *)lenp, arg)); 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate case DDI_DMA_E_SWSTART: 264*0Sstevel@tonic-gate i_dmae_swstart(rdip, arg); 265*0Sstevel@tonic-gate return (DDI_SUCCESS); 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate case DDI_DMA_E_GETLIM: 268*0Sstevel@tonic-gate bcopy(&ISA_dma_limits, objp, sizeof (ddi_dma_lim_t)); 269*0Sstevel@tonic-gate return (DDI_SUCCESS); 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate case DDI_DMA_E_GETATTR: 272*0Sstevel@tonic-gate bcopy(&ISA_dma_attr, objp, sizeof (ddi_dma_attr_t)); 273*0Sstevel@tonic-gate return (DDI_SUCCESS); 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate case DDI_DMA_E_1STPTY: 276*0Sstevel@tonic-gate { 277*0Sstevel@tonic-gate struct ddi_dmae_req req1stpty = 278*0Sstevel@tonic-gate { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 279*0Sstevel@tonic-gate if (arg == 0) { 280*0Sstevel@tonic-gate req1stpty.der_command = DMAE_CMD_TRAN; 281*0Sstevel@tonic-gate req1stpty.der_trans = DMAE_TRANS_DMND; 282*0Sstevel@tonic-gate } else { 283*0Sstevel@tonic-gate req1stpty.der_trans = DMAE_TRANS_CSCD; 284*0Sstevel@tonic-gate } 285*0Sstevel@tonic-gate return (i_dmae_prog(rdip, &req1stpty, NULL, arg)); 286*0Sstevel@tonic-gate } 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate case DDI_DMA_IOPB_ALLOC: /* get contiguous DMA-able memory */ 289*0Sstevel@tonic-gate case DDI_DMA_SMEM_ALLOC: 290*0Sstevel@tonic-gate if (!offp) { 291*0Sstevel@tonic-gate defalt = ISA_dma_limits; 292*0Sstevel@tonic-gate offp = (off_t *)&defalt; 293*0Sstevel@tonic-gate } 294*0Sstevel@tonic-gate /*FALLTHROUGH*/ 295*0Sstevel@tonic-gate default: 296*0Sstevel@tonic-gate rval = ddi_dma_mctl(dip, rdip, handle, request, offp, 297*0Sstevel@tonic-gate lenp, objp, flags); 298*0Sstevel@tonic-gate } 299*0Sstevel@tonic-gate return (rval); 300*0Sstevel@tonic-gate } 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate /* 303*0Sstevel@tonic-gate * Check if driver should be treated as an old pre 2.6 driver 304*0Sstevel@tonic-gate */ 305*0Sstevel@tonic-gate static int 306*0Sstevel@tonic-gate old_driver(dev_info_t *dip) 307*0Sstevel@tonic-gate { 308*0Sstevel@tonic-gate extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */ 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate if (ndi_dev_is_persistent_node(dip)) { 311*0Sstevel@tonic-gate if (ignore_hardware_nodes) 312*0Sstevel@tonic-gate return (1); 313*0Sstevel@tonic-gate if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 314*0Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1) 315*0Sstevel@tonic-gate return (1); 316*0Sstevel@tonic-gate } 317*0Sstevel@tonic-gate return (0); 318*0Sstevel@tonic-gate } 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gate typedef struct { 321*0Sstevel@tonic-gate uint32_t phys_hi; 322*0Sstevel@tonic-gate uint32_t phys_lo; 323*0Sstevel@tonic-gate uint32_t size; 324*0Sstevel@tonic-gate } isa_regs_t; 325*0Sstevel@tonic-gate 326*0Sstevel@tonic-gate /* 327*0Sstevel@tonic-gate * Return non-zero if device in tree is a PnP isa device 328*0Sstevel@tonic-gate */ 329*0Sstevel@tonic-gate static int 330*0Sstevel@tonic-gate is_pnpisa(dev_info_t *dip) 331*0Sstevel@tonic-gate { 332*0Sstevel@tonic-gate isa_regs_t *isa_regs; 333*0Sstevel@tonic-gate int proplen, pnpisa; 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate if (ndi_dev_is_persistent_node(dip) == 0) 336*0Sstevel@tonic-gate return (0); 337*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg", 338*0Sstevel@tonic-gate (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) { 339*0Sstevel@tonic-gate return (0); 340*0Sstevel@tonic-gate } 341*0Sstevel@tonic-gate pnpisa = isa_regs[0].phys_hi & 0x80000000; 342*0Sstevel@tonic-gate /* 343*0Sstevel@tonic-gate * free the memory allocated by ddi_getlongprop(). 344*0Sstevel@tonic-gate */ 345*0Sstevel@tonic-gate kmem_free(isa_regs, proplen); 346*0Sstevel@tonic-gate if (pnpisa) 347*0Sstevel@tonic-gate return (1); 348*0Sstevel@tonic-gate else 349*0Sstevel@tonic-gate return (0); 350*0Sstevel@tonic-gate } 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate /*ARGSUSED*/ 353*0Sstevel@tonic-gate static int 354*0Sstevel@tonic-gate isa_ctlops(dev_info_t *dip, dev_info_t *rdip, 355*0Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 356*0Sstevel@tonic-gate { 357*0Sstevel@tonic-gate switch (ctlop) { 358*0Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 359*0Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 360*0Sstevel@tonic-gate return (DDI_FAILURE); 361*0Sstevel@tonic-gate cmn_err(CE_CONT, "?ISA-device: %s%d\n", 362*0Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 363*0Sstevel@tonic-gate return (DDI_SUCCESS); 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 366*0Sstevel@tonic-gate /* 367*0Sstevel@tonic-gate * older drivers aren't expecting the "standard" device 368*0Sstevel@tonic-gate * node format used by the hardware nodes. these drivers 369*0Sstevel@tonic-gate * only expect their own properties set in their driver.conf 370*0Sstevel@tonic-gate * files. so they tell us not to call them with hardware 371*0Sstevel@tonic-gate * nodes by setting the property "ignore-hardware-nodes". 372*0Sstevel@tonic-gate */ 373*0Sstevel@tonic-gate if (old_driver((dev_info_t *)arg)) { 374*0Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 375*0Sstevel@tonic-gate } 376*0Sstevel@tonic-gate 377*0Sstevel@tonic-gate return (isa_initchild((dev_info_t *)arg)); 378*0Sstevel@tonic-gate 379*0Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 380*0Sstevel@tonic-gate impl_ddi_sunbus_removechild((dev_info_t *)arg); 381*0Sstevel@tonic-gate return (DDI_SUCCESS); 382*0Sstevel@tonic-gate 383*0Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 384*0Sstevel@tonic-gate /* 385*0Sstevel@tonic-gate * All ISA devices need to do confirming probes 386*0Sstevel@tonic-gate * unless they are PnP ISA. 387*0Sstevel@tonic-gate */ 388*0Sstevel@tonic-gate if (is_pnpisa(dip)) 389*0Sstevel@tonic-gate return (DDI_SUCCESS); 390*0Sstevel@tonic-gate else 391*0Sstevel@tonic-gate return (DDI_FAILURE); 392*0Sstevel@tonic-gate 393*0Sstevel@tonic-gate default: 394*0Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 395*0Sstevel@tonic-gate } 396*0Sstevel@tonic-gate } 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate static void 399*0Sstevel@tonic-gate isa_vendor(uint32_t id, char *vendor) 400*0Sstevel@tonic-gate { 401*0Sstevel@tonic-gate vendor[0] = '@' + ((id >> 26) & 0x1f); 402*0Sstevel@tonic-gate vendor[1] = '@' + ((id >> 21) & 0x1f); 403*0Sstevel@tonic-gate vendor[2] = '@' + ((id >> 16) & 0x1f); 404*0Sstevel@tonic-gate vendor[3] = 0; 405*0Sstevel@tonic-gate } 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gate /* 408*0Sstevel@tonic-gate * Name a child 409*0Sstevel@tonic-gate */ 410*0Sstevel@tonic-gate static int 411*0Sstevel@tonic-gate isa_name_child(dev_info_t *child, char *name, int namelen) 412*0Sstevel@tonic-gate { 413*0Sstevel@tonic-gate char vendor[8]; 414*0Sstevel@tonic-gate int device; 415*0Sstevel@tonic-gate uint32_t serial; 416*0Sstevel@tonic-gate int func; 417*0Sstevel@tonic-gate int bustype; 418*0Sstevel@tonic-gate uint32_t base; 419*0Sstevel@tonic-gate int proplen; 420*0Sstevel@tonic-gate int pnpisa = 0; 421*0Sstevel@tonic-gate isa_regs_t *isa_regs; 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate void make_ddi_ppd(dev_info_t *, struct ddi_parent_private_data **); 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate /* 426*0Sstevel@tonic-gate * older drivers aren't expecting the "standard" device 427*0Sstevel@tonic-gate * node format used by the hardware nodes. these drivers 428*0Sstevel@tonic-gate * only expect their own properties set in their driver.conf 429*0Sstevel@tonic-gate * files. so they tell us not to call them with hardware 430*0Sstevel@tonic-gate * nodes by setting the property "ignore-hardware-nodes". 431*0Sstevel@tonic-gate */ 432*0Sstevel@tonic-gate if (old_driver(child)) 433*0Sstevel@tonic-gate return (DDI_FAILURE); 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate /* 436*0Sstevel@tonic-gate * Fill in parent-private data 437*0Sstevel@tonic-gate */ 438*0Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 439*0Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 440*0Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 441*0Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 442*0Sstevel@tonic-gate } 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 445*0Sstevel@tonic-gate /* 446*0Sstevel@tonic-gate * For .conf nodes, generate name from parent private data 447*0Sstevel@tonic-gate */ 448*0Sstevel@tonic-gate name[0] = '\0'; 449*0Sstevel@tonic-gate if (sparc_pd_getnreg(child) > 0) { 450*0Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 451*0Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 452*0Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 453*0Sstevel@tonic-gate } 454*0Sstevel@tonic-gate return (DDI_SUCCESS); 455*0Sstevel@tonic-gate } 456*0Sstevel@tonic-gate 457*0Sstevel@tonic-gate /* 458*0Sstevel@tonic-gate * For hw nodes, look up "reg" property 459*0Sstevel@tonic-gate */ 460*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg", 461*0Sstevel@tonic-gate (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) { 462*0Sstevel@tonic-gate return (DDI_FAILURE); 463*0Sstevel@tonic-gate } 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate /* 466*0Sstevel@tonic-gate * extract the device identifications 467*0Sstevel@tonic-gate */ 468*0Sstevel@tonic-gate pnpisa = isa_regs[0].phys_hi & 0x80000000; 469*0Sstevel@tonic-gate if (pnpisa) { 470*0Sstevel@tonic-gate isa_vendor(isa_regs[0].phys_hi, vendor); 471*0Sstevel@tonic-gate device = isa_regs[0].phys_hi & 0xffff; 472*0Sstevel@tonic-gate serial = isa_regs[0].phys_lo; 473*0Sstevel@tonic-gate func = (isa_regs[0].size >> 24) & 0xff; 474*0Sstevel@tonic-gate if (func != 0) 475*0Sstevel@tonic-gate (void) snprintf(name, namelen, "pnp%s,%04x,%x,%x", 476*0Sstevel@tonic-gate vendor, device, serial, func); 477*0Sstevel@tonic-gate else 478*0Sstevel@tonic-gate (void) snprintf(name, namelen, "pnp%s,%04x,%x", 479*0Sstevel@tonic-gate vendor, device, serial); 480*0Sstevel@tonic-gate } else { 481*0Sstevel@tonic-gate bustype = isa_regs[0].phys_hi; 482*0Sstevel@tonic-gate base = isa_regs[0].phys_lo; 483*0Sstevel@tonic-gate (void) sprintf(name, "%x,%x", bustype, base); 484*0Sstevel@tonic-gate } 485*0Sstevel@tonic-gate 486*0Sstevel@tonic-gate /* 487*0Sstevel@tonic-gate * free the memory allocated by ddi_getlongprop(). 488*0Sstevel@tonic-gate */ 489*0Sstevel@tonic-gate kmem_free(isa_regs, proplen); 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate return (DDI_SUCCESS); 492*0Sstevel@tonic-gate } 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gate static int 495*0Sstevel@tonic-gate isa_initchild(dev_info_t *child) 496*0Sstevel@tonic-gate { 497*0Sstevel@tonic-gate char name[80]; 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate if (isa_name_child(child, name, 80) != DDI_SUCCESS) 500*0Sstevel@tonic-gate return (DDI_FAILURE); 501*0Sstevel@tonic-gate ddi_set_name_addr(child, name); 502*0Sstevel@tonic-gate 503*0Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) != 0) 504*0Sstevel@tonic-gate return (DDI_SUCCESS); 505*0Sstevel@tonic-gate 506*0Sstevel@tonic-gate /* 507*0Sstevel@tonic-gate * This is a .conf node, try merge properties onto a 508*0Sstevel@tonic-gate * hw node with the same name. 509*0Sstevel@tonic-gate */ 510*0Sstevel@tonic-gate if (ndi_merge_node(child, isa_name_child) == DDI_SUCCESS) { 511*0Sstevel@tonic-gate /* 512*0Sstevel@tonic-gate * Return failure to remove node 513*0Sstevel@tonic-gate */ 514*0Sstevel@tonic-gate impl_ddi_sunbus_removechild(child); 515*0Sstevel@tonic-gate return (DDI_FAILURE); 516*0Sstevel@tonic-gate } 517*0Sstevel@tonic-gate /* 518*0Sstevel@tonic-gate * Cannot merge node, permit pseudo children 519*0Sstevel@tonic-gate */ 520*0Sstevel@tonic-gate return (DDI_SUCCESS); 521*0Sstevel@tonic-gate } 522*0Sstevel@tonic-gate 523*0Sstevel@tonic-gate /* 524*0Sstevel@tonic-gate * called when ACPI enumeration is not used 525*0Sstevel@tonic-gate */ 526*0Sstevel@tonic-gate static void 527*0Sstevel@tonic-gate add_known_used_resources(void) 528*0Sstevel@tonic-gate { 529*0Sstevel@tonic-gate /* needs to be in increasing order */ 530*0Sstevel@tonic-gate int intr[] = {0x1, 0x3, 0x4, 0x6, 0x7, 0xc}; 531*0Sstevel@tonic-gate int dma[] = {0x2}; 532*0Sstevel@tonic-gate int io[] = {0x60, 0x1, 0x64, 0x1, 0x2f8, 0x8, 0x378, 0x8, 0x3f0, 0x10, 533*0Sstevel@tonic-gate 0x778, 0x4}; 534*0Sstevel@tonic-gate dev_info_t *usedrdip; 535*0Sstevel@tonic-gate 536*0Sstevel@tonic-gate usedrdip = ddi_find_devinfo(USED_RESOURCES, -1, 0); 537*0Sstevel@tonic-gate 538*0Sstevel@tonic-gate if (usedrdip == NULL) { 539*0Sstevel@tonic-gate (void) ndi_devi_alloc_sleep(ddi_root_node(), USED_RESOURCES, 540*0Sstevel@tonic-gate (dnode_t)DEVI_SID_NODEID, &usedrdip); 541*0Sstevel@tonic-gate } 542*0Sstevel@tonic-gate 543*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 544*0Sstevel@tonic-gate "interrupts", (int *)intr, (int)(sizeof (intr) / sizeof (int))); 545*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 546*0Sstevel@tonic-gate "io-space", (int *)io, (int)(sizeof (io) / sizeof (int))); 547*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 548*0Sstevel@tonic-gate "dma-channels", (int *)dma, (int)(sizeof (dma) / sizeof (int))); 549*0Sstevel@tonic-gate (void) ndi_devi_bind_driver(usedrdip, 0); 550*0Sstevel@tonic-gate 551*0Sstevel@tonic-gate } 552*0Sstevel@tonic-gate 553*0Sstevel@tonic-gate static void 554*0Sstevel@tonic-gate isa_alloc_nodes(dev_info_t *isa_dip) 555*0Sstevel@tonic-gate { 556*0Sstevel@tonic-gate static int alloced = 0; 557*0Sstevel@tonic-gate int circ, i; 558*0Sstevel@tonic-gate dev_info_t *xdip; 559*0Sstevel@tonic-gate 560*0Sstevel@tonic-gate /* hard coded isa stuff */ 561*0Sstevel@tonic-gate struct regspec asy_regs[] = { 562*0Sstevel@tonic-gate {1, 0x3f8, 0x8}, 563*0Sstevel@tonic-gate {1, 0x2f8, 0x8} 564*0Sstevel@tonic-gate }; 565*0Sstevel@tonic-gate int asy_intrs[] = {0x4, 0x3}; 566*0Sstevel@tonic-gate 567*0Sstevel@tonic-gate struct regspec lp_regs = {1, 0x378, 8}; 568*0Sstevel@tonic-gate int lp_intr = 7; 569*0Sstevel@tonic-gate 570*0Sstevel@tonic-gate struct regspec i8042_regs[] = { 571*0Sstevel@tonic-gate {1, 0x60, 0x1}, 572*0Sstevel@tonic-gate {1, 0x64, 0x1} 573*0Sstevel@tonic-gate }; 574*0Sstevel@tonic-gate int i8042_intrs[] = {0x1, 0xc}; 575*0Sstevel@tonic-gate char *acpi_prop; 576*0Sstevel@tonic-gate int acpi_enum = 1; /* ACPI is default to be on */ 577*0Sstevel@tonic-gate 578*0Sstevel@tonic-gate if (alloced) 579*0Sstevel@tonic-gate return; 580*0Sstevel@tonic-gate 581*0Sstevel@tonic-gate ndi_devi_enter(isa_dip, &circ); 582*0Sstevel@tonic-gate if (alloced) { /* just in case we are multi-threaded */ 583*0Sstevel@tonic-gate ndi_devi_exit(isa_dip, circ); 584*0Sstevel@tonic-gate return; 585*0Sstevel@tonic-gate } 586*0Sstevel@tonic-gate alloced = 1; 587*0Sstevel@tonic-gate 588*0Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 589*0Sstevel@tonic-gate DDI_PROP_DONTPASS, "acpi-enum", &acpi_prop) == DDI_PROP_SUCCESS) { 590*0Sstevel@tonic-gate acpi_enum = strcmp("off", acpi_prop); 591*0Sstevel@tonic-gate ddi_prop_free(acpi_prop); 592*0Sstevel@tonic-gate } 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate if (acpi_enum) { 595*0Sstevel@tonic-gate if (acpi_isa_device_enum(isa_dip)) { 596*0Sstevel@tonic-gate ndi_devi_exit(isa_dip, circ); 597*0Sstevel@tonic-gate if (isa_resource_setup() != NDI_SUCCESS) { 598*0Sstevel@tonic-gate cmn_err(CE_WARN, "isa nexus: isa " 599*0Sstevel@tonic-gate "resource setup failed"); 600*0Sstevel@tonic-gate } 601*0Sstevel@tonic-gate return; 602*0Sstevel@tonic-gate } 603*0Sstevel@tonic-gate cmn_err(CE_NOTE, "!Solaris did not detect ACPI BIOS"); 604*0Sstevel@tonic-gate } 605*0Sstevel@tonic-gate cmn_err(CE_NOTE, "!ACPI is off"); 606*0Sstevel@tonic-gate 607*0Sstevel@tonic-gate /* serial ports */ 608*0Sstevel@tonic-gate for (i = 0; i < 2; i++) { 609*0Sstevel@tonic-gate ndi_devi_alloc_sleep(isa_dip, "asy", 610*0Sstevel@tonic-gate (dnode_t)DEVI_SID_NODEID, &xdip); 611*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 612*0Sstevel@tonic-gate "reg", (int *)&asy_regs[i], 3); 613*0Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip, 614*0Sstevel@tonic-gate "interrupts", asy_intrs[i]); 615*0Sstevel@tonic-gate (void) ndi_devi_bind_driver(xdip, 0); 616*0Sstevel@tonic-gate } 617*0Sstevel@tonic-gate 618*0Sstevel@tonic-gate /* parallel port */ 619*0Sstevel@tonic-gate ndi_devi_alloc_sleep(isa_dip, "lp", 620*0Sstevel@tonic-gate (dnode_t)DEVI_SID_NODEID, &xdip); 621*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 622*0Sstevel@tonic-gate "reg", (int *)&lp_regs, 3); 623*0Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip, 624*0Sstevel@tonic-gate "interrupts", lp_intr); 625*0Sstevel@tonic-gate (void) ndi_devi_bind_driver(xdip, 0); 626*0Sstevel@tonic-gate 627*0Sstevel@tonic-gate /* i8042 node */ 628*0Sstevel@tonic-gate ndi_devi_alloc_sleep(isa_dip, "i8042", 629*0Sstevel@tonic-gate (dnode_t)DEVI_SID_NODEID, &xdip); 630*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 631*0Sstevel@tonic-gate "reg", (int *)i8042_regs, 6); 632*0Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 633*0Sstevel@tonic-gate "interrupts", (int *)i8042_intrs, 2); 634*0Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 635*0Sstevel@tonic-gate "unit-address", "1,60"); 636*0Sstevel@tonic-gate (void) ndi_devi_bind_driver(xdip, 0); 637*0Sstevel@tonic-gate 638*0Sstevel@tonic-gate add_known_used_resources(); 639*0Sstevel@tonic-gate 640*0Sstevel@tonic-gate ndi_devi_exit(isa_dip, circ); 641*0Sstevel@tonic-gate 642*0Sstevel@tonic-gate } 643