VirtualBox

Changeset 35676 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Jan 24, 2011 2:24:34 PM (14 years ago)
Author:
vboxsync
Message:

Main, VMM: PCI passthrough work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r35638 r35676  
    5050#include "DisplayUtils.h"
    5151#include "BandwidthControlImpl.h"
     52
     53// generated header
     54#include "VBoxEvents.h"
    5255
    5356#ifdef VBOX_WITH_USB
     
    58125815
    58135816
    5814 STDMETHODIMP Machine::AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, IEventContext * /*eventContext*/, BOOL /*tryToUnbind*/)
    5815 {
    5816     AutoCaller autoCaller(this);
    5817     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    5818     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    5819 
    5820     ComObjPtr<PciDeviceAttachment> pda;
    5821     char name[32];
    5822 
    5823     pda.createObject();
    5824     RTStrPrintf(name, sizeof(name), "host%02x:%02x.%x", (hostAddress>>8) & 0xff, (hostAddress & 0xf8) >> 3, hostAddress & 7);
    5825     Bstr bname(name);
    5826     pda.createObject();
    5827     pda->init(this, bname,  hostAddress, desiredGuestAddress, TRUE);
    5828 
    5829     mPciDeviceAssignments.push_back(pda);
    5830     return S_OK;
    5831 }
    5832 
    5833 STDMETHODIMP Machine::DetachHostPciDevice(LONG /*hostAddress*/)
    5834 {
    5835     AutoCaller autoCaller(this);
    5836     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    5837     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    5838 
    5839     return E_NOTIMPL;
     5817/**
     5818 * Currently this method doesn't attach device to the running VM,
     5819 * just makes sure it's plugged on next VM start.
     5820 */
     5821STDMETHODIMP Machine::AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, BOOL /*tryToUnbind*/)
     5822{
     5823    AutoCaller autoCaller(this);
     5824    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     5825
     5826    // lock scope
     5827    {
     5828        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     5829
     5830        //HRESULT rc = checkStateDependency(MutableStateDep);
     5831        //if (FAILED(rc)) return rc;
     5832
     5833        ComObjPtr<PciDeviceAttachment> pda;
     5834        char name[32];
     5835
     5836        RTStrPrintf(name, sizeof(name), "host%02x:%02x.%x", (hostAddress>>8) & 0xff, (hostAddress & 0xf8) >> 3, hostAddress & 7);
     5837        Bstr bname(name);
     5838        pda.createObject();
     5839        pda->init(this, bname,  hostAddress, desiredGuestAddress, TRUE);
     5840        setModified(IsModified_MachineData);
     5841        mHWData.backup();
     5842        mHWData->mPciDeviceAssignments.push_back(pda);
     5843    }
     5844
     5845    // do we need it?
     5846    //saveSettings(NULL);
     5847    mHWData.commit();
     5848
     5849    return S_OK;
     5850}
     5851
     5852/**
     5853 * Currently this method doesn't detach device from the running VM,
     5854 * just makes sure it's not plugged on next VM start.
     5855 */
     5856STDMETHODIMP Machine::DetachHostPciDevice(LONG hostAddress)
     5857{
     5858    AutoCaller autoCaller(this);
     5859    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     5860
     5861    ComObjPtr<PciDeviceAttachment> pAttach;
     5862    bool fRemoved = false;
     5863    HRESULT rc;
     5864
     5865    // lock scope
     5866    {
     5867        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     5868
     5869        rc = checkStateDependency(MutableStateDep);
     5870        if (FAILED(rc)) return rc;
     5871
     5872        for (HWData::PciDeviceAssignmentList::iterator it =  mHWData->mPciDeviceAssignments.begin();
     5873             it !=  mHWData->mPciDeviceAssignments.end();
     5874             ++it)
     5875        {
     5876            LONG iHostAddress = -1;
     5877            pAttach = *it;
     5878            pAttach->COMGETTER(HostAddress)(&iHostAddress);
     5879            if (iHostAddress  != -1  && iHostAddress == hostAddress)
     5880            {
     5881                setModified(IsModified_MachineData);
     5882                mHWData.backup();
     5883                mHWData->mPciDeviceAssignments.remove(pAttach);
     5884                fRemoved = true;
     5885                break;
     5886            }
     5887        }
     5888        // Indeed under lock?
     5889        mHWData.commit();
     5890
     5891        // do we need it?
     5892        // saveSettings(NULL);
     5893    }
     5894
     5895
     5896    /* Fire event outside of the lock */
     5897    if (fRemoved)
     5898    {
     5899        Assert(!pAttach.isNull());
     5900        ComPtr<IEventSource> es;
     5901        rc = mParent->COMGETTER(EventSource)(es.asOutParam());
     5902        Assert(SUCCEEDED(rc));
     5903        Bstr mid;
     5904        rc = this->COMGETTER(Id)(mid.asOutParam());
     5905        Assert(SUCCEEDED(rc));
     5906        fireHostPciDevicePlugEvent(es, mid.raw(), false /* unplugged */, true /* success */, pAttach, NULL);
     5907    }
     5908
     5909    return S_OK;
    58405910}
    58415911
     
    58495919    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    58505920
    5851     SafeIfaceArray<IPciDeviceAttachment> assignments(mPciDeviceAssignments);
     5921    SafeIfaceArray<IPciDeviceAttachment> assignments(mHWData->mPciDeviceAssignments);
    58525922    assignments.detachTo(ComSafeArrayOutArg(aAssignments));
    58535923
     
    61286198        Utf8Str idStr = mData->mUuid.toString();
    61296199        const char * args[] = {szPath, "--comment", mUserData->s.strName.c_str(), "--startvm", idStr.c_str(), 0 };
     6200        fprintf(stderr, "SDL=%s\n",  szPath);
    61306201        vrc = RTProcCreate(szPath, args, env, 0, &pid);
    61316202    }
Note: See TracChangeset for help on using the changeset viewer.

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