1 | /* $Id: PDM.cpp 81513 2019-10-24 09:23:02Z 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 | */
|
---|
402 | typedef 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. */
|
---|
420 | typedef PDMNOTIFYASYNCSTATS *PPDMNOTIFYASYNCSTATS;
|
---|
421 |
|
---|
422 |
|
---|
423 | /*********************************************************************************************************************************
|
---|
424 | * Internal Functions *
|
---|
425 | *********************************************************************************************************************************/
|
---|
426 | static DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass);
|
---|
427 | static DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM);
|
---|
428 | static DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
|
---|
429 | static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
|
---|
430 |
|
---|
431 | static 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 | */
|
---|
443 | VMMR3_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 | */
|
---|
460 | VMMR3_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 | */
|
---|
554 | VMMR3_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 | */
|
---|
572 | VMMR3_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 | */
|
---|
700 | static 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 | */
|
---|
755 | VMMR3_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 | Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
821 | Req.Hdr.cbReq = sizeof(Req);
|
---|
822 | Req.enmCall = PDMDEVICEGENCALL_DESTRUCT;
|
---|
823 | Req.idxR0Device = pDevIns->Internal.s.idxR0Device;
|
---|
824 | Req.pDevInsR3 = pDevIns;
|
---|
825 | int rc2 = VMMR3CallR0(pVM, VMMR0_DO_PDM_DEVICE_GEN_CALL, 0, &Req.Hdr);
|
---|
826 | AssertRC(rc2);
|
---|
827 | }
|
---|
828 |
|
---|
829 | TMR3TimerDestroyDevice(pVM, pDevIns);
|
---|
830 | SSMR3DeregisterDevice(pVM, pDevIns, NULL, 0);
|
---|
831 | pdmR3CritSectBothDeleteDevice(pVM, pDevIns);
|
---|
832 | pdmR3ThreadDestroyDevice(pVM, pDevIns);
|
---|
833 | PDMR3QueueDestroyDevice(pVM, pDevIns);
|
---|
834 | PGMR3PhysMMIOExDeregister(pVM, pDevIns, UINT32_MAX, UINT32_MAX);
|
---|
835 | #ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
|
---|
836 | pdmR3AsyncCompletionTemplateDestroyDevice(pVM, pDevIns);
|
---|
837 | #endif
|
---|
838 | DBGFR3InfoDeregisterDevice(pVM, pDevIns, NULL);
|
---|
839 | }
|
---|
840 |
|
---|
841 | /*
|
---|
842 | * Destroy all threads.
|
---|
843 | */
|
---|
844 | pdmR3ThreadDestroyAll(pVM);
|
---|
845 |
|
---|
846 | /*
|
---|
847 | * Destroy the block cache.
|
---|
848 | */
|
---|
849 | pdmR3BlkCacheTerm(pVM);
|
---|
850 |
|
---|
851 | #ifdef VBOX_WITH_NETSHAPER
|
---|
852 | /*
|
---|
853 | * Destroy network bandwidth groups.
|
---|
854 | */
|
---|
855 | pdmR3NetShaperTerm(pVM);
|
---|
856 | #endif
|
---|
857 | #ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
|
---|
858 | /*
|
---|
859 | * Free async completion managers.
|
---|
860 | */
|
---|
861 | pdmR3AsyncCompletionTerm(pVM);
|
---|
862 | #endif
|
---|
863 |
|
---|
864 | /*
|
---|
865 | * Free modules.
|
---|
866 | */
|
---|
867 | pdmR3LdrTermU(pVM->pUVM);
|
---|
868 |
|
---|
869 | /*
|
---|
870 | * Stop task threads.
|
---|
871 | */
|
---|
872 | pdmR3TaskTerm(pVM);
|
---|
873 |
|
---|
874 | /*
|
---|
875 | * Destroy the PDM lock.
|
---|
876 | */
|
---|
877 | PDMR3CritSectDelete(&pVM->pdm.s.CritSect);
|
---|
878 | /* The MiscCritSect is deleted by PDMR3CritSectBothTerm later. */
|
---|
879 |
|
---|
880 | LogFlow(("PDMR3Term: returns %Rrc\n", VINF_SUCCESS));
|
---|
881 | return VINF_SUCCESS;
|
---|
882 | }
|
---|
883 |
|
---|
884 |
|
---|
885 | /**
|
---|
886 | * Terminates the PDM part of the UVM.
|
---|
887 | *
|
---|
888 | * This will unload any modules left behind.
|
---|
889 | *
|
---|
890 | * @param pUVM Pointer to the user mode VM structure.
|
---|
891 | */
|
---|
892 | VMMR3_INT_DECL(void) PDMR3TermUVM(PUVM pUVM)
|
---|
893 | {
|
---|
894 | /*
|
---|
895 | * In the normal cause of events we will now call pdmR3LdrTermU for
|
---|
896 | * the second time. In the case of init failure however, this might
|
---|
897 | * the first time, which is why we do it.
|
---|
898 | */
|
---|
899 | pdmR3LdrTermU(pUVM);
|
---|
900 |
|
---|
901 | Assert(pUVM->pdm.s.pCritSects == NULL);
|
---|
902 | Assert(pUVM->pdm.s.pRwCritSects == NULL);
|
---|
903 | RTCritSectDelete(&pUVM->pdm.s.ListCritSect);
|
---|
904 | }
|
---|
905 |
|
---|
906 |
|
---|
907 | /**
|
---|
908 | * For APIC assertions.
|
---|
909 | *
|
---|
910 | * @returns true if we've loaded state.
|
---|
911 | * @param pVM The cross context VM structure.
|
---|
912 | */
|
---|
913 | VMMR3_INT_DECL(bool) PDMR3HasLoadedState(PVM pVM)
|
---|
914 | {
|
---|
915 | return pVM->pdm.s.fStateLoaded;
|
---|
916 | }
|
---|
917 |
|
---|
918 |
|
---|
919 | /**
|
---|
920 | * Bits that are saved in pass 0 and in the final pass.
|
---|
921 | *
|
---|
922 | * @param pVM The cross context VM structure.
|
---|
923 | * @param pSSM The saved state handle.
|
---|
924 | */
|
---|
925 | static void pdmR3SaveBoth(PVM pVM, PSSMHANDLE pSSM)
|
---|
926 | {
|
---|
927 | /*
|
---|
928 | * Save the list of device instances so we can check that they're all still
|
---|
929 | * there when we load the state and that nothing new has been added.
|
---|
930 | */
|
---|
931 | uint32_t i = 0;
|
---|
932 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3, i++)
|
---|
933 | {
|
---|
934 | SSMR3PutU32(pSSM, i);
|
---|
935 | SSMR3PutStrZ(pSSM, pDevIns->pReg->szName);
|
---|
936 | SSMR3PutU32(pSSM, pDevIns->iInstance);
|
---|
937 | }
|
---|
938 | SSMR3PutU32(pSSM, UINT32_MAX); /* terminator */
|
---|
939 | }
|
---|
940 |
|
---|
941 |
|
---|
942 | /**
|
---|
943 | * Live save.
|
---|
944 | *
|
---|
945 | * @returns VBox status code.
|
---|
946 | * @param pVM The cross context VM structure.
|
---|
947 | * @param pSSM The saved state handle.
|
---|
948 | * @param uPass The pass.
|
---|
949 | */
|
---|
950 | static DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass)
|
---|
951 | {
|
---|
952 | LogFlow(("pdmR3LiveExec:\n"));
|
---|
953 | AssertReturn(uPass == 0, VERR_SSM_UNEXPECTED_PASS);
|
---|
954 | pdmR3SaveBoth(pVM, pSSM);
|
---|
955 | return VINF_SSM_DONT_CALL_AGAIN;
|
---|
956 | }
|
---|
957 |
|
---|
958 |
|
---|
959 | /**
|
---|
960 | * Execute state save operation.
|
---|
961 | *
|
---|
962 | * @returns VBox status code.
|
---|
963 | * @param pVM The cross context VM structure.
|
---|
964 | * @param pSSM The saved state handle.
|
---|
965 | */
|
---|
966 | static DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM)
|
---|
967 | {
|
---|
968 | LogFlow(("pdmR3SaveExec:\n"));
|
---|
969 |
|
---|
970 | /*
|
---|
971 | * Save interrupt and DMA states.
|
---|
972 | */
|
---|
973 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
974 | {
|
---|
975 | PVMCPU pVCpu = pVM->apCpusR3[idCpu];
|
---|
976 | SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC));
|
---|
977 | SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC));
|
---|
978 | SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI));
|
---|
979 | SSMR3PutU32(pSSM, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI));
|
---|
980 | }
|
---|
981 | SSMR3PutU32(pSSM, VM_FF_IS_SET(pVM, VM_FF_PDM_DMA));
|
---|
982 |
|
---|
983 | pdmR3SaveBoth(pVM, pSSM);
|
---|
984 | return VINF_SUCCESS;
|
---|
985 | }
|
---|
986 |
|
---|
987 |
|
---|
988 | /**
|
---|
989 | * Prepare state load operation.
|
---|
990 | *
|
---|
991 | * This will dispatch pending operations and clear the FFs governed by PDM and its devices.
|
---|
992 | *
|
---|
993 | * @returns VBox status code.
|
---|
994 | * @param pVM The cross context VM structure.
|
---|
995 | * @param pSSM The SSM handle.
|
---|
996 | */
|
---|
997 | static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
|
---|
998 | {
|
---|
999 | LogFlow(("pdmR3LoadPrep: %s%s\n",
|
---|
1000 | VM_FF_IS_SET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
|
---|
1001 | VM_FF_IS_SET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : ""));
|
---|
1002 | #ifdef LOG_ENABLED
|
---|
1003 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
1004 | {
|
---|
1005 | PVMCPU pVCpu = pVM->apCpusR3[idCpu];
|
---|
1006 | LogFlow(("pdmR3LoadPrep: VCPU %u %s%s\n", idCpu,
|
---|
1007 | VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC) ? " VMCPU_FF_INTERRUPT_APIC" : "",
|
---|
1008 | VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC) ? " VMCPU_FF_INTERRUPT_PIC" : ""));
|
---|
1009 | }
|
---|
1010 | #endif
|
---|
1011 | NOREF(pSSM);
|
---|
1012 |
|
---|
1013 | /*
|
---|
1014 | * In case there is work pending that will raise an interrupt,
|
---|
1015 | * start a DMA transfer, or release a lock. (unlikely)
|
---|
1016 | */
|
---|
1017 | if (VM_FF_IS_SET(pVM, VM_FF_PDM_QUEUES))
|
---|
1018 | PDMR3QueueFlushAll(pVM);
|
---|
1019 |
|
---|
1020 | /* Clear the FFs. */
|
---|
1021 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
1022 | {
|
---|
1023 | PVMCPU pVCpu = pVM->apCpusR3[idCpu];
|
---|
1024 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
|
---|
1025 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
|
---|
1026 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
|
---|
1027 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
|
---|
1028 | }
|
---|
1029 | VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
|
---|
1030 |
|
---|
1031 | return VINF_SUCCESS;
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 |
|
---|
1035 | /**
|
---|
1036 | * Execute state load operation.
|
---|
1037 | *
|
---|
1038 | * @returns VBox status code.
|
---|
1039 | * @param pVM The cross context VM structure.
|
---|
1040 | * @param pSSM SSM operation handle.
|
---|
1041 | * @param uVersion Data layout version.
|
---|
1042 | * @param uPass The data pass.
|
---|
1043 | */
|
---|
1044 | static DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
|
---|
1045 | {
|
---|
1046 | int rc;
|
---|
1047 |
|
---|
1048 | LogFlow(("pdmR3LoadExec: uPass=%#x\n", uPass));
|
---|
1049 |
|
---|
1050 | /*
|
---|
1051 | * Validate version.
|
---|
1052 | */
|
---|
1053 | if ( uVersion != PDM_SAVED_STATE_VERSION
|
---|
1054 | && uVersion != PDM_SAVED_STATE_VERSION_PRE_NMI_FF
|
---|
1055 | && uVersion != PDM_SAVED_STATE_VERSION_PRE_PDM_AUDIO)
|
---|
1056 | {
|
---|
1057 | AssertMsgFailed(("Invalid version uVersion=%d!\n", uVersion));
|
---|
1058 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | if (uPass == SSM_PASS_FINAL)
|
---|
1062 | {
|
---|
1063 | /*
|
---|
1064 | * Load the interrupt and DMA states.
|
---|
1065 | *
|
---|
1066 | * The APIC, PIC and DMA devices does not restore these, we do. In the
|
---|
1067 | * APIC and PIC cases, it is possible that some devices is incorrectly
|
---|
1068 | * setting IRQs during restore. We'll warn when this happens. (There
|
---|
1069 | * are debug assertions in PDMDevMiscHlp.cpp and APICAll.cpp for
|
---|
1070 | * catching the buggy device.)
|
---|
1071 | */
|
---|
1072 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
1073 | {
|
---|
1074 | PVMCPU pVCpu = pVM->apCpusR3[idCpu];
|
---|
1075 |
|
---|
1076 | /* APIC interrupt */
|
---|
1077 | uint32_t fInterruptPending = 0;
|
---|
1078 | rc = SSMR3GetU32(pSSM, &fInterruptPending);
|
---|
1079 | if (RT_FAILURE(rc))
|
---|
1080 | return rc;
|
---|
1081 | if (fInterruptPending & ~1)
|
---|
1082 | {
|
---|
1083 | AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
|
---|
1084 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
1085 | }
|
---|
1086 | AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC),
|
---|
1087 | ("VCPU%03u: VMCPU_FF_INTERRUPT_APIC set! Devices shouldn't set interrupts during state restore...\n", idCpu));
|
---|
1088 | if (fInterruptPending)
|
---|
1089 | VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC);
|
---|
1090 |
|
---|
1091 | /* PIC interrupt */
|
---|
1092 | fInterruptPending = 0;
|
---|
1093 | rc = SSMR3GetU32(pSSM, &fInterruptPending);
|
---|
1094 | if (RT_FAILURE(rc))
|
---|
1095 | return rc;
|
---|
1096 | if (fInterruptPending & ~1)
|
---|
1097 | {
|
---|
1098 | AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
|
---|
1099 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
1100 | }
|
---|
1101 | AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC),
|
---|
1102 | ("VCPU%03u: VMCPU_FF_INTERRUPT_PIC set! Devices shouldn't set interrupts during state restore...\n", idCpu));
|
---|
1103 | if (fInterruptPending)
|
---|
1104 | VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
|
---|
1105 |
|
---|
1106 | if (uVersion > PDM_SAVED_STATE_VERSION_PRE_NMI_FF)
|
---|
1107 | {
|
---|
1108 | /* NMI interrupt */
|
---|
1109 | fInterruptPending = 0;
|
---|
1110 | rc = SSMR3GetU32(pSSM, &fInterruptPending);
|
---|
1111 | if (RT_FAILURE(rc))
|
---|
1112 | return rc;
|
---|
1113 | if (fInterruptPending & ~1)
|
---|
1114 | {
|
---|
1115 | AssertMsgFailed(("fInterruptPending=%#x (NMI)\n", fInterruptPending));
|
---|
1116 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
1117 | }
|
---|
1118 | AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI), ("VCPU%3u: VMCPU_FF_INTERRUPT_NMI set!\n", idCpu));
|
---|
1119 | if (fInterruptPending)
|
---|
1120 | VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI);
|
---|
1121 |
|
---|
1122 | /* SMI interrupt */
|
---|
1123 | fInterruptPending = 0;
|
---|
1124 | rc = SSMR3GetU32(pSSM, &fInterruptPending);
|
---|
1125 | if (RT_FAILURE(rc))
|
---|
1126 | return rc;
|
---|
1127 | if (fInterruptPending & ~1)
|
---|
1128 | {
|
---|
1129 | AssertMsgFailed(("fInterruptPending=%#x (SMI)\n", fInterruptPending));
|
---|
1130 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
1131 | }
|
---|
1132 | AssertLogRelMsg(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI), ("VCPU%3u: VMCPU_FF_INTERRUPT_SMI set!\n", idCpu));
|
---|
1133 | if (fInterruptPending)
|
---|
1134 | VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI);
|
---|
1135 | }
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | /* DMA pending */
|
---|
1139 | uint32_t fDMAPending = 0;
|
---|
1140 | rc = SSMR3GetU32(pSSM, &fDMAPending);
|
---|
1141 | if (RT_FAILURE(rc))
|
---|
1142 | return rc;
|
---|
1143 | if (fDMAPending & ~1)
|
---|
1144 | {
|
---|
1145 | AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
|
---|
1146 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
1147 | }
|
---|
1148 | if (fDMAPending)
|
---|
1149 | VM_FF_SET(pVM, VM_FF_PDM_DMA);
|
---|
1150 | Log(("pdmR3LoadExec: VM_FF_PDM_DMA=%RTbool\n", VM_FF_IS_SET(pVM, VM_FF_PDM_DMA)));
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | /*
|
---|
1154 | * Load the list of devices and verify that they are all there.
|
---|
1155 | */
|
---|
1156 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1157 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_FOUND;
|
---|
1158 |
|
---|
1159 | for (uint32_t i = 0; ; i++)
|
---|
1160 | {
|
---|
1161 | /* Get the sequence number / terminator. */
|
---|
1162 | uint32_t u32Sep;
|
---|
1163 | rc = SSMR3GetU32(pSSM, &u32Sep);
|
---|
1164 | if (RT_FAILURE(rc))
|
---|
1165 | return rc;
|
---|
1166 | if (u32Sep == UINT32_MAX)
|
---|
1167 | break;
|
---|
1168 | if (u32Sep != i)
|
---|
1169 | AssertMsgFailedReturn(("Out of sequence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
|
---|
1170 |
|
---|
1171 | /* Get the name and instance number. */
|
---|
1172 | char szName[RT_SIZEOFMEMB(PDMDEVREG, szName)];
|
---|
1173 | rc = SSMR3GetStrZ(pSSM, szName, sizeof(szName));
|
---|
1174 | if (RT_FAILURE(rc))
|
---|
1175 | return rc;
|
---|
1176 | uint32_t iInstance;
|
---|
1177 | rc = SSMR3GetU32(pSSM, &iInstance);
|
---|
1178 | if (RT_FAILURE(rc))
|
---|
1179 | return rc;
|
---|
1180 |
|
---|
1181 | /* Try locate it. */
|
---|
1182 | PPDMDEVINS pDevIns;
|
---|
1183 | for (pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1184 | if ( !RTStrCmp(szName, pDevIns->pReg->szName)
|
---|
1185 | && pDevIns->iInstance == iInstance)
|
---|
1186 | {
|
---|
1187 | AssertLogRelMsgReturn(!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND),
|
---|
1188 | ("%s/#%u\n", pDevIns->pReg->szName, pDevIns->iInstance),
|
---|
1189 | VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
|
---|
1190 | pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_FOUND;
|
---|
1191 | break;
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | if (!pDevIns)
|
---|
1195 | {
|
---|
1196 | bool fSkip = false;
|
---|
1197 |
|
---|
1198 | /* Skip the non-existing (deprecated) "AudioSniffer" device stored in the saved state. */
|
---|
1199 | if ( uVersion <= PDM_SAVED_STATE_VERSION_PRE_PDM_AUDIO
|
---|
1200 | && !RTStrCmp(szName, "AudioSniffer"))
|
---|
1201 | fSkip = true;
|
---|
1202 |
|
---|
1203 | if (!fSkip)
|
---|
1204 | {
|
---|
1205 | LogRel(("Device '%s'/%d not found in current config\n", szName, iInstance));
|
---|
1206 | if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
|
---|
1207 | return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in current config"), szName, iInstance);
|
---|
1208 | }
|
---|
1209 | }
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 | /*
|
---|
1213 | * Check that no additional devices were configured.
|
---|
1214 | */
|
---|
1215 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1216 | if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND))
|
---|
1217 | {
|
---|
1218 | LogRel(("Device '%s'/%d not found in the saved state\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1219 | if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
|
---|
1220 | return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in the saved state"),
|
---|
1221 | pDevIns->pReg->szName, pDevIns->iInstance);
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 |
|
---|
1225 | /*
|
---|
1226 | * Indicate that we've been called (for assertions).
|
---|
1227 | */
|
---|
1228 | pVM->pdm.s.fStateLoaded = true;
|
---|
1229 |
|
---|
1230 | return VINF_SUCCESS;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 |
|
---|
1234 | /**
|
---|
1235 | * Worker for PDMR3PowerOn that deals with one driver.
|
---|
1236 | *
|
---|
1237 | * @param pDrvIns The driver instance.
|
---|
1238 | * @param pszDevName The parent device name.
|
---|
1239 | * @param iDevInstance The parent device instance number.
|
---|
1240 | * @param iLun The parent LUN number.
|
---|
1241 | */
|
---|
1242 | DECLINLINE(int) pdmR3PowerOnDrv(PPDMDRVINS pDrvIns, const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
|
---|
1243 | {
|
---|
1244 | Assert(pDrvIns->Internal.s.fVMSuspended);
|
---|
1245 | if (pDrvIns->pReg->pfnPowerOn)
|
---|
1246 | {
|
---|
1247 | LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1248 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1249 | int rc = VINF_SUCCESS; pDrvIns->pReg->pfnPowerOn(pDrvIns);
|
---|
1250 | if (RT_FAILURE(rc))
|
---|
1251 | {
|
---|
1252 | LogRel(("PDMR3PowerOn: Driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
|
---|
1253 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, rc));
|
---|
1254 | return rc;
|
---|
1255 | }
|
---|
1256 | }
|
---|
1257 | pDrvIns->Internal.s.fVMSuspended = false;
|
---|
1258 | return VINF_SUCCESS;
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 |
|
---|
1262 | /**
|
---|
1263 | * Worker for PDMR3PowerOn that deals with one USB device instance.
|
---|
1264 | *
|
---|
1265 | * @returns VBox status code.
|
---|
1266 | * @param pUsbIns The USB device instance.
|
---|
1267 | */
|
---|
1268 | DECLINLINE(int) pdmR3PowerOnUsb(PPDMUSBINS pUsbIns)
|
---|
1269 | {
|
---|
1270 | Assert(pUsbIns->Internal.s.fVMSuspended);
|
---|
1271 | if (pUsbIns->pReg->pfnVMPowerOn)
|
---|
1272 | {
|
---|
1273 | LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1274 | int rc = VINF_SUCCESS; pUsbIns->pReg->pfnVMPowerOn(pUsbIns);
|
---|
1275 | if (RT_FAILURE(rc))
|
---|
1276 | {
|
---|
1277 | LogRel(("PDMR3PowerOn: Device '%s'/%d -> %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
|
---|
1278 | return rc;
|
---|
1279 | }
|
---|
1280 | }
|
---|
1281 | pUsbIns->Internal.s.fVMSuspended = false;
|
---|
1282 | return VINF_SUCCESS;
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | /**
|
---|
1287 | * Worker for PDMR3PowerOn that deals with one device instance.
|
---|
1288 | *
|
---|
1289 | * @returns VBox status code.
|
---|
1290 | * @param pDevIns The device instance.
|
---|
1291 | */
|
---|
1292 | DECLINLINE(int) pdmR3PowerOnDev(PPDMDEVINS pDevIns)
|
---|
1293 | {
|
---|
1294 | Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
|
---|
1295 | if (pDevIns->pReg->pfnPowerOn)
|
---|
1296 | {
|
---|
1297 | LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1298 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
1299 | int rc = VINF_SUCCESS; pDevIns->pReg->pfnPowerOn(pDevIns);
|
---|
1300 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
1301 | if (RT_FAILURE(rc))
|
---|
1302 | {
|
---|
1303 | LogRel(("PDMR3PowerOn: Device '%s'/%d -> %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
|
---|
1304 | return rc;
|
---|
1305 | }
|
---|
1306 | }
|
---|
1307 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
1308 | return VINF_SUCCESS;
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 |
|
---|
1312 | /**
|
---|
1313 | * This function will notify all the devices and their
|
---|
1314 | * attached drivers about the VM now being powered on.
|
---|
1315 | *
|
---|
1316 | * @param pVM The cross context VM structure.
|
---|
1317 | */
|
---|
1318 | VMMR3DECL(void) PDMR3PowerOn(PVM pVM)
|
---|
1319 | {
|
---|
1320 | LogFlow(("PDMR3PowerOn:\n"));
|
---|
1321 |
|
---|
1322 | /*
|
---|
1323 | * Iterate thru the device instances and USB device instances,
|
---|
1324 | * processing the drivers associated with those.
|
---|
1325 | */
|
---|
1326 | int rc = VINF_SUCCESS;
|
---|
1327 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1328 | {
|
---|
1329 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
|
---|
1330 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
1331 | rc = pdmR3PowerOnDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun);
|
---|
1332 | if (RT_SUCCESS(rc))
|
---|
1333 | rc = pdmR3PowerOnDev(pDevIns);
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | #ifdef VBOX_WITH_USB
|
---|
1337 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
1338 | {
|
---|
1339 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
|
---|
1340 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
1341 | rc = pdmR3PowerOnDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun);
|
---|
1342 | if (RT_SUCCESS(rc))
|
---|
1343 | rc = pdmR3PowerOnUsb(pUsbIns);
|
---|
1344 | }
|
---|
1345 | #endif
|
---|
1346 |
|
---|
1347 | #ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
|
---|
1348 | pdmR3AsyncCompletionResume(pVM);
|
---|
1349 | #endif
|
---|
1350 |
|
---|
1351 | /*
|
---|
1352 | * Resume all threads.
|
---|
1353 | */
|
---|
1354 | if (RT_SUCCESS(rc))
|
---|
1355 | pdmR3ThreadResumeAll(pVM);
|
---|
1356 |
|
---|
1357 | /*
|
---|
1358 | * On failure, clean up via PDMR3Suspend.
|
---|
1359 | */
|
---|
1360 | if (RT_FAILURE(rc))
|
---|
1361 | PDMR3Suspend(pVM);
|
---|
1362 |
|
---|
1363 | LogFlow(("PDMR3PowerOn: returns %Rrc\n", rc));
|
---|
1364 | return /*rc*/;
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 |
|
---|
1368 | /**
|
---|
1369 | * Initializes the asynchronous notifi stats structure.
|
---|
1370 | *
|
---|
1371 | * @param pThis The asynchronous notifification stats.
|
---|
1372 | * @param pszOp The name of the operation.
|
---|
1373 | */
|
---|
1374 | static void pdmR3NotifyAsyncInit(PPDMNOTIFYASYNCSTATS pThis, const char *pszOp)
|
---|
1375 | {
|
---|
1376 | pThis->uStartNsTs = RTTimeNanoTS();
|
---|
1377 | pThis->cNsElapsedNextLog = 0;
|
---|
1378 | pThis->cLoops = 0;
|
---|
1379 | pThis->cAsync = 0;
|
---|
1380 | pThis->pszOp = pszOp;
|
---|
1381 | pThis->offList = 0;
|
---|
1382 | pThis->szList[0] = '\0';
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 |
|
---|
1386 | /**
|
---|
1387 | * Begin a new loop, prepares to gather new stats.
|
---|
1388 | *
|
---|
1389 | * @param pThis The asynchronous notifification stats.
|
---|
1390 | */
|
---|
1391 | static void pdmR3NotifyAsyncBeginLoop(PPDMNOTIFYASYNCSTATS pThis)
|
---|
1392 | {
|
---|
1393 | pThis->cLoops++;
|
---|
1394 | pThis->cAsync = 0;
|
---|
1395 | pThis->offList = 0;
|
---|
1396 | pThis->szList[0] = '\0';
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 |
|
---|
1400 | /**
|
---|
1401 | * Records a device or USB device with a pending asynchronous notification.
|
---|
1402 | *
|
---|
1403 | * @param pThis The asynchronous notifification stats.
|
---|
1404 | * @param pszName The name of the thing.
|
---|
1405 | * @param iInstance The instance number.
|
---|
1406 | */
|
---|
1407 | static void pdmR3NotifyAsyncAdd(PPDMNOTIFYASYNCSTATS pThis, const char *pszName, uint32_t iInstance)
|
---|
1408 | {
|
---|
1409 | pThis->cAsync++;
|
---|
1410 | if (pThis->offList < sizeof(pThis->szList) - 4)
|
---|
1411 | pThis->offList += RTStrPrintf(&pThis->szList[pThis->offList], sizeof(pThis->szList) - pThis->offList,
|
---|
1412 | pThis->offList == 0 ? "%s/%u" : ", %s/%u",
|
---|
1413 | pszName, iInstance);
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 |
|
---|
1417 | /**
|
---|
1418 | * Records the asynchronous completition of a reset, suspend or power off.
|
---|
1419 | *
|
---|
1420 | * @param pThis The asynchronous notifification stats.
|
---|
1421 | * @param pszDrvName The driver name.
|
---|
1422 | * @param iDrvInstance The driver instance number.
|
---|
1423 | * @param pszDevName The device or USB device name.
|
---|
1424 | * @param iDevInstance The device or USB device instance number.
|
---|
1425 | * @param iLun The LUN.
|
---|
1426 | */
|
---|
1427 | static void pdmR3NotifyAsyncAddDrv(PPDMNOTIFYASYNCSTATS pThis, const char *pszDrvName, uint32_t iDrvInstance,
|
---|
1428 | const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
|
---|
1429 | {
|
---|
1430 | pThis->cAsync++;
|
---|
1431 | if (pThis->offList < sizeof(pThis->szList) - 8)
|
---|
1432 | pThis->offList += RTStrPrintf(&pThis->szList[pThis->offList], sizeof(pThis->szList) - pThis->offList,
|
---|
1433 | pThis->offList == 0 ? "%s/%u/%u/%s/%u" : ", %s/%u/%u/%s/%u",
|
---|
1434 | pszDevName, iDevInstance, iLun, pszDrvName, iDrvInstance);
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 |
|
---|
1438 | /**
|
---|
1439 | * Log the stats.
|
---|
1440 | *
|
---|
1441 | * @param pThis The asynchronous notifification stats.
|
---|
1442 | */
|
---|
1443 | static void pdmR3NotifyAsyncLog(PPDMNOTIFYASYNCSTATS pThis)
|
---|
1444 | {
|
---|
1445 | /*
|
---|
1446 | * Return if we shouldn't log at this point.
|
---|
1447 | * We log with an internval increasing from 0 sec to 60 sec.
|
---|
1448 | */
|
---|
1449 | if (!pThis->cAsync)
|
---|
1450 | return;
|
---|
1451 |
|
---|
1452 | uint64_t cNsElapsed = RTTimeNanoTS() - pThis->uStartNsTs;
|
---|
1453 | if (cNsElapsed < pThis->cNsElapsedNextLog)
|
---|
1454 | return;
|
---|
1455 |
|
---|
1456 | if (pThis->cNsElapsedNextLog == 0)
|
---|
1457 | pThis->cNsElapsedNextLog = RT_NS_1SEC;
|
---|
1458 | else if (pThis->cNsElapsedNextLog >= RT_NS_1MIN / 2)
|
---|
1459 | pThis->cNsElapsedNextLog = RT_NS_1MIN;
|
---|
1460 | else
|
---|
1461 | pThis->cNsElapsedNextLog *= 2;
|
---|
1462 |
|
---|
1463 | /*
|
---|
1464 | * Do the logging.
|
---|
1465 | */
|
---|
1466 | LogRel(("%s: after %5llu ms, %u loops: %u async tasks - %s\n",
|
---|
1467 | pThis->pszOp, cNsElapsed / RT_NS_1MS, pThis->cLoops, pThis->cAsync, pThis->szList));
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 |
|
---|
1471 | /**
|
---|
1472 | * Wait for events and process pending requests.
|
---|
1473 | *
|
---|
1474 | * @param pThis The asynchronous notifification stats.
|
---|
1475 | * @param pVM The cross context VM structure.
|
---|
1476 | */
|
---|
1477 | static void pdmR3NotifyAsyncWaitAndProcessRequests(PPDMNOTIFYASYNCSTATS pThis, PVM pVM)
|
---|
1478 | {
|
---|
1479 | VM_ASSERT_EMT0(pVM);
|
---|
1480 | int rc = VMR3AsyncPdmNotificationWaitU(&pVM->pUVM->aCpus[0]);
|
---|
1481 | AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc - %s - %s\n", rc, pThis->pszOp, pThis->szList));
|
---|
1482 |
|
---|
1483 | rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY, true /*fPriorityOnly*/);
|
---|
1484 | AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc - %s - %s\n", rc, pThis->pszOp, pThis->szList));
|
---|
1485 | rc = VMR3ReqProcessU(pVM->pUVM, 0/*idDstCpu*/, true /*fPriorityOnly*/);
|
---|
1486 | AssertReleaseMsg(rc == VINF_SUCCESS, ("%Rrc - %s - %s\n", rc, pThis->pszOp, pThis->szList));
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 |
|
---|
1490 | /**
|
---|
1491 | * Worker for PDMR3Reset that deals with one driver.
|
---|
1492 | *
|
---|
1493 | * @param pDrvIns The driver instance.
|
---|
1494 | * @param pAsync The structure for recording asynchronous
|
---|
1495 | * notification tasks.
|
---|
1496 | * @param pszDevName The parent device name.
|
---|
1497 | * @param iDevInstance The parent device instance number.
|
---|
1498 | * @param iLun The parent LUN number.
|
---|
1499 | */
|
---|
1500 | DECLINLINE(bool) pdmR3ResetDrv(PPDMDRVINS pDrvIns, PPDMNOTIFYASYNCSTATS pAsync,
|
---|
1501 | const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
|
---|
1502 | {
|
---|
1503 | if (!pDrvIns->Internal.s.fVMReset)
|
---|
1504 | {
|
---|
1505 | pDrvIns->Internal.s.fVMReset = true;
|
---|
1506 | if (pDrvIns->pReg->pfnReset)
|
---|
1507 | {
|
---|
1508 | if (!pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
1509 | {
|
---|
1510 | LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1511 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1512 | pDrvIns->pReg->pfnReset(pDrvIns);
|
---|
1513 | if (pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
1514 | LogFlow(("PDMR3Reset: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1515 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1516 | }
|
---|
1517 | else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
|
---|
1518 | {
|
---|
1519 | LogFlow(("PDMR3Reset: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1520 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1521 | pDrvIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
1522 | }
|
---|
1523 | if (pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
1524 | {
|
---|
1525 | pDrvIns->Internal.s.fVMReset = false;
|
---|
1526 | pdmR3NotifyAsyncAddDrv(pAsync, pDrvIns->Internal.s.pDrv->pReg->szName, pDrvIns->iInstance,
|
---|
1527 | pszDevName, iDevInstance, iLun);
|
---|
1528 | return false;
|
---|
1529 | }
|
---|
1530 | }
|
---|
1531 | }
|
---|
1532 | return true;
|
---|
1533 | }
|
---|
1534 |
|
---|
1535 |
|
---|
1536 | /**
|
---|
1537 | * Worker for PDMR3Reset that deals with one USB device instance.
|
---|
1538 | *
|
---|
1539 | * @param pUsbIns The USB device instance.
|
---|
1540 | * @param pAsync The structure for recording asynchronous
|
---|
1541 | * notification tasks.
|
---|
1542 | */
|
---|
1543 | DECLINLINE(void) pdmR3ResetUsb(PPDMUSBINS pUsbIns, PPDMNOTIFYASYNCSTATS pAsync)
|
---|
1544 | {
|
---|
1545 | if (!pUsbIns->Internal.s.fVMReset)
|
---|
1546 | {
|
---|
1547 | pUsbIns->Internal.s.fVMReset = true;
|
---|
1548 | if (pUsbIns->pReg->pfnVMReset)
|
---|
1549 | {
|
---|
1550 | if (!pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
1551 | {
|
---|
1552 | LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1553 | pUsbIns->pReg->pfnVMReset(pUsbIns);
|
---|
1554 | if (pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
1555 | LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1556 | }
|
---|
1557 | else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
|
---|
1558 | {
|
---|
1559 | LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1560 | pUsbIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
1561 | }
|
---|
1562 | if (pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
1563 | {
|
---|
1564 | pUsbIns->Internal.s.fVMReset = false;
|
---|
1565 | pdmR3NotifyAsyncAdd(pAsync, pUsbIns->Internal.s.pUsbDev->pReg->szName, pUsbIns->iInstance);
|
---|
1566 | }
|
---|
1567 | }
|
---|
1568 | }
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 |
|
---|
1572 | /**
|
---|
1573 | * Worker for PDMR3Reset that deals with one device instance.
|
---|
1574 | *
|
---|
1575 | * @param pDevIns The device instance.
|
---|
1576 | * @param pAsync The structure for recording asynchronous
|
---|
1577 | * notification tasks.
|
---|
1578 | */
|
---|
1579 | DECLINLINE(void) pdmR3ResetDev(PPDMDEVINS pDevIns, PPDMNOTIFYASYNCSTATS pAsync)
|
---|
1580 | {
|
---|
1581 | if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_RESET))
|
---|
1582 | {
|
---|
1583 | pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_RESET;
|
---|
1584 | if (pDevIns->pReg->pfnReset)
|
---|
1585 | {
|
---|
1586 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
1587 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
1588 |
|
---|
1589 | if (!pDevIns->Internal.s.pfnAsyncNotify)
|
---|
1590 | {
|
---|
1591 | LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1592 | pDevIns->pReg->pfnReset(pDevIns);
|
---|
1593 | if (pDevIns->Internal.s.pfnAsyncNotify)
|
---|
1594 | LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1595 | }
|
---|
1596 | else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
|
---|
1597 | {
|
---|
1598 | LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1599 | pDevIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
1600 | }
|
---|
1601 | if (pDevIns->Internal.s.pfnAsyncNotify)
|
---|
1602 | {
|
---|
1603 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_RESET;
|
---|
1604 | pdmR3NotifyAsyncAdd(pAsync, pDevIns->Internal.s.pDevR3->pReg->szName, pDevIns->iInstance);
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
1608 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
1609 | if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
|
---|
1610 | LogRel(("PDMR3Reset: Device '%s'/%d took %'llu ns to reset\n",
|
---|
1611 | pDevIns->pReg->szName, pDevIns->iInstance, cNsElapsed));
|
---|
1612 | }
|
---|
1613 | }
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 |
|
---|
1617 | /**
|
---|
1618 | * Resets a virtual CPU.
|
---|
1619 | *
|
---|
1620 | * Used by PDMR3Reset and CPU hot plugging.
|
---|
1621 | *
|
---|
1622 | * @param pVCpu The cross context virtual CPU structure.
|
---|
1623 | */
|
---|
1624 | VMMR3_INT_DECL(void) PDMR3ResetCpu(PVMCPU pVCpu)
|
---|
1625 | {
|
---|
1626 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
|
---|
1627 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
|
---|
1628 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
|
---|
1629 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
|
---|
1630 | }
|
---|
1631 |
|
---|
1632 |
|
---|
1633 | /**
|
---|
1634 | * This function will notify all the devices and their attached drivers about
|
---|
1635 | * the VM now being reset.
|
---|
1636 | *
|
---|
1637 | * @param pVM The cross context VM structure.
|
---|
1638 | */
|
---|
1639 | VMMR3_INT_DECL(void) PDMR3Reset(PVM pVM)
|
---|
1640 | {
|
---|
1641 | LogFlow(("PDMR3Reset:\n"));
|
---|
1642 |
|
---|
1643 | /*
|
---|
1644 | * Clear all the reset flags.
|
---|
1645 | */
|
---|
1646 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1647 | {
|
---|
1648 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_RESET;
|
---|
1649 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
1650 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
1651 | pDrvIns->Internal.s.fVMReset = false;
|
---|
1652 | }
|
---|
1653 | #ifdef VBOX_WITH_USB
|
---|
1654 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
1655 | {
|
---|
1656 | pUsbIns->Internal.s.fVMReset = false;
|
---|
1657 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
1658 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
1659 | pDrvIns->Internal.s.fVMReset = false;
|
---|
1660 | }
|
---|
1661 | #endif
|
---|
1662 |
|
---|
1663 | /*
|
---|
1664 | * The outer loop repeats until there are no more async requests.
|
---|
1665 | */
|
---|
1666 | PDMNOTIFYASYNCSTATS Async;
|
---|
1667 | pdmR3NotifyAsyncInit(&Async, "PDMR3Reset");
|
---|
1668 | for (;;)
|
---|
1669 | {
|
---|
1670 | pdmR3NotifyAsyncBeginLoop(&Async);
|
---|
1671 |
|
---|
1672 | /*
|
---|
1673 | * Iterate thru the device instances and USB device instances,
|
---|
1674 | * processing the drivers associated with those.
|
---|
1675 | */
|
---|
1676 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1677 | {
|
---|
1678 | unsigned const cAsyncStart = Async.cAsync;
|
---|
1679 |
|
---|
1680 | if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION)
|
---|
1681 | pdmR3ResetDev(pDevIns, &Async);
|
---|
1682 |
|
---|
1683 | if (Async.cAsync == cAsyncStart)
|
---|
1684 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
1685 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
1686 | if (!pdmR3ResetDrv(pDrvIns, &Async, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
|
---|
1687 | break;
|
---|
1688 |
|
---|
1689 | if ( Async.cAsync == cAsyncStart
|
---|
1690 | && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION))
|
---|
1691 | pdmR3ResetDev(pDevIns, &Async);
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 | #ifdef VBOX_WITH_USB
|
---|
1695 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
1696 | {
|
---|
1697 | unsigned const cAsyncStart = Async.cAsync;
|
---|
1698 |
|
---|
1699 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
1700 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
1701 | if (!pdmR3ResetDrv(pDrvIns, &Async, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
|
---|
1702 | break;
|
---|
1703 |
|
---|
1704 | if (Async.cAsync == cAsyncStart)
|
---|
1705 | pdmR3ResetUsb(pUsbIns, &Async);
|
---|
1706 | }
|
---|
1707 | #endif
|
---|
1708 | if (!Async.cAsync)
|
---|
1709 | break;
|
---|
1710 | pdmR3NotifyAsyncLog(&Async);
|
---|
1711 | pdmR3NotifyAsyncWaitAndProcessRequests(&Async, pVM);
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | /*
|
---|
1715 | * Clear all pending interrupts and DMA operations.
|
---|
1716 | */
|
---|
1717 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
1718 | PDMR3ResetCpu(pVM->apCpusR3[idCpu]);
|
---|
1719 | VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
|
---|
1720 |
|
---|
1721 | LogFlow(("PDMR3Reset: returns void\n"));
|
---|
1722 | }
|
---|
1723 |
|
---|
1724 |
|
---|
1725 | /**
|
---|
1726 | * This function will tell all the devices to setup up their memory structures
|
---|
1727 | * after VM construction and after VM reset.
|
---|
1728 | *
|
---|
1729 | * @param pVM The cross context VM structure.
|
---|
1730 | * @param fAtReset Indicates the context, after reset if @c true or after
|
---|
1731 | * construction if @c false.
|
---|
1732 | */
|
---|
1733 | VMMR3_INT_DECL(void) PDMR3MemSetup(PVM pVM, bool fAtReset)
|
---|
1734 | {
|
---|
1735 | LogFlow(("PDMR3MemSetup: fAtReset=%RTbool\n", fAtReset));
|
---|
1736 | PDMDEVMEMSETUPCTX const enmCtx = fAtReset ? PDMDEVMEMSETUPCTX_AFTER_RESET : PDMDEVMEMSETUPCTX_AFTER_CONSTRUCTION;
|
---|
1737 |
|
---|
1738 | /*
|
---|
1739 | * Iterate thru the device instances and work the callback.
|
---|
1740 | */
|
---|
1741 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1742 | if (pDevIns->pReg->pfnMemSetup)
|
---|
1743 | {
|
---|
1744 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
1745 | pDevIns->pReg->pfnMemSetup(pDevIns, enmCtx);
|
---|
1746 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
1747 | }
|
---|
1748 |
|
---|
1749 | LogFlow(("PDMR3MemSetup: returns void\n"));
|
---|
1750 | }
|
---|
1751 |
|
---|
1752 |
|
---|
1753 | /**
|
---|
1754 | * Retrieves and resets the info left behind by PDMDevHlpVMReset.
|
---|
1755 | *
|
---|
1756 | * @returns True if hard reset, false if soft reset.
|
---|
1757 | * @param pVM The cross context VM structure.
|
---|
1758 | * @param fOverride If non-zero, the override flags will be used instead
|
---|
1759 | * of the reset flags kept by PDM. (For triple faults.)
|
---|
1760 | * @param pfResetFlags Where to return the reset flags (PDMVMRESET_F_XXX).
|
---|
1761 | * @thread EMT
|
---|
1762 | */
|
---|
1763 | VMMR3_INT_DECL(bool) PDMR3GetResetInfo(PVM pVM, uint32_t fOverride, uint32_t *pfResetFlags)
|
---|
1764 | {
|
---|
1765 | VM_ASSERT_EMT(pVM);
|
---|
1766 |
|
---|
1767 | /*
|
---|
1768 | * Get the reset flags.
|
---|
1769 | */
|
---|
1770 | uint32_t fResetFlags;
|
---|
1771 | fResetFlags = ASMAtomicXchgU32(&pVM->pdm.s.fResetFlags, 0);
|
---|
1772 | if (fOverride)
|
---|
1773 | fResetFlags = fOverride;
|
---|
1774 | *pfResetFlags = fResetFlags;
|
---|
1775 |
|
---|
1776 | /*
|
---|
1777 | * To try avoid trouble, we never ever do soft/warm resets on SMP systems
|
---|
1778 | * with more than CPU #0 active. However, if only one CPU is active we
|
---|
1779 | * will ask the firmware what it wants us to do (because the firmware may
|
---|
1780 | * depend on the VMM doing a lot of what is normally its responsibility,
|
---|
1781 | * like clearing memory).
|
---|
1782 | */
|
---|
1783 | bool fOtherCpusActive = false;
|
---|
1784 | VMCPUID idCpu = pVM->cCpus;
|
---|
1785 | while (idCpu-- > 1)
|
---|
1786 | {
|
---|
1787 | EMSTATE enmState = EMGetState(pVM->apCpusR3[idCpu]);
|
---|
1788 | if ( enmState != EMSTATE_WAIT_SIPI
|
---|
1789 | && enmState != EMSTATE_NONE)
|
---|
1790 | {
|
---|
1791 | fOtherCpusActive = true;
|
---|
1792 | break;
|
---|
1793 | }
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 | bool fHardReset = fOtherCpusActive
|
---|
1797 | || (fResetFlags & PDMVMRESET_F_SRC_MASK) < PDMVMRESET_F_LAST_ALWAYS_HARD
|
---|
1798 | || !pVM->pdm.s.pFirmware
|
---|
1799 | || pVM->pdm.s.pFirmware->Reg.pfnIsHardReset(pVM->pdm.s.pFirmware->pDevIns, fResetFlags);
|
---|
1800 |
|
---|
1801 | Log(("PDMR3GetResetInfo: returns fHardReset=%RTbool fResetFlags=%#x\n", fHardReset, fResetFlags));
|
---|
1802 | return fHardReset;
|
---|
1803 | }
|
---|
1804 |
|
---|
1805 |
|
---|
1806 | /**
|
---|
1807 | * Performs a soft reset of devices.
|
---|
1808 | *
|
---|
1809 | * @param pVM The cross context VM structure.
|
---|
1810 | * @param fResetFlags PDMVMRESET_F_XXX.
|
---|
1811 | */
|
---|
1812 | VMMR3_INT_DECL(void) PDMR3SoftReset(PVM pVM, uint32_t fResetFlags)
|
---|
1813 | {
|
---|
1814 | LogFlow(("PDMR3SoftReset: fResetFlags=%#x\n", fResetFlags));
|
---|
1815 |
|
---|
1816 | /*
|
---|
1817 | * Iterate thru the device instances and work the callback.
|
---|
1818 | */
|
---|
1819 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
1820 | if (pDevIns->pReg->pfnSoftReset)
|
---|
1821 | {
|
---|
1822 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
1823 | pDevIns->pReg->pfnSoftReset(pDevIns, fResetFlags);
|
---|
1824 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
1825 | }
|
---|
1826 |
|
---|
1827 | LogFlow(("PDMR3SoftReset: returns void\n"));
|
---|
1828 | }
|
---|
1829 |
|
---|
1830 |
|
---|
1831 | /**
|
---|
1832 | * Worker for PDMR3Suspend that deals with one driver.
|
---|
1833 | *
|
---|
1834 | * @param pDrvIns The driver instance.
|
---|
1835 | * @param pAsync The structure for recording asynchronous
|
---|
1836 | * notification tasks.
|
---|
1837 | * @param pszDevName The parent device name.
|
---|
1838 | * @param iDevInstance The parent device instance number.
|
---|
1839 | * @param iLun The parent LUN number.
|
---|
1840 | */
|
---|
1841 | DECLINLINE(bool) pdmR3SuspendDrv(PPDMDRVINS pDrvIns, PPDMNOTIFYASYNCSTATS pAsync,
|
---|
1842 | const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
|
---|
1843 | {
|
---|
1844 | if (!pDrvIns->Internal.s.fVMSuspended)
|
---|
1845 | {
|
---|
1846 | pDrvIns->Internal.s.fVMSuspended = true;
|
---|
1847 | if (pDrvIns->pReg->pfnSuspend)
|
---|
1848 | {
|
---|
1849 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
1850 |
|
---|
1851 | if (!pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
1852 | {
|
---|
1853 | LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1854 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1855 | pDrvIns->pReg->pfnSuspend(pDrvIns);
|
---|
1856 | if (pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
1857 | LogFlow(("PDMR3Suspend: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1858 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1859 | }
|
---|
1860 | else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
|
---|
1861 | {
|
---|
1862 | LogFlow(("PDMR3Suspend: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
1863 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
1864 | pDrvIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
1868 | if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
|
---|
1869 | LogRel(("PDMR3Suspend: Driver '%s'/%d on LUN#%d of device '%s'/%d took %'llu ns to suspend\n",
|
---|
1870 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, cNsElapsed));
|
---|
1871 |
|
---|
1872 | if (pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
1873 | {
|
---|
1874 | pDrvIns->Internal.s.fVMSuspended = false;
|
---|
1875 | pdmR3NotifyAsyncAddDrv(pAsync, pDrvIns->Internal.s.pDrv->pReg->szName, pDrvIns->iInstance, pszDevName, iDevInstance, iLun);
|
---|
1876 | return false;
|
---|
1877 | }
|
---|
1878 | }
|
---|
1879 | }
|
---|
1880 | return true;
|
---|
1881 | }
|
---|
1882 |
|
---|
1883 |
|
---|
1884 | /**
|
---|
1885 | * Worker for PDMR3Suspend that deals with one USB device instance.
|
---|
1886 | *
|
---|
1887 | * @param pUsbIns The USB device instance.
|
---|
1888 | * @param pAsync The structure for recording asynchronous
|
---|
1889 | * notification tasks.
|
---|
1890 | */
|
---|
1891 | DECLINLINE(void) pdmR3SuspendUsb(PPDMUSBINS pUsbIns, PPDMNOTIFYASYNCSTATS pAsync)
|
---|
1892 | {
|
---|
1893 | if (!pUsbIns->Internal.s.fVMSuspended)
|
---|
1894 | {
|
---|
1895 | pUsbIns->Internal.s.fVMSuspended = true;
|
---|
1896 | if (pUsbIns->pReg->pfnVMSuspend)
|
---|
1897 | {
|
---|
1898 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
1899 |
|
---|
1900 | if (!pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
1901 | {
|
---|
1902 | LogFlow(("PDMR3Suspend: Notifying - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1903 | pUsbIns->pReg->pfnVMSuspend(pUsbIns);
|
---|
1904 | if (pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
1905 | LogFlow(("PDMR3Suspend: Async notification started - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1906 | }
|
---|
1907 | else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
|
---|
1908 | {
|
---|
1909 | LogFlow(("PDMR3Suspend: Async notification completed - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
1910 | pUsbIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
1911 | }
|
---|
1912 | if (pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
1913 | {
|
---|
1914 | pUsbIns->Internal.s.fVMSuspended = false;
|
---|
1915 | pdmR3NotifyAsyncAdd(pAsync, pUsbIns->Internal.s.pUsbDev->pReg->szName, pUsbIns->iInstance);
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
1919 | if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
|
---|
1920 | LogRel(("PDMR3Suspend: USB device '%s'/%d took %'llu ns to suspend\n",
|
---|
1921 | pUsbIns->pReg->szName, pUsbIns->iInstance, cNsElapsed));
|
---|
1922 | }
|
---|
1923 | }
|
---|
1924 | }
|
---|
1925 |
|
---|
1926 |
|
---|
1927 | /**
|
---|
1928 | * Worker for PDMR3Suspend that deals with one device instance.
|
---|
1929 | *
|
---|
1930 | * @param pDevIns The device instance.
|
---|
1931 | * @param pAsync The structure for recording asynchronous
|
---|
1932 | * notification tasks.
|
---|
1933 | */
|
---|
1934 | DECLINLINE(void) pdmR3SuspendDev(PPDMDEVINS pDevIns, PPDMNOTIFYASYNCSTATS pAsync)
|
---|
1935 | {
|
---|
1936 | if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED))
|
---|
1937 | {
|
---|
1938 | pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
1939 | if (pDevIns->pReg->pfnSuspend)
|
---|
1940 | {
|
---|
1941 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
1942 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
1943 |
|
---|
1944 | if (!pDevIns->Internal.s.pfnAsyncNotify)
|
---|
1945 | {
|
---|
1946 | LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1947 | pDevIns->pReg->pfnSuspend(pDevIns);
|
---|
1948 | if (pDevIns->Internal.s.pfnAsyncNotify)
|
---|
1949 | LogFlow(("PDMR3Suspend: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1950 | }
|
---|
1951 | else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
|
---|
1952 | {
|
---|
1953 | LogFlow(("PDMR3Suspend: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
1954 | pDevIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
1955 | }
|
---|
1956 | if (pDevIns->Internal.s.pfnAsyncNotify)
|
---|
1957 | {
|
---|
1958 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
1959 | pdmR3NotifyAsyncAdd(pAsync, pDevIns->Internal.s.pDevR3->pReg->szName, pDevIns->iInstance);
|
---|
1960 | }
|
---|
1961 |
|
---|
1962 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
1963 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
1964 | if (cNsElapsed >= PDMSUSPEND_WARN_AT_NS)
|
---|
1965 | LogRel(("PDMR3Suspend: Device '%s'/%d took %'llu ns to suspend\n",
|
---|
1966 | pDevIns->pReg->szName, pDevIns->iInstance, cNsElapsed));
|
---|
1967 | }
|
---|
1968 | }
|
---|
1969 | }
|
---|
1970 |
|
---|
1971 |
|
---|
1972 | /**
|
---|
1973 | * This function will notify all the devices and their attached drivers about
|
---|
1974 | * the VM now being suspended.
|
---|
1975 | *
|
---|
1976 | * @param pVM The cross context VM structure.
|
---|
1977 | * @thread EMT(0)
|
---|
1978 | */
|
---|
1979 | VMMR3_INT_DECL(void) PDMR3Suspend(PVM pVM)
|
---|
1980 | {
|
---|
1981 | LogFlow(("PDMR3Suspend:\n"));
|
---|
1982 | VM_ASSERT_EMT0(pVM);
|
---|
1983 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
1984 |
|
---|
1985 | /*
|
---|
1986 | * The outer loop repeats until there are no more async requests.
|
---|
1987 | *
|
---|
1988 | * Note! We depend on the suspended indicators to be in the desired state
|
---|
1989 | * and we do not reset them before starting because this allows
|
---|
1990 | * PDMR3PowerOn and PDMR3Resume to use PDMR3Suspend for cleaning up
|
---|
1991 | * on failure.
|
---|
1992 | */
|
---|
1993 | PDMNOTIFYASYNCSTATS Async;
|
---|
1994 | pdmR3NotifyAsyncInit(&Async, "PDMR3Suspend");
|
---|
1995 | for (;;)
|
---|
1996 | {
|
---|
1997 | pdmR3NotifyAsyncBeginLoop(&Async);
|
---|
1998 |
|
---|
1999 | /*
|
---|
2000 | * Iterate thru the device instances and USB device instances,
|
---|
2001 | * processing the drivers associated with those.
|
---|
2002 | *
|
---|
2003 | * The attached drivers are normally processed first. Some devices
|
---|
2004 | * (like DevAHCI) though needs to be notified before the drivers so
|
---|
2005 | * that it doesn't kick off any new requests after the drivers stopped
|
---|
2006 | * taking any. (DrvVD changes to read-only in this particular case.)
|
---|
2007 | */
|
---|
2008 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2009 | {
|
---|
2010 | unsigned const cAsyncStart = Async.cAsync;
|
---|
2011 |
|
---|
2012 | if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION)
|
---|
2013 | pdmR3SuspendDev(pDevIns, &Async);
|
---|
2014 |
|
---|
2015 | if (Async.cAsync == cAsyncStart)
|
---|
2016 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2017 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2018 | if (!pdmR3SuspendDrv(pDrvIns, &Async, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
|
---|
2019 | break;
|
---|
2020 |
|
---|
2021 | if ( Async.cAsync == cAsyncStart
|
---|
2022 | && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION))
|
---|
2023 | pdmR3SuspendDev(pDevIns, &Async);
|
---|
2024 | }
|
---|
2025 |
|
---|
2026 | #ifdef VBOX_WITH_USB
|
---|
2027 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2028 | {
|
---|
2029 | unsigned const cAsyncStart = Async.cAsync;
|
---|
2030 |
|
---|
2031 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2032 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2033 | if (!pdmR3SuspendDrv(pDrvIns, &Async, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
|
---|
2034 | break;
|
---|
2035 |
|
---|
2036 | if (Async.cAsync == cAsyncStart)
|
---|
2037 | pdmR3SuspendUsb(pUsbIns, &Async);
|
---|
2038 | }
|
---|
2039 | #endif
|
---|
2040 | if (!Async.cAsync)
|
---|
2041 | break;
|
---|
2042 | pdmR3NotifyAsyncLog(&Async);
|
---|
2043 | pdmR3NotifyAsyncWaitAndProcessRequests(&Async, pVM);
|
---|
2044 | }
|
---|
2045 |
|
---|
2046 | /*
|
---|
2047 | * Suspend all threads.
|
---|
2048 | */
|
---|
2049 | pdmR3ThreadSuspendAll(pVM);
|
---|
2050 |
|
---|
2051 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
2052 | LogRel(("PDMR3Suspend: %'llu ns run time\n", cNsElapsed));
|
---|
2053 | }
|
---|
2054 |
|
---|
2055 |
|
---|
2056 | /**
|
---|
2057 | * Worker for PDMR3Resume that deals with one driver.
|
---|
2058 | *
|
---|
2059 | * @param pDrvIns The driver instance.
|
---|
2060 | * @param pszDevName The parent device name.
|
---|
2061 | * @param iDevInstance The parent device instance number.
|
---|
2062 | * @param iLun The parent LUN number.
|
---|
2063 | */
|
---|
2064 | DECLINLINE(int) pdmR3ResumeDrv(PPDMDRVINS pDrvIns, const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
|
---|
2065 | {
|
---|
2066 | Assert(pDrvIns->Internal.s.fVMSuspended);
|
---|
2067 | if (pDrvIns->pReg->pfnResume)
|
---|
2068 | {
|
---|
2069 | LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
2070 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
2071 | int rc = VINF_SUCCESS; pDrvIns->pReg->pfnResume(pDrvIns);
|
---|
2072 | if (RT_FAILURE(rc))
|
---|
2073 | {
|
---|
2074 | LogRel(("PDMR3Resume: Driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
|
---|
2075 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, rc));
|
---|
2076 | return rc;
|
---|
2077 | }
|
---|
2078 | }
|
---|
2079 | pDrvIns->Internal.s.fVMSuspended = false;
|
---|
2080 | return VINF_SUCCESS;
|
---|
2081 | }
|
---|
2082 |
|
---|
2083 |
|
---|
2084 | /**
|
---|
2085 | * Worker for PDMR3Resume that deals with one USB device instance.
|
---|
2086 | *
|
---|
2087 | * @returns VBox status code.
|
---|
2088 | * @param pUsbIns The USB device instance.
|
---|
2089 | */
|
---|
2090 | DECLINLINE(int) pdmR3ResumeUsb(PPDMUSBINS pUsbIns)
|
---|
2091 | {
|
---|
2092 | Assert(pUsbIns->Internal.s.fVMSuspended);
|
---|
2093 | if (pUsbIns->pReg->pfnVMResume)
|
---|
2094 | {
|
---|
2095 | LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
2096 | int rc = VINF_SUCCESS; pUsbIns->pReg->pfnVMResume(pUsbIns);
|
---|
2097 | if (RT_FAILURE(rc))
|
---|
2098 | {
|
---|
2099 | LogRel(("PDMR3Resume: Device '%s'/%d -> %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
|
---|
2100 | return rc;
|
---|
2101 | }
|
---|
2102 | }
|
---|
2103 | pUsbIns->Internal.s.fVMSuspended = false;
|
---|
2104 | return VINF_SUCCESS;
|
---|
2105 | }
|
---|
2106 |
|
---|
2107 |
|
---|
2108 | /**
|
---|
2109 | * Worker for PDMR3Resume that deals with one device instance.
|
---|
2110 | *
|
---|
2111 | * @returns VBox status code.
|
---|
2112 | * @param pDevIns The device instance.
|
---|
2113 | */
|
---|
2114 | DECLINLINE(int) pdmR3ResumeDev(PPDMDEVINS pDevIns)
|
---|
2115 | {
|
---|
2116 | Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
|
---|
2117 | if (pDevIns->pReg->pfnResume)
|
---|
2118 | {
|
---|
2119 | LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
2120 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
2121 | int rc = VINF_SUCCESS; pDevIns->pReg->pfnResume(pDevIns);
|
---|
2122 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
2123 | if (RT_FAILURE(rc))
|
---|
2124 | {
|
---|
2125 | LogRel(("PDMR3Resume: Device '%s'/%d -> %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
|
---|
2126 | return rc;
|
---|
2127 | }
|
---|
2128 | }
|
---|
2129 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
2130 | return VINF_SUCCESS;
|
---|
2131 | }
|
---|
2132 |
|
---|
2133 |
|
---|
2134 | /**
|
---|
2135 | * This function will notify all the devices and their
|
---|
2136 | * attached drivers about the VM now being resumed.
|
---|
2137 | *
|
---|
2138 | * @param pVM The cross context VM structure.
|
---|
2139 | */
|
---|
2140 | VMMR3_INT_DECL(void) PDMR3Resume(PVM pVM)
|
---|
2141 | {
|
---|
2142 | LogFlow(("PDMR3Resume:\n"));
|
---|
2143 |
|
---|
2144 | /*
|
---|
2145 | * Iterate thru the device instances and USB device instances,
|
---|
2146 | * processing the drivers associated with those.
|
---|
2147 | */
|
---|
2148 | int rc = VINF_SUCCESS;
|
---|
2149 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2150 | {
|
---|
2151 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
|
---|
2152 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2153 | rc = pdmR3ResumeDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun);
|
---|
2154 | if (RT_SUCCESS(rc))
|
---|
2155 | rc = pdmR3ResumeDev(pDevIns);
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 | #ifdef VBOX_WITH_USB
|
---|
2159 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2160 | {
|
---|
2161 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
|
---|
2162 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2163 | rc = pdmR3ResumeDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun);
|
---|
2164 | if (RT_SUCCESS(rc))
|
---|
2165 | rc = pdmR3ResumeUsb(pUsbIns);
|
---|
2166 | }
|
---|
2167 | #endif
|
---|
2168 |
|
---|
2169 | /*
|
---|
2170 | * Resume all threads.
|
---|
2171 | */
|
---|
2172 | if (RT_SUCCESS(rc))
|
---|
2173 | pdmR3ThreadResumeAll(pVM);
|
---|
2174 |
|
---|
2175 | /*
|
---|
2176 | * Resume the block cache.
|
---|
2177 | */
|
---|
2178 | if (RT_SUCCESS(rc))
|
---|
2179 | pdmR3BlkCacheResume(pVM);
|
---|
2180 |
|
---|
2181 | /*
|
---|
2182 | * On failure, clean up via PDMR3Suspend.
|
---|
2183 | */
|
---|
2184 | if (RT_FAILURE(rc))
|
---|
2185 | PDMR3Suspend(pVM);
|
---|
2186 |
|
---|
2187 | LogFlow(("PDMR3Resume: returns %Rrc\n", rc));
|
---|
2188 | return /*rc*/;
|
---|
2189 | }
|
---|
2190 |
|
---|
2191 |
|
---|
2192 | /**
|
---|
2193 | * Worker for PDMR3PowerOff that deals with one driver.
|
---|
2194 | *
|
---|
2195 | * @param pDrvIns The driver instance.
|
---|
2196 | * @param pAsync The structure for recording asynchronous
|
---|
2197 | * notification tasks.
|
---|
2198 | * @param pszDevName The parent device name.
|
---|
2199 | * @param iDevInstance The parent device instance number.
|
---|
2200 | * @param iLun The parent LUN number.
|
---|
2201 | */
|
---|
2202 | DECLINLINE(bool) pdmR3PowerOffDrv(PPDMDRVINS pDrvIns, PPDMNOTIFYASYNCSTATS pAsync,
|
---|
2203 | const char *pszDevName, uint32_t iDevInstance, uint32_t iLun)
|
---|
2204 | {
|
---|
2205 | if (!pDrvIns->Internal.s.fVMSuspended)
|
---|
2206 | {
|
---|
2207 | pDrvIns->Internal.s.fVMSuspended = true;
|
---|
2208 | if (pDrvIns->pReg->pfnPowerOff)
|
---|
2209 | {
|
---|
2210 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
2211 |
|
---|
2212 | if (!pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
2213 | {
|
---|
2214 | LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
2215 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
2216 | pDrvIns->pReg->pfnPowerOff(pDrvIns);
|
---|
2217 | if (pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
2218 | LogFlow(("PDMR3PowerOff: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
2219 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
2220 | }
|
---|
2221 | else if (pDrvIns->Internal.s.pfnAsyncNotify(pDrvIns))
|
---|
2222 | {
|
---|
2223 | LogFlow(("PDMR3PowerOff: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
2224 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance));
|
---|
2225 | pDrvIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
2226 | }
|
---|
2227 |
|
---|
2228 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
2229 | if (cNsElapsed >= PDMPOWEROFF_WARN_AT_NS)
|
---|
2230 | LogRel(("PDMR3PowerOff: Driver '%s'/%d on LUN#%d of device '%s'/%d took %'llu ns to power off\n",
|
---|
2231 | pDrvIns->pReg->szName, pDrvIns->iInstance, iLun, pszDevName, iDevInstance, cNsElapsed));
|
---|
2232 |
|
---|
2233 | if (pDrvIns->Internal.s.pfnAsyncNotify)
|
---|
2234 | {
|
---|
2235 | pDrvIns->Internal.s.fVMSuspended = false;
|
---|
2236 | pdmR3NotifyAsyncAddDrv(pAsync, pDrvIns->Internal.s.pDrv->pReg->szName, pDrvIns->iInstance,
|
---|
2237 | pszDevName, iDevInstance, iLun);
|
---|
2238 | return false;
|
---|
2239 | }
|
---|
2240 | }
|
---|
2241 | }
|
---|
2242 | return true;
|
---|
2243 | }
|
---|
2244 |
|
---|
2245 |
|
---|
2246 | /**
|
---|
2247 | * Worker for PDMR3PowerOff that deals with one USB device instance.
|
---|
2248 | *
|
---|
2249 | * @param pUsbIns The USB device instance.
|
---|
2250 | * @param pAsync The structure for recording asynchronous
|
---|
2251 | * notification tasks.
|
---|
2252 | */
|
---|
2253 | DECLINLINE(void) pdmR3PowerOffUsb(PPDMUSBINS pUsbIns, PPDMNOTIFYASYNCSTATS pAsync)
|
---|
2254 | {
|
---|
2255 | if (!pUsbIns->Internal.s.fVMSuspended)
|
---|
2256 | {
|
---|
2257 | pUsbIns->Internal.s.fVMSuspended = true;
|
---|
2258 | if (pUsbIns->pReg->pfnVMPowerOff)
|
---|
2259 | {
|
---|
2260 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
2261 |
|
---|
2262 | if (!pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
2263 | {
|
---|
2264 | LogFlow(("PDMR3PowerOff: Notifying - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
2265 | pUsbIns->pReg->pfnVMPowerOff(pUsbIns);
|
---|
2266 | if (pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
2267 | LogFlow(("PDMR3PowerOff: Async notification started - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
2268 | }
|
---|
2269 | else if (pUsbIns->Internal.s.pfnAsyncNotify(pUsbIns))
|
---|
2270 | {
|
---|
2271 | LogFlow(("PDMR3PowerOff: Async notification completed - USB device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
|
---|
2272 | pUsbIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
2273 | }
|
---|
2274 | if (pUsbIns->Internal.s.pfnAsyncNotify)
|
---|
2275 | {
|
---|
2276 | pUsbIns->Internal.s.fVMSuspended = false;
|
---|
2277 | pdmR3NotifyAsyncAdd(pAsync, pUsbIns->Internal.s.pUsbDev->pReg->szName, pUsbIns->iInstance);
|
---|
2278 | }
|
---|
2279 |
|
---|
2280 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
2281 | if (cNsElapsed >= PDMPOWEROFF_WARN_AT_NS)
|
---|
2282 | LogRel(("PDMR3PowerOff: USB device '%s'/%d took %'llu ns to power off\n",
|
---|
2283 | pUsbIns->pReg->szName, pUsbIns->iInstance, cNsElapsed));
|
---|
2284 |
|
---|
2285 | }
|
---|
2286 | }
|
---|
2287 | }
|
---|
2288 |
|
---|
2289 |
|
---|
2290 | /**
|
---|
2291 | * Worker for PDMR3PowerOff that deals with one device instance.
|
---|
2292 | *
|
---|
2293 | * @param pDevIns The device instance.
|
---|
2294 | * @param pAsync The structure for recording asynchronous
|
---|
2295 | * notification tasks.
|
---|
2296 | */
|
---|
2297 | DECLINLINE(void) pdmR3PowerOffDev(PPDMDEVINS pDevIns, PPDMNOTIFYASYNCSTATS pAsync)
|
---|
2298 | {
|
---|
2299 | if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED))
|
---|
2300 | {
|
---|
2301 | pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
2302 | if (pDevIns->pReg->pfnPowerOff)
|
---|
2303 | {
|
---|
2304 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
2305 | PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
2306 |
|
---|
2307 | if (!pDevIns->Internal.s.pfnAsyncNotify)
|
---|
2308 | {
|
---|
2309 | LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
2310 | pDevIns->pReg->pfnPowerOff(pDevIns);
|
---|
2311 | if (pDevIns->Internal.s.pfnAsyncNotify)
|
---|
2312 | LogFlow(("PDMR3PowerOff: Async notification started - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
2313 | }
|
---|
2314 | else if (pDevIns->Internal.s.pfnAsyncNotify(pDevIns))
|
---|
2315 | {
|
---|
2316 | LogFlow(("PDMR3PowerOff: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
2317 | pDevIns->Internal.s.pfnAsyncNotify = NULL;
|
---|
2318 | }
|
---|
2319 | if (pDevIns->Internal.s.pfnAsyncNotify)
|
---|
2320 | {
|
---|
2321 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
2322 | pdmR3NotifyAsyncAdd(pAsync, pDevIns->Internal.s.pDevR3->pReg->szName, pDevIns->iInstance);
|
---|
2323 | }
|
---|
2324 |
|
---|
2325 | PDMCritSectLeave(pDevIns->pCritSectRoR3);
|
---|
2326 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
2327 | if (cNsElapsed >= PDMPOWEROFF_WARN_AT_NS)
|
---|
2328 | LogFlow(("PDMR3PowerOff: Device '%s'/%d took %'llu ns to power off\n",
|
---|
2329 | pDevIns->pReg->szName, pDevIns->iInstance, cNsElapsed));
|
---|
2330 | }
|
---|
2331 | }
|
---|
2332 | }
|
---|
2333 |
|
---|
2334 |
|
---|
2335 | /**
|
---|
2336 | * This function will notify all the devices and their
|
---|
2337 | * attached drivers about the VM being powered off.
|
---|
2338 | *
|
---|
2339 | * @param pVM The cross context VM structure.
|
---|
2340 | */
|
---|
2341 | VMMR3DECL(void) PDMR3PowerOff(PVM pVM)
|
---|
2342 | {
|
---|
2343 | LogFlow(("PDMR3PowerOff:\n"));
|
---|
2344 | uint64_t cNsElapsed = RTTimeNanoTS();
|
---|
2345 |
|
---|
2346 | /*
|
---|
2347 | * Clear the suspended flags on all devices and drivers first because they
|
---|
2348 | * might have been set during a suspend but the power off callbacks should
|
---|
2349 | * be called in any case.
|
---|
2350 | */
|
---|
2351 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2352 | {
|
---|
2353 | pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
|
---|
2354 |
|
---|
2355 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2356 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2357 | pDrvIns->Internal.s.fVMSuspended = false;
|
---|
2358 | }
|
---|
2359 |
|
---|
2360 | #ifdef VBOX_WITH_USB
|
---|
2361 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2362 | {
|
---|
2363 | pUsbIns->Internal.s.fVMSuspended = false;
|
---|
2364 |
|
---|
2365 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2366 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2367 | pDrvIns->Internal.s.fVMSuspended = false;
|
---|
2368 | }
|
---|
2369 | #endif
|
---|
2370 |
|
---|
2371 | /*
|
---|
2372 | * The outer loop repeats until there are no more async requests.
|
---|
2373 | */
|
---|
2374 | PDMNOTIFYASYNCSTATS Async;
|
---|
2375 | pdmR3NotifyAsyncInit(&Async, "PDMR3PowerOff");
|
---|
2376 | for (;;)
|
---|
2377 | {
|
---|
2378 | pdmR3NotifyAsyncBeginLoop(&Async);
|
---|
2379 |
|
---|
2380 | /*
|
---|
2381 | * Iterate thru the device instances and USB device instances,
|
---|
2382 | * processing the drivers associated with those.
|
---|
2383 | *
|
---|
2384 | * The attached drivers are normally processed first. Some devices
|
---|
2385 | * (like DevAHCI) though needs to be notified before the drivers so
|
---|
2386 | * that it doesn't kick off any new requests after the drivers stopped
|
---|
2387 | * taking any. (DrvVD changes to read-only in this particular case.)
|
---|
2388 | */
|
---|
2389 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2390 | {
|
---|
2391 | unsigned const cAsyncStart = Async.cAsync;
|
---|
2392 |
|
---|
2393 | if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION)
|
---|
2394 | pdmR3PowerOffDev(pDevIns, &Async);
|
---|
2395 |
|
---|
2396 | if (Async.cAsync == cAsyncStart)
|
---|
2397 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2398 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2399 | if (!pdmR3PowerOffDrv(pDrvIns, &Async, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun))
|
---|
2400 | break;
|
---|
2401 |
|
---|
2402 | if ( Async.cAsync == cAsyncStart
|
---|
2403 | && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION))
|
---|
2404 | pdmR3PowerOffDev(pDevIns, &Async);
|
---|
2405 | }
|
---|
2406 |
|
---|
2407 | #ifdef VBOX_WITH_USB
|
---|
2408 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2409 | {
|
---|
2410 | unsigned const cAsyncStart = Async.cAsync;
|
---|
2411 |
|
---|
2412 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2413 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2414 | if (!pdmR3PowerOffDrv(pDrvIns, &Async, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun))
|
---|
2415 | break;
|
---|
2416 |
|
---|
2417 | if (Async.cAsync == cAsyncStart)
|
---|
2418 | pdmR3PowerOffUsb(pUsbIns, &Async);
|
---|
2419 | }
|
---|
2420 | #endif
|
---|
2421 | if (!Async.cAsync)
|
---|
2422 | break;
|
---|
2423 | pdmR3NotifyAsyncLog(&Async);
|
---|
2424 | pdmR3NotifyAsyncWaitAndProcessRequests(&Async, pVM);
|
---|
2425 | }
|
---|
2426 |
|
---|
2427 | /*
|
---|
2428 | * Suspend all threads.
|
---|
2429 | */
|
---|
2430 | pdmR3ThreadSuspendAll(pVM);
|
---|
2431 |
|
---|
2432 | cNsElapsed = RTTimeNanoTS() - cNsElapsed;
|
---|
2433 | LogRel(("PDMR3PowerOff: %'llu ns run time\n", cNsElapsed));
|
---|
2434 | }
|
---|
2435 |
|
---|
2436 |
|
---|
2437 | /**
|
---|
2438 | * Queries the base interface of a device instance.
|
---|
2439 | *
|
---|
2440 | * The caller can use this to query other interfaces the device implements
|
---|
2441 | * and use them to talk to the device.
|
---|
2442 | *
|
---|
2443 | * @returns VBox status code.
|
---|
2444 | * @param pUVM The user mode VM handle.
|
---|
2445 | * @param pszDevice Device name.
|
---|
2446 | * @param iInstance Device instance.
|
---|
2447 | * @param ppBase Where to store the pointer to the base device interface on success.
|
---|
2448 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
2449 | * device chain is known to be updated.
|
---|
2450 | */
|
---|
2451 | VMMR3DECL(int) PDMR3QueryDevice(PUVM pUVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
|
---|
2452 | {
|
---|
2453 | LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
|
---|
2454 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
2455 | VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
|
---|
2456 |
|
---|
2457 | /*
|
---|
2458 | * Iterate registered devices looking for the device.
|
---|
2459 | */
|
---|
2460 | size_t cchDevice = strlen(pszDevice);
|
---|
2461 | for (PPDMDEV pDev = pUVM->pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext)
|
---|
2462 | {
|
---|
2463 | if ( pDev->cchName == cchDevice
|
---|
2464 | && !memcmp(pDev->pReg->szName, pszDevice, cchDevice))
|
---|
2465 | {
|
---|
2466 | /*
|
---|
2467 | * Iterate device instances.
|
---|
2468 | */
|
---|
2469 | for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextR3)
|
---|
2470 | {
|
---|
2471 | if (pDevIns->iInstance == iInstance)
|
---|
2472 | {
|
---|
2473 | if (pDevIns->IBase.pfnQueryInterface)
|
---|
2474 | {
|
---|
2475 | *ppBase = &pDevIns->IBase;
|
---|
2476 | LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
|
---|
2477 | return VINF_SUCCESS;
|
---|
2478 | }
|
---|
2479 |
|
---|
2480 | LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
|
---|
2481 | return VERR_PDM_DEVICE_INSTANCE_NO_IBASE;
|
---|
2482 | }
|
---|
2483 | }
|
---|
2484 |
|
---|
2485 | LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
|
---|
2486 | return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND;
|
---|
2487 | }
|
---|
2488 | }
|
---|
2489 |
|
---|
2490 | LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
|
---|
2491 | return VERR_PDM_DEVICE_NOT_FOUND;
|
---|
2492 | }
|
---|
2493 |
|
---|
2494 |
|
---|
2495 | /**
|
---|
2496 | * Queries the base interface of a device LUN.
|
---|
2497 | *
|
---|
2498 | * This differs from PDMR3QueryLun by that it returns the interface on the
|
---|
2499 | * device and not the top level driver.
|
---|
2500 | *
|
---|
2501 | * @returns VBox status code.
|
---|
2502 | * @param pUVM The user mode VM handle.
|
---|
2503 | * @param pszDevice Device name.
|
---|
2504 | * @param iInstance Device instance.
|
---|
2505 | * @param iLun The Logical Unit to obtain the interface of.
|
---|
2506 | * @param ppBase Where to store the base interface pointer.
|
---|
2507 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
2508 | * device chain is known to be updated.
|
---|
2509 | */
|
---|
2510 | VMMR3DECL(int) PDMR3QueryDeviceLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
|
---|
2511 | {
|
---|
2512 | LogFlow(("PDMR3QueryDeviceLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
|
---|
2513 | pszDevice, pszDevice, iInstance, iLun, ppBase));
|
---|
2514 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
2515 | VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
|
---|
2516 |
|
---|
2517 | /*
|
---|
2518 | * Find the LUN.
|
---|
2519 | */
|
---|
2520 | PPDMLUN pLun;
|
---|
2521 | int rc = pdmR3DevFindLun(pUVM->pVM, pszDevice, iInstance, iLun, &pLun);
|
---|
2522 | if (RT_SUCCESS(rc))
|
---|
2523 | {
|
---|
2524 | *ppBase = pLun->pBase;
|
---|
2525 | LogFlow(("PDMR3QueryDeviceLun: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
|
---|
2526 | return VINF_SUCCESS;
|
---|
2527 | }
|
---|
2528 | LogFlow(("PDMR3QueryDeviceLun: returns %Rrc\n", rc));
|
---|
2529 | return rc;
|
---|
2530 | }
|
---|
2531 |
|
---|
2532 |
|
---|
2533 | /**
|
---|
2534 | * Query the interface of the top level driver on a LUN.
|
---|
2535 | *
|
---|
2536 | * @returns VBox status code.
|
---|
2537 | * @param pUVM The user mode VM handle.
|
---|
2538 | * @param pszDevice Device name.
|
---|
2539 | * @param iInstance Device instance.
|
---|
2540 | * @param iLun The Logical Unit to obtain the interface of.
|
---|
2541 | * @param ppBase Where to store the base interface pointer.
|
---|
2542 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
2543 | * device chain is known to be updated.
|
---|
2544 | */
|
---|
2545 | VMMR3DECL(int) PDMR3QueryLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
|
---|
2546 | {
|
---|
2547 | LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
|
---|
2548 | pszDevice, pszDevice, iInstance, iLun, ppBase));
|
---|
2549 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
2550 | PVM pVM = pUVM->pVM;
|
---|
2551 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
2552 |
|
---|
2553 | /*
|
---|
2554 | * Find the LUN.
|
---|
2555 | */
|
---|
2556 | PPDMLUN pLun;
|
---|
2557 | int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
|
---|
2558 | if (RT_SUCCESS(rc))
|
---|
2559 | {
|
---|
2560 | if (pLun->pTop)
|
---|
2561 | {
|
---|
2562 | *ppBase = &pLun->pTop->IBase;
|
---|
2563 | LogFlow(("PDMR3QueryLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
|
---|
2564 | return VINF_SUCCESS;
|
---|
2565 | }
|
---|
2566 | rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
|
---|
2567 | }
|
---|
2568 | LogFlow(("PDMR3QueryLun: returns %Rrc\n", rc));
|
---|
2569 | return rc;
|
---|
2570 | }
|
---|
2571 |
|
---|
2572 |
|
---|
2573 | /**
|
---|
2574 | * Query the interface of a named driver on a LUN.
|
---|
2575 | *
|
---|
2576 | * If the driver appears more than once in the driver chain, the first instance
|
---|
2577 | * is returned.
|
---|
2578 | *
|
---|
2579 | * @returns VBox status code.
|
---|
2580 | * @param pUVM The user mode VM handle.
|
---|
2581 | * @param pszDevice Device name.
|
---|
2582 | * @param iInstance Device instance.
|
---|
2583 | * @param iLun The Logical Unit to obtain the interface of.
|
---|
2584 | * @param pszDriver The driver name.
|
---|
2585 | * @param ppBase Where to store the base interface pointer.
|
---|
2586 | *
|
---|
2587 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
2588 | * device chain is known to be updated.
|
---|
2589 | */
|
---|
2590 | VMMR3DECL(int) PDMR3QueryDriverOnLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, const char *pszDriver, PPPDMIBASE ppBase)
|
---|
2591 | {
|
---|
2592 | LogFlow(("PDMR3QueryDriverOnLun: pszDevice=%p:{%s} iInstance=%u iLun=%u pszDriver=%p:{%s} ppBase=%p\n",
|
---|
2593 | pszDevice, pszDevice, iInstance, iLun, pszDriver, pszDriver, ppBase));
|
---|
2594 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
2595 | VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
|
---|
2596 |
|
---|
2597 | /*
|
---|
2598 | * Find the LUN.
|
---|
2599 | */
|
---|
2600 | PPDMLUN pLun;
|
---|
2601 | int rc = pdmR3DevFindLun(pUVM->pVM, pszDevice, iInstance, iLun, &pLun);
|
---|
2602 | if (RT_SUCCESS(rc))
|
---|
2603 | {
|
---|
2604 | if (pLun->pTop)
|
---|
2605 | {
|
---|
2606 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2607 | if (!strcmp(pDrvIns->pReg->szName, pszDriver))
|
---|
2608 | {
|
---|
2609 | *ppBase = &pDrvIns->IBase;
|
---|
2610 | LogFlow(("PDMR3QueryDriverOnLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
|
---|
2611 | return VINF_SUCCESS;
|
---|
2612 |
|
---|
2613 | }
|
---|
2614 | rc = VERR_PDM_DRIVER_NOT_FOUND;
|
---|
2615 | }
|
---|
2616 | else
|
---|
2617 | rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
|
---|
2618 | }
|
---|
2619 | LogFlow(("PDMR3QueryDriverOnLun: returns %Rrc\n", rc));
|
---|
2620 | return rc;
|
---|
2621 | }
|
---|
2622 |
|
---|
2623 | /**
|
---|
2624 | * Executes pending DMA transfers.
|
---|
2625 | * Forced Action handler.
|
---|
2626 | *
|
---|
2627 | * @param pVM The cross context VM structure.
|
---|
2628 | */
|
---|
2629 | VMMR3DECL(void) PDMR3DmaRun(PVM pVM)
|
---|
2630 | {
|
---|
2631 | /* Note! Not really SMP safe; restrict it to VCPU 0. */
|
---|
2632 | if (VMMGetCpuId(pVM) != 0)
|
---|
2633 | return;
|
---|
2634 |
|
---|
2635 | if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_PDM_DMA))
|
---|
2636 | {
|
---|
2637 | if (pVM->pdm.s.pDmac)
|
---|
2638 | {
|
---|
2639 | bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns);
|
---|
2640 | if (fMore)
|
---|
2641 | VM_FF_SET(pVM, VM_FF_PDM_DMA);
|
---|
2642 | }
|
---|
2643 | }
|
---|
2644 | }
|
---|
2645 |
|
---|
2646 |
|
---|
2647 | /**
|
---|
2648 | * Service a VMMCALLRING3_PDM_LOCK call.
|
---|
2649 | *
|
---|
2650 | * @returns VBox status code.
|
---|
2651 | * @param pVM The cross context VM structure.
|
---|
2652 | */
|
---|
2653 | VMMR3_INT_DECL(int) PDMR3LockCall(PVM pVM)
|
---|
2654 | {
|
---|
2655 | return PDMR3CritSectEnterEx(&pVM->pdm.s.CritSect, true /* fHostCall */);
|
---|
2656 | }
|
---|
2657 |
|
---|
2658 |
|
---|
2659 | /**
|
---|
2660 | * Allocates memory from the VMM device heap.
|
---|
2661 | *
|
---|
2662 | * @returns VBox status code.
|
---|
2663 | * @param pVM The cross context VM structure.
|
---|
2664 | * @param cbSize Allocation size.
|
---|
2665 | * @param pfnNotify Mapping/unmapping notification callback.
|
---|
2666 | * @param ppv Ring-3 pointer. (out)
|
---|
2667 | */
|
---|
2668 | VMMR3_INT_DECL(int) PDMR3VmmDevHeapAlloc(PVM pVM, size_t cbSize, PFNPDMVMMDEVHEAPNOTIFY pfnNotify, RTR3PTR *ppv)
|
---|
2669 | {
|
---|
2670 | #ifdef DEBUG_bird
|
---|
2671 | if (!cbSize || cbSize > pVM->pdm.s.cbVMMDevHeapLeft)
|
---|
2672 | return VERR_NO_MEMORY;
|
---|
2673 | #else
|
---|
2674 | AssertReturn(cbSize && cbSize <= pVM->pdm.s.cbVMMDevHeapLeft, VERR_NO_MEMORY);
|
---|
2675 | #endif
|
---|
2676 |
|
---|
2677 | Log(("PDMR3VMMDevHeapAlloc: %#zx\n", cbSize));
|
---|
2678 |
|
---|
2679 | /** @todo Not a real heap as there's currently only one user. */
|
---|
2680 | *ppv = pVM->pdm.s.pvVMMDevHeap;
|
---|
2681 | pVM->pdm.s.cbVMMDevHeapLeft = 0;
|
---|
2682 | pVM->pdm.s.pfnVMMDevHeapNotify = pfnNotify;
|
---|
2683 | return VINF_SUCCESS;
|
---|
2684 | }
|
---|
2685 |
|
---|
2686 |
|
---|
2687 | /**
|
---|
2688 | * Frees memory from the VMM device heap
|
---|
2689 | *
|
---|
2690 | * @returns VBox status code.
|
---|
2691 | * @param pVM The cross context VM structure.
|
---|
2692 | * @param pv Ring-3 pointer.
|
---|
2693 | */
|
---|
2694 | VMMR3_INT_DECL(int) PDMR3VmmDevHeapFree(PVM pVM, RTR3PTR pv)
|
---|
2695 | {
|
---|
2696 | Log(("PDMR3VmmDevHeapFree: %RHv\n", pv)); RT_NOREF_PV(pv);
|
---|
2697 |
|
---|
2698 | /** @todo not a real heap as there's currently only one user. */
|
---|
2699 | pVM->pdm.s.cbVMMDevHeapLeft = pVM->pdm.s.cbVMMDevHeap;
|
---|
2700 | pVM->pdm.s.pfnVMMDevHeapNotify = NULL;
|
---|
2701 | return VINF_SUCCESS;
|
---|
2702 | }
|
---|
2703 |
|
---|
2704 |
|
---|
2705 | /**
|
---|
2706 | * Worker for DBGFR3TraceConfig that checks if the given tracing group name
|
---|
2707 | * matches a device or driver name and applies the tracing config change.
|
---|
2708 | *
|
---|
2709 | * @returns VINF_SUCCESS or VERR_NOT_FOUND.
|
---|
2710 | * @param pVM The cross context VM structure.
|
---|
2711 | * @param pszName The tracing config group name. This is NULL if
|
---|
2712 | * the operation applies to every device and
|
---|
2713 | * driver.
|
---|
2714 | * @param cchName The length to match.
|
---|
2715 | * @param fEnable Whether to enable or disable the corresponding
|
---|
2716 | * trace points.
|
---|
2717 | * @param fApply Whether to actually apply the changes or just do
|
---|
2718 | * existence checks.
|
---|
2719 | */
|
---|
2720 | VMMR3_INT_DECL(int) PDMR3TracingConfig(PVM pVM, const char *pszName, size_t cchName, bool fEnable, bool fApply)
|
---|
2721 | {
|
---|
2722 | /** @todo This code is potentially racing driver attaching and detaching. */
|
---|
2723 |
|
---|
2724 | /*
|
---|
2725 | * Applies to all.
|
---|
2726 | */
|
---|
2727 | if (pszName == NULL)
|
---|
2728 | {
|
---|
2729 | AssertReturn(fApply, VINF_SUCCESS);
|
---|
2730 |
|
---|
2731 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2732 | {
|
---|
2733 | pDevIns->fTracing = fEnable;
|
---|
2734 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2735 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2736 | pDrvIns->fTracing = fEnable;
|
---|
2737 | }
|
---|
2738 |
|
---|
2739 | #ifdef VBOX_WITH_USB
|
---|
2740 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2741 | {
|
---|
2742 | pUsbIns->fTracing = fEnable;
|
---|
2743 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2744 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2745 | pDrvIns->fTracing = fEnable;
|
---|
2746 |
|
---|
2747 | }
|
---|
2748 | #endif
|
---|
2749 | return VINF_SUCCESS;
|
---|
2750 | }
|
---|
2751 |
|
---|
2752 | /*
|
---|
2753 | * Specific devices, USB devices or drivers.
|
---|
2754 | * Decode prefix to figure which of these it applies to.
|
---|
2755 | */
|
---|
2756 | if (cchName <= 3)
|
---|
2757 | return VERR_NOT_FOUND;
|
---|
2758 |
|
---|
2759 | uint32_t cMatches = 0;
|
---|
2760 | if (!strncmp("dev", pszName, 3))
|
---|
2761 | {
|
---|
2762 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2763 | {
|
---|
2764 | const char *pszDevName = pDevIns->Internal.s.pDevR3->pReg->szName;
|
---|
2765 | size_t cchDevName = strlen(pszDevName);
|
---|
2766 | if ( ( cchDevName == cchName
|
---|
2767 | && RTStrNICmp(pszName, pszDevName, cchDevName))
|
---|
2768 | || ( cchDevName == cchName - 3
|
---|
2769 | && RTStrNICmp(pszName + 3, pszDevName, cchDevName)) )
|
---|
2770 | {
|
---|
2771 | cMatches++;
|
---|
2772 | if (fApply)
|
---|
2773 | pDevIns->fTracing = fEnable;
|
---|
2774 | }
|
---|
2775 | }
|
---|
2776 | }
|
---|
2777 | else if (!strncmp("usb", pszName, 3))
|
---|
2778 | {
|
---|
2779 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2780 | {
|
---|
2781 | const char *pszUsbName = pUsbIns->Internal.s.pUsbDev->pReg->szName;
|
---|
2782 | size_t cchUsbName = strlen(pszUsbName);
|
---|
2783 | if ( ( cchUsbName == cchName
|
---|
2784 | && RTStrNICmp(pszName, pszUsbName, cchUsbName))
|
---|
2785 | || ( cchUsbName == cchName - 3
|
---|
2786 | && RTStrNICmp(pszName + 3, pszUsbName, cchUsbName)) )
|
---|
2787 | {
|
---|
2788 | cMatches++;
|
---|
2789 | if (fApply)
|
---|
2790 | pUsbIns->fTracing = fEnable;
|
---|
2791 | }
|
---|
2792 | }
|
---|
2793 | }
|
---|
2794 | else if (!strncmp("drv", pszName, 3))
|
---|
2795 | {
|
---|
2796 | AssertReturn(fApply, VINF_SUCCESS);
|
---|
2797 |
|
---|
2798 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2799 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2800 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2801 | {
|
---|
2802 | const char *pszDrvName = pDrvIns->Internal.s.pDrv->pReg->szName;
|
---|
2803 | size_t cchDrvName = strlen(pszDrvName);
|
---|
2804 | if ( ( cchDrvName == cchName
|
---|
2805 | && RTStrNICmp(pszName, pszDrvName, cchDrvName))
|
---|
2806 | || ( cchDrvName == cchName - 3
|
---|
2807 | && RTStrNICmp(pszName + 3, pszDrvName, cchDrvName)) )
|
---|
2808 | {
|
---|
2809 | cMatches++;
|
---|
2810 | if (fApply)
|
---|
2811 | pDrvIns->fTracing = fEnable;
|
---|
2812 | }
|
---|
2813 | }
|
---|
2814 |
|
---|
2815 | #ifdef VBOX_WITH_USB
|
---|
2816 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2817 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2818 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2819 | {
|
---|
2820 | const char *pszDrvName = pDrvIns->Internal.s.pDrv->pReg->szName;
|
---|
2821 | size_t cchDrvName = strlen(pszDrvName);
|
---|
2822 | if ( ( cchDrvName == cchName
|
---|
2823 | && RTStrNICmp(pszName, pszDrvName, cchDrvName))
|
---|
2824 | || ( cchDrvName == cchName - 3
|
---|
2825 | && RTStrNICmp(pszName + 3, pszDrvName, cchDrvName)) )
|
---|
2826 | {
|
---|
2827 | cMatches++;
|
---|
2828 | if (fApply)
|
---|
2829 | pDrvIns->fTracing = fEnable;
|
---|
2830 | }
|
---|
2831 | }
|
---|
2832 | #endif
|
---|
2833 | }
|
---|
2834 | else
|
---|
2835 | return VERR_NOT_FOUND;
|
---|
2836 |
|
---|
2837 | return cMatches > 0 ? VINF_SUCCESS : VERR_NOT_FOUND;
|
---|
2838 | }
|
---|
2839 |
|
---|
2840 |
|
---|
2841 | /**
|
---|
2842 | * Worker for DBGFR3TraceQueryConfig that checks whether all drivers, devices,
|
---|
2843 | * and USB device have the same tracing settings.
|
---|
2844 | *
|
---|
2845 | * @returns true / false.
|
---|
2846 | * @param pVM The cross context VM structure.
|
---|
2847 | * @param fEnabled The tracing setting to check for.
|
---|
2848 | */
|
---|
2849 | VMMR3_INT_DECL(bool) PDMR3TracingAreAll(PVM pVM, bool fEnabled)
|
---|
2850 | {
|
---|
2851 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2852 | {
|
---|
2853 | if (pDevIns->fTracing != (uint32_t)fEnabled)
|
---|
2854 | return false;
|
---|
2855 |
|
---|
2856 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2857 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2858 | if (pDrvIns->fTracing != (uint32_t)fEnabled)
|
---|
2859 | return false;
|
---|
2860 | }
|
---|
2861 |
|
---|
2862 | #ifdef VBOX_WITH_USB
|
---|
2863 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2864 | {
|
---|
2865 | if (pUsbIns->fTracing != (uint32_t)fEnabled)
|
---|
2866 | return false;
|
---|
2867 |
|
---|
2868 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2869 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2870 | if (pDrvIns->fTracing != (uint32_t)fEnabled)
|
---|
2871 | return false;
|
---|
2872 | }
|
---|
2873 | #endif
|
---|
2874 |
|
---|
2875 | return true;
|
---|
2876 | }
|
---|
2877 |
|
---|
2878 |
|
---|
2879 | /**
|
---|
2880 | * Worker for PDMR3TracingQueryConfig that adds a prefixed name to the output
|
---|
2881 | * string.
|
---|
2882 | *
|
---|
2883 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW
|
---|
2884 | * @param ppszDst The pointer to the output buffer pointer.
|
---|
2885 | * @param pcbDst The pointer to the output buffer size.
|
---|
2886 | * @param fSpace Whether to add a space before the name.
|
---|
2887 | * @param pszPrefix The name prefix.
|
---|
2888 | * @param pszName The name.
|
---|
2889 | */
|
---|
2890 | static int pdmR3TracingAdd(char **ppszDst, size_t *pcbDst, bool fSpace, const char *pszPrefix, const char *pszName)
|
---|
2891 | {
|
---|
2892 | size_t const cchPrefix = strlen(pszPrefix);
|
---|
2893 | if (!RTStrNICmp(pszPrefix, pszName, cchPrefix))
|
---|
2894 | pszName += cchPrefix;
|
---|
2895 | size_t const cchName = strlen(pszName);
|
---|
2896 |
|
---|
2897 | size_t const cchThis = cchName + cchPrefix + fSpace;
|
---|
2898 | if (cchThis >= *pcbDst)
|
---|
2899 | return VERR_BUFFER_OVERFLOW;
|
---|
2900 | if (fSpace)
|
---|
2901 | {
|
---|
2902 | **ppszDst = ' ';
|
---|
2903 | memcpy(*ppszDst + 1, pszPrefix, cchPrefix);
|
---|
2904 | memcpy(*ppszDst + 1 + cchPrefix, pszName, cchName + 1);
|
---|
2905 | }
|
---|
2906 | else
|
---|
2907 | {
|
---|
2908 | memcpy(*ppszDst, pszPrefix, cchPrefix);
|
---|
2909 | memcpy(*ppszDst + cchPrefix, pszName, cchName + 1);
|
---|
2910 | }
|
---|
2911 | *ppszDst += cchThis;
|
---|
2912 | *pcbDst -= cchThis;
|
---|
2913 | return VINF_SUCCESS;
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 |
|
---|
2917 | /**
|
---|
2918 | * Worker for DBGFR3TraceQueryConfig use when not everything is either enabled
|
---|
2919 | * or disabled.
|
---|
2920 | *
|
---|
2921 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW
|
---|
2922 | * @param pVM The cross context VM structure.
|
---|
2923 | * @param pszConfig Where to store the config spec.
|
---|
2924 | * @param cbConfig The size of the output buffer.
|
---|
2925 | */
|
---|
2926 | VMMR3_INT_DECL(int) PDMR3TracingQueryConfig(PVM pVM, char *pszConfig, size_t cbConfig)
|
---|
2927 | {
|
---|
2928 | int rc;
|
---|
2929 | char *pszDst = pszConfig;
|
---|
2930 | size_t cbDst = cbConfig;
|
---|
2931 |
|
---|
2932 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
2933 | {
|
---|
2934 | if (pDevIns->fTracing)
|
---|
2935 | {
|
---|
2936 | rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "dev", pDevIns->Internal.s.pDevR3->pReg->szName);
|
---|
2937 | if (RT_FAILURE(rc))
|
---|
2938 | return rc;
|
---|
2939 | }
|
---|
2940 |
|
---|
2941 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
2942 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2943 | if (pDrvIns->fTracing)
|
---|
2944 | {
|
---|
2945 | rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName);
|
---|
2946 | if (RT_FAILURE(rc))
|
---|
2947 | return rc;
|
---|
2948 | }
|
---|
2949 | }
|
---|
2950 |
|
---|
2951 | #ifdef VBOX_WITH_USB
|
---|
2952 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
2953 | {
|
---|
2954 | if (pUsbIns->fTracing)
|
---|
2955 | {
|
---|
2956 | rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "usb", pUsbIns->Internal.s.pUsbDev->pReg->szName);
|
---|
2957 | if (RT_FAILURE(rc))
|
---|
2958 | return rc;
|
---|
2959 | }
|
---|
2960 |
|
---|
2961 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
2962 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
2963 | if (pDrvIns->fTracing)
|
---|
2964 | {
|
---|
2965 | rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName);
|
---|
2966 | if (RT_FAILURE(rc))
|
---|
2967 | return rc;
|
---|
2968 | }
|
---|
2969 | }
|
---|
2970 | #endif
|
---|
2971 |
|
---|
2972 | return VINF_SUCCESS;
|
---|
2973 | }
|
---|
2974 |
|
---|
2975 |
|
---|
2976 | /**
|
---|
2977 | * Checks that a PDMDRVREG::szName, PDMDEVREG::szName or PDMUSBREG::szName
|
---|
2978 | * field contains only a limited set of ASCII characters.
|
---|
2979 | *
|
---|
2980 | * @returns true / false.
|
---|
2981 | * @param pszName The name to validate.
|
---|
2982 | */
|
---|
2983 | bool pdmR3IsValidName(const char *pszName)
|
---|
2984 | {
|
---|
2985 | char ch;
|
---|
2986 | while ( (ch = *pszName) != '\0'
|
---|
2987 | && ( RT_C_IS_ALNUM(ch)
|
---|
2988 | || ch == '-'
|
---|
2989 | || ch == ' ' /** @todo disallow this! */
|
---|
2990 | || ch == '_') )
|
---|
2991 | pszName++;
|
---|
2992 | return ch == '\0';
|
---|
2993 | }
|
---|
2994 |
|
---|
2995 |
|
---|
2996 | /**
|
---|
2997 | * Info handler for 'pdmtracingids'.
|
---|
2998 | *
|
---|
2999 | * @param pVM The cross context VM structure.
|
---|
3000 | * @param pHlp The output helpers.
|
---|
3001 | * @param pszArgs The optional user arguments.
|
---|
3002 | *
|
---|
3003 | * @remarks Can be called on most threads.
|
---|
3004 | */
|
---|
3005 | static DECLCALLBACK(void) pdmR3InfoTracingIds(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
|
---|
3006 | {
|
---|
3007 | /*
|
---|
3008 | * Parse the argument (optional).
|
---|
3009 | */
|
---|
3010 | if ( pszArgs
|
---|
3011 | && *pszArgs
|
---|
3012 | && strcmp(pszArgs, "all")
|
---|
3013 | && strcmp(pszArgs, "devices")
|
---|
3014 | && strcmp(pszArgs, "drivers")
|
---|
3015 | && strcmp(pszArgs, "usb"))
|
---|
3016 | {
|
---|
3017 | pHlp->pfnPrintf(pHlp, "Unable to grok '%s'\n", pszArgs);
|
---|
3018 | return;
|
---|
3019 | }
|
---|
3020 | bool fAll = !pszArgs || !*pszArgs || !strcmp(pszArgs, "all");
|
---|
3021 | bool fDevices = fAll || !strcmp(pszArgs, "devices");
|
---|
3022 | bool fUsbDevs = fAll || !strcmp(pszArgs, "usb");
|
---|
3023 | bool fDrivers = fAll || !strcmp(pszArgs, "drivers");
|
---|
3024 |
|
---|
3025 | /*
|
---|
3026 | * Produce the requested output.
|
---|
3027 | */
|
---|
3028 | /** @todo lock PDM lists! */
|
---|
3029 | /* devices */
|
---|
3030 | if (fDevices)
|
---|
3031 | {
|
---|
3032 | pHlp->pfnPrintf(pHlp, "Device tracing IDs:\n");
|
---|
3033 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
3034 | pHlp->pfnPrintf(pHlp, "%05u %s\n", pDevIns->idTracing, pDevIns->Internal.s.pDevR3->pReg->szName);
|
---|
3035 | }
|
---|
3036 |
|
---|
3037 | /* USB devices */
|
---|
3038 | if (fUsbDevs)
|
---|
3039 | {
|
---|
3040 | pHlp->pfnPrintf(pHlp, "USB device tracing IDs:\n");
|
---|
3041 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
3042 | pHlp->pfnPrintf(pHlp, "%05u %s\n", pUsbIns->idTracing, pUsbIns->Internal.s.pUsbDev->pReg->szName);
|
---|
3043 | }
|
---|
3044 |
|
---|
3045 | /* Drivers */
|
---|
3046 | if (fDrivers)
|
---|
3047 | {
|
---|
3048 | pHlp->pfnPrintf(pHlp, "Driver tracing IDs:\n");
|
---|
3049 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
|
---|
3050 | {
|
---|
3051 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
|
---|
3052 | {
|
---|
3053 | uint32_t iLevel = 0;
|
---|
3054 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown, iLevel++)
|
---|
3055 | pHlp->pfnPrintf(pHlp, "%05u %s (level %u, lun %u, dev %s)\n",
|
---|
3056 | pDrvIns->idTracing, pDrvIns->Internal.s.pDrv->pReg->szName,
|
---|
3057 | iLevel, pLun->iLun, pDevIns->Internal.s.pDevR3->pReg->szName);
|
---|
3058 | }
|
---|
3059 | }
|
---|
3060 |
|
---|
3061 | for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
|
---|
3062 | {
|
---|
3063 | for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
|
---|
3064 | {
|
---|
3065 | uint32_t iLevel = 0;
|
---|
3066 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown, iLevel++)
|
---|
3067 | pHlp->pfnPrintf(pHlp, "%05u %s (level %u, lun %u, dev %s)\n",
|
---|
3068 | pDrvIns->idTracing, pDrvIns->Internal.s.pDrv->pReg->szName,
|
---|
3069 | iLevel, pLun->iLun, pUsbIns->Internal.s.pUsbDev->pReg->szName);
|
---|
3070 | }
|
---|
3071 | }
|
---|
3072 | }
|
---|
3073 | }
|
---|
3074 |
|
---|