VirtualBox

source: vbox/trunk/src/VBox/VMM/PDM.cpp@ 34347

Last change on this file since 34347 was 34347, checked in by vboxsync, 14 years ago

BlkCache: Suspend the VM if an error occurs during a write

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 75.8 KB
Line 
1/* $Id: PDM.cpp 34347 2010-11-24 22:34:21Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device Manager.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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
18
19/** @page pg_pdm PDM - The Pluggable Device & Driver Manager
20 *
21 * VirtualBox is designed to be very configurable, i.e. the ability to select
22 * virtual devices and configure them uniquely for a VM. For this reason
23 * virtual devices are not statically linked with the VMM but loaded, linked and
24 * instantiated at runtime by PDM using the information found in the
25 * Configuration Manager (CFGM).
26 *
27 * While the chief purpose of PDM is to manager of devices their drivers, it
28 * also serves as somewhere to put usful things like cross context queues, cross
29 * context synchronization (like critsect), VM centric thread management,
30 * asynchronous I/O framework, and so on.
31 *
32 * @see grp_pdm
33 *
34 *
35 * @section sec_pdm_dev The Pluggable Devices
36 *
37 * Devices register themselves when the module containing them is loaded. PDM
38 * will call the entry point 'VBoxDevicesRegister' when loading a device module.
39 * The device module will then use the supplied callback table to check the VMM
40 * version and to register its devices. Each device have an unique (for the
41 * configured VM) name. The name is not only used in PDM but also in CFGM (to
42 * organize device and device instance settings) and by anyone who wants to talk
43 * to a specific device instance.
44 *
45 * When all device modules have been successfully loaded PDM will instantiate
46 * those devices which are configured for the VM. Note that a device may have
47 * more than one instance, see network adaptors for instance. When
48 * instantiating a device PDM provides device instance memory and a callback
49 * table (aka Device Helpers / DevHlp) with the VM APIs which the device
50 * instance is trusted with.
51 *
52 * Some devices are trusted devices, most are not. The trusted devices are an
53 * integrated part of the VM and can obtain the VM handle from their device
54 * instance handles, thus enabling them to call any VM api. Untrusted devices
55 * can only use the callbacks provided during device instantiation.
56 *
57 * The main purpose in having DevHlps rather than just giving all the devices
58 * the VM handle and let them call the internal VM APIs directly, is both to
59 * create a binary interface that can be supported across releases and to
60 * create a barrier between devices and the VM. (The trusted / untrusted bit
61 * hasn't turned out to be of much use btw., but it's easy to maintain so there
62 * isn't any point in removing it.)
63 *
64 * A device can provide a ring-0 and/or a raw-mode context extension to improve
65 * the VM performance by handling exits and traps (respectively) without
66 * requiring context switches (to ring-3). Callbacks for MMIO and I/O ports can
67 * needs to be registered specifically for the additional contexts for this to
68 * make sense. Also, the device has to be trusted to be loaded into R0/RC
69 * because of the extra privilege it entails. Note that raw-mode code and data
70 * will be subject to relocation.
71 *
72 *
73 * @section sec_pdm_special_devs Special Devices
74 *
75 * Several kinds of devices interacts with the VMM and/or other device and PDM
76 * will work like a mediator for these. The typical pattern is that the device
77 * calls a special registration device helper with a set of callbacks, PDM
78 * responds by copying this and providing a pointer to a set helper callbacks
79 * for that particular kind of device. Unlike interfaces where the callback
80 * table pointer is used a 'this' pointer, these arrangements will use the
81 * device instance pointer (PPDMDEVINS) as a kind of 'this' pointer.
82 *
83 * For an example of this kind of setup, see the PIC. The PIC registers itself
84 * by calling PDMDEVHLPR3::pfnPICRegister. PDM saves the device instance,
85 * copies the callback tables (PDMPICREG), resolving the ring-0 and raw-mode
86 * addresses in the process, and hands back the pointer to a set of helper
87 * methods (PDMPICHLPR3). The PCI device then queries the ring-0 and raw-mode
88 * helpers using PDMPICHLPR3::pfnGetR0Helpers and PDMPICHLPR3::pfnGetRCHelpers.
89 * The PCI device repeats ths pfnGetRCHelpers call in it's relocation method
90 * since the address changes when RC is relocated.
91 *
92 * @see grp_pdm_device
93 *
94 *
95 * @section sec_pdm_usbdev The Pluggable USB Devices
96 *
97 * USB devices are handled a little bit differently than other devices. The
98 * general concepts wrt. pluggability are mostly the same, but the details
99 * varies. The registration entry point is 'VBoxUsbRegister', the device
100 * instance is PDMUSBINS and the callbacks helpers are different. Also, USB
101 * device are restricted to ring-3 and cannot have any ring-0 or raw-mode
102 * extensions (at least not yet).
103 *
104 * The way USB devices work differs greatly from other devices though since they
105 * aren't attaches directly to the PCI/ISA/whatever system buses but via a
106 * USB host control (OHCI, UHCI or EHCI). USB devices handles USB requests
107 * (URBs) and does not register I/O ports, MMIO ranges or PCI bus
108 * devices/functions.
109 *
110 * @see grp_pdm_usbdev
111 *
112 *
113 * @section sec_pdm_drv The Pluggable Drivers
114 *
115 * The VM devices are often accessing host hardware or OS facilities. For most
116 * devices these facilities can be abstracted in one or more levels. These
117 * abstractions are called drivers.
118 *
119 * For instance take a DVD/CD drive. This can be connected to a SCSI
120 * controller, an ATA controller or a SATA controller. The basics of the DVD/CD
121 * drive implementation remains the same - eject, insert, read, seek, and such.
122 * (For the scsi case, you might wanna speak SCSI directly to, but that can of
123 * course be fixed - see SCSI passthru.) So, it
124 * makes much sense to have a generic CD/DVD driver which implements this.
125 *
126 * Then the media 'inserted' into the DVD/CD drive can be a ISO image, or it can
127 * be read from a real CD or DVD drive (there are probably other custom formats
128 * someone could desire to read or construct too). So, it would make sense to
129 * have abstracted interfaces for dealing with this in a generic way so the
130 * cdrom unit doesn't have to implement it all. Thus we have created the
131 * CDROM/DVD media driver family.
132 *
133 * So, for this example the IDE controller #1 (i.e. secondary) will have
134 * the DVD/CD Driver attached to it's LUN #0 (master). When a media is mounted
135 * the DVD/CD Driver will have a ISO, HostDVD or RAW (media) Driver attached.
136 *
137 * It is possible to configure many levels of drivers inserting filters, loggers,
138 * or whatever you desire into the chain. We're using this for network sniffing
139 * for instance.
140 *
141 * The drivers are loaded in a similar manner to that of the device, namely by
142 * iterating a keyspace in CFGM, load the modules listed there and call
143 * 'VBoxDriversRegister' with a callback table.
144 *
145 * @see grp_pdm_driver
146 *
147 *
148 * @section sec_pdm_ifs Interfaces
149 *
150 * The pluggable drivers and devices exposes one standard interface (callback
151 * table) which is used to construct, destruct, attach, detach,( ++,) and query
152 * other interfaces. A device will query the interfaces required for it's
153 * operation during init and hot-plug. PDM may query some interfaces during
154 * runtime mounting too.
155 *
156 * An interface here means a function table contained within the device or
157 * driver instance data. Its method are invoked with the function table pointer
158 * as the first argument and they will calculate the address of the device or
159 * driver instance data from it. (This is one of the aspects which *might* have
160 * been better done in C++.)
161 *
162 * @see grp_pdm_interfaces
163 *
164 *
165 * @section sec_pdm_utils Utilities
166 *
167 * As mentioned earlier, PDM is the location of any usful constructs that doesn't
168 * quite fit into IPRT. The next subsections will discuss these.
169 *
170 * One thing these APIs all have in common is that resources will be associated
171 * with a device / driver and automatically freed after it has been destroyed if
172 * the destructor didn't do this.
173 *
174 *
175 * @subsection sec_pdm_async_completion Async I/O
176 *
177 * The PDM Async I/O API provides a somewhat platform agnostic interface for
178 * asynchronous I/O. For reasons of performance and complexity this does not
179 * build upon any IPRT API.
180 *
181 * @todo more details.
182 *
183 * @see grp_pdm_async_completion
184 *
185 *
186 * @subsection sec_pdm_async_task Async Task - not implemented
187 *
188 * @todo implement and describe
189 *
190 * @see grp_pdm_async_task
191 *
192 *
193 * @subsection sec_pdm_critsect Critical Section
194 *
195 * The PDM Critical Section API is currently building on the IPRT API with the
196 * same name. It adds the possibility to use critical sections in ring-0 and
197 * raw-mode as well as in ring-3. There are certain restrictions on the RC and
198 * R0 usage though since we're not able to wait on it, nor wake up anyone that
199 * is waiting on it. These restrictions origins with the use of a ring-3 event
200 * semaphore. In a later incarnation we plan to replace the ring-3 event
201 * semaphore with a ring-0 one, thus enabling us to wake up waiters while
202 * exectuing in ring-0 and making the hardware assisted execution mode more
203 * efficient. (Raw-mode won't benefit much from this, naturally.)
204 *
205 * @see grp_pdm_critsect
206 *
207 *
208 * @subsection sec_pdm_queue Queue
209 *
210 * The PDM Queue API is for queuing one or more tasks for later consumption in
211 * ring-3 by EMT, and optionally forcing a delayed or ASAP return to ring-3. The
212 * queues can also be run on a timer basis as an alternative to the ASAP thing.
213 * The queue will be flushed at forced action time.
214 *
215 * A queue can also be used by another thread (a I/O worker for instance) to
216 * send work / events over to the EMT.
217 *
218 * @see grp_pdm_queue
219 *
220 *
221 * @subsection sec_pdm_task Task - not implemented yet
222 *
223 * The PDM Task API is for flagging a task for execution at a later point when
224 * we're back in ring-3, optionally forcing the ring-3 return to happen ASAP.
225 * As you can see the concept is similar to queues only simpler.
226 *
227 * A task can also be scheduled by another thread (a I/O worker for instance) as
228 * a mean of getting something done in EMT.
229 *
230 * @see grp_pdm_task
231 *
232 *
233 * @subsection sec_pdm_thread Thread
234 *
235 * The PDM Thread API is there to help devices and drivers manage their threads
236 * correctly wrt. power on, suspend, resume, power off and destruction.
237 *
238 * The general usage pattern for threads in the employ of devices and drivers is
239 * that they shuffle data or requests while the VM is running and stop doing
240 * this when the VM is paused or powered down. Rogue threads running while the
241 * VM is paused can cause the state to change during saving or have other
242 * unwanted side effects. The PDM Threads API ensures that this won't happen.
243 *
244 * @see grp_pdm_thread
245 *
246 */
247
248
249/*******************************************************************************
250* Header Files *
251*******************************************************************************/
252#define LOG_GROUP LOG_GROUP_PDM
253#include "PDMInternal.h"
254#include <VBox/pdm.h>
255#include <VBox/mm.h>
256#include <VBox/pgm.h>
257#include <VBox/ssm.h>
258#include <VBox/vm.h>
259#include <VBox/uvm.h>
260#include <VBox/vmm.h>
261#include <VBox/param.h>
262#include <VBox/err.h>
263#include <VBox/sup.h>
264
265#include <VBox/log.h>
266#include <iprt/asm.h>
267#include <iprt/assert.h>
268#include <iprt/alloc.h>
269#include <iprt/ldr.h>
270#include <iprt/path.h>
271#include <iprt/string.h>
272
273
274/*******************************************************************************
275* Defined Constants And Macros *
276*******************************************************************************/
277/** The PDM saved state version. */
278#define PDM_SAVED_STATE_VERSION 4
279#define PDM_SAVED_STATE_VERSION_PRE_NMI_FF 3
280
281
282/*******************************************************************************
283* Internal Functions *
284*******************************************************************************/
285static DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass);
286static DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM);
287static DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
288static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
289
290
291
292/**
293 * Initializes the PDM part of the UVM.
294 *
295 * This doesn't really do much right now but has to be here for the sake
296 * of completeness.
297 *
298 * @returns VBox status code.
299 * @param pUVM Pointer to the user mode VM structure.
300 */
301VMMR3DECL(int) PDMR3InitUVM(PUVM pUVM)
302{
303 AssertCompile(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
304 AssertRelease(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
305 pUVM->pdm.s.pModules = NULL;
306 pUVM->pdm.s.pCritSects = NULL;
307 return RTCritSectInit(&pUVM->pdm.s.ListCritSect);
308}
309
310
311/**
312 * Initializes the PDM.
313 *
314 * @returns VBox status code.
315 * @param pVM The VM to operate on.
316 */
317VMMR3DECL(int) PDMR3Init(PVM pVM)
318{
319 LogFlow(("PDMR3Init\n"));
320
321 /*
322 * Assert alignment and sizes.
323 */
324 AssertRelease(!(RT_OFFSETOF(VM, pdm.s) & 31));
325 AssertRelease(sizeof(pVM->pdm.s) <= sizeof(pVM->pdm.padding));
326 AssertCompileMemberAlignment(PDM, CritSect, sizeof(uintptr_t));
327 /*
328 * Init the structure.
329 */
330 pVM->pdm.s.offVM = RT_OFFSETOF(VM, pdm.s);
331 pVM->pdm.s.GCPhysVMMDevHeap = NIL_RTGCPHYS;
332
333 /*
334 * Initialize sub components.
335 */
336 int rc = pdmR3CritSectInitStats(pVM);
337 if (RT_SUCCESS(rc))
338 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, RT_SRC_POS, "PDM");
339 if (RT_SUCCESS(rc))
340 rc = pdmR3LdrInitU(pVM->pUVM);
341#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
342 if (RT_SUCCESS(rc))
343 rc = pdmR3AsyncCompletionInit(pVM);
344#endif
345 if (RT_SUCCESS(rc))
346 rc = pdmR3BlkCacheInit(pVM);
347 if (RT_SUCCESS(rc))
348 rc = pdmR3DrvInit(pVM);
349 if (RT_SUCCESS(rc))
350 rc = pdmR3DevInit(pVM);
351 if (RT_SUCCESS(rc))
352 {
353 /*
354 * Register the saved state data unit.
355 */
356 rc = SSMR3RegisterInternal(pVM, "pdm", 1, PDM_SAVED_STATE_VERSION, 128,
357 NULL, pdmR3LiveExec, NULL,
358 NULL, pdmR3SaveExec, NULL,
359 pdmR3LoadPrep, pdmR3LoadExec, NULL);
360 if (RT_SUCCESS(rc))
361 {
362 LogFlow(("PDM: Successfully initialized\n"));
363 return rc;
364 }
365 }
366
367 /*
368 * Cleanup and return failure.
369 */
370 PDMR3Term(pVM);
371 LogFlow(("PDMR3Init: returns %Rrc\n", rc));
372 return rc;
373}
374
375
376/**
377 * Applies relocations to data and code managed by this
378 * component. This function will be called at init and
379 * whenever the VMM need to relocate it self inside the GC.
380 *
381 * @param pVM VM handle.
382 * @param offDelta Relocation delta relative to old location.
383 * @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
384 * early in the relocation phase.
385 */
386VMMR3DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
387{
388 LogFlow(("PDMR3Relocate\n"));
389
390 /*
391 * Queues.
392 */
393 pdmR3QueueRelocate(pVM, offDelta);
394 pVM->pdm.s.pDevHlpQueueRC = PDMQueueRCPtr(pVM->pdm.s.pDevHlpQueueR3);
395
396 /*
397 * Critical sections.
398 */
399 pdmR3CritSectRelocate(pVM);
400
401 /*
402 * The registered PIC.
403 */
404 if (pVM->pdm.s.Pic.pDevInsRC)
405 {
406 pVM->pdm.s.Pic.pDevInsRC += offDelta;
407 pVM->pdm.s.Pic.pfnSetIrqRC += offDelta;
408 pVM->pdm.s.Pic.pfnGetInterruptRC += offDelta;
409 }
410
411 /*
412 * The registered APIC.
413 */
414 if (pVM->pdm.s.Apic.pDevInsRC)
415 {
416 pVM->pdm.s.Apic.pDevInsRC += offDelta;
417 pVM->pdm.s.Apic.pfnGetInterruptRC += offDelta;
418 pVM->pdm.s.Apic.pfnSetBaseRC += offDelta;
419 pVM->pdm.s.Apic.pfnGetBaseRC += offDelta;
420 pVM->pdm.s.Apic.pfnSetTPRRC += offDelta;
421 pVM->pdm.s.Apic.pfnGetTPRRC += offDelta;
422 pVM->pdm.s.Apic.pfnBusDeliverRC += offDelta;
423 if (pVM->pdm.s.Apic.pfnLocalInterruptRC)
424 pVM->pdm.s.Apic.pfnLocalInterruptRC += offDelta;
425 pVM->pdm.s.Apic.pfnWriteMSRRC += offDelta;
426 pVM->pdm.s.Apic.pfnReadMSRRC += offDelta;
427 }
428
429 /*
430 * The registered I/O APIC.
431 */
432 if (pVM->pdm.s.IoApic.pDevInsRC)
433 {
434 pVM->pdm.s.IoApic.pDevInsRC += offDelta;
435 pVM->pdm.s.IoApic.pfnSetIrqRC += offDelta;
436 }
437
438 /*
439 * The register PCI Buses.
440 */
441 for (unsigned i = 0; i < RT_ELEMENTS(pVM->pdm.s.aPciBuses); i++)
442 {
443 if (pVM->pdm.s.aPciBuses[i].pDevInsRC)
444 {
445 pVM->pdm.s.aPciBuses[i].pDevInsRC += offDelta;
446 pVM->pdm.s.aPciBuses[i].pfnSetIrqRC += offDelta;
447 }
448 }
449
450 /*
451 * Devices & Drivers.
452 */
453 PCPDMDEVHLPRC pDevHlpRC;
454 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDevHlp", &pDevHlpRC);
455 AssertReleaseMsgRC(rc, ("rc=%Rrc when resolving g_pdmRCDevHlp\n", rc));
456
457 PCPDMDRVHLPRC pDrvHlpRC;
458 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDevHlp", &pDrvHlpRC);
459 AssertReleaseMsgRC(rc, ("rc=%Rrc when resolving g_pdmRCDevHlp\n", rc));
460
461 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
462 {
463 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
464 {
465 pDevIns->pHlpRC = pDevHlpRC;
466 pDevIns->pvInstanceDataRC = MMHyperR3ToRC(pVM, pDevIns->pvInstanceDataR3);
467 if (pDevIns->pCritSectR3)
468 pDevIns->pCritSectRC = MMHyperR3ToRC(pVM, pDevIns->pCritSectR3);
469 pDevIns->Internal.s.pVMRC = pVM->pVMRC;
470 if (pDevIns->Internal.s.pPciBusR3)
471 pDevIns->Internal.s.pPciBusRC = MMHyperR3ToRC(pVM, pDevIns->Internal.s.pPciBusR3);
472 if (pDevIns->Internal.s.pPciDeviceR3)
473 pDevIns->Internal.s.pPciDeviceRC = MMHyperR3ToRC(pVM, pDevIns->Internal.s.pPciDeviceR3);
474 if (pDevIns->pReg->pfnRelocate)
475 {
476 LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
477 pDevIns->pReg->szName, pDevIns->iInstance));
478 pDevIns->pReg->pfnRelocate(pDevIns, offDelta);
479 }
480 }
481
482 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
483 {
484 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
485 {
486 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
487 {
488 pDrvIns->pHlpRC = pDrvHlpRC;
489 pDrvIns->pvInstanceDataRC = MMHyperR3ToRC(pVM, pDrvIns->pvInstanceDataR3);
490 pDrvIns->Internal.s.pVMRC = pVM->pVMRC;
491 if (pDrvIns->pReg->pfnRelocate)
492 {
493 LogFlow(("PDMR3Relocate: Relocating driver '%s'/%u attached to '%s'/%d/%u\n",
494 pDrvIns->pReg->szName, pDrvIns->iInstance,
495 pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun));
496 pDrvIns->pReg->pfnRelocate(pDrvIns, offDelta);
497 }
498 }
499 }
500 }
501
502 }
503}
504
505
506/**
507 * Worker for pdmR3Term that terminates a LUN chain.
508 *
509 * @param pVM Pointer to the shared VM structure.
510 * @param pLun The head of the chain.
511 * @param pszDevice The name of the device (for logging).
512 * @param iInstance The device instance number (for logging).
513 */
514static void pdmR3TermLuns(PVM pVM, PPDMLUN pLun, const char *pszDevice, unsigned iInstance)
515{
516 for (; pLun; pLun = pLun->pNext)
517 {
518 /*
519 * Destroy them one at a time from the bottom up.
520 * (The serial device/drivers depends on this - bad.)
521 */
522 PPDMDRVINS pDrvIns = pLun->pBottom;
523 pLun->pBottom = pLun->pTop = NULL;
524 while (pDrvIns)
525 {
526 PPDMDRVINS pDrvNext = pDrvIns->Internal.s.pUp;
527
528 if (pDrvIns->pReg->pfnDestruct)
529 {
530 LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
531 pDrvIns->pReg->szName, pDrvIns->iInstance, pLun->iLun, pszDevice, iInstance));
532 pDrvIns->pReg->pfnDestruct(pDrvIns);
533 }
534 pDrvIns->Internal.s.pDrv->cInstances--;
535
536 TMR3TimerDestroyDriver(pVM, pDrvIns);
537 //PDMR3QueueDestroyDriver(pVM, pDrvIns);
538 //pdmR3ThreadDestroyDriver(pVM, pDrvIns);
539 SSMR3DeregisterDriver(pVM, pDrvIns, NULL, 0);
540
541 pDrvIns = pDrvNext;
542 }
543 }
544}
545
546
547/**
548 * Terminates the PDM.
549 *
550 * Termination means cleaning up and freeing all resources,
551 * the VM it self is at this point powered off or suspended.
552 *
553 * @returns VBox status code.
554 * @param pVM The VM to operate on.
555 */
556VMMR3DECL(int) PDMR3Term(PVM pVM)
557{
558 LogFlow(("PDMR3Term:\n"));
559 AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n"));
560
561 /*
562 * Iterate the device instances and attach drivers, doing
563 * relevant destruction processing.
564 *
565 * N.B. There is no need to mess around freeing memory allocated
566 * from any MM heap since MM will do that in its Term function.
567 */
568 /* usb ones first. */
569 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
570 {
571 pdmR3TermLuns(pVM, pUsbIns->Internal.s.pLuns, pUsbIns->pReg->szName, pUsbIns->iInstance);
572
573 if (pUsbIns->pReg->pfnDestruct)
574 {
575 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
576 pUsbIns->pReg->szName, pUsbIns->iInstance));
577 pUsbIns->pReg->pfnDestruct(pUsbIns);
578 }
579
580 //TMR3TimerDestroyUsb(pVM, pUsbIns);
581 //SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
582 pdmR3ThreadDestroyUsb(pVM, pUsbIns);
583 }
584
585 /* then the 'normal' ones. */
586 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
587 {
588 pdmR3TermLuns(pVM, pDevIns->Internal.s.pLunsR3, pDevIns->pReg->szName, pDevIns->iInstance);
589
590 if (pDevIns->pReg->pfnDestruct)
591 {
592 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
593 pDevIns->pReg->szName, pDevIns->iInstance));
594 pDevIns->pReg->pfnDestruct(pDevIns);
595 }
596
597 TMR3TimerDestroyDevice(pVM, pDevIns);
598 //SSMR3DeregisterDriver(pVM, pDevIns, NULL, 0);
599 pdmR3CritSectDeleteDevice(pVM, pDevIns);
600 //pdmR3ThreadDestroyDevice(pVM, pDevIns);
601 //PDMR3QueueDestroyDevice(pVM, pDevIns);
602 PGMR3PhysMMIO2Deregister(pVM, pDevIns, UINT32_MAX);
603 }
604
605 /*
606 * Destroy all threads.
607 */
608 pdmR3ThreadDestroyAll(pVM);
609
610 /*
611 * Destroy the block cache.
612 */
613 pdmR3BlkCacheTerm(pVM);
614
615#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
616 /*
617 * Free async completion managers.
618 */
619 pdmR3AsyncCompletionTerm(pVM);
620#endif
621
622 /*
623 * Free modules.
624 */
625 pdmR3LdrTermU(pVM->pUVM);
626
627 /*
628 * Destroy the PDM lock.
629 */
630 PDMR3CritSectDelete(&pVM->pdm.s.CritSect);
631 /* The MiscCritSect is deleted by PDMR3CritSectTerm. */
632
633 LogFlow(("PDMR3Term: returns %Rrc\n", VINF_SUCCESS));
634 return VINF_SUCCESS;
635}
636
637
638/**
639 * Terminates the PDM part of the UVM.
640 *
641 * This will unload any modules left behind.
642 *
643 * @param pUVM Pointer to the user mode VM structure.
644 */
645VMMR3DECL(void) PDMR3TermUVM(PUVM pUVM)
646{
647 /*
648 * In the normal cause of events we will now call pdmR3LdrTermU for
649 * the second time. In the case of init failure however, this might
650 * the first time, which is why we do it.
651 */
652 pdmR3LdrTermU(pUVM);
653
654 Assert(pUVM->pdm.s.pCritSects == NULL);
655 RTCritSectDelete(&pUVM->pdm.s.ListCritSect);
656}
657
658
659/**
660 * Bits that are saved in pass 0 and in the final pass.
661 *
662 * @param pVM The VM handle.
663 * @param pSSM The saved state handle.
664 */
665static void pdmR3SaveBoth(PVM pVM, PSSMHANDLE pSSM)
666{
667 /*
668 * Save the list of device instances so we can check that they're all still
669 * there when we load the state and that nothing new has been added.
670 */
671 uint32_t i = 0;
672 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3, i++)
673 {
674 SSMR3PutU32(pSSM, i);
675 SSMR3PutStrZ(pSSM, pDevIns->pReg->szName);
676 SSMR3PutU32(pSSM, pDevIns->iInstance);
677 }
678 SSMR3PutU32(pSSM, UINT32_MAX); /* terminator */
679}
680
681
682/**
683 * Live save.
684 *
685 * @returns VBox status code.
686 * @param pVM The VM handle.
687 * @param pSSM The saved state handle.
688 * @param uPass The pass.
689 */
690static DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass)
691{
692 LogFlow(("pdmR3LiveExec:\n"));
693 AssertReturn(uPass == 0, VERR_INTERNAL_ERROR_4);
694 pdmR3SaveBoth(pVM, pSSM);
695 return VINF_SSM_DONT_CALL_AGAIN;
696}
697
698
699/**
700 * Execute state save operation.
701 *
702 * @returns VBox status code.
703 * @param pVM The VM handle.
704 * @param pSSM The saved state handle.
705 */
706static DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM)
707{
708 LogFlow(("pdmR3SaveExec:\n"));
709
710 /*
711 * Save interrupt and DMA states.
712 */
713 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
714 {
715 PVMCPU pVCpu = &pVM->aCpus[idCpu];
716 SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC));
717 SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC));
718 SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_NMI));
719 SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_SMI));
720 }
721 SSMR3PutU32(pSSM, VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
722
723 pdmR3SaveBoth(pVM, pSSM);
724 return VINF_SUCCESS;
725}
726
727
728/**
729 * Prepare state load operation.
730 *
731 * This will dispatch pending operations and clear the FFs governed by PDM and its devices.
732 *
733 * @returns VBox status code.
734 * @param pVM The VM handle.
735 * @param pSSM The SSM handle.
736 */
737static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
738{
739 LogFlow(("pdmR3LoadPrep: %s%s\n",
740 VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
741 VM_FF_ISSET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : ""));
742#ifdef LOG_ENABLED
743 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
744 {
745 PVMCPU pVCpu = &pVM->aCpus[idCpu];
746 LogFlow(("pdmR3LoadPrep: VCPU %u %s%s\n", idCpu,
747 VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC) ? " VMCPU_FF_INTERRUPT_APIC" : "",
748 VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC) ? " VMCPU_FF_INTERRUPT_PIC" : ""));
749 }
750#endif
751
752 /*
753 * In case there is work pending that will raise an interrupt,
754 * start a DMA transfer, or release a lock. (unlikely)
755 */
756 if (VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES))
757 PDMR3QueueFlushAll(pVM);
758
759 /* Clear the FFs. */
760 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
761 {
762 PVMCPU pVCpu = &pVM->aCpus[idCpu];
763 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
764 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
765 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
766 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
767 }
768 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
769
770 return VINF_SUCCESS;
771}
772
773
774/**
775 * Execute state load operation.
776 *
777 * @returns VBox status code.
778 * @param pVM VM Handle.
779 * @param pSSM SSM operation handle.
780 * @param uVersion Data layout version.
781 * @param uPass The data pass.
782 */
783static DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
784{
785 int rc;
786
787 LogFlow(("pdmR3LoadExec: uPass=%#x\n", uPass));
788
789 /*
790 * Validate version.
791 */
792 if ( uVersion != PDM_SAVED_STATE_VERSION
793 && uVersion != PDM_SAVED_STATE_VERSION_PRE_NMI_FF)
794 {
795 AssertMsgFailed(("Invalid version uVersion=%d!\n", uVersion));
796 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
797 }
798
799 if (uPass == SSM_PASS_FINAL)
800 {
801 /*
802 * Load the interrupt and DMA states.
803 */
804 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
805 {
806 PVMCPU pVCpu = &pVM->aCpus[idCpu];
807
808 /* APIC interrupt */
809 uint32_t fInterruptPending = 0;
810 rc = SSMR3GetU32(pSSM, &fInterruptPending);
811 if (RT_FAILURE(rc))
812 return rc;
813 if (fInterruptPending & ~1)
814 {
815 AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
816 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
817 }
818 AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC));
819 if (fInterruptPending)
820 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC);
821
822 /* PIC interrupt */
823 fInterruptPending = 0;
824 rc = SSMR3GetU32(pSSM, &fInterruptPending);
825 if (RT_FAILURE(rc))
826 return rc;
827 if (fInterruptPending & ~1)
828 {
829 AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
830 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
831 }
832 AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC));
833 if (fInterruptPending)
834 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
835
836 if (uVersion > PDM_SAVED_STATE_VERSION_PRE_NMI_FF)
837 {
838 /* NMI interrupt */
839 fInterruptPending = 0;
840 rc = SSMR3GetU32(pSSM, &fInterruptPending);
841 if (RT_FAILURE(rc))
842 return rc;
843 if (fInterruptPending & ~1)
844 {
845 AssertMsgFailed(("fInterruptPending=%#x (NMI)\n", fInterruptPending));
846 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
847 }
848 AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_NMI));
849 if (fInterruptPending)
850 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI);
851
852 /* SMI interrupt */
853 fInterruptPending = 0;
854 rc = SSMR3GetU32(pSSM, &fInterruptPending);
855 if (RT_FAILURE(rc))
856 return rc;
857 if (fInterruptPending & ~1)
858 {
859 AssertMsgFailed(("fInterruptPending=%#x (SMI)\n", fInterruptPending));
860 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
861 }
862 AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_SMI));
863 if (fInterruptPending)
864 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI);
865 }
866 }
867
868 /* DMA pending */
869 uint32_t fDMAPending = 0;
870 rc = SSMR3GetU32(pSSM, &fDMAPending);
871 if (RT_FAILURE(rc))
872 return rc;
873 if (fDMAPending & ~1)
874 {
875 AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
876 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
877 }
878 if (fDMAPending)
879 VM_FF_SET(pVM, VM_FF_PDM_DMA);
880 Log(("pdmR3LoadExec: VM_FF_PDM_DMA=%RTbool\n", VM_FF_ISSET(pVM, VM_FF_PDM_DMA)));
881 }
882
883 /*
884 * Load the list of devices and verify that they are all there.
885 */
886 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
887 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_FOUND;
888
889 for (uint32_t i = 0; ; i++)
890 {
891 /* Get the sequence number / terminator. */
892 uint32_t u32Sep;
893 rc = SSMR3GetU32(pSSM, &u32Sep);
894 if (RT_FAILURE(rc))
895 return rc;
896 if (u32Sep == UINT32_MAX)
897 break;
898 if (u32Sep != i)
899 AssertMsgFailedReturn(("Out of sequence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
900
901 /* Get the name and instance number. */
902 char szName[RT_SIZEOFMEMB(PDMDEVREG, szName)];
903 rc = SSMR3GetStrZ(pSSM, szName, sizeof(szName));
904 if (RT_FAILURE(rc))
905 return rc;
906 uint32_t iInstance;
907 rc = SSMR3GetU32(pSSM, &iInstance);
908 if (RT_FAILURE(rc))
909 return rc;
910
911 /* Try locate it. */
912 PPDMDEVINS pDevIns;
913 for (pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
914 if ( !strcmp(szName, pDevIns->pReg->szName)
915 && pDevIns->iInstance == iInstance)
916 {
917 AssertLogRelMsgReturn(!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND),
918 ("%s/#%u\n", pDevIns->pReg->szName, pDevIns->iInstance),
919 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
920 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_FOUND;
921 break;
922 }
923 if (!pDevIns)
924 {
925 LogRel(("Device '%s'/%d not found in current config\n", szName, iInstance));
926 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
927 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in current config"), szName, iInstance);
928 }
929 }
930
931 /*
932 * Check that no additional devices were configured.
933 */
934 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
935 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND))
936 {
937 LogRel(("Device '%s'/%d not found in the saved state\n", pDevIns->pReg->szName, pDevIns->iInstance));
938 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
939 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in the saved state"),
940 pDevIns->pReg->szName, pDevIns->iInstance);
941 }
942
943 return VINF_SUCCESS;
944}
945
946
947/**
948 * Worker for PDMR3PowerOn that deals with one driver.
949 *
950 * @param pDrvIns The driver instance.
951 * @param pszDeviceName The parent device name.
952 * @param iDevInstance The parent device instance number.
953 * @param iLun The parent LUN number.
954 */
955DECLINLINE(int) pdmR3PowerOnDrv(PPDMDRVINS pDrvIns, const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
956{
957 Assert(pDrvIns->Internal.s.fVMSuspended);
958 if (pDrvIns->pReg->pfnPowerOn)
959 {
960 LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
961 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
962 int rc = VINF_SUCCESS; pDrvIns->pReg->pfnPowerOn(pDrvIns);
963 if (RT_FAILURE(rc))
964 {
965 LogRel(("PDMR3PowerOn: driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
966 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance, rc));
967 return rc;
968 }
969 }
970 pDrvIns->Internal.s.fVMSuspended = false;
971 return VINF_SUCCESS;
972}
973
974
975/**
976 * Worker for PDMR3PowerOn that deals with one USB device instance.
977 *
978 * @returns VBox status code.
979 * @param pUsbIns The USB device instance.
980 */
981DECLINLINE(int) pdmR3PowerOnUsb(PPDMUSBINS pUsbIns)
982{
983 Assert(pUsbIns->Internal.s.fVMSuspended);
984 if (pUsbIns->pReg->pfnVMPowerOn)
985 {
986 LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
987 int rc = VINF_SUCCESS; pUsbIns->pReg->pfnVMPowerOn(pUsbIns);
988 if (RT_FAILURE(rc))
989 {
990 LogRel(("PDMR3PowerOn: device '%s'/%d -> %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
991 return rc;
992 }
993 }
994 pUsbIns->Internal.s.fVMSuspended = false;
995 return VINF_SUCCESS;
996}
997
998
999/**
1000 * Worker for PDMR3PowerOn that deals with one device instance.
1001 *
1002 * @returns VBox status code.
1003 * @param pDevIns The device instance.
1004 */
1005DECLINLINE(int) pdmR3PowerOnDev(PPDMDEVINS pDevIns)
1006{
1007 Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
1008 if (pDevIns->pReg->pfnPowerOn)
1009 {
1010 LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1011 int rc = VINF_SUCCESS; pDevIns->pReg->pfnPowerOn(pDevIns);
1012 if (RT_FAILURE(rc))
1013 {
1014 LogRel(("PDMR3PowerOn: device '%s'/%d -> %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1015 return rc;
1016 }
1017 }
1018 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
1019 return VINF_SUCCESS;
1020}
1021
1022
1023/**
1024 * This function will notify all the devices and their
1025 * attached drivers about the VM now being powered on.
1026 *
1027 * @param pVM VM Handle.
1028 */
1029VMMR3DECL(void) PDMR3PowerOn(PVM pVM)
1030{
1031 LogFlow(("PDMR3PowerOn:\n"));
1032
1033 /*
1034 * Iterate thru the device instances and USB device instances,
1035 * processing the drivers associated with those.
1036 */
1037 int rc = VINF_SUCCESS;
1038 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
1039 {
1040 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
1041 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
1042 rc = pdmR3PowerOnDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun);
1043 if (RT_SUCCESS(rc))
1044 rc = pdmR3PowerOnDev(pDevIns);
1045 }
1046
1047#ifdef VBOX_WITH_USB
1048 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
1049 {
1050 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
1051 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
1052 rc = pdmR3PowerOnDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun);
1053 if (RT_SUCCESS(rc))
1054 rc = pdmR3PowerOnUsb(pUsbIns);
1055 }
1056#endif
1057
1058#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1059 pdmR3AsyncCompletionResume(pVM);
1060#endif
1061
1062 /*
1063 * Resume all threads.
1064 */
1065 if (RT_SUCCESS(rc))
1066 pdmR3ThreadResumeAll(pVM);
1067
1068 /*
1069 * On failure, clean up via PDMR3Suspend.
1070 */
1071 if (RT_FAILURE(rc))
1072 PDMR3Suspend(pVM);
1073
1074 LogFlow(("PDMR3PowerOn: returns %Rrc\n", rc));
1075 return /*rc*/;
1076}
1077
1078
1079/**
1080 * Worker for PDMR3Reset that deals with one driver.
1081 *
1082 * @param pDrvIns The driver instance.
1083 * @param pcAsync The asynchronous reset notification counter.
1084 * @param pszDeviceName The parent device name.
1085 * @param iDevInstance The parent device instance number.
1086 * @param iLun The parent LUN number.
1087 */
1088DECLINLINE(bool) pdmR3ResetDrv(PPDMDRVINS pDrvIns, unsigned *pcAsync,
1089 const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
1090{
1091 if (!pDrvIns->Internal.s.fVMReset)
1092 {
1093 pDrvIns->Internal.s.fVMReset = true;
1094 if (pDrvIns->pReg->pfnReset)
1095 {
1096 if (!pDrvIns->Internal.s.pfnAsyncNotify)
1097 {
1098 LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1099 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1100 pDrvIns->pReg->pfnReset(pDrvIns);
1101 if (pDrvIns->Internal.s.pfnAsyncNotify)
1102 LogFlow(("PDMR3Reset: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1103 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1104 }
1105 else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
1106 {
1107 pDrvIns->Internal.s.pfnAsyncNotify = false;
1108 LogFlow(("PDMR3Reset: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1109 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1110 }
1111 if (pDrvIns->Internal.s.pfnAsyncNotify)
1112 {
1113 pDrvIns->Internal.s.fVMReset = false;
1114 (*pcAsync)++;
1115 return false;
1116 }
1117 }
1118 }
1119 return true;
1120}
1121
1122
1123/**
1124 * Worker for PDMR3Reset that deals with one USB device instance.
1125 *
1126 * @param pUsbIns The USB device instance.
1127 * @param pcAsync The asynchronous reset notification counter.
1128 */
1129DECLINLINE(void) pdmR3ResetUsb(PPDMUSBINS pUsbIns, unsigned *pcAsync)
1130{
1131 if (!pUsbIns->Internal.s.fVMReset)
1132 {
1133 pUsbIns->Internal.s.fVMReset = true;
1134 if (pUsbIns->pReg->pfnVMReset)
1135 {
1136 if (!pUsbIns->Internal.s.pfnAsyncNotify)
1137 {
1138 LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1139 pUsbIns->pReg->pfnVMReset(pUsbIns);
1140 if (pUsbIns->Internal.s.pfnAsyncNotify)
1141 LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1142 }
1143 else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
1144 {
1145 LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1146 pUsbIns->Internal.s.pfnAsyncNotify = NULL;
1147 }
1148 if (pUsbIns->Internal.s.pfnAsyncNotify)
1149 {
1150 pUsbIns->Internal.s.fVMReset = false;
1151 (*pcAsync)++;
1152 }
1153 }
1154 }
1155}
1156
1157
1158/**
1159 * Worker for PDMR3Reset that deals with one device instance.
1160 *
1161 * @param pDevIns The device instance.
1162 * @param pcAsync The asynchronous reset notification counter.
1163 */
1164DECLINLINE(void) pdmR3ResetDev(PPDMDEVINS pDevIns, unsigned *pcAsync)
1165{
1166 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_RESET))
1167 {
1168 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_RESET;
1169 if (pDevIns->pReg->pfnReset)
1170 {
1171 if (!pDevIns->Internal.s.pfnAsyncNotify)
1172 {
1173 LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1174 pDevIns->pReg->pfnReset(pDevIns);
1175 if (pDevIns->Internal.s.pfnAsyncNotify)
1176 LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1177 }
1178 else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
1179 {
1180 LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1181 pDevIns->Internal.s.pfnAsyncNotify = NULL;
1182 }
1183 if (pDevIns->Internal.s.pfnAsyncNotify)
1184 {
1185 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_RESET;
1186 (*pcAsync)++;
1187 }
1188 }
1189 }
1190}
1191
1192
1193/**
1194 * Resets a virtual CPU.
1195 *
1196 * Used by PDMR3Reset and CPU hot plugging.
1197 *
1198 * @param pVCpu The virtual CPU handle.
1199 */
1200VMMR3DECL(void) PDMR3ResetCpu(PVMCPU pVCpu)
1201{
1202 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
1203 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
1204 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
1205 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
1206}
1207
1208
1209/**
1210 * This function will notify all the devices and their attached drivers about
1211 * the VM now being reset.
1212 *
1213 * @param pVM VM Handle.
1214 */
1215VMMR3DECL(void) PDMR3Reset(PVM pVM)
1216{
1217 LogFlow(("PDMR3Reset:\n"));
1218
1219 /*
1220 * Clear all the reset flags.
1221 */
1222 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1223 {
1224 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_RESET;
1225 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
1226 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1227 pDrvIns->Internal.s.fVMReset = false;
1228 }
1229#ifdef VBOX_WITH_USB
1230 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1231 {
1232 pUsbIns->Internal.s.fVMReset = false;
1233 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
1234 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1235 pDrvIns->Internal.s.fVMReset = false;
1236 }
1237#endif
1238
1239 /*
1240 * The outer loop repeats until there are no more async requests.
1241 */
1242 unsigned cAsync;
1243 for (unsigned iLoop = 0; ; iLoop++)
1244 {
1245 /*
1246 * Iterate thru the device instances and USB device instances,
1247 * processing the drivers associated with those.
1248 */
1249 cAsync = 0;
1250 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1251 {
1252 unsigned const cAsyncStart = cAsync;
1253
1254 if (cAsync == cAsyncStart)
1255 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
1256 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1257 if (!pdmR3ResetDrv(pDrvIns, &cAsync, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
1258 break;
1259
1260 if (cAsync == cAsyncStart)
1261 pdmR3ResetDev(pDevIns, &cAsync);
1262 }
1263
1264#ifdef VBOX_WITH_USB
1265 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1266 {
1267 unsigned const cAsyncStart = cAsync;
1268
1269 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
1270 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1271 if (!pdmR3ResetDrv(pDrvIns, &cAsync, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
1272 break;
1273
1274 if (cAsync == cAsyncStart)
1275 pdmR3ResetUsb(pUsbIns, &cAsync);
1276 }
1277#endif
1278 if (!cAsync)
1279 break;
1280
1281 /*
1282 * Process requests.
1283 */
1284 /** @todo This is utterly nuts and completely unsafe... will get back to it in a
1285 * bit I hope... */
1286 int rc = VMR3AsyncPdmNotificationWaitU(&pVM->pUVM->aCpus[0]);
1287 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1288 rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY);
1289 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1290 rc = VMR3ReqProcessU(pVM->pUVM, 0/*idDstCpu*/);
1291 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1292 }
1293
1294 /*
1295 * Clear all pending interrupts and DMA operations.
1296 */
1297 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1298 PDMR3ResetCpu(&pVM->aCpus[idCpu]);
1299 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
1300
1301 LogFlow(("PDMR3Reset: returns void\n"));
1302}
1303
1304
1305/**
1306 * Worker for PDMR3Suspend that deals with one driver.
1307 *
1308 * @param pDrvIns The driver instance.
1309 * @param pcAsync The asynchronous suspend notification counter.
1310 * @param pszDeviceName The parent device name.
1311 * @param iDevInstance The parent device instance number.
1312 * @param iLun The parent LUN number.
1313 */
1314DECLINLINE(bool) pdmR3SuspendDrv(PPDMDRVINS pDrvIns, unsigned *pcAsync,
1315 const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
1316{
1317 if (!pDrvIns->Internal.s.fVMSuspended)
1318 {
1319 pDrvIns->Internal.s.fVMSuspended = true;
1320 if (pDrvIns->pReg->pfnSuspend)
1321 {
1322 if (!pDrvIns->Internal.s.pfnAsyncNotify)
1323 {
1324 LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1325 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1326 pDrvIns->pReg->pfnSuspend(pDrvIns);
1327 if (pDrvIns->Internal.s.pfnAsyncNotify)
1328 LogFlow(("PDMR3Suspend: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1329 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1330 }
1331 else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
1332 {
1333 pDrvIns->Internal.s.pfnAsyncNotify = false;
1334 LogFlow(("PDMR3Suspend: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1335 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1336 }
1337 if (pDrvIns->Internal.s.pfnAsyncNotify)
1338 {
1339 pDrvIns->Internal.s.fVMSuspended = false;
1340 (*pcAsync)++;
1341 return false;
1342 }
1343 }
1344 }
1345 return true;
1346}
1347
1348
1349/**
1350 * Worker for PDMR3Suspend that deals with one USB device instance.
1351 *
1352 * @param pUsbIns The USB device instance.
1353 * @param pcAsync The asynchronous suspend notification counter.
1354 */
1355DECLINLINE(void) pdmR3SuspendUsb(PPDMUSBINS pUsbIns, unsigned *pcAsync)
1356{
1357 if (!pUsbIns->Internal.s.fVMSuspended)
1358 {
1359 pUsbIns->Internal.s.fVMSuspended = true;
1360 if (pUsbIns->pReg->pfnVMSuspend)
1361 {
1362 if (!pUsbIns->Internal.s.pfnAsyncNotify)
1363 {
1364 LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1365 pUsbIns->pReg->pfnVMSuspend(pUsbIns);
1366 if (pUsbIns->Internal.s.pfnAsyncNotify)
1367 LogFlow(("PDMR3Suspend: Async notification started - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1368 }
1369 else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
1370 {
1371 LogFlow(("PDMR3Suspend: Async notification completed - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1372 pUsbIns->Internal.s.pfnAsyncNotify = NULL;
1373 }
1374 if (pUsbIns->Internal.s.pfnAsyncNotify)
1375 {
1376 pUsbIns->Internal.s.fVMSuspended = false;
1377 (*pcAsync)++;
1378 }
1379 }
1380 }
1381}
1382
1383
1384/**
1385 * Worker for PDMR3Suspend that deals with one device instance.
1386 *
1387 * @param pDevIns The device instance.
1388 * @param pcAsync The asynchronous suspend notification counter.
1389 */
1390DECLINLINE(void) pdmR3SuspendDev(PPDMDEVINS pDevIns, unsigned *pcAsync)
1391{
1392 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED))
1393 {
1394 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_SUSPENDED;
1395 if (pDevIns->pReg->pfnSuspend)
1396 {
1397 if (!pDevIns->Internal.s.pfnAsyncNotify)
1398 {
1399 LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1400 pDevIns->pReg->pfnSuspend(pDevIns);
1401 if (pDevIns->Internal.s.pfnAsyncNotify)
1402 LogFlow(("PDMR3Suspend: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1403 }
1404 else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
1405 {
1406 LogFlow(("PDMR3Suspend: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1407 pDevIns->Internal.s.pfnAsyncNotify = NULL;
1408 }
1409 if (pDevIns->Internal.s.pfnAsyncNotify)
1410 {
1411 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
1412 (*pcAsync)++;
1413 }
1414 }
1415 }
1416}
1417
1418
1419/**
1420 * This function will notify all the devices and their attached drivers about
1421 * the VM now being suspended.
1422 *
1423 * @param pVM The VM Handle.
1424 * @thread EMT(0)
1425 */
1426VMMR3DECL(void) PDMR3Suspend(PVM pVM)
1427{
1428 LogFlow(("PDMR3Suspend:\n"));
1429 VM_ASSERT_EMT0(pVM);
1430
1431 /*
1432 * The outer loop repeats until there are no more async requests.
1433 *
1434 * Note! We depend on the suspended indicators to be in the desired state
1435 * and we do not reset them before starting because this allows
1436 * PDMR3PowerOn and PDMR3Resume to use PDMR3Suspend for cleaning up
1437 * on failure.
1438 */
1439 unsigned cAsync;
1440 for (unsigned iLoop = 0; ; iLoop++)
1441 {
1442 /*
1443 * Iterate thru the device instances and USB device instances,
1444 * processing the drivers associated with those.
1445 *
1446 * The attached drivers are normally processed first. Some devices
1447 * (like DevAHCI) though needs to be notified before the drivers so
1448 * that it doesn't kick off any new requests after the drivers stopped
1449 * taking any. (DrvVD changes to read-only in this particular case.)
1450 */
1451 cAsync = 0;
1452 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1453 {
1454 unsigned const cAsyncStart = cAsync;
1455
1456 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION)
1457 pdmR3SuspendDev(pDevIns, &cAsync);
1458
1459 if (cAsync == cAsyncStart)
1460 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
1461 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1462 if (!pdmR3SuspendDrv(pDrvIns, &cAsync, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
1463 break;
1464
1465 if ( cAsync == cAsyncStart
1466 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION))
1467 pdmR3SuspendDev(pDevIns, &cAsync);
1468 }
1469
1470#ifdef VBOX_WITH_USB
1471 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1472 {
1473 unsigned const cAsyncStart = cAsync;
1474
1475 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
1476 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1477 if (!pdmR3SuspendDrv(pDrvIns, &cAsync, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
1478 break;
1479
1480 if (cAsync == cAsyncStart)
1481 pdmR3SuspendUsb(pUsbIns, &cAsync);
1482 }
1483#endif
1484 if (!cAsync)
1485 break;
1486
1487 /*
1488 * Process requests.
1489 */
1490 /** @todo This is utterly nuts and completely unsafe... will get back to it in a
1491 * bit I hope... */
1492 int rc = VMR3AsyncPdmNotificationWaitU(&pVM->pUVM->aCpus[0]);
1493 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1494 rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY);
1495 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1496 rc = VMR3ReqProcessU(pVM->pUVM, 0/*idDstCpu*/);
1497 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1498 }
1499
1500 /*
1501 * Suspend all threads.
1502 */
1503 pdmR3ThreadSuspendAll(pVM);
1504
1505 LogFlow(("PDMR3Suspend: returns void\n"));
1506}
1507
1508
1509/**
1510 * Worker for PDMR3Resume that deals with one driver.
1511 *
1512 * @param pDrvIns The driver instance.
1513 * @param pszDeviceName The parent device name.
1514 * @param iDevInstance The parent device instance number.
1515 * @param iLun The parent LUN number.
1516 */
1517DECLINLINE(int) pdmR3ResumeDrv(PPDMDRVINS pDrvIns, const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
1518{
1519 Assert(pDrvIns->Internal.s.fVMSuspended);
1520 if (pDrvIns->pReg->pfnResume)
1521 {
1522 LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1523 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1524 int rc = VINF_SUCCESS; pDrvIns->pReg->pfnResume(pDrvIns);
1525 if (RT_FAILURE(rc))
1526 {
1527 LogRel(("PDMR3Resume: driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
1528 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance, rc));
1529 return rc;
1530 }
1531 }
1532 pDrvIns->Internal.s.fVMSuspended = false;
1533 return VINF_SUCCESS;
1534}
1535
1536
1537/**
1538 * Worker for PDMR3Resume that deals with one USB device instance.
1539 *
1540 * @returns VBox status code.
1541 * @param pUsbIns The USB device instance.
1542 */
1543DECLINLINE(int) pdmR3ResumeUsb(PPDMUSBINS pUsbIns)
1544{
1545 Assert(pUsbIns->Internal.s.fVMSuspended);
1546 if (pUsbIns->pReg->pfnVMResume)
1547 {
1548 LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1549 int rc = VINF_SUCCESS; pUsbIns->pReg->pfnVMResume(pUsbIns);
1550 if (RT_FAILURE(rc))
1551 {
1552 LogRel(("PDMR3Resume: device '%s'/%d -> %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1553 return rc;
1554 }
1555 }
1556 pUsbIns->Internal.s.fVMSuspended = false;
1557 return VINF_SUCCESS;
1558}
1559
1560
1561/**
1562 * Worker for PDMR3Resume that deals with one device instance.
1563 *
1564 * @returns VBox status code.
1565 * @param pDevIns The device instance.
1566 */
1567DECLINLINE(int) pdmR3ResumeDev(PPDMDEVINS pDevIns)
1568{
1569 Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
1570 if (pDevIns->pReg->pfnResume)
1571 {
1572 LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1573 int rc = VINF_SUCCESS; pDevIns->pReg->pfnResume(pDevIns);
1574 if (RT_FAILURE(rc))
1575 {
1576 LogRel(("PDMR3Resume: device '%s'/%d -> %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1577 return rc;
1578 }
1579 }
1580 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
1581 return VINF_SUCCESS;
1582}
1583
1584
1585/**
1586 * This function will notify all the devices and their
1587 * attached drivers about the VM now being resumed.
1588 *
1589 * @param pVM VM Handle.
1590 */
1591VMMR3DECL(void) PDMR3Resume(PVM pVM)
1592{
1593 LogFlow(("PDMR3Resume:\n"));
1594
1595 /*
1596 * Iterate thru the device instances and USB device instances,
1597 * processing the drivers associated with those.
1598 */
1599 int rc = VINF_SUCCESS;
1600 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
1601 {
1602 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
1603 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
1604 rc = pdmR3ResumeDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun);
1605 if (RT_SUCCESS(rc))
1606 rc = pdmR3ResumeDev(pDevIns);
1607 }
1608
1609#ifdef VBOX_WITH_USB
1610 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
1611 {
1612 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
1613 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
1614 rc = pdmR3ResumeDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun);
1615 if (RT_SUCCESS(rc))
1616 rc = pdmR3ResumeUsb(pUsbIns);
1617 }
1618#endif
1619
1620 /*
1621 * Resume all threads.
1622 */
1623 if (RT_SUCCESS(rc))
1624 pdmR3ThreadResumeAll(pVM);
1625
1626 /*
1627 * Resume the block cache.
1628 */
1629 if (RT_SUCCESS(rc))
1630 pdmR3BlkCacheResume(pVM);
1631
1632 /*
1633 * On failure, clean up via PDMR3Suspend.
1634 */
1635 if (RT_FAILURE(rc))
1636 PDMR3Suspend(pVM);
1637
1638 LogFlow(("PDMR3Resume: returns %Rrc\n", rc));
1639 return /*rc*/;
1640}
1641
1642
1643/**
1644 * Worker for PDMR3PowerOff that deals with one driver.
1645 *
1646 * @param pDrvIns The driver instance.
1647 * @param pcAsync The asynchronous power off notification counter.
1648 * @param pszDeviceName The parent device name.
1649 * @param iDevInstance The parent device instance number.
1650 * @param iLun The parent LUN number.
1651 */
1652DECLINLINE(bool) pdmR3PowerOffDrv(PPDMDRVINS pDrvIns, unsigned *pcAsync,
1653 const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
1654{
1655 if (!pDrvIns->Internal.s.fVMSuspended)
1656 {
1657 pDrvIns->Internal.s.fVMSuspended = true;
1658 if (pDrvIns->pReg->pfnPowerOff)
1659 {
1660 if (!pDrvIns->Internal.s.pfnAsyncNotify)
1661 {
1662 LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1663 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1664 pDrvIns->pReg->pfnPowerOff(pDrvIns);
1665 if (pDrvIns->Internal.s.pfnAsyncNotify)
1666 LogFlow(("PDMR3PowerOff: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1667 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1668 }
1669 else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
1670 {
1671 pDrvIns->Internal.s.pfnAsyncNotify = false;
1672 LogFlow(("PDMR3PowerOff: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1673 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
1674 }
1675 if (pDrvIns->Internal.s.pfnAsyncNotify)
1676 {
1677 pDrvIns->Internal.s.fVMSuspended = false;
1678 (*pcAsync)++;
1679 return false;
1680 }
1681 }
1682 }
1683 return true;
1684}
1685
1686
1687/**
1688 * Worker for PDMR3PowerOff that deals with one USB device instance.
1689 *
1690 * @param pUsbIns The USB device instance.
1691 * @param pcAsync The asynchronous power off notification counter.
1692 */
1693DECLINLINE(void) pdmR3PowerOffUsb(PPDMUSBINS pUsbIns, unsigned *pcAsync)
1694{
1695 if (!pUsbIns->Internal.s.fVMSuspended)
1696 {
1697 pUsbIns->Internal.s.fVMSuspended = true;
1698 if (pUsbIns->pReg->pfnVMPowerOff)
1699 {
1700 if (!pUsbIns->Internal.s.pfnAsyncNotify)
1701 {
1702 LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1703 pUsbIns->pReg->pfnVMPowerOff(pUsbIns);
1704 if (pUsbIns->Internal.s.pfnAsyncNotify)
1705 LogFlow(("PDMR3PowerOff: Async notification started - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1706 }
1707 else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
1708 {
1709 LogFlow(("PDMR3PowerOff: Async notification completed - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1710 pUsbIns->Internal.s.pfnAsyncNotify = NULL;
1711 }
1712 if (pUsbIns->Internal.s.pfnAsyncNotify)
1713 {
1714 pUsbIns->Internal.s.fVMSuspended = false;
1715 (*pcAsync)++;
1716 }
1717 }
1718 }
1719}
1720
1721
1722/**
1723 * Worker for PDMR3PowerOff that deals with one device instance.
1724 *
1725 * @param pDevIns The device instance.
1726 * @param pcAsync The asynchronous power off notification counter.
1727 */
1728DECLINLINE(void) pdmR3PowerOffDev(PPDMDEVINS pDevIns, unsigned *pcAsync)
1729{
1730 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED))
1731 {
1732 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_SUSPENDED;
1733 if (pDevIns->pReg->pfnPowerOff)
1734 {
1735 if (!pDevIns->Internal.s.pfnAsyncNotify)
1736 {
1737 LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1738 pDevIns->pReg->pfnPowerOff(pDevIns);
1739 if (pDevIns->Internal.s.pfnAsyncNotify)
1740 LogFlow(("PDMR3PowerOff: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1741 }
1742 else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
1743 {
1744 LogFlow(("PDMR3PowerOff: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1745 pDevIns->Internal.s.pfnAsyncNotify = NULL;
1746 }
1747 if (pDevIns->Internal.s.pfnAsyncNotify)
1748 {
1749 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
1750 (*pcAsync)++;
1751 }
1752 }
1753 }
1754}
1755
1756
1757/**
1758 * This function will notify all the devices and their
1759 * attached drivers about the VM being powered off.
1760 *
1761 * @param pVM VM Handle.
1762 */
1763VMMR3DECL(void) PDMR3PowerOff(PVM pVM)
1764{
1765 LogFlow(("PDMR3PowerOff:\n"));
1766
1767 /*
1768 * The outer loop repeats until there are no more async requests.
1769 */
1770 unsigned cAsync;
1771 for (unsigned iLoop = 0; ; iLoop++)
1772 {
1773 /*
1774 * Iterate thru the device instances and USB device instances,
1775 * processing the drivers associated with those.
1776 *
1777 * The attached drivers are normally processed first. Some devices
1778 * (like DevAHCI) though needs to be notified before the drivers so
1779 * that it doesn't kick off any new requests after the drivers stopped
1780 * taking any. (DrvVD changes to read-only in this particular case.)
1781 */
1782 cAsync = 0;
1783 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1784 {
1785 unsigned const cAsyncStart = cAsync;
1786
1787 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION)
1788 pdmR3PowerOffDev(pDevIns, &cAsync);
1789
1790 if (cAsync == cAsyncStart)
1791 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
1792 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1793 if (!pdmR3PowerOffDrv(pDrvIns, &cAsync, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
1794 break;
1795
1796 if ( cAsync == cAsyncStart
1797 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION))
1798 pdmR3PowerOffDev(pDevIns, &cAsync);
1799 }
1800
1801#ifdef VBOX_WITH_USB
1802 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1803 {
1804 unsigned const cAsyncStart = cAsync;
1805
1806 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
1807 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1808 if (!pdmR3PowerOffDrv(pDrvIns, &cAsync, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
1809 break;
1810
1811 if (cAsync == cAsyncStart)
1812 pdmR3PowerOffUsb(pUsbIns, &cAsync);
1813 }
1814#endif
1815 if (!cAsync)
1816 break;
1817
1818 /*
1819 * Process requests.
1820 */
1821 /** @todo This is utterly nuts and completely unsafe... will get back to it in a
1822 * bit I hope... */
1823 int rc = VMR3AsyncPdmNotificationWaitU(&pVM->pUVM->aCpus[0]);
1824 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1825 rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY);
1826 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1827 rc = VMR3ReqProcessU(pVM->pUVM, 0/*idDstCpu*/);
1828 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
1829 }
1830
1831 /*
1832 * Suspend all threads.
1833 */
1834 pdmR3ThreadSuspendAll(pVM);
1835
1836 LogFlow(("PDMR3PowerOff: returns void\n"));
1837}
1838
1839
1840/**
1841 * Queries the base interface of a device instance.
1842 *
1843 * The caller can use this to query other interfaces the device implements
1844 * and use them to talk to the device.
1845 *
1846 * @returns VBox status code.
1847 * @param pVM VM handle.
1848 * @param pszDevice Device name.
1849 * @param iInstance Device instance.
1850 * @param ppBase Where to store the pointer to the base device interface on success.
1851 * @remark We're not doing any locking ATM, so don't try call this at times when the
1852 * device chain is known to be updated.
1853 */
1854VMMR3DECL(int) PDMR3QueryDevice(PVM pVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
1855{
1856 LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
1857
1858 /*
1859 * Iterate registered devices looking for the device.
1860 */
1861 size_t cchDevice = strlen(pszDevice);
1862 for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext)
1863 {
1864 if ( pDev->cchName == cchDevice
1865 && !memcmp(pDev->pReg->szName, pszDevice, cchDevice))
1866 {
1867 /*
1868 * Iterate device instances.
1869 */
1870 for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextR3)
1871 {
1872 if (pDevIns->iInstance == iInstance)
1873 {
1874 if (pDevIns->IBase.pfnQueryInterface)
1875 {
1876 *ppBase = &pDevIns->IBase;
1877 LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
1878 return VINF_SUCCESS;
1879 }
1880
1881 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
1882 return VERR_PDM_DEVICE_INSTANCE_NO_IBASE;
1883 }
1884 }
1885
1886 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
1887 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND;
1888 }
1889 }
1890
1891 LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
1892 return VERR_PDM_DEVICE_NOT_FOUND;
1893}
1894
1895
1896/**
1897 * Queries the base interface of a device LUN.
1898 *
1899 * This differs from PDMR3QueryLun by that it returns the interface on the
1900 * device and not the top level driver.
1901 *
1902 * @returns VBox status code.
1903 * @param pVM VM Handle.
1904 * @param pszDevice Device name.
1905 * @param iInstance Device instance.
1906 * @param iLun The Logical Unit to obtain the interface of.
1907 * @param ppBase Where to store the base interface pointer.
1908 * @remark We're not doing any locking ATM, so don't try call this at times when the
1909 * device chain is known to be updated.
1910 */
1911VMMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
1912{
1913 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
1914 pszDevice, pszDevice, iInstance, iLun, ppBase));
1915
1916 /*
1917 * Find the LUN.
1918 */
1919 PPDMLUN pLun;
1920 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
1921 if (RT_SUCCESS(rc))
1922 {
1923 *ppBase = pLun->pBase;
1924 LogFlow(("PDMR3QueryDeviceLun: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
1925 return VINF_SUCCESS;
1926 }
1927 LogFlow(("PDMR3QueryDeviceLun: returns %Rrc\n", rc));
1928 return rc;
1929}
1930
1931
1932/**
1933 * Query the interface of the top level driver on a LUN.
1934 *
1935 * @returns VBox status code.
1936 * @param pVM VM Handle.
1937 * @param pszDevice Device name.
1938 * @param iInstance Device instance.
1939 * @param iLun The Logical Unit to obtain the interface of.
1940 * @param ppBase Where to store the base interface pointer.
1941 * @remark We're not doing any locking ATM, so don't try call this at times when the
1942 * device chain is known to be updated.
1943 */
1944VMMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
1945{
1946 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
1947 pszDevice, pszDevice, iInstance, iLun, ppBase));
1948
1949 /*
1950 * Find the LUN.
1951 */
1952 PPDMLUN pLun;
1953 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
1954 if (RT_SUCCESS(rc))
1955 {
1956 if (pLun->pTop)
1957 {
1958 *ppBase = &pLun->pTop->IBase;
1959 LogFlow(("PDMR3QueryLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
1960 return VINF_SUCCESS;
1961 }
1962 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
1963 }
1964 LogFlow(("PDMR3QueryLun: returns %Rrc\n", rc));
1965 return rc;
1966}
1967
1968
1969/**
1970 * Query the interface of a named driver on a LUN.
1971 *
1972 * If the driver appears more than once in the driver chain, the first instance
1973 * is returned.
1974 *
1975 * @returns VBox status code.
1976 * @param pVM VM Handle.
1977 * @param pszDevice Device name.
1978 * @param iInstance Device instance.
1979 * @param iLun The Logical Unit to obtain the interface of.
1980 * @param pszDriver The driver name.
1981 * @param ppBase Where to store the base interface pointer.
1982 *
1983 * @remark We're not doing any locking ATM, so don't try call this at times when the
1984 * device chain is known to be updated.
1985 */
1986VMMR3DECL(int) PDMR3QueryDriverOnLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, const char *pszDriver, PPPDMIBASE ppBase)
1987{
1988 LogFlow(("PDMR3QueryDriverOnLun: pszDevice=%p:{%s} iInstance=%u iLun=%u pszDriver=%p:{%s} ppBase=%p\n",
1989 pszDevice, pszDevice, iInstance, iLun, pszDriver, pszDriver, ppBase));
1990
1991 /*
1992 * Find the LUN.
1993 */
1994 PPDMLUN pLun;
1995 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
1996 if (RT_SUCCESS(rc))
1997 {
1998 if (pLun->pTop)
1999 {
2000 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2001 if (!strcmp(pDrvIns->pReg->szName, pszDriver))
2002 {
2003 *ppBase = &pDrvIns->IBase;
2004 LogFlow(("PDMR3QueryDriverOnLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
2005 return VINF_SUCCESS;
2006
2007 }
2008 rc = VERR_PDM_DRIVER_NOT_FOUND;
2009 }
2010 else
2011 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
2012 }
2013 LogFlow(("PDMR3QueryDriverOnLun: returns %Rrc\n", rc));
2014 return rc;
2015}
2016
2017/**
2018 * Executes pending DMA transfers.
2019 * Forced Action handler.
2020 *
2021 * @param pVM VM handle.
2022 */
2023VMMR3DECL(void) PDMR3DmaRun(PVM pVM)
2024{
2025 /* Note! Not really SMP safe; restrict it to VCPU 0. */
2026 if (VMMGetCpuId(pVM) != 0)
2027 return;
2028
2029 if (VM_FF_TESTANDCLEAR(pVM, VM_FF_PDM_DMA))
2030 {
2031 if (pVM->pdm.s.pDmac)
2032 {
2033 bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns);
2034 if (fMore)
2035 VM_FF_SET(pVM, VM_FF_PDM_DMA);
2036 }
2037 }
2038}
2039
2040
2041/**
2042 * Service a VMMCALLRING3_PDM_LOCK call.
2043 *
2044 * @returns VBox status code.
2045 * @param pVM The VM handle.
2046 */
2047VMMR3DECL(int) PDMR3LockCall(PVM pVM)
2048{
2049 return PDMR3CritSectEnterEx(&pVM->pdm.s.CritSect, true /* fHostCall */);
2050}
2051
2052
2053/**
2054 * Registers the VMM device heap
2055 *
2056 * @returns VBox status code.
2057 * @param pVM VM handle.
2058 * @param GCPhys The physical address.
2059 * @param pvHeap Ring-3 pointer.
2060 * @param cbSize Size of the heap.
2061 */
2062VMMR3DECL(int) PDMR3RegisterVMMDevHeap(PVM pVM, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
2063{
2064 Assert(pVM->pdm.s.pvVMMDevHeap == NULL);
2065
2066 Log(("PDMR3RegisterVMMDevHeap %RGp %RHv %x\n", GCPhys, pvHeap, cbSize));
2067 pVM->pdm.s.pvVMMDevHeap = pvHeap;
2068 pVM->pdm.s.GCPhysVMMDevHeap = GCPhys;
2069 pVM->pdm.s.cbVMMDevHeap = cbSize;
2070 pVM->pdm.s.cbVMMDevHeapLeft = cbSize;
2071 return VINF_SUCCESS;
2072}
2073
2074
2075/**
2076 * Unregisters the VMM device heap
2077 *
2078 * @returns VBox status code.
2079 * @param pVM VM handle.
2080 * @param GCPhys The physical address.
2081 */
2082VMMR3DECL(int) PDMR3UnregisterVMMDevHeap(PVM pVM, RTGCPHYS GCPhys)
2083{
2084 Assert(pVM->pdm.s.GCPhysVMMDevHeap == GCPhys);
2085
2086 Log(("PDMR3UnregisterVMMDevHeap %RGp\n", GCPhys));
2087 pVM->pdm.s.pvVMMDevHeap = NULL;
2088 pVM->pdm.s.GCPhysVMMDevHeap = NIL_RTGCPHYS;
2089 pVM->pdm.s.cbVMMDevHeap = 0;
2090 pVM->pdm.s.cbVMMDevHeapLeft = 0;
2091 return VINF_SUCCESS;
2092}
2093
2094
2095/**
2096 * Allocates memory from the VMM device heap
2097 *
2098 * @returns VBox status code.
2099 * @param pVM VM handle.
2100 * @param cbSize Allocation size.
2101 * @param pv Ring-3 pointer. (out)
2102 */
2103VMMR3DECL(int) PDMR3VMMDevHeapAlloc(PVM pVM, unsigned cbSize, RTR3PTR *ppv)
2104{
2105#ifdef DEBUG_bird
2106 if (!cbSize || cbSize > pVM->pdm.s.cbVMMDevHeapLeft)
2107 return VERR_NO_MEMORY;
2108#else
2109 AssertReturn(cbSize && cbSize <= pVM->pdm.s.cbVMMDevHeapLeft, VERR_NO_MEMORY);
2110#endif
2111
2112 Log(("PDMR3VMMDevHeapAlloc %x\n", cbSize));
2113
2114 /** @todo not a real heap as there's currently only one user. */
2115 *ppv = pVM->pdm.s.pvVMMDevHeap;
2116 pVM->pdm.s.cbVMMDevHeapLeft = 0;
2117 return VINF_SUCCESS;
2118}
2119
2120
2121/**
2122 * Frees memory from the VMM device heap
2123 *
2124 * @returns VBox status code.
2125 * @param pVM VM handle.
2126 * @param pv Ring-3 pointer.
2127 */
2128VMMR3DECL(int) PDMR3VMMDevHeapFree(PVM pVM, RTR3PTR pv)
2129{
2130 Log(("PDMR3VMMDevHeapFree %RHv\n", pv));
2131
2132 /** @todo not a real heap as there's currently only one user. */
2133 pVM->pdm.s.cbVMMDevHeapLeft = pVM->pdm.s.cbVMMDevHeap;
2134 return VINF_SUCCESS;
2135}
2136
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