2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A#include <fcntl.h>
2N/A#include <dirent.h>
2N/A#include <varargs.h>
2N/A#include <errno.h>
2N/A#include <unistd.h>
2N/A#include <sys/systeminfo.h>
2N/A#include <sys/utsname.h>
2N/A#include <sys/openpromio.h>
2N/A#include <kstat.h>
2N/A#include <libintl.h>
2N/A#include "pdevinfo.h"
2N/A#include "pdevinfo_sun4u.h"
2N/A#include "display.h"
2N/A#include "display_sun4u.h"
2N/A#include "libprtdiag.h"
2N/A
2N/A#if !defined(TEXT_DOMAIN)
2N/A#define TEXT_DOMAIN "SYS_TEST"
2N/A#endif
2N/A
2N/A/*
2N/A * Global variables
2N/A */
2N/Achar *progname;
2N/Achar *promdev = "/dev/openprom";
2N/Aint print_flag = 1;
2N/Aint logging = 0;
2N/A
2N/A/*
2N/A * This file represents the splitting out of some functionality
2N/A * of prtdiag due to the port to the sun4u platform. The PROM
2N/A * tree-walking functions which contain sun4u specifics were moved
2N/A * into this module.
2N/A */
2N/A
2N/Aextern int get_id(Prom_node *);
2N/A
2N/A/* Function prototypes */
2N/AProm_node *walk(Sys_tree *, Prom_node *, int);
2N/A
2N/A/*
2N/A * do_prominfo() is called from main() in usr/src/cmd/prtdiag/main.c
2N/A *
2N/A * This is the starting point for all platforms. However, this function
2N/A * can be overlayed by writing a do_prominfo() function
2N/A * in the libprtdiag_psr for a particular platform.
2N/A *
2N/A */
2N/Aint
2N/Ado_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag)
2N/A{
2N/A Sys_tree sys_tree; /* system information */
2N/A Prom_node *root_node; /* root node of OBP device tree */
2N/A struct system_kstat_data sys_kstat; /* kstats for non-OBP data */
2N/A
2N/A
2N/A /* set the global flags */
2N/A progname = pgname;
2N/A logging = log_flag;
2N/A print_flag = prt_flag;
2N/A
2N/A /* set the the system tree fields */
2N/A sys_tree.sys_mem = NULL;
2N/A sys_tree.boards = NULL;
2N/A sys_tree.bd_list = NULL;
2N/A sys_tree.board_cnt = 0;
2N/A
2N/A if (promopen(O_RDONLY)) {
2N/A exit(_error(dgettext(TEXT_DOMAIN, "openeepr device "
2N/A "open failed")));
2N/A }
2N/A
2N/A if (is_openprom() == 0) {
2N/A (void) fprintf(stderr, "%s",
2N/A dgettext(TEXT_DOMAIN, "System architecture "
2N/A "does not support this option of this "
2N/A "command.\n"));
2N/A return (2);
2N/A }
2N/A
2N/A if (next(0) == 0) {
2N/A return (2);
2N/A }
2N/A
2N/A root_node = walk(&sys_tree, NULL, next(0));
2N/A promclose();
2N/A
2N/A /* resolve the board types now */
2N/A resolve_board_types(&sys_tree);
2N/A
2N/A read_sun4u_kstats(&sys_tree, &sys_kstat);
2N/A
2N/A return (display(&sys_tree, root_node, &sys_kstat, syserrlog));
2N/A
2N/A}
2N/A
2N/Aint
2N/Aget_id(Prom_node *node)
2N/A{
2N/A int *value;
2N/A
2N/A /*
2N/A * check for upa-portid on UI and UII systems
2N/A */
2N/A if ((value = (int *)get_prop_val(find_prop(node, "upa-portid")))
2N/A == NULL) {
2N/A /*
2N/A * check for portid on UIII systems
2N/A */
2N/A if ((value = (int *)get_prop_val(find_prop(node, "portid")))
2N/A == NULL) {
2N/A return (-1);
2N/A }
2N/A }
2N/A return (*value);
2N/A}
2N/A
2N/A
2N/A
2N/A/*
2N/A * Walk the PROM device tree and build the system tree and root tree.
2N/A * Nodes that have a board number property are placed in the board
2N/A * structures for easier processing later. Child nodes are placed
2N/A * under their parents. ffb (Fusion Frame Buffer) nodes are handled
2N/A * specially, because they do not contain board number properties.
2N/A * This was requested from OBP, but was not granted. So this code
2N/A * must parse the MID of the FFB to find the board#.
2N/A *
2N/A */
2N/AProm_node *
2N/Awalk(Sys_tree *tree, Prom_node *root, int id)
2N/A{
2N/A register int curnode;
2N/A Prom_node *pnode;
2N/A char *name;
2N/A char *type;
2N/A char *model;
2N/A int board_node = 0;
2N/A
2N/A /* allocate a node for this level */
2N/A if ((pnode = (Prom_node *) malloc(sizeof (struct prom_node))) ==
2N/A NULL) {
2N/A perror("malloc");
2N/A exit(2); /* program errors cause exit 2 */
2N/A }
2N/A
2N/A /* assign parent Prom_node */
2N/A pnode->parent = root;
2N/A pnode->sibling = NULL;
2N/A pnode->child = NULL;
2N/A
2N/A /* read properties for this node */
2N/A dump_node(pnode);
2N/A
2N/A /*
2N/A * Place a node in a 'board' if it has 'board'-ness. The definition
2N/A * is that all nodes that are children of root should have a
2N/A * board# property. But the PROM tree does not exactly follow
2N/A * this. This is where we start hacking. The name 'ffb' can
2N/A * change, so watch out for this.
2N/A *
2N/A * The UltraSPARC, sbus, pci and ffb nodes will exit in
2N/A * the desktops and will not have board# properties. These
2N/A * cases must be handled here.
2N/A *
2N/A * PCI to PCI bridges also have the name "pci", but with different
2N/A * model property values. They should not be put under 'board'.
2N/A */
2N/A name = get_node_name(pnode);
2N/A type = get_node_type(pnode);
2N/A model = (char *)get_prop_val(find_prop(pnode, "model"));
2N/A#ifdef DEBUG
2N/A if (name != NULL)
2N/A printf("name=%s ", name);
2N/A if (type != NULL)
2N/A printf("type=%s ", type);
2N/A if (model != NULL)
2N/A printf("model=%s", model);
2N/A printf("\n");
2N/A#endif
2N/A if (model == NULL)
2N/A model = "";
2N/A if (type == NULL)
2N/A type = "";
2N/A if (name != NULL) {
2N/A if (has_board_num(pnode)) {
2N/A add_node(tree, pnode);
2N/A board_node = 1;
2N/A#ifdef DEBUG
2N/A printf("ADDED BOARD name=%s type=%s model=%s\n",
2N/A name, type, model);
2N/A#endif
2N/A } else if ((strcmp(name, FFB_NAME) == 0) ||
2N/A (strcmp(name, AFB_NAME) == 0) ||
2N/A (strcmp(type, "cpu") == 0) ||
2N/A
2N/A ((strcmp(type, "memory-controller") == 0) &&
2N/A (strcmp(name, "ac") != 0)) ||
2N/A
2N/A ((strcmp(name, "pci") == 0) &&
2N/A (strcmp(model, "SUNW,psycho") == 0)) ||
2N/A
2N/A ((strcmp(name, "pci") == 0) &&
2N/A (strcmp(model, "SUNW,sabre") == 0)) ||
2N/A
2N/A ((strcmp(name, "pci") == 0) &&
2N/A (strcmp(model, "SUNW,schizo") == 0)) ||
2N/A
2N/A ((strcmp(name, "pci") == 0) &&
2N/A (strcmp(model, "SUNW,xmits") == 0)) ||
2N/A
2N/A (strcmp(name, "counter-timer") == 0) ||
2N/A (strcmp(name, "sbus") == 0)) {
2N/A add_node(tree, pnode);
2N/A board_node = 1;
2N/A#ifdef DEBUG
2N/A printf("ADDED BOARD name=%s type=%s model=%s\n",
2N/A name, type, model);
2N/A#endif
2N/A }
2N/A#ifdef DEBUG
2N/A else
2N/A printf("node not added: name=%s type=%s\n", name, type);
2N/A#endif
2N/A }
2N/A
2N/A if (curnode = child(id)) {
2N/A pnode->child = walk(tree, pnode, curnode);
2N/A }
2N/A
2N/A if (curnode = next(id)) {
2N/A if (board_node) {
2N/A return (walk(tree, root, curnode));
2N/A } else {
2N/A pnode->sibling = walk(tree, root, curnode);
2N/A }
2N/A }
2N/A
2N/A if (board_node) {
2N/A return (NULL);
2N/A } else {
2N/A return (pnode);
2N/A }
2N/A}