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 (c) 1999-2001 by Sun Microsystems, Inc.
2N/A * All rights reserved.
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 <unistd.h>
2N/A#include <ctype.h>
2N/A#include <string.h>
2N/A#include <kvm.h>
2N/A#include <varargs.h>
2N/A#include <errno.h>
2N/A#include <time.h>
2N/A#include <dirent.h>
2N/A#include <fcntl.h>
2N/A#include <sys/param.h>
2N/A#include <sys/stat.h>
2N/A#include <sys/types.h>
2N/A#include <sys/utsname.h>
2N/A#include <sys/openpromio.h>
2N/A#include <sys/systeminfo.h>
2N/A#include <kstat.h>
2N/A#include <libintl.h>
2N/A#include <syslog.h>
2N/A#include <sys/dkio.h>
2N/A#include "pdevinfo.h"
2N/A#include "display.h"
2N/A#include "pdevinfo_sun4u.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/AProm_node *
2N/Afind_pci_bus(Prom_node *node, int id, int bus)
2N/A{
2N/A Prom_node *pnode;
2N/A
2N/A /* find the first pci node */
2N/A pnode = dev_find_node(node, "pci");
2N/A
2N/A while (pnode != NULL) {
2N/A int tmp_id;
2N/A int tmp_bus;
2N/A
2N/A tmp_id = get_id(pnode);
2N/A tmp_bus = get_pci_bus(pnode);
2N/A
2N/A if ((tmp_id == id) &&
2N/A (tmp_bus == bus)) {
2N/A break;
2N/A }
2N/A
2N/A pnode = dev_next_node(pnode, "pci");
2N/A }
2N/A return (pnode);
2N/A}
2N/A
2N/A/*
2N/A * get_pci_bus
2N/A *
2N/A * Determines the PCI bus, either A (0) or B (1). If the function cannot
2N/A * find the bus-ranges property, it returns -1.
2N/A */
2N/Aint
2N/Aget_pci_bus(Prom_node *pnode)
2N/A{
2N/A int *value;
2N/A
2N/A /* look up the bus-range property */
2N/A if ((value = (int *)get_prop_val(find_prop(pnode, "bus-range"))) ==
2N/A NULL) {
2N/A return (-1);
2N/A }
2N/A
2N/A if (*value == 0) {
2N/A return (1); /* B bus has a bus-range value = 0 */
2N/A } else {
2N/A return (0);
2N/A }
2N/A}
2N/A
2N/A
2N/A
2N/A/*
2N/A * Find the PCI device number of this PCI device. If no device number can
2N/A * be determined, then return -1.
2N/A */
2N/Aint
2N/Aget_pci_device(Prom_node *pnode)
2N/A{
2N/A void *value;
2N/A
2N/A if ((value = get_prop_val(find_prop(pnode, "assigned-addresses"))) !=
2N/A NULL) {
2N/A return (PCI_DEVICE(*(int *)value));
2N/A } else {
2N/A return (-1);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Find the PCI device number of this PCI device. If no device number can
2N/A * be determined, then return -1.
2N/A */
2N/Aint
2N/Aget_pci_to_pci_device(Prom_node *pnode)
2N/A{
2N/A void *value;
2N/A
2N/A if ((value = get_prop_val(find_prop(pnode, "reg"))) !=
2N/A NULL) {
2N/A return (PCI_DEVICE(*(int *)value));
2N/A } else {
2N/A return (-1);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * free_io_cards
2N/A * Frees the memory allocated for an io card list.
2N/A */
2N/Avoid
2N/Afree_io_cards(struct io_card *card_list)
2N/A{
2N/A /* Free the list */
2N/A if (card_list != NULL) {
2N/A struct io_card *p, *q;
2N/A
2N/A for (p = card_list, q = NULL; p != NULL; p = q) {
2N/A q = p->next;
2N/A free(p);
2N/A }
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * insert_io_card
2N/A * Inserts an io_card structure into the list. The list is maintained
2N/A * in order based on board number and slot number. Also, the storage
2N/A * for the "card" argument is assumed to be handled by the caller,
2N/A * so we won't touch it.
2N/A */
2N/Astruct io_card *
2N/Ainsert_io_card(struct io_card *list, struct io_card *card)
2N/A{
2N/A struct io_card *newcard;
2N/A struct io_card *p, *q;
2N/A
2N/A if (card == NULL)
2N/A return (list);
2N/A
2N/A /* Copy the card to be added into new storage */
2N/A newcard = (struct io_card *)malloc(sizeof (struct io_card));
2N/A if (newcard == NULL) {
2N/A perror("malloc");
2N/A exit(2);
2N/A }
2N/A (void) memcpy(newcard, card, sizeof (struct io_card));
2N/A newcard->next = NULL;
2N/A
2N/A if (list == NULL)
2N/A return (newcard);
2N/A
2N/A /* Find the proper place in the list for the new card */
2N/A for (p = list, q = NULL; p != NULL; q = p, p = p->next) {
2N/A if (newcard->board < p->board)
2N/A break;
2N/A if ((newcard->board == p->board) && (newcard->slot < p->slot))
2N/A break;
2N/A }
2N/A
2N/A /* Insert the new card into the list */
2N/A if (q == NULL) {
2N/A newcard->next = p;
2N/A return (newcard);
2N/A } else {
2N/A newcard->next = p;
2N/A q->next = newcard;
2N/A return (list);
2N/A }
2N/A}
2N/A
2N/A
2N/Achar *
2N/Afmt_manf_id(unsigned int encoded_id, char *outbuf)
2N/A{
2N/A union manuf manuf;
2N/A
2N/A /*
2N/A * Format the manufacturer's info. Note a small inconsistency we
2N/A * have to work around - Brooktree has it's part number in decimal,
2N/A * while Mitsubishi has it's part number in hex.
2N/A */
2N/A manuf.encoded_id = encoded_id;
2N/A switch (manuf.fld.manf) {
2N/A case MANF_BROOKTREE:
2N/A (void) sprintf(outbuf, "%s %d, version %d", "Brooktree",
2N/A manuf.fld.partno, manuf.fld.version);
2N/A break;
2N/A
2N/A case MANF_MITSUBISHI:
2N/A (void) sprintf(outbuf, "%s %x, version %d", "Mitsubishi",
2N/A manuf.fld.partno, manuf.fld.version);
2N/A break;
2N/A
2N/A default:
2N/A (void) sprintf(outbuf, "JED code %d, Part num 0x%x, version %d",
2N/A manuf.fld.manf, manuf.fld.partno, manuf.fld.version);
2N/A }
2N/A return (outbuf);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Find the sbus slot number of this Sbus device. If no slot number can
2N/A * be determined, then return -1.
2N/A */
2N/Aint
2N/Aget_sbus_slot(Prom_node *pnode)
2N/A{
2N/A void *value;
2N/A
2N/A if ((value = get_prop_val(find_prop(pnode, "reg"))) != NULL) {
2N/A return (*(int *)value);
2N/A } else {
2N/A return (-1);
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * This routine is the generic link into displaying system IO
2N/A * configuration. It displays the table header, then displays
2N/A * all the SBus cards, then displays all fo the PCI IO cards.
2N/A */
2N/Avoid
2N/Adisplay_io_devices(Sys_tree *tree)
2N/A{
2N/A Board_node *bnode;
2N/A
2N/A /*
2N/A * TRANSLATION_NOTE
2N/A * Following string is used as a table header.
2N/A * Please maintain the current alignment in
2N/A * translation.
2N/A */
2N/A log_printf("\n", 0);
2N/A log_printf("=========================", 0);
2N/A log_printf(dgettext(TEXT_DOMAIN, " IO Cards "), 0);
2N/A log_printf("=========================", 0);
2N/A log_printf("\n", 0);
2N/A log_printf("\n", 0);
2N/A bnode = tree->bd_list;
2N/A while (bnode != NULL) {
2N/A display_sbus(bnode);
2N/A display_pci(bnode);
2N/A display_ffb(bnode, 1);
2N/A bnode = bnode->next;
2N/A }
2N/A}
2N/A
2N/Avoid
2N/Adisplay_pci(Board_node *bnode)
2N/A{
2N/A#ifdef lint
2N/A bnode = bnode;
2N/A#endif
2N/A /*
2N/A * This function is intentionally empty
2N/A */
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Print out all the io cards in the list. Also print the column
2N/A * headers if told to do so.
2N/A */
2N/Avoid
2N/Adisplay_io_cards(struct io_card *list)
2N/A{
2N/A static int banner = 0; /* Have we printed the column headings? */
2N/A struct io_card *p;
2N/A
2N/A if (list == NULL)
2N/A return;
2N/A
2N/A if (banner == 0) {
2N/A log_printf(" Bus Freq\n", 0);
2N/A log_printf("Brd Type MHz Slot "
2N/A "Name "
2N/A "Model", 0);
2N/A log_printf("\n", 0);
2N/A log_printf("--- ---- ---- ---------- "
2N/A "---------------------------- "
2N/A "--------------------", 0);
2N/A log_printf("\n", 0);
2N/A banner = 1;
2N/A }
2N/A
2N/A for (p = list; p != NULL; p = p -> next) {
2N/A log_printf("%2d ", p->board, 0);
2N/A log_printf("%-4s ", p->bus_type, 0);
2N/A log_printf("%3d ", p->freq, 0);
2N/A /*
2N/A * We check to see if it's an int or
2N/A * a char string to display for slot.
2N/A */
2N/A if (p->slot == PCI_SLOT_IS_STRING)
2N/A log_printf("%10s ", p->slot_str, 0);
2N/A else
2N/A log_printf("%10d ", p->slot, 0);
2N/A
2N/A log_printf("%-28.28s", p->name, 0);
2N/A if (strlen(p->name) > 28)
2N/A log_printf("+ ", 0);
2N/A else
2N/A log_printf(" ", 0);
2N/A log_printf("%-19.19s", p->model, 0);
2N/A if (strlen(p->model) > 19)
2N/A log_printf("+", 0);
2N/A log_printf("\n", 0);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Display all FFBs on this board. It can either be in tabular format,
2N/A * or a more verbose format.
2N/A */
2N/Avoid
2N/Adisplay_ffb(Board_node *board, int table)
2N/A{
2N/A Prom_node *fb;
2N/A void *value;
2N/A struct io_card *card_list = NULL;
2N/A struct io_card card;
2N/A char *type;
2N/A char *label;
2N/A
2N/A if (board == NULL)
2N/A return;
2N/A
2N/A /* Fill in common information */
2N/A card.display = 1;
2N/A card.board = board->board_num;
2N/A (void) sprintf(card.bus_type, BUS_TYPE);
2N/A card.freq = sys_clk;
2N/A
2N/A for (fb = dev_find_node_by_type(board->nodes, "device_type", "display");
2N/A fb != NULL;
2N/A fb = dev_next_node_by_type(fb, "device_type", "display")) {
2N/A value = get_prop_val(find_prop(fb, "name"));
2N/A if (value != NULL) {
2N/A if ((strcmp(FFB_NAME, value)) == 0) {
2N/A type = FFB_NAME;
2N/A label = "FFB";
2N/A } else if ((strcmp(AFB_NAME, value)) == 0) {
2N/A type = AFB_NAME;
2N/A label = "AFB";
2N/A } else
2N/A continue;
2N/A } else
2N/A continue;
2N/A if (table == 1) {
2N/A /* Print out in table format */
2N/A
2N/A /* XXX - Get the slot number (hack) */
2N/A card.slot = get_id(fb);
2N/A
2N/A /* Find out if it's single or double buffered */
2N/A (void) sprintf(card.name, "%s", label);
2N/A value = get_prop_val(find_prop(fb, "board_type"));
2N/A if (value != NULL)
2N/A if ((*(int *)value) & FFB_B_BUFF)
2N/A (void) sprintf(card.name,
2N/A "%s, Double Buffered", label);
2N/A else
2N/A (void) sprintf(card.name,
2N/A "%s, Single Buffered", label);
2N/A
2N/A /*
2N/A * Print model number only if board_type bit 2
2N/A * is not set and it is not SUNW,XXX-XXXX.
2N/A */
2N/A card.model[0] = '\0';
2N/A
2N/A if (strcmp(type, AFB_NAME) == 0) {
2N/A if (((*(int *)value) & 0x4) != 0x4) {
2N/A value = get_prop_val(find_prop(fb,
2N/A "model"));
2N/A if ((value != NULL) &&
2N/A (strcmp(value,
2N/A "SUNW,XXX-XXXX") != 0)) {
2N/A (void) sprintf(card.model, "%s",
2N/A (char *)value);
2N/A }
2N/A }
2N/A } else {
2N/A value = get_prop_val(find_prop(fb, "model"));
2N/A if (value != NULL)
2N/A (void) sprintf(card.model, "%s",
2N/A (char *)value);
2N/A }
2N/A
2N/A card_list = insert_io_card(card_list, &card);
2N/A } else {
2N/A /* print in long format */
2N/A char device[MAXSTRLEN];
2N/A int fd = -1;
2N/A struct dirent *direntp;
2N/A DIR *dirp;
2N/A union strap_un strap;
2N/A struct ffb_sys_info fsi;
2N/A
2N/A /* Find the device node using upa-portid/portid */
2N/A value = get_prop_val(find_prop(fb, "upa-portid"));
2N/A if (value == NULL)
2N/A value = get_prop_val(find_prop(fb, "portid"));
2N/A
2N/A if (value == NULL)
2N/A continue;
2N/A
2N/A (void) sprintf(device, "%s@%x", type,
2N/A *(int *)value);
2N/A if ((dirp = opendir("/devices")) == NULL)
2N/A continue;
2N/A
2N/A while ((direntp = readdir(dirp)) != NULL) {
2N/A if (strstr(direntp->d_name, device) != NULL) {
2N/A (void) sprintf(device, "/devices/%s",
2N/A direntp->d_name);
2N/A fd = open(device, O_RDWR, 0666);
2N/A break;
2N/A }
2N/A }
2N/A (void) closedir(dirp);
2N/A
2N/A if (fd == -1)
2N/A continue;
2N/A
2N/A if (ioctl(fd, FFB_SYS_INFO, &fsi) < 0)
2N/A continue;
2N/A
2N/A log_printf("%s Hardware Configuration:\n", label, 0);
2N/A log_printf("-----------------------------------\n", 0);
2N/A
2N/A strap.ffb_strap_bits = fsi.ffb_strap_bits;
2N/A log_printf("\tBoard rev: %d\n",
2N/A (int)strap.fld.board_rev, 0);
2N/A log_printf("\tFBC version: 0x%x\n", fsi.fbc_version, 0);
2N/A log_printf("\tDAC: %s\n",
2N/A fmt_manf_id(fsi.dac_version, device), 0);
2N/A log_printf("\t3DRAM: %s\n",
2N/A fmt_manf_id(fsi.fbram_version, device), 0);
2N/A log_printf("\n", 0);
2N/A }
2N/A
2N/A }
2N/A display_io_cards(card_list);
2N/A free_io_cards(card_list);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Display all the SBus IO cards on this board.
2N/A */
2N/Avoid
2N/Adisplay_sbus(Board_node *board)
2N/A{
2N/A struct io_card card;
2N/A struct io_card *card_list = NULL;
2N/A int freq;
2N/A int card_num;
2N/A void *value;
2N/A Prom_node *sbus;
2N/A Prom_node *card_node;
2N/A
2N/A if (board == NULL)
2N/A return;
2N/A
2N/A for (sbus = dev_find_node(board->nodes, SBUS_NAME); sbus != NULL;
2N/A sbus = dev_next_node(sbus, SBUS_NAME)) {
2N/A
2N/A /* Skip failed nodes for now */
2N/A if (node_failed(sbus))
2N/A continue;
2N/A
2N/A /* Calculate SBus frequency in MHz */
2N/A value = get_prop_val(find_prop(sbus, "clock-frequency"));
2N/A if (value != NULL)
2N/A freq = ((*(int *)value) + 500000) / 1000000;
2N/A else
2N/A freq = -1;
2N/A
2N/A for (card_node = sbus->child; card_node != NULL;
2N/A card_node = card_node->sibling) {
2N/A char *model;
2N/A char *name;
2N/A char *child_name;
2N/A
2N/A card_num = get_sbus_slot(card_node);
2N/A if (card_num == -1)
2N/A continue;
2N/A
2N/A /* Fill in card information */
2N/A card.display = 1;
2N/A card.freq = freq;
2N/A card.board = board->board_num;
2N/A (void) sprintf(card.bus_type, "SBus");
2N/A card.slot = card_num;
2N/A card.status[0] = '\0';
2N/A
2N/A /* Try and get card status */
2N/A value = get_prop_val(find_prop(card_node, "status"));
2N/A if (value != NULL)
2N/A (void) strncpy(card.status, (char *)value,
2N/A MAXSTRLEN);
2N/A
2N/A /* XXX - For now, don't display failed cards */
2N/A if (strstr(card.status, "fail") != NULL)
2N/A continue;
2N/A
2N/A /* Now gather all of the node names for that card */
2N/A model = (char *)get_prop_val(find_prop(card_node,
2N/A "model"));
2N/A name = get_node_name(card_node);
2N/A
2N/A if (name == NULL)
2N/A continue;
2N/A
2N/A card.name[0] = '\0';
2N/A card.model[0] = '\0';
2N/A
2N/A /* Figure out how we want to display the name */
2N/A child_name = get_node_name(card_node->child);
2N/A if ((card_node->child != NULL) &&
2N/A (child_name != NULL)) {
2N/A value = get_prop_val(find_prop(card_node->child,
2N/A "device_type"));
2N/A if (value != NULL)
2N/A (void) sprintf(card.name, "%s/%s (%s)",
2N/A name, child_name,
2N/A (char *)value);
2N/A else
2N/A (void) sprintf(card.name, "%s/%s", name,
2N/A child_name);
2N/A } else {
2N/A (void) strncpy(card.name, name, MAXSTRLEN);
2N/A }
2N/A
2N/A if (model != NULL)
2N/A (void) strncpy(card.model, model, MAXSTRLEN);
2N/A
2N/A card_list = insert_io_card(card_list, &card);
2N/A }
2N/A }
2N/A
2N/A /* We're all done gathering card info, now print it out */
2N/A display_io_cards(card_list);
2N/A free_io_cards(card_list);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Get slot-names properties from parent node and
2N/A * store them in an array.
2N/A */
2N/Aint
2N/Apopulate_slot_name_arr(Prom_node *pci, int *slot_name_bits,
2N/A char **slot_name_arr, int num_slots)
2N/A{
2N/A int i, j, bit_mask;
2N/A char *value;
2N/A
2N/A value = (char *)get_prop_val(find_prop(pci, "slot-names"));
2N/A D_PRINTF("\n populate_slot_name_arr: value = [0x%x]\n", value);
2N/A
2N/A if (value != NULL) {
2N/A char *strings_arr[MAX_SLOTS_PER_IO_BD];
2N/A bit_mask = *slot_name_bits = *(int *)value;
2N/A D_PRINTF("\nslot_names 1st integer = [0x%x]", *slot_name_bits);
2N/A
2N/A /* array starts after first int */
2N/A strings_arr[0] = value + sizeof (int);
2N/A
2N/A /*
2N/A * break the array out into num_slots number of strings
2N/A */
2N/A for (i = 1; i < num_slots; i++) {
2N/A strings_arr[i] = (char *)strings_arr[i - 1]
2N/A + strlen(strings_arr[i - 1]) + 1;
2N/A }
2N/A
2N/A /*
2N/A * process array of slot_names to remove blanks
2N/A */
2N/A j = 0;
2N/A for (i = 0; i < num_slots; i++) {
2N/A if ((bit_mask >> i) & 0x1)
2N/A slot_name_arr[i] = strings_arr[j++];
2N/A else
2N/A slot_name_arr[i] = "";
2N/A
2N/A D_PRINTF("\nslot_name_arr[%d] = [%s]", i,
2N/A slot_name_arr[i]);
2N/A }
2N/A return (0);
2N/A } else {
2N/A D_PRINTF("\n populate_slot_name_arr: - psycho with no "
2N/A "slot-names\n");
2N/A return (0);
2N/A }
2N/A}
2N/A
2N/Aint
2N/Aget_card_frequency(Prom_node *pci)
2N/A{
2N/A char *value = get_prop_val(find_prop(pci, "clock-frequency"));
2N/A
2N/A if (value == NULL)
2N/A return (-1);
2N/A else
2N/A return (int)(((*(int *)value) + 500000) / 1000000);
2N/A
2N/A}
2N/A
2N/Avoid
2N/Aget_dev_func_num(Prom_node *card_node, int *dev_no, int *func_no)
2N/A{
2N/A
2N/A void *value = get_prop_val(find_prop(card_node, "reg"));
2N/A
2N/A if (value != NULL) {
2N/A int int_val = *(int *)value;
2N/A *dev_no = PCI_REG_TO_DEV(int_val);
2N/A *func_no = PCI_REG_TO_FUNC(int_val);
2N/A } else {
2N/A *dev_no = -1;
2N/A *func_no = -1;
2N/A }
2N/A}
2N/A
2N/Avoid
2N/Aget_pci_class_codes(Prom_node *card_node, int *class_code, int *subclass_code)
2N/A{
2N/A int class_code_reg = get_pci_class_code_reg(card_node);
2N/A
2N/A *class_code = CLASS_REG_TO_CLASS(class_code_reg);
2N/A *subclass_code = CLASS_REG_TO_SUBCLASS(class_code_reg);
2N/A}
2N/A
2N/Aint
2N/Ais_pci_bridge(Prom_node *card_node, char *name)
2N/A{
2N/A int class_code, subclass_code;
2N/A
2N/A if (card_node == NULL)
2N/A return (FALSE);
2N/A
2N/A get_pci_class_codes(card_node, &class_code, &subclass_code);
2N/A
2N/A if ((strncmp(name, "pci", 3) == 0) &&
2N/A (class_code == PCI_BRIDGE_CLASS) &&
2N/A (subclass_code == PCI_PCI_BRIDGE_SUBCLASS))
2N/A return (TRUE);
2N/A else
2N/A return (FALSE);
2N/A}
2N/A
2N/Aint
2N/Ais_pci_bridge_other(Prom_node *card_node, char *name)
2N/A{
2N/A int class_code, subclass_code;
2N/A
2N/A if (card_node == NULL)
2N/A return (FALSE);
2N/A
2N/A get_pci_class_codes(card_node, &class_code, &subclass_code);
2N/A
2N/A if ((strncmp(name, "pci", 3) == 0) &&
2N/A (class_code == PCI_BRIDGE_CLASS) &&
2N/A (subclass_code == PCI_SUBCLASS_OTHER))
2N/A return (TRUE);
2N/A else
2N/A return (FALSE);
2N/A}
2N/Avoid
2N/Aget_pci_card_model(Prom_node *card_node, char *model)
2N/A{
2N/A char *name = get_prop_val(find_prop(card_node, "name"));
2N/A char *value = get_prop_val(find_prop(card_node, "model"));
2N/A int pci_bridge = is_pci_bridge(card_node, name);
2N/A
2N/A if (value == NULL)
2N/A model[0] = '\0';
2N/A else
2N/A (void) sprintf(model, "%s",
2N/A (char *)value);
2N/A
2N/A if (pci_bridge) {
2N/A if (strlen(model) == 0)
2N/A (void) sprintf(model,
2N/A "%s", "pci-bridge");
2N/A else
2N/A (void) sprintf(model,
2N/A "%s/pci-bridge", model);
2N/A }
2N/A}
2N/A
2N/Avoid
2N/Acreate_io_card_name(Prom_node *card_node, char *name, char *card_name)
2N/A{
2N/A char *value = get_prop_val(find_prop(card_node, "compatible"));
2N/A char *child_name;
2N/A char buf[MAXSTRLEN];
2N/A
2N/A if (value != NULL) {
2N/A (void) sprintf(buf, "%s-%s", name,
2N/A (char *)value);
2N/A } else
2N/A (void) sprintf(buf, "%s", name);
2N/A
2N/A name = buf;
2N/A
2N/A child_name = (char *)get_node_name(card_node->child);
2N/A
2N/A if ((card_node->child != NULL) &&
2N/A (child_name != NULL)) {
2N/A value = get_prop_val(find_prop(card_node->child,
2N/A "device_type"));
2N/A if (value != NULL)
2N/A (void) sprintf(card_name, "%s/%s (%s)",
2N/A name, child_name,
2N/A (char *)value);
2N/A else
2N/A (void) sprintf(card_name, "%s/%s", name,
2N/A child_name);
2N/A } else {
2N/A (void) sprintf(card_name, "%s", (char *)name);
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Desktop display_psycho_pci
2N/A * Display all the psycho based PCI IO cards on this board.
2N/A */
2N/A
2N/A/* ARGSUSED */
2N/Avoid
2N/Adisplay_psycho_pci(Board_node *board)
2N/A{
2N/A struct io_card *card_list = NULL;
2N/A struct io_card card;
2N/A void *value;
2N/A
2N/A Prom_node *pci, *card_node, *pci_bridge_node = NULL;
2N/A char *name;
2N/A int slot_name_bits, pci_bridge_dev_no,
2N/A class_code, subclass_code,
2N/A pci_pci_bridge;
2N/A char *slot_name_arr[MAX_SLOTS_PER_IO_BD];
2N/A
2N/A if (board == NULL)
2N/A return;
2N/A
2N/A /* Initialize all the common information */
2N/A card.display = 1;
2N/A card.board = board->board_num;
2N/A (void) sprintf(card.bus_type, "PCI");
2N/A
2N/A for (pci = dev_find_node_by_type(board->nodes, "model", "SUNW,psycho");
2N/A pci != NULL;
2N/A pci = dev_next_node_by_type(pci, "model", "SUNW,psycho")) {
2N/A
2N/A /*
2N/A * If we have reached a pci-to-pci bridge node,
2N/A * we are one level below the 'pci' nodes level
2N/A * in the device tree. To get back to that level,
2N/A * the search should continue with the sibling of
2N/A * the parent or else the remaining 'pci' cards
2N/A * will not show up in the output.
2N/A */
2N/A if (find_prop(pci, "upa-portid") == NULL) {
2N/A if ((pci->parent->sibling != NULL) &&
2N/A (strcmp(get_prop_val(
2N/A find_prop(pci->parent->sibling,
2N/A "name")), PCI_NAME) == 0))
2N/A pci = pci->parent->sibling;
2N/A else {
2N/A pci = pci->parent->sibling;
2N/A continue;
2N/A }
2N/A }
2N/A
2N/A D_PRINTF("\n\n------->Looking at device [%s][%d] - [%s]\n",
2N/A PCI_NAME, *((int *)get_prop_val(find_prop(
2N/A pci, "upa-portid"))),
2N/A get_prop_val(find_prop(pci, "model")));
2N/A
2N/A /* Skip all failed nodes for now */
2N/A if (node_failed(pci))
2N/A continue;
2N/A
2N/A /* Fill in frequency */
2N/A card.freq = get_card_frequency(pci);
2N/A
2N/A /*
2N/A * Each PSYCHO device has a slot-names property that can be
2N/A * used to determine the slot-name string for each IO
2N/A * device under this node. We get this array now and use
2N/A * it later when looking at the children of this PSYCHO.
2N/A */
2N/A if ((populate_slot_name_arr(pci, &slot_name_bits,
2N/A (char **)&slot_name_arr, MAX_SLOTS_PER_IO_BD)) != 0)
2N/A goto next_card;
2N/A
2N/A /* Walk through the PSYCHO children */
2N/A card_node = pci->child;
2N/A while (card_node != NULL) {
2N/A
2N/A pci_pci_bridge = FALSE;
2N/A
2N/A /* If it doesn't have a name, skip it */
2N/A name = (char *)get_prop_val(
2N/A find_prop(card_node, "name"));
2N/A if (name == NULL)
2N/A goto next_card;
2N/A
2N/A /* get dev# and func# for this card. */
2N/A get_dev_func_num(card_node, &card.dev_no,
2N/A &card.func_no);
2N/A
2N/A /* get class/subclass code for this card. */
2N/A get_pci_class_codes(card_node, &class_code,
2N/A &subclass_code);
2N/A
2N/A D_PRINTF("\nName [%s] - ", name);
2N/A D_PRINTF("device no [%d] - ", card.dev_no);
2N/A D_PRINTF("class_code [%d] subclass_code [%d] - ",
2N/A class_code, subclass_code);
2N/A
2N/A /*
2N/A * Weed out PCI Bridge, subclass 'other' and
2N/A * ebus nodes.
2N/A */
2N/A if (((class_code == PCI_BRIDGE_CLASS) &&
2N/A (subclass_code == PCI_SUBCLASS_OTHER)) ||
2N/A (strstr(name, "ebus"))) {
2N/A D_PRINTF("\nSkip ebus/class-other nodes [%s]",
2N/A name);
2N/A goto next_card;
2N/A }
2N/A
2N/A /*
2N/A * If this is a PCI bridge, then we store it's dev_no
2N/A * so that it's children can use it for getting at
2N/A * the slot_name.
2N/A */
2N/A if (is_pci_bridge(card_node, name)) {
2N/A pci_bridge_dev_no = card.dev_no;
2N/A pci_bridge_node = card_node;
2N/A pci_pci_bridge = TRUE;
2N/A D_PRINTF("\nPCI Bridge detected\n");
2N/A }
2N/A
2N/A /*
2N/A * If we are the child of a pci_bridge we use the
2N/A * dev# of the pci_bridge as an index to get
2N/A * the slot number. We know that we are a child of
2N/A * a pci-bridge if our parent is the same as the last
2N/A * pci_bridge node found above.
2N/A */
2N/A if (card_node->parent == pci_bridge_node)
2N/A card.dev_no = pci_bridge_dev_no;
2N/A
2N/A /* Get slot-names property from slot_names_arr. */
2N/A get_slot_number_str(&card, (char **)slot_name_arr,
2N/A slot_name_bits);
2N/A
2N/A if (slot_name_bits)
2N/A D_PRINTF("\nIO Card [%s] dev_no [%d] SlotStr "
2N/A "[%s] slot [%s]", name, card.dev_no,
2N/A slot_name_arr[card.dev_no],
2N/A card.slot_str);
2N/A
2N/A /* XXX - Don't know how to get status for PCI cards */
2N/A card.status[0] = '\0';
2N/A
2N/A /* Get the model of this card */
2N/A get_pci_card_model(card_node, (char *)&card.model);
2N/A
2N/A /*
2N/A * If we haven't figured out the frequency yet,
2N/A * try and get it from the card.
2N/A */
2N/A value = get_prop_val(find_prop(pci, "clock-frequency"));
2N/A if (value != NULL && card.freq == -1)
2N/A card.freq = ((*(int *)value) + 500000)
2N/A / 1000000;
2N/A
2N/A
2N/A /* Figure out how we want to display the name */
2N/A create_io_card_name(card_node, name,
2N/A (char *)&card.name);
2N/A
2N/A if (card.freq != -1)
2N/A card_list = insert_io_card(card_list, &card);
2N/A
2N/Anext_card:
2N/A /*
2N/A * If we are done with the children of the pci bridge,
2N/A * we must continue with the remaining siblings of
2N/A * the pci-to-pci bridge - otherwise we move onto our
2N/A * own sibling.
2N/A */
2N/A if (pci_pci_bridge) {
2N/A if (card_node->child != NULL)
2N/A card_node = card_node->child;
2N/A else
2N/A card_node = card_node->sibling;
2N/A } else {
2N/A if ((card_node->parent == pci_bridge_node) &&
2N/A (card_node->sibling == NULL))
2N/A card_node = pci_bridge_node->sibling;
2N/A else
2N/A card_node = card_node->sibling;
2N/A }
2N/A } /* end-while */
2N/A } /* end-for */
2N/A
2N/A D_PRINTF("\n\n");
2N/A
2N/A display_io_cards(card_list);
2N/A free_io_cards(card_list);
2N/A}
2N/A
2N/Avoid
2N/Aget_slot_number_str(struct io_card *card, char **slot_name_arr,
2N/A int slot_name_bits)
2N/A{
2N/A if (card->dev_no != -1) {
2N/A char *slot;
2N/A /*
2N/A * slot_name_bits is a mask of the plug-in slots so if our
2N/A * dev_no does not appear in this mask we must be an
2N/A * on_board device so set the slot to 'On-Board'
2N/A */
2N/A if (slot_name_bits & (1 << card->dev_no)) {
2N/A /* we are a plug-in card */
2N/A slot = slot_name_arr[card->dev_no];
2N/A if (strlen(slot) != 0) {
2N/A (void) sprintf(card->slot_str, "%s",
2N/A slot);
2N/A } else
2N/A (void) sprintf(card->slot_str, "-");
2N/A } else {
2N/A /* this is an on-board dev. */
2N/A sprintf(card->slot_str, "On-Board");
2N/A }
2N/A
2N/A } else {
2N/A (void) sprintf(card->slot_str, "%c", '-');
2N/A }
2N/A
2N/A /* Informs display_io_cards to print slot_str instead of slot */
2N/A card->slot = PCI_SLOT_IS_STRING;
2N/A}
2N/A
2N/A
2N/A/*
2N/A * The output of a number of I/O cards are identical so we need to
2N/A * differentiate between them.
2N/A *
2N/A * This function is called by the platform specific code and it decides
2N/A * if the card needs further processing.
2N/A *
2N/A * It can be extended in the future if card types other than QLC have
2N/A * the same problems.
2N/A */
2N/Avoid
2N/Adistinguish_identical_io_cards(char *name, Prom_node *node,
2N/A struct io_card *card)
2N/A{
2N/A if ((name == NULL) || (node == NULL))
2N/A return;
2N/A
2N/A if (strcmp(name, "SUNW,qlc") == 0)
2N/A decode_qlc_card_model_prop(node, card);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * The name/model properties for a number of the QLC FCAL PCI cards are
2N/A * identical (*), so we need to distinguish them using the subsystem-id
2N/A * and modify the model string to be more informative.
2N/A *
2N/A * (*) Currently the problem cards are:
2N/A * Amber
2N/A * Crystal+
2N/A */
2N/Avoid
2N/Adecode_qlc_card_model_prop(Prom_node *card_node, struct io_card *card)
2N/A{
2N/A void *value = NULL;
2N/A
2N/A if (card_node == NULL)
2N/A return;
2N/A
2N/A value = get_prop_val(find_prop(card_node, "subsystem-id"));
2N/A if (value != NULL) {
2N/A int id = *(int *)value;
2N/A
2N/A switch (id) {
2N/A case AMBER_SUBSYSTEM_ID:
2N/A (void) snprintf(card->model, MAX_QLC_MODEL_LEN, "%s",
2N/A AMBER_CARD_NAME);
2N/A break;
2N/A
2N/A case CRYSTAL_SUBSYSTEM_ID:
2N/A (void) snprintf(card->model, MAX_QLC_MODEL_LEN, "%s",
2N/A CRYSTAL_CARD_NAME);
2N/A break;
2N/A
2N/A default:
2N/A /*
2N/A * If information has been saved into the model field
2N/A * before this function was called we will keep it as
2N/A * it probably will be more meaningful that the
2N/A * subsystem-id, otherwise we save the subsystem-id in
2N/A * the hope that it will distinguish the cards.
2N/A */
2N/A if (strcmp(card->model, "") == 0) {
2N/A (void) snprintf(card->model, MAX_QLC_MODEL_LEN,
2N/A "0x%x", id);
2N/A }
2N/A break;
2N/A }
2N/A }
2N/A}