| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sysmon.c,v 1.20 2015/04/23 23:22:03 pgoyette Exp $ */ | | 1 | /* $NetBSD: sysmon.c,v 1.21 2015/04/24 03:35:49 pgoyette Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2000 Zembu Labs, Inc. | | 4 | * Copyright (c) 2000 Zembu Labs, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Author: Jason R. Thorpe <thorpej@zembu.com> | | 7 | * Author: Jason R. Thorpe <thorpej@zembu.com> |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -29,27 +29,27 @@ | | | @@ -29,27 +29,27 @@ |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | /* | | 36 | /* |
37 | * Clearing house for system monitoring hardware. We currently | | 37 | * Clearing house for system monitoring hardware. We currently |
38 | * handle environmental sensors, watchdog timers, and power management. | | 38 | * handle environmental sensors, watchdog timers, and power management. |
39 | */ | | 39 | */ |
40 | | | 40 | |
41 | #include <sys/cdefs.h> | | 41 | #include <sys/cdefs.h> |
42 | __KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.20 2015/04/23 23:22:03 pgoyette Exp $"); | | 42 | __KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.21 2015/04/24 03:35:49 pgoyette Exp $"); |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/conf.h> | | 45 | #include <sys/conf.h> |
46 | #include <sys/errno.h> | | 46 | #include <sys/errno.h> |
47 | #include <sys/fcntl.h> | | 47 | #include <sys/fcntl.h> |
48 | #include <sys/callout.h> | | 48 | #include <sys/callout.h> |
49 | #include <sys/kernel.h> | | 49 | #include <sys/kernel.h> |
50 | #include <sys/systm.h> | | 50 | #include <sys/systm.h> |
51 | #include <sys/proc.h> | | 51 | #include <sys/proc.h> |
52 | #include <sys/module.h> | | 52 | #include <sys/module.h> |
53 | #include <sys/mutex.h> | | 53 | #include <sys/mutex.h> |
54 | #include <sys/device.h> | | 54 | #include <sys/device.h> |
55 | | | 55 | |
| @@ -335,58 +335,62 @@ sysmonkqfilter(dev_t dev, struct knote * | | | @@ -335,58 +335,62 @@ sysmonkqfilter(dev_t dev, struct knote * |
335 | break; | | 335 | break; |
336 | default: | | 336 | default: |
337 | error = 1; | | 337 | error = 1; |
338 | } | | 338 | } |
339 | | | 339 | |
340 | return (error); | | 340 | return (error); |
341 | } | | 341 | } |
342 | | | 342 | |
343 | MODULE(MODULE_CLASS_DRIVER, sysmon, ""); | | 343 | MODULE(MODULE_CLASS_DRIVER, sysmon, ""); |
344 | | | 344 | |
345 | int | | 345 | int |
346 | sysmon_init(void) | | 346 | sysmon_init(void) |
347 | { | | 347 | { |
| | | 348 | #ifdef _MODULE |
348 | devmajor_t bmajor, cmajor; | | 349 | devmajor_t bmajor, cmajor; |
| | | 350 | #endif |
349 | static struct cfdata cf; | | 351 | static struct cfdata cf; |
350 | int error = 0; | | 352 | int error = 0; |
351 | | | 353 | |
352 | if (sysmon_dev != NULL) { | | 354 | if (sysmon_dev != NULL) { |
353 | return EEXIST; | | 355 | return EEXIST; |
354 | } | | 356 | } |
355 | | | 357 | |
356 | error = config_cfdriver_attach(&sysmon_cd); | | 358 | error = config_cfdriver_attach(&sysmon_cd); |
357 | if (error) { | | 359 | if (error) { |
358 | aprint_error("%s: unable to attach cfdriver\n", | | 360 | aprint_error("%s: unable to attach cfdriver\n", |
359 | sysmon_cd.cd_name); | | 361 | sysmon_cd.cd_name); |
360 | return error; | | 362 | return error; |
361 | } | | 363 | } |
362 | error = config_cfattach_attach(sysmon_cd.cd_name, &sysmon_ca); | | 364 | error = config_cfattach_attach(sysmon_cd.cd_name, &sysmon_ca); |
363 | if (error) { | | 365 | if (error) { |
364 | config_cfdriver_detach(&sysmon_cd); | | 366 | config_cfdriver_detach(&sysmon_cd); |
365 | aprint_error("%s: unable to attach cfattach\n", | | 367 | aprint_error("%s: unable to attach cfattach\n", |
366 | sysmon_cd.cd_name); | | 368 | sysmon_cd.cd_name); |
367 | return error; | | 369 | return error; |
368 | } | | 370 | } |
369 | | | 371 | |
| | | 372 | #ifdef _MODULE |
370 | bmajor = cmajor = -1; | | 373 | bmajor = cmajor = -1; |
371 | error = devsw_attach("sysmon", NULL, &bmajor, | | 374 | error = devsw_attach("sysmon", NULL, &bmajor, |
372 | &sysmon_cdevsw, &cmajor); | | 375 | &sysmon_cdevsw, &cmajor); |
373 | if (error) { | | 376 | if (error) { |
374 | config_cfattach_detach(sysmon_cd.cd_name, &sysmon_ca); | | 377 | config_cfattach_detach(sysmon_cd.cd_name, &sysmon_ca); |
375 | config_cfdriver_detach(&sysmon_cd); | | 378 | config_cfdriver_detach(&sysmon_cd); |
376 | aprint_error("%s: unable to attach devsw\n", | | 379 | aprint_error("%s: unable to attach devsw\n", |
377 | sysmon_cd.cd_name); | | 380 | sysmon_cd.cd_name); |
378 | return error; | | 381 | return error; |
379 | } | | 382 | } |
| | | 383 | #endif |
380 | | | 384 | |
381 | cf.cf_name = sysmon_cd.cd_name; | | 385 | cf.cf_name = sysmon_cd.cd_name; |
382 | cf.cf_atname = sysmon_cd.cd_name; | | 386 | cf.cf_atname = sysmon_cd.cd_name; |
383 | cf.cf_unit = 0; | | 387 | cf.cf_unit = 0; |
384 | cf.cf_fstate = FSTATE_STAR; | | 388 | cf.cf_fstate = FSTATE_STAR; |
385 | cf.cf_pspec = NULL; | | 389 | cf.cf_pspec = NULL; |
386 | cf.cf_loc = NULL; | | 390 | cf.cf_loc = NULL; |
387 | cf.cf_flags = 0; | | 391 | cf.cf_flags = 0; |
388 | | | 392 | |
389 | sysmon_dev = config_attach_pseudo(&cf); | | 393 | sysmon_dev = config_attach_pseudo(&cf); |
390 | if (sysmon_dev == NULL) { | | 394 | if (sysmon_dev == NULL) { |
391 | aprint_error("%s: failed to attach pseudo device\n", | | 395 | aprint_error("%s: failed to attach pseudo device\n", |
392 | sysmon_cd.cd_name); | | 396 | sysmon_cd.cd_name); |