Home | History | Annotate | Line # | Download | only in sysmon
sysmon_envsysvar.h revision 1.9
      1 /* $NetBSD: sysmon_envsysvar.h,v 1.9 2007/07/21 12:11:27 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_mtx;	/* mutex for the sysmon envsys devices */
     96 extern	kmutex_t sme_event_mtx;	/* mutex for the sysmon envsys events */
     97 extern	kmutex_t sme_event_init_mtx;	/* mutex to initialize/destroy see */
     98 extern	kcondvar_t sme_event_cv;
     99 
    100 /* linked list for the sysmon envsys devices */
    101 LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
    102 
    103 /* linked list for the sysmon envsys events */
    104 LIST_HEAD(, sme_event) sme_events_list;
    105 
    106 /* functions to handle sysmon envsys devices */
    107 int	sysmon_envsys_createplist(struct sysmon_envsys *);
    108 int	sme_make_dictionary(struct sysmon_envsys *, prop_array_t,
    109 			    envsys_data_t *);
    110 int	sme_update_dictionary(struct sysmon_envsys *);
    111 int	sme_userset_dictionary(struct sysmon_envsys *,
    112 			       prop_dictionary_t, prop_array_t);
    113 
    114 /* functions to handle sysmon envsys events */
    115 int	sme_event_register(struct sme_event *);
    116 int	sme_event_unregister(const char *, int);
    117 void	sme_event_drvadd(void *);
    118 int	sme_event_add(prop_dictionary_t, envsys_data_t *,
    119 		      const char *, const char *, int32_t, int, int);
    120 int	sme_events_init(void);
    121 void	sme_events_check(void *);
    122 void	sme_events_worker(struct work *, void *);
    123 
    124 /* common functions to create/update objects in a dictionary */
    125 int	sme_sensor_upbool(prop_dictionary_t, const char *, bool);
    126 int	sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
    127 int	sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
    128 int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
    129 
    130 #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
    131