VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/PCIRawDevImpl.cpp@ 42551

Last change on this file since 42551 was 42551, checked in by vboxsync, 12 years ago

Main: big API naming cleanup, use all caps acronyms everywhere, including SDK docs
Frontends/VBoxManage: implement guestcontrol execute for new API, disabled by default

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: PCIRawDevImpl.cpp 42551 2012-08-02 16:44:39Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to raw PCI device.
4 */
5
6/*
7 * Copyright (C) 2010-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17#include "Logging.h"
18#include "PCIRawDevImpl.h"
19#include "PCIDeviceAttachmentImpl.h"
20#include "ConsoleImpl.h"
21#include "MachineImpl.h"
22
23// generated header for events
24#include "VBoxEvents.h"
25
26/**
27 * PCI raw driver instance data.
28 */
29typedef struct DRVMAINPCIRAWDEV
30{
31 /** Pointer to the real PCI raw object. */
32 PCIRawDev *pPCIRawDev;
33 /** Pointer to the driver instance structure. */
34 PPDMDRVINS pDrvIns;
35 /** Our PCI device connector interface. */
36 PDMIPCIRAWCONNECTOR IConnector;
37
38} DRVMAINPCIRAWDEV, *PDRVMAINPCIRAWDEV;
39
40//
41// constructor / destructor
42//
43PCIRawDev::PCIRawDev(Console *console)
44 : mpDrv(NULL),
45 mParent(console)
46{
47}
48
49PCIRawDev::~PCIRawDev()
50{
51}
52
53/**
54 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
55 */
56DECLCALLBACK(void *) PCIRawDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
57{
58 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
59 PDRVMAINPCIRAWDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINPCIRAWDEV);
60
61 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
62 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIPCIRAWCONNECTOR, &pThis->IConnector);
63
64 return NULL;
65}
66
67
68/**
69 * @interface_method_impl{PDMIPCIRAWUP,pfnPciDeviceConstructComplete}
70 */
71DECLCALLBACK(int) PCIRawDev::drvDeviceConstructComplete(PPDMIPCIRAWCONNECTOR pInterface, const char *pcszName,
72 uint32_t uHostPCIAddress, uint32_t uGuestPCIAddress,
73 int rc)
74{
75 PDRVMAINPCIRAWDEV pThis = RT_FROM_CPP_MEMBER(pInterface, DRVMAINPCIRAWDEV, IConnector);
76 Console *pConsole = pThis->pPCIRawDev->getParent();
77 const ComPtr<IMachine>& machine = pConsole->machine();
78 ComPtr<IVirtualBox> vbox;
79
80 HRESULT hrc = machine->COMGETTER(Parent)(vbox.asOutParam());
81 Assert(SUCCEEDED(hrc));
82
83 ComPtr<IEventSource> es;
84 hrc = vbox->COMGETTER(EventSource)(es.asOutParam());
85 Assert(SUCCEEDED(hrc));
86
87 Bstr bstrId;
88 hrc = machine->COMGETTER(Id)(bstrId.asOutParam());
89 Assert(SUCCEEDED(hrc));
90
91 ComObjPtr<PCIDeviceAttachment> pda;
92 BstrFmt bstrName(pcszName);
93 pda.createObject();
94 pda->init(machine, bstrName, uHostPCIAddress, uGuestPCIAddress, TRUE);
95
96 Bstr msg("");
97 if (RT_FAILURE(rc))
98 msg = BstrFmt("runtime error %Rrc", rc);
99
100 fireHostPCIDevicePlugEvent(es, bstrId.raw(), true /* plugged */, RT_SUCCESS(rc) /* success */, pda, msg.raw());
101
102 return VINF_SUCCESS;
103}
104
105
106/**
107 * Destruct a PCI raw driver instance.
108 *
109 * @returns VBox status.
110 * @param pDrvIns The driver instance data.
111 */
112DECLCALLBACK(void) PCIRawDev::drvDestruct(PPDMDRVINS pDrvIns)
113{
114 PDRVMAINPCIRAWDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINPCIRAWDEV);
115 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
116
117 if (pData->pPCIRawDev)
118 pData->pPCIRawDev->mpDrv = NULL;
119}
120
121
122/**
123 * Reset notification.
124 *
125 * @returns VBox status.
126 * @param pDrvIns The driver instance data.
127 */
128DECLCALLBACK(void) PCIRawDev::drvReset(PPDMDRVINS pDrvIns)
129{
130}
131
132
133/**
134 * Construct a raw PCI driver instance.
135 *
136 * @copydoc FNPDMDRVCONSTRUCT
137 */
138DECLCALLBACK(int) PCIRawDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
139{
140 PDRVMAINPCIRAWDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINPCIRAWDEV);
141 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
142
143 /*
144 * Validate configuration.
145 */
146 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
147 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
148
149 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
150 ("Configuration error: Not possible to attach anything to this driver!\n"),
151 VERR_PDM_DRVINS_NO_ATTACH);
152
153 /*
154 * IBase.
155 */
156 pDrvIns->IBase.pfnQueryInterface = PCIRawDev::drvQueryInterface;
157
158 /*
159 * IConnector.
160 */
161 pData->IConnector.pfnDeviceConstructComplete = PCIRawDev::drvDeviceConstructComplete;
162
163 /*
164 * Get the object pointer and update the mpDrv member.
165 */
166 void *pv;
167 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
168 if (RT_FAILURE(rc))
169 {
170 AssertMsgFailed(("Configuration error: No \"Object\" value! rc=%Rrc\n", rc));
171 return rc;
172 }
173
174 pData->pPCIRawDev = (PCIRawDev *)pv;
175 pData->pPCIRawDev->mpDrv = pData;
176
177 return VINF_SUCCESS;
178}
179
180/**
181 * Main raw PCI driver registration record.
182 */
183const PDMDRVREG PCIRawDev::DrvReg =
184{
185 /* u32Version */
186 PDM_DRVREG_VERSION,
187 /* szName */
188 "MainPciRaw",
189 /* szRCMod */
190 "",
191 /* szR0Mod */
192 "",
193 /* pszDescription */
194 "Main PCI raw driver (Main as in the API).",
195 /* fFlags */
196 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
197 /* fClass. */
198 PDM_DRVREG_CLASS_PCIRAW,
199 /* cMaxInstances */
200 ~0U,
201 /* cbInstance */
202 sizeof(DRVMAINPCIRAWDEV),
203 /* pfnConstruct */
204 PCIRawDev::drvConstruct,
205 /* pfnDestruct */
206 PCIRawDev::drvDestruct,
207 /* pfnRelocate */
208 NULL,
209 /* pfnIOCtl */
210 NULL,
211 /* pfnPowerOn */
212 NULL,
213 /* pfnReset */
214 PCIRawDev::drvReset,
215 /* pfnSuspend */
216 NULL,
217 /* pfnResume */
218 NULL,
219 /* pfnAttach */
220 NULL,
221 /* pfnDetach */
222 NULL,
223 /* pfnPowerOff */
224 NULL,
225 /* pfnSoftReset */
226 NULL,
227 /* u32EndVersion */
228 PDM_DRVREG_VERSION
229};
Note: See TracBrowser for help on using the repository browser.

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