xref: /onnv-gate/usr/src/uts/common/os/autoconf.c (revision 4145:90dc07a3821d)
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
5*4145Scth  * Common Development and Distribution License (the "License").
6*4145Scth  * 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  */
210Sstevel@tonic-gate /*
22*4145Scth  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * This file contains ddi functions needed during boot and DR.
300Sstevel@tonic-gate  * Many functions in swapgeneric.c can be moved here.
310Sstevel@tonic-gate  *
320Sstevel@tonic-gate  * The object file is currently linked into unix.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/bootconf.h>
360Sstevel@tonic-gate #include <sys/conf.h>
370Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
380Sstevel@tonic-gate #include <sys/ddi_implfuncs.h>
390Sstevel@tonic-gate #include <sys/hwconf.h>
400Sstevel@tonic-gate #include <sys/instance.h>
410Sstevel@tonic-gate #include <sys/kmem.h>
420Sstevel@tonic-gate #include <sys/modctl.h>
430Sstevel@tonic-gate #include <sys/promif.h>
440Sstevel@tonic-gate #include <sys/sunndi.h>
450Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
460Sstevel@tonic-gate #include <sys/systeminfo.h>
470Sstevel@tonic-gate #include <sys/hwconf.h>
480Sstevel@tonic-gate #include <sys/sysevent_impl.h>
490Sstevel@tonic-gate #include <sys/sunldi_impl.h>
500Sstevel@tonic-gate #include <sys/disp.h>
510Sstevel@tonic-gate #include <sys/fm/util.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate extern dev_info_t *top_devinfo;
540Sstevel@tonic-gate extern dev_info_t *scsi_vhci_dip;
550Sstevel@tonic-gate extern struct hwc_class *hcl_head;
560Sstevel@tonic-gate static char *rootname;		/* node name of top_devinfo */
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * This lock must be held while updating devi_sibling pointers of
600Sstevel@tonic-gate  * rootnex immediate children
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate kmutex_t global_vhci_lock;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate major_t mm_major;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * Forward declarations
680Sstevel@tonic-gate  */
690Sstevel@tonic-gate static void impl_create_root_class(void);
700Sstevel@tonic-gate static void create_devinfo_tree(void);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #if defined(__x86)
730Sstevel@tonic-gate char *bootpath_prop = NULL;
740Sstevel@tonic-gate char *fstype_prop = NULL;
750Sstevel@tonic-gate #endif
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * Setup the DDI but don't necessarily init the DDI.  This will happen
790Sstevel@tonic-gate  * later once /boot is released.
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate void
820Sstevel@tonic-gate setup_ddi(void)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate 	impl_ddi_init_nodeid();
850Sstevel@tonic-gate 	impl_create_root_class();
860Sstevel@tonic-gate 	create_devinfo_tree();
870Sstevel@tonic-gate 	e_ddi_instance_init();
880Sstevel@tonic-gate 	impl_ddi_callback_init();
890Sstevel@tonic-gate 	log_event_init();
900Sstevel@tonic-gate 	fm_init();
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	(void) i_ddi_load_drvconf((major_t)-1);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	ldi_init();
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	i_ddi_devices_init();
970Sstevel@tonic-gate 	i_ddi_read_devices_files();
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /*
1010Sstevel@tonic-gate  * Perform setup actions post startup (i_ddi_io_initialized)
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate void
1040Sstevel@tonic-gate setup_ddi_poststartup(void)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	extern void i_ddi_start_flush_daemon(void);
1070Sstevel@tonic-gate 	extern void i_ddi_intr_redist_all_cpus(void);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	i_ddi_start_flush_daemon();
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	/*
1120Sstevel@tonic-gate 	 * For platforms that support INTR_WEIGHTED_DIST, we perform a
1130Sstevel@tonic-gate 	 * redistribution at this point (after NICs configured) so that
1140Sstevel@tonic-gate 	 * "isolation" relative to "ddi-intr-weight" occurs.
1150Sstevel@tonic-gate 	 */
1160Sstevel@tonic-gate 	i_ddi_intr_redist_all_cpus();
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * Create classes and major number bindings for the name of my root.
1210Sstevel@tonic-gate  * Called immediately before 'loadrootmodules'
1220Sstevel@tonic-gate  */
1230Sstevel@tonic-gate static void
1240Sstevel@tonic-gate impl_create_root_class(void)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate 	major_t major;
1270Sstevel@tonic-gate 	size_t size;
1280Sstevel@tonic-gate 	char *cp;
1290Sstevel@tonic-gate 	extern struct bootops *bootops;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	/*
1320Sstevel@tonic-gate 	 * The name for the root nexus is exactly as the manufacturer
1330Sstevel@tonic-gate 	 * placed it in the prom name property.  No translation.
1340Sstevel@tonic-gate 	 */
1350Sstevel@tonic-gate 	if ((major = ddi_name_to_major("rootnex")) == (major_t)-1)
1360Sstevel@tonic-gate 		panic("Couldn't find major number for 'rootnex'");
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	size = (size_t)BOP_GETPROPLEN(bootops, "mfg-name");
1390Sstevel@tonic-gate 	rootname = kmem_zalloc(size, KM_SLEEP);
1400Sstevel@tonic-gate 	(void) BOP_GETPROP(bootops, "mfg-name", rootname);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 * Fix conflict between OBP names and filesystem names.
1440Sstevel@tonic-gate 	 * Substitute '_' for '/' in the name.  Ick.  This is only
1450Sstevel@tonic-gate 	 * needed for the root node since '/' is not a legal name
1460Sstevel@tonic-gate 	 * character in an OBP device name.
1470Sstevel@tonic-gate 	 */
1480Sstevel@tonic-gate 	for (cp = rootname; *cp; cp++)
1490Sstevel@tonic-gate 		if (*cp == '/')
1500Sstevel@tonic-gate 			*cp = '_';
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	/*
1530Sstevel@tonic-gate 	 * Bind rootname to rootnex driver
1540Sstevel@tonic-gate 	 */
1550Sstevel@tonic-gate 	if (make_mbind(rootname, major, NULL, mb_hashtab) != 0) {
1560Sstevel@tonic-gate 		cmn_err(CE_WARN, "A driver or driver alias has already "
1570Sstevel@tonic-gate 		    "registered the name \"%s\".  The root nexus needs to "
1580Sstevel@tonic-gate 		    "use this name, and will override the existing entry. "
1590Sstevel@tonic-gate 		    "Please correct /etc/name_to_major and/or "
1600Sstevel@tonic-gate 		    "/etc/driver_aliases and reboot.", rootname);
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 		/*
1630Sstevel@tonic-gate 		 * Resort to the emergency measure of blowing away the
1640Sstevel@tonic-gate 		 * existing hash entry and replacing it with rootname's.
1650Sstevel@tonic-gate 		 */
1660Sstevel@tonic-gate 		delete_mbind(rootname, mb_hashtab);
1670Sstevel@tonic-gate 		if (make_mbind(rootname, major, NULL, mb_hashtab) != 0)
1680Sstevel@tonic-gate 			panic("mb_hashtab: inconsistent state.");
1690Sstevel@tonic-gate 	}
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	/*
1720Sstevel@tonic-gate 	 * The `platform' or `implementation architecture' name has been
1730Sstevel@tonic-gate 	 * translated by boot to be proper for file system use.  It is
1740Sstevel@tonic-gate 	 * the `name' of the platform actually booted.  Note the assumption
1750Sstevel@tonic-gate 	 * is that the name will `fit' in the buffer platform (which is
1760Sstevel@tonic-gate 	 * of size SYS_NMLN, which is far bigger than will actually ever
1770Sstevel@tonic-gate 	 * be needed).
1780Sstevel@tonic-gate 	 */
1790Sstevel@tonic-gate 	(void) BOP_GETPROP(bootops, "impl-arch-name", platform);
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #if defined(__x86)
1820Sstevel@tonic-gate 	/*
1830Sstevel@tonic-gate 	 * Retrieve and honor the bootpath and optional fstype properties
1840Sstevel@tonic-gate 	 */
1850Sstevel@tonic-gate 	size = (size_t)BOP_GETPROPLEN(bootops, "bootpath");
1860Sstevel@tonic-gate 	if (size != -1) {
1870Sstevel@tonic-gate 		bootpath_prop = kmem_zalloc(size, KM_SLEEP);
1880Sstevel@tonic-gate 		(void) BOP_GETPROP(bootops, "bootpath", bootpath_prop);
1890Sstevel@tonic-gate 		setbootpath(bootpath_prop);
1900Sstevel@tonic-gate 	}
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	size = (size_t)BOP_GETPROPLEN(bootops, "fstype");
1930Sstevel@tonic-gate 	if (size != -1) {
1940Sstevel@tonic-gate 		fstype_prop = kmem_zalloc(size, KM_SLEEP);
1950Sstevel@tonic-gate 		(void) BOP_GETPROP(bootops, "fstype", fstype_prop);
1960Sstevel@tonic-gate 		setbootfstype(fstype_prop);
1970Sstevel@tonic-gate 	}
1980Sstevel@tonic-gate #endif
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate /*
2020Sstevel@tonic-gate  * Note that this routine does not take into account the endianness
2030Sstevel@tonic-gate  * of the host or the device (or PROM) when retrieving properties.
2040Sstevel@tonic-gate  */
2050Sstevel@tonic-gate static int
2060Sstevel@tonic-gate getlongprop_buf(int id, char *name, char *buf, int maxlen)
2070Sstevel@tonic-gate {
2080Sstevel@tonic-gate 	int size;
2090Sstevel@tonic-gate 
210789Sahrens 	size = prom_getproplen((pnode_t)id, name);
2110Sstevel@tonic-gate 	if (size <= 0 || (size > maxlen - 1))
2120Sstevel@tonic-gate 		return (-1);
2130Sstevel@tonic-gate 
214789Sahrens 	if (-1 == prom_getprop((pnode_t)id, name, buf))
2150Sstevel@tonic-gate 		return (-1);
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	/*
2180Sstevel@tonic-gate 	 * Workaround for bugid 1085575 - OBP may return a "name" property
2190Sstevel@tonic-gate 	 * without null terminating the string with '\0'.  When this occurs,
2200Sstevel@tonic-gate 	 * append a '\0' and return (size + 1).
2210Sstevel@tonic-gate 	 */
2220Sstevel@tonic-gate 	if (strcmp("name", name) == 0) {
2230Sstevel@tonic-gate 		if (buf[size - 1] != '\0') {
2240Sstevel@tonic-gate 			buf[size] = '\0';
2250Sstevel@tonic-gate 			size += 1;
2260Sstevel@tonic-gate 		}
2270Sstevel@tonic-gate 	}
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 	return (size);
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate /*ARGSUSED1*/
2330Sstevel@tonic-gate static int
2340Sstevel@tonic-gate get_neighbors(dev_info_t *di, int flag)
2350Sstevel@tonic-gate {
2360Sstevel@tonic-gate 	register int nid, snid, cnid;
2370Sstevel@tonic-gate 	dev_info_t *parent;
2380Sstevel@tonic-gate 	char buf[OBP_MAXPROPNAME];
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	if (di == NULL)
2410Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	nid = ddi_get_nodeid(di);
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	snid = cnid = 0;
2460Sstevel@tonic-gate 	switch (flag) {
2470Sstevel@tonic-gate 		case DDI_WALK_PRUNESIB:
248789Sahrens 			cnid = (int)prom_childnode((pnode_t)nid);
2490Sstevel@tonic-gate 			break;
2500Sstevel@tonic-gate 		case DDI_WALK_PRUNECHILD:
251789Sahrens 			snid = (int)prom_nextnode((pnode_t)nid);
2520Sstevel@tonic-gate 			break;
2530Sstevel@tonic-gate 		case 0:
254789Sahrens 			snid = (int)prom_nextnode((pnode_t)nid);
255789Sahrens 			cnid = (int)prom_childnode((pnode_t)nid);
2560Sstevel@tonic-gate 			break;
2570Sstevel@tonic-gate 		default:
2580Sstevel@tonic-gate 			return (DDI_WALK_TERMINATE);
2590Sstevel@tonic-gate 	}
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate 	if (snid && (snid != -1) && ((parent = ddi_get_parent(di)) != NULL)) {
2630Sstevel@tonic-gate 		/*
2640Sstevel@tonic-gate 		 * add the first sibling that passes check_status()
2650Sstevel@tonic-gate 		 */
2660Sstevel@tonic-gate 		for (; snid && (snid != -1);
267789Sahrens 		    snid = (int)prom_nextnode((pnode_t)snid)) {
2680Sstevel@tonic-gate 			if (getlongprop_buf(snid, OBP_NAME, buf,
2690Sstevel@tonic-gate 			    sizeof (buf)) > 0) {
2700Sstevel@tonic-gate 				if (check_status(snid, buf, parent) ==
2710Sstevel@tonic-gate 				    DDI_SUCCESS) {
2720Sstevel@tonic-gate 					(void) ddi_add_child(parent, buf,
2730Sstevel@tonic-gate 					    snid, -1);
2740Sstevel@tonic-gate 					break;
2750Sstevel@tonic-gate 				}
2760Sstevel@tonic-gate 			}
2770Sstevel@tonic-gate 		}
2780Sstevel@tonic-gate 	}
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 	if (cnid && (cnid != -1)) {
2810Sstevel@tonic-gate 		/*
2820Sstevel@tonic-gate 		 * add the first child that passes check_status()
2830Sstevel@tonic-gate 		 */
2840Sstevel@tonic-gate 		if (getlongprop_buf(cnid, OBP_NAME, buf, sizeof (buf)) > 0) {
2850Sstevel@tonic-gate 			if (check_status(cnid, buf, di) == DDI_SUCCESS) {
2860Sstevel@tonic-gate 				(void) ddi_add_child(di, buf, cnid, -1);
2870Sstevel@tonic-gate 			} else {
288789Sahrens 				for (cnid = (int)prom_nextnode((pnode_t)cnid);
2890Sstevel@tonic-gate 				    cnid && (cnid != -1);
290789Sahrens 				    cnid = (int)prom_nextnode((pnode_t)cnid)) {
2910Sstevel@tonic-gate 					if (getlongprop_buf(cnid, OBP_NAME,
2920Sstevel@tonic-gate 					    buf, sizeof (buf)) > 0) {
2930Sstevel@tonic-gate 						if (check_status(cnid, buf, di)
2940Sstevel@tonic-gate 						    == DDI_SUCCESS) {
2950Sstevel@tonic-gate 							(void) ddi_add_child(
2960Sstevel@tonic-gate 							    di, buf, cnid, -1);
2970Sstevel@tonic-gate 							break;
2980Sstevel@tonic-gate 						}
2990Sstevel@tonic-gate 					}
3000Sstevel@tonic-gate 				}
3010Sstevel@tonic-gate 			}
3020Sstevel@tonic-gate 		}
3030Sstevel@tonic-gate 	}
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	return (DDI_WALK_CONTINUE);
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate static void
3090Sstevel@tonic-gate di_dfs(dev_info_t *devi, int (*f)(dev_info_t *, int), caddr_t arg)
3100Sstevel@tonic-gate {
3110Sstevel@tonic-gate 	(void) (*f)(devi, 0);
3120Sstevel@tonic-gate 	if (devi) {
3130Sstevel@tonic-gate 		di_dfs((dev_info_t *)DEVI(devi)->devi_child, f, arg);
3140Sstevel@tonic-gate 		di_dfs((dev_info_t *)DEVI(devi)->devi_sibling, f, arg);
3150Sstevel@tonic-gate 	}
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate dev_info_t *
3190Sstevel@tonic-gate i_ddi_create_branch(dev_info_t *pdip, int nid)
3200Sstevel@tonic-gate {
3210Sstevel@tonic-gate 	char *buf;
3220Sstevel@tonic-gate 	dev_info_t *dip = NULL;
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 	if (pdip == NULL || nid == OBP_NONODE || nid == OBP_BADNODE)
3250Sstevel@tonic-gate 		return (NULL);
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 	buf = kmem_alloc(OBP_MAXPROPNAME, KM_SLEEP);
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 	if (getlongprop_buf(nid, OBP_NAME, buf, OBP_MAXPROPNAME) > 0) {
3300Sstevel@tonic-gate 		if (check_status(nid, buf, pdip) == DDI_SUCCESS)
3310Sstevel@tonic-gate 			dip = ddi_add_child(pdip, buf, nid, -1);
3320Sstevel@tonic-gate 	}
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	kmem_free(buf, OBP_MAXPROPNAME);
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	if (dip == NULL)
3370Sstevel@tonic-gate 		return (NULL);
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	/*
3400Sstevel@tonic-gate 	 * Don't create any siblings of the branch root, just
3410Sstevel@tonic-gate 	 * children.
3420Sstevel@tonic-gate 	 */
3430Sstevel@tonic-gate 	(void) get_neighbors(dip, DDI_WALK_PRUNESIB);
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 	di_dfs(ddi_get_child(dip), get_neighbors, 0);
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	return (dip);
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate static void
3510Sstevel@tonic-gate create_devinfo_tree(void)
3520Sstevel@tonic-gate {
3530Sstevel@tonic-gate 	major_t major;
354789Sahrens 	pnode_t nodeid;
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	i_ddi_node_cache_init();
3570Sstevel@tonic-gate #if defined(__sparc)
3580Sstevel@tonic-gate 	nodeid = prom_nextnode(0);
3590Sstevel@tonic-gate #else /* x86 */
3600Sstevel@tonic-gate 	nodeid = DEVI_SID_NODEID;
3610Sstevel@tonic-gate #endif
3620Sstevel@tonic-gate 	top_devinfo = i_ddi_alloc_node(NULL, rootname,
3630Sstevel@tonic-gate 	    nodeid, -1, NULL, KM_SLEEP);
3640Sstevel@tonic-gate 	ndi_hold_devi(top_devinfo);	/* never release the root */
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	i_ddi_add_devimap(top_devinfo);
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	/*
3690Sstevel@tonic-gate 	 * Bind root node.
3700Sstevel@tonic-gate 	 * This code is special because root node has no parent
3710Sstevel@tonic-gate 	 */
3720Sstevel@tonic-gate 	major = ddi_name_to_major("rootnex");
3730Sstevel@tonic-gate 	ASSERT(major != (major_t)-1);
3740Sstevel@tonic-gate 	DEVI(top_devinfo)->devi_major = major;
3750Sstevel@tonic-gate 	devnamesp[major].dn_head = top_devinfo;
3760Sstevel@tonic-gate 	i_ddi_set_binding_name(top_devinfo, rootname);
3770Sstevel@tonic-gate 	i_ddi_set_node_state(top_devinfo, DS_BOUND);
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 	/*
3800Sstevel@tonic-gate 	 * Record that devinfos have been made for "rootnex."
3810Sstevel@tonic-gate 	 * di_dfs() is used to read the prom because it doesn't get the
3820Sstevel@tonic-gate 	 * next sibling until the function returns, unlike ddi_walk_devs().
3830Sstevel@tonic-gate 	 */
3840Sstevel@tonic-gate 	di_dfs(ddi_root_node(), get_neighbors, 0);
385851Sszhou 
386851Sszhou #if !defined(__sparc)
387851Sszhou 	/*
388851Sszhou 	 * On x86, there is no prom. Create device tree by
389851Sszhou 	 * probing pci config space
390851Sszhou 	 */
391851Sszhou 	{
392851Sszhou 		extern void impl_setup_ddi(void);
393851Sszhou 		impl_setup_ddi();
394851Sszhou 	}
395851Sszhou #endif /* x86 */
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * Init and attach the root node. root node is the first one to be
4000Sstevel@tonic-gate  * attached, so the process is somewhat "handcrafted".
4010Sstevel@tonic-gate  */
4020Sstevel@tonic-gate void
4030Sstevel@tonic-gate i_ddi_init_root()
4040Sstevel@tonic-gate {
4050Sstevel@tonic-gate #ifdef  DDI_PROP_DEBUG
4060Sstevel@tonic-gate 	(void) ddi_prop_debug(1);	/* Enable property debugging */
4070Sstevel@tonic-gate #endif  /* DDI_PROP_DEBUG */
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate 	/*
4100Sstevel@tonic-gate 	 * Initialize root node
4110Sstevel@tonic-gate 	 */
4120Sstevel@tonic-gate 	if (impl_ddi_sunbus_initchild(top_devinfo) != DDI_SUCCESS)
4130Sstevel@tonic-gate 		panic("Could not initialize root nexus");
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate 	/*
4160Sstevel@tonic-gate 	 * Attach root node (no need to probe)
4170Sstevel@tonic-gate 	 * Hold both devinfo and rootnex driver so they can't go away.
4180Sstevel@tonic-gate 	 */
4190Sstevel@tonic-gate 	DEVI(top_devinfo)->devi_ops = ndi_hold_driver(top_devinfo);
4200Sstevel@tonic-gate 	ASSERT(DEV_OPS_HELD(DEVI(top_devinfo)->devi_ops));
4210Sstevel@tonic-gate 	DEVI(top_devinfo)->devi_instance = e_ddi_assign_instance(top_devinfo);
4220Sstevel@tonic-gate 
423495Scth 	mutex_enter(&(DEVI(top_devinfo)->devi_lock));
4240Sstevel@tonic-gate 	DEVI_SET_ATTACHING(top_devinfo);
425495Scth 	mutex_exit(&(DEVI(top_devinfo)->devi_lock));
426495Scth 
4270Sstevel@tonic-gate 	if (devi_attach(top_devinfo, DDI_ATTACH) != DDI_SUCCESS)
4280Sstevel@tonic-gate 		panic("Could not attach root nexus");
429495Scth 
430495Scth 	mutex_enter(&(DEVI(top_devinfo)->devi_lock));
4310Sstevel@tonic-gate 	DEVI_CLR_ATTACHING(top_devinfo);
432495Scth 	mutex_exit(&(DEVI(top_devinfo)->devi_lock));
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 	mutex_init(&global_vhci_lock, NULL, MUTEX_DEFAULT, NULL);
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate 	ndi_hold_devi(top_devinfo);	/* hold it forever */
4370Sstevel@tonic-gate 	i_ddi_set_node_state(top_devinfo, DS_READY);
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	/*
4400Sstevel@tonic-gate 	 * Now, expand .conf children of root
4410Sstevel@tonic-gate 	 */
4420Sstevel@tonic-gate 	(void) i_ndi_make_spec_children(top_devinfo, 0);
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate 	/*
4450Sstevel@tonic-gate 	 * Must be set up before attaching root or pseudo drivers
4460Sstevel@tonic-gate 	 */
4470Sstevel@tonic-gate 	pm_init_locks();
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	/*
4500Sstevel@tonic-gate 	 * Attach options dip
4510Sstevel@tonic-gate 	 */
4520Sstevel@tonic-gate 	options_dip = i_ddi_attach_pseudo_node("options");
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 	/*
4550Sstevel@tonic-gate 	 * Attach pseudo nexus and enumerate its children
4560Sstevel@tonic-gate 	 */
4570Sstevel@tonic-gate 	pseudo_dip = i_ddi_attach_pseudo_node(DEVI_PSEUDO_NEXNAME);
4580Sstevel@tonic-gate 	(void) i_ndi_make_spec_children(pseudo_dip, 0);
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 	/*
4610Sstevel@tonic-gate 	 * Attach and hold clone dip
4620Sstevel@tonic-gate 	 */
4630Sstevel@tonic-gate 	clone_dip = i_ddi_attach_pseudo_node("clone");
4640Sstevel@tonic-gate 	clone_major = ddi_driver_major(clone_dip);
4650Sstevel@tonic-gate 	mm_major = ddi_name_to_major("mm");
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	/*
4680Sstevel@tonic-gate 	 * Attach scsi_vhci for MPXIO, this registers scsi vhci class
4690Sstevel@tonic-gate 	 * with the MPXIO framework.
4700Sstevel@tonic-gate 	 */
4710Sstevel@tonic-gate 	scsi_vhci_dip = i_ddi_attach_pseudo_node("scsi_vhci");
4720Sstevel@tonic-gate }
473