[RFC,6/7] raw/vfio_platform: support rawdev device info
Checks
Commit Message
Add support for querying rawdev device info.
Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
.../raw/vfio_platform/rte_pmd_vfio_platform.h | 34 ++++++++++++++
drivers/raw/vfio_platform/vfio_platform.c | 45 +++++++++++++++++++
2 files changed, 79 insertions(+)
@@ -17,6 +17,40 @@
extern "C" {
#endif
+#include <rte_compat.h>
+#include <rte_dev.h>
+
+/**
+ * vfio platform device region info
+ *
+ * Caller uses that to retrieve information about device memory regions.
+ * Caller provides either resource name or an index, both of which can
+ * be extracted from the device tree. The former is equivalent to
+ * 'reg-names' property while the latter is a 0-based index into 'reg'
+ * array.
+ */
+struct vfio_platform_dev_region_info {
+ /**< mmapped memory resource */
+ struct rte_mem_resource mem;
+ /**< name of the resource */
+ const char *name;
+ /**< index of the resource */
+ int index;
+};
+
+enum vfio_platform_info {
+ INFO_REGION_INDEX,
+ INFO_REGION_NAME,
+};
+
+/**< vfio platform device info */
+struct vfio_platform_dev_info {
+ /**< Type of device info */
+ enum vfio_platform_info type;
+ /**< Memory region info */
+ struct vfio_platform_dev_region_info reg_info;
+};
+
/** vfio platform device configuration */
struct vfio_platform_dev_config {
/** logical value representing the vfio container */
@@ -94,6 +94,50 @@ rte_pmd_vfio_platform_container_destroy(int container)
return 0;
}
+static int
+vfio_rawdev_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info,
+ size_t dev_private_size)
+{
+ struct vfio_platform_dev_info *info = (struct vfio_platform_dev_info *)dev_info;
+ struct vfio_platform_dev_region_info *reg_info = &info->reg_info;
+ struct vfio_platform *plat = dev->dev_private;
+ int i;
+
+ if (dev_private_size != sizeof(*info))
+ return -EINVAL;
+
+ if (plat->num_resource == 0)
+ return -ENODATA;
+
+ switch (info->type) {
+ case INFO_REGION_INDEX:
+ if (reg_info->index < 0 || reg_info->index >= plat->num_resource)
+ return -EINVAL;
+
+ i = reg_info->index;
+ break;
+ case INFO_REGION_NAME:
+ if (!reg_info->name)
+ return -EINVAL;
+
+ for (i = 0; i < plat->num_resource; i++) {
+ if (!strcmp(reg_info->name, plat->resource[i].name))
+ break;
+ }
+
+ if (i == plat->num_resource)
+ return -ENODATA;
+
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ memcpy(®_info->mem, &plat->resource[i].mem, sizeof(reg_info->mem));
+
+ return 0;
+}
+
static char *
of_resource_name(const char *dev_name, int index)
{
@@ -277,6 +321,7 @@ vfio_rawdev_dev_close(struct rte_rawdev *dev)
}
static const struct rte_rawdev_ops vfio_platform_rawdev_ops = {
+ .dev_info_get = vfio_rawdev_dev_info_get,
.dev_configure = vfio_rawdev_dev_configure,
.dev_close = vfio_rawdev_dev_close,
};