1 | /* $Id: PDM.cpp 4188 2007-08-16 22:47:14Z 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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * 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/vmm.h>
|
---|
112 | #include <VBox/param.h>
|
---|
113 | #include <VBox/err.h>
|
---|
114 | #include <VBox/sup.h>
|
---|
115 |
|
---|
116 | #include <VBox/log.h>
|
---|
117 | #include <iprt/asm.h>
|
---|
118 | #include <iprt/assert.h>
|
---|
119 | #include <iprt/alloc.h>
|
---|
120 | #include <iprt/ldr.h>
|
---|
121 | #include <iprt/path.h>
|
---|
122 | #include <iprt/string.h>
|
---|
123 |
|
---|
124 |
|
---|
125 | /*******************************************************************************
|
---|
126 | * Defined Constants And Macros *
|
---|
127 | *******************************************************************************/
|
---|
128 | /** The PDM saved state version. */
|
---|
129 | #define PDM_SAVED_STATE_VERSION 3
|
---|
130 |
|
---|
131 |
|
---|
132 | /*******************************************************************************
|
---|
133 | * Internal Functions *
|
---|
134 | *******************************************************************************/
|
---|
135 | static DECLCALLBACK(int) pdmR3Save(PVM pVM, PSSMHANDLE pSSM);
|
---|
136 | static DECLCALLBACK(int) pdmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
|
---|
137 | static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
|
---|
138 | static DECLCALLBACK(void) pdmR3PollerTimer(PVM pVM, PTMTIMER pTimer, void *pvUser);
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Initializes the PDM.
|
---|
144 | *
|
---|
145 | * @returns VBox status code.
|
---|
146 | * @param pVM The VM to operate on.
|
---|
147 | */
|
---|
148 | PDMR3DECL(int) PDMR3Init(PVM pVM)
|
---|
149 | {
|
---|
150 | LogFlow(("PDMR3Init\n"));
|
---|
151 | /*
|
---|
152 | * Assert alignment and sizes.
|
---|
153 | */
|
---|
154 | AssertRelease(!(RT_OFFSETOF(VM, pdm.s) & 31));
|
---|
155 | AssertRelease(sizeof(pVM->pdm.s) <= sizeof(pVM->pdm.padding));
|
---|
156 |
|
---|
157 | /*
|
---|
158 | * Init the structure.
|
---|
159 | */
|
---|
160 | pVM->pdm.s.offVM = RT_OFFSETOF(VM, pdm.s);
|
---|
161 |
|
---|
162 | int rc = TMR3TimerCreateInternal(pVM, TMCLOCK_VIRTUAL, pdmR3PollerTimer, NULL, "PDM Poller", &pVM->pdm.s.pTimerPollers);
|
---|
163 | AssertRC(rc);
|
---|
164 |
|
---|
165 | /*
|
---|
166 | * Initialize sub compontents.
|
---|
167 | */
|
---|
168 | rc = pdmR3CritSectInit(pVM);
|
---|
169 | if (VBOX_SUCCESS(rc))
|
---|
170 | {
|
---|
171 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
172 | rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, "PDM");
|
---|
173 | if (VBOX_SUCCESS(rc))
|
---|
174 | #endif
|
---|
175 | rc = pdmR3LdrInit(pVM);
|
---|
176 | if (VBOX_SUCCESS(rc))
|
---|
177 | {
|
---|
178 | rc = pdmR3DrvInit(pVM);
|
---|
179 | if (VBOX_SUCCESS(rc))
|
---|
180 | {
|
---|
181 | rc = pdmR3DevInit(pVM);
|
---|
182 | if (VBOX_SUCCESS(rc))
|
---|
183 | {
|
---|
184 | /*
|
---|
185 | * Register the saved state data unit.
|
---|
186 | */
|
---|
187 | rc = SSMR3RegisterInternal(pVM, "pdm", 1, PDM_SAVED_STATE_VERSION, 128,
|
---|
188 | NULL, pdmR3Save, NULL,
|
---|
189 | pdmR3LoadPrep, pdmR3Load, NULL);
|
---|
190 | if (VBOX_SUCCESS(rc))
|
---|
191 | {
|
---|
192 | LogFlow(("PDM: Successfully initialized\n"));
|
---|
193 | return rc;
|
---|
194 | }
|
---|
195 |
|
---|
196 | }
|
---|
197 | }
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | /*
|
---|
202 | * Cleanup and return failure.
|
---|
203 | */
|
---|
204 | PDMR3Term(pVM);
|
---|
205 | LogFlow(("PDMR3Init: returns %Vrc\n", rc));
|
---|
206 | return rc;
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Applies relocations to data and code managed by this
|
---|
212 | * component. This function will be called at init and
|
---|
213 | * whenever the VMM need to relocate it self inside the GC.
|
---|
214 | *
|
---|
215 | * @param pVM VM handle.
|
---|
216 | * @param offDelta Relocation delta relative to old location.
|
---|
217 | * @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
|
---|
218 | * early in the relocation phase.
|
---|
219 | */
|
---|
220 | PDMR3DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
|
---|
221 | {
|
---|
222 | LogFlow(("PDMR3Relocate\n"));
|
---|
223 |
|
---|
224 | /*
|
---|
225 | * Queues.
|
---|
226 | */
|
---|
227 | pdmR3QueueRelocate(pVM, offDelta);
|
---|
228 | pVM->pdm.s.pDevHlpQueueGC = PDMQueueGCPtr(pVM->pdm.s.pDevHlpQueueHC);
|
---|
229 |
|
---|
230 | /*
|
---|
231 | * Critical sections.
|
---|
232 | */
|
---|
233 | pdmR3CritSectRelocate(pVM);
|
---|
234 |
|
---|
235 | /*
|
---|
236 | * The registered PIC.
|
---|
237 | */
|
---|
238 | if (pVM->pdm.s.Pic.pDevInsGC)
|
---|
239 | {
|
---|
240 | pVM->pdm.s.Pic.pDevInsGC += offDelta;
|
---|
241 | pVM->pdm.s.Pic.pfnSetIrqGC += offDelta;
|
---|
242 | pVM->pdm.s.Pic.pfnGetInterruptGC += offDelta;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * The registered APIC.
|
---|
247 | */
|
---|
248 | if (pVM->pdm.s.Apic.pDevInsGC)
|
---|
249 | {
|
---|
250 | pVM->pdm.s.Apic.pDevInsGC += offDelta;
|
---|
251 | pVM->pdm.s.Apic.pfnGetInterruptGC += offDelta;
|
---|
252 | pVM->pdm.s.Apic.pfnSetBaseGC += offDelta;
|
---|
253 | pVM->pdm.s.Apic.pfnGetBaseGC += offDelta;
|
---|
254 | pVM->pdm.s.Apic.pfnSetTPRGC += offDelta;
|
---|
255 | pVM->pdm.s.Apic.pfnGetTPRGC += offDelta;
|
---|
256 | pVM->pdm.s.Apic.pfnBusDeliverGC += offDelta;
|
---|
257 | }
|
---|
258 |
|
---|
259 | /*
|
---|
260 | * The registered I/O APIC.
|
---|
261 | */
|
---|
262 | if (pVM->pdm.s.IoApic.pDevInsGC)
|
---|
263 | {
|
---|
264 | pVM->pdm.s.IoApic.pDevInsGC += offDelta;
|
---|
265 | pVM->pdm.s.IoApic.pfnSetIrqGC += offDelta;
|
---|
266 | }
|
---|
267 |
|
---|
268 | /*
|
---|
269 | * The register PCI Buses.
|
---|
270 | */
|
---|
271 | for (unsigned i = 0; i < ELEMENTS(pVM->pdm.s.aPciBuses); i++)
|
---|
272 | {
|
---|
273 | if (pVM->pdm.s.aPciBuses[i].pDevInsGC)
|
---|
274 | {
|
---|
275 | pVM->pdm.s.aPciBuses[i].pDevInsGC += offDelta;
|
---|
276 | pVM->pdm.s.aPciBuses[i].pfnSetIrqGC += offDelta;
|
---|
277 | }
|
---|
278 | }
|
---|
279 |
|
---|
280 | /*
|
---|
281 | * Devices.
|
---|
282 | */
|
---|
283 | GCPTRTYPE(PCPDMDEVHLPGC) pDevHlpGC;
|
---|
284 | int rc = PDMR3GetSymbolGC(pVM, NULL, "g_pdmGCDevHlp", &pDevHlpGC);
|
---|
285 | AssertReleaseMsgRC(rc, ("rc=%Vrc when resolving g_pdmGCDevHlp\n", rc));
|
---|
286 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
287 | {
|
---|
288 | if (pDevIns->pDevReg->fFlags & PDM_DEVREG_FLAGS_GC)
|
---|
289 | {
|
---|
290 | pDevIns->pDevHlpGC = pDevHlpGC;
|
---|
291 | pDevIns->pvInstanceDataGC = MMHyperR3ToGC(pVM, pDevIns->pvInstanceDataR3);
|
---|
292 | pDevIns->pvInstanceDataR0 = MMHyperR3ToR0(pVM, pDevIns->pvInstanceDataR3);
|
---|
293 | pDevIns->Internal.s.pVMGC = pVM->pVMGC;
|
---|
294 | if (pDevIns->Internal.s.pPciBusHC)
|
---|
295 | pDevIns->Internal.s.pPciBusGC = MMHyperR3ToGC(pVM, pDevIns->Internal.s.pPciBusHC);
|
---|
296 | if (pDevIns->Internal.s.pPciDeviceHC)
|
---|
297 | pDevIns->Internal.s.pPciDeviceGC = MMHyperR3ToGC(pVM, pDevIns->Internal.s.pPciDeviceHC);
|
---|
298 | if (pDevIns->pDevReg->pfnRelocate)
|
---|
299 | {
|
---|
300 | LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
|
---|
301 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
302 | pDevIns->pDevReg->pfnRelocate(pDevIns, offDelta);
|
---|
303 | }
|
---|
304 | }
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Terminates the PDM.
|
---|
311 | *
|
---|
312 | * Termination means cleaning up and freeing all resources,
|
---|
313 | * the VM it self is at this point powered off or suspended.
|
---|
314 | *
|
---|
315 | * @returns VBox status code.
|
---|
316 | * @param pVM The VM to operate on.
|
---|
317 | */
|
---|
318 | PDMR3DECL(int) PDMR3Term(PVM pVM)
|
---|
319 | {
|
---|
320 | LogFlow(("PDMR3Term:\n"));
|
---|
321 | AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n"));
|
---|
322 |
|
---|
323 | /*
|
---|
324 | * Iterate the device instances.
|
---|
325 | * The attached drivers are processed first.
|
---|
326 | * N.B. There is no need to mess around freeing memory allocated
|
---|
327 | * from any MM heap since MM will do that in its Term function.
|
---|
328 | */
|
---|
329 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
330 | {
|
---|
331 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
|
---|
332 | {
|
---|
333 | /* Find the bottom driver. */
|
---|
334 | /** @todo Add pBottom to PDMLUN, this might not be the only place we will have to work it from the bottom up. */
|
---|
335 | PPDMDRVINS pDrvIns = pLun->pTop;
|
---|
336 | while (pDrvIns && pDrvIns->Internal.s.pDown)
|
---|
337 | pDrvIns = pDrvIns->Internal.s.pDown;
|
---|
338 |
|
---|
339 | /* And destroy them one at a time from the bottom up. */
|
---|
340 | while (pDrvIns)
|
---|
341 | {
|
---|
342 | PPDMDRVINS pDrvNext = pDrvIns->Internal.s.pUp;
|
---|
343 |
|
---|
344 | if (pDrvIns->pDrvReg->pfnDestruct)
|
---|
345 | {
|
---|
346 | LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
347 | pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
348 | pDrvIns->pDrvReg->pfnDestruct(pDrvIns);
|
---|
349 | TMR3TimerDestroyDriver(pVM, pDrvIns);
|
---|
350 | }
|
---|
351 |
|
---|
352 | pDrvIns = pDrvNext;
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (pDevIns->pDevReg->pfnDestruct)
|
---|
357 | {
|
---|
358 | LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
|
---|
359 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
360 | pDevIns->pDevReg->pfnDestruct(pDevIns);
|
---|
361 | TMR3TimerDestroyDevice(pVM, pDevIns);
|
---|
362 | pdmR3CritSectDeleteDevice(pVM, pDevIns);
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 | /*
|
---|
367 | * Destroy all threads.
|
---|
368 | */
|
---|
369 | pdmR3ThreadDestroyAll(pVM);
|
---|
370 |
|
---|
371 | /*
|
---|
372 | * Free modules.
|
---|
373 | */
|
---|
374 | pdmR3LdrTerm(pVM);
|
---|
375 |
|
---|
376 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
377 | /*
|
---|
378 | * Destroy the PDM lock.
|
---|
379 | */
|
---|
380 | PDMR3CritSectDelete(&pVM->pdm.s.CritSect);
|
---|
381 | #endif
|
---|
382 |
|
---|
383 | LogFlow(("PDMR3Term: returns %Vrc\n", VINF_SUCCESS));
|
---|
384 | return VINF_SUCCESS;
|
---|
385 | }
|
---|
386 |
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Execute state save operation.
|
---|
390 | *
|
---|
391 | * @returns VBox status code.
|
---|
392 | * @param pVM VM Handle.
|
---|
393 | * @param pSSM SSM operation handle.
|
---|
394 | */
|
---|
395 | static DECLCALLBACK(int) pdmR3Save(PVM pVM, PSSMHANDLE pSSM)
|
---|
396 | {
|
---|
397 | LogFlow(("pdmR3Save:\n"));
|
---|
398 |
|
---|
399 | /*
|
---|
400 | * Save interrupt and DMA states.
|
---|
401 | */
|
---|
402 | SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC));
|
---|
403 | SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC));
|
---|
404 | SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
|
---|
405 |
|
---|
406 | /*
|
---|
407 | * Save the list of device instances so we can check that
|
---|
408 | * they're all still there when we load the state and that
|
---|
409 | * nothing new have been added.
|
---|
410 | */
|
---|
411 | /** @todo We might have to filter out some device classes, like USB attached devices. */
|
---|
412 | uint32_t i = 0;
|
---|
413 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC, i++)
|
---|
414 | {
|
---|
415 | SSMR3PutU32(pSSM, i);
|
---|
416 | SSMR3PutStrZ(pSSM, pDevIns->pDevReg->szDeviceName);
|
---|
417 | SSMR3PutU32(pSSM, pDevIns->iInstance);
|
---|
418 | }
|
---|
419 | return SSMR3PutU32(pSSM, ~0); /* terminator */
|
---|
420 | }
|
---|
421 |
|
---|
422 |
|
---|
423 | /**
|
---|
424 | * Prepare state load operation.
|
---|
425 | *
|
---|
426 | * This will dispatch pending operations and clear the FFs governed by PDM and its devices.
|
---|
427 | *
|
---|
428 | * @returns VBox status code.
|
---|
429 | * @param pVM The VM handle.
|
---|
430 | * @param pSSM The SSM handle.
|
---|
431 | */
|
---|
432 | static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
|
---|
433 | {
|
---|
434 | LogFlow(("pdmR3LoadPrep: %s%s%s%s\n",
|
---|
435 | VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
|
---|
436 | VM_FF_ISSET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : "",
|
---|
437 | VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC) ? " VM_FF_INTERRUPT_APIC" : "",
|
---|
438 | VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC) ? " VM_FF_INTERRUPT_PIC" : ""
|
---|
439 | ));
|
---|
440 |
|
---|
441 | /*
|
---|
442 | * In case there is work pending that will raise an interrupt,
|
---|
443 | * start a DMA transfer, or release a lock. (unlikely)
|
---|
444 | */
|
---|
445 | if (VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES))
|
---|
446 | PDMR3QueueFlushAll(pVM);
|
---|
447 |
|
---|
448 | /* Clear the FFs. */
|
---|
449 | VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
|
---|
450 | VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
|
---|
451 | VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
|
---|
452 |
|
---|
453 | return VINF_SUCCESS;
|
---|
454 | }
|
---|
455 |
|
---|
456 |
|
---|
457 | /**
|
---|
458 | * Execute state load operation.
|
---|
459 | *
|
---|
460 | * @returns VBox status code.
|
---|
461 | * @param pVM VM Handle.
|
---|
462 | * @param pSSM SSM operation handle.
|
---|
463 | * @param u32Version Data layout version.
|
---|
464 | */
|
---|
465 | static DECLCALLBACK(int) pdmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
|
---|
466 | {
|
---|
467 | LogFlow(("pdmR3Load:\n"));
|
---|
468 |
|
---|
469 | /*
|
---|
470 | * Validate version.
|
---|
471 | */
|
---|
472 | if (u32Version != PDM_SAVED_STATE_VERSION)
|
---|
473 | {
|
---|
474 | Log(("pdmR3Load: Invalid version u32Version=%d!\n", u32Version));
|
---|
475 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
476 | }
|
---|
477 |
|
---|
478 | /*
|
---|
479 | * Load the interrupt and DMA states.
|
---|
480 | */
|
---|
481 | /* APIC interrupt */
|
---|
482 | RTUINT fInterruptPending = 0;
|
---|
483 | int rc = SSMR3GetUInt(pSSM, &fInterruptPending);
|
---|
484 | if (VBOX_FAILURE(rc))
|
---|
485 | return rc;
|
---|
486 | if (fInterruptPending & ~1)
|
---|
487 | {
|
---|
488 | AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
|
---|
489 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
490 | }
|
---|
491 | AssertRelease(!VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC));
|
---|
492 | if (fInterruptPending)
|
---|
493 | VM_FF_SET(pVM, VM_FF_INTERRUPT_APIC);
|
---|
494 |
|
---|
495 | /* PIC interrupt */
|
---|
496 | fInterruptPending = 0;
|
---|
497 | rc = SSMR3GetUInt(pSSM, &fInterruptPending);
|
---|
498 | if (VBOX_FAILURE(rc))
|
---|
499 | return rc;
|
---|
500 | if (fInterruptPending & ~1)
|
---|
501 | {
|
---|
502 | AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
|
---|
503 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
504 | }
|
---|
505 | AssertRelease(!VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC));
|
---|
506 | if (fInterruptPending)
|
---|
507 | VM_FF_SET(pVM, VM_FF_INTERRUPT_PIC);
|
---|
508 |
|
---|
509 | /* DMA pending */
|
---|
510 | RTUINT fDMAPending = 0;
|
---|
511 | rc = SSMR3GetUInt(pSSM, &fDMAPending);
|
---|
512 | if (VBOX_FAILURE(rc))
|
---|
513 | return rc;
|
---|
514 | if (fDMAPending & ~1)
|
---|
515 | {
|
---|
516 | AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
|
---|
517 | return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
|
---|
518 | }
|
---|
519 | AssertRelease(!VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
|
---|
520 | if (fDMAPending)
|
---|
521 | VM_FF_SET(pVM, VM_FF_PDM_DMA);
|
---|
522 |
|
---|
523 | /*
|
---|
524 | * Load the list of devices and verify that they are all there.
|
---|
525 | *
|
---|
526 | * We boldly ASSUME that the order is fixed and that it's a good, this
|
---|
527 | * makes it way easier to validate...
|
---|
528 | */
|
---|
529 | uint32_t i = 0;
|
---|
530 | PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances;
|
---|
531 | for (;;pDevIns = pDevIns->Internal.s.pNextHC, i++)
|
---|
532 | {
|
---|
533 | /* Get the separator / terminator. */
|
---|
534 | uint32_t u32Sep;
|
---|
535 | int rc = SSMR3GetU32(pSSM, &u32Sep);
|
---|
536 | if (VBOX_FAILURE(rc))
|
---|
537 | return rc;
|
---|
538 | if (u32Sep == (uint32_t)~0)
|
---|
539 | break;
|
---|
540 | if (u32Sep != i)
|
---|
541 | AssertMsgFailedReturn(("Out of seqence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
|
---|
542 |
|
---|
543 | /* get the name and instance number. */
|
---|
544 | char szDeviceName[sizeof(pDevIns->pDevReg->szDeviceName)];
|
---|
545 | rc = SSMR3GetStrZ(pSSM, szDeviceName, sizeof(szDeviceName));
|
---|
546 | if (VBOX_FAILURE(rc))
|
---|
547 | return rc;
|
---|
548 | RTUINT iInstance;
|
---|
549 | rc = SSMR3GetUInt(pSSM, &iInstance);
|
---|
550 | if (VBOX_FAILURE(rc))
|
---|
551 | return rc;
|
---|
552 |
|
---|
553 | /* compare */
|
---|
554 | if (!pDevIns)
|
---|
555 | {
|
---|
556 | LogRel(("Device '%s'/%d not found in current config\n", szDeviceName, iInstance));
|
---|
557 | if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
|
---|
558 | AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
|
---|
559 | break;
|
---|
560 | }
|
---|
561 | if ( strcmp(szDeviceName, pDevIns->pDevReg->szDeviceName)
|
---|
562 | || pDevIns->iInstance != iInstance)
|
---|
563 | {
|
---|
564 | LogRel(("u32Sep=%d loaded '%s'/%d configured '%s'/%d\n",
|
---|
565 | u32Sep, szDeviceName, iInstance, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
566 | if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
|
---|
567 | AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
|
---|
568 | }
|
---|
569 | }
|
---|
570 |
|
---|
571 | /*
|
---|
572 | * Too many devices?
|
---|
573 | */
|
---|
574 | if (pDevIns)
|
---|
575 | {
|
---|
576 | LogRel(("Device '%s'/%d not found in saved state\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
577 | if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
|
---|
578 | AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
|
---|
579 | }
|
---|
580 |
|
---|
581 | return VINF_SUCCESS;
|
---|
582 | }
|
---|
583 |
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * This function will notify all the devices and their
|
---|
587 | * attached drivers about the VM now being powered on.
|
---|
588 | *
|
---|
589 | * @param pVM VM Handle.
|
---|
590 | */
|
---|
591 | PDMR3DECL(void) PDMR3PowerOn(PVM pVM)
|
---|
592 | {
|
---|
593 | LogFlow(("PDMR3PowerOn:\n"));
|
---|
594 |
|
---|
595 | /*
|
---|
596 | * Iterate the device instances.
|
---|
597 | * The attached drivers are processed first.
|
---|
598 | */
|
---|
599 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
600 | {
|
---|
601 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
|
---|
602 | /** @todo Inverse the order here? */
|
---|
603 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
604 | if (pDrvIns->pDrvReg->pfnPowerOn)
|
---|
605 | {
|
---|
606 | LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
607 | pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
608 | pDrvIns->pDrvReg->pfnPowerOn(pDrvIns);
|
---|
609 | }
|
---|
610 |
|
---|
611 | if (pDevIns->pDevReg->pfnPowerOn)
|
---|
612 | {
|
---|
613 | LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
|
---|
614 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
615 | pDevIns->pDevReg->pfnPowerOn(pDevIns);
|
---|
616 | }
|
---|
617 | }
|
---|
618 |
|
---|
619 | /*
|
---|
620 | * Resume all threads.
|
---|
621 | */
|
---|
622 | pdmR3ThreadResumeAll(pVM);
|
---|
623 |
|
---|
624 | LogFlow(("PDMR3PowerOn: returns void\n"));
|
---|
625 | }
|
---|
626 |
|
---|
627 |
|
---|
628 |
|
---|
629 |
|
---|
630 | /**
|
---|
631 | * This function will notify all the devices and their
|
---|
632 | * attached drivers about the VM now being reset.
|
---|
633 | *
|
---|
634 | * @param pVM VM Handle.
|
---|
635 | */
|
---|
636 | PDMR3DECL(void) PDMR3Reset(PVM pVM)
|
---|
637 | {
|
---|
638 | LogFlow(("PDMR3Reset:\n"));
|
---|
639 |
|
---|
640 | /*
|
---|
641 | * Clear all pending interrupts and DMA operations.
|
---|
642 | */
|
---|
643 | VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
|
---|
644 | VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
|
---|
645 | VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
|
---|
646 |
|
---|
647 | /*
|
---|
648 | * Iterate the device instances.
|
---|
649 | * The attached drivers are processed first.
|
---|
650 | */
|
---|
651 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
652 | {
|
---|
653 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
|
---|
654 | /** @todo Inverse the order here? */
|
---|
655 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
656 | if (pDrvIns->pDrvReg->pfnReset)
|
---|
657 | {
|
---|
658 | LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
659 | pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
660 | pDrvIns->pDrvReg->pfnReset(pDrvIns);
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (pDevIns->pDevReg->pfnReset)
|
---|
664 | {
|
---|
665 | LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
|
---|
666 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
667 | pDevIns->pDevReg->pfnReset(pDevIns);
|
---|
668 | }
|
---|
669 | }
|
---|
670 |
|
---|
671 | LogFlow(("PDMR3Reset: returns void\n"));
|
---|
672 | }
|
---|
673 |
|
---|
674 |
|
---|
675 | /**
|
---|
676 | * This function will notify all the devices and their
|
---|
677 | * attached drivers about the VM now being reset.
|
---|
678 | *
|
---|
679 | * @param pVM VM Handle.
|
---|
680 | */
|
---|
681 | PDMR3DECL(void) PDMR3Suspend(PVM pVM)
|
---|
682 | {
|
---|
683 | LogFlow(("PDMR3Suspend:\n"));
|
---|
684 |
|
---|
685 | /*
|
---|
686 | * Iterate the device instances.
|
---|
687 | * The attached drivers are processed first.
|
---|
688 | */
|
---|
689 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
690 | {
|
---|
691 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
|
---|
692 | /** @todo Inverse the order here? */
|
---|
693 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
694 | if (pDrvIns->pDrvReg->pfnSuspend)
|
---|
695 | {
|
---|
696 | LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
697 | pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
698 | pDrvIns->pDrvReg->pfnSuspend(pDrvIns);
|
---|
699 | }
|
---|
700 |
|
---|
701 | if (pDevIns->pDevReg->pfnSuspend)
|
---|
702 | {
|
---|
703 | LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
|
---|
704 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
705 | pDevIns->pDevReg->pfnSuspend(pDevIns);
|
---|
706 | }
|
---|
707 | }
|
---|
708 |
|
---|
709 | /*
|
---|
710 | * Suspend all threads.
|
---|
711 | */
|
---|
712 | pdmR3ThreadSuspendAll(pVM);
|
---|
713 |
|
---|
714 | LogFlow(("PDMR3Suspend: returns void\n"));
|
---|
715 | }
|
---|
716 |
|
---|
717 |
|
---|
718 | /**
|
---|
719 | * This function will notify all the devices and their
|
---|
720 | * attached drivers about the VM now being resumed.
|
---|
721 | *
|
---|
722 | * @param pVM VM Handle.
|
---|
723 | */
|
---|
724 | PDMR3DECL(void) PDMR3Resume(PVM pVM)
|
---|
725 | {
|
---|
726 | LogFlow(("PDMR3Resume:\n"));
|
---|
727 |
|
---|
728 | /*
|
---|
729 | * Iterate the device instances.
|
---|
730 | * The attached drivers are processed first.
|
---|
731 | */
|
---|
732 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
733 | {
|
---|
734 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
|
---|
735 | /** @todo Inverse the order here? */
|
---|
736 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
737 | if (pDrvIns->pDrvReg->pfnResume)
|
---|
738 | {
|
---|
739 | LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
740 | pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
741 | pDrvIns->pDrvReg->pfnResume(pDrvIns);
|
---|
742 | }
|
---|
743 |
|
---|
744 | if (pDevIns->pDevReg->pfnResume)
|
---|
745 | {
|
---|
746 | LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
|
---|
747 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
748 | pDevIns->pDevReg->pfnResume(pDevIns);
|
---|
749 | }
|
---|
750 | }
|
---|
751 |
|
---|
752 | /*
|
---|
753 | * Resume all threads.
|
---|
754 | */
|
---|
755 | pdmR3ThreadResumeAll(pVM);
|
---|
756 |
|
---|
757 | LogFlow(("PDMR3Resume: returns void\n"));
|
---|
758 | }
|
---|
759 |
|
---|
760 |
|
---|
761 | /**
|
---|
762 | * This function will notify all the devices and their
|
---|
763 | * attached drivers about the VM being powered off.
|
---|
764 | *
|
---|
765 | * @param pVM VM Handle.
|
---|
766 | */
|
---|
767 | PDMR3DECL(void) PDMR3PowerOff(PVM pVM)
|
---|
768 | {
|
---|
769 | LogFlow(("PDMR3PowerOff:\n"));
|
---|
770 |
|
---|
771 | /*
|
---|
772 | * Iterate the device instances.
|
---|
773 | * The attached drivers are processed first.
|
---|
774 | */
|
---|
775 | for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
|
---|
776 | {
|
---|
777 | for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
|
---|
778 | /** @todo Inverse the order here? */
|
---|
779 | for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
|
---|
780 | if (pDrvIns->pDrvReg->pfnPowerOff)
|
---|
781 | {
|
---|
782 | LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
|
---|
783 | pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
784 | pDrvIns->pDrvReg->pfnPowerOff(pDrvIns);
|
---|
785 | }
|
---|
786 |
|
---|
787 | if (pDevIns->pDevReg->pfnPowerOff)
|
---|
788 | {
|
---|
789 | LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
|
---|
790 | pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
791 | pDevIns->pDevReg->pfnPowerOff(pDevIns);
|
---|
792 | }
|
---|
793 | }
|
---|
794 |
|
---|
795 | /*
|
---|
796 | * Suspend all threads.
|
---|
797 | */
|
---|
798 | pdmR3ThreadSuspendAll(pVM);
|
---|
799 |
|
---|
800 | LogFlow(("PDMR3PowerOff: returns void\n"));
|
---|
801 | }
|
---|
802 |
|
---|
803 |
|
---|
804 | /**
|
---|
805 | * Queries the base interace of a device instance.
|
---|
806 | *
|
---|
807 | * The caller can use this to query other interfaces the device implements
|
---|
808 | * and use them to talk to the device.
|
---|
809 | *
|
---|
810 | * @returns VBox status code.
|
---|
811 | * @param pVM VM handle.
|
---|
812 | * @param pszDevice Device name.
|
---|
813 | * @param iInstance Device instance.
|
---|
814 | * @param ppBase Where to store the pointer to the base device interface on success.
|
---|
815 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
816 | * device chain is known to be updated.
|
---|
817 | */
|
---|
818 | PDMR3DECL(int) PDMR3QueryDevice(PVM pVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
|
---|
819 | {
|
---|
820 | LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
|
---|
821 |
|
---|
822 | /*
|
---|
823 | * Iterate registered devices looking for the device.
|
---|
824 | */
|
---|
825 | RTUINT cchDevice = strlen(pszDevice);
|
---|
826 | for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext)
|
---|
827 | {
|
---|
828 | if ( pDev->cchName == cchDevice
|
---|
829 | && !memcmp(pDev->pDevReg->szDeviceName, pszDevice, cchDevice))
|
---|
830 | {
|
---|
831 | /*
|
---|
832 | * Iterate device instances.
|
---|
833 | */
|
---|
834 | for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextHC)
|
---|
835 | {
|
---|
836 | if (pDevIns->iInstance == iInstance)
|
---|
837 | {
|
---|
838 | if (pDevIns->IBase.pfnQueryInterface)
|
---|
839 | {
|
---|
840 | *ppBase = &pDevIns->IBase;
|
---|
841 | LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
|
---|
842 | return VINF_SUCCESS;
|
---|
843 | }
|
---|
844 |
|
---|
845 | LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
|
---|
846 | return VERR_PDM_DEVICE_INSTANCE_NO_IBASE;
|
---|
847 | }
|
---|
848 | }
|
---|
849 |
|
---|
850 | LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
|
---|
851 | return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND;
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 | LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
|
---|
856 | return VERR_PDM_DEVICE_NOT_FOUND;
|
---|
857 | }
|
---|
858 |
|
---|
859 |
|
---|
860 | /**
|
---|
861 | * Queries the base interface of a device LUN.
|
---|
862 | *
|
---|
863 | * This differs from PDMR3QueryLun by that it returns the interface on the
|
---|
864 | * device and not the top level driver.
|
---|
865 | *
|
---|
866 | * @returns VBox status code.
|
---|
867 | * @param pVM VM Handle.
|
---|
868 | * @param pszDevice Device name.
|
---|
869 | * @param iInstance Device instance.
|
---|
870 | * @param iLun The Logical Unit to obtain the interface of.
|
---|
871 | * @param ppBase Where to store the base interface pointer.
|
---|
872 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
873 | * device chain is known to be updated.
|
---|
874 | */
|
---|
875 | PDMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
|
---|
876 | {
|
---|
877 | LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
|
---|
878 | pszDevice, pszDevice, iInstance, iLun, ppBase));
|
---|
879 |
|
---|
880 | /*
|
---|
881 | * Find the LUN.
|
---|
882 | */
|
---|
883 | PPDMLUN pLun;
|
---|
884 | int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
|
---|
885 | if (VBOX_SUCCESS(rc))
|
---|
886 | {
|
---|
887 | *ppBase = pLun->pBase;
|
---|
888 | LogFlow(("PDMR3QueryDeviceLun: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
|
---|
889 | return VINF_SUCCESS;
|
---|
890 | }
|
---|
891 | LogFlow(("PDMR3QueryDeviceLun: returns %Vrc\n", rc));
|
---|
892 | return rc;
|
---|
893 | }
|
---|
894 |
|
---|
895 |
|
---|
896 | /**
|
---|
897 | * Query the interface of the top level driver on a LUN.
|
---|
898 | *
|
---|
899 | * @returns VBox status code.
|
---|
900 | * @param pVM VM Handle.
|
---|
901 | * @param pszDevice Device name.
|
---|
902 | * @param iInstance Device instance.
|
---|
903 | * @param iLun The Logical Unit to obtain the interface of.
|
---|
904 | * @param ppBase Where to store the base interface pointer.
|
---|
905 | * @remark We're not doing any locking ATM, so don't try call this at times when the
|
---|
906 | * device chain is known to be updated.
|
---|
907 | */
|
---|
908 | PDMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
|
---|
909 | {
|
---|
910 | LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
|
---|
911 | pszDevice, pszDevice, iInstance, iLun, ppBase));
|
---|
912 |
|
---|
913 | /*
|
---|
914 | * Find the LUN.
|
---|
915 | */
|
---|
916 | PPDMLUN pLun;
|
---|
917 | int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
|
---|
918 | if (VBOX_SUCCESS(rc))
|
---|
919 | {
|
---|
920 | if (pLun->pTop)
|
---|
921 | {
|
---|
922 | *ppBase = &pLun->pTop->IBase;
|
---|
923 | LogFlow(("PDMR3QueryLun: return %Vrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
|
---|
924 | return VINF_SUCCESS;
|
---|
925 | }
|
---|
926 | rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
|
---|
927 | }
|
---|
928 | LogFlow(("PDMR3QueryLun: returns %Vrc\n", rc));
|
---|
929 | return rc;
|
---|
930 | }
|
---|
931 |
|
---|
932 | /**
|
---|
933 | * Executes pending DMA transfers.
|
---|
934 | * Forced Action handler.
|
---|
935 | *
|
---|
936 | * @param pVM VM handle.
|
---|
937 | */
|
---|
938 | PDMR3DECL(void) PDMR3DmaRun(PVM pVM)
|
---|
939 | {
|
---|
940 | VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
|
---|
941 | if (pVM->pdm.s.pDmac)
|
---|
942 | {
|
---|
943 | bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns);
|
---|
944 | if (fMore)
|
---|
945 | VM_FF_SET(pVM, VM_FF_PDM_DMA);
|
---|
946 | }
|
---|
947 | }
|
---|
948 |
|
---|
949 |
|
---|
950 | /**
|
---|
951 | * Call polling function.
|
---|
952 | *
|
---|
953 | * @param pVM VM handle.
|
---|
954 | */
|
---|
955 | PDMR3DECL(void) PDMR3Poll(PVM pVM)
|
---|
956 | {
|
---|
957 | /* This is temporary hack and shall be removed ASAP! */
|
---|
958 | unsigned iPoller = pVM->pdm.s.cPollers;
|
---|
959 | if (iPoller)
|
---|
960 | {
|
---|
961 | while (iPoller-- > 0)
|
---|
962 | pVM->pdm.s.apfnPollers[iPoller](pVM->pdm.s.aDrvInsPollers[iPoller]);
|
---|
963 | TMTimerSetMillies(pVM->pdm.s.pTimerPollers, 3);
|
---|
964 | }
|
---|
965 | }
|
---|
966 |
|
---|
967 |
|
---|
968 | /**
|
---|
969 | * Internal timer callback function.
|
---|
970 | *
|
---|
971 | * @param pVM The VM.
|
---|
972 | * @param pTimer The timer handle.
|
---|
973 | * @param pvUser User argument specified upon timer creation.
|
---|
974 | */
|
---|
975 | static DECLCALLBACK(void) pdmR3PollerTimer(PVM pVM, PTMTIMER pTimer, void *pvUser)
|
---|
976 | {
|
---|
977 | PDMR3Poll(pVM);
|
---|
978 | }
|
---|
979 |
|
---|
980 |
|
---|
981 | /**
|
---|
982 | * Serivce a VMMCALLHOST_PDM_LOCK call.
|
---|
983 | *
|
---|
984 | * @returns VBox status code.
|
---|
985 | * @param pVM The VM handle.
|
---|
986 | */
|
---|
987 | PDMR3DECL(int) PDMR3LockCall(PVM pVM)
|
---|
988 | {
|
---|
989 | return pdmLockEx(pVM, VERR_INTERNAL_ERROR);
|
---|
990 | }
|
---|
991 |
|
---|