PDM.cpp revision 7521bd76d764c3c9534c162e2a37fefb446f2071
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/* $Id$ */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/** @file
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * PDM - Pluggable Device Manager.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/*
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * available from http://www.virtualbox.org. This file is free software;
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * you can redistribute it and/or modify it under the terms of the GNU
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * General Public License (GPL) as published by the Free Software
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync *
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * additional information or have any questions.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync */
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/** @page pg_pdm PDM - The Pluggable Device Manager
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * VBox is designed to be very configurable, i.e. the ability to select
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * virtual devices and configure them uniquely for a VM. For this reason
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * virtual devices are not statically linked with the VMM but loaded and
0c437bb10c61b229407a7517efde04dfe3b1e4a1vboxsync * linked at runtime thru the Configuration Manager (CFGM). PDM will use
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * CFGM to enumerate devices which needs loading and instantiation.
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync *
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync *
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * @section sec_pdm_dev The Pluggable Device
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Devices register themselves when the module containing them is loaded.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * PDM will call an entry point 'VBoxDevicesRegister' when loading a device
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * module. The device module will then use the supplied callback table to
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * check the VMM version and to register its devices. Each device have an
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * unique (for the configured VM) name (string). The name is not only used
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * in PDM but in CFGM - to organize device and device instance settings - and
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * by anyone who wants to do ioctls to the device.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * When all device modules have been successfully loaded PDM will instantiate
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * those devices which are configured for the VM. Mark that this might mean
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * creating several instances of some devices. When instantiating a device
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * PDM provides device instance memory and a callback table with the VM APIs
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * which the device instance is trusted with.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Some devices are trusted devices, most are not. The trusted devices are
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * an integrated part of the VM and can obtain the VM handle from their
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * device instance handles, thus enabling them to call any VM api. Untrusted
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * devices are can only use the callbacks provided during device
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * instantiation.
0493c79a1867f7760af6bc330c8c42a09da852abvboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * The guest context extention (optional) of a device is initialized as part
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * of the GC init. A device marks in it's registration structure that it have
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * a GC part, in which module and which name the entry point have. PDM will
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * use its loader facilities to load this module into GC and to find the
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * specified entry point.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * When writing a GC extention the programmer must keep in mind that this
22ec733a5e041fcdfe02fce2eafc9faf8b0077ddvboxsync * code will be relocated, so that using global/static pointer variables
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * won't work.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @section sec_pdm_drv The Pluggable Drivers
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * The VM devices are often accessing host hardware or OS facilities. For
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * most devices these facilities can be abstracted in one or more levels.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * These abstractions are called drivers.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * For instance take a DVD/CD drive. This can be connected to a SCSI
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * controller, EIDE controller or SATA controller. The basics of the
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * DVD/CD drive implementation remains the same - eject, insert,
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * read, seek, and such. (For the scsi case, you might wanna speak SCSI
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * directly to, but that can of course be fixed.) So, it makes much sense to
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * have a generic CD/DVD driver which implements this.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Then the media 'inserted' into the DVD/CD drive can be a ISO image, or
230bd8589bba39933ac5ec21482d6186d675e604vboxsync * it can be read from a real CD or DVD drive (there are probably other
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * custom formats someone could desire to read or construct too). So, it
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * would make sense to have abstracted interfaces for dealing with this
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * in a generic way so the cdrom unit doesn't have to implement it all.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Thus we have created the CDROM/DVD media driver family.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * So, for this example the IDE controller #1 (i.e. secondary) will have
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * the DVD/CD Driver attached to it's LUN #0 (master). When a media is mounted
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * the DVD/CD Driver will have a ISO, NativeCD, NativeDVD or RAW (media) Driver
230bd8589bba39933ac5ec21482d6186d675e604vboxsync * attached.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * It is possible to configure many levels of drivers inserting filters, loggers,
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * or whatever you desire into the chain.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @subsection sec_pdm_drv_interfaces Interfaces
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * The pluggable drivers exposes one standard interface (callback table) which
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * is used to construct, destruct, attach, detach, and query other interfaces.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * A device will query the interfaces required for it's operation during init
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * and hotplug. PDM will query some interfaces during runtime mounting too.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * ... list interfaces ...
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/*******************************************************************************
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync* Header Files *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync*******************************************************************************/
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#define LOG_GROUP LOG_GROUP_PDM
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include "PDMInternal.h"
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync#include <VBox/pdm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/mm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/pgm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/ssm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/vm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/uvm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/vmm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/param.h>
b4fc07ae3f394595370fc5ed6ab1c353a87259dbvboxsync#include <VBox/err.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/sup.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <VBox/log.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <iprt/asm.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <iprt/assert.h>
b4fc07ae3f394595370fc5ed6ab1c353a87259dbvboxsync#include <iprt/alloc.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <iprt/ldr.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <iprt/path.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#include <iprt/string.h>
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
8bed792bc65abd39393889351f22263ce6c289bfvboxsync/*******************************************************************************
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync* Defined Constants And Macros *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync*******************************************************************************/
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/** The PDM saved state version. */
b4fc07ae3f394595370fc5ed6ab1c353a87259dbvboxsync#define PDM_SAVED_STATE_VERSION 3
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/*******************************************************************************
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync* Internal Functions *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync*******************************************************************************/
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncstatic DECLCALLBACK(int) pdmR3Save(PVM pVM, PSSMHANDLE pSSM);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncstatic DECLCALLBACK(int) pdmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncstatic DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncstatic DECLCALLBACK(void) pdmR3PollerTimer(PVM pVM, PTMTIMER pTimer, void *pvUser);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/**
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Initializes the PDM part of the UVM.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * This doesn't really do much right now but has to be here for the sake
9ee436b6765f11cddb90819b9c4fc67899ba479bvboxsync * of completeness.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync *
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * @returns VBox status code.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pUVM Pointer to the user mode VM structure.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncPDMR3DECL(int) PDMR3InitUVM(PUVM pUVM)
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync{
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync AssertCompile(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync AssertRelease(sizeof(pUVM->pdm.s) <= sizeof(pUVM->pdm.padding));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync pUVM->pdm.s.pModules = NULL;
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync return VINF_SUCCESS;
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync}
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/**
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * Initializes the PDM.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync *
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * @returns VBox status code.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * @param pVM The VM to operate on.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncPDMR3DECL(int) PDMR3Init(PVM pVM)
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync{
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync LogFlow(("PDMR3Init\n"));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync /*
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync * Assert alignment and sizes.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync AssertRelease(!(RT_OFFSETOF(VM, pdm.s) & 31));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync AssertRelease(sizeof(pVM->pdm.s) <= sizeof(pVM->pdm.padding));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync /*
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Init the structure.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync pVM->pdm.s.offVM = RT_OFFSETOF(VM, pdm.s);
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync int rc = TMR3TimerCreateInternal(pVM, TMCLOCK_VIRTUAL, pdmR3PollerTimer, NULL, "PDM Poller", &pVM->pdm.s.pTimerPollers);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync AssertRC(rc);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /*
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Initialize sub compontents.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync rc = pdmR3CritSectInit(pVM);
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync if (VBOX_SUCCESS(rc))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync {
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, "PDM");
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync if (VBOX_SUCCESS(rc))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync rc = pdmR3LdrInitU(pVM->pUVM);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync if (VBOX_SUCCESS(rc))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync {
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync rc = pdmR3DrvInit(pVM);
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync if (VBOX_SUCCESS(rc))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync {
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync rc = pdmR3DevInit(pVM);
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync if (VBOX_SUCCESS(rc))
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync {
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync rc = pdmR3AsyncCompletionInit(pVM);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync if (VBOX_SUCCESS(rc))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync#endif
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync {
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /*
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Register the saved state data unit.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync rc = SSMR3RegisterInternal(pVM, "pdm", 1, PDM_SAVED_STATE_VERSION, 128,
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync NULL, pdmR3Save, NULL,
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync pdmR3LoadPrep, pdmR3Load, NULL);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync if (VBOX_SUCCESS(rc))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync {
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync LogFlow(("PDM: Successfully initialized\n"));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync return rc;
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync }
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync }
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync }
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync }
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync }
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync }
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /*
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Cleanup and return failure.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync PDMR3Term(pVM);
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync LogFlow(("PDMR3Init: returns %Vrc\n", rc));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync return rc;
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync}
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/**
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Applies relocations to data and code managed by this
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * component. This function will be called at init and
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * whenever the VMM need to relocate it self inside the GC.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pVM VM handle.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param offDelta Relocation delta relative to old location.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * early in the relocation phase.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsyncPDMR3DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync{
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync LogFlow(("PDMR3Relocate\n"));
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /*
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Queues.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync pdmR3QueueRelocate(pVM, offDelta);
pVM->pdm.s.pDevHlpQueueGC = PDMQueueGCPtr(pVM->pdm.s.pDevHlpQueueHC);
/*
* Critical sections.
*/
pdmR3CritSectRelocate(pVM);
/*
* The registered PIC.
*/
if (pVM->pdm.s.Pic.pDevInsGC)
{
pVM->pdm.s.Pic.pDevInsGC += offDelta;
pVM->pdm.s.Pic.pfnSetIrqGC += offDelta;
pVM->pdm.s.Pic.pfnGetInterruptGC += offDelta;
}
/*
* The registered APIC.
*/
if (pVM->pdm.s.Apic.pDevInsRC)
{
pVM->pdm.s.Apic.pDevInsRC += offDelta;
pVM->pdm.s.Apic.pfnGetInterruptRC += offDelta;
pVM->pdm.s.Apic.pfnSetBaseRC += offDelta;
pVM->pdm.s.Apic.pfnGetBaseRC += offDelta;
pVM->pdm.s.Apic.pfnSetTPRRC += offDelta;
pVM->pdm.s.Apic.pfnGetTPRRC += offDelta;
pVM->pdm.s.Apic.pfnBusDeliverRC += offDelta;
}
/*
* The registered I/O APIC.
*/
if (pVM->pdm.s.IoApic.pDevInsRC)
{
pVM->pdm.s.IoApic.pDevInsRC += offDelta;
pVM->pdm.s.IoApic.pfnSetIrqRC += offDelta;
}
/*
* The register PCI Buses.
*/
for (unsigned i = 0; i < ELEMENTS(pVM->pdm.s.aPciBuses); i++)
{
if (pVM->pdm.s.aPciBuses[i].pDevInsGC)
{
pVM->pdm.s.aPciBuses[i].pDevInsGC += offDelta;
pVM->pdm.s.aPciBuses[i].pfnSetIrqGC += offDelta;
}
}
/*
* Devices.
*/
RCPTRTYPE(PCPDMDEVHLPGC) pDevHlpGC;
int rc = PDMR3GetSymbolGC(pVM, NULL, "g_pdmGCDevHlp", &pDevHlpGC);
AssertReleaseMsgRC(rc, ("rc=%Vrc when resolving g_pdmGCDevHlp\n", rc));
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
if (pDevIns->pDevReg->fFlags & PDM_DEVREG_FLAGS_GC)
{
pDevIns->pDevHlpGC = pDevHlpGC;
pDevIns->pvInstanceDataGC = MMHyperR3ToGC(pVM, pDevIns->pvInstanceDataR3);
pDevIns->pvInstanceDataR0 = MMHyperR3ToR0(pVM, pDevIns->pvInstanceDataR3);
pDevIns->Internal.s.pVMGC = pVM->pVMGC;
if (pDevIns->Internal.s.pPciBusHC)
pDevIns->Internal.s.pPciBusGC = MMHyperR3ToGC(pVM, pDevIns->Internal.s.pPciBusHC);
if (pDevIns->Internal.s.pPciDeviceHC)
pDevIns->Internal.s.pPciDeviceGC = MMHyperR3ToGC(pVM, pDevIns->Internal.s.pPciDeviceHC);
if (pDevIns->pDevReg->pfnRelocate)
{
LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnRelocate(pDevIns, offDelta);
}
}
}
}
/**
* Worker for pdmR3Term that terminates a LUN chain.
*
* @param pVM Pointer to the shared VM structure.
* @param pLun The head of the chain.
* @param pszDevice The name of the device (for logging).
* @param iInstance The device instance number (for logging).
*/
static void pdmR3TermLuns(PVM pVM, PPDMLUN pLun, const char *pszDevice, unsigned iInstance)
{
for (; pLun; pLun = pLun->pNext)
{
/*
* Destroy them one at a time from the bottom up.
* (The serial device/drivers depends on this - bad.)
*/
PPDMDRVINS pDrvIns = pLun->pBottom;
pLun->pBottom = pLun->pTop = NULL;
while (pDrvIns)
{
PPDMDRVINS pDrvNext = pDrvIns->Internal.s.pUp;
if (pDrvIns->pDrvReg->pfnDestruct)
{
LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pszDevice, iInstance));
pDrvIns->pDrvReg->pfnDestruct(pDrvIns);
}
TMR3TimerDestroyDriver(pVM, pDrvIns);
//PDMR3QueueDestroyDriver(pVM, pDrvIns);
//pdmR3ThreadDestroyDriver(pVM, pDrvIns);
SSMR3DeregisterDriver(pVM, pDrvIns, NULL, 0);
pDrvIns = pDrvNext;
}
}
}
/**
* Terminates the PDM.
*
* Termination means cleaning up and freeing all resources,
* the VM it self is at this point powered off or suspended.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
PDMR3DECL(int) PDMR3Term(PVM pVM)
{
LogFlow(("PDMR3Term:\n"));
AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n"));
/*
* Iterate the device instances and attach drivers, doing
* relevant destruction processing.
*
* N.B. There is no need to mess around freeing memory allocated
* from any MM heap since MM will do that in its Term function.
*/
/* usb ones first. */
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
{
pdmR3TermLuns(pVM, pUsbIns->Internal.s.pLuns, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance);
if (pUsbIns->pUsbReg->pfnDestruct)
{
LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pUsbIns->pUsbReg->pfnDestruct(pUsbIns);
}
//TMR3TimerDestroyUsb(pVM, pUsbIns);
//SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
pdmR3ThreadDestroyUsb(pVM, pUsbIns);
}
/* then the 'normal' ones. */
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
pdmR3TermLuns(pVM, pDevIns->Internal.s.pLunsHC, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance);
if (pDevIns->pDevReg->pfnDestruct)
{
LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnDestruct(pDevIns);
}
TMR3TimerDestroyDevice(pVM, pDevIns);
//SSMR3DeregisterDriver(pVM, pDevIns, NULL, 0);
pdmR3CritSectDeleteDevice(pVM, pDevIns);
//pdmR3ThreadDestroyDevice(pVM, pDevIns);
//PDMR3QueueDestroyDevice(pVM, pDevIns);
PGMR3PhysMMIO2Deregister(pVM, pDevIns, UINT32_MAX);
}
/*
* Destroy all threads.
*/
pdmR3ThreadDestroyAll(pVM);
#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
/*
* Free async completion managers.
*/
pdmR3AsyncCompletionTerm(pVM);
#endif
/*
* Free modules.
*/
pdmR3LdrTermU(pVM->pUVM);
/*
* Destroy the PDM lock.
*/
PDMR3CritSectDelete(&pVM->pdm.s.CritSect);
LogFlow(("PDMR3Term: returns %Vrc\n", VINF_SUCCESS));
return VINF_SUCCESS;
}
/**
* Terminates the PDM part of the UVM.
*
* This will unload any modules left behind.
*
* @param pUVM Pointer to the user mode VM structure.
*/
PDMR3DECL(void) PDMR3TermUVM(PUVM pUVM)
{
/*
* In the normal cause of events we will now call pdmR3LdrTermU for
* the second time. In the case of init failure however, this might
* the first time, which is why we do it.
*/
pdmR3LdrTermU(pUVM);
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
static DECLCALLBACK(int) pdmR3Save(PVM pVM, PSSMHANDLE pSSM)
{
LogFlow(("pdmR3Save:\n"));
/*
* Save interrupt and DMA states.
*/
SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC));
SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC));
SSMR3PutUInt(pSSM, VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
/*
* Save the list of device instances so we can check that
* they're all still there when we load the state and that
* nothing new have been added.
*/
/** @todo We might have to filter out some device classes, like USB attached devices. */
uint32_t i = 0;
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC, i++)
{
SSMR3PutU32(pSSM, i);
SSMR3PutStrZ(pSSM, pDevIns->pDevReg->szDeviceName);
SSMR3PutU32(pSSM, pDevIns->iInstance);
}
return SSMR3PutU32(pSSM, ~0); /* terminator */
}
/**
* Prepare state load operation.
*
* This will dispatch pending operations and clear the FFs governed by PDM and its devices.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
*/
static DECLCALLBACK(int) pdmR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
{
LogFlow(("pdmR3LoadPrep: %s%s%s%s\n",
VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES) ? " VM_FF_PDM_QUEUES" : "",
VM_FF_ISSET(pVM, VM_FF_PDM_DMA) ? " VM_FF_PDM_DMA" : "",
VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC) ? " VM_FF_INTERRUPT_APIC" : "",
VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC) ? " VM_FF_INTERRUPT_PIC" : ""
));
/*
* In case there is work pending that will raise an interrupt,
* start a DMA transfer, or release a lock. (unlikely)
*/
if (VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES))
PDMR3QueueFlushAll(pVM);
/* Clear the FFs. */
VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
return VINF_SUCCESS;
}
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @param u32Version Data layout version.
*/
static DECLCALLBACK(int) pdmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
{
LogFlow(("pdmR3Load:\n"));
/*
* Validate version.
*/
if (u32Version != PDM_SAVED_STATE_VERSION)
{
Log(("pdmR3Load: Invalid version u32Version=%d!\n", u32Version));
return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
}
/*
* Load the interrupt and DMA states.
*/
/* APIC interrupt */
RTUINT fInterruptPending = 0;
int rc = SSMR3GetUInt(pSSM, &fInterruptPending);
if (VBOX_FAILURE(rc))
return rc;
if (fInterruptPending & ~1)
{
AssertMsgFailed(("fInterruptPending=%#x (APIC)\n", fInterruptPending));
return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
}
AssertRelease(!VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC));
if (fInterruptPending)
VM_FF_SET(pVM, VM_FF_INTERRUPT_APIC);
/* PIC interrupt */
fInterruptPending = 0;
rc = SSMR3GetUInt(pSSM, &fInterruptPending);
if (VBOX_FAILURE(rc))
return rc;
if (fInterruptPending & ~1)
{
AssertMsgFailed(("fInterruptPending=%#x (PIC)\n", fInterruptPending));
return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
}
AssertRelease(!VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC));
if (fInterruptPending)
VM_FF_SET(pVM, VM_FF_INTERRUPT_PIC);
/* DMA pending */
RTUINT fDMAPending = 0;
rc = SSMR3GetUInt(pSSM, &fDMAPending);
if (VBOX_FAILURE(rc))
return rc;
if (fDMAPending & ~1)
{
AssertMsgFailed(("fDMAPending=%#x\n", fDMAPending));
return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
}
AssertRelease(!VM_FF_ISSET(pVM, VM_FF_PDM_DMA));
if (fDMAPending)
VM_FF_SET(pVM, VM_FF_PDM_DMA);
/*
* Load the list of devices and verify that they are all there.
*
* We boldly ASSUME that the order is fixed and that it's a good, this
* makes it way easier to validate...
*/
uint32_t i = 0;
PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances;
for (;;pDevIns = pDevIns->Internal.s.pNextHC, i++)
{
/* Get the separator / terminator. */
uint32_t u32Sep;
int rc = SSMR3GetU32(pSSM, &u32Sep);
if (VBOX_FAILURE(rc))
return rc;
if (u32Sep == (uint32_t)~0)
break;
if (u32Sep != i)
AssertMsgFailedReturn(("Out of seqence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
/* get the name and instance number. */
char szDeviceName[sizeof(pDevIns->pDevReg->szDeviceName)];
rc = SSMR3GetStrZ(pSSM, szDeviceName, sizeof(szDeviceName));
if (VBOX_FAILURE(rc))
return rc;
RTUINT iInstance;
rc = SSMR3GetUInt(pSSM, &iInstance);
if (VBOX_FAILURE(rc))
return rc;
/* compare */
if (!pDevIns)
{
LogRel(("Device '%s'/%d not found in current config\n", szDeviceName, iInstance));
if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
break;
}
if ( strcmp(szDeviceName, pDevIns->pDevReg->szDeviceName)
|| pDevIns->iInstance != iInstance)
{
LogRel(("u32Sep=%d loaded '%s'/%d configured '%s'/%d\n",
u32Sep, szDeviceName, iInstance, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
}
}
/*
* Too many devices?
*/
if (pDevIns)
{
LogRel(("Device '%s'/%d not found in saved state\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
AssertFailedReturn(VERR_SSM_LOAD_CONFIG_MISMATCH);
}
return VINF_SUCCESS;
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being powered on.
*
* @param pVM VM Handle.
*/
PDMR3DECL(void) PDMR3PowerOn(PVM pVM)
{
LogFlow(("PDMR3PowerOn:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
/** @todo Inverse the order here? */
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnPowerOn)
{
LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDrvIns->pDrvReg->pfnPowerOn(pDrvIns);
}
if (pDevIns->pDevReg->pfnPowerOn)
{
LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnPowerOn(pDevIns);
}
}
#ifdef VBOX_WITH_USB
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
{
for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnPowerOn)
{
LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pDrvIns->pDrvReg->pfnPowerOn(pDrvIns);
}
if (pUsbIns->pUsbReg->pfnVMPowerOn)
{
LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pUsbIns->pUsbReg->pfnVMPowerOn(pUsbIns);
}
}
#endif
/*
* Resume all threads.
*/
pdmR3ThreadResumeAll(pVM);
LogFlow(("PDMR3PowerOn: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being reset.
*
* @param pVM VM Handle.
*/
PDMR3DECL(void) PDMR3Reset(PVM pVM)
{
LogFlow(("PDMR3Reset:\n"));
/*
* Clear all pending interrupts and DMA operations.
*/
VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
/** @todo Inverse the order here? */
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnReset)
{
LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDrvIns->pDrvReg->pfnReset(pDrvIns);
}
if (pDevIns->pDevReg->pfnReset)
{
LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnReset(pDevIns);
}
}
#ifdef VBOX_WITH_USB
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
{
for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnReset)
{
LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pDrvIns->pDrvReg->pfnReset(pDrvIns);
}
if (pUsbIns->pUsbReg->pfnVMReset)
{
LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pUsbIns->pUsbReg->pfnVMReset(pUsbIns);
}
}
#endif
LogFlow(("PDMR3Reset: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being reset.
*
* @param pVM VM Handle.
*/
PDMR3DECL(void) PDMR3Suspend(PVM pVM)
{
LogFlow(("PDMR3Suspend:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnSuspend)
{
LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDrvIns->pDrvReg->pfnSuspend(pDrvIns);
}
if (pDevIns->pDevReg->pfnSuspend)
{
LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnSuspend(pDevIns);
}
}
#ifdef VBOX_WITH_USB
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
{
for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnSuspend)
{
LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pDrvIns->pDrvReg->pfnSuspend(pDrvIns);
}
if (pUsbIns->pUsbReg->pfnVMSuspend)
{
LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pUsbIns->pUsbReg->pfnVMSuspend(pUsbIns);
}
}
#endif
/*
* Suspend all threads.
*/
pdmR3ThreadSuspendAll(pVM);
LogFlow(("PDMR3Suspend: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being resumed.
*
* @param pVM VM Handle.
*/
PDMR3DECL(void) PDMR3Resume(PVM pVM)
{
LogFlow(("PDMR3Resume:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnResume)
{
LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDrvIns->pDrvReg->pfnResume(pDrvIns);
}
if (pDevIns->pDevReg->pfnResume)
{
LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnResume(pDevIns);
}
}
#ifdef VBOX_WITH_USB
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
{
for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnResume)
{
LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pDrvIns->pDrvReg->pfnResume(pDrvIns);
}
if (pUsbIns->pUsbReg->pfnVMResume)
{
LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pUsbIns->pUsbReg->pfnVMResume(pUsbIns);
}
}
#endif
/*
* Resume all threads.
*/
pdmR3ThreadResumeAll(pVM);
LogFlow(("PDMR3Resume: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM being powered off.
*
* @param pVM VM Handle.
*/
PDMR3DECL(void) PDMR3PowerOff(PVM pVM)
{
LogFlow(("PDMR3PowerOff:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextHC)
{
for (PPDMLUN pLun = pDevIns->Internal.s.pLunsHC; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnPowerOff)
{
LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDrvIns->pDrvReg->pfnPowerOff(pDrvIns);
}
if (pDevIns->pDevReg->pfnPowerOff)
{
LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
pDevIns->pDevReg->pfnPowerOff(pDevIns);
}
}
#ifdef VBOX_WITH_USB
for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
{
for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext)
for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown)
if (pDrvIns->pDrvReg->pfnPowerOff)
{
LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pDrvIns->pDrvReg->pfnPowerOff(pDrvIns);
}
if (pUsbIns->pUsbReg->pfnVMPowerOff)
{
LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
pUsbIns->pUsbReg->pfnVMPowerOff(pUsbIns);
}
}
#endif
/*
* Suspend all threads.
*/
pdmR3ThreadSuspendAll(pVM);
LogFlow(("PDMR3PowerOff: returns void\n"));
}
/**
* Queries the base interace of a device instance.
*
* The caller can use this to query other interfaces the device implements
* and use them to talk to the device.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszDevice Device name.
* @param iInstance Device instance.
* @param ppBase Where to store the pointer to the base device interface on success.
* @remark We're not doing any locking ATM, so don't try call this at times when the
* device chain is known to be updated.
*/
PDMR3DECL(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));
/*
* Iterate registered devices looking for the device.
*/
RTUINT cchDevice = strlen(pszDevice);
for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext)
{
if ( pDev->cchName == cchDevice
&& !memcmp(pDev->pDevReg->szDeviceName, pszDevice, cchDevice))
{
/*
* Iterate device instances.
*/
for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextHC)
{
if (pDevIns->iInstance == iInstance)
{
if (pDevIns->IBase.pfnQueryInterface)
{
*ppBase = &pDevIns->IBase;
LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
return VINF_SUCCESS;
}
LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
return VERR_PDM_DEVICE_INSTANCE_NO_IBASE;
}
}
LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND;
}
}
LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
return VERR_PDM_DEVICE_NOT_FOUND;
}
/**
* Queries the base interface of a device LUN.
*
* This differs from PDMR3QueryLun by that it returns the interface on the
* device and not the top level driver.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pszDevice Device name.
* @param iInstance Device instance.
* @param iLun The Logical Unit to obtain the interface of.
* @param ppBase Where to store the base interface pointer.
* @remark We're not doing any locking ATM, so don't try call this at times when the
* device chain is known to be updated.
*/
PDMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
{
LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
pszDevice, pszDevice, iInstance, iLun, ppBase));
/*
* Find the LUN.
*/
PPDMLUN pLun;
int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
if (VBOX_SUCCESS(rc))
{
*ppBase = pLun->pBase;
LogFlow(("PDMR3QueryDeviceLun: return VINF_SUCCESS and *ppBase=%p\n", *ppBase));
return VINF_SUCCESS;
}
LogFlow(("PDMR3QueryDeviceLun: returns %Vrc\n", rc));
return rc;
}
/**
* Query the interface of the top level driver on a LUN.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pszDevice Device name.
* @param iInstance Device instance.
* @param iLun The Logical Unit to obtain the interface of.
* @param ppBase Where to store the base interface pointer.
* @remark We're not doing any locking ATM, so don't try call this at times when the
* device chain is known to be updated.
*/
PDMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
{
LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
pszDevice, pszDevice, iInstance, iLun, ppBase));
/*
* Find the LUN.
*/
PPDMLUN pLun;
int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun);
if (VBOX_SUCCESS(rc))
{
if (pLun->pTop)
{
*ppBase = &pLun->pTop->IBase;
LogFlow(("PDMR3QueryLun: return %Vrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase));
return VINF_SUCCESS;
}
rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN;
}
LogFlow(("PDMR3QueryLun: returns %Vrc\n", rc));
return rc;
}
/**
* Executes pending DMA transfers.
* Forced Action handler.
*
* @param pVM VM handle.
*/
PDMR3DECL(void) PDMR3DmaRun(PVM pVM)
{
VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
if (pVM->pdm.s.pDmac)
{
bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns);
if (fMore)
VM_FF_SET(pVM, VM_FF_PDM_DMA);
}
}
/**
* Call polling function.
*
* @param pVM VM handle.
*/
PDMR3DECL(void) PDMR3Poll(PVM pVM)
{
/* This is temporary hack and shall be removed ASAP! */
unsigned iPoller = pVM->pdm.s.cPollers;
if (iPoller)
{
while (iPoller-- > 0)
pVM->pdm.s.apfnPollers[iPoller](pVM->pdm.s.aDrvInsPollers[iPoller]);
TMTimerSetMillies(pVM->pdm.s.pTimerPollers, 3);
}
}
/**
* Internal timer callback function.
*
* @param pVM The VM.
* @param pTimer The timer handle.
* @param pvUser User argument specified upon timer creation.
*/
static DECLCALLBACK(void) pdmR3PollerTimer(PVM pVM, PTMTIMER pTimer, void *pvUser)
{
PDMR3Poll(pVM);
}
/**
* Service a VMMCALLHOST_PDM_LOCK call.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
PDMR3DECL(int) PDMR3LockCall(PVM pVM)
{
return PDMR3CritSectEnterEx(&pVM->pdm.s.CritSect, true /* fHostCall */);
}