All of lore.kernel.org
 help / color / mirror / Atom feed
* [pvops-dom0] [patch] Hook Linux's PCI probe and remove callbacks
@ 2009-07-16  5:15 Han, Weidong
  2009-07-16  7:18 ` Han, Weidong
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Han, Weidong @ 2009-07-16  5:15 UTC (permalink / raw)
  To: 'jeremy@goop.org'
  Cc: 'Keir, 'xen-devel@lists.xensource.com', Kay, Allen M,
	Fraser'

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

Hijack the pci_bus_type probe and remove callbacks. This option only
requires modification to the Xen specific part of Linux.

This is useful to add and remove pci device to Xen hypervisor when
load and remove its driver. For example, when VFs are created by PF,
they will be added to Xen hypervisor, and then can be assigned to guest.

This patch is based on xen-tip-master branch of jeremy's pv-ops tree.


Signed-off-by: Weidong Han <weidong.han@intel.com>
Signed-off-by: Allen Kay <allen.m.kay@intel.com>

[-- Attachment #2: 0001-Hook-Linux-s-PCI-probe-and-remove-callbacks.patch --]
[-- Type: application/octet-stream, Size: 4874 bytes --]

From ada197119ddc3ed692bdc085f97024c8e27730d1 Mon Sep 17 00:00:00 2001
From: Weidong Han <weidong.han@intel.com>
Date: Thu, 16 Jul 2009 20:37:02 +0800
Subject: [PATCH] Hook Linux's PCI probe and remove callbacks

Hijack the pci_bus_type probe and remove callbacks. This option only
requires modification to the Xen specific part of Linux.

This is useful to add and remove pci device to Xen hypervisor when
load and remove its driver. For example, when VFs are created by PF,
they will be added to Xen hypervisor, and then can be assigned to guest.

Signed-off-by: Weidong Han <weidong.han@intel.com>
Signed-off-by: Allen Kay <allen.m.kay@intel.com>
---
 drivers/xen/Makefile            |    3 +-
 drivers/xen/pci.c               |   84 +++++++++++++++++++++++++++++++++++++++
 include/xen/interface/physdev.h |   21 ++++++++++
 3 files changed, 107 insertions(+), 1 deletions(-)
 create mode 100644 drivers/xen/pci.c

diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 007aa99..a76dca5 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -1,6 +1,7 @@
 obj-y	+= grant-table.o features.o events.o manage.o biomerge.o
 obj-y	+= xenbus/
 
+obj-$(CONFIG_PCI)			+= pci.o
 obj-$(CONFIG_HOTPLUG_CPU)		+= cpu_hotplug.o
 obj-$(CONFIG_XEN_XENCOMM)		+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)		+= balloon.o
@@ -9,4 +10,4 @@ obj-$(CONFIG_XEN_GNTDEV)	+= gntdev.o
 obj-$(CONFIG_XEN_BLKDEV_BACKEND)	+= blkback/
 obj-$(CONFIG_XEN_NETDEV_BACKEND)	+= netback/
 obj-$(CONFIG_XENFS)			+= xenfs/
-obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
\ No newline at end of file
+obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c
new file mode 100644
index 0000000..8308b29
--- /dev/null
+++ b/drivers/xen/pci.c
@@ -0,0 +1,84 @@
+/*
+ * vim:shiftwidth=8:noexpandtab
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <xen/interface/physdev.h>
+#include <asm/xen/hypercall.h>
+#include "../pci/pci.h"
+
+static int (*pci_bus_probe)(struct device *dev);
+static int (*pci_bus_remove)(struct device *dev);
+
+static int pci_bus_probe_wrapper(struct device *dev)
+{
+	int r;
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct physdev_manage_pci manage_pci;
+	struct physdev_manage_pci_ext manage_pci_ext;
+
+#ifdef CONFIG_PCI_IOV
+	if (pci_dev->is_virtfn) {
+		memset(&manage_pci_ext, 0, sizeof(manage_pci_ext));
+		manage_pci_ext.bus = pci_dev->bus->number;
+		manage_pci_ext.devfn = pci_dev->devfn;
+		manage_pci_ext.is_virtfn = 1;
+		manage_pci_ext.physfn.bus = pci_dev->physfn->bus->number;
+		manage_pci_ext.physfn.devfn = pci_dev->physfn->devfn;
+		r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add_ext,
+					  &manage_pci_ext);
+	} else
+#endif
+	if (pci_ari_enabled(pci_dev->bus) && PCI_SLOT(pci_dev->devfn)) {
+		memset(&manage_pci_ext, 0, sizeof(manage_pci_ext));
+		manage_pci_ext.bus = pci_dev->bus->number;
+		manage_pci_ext.devfn = pci_dev->devfn;
+		manage_pci_ext.is_extfn = 1;
+		r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add_ext,
+					  &manage_pci_ext);
+	} else {
+		manage_pci.bus = pci_dev->bus->number;
+		manage_pci.devfn = pci_dev->devfn;
+		r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add,
+					  &manage_pci);
+	}
+	if (r && r != -ENOSYS)
+		return r;
+
+	r = pci_bus_probe(dev);
+	return r;
+}
+
+static int pci_bus_remove_wrapper(struct device *dev)
+{
+	int r;
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct physdev_manage_pci manage_pci;
+	manage_pci.bus = pci_dev->bus->number;
+	manage_pci.devfn = pci_dev->devfn;
+
+	r = pci_bus_remove(dev);
+	/* dev and pci_dev are no longer valid!! */
+
+	WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove,
+		&manage_pci));
+	return r;
+}
+
+static int __init hook_pci_bus(void)
+{
+	if (!xen_domain() || !xen_initial_domain())
+		return 0;
+
+	pci_bus_probe = pci_bus_type.probe;
+	pci_bus_type.probe = pci_bus_probe_wrapper;
+
+	pci_bus_remove = pci_bus_type.remove;
+	pci_bus_type.remove = pci_bus_remove_wrapper;
+
+	return 0;
+}
+
+core_initcall(hook_pci_bus);
diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physdev.h
index cd69391..dd08c7d 100644
--- a/include/xen/interface/physdev.h
+++ b/include/xen/interface/physdev.h
@@ -106,6 +106,27 @@ struct physdev_irq {
 	uint32_t vector;
 };
 
+#define PHYSDEVOP_manage_pci_add         15
+#define PHYSDEVOP_manage_pci_remove      16
+struct physdev_manage_pci {
+    /* IN */
+    uint8_t bus;
+    uint8_t devfn;
+};
+
+#define PHYSDEVOP_manage_pci_add_ext     20
+struct physdev_manage_pci_ext {
+    /* IN */
+    uint8_t bus;
+    uint8_t devfn;
+    unsigned is_extfn;
+    unsigned is_virtfn;
+    struct {
+        uint8_t bus;
+        uint8_t devfn;
+    } physfn;
+};
+
 /*
  * Argument to physdev_op_compat() hypercall. Superceded by new physdev_op()
  * hypercall since 0x00030202.
-- 
1.6.0.4


[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-07-20 17:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-16  5:15 [pvops-dom0] [patch] Hook Linux's PCI probe and remove callbacks Han, Weidong
2009-07-16  7:18 ` Han, Weidong
2009-07-17  6:28 ` Andy Burns
2009-07-17 23:14 ` Jeremy Fitzhardinge
2009-07-17 23:42   ` Kay, Allen M
2009-07-19 11:55     ` Jiang, Yunhong
2009-07-20  9:03       ` Han, Weidong
2009-07-20 17:01       ` Jeremy Fitzhardinge
2009-07-20 17:12         ` Jesse Barnes
2009-07-20 17:00     ` Jeremy Fitzhardinge

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.