| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $ */ | | 1 | /* $NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007, 2008 Juan Romero Pardines. | | 4 | * Copyright (c) 2007, 2008 Juan Romero Pardines. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 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 | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 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 | | 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. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | /* | | 28 | /* |
29 | * sysmon_envsys(9) events framework. | | 29 | * sysmon_envsys(9) events framework. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $"); |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/types.h> | | 36 | #include <sys/types.h> |
37 | #include <sys/conf.h> | | 37 | #include <sys/conf.h> |
38 | #include <sys/errno.h> | | 38 | #include <sys/errno.h> |
39 | #include <sys/kernel.h> | | 39 | #include <sys/kernel.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/proc.h> | | 41 | #include <sys/proc.h> |
42 | #include <sys/mutex.h> | | 42 | #include <sys/mutex.h> |
43 | #include <sys/kmem.h> | | 43 | #include <sys/kmem.h> |
44 | #include <sys/callout.h> | | 44 | #include <sys/callout.h> |
45 | | | 45 | |
46 | /* #define ENVSYS_DEBUG */ | | 46 | /* #define ENVSYS_DEBUG */ |
| @@ -91,44 +91,47 @@ sme_event_register(prop_dictionary_t sdi | | | @@ -91,44 +91,47 @@ sme_event_register(prop_dictionary_t sdi |
91 | sme_event_t *see = NULL, *osee = NULL; | | 91 | sme_event_t *see = NULL, *osee = NULL; |
92 | prop_object_t obj; | | 92 | prop_object_t obj; |
93 | int error = 0; | | 93 | int error = 0; |
94 | const char *objkey; | | 94 | const char *objkey; |
95 | | | 95 | |
96 | KASSERT(sdict != NULL); | | 96 | KASSERT(sdict != NULL); |
97 | KASSERT(edata != NULL); | | 97 | KASSERT(edata != NULL); |
98 | KASSERT(sme != NULL); | | 98 | KASSERT(sme != NULL); |
99 | KASSERT(lims != NULL); | | 99 | KASSERT(lims != NULL); |
100 | | | 100 | |
101 | /* | | 101 | /* |
102 | * Some validation first for limit-checking events | | 102 | * Some validation first for limit-checking events |
103 | * | | 103 | * |
104 | * 1. Limits are not permitted if the units is ENVSYS_INDICATOR. | | 104 | * 1. Limits are not permitted if the units is ENVSYS_INDICATOR |
| | | 105 | * or ENVSYS_BATTERY_CHARGE. |
105 | * | | 106 | * |
106 | * 2. Capacity limits are permitted only if the sensor has the | | 107 | * 2. Capacity limits are permitted only if the sensor has the |
107 | * ENVSYS_FPERCENT flag set and value_max is set. | | 108 | * ENVSYS_FPERCENT flag set and value_max is set. |
108 | * | | 109 | * |
109 | * 3. It is not permissible for both capacity and value limits | | 110 | * 3. It is not permissible for both capacity and value limits |
110 | * to coexist. | | 111 | * to coexist. |
111 | * | | 112 | * |
112 | * Note that it permissible for a sensor to have value limits | | 113 | * Note that it permissible for a sensor to have value limits |
113 | * even if its ENVSYS_FPERCENT flag and value_max are set. | | 114 | * even if its ENVSYS_FPERCENT flag and value_max are set. |
114 | */ | | 115 | */ |
115 | | | 116 | |
116 | DPRINTF(("%s: units %d props 0x%04x upropset 0x%04x max_val %d" | | 117 | DPRINTF(("%s: units %d props 0x%04x upropset 0x%04x max_val %d" |
117 | " edata-flags 0x%04x\n", __func__, edata->units, props, | | 118 | " edata-flags 0x%04x\n", __func__, edata->units, props, |
118 | edata->upropset, edata->value_max, edata->flags)); | | 119 | edata->upropset, edata->value_max, edata->flags)); |
119 | | | 120 | |
120 | if (props && edata->units == ENVSYS_INDICATOR) | | 121 | if (props) |
121 | return ENOTSUP; | | 122 | if (edata->units == ENVSYS_INDICATOR || |
| | | 123 | edata->units == ENVSYS_BATTERY_CHARGE) |
| | | 124 | return ENOTSUP; |
122 | | | 125 | |
123 | if ((props & PROP_CAP_LIMITS) && | | 126 | if ((props & PROP_CAP_LIMITS) && |
124 | ((edata->value_max == 0) || | | 127 | ((edata->value_max == 0) || |
125 | !(edata->flags & ENVSYS_FPERCENT) || | | 128 | !(edata->flags & ENVSYS_FPERCENT) || |
126 | (props & PROP_VAL_LIMITS) || | | 129 | (props & PROP_VAL_LIMITS) || |
127 | (edata->upropset & PROP_VAL_LIMITS))) | | 130 | (edata->upropset & PROP_VAL_LIMITS))) |
128 | props = 0; | | 131 | props = 0; |
129 | | | 132 | |
130 | if ((props & PROP_VAL_LIMITS) && (edata->upropset & PROP_CAP_LIMITS)) | | 133 | if ((props & PROP_VAL_LIMITS) && (edata->upropset & PROP_CAP_LIMITS)) |
131 | props = 0; | | 134 | props = 0; |
132 | | | 135 | |
133 | /* | | 136 | /* |
134 | * check if the event is already on the list and return | | 137 | * check if the event is already on the list and return |