virtio and vhost-rpmsg: add virtio and vhost rpmsg device support

virtio and vhost rpmsg device as standalone device registered to
the virtio and vhost bus.

virtio-rpmsg and vhost-rpmsg use the common virtio_rpmsg_common.c
implementation in rpmsg dir.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang
2024-07-22 22:41:09 +08:00
committed by GUIDINGLI
parent 6003369ceb
commit 4ded8df3d5
12 changed files with 272 additions and 0 deletions
+4
View File
@@ -29,5 +29,9 @@ if(CONFIG_DRIVERS_VHOST_RNG)
list(APPEND SRCS vhost_rng.c)
endif()
if(CONFIG_DRIVERS_VHOST_RPMSG)
list(APPEND SRCS vhost-rpmsg.c)
endif()
target_sources(drivers PRIVATE ${SRCS})
target_include_directories(drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+5
View File
@@ -14,4 +14,9 @@ config DRIVERS_VHOST_RNG
bool "Virtual Host Rng Device Support"
default n
config DRIVERS_VHOST_RPMSG
bool "Virtual Host Rpmsg Device Support"
default n
select RPMSG_VIRTIO
endif # DRIVERS_VHOST
+4
View File
@@ -30,6 +30,10 @@ ifeq ($(CONFIG_DRIVERS_VHOST_RNG),y)
CSRCS += vhost-rng.c
endif
ifeq ($(CONFIG_DRIVERS_VHOST_RPMSG),y)
CSRCS += vhost-rpmsg.c
endif
# Include build support
DEPPATH += --dep-path vhost
+53
View File
@@ -0,0 +1,53 @@
/****************************************************************************
* drivers/vhost/vhost-rpmsg.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/rpmsg/rpmsg_virtio.h>
#include <nuttx/vhost/vhost.h>
#include "vhost-rpmsg.h"
/****************************************************************************
* Private Data
****************************************************************************/
static struct vhost_driver g_vhost_rpmsg_driver =
{
LIST_INITIAL_VALUE(g_vhost_rpmsg_driver.node), /* Node */
VIRTIO_ID_RPMSG, /* Device id */
rpmsg_virtio_probe, /* Probe */
rpmsg_virtio_remove, /* Remove */
};
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: vhost_register_rng_driver
****************************************************************************/
int vhost_register_rpmsg_driver(void)
{
return vhost_register_driver(&g_vhost_rpmsg_driver);
}
+61
View File
@@ -0,0 +1,61 @@
/****************************************************************************
* drivers/vhost/vhost-rpmsg.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_VHOST_VHOST_RPMSG_H
#define __DRIVERS_VHOST_VHOST_RPMSG_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_DRIVERS_VHOST_RPMSG
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int vhost_register_rpmsg_driver(void);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_DRIVERS_VHOST_RPMSG */
#endif /* __DRIVERS_VHOST_VHOST_RPMSG_H */
+9
View File
@@ -32,6 +32,7 @@
#include <nuttx/vhost/vhost.h>
#include "vhost-rng.h"
#include "vhost-rpmsg.h"
/****************************************************************************
* Pre-processor Definitions
@@ -397,5 +398,13 @@ void vhost_register_drivers(void)
}
#endif
#ifdef CONFIG_DRIVERS_VHOST_RPMSG
ret = vhost_register_rpmsg_driver();
if (ret < 0)
{
vhosterr("vhost_register_rpmsg_driver failed, ret=%d\n", ret);
}
#endif
UNUSED(ret);
}
+4
View File
@@ -57,6 +57,10 @@ if(CONFIG_DRIVERS_VIRTIO_RPMB)
list(APPEND SRCS virtio-rpmb.c)
endif()
if(CONFIG_DRIVERS_VIRTIO_RPMSG)
list(APPEND SRCS virtio-rpmsg.c)
endif()
if(CONFIG_DRIVERS_VIRTIO_SERIAL)
list(APPEND SRCS virtio-serial.c)
endif()
+5
View File
@@ -79,6 +79,11 @@ config DRIVERS_VIRTIO_RPMB
bool "Virtio RPMB support"
default n
config DRIVERS_VIRTIO_RPMSG
bool "Virtio Rpmsg support"
default n
select RPMSG_VIRTIO
config DRIVERS_VIRTIO_SERIAL
bool "Virtio serial support"
depends on SERIAL
+4
View File
@@ -58,6 +58,10 @@ ifeq ($(CONFIG_DRIVERS_VIRTIO_RPMB),y)
CSRCS += virtio-rpmb.c
endif
ifeq ($(CONFIG_DRIVERS_VIRTIO_RPMSG),y)
CSRCS += virtio-rpmsg.c
endif
ifeq ($(CONFIG_DRIVERS_VIRTIO_SERIAL),y)
CSRCS += virtio-serial.c
endif
+53
View File
@@ -0,0 +1,53 @@
/****************************************************************************
* drivers/virtio/virtio-rpmsg.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/rpmsg/rpmsg_virtio.h>
#include <nuttx/virtio/virtio.h>
#include "virtio-rpmsg.h"
/****************************************************************************
* Private Data
****************************************************************************/
static struct virtio_driver g_virtio_rpmsg_driver =
{
LIST_INITIAL_VALUE(g_virtio_rpmsg_driver.node), /* Node */
VIRTIO_ID_RPMSG, /* Device id */
rpmsg_virtio_probe, /* Probe */
rpmsg_virtio_remove, /* Remove */
};
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: virtio_register_rpmsg_driver
****************************************************************************/
int virtio_register_rpmsg_driver(void)
{
return virtio_register_driver(&g_virtio_rpmsg_driver);
}
+61
View File
@@ -0,0 +1,61 @@
/****************************************************************************
* drivers/virtio/virtio-rpmsg.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_VIRTIO_VIRTIO_RPMSG_H
#define __DRIVERS_VIRTIO_VIRTIO_RPMSG_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_DRIVERS_VIRTIO_RPMSG
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int virtio_register_rpmsg_driver(void);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_DRIVERS_VIRTIO_RPMSG */
#endif /* __DRIVERS_VIRTIO_VIRTIO_RPMSG_H */
+9
View File
@@ -37,6 +37,7 @@
#include "virtio-net.h"
#include "virtio-rng.h"
#include "virtio-rpmb.h"
#include "virtio-rpmsg.h"
#include "virtio-serial.h"
#include "virtio-snd.h"
@@ -129,6 +130,14 @@ void virtio_register_drivers(void)
}
#endif
#ifdef CONFIG_DRIVERS_VIRTIO_RPMSG
ret = virtio_register_rpmsg_driver();
if (ret < 0)
{
vrterr("virtio_register_rpmsg_driver failed, ret=%d\n", ret);
}
#endif
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL
ret = virtio_register_serial_driver();
if (ret < 0)