4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/systeminfo.h>
38 #include <sys/utsname.h>
39 #include <sys/openpromio.h>
44 #include "display_sun4v.h"
45 #include "libprtdiag.h"
47 #if !defined(TEXT_DOMAIN)
48 #define TEXT_DOMAIN "SYS_TEST"
55 char *promdev
= "/dev/openprom";
60 * This file represents the splitting out of some functionality
61 * of prtdiag due to the port to the sun4v platform. The PROM
62 * tree-walking functions which contain sun4v specifics were moved
66 extern int get_id(Prom_node
*);
68 /* Function prototypes */
69 Prom_node
*sun4v_walk(Sys_tree
*, Prom_node
*, int);
70 picl_errno_t
sun4v_get_node_by_name(picl_nodehdl_t
, char *, picl_nodehdl_t
*);
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 picl_nodehdl_t rooth
; /* root PICL node for IO display */
86 picl_nodehdl_t plafh
; /* Platform PICL node for IO display */
90 err
= picl_initialize();
91 if (err
!= PICL_SUCCESS
) {
92 (void) fprintf(stderr
, EM_INIT_FAIL
, picl_strerror(err
));
96 /* set the global flags */
99 print_flag
= prt_flag
;
101 /* set the the system tree fields */
102 sys_tree
.sys_mem
= NULL
;
103 sys_tree
.boards
= NULL
;
104 sys_tree
.bd_list
= NULL
;
105 sys_tree
.board_cnt
= 0;
107 if (promopen(O_RDONLY
)) {
108 exit(_error(dgettext(TEXT_DOMAIN
, "openeepr device "
112 if (is_openprom() == 0) {
113 (void) fprintf(stderr
, "%s",
114 dgettext(TEXT_DOMAIN
, "System architecture "
115 "does not support this option of this "
124 root_node
= sun4v_walk(&sys_tree
, NULL
, next(0));
127 err
= picl_get_root(&rooth
);
128 if (err
!= PICL_SUCCESS
) {
129 (void) fprintf(stderr
, EM_GET_ROOT_FAIL
, picl_strerror(err
));
133 err
= sun4v_get_node_by_name(rooth
, PICL_NODE_PLATFORM
, &plafh
);
134 if (err
!= PICL_SUCCESS
)
137 return (sun4v_display(&sys_tree
, root_node
, syserrlog
, plafh
));
142 * sun4v_Walk the PROM device tree and build the system tree and root tree.
143 * Nodes that have a board number property are placed in the board
144 * structures for easier processing later. Child nodes are placed
145 * under their parents.
148 sun4v_walk(Sys_tree
*tree
, Prom_node
*root
, int id
)
150 register int curnode
;
157 /* allocate a node for this level */
158 if ((pnode
= (Prom_node
*) malloc(sizeof (struct prom_node
))) ==
161 exit(2); /* program errors cause exit 2 */
164 /* assign parent Prom_node */
165 pnode
->parent
= root
;
166 pnode
->sibling
= NULL
;
169 /* read properties for this node */
173 * Place a node in a 'board' if it has 'board'-ness. The definition
174 * is that all nodes that are children of root should have a
175 * board# property. But the PROM tree does not exactly follow
176 * this. This is where we start hacking.
178 * PCI to PCI bridges also have the name "pci", but with different
179 * model property values. They should not be put under 'board'.
181 name
= get_node_name(pnode
);
182 type
= get_node_type(pnode
);
183 compatible
= (char *)get_prop_val(find_prop(pnode
, "compatible"));
187 printf("name=%s ", name
);
189 printf("type=%s ", type
);
192 if (compatible
== NULL
)
197 if (has_board_num(pnode
)) {
198 add_node(tree
, pnode
);
201 printf("ADDED BOARD name=%s type=%s compatible=%s\n",
202 name
, type
, compatible
);
204 } else if (strcmp(type
, "cpu") == 0) {
205 add_node(tree
, pnode
);
208 printf("ADDED BOARD name=%s type=%s compatible=%s\n",
209 name
, type
, compatible
);
214 printf("node not added: name=%s type=%s\n", name
, type
);
218 if (curnode
= child(id
)) {
219 pnode
->child
= sun4v_walk(tree
, pnode
, curnode
);
222 if (curnode
= next(id
)) {
224 return (sun4v_walk(tree
, root
, curnode
));
226 pnode
->sibling
= sun4v_walk(tree
, root
, curnode
);
238 * search children to get the node by the nodename
241 sun4v_get_node_by_name(picl_nodehdl_t rooth
, char *name
,
242 picl_nodehdl_t
*nodeh
)
244 picl_nodehdl_t childh
;
248 nodename
= alloca(strlen(name
) + 1);
249 if (nodename
== NULL
)
250 return (PICL_FAILURE
);
252 err
= picl_get_propval_by_name(rooth
, PICL_PROP_CHILD
, &childh
,
253 sizeof (picl_nodehdl_t
));
255 while (err
== PICL_SUCCESS
) {
256 err
= picl_get_propval_by_name(childh
, PICL_PROP_NAME
,
257 nodename
, (strlen(name
) + 1));
258 if (err
!= PICL_SUCCESS
) {
259 err
= picl_get_propval_by_name(childh
, PICL_PROP_PEER
,
260 &childh
, sizeof (picl_nodehdl_t
));
264 if (strcmp(nodename
, name
) == 0) {
266 return (PICL_SUCCESS
);
269 err
= picl_get_propval_by_name(childh
, PICL_PROP_PEER
,
270 &childh
, sizeof (picl_nodehdl_t
));
277 get_id(Prom_node
*node
)
281 * This function is intentionally empty