diff options
author | Jan Beulich <jbeulich@suse.com> | 2013-08-28 10:12:36 +0200 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2013-08-28 10:12:36 +0200 |
commit | aa4b2aea4fa300341668971e50fbfd16b1ed925d (patch) | |
tree | 58cc54354404464bc163272fbc696ce858c06b36 /xen/drivers/pci | |
parent | dcbff3aeac6020cdf1f5bd0f0eb0d329fc55d939 (diff) | |
download | xen-aa4b2aea4fa300341668971e50fbfd16b1ed925d.tar.gz xen-aa4b2aea4fa300341668971e50fbfd16b1ed925d.tar.bz2 xen-aa4b2aea4fa300341668971e50fbfd16b1ed925d.zip |
PCI: centralize parsing of device coordinates in command line options
With yet another case to come in a subsequent patch, it seems time to
do this in a single place rather than hand crafting it in various
scattered around locations.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/drivers/pci')
-rw-r--r-- | xen/drivers/pci/pci.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c index b6e388a4f1..25dc5f1486 100644 --- a/xen/drivers/pci/pci.c +++ b/xen/drivers/pci/pci.c @@ -4,6 +4,7 @@ * Architecture-independent PCI access functions. */ +#include <xen/init.h> #include <xen/pci.h> #include <xen/pci_regs.h> @@ -102,3 +103,44 @@ int pci_find_ext_capability(int seg, int bus, int devfn, int cap) } return 0; } + +const char *__init parse_pci(const char *s, unsigned int *seg_p, + unsigned int *bus_p, unsigned int *dev_p, + unsigned int *func_p) +{ + unsigned long seg = simple_strtoul(s, &s, 16), bus, dev, func; + + if ( *s != ':' ) + return NULL; + bus = simple_strtoul(s + 1, &s, 16); + if ( *s == ':' ) + dev = simple_strtoul(s + 1, &s, 16); + else + { + dev = bus; + bus = seg; + seg = 0; + } + if ( func_p ) + { + if ( *s != '.' ) + return NULL; + func = simple_strtoul(s + 1, &s, 0); + } + else + func = 0; + if ( seg != (seg_p ? (u16)seg : 0) || + bus != PCI_BUS(PCI_BDF2(bus, 0)) || + dev != PCI_SLOT(PCI_DEVFN(dev, 0)) || + func != PCI_FUNC(PCI_DEVFN(0, func)) ) + return NULL; + + if ( seg_p ) + *seg_p = seg; + *bus_p = bus; + *dev_p = dev; + if ( func_p ) + *func_p = func; + + return s; +} |