4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/systeminfo.h>
38 #include <sys/utsname.h>
39 #include <sys/openpromio.h>
43 #include "pdevinfo_sun4u.h"
45 #include "display_sun4u.h"
46 #include "libprtdiag.h"
48 #if !defined(TEXT_DOMAIN)
49 #define TEXT_DOMAIN "SYS_TEST"
56 char *promdev
= "/dev/openprom";
61 * This file represents the splitting out of some functionality
62 * of prtdiag due to the port to the sun4u platform. The PROM
63 * tree-walking functions which contain sun4u specifics were moved
67 extern int get_id(Prom_node
*);
69 /* Function prototypes */
70 Prom_node
*walk(Sys_tree
*, Prom_node
*, int);
73 * do_prominfo() is called from main() in usr/src/cmd/prtdiag/main.c
75 * This is the starting point for all platforms. However, this function
76 * can be overlayed by writing a do_prominfo() function
77 * in the libprtdiag_psr for a particular platform.
81 do_prominfo(int syserrlog
, char *pgname
, int log_flag
, int prt_flag
)
83 Sys_tree sys_tree
; /* system information */
84 Prom_node
*root_node
; /* root node of OBP device tree */
85 struct system_kstat_data sys_kstat
; /* kstats for non-OBP data */
88 /* set the global flags */
91 print_flag
= prt_flag
;
93 /* set the the system tree fields */
94 sys_tree
.sys_mem
= NULL
;
95 sys_tree
.boards
= NULL
;
96 sys_tree
.bd_list
= NULL
;
97 sys_tree
.board_cnt
= 0;
99 if (promopen(O_RDONLY
)) {
100 exit(_error(dgettext(TEXT_DOMAIN
, "openeepr device "
104 if (is_openprom() == 0) {
105 (void) fprintf(stderr
, "%s",
106 dgettext(TEXT_DOMAIN
, "System architecture "
107 "does not support this option of this "
116 root_node
= walk(&sys_tree
, NULL
, next(0));
119 /* resolve the board types now */
120 resolve_board_types(&sys_tree
);
122 read_sun4u_kstats(&sys_tree
, &sys_kstat
);
124 return (display(&sys_tree
, root_node
, &sys_kstat
, syserrlog
));
129 get_id(Prom_node
*node
)
134 * check for upa-portid on UI and UII systems
136 if ((value
= (int *)get_prop_val(find_prop(node
, "upa-portid")))
139 * check for portid on UIII systems
141 if ((value
= (int *)get_prop_val(find_prop(node
, "portid")))
152 * Walk the PROM device tree and build the system tree and root tree.
153 * Nodes that have a board number property are placed in the board
154 * structures for easier processing later. Child nodes are placed
155 * under their parents. ffb (Fusion Frame Buffer) nodes are handled
156 * specially, because they do not contain board number properties.
157 * This was requested from OBP, but was not granted. So this code
158 * must parse the MID of the FFB to find the board#.
162 walk(Sys_tree
*tree
, Prom_node
*root
, int id
)
164 register int curnode
;
171 /* allocate a node for this level */
172 if ((pnode
= (Prom_node
*) malloc(sizeof (struct prom_node
))) ==
175 exit(2); /* program errors cause exit 2 */
178 /* assign parent Prom_node */
179 pnode
->parent
= root
;
180 pnode
->sibling
= NULL
;
183 /* read properties for this node */
187 * Place a node in a 'board' if it has 'board'-ness. The definition
188 * is that all nodes that are children of root should have a
189 * board# property. But the PROM tree does not exactly follow
190 * this. This is where we start hacking. The name 'ffb' can
191 * change, so watch out for this.
193 * The UltraSPARC, sbus, pci and ffb nodes will exit in
194 * the desktops and will not have board# properties. These
195 * cases must be handled here.
197 * PCI to PCI bridges also have the name "pci", but with different
198 * model property values. They should not be put under 'board'.
200 name
= get_node_name(pnode
);
201 type
= get_node_type(pnode
);
202 model
= (char *)get_prop_val(find_prop(pnode
, "model"));
205 printf("name=%s ", name
);
207 printf("type=%s ", type
);
209 printf("model=%s", model
);
217 if (has_board_num(pnode
)) {
218 add_node(tree
, pnode
);
221 printf("ADDED BOARD name=%s type=%s model=%s\n",
224 } else if ((strcmp(name
, FFB_NAME
) == 0) ||
225 (strcmp(name
, AFB_NAME
) == 0) ||
226 (strcmp(type
, "cpu") == 0) ||
228 ((strcmp(type
, "memory-controller") == 0) &&
229 (strcmp(name
, "ac") != 0)) ||
231 ((strcmp(name
, "pci") == 0) &&
232 (strcmp(model
, "SUNW,psycho") == 0)) ||
234 ((strcmp(name
, "pci") == 0) &&
235 (strcmp(model
, "SUNW,sabre") == 0)) ||
237 ((strcmp(name
, "pci") == 0) &&
238 (strcmp(model
, "SUNW,schizo") == 0)) ||
240 ((strcmp(name
, "pci") == 0) &&
241 (strcmp(model
, "SUNW,xmits") == 0)) ||
243 (strcmp(name
, "counter-timer") == 0) ||
244 (strcmp(name
, "sbus") == 0)) {
245 add_node(tree
, pnode
);
248 printf("ADDED BOARD name=%s type=%s model=%s\n",
254 printf("node not added: name=%s type=%s\n", name
, type
);
258 if (curnode
= child(id
)) {
259 pnode
->child
= walk(tree
, pnode
, curnode
);
262 if (curnode
= next(id
)) {
264 return (walk(tree
, root
, curnode
));
266 pnode
->sibling
= walk(tree
, root
, curnode
);