2007-07-20 14:40:07 +04:00
|
|
|
/* $NetBSD: sysmon_envsysvar.h,v 1.7 2007/07/20 10:40:08 xtraeme Exp $ */
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2007 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Juan Romero Pardines.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Juan Romero Pardines
|
|
|
|
* for the NetBSD Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _DEV_SYSMON_ENVSYSVAR_H_
|
|
|
|
#define _DEV_SYSMON_ENVSYSVAR_H_
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/workqueue.h>
|
|
|
|
|
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
|
|
|
#include <prop/proplib.h>
|
|
|
|
|
|
|
|
#ifdef ENVSYS_DEBUG
|
|
|
|
#define DPRINTF(x) printf x
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENVSYS_OBJECTS_DEBUG
|
|
|
|
#define DPRINTFOBJ(x) printf x
|
|
|
|
#else
|
|
|
|
#define DPRINTFOBJ(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* convenience macros to avoid writing same code many times */
|
|
|
|
#define SENSOR_OBJUPDATED(a, b) \
|
|
|
|
do { \
|
|
|
|
DPRINTFOBJ(("%s: obj (%s:%d) updated\n", __func__, (a), (b))); \
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
2007-07-20 14:40:07 +04:00
|
|
|
/*
|
|
|
|
* Functions to create objects in a dictionary if they do not exist, or
|
|
|
|
* for updating its value it value provided doesn't match with the value
|
|
|
|
* in dictionary.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
sme_sensor_upbool(prop_object_t obj, prop_dictionary_t dict,
|
|
|
|
const char *key, bool val)
|
|
|
|
{
|
|
|
|
KASSERT(dict != NULL);
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
2007-07-20 14:40:07 +04:00
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
|
|
if (obj) {
|
|
|
|
if (prop_bool_true(obj) != val) {
|
|
|
|
if (!prop_dictionary_set_bool(dict, key, val)) {
|
|
|
|
DPRINTF(("%s: (up) set_bool %s:%d\n",
|
|
|
|
__func__, key, val));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
SENSOR_OBJUPDATED(key, val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!prop_dictionary_set_bool(dict, key, val)) {
|
|
|
|
DPRINTF(("%s: (set) set_bool %s:%d\n",
|
|
|
|
__func__, key, val));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
2007-07-20 14:40:07 +04:00
|
|
|
return 0;
|
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
2007-07-20 14:40:07 +04:00
|
|
|
static inline int
|
|
|
|
sme_sensor_upint32(prop_object_t obj, prop_dictionary_t dict,
|
|
|
|
const char *key, int32_t val)
|
|
|
|
{
|
|
|
|
KASSERT(dict != NULL);
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
2007-07-20 14:40:07 +04:00
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
|
|
if (obj) {
|
|
|
|
if (!prop_number_equals_integer(obj, val)) {
|
|
|
|
if (!prop_dictionary_set_int32(dict, key, val)) {
|
|
|
|
DPRINTF(("%s: (up) set_int32 %s:%d\n",
|
|
|
|
__func__, key, val));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
SENSOR_OBJUPDATED(key, val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!prop_dictionary_set_int32(dict, key, val)) {
|
|
|
|
DPRINTF(("%s: (set) set_int32 %s:%d\n",
|
|
|
|
__func__, key, val));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
sme_sensor_upuint32(prop_object_t obj, prop_dictionary_t dict,
|
|
|
|
const char *key, uint32_t val)
|
|
|
|
{
|
|
|
|
KASSERT(dict != NULL);
|
|
|
|
|
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
|
|
if (obj) {
|
|
|
|
if (!prop_number_equals_unsigned_integer(obj, val)) {
|
|
|
|
if (!prop_dictionary_set_uint32(dict, key, val)) {
|
|
|
|
DPRINTF(("%s: (up) set_uint32 %s:%d\n",
|
|
|
|
__func__, key, val));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
SENSOR_OBJUPDATED(key, val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!prop_dictionary_set_uint32(dict, key, val)) {
|
|
|
|
DPRINTF(("%s: (set) set_uint32 %s:%d\n",
|
|
|
|
__func__, key, val));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
sme_sensor_upstring(prop_object_t obj, prop_dictionary_t dict,
|
|
|
|
const char *key, const char *str)
|
|
|
|
{
|
|
|
|
KASSERT(dict != NULL);
|
|
|
|
|
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
|
|
if (obj == NULL) {
|
|
|
|
if (!prop_dictionary_set_cstring_nocopy(dict, key, str)) {
|
|
|
|
DPRINTF(("%s: (up) set_cstring %s:%s\n",
|
|
|
|
__func__, key, str));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!prop_string_equals_cstring(obj, str)) {
|
|
|
|
if (!prop_dictionary_set_cstring_nocopy(dict,
|
|
|
|
key,
|
|
|
|
str)) {
|
|
|
|
DPRINTF(("%s: (set) set_cstring %s:%s\n",
|
|
|
|
__func__, key, str));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
|
|
|
/* struct used by a sysmon envsys event */
|
|
|
|
typedef struct sme_event {
|
|
|
|
/* to add works into our workqueue */
|
2007-07-19 04:28:47 +04:00
|
|
|
struct work see_wk;
|
|
|
|
LIST_ENTRY(sme_event) see_list;
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
struct penvsys_state pes; /* our power envsys */
|
|
|
|
int32_t critval; /* critical value set */
|
|
|
|
int type; /* type of the event */
|
|
|
|
int snum; /* sensor number */
|
|
|
|
int evsent; /* event already sent */
|
2007-07-19 00:31:41 +04:00
|
|
|
int see_flags; /* see above */
|
2007-07-19 04:28:47 +04:00
|
|
|
#define SME_EVENT_WORKING 0x0001 /* This event is busy */
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
} sme_event_t;
|
|
|
|
|
|
|
|
/* struct by a sysmon envsys event set by a driver */
|
|
|
|
typedef struct sme_event_drv {
|
|
|
|
struct sysmon_envsys *sme;
|
|
|
|
prop_dictionary_t sdict;
|
|
|
|
envsys_data_t *edata;
|
|
|
|
int powertype;
|
|
|
|
} sme_event_drv_t;
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
extern kmutex_t sme_mtx; /* mutex for the sysmon envsys devices */
|
|
|
|
extern kmutex_t sme_event_mtx; /* mutex for the sysmon envsys events */
|
|
|
|
extern kmutex_t sme_event_init_mtx; /* mutex to initialize/destroy see */
|
2007-07-19 00:31:41 +04:00
|
|
|
extern kcondvar_t sme_event_cv;
|
Imported envsys 2, a brief description of the new features:
(Part 1: API)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:36:39 +04:00
|
|
|
|
|
|
|
/* linked list for the sysmon envsys devices */
|
|
|
|
LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
|
|
|
|
|
|
|
|
/* linked list for the sysmon envsys events */
|
|
|
|
LIST_HEAD(, sme_event) sme_events_list;
|
|
|
|
|
|
|
|
/* functions to handle sysmon envsys devices */
|
|
|
|
int sysmon_envsys_createplist(struct sysmon_envsys *);
|
|
|
|
int sme_make_dictionary(struct sysmon_envsys *, prop_array_t,
|
|
|
|
envsys_data_t *);
|
|
|
|
int sme_update_dictionary(struct sysmon_envsys *);
|
|
|
|
int sme_userset_dictionary(struct sysmon_envsys *,
|
|
|
|
prop_dictionary_t, prop_array_t);
|
|
|
|
|
|
|
|
/* functions to handle sysmon envsys events */
|
|
|
|
int sme_event_register(struct sme_event *);
|
|
|
|
int sme_event_unregister(const char *, int);
|
|
|
|
void sme_event_drvadd(void *);
|
|
|
|
int sme_event_add(prop_dictionary_t, envsys_data_t *,
|
|
|
|
const char *, const char *, int32_t, int, int);
|
|
|
|
int sme_events_init(void);
|
|
|
|
void sme_events_check(void *);
|
|
|
|
void sme_events_worker(struct work *, void *);
|
|
|
|
|
|
|
|
#endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
|