xref: /onnv-gate/usr/src/uts/common/os/autoconf.c (revision 8561:14b63022c7d9)
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
54145Scth  * Common Development and Distribution License (the "License").
64145Scth  * 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*8561SScott.Carter@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * This file contains ddi functions needed during boot and DR.
280Sstevel@tonic-gate  * Many functions in swapgeneric.c can be moved here.
290Sstevel@tonic-gate  *
300Sstevel@tonic-gate  * The object file is currently linked into unix.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/bootconf.h>
340Sstevel@tonic-gate #include <sys/conf.h>
350Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
360Sstevel@tonic-gate #include <sys/ddi_implfuncs.h>
370Sstevel@tonic-gate #include <sys/hwconf.h>
380Sstevel@tonic-gate #include <sys/instance.h>
390Sstevel@tonic-gate #include <sys/kmem.h>
400Sstevel@tonic-gate #include <sys/modctl.h>
410Sstevel@tonic-gate #include <sys/promif.h>
420Sstevel@tonic-gate #include <sys/sunndi.h>
430Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
440Sstevel@tonic-gate #include <sys/systeminfo.h>
450Sstevel@tonic-gate #include <sys/hwconf.h>
460Sstevel@tonic-gate #include <sys/sysevent_impl.h>
470Sstevel@tonic-gate #include <sys/sunldi_impl.h>
480Sstevel@tonic-gate #include <sys/disp.h>
495648Ssetje #include <sys/bootconf.h>
500Sstevel@tonic-gate #include <sys/fm/util.h>
517931SSean.Ye@Sun.COM #include <sys/ddifm_impl.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;
658011SChris.Horne@Sun.COM major_t	nulldriver_major;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * Forward declarations
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate static void impl_create_root_class(void);
710Sstevel@tonic-gate static void create_devinfo_tree(void);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #if defined(__x86)
740Sstevel@tonic-gate char *bootpath_prop = NULL;
750Sstevel@tonic-gate char *fstype_prop = NULL;
760Sstevel@tonic-gate #endif
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * Setup the DDI but don't necessarily init the DDI.  This will happen
800Sstevel@tonic-gate  * later once /boot is released.
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate void
setup_ddi(void)830Sstevel@tonic-gate setup_ddi(void)
840Sstevel@tonic-gate {
850Sstevel@tonic-gate 	impl_ddi_init_nodeid();
860Sstevel@tonic-gate 	impl_create_root_class();
870Sstevel@tonic-gate 	create_devinfo_tree();
880Sstevel@tonic-gate 	e_ddi_instance_init();
890Sstevel@tonic-gate 	impl_ddi_callback_init();
900Sstevel@tonic-gate 	log_event_init();
910Sstevel@tonic-gate 	fm_init();
927931SSean.Ye@Sun.COM 	ndi_fm_init();
93*8561SScott.Carter@Sun.COM 	irm_init();
940Sstevel@tonic-gate 
957009Scth 	(void) i_ddi_load_drvconf(DDI_MAJOR_T_NONE);
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	ldi_init();
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	i_ddi_devices_init();
1000Sstevel@tonic-gate 	i_ddi_read_devices_files();
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * Perform setup actions post startup (i_ddi_io_initialized)
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate void
setup_ddi_poststartup(void)1070Sstevel@tonic-gate setup_ddi_poststartup(void)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	extern void i_ddi_start_flush_daemon(void);
110*8561SScott.Carter@Sun.COM 	extern void i_ddi_irm_poststartup(void);
1110Sstevel@tonic-gate 	extern void i_ddi_intr_redist_all_cpus(void);
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	i_ddi_start_flush_daemon();
1140Sstevel@tonic-gate 
115*8561SScott.Carter@Sun.COM 	/* Startup Interrupt Resource Management (IRM) */
116*8561SScott.Carter@Sun.COM 	i_ddi_irm_poststartup();
117*8561SScott.Carter@Sun.COM 
1180Sstevel@tonic-gate 	/*
1190Sstevel@tonic-gate 	 * For platforms that support INTR_WEIGHTED_DIST, we perform a
1200Sstevel@tonic-gate 	 * redistribution at this point (after NICs configured) so that
1210Sstevel@tonic-gate 	 * "isolation" relative to "ddi-intr-weight" occurs.
1220Sstevel@tonic-gate 	 */
1230Sstevel@tonic-gate 	i_ddi_intr_redist_all_cpus();
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * Create classes and major number bindings for the name of my root.
1280Sstevel@tonic-gate  * Called immediately before 'loadrootmodules'
1290Sstevel@tonic-gate  */
1300Sstevel@tonic-gate static void
impl_create_root_class(void)1310Sstevel@tonic-gate impl_create_root_class(void)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	major_t major;
1340Sstevel@tonic-gate 	size_t size;
1350Sstevel@tonic-gate 	char *cp;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/*
1380Sstevel@tonic-gate 	 * The name for the root nexus is exactly as the manufacturer
1390Sstevel@tonic-gate 	 * placed it in the prom name property.  No translation.
1400Sstevel@tonic-gate 	 */
1417009Scth 	if ((major = ddi_name_to_major("rootnex")) == DDI_MAJOR_T_NONE)
1420Sstevel@tonic-gate 		panic("Couldn't find major number for 'rootnex'");
1430Sstevel@tonic-gate 
1446582Ssetje 	/*
1456582Ssetje 	 * C OBP (Serengeti) does not include the NULL when returning
1466582Ssetje 	 * the length of the name property, while this violates 1275,
1476582Ssetje 	 * Solaris needs to work around this by allocating space for
1486582Ssetje 	 * an extra character.
1496582Ssetje 	 */
1506582Ssetje 	size = (size_t)BOP_GETPROPLEN(bootops, "mfg-name") + 1;
1510Sstevel@tonic-gate 	rootname = kmem_zalloc(size, KM_SLEEP);
1520Sstevel@tonic-gate 	(void) BOP_GETPROP(bootops, "mfg-name", rootname);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	/*
1550Sstevel@tonic-gate 	 * Fix conflict between OBP names and filesystem names.
1560Sstevel@tonic-gate 	 * Substitute '_' for '/' in the name.  Ick.  This is only
1570Sstevel@tonic-gate 	 * needed for the root node since '/' is not a legal name
1580Sstevel@tonic-gate 	 * character in an OBP device name.
1590Sstevel@tonic-gate 	 */
1600Sstevel@tonic-gate 	for (cp = rootname; *cp; cp++)
1610Sstevel@tonic-gate 		if (*cp == '/')
1620Sstevel@tonic-gate 			*cp = '_';
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	/*
1650Sstevel@tonic-gate 	 * Bind rootname to rootnex driver
1660Sstevel@tonic-gate 	 */
1670Sstevel@tonic-gate 	if (make_mbind(rootname, major, NULL, mb_hashtab) != 0) {
1680Sstevel@tonic-gate 		cmn_err(CE_WARN, "A driver or driver alias has already "
1690Sstevel@tonic-gate 		    "registered the name \"%s\".  The root nexus needs to "
1700Sstevel@tonic-gate 		    "use this name, and will override the existing entry. "
1710Sstevel@tonic-gate 		    "Please correct /etc/name_to_major and/or "
1720Sstevel@tonic-gate 		    "/etc/driver_aliases and reboot.", rootname);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 		/*
1750Sstevel@tonic-gate 		 * Resort to the emergency measure of blowing away the
1760Sstevel@tonic-gate 		 * existing hash entry and replacing it with rootname's.
1770Sstevel@tonic-gate 		 */
1780Sstevel@tonic-gate 		delete_mbind(rootname, mb_hashtab);
1790Sstevel@tonic-gate 		if (make_mbind(rootname, major, NULL, mb_hashtab) != 0)
1800Sstevel@tonic-gate 			panic("mb_hashtab: inconsistent state.");
1810Sstevel@tonic-gate 	}
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 	/*
1840Sstevel@tonic-gate 	 * The `platform' or `implementation architecture' name has been
1850Sstevel@tonic-gate 	 * translated by boot to be proper for file system use.  It is
1860Sstevel@tonic-gate 	 * the `name' of the platform actually booted.  Note the assumption
1870Sstevel@tonic-gate 	 * is that the name will `fit' in the buffer platform (which is
1880Sstevel@tonic-gate 	 * of size SYS_NMLN, which is far bigger than will actually ever
1890Sstevel@tonic-gate 	 * be needed).
1900Sstevel@tonic-gate 	 */
1910Sstevel@tonic-gate 	(void) BOP_GETPROP(bootops, "impl-arch-name", platform);
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #if defined(__x86)
1940Sstevel@tonic-gate 	/*
1950Sstevel@tonic-gate 	 * Retrieve and honor the bootpath and optional fstype properties
1960Sstevel@tonic-gate 	 */
1970Sstevel@tonic-gate 	size = (size_t)BOP_GETPROPLEN(bootops, "bootpath");
1980Sstevel@tonic-gate 	if (size != -1) {
1990Sstevel@tonic-gate 		bootpath_prop = kmem_zalloc(size, KM_SLEEP);
2000Sstevel@tonic-gate 		(void) BOP_GETPROP(bootops, "bootpath", bootpath_prop);
2010Sstevel@tonic-gate 		setbootpath(bootpath_prop);
2020Sstevel@tonic-gate 	}
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	size = (size_t)BOP_GETPROPLEN(bootops, "fstype");
2050Sstevel@tonic-gate 	if (size != -1) {
2060Sstevel@tonic-gate 		fstype_prop = kmem_zalloc(size, KM_SLEEP);
2070Sstevel@tonic-gate 		(void) BOP_GETPROP(bootops, "fstype", fstype_prop);
2080Sstevel@tonic-gate 		setbootfstype(fstype_prop);
2090Sstevel@tonic-gate 	}
2100Sstevel@tonic-gate #endif
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate /*
2140Sstevel@tonic-gate  * Note that this routine does not take into account the endianness
2150Sstevel@tonic-gate  * of the host or the device (or PROM) when retrieving properties.
2160Sstevel@tonic-gate  */
2170Sstevel@tonic-gate static int
getlongprop_buf(int id,char * name,char * buf,int maxlen)2180Sstevel@tonic-gate getlongprop_buf(int id, char *name, char *buf, int maxlen)
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate 	int size;
2210Sstevel@tonic-gate 
222789Sahrens 	size = prom_getproplen((pnode_t)id, name);
2230Sstevel@tonic-gate 	if (size <= 0 || (size > maxlen - 1))
2240Sstevel@tonic-gate 		return (-1);
2250Sstevel@tonic-gate 
226789Sahrens 	if (-1 == prom_getprop((pnode_t)id, name, buf))
2270Sstevel@tonic-gate 		return (-1);
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 	/*
2300Sstevel@tonic-gate 	 * Workaround for bugid 1085575 - OBP may return a "name" property
2310Sstevel@tonic-gate 	 * without null terminating the string with '\0'.  When this occurs,
2320Sstevel@tonic-gate 	 * append a '\0' and return (size + 1).
2330Sstevel@tonic-gate 	 */
2340Sstevel@tonic-gate 	if (strcmp("name", name) == 0) {
2350Sstevel@tonic-gate 		if (buf[size - 1] != '\0') {
2360Sstevel@tonic-gate 			buf[size] = '\0';
2370Sstevel@tonic-gate 			size += 1;
2380Sstevel@tonic-gate 		}
2390Sstevel@tonic-gate 	}
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	return (size);
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate /*ARGSUSED1*/
2450Sstevel@tonic-gate static int
get_neighbors(dev_info_t * di,int flag)2460Sstevel@tonic-gate get_neighbors(dev_info_t *di, int flag)
2470Sstevel@tonic-gate {
2480Sstevel@tonic-gate 	register int nid, snid, cnid;
2490Sstevel@tonic-gate 	dev_info_t *parent;
2500Sstevel@tonic-gate 	char buf[OBP_MAXPROPNAME];
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 	if (di == NULL)
2530Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	nid = ddi_get_nodeid(di);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	snid = cnid = 0;
2580Sstevel@tonic-gate 	switch (flag) {
2590Sstevel@tonic-gate 		case DDI_WALK_PRUNESIB:
260789Sahrens 			cnid = (int)prom_childnode((pnode_t)nid);
2610Sstevel@tonic-gate 			break;
2620Sstevel@tonic-gate 		case DDI_WALK_PRUNECHILD:
263789Sahrens 			snid = (int)prom_nextnode((pnode_t)nid);
2640Sstevel@tonic-gate 			break;
2650Sstevel@tonic-gate 		case 0:
266789Sahrens 			snid = (int)prom_nextnode((pnode_t)nid);
267789Sahrens 			cnid = (int)prom_childnode((pnode_t)nid);
2680Sstevel@tonic-gate 			break;
2690Sstevel@tonic-gate 		default:
2700Sstevel@tonic-gate 			return (DDI_WALK_TERMINATE);
2710Sstevel@tonic-gate 	}
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate 	if (snid && (snid != -1) && ((parent = ddi_get_parent(di)) != NULL)) {
2750Sstevel@tonic-gate 		/*
2760Sstevel@tonic-gate 		 * add the first sibling that passes check_status()
2770Sstevel@tonic-gate 		 */
2780Sstevel@tonic-gate 		for (; snid && (snid != -1);
279789Sahrens 		    snid = (int)prom_nextnode((pnode_t)snid)) {
2800Sstevel@tonic-gate 			if (getlongprop_buf(snid, OBP_NAME, buf,
2810Sstevel@tonic-gate 			    sizeof (buf)) > 0) {
2820Sstevel@tonic-gate 				if (check_status(snid, buf, parent) ==
2830Sstevel@tonic-gate 				    DDI_SUCCESS) {
2840Sstevel@tonic-gate 					(void) ddi_add_child(parent, buf,
2850Sstevel@tonic-gate 					    snid, -1);
2860Sstevel@tonic-gate 					break;
2870Sstevel@tonic-gate 				}
2880Sstevel@tonic-gate 			}
2890Sstevel@tonic-gate 		}
2900Sstevel@tonic-gate 	}
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 	if (cnid && (cnid != -1)) {
2930Sstevel@tonic-gate 		/*
2940Sstevel@tonic-gate 		 * add the first child that passes check_status()
2950Sstevel@tonic-gate 		 */
2960Sstevel@tonic-gate 		if (getlongprop_buf(cnid, OBP_NAME, buf, sizeof (buf)) > 0) {
2970Sstevel@tonic-gate 			if (check_status(cnid, buf, di) == DDI_SUCCESS) {
2980Sstevel@tonic-gate 				(void) ddi_add_child(di, buf, cnid, -1);
2990Sstevel@tonic-gate 			} else {
300789Sahrens 				for (cnid = (int)prom_nextnode((pnode_t)cnid);
3010Sstevel@tonic-gate 				    cnid && (cnid != -1);
302789Sahrens 				    cnid = (int)prom_nextnode((pnode_t)cnid)) {
3030Sstevel@tonic-gate 					if (getlongprop_buf(cnid, OBP_NAME,
3040Sstevel@tonic-gate 					    buf, sizeof (buf)) > 0) {
3050Sstevel@tonic-gate 						if (check_status(cnid, buf, di)
3060Sstevel@tonic-gate 						    == DDI_SUCCESS) {
3070Sstevel@tonic-gate 							(void) ddi_add_child(
3080Sstevel@tonic-gate 							    di, buf, cnid, -1);
3090Sstevel@tonic-gate 							break;
3100Sstevel@tonic-gate 						}
3110Sstevel@tonic-gate 					}
3120Sstevel@tonic-gate 				}
3130Sstevel@tonic-gate 			}
3140Sstevel@tonic-gate 		}
3150Sstevel@tonic-gate 	}
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 	return (DDI_WALK_CONTINUE);
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate static void
di_dfs(dev_info_t * devi,int (* f)(dev_info_t *,int),caddr_t arg)3210Sstevel@tonic-gate di_dfs(dev_info_t *devi, int (*f)(dev_info_t *, int), caddr_t arg)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate 	(void) (*f)(devi, 0);
3240Sstevel@tonic-gate 	if (devi) {
3250Sstevel@tonic-gate 		di_dfs((dev_info_t *)DEVI(devi)->devi_child, f, arg);
3260Sstevel@tonic-gate 		di_dfs((dev_info_t *)DEVI(devi)->devi_sibling, f, arg);
3270Sstevel@tonic-gate 	}
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate dev_info_t *
i_ddi_create_branch(dev_info_t * pdip,int nid)3310Sstevel@tonic-gate i_ddi_create_branch(dev_info_t *pdip, int nid)
3320Sstevel@tonic-gate {
3330Sstevel@tonic-gate 	char *buf;
3340Sstevel@tonic-gate 	dev_info_t *dip = NULL;
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	if (pdip == NULL || nid == OBP_NONODE || nid == OBP_BADNODE)
3370Sstevel@tonic-gate 		return (NULL);
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	buf = kmem_alloc(OBP_MAXPROPNAME, KM_SLEEP);
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 	if (getlongprop_buf(nid, OBP_NAME, buf, OBP_MAXPROPNAME) > 0) {
3420Sstevel@tonic-gate 		if (check_status(nid, buf, pdip) == DDI_SUCCESS)
3430Sstevel@tonic-gate 			dip = ddi_add_child(pdip, buf, nid, -1);
3440Sstevel@tonic-gate 	}
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	kmem_free(buf, OBP_MAXPROPNAME);
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate 	if (dip == NULL)
3490Sstevel@tonic-gate 		return (NULL);
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	/*
3520Sstevel@tonic-gate 	 * Don't create any siblings of the branch root, just
3530Sstevel@tonic-gate 	 * children.
3540Sstevel@tonic-gate 	 */
3550Sstevel@tonic-gate 	(void) get_neighbors(dip, DDI_WALK_PRUNESIB);
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	di_dfs(ddi_get_child(dip), get_neighbors, 0);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	return (dip);
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate static void
create_devinfo_tree(void)3630Sstevel@tonic-gate create_devinfo_tree(void)
3640Sstevel@tonic-gate {
3650Sstevel@tonic-gate 	major_t major;
366789Sahrens 	pnode_t nodeid;
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	i_ddi_node_cache_init();
3690Sstevel@tonic-gate #if defined(__sparc)
3700Sstevel@tonic-gate 	nodeid = prom_nextnode(0);
3710Sstevel@tonic-gate #else /* x86 */
3720Sstevel@tonic-gate 	nodeid = DEVI_SID_NODEID;
3730Sstevel@tonic-gate #endif
3740Sstevel@tonic-gate 	top_devinfo = i_ddi_alloc_node(NULL, rootname,
3750Sstevel@tonic-gate 	    nodeid, -1, NULL, KM_SLEEP);
3760Sstevel@tonic-gate 	ndi_hold_devi(top_devinfo);	/* never release the root */
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	i_ddi_add_devimap(top_devinfo);
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	/*
3810Sstevel@tonic-gate 	 * Bind root node.
3820Sstevel@tonic-gate 	 * This code is special because root node has no parent
3830Sstevel@tonic-gate 	 */
3840Sstevel@tonic-gate 	major = ddi_name_to_major("rootnex");
3857009Scth 	ASSERT(major != DDI_MAJOR_T_NONE);
3860Sstevel@tonic-gate 	DEVI(top_devinfo)->devi_major = major;
3870Sstevel@tonic-gate 	devnamesp[major].dn_head = top_devinfo;
3880Sstevel@tonic-gate 	i_ddi_set_binding_name(top_devinfo, rootname);
3890Sstevel@tonic-gate 	i_ddi_set_node_state(top_devinfo, DS_BOUND);
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 	/*
3920Sstevel@tonic-gate 	 * Record that devinfos have been made for "rootnex."
3930Sstevel@tonic-gate 	 * di_dfs() is used to read the prom because it doesn't get the
3940Sstevel@tonic-gate 	 * next sibling until the function returns, unlike ddi_walk_devs().
3950Sstevel@tonic-gate 	 */
3960Sstevel@tonic-gate 	di_dfs(ddi_root_node(), get_neighbors, 0);
397851Sszhou 
398851Sszhou #if !defined(__sparc)
399851Sszhou 	/*
400851Sszhou 	 * On x86, there is no prom. Create device tree by
401851Sszhou 	 * probing pci config space
402851Sszhou 	 */
403851Sszhou 	{
404851Sszhou 		extern void impl_setup_ddi(void);
405851Sszhou 		impl_setup_ddi();
406851Sszhou 	}
407851Sszhou #endif /* x86 */
4080Sstevel@tonic-gate }
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate /*
4110Sstevel@tonic-gate  * Init and attach the root node. root node is the first one to be
4120Sstevel@tonic-gate  * attached, so the process is somewhat "handcrafted".
4130Sstevel@tonic-gate  */
4140Sstevel@tonic-gate void
i_ddi_init_root()4150Sstevel@tonic-gate i_ddi_init_root()
4160Sstevel@tonic-gate {
4170Sstevel@tonic-gate #ifdef  DDI_PROP_DEBUG
4180Sstevel@tonic-gate 	(void) ddi_prop_debug(1);	/* Enable property debugging */
4190Sstevel@tonic-gate #endif  /* DDI_PROP_DEBUG */
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 	/*
4220Sstevel@tonic-gate 	 * Initialize root node
4230Sstevel@tonic-gate 	 */
4240Sstevel@tonic-gate 	if (impl_ddi_sunbus_initchild(top_devinfo) != DDI_SUCCESS)
4250Sstevel@tonic-gate 		panic("Could not initialize root nexus");
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate 	/*
4280Sstevel@tonic-gate 	 * Attach root node (no need to probe)
4290Sstevel@tonic-gate 	 * Hold both devinfo and rootnex driver so they can't go away.
4300Sstevel@tonic-gate 	 */
4310Sstevel@tonic-gate 	DEVI(top_devinfo)->devi_ops = ndi_hold_driver(top_devinfo);
4320Sstevel@tonic-gate 	ASSERT(DEV_OPS_HELD(DEVI(top_devinfo)->devi_ops));
4330Sstevel@tonic-gate 	DEVI(top_devinfo)->devi_instance = e_ddi_assign_instance(top_devinfo);
4340Sstevel@tonic-gate 
4358371SVikram.Hegde@Sun.COM 	(void) i_ddi_load_drvconf(DEVI(top_devinfo)->devi_major);
4368371SVikram.Hegde@Sun.COM 
437495Scth 	mutex_enter(&(DEVI(top_devinfo)->devi_lock));
4380Sstevel@tonic-gate 	DEVI_SET_ATTACHING(top_devinfo);
439495Scth 	mutex_exit(&(DEVI(top_devinfo)->devi_lock));
440495Scth 
4410Sstevel@tonic-gate 	if (devi_attach(top_devinfo, DDI_ATTACH) != DDI_SUCCESS)
4420Sstevel@tonic-gate 		panic("Could not attach root nexus");
443495Scth 
444495Scth 	mutex_enter(&(DEVI(top_devinfo)->devi_lock));
4450Sstevel@tonic-gate 	DEVI_CLR_ATTACHING(top_devinfo);
446495Scth 	mutex_exit(&(DEVI(top_devinfo)->devi_lock));
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	mutex_init(&global_vhci_lock, NULL, MUTEX_DEFAULT, NULL);
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	ndi_hold_devi(top_devinfo);	/* hold it forever */
4510Sstevel@tonic-gate 	i_ddi_set_node_state(top_devinfo, DS_READY);
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate 	/*
4540Sstevel@tonic-gate 	 * Now, expand .conf children of root
4550Sstevel@tonic-gate 	 */
4560Sstevel@tonic-gate 	(void) i_ndi_make_spec_children(top_devinfo, 0);
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 	/*
4590Sstevel@tonic-gate 	 * Must be set up before attaching root or pseudo drivers
4600Sstevel@tonic-gate 	 */
4610Sstevel@tonic-gate 	pm_init_locks();
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate 	/*
4640Sstevel@tonic-gate 	 * Attach options dip
4650Sstevel@tonic-gate 	 */
4660Sstevel@tonic-gate 	options_dip = i_ddi_attach_pseudo_node("options");
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	/*
4690Sstevel@tonic-gate 	 * Attach pseudo nexus and enumerate its children
4700Sstevel@tonic-gate 	 */
4710Sstevel@tonic-gate 	pseudo_dip = i_ddi_attach_pseudo_node(DEVI_PSEUDO_NEXNAME);
4720Sstevel@tonic-gate 	(void) i_ndi_make_spec_children(pseudo_dip, 0);
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate 	/*
4750Sstevel@tonic-gate 	 * Attach and hold clone dip
4760Sstevel@tonic-gate 	 */
4770Sstevel@tonic-gate 	clone_dip = i_ddi_attach_pseudo_node("clone");
4780Sstevel@tonic-gate 	clone_major = ddi_driver_major(clone_dip);
4790Sstevel@tonic-gate 	mm_major = ddi_name_to_major("mm");
4808011SChris.Horne@Sun.COM 	nulldriver_major = ddi_name_to_major("nulldriver");
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate 	/*
4830Sstevel@tonic-gate 	 * Attach scsi_vhci for MPXIO, this registers scsi vhci class
4840Sstevel@tonic-gate 	 * with the MPXIO framework.
4850Sstevel@tonic-gate 	 */
4860Sstevel@tonic-gate 	scsi_vhci_dip = i_ddi_attach_pseudo_node("scsi_vhci");
4870Sstevel@tonic-gate }
488