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