1*a4c9570dSpgoyette /* $NetBSD: opencrypto_component.c,v 1.6 2020/01/27 17:10:23 pgoyette Exp $ */
27a69fdf4Spooka
37a69fdf4Spooka /*
47a69fdf4Spooka * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
57a69fdf4Spooka *
67a69fdf4Spooka * Redistribution and use in source and binary forms, with or without
77a69fdf4Spooka * modification, are permitted provided that the following conditions
87a69fdf4Spooka * are met:
97a69fdf4Spooka * 1. Redistributions of source code must retain the above copyright
107a69fdf4Spooka * notice, this list of conditions and the following disclaimer.
117a69fdf4Spooka * 2. Redistributions in binary form must reproduce the above copyright
127a69fdf4Spooka * notice, this list of conditions and the following disclaimer in the
137a69fdf4Spooka * documentation and/or other materials provided with the distribution.
147a69fdf4Spooka *
157a69fdf4Spooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
167a69fdf4Spooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
177a69fdf4Spooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
187a69fdf4Spooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197a69fdf4Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
207a69fdf4Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
217a69fdf4Spooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227a69fdf4Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237a69fdf4Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247a69fdf4Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257a69fdf4Spooka * SUCH DAMAGE.
267a69fdf4Spooka */
277a69fdf4Spooka
287a69fdf4Spooka #include <sys/cdefs.h>
29*a4c9570dSpgoyette __KERNEL_RCSID(0, "$NetBSD: opencrypto_component.c,v 1.6 2020/01/27 17:10:23 pgoyette Exp $");
307a69fdf4Spooka
317a69fdf4Spooka #include <sys/param.h>
327a69fdf4Spooka #include <sys/conf.h>
337a69fdf4Spooka #include <sys/device.h>
347a69fdf4Spooka #include <sys/stat.h>
357a69fdf4Spooka #include <sys/module.h>
367a69fdf4Spooka
376bb51422Spooka #include <rump-sys/kern.h>
386bb51422Spooka #include <rump-sys/dev.h>
396bb51422Spooka #include <rump-sys/vfs.h>
407a69fdf4Spooka
41f2fa9ab0Schristos #include "ioconf.h"
42f2fa9ab0Schristos
437a69fdf4Spooka void crypto_init(void);
447a69fdf4Spooka
RUMP_COMPONENT(RUMP_COMPONENT_DEV)457a69fdf4Spooka RUMP_COMPONENT(RUMP_COMPONENT_DEV)
467a69fdf4Spooka {
477a69fdf4Spooka extern const struct cdevsw crypto_cdevsw;
487a69fdf4Spooka devmajor_t bmaj, cmaj;
497a69fdf4Spooka int error;
507a69fdf4Spooka
517a69fdf4Spooka /* go, mydevfs */
527a69fdf4Spooka bmaj = cmaj = -1;
537a69fdf4Spooka
547a69fdf4Spooka if ((error = devsw_attach("crypto", NULL, &bmaj,
557a69fdf4Spooka &crypto_cdevsw, &cmaj)) != 0)
567a69fdf4Spooka panic("cannot attach crypto: %d", error);
577a69fdf4Spooka
587a69fdf4Spooka if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/crypto",
597a69fdf4Spooka cmaj, 0)) != 0)
607a69fdf4Spooka panic("cannot create /dev/crypto: %d", error);
617a69fdf4Spooka
627a69fdf4Spooka /*
637a69fdf4Spooka * Initialize OpenCrypto and its pseudo-devices here
647a69fdf4Spooka */
657a69fdf4Spooka crypto_init();
667a69fdf4Spooka rump_pdev_add(cryptoattach, 1);
67e3753d82Sknakahara #if 0
68e3753d82Sknakahara /*
69e3753d82Sknakahara * rump defines "_MODULE" in spite of using built-in module
70e3753d82Sknakahara * initialization(module_init_class()). So, swcryptoattach_internal()
71e3753d82Sknakahara * is called by two functions, one is swcryptoattach() and the other is
72e3753d82Sknakahara * swcrypto_modcmd().
73e3753d82Sknakahara * That causes "builtin module `swcrypto' failed to init" WARNING message.
74e3753d82Sknakahara * To suppress this warning, we let rump use swcrypto_modcmd() call-path
75e3753d82Sknakahara * only.
76e3753d82Sknakahara *
77e3753d82Sknakahara * TODO:
78*a4c9570dSpgoyette * There is still "crypto: unable to register devsw, error 17" message.
79*a4c9570dSpgoyette * it should be suppressed.
80e3753d82Sknakahara */
817a69fdf4Spooka rump_pdev_add(swcryptoattach, 0);
82e3753d82Sknakahara #endif
837a69fdf4Spooka }
84