VirtualBox

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

Last change on this file since 6862 was 6796, checked in by vboxsync, 17 years ago

Fixed init problems wrt. VM ownership by implementing the UVM structure (U = user mode) and moving problematic ring-3 stuff over there (emt+reqs, r3heap, stam, loader[VMMR0.r0]). Big change, but it works fine here... :-)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 39.7 KB
Line 
1/* $Id: PDM.cpp 6796 2008-02-04 18:19:58Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device Manager.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 Manager
20 *
21 * VBox 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 and
24 * linked at runtime thru the Configuration Manager (CFGM). PDM will use
25 * CFGM to enumerate devices which needs loading and instantiation.
26 *
27 *
28 * @section sec_pdm_dev The Pluggable Device
29 *
30 * Devices register themselves when the module containing them is loaded.
31 * PDM will call an entry point 'VBoxDevicesRegister' when loading a device
32 * module. The device module will then use the supplied callback table to
33 * check the VMM version and to register its devices. Each device have an
34 * unique (for the configured VM) name (string). The name is not only used
35 * in PDM but in CFGM - to organize device and device instance settings - and
36 * by anyone who wants to do ioctls to the device.
37 *
38 * When all device modules have been successfully loaded PDM will instantiate
39 * those devices which are configured for the VM. Mark that this might mean
40 * creating several instances of some devices. When instantiating a device
41 * PDM provides device instance memory and a callback table with the VM APIs
42 * which the device instance is trusted with.
43 *
44 * Some devices are trusted devices, most are not. The trusted devices are
45 * an integrated part of the VM and can obtain the VM handle from their
46 * device instance handles, thus enabling them to call any VM api. Untrusted
47 * devices are can only use the callbacks provided during device
48 * instantiation.
49 *
50 * The guest context extention (optional) of a device is initialized as part
51 * of the GC init. A device marks in it's registration structure that it have
52 * a GC part, in which module and which name the entry point have. PDM will
53 * use its loader facilities to load this module into GC and to find the
54 * specified entry point.
55 *
56 * When writing a GC extention the programmer must keep in mind that this
57 * code will be relocated, so that using global/static pointer variables
58 * won't work.
59 *
60 *
61 * @section sec_pdm_drv The Pluggable Drivers
62 *
63 * The VM devices are often accessing host hardware or OS facilities. For
64 * most devices these facilities can be abstracted in one or more levels.
65 * These abstractions are called drivers.
66 *
67 * For instance take a DVD/CD drive. This can be connected to a SCSI
68 * controller, EIDE controller or SATA controller. The basics of the
69 * DVD/CD drive implementation remains the same - eject, insert,
70 * read, seek, and such. (For the scsi case, you might wanna speak SCSI
71 * directly to, but that can of course be fixed.) So, it makes much sense to
72 * have a generic CD/DVD driver which implements this.
73 *
74 * Then the media 'inserted' into the DVD/CD drive can be a ISO image, or
75 * it can be read from a real CD or DVD drive (there are probably other
76 * custom formats someone could desire to read or construct too). So, it
77 * would make sense to have abstracted interfaces for dealing with this
78 * in a generic way so the cdrom unit doesn't have to implement it all.
79 * Thus we have created the CDROM/DVD media driver family.
80 *
81 * So, for this example the IDE controller #1 (i.e. secondary) will have
82 * the DVD/CD Driver attached to it's LUN #0 (master). When a media is mounted
83 * the DVD/CD Driver will have a ISO, NativeCD, NativeDVD or RAW (media) Driver
84 * attached.
85 *
86 * It is possible to configure many levels of drivers inserting filters, loggers,
87 * or whatever you desire into the chain.
88 *
89 *
90 * @subsection sec_pdm_drv_interfaces Interfaces
91 *
92 * The pluggable drivers exposes one standard interface (callback table) which
93 * is used to construct, destruct, attach, detach, and query other interfaces.
94 * A device will query the interfaces required for it's operation during init
95 * and hotplug. PDM will query some interfaces during runtime mounting too.
96 *
97 * ... list interfaces ...
98 *
99 */
100
101
102/*******************************************************************************
103* Header Files *
104*******************************************************************************/
105#define LOG_GROUP LOG_GROUP_PDM
106#include "PDMInternal.h"
107#include <VBox/pdm.h>
108#include <VBox/mm.h>
109#include <VBox/ssm.h>
110#include <VBox/vm.h>
111#include <VBox/uvm.h>
112#include <VBox/vmm.h>
113#include <VBox/param.h>
114#include <VBox/err.h>
115#include <VBox/sup.h>
116
117#include <VBox/log.h>
118#include <iprt/asm.h>
119#include <iprt/assert.h>
120#include <iprt/alloc.h>
121#include <iprt/ldr.h>
122#include <iprt/path.h>
123#include <iprt/string.h>
124
125
126/*******************************************************************************
127* Defined Constants And Macros *
128*******************************************************************************/
129/** The PDM saved state version. */
130#define PDM_SAVED_STATE_VERSION 3
131
132
133/*******************************************************************************
134* Internal Functions *
135*******************************************************************************/
136static DECLCALLBACK(int) pdmR3Save(PVM pVM, PSSMHANDLE pSSM);
137static DECLCALLBACK(int) pdmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
138static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
139static DECLCALLBACK(void) pdmR3PollerTimer(PVM pVM, PTMTIMER pTimer, void *pvUser);
140
141
142
143/**
144 * Initializes the PDM part of the UVM.
145 *
146 * This doesn't really do much right now but has to be here for the sake
147 * of completeness.
148 *
149 * @returns VBox status code.
150 * @param pUVM Pointer to the user mode VM structure.
151 */
152PDMR3DECL(int) PDMR3InitUVM(PUVM pUVM)
153{
154 AssertCompile(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
155 AssertRelease(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
156 pUVM->pdm.s.pModules = NULL;
157 return VINF_SUCCESS;
158}
159
160
161/**
162 * Initializes the PDM.
163 *
164 * @returns VBox status code.
165 * @param pVM The VM to operate on.
166 */
167PDMR3DECL(int) PDMR3Init(PVM pVM)
168{
169 LogFlow(("PDMR3Init\n"));
170
171 /*
172 * Assert alignment and sizes.
173 */
174 AssertRelease(!(RT_OFFSETOF(VM, pdm.s) & 31));
175 AssertRelease(sizeof(pVM->pdm.s) <= sizeof(pVM->pdm.padding));
176
177 /*
178 * Init the structure.
179 */
180 pVM->pdm.s.offVM = RT_OFFSETOF(VM, pdm.s);
181
182 int rc = TMR3TimerCreateInternal(pVM, TMCLOCK_VIRTUAL, pdmR3PollerTimer, NULL, "PDM Poller", &pVM->pdm.s.pTimerPollers);
183 AssertRC(rc);
184
185 /*
186 * Initialize sub compontents.
187 */
188 rc = pdmR3CritSectInit(pVM);
189 if (VBOX_SUCCESS(rc))
190 {
191#ifdef VBOX_WITH_PDM_LOCK
192 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, "PDM");
193 if (VBOX_SUCCESS(rc))
194#endif
195 rc = pdmR3LdrInitU(pVM->pUVM);
196 if (VBOX_SUCCESS(rc))
197 {
198 rc = pdmR3DrvInit(pVM);
199 if (VBOX_SUCCESS(rc))
200 {
201 rc = pdmR3DevInit(pVM);
202 if (VBOX_SUCCESS(rc))
203 {
204#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
205 rc = pdmR3AsyncCompletionInit(pVM);
206 if (VBOX_SUCCESS(rc))
207#endif
208 {
209 /*
210 * Register the saved state data unit.
211 */
212 rc = SSMR3RegisterInternal(pVM, "pdm", 1, PDM_SAVED_STATE_VERSION, 128,
213 NULL, pdmR3Save, NULL,
214 pdmR3LoadPrep, pdmR3Load, NULL);
215 if (VBOX_SUCCESS(rc))
216 {
217 LogFlow(("PDM: Successfully initialized\n"));
218 return rc;
219 }
220
221 }
222 }
223 }
224 }
225 }
226
227 /*
228 * Cleanup and return failure.
229 */
230 PDMR3Term(pVM);
231 LogFlow(("PDMR3Init: returns %Vrc\n", rc));
232 return rc;
233}
234
235
236/**
237 * Applies relocations to data and code managed by this
238 * component. This function will be called at init and
239 * whenever the VMM need to relocate it self inside the GC.
240 *
241 * @param pVM VM handle.
242 * @param offDelta Relocation delta relative to old location.
243 * @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
244 * early in the relocation phase.
245 */
246PDMR3DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
247{
248 LogFlow(("PDMR3Relocate\n"));
249
250 /*
251 * Queues.
252 */
253 pdmR3QueueRelocate(pVM, offDelta);
254 pVM->pdm.s.pDevHlpQueueGC = PDMQueueGCPtr(pVM->pdm.s.pDevHlpQueueHC);
255
256 /*
257 * Critical sections.
258 */
259 pdmR3CritSectRelocate(pVM);
260
261 /*
262 * The registered PIC.
263 */
264 if (pVM->pdm.s.Pic.pDevInsGC)
265 {
266 pVM->pdm.s.Pic.pDevInsGC += offDelta;
267 pVM->pdm.s.Pic.pfnSetIrqGC += offDelta;
268 pVM->pdm.s.Pic.pfnGetInterruptGC += offDelta;
269 }
270
271 /*
272 * The registered APIC.
273 */
274 if (pVM->pdm.s.Apic.pDevInsGC)
275 {
276 pVM->pdm.s.Apic.pDevInsGC += offDelta;
277 pVM->pdm.s.Apic.pfnGetInterruptGC += offDelta;
278 pVM->pdm.s.Apic.pfnSetBaseGC += offDelta;
279 pVM->pdm.s.Apic.pfnGetBaseGC += offDelta;
280 pVM->pdm.s.Apic.pfnSetTPRGC += offDelta;
281 pVM->pdm.s.Apic.pfnGetTPRGC += offDelta;
282 pVM->pdm.s.Apic.pfnBusDeliverGC += offDelta;
283 }
284
285 /*
286 * The registered I/O APIC.
287 */
288 if (pVM->pdm.s.IoApic.pDevInsGC)
289 {
290 pVM->pdm.s.IoApic.pDevInsGC += offDelta;
291 pVM->pdm.s.IoApic.pfnSetIrqGC += offDelta;
292 }
293
294 /*
295 * The register PCI Buses.
296 */
297 for (unsigned i = 0; i < ELEMENTS(pVM->pdm.s.aPciBuses); i++)
298 {
299 if (pVM->pdm.s.aPciBuses[i].pDevInsGC)
300 {
301 pVM->pdm.s.aPciBuses[i].pDevInsGC += offDelta;
302 pVM->pdm.s.aPciBuses[i].pfnSetIrqGC += offDelta;
303 }
304 }
305
306 /*
307 * Devices.
308 */
309 GCPTRTYPE(PCPDMDEVHLPGC) pDevHlpGC;
310 int rc = PDMR3GetSymbolGC(pVM, NULL, "g_pdmGCDevHlp", &pDevHlpGC);
311 AssertReleaseMsgRC(rc, ("rc=%Vrc when resolving g_pdmGCDevHlp\n", rc));
312 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
313 {
314 if (pDevIns->pDevReg->fFlags & PDM_DEVREG_FLAGS_GC)
315 {
316 pDevIns->pDevHlpGC = pDevHlpGC;
317 pDevIns->pvInstanceDataGC = MMHyperR3ToGC(pVM, pDevIns->pvInstanceDataR3);
318 pDevIns->pvInstanceDataR0 = MMHyperR3ToR0(pVM, pDevIns->pvInstanceDataR3);
319 pDevIns->Internal.s.pVMGC = pVM->pVMGC;
320 if (pDevIns->Internal.s.pPciBusHC)
321 pDevIns->Internal.s.pPciBusGC = MMHyperR3ToGC(pVM, pDevIns->Internal.s.pPciBusHC);
322 if (pDevIns->Internal.s.pPciDeviceHC)
323 pDevIns->Internal.s.pPciDeviceGC = MMHyperR3ToGC(pVM, pDevIns->Internal.s.pPciDeviceHC);
324 if (pDevIns->pDevReg->pfnRelocate)
325 {
326 LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
327 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
328 pDevIns->pDevReg->pfnRelocate(pDevIns, offDelta);
329 }
330 }
331 }
332}
333
334
335/**
336 * Worker for pdmR3Term that terminates a LUN chain.
337 *
338 * @param pVM Pointer to the shared VM structure.
339 * @param pLun The head of the chain.
340 * @param pszDevice The name of the device (for logging).
341 * @param iInstance The device instance number (for logging).
342 */
343static void pdmR3TermLuns(PVM pVM, PPDMLUN pLun, const char *pszDevice, unsigned iInstance)
344{
345 for (; pLun; pLun = pLun->pNext)
346 {
347 /*
348 * Destroy them one at a time from the bottom up.
349 * (The serial device/drivers depends on this - bad.)
350 */
351 PPDMDRVINS pDrvIns = pLun->pBottom;
352 pLun->pBottom = pLun->pTop = NULL;
353 while (pDrvIns)
354 {
355 PPDMDRVINS pDrvNext = pDrvIns->Internal.s.pUp;
356
357 if (pDrvIns->pDrvReg->pfnDestruct)
358 {
359 LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
360 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pszDevice, iInstance));
361 pDrvIns->pDrvReg->pfnDestruct(pDrvIns);
362 }
363
364 TMR3TimerDestroyDriver(pVM, pDrvIns);
365 //PDMR3QueueDestroyDriver(pVM, pDrvIns);
366 //pdmR3ThreadDestroyDriver(pVM, pDrvIns);
367 SSMR3DeregisterDriver(pVM, pDrvIns, NULL, 0);
368
369 pDrvIns = pDrvNext;
370 }
371 }
372}
373
374
375/**
376 * Terminates the PDM.
377 *
378 * Termination means cleaning up and freeing all resources,
379 * the VM it self is at this point powered off or suspended.
380 *
381 * @returns VBox status code.
382 * @param pVM The VM to operate on.
383 */
384PDMR3DECL(int) PDMR3Term(PVM pVM)
385{
386 LogFlow(("PDMR3Term:\n"));
387 AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n"));
388
389 /*
390 * Iterate the device instances and attach drivers, doing
391 * relevant destruction processing.
392 *
393 * N.B. There is no need to mess around freeing memory allocated
394 * from any MM heap since MM will do that in its Term function.
395 */
396 /* usb ones first. */
397 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
398 {
399 pdmR3TermLuns(pVM, pUsbIns->Internal.s.pLuns, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance);
400
401 if (pUsbIns->pUsbReg->pfnDestruct)
402 {
403 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
404 pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
405 pUsbIns->pUsbReg->pfnDestruct(pUsbIns);
406 }
407
408 //TMR3TimerDestroyUsb(pVM, pUsbIns);
409 //SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
410 pdmR3ThreadDestroyUsb(pVM, pUsbIns);
411 }
412
413 /* then the 'normal' ones. */
414 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
415 {
416 pdmR3TermLuns(pVM, pDevIns->Internal.s.pLunsHC, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance);
417
418 if (pDevIns->pDevReg->pfnDestruct)
419 {
420 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
421 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
422 pDevIns->pDevReg->pfnDestruct(pDevIns);
423 }
424
425 TMR3TimerDestroyDevice(pVM, pDevIns);
426 //SSMR3DeregisterDriver(pVM, pDevIns, NULL, 0);
427 pdmR3CritSectDeleteDevice(pVM, pDevIns);
428 //pdmR3ThreadDestroyDevice(pVM, pDevIns);
429 //PDMR3QueueDestroyDevice(pVM, pDevIns);
430 }
431
432 /*
433 * Destroy all threads.
434 */
435 pdmR3ThreadDestroyAll(pVM);
436
437#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
438 /*
439 * Free async completion managers.
440 */
441 pdmR3AsyncCompletionTerm(pVM);
442#endif
443
444 /*
445 * Free modules.
446 */
447 pdmR3LdrTermU(pVM->pUVM);
448
449#ifdef VBOX_WITH_PDM_LOCK
450 /*
451 * Destroy the PDM lock.
452 */
453 PDMR3CritSectDelete(&pVM->pdm.s.CritSect);
454#endif
455
456 LogFlow(("PDMR3Term: returns %Vrc\n", VINF_SUCCESS));
457 return VINF_SUCCESS;
458}
459
460
461/**
462 * Terminates the PDM part of the UVM.
463 *
464 * This will unload any modules left behind.
465 *
466 * @param pUVM Pointer to the user mode VM structure.
467 */
468PDMR3DECL(void) PDMR3TermUVM(PUVM pUVM)
469{
470 /*
471 * In the normal cause of events we will now call pdmR3LdrTermU for
472 * the second time. In the case of init failure however, this might
473 * the first time, which is why we do it.
474 */
475 pdmR3LdrTermU(pUVM);
476}
477
478
479
480
481
482/**
483 * Execute state save operation.
484 *
485 * @returns VBox status code.
486 * @param pVM VM Handle.
487 * @param pSSM SSM operation handle.
488 */
489static DECLCALLBACK(int) pdmR3Save(PVM pVM, PSSMHANDLE pSSM)
490{
491 LogFlow(("pdmR3Save:\n"));
492
493 /*
494 * Save interrupt and DMA states.
495 */
496 SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC));
497 SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC));
498 SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
499
500 /*
501 * Save the list of device instances so we can check that
502 * they're all still there when we load the state and that
503 * nothing new have been added.
504 */
505 /** @todo We might have to filter out some device classes, like USB attached devices. */
506 uint32_t i = 0;
507 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC, i++)
508 {
509 SSMR3PutU32(pSSM, i);
510 SSMR3PutStrZ(pSSM, pDevIns->pDevReg->szDeviceName);
511 SSMR3PutU32(pSSM, pDevIns->iInstance);
512 }
513 return SSMR3PutU32(pSSM, ~0); /* terminator */
514}
515
516
517/**
518 * Prepare state load operation.
519 *
520 * This will dispatch pending operations and clear the FFs governed by PDM and its devices.
521 *
522 * @returns VBox status code.
523 * @param pVM The VM handle.
524 * @param pSSM The SSM handle.
525 */
526static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
527{
528 LogFlow(("pdmR3LoadPrep: %s%s%s%s\n",
529 VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
530 VM_FF_ISSET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : "",
531 VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC) ? " VM_FF_INTERRUPT_APIC" : "",
532 VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC) ? " VM_FF_INTERRUPT_PIC" : ""
533 ));
534
535 /*
536 * In case there is work pending that will raise an interrupt,
537 * start a DMA transfer, or release a lock. (unlikely)
538 */
539 if (VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES))
540 PDMR3QueueFlushAll(pVM);
541
542 /* Clear the FFs. */
543 VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
544 VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
545 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
546
547 return VINF_SUCCESS;
548}
549
550
551/**
552 * Execute state load operation.
553 *
554 * @returns VBox status code.
555 * @param pVM VM Handle.
556 * @param pSSM SSM operation handle.
557 * @param u32Version Data layout version.
558 */
559static DECLCALLBACK(int) pdmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
560{
561 LogFlow(("pdmR3Load:\n"));
562
563 /*
564 * Validate version.
565 */
566 if (u32Version != PDM_SAVED_STATE_VERSION)
567 {
568 Log(("pdmR3Load: Invalid version u32Version=%d!\n", u32Version));
569 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
570 }
571
572 /*
573 * Load the interrupt and DMA states.
574 */
575 /* APIC interrupt */
576 RTUINT fInterruptPending = 0;
577 int rc = SSMR3GetUInt(pSSM, &fInterruptPending);
578 if (VBOX_FAILURE(rc))
579 return rc;
580 if (fInterruptPending & ~1)
581 {
582 AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
583 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
584 }
585 AssertRelease(!VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC));
586 if (fInterruptPending)
587 VM_FF_SET(pVM, VM_FF_INTERRUPT_APIC);
588
589 /* PIC interrupt */
590 fInterruptPending = 0;
591 rc = SSMR3GetUInt(pSSM, &fInterruptPending);
592 if (VBOX_FAILURE(rc))
593 return rc;
594 if (fInterruptPending & ~1)
595 {
596 AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
597 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
598 }
599 AssertRelease(!VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC));
600 if (fInterruptPending)
601 VM_FF_SET(pVM, VM_FF_INTERRUPT_PIC);
602
603 /* DMA pending */
604 RTUINT fDMAPending = 0;
605 rc = SSMR3GetUInt(pSSM, &fDMAPending);
606 if (VBOX_FAILURE(rc))
607 return rc;
608 if (fDMAPending & ~1)
609 {
610 AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
611 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
612 }
613 AssertRelease(!VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
614 if (fDMAPending)
615 VM_FF_SET(pVM, VM_FF_PDM_DMA);
616
617 /*
618 * Load the list of devices and verify that they are all there.
619 *
620 * We boldly ASSUME that the order is fixed and that it's a good, this
621 * makes it way easier to validate...
622 */
623 uint32_t i = 0;
624 PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances;
625 for (;;pDevIns = pDevIns->Internal.s.pNextHC, i++)
626 {
627 /* Get the separator / terminator. */
628 uint32_t u32Sep;
629 int rc = SSMR3GetU32(pSSM, &u32Sep);
630 if (VBOX_FAILURE(rc))
631 return rc;
632 if (u32Sep == (uint32_t)~0)
633 break;
634 if (u32Sep != i)
635 AssertMsgFailedReturn(("Out of seqence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
636
637 /* get the name and instance number. */
638 char szDeviceName[sizeof(pDevIns->pDevReg->szDeviceName)];
639 rc = SSMR3GetStrZ(pSSM, szDeviceName, sizeof(szDeviceName));
640 if (VBOX_FAILURE(rc))
641 return rc;
642 RTUINT iInstance;
643 rc = SSMR3GetUInt(pSSM, &iInstance);
644 if (VBOX_FAILURE(rc))
645 return rc;
646
647 /* compare */
648 if (!pDevIns)
649 {
650 LogRel(("Device '%s'/%d not found in current config\n", szDeviceName, iInstance));
651 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
652 AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
653 break;
654 }
655 if ( strcmp(szDeviceName, pDevIns->pDevReg->szDeviceName)
656 || pDevIns->iInstance != iInstance)
657 {
658 LogRel(("u32Sep=%d loaded '%s'/%d configured '%s'/%d\n",
659 u32Sep, szDeviceName, iInstance, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
660 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
661 AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
662 }
663 }
664
665 /*
666 * Too many devices?
667 */
668 if (pDevIns)
669 {
670 LogRel(("Device '%s'/%d not found in saved state\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
671 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
672 AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
673 }
674
675 return VINF_SUCCESS;
676}
677
678
679/**
680 * This function will notify all the devices and their
681 * attached drivers about the VM now being powered on.
682 *
683 * @param pVM VM Handle.
684 */
685PDMR3DECL(void) PDMR3PowerOn(PVM pVM)
686{
687 LogFlow(("PDMR3PowerOn:\n"));
688
689 /*
690 * Iterate the device instances.
691 * The attached drivers are processed first.
692 */
693 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
694 {
695 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
696 /** @todo Inverse the order here? */
697 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
698 if (pDrvIns->pDrvReg->pfnPowerOn)
699 {
700 LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
701 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
702 pDrvIns->pDrvReg->pfnPowerOn(pDrvIns);
703 }
704
705 if (pDevIns->pDevReg->pfnPowerOn)
706 {
707 LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
708 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
709 pDevIns->pDevReg->pfnPowerOn(pDevIns);
710 }
711 }
712
713#ifdef VBOX_WITH_USB
714 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
715 {
716 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
717 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
718 if (pDrvIns->pDrvReg->pfnPowerOn)
719 {
720 LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
721 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
722 pDrvIns->pDrvReg->pfnPowerOn(pDrvIns);
723 }
724
725 if (pUsbIns->pUsbReg->pfnVMPowerOn)
726 {
727 LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
728 pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
729 pUsbIns->pUsbReg->pfnVMPowerOn(pUsbIns);
730 }
731 }
732#endif
733
734 /*
735 * Resume all threads.
736 */
737 pdmR3ThreadResumeAll(pVM);
738
739 LogFlow(("PDMR3PowerOn: returns void\n"));
740}
741
742
743
744
745/**
746 * This function will notify all the devices and their
747 * attached drivers about the VM now being reset.
748 *
749 * @param pVM VM Handle.
750 */
751PDMR3DECL(void) PDMR3Reset(PVM pVM)
752{
753 LogFlow(("PDMR3Reset:\n"));
754
755 /*
756 * Clear all pending interrupts and DMA operations.
757 */
758 VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
759 VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
760 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
761
762 /*
763 * Iterate the device instances.
764 * The attached drivers are processed first.
765 */
766 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
767 {
768 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
769 /** @todo Inverse the order here? */
770 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
771 if (pDrvIns->pDrvReg->pfnReset)
772 {
773 LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
774 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
775 pDrvIns->pDrvReg->pfnReset(pDrvIns);
776 }
777
778 if (pDevIns->pDevReg->pfnReset)
779 {
780 LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
781 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
782 pDevIns->pDevReg->pfnReset(pDevIns);
783 }
784 }
785
786#ifdef VBOX_WITH_USB
787 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
788 {
789 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
790 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
791 if (pDrvIns->pDrvReg->pfnReset)
792 {
793 LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
794 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
795 pDrvIns->pDrvReg->pfnReset(pDrvIns);
796 }
797
798 if (pUsbIns->pUsbReg->pfnVMReset)
799 {
800 LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
801 pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
802 pUsbIns->pUsbReg->pfnVMReset(pUsbIns);
803 }
804 }
805#endif
806
807 LogFlow(("PDMR3Reset: returns void\n"));
808}
809
810
811/**
812 * This function will notify all the devices and their
813 * attached drivers about the VM now being reset.
814 *
815 * @param pVM VM Handle.
816 */
817PDMR3DECL(void) PDMR3Suspend(PVM pVM)
818{
819 LogFlow(("PDMR3Suspend:\n"));
820
821 /*
822 * Iterate the device instances.
823 * The attached drivers are processed first.
824 */
825 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
826 {
827 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
828 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
829 if (pDrvIns->pDrvReg->pfnSuspend)
830 {
831 LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
832 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
833 pDrvIns->pDrvReg->pfnSuspend(pDrvIns);
834 }
835
836 if (pDevIns->pDevReg->pfnSuspend)
837 {
838 LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
839 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
840 pDevIns->pDevReg->pfnSuspend(pDevIns);
841 }
842 }
843
844#ifdef VBOX_WITH_USB
845 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
846 {
847 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
848 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
849 if (pDrvIns->pDrvReg->pfnSuspend)
850 {
851 LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
852 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
853 pDrvIns->pDrvReg->pfnSuspend(pDrvIns);
854 }
855
856 if (pUsbIns->pUsbReg->pfnVMSuspend)
857 {
858 LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
859 pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
860 pUsbIns->pUsbReg->pfnVMSuspend(pUsbIns);
861 }
862 }
863#endif
864
865 /*
866 * Suspend all threads.
867 */
868 pdmR3ThreadSuspendAll(pVM);
869
870 LogFlow(("PDMR3Suspend: returns void\n"));
871}
872
873
874/**
875 * This function will notify all the devices and their
876 * attached drivers about the VM now being resumed.
877 *
878 * @param pVM VM Handle.
879 */
880PDMR3DECL(void) PDMR3Resume(PVM pVM)
881{
882 LogFlow(("PDMR3Resume:\n"));
883
884 /*
885 * Iterate the device instances.
886 * The attached drivers are processed first.
887 */
888 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
889 {
890 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
891 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
892 if (pDrvIns->pDrvReg->pfnResume)
893 {
894 LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
895 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
896 pDrvIns->pDrvReg->pfnResume(pDrvIns);
897 }
898
899 if (pDevIns->pDevReg->pfnResume)
900 {
901 LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
902 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
903 pDevIns->pDevReg->pfnResume(pDevIns);
904 }
905 }
906
907#ifdef VBOX_WITH_USB
908 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
909 {
910 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
911 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
912 if (pDrvIns->pDrvReg->pfnResume)
913 {
914 LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
915 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
916 pDrvIns->pDrvReg->pfnResume(pDrvIns);
917 }
918
919 if (pUsbIns->pUsbReg->pfnVMResume)
920 {
921 LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
922 pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
923 pUsbIns->pUsbReg->pfnVMResume(pUsbIns);
924 }
925 }
926#endif
927
928 /*
929 * Resume all threads.
930 */
931 pdmR3ThreadResumeAll(pVM);
932
933 LogFlow(("PDMR3Resume: returns void\n"));
934}
935
936
937/**
938 * This function will notify all the devices and their
939 * attached drivers about the VM being powered off.
940 *
941 * @param pVM VM Handle.
942 */
943PDMR3DECL(void) PDMR3PowerOff(PVM pVM)
944{
945 LogFlow(("PDMR3PowerOff:\n"));
946
947 /*
948 * Iterate the device instances.
949 * The attached drivers are processed first.
950 */
951 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
952 {
953 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
954 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
955 if (pDrvIns->pDrvReg->pfnPowerOff)
956 {
957 LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
958 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
959 pDrvIns->pDrvReg->pfnPowerOff(pDrvIns);
960 }
961
962 if (pDevIns->pDevReg->pfnPowerOff)
963 {
964 LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
965 pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
966 pDevIns->pDevReg->pfnPowerOff(pDevIns);
967 }
968 }
969
970#ifdef VBOX_WITH_USB
971 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
972 {
973 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
974 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
975 if (pDrvIns->pDrvReg->pfnPowerOff)
976 {
977 LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
978 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
979 pDrvIns->pDrvReg->pfnPowerOff(pDrvIns);
980 }
981
982 if (pUsbIns->pUsbReg->pfnVMPowerOff)
983 {
984 LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
985 pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
986 pUsbIns->pUsbReg->pfnVMPowerOff(pUsbIns);
987 }
988 }
989#endif
990
991 /*
992 * Suspend all threads.
993 */
994 pdmR3ThreadSuspendAll(pVM);
995
996 LogFlow(("PDMR3PowerOff: returns void\n"));
997}
998
999
1000/**
1001 * Queries the base interace of a device instance.
1002 *
1003 * The caller can use this to query other interfaces the device implements
1004 * and use them to talk to the device.
1005 *
1006 * @returns VBox status code.
1007 * @param pVM VM handle.
1008 * @param pszDevice Device name.
1009 * @param iInstance Device instance.
1010 * @param ppBase Where to store the pointer to the base device interface on success.
1011 * @remark We're not doing any locking ATM, so don't try call this at times when the
1012 * device chain is known to be updated.
1013 */
1014PDMR3DECL(int) PDMR3QueryDevice(PVM pVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
1015{
1016 LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
1017
1018 /*
1019 * Iterate registered devices looking for the device.
1020 */
1021 RTUINT cchDevice = strlen(pszDevice);
1022 for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext)
1023 {
1024 if ( pDev->cchName == cchDevice
1025 && !memcmp(pDev->pDevReg->szDeviceName, pszDevice, cchDevice))
1026 {
1027 /*
1028 * Iterate device instances.
1029 */
1030 for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextHC)
1031 {
1032 if (pDevIns->iInstance == iInstance)
1033 {
1034 if (pDevIns->IBase.pfnQueryInterface)
1035 {
1036 *ppBase = &pDevIns->IBase;
1037 LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
1038 return VINF_SUCCESS;
1039 }
1040
1041 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
1042 return VERR_PDM_DEVICE_INSTANCE_NO_IBASE;
1043 }
1044 }
1045
1046 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
1047 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND;
1048 }
1049 }
1050
1051 LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
1052 return VERR_PDM_DEVICE_NOT_FOUND;
1053}
1054
1055
1056/**
1057 * Queries the base interface of a device LUN.
1058 *
1059 * This differs from PDMR3QueryLun by that it returns the interface on the
1060 * device and not the top level driver.
1061 *
1062 * @returns VBox status code.
1063 * @param pVM VM Handle.
1064 * @param pszDevice Device name.
1065 * @param iInstance Device instance.
1066 * @param iLun The Logical Unit to obtain the interface of.
1067 * @param ppBase Where to store the base interface pointer.
1068 * @remark We're not doing any locking ATM, so don't try call this at times when the
1069 * device chain is known to be updated.
1070 */
1071PDMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
1072{
1073 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
1074 pszDevice, pszDevice, iInstance, iLun, ppBase));
1075
1076 /*
1077 * Find the LUN.
1078 */
1079 PPDMLUN pLun;
1080 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
1081 if (VBOX_SUCCESS(rc))
1082 {
1083 *ppBase = pLun->pBase;
1084 LogFlow(("PDMR3QueryDeviceLun: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
1085 return VINF_SUCCESS;
1086 }
1087 LogFlow(("PDMR3QueryDeviceLun: returns %Vrc\n", rc));
1088 return rc;
1089}
1090
1091
1092/**
1093 * Query the interface of the top level driver on a LUN.
1094 *
1095 * @returns VBox status code.
1096 * @param pVM VM Handle.
1097 * @param pszDevice Device name.
1098 * @param iInstance Device instance.
1099 * @param iLun The Logical Unit to obtain the interface of.
1100 * @param ppBase Where to store the base interface pointer.
1101 * @remark We're not doing any locking ATM, so don't try call this at times when the
1102 * device chain is known to be updated.
1103 */
1104PDMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
1105{
1106 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
1107 pszDevice, pszDevice, iInstance, iLun, ppBase));
1108
1109 /*
1110 * Find the LUN.
1111 */
1112 PPDMLUN pLun;
1113 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
1114 if (VBOX_SUCCESS(rc))
1115 {
1116 if (pLun->pTop)
1117 {
1118 *ppBase = &pLun->pTop->IBase;
1119 LogFlow(("PDMR3QueryLun: return %Vrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
1120 return VINF_SUCCESS;
1121 }
1122 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
1123 }
1124 LogFlow(("PDMR3QueryLun: returns %Vrc\n", rc));
1125 return rc;
1126}
1127
1128/**
1129 * Executes pending DMA transfers.
1130 * Forced Action handler.
1131 *
1132 * @param pVM VM handle.
1133 */
1134PDMR3DECL(void) PDMR3DmaRun(PVM pVM)
1135{
1136 VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
1137 if (pVM->pdm.s.pDmac)
1138 {
1139 bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns);
1140 if (fMore)
1141 VM_FF_SET(pVM, VM_FF_PDM_DMA);
1142 }
1143}
1144
1145
1146/**
1147 * Call polling function.
1148 *
1149 * @param pVM VM handle.
1150 */
1151PDMR3DECL(void) PDMR3Poll(PVM pVM)
1152{
1153 /* This is temporary hack and shall be removed ASAP! */
1154 unsigned iPoller = pVM->pdm.s.cPollers;
1155 if (iPoller)
1156 {
1157 while (iPoller-- > 0)
1158 pVM->pdm.s.apfnPollers[iPoller](pVM->pdm.s.aDrvInsPollers[iPoller]);
1159 TMTimerSetMillies(pVM->pdm.s.pTimerPollers, 3);
1160 }
1161}
1162
1163
1164/**
1165 * Internal timer callback function.
1166 *
1167 * @param pVM The VM.
1168 * @param pTimer The timer handle.
1169 * @param pvUser User argument specified upon timer creation.
1170 */
1171static DECLCALLBACK(void) pdmR3PollerTimer(PVM pVM, PTMTIMER pTimer, void *pvUser)
1172{
1173 PDMR3Poll(pVM);
1174}
1175
1176
1177/**
1178 * Serivce a VMMCALLHOST_PDM_LOCK call.
1179 *
1180 * @returns VBox status code.
1181 * @param pVM The VM handle.
1182 */
1183PDMR3DECL(int) PDMR3LockCall(PVM pVM)
1184{
1185 return pdmLockEx(pVM, VERR_INTERNAL_ERROR);
1186}
1187
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette