Home | History | Annotate | Line # | Download | only in sysmon
sysmon_envsysvar.h revision 1.3.4.4
      1  1.3.4.4  ad /* $NetBSD: sysmon_envsysvar.h,v 1.3.4.4 2007/10/09 13:42:06 ad Exp $ */
      2  1.3.4.2  ad 
      3  1.3.4.2  ad /*-
      4  1.3.4.4  ad  * Copyright (c) 2007 Juan Romero Pardines.
      5  1.3.4.2  ad  * All rights reserved.
      6  1.3.4.2  ad  *
      7  1.3.4.2  ad  * Redistribution and use in source and binary forms, with or without
      8  1.3.4.2  ad  * modification, are permitted provided that the following conditions
      9  1.3.4.2  ad  * are met:
     10  1.3.4.2  ad  * 1. Redistributions of source code must retain the above copyright
     11  1.3.4.2  ad  *    notice, this list of conditions and the following disclaimer.
     12  1.3.4.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.3.4.2  ad  *    notice, this list of conditions and the following disclaimer in the
     14  1.3.4.2  ad  *    documentation and/or other materials provided with the distribution.
     15  1.3.4.2  ad  *
     16  1.3.4.4  ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.3.4.4  ad  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.3.4.4  ad  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.3.4.4  ad  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.3.4.4  ad  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.3.4.4  ad  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.3.4.4  ad  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.3.4.4  ad  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.3.4.4  ad  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.3.4.4  ad  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.3.4.2  ad  */
     27  1.3.4.2  ad 
     28  1.3.4.2  ad #ifndef _DEV_SYSMON_ENVSYSVAR_H_
     29  1.3.4.2  ad #define _DEV_SYSMON_ENVSYSVAR_H_
     30  1.3.4.2  ad 
     31  1.3.4.2  ad #include <sys/param.h>
     32  1.3.4.2  ad #include <sys/types.h>
     33  1.3.4.2  ad #include <sys/conf.h>
     34  1.3.4.2  ad #include <sys/kernel.h>
     35  1.3.4.2  ad #include <sys/systm.h>
     36  1.3.4.2  ad #include <sys/mutex.h>
     37  1.3.4.2  ad #include <sys/workqueue.h>
     38  1.3.4.3  ad #include <sys/condvar.h>
     39  1.3.4.2  ad 
     40  1.3.4.2  ad #include <dev/sysmon/sysmonvar.h>
     41  1.3.4.2  ad #include <prop/proplib.h>
     42  1.3.4.2  ad 
     43  1.3.4.4  ad enum sme_description_types {
     44  1.3.4.4  ad 	SME_DESC_UNITS = 1,
     45  1.3.4.4  ad 	SME_DESC_STATES,
     46  1.3.4.4  ad 	SME_DESC_DRIVE_STATES,
     47  1.3.4.4  ad 	SME_DESC_BATTERY_STATES
     48  1.3.4.4  ad };
     49  1.3.4.4  ad 
     50  1.3.4.2  ad #ifdef ENVSYS_DEBUG
     51  1.3.4.2  ad #define DPRINTF(x)	printf x
     52  1.3.4.2  ad #else
     53  1.3.4.2  ad #define DPRINTF(x)
     54  1.3.4.2  ad #endif
     55  1.3.4.2  ad 
     56  1.3.4.2  ad #ifdef ENVSYS_OBJECTS_DEBUG
     57  1.3.4.2  ad #define DPRINTFOBJ(x)	printf x
     58  1.3.4.2  ad #else
     59  1.3.4.2  ad #define DPRINTFOBJ(x)
     60  1.3.4.2  ad #endif
     61  1.3.4.2  ad 
     62  1.3.4.2  ad /* convenience macros to avoid writing same code many times */
     63  1.3.4.2  ad #define SENSOR_OBJUPDATED(a, b)						\
     64  1.3.4.2  ad do {									\
     65  1.3.4.2  ad 	DPRINTFOBJ(("%s: obj (%s:%d) updated\n", __func__, (a), (b)));	\
     66  1.3.4.2  ad } while (/* CONSTCOND */ 0)
     67  1.3.4.2  ad 
     68  1.3.4.2  ad /* struct used by a sysmon envsys event */
     69  1.3.4.2  ad typedef struct sme_event {
     70  1.3.4.2  ad 	/* to add works into our workqueue */
     71  1.3.4.3  ad 	struct work 		see_wk;
     72  1.3.4.3  ad 	LIST_ENTRY(sme_event) 	see_list;
     73  1.3.4.2  ad 	struct penvsys_state	pes;		/* our power envsys */
     74  1.3.4.2  ad 	int32_t			critval;	/* critical value set */
     75  1.3.4.2  ad 	int			type;		/* type of the event */
     76  1.3.4.2  ad 	int			snum;		/* sensor number */
     77  1.3.4.2  ad 	int			evsent;		/* event already sent */
     78  1.3.4.3  ad 	int 			see_flags;	/* see above */
     79  1.3.4.3  ad #define SME_EVENT_WORKING	0x0001 		/* This event is busy */
     80  1.3.4.2  ad } sme_event_t;
     81  1.3.4.2  ad 
     82  1.3.4.2  ad /* struct by a sysmon envsys event set by a driver */
     83  1.3.4.2  ad typedef struct sme_event_drv {
     84  1.3.4.2  ad 	struct sysmon_envsys	*sme;
     85  1.3.4.2  ad 	prop_dictionary_t	sdict;
     86  1.3.4.2  ad 	envsys_data_t		*edata;
     87  1.3.4.2  ad 	int			powertype;
     88  1.3.4.2  ad } sme_event_drv_t;
     89  1.3.4.2  ad 
     90  1.3.4.4  ad struct sme_description_table {
     91  1.3.4.4  ad 	int 		type;
     92  1.3.4.4  ad 	int 		crittype;
     93  1.3.4.4  ad 	const char 	*desc;
     94  1.3.4.4  ad };
     95  1.3.4.3  ad 
     96  1.3.4.4  ad /* common */
     97  1.3.4.4  ad extern	kmutex_t sme_mtx; 		/* mutex for devices/events */
     98  1.3.4.4  ad extern 	kmutex_t sme_event_init_mtx;	/* init/destroy the events framework */
     99  1.3.4.4  ad extern 	kcondvar_t sme_cv;		/* to wait for devices/events working */
    100  1.3.4.2  ad 
    101  1.3.4.2  ad /* linked list for the sysmon envsys devices */
    102  1.3.4.2  ad LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
    103  1.3.4.2  ad 
    104  1.3.4.2  ad /* linked list for the sysmon envsys events */
    105  1.3.4.2  ad LIST_HEAD(, sme_event) sme_events_list;
    106  1.3.4.2  ad 
    107  1.3.4.2  ad /* functions to handle sysmon envsys devices */
    108  1.3.4.4  ad sme_event_drv_t *sme_add_sensor_dictionary(struct sysmon_envsys *,
    109  1.3.4.4  ad 					   prop_array_t,
    110  1.3.4.4  ad 			    	  	   prop_dictionary_t,
    111  1.3.4.4  ad 					   envsys_data_t *);
    112  1.3.4.2  ad int	sme_update_dictionary(struct sysmon_envsys *);
    113  1.3.4.2  ad int	sme_userset_dictionary(struct sysmon_envsys *,
    114  1.3.4.2  ad 			       prop_dictionary_t, prop_array_t);
    115  1.3.4.4  ad prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *);
    116  1.3.4.2  ad 
    117  1.3.4.2  ad /* functions to handle sysmon envsys events */
    118  1.3.4.4  ad int	sme_event_register(prop_dictionary_t, envsys_data_t *, const char *,
    119  1.3.4.4  ad 			   const char *, int32_t, int, int);
    120  1.3.4.2  ad int	sme_event_unregister(const char *, int);
    121  1.3.4.4  ad void	sme_event_unregister_all(const char *);
    122  1.3.4.2  ad void	sme_event_drvadd(void *);
    123  1.3.4.2  ad int	sme_events_init(void);
    124  1.3.4.3  ad void	sme_events_destroy(void);
    125  1.3.4.2  ad void	sme_events_check(void *);
    126  1.3.4.2  ad void	sme_events_worker(struct work *, void *);
    127  1.3.4.2  ad 
    128  1.3.4.3  ad /* common functions to create/update objects in a dictionary */
    129  1.3.4.3  ad int	sme_sensor_upbool(prop_dictionary_t, const char *, bool);
    130  1.3.4.3  ad int	sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
    131  1.3.4.3  ad int	sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
    132  1.3.4.3  ad int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
    133  1.3.4.3  ad 
    134  1.3.4.4  ad const struct	sme_description_table *sme_get_description_table(int);
    135  1.3.4.4  ad 
    136  1.3.4.2  ad #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
    137