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

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

commit 8c4345e0081507c563b583f3bfd45934eb90b41e
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Oct 27 21:37:39 2026 +0800

    drivers/ivshmem: let the backend choose the device id
    
    The bus numbers devices in the order the backends register them, so a
    board with several ivshmem devices cannot tie a driver to a given one.
    Keep the id the backend sets, and assign the next one only when it is
    negative, as the PCI backend now asks for.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/ivshmem/ivshmem.c | 5 ++++-
 drivers/pci/pci_ivshmem.c | 1 +
 include/nuttx/ivshmem.h   | 9 +++++----
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/ivshmem/ivshmem.c b/drivers/ivshmem/ivshmem.c
index 2c14eabbc24..ea9449056b8 100644
--- a/drivers/ivshmem/ivshmem.c
+++ b/drivers/ivshmem/ivshmem.c
@@ -83,7 +83,10 @@ int ivshmem_register_device(FAR struct ivshmem_device_s *dev,
 
   dev->kick_peer = kick_peer;
 
-  dev->id = g_ivshmem_next_id++;
+  if (dev->id < 0)
+    {
+      dev->id = g_ivshmem_next_id++;
+    }
 
   /* Add the device to the ivshmem_bus device queue */
 
diff --git a/drivers/pci/pci_ivshmem.c b/drivers/pci/pci_ivshmem.c
index 4d992377544..82bb298502e 100644
--- a/drivers/pci/pci_ivshmem.c
+++ b/drivers/pci/pci_ivshmem.c
@@ -124,6 +124,7 @@ static int pci_ivshmem_probe(FAR struct pci_device_s *dev)
   dev->priv  = priv;
   priv->dev  = dev;
   ivdev      = &priv->ivdev;
+  ivdev->id  = -1;
 
   ret = pci_enable_device(dev);
   if (ret < 0)
diff --git a/include/nuttx/ivshmem.h b/include/nuttx/ivshmem.h
index dc6e6fe1f29..61d02c54304 100644
--- a/include/nuttx/ivshmem.h
+++ b/include/nuttx/ivshmem.h
@@ -70,8 +70,8 @@ struct ivshmem_driver_s
   dq_entry_t       node;
 };
 
-/* Filled in by a backend and embedded in its own device structure. The
- * id is assigned by ivshmem_register_device().
+/* Filled in by a backend and embedded in its own device structure. A
+ * negative id asks ivshmem_register_device() to assign the next one.
  */
 
 struct ivshmem_device_s
@@ -198,8 +198,9 @@ int ivshmem_unregister_driver(FAR struct ivshmem_driver_s 
*drv);
  *
  * Description:
  *   Called by a backend to add a device to the ivshmem bus. Assigns the
- *   device id and probes the matching driver, if one is registered.
- *   kick_peer notifies the peer, or is NULL when the device has none.
+ *   device id if it is negative and probes the matching driver, if one
+ *   is registered. kick_peer notifies the peer, or is NULL when the
+ *   device has none.
  *
  ****************************************************************************/
 

Reply via email to