include/nuttx/virtio: allow common virtio helpers to be used by vhost

Move common virtio inline functions (virtqueue_kick_lock, virtio_malloc_buf,
virtio_zalloc_buf, etc.) from CONFIG_DRIVERS_VIRTIO guard to CONFIG_OPENAMP
guard. This allows vhost drivers to reuse these helper functions without
requiring the full virtio driver framework.

The virtio_driver structure and driver registration APIs remain under
CONFIG_DRIVERS_VIRTIO as they are specific to virtio device drivers.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang
2025-08-17 16:51:50 +08:00
committed by Xiang Xiao
parent 2274c31950
commit 8d6eaae3d7
+19 -13
View File
@@ -33,7 +33,7 @@
#include <nuttx/spinlock.h> #include <nuttx/spinlock.h>
#include <nuttx/virtio/virtio-config.h> #include <nuttx/virtio/virtio-config.h>
#ifdef CONFIG_DRIVERS_VIRTIO #ifdef CONFIG_OPENAMP
#include <openamp/open_amp.h> #include <openamp/open_amp.h>
@@ -41,6 +41,7 @@
* Public Type Definitions * Public Type Definitions
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_DRIVERS_VIRTIO
struct virtio_driver struct virtio_driver
{ {
struct list_node node; struct list_node node;
@@ -48,6 +49,7 @@ struct virtio_driver
CODE int (*probe)(FAR struct virtio_device *vdev); CODE int (*probe)(FAR struct virtio_device *vdev);
CODE void (*remove)(FAR struct virtio_device *vdev); CODE void (*remove)(FAR struct virtio_device *vdev);
}; };
#endif
/**************************************************************************** /****************************************************************************
* Inline functions * Inline functions
@@ -175,18 +177,6 @@ static inline_function void virtqueue_kick_lock(FAR struct virtqueue *vq,
spin_unlock_irqrestore(lock, flags); spin_unlock_irqrestore(lock, flags);
} }
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
static inline_function FAR void * static inline_function FAR void *
virtio_malloc_buf(FAR struct virtio_device *vdev, size_t size, size_t align) virtio_malloc_buf(FAR struct virtio_device *vdev, size_t size, size_t align)
{ {
@@ -214,6 +204,22 @@ virtio_zalloc_buf(FAR struct virtio_device *vdev, size_t size, size_t align)
return buf; return buf;
} }
#endif /* CONFIG_OPENAMP */
#ifdef CONFIG_DRIVERS_VIRTIO
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/* Driver and device register/unregister function */ /* Driver and device register/unregister function */
int virtio_register_driver(FAR struct virtio_driver *driver); int virtio_register_driver(FAR struct virtio_driver *driver);