1 | /* $Id: initterm-r0drv-solaris.c 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Initialization & Termination, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #include "the-solaris-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/assert.h>
|
---|
35 | #include <iprt/err.h>
|
---|
36 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
37 | # include <iprt/asm-amd64-x86.h>
|
---|
38 | #endif
|
---|
39 | #include "internal/initterm.h"
|
---|
40 |
|
---|
41 |
|
---|
42 | /*******************************************************************************
|
---|
43 | * Global Variables *
|
---|
44 | *******************************************************************************/
|
---|
45 | /** Kernel debug info handle. */
|
---|
46 | RTDBGKRNLINFO g_hKrnlDbgInfo;
|
---|
47 | /** Indicates that the spl routines (and therefore a bunch of other ones too)
|
---|
48 | * will set EFLAGS::IF and break code that disables interrupts. */
|
---|
49 | bool g_frtSolSplSetsEIF = false;
|
---|
50 | /** timeout_generic address. */
|
---|
51 | PFNSOL_timeout_generic g_pfnrtR0Sol_timeout_generic = NULL;
|
---|
52 | /** untimeout_generic address. */
|
---|
53 | PFNSOL_untimeout_generic g_pfnrtR0Sol_untimeout_generic = NULL;
|
---|
54 | /** cyclic_reprogram address. */
|
---|
55 | PFNSOL_cyclic_reprogram g_pfnrtR0Sol_cyclic_reprogram = NULL;
|
---|
56 | /** page_noreloc_supported address. */
|
---|
57 | PFNSOL_page_noreloc_supported g_pfnrtR0Sol_page_noreloc_supported = NULL;
|
---|
58 | /** Whether to use the kernel page freelist. */
|
---|
59 | bool g_frtSolUseKflt = false;
|
---|
60 | /** Whether we've completed R0 initialization. */
|
---|
61 | bool g_frtSolInitDone = false;
|
---|
62 | /** Whether to use old-style xc_call interface. */
|
---|
63 | bool g_frtSolOldIPI = false;
|
---|
64 | /** Whether to use old-style xc_call interface using one ulong_t as the CPU set
|
---|
65 | * representation. */
|
---|
66 | bool g_frtSolOldIPIUlong = false;
|
---|
67 | /** The xc_call callout table structure. */
|
---|
68 | RTR0FNSOLXCCALL g_rtSolXcCall;
|
---|
69 | /** Thread preemption offset. */
|
---|
70 | size_t g_offrtSolThreadPreempt;
|
---|
71 | /** Host scheduler preemption offset. */
|
---|
72 | size_t g_offrtSolCpuPreempt;
|
---|
73 | /** Host scheduler force preemption offset. */
|
---|
74 | size_t g_offrtSolCpuForceKernelPreempt;
|
---|
75 | /* Resolve using dl_lookup (remove if no longer relevant for supported S10 versions) */
|
---|
76 | extern void contig_free(void *addr, size_t size);
|
---|
77 | #pragma weak contig_free
|
---|
78 | /** contig_free address. */
|
---|
79 | PFNSOL_contig_free g_pfnrtR0Sol_contig_free = contig_free;
|
---|
80 |
|
---|
81 | DECLHIDDEN(int) rtR0InitNative(void)
|
---|
82 | {
|
---|
83 | /*
|
---|
84 | * IPRT has not yet been initialized at this point, so use Solaris' native cmn_err() for logging.
|
---|
85 | */
|
---|
86 | int rc = RTR0DbgKrnlInfoOpen(&g_hKrnlDbgInfo, 0 /* fFlags */);
|
---|
87 | if (RT_SUCCESS(rc))
|
---|
88 | {
|
---|
89 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
90 | /*
|
---|
91 | * Detect whether spl*() is preserving the interrupt flag or not.
|
---|
92 | * This is a problem on S10.
|
---|
93 | */
|
---|
94 | RTCCUINTREG uOldFlags = ASMIntDisableFlags();
|
---|
95 | int iOld = splr(DISP_LEVEL);
|
---|
96 | if (ASMIntAreEnabled())
|
---|
97 | g_frtSolSplSetsEIF = true;
|
---|
98 | splx(iOld);
|
---|
99 | if (ASMIntAreEnabled())
|
---|
100 | g_frtSolSplSetsEIF = true;
|
---|
101 | ASMSetFlags(uOldFlags);
|
---|
102 | #else
|
---|
103 | /* PORTME: See if the amd64/x86 problem applies to this architecture. */
|
---|
104 | #endif
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * Mandatory: Preemption offsets.
|
---|
108 | */
|
---|
109 | rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_runrun", &g_offrtSolCpuPreempt);
|
---|
110 | if (RT_FAILURE(rc))
|
---|
111 | {
|
---|
112 | cmn_err(CE_NOTE, "Failed to find cpu_t::cpu_runrun!\n");
|
---|
113 | goto errorbail;
|
---|
114 | }
|
---|
115 |
|
---|
116 | rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_kprunrun", &g_offrtSolCpuForceKernelPreempt);
|
---|
117 | if (RT_FAILURE(rc))
|
---|
118 | {
|
---|
119 | cmn_err(CE_NOTE, "Failed to find cpu_t::cpu_kprunrun!\n");
|
---|
120 | goto errorbail;
|
---|
121 | }
|
---|
122 |
|
---|
123 | rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_preempt", &g_offrtSolThreadPreempt);
|
---|
124 | if (RT_FAILURE(rc))
|
---|
125 | {
|
---|
126 | cmn_err(CE_NOTE, "Failed to find kthread_t::t_preempt!\n");
|
---|
127 | goto errorbail;
|
---|
128 | }
|
---|
129 | cmn_err(CE_CONT, "!cpu_t::cpu_runrun @ 0x%lx\n", g_offrtSolCpuPreempt);
|
---|
130 | cmn_err(CE_CONT, "!cpu_t::cpu_kprunrun @ 0x%lx\n", g_offrtSolCpuForceKernelPreempt);
|
---|
131 | cmn_err(CE_CONT, "!kthread_t::t_preempt @ 0x%lx\n", g_offrtSolThreadPreempt);
|
---|
132 |
|
---|
133 | /*
|
---|
134 | * Mandatory: CPU cross call infrastructure. Refer the-solaris-kernel.h for details.
|
---|
135 | */
|
---|
136 | rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "xc_init_cpu", NULL /* ppvSymbol */);
|
---|
137 | if (RT_SUCCESS(rc))
|
---|
138 | {
|
---|
139 | if (ncpus > IPRT_SOL_NCPUS)
|
---|
140 | {
|
---|
141 | cmn_err(CE_NOTE, "rtR0InitNative: CPU count mismatch! ncpus=%d IPRT_SOL_NCPUS=%d\n", ncpus, IPRT_SOL_NCPUS);
|
---|
142 | rc = VERR_NOT_SUPPORTED;
|
---|
143 | goto errorbail;
|
---|
144 | }
|
---|
145 | g_rtSolXcCall.u.pfnSol_xc_call = (void *)xc_call;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | g_frtSolOldIPI = true;
|
---|
150 | g_rtSolXcCall.u.pfnSol_xc_call_old = (void *)xc_call;
|
---|
151 | if (max_cpuid + 1 == sizeof(ulong_t) * 8)
|
---|
152 | {
|
---|
153 | g_frtSolOldIPIUlong = true;
|
---|
154 | g_rtSolXcCall.u.pfnSol_xc_call_old_ulong = (void *)xc_call;
|
---|
155 | }
|
---|
156 | else if (max_cpuid + 1 != IPRT_SOL_NCPUS)
|
---|
157 | {
|
---|
158 | cmn_err(CE_NOTE, "rtR0InitNative: cpuset_t size mismatch! max_cpuid=%d IPRT_SOL_NCPUS=%d\n", max_cpuid,
|
---|
159 | IPRT_SOL_NCPUS);
|
---|
160 | rc = VERR_NOT_SUPPORTED;
|
---|
161 | goto errorbail;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | /*
|
---|
166 | * Optional: Timeout hooks.
|
---|
167 | */
|
---|
168 | RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "timeout_generic",
|
---|
169 | (void **)&g_pfnrtR0Sol_timeout_generic);
|
---|
170 | RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "untimeout_generic",
|
---|
171 | (void **)&g_pfnrtR0Sol_untimeout_generic);
|
---|
172 | if ((g_pfnrtR0Sol_timeout_generic == NULL) != (g_pfnrtR0Sol_untimeout_generic == NULL))
|
---|
173 | {
|
---|
174 | static const char *s_apszFn[2] = { "timeout_generic", "untimeout_generic" };
|
---|
175 | bool iMissingFn = g_pfnrtR0Sol_timeout_generic == NULL;
|
---|
176 | cmn_err(CE_NOTE, "rtR0InitNative: Weird! Found %s but not %s!\n", s_apszFn[!iMissingFn], s_apszFn[iMissingFn]);
|
---|
177 | g_pfnrtR0Sol_timeout_generic = NULL;
|
---|
178 | g_pfnrtR0Sol_untimeout_generic = NULL;
|
---|
179 | }
|
---|
180 | RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "cyclic_reprogram",
|
---|
181 | (void **)&g_pfnrtR0Sol_cyclic_reprogram);
|
---|
182 |
|
---|
183 | /*
|
---|
184 | * Optional: Querying page no-relocation support.
|
---|
185 | */
|
---|
186 | RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /*pszModule */, "page_noreloc_supported",
|
---|
187 | (void **)&g_pfnrtR0Sol_page_noreloc_supported);
|
---|
188 |
|
---|
189 | /*
|
---|
190 | * Weak binding failures: contig_free
|
---|
191 | */
|
---|
192 | if (g_pfnrtR0Sol_contig_free == NULL)
|
---|
193 | {
|
---|
194 | rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "contig_free", (void **)&g_pfnrtR0Sol_contig_free);
|
---|
195 | if (RT_FAILURE(rc))
|
---|
196 | {
|
---|
197 | cmn_err(CE_NOTE, "rtR0InitNative: failed to find contig_free!\n");
|
---|
198 | goto errorbail;
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | g_frtSolInitDone = true;
|
---|
203 | return VINF_SUCCESS;
|
---|
204 | }
|
---|
205 | else
|
---|
206 | {
|
---|
207 | cmn_err(CE_NOTE, "RTR0DbgKrnlInfoOpen failed. rc=%d\n", rc);
|
---|
208 | return rc;
|
---|
209 | }
|
---|
210 |
|
---|
211 | errorbail:
|
---|
212 | RTR0DbgKrnlInfoRelease(g_hKrnlDbgInfo);
|
---|
213 | return rc;
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 | DECLHIDDEN(void) rtR0TermNative(void)
|
---|
218 | {
|
---|
219 | RTR0DbgKrnlInfoRelease(g_hKrnlDbgInfo);
|
---|
220 | g_frtSolInitDone = false;
|
---|
221 | }
|
---|
222 |
|
---|