Skip to content

Commit

Permalink
9104 smbios(1M) should display PSU info
Browse files Browse the repository at this point in the history
9105 smbios(1M) processor table info can be confusing
Reviewed by: Tim Kordas <tim.kordas@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
  • Loading branch information
rmustacc committed May 24, 2018
1 parent fcd6927 commit 32ece1f
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 5 deletions.
69 changes: 66 additions & 3 deletions usr/src/cmd/smbios/smbios.c
Expand Up @@ -55,6 +55,24 @@ static int opt_s;
static int opt_t = -1;
static int opt_x;

/*PRINTFLIKE2*/
static void
smbios_warn(smbios_hdl_t *shp, const char *format, ...)
{
va_list ap;

va_start(ap, format);
(void) vfprintf(stderr, format, ap);
va_end(ap);

if (shp != NULL) {
(void) fprintf(stderr, ": %s",
smbios_errmsg(smbios_errno(shp)));
}

(void) fprintf(stderr, "\n");
}

/*PRINTFLIKE2*/
static void
oprintf(FILE *fp, const char *format, ...)
Expand Down Expand Up @@ -526,9 +544,9 @@ print_processor(smbios_hdl_t *shp, id_t id, FILE *fp)
else
oprintf(fp, " Current Speed: Unknown\n");

id_printf(fp, " L1 Cache: ", p.smbp_l1cache);
id_printf(fp, " L2 Cache: ", p.smbp_l2cache);
id_printf(fp, " L3 Cache: ", p.smbp_l3cache);
id_printf(fp, " L1 Cache Handle: ", p.smbp_l1cache);
id_printf(fp, " L2 Cache Handle: ", p.smbp_l2cache);
id_printf(fp, " L3 Cache Handle: ", p.smbp_l3cache);
}

static void
Expand Down Expand Up @@ -997,6 +1015,47 @@ print_ipmi(smbios_hdl_t *shp, FILE *fp)
smbios_ipmi_flag_name, smbios_ipmi_flag_desc);
}

static void
print_powersup(smbios_hdl_t *shp, id_t id, FILE *fp)
{
smbios_powersup_t p;

if (smbios_info_powersup(shp, id, &p) != 0) {
smbios_warn(shp, "failed to read power supply information");
return;
}

oprintf(fp, " Power Supply Group: %u\n", p.smbps_group);
if (p.smbps_maxout != 0x8000) {
oprintf(fp, " Maximum Output: %llu mW\n", p.smbps_maxout);
} else {
oprintf(fp, " Maximum Output: unknown\n");
}

flag_printf(fp, "Characteristics", p.smbps_flags,
sizeof (p.smbps_flags) * NBBY, smbios_powersup_flag_name,
smbios_powersup_flag_desc);

desc_printf(smbios_powersup_input_desc(p.smbps_ivrs),
fp, " Input Voltage Range Switching: %u", p.smbps_ivrs);
desc_printf(smbios_powersup_status_desc(p.smbps_status),
fp, " Status: %u", p.smbps_status);
desc_printf(smbios_powersup_type_desc(p.smbps_pstype),
fp, " Type: %u", p.smbps_pstype);

if (p.smbps_vprobe != 0xffff) {
oprintf(fp, " Voltage Probe Handle: %lu\n", p.smbps_vprobe);
}

if (p.smbps_cooldev != 0xffff) {
oprintf(fp, " Cooling Device Handle: %lu\n", p.smbps_cooldev);
}

if (p.smbps_iprobe != 0xffff) {
oprintf(fp, " Current Probe Handle: %lu\n", p.smbps_iprobe);
}
}

static void
print_extprocessor(smbios_hdl_t *shp, id_t id, FILE *fp)
{
Expand Down Expand Up @@ -1204,6 +1263,10 @@ print_struct(smbios_hdl_t *shp, const smbios_struct_t *sp, void *fp)
oprintf(fp, "\n");
print_ipmi(shp, fp);
break;
case SMB_TYPE_POWERSUP:
oprintf(fp, "\n");
print_powersup(shp, sp->smbstr_id, fp);
break;
case SMB_TYPE_OBDEVEXT:
oprintf(fp, "\n");
print_obdevs_ext(shp, sp->smbstr_id, fp);
Expand Down
6 changes: 6 additions & 0 deletions usr/src/common/smbios/mktables.sh
Expand Up @@ -22,6 +22,7 @@
#
#
# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2017, Joyent, Inc.
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
Expand All @@ -47,6 +48,7 @@ SMB_CAT_ smbios_cache_ctype_name uint_t
SMB_CAF_ smbios_cache_flag_name uint_t
SMB_EVFL_ smbios_evlog_flag_name uint_t
SMB_IPMI_F_ smbios_ipmi_flag_name uint_t
SMB_POWERSUP_F_ smbios_powersup_flag_name uint_t
SMB_MDF_ smbios_memdevice_flag_name uint_t
SMB_PRC_ smbios_processor_core_flag_name uint_t
SMB_TYPE_ smbios_type_name uint_t
Expand Down Expand Up @@ -76,6 +78,10 @@ SMB_EVM_ smbios_evlog_method_desc uint_t
SMB_HWSEC_PS_ smbios_hwsec_desc uint_t
SMB_IPMI_F_ smbios_ipmi_flag_desc uint_t
SMB_IPMI_T_ smbios_ipmi_type_desc uint_t
SMB_POWERSUP_F_ smbios_powersup_flag_desc uint_t
SMB_POWERSUP_I_ smbios_powersup_input_desc uint_t
SMB_POWERSUP_S_ smbios_powersup_status_desc uint_t
SMB_POWERSUP_T_ smbios_powersup_type_desc uint_t
SMB_MAL_ smbios_memarray_loc_desc uint_t
SMB_MAU_ smbios_memarray_use_desc uint_t
SMB_MAE_ smbios_memarray_ecc_desc uint_t
Expand Down
55 changes: 54 additions & 1 deletion usr/src/common/smbios/smb_info.c
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
* Copyright 2016 Joyent, Inc.
* Copyright (c) 2017, Joyent, Inc.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
Expand Down Expand Up @@ -1265,3 +1265,56 @@ smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id,

return (0);
}

int
smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup)
{
const smb_struct_t *stp = smb_lookup_id(shp, id);
smb_powersup_t psu;

if (stp == NULL)
return (-1); /* errno is set for us */

if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP)
return (smb_set_errno(shp, ESMB_TYPE));

/* The minimum length required by the spec is 0x10. */
if (stp->smbst_hdr->smbh_len < 0x10)
return (smb_set_errno(shp, ESMB_SHORT));

bzero(psup, sizeof (*psup));
smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu));
psup->smbps_group = psu.smbpsup_group;
psup->smbps_maxout = psu.smbpsup_max;

if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char))
psup->smbps_flags |= SMB_POWERSUP_F_HOT;
if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char))
psup->smbps_flags |= SMB_POWERSUP_F_PRESENT;
if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char))
psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG;

psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char);
psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char);
psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char);

if (stp->smbst_hdr->smbh_len >= 0x12) {
psup->smbps_vprobe = psu.smbpsup_vprobe;
} else {
psup->smbps_vprobe = 0xffff;
}

if (stp->smbst_hdr->smbh_len >= 0x14) {
psup->smbps_cooldev = psu.smbpsup_cooldev;
} else {
psup->smbps_cooldev = 0xffff;
}

if (stp->smbst_hdr->smbh_len >= 0x16) {
psup->smbps_iprobe = psu.smbpsup_iprobe;
} else {
psup->smbps_iprobe = 0xffff;
}

return (0);
}
7 changes: 7 additions & 0 deletions usr/src/lib/libsmbios/common/mapfile-vers
Expand Up @@ -20,6 +20,7 @@
#
#
# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2017, Joyent, Inc.
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#

Expand Down Expand Up @@ -98,6 +99,7 @@ SYMBOL_VERSION SUNWprivate_1.1 {
smbios_info_obdevs_ext;
smbios_info_port;
smbios_info_extport;
smbios_info_powersup;
smbios_info_processor;
smbios_info_extprocessor;
smbios_info_slot;
Expand All @@ -124,6 +126,11 @@ SYMBOL_VERSION SUNWprivate_1.1 {
smbios_onboard_type_desc;
smbios_port_conn_desc;
smbios_port_type_desc;
smbios_powersup_flag_desc;
smbios_powersup_flag_name;
smbios_powersup_input_desc;
smbios_powersup_status_desc;
smbios_powersup_type_desc;
smbios_processor_family_desc;
smbios_processor_status_desc;
smbios_processor_type_desc;
Expand Down
51 changes: 51 additions & 0 deletions usr/src/uts/common/sys/smbios.h
Expand Up @@ -1350,6 +1350,50 @@ typedef struct smbios_ipmi {
#define SMB_IPMI_F_INTRHIGH 0x04 /* intr active high (else low) */
#define SMB_IPMI_F_INTREDGE 0x08 /* intr is edge triggered (else lvl) */

/*
* SMBIOS System Power Supply Information. See DSP0134 7.40 for more
* information.
*/
typedef struct smbios_powersup {
uint32_t smbps_group; /* group ID */
uint64_t smbps_maxout; /* max output in milliwatts */
uint32_t smbps_flags; /* see below */
uint8_t smbps_ivrs; /* input voltage range switching type */
uint8_t smbps_status; /* PSU status */
uint8_t smbps_pstype; /* PSU type */
id_t smbps_vprobe; /* voltage probe handle */
id_t smbps_cooldev; /* cooling device handle */
id_t smbps_iprobe; /* current probe handle */
} smbios_powersup_t;

/* smbpfs_flags */
#define SMB_POWERSUP_F_HOT 0x01 /* PSU is hot-replaceable */
#define SMB_POWERSUP_F_PRESENT 0x02 /* PSU is present */
#define SMB_POWERSUP_F_UNPLUG 0x04 /* PSU is unplugged from outlet */

/* Values for smbps_ivrs */
#define SMB_POWERSUP_I_OTHER 0x01 /* other */
#define SMB_POWERSUP_I_UNKNOWN 0x02 /* unknown */
#define SMB_POWERSUP_I_MANUAL 0x03 /* manual */
#define SMB_POWERSUP_I_AUTO 0x04 /* auto-switch */
#define SMB_POWERSUP_I_WIDE 0x05 /* wide range */
#define SMB_POWERSUP_I_NA 0x06 /* not applicable */

#define SMB_POWERSUP_S_OTHER 0x01 /* other */
#define SMB_POWERSUP_S_UNKNOWN 0x02 /* unknown */
#define SMB_POWERSUP_S_OK 0x03 /* OK */
#define SMB_POWERSUP_S_NONCRIT 0x04 /* non-critical */
#define SMB_POWERSUP_S_CRIT 0x05 /* critical; PSU failed */

#define SMB_POWERSUP_T_OTHER 0x01 /* other */
#define SMB_POWERSUP_T_UNKNOWN 0x02 /* unknown */
#define SMB_POWERSUP_T_LINEAR 0x03 /* linear */
#define SMB_POWERSUP_T_SWITCH 0x04 /* switching */
#define SMB_POWERSUP_T_BAT 0x05 /* battery */
#define SMB_POWERSUP_T_UPS 0x06 /* UPS */
#define SMB_POWERSUP_T_CONV 0x07 /* converter */
#define SMB_POWERSUP_T_REGL 0x08 /* regulator */

/*
* SMBIOS Onboard Devices Extended Information. See DSP0134 Section 7.42
* for more information.
Expand Down Expand Up @@ -1507,6 +1551,7 @@ extern int smbios_info_memdevmap(smbios_hdl_t *, id_t, smbios_memdevmap_t *);
extern id_t smbios_info_hwsec(smbios_hdl_t *, smbios_hwsec_t *);
extern id_t smbios_info_boot(smbios_hdl_t *, smbios_boot_t *);
extern id_t smbios_info_ipmi(smbios_hdl_t *, smbios_ipmi_t *);
extern int smbios_info_powersup(smbios_hdl_t *, id_t, smbios_powersup_t *);
extern int smbios_info_pciexrc(smbios_hdl_t *, id_t, smbios_pciexrc_t *);

extern const char *smbios_psn(smbios_hdl_t *);
Expand Down Expand Up @@ -1555,6 +1600,12 @@ extern const char *smbios_ipmi_flag_name(uint_t);
extern const char *smbios_ipmi_flag_desc(uint_t);
extern const char *smbios_ipmi_type_desc(uint_t);

extern const char *smbios_powersup_flag_name(uint_t);
extern const char *smbios_powersup_flag_desc(uint_t);
extern const char *smbios_powersup_input_desc(uint_t);
extern const char *smbios_powersup_status_desc(uint_t);
extern const char *smbios_powersup_type_desc(uint_t);

extern const char *smbios_hwsec_desc(uint_t);

extern const char *smbios_memarray_loc_desc(uint_t);
Expand Down
9 changes: 8 additions & 1 deletion usr/src/uts/common/sys/smbios_impl.h
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
* Copyright 2016 Joyent, Inc.
* Copyright (c) 2017, Joyent, Inc.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
Expand Down Expand Up @@ -398,6 +398,13 @@ typedef struct smb_powersup {
uint16_t smbpsup_iprobe; /* current probe handle */
} smb_powersup_t;

#define SMB_PSU_CHARS_ISHOT(x) ((x) & 0x01)
#define SMB_PSU_CHARS_ISPRES(x) ((x) & 0x02)
#define SMB_PSU_CHARS_ISUNPLUG(x) ((x) & 0x04)
#define SMB_PSU_CHARS_IVRS(x) (((x) >> 3) & 0xf)
#define SMB_PSU_CHARS_STATUS(x) (((x) >> 7) & 0x7)
#define SMB_PSU_CHARS_TYPE(x) (((x) >> 10) & 0xf)

typedef struct smb_obdev_ext {
smb_header_t smbobe_hdr; /* structure header */
uint8_t smbobe_name; /* reference designation */
Expand Down

0 comments on commit 32ece1f

Please sign in to comment.