xref: /illumos-gate/usr/src/uts/sun4u/io/mach_rootnex.c (revision d35ce8d7)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51c0f05faSjasonwu  * Common Development and Distribution License (the "License").
61c0f05faSjasonwu  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
221c0f05faSjasonwu  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
252a1fd0ffSPeter Tribble /*
262a1fd0ffSPeter Tribble  * Copyright 2019 Peter Tribble.
272a1fd0ffSPeter Tribble  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * sun4u root nexus driver
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate #include <sys/conf.h>
337c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
347c478bd9Sstevel@tonic-gate #include <sys/sysiosbus.h>
357c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
377c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
387c478bd9Sstevel@tonic-gate #include <sys/async.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /* Useful debugging Stuff */
417c478bd9Sstevel@tonic-gate #include <sys/nexusdebug.h>
427c478bd9Sstevel@tonic-gate #define	ROOTNEX_MAP_DEBUG		0x1
437c478bd9Sstevel@tonic-gate #define	ROOTNEX_INTR_DEBUG		0x2
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Extern declarations
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate extern uint_t	root_phys_addr_lo_mask;
497c478bd9Sstevel@tonic-gate extern int rootnex_name_child(dev_info_t *child, char *name, int namelen);
507c478bd9Sstevel@tonic-gate extern int rootnex_ctl_uninitchild(dev_info_t *dip);
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate uint_t	root_phys_addr_hi_mask = 0xffffffff;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * config information
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate int
587c478bd9Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
597c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp);
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate int
627c478bd9Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
637c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp);
647c478bd9Sstevel@tonic-gate 
65a195726fSgovinda int
667c478bd9Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
677c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t rootnex_err_ibc;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * rootnex_add_intr_impl:
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate /*ARGSUSED*/
757c478bd9Sstevel@tonic-gate int
rootnex_add_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)767c478bd9Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
777c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate 	volatile uint64_t	*intr_mapping_reg;
807c478bd9Sstevel@tonic-gate 	volatile uint64_t	mondo_vector;
817c478bd9Sstevel@tonic-gate 	int32_t			r_upaid = -1;
827c478bd9Sstevel@tonic-gate 	int32_t			slave = 0;
831c0f05faSjasonwu 	int32_t			portid;
847c478bd9Sstevel@tonic-gate 	int			len, ret;
857c478bd9Sstevel@tonic-gate 
861c0f05faSjasonwu 	if (((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
871c0f05faSjasonwu 	    DDI_PROP_DONTPASS, "upa-portid", -1)) != -1) ||
881c0f05faSjasonwu 	    ((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
891c0f05faSjasonwu 	    DDI_PROP_DONTPASS, "portid", -1)) != -1)) {
907c478bd9Sstevel@tonic-gate 		if (ddi_getprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
917c478bd9Sstevel@tonic-gate 		    "upa-interrupt-slave", 0) != 0) {
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 			/* Give slave devices pri of 5. e.g. fb's */
94a195726fSgovinda 			hdlp->ih_pri = 5;
957c478bd9Sstevel@tonic-gate 		}
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 		/*
987c478bd9Sstevel@tonic-gate 		 * Translate the interrupt property by stuffing in the
991c0f05faSjasonwu 		 * portid for those devices which have a portid.
1007c478bd9Sstevel@tonic-gate 		 */
1011c0f05faSjasonwu 		hdlp->ih_vector |= (UPAID_TO_IGN(portid) << 6);
1027c478bd9Sstevel@tonic-gate 	}
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	/*
1057c478bd9Sstevel@tonic-gate 	 * Hack to support the UPA slave devices before the 1275
1067c478bd9Sstevel@tonic-gate 	 * support for imap was introduced.
1077c478bd9Sstevel@tonic-gate 	 */
108*d35ce8d7SToomas Soome 	if (ddi_getproplen(DDI_DEV_T_ANY, dip, 0, "interrupt-map",
1097c478bd9Sstevel@tonic-gate 	    &len) != DDI_PROP_SUCCESS && ddi_getprop(DDI_DEV_T_ANY,
1107c478bd9Sstevel@tonic-gate 	    rdip, DDI_PROP_DONTPASS, "upa-interrupt-slave", 0) != 0 &&
1117c478bd9Sstevel@tonic-gate 	    ddi_get_parent(rdip) == dip) {
1127c478bd9Sstevel@tonic-gate 		slave = 1;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 		if ((r_upaid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
1157c478bd9Sstevel@tonic-gate 		    DDI_PROP_DONTPASS, "upa-portid", -1)) != -1) {
1167c478bd9Sstevel@tonic-gate 			extern uint64_t *get_intr_mapping_reg(int, int);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 			if ((intr_mapping_reg = get_intr_mapping_reg(
1197c478bd9Sstevel@tonic-gate 			    r_upaid, 1)) == NULL)
1207c478bd9Sstevel@tonic-gate 				return (DDI_FAILURE);
1217c478bd9Sstevel@tonic-gate 		} else
1227c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	if ((ret = i_ddi_add_ivintr(hdlp)) != DDI_SUCCESS)
1267c478bd9Sstevel@tonic-gate 		return (ret);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	/*
1297c478bd9Sstevel@tonic-gate 	 * Hack to support the UPA slave devices before the 1275
1307c478bd9Sstevel@tonic-gate 	 * support for imap was introduced.
1317c478bd9Sstevel@tonic-gate 	 */
1327c478bd9Sstevel@tonic-gate 	if (slave) {
1337c478bd9Sstevel@tonic-gate 		/*
1347c478bd9Sstevel@tonic-gate 		 * Program the interrupt mapping register.
1357c478bd9Sstevel@tonic-gate 		 * Interrupts from the slave UPA devices are
1367c478bd9Sstevel@tonic-gate 		 * directed at the boot CPU until it is known
1377c478bd9Sstevel@tonic-gate 		 * that they can be safely redirected while
1387c478bd9Sstevel@tonic-gate 		 * running under load.
1397c478bd9Sstevel@tonic-gate 		 */
1407c478bd9Sstevel@tonic-gate 		mondo_vector = cpu0.cpu_id << IMR_TID_SHIFT;
141a195726fSgovinda 		mondo_vector |= (IMR_VALID | (uint64_t)hdlp->ih_vector);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 		/* Set the mapping register */
1447c478bd9Sstevel@tonic-gate 		*intr_mapping_reg = mondo_vector;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 		/* Flush write buffers */
1477c478bd9Sstevel@tonic-gate 		mondo_vector = *intr_mapping_reg;
1487c478bd9Sstevel@tonic-gate 	}
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	return (ret);
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * rootnex_remove_intr_impl:
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1577c478bd9Sstevel@tonic-gate int
rootnex_remove_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)1587c478bd9Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
1597c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
1607c478bd9Sstevel@tonic-gate {
1611c0f05faSjasonwu 	int32_t		portid;
1627c478bd9Sstevel@tonic-gate 	int		len;
1637c478bd9Sstevel@tonic-gate 
1641c0f05faSjasonwu 	if (((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
1651c0f05faSjasonwu 	    DDI_PROP_DONTPASS, "upa-portid", -1)) != -1) ||
1661c0f05faSjasonwu 	    ((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
1671c0f05faSjasonwu 	    DDI_PROP_DONTPASS, "portid", -1)) != -1)) {
1687c478bd9Sstevel@tonic-gate 		/*
1697c478bd9Sstevel@tonic-gate 		 * Translate the interrupt property by stuffing in the
1701c0f05faSjasonwu 		 * portid for those devices which have a portid.
1717c478bd9Sstevel@tonic-gate 		 */
1721c0f05faSjasonwu 		hdlp->ih_vector |= (UPAID_TO_IGN(portid) << 6);
1737c478bd9Sstevel@tonic-gate 	}
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/*
1767c478bd9Sstevel@tonic-gate 	 * Hack to support the UPA slave devices before the 1275
1777c478bd9Sstevel@tonic-gate 	 * support for imap was introduced.
1787c478bd9Sstevel@tonic-gate 	 */
179*d35ce8d7SToomas Soome 	if (ddi_getproplen(DDI_DEV_T_ANY, dip, 0, "interrupt-map",
1807c478bd9Sstevel@tonic-gate 	    &len) != DDI_PROP_SUCCESS && ddi_getprop(DDI_DEV_T_ANY,
1817c478bd9Sstevel@tonic-gate 	    rdip, DDI_PROP_DONTPASS, "upa-interrupt-slave", 0) != 0) {
1827c478bd9Sstevel@tonic-gate 		int32_t r_upaid = -1;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 		if ((r_upaid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
1857c478bd9Sstevel@tonic-gate 		    DDI_PROP_DONTPASS, "upa-portid", -1)) != -1 &&
1867c478bd9Sstevel@tonic-gate 		    ddi_get_parent(rdip) == dip) {
1877c478bd9Sstevel@tonic-gate 			volatile uint64_t *intr_mapping_reg;
1887c478bd9Sstevel@tonic-gate 			volatile uint64_t flush_data;
1897c478bd9Sstevel@tonic-gate 			extern uint64_t *get_intr_mapping_reg(int, int);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 			if ((intr_mapping_reg = get_intr_mapping_reg(
1927c478bd9Sstevel@tonic-gate 			    r_upaid, 1)) == NULL)
1937c478bd9Sstevel@tonic-gate 				return (DDI_SUCCESS);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 			/* Clear the mapping register */
1967c478bd9Sstevel@tonic-gate 			*intr_mapping_reg = 0x0ull;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 			/* Flush write buffers */
1997c478bd9Sstevel@tonic-gate 			flush_data = *intr_mapping_reg;
2007c478bd9Sstevel@tonic-gate #ifdef lint
2017c478bd9Sstevel@tonic-gate 			flush_data = flush_data;
2027c478bd9Sstevel@tonic-gate #endif /* lint */
2037c478bd9Sstevel@tonic-gate 		}
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	i_ddi_rem_ivintr(hdlp);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * rootnex_get_intr_pri:
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate /*ARGSUSED*/
215a195726fSgovinda int
rootnex_get_intr_pri(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)2167c478bd9Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
2177c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
2187c478bd9Sstevel@tonic-gate {
219a195726fSgovinda 	int	pri = hdlp->ih_pri;
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	if (ddi_prop_get_int(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
2227c478bd9Sstevel@tonic-gate 	    "upa-portid", -1) != -1) {
2237c478bd9Sstevel@tonic-gate 		if (ddi_getprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
2247c478bd9Sstevel@tonic-gate 		    "upa-interrupt-slave", 0) != 0) {
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 			/* Give slave devices pri of 5. e.g. fb's */
227a195726fSgovinda 			pri = 5;
2287c478bd9Sstevel@tonic-gate 		}
2297c478bd9Sstevel@tonic-gate 	}
230a195726fSgovinda 
231a195726fSgovinda 	return (pri);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate int
rootnex_ctl_reportdev_impl(dev_info_t * dev)2357c478bd9Sstevel@tonic-gate rootnex_ctl_reportdev_impl(dev_info_t *dev)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	struct regspec *rp;
2387c478bd9Sstevel@tonic-gate 	char buf[80];
2397c478bd9Sstevel@tonic-gate 	char *p = buf;
2407c478bd9Sstevel@tonic-gate 	register int n;
2417c478bd9Sstevel@tonic-gate 	int	portid;
2427c478bd9Sstevel@tonic-gate 	int	nodeid;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	(void) sprintf(p, "%s%d at root", ddi_driver_name(dev),
2457c478bd9Sstevel@tonic-gate 	    ddi_get_instance(dev));
2467c478bd9Sstevel@tonic-gate 	p += strlen(p);
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	if ((n = sparc_pd_getnreg(dev)) > 0) {
2497c478bd9Sstevel@tonic-gate 		rp = sparc_pd_getreg(dev, 0);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 		(void) strcpy(p, ": ");
2527c478bd9Sstevel@tonic-gate 		p += strlen(p);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 		/*
2557c478bd9Sstevel@tonic-gate 		 * This stuff needs to be fixed correctly for the FFB
2567c478bd9Sstevel@tonic-gate 		 * devices and the UPA add-on devices.
2577c478bd9Sstevel@tonic-gate 		 */
2587c478bd9Sstevel@tonic-gate 		portid = ddi_prop_get_int(DDI_DEV_T_ANY, dev,
2597c478bd9Sstevel@tonic-gate 		    DDI_PROP_DONTPASS, "upa-portid", -1);
2607c478bd9Sstevel@tonic-gate 		if (portid != -1)
2617c478bd9Sstevel@tonic-gate 			(void) sprintf(p, "UPA 0x%x 0x%x%s",
2627c478bd9Sstevel@tonic-gate 			    portid,
2637c478bd9Sstevel@tonic-gate 			    rp->regspec_addr, (n > 1 ? "" : " ..."));
2647c478bd9Sstevel@tonic-gate 		else {
2657c478bd9Sstevel@tonic-gate 			portid = ddi_prop_get_int(DDI_DEV_T_ANY, dev,
2667c478bd9Sstevel@tonic-gate 			    DDI_PROP_DONTPASS, "portid", -1);
2677c478bd9Sstevel@tonic-gate 			nodeid = ddi_prop_get_int(DDI_DEV_T_ANY, dev,
2687c478bd9Sstevel@tonic-gate 			    DDI_PROP_DONTPASS, "nodeid", -1);
2697c478bd9Sstevel@tonic-gate 			if (portid == -1 && nodeid == -1)
2707c478bd9Sstevel@tonic-gate 				printf("could not find portid "
2717c478bd9Sstevel@tonic-gate 				    "or nodeid property in %s\n",
2727c478bd9Sstevel@tonic-gate 				    DEVI(dev)->devi_node_name);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 			if (portid != -1)
2757c478bd9Sstevel@tonic-gate 				(void) sprintf(p, "SAFARI 0x%x 0x%x%s",
2767c478bd9Sstevel@tonic-gate 				    portid,
2777c478bd9Sstevel@tonic-gate 				    rp->regspec_addr &
2787c478bd9Sstevel@tonic-gate 				    root_phys_addr_lo_mask,
2797c478bd9Sstevel@tonic-gate 				    (n > 1 ? "" : " ..."));
2807c478bd9Sstevel@tonic-gate 			if (nodeid != -1)
2817c478bd9Sstevel@tonic-gate 				(void) sprintf(p, "SSM Node %d", nodeid);
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 		p += strlen(p);
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	/*
2877c478bd9Sstevel@tonic-gate 	 * This is where we need to print out the interrupt specifications
2887c478bd9Sstevel@tonic-gate 	 * for the FFB device and any UPA add-on devices.  Not sure how to
2897c478bd9Sstevel@tonic-gate 	 * do this yet?
2907c478bd9Sstevel@tonic-gate 	 */
2917c478bd9Sstevel@tonic-gate 	cmn_err(CE_CONT, "?%s\n", buf);
2927c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate int
rootnex_name_child_impl(dev_info_t * child,char * name,int namelen)2967c478bd9Sstevel@tonic-gate rootnex_name_child_impl(dev_info_t *child, char *name, int namelen)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	struct ddi_parent_private_data *pdptr;
2997c478bd9Sstevel@tonic-gate 	int portid, nodeid;
3007c478bd9Sstevel@tonic-gate 	char *node_name;
3017c478bd9Sstevel@tonic-gate 	struct regspec *rp;
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	extern uint_t root_phys_addr_lo_mask;
3047c478bd9Sstevel@tonic-gate 	extern void make_ddi_ppd(
3057c478bd9Sstevel@tonic-gate 	    dev_info_t *, struct ddi_parent_private_data **);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	/*
3087c478bd9Sstevel@tonic-gate 	 * Fill in parent-private data and this function returns to us
3097c478bd9Sstevel@tonic-gate 	 * an indication if it used "registers" to fill in the data.
3107c478bd9Sstevel@tonic-gate 	 */
3117c478bd9Sstevel@tonic-gate 	if (ddi_get_parent_data(child) == NULL) {
3127c478bd9Sstevel@tonic-gate 		make_ddi_ppd(child, &pdptr);
3137c478bd9Sstevel@tonic-gate 		ddi_set_parent_data(child, pdptr);
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	/*
3177c478bd9Sstevel@tonic-gate 	 * No reg property, return null string as address (e.g. pseudo)
3187c478bd9Sstevel@tonic-gate 	 */
3197c478bd9Sstevel@tonic-gate 	name[0] = '\0';
3207c478bd9Sstevel@tonic-gate 	if (sparc_pd_getnreg(child) == 0) {
3217c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3227c478bd9Sstevel@tonic-gate 	}
3237c478bd9Sstevel@tonic-gate 	rp = sparc_pd_getreg(child, 0);
3247c478bd9Sstevel@tonic-gate 	ASSERT(rp != NULL);
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	/*
3277c478bd9Sstevel@tonic-gate 	 * Create portid property for fhc node under root(/fhc).
3287c478bd9Sstevel@tonic-gate 	 */
3297c478bd9Sstevel@tonic-gate 	node_name = ddi_node_name(child);
3307c478bd9Sstevel@tonic-gate 	if ((strcmp(node_name, "fhc") == 0) ||
3317c478bd9Sstevel@tonic-gate 	    (strcmp(node_name, "mem-unit") == 0) ||
3327c478bd9Sstevel@tonic-gate 	    (strcmp(node_name, "central") == 0)) {
3337c478bd9Sstevel@tonic-gate 		portid = (rp->regspec_bustype >> 1) & 0x1f;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 		/*
3367c478bd9Sstevel@tonic-gate 		 * The port-id must go on the hardware property list,
3377c478bd9Sstevel@tonic-gate 		 * otherwise, initchild may fail.
3387c478bd9Sstevel@tonic-gate 		 */
3397c478bd9Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, child, "upa-portid",
3407c478bd9Sstevel@tonic-gate 		    portid) != DDI_SUCCESS)
3417c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
3427c478bd9Sstevel@tonic-gate 			    "Error in creating upa-portid property for fhc.\n");
3437c478bd9Sstevel@tonic-gate 	}
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	/*
3467c478bd9Sstevel@tonic-gate 	 * Name node on behalf of child nexus.
3477c478bd9Sstevel@tonic-gate 	 */
3487c478bd9Sstevel@tonic-gate 	if (ddi_get_parent(child) != ddi_root_node()) {
3497c478bd9Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%x,%x",
3507c478bd9Sstevel@tonic-gate 		    rp->regspec_bustype, rp->regspec_addr);
3517c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	/*
3557c478bd9Sstevel@tonic-gate 	 * On sun4u, the 'name' of children of the root node
3567c478bd9Sstevel@tonic-gate 	 * is foo@<upa-mid>,<offset>, which is derived from,
3577c478bd9Sstevel@tonic-gate 	 * but not identical to the physical address.
3587c478bd9Sstevel@tonic-gate 	 */
3597c478bd9Sstevel@tonic-gate 	portid = ddi_prop_get_int(DDI_DEV_T_ANY, child,
3607c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "upa-portid", -1);
3617c478bd9Sstevel@tonic-gate 	if (portid == -1)
3627c478bd9Sstevel@tonic-gate 		portid = ddi_prop_get_int(DDI_DEV_T_ANY, child,
3637c478bd9Sstevel@tonic-gate 		    DDI_PROP_DONTPASS, "portid", -1);
3647c478bd9Sstevel@tonic-gate 	nodeid = ddi_prop_get_int(DDI_DEV_T_ANY, child,
3657c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "nodeid", -1);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	/*
3687c478bd9Sstevel@tonic-gate 	 * Do not log message, to handle cases where OBP version
3697c478bd9Sstevel@tonic-gate 	 * does not have "portid" property for the root i2c node.
3707c478bd9Sstevel@tonic-gate 	 *
3717c478bd9Sstevel@tonic-gate 	 * Platforms supporting root i2c node (potentially without
3727c478bd9Sstevel@tonic-gate 	 * "portid" property) are :
3737c478bd9Sstevel@tonic-gate 	 *	SunBlade 1500, SunBlade 2500, V240, V250
3747c478bd9Sstevel@tonic-gate 	 */
3757c478bd9Sstevel@tonic-gate 	if (portid == -1 && nodeid == -1 &&
3767c478bd9Sstevel@tonic-gate 	    strncmp(node_name, "i2c", strlen("i2c")) != 0)
3777c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
3787c478bd9Sstevel@tonic-gate 		    "could not find portid or nodeid property in %s\n",
3797c478bd9Sstevel@tonic-gate 		    DEVI(child)->devi_node_name);
3807c478bd9Sstevel@tonic-gate 	if (nodeid != -1)
3817c478bd9Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%x,0", nodeid);
3827c478bd9Sstevel@tonic-gate 	else
3837c478bd9Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%x,%x", portid,
3847c478bd9Sstevel@tonic-gate 		    rp->regspec_addr & root_phys_addr_lo_mask);
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate int
rootnex_ctl_initchild_impl(dev_info_t * dip)3907c478bd9Sstevel@tonic-gate rootnex_ctl_initchild_impl(dev_info_t *dip)
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate 	struct regspec *rp;
3937c478bd9Sstevel@tonic-gate 	struct ddi_parent_private_data *pd;
3947c478bd9Sstevel@tonic-gate 	char name[MAXNAMELEN];
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	extern struct ddi_parent_private_data *init_regspec_64(dev_info_t *dip);
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	/* Name the child */
3997c478bd9Sstevel@tonic-gate 	(void) rootnex_name_child(dip, name, MAXNAMELEN);
4007c478bd9Sstevel@tonic-gate 	ddi_set_name_addr(dip, name);
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	/*
4037c478bd9Sstevel@tonic-gate 	 * Try to merge .conf node. If merge is successful, return
4047c478bd9Sstevel@tonic-gate 	 * DDI_FAILURE to allow caller to remove this node.
4057c478bd9Sstevel@tonic-gate 	 */
4067c478bd9Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(dip) == 0 &&
4077c478bd9Sstevel@tonic-gate 	    (ndi_merge_node(dip, rootnex_name_child) == DDI_SUCCESS)) {
4087c478bd9Sstevel@tonic-gate 		(void) rootnex_ctl_uninitchild(dip);
4097c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4107c478bd9Sstevel@tonic-gate 	}
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	/*
4137c478bd9Sstevel@tonic-gate 	 * If there are no "reg"s in the child node, return.
4147c478bd9Sstevel@tonic-gate 	 */
4157c478bd9Sstevel@tonic-gate 	pd = init_regspec_64(dip);
4167c478bd9Sstevel@tonic-gate 	if ((pd == NULL) || (pd->par_nreg == 0))
4177c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	/*
4207c478bd9Sstevel@tonic-gate 	 * If this is a slave device sitting on the UPA, we assume that
4217c478bd9Sstevel@tonic-gate 	 * This device can accept DMA accesses from other devices.  We need
4227c478bd9Sstevel@tonic-gate 	 * to register this fact with the system by using the highest
4237c478bd9Sstevel@tonic-gate 	 * and lowest physical pfns of the devices register space.  This
4247c478bd9Sstevel@tonic-gate 	 * will then represent a physical block of addresses that are valid
4257c478bd9Sstevel@tonic-gate 	 * for DMA accesses.
4267c478bd9Sstevel@tonic-gate 	 */
4277c478bd9Sstevel@tonic-gate 	if ((ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "upa-portid",
4287c478bd9Sstevel@tonic-gate 	    -1) != -1) && ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
4297c478bd9Sstevel@tonic-gate 	    "upa-interrupt-slave", 0)) {
4307c478bd9Sstevel@tonic-gate 		pfn_t lopfn = (pfn_t)-1;
4317c478bd9Sstevel@tonic-gate 		pfn_t hipfn = 0;
4327c478bd9Sstevel@tonic-gate 		int i;
4337c478bd9Sstevel@tonic-gate 		extern void pf_set_dmacapable(pfn_t, pfn_t);
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 		/* Scan the devices highest and lowest physical pfns */
4367c478bd9Sstevel@tonic-gate 		for (i = 0, rp = pd->par_reg; i < pd->par_nreg; i++, rp++) {
4377c478bd9Sstevel@tonic-gate 			uint64_t addr;
4387c478bd9Sstevel@tonic-gate 			pfn_t tmphipfn, tmplopfn;
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 			addr = (unsigned long long)((unsigned long long)
4417c478bd9Sstevel@tonic-gate 			    rp->regspec_bustype << 32);
4427c478bd9Sstevel@tonic-gate 			addr |= (uint64_t)rp->regspec_addr;
4437c478bd9Sstevel@tonic-gate 			tmplopfn = (pfn_t)(addr >> MMU_PAGESHIFT);
4447c478bd9Sstevel@tonic-gate 			addr += (uint64_t)(rp->regspec_size - 1);
4457c478bd9Sstevel@tonic-gate 			tmphipfn = (pfn_t)(addr >> MMU_PAGESHIFT);
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 			hipfn = (tmphipfn > hipfn) ? tmphipfn : hipfn;
4487c478bd9Sstevel@tonic-gate 			lopfn = (tmplopfn < lopfn) ? tmplopfn : lopfn;
4497c478bd9Sstevel@tonic-gate 		}
4507c478bd9Sstevel@tonic-gate 		pf_set_dmacapable(hipfn, lopfn);
4517c478bd9Sstevel@tonic-gate 	}
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate void
rootnex_ctl_uninitchild_impl(dev_info_t * dip)4577c478bd9Sstevel@tonic-gate rootnex_ctl_uninitchild_impl(dev_info_t *dip)
4587c478bd9Sstevel@tonic-gate {
4597c478bd9Sstevel@tonic-gate 	if ((ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "upa-portid",
4607c478bd9Sstevel@tonic-gate 	    -1) != -1) && (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
4617c478bd9Sstevel@tonic-gate 	    "upa-interrupt-slave", 0))) {
4627c478bd9Sstevel@tonic-gate 		struct regspec *rp;
4637c478bd9Sstevel@tonic-gate 		extern void pf_unset_dmacapable(pfn_t);
4647c478bd9Sstevel@tonic-gate 		unsigned long long addr;
4657c478bd9Sstevel@tonic-gate 		pfn_t pfn;
4667c478bd9Sstevel@tonic-gate 		struct ddi_parent_private_data *pd;
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 		pd = ddi_get_parent_data(dip);
4697c478bd9Sstevel@tonic-gate 		ASSERT(pd != NULL);
4707c478bd9Sstevel@tonic-gate 		rp = pd->par_reg;
4717c478bd9Sstevel@tonic-gate 		addr = (unsigned long long) ((unsigned long long)
4727c478bd9Sstevel@tonic-gate 		    rp->regspec_bustype << 32);
4737c478bd9Sstevel@tonic-gate 		addr |= (unsigned long long) rp->regspec_addr;
4747c478bd9Sstevel@tonic-gate 		pfn = (pfn_t)(addr >> MMU_PAGESHIFT);
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 		pf_unset_dmacapable(pfn);
4777c478bd9Sstevel@tonic-gate 	}
4787c478bd9Sstevel@tonic-gate }
479