1 | /* $Id: the-solaris-kernel.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Include all necessary headers for the Solaris kernel.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_SRC_r0drv_solaris_the_solaris_kernel_h
|
---|
38 | #define IPRT_INCLUDED_SRC_r0drv_solaris_the_solaris_kernel_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <sys/kmem.h>
|
---|
44 | #include <sys/types.h>
|
---|
45 | #include <sys/mman.h>
|
---|
46 | #include <sys/thread.h>
|
---|
47 | #include <sys/mutex.h>
|
---|
48 | #include <sys/condvar.h>
|
---|
49 | #include <sys/sdt.h>
|
---|
50 | #include <sys/schedctl.h>
|
---|
51 | #include <sys/time.h>
|
---|
52 | #include <sys/sysmacros.h>
|
---|
53 | #include <sys/cmn_err.h>
|
---|
54 | #include <sys/vmsystm.h>
|
---|
55 | #include <sys/cyclic.h>
|
---|
56 | #include <sys/class.h>
|
---|
57 | #include <sys/cpuvar.h>
|
---|
58 | #include <sys/archsystm.h>
|
---|
59 | #include <sys/x_call.h> /* in platform dir */
|
---|
60 | #include <sys/x86_archext.h>
|
---|
61 | #include <vm/hat.h>
|
---|
62 | #include <vm/seg_vn.h>
|
---|
63 | #include <vm/seg_kmem.h>
|
---|
64 | #include <vm/page.h>
|
---|
65 | #include <sys/ddi.h>
|
---|
66 | #include <sys/sunddi.h>
|
---|
67 | #include <sys/spl.h>
|
---|
68 | #include <sys/archsystm.h>
|
---|
69 | #include <sys/callo.h>
|
---|
70 | #include <sys/kobj.h>
|
---|
71 | #include <sys/ctf_api.h>
|
---|
72 | #include <sys/modctl.h>
|
---|
73 | #include <sys/proc.h>
|
---|
74 | #include <sys/t_lock.h>
|
---|
75 |
|
---|
76 | #undef u /* /usr/include/sys/user.h:249:1 is where this is defined to (curproc->p_user). very cool. */
|
---|
77 |
|
---|
78 | #include <iprt/cdefs.h>
|
---|
79 | #include <iprt/types.h>
|
---|
80 | #include <iprt/dbg.h>
|
---|
81 |
|
---|
82 | RT_C_DECLS_BEGIN
|
---|
83 |
|
---|
84 | /* IPRT functions. */
|
---|
85 | DECLHIDDEN(void *) rtR0SolMemAlloc(uint64_t cbPhysHi, uint64_t *puPhys, size_t cb, uint64_t cbAlign, bool fContig);
|
---|
86 | DECLHIDDEN(void) rtR0SolMemFree(void *pv, size_t cb);
|
---|
87 |
|
---|
88 |
|
---|
89 | /* Solaris functions. */
|
---|
90 | typedef callout_id_t (*PFNSOL_timeout_generic)(int type, void (*func)(void *),
|
---|
91 | void *arg, hrtime_t expiration,
|
---|
92 | hrtime_t resultion, int flags);
|
---|
93 | typedef hrtime_t (*PFNSOL_untimeout_generic)(callout_id_t id, int nowait);
|
---|
94 | typedef int (*PFNSOL_cyclic_reprogram)(cyclic_id_t id, hrtime_t expiration);
|
---|
95 | typedef void (*PFNSOL_contig_free)(void *addr, size_t size);
|
---|
96 | typedef int (*PFNSOL_page_noreloc_supported)(size_t cbPageSize);
|
---|
97 |
|
---|
98 | /* IPRT globals. */
|
---|
99 | extern bool g_frtSolSplSetsEIF;
|
---|
100 | extern RTCPUSET g_rtMpSolCpuSet;
|
---|
101 | extern PFNSOL_timeout_generic g_pfnrtR0Sol_timeout_generic;
|
---|
102 | extern PFNSOL_untimeout_generic g_pfnrtR0Sol_untimeout_generic;
|
---|
103 | extern PFNSOL_cyclic_reprogram g_pfnrtR0Sol_cyclic_reprogram;
|
---|
104 | extern PFNSOL_contig_free g_pfnrtR0Sol_contig_free;
|
---|
105 | extern PFNSOL_page_noreloc_supported g_pfnrtR0Sol_page_noreloc_supported;
|
---|
106 | extern size_t g_offrtSolThreadPreempt;
|
---|
107 | extern size_t g_offrtSolThreadIntrThread;
|
---|
108 | extern size_t g_offrtSolThreadLock;
|
---|
109 | extern size_t g_offrtSolThreadProc;
|
---|
110 | extern size_t g_offrtSolThreadId;
|
---|
111 | extern size_t g_offrtSolCpuPreempt;
|
---|
112 | extern size_t g_offrtSolCpuForceKernelPreempt;
|
---|
113 | extern bool g_frtSolInitDone;
|
---|
114 | extern RTDBGKRNLINFO g_hKrnlDbgInfo;
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * Workarounds for running on old versions of solaris with different cross call
|
---|
118 | * interfaces. If we find xc_init_cpu() in the kernel, then just use the
|
---|
119 | * defined interfaces for xc_call() from the include file where the xc_call()
|
---|
120 | * interfaces just takes a pointer to a ulong_t array. The array must be long
|
---|
121 | * enough to hold "ncpus" bits at runtime.
|
---|
122 |
|
---|
123 | * The reason for the hacks is that using the type "cpuset_t" is pretty much
|
---|
124 | * impossible from code built outside the Solaris source repository that wants
|
---|
125 | * to run on multiple releases of Solaris.
|
---|
126 | *
|
---|
127 | * For old style xc_call()s, 32 bit solaris and older 64 bit versions use
|
---|
128 | * "ulong_t" as cpuset_t.
|
---|
129 | *
|
---|
130 | * Later versions of 64 bit Solaris used: struct {ulong_t words[x];}
|
---|
131 | * where "x" depends on NCPU.
|
---|
132 | *
|
---|
133 | * We detect the difference in 64 bit support by checking the kernel value of
|
---|
134 | * max_cpuid, which always holds the compiled value of NCPU - 1.
|
---|
135 | *
|
---|
136 | * If Solaris increases NCPU to more than 256, VBox will continue to work on
|
---|
137 | * all versions of Solaris as long as the number of installed CPUs in the
|
---|
138 | * machine is <= IPRT_SOLARIS_NCPUS. If IPRT_SOLARIS_NCPUS is increased, this
|
---|
139 | * code has to be re-written some to provide compatibility with older Solaris
|
---|
140 | * which expects cpuset_t to be based on NCPU==256 -- or we discontinue
|
---|
141 | * support of old Nevada/S10.
|
---|
142 | */
|
---|
143 | #define IPRT_SOL_NCPUS 256
|
---|
144 | #define IPRT_SOL_SET_WORDS (IPRT_SOL_NCPUS / (sizeof(ulong_t) * 8))
|
---|
145 | #define IPRT_SOL_X_CALL_HIPRI (2) /* for Old Solaris interface */
|
---|
146 | typedef struct RTSOLCPUSET
|
---|
147 | {
|
---|
148 | ulong_t auCpus[IPRT_SOL_SET_WORDS];
|
---|
149 | } RTSOLCPUSET;
|
---|
150 | typedef RTSOLCPUSET *PRTSOLCPUSET;
|
---|
151 |
|
---|
152 | /* Avoid warnings even if it means more typing... */
|
---|
153 | typedef struct RTR0FNSOLXCCALL
|
---|
154 | {
|
---|
155 | union
|
---|
156 | {
|
---|
157 | void *(*pfnSol_xc_call) (xc_arg_t, xc_arg_t, xc_arg_t, ulong_t *, xc_func_t);
|
---|
158 | void *(*pfnSol_xc_call_old) (xc_arg_t, xc_arg_t, xc_arg_t, int, RTSOLCPUSET, xc_func_t);
|
---|
159 | void *(*pfnSol_xc_call_old_ulong)(xc_arg_t, xc_arg_t, xc_arg_t, int, ulong_t, xc_func_t);
|
---|
160 | } u;
|
---|
161 | } RTR0FNSOLXCCALL;
|
---|
162 | typedef RTR0FNSOLXCCALL *PRTR0FNSOLXCCALL;
|
---|
163 |
|
---|
164 | extern RTR0FNSOLXCCALL g_rtSolXcCall;
|
---|
165 | extern bool g_frtSolOldIPI;
|
---|
166 | extern bool g_frtSolOldIPIUlong;
|
---|
167 |
|
---|
168 | /*
|
---|
169 | * Thread-context hooks.
|
---|
170 | * Workarounds for older Solaris versions that did not have the exitctx() callback.
|
---|
171 | */
|
---|
172 | typedef struct RTR0FNSOLTHREADCTX
|
---|
173 | {
|
---|
174 | union
|
---|
175 | {
|
---|
176 | void *(*pfnSol_installctx) (kthread_t *pThread, void *pvArg,
|
---|
177 | void (*pfnSave)(void *pvArg),
|
---|
178 | void (*pfnRestore)(void *pvArg),
|
---|
179 | void (*pfnFork)(void *pvThread, void *pvThreadFork),
|
---|
180 | void (*pfnLwpCreate)(void *pvThread, void *pvThreadCreate),
|
---|
181 | void (*pfnExit)(void *pvThread),
|
---|
182 | void (*pfnFree)(void *pvArg, int fIsExec));
|
---|
183 |
|
---|
184 | void *(*pfnSol_installctx_old) (kthread_t *pThread, void *pvArg,
|
---|
185 | void (*pfnSave)(void *pvArg),
|
---|
186 | void (*pfnRestore)(void *pvArg),
|
---|
187 | void (*pfnFork)(void *pvThread, void *pvThreadFork),
|
---|
188 | void (*pfnLwpCreate)(void *pvThread, void *pvThreadCreate),
|
---|
189 | void (*pfnFree)(void *pvArg, int fIsExec));
|
---|
190 | } Install;
|
---|
191 |
|
---|
192 | union
|
---|
193 | {
|
---|
194 | int (*pfnSol_removectx) (kthread_t *pThread, void *pvArg,
|
---|
195 | void (*pfnSave)(void *pvArg),
|
---|
196 | void (*pfnRestore)(void *pvArg),
|
---|
197 | void (*pfnFork)(void *pvThread, void *pvThreadFork),
|
---|
198 | void (*pfnLwpCreate)(void *pvThread, void *pvThreadCreate),
|
---|
199 | void (*pfnExit)(void *pvThread),
|
---|
200 | void (*pfnFree)(void *pvArg, int fIsExec));
|
---|
201 |
|
---|
202 | int (*pfnSol_removectx_old) (kthread_t *pThread, void *pvArg,
|
---|
203 | void (*pfnSave)(void *pvArg),
|
---|
204 | void (*pfnRestore)(void *pvArg),
|
---|
205 | void (*pfnFork)(void *pvThread, void *pvThreadFork),
|
---|
206 | void (*pfnLwpCreate)(void *pvThread, void *pvThreadCreate),
|
---|
207 | void (*pfnFree)(void *pvArg, int fIsExec));
|
---|
208 | } Remove;
|
---|
209 | } RTR0FNSOLTHREADCTX;
|
---|
210 | typedef RTR0FNSOLTHREADCTX *PRTR0FNSOLTHREADCTX;
|
---|
211 |
|
---|
212 | extern RTR0FNSOLTHREADCTX g_rtSolThreadCtx;
|
---|
213 | extern bool g_frtSolOldThreadCtx;
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * Workaround for older Solaris versions which called map_addr()/choose_addr()/
|
---|
217 | * map_addr_proc() with an 'alignment' argument that was removed in Solaris
|
---|
218 | * 11.4.
|
---|
219 | */
|
---|
220 | typedef struct RTR0FNSOLMAPADDR
|
---|
221 | {
|
---|
222 | union
|
---|
223 | {
|
---|
224 | void *(*pfnSol_map_addr) (caddr_t *, size_t, offset_t, uint_t);
|
---|
225 | void *(*pfnSol_map_addr_old) (caddr_t *, size_t, offset_t, int, uint_t);
|
---|
226 | } u;
|
---|
227 | } RTR0FNSOLMAPADDR;
|
---|
228 | typedef RTR0FNSOLMAPADDR *PRTR0FNSOLMAPADDR;
|
---|
229 |
|
---|
230 | extern RTR0FNSOLMAPADDR g_rtSolMapAddr;
|
---|
231 | extern bool g_frtSolOldMapAddr;
|
---|
232 |
|
---|
233 | /* Solaris globals. */
|
---|
234 | extern uintptr_t kernelbase;
|
---|
235 |
|
---|
236 | /* Misc stuff from newer kernels. */
|
---|
237 | #ifndef CALLOUT_FLAG_ABSOLUTE
|
---|
238 | # define CALLOUT_FLAG_ABSOLUTE 2
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | RT_C_DECLS_END
|
---|
242 |
|
---|
243 | #endif /* !IPRT_INCLUDED_SRC_r0drv_solaris_the_solaris_kernel_h */
|
---|
244 |
|
---|