[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [rfc 5/8] qemu-xen: pass-through: Add AUTO_PHP_DEVFN_MULTI



Up until now there has been a signle magic value that xend can pass to
qemu-xen to signify that qemu-xen should choose a devfn for a pass-through
function.

When supporting multi-function devices in guests, it is useful for xend to
be able to sepcify if a function is to appear in a guest as a
single-function deveice, or as part of a multi-function device.

By adding AUTO_PHP_DEVFN_MULTI to suplement the existing AUTO_PHP_DEVFN,
this patch achieves that goal.

This patch does not break compatibility with xend as the value chosen for
AUTO_PHP_DEVFN_MULTI could never validly be sent by xend up until now.
However, there is a companion change to xend in order to make use of this
feature.

Cc: Dexuan Cui <dexuan.cui@xxxxxxxxx>
Cc: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>

Index: ioemu-remote/hw/pass-through.c
===================================================================
--- ioemu-remote.orig/hw/pass-through.c 2009-06-15 11:25:50.000000000 +1000
+++ ioemu-remote/hw/pass-through.c      2009-06-15 11:25:53.000000000 +1000
@@ -859,7 +859,7 @@ static int parse_bdf(char **str, int *se
     }
     else
     {
-        *vdevfn = AUTO_PHP_DEVFN;
+        *vdevfn = AUTO_PHP_SLOT;
         *opt = token;
     }
 
@@ -902,8 +902,32 @@ static int pci_devfn_match(int bus, int 
     return 0;
 }
 
+static int find_free_vslot(void)
+{
+    PCIBus *e_bus = dpci_infos.e_bus;
+    int slot, func, devfn;
+
+    for ( slot = 0; slot < NR_PCI_DEV; slot++ )
+    {
+        for ( func = 0; func < NR_PCI_FUNC; func++ )
+        {
+            devfn = PCI_DEVFN(slot, func);
+            if ( test_pci_devfn(devfn) || pci_devfn_in_use(e_bus, devfn) )
+            {
+                break;
+            }
+        }
+        if (func == NR_PCI_FUNC)
+            return slot;
+    }
+
+    /* not found */
+    return -1;
+}
+
+
 /* Insert a new pass-through device into a specific pci devfn.
- * input  dom:bus:dev.func@devfn, chose free one if devfn == AUTO_PHP_DEVFN
+ * input  dom:bus:dev.func@devfn, chose free one if devfn & AUTO_PHP_SLOT
  * return -2: requested devfn not available
  *        -1: no free devfns
  *        >=0: the new hotplug devfn
@@ -912,28 +936,23 @@ static int __insert_to_pci_devfn(int bus
                                  char *opt)
 {
     PCIBus *e_bus = dpci_infos.e_bus;
-    int slot;
+    int vslot;
 
-    /* preferred virt pci devfn */
-    if ( devfn != AUTO_PHP_DEVFN )
+    if ( devfn & AUTO_PHP_SLOT )
     {
-        if ( !test_pci_devfn(devfn) && !pci_devfn_in_use(e_bus, devfn) )
-            goto found;
-        return -2;
+        vslot = find_free_vslot();
+        if (vslot < 0)
+            return -1;
+        /* The vfunc is provided in the devfn paramter */
+        devfn = PCI_DEVFN(vslot, PCI_FUNC(devfn));
     }
-
-    /* pick a free slot */
-    for ( slot = 0; slot < NR_PCI_DEV; slot++ )
+    else
     {
-        devfn = PCI_DEVFN(slot, 0);
-        if ( !test_pci_devfn(devfn) && !pci_devfn_in_use(e_bus, devfn) )
-            goto found;
+        /* Prefered devfn */
+        if ( test_pci_devfn(devfn) || pci_devfn_in_use(e_bus, devfn) )
+            return -2;
     }
 
-    /* not found */
-    return -1;
-
-found:
     dpci_infos.php_devs[devfn].valid  = 1;
     dpci_infos.php_devs[devfn].r_bus  = bus;
     dpci_infos.php_devs[devfn].r_dev  = dev;
Index: ioemu-remote/hw/pci.h
===================================================================
--- ioemu-remote.orig/hw/pci.h  2009-06-15 11:25:50.000000000 +1000
+++ ioemu-remote/hw/pci.h       2009-06-15 11:25:53.000000000 +1000
@@ -255,11 +255,10 @@ void pci_info(void);
 PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
                         pci_map_irq_fn map_irq, const char *name);
 
-#define NR_PCI_FUNC    8
-#define NR_PCI_DEV     32
-#define NR_PCI_DEVFN   (NR_PCI_FUNC * NR_PCI_DEV)
-#define AUTO_PHP_SLOT  NR_PCI_DEV
-#define AUTO_PHP_DEVFN NR_PCI_DEVFN
+#define NR_PCI_FUNC          8
+#define NR_PCI_DEV           32
+#define NR_PCI_DEVFN         (NR_PCI_FUNC * NR_PCI_DEV)
+#define AUTO_PHP_SLOT        0x100
 
 int insert_to_pci_devfn(char *bdf_devfn);
 int test_pci_devfn(int devfn);

-- 

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.