[dpdk-dev] [PATCH 03/14] eal/common: introduce union rte_device and related
Jan Viktorin
viktorin at rehivetech.com
Mon Jan 4 21:08:15 CET 2016
The union rte_device can be used in situations where we want to work with all
devices without distinguishing among bus-specific features (PCI, ...).
The target device type can be detected by reading the magic.
Also, the macros RTE_DEVICE_DECL and RTE_DEVICE_PTR_DECL are introduced to
provide a generic way to declare a device or a pointer to a device. The macros
aim to preserve API backwards-compatibility. Eg.
struct old_super_struct { => struct old_super_struct {
struct rte_pci_device *pci_dev; => RTE_DEVICE_PTR_DECL(pci_dev);
... => ...
}; => };
struct old_super_struct inst;
The new code should reference inst.dev.pci, the old code can still use the
inst.pci_dev. The previously introduced magic is included so one can ask the
instance about its type:
if (inst.dev.magic == RTE_PCI_DEVICE_MAGIC) {
...
}
I don't like to include the rte_pci.h header here, however, I didn't find
a better way at the moment.
Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
lib/librte_eal/common/include/rte_dev.h | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index f1b5507..c99d038 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -49,6 +49,7 @@ extern "C" {
#include <stdio.h>
#include <sys/queue.h>
+#include <rte_pci.h>
#include <rte_log.h>
__attribute__((format(printf, 2, 0)))
@@ -134,6 +135,32 @@ struct rte_driver {
};
/**
+ * Generic representation of a device.
+ */
+union rte_device {
+ unsigned int magic;
+ struct rte_pci_device pci;
+};
+
+/**
+ * The macro preserves API backwards compatibility.
+ */
+#define RTE_DEVICE_DECL(_pci) \
+ union { \
+ union rte_device dev; \
+ struct rte_pci_device _pci; \
+ }
+
+/**
+ * The macro preserves API backwards compatibility.
+ */
+#define RTE_DEVICE_PTR_DECL(_pci) \
+ union { \
+ union rte_device *dev; \
+ struct rte_pci_device *_pci; \
+ }
+
+/**
* Register a device driver.
*
* @param driver
--
2.6.3
More information about the dev
mailing list