This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 6a19b6652639cfdfcda60bc47ac6dcdae404a3e7
Author: p-szafonimateusz <[email protected]>
AuthorDate: Wed Jun 3 11:30:17 2026 +0200

    drivers/rptun/rptun_ivshmem: add the vhost-i2c vdev to the resource table
    
    With CONFIG_DRIVERS_VHOST_I2C, publish a VirtIO I2C device (device role)
    in the ivshmem resource table, with one vring, its own carveout and the
    local I2C device node ("/dev/i2c0") in the config space for vhost-i2c to
    open.
    
    Signed-off-by: p-szafonimateusz <[email protected]>
    Signed-off-by: yangsong8 <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/rptun_ivshmem.c | 59 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/drivers/rptun/rptun_ivshmem.c b/drivers/rptun/rptun_ivshmem.c
index 6884d783775..7c65adeeec5 100644
--- a/drivers/rptun/rptun_ivshmem.c
+++ b/drivers/rptun/rptun_ivshmem.c
@@ -32,6 +32,7 @@
 
 #include <nuttx/nuttx.h>
 #include <nuttx/drivers/addrenv.h>
+#include <nuttx/virtio/virtio-i2c.h>
 #include <nuttx/pci/pci_ivshmem.h>
 #include <nuttx/rptun/rptun.h>
 #include <nuttx/rptun/rptun_ivshmem.h>
@@ -74,10 +75,17 @@
 #  define RPTUN_IVSHMEM_NET       0
 #endif
 
+#ifdef CONFIG_DRIVERS_VHOST_I2C
+#  define RPTUN_IVSHMEM_I2C       1
+#else
+#  define RPTUN_IVSHMEM_I2C       0
+#endif
+
 #define RPTUN_IVSHMEM_VIRTIO_NUM  (RPTUN_IVSHMEM_RNG + \
                                    RPTUN_IVSHMEM_RPMSG + \
                                    RPTUN_IVSHMEM_VSOCK + \
-                                   RPTUN_IVSHMEM_NET)
+                                   RPTUN_IVSHMEM_NET + \
+                                   RPTUN_IVSHMEM_I2C)
 #define RPTUN_IVSHMEM_RSC_NUM     (2 * RPTUN_IVSHMEM_VIRTIO_NUM)
 
 /****************************************************************************
@@ -118,6 +126,13 @@ struct aligned_data(8) rptun_ivshmem_rsc_s
   struct fw_rsc_carveout       net_carveout;
   char                         net_shm[RPTUN_IVSHMEM_SHMEM_SIZE];
 #endif
+#if RPTUN_IVSHMEM_I2C
+  struct fw_rsc_vdev           i2c;
+  struct fw_rsc_vdev_vring     i2c_vring;
+  struct vhost_i2c_config_s    i2c_config;
+  struct fw_rsc_carveout       i2c_carveout;
+  char                         i2c_shm[RPTUN_IVSHMEM_SHMEM_SIZE];
+#endif
 };
 
 struct rptun_ivshmem_mem_s
@@ -215,6 +230,10 @@ static const struct rptun_ivshmem_rsc_s g_rsc_table =
 #ifdef CONFIG_DRIVERS_VHOST_NET
       offsetof(struct rptun_ivshmem_rsc_s, net),
       offsetof(struct rptun_ivshmem_rsc_s, net_carveout),
+#endif
+#if RPTUN_IVSHMEM_I2C
+      offsetof(struct rptun_ivshmem_rsc_s, i2c),
+      offsetof(struct rptun_ivshmem_rsc_s, i2c_carveout),
 #endif
     },
 
@@ -375,6 +394,40 @@ static const struct rptun_ivshmem_rsc_s g_rsc_table =
       .len  = sizeof(g_rsc_table.net_shm),
     },
 #endif
+#if RPTUN_IVSHMEM_I2C
+  .i2c =
+    {
+      .type          = RSC_VDEV,
+      .id            = VIRTIO_ID_I2C_ADAPTER,
+      .notifyid      = RSC_NOTIFY_ID_ANY,
+      .dfeatures     = 1 << VIRTIO_I2C_F_ZERO_LENGTH_REQUEST,
+      .config_len    = sizeof(struct vhost_i2c_config_s),
+      .num_of_vrings = 1,
+      .reserved      =
+        {
+          VIRTIO_DEV_DRIVER, 0
+        },
+    },
+  .i2c_vring =
+    {
+      .align     = 8,
+      .num       = 8,
+      .notifyid  = RSC_NOTIFY_ID_ANY,
+      .da        = FW_RSC_U32_ADDR_ANY,
+    },
+  .i2c_config =
+    {
+      .path = "/dev/i2c0",    /* Local I2C device node on the device side */
+    },
+  .i2c_carveout =
+    {
+      .type = RSC_CARVEOUT,
+      .da   = offsetof(struct rptun_ivshmem_rsc_s, i2c_shm) +
+              offsetof(struct rptun_ivshmem_mem_s, rsc_table),
+      .pa   = (uint32_t)METAL_BAD_PHYS,
+      .len  = sizeof(g_rsc_table.i2c_shm),
+    },
+#endif
 };
 
 /****************************************************************************
@@ -445,6 +498,10 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev)
 #ifdef CONFIG_DRIVERS_VHOST_NET
           snprintf((FAR char *)rsc->net_carveout.name, RPROC_MAX_NAME_LEN,
                    "vdev%dbuffer", i++);
+#endif
+#ifdef CONFIG_DRIVERS_VHOST_I2C
+          snprintf((FAR char *)rsc->i2c_carveout.name, RPROC_MAX_NAME_LEN,
+                   "vdev%dbuffer", i++);
 #endif
           UNUSED(rsc);
           UNUSED(i);

Reply via email to