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