summaryrefslogtreecommitdiff
path: root/sys/dev/sysmon/sysmon_envsysvar.h
blob: 9a7e9de20bc952c586bd17125f8e5a4b64efb7b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* $NetBSD: sysmon_envsysvar.h,v 1.48 2021/12/31 11:05:41 riastradh Exp $ */

/*-
 * Copyright (c) 2007, 2008 Juan Romero Pardines.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _DEV_SYSMON_ENVSYSVAR_H_
#define _DEV_SYSMON_ENVSYSVAR_H_

#include <sys/param.h>
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/mutex.h>
#include <sys/workqueue.h>
#include <sys/condvar.h>

#include <dev/sysmon/sysmonvar.h>
#include <prop/proplib.h>

#ifdef _KERNEL_OPT
#include "opt_envsys.h"
#endif

enum sme_descr_type {
	SME_DESC_UNITS = 1,
	SME_DESC_STATES,
	SME_DESC_DRIVE_STATES,
	SME_DESC_BATTERY_CAPACITY,
	SME_DESC_INDICATOR
};

#ifdef ENVSYS_DEBUG
#define DPRINTF(x)	printf x
#else
#define DPRINTF(x)
#endif

#ifdef ENVSYS_OBJECTS_DEBUG
#define DPRINTFOBJ(x)	printf x
#else
#define DPRINTFOBJ(x)
#endif

/*
 * Default timeout value for the callouts if no specified.
 */
#define SME_EVENTS_DEFTIMEOUT	30

/*
 * struct used by a sysmon envsys event.
 */
typedef struct sme_event {
	struct work		see_wk;
	LIST_ENTRY(sme_event) 	see_list;
	struct sysmon_envsys	*see_sme;	/* device associated */
	struct penvsys_state	see_pes;	/* our power envsys */
	envsys_data_t		*see_edata;	/* our sensor data */
	int			see_type;	/* type of the event */
	int			see_evstate;	/* state of prev event */
	int			see_evvalue;	/* value of prev event */
	int 			see_flags;	/* see above */
#define SEE_EVENT_WORKING	0x0001 		/* This event is busy */
} sme_event_t;

/*
 * struct by a sysmon envsys event set by a driver.
 */
typedef struct sme_event_drv {
	struct sysmon_envsys	*sed_sme;
	prop_dictionary_t	sed_sdict;
	envsys_data_t		*sed_edata;
	int			sed_powertype;
} sme_event_drv_t;

struct sme_descr_entry {
	int 		type;
	int 		crittype;
	const char 	*desc;
};

/*
 * common stuff.
 */
extern	kmutex_t sme_global_mtx; 	/* for the sme linked list and dict */
extern	prop_dictionary_t sme_propd;	/* the global sensor dictionary */

/*
 * linked list for the sysmon envsys devices.
 */
LIST_HEAD(sysmon_envsys_lh, sysmon_envsys);
extern	struct sysmon_envsys_lh sysmon_envsys_list;

/*
 * functions to handle sysmon envsys devices.
 */
int	sme_update_dictionary(struct sysmon_envsys *);
int	sme_update_sensor_dictionary(prop_object_t, envsys_data_t *, bool);
int	sme_userset_dictionary(struct sysmon_envsys *,
			       prop_dictionary_t, prop_array_t);
prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *);
struct	sysmon_envsys *sysmon_envsys_find(const char *);
void	sysmon_envsys_acquire(struct sysmon_envsys *, bool);
void	sysmon_envsys_release(struct sysmon_envsys *, bool);

/*
 * functions to handle sysmon envsys events.
 */
int	sme_event_register(prop_dictionary_t, envsys_data_t *,
			   struct sysmon_envsys *, sysmon_envsys_lim_t *,
			   uint32_t, int, int);
int	sme_event_unregister(struct sysmon_envsys *, const char *, int);
int	sme_event_unregister_sensor(struct sysmon_envsys *, envsys_data_t *);
void	sme_event_unregister_all(struct sysmon_envsys *);
void	sme_event_drvadd(void *);
int	sme_events_init(struct sysmon_envsys *);
void	sme_events_destroy(struct sysmon_envsys *);
void	sme_events_halt_callout(struct sysmon_envsys *);
void	sme_events_check(void *);
void	sme_events_worker(struct work *, void *);
void	sme_deliver_event(sme_event_t *);
int	sme_update_limits(struct sysmon_envsys *, envsys_data_t *);
void	sme_schedule_callout(struct sysmon_envsys *);

/*
 * common functions to create/update objects in a dictionary.
 */
int	sme_sensor_upbool(prop_dictionary_t, const char *, bool);
int	sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
int	sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);

const struct sme_descr_entry *sme_find_table_entry(enum sme_descr_type, int);
const struct sme_descr_entry * sme_find_table_desc(enum sme_descr_type,
						   const char *);

#endif /* _DEV_SYSMON_ENVSYSVAR_H_ */