sysmon_envsysvar.h revision 1.44 1 /* $NetBSD: sysmon_envsysvar.h,v 1.44 2012/09/06 12:10:28 macallan Exp $ */
2
3 /*-
4 * Copyright (c) 2007, 2008 Juan Romero Pardines.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _DEV_SYSMON_ENVSYSVAR_H_
29 #define _DEV_SYSMON_ENVSYSVAR_H_
30
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/conf.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
36 #include <sys/mutex.h>
37 #include <sys/workqueue.h>
38 #include <sys/condvar.h>
39
40 #include <dev/sysmon/sysmonvar.h>
41 #include <prop/proplib.h>
42
43 #include "opt_envsys.h"
44
45 enum sme_descr_type {
46 SME_DESC_UNITS = 1,
47 SME_DESC_STATES,
48 SME_DESC_DRIVE_STATES,
49 SME_DESC_BATTERY_CAPACITY,
50 SME_DESC_INDICATOR
51 };
52
53 #ifdef ENVSYS_DEBUG
54 #define DPRINTF(x) printf x
55 #else
56 #define DPRINTF(x)
57 #endif
58
59 #ifdef ENVSYS_OBJECTS_DEBUG
60 #define DPRINTFOBJ(x) printf x
61 #else
62 #define DPRINTFOBJ(x)
63 #endif
64
65 /*
66 * Default timeout value for the callouts if no specified.
67 */
68 #define SME_EVENTS_DEFTIMEOUT 30
69
70 /*
71 * struct used by a sysmon envsys event.
72 */
73 typedef struct sme_event {
74 struct work see_wk;
75 LIST_ENTRY(sme_event) see_list;
76 struct sysmon_envsys *see_sme; /* device associated */
77 struct penvsys_state see_pes; /* our power envsys */
78 envsys_data_t *see_edata; /* our sensor data */
79 sysmon_envsys_lim_t see_lims; /* limit values */
80 int see_type; /* type of the event */
81 int see_evstate; /* state of prev event */
82 int see_evvalue; /* value of prev event */
83 int see_flags; /* see above */
84 #define SEE_EVENT_WORKING 0x0001 /* This event is busy */
85 } sme_event_t;
86
87 /*
88 * struct by a sysmon envsys event set by a driver.
89 */
90 typedef struct sme_event_drv {
91 struct sysmon_envsys *sed_sme;
92 prop_dictionary_t sed_sdict;
93 envsys_data_t *sed_edata;
94 int sed_powertype;
95 } sme_event_drv_t;
96
97 struct sme_descr_entry {
98 int type;
99 int crittype;
100 const char *desc;
101 };
102
103 /*
104 * common stuff.
105 */
106 extern kmutex_t sme_global_mtx; /* for the sme linked list and dict */
107 extern prop_dictionary_t sme_propd; /* the global sensor dictionary */
108
109 /*
110 * linked list for the sysmon envsys devices.
111 */
112 LIST_HEAD(sysmon_envsys_lh, sysmon_envsys);
113 extern struct sysmon_envsys_lh sysmon_envsys_list;
114
115 /*
116 * functions to handle sysmon envsys devices.
117 */
118 int sme_update_dictionary(struct sysmon_envsys *);
119 int sme_update_sensor_dictionary(prop_object_t, envsys_data_t *, bool);
120 int sme_userset_dictionary(struct sysmon_envsys *,
121 prop_dictionary_t, prop_array_t);
122 prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *);
123 struct sysmon_envsys *sysmon_envsys_find(const char *);
124 void sysmon_envsys_acquire(struct sysmon_envsys *, bool);
125 void sysmon_envsys_release(struct sysmon_envsys *, bool);
126
127 /*
128 * functions to handle sysmon envsys events.
129 */
130 int sme_event_register(prop_dictionary_t, envsys_data_t *,
131 struct sysmon_envsys *, sysmon_envsys_lim_t *,
132 uint32_t, int, int);
133 int sme_event_unregister(struct sysmon_envsys *, const char *, int);
134 int sme_event_unregister_sensor(struct sysmon_envsys *, envsys_data_t *);
135 void sme_event_unregister_all(struct sysmon_envsys *);
136 void sme_event_drvadd(void *);
137 int sme_events_init(struct sysmon_envsys *);
138 void sme_events_destroy(struct sysmon_envsys *);
139 void sme_events_check(void *);
140 void sme_events_worker(struct work *, void *);
141 void sme_deliver_event(sme_event_t *);
142 int sme_update_limits(struct sysmon_envsys *, envsys_data_t *);
143 void sme_schedule_callout(struct sysmon_envsys *);
144
145 /*
146 * common functions to create/update objects in a dictionary.
147 */
148 int sme_sensor_upbool(prop_dictionary_t, const char *, bool);
149 int sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
150 int sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
151 int sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
152
153 const struct sme_descr_entry *sme_find_table_entry(enum sme_descr_type, int);
154 const struct sme_descr_entry * sme_find_table_desc(enum sme_descr_type,
155 const char *);
156
157 #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
158