#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <varargs.h>
#include <errno.h>
#include <unistd.h>
#include <sys/systeminfo.h>
#include <sys/utsname.h>
#include <sys/openpromio.h>
#include <kstat.h>
#include <libintl.h>
#include "pdevinfo.h"
#include "pdevinfo_sun4u.h"
#include "display.h"
#include "display_sun4u.h"
#include "libprtdiag.h"
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
char *progname;
char *promdev = "/dev/openprom";
int print_flag = 1;
int logging = 0;
extern int get_id(Prom_node *);
Prom_node *walk(Sys_tree *, Prom_node *, int);
int
do_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag)
{
Sys_tree sys_tree;
Prom_node *root_node;
struct system_kstat_data sys_kstat;
progname = pgname;
logging = log_flag;
print_flag = prt_flag;
sys_tree.sys_mem = NULL;
sys_tree.boards = NULL;
sys_tree.bd_list = NULL;
sys_tree.board_cnt = 0;
if (promopen(O_RDONLY)) {
exit(_error(dgettext(TEXT_DOMAIN, "openeepr device "
"open failed")));
}
if (is_openprom() == 0) {
(void) fprintf(stderr, "%s",
dgettext(TEXT_DOMAIN, "System architecture "
"does not support this option of this "
"command.\n"));
return (2);
}
if (next(0) == 0) {
return (2);
}
root_node = walk(&sys_tree, NULL, next(0));
promclose();
resolve_board_types(&sys_tree);
read_sun4u_kstats(&sys_tree, &sys_kstat);
return (display(&sys_tree, root_node, &sys_kstat, syserrlog));
}
int
get_id(Prom_node *node)
{
int *value;
if ((value = (int *)get_prop_val(find_prop(node, "upa-portid")))
== NULL) {
if ((value = (int *)get_prop_val(find_prop(node, "portid")))
== NULL) {
return (-1);
}
}
return (*value);
}
Prom_node *
walk(Sys_tree *tree, Prom_node *root, int id)
{
register int curnode;
Prom_node *pnode;
char *name;
char *type;
char *model;
int board_node = 0;
if ((pnode = (Prom_node *) malloc(sizeof (struct prom_node))) ==
NULL) {
perror("malloc");
exit(2);
}
pnode->parent = root;
pnode->sibling = NULL;
pnode->child = NULL;
dump_node(pnode);
name = get_node_name(pnode);
type = get_node_type(pnode);
model = (char *)get_prop_val(find_prop(pnode, "model"));
#ifdef DEBUG
if (name != NULL)
printf("name=%s ", name);
if (type != NULL)
printf("type=%s ", type);
if (model != NULL)
printf("model=%s", model);
printf("\n");
#endif
if (model == NULL)
model = "";
if (type == NULL)
type = "";
if (name != NULL) {
if (has_board_num(pnode)) {
add_node(tree, pnode);
board_node = 1;
#ifdef DEBUG
printf("ADDED BOARD name=%s type=%s model=%s\n",
name, type, model);
#endif
} else if ((strcmp(name, FFB_NAME) == 0) ||
(strcmp(name, AFB_NAME) == 0) ||
(strcmp(type, "cpu") == 0) ||
((strcmp(type, "memory-controller") == 0) &&
(strcmp(name, "ac") != 0)) ||
((strcmp(name, "pci") == 0) &&
(strcmp(model, "SUNW,psycho") == 0)) ||
((strcmp(name, "pci") == 0) &&
(strcmp(model, "SUNW,sabre") == 0)) ||
((strcmp(name, "pci") == 0) &&
(strcmp(model, "SUNW,schizo") == 0)) ||
((strcmp(name, "pci") == 0) &&
(strcmp(model, "SUNW,xmits") == 0)) ||
(strcmp(name, "counter-timer") == 0) ||
(strcmp(name, "sbus") == 0)) {
add_node(tree, pnode);
board_node = 1;
#ifdef DEBUG
printf("ADDED BOARD name=%s type=%s model=%s\n",
name, type, model);
#endif
}
#ifdef DEBUG
else
printf("node not added: name=%s type=%s\n", name, type);
#endif
}
if (curnode = child(id)) {
pnode->child = walk(tree, pnode, curnode);
}
if (curnode = next(id)) {
if (board_node) {
return (walk(tree, root, curnode));
} else {
pnode->sibling = walk(tree, root, curnode);
}
}
if (board_node) {
return (NULL);
} else {
return (pnode);
}
}