1*6bb51422Spooka /* $NetBSD: sysmon_component.c,v 1.3 2016/01/26 23:12:16 pooka Exp $ */
2408eb8f3Spooka
3408eb8f3Spooka /*
4408eb8f3Spooka * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
5408eb8f3Spooka *
6408eb8f3Spooka * Redistribution and use in source and binary forms, with or without
7408eb8f3Spooka * modification, are permitted provided that the following conditions
8408eb8f3Spooka * are met:
9408eb8f3Spooka * 1. Redistributions of source code must retain the above copyright
10408eb8f3Spooka * notice, this list of conditions and the following disclaimer.
11408eb8f3Spooka * 2. Redistributions in binary form must reproduce the above copyright
12408eb8f3Spooka * notice, this list of conditions and the following disclaimer in the
13408eb8f3Spooka * documentation and/or other materials provided with the distribution.
14408eb8f3Spooka *
15408eb8f3Spooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16408eb8f3Spooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17408eb8f3Spooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18408eb8f3Spooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19408eb8f3Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20408eb8f3Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21408eb8f3Spooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22408eb8f3Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23408eb8f3Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24408eb8f3Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25408eb8f3Spooka * SUCH DAMAGE.
26408eb8f3Spooka */
27408eb8f3Spooka
28408eb8f3Spooka #include <sys/cdefs.h>
29*6bb51422Spooka __KERNEL_RCSID(0, "$NetBSD: sysmon_component.c,v 1.3 2016/01/26 23:12:16 pooka Exp $");
30408eb8f3Spooka
31408eb8f3Spooka #include <sys/param.h>
32408eb8f3Spooka #include <sys/conf.h>
33408eb8f3Spooka #include <sys/device.h>
34408eb8f3Spooka #include <sys/stat.h>
35408eb8f3Spooka
36408eb8f3Spooka #include <dev/sysmon/sysmon_taskq.h>
37408eb8f3Spooka #include <dev/sysmon/sysmonvar.h>
38408eb8f3Spooka
39*6bb51422Spooka #include <rump-sys/kern.h>
40*6bb51422Spooka #include <rump-sys/dev.h>
41*6bb51422Spooka #include <rump-sys/vfs.h>
42408eb8f3Spooka
RUMP_COMPONENT(RUMP_COMPONENT_DEV)43408eb8f3Spooka RUMP_COMPONENT(RUMP_COMPONENT_DEV)
44408eb8f3Spooka {
45408eb8f3Spooka extern const struct cdevsw sysmon_cdevsw;
46408eb8f3Spooka devmajor_t bmaj, cmaj;
47408eb8f3Spooka int error;
48408eb8f3Spooka
492c08ddf9Spgoyette /*
502c08ddf9Spgoyette * Temporarily attach the devsw so we can determine our
512c08ddf9Spgoyette * major device number. We'll detach it immediately, so
522c08ddf9Spgoyette * normal module initialization can permanently attach.
532c08ddf9Spgoyette */
54408eb8f3Spooka bmaj = cmaj = -1;
55408eb8f3Spooka if ((error = devsw_attach("sysmon", NULL, &bmaj,
56408eb8f3Spooka &sysmon_cdevsw, &cmaj)) != 0)
57408eb8f3Spooka panic("sysmon devsw attach failed: %d", error);
582c08ddf9Spgoyette devsw_detach(NULL, &sysmon_cdevsw);
59408eb8f3Spooka
60408eb8f3Spooka if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/sysmon",
61408eb8f3Spooka cmaj, SYSMON_MINOR_ENVSYS)) != 0)
62408eb8f3Spooka panic("cannot create /dev/sysmon: %d", error);
63408eb8f3Spooka if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/watchdog",
64408eb8f3Spooka cmaj, SYSMON_MINOR_WDOG)) != 0)
65408eb8f3Spooka panic("cannot create /dev/watchdog: %d", error);
66408eb8f3Spooka if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/power",
67408eb8f3Spooka cmaj, SYSMON_MINOR_POWER)) != 0)
68408eb8f3Spooka panic("cannot create /dev/power: %d", error);
69408eb8f3Spooka }
70