diff options
Diffstat (limited to 'usr/src/cmd/picl')
18 files changed, 4 insertions, 5503 deletions
diff --git a/usr/src/cmd/picl/plugins/sun4u/Makefile b/usr/src/cmd/picl/plugins/sun4u/Makefile index 2de3454ef2..a4e4c018d8 100644 --- a/usr/src/cmd/picl/plugins/sun4u/Makefile +++ b/usr/src/cmd/picl/plugins/sun4u/Makefile @@ -31,11 +31,11 @@ include $(SRC)/Makefile.master SUBDIRS= lib .WAIT envmon .WAIT \ frudata grover excalibur psvc littleneck daktari \ - cherrystone lw2plus lw8 taco enchilada chicago blade mpxu ents \ + cherrystone lw2plus lw8 taco enchilada chicago mpxu ents \ chalupa silverstone sebring schumacher seattle boston .WAIT MSGSUBDIRS= lib frudata grover excalibur psvc littleneck daktari \ - cherrystone lw2plus lw8 taco enchilada chicago blade envmon mpxu ents \ + cherrystone lw2plus lw8 taco enchilada chicago envmon mpxu ents \ silverstone sebring all := TARGET= all diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/Makefile b/usr/src/cmd/picl/plugins/sun4u/blade/Makefile deleted file mode 100644 index 8debfd7d68..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2002 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/sun4u/blade/Makefile -# - -SUBDIRS= devtree frutree frudata bsc fruaccess .WAIT -MSGSUBDIRS= bsc fruaccess - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint -_msg := TARGET= _msg - -.KEEP_STATE: - -all install clean clobber lint : $(SUBDIRS) - -_msg: $(MSGSUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/Makefile b/usr/src/cmd/picl/plugins/sun4u/blade/bsc/Makefile deleted file mode 100644 index 7274aede33..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/picl/plugins/sun4u/blade/bsc/Makefile -# -include $(SRC)/Makefile.psm - -LIBRARY= libpicllom.a -VERS= .1 - -OBJECTS= picllom.o - -# include library definitions -include $(SRC)/lib/Makefile.lib - -ROOT_PLATFORM = $(USR_PLAT_DIR)/SUNW,Serverblade1 - -include $(SRC)/cmd/picl/plugins/Makefile.com - -SRCS= $(OBJECTS:%.o=%.c) - -LIBS = $(DYNLIB) - -ROOTLIBDIR = $(ROOT_PLAT_PLUGINDIR) - -CONF= picllom.conf -ROOTCONF= $(CONF:%=$(ROOTLIBDIR)/%) -$(ROOTCONF) := FILEMODE = 0644 -INFOS= picllom.info - -LINTSRC = $(LINTLIB:%.ln=%) -ROOTLINTDIR = $(ROOTLIBDIR) -ROOTLINT = $(LINTSRC:%=$(ROOTLINTDIR)/%) - -CLEANFILES= $(LINTOUT) $(LINTLIB) - -CPPFLAGS += -I$(SRC)/uts/sun4u/ -I$(SRC)/uts/common/ -CPPFLAGS += -I$(SRC)/cmd/picl/plugins/lib/picld_pluginutil -CPPFLAGS += -D_REENTRANT -CFLAGS += $(CCVERBOSE) -LINTFLAGS = -uxmn -DYNFLAGS += -R/usr/platform/sun4u/lib/picl/plugins:/usr/lib/picl/plugins -LDLIBS += -L$(SRC)/cmd/picl/plugins/lib/picld_pluginutil/$(MACH) -LDLIBS += -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -L$(SRC)/cmd/picl/plugins/common/piclevent -LDLIBS += -L$(SRC)/cmd/picl/plugins/common/memcfg -LDLIBS += -L$(SRC)/cmd/picl/plugins/common/devtree -LDLIBS += -L$(SRC)/cmd/picl/plugins/common/frutree -LDLIBS += -lpicldevtree -lpiclfrutree -lpicltree -lpicld_pluginutil -LDLIBS += -ldevinfo -lc - -.KEEP_STATE: - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint -_msg := TARGET= _msg - -POFILE = picllom_blade.po -POFILES = $(SRCS:%.c=%.po) - -all: $(LIBS) $(LIBLINKS) $(CONF) - -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) $(ROOTCONF) - -$(POFILE): $(POFILES) - $(CAT) $(POFILES) > $(POFILE) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN)/$(POFILE) - -$(MSGDOMAIN): - $(INS.dir) - -$(CONF): $(INFOS) - $(RM) $@ - $(CPP) $(INFOS) | \ - $(SED) -e '/^[ ]*$$/d' -e '/^#/d' > $@ - -$(LIBLINKS): FRC - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -# include library targets -include $(SRC)/lib/Makefile.targ -include $(SRC)/cmd/picl/plugins/Makefile.targ - -$(ROOTLINTDIR)/%: ../% - $(INS.file) - -lint: - $(LINT.c) $(SRCS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: - diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.c b/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.c deleted file mode 100644 index 462ccc1dec..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.c +++ /dev/null @@ -1,1435 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. - */ - -/* - * This plugin creates PICL nodes and properties for objects handled through - * the blade support chip (BSC). The BSC Solaris land device driver exposes - * information to the plugin and other clients through an existing LOM - * (Lights Out Management) ioctl interface. The plugin only exercises - * a subset of the interface which is known to be supported by the bsc. - * - * All the nodes which may be accessible through the BSC are included below - * the SUNW,bscv node (class system-controller) in the /platform tree. - * This plugin interrogates the BSC to determine which of - * those nodes are actually available. Properties are added to such nodes and - * in the case of volatile properties like temperature, a call-back function - * is established for on-demand access to the current value. - * - * NOTE: - * Depends on PICL devtree plugin. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <alloca.h> -#include <syslog.h> -#include <string.h> -#include <libintl.h> -#include <picl.h> -#include <picltree.h> -#include <errno.h> -#include <limits.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/obpdefs.h> -#include <sys/lom_io.h> -#include <sys/systeminfo.h> -#include <time.h> -#include <picldefs.h> -#include <picld_pluginutil.h> -#include "picllom.h" - -static void picllom_register(void); -static void picllom_init(void); -static void picllom_fini(void); -static node_el_t *create_node_el(picl_nodehdl_t nodeh); -static void delete_node_el(node_el_t *pel); -static node_list_t *create_node_list(); -static void delete_node_list_contents(node_list_t *pnl); -static void delete_node_list(node_list_t *pnl); -static void add_node_to_list(picl_nodehdl_t nodeh, - node_list_t *listp); -static void get_node_list_by_class(picl_nodehdl_t nodeh, - const char *classname, node_list_t *listp); -static int get_lom_node(picl_nodehdl_t *lominfh); -static int get_lom_device_path(picl_nodehdl_t *lominfh); -static int get_node_by_name_and_class(picl_nodehdl_t srchnodeh, - const char *nodename, const char *classname, picl_nodehdl_t *chdh); -static int add_regular_prop(picl_nodehdl_t nodeh, const char *name, - int type, int access, int size, const void *valbuf, picl_prophdl_t *prophp); -static int add_volatile_prop(picl_nodehdl_t nodeh, char *name, - int type, int access, int size, ptree_vol_rdfunc_t rdfunc, - ptree_vol_wrfunc_t wrfunc, picl_prophdl_t *prophp); -static int open_lom_rd(int *lom_fd); -static int get_lom_temp(int index, tempr_t *temp_p); -static int update_voltage_stats(); -static int get_lom_volts_status(int index, int *voltsStatus_p); -static int get_lom_volts_shutdown(int index, int *voltsShutdown_p); -static int update_fan_stats(); -static int get_lom_fan_speed(int index, int *fan_speed); -static int read_vol_temp(ptree_rarg_t *parg, void *buf); -static int read_vol_volts_status(ptree_rarg_t *parg, void *buf); -static int read_vol_volts_shutdown(ptree_rarg_t *parg, void *buf); -static int read_fan_speed(ptree_rarg_t *parg, void *buf); -static int read_fan_status(ptree_rarg_t *parg, void *buf); -static int lookup_led_status(int8_t state, const char **string); -static int read_led_status(ptree_rarg_t *parg, void *buf); -static void convert_node_name(char *ptr); -static int add_temp_sensors(int lom_fd, picl_nodehdl_t lominfh); -static int add_voltage_monitors(int lom_fd, - picl_nodehdl_t lominfh); -static int add_fan_nodes(int lom_fd, picl_nodehdl_t lominfh); -static int get_config_file(char *outfilename); - -#pragma init(picllom_register) - -static picld_plugin_reg_t my_reg_info = { - PICLD_PLUGIN_VERSION_1, - PICLD_PLUGIN_NON_CRITICAL, - "SUNW_picllom", - picllom_init, - picllom_fini -}; - -static const char str_OK[] = "OK"; -static const char str_FAIL[] = "FAIL"; -static const char str_On[] = "on"; -static const char str_Off[] = "off"; -static const char str_Enabled[] = "Enabled"; -static const char str_Disabled[] = "Disabled"; -static char lom_device_path[PATH_MAX]; -static tempr_t high_warnings[MAX_TEMPS]; -static tempr_t high_shutdowns[MAX_TEMPS]; -static picl_prophdl_t temp_handles[MAX_TEMPS]; -static lom_fandata_t fandata; -static picl_prophdl_t fan_speed_handles[MAX_FANS]; -static picl_prophdl_t fan_status_handles[MAX_FANS]; -static lom_volts_t voltsdata; -static picl_prophdl_t volts_status_handles[MAX_VOLTS]; -static picl_prophdl_t volts_shutdown_handles[MAX_VOLTS]; -static int n_leds = 0; -static int max_state_size = 0; -static picl_prophdl_t *led_handles = NULL; -static char **led_labels = NULL; -static lom2_info_t info2data; -static struct { - int size; - char *str_colour; -} colour_lkup[1 + LOM_LED_COLOUR_AMBER]; - -static struct { - int8_t state; - char *str_ledstate; -} ledstate_lkup[] = { - { LOM_LED_OFF }, - { LOM_LED_ON }, - { LOM_LED_BLINKING }, -}; - -static node_el_t * -create_node_el(picl_nodehdl_t nodeh) -{ - node_el_t *ptr = malloc(sizeof (node_el_t)); - - if (ptr != NULL) { - ptr->nodeh = nodeh; - ptr->next = NULL; - } - - return (ptr); -} - -static void -delete_node_el(node_el_t *pel) -{ - free(pel); -} - -static node_list_t * -create_node_list() -{ - node_list_t *ptr = malloc(sizeof (node_list_t)); - - if (ptr != NULL) { - ptr->head = NULL; - ptr->tail = NULL; - } - - return (ptr); -} - -static void -delete_node_list_contents(node_list_t *pnl) -{ - node_el_t *pel; - - if (pnl == NULL) - return; - - while ((pel = pnl->head) != NULL) { - pnl->head = pel->next; - delete_node_el(pel); - } - - pnl->tail = NULL; -} - -static void -delete_node_list(node_list_t *pnl) -{ - delete_node_list_contents(pnl); - free(pnl); -} - -/* - * Get a linking element and add handle to end of chain - */ -static void -add_node_to_list(picl_nodehdl_t nodeh, node_list_t *listp) -{ - node_el_t *pel = create_node_el(nodeh); - - if (pel != NULL) { - if (listp->tail == NULL) - listp->head = pel; - else - listp->tail->next = pel; - - listp->tail = pel; - } -} - -/* - * Get a list of nodes of the specified classname under nodeh. - * Once a node of the specified class is found, its children are not - * searched. - */ -static void -get_node_list_by_class(picl_nodehdl_t nodeh, const char *classname, - node_list_t *listp) -{ - int err; - char clname[PICL_CLASSNAMELEN_MAX+1]; - picl_nodehdl_t chdh; - - /* - * go through the children - */ - err = ptree_get_propval_by_name(nodeh, PICL_PROP_CHILD, &chdh, - sizeof (picl_nodehdl_t)); - - while (err == PICL_SUCCESS) { - err = ptree_get_propval_by_name(chdh, PICL_PROP_CLASSNAME, - clname, strlen(classname) + 1); - - if ((err == PICL_SUCCESS) && (strcmp(clname, classname) == 0)) - add_node_to_list(chdh, listp); - else - get_node_list_by_class(chdh, classname, listp); - - err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (picl_nodehdl_t)); - } -} - -static int -get_lom_node(picl_nodehdl_t *lominfh) -{ - int err = PICL_SUCCESS; - node_list_t *listp; - - listp = create_node_list(); - - if ((err = ptree_get_node_by_path(PICL_NODE_ROOT PICL_NODE_PLATFORM, - lominfh)) != PICL_SUCCESS) { - syslog(LOG_ERR, EM_MISSING_NODE, - PICL_NODE_ROOT PICL_NODE_PLATFORM); - return (err); /* no /platform ! */ - } - - get_node_list_by_class(*lominfh, PICL_CLASS_SERVICE_PROCESSOR, listp); - - if (listp->head == NULL) { - *lominfh = 0; - syslog(LOG_ERR, EM_MISSING_NODE, PICL_CLASS_SERVICE_PROCESSOR); - err = PICL_NODENOTFOUND; - } else { - *lominfh = listp->head->nodeh; - - if (listp->head != listp->tail) - syslog(LOG_ERR, EM_LOM_DUPLICATE); - } - - delete_node_list(listp); - return (err); -} - -static int -get_lom_device_path(picl_nodehdl_t *lominfh) -{ - int err = PICL_SUCCESS; - char devfs_path[PATH_MAX]; - char devices_path[PATH_MAX]; - - err = ptree_get_propval_by_name(*lominfh, PICL_PROP_DEVFS_PATH, - devfs_path, sizeof (devfs_path)); - - /* Build up the full device path and set the global */ - strcpy(devices_path, "/devices"); - strcat(devices_path, devfs_path); - strcat(devices_path, LOM_DEV_MINOR_NAME); - strcpy(lom_device_path, devices_path); - - return (err); - -} - - - - -/* - * Look for a node of specified name and class - * Confine search to nodes one level below that of supplied handle - */ -static int -get_node_by_name_and_class(picl_nodehdl_t srchnodeh, const char *nodename, - const char *classname, picl_nodehdl_t *chdh) -{ - int err; - char namebuf[PATH_MAX]; - - err = ptree_get_propval_by_name(srchnodeh, PICL_PROP_CHILD, chdh, - sizeof (picl_nodehdl_t)); - - while (err == PICL_SUCCESS) { - err = ptree_get_propval_by_name(*chdh, PICL_PROP_NAME, namebuf, - sizeof (namebuf)); - if (err != PICL_SUCCESS) - break; - if (strcmp(namebuf, nodename) == 0) { - err = ptree_get_propval_by_name(*chdh, - PICL_PROP_CLASSNAME, namebuf, sizeof (namebuf)); - if ((err == PICL_SUCCESS) && - (strcmp(namebuf, classname) == 0)) - return (PICL_SUCCESS); - } - err = ptree_get_propval_by_name(*chdh, PICL_PROP_PEER, chdh, - sizeof (picl_nodehdl_t)); - } - - return (err); -} - -/* - * Create and add the specified regular property - */ - -static int -add_regular_prop(picl_nodehdl_t nodeh, const char *name, int type, int access, - int size, const void *valbuf, picl_prophdl_t *prophp) -{ - int err; - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - type, access, size, (char *)name, NULL, NULL); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_and_add_prop(nodeh, &propinfo, (void *)valbuf, - &proph); - if (err == PICL_SUCCESS && prophp) - *prophp = proph; - return (err); -} - - -/* - * Create and add the specified volatile property - */ -static int -add_volatile_prop(picl_nodehdl_t nodeh, char *name, int type, int access, - int size, ptree_vol_rdfunc_t rdfunc, ptree_vol_wrfunc_t wrfunc, - picl_prophdl_t *prophp) -{ - int err; - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - type, (access|PICL_VOLATILE), size, name, rdfunc, wrfunc); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_and_add_prop(nodeh, &propinfo, NULL, &proph); - if (err == PICL_SUCCESS && prophp) - *prophp = proph; - return (err); -} - -/* - * open LOM device to read - */ -static int -open_lom_rd(int *lom_fd) -{ - *lom_fd = open(lom_device_path, O_RDONLY); - - if (*lom_fd < 0) - return (PICL_FAILURE); - - return (PICL_SUCCESS); -} - -/* - * Function to open LOM and read temperature sensor values. - * The index to a specific sensor is supplied and that value returned. - */ -static int -get_lom_temp(int index, tempr_t *temp_p) -{ - lom_temp_t lom_temp; - int lom_fd; - int err; - int res; - - err = open_lom_rd(&lom_fd); - - if (err == PICL_SUCCESS) { - res = ioctl(lom_fd, LOMIOCTEMP, &lom_temp); - (void) close(lom_fd); - - if (res == 0) { - *temp_p = lom_temp.temp[index]; - } else { - err = PICL_FAILURE; - } - } - - return (err); -} - -/* - * Function to open LOM and read voltage monitor values. - * Called for each property, so only perform update if time has changed - */ -static int -update_voltage_stats() -{ - static time_t then = 0; - int lom_fd; - int err; - int res; - time_t now = time(NULL); - - if (now == then) - return (PICL_SUCCESS); - - then = now; - err = open_lom_rd(&lom_fd); - - if (err == PICL_SUCCESS) { - res = ioctl(lom_fd, LOMIOCVOLTS, &voltsdata); - (void) close(lom_fd); - if (res < 0) { - err = PICL_FAILURE; - } - } - - return (err); -} - -/* - * Function to open LOM and read voltage monitor values. - * The index to a specific voltage status is supplied and that value returned. - */ -static int -get_lom_volts_status(int index, int *voltsStatus_p) -{ - int res; - - if ((res = update_voltage_stats()) != PICL_SUCCESS) - return (res); - - *voltsStatus_p = voltsdata.status[index]; - return (PICL_SUCCESS); -} - -/* - * Function to open LOM and read voltage monitor values. - * The index to a specific shutdown flag is supplied and that value returned. - */ -static int -get_lom_volts_shutdown(int index, int *voltsShutdown_p) -{ - int res; - - if ((res = update_voltage_stats()) != PICL_SUCCESS) - return (res); - - *voltsShutdown_p = voltsdata.shutdown_enabled[index]; - return (PICL_SUCCESS); -} - - - -/* - * Function to open LOM and read fan values. - * Called for each property, so only perform update if time has changed - */ -static int -update_fan_stats() -{ - static time_t then = 0; - int lom_fd; - int err; - int res; - time_t now = time(NULL); - - if (now == then) - return (PICL_SUCCESS); - - then = now; - err = open_lom_rd(&lom_fd); - if (err == PICL_SUCCESS) { - res = ioctl(lom_fd, LOMIOCFANSTATE, &fandata); - (void) close(lom_fd); - if (res < 0) { - err = PICL_FAILURE; - } - } - - return (err); -} - - - -/* - * The index to a specific fan is supplied and its speed value returned. - */ -static int -get_lom_fan_speed(int index, int *fan_speed) -{ - int res; - - if ((res = update_fan_stats()) != PICL_SUCCESS) - return (res); - - *fan_speed = fandata.speed[index]; - return (PICL_SUCCESS); -} - - -/* - * Read function for volatile "Temperature" property via LOM - */ -static int -read_vol_temp(ptree_rarg_t *parg, void *buf) -{ - tempr_t temp; - picl_prophdl_t proph; - int index; - - /* - * get the sensor index from the displacement of the - * property handle and get its temperature. - */ - proph = parg->proph; - for (index = 0; index < MAX_TEMPS; index++) { - if (temp_handles[index] == proph) - break; - } - - if (index == MAX_TEMPS) { - /* - * Handle not found. As this is a plugin, stale handles - * cannot occur, so just fail. - */ - return (PICL_FAILURE); - } - - if (get_lom_temp(index, &temp) != PICL_SUCCESS) - return (PICL_FAILURE); - (void) memcpy(buf, (caddr_t)&temp, sizeof (tempr_t)); - return (PICL_SUCCESS); -} - -/* - * Read function for volatile "VoltageStatus" property via LOM - */ -static int -read_vol_volts_status(ptree_rarg_t *parg, void *buf) -{ - int voltsStatus; - picl_prophdl_t proph; - int index; - - /* - * get the voltage monitor index from the displacement of the - * status property handle and get its status. - */ - proph = parg->proph; - - for (index = 0; index < MAX_VOLTS; index++) { - if (volts_status_handles[index] == proph) - break; - } - - if (index == MAX_VOLTS) - return (PICL_FAILURE); - - if (get_lom_volts_status(index, &voltsStatus) != PICL_SUCCESS) - return (PICL_FAILURE); - - (void) strlcpy(buf, (voltsStatus == 0) ? str_OK : str_FAIL, - sizeof (str_FAIL)); - return (PICL_SUCCESS); -} - -/* - * Read function for volatile "VoltageShutdown" property via LOM - */ -static int -read_vol_volts_shutdown(ptree_rarg_t *parg, void *buf) -{ - int voltsShutdown; - picl_prophdl_t proph; - int index; - - /* - * get the voltage monitor index from the displacement of the - * shutdown property handle and get its value. - */ - proph = parg->proph; - - for (index = 0; index < MAX_VOLTS; index++) { - if (volts_shutdown_handles[index] == proph) - break; - } - - if (index == MAX_VOLTS) - return (PICL_FAILURE); - - if (get_lom_volts_shutdown(index, &voltsShutdown) != PICL_SUCCESS) - return (PICL_FAILURE); - - (void) strlcpy(buf, (voltsShutdown == 0) ? str_Disabled : str_Enabled, - sizeof (str_Disabled)); - return (PICL_SUCCESS); -} - - -/* - * Read function for volatile fan speed property via LOM - */ -static int -read_fan_speed(ptree_rarg_t *parg, void *buf) -{ - int fan_speed; - picl_prophdl_t proph; - int index; - - /* - * get the relevant fan from the displacement of its property handle - */ - proph = parg->proph; - - for (index = 0; index < MAX_FANS; index++) { - if (fan_speed_handles[index] == proph) - break; - } - - if (index == MAX_FANS) - return (PICL_FAILURE); - - if (get_lom_fan_speed(index, &fan_speed) != PICL_SUCCESS) - return (PICL_FAILURE); - - (void) memcpy(buf, (caddr_t)&fan_speed, sizeof (fan_speed)); - return (PICL_SUCCESS); -} - -/* - * look up function to convert led status into string - */ -static int -lookup_led_status(int8_t state, const char **string) -{ - int i; - int lim = sizeof (ledstate_lkup) / sizeof (ledstate_lkup[0]); - - for (i = 0; i < lim; i++) { - if (ledstate_lkup[i].state == state) { - *string = ledstate_lkup[i].str_ledstate; - return (PICL_SUCCESS); - } - } - - *string = ""; - switch (state) { - case LOM_LED_ACCESS_ERROR: - return (PICL_PROPVALUNAVAILABLE); - case LOM_LED_NOT_IMPLEMENTED: - /*FALLTHROUGH*/ - case LOM_LED_OUTOFRANGE: - /*FALLTHROUGH*/ - default: - return (PICL_FAILURE); - } -} - -/* - * Read function for volatile led status property. - */ -static int -read_led_status(ptree_rarg_t *parg, void *buf) -{ - lom_led_state_t led_data; - picl_prophdl_t proph; - int index; - int lom_fd; - int res; - const char *string; - - /* - * get the relevant led from the displacement of its property handle - */ - proph = parg->proph; - - for (index = 0; index < n_leds; index++) { - if (led_handles[index] == proph) - break; - } - - if (index == n_leds) - return (PICL_FAILURE); - - res = open_lom_rd(&lom_fd); - if (res != PICL_SUCCESS) - return (res); - /* - * The interface for reading LED status doesn't promise to maintain - * a constant mapping between LED index number and LED identity - * (as defined by its label). On the other hand, PICL does promise - * that whilst a handle remains valid the object it represents will - * remain constant. To reconcile these positions, we maintain - * tables of labels and handles linked by index value. We search - * for the handle with which we are presented and then locate its - * label. Then we request LED entries from the LOM and compare their - * labels with the one we seek. As an optimisation, we try the original - * index value first and then revert to a full search. - */ - (void) memset(&led_data, 0, sizeof (led_data)); - led_data.index = index; - res = ioctl(lom_fd, LOMIOCLEDSTATE, &led_data); - - if (res != 0 || led_data.state == LOM_LED_NOT_IMPLEMENTED || - strcmp(led_data.label, led_labels[index]) != 0) { - /* - * full scan required (bet it doesn't work!) - * first re-establish the range to scan - */ - int i; - int n; - - (void) memset(&led_data, 0, sizeof (led_data)); - led_data.index = -1; - res = ioctl(lom_fd, LOMIOCLEDSTATE, &led_data); - - if (res != 0) { - (void) close(lom_fd); - return (PICL_PROPVALUNAVAILABLE); - } - - if (led_data.state == LOM_LED_NOT_IMPLEMENTED || - strcmp(led_data.label, led_labels[index]) != 0) { - n = led_data.index; - for (i = 0; i < n; i++) { - (void) memset(&led_data, 0, sizeof (led_data)); - led_data.index = i; - res = ioctl(lom_fd, LOMIOCLEDSTATE, &led_data); - - if (res == 0 && - led_data.state != LOM_LED_NOT_IMPLEMENTED || - strcmp(led_data.label, led_labels[index]) == - 0) { - break; - } - } - - if (i == n) { - (void) close(lom_fd); - return (PICL_PROPVALUNAVAILABLE); - } - } - } - - /* - * if we get here, then we found the right LED. - */ - (void) close(lom_fd); - res = lookup_led_status(led_data.state, &string); - (void) strlcpy(buf, string, max_state_size); - return (res); -} - -/* - * Read function for volatile fan status property. - * This is a synthesized property using speed and min speed properties - */ -static int -read_fan_status(ptree_rarg_t *parg, void *buf) -{ - int fan_speed; - picl_prophdl_t proph; - int index; - - /* - * get the relevant fan from the displacement of its property handle - */ - proph = parg->proph; - - for (index = 0; index < MAX_FANS; index++) { - if (fan_status_handles[index] == proph) - break; - } - - if (index == MAX_FANS) - return (PICL_FAILURE); - - if (get_lom_fan_speed(index, &fan_speed) != PICL_SUCCESS) - return (PICL_FAILURE); - - (void) strlcpy(buf, - fan_speed < fandata.minspeed[index] ? str_FAIL : str_OK, - sizeof (str_FAIL)); - return (PICL_SUCCESS); -} - - - -/* - * change to lower case and convert any spaces into hyphens - */ -static void -convert_node_name(char *ptr) -{ - char ch; - - for (ch = *ptr; ch != '\0'; ch = *++ptr) { - if (isupper(ch)) { - *ptr = tolower(ch); - } else if (isspace(ch)) { - *ptr = '-'; - } - } -} - -static int -add_temp_sensors(int lom_fd, picl_nodehdl_t lominfh) -{ - lom_temp_t lom_temp; - int res; - int i; - int err = PICL_SUCCESS; - const char *cptr; - - res = ioctl(lom_fd, LOMIOCTEMP, &lom_temp); - - if ((res == 0) && (lom_temp.num > 0)) { - /* - * for each temperature location add a sensor node - */ - for (i = 0; i < lom_temp.num; i++) { - picl_nodehdl_t tempsensh; - picl_prophdl_t proph; - - high_warnings[i] = lom_temp.warning[i]; - high_shutdowns[i] = lom_temp.shutdown[i]; - - convert_node_name(lom_temp.name[i]); - - err = ptree_create_node(lom_temp.name[i], - PICL_CLASS_TEMPERATURE_SENSOR, &tempsensh); - if (err != PICL_SUCCESS) - break; - - err = add_volatile_prop(tempsensh, - PICL_PROP_TEMPERATURE, PICL_PTYPE_INT, PICL_READ, - sizeof (tempr_t), read_vol_temp, NULL, - &temp_handles[i]); - if (err != PICL_SUCCESS) - break; - - if (high_warnings[i] != 0) { - err = add_regular_prop( - tempsensh, PICL_PROP_HIGH_WARNING, - PICL_PTYPE_INT, PICL_READ, - sizeof (tempr_t), &high_warnings[i], - &proph); - if (err != PICL_SUCCESS) - break; - } - - if (high_shutdowns[i] != 0) { - err = add_regular_prop( - tempsensh, PICL_PROP_HIGH_SHUTDOWN, - PICL_PTYPE_INT, PICL_READ, - sizeof (tempr_t), &high_shutdowns[i], - &proph); - if (err != PICL_SUCCESS) - break; - } - - /* - * for the benefit of prtdiag, add a label of - * either enclosure or die where appropriate - */ - if ((strcasestr(lom_temp.name[i], CPU_ENCLOSURE) != - NULL) || - (strcasestr(lom_temp.name[i], CPU_AMBIENT) != - NULL)) { - cptr = CPU_AMBIENT; - } else if ((cptr = strcasestr(lom_temp.name[i], - CPU_DIE)) != NULL) { - cptr = CPU_DIE; - } - - if (cptr != NULL) { - err = add_regular_prop( - tempsensh, PICL_PROP_LABEL, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(cptr) + 1, cptr, &proph); - - if (err != PICL_SUCCESS) { - break; - } - } - - err = ptree_add_node(lominfh, tempsensh); - - if (err != PICL_SUCCESS) - break; - } - - if (err != PICL_SUCCESS) { - syslog(LOG_ERR, EM_LOMINFO_TREE_FAILED); - } - } - - return (err); -} - -static int -add_voltage_monitors(int lom_fd, picl_nodehdl_t lominfh) -{ - int res; - int i; - int err = PICL_SUCCESS; - picl_prophdl_t proph; - - res = ioctl(lom_fd, LOMIOCVOLTS, &voltsdata); - - if ((res == 0) && (voltsdata.num > 0)) { - /* - * for each voltage monitor add a monitor node - */ - for (i = 0; i < voltsdata.num; i++) { - picl_nodehdl_t voltsmonh; - - convert_node_name(voltsdata.name[i]); - - err = ptree_create_node(voltsdata.name[i], - PICL_CLASS_VOLTAGE_INDICATOR, &voltsmonh); - if (err != PICL_SUCCESS) - break; - - err = add_regular_prop(voltsmonh, PICL_PROP_LABEL, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(voltsdata.name[i]) + 1, - voltsdata.name[i], &proph); - if (err != PICL_SUCCESS) - break; - - err = add_volatile_prop(voltsmonh, PICL_VOLTS_SHUTDOWN, - PICL_PTYPE_CHARSTRING, PICL_READ, - sizeof (str_Disabled), read_vol_volts_shutdown, - NULL, &volts_shutdown_handles[i]); - if (err != PICL_SUCCESS) - break; - - err = add_volatile_prop(voltsmonh, PICL_PROP_CONDITION, - PICL_PTYPE_CHARSTRING, PICL_READ, - sizeof (str_FAIL), read_vol_volts_status, NULL, - &volts_status_handles[i]); - if (err != PICL_SUCCESS) - break; - - err = ptree_add_node(lominfh, voltsmonh); - - if (err != PICL_SUCCESS) - break; - } - - if (err != PICL_SUCCESS) { - syslog(LOG_ERR, EM_LOMINFO_TREE_FAILED); - } - } - - return (err); -} - -static void -add_led(const lom_led_state_t *led_state, picl_nodehdl_t lominfh) -{ - int err; - picl_nodehdl_t ledh; - picl_nodehdl_t proph; - - if (((unsigned char)led_state->state == LOM_LED_STATE_NOT_PRESENT) || - (led_state->label[0] == '\0')) { - return; - } - - err = ptree_create_node(led_state->label, PICL_CLASS_LED, &ledh); - /* - * the led may exist already, e.g. Fault - */ - if (err != PICL_SUCCESS) - return; - - /* - * Unlike LEDs derived from other interfaces, these are not - * writable. Establish a read-only volatile property. - */ - err = add_volatile_prop(ledh, PICL_PROP_STATE, PICL_PTYPE_CHARSTRING, - PICL_READ, max_state_size, read_led_status, NULL, - &led_handles[led_state->index]); - if (err != PICL_SUCCESS) - return; - - /* - * if colour was defined for this LED, add a colour property - */ - if ((led_state->colour != LOM_LED_COLOUR_NONE) && - (led_state->colour != LOM_LED_COLOUR_ANY)) { - err = add_regular_prop(ledh, PICL_PROP_COLOR, - PICL_PTYPE_CHARSTRING, PICL_READ, - colour_lkup[led_state->index].size, - colour_lkup[led_state->index].str_colour, &proph); - } - if (err != PICL_SUCCESS) - return; - - err = add_regular_prop(ledh, PICL_PROP_LABEL, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(led_state->label) + 1, - led_state->label, &proph); - if (err != PICL_SUCCESS) - return; - - err = ptree_add_node(lominfh, ledh); - - if (err != PICL_SUCCESS) { - syslog(LOG_ERR, EM_LOMINFO_TREE_FAILED); - } -} - -static void -fixstate(uint8_t state, const char *string, int *max_len) -{ - int i; - int len; - - for (i = 0; i < (sizeof (ledstate_lkup) / sizeof (ledstate_lkup[0])); - i++) { - if (ledstate_lkup[i].state == state) { - if (ledstate_lkup[i].str_ledstate != NULL) - free(ledstate_lkup[i].str_ledstate); - ledstate_lkup[i].str_ledstate = strdup(string); - len = strlen(string); - if (len >= *max_len) - *max_len = len + 1; - break; - } - } -} - -static void -add_led_nodes(int lom_fd, picl_nodehdl_t lominfh) -{ - lom_led_state_t led_data; - picl_nodehdl_t ledh; - int res; - int i; - - /* - * If the led state enquiry ioctl is supported, an enquiry on - * index -1 will return the state of the highest supported index - * value. - */ - (void) memset(&led_data, 0, sizeof (led_data)); - led_data.index = -1; - res = ioctl(lom_fd, LOMIOCLEDSTATE, &led_data); - - if (res != 0) - return; - - if (led_labels != NULL) { - for (i = 0; i < n_leds; i++) { - if (led_labels[i] != NULL) { - free(led_labels[i]); - } - } - - free(led_labels); - led_labels = NULL; - } - - if (led_handles != NULL) { - free(led_handles); - } - - n_leds = 0; - led_handles = calloc(led_data.index + 1, sizeof (picl_nodehdl_t)); - led_labels = calloc(led_data.index + 1, sizeof (char *)); - - if ((led_labels == NULL) || (led_handles == NULL)) { - if (led_labels != NULL) - free(led_labels); - if (led_handles != NULL) - free(led_handles); - led_labels = NULL; - led_handles = NULL; - syslog(LOG_ERR, EM_NO_LED_MEM); - return; - } - - n_leds = led_data.index + 1; - - /* - * For each LED with a valid state, add a node - * and because of the ludicrous API, stache a copy of its label too - */ - for (i = 0; i < n_leds; i++) { - (void) memset(&led_data, 0, sizeof (led_data)); - led_data.index = i; - res = ioctl(lom_fd, LOMIOCLEDSTATE, &led_data); - - if (res != 0) - continue; - - if (led_data.state == LOM_LED_OUTOFRANGE || - led_data.state == LOM_LED_NOT_IMPLEMENTED) - continue; - - - led_labels[i] = strdup(led_data.label); - convert_node_name(led_data.label); - - if (get_node_by_name_and_class(lominfh, led_data.label, - "led", &ledh) != PICL_SUCCESS) { - /* - * only add a new led node, - * if it's not already in place - */ - add_led(&led_data, lominfh); - } - } -} - -static int -add_fan_nodes(int lom_fd, picl_nodehdl_t lominfh) -{ - int res; - int i; - int err = PICL_SUCCESS; - - res = ioctl(lom_fd, LOMIOCFANSTATE, &fandata); - - if (res == 0) { - /* - * fan data available through lom, remove any placeholder - * fan-unit nodes, they will be superseded via lom.conf - */ - char path[80]; - int slot; - picl_nodehdl_t fan_unit_h; - - for (slot = 0; slot < MAX_FANS; slot++) { - (void) snprintf(path, sizeof (path), - "/frutree/chassis/fan-slot?Slot=%d/fan-unit", slot); - if (ptree_get_node_by_path(path, &fan_unit_h) != - PICL_SUCCESS) - continue; - if (ptree_delete_node(fan_unit_h) != PICL_SUCCESS) - continue; - (void) ptree_destroy_node(fan_unit_h); - } - /* - * see if fan names can be obtained - */ - (void) memset(&info2data, 0, sizeof (info2data)); - /* - * if LOMIOCINFO2 not supported, names area - * will remain empty - */ - (void) ioctl(lom_fd, LOMIOCINFO2, &info2data); - - /* - * for each fan which is present, add a fan node - */ - for (i = 0; i < MAX_FANS; i++) { - char fanname[80]; - picl_nodehdl_t fanh; - picl_nodehdl_t proph; - - if (fandata.fitted[i] == 0) - continue; - - if (info2data.fan_names[i][0] == '\0') { - (void) snprintf(fanname, sizeof (fanname), - "fan%d", i + 1); - } else { - (void) strlcpy(fanname, info2data.fan_names[i], - sizeof (fanname)); - } - convert_node_name(fanname); - err = ptree_create_node(fanname, PICL_CLASS_FAN, &fanh); - if (err != PICL_SUCCESS) - break; - - err = add_volatile_prop(fanh, PICL_PROP_FAN_SPEED, - PICL_PTYPE_INT, PICL_READ, sizeof (int), - read_fan_speed, NULL, &fan_speed_handles[i]); - if (err != PICL_SUCCESS) - break; - - err = add_regular_prop(fanh, PICL_PROP_LOW_WARNING, - PICL_PTYPE_INT, PICL_READ, sizeof (int), - &fandata.minspeed[i], &proph); - if (err != PICL_SUCCESS) - break; - - err = add_regular_prop(fanh, PICL_PROP_FAN_SPEED_UNIT, - PICL_PTYPE_CHARSTRING, PICL_READ, sizeof ("%"), - "%", &proph); - if (err != PICL_SUCCESS) - break; - - err = add_volatile_prop(fanh, PICL_PROP_CONDITION, - PICL_PTYPE_CHARSTRING, PICL_READ, - sizeof (str_FAIL), read_fan_status, NULL, - &fan_status_handles[i]); - if (err != PICL_SUCCESS) - break; - - /* - * add a label for prtdiag - */ - err = add_regular_prop(fanh, PICL_PROP_LABEL, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(fanname) + 1, fanname, &proph); - if (err != PICL_SUCCESS) - break; - - err = ptree_add_node(lominfh, fanh); - if (err != PICL_SUCCESS) - break; - } - - if (err != PICL_SUCCESS) { - syslog(LOG_ERR, EM_LOMINFO_TREE_FAILED); - } - } - - return (err); -} - -static void -setup_strings() -{ - /* - * initialise led colours lookup - */ - int i; - int lim = sizeof (colour_lkup) / sizeof (colour_lkup[0]); - - for (i = 0; i < lim; i++) { - if (colour_lkup[i].str_colour != NULL) - free(colour_lkup[i].str_colour); - } - - colour_lkup[LOM_LED_COLOUR_ANY].str_colour = strdup(gettext("any")); - colour_lkup[LOM_LED_COLOUR_WHITE].str_colour = strdup(gettext("white")); - colour_lkup[LOM_LED_COLOUR_BLUE].str_colour = strdup(gettext("blue")); - colour_lkup[LOM_LED_COLOUR_GREEN].str_colour = strdup(gettext("green")); - colour_lkup[LOM_LED_COLOUR_AMBER].str_colour = strdup(gettext("amber")); - - for (i = 0; i < lim; i++) { - if (colour_lkup[i].str_colour != NULL) - colour_lkup[i].size = - 1 + strlen(colour_lkup[i].str_colour); - } - - /* - * initialise led state lookup strings - */ - fixstate(LOM_LED_OFF, gettext("off"), &max_state_size); - fixstate(LOM_LED_ON, gettext("on"), &max_state_size); - fixstate(LOM_LED_BLINKING, gettext("blinking"), &max_state_size); -} - -/* - * The size of outfilename must be PATH_MAX - */ -static int -get_config_file(char *outfilename) -{ - char nmbuf[SYS_NMLN]; - char pname[PATH_MAX]; - - if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) { - (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf); - (void) strlcat(pname, LOM_CONFFILE_NAME, PATH_MAX); - if (access(pname, R_OK) == 0) { - (void) strlcpy(outfilename, pname, PATH_MAX); - return (0); - } - } - - if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) { - (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf); - (void) strlcat(pname, LOM_CONFFILE_NAME, PATH_MAX); - if (access(pname, R_OK) == 0) { - (void) strlcpy(outfilename, pname, PATH_MAX); - return (0); - } - } - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR, - LOM_CONFFILE_NAME); - - if (access(pname, R_OK) == 0) { - (void) strlcpy(outfilename, pname, PATH_MAX); - return (0); - } - - return (-1); -} - - - -/* - * executed as part of .init when the plugin is dlopen()ed - */ -static void -picllom_register(void) -{ - (void) picld_plugin_register(&my_reg_info); -} - -/* - * Init entry point of the plugin - * Creates the PICL nodes and properties in the physical and logical aspects. - */ -static void -picllom_init(void) -{ - picl_nodehdl_t rooth; - picl_nodehdl_t plfh; - picl_nodehdl_t lominfh; - int lom_fd; - char fullfilename[PATH_MAX]; - - /* - * Get platform node - */ - if (ptree_get_node_by_path(PICL_NODE_ROOT PICL_NODE_PLATFORM, &plfh) - != PICL_SUCCESS) { - syslog(LOG_ERR, EM_MISSING_NODE, PICL_NODE_PLATFORM); - syslog(LOG_ERR, EM_INIT_FAILED); - return; - } - - /* - * Get lom node - */ - if (get_lom_node(&lominfh) != PICL_SUCCESS) { - syslog(LOG_ERR, EM_LOM_NODE_MISSING); - syslog(LOG_ERR, EM_INIT_FAILED); - return; - } - - /* - * Retrive the device path to open - */ - if (get_lom_device_path(&lominfh) < 0) { - syslog(LOG_ERR, EM_INIT_FAILED); - return; - } - - /* - * Open LOM device and interrogate for devices it monitors - */ - if ((lom_fd = open(lom_device_path, O_RDONLY)) < 0) { - syslog(LOG_ERR, EM_SYS_ERR, lom_device_path, strerror(errno)); - return; - } - - setup_strings(); - (void) add_temp_sensors(lom_fd, lominfh); - (void) add_voltage_monitors(lom_fd, lominfh); - (void) add_fan_nodes(lom_fd, lominfh); - add_led_nodes(lom_fd, lominfh); - - - if (get_config_file(fullfilename) < 0) { - (void) close(lom_fd); - syslog(LOG_ERR, EM_NO_CONFIG); - return; - } - - if (ptree_get_root(&rooth) != PICL_SUCCESS) { - (void) close(lom_fd); - return; - } - - if (picld_pluginutil_parse_config_file(rooth, fullfilename) != - PICL_SUCCESS) - syslog(LOG_ERR, EM_INIT_FAILED); - - (void) close(lom_fd); -} - -/* - * fini entry point of the plugin - */ -static void -picllom_fini(void) -{ -} diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.h b/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.h deleted file mode 100644 index 193eef2c76..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICLLOM_H -#define _PICLLOM_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Log message texts - */ -#define EM_INIT_FAILED gettext("SUNW_picllom: init failed!\n") -#define EM_MISSING_NODE gettext("SUNW_picllom: no %s node!\n") -#define EM_LOM_MISSING \ - gettext("SUNW_picllom: Lights Out Module missing!\n") -#define EM_LOM_NODE_MISSING \ - gettext("SUNW_picllom: failed to locate LOM device node\n") -#define EM_LOM_DUPLICATE \ - gettext("SUNW_picllom: more than one LOM device node found\n") -#define EM_CREATE_FAILED \ - gettext("SUNW_picllom: failed to create %s node\n") -#define EM_NO_LED_MEM \ - gettext("SUNW_picllom: couldn't get memory for LED nodes\n") -#define EM_LOMINFO_TREE_FAILED \ - gettext("SUNW_picllom: failed to initialize lom nodes\n") -#define EM_SYS_ERR gettext("SUNW_picllom: %s: %s\n") -#define EM_NO_CONFIG \ - gettext("SUNW_picllom: no config file picllom.conf") - -/* - * define for super-user uid - used in credential checking - */ -#define SUPER_USER ((uid_t)0) - -/* - * CPU temperature sensor labels - * prtdiag relies on the labels "ambient" and "die" when reporting CPU temp. - */ -#define CPU_ENCLOSURE "Enclosure" -#define CPU_AMBIENT "Ambient" -#define CPU_DIE "Die" - -/* - * Constants for some PICL properties - */ -#define PICL_VOLTS_SHUTDOWN "VoltageShutdown" - -/* - * Config file name - */ -#define LOM_CONFFILE_NAME "picllom.conf" - -/* - * lom device mnior name - */ -#define LOM_DEV_MINOR_NAME ":lom" - -typedef int16_t tempr_t; - -typedef int (*ptree_vol_rdfunc_t)(ptree_rarg_t *arg, void *buf); -typedef int (*ptree_vol_wrfunc_t)(ptree_warg_t *arg, const void *buf); - -typedef struct node_el { - picl_nodehdl_t nodeh; - struct node_el *next; -} node_el_t; - -typedef struct node_list { - node_el_t *head; - node_el_t *tail; -} node_list_t; - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLLOM_H */ diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.info b/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.info deleted file mode 100644 index 06f97f5076..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/bsc/picllom.info +++ /dev/null @@ -1,179 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * #ident "%Z%%M% %I% %E% SMI" - * - * supported prop types: void, int, uint, float, string - * supported prop access_modes: r, w, rw - * - * VERSION <version_number> -- supported version number is 1.0 - * - * name:<namepath> -- gives the anchor node - * where <namepath> is <nodename>[@<bus-addr>][?<prop>=<val>] - * - * _class:<classpath> -- gives the anchor node - * where <classpath> is <classname>[@<bus-addr>][?<prop>=<val>] - * - * NODE <name> <class> - * {describes a subtree} - * ENDNODE - * - * PROP <name> <type> <access_mode> [<size> <value>] -- per property - * - * REFPROP <name> <dstnode> - * - * REFNODE <name> <class> with <destnode> -- Associates a new node - * with <destnode> if exists - * where - * <name> is the nodename - * <class> is the picl class. - * <destnode> is name:<namepath> or _class:<classpath> - * - * If "name:" or "_class:" is not specified in the <path>, - * the default is "name:" - * - */ -VERSION 1.1 -VERBOSE 1 - -/* Add a fan fru if the cpu fan node is present to the fan slot */ -name:/frutree/chassis/system-board/fan-slot?Slot=0 -REFNODE cpu-fan fru WITH name:/platform/pci/isa/bscbus/bscv/cpu_fan?_class=fan - -/* Add _fru_parent and Environment tables from cpu nodes */ -name:/platform/SUNW,UltraSPARC-IIe@0,0 -REFPROP _fru_parent name:/frutree/chassis/system-board/cpu-slot?Slot=0/cpu-module -TABLE Environment -ROW -PROP Class string r 0 "temperature-sensor" -REFPROP _temperature-sensor_ name:/platform/pci/isa/bscbus/bscv/cpu-die?_class=temperature-sensor -ENDROW -ROW -PROP Class string r 0 "temperature-sensor" -REFPROP _temperature-sensor_ name:/platform/pci/isa/bscbus/bscv/enclosure?_class=temperature-sensor -ENDROW -ROW -PROP Class string r 0 "fan" -REFPROP _fan_ name:/platform/pci/isa/bscbus/bscv/cpu_fan?_class=fan -ENDROW -ENDTABLE - - -/* Set the colour property of the leds */ -name:/platform/pci/isa/bscbus/bscv/active?_class=led -PROP Color string r 0 "green" -name:/platform/pci/isa/bscbus/bscv/svc_reqd?_class=led -PROP Color string r 0 "amber" -name:/platform/pci/isa/bscbus/bscv/rdy_to_rmv?_class=led -PROP Color string r 0 "blue" - -/* Add Devices tables from fru nodes to platform tree counterparts */ - -name:/frutree/chassis -TABLE Devices -ROW -PROP Class string r 0 "led" -REFPROP _led_ name:/platform/pci/isa/bscbus/bscv/active?_class=led -ENDROW -ROW -PROP Class string r 0 "led" -REFPROP _led_ name:/platform/pci/isa/bscbus/bscv/svc_reqd?_class=led -ENDROW -ROW -PROP Class string r 0 "led" -REFPROP _led_ name:/platform/pci/isa/bscbus/bscv/rdy_to_rmv?_class=led -ENDROW -ENDTABLE - - -name:/frutree/chassis/system-board -TABLE Devices -ROW -PROP Class string r 0 "voltage-indicator" -REFPROP _voltage-indicator_ name:/platform/pci/isa/bscbus/bscv/5v?_class=voltage-indicator -ENDROW -ROW -PROP Class string r 0 "voltage-indicator" -REFPROP _voltage-indicator_ name:/platform/pci/isa/bscbus/bscv/3.3v?_class=voltage-indicator -ENDROW -ROW -PROP Class string r 0 "voltage-indicator" -REFPROP _voltage-indicator_ name:/platform/pci/isa/bscbus/bscv/2.5v?_class=voltage-indicator -ENDROW -ROW -PROP Class string r 0 "voltage-indicator" -REFPROP _voltage-indicator_ name:/platform/pci/isa/bscbus/bscv/vcore?_class=voltage-indicator -ENDROW -ENDTABLE - - -name:/frutree/chassis/system-board/fan-slot?Slot=0/cpu-fan -TABLE Devices -ROW -PROP Class string r 0 "fan" -REFPROP _fan_ name:/platform/pci/isa/bscbus/bscv/cpu_fan?_class=fan -ENDROW -ENDTABLE - - -name:/frutree/chassis/system-board/cpu-slot?Slot=0/cpu-module -Table Devices -ROW -PROP Class string r 0 "temperature-sensor" -REFPROP _temperature-sensor_ name:/platform/pci/isa/bscbus/bscv/cpu-die?_class=temperature-sensor -ENDROW -ROW -PROP Class string r 0 "temperature-sensor" -REFPROP _temperature-sensor_ name:/platform/pci/isa/bscbus/bscv/enclosure?_class=temperature-sensor -ENDROW -ENDTABLE - - -/* now link back with _fru_parents */ - -name:/platform/pci/isa/bscbus/bscv/cpu_fan?_class=fan -REFPROP _fru_parent name:/frutree/chassis/system-board/fan-slot?Slot=0/cpu-fan - -name:/platform/pci/isa/bscbus/bscv/cpu-die?_class=temperature-sensor -REFPROP _fru_parent name:/frutree/chassis/system-board/cpu-slot?Slot=0/cpu-module -name:/platform/pci/isa/bscbus/bscv/enclosure?_class=temperature-sensor -REFPROP _fru_parent name:/frutree/chassis/system-board/cpu-slot?Slot=0/cpu-module - -name:/platform/pci/isa/bscbus/bscv/5v?_class=voltage-indicator -REFPROP _fru_parent name:/frutree/chassis/system-board -name:/platform/pci/isa/bscbus/bscv/3.3v?_class=voltage-indicator -REFPROP _fru_parent name:/frutree/chassis/system-board -name:/platform/pci/isa/bscbus/bscv/2.5v?_class=voltage-indicator -REFPROP _fru_parent name:/frutree/chassis/system-board -name:/platform/pci/isa/bscbus/bscv/vcore?_class=voltage-indicator -REFPROP _fru_parent name:/frutree/chassis/system-board - -name:/platform/pci/isa/bscbus/bscv/active?_class=led -REFPROP _fru_parent name:/frutree/chassis -name:/platform/pci/isa/bscbus/bscv/svc_reqd?_class=led -REFPROP _fru_parent name:/frutree/chassis -name:/platform/pci/isa/bscbus/bscv/rdy_to_rmv?_class=led -REFPROP _fru_parent name:/frutree/chassis - diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/devtree/Makefile b/usr/src/cmd/picl/plugins/sun4u/blade/devtree/Makefile deleted file mode 100644 index 22648acd00..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/devtree/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/sun4u/blade/devtree/Makefile -# -include $(SRC)/Makefile.psm - -# include library definitions -include $(SRC)/lib/Makefile.lib - -ROOT_PLATFORM = $(USR_PLAT_DIR)/SUNW,Serverblade1 - -include $(SRC)/cmd/picl/plugins/Makefile.com - -ROOTLIBDIR = $(ROOT_PLAT_PLUGINDIR) - -CONF= picldevtree.conf -ROOTCONF= $(CONF:%=$(ROOTLIBDIR)/%) -$(ROOTCONF) := FILEMODE = 0644 - -ROOTLINTDIR = $(ROOTLIBDIR) - -.KEEP_STATE: - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint - -all: - -install: $(ROOTLIBDIR) $(ROOTCONF) - -# include library targets -include $(SRC)/lib/Makefile.targ -include $(SRC)/cmd/picl/plugins/Makefile.targ - -$(ROOTLINTDIR)/%: ../% - $(INS.file) - -lint: - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/devtree/picldevtree.conf b/usr/src/cmd/picl/plugins/sun4u/blade/devtree/picldevtree.conf deleted file mode 100644 index f3e98dac57..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/devtree/picldevtree.conf +++ /dev/null @@ -1,28 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2002 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -#ident "%Z%%M% %I% %E% SMI" -# -# Platform specific .conf file for picldevtree plug-in -bscv service-processor diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/Makefile b/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/Makefile deleted file mode 100644 index c75189a6e4..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/Makefile +++ /dev/null @@ -1,119 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/sun4u/blade/fruaccess/Makefile -# -LIBRARY= libfruaccess.a -VERS= .1 -OBJECTS= fru_access.o crcutils.o crcmodel.o - -# include library definitions -include $(SRC)/Makefile.psm -include $(SRC)/lib/Makefile.lib - -ROOT_PLATFORM = $(USR_PLAT_DIR)/SUNW,Serverblade1 - -include $(SRC)/cmd/picl/plugins/Makefile.com - -SRCS= fru_access.c ../../lib/fruaccess/crcutils.c \ - ../../lib/fruaccess/crcmodel.c - -SRCDIR= ../../lib/fruaccess/. - -LIBS= $(DYNLIB) - -ROOTLIBDIR = $(ROOT_PLATFORM)/lib - -CONF = fru_container.conf -ROOTCONF= $(CONF:%=$(ROOTLIBDIR)/%) -$(ROOTCONF) := FILEMODE = 0644 - - -CLEANFILES= $(LINTOUT) $(LINTLIB) -CLOBBERFILES += $(LIBLINKS) -CSTYLE = cstyle -p -P -HDRCHK = hdrchk - - -CPPFLAGS += -I$(SRC)/lib/libfru/include -CPPFLAGS += -I$(SRC)/lib/libfruutils/ -CPPFLAGS += -I$(SRC)/cmd/picl/plugins/sun4u/lib/fruaccess -CFLAGS += $(CCVERBOSE) -DBIG_ENDIAN -LDLIBS += -L$(SRC)/lib/libfruutils/$(MACH) -LDLIBS += -lc -lpicltree -lfruutils -LDLIBS += -ldevinfo -LDLIBS += -Wl,-f/opt/SUNWSMS/lib/$(DYNLIBPSR) # SMS before platform -LDLIBS += -Wl,-f/usr/platform/\$$PLATFORM/lib/$(DYNLIBPSR) - - -.KEEP_STATE: - - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint -_msg := TARGET= _msg - -LN = ln -s - -POFILE= $(LIBRARY:.a=.po) - -all: $(DYNLIB) $(LIBLINKS) $(CONF) - -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) $(ROOTCONF) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - -$(POFILE): - $(RM) $@ messages.po - $(XGETTEXT) $(XGETFLAGS) *.[ch]* */*.[ch]* - $(SED) -e '/^# msg/d' -e '/^domain/d' messages.po > $@ - $(RM) messages.po - -$(MSGDOMAIN): - $(INS.dir) - -$(LIBLINKS): FRC - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -check-style: - $(CSTYLE) *.cc *.c *.h - $(HDRCHK) *.h - -# include library targets -include $(SRC)/cmd/picl/plugins/Makefile.targ -include $(SRC)/lib/Makefile.targ - -lint : - $(LINT.c) -m $(SRCS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_access.c b/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_access.c deleted file mode 100644 index 5eb01b4ec6..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_access.c +++ /dev/null @@ -1,2746 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <limits.h> -#include <alloca.h> -#include "fru_access_impl.h" - -#pragma init(initialize_fruaccess) /* .init section */ - -static hash_obj_t *hash_table[TABLE_SIZE]; - -/* - * seeprom is the driver_name for the SEEPROM device drivers in excalibur - * Define the devfsadm command to load the seeprom drivers if open fails. - */ - -static char devfsadm_cmd[] = "/usr/sbin/devfsadm -i seeprom"; - -/* this routine initialize the hash table. */ - -static void -initialize_fruaccess(void) -{ - int count; - for (count = 0; count < TABLE_SIZE; count++) { - hash_table[count] = NULL; - } -} - -/* - * called to lookup hash object for specified handle in the hash table. - * - */ - -static hash_obj_t * -lookup_handle_object(handle_t handle, int object_type) -{ - handle_t index_to_hash; - hash_obj_t *first_hash_obj; - hash_obj_t *next_hash_obj; - - index_to_hash = (handle % TABLE_SIZE); - - first_hash_obj = hash_table[index_to_hash]; - for (next_hash_obj = first_hash_obj; next_hash_obj != NULL; - next_hash_obj = next_hash_obj->next) { - if ((handle == next_hash_obj->obj_hdl) && - (object_type == next_hash_obj->object_type)) { - return (next_hash_obj); - } - } - return (NULL); -} - -/* called to allocate container hash object */ - -static hash_obj_t * -create_container_hash_object(void) -{ - hash_obj_t *hash_obj; - container_obj_t *cont_obj; - - cont_obj = malloc(sizeof (container_obj_t)); - if (cont_obj == NULL) { - return (NULL); - } - - hash_obj = malloc(sizeof (hash_obj_t)); - if (hash_obj == NULL) { - free(cont_obj); - return (NULL); - } - - cont_obj->sec_obj_list = NULL; - - hash_obj->object_type = CONTAINER_TYPE; - hash_obj->u.cont_obj = cont_obj; - hash_obj->next = NULL; - hash_obj->prev = NULL; - - return (hash_obj); -} - -/* called to allocate section hash object */ - -static hash_obj_t * -create_section_hash_object(void) -{ - hash_obj_t *hash_obj; - section_obj_t *sec_obj; - - sec_obj = malloc(sizeof (section_obj_t)); - if (sec_obj == NULL) { - return (NULL); - } - - hash_obj = malloc(sizeof (hash_obj_t)); - if (hash_obj == NULL) { - free(sec_obj); - return (NULL); - } - - sec_obj->next = NULL; - sec_obj->seg_obj_list = NULL; - - hash_obj->u.sec_obj = sec_obj; - hash_obj->object_type = SECTION_TYPE; - hash_obj->next = NULL; - hash_obj->prev = NULL; - - return (hash_obj); -} - -/* called to allocate segment hash object */ - -static hash_obj_t * -create_segment_hash_object(void) -{ - hash_obj_t *hash_obj; - segment_obj_t *seg_obj; - - seg_obj = malloc(sizeof (segment_obj_t)); - if (seg_obj == NULL) { - return (NULL); - } - - hash_obj = malloc(sizeof (hash_obj_t)); - if (hash_obj == NULL) { - free(seg_obj); - return (NULL); - } - - seg_obj->next = NULL; - seg_obj->pkt_obj_list = NULL; - - hash_obj->object_type = SEGMENT_TYPE; - hash_obj->u.seg_obj = seg_obj; - hash_obj->next = NULL; - hash_obj->prev = NULL; - - return (hash_obj); -} - -/* called to allocate packet hash object */ - -static hash_obj_t * -create_packet_hash_object(void) -{ - hash_obj_t *hash_obj; - packet_obj_t *pkt_obj; - - pkt_obj = malloc(sizeof (packet_obj_t)); - if (pkt_obj == NULL) { - return (NULL); - } - - hash_obj = malloc(sizeof (hash_obj_t)); - if (hash_obj == NULL) { - free(pkt_obj); - return (NULL); - } - - pkt_obj->next = NULL; - - hash_obj->object_type = PACKET_TYPE; - hash_obj->u.pkt_obj = pkt_obj; - hash_obj->next = NULL; - hash_obj->prev = NULL; - - return (hash_obj); -} - -/* called to add allocated hash object into the hash table */ - -static void -add_hashobject_to_hashtable(hash_obj_t *hash_obj) -{ - handle_t index_to_hash; - static uint64_t handle_count = 0; - - hash_obj->obj_hdl = ++handle_count; /* store the handle */ - - /* where to add ? */ - index_to_hash = ((hash_obj->obj_hdl) % TABLE_SIZE); - - hash_obj->next = hash_table[index_to_hash]; - hash_table[index_to_hash] = hash_obj; /* hash obj. added */ - - if (hash_obj->next != NULL) { - hash_obj->next->prev = hash_obj; - } -} - -/* called to add section object list into the section list */ - -static void -add_to_sec_object_list(hash_obj_t *parent_obj, hash_obj_t *child_obj) -{ - hash_obj_t *next_hash; - - child_obj->u.sec_obj->cont_hdl = parent_obj->obj_hdl; - if (parent_obj->u.cont_obj->sec_obj_list == NULL) { - parent_obj->u.cont_obj->sec_obj_list = child_obj; - return; - } - - for (next_hash = parent_obj->u.cont_obj->sec_obj_list; - next_hash->u.sec_obj->next != NULL; - next_hash = next_hash->u.sec_obj->next) { - ; - } - - next_hash->u.sec_obj->next = child_obj; -} - -/* called to add segment object list into segment list */ - -static void -add_to_seg_object_list(hash_obj_t *parent_obj, hash_obj_t *child_obj) -{ - hash_obj_t *next_hash; - - child_obj->u.seg_obj->section_hdl = parent_obj->obj_hdl; - if (parent_obj->u.sec_obj->seg_obj_list == NULL) { - parent_obj->u.sec_obj->seg_obj_list = child_obj; - return; - } - - for (next_hash = parent_obj->u.sec_obj->seg_obj_list; - next_hash->u.seg_obj->next != NULL; - next_hash = next_hash->u.seg_obj->next) { - ; - } - - next_hash->u.seg_obj->next = child_obj; -} - -/* called to add packet object list into packet list */ - -static void -add_to_pkt_object_list(hash_obj_t *parent_obj, hash_obj_t *child_obj) -{ - hash_obj_t *next_hash; - - /* add the packet object in the end of list */ - child_obj->u.pkt_obj->segment_hdl = parent_obj->obj_hdl; - - if (parent_obj->u.seg_obj->pkt_obj_list == NULL) { - parent_obj->u.seg_obj->pkt_obj_list = child_obj; - return; - } - - for (next_hash = parent_obj->u.seg_obj->pkt_obj_list; - next_hash->u.pkt_obj->next != NULL; - next_hash = next_hash->u.pkt_obj->next) { - ; - } - - next_hash->u.pkt_obj->next = child_obj; -} - -static void -copy_segment_layout(segment_t *seghdr, void *layout) -{ - segment_layout_t *seg_layout; - - seg_layout = (segment_layout_t *)layout; - (void) memcpy(seghdr->name, &seg_layout->name, SEG_NAME_LEN); - seghdr->descriptor = GET_SEGMENT_DESCRIPTOR; - seghdr->offset = seg_layout->offset; - seghdr->length = seg_layout->length; -} - -static hash_obj_t * -get_container_hash_object(int object_type, handle_t handle) -{ - hash_obj_t *hash_obj; - - switch (object_type) { - case CONTAINER_TYPE : - break; - case SECTION_TYPE : - hash_obj = lookup_handle_object(handle, CONTAINER_TYPE); - if (hash_obj == NULL) { - return (NULL); - } - break; - case SEGMENT_TYPE : - hash_obj = lookup_handle_object(handle, SECTION_TYPE); - if (hash_obj == NULL) { - return (NULL); - } - hash_obj = lookup_handle_object(hash_obj->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - break; - case PACKET_TYPE : - break; - default : - return (NULL); - } - return (hash_obj); -} - - -static void -sort_offsettbl(int segcnt, seg_info_t *offset_tbl) -{ - int cntx; - int cnty; - seg_info_t tmp; - - for (cntx = 0; cntx < segcnt+2; cntx++) { - for (cnty = cntx+1; cnty < segcnt + 2; cnty++) { - if (offset_tbl[cntx].offset > - offset_tbl[cnty].offset) { - (void) memcpy(&tmp, &offset_tbl[cnty], - sizeof (seg_info_t)); - (void) memcpy(&offset_tbl[cnty], - &offset_tbl[cntx], sizeof (seg_info_t)); - - (void) memcpy(&offset_tbl[cntx], &tmp, - sizeof (seg_info_t)); - } - } - } -} - -/* - * Description : move_segment_data() reads the segment data and writes it - * back to the new segment offset. - */ - -static void -move_segment_data(void *seghdr, int newoffset, container_hdl_t contfd) -{ - int ret; - char *buffer; - segment_layout_t *segment; - - segment = (segment_layout_t *)seghdr; - - buffer = alloca(segment->length); - if (buffer == NULL) { - return; - } - - ret = pread(contfd, buffer, - segment->length, segment->offset); - if (ret != segment->length) { - return; - } - - segment->offset = newoffset; - - ret = pwrite(contfd, buffer, segment->length, segment->offset); - if (ret != segment->length) { - return; - } -} - -/* - * Description : pack_segment_data() moves the segment data if there is - * a hole between two segments. - */ - -static void -pack_segment_data(char *seghdr, int segcnt, container_hdl_t contfd, - seg_info_t *offset_tbl) -{ - int cnt; - int diff; - int newoffset; - - for (cnt = segcnt + 1; cnt > 0; cnt--) { - if (!offset_tbl[cnt - 1].fixed) { - if (offset_tbl[cnt].offset - - (offset_tbl[cnt -1 ].offset - + offset_tbl[cnt - 1].length) > 0) { - - diff = offset_tbl[cnt].offset - - (offset_tbl[cnt - 1].offset - + offset_tbl[cnt - 1].length); - newoffset = offset_tbl[cnt - 1].offset - + diff; - - move_segment_data(seghdr, newoffset, - contfd); - - offset_tbl[cnt - 1].offset = newoffset; - - sort_offsettbl(segcnt, offset_tbl); - } - } - } -} - -/* - * Description : build_offset_tbl() builds the offset table by reading all the - * segment header. it makes two more entry into the table one for - * section size and another with start of the section after the - * segment header. - */ - -static int -build_offset_tbl(void *seghdr, int segcnt, int secsize, - seg_info_t *offset_tbl) -{ - int cnt; - fru_segdesc_t segdesc; - segment_layout_t *segment; - - for (cnt = 0; cnt < segcnt; cnt++) { - segment = (segment_layout_t *)(seghdr) + cnt; - - (void) memcpy(&segdesc, &segment->descriptor, - sizeof (uint32_t)); - offset_tbl[cnt].segnum = cnt; - offset_tbl[cnt].offset = segment->offset; - offset_tbl[cnt].length = segment->length; - offset_tbl[cnt].fixed = segdesc.field.fixed; - } - - /* upper boundary of segment area (lower address bytes) */ - offset_tbl[cnt].segnum = -1; - offset_tbl[cnt].offset = sizeof (section_layout_t) + ((cnt + 1) - * sizeof (segment_layout_t)); - - offset_tbl[cnt].length = 0; - offset_tbl[cnt].fixed = 1; - /* lower boundary of segment area (higher address bytes) */ - - offset_tbl[cnt+1].segnum = -1; - offset_tbl[cnt+1].offset = secsize; - offset_tbl[cnt+1].length = 0; - offset_tbl[cnt+1].fixed = 1; - return (0); -} - -static int -hole_discovery(int bytes, int segcnt, int *totsize, seg_info_t *offset_tbl) -{ - int cnt = 0; - - *totsize = 0; - for (cnt = segcnt + 1; cnt > 0; cnt--) { - if (bytes <= offset_tbl[cnt].offset - - (offset_tbl[cnt - 1].offset + - offset_tbl[cnt - 1].length)) { - return (offset_tbl[cnt].offset - bytes); - } - - *totsize += offset_tbl[cnt].offset - - (offset_tbl[cnt - 1].offset + - offset_tbl[cnt - 1].length); - } - return (0); -} - - -/* - * Description : segment_hdr_present() verify space for new segment header to - * be added. - */ - -static int -segment_hdr_present(int segoffset, int size, seg_info_t *offset_tbl) -{ - if ((segoffset + size) <= offset_tbl[0].offset) - return (0); - else - return (-1); -} - -/* - * Description : find_offset() is called from fru_add_segment routine to find - * a valid offset. - */ - -static int -find_offset(char *seghdr, int segcnt, int secsize, int *sectionoffset, - int segsize, int fix, container_hdl_t contfd) -{ - int ret; - int newoffset; - int totsize = 0; - seg_info_t *offset_tbl; - - if (segcnt == 0) { - if (!fix) { /* if not fixed segment */ - *sectionoffset = secsize - segsize; - } - return (0); - } - - /* - * two extra segment info structure are allocated for start of segment - * and other end of segment. first segment offset is first available - * space and length is 0. second segment offset is is segment length and - * offset is 0. build_offset_tbl() explains how upper boundary and lower - * boudary segment area are initialized in seg_info_t table. - */ - - offset_tbl = malloc((segcnt + 2) * sizeof (seg_info_t)); - if (offset_tbl == NULL) { - return (-1); - } - - /* read all the segment header to make offset table */ - ret = build_offset_tbl(seghdr, segcnt, secsize, offset_tbl); - if (ret != 0) { - free(offset_tbl); - return (-1); - } - - /* sort the table */ - sort_offsettbl(segcnt, offset_tbl); - - /* new segment header offset */ - newoffset = sizeof (section_layout_t) + segcnt * - sizeof (segment_layout_t); - - /* do? new segment header overlap any existing data */ - ret = segment_hdr_present(newoffset, sizeof (segment_layout_t), - offset_tbl); - if (ret != 0) { /* make room for new segment if possible */ - - /* look for hole in order to move segment data */ - if (offset_tbl[0].fixed == SEGMENT_FIXED) { /* fixed segment */ - free(offset_tbl); - return (-1); - } - - newoffset = hole_discovery(offset_tbl[0].length, - segcnt, &totsize, offset_tbl); - if (newoffset != 0) { /* found new offset */ - /* now new offset */ - offset_tbl[0].offset = newoffset; - - /* move the segment data */ - move_segment_data(seghdr, newoffset, contfd); - /* again sort the offset table */ - sort_offsettbl(segcnt, offset_tbl); - } else { - /* pack the existing hole */ - if (totsize > offset_tbl[0].length) { - pack_segment_data(seghdr, segcnt, - contfd, offset_tbl); - } else { - free(offset_tbl); - return (-1); - } - } - } - - totsize = 0; - newoffset = hole_discovery(segsize, segcnt, &totsize, offset_tbl); - - if (newoffset == 0) { /* No hole found */ - if (totsize >= segsize) { - pack_segment_data(seghdr, segcnt, contfd, - offset_tbl); - newoffset = hole_discovery(segsize, segcnt, - &totsize, offset_tbl); - if (newoffset != 0) { - *sectionoffset = newoffset; - free(offset_tbl); - return (0); - } - } - } else { - *sectionoffset = newoffset; - free(offset_tbl); - return (0); - } - free(offset_tbl); - return (-1); -} - -static char * -tokenizer(char *buf, char *separator, char **nextBuf, char *matched) -{ - int i = 0; - int j = 0; - - for (i = 0; buf[i] != '\0'; i++) { - for (j = 0; j < strlen(separator); j++) { - if (buf[i] == separator[j]) { - buf[i] = '\0'; - *nextBuf = &(buf[i+1]); - *matched = separator[j]; - return (buf); - } - } - } - - *nextBuf = buf; - *matched = '\0'; - return (NULL); -} - -static int -get_container_info(const char *def_file, const char *cont_desc_str, - container_info_t *cont_info) -{ - char *item; - char *token; - char *field; - char matched; - char buf[1024]; - int foundIt = 0; - FILE *file = fopen(def_file, "r"); - - if (file == NULL) - return (-1); - - cont_info->num_sections = 0; - - while (fgets(buf, sizeof (buf), file) != NULL) { - /* ignore all comments */ - token = tokenizer(buf, "#", &field, &matched); - /* find the names */ - token = tokenizer(buf, ":", &field, &matched); - if (token != 0x00) { - token = tokenizer(token, "|", &item, &matched); - while (token != 0x00) { - if (strcmp(token, cont_desc_str) == 0) { - foundIt = 1; - goto found; - } - token = tokenizer(item, "|", &item, &matched); - } - /* check the last remaining item */ - if ((item != 0x00) && - (strcmp(item, cont_desc_str) == 0)) { - foundIt = 1; - goto found; - } - } - } - -found : - if (foundIt == 1) { - token = tokenizer(field, ":", &field, &matched); - if (token == 0x00) { - (void) fclose(file); - return (-1); - } - cont_info->header_ver = (headerrev_t)atoi(token); - - token = tokenizer(field, ":\n", &field, &matched); - while (token != 0x00) { - token = tokenizer(token, ",", &item, &matched); - if (token == 0x00) { - (void) fclose(file); - return (-1); - } - if (atoi(token) == 1) { - cont_info->section_info[cont_info-> - num_sections].description.field.read_only = 1; - } else if (atoi(token) == 0) { - cont_info->section_info[cont_info-> - num_sections].description.field.read_only = 0; - } else { - (void) fclose(file); - return (-1); - } - - token = tokenizer(item, ",", &item, &matched); - if (token == 0x00) { - (void) fclose(file); - return (-1); - } - - if (atoi(token) == 1) { - cont_info->section_info[cont_info-> - num_sections].description.field.chk_type = 1; - } else if (atoi(token) == 0) { - cont_info->section_info[cont_info-> - num_sections].description.field.chk_type = 0; - } else { - (void) fclose(file); - return (-1); - } - - - token = tokenizer(item, ",", &item, &matched); - if (token == 0x00) { - (void) fclose(file); - return (-1); - } - - cont_info->section_info[cont_info->num_sections]. - address = atoi(token); - - - if (item == '\0') { - (void) fclose(file); - return (-1); - } - cont_info->section_info[cont_info->num_sections].size = - atoi(item); - (cont_info->num_sections)++; - - token = tokenizer(field, ":\n ", &field, &matched); - } - } - (void) fclose(file); - return (0); -} - -/* - * Description :fru_open_container() opens the container associated with a fru. - * it's called by data plugin module before creating container - * property. it calls picltree library routine to get the - * device path and driver binding name for the fru to get the - * corresponding fru name that describe the fru layout. - * - * Arguments :picl_hdl_t fru - * A handle for PICL tree node of class "fru" representing the - * FRU with the container to open. - * - * Return : - * On Success, a Positive integer container handle. is returned - * for use in subsequent fru operations;on error, 0 is returned - * and "errno" is set appropriately. - */ - -container_hdl_t -fru_open_container(picl_nodehdl_t fruhdl) -{ - int retval; - int count; - char *bname; - char devpath[PATH_MAX]; - hash_obj_t *cont_hash_obj; - hash_obj_t *sec_hash_obj; - picl_nodehdl_t tmphdl; - picl_prophdl_t prophdl; - ptree_propinfo_t propinfo; - container_info_t cont_info; - - /* Get property handle of _seeprom_source under fru node */ - retval = ptree_get_propval_by_name(fruhdl, PICL_REFPROP_SEEPROM_SRC, - &tmphdl, sizeof (tmphdl)); - if (retval != PICL_SUCCESS) { - return (NULL); - } - - /* Get the device path of the fru */ - retval = ptree_get_propval_by_name(tmphdl, PICL_PROP_DEVICEPATH, - devpath, PATH_MAX); - if (retval != PICL_SUCCESS) { - return (NULL); - } - - retval = ptree_get_prop_by_name(tmphdl, PICL_PROP_BINDING_NAME, - &prophdl); - if (retval != PICL_SUCCESS) { - return (NULL); - } - - retval = ptree_get_propinfo(prophdl, &propinfo); - if (retval != PICL_SUCCESS) { - return (NULL); - } - - bname = alloca(propinfo.piclinfo.size); - if (bname == NULL) { - return (NULL); - } - - /* get the driver binding name */ - retval = ptree_get_propval(prophdl, bname, propinfo.piclinfo.size); - if (retval != PICL_SUCCESS) { - return (NULL); - } - - cont_hash_obj = create_container_hash_object(); - if (cont_hash_obj == NULL) { - return (NULL); - } - - add_hashobject_to_hashtable(cont_hash_obj); - - (void) strlcpy(cont_hash_obj->u.cont_obj->device_pathname, devpath, - sizeof (devpath)); - - /* takes driver binding name as to get container information */ - retval = get_container_info(CONTAINER_CONF_FILE, bname, &cont_info); - if (retval < 0) { - return (NULL); - } - - cont_hash_obj->u.cont_obj->num_of_section = cont_info.num_sections; - cont_hash_obj->u.cont_obj->sec_obj_list = NULL; - - for (count = 0; count < cont_info.num_sections; count++) { - sec_hash_obj = create_section_hash_object(); - if (sec_hash_obj == NULL) { - return (NULL); - } - - add_hashobject_to_hashtable(sec_hash_obj); - - sec_hash_obj->u.sec_obj->section.offset = - cont_info.section_info[count].address; - - sec_hash_obj->u.sec_obj->section.protection = - cont_info.section_info[count].description.field.read_only; - - sec_hash_obj->u.sec_obj->checksum_method = - cont_info.section_info[count].description.field.chk_type; - - sec_hash_obj->u.sec_obj->section.length = - cont_info.section_info[count].size; - - sec_hash_obj->u.sec_obj->section.version = cont_info.header_ver; - - add_to_sec_object_list(cont_hash_obj, sec_hash_obj); - } - return (cont_hash_obj->obj_hdl); -} - -static int -verify_header_crc8(headerrev_t head_ver, unsigned char *bytes, int length) -{ - int crc_offset = 0; - unsigned char orig_crc8 = 0; - unsigned char calc_crc8 = 0; - - switch (head_ver) { - case SECTION_HDR_VER: - crc_offset = 4; - break; - default: - errno = EINVAL; - return (0); - } - - orig_crc8 = bytes[crc_offset]; - bytes[crc_offset] = 0x00; /* clear for calc */ - calc_crc8 = compute_crc8(bytes, length); - bytes[crc_offset] = orig_crc8; /* restore */ - - return (orig_crc8 == calc_crc8); -} - -/* - * Description : - * fru_get_num_sections() returns number of sections in a - * container. it calls get_container_index() to get the container - * index number in the container list. - * - * Arguments : - * container_hdl_t : container handle. - * - * Return : - * int - * On success, returns number of sections in a container. - * - */ -/*ARGSUSED*/ -int -fru_get_num_sections(container_hdl_t container, door_cred_t *cred) -{ - hash_obj_t *hash_object; - - hash_object = lookup_handle_object(container, CONTAINER_TYPE); - if (hash_object == NULL) { - return (-1); - } - - return (hash_object->u.cont_obj->num_of_section); -} - -/* - * called from fru_get_sections() - */ - -static void -get_section(int fd, hash_obj_t *sec_hash, section_t *section) -{ - int retval; - int size; - int count; - uint16_t hdrver; - hash_obj_t *seg_hash; - unsigned char *buffer; - section_obj_t *sec_obj; - section_layout_t sec_hdr; - segment_layout_t *seg_hdr; - segment_layout_t *seg_buf; - - sec_obj = sec_hash->u.sec_obj; - if (sec_obj == NULL) { - return; - } - - /* populate section_t */ - section->handle = sec_hash->obj_hdl; - section->offset = sec_obj->section.offset; - section->length = sec_obj->section.length; - section->protection = sec_obj->section.protection; - section->version = sec_obj->section.version; - sec_obj->num_of_segment = 0; - - /* read section header layout */ - retval = pread(fd, &sec_hdr, sizeof (sec_hdr), - sec_obj->section.offset); - if (retval != sizeof (sec_hdr)) { - return; - } - - hdrver = GET_SECTION_HDR_VERSION; - - if ((sec_hdr.headertag != SECTION_HDR_TAG) && - (hdrver != section->version)) { - return; - } - - /* size = section layout + total sizeof segment header */ - size = sizeof (sec_hdr) + ((sec_hdr.segmentcount) - * sizeof (segment_layout_t)); - - buffer = alloca(size); - if (buffer == NULL) { - return; - } - - /* segment header buffer */ - seg_buf = alloca(size - sizeof (sec_hdr)); - if (seg_buf == NULL) { - return; - } - - /* read segment header */ - retval = pread(fd, seg_buf, size - sizeof (sec_hdr), - sec_obj->section.offset + sizeof (sec_hdr)); - if (retval != (size - sizeof (sec_hdr))) { - return; - } - - /* copy section header layout */ - (void) memcpy(buffer, &sec_hdr, sizeof (sec_hdr)); - - /* copy segment header layout */ - (void) memcpy(buffer + sizeof (sec_hdr), seg_buf, size - - sizeof (sec_hdr)); - - /* verify crc8 */ - retval = verify_header_crc8(hdrver, buffer, size); - if (retval != TRUE) { - return; - } - - - section->version = hdrver; - sec_obj->section.version = hdrver; - - seg_hdr = (segment_layout_t *)seg_buf; - - for (count = 0; count < sec_hdr.segmentcount; count++, seg_hdr++) { - seg_hash = create_segment_hash_object(); - if (seg_hash == NULL) { - return; - } - - add_hashobject_to_hashtable(seg_hash); - - copy_segment_layout(&seg_hash->u.seg_obj->segment, seg_hdr); - - add_to_seg_object_list(sec_hash, seg_hash); - - sec_obj->num_of_segment++; - } -} - - -static int -call_devfsadm(void) -{ - char *phys_path; - di_node_t root_node; - di_node_t prom_node; - di_node_t f_node; - - if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) { - return (-1); - } - - f_node = di_drv_first_node(PICL_CLASS_SEEPROM, root_node); - if (f_node != DI_NODE_NIL) { - phys_path = di_devfs_path(f_node); - if ((prom_node = di_init(phys_path, DINFOMINOR)) - != DI_NODE_NIL) { - di_fini(prom_node); - di_fini(root_node); - (void) pclose(popen(devfsadm_cmd, "r")); - return (0); - } - } - di_fini(root_node); - return (-1); -} - -/* - * Description : - * fru_get_sections() fills an array of section structures passed - * as an argument. - * - * Arguments : - * container_hdl_t : container handle(device descriptor). - * section_t : array of section structure. - * int : maximum number of section in a container. - * - * Returns : - * int - * On success,the number of section structures written is returned; - * on error, -1 is returned and "errno" is set appropriately. - * - */ - -/* ARGSUSED */ -int -fru_get_sections(container_hdl_t container, section_t *section, int maxsec, - door_cred_t *cred) -{ - int device_fd; - int retrys = 1; - int count; - hash_obj_t *cont_object; - hash_obj_t *sec_hash; - - cont_object = lookup_handle_object(container, CONTAINER_TYPE); - if (cont_object == NULL) { - return (-1); - } - - if (cont_object->u.cont_obj->num_of_section > maxsec) { - return (-1); - } - - sec_hash = cont_object->u.cont_obj->sec_obj_list; - if (sec_hash == NULL) { - return (-1); - } - - do { - device_fd = open(cont_object->u.cont_obj->device_pathname, - O_RDWR); - if (device_fd >= 0) { - break; - } - } while ((retrys-- > 0) && (call_devfsadm() == 0)); - - if (device_fd < 0) { - return (-1); - } - - for (count = 0; count < cont_object->u.cont_obj->num_of_section; - count++, section++) { - section->version = -1; - /* populate section_t */ - get_section(device_fd, sec_hash, section); - sec_hash = sec_hash->u.sec_obj->next; - } - - (void) close(device_fd); - - return (count); -} - -/* - * Description : - * fru_get_num_segments() returns the current number of segments - * in a section. - * - * Arguments : - * section_hdl_t : section header holding section information. - * - * Return : - * int - * On success, the number of segments in the argument section is - * returned; on error -1 is returned. - */ -/*ARGSUSED*/ -int -fru_get_num_segments(section_hdl_t section, door_cred_t *cred) -{ - hash_obj_t *sec_object; - section_obj_t *sec_obj; - - sec_object = lookup_handle_object(section, SECTION_TYPE); - if (sec_object == NULL) { - return (-1); - } - - sec_obj = sec_object->u.sec_obj; - if (sec_obj == NULL) { - return (-1); - } - - return (sec_obj->num_of_segment); -} - -/* - * Description : - * fru_get_segments() fills an array of structures representing the - * segments in a section. - * - * Arguments : - * section_hdl_t : holds section number. - * segment_t : on success will hold segment information. - * int : maximum number of segment. - * - * Return : - * int - * On success, the number of segment structures written is - * returned; on errno -1 is returned. - */ - -/* ARGSUSED */ -int -fru_get_segments(section_hdl_t section, segment_t *segment, int maxseg, - door_cred_t *cred) -{ - int count; - hash_obj_t *sec_object; - hash_obj_t *seg_object; - section_obj_t *sec_obj; - - sec_object = lookup_handle_object(section, SECTION_TYPE); - if (sec_object == NULL) { - return (-1); - } - - sec_obj = sec_object->u.sec_obj; - if (sec_obj == NULL) { - return (-1); - } - - if (sec_obj->num_of_segment > maxseg) { - return (-1); - } - - seg_object = sec_object->u.sec_obj->seg_obj_list; - if (seg_object == NULL) { - return (-1); - } - - for (count = 0; count < sec_obj->num_of_segment; count++) { - - /* populate segment_t */ - segment->handle = seg_object->obj_hdl; - (void) memcpy(segment->name, - seg_object->u.seg_obj->segment.name, SEG_NAME_LEN); - segment->descriptor = seg_object->u.seg_obj->segment.descriptor; - - segment->offset = seg_object->u.seg_obj->segment.offset; - segment->length = seg_object->u.seg_obj->segment.length; - seg_object = seg_object->u.seg_obj->next; - segment++; - } - return (0); -} - -/* - * Description : - * fru_add_segment() adds a segment to a section. - * - * Arguments : - * section_hdl_t section - * A handle for the section in which to add the segment. - * - * segment_t *segment - * On entry, the "handle" component of "segment" is ignored and the - * remaining components specify the parameters of the segment to be - * added. On return, the "handle" component is set to the handle - * for the added segment. The segment offset is mandatory for FIXED - * segments; otherwise, the offset is advisory. - * - * Return : - * int - * On success, 0 is returned; on error -1 is returned. - * - */ - -int -fru_add_segment(section_hdl_t section, segment_t *segment, - section_hdl_t *newsection, door_cred_t *cred) -{ - int fd; - int retval; - int offset; - int sec_size; - int seg_cnt; - int bufsize; - int new_seg_offset; - int new_seg_length; - int fixed_segment; - char trailer[] = { 0x0c, 0x00, 0x00, 0x00, 0x00 }; - hash_obj_t *cont_hash; - hash_obj_t *sec_hash; - hash_obj_t *seg_hash; - fru_segdesc_t *new_seg_desc; - unsigned char *crcbuf; - section_layout_t sec_layout; - segment_layout_t *seg_layout; - segment_layout_t *segment_buf; - - /* check the effective uid of the client */ - if (cred->dc_euid != 0) { - errno = EPERM; - return (-1); /* not a root */ - } - - /* section hash */ - sec_hash = lookup_handle_object(section, SECTION_TYPE); - if (sec_hash == NULL) { - return (-1); - } - - /* check for read-only section */ - if (sec_hash->u.sec_obj->section.protection == READ_ONLY_SECTION) { - errno = EPERM; - return (-1); - } - - /* look for duplicate segment */ - seg_hash = sec_hash->u.sec_obj->seg_obj_list; - while (seg_hash != NULL) { - if (strncmp(segment->name, seg_hash->u.seg_obj->segment.name, - SEG_NAME_LEN) == 0) { - errno = EEXIST; - return (-1); /* can't add duplicate segment */ - } - seg_hash = seg_hash->u.seg_obj->next; - } - - /* get the container hash */ - cont_hash = lookup_handle_object(sec_hash->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - if (cont_hash == NULL) { - return (-1); - } - - /* open the container */ - fd = open(cont_hash->u.cont_obj->device_pathname, O_RDWR); - if (fd < 0) { - return (-1); - } - - /* section start here */ - offset = sec_hash->u.sec_obj->section.offset; - - /* read section header layout */ - retval = pread(fd, &sec_layout, sizeof (sec_layout), offset); - if (retval != sizeof (sec_layout)) { - (void) close(fd); - return (-1); - } - - /* check for valid section header */ - if (sec_layout.headertag != SECTION_HDR_TAG) { - /* write a new one */ - sec_layout.headertag = SECTION_HDR_TAG; - sec_layout.headerversion[0] = SECTION_HDR_VER_BIT0; - sec_layout.headerversion[1] = SECTION_HDR_VER_BIT1; - sec_layout.headerlength = sizeof (sec_layout); - sec_layout.segmentcount = 0; - } - - /* section size */ - sec_size = sec_hash->u.sec_obj->section.length; - - /* number of segment in the section */ - seg_cnt = sec_layout.segmentcount; - - /* total sizeof segment + new segment */ - bufsize = sizeof (segment_layout_t) * (seg_cnt + 1); - segment_buf = alloca(bufsize); - if (segment_buf == NULL) { - return (-1); - } - - /* read entire segment header */ - retval = pread(fd, segment_buf, (bufsize - sizeof (segment_layout_t)), - offset + sizeof (section_layout_t)); - if (retval != (bufsize - sizeof (segment_layout_t))) { - (void) close(fd); - return (-1); - } - - new_seg_offset = segment->offset; /* new segment offset */ - new_seg_length = segment->length; /* new segment length */ - - new_seg_desc = (fru_segdesc_t *)&segment->descriptor; - - fixed_segment = new_seg_desc->field.fixed; - - /* get new offset for new segment to be addedd */ - retval = find_offset((char *)segment_buf, seg_cnt, sec_size, - &new_seg_offset, new_seg_length, fixed_segment, fd); - - if (retval != 0) { - (void) close(fd); - errno = EAGAIN; - return (-1); - } - - /* copy new segment data in segment layout */ - seg_layout = (segment_layout_t *)(segment_buf + seg_cnt); - (void) memcpy(&seg_layout->name, segment->name, SEG_NAME_LEN); - (void) memcpy(seg_layout->descriptor, &segment->descriptor, - sizeof (uint32_t)); - seg_layout->length = segment->length; - seg_layout->offset = new_seg_offset; /* new segment offset */ - - sec_layout.segmentcount += 1; - - crcbuf = alloca(sizeof (section_layout_t) + bufsize); - if (crcbuf == NULL) { - (void) close(fd); - return (-1); - } - - sec_layout.headercrc8 = 0; - sec_layout.headerlength += sizeof (segment_layout_t); - - (void) memcpy(crcbuf, (char *)&sec_layout, sizeof (section_layout_t)); - (void) memcpy(crcbuf + sizeof (section_layout_t), segment_buf, bufsize); - - sec_layout.headercrc8 = compute_crc8(crcbuf, bufsize + - sizeof (section_layout_t)); - - /* write section header */ - retval = pwrite(fd, &sec_layout, sizeof (section_layout_t), offset); - if (retval != sizeof (section_layout_t)) { - (void) close(fd); - return (-1); - } - - /* write segment header */ - retval = pwrite(fd, segment_buf, bufsize, offset + - sizeof (section_layout_t)); - if (retval != bufsize) { - (void) close(fd); - return (-1); - } - - /* write segment trailer */ - retval = pwrite(fd, &trailer, sizeof (trailer), new_seg_offset); - if (retval != sizeof (trailer)) { - (void) close(fd); - return (-1); - } - - (void) close(fd); - - /* create new segment hash object */ - seg_hash = create_segment_hash_object(); - if (seg_hash == NULL) { - return (-1); - } - - add_hashobject_to_hashtable(seg_hash); - - copy_segment_layout(&seg_hash->u.seg_obj->segment, seg_layout); - - add_to_seg_object_list(sec_hash, seg_hash); - - sec_hash->u.sec_obj->num_of_segment += 1; - seg_hash->u.seg_obj->trailer_offset = new_seg_offset; - *newsection = section; /* return the new section handle */ - return (0); -} - -static void -free_pkt_object_list(hash_obj_t *hash_obj) -{ - hash_obj_t *next_obj; - hash_obj_t *free_obj; - - next_obj = hash_obj->u.seg_obj->pkt_obj_list; - while (next_obj != NULL) { - free_obj = next_obj; - next_obj = next_obj->u.pkt_obj->next; - /* if prev is NULL it's the first object in the list */ - if (free_obj->prev == NULL) { - hash_table[(free_obj->obj_hdl % TABLE_SIZE)] = - free_obj->next; - if (free_obj->next != NULL) { - free_obj->next->prev = free_obj->prev; - } - } else { - free_obj->prev->next = free_obj->next; - if (free_obj->next != NULL) { - free_obj->next->prev = free_obj->prev; - } - } - free(free_obj->u.pkt_obj); - free(free_obj); - } - - hash_obj->u.seg_obj->pkt_obj_list = NULL; -} - -static void -free_segment_hash(handle_t handle, hash_obj_t *sec_hash) -{ - hash_obj_t *seg_hash; - hash_obj_t *next_hash; - - seg_hash = sec_hash->u.sec_obj->seg_obj_list; - if (seg_hash == NULL) { - return; - } - - if (seg_hash->obj_hdl == handle) { - sec_hash->u.sec_obj->seg_obj_list = seg_hash->u.seg_obj->next; - } else { - while (seg_hash->obj_hdl != handle) { - next_hash = seg_hash; - seg_hash = seg_hash->u.seg_obj->next; - if (seg_hash == NULL) { - return; - } - } - next_hash->u.seg_obj->next = seg_hash->u.seg_obj->next; - } - - if (seg_hash->prev == NULL) { - hash_table[(seg_hash->obj_hdl % TABLE_SIZE)] = seg_hash->next; - if (seg_hash->next != NULL) { - seg_hash->next->prev = NULL; - } - } else { - seg_hash->prev->next = seg_hash->next; - if (seg_hash->next != NULL) { - seg_hash->next->prev = seg_hash->prev; - } - } - - free_pkt_object_list(seg_hash); - free(seg_hash->u.seg_obj); - free(seg_hash); -} - -/* - * Description : - * fru_delete_segment() deletes a segment from a section; the - * associated container data is not altered. - * - * Arguments : segment_hdl_t segment handle. - * section_hdl_t new section handle. - * - * Return : - * int - * On success, 0 returned; On error -1 is returned. - */ - -int -fru_delete_segment(segment_hdl_t segment, section_hdl_t *newsection, - door_cred_t *cred) -{ - int num_of_seg; - int bufsize; - int count; - int retval; - int fd; - int segnum; - hash_obj_t *seg_hash; - hash_obj_t *sec_hash; - hash_obj_t *cont_hash; - hash_obj_t *tmp_hash; - unsigned char *buffer; - fru_segdesc_t *desc; - segment_layout_t *seg_buf; - section_layout_t *sec_layout; - segment_layout_t *seg_layout; - segment_layout_t *next_layout; - - /* check the effective uid of the client */ - if (cred->dc_euid != 0) { - errno = EPERM; - return (-1); /* not a root */ - } - - seg_hash = lookup_handle_object(segment, SEGMENT_TYPE); - if (seg_hash == NULL) { - return (-1); - } - - desc = (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor; - if (!(desc->field.field_perm & SEGMENT_DELETE)) { - errno = EPERM; - return (-1); /* can't delete this segment */ - } - - sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, - SECTION_TYPE); - if (sec_hash == NULL) { - return (-1); - } - - if (sec_hash->u.sec_obj->section.protection == READ_ONLY_SECTION) { - errno = EPERM; - return (-1); - } - - num_of_seg = sec_hash->u.sec_obj->num_of_segment; - - bufsize = (sizeof (segment_layout_t) * num_of_seg); - - seg_buf = alloca(bufsize); - if (seg_buf == NULL) { - return (-1); - } - - segnum = 0; - for (tmp_hash = sec_hash->u.sec_obj->seg_obj_list; tmp_hash != NULL; - tmp_hash = tmp_hash->u.seg_obj->next) { - if (tmp_hash->obj_hdl == segment) { - break; - } - segnum++; - } - - cont_hash = lookup_handle_object(sec_hash->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - if (cont_hash == NULL) { - return (-1); - } - - fd = open(cont_hash->u.cont_obj->device_pathname, O_RDWR); - if (fd < 0) { - return (-1); - } - - sec_layout = alloca(sizeof (section_layout_t)); - if (sec_layout == NULL) { - (void) close(fd); - return (-1); - } - - /* read section layout header */ - retval = pread(fd, sec_layout, sizeof (section_layout_t), - sec_hash->u.sec_obj->section.offset); - if (retval != sizeof (section_layout_t)) { - (void) close(fd); - return (-1); - } - - /* read segment header layout */ - retval = pread(fd, seg_buf, bufsize, - sec_hash->u.sec_obj->section.offset + - sizeof (section_layout_t)); - if (retval != bufsize) { - (void) close(fd); - return (-1); - } - - seg_layout = (segment_layout_t *)(seg_buf + segnum); - next_layout = seg_layout; - for (count = segnum; count < sec_hash->u.sec_obj->num_of_segment-1; - count++) { - next_layout++; - (void) memcpy(seg_layout, next_layout, - sizeof (segment_layout_t)); - seg_layout++; - } - - (void) memset(seg_layout, '\0', sizeof (segment_layout_t)); - - sec_layout->headercrc8 = 0; - - sec_layout->headerlength -= sizeof (segment_layout_t); - sec_layout->segmentcount -= 1; - - buffer = alloca(sec_layout->headerlength); - if (buffer == NULL) { - (void) close(fd); - return (-1); - } - - (void) memcpy(buffer, sec_layout, sizeof (section_layout_t)); - (void) memcpy(buffer + sizeof (section_layout_t), seg_buf, bufsize - - sizeof (segment_layout_t)); - sec_layout->headercrc8 = compute_crc8(buffer, - sec_layout->headerlength); - - /* write section header with update crc8 and header length */ - retval = pwrite(fd, sec_layout, sizeof (section_layout_t), - sec_hash->u.sec_obj->section.offset); - if (retval != sizeof (section_layout_t)) { - (void) close(fd); - return (-1); - } - - /* write the update segment header */ - retval = pwrite(fd, seg_buf, bufsize, - sec_hash->u.sec_obj->section.offset + - sizeof (section_layout_t)); - (void) close(fd); - if (retval != bufsize) { - return (-1); - } - - free_segment_hash(segment, sec_hash); - - *newsection = sec_hash->obj_hdl; - sec_hash->u.sec_obj->num_of_segment = sec_layout->segmentcount; - - return (0); -} - -/* - * Description : - * fru_read_segment() reads the raw contents of a segment. - * - * Arguments : segment_hdl_t : segment handle. - * void * : buffer containing segment data when function returns. - * size_t :number of bytes. - * - * Return : - * int - * On success, the number of bytes read is returned; - * - * Notes : - * Segments containing packets can be read in structured fashion - * using the fru_get_packets() and fru_get_payload() primitives;the - * entire byte range of a segment can be read using - * fru_read_segment(). - */ -/*ARGSUSED*/ -ssize_t -fru_read_segment(segment_hdl_t segment, void *buffer, size_t nbytes, - door_cred_t *cred) -{ - int fd; - int retval; - hash_obj_t *seg_hash; - hash_obj_t *sec_hash; - hash_obj_t *cont_hash; - - /* segment hash object */ - seg_hash = lookup_handle_object(segment, SEGMENT_TYPE); - if (seg_hash == NULL) { - return (-1); - } - - /* section hash object */ - sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, - SECTION_TYPE); - if (sec_hash == NULL) { - return (-1); - } - - /* container hash object */ - cont_hash = lookup_handle_object(sec_hash->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - if (cont_hash == NULL) { - return (-1); - } - - if (seg_hash->u.seg_obj->segment.length < nbytes) { - return (-1); - } - - fd = open(cont_hash->u.cont_obj->device_pathname, O_RDWR); - if (fd < 0) { - return (-1); - } - - retval = pread(fd, buffer, nbytes, seg_hash->u.seg_obj->segment.offset); - (void) close(fd); - if (retval != nbytes) { - return (-1); - } - return (nbytes); -} - -/* - * Description : - * fru_write_segment() writes a raw segment. - * - * Arguments : segment_hdl_t :segment handle. - * const void * : data buffer. - * size_t : number of bytes. - * segment_hdl_t : new segment handle. - * - * Returns : - * int - * On success, the number of bytes written is returned - * - */ -/*ARGSUSED*/ -int -fru_write_segment(segment_hdl_t segment, const void *data, size_t nbytes, - segment_hdl_t *newsegment, door_cred_t *cred) -{ - return (ENOTSUP); -} - - -static int -get_packet(int device_fd, void *buffer, int size, int offset) -{ - int retval; - - retval = pread(device_fd, (char *)buffer, size, offset); - if (retval != -1) { - return (0); - } - return (-1); -} - -/* - * Description : - * get_payload() populates a buffer with the packets payload - * - * Arguments : hash_obj_t : packet. - * int : device file descriptor - * uint8_t* : pointer to a pre allocated buffer - * - * - * Return : - * int - * On success, 0 is returned; on failure - * -1 returned. - */ -int -get_payload(int device_fd, hash_obj_t *packet, uint8_t *payload) -{ - int retval; - packet_obj_t *packet_object; - - - packet_object = packet->u.pkt_obj; - if (packet_object == NULL) { - return (-1); - } - - /* Get the data */ - retval = pread(device_fd, payload, packet_object->paylen, - packet_object->payload_offset); - if (retval != packet_object->paylen) { - free(payload); - return (-1); - } - - return (0); - -} - - -static uint32_t -get_checksum_crc(int device_fd, hash_obj_t *seg_hash, int data_size) -{ - int checksum; - int offset = 0; - int retval; - uint8_t *payload; - uint32_t crc; - hash_obj_t *sec_hash; - hash_obj_t *pkt_hash; - unsigned char *buffer; - - sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, - SECTION_TYPE); - if (sec_hash == NULL) { - return ((uint32_t)-1); - } - - buffer = alloca(data_size); - if (buffer == NULL) { - return ((uint32_t)-1); - } - - /* traverse the packet object list for all the tags and payload */ - for (pkt_hash = seg_hash->u.seg_obj->pkt_obj_list; pkt_hash != NULL; - pkt_hash = pkt_hash->u.pkt_obj->next) { - (void) memcpy(buffer + offset, &pkt_hash->u.pkt_obj->tag, - pkt_hash->u.pkt_obj->tag_size); - offset += pkt_hash->u.pkt_obj->tag_size; - - /* read packet payload */ - payload = malloc(pkt_hash->u.pkt_obj->paylen); - if (payload == NULL) { - return ((uint32_t)-1); - } - retval = get_payload(device_fd, pkt_hash, payload); - if (retval == -1) { - free(payload); - return ((uint32_t)-1); - } - (void) memcpy(buffer + offset, payload, - pkt_hash->u.pkt_obj->paylen); - offset += pkt_hash->u.pkt_obj->paylen; - free(payload); - } - - checksum = sec_hash->u.sec_obj->checksum_method; - - if (checksum == CRC32_SECTION) { /* read-only section */ - crc = compute_crc32(buffer, data_size); - } else { /* read/write section */ - crc = compute_checksum32(buffer, data_size); - } - return (crc); /* computed crc */ -} - -static int -get_packets(hash_obj_t *seg_hash, int device_fd, int offset, int length) -{ - int tag_size; - int paylen; - int retval; - int seg_limit = 0; - int pktcnt = 0; - char *data; - uint32_t crc; - uint32_t origcrc; - fru_tag_t tag; - hash_obj_t *pkt_hash_obj; - fru_segdesc_t *segdesc; - fru_tagtype_t tagtype; - - retval = get_packet(device_fd, &tag, sizeof (fru_tag_t), offset); - if (retval == -1) { - return (-1); - } - - seg_hash->u.seg_obj->trailer_offset = offset; - - data = (char *)&tag; - while (data[0] != SEG_TRAILER_TAG) { - tagtype = get_tag_type(&tag); /* verify tag type */ - if (tagtype == -1) { - return (-1); - } - - tag_size = get_tag_size(tagtype); - if (tag_size == -1) { - return (-1); - } - - seg_limit += tag_size; - if (seg_limit > length) { - return (-1); - } - - paylen = get_payload_length((void *)&tag); - if (paylen == -1) { - return (-1); - } - - seg_limit += paylen; - if (seg_limit > length) { - return (-1); - } - - pkt_hash_obj = create_packet_hash_object(); - if (pkt_hash_obj == NULL) { - return (-1); - } - - offset += tag_size; - - /* don't change this */ - pkt_hash_obj->u.pkt_obj->tag.raw_data = 0; - (void) memcpy(&pkt_hash_obj->u.pkt_obj->tag, &tag, tag_size); - pkt_hash_obj->u.pkt_obj->paylen = paylen; - pkt_hash_obj->u.pkt_obj->tag_size = tag_size; - pkt_hash_obj->u.pkt_obj->payload_offset = offset; - - offset += paylen; - - add_hashobject_to_hashtable(pkt_hash_obj); - add_to_pkt_object_list(seg_hash, pkt_hash_obj); - - pktcnt++; - - retval = get_packet(device_fd, &tag, sizeof (fru_tag_t), - offset); - if (retval == -1) { - return (retval); - } - - data = (char *)&tag; - } - - segdesc = (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor; - - seg_hash->u.seg_obj->trailer_offset = offset; - - if (!segdesc->field.ignore_checksum) { - crc = get_checksum_crc(device_fd, seg_hash, seg_limit); - offset = seg_hash->u.seg_obj->segment.offset; - - retval = pread(device_fd, &origcrc, sizeof (origcrc), - offset + seg_limit + 1); - if (retval != sizeof (origcrc)) { - return (-1); - } - - if (origcrc != crc) { - seg_hash->u.seg_obj->trailer_offset = offset; - return (-1); - } - } - - return (pktcnt); -} - -/* - * Description : - * fru_get_num_packets() returns the current number of packets - * in a segment. - * - * Arguments : segment_hdl_t : segment handle. - * - * Return : - * int - * On success, the number of packets is returned; - * -1 on failure. - */ -/*ARGSUSED*/ -int -fru_get_num_packets(segment_hdl_t segment, door_cred_t *cred) -{ - int device_fd; - int pktcnt; - int length; - uint16_t offset; - hash_obj_t *cont_hash_obj; - hash_obj_t *seg_hash; - fru_segdesc_t *segdesc; - segment_obj_t *segment_object; - - seg_hash = lookup_handle_object(segment, SEGMENT_TYPE); - if (seg_hash == NULL) { - return (-1); - } - - segment_object = seg_hash->u.seg_obj; - if (segment_object == NULL) { - return (-1); - } - - - segdesc = (fru_segdesc_t *)&segment_object->segment.descriptor; - if (segdesc->field.opaque) { - return (0); - } - - offset = segment_object->segment.offset; - length = segment_object->segment.length; - - cont_hash_obj = get_container_hash_object(SEGMENT_TYPE, - segment_object->section_hdl); - - if (cont_hash_obj == NULL) { - return (-1); - } - - if (seg_hash->u.seg_obj->pkt_obj_list != NULL) { - return (segment_object->num_of_packets); - } - - segment_object->num_of_packets = 0; - device_fd = open(cont_hash_obj->u.cont_obj->device_pathname, - O_RDWR); - if (device_fd < 0) { - return (-1); - } - - pktcnt = get_packets(seg_hash, device_fd, offset, - length); - if (pktcnt == -1) { - free_pkt_object_list(seg_hash); - seg_hash->u.seg_obj->pkt_obj_list = NULL; - } - - segment_object->num_of_packets = pktcnt; - (void) close(device_fd); - - return (segment_object->num_of_packets); -} - - -/* - * Description : - * fru_get_packets() fills an array of structures representing the - * packets in a segment. - * - * Arguments : segment_hdl_t : segment handle. - * packet_t : packet buffer. - * int : maximum number of packets. - * - * Return : - * int - * On success, the number of packet structures written is returned; - * On failure -1 is returned; - * - */ -/*ARGSUSED*/ -int -fru_get_packets(segment_hdl_t segment, packet_t *packet, int maxpackets, - door_cred_t *cred) -{ - int count; - hash_obj_t *seg_hash_obj; - hash_obj_t *pkt_hash_obj; - - /* segment hash object */ - seg_hash_obj = lookup_handle_object(segment, SEGMENT_TYPE); - if (seg_hash_obj == NULL) { - return (-1); - } - - if (seg_hash_obj->u.seg_obj->num_of_packets != maxpackets) { - return (-1); - } - - pkt_hash_obj = seg_hash_obj->u.seg_obj->pkt_obj_list; - if (pkt_hash_obj == NULL) { - return (-1); - } - - for (count = 0; count < maxpackets; count++, packet++) { - packet->handle = pkt_hash_obj->obj_hdl; - packet->tag = 0; - (void) memcpy(&packet->tag, &pkt_hash_obj->u.pkt_obj->tag, - pkt_hash_obj->u.pkt_obj->tag_size); - pkt_hash_obj = pkt_hash_obj->u.pkt_obj->next; - } - - return (0); -} - -/* - * Description : - * fru_get_payload() copies the contents of a packet's payload. - * - * Arguments : packet_hdl_t : packet handle. - * void * : payload buffer. - * size_t : sizeof the buffer. - * - * Return : - * int - * On success, the number of bytes copied is returned; On error - * -1 returned. - */ -/*ARGSUSED*/ -ssize_t -fru_get_payload(packet_hdl_t packet, void *buffer, size_t nbytes, - door_cred_t *cred) -{ - int retval; - int device_fd; - uint8_t *payload; - hash_obj_t *packet_hash_obj; - hash_obj_t *segment_hash_obj; - hash_obj_t *container_hash_obj; - - /* packet hash object */ - packet_hash_obj = lookup_handle_object(packet, PACKET_TYPE); - if (packet_hash_obj == NULL) { - return (-1); - } - - payload = malloc(packet_hash_obj->u.pkt_obj->paylen); - if (payload == NULL) { - return (-1); - } - - /* lookup the segment hash object */ - segment_hash_obj = - lookup_handle_object(packet_hash_obj->u.pkt_obj->segment_hdl, - SEGMENT_TYPE); - if (segment_hash_obj == NULL) { - free(payload); - return (-1); - } - - /* Get the container hash object to get the seeprom device path */ - container_hash_obj = get_container_hash_object(SEGMENT_TYPE, - segment_hash_obj->u.seg_obj->section_hdl); - if (container_hash_obj == NULL) { - free(payload); - return (-1); - } - - /* Open the seeprom device */ - device_fd = open(container_hash_obj->u.cont_obj->device_pathname, - O_RDWR); - if (device_fd < 0) { - free(payload); - return (-1); - } - - - /* Call to get the payload */ - retval = get_payload(device_fd, packet_hash_obj, payload); - if (retval == -1) { - free(payload); - (void) close(device_fd); - return (-1); - } - - - /* verify payload length */ - if (nbytes != packet_hash_obj->u.pkt_obj->paylen) { - free(payload); - (void) close(device_fd); - return (-1); - } - - (void) memcpy(buffer, payload, nbytes); - free(payload); - (void) close(device_fd); - return (nbytes); -} - -/* - * Description : - * fru_update_payload() writes the contents of a packet's payload. - * - * Arguments : packet_hdl_t : packet handle. - * const void * : data buffer. - * size_t : buffer size. - * packet_hdl_t : new packet handle. - * - * Return : - * int - * On success, 0 is returned; on failure - * -1 is returned. - */ - -int -fru_update_payload(packet_hdl_t packet, const void *data, size_t nbytes, - packet_hdl_t *newpacket, door_cred_t *cred) -{ - int fd; - int segment_offset; - int trailer_offset; - int retval; - uint32_t crc; - hash_obj_t *pkt_hash; - hash_obj_t *seg_hash; - hash_obj_t *sec_hash; - hash_obj_t *cont_hash; - fru_segdesc_t *desc; - - /* check the effective uid of the client */ - if (cred->dc_euid != 0) { - errno = EPERM; - return (-1); /* not a root */ - } - - /* packet hash object */ - pkt_hash = lookup_handle_object(packet, PACKET_TYPE); - if (pkt_hash == NULL) { - return (-1); - } - - /* segment hash object */ - seg_hash = lookup_handle_object(pkt_hash->u.pkt_obj->segment_hdl, - SEGMENT_TYPE); - if (seg_hash == NULL) { - return (-1); - } - - /* check for write perm. */ - desc = (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor; - if (!(desc->field.field_perm & SEGMENT_WRITE)) { - errno = EPERM; - return (-1); /* write not allowed */ - } - - sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, - SECTION_TYPE); - if (sec_hash == NULL) { - return (-1); - } - - if (sec_hash->u.sec_obj->section.protection == READ_ONLY_SECTION) { - errno = EPERM; - return (-1); /* read-only section */ - } - - cont_hash = lookup_handle_object(sec_hash->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - if (cont_hash == NULL) { - return (-1); - } - - if (pkt_hash->u.pkt_obj->paylen != nbytes) { - return (-1); - } - - fd = open(cont_hash->u.cont_obj->device_pathname, O_RDWR); - if (fd < 0) { - return (-1); - } - - trailer_offset = seg_hash->u.seg_obj->trailer_offset; - segment_offset = seg_hash->u.seg_obj->segment.offset; - - crc = get_checksum_crc(fd, seg_hash, (trailer_offset - segment_offset)); - retval = pwrite(fd, data, nbytes, pkt_hash->u.pkt_obj->payload_offset); - if (retval != nbytes) { - (void) close(fd); - return (-1); - } - - retval = pwrite(fd, &crc, sizeof (crc), trailer_offset + 1); - (void) close(fd); - if (retval != sizeof (crc)) { - return (-1); - } - *newpacket = packet; - return (0); -} - -/* - * Description : - * fru_append_packet() appends a packet to a segment. - * - * Arguments : - * segment_hdl_t segment - * A handle for the segment to which the packet will be appended. - * - * packet_t *packet - * On entry, the "tag" component of "packet" specifies the tag - * value for the added packet; the "handle" component is ignored. - * On return, the "handle" component is set to the handle of the - * appended packet. - * - * const void *payload - * A pointer to the caller's buffer containing the payload data for - * the appended packet. - * - * size_t nbytes - * The size of the caller buffer. - * - * Return : - * int - * On success, 0 is returned; on error -1 is returned; - */ - -int -fru_append_packet(segment_hdl_t segment, packet_t *packet, const void *payload, - size_t nbytes, segment_hdl_t *newsegment, door_cred_t *cred) -{ - int trailer_offset; - int tag_size; - int fd; - int retval; - char trailer[] = {0x0c, 0x00, 0x00, 0x00, 0x00}; - uint32_t crc; - hash_obj_t *seg_hash; - hash_obj_t *sec_hash; - hash_obj_t *pkt_hash; - hash_obj_t *cont_hash; - fru_tagtype_t tagtype; - fru_segdesc_t *desc; - - /* check the effective uid of the client */ - if (cred->dc_euid != 0) { - errno = EPERM; - return (-1); /* not a root */ - } - - seg_hash = lookup_handle_object(segment, SEGMENT_TYPE); - if (seg_hash == NULL) { - return (-1); - } - - /* check for write perm. */ - desc = (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor; - if (!(desc->field.field_perm & SEGMENT_WRITE)) { - errno = EPERM; - return (-1); /* write not allowed */ - } - - sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, - SECTION_TYPE); - if (sec_hash == NULL) { - return (-1); - } - - if (sec_hash->u.sec_obj->section.protection == READ_ONLY_SECTION) { - errno = EPERM; - return (-1); /* read-only section */ - } - - trailer_offset = seg_hash->u.seg_obj->trailer_offset; - - /* - * if trailer offset is 0 than parse the segment data to get the trailer - * offset to compute the remaining space left in the segment area for - * new packet to be added. - */ - if (trailer_offset == 0) { - (void) fru_get_num_packets(segment, cred); - trailer_offset = seg_hash->u.seg_obj->trailer_offset; - } - - tagtype = get_tag_type((void *)&packet->tag); - if (tagtype == -1) { - return (-1); - } - - tag_size = get_tag_size(tagtype); - if (tag_size == -1) { - return (-1); - } - - if (seg_hash->u.seg_obj->segment.length > - ((trailer_offset - seg_hash->u.seg_obj->segment.offset) + - tag_size + nbytes + sizeof (char) - + sizeof (uint32_t))) { - /* create new packet hash */ - pkt_hash = create_packet_hash_object(); - if (pkt_hash == NULL) { - return (-1); - } - - /* tag initialization */ - (void) memcpy(&pkt_hash->u.pkt_obj->tag, &packet->tag, - tag_size); - pkt_hash->u.pkt_obj->tag_size = tag_size; - pkt_hash->u.pkt_obj->paylen = nbytes; - pkt_hash->u.pkt_obj->payload_offset = trailer_offset + tag_size; - - /* add to hash table */ - add_hashobject_to_hashtable(pkt_hash); - - add_to_pkt_object_list(seg_hash, pkt_hash); - - cont_hash = lookup_handle_object(sec_hash->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - if (cont_hash == NULL) { - return (-1); - } - - fd = open(cont_hash->u.cont_obj->device_pathname, O_RDWR); - if (fd < 0) { - return (-1); - } - - /* update the trailer offset */ - trailer_offset += tag_size + nbytes; - - /* calculate new checksum */ - crc = get_checksum_crc(fd, seg_hash, (trailer_offset - - seg_hash->u.seg_obj->segment.offset)); - - retval = pwrite(fd, &packet->tag, tag_size, trailer_offset - - (tag_size + nbytes)); - if (retval != tag_size) { - (void) close(fd); - return (-1); - } - - retval = pwrite(fd, payload, nbytes, trailer_offset - nbytes); - if (retval != nbytes) { - (void) close(fd); - return (-1); - } - - retval = pwrite(fd, trailer, sizeof (trailer), trailer_offset); - if (retval != sizeof (trailer)) { - (void) close(fd); - return (-1); - } - - retval = pwrite(fd, &crc, sizeof (crc), trailer_offset + 1); - (void) close(fd); - if (retval != sizeof (crc)) { - return (-1); - } - - seg_hash->u.seg_obj->trailer_offset = trailer_offset; - seg_hash->u.seg_obj->num_of_packets += 1; - - *newsegment = segment; /* return new segment handle */ - return (0); - } else { - errno = EAGAIN; - } - - return (-1); -} - -static void -adjust_packets(int fd, hash_obj_t *free_obj, hash_obj_t *object_list) -{ - int retval; - uint8_t *payload; - uint32_t new_offset; - hash_obj_t *hash_ptr; - - - new_offset = free_obj->u.pkt_obj->payload_offset - - free_obj->u.pkt_obj->tag_size; - for (hash_ptr = object_list; hash_ptr != NULL; - hash_ptr = hash_ptr->u.pkt_obj->next) { - - payload = malloc(hash_ptr->u.pkt_obj->paylen); - if (payload == NULL) { - return; - } - retval = get_payload(fd, hash_ptr, payload); - if (retval == -1) { - free(payload); - return; - } - - retval = pwrite(fd, &hash_ptr->u.pkt_obj->tag, - hash_ptr->u.pkt_obj->tag_size, new_offset); - if (retval != hash_ptr->u.pkt_obj->tag_size) { - free(payload); - return; - } - new_offset += hash_ptr->u.pkt_obj->tag_size; - hash_ptr->u.pkt_obj->payload_offset = new_offset; - retval = pwrite(fd, payload, - hash_ptr->u.pkt_obj->paylen, new_offset); - if (retval != hash_ptr->u.pkt_obj->paylen) { - free(payload); - return; - } - new_offset += hash_ptr->u.pkt_obj->paylen; - free(payload); - } -} - -static void -free_packet_object(handle_t handle, hash_obj_t *seg_hash) -{ - hash_obj_t *pkt_hash; - hash_obj_t *next_hash; - - pkt_hash = seg_hash->u.seg_obj->pkt_obj_list; - if (pkt_hash == NULL) { - return; - } - - if (pkt_hash->obj_hdl == handle) { - seg_hash->u.seg_obj->pkt_obj_list = pkt_hash->u.pkt_obj->next; - } else { - while (pkt_hash->obj_hdl != handle) { - next_hash = pkt_hash; - pkt_hash = pkt_hash->u.pkt_obj->next; - if (pkt_hash == NULL) { - return; - } - } - next_hash->u.pkt_obj->next = pkt_hash->u.pkt_obj->next; - } - - if (pkt_hash->prev == NULL) { - hash_table[(pkt_hash->obj_hdl % TABLE_SIZE)] = pkt_hash->next; - if (pkt_hash->next != NULL) { - pkt_hash->next->prev = NULL; - } - } else { - pkt_hash->prev->next = pkt_hash->next; - if (pkt_hash->next != NULL) { - pkt_hash->next->prev = pkt_hash->prev; - } - } - - free(pkt_hash->u.pkt_obj); - free(pkt_hash); -} - -/* - * Description : - * fru_delete_packet() deletes a packet from a segment. - * - * Arguments : packet_hdl_t : packet number to be deleted. - * segment_hdl_t : new segment handler. - * - * Return : - * int - * On success, 0 is returned; on error, -1. - * - * NOTES - * Packets are adjacent; thus, deleting a packet requires moving - * succeeding packets to compact the resulting hole. - */ - -int -fru_delete_packet(packet_hdl_t packet, segment_hdl_t *newsegment, - door_cred_t *cred) -{ - int retval; - int fd; - char trailer[] = { 0x0c, 0x00, 0x00, 0x00, 0x00}; - uint32_t crc; - hash_obj_t *tmp_obj; - hash_obj_t *pkt_hash; - hash_obj_t *sec_hash; - hash_obj_t *cont_hash; - hash_obj_t *prev_obj; - hash_obj_t *seg_hash; - fru_segdesc_t *desc; - - /* check the effective uid of the client */ - if (cred->dc_euid != 0) { - errno = EPERM; - return (-1); /* not a root */ - } - - /* packet hash object */ - pkt_hash = lookup_handle_object(packet, PACKET_TYPE); - if (pkt_hash == NULL) { - return (-1); - } - - /* segment hash object */ - seg_hash = lookup_handle_object(pkt_hash->u.pkt_obj->segment_hdl, - SEGMENT_TYPE); - if (seg_hash == NULL) { - return (-1); - } - - /* check for write perm. */ - desc = (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor; - if (!(desc->field.field_perm & SEGMENT_WRITE)) { - errno = EPERM; - return (-1); /* write not allowed */ - } - - /* section hash object */ - sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, - SECTION_TYPE); - if (sec_hash == NULL) { - return (-1); - } - - if (sec_hash->u.sec_obj->section.protection == READ_ONLY_SECTION) { - errno = EPERM; - return (-1); /* read-only section */ - } - - prev_obj = seg_hash->u.seg_obj->pkt_obj_list; - if (prev_obj == NULL) { - return (-1); - } - - /* container hash object */ - cont_hash = lookup_handle_object(sec_hash->u.sec_obj->cont_hdl, - CONTAINER_TYPE); - if (cont_hash == NULL) { - return (-1); - } - - fd = open(cont_hash->u.cont_obj->device_pathname, O_RDWR); - if (fd < 0) { - return (-1); - } - - if (prev_obj->obj_hdl == packet) { /* first object to be deleted */ - adjust_packets(fd, prev_obj, prev_obj->u.pkt_obj->next); - seg_hash->u.seg_obj->trailer_offset -= - (prev_obj->u.pkt_obj->tag_size - + prev_obj->u.pkt_obj->paylen); - free_packet_object(packet, seg_hash); - } else { - for (tmp_obj = prev_obj; - tmp_obj != NULL; tmp_obj = tmp_obj->u.pkt_obj->next) { - /* found the object */ - if (tmp_obj->obj_hdl == packet) { - adjust_packets(fd, tmp_obj, - tmp_obj->u.pkt_obj->next); - seg_hash->u.seg_obj->trailer_offset -= - (tmp_obj->u.pkt_obj->tag_size - + tmp_obj->u.pkt_obj->paylen); - free_packet_object(packet, seg_hash); - } - } - } - - seg_hash->u.seg_obj->num_of_packets -= 1; - - /* calculate checksum */ - crc = get_checksum_crc(fd, seg_hash, - (seg_hash->u.seg_obj->trailer_offset - - seg_hash->u.seg_obj->segment.offset)); - /* write trailer at new offset */ - retval = pwrite(fd, &trailer, sizeof (trailer), - seg_hash->u.seg_obj->trailer_offset); - if (retval != sizeof (trailer)) { - (void) close(fd); - return (-1); - } - - /* write the checksum value */ - retval = pwrite(fd, &crc, sizeof (crc), - seg_hash->u.seg_obj->trailer_offset + 1); - (void) close(fd); - if (retval != sizeof (crc)) { - return (-1); - } - - *newsegment = seg_hash->obj_hdl; /* return new segment handle */ - return (0); -} - -/* - * Description : - * fru_close_container() removes the association between a - * container and its handle. this routines free's up all the - * hash object contained under container. - * - * Arguments : - * container_hdl_t holds the file descriptor of the fru. - * - * Return : - * int - * return 0. - * - */ - -/* ARGSUSED */ -int -fru_close_container(container_hdl_t container) -{ - hash_obj_t *hash_obj; - hash_obj_t *prev_hash; - hash_obj_t *sec_hash_obj; - handle_t obj_hdl; - - /* lookup for container hash object */ - hash_obj = lookup_handle_object(container, CONTAINER_TYPE); - if (hash_obj == NULL) { - return (0); - } - - /* points to section object list */ - sec_hash_obj = hash_obj->u.cont_obj->sec_obj_list; - - /* traverse section object list */ - while (sec_hash_obj != NULL) { - - /* traverse segment hash object in the section */ - while (sec_hash_obj->u.sec_obj->seg_obj_list != NULL) { - /* object handle of the segment hash object */ - obj_hdl = - sec_hash_obj->u.sec_obj->seg_obj_list->obj_hdl; - free_segment_hash(obj_hdl, sec_hash_obj); - } - - /* going to free section hash object, relink the hash object */ - if (sec_hash_obj->prev == NULL) { - hash_table[(sec_hash_obj->obj_hdl % TABLE_SIZE)] - = sec_hash_obj->next; - if (sec_hash_obj->next != NULL) { - sec_hash_obj->next->prev = NULL; - } - } else { - sec_hash_obj->prev->next = sec_hash_obj->next; - if (sec_hash_obj->next != NULL) { - sec_hash_obj->next->prev = sec_hash_obj->prev; - } - } - - free(sec_hash_obj->u.sec_obj); /* free section hash object */ - - prev_hash = sec_hash_obj; - - sec_hash_obj = sec_hash_obj->u.sec_obj->next; - - free(prev_hash); /* free section hash */ - } - - /* free container hash object */ - if (hash_obj->prev == NULL) { - hash_table[(sec_hash_obj->obj_hdl % TABLE_SIZE)] = - hash_obj->next; - if (hash_obj->next != NULL) { - hash_obj->next->prev = NULL; - } - } else { - hash_obj->prev->next = hash_obj->next; - if (hash_obj->next != NULL) { - hash_obj->next->prev = hash_obj->prev; - } - } - - free(hash_obj->u.cont_obj); - free(hash_obj); - return (0); -} - -/* - * Description : - * fru_is_data_available() checks to see if the frudata - * is available on a fru. - * - * Arguments : - * picl_nodehdl_t holds the picl node handle of the fru. - * - * Return : - * int - * return 1: if FRUID information is available - * return 0: if FRUID information is not present - * - */ - -/* ARGSUSED */ -int -fru_is_data_available(picl_nodehdl_t fru) -{ - return (0); -} diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_access_impl.h b/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_access_impl.h deleted file mode 100644 index 72691a0ab0..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_access_impl.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - */ - -#ifndef _FRU_ACCESS_IMPL_H -#define _FRU_ACCESS_IMPL_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <dial.h> -#include <strings.h> -#include <libdevinfo.h> -#include <sys/systeminfo.h> -#include <picl.h> -#include <picltree.h> -#include "picldefs.h" -#include <syslog.h> -#include <errno.h> -#include "libfru.h" -#include "fru_tag.h" -#include "fru_access.h" - -/* object types */ -typedef enum {CONTAINER_TYPE, SECTION_TYPE, SEGMENT_TYPE, PACKET_TYPE} object_t; - -#define TABLE_SIZE 64 /* hash table size */ - -/* container configuration file name */ -#define CONTAINER_CONF_FILE \ - "/usr/platform/SUNW,Serverblade1/lib/fru_container.conf" - -/* section header */ -#define SECTION_HDR_TAG 0x08 -#define SECTION_HDR_VER 0x0001 -#define SECTION_HDR_LENGTH 0x06 -#define SECTION_HDR_CRC8 0x00 -#define SECTION_HDR_VER_BIT0 0x00 -#define SECTION_HDR_VER_BIT1 0x01 - -#define READ_ONLY_SECTION 1 /* section is read-only */ - -#define CRC32_SECTION 0 -#define CHECKSUM32_SECTION 1 - -#define GET_SEGMENT_DESCRIPTOR \ - (seg_layout->descriptor[1]|seg_layout->descriptor[0] << 16) - -#define GET_SECTION_HDR_VERSION \ - (sec_hdr.headerversion[1]|sec_hdr.headerversion[0] << 8) - -/* Segment Trailer Tag */ -#define SEG_TRAILER_TAG 0x0C - -/* defines fixed segment */ -#define SEGMENT_FIXED 1 - -typedef union { - uint32_t all_bits; - struct { - unsigned read_only : 1; - unsigned chk_type : 1; - unsigned unused : 8; - unsigned : 8; - unsigned : 8; - unsigned : 6; - } field; -} sectdescbit_t; - -typedef struct { - sectdescbit_t description; - uint32_t address; /* for SEEPROMS this is the offset */ - uint32_t size; -} sectioninfo_t; - -typedef uint16_t headerrev_t; - -#define MAX_NUMOF_SECTION 2 - -typedef struct { - headerrev_t header_ver; - int num_sections; - sectioninfo_t section_info[MAX_NUMOF_SECTION]; -} container_info_t; - - -/* section header layout */ -typedef struct { - uint8_t headertag; /* section header tag */ - uint8_t headerversion[2]; /* header version (msb) */ - uint8_t headerlength; /* header length */ - uint8_t headercrc8; /* crc8 */ - uint8_t segmentcount; /* total number of segment */ -} section_layout_t; - -/* segment header layout */ -typedef struct { - uint16_t name; /* segment name */ - uint16_t descriptor[2]; /* descriptor (msb) */ - uint16_t offset; /* segment data offset */ - uint16_t length; /* segment length */ -} segment_layout_t; - -/* segment information used in finding new offset for a new segment */ -typedef struct { - int segnum; /* segment number */ - int offset; /* segment offset */ - int length; /* segment length */ - int fixed; /* fixed or non-fixed segment */ -} seg_info_t; - -typedef uint64_t handle_t; - -struct hash_obj; - -/* packet hash object */ -typedef struct { - handle_t segment_hdl; /* segment handle */ - fru_tag_t tag; - int tag_size; - uint32_t paylen; - uint32_t payload_offset; - struct hash_obj *next; -} packet_obj_t; - -/* segment hash object */ -typedef struct { - handle_t section_hdl; /* section handle */ - int num_of_packets; /* in a segment */ - int trailer_offset; - segment_t segment; - struct hash_obj *pkt_obj_list; /* packet object list */ - struct hash_obj *next; -} segment_obj_t; - -/* section hash object */ -typedef struct { - handle_t cont_hdl; /* container handle */ - section_t section; - int num_of_segment; /* in a section */ - int checksum_method; /* indicates the checksum method used */ - struct hash_obj *seg_obj_list; /* points to segment objects list */ - struct hash_obj *next; -} section_obj_t; - -/* container hash object */ -typedef struct { - char device_pathname[PATH_MAX]; /* device name */ - int num_of_section; /* num of section in container */ - struct hash_obj *sec_obj_list; /* points to section objects list */ -} container_obj_t; - -/* hash object */ -typedef struct hash_obj { - int object_type; - handle_t obj_hdl; - union { - container_obj_t *cont_obj; - section_obj_t *sec_obj; - segment_obj_t *seg_obj; - packet_obj_t *pkt_obj; - } u; - struct hash_obj *next; - struct hash_obj *prev; -} hash_obj_t; - -unsigned char compute_crc8(unsigned char *bytes, int length); -long compute_crc32(unsigned char *bytes, int length); -long compute_checksum32(unsigned char *bytes, int length); - -#ifdef __cplusplus -} -#endif - -#endif /* _FRU_ACCESS_IMPL_H */ diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_container.conf b/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_container.conf deleted file mode 100644 index 282f6c3db1..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/fruaccess/fru_container.conf +++ /dev/null @@ -1,36 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2002 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -#ident "%Z%%M% %I% %E% SMI" -# - -# cut off read only section. -8k_6krw1792ro_SEEPROM:1:0,0,6144:1,6144,1792 - -# Note the extra flag per section to represent the checksum method -# 0 = CRC32 1 = CHECKSUM32 -# standard SEEPROM -i2c-at24c64|6krw2kro|8k_6krw2kro_SEEPROM:1:1,1,0,6144:1,0,6144,2048 - diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/frudata/Makefile b/usr/src/cmd/picl/plugins/sun4u/blade/frudata/Makefile deleted file mode 100644 index 0e76092544..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/frudata/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/sun4u/blade/frudata/Makefile -# - -include $(SRC)/Makefile.psm - -# include library definitions -include $(SRC)/lib/Makefile.lib - -ROOT_PLATFORM = $(USR_PLAT_DIR)/SUNW,Serverblade1 - -include $(SRC)/cmd/picl/plugins/Makefile.com - -ROOTLIBDIR = $(ROOT_PLAT_PLUGINDIR) - -CONF= libpiclfrudata.conf -ROOTCONF= $(CONF:%=$(ROOTLIBDIR)/%) -$(ROOTCONF) := FILEMODE = 0644 - -ROOTLINTDIR = $(ROOTLIBDIR) - -.KEEP_STATE: - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint - -all: $(CONF) - -install: $(ROOTLIBDIR) $(ROOTCONF) - -# include library targets -include $(SRC)/lib/Makefile.targ -include $(SRC)/cmd/picl/plugins/Makefile.targ - -$(ROOTLINTDIR)/%: ../% - $(INS.file) - -lint: - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/frudata/libpiclfrudata.conf b/usr/src/cmd/picl/plugins/sun4u/blade/frudata/libpiclfrudata.conf deleted file mode 100644 index 1cfadefdcd..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/frudata/libpiclfrudata.conf +++ /dev/null @@ -1,34 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2002 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -#ident "%Z%%M% %I% %E% SMI" -# -# This file creates the FRU device paths for the FRUAccess library -# - -VERSION 1.0 - -name:/platform/pci/isa/bscbus/i2c/motherboard-fru -PROP FRUDevicePath string r 0 "/devices/pci@1f,0/isa@7/bscbus@0,1000/i2c@300,0/motherboard-fru@0,a0:motherboard-fru" diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/frutree/Makefile b/usr/src/cmd/picl/plugins/sun4u/blade/frutree/Makefile deleted file mode 100644 index c71fdb90df..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/frutree/Makefile +++ /dev/null @@ -1,77 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/sun4u/blade/frutree/Makefile -# - -include $(SRC)/Makefile.psm - -# include library definitions -include $(SRC)/lib/Makefile.lib - -ROOT_PLATFORM = $(USR_PLAT_DIR)/SUNW,Serverblade1 - - -include $(SRC)/cmd/picl/plugins/Makefile.com - -ROOTLIBDIR = $(ROOT_PLAT_PLUGINDIR) - -CONF= piclfrutree.conf -ROOTCONF= $(CONF:%=$(ROOTLIBDIR)/%) -$(ROOTCONF) := FILEMODE = 0644 -INFOS= piclfrutree.info system-board.info - -ROOTLINTDIR = $(ROOTLIBDIR) - -.KEEP_STATE: - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint - -all: $(CONF) - -install: $(ROOTLIBDIR) $(ROOTCONF) - -$(CONF): $(INFOS) - $(RM) $@ - $(CPP) piclfrutree.info | \ - $(SED) -e '/^[ ]*$$/d' -e '/^#/d' > $@ - -# include library targets -include $(SRC)/lib/Makefile.targ -include $(SRC)/cmd/picl/plugins/Makefile.targ - -$(ROOTLINTDIR)/%: ../% - $(INS.file) - -lint: - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/frutree/piclfrutree.info b/usr/src/cmd/picl/plugins/sun4u/blade/frutree/piclfrutree.info deleted file mode 100644 index 810c7b479c..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/frutree/piclfrutree.info +++ /dev/null @@ -1,74 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * #ident "%Z%%M% %I% %E% SMI" - * - * supported prop types: void, int, uint, float, string - * supported prop access_modes: r, w, rw - * - * VERSION <version_number> -- supported version number is 1.0 - * - * name:<namepath> -- gives the anchor node - * where <namepath> is <nodename>[@<bus-addr>][?<prop>=<val>] - * - * _class:<classpath> -- gives the anchor node - * where <classpath> is <classname>[@<bus-addr>][?<prop>=<val>] - * - * NODE <name> <class> - * {describes a subtree} - * ENDNODE - * - * PROP <name> <type> <access_mode> [<size> <value>] -- per property - * - * REFPROP <name> <dstnode> - * - * REFNODE <name> <class> with <destnode> -- Associates a new node - * with <destnode> if exists - * where - * <name> is the nodename - * <class> is the picl class. - * <destnode> is name:<namepath> or _class:<classpath> - * - * If "name:" or "_class:" is not specified in the <path>, - * the default is "name:" - * - */ - -VERSION 1.0 -VERBOSE 1 -NODE frutree picl - NODE chassis fru - /* - * SunMC physical view view_points for this platform - * This will get moved to a separate SunMC physical view plugin later. - */ - PROP ViewPoints string r 0 "front rear side" - PROP SlotType string r 0 "chassis" - PROP Label string r 0 "Blade" - ENDNODE -ENDNODE - -name:/frutree/chassis -#include "system-board.info" diff --git a/usr/src/cmd/picl/plugins/sun4u/blade/frutree/system-board.info b/usr/src/cmd/picl/plugins/sun4u/blade/frutree/system-board.info deleted file mode 100644 index 6bb20ad990..0000000000 --- a/usr/src/cmd/picl/plugins/sun4u/blade/frutree/system-board.info +++ /dev/null @@ -1,115 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * #ident "%Z%%M% %I% %E% SMI" - * - * This file creates the system board structure - */ - -NODE system-board fru - PROP SlotType string r 0 "system-board" - NODE cpu-slot location - PROP SlotType string r 0 "cpu" - PROP Label string r 0 "CPU0" - PROP Slot uint r 4 0 - ENDNODE - NODE fan-slot location - PROP SlotType string r 0 "fan-unit" - PROP Label string r 0 "cpu-fan" - PROP Slot uint r 4 0 - ENDNODE - NODE mem-slot location - PROP SlotType string r 0 "memory-module" - PROP Slot uint r 4 0 - PROP Label string r 0 "DIMM0" - ENDNODE - NODE mem-slot location - PROP SlotType string r 0 "memory-module" - PROP Slot uint r 4 1 - PROP Label string r 0 "DIMM1" - ENDNODE -ENDNODE - -/* - * create the fru modules for CPUs in the fru tree - */ -name:/frutree/chassis/system-board/cpu-slot?Slot=0 -REFNODE cpu-module fru WITH _class:/upa/cpu?ID=0 - - -/* - * seeprom source for motherboard - */ -name:/frutree/chassis/system-board -PROP FRUDataAvailable void r -REFPROP _seeprom_source name:/platform/pci/isa/bscbus/i2c/motherboard-fru - - -/* - * Set up memory module fru - */ -name:/frutree/chassis/system-board/mem-slot?Label=DIMM0 -REFNODE mem-module fru WITH name:/platform/pci/pmu/i2c/dimm-fru-prom?UnitAddress=0,a8 - -name:/frutree/chassis/system-board/mem-slot?Label=DIMM1 -REFNODE mem-module fru WITH name:/platform/pci/pmu/i2c/dimm-fru-prom?UnitAddress=0,aa - - -/* - * _fru_parent memory seeprom devices - */ -name:/platform/pci/pmu/i2c/dimm-fru-prom?UnitAddress=0,a8 -REFPROP _fru_parent name:/frutree/chassis/system-board/mem-slot?Label=DIMM0/mem-module - -name:/platform/pci/pmu/i2c/dimm-fru-prom?UnitAddress=0,aa -REFPROP _fru_parent name:/frutree/chassis/system-board/mem-slot?Label=DIMM1/mem-module - - -/* - * _fru_parent CPU, memory-controller devices - */ -_class:cpu?ID=0 -REFPROP _fru_parent /frutree/chassis/system-board/cpu-slot?Slot=0/cpu-module - -name:/platform/memory-controller?portid=0 -REFPROP _fru_parent /frutree/chassis/system-board/cpu-slot?Slot=0/cpu-module - - -/* - * _fru_parent motherboard & platform - */ -name:/platform/pci/isa/bscbus/i2c/motherboard-fru -REFPROP _fru_parent /frutree/chassis/system-board -name:/platform -REFPROP _fru_parent /frutree/chassis/system-board - -/* - * _fru_parent memory modules - */ -name:/platform/memory-controller/memory-module?ID=0 -REFPROP _fru_parent name:/frutree/chassis/system-board/mem-slot?Label=DIMM0/mem-module - -name:/platform/memory-controller/memory-module?ID=1 -REFPROP _fru_parent name:/frutree/chassis/system-board/mem-slot?Label=DIMM1/mem-module diff --git a/usr/src/cmd/picl/plugins/sun4u/grover/memcfg/Makefile b/usr/src/cmd/picl/plugins/sun4u/grover/memcfg/Makefile index 05a2a87f81..a1a6034e34 100644 --- a/usr/src/cmd/picl/plugins/sun4u/grover/memcfg/Makefile +++ b/usr/src/cmd/picl/plugins/sun4u/grover/memcfg/Makefile @@ -21,6 +21,7 @@ # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. +# Copyright 2019 Peter Tribble. # include $(SRC)/Makefile.psm @@ -57,19 +58,6 @@ LDLIBS += -L$(ROOT)/usr/lib/picl/plugins LDLIBS += -lc -lpicltree -lpicldevtree LDLIBS += -R/usr/platform/\$$PLATFORM/lib/picl/plugins:/usr/platform/sun4u/lib/picl/plugins:/usr/lib/picl/plugins - -LINKED_PLATFORMS = SUNW,Serverblade1 - -LINKED_DIRS = $(LINKED_PLATFORMS:%=$(USR_PLAT_DIR)/%) -LINKED_LIB_DIRS = $(LINKED_PLATFORMS:%=$(USR_PLAT_DIR)/%/lib) -LINKED_PICL_DIRS = $(LINKED_PLATFORMS:%=$(USR_PLAT_DIR)/%/lib/picl) -LINKED_PLUGIN_DIRS = $(LINKED_PLATFORMS:%=$(USR_PLAT_DIR)/%/lib/picl/plugins) - -LINKED_PLUGINS_DYNLIBS = $(LINKED_PLUGIN_DIRS:%=%/$(DYNLIB)) -LINKED_PLUGINS_LIBLINKS = $(LINKED_PLUGIN_DIRS:%=%/$(LIBLINKS)) - -GROVER_DYNLIB_DIR = ../../../../SUNW,Sun-Blade-100/lib/picl/plugins - PLATFORM= SUNW,Sun-Blade-100 .KEEP_STATE: @@ -87,9 +75,7 @@ POFILE= piclmemcfg.po all: $(LIBS) $(LIBLINKS) -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) \ - $(LINKED_PLUGIN_DIRS) $(LINKED_PLUGINS_DYNLIBS) \ - $(LINKED_PLUGINS_LIBLINKS) +install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) _msg: $(MSGDOMAIN) $(POFILE) $(RM) $(MSGDOMAIN)/$(POFILE) @@ -101,25 +87,6 @@ $(MSGDOMAIN): $(LIBLINKS): FRC $(RM) $@; $(SYMLINK) $(DYNLIB) $@ -# Linked platforms directory hierarchy -$(LINKED_DIRS): - $(INS.dir) -$(LINKED_LIB_DIRS): $(LINKED_DIRS) - $(INS.dir) -$(LINKED_PICL_DIRS): $(LINKED_LIB_DIRS) - $(INS.dir) -$(LINKED_PLUGIN_DIRS): $(LINKED_PICL_DIRS) - $(INS.dir) - -# Linked platforms links -$(LINKED_PLUGINS_DYNLIBS): $(LINKED_PLUGIN_DIRS) - $(RM) -r $@ ;\ - $(SYMLINK) $(GROVER_DYNLIB_DIR)/$(DYNLIB) $@ - -$(LINKED_PLUGINS_LIBLINKS): $(LINKED_PLUGIN_DIRS) - $(RM) -r $@ ;\ - $(SYMLINK) $(GROVER_DYNLIB_DIR)/$(DYNLIB) $@ - # include library targets include $(SRC)/cmd/picl/plugins/Makefile.targ include $(SRC)/lib/Makefile.targ |
