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