[PATCH v4 1/1] bus/cdx: provide driver flag for optional resource mapping

2023-10-16 Thread Abhijit Gangurde
Provide driver flag which gives an option to map the cdx device
resource before probing the device driver. External driver can
use rte_cdx_map_device() and rte_cdx_unmap_device() APIs to map/
unmap device resource separately.

Signed-off-by: Abhijit Gangurde 
---
 v4:
 - rte_cdx_map_device() and rte_cdx_unmap_device() APIs are kept
   as internal APIs.

 v3:
 - Changed APIs to __rte_experimental.

 v2:
 - Corrected _RTE_BUS_CDX_H_ to RTE_BUS_CDX_H
 - Improved code comments.

 drivers/bus/cdx/bus_cdx_driver.h |  3 +++
 drivers/bus/cdx/cdx.c| 10 ++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index fcacdb5896..1c9a64c87a 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -37,6 +37,9 @@ struct rte_cdx_bus;
 static const char DRV_EXP_TAG(name, cdx_tbl_export)[] __rte_used = \
 RTE_STR(table)
 
+/** Device needs resource mapping */
+#define RTE_CDX_DRV_NEED_MAPPING 0x0001
+
 /**
  * A structure describing an ID for a CDX driver. Each driver provides a
  * table of these IDs for each device that it supports.
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index f9526e08cc..541aae76c3 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -383,10 +383,12 @@ cdx_probe_one_driver(struct rte_cdx_driver *dr,
CDX_BUS_DEBUG("  probe device %s using driver: %s", dev_name,
dr->driver.name);
 
-   ret = cdx_vfio_map_resource(dev);
-   if (ret != 0) {
-   CDX_BUS_ERR("CDX map device failed: %d", ret);
-   goto error_map_device;
+   if (dr->drv_flags & RTE_CDX_DRV_NEED_MAPPING) {
+   ret = cdx_vfio_map_resource(dev);
+   if (ret != 0) {
+   CDX_BUS_ERR("CDX map device failed: %d", ret);
+   goto error_map_device;
+   }
}
 
/* call the driver probe() function */
-- 
2.34.1



[PATCH] bus/cdx: Remove ineffective code statement

2023-06-14 Thread Abhijit Gangurde
ret = 0 statement is ineffective since it is overwritten in a loop.

Coverity issue: 385379
Fixes: 45ef232af515 ("bus/cdx: introduce AMD CDX bus")
Signed-off-by: Abhijit Gangurde 
---
 drivers/bus/cdx/cdx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..9130c30515 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -452,7 +452,6 @@ cdx_probe(void)
dev->name);
rte_errno = errno;
failed++;
-   ret = 0;
}
}
 
-- 
2.25.1



[PATCH] bus/cdx: Move debug print before unmapping resource

2023-06-14 Thread Abhijit Gangurde
Debug print is moved before unmapping requested address
to fix use after free coverity issue.

Coverity issue: 385381
Fixes: 45ef232af515 ("bus/cdx: introduce AMD CDX bus")
Signed-off-by: Abhijit Gangurde 
---
 drivers/bus/cdx/cdx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..85353d8996 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -322,12 +322,13 @@ cdx_unmap_resource(void *requested_addr, size_t size)
if (requested_addr == NULL)
return;
 
+   CDX_BUS_DEBUG("Unmapping CDX memory at %p", requested_addr);
+
/* Unmap the CDX memory resource of device */
if (rte_mem_unmap(requested_addr, size)) {
CDX_BUS_ERR("%s(): cannot mem unmap(%p, %#zx): %s", __func__,
requested_addr, size, rte_strerror(rte_errno));
}
-   CDX_BUS_DEBUG("CDX memory unmapped at %p", requested_addr);
 }
 /*
  * Match the CDX Driver and Device using device id and vendor id.
-- 
2.25.1



[PATCH] bus/cdx: Fix resource leak

2023-06-14 Thread Abhijit Gangurde
Freeing the allocated resources on error scenarios.

Coverity issue: 385377
Fixes: f29fb5caa135 ("bus/cdx: support MSI")
Signed-off-by: Abhijit Gangurde 
---
 drivers/bus/cdx/cdx.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..0f643ad2cb 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -208,8 +208,8 @@ cdx_scan_one(const char *dirname, const char *dev_name)
ret = cdx_get_kernel_driver_by_path(filename, driver, sizeof(driver));
if (ret < 0) {
CDX_BUS_ERR("Fail to get kernel driver");
-   ret = -1;
-   goto err;
+   free(dev);
+   return -1;
}
 
/* Allocate interrupt instance for cdx device */
@@ -218,6 +218,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
if (dev->intr_handle == NULL) {
CDX_BUS_ERR("Failed to create interrupt instance for %s",
dev->device.name);
+   free(dev);
return -ENOMEM;
}
 
@@ -241,8 +242,8 @@ cdx_scan_one(const char *dirname, const char *dev_name)
/* get device id */
snprintf(filename, sizeof(filename), "%s/device", dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
-   free(dev);
-   return -1;
+   ret = -1;
+   goto err;
}
dev->id.device_id = (uint16_t)tmp;
 
@@ -251,6 +252,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
return 0;
 
 err:
+   rte_intr_instance_free(dev->intr_handle);
free(dev);
return ret;
 }
-- 
2.25.1



[PATCH v2 0/3] bus/cdx: fix coverity issue

2023-06-16 Thread Abhijit Gangurde
This series fixes coverity issues 385379, 385381, 385377

v2:
- Merged coverity fix patches into series
- Updated commit message

Abhijit Gangurde (3):
  bus/cdx: remove ineffective code statement
  bus/cdx: move debug print before unmapping resource
  bus/cdx: fix resource leak

 drivers/bus/cdx/cdx.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

-- 
2.25.1



[PATCH v2 1/3] bus/cdx: remove ineffective code statement

2023-06-16 Thread Abhijit Gangurde
Remove ineffective code statement ret = 0 since it is
overwritten in a loop.

Coverity issue: 385379
Fixes: 45ef232af515 ("bus/cdx: introduce AMD CDX bus")
Signed-off-by: Abhijit Gangurde 
Acked-by: Nipun Gupta 
---
 v2:
 - Updated commit message

 drivers/bus/cdx/cdx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..9130c30515 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -452,7 +452,6 @@ cdx_probe(void)
dev->name);
rte_errno = errno;
failed++;
-   ret = 0;
}
}
 
-- 
2.25.1



[PATCH v2 2/3] bus/cdx: move debug print before unmapping resource

2023-06-16 Thread Abhijit Gangurde
Move debug print before unmapping requested address
to fix use after free coverity issue.

Coverity issue: 385381
Fixes: 45ef232af515 ("bus/cdx: introduce AMD CDX bus")
Signed-off-by: Abhijit Gangurde 
---
 v2:
 - Updated commit message

 drivers/bus/cdx/cdx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 9130c30515..aef19682f4 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -322,12 +322,13 @@ cdx_unmap_resource(void *requested_addr, size_t size)
if (requested_addr == NULL)
return;
 
+   CDX_BUS_DEBUG("Unmapping CDX memory at %p", requested_addr);
+
/* Unmap the CDX memory resource of device */
if (rte_mem_unmap(requested_addr, size)) {
CDX_BUS_ERR("%s(): cannot mem unmap(%p, %#zx): %s", __func__,
requested_addr, size, rte_strerror(rte_errno));
}
-   CDX_BUS_DEBUG("CDX memory unmapped at %p", requested_addr);
 }
 /*
  * Match the CDX Driver and Device using device id and vendor id.
-- 
2.25.1



[PATCH v2 3/3] bus/cdx: fix resource leak

2023-06-16 Thread Abhijit Gangurde
Free the allocated device memory and interrupt handler
on error scenarios.

Coverity issue: 385377
Fixes: f29fb5caa135 ("bus/cdx: support MSI")
Signed-off-by: Abhijit Gangurde 
---
 v2:
 - Updated commit message

 drivers/bus/cdx/cdx.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index aef19682f4..f9526e08cc 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -208,8 +208,8 @@ cdx_scan_one(const char *dirname, const char *dev_name)
ret = cdx_get_kernel_driver_by_path(filename, driver, sizeof(driver));
if (ret < 0) {
CDX_BUS_ERR("Fail to get kernel driver");
-   ret = -1;
-   goto err;
+   free(dev);
+   return -1;
}
 
/* Allocate interrupt instance for cdx device */
@@ -218,6 +218,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
if (dev->intr_handle == NULL) {
CDX_BUS_ERR("Failed to create interrupt instance for %s",
dev->device.name);
+   free(dev);
return -ENOMEM;
}
 
@@ -241,8 +242,8 @@ cdx_scan_one(const char *dirname, const char *dev_name)
/* get device id */
snprintf(filename, sizeof(filename), "%s/device", dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
-   free(dev);
-   return -1;
+   ret = -1;
+   goto err;
}
dev->id.device_id = (uint16_t)tmp;
 
@@ -251,6 +252,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
return 0;
 
 err:
+   rte_intr_instance_free(dev->intr_handle);
free(dev);
return ret;
 }
-- 
2.25.1



[PATCH] bus/cdx: provide driver flag for optional resource mapping

2023-06-26 Thread Abhijit Gangurde
Provide driver flag which gives an option to map the cdx
device resource before probing the device driver.
Also, make rte_cdx_map_device() API as public to map
device resource separately.

Signed-off-by: Abhijit Gangurde 
---
 drivers/bus/cdx/bus_cdx_driver.h | 26 ++---
 drivers/bus/cdx/cdx.c| 11 ---
 drivers/bus/cdx/rte_bus_cdx.h| 50 
 drivers/bus/cdx/version.map  | 11 +--
 4 files changed, 69 insertions(+), 29 deletions(-)
 create mode 100644 drivers/bus/cdx/rte_bus_cdx.h

diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index fcacdb5896..1571131417 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -37,6 +37,9 @@ struct rte_cdx_bus;
 static const char DRV_EXP_TAG(name, cdx_tbl_export)[] __rte_used = \
 RTE_STR(table)
 
+/** Device needs resource mapping */
+#define RTE_CDX_DRV_NEED_MAPPING 0x0001
+
 /**
  * A structure describing an ID for a CDX driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -107,29 +110,6 @@ struct rte_cdx_driver {
uint32_t drv_flags; /**< Flags RTE_CDX_DRV_*. */
 };
 
-/**
- * Map the CDX device resources in user space virtual memory address.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- *
- * @return
- *   0 on success, <0 on error.
- */
-__rte_internal
-int rte_cdx_map_device(struct rte_cdx_device *dev);
-
-/**
- * Unmap this device.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- */
-__rte_internal
-void rte_cdx_unmap_device(struct rte_cdx_device *dev);
-
 /**
  * Register a CDX driver.
  *
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..47dc4eabe7 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -74,6 +74,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -380,10 +381,12 @@ cdx_probe_one_driver(struct rte_cdx_driver *dr,
CDX_BUS_DEBUG("  probe device %s using driver: %s", dev_name,
dr->driver.name);
 
-   ret = cdx_vfio_map_resource(dev);
-   if (ret != 0) {
-   CDX_BUS_ERR("CDX map device failed: %d", ret);
-   goto error_map_device;
+   if (dr->drv_flags & RTE_CDX_DRV_NEED_MAPPING) {
+   ret = cdx_vfio_map_resource(dev);
+   if (ret != 0) {
+   CDX_BUS_ERR("CDX map device failed: %d", ret);
+   goto error_map_device;
+   }
}
 
/* call the driver probe() function */
diff --git a/drivers/bus/cdx/rte_bus_cdx.h b/drivers/bus/cdx/rte_bus_cdx.h
new file mode 100644
index 00..b9280b5f7f
--- /dev/null
+++ b/drivers/bus/cdx/rte_bus_cdx.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2023, Advanced Micro Devices, Inc.
+ */
+
+#ifndef _RTE_BUS_CDX_H_
+#define _RTE_BUS_CDX_H_
+
+/**
+ * @file
+ * CDX device & driver interface
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward declarations */
+struct rte_cdx_device;
+
+/**
+ * Map the CDX device resources in user space virtual memory address
+ *
+ * Note that driver should not call this function when flag
+ * RTE_CDX_DRV_NEED_MAPPING is set, as EAL will do that for
+ * you when it's on.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use
+ *
+ * @return
+ *   0 on success, negative on error and positive if no driver
+ *   is found for the device.
+ */
+int rte_cdx_map_device(struct rte_cdx_device *dev);
+
+/**
+ * Unmap this device
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use
+ */
+void rte_cdx_unmap_device(struct rte_cdx_device *dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_BUS_CDX_H_ */
diff --git a/drivers/bus/cdx/version.map b/drivers/bus/cdx/version.map
index 0a15d39ae8..cc7b1f821b 100644
--- a/drivers/bus/cdx/version.map
+++ b/drivers/bus/cdx/version.map
@@ -1,9 +1,16 @@
-INTERNAL {
+DPDK_23 {
global:
 
rte_cdx_map_device;
-   rte_cdx_register;
rte_cdx_unmap_device;
+
+   local: *;
+};
+
+INTERNAL {
+   global:
+
+   rte_cdx_register;
rte_cdx_unregister;
rte_cdx_vfio_intr_disable;
rte_cdx_vfio_intr_enable;
-- 
2.25.1



[PATCH v2] bus/cdx: provide driver flag for optional resource mapping

2023-07-04 Thread Abhijit Gangurde
Provide driver flag which gives an option to map the cdx
device resource before probing the device driver.
Also, make rte_cdx_map_device() API as public to map
device resource separately.

Signed-off-by: Abhijit Gangurde 
---
 v2:
 - Corrected _RTE_BUS_CDX_H_ to RTE_BUS_CDX_H
 - Improved code comments.
 
 drivers/bus/cdx/bus_cdx_driver.h | 26 ++---
 drivers/bus/cdx/cdx.c| 11 ---
 drivers/bus/cdx/rte_bus_cdx.h| 50 
 drivers/bus/cdx/version.map  | 11 +--
 4 files changed, 69 insertions(+), 29 deletions(-)
 create mode 100644 drivers/bus/cdx/rte_bus_cdx.h

diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index fcacdb5896..1571131417 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -37,6 +37,9 @@ struct rte_cdx_bus;
 static const char DRV_EXP_TAG(name, cdx_tbl_export)[] __rte_used = \
 RTE_STR(table)
 
+/** Device needs resource mapping */
+#define RTE_CDX_DRV_NEED_MAPPING 0x0001
+
 /**
  * A structure describing an ID for a CDX driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -107,29 +110,6 @@ struct rte_cdx_driver {
uint32_t drv_flags; /**< Flags RTE_CDX_DRV_*. */
 };
 
-/**
- * Map the CDX device resources in user space virtual memory address.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- *
- * @return
- *   0 on success, <0 on error.
- */
-__rte_internal
-int rte_cdx_map_device(struct rte_cdx_device *dev);
-
-/**
- * Unmap this device.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- */
-__rte_internal
-void rte_cdx_unmap_device(struct rte_cdx_device *dev);
-
 /**
  * Register a CDX driver.
  *
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 28bbf92ed5..47dc4eabe7 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -74,6 +74,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -380,10 +381,12 @@ cdx_probe_one_driver(struct rte_cdx_driver *dr,
CDX_BUS_DEBUG("  probe device %s using driver: %s", dev_name,
dr->driver.name);
 
-   ret = cdx_vfio_map_resource(dev);
-   if (ret != 0) {
-   CDX_BUS_ERR("CDX map device failed: %d", ret);
-   goto error_map_device;
+   if (dr->drv_flags & RTE_CDX_DRV_NEED_MAPPING) {
+   ret = cdx_vfio_map_resource(dev);
+   if (ret != 0) {
+   CDX_BUS_ERR("CDX map device failed: %d", ret);
+   goto error_map_device;
+   }
}
 
/* call the driver probe() function */
diff --git a/drivers/bus/cdx/rte_bus_cdx.h b/drivers/bus/cdx/rte_bus_cdx.h
new file mode 100644
index 00..80acd668c0
--- /dev/null
+++ b/drivers/bus/cdx/rte_bus_cdx.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2023, Advanced Micro Devices, Inc.
+ */
+
+#ifndef RTE_BUS_CDX_H
+#define RTE_BUS_CDX_H
+
+/**
+ * @file
+ * CDX device & driver interface
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward declarations */
+struct rte_cdx_device;
+
+/**
+ * Map the CDX device resources in user space virtual memory address.
+ *
+ * Note that driver should not call this function when flag
+ * RTE_CDX_DRV_NEED_MAPPING is set, as EAL will do that for
+ * you when it's on.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use.
+ *
+ * @return
+ *   0 on success, negative on error and positive if no driver
+ *   is found for the device.
+ */
+int rte_cdx_map_device(struct rte_cdx_device *dev);
+
+/**
+ * Unmap this device.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use.
+ */
+void rte_cdx_unmap_device(struct rte_cdx_device *dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_BUS_CDX_H */
diff --git a/drivers/bus/cdx/version.map b/drivers/bus/cdx/version.map
index 0a15d39ae8..cc7b1f821b 100644
--- a/drivers/bus/cdx/version.map
+++ b/drivers/bus/cdx/version.map
@@ -1,9 +1,16 @@
-INTERNAL {
+DPDK_23 {
global:
 
rte_cdx_map_device;
-   rte_cdx_register;
rte_cdx_unmap_device;
+
+   local: *;
+};
+
+INTERNAL {
+   global:
+
+   rte_cdx_register;
rte_cdx_unregister;
rte_cdx_vfio_intr_disable;
rte_cdx_vfio_intr_enable;
-- 
2.25.1



[PATCH v3] bus/cdx: provide driver flag for optional resource mapping

2023-07-10 Thread Abhijit Gangurde
Provide driver flag which gives an option to map the cdx
device resource before probing the device driver.
Also, make rte_cdx_map_device() API as public to map
device resource separately.

Signed-off-by: Abhijit Gangurde 
---
 v3:
 - Changed APIs to __rte_experimental.

 v2:
 - Corrected _RTE_BUS_CDX_H_ to RTE_BUS_CDX_H
 - Improved code comments.

 drivers/bus/cdx/bus_cdx_driver.h | 26 ++--
 drivers/bus/cdx/cdx.c| 11 ---
 drivers/bus/cdx/rte_bus_cdx.h| 52 
 drivers/bus/cdx/version.map  | 11 +--
 4 files changed, 71 insertions(+), 29 deletions(-)
 create mode 100644 drivers/bus/cdx/rte_bus_cdx.h

diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index fcacdb5896..1571131417 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -37,6 +37,9 @@ struct rte_cdx_bus;
 static const char DRV_EXP_TAG(name, cdx_tbl_export)[] __rte_used = \
 RTE_STR(table)
 
+/** Device needs resource mapping */
+#define RTE_CDX_DRV_NEED_MAPPING 0x0001
+
 /**
  * A structure describing an ID for a CDX driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -107,29 +110,6 @@ struct rte_cdx_driver {
uint32_t drv_flags; /**< Flags RTE_CDX_DRV_*. */
 };
 
-/**
- * Map the CDX device resources in user space virtual memory address.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- *
- * @return
- *   0 on success, <0 on error.
- */
-__rte_internal
-int rte_cdx_map_device(struct rte_cdx_device *dev);
-
-/**
- * Unmap this device.
- *
- * @param dev
- *   A pointer to a rte_cdx_device structure describing the device
- *   to use.
- */
-__rte_internal
-void rte_cdx_unmap_device(struct rte_cdx_device *dev);
-
 /**
  * Register a CDX driver.
  *
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index f9526e08cc..fc8d3b668b 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -74,6 +74,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -383,10 +384,12 @@ cdx_probe_one_driver(struct rte_cdx_driver *dr,
CDX_BUS_DEBUG("  probe device %s using driver: %s", dev_name,
dr->driver.name);
 
-   ret = cdx_vfio_map_resource(dev);
-   if (ret != 0) {
-   CDX_BUS_ERR("CDX map device failed: %d", ret);
-   goto error_map_device;
+   if (dr->drv_flags & RTE_CDX_DRV_NEED_MAPPING) {
+   ret = cdx_vfio_map_resource(dev);
+   if (ret != 0) {
+   CDX_BUS_ERR("CDX map device failed: %d", ret);
+   goto error_map_device;
+   }
}
 
/* call the driver probe() function */
diff --git a/drivers/bus/cdx/rte_bus_cdx.h b/drivers/bus/cdx/rte_bus_cdx.h
new file mode 100644
index 00..4ca12f90c4
--- /dev/null
+++ b/drivers/bus/cdx/rte_bus_cdx.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2023, Advanced Micro Devices, Inc.
+ */
+
+#ifndef RTE_BUS_CDX_H
+#define RTE_BUS_CDX_H
+
+/**
+ * @file
+ * CDX device & driver interface
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward declarations */
+struct rte_cdx_device;
+
+/**
+ * Map the CDX device resources in user space virtual memory address.
+ *
+ * Note that driver should not call this function when flag
+ * RTE_CDX_DRV_NEED_MAPPING is set, as EAL will do that for
+ * you when it's on.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use.
+ *
+ * @return
+ *   0 on success, negative on error and positive if no driver
+ *   is found for the device.
+ */
+__rte_experimental
+int rte_cdx_map_device(struct rte_cdx_device *dev);
+
+/**
+ * Unmap this device.
+ *
+ * @param dev
+ *   A pointer to a rte_cdx_device structure describing the device
+ *   to use.
+ */
+__rte_experimental
+void rte_cdx_unmap_device(struct rte_cdx_device *dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_BUS_CDX_H */
diff --git a/drivers/bus/cdx/version.map b/drivers/bus/cdx/version.map
index 0a15d39ae8..4ce444572b 100644
--- a/drivers/bus/cdx/version.map
+++ b/drivers/bus/cdx/version.map
@@ -1,9 +1,16 @@
-INTERNAL {
+EXPERIMENTAL {
global:
 
rte_cdx_map_device;
-   rte_cdx_register;
rte_cdx_unmap_device;
+
+   local: *;
+};
+
+INTERNAL {
+   global:
+
+   rte_cdx_register;
rte_cdx_unregister;
rte_cdx_vfio_intr_disable;
rte_cdx_vfio_intr_enable;
-- 
2.25.1