xref: /netbsd-src/sys/rump/dev/lib/librnd/rnd_component.c (revision 5084c1b50f9863db4e36c6ec86538f91c324b1ac)
1*5084c1b5Sriastradh /*	$NetBSD: rnd_component.c,v 1.7 2020/04/30 03:28:19 riastradh Exp $	*/
20e3e572aSpooka 
30e3e572aSpooka /*
40e3e572aSpooka  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
50e3e572aSpooka  *
60e3e572aSpooka  * Redistribution and use in source and binary forms, with or without
70e3e572aSpooka  * modification, are permitted provided that the following conditions
80e3e572aSpooka  * are met:
90e3e572aSpooka  * 1. Redistributions of source code must retain the above copyright
100e3e572aSpooka  *    notice, this list of conditions and the following disclaimer.
110e3e572aSpooka  * 2. Redistributions in binary form must reproduce the above copyright
120e3e572aSpooka  *    notice, this list of conditions and the following disclaimer in the
130e3e572aSpooka  *    documentation and/or other materials provided with the distribution.
140e3e572aSpooka  *
150e3e572aSpooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
160e3e572aSpooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
170e3e572aSpooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
180e3e572aSpooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190e3e572aSpooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200e3e572aSpooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
210e3e572aSpooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220e3e572aSpooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230e3e572aSpooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240e3e572aSpooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250e3e572aSpooka  * SUCH DAMAGE.
260e3e572aSpooka  */
270e3e572aSpooka 
280e3e572aSpooka #include <sys/cdefs.h>
29*5084c1b5Sriastradh __KERNEL_RCSID(0, "$NetBSD: rnd_component.c,v 1.7 2020/04/30 03:28:19 riastradh Exp $");
300e3e572aSpooka 
310e3e572aSpooka #include <sys/param.h>
320e3e572aSpooka #include <sys/conf.h>
330e3e572aSpooka #include <sys/device.h>
340e3e572aSpooka #include <sys/rnd.h>
350e3e572aSpooka #include <sys/stat.h>
360e3e572aSpooka 
376bb51422Spooka #include <rump-sys/kern.h>
386bb51422Spooka #include <rump-sys/dev.h>
396bb51422Spooka #include <rump-sys/vfs.h>
400e3e572aSpooka 
41f2fa9ab0Schristos #include "ioconf.h"
420e3e572aSpooka 
RUMP_COMPONENT(RUMP_COMPONENT_DEV)430e3e572aSpooka RUMP_COMPONENT(RUMP_COMPONENT_DEV)
440e3e572aSpooka {
450e3e572aSpooka 	extern const struct cdevsw rnd_cdevsw;
460e3e572aSpooka 	devmajor_t bmaj, cmaj;
470e3e572aSpooka 	int error;
480e3e572aSpooka 
490e3e572aSpooka 	/* go, mydevfs */
500e3e572aSpooka 	bmaj = cmaj = -1;
510e3e572aSpooka 
520e3e572aSpooka 	if ((error = devsw_attach("random", NULL, &bmaj,
530e3e572aSpooka 	    &rnd_cdevsw, &cmaj)) != 0)
540e3e572aSpooka 		panic("cannot attach rnd: %d", error);
550e3e572aSpooka 
560e3e572aSpooka 	if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/random",
570e3e572aSpooka 	    cmaj, RND_DEV_RANDOM)) != 0)
580e3e572aSpooka 		panic("cannot create /dev/random: %d", error);
590e3e572aSpooka 	if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/urandom",
600e3e572aSpooka 	    cmaj, RND_DEV_URANDOM)) != 0)
610e3e572aSpooka 		panic("cannot create /dev/urandom: %d", error);
620e3e572aSpooka 
630e3e572aSpooka 	rump_pdev_add(rndattach, 4);
640e3e572aSpooka }
65