Home | History | Annotate | Line # | Download | only in sysmon
sysmon_envsysvar.h revision 1.18
      1 /* $NetBSD: sysmon_envsysvar.h,v 1.18 2007/09/08 03:17:38 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 enum sme_description_types {
     55 	SME_DESC_UNITS = 1,
     56 	SME_DESC_STATES,
     57 	SME_DESC_DRIVE_STATES,
     58 	SME_DESC_BATTERY_STATES
     59 };
     60 
     61 #ifdef ENVSYS_DEBUG
     62 #define DPRINTF(x)	printf x
     63 #else
     64 #define DPRINTF(x)
     65 #endif
     66 
     67 #ifdef ENVSYS_OBJECTS_DEBUG
     68 #define DPRINTFOBJ(x)	printf x
     69 #else
     70 #define DPRINTFOBJ(x)
     71 #endif
     72 
     73 /* convenience macros to avoid writing same code many times */
     74 #define SENSOR_OBJUPDATED(a, b)						\
     75 do {									\
     76 	DPRINTFOBJ(("%s: obj (%s:%d) updated\n", __func__, (a), (b)));	\
     77 } while (/* CONSTCOND */ 0)
     78 
     79 /* struct used by a sysmon envsys event */
     80 typedef struct sme_event {
     81 	/* to add works into our workqueue */
     82 	struct work 		see_wk;
     83 	LIST_ENTRY(sme_event) 	see_list;
     84 	struct penvsys_state	pes;		/* our power envsys */
     85 	int32_t			critval;	/* critical value set */
     86 	int			type;		/* type of the event */
     87 	int			snum;		/* sensor number */
     88 	int			evsent;		/* event already sent */
     89 	int 			see_flags;	/* see above */
     90 #define SME_EVENT_WORKING	0x0001 		/* This event is busy */
     91 } sme_event_t;
     92 
     93 /* struct by a sysmon envsys event set by a driver */
     94 typedef struct sme_event_drv {
     95 	struct sysmon_envsys	*sme;
     96 	prop_dictionary_t	sdict;
     97 	envsys_data_t		*edata;
     98 	int			powertype;
     99 } sme_event_drv_t;
    100 
    101 struct sme_description_table {
    102 	int 		type;
    103 	int 		crittype;
    104 	const char 	*desc;
    105 };
    106 
    107 /* common */
    108 extern	kmutex_t sme_mtx;	/* mutex for the sysmon envsys devices/events */
    109 
    110 /* mutex to intialize/destroy the sysmon envsys events framework */
    111 extern kmutex_t sme_event_init_mtx;
    112 
    113 /* condition variable to wait for the worker thread to finish */
    114 extern	kcondvar_t sme_event_cv;
    115 
    116 /* linked list for the sysmon envsys devices */
    117 LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
    118 
    119 /* linked list for the sysmon envsys events */
    120 LIST_HEAD(, sme_event) sme_events_list;
    121 
    122 /* functions to handle sysmon envsys devices */
    123 sme_event_drv_t *sme_add_sensor_dictionary(struct sysmon_envsys *,
    124 					   prop_array_t,
    125 			    	  	   prop_dictionary_t,
    126 					   envsys_data_t *);
    127 int	sme_update_dictionary(struct sysmon_envsys *);
    128 int	sme_userset_dictionary(struct sysmon_envsys *,
    129 			       prop_dictionary_t, prop_array_t);
    130 
    131 /* functions to handle sysmon envsys events */
    132 int	sme_event_register(prop_dictionary_t, envsys_data_t *, const char *,
    133 			   const char *, int32_t, int, int);
    134 int	sme_event_unregister(const char *, int);
    135 void	sme_event_unregister_all(const char *);
    136 void	sme_event_drvadd(void *);
    137 int	sme_events_init(void);
    138 void	sme_events_destroy(void);
    139 void	sme_events_check(void *);
    140 void	sme_events_worker(struct work *, void *);
    141 
    142 /* common functions to create/update objects in a dictionary */
    143 int	sme_sensor_upbool(prop_dictionary_t, const char *, bool);
    144 int	sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
    145 int	sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
    146 int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
    147 
    148 const struct	sme_description_table *sme_get_description_table(int);
    149 
    150 #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
    151