Author: dexuan
Date: Wed Nov 16 09:25:00 2016
New Revision: 308725
URL: https://svnweb.freebsd.org/changeset/base/308725
Log:
hyperv/pcib: enable PCIe pass-through (a.k.a. Discrete Device Assignment)
The feature enables us to pass through physical PCIe devices to FreeBSD VM
running on Hyper-V (Windows Server 2016) to get near-native performance with
low CPU utilization.
The patch implements a PCI bridge driver to support the feature:
1) The pcib driver talks to the host to discover device(s) and presents
the device(s) to FreeBSD's pci driver via PCI configuration space (note:
to access the configuration space, we don't use the standard I/O port
0xCF8/CFC method; instead, we use an MMIO-based method supplied by Hyper-V,
which is very similar to the 0xCF8/CFC method).
2) The pcib driver allocates resources for the device(s) and initialize
the related BARs, when the device driver's attach method is invoked;
3) The pcib driver talks to the host to create MSI/MSI-X interrupt
remapping between the guest and the host;
4) The pcib driver supports device hot add/remove.
Reviewed by: sephe
Approved by: sephe (mentor)
MFC after:1 week
Sponsored by: Microsoft
Differential Revision:https://reviews.freebsd.org/D8332
Added:
head/sys/dev/hyperv/pcib/
head/sys/dev/hyperv/pcib/pcib.c (contents, props changed)
head/sys/modules/hyperv/pcib/
head/sys/modules/hyperv/pcib/Makefile (contents, props changed)
Modified:
head/sys/conf/files.amd64
head/sys/conf/files.i386
Modified: head/sys/conf/files.amd64
==
--- head/sys/conf/files.amd64 Wed Nov 16 09:08:32 2016(r308724)
+++ head/sys/conf/files.amd64 Wed Nov 16 09:25:00 2016(r308725)
@@ -292,6 +292,7 @@ dev/hwpmc/hwpmc_uncore.coptionalhwpmc
dev/hwpmc/hwpmc_piv.c optionalhwpmc
dev/hwpmc/hwpmc_tsc.c optionalhwpmc
dev/hwpmc/hwpmc_x86.c optionalhwpmc
+dev/hyperv/pcib/pcib.c optionalhyperv
dev/hyperv/netvsc/hn_nvs.c optionalhyperv
dev/hyperv/netvsc/hn_rndis.c optionalhyperv
dev/hyperv/netvsc/if_hn.c optionalhyperv
Modified: head/sys/conf/files.i386
==
--- head/sys/conf/files.i386Wed Nov 16 09:08:32 2016(r308724)
+++ head/sys/conf/files.i386Wed Nov 16 09:25:00 2016(r308725)
@@ -249,6 +249,7 @@ dev/hwpmc/hwpmc_piv.c optional hwpmc
dev/hwpmc/hwpmc_ppro.c optional hwpmc
dev/hwpmc/hwpmc_tsc.c optional hwpmc
dev/hwpmc/hwpmc_x86.c optional hwpmc
+dev/hyperv/pcib/pcib.c optionalhyperv
dev/hyperv/netvsc/hn_nvs.c optionalhyperv
dev/hyperv/netvsc/hn_rndis.c optionalhyperv
dev/hyperv/netvsc/if_hn.c optionalhyperv
Added: head/sys/dev/hyperv/pcib/pcib.c
==
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/sys/dev/hyperv/pcib/pcib.c Wed Nov 16 09:25:00 2016
(r308725)
@@ -0,0 +1,1790 @@
+/*-
+ * Copyright (c) 2016 Microsoft Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include
+__FBSDID("$FreeBSD$");
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include