103831d35Sstevel /*
203831d35Sstevel  * CDDL HEADER START
303831d35Sstevel  *
403831d35Sstevel  * The contents of this file are subject to the terms of the
503831d35Sstevel  * Common Development and Distribution License, Version 1.0 only
603831d35Sstevel  * (the "License").  You may not use this file except in compliance
703831d35Sstevel  * with the License.
803831d35Sstevel  *
903831d35Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1003831d35Sstevel  * or http://www.opensolaris.org/os/licensing.
1103831d35Sstevel  * See the License for the specific language governing permissions
1203831d35Sstevel  * and limitations under the License.
1303831d35Sstevel  *
1403831d35Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
1503831d35Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1603831d35Sstevel  * If applicable, add the following below this CDDL HEADER, with the
1703831d35Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
1803831d35Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
1903831d35Sstevel  *
2003831d35Sstevel  * CDDL HEADER END
2103831d35Sstevel  */
2203831d35Sstevel /*
2303831d35Sstevel  * Copyright 2000-2003 Sun Microsystems, Inc.  All rights reserved.
2403831d35Sstevel  * Use is subject to license terms.
2503831d35Sstevel  */
2603831d35Sstevel 
2703831d35Sstevel #include <stdio.h>
2803831d35Sstevel #include <stdlib.h>
2903831d35Sstevel #include <string.h>
3003831d35Sstevel #include <unistd.h>
3103831d35Sstevel #include <sys/systeminfo.h>
3203831d35Sstevel #include <sys/utsname.h>
3303831d35Sstevel #include <sys/openpromio.h>
3403831d35Sstevel #include <libdevinfo.h>
3503831d35Sstevel 
3603831d35Sstevel #include "pdevinfo.h"
3703831d35Sstevel #include "pdevinfo_sun4u.h"
3803831d35Sstevel #include "display.h"
3903831d35Sstevel #include "display_sun4u.h"
4003831d35Sstevel #include "libprtdiag.h"
4103831d35Sstevel 
4203831d35Sstevel /*
4303831d35Sstevel  * This file contains the functions that are to be called when
4403831d35Sstevel  * a platform wants to use libdevinfo for it's device information
4503831d35Sstevel  * instead of OBP. This will allow prtdiag to support hot-plug
4603831d35Sstevel  * events on platforms whose OBP doesn't get updated to reflect
4703831d35Sstevel  * the hot-plug changes to the system.
4803831d35Sstevel  */
4903831d35Sstevel 
5003831d35Sstevel int	do_devinfo(int syserrlog, char *pgname, int log_flag,
51*6fb59094SToomas Soome     int prt_flag);
52*6fb59094SToomas Soome static void dump_di_node(Prom_node *pnode, di_node_t di_node);
5303831d35Sstevel static Prom_node *walk_di_tree(Sys_tree *tree, Prom_node *root,
54*6fb59094SToomas Soome     di_node_t di_node);
5503831d35Sstevel static int match_compatible_name(char *, int, char *);
5603831d35Sstevel 
5703831d35Sstevel /*
5803831d35Sstevel  * Global variables
5903831d35Sstevel  */
6003831d35Sstevel di_prom_handle_t	ph;	/* Handle for using di_prom interface */
6103831d35Sstevel extern  char		*progname;
6203831d35Sstevel 
6303831d35Sstevel 
6403831d35Sstevel 
6503831d35Sstevel /*
6603831d35Sstevel  * Used instead of the walk() function when a platform wants to
6703831d35Sstevel  * walk libdevinfo's device tree instead of walking OBP's
6803831d35Sstevel  * device tree.
6903831d35Sstevel  */
7003831d35Sstevel static Prom_node*
walk_di_tree(Sys_tree * tree,Prom_node * root,di_node_t di_node)7103831d35Sstevel walk_di_tree(Sys_tree *tree, Prom_node *root, di_node_t di_node)
7203831d35Sstevel {
7303831d35Sstevel 	di_node_t	curnode;
7403831d35Sstevel 	Prom_node	*pnode;
7503831d35Sstevel 	char		*name, *type, *model, *compatible_array;
7603831d35Sstevel 	int		board_node = 0;
7703831d35Sstevel 	int		*int_val;
7803831d35Sstevel 	int		is_schizo = 0, n_names;
79*6fb59094SToomas Soome #ifdef DEBUG
80*6fb59094SToomas Soome 	int		portid;
81*6fb59094SToomas Soome #endif
8203831d35Sstevel 
8303831d35Sstevel 	/* allocate a node for this level */
8403831d35Sstevel 	if ((pnode = (Prom_node *) malloc(sizeof (struct prom_node))) ==
8503831d35Sstevel 	    NULL) {
8603831d35Sstevel 		perror("malloc");
8703831d35Sstevel 		exit(2);
8803831d35Sstevel 	}
8903831d35Sstevel 
9003831d35Sstevel 	/* assign parent Prom_node */
9103831d35Sstevel 	pnode->parent = root;
9203831d35Sstevel 	pnode->sibling = NULL;
9303831d35Sstevel 	pnode->child = NULL;
9403831d35Sstevel 
9503831d35Sstevel 	/* read properties for this node */
9603831d35Sstevel 	dump_di_node(pnode, di_node);
9703831d35Sstevel 
9803831d35Sstevel 	name = get_node_name(pnode);
9903831d35Sstevel 	type = get_node_type(pnode);
10003831d35Sstevel 	if (type == NULL)
10103831d35Sstevel 		type = "";
10203831d35Sstevel 	model = (char *)get_prop_val(find_prop(pnode, "model"));
10303831d35Sstevel 	if (model == NULL)
10403831d35Sstevel 		model = "";
10503831d35Sstevel 
10603831d35Sstevel 	/*
10703831d35Sstevel 	 * For identifying Schizo nodes we need to check if the
10803831d35Sstevel 	 * compatible property contains the string 'pci108e,8001'.
10903831d35Sstevel 	 * This property contains an array of strings so we need
11003831d35Sstevel 	 * search all strings.
11103831d35Sstevel 	 */
11203831d35Sstevel 	if ((n_names = di_compatible_names(di_node, &compatible_array)) > 0) {
11303831d35Sstevel 		if (match_compatible_name(compatible_array, n_names,
11403831d35Sstevel 		    "pci108e,8001"))
11503831d35Sstevel 			is_schizo = 1;
11603831d35Sstevel 	}
11703831d35Sstevel 
118*6fb59094SToomas Soome #ifdef DEBUG
11903831d35Sstevel 	if (int_val = (int *)get_prop_val(find_prop(pnode, "portid")))
12003831d35Sstevel 		portid = *int_val;
12103831d35Sstevel 	else if ((strcmp(type, "cpu") == 0) &&
12203831d35Sstevel 	    (int_val = (int *)get_prop_val(find_prop(pnode->parent, "portid"))))
12303831d35Sstevel 		portid = *int_val;
12403831d35Sstevel 	else
12503831d35Sstevel 		portid = -1;
12603831d35Sstevel 
12703831d35Sstevel 	if (name != NULL)
12803831d35Sstevel 		printf("name=%s\n", name);
12903831d35Sstevel 	if (type != NULL)
13003831d35Sstevel 		printf("type=%s\n", type);
13103831d35Sstevel 	if (model != NULL)
13203831d35Sstevel 		printf("model=%s\n", model);
13303831d35Sstevel 	printf("portid=%d\n", portid);
13403831d35Sstevel #endif
13503831d35Sstevel 
13603831d35Sstevel 	if (name != NULL) {
13703831d35Sstevel 		if (has_board_num(pnode)) {
13803831d35Sstevel 			add_node(tree, pnode);
13903831d35Sstevel 			board_node = 1;
14003831d35Sstevel 			D_PRINTF("\n---\nnodename = %s [ %s ] \n",
14103831d35Sstevel 			    di_node_name(di_node), di_devfs_path(di_node));
14203831d35Sstevel 			D_PRINTF("ADDED BOARD name=%s type=%s model=%s "
14303831d35Sstevel 			    "portid =%d\n", name, type, model, portid);
14403831d35Sstevel 		} else if ((strcmp(name, FFB_NAME) == 0) ||
14503831d35Sstevel 		    (strcmp(type, "cpu") == 0) ||
14603831d35Sstevel 
14703831d35Sstevel 		    ((strcmp(type, "memory-controller") == 0) &&
14803831d35Sstevel 		    (strcmp(name, "ac") != 0)) ||
14903831d35Sstevel 
15003831d35Sstevel 		    ((strcmp(name, "pci") == 0) &&
15103831d35Sstevel 		    (strcmp(model, "SUNW,psycho") == 0)) ||
15203831d35Sstevel 
15303831d35Sstevel 		    ((strcmp(name, "pci") == 0) &&
15403831d35Sstevel 		    (strcmp(model, "SUNW,sabre") == 0)) ||
15503831d35Sstevel 
15603831d35Sstevel 		    ((strcmp(name, "pci") == 0) && (is_schizo)) ||
15703831d35Sstevel 
15803831d35Sstevel 		    (strcmp(name, "counter-timer") == 0) ||
15903831d35Sstevel 		    (strcmp(name, "sbus") == 0)) {
16003831d35Sstevel 			add_node(tree, pnode);
16103831d35Sstevel 			board_node = 1;
16203831d35Sstevel 			D_PRINTF("\n---\nnodename = %s [ %s ] \n",
16303831d35Sstevel 			    di_node_name(di_node), di_devfs_path(di_node));
16403831d35Sstevel 			D_PRINTF("ADDED BOARD name=%s type=%s model=%s\n",
16503831d35Sstevel 			    name, type, model);
16603831d35Sstevel 		}
16703831d35Sstevel 	} else {
16803831d35Sstevel 		D_PRINTF("node not added: type=%s portid =%d\n", type, portid);
16903831d35Sstevel 	}
17003831d35Sstevel 
17103831d35Sstevel 	if (curnode = di_child_node(di_node)) {
17203831d35Sstevel 		pnode->child = walk_di_tree(tree, pnode, curnode);
17303831d35Sstevel 	}
17403831d35Sstevel 
17503831d35Sstevel 	if (curnode = di_sibling_node(di_node)) {
17603831d35Sstevel 		if (board_node) {
17703831d35Sstevel 			return (walk_di_tree(tree, root, curnode));
17803831d35Sstevel 		} else {
17903831d35Sstevel 			pnode->sibling = walk_di_tree(tree, root, curnode);
18003831d35Sstevel 		}
18103831d35Sstevel 	}
18203831d35Sstevel 
18303831d35Sstevel 	/*
18403831d35Sstevel 	 * This check is needed in case the "board node" occurs at the
18503831d35Sstevel 	 * end of the sibling chain as opposed to the middle or front.
18603831d35Sstevel 	 */
18703831d35Sstevel 	if (board_node)
188*6fb59094SToomas Soome 		return (NULL);
18903831d35Sstevel 
19003831d35Sstevel 	return (pnode);
19103831d35Sstevel }
19203831d35Sstevel 
19303831d35Sstevel /*
19403831d35Sstevel  * Dump all the devinfo properties and then the obp properties for
19503831d35Sstevel  * the specified devinfo node into the Prom_node structure.
19603831d35Sstevel  */
19703831d35Sstevel static void
dump_di_node(Prom_node * pnode,di_node_t di_node)19803831d35Sstevel dump_di_node(Prom_node *pnode, di_node_t di_node)
19903831d35Sstevel {
20003831d35Sstevel 	Prop *prop = NULL;	/* tail of properties list */
20103831d35Sstevel 
202*6fb59094SToomas Soome 	Prop		*temp;	/* newly allocated property */
20303831d35Sstevel 	di_prop_t	di_prop;
20403831d35Sstevel 	di_prom_prop_t	p_prop;
20503831d35Sstevel 	int		retval = 0;
20603831d35Sstevel 	int		i;
20703831d35Sstevel 
20803831d35Sstevel 	/* clear out pointers in pnode */
20903831d35Sstevel 	pnode->props = NULL;
21003831d35Sstevel 
21103831d35Sstevel 	D_PRINTF("\n\n ------- Dumping devinfo properties for node ------\n");
21203831d35Sstevel 
21303831d35Sstevel 	/*
21403831d35Sstevel 	 * get all the devinfo properties first
21503831d35Sstevel 	 */
21603831d35Sstevel 	for (di_prop = di_prop_next(di_node, DI_PROP_NIL);
21703831d35Sstevel 	    di_prop != DI_PROP_NIL;
21803831d35Sstevel 	    di_prop = di_prop_next(di_node, di_prop)) {
21903831d35Sstevel 
22003831d35Sstevel 		char		*di_name;
22103831d35Sstevel 		void		*di_data;
22203831d35Sstevel 		int		di_ptype;
22303831d35Sstevel 
22403831d35Sstevel 		di_name = di_prop_name(di_prop);
22503831d35Sstevel 		if (di_name == (char *)NULL)
22603831d35Sstevel 			continue;
22703831d35Sstevel 
22803831d35Sstevel 		di_ptype = di_prop_type(di_prop);
22903831d35Sstevel 		D_PRINTF("DEVINFO Properties  %s: ", di_name);
23003831d35Sstevel 
23103831d35Sstevel 		switch (di_ptype) {
23203831d35Sstevel 		case DI_PROP_TYPE_INT:
23303831d35Sstevel 			retval = di_prop_lookup_ints(DDI_DEV_T_ANY,
234*6fb59094SToomas Soome 			    di_node, di_name, (int **)&di_data);
23503831d35Sstevel 			if (retval > 0) {
236*6fb59094SToomas Soome 				D_PRINTF("0x%x\n", *(int *)di_data);
23703831d35Sstevel 			}
23803831d35Sstevel 			break;
23903831d35Sstevel 		case DI_PROP_TYPE_STRING:
24003831d35Sstevel 			retval = di_prop_lookup_strings(DDI_DEV_T_ANY,
241*6fb59094SToomas Soome 			    di_node, di_name, (char **)&di_data);
24203831d35Sstevel 			if (retval > 0) {
243*6fb59094SToomas Soome 				D_PRINTF("%s\n", (char *)di_data);
24403831d35Sstevel 			}
24503831d35Sstevel 			break;
24603831d35Sstevel 		case DI_PROP_TYPE_BYTE:
24703831d35Sstevel 			retval = di_prop_lookup_bytes(DDI_DEV_T_ANY,
248*6fb59094SToomas Soome 			    di_node, di_name, (uchar_t **)&di_data);
24903831d35Sstevel 			if (retval > 0) {
250*6fb59094SToomas Soome 				D_PRINTF("%s\n", (char *)di_data);
25103831d35Sstevel 			}
25203831d35Sstevel 			break;
25303831d35Sstevel 		case DI_PROP_TYPE_UNKNOWN:
25403831d35Sstevel 			retval = di_prop_lookup_bytes(DDI_DEV_T_ANY,
255*6fb59094SToomas Soome 			    di_node, di_name, (uchar_t **)&di_data);
25603831d35Sstevel 			if (retval > 0) {
257*6fb59094SToomas Soome 				D_PRINTF("%s\n", (char *)di_data);
25803831d35Sstevel 			}
25903831d35Sstevel 			break;
26003831d35Sstevel 		case DI_PROP_TYPE_BOOLEAN:
26103831d35Sstevel 			di_data = NULL;
26203831d35Sstevel 			retval = 1;
26303831d35Sstevel 			break;
26403831d35Sstevel 		default:
26503831d35Sstevel 			D_PRINTF(" Skipping property\n");
26603831d35Sstevel 			retval = -1;
26703831d35Sstevel 		}
26803831d35Sstevel 
26903831d35Sstevel 		if (retval <= 0)
27003831d35Sstevel 			continue;
27103831d35Sstevel 
27203831d35Sstevel 		/* allocate space for the property */
27303831d35Sstevel 		if ((temp = (Prop *) malloc(sizeof (Prop))) == NULL) {
27403831d35Sstevel 			perror("malloc");
27503831d35Sstevel 			exit(1);
27603831d35Sstevel 		}
27703831d35Sstevel 
27803831d35Sstevel 		/*
27903831d35Sstevel 		 * Given that we're using libdevinfo rather than OBP,
28003831d35Sstevel 		 * the chances are that future accesses to di_name and
28103831d35Sstevel 		 * di_data will be via temp->name.val_ptr and
28203831d35Sstevel 		 * temp->value.val_ptr respectively. However, this may
28303831d35Sstevel 		 * not be the case, so we have to suitably fill in
28403831d35Sstevel 		 * temp->name.opp and temp->value.opp.
28503831d35Sstevel 		 *
28603831d35Sstevel 		 * di_name is char * and non-NULL if we've made it to
28703831d35Sstevel 		 * here, so we can simply point
28803831d35Sstevel 		 * temp->name.opp.oprom_array to temp->name.val_ptr.
28903831d35Sstevel 		 *
29003831d35Sstevel 		 * di_data could be NULL, char * or int * at this point.
29103831d35Sstevel 		 * If it's non-NULL, a 1st char of '\0' indicates int *.
29203831d35Sstevel 		 * We thus set temp->value.opp.oprom_node[] (although
29303831d35Sstevel 		 * interest in any element other than 0 is rare, all
29403831d35Sstevel 		 * elements must be set to ensure compatibility with
29503831d35Sstevel 		 * OBP), and holds_array is set to 0.
29603831d35Sstevel 		 *
29703831d35Sstevel 		 * If di_data is NULL, or the 1st char is not '\0', we set
29803831d35Sstevel 		 * temp->value.opp.oprom_array. If di_ptype is
29903831d35Sstevel 		 * DI_PROP_TYPE_BOOLEAN, holds_array is set to 0, else it
30003831d35Sstevel 		 * is set to 1.
30103831d35Sstevel 		 */
30203831d35Sstevel 		temp->name.val_ptr = (void *)di_name;
30303831d35Sstevel 		temp->name.opp.oprom_array = temp->name.val_ptr;
30403831d35Sstevel 		temp->name.opp.holds_array = 1;
30503831d35Sstevel 
30603831d35Sstevel 		temp->value.val_ptr = (void *)di_data;
30703831d35Sstevel 		if ((di_data != NULL) && (*((char *)di_data) == '\0')) {
308*6fb59094SToomas Soome 			for (i = 0; i < OPROM_NODE_SIZE; i++)
309*6fb59094SToomas Soome 				temp->value.opp.oprom_node[i] =
310*6fb59094SToomas Soome 				    *((int *)di_data+i);
31103831d35Sstevel 
31203831d35Sstevel 			temp->value.opp.holds_array = 0;
313*6fb59094SToomas Soome 		} else {
314*6fb59094SToomas Soome 			temp->value.opp.oprom_array = temp->value.val_ptr;
315*6fb59094SToomas Soome 			if (di_ptype == DI_PROP_TYPE_BOOLEAN)
316*6fb59094SToomas Soome 				temp->value.opp.holds_array = 0;
317*6fb59094SToomas Soome 			else
318*6fb59094SToomas Soome 				temp->value.opp.holds_array = 1;
31903831d35Sstevel 		}
32003831d35Sstevel 
32103831d35Sstevel 		temp->size = retval;
32203831d35Sstevel 
32303831d35Sstevel 		/* everything worked so link the property list */
32403831d35Sstevel 		if (pnode->props == NULL)
32503831d35Sstevel 			pnode->props = temp;
32603831d35Sstevel 		else if (prop != NULL)
32703831d35Sstevel 			prop->next = temp;
32803831d35Sstevel 		prop = temp;
32903831d35Sstevel 		prop->next = NULL;
33003831d35Sstevel 	}
33103831d35Sstevel 
33203831d35Sstevel 	/*
33303831d35Sstevel 	 * Then get all the OBP properties.
33403831d35Sstevel 	 */
33503831d35Sstevel 	for (p_prop = di_prom_prop_next(ph, di_node, DI_PROM_PROP_NIL);
33603831d35Sstevel 	    p_prop != DI_PROM_PROP_NIL;
33703831d35Sstevel 	    p_prop = di_prom_prop_next(ph, di_node, p_prop)) {
33803831d35Sstevel 
33903831d35Sstevel 		char		*p_name;
34003831d35Sstevel 		unsigned char	*p_data;
34103831d35Sstevel 
34203831d35Sstevel 		p_name = di_prom_prop_name(p_prop);
34303831d35Sstevel 		if (p_name == (char *)NULL)
34403831d35Sstevel 			retval = -1;
34503831d35Sstevel 		else
34603831d35Sstevel 			retval = di_prom_prop_data(p_prop, &p_data);
34703831d35Sstevel 
34803831d35Sstevel 		if (retval <= 0)
34903831d35Sstevel 			continue;
35003831d35Sstevel 
35103831d35Sstevel 		/* allocate space for the property */
35203831d35Sstevel 		if ((temp = (Prop *) malloc(sizeof (Prop))) == NULL) {
35303831d35Sstevel 			perror("malloc");
35403831d35Sstevel 			exit(1);
35503831d35Sstevel 		}
35603831d35Sstevel 
35703831d35Sstevel 		/*
35803831d35Sstevel 		 * As above, p_name is char * and non-NULL if we've made
35903831d35Sstevel 		 * it to here, so we can simply point
36003831d35Sstevel 		 * temp->name.opp.oprom_array to temp->name.val_ptr.
36103831d35Sstevel 		 *
36203831d35Sstevel 		 * p_data could be NULL, a character or a number at this
36303831d35Sstevel 		 * point. If it's non-NULL, a 1st char of '\0' indicates a
36403831d35Sstevel 		 * number, so we set temp->value.opp.oprom_node[] (again
36503831d35Sstevel 		 * setting every element to ensure OBP compatibility).
36603831d35Sstevel 		 * These assignments create a lint error, hence the LINTED
36703831d35Sstevel 		 * comment.
36803831d35Sstevel 		 *
36903831d35Sstevel 		 * If p_data is NULL, or the 1st char is not '\0', we set
37003831d35Sstevel 		 * temp->value.opp.oprom_array.
37103831d35Sstevel 		 */
37203831d35Sstevel 		temp->name.val_ptr = (void *)p_name;
37303831d35Sstevel 		temp->name.opp.oprom_array = temp->name.val_ptr;
37403831d35Sstevel 		temp->name.opp.holds_array = 1;
37503831d35Sstevel 
37603831d35Sstevel 		temp->value.val_ptr = (void *)p_data;
37703831d35Sstevel 		if ((p_data != NULL) && (*p_data == '\0')) {
378*6fb59094SToomas Soome 			for (i = 0; i < OPROM_NODE_SIZE; i++)
379*6fb59094SToomas Soome 				temp->value.opp.oprom_node[i] =
380*6fb59094SToomas Soome 				    *((int *)p_data+i);
38103831d35Sstevel 
382*6fb59094SToomas Soome 			temp->value.opp.holds_array = 0;
38303831d35Sstevel 		} else {
384*6fb59094SToomas Soome 			temp->value.opp.oprom_array = temp->value.val_ptr;
385*6fb59094SToomas Soome 			temp->value.opp.holds_array = 1;
38603831d35Sstevel 		}
38703831d35Sstevel 
38803831d35Sstevel 		temp->size = retval;
38903831d35Sstevel 
39003831d35Sstevel 		/* everything worked so link the property list */
39103831d35Sstevel 		if (pnode->props == NULL) {
39203831d35Sstevel 			pnode->props = temp;
39303831d35Sstevel 		} else if (prop != NULL) {
39403831d35Sstevel 			prop->next = temp;
39503831d35Sstevel 		}
39603831d35Sstevel 		prop = temp;
39703831d35Sstevel 		prop->next = NULL;
39803831d35Sstevel 	}
39903831d35Sstevel }
40003831d35Sstevel 
40103831d35Sstevel /*
40203831d35Sstevel  * Used in place of do_prominfo() when a platform wants to use
40303831d35Sstevel  * libdevinfo for getting the device tree instead of OBP.
40403831d35Sstevel  */
40503831d35Sstevel int
do_devinfo(int syserrlog,char * pgname,int log_flag,int prt_flag)40603831d35Sstevel do_devinfo(int syserrlog, char *pgname, int log_flag, int prt_flag)
40703831d35Sstevel {
40803831d35Sstevel 	Sys_tree sys_tree;		/* system information */
40903831d35Sstevel 	Prom_node *root_node;		/* root node of OBP device tree */
41003831d35Sstevel 	di_node_t di_root_node;		/* root of the devinfo tree */
41103831d35Sstevel 	struct system_kstat_data sys_kstat; /* kstats for non-OBP data */
41203831d35Sstevel 	int retval = -1;
41303831d35Sstevel 
41403831d35Sstevel 	/* set the global flags */
41503831d35Sstevel 	progname = pgname;
41603831d35Sstevel 	logging = log_flag;
41703831d35Sstevel 	print_flag = prt_flag;
41803831d35Sstevel 
41903831d35Sstevel 	/* set the the system tree fields */
42003831d35Sstevel 	sys_tree.sys_mem = NULL;
42103831d35Sstevel 	sys_tree.boards = NULL;
42203831d35Sstevel 	sys_tree.bd_list = NULL;
42303831d35Sstevel 	sys_tree.board_cnt = 0;
42403831d35Sstevel 
42503831d35Sstevel 	/*
42603831d35Sstevel 	 * create a snapshot of the kernel device tree
42703831d35Sstevel 	 * and return a handle to it.
42803831d35Sstevel 	 */
42903831d35Sstevel 	if ((di_root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
43003831d35Sstevel 		exit(_error("di_init() failed"));
43103831d35Sstevel 	}
43203831d35Sstevel 
43303831d35Sstevel 	/*
43403831d35Sstevel 	 * create a handle to the PROM device tree.
43503831d35Sstevel 	 */
43603831d35Sstevel 	if ((ph = di_prom_init()) == NULL) {
43703831d35Sstevel 		exit(_error("di_prom_init() failed"));
43803831d35Sstevel 	}
43903831d35Sstevel 
44003831d35Sstevel 	/*
44103831d35Sstevel 	 * walk the devinfo tree and build up a list of all
44203831d35Sstevel 	 * nodes and properties.
44303831d35Sstevel 	 */
44403831d35Sstevel 	root_node = walk_di_tree(&sys_tree, NULL, di_root_node);
44503831d35Sstevel 
44603831d35Sstevel 	/* resolve the board types now */
44703831d35Sstevel 	resolve_board_types(&sys_tree);
44803831d35Sstevel 
44903831d35Sstevel 	read_sun4u_kstats(&sys_tree, &sys_kstat);
45003831d35Sstevel 	retval = display(&sys_tree, root_node, &sys_kstat, syserrlog);
45103831d35Sstevel 
45203831d35Sstevel 	di_fini(di_root_node);
45303831d35Sstevel 	di_prom_fini(ph);
45403831d35Sstevel 	return (retval);
45503831d35Sstevel }
45603831d35Sstevel 
45703831d35Sstevel /*
45803831d35Sstevel  * check to see if the name shows up in the compatible array
45903831d35Sstevel  */
46003831d35Sstevel static int
match_compatible_name(char * compatible_array,int n_names,char * name)46103831d35Sstevel match_compatible_name(char *compatible_array, int n_names, char *name)
46203831d35Sstevel {
463*6fb59094SToomas Soome 	int	i, ret = 0;
46403831d35Sstevel 
46503831d35Sstevel 	/* parse the compatible list */
46603831d35Sstevel 	for (i = 0; i < n_names; i++) {
46703831d35Sstevel 		if (strcmp(compatible_array, name) == 0) {
46803831d35Sstevel 			ret = 1;
46903831d35Sstevel 			break;
47003831d35Sstevel 		}
47103831d35Sstevel 		compatible_array += strlen(compatible_array) + 1;
47203831d35Sstevel 	}
47303831d35Sstevel 	return (ret);
47403831d35Sstevel }
475