diff --git a/drivers/vhost/CMakeLists.txt b/drivers/vhost/CMakeLists.txt index 4955d47a4e7..bbd55eea04a 100644 --- a/drivers/vhost/CMakeLists.txt +++ b/drivers/vhost/CMakeLists.txt @@ -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}) diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig index e2f7bb73ed4..b203565e149 100644 --- a/drivers/vhost/Kconfig +++ b/drivers/vhost/Kconfig @@ -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 diff --git a/drivers/vhost/Make.defs b/drivers/vhost/Make.defs index 4a70eef5943..d48ca2b45c8 100644 --- a/drivers/vhost/Make.defs +++ b/drivers/vhost/Make.defs @@ -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 diff --git a/drivers/vhost/vhost-rpmsg.c b/drivers/vhost/vhost-rpmsg.c new file mode 100644 index 00000000000..00ec58a9a51 --- /dev/null +++ b/drivers/vhost/vhost-rpmsg.c @@ -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 +#include + +#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); +} diff --git a/drivers/vhost/vhost-rpmsg.h b/drivers/vhost/vhost-rpmsg.h new file mode 100644 index 00000000000..d0a79331827 --- /dev/null +++ b/drivers/vhost/vhost-rpmsg.h @@ -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 + +#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 */ diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index a2c83d2f2e0..1d74723b345 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -32,6 +32,7 @@ #include #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); } diff --git a/drivers/virtio/CMakeLists.txt b/drivers/virtio/CMakeLists.txt index 40573d07cf6..89750f12c34 100644 --- a/drivers/virtio/CMakeLists.txt +++ b/drivers/virtio/CMakeLists.txt @@ -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() diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index 3642add84f8..a8ead4c872e 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -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 diff --git a/drivers/virtio/Make.defs b/drivers/virtio/Make.defs index 46a1d928e50..f9545548b14 100644 --- a/drivers/virtio/Make.defs +++ b/drivers/virtio/Make.defs @@ -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 diff --git a/drivers/virtio/virtio-rpmsg.c b/drivers/virtio/virtio-rpmsg.c new file mode 100644 index 00000000000..cf8b3ff8a6c --- /dev/null +++ b/drivers/virtio/virtio-rpmsg.c @@ -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 +#include + +#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); +} diff --git a/drivers/virtio/virtio-rpmsg.h b/drivers/virtio/virtio-rpmsg.h new file mode 100644 index 00000000000..ce374d55e19 --- /dev/null +++ b/drivers/virtio/virtio-rpmsg.h @@ -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 + +#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 */ diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 571cbfb35da..24783aad4a1 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -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)