1 | /* $Id: VBoxGuestR3LibCpuHotPlug.cpp 27083 2010-03-05 13:05:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, CPU Hot Plugging.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include "VBGLR3Internal.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Initialize CPU hot plugging.
|
---|
40 | *
|
---|
41 | * This will enable the CPU hot plugging events.
|
---|
42 | *
|
---|
43 | * @returns VBox status code.
|
---|
44 | */
|
---|
45 | VBGLR3DECL(int) VbglR3CpuHotPlugInit(void)
|
---|
46 | {
|
---|
47 | int rc = VbglR3CtlFilterMask(VMMDEV_EVENT_CPU_HOTPLUG, 0);
|
---|
48 | if (RT_FAILURE(rc))
|
---|
49 | return rc;
|
---|
50 |
|
---|
51 | VMMDevCpuHotPlugStatusRequest Req;
|
---|
52 | vmmdevInitRequest(&Req.header, VMMDevReq_SetCpuHotPlugStatus);
|
---|
53 | Req.enmStatusType = VMMDevCpuStatusType_Enable;
|
---|
54 | rc = vbglR3GRPerform(&Req.header);
|
---|
55 | if (RT_FAILURE(rc))
|
---|
56 | VbglR3CtlFilterMask(0, VMMDEV_EVENT_CPU_HOTPLUG);
|
---|
57 |
|
---|
58 | return rc;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Terminate CPU hot plugging.
|
---|
64 | *
|
---|
65 | * This will disable the CPU hot plugging events.
|
---|
66 | *
|
---|
67 | * @returns VBox status.
|
---|
68 | */
|
---|
69 | VBGLR3DECL(int) VbglR3CpuHotPlugTerm(void)
|
---|
70 | {
|
---|
71 | /* Clear the events. */
|
---|
72 | VbglR3CtlFilterMask(0, VMMDEV_EVENT_CPU_HOTPLUG);
|
---|
73 |
|
---|
74 | VMMDevCpuHotPlugStatusRequest Req;
|
---|
75 | vmmdevInitRequest(&Req.header, VMMDevReq_SetCpuHotPlugStatus);
|
---|
76 | Req.enmStatusType = VMMDevCpuStatusType_Disable;
|
---|
77 | return vbglR3GRPerform(&Req.header);
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Waits for a CPU hot plugging event and retrive the data associated with it.
|
---|
83 | *
|
---|
84 | * @returns VBox status code.
|
---|
85 | * @param penmEventType Where to store the event type on success.
|
---|
86 | * @param pidCpuCore Where to store the CPU core ID on success.
|
---|
87 | * @param pidCpuPackage Where to store the CPU package ID on success.
|
---|
88 | */
|
---|
89 | VBGLR3DECL(int) VbglR3CpuHotPlugWaitForEvent(VMMDevCpuEventType *penmEventType, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
|
---|
90 | {
|
---|
91 | AssertPtrReturn(penmEventType, VERR_INVALID_POINTER);
|
---|
92 | AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER);
|
---|
93 | AssertPtrReturn(pidCpuPackage, VERR_INVALID_POINTER);
|
---|
94 |
|
---|
95 | VBoxGuestWaitEventInfo waitEvent;
|
---|
96 | waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
|
---|
97 | waitEvent.u32EventMaskIn = VMMDEV_EVENT_CPU_HOTPLUG;
|
---|
98 | waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
|
---|
99 | waitEvent.u32EventFlagsOut = 0;
|
---|
100 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
|
---|
101 | if (RT_SUCCESS(rc))
|
---|
102 | {
|
---|
103 | /* did we get the right event? */
|
---|
104 | if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_CPU_HOTPLUG)
|
---|
105 | {
|
---|
106 | VMMDevGetCpuHotPlugRequest Req;
|
---|
107 |
|
---|
108 | /* get the CPU hot plugging request */
|
---|
109 | vmmdevInitRequest(&Req.header, VMMDevReq_GetCpuHotPlugRequest);
|
---|
110 | Req.idCpuCore = UINT32_MAX;
|
---|
111 | Req.idCpuPackage = UINT32_MAX;
|
---|
112 | Req.enmEventType = VMMDevCpuEventType_None;
|
---|
113 | rc = vbglR3GRPerform(&Req.header);
|
---|
114 | if (RT_SUCCESS(rc))
|
---|
115 | {
|
---|
116 | *penmEventType = Req.enmEventType;
|
---|
117 | *pidCpuCore = Req.idCpuCore;
|
---|
118 | *pidCpuPackage = Req.idCpuPackage;
|
---|
119 | return VINF_SUCCESS;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | else
|
---|
123 | rc = VERR_TRY_AGAIN;
|
---|
124 | }
|
---|
125 | return rc;
|
---|
126 | }
|
---|
127 |
|
---|