Home | History | Annotate | Line # | Download | only in sysmon
sysmon_envsysvar.h revision 1.24
      1 /* $NetBSD: sysmon_envsysvar.h,v 1.24 2007/11/16 08:00:16 xtraeme Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 Juan Romero Pardines.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef _DEV_SYSMON_ENVSYSVAR_H_
     29 #define _DEV_SYSMON_ENVSYSVAR_H_
     30 
     31 #include <sys/param.h>
     32 #include <sys/types.h>
     33 #include <sys/conf.h>
     34 #include <sys/kernel.h>
     35 #include <sys/systm.h>
     36 #include <sys/mutex.h>
     37 #include <sys/workqueue.h>
     38 #include <sys/condvar.h>
     39 
     40 #include <dev/sysmon/sysmonvar.h>
     41 #include <prop/proplib.h>
     42 
     43 enum sme_description_types {
     44 	SME_DESC_UNITS = 1,
     45 	SME_DESC_STATES,
     46 	SME_DESC_DRIVE_STATES,
     47 	SME_DESC_BATTERY_CAPACITY
     48 };
     49 
     50 #ifdef ENVSYS_DEBUG
     51 #define DPRINTF(x)	printf x
     52 #else
     53 #define DPRINTF(x)
     54 #endif
     55 
     56 #ifdef ENVSYS_OBJECTS_DEBUG
     57 #define DPRINTFOBJ(x)	printf x
     58 #else
     59 #define DPRINTFOBJ(x)
     60 #endif
     61 
     62 /*
     63  * Default timeout value for the callouts if no specified.
     64  */
     65 #define SME_EVENTS_DEFTIMEOUT	30
     66 
     67 /*
     68  * struct used by a sensor description in a sysmon envsys device.
     69  */
     70 struct sme_sensor_names {
     71 	SLIST_ENTRY(sme_sensor_names) sme_names;
     72 	int	assigned;
     73 	char	desc[ENVSYS_DESCLEN];
     74 };
     75 
     76 /*
     77  * struct used by a sysmon envsys event.
     78  */
     79 typedef struct sme_event {
     80 	struct work 		see_wk;
     81 	LIST_ENTRY(sme_event) 	see_list;
     82 	struct sysmon_envsys	*see_sme;	/* device associated */
     83 	struct penvsys_state	see_pes;	/* our power envsys */
     84 	envsys_data_t		*see_edata;	/* our sensor data */
     85 	int32_t			see_critval;	/* critical value set */
     86 	int			see_type;	/* type of the event */
     87 	int			see_evsent;	/* event already sent */
     88 	int 			see_flags;	/* see above */
     89 #define SME_EVENT_WORKING	0x0001 		/* This event is busy */
     90 #define SME_EVENT_REFRESHED	0x0002		/* sensor already refreshed */
     91 } sme_event_t;
     92 
     93 /*
     94  * struct by a sysmon envsys event set by a driver.
     95  */
     96 typedef struct sme_event_drv {
     97 	struct sysmon_envsys	*sed_sme;
     98 	prop_dictionary_t	sed_sdict;
     99 	envsys_data_t		*sed_edata;
    100 	int			sed_powertype;
    101 } sme_event_drv_t;
    102 
    103 struct sme_description_table {
    104 	int 		type;
    105 	int 		crittype;
    106 	const char 	*desc;
    107 };
    108 
    109 /*
    110  * common stuff.
    111  */
    112 extern	kmutex_t sme_mtx; 		/* mutex for devices/events */
    113 extern 	kmutex_t sme_events_mtx;	/* to init/destroy the events layer */
    114 extern	kmutex_t sme_callout_mtx;	/* for the callouts */
    115 extern 	kcondvar_t sme_cv;		/* to wait for devices/events working */
    116 extern	kcondvar_t sme_callout_cv;	/* to wait for the callout handler */
    117 
    118 /*
    119  * linked list for the sysmon envsys devices.
    120  */
    121 LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
    122 
    123 /*
    124  * linked list for the sysmon envsys events.
    125  */
    126 LIST_HEAD(, sme_event) sme_events_list;
    127 
    128 /*
    129  * functions to handle sysmon envsys devices.
    130  */
    131 sme_event_drv_t *sme_add_sensor_dictionary(struct sysmon_envsys *,
    132 					   prop_array_t,
    133 			    	  	   prop_dictionary_t,
    134 					   envsys_data_t *);
    135 int	sme_update_dictionary(struct sysmon_envsys *);
    136 int	sme_userset_dictionary(struct sysmon_envsys *,
    137 			       prop_dictionary_t, prop_array_t);
    138 prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *);
    139 struct	sysmon_envsys *sysmon_envsys_find(const char *);
    140 void	sysmon_envsys_acquire(struct sysmon_envsys *);
    141 void	sysmon_envsys_release(struct sysmon_envsys *);
    142 
    143 /*
    144  * functions to handle sysmon envsys events.
    145  */
    146 int	sme_event_register(prop_dictionary_t, envsys_data_t *,
    147 			   struct sysmon_envsys *, const char *,
    148 			   int32_t, int, int);
    149 int	sme_event_unregister(struct sysmon_envsys *, const char *, int);
    150 void	sme_event_unregister_all(struct sysmon_envsys *);
    151 void	sme_event_drvadd(void *);
    152 int	sme_events_init(struct sysmon_envsys *);
    153 void	sme_events_destroy(struct sysmon_envsys *);
    154 void	sme_events_check(void *);
    155 void	sme_events_worker(struct work *, void *);
    156 
    157 /*
    158  * common functions to create/update objects in a dictionary.
    159  */
    160 int	sme_sensor_upbool(prop_dictionary_t, const char *, bool);
    161 int	sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
    162 int	sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
    163 int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
    164 
    165 const struct	sme_description_table *sme_get_description_table(int);
    166 
    167 #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
    168