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