/*
* 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
* 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) 1999-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* PICL plug-in that creates the FRU Hierarchy for the
* SUNW,Sun-Fire-280R (Littleneck) platform
*/
#include <stdio.h>
#include <string.h>
#include <libintl.h>
#include <syslog.h>
#include <picl.h>
#include <picltree.h>
#include <picldefs.h>
/*
* Plugin registration entry points
*/
static void picl_frutree_register(void);
static void picl_frutree_init(void);
static void picl_frutree_fini(void);
#pragma init(picl_frutree_register)
/*
* Log message texts
*/
/*
* ViewPoints property field used by SunMC
*/
/*
* Ref prop values
*/
/*
* List of all the FRU locations in the platform_frupath[] array, and
* location_label[] array
*/
#define CPU0 0
/*
* Local variables
*/
"SUNW_Sun-Fire-280R_frutree",
};
/*
* List of all the FRUs in the /platform tree with SEEPROMs
*/
static char *platform_frupath[] = {
NULL};
/*
* List of all the FRU slots in the frutree that can be hotplugged
*/
static char *frutree_power_supply[] = {
"/frutree/chassis/power-dist-board/power-supply-slot?Slot=0",
"/frutree/chassis/power-dist-board/power-supply-slot?Slot=1",
NULL};
/*
* List of Labels for FRU locations (uses the #define's from above)
*/
static char *location_label[] = {
"0",
"1",
"J0100",
"J0101",
"J0202",
"J0203",
"J0304",
"J0305",
"J0406",
"J0407",
NULL, /* power distribution board placeholder */
"0",
"1",
NULL};
/* PICL handle for the root node of the "frutree" */
static int do_cpus_init(picl_nodehdl_t);
static int do_mem_init(picl_nodehdl_t);
static int do_power_supplies_init(picl_nodehdl_t);
static int do_fcal_init(picl_nodehdl_t);
static int do_rscboard_init(picl_nodehdl_t);
static int add_slot_prop(picl_nodehdl_t, int);
static int add_label_prop(picl_nodehdl_t, char *);
static int add_void_fda_prop(picl_nodehdl_t);
static int add_viewpoints_prop(picl_nodehdl_t, char *);
static int add_all_nodes();
static int remove_all_nodes(picl_nodehdl_t);
static int add_hotplug_fru_device(void);
static int rem_hotplug_fru_device(void);
static int is_added_device(char *, char *);
static int is_removed_device(char *, char *);
static int add_power_supply(int);
static int remove_power_supply(int);
/*
* This function is executed as part of .init when the plugin is
* dlopen()ed
*/
void
{
(void) picld_plugin_register(&my_reg_info);
}
/*
* This function is the init entry point of the plugin.
* It initializes the /frutree tree
*/
void
{
int err;
err = add_all_nodes();
if (err != PICL_SUCCESS) {
(void) remove_all_nodes(frutreeh);
return;
}
/* Register the event handler routine */
}
/*
* This function is the fini entry point of the plugin
*/
void
picl_frutree_fini(void)
{
/* Unregister the event handler routine */
(void) remove_all_nodes(frutreeh);
}
/*
* This function is the event handler of this plug-in.
*
* It processes the following events:
*
* PICLEVENT_SYSEVENT_DEVICE_ADDED
* PICLEVENT_SYSEVENT_DEVICE_REMOVED
*/
/* ARGSUSED */
static void
void *cookie)
{
/* Check for and add any hotplugged device(s) */
(void) add_hotplug_fru_device();
/* Check for and remove any hotplugged device(s) */
(void) rem_hotplug_fru_device();
}
}
/* Initialize the FRU node for the system board */
static int
{
int err;
/* Create the node for the system board */
PICL_SUCCESS) {
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
return (PICL_SUCCESS);
}
/* Initializes the FRU nodes for the CPU modules */
static int
{
int i, err;
/* Create the node for the CPU slot */
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
/* If the CPU module exists, create a node for it */
PICL_SUCCESS) {
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
}
return (PICL_SUCCESS);
}
/* Initializes the FRU nodes for the memory modules */
static int
{
/* Create the node for the memory slot */
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
/* If the memory exists, create a node for it */
PICL_SUCCESS) {
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
}
return (PICL_SUCCESS);
}
/* Initializes the FRU nodes for the PDB and the power supplies */
static int
{
/* Create the node for the PDB (if it exists) */
PICL_SUCCESS) {
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
/* Create the node for the power supply slot */
"location", &powersloth);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
/* If the PS exists, create a node for it */
&tmph) == PICL_SUCCESS) {
"fru", &powermodh);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
}
}
return (PICL_SUCCESS);
}
/* Initializes the FRU nodes for the FCAL backplane */
static int
{
int err;
/* Create the node for the FCAL backplane (if it exists) */
PICL_SUCCESS) {
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
return (PICL_SUCCESS);
}
/* Initializes the FRU node for the RSC card */
static int
{
int err;
/* Create the node for the RSC board (if it exists) */
PICL_SUCCESS) {
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
return (PICL_SUCCESS);
}
/* Creates a "reference" property between two PICL nodes */
static int
{
int err;
return (PICL_FAILURE);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
return (PICL_SUCCESS);
}
/* Creates a "Slot" property for a given PICL node */
static int
{
int err;
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
return (PICL_SUCCESS);
}
/* Creates a "Label" property for a given PICL node */
static int
{
int err;
return (PICL_FAILURE);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
return (PICL_SUCCESS);
}
/* Creates a "FRUDataAvailable" void property for the given PICL node */
static int
{
int err;
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
return (PICL_SUCCESS);
}
/* Creates a "ViewPoints" property -- used for chassis */
static int
{
int err;
return (PICL_FAILURE);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
return (PICL_SUCCESS);
}
/* Creates and adds all of the frutree nodes */
static int
{
int err;
/* Get the root node of the PICL tree */
if (err != PICL_SUCCESS) {
return (err);
}
/* Create and add the root node of the FRU subtree */
if (err != PICL_SUCCESS) {
return (err);
}
/* Create and add the chassis node */
if (err != PICL_SUCCESS) {
return (err);
}
/* Add ViewPoints prop to chassis node */
if (err != PICL_SUCCESS)
return (err);
/* Initialize the FRU node for the system board */
if (err != PICL_SUCCESS) {
return (err);
}
/* Initialize the FRU nodes for the CPU modules */
if (err != PICL_SUCCESS) {
return (err);
}
/* Initialize the FRU nodes for the memory modules */
if (err != PICL_SUCCESS) {
return (err);
}
/* Initialize the FRU nodes for the PDB and the power supplies */
if (err != PICL_SUCCESS) {
return (err);
}
/* Initialize the FRU nodes for the FCAL backplane */
if (err != PICL_SUCCESS) {
return (err);
}
/* Initialize the FRU node for the RSC card */
if (err != PICL_SUCCESS) {
return (err);
}
return (PICL_SUCCESS);
}
/* Deletes and destroys all PICL nodes for which rooth is a ancestor */
static int
{
while (!done) {
sizeof (picl_nodehdl_t));
if (err != PICL_PROPNOTFOUND) {
(void) remove_all_nodes(chdh);
} else {
if (err != PICL_SUCCESS) {
return (err);
} else {
(void) ptree_destroy_node(rooth);
}
done = 1;
}
}
return (PICL_SUCCESS);
}
/*
* Searches the list of hotpluggable FRUs for this platform and adds the
* appropriate node(s) to the frutree
*/
static int
{
/* Check for hotplugged power supplies */
/* Compare the /platform tree to the frutree */
if (err != PICL_SUCCESS)
continue;
/* If they are different, then add a power supply */
if (err != PICL_SUCCESS)
continue;
}
return (PICL_SUCCESS);
}
/*
* Searches the list of hotpluggable FRUs for this platform and removes the
* appropriate node(s) from the frutree
*/
static int
{
/* Check for hotplugged power supplies */
/* Compare the /platform tree to the frutree */
if (err != PICL_SUCCESS)
continue;
/* If they are different, then remove a power supply */
if (err != PICL_SUCCESS)
continue;
}
return (PICL_SUCCESS);
}
/*
* Compare the /platform tree to the /frutree to determine if a
* new device has been added
*/
static int
{
int err;
/* Check for node in the /platform tree */
if (err != PICL_SUCCESS)
return (err);
/*
* The node is in /platform, so find the corresponding slot in
* the frutree
*/
if (err != PICL_SUCCESS)
return (err);
/*
* If the slot in the frutree has a child, then return
* PICL_FAILURE. This means that the /platform tree and
* the frutree are consistent and no action is necessary.
* Otherwise return PICL_SUCCESS to indicate that a node needs
* to be added to the frutree
*/
&frumodh, sizeof (picl_nodehdl_t));
if (err == PICL_SUCCESS)
return (PICL_FAILURE);
return (PICL_SUCCESS);
}
/*
* Compare the /platform tree to the /frutree to determine if a
* device has been removed
*/
static int
{
int err;
/* Check for node in /platform tree */
if (err == PICL_SUCCESS)
return (PICL_FAILURE);
/*
* The node is not in /platform, so find the corresponding slot in
* the frutree
*/
if (err != PICL_SUCCESS)
return (err);
/*
* If the slot in the frutree does not have a child, then return
* PICL_FAILURE. This means that the /platform tree and
* the frutree are consistent and no action is necessary.
* Otherwise return PICL_SUCCESS to indicate that the needs
* to be removed from the frutree
*/
&frumodh, sizeof (picl_nodehdl_t));
if (err != PICL_SUCCESS)
return (PICL_FAILURE);
return (PICL_SUCCESS);
}
/* Hotplug routine used to add a new power supply */
static int
{
int i, err;
/* Find the node for the given power supply slot */
&powersloth) == PICL_SUCCESS) {
/* Make sure it's in /platform and create the frutree node */
PICL_SUCCESS) {
&powermodh);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
if (err != PICL_SUCCESS)
return (err);
}
}
return (PICL_SUCCESS);
}
/* Hotplug routine used to remove an existing power supply */
static int
{
int err;
/* Find the node for the given power supply slot */
&powersloth) == PICL_SUCCESS) {
/* Make sure it's got a child, then delete it */
&powermodh, sizeof (picl_nodehdl_t));
if (err != PICL_SUCCESS) {
return (err);
}
if (err != PICL_SUCCESS) {
return (err);
} else {
(void) ptree_destroy_node(powermodh);
}
}
return (PICL_SUCCESS);
}