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

[PATCH v2 05/15] pci: Allow ommiting func when parsing with parse_pci_sbdf()



Allow parsing PCI SBDF with the function part omitted (i.e XXXX:YY:ZZ),
in such case, the parsed PCI function is zero.

That allows us to now use parse_pci_sbdf() in parse_phantom_dev().

Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
 xen/drivers/passthrough/pci.c | 10 +++++-----
 xen/drivers/pci/pci.c         | 12 ++++--------
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 7b09c9a7cd..f222da8879 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -148,7 +148,7 @@ static unsigned int nr_phantom_devs;
 static int __init cf_check parse_phantom_dev(const char *str)
 {
     const char *s;
-    unsigned int seg, bus, slot;
+    pci_sbdf_t sbdf;
     struct phantom_dev phantom;
 
     if ( !*str )
@@ -156,13 +156,13 @@ static int __init cf_check parse_phantom_dev(const char 
*str)
     if ( nr_phantom_devs >= ARRAY_SIZE(phantom_devs) )
         return -E2BIG;
 
-    s = parse_pci(str, &seg, &bus, &slot, NULL);
+    s = parse_pci_sbdf(str, &sbdf);
     if ( !s || *s != ',' )
         return -EINVAL;
 
-    phantom.seg = seg;
-    phantom.bus = bus;
-    phantom.slot = slot;
+    phantom.seg = sbdf.seg;
+    phantom.bus = sbdf.bus;
+    phantom.slot = sbdf.dev;
 
     switch ( phantom.stride = simple_strtol(s + 1, &s, 0) )
     {
diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c
index 1d06cb035b..a2b49f1b26 100644
--- a/xen/drivers/pci/pci.c
+++ b/xen/drivers/pci/pci.c
@@ -179,18 +179,14 @@ const char *__init parse_pci_seg(const char *s, unsigned 
int *seg_p,
         seg = 0;
         *def_seg = true;
     }
+
     if ( func_p )
-    {
-        if ( *s != '.' )
-            return NULL;
-        func = simple_strtoul(s + 1, &s, 0);
-    }
-    else
-        func = 0;
+        func = *s == '.' ? simple_strtoul(s + 1, &s, 0) : 0;
+
     if ( seg != (seg_p ? (u16)seg : 0) ||
          bus != PCI_BUS(PCI_BDF(bus, 0)) ||
          dev != PCI_SLOT(PCI_DEVFN(dev, 0)) ||
-         func != PCI_FUNC(PCI_DEVFN(0, func)) )
+         func != (func_p ? PCI_FUNC(PCI_DEVFN(0, func)) : 0) )
         return NULL;
 
     if ( seg_p )
-- 
2.54.0



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

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