VirtualBox

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

Last change on this file since 81525 was 81519, checked in by vboxsync, 5 years ago

DevSmc,PDM: Converted the SMC device to the new style. Converted PDMDevHlpCallR0 to use PDMDEVREGR0::pfnRequest and ditch the inefficient symbol resolving stuff. The SMC device was the only user I could find for this helper. bugref:9218

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 114.2 KB
Line 
1/* $Id: PDM.cpp 81519 2019-10-24 13:25:31Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device Manager.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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 * The PDM handles devices and their drivers in a flexible and dynamic manner.
22 *
23 * VirtualBox is designed to be very configurable, i.e. the ability to select
24 * virtual devices and configure them uniquely for a VM. For this reason
25 * virtual devices are not statically linked with the VMM but loaded, linked and
26 * instantiated at runtime by PDM using the information found in the
27 * Configuration Manager (CFGM).
28 *
29 * While the chief purpose of PDM is to manager of devices their drivers, it
30 * also serves as somewhere to put usful things like cross context queues, cross
31 * context synchronization (like critsect), VM centric thread management,
32 * asynchronous I/O framework, and so on.
33 *
34 * @sa @ref grp_pdm
35 * @subpage pg_pdm_block_cache
36 *
37 *
38 * @section sec_pdm_dev The Pluggable Devices
39 *
40 * Devices register themselves when the module containing them is loaded. PDM
41 * will call the entry point 'VBoxDevicesRegister' when loading a device module.
42 * The device module will then use the supplied callback table to check the VMM
43 * version and to register its devices. Each device has an unique name (within
44 * the VM configuration anyway). The name is not only used in PDM, but also in
45 * CFGM to organize device and device instance settings, and by anyone who wants
46 * to talk to a specific device instance.
47 *
48 * When all device modules have been successfully loaded PDM will instantiate
49 * those devices which are configured for the VM. Note that a device may have
50 * more than one instance, take network adaptors as an example. When
51 * instantiating a device PDM provides device instance memory and a callback
52 * table (aka Device Helpers / DevHlp) with the VM APIs which the device
53 * instance is trusted with.
54 *
55 * Some devices are trusted devices, most are not. The trusted devices are an
56 * integrated part of the VM and can obtain the VM handle, thus enabling them to
57 * call any VM API. Untrusted devices can only use the callbacks provided
58 * during device instantiation.
59 *
60 * The main purpose in having DevHlps rather than just giving all the devices
61 * the VM handle and let them call the internal VM APIs directly, is both to
62 * create a binary interface that can be supported across releases and to
63 * create a barrier between devices and the VM. (The trusted / untrusted bit
64 * hasn't turned out to be of much use btw., but it's easy to maintain so there
65 * isn't any point in removing it.)
66 *
67 * A device can provide a ring-0 and/or a raw-mode context extension to improve
68 * the VM performance by handling exits and traps (respectively) without
69 * requiring context switches (to ring-3). Callbacks for MMIO and I/O ports
70 * need to be registered specifically for the additional contexts for this to
71 * make sense. Also, the device has to be trusted to be loaded into R0/RC
72 * because of the extra privilege it entails. Note that raw-mode code and data
73 * will be subject to relocation.
74 *
75 *
76 * @subsection sec_pdm_dev_pci PCI Devices
77 *
78 * A PDM device usually registers one a PCI device during it's instantiation,
79 * legacy devices may register zero, while a few (currently none) more
80 * complicated devices may register multiple PCI functions or devices.
81 *
82 * The bus, device and function assignments can either be done explictly via the
83 * configuration or the registration call, or it can be left up to the PCI bus.
84 * The typical VBox configuration construct (ConsoleImpl2.cpp) will do explict
85 * assignments for all devices it's BusAssignmentManager class knows about.
86 *
87 * For explict CFGM style configuration, the "PCIBusNo", "PCIDeviceNo", and
88 * "PCIFunctionNo" values in the PDM device instance configuration (not the
89 * "config" subkey, but the top level one) will be picked up for the primary PCI
90 * device. The primary PCI configuration is by default the first one, but this
91 * can be controlled using the @a idxDevCfg parameter of the
92 * PDMDEVHLPR3::pfnPCIRegister method. For subsequent configuration (@a
93 * idxDevCfg > 0) the values are taken from the "PciDevNN" subkey, where "NN" is
94 * replaced by the @a idxDevCfg value.
95 *
96 * There's currently a limit of 256 PCI devices per PDM device.
97 *
98 *
99 * @subsection sec_pdm_dev_new New Style (6.1)
100 *
101 * VBox 6.1 changes the PDM interface for devices and they have to be converted
102 * to the new style to continue working (see @bugref{9218}).
103 *
104 * Steps for converting a PDM device to the new style:
105 *
106 * - State data needs to be split into shared, ring-3, ring-0 and raw-mode
107 * structures. The shared structure shall contains absolutely no pointers.
108 *
109 * - Context specific typedefs ending in CC for the structure and pointer to
110 * it are required (copy & edit the PRTCSTATECC stuff).
111 * The pointer to a context specific structure is obtained using the
112 * PDMINS_2_DATA_CC macro. The PDMINS_2_DATA macro gets the shared one.
113 *
114 * - Update the registration structure with sizeof the new structures.
115 *
116 * - MMIO handlers to FNIOMMMIONEWREAD and FNIOMMMIONEWRITE form, take care renaming
117 * GCPhys to off and really treat it as an offset. Return status is VBOXSTRICTRC,
118 * which should be propagated to worker functions as far as possible.
119 *
120 * - I/O handlers to FNIOMIOPORTNEWIN and FNIOMIOPORTNEWOUT form, take care renaming
121 * uPort/Port to offPort and really treat it as an offset. Return status is
122 * VBOXSTRICTRC, which should be propagated to worker functions as far as possible.
123 *
124 * - MMIO and I/O port registration must be converted, handles stored in the shared structure.
125 *
126 * - PCI devices must also update the I/O region registration and corresponding
127 * mapping callback. The latter is generally not needed any more, as the PCI
128 * bus does the mapping and unmapping using the handle passed to it during registration.
129 *
130 * - If the device contains ring-0 or raw-mode optimizations:
131 * - Make sure to replace any R0Enabled, GCEnabled, and RZEnabled with
132 * pDevIns->fR0Enabled and pDevIns->fRCEnabled. Removing CFGM reading and
133 * validation of such options as well as state members for them.
134 * - Callbacks for ring-0 and raw-mode are registered in a context contructor.
135 * Setting up of non-default critical section handling needs to be repeated
136 * in the ring-0/raw-mode context constructor too. See for instance
137 * e1kRZConstruct().
138 *
139 * - Convert all PDMCritSect calls to PDMDevHlpCritSect.
140 * Note! pDevIns should be passed as parameter rather than put in pThisCC.
141 *
142 * - Convert all timers to the handle based ones.
143 *
144 * - Convert all queues to the handle based ones or tasks.
145 *
146 * - Set the PDM_DEVREG_FLAGS_NEW_STYLE in the registration structure.
147 *
148 * - Convert all CFGMR3Xxxx calls to pHlp->pfnCFGMXxxx.
149 *
150 * - Convert all SSMR3Xxxx calls to pHlp->pfnSSMXxxx.
151 *
152 * - Ensure that CFGM values and nodes are validated using PDMDEV_VALIDATE_CONFIG_RETURN()
153 *
154 * - Ensure that the first statement in the constructors is
155 * @code
156 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
157 @endcode
158 * There shall be absolutely nothing preceeding that and it is mandatory.
159 *
160 * - Ensure that the first statement in the destructors is
161 * @code
162 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
163 @endcode
164 * There shall be absolutely nothing preceeding that and it is mandatory.
165 *
166 * - Use 'nm -u' (tools\win.amd64\mingw-w64\r1\bin\nm.exe on windows) to check for
167 * VBoxVMM and VMMR0 function you forgot to convert to device help calls or would
168 * need adding as device helpers or something.
169 *
170 *
171 * @section sec_pdm_special_devs Special Devices
172 *
173 * Several kinds of devices interacts with the VMM and/or other device and PDM
174 * will work like a mediator for these. The typical pattern is that the device
175 * calls a special registration device helper with a set of callbacks, PDM
176 * responds by copying this and providing a pointer to a set helper callbacks
177 * for that particular kind of device. Unlike interfaces where the callback
178 * table pointer is used a 'this' pointer, these arrangements will use the
179 * device instance pointer (PPDMDEVINS) as a kind of 'this' pointer.
180 *
181 * For an example of this kind of setup, see the PIC. The PIC registers itself
182 * by calling PDMDEVHLPR3::pfnPICRegister. PDM saves the device instance,
183 * copies the callback tables (PDMPICREG), resolving the ring-0 and raw-mode
184 * addresses in the process, and hands back the pointer to a set of helper
185 * methods (PDMPICHLPR3). The PCI device then queries the ring-0 and raw-mode
186 * helpers using PDMPICHLPR3::pfnGetR0Helpers and PDMPICHLPR3::pfnGetRCHelpers.
187 * The PCI device repeats ths pfnGetRCHelpers call in it's relocation method
188 * since the address changes when RC is relocated.
189 *
190 * @see grp_pdm_device
191 *
192 * @section sec_pdm_usbdev The Pluggable USB Devices
193 *
194 * USB devices are handled a little bit differently than other devices. The
195 * general concepts wrt. pluggability are mostly the same, but the details
196 * varies. The registration entry point is 'VBoxUsbRegister', the device
197 * instance is PDMUSBINS and the callbacks helpers are different. Also, USB
198 * device are restricted to ring-3 and cannot have any ring-0 or raw-mode
199 * extensions (at least not yet).
200 *
201 * The way USB devices work differs greatly from other devices though since they
202 * aren't attaches directly to the PCI/ISA/whatever system buses but via a
203 * USB host control (OHCI, UHCI or EHCI). USB devices handle USB requests
204 * (URBs) and does not register I/O ports, MMIO ranges or PCI bus
205 * devices/functions.
206 *
207 * @see grp_pdm_usbdev
208 *
209 *
210 * @section sec_pdm_drv The Pluggable Drivers
211 *
212 * The VM devices are often accessing host hardware or OS facilities. For most
213 * devices these facilities can be abstracted in one or more levels. These
214 * abstractions are called drivers.
215 *
216 * For instance take a DVD/CD drive. This can be connected to a SCSI
217 * controller, an ATA controller or a SATA controller. The basics of the DVD/CD
218 * drive implementation remains the same - eject, insert, read, seek, and such.
219 * (For the scsi SCSCI, you might want to speak SCSI directly to, but that can of
220 * course be fixed - see SCSI passthru.) So, it
221 * makes much sense to have a generic CD/DVD driver which implements this.
222 *
223 * Then the media 'inserted' into the DVD/CD drive can be a ISO image, or it can
224 * be read from a real CD or DVD drive (there are probably other custom formats
225 * someone could desire to read or construct too). So, it would make sense to
226 * have abstracted interfaces for dealing with this in a generic way so the
227 * cdrom unit doesn't have to implement it all. Thus we have created the
228 * CDROM/DVD media driver family.
229 *
230 * So, for this example the IDE controller #1 (i.e. secondary) will have
231 * the DVD/CD Driver attached to it's LUN #0 (master). When a media is mounted
232 * the DVD/CD Driver will have a ISO, HostDVD or RAW (media) Driver attached.
233 *
234 * It is possible to configure many levels of drivers inserting filters, loggers,
235 * or whatever you desire into the chain. We're using this for network sniffing,
236 * for instance.
237 *
238 * The drivers are loaded in a similar manner to that of a device, namely by
239 * iterating a keyspace in CFGM, load the modules listed there and call
240 * 'VBoxDriversRegister' with a callback table.
241 *
242 * @see grp_pdm_driver
243 *
244 *
245 * @section sec_pdm_ifs Interfaces
246 *
247 * The pluggable drivers and devices expose one standard interface (callback
248 * table) which is used to construct, destruct, attach, detach,( ++,) and query
249 * other interfaces. A device will query the interfaces required for it's
250 * operation during init and hot-plug. PDM may query some interfaces during
251 * runtime mounting too.
252 *
253 * An interface here means a function table contained within the device or
254 * driver instance data. Its methods are invoked with the function table pointer
255 * as the first argument and they will calculate the address of the device or
256 * driver instance data from it. (This is one of the aspects which *might* have
257 * been better done in C++.)
258 *
259 * @see grp_pdm_interfaces
260 *
261 *
262 * @section sec_pdm_utils Utilities
263 *
264 * As mentioned earlier, PDM is the location of any usful constructs that doesn't
265 * quite fit into IPRT. The next subsections will discuss these.
266 *
267 * One thing these APIs all have in common is that resources will be associated
268 * with a device / driver and automatically freed after it has been destroyed if
269 * the destructor didn't do this.
270 *
271 *
272 * @subsection sec_pdm_async_completion Async I/O
273 *
274 * The PDM Async I/O API provides a somewhat platform agnostic interface for
275 * asynchronous I/O. For reasons of performance and complexity this does not
276 * build upon any IPRT API.
277 *
278 * @todo more details.
279 *
280 * @see grp_pdm_async_completion
281 *
282 *
283 * @subsection sec_pdm_async_task Async Task - not implemented
284 *
285 * @todo implement and describe
286 *
287 * @see grp_pdm_async_task
288 *
289 *
290 * @subsection sec_pdm_critsect Critical Section
291 *
292 * The PDM Critical Section API is currently building on the IPRT API with the
293 * same name. It adds the possibility to use critical sections in ring-0 and
294 * raw-mode as well as in ring-3. There are certain restrictions on the RC and
295 * R0 usage though since we're not able to wait on it, nor wake up anyone that
296 * is waiting on it. These restrictions origins with the use of a ring-3 event
297 * semaphore. In a later incarnation we plan to replace the ring-3 event
298 * semaphore with a ring-0 one, thus enabling us to wake up waiters while
299 * exectuing in ring-0 and making the hardware assisted execution mode more
300 * efficient. (Raw-mode won't benefit much from this, naturally.)
301 *
302 * @see grp_pdm_critsect
303 *
304 *
305 * @subsection sec_pdm_queue Queue
306 *
307 * The PDM Queue API is for queuing one or more tasks for later consumption in
308 * ring-3 by EMT, and optionally forcing a delayed or ASAP return to ring-3. The
309 * queues can also be run on a timer basis as an alternative to the ASAP thing.
310 * The queue will be flushed at forced action time.
311 *
312 * A queue can also be used by another thread (a I/O worker for instance) to
313 * send work / events over to the EMT.
314 *
315 * @see grp_pdm_queue
316 *
317 *
318 * @subsection sec_pdm_task Task - not implemented yet
319 *
320 * The PDM Task API is for flagging a task for execution at a later point when
321 * we're back in ring-3, optionally forcing the ring-3 return to happen ASAP.
322 * As you can see the concept is similar to queues only simpler.
323 *
324 * A task can also be scheduled by another thread (a I/O worker for instance) as
325 * a mean of getting something done in EMT.
326 *
327 * @see grp_pdm_task
328 *
329 *
330 * @subsection sec_pdm_thread Thread
331 *
332 * The PDM Thread API is there to help devices and drivers manage their threads
333 * correctly wrt. power on, suspend, resume, power off and destruction.
334 *
335 * The general usage pattern for threads in the employ of devices and drivers is
336 * that they shuffle data or requests while the VM is running and stop doing
337 * this when the VM is paused or powered down. Rogue threads running while the
338 * VM is paused can cause the state to change during saving or have other
339 * unwanted side effects. The PDM Threads API ensures that this won't happen.
340 *
341 * @see grp_pdm_thread
342 *
343 */
344
345
346/*********************************************************************************************************************************
347* Header Files *
348*********************************************************************************************************************************/
349#define LOG_GROUP LOG_GROUP_PDM
350#define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
351#include "PDMInternal.h"
352#include <VBox/vmm/pdm.h>
353#include <VBox/vmm/em.h>
354#include <VBox/vmm/mm.h>
355#include <VBox/vmm/pgm.h>
356#include <VBox/vmm/ssm.h>
357#include <VBox/vmm/hm.h>
358#include <VBox/vmm/vm.h>
359#include <VBox/vmm/uvm.h>
360#include <VBox/vmm/vmm.h>
361#include <VBox/param.h>
362#include <VBox/err.h>
363#include <VBox/sup.h>
364
365#include <VBox/log.h>
366#include <iprt/asm.h>
367#include <iprt/assert.h>
368#include <iprt/alloc.h>
369#include <iprt/ctype.h>
370#include <iprt/ldr.h>
371#include <iprt/path.h>
372#include <iprt/string.h>
373
374
375/*********************************************************************************************************************************
376* Defined Constants And Macros *
377*********************************************************************************************************************************/
378/** The PDM saved state version. */
379#define PDM_SAVED_STATE_VERSION 5
380/** Before the PDM audio architecture was introduced there was an "AudioSniffer"
381 * device which took care of multiplexing input/output audio data from/to various places.
382 * Thus this device is not needed/used anymore. */
383#define PDM_SAVED_STATE_VERSION_PRE_PDM_AUDIO 4
384#define PDM_SAVED_STATE_VERSION_PRE_NMI_FF 3
385
386/** The number of nanoseconds a suspend callback needs to take before
387 * PDMR3Suspend warns about it taking too long. */
388#define PDMSUSPEND_WARN_AT_NS UINT64_C(1200000000)
389
390/** The number of nanoseconds a suspend callback needs to take before
391 * PDMR3PowerOff warns about it taking too long. */
392#define PDMPOWEROFF_WARN_AT_NS UINT64_C( 900000000)
393
394
395/*********************************************************************************************************************************
396* Structures and Typedefs *
397*********************************************************************************************************************************/
398/**
399 * Statistics of asynchronous notification tasks - used by reset, suspend and
400 * power off.
401 */
402typedef struct PDMNOTIFYASYNCSTATS
403{
404 /** The start timestamp. */
405 uint64_t uStartNsTs;
406 /** When to log the next time. */
407 uint64_t cNsElapsedNextLog;
408 /** The loop counter. */
409 uint32_t cLoops;
410 /** The number of pending asynchronous notification tasks. */
411 uint32_t cAsync;
412 /** The name of the operation (log prefix). */
413 const char *pszOp;
414 /** The current list buffer position. */
415 size_t offList;
416 /** String containing a list of the pending tasks. */
417 char szList[1024];
418} PDMNOTIFYASYNCSTATS;
419/** Pointer to the stats of pending asynchronous notification tasks. */
420typedef PDMNOTIFYASYNCSTATS *PPDMNOTIFYASYNCSTATS;
421
422
423/*********************************************************************************************************************************
424* Internal Functions *
425*********************************************************************************************************************************/
426static DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass);
427static DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM);
428static DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
429static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
430
431static FNDBGFHANDLERINT pdmR3InfoTracingIds;
432
433
434/**
435 * Initializes the PDM part of the UVM.
436 *
437 * This doesn't really do much right now but has to be here for the sake
438 * of completeness.
439 *
440 * @returns VBox status code.
441 * @param pUVM Pointer to the user mode VM structure.
442 */
443VMMR3_INT_DECL(int) PDMR3InitUVM(PUVM pUVM)
444{
445 AssertCompile(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
446 AssertRelease(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
447 pUVM->pdm.s.pModules = NULL;
448 pUVM->pdm.s.pCritSects = NULL;
449 pUVM->pdm.s.pRwCritSects = NULL;
450 return RTCritSectInit(&pUVM->pdm.s.ListCritSect);
451}
452
453
454/**
455 * Initializes the PDM.
456 *
457 * @returns VBox status code.
458 * @param pVM The cross context VM structure.
459 */
460VMMR3_INT_DECL(int) PDMR3Init(PVM pVM)
461{
462 LogFlow(("PDMR3Init\n"));
463
464 /*
465 * Assert alignment and sizes.
466 */
467 AssertRelease(!(RT_UOFFSETOF(VM, pdm.s) & 31));
468 AssertRelease(sizeof(pVM->pdm.s) <= sizeof(pVM->pdm.padding));
469 AssertCompileMemberAlignment(PDM, CritSect, sizeof(uintptr_t));
470
471 /*
472 * Init the structure.
473 */
474 pVM->pdm.s.GCPhysVMMDevHeap = NIL_RTGCPHYS;
475 //pVM->pdm.s.idTracingDev = 0;
476 pVM->pdm.s.idTracingOther = 1024;
477
478 /*
479 * Initialize critical sections first.
480 */
481 int rc = pdmR3CritSectBothInitStats(pVM);
482 if (RT_SUCCESS(rc))
483 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, RT_SRC_POS, "PDM");
484 if (RT_SUCCESS(rc))
485 {
486 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.NopCritSect, RT_SRC_POS, "NOP");
487 if (RT_SUCCESS(rc))
488 pVM->pdm.s.NopCritSect.s.Core.fFlags |= RTCRITSECT_FLAGS_NOP;
489 }
490
491 /*
492 * Initialize sub components.
493 */
494 if (RT_SUCCESS(rc))
495 rc = pdmR3TaskInit(pVM);
496 if (RT_SUCCESS(rc))
497 rc = pdmR3LdrInitU(pVM->pUVM);
498#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
499 if (RT_SUCCESS(rc))
500 rc = pdmR3AsyncCompletionInit(pVM);
501#endif
502#ifdef VBOX_WITH_NETSHAPER
503 if (RT_SUCCESS(rc))
504 rc = pdmR3NetShaperInit(pVM);
505#endif
506 if (RT_SUCCESS(rc))
507 rc = pdmR3BlkCacheInit(pVM);
508 if (RT_SUCCESS(rc))
509 rc = pdmR3DrvInit(pVM);
510 if (RT_SUCCESS(rc))
511 rc = pdmR3DevInit(pVM);
512 if (RT_SUCCESS(rc))
513 {
514 /*
515 * Register the saved state data unit.
516 */
517 rc = SSMR3RegisterInternal(pVM, "pdm", 1, PDM_SAVED_STATE_VERSION, 128,
518 NULL, pdmR3LiveExec, NULL,
519 NULL, pdmR3SaveExec, NULL,
520 pdmR3LoadPrep, pdmR3LoadExec, NULL);
521 if (RT_SUCCESS(rc))
522 {
523 /*
524 * Register the info handlers.
525 */
526 DBGFR3InfoRegisterInternal(pVM, "pdmtracingids",
527 "Displays the tracing IDs assigned by PDM to devices, USB device, drivers and more.",
528 pdmR3InfoTracingIds);
529
530 LogFlow(("PDM: Successfully initialized\n"));
531 return rc;
532 }
533 }
534
535 /*
536 * Cleanup and return failure.
537 */
538 PDMR3Term(pVM);
539 LogFlow(("PDMR3Init: returns %Rrc\n", rc));
540 return rc;
541}
542
543
544/**
545 * Init phase completed callback.
546 *
547 * We use this for calling PDMDEVREG::pfnInitComplete callback after everything
548 * else has been initialized.
549 *
550 * @returns VBox status code.
551 * @param pVM The cross context VM structure.
552 * @param enmWhat The phase that was completed.
553 */
554VMMR3_INT_DECL(int) PDMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat)
555{
556 if (enmWhat == VMINITCOMPLETED_RING0)
557 return pdmR3DevInitComplete(pVM);
558 return VINF_SUCCESS;
559}
560
561
562/**
563 * Applies relocations to data and code managed by this
564 * component. This function will be called at init and
565 * whenever the VMM need to relocate it self inside the GC.
566 *
567 * @param pVM The cross context VM structure.
568 * @param offDelta Relocation delta relative to old location.
569 * @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
570 * early in the relocation phase.
571 */
572VMMR3_INT_DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
573{
574 LogFlow(("PDMR3Relocate\n"));
575
576 /*
577 * Queues.
578 */
579 pdmR3QueueRelocate(pVM, offDelta);
580 pVM->pdm.s.pDevHlpQueueRC = PDMQueueRCPtr(pVM->pdm.s.pDevHlpQueueR3);
581
582 /*
583 * Critical sections.
584 */
585 pdmR3CritSectBothRelocate(pVM);
586
587 /*
588 * The registered PIC.
589 */
590 if (pVM->pdm.s.Pic.pDevInsRC)
591 {
592 pVM->pdm.s.Pic.pDevInsRC += offDelta;
593 pVM->pdm.s.Pic.pfnSetIrqRC += offDelta;
594 pVM->pdm.s.Pic.pfnGetInterruptRC += offDelta;
595 }
596
597 /*
598 * The registered APIC.
599 */
600 if (pVM->pdm.s.Apic.pDevInsRC)
601 pVM->pdm.s.Apic.pDevInsRC += offDelta;
602
603 /*
604 * The registered I/O APIC.
605 */
606 if (pVM->pdm.s.IoApic.pDevInsRC)
607 {
608 pVM->pdm.s.IoApic.pDevInsRC += offDelta;
609 pVM->pdm.s.IoApic.pfnSetIrqRC += offDelta;
610 if (pVM->pdm.s.IoApic.pfnSendMsiRC)
611 pVM->pdm.s.IoApic.pfnSendMsiRC += offDelta;
612 if (pVM->pdm.s.IoApic.pfnSetEoiRC)
613 pVM->pdm.s.IoApic.pfnSetEoiRC += offDelta;
614 }
615
616 /*
617 * Devices & Drivers.
618 */
619#ifdef VBOX_WITH_RAW_MODE_KEEP /* needs fixing */
620 int rc;
621 PCPDMDEVHLPRC pDevHlpRC = NIL_RTRCPTR;
622 if (VM_IS_RAW_MODE_ENABLED(pVM))
623 {
624 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDevHlp", &pDevHlpRC);
625 AssertReleaseMsgRC(rc, ("rc=%Rrc when resolving g_pdmRCDevHlp\n", rc));
626 }
627
628 PCPDMDRVHLPRC pDrvHlpRC = NIL_RTRCPTR;
629 if (VM_IS_RAW_MODE_ENABLED(pVM))
630 {
631 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDevHlp", &pDrvHlpRC);
632 AssertReleaseMsgRC(rc, ("rc=%Rrc when resolving g_pdmRCDevHlp\n", rc));
633 }
634
635 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
636 {
637 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
638 {
639 pDevIns->pHlpRC = pDevHlpRC;
640 pDevIns->pvInstanceDataRC = MMHyperR3ToRC(pVM, pDevIns->pvInstanceDataR3);
641 if (pDevIns->pCritSectRoR3)
642 pDevIns->pCritSectRoRC = MMHyperR3ToRC(pVM, pDevIns->pCritSectRoR3);
643 pDevIns->Internal.s.pVMRC = pVM->pVMRC;
644
645 PPDMPCIDEV pPciDev = pDevIns->Internal.s.pHeadPciDevR3;
646 if (pPciDev)
647 {
648 pDevIns->Internal.s.pHeadPciDevRC = MMHyperR3ToRC(pVM, pPciDev);
649 do
650 {
651 pPciDev->Int.s.pDevInsRC = MMHyperR3ToRC(pVM, pPciDev->Int.s.pDevInsR3);
652 pPciDev->Int.s.pPdmBusRC = MMHyperR3ToRC(pVM, pPciDev->Int.s.pPdmBusR3);
653 if (pPciDev->Int.s.pNextR3)
654 pPciDev->Int.s.pNextRC = MMHyperR3ToRC(pVM, pPciDev->Int.s.pNextR3);
655 pPciDev = pPciDev->Int.s.pNextR3;
656 } while (pPciDev);
657 }
658
659 if (pDevIns->pReg->pfnRelocate)
660 {
661 LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
662 pDevIns->pReg->szName, pDevIns->iInstance));
663 pDevIns->pReg->pfnRelocate(pDevIns, offDelta);
664 }
665 }
666
667 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
668 {
669 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
670 {
671 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
672 {
673 pDrvIns->pHlpRC = pDrvHlpRC;
674 pDrvIns->pvInstanceDataRC = MMHyperR3ToRC(pVM, pDrvIns->pvInstanceDataR3);
675 pDrvIns->Internal.s.pVMRC = pVM->pVMRC;
676 if (pDrvIns->pReg->pfnRelocate)
677 {
678 LogFlow(("PDMR3Relocate: Relocating driver '%s'/%u attached to '%s'/%d/%u\n",
679 pDrvIns->pReg->szName, pDrvIns->iInstance,
680 pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun));
681 pDrvIns->pReg->pfnRelocate(pDrvIns, offDelta);
682 }
683 }
684 }
685 }
686
687 }
688#endif
689}
690
691
692/**
693 * Worker for pdmR3Term that terminates a LUN chain.
694 *
695 * @param pVM The cross context VM structure.
696 * @param pLun The head of the chain.
697 * @param pszDevice The name of the device (for logging).
698 * @param iInstance The device instance number (for logging).
699 */
700static void pdmR3TermLuns(PVM pVM, PPDMLUN pLun, const char *pszDevice, unsigned iInstance)
701{
702 RT_NOREF2(pszDevice, iInstance);
703
704 for (; pLun; pLun = pLun->pNext)
705 {
706 /*
707 * Destroy them one at a time from the bottom up.
708 * (The serial device/drivers depends on this - bad.)
709 */
710 PPDMDRVINS pDrvIns = pLun->pBottom;
711 pLun->pBottom = pLun->pTop = NULL;
712 while (pDrvIns)
713 {
714 PPDMDRVINS pDrvNext = pDrvIns->Internal.s.pUp;
715
716 if (pDrvIns->pReg->pfnDestruct)
717 {
718 LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
719 pDrvIns->pReg->szName, pDrvIns->iInstance, pLun->iLun, pszDevice, iInstance));
720 pDrvIns->pReg->pfnDestruct(pDrvIns);
721 }
722 pDrvIns->Internal.s.pDrv->cInstances--;
723
724 /* Order of resource freeing like in pdmR3DrvDestroyChain, but
725 * not all need to be done as they are done globally later. */
726 //PDMR3QueueDestroyDriver(pVM, pDrvIns);
727 TMR3TimerDestroyDriver(pVM, pDrvIns);
728 SSMR3DeregisterDriver(pVM, pDrvIns, NULL, 0);
729 //pdmR3ThreadDestroyDriver(pVM, pDrvIns);
730 //DBGFR3InfoDeregisterDriver(pVM, pDrvIns, NULL);
731 //pdmR3CritSectBothDeleteDriver(pVM, pDrvIns);
732 //PDMR3BlkCacheReleaseDriver(pVM, pDrvIns);
733#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
734 //pdmR3AsyncCompletionTemplateDestroyDriver(pVM, pDrvIns);
735#endif
736
737 /* Clear the driver struture to catch sloppy code. */
738 ASMMemFill32(pDrvIns, RT_UOFFSETOF_DYN(PDMDRVINS, achInstanceData[pDrvIns->pReg->cbInstance]), 0xdeadd0d0);
739
740 pDrvIns = pDrvNext;
741 }
742 }
743}
744
745
746/**
747 * Terminates the PDM.
748 *
749 * Termination means cleaning up and freeing all resources,
750 * the VM it self is at this point powered off or suspended.
751 *
752 * @returns VBox status code.
753 * @param pVM The cross context VM structure.
754 */
755VMMR3_INT_DECL(int) PDMR3Term(PVM pVM)
756{
757 LogFlow(("PDMR3Term:\n"));
758 AssertMsg(PDMCritSectIsInitialized(&pVM->pdm.s.CritSect), ("bad init order!\n"));
759
760 /*
761 * Iterate the device instances and attach drivers, doing
762 * relevant destruction processing.
763 *
764 * N.B. There is no need to mess around freeing memory allocated
765 * from any MM heap since MM will do that in its Term function.
766 */
767 /* usb ones first. */
768 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
769 {
770 pdmR3TermLuns(pVM, pUsbIns->Internal.s.pLuns, pUsbIns->pReg->szName, pUsbIns->iInstance);
771
772 /*
773 * Detach it from the HUB (if it's actually attached to one) so the HUB has
774 * a chance to stop accessing any data.
775 */
776 PPDMUSBHUB pHub = pUsbIns->Internal.s.pHub;
777 if (pHub)
778 {
779 int rc = pHub->Reg.pfnDetachDevice(pHub->pDrvIns, pUsbIns, pUsbIns->Internal.s.iPort);
780 if (RT_FAILURE(rc))
781 {
782 LogRel(("PDM: Failed to detach USB device '%s' instance %d from %p: %Rrc\n",
783 pUsbIns->pReg->szName, pUsbIns->iInstance, pHub, rc));
784 }
785 else
786 {
787 pHub->cAvailablePorts++;
788 Assert(pHub->cAvailablePorts > 0 && pHub->cAvailablePorts <= pHub->cPorts);
789 pUsbIns->Internal.s.pHub = NULL;
790 }
791 }
792
793 if (pUsbIns->pReg->pfnDestruct)
794 {
795 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
796 pUsbIns->pReg->szName, pUsbIns->iInstance));
797 pUsbIns->pReg->pfnDestruct(pUsbIns);
798 }
799
800 //TMR3TimerDestroyUsb(pVM, pUsbIns);
801 //SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
802 pdmR3ThreadDestroyUsb(pVM, pUsbIns);
803 }
804
805 /* then the 'normal' ones. */
806 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
807 {
808 pdmR3TermLuns(pVM, pDevIns->Internal.s.pLunsR3, pDevIns->pReg->szName, pDevIns->iInstance);
809
810 if (pDevIns->pReg->pfnDestruct)
811 {
812 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
813 pDevIns->pReg->pfnDestruct(pDevIns);
814 }
815
816 if (pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_R0_CONTRUCT)
817 {
818 LogFlow(("pdmR3DevTerm: Destroying (ring-0) - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
819 PDMDEVICEGENCALLREQ Req;
820 RT_ZERO(Req.Params);
821 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
822 Req.Hdr.cbReq = sizeof(Req);
823 Req.enmCall = PDMDEVICEGENCALL_DESTRUCT;
824 Req.idxR0Device = pDevIns->Internal.s.idxR0Device;
825 Req.pDevInsR3 = pDevIns;
826 int rc2 = VMMR3CallR0(pVM, VMMR0_DO_PDM_DEVICE_GEN_CALL, 0, &Req.Hdr);
827 AssertRC(rc2);
828 }
829
830 TMR3TimerDestroyDevice(pVM, pDevIns);
831 SSMR3DeregisterDevice(pVM, pDevIns, NULL, 0);
832 pdmR3CritSectBothDeleteDevice(pVM, pDevIns);
833 pdmR3ThreadDestroyDevice(pVM, pDevIns);
834 PDMR3QueueDestroyDevice(pVM, pDevIns);
835 PGMR3PhysMMIOExDeregister(pVM, pDevIns, UINT32_MAX, UINT32_MAX);
836#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
837 pdmR3AsyncCompletionTemplateDestroyDevice(pVM, pDevIns);
838#endif
839 DBGFR3InfoDeregisterDevice(pVM, pDevIns, NULL);
840 }
841
842 /*
843 * Destroy all threads.
844 */
845 pdmR3ThreadDestroyAll(pVM);
846
847 /*
848 * Destroy the block cache.
849 */
850 pdmR3BlkCacheTerm(pVM);
851
852#ifdef VBOX_WITH_NETSHAPER
853 /*
854 * Destroy network bandwidth groups.
855 */
856 pdmR3NetShaperTerm(pVM);
857#endif
858#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
859 /*
860 * Free async completion managers.
861 */
862 pdmR3AsyncCompletionTerm(pVM);
863#endif
864
865 /*
866 * Free modules.
867 */
868 pdmR3LdrTermU(pVM->pUVM);
869
870 /*
871 * Stop task threads.
872 */
873 pdmR3TaskTerm(pVM);
874
875 /*
876 * Destroy the PDM lock.
877 */
878 PDMR3CritSectDelete(&pVM->pdm.s.CritSect);
879 /* The MiscCritSect is deleted by PDMR3CritSectBothTerm later. */
880
881 LogFlow(("PDMR3Term: returns %Rrc\n", VINF_SUCCESS));
882 return VINF_SUCCESS;
883}
884
885
886/**
887 * Terminates the PDM part of the UVM.
888 *
889 * This will unload any modules left behind.
890 *
891 * @param pUVM Pointer to the user mode VM structure.
892 */
893VMMR3_INT_DECL(void) PDMR3TermUVM(PUVM pUVM)
894{
895 /*
896 * In the normal cause of events we will now call pdmR3LdrTermU for
897 * the second time. In the case of init failure however, this might
898 * the first time, which is why we do it.
899 */
900 pdmR3LdrTermU(pUVM);
901
902 Assert(pUVM->pdm.s.pCritSects == NULL);
903 Assert(pUVM->pdm.s.pRwCritSects == NULL);
904 RTCritSectDelete(&pUVM->pdm.s.ListCritSect);
905}
906
907
908/**
909 * For APIC assertions.
910 *
911 * @returns true if we've loaded state.
912 * @param pVM The cross context VM structure.
913 */
914VMMR3_INT_DECL(bool) PDMR3HasLoadedState(PVM pVM)
915{
916 return pVM->pdm.s.fStateLoaded;
917}
918
919
920/**
921 * Bits that are saved in pass 0 and in the final pass.
922 *
923 * @param pVM The cross context VM structure.
924 * @param pSSM The saved state handle.
925 */
926static void pdmR3SaveBoth(PVM pVM, PSSMHANDLE pSSM)
927{
928 /*
929 * Save the list of device instances so we can check that they're all still
930 * there when we load the state and that nothing new has been added.
931 */
932 uint32_t i = 0;
933 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3, i++)
934 {
935 SSMR3PutU32(pSSM, i);
936 SSMR3PutStrZ(pSSM, pDevIns->pReg->szName);
937 SSMR3PutU32(pSSM, pDevIns->iInstance);
938 }
939 SSMR3PutU32(pSSM, UINT32_MAX); /* terminator */
940}
941
942
943/**
944 * Live save.
945 *
946 * @returns VBox status code.
947 * @param pVM The cross context VM structure.
948 * @param pSSM The saved state handle.
949 * @param uPass The pass.
950 */
951static DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass)
952{
953 LogFlow(("pdmR3LiveExec:\n"));
954 AssertReturn(uPass == 0, VERR_SSM_UNEXPECTED_PASS);
955 pdmR3SaveBoth(pVM, pSSM);
956 return VINF_SSM_DONT_CALL_AGAIN;
957}
958
959
960/**
961 * Execute state save operation.
962 *
963 * @returns VBox status code.
964 * @param pVM The cross context VM structure.
965 * @param pSSM The saved state handle.
966 */
967static DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM)
968{
969 LogFlow(("pdmR3SaveExec:\n"));
970
971 /*
972 * Save interrupt and DMA states.
973 */
974 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
975 {
976 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
977 SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC));
978 SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC));
979 SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI));
980 SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI));
981 }
982 SSMR3PutU32(pSSM, VM_FF_IS_SET(pVM, VM_FF_PDM_DMA));
983
984 pdmR3SaveBoth(pVM, pSSM);
985 return VINF_SUCCESS;
986}
987
988
989/**
990 * Prepare state load operation.
991 *
992 * This will dispatch pending operations and clear the FFs governed by PDM and its devices.
993 *
994 * @returns VBox status code.
995 * @param pVM The cross context VM structure.
996 * @param pSSM The SSM handle.
997 */
998static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
999{
1000 LogFlow(("pdmR3LoadPrep: %s%s\n",
1001 VM_FF_IS_SET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
1002 VM_FF_IS_SET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : ""));
1003#ifdef LOG_ENABLED
1004 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1005 {
1006 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
1007 LogFlow(("pdmR3LoadPrep: VCPU %u %s%s\n", idCpu,
1008 VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC) ? " VMCPU_FF_INTERRUPT_APIC" : "",
1009 VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC) ? " VMCPU_FF_INTERRUPT_PIC" : ""));
1010 }
1011#endif
1012 NOREF(pSSM);
1013
1014 /*
1015 * In case there is work pending that will raise an interrupt,
1016 * start a DMA transfer, or release a lock. (unlikely)
1017 */
1018 if (VM_FF_IS_SET(pVM, VM_FF_PDM_QUEUES))
1019 PDMR3QueueFlushAll(pVM);
1020
1021 /* Clear the FFs. */
1022 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1023 {
1024 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
1025 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
1026 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
1027 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
1028 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
1029 }
1030 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
1031
1032 return VINF_SUCCESS;
1033}
1034
1035
1036/**
1037 * Execute state load operation.
1038 *
1039 * @returns VBox status code.
1040 * @param pVM The cross context VM structure.
1041 * @param pSSM SSM operation handle.
1042 * @param uVersion Data layout version.
1043 * @param uPass The data pass.
1044 */
1045static DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1046{
1047 int rc;
1048
1049 LogFlow(("pdmR3LoadExec: uPass=%#x\n", uPass));
1050
1051 /*
1052 * Validate version.
1053 */
1054 if ( uVersion != PDM_SAVED_STATE_VERSION
1055 && uVersion != PDM_SAVED_STATE_VERSION_PRE_NMI_FF
1056 && uVersion != PDM_SAVED_STATE_VERSION_PRE_PDM_AUDIO)
1057 {
1058 AssertMsgFailed(("Invalid version uVersion=%d!\n", uVersion));
1059 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1060 }
1061
1062 if (uPass == SSM_PASS_FINAL)
1063 {
1064 /*
1065 * Load the interrupt and DMA states.
1066 *
1067 * The APIC, PIC and DMA devices does not restore these, we do. In the
1068 * APIC and PIC cases, it is possible that some devices is incorrectly
1069 * setting IRQs during restore. We'll warn when this happens. (There
1070 * are debug assertions in PDMDevMiscHlp.cpp and APICAll.cpp for
1071 * catching the buggy device.)
1072 */
1073 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1074 {
1075 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
1076
1077 /* APIC interrupt */
1078 uint32_t fInterruptPending = 0;
1079 rc = SSMR3GetU32(pSSM, &fInterruptPending);
1080 if (RT_FAILURE(rc))
1081 return rc;
1082 if (fInterruptPending & ~1)
1083 {
1084 AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
1085 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1086 }
1087 AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC),
1088 ("VCPU%03u: VMCPU_FF_INTERRUPT_APIC set! Devices shouldn't set interrupts during state restore...\n", idCpu));
1089 if (fInterruptPending)
1090 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC);
1091
1092 /* PIC interrupt */
1093 fInterruptPending = 0;
1094 rc = SSMR3GetU32(pSSM, &fInterruptPending);
1095 if (RT_FAILURE(rc))
1096 return rc;
1097 if (fInterruptPending & ~1)
1098 {
1099 AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
1100 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1101 }
1102 AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC),
1103 ("VCPU%03u: VMCPU_FF_INTERRUPT_PIC set! Devices shouldn't set interrupts during state restore...\n", idCpu));
1104 if (fInterruptPending)
1105 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
1106
1107 if (uVersion > PDM_SAVED_STATE_VERSION_PRE_NMI_FF)
1108 {
1109 /* NMI interrupt */
1110 fInterruptPending = 0;
1111 rc = SSMR3GetU32(pSSM, &fInterruptPending);
1112 if (RT_FAILURE(rc))
1113 return rc;
1114 if (fInterruptPending & ~1)
1115 {
1116 AssertMsgFailed(("fInterruptPending=%#x (NMI)\n", fInterruptPending));
1117 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1118 }
1119 AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI), ("VCPU%3u: VMCPU_FF_INTERRUPT_NMI set!\n", idCpu));
1120 if (fInterruptPending)
1121 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI);
1122
1123 /* SMI interrupt */
1124 fInterruptPending = 0;
1125 rc = SSMR3GetU32(pSSM, &fInterruptPending);
1126 if (RT_FAILURE(rc))
1127 return rc;
1128 if (fInterruptPending & ~1)
1129 {
1130 AssertMsgFailed(("fInterruptPending=%#x (SMI)\n", fInterruptPending));
1131 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1132 }
1133 AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI), ("VCPU%3u: VMCPU_FF_INTERRUPT_SMI set!\n", idCpu));
1134 if (fInterruptPending)
1135 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI);
1136 }
1137 }
1138
1139 /* DMA pending */
1140 uint32_t fDMAPending = 0;
1141 rc = SSMR3GetU32(pSSM, &fDMAPending);
1142 if (RT_FAILURE(rc))
1143 return rc;
1144 if (fDMAPending & ~1)
1145 {
1146 AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
1147 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1148 }
1149 if (fDMAPending)
1150 VM_FF_SET(pVM, VM_FF_PDM_DMA);
1151 Log(("pdmR3LoadExec: VM_FF_PDM_DMA=%RTbool\n", VM_FF_IS_SET(pVM, VM_FF_PDM_DMA)));
1152 }
1153
1154 /*
1155 * Load the list of devices and verify that they are all there.
1156 */
1157 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1158 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_FOUND;
1159
1160 for (uint32_t i = 0; ; i++)
1161 {
1162 /* Get the sequence number / terminator. */
1163 uint32_t u32Sep;
1164 rc = SSMR3GetU32(pSSM, &u32Sep);
1165 if (RT_FAILURE(rc))
1166 return rc;
1167 if (u32Sep == UINT32_MAX)
1168 break;
1169 if (u32Sep != i)
1170 AssertMsgFailedReturn(("Out of sequence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
1171
1172 /* Get the name and instance number. */
1173 char szName[RT_SIZEOFMEMB(PDMDEVREG, szName)];
1174 rc = SSMR3GetStrZ(pSSM, szName, sizeof(szName));
1175 if (RT_FAILURE(rc))
1176 return rc;
1177 uint32_t iInstance;
1178 rc = SSMR3GetU32(pSSM, &iInstance);
1179 if (RT_FAILURE(rc))
1180 return rc;
1181
1182 /* Try locate it. */
1183 PPDMDEVINS pDevIns;
1184 for (pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1185 if ( !RTStrCmp(szName, pDevIns->pReg->szName)
1186 && pDevIns->iInstance == iInstance)
1187 {
1188 AssertLogRelMsgReturn(!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND),
1189 ("%s/#%u\n", pDevIns->pReg->szName, pDevIns->iInstance),
1190 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
1191 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_FOUND;
1192 break;
1193 }
1194
1195 if (!pDevIns)
1196 {
1197 bool fSkip = false;
1198
1199 /* Skip the non-existing (deprecated) "AudioSniffer" device stored in the saved state. */
1200 if ( uVersion <= PDM_SAVED_STATE_VERSION_PRE_PDM_AUDIO
1201 && !RTStrCmp(szName, "AudioSniffer"))
1202 fSkip = true;
1203
1204 if (!fSkip)
1205 {
1206 LogRel(("Device '%s'/%d not found in current config\n", szName, iInstance));
1207 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
1208 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in current config"), szName, iInstance);
1209 }
1210 }
1211 }
1212
1213 /*
1214 * Check that no additional devices were configured.
1215 */
1216 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1217 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND))
1218 {
1219 LogRel(("Device '%s'/%d not found in the saved state\n", pDevIns->pReg->szName, pDevIns->iInstance));
1220 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
1221 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in the saved state"),
1222 pDevIns->pReg->szName, pDevIns->iInstance);
1223 }
1224
1225
1226 /*
1227 * Indicate that we've been called (for assertions).
1228 */
1229 pVM->pdm.s.fStateLoaded = true;
1230
1231 return VINF_SUCCESS;
1232}
1233
1234
1235/**
1236 * Worker for PDMR3PowerOn that deals with one driver.
1237 *
1238 * @param pDrvIns The driver instance.
1239 * @param pszDevName The parent device name.
1240 * @param iDevInstance The parent device instance number.
1241 * @param iLun The parent LUN number.
1242 */
1243DECLINLINE(int) pdmR3PowerOnDrv(PPDMDRVINS pDrvIns, const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
1244{
1245 Assert(pDrvIns->Internal.s.fVMSuspended);
1246 if (pDrvIns->pReg->pfnPowerOn)
1247 {
1248 LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1249 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1250 int rc = VINF_SUCCESS; pDrvIns->pReg->pfnPowerOn(pDrvIns);
1251 if (RT_FAILURE(rc))
1252 {
1253 LogRel(("PDMR3PowerOn: Driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
1254 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, rc));
1255 return rc;
1256 }
1257 }
1258 pDrvIns->Internal.s.fVMSuspended = false;
1259 return VINF_SUCCESS;
1260}
1261
1262
1263/**
1264 * Worker for PDMR3PowerOn that deals with one USB device instance.
1265 *
1266 * @returns VBox status code.
1267 * @param pUsbIns The USB device instance.
1268 */
1269DECLINLINE(int) pdmR3PowerOnUsb(PPDMUSBINS pUsbIns)
1270{
1271 Assert(pUsbIns->Internal.s.fVMSuspended);
1272 if (pUsbIns->pReg->pfnVMPowerOn)
1273 {
1274 LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1275 int rc = VINF_SUCCESS; pUsbIns->pReg->pfnVMPowerOn(pUsbIns);
1276 if (RT_FAILURE(rc))
1277 {
1278 LogRel(("PDMR3PowerOn: Device '%s'/%d -> %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1279 return rc;
1280 }
1281 }
1282 pUsbIns->Internal.s.fVMSuspended = false;
1283 return VINF_SUCCESS;
1284}
1285
1286
1287/**
1288 * Worker for PDMR3PowerOn that deals with one device instance.
1289 *
1290 * @returns VBox status code.
1291 * @param pDevIns The device instance.
1292 */
1293DECLINLINE(int) pdmR3PowerOnDev(PPDMDEVINS pDevIns)
1294{
1295 Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
1296 if (pDevIns->pReg->pfnPowerOn)
1297 {
1298 LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1299 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
1300 int rc = VINF_SUCCESS; pDevIns->pReg->pfnPowerOn(pDevIns);
1301 PDMCritSectLeave(pDevIns->pCritSectRoR3);
1302 if (RT_FAILURE(rc))
1303 {
1304 LogRel(("PDMR3PowerOn: Device '%s'/%d -> %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1305 return rc;
1306 }
1307 }
1308 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
1309 return VINF_SUCCESS;
1310}
1311
1312
1313/**
1314 * This function will notify all the devices and their
1315 * attached drivers about the VM now being powered on.
1316 *
1317 * @param pVM The cross context VM structure.
1318 */
1319VMMR3DECL(void) PDMR3PowerOn(PVM pVM)
1320{
1321 LogFlow(("PDMR3PowerOn:\n"));
1322
1323 /*
1324 * Iterate thru the device instances and USB device instances,
1325 * processing the drivers associated with those.
1326 */
1327 int rc = VINF_SUCCESS;
1328 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
1329 {
1330 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
1331 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
1332 rc = pdmR3PowerOnDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun);
1333 if (RT_SUCCESS(rc))
1334 rc = pdmR3PowerOnDev(pDevIns);
1335 }
1336
1337#ifdef VBOX_WITH_USB
1338 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
1339 {
1340 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
1341 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
1342 rc = pdmR3PowerOnDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun);
1343 if (RT_SUCCESS(rc))
1344 rc = pdmR3PowerOnUsb(pUsbIns);
1345 }
1346#endif
1347
1348#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1349 pdmR3AsyncCompletionResume(pVM);
1350#endif
1351
1352 /*
1353 * Resume all threads.
1354 */
1355 if (RT_SUCCESS(rc))
1356 pdmR3ThreadResumeAll(pVM);
1357
1358 /*
1359 * On failure, clean up via PDMR3Suspend.
1360 */
1361 if (RT_FAILURE(rc))
1362 PDMR3Suspend(pVM);
1363
1364 LogFlow(("PDMR3PowerOn: returns %Rrc\n", rc));
1365 return /*rc*/;
1366}
1367
1368
1369/**
1370 * Initializes the asynchronous notifi stats structure.
1371 *
1372 * @param pThis The asynchronous notifification stats.
1373 * @param pszOp The name of the operation.
1374 */
1375static void pdmR3NotifyAsyncInit(PPDMNOTIFYASYNCSTATS pThis, const char *pszOp)
1376{
1377 pThis->uStartNsTs = RTTimeNanoTS();
1378 pThis->cNsElapsedNextLog = 0;
1379 pThis->cLoops = 0;
1380 pThis->cAsync = 0;
1381 pThis->pszOp = pszOp;
1382 pThis->offList = 0;
1383 pThis->szList[0] = '\0';
1384}
1385
1386
1387/**
1388 * Begin a new loop, prepares to gather new stats.
1389 *
1390 * @param pThis The asynchronous notifification stats.
1391 */
1392static void pdmR3NotifyAsyncBeginLoop(PPDMNOTIFYASYNCSTATS pThis)
1393{
1394 pThis->cLoops++;
1395 pThis->cAsync = 0;
1396 pThis->offList = 0;
1397 pThis->szList[0] = '\0';
1398}
1399
1400
1401/**
1402 * Records a device or USB device with a pending asynchronous notification.
1403 *
1404 * @param pThis The asynchronous notifification stats.
1405 * @param pszName The name of the thing.
1406 * @param iInstance The instance number.
1407 */
1408static void pdmR3NotifyAsyncAdd(PPDMNOTIFYASYNCSTATS pThis, const char *pszName, uint32_t iInstance)
1409{
1410 pThis->cAsync++;
1411 if (pThis->offList < sizeof(pThis->szList) - 4)
1412 pThis->offList += RTStrPrintf(&pThis->szList[pThis->offList], sizeof(pThis->szList) - pThis->offList,
1413 pThis->offList == 0 ? "%s/%u" : ", %s/%u",
1414 pszName, iInstance);
1415}
1416
1417
1418/**
1419 * Records the asynchronous completition of a reset, suspend or power off.
1420 *
1421 * @param pThis The asynchronous notifification stats.
1422 * @param pszDrvName The driver name.
1423 * @param iDrvInstance The driver instance number.
1424 * @param pszDevName The device or USB device name.
1425 * @param iDevInstance The device or USB device instance number.
1426 * @param iLun The LUN.
1427 */
1428static void pdmR3NotifyAsyncAddDrv(PPDMNOTIFYASYNCSTATS pThis, const char *pszDrvName, uint32_t iDrvInstance,
1429 const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
1430{
1431 pThis->cAsync++;
1432 if (pThis->offList < sizeof(pThis->szList) - 8)
1433 pThis->offList += RTStrPrintf(&pThis->szList[pThis->offList], sizeof(pThis->szList) - pThis->offList,
1434 pThis->offList == 0 ? "%s/%u/%u/%s/%u" : ", %s/%u/%u/%s/%u",
1435 pszDevName, iDevInstance, iLun, pszDrvName, iDrvInstance);
1436}
1437
1438
1439/**
1440 * Log the stats.
1441 *
1442 * @param pThis The asynchronous notifification stats.
1443 */
1444static void pdmR3NotifyAsyncLog(PPDMNOTIFYASYNCSTATS pThis)
1445{
1446 /*
1447 * Return if we shouldn't log at this point.
1448 * We log with an internval increasing from 0 sec to 60 sec.
1449 */
1450 if (!pThis->cAsync)
1451 return;
1452
1453 uint64_t cNsElapsed = RTTimeNanoTS() - pThis->uStartNsTs;
1454 if (cNsElapsed < pThis->cNsElapsedNextLog)
1455 return;
1456
1457 if (pThis->cNsElapsedNextLog == 0)
1458 pThis->cNsElapsedNextLog = RT_NS_1SEC;
1459 else if (pThis->cNsElapsedNextLog >= RT_NS_1MIN / 2)
1460 pThis->cNsElapsedNextLog = RT_NS_1MIN;
1461 else
1462 pThis->cNsElapsedNextLog *= 2;
1463
1464 /*
1465 * Do the logging.
1466 */
1467 LogRel(("%s: after %5llu ms, %u loops: %u async tasks - %s\n",
1468 pThis->pszOp, cNsElapsed / RT_NS_1MS, pThis->cLoops, pThis->cAsync, pThis->szList));
1469}
1470
1471
1472/**
1473 * Wait for events and process pending requests.
1474 *
1475 * @param pThis The asynchronous notifification stats.
1476 * @param pVM The cross context VM structure.
1477 */
1478static void pdmR3NotifyAsyncWaitAndProcessRequests(PPDMNOTIFYASYNCSTATS pThis, PVM pVM)
1479{
1480 VM_ASSERT_EMT0(pVM);
1481 int rc = VMR3AsyncPdmNotificationWaitU(&pVM->pUVM->aCpus[0]);
1482 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc - %s - %s\n", rc, pThis->pszOp, pThis->szList));
1483
1484 rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY, true /*fPriorityOnly*/);
1485 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc - %s - %s\n", rc, pThis->pszOp, pThis->szList));
1486 rc = VMR3ReqProcessU(pVM->pUVM, 0/*idDstCpu*/, true /*fPriorityOnly*/);
1487 AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc - %s - %s\n", rc, pThis->pszOp, pThis->szList));
1488}
1489
1490
1491/**
1492 * Worker for PDMR3Reset that deals with one driver.
1493 *
1494 * @param pDrvIns The driver instance.
1495 * @param pAsync The structure for recording asynchronous
1496 * notification tasks.
1497 * @param pszDevName The parent device name.
1498 * @param iDevInstance The parent device instance number.
1499 * @param iLun The parent LUN number.
1500 */
1501DECLINLINE(bool) pdmR3ResetDrv(PPDMDRVINS pDrvIns, PPDMNOTIFYASYNCSTATS pAsync,
1502 const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
1503{
1504 if (!pDrvIns->Internal.s.fVMReset)
1505 {
1506 pDrvIns->Internal.s.fVMReset = true;
1507 if (pDrvIns->pReg->pfnReset)
1508 {
1509 if (!pDrvIns->Internal.s.pfnAsyncNotify)
1510 {
1511 LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1512 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1513 pDrvIns->pReg->pfnReset(pDrvIns);
1514 if (pDrvIns->Internal.s.pfnAsyncNotify)
1515 LogFlow(("PDMR3Reset: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1516 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1517 }
1518 else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
1519 {
1520 LogFlow(("PDMR3Reset: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1521 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1522 pDrvIns->Internal.s.pfnAsyncNotify = NULL;
1523 }
1524 if (pDrvIns->Internal.s.pfnAsyncNotify)
1525 {
1526 pDrvIns->Internal.s.fVMReset = false;
1527 pdmR3NotifyAsyncAddDrv(pAsync, pDrvIns->Internal.s.pDrv->pReg->szName, pDrvIns->iInstance,
1528 pszDevName, iDevInstance, iLun);
1529 return false;
1530 }
1531 }
1532 }
1533 return true;
1534}
1535
1536
1537/**
1538 * Worker for PDMR3Reset that deals with one USB device instance.
1539 *
1540 * @param pUsbIns The USB device instance.
1541 * @param pAsync The structure for recording asynchronous
1542 * notification tasks.
1543 */
1544DECLINLINE(void) pdmR3ResetUsb(PPDMUSBINS pUsbIns, PPDMNOTIFYASYNCSTATS pAsync)
1545{
1546 if (!pUsbIns->Internal.s.fVMReset)
1547 {
1548 pUsbIns->Internal.s.fVMReset = true;
1549 if (pUsbIns->pReg->pfnVMReset)
1550 {
1551 if (!pUsbIns->Internal.s.pfnAsyncNotify)
1552 {
1553 LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1554 pUsbIns->pReg->pfnVMReset(pUsbIns);
1555 if (pUsbIns->Internal.s.pfnAsyncNotify)
1556 LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1557 }
1558 else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
1559 {
1560 LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1561 pUsbIns->Internal.s.pfnAsyncNotify = NULL;
1562 }
1563 if (pUsbIns->Internal.s.pfnAsyncNotify)
1564 {
1565 pUsbIns->Internal.s.fVMReset = false;
1566 pdmR3NotifyAsyncAdd(pAsync, pUsbIns->Internal.s.pUsbDev->pReg->szName, pUsbIns->iInstance);
1567 }
1568 }
1569 }
1570}
1571
1572
1573/**
1574 * Worker for PDMR3Reset that deals with one device instance.
1575 *
1576 * @param pDevIns The device instance.
1577 * @param pAsync The structure for recording asynchronous
1578 * notification tasks.
1579 */
1580DECLINLINE(void) pdmR3ResetDev(PPDMDEVINS pDevIns, PPDMNOTIFYASYNCSTATS pAsync)
1581{
1582 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_RESET))
1583 {
1584 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_RESET;
1585 if (pDevIns->pReg->pfnReset)
1586 {
1587 uint64_t cNsElapsed = RTTimeNanoTS();
1588 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
1589
1590 if (!pDevIns->Internal.s.pfnAsyncNotify)
1591 {
1592 LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1593 pDevIns->pReg->pfnReset(pDevIns);
1594 if (pDevIns->Internal.s.pfnAsyncNotify)
1595 LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1596 }
1597 else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
1598 {
1599 LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1600 pDevIns->Internal.s.pfnAsyncNotify = NULL;
1601 }
1602 if (pDevIns->Internal.s.pfnAsyncNotify)
1603 {
1604 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_RESET;
1605 pdmR3NotifyAsyncAdd(pAsync, pDevIns->Internal.s.pDevR3->pReg->szName, pDevIns->iInstance);
1606 }
1607
1608 PDMCritSectLeave(pDevIns->pCritSectRoR3);
1609 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
1610 if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
1611 LogRel(("PDMR3Reset: Device '%s'/%d took %'llu ns to reset\n",
1612 pDevIns->pReg->szName, pDevIns->iInstance, cNsElapsed));
1613 }
1614 }
1615}
1616
1617
1618/**
1619 * Resets a virtual CPU.
1620 *
1621 * Used by PDMR3Reset and CPU hot plugging.
1622 *
1623 * @param pVCpu The cross context virtual CPU structure.
1624 */
1625VMMR3_INT_DECL(void) PDMR3ResetCpu(PVMCPU pVCpu)
1626{
1627 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
1628 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
1629 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
1630 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
1631}
1632
1633
1634/**
1635 * This function will notify all the devices and their attached drivers about
1636 * the VM now being reset.
1637 *
1638 * @param pVM The cross context VM structure.
1639 */
1640VMMR3_INT_DECL(void) PDMR3Reset(PVM pVM)
1641{
1642 LogFlow(("PDMR3Reset:\n"));
1643
1644 /*
1645 * Clear all the reset flags.
1646 */
1647 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1648 {
1649 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_RESET;
1650 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
1651 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1652 pDrvIns->Internal.s.fVMReset = false;
1653 }
1654#ifdef VBOX_WITH_USB
1655 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1656 {
1657 pUsbIns->Internal.s.fVMReset = false;
1658 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
1659 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1660 pDrvIns->Internal.s.fVMReset = false;
1661 }
1662#endif
1663
1664 /*
1665 * The outer loop repeats until there are no more async requests.
1666 */
1667 PDMNOTIFYASYNCSTATS Async;
1668 pdmR3NotifyAsyncInit(&Async, "PDMR3Reset");
1669 for (;;)
1670 {
1671 pdmR3NotifyAsyncBeginLoop(&Async);
1672
1673 /*
1674 * Iterate thru the device instances and USB device instances,
1675 * processing the drivers associated with those.
1676 */
1677 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1678 {
1679 unsigned const cAsyncStart = Async.cAsync;
1680
1681 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION)
1682 pdmR3ResetDev(pDevIns, &Async);
1683
1684 if (Async.cAsync == cAsyncStart)
1685 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
1686 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1687 if (!pdmR3ResetDrv(pDrvIns, &Async, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
1688 break;
1689
1690 if ( Async.cAsync == cAsyncStart
1691 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION))
1692 pdmR3ResetDev(pDevIns, &Async);
1693 }
1694
1695#ifdef VBOX_WITH_USB
1696 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1697 {
1698 unsigned const cAsyncStart = Async.cAsync;
1699
1700 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
1701 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
1702 if (!pdmR3ResetDrv(pDrvIns, &Async, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
1703 break;
1704
1705 if (Async.cAsync == cAsyncStart)
1706 pdmR3ResetUsb(pUsbIns, &Async);
1707 }
1708#endif
1709 if (!Async.cAsync)
1710 break;
1711 pdmR3NotifyAsyncLog(&Async);
1712 pdmR3NotifyAsyncWaitAndProcessRequests(&Async, pVM);
1713 }
1714
1715 /*
1716 * Clear all pending interrupts and DMA operations.
1717 */
1718 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1719 PDMR3ResetCpu(pVM->apCpusR3[idCpu]);
1720 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
1721
1722 LogFlow(("PDMR3Reset: returns void\n"));
1723}
1724
1725
1726/**
1727 * This function will tell all the devices to setup up their memory structures
1728 * after VM construction and after VM reset.
1729 *
1730 * @param pVM The cross context VM structure.
1731 * @param fAtReset Indicates the context, after reset if @c true or after
1732 * construction if @c false.
1733 */
1734VMMR3_INT_DECL(void) PDMR3MemSetup(PVM pVM, bool fAtReset)
1735{
1736 LogFlow(("PDMR3MemSetup: fAtReset=%RTbool\n", fAtReset));
1737 PDMDEVMEMSETUPCTX const enmCtx = fAtReset ? PDMDEVMEMSETUPCTX_AFTER_RESET : PDMDEVMEMSETUPCTX_AFTER_CONSTRUCTION;
1738
1739 /*
1740 * Iterate thru the device instances and work the callback.
1741 */
1742 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1743 if (pDevIns->pReg->pfnMemSetup)
1744 {
1745 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
1746 pDevIns->pReg->pfnMemSetup(pDevIns, enmCtx);
1747 PDMCritSectLeave(pDevIns->pCritSectRoR3);
1748 }
1749
1750 LogFlow(("PDMR3MemSetup: returns void\n"));
1751}
1752
1753
1754/**
1755 * Retrieves and resets the info left behind by PDMDevHlpVMReset.
1756 *
1757 * @returns True if hard reset, false if soft reset.
1758 * @param pVM The cross context VM structure.
1759 * @param fOverride If non-zero, the override flags will be used instead
1760 * of the reset flags kept by PDM. (For triple faults.)
1761 * @param pfResetFlags Where to return the reset flags (PDMVMRESET_F_XXX).
1762 * @thread EMT
1763 */
1764VMMR3_INT_DECL(bool) PDMR3GetResetInfo(PVM pVM, uint32_t fOverride, uint32_t *pfResetFlags)
1765{
1766 VM_ASSERT_EMT(pVM);
1767
1768 /*
1769 * Get the reset flags.
1770 */
1771 uint32_t fResetFlags;
1772 fResetFlags = ASMAtomicXchgU32(&pVM->pdm.s.fResetFlags, 0);
1773 if (fOverride)
1774 fResetFlags = fOverride;
1775 *pfResetFlags = fResetFlags;
1776
1777 /*
1778 * To try avoid trouble, we never ever do soft/warm resets on SMP systems
1779 * with more than CPU #0 active. However, if only one CPU is active we
1780 * will ask the firmware what it wants us to do (because the firmware may
1781 * depend on the VMM doing a lot of what is normally its responsibility,
1782 * like clearing memory).
1783 */
1784 bool fOtherCpusActive = false;
1785 VMCPUID idCpu = pVM->cCpus;
1786 while (idCpu-- > 1)
1787 {
1788 EMSTATE enmState = EMGetState(pVM->apCpusR3[idCpu]);
1789 if ( enmState != EMSTATE_WAIT_SIPI
1790 && enmState != EMSTATE_NONE)
1791 {
1792 fOtherCpusActive = true;
1793 break;
1794 }
1795 }
1796
1797 bool fHardReset = fOtherCpusActive
1798 || (fResetFlags & PDMVMRESET_F_SRC_MASK) < PDMVMRESET_F_LAST_ALWAYS_HARD
1799 || !pVM->pdm.s.pFirmware
1800 || pVM->pdm.s.pFirmware->Reg.pfnIsHardReset(pVM->pdm.s.pFirmware->pDevIns, fResetFlags);
1801
1802 Log(("PDMR3GetResetInfo: returns fHardReset=%RTbool fResetFlags=%#x\n", fHardReset, fResetFlags));
1803 return fHardReset;
1804}
1805
1806
1807/**
1808 * Performs a soft reset of devices.
1809 *
1810 * @param pVM The cross context VM structure.
1811 * @param fResetFlags PDMVMRESET_F_XXX.
1812 */
1813VMMR3_INT_DECL(void) PDMR3SoftReset(PVM pVM, uint32_t fResetFlags)
1814{
1815 LogFlow(("PDMR3SoftReset: fResetFlags=%#x\n", fResetFlags));
1816
1817 /*
1818 * Iterate thru the device instances and work the callback.
1819 */
1820 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
1821 if (pDevIns->pReg->pfnSoftReset)
1822 {
1823 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
1824 pDevIns->pReg->pfnSoftReset(pDevIns, fResetFlags);
1825 PDMCritSectLeave(pDevIns->pCritSectRoR3);
1826 }
1827
1828 LogFlow(("PDMR3SoftReset: returns void\n"));
1829}
1830
1831
1832/**
1833 * Worker for PDMR3Suspend that deals with one driver.
1834 *
1835 * @param pDrvIns The driver instance.
1836 * @param pAsync The structure for recording asynchronous
1837 * notification tasks.
1838 * @param pszDevName The parent device name.
1839 * @param iDevInstance The parent device instance number.
1840 * @param iLun The parent LUN number.
1841 */
1842DECLINLINE(bool) pdmR3SuspendDrv(PPDMDRVINS pDrvIns, PPDMNOTIFYASYNCSTATS pAsync,
1843 const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
1844{
1845 if (!pDrvIns->Internal.s.fVMSuspended)
1846 {
1847 pDrvIns->Internal.s.fVMSuspended = true;
1848 if (pDrvIns->pReg->pfnSuspend)
1849 {
1850 uint64_t cNsElapsed = RTTimeNanoTS();
1851
1852 if (!pDrvIns->Internal.s.pfnAsyncNotify)
1853 {
1854 LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1855 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1856 pDrvIns->pReg->pfnSuspend(pDrvIns);
1857 if (pDrvIns->Internal.s.pfnAsyncNotify)
1858 LogFlow(("PDMR3Suspend: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1859 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1860 }
1861 else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
1862 {
1863 LogFlow(("PDMR3Suspend: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
1864 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
1865 pDrvIns->Internal.s.pfnAsyncNotify = NULL;
1866 }
1867
1868 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
1869 if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
1870 LogRel(("PDMR3Suspend: Driver '%s'/%d on LUN#%d of device '%s'/%d took %'llu ns to suspend\n",
1871 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, cNsElapsed));
1872
1873 if (pDrvIns->Internal.s.pfnAsyncNotify)
1874 {
1875 pDrvIns->Internal.s.fVMSuspended = false;
1876 pdmR3NotifyAsyncAddDrv(pAsync, pDrvIns->Internal.s.pDrv->pReg->szName, pDrvIns->iInstance, pszDevName, iDevInstance, iLun);
1877 return false;
1878 }
1879 }
1880 }
1881 return true;
1882}
1883
1884
1885/**
1886 * Worker for PDMR3Suspend that deals with one USB device instance.
1887 *
1888 * @param pUsbIns The USB device instance.
1889 * @param pAsync The structure for recording asynchronous
1890 * notification tasks.
1891 */
1892DECLINLINE(void) pdmR3SuspendUsb(PPDMUSBINS pUsbIns, PPDMNOTIFYASYNCSTATS pAsync)
1893{
1894 if (!pUsbIns->Internal.s.fVMSuspended)
1895 {
1896 pUsbIns->Internal.s.fVMSuspended = true;
1897 if (pUsbIns->pReg->pfnVMSuspend)
1898 {
1899 uint64_t cNsElapsed = RTTimeNanoTS();
1900
1901 if (!pUsbIns->Internal.s.pfnAsyncNotify)
1902 {
1903 LogFlow(("PDMR3Suspend: Notifying - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1904 pUsbIns->pReg->pfnVMSuspend(pUsbIns);
1905 if (pUsbIns->Internal.s.pfnAsyncNotify)
1906 LogFlow(("PDMR3Suspend: Async notification started - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1907 }
1908 else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
1909 {
1910 LogFlow(("PDMR3Suspend: Async notification completed - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1911 pUsbIns->Internal.s.pfnAsyncNotify = NULL;
1912 }
1913 if (pUsbIns->Internal.s.pfnAsyncNotify)
1914 {
1915 pUsbIns->Internal.s.fVMSuspended = false;
1916 pdmR3NotifyAsyncAdd(pAsync, pUsbIns->Internal.s.pUsbDev->pReg->szName, pUsbIns->iInstance);
1917 }
1918
1919 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
1920 if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
1921 LogRel(("PDMR3Suspend: USB device '%s'/%d took %'llu ns to suspend\n",
1922 pUsbIns->pReg->szName, pUsbIns->iInstance, cNsElapsed));
1923 }
1924 }
1925}
1926
1927
1928/**
1929 * Worker for PDMR3Suspend that deals with one device instance.
1930 *
1931 * @param pDevIns The device instance.
1932 * @param pAsync The structure for recording asynchronous
1933 * notification tasks.
1934 */
1935DECLINLINE(void) pdmR3SuspendDev(PPDMDEVINS pDevIns, PPDMNOTIFYASYNCSTATS pAsync)
1936{
1937 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED))
1938 {
1939 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_SUSPENDED;
1940 if (pDevIns->pReg->pfnSuspend)
1941 {
1942 uint64_t cNsElapsed = RTTimeNanoTS();
1943 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
1944
1945 if (!pDevIns->Internal.s.pfnAsyncNotify)
1946 {
1947 LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1948 pDevIns->pReg->pfnSuspend(pDevIns);
1949 if (pDevIns->Internal.s.pfnAsyncNotify)
1950 LogFlow(("PDMR3Suspend: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1951 }
1952 else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
1953 {
1954 LogFlow(("PDMR3Suspend: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
1955 pDevIns->Internal.s.pfnAsyncNotify = NULL;
1956 }
1957 if (pDevIns->Internal.s.pfnAsyncNotify)
1958 {
1959 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
1960 pdmR3NotifyAsyncAdd(pAsync, pDevIns->Internal.s.pDevR3->pReg->szName, pDevIns->iInstance);
1961 }
1962
1963 PDMCritSectLeave(pDevIns->pCritSectRoR3);
1964 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
1965 if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
1966 LogRel(("PDMR3Suspend: Device '%s'/%d took %'llu ns to suspend\n",
1967 pDevIns->pReg->szName, pDevIns->iInstance, cNsElapsed));
1968 }
1969 }
1970}
1971
1972
1973/**
1974 * This function will notify all the devices and their attached drivers about
1975 * the VM now being suspended.
1976 *
1977 * @param pVM The cross context VM structure.
1978 * @thread EMT(0)
1979 */
1980VMMR3_INT_DECL(void) PDMR3Suspend(PVM pVM)
1981{
1982 LogFlow(("PDMR3Suspend:\n"));
1983 VM_ASSERT_EMT0(pVM);
1984 uint64_t cNsElapsed = RTTimeNanoTS();
1985
1986 /*
1987 * The outer loop repeats until there are no more async requests.
1988 *
1989 * Note! We depend on the suspended indicators to be in the desired state
1990 * and we do not reset them before starting because this allows
1991 * PDMR3PowerOn and PDMR3Resume to use PDMR3Suspend for cleaning up
1992 * on failure.
1993 */
1994 PDMNOTIFYASYNCSTATS Async;
1995 pdmR3NotifyAsyncInit(&Async, "PDMR3Suspend");
1996 for (;;)
1997 {
1998 pdmR3NotifyAsyncBeginLoop(&Async);
1999
2000 /*
2001 * Iterate thru the device instances and USB device instances,
2002 * processing the drivers associated with those.
2003 *
2004 * The attached drivers are normally processed first. Some devices
2005 * (like DevAHCI) though needs to be notified before the drivers so
2006 * that it doesn't kick off any new requests after the drivers stopped
2007 * taking any. (DrvVD changes to read-only in this particular case.)
2008 */
2009 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2010 {
2011 unsigned const cAsyncStart = Async.cAsync;
2012
2013 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION)
2014 pdmR3SuspendDev(pDevIns, &Async);
2015
2016 if (Async.cAsync == cAsyncStart)
2017 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2018 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2019 if (!pdmR3SuspendDrv(pDrvIns, &Async, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
2020 break;
2021
2022 if ( Async.cAsync == cAsyncStart
2023 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION))
2024 pdmR3SuspendDev(pDevIns, &Async);
2025 }
2026
2027#ifdef VBOX_WITH_USB
2028 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2029 {
2030 unsigned const cAsyncStart = Async.cAsync;
2031
2032 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2033 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2034 if (!pdmR3SuspendDrv(pDrvIns, &Async, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
2035 break;
2036
2037 if (Async.cAsync == cAsyncStart)
2038 pdmR3SuspendUsb(pUsbIns, &Async);
2039 }
2040#endif
2041 if (!Async.cAsync)
2042 break;
2043 pdmR3NotifyAsyncLog(&Async);
2044 pdmR3NotifyAsyncWaitAndProcessRequests(&Async, pVM);
2045 }
2046
2047 /*
2048 * Suspend all threads.
2049 */
2050 pdmR3ThreadSuspendAll(pVM);
2051
2052 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
2053 LogRel(("PDMR3Suspend: %'llu ns run time\n", cNsElapsed));
2054}
2055
2056
2057/**
2058 * Worker for PDMR3Resume that deals with one driver.
2059 *
2060 * @param pDrvIns The driver instance.
2061 * @param pszDevName The parent device name.
2062 * @param iDevInstance The parent device instance number.
2063 * @param iLun The parent LUN number.
2064 */
2065DECLINLINE(int) pdmR3ResumeDrv(PPDMDRVINS pDrvIns, const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
2066{
2067 Assert(pDrvIns->Internal.s.fVMSuspended);
2068 if (pDrvIns->pReg->pfnResume)
2069 {
2070 LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
2071 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
2072 int rc = VINF_SUCCESS; pDrvIns->pReg->pfnResume(pDrvIns);
2073 if (RT_FAILURE(rc))
2074 {
2075 LogRel(("PDMR3Resume: Driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
2076 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, rc));
2077 return rc;
2078 }
2079 }
2080 pDrvIns->Internal.s.fVMSuspended = false;
2081 return VINF_SUCCESS;
2082}
2083
2084
2085/**
2086 * Worker for PDMR3Resume that deals with one USB device instance.
2087 *
2088 * @returns VBox status code.
2089 * @param pUsbIns The USB device instance.
2090 */
2091DECLINLINE(int) pdmR3ResumeUsb(PPDMUSBINS pUsbIns)
2092{
2093 Assert(pUsbIns->Internal.s.fVMSuspended);
2094 if (pUsbIns->pReg->pfnVMResume)
2095 {
2096 LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
2097 int rc = VINF_SUCCESS; pUsbIns->pReg->pfnVMResume(pUsbIns);
2098 if (RT_FAILURE(rc))
2099 {
2100 LogRel(("PDMR3Resume: Device '%s'/%d -> %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
2101 return rc;
2102 }
2103 }
2104 pUsbIns->Internal.s.fVMSuspended = false;
2105 return VINF_SUCCESS;
2106}
2107
2108
2109/**
2110 * Worker for PDMR3Resume that deals with one device instance.
2111 *
2112 * @returns VBox status code.
2113 * @param pDevIns The device instance.
2114 */
2115DECLINLINE(int) pdmR3ResumeDev(PPDMDEVINS pDevIns)
2116{
2117 Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
2118 if (pDevIns->pReg->pfnResume)
2119 {
2120 LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
2121 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
2122 int rc = VINF_SUCCESS; pDevIns->pReg->pfnResume(pDevIns);
2123 PDMCritSectLeave(pDevIns->pCritSectRoR3);
2124 if (RT_FAILURE(rc))
2125 {
2126 LogRel(("PDMR3Resume: Device '%s'/%d -> %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2127 return rc;
2128 }
2129 }
2130 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
2131 return VINF_SUCCESS;
2132}
2133
2134
2135/**
2136 * This function will notify all the devices and their
2137 * attached drivers about the VM now being resumed.
2138 *
2139 * @param pVM The cross context VM structure.
2140 */
2141VMMR3_INT_DECL(void) PDMR3Resume(PVM pVM)
2142{
2143 LogFlow(("PDMR3Resume:\n"));
2144
2145 /*
2146 * Iterate thru the device instances and USB device instances,
2147 * processing the drivers associated with those.
2148 */
2149 int rc = VINF_SUCCESS;
2150 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
2151 {
2152 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
2153 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
2154 rc = pdmR3ResumeDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun);
2155 if (RT_SUCCESS(rc))
2156 rc = pdmR3ResumeDev(pDevIns);
2157 }
2158
2159#ifdef VBOX_WITH_USB
2160 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
2161 {
2162 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
2163 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
2164 rc = pdmR3ResumeDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun);
2165 if (RT_SUCCESS(rc))
2166 rc = pdmR3ResumeUsb(pUsbIns);
2167 }
2168#endif
2169
2170 /*
2171 * Resume all threads.
2172 */
2173 if (RT_SUCCESS(rc))
2174 pdmR3ThreadResumeAll(pVM);
2175
2176 /*
2177 * Resume the block cache.
2178 */
2179 if (RT_SUCCESS(rc))
2180 pdmR3BlkCacheResume(pVM);
2181
2182 /*
2183 * On failure, clean up via PDMR3Suspend.
2184 */
2185 if (RT_FAILURE(rc))
2186 PDMR3Suspend(pVM);
2187
2188 LogFlow(("PDMR3Resume: returns %Rrc\n", rc));
2189 return /*rc*/;
2190}
2191
2192
2193/**
2194 * Worker for PDMR3PowerOff that deals with one driver.
2195 *
2196 * @param pDrvIns The driver instance.
2197 * @param pAsync The structure for recording asynchronous
2198 * notification tasks.
2199 * @param pszDevName The parent device name.
2200 * @param iDevInstance The parent device instance number.
2201 * @param iLun The parent LUN number.
2202 */
2203DECLINLINE(bool) pdmR3PowerOffDrv(PPDMDRVINS pDrvIns, PPDMNOTIFYASYNCSTATS pAsync,
2204 const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
2205{
2206 if (!pDrvIns->Internal.s.fVMSuspended)
2207 {
2208 pDrvIns->Internal.s.fVMSuspended = true;
2209 if (pDrvIns->pReg->pfnPowerOff)
2210 {
2211 uint64_t cNsElapsed = RTTimeNanoTS();
2212
2213 if (!pDrvIns->Internal.s.pfnAsyncNotify)
2214 {
2215 LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
2216 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
2217 pDrvIns->pReg->pfnPowerOff(pDrvIns);
2218 if (pDrvIns->Internal.s.pfnAsyncNotify)
2219 LogFlow(("PDMR3PowerOff: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
2220 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
2221 }
2222 else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
2223 {
2224 LogFlow(("PDMR3PowerOff: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
2225 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
2226 pDrvIns->Internal.s.pfnAsyncNotify = NULL;
2227 }
2228
2229 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
2230 if (cNsElapsed >= PDMPOWEROFF_WARN_AT_NS)
2231 LogRel(("PDMR3PowerOff: Driver '%s'/%d on LUN#%d of device '%s'/%d took %'llu ns to power off\n",
2232 pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, cNsElapsed));
2233
2234 if (pDrvIns->Internal.s.pfnAsyncNotify)
2235 {
2236 pDrvIns->Internal.s.fVMSuspended = false;
2237 pdmR3NotifyAsyncAddDrv(pAsync, pDrvIns->Internal.s.pDrv->pReg->szName, pDrvIns->iInstance,
2238 pszDevName, iDevInstance, iLun);
2239 return false;
2240 }
2241 }
2242 }
2243 return true;
2244}
2245
2246
2247/**
2248 * Worker for PDMR3PowerOff that deals with one USB device instance.
2249 *
2250 * @param pUsbIns The USB device instance.
2251 * @param pAsync The structure for recording asynchronous
2252 * notification tasks.
2253 */
2254DECLINLINE(void) pdmR3PowerOffUsb(PPDMUSBINS pUsbIns, PPDMNOTIFYASYNCSTATS pAsync)
2255{
2256 if (!pUsbIns->Internal.s.fVMSuspended)
2257 {
2258 pUsbIns->Internal.s.fVMSuspended = true;
2259 if (pUsbIns->pReg->pfnVMPowerOff)
2260 {
2261 uint64_t cNsElapsed = RTTimeNanoTS();
2262
2263 if (!pUsbIns->Internal.s.pfnAsyncNotify)
2264 {
2265 LogFlow(("PDMR3PowerOff: Notifying - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
2266 pUsbIns->pReg->pfnVMPowerOff(pUsbIns);
2267 if (pUsbIns->Internal.s.pfnAsyncNotify)
2268 LogFlow(("PDMR3PowerOff: Async notification started - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
2269 }
2270 else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
2271 {
2272 LogFlow(("PDMR3PowerOff: Async notification completed - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
2273 pUsbIns->Internal.s.pfnAsyncNotify = NULL;
2274 }
2275 if (pUsbIns->Internal.s.pfnAsyncNotify)
2276 {
2277 pUsbIns->Internal.s.fVMSuspended = false;
2278 pdmR3NotifyAsyncAdd(pAsync, pUsbIns->Internal.s.pUsbDev->pReg->szName, pUsbIns->iInstance);
2279 }
2280
2281 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
2282 if (cNsElapsed >= PDMPOWEROFF_WARN_AT_NS)
2283 LogRel(("PDMR3PowerOff: USB device '%s'/%d took %'llu ns to power off\n",
2284 pUsbIns->pReg->szName, pUsbIns->iInstance, cNsElapsed));
2285
2286 }
2287 }
2288}
2289
2290
2291/**
2292 * Worker for PDMR3PowerOff that deals with one device instance.
2293 *
2294 * @param pDevIns The device instance.
2295 * @param pAsync The structure for recording asynchronous
2296 * notification tasks.
2297 */
2298DECLINLINE(void) pdmR3PowerOffDev(PPDMDEVINS pDevIns, PPDMNOTIFYASYNCSTATS pAsync)
2299{
2300 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED))
2301 {
2302 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_SUSPENDED;
2303 if (pDevIns->pReg->pfnPowerOff)
2304 {
2305 uint64_t cNsElapsed = RTTimeNanoTS();
2306 PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
2307
2308 if (!pDevIns->Internal.s.pfnAsyncNotify)
2309 {
2310 LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
2311 pDevIns->pReg->pfnPowerOff(pDevIns);
2312 if (pDevIns->Internal.s.pfnAsyncNotify)
2313 LogFlow(("PDMR3PowerOff: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
2314 }
2315 else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
2316 {
2317 LogFlow(("PDMR3PowerOff: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
2318 pDevIns->Internal.s.pfnAsyncNotify = NULL;
2319 }
2320 if (pDevIns->Internal.s.pfnAsyncNotify)
2321 {
2322 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
2323 pdmR3NotifyAsyncAdd(pAsync, pDevIns->Internal.s.pDevR3->pReg->szName, pDevIns->iInstance);
2324 }
2325
2326 PDMCritSectLeave(pDevIns->pCritSectRoR3);
2327 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
2328 if (cNsElapsed >= PDMPOWEROFF_WARN_AT_NS)
2329 LogFlow(("PDMR3PowerOff: Device '%s'/%d took %'llu ns to power off\n",
2330 pDevIns->pReg->szName, pDevIns->iInstance, cNsElapsed));
2331 }
2332 }
2333}
2334
2335
2336/**
2337 * This function will notify all the devices and their
2338 * attached drivers about the VM being powered off.
2339 *
2340 * @param pVM The cross context VM structure.
2341 */
2342VMMR3DECL(void) PDMR3PowerOff(PVM pVM)
2343{
2344 LogFlow(("PDMR3PowerOff:\n"));
2345 uint64_t cNsElapsed = RTTimeNanoTS();
2346
2347 /*
2348 * Clear the suspended flags on all devices and drivers first because they
2349 * might have been set during a suspend but the power off callbacks should
2350 * be called in any case.
2351 */
2352 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2353 {
2354 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
2355
2356 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2357 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2358 pDrvIns->Internal.s.fVMSuspended = false;
2359 }
2360
2361#ifdef VBOX_WITH_USB
2362 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2363 {
2364 pUsbIns->Internal.s.fVMSuspended = false;
2365
2366 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2367 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2368 pDrvIns->Internal.s.fVMSuspended = false;
2369 }
2370#endif
2371
2372 /*
2373 * The outer loop repeats until there are no more async requests.
2374 */
2375 PDMNOTIFYASYNCSTATS Async;
2376 pdmR3NotifyAsyncInit(&Async, "PDMR3PowerOff");
2377 for (;;)
2378 {
2379 pdmR3NotifyAsyncBeginLoop(&Async);
2380
2381 /*
2382 * Iterate thru the device instances and USB device instances,
2383 * processing the drivers associated with those.
2384 *
2385 * The attached drivers are normally processed first. Some devices
2386 * (like DevAHCI) though needs to be notified before the drivers so
2387 * that it doesn't kick off any new requests after the drivers stopped
2388 * taking any. (DrvVD changes to read-only in this particular case.)
2389 */
2390 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2391 {
2392 unsigned const cAsyncStart = Async.cAsync;
2393
2394 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION)
2395 pdmR3PowerOffDev(pDevIns, &Async);
2396
2397 if (Async.cAsync == cAsyncStart)
2398 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2399 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2400 if (!pdmR3PowerOffDrv(pDrvIns, &Async, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
2401 break;
2402
2403 if ( Async.cAsync == cAsyncStart
2404 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION))
2405 pdmR3PowerOffDev(pDevIns, &Async);
2406 }
2407
2408#ifdef VBOX_WITH_USB
2409 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2410 {
2411 unsigned const cAsyncStart = Async.cAsync;
2412
2413 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2414 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2415 if (!pdmR3PowerOffDrv(pDrvIns, &Async, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
2416 break;
2417
2418 if (Async.cAsync == cAsyncStart)
2419 pdmR3PowerOffUsb(pUsbIns, &Async);
2420 }
2421#endif
2422 if (!Async.cAsync)
2423 break;
2424 pdmR3NotifyAsyncLog(&Async);
2425 pdmR3NotifyAsyncWaitAndProcessRequests(&Async, pVM);
2426 }
2427
2428 /*
2429 * Suspend all threads.
2430 */
2431 pdmR3ThreadSuspendAll(pVM);
2432
2433 cNsElapsed = RTTimeNanoTS() - cNsElapsed;
2434 LogRel(("PDMR3PowerOff: %'llu ns run time\n", cNsElapsed));
2435}
2436
2437
2438/**
2439 * Queries the base interface of a device instance.
2440 *
2441 * The caller can use this to query other interfaces the device implements
2442 * and use them to talk to the device.
2443 *
2444 * @returns VBox status code.
2445 * @param pUVM The user mode VM handle.
2446 * @param pszDevice Device name.
2447 * @param iInstance Device instance.
2448 * @param ppBase Where to store the pointer to the base device interface on success.
2449 * @remark We're not doing any locking ATM, so don't try call this at times when the
2450 * device chain is known to be updated.
2451 */
2452VMMR3DECL(int) PDMR3QueryDevice(PUVM pUVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
2453{
2454 LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
2455 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
2456 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
2457
2458 /*
2459 * Iterate registered devices looking for the device.
2460 */
2461 size_t cchDevice = strlen(pszDevice);
2462 for (PPDMDEV pDev = pUVM->pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext)
2463 {
2464 if ( pDev->cchName == cchDevice
2465 && !memcmp(pDev->pReg->szName, pszDevice, cchDevice))
2466 {
2467 /*
2468 * Iterate device instances.
2469 */
2470 for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextR3)
2471 {
2472 if (pDevIns->iInstance == iInstance)
2473 {
2474 if (pDevIns->IBase.pfnQueryInterface)
2475 {
2476 *ppBase = &pDevIns->IBase;
2477 LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
2478 return VINF_SUCCESS;
2479 }
2480
2481 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
2482 return VERR_PDM_DEVICE_INSTANCE_NO_IBASE;
2483 }
2484 }
2485
2486 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
2487 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND;
2488 }
2489 }
2490
2491 LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
2492 return VERR_PDM_DEVICE_NOT_FOUND;
2493}
2494
2495
2496/**
2497 * Queries the base interface of a device LUN.
2498 *
2499 * This differs from PDMR3QueryLun by that it returns the interface on the
2500 * device and not the top level driver.
2501 *
2502 * @returns VBox status code.
2503 * @param pUVM The user mode VM handle.
2504 * @param pszDevice Device name.
2505 * @param iInstance Device instance.
2506 * @param iLun The Logical Unit to obtain the interface of.
2507 * @param ppBase Where to store the base interface pointer.
2508 * @remark We're not doing any locking ATM, so don't try call this at times when the
2509 * device chain is known to be updated.
2510 */
2511VMMR3DECL(int) PDMR3QueryDeviceLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
2512{
2513 LogFlow(("PDMR3QueryDeviceLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
2514 pszDevice, pszDevice, iInstance, iLun, ppBase));
2515 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
2516 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
2517
2518 /*
2519 * Find the LUN.
2520 */
2521 PPDMLUN pLun;
2522 int rc = pdmR3DevFindLun(pUVM->pVM, pszDevice, iInstance, iLun, &pLun);
2523 if (RT_SUCCESS(rc))
2524 {
2525 *ppBase = pLun->pBase;
2526 LogFlow(("PDMR3QueryDeviceLun: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
2527 return VINF_SUCCESS;
2528 }
2529 LogFlow(("PDMR3QueryDeviceLun: returns %Rrc\n", rc));
2530 return rc;
2531}
2532
2533
2534/**
2535 * Query the interface of the top level driver on a LUN.
2536 *
2537 * @returns VBox status code.
2538 * @param pUVM The user mode VM handle.
2539 * @param pszDevice Device name.
2540 * @param iInstance Device instance.
2541 * @param iLun The Logical Unit to obtain the interface of.
2542 * @param ppBase Where to store the base interface pointer.
2543 * @remark We're not doing any locking ATM, so don't try call this at times when the
2544 * device chain is known to be updated.
2545 */
2546VMMR3DECL(int) PDMR3QueryLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
2547{
2548 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
2549 pszDevice, pszDevice, iInstance, iLun, ppBase));
2550 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
2551 PVM pVM = pUVM->pVM;
2552 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
2553
2554 /*
2555 * Find the LUN.
2556 */
2557 PPDMLUN pLun;
2558 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
2559 if (RT_SUCCESS(rc))
2560 {
2561 if (pLun->pTop)
2562 {
2563 *ppBase = &pLun->pTop->IBase;
2564 LogFlow(("PDMR3QueryLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
2565 return VINF_SUCCESS;
2566 }
2567 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
2568 }
2569 LogFlow(("PDMR3QueryLun: returns %Rrc\n", rc));
2570 return rc;
2571}
2572
2573
2574/**
2575 * Query the interface of a named driver on a LUN.
2576 *
2577 * If the driver appears more than once in the driver chain, the first instance
2578 * is returned.
2579 *
2580 * @returns VBox status code.
2581 * @param pUVM The user mode VM handle.
2582 * @param pszDevice Device name.
2583 * @param iInstance Device instance.
2584 * @param iLun The Logical Unit to obtain the interface of.
2585 * @param pszDriver The driver name.
2586 * @param ppBase Where to store the base interface pointer.
2587 *
2588 * @remark We're not doing any locking ATM, so don't try call this at times when the
2589 * device chain is known to be updated.
2590 */
2591VMMR3DECL(int) PDMR3QueryDriverOnLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, const char *pszDriver, PPPDMIBASE ppBase)
2592{
2593 LogFlow(("PDMR3QueryDriverOnLun: pszDevice=%p:{%s} iInstance=%u iLun=%u pszDriver=%p:{%s} ppBase=%p\n",
2594 pszDevice, pszDevice, iInstance, iLun, pszDriver, pszDriver, ppBase));
2595 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
2596 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
2597
2598 /*
2599 * Find the LUN.
2600 */
2601 PPDMLUN pLun;
2602 int rc = pdmR3DevFindLun(pUVM->pVM, pszDevice, iInstance, iLun, &pLun);
2603 if (RT_SUCCESS(rc))
2604 {
2605 if (pLun->pTop)
2606 {
2607 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2608 if (!strcmp(pDrvIns->pReg->szName, pszDriver))
2609 {
2610 *ppBase = &pDrvIns->IBase;
2611 LogFlow(("PDMR3QueryDriverOnLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
2612 return VINF_SUCCESS;
2613
2614 }
2615 rc = VERR_PDM_DRIVER_NOT_FOUND;
2616 }
2617 else
2618 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
2619 }
2620 LogFlow(("PDMR3QueryDriverOnLun: returns %Rrc\n", rc));
2621 return rc;
2622}
2623
2624/**
2625 * Executes pending DMA transfers.
2626 * Forced Action handler.
2627 *
2628 * @param pVM The cross context VM structure.
2629 */
2630VMMR3DECL(void) PDMR3DmaRun(PVM pVM)
2631{
2632 /* Note! Not really SMP safe; restrict it to VCPU 0. */
2633 if (VMMGetCpuId(pVM) != 0)
2634 return;
2635
2636 if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_PDM_DMA))
2637 {
2638 if (pVM->pdm.s.pDmac)
2639 {
2640 bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns);
2641 if (fMore)
2642 VM_FF_SET(pVM, VM_FF_PDM_DMA);
2643 }
2644 }
2645}
2646
2647
2648/**
2649 * Service a VMMCALLRING3_PDM_LOCK call.
2650 *
2651 * @returns VBox status code.
2652 * @param pVM The cross context VM structure.
2653 */
2654VMMR3_INT_DECL(int) PDMR3LockCall(PVM pVM)
2655{
2656 return PDMR3CritSectEnterEx(&pVM->pdm.s.CritSect, true /* fHostCall */);
2657}
2658
2659
2660/**
2661 * Allocates memory from the VMM device heap.
2662 *
2663 * @returns VBox status code.
2664 * @param pVM The cross context VM structure.
2665 * @param cbSize Allocation size.
2666 * @param pfnNotify Mapping/unmapping notification callback.
2667 * @param ppv Ring-3 pointer. (out)
2668 */
2669VMMR3_INT_DECL(int) PDMR3VmmDevHeapAlloc(PVM pVM, size_t cbSize, PFNPDMVMMDEVHEAPNOTIFY pfnNotify, RTR3PTR *ppv)
2670{
2671#ifdef DEBUG_bird
2672 if (!cbSize || cbSize > pVM->pdm.s.cbVMMDevHeapLeft)
2673 return VERR_NO_MEMORY;
2674#else
2675 AssertReturn(cbSize && cbSize <= pVM->pdm.s.cbVMMDevHeapLeft, VERR_NO_MEMORY);
2676#endif
2677
2678 Log(("PDMR3VMMDevHeapAlloc: %#zx\n", cbSize));
2679
2680 /** @todo Not a real heap as there's currently only one user. */
2681 *ppv = pVM->pdm.s.pvVMMDevHeap;
2682 pVM->pdm.s.cbVMMDevHeapLeft = 0;
2683 pVM->pdm.s.pfnVMMDevHeapNotify = pfnNotify;
2684 return VINF_SUCCESS;
2685}
2686
2687
2688/**
2689 * Frees memory from the VMM device heap
2690 *
2691 * @returns VBox status code.
2692 * @param pVM The cross context VM structure.
2693 * @param pv Ring-3 pointer.
2694 */
2695VMMR3_INT_DECL(int) PDMR3VmmDevHeapFree(PVM pVM, RTR3PTR pv)
2696{
2697 Log(("PDMR3VmmDevHeapFree: %RHv\n", pv)); RT_NOREF_PV(pv);
2698
2699 /** @todo not a real heap as there's currently only one user. */
2700 pVM->pdm.s.cbVMMDevHeapLeft = pVM->pdm.s.cbVMMDevHeap;
2701 pVM->pdm.s.pfnVMMDevHeapNotify = NULL;
2702 return VINF_SUCCESS;
2703}
2704
2705
2706/**
2707 * Worker for DBGFR3TraceConfig that checks if the given tracing group name
2708 * matches a device or driver name and applies the tracing config change.
2709 *
2710 * @returns VINF_SUCCESS or VERR_NOT_FOUND.
2711 * @param pVM The cross context VM structure.
2712 * @param pszName The tracing config group name. This is NULL if
2713 * the operation applies to every device and
2714 * driver.
2715 * @param cchName The length to match.
2716 * @param fEnable Whether to enable or disable the corresponding
2717 * trace points.
2718 * @param fApply Whether to actually apply the changes or just do
2719 * existence checks.
2720 */
2721VMMR3_INT_DECL(int) PDMR3TracingConfig(PVM pVM, const char *pszName, size_t cchName, bool fEnable, bool fApply)
2722{
2723 /** @todo This code is potentially racing driver attaching and detaching. */
2724
2725 /*
2726 * Applies to all.
2727 */
2728 if (pszName == NULL)
2729 {
2730 AssertReturn(fApply, VINF_SUCCESS);
2731
2732 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2733 {
2734 pDevIns->fTracing = fEnable;
2735 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2736 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2737 pDrvIns->fTracing = fEnable;
2738 }
2739
2740#ifdef VBOX_WITH_USB
2741 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2742 {
2743 pUsbIns->fTracing = fEnable;
2744 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2745 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2746 pDrvIns->fTracing = fEnable;
2747
2748 }
2749#endif
2750 return VINF_SUCCESS;
2751 }
2752
2753 /*
2754 * Specific devices, USB devices or drivers.
2755 * Decode prefix to figure which of these it applies to.
2756 */
2757 if (cchName <= 3)
2758 return VERR_NOT_FOUND;
2759
2760 uint32_t cMatches = 0;
2761 if (!strncmp("dev", pszName, 3))
2762 {
2763 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2764 {
2765 const char *pszDevName = pDevIns->Internal.s.pDevR3->pReg->szName;
2766 size_t cchDevName = strlen(pszDevName);
2767 if ( ( cchDevName == cchName
2768 && RTStrNICmp(pszName, pszDevName, cchDevName))
2769 || ( cchDevName == cchName - 3
2770 && RTStrNICmp(pszName + 3, pszDevName, cchDevName)) )
2771 {
2772 cMatches++;
2773 if (fApply)
2774 pDevIns->fTracing = fEnable;
2775 }
2776 }
2777 }
2778 else if (!strncmp("usb", pszName, 3))
2779 {
2780 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2781 {
2782 const char *pszUsbName = pUsbIns->Internal.s.pUsbDev->pReg->szName;
2783 size_t cchUsbName = strlen(pszUsbName);
2784 if ( ( cchUsbName == cchName
2785 && RTStrNICmp(pszName, pszUsbName, cchUsbName))
2786 || ( cchUsbName == cchName - 3
2787 && RTStrNICmp(pszName + 3, pszUsbName, cchUsbName)) )
2788 {
2789 cMatches++;
2790 if (fApply)
2791 pUsbIns->fTracing = fEnable;
2792 }
2793 }
2794 }
2795 else if (!strncmp("drv", pszName, 3))
2796 {
2797 AssertReturn(fApply, VINF_SUCCESS);
2798
2799 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2800 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2801 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2802 {
2803 const char *pszDrvName = pDrvIns->Internal.s.pDrv->pReg->szName;
2804 size_t cchDrvName = strlen(pszDrvName);
2805 if ( ( cchDrvName == cchName
2806 && RTStrNICmp(pszName, pszDrvName, cchDrvName))
2807 || ( cchDrvName == cchName - 3
2808 && RTStrNICmp(pszName + 3, pszDrvName, cchDrvName)) )
2809 {
2810 cMatches++;
2811 if (fApply)
2812 pDrvIns->fTracing = fEnable;
2813 }
2814 }
2815
2816#ifdef VBOX_WITH_USB
2817 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2818 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2819 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2820 {
2821 const char *pszDrvName = pDrvIns->Internal.s.pDrv->pReg->szName;
2822 size_t cchDrvName = strlen(pszDrvName);
2823 if ( ( cchDrvName == cchName
2824 && RTStrNICmp(pszName, pszDrvName, cchDrvName))
2825 || ( cchDrvName == cchName - 3
2826 && RTStrNICmp(pszName + 3, pszDrvName, cchDrvName)) )
2827 {
2828 cMatches++;
2829 if (fApply)
2830 pDrvIns->fTracing = fEnable;
2831 }
2832 }
2833#endif
2834 }
2835 else
2836 return VERR_NOT_FOUND;
2837
2838 return cMatches > 0 ? VINF_SUCCESS : VERR_NOT_FOUND;
2839}
2840
2841
2842/**
2843 * Worker for DBGFR3TraceQueryConfig that checks whether all drivers, devices,
2844 * and USB device have the same tracing settings.
2845 *
2846 * @returns true / false.
2847 * @param pVM The cross context VM structure.
2848 * @param fEnabled The tracing setting to check for.
2849 */
2850VMMR3_INT_DECL(bool) PDMR3TracingAreAll(PVM pVM, bool fEnabled)
2851{
2852 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2853 {
2854 if (pDevIns->fTracing != (uint32_t)fEnabled)
2855 return false;
2856
2857 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2858 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2859 if (pDrvIns->fTracing != (uint32_t)fEnabled)
2860 return false;
2861 }
2862
2863#ifdef VBOX_WITH_USB
2864 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2865 {
2866 if (pUsbIns->fTracing != (uint32_t)fEnabled)
2867 return false;
2868
2869 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2870 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2871 if (pDrvIns->fTracing != (uint32_t)fEnabled)
2872 return false;
2873 }
2874#endif
2875
2876 return true;
2877}
2878
2879
2880/**
2881 * Worker for PDMR3TracingQueryConfig that adds a prefixed name to the output
2882 * string.
2883 *
2884 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW
2885 * @param ppszDst The pointer to the output buffer pointer.
2886 * @param pcbDst The pointer to the output buffer size.
2887 * @param fSpace Whether to add a space before the name.
2888 * @param pszPrefix The name prefix.
2889 * @param pszName The name.
2890 */
2891static int pdmR3TracingAdd(char **ppszDst, size_t *pcbDst, bool fSpace, const char *pszPrefix, const char *pszName)
2892{
2893 size_t const cchPrefix = strlen(pszPrefix);
2894 if (!RTStrNICmp(pszPrefix, pszName, cchPrefix))
2895 pszName += cchPrefix;
2896 size_t const cchName = strlen(pszName);
2897
2898 size_t const cchThis = cchName + cchPrefix + fSpace;
2899 if (cchThis >= *pcbDst)
2900 return VERR_BUFFER_OVERFLOW;
2901 if (fSpace)
2902 {
2903 **ppszDst = ' ';
2904 memcpy(*ppszDst + 1, pszPrefix, cchPrefix);
2905 memcpy(*ppszDst + 1 + cchPrefix, pszName, cchName + 1);
2906 }
2907 else
2908 {
2909 memcpy(*ppszDst, pszPrefix, cchPrefix);
2910 memcpy(*ppszDst + cchPrefix, pszName, cchName + 1);
2911 }
2912 *ppszDst += cchThis;
2913 *pcbDst -= cchThis;
2914 return VINF_SUCCESS;
2915}
2916
2917
2918/**
2919 * Worker for DBGFR3TraceQueryConfig use when not everything is either enabled
2920 * or disabled.
2921 *
2922 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW
2923 * @param pVM The cross context VM structure.
2924 * @param pszConfig Where to store the config spec.
2925 * @param cbConfig The size of the output buffer.
2926 */
2927VMMR3_INT_DECL(int) PDMR3TracingQueryConfig(PVM pVM, char *pszConfig, size_t cbConfig)
2928{
2929 int rc;
2930 char *pszDst = pszConfig;
2931 size_t cbDst = cbConfig;
2932
2933 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
2934 {
2935 if (pDevIns->fTracing)
2936 {
2937 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "dev", pDevIns->Internal.s.pDevR3->pReg->szName);
2938 if (RT_FAILURE(rc))
2939 return rc;
2940 }
2941
2942 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2943 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2944 if (pDrvIns->fTracing)
2945 {
2946 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName);
2947 if (RT_FAILURE(rc))
2948 return rc;
2949 }
2950 }
2951
2952#ifdef VBOX_WITH_USB
2953 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
2954 {
2955 if (pUsbIns->fTracing)
2956 {
2957 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "usb", pUsbIns->Internal.s.pUsbDev->pReg->szName);
2958 if (RT_FAILURE(rc))
2959 return rc;
2960 }
2961
2962 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
2963 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
2964 if (pDrvIns->fTracing)
2965 {
2966 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName);
2967 if (RT_FAILURE(rc))
2968 return rc;
2969 }
2970 }
2971#endif
2972
2973 return VINF_SUCCESS;
2974}
2975
2976
2977/**
2978 * Checks that a PDMDRVREG::szName, PDMDEVREG::szName or PDMUSBREG::szName
2979 * field contains only a limited set of ASCII characters.
2980 *
2981 * @returns true / false.
2982 * @param pszName The name to validate.
2983 */
2984bool pdmR3IsValidName(const char *pszName)
2985{
2986 char ch;
2987 while ( (ch = *pszName) != '\0'
2988 && ( RT_C_IS_ALNUM(ch)
2989 || ch == '-'
2990 || ch == ' ' /** @todo disallow this! */
2991 || ch == '_') )
2992 pszName++;
2993 return ch == '\0';
2994}
2995
2996
2997/**
2998 * Info handler for 'pdmtracingids'.
2999 *
3000 * @param pVM The cross context VM structure.
3001 * @param pHlp The output helpers.
3002 * @param pszArgs The optional user arguments.
3003 *
3004 * @remarks Can be called on most threads.
3005 */
3006static DECLCALLBACK(void) pdmR3InfoTracingIds(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
3007{
3008 /*
3009 * Parse the argument (optional).
3010 */
3011 if ( pszArgs
3012 && *pszArgs
3013 && strcmp(pszArgs, "all")
3014 && strcmp(pszArgs, "devices")
3015 && strcmp(pszArgs, "drivers")
3016 && strcmp(pszArgs, "usb"))
3017 {
3018 pHlp->pfnPrintf(pHlp, "Unable to grok '%s'\n", pszArgs);
3019 return;
3020 }
3021 bool fAll = !pszArgs || !*pszArgs || !strcmp(pszArgs, "all");
3022 bool fDevices = fAll || !strcmp(pszArgs, "devices");
3023 bool fUsbDevs = fAll || !strcmp(pszArgs, "usb");
3024 bool fDrivers = fAll || !strcmp(pszArgs, "drivers");
3025
3026 /*
3027 * Produce the requested output.
3028 */
3029/** @todo lock PDM lists! */
3030 /* devices */
3031 if (fDevices)
3032 {
3033 pHlp->pfnPrintf(pHlp, "Device tracing IDs:\n");
3034 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
3035 pHlp->pfnPrintf(pHlp, "%05u %s\n", pDevIns->idTracing, pDevIns->Internal.s.pDevR3->pReg->szName);
3036 }
3037
3038 /* USB devices */
3039 if (fUsbDevs)
3040 {
3041 pHlp->pfnPrintf(pHlp, "USB device tracing IDs:\n");
3042 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
3043 pHlp->pfnPrintf(pHlp, "%05u %s\n", pUsbIns->idTracing, pUsbIns->Internal.s.pUsbDev->pReg->szName);
3044 }
3045
3046 /* Drivers */
3047 if (fDrivers)
3048 {
3049 pHlp->pfnPrintf(pHlp, "Driver tracing IDs:\n");
3050 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
3051 {
3052 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
3053 {
3054 uint32_t iLevel = 0;
3055 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown, iLevel++)
3056 pHlp->pfnPrintf(pHlp, "%05u %s (level %u, lun %u, dev %s)\n",
3057 pDrvIns->idTracing, pDrvIns->Internal.s.pDrv->pReg->szName,
3058 iLevel, pLun->iLun, pDevIns->Internal.s.pDevR3->pReg->szName);
3059 }
3060 }
3061
3062 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
3063 {
3064 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
3065 {
3066 uint32_t iLevel = 0;
3067 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown, iLevel++)
3068 pHlp->pfnPrintf(pHlp, "%05u %s (level %u, lun %u, dev %s)\n",
3069 pDrvIns->idTracing, pDrvIns->Internal.s.pDrv->pReg->szName,
3070 iLevel, pLun->iLun, pUsbIns->Internal.s.pUsbDev->pReg->szName);
3071 }
3072 }
3073 }
3074}
3075
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