#ifndef _DEV_SYSMON_SYSMONVAR_H_
#define _DEV_SYSMON_SYSMONVAR_H_
#include <sys/param.h>
#include <sys/envsys.h>
#include <sys/wdog.h>
#include <sys/power.h>
#include <sys/queue.h>
#include <sys/callout.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/rndsource.h>
struct lwp;
struct proc;
struct knote;
struct uio;
struct workqueue;
#define SYSMON_MINOR_ENVSYS 0
#define SYSMON_MINOR_WDOG 1
#define SYSMON_MINOR_POWER 2
enum envsys_lims {
ENVSYS_LIM_CRITMAX,
ENVSYS_LIM_WARNMAX,
ENVSYS_LIM_WARNMIN,
ENVSYS_LIM_CRITMIN,
ENVSYS_LIM_LASTLIM
};
struct sysmon_envsys_lim {
int32_t critmax;
int32_t warnmax;
int32_t warnmin;
int32_t critmin;
};
typedef union {
int32_t sel_limit_list[ENVSYS_LIM_LASTLIM];
struct sysmon_envsys_lim sel_limits;
} sysmon_envsys_lim_t;
#define sel_critmax sel_limits.critmax
#define sel_warnmax sel_limits.warnmax
#define sel_warnmin sel_limits.warnmin
#define sel_critmin sel_limits.critmin
struct envsys_data {
TAILQ_ENTRY(envsys_data) sensors_head;
uint32_t sensor;
uint32_t units;
uint32_t state;
uint32_t flags;
uint32_t rpms;
int32_t rfact;
int32_t value_cur;
int32_t value_prev;
int32_t value_max;
int32_t value_min;
int32_t private;
sysmon_envsys_lim_t limits;
uint32_t upropset;
krndsource_t rnd_src;
char desc[ENVSYS_DESCLEN];
};
typedef struct envsys_data envsys_data_t;
#define ENVSYS_FPERCENT 0x00000001
#define ENVSYS_FVALID_MAX 0x00000002
#define ENVSYS_FVALID_MIN 0x00000004
#define ENVSYS_F_OBSOLETE 0x00000008
#define ENVSYS_FCHANGERFACT 0x00000010
#define ENVSYS_FMONCRITICAL 0x00000020
#define ENVSYS_FMONLIMITS 0x00000040
#define ENVSYS_FMONSTCHANGED 0x00000400
#define ENVSYS_FMONANY \
(ENVSYS_FMONCRITICAL | ENVSYS_FMONLIMITS | ENVSYS_FMONSTCHANGED)
#define ENVSYS_FMONNOTSUPP 0x00000800
#define ENVSYS_FNEED_REFRESH 0x00001000
#define ENVSYS_FHAS_ENTROPY 0x00002000
#define PROP_CRITMAX 0x0001
#define PROP_CRITMIN 0x0002
#define PROP_WARNMAX 0x0004
#define PROP_WARNMIN 0x0008
#define PROP_BATTCAP 0x0010
#define PROP_BATTWARN 0x0020
#define PROP_BATTHIGH 0x0040
#define PROP_BATTMAX 0x0080
#define PROP_DESC 0x0100
#define PROP_RFACT 0x0200
#define PROP_DRIVER_LIMITS 0x8000
#define PROP_CAP_LIMITS (PROP_BATTCAP | PROP_BATTWARN | \
PROP_BATTHIGH | PROP_BATTMAX)
#define PROP_VAL_LIMITS (PROP_CRITMAX | PROP_CRITMIN | \
PROP_WARNMAX | PROP_WARNMIN)
#define PROP_LIMITS (PROP_CAP_LIMITS | PROP_VAL_LIMITS)
struct sme_event;
struct sysmon_envsys {
const char *sme_name;
u_int sme_nsensors;
u_int sme_fsensor;
#define SME_SENSOR_IDX(sme, idx) ((idx) - (sme)->sme_fsensor)
int sme_class;
#define SME_CLASS_BATTERY 1
#define SME_CLASS_ACADAPTER 2
int sme_flags;
#define SME_FLAG_BUSY 0x00000001
#define SME_DISABLE_REFRESH 0x00000002
#define SME_INIT_REFRESH 0x00000008
#define SME_POLL_ONLY 0x00000010
void *sme_cookie;
void (*sme_refresh)(struct sysmon_envsys *, envsys_data_t *);
void (*sme_set_limits)(struct sysmon_envsys *, envsys_data_t *,
sysmon_envsys_lim_t *, uint32_t *);
void (*sme_get_limits)(struct sysmon_envsys *, envsys_data_t *,
sysmon_envsys_lim_t *, uint32_t *);
struct workqueue *sme_wq;
struct callout sme_callout;
int sme_callout_state;
#define SME_CALLOUT_INVALID 0x0
#define SME_CALLOUT_READY 0x1
#define SME_CALLOUT_HALTED 0x2
uint64_t sme_events_timeout;
LIST_ENTRY(sysmon_envsys) sme_list;
LIST_HEAD(, sme_event) sme_events_list;
TAILQ_HEAD(, envsys_data) sme_sensors_list;
int sme_busy;
kmutex_t sme_mtx;
kmutex_t sme_work_mtx;
kcondvar_t sme_condvar;
};
int sysmonopen_envsys(dev_t, int, int, struct lwp *);
int sysmonclose_envsys(dev_t, int, int, struct lwp *);
int sysmonioctl_envsys(dev_t, u_long, void *, int, struct lwp *);
struct sysmon_envsys *sysmon_envsys_create(void);
void sysmon_envsys_destroy(struct sysmon_envsys *);
int sysmon_envsys_register(struct sysmon_envsys *);
void sysmon_envsys_unregister(struct sysmon_envsys *);
int sysmon_envsys_sensor_attach(struct sysmon_envsys *, envsys_data_t *);
int sysmon_envsys_sensor_detach(struct sysmon_envsys *, envsys_data_t *);
uint32_t sysmon_envsys_get_max_value(bool (*)(const envsys_data_t*), bool);
void sysmon_envsys_sensor_event(struct sysmon_envsys *, envsys_data_t *,
int);
void sysmon_envsys_refresh_sensor(struct sysmon_envsys *, envsys_data_t *);
typedef bool (*sysmon_envsys_callback_t)(const struct sysmon_envsys *,
const envsys_data_t *, void*);
void sysmon_envsys_foreach_sensor(sysmon_envsys_callback_t, void *, bool);
int sysmon_envsys_update_limits(struct sysmon_envsys *, envsys_data_t *);
int sysmon_envsys_init(void);
int sysmon_envsys_fini(void);
struct sysmon_wdog {
const char *smw_name;
LIST_ENTRY(sysmon_wdog) smw_list;
void *smw_cookie;
int (*smw_setmode)(struct sysmon_wdog *);
int (*smw_tickle)(struct sysmon_wdog *);
u_int smw_period;
int smw_mode;
u_int smw_refcnt;
pid_t smw_tickler;
};
int sysmonopen_wdog(dev_t, int, int, struct lwp *);
int sysmonclose_wdog(dev_t, int, int, struct lwp *);
int sysmonioctl_wdog(dev_t, u_long, void *, int, struct lwp *);
int sysmon_wdog_setmode(struct sysmon_wdog *, int, u_int);
int sysmon_wdog_register(struct sysmon_wdog *);
int sysmon_wdog_unregister(struct sysmon_wdog *);
int sysmon_wdog_init(void);
int sysmon_wdog_fini(void);
struct sysmon_pswitch {
const char *smpsw_name;
int smpsw_type;
LIST_ENTRY(sysmon_pswitch) smpsw_list;
};
int sysmonopen_power(dev_t, int, int, struct lwp *);
int sysmonclose_power(dev_t, int, int, struct lwp *);
int sysmonread_power(dev_t, struct uio *, int);
int sysmonpoll_power(dev_t, int, struct lwp *);
int sysmonkqfilter_power(dev_t, struct knote *);
int sysmonioctl_power(dev_t, u_long, void *, int, struct lwp *);
void sysmon_power_settype(const char *);
int sysmon_pswitch_register(struct sysmon_pswitch *);
void sysmon_pswitch_unregister(struct sysmon_pswitch *);
void sysmon_pswitch_event(struct sysmon_pswitch *, int);
void sysmon_penvsys_event(struct penvsys_state *, int);
int sysmon_power_init(void);
int sysmon_power_fini(void);
struct sysmon_opvec {
int (*so_open)(dev_t, int, int, struct lwp*);
int (*so_close)(dev_t, int, int, struct lwp*);
int (*so_ioctl)(dev_t, u_long, void *, int, struct lwp*);
int (*so_read)(dev_t, struct uio*, int);
int (*so_poll)(dev_t, int, struct lwp*);
int (*so_filter)(dev_t, struct knote*);
};
int sysmon_init(void);
int sysmon_fini(void);
int sysmon_attach_minor(int, struct sysmon_opvec*);
#endif