|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v3 08/18] pci: Introduce parse_pci_sbdf{_seg}()
In many places, we're parsing a PCI string into individual
parts (seg, bus, dev, fn) and then transform it into a pci_sbdf_t
using PCI_SBDF macro. Rather than converting from parts to pci_sbdf_t
and vice versa, introduce a new function that parses a PCI string
into a pci_sbdf_t structure directly.
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
v3:
* Address Andrew's changes (add __init)
* Use intermediate parse_pci_split_*().
---
xen/drivers/pci/pci.c | 22 ++++++++++++++++++++--
xen/include/xen/pci.h | 20 ++++++++++++++++++--
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c
index 084be3880c..743e2fd263 100644
--- a/xen/drivers/pci/pci.c
+++ b/xen/drivers/pci/pci.c
@@ -151,7 +151,7 @@ void pci_intx(const struct pci_dev *pdev, bool enable)
pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
}
-const char *__init parse_pci(const char *s, unsigned int *seg_p,
+const char *__init parse_pci_split(const char *s, unsigned int *seg_p,
unsigned int *bus_p, unsigned int *dev_p,
unsigned int *func_p)
{
@@ -160,7 +160,7 @@ const char *__init parse_pci(const char *s, unsigned int
*seg_p,
return parse_pci_seg(s, seg_p, bus_p, dev_p, func_p, &def_seg);
}
-const char *__init parse_pci_seg(const char *s, unsigned int *seg_p,
+const char *__init parse_pci_split_seg(const char *s, unsigned int *seg_p,
unsigned int *bus_p, unsigned int *dev_p,
unsigned int *func_p, bool *def_seg)
{
@@ -202,3 +202,21 @@ const char *__init parse_pci_seg(const char *s, unsigned
int *seg_p,
return s;
}
+
+const char *__init parse_pci_sbdf(const char *s, pci_sbdf_t *sbdf)
+{
+ unsigned int seg, bus, dev, func;
+ const char *out = parse_pci(s, &seg, &bus, &dev, &func);
+
+ *sbdf = PCI_SBDF(seg, bus, dev, func);
+ return out;
+}
+
+const char *__init parse_pci_sbdf_seg(const char *s, pci_sbdf_t *sbdf, bool
*def_seg)
+{
+ unsigned int seg, bus, dev, func;
+ const char *out = parse_pci_seg(s, &seg, &bus, &dev, &func, def_seg);
+
+ *sbdf = PCI_SBDF(seg, bus, dev, func);
+ return out;
+}
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index ed6c95452f..8e2f8a1ab7 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -274,12 +274,28 @@ unsigned int pci_find_ext_capability(const struct pci_dev
*pdev,
unsigned int pci_find_next_ext_capability(const struct pci_dev *pdev,
unsigned int start,
unsigned int cap);
-const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p,
+const char *parse_pci_split(const char *s, unsigned int *seg_p, unsigned int
*bus_p,
unsigned int *dev_p, unsigned int *func_p);
-const char *parse_pci_seg(const char *s, unsigned int *seg_p,
+const char *parse_pci_split_seg(const char *s, unsigned int *seg_p,
unsigned int *bus_p, unsigned int *dev_p,
unsigned int *func_p, bool *def_seg);
+const char *parse_pci_sbdf(const char *s, pci_sbdf_t *sbdf);
+const char *parse_pci_sbdf_seg(const char *s, pci_sbdf_t *sbdf, bool *def_seg);
+
+#define _parse_pci_split(a, b, c, d, e, ...) parse_pci_split(a, b, c, d, e)
+#define _parse_pci_split_seg(a, b, c, d, e, f, ...) parse_pci_split_seg(a, b,
c, d, e, f)
+
+#define parse_pci(a, b, ...) \
+ (count_args(__VA_ARGS__) > 0 \
+ ? _parse_pci_split(a, (void *)b, ##__VA_ARGS__, NULL, NULL, NULL) \
+ : parse_pci_sbdf(a, (void *)b))
+
+#define parse_pci_seg(a, b, c, ...) \
+ (count_args(__VA_ARGS__) > 0 \
+ ? _parse_pci_split_seg(a, (void *)b, (void *)c, ##__VA_ARGS__, NULL,
NULL, NULL, NULL) \
+ : parse_pci_sbdf_seg(a, (void *)b, (void *)c))
+
#define PCI_BAR_VF (1u << 0)
#define PCI_BAR_LAST (1u << 1)
#define PCI_BAR_ROM (1u << 2)
--
2.54.0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |