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/*
2N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <stdarg.h>
2N/A#include <string.h>
2N/A#include <strings.h>
2N/A#include <libnvpair.h>
2N/A#include <kstat.h>
2N/A#include <unistd.h>
2N/A#include <sys/types.h>
2N/A#include <fm/topo_mod.h>
2N/A#include <sys/devfm.h>
2N/A#include <fm/fmd_agent.h>
2N/A
2N/A#define BUFSZ 128
2N/A
2N/Achar *
2N/Aget_fmtstr(topo_mod_t *mod, nvlist_t *in)
2N/A{
2N/A char *fmtstr;
2N/A nvlist_t *args;
2N/A int ret;
2N/A
2N/A topo_mod_dprintf(mod, "get_fmtstr() called\n");
2N/A
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A (void) topo_mod_seterrno(mod, EMOD_NVL_INVAL);
2N/A return (NULL);
2N/A }
2N/A if ((ret = nvlist_lookup_string(args, "format", &fmtstr)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'format' arg (%s)\n",
2N/A strerror(ret));
2N/A (void) topo_mod_seterrno(mod, EMOD_NVL_INVAL);
2N/A return (NULL);
2N/A }
2N/A return (fmtstr);
2N/A}
2N/A
2N/Aint
2N/Astore_prop_val(topo_mod_t *mod, char *buf, char *propname, nvlist_t **out)
2N/A{
2N/A if (topo_mod_nvalloc(mod, out, NV_UNIQUE_NAME) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to allocate 'out' nvlist\n");
2N/A return (topo_mod_seterrno(mod, EMOD_NOMEM));
2N/A }
2N/A if (nvlist_add_string(*out, TOPO_PROP_VAL_NAME, propname) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set '%s'\n",
2N/A TOPO_PROP_VAL_NAME);
2N/A nvlist_free(*out);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if (nvlist_add_uint32(*out, TOPO_PROP_VAL_TYPE, TOPO_TYPE_STRING)
2N/A != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set '%s'\n",
2N/A TOPO_PROP_VAL_TYPE);
2N/A nvlist_free(*out);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if (nvlist_add_string(*out, TOPO_PROP_VAL_VAL, buf) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set '%s'\n",
2N/A TOPO_PROP_VAL_VAL);
2N/A nvlist_free(*out);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * This is a somewhat generic property method for labelling the dimm slots on
2N/A * uni-socket x86/x64 platforms. This method assumes a direct linear
2N/A * correlation between the dimm topo node instance number and the dimm slot
2N/A * label number. It takes the following two arguments:
2N/A *
2N/A * format: a string containing a printf-like format with a single %d token
2N/A * which this method computes
2N/A *
2N/A * i.e.: DIMM %d
2N/A *
2N/A * offset: a numeric offset that we'll number the dimms from. This is to
2N/A * allow for the fact that some systems number the dimm slots
2N/A * from zero and others start from one (like the Ultra 20)
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Asimple_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ];
2N/A int ret;
2N/A uint32_t offset;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "simple_dimm_label() called\n");
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr,
2N/A (topo_node_instance(node) + offset));
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * This is a somewhat generic property method for labelling the dimm slots on
2N/A * multi-socket x86/x64 platforms. It takes the following two arguments:
2N/A *
2N/A * format: a string containing a printf-like format with a two %d tokens
2N/A * for the cpu and dimm slot label numbers, which this method
2N/A * computes
2N/A *
2N/A * i.e.: CPU %d DIMM %d
2N/A *
2N/A * offset: a numeric offset that we'll number the dimms from. This is to
2N/A * allow for the fact that some systems number the dimm slots
2N/A * from zero while others may start from one
2N/A *
2N/A * order: "reverse" or "forward" - sets the direction of the correlation
2N/A * between dimm topo node instance number and DIMM slot number
2N/A *
2N/A * dimms_per_chip: the number of DIMM slots per chip
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Asimple_dimm_label_mp(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, *order, buf[BUFSZ];
2N/A tnode_t *chip;
2N/A int ret;
2N/A uint32_t offset, dimms_per_chip;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "simple_dimm_label_mp() called\n");
2N/A
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "dimms_per_chip",
2N/A &dimms_per_chip)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'dimms_per_chip' arg "
2N/A "(%s)\n", strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_string(args, "order", &order)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'order' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A topo_mod_free(mod, order, BUFSZ);
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A chip = topo_node_parent(topo_node_parent(node));
2N/A
2N/A if (strcasecmp(order, "forward") == 0)
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip),
2N/A (topo_node_instance(node) + offset));
2N/A else if (strcasecmp(order, "reverse") == 0)
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip),
2N/A (((topo_node_instance(chip) + 1) * dimms_per_chip)
2N/A - (topo_node_instance(node)) - 1 + offset));
2N/A else {
2N/A topo_mod_dprintf(mod, "Invalid value for order arg\n");
2N/A topo_mod_free(mod, order, BUFSZ);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A topo_mod_free(mod, order, BUFSZ);
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * This method assumes a correspondence between the dimm topo node instance
2N/A * number and the dimm slot label number, but unlike simple_chip_label_mp, the
2N/A * slot numbers aren't reused between CPU's. This method assumes there
2N/A * are 4 DIMM slots per chip. It takes the following two arguments:
2N/A *
2N/A * format: a string containing a printf-like format with a single %d token
2N/A * which this method computes
2N/A *
2N/A * i.e.: DIMM %d
2N/A *
2N/A * offset: a numeric offset that we'll number the dimms from. This is to
2N/A * allow for the fact that some systems number the dimm slots
2N/A * from zero and others may start from one
2N/A *
2N/A * order: "reverse" or "forward" - sets the direction of the correlation
2N/A * between dimm topo node instance number and DIMM slot number
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Aseq_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, *order, buf[BUFSZ];
2N/A int ret;
2N/A uint32_t offset;
2N/A nvlist_t *args;
2N/A tnode_t *chip;
2N/A
2N/A topo_mod_dprintf(mod, "seq_dimm_label() called\n");
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_string(args, "order", &order)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'order' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A topo_mod_free(mod, order, BUFSZ);
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A chip = topo_node_parent(topo_node_parent(node));
2N/A
2N/A if (strcasecmp(order, "forward") == 0)
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, ((topo_node_instance(node))
2N/A + (topo_node_instance(chip) * 4) + offset));
2N/A else if (strcasecmp(order, "reverse") == 0)
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr,
2N/A (((topo_node_instance(chip) + 1) * 4)
2N/A - (topo_node_instance(node)) - 1 + offset));
2N/A else {
2N/A topo_mod_dprintf(mod, "Invalid value for order arg\n");
2N/A topo_mod_free(mod, order, BUFSZ);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A topo_mod_free(mod, order, BUFSZ);
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * This is a somewhat generic property method for labelling the CPU sockets on
2N/A * x86/x64 platforms. This method assumes a correspondence between
2N/A * the chip topo node instance number and the CPU socket label number. It takes
2N/A * the following two arguments:
2N/A *
2N/A * format: a string containing a printf-like format with a single %d token
2N/A * which this method computes
2N/A *
2N/A * i.e.: CPU %d
2N/A *
2N/A * offset: a numeric offset that we'll number the CPU's from. This is to
2N/A * allow for the fact that some systems number the CPU sockets
2N/A * from zero and others start from one (like the X4X00-M2 systems)
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Asimple_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ];
2N/A int ret;
2N/A uint32_t offset;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "simple_chip_label() called\n");
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr,
2N/A (topo_node_instance(node) + offset));
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * This is a somewhat generic property method for labelling the CPU sockets on
2N/A * x86/x64 platforms. This method assumes a correspondence between
2N/A * the chip topo node instance number and the CPU socket label number. It takes
2N/A * the following argument:
2N/A *
2N/A * format: a string containing a printf-like format with a single %d token
2N/A * which this method computes
2N/A *
2N/A * i.e.: CPU %d
2N/A *
2N/A * offset: a numeric offset that we'll number the CPU's from. This is to
2N/A * allow for the fact that some systems number the CPU sockets
2N/A * from zero and others start from one (like the X8450 systems)
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Afsb2_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ];
2N/A int ret;
2N/A uint32_t offset;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "fsb2_chip_label() called\n");
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr,
2N/A ((topo_node_instance(node) / 2) + offset));
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * This is a custom property method for generating the CPU slot label for the
2N/A * Galaxy 4E/4F platforms.
2N/A *
2N/A * format: a string containing a printf-like format with a single %c token
2N/A * which this method computes
2N/A *
2N/A * i.e.: CPU %c
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Ag4_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ], slot_id;
2N/A int err, htid, mapidx;
2N/A uint32_t num_nodes;
2N/A /*
2N/A * G4 HT node ID to FRU label translation. The g4map array
2N/A * is indexed by (number of coherent nodes) / 2 - 1.
2N/A * The value for a given number of nodes is a char array
2N/A * indexed by node ID.
2N/A */
2N/A const char *g4map[] = {
2N/A "AB", /* 2 nodes */
2N/A "ADEH", /* 4 nodes */
2N/A "ABDEFH", /* 6 nodes */
2N/A "ACBDEFGH" /* 8 nodes */
2N/A };
2N/A
2N/A topo_mod_dprintf(mod, "g4_chip_label() called\n");
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A /*
2N/A * The chip-properties property will not exist if this platform has
2N/A * AMD family 0x10 modules. In that case we don't want to treat it as a
2N/A * fatal error as that will cause calls like topo_prop_getprops to fail
2N/A * to return any properties on this node. Therefore, if the topo errno
2N/A * is set to ETOPO_PROP_NOENT, then we'll just set an empty label
2N/A * and return 0. If the topo errno is set to anything else we'll
2N/A * return -1.
2N/A */
2N/A if (topo_prop_get_uint32(node, "chip-properties", "CoherentNodes",
2N/A &num_nodes, &err) != 0) {
2N/A if (err == ETOPO_PROP_NOENT) {
2N/A if (store_prop_val(mod, "", "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A return (0);
2N/A } else {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'CoherentNodes'"
2N/A "property\n");
2N/A return (topo_mod_seterrno(mod, err));
2N/A }
2N/A }
2N/A
2N/A mapidx = num_nodes / 2 - 1;
2N/A htid = topo_node_instance(node);
2N/A
2N/A /* HT nodes must number 0 .. num_nodes - 1 */
2N/A if (htid >= num_nodes) {
2N/A topo_mod_dprintf(mod, "chip node instance range check failed:"
2N/A "num_nodes=%d, instance=%d\n", num_nodes, htid);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A switch (num_nodes) {
2N/A case (2):
2N/A case (4):
2N/A case (6):
2N/A case (8):
2N/A /* htid is already range-checked */
2N/A mapidx = num_nodes / 2 - 1;
2N/A slot_id = g4map[mapidx][htid];
2N/A break;
2N/A default:
2N/A topo_mod_dprintf(mod, "Invalid number of CoherentNodes:"
2N/A " %d\n", num_nodes);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, slot_id);
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Utility function used by a4fplus_chip_label to determine the number of chips
2N/A * (as opposed to processors) that are installed in the system by counting
2N/A * the unique chipids.
2N/A */
2N/Astatic int
2N/Aget_num_chips(topo_mod_t *mod)
2N/A{
2N/A fmd_agent_hdl_t *hdl;
2N/A nvlist_t **cpus;
2N/A uint_t ncpu;
2N/A int i, nchip = 0;
2N/A int32_t chipid;
2N/A uint64_t bitmap = 0;
2N/A
2N/A if ((hdl = fmd_agent_open(FMD_AGENT_VERSION)) == NULL)
2N/A return (-1);
2N/A if (fmd_agent_physcpu_info(hdl, &cpus, &ncpu) == -1) {
2N/A topo_mod_dprintf(mod, "get physcpu info failed:%s\n",
2N/A fmd_agent_errmsg(hdl));
2N/A fmd_agent_close(hdl);
2N/A return (-1);
2N/A }
2N/A fmd_agent_close(hdl);
2N/A
2N/A for (i = 0; i < ncpu; i++) {
2N/A if (nvlist_lookup_int32(cpus[i], FM_PHYSCPU_INFO_CHIP_ID,
2N/A &chipid) != 0 || chipid >= 64) {
2N/A topo_mod_dprintf(mod, "lookup chipid failed\n");
2N/A nchip = -1;
2N/A break;
2N/A }
2N/A if ((bitmap & (1 << chipid)) != 0) {
2N/A bitmap |= (1 << chipid);
2N/A nchip++;
2N/A }
2N/A }
2N/A
2N/A for (i = 0; i < ncpu; i++)
2N/A nvlist_free(cpus[i]);
2N/A umem_free(cpus, sizeof (nvlist_t *) * ncpu);
2N/A
2N/A return (nchip);
2N/A}
2N/A
2N/A/*
2N/A * This is a custom property method for generating the CPU slot label for the
2N/A * Andromeda Fplus platforms.
2N/A *
2N/A * format: a string containing a printf-like format with a single %d token
2N/A * which this method computes
2N/A *
2N/A * i.e.: CPU %d
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Aa4fplus_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ];
2N/A int num_nodes;
2N/A
2N/A topo_mod_dprintf(mod, "a4fplus_chip_label() called\n");
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A /*
2N/A * Normally we'd figure out the total number of chip nodes by looking
2N/A * at the CoherentNodes property. However, due to the lack of a memory
2N/A * controller driver for family 0x10, this property wont exist on the
2N/A * chip nodes on A4Fplus.
2N/A */
2N/A if ((num_nodes = get_num_chips(mod)) < 0) {
2N/A topo_mod_dprintf(mod, "Failed to determine number of chip "
2N/A "nodes\n");
2N/A return (topo_mod_seterrno(mod, EMOD_UNKNOWN));
2N/A }
2N/A switch (num_nodes) {
2N/A case (2):
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr,
2N/A topo_node_instance(node) + 2);
2N/A break;
2N/A case (4):
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr,
2N/A topo_node_instance(node));
2N/A break;
2N/A default:
2N/A topo_mod_dprintf(mod, "Invalid number of chip nodes:"
2N/A " %d\n", num_nodes);
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * This is a somewhat generic property method for labelling the chip-select
2N/A * nodes on multi-socket AMD family 0x10 platforms. This is necessary because
2N/A * these platforms are not supported by the current AMD memory controller driver
2N/A * and therefore we're not able to discover the memory topology on AMD family
2N/A * 0x10 systems. As a result, instead of enumerating the installed dimms and
2N/A * their ranks, the chip enumerator generically enumerates all of the possible
2N/A * chip-selects beneath each dram channel.
2N/A *
2N/A * When we diagnose a dimm fault, the FRU fmri will be for the chip-select node,
2N/A * so we need to attach FRU labels to the chip-select nodes.
2N/A *
2N/A * format: a string containing a printf-like format with a two %d tokens
2N/A * for the cpu and dimm slot label numbers, which this method
2N/A * computes
2N/A *
2N/A * i.e.: CPU %d DIMM %d
2N/A *
2N/A * offset: a numeric offset that we'll number the dimms from. This is to
2N/A * allow for the fact that some systems may number the dimm slots
2N/A * from zero while others may start from one
2N/A *
2N/A * This function computes the DIMM slot number using the following formula:
2N/A *
2N/A * slot = cs - (cs % 2) + channel + offset
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Asimple_cs_label_mp(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ];
2N/A tnode_t *chip, *chan;
2N/A int dimm_num, ret;
2N/A uint32_t offset;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "simple_cs_label_mp() called\n");
2N/A
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A chip = topo_node_parent(topo_node_parent(topo_node_parent(node)));
2N/A chan = topo_node_parent(node);
2N/A
2N/A dimm_num = topo_node_instance(node) - (topo_node_instance(node) % 2)
2N/A + topo_node_instance(chan) + offset;
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip),
2N/A dimm_num);
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/* ARGSUSED */
2N/Aint
2N/Ag4_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, *chip_lbl, buf[BUFSZ];
2N/A tnode_t *chip;
2N/A int ret, err = 0;
2N/A uint32_t offset;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "g4_dimm_label() called\n");
2N/A
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A /*
2N/A * The 4600/4600M2 have a weird way of labeling the chip nodes, so
2N/A * instead of trying to recompute it, we'll simply look it up and
2N/A * prepend it to our dimm label.
2N/A */
2N/A chip = topo_node_parent(topo_node_parent(node));
2N/A if (topo_prop_get_string(chip, TOPO_PGROUP_PROTOCOL, "label", &chip_lbl,
2N/A &err) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup label prop on %s=%d\n",
2N/A topo_node_name(chip), topo_node_instance(chip),
2N/A topo_strerror(err));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, chip_lbl,
2N/A (topo_node_instance(node) + offset));
2N/A
2N/A topo_mod_strfree(mod, chip_lbl);
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * This method is used to compute the labels for DIMM slots on the Galaxy 1F and
2N/A * 2F platforms. It results in following dimm node label assignments:
2N/A *
2N/A * chip/dimm instances label
2N/A * ------------------- -----
2N/A * chip=0/dimm=0 CPU 1 DIMM A0
2N/A * chip=0/dimm=1 CPU 1 DIMM B0
2N/A * chip=0/dimm=2 CPU 1 DIMM A1
2N/A * chip=0/dimm=3 CPU 1 DIMM B1
2N/A *
2N/A * chip=1/dimm=0 CPU 2 DIMM A0
2N/A * chip=1/dimm=1 CPU 2 DIMM B0
2N/A * chip=1/dimm=2 CPU 2 DIMM A1
2N/A * chip=1/dimm=3 CPU 2 DIMM B1
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Ag12f_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A char *fmtstr, buf[BUFSZ], chan;
2N/A tnode_t *chip;
2N/A int ret, dimm_inst, slot_num;
2N/A nvlist_t *args;
2N/A
2N/A topo_mod_dprintf(mod, "g12f_dimm_label() called\n");
2N/A
2N/A if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n",
2N/A strerror(ret));
2N/A return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
2N/A }
2N/A if ((fmtstr = get_fmtstr(mod, in)) == NULL) {
2N/A topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A chip = topo_node_parent(topo_node_parent(node));
2N/A dimm_inst = topo_node_instance(node);
2N/A chan = dimm_inst == 0 || dimm_inst == 2 ? 'A': 'B';
2N/A slot_num = (dimm_inst <= 1 ? 0 : 1);
2N/A
2N/A /* LINTED: E_SEC_PRINTF_VAR_FMT */
2N/A (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip) + 1, chan,
2N/A slot_num);
2N/A
2N/A if (store_prop_val(mod, buf, "label", out) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to set label\n");
2N/A /* topo errno already set */
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}