sysmon_envsysvar.h revision 1.3.2.2 1 1.3.2.2 mjf /* $NetBSD: sysmon_envsysvar.h,v 1.3.2.2 2007/07/11 20:08:25 mjf Exp $ */
2 1.3.2.2 mjf
3 1.3.2.2 mjf /*-
4 1.3.2.2 mjf * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.3.2.2 mjf * All rights reserved.
6 1.3.2.2 mjf *
7 1.3.2.2 mjf * This code is derived from software contributed to The NetBSD Foundation
8 1.3.2.2 mjf * by Juan Romero Pardines.
9 1.3.2.2 mjf *
10 1.3.2.2 mjf * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 mjf * modification, are permitted provided that the following conditions
12 1.3.2.2 mjf * are met:
13 1.3.2.2 mjf * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 mjf * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 mjf * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 mjf * documentation and/or other materials provided with the distribution.
18 1.3.2.2 mjf * 3. All advertising materials mentioning features or use of this software
19 1.3.2.2 mjf * must display the following acknowledgement:
20 1.3.2.2 mjf * This product includes software developed by Juan Romero Pardines
21 1.3.2.2 mjf * for the NetBSD Foundation, Inc. and its contributors.
22 1.3.2.2 mjf * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.2.2 mjf * contributors may be used to endorse or promote products derived
24 1.3.2.2 mjf * from this software without specific prior written permission.
25 1.3.2.2 mjf *
26 1.3.2.2 mjf * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.2.2 mjf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.2.2 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.2.2 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.2.2 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.2.2 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.2.2 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.2.2 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.2.2 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.2.2 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.2.2 mjf * POSSIBILITY OF SUCH DAMAGE.
37 1.3.2.2 mjf */
38 1.3.2.2 mjf
39 1.3.2.2 mjf #ifndef _DEV_SYSMON_ENVSYSVAR_H_
40 1.3.2.2 mjf #define _DEV_SYSMON_ENVSYSVAR_H_
41 1.3.2.2 mjf
42 1.3.2.2 mjf #include <sys/param.h>
43 1.3.2.2 mjf #include <sys/types.h>
44 1.3.2.2 mjf #include <sys/conf.h>
45 1.3.2.2 mjf #include <sys/kernel.h>
46 1.3.2.2 mjf #include <sys/systm.h>
47 1.3.2.2 mjf #include <sys/mutex.h>
48 1.3.2.2 mjf #include <sys/workqueue.h>
49 1.3.2.2 mjf
50 1.3.2.2 mjf #include <dev/sysmon/sysmonvar.h>
51 1.3.2.2 mjf #include <prop/proplib.h>
52 1.3.2.2 mjf
53 1.3.2.2 mjf #ifdef ENVSYS_DEBUG
54 1.3.2.2 mjf #define DPRINTF(x) printf x
55 1.3.2.2 mjf #else
56 1.3.2.2 mjf #define DPRINTF(x)
57 1.3.2.2 mjf #endif
58 1.3.2.2 mjf
59 1.3.2.2 mjf #ifdef ENVSYS_OBJECTS_DEBUG
60 1.3.2.2 mjf #define DPRINTFOBJ(x) printf x
61 1.3.2.2 mjf #else
62 1.3.2.2 mjf #define DPRINTFOBJ(x)
63 1.3.2.2 mjf #endif
64 1.3.2.2 mjf
65 1.3.2.2 mjf /* convenience macros to avoid writing same code many times */
66 1.3.2.2 mjf #define SENSOR_OBJUPDATED(a, b) \
67 1.3.2.2 mjf do { \
68 1.3.2.2 mjf DPRINTFOBJ(("%s: obj (%s:%d) updated\n", __func__, (a), (b))); \
69 1.3.2.2 mjf } while (/* CONSTCOND */ 0)
70 1.3.2.2 mjf
71 1.3.2.2 mjf #define SENSOR_DICTSETFAILED(a, b) \
72 1.3.2.2 mjf do { \
73 1.3.2.2 mjf DPRINTF(("%s: dict_set (%s:%d) failed\n", __func__, (a), (b))); \
74 1.3.2.2 mjf } while (/* CONSTCOND */ 0)
75 1.3.2.2 mjf
76 1.3.2.2 mjf #define SENSOR_SETTYPE(a, b, c, d) \
77 1.3.2.2 mjf do { \
78 1.3.2.2 mjf if (!prop_dictionary_set_ ## d((a), (b), (c))) { \
79 1.3.2.2 mjf SENSOR_DICTSETFAILED((b), (c)); \
80 1.3.2.2 mjf if ((a)) \
81 1.3.2.2 mjf prop_object_release((a)); \
82 1.3.2.2 mjf goto out; \
83 1.3.2.2 mjf } \
84 1.3.2.2 mjf } while (/* CONSTCOND */ 0)
85 1.3.2.2 mjf
86 1.3.2.2 mjf #define SENSOR_SINT32(a, b, c) SENSOR_SETTYPE(a, b, c, int32)
87 1.3.2.2 mjf #define SENSOR_SUINT32(a, b, c) SENSOR_SETTYPE(a, b, c, uint32)
88 1.3.2.2 mjf #define SENSOR_SBOOL(a, b, c) SENSOR_SETTYPE(a, b, c, bool)
89 1.3.2.2 mjf #define SENSOR_SSTRING(a, b, c) \
90 1.3.2.2 mjf do { \
91 1.3.2.2 mjf if (!prop_dictionary_set_cstring_nocopy((a), (b), (c))) { \
92 1.3.2.2 mjf DPRINTF(("%s: set_cstring (%s) failed.\n", \
93 1.3.2.2 mjf __func__, (c))); \
94 1.3.2.2 mjf if ((a)) \
95 1.3.2.2 mjf prop_object_release((a)); \
96 1.3.2.2 mjf goto out; \
97 1.3.2.2 mjf } \
98 1.3.2.2 mjf } while (/* CONSTCOND */ 0)
99 1.3.2.2 mjf
100 1.3.2.2 mjf #define SENSOR_UPTYPE(a, b, c, d, e) \
101 1.3.2.2 mjf do { \
102 1.3.2.2 mjf obj = prop_dictionary_get((a), (b)); \
103 1.3.2.2 mjf if (!prop_number_equals_ ## e(obj, (c))) { \
104 1.3.2.2 mjf if (!prop_dictionary_set_ ## d((a), (b), (c))) { \
105 1.3.2.2 mjf SENSOR_DICTSETFAILED((b), (c)); \
106 1.3.2.2 mjf return EINVAL; \
107 1.3.2.2 mjf } \
108 1.3.2.2 mjf SENSOR_OBJUPDATED((b), (c)); \
109 1.3.2.2 mjf } \
110 1.3.2.2 mjf } while (/* CONSTCOND */ 0)
111 1.3.2.2 mjf
112 1.3.2.2 mjf #define SENSOR_UPINT32(a, b, c) \
113 1.3.2.2 mjf SENSOR_UPTYPE(a, b, c, int32, integer)
114 1.3.2.2 mjf #define SENSOR_UPUINT32(a, b, c) \
115 1.3.2.2 mjf SENSOR_UPTYPE(a, b, c, uint32, unsigned_integer)
116 1.3.2.2 mjf #define SENSOR_UPSTRING(a, b, c) \
117 1.3.2.2 mjf do { \
118 1.3.2.2 mjf obj = prop_dictionary_get((a), (b)); \
119 1.3.2.2 mjf if (obj == NULL) { \
120 1.3.2.2 mjf SENSOR_SSTRING((a), (b), (c)); \
121 1.3.2.2 mjf } else { \
122 1.3.2.2 mjf if (!prop_string_equals_cstring((obj), (c))) { \
123 1.3.2.2 mjf SENSOR_SSTRING((a), (b), (c)); \
124 1.3.2.2 mjf } \
125 1.3.2.2 mjf } \
126 1.3.2.2 mjf } while (/* CONSTCOND */ 0)
127 1.3.2.2 mjf
128 1.3.2.2 mjf /* struct used by a sysmon envsys event */
129 1.3.2.2 mjf typedef struct sme_event {
130 1.3.2.2 mjf /* to add works into our workqueue */
131 1.3.2.2 mjf union {
132 1.3.2.2 mjf struct work u_work;
133 1.3.2.2 mjf TAILQ_ENTRY(sme_event) u_q;
134 1.3.2.2 mjf } see_u;
135 1.3.2.2 mjf #define see_wk see_u.u_work
136 1.3.2.2 mjf #define see_q see_u.u_q
137 1.3.2.2 mjf LIST_ENTRY(sme_event) see_list;
138 1.3.2.2 mjf struct penvsys_state pes; /* our power envsys */
139 1.3.2.2 mjf int32_t critval; /* critical value set */
140 1.3.2.2 mjf int type; /* type of the event */
141 1.3.2.2 mjf int snum; /* sensor number */
142 1.3.2.2 mjf int evsent; /* event already sent */
143 1.3.2.2 mjf } sme_event_t;
144 1.3.2.2 mjf
145 1.3.2.2 mjf /* struct by a sysmon envsys event set by a driver */
146 1.3.2.2 mjf typedef struct sme_event_drv {
147 1.3.2.2 mjf struct sysmon_envsys *sme;
148 1.3.2.2 mjf prop_dictionary_t sdict;
149 1.3.2.2 mjf envsys_data_t *edata;
150 1.3.2.2 mjf int powertype;
151 1.3.2.2 mjf } sme_event_drv_t;
152 1.3.2.2 mjf
153 1.3.2.2 mjf /* common */
154 1.3.2.2 mjf extern kmutex_t sme_mtx; /* mutex for the sysmon envsys devices */
155 1.3.2.2 mjf extern kmutex_t sme_event_mtx; /* mutex for the sysmon envsys events */
156 1.3.2.2 mjf extern kmutex_t sme_event_init_mtx; /* mutex to initialize/destroy see */
157 1.3.2.2 mjf
158 1.3.2.2 mjf /* linked list for the sysmon envsys devices */
159 1.3.2.2 mjf LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
160 1.3.2.2 mjf
161 1.3.2.2 mjf /* linked list for the sysmon envsys events */
162 1.3.2.2 mjf LIST_HEAD(, sme_event) sme_events_list;
163 1.3.2.2 mjf
164 1.3.2.2 mjf /* functions to handle sysmon envsys devices */
165 1.3.2.2 mjf int sysmon_envsys_createplist(struct sysmon_envsys *);
166 1.3.2.2 mjf int sme_make_dictionary(struct sysmon_envsys *, prop_array_t,
167 1.3.2.2 mjf envsys_data_t *);
168 1.3.2.2 mjf int sme_update_dictionary(struct sysmon_envsys *);
169 1.3.2.2 mjf int sme_userset_dictionary(struct sysmon_envsys *,
170 1.3.2.2 mjf prop_dictionary_t, prop_array_t);
171 1.3.2.2 mjf
172 1.3.2.2 mjf /* functions to handle sysmon envsys events */
173 1.3.2.2 mjf int sme_event_register(struct sme_event *);
174 1.3.2.2 mjf int sme_event_unregister(const char *, int);
175 1.3.2.2 mjf void sme_event_drvadd(void *);
176 1.3.2.2 mjf int sme_event_add(prop_dictionary_t, envsys_data_t *,
177 1.3.2.2 mjf const char *, const char *, int32_t, int, int);
178 1.3.2.2 mjf int sme_events_init(void);
179 1.3.2.2 mjf void sme_events_check(void *);
180 1.3.2.2 mjf void sme_events_worker(struct work *, void *);
181 1.3.2.2 mjf
182 1.3.2.2 mjf #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
183