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