PDM.cpp revision e2b721de2492ed4f33cf02aa9e72f6e05b7c9a61
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * PDM - Pluggable Device Manager.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Copyright (C) 2006-2007 Sun Microsystems, Inc.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * This file is part of VirtualBox Open Source Edition (OSE), as
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * available from http://www.virtualbox.org. This file is free software;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * you can redistribute it and/or modify it under the terms of the GNU
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * General Public License (GPL) as published by the Free Software
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Foundation, in version 2 as it comes in the "COPYING" file of the
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * Clara, CA 95054 USA or visit http://www.sun.com if you need
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * additional information or have any questions.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/** @page pg_pdm PDM - The Pluggable Device & Driver Manager
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * VirtualBox is designed to be very configurable, i.e. the ability to select
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * virtual devices and configure them uniquely for a VM. For this reason
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * virtual devices are not statically linked with the VMM but loaded, linked and
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * instantiated at runtime by PDM using the information found in the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Configuration Manager (CFGM).
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * While the chief purpose of PDM is to manager of devices their drivers, it
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * also serves as somewhere to put usful things like cross context queues, cross
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * context synchronization (like critsect), VM centric thread management,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * asynchronous I/O framework, and so on.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @section sec_pdm_dev The Pluggable Devices
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Devices register themselves when the module containing them is loaded. PDM
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * will call the entry point 'VBoxDevicesRegister' when loading a device module.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The device module will then use the supplied callback table to check the VMM
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * version and to register its devices. Each device have an unique (for the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * configured VM) name. The name is not only used in PDM but also in CFGM (to
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * organize device and device instance settings) and by anyone who wants to talk
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * to a specific device instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * When all device modules have been successfully loaded PDM will instantiate
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * those devices which are configured for the VM. Note that a device may have
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * more than one instance, see network adaptors for instance. When
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * instantiating a device PDM provides device instance memory and a callback
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * table (aka Device Helpers / DevHlp) with the VM APIs which the device
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * instance is trusted with.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Some devices are trusted devices, most are not. The trusted devices are an
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * integrated part of the VM and can obtain the VM handle from their device
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * instance handles, thus enabling them to call any VM api. Untrusted devices
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * can only use the callbacks provided during device instantiation.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The main purpose in having DevHlps rather than just giving all the devices
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the VM handle and let them call the internal VM APIs directly, is both to
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * create a binary interface that can be supported accross releases and to
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * create a barrier between devices and the VM. (The trusted / untrusted bit
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * hasn't turned out to be of much use btw., but it's easy to maintain so there
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * isn't any point in removing it.)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * A device can provide a ring-0 and/or a raw-mode context extension to improve
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the VM performance by handling exits and traps (respectively) without
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * requiring context switches (to ring-3). Callbacks for MMIO and I/O ports can
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * needs to be registered specifically for the additional contexts for this to
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * make sense. Also, the device has to be trusted to be loaded into R0/RC
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * because of the extra privilege it entails. Note that raw-mode code and data
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * will be subject to relocation.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @section sec_pdm_special_devs Special Devices
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Several kinds of devices interacts with the VMM and/or other device and PDM
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * will work like a mediator for these. The typical pattern is that the device
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * calls a special registration device helper with a set of callbacks, PDM
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * responds by copying this and providing a pointer to a set helper callbacks
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * for that particular kind of device. Unlike interfaces where the callback
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * table pointer is used a 'this' pointer, these arrangements will use the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * device instance pointer (PPDMDEVINS) as a kind of 'this' pointer.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * For an example of this kind of setup, see the PIC. The PIC registers itself
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * by calling PDMDEVHLPR3::pfnPICRegister. PDM saves the device instance,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * copies the callback tables (PDMPICREG), resolving the ring-0 and raw-mode
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * addresses in the process, and hands back the pointer to a set of helper
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * methods (PDMPICHLPR3). The PCI device then queries the ring-0 and raw-mode
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * helpers using PDMPICHLPR3::pfnGetR0Helpers and PDMPICHLPR3::pfnGetRCHelpers.
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * The PCI device repeates ths pfnGetRCHelpers call in it's relocation method
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * since the address changes when RC is relocated.
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * @see grp_pdm_device
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @section sec_pdm_usbdev The Pluggable USB Devices
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * USB devices are handled a little bit differently than other devices. The
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * general concepts wrt. pluggability are mostly the same, but the details
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * varies. The registration entry point is 'VBoxUsbRegister', the device
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * instance is PDMUSBINS and the callbacks helpers are different. Also, USB
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * device are restricted to ring-3 and cannot have any ring-0 or raw-mode
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * extensions (at least not yet).
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The way USB devices work differs greatly from other devices though since they
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * aren't attaches directly to the PCI/ISA/whatever system buses but via a
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * USB host control (OHCI, UHCI or EHCI). USB devices handles USB requests
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * (URBs) and does not register I/O ports, MMIO ranges or PCI bus
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_usbdev
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @section sec_pdm_drv The Pluggable Drivers
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The VM devices are often accessing host hardware or OS facilities. For most
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * devices these facilities can be abstracted in one or more levels. These
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * abstractions are called drivers.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * For instance take a DVD/CD drive. This can be connected to a SCSI
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * controller, an ATA controller or a SATA controller. The basics of the DVD/CD
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * drive implementation remains the same - eject, insert, read, seek, and such.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * (For the scsi case, you might wanna speak SCSI directly to, but that can of
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * course be fixed - see SCSI passthru.) So, it
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * makes much sense to have a generic CD/DVD driver which implements this.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Then the media 'inserted' into the DVD/CD drive can be a ISO image, or it can
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * be read from a real CD or DVD drive (there are probably other custom formats
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * someone could desire to read or construct too). So, it would make sense to
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * have abstracted interfaces for dealing with this in a generic way so the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * cdrom unit doesn't have to implement it all. Thus we have created the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * CDROM/DVD media driver family.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * So, for this example the IDE controller #1 (i.e. secondary) will have
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the DVD/CD Driver attached to it's LUN #0 (master). When a media is mounted
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the DVD/CD Driver will have a ISO, HostDVD or RAW (media) Driver attached.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * It is possible to configure many levels of drivers inserting filters, loggers,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * or whatever you desire into the chain. We're using this for network sniffing
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * for instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The drivers are loaded in a similar manner to that of the device, namely by
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * iterating a keyspace in CFGM, load the modules listed there and call
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * 'VBoxDriversRegister' with a callback table.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_driver
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @section sec_pdm_ifs Interfaces
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The pluggable drivers and devices exposes one standard interface (callback
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * table) which is used to construct, destruct, attach, detach,( ++,) and query
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * other interfaces. A device will query the interfaces required for it's
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * operation during init and hot-plug. PDM may query some interfaces during
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * runtime mounting too.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * An interface here means a function table contained within the device or
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * driver instance data. Its method are invoked with the function table pointer
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * as the first argument and they will calculate the address of the device or
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * driver instance data from it. (This is one of the aspects which *might* have
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * been better done in C++.)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_interfaces
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @section sec_pdm_utils Utilities
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * As mentioned earlier, PDM is the location of any usful constrcts that doesn't
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * quite fit into IPRT. The next subsections will discuss these.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * One thing these APIs all have in common is that resources will be associated
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * with a device / driver and automatically freed after it has been destroyed if
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the destructor didn't do this.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @subsection sec_pdm_async_completion Async I/O
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The PDM Async I/O API provides a somewhat platform agnostic interface for
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * asynchronous I/O. For reasons of performance and complexcity this does not
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * build upon any IPRT API.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @todo more details.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_async_completion
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @subsection sec_pdm_async_task Async Task - not implemented
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @todo implement and describe
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_async_task
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @subsection sec_pdm_critsect Critical Section
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The PDM Critical Section API is currently building on the IPRT API with the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * same name. It adds the posibility to use critical sections in ring-0 and
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * raw-mode as well as in ring-3. There are certain restrictions on the RC and
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * R0 usage though since we're not able to wait on it, nor wake up anyone that
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * is waiting on it. These restrictions origins with the use of a ring-3 event
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * semaphore. In a later incarnation we plan to replace the ring-3 event
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * semaphore with a ring-0 one, thus enabling us to wake up waiters while
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * exectuing in ring-0 and making the hardware assisted execution mode more
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * efficient. (Raw-mode won't benefit much from this, naturally.)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_critsect
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @subsection sec_pdm_queue Queue
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The PDM Queue API is for queuing one or more tasks for later consumption in
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * ring-3 by EMT, and optinally forcing a delayed or ASAP return to ring-3. The
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * queues can also be run on a timer basis as an alternative to the ASAP thing.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The queue will be flushed at forced action time.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * A queue can also be used by another thread (a I/O worker for instance) to
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * send work / events over to the EMT.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_queue
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @subsection sec_pdm_task Task - not implemented yet
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The PDM Task API is for flagging a task for execution at a later point when
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * we're back in ring-3, optionally forcing the ring-3 return to happen ASAP.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * As you can see the concept is similar to queues only simpler.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * A task can also be scheduled by another thread (a I/O worker for instance) as
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * a mean of getting something done in EMT.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_task
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @subsection sec_pdm_thread Thread
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The PDM Thread API is there to help devices and drivers manage their threads
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * correctly wrt. power on, suspend, resume, power off and destruction.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The general usage pattern for threads in the employ of devices and drivers is
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * that they shuffle data or requests while the VM is running and stop doing
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * this when the VM is paused or powered down. Rogue threads running while the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * VM is paused can cause the state to change during saving or have other
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * unwanted side effects. The PDM Threads API ensures that this won't happen.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @see grp_pdm_thread
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*******************************************************************************
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore* Header Files *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore*******************************************************************************/
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*******************************************************************************
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore* Defined Constants And Macros *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore*******************************************************************************/
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/** The PDM saved state version. */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*******************************************************************************
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore* Internal Functions *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore*******************************************************************************/
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Initializes the PDM part of the UVM.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * This doesn't really do much right now but has to be here for the sake
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * of completeness.
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pUVM Pointer to the user mode VM structure.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertCompile(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Initializes the PDM.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM The VM to operate on.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Assert alignment and sizes.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(!(RT_OFFSETOF(VM, pdm.s) & 31));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(sizeof(pVM->pdm.s) <= sizeof(pVM->pdm.padding));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertCompileMemberAlignment(PDM, CritSect, sizeof(uintptr_t));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Init the structure.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Initialize sub compontents.
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi int rc = RTCritSectInit(&pVM->pdm.s.MiscCritSect);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, RT_SRC_POS, "PDM");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Register the saved state data unit.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rc = SSMR3RegisterInternal(pVM, "pdm", 1, PDM_SAVED_STATE_VERSION, 128,
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi LogFlow(("PDM: Successfully initialized\n"));
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * Cleanup and return failure.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Applies relocations to data and code managed by this
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * component. This function will be called at init and
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * whenever the VMM need to relocate it self inside the GC.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM VM handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param offDelta Relocation delta relative to old location.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * early in the relocation phase.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'AmoreVMMR3DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.pDevHlpQueueRC = PDMQueueRCPtr(pVM->pdm.s.pDevHlpQueueR3);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Critical sections.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The registered PIC.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.Pic.pfnGetInterruptRC += offDelta;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The registered APIC.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.Apic.pfnGetInterruptRC += offDelta;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.Apic.pfnBusDeliverRC += offDelta;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.Apic.pfnLocalInterruptRC += offDelta;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The registered I/O APIC.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * The register PCI Buses.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (unsigned i = 0; i < RT_ELEMENTS(pVM->pdm.s.aPciBuses); i++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.aPciBuses[i].pDevInsRC += offDelta;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pVM->pdm.s.aPciBuses[i].pfnSetIrqRC += offDelta;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDevHlp", &pDevHlpRC);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertReleaseMsgRC(rc, ("rc=%Rrc when resolving g_pdmRCDevHlp\n", rc));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->pvInstanceDataRC = MMHyperR3ToRC(pVM, pDevIns->pvInstanceDataR3);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->Internal.s.pPciBusRC = MMHyperR3ToRC(pVM, pDevIns->Internal.s.pPciBusR3);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->Internal.s.pPciDeviceRC = MMHyperR3ToRC(pVM, pDevIns->Internal.s.pPciDeviceR3);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->pReg->szDeviceName, pDevIns->iInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->pReg->pfnRelocate(pDevIns, offDelta);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Worker for pdmR3Term that terminates a LUN chain.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM Pointer to the shared VM structure.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pLun The head of the chain.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pszDevice The name of the device (for logging).
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param iInstance The device instance number (for logging).
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void pdmR3TermLuns(PVM pVM, PPDMLUN pLun, const char *pszDevice, unsigned iInstance)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Destroy them one at a time from the bottom up.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * (The serial device/drivers depends on this - bad.)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore PPDMDRVINS pDrvNext = pDrvIns->Internal.s.pUp;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDrvIns->pReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pszDevice, iInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore //PDMR3QueueDestroyDriver(pVM, pDrvIns);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore //pdmR3ThreadDestroyDriver(pVM, pDrvIns);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3DeregisterDriver(pVM, pDrvIns, NULL, 0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Terminates the PDM.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Termination means cleaning up and freeing all resources,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the VM it self is at this point powered off or suspended.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM The VM to operate on.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n"));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Iterate the device instances and attach drivers, doing
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * relevant destruction processing.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * N.B. There is no need to mess around freeing memory allocated
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * from any MM heap since MM will do that in its Term function.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* usb ones first. */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pdmR3TermLuns(pVM, pUsbIns->Internal.s.pLuns, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi //TMR3TimerDestroyUsb(pVM, pUsbIns);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi //SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi /* then the 'normal' ones. */
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi pdmR3TermLuns(pVM, pDevIns->Internal.s.pLunsR3, pDevIns->pReg->szDeviceName, pDevIns->iInstance);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi pDevIns->pReg->szDeviceName, pDevIns->iInstance));
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi //SSMR3DeregisterDriver(pVM, pDevIns, NULL, 0);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi //pdmR3ThreadDestroyDevice(pVM, pDevIns);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi //PDMR3QueueDestroyDevice(pVM, pDevIns);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi PGMR3PhysMMIO2Deregister(pVM, pDevIns, UINT32_MAX);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * Destroy all threads.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Free async completion managers.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Free modules.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Destroy the PDM lock.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* The MiscCritSect is deleted by PDMR3CritSectTerm. */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("PDMR3Term: returns %Rrc\n", VINF_SUCCESS));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Terminates the PDM part of the UVM.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * This will unload any modules left behind.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pUVM Pointer to the user mode VM structure.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * In the normal cause of events we will now call pdmR3LdrTermU for
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the second time. In the case of init failure however, this might
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * the first time, which is why we do it.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Bits that are saved in pass 0 and in the final pass.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM The VM handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pSSM The saved state handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void pdmR3SaveBoth(PVM pVM, PSSMHANDLE pSSM)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Save the list of device instances so we can check that they're all still
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * there when we load the state and that nothing new has been added.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3, i++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutStrZ(pSSM, pDevIns->pReg->szDeviceName);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutU32(pSSM, UINT32_MAX); /* terminator */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM The VM handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pSSM The saved state handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param uPass The pass.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertReturn(uPass == 0, VERR_INTERNAL_ERROR_4);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Execute state save operation.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM The VM handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pSSM The saved state handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3SaveExec(PVM pVM, PSSMHANDLE pSSM)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Save interrupt and DMA states.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_NMI));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutU32(pSSM, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_SMI));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore SSMR3PutU32(pSSM, VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Prepare state load operation.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * This will dispatch pending operations and clear the FFs governed by PDM and its devices.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM The VM handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pSSM The SSM handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VM_FF_ISSET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : ""));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("pdmR3LoadPrep: VCPU %u %s%s\n", idCpu,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC) ? " VMCPU_FF_INTERRUPT_APIC" : "",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC) ? " VMCPU_FF_INTERRUPT_PIC" : ""));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * In case there is work pending that will raise an interrupt,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * start a DMA transfer, or release a lock. (unlikely)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* Clear the FFs. */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Execute state load operation.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM VM Handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pSSM SSM operation handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param uVersion Data layout version.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param uPass The data pass.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic DECLCALLBACK(int) pdmR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("pdmR3LoadExec: uPass=%#x\n", uPass));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Validate version.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore && uVersion != PDM_SAVED_STATE_VERSION_PRE_NMI_FF)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailed(("Invalid version uVersion=%d!\n", uVersion));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Load the interrupt and DMA states.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* APIC interrupt */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* PIC interrupt */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (uVersion > PDM_SAVED_STATE_VERSION_PRE_NMI_FF)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* NMI interrupt */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailed(("fInterruptPending=%#x (NMI)\n", fInterruptPending));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_NMI));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* SMI interrupt */
b599bd937c305a895426e8c412ca920ce7824850Robert Mustacchi rc = SSMR3GetU32(pSSM, &fInterruptPending);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailed(("fInterruptPending=%#x (SMI)\n", fInterruptPending));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertRelease(!VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_SMI));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* DMA pending */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore Log(("pdmR3LoadExec: VM_FF_PDM_DMA=%RTbool\n", VM_FF_ISSET(pVM, VM_FF_PDM_DMA)));
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * Load the list of devices and verify that they are all there.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_FOUND;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (uint32_t i = 0; ; i++)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* Get the sequence number / terminator. */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore AssertMsgFailedReturn(("Out of seqence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* Get the name and instance number. */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char szDeviceName[RT_SIZEOFMEMB(PDMDEVREG, szDeviceName)];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rc = SSMR3GetStrZ(pSSM, szDeviceName, sizeof(szDeviceName));
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi /* Try locate it. */
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi for (pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if ( !strcmp(szDeviceName, pDevIns->pReg->szDeviceName)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi AssertLogRelMsgReturn(!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND),
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi ("%s/#%u\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance),
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_FOUND;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogRel(("Device '%s'/%d not found in current config\n", szDeviceName, iInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in current config"), szDeviceName, iInstance);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Check that no additional devices were configured.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND))
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogRel(("Device '%s'/%d not found in the saved state\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in the saved state"),
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->pReg->szDeviceName, pDevIns->iInstance);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Worker for PDMR3PowerOn that deals with one driver.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pDrvIns The driver instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pszDeviceName The parent device name.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param iDevInstance The parent device instance number.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param iLun The parent LUN number.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'AmoreDECLINLINE(int) pdmR3PowerOnDrv(PPDMDRVINS pDrvIns, const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDrvIns->pReg->szDriverName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int rc = VINF_SUCCESS; pDrvIns->pReg->pfnPowerOn(pDrvIns);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogRel(("PDMR3PowerOn: driver '%s'/%d on LUN#%d of device '%s'/%d -> %Rrc\n",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDrvIns->pReg->szDriverName, pDrvIns->iInstance, iLun, pszDeviceName, iDevInstance, rc));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Worker for PDMR3PowerOn that deals with one USB device instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pUsbIns The USB device instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'AmoreDECLINLINE(int) pdmR3PowerOnUsb(PPDMUSBINS pUsbIns)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int rc = VINF_SUCCESS; pUsbIns->pUsbReg->pfnVMPowerOn(pUsbIns);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogRel(("PDMR3PowerOn: device '%s'/%d -> %Rrc\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance, rc));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Worker for PDMR3PowerOn that deals with one device instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @returns VBox status code.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pDevIns The device instance.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'AmoreDECLINLINE(int) pdmR3PowerOnDev(PPDMDEVINS pDevIns)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore Assert(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_SUSPENDED);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int rc = VINF_SUCCESS; pDevIns->pReg->pfnPowerOn(pDevIns);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore LogRel(("PDMR3PowerOn: device '%s'/%d -> %Rrc\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance, rc));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_SUSPENDED;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * This function will notify all the devices and their
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * attached drivers about the VM now being powered on.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * @param pVM VM Handle.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Iterate thru the device instances and USB device instances,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * processing the drivers associated with those.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rc = pdmR3PowerOnDrv(pDrvIns, pDevIns->pReg->szDeviceName, pDevIns->iInstance, pLun->iLun);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi rc = pdmR3PowerOnDrv(pDrvIns, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance, pLun->iLun);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Resume all threads.
(*pcAsync)++;
LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
(*pcAsync)++;
LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogFlow(("PDMR3Reset: Async notification started - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogFlow(("PDMR3Reset: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
(*pcAsync)++;
#ifdef VBOX_WITH_USB
unsigned cAsync;
cAsync = 0;
#ifdef VBOX_WITH_USB
if (!pdmR3ResetDrv(pDrvIns, &cAsync, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance, pLun->iLun))
if (!cAsync)
LogFlow(("PDMR3Suspend: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
(*pcAsync)++;
LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogFlow(("PDMR3Suspend: Async notification started - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogFlow(("PDMR3Suspend: Async notification completed - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
(*pcAsync)++;
LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogFlow(("PDMR3Suspend: Async notification started - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogFlow(("PDMR3Suspend: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
(*pcAsync)++;
unsigned cAsync;
cAsync = 0;
if (!pdmR3SuspendDrv(pDrvIns, &cAsync, pDevIns->pReg->szDeviceName, pDevIns->iInstance, pLun->iLun))
#ifdef VBOX_WITH_USB
if (!pdmR3SuspendDrv(pDrvIns, &cAsync, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance, pLun->iLun))
if (!cAsync)
DECLINLINE(int) pdmR3ResumeDrv(PPDMDRVINS pDrvIns, const char *pszDeviceName, uint32_t iDevInstance, uint32_t iLun)
return rc;
return VINF_SUCCESS;
LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogRel(("PDMR3Resume: device '%s'/%d -> %Rrc\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance, rc));
return rc;
return VINF_SUCCESS;
LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogRel(("PDMR3Resume: device '%s'/%d -> %Rrc\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance, rc));
return rc;
return VINF_SUCCESS;
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
#ifdef VBOX_WITH_USB
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown)
LogFlow(("PDMR3PowerOff: Async notification started - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
LogFlow(("PDMR3PowerOff: Async notification completed - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
(*pcAsync)++;
LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogFlow(("PDMR3PowerOff: Async notification started - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
LogFlow(("PDMR3PowerOff: Async notification completed - device '%s'/%d\n", pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
(*pcAsync)++;
LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogFlow(("PDMR3PowerOff: Async notification started - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
LogFlow(("PDMR3PowerOff: Async notification completed - device '%s'/%d\n", pDevIns->pReg->szDeviceName, pDevIns->iInstance));
(*pcAsync)++;
unsigned cAsync;
cAsync = 0;
if (!pdmR3PowerOffDrv(pDrvIns, &cAsync, pDevIns->pReg->szDeviceName, pDevIns->iInstance, pLun->iLun))
#ifdef VBOX_WITH_USB
if (!pdmR3PowerOffDrv(pDrvIns, &cAsync, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance, pLun->iLun))
if (!cAsync)
VMMR3DECL(int) PDMR3QueryDevice(PVM pVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextR3)
return VINF_SUCCESS;
return VERR_PDM_DEVICE_NOT_FOUND;
VMMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
return VINF_SUCCESS;
return rc;
VMMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
return VINF_SUCCESS;
return rc;
if (fMore)
return VINF_SUCCESS;
return VINF_SUCCESS;
#ifdef DEBUG_bird
return VERR_NO_MEMORY;
return VINF_SUCCESS;
return VINF_SUCCESS;