VirtualBox

Changeset 35885 in vbox


Ignore:
Timestamp:
Feb 8, 2011 1:20:04 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69897
Message:

Main, VMM, vboxshell: more PCI work (persistent settings, logging, more driver API), API consumer in vboxshell

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/log.h

    r34219 r35885  
    120120    /** PCI Device group. */
    121121    LOG_GROUP_DEV_PCI,
     122    /** PCI Raw Device group. */
     123    LOG_GROUP_DEV_PCI_RAW,
    122124    /** PCNet Device group. */
    123125    LOG_GROUP_DEV_PCNET,
     
    395397    "DEV_PC_BIOS",  \
    396398    "DEV_PCI",      \
     399    "DEV_PCI_RAW",  \
    397400    "DEV_PCNET",    \
    398401    "DEV_PIC",      \
  • trunk/include/VBox/settings.h

    r35146 r35885  
    693693
    694694/**
     695 * NOTE: If you add any fields in here, you must update a) the constructor and b)
     696 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
     697 * your settings might never get saved.
     698 */
     699struct HostPciDeviceAttachment
     700{
     701    HostPciDeviceAttachment()
     702        : uHostAddress(0),
     703          uGuestAddress(0)
     704    {}
     705
     706    bool operator==(const HostPciDeviceAttachment &a) const
     707    {
     708        return (   (uHostAddress   == a.uHostAddress)
     709                && (uGuestAddress  == a.uGuestAddress)
     710                && (strDeviceName  == a.strDeviceName)
     711               );
     712    }
     713
     714    com::Utf8Str    strDeviceName;
     715    uint32_t        uHostAddress;
     716    uint32_t        uGuestAddress;
     717};
     718typedef std::list<HostPciDeviceAttachment> HostPciDeviceAttachmentList;
     719
     720/**
    695721 * Representation of Machine hardware; this is used in the MachineConfigFile.hardwareMachine
    696722 * field.
     
    761787
    762788    IoSettings          ioSettings;             // requires settings version 1.10 (VirtualBox 3.2)
     789    HostPciDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
    763790};
    764791
  • trunk/src/VBox/Devices/Makefile.kmk

    r35855 r35885  
    160160 ifdef VBOX_WITH_VDE
    161161  VBoxDD_DEFS           += VBOX_WITH_VDE
     162 endif
     163 ifdef VBOX_WITH_PCI_PASSTHROUGH
     164  VBoxDD_DEFS           += VBOX_WITH_PCI_PASSTHROUGH
    162165 endif
    163166
     
    261264        VBOX_HGCM_HOST_CODE \
    262265        VBOX_WITH_HGCM \
    263         $(if $(VBOX_BIOS_DMI_FALLBACK),VBOX_BIOS_DMI_FALLBACK,)
     266        $(if $(VBOX_BIOS_DMI_FALLBACK),VBOX_BIOS_DMI_FALLBACK,) \
     267        $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,)
     268
    264269 DevicesR3_DEFS.linux   += _GNU_SOURCE
    265270 DevicesR3_DEFS.l4      += _GNU_SOURCE
     
    541546        Bus/MsiCommon.cpp \
    542547        Bus/MsixCommon.cpp \
    543         $(if $(VBOX_WITH_PCI_PASSTHROUGH),Bus/DevPciRaw.cpp,) \
    544548        Graphics/DevVGA.cpp \
    545549        Input/DevPS2.cpp \
  • trunk/src/VBox/Devices/testcase/Makefile.kmk

    r35353 r35885  
    4040        $(if $(VBOX_WITH_VDMA),VBOX_WITH_VDMA,) \
    4141        $(if $(VBOX_WITH_WDDM),VBOX_WITH_WDDM,) \
    42         $(if $(VBOX_WITH_VIDEOHWACCEL),VBOX_WITH_VIDEOHWACCEL,)
     42        $(if $(VBOX_WITH_VIDEOHWACCEL),VBOX_WITH_VIDEOHWACCEL,) \
     43        $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,)
     44
    4345
    4446#
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSize.cpp

    r32471 r35885  
    8585# undef LOG_GROUP
    8686# include "../Storage/DevLsiLogicSCSI.cpp"
     87#endif
     88
     89#ifdef VBOX_WITH_PCI_PASSTHROUGH
     90# undef LOG_GROUP
     91# include "../Bus/DevPciRaw.cpp"
    8792#endif
    8893
     
    317322    CHECK_MEMBER_ALIGNMENT(VPCISTATE, Queues, 8);
    318323#endif
     324#ifdef VBOX_WITH_PCI_PASSTHROUGH
     325    CHECK_MEMBER_ALIGNMENT(PCIRAWSENDREQ, u.aGetRegionInfo.u64RegionSize, 8);
     326#endif
    319327
    320328#ifdef VBOX_WITH_RAW_MODE
     
    335343    return rc;
    336344}
    337 
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r35783 r35885  
    31033103    return
    31043104
     3105def parsePci(str):
     3106    pcire = re.compile(r'(?P<b>\d+):(?P<d>\d+)\.(?P<f>\d)')
     3107    m = pcire.search(str)
     3108    if m is None:
     3109        return -1
     3110    dict = m.groupdict()
     3111    return ((int(dict['b'])) << 8) | ((int(dict['d'])) << 3) | int(dict['f'])
    31053112
    31063113def lspciCmd(ctx, args):
     
    31123119        return 0
    31133120    cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args:  lspci(ctx, console)])
     3121    return 0
     3122
     3123def attachpciCmd(ctx, args):
     3124    if (len(args) < 3):
     3125        print "usage: attachpci vm hostpci <guestpci>"
     3126        return 0
     3127    mach = argsToMach(ctx,args)
     3128    if mach == None:
     3129        return 0
     3130    hostaddr = parsePci(args[2])
     3131    if hostaddr == -1:
     3132        print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" %(args[2])
     3133        return 0
     3134
     3135    if (len(args) > 3):
     3136        guestaddr = parsePci(args[3])
     3137        if guestaddr == -1:
     3138            print "invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" %(args[3])
     3139            return 0
     3140    else:
     3141        guestaddr = hostaddr
     3142    cmdClosedVm(ctx, mach, lambda ctx,mach,a: mach.attachHostPciDevice(hostaddr, guestaddr, True))
     3143    return 0
     3144
     3145def detachpciCmd(ctx, args):
     3146    if (len(args) < 3):
     3147        print "usage: detachpci vm hostpci"
     3148        return 0
     3149    mach = argsToMach(ctx,args)
     3150    if mach == None:
     3151        return 0
     3152    hostaddr = parsePci(args[2])
     3153    if hostaddr == -1:
     3154        print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" %(args[2])
     3155        return 0
     3156
     3157    cmdClosedVm(ctx, mach, 'guestlambda', lambda ctx,mach,a: mach.detachHostPciDevice(hostaddr))
    31143158    return 0
    31153159
     
    32003244            'recordDemo':['Record demo: recordDemo Win32 file.dmo 10', recordDemoCmd, 0],
    32013245            'playbackDemo':['Playback demo: playbackDemo Win32 file.dmo 10', playbackDemoCmd, 0],
    3202             'lspci': ['List PCI devices attached to the VM: lspci Win32', lspciCmd]
     3246            'lspci': ['List PCI devices attached to the VM: lspci Win32', lspciCmd, 0],
     3247            'attachpci': ['Attach host PCI device to the VM: attachpci Win32 01:00.0', attachpciCmd, 0],
     3248            'detachpci': ['Detach host PCI device from the VM: detachpci Win32 01:00.0', detachpciCmd, 0]
    32033249            }
    32043250
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r35765 r35885  
    481481      -->
    482482    </const>
     483    <const name="v1_12"     value="14">
     484      <desc>Settings version "1.12", written by VirtualBox 4.1.x.</desc>
     485      <!--
     486          Machine changes: raw PCI device atatchment.
     487      -->
     488    </const>
     489
    483490    <const name="Future"     value="99999">
    484491      <desc>Settings version greater than "1.11", written by a future VirtualBox version.</desc>
  • trunk/src/VBox/Main/include/PciDeviceAttachmentImpl.h

    r35684 r35885  
    2222
    2323#include "VirtualBoxBase.h"
     24#include <VBox/settings.h>
    2425
    2526class ATL_NO_VTABLE PciAddress :
     
    109110                 LONG          aGuestAddress,
    110111                 BOOL          fPhysical);
     112
    111113    void uninit();
     114
     115    // settings
     116    HRESULT loadSettings(IMachine * aParent,
     117                         const settings::HostPciDeviceAttachment& aHpda);
     118    HRESULT saveSettings(settings::HostPciDeviceAttachment &data);
    112119
    113120    HRESULT FinalConstruct();
     
    122129private:
    123130    struct Data;
    124     Data *m;
     131    Datam;
    125132};
    126133
  • trunk/src/VBox/Main/src-all/PciDeviceAttachmentImpl.cpp

    r35684 r35885  
    3333          fPhysical(afPhysical)
    3434    {
     35        (void)aParent;
    3536        DevName = aDevName;
    3637    }
     
    6970
    7071    return m != NULL ? S_OK : E_FAIL;
     72}
     73
     74HRESULT PciDeviceAttachment::loadSettings(IMachine *aParent,
     75                                          const settings::HostPciDeviceAttachment &hpda)
     76{
     77    Bstr bname(hpda.strDeviceName);
     78    return init(aParent, bname,  hpda.uHostAddress, hpda.uGuestAddress, TRUE);
     79}
     80
     81
     82HRESULT PciDeviceAttachment::saveSettings(settings::HostPciDeviceAttachment &data)
     83{
     84    Assert(m);
     85    data.uHostAddress = m->HostAddress;
     86    data.uGuestAddress = m->GuestAddress;
     87    data.strDeviceName = m->DevName;
     88
     89    return S_OK;
    7190}
    7291
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r35875 r35885  
    17341734    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    17351735
    1736     mBusMgr->listAttachedPciDevices(ComSafeArrayOutArg(aAttachments));
     1736    if (mBusMgr)
     1737        mBusMgr->listAttachedPciDevices(ComSafeArrayOutArg(aAttachments));
     1738    else
     1739    {
     1740        com::SafeIfaceArray<IPciDeviceAttachment> result(0);
     1741        result.detachTo(ComSafeArrayOutArg(aAttachments));           
     1742    }
    17371743
    17381744    return S_OK;
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r35838 r35885  
    58295829        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    58305830
    5831         //HRESULT rc = checkStateDependency(MutableStateDep);
    5832         //if (FAILED(rc)) return rc;
     5831        HRESULT rc = checkStateDependency(MutableStateDep);
     5832        if (FAILED(rc)) return rc;
    58335833
    58345834        ComObjPtr<PciDeviceAttachment> pda;
     
    58435843        mHWData->mPciDeviceAssignments.push_back(pda);
    58445844    }
    5845 
    5846     // do we need it?
    5847     //saveSettings(NULL);
    5848     mHWData.commit();
    58495845
    58505846    return S_OK;
     
    58875883            }
    58885884        }
    5889         // Indeed under lock?
    5890         mHWData.commit();
    5891 
    5892         // do we need it?
    5893         // saveSettings(NULL);
    58945885    }
    58955886
     
    74517442        rc = mBandwidthControl->loadSettings(data.ioSettings);
    74527443        if (FAILED(rc)) return rc;
     7444
     7445        // Host PCI devices
     7446        for (settings::HostPciDeviceAttachmentList::const_iterator it = data.pciAttachments.begin();
     7447             it != data.pciAttachments.end();
     7448             ++it)
     7449        {
     7450            const settings::HostPciDeviceAttachment &hpda = *it;
     7451            ComObjPtr<PciDeviceAttachment> pda;
     7452
     7453            pda.createObject();
     7454            pda->loadSettings(this, hpda);
     7455            mHWData->mPciDeviceAssignments.push_back(pda);
     7456        }
    74537457
    74547458#ifdef VBOX_WITH_GUEST_PROPS
     
    85308534        rc = mBandwidthControl->saveSettings(data.ioSettings);
    85318535        if (FAILED(rc)) throw rc;
     8536
     8537        /* Host PCI devices */
     8538        for (HWData::PciDeviceAssignmentList::const_iterator it = mHWData->mPciDeviceAssignments.begin();
     8539             it != mHWData->mPciDeviceAssignments.end();
     8540             ++it)
     8541        {
     8542            ComObjPtr<PciDeviceAttachment> pda = *it;
     8543            settings::HostPciDeviceAttachment hpda;
     8544
     8545            rc = pda->saveSettings(hpda);
     8546            if (FAILED(rc)) throw rc;
     8547
     8548            data.pciAttachments.push_back(hpda);
     8549        }
     8550
    85328551
    85338552        // guest properties
  • trunk/src/VBox/Main/xml/Settings.cpp

    r35818 r35885  
    9191
    9292/** VirtualBox XML settings version number substring ("x.y")  */
    93 #define VBOX_XML_VERSION        "1.11"
     93#define VBOX_XML_VERSION        "1.12"
    9494
    9595/** VirtualBox XML settings version platform substring */
     
    320320                else if (ulMinor == 11)
    321321                    m->sv = SettingsVersion_v1_11;
    322                 else if (ulMinor > 11)
     322                else if (ulMinor == 12)
     323                    m->sv = SettingsVersion_v1_12;
     324                else if (ulMinor > 12)
    323325                    m->sv = SettingsVersion_Future;
    324326            }
     
    340342        // creating new settings file:
    341343        m->strSettingsVersionFull = VBOX_XML_VERSION_FULL;
    342         m->sv = SettingsVersion_v1_11;
     344        m->sv = SettingsVersion_v1_12;
    343345    }
    344346}
     
    818820            break;
    819821
     822        case SettingsVersion_v1_12:
     823            pcszVersion = "1.12";
     824            break;
     825
    820826        case SettingsVersion_Future:
    821827            // can be set if this code runs on XML files that were created by a future version of VBox;
    822828            // in that case, downgrade to current version when writing since we can't write future versions...
    823             pcszVersion = "1.11";
    824             m->sv = SettingsVersion_v1_10;
     829            pcszVersion = "1.12";
     830            m->sv = SettingsVersion_v1_12;
    825831        break;
    826832
     
    846852 * set the "sv" member to the required settings version that is to
    847853 * be written. For newly created files, the settings version will be
    848  * the latest (1.11); for files read in from disk earlier, it will be
     854 * the latest (1.12); for files read in from disk earlier, it will be
    849855 * the settings version indicated in the file. However, this method
    850856 * will silently make sure that the settings version is always
     
    16481654                  && (strNotificationPatterns   == h.strNotificationPatterns)
    16491655                  && (ioSettings                == h.ioSettings)
     1656                  && (pciAttachments            == h.pciAttachments)
    16501657                )
    16511658            );
     
    27172724                    pelmBandwidthGroup->getAttributeValue("maxMbPerSec", gr.cMaxMbPerSec);
    27182725                    hw.ioSettings.llBandwidthGroups.push_back(gr);
     2726                }
     2727            }
     2728        }  else if (pelmHwChild->nameEquals("HostPci")) {
     2729            const xml::ElementNode *pelmDevices;
     2730
     2731            if ((pelmDevices = pelmHwChild->findChildElement("Devices")))
     2732            {
     2733                xml::NodesLoop nl2(*pelmDevices, "Device");
     2734                const xml::ElementNode *pelmDevice;
     2735                while ((pelmDevice = nl2.forAllNodes()))
     2736                {
     2737                    HostPciDeviceAttachment hpda;
     2738
     2739                    if (!pelmDevice->getAttributeValue("host", hpda.uHostAddress))
     2740                         throw ConfigFileError(this, pelmDevice, N_("Missing Device/@host attribute"));
     2741
     2742                    if (!pelmDevice->getAttributeValue("host", hpda.uGuestAddress))
     2743                         throw ConfigFileError(this, pelmDevice, N_("Missing Device/@guest attribute"));
     2744
     2745                    /* name is optional */
     2746                    pelmDevice->getAttributeValue("name", hpda.strDeviceName);
     2747
     2748                    hw.pciAttachments.push_back(hpda);
    27192749                }
    27202750            }
     
    38633893    }
    38643894
     3895    if (m->sv >= SettingsVersion_v1_12)
     3896    {
     3897        xml::ElementNode *pelmPci = pelmHardware->createChild("HostPci");
     3898        xml::ElementNode *pelmPciDevices = pelmPci->createChild("Devices");
     3899
     3900        for (HostPciDeviceAttachmentList::const_iterator it = hw.pciAttachments.begin();
     3901             it != hw.pciAttachments.end();
     3902             ++it)
     3903        {
     3904            const HostPciDeviceAttachment &hpda = *it;
     3905
     3906            xml::ElementNode *pelmThis = pelmPciDevices->createChild("Device");
     3907
     3908            pelmThis->setAttribute("host",  hpda.uHostAddress);
     3909            pelmThis->setAttribute("guest", hpda.uGuestAddress);
     3910            pelmThis->setAttribute("name",  hpda.strDeviceName);
     3911        }
     3912    }
     3913
    38653914    xml::ElementNode *pelmGuest = pelmHardware->createChild("Guest");
    38663915    pelmGuest->setAttribute("memoryBalloonSize", hw.ulMemoryBalloonSize);
     
    44184467void MachineConfigFile::bumpSettingsVersionIfNeeded()
    44194468{
     4469    if (m->sv < SettingsVersion_v1_12)
     4470    {
     4471        // VirtualBox 4.1 adds PCI passthrough
     4472        if (hardwareMachine.pciAttachments.size())
     4473            m->sv = SettingsVersion_v1_12;
     4474    }
     4475
    44204476    if (m->sv < SettingsVersion_v1_11)
    44214477    {
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r35856 r35885  
    143143                                }
    144144                            }
    145                            
     145
    146146                            /* bail out */
    147147                            LogFlow(("ModuleTerm: returns %Rrc\n", rc));
     
    192192    PGMR0DynMapTerm();
    193193#endif
    194        
     194
    195195#ifdef VBOX_WITH_PCI_PASSTHROUGH
    196196    /*
Note: See TracChangeset for help on using the changeset viewer.

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