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 5580Swesolows * Common Development and Distribution License (the "License"). 6580Swesolows * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21580Swesolows 220Sstevel@tonic-gate /* 23*2548Saa72041 * Copyright 2006 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 * sun4 root nexus driver 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/conf.h> 340Sstevel@tonic-gate #include <sys/modctl.h> 350Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 360Sstevel@tonic-gate #include <sys/sunndi.h> 370Sstevel@tonic-gate #include <sys/vmsystm.h> 380Sstevel@tonic-gate #include <sys/async.h> 390Sstevel@tonic-gate #include <sys/intr.h> 400Sstevel@tonic-gate #include <sys/ndifm.h> 410Sstevel@tonic-gate #include <vm/seg_dev.h> 420Sstevel@tonic-gate #include <vm/seg_kmem.h> 430Sstevel@tonic-gate #include <sys/ontrap.h> 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* Useful debugging Stuff */ 460Sstevel@tonic-gate #include <sys/nexusdebug.h> 470Sstevel@tonic-gate #define ROOTNEX_MAP_DEBUG 0x1 480Sstevel@tonic-gate #define ROOTNEX_INTR_DEBUG 0x2 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * config information 520Sstevel@tonic-gate */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate static int 550Sstevel@tonic-gate rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 560Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp); 570Sstevel@tonic-gate 580Sstevel@tonic-gate static int 590Sstevel@tonic-gate rootnex_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t, 600Sstevel@tonic-gate ddi_intr_handle_impl_t *, void *); 610Sstevel@tonic-gate 620Sstevel@tonic-gate static int 630Sstevel@tonic-gate rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip, 640Sstevel@tonic-gate struct hat *hat, struct seg *seg, caddr_t addr, 650Sstevel@tonic-gate struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock); 660Sstevel@tonic-gate 670Sstevel@tonic-gate static int 680Sstevel@tonic-gate rootnex_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 690Sstevel@tonic-gate 700Sstevel@tonic-gate static int 710Sstevel@tonic-gate rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int tcap, 720Sstevel@tonic-gate ddi_iblock_cookie_t *ibc); 730Sstevel@tonic-gate 740Sstevel@tonic-gate static void 750Sstevel@tonic-gate rootnex_fm_init(dev_info_t *); 760Sstevel@tonic-gate 770Sstevel@tonic-gate static int 780Sstevel@tonic-gate rootnex_ctlops_peekpoke(ddi_ctl_enum_t, peekpoke_ctlops_t *, void *result); 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * Defined in $KARCH/io/mach_rootnex.c 820Sstevel@tonic-gate */ 830Sstevel@tonic-gate int rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 840Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 850Sstevel@tonic-gate #pragma weak rootnex_add_intr_impl 860Sstevel@tonic-gate 870Sstevel@tonic-gate int rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 880Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 890Sstevel@tonic-gate #pragma weak rootnex_remove_intr_impl 900Sstevel@tonic-gate 91693Sgovinda int rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip, 920Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 930Sstevel@tonic-gate #pragma weak rootnex_get_intr_pri 940Sstevel@tonic-gate 950Sstevel@tonic-gate int rootnex_name_child_impl(dev_info_t *child, char *name, int namelen); 960Sstevel@tonic-gate #pragma weak rootnex_name_child_impl 970Sstevel@tonic-gate 980Sstevel@tonic-gate int rootnex_ctl_initchild_impl(dev_info_t *dip); 990Sstevel@tonic-gate #pragma weak rootnex_initchild_impl 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate void rootnex_ctl_uninitchild_impl(dev_info_t *dip); 1020Sstevel@tonic-gate #pragma weak rootnex_uninitchild_impl 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate int rootnex_ctl_reportdev_impl(dev_info_t *dev); 1050Sstevel@tonic-gate #pragma weak rootnex_reportdev_impl 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate static struct cb_ops rootnex_cb_ops = { 1080Sstevel@tonic-gate nodev, /* open */ 1090Sstevel@tonic-gate nodev, /* close */ 1100Sstevel@tonic-gate nodev, /* strategy */ 1110Sstevel@tonic-gate nodev, /* print */ 1120Sstevel@tonic-gate nodev, /* dump */ 1130Sstevel@tonic-gate nodev, /* read */ 1140Sstevel@tonic-gate nodev, /* write */ 1150Sstevel@tonic-gate nodev, /* ioctl */ 1160Sstevel@tonic-gate nodev, /* devmap */ 1170Sstevel@tonic-gate nodev, /* mmap */ 1180Sstevel@tonic-gate nodev, /* segmap */ 1190Sstevel@tonic-gate nochpoll, /* chpoll */ 1200Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 1210Sstevel@tonic-gate NULL, /* struct streamtab */ 1220Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* compatibility flags */ 1230Sstevel@tonic-gate CB_REV, /* Rev */ 1240Sstevel@tonic-gate nodev, /* cb_aread */ 1250Sstevel@tonic-gate nodev /* cb_awrite */ 1260Sstevel@tonic-gate }; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate static struct bus_ops rootnex_bus_ops = { 1290Sstevel@tonic-gate BUSO_REV, 1300Sstevel@tonic-gate rootnex_map, 1310Sstevel@tonic-gate NULL, 1320Sstevel@tonic-gate NULL, 1330Sstevel@tonic-gate NULL, 1340Sstevel@tonic-gate rootnex_map_fault, 1350Sstevel@tonic-gate ddi_no_dma_map, /* no rootnex_dma_map- now in sysio nexus */ 1360Sstevel@tonic-gate ddi_no_dma_allochdl, 1370Sstevel@tonic-gate ddi_no_dma_freehdl, 1380Sstevel@tonic-gate ddi_no_dma_bindhdl, 1390Sstevel@tonic-gate ddi_no_dma_unbindhdl, 1400Sstevel@tonic-gate ddi_no_dma_flush, 1410Sstevel@tonic-gate ddi_no_dma_win, 1420Sstevel@tonic-gate ddi_no_dma_mctl, /* no rootnex_dma_mctl- now in sysio nexus */ 1430Sstevel@tonic-gate rootnex_ctlops, 1440Sstevel@tonic-gate ddi_bus_prop_op, 1450Sstevel@tonic-gate i_ddi_rootnex_get_eventcookie, 1460Sstevel@tonic-gate i_ddi_rootnex_add_eventcall, 1470Sstevel@tonic-gate i_ddi_rootnex_remove_eventcall, 1480Sstevel@tonic-gate i_ddi_rootnex_post_event, 1490Sstevel@tonic-gate NULL, /* bus_intr_ctl */ 1500Sstevel@tonic-gate NULL, /* bus_config */ 1510Sstevel@tonic-gate NULL, /* bus_unconfig */ 1520Sstevel@tonic-gate rootnex_busop_fminit, /* bus_fm_init */ 1530Sstevel@tonic-gate NULL, /* bus_fm_fini */ 1540Sstevel@tonic-gate NULL, /* bus_fm_access_enter */ 1550Sstevel@tonic-gate NULL, /* bus_fm_access_fini */ 1560Sstevel@tonic-gate NULL, /* bus_power */ 1570Sstevel@tonic-gate rootnex_intr_ops /* bus_intr_op */ 1580Sstevel@tonic-gate }; 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate static int rootnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 1610Sstevel@tonic-gate static int rootnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate static struct dev_ops rootnex_ops = { 1640Sstevel@tonic-gate DEVO_REV, 1650Sstevel@tonic-gate 0, /* refcnt */ 1660Sstevel@tonic-gate ddi_no_info, /* info */ 1670Sstevel@tonic-gate nulldev, 1680Sstevel@tonic-gate nulldev, /* probe */ 1690Sstevel@tonic-gate rootnex_attach, 1700Sstevel@tonic-gate rootnex_detach, 1710Sstevel@tonic-gate nodev, /* reset */ 1720Sstevel@tonic-gate &rootnex_cb_ops, 1730Sstevel@tonic-gate &rootnex_bus_ops 1740Sstevel@tonic-gate }; 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate extern uint_t root_phys_addr_lo_mask; 1780Sstevel@tonic-gate extern uint_t root_phys_addr_hi_mask; 1790Sstevel@tonic-gate extern struct mod_ops mod_driverops; 1800Sstevel@tonic-gate extern struct dev_ops rootnex_ops; 1810Sstevel@tonic-gate extern struct cpu cpu0; 1820Sstevel@tonic-gate extern ddi_iblock_cookie_t rootnex_err_ibc; 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * Add statically defined root properties to this list... 1870Sstevel@tonic-gate */ 1880Sstevel@tonic-gate static const int pagesize = PAGESIZE; 1890Sstevel@tonic-gate static const int mmu_pagesize = MMU_PAGESIZE; 1900Sstevel@tonic-gate static const int mmu_pageoffset = MMU_PAGEOFFSET; 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate struct prop_def { 1930Sstevel@tonic-gate char *prop_name; 1940Sstevel@tonic-gate caddr_t prop_value; 1950Sstevel@tonic-gate }; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate static struct prop_def root_props[] = { 1980Sstevel@tonic-gate { "PAGESIZE", (caddr_t)&pagesize }, 1990Sstevel@tonic-gate { "MMU_PAGESIZE", (caddr_t)&mmu_pagesize}, 2000Sstevel@tonic-gate { "MMU_PAGEOFFSET", (caddr_t)&mmu_pageoffset}, 2010Sstevel@tonic-gate }; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate static vmem_t *rootnex_regspec_arena; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #define NROOT_PROPS (sizeof (root_props) / sizeof (struct prop_def)) 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * Module linkage information for the kernel. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate static struct modldrv modldrv = { 2140Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a nexus driver */ 2150Sstevel@tonic-gate "sun4 root nexus %I%", 2160Sstevel@tonic-gate &rootnex_ops, /* Driver ops */ 2170Sstevel@tonic-gate }; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate static struct modlinkage modlinkage = { 2200Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 2210Sstevel@tonic-gate }; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate int 2240Sstevel@tonic-gate _init(void) 2250Sstevel@tonic-gate { 2260Sstevel@tonic-gate return (mod_install(&modlinkage)); 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate int 2300Sstevel@tonic-gate _fini(void) 2310Sstevel@tonic-gate { 2320Sstevel@tonic-gate return (EBUSY); 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate int 2360Sstevel@tonic-gate _info(struct modinfo *modinfop) 2370Sstevel@tonic-gate { 2380Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * rootnex_attach: 2430Sstevel@tonic-gate * 2440Sstevel@tonic-gate * attach the root nexus. 2450Sstevel@tonic-gate */ 2460Sstevel@tonic-gate static void add_root_props(dev_info_t *); 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /*ARGSUSED*/ 2490Sstevel@tonic-gate static int 2500Sstevel@tonic-gate rootnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 2510Sstevel@tonic-gate { 2520Sstevel@tonic-gate int length; 2530Sstevel@tonic-gate char *valuep = NULL; 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate /* 2560Sstevel@tonic-gate * Only do these functions when the driver is acting as the 2570Sstevel@tonic-gate * root nexus, not when it is driving a memory controller. 2580Sstevel@tonic-gate */ 2590Sstevel@tonic-gate if (ddi_root_node() == devi) { 2600Sstevel@tonic-gate rootnex_fm_init(devi); 2610Sstevel@tonic-gate add_root_props(devi); 2620Sstevel@tonic-gate i_ddi_rootnex_init_events(devi); 2630Sstevel@tonic-gate rootnex_regspec_arena = vmem_create("regspec", 2640Sstevel@tonic-gate (void *)PIOMAPBASE, PIOMAPSIZE, MMU_PAGESIZE, NULL, NULL, 2650Sstevel@tonic-gate NULL, 0, VM_SLEEP); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate if (ddi_prop_op(DDI_DEV_T_ANY, devi, PROP_LEN_AND_VAL_ALLOC, 2690Sstevel@tonic-gate DDI_PROP_DONTPASS, "banner-name", (caddr_t)&valuep, 2700Sstevel@tonic-gate &length) == DDI_PROP_SUCCESS) { 2710Sstevel@tonic-gate cmn_err(CE_CONT, "?root nexus = %s\n", valuep); 2720Sstevel@tonic-gate kmem_free(valuep, length); 2730Sstevel@tonic-gate } 2740Sstevel@tonic-gate /* 2750Sstevel@tonic-gate * Add a no-suspend-resume property so that NDI 2760Sstevel@tonic-gate * does not attempt to suspend/resume the rootnex 2770Sstevel@tonic-gate * (or any of its aliases) node. 2780Sstevel@tonic-gate */ 2790Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE, devi, 2800Sstevel@tonic-gate "pm-hardware-state", "no-suspend-resume"); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate return (DDI_SUCCESS); 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /*ARGSUSED*/ 2860Sstevel@tonic-gate static int 2870Sstevel@tonic-gate rootnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 2880Sstevel@tonic-gate { 2890Sstevel@tonic-gate return (DDI_SUCCESS); 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate static void 2930Sstevel@tonic-gate add_root_props(dev_info_t *devi) 2940Sstevel@tonic-gate { 2950Sstevel@tonic-gate int i; 2960Sstevel@tonic-gate struct prop_def *rpp; 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate /* 2990Sstevel@tonic-gate * Note that this for loop works because all of the 3000Sstevel@tonic-gate * properties in root_prop are integers 3010Sstevel@tonic-gate */ 3020Sstevel@tonic-gate for (i = 0, rpp = root_props; i < NROOT_PROPS; ++i, ++rpp) { 3030Sstevel@tonic-gate (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, 3040Sstevel@tonic-gate rpp->prop_name, *((int *)rpp->prop_value)); 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* 3080Sstevel@tonic-gate * Create the root node "boolean" property 3090Sstevel@tonic-gate * corresponding to addressing type supported in the root node: 3100Sstevel@tonic-gate * 3110Sstevel@tonic-gate * Choices are: 3120Sstevel@tonic-gate * "relative-addressing" (OBP PROMS) 3130Sstevel@tonic-gate * "generic-addressing" (SunMon -- pseudo OBP/DDI) 3140Sstevel@tonic-gate */ 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, 3170Sstevel@tonic-gate DDI_RELATIVE_ADDRESSING, 1); 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* 3200Sstevel@tonic-gate * Create fault management capability property 3210Sstevel@tonic-gate */ 3220Sstevel@tonic-gate (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, "fm-capable", 3230Sstevel@tonic-gate ddi_fm_capable(devi)); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate static int 3270Sstevel@tonic-gate rootnex_map_regspec(ddi_map_req_t *mp, caddr_t *vaddrp, uint_t mapping_attr) 3280Sstevel@tonic-gate { 329*2548Saa72041 uint64_t base; 3300Sstevel@tonic-gate caddr_t kaddr; 3310Sstevel@tonic-gate pgcnt_t npages; 3320Sstevel@tonic-gate pfn_t pfn; 3330Sstevel@tonic-gate uint_t pgoffset; 3340Sstevel@tonic-gate struct regspec *rp = mp->map_obj.rp; 3350Sstevel@tonic-gate ddi_acc_hdl_t *hp; 3360Sstevel@tonic-gate 337*2548Saa72041 base = (uint64_t)rp->regspec_addr & (~MMU_PAGEOFFSET); /* base addr */ 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate /* 340*2548Saa72041 * Take the bustype and addr and convert it to a 341*2548Saa72041 * page frame number. 3420Sstevel@tonic-gate */ 343*2548Saa72041 pfn = mmu_btop(((uint64_t)(rp->regspec_bustype & 344*2548Saa72041 root_phys_addr_hi_mask) << 32) | base); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * Do a quick sanity check to make sure we are in I/O space. 3480Sstevel@tonic-gate */ 3490Sstevel@tonic-gate if (pf_is_memory(pfn)) 3500Sstevel@tonic-gate return (DDI_ME_INVAL); 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate if (rp->regspec_size == 0) { 3530Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: zero " 3540Sstevel@tonic-gate "regspec_size\n")); 3550Sstevel@tonic-gate return (DDI_ME_INVAL); 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate if (mp->map_flags & DDI_MF_DEVICE_MAPPING) 3590Sstevel@tonic-gate *vaddrp = (caddr_t)pfn; 3600Sstevel@tonic-gate else { 3610Sstevel@tonic-gate pgoffset = (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET; 3620Sstevel@tonic-gate npages = mmu_btopr(rp->regspec_size + pgoffset); 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: Mapping " 3650Sstevel@tonic-gate "%lu pages physical %x.%lx ", npages, rp->regspec_bustype, 3660Sstevel@tonic-gate base)); 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate if ((kaddr = vmem_alloc(rootnex_regspec_arena, 3690Sstevel@tonic-gate ptob(npages), VM_NOSLEEP)) == NULL) 3700Sstevel@tonic-gate return (DDI_ME_NORESOURCES); 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate /* 3730Sstevel@tonic-gate * Now map in the pages we've allocated... 3740Sstevel@tonic-gate */ 3750Sstevel@tonic-gate hat_devload(kas.a_hat, kaddr, ptob(npages), pfn, 3760Sstevel@tonic-gate mp->map_prot | mapping_attr, HAT_LOAD_LOCK); 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate *vaddrp = kaddr + pgoffset; 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate hp = mp->map_handlep; 3810Sstevel@tonic-gate if (hp) { 3820Sstevel@tonic-gate hp->ah_pfn = pfn; 3830Sstevel@tonic-gate hp->ah_pnum = npages; 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 387580Swesolows DPRINTF(ROOTNEX_MAP_DEBUG, ("at virtual 0x%p\n", *vaddrp)); 3880Sstevel@tonic-gate return (0); 3890Sstevel@tonic-gate } 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate static int 3920Sstevel@tonic-gate rootnex_unmap_regspec(ddi_map_req_t *mp, caddr_t *vaddrp) 3930Sstevel@tonic-gate { 3940Sstevel@tonic-gate caddr_t addr = *vaddrp; 3950Sstevel@tonic-gate pgcnt_t npages; 3960Sstevel@tonic-gate uint_t pgoffset; 3970Sstevel@tonic-gate caddr_t base; 3980Sstevel@tonic-gate struct regspec *rp; 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate if (mp->map_flags & DDI_MF_DEVICE_MAPPING) 4010Sstevel@tonic-gate return (0); 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate rp = mp->map_obj.rp; 4040Sstevel@tonic-gate pgoffset = (uintptr_t)addr & MMU_PAGEOFFSET; 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate if (rp->regspec_size == 0) { 4070Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_unmap_regspec: " 4080Sstevel@tonic-gate "zero regspec_size\n")); 4090Sstevel@tonic-gate return (DDI_ME_INVAL); 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate base = addr - pgoffset; 4130Sstevel@tonic-gate npages = mmu_btopr(rp->regspec_size + pgoffset); 4140Sstevel@tonic-gate hat_unload(kas.a_hat, base, ptob(npages), HAT_UNLOAD_UNLOCK); 4150Sstevel@tonic-gate vmem_free(rootnex_regspec_arena, base, ptob(npages)); 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate /* 4180Sstevel@tonic-gate * Destroy the pointer - the mapping has logically gone 4190Sstevel@tonic-gate */ 4200Sstevel@tonic-gate *vaddrp = (caddr_t)0; 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate return (0); 4230Sstevel@tonic-gate } 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate static int 4260Sstevel@tonic-gate rootnex_map_handle(ddi_map_req_t *mp) 4270Sstevel@tonic-gate { 4280Sstevel@tonic-gate ddi_acc_hdl_t *hp; 4290Sstevel@tonic-gate uint_t hat_flags; 4300Sstevel@tonic-gate register struct regspec *rp; 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate /* 4330Sstevel@tonic-gate * Set up the hat_flags for the mapping. 4340Sstevel@tonic-gate */ 4350Sstevel@tonic-gate hp = mp->map_handlep; 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate switch (hp->ah_acc.devacc_attr_endian_flags) { 4380Sstevel@tonic-gate case DDI_NEVERSWAP_ACC: 4390Sstevel@tonic-gate hat_flags = HAT_NEVERSWAP | HAT_STRICTORDER; 4400Sstevel@tonic-gate break; 4410Sstevel@tonic-gate case DDI_STRUCTURE_BE_ACC: 4420Sstevel@tonic-gate hat_flags = HAT_STRUCTURE_BE; 4430Sstevel@tonic-gate break; 4440Sstevel@tonic-gate case DDI_STRUCTURE_LE_ACC: 4450Sstevel@tonic-gate hat_flags = HAT_STRUCTURE_LE; 4460Sstevel@tonic-gate break; 4470Sstevel@tonic-gate default: 4480Sstevel@tonic-gate return (DDI_REGS_ACC_CONFLICT); 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate switch (hp->ah_acc.devacc_attr_dataorder) { 4520Sstevel@tonic-gate case DDI_STRICTORDER_ACC: 4530Sstevel@tonic-gate break; 4540Sstevel@tonic-gate case DDI_UNORDERED_OK_ACC: 4550Sstevel@tonic-gate hat_flags |= HAT_UNORDERED_OK; 4560Sstevel@tonic-gate break; 4570Sstevel@tonic-gate case DDI_MERGING_OK_ACC: 4580Sstevel@tonic-gate hat_flags |= HAT_MERGING_OK; 4590Sstevel@tonic-gate break; 4600Sstevel@tonic-gate case DDI_LOADCACHING_OK_ACC: 4610Sstevel@tonic-gate hat_flags |= HAT_LOADCACHING_OK; 4620Sstevel@tonic-gate break; 4630Sstevel@tonic-gate case DDI_STORECACHING_OK_ACC: 4640Sstevel@tonic-gate hat_flags |= HAT_STORECACHING_OK; 4650Sstevel@tonic-gate break; 4660Sstevel@tonic-gate default: 4670Sstevel@tonic-gate return (DDI_FAILURE); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate rp = mp->map_obj.rp; 4710Sstevel@tonic-gate if (rp->regspec_size == 0) 4720Sstevel@tonic-gate return (DDI_ME_INVAL); 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate hp->ah_hat_flags = hat_flags; 4750Sstevel@tonic-gate hp->ah_pfn = mmu_btop((ulong_t)rp->regspec_addr & (~MMU_PAGEOFFSET)); 4760Sstevel@tonic-gate hp->ah_pnum = mmu_btopr(rp->regspec_size + 4770Sstevel@tonic-gate (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET); 4780Sstevel@tonic-gate return (DDI_SUCCESS); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate static int 4820Sstevel@tonic-gate rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 4830Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp) 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate struct regspec *rp, tmp_reg; 4860Sstevel@tonic-gate ddi_map_req_t mr = *mp; /* Get private copy of request */ 4870Sstevel@tonic-gate int error; 4880Sstevel@tonic-gate uint_t mapping_attr; 4890Sstevel@tonic-gate ddi_acc_hdl_t *hp = NULL; 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate mp = &mr; 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate switch (mp->map_op) { 4940Sstevel@tonic-gate case DDI_MO_MAP_LOCKED: 4950Sstevel@tonic-gate case DDI_MO_UNMAP: 4960Sstevel@tonic-gate case DDI_MO_MAP_HANDLE: 4970Sstevel@tonic-gate break; 4980Sstevel@tonic-gate default: 4990Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map " 5000Sstevel@tonic-gate "op %d.", mp->map_op)); 5010Sstevel@tonic-gate return (DDI_ME_UNIMPLEMENTED); 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate if (mp->map_flags & DDI_MF_USER_MAPPING) { 5050Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map " 5060Sstevel@tonic-gate "type: user.")); 5070Sstevel@tonic-gate return (DDI_ME_UNIMPLEMENTED); 5080Sstevel@tonic-gate } 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate /* 5110Sstevel@tonic-gate * First, if given an rnumber, convert it to a regspec... 5120Sstevel@tonic-gate * (Presumably, this is on behalf of a child of the root node?) 5130Sstevel@tonic-gate */ 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate if (mp->map_type == DDI_MT_RNUMBER) { 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate int rnumber = mp->map_obj.rnumber; 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate rp = i_ddi_rnumber_to_regspec(rdip, rnumber); 5200Sstevel@tonic-gate if (rp == (struct regspec *)0) { 5210Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: Out of " 5220Sstevel@tonic-gate "range rnumber <%d>, device <%s>", rnumber, 5230Sstevel@tonic-gate ddi_get_name(rdip))); 5240Sstevel@tonic-gate return (DDI_ME_RNUMBER_RANGE); 5250Sstevel@tonic-gate } 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * Convert the given ddi_map_req_t from rnumber to regspec... 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate mp->map_type = DDI_MT_REGSPEC; 5320Sstevel@tonic-gate mp->map_obj.rp = rp; 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate /* 5360Sstevel@tonic-gate * Adjust offset and length corresponding to called values... 5370Sstevel@tonic-gate * XXX: A non-zero length means override the one in the regspec 5380Sstevel@tonic-gate * XXX: regardless of what's in the parent's range?. 5390Sstevel@tonic-gate */ 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate tmp_reg = *(mp->map_obj.rp); /* Preserve underlying data */ 5420Sstevel@tonic-gate rp = mp->map_obj.rp = &tmp_reg; /* Use tmp_reg in request */ 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate rp->regspec_addr += (uint_t)offset; 5450Sstevel@tonic-gate if (len != 0) 5460Sstevel@tonic-gate rp->regspec_size = (uint_t)len; 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate /* 5490Sstevel@tonic-gate * Apply any parent ranges at this level, if applicable. 5500Sstevel@tonic-gate * (This is where nexus specific regspec translation takes place. 5510Sstevel@tonic-gate * Use of this function is implicit agreement that translation is 5520Sstevel@tonic-gate * provided via ddi_apply_range.) 5530Sstevel@tonic-gate */ 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: applying range of parent " 5560Sstevel@tonic-gate "<%s> to child <%s>...\n", ddi_get_name(dip), ddi_get_name(rdip))); 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate if ((error = i_ddi_apply_range(dip, rdip, mp->map_obj.rp)) != 0) 5590Sstevel@tonic-gate return (error); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate switch (mp->map_op) { 5620Sstevel@tonic-gate case DDI_MO_MAP_LOCKED: 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * Set up the locked down kernel mapping to the regspec... 5660Sstevel@tonic-gate */ 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate /* 5690Sstevel@tonic-gate * If we were passed an access handle we need to determine 5700Sstevel@tonic-gate * the "endian-ness" of the mapping and fill in the handle. 5710Sstevel@tonic-gate */ 5720Sstevel@tonic-gate if (mp->map_handlep) { 5730Sstevel@tonic-gate hp = mp->map_handlep; 5740Sstevel@tonic-gate switch (hp->ah_acc.devacc_attr_endian_flags) { 5750Sstevel@tonic-gate case DDI_NEVERSWAP_ACC: 5760Sstevel@tonic-gate mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER; 5770Sstevel@tonic-gate break; 5780Sstevel@tonic-gate case DDI_STRUCTURE_BE_ACC: 5790Sstevel@tonic-gate mapping_attr = HAT_STRUCTURE_BE; 5800Sstevel@tonic-gate break; 5810Sstevel@tonic-gate case DDI_STRUCTURE_LE_ACC: 5820Sstevel@tonic-gate mapping_attr = HAT_STRUCTURE_LE; 5830Sstevel@tonic-gate break; 5840Sstevel@tonic-gate default: 5850Sstevel@tonic-gate return (DDI_REGS_ACC_CONFLICT); 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate switch (hp->ah_acc.devacc_attr_dataorder) { 5890Sstevel@tonic-gate case DDI_STRICTORDER_ACC: 5900Sstevel@tonic-gate break; 5910Sstevel@tonic-gate case DDI_UNORDERED_OK_ACC: 5920Sstevel@tonic-gate mapping_attr |= HAT_UNORDERED_OK; 5930Sstevel@tonic-gate break; 5940Sstevel@tonic-gate case DDI_MERGING_OK_ACC: 5950Sstevel@tonic-gate mapping_attr |= HAT_MERGING_OK; 5960Sstevel@tonic-gate break; 5970Sstevel@tonic-gate case DDI_LOADCACHING_OK_ACC: 5980Sstevel@tonic-gate mapping_attr |= HAT_LOADCACHING_OK; 5990Sstevel@tonic-gate break; 6000Sstevel@tonic-gate case DDI_STORECACHING_OK_ACC: 6010Sstevel@tonic-gate mapping_attr |= HAT_STORECACHING_OK; 6020Sstevel@tonic-gate break; 6030Sstevel@tonic-gate default: 6040Sstevel@tonic-gate return (DDI_REGS_ACC_CONFLICT); 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate } else { 6070Sstevel@tonic-gate mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER; 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate /* 6110Sstevel@tonic-gate * Set up the mapping. 6120Sstevel@tonic-gate */ 6130Sstevel@tonic-gate error = rootnex_map_regspec(mp, vaddrp, mapping_attr); 6140Sstevel@tonic-gate 6150Sstevel@tonic-gate /* 6160Sstevel@tonic-gate * Fill in the access handle if needed. 6170Sstevel@tonic-gate */ 6180Sstevel@tonic-gate if (hp) { 6190Sstevel@tonic-gate hp->ah_addr = *vaddrp; 6200Sstevel@tonic-gate hp->ah_hat_flags = mapping_attr; 6210Sstevel@tonic-gate if (error == 0) 6220Sstevel@tonic-gate impl_acc_hdl_init(hp); 6230Sstevel@tonic-gate } 6240Sstevel@tonic-gate return (error); 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate case DDI_MO_UNMAP: 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate /* 6290Sstevel@tonic-gate * Release mapping... 6300Sstevel@tonic-gate */ 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate return (rootnex_unmap_regspec(mp, vaddrp)); 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate case DDI_MO_MAP_HANDLE: 6350Sstevel@tonic-gate return (rootnex_map_handle(mp)); 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate return (DDI_ME_UNIMPLEMENTED); 6400Sstevel@tonic-gate } 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate static int 6430Sstevel@tonic-gate rootnex_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6440Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6450Sstevel@tonic-gate { 646693Sgovinda int ret = DDI_SUCCESS; 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate DPRINTF(ROOTNEX_INTR_DEBUG, ("rootnex_intr_ops: rdip=%s%d " 6490Sstevel@tonic-gate "intr_op 0x%x hdlp 0x%p\n", ddi_driver_name(rdip), 6500Sstevel@tonic-gate ddi_get_instance(rdip), intr_op, hdlp)); 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate switch (intr_op) { 6530Sstevel@tonic-gate case DDI_INTROP_GETCAP: 654693Sgovinda *(int *)result = DDI_INTR_FLAG_LEVEL; 6550Sstevel@tonic-gate break; 6560Sstevel@tonic-gate case DDI_INTROP_SETCAP: 6570Sstevel@tonic-gate ret = DDI_ENOTSUP; 6580Sstevel@tonic-gate break; 6590Sstevel@tonic-gate case DDI_INTROP_ALLOC: 6600Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 6610Sstevel@tonic-gate break; 6620Sstevel@tonic-gate case DDI_INTROP_FREE: 6630Sstevel@tonic-gate break; 6640Sstevel@tonic-gate case DDI_INTROP_GETPRI: 665693Sgovinda *(int *)result = rootnex_get_intr_pri(dip, rdip, hdlp); 6660Sstevel@tonic-gate break; 6670Sstevel@tonic-gate case DDI_INTROP_SETPRI: 6680Sstevel@tonic-gate break; 6690Sstevel@tonic-gate case DDI_INTROP_ADDISR: 6700Sstevel@tonic-gate ret = rootnex_add_intr_impl(dip, rdip, hdlp); 6710Sstevel@tonic-gate break; 6720Sstevel@tonic-gate case DDI_INTROP_REMISR: 6730Sstevel@tonic-gate ret = rootnex_remove_intr_impl(dip, rdip, hdlp); 6740Sstevel@tonic-gate break; 6750Sstevel@tonic-gate case DDI_INTROP_ENABLE: 6760Sstevel@tonic-gate case DDI_INTROP_DISABLE: 6770Sstevel@tonic-gate break; 6780Sstevel@tonic-gate case DDI_INTROP_NINTRS: 6790Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 6800Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip); 6810Sstevel@tonic-gate break; 6820Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 6830Sstevel@tonic-gate /* Root nexus driver supports only fixed interrupts */ 6840Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip) ? 6850Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0; 6860Sstevel@tonic-gate break; 6870Sstevel@tonic-gate default: 6880Sstevel@tonic-gate ret = DDI_ENOTSUP; 6890Sstevel@tonic-gate break; 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate return (ret); 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate /* 6970Sstevel@tonic-gate * Shorthand defines 6980Sstevel@tonic-gate */ 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate #define DMAOBJ_PP_PP dmao_obj.pp_obj.pp_pp 7010Sstevel@tonic-gate #define DMAOBJ_PP_OFF dmao_ogj.pp_obj.pp_offset 7020Sstevel@tonic-gate #define ALO dma_lim->dlim_addr_lo 7030Sstevel@tonic-gate #define AHI dma_lim->dlim_addr_hi 7040Sstevel@tonic-gate #define OBJSIZE dmareq->dmar_object.dmao_size 7050Sstevel@tonic-gate #define ORIGVADDR dmareq->dmar_object.dmao_obj.virt_obj.v_addr 7060Sstevel@tonic-gate #define RED ((mp->dmai_rflags & DDI_DMA_REDZONE)? 1 : 0) 7070Sstevel@tonic-gate #define DIRECTION (mp->dmai_rflags & DDI_DMA_RDWR) 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate /* 7100Sstevel@tonic-gate * rootnex_map_fault: 7110Sstevel@tonic-gate * 7120Sstevel@tonic-gate * fault in mappings for requestors 7130Sstevel@tonic-gate */ 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate /*ARGSUSED*/ 7160Sstevel@tonic-gate static int 7170Sstevel@tonic-gate rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip, 7180Sstevel@tonic-gate struct hat *hat, struct seg *seg, caddr_t addr, 7190Sstevel@tonic-gate struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock) 7200Sstevel@tonic-gate { 7210Sstevel@tonic-gate extern struct seg_ops segdev_ops; 7220Sstevel@tonic-gate 723580Swesolows DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_fault: address <%p> " 724580Swesolows "pfn <%lx>", addr, pfn)); 7250Sstevel@tonic-gate DPRINTF(ROOTNEX_MAP_DEBUG, (" Seg <%s>\n", 7260Sstevel@tonic-gate seg->s_ops == &segdev_ops ? "segdev" : 7270Sstevel@tonic-gate seg == &kvseg ? "segkmem" : "NONE!")); 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate /* 7300Sstevel@tonic-gate * This is all terribly broken, but it is a start 7310Sstevel@tonic-gate * 7320Sstevel@tonic-gate * XXX Note that this test means that segdev_ops 7330Sstevel@tonic-gate * must be exported from seg_dev.c. 7340Sstevel@tonic-gate * XXX What about devices with their own segment drivers? 7350Sstevel@tonic-gate */ 7360Sstevel@tonic-gate if (seg->s_ops == &segdev_ops) { 7370Sstevel@tonic-gate register struct segdev_data *sdp = 7380Sstevel@tonic-gate (struct segdev_data *)seg->s_data; 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate if (hat == NULL) { 7410Sstevel@tonic-gate /* 7420Sstevel@tonic-gate * This is one plausible interpretation of 7430Sstevel@tonic-gate * a null hat i.e. use the first hat on the 7440Sstevel@tonic-gate * address space hat list which by convention is 7450Sstevel@tonic-gate * the hat of the system MMU. At alternative 7460Sstevel@tonic-gate * would be to panic .. this might well be better .. 7470Sstevel@tonic-gate */ 7480Sstevel@tonic-gate ASSERT(AS_READ_HELD(seg->s_as, &seg->s_as->a_lock)); 7490Sstevel@tonic-gate hat = seg->s_as->a_hat; 7500Sstevel@tonic-gate cmn_err(CE_NOTE, "rootnex_map_fault: nil hat"); 7510Sstevel@tonic-gate } 7520Sstevel@tonic-gate hat_devload(hat, addr, MMU_PAGESIZE, pfn, prot | sdp->hat_attr, 7530Sstevel@tonic-gate (lock ? HAT_LOAD_LOCK : HAT_LOAD)); 7540Sstevel@tonic-gate } else if (seg == &kvseg && dp == (struct devpage *)0) { 7550Sstevel@tonic-gate hat_devload(kas.a_hat, addr, MMU_PAGESIZE, pfn, prot, 7560Sstevel@tonic-gate HAT_LOAD_LOCK); 7570Sstevel@tonic-gate } else 7580Sstevel@tonic-gate return (DDI_FAILURE); 7590Sstevel@tonic-gate return (DDI_SUCCESS); 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate /* 7630Sstevel@tonic-gate * Name a child of rootnex 7640Sstevel@tonic-gate * 7650Sstevel@tonic-gate * This may be called multiple times, independent of initchild calls. 7660Sstevel@tonic-gate */ 7670Sstevel@tonic-gate int 7680Sstevel@tonic-gate rootnex_name_child(dev_info_t *child, char *name, int namelen) 7690Sstevel@tonic-gate { 7700Sstevel@tonic-gate return (rootnex_name_child_impl(child, name, namelen)); 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate static int 7750Sstevel@tonic-gate rootnex_ctl_initchild(dev_info_t *dip) 7760Sstevel@tonic-gate { 7770Sstevel@tonic-gate return (rootnex_ctl_initchild_impl(dip)); 7780Sstevel@tonic-gate } 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate int 7820Sstevel@tonic-gate rootnex_ctl_uninitchild(dev_info_t *dip) 7830Sstevel@tonic-gate { 7840Sstevel@tonic-gate extern void impl_free_ddi_ppd(dev_info_t *); 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate rootnex_ctl_uninitchild_impl(dip); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate /* 7890Sstevel@tonic-gate * strip properties and convert node to prototype form 7900Sstevel@tonic-gate */ 7910Sstevel@tonic-gate impl_free_ddi_ppd(dip); 7920Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 7930Sstevel@tonic-gate impl_rem_dev_props(dip); 7940Sstevel@tonic-gate return (DDI_SUCCESS); 7950Sstevel@tonic-gate } 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate static int 7990Sstevel@tonic-gate rootnex_ctl_reportdev(dev_info_t *dev) 8000Sstevel@tonic-gate { 8010Sstevel@tonic-gate return (rootnex_ctl_reportdev_impl(dev)); 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate static int 8060Sstevel@tonic-gate rootnex_ctlops_peekpoke(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args, 8070Sstevel@tonic-gate void *result) 8080Sstevel@tonic-gate { 8090Sstevel@tonic-gate int err = DDI_SUCCESS; 8100Sstevel@tonic-gate on_trap_data_t otd; 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate /* No safe access except for peek/poke is supported. */ 8130Sstevel@tonic-gate if (in_args->handle != NULL) 8140Sstevel@tonic-gate return (DDI_FAILURE); 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate /* Set up protected environment. */ 8170Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 8180Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate if (cmd == DDI_CTLOPS_POKE) { 8210Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault; 8220Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr, 8230Sstevel@tonic-gate (void *)in_args->host_addr); 8240Sstevel@tonic-gate } else { 8250Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault; 8260Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr, 8270Sstevel@tonic-gate (void *)in_args->host_addr); 8280Sstevel@tonic-gate result = (void *)in_args->host_addr; 8290Sstevel@tonic-gate } 8300Sstevel@tonic-gate otd.ot_trampoline = tramp; 8310Sstevel@tonic-gate } else 8320Sstevel@tonic-gate err = DDI_FAILURE; 8330Sstevel@tonic-gate 8340Sstevel@tonic-gate /* Take down protected environment. */ 8350Sstevel@tonic-gate no_trap(); 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate return (err); 8380Sstevel@tonic-gate } 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate /*ARGSUSED*/ 8410Sstevel@tonic-gate static int 8420Sstevel@tonic-gate rootnex_ctlops(dev_info_t *dip, dev_info_t *rdip, 8430Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 8440Sstevel@tonic-gate { 8450Sstevel@tonic-gate register int n, *ptr; 8460Sstevel@tonic-gate register struct ddi_parent_private_data *pdp; 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate static boolean_t reserved_msg_printed = B_FALSE; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate switch (ctlop) { 8510Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 8520Sstevel@tonic-gate return (DDI_FAILURE); 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate case DDI_CTLOPS_BTOP: 8550Sstevel@tonic-gate /* 8560Sstevel@tonic-gate * Convert byte count input to physical page units. 8570Sstevel@tonic-gate * (byte counts that are not a page-size multiple 8580Sstevel@tonic-gate * are rounded down) 8590Sstevel@tonic-gate */ 8600Sstevel@tonic-gate *(ulong_t *)result = btop(*(ulong_t *)arg); 8610Sstevel@tonic-gate return (DDI_SUCCESS); 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate case DDI_CTLOPS_PTOB: 8640Sstevel@tonic-gate /* 8650Sstevel@tonic-gate * Convert size in physical pages to bytes 8660Sstevel@tonic-gate */ 8670Sstevel@tonic-gate *(ulong_t *)result = ptob(*(ulong_t *)arg); 8680Sstevel@tonic-gate return (DDI_SUCCESS); 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate case DDI_CTLOPS_BTOPR: 8710Sstevel@tonic-gate /* 8720Sstevel@tonic-gate * Convert byte count input to physical page units 8730Sstevel@tonic-gate * (byte counts that are not a page-size multiple 8740Sstevel@tonic-gate * are rounded up) 8750Sstevel@tonic-gate */ 8760Sstevel@tonic-gate *(ulong_t *)result = btopr(*(ulong_t *)arg); 8770Sstevel@tonic-gate return (DDI_SUCCESS); 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 8800Sstevel@tonic-gate return (rootnex_ctl_initchild((dev_info_t *)arg)); 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 8830Sstevel@tonic-gate return (rootnex_ctl_uninitchild((dev_info_t *)arg)); 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 8860Sstevel@tonic-gate return (rootnex_ctl_reportdev(rdip)); 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 8890Sstevel@tonic-gate /* 8900Sstevel@tonic-gate * Nothing to do here but reflect back.. 8910Sstevel@tonic-gate */ 8920Sstevel@tonic-gate return (DDI_SUCCESS); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 8950Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 8960Sstevel@tonic-gate break; 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 8990Sstevel@tonic-gate if (ndi_dev_is_prom_node(rdip)) 9000Sstevel@tonic-gate return (DDI_SUCCESS); 9010Sstevel@tonic-gate if (ndi_dev_is_persistent_node(rdip)) 9020Sstevel@tonic-gate return (DDI_SUCCESS); 9030Sstevel@tonic-gate return (DDI_FAILURE); 9040Sstevel@tonic-gate 9050Sstevel@tonic-gate case DDI_CTLOPS_POWER: { 9060Sstevel@tonic-gate return ((*pm_platform_power)((power_req_t *)arg)); 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 909693Sgovinda case DDI_CTLOPS_RESERVED0: /* Was DDI_CTLOPS_NINTRS, obsolete */ 9100Sstevel@tonic-gate case DDI_CTLOPS_RESERVED1: /* Was DDI_CTLOPS_POKE_INIT, obsolete */ 9110Sstevel@tonic-gate case DDI_CTLOPS_RESERVED2: /* Was DDI_CTLOPS_POKE_FLUSH, obsolete */ 9120Sstevel@tonic-gate case DDI_CTLOPS_RESERVED3: /* Was DDI_CTLOPS_POKE_FINI, obsolete */ 913693Sgovinda case DDI_CTLOPS_RESERVED4: /* Was DDI_CTLOPS_INTR_HILEVEL, obsolete */ 914693Sgovinda case DDI_CTLOPS_RESERVED5: /* Was DDI_CTLOPS_XLATE_INTRS, obsolete */ 9150Sstevel@tonic-gate if (!reserved_msg_printed) { 9160Sstevel@tonic-gate reserved_msg_printed = B_TRUE; 9170Sstevel@tonic-gate cmn_err(CE_WARN, "Failing ddi_ctlops call(s) for " 9180Sstevel@tonic-gate "1 or more reserved/obsolete operations."); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate return (DDI_FAILURE); 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate case DDI_CTLOPS_POKE: 9230Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 9240Sstevel@tonic-gate return (rootnex_ctlops_peekpoke(ctlop, (peekpoke_ctlops_t *)arg, 9250Sstevel@tonic-gate result)); 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate default: 9280Sstevel@tonic-gate return (DDI_FAILURE); 9290Sstevel@tonic-gate } 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate /* 9320Sstevel@tonic-gate * The rest are for "hardware" properties 9330Sstevel@tonic-gate */ 9340Sstevel@tonic-gate if ((pdp = ddi_get_parent_data(rdip)) == NULL) 9350Sstevel@tonic-gate return (DDI_FAILURE); 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate if (ctlop == DDI_CTLOPS_NREGS) { 9380Sstevel@tonic-gate ptr = (int *)result; 9390Sstevel@tonic-gate *ptr = pdp->par_nreg; 9400Sstevel@tonic-gate } else { /* ctlop == DDI_CTLOPS_REGSIZE */ 9410Sstevel@tonic-gate off_t *size = (off_t *)result; 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate ptr = (int *)arg; 9440Sstevel@tonic-gate n = *ptr; 9450Sstevel@tonic-gate if (n >= pdp->par_nreg) { 9460Sstevel@tonic-gate return (DDI_FAILURE); 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate *size = (off_t)pdp->par_reg[n].regspec_size; 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate return (DDI_SUCCESS); 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate /* ARGSUSED */ 9540Sstevel@tonic-gate int 9550Sstevel@tonic-gate rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int cap, 9560Sstevel@tonic-gate ddi_iblock_cookie_t *ibc) 9570Sstevel@tonic-gate { 9580Sstevel@tonic-gate *ibc = rootnex_err_ibc; 9590Sstevel@tonic-gate return (ddi_system_fmcap | DDI_FM_ACCCHK_CAPABLE | 9600Sstevel@tonic-gate DDI_FM_DMACHK_CAPABLE); 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate static void 9640Sstevel@tonic-gate rootnex_fm_init(dev_info_t *dip) 9650Sstevel@tonic-gate { 9660Sstevel@tonic-gate int fmcap; 9670Sstevel@tonic-gate 9680Sstevel@tonic-gate /* Minimum fm capability level for sun4u platforms */ 9690Sstevel@tonic-gate ddi_system_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE; 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate fmcap = ddi_system_fmcap; 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate /* 9740Sstevel@tonic-gate * Initialize ECC error handling 9750Sstevel@tonic-gate */ 9760Sstevel@tonic-gate rootnex_err_ibc = (ddi_iblock_cookie_t)PIL_15; 9770Sstevel@tonic-gate ddi_fm_init(dip, &fmcap, &rootnex_err_ibc); 9780Sstevel@tonic-gate } 979