VBoxPciInternal.h revision 80559ecb51cb45f6869d8450a1317ead0dd5129d
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync/* $Id$ */
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync/** @file
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * VBoxPci - PCI driver (Host), Internal Header.
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync */
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync/*
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * Copyright (C) 2011 Oracle Corporation
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync *
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * available from http://www.virtualbox.org. This file is free software;
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * General Public License (GPL) as published by the Free Software
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync */
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync#ifndef ___VBoPciInternal_h___
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync#define ___VBoxPciInternal_h___
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync#include <VBox/sup.h>
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync#include <VBox/rawpci.h>
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync#include <iprt/semaphore.h>
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync#include <iprt/assert.h>
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#ifdef RT_OS_LINUX
a5d214fbec758376bb145deec768ab9ac838dedevboxsync
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync# ifdef DEBUG_nike
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync# define VBOX_WITH_IOMMU
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync# endif
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#endif
a5d214fbec758376bb145deec768ab9ac838dedevboxsync
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#ifdef VBOX_WITH_IOMMU
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#include <linux/iommu.h>
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#endif
a5d214fbec758376bb145deec768ab9ac838dedevboxsync
a5d214fbec758376bb145deec768ab9ac838dedevboxsync#endif
c285785ffc9f35513e0c6e7e2a05df3090dc919cvboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsyncRT_C_DECLS_BEGIN
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync/* Forward declaration. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsynctypedef struct VBOXRAWPCIGLOBALS *PVBOXRAWPCIGLOBALS;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsynctypedef struct VBOXRAWPCIINS *PVBOXRAWPCIINS;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync/**
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * The per-instance data of the VBox raw PCI interface.
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync *
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * This is data associated with a host PCI card which
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * the filter driver has been or may be attached to. When possible it is
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * attached dynamically, but this may not be possible on all OSes so we have
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * to be flexible about things.
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync *
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsynctypedef struct VBOXRAWPCIINS
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync{
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Pointer to the globals. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync PVBOXRAWPCIGLOBALS pGlobals;
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync /** Mutex protecting device access. */
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync RTSEMFASTMUTEX hFastMtx;
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync /** The spinlock protecting the state variables and device access. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync RTSPINLOCK hSpinlock;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Pointer to the next device in the list. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync PVBOXRAWPCIINS pNext;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Reference count. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync uint32_t volatile cRefs;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /* Host PCI address of this device. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync uint32_t HostPciAddress;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync#ifdef RT_OS_LINUX
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync struct pci_dev * pPciDev;
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync#endif
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync bool fMsiUsed;
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync bool fMsixUsed;
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync bool fIommuUsed;
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync bool fPad0;
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync
1f73d6e394af91adc1608bd0a917dff9ec4ee874vboxsync /** The session this interface is associated with. */
1f73d6e394af91adc1608bd0a917dff9ec4ee874vboxsync PSUPDRVSESSION pSession;
1f73d6e394af91adc1608bd0a917dff9ec4ee874vboxsync /** The SUPR0 object id. */
1f73d6e394af91adc1608bd0a917dff9ec4ee874vboxsync void *pvObj;
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Port, given to the outside world. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync RAWPCIDEVPORT DevPort;
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsync
80559ecb51cb45f6869d8450a1317ead0dd5129dvboxsync uint32_t cHandlersCount;
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsync PFNRAWPCIISR pfnIrqHandler;
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsync void *pIrqContext;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync} VBOXRAWPCIINS;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync/**
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * The global data of the VBox PCI driver.
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync *
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * This contains the bit required for communicating with support driver, VBoxDrv
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * (start out as SupDrv).
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsynctypedef struct VBOXRAWPCIGLOBALS
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync{
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Mutex protecting the list of instances and state changes. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync RTSEMFASTMUTEX hFastMtx;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Pointer to a list of instance data. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync PVBOXRAWPCIINS pInstanceHead;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** The raw PCI interface factory. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync RAWPCIFACTORY RawPciFactory;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** The SUPDRV component factory registration. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync SUPDRVFACTORY SupDrvFactory;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** The number of current factory references. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync int32_t volatile cFactoryRefs;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** Whether the IDC connection is open or not.
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync * This is only for cleaning up correctly after the separate IDC init on Windows. */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync bool fIDCOpen;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync /** The SUPDRV IDC handle (opaque struct). */
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync SUPDRVIDCHANDLE SupDrvIDC;
2d3c9a4b29fcd6be8b49f5967c6e98553549b515vboxsync#ifdef RT_OS_LINUX
2d3c9a4b29fcd6be8b49f5967c6e98553549b515vboxsync struct module * pciStubModule;
2d3c9a4b29fcd6be8b49f5967c6e98553549b515vboxsync#endif
2d3c9a4b29fcd6be8b49f5967c6e98553549b515vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync} VBOXRAWPCIGLOBALS;
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsyncDECLHIDDEN(int) vboxPciInit(PVBOXRAWPCIGLOBALS pGlobals);
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsyncDECLHIDDEN(void) vboxPciShutdown(PVBOXRAWPCIGLOBALS pGlobals);
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
bcf9fab594306cd97251f7f03b8319a158c29ea5vboxsyncDECLHIDDEN(int) vboxPciOsDevInit (PVBOXRAWPCIINS pIns, uint32_t fFlags);
bcf9fab594306cd97251f7f03b8319a158c29ea5vboxsyncDECLHIDDEN(int) vboxPciOsDevDeinit(PVBOXRAWPCIINS pIns, uint32_t fFlags);
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsync
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsyncDECLHIDDEN(int) vboxPciOsDevGetRegionInfo(PVBOXRAWPCIINS pIns,
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync int32_t iRegion,
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync RTHCPHYS *pRegionStart,
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync uint64_t *pu64RegionSize,
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsync bool *pfPresent,
464697bd4c58e78f3b3eecc1d51904482bae27f8vboxsync uint32_t *pfFlags);
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsyncDECLHIDDEN(int) vboxPciOsDevMapRegion(PVBOXRAWPCIINS pIns,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync int32_t iRegion,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync RTHCPHYS pRegionStart,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync uint64_t u64RegionSize,
1e4093b98e92fd2f47c3126f2dfb3ba33d7f77dcvboxsync uint32_t fFlags,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync RTR0PTR *pRegionBase);
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsyncDECLHIDDEN(int) vboxPciOsDevUnmapRegion(PVBOXRAWPCIINS pIns,
1e4093b98e92fd2f47c3126f2dfb3ba33d7f77dcvboxsync int32_t iRegion,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync RTHCPHYS RegionStart,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync uint64_t u64RegionSize,
c97d00f4828608e3ac87e48fee3dfa8bc4437bf1vboxsync RTR0PTR RegionBase);
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsync
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsyncDECLHIDDEN(int) vboxPciOsDevPciCfgWrite(PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
2c709acd5e2f434e71614aa89020bf8d0776a1e9vboxsyncDECLHIDDEN(int) vboxPciOsDevPciCfgRead (PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
bcf9fab594306cd97251f7f03b8319a158c29ea5vboxsync
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsyncDECLHIDDEN(int) vboxPciOsDevRegisterIrqHandler (PVBOXRAWPCIINS pIns, PFNRAWPCIISR pfnHandler, void* pIrqContext, int32_t *piHostIrq);
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsyncDECLHIDDEN(int) vboxPciOsDevUnregisterIrqHandler(PVBOXRAWPCIINS pIns, int32_t iHostIrq);
1fff175c9a0fea173ee52a209224dc6ecbd39572vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsyncRT_C_DECLS_END
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync
f73c68fe41a3db55167b7266efd6955e5dbd0b47vboxsync#endif