VBoxPciInternal.h revision d50b5e3e6c603275de6811050f6c304c5be7ae31
de4157257515400c2c25373591135f110227b68cvboxsync/* $Id$ */
de4157257515400c2c25373591135f110227b68cvboxsync/** @file
de4157257515400c2c25373591135f110227b68cvboxsync * VBoxPci - PCI driver (Host), Internal Header.
de4157257515400c2c25373591135f110227b68cvboxsync */
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync/*
de4157257515400c2c25373591135f110227b68cvboxsync * Copyright (C) 2011 Oracle Corporation
de4157257515400c2c25373591135f110227b68cvboxsync *
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * available from http://www.virtualbox.org. This file is free software;
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * General Public License (GPL) as published by the Free Software
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync */
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync#ifndef ___VBoPciInternal_h___
b263fac6f6e7fa933c7bfb2a45d598fe8e458c09vboxsync#define ___VBoxPciInternal_h___
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#include <VBox/sup.h>
de4157257515400c2c25373591135f110227b68cvboxsync#include <VBox/rawpci.h>
de4157257515400c2c25373591135f110227b68cvboxsync#include <iprt/semaphore.h>
de4157257515400c2c25373591135f110227b68cvboxsync#include <iprt/assert.h>
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#ifdef RT_OS_LINUX
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
de4157257515400c2c25373591135f110227b68cvboxsync//# ifdef DEBUG_nike
de4157257515400c2c25373591135f110227b68cvboxsync# define VBOX_WITH_IOMMU
de4157257515400c2c25373591135f110227b68cvboxsync//# endif
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#ifdef VBOX_WITH_IOMMU
de4157257515400c2c25373591135f110227b68cvboxsync#include <linux/iommu.h>
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncRT_C_DECLS_BEGIN
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync/* Forward declaration. */
de4157257515400c2c25373591135f110227b68cvboxsynctypedef struct VBOXRAWPCIGLOBALS *PVBOXRAWPCIGLOBALS;
de4157257515400c2c25373591135f110227b68cvboxsynctypedef struct VBOXRAWPCIDRVVM *PVBOXRAWPCIDRVVM;
de4157257515400c2c25373591135f110227b68cvboxsynctypedef struct VBOXRAWPCIINS *PVBOXRAWPCIINS;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync/**
de4157257515400c2c25373591135f110227b68cvboxsync * The per-instance data of the VBox raw PCI interface.
de4157257515400c2c25373591135f110227b68cvboxsync *
de4157257515400c2c25373591135f110227b68cvboxsync * This is data associated with a host PCI card attached to the VM.
de4157257515400c2c25373591135f110227b68cvboxsync *
de4157257515400c2c25373591135f110227b68cvboxsync */
de4157257515400c2c25373591135f110227b68cvboxsynctypedef struct VBOXRAWPCIINS
de4157257515400c2c25373591135f110227b68cvboxsync{
de4157257515400c2c25373591135f110227b68cvboxsync /** Pointer to the globals. */
de4157257515400c2c25373591135f110227b68cvboxsync PVBOXRAWPCIGLOBALS pGlobals;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync /** Mutex protecting device access. */
de4157257515400c2c25373591135f110227b68cvboxsync RTSEMFASTMUTEX hFastMtx;
de4157257515400c2c25373591135f110227b68cvboxsync /** The spinlock protecting the state variables and device access. */
de4157257515400c2c25373591135f110227b68cvboxsync RTSPINLOCK hSpinlock;
de4157257515400c2c25373591135f110227b68cvboxsync /** Pointer to the next device in the list. */
de4157257515400c2c25373591135f110227b68cvboxsync PVBOXRAWPCIINS pNext;
de4157257515400c2c25373591135f110227b68cvboxsync /** Reference count. */
de4157257515400c2c25373591135f110227b68cvboxsync uint32_t volatile cRefs;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync /* Host PCI address of this device. */
de4157257515400c2c25373591135f110227b68cvboxsync uint32_t HostPciAddress;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#ifdef RT_OS_LINUX
de4157257515400c2c25373591135f110227b68cvboxsync struct pci_dev * pPciDev;
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync bool fMsiUsed;
de4157257515400c2c25373591135f110227b68cvboxsync bool fMsixUsed;
de4157257515400c2c25373591135f110227b68cvboxsync bool fIommuUsed;
de4157257515400c2c25373591135f110227b68cvboxsync bool fPad0;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync /** Temporary: host IRQ we were given. Assumes single IRQ devices. */
de4157257515400c2c25373591135f110227b68cvboxsync int32_t iHostIrq;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync /** Port, given to the outside world. */
de4157257515400c2c25373591135f110227b68cvboxsync RAWPCIDEVPORT DevPort;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync uint32_t cHandlersCount;
de4157257515400c2c25373591135f110227b68cvboxsync PFNRAWPCIISR pfnIrqHandler;
de4157257515400c2c25373591135f110227b68cvboxsync void *pIrqContext;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync PRAWPCIPERVM pVmCtx;
de4157257515400c2c25373591135f110227b68cvboxsync} VBOXRAWPCIINS;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync/**
de4157257515400c2c25373591135f110227b68cvboxsync * Per-VM data of the VBox PCI driver. Pointed to by pGVM->rawpci.s.pDriverData.
de4157257515400c2c25373591135f110227b68cvboxsync *
de4157257515400c2c25373591135f110227b68cvboxsync */
de4157257515400c2c25373591135f110227b68cvboxsynctypedef struct VBOXRAWPCIDRVVM
de4157257515400c2c25373591135f110227b68cvboxsync{
de4157257515400c2c25373591135f110227b68cvboxsync /** Mutex protecting state changes. */
de4157257515400c2c25373591135f110227b68cvboxsync RTSEMFASTMUTEX hFastMtx;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#ifdef RT_OS_LINUX
de4157257515400c2c25373591135f110227b68cvboxsync# ifdef VBOX_WITH_IOMMU
de4157257515400c2c25373591135f110227b68cvboxsync /* IOMMU domain. */
de4157257515400c2c25373591135f110227b68cvboxsync struct iommu_domain* pIommuDomain;
de4157257515400c2c25373591135f110227b68cvboxsync# endif
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync /* Back pointer to pGVM->rawpci.s. */
de4157257515400c2c25373591135f110227b68cvboxsync PRAWPCIPERVM pPerVmData;
de4157257515400c2c25373591135f110227b68cvboxsync} VBOXRAWPCIDRVVM;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync/**
de4157257515400c2c25373591135f110227b68cvboxsync * The global data of the VBox PCI driver.
de4157257515400c2c25373591135f110227b68cvboxsync *
de4157257515400c2c25373591135f110227b68cvboxsync * This contains the bit required for communicating with support driver, VBoxDrv
de4157257515400c2c25373591135f110227b68cvboxsync * (start out as SupDrv).
de4157257515400c2c25373591135f110227b68cvboxsync */
de4157257515400c2c25373591135f110227b68cvboxsynctypedef struct VBOXRAWPCIGLOBALS
de4157257515400c2c25373591135f110227b68cvboxsync{
de4157257515400c2c25373591135f110227b68cvboxsync /** Mutex protecting the list of instances and state changes. */
de4157257515400c2c25373591135f110227b68cvboxsync RTSEMFASTMUTEX hFastMtx;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync /** Pointer to a list of instance data. */
de4157257515400c2c25373591135f110227b68cvboxsync PVBOXRAWPCIINS pInstanceHead;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync /** The raw PCI interface factory. */
de4157257515400c2c25373591135f110227b68cvboxsync RAWPCIFACTORY RawPciFactory;
de4157257515400c2c25373591135f110227b68cvboxsync /** The SUPDRV component factory registration. */
de4157257515400c2c25373591135f110227b68cvboxsync SUPDRVFACTORY SupDrvFactory;
de4157257515400c2c25373591135f110227b68cvboxsync /** The number of current factory references. */
de4157257515400c2c25373591135f110227b68cvboxsync int32_t volatile cFactoryRefs;
de4157257515400c2c25373591135f110227b68cvboxsync /** Whether the IDC connection is open or not.
de4157257515400c2c25373591135f110227b68cvboxsync * This is only for cleaning up correctly after the separate IDC init on Windows. */
de4157257515400c2c25373591135f110227b68cvboxsync bool fIDCOpen;
de4157257515400c2c25373591135f110227b68cvboxsync /** The SUPDRV IDC handle (opaque struct). */
de4157257515400c2c25373591135f110227b68cvboxsync SUPDRVIDCHANDLE SupDrvIDC;
de4157257515400c2c25373591135f110227b68cvboxsync#ifdef RT_OS_LINUX
de4157257515400c2c25373591135f110227b68cvboxsync struct module * pciStubModule;
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync} VBOXRAWPCIGLOBALS;
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciInit(PVBOXRAWPCIGLOBALS pGlobals);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(void) vboxPciShutdown(PVBOXRAWPCIGLOBALS pGlobals);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsInitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM, PRAWPCIPERVM pVmData);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(void) vboxPciOsDeinitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevInit (PVBOXRAWPCIINS pIns, uint32_t fFlags);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevDeinit(PVBOXRAWPCIINS pIns, uint32_t fFlags);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevDestroy(PVBOXRAWPCIINS pIns);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevGetRegionInfo(PVBOXRAWPCIINS pIns,
de4157257515400c2c25373591135f110227b68cvboxsync int32_t iRegion,
de4157257515400c2c25373591135f110227b68cvboxsync RTHCPHYS *pRegionStart,
de4157257515400c2c25373591135f110227b68cvboxsync uint64_t *pu64RegionSize,
de4157257515400c2c25373591135f110227b68cvboxsync bool *pfPresent,
de4157257515400c2c25373591135f110227b68cvboxsync uint32_t *pfFlags);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevMapRegion(PVBOXRAWPCIINS pIns,
de4157257515400c2c25373591135f110227b68cvboxsync int32_t iRegion,
de4157257515400c2c25373591135f110227b68cvboxsync RTHCPHYS pRegionStart,
de4157257515400c2c25373591135f110227b68cvboxsync uint64_t u64RegionSize,
de4157257515400c2c25373591135f110227b68cvboxsync uint32_t fFlags,
de4157257515400c2c25373591135f110227b68cvboxsync RTR0PTR *pRegionBase);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevUnmapRegion(PVBOXRAWPCIINS pIns,
de4157257515400c2c25373591135f110227b68cvboxsync int32_t iRegion,
de4157257515400c2c25373591135f110227b68cvboxsync RTHCPHYS RegionStart,
de4157257515400c2c25373591135f110227b68cvboxsync uint64_t u64RegionSize,
de4157257515400c2c25373591135f110227b68cvboxsync RTR0PTR RegionBase);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevPciCfgWrite(PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevPciCfgRead (PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevRegisterIrqHandler (PVBOXRAWPCIINS pIns, PFNRAWPCIISR pfnHandler, void* pIrqContext, int32_t *piHostIrq);
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevUnregisterIrqHandler(PVBOXRAWPCIINS pIns, int32_t iHostIrq);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncDECLHIDDEN(int) vboxPciOsDevPowerStateChange(PVBOXRAWPCIINS pIns, PCIRAWPOWERSTATE aState);
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#define VBOX_DRV_VMDATA(pIns) ((PVBOXRAWPCIDRVVM)(pIns->pVmCtx ? pIns->pVmCtx->pDriverData : NULL))
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsyncRT_C_DECLS_END
de4157257515400c2c25373591135f110227b68cvboxsync
de4157257515400c2c25373591135f110227b68cvboxsync#endif
de4157257515400c2c25373591135f110227b68cvboxsync