WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [GIT PULL] Xen updates

To: Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [GIT PULL] Xen updates
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Wed, 27 Oct 2010 18:34:07 +0100
Cc: Jeremy Fitzhardinge <jeremy@xxxxxxxx>, "Xen-devel@xxxxxxxxxxxxxxxxxxx" <Xen-devel@xxxxxxxxxxxxxxxxxxx>, Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>, Sander Eikelenboom <linux@xxxxxxxxxxxxxx>, Konrad
Delivery-date: Wed, 27 Oct 2010 10:35:35 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <alpine.DEB.2.00.1010271820400.1407@kaball-desktop>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <4CC7681B.9060301@xxxxxxxx> <528869330.20101027105603@xxxxxxxxxxxxxx> <1288170828.8361.161.camel@xxxxxxxxxxxxxxxxxxxxxx> <266556691.20101027115009@xxxxxxxxxxxxxx> <alpine.DEB.2.00.1010271142220.1407@kaball-desktop> <61405929.20101027172904@xxxxxxxxxxxxxx> <alpine.DEB.2.00.1010271814160.1407@kaball-desktop> <alpine.DEB.2.00.1010271820400.1407@kaball-desktop>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
On Wed, 27 Oct 2010, Stefano Stabellini wrote:
> commit 8cd3c8d3c59c3d349c91108a8b0016c5a6aaf46d
> Author: Weidong Han <weidong.han@xxxxxxxxx>
> Date:   Wed Oct 27 17:55:04 2010 +0100
> 
>     xen: register xen pci notifier
>     
>     Register the notifier to handle hot-plug devices and SR-IOV devices
>     for Xen hypervisor. When a device is hot added or removed, it adds
>     or removes it to Xen via hypercalls.
>     
>     Signed-off-by: Weidong Han <weidong.han@xxxxxxxxx>
>     Signed-off-by: Qing He <qing.he@xxxxxxxxx>
>     Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
>     Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
> 

I realize that the description of the commit is out of date so I wrote a
new one:

---

commit d5940db0f915c3e045fe18a60a2ef2145bf85b1c
Author: Weidong Han <weidong.han@xxxxxxxxx>
Date:   Wed Oct 27 17:55:04 2010 +0100

    xen: register xen pci notifier
    
    Register a pci notifier to add (or remove) pci devices to Xen via
    hypercalls. Xen needs to know the pci devices present in the system to
    handle pci passthrough and even MSI remapping in the initial domain.
    
    Signed-off-by: Weidong Han <weidong.han@xxxxxxxxx>
    Signed-off-by: Qing He <qing.he@xxxxxxxxx>
    Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
    Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index b978645..a572a45 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_XENFS)           += xenfs/
 obj-$(CONFIG_XEN_SYS_HYPERVISOR)       += sys-hypervisor.o
 obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o
 obj-$(CONFIG_SWIOTLB_XEN)      += swiotlb-xen.o
+obj-$(CONFIG_PCI)              += pci.o
diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c
new file mode 100644
index 0000000..7701741
--- /dev/null
+++ b/drivers/xen/pci.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2009, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Author: Weidong Han <weidong.han@xxxxxxxxx>
+ */
+
+#include <linux/pci.h>
+#include <xen/interface/physdev.h>
+#include <xen/interface/xen.h>
+
+#include <asm/xen/hypervisor.h>
+#include <asm/xen/hypercall.h>
+#include "../pci/pci.h"
+
+static int xen_add_device(struct device *dev)
+{
+       int r;
+       struct pci_dev *pci_dev = to_pci_dev(dev);
+
+#ifdef CONFIG_PCI_IOV
+       if (pci_dev->is_virtfn) {
+               struct physdev_manage_pci_ext manage_pci_ext = {
+                       .bus            = pci_dev->bus->number,
+                       .devfn          = pci_dev->devfn,
+                       .is_virtfn      = 1,
+                       .physfn.bus     = pci_dev->physfn->bus->number,
+                       .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)) {
+               struct physdev_manage_pci_ext manage_pci_ext = {
+                       .bus            = pci_dev->bus->number,
+                       .devfn          = pci_dev->devfn,
+                       .is_extfn       = 1,
+               };
+
+               r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add_ext,
+                       &manage_pci_ext);
+       } else {
+               struct physdev_manage_pci manage_pci = {
+                       .bus    = pci_dev->bus->number,
+                       .devfn  = pci_dev->devfn,
+               };
+
+               r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add,
+                       &manage_pci);
+       }
+
+       return r;
+}
+
+static int xen_remove_device(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 = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove,
+               &manage_pci);
+
+       return r;
+}
+
+static int xen_pci_notifier(struct notifier_block *nb,
+                           unsigned long action, void *data)
+{
+       struct device *dev = data;
+       int r = 0;
+
+       switch (action) {
+       case BUS_NOTIFY_ADD_DEVICE:
+               r = xen_add_device(dev);
+               break;
+       case BUS_NOTIFY_DEL_DEVICE:
+               r = xen_remove_device(dev);
+               break;
+       default:
+               break;
+       }
+
+       return r;
+}
+
+struct notifier_block device_nb = {
+       .notifier_call = xen_pci_notifier,
+};
+
+static int __init register_xen_pci_notifier(void)
+{
+       if (!xen_pv_domain())
+               return 0;
+
+       return bus_register_notifier(&pci_bus_type, &device_nb);
+}
+
+arch_initcall(register_xen_pci_notifier);
diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physdev.h
index a85d76c..2b2c66c 100644
--- a/include/xen/interface/physdev.h
+++ b/include/xen/interface/physdev.h
@@ -136,6 +136,27 @@ struct physdev_unmap_pirq {
     int pirq;
 };
 
+#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.

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

<Prev in Thread] Current Thread [Next in Thread>