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