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