Index: /trunk/include/VBox/rawpci.h
===================================================================
--- /trunk/include/VBox/rawpci.h	(revision 35920)
+++ /trunk/include/VBox/rawpci.h	(revision 35920)
@@ -0,0 +1,193 @@
+/** @file
+ * PDM - Pluggable Device Manager, raw PCI Devices. (VMM)
+ */
+
+/*
+ * Copyright (C) 2010-2011 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+#ifndef ___VBox_rawpci_h
+#define ___VBox_rawpci_h
+
+#include <iprt/types.h>
+
+
+RT_C_DECLS_BEGIN
+
+/** Parameters buffer for PCIRAWR0_DO_GET_REGION_INFO call */
+typedef struct
+{
+    /* in */
+    int32_t  iRegion;
+    /* out */
+    RTHCPHYS RegionStart;
+    uint64_t u64RegionSize;
+    bool     fPresent;
+    bool     fMmio;
+} PCIRAWREQGETREGIONINFO;
+
+/** Parameters buffer for PCIRAWR0_DO_MAP_REGION call. */
+typedef struct
+{
+    /* in */
+    RTHCPHYS             StartAddress;
+    uint64_t             iRegionSize;
+    uint32_t             fFlags;
+    /* out */
+    RTR3PTR              pvAddressR3;
+    RTR0PTR              pvAddressR0;
+} PCIRAWREQMAPREGION;
+
+/** Parameters buffer for PCIRAWR0_DO_UNMAP_REGION call. */
+typedef struct
+{
+    /* in */
+    RTR3PTR              pvAddressR3;
+    RTR0PTR              pvAddressR0;
+} PCIRAWREQUNMAPREGION;
+
+/** Parameters buffer for PCIRAWR0_DO_PIO_WRITE call. */
+typedef struct
+{
+    /* in */
+    uint16_t             iPort;
+    uint16_t             cb;
+    uint32_t             iValue;
+} PCIRAWREQPIOWRITE;
+
+/** Parameters buffer for PCIRAWR0_DO_PIO_READ call. */
+typedef struct
+{
+    /* in */
+    uint16_t             iPort;
+    uint16_t             cb;
+    /* out */
+    uint32_t             iValue;
+} PCIRAWREQPIOREAD;
+
+/** Memory operand. */
+typedef struct
+{
+    union
+    {
+        uint8_t          u8;
+        uint16_t         u16;
+        uint32_t         u32;
+        uint64_t         u64;
+    } u;
+    uint8_t cb;
+} PCIRAWMEMLOC;
+
+/** Parameters buffer for PCIRAWR0_DO_MMIO_WRITE call. */
+typedef struct
+{
+    /* in */
+    RTGCPHYS             Address;
+    PCIRAWMEMLOC         Value;
+} PCIRAWREQMMIOWRITE;
+
+/** Parameters buffer for PCIRAWR0_DO_MMIO_READ call. */
+typedef struct
+{
+    /* in */
+    RTGCPHYS             Address;
+    /* inout (Value.cb is in) */
+    PCIRAWMEMLOC         Value;
+} PCIRAWREQMMIOREAD;
+
+/* Parameters buffer for PCIRAWR0_DO_PCICFG_WRITE call. */
+typedef struct
+{
+    /* in */
+    uint32_t             iOffset;
+    PCIRAWMEMLOC         Value;
+} PCIRAWREQPCICFGWRITE;
+
+/** Parameters buffer for PCIRAWR0_DO_PCICFG_READ call. */
+typedef struct
+{
+    /* in */
+    uint32_t             iOffset;
+    /* inout (Value.cb is in) */
+    PCIRAWMEMLOC         Value;
+} PCIRAWREQPCICFGREAD;
+
+/**
+ * Request buffer use for communication with the driver.
+ */
+typedef struct PCIRAWSENDREQ
+{
+    /** The request header. */
+    SUPVMMR0REQHDR  Hdr;
+    /** Alternative to passing the taking the session from the VM handle.
+     *  Either use this member or use the VM handle, don't do both.
+     */
+    PSUPDRVSESSION  pSession;
+    /** Request type. */
+    int32_t         iRequest;
+    /** Host device request targetted to. */
+    uint32_t        TargetDevice;
+    /** Call parameters. */
+    union
+    {
+        PCIRAWREQGETREGIONINFO aGetRegionInfo;
+        PCIRAWREQMAPREGION     aMapRegion;
+        PCIRAWREQUNMAPREGION   aUnmapRegion;
+        PCIRAWREQPIOWRITE      aPioWrite;
+        PCIRAWREQPIOREAD       aPioRead;
+        PCIRAWREQMMIOWRITE     aMmioWrite;
+        PCIRAWREQMMIOREAD      aMmioRead;
+        PCIRAWREQPCICFGWRITE   aPciCfgWrite;
+        PCIRAWREQPCICFGREAD    aPciCfgRead;
+    } u;
+} PCIRAWSENDREQ;
+typedef PCIRAWSENDREQ *PPCIRAWSENDREQ;
+
+
+/**
+ * Operations performed by the driver.
+ */
+typedef enum PCIRAWR0OPERATION
+{
+    /* Get PCI region info. */
+    PCIRAWR0_DO_GET_REGION_INFO,
+    /* Map PCI region into VM address space. */
+    PCIRAWR0_DO_MAP_REGION,
+    /* Unmap PCI region from VM address space. */
+    PCIRAWR0_DO_UNMAP_REGION,
+    /* Perform PIO write. */
+    PCIRAWR0_DO_PIO_WRITE,
+    /* Perform PIO read. */
+    PCIRAWR0_DO_PIO_READ,
+    /* Perform MMIO write. */
+    PCIRAWR0_DO_MMIO_WRITE,
+    /* Perform MMIO read. */
+    PCIRAWR0_DO_MMIO_READ,
+    /* Perform PCI config write. */
+    PCIRAWR0_DO_PCICFG_WRITE,
+    /* Perform PCI config read. */
+    PCIRAWR0_DO_PCICFG_READ,
+    /** The usual 32-bit type blow up. */
+    PCIRAWR0_DO_32BIT_HACK = 0x7fffffff
+} PCIRAWR0OPERATION;
+
+RT_C_DECLS_END
+
+#endif
Index: /trunk/src/VBox/HostDrivers/Makefile.kmk
===================================================================
--- /trunk/src/VBox/HostDrivers/Makefile.kmk	(revision 35919)
+++ /trunk/src/VBox/HostDrivers/Makefile.kmk	(revision 35920)
@@ -40,4 +40,10 @@
  ifeq ($(KBUILD_TARGET),darwin)
   include $(PATH_SUB_CURRENT)/darwin/Makefile.kmk
+ endif
+
+ if1of ($(KBUILD_TARGET), linux)
+  ifdef VBOX_WITH_PCI_PASSTHROUGH
+   include $(PATH_SUB_CURRENT)/VBoxPci/Makefile.kmk
+  endif
  endif
 
Index: /trunk/src/VBox/HostDrivers/VBoxPci/Makefile.kmk
===================================================================
--- /trunk/src/VBox/HostDrivers/VBoxPci/Makefile.kmk	(revision 35920)
+++ /trunk/src/VBox/HostDrivers/VBoxPci/Makefile.kmk	(revision 35920)
@@ -0,0 +1,78 @@
+SUB_DEPTH = ../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+ifeq (1,1)
+
+if1of ($(KBUILD_TARGET), linux)
+
+SYSMODS += VBoxPci
+VBoxPci_TEMPLATE         = VBOXR0DRV
+VBoxPci_INST = $(INST_VBOXPCI)$(if $(eq $(KBUILD_TARGET),darwin),Contents/MacOS/)
+VBoxPci_NAME.linux       = vboxpci
+VBoxPci_NOINST.linux     = true
+VBoxPci_DEFS             = IN_RT_R0 VBOX_SVN_REV=$(VBOX_SVN_REV) IN_SUP_STATIC
+VBoxPci_DEFS.linux       = KBUILD_MODNAME=KBUILD_STR\(vboxpci\) KBUILD_BASENAME=KBUILD_STR\(vboxpci\) MODULE
+VBoxPci_INCS.linux   := \
+	$(PATH_ROOT)/src/VBox/Runtime/r0drv/linux
+VBoxPci_INCS             = \
+	.
+VBoxPci_SOURCES.linux   = \
+	linux/VBoxPci-linux.c \
+	VBoxPci.c
+VBoxPci_SOURCES          =
+VBoxPci_LIBS            += \
+	$(PATH_LIB)/SUPR0IdcClient$(VBOX_SUFF_LIB)
+
+endif
+
+
+ifeq ($(KBUILD_TARGET),linux)
+
+ include $(PATH_SUB_CURRENT)/linux/files_vboxpci
+
+ INSTALLS += VBoxPci-src VBoxPci-sh
+
+ VBoxPci-src_INST    = bin/src/vboxpci/
+ VBoxPci-src_MODE    = a+r,u+w
+ VBoxPci-src_SOURCES = $(subst ",,$(VBOX_VBOXPCI_SOURCES)) #"
+ VBoxPci-src_SOURCES+= \
+        $(VBoxPci-src_0_OUTDIR)/Makefile
+ VBoxPci-src_CLEAN   = \
+        $(VBoxPci-src_0_OUTDIR)/Makefile     \
+        $(PATH_TARGET)/VBoxPciSrc-src-1.dep
+
+ VBoxPci-sh_INST    = bin/src/vboxpci/
+ VBoxPci-sh_MODE    = a+rx,u+w
+ VBoxPci-sh_SOURCES = \
+	$(VBoxPci-sh_0_OUTDIR)/build_in_tmp \
+	$(PATH_ROOT)/src/VBox/HostDrivers/linux/do_Module.symvers
+ VBoxPci-sh_CLEAN   = $(VBoxPci-sh_0_OUTDIR)/build_in_tmp
+
+
+includedep $(PATH_TARGET)/VBoxPci-src-1.dep
+$$(VBoxPci-src_0_OUTDIR)/Makefile: \
+		$(PATH_SUB_CURRENT)/linux/Makefile \
+		$$(if $$(eq $$(VBoxPci/linux/Makefile_VBOX_HARDENED),$$(VBOX_WITH_HARDENING)),,FORCE) \
+		| $$(dir $$@)
+ifndef VBOX_WITH_HARDENING
+	$(QUIET)$(SED) -e "s;-DVBOX_WITH_HARDENING;;g" --output $@ $<
+else
+	$(QUIET)$(CP) -f $< $@
+endif
+	%$(QUIET2)$(RM) -f -- $(PATH_TARGET)/VBoxPci-src-1.dep
+	%$(QUIET2)$(APPEND) '$(PATH_TARGET)/VBoxPci-src-1.dep' 'VBoxPci/linux/Makefile_VBOX_HARDENED=$(VBOX_WITH_HARDENING)'
+
+## Scripts needed for building the kernel modules
+
+$$(VBoxPci-sh_0_OUTDIR)/build_in_tmp: \
+		$(PATH_ROOT)/src/VBox/HostDrivers/linux/build_in_tmp \
+		$(VBOX_VERSION_STAMP) \
+		| $$(dir $$@)
+	$(call MSG_TOOL,Creating,,$@)
+	$(QUIET)$(SED) -e "s;_VERSION_;${VBOX_VERSION_STRING};g; s;_MODULE_;vboxpci;g; s;_BUILDTYPE_;${KBUILD_TYPE};g" --output $@ $<
+	$(QUIET)chmod 0755 $@
+endif
+
+endif
+
+include $(KBUILD_PATH)/subfooter.kmk
Index: /trunk/src/VBox/HostDrivers/VBoxPci/VBoxPci.c
===================================================================
--- /trunk/src/VBox/HostDrivers/VBoxPci/VBoxPci.c	(revision 35920)
+++ /trunk/src/VBox/HostDrivers/VBoxPci/VBoxPci.c	(revision 35920)
@@ -0,0 +1,37 @@
+/* $Id $ */
+/** @file
+ * VBoxPci - PCI card passthrough support (Host), Common Code.
+ */
+
+/*
+ * Copyright (C) 2011 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+/** @page pg_rawpci     VBoxPci - host PCI support
+ *
+ * This is a kernel module that works as host proxy between guest and 
+ * PCI hardware.
+ *
+ */
+
+#define LOG_GROUP LOG_GROUP_PCI_RAW
+#include "VBoxPciInternal.h"
+
+#include <VBox/log.h>
+#include <VBox/err.h>
+#include <iprt/string.h>
+
+#include <VBox/sup.h>
+#include <iprt/assert.h>
+#include <iprt/spinlock.h>
+#include <iprt/uuid.h>
+#include <VBox/version.h>
+
Index: /trunk/src/VBox/HostDrivers/VBoxPci/VBoxPciInternal.h
===================================================================
--- /trunk/src/VBox/HostDrivers/VBoxPci/VBoxPciInternal.h	(revision 35920)
+++ /trunk/src/VBox/HostDrivers/VBoxPci/VBoxPciInternal.h	(revision 35920)
@@ -0,0 +1,27 @@
+/* $Id$ */
+/** @file
+ * VBoxPci - PCI driver (Host), Internal Header.
+ */
+
+/*
+ * Copyright (C) 2011 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+#ifndef ___VBoPciInternal_h___
+#define ___VBoxPciInternal_h___
+
+#include <VBox/sup.h>
+#include <VBox/rawpci.h>
+#include <iprt/semaphore.h>
+#include <iprt/assert.h>
+
+#endif
+
Index: /trunk/src/VBox/HostDrivers/linux/Makefile
===================================================================
--- /trunk/src/VBox/HostDrivers/linux/Makefile	(revision 35919)
+++ /trunk/src/VBox/HostDrivers/linux/Makefile	(revision 35920)
@@ -27,5 +27,7 @@
  obj-m += vboxnetadp/
 endif
-
+ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxpci/Makefile),)
+ obj-m += vboxpci/
+endif
 else # ! KBUILD_EXTMOD
 
@@ -57,4 +59,13 @@
 	    echo; \
 	fi
+	@if [ -d vboxpci ]; then \
+	    if [ -f vboxdrv/Module.symvers ]; then \
+	        cp vboxdrv/Module.symvers vboxpci; \
+	    fi; \
+	    echo "*** Building 'vboxpci' module ***"; \
+	    $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxpci; \
+	    cp vboxpci/vboxpci.ko .; \
+	    echo; \
+	fi
 
 
@@ -67,4 +78,7 @@
 	    $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetadp install; \
 	fi
+	@if [ -d vboxpci ]; then \
+	    $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxpci install; \
+	fi
 
 clean:
@@ -76,8 +90,11 @@
 	    $(MAKE) -C vboxnetadp clean; \
 	fi
-	rm -f vboxdrv.ko vboxnetflt.ko vboxnetadp.ko
+	@if [ -d vboxpci ]; then \
+	    $(MAKE) -C vboxpci clean; \
+	fi
+	rm -f vboxdrv.ko vboxnetflt.ko vboxnetadp.ko vboxpci.ko 
 
 unload:
-	@for module in vboxnetadp vboxnetflt vboxdrv; do \
+	@for module in vboxnetadp vboxnetflt vboxdrv vboxpci; do \
 		if grep "^$$module " /proc/modules >/dev/null; then \
 			echo "Removing previously installed $$module module"; \
@@ -87,5 +104,5 @@
 
 load: unload
-	@for module in vboxdrv vboxnetflt vboxnetadp; do \
+	@for module in vboxdrv vboxnetflt vboxnetadp vboxpci; do \
 		if test -f $$module.ko; then \
 			echo "Installing $$module module"; \
Index: /trunk/src/VBox/HostDrivers/linux/dkms.conf
===================================================================
--- /trunk/src/VBox/HostDrivers/linux/dkms.conf	(revision 35919)
+++ /trunk/src/VBox/HostDrivers/linux/dkms.conf	(revision 35920)
@@ -30,2 +30,6 @@
 _OMIT_VBOXNETADP_BUILT_MODULE_LOCATION[2]="vboxnetadp"
 _OMIT_VBOXNETADP_DEST_MODULE_LOCATION[2]="/kernel/misc"
+
+_OMIT_VBOXPCI_BUILT_MODULE_NAME[1]="vboxpci"
+_OMIT_VBOXPCI_BUILT_MODULE_LOCATION[1]="vboxpci"
+_OMIT_VBOXPCI_DEST_MODULE_LOCATION[1]="/kernel/misc"
Index: /trunk/src/VBox/HostDrivers/linux/export_modules
===================================================================
--- /trunk/src/VBox/HostDrivers/linux/export_modules	(revision 35919)
+++ /trunk/src/VBox/HostDrivers/linux/export_modules	(revision 35920)
@@ -34,4 +34,5 @@
 PATH_VBOXNET="$PATH_ROOT/src/VBox/HostDrivers/VBoxNetFlt"
 PATH_VBOXADP="$PATH_ROOT/src/VBox/HostDrivers/VBoxNetAdp"
+PATH_VBOXPCI="$PATH_ROOT/src/VBox/HostDrivers/VBoxPci"
 
 VBOX_VERSION_MAJOR=`sed -e "s/^ *VBOX_VERSION_MAJOR *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Config.kmk`
@@ -39,9 +40,10 @@
 VBOX_VERSION_BUILD=`sed -e "s/^ *VBOX_VERSION_BUILD *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Config.kmk`
 VBOX_VERSION_STRING=$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD
-VBOX_SVN_REV=`sed -e 's/^ *VBOX_SVN_REV_FALLBACK *:= \+\$(patsubst *%:,, *\$Rev: *\([0-9]\+\) *\$ *) */\1/;t;d' $PATH_ROOT/Config.kmk`                                                                                                        VBOX_VENDOR=`sed -e 's/^ *VBOX_VENDOR *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`                                     VBOX_VENDOR_SHORT=`sed -e 's/^ *VBOX_VENDOR_SHORT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`                         VBOX_PRODUCT=`sed -e 's/^ *VBOX_PRODUCT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`                                   VBOX_C_YEAR=`date +%Y`                                                                                                 
+VBOX_SVN_REV=`sed -e 's/^ *VBOX_SVN_REV_FALLBACK *:= \+\$(patsubst *%:,, *\$Rev: *\([0-9]\+\) *\$ *) */\1/;t;d' $PATH_ROOT/Config.kmk`                                                                                                        VBOX_VENDOR=`sed -e 's/^ *VBOX_VENDOR *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`                                     VBOX_VENDOR_SHORT=`sed -e 's/^ *VBOX_VENDOR_SHORT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`                         VBOX_PRODUCT=`sed -e 's/^ *VBOX_PRODUCT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`                                   VBOX_C_YEAR=`date +%Y`
 
 . $PATH_VBOXDRV/linux/files_vboxdrv
 . $PATH_VBOXNET/linux/files_vboxnetflt
 . $PATH_VBOXADP/linux/files_vboxnetadp
+. $PATH_VBOXPCI/linux/files_vboxpci
 
 # Temporary path for creating the modules, will be removed later
@@ -124,4 +126,18 @@
 fi
 
+# vboxpci (VirtualBox host PCI access kernel module)
+mkdir $PATH_TMP/vboxpci || exit 1
+for f in $VBOX_VBOXPCI_SOURCES; do
+    install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxpci/`echo $f|cut -d'>' -f2`"
+done
+sed -e "s;_VERSION_;$VBOX_VERSION_STRING;g" < $PATH_LINUX/build_in_tmp > $PATH_TMP/vboxpci/build_in_tmp
+chmod 0755 $PATH_TMP/vboxpci/build_in_tmp
+sed -e "s;_VERSION_;$VBOX_VERSION_STRING;g" < $PATH_VBOXPCI/linux/dkms.conf > $PATH_TMP/vboxpci/dkms.conf
+if [ -n "$VBOX_WITH_HARDENING" ]; then
+    cat                                   $PATH_VBOXPCI/linux/Makefile > $PATH_TMP/vboxpci/Makefile
+else
+    sed -e "s;-DVBOX_WITH_HARDENING;;g" < $PATH_VBOXPCI/linux/Makefile > $PATH_TMP/vboxpci/Makefile
+fi
+
 install -D -m 0644 $PATH_LINUX/Makefile $PATH_TMP/Makefile
 
@@ -136,3 +152,2 @@
 # Remove the temporary directory
 rm -r $PATH_TMP
-
