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