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