xref: /freebsd-src/sys/cddl/compat/opensolaris/kern/opensolaris.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
185993067SJohn Birrell /*-
285993067SJohn Birrell  * Copyright 2007 John Birrell <jb@FreeBSD.org>
385993067SJohn Birrell  *
485993067SJohn Birrell  * Redistribution and use in source and binary forms, with or without
585993067SJohn Birrell  * modification, are permitted provided that the following conditions
685993067SJohn Birrell  * are met:
785993067SJohn Birrell  * 1. Redistributions of source code must retain the above copyright
885993067SJohn Birrell  *    notice, this list of conditions and the following disclaimer.
985993067SJohn Birrell  * 2. Redistributions in binary form must reproduce the above copyright
1085993067SJohn Birrell  *    notice, this list of conditions and the following disclaimer in the
1185993067SJohn Birrell  *    documentation and/or other materials provided with the distribution.
1285993067SJohn Birrell  *
1385993067SJohn Birrell  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1485993067SJohn Birrell  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1585993067SJohn Birrell  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1685993067SJohn Birrell  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
1785993067SJohn Birrell  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1885993067SJohn Birrell  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1985993067SJohn Birrell  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2085993067SJohn Birrell  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2185993067SJohn Birrell  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2285993067SJohn Birrell  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2385993067SJohn Birrell  * SUCH DAMAGE.
2485993067SJohn Birrell  *
2585993067SJohn Birrell  */
2685993067SJohn Birrell 
27e2e050c8SConrad Meyer #include <sys/param.h>
2885993067SJohn Birrell #include <sys/conf.h>
2985993067SJohn Birrell #include <sys/cpuvar.h>
3085993067SJohn Birrell #include <sys/errno.h>
3176ca6f88SJamie Gritton #include <sys/jail.h>
3285993067SJohn Birrell #include <sys/kernel.h>
3329b02909SMarko Zec #include <sys/misc.h>
3485993067SJohn Birrell #include <sys/module.h>
3585993067SJohn Birrell #include <sys/mutex.h>
3685993067SJohn Birrell 
37*9e5787d2SMatt Macy extern struct opensolaris_utsname utsname;
38*9e5787d2SMatt Macy 
3985993067SJohn Birrell cpu_core_t	cpu_core[MAXCPU];
4085993067SJohn Birrell kmutex_t	cpu_lock;
4185993067SJohn Birrell solaris_cpu_t	solaris_cpu[MAXCPU];
422386e135SAndriy Gapon int		nsec_per_tick;
4385993067SJohn Birrell 
4485993067SJohn Birrell /*
4585993067SJohn Birrell  *  OpenSolaris subsystem initialisation.
4685993067SJohn Birrell  */
4785993067SJohn Birrell static void
opensolaris_load(void * dummy)4885993067SJohn Birrell opensolaris_load(void *dummy)
4985993067SJohn Birrell {
5085993067SJohn Birrell 	int i;
5185993067SJohn Birrell 
5285993067SJohn Birrell 	/*
5385993067SJohn Birrell 	 * "Enable" all CPUs even though they may not exist just so
5485993067SJohn Birrell 	 * that the asserts work. On FreeBSD, if a CPU exists, it is
5585993067SJohn Birrell 	 * enabled.
5685993067SJohn Birrell 	 */
5785993067SJohn Birrell 	for (i = 0; i < MAXCPU; i++) {
5885993067SJohn Birrell 		solaris_cpu[i].cpuid = i;
5985993067SJohn Birrell 		solaris_cpu[i].cpu_flags &= CPU_ENABLE;
6085993067SJohn Birrell 	}
6185993067SJohn Birrell 
6285993067SJohn Birrell 	mutex_init(&cpu_lock, "OpenSolaris CPU lock", MUTEX_DEFAULT, NULL);
632386e135SAndriy Gapon 
642386e135SAndriy Gapon 	nsec_per_tick = NANOSEC / hz;
6585993067SJohn Birrell }
6685993067SJohn Birrell 
6785993067SJohn Birrell SYSINIT(opensolaris_register, SI_SUB_OPENSOLARIS, SI_ORDER_FIRST, opensolaris_load, NULL);
6885993067SJohn Birrell 
6985993067SJohn Birrell static void
opensolaris_unload(void)7085993067SJohn Birrell opensolaris_unload(void)
7185993067SJohn Birrell {
7285993067SJohn Birrell 	mutex_destroy(&cpu_lock);
7385993067SJohn Birrell }
7485993067SJohn Birrell 
7585993067SJohn Birrell SYSUNINIT(opensolaris_unregister, SI_SUB_OPENSOLARIS, SI_ORDER_FIRST, opensolaris_unload, NULL);
7685993067SJohn Birrell 
7785993067SJohn Birrell static int
opensolaris_modevent(module_t mod __unused,int type,void * data __unused)7885993067SJohn Birrell opensolaris_modevent(module_t mod __unused, int type, void *data __unused)
7985993067SJohn Birrell {
8085993067SJohn Birrell 	int error = 0;
8185993067SJohn Birrell 
8285993067SJohn Birrell 	switch (type) {
8385993067SJohn Birrell 	case MOD_LOAD:
8485993067SJohn Birrell 		break;
8585993067SJohn Birrell 
8685993067SJohn Birrell 	case MOD_UNLOAD:
8785993067SJohn Birrell 		break;
8885993067SJohn Birrell 
8985993067SJohn Birrell 	case MOD_SHUTDOWN:
9085993067SJohn Birrell 		break;
9185993067SJohn Birrell 
9285993067SJohn Birrell 	default:
9385993067SJohn Birrell 		error = EOPNOTSUPP;
9485993067SJohn Birrell 		break;
9585993067SJohn Birrell 
9685993067SJohn Birrell 	}
9785993067SJohn Birrell 	return (error);
9885993067SJohn Birrell }
9985993067SJohn Birrell 
10085993067SJohn Birrell DEV_MODULE(opensolaris, opensolaris_modevent, NULL);
10185993067SJohn Birrell MODULE_VERSION(opensolaris, 1);
102