]> xenbits.xen.org Git - xenclient/ioemu.git/commitdiff
ioemu: Do slot parsing inside of next_bdf
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 31 Mar 2009 10:38:55 +0000 (11:38 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 31 Mar 2009 10:38:55 +0000 (11:38 +0100)
Currently only hotplug provides vslot information from xend.
A subsequent patch will have xend provide this information
for boot-time inserted pass-through devices too.

With this in mind, this patch makes some infrastructure
to parse bdf + slot information.

Signed-off-by: Simon Horman <horms@verge.net.au>
hw/pass-through.c

index b82fdf999a5f51359fa816f6c06e2839711b1138..235c4c3cf4d731614b146768154bf17c0f351595 100644 (file)
@@ -776,9 +776,10 @@ static int token_value(char *token)
     return strtol(token, NULL, 16);
 }
 
-static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func, char **opt)
+static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func,
+                    char **opt, int *vslot)
 {
-    char *token;
+    char *token, *endptr;
     const char *delim = ":.-";
 
     if ( !(*str) ||
@@ -795,7 +796,20 @@ static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func, char **
     *dev  = token_value(token);
 
     token  = strsep(str, delim);
-    *opt = strchr(token, ',');
+
+    *opt = strchr(token, '@');
+    if (*opt)
+    {
+        *(*opt)++ = '\0';
+        *vslot = token_value(*opt);
+    }
+    else
+    {
+        *vslot = AUTO_PHP_SLOT;
+        *opt = token;
+    }
+
+    *opt = strchr(*opt, ',');
     if (*opt)
         *(*opt)++ = '\0';
 
@@ -881,14 +895,9 @@ found:
 int insert_to_pci_slot(char *bdf_slt)
 {
     int seg, bus, dev, func, slot;
-    char *bdf_str, *slt_str, *opt, *endptr;
-    const char *delim="@";
-
-    bdf_str = strsep(&bdf_slt, delim);
-    slt_str = bdf_slt;
-    slot = token_value(slt_str);
+    char *opt;
 
-    if ( !next_bdf(&bdf_str, &seg, &bus, &dev, &func, &opt))
+    if ( !next_bdf(&bdf_slt, &seg, &bus, &dev, &func, &opt, &slot) )
     {
         return -1;
     }
@@ -916,10 +925,10 @@ int test_pci_slot(int slot)
 /* find the pci slot for pass-through dev with specified BDF */
 int bdf_to_slot(char *bdf_str)
 {
-    int seg, bus, dev, func, i;
+    int seg, bus, dev, func, slot, i;
     char *opt;
 
-    if ( !next_bdf(&bdf_str, &seg, &bus, &dev, &func, &opt))
+    if ( !next_bdf(&bdf_str, &seg, &bus, &dev, &func, &opt, &slot))
     {
         return -1;
     }
@@ -3901,7 +3910,7 @@ int power_off_php_slot(int php_slot)
 
 int pt_init(PCIBus *e_bus, const char *direct_pci)
 {
-    int seg, b, d, f, status = -1;
+    int seg, b, d, f, s, status = -1;
     struct pt_dev *pt_dev;
     struct pci_access *pci_access;
     char *vslots;
@@ -3949,7 +3958,7 @@ int pt_init(PCIBus *e_bus, const char *direct_pci)
     }
 
     /* Assign given devices to guest */
-    while ( next_bdf(&direct_pci_p, &seg, &b, &d, &f, &opt) )
+    while ( next_bdf(&direct_pci_p, &seg, &b, &d, &f, &opt, &s) )
     {
         /* Register real device with the emulated bus */
         pt_dev = register_real_device(e_bus, "DIRECT PCI", PT_VIRT_DEVFN_AUTO,