/*
* 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-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains code for setting up environmental related nodes
* and properties in the PICL tree.
*
* For each temperature-device class node, it does the following:
* - Create cpu and cpu-ambient temperautre-sensor class nodes.
* - Create "devfs-path" property under each temperature-sensor class node
* - Create "Temperature" volatile property under these nodes.
* - Create various temperature threshold properties under each node.
* - Create "Temperature" and "AmbientTemperature" volatile properties
* under corresponding "cpu" class node.
*
* For the "fan-control" node, it does the following:
* - Create system-fan node
* - Create "devfs-path" property under "fan" class node
* - Create "Speed" volatile propery under each node.
* - Create "SpeedUnit" property under each node.
*
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <alloca.h>
#include <libintl.h>
#include <sys/systeminfo.h>
#include <picl.h>
#include <picltree.h>
#include <picld_pluginutil.h>
#include <pthread.h>
#include <sys/systeminfo.h>
#include "picldefs.h"
#include "envd.h"
/*
*/
/*
* PICL class path for CPU nodes
*/
/*
* "UnitAddress" propval for various temperature devices (platform dependent)
*/
/*
* Sensor node data structure
*/
typedef struct {
/*
* Sensor nodes array
*/
};
/*
* Fan node data structure
*/
typedef struct {
} fan_node_t;
/*
* Fan node array
*/
};
/*
* Miscellaneous declarations
*/
typedef struct node_list {
} node_list_t;
static void delete_sensor_nodes_and_props(void);
static void delete_fan_nodes_and_props(void);
/*
* Read function for volatile "Temperature" property
*/
static int
{
/*
* Locate the sensor in our sensor_nodes table by matching the
* property handle and get its temperature.
*/
(void) pthread_rwlock_rdlock(&envpicl_rwlock);
snodep++) {
continue;
break;
sizeof (sensorp->target_temp));
(void) pthread_rwlock_unlock(&envpicl_rwlock);
return (PICL_SUCCESS);
}
(void) pthread_rwlock_unlock(&envpicl_rwlock);
return (PICL_FAILURE);
}
/*
* Read function for volatile "Temperature" property
*/
static int
{
/*
* Locate the sensor in our sensor_nodes table by matching the
* property handle and get its temperature.
*/
(void) pthread_rwlock_rdlock(&envpicl_rwlock);
snodep++) {
continue;
break;
(void) pthread_rwlock_unlock(&envpicl_rwlock);
return (PICL_SUCCESS);
}
(void) pthread_rwlock_unlock(&envpicl_rwlock);
return (PICL_FAILURE);
}
/*
* Read function for volatile "Speed" property on "fan" class node
*/
static int
{
/*
* Locate the fan in our fan_nodes table by matching the
* property handle and get fan speed.
*/
(void) pthread_rwlock_rdlock(&envpicl_rwlock);
continue;
break;
(void) pthread_rwlock_unlock(&envpicl_rwlock);
return (PICL_SUCCESS);
}
(void) pthread_rwlock_unlock(&envpicl_rwlock);
return (PICL_FAILURE);
}
static node_list_t *
{
return (listp);
return (listp);
}
/*
* append to the end to preserve the order found
*/
return (listp);
}
/*
* Get a list of nodes of the specified classname under nodeh
* Once a node of the specified class is found, it's children are not
* searched.
*/
static node_list_t *
{
int err;
/*
* go through the children
*/
sizeof (picl_nodehdl_t));
while (err == PICL_SUCCESS) {
else
sizeof (picl_nodehdl_t));
}
return (listp);
}
/*
* Free memory allocated to build the specified node list.
*/
static void
{
}
}
/*
* Get PICL_PTYPE_CHARSTRING "UnitAddress" property
*/
static int
{
int err;
if (err == PICL_SUCCESS)
if (err != PICL_SUCCESS)
return (err);
return (PICL_FAILURE);
return (err);
}
/*
* Create and add the specified regular property
*/
static int
{
int err;
if (err != PICL_SUCCESS)
return (err);
return (err);
}
/*
* Create and add the specified volatile property
*/
static int
{
int err;
if (err != PICL_SUCCESS)
return (err);
return (err);
}
/*
* Add temperature threshold properties
*/
static void
{
sizeof (threshp->low_power_off),
sizeof (threshp->low_shutdown),
sizeof (threshp->low_warning),
sizeof (threshp->high_warning),
sizeof (threshp->high_shutdown),
sizeof (threshp->high_power_off),
}
/*
* Lookup "temperature-device" class nodes and create "temperature-sensor"
* class nodes and relevant properties under those nodes.
*
* For each entry in sensor_nodes[] array, do the following:
* - Create specified (cpu-die or cpu-ambient) "temperautre-sensor" class
* node.
* - Create "devfs-path" property under this node.
* - Create "Temperature" volatile property under this node.
* - Create various temperature threshold properties under this node.
* - Create specified ("Temperature" or "AmbientTemperature") volatile
* temperature property under specified sdev_node node.
*/
static int
{
int err;
return (PICL_FAILURE);
/*
* Get "reg" property. Skip if no "reg" property found.
*/
sizeof (unitaddr));
if (err != PICL_SUCCESS)
continue;
snodep++) {
/* Match "UnitAddress" property */
continue;
/*
* Skip if already initialized or no sensor info
*/
continue;
/*
* Create temperature-sensor node
*/
if (env_debug)
"Creating PICL sensor node '%s' err:%d\n",
if (err != PICL_SUCCESS)
break;
/* save node handle */
/*
* Add "devfs_path" property in child node
*/
if (err != PICL_SUCCESS)
break;
/*
* Now add volatile "temperature" volatile property
* in this "temperature-sensor" class node.
*/
if (err != PICL_SUCCESS)
break;
/* Save prop handle */
/*
* Add threshold related properties
*/
/*
* Add volatile "TargetTemperature" property
*/
sizeof (sensorp->target_temp),
if (err != PICL_SUCCESS)
break;
}
/*
* Finally create property in the sensed device
* (if one specified)
*/
continue;
if (err == PICL_SUCCESS) {
sizeof (tempr_t), get_current_temp,
}
if (err != PICL_SUCCESS)
break;
/* Save prop handle */
}
if (err != PICL_SUCCESS) {
if (env_debug)
nodename);
return (err);
}
}
return (PICL_SUCCESS);
}
/*
* Delete all sensor nodes and related properties created by the
* add_sensor_prop() for each sensor node in the PICL tree.
*/
static void
{
/*
* as well as the sensor node and all properties under it.
* Note that deleiing/destroying a node deletes/destroys
* all properties within that node.
*/
}
/* delete node and all properties under it */
}
}
}
/*
* Lookup "fan-control" class node and create "fan" class nodes and
* relevant properties under those nodes.
*
* For each entry in fan_nodes[] array, do the following:
* - Create specified "fan" class node.
* - Create "devfs-path" property under "fan" class node
* - Create "Speed" volatile propery under "fan" class node.
* - Create "SpeedUnit" property under "fan" class node.
*/
static int
{
int err;
return (PICL_FAILURE);
/*
* Add various fan nodes and properties
*/
err = PICL_SUCCESS;
/* Skip if already initialized or no fan info */
continue;
/*
* Create "fan" class node and save node handle
*/
PICL_CLASS_FAN, &cnodeh);
if (env_debug)
"Creating PICL fan node '%s' err:%d\n",
if (err != PICL_SUCCESS)
break;
/*
* Add "devfs_path" property in child node
*/
if (err != PICL_SUCCESS)
break;
/*
* Add "Speed" volatile property in this "fan"
* class node and save prop handle.
*/
if (err != PICL_SUCCESS)
break;
/*
* Add other "fan" class properties
*/
if (err != PICL_SUCCESS)
break;
}
if (err != PICL_SUCCESS) {
if (env_debug)
nodename);
return (err);
}
}
return (PICL_SUCCESS);
}
/*
* Delete all fan nodes and related properties created by the
* add_fan_props() for each fan node in the PICL tree.
*/
static void
{
/*
* Note that deleiing/destroying a node deletes/destroys
* all properties within that node.
*/
}
}
}
/*
* Find the ENVMODEL_CONF_FILE file.
*/
static int
{
return (0);
}
}
return (0);
}
}
return (0);
}
return (-1);
}
void
env_picl_destroy(void)
{
(void) pthread_rwlock_wrlock(&envpicl_rwlock);
(void) pthread_rwlock_unlock(&envpicl_rwlock);
}
void
env_picl_setup(void)
{
int err;
/*
* Initialize sensorp and other fields in the sensor_nodes[] array
*/
}
/*
* Initialize fanp and other fields in the fan_nodes[] array
*/
}
/*
* Get platform handle and populate PICL tree with environmental
* nodes and properties
*/
if (err == PICL_SUCCESS) {
(void) pthread_rwlock_wrlock(&envpicl_rwlock);
if (err == PICL_SUCCESS)
if (err != PICL_SUCCESS)
(void) pthread_rwlock_unlock(&envpicl_rwlock);
}
if (err != PICL_SUCCESS) {
return;
}
/*
* Parse the envmodel.conf file and populate the PICL tree
*/
if (get_envmodel_conf_file(fullfilename) < 0)
if (err != PICL_SUCCESS)
}