xref: /onnv-gate/usr/src/uts/sun4v/io/mach_rootnex.c (revision 693:1c08294a694e)
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  * sun4v root nexus driver
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate #include <sys/conf.h>
330Sstevel@tonic-gate #include <sys/cpuvar.h>
340Sstevel@tonic-gate #include <sys/ivintr.h>
350Sstevel@tonic-gate #include <sys/intreg.h>
360Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
370Sstevel@tonic-gate #include <sys/sunndi.h>
380Sstevel@tonic-gate #include <sys/async.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /* Useful debugging Stuff */
410Sstevel@tonic-gate #include <sys/nexusdebug.h>
420Sstevel@tonic-gate #define	ROOTNEX_MAP_DEBUG		0x1
430Sstevel@tonic-gate #define	ROOTNEX_INTR_DEBUG		0x2
440Sstevel@tonic-gate 
450Sstevel@tonic-gate extern uint_t	root_phys_addr_lo_mask;
460Sstevel@tonic-gate extern int rootnex_name_child(dev_info_t *child, char *name, int namelen);
470Sstevel@tonic-gate extern int rootnex_ctl_uninitchild(dev_info_t *dip);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate uint_t	root_phys_addr_hi_mask = 0xfffffff;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #define	BUS_ADDRTYPE_CONFIG		0xc
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #define	BUSTYPE_TO_ADDRTYPE(bustype)	((bustype >> 28) & 0xf)
540Sstevel@tonic-gate 
550Sstevel@tonic-gate static char *bus_addrtype[16] = {
560Sstevel@tonic-gate 	"m", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
570Sstevel@tonic-gate 	"i", NULL, NULL, NULL, "", NULL, NULL, NULL
580Sstevel@tonic-gate };
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * config information
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate int
640Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
650Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp);
660Sstevel@tonic-gate 
670Sstevel@tonic-gate int
680Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
690Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp);
700Sstevel@tonic-gate 
71*693Sgovinda int
720Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
730Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp);
740Sstevel@tonic-gate 
750Sstevel@tonic-gate ddi_iblock_cookie_t rootnex_err_ibc;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * rootnex_add_intr_impl:
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate /*ARGSUSED*/
810Sstevel@tonic-gate int
rootnex_add_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)820Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
830Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
840Sstevel@tonic-gate {
850Sstevel@tonic-gate 	return (i_ddi_add_ivintr(hdlp));
860Sstevel@tonic-gate }
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * rootnex_remove_intr_impl:
900Sstevel@tonic-gate  */
910Sstevel@tonic-gate /*ARGSUSED*/
920Sstevel@tonic-gate int
rootnex_remove_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)930Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
940Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 	i_ddi_rem_ivintr(hdlp);
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	return (DDI_SUCCESS);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * rootnex_get_intr_pri:
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate /*ARGSUSED*/
105*693Sgovinda int
rootnex_get_intr_pri(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)1060Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
1070Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
1080Sstevel@tonic-gate {
109*693Sgovinda 	return (hdlp->ih_pri);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate int
rootnex_ctl_reportdev_impl(dev_info_t * dev)1130Sstevel@tonic-gate rootnex_ctl_reportdev_impl(dev_info_t *dev)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate 	struct regspec *rp;
1160Sstevel@tonic-gate 	char buf[80];
1170Sstevel@tonic-gate 	char *p = buf;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	(void) sprintf(p, "%s%d at root", ddi_driver_name(dev),
1200Sstevel@tonic-gate 	    ddi_get_instance(dev));
1210Sstevel@tonic-gate 	p += strlen(p);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	if (sparc_pd_getnreg(dev) > 0) {
1240Sstevel@tonic-gate 		rp = sparc_pd_getreg(dev, 0);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 		(void) strcpy(p, ": ");
1270Sstevel@tonic-gate 		p += strlen(p);
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 		(void) snprintf(p, sizeof (buf) - (buf - p),
1300Sstevel@tonic-gate 		    "0x%x 0x%x", rp->regspec_bustype & root_phys_addr_hi_mask,
1310Sstevel@tonic-gate 		    rp->regspec_addr & root_phys_addr_lo_mask);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 		p += strlen(p);
1340Sstevel@tonic-gate 	}
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	/*
1370Sstevel@tonic-gate 	 * This is where we need to print out the interrupt specifications
1380Sstevel@tonic-gate 	 * for the FFB device and any UPA add-on devices.  Not sure how to
1390Sstevel@tonic-gate 	 * do this yet?
1400Sstevel@tonic-gate 	 */
1410Sstevel@tonic-gate 	cmn_err(CE_CONT, "?%s\n", buf);
1420Sstevel@tonic-gate 	return (DDI_SUCCESS);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate int
rootnex_name_child_impl(dev_info_t * child,char * name,int namelen)1460Sstevel@tonic-gate rootnex_name_child_impl(dev_info_t *child, char *name, int namelen)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate 	struct ddi_parent_private_data *pdptr;
1490Sstevel@tonic-gate 	uint_t addrtype;
1500Sstevel@tonic-gate 	uint_t addrlow;
1510Sstevel@tonic-gate 	struct regspec *rp;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	extern uint_t root_phys_addr_lo_mask;
1540Sstevel@tonic-gate 	extern void make_ddi_ppd(
1550Sstevel@tonic-gate 	    dev_info_t *, struct ddi_parent_private_data **);
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	/*
1580Sstevel@tonic-gate 	 * Fill in parent-private data and this function returns to us
1590Sstevel@tonic-gate 	 * an indication if it used "registers" to fill in the data.
1600Sstevel@tonic-gate 	 */
1610Sstevel@tonic-gate 	if (ddi_get_parent_data(child) == NULL) {
1620Sstevel@tonic-gate 		make_ddi_ppd(child, &pdptr);
1630Sstevel@tonic-gate 		ddi_set_parent_data(child, pdptr);
1640Sstevel@tonic-gate 	}
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	/*
1670Sstevel@tonic-gate 	 * No reg property, return null string as address (e.g. pseudo)
1680Sstevel@tonic-gate 	 */
1690Sstevel@tonic-gate 	name[0] = '\0';
1700Sstevel@tonic-gate 	if (sparc_pd_getnreg(child) == 0) {
1710Sstevel@tonic-gate 		return (DDI_SUCCESS);
1720Sstevel@tonic-gate 	}
1730Sstevel@tonic-gate 	rp = sparc_pd_getreg(child, 0);
1740Sstevel@tonic-gate 	ASSERT(rp != NULL);
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	/*
1770Sstevel@tonic-gate 	 * Name node on behalf of child nexus.
1780Sstevel@tonic-gate 	 */
1790Sstevel@tonic-gate 	if (ddi_get_parent(child) != ddi_root_node()) {
1800Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%x,%x",
1810Sstevel@tonic-gate 		    rp->regspec_bustype, rp->regspec_addr);
1820Sstevel@tonic-gate 		return (DDI_SUCCESS);
1830Sstevel@tonic-gate 	}
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	/*
1860Sstevel@tonic-gate 	 * On sun4v, the 'name' of a root node device depends upon
1870Sstevel@tonic-gate 	 * the first reg property, which contains two 32-bit address
1880Sstevel@tonic-gate 	 * cells as follows:
1890Sstevel@tonic-gate 	 *
1900Sstevel@tonic-gate 	 *  bit# 63-32: ssss.hhhh.hhhh.hhhh.hhhh.hhhh.hhhh.hhhh
1910Sstevel@tonic-gate 	 *  bit# 31-00: llll.llll.llll.llll.llll.llll.llll.llll
1920Sstevel@tonic-gate 	 *
1930Sstevel@tonic-gate 	 * where 'ssss' defines the address type and naming convention
1940Sstevel@tonic-gate 	 * as follows:
1950Sstevel@tonic-gate 	 *
1960Sstevel@tonic-gate 	 *    0000  -> cacheable address space
1970Sstevel@tonic-gate 	 *		foo@m<high-addr>[,<low-addr>]
1980Sstevel@tonic-gate 	 *    1000  -> non-cacheable IO address space
1990Sstevel@tonic-gate 	 *		foo@i<high-addr>[,<low-addr>]
2000Sstevel@tonic-gate 	 *    1100  -> non-cacheable configuration address space
2010Sstevel@tonic-gate 	 *		foo@<high-addr>
2020Sstevel@tonic-gate 	 *
2030Sstevel@tonic-gate 	 * where <hish-addr> is hex-ASCII reprensation of the hh...hh
2040Sstevel@tonic-gate 	 * bits and <low-addr> is hex-ASCII represenation of the
2050Sstevel@tonic-gate 	 * ll...ll bits.
2060Sstevel@tonic-gate 	 *
2070Sstevel@tonic-gate 	 * Note that the leading zeros are omitted here. Also, if the
2080Sstevel@tonic-gate 	 * <low-addr> bits are zero, then the trailing component is
2090Sstevel@tonic-gate 	 * omitted as well.
2100Sstevel@tonic-gate 	 */
2110Sstevel@tonic-gate 	addrtype = BUSTYPE_TO_ADDRTYPE(rp->regspec_bustype);
2120Sstevel@tonic-gate 	addrlow = rp->regspec_addr & root_phys_addr_lo_mask;
2130Sstevel@tonic-gate 	if (bus_addrtype[addrtype] == NULL)
2140Sstevel@tonic-gate 		cmn_err(CE_PANIC, "rootnex: wrong bustype: %x child: %s\n",
2150Sstevel@tonic-gate 		    rp->regspec_bustype, ddi_node_name(child));
2160Sstevel@tonic-gate 	else if (addrtype == BUS_ADDRTYPE_CONFIG || addrlow == 0)
2170Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%s%x",
2180Sstevel@tonic-gate 		    bus_addrtype[addrtype],
2190Sstevel@tonic-gate 		    rp->regspec_bustype & root_phys_addr_hi_mask);
2200Sstevel@tonic-gate 	else
2210Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%s%x,%x",
2220Sstevel@tonic-gate 		    bus_addrtype[addrtype],
2230Sstevel@tonic-gate 		    rp->regspec_bustype & root_phys_addr_hi_mask, addrlow);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 	return (DDI_SUCCESS);
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate int
rootnex_ctl_initchild_impl(dev_info_t * dip)2300Sstevel@tonic-gate rootnex_ctl_initchild_impl(dev_info_t *dip)
2310Sstevel@tonic-gate {
2320Sstevel@tonic-gate 	struct ddi_parent_private_data *pd;
2330Sstevel@tonic-gate 	char name[MAXNAMELEN];
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	extern struct ddi_parent_private_data *init_regspec_64(dev_info_t *dip);
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	/* Name the child */
2380Sstevel@tonic-gate 	(void) rootnex_name_child(dip, name, MAXNAMELEN);
2390Sstevel@tonic-gate 	ddi_set_name_addr(dip, name);
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	/*
2420Sstevel@tonic-gate 	 * Try to merge .conf node. If merge is successful, return
2430Sstevel@tonic-gate 	 * DDI_FAILURE to allow caller to remove this node.
2440Sstevel@tonic-gate 	 */
2450Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(dip) == 0 &&
2460Sstevel@tonic-gate 	    (ndi_merge_node(dip, rootnex_name_child) == DDI_SUCCESS)) {
2470Sstevel@tonic-gate 		(void) rootnex_ctl_uninitchild(dip);
2480Sstevel@tonic-gate 		return (DDI_FAILURE);
2490Sstevel@tonic-gate 	}
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * If there are no "reg"s in the child node, return.
2530Sstevel@tonic-gate 	 */
2540Sstevel@tonic-gate 	pd = init_regspec_64(dip);
2550Sstevel@tonic-gate 	if ((pd == NULL) || (pd->par_nreg == 0))
2560Sstevel@tonic-gate 		return (DDI_SUCCESS);
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	return (DDI_SUCCESS);
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate /*ARGSUSED*/
2620Sstevel@tonic-gate void
rootnex_ctl_uninitchild_impl(dev_info_t * dip)2630Sstevel@tonic-gate rootnex_ctl_uninitchild_impl(dev_info_t *dip)
2640Sstevel@tonic-gate {
2650Sstevel@tonic-gate }
266