1*1708Sstevel /*
2*1708Sstevel * CDDL HEADER START
3*1708Sstevel *
4*1708Sstevel * The contents of this file are subject to the terms of the
5*1708Sstevel * Common Development and Distribution License, Version 1.0 only
6*1708Sstevel * (the "License"). You may not use this file except in compliance
7*1708Sstevel * with the License.
8*1708Sstevel *
9*1708Sstevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*1708Sstevel * or http://www.opensolaris.org/os/licensing.
11*1708Sstevel * See the License for the specific language governing permissions
12*1708Sstevel * and limitations under the License.
13*1708Sstevel *
14*1708Sstevel * When distributing Covered Code, include this CDDL HEADER in each
15*1708Sstevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*1708Sstevel * If applicable, add the following below this CDDL HEADER, with the
17*1708Sstevel * fields enclosed by brackets "[]" replaced with your own identifying
18*1708Sstevel * information: Portions Copyright [yyyy] [name of copyright owner]
19*1708Sstevel *
20*1708Sstevel * CDDL HEADER END
21*1708Sstevel */
22*1708Sstevel /*
23*1708Sstevel * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved.
24*1708Sstevel * Use is subject to license terms.
25*1708Sstevel */
26*1708Sstevel
27*1708Sstevel #pragma ident "%Z%%M% %I% %E% SMI"
28*1708Sstevel
29*1708Sstevel #include <stdio.h>
30*1708Sstevel #include <stdlib.h>
31*1708Sstevel #include <string.h>
32*1708Sstevel #include <fcntl.h>
33*1708Sstevel #include <dirent.h>
34*1708Sstevel #include <varargs.h>
35*1708Sstevel #include <errno.h>
36*1708Sstevel #include <unistd.h>
37*1708Sstevel #include <sys/systeminfo.h>
38*1708Sstevel #include <sys/utsname.h>
39*1708Sstevel #include <sys/openpromio.h>
40*1708Sstevel #include <kstat.h>
41*1708Sstevel #include <libintl.h>
42*1708Sstevel #include "pdevinfo.h"
43*1708Sstevel #include "pdevinfo_sun4u.h"
44*1708Sstevel #include "display.h"
45*1708Sstevel #include "display_sun4u.h"
46*1708Sstevel #include "libprtdiag.h"
47*1708Sstevel
48*1708Sstevel #if !defined(TEXT_DOMAIN)
49*1708Sstevel #define TEXT_DOMAIN "SYS_TEST"
50*1708Sstevel #endif
51*1708Sstevel
52*1708Sstevel /*
53*1708Sstevel * Global variables
54*1708Sstevel */
55*1708Sstevel char *progname;
56*1708Sstevel char *promdev = "/dev/openprom";
57*1708Sstevel int print_flag = 1;
58*1708Sstevel int logging = 0;
59*1708Sstevel
60*1708Sstevel /*
61*1708Sstevel * This file represents the splitting out of some functionality
62*1708Sstevel * of prtdiag due to the port to the sun4u platform. The PROM
63*1708Sstevel * tree-walking functions which contain sun4u specifics were moved
64*1708Sstevel * into this module.
65*1708Sstevel */
66*1708Sstevel
67*1708Sstevel extern int get_id(Prom_node *);
68*1708Sstevel
69*1708Sstevel /* Function prototypes */
70*1708Sstevel Prom_node *walk(Sys_tree *, Prom_node *, int);
71*1708Sstevel
72*1708Sstevel /*
73*1708Sstevel * do_prominfo() is called from main() in usr/src/cmd/prtdiag/main.c
74*1708Sstevel *
75*1708Sstevel * This is the starting point for all platforms. However, this function
76*1708Sstevel * can be overlayed by writing a do_prominfo() function
77*1708Sstevel * in the libprtdiag_psr for a particular platform.
78*1708Sstevel *
79*1708Sstevel */
80*1708Sstevel int
do_prominfo(int syserrlog,char * pgname,int log_flag,int prt_flag)81*1708Sstevel do_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag)
82*1708Sstevel {
83*1708Sstevel Sys_tree sys_tree; /* system information */
84*1708Sstevel Prom_node *root_node; /* root node of OBP device tree */
85*1708Sstevel struct system_kstat_data sys_kstat; /* kstats for non-OBP data */
86*1708Sstevel
87*1708Sstevel
88*1708Sstevel /* set the global flags */
89*1708Sstevel progname = pgname;
90*1708Sstevel logging = log_flag;
91*1708Sstevel print_flag = prt_flag;
92*1708Sstevel
93*1708Sstevel /* set the the system tree fields */
94*1708Sstevel sys_tree.sys_mem = NULL;
95*1708Sstevel sys_tree.boards = NULL;
96*1708Sstevel sys_tree.bd_list = NULL;
97*1708Sstevel sys_tree.board_cnt = 0;
98*1708Sstevel
99*1708Sstevel if (promopen(O_RDONLY)) {
100*1708Sstevel exit(_error(dgettext(TEXT_DOMAIN, "openeepr device "
101*1708Sstevel "open failed")));
102*1708Sstevel }
103*1708Sstevel
104*1708Sstevel if (is_openprom() == 0) {
105*1708Sstevel (void) fprintf(stderr, "%s",
106*1708Sstevel dgettext(TEXT_DOMAIN, "System architecture "
107*1708Sstevel "does not support this option of this "
108*1708Sstevel "command.\n"));
109*1708Sstevel return (2);
110*1708Sstevel }
111*1708Sstevel
112*1708Sstevel if (next(0) == 0) {
113*1708Sstevel return (2);
114*1708Sstevel }
115*1708Sstevel
116*1708Sstevel root_node = walk(&sys_tree, NULL, next(0));
117*1708Sstevel promclose();
118*1708Sstevel
119*1708Sstevel /* resolve the board types now */
120*1708Sstevel resolve_board_types(&sys_tree);
121*1708Sstevel
122*1708Sstevel read_sun4u_kstats(&sys_tree, &sys_kstat);
123*1708Sstevel
124*1708Sstevel return (display(&sys_tree, root_node, &sys_kstat, syserrlog));
125*1708Sstevel
126*1708Sstevel }
127*1708Sstevel
128*1708Sstevel int
get_id(Prom_node * node)129*1708Sstevel get_id(Prom_node *node)
130*1708Sstevel {
131*1708Sstevel int *value;
132*1708Sstevel
133*1708Sstevel /*
134*1708Sstevel * check for upa-portid on UI and UII systems
135*1708Sstevel */
136*1708Sstevel if ((value = (int *)get_prop_val(find_prop(node, "upa-portid")))
137*1708Sstevel == NULL) {
138*1708Sstevel /*
139*1708Sstevel * check for portid on UIII systems
140*1708Sstevel */
141*1708Sstevel if ((value = (int *)get_prop_val(find_prop(node, "portid")))
142*1708Sstevel == NULL) {
143*1708Sstevel return (-1);
144*1708Sstevel }
145*1708Sstevel }
146*1708Sstevel return (*value);
147*1708Sstevel }
148*1708Sstevel
149*1708Sstevel
150*1708Sstevel
151*1708Sstevel /*
152*1708Sstevel * Walk the PROM device tree and build the system tree and root tree.
153*1708Sstevel * Nodes that have a board number property are placed in the board
154*1708Sstevel * structures for easier processing later. Child nodes are placed
155*1708Sstevel * under their parents. ffb (Fusion Frame Buffer) nodes are handled
156*1708Sstevel * specially, because they do not contain board number properties.
157*1708Sstevel * This was requested from OBP, but was not granted. So this code
158*1708Sstevel * must parse the MID of the FFB to find the board#.
159*1708Sstevel *
160*1708Sstevel */
161*1708Sstevel Prom_node *
walk(Sys_tree * tree,Prom_node * root,int id)162*1708Sstevel walk(Sys_tree *tree, Prom_node *root, int id)
163*1708Sstevel {
164*1708Sstevel register int curnode;
165*1708Sstevel Prom_node *pnode;
166*1708Sstevel char *name;
167*1708Sstevel char *type;
168*1708Sstevel char *model;
169*1708Sstevel int board_node = 0;
170*1708Sstevel
171*1708Sstevel /* allocate a node for this level */
172*1708Sstevel if ((pnode = (Prom_node *) malloc(sizeof (struct prom_node))) ==
173*1708Sstevel NULL) {
174*1708Sstevel perror("malloc");
175*1708Sstevel exit(2); /* program errors cause exit 2 */
176*1708Sstevel }
177*1708Sstevel
178*1708Sstevel /* assign parent Prom_node */
179*1708Sstevel pnode->parent = root;
180*1708Sstevel pnode->sibling = NULL;
181*1708Sstevel pnode->child = NULL;
182*1708Sstevel
183*1708Sstevel /* read properties for this node */
184*1708Sstevel dump_node(pnode);
185*1708Sstevel
186*1708Sstevel /*
187*1708Sstevel * Place a node in a 'board' if it has 'board'-ness. The definition
188*1708Sstevel * is that all nodes that are children of root should have a
189*1708Sstevel * board# property. But the PROM tree does not exactly follow
190*1708Sstevel * this. This is where we start hacking. The name 'ffb' can
191*1708Sstevel * change, so watch out for this.
192*1708Sstevel *
193*1708Sstevel * The UltraSPARC, sbus, pci and ffb nodes will exit in
194*1708Sstevel * the desktops and will not have board# properties. These
195*1708Sstevel * cases must be handled here.
196*1708Sstevel *
197*1708Sstevel * PCI to PCI bridges also have the name "pci", but with different
198*1708Sstevel * model property values. They should not be put under 'board'.
199*1708Sstevel */
200*1708Sstevel name = get_node_name(pnode);
201*1708Sstevel type = get_node_type(pnode);
202*1708Sstevel model = (char *)get_prop_val(find_prop(pnode, "model"));
203*1708Sstevel #ifdef DEBUG
204*1708Sstevel if (name != NULL)
205*1708Sstevel printf("name=%s ", name);
206*1708Sstevel if (type != NULL)
207*1708Sstevel printf("type=%s ", type);
208*1708Sstevel if (model != NULL)
209*1708Sstevel printf("model=%s", model);
210*1708Sstevel printf("\n");
211*1708Sstevel #endif
212*1708Sstevel if (model == NULL)
213*1708Sstevel model = "";
214*1708Sstevel if (type == NULL)
215*1708Sstevel type = "";
216*1708Sstevel if (name != NULL) {
217*1708Sstevel if (has_board_num(pnode)) {
218*1708Sstevel add_node(tree, pnode);
219*1708Sstevel board_node = 1;
220*1708Sstevel #ifdef DEBUG
221*1708Sstevel printf("ADDED BOARD name=%s type=%s model=%s\n",
222*1708Sstevel name, type, model);
223*1708Sstevel #endif
224*1708Sstevel } else if ((strcmp(name, FFB_NAME) == 0) ||
225*1708Sstevel (strcmp(name, AFB_NAME) == 0) ||
226*1708Sstevel (strcmp(type, "cpu") == 0) ||
227*1708Sstevel
228*1708Sstevel ((strcmp(type, "memory-controller") == 0) &&
229*1708Sstevel (strcmp(name, "ac") != 0)) ||
230*1708Sstevel
231*1708Sstevel ((strcmp(name, "pci") == 0) &&
232*1708Sstevel (strcmp(model, "SUNW,psycho") == 0)) ||
233*1708Sstevel
234*1708Sstevel ((strcmp(name, "pci") == 0) &&
235*1708Sstevel (strcmp(model, "SUNW,sabre") == 0)) ||
236*1708Sstevel
237*1708Sstevel ((strcmp(name, "pci") == 0) &&
238*1708Sstevel (strcmp(model, "SUNW,schizo") == 0)) ||
239*1708Sstevel
240*1708Sstevel ((strcmp(name, "pci") == 0) &&
241*1708Sstevel (strcmp(model, "SUNW,xmits") == 0)) ||
242*1708Sstevel
243*1708Sstevel (strcmp(name, "counter-timer") == 0) ||
244*1708Sstevel (strcmp(name, "sbus") == 0)) {
245*1708Sstevel add_node(tree, pnode);
246*1708Sstevel board_node = 1;
247*1708Sstevel #ifdef DEBUG
248*1708Sstevel printf("ADDED BOARD name=%s type=%s model=%s\n",
249*1708Sstevel name, type, model);
250*1708Sstevel #endif
251*1708Sstevel }
252*1708Sstevel #ifdef DEBUG
253*1708Sstevel else
254*1708Sstevel printf("node not added: name=%s type=%s\n", name, type);
255*1708Sstevel #endif
256*1708Sstevel }
257*1708Sstevel
258*1708Sstevel if (curnode = child(id)) {
259*1708Sstevel pnode->child = walk(tree, pnode, curnode);
260*1708Sstevel }
261*1708Sstevel
262*1708Sstevel if (curnode = next(id)) {
263*1708Sstevel if (board_node) {
264*1708Sstevel return (walk(tree, root, curnode));
265*1708Sstevel } else {
266*1708Sstevel pnode->sibling = walk(tree, root, curnode);
267*1708Sstevel }
268*1708Sstevel }
269*1708Sstevel
270*1708Sstevel if (board_node) {
271*1708Sstevel return (NULL);
272*1708Sstevel } else {
273*1708Sstevel return (pnode);
274*1708Sstevel }
275*1708Sstevel }
276