opencrypto_component.c revision 1.6
11.6Spgoyette/*	$NetBSD: opencrypto_component.c,v 1.6 2020/01/27 17:10:23 pgoyette Exp $ */
21.1Spooka
31.1Spooka/*
41.1Spooka * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
51.1Spooka *
61.1Spooka * Redistribution and use in source and binary forms, with or without
71.1Spooka * modification, are permitted provided that the following conditions
81.1Spooka * are met:
91.1Spooka * 1. Redistributions of source code must retain the above copyright
101.1Spooka *    notice, this list of conditions and the following disclaimer.
111.1Spooka * 2. Redistributions in binary form must reproduce the above copyright
121.1Spooka *    notice, this list of conditions and the following disclaimer in the
131.1Spooka *    documentation and/or other materials provided with the distribution.
141.1Spooka *
151.1Spooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
161.1Spooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
171.1Spooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
181.1Spooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191.1Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201.1Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
211.1Spooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231.1Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Spooka * SUCH DAMAGE.
261.1Spooka */
271.1Spooka
281.1Spooka#include <sys/cdefs.h>
291.6Spgoyette__KERNEL_RCSID(0, "$NetBSD: opencrypto_component.c,v 1.6 2020/01/27 17:10:23 pgoyette Exp $");
301.1Spooka
311.1Spooka#include <sys/param.h>
321.1Spooka#include <sys/conf.h>
331.1Spooka#include <sys/device.h>
341.1Spooka#include <sys/stat.h>
351.1Spooka#include <sys/module.h>
361.1Spooka
371.4Spooka#include <rump-sys/kern.h>
381.4Spooka#include <rump-sys/dev.h>
391.4Spooka#include <rump-sys/vfs.h>
401.1Spooka
411.3Schristos#include "ioconf.h"
421.3Schristos
431.1Spookavoid crypto_init(void);
441.1Spooka
451.1SpookaRUMP_COMPONENT(RUMP_COMPONENT_DEV)
461.1Spooka{
471.1Spooka	extern const struct cdevsw crypto_cdevsw;
481.1Spooka	devmajor_t bmaj, cmaj;
491.1Spooka	int error;
501.1Spooka
511.1Spooka	/* go, mydevfs */
521.1Spooka	bmaj = cmaj = -1;
531.1Spooka
541.1Spooka	if ((error = devsw_attach("crypto", NULL, &bmaj,
551.1Spooka	    &crypto_cdevsw, &cmaj)) != 0)
561.1Spooka		panic("cannot attach crypto: %d", error);
571.1Spooka
581.1Spooka	if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/crypto",
591.1Spooka	    cmaj, 0)) != 0)
601.1Spooka		panic("cannot create /dev/crypto: %d", error);
611.1Spooka
621.1Spooka	/*
631.1Spooka	 * Initialize OpenCrypto and its pseudo-devices here
641.1Spooka	 */
651.1Spooka	crypto_init();
661.1Spooka	rump_pdev_add(cryptoattach, 1);
671.5Sknakahar#if 0
681.5Sknakahar	/*
691.5Sknakahar	 * rump defines "_MODULE" in spite of using built-in module
701.5Sknakahar	 * initialization(module_init_class()). So, swcryptoattach_internal()
711.5Sknakahar	 * is called by two functions, one is swcryptoattach() and the other is
721.5Sknakahar	 * swcrypto_modcmd().
731.5Sknakahar	 * That causes "builtin module `swcrypto' failed to init" WARNING message.
741.5Sknakahar	 * To suppress this warning, we let rump use swcrypto_modcmd() call-path
751.5Sknakahar	 * only.
761.5Sknakahar	 *
771.5Sknakahar	 * TODO:
781.6Spgoyette	 * There is still "crypto: unable to register devsw, error 17" message.
791.6Spgoyette	 * it should be suppressed.
801.5Sknakahar	 */
811.1Spooka	rump_pdev_add(swcryptoattach, 0);
821.5Sknakahar#endif
831.1Spooka}
84