DevPciRaw.cpp revision 43747b1f0bc8302a238fb35e55857a5e9aa1933d
/* $Id$ */
/** @file
* PCI passthrough device emulation.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_PCI
#include "../Builtins.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The version of the saved state. */
#define PCIRAW_SAVED_STATE_VERSION 1
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/* Temporary PDM stubs */
typedef struct PDMPCIRAWREG
{
/** Struct version+magic number (PDM_PCIRAWREG_VERSION). */
} PDMPCIRAWREG;
/** Pointer to a raw PCI registration structure. */
typedef PDMPCIRAWREG *PPDMPCIRAWREG;
/** Current PDMPCIRAWREG version number. */
struct PDMPCIRAWHLPRC
{
};
struct PDMPCIRAWHLPR0
{
};
struct PDMPCIRAWHLPR3
{
/**
* Gets the address of the RC PCI raw helpers.
*
* This should be called at both construction and relocation time
* to obtain the correct address of the RC helpers.
*
* @returns RC pointer to the PCI raw helpers.
* @param pDevIns Device instance of the raw PCI device.
*/
/**
* Gets the address of the R0 PCI raw helpers.
*
* This should be called at both construction and relocation time
* to obtain the correct address of the R0 helpers.
*
* @returns R0 pointer to the PCI raw helpers.
* @param pDevIns Device instance of the raw PCI device.
*/
/** Just a safety precaution. */
};
/** Pointer to raw PCI R3 helpers. */
/** Pointer to const raw PCI R3 helpers. */
/**
* @copydoc PDMDEVHLPR3::pfnPciRawRegister
*/
DECLINLINE(int) PDMDevHlpPciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
{
//return pDevIns->pHlpR3->pfnPciRawRegister(pDevIns, pPciRawReg, ppPciRawHlpR3);
return VINF_SUCCESS;
}
/* End of PDM stubs */
typedef struct PciRawState
{
/** Pointer to the device instance. - R3 ptr. */
/** The PCI raw helpers - R3 Ptr. */
/** Pointer to the device instance. - R0 ptr. */
/** The PCI raw helpers - R0 Ptr. */
/** Pointer to the device instance. - RC ptr. */
/** The PCI raw helpers - RC Ptr. */
/* Virtual PCI device */
/* Address of device on the host */
/* Address of device in the guest */
/* Global device lock */
} PciRawState;
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
PDMBOTHCBDECL(int) pcirawMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
PDMBOTHCBDECL(int) pcirawMMIORead (PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
/*
* Temporary control to disable locking if problems found
*/
{
}
{
}
void * pvUser,
void * pv,
unsigned cb)
{
int rc = VINF_SUCCESS;
return rc;
switch (cb)
{
case 1:
case 2:
case 4:
case 8:
{
break;
}
default:
rc = VINF_SUCCESS;
}
return rc;
}
void * pvUser,
void * pv,
unsigned cb)
{
int rc = VINF_SUCCESS;
LogFlow(("pcirawMMIOWrite: %llx (%d) <- %x\n",
return rc;
switch (cb)
{
case 1:
case 2:
case 4:
case 8:
{
break;
}
default:
}
return rc;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
#ifdef IN_RING3
/**
* @copydoc FNSSMDEVLIVEEXEC
*/
{
return VINF_SSM_DONT_CALL_AGAIN;
}
/**
* Saves a state of the raw PCI device. Do nothing yet.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to save the state to.
*/
{
/* The config. */
return VINF_SUCCESS;
}
/**
* Loads a state of the raw PCI device state.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to the saved state.
* @param uVersion The data unit version number.
* @param uPass The data pass.
*/
{
int rc;
if (uVersion != PCIRAW_SAVED_STATE_VERSION)
return VINF_SUCCESS;
}
/**
* Relocation notification.
*
* @returns VBox status.
* @param pDevIns The device instance data.
* @param offDelta The delta relative to the old address.
*/
{
unsigned i;
LogFlow(("pcirawRelocate:\n"));
}
/**
* Reset notification.
*
* @returns VBox status.
* @param pDevIns The device instance data.
*/
{
unsigned i;
LogFlow(("pcirawReset:\n"));
}
/**
* Initialization routine.
*
* @returns VBox status.
* @param pDevIns The device instance data.
*/
{
unsigned i;
int rc;
return VINF_SUCCESS;
}
/**
* @interface_method_impl{PDMDEVREG,pfnConstruct}
*/
{
int rc;
bool fRCEnabled = false;
bool fR0Enabled = false;
/*
* Validate configuration.
*/
if (!CFGMR3AreValuesValid(pCfg,
"GCEnabled\0"
"R0Enabled\0"
"HostPCIBusNo\0"
"HostPCIDeviceNo\0"
"HostPCIFunctionNo\0"
))
/* Query configuration. */
if (RT_FAILURE(rc))
N_("Configuration error: Querying \"GCEnabled\" as a bool failed"));
if (RT_FAILURE(rc))
N_("Configuration error: failed to read R0Enabled as boolean"));
/* Obtain host device address */
if (RT_FAILURE(rc))
N_("Configuration error: Querying \"HostPCIBusNo\" as a int failed"));
if (RT_FAILURE(rc))
N_("Configuration error: Querying \"HostPCIDeviceNo\" as a int failed"));
if (RT_FAILURE(rc))
N_("Configuration error: Querying \"HostPCIFunctionNo\" as a int failed"));
/* Initialize the device state */
if (RT_FAILURE(rc))
return rc;
/*
* Register the raw device and get helpers.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Initialize critical section.
*/
if (RT_FAILURE(rc))
#if 0
/*
*/
{
}
#endif
if (fRCEnabled)
{
if (!pThis->pPciRawHlpRC)
{
AssertReleaseMsgFailed(("cannot get RC helper\n"));
return VERR_INTERNAL_ERROR;
}
}
if (fR0Enabled)
{
if (!pThis->pPciRawHlpR0)
{
AssertReleaseMsgFailed(("cannot get R0 helper\n"));
return VERR_INTERNAL_ERROR;
}
}
/* Register SSM callbacks */
rc = PDMDevHlpSSMRegister3(pDevIns, PCIRAW_SAVED_STATE_VERSION, sizeof(*pThis), pcirawLiveExec, pcirawSaveExec, pcirawLoadExec);
if (RT_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/**
* The device registration structure.
*/
const PDMDEVREG g_DevicePciRaw =
{
/* u32Version */
/* szName */
"pciraw",
/* szRCMod */
"VBoxDDGC.gc",
/* szR0Mod */
"VBoxDDR0.r0",
/* pszDescription */
"Raw PCI wrapper Device",
/* fFlags */
PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32_64 | PDM_DEVREG_FLAGS_PAE36 | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
/* fClass */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(PciRawState),
/* pfnConstruct */
/* pfnDestruct */
NULL,
/* pfnRelocate */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface. */
NULL,
/* pfnInitComplete */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
};
#endif /* IN_RING3 */
#endif /* VBOX_DEVICE_STRUCT_TESTCASE */