opensolaris.c revision 302408
1159720Syar/*-
2159720Syar * Copyright 2007 John Birrell <jb@FreeBSD.org>
3159720Syar *
4159720Syar * Redistribution and use in source and binary forms, with or without
5159720Syar * modification, are permitted provided that the following conditions
6159720Syar * are met:
7159720Syar * 1. Redistributions of source code must retain the above copyright
8159720Syar *    notice, this list of conditions and the following disclaimer.
9159720Syar * 2. Redistributions in binary form must reproduce the above copyright
10159720Syar *    notice, this list of conditions and the following disclaimer in the
11159720Syar *    documentation and/or other materials provided with the distribution.
12159720Syar *
13159720Syar * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14159720Syar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15159720Syar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16159720Syar * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17159720Syar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18159720Syar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19159720Syar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20159720Syar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21159720Syar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22159720Syar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23159720Syar * SUCH DAMAGE.
24159720Syar *
25159720Syar * $FreeBSD: stable/11/sys/cddl/compat/opensolaris/kern/opensolaris.c 222670 2011-06-04 07:02:06Z avg $
26159720Syar *
27159720Syar */
28159720Syar
29159720Syar#include <sys/cdefs.h>
30159720Syar#include <sys/types.h>
31159720Syar#include <sys/conf.h>
32159720Syar#include <sys/cpuvar.h>
33159720Syar#include <sys/errno.h>
34159720Syar#include <sys/jail.h>
35159720Syar#include <sys/kernel.h>
36159720Syar#include <sys/misc.h>
37159720Syar#include <sys/module.h>
38159720Syar#include <sys/mutex.h>
39159720Syar
40159720Syarcpu_core_t	cpu_core[MAXCPU];
41159720Syarkmutex_t	cpu_lock;
42159720Syarsolaris_cpu_t	solaris_cpu[MAXCPU];
43159720Syarint		nsec_per_tick;
44159720Syar
45159720Syar/*
46159720Syar *  OpenSolaris subsystem initialisation.
47159720Syar */
48159720Syarstatic void
49159720Syaropensolaris_load(void *dummy)
50159720Syar{
51159720Syar	int i;
52159720Syar
53159720Syar	/*
54159720Syar	 * "Enable" all CPUs even though they may not exist just so
55159720Syar	 * that the asserts work. On FreeBSD, if a CPU exists, it is
56159720Syar	 * enabled.
57159720Syar	 */
58159720Syar	for (i = 0; i < MAXCPU; i++) {
59159720Syar		solaris_cpu[i].cpuid = i;
60159720Syar		solaris_cpu[i].cpu_flags &= CPU_ENABLE;
61159720Syar	}
62159720Syar
63159720Syar	mutex_init(&cpu_lock, "OpenSolaris CPU lock", MUTEX_DEFAULT, NULL);
64159720Syar
65159720Syar	nsec_per_tick = NANOSEC / hz;
66159720Syar}
67159720Syar
68159720SyarSYSINIT(opensolaris_register, SI_SUB_OPENSOLARIS, SI_ORDER_FIRST, opensolaris_load, NULL);
69159720Syar
70159720Syarstatic void
71159720Syaropensolaris_unload(void)
72159720Syar{
73159720Syar	mutex_destroy(&cpu_lock);
74}
75
76SYSUNINIT(opensolaris_unregister, SI_SUB_OPENSOLARIS, SI_ORDER_FIRST, opensolaris_unload, NULL);
77
78static int
79opensolaris_modevent(module_t mod __unused, int type, void *data __unused)
80{
81	int error = 0;
82
83	switch (type) {
84	case MOD_LOAD:
85		utsname.nodename = prison0.pr_hostname;
86		break;
87
88	case MOD_UNLOAD:
89		break;
90
91	case MOD_SHUTDOWN:
92		break;
93
94	default:
95		error = EOPNOTSUPP;
96		break;
97
98	}
99	return (error);
100}
101
102DEV_MODULE(opensolaris, opensolaris_modevent, NULL);
103MODULE_VERSION(opensolaris, 1);
104