sysmon_envsysvar.h revision 1.12 1 /* $NetBSD: sysmon_envsysvar.h,v 1.12 2007/07/23 17:51:17 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 to protect the sysmon envsys data */
96 extern kmutex_t sme_list_mtx; /* mutex to protect the sysmon envsys list */
97 extern kmutex_t sme_event_mtx; /* mutex to protect the sme event data */
98
99 /* mutex to intialize/destroy the sysmon envsys events framework */
100 extern kmutex_t sme_event_init_mtx;
101
102 /* condition variable to wait for the worker thread to finish */
103 extern kcondvar_t sme_event_cv;
104
105 /* linked list for the sysmon envsys devices */
106 LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
107
108 /* linked list for the sysmon envsys events */
109 LIST_HEAD(, sme_event) sme_events_list;
110
111 /* functions to handle sysmon envsys devices */
112 int sysmon_envsys_createplist(struct sysmon_envsys *);
113 void sme_make_dictionary(struct sysmon_envsys *, prop_array_t,
114 envsys_data_t *);
115 int sme_update_dictionary(struct sysmon_envsys *);
116 int sme_userset_dictionary(struct sysmon_envsys *,
117 prop_dictionary_t, prop_array_t);
118
119 /* functions to handle sysmon envsys events */
120 int sme_event_register(struct sme_event *);
121 int sme_event_unregister(const char *, int);
122 void sme_event_unregister_all(struct sysmon_envsys *);
123 void sme_event_drvadd(void *);
124 int sme_event_add(prop_dictionary_t, envsys_data_t *,
125 const char *, const char *, int32_t, int, int);
126 int sme_events_init(void);
127 void sme_events_destroy(void);
128 void sme_events_check(void *);
129 void sme_events_worker(struct work *, void *);
130
131 /* common functions to create/update objects in a dictionary */
132 int sme_sensor_upbool(prop_dictionary_t, const char *, bool);
133 int sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
134 int sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
135 int sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
136
137 #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
138