1 | /* $Id: mp-r0drv-haiku.c 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Multiprocessor, Ring-0 Driver, Haiku.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-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 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include "the-haiku-kernel.h"
|
---|
42 |
|
---|
43 | #include <iprt/mp.h>
|
---|
44 | #include <iprt/err.h>
|
---|
45 | #include <iprt/asm.h>
|
---|
46 | #include <iprt/cpuset.h>
|
---|
47 | #include "r0drv/mp-r0drv.h"
|
---|
48 |
|
---|
49 |
|
---|
50 | RTDECL(RTCPUID) RTMpCpuId(void)
|
---|
51 | {
|
---|
52 | return smp_get_current_cpu();
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | RTDECL(int) RTMpCurSetIndex(void)
|
---|
57 | {
|
---|
58 | return smp_get_current_cpu();
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | RTDECL(int) RTMpCurSetIndexAndId(PRTCPUID pidCpu)
|
---|
63 | {
|
---|
64 | return *pidCpu = smp_get_current_cpu();
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
|
---|
69 | {
|
---|
70 | return idCpu < smp_get_num_cpus() ? (int)idCpu : -1;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
|
---|
75 | {
|
---|
76 | return (unsigned)iCpu < smp_get_num_cpus() ? (RTCPUID)iCpu : NIL_RTCPUID;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
|
---|
81 | {
|
---|
82 | return smp_get_num_cpus() - 1;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
|
---|
87 | {
|
---|
88 | return idCpu < smp_get_num_cpus();
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
|
---|
93 | {
|
---|
94 | RTCPUID idCpu;
|
---|
95 |
|
---|
96 | RTCpuSetEmpty(pSet);
|
---|
97 | idCpu = RTMpGetMaxCpuId();
|
---|
98 | do
|
---|
99 | {
|
---|
100 | if (RTMpIsCpuPossible(idCpu))
|
---|
101 | RTCpuSetAdd(pSet, idCpu);
|
---|
102 | } while (idCpu-- > 0);
|
---|
103 | return pSet;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | RTDECL(RTCPUID) RTMpGetCount(void)
|
---|
108 | {
|
---|
109 | return smp_get_num_cpus();
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
|
---|
114 | {
|
---|
115 | return idCpu < smp_get_num_cpus();
|
---|
116 | /** @todo FixMe && !CPU_ABSENT(idCpu) */
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
|
---|
121 | {
|
---|
122 | RTCPUID idCpu;
|
---|
123 |
|
---|
124 | RTCpuSetEmpty(pSet);
|
---|
125 | idCpu = RTMpGetMaxCpuId();
|
---|
126 | do
|
---|
127 | {
|
---|
128 | if (RTMpIsCpuOnline(idCpu))
|
---|
129 | RTCpuSetAdd(pSet, idCpu);
|
---|
130 | } while (idCpu-- > 0);
|
---|
131 |
|
---|
132 | return pSet;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | RTDECL(RTCPUID) RTMpGetOnlineCount(void)
|
---|
137 | {
|
---|
138 | return smp_get_num_cpus();
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Wrapper between the native Haiku per-cpu callback and PFNRTWORKER
|
---|
144 | * for the RTMpOnAll API.
|
---|
145 | *
|
---|
146 | * @param pvArg Pointer to the RTMPARGS package.
|
---|
147 | */
|
---|
148 | static void rtmpOnAllHaikuWrapper(void *pvArg, int current)
|
---|
149 | {
|
---|
150 | PRTMPARGS pArgs = (PRTMPARGS)pvArg;
|
---|
151 | pArgs->pfnWorker(current, pArgs->pvUser1, pArgs->pvUser2);
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
156 | {
|
---|
157 | RTMPARGS Args;
|
---|
158 | Args.pfnWorker = pfnWorker;
|
---|
159 | Args.pvUser1 = pvUser1;
|
---|
160 | Args.pvUser2 = pvUser2;
|
---|
161 | Args.idCpu = NIL_RTCPUID;
|
---|
162 | Args.cHits = 0;
|
---|
163 | /* is _sync needed ? */
|
---|
164 | call_all_cpus_sync(rtmpOnAllHaikuWrapper, &Args);
|
---|
165 | return VINF_SUCCESS;
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Wrapper between the native Haiku per-cpu callback and PFNRTWORKER
|
---|
171 | * for the RTMpOnOthers API.
|
---|
172 | *
|
---|
173 | * @param pvArg Pointer to the RTMPARGS package.
|
---|
174 | */
|
---|
175 | static void rtmpOnOthersHaikuWrapper(void *pvArg, int current)
|
---|
176 | {
|
---|
177 | PRTMPARGS pArgs = (PRTMPARGS)pvArg;
|
---|
178 | RTCPUID idCpu = current;
|
---|
179 | if (pArgs->idCpu != idCpu)
|
---|
180 | pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
185 | {
|
---|
186 | /* Will panic if no rendezvousing cpus, so check up front. */
|
---|
187 | if (RTMpGetOnlineCount() > 1)
|
---|
188 | {
|
---|
189 | RTMPARGS Args;
|
---|
190 |
|
---|
191 | Args.pfnWorker = pfnWorker;
|
---|
192 | Args.pvUser1 = pvUser1;
|
---|
193 | Args.pvUser2 = pvUser2;
|
---|
194 | Args.idCpu = RTMpCpuId();
|
---|
195 | Args.cHits = 0;
|
---|
196 | /* is _sync needed ? */
|
---|
197 | call_all_cpus_sync(rtmpOnOthersHaikuWrapper, &Args);
|
---|
198 | }
|
---|
199 | return VINF_SUCCESS;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Wrapper between the native Haiku per-cpu callback and PFNRTWORKER
|
---|
205 | * for the RTMpOnSpecific API.
|
---|
206 | *
|
---|
207 | * @param pvArg Pointer to the RTMPARGS package.
|
---|
208 | */
|
---|
209 | static void rtmpOnSpecificHaikuWrapper(void *pvArg, int current)
|
---|
210 | {
|
---|
211 | PRTMPARGS pArgs = (PRTMPARGS)pvArg;
|
---|
212 | RTCPUID idCpu = current;
|
---|
213 | if (pArgs->idCpu == idCpu)
|
---|
214 | {
|
---|
215 | pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
|
---|
216 | ASMAtomicIncU32(&pArgs->cHits);
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
222 | {
|
---|
223 | RTMPARGS Args;
|
---|
224 |
|
---|
225 | /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
|
---|
226 | if (!RTMpIsCpuOnline(idCpu))
|
---|
227 | return VERR_CPU_NOT_FOUND;
|
---|
228 |
|
---|
229 | Args.pfnWorker = pfnWorker;
|
---|
230 | Args.pvUser1 = pvUser1;
|
---|
231 | Args.pvUser2 = pvUser2;
|
---|
232 | Args.idCpu = idCpu;
|
---|
233 | Args.cHits = 0;
|
---|
234 | /* is _sync needed ? */
|
---|
235 | call_all_cpus_sync(rtmpOnSpecificHaikuWrapper, &Args);
|
---|
236 | return Args.cHits == 1
|
---|
237 | ? VINF_SUCCESS
|
---|
238 | : VERR_CPU_NOT_FOUND;
|
---|
239 | }
|
---|
240 |
|
---|
241 |
|
---|
242 | RTDECL(bool) RTMpOnAllIsConcurrentSafe(void)
|
---|
243 | {
|
---|
244 | return true;
|
---|
245 | }
|
---|
246 |
|
---|