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 (the "License").
2N/A * You may not use this file except in compliance 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 2007 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 <alloca.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 "display.h"
2N/A#include "display_sun4v.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 sun4v platform. The PROM
2N/A * tree-walking functions which contain sun4v 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 *sun4v_walk(Sys_tree *, Prom_node *, int);
2N/Apicl_errno_t sun4v_get_node_by_name(picl_nodehdl_t, char *, picl_nodehdl_t *);
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 picl_nodehdl_t rooth; /* root PICL node for IO display */
2N/A picl_nodehdl_t plafh; /* Platform PICL node for IO display */
2N/A
2N/A picl_errno_t err;
2N/A
2N/A err = picl_initialize();
2N/A if (err != PICL_SUCCESS) {
2N/A (void) fprintf(stderr, EM_INIT_FAIL, picl_strerror(err));
2N/A exit(1);
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 = sun4v_walk(&sys_tree, NULL, next(0));
2N/A promclose();
2N/A
2N/A err = picl_get_root(&rooth);
2N/A if (err != PICL_SUCCESS) {
2N/A (void) fprintf(stderr, EM_GET_ROOT_FAIL, picl_strerror(err));
2N/A exit(1);
2N/A }
2N/A
2N/A err = sun4v_get_node_by_name(rooth, PICL_NODE_PLATFORM, &plafh);
2N/A if (err != PICL_SUCCESS)
2N/A return (err);
2N/A
2N/A return (sun4v_display(&sys_tree, root_node, syserrlog, plafh));
2N/A
2N/A}
2N/A
2N/A/*
2N/A * sun4v_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.
2N/A */
2N/AProm_node *
2N/Asun4v_walk(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 *compatible;
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.
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 compatible = (char *)get_prop_val(find_prop(pnode, "compatible"));
2N/A
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 printf("\n");
2N/A#endif
2N/A if (compatible == NULL)
2N/A compatible = "";
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 compatible=%s\n",
2N/A name, type, compatible);
2N/A#endif
2N/A } else if (strcmp(type, "cpu") == 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 compatible=%s\n",
2N/A name, type, compatible);
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 = sun4v_walk(tree, pnode, curnode);
2N/A }
2N/A
2N/A if (curnode = next(id)) {
2N/A if (board_node) {
2N/A return (sun4v_walk(tree, root, curnode));
2N/A } else {
2N/A pnode->sibling = sun4v_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}
2N/A
2N/A/*
2N/A * search children to get the node by the nodename
2N/A */
2N/Apicl_errno_t
2N/Asun4v_get_node_by_name(picl_nodehdl_t rooth, char *name,
2N/A picl_nodehdl_t *nodeh)
2N/A{
2N/A picl_nodehdl_t childh;
2N/A int err;
2N/A char *nodename;
2N/A
2N/A nodename = alloca(strlen(name) + 1);
2N/A if (nodename == NULL)
2N/A return (PICL_FAILURE);
2N/A
2N/A err = picl_get_propval_by_name(rooth, PICL_PROP_CHILD, &childh,
2N/A sizeof (picl_nodehdl_t));
2N/A
2N/A while (err == PICL_SUCCESS) {
2N/A err = picl_get_propval_by_name(childh, PICL_PROP_NAME,
2N/A nodename, (strlen(name) + 1));
2N/A if (err != PICL_SUCCESS) {
2N/A err = picl_get_propval_by_name(childh, PICL_PROP_PEER,
2N/A &childh, sizeof (picl_nodehdl_t));
2N/A continue;
2N/A }
2N/A
2N/A if (strcmp(nodename, name) == 0) {
2N/A *nodeh = childh;
2N/A return (PICL_SUCCESS);
2N/A }
2N/A
2N/A err = picl_get_propval_by_name(childh, PICL_PROP_PEER,
2N/A &childh, sizeof (picl_nodehdl_t));
2N/A }
2N/A
2N/A return (err);
2N/A}
2N/A
2N/Aint
2N/Aget_id(Prom_node *node)
2N/A{
2N/A#ifdef lint
2N/A node = node;
2N/A#endif
2N/A
2N/A /*
2N/A * This function is intentionally empty
2N/A */
2N/A return (0);
2N/A}