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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * 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 /* 300Sstevel@tonic-gate * ISA bus nexus driver 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <sys/cmn_err.h> 350Sstevel@tonic-gate #include <sys/conf.h> 360Sstevel@tonic-gate #include <sys/modctl.h> 370Sstevel@tonic-gate #include <sys/autoconf.h> 380Sstevel@tonic-gate #include <sys/errno.h> 390Sstevel@tonic-gate #include <sys/debug.h> 400Sstevel@tonic-gate #include <sys/kmem.h> 410Sstevel@tonic-gate #include <sys/ddidmareq.h> 420Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 430Sstevel@tonic-gate #include <sys/dma_engine.h> 440Sstevel@tonic-gate #include <sys/ddi.h> 450Sstevel@tonic-gate #include <sys/sunddi.h> 460Sstevel@tonic-gate #include <sys/sunndi.h> 470Sstevel@tonic-gate #include <sys/acpi/acpi_enum.h> 480Sstevel@tonic-gate 490Sstevel@tonic-gate extern int isa_resource_setup(void); 500Sstevel@tonic-gate static char USED_RESOURCES[] = "used-resources"; 510Sstevel@tonic-gate static void isa_alloc_nodes(dev_info_t *); 520Sstevel@tonic-gate /* 530Sstevel@tonic-gate * #define ISA_DEBUG 1 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 570Sstevel@tonic-gate * Local data 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate static ddi_dma_lim_t ISA_dma_limits = { 600Sstevel@tonic-gate 0, /* address low */ 610Sstevel@tonic-gate 0x00ffffff, /* address high */ 620Sstevel@tonic-gate 0, /* counter max */ 630Sstevel@tonic-gate 1, /* burstsize */ 640Sstevel@tonic-gate DMA_UNIT_8, /* minimum xfer */ 650Sstevel@tonic-gate 0, /* dma speed */ 660Sstevel@tonic-gate (uint_t)DMALIM_VER0, /* version */ 670Sstevel@tonic-gate 0x0000ffff, /* address register */ 680Sstevel@tonic-gate 0x0000ffff, /* counter register */ 690Sstevel@tonic-gate 1, /* sector size */ 700Sstevel@tonic-gate 0x00000001, /* scatter/gather list length */ 710Sstevel@tonic-gate (uint_t)0xffffffff /* request size */ 720Sstevel@tonic-gate }; 730Sstevel@tonic-gate 740Sstevel@tonic-gate static ddi_dma_attr_t ISA_dma_attr = { 750Sstevel@tonic-gate DMA_ATTR_V0, 760Sstevel@tonic-gate (unsigned long long)0, 770Sstevel@tonic-gate (unsigned long long)0x00ffffff, 780Sstevel@tonic-gate 0x0000ffff, 790Sstevel@tonic-gate 1, 800Sstevel@tonic-gate 1, 810Sstevel@tonic-gate 1, 820Sstevel@tonic-gate (unsigned long long)0xffffffff, 830Sstevel@tonic-gate (unsigned long long)0x0000ffff, 840Sstevel@tonic-gate 1, 850Sstevel@tonic-gate 1, 860Sstevel@tonic-gate 0 870Sstevel@tonic-gate }; 880Sstevel@tonic-gate 890Sstevel@tonic-gate 900Sstevel@tonic-gate /* 910Sstevel@tonic-gate * Config information 920Sstevel@tonic-gate */ 930Sstevel@tonic-gate 940Sstevel@tonic-gate static int 950Sstevel@tonic-gate isa_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, 960Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *); 970Sstevel@tonic-gate 980Sstevel@tonic-gate static int 990Sstevel@tonic-gate isa_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t, enum ddi_dma_ctlops, 1000Sstevel@tonic-gate off_t *, size_t *, caddr_t *, uint_t); 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate static int 1030Sstevel@tonic-gate isa_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate struct bus_ops isa_bus_ops = { 1060Sstevel@tonic-gate BUSO_REV, 1070Sstevel@tonic-gate i_ddi_bus_map, 1080Sstevel@tonic-gate NULL, 1090Sstevel@tonic-gate NULL, 1100Sstevel@tonic-gate NULL, 1110Sstevel@tonic-gate i_ddi_map_fault, 1120Sstevel@tonic-gate ddi_dma_map, 1130Sstevel@tonic-gate isa_dma_allochdl, 1140Sstevel@tonic-gate ddi_dma_freehdl, 1150Sstevel@tonic-gate ddi_dma_bindhdl, 1160Sstevel@tonic-gate ddi_dma_unbindhdl, 1170Sstevel@tonic-gate ddi_dma_flush, 1180Sstevel@tonic-gate ddi_dma_win, 1190Sstevel@tonic-gate isa_dma_mctl, 1200Sstevel@tonic-gate isa_ctlops, 1210Sstevel@tonic-gate ddi_bus_prop_op, 1220Sstevel@tonic-gate NULL, /* (*bus_get_eventcookie)(); */ 1230Sstevel@tonic-gate NULL, /* (*bus_add_eventcall)(); */ 1240Sstevel@tonic-gate NULL, /* (*bus_remove_eventcall)(); */ 1250Sstevel@tonic-gate NULL, /* (*bus_post_event)(); */ 1260Sstevel@tonic-gate NULL, /* (*bus_intr_ctl)(); */ 1270Sstevel@tonic-gate NULL, /* (*bus_config)(); */ 1280Sstevel@tonic-gate NULL, /* (*bus_unconfig)(); */ 1290Sstevel@tonic-gate NULL, /* (*bus_fm_init)(); */ 1300Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 1310Sstevel@tonic-gate NULL, /* (*bus_fm_access_enter)(); */ 1320Sstevel@tonic-gate NULL, /* (*bus_fm_access_exit)(); */ 1330Sstevel@tonic-gate NULL, /* (*bus_power)(); */ 1340Sstevel@tonic-gate i_ddi_intr_ops /* (*bus_intr_op)(); */ 1350Sstevel@tonic-gate }; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate static int isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * Internal isa ctlops support routines 1420Sstevel@tonic-gate */ 1430Sstevel@tonic-gate static int isa_initchild(dev_info_t *child); 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate struct dev_ops isa_ops = { 1460Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 1470Sstevel@tonic-gate 0, /* refcnt */ 1480Sstevel@tonic-gate ddi_no_info, /* info */ 1490Sstevel@tonic-gate nulldev, /* identify */ 1500Sstevel@tonic-gate nulldev, /* probe */ 1510Sstevel@tonic-gate isa_attach, /* attach */ 1520Sstevel@tonic-gate nodev, /* detach */ 1530Sstevel@tonic-gate nodev, /* reset */ 1540Sstevel@tonic-gate (struct cb_ops *)0, /* driver operations */ 1550Sstevel@tonic-gate &isa_bus_ops /* bus operations */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate }; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate /* 1600Sstevel@tonic-gate * Module linkage information for the kernel. 1610Sstevel@tonic-gate */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate static struct modldrv modldrv = { 1640Sstevel@tonic-gate &mod_driverops, /* Type of module. This is ISA bus driver */ 1650Sstevel@tonic-gate "isa nexus driver for 'ISA' %I%", 1660Sstevel@tonic-gate &isa_ops, /* driver ops */ 1670Sstevel@tonic-gate }; 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate static struct modlinkage modlinkage = { 1700Sstevel@tonic-gate MODREV_1, 1710Sstevel@tonic-gate &modldrv, 1720Sstevel@tonic-gate NULL 1730Sstevel@tonic-gate }; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate int 1760Sstevel@tonic-gate _init(void) 1770Sstevel@tonic-gate { 1780Sstevel@tonic-gate return (mod_install(&modlinkage)); 1790Sstevel@tonic-gate } 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate int 1820Sstevel@tonic-gate _fini(void) 1830Sstevel@tonic-gate { 1840Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate int 1880Sstevel@tonic-gate _info(struct modinfo *modinfop) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate static int 1940Sstevel@tonic-gate isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 1950Sstevel@tonic-gate { 1960Sstevel@tonic-gate int rval; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate if (cmd != DDI_ATTACH) 1990Sstevel@tonic-gate return (DDI_FAILURE); 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate if ((rval = i_dmae_init(devi)) == DDI_SUCCESS) { 2020Sstevel@tonic-gate ddi_report_dev(devi); 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * Enumerate children -- invoking ACPICA 2050Sstevel@tonic-gate * This is normally in bus_config(), but we need this 2060Sstevel@tonic-gate * to happen earlier to boot. 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate isa_alloc_nodes(devi); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate return (rval); 2110Sstevel@tonic-gate } 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate static int 2140Sstevel@tonic-gate isa_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *dma_attr, 2150Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 2160Sstevel@tonic-gate { 2170Sstevel@tonic-gate ddi_dma_attr_merge(dma_attr, &ISA_dma_attr); 2180Sstevel@tonic-gate return (ddi_dma_allochdl(dip, rdip, dma_attr, waitfp, arg, handlep)); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate static int 2220Sstevel@tonic-gate isa_dma_mctl(dev_info_t *dip, dev_info_t *rdip, 2230Sstevel@tonic-gate ddi_dma_handle_t handle, enum ddi_dma_ctlops request, 2240Sstevel@tonic-gate off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags) 2250Sstevel@tonic-gate { 2260Sstevel@tonic-gate int rval; 2270Sstevel@tonic-gate ddi_dma_lim_t defalt; 2280Sstevel@tonic-gate int arg = (int)(uintptr_t)objp; 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate switch (request) { 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate case DDI_DMA_E_PROG: 2330Sstevel@tonic-gate return (i_dmae_prog(rdip, (struct ddi_dmae_req *)offp, 2340Sstevel@tonic-gate (ddi_dma_cookie_t *)lenp, arg)); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate case DDI_DMA_E_ACQUIRE: 2370Sstevel@tonic-gate return (i_dmae_acquire(rdip, arg, (int(*)(caddr_t))offp, 2380Sstevel@tonic-gate (caddr_t)lenp)); 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate case DDI_DMA_E_FREE: 2410Sstevel@tonic-gate return (i_dmae_free(rdip, arg)); 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate case DDI_DMA_E_STOP: 2440Sstevel@tonic-gate i_dmae_stop(rdip, arg); 2450Sstevel@tonic-gate return (DDI_SUCCESS); 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate case DDI_DMA_E_ENABLE: 2480Sstevel@tonic-gate i_dmae_enable(rdip, arg); 2490Sstevel@tonic-gate return (DDI_SUCCESS); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate case DDI_DMA_E_DISABLE: 2520Sstevel@tonic-gate i_dmae_disable(rdip, arg); 2530Sstevel@tonic-gate return (DDI_SUCCESS); 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate case DDI_DMA_E_GETCNT: 2560Sstevel@tonic-gate i_dmae_get_chan_stat(rdip, arg, NULL, (int *)lenp); 2570Sstevel@tonic-gate return (DDI_SUCCESS); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate case DDI_DMA_E_SWSETUP: 2600Sstevel@tonic-gate return (i_dmae_swsetup(rdip, (struct ddi_dmae_req *)offp, 2610Sstevel@tonic-gate (ddi_dma_cookie_t *)lenp, arg)); 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate case DDI_DMA_E_SWSTART: 2640Sstevel@tonic-gate i_dmae_swstart(rdip, arg); 2650Sstevel@tonic-gate return (DDI_SUCCESS); 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate case DDI_DMA_E_GETLIM: 2680Sstevel@tonic-gate bcopy(&ISA_dma_limits, objp, sizeof (ddi_dma_lim_t)); 2690Sstevel@tonic-gate return (DDI_SUCCESS); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate case DDI_DMA_E_GETATTR: 2720Sstevel@tonic-gate bcopy(&ISA_dma_attr, objp, sizeof (ddi_dma_attr_t)); 2730Sstevel@tonic-gate return (DDI_SUCCESS); 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate case DDI_DMA_E_1STPTY: 2760Sstevel@tonic-gate { 2770Sstevel@tonic-gate struct ddi_dmae_req req1stpty = 2780Sstevel@tonic-gate { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 2790Sstevel@tonic-gate if (arg == 0) { 2800Sstevel@tonic-gate req1stpty.der_command = DMAE_CMD_TRAN; 2810Sstevel@tonic-gate req1stpty.der_trans = DMAE_TRANS_DMND; 2820Sstevel@tonic-gate } else { 2830Sstevel@tonic-gate req1stpty.der_trans = DMAE_TRANS_CSCD; 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate return (i_dmae_prog(rdip, &req1stpty, NULL, arg)); 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate case DDI_DMA_IOPB_ALLOC: /* get contiguous DMA-able memory */ 2890Sstevel@tonic-gate case DDI_DMA_SMEM_ALLOC: 2900Sstevel@tonic-gate if (!offp) { 2910Sstevel@tonic-gate defalt = ISA_dma_limits; 2920Sstevel@tonic-gate offp = (off_t *)&defalt; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate /*FALLTHROUGH*/ 2950Sstevel@tonic-gate default: 2960Sstevel@tonic-gate rval = ddi_dma_mctl(dip, rdip, handle, request, offp, 2970Sstevel@tonic-gate lenp, objp, flags); 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate return (rval); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* 3030Sstevel@tonic-gate * Check if driver should be treated as an old pre 2.6 driver 3040Sstevel@tonic-gate */ 3050Sstevel@tonic-gate static int 3060Sstevel@tonic-gate old_driver(dev_info_t *dip) 3070Sstevel@tonic-gate { 3080Sstevel@tonic-gate extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */ 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate if (ndi_dev_is_persistent_node(dip)) { 3110Sstevel@tonic-gate if (ignore_hardware_nodes) 3120Sstevel@tonic-gate return (1); 3130Sstevel@tonic-gate if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 3140Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1) 3150Sstevel@tonic-gate return (1); 3160Sstevel@tonic-gate } 3170Sstevel@tonic-gate return (0); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate typedef struct { 3210Sstevel@tonic-gate uint32_t phys_hi; 3220Sstevel@tonic-gate uint32_t phys_lo; 3230Sstevel@tonic-gate uint32_t size; 3240Sstevel@tonic-gate } isa_regs_t; 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate /* 3270Sstevel@tonic-gate * Return non-zero if device in tree is a PnP isa device 3280Sstevel@tonic-gate */ 3290Sstevel@tonic-gate static int 3300Sstevel@tonic-gate is_pnpisa(dev_info_t *dip) 3310Sstevel@tonic-gate { 3320Sstevel@tonic-gate isa_regs_t *isa_regs; 3330Sstevel@tonic-gate int proplen, pnpisa; 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate if (ndi_dev_is_persistent_node(dip) == 0) 3360Sstevel@tonic-gate return (0); 3370Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg", 3380Sstevel@tonic-gate (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) { 3390Sstevel@tonic-gate return (0); 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate pnpisa = isa_regs[0].phys_hi & 0x80000000; 3420Sstevel@tonic-gate /* 3430Sstevel@tonic-gate * free the memory allocated by ddi_getlongprop(). 3440Sstevel@tonic-gate */ 3450Sstevel@tonic-gate kmem_free(isa_regs, proplen); 3460Sstevel@tonic-gate if (pnpisa) 3470Sstevel@tonic-gate return (1); 3480Sstevel@tonic-gate else 3490Sstevel@tonic-gate return (0); 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate /*ARGSUSED*/ 3530Sstevel@tonic-gate static int 3540Sstevel@tonic-gate isa_ctlops(dev_info_t *dip, dev_info_t *rdip, 3550Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 3560Sstevel@tonic-gate { 3570Sstevel@tonic-gate switch (ctlop) { 3580Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 3590Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 3600Sstevel@tonic-gate return (DDI_FAILURE); 3610Sstevel@tonic-gate cmn_err(CE_CONT, "?ISA-device: %s%d\n", 3620Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 3630Sstevel@tonic-gate return (DDI_SUCCESS); 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 3660Sstevel@tonic-gate /* 3670Sstevel@tonic-gate * older drivers aren't expecting the "standard" device 3680Sstevel@tonic-gate * node format used by the hardware nodes. these drivers 3690Sstevel@tonic-gate * only expect their own properties set in their driver.conf 3700Sstevel@tonic-gate * files. so they tell us not to call them with hardware 3710Sstevel@tonic-gate * nodes by setting the property "ignore-hardware-nodes". 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate if (old_driver((dev_info_t *)arg)) { 3740Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate return (isa_initchild((dev_info_t *)arg)); 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 3800Sstevel@tonic-gate impl_ddi_sunbus_removechild((dev_info_t *)arg); 3810Sstevel@tonic-gate return (DDI_SUCCESS); 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 3840Sstevel@tonic-gate /* 3850Sstevel@tonic-gate * All ISA devices need to do confirming probes 3860Sstevel@tonic-gate * unless they are PnP ISA. 3870Sstevel@tonic-gate */ 3880Sstevel@tonic-gate if (is_pnpisa(dip)) 3890Sstevel@tonic-gate return (DDI_SUCCESS); 3900Sstevel@tonic-gate else 3910Sstevel@tonic-gate return (DDI_FAILURE); 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate default: 3940Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 3950Sstevel@tonic-gate } 3960Sstevel@tonic-gate } 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate static void 3990Sstevel@tonic-gate isa_vendor(uint32_t id, char *vendor) 4000Sstevel@tonic-gate { 4010Sstevel@tonic-gate vendor[0] = '@' + ((id >> 26) & 0x1f); 4020Sstevel@tonic-gate vendor[1] = '@' + ((id >> 21) & 0x1f); 4030Sstevel@tonic-gate vendor[2] = '@' + ((id >> 16) & 0x1f); 4040Sstevel@tonic-gate vendor[3] = 0; 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Name a child 4090Sstevel@tonic-gate */ 4100Sstevel@tonic-gate static int 4110Sstevel@tonic-gate isa_name_child(dev_info_t *child, char *name, int namelen) 4120Sstevel@tonic-gate { 4130Sstevel@tonic-gate char vendor[8]; 4140Sstevel@tonic-gate int device; 4150Sstevel@tonic-gate uint32_t serial; 4160Sstevel@tonic-gate int func; 4170Sstevel@tonic-gate int bustype; 4180Sstevel@tonic-gate uint32_t base; 4190Sstevel@tonic-gate int proplen; 4200Sstevel@tonic-gate int pnpisa = 0; 4210Sstevel@tonic-gate isa_regs_t *isa_regs; 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate void make_ddi_ppd(dev_info_t *, struct ddi_parent_private_data **); 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate /* 4260Sstevel@tonic-gate * older drivers aren't expecting the "standard" device 4270Sstevel@tonic-gate * node format used by the hardware nodes. these drivers 4280Sstevel@tonic-gate * only expect their own properties set in their driver.conf 4290Sstevel@tonic-gate * files. so they tell us not to call them with hardware 4300Sstevel@tonic-gate * nodes by setting the property "ignore-hardware-nodes". 4310Sstevel@tonic-gate */ 4320Sstevel@tonic-gate if (old_driver(child)) 4330Sstevel@tonic-gate return (DDI_FAILURE); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate /* 4360Sstevel@tonic-gate * Fill in parent-private data 4370Sstevel@tonic-gate */ 4380Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 4390Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 4400Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 4410Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 4450Sstevel@tonic-gate /* 4460Sstevel@tonic-gate * For .conf nodes, generate name from parent private data 4470Sstevel@tonic-gate */ 4480Sstevel@tonic-gate name[0] = '\0'; 4490Sstevel@tonic-gate if (sparc_pd_getnreg(child) > 0) { 4500Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 4510Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 4520Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate return (DDI_SUCCESS); 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate /* 4580Sstevel@tonic-gate * For hw nodes, look up "reg" property 4590Sstevel@tonic-gate */ 4600Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg", 4610Sstevel@tonic-gate (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) { 4620Sstevel@tonic-gate return (DDI_FAILURE); 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* 4660Sstevel@tonic-gate * extract the device identifications 4670Sstevel@tonic-gate */ 4680Sstevel@tonic-gate pnpisa = isa_regs[0].phys_hi & 0x80000000; 4690Sstevel@tonic-gate if (pnpisa) { 4700Sstevel@tonic-gate isa_vendor(isa_regs[0].phys_hi, vendor); 4710Sstevel@tonic-gate device = isa_regs[0].phys_hi & 0xffff; 4720Sstevel@tonic-gate serial = isa_regs[0].phys_lo; 4730Sstevel@tonic-gate func = (isa_regs[0].size >> 24) & 0xff; 4740Sstevel@tonic-gate if (func != 0) 4750Sstevel@tonic-gate (void) snprintf(name, namelen, "pnp%s,%04x,%x,%x", 4760Sstevel@tonic-gate vendor, device, serial, func); 4770Sstevel@tonic-gate else 4780Sstevel@tonic-gate (void) snprintf(name, namelen, "pnp%s,%04x,%x", 4790Sstevel@tonic-gate vendor, device, serial); 4800Sstevel@tonic-gate } else { 4810Sstevel@tonic-gate bustype = isa_regs[0].phys_hi; 4820Sstevel@tonic-gate base = isa_regs[0].phys_lo; 4830Sstevel@tonic-gate (void) sprintf(name, "%x,%x", bustype, base); 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate /* 4870Sstevel@tonic-gate * free the memory allocated by ddi_getlongprop(). 4880Sstevel@tonic-gate */ 4890Sstevel@tonic-gate kmem_free(isa_regs, proplen); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate return (DDI_SUCCESS); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate static int 4950Sstevel@tonic-gate isa_initchild(dev_info_t *child) 4960Sstevel@tonic-gate { 4970Sstevel@tonic-gate char name[80]; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate if (isa_name_child(child, name, 80) != DDI_SUCCESS) 5000Sstevel@tonic-gate return (DDI_FAILURE); 5010Sstevel@tonic-gate ddi_set_name_addr(child, name); 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) != 0) 5040Sstevel@tonic-gate return (DDI_SUCCESS); 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate /* 5070Sstevel@tonic-gate * This is a .conf node, try merge properties onto a 5080Sstevel@tonic-gate * hw node with the same name. 5090Sstevel@tonic-gate */ 5100Sstevel@tonic-gate if (ndi_merge_node(child, isa_name_child) == DDI_SUCCESS) { 5110Sstevel@tonic-gate /* 5120Sstevel@tonic-gate * Return failure to remove node 5130Sstevel@tonic-gate */ 5140Sstevel@tonic-gate impl_ddi_sunbus_removechild(child); 5150Sstevel@tonic-gate return (DDI_FAILURE); 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate /* 5180Sstevel@tonic-gate * Cannot merge node, permit pseudo children 5190Sstevel@tonic-gate */ 5200Sstevel@tonic-gate return (DDI_SUCCESS); 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate /* 5240Sstevel@tonic-gate * called when ACPI enumeration is not used 5250Sstevel@tonic-gate */ 5260Sstevel@tonic-gate static void 5270Sstevel@tonic-gate add_known_used_resources(void) 5280Sstevel@tonic-gate { 5290Sstevel@tonic-gate /* needs to be in increasing order */ 5300Sstevel@tonic-gate int intr[] = {0x1, 0x3, 0x4, 0x6, 0x7, 0xc}; 5310Sstevel@tonic-gate int dma[] = {0x2}; 5320Sstevel@tonic-gate int io[] = {0x60, 0x1, 0x64, 0x1, 0x2f8, 0x8, 0x378, 0x8, 0x3f0, 0x10, 5330Sstevel@tonic-gate 0x778, 0x4}; 5340Sstevel@tonic-gate dev_info_t *usedrdip; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate usedrdip = ddi_find_devinfo(USED_RESOURCES, -1, 0); 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate if (usedrdip == NULL) { 5390Sstevel@tonic-gate (void) ndi_devi_alloc_sleep(ddi_root_node(), USED_RESOURCES, 540*789Sahrens (pnode_t)DEVI_SID_NODEID, &usedrdip); 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 5440Sstevel@tonic-gate "interrupts", (int *)intr, (int)(sizeof (intr) / sizeof (int))); 5450Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 5460Sstevel@tonic-gate "io-space", (int *)io, (int)(sizeof (io) / sizeof (int))); 5470Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 5480Sstevel@tonic-gate "dma-channels", (int *)dma, (int)(sizeof (dma) / sizeof (int))); 5490Sstevel@tonic-gate (void) ndi_devi_bind_driver(usedrdip, 0); 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate static void 5540Sstevel@tonic-gate isa_alloc_nodes(dev_info_t *isa_dip) 5550Sstevel@tonic-gate { 5560Sstevel@tonic-gate static int alloced = 0; 5570Sstevel@tonic-gate int circ, i; 5580Sstevel@tonic-gate dev_info_t *xdip; 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate /* hard coded isa stuff */ 5610Sstevel@tonic-gate struct regspec asy_regs[] = { 5620Sstevel@tonic-gate {1, 0x3f8, 0x8}, 5630Sstevel@tonic-gate {1, 0x2f8, 0x8} 5640Sstevel@tonic-gate }; 5650Sstevel@tonic-gate int asy_intrs[] = {0x4, 0x3}; 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate struct regspec lp_regs = {1, 0x378, 8}; 5680Sstevel@tonic-gate int lp_intr = 7; 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate struct regspec i8042_regs[] = { 5710Sstevel@tonic-gate {1, 0x60, 0x1}, 5720Sstevel@tonic-gate {1, 0x64, 0x1} 5730Sstevel@tonic-gate }; 5740Sstevel@tonic-gate int i8042_intrs[] = {0x1, 0xc}; 5750Sstevel@tonic-gate char *acpi_prop; 5760Sstevel@tonic-gate int acpi_enum = 1; /* ACPI is default to be on */ 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate if (alloced) 5790Sstevel@tonic-gate return; 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate ndi_devi_enter(isa_dip, &circ); 5820Sstevel@tonic-gate if (alloced) { /* just in case we are multi-threaded */ 5830Sstevel@tonic-gate ndi_devi_exit(isa_dip, circ); 5840Sstevel@tonic-gate return; 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate alloced = 1; 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 5890Sstevel@tonic-gate DDI_PROP_DONTPASS, "acpi-enum", &acpi_prop) == DDI_PROP_SUCCESS) { 5900Sstevel@tonic-gate acpi_enum = strcmp("off", acpi_prop); 5910Sstevel@tonic-gate ddi_prop_free(acpi_prop); 5920Sstevel@tonic-gate } 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate if (acpi_enum) { 5950Sstevel@tonic-gate if (acpi_isa_device_enum(isa_dip)) { 5960Sstevel@tonic-gate ndi_devi_exit(isa_dip, circ); 5970Sstevel@tonic-gate if (isa_resource_setup() != NDI_SUCCESS) { 5980Sstevel@tonic-gate cmn_err(CE_WARN, "isa nexus: isa " 5990Sstevel@tonic-gate "resource setup failed"); 6000Sstevel@tonic-gate } 6010Sstevel@tonic-gate return; 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate cmn_err(CE_NOTE, "!Solaris did not detect ACPI BIOS"); 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate cmn_err(CE_NOTE, "!ACPI is off"); 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate /* serial ports */ 6080Sstevel@tonic-gate for (i = 0; i < 2; i++) { 6090Sstevel@tonic-gate ndi_devi_alloc_sleep(isa_dip, "asy", 610*789Sahrens (pnode_t)DEVI_SID_NODEID, &xdip); 6110Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 6120Sstevel@tonic-gate "reg", (int *)&asy_regs[i], 3); 6130Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip, 6140Sstevel@tonic-gate "interrupts", asy_intrs[i]); 6150Sstevel@tonic-gate (void) ndi_devi_bind_driver(xdip, 0); 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate /* parallel port */ 6190Sstevel@tonic-gate ndi_devi_alloc_sleep(isa_dip, "lp", 620*789Sahrens (pnode_t)DEVI_SID_NODEID, &xdip); 6210Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 6220Sstevel@tonic-gate "reg", (int *)&lp_regs, 3); 6230Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip, 6240Sstevel@tonic-gate "interrupts", lp_intr); 6250Sstevel@tonic-gate (void) ndi_devi_bind_driver(xdip, 0); 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate /* i8042 node */ 6280Sstevel@tonic-gate ndi_devi_alloc_sleep(isa_dip, "i8042", 629*789Sahrens (pnode_t)DEVI_SID_NODEID, &xdip); 6300Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 6310Sstevel@tonic-gate "reg", (int *)i8042_regs, 6); 6320Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 6330Sstevel@tonic-gate "interrupts", (int *)i8042_intrs, 2); 6340Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 6350Sstevel@tonic-gate "unit-address", "1,60"); 6360Sstevel@tonic-gate (void) ndi_devi_bind_driver(xdip, 0); 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate add_known_used_resources(); 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate ndi_devi_exit(isa_dip, circ); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate } 643