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