VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/haiku/mp-r0drv-haiku.c@ 45733

Last change on this file since 45733 was 43373, checked in by vboxsync, 12 years ago

Additions/Haiku: missed commits.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette