1 | /* $Id: VBoxGuestR3LibCpuHotPlug.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, CPU Hot Plugging.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2024 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 "VBoxGuestR3LibInternal.h"
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include <iprt/errcore.h>
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Initialize CPU hot plugging.
|
---|
48 | *
|
---|
49 | * This will enable the CPU hot plugging events.
|
---|
50 | *
|
---|
51 | * @returns VBox status code.
|
---|
52 | */
|
---|
53 | VBGLR3DECL(int) VbglR3CpuHotPlugInit(void)
|
---|
54 | {
|
---|
55 | int rc = VbglR3CtlFilterMask(VMMDEV_EVENT_CPU_HOTPLUG, 0);
|
---|
56 | if (RT_FAILURE(rc))
|
---|
57 | return rc;
|
---|
58 |
|
---|
59 | VMMDevCpuHotPlugStatusRequest Req;
|
---|
60 | vmmdevInitRequest(&Req.header, VMMDevReq_SetCpuHotPlugStatus);
|
---|
61 | Req.enmStatusType = VMMDevCpuStatusType_Enable;
|
---|
62 | rc = vbglR3GRPerform(&Req.header);
|
---|
63 | if (RT_FAILURE(rc))
|
---|
64 | VbglR3CtlFilterMask(0, VMMDEV_EVENT_CPU_HOTPLUG);
|
---|
65 |
|
---|
66 | return rc;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Terminate CPU hot plugging.
|
---|
72 | *
|
---|
73 | * This will disable the CPU hot plugging events.
|
---|
74 | *
|
---|
75 | * @returns VBox status code.
|
---|
76 | */
|
---|
77 | VBGLR3DECL(int) VbglR3CpuHotPlugTerm(void)
|
---|
78 | {
|
---|
79 | /* Clear the events. */
|
---|
80 | VbglR3CtlFilterMask(0, VMMDEV_EVENT_CPU_HOTPLUG);
|
---|
81 |
|
---|
82 | VMMDevCpuHotPlugStatusRequest Req;
|
---|
83 | vmmdevInitRequest(&Req.header, VMMDevReq_SetCpuHotPlugStatus);
|
---|
84 | Req.enmStatusType = VMMDevCpuStatusType_Disable;
|
---|
85 | return vbglR3GRPerform(&Req.header);
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Waits for a CPU hot plugging event and retrieve the data associated with it.
|
---|
91 | *
|
---|
92 | * @returns VBox status code.
|
---|
93 | * @param penmEventType Where to store the event type on success.
|
---|
94 | * @param pidCpuCore Where to store the CPU core ID on success.
|
---|
95 | * @param pidCpuPackage Where to store the CPU package ID on success.
|
---|
96 | */
|
---|
97 | VBGLR3DECL(int) VbglR3CpuHotPlugWaitForEvent(VMMDevCpuEventType *penmEventType, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
|
---|
98 | {
|
---|
99 | AssertPtrReturn(penmEventType, VERR_INVALID_POINTER);
|
---|
100 | AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER);
|
---|
101 | AssertPtrReturn(pidCpuPackage, VERR_INVALID_POINTER);
|
---|
102 |
|
---|
103 | uint32_t fEvents = 0;
|
---|
104 | int rc = VbglR3WaitEvent(VMMDEV_EVENT_CPU_HOTPLUG, RT_INDEFINITE_WAIT, &fEvents);
|
---|
105 | if (RT_SUCCESS(rc))
|
---|
106 | {
|
---|
107 | /* did we get the right event? */
|
---|
108 | if (fEvents & VMMDEV_EVENT_CPU_HOTPLUG)
|
---|
109 | {
|
---|
110 | VMMDevGetCpuHotPlugRequest Req;
|
---|
111 |
|
---|
112 | /* get the CPU hot plugging request */
|
---|
113 | vmmdevInitRequest(&Req.header, VMMDevReq_GetCpuHotPlugRequest);
|
---|
114 | Req.idCpuCore = UINT32_MAX;
|
---|
115 | Req.idCpuPackage = UINT32_MAX;
|
---|
116 | Req.enmEventType = VMMDevCpuEventType_None;
|
---|
117 | rc = vbglR3GRPerform(&Req.header);
|
---|
118 | if (RT_SUCCESS(rc))
|
---|
119 | {
|
---|
120 | *penmEventType = Req.enmEventType;
|
---|
121 | *pidCpuCore = Req.idCpuCore;
|
---|
122 | *pidCpuPackage = Req.idCpuPackage;
|
---|
123 | return VINF_SUCCESS;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | else
|
---|
127 | rc = VERR_TRY_AGAIN;
|
---|
128 | }
|
---|
129 | else if (rc == VERR_TIMEOUT) /* just in case */
|
---|
130 | rc = VERR_TRY_AGAIN;
|
---|
131 | return rc;
|
---|
132 | }
|
---|
133 |
|
---|