GIMDev.cpp revision 2ac3892cdc8b16a0dee55e8b4510b8ecea83c95f
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest/* $Id$ */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest/** @file
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * Guest Interface Manager Device.
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest/*
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * Copyright (C) 2014 Oracle Corporation
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest *
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * This file is part of VirtualBox Open Source Edition (OSE), as
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * available from http://www.virtualbox.org. This file is free software;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * you can redistribute it and/or modify it under the terms of the GNU
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * General Public License (GPL) as published by the Free Software
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * Foundation, in version 2 as it comes in the "COPYING" file of the
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest */
7bf512aea50c834dc9c3ef5a0a228059fcc753a5jenkins
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest/*******************************************************************************
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest* Header Files *
7bf512aea50c834dc9c3ef5a0a228059fcc753a5jenkins*******************************************************************************/
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#define LOG_GROUP LOG_GROUP_DEV_GIM
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#include <VBox/vmm/pdmdev.h>
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#include <VBox/vmm/gim.h>
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#include <VBox/vmm/vm.h>
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#include "VBoxDD.h"
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
6202ba4d983650b484ebe9607707003fef5e09c6Andrew Forrest/**
6202ba4d983650b484ebe9607707003fef5e09c6Andrew Forrest * GIM device.
6202ba4d983650b484ebe9607707003fef5e09c6Andrew Forrest */
6202ba4d983650b484ebe9607707003fef5e09c6Andrew Forresttypedef struct GIMDEV
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest{
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /** Pointer to the device instance - R3 Ptr. */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PPDMDEVINSR3 pDevInsR3;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /** Pointer to the device instance - R0 Ptr. */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PPDMDEVINSR0 pDevInsR0;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /** Pointer to the device instance - RC Ptr. */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PPDMDEVINSRC pDevInsRC;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /** Alignment. */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest RTRCPTR Alignment0;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest} GIMDEV;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest/** Pointer to the GIM device state. */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forresttypedef GIMDEV *PGIMDEV;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#ifndef VBOX_DEVICE_STRUCT_TESTCASE
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#ifdef IN_RING3
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest/**
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest * @interface_method_impl{PDMDEVREG,pfnConstruct}
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest */
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forreststatic DECLCALLBACK(int) gimdevR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest{
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest Assert(iInstance == 0);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PGIMDEV pThis = PDMINS_2_DATA(pDevIns, PGIMDEV);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /*
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * Initialize relevant state bits.
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest pThis->pDevInsR3 = pDevIns;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest /*
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest * Register ourselves with the GIM VMM component.
87e1cbcd02820f55e1816ee4efe9e9127be22a11James Phillpotts */
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest PVM pVM = PDMDevHlpGetVM(pDevIns);
0440e371231a4e5877f4f26b7c7195c5ceda0545Andrew Forrest GIMR3GimDeviceRegister(pVM, pDevIns);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /*
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * Get the MMIO2 regions from the GIM provider.
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest uint32_t cRegions = 0;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PGIMMMIO2REGION pRegionsR3 = GIMR3GetMmio2Regions(pVM, &cRegions);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest if ( cRegions
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest && pRegionsR3)
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest {
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest /*
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest * Register the MMIO2 regions.
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest */
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest PGIMMMIO2REGION pCur = pRegionsR3;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest for (uint32_t i = 0; i < cRegions; i++, pCur++)
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest {
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest Assert(!pCur->fRegistered);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest int rc = PDMDevHlpMMIO2Register(pDevIns, pCur->iRegion, pCur->cbRegion, 0 /* fFlags */, &pCur->pvPageR3,
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest pCur->szDescription);
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest if (RT_FAILURE(rc))
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest return rc;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest pCur->fRegistered = true;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE)
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest RTR0PTR pR0Mapping = 0;
9401b2513f39074de0be9ae452108d0508a6d59fAndrew Forrest rc = PDMDevHlpMMIO2MapKernel(pDevIns, pCur->iRegion, 0 /* off */, pCur->cbRegion, pCur->szDescription,
&pR0Mapping);
AssertLogRelMsgRCReturn(rc, ("PDMDevHlpMapMMIO2IntoR0(%#x,) -> %Rrc\n", pCur->cbRegion, rc), rc);
pCur->pvPageR0 = pR0Mapping;
#else
pCur->pvPageR0 = (RTR0PTR)pCur->pvPageR3;
#endif
/*
* Map into RC if required.
*/
if (pCur->fRCMapping)
{
RTRCPTR pRCMapping = 0;
rc = PDMDevHlpMMHyperMapMMIO2(pDevIns, pCur->iRegion, 0 /* off */, pCur->cbRegion, pCur->szDescription,
&pRCMapping);
AssertLogRelMsgRCReturn(rc, ("PDMDevHlpMMHyperMapMMIO2(%#x,) -> %Rrc\n", pCur->cbRegion, rc), rc);
pCur->pvPageRC = pRCMapping;
}
else
pCur->pvPageRC = NIL_RTRCPTR;
LogRel(("GIMDev: Registered %s\n", pCur->szDescription));
}
}
/** @todo Register SSM: PDMDevHlpSSMRegister(). */
/** @todo Register statistics: STAM_REG(). */
/** @todo Register DBGFInfo: PDMDevHlpDBGFInfoRegister(). */
return VINF_SUCCESS;
}
/**
* @interface_method_impl{PDMDEVREG,pfnDestruct}
*/
static DECLCALLBACK(int) gimdevR3Destruct(PPDMDEVINS pDevIns)
{
PGIMDEV pThis = PDMINS_2_DATA(pDevIns, PGIMDEV);
PVM pVM = PDMDevHlpGetVM(pDevIns);
uint32_t cRegions = 0;
PGIMMMIO2REGION pCur = GIMR3GetMmio2Regions(pVM, &cRegions);
for (uint32_t i = 0; i < cRegions; i++, pCur++)
{
int rc = PDMDevHlpMMIO2Deregister(pDevIns, pCur->iRegion);
if (RT_FAILURE(rc))
return rc;
}
return VINF_SUCCESS;
}
/**
* @interface_method_impl{PDMDEVREG,pfnRelocate}
*/
static DECLCALLBACK(void) gimdevR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
{
NOREF(pDevIns);
NOREF(offDelta);
}
/**
* @interface_method_impl{PDMDEVREG,pfnReset}
*/
static DECLCALLBACK(void) gimdevR3Reset(PPDMDEVINS pDevIns)
{
NOREF(pDevIns);
/* We do not deregister any MMIO2 regions as the regions are expected to be static. */
}
/**
* The device registration structure.
*/
const PDMDEVREG g_DeviceGIMDev =
{
/* u32Version */
PDM_DEVREG_VERSION,
/* szName */
"GIMDev",
/* szRCMod */
"VBoxDDGC.gc",
/* szR0Mod */
"VBoxDDR0.r0",
/* pszDescription */
"VirtualBox GIM Device",
/* fFlags */
PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_R0 | PDM_DEVREG_FLAGS_RC,
/* fClass */
PDM_DEVREG_CLASS_MISC,
/* cMaxInstances */
1,
/* cbInstance */
sizeof(GIMDEV),
/* pfnConstruct */
gimdevR3Construct,
/* pfnDestruct */
gimdevR3Destruct,
/* pfnRelocate */
gimdevR3Relocate,
/* pfnMemSetup */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
gimdevR3Reset,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface. */
NULL,
/* pfnInitComplete */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
PDM_DEVREG_VERSION
};
#endif /* IN_RING3 */
#endif /* VBOX_DEVICE_STRUCT_TESTCASE */