| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sysmon_envsys.c,v 1.144 2019/03/26 15:50:23 bad Exp $ */ | | 1 | /* $NetBSD: sysmon_envsys.c,v 1.144.4.1 2020/06/07 16:40:00 martin 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. |
| @@ -54,27 +54,27 @@ | | | @@ -54,27 +54,27 @@ |
54 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 54 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
55 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 55 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
56 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 56 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
57 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 57 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
58 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 58 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
59 | */ | | 59 | */ |
60 | | | 60 | |
61 | /* | | 61 | /* |
62 | * Environmental sensor framework for sysmon, exported to userland | | 62 | * Environmental sensor framework for sysmon, exported to userland |
63 | * with proplib(3). | | 63 | * with proplib(3). |
64 | */ | | 64 | */ |
65 | | | 65 | |
66 | #include <sys/cdefs.h> | | 66 | #include <sys/cdefs.h> |
67 | __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.144 2019/03/26 15:50:23 bad Exp $"); | | 67 | __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.144.4.1 2020/06/07 16:40:00 martin Exp $"); |
68 | | | 68 | |
69 | #include <sys/param.h> | | 69 | #include <sys/param.h> |
70 | #include <sys/types.h> | | 70 | #include <sys/types.h> |
71 | #include <sys/conf.h> | | 71 | #include <sys/conf.h> |
72 | #include <sys/errno.h> | | 72 | #include <sys/errno.h> |
73 | #include <sys/fcntl.h> | | 73 | #include <sys/fcntl.h> |
74 | #include <sys/kernel.h> | | 74 | #include <sys/kernel.h> |
75 | #include <sys/systm.h> | | 75 | #include <sys/systm.h> |
76 | #include <sys/proc.h> | | 76 | #include <sys/proc.h> |
77 | #include <sys/mutex.h> | | 77 | #include <sys/mutex.h> |
78 | #include <sys/kmem.h> | | 78 | #include <sys/kmem.h> |
79 | #include <sys/rndsource.h> | | 79 | #include <sys/rndsource.h> |
80 | #include <sys/module.h> | | 80 | #include <sys/module.h> |
| @@ -814,36 +814,26 @@ sysmon_envsys_register(struct sysmon_env | | | @@ -814,36 +814,26 @@ sysmon_envsys_register(struct sysmon_env |
814 | sysmon_envsys_next_sensor_index += sme->sme_nsensors; | | 814 | sysmon_envsys_next_sensor_index += sme->sme_nsensors; |
815 | mutex_exit(&sme_global_mtx); | | 815 | mutex_exit(&sme_global_mtx); |
816 | | | 816 | |
817 | out: | | 817 | out: |
818 | /* | | 818 | /* |
819 | * No errors? Make an initial data refresh if was requested, | | 819 | * No errors? Make an initial data refresh if was requested, |
820 | * then register the events that were set in the driver. Do | | 820 | * then register the events that were set in the driver. Do |
821 | * the refresh first in case it is needed to establish the | | 821 | * the refresh first in case it is needed to establish the |
822 | * limits or max_value needed by some events. | | 822 | * limits or max_value needed by some events. |
823 | */ | | 823 | */ |
824 | if (error == 0) { | | 824 | if (error == 0) { |
825 | nevent = 0; | | 825 | nevent = 0; |
826 | | | 826 | |
827 | if (sme->sme_flags & SME_INIT_REFRESH) { | | | |
828 | sysmon_task_queue_sched(0, sme_initial_refresh, sme); | | | |
829 | DPRINTF(("%s: scheduled initial refresh for '%s'\n", | | | |
830 | __func__, sme->sme_name)); | | | |
831 | } | | | |
832 | SLIST_FOREACH(evdv, &sme_evdrv_list, evdrv_head) { | | | |
833 | sysmon_task_queue_sched(0, | | | |
834 | sme_event_drvadd, evdv->evdrv); | | | |
835 | nevent++; | | | |
836 | } | | | |
837 | /* | | 827 | /* |
838 | * Hook the sensor into rnd(4) entropy pool if requested | | 828 | * Hook the sensor into rnd(4) entropy pool if requested |
839 | */ | | 829 | */ |
840 | TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) { | | 830 | TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) { |
841 | if (edata->flags & ENVSYS_FHAS_ENTROPY) { | | 831 | if (edata->flags & ENVSYS_FHAS_ENTROPY) { |
842 | uint32_t rnd_type, rnd_flag = 0; | | 832 | uint32_t rnd_type, rnd_flag = 0; |
843 | size_t n; | | 833 | size_t n; |
844 | int tail = 1; | | 834 | int tail = 1; |
845 | | | 835 | |
846 | snprintf(rnd_name, sizeof(rnd_name), "%s-%s", | | 836 | snprintf(rnd_name, sizeof(rnd_name), "%s-%s", |
847 | sme->sme_name, edata->desc); | | 837 | sme->sme_name, edata->desc); |
848 | n = strlen(rnd_name); | | 838 | n = strlen(rnd_name); |
849 | /* | | 839 | /* |
| @@ -879,26 +869,37 @@ out: | | | @@ -879,26 +869,37 @@ out: |
879 | case ENVSYS_SAMPHOUR: | | 869 | case ENVSYS_SAMPHOUR: |
880 | rnd_type = RND_TYPE_POWER; | | 870 | rnd_type = RND_TYPE_POWER; |
881 | rnd_flag |= RND_FLAG_COLLECT_VALUE; | | 871 | rnd_flag |= RND_FLAG_COLLECT_VALUE; |
882 | rnd_flag |= RND_FLAG_ESTIMATE_VALUE; | | 872 | rnd_flag |= RND_FLAG_ESTIMATE_VALUE; |
883 | break; | | 873 | break; |
884 | default: | | 874 | default: |
885 | rnd_type = RND_TYPE_UNKNOWN; | | 875 | rnd_type = RND_TYPE_UNKNOWN; |
886 | break; | | 876 | break; |
887 | } | | 877 | } |
888 | rnd_attach_source(&edata->rnd_src, rnd_name, | | 878 | rnd_attach_source(&edata->rnd_src, rnd_name, |
889 | rnd_type, rnd_flag); | | 879 | rnd_type, rnd_flag); |
890 | } | | 880 | } |
891 | } | | 881 | } |
| | | 882 | |
| | | 883 | if (sme->sme_flags & SME_INIT_REFRESH) { |
| | | 884 | sysmon_task_queue_sched(0, sme_initial_refresh, sme); |
| | | 885 | DPRINTF(("%s: scheduled initial refresh for '%s'\n", |
| | | 886 | __func__, sme->sme_name)); |
| | | 887 | } |
| | | 888 | SLIST_FOREACH(evdv, &sme_evdrv_list, evdrv_head) { |
| | | 889 | sysmon_task_queue_sched(0, |
| | | 890 | sme_event_drvadd, evdv->evdrv); |
| | | 891 | nevent++; |
| | | 892 | } |
892 | DPRINTF(("%s: driver '%s' registered (nsens=%d nevent=%d)\n", | | 893 | DPRINTF(("%s: driver '%s' registered (nsens=%d nevent=%d)\n", |
893 | __func__, sme->sme_name, sme->sme_nsensors, nevent)); | | 894 | __func__, sme->sme_name, sme->sme_nsensors, nevent)); |
894 | } | | 895 | } |
895 | | | 896 | |
896 | out2: | | 897 | out2: |
897 | while (!SLIST_EMPTY(&sme_evdrv_list)) { | | 898 | while (!SLIST_EMPTY(&sme_evdrv_list)) { |
898 | evdv = SLIST_FIRST(&sme_evdrv_list); | | 899 | evdv = SLIST_FIRST(&sme_evdrv_list); |
899 | SLIST_REMOVE_HEAD(&sme_evdrv_list, evdrv_head); | | 900 | SLIST_REMOVE_HEAD(&sme_evdrv_list, evdrv_head); |
900 | kmem_free(evdv, sizeof(*evdv)); | | 901 | kmem_free(evdv, sizeof(*evdv)); |
901 | } | | 902 | } |
902 | if (!error) | | 903 | if (!error) |
903 | return 0; | | 904 | return 0; |
904 | | | 905 | |