mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
virtio: add virtio framework in NuttX
1. virtio devics/drivers match and probe/remote mechanism;
2. virtio mmio transport layer based on OpenAmp (Compatible with both
virtio mmio version 1 and 2);
3. virtio-serial driver based on new virtio framework;
4. virtio-rng driver based on new virtio framework;
5. virtio-net driver based on new virtio framework
(IOB Offload implementation);
6. virtio-blk driver based on new virtio framework;
7. Remove the old virtio mmio framework, the old framework only
support mmio transport layer, and the new framwork support
more transport layer and this commit has implemented all the
old virtio drivers;
8. Refresh the the qemu-arm64 and qemu-riscv virtio related
configs, and update its README.txt;
New virtio-net driver has better performance
Compared with previous virtio-mmio-net:
| | master/-c | master/-s | this/-c | this/-s |
| :--------------------: | :-------: | :-------: | :-----: | :-----: |
| qemu-armv8a:netnsh | 539Mbps | 524Mbps | 906Mbps | 715Mbps |
| qemu-armv8a:netnsh_smp | 401Mbps | 437Mbps | 583Mbps | 505Mbps |
| rv-virt:netnsh | 487Mbps | 512Mbps | 760Mbps | 634Mbps |
| rv-virt:netnsh_smp | 387Mbps | 455Mbps | 447Mbps | 502Mbps |
| rv-virt:netnsh64 | 602Mbps | 595Mbps | 881Mbps | 769Mbps |
| rv-virt:netnsh64_smp | 414Mbps | 515Mbps | 491Mbps | 525Mbps |
| rv-virt:knetnsh64 | 515Mbps | 457Mbps | 606Mbps | 540Mbps |
| rv-virt:knetnsh64_smp | 308Mbps | 389Mbps | 415Mbps | 474Mbps |
Note: Both CONFIG_IOB_NBUFFERS=64, using iperf command, all in Mbits/sec
Tested in QEMU 7.2.2
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
@@ -26,7 +26,3 @@ CHIP_CSRCS = qemu_boot.c qemu_serial.c
|
|||||||
ifeq ($(CONFIG_ARCH_EARLY_PRINT),y)
|
ifeq ($(CONFIG_ARCH_EARLY_PRINT),y)
|
||||||
CHIP_ASRCS = qemu_lowputc.S
|
CHIP_ASRCS = qemu_lowputc.S
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_DRIVERS_VIRTIO_NET),y)
|
|
||||||
CHIP_CSRCS += qemu_virtio.c
|
|
||||||
endif
|
|
||||||
|
|||||||
@@ -36,7 +36,3 @@ endif
|
|||||||
ifeq ($(CONFIG_MM_PGALLOC),y)
|
ifeq ($(CONFIG_MM_PGALLOC),y)
|
||||||
CHIP_CSRCS += qemu_rv_pgalloc.c
|
CHIP_CSRCS += qemu_rv_pgalloc.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_DRIVERS_VIRTIO_NET),y)
|
|
||||||
CHIP_CSRCS += qemu_rv_virtio.c
|
|
||||||
endif
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ Getting Started
|
|||||||
-net none -chardev stdio,id=con,mux=on -serial chardev:con \
|
-net none -chardev stdio,id=con,mux=on -serial chardev:con \
|
||||||
-mon chardev=con,mode=readline -kernel ./nuttx
|
-mon chardev=con,mode=readline -kernel ./nuttx
|
||||||
|
|
||||||
3.1.1 Single Core with virtio network and block driver (GICv3)
|
3.1.1 Single Core with virtio network, block, rng, serial driver (GICv3)
|
||||||
Configuring NuttX and compile:
|
Configuring NuttX and compile:
|
||||||
$ ./tools/configure.sh -l qemu-armv8a:netnsh
|
$ ./tools/configure.sh -l qemu-armv8a:netnsh
|
||||||
$ make
|
$ make
|
||||||
@@ -61,9 +61,14 @@ Getting Started
|
|||||||
-machine virt,virtualization=on,gic-version=3 \
|
-machine virt,virtualization=on,gic-version=3 \
|
||||||
-chardev stdio,id=con,mux=on -serial chardev:con \
|
-chardev stdio,id=con,mux=on -serial chardev:con \
|
||||||
-global virtio-mmio.force-legacy=false \
|
-global virtio-mmio.force-legacy=false \
|
||||||
-drive file=./mydisk-1gb.img,if=none,format=raw,id=hd -device virtio-blk-device,drive=hd \
|
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
|
||||||
|
-chardev socket,telnet=on,host=127.0.0.1,port=3450,server=on,wait=off,id=foo \
|
||||||
|
-device virtconsole,chardev=foo \
|
||||||
|
-device virtio-rng-device,bus=virtio-mmio-bus.1 \
|
||||||
-netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
|
-netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
|
||||||
-device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \
|
-device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.2 \
|
||||||
|
-drive file=./mydisk-1gb.img,if=none,format=raw,id=hd \
|
||||||
|
-device virtio-blk-device,bus=virtio-mmio-bus.3,drive=hd \
|
||||||
-mon chardev=con,mode=readline -kernel ./nuttx
|
-mon chardev=con,mode=readline -kernel ./nuttx
|
||||||
|
|
||||||
3.2 SMP (GICv3)
|
3.2 SMP (GICv3)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
# modifications.
|
# modifications.
|
||||||
#
|
#
|
||||||
|
# CONFIG_NDEBUG is not set
|
||||||
CONFIG_ALLOW_BSD_COMPONENTS=y
|
CONFIG_ALLOW_BSD_COMPONENTS=y
|
||||||
CONFIG_ARCH="arm64"
|
CONFIG_ARCH="arm64"
|
||||||
CONFIG_ARCH_ARM64=y
|
CONFIG_ARCH_ARM64=y
|
||||||
@@ -22,11 +23,10 @@ CONFIG_DEFAULT_TASK_STACKSIZE=8192
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x0a000000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=48
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=32
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x200
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_EXAMPLES_HELLO=y
|
CONFIG_EXAMPLES_HELLO=y
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
CONFIG_FAT_LFN=y
|
CONFIG_FAT_LFN=y
|
||||||
@@ -38,7 +38,10 @@ CONFIG_HAVE_CXXINITIALIZE=y
|
|||||||
CONFIG_IDLETHREAD_STACKSIZE=8192
|
CONFIG_IDLETHREAD_STACKSIZE=8192
|
||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_ALIGNMENT=16
|
||||||
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_NET=y
|
CONFIG_NET=y
|
||||||
CONFIG_NETDB_DNSCLIENT=y
|
CONFIG_NETDB_DNSCLIENT=y
|
||||||
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
||||||
@@ -55,7 +58,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -65,6 +70,7 @@ CONFIG_NSH_ARCHINIT=y
|
|||||||
CONFIG_NSH_BUILTIN_APPS=y
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
CONFIG_NSH_FILEIOSIZE=512
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
CONFIG_NSH_READLINE=y
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PREALLOC_TIMERS=4
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
CONFIG_PTHREAD_STACK_MIN=8192
|
CONFIG_PTHREAD_STACK_MIN=8192
|
||||||
CONFIG_RAM_SIZE=134217728
|
CONFIG_RAM_SIZE=134217728
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ CONFIG_DEFAULT_TASK_STACKSIZE=8192
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x0a000000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=48
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=32
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x200
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_EXAMPLES_HELLO=y
|
CONFIG_EXAMPLES_HELLO=y
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
CONFIG_FAT_LFN=y
|
CONFIG_FAT_LFN=y
|
||||||
@@ -40,7 +39,10 @@ CONFIG_HAVE_CXXINITIALIZE=y
|
|||||||
CONFIG_IDLETHREAD_STACKSIZE=8192
|
CONFIG_IDLETHREAD_STACKSIZE=8192
|
||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_ALIGNMENT=16
|
||||||
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_NET=y
|
CONFIG_NET=y
|
||||||
CONFIG_NETDB_DNSCLIENT=y
|
CONFIG_NETDB_DNSCLIENT=y
|
||||||
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
||||||
@@ -57,7 +59,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -67,6 +71,7 @@ CONFIG_NSH_ARCHINIT=y
|
|||||||
CONFIG_NSH_BUILTIN_APPS=y
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
CONFIG_NSH_FILEIOSIZE=512
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
CONFIG_NSH_READLINE=y
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PREALLOC_TIMERS=4
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
CONFIG_PTHREAD_STACK_MIN=8192
|
CONFIG_PTHREAD_STACK_MIN=8192
|
||||||
CONFIG_RAM_SIZE=134217728
|
CONFIG_RAM_SIZE=134217728
|
||||||
|
|||||||
@@ -22,11 +22,10 @@ CONFIG_DEFAULT_TASK_STACKSIZE=8192
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x0a000000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=48
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=32
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x200
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_EXAMPLES_HELLO=y
|
CONFIG_EXAMPLES_HELLO=y
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
CONFIG_FAT_LFN=y
|
CONFIG_FAT_LFN=y
|
||||||
@@ -38,8 +37,9 @@ CONFIG_HAVE_CXXINITIALIZE=y
|
|||||||
CONFIG_IDLETHREAD_STACKSIZE=8192
|
CONFIG_IDLETHREAD_STACKSIZE=8192
|
||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
CONFIG_IOB_NBUFFERS=64
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_NET=y
|
CONFIG_NET=y
|
||||||
CONFIG_NETDB_DNSCLIENT=y
|
CONFIG_NETDB_DNSCLIENT=y
|
||||||
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
||||||
@@ -56,7 +56,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -66,6 +68,7 @@ CONFIG_NSH_ARCHINIT=y
|
|||||||
CONFIG_NSH_BUILTIN_APPS=y
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
CONFIG_NSH_FILEIOSIZE=512
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
CONFIG_NSH_READLINE=y
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PREALLOC_TIMERS=4
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
CONFIG_PTHREAD_STACK_MIN=8192
|
CONFIG_PTHREAD_STACK_MIN=8192
|
||||||
CONFIG_RAM_SIZE=134217728
|
CONFIG_RAM_SIZE=134217728
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ CONFIG_DEFAULT_TASK_STACKSIZE=8192
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x0a000000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=48
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=32
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x200
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_EXAMPLES_HELLO=y
|
CONFIG_EXAMPLES_HELLO=y
|
||||||
CONFIG_FAT_LFN=y
|
CONFIG_FAT_LFN=y
|
||||||
CONFIG_FS_FAT=y
|
CONFIG_FS_FAT=y
|
||||||
@@ -39,8 +38,9 @@ CONFIG_HAVE_CXXINITIALIZE=y
|
|||||||
CONFIG_IDLETHREAD_STACKSIZE=8192
|
CONFIG_IDLETHREAD_STACKSIZE=8192
|
||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
CONFIG_IOB_NBUFFERS=64
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_NET=y
|
CONFIG_NET=y
|
||||||
CONFIG_NETDB_DNSCLIENT=y
|
CONFIG_NETDB_DNSCLIENT=y
|
||||||
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
CONFIG_NETDB_DNSCLIENT_ENTRIES=4
|
||||||
@@ -57,7 +57,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -67,6 +69,7 @@ CONFIG_NSH_ARCHINIT=y
|
|||||||
CONFIG_NSH_BUILTIN_APPS=y
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
CONFIG_NSH_FILEIOSIZE=512
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
CONFIG_NSH_READLINE=y
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PREALLOC_TIMERS=4
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
CONFIG_PTHREAD_STACK_MIN=8192
|
CONFIG_PTHREAD_STACK_MIN=8192
|
||||||
CONFIG_RAM_SIZE=134217728
|
CONFIG_RAM_SIZE=134217728
|
||||||
|
|||||||
@@ -28,9 +28,42 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
|
#include <nuttx/virtio/virtio-mmio.h>
|
||||||
|
|
||||||
#include "qemu-armv8a.h"
|
#include "qemu-armv8a.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define QEMU_VIRTIO_MMIO_BASE 0x0a000000
|
||||||
|
#define QEMU_VIRTIO_MMIO_REGSIZE 0x200
|
||||||
|
#define QEMU_VIRTIO_MMIO_IRQ 48
|
||||||
|
#define QEMU_VIRTIO_MMIO_NUM 4
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: qemu_virtio_register_mmio_devices
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_MMIO
|
||||||
|
static void qemu_virtio_register_mmio_devices(void)
|
||||||
|
{
|
||||||
|
uintptr_t virtio = (uintptr_t)QEMU_VIRTIO_MMIO_BASE;
|
||||||
|
size_t size = QEMU_VIRTIO_MMIO_REGSIZE;
|
||||||
|
int irq = QEMU_VIRTIO_MMIO_IRQ;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < QEMU_VIRTIO_MMIO_NUM; i++)
|
||||||
|
{
|
||||||
|
virtio_register_mmio_device((FAR void *)(virtio + size * i), irq + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -57,6 +90,10 @@ int qemu_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_MMIO
|
||||||
|
qemu_virtio_register_mmio_devices();
|
||||||
|
#endif
|
||||||
|
|
||||||
UNUSED(ret);
|
UNUSED(ret);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,25 +57,35 @@
|
|||||||
...
|
...
|
||||||
nsh>
|
nsh>
|
||||||
|
|
||||||
4. Run the virtio network and block driver with qemu
|
4. Run the virtio network, block, serial and rng driver with qemu
|
||||||
|
|
||||||
$ dd if=/dev/zero of=./mydisk-1gb.img bs=1M count=1024
|
$ dd if=/dev/zero of=./mydisk-1gb.img bs=1M count=1024
|
||||||
|
|
||||||
$ qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 \
|
$ qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 \
|
||||||
-global virtio-mmio.force-legacy=false \
|
-global virtio-mmio.force-legacy=false \
|
||||||
-drive file=./mydisk-1gb.img,if=none,format=raw,id=hd -device virtio-blk-device,drive=hd \
|
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
|
||||||
-netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
|
-chardev socket,telnet=on,host=127.0.0.1,port=3450,server=on,wait=off,id=foo \
|
||||||
-device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \
|
-device virtconsole,chardev=foo \
|
||||||
-bios none -kernel nuttx -nographic
|
-device virtio-rng-device,bus=virtio-mmio-bus.1 \
|
||||||
|
-netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
|
||||||
|
-device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.2 \
|
||||||
|
-drive file=./mydisk-1gb.img,if=none,format=raw,id=hd \
|
||||||
|
-device virtio-blk-device,bus=virtio-mmio-bus.3,drive=hd \
|
||||||
|
-bios none -kernel ./nuttx/nuttx -nographic
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
$ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 \
|
$ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 \
|
||||||
-global virtio-mmio.force-legacy=false \
|
-global virtio-mmio.force-legacy=false \
|
||||||
-drive file=./mydisk-1gb.img,if=none,format=raw,id=hd -device virtio-blk-device,drive=hd \
|
-device virtio-serial-device,bus=virtio-mmio-bus.0 \
|
||||||
-netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
|
-chardev socket,telnet=on,host=127.0.0.1,port=3450,server=on,wait=off,id=foo \
|
||||||
-device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \
|
-device virtconsole,chardev=foo \
|
||||||
-bios none -kernel nuttx -nographic
|
-device virtio-rng-device,bus=virtio-mmio-bus.1 \
|
||||||
|
-netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
|
||||||
|
-device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.2 \
|
||||||
|
-drive file=./mydisk-1gb.img,if=none,format=raw,id=hd \
|
||||||
|
-device virtio-blk-device,bus=virtio-mmio-bus.3,drive=hd \
|
||||||
|
-bios none -kernel ./nuttx/nuttx -nographic
|
||||||
|
|
||||||
5. TODO
|
5. TODO
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,10 @@ CONFIG_DEBUG_SYMBOLS=y
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x10001000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=26
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=8
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x1000
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_ELF=y
|
CONFIG_ELF=y
|
||||||
CONFIG_EXAMPLES_HELLO=m
|
CONFIG_EXAMPLES_HELLO=m
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
@@ -73,7 +72,8 @@ CONFIG_INIT_MOUNT_SOURCE=""
|
|||||||
CONFIG_INIT_MOUNT_TARGET="/system"
|
CONFIG_INIT_MOUNT_TARGET="/system"
|
||||||
CONFIG_INIT_STACKSIZE=3072
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
|
CONFIG_IOB_THROTTLE=2
|
||||||
CONFIG_LIBC_ENVPATH=y
|
CONFIG_LIBC_ENVPATH=y
|
||||||
CONFIG_LIBC_EXECFUNCS=y
|
CONFIG_LIBC_EXECFUNCS=y
|
||||||
CONFIG_LIBC_PERROR_STDOUT=y
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
@@ -97,7 +97,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=16384
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -108,6 +110,7 @@ CONFIG_NSH_ARCHINIT=y
|
|||||||
CONFIG_NSH_FILEIOSIZE=512
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
CONFIG_NSH_FILE_APPS=y
|
CONFIG_NSH_FILE_APPS=y
|
||||||
CONFIG_NSH_READLINE=y
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PATH_INITIAL="/system/bin"
|
CONFIG_PATH_INITIAL="/system/bin"
|
||||||
CONFIG_RAM_SIZE=1048576
|
CONFIG_RAM_SIZE=1048576
|
||||||
CONFIG_RAM_START=0x80100000
|
CONFIG_RAM_START=0x80100000
|
||||||
|
|||||||
@@ -50,11 +50,10 @@ CONFIG_DEBUG_SYMBOLS=y
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x10001000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=26
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=8
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x1000
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_ELF=y
|
CONFIG_ELF=y
|
||||||
CONFIG_EXAMPLES_HELLO=m
|
CONFIG_EXAMPLES_HELLO=m
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
@@ -73,12 +72,15 @@ CONFIG_INIT_MOUNT_SOURCE=""
|
|||||||
CONFIG_INIT_MOUNT_TARGET="/system"
|
CONFIG_INIT_MOUNT_TARGET="/system"
|
||||||
CONFIG_INIT_STACKSIZE=3072
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
CONFIG_IOB_NBUFFERS=64
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_LIBC_ENVPATH=y
|
CONFIG_LIBC_ENVPATH=y
|
||||||
CONFIG_LIBC_EXECFUNCS=y
|
CONFIG_LIBC_EXECFUNCS=y
|
||||||
CONFIG_LIBC_PERROR_STDOUT=y
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
CONFIG_LIBC_STRERROR=y
|
CONFIG_LIBC_STRERROR=y
|
||||||
|
CONFIG_MEMCPY_64BIT=y
|
||||||
|
CONFIG_MEMCPY_VIK=y
|
||||||
CONFIG_MEMSET_64BIT=y
|
CONFIG_MEMSET_64BIT=y
|
||||||
CONFIG_MEMSET_OPTSPEED=y
|
CONFIG_MEMSET_OPTSPEED=y
|
||||||
CONFIG_MM_PGALLOC=y
|
CONFIG_MM_PGALLOC=y
|
||||||
@@ -98,7 +100,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -109,6 +113,7 @@ CONFIG_NSH_ARCHINIT=y
|
|||||||
CONFIG_NSH_FILEIOSIZE=512
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
CONFIG_NSH_FILE_APPS=y
|
CONFIG_NSH_FILE_APPS=y
|
||||||
CONFIG_NSH_READLINE=y
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PATH_INITIAL="/system/bin"
|
CONFIG_PATH_INITIAL="/system/bin"
|
||||||
CONFIG_RAM_SIZE=1048576
|
CONFIG_RAM_SIZE=1048576
|
||||||
CONFIG_RAM_START=0x80100000
|
CONFIG_RAM_START=0x80100000
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ CONFIG_DEBUG_SYMBOLS=y
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x10001000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=28
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=8
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x1000
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_ELF=y
|
CONFIG_ELF=y
|
||||||
CONFIG_EXAMPLES_HELLO=m
|
CONFIG_EXAMPLES_HELLO=m
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
@@ -52,7 +51,8 @@ CONFIG_IDLETHREAD_STACKSIZE=2048
|
|||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INIT_STACKSIZE=3072
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1530
|
||||||
|
CONFIG_IOB_THROTTLE=2
|
||||||
CONFIG_LIBC_ENVPATH=y
|
CONFIG_LIBC_ENVPATH=y
|
||||||
CONFIG_LIBC_EXECFUNCS=y
|
CONFIG_LIBC_EXECFUNCS=y
|
||||||
CONFIG_LIBC_PERROR_STDOUT=y
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
@@ -73,7 +73,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=28
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=16384
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -87,6 +89,7 @@ CONFIG_NSH_READLINE=y
|
|||||||
CONFIG_NSH_SYMTAB=y
|
CONFIG_NSH_SYMTAB=y
|
||||||
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
||||||
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PATH_INITIAL="/system/bin"
|
CONFIG_PATH_INITIAL="/system/bin"
|
||||||
CONFIG_RAM_SIZE=33554432
|
CONFIG_RAM_SIZE=33554432
|
||||||
CONFIG_RAM_START=0x80000000
|
CONFIG_RAM_START=0x80000000
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ CONFIG_DEBUG_SYMBOLS=y
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x10001000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=28
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=8
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x1000
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_ELF=y
|
CONFIG_ELF=y
|
||||||
CONFIG_EXAMPLES_HELLO=m
|
CONFIG_EXAMPLES_HELLO=m
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
@@ -52,7 +51,8 @@ CONFIG_IDLETHREAD_STACKSIZE=2048
|
|||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INIT_STACKSIZE=3072
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
|
CONFIG_IOB_THROTTLE=2
|
||||||
CONFIG_LIBC_ENVPATH=y
|
CONFIG_LIBC_ENVPATH=y
|
||||||
CONFIG_LIBC_EXECFUNCS=y
|
CONFIG_LIBC_EXECFUNCS=y
|
||||||
CONFIG_LIBC_PERROR_STDOUT=y
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
@@ -73,7 +73,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=16384
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -87,6 +89,7 @@ CONFIG_NSH_READLINE=y
|
|||||||
CONFIG_NSH_SYMTAB=y
|
CONFIG_NSH_SYMTAB=y
|
||||||
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
||||||
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PATH_INITIAL="/system/bin"
|
CONFIG_PATH_INITIAL="/system/bin"
|
||||||
CONFIG_RAM_SIZE=33554432
|
CONFIG_RAM_SIZE=33554432
|
||||||
CONFIG_RAM_START=0x80000000
|
CONFIG_RAM_START=0x80000000
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ CONFIG_DEBUG_SYMBOLS=y
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x10001000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=28
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=8
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x1000
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_ELF=y
|
CONFIG_ELF=y
|
||||||
CONFIG_EXAMPLES_HELLO=m
|
CONFIG_EXAMPLES_HELLO=m
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
@@ -52,8 +51,9 @@ CONFIG_IDLETHREAD_STACKSIZE=2048
|
|||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INIT_STACKSIZE=3072
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1534
|
||||||
CONFIG_IOB_NBUFFERS=64
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_LIBC_ENVPATH=y
|
CONFIG_LIBC_ENVPATH=y
|
||||||
CONFIG_LIBC_EXECFUNCS=y
|
CONFIG_LIBC_EXECFUNCS=y
|
||||||
CONFIG_LIBC_PERROR_STDOUT=y
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
@@ -77,7 +77,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=32
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -91,6 +93,7 @@ CONFIG_NSH_READLINE=y
|
|||||||
CONFIG_NSH_SYMTAB=y
|
CONFIG_NSH_SYMTAB=y
|
||||||
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
||||||
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PATH_INITIAL="/system/bin"
|
CONFIG_PATH_INITIAL="/system/bin"
|
||||||
CONFIG_RAM_SIZE=33554432
|
CONFIG_RAM_SIZE=33554432
|
||||||
CONFIG_RAM_START=0x80000000
|
CONFIG_RAM_START=0x80000000
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ CONFIG_DEBUG_SYMBOLS=y
|
|||||||
CONFIG_DEV_ZERO=y
|
CONFIG_DEV_ZERO=y
|
||||||
CONFIG_DRIVERS_VIRTIO=y
|
CONFIG_DRIVERS_VIRTIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_BLK=y
|
CONFIG_DRIVERS_VIRTIO_BLK=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_BASE=0x10001000
|
CONFIG_DRIVERS_VIRTIO_MMIO=y
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_IRQ=28
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_NUM=8
|
|
||||||
CONFIG_DRIVERS_VIRTIO_MMIO_REGSIZE=0x1000
|
|
||||||
CONFIG_DRIVERS_VIRTIO_NET=y
|
CONFIG_DRIVERS_VIRTIO_NET=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_RNG=y
|
||||||
|
CONFIG_DRIVERS_VIRTIO_SERIAL=y
|
||||||
CONFIG_ELF=y
|
CONFIG_ELF=y
|
||||||
CONFIG_EXAMPLES_HELLO=m
|
CONFIG_EXAMPLES_HELLO=m
|
||||||
CONFIG_FAT_LCNAMES=y
|
CONFIG_FAT_LCNAMES=y
|
||||||
@@ -52,8 +51,9 @@ CONFIG_IDLETHREAD_STACKSIZE=2048
|
|||||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
CONFIG_INIT_STACKSIZE=3072
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
CONFIG_INTELHEX_BINARY=y
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_IOB_BUFSIZE=1514
|
CONFIG_IOB_BUFSIZE=1530
|
||||||
CONFIG_IOB_NBUFFERS=64
|
CONFIG_IOB_NBUFFERS=64
|
||||||
|
CONFIG_IOB_THROTTLE=8
|
||||||
CONFIG_LIBC_ENVPATH=y
|
CONFIG_LIBC_ENVPATH=y
|
||||||
CONFIG_LIBC_EXECFUNCS=y
|
CONFIG_LIBC_EXECFUNCS=y
|
||||||
CONFIG_LIBC_PERROR_STDOUT=y
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
@@ -77,7 +77,9 @@ CONFIG_NET_BROADCAST=y
|
|||||||
CONFIG_NET_ETH_PKTSIZE=1514
|
CONFIG_NET_ETH_PKTSIZE=1514
|
||||||
CONFIG_NET_ICMP=y
|
CONFIG_NET_ICMP=y
|
||||||
CONFIG_NET_ICMP_SOCKET=y
|
CONFIG_NET_ICMP_SOCKET=y
|
||||||
|
CONFIG_NET_LL_GUARDSIZE=28
|
||||||
CONFIG_NET_MAX_LISTENPORTS=8
|
CONFIG_NET_MAX_LISTENPORTS=8
|
||||||
|
CONFIG_NET_RECV_BUFSIZE=32768
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_TCPBACKLOG=y
|
CONFIG_NET_TCPBACKLOG=y
|
||||||
@@ -91,6 +93,7 @@ CONFIG_NSH_READLINE=y
|
|||||||
CONFIG_NSH_SYMTAB=y
|
CONFIG_NSH_SYMTAB=y
|
||||||
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
|
||||||
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
|
||||||
|
CONFIG_OPENAMP=y
|
||||||
CONFIG_PATH_INITIAL="/system/bin"
|
CONFIG_PATH_INITIAL="/system/bin"
|
||||||
CONFIG_RAM_SIZE=33554432
|
CONFIG_RAM_SIZE=33554432
|
||||||
CONFIG_RAM_START=0x80000000
|
CONFIG_RAM_START=0x80000000
|
||||||
|
|||||||
@@ -30,9 +30,46 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/board.h>
|
#include <nuttx/board.h>
|
||||||
|
#include <nuttx/virtio/virtio-mmio.h>
|
||||||
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define QEMU_VIRTIO_MMIO_BASE 0x10001000
|
||||||
|
#define QEMU_VIRTIO_MMIO_REGSIZE 0x1000
|
||||||
|
#ifdef CONFIG_ARCH_USE_S_MODE
|
||||||
|
# define QEMU_VIRTIO_MMIO_IRQ 26
|
||||||
|
#else
|
||||||
|
# define QEMU_VIRTIO_MMIO_IRQ 28
|
||||||
|
#endif
|
||||||
|
#define QEMU_VIRTIO_MMIO_NUM 4
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: qemu_virtio_register_mmio_devices
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_MMIO
|
||||||
|
static void qemu_virtio_register_mmio_devices(void)
|
||||||
|
{
|
||||||
|
uintptr_t virtio = (uintptr_t)QEMU_VIRTIO_MMIO_BASE;
|
||||||
|
size_t size = QEMU_VIRTIO_MMIO_REGSIZE;
|
||||||
|
int irq = QEMU_VIRTIO_MMIO_IRQ;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < QEMU_VIRTIO_MMIO_NUM; i++)
|
||||||
|
{
|
||||||
|
virtio_register_mmio_device((FAR void *)(virtio + size * i), irq + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -75,6 +112,10 @@ int board_app_initialize(uintptr_t arg)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_MMIO
|
||||||
|
qemu_virtio_register_mmio_devices();
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
#include <nuttx/syslog/syslog.h>
|
#include <nuttx/syslog/syslog.h>
|
||||||
#include <nuttx/syslog/syslog_console.h>
|
#include <nuttx/syslog/syslog_console.h>
|
||||||
#include <nuttx/usrsock/usrsock_rpmsg.h>
|
#include <nuttx/usrsock/usrsock_rpmsg.h>
|
||||||
|
#include <nuttx/virtio/virtio.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
@@ -203,4 +204,8 @@ void drivers_initialize(void)
|
|||||||
#ifdef CONFIG_MTD_LOOP
|
#ifdef CONFIG_MTD_LOOP
|
||||||
mtd_loop_register();
|
mtd_loop_register();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO
|
||||||
|
virtio_register_drivers();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# ##############################################################################
|
||||||
|
# drivers/virtio/CMakeLists.txt
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# ##############################################################################
|
||||||
|
set(SRCS)
|
||||||
|
|
||||||
|
if(CONFIG_DRIVERS_VIRTIO)
|
||||||
|
list(APPEND SRCS virtio.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_DRIVERS_VIRTIO_MMIO)
|
||||||
|
list(APPEND SRCS virtio-mmio.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_DRIVERS_VIRTIO_BLK)
|
||||||
|
list(APPEND SRCS virtio-blk.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_DRIVERS_VIRTIO_NET)
|
||||||
|
list(APPEND SRCS virtio-net.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_DRIVERS_VIRTIO_RNG)
|
||||||
|
list(APPEND SRCS virtio-rng.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_DRIVERS_VIRTIO_SERIAL)
|
||||||
|
list(APPEND SRCS virtio-serial.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_sources(drivers PRIVATE ${SRCS})
|
||||||
|
target_include_directories(drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
+46
-37
@@ -5,50 +5,59 @@
|
|||||||
|
|
||||||
menuconfig DRIVERS_VIRTIO
|
menuconfig DRIVERS_VIRTIO
|
||||||
bool "Virtio Device Support"
|
bool "Virtio Device Support"
|
||||||
depends on !OPENAMP
|
depends on OPENAMP
|
||||||
default n
|
default n
|
||||||
|
|
||||||
if DRIVERS_VIRTIO
|
if DRIVERS_VIRTIO
|
||||||
menuconfig DRIVERS_VIRTIO_MMIO_NUM
|
config DRIVERS_VIRTIO_MMIO
|
||||||
int "The number of virtio mmio devices"
|
bool "Virtio MMIO Device Support"
|
||||||
default 1
|
default n
|
||||||
|
|
||||||
if DRIVERS_VIRTIO_MMIO_NUM != 0
|
config DRIVERS_VIRTIO_MMIO_QUEUE_LEN
|
||||||
menuconfig DRIVERS_VIRTIO_MMIO_BASE
|
int "Virtio MMIO Virtio Queue Length"
|
||||||
hex "Virtio-mmio base address"
|
|
||||||
|
|
||||||
menuconfig DRIVERS_VIRTIO_MMIO_REGSIZE
|
|
||||||
hex "Virtio-mmio register size"
|
|
||||||
default 0
|
default 0
|
||||||
|
range 0 1024
|
||||||
|
depends on DRIVERS_VIRTIO_MMIO
|
||||||
|
---help---
|
||||||
|
If this value equals to 0, use the max queue length get from
|
||||||
|
mmio register.
|
||||||
|
|
||||||
menuconfig DRIVERS_VIRTIO_MMIO_IRQ
|
config DRIVERS_VIRTIO_BLK
|
||||||
int "Virtio-mmio irq number"
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
menuconfig DRIVERS_VIRTIO_NET
|
|
||||||
bool "Virtio network support"
|
|
||||||
default n
|
|
||||||
depends on DRIVERS_VIRTIO_MMIO_NUM > 0
|
|
||||||
select ARCH_HAVE_NETDEV_STATISTICS
|
|
||||||
|
|
||||||
if DRIVERS_VIRTIO_NET
|
|
||||||
config DRIVERS_VIRTIO_NET_QUEUE_LEN
|
|
||||||
int "Queue length"
|
|
||||||
default 16
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
menuconfig DRIVERS_VIRTIO_BLK
|
|
||||||
bool "Virtio block support"
|
bool "Virtio block support"
|
||||||
|
depends on !DISABLE_MOUNTPOINT
|
||||||
default n
|
default n
|
||||||
depends on DRIVERS_VIRTIO_MMIO_NUM > 0
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
if DRIVERS_VIRTIO_BLK
|
|
||||||
config DRIVERS_VIRTIO_BLK_QUEUE_LEN
|
|
||||||
int "Queue length"
|
|
||||||
default 16
|
|
||||||
|
|
||||||
|
config DRIVERS_VIRTIO_NET
|
||||||
|
bool "Virtio network support"
|
||||||
|
depends on NETDEVICES
|
||||||
|
default n
|
||||||
|
select ARCH_HAVE_NETDEV_STATISTICS
|
||||||
|
select NETDEV_LATEINIT
|
||||||
|
|
||||||
|
config DRIVERS_VIRTIO_NET_BUFNUM
|
||||||
|
int "Virtio network driver buffer number"
|
||||||
|
default 0
|
||||||
|
depends on DRIVERS_VIRTIO_NET
|
||||||
|
---help---
|
||||||
|
The buffer number in each virtqueue. (We have 2 virtqueues.)
|
||||||
|
If this value equals to 0, use CONFIG_IOB_NBUFFERS / 4 for each.
|
||||||
|
Normally we get just a little improvement for >8 buffers, and very little for >32.
|
||||||
|
|
||||||
|
config DRIVERS_VIRTIO_RNG
|
||||||
|
bool "Virtio rng support"
|
||||||
|
default n
|
||||||
|
select ARCH_HAVE_RNG
|
||||||
|
|
||||||
|
config DRIVERS_VIRTIO_SERIAL
|
||||||
|
bool "Virtio serial support"
|
||||||
|
depends on SERIAL
|
||||||
|
default n
|
||||||
|
select SERIAL_RXDMA
|
||||||
|
select SERIAL_TXDMA
|
||||||
|
|
||||||
|
if DRIVERS_VIRTIO_SERIAL
|
||||||
|
config DRIVERS_VIRTIO_SERIAL_BUFSIZE
|
||||||
|
int "Virtio serial driver buffer size"
|
||||||
|
default 256
|
||||||
endif
|
endif
|
||||||
|
endif # DRIVERS_VIRTIO
|
||||||
|
|||||||
@@ -21,15 +21,27 @@
|
|||||||
# Include virtio support
|
# Include virtio support
|
||||||
|
|
||||||
ifeq ($(CONFIG_DRIVERS_VIRTIO),y)
|
ifeq ($(CONFIG_DRIVERS_VIRTIO),y)
|
||||||
|
CSRCS += virtio.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_DRIVERS_VIRTIO_MMIO),y)
|
||||||
CSRCS += virtio-mmio.c
|
CSRCS += virtio-mmio.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_DRIVERS_VIRTIO_NET),y)
|
ifeq ($(CONFIG_DRIVERS_VIRTIO_BLK),y)
|
||||||
CSRCS += virtio-mmio-net.c
|
CSRCS += virtio-blk.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_DRIVERS_VIRTIO_BLK),y)
|
ifeq ($(CONFIG_DRIVERS_VIRTIO_NET),y)
|
||||||
CSRCS += virtio-mmio-blk.c
|
CSRCS += virtio-net.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_DRIVERS_VIRTIO_RNG),y)
|
||||||
|
CSRCS += virtio-rng.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_DRIVERS_VIRTIO_SERIAL),y)
|
||||||
|
CSRCS += virtio-serial.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Include build support
|
# Include build support
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* drivers/virtio/virtio-mmio-blk.h
|
* drivers/virtio/virtio-blk.h
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __DRIVERS_VIRTIO_VIRTIO_MMIO_BLK_H
|
#ifndef __DRIVERS_VIRTIO_VIRTIO_BLK_H
|
||||||
#define __DRIVERS_VIRTIO_VIRTIO_MMIO_BLK_H
|
#define __DRIVERS_VIRTIO_VIRTIO_BLK_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
@@ -49,15 +49,7 @@ extern "C"
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
int virtio_register_blk_driver(void);
|
||||||
* Name: virtio_mmio_blk_init
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Called from virtio-mmio.c to initialize virtblk
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int virtio_mmio_blk_init(FAR struct virtio_mmio_regs *regs, uint32_t intid);
|
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -65,4 +57,5 @@ int virtio_mmio_blk_init(FAR struct virtio_mmio_regs *regs, uint32_t intid);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_DRIVERS_VIRTIO_BLK */
|
#endif /* CONFIG_DRIVERS_VIRTIO_BLK */
|
||||||
#endif /* __DRIVERS_VIRTIO_VIRTIO_MMIO_BLK_H */
|
|
||||||
|
#endif /* __DRIVERS_VIRTIO_VIRTIO_BLK_H */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+795
-155
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* drivers/virtio/virtio-mmio-net.h
|
* drivers/virtio/virtio-net.h
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __DRIVERS_VIRTIO_VIRTIO_MMIO_NET_H
|
#ifndef __DRIVERS_VIRTIO_VIRTIO_NET_H
|
||||||
#define __DRIVERS_VIRTIO_VIRTIO_MMIO_NET_H
|
#define __DRIVERS_VIRTIO_VIRTIO_NET_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
@@ -49,15 +49,7 @@ extern "C"
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
int virtio_register_net_driver(void);
|
||||||
* Name: virtio_mmio_net_init
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Called from virtio-mmio.c to initialize virtnet
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int virtio_mmio_net_init(FAR struct virtio_mmio_regs *regs, uint32_t intid);
|
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -65,4 +57,4 @@ int virtio_mmio_net_init(FAR struct virtio_mmio_regs *regs, uint32_t intid);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_DRIVERS_VIRTIO_NET */
|
#endif /* CONFIG_DRIVERS_VIRTIO_NET */
|
||||||
#endif /* __DRIVERS_VIRTIO_VIRTIO_MMIO_NET_H */
|
#endif /* __DRIVERS_VIRTIO_VIRTIO_NET_H */
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* drivers/virtio/virtio-rng.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 <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/fs/fs.h>
|
||||||
|
#include <nuttx/semaphore.h>
|
||||||
|
#include <nuttx/virtio/virtio.h>
|
||||||
|
|
||||||
|
#include "virtio-rng.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct virtio_rng_cookie_s
|
||||||
|
{
|
||||||
|
sem_t sem;
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct virtio_rng_priv_s
|
||||||
|
{
|
||||||
|
FAR struct virtio_device *vdev;
|
||||||
|
char name[NAME_MAX];
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* RNG file operation function */
|
||||||
|
|
||||||
|
static ssize_t virtio_rng_read(FAR struct file *filep, FAR char *buffer,
|
||||||
|
size_t buflen);
|
||||||
|
|
||||||
|
/* Virtio driver functions */
|
||||||
|
|
||||||
|
static int virtio_rng_probe(FAR struct virtio_device *vdev);
|
||||||
|
static void virtio_rng_remove(FAR struct virtio_device *vdev);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static struct virtio_driver g_virtio_rng_driver =
|
||||||
|
{
|
||||||
|
LIST_INITIAL_VALUE(g_virtio_rng_driver.node), /* node */
|
||||||
|
VIRTIO_ID_ENTROPY, /* device id */
|
||||||
|
virtio_rng_probe, /* probe */
|
||||||
|
virtio_rng_remove, /* remove */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct file_operations g_virtio_rng_ops =
|
||||||
|
{
|
||||||
|
NULL, /* open */
|
||||||
|
NULL, /* close */
|
||||||
|
virtio_rng_read, /* read */
|
||||||
|
NULL, /* write */
|
||||||
|
NULL, /* seek */
|
||||||
|
NULL, /* ioctl */
|
||||||
|
NULL, /* mmap */
|
||||||
|
NULL, /* truncate */
|
||||||
|
NULL, /* poll */
|
||||||
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||||
|
NULL, /* unlink */
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
static int g_virtio_rng_idx = 0;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_rng_done
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void virtio_rng_done(FAR struct virtqueue *vq)
|
||||||
|
{
|
||||||
|
FAR struct virtio_rng_cookie_s *cookie;
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
|
/* Get the buffer, virtqueue_get_buffer() return the cookie added in
|
||||||
|
* virtio_rng_read().
|
||||||
|
*/
|
||||||
|
|
||||||
|
cookie = virtqueue_get_buffer(vq, &len, NULL);
|
||||||
|
if (cookie != NULL)
|
||||||
|
{
|
||||||
|
/* Assign the return length */
|
||||||
|
|
||||||
|
cookie->len = len;
|
||||||
|
|
||||||
|
/* Read completed, post the sem */
|
||||||
|
|
||||||
|
nxsem_post(&cookie->sem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_rng_read
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static ssize_t virtio_rng_read(FAR struct file *filep, FAR char *buffer,
|
||||||
|
size_t buflen)
|
||||||
|
{
|
||||||
|
FAR struct virtio_rng_priv_s *priv = filep->f_inode->i_private;
|
||||||
|
FAR struct virtqueue *vq = priv->vdev->vrings_info[0].vq;
|
||||||
|
struct virtio_rng_cookie_s cookie;
|
||||||
|
struct virtqueue_buf vb;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Init the cookie */
|
||||||
|
|
||||||
|
cookie.len = 0;
|
||||||
|
nxsem_init(&cookie.sem, 0, 0);
|
||||||
|
|
||||||
|
/* Add the input buffer to the virtqueue, and the cookie as the virtqueue
|
||||||
|
* cookie. (virtqueue_get_buffer() will return cookie).
|
||||||
|
*/
|
||||||
|
|
||||||
|
vb.buf = buffer;
|
||||||
|
vb.len = buflen;
|
||||||
|
ret = virtqueue_add_buffer(vq, &vb, 0, 1, &cookie);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Notify the other side to process the added virtqueue buffer */
|
||||||
|
|
||||||
|
virtqueue_kick(vq);
|
||||||
|
|
||||||
|
/* Wait fot completion */
|
||||||
|
|
||||||
|
nxsem_wait_uninterruptible(&cookie.sem);
|
||||||
|
return cookie.len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_rng_probe
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int virtio_rng_probe(FAR struct virtio_device *vdev)
|
||||||
|
{
|
||||||
|
FAR struct virtio_rng_priv_s *priv;
|
||||||
|
FAR const char *vqnames[1];
|
||||||
|
vq_callback callback[1];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
priv = kmm_zalloc(sizeof(*priv));
|
||||||
|
if (priv == NULL)
|
||||||
|
{
|
||||||
|
vrterr("No enough memory\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->vdev = vdev;
|
||||||
|
vdev->priv = priv;
|
||||||
|
|
||||||
|
/* Call openamp api to intialize the virtio deivce */
|
||||||
|
|
||||||
|
virtio_set_status(vdev, VIRTIO_CONFIG_STATUS_DRIVER);
|
||||||
|
virtio_set_features(vdev, 0);
|
||||||
|
virtio_set_status(vdev, VIRTIO_CONFIG_FEATURES_OK);
|
||||||
|
|
||||||
|
vqnames[0] = "virtio_rng_rx";
|
||||||
|
callback[0] = virtio_rng_done;
|
||||||
|
ret = virtio_create_virtqueues(vdev, 0, 1, vqnames, callback);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
vrterr("virtio_device_create_virtqueue failed, ret=%d\n", ret);
|
||||||
|
goto err_with_priv;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtio_set_status(vdev, VIRTIO_CONFIG_STATUS_DRIVER_OK);
|
||||||
|
virtqueue_enable_cb(vdev->vrings_info[0].vq);
|
||||||
|
|
||||||
|
/* Register NuttX driver */
|
||||||
|
|
||||||
|
if (g_virtio_rng_idx == 0)
|
||||||
|
{
|
||||||
|
strlcpy(priv->name, "/dev/random", NAME_MAX);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(priv->name, NAME_MAX, "/dev/random%d", g_virtio_rng_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = register_driver(priv->name, &g_virtio_rng_ops, 0444, priv);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
vrterr("Register NuttX driver failed, ret=%d\n", ret);
|
||||||
|
goto err_with_virtqueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_virtio_rng_idx++;
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
err_with_virtqueue:
|
||||||
|
virtio_reset_device(vdev);
|
||||||
|
virtio_delete_virtqueues(vdev);
|
||||||
|
err_with_priv:
|
||||||
|
kmm_free(priv);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_rng_remove
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void virtio_rng_remove(FAR struct virtio_device *vdev)
|
||||||
|
{
|
||||||
|
FAR struct virtio_rng_priv_s *priv = vdev->priv;
|
||||||
|
|
||||||
|
unregister_driver(priv->name);
|
||||||
|
virtio_reset_device(vdev);
|
||||||
|
virtio_delete_virtqueues(vdev);
|
||||||
|
kmm_free(priv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: devrandom_register
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the RNG hardware and register the /dev/random driver.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEV_RANDOM
|
||||||
|
void weak_function devrandom_register(void)
|
||||||
|
{
|
||||||
|
/* Nothing, implement it here just avoid the compile error, the driver
|
||||||
|
* /dev/random will be registered in the virtio rng driver.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_register_rng_driver
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_register_rng_driver(void)
|
||||||
|
{
|
||||||
|
return virtio_register_driver(&g_virtio_rng_driver);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* arch/arm64/src/qemu/qemu_virtio.c
|
* drivers/virtio/virtio-rng.h
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@@ -18,23 +18,44 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __DRIVERS_VIRTIO_VIRTIO_RNG_H
|
||||||
|
#define __DRIVERS_VIRTIO_VIRTIO_RNG_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <syslog.h>
|
#ifdef CONFIG_DRIVERS_VIRTIO_RNG
|
||||||
#include <errno.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/virtio/virtio-mmio.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void arm64_netinitialize(void)
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
{
|
{
|
||||||
virtio_mmio_init();
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_register_rng_driver(void);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_DRIVERS_VIRTIO_RNG */
|
||||||
|
|
||||||
|
#endif /* __DRIVERS_VIRTIO_VIRTIO_RNG_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* arch/risc-v/src/qemu-rv/qemu_rv_virtio.c
|
* drivers/virtio/virtio-serial.h
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@@ -18,23 +18,44 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __DRIVERS_VIRTIO_VIRTIO_SERIAL_H
|
||||||
|
#define __DRIVERS_VIRTIO_VIRTIO_SERIAL_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <syslog.h>
|
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL
|
||||||
#include <errno.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/virtio/virtio-mmio.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void riscv_netinitialize(void)
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
{
|
{
|
||||||
virtio_mmio_init();
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_register_serial_driver(void);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_DRIVERS_VIRTIO_SERIAL */
|
||||||
|
|
||||||
|
#endif /* __DRIVERS_VIRTIO_VIRTIO_SERIAL_H */
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* drivers/virtio/virtio.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 <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/mutex.h>
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/virtio/virtio.h>
|
||||||
|
|
||||||
|
#include "virtio-blk.h"
|
||||||
|
#include "virtio-net.h"
|
||||||
|
#include "virtio-rng.h"
|
||||||
|
#include "virtio-serial.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct virtio_bus_s
|
||||||
|
{
|
||||||
|
mutex_t lock; /* Lock for the list */
|
||||||
|
struct list_node device; /* Wait match virtio device list */
|
||||||
|
struct list_node driver; /* Virtio driver list */
|
||||||
|
};
|
||||||
|
struct virtio_device_item_s
|
||||||
|
{
|
||||||
|
struct list_node node; /* list node */
|
||||||
|
struct virtio_device *device; /* Pointer to the virtio device */
|
||||||
|
struct virtio_driver *driver; /* Pointer to the virtio driver that
|
||||||
|
* matched with current virtio device
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static struct virtio_bus_s g_virtio_bus =
|
||||||
|
{
|
||||||
|
NXMUTEX_INITIALIZER,
|
||||||
|
LIST_INITIAL_VALUE(g_virtio_bus.device),
|
||||||
|
LIST_INITIAL_VALUE(g_virtio_bus.driver),
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_alloc_buf
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR void *virtio_alloc_buf(FAR struct virtio_device *vdev,
|
||||||
|
size_t size, size_t align)
|
||||||
|
{
|
||||||
|
if (align == 0)
|
||||||
|
{
|
||||||
|
return kmm_malloc(size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return kmm_memalign(align, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_zalloc_buf
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR void *virtio_zalloc_buf(FAR struct virtio_device *vdev,
|
||||||
|
size_t size, size_t align)
|
||||||
|
{
|
||||||
|
FAR void *ptr = virtio_alloc_buf(vdev, size, align);
|
||||||
|
if (ptr != NULL)
|
||||||
|
{
|
||||||
|
memset(ptr, 0, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_mmio_free_buf
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void virtio_free_buf(FAR struct virtio_device *vdev, FAR void *buf)
|
||||||
|
{
|
||||||
|
kmm_free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_register_drivers
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void virtio_register_drivers(void)
|
||||||
|
{
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_BLK
|
||||||
|
ret = virtio_register_blk_driver();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
vrterr("virtio_register_blk_driver failed, ret=%d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_NET
|
||||||
|
ret = virtio_register_net_driver();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
vrterr("virtio_register_net_driver failed, ret=%d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_RNG
|
||||||
|
ret = virtio_register_rng_driver();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
vrterr("virtio_register_rng_driver failed, ret=%d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL
|
||||||
|
ret = virtio_register_serial_driver();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
vrterr("virtio_serial_driver_init failed, ret=%d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
UNUSED(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_register_driver
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_register_driver(FAR struct virtio_driver *driver)
|
||||||
|
{
|
||||||
|
FAR struct list_node *node;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
DEBUGASSERT(driver != NULL && driver->probe != NULL &&
|
||||||
|
driver->remove != NULL);
|
||||||
|
|
||||||
|
ret = nxmutex_lock(&g_virtio_bus.lock);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add the driver to the virtio_bus driver list */
|
||||||
|
|
||||||
|
list_add_tail(&g_virtio_bus.driver, &driver->node);
|
||||||
|
|
||||||
|
/* Match all the devices has registered in the virtio_bus */
|
||||||
|
|
||||||
|
list_for_every(&g_virtio_bus.device, node)
|
||||||
|
{
|
||||||
|
FAR struct virtio_device_item_s *item =
|
||||||
|
container_of(node, struct virtio_device_item_s, node);
|
||||||
|
FAR struct virtio_device *device = item->device;
|
||||||
|
if (driver->device == device->id.device)
|
||||||
|
{
|
||||||
|
/* If found the device in the device list, call driver probe,
|
||||||
|
* if probe success, assign item->driver to indicate the device
|
||||||
|
* matched.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (driver->probe(device) >= 0)
|
||||||
|
{
|
||||||
|
item->driver = driver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nxmutex_unlock(&g_virtio_bus.lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_unregister_driver
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_unregister_driver(FAR struct virtio_driver *driver)
|
||||||
|
{
|
||||||
|
FAR struct list_node *node;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
DEBUGASSERT(driver != NULL);
|
||||||
|
|
||||||
|
ret = nxmutex_lock(&g_virtio_bus.lock);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find all the devices matched with driver in device list */
|
||||||
|
|
||||||
|
list_for_every(&g_virtio_bus.device, node)
|
||||||
|
{
|
||||||
|
FAR struct virtio_device_item_s *item =
|
||||||
|
container_of(node, struct virtio_device_item_s, node);
|
||||||
|
if (item->driver == driver)
|
||||||
|
{
|
||||||
|
/* 1. Call driver remove function;
|
||||||
|
* 2. Mark item->driver NULL to indicate the device unmatched;
|
||||||
|
*/
|
||||||
|
|
||||||
|
driver->remove(item->device);
|
||||||
|
item->driver = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove the driver from the driver list */
|
||||||
|
|
||||||
|
list_delete(&driver->node);
|
||||||
|
|
||||||
|
nxmutex_unlock(&g_virtio_bus.lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_register_device
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_register_device(FAR struct virtio_device *device)
|
||||||
|
{
|
||||||
|
FAR struct virtio_device_item_s *item;
|
||||||
|
FAR struct list_node *node;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
item = kmm_zalloc(sizeof(*item));
|
||||||
|
if (item == NULL)
|
||||||
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
item->device = device;
|
||||||
|
|
||||||
|
ret = nxmutex_lock(&g_virtio_bus.lock);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
kmm_free(item);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add the device to the virtio_bus device list */
|
||||||
|
|
||||||
|
list_add_tail(&g_virtio_bus.device, &item->node);
|
||||||
|
|
||||||
|
/* Match the driver has registered in the virtio_bus */
|
||||||
|
|
||||||
|
list_for_every(&g_virtio_bus.driver, node)
|
||||||
|
{
|
||||||
|
FAR struct virtio_driver *driver =
|
||||||
|
container_of(node, struct virtio_driver, node);
|
||||||
|
if (driver->device == device->id.device)
|
||||||
|
{
|
||||||
|
/* If found the driver in the driver list, call driver probe,
|
||||||
|
* if probe success, assign item->driver to indicate the device
|
||||||
|
* matched.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (driver->probe(device) >= 0)
|
||||||
|
{
|
||||||
|
item->driver = driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nxmutex_unlock(&g_virtio_bus.lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: virtio_unregister_device
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int virtio_unregister_device(FAR struct virtio_device *device)
|
||||||
|
{
|
||||||
|
FAR struct list_node *node;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = nxmutex_lock(&g_virtio_bus.lock);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find the device in device list */
|
||||||
|
|
||||||
|
list_for_every(&g_virtio_bus.device, node)
|
||||||
|
{
|
||||||
|
FAR struct virtio_device_item_s *item =
|
||||||
|
container_of(node, struct virtio_device_item_s, node);
|
||||||
|
if (item->device == device)
|
||||||
|
{
|
||||||
|
/* Call driver remove and mark item->driver NULL to indicate
|
||||||
|
* the device unmatched
|
||||||
|
*/
|
||||||
|
|
||||||
|
item->driver->remove(device);
|
||||||
|
item->driver = NULL;
|
||||||
|
|
||||||
|
/* Remove the device from the device list and free memory */
|
||||||
|
|
||||||
|
list_delete(&item->node);
|
||||||
|
kmm_free(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nxmutex_unlock(&g_virtio_bus.lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -25,119 +25,18 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <arch/spinlock.h>
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO_MMIO
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* See virtio-v1.1-csprd01.pdf */
|
|
||||||
|
|
||||||
#define VIRTIO_MAGIC 0x74726976
|
|
||||||
#define VIRTIO_VERSION 0x2 /* NOTE: Legacy devices used 0x1 */
|
|
||||||
|
|
||||||
#define VIRTIO_DEV_NET 0x1
|
|
||||||
#define VIRTIO_DEV_BLK 0x2
|
|
||||||
|
|
||||||
#define VIRTIO_STATUS_ACKNOWLEDGE (1)
|
|
||||||
#define VIRTIO_STATUS_DRIVER (2)
|
|
||||||
#define VIRTIO_STATUS_DRIVER_OK (4)
|
|
||||||
#define VIRTIO_STATUS_FEATURES_OK (8)
|
|
||||||
|
|
||||||
#define VIRTQ_DESC_F_NEXT 1 /* marks a buffer as continuing */
|
|
||||||
#define VIRTQ_DESC_F_WRITE 2 /* marks a buffer as device write-only */
|
|
||||||
|
|
||||||
#define virtio_mb() SP_DMB()
|
|
||||||
|
|
||||||
#define virtio_getreg32(a) (FAR *(volatile FAR uint32_t *)(a))
|
|
||||||
#define virtio_putreg32(v,a) (FAR *(volatile FAR uint32_t *)(a) = (v))
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Type Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Table 4.1 MMIO Device Register Layout */
|
|
||||||
|
|
||||||
struct virtio_mmio_regs
|
|
||||||
{
|
|
||||||
uint32_t magic_value; /* offset:0x000 */
|
|
||||||
uint32_t version; /* offset:0x004 */
|
|
||||||
uint32_t device_id; /* offset:0x008 */
|
|
||||||
uint32_t vendor_id; /* offset:0x00c */
|
|
||||||
uint32_t device_features; /* offset:0x010 */
|
|
||||||
uint32_t device_features_sel; /* offset:0x014 */
|
|
||||||
uint32_t _reserved0[2];
|
|
||||||
uint32_t driver_features; /* offset:0x020 */
|
|
||||||
uint32_t driver_features_sel; /* offset:0x024 */
|
|
||||||
uint32_t _reserved1[2];
|
|
||||||
uint32_t queue_sel; /* offset:0x030 */
|
|
||||||
uint32_t queue_num_max; /* offset:0x034 */
|
|
||||||
uint32_t queue_num; /* offset:0x038 */
|
|
||||||
uint32_t _reserved2[2];
|
|
||||||
uint32_t queue_ready; /* offset:0x044 */
|
|
||||||
uint32_t _reserved3[2];
|
|
||||||
uint32_t queue_notify; /* offset:0x050 */
|
|
||||||
uint32_t _reserved4[3];
|
|
||||||
uint32_t interrupt_status; /* offset:0x060 */
|
|
||||||
uint32_t interrupt_ack; /* offset:0x064 */
|
|
||||||
uint32_t _reserved5[2];
|
|
||||||
uint32_t status; /* offset:0x070 */
|
|
||||||
uint32_t _reserved6[3];
|
|
||||||
uint32_t queue_desc_low; /* offset:0x080 */
|
|
||||||
uint32_t queue_desc_high; /* offset:0x084 */
|
|
||||||
uint32_t _reserved7[2];
|
|
||||||
uint32_t queue_avail_low; /* offset:0x090 */
|
|
||||||
uint32_t queue_avail_high; /* offset:0x094 */
|
|
||||||
uint32_t _reserved8[2];
|
|
||||||
uint32_t queue_used_low; /* offset:0x0a0 */
|
|
||||||
uint32_t queue_used_high; /* offset:0x0a4 */
|
|
||||||
uint32_t _reserved9[21];
|
|
||||||
uint32_t config_generation; /* offset:0x0fc */
|
|
||||||
uint32_t config[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct virtqueue_desc
|
|
||||||
{
|
|
||||||
uint64_t addr;
|
|
||||||
uint32_t len;
|
|
||||||
uint16_t flags;
|
|
||||||
uint16_t next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct virtqueue_avail
|
|
||||||
{
|
|
||||||
uint16_t flags;
|
|
||||||
uint16_t idx;
|
|
||||||
uint16_t ring[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct virtqueue_used_elem
|
|
||||||
{
|
|
||||||
uint32_t id;
|
|
||||||
uint32_t len;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct virtqueue_used
|
|
||||||
{
|
|
||||||
uint16_t flags;
|
|
||||||
uint16_t idx;
|
|
||||||
struct virtqueue_used_elem ring[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct virtqueue
|
|
||||||
{
|
|
||||||
uint32_t len;
|
|
||||||
uint16_t last_used_idx;
|
|
||||||
|
|
||||||
FAR struct virtqueue_desc *desc;
|
|
||||||
FAR struct virtqueue_avail *avail;
|
|
||||||
FAR struct virtqueue_used *used;
|
|
||||||
FAR uint16_t *avail_event;
|
|
||||||
FAR void **desc_virt;
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -150,21 +49,20 @@ extern "C"
|
|||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FAR struct virtqueue *virtq_create(uint32_t len);
|
/****************************************************************************
|
||||||
|
* Name: virtio_register_mmio_device
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register virtio mmio device to the virtio bus
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
uint32_t virtq_alloc_desc(FAR struct virtqueue *virtq,
|
int virtio_register_mmio_device(FAR void *regs, int irq);
|
||||||
uint32_t id,
|
|
||||||
FAR void *addr);
|
|
||||||
|
|
||||||
void virtq_add_to_mmio_device(FAR struct virtio_mmio_regs *regs,
|
|
||||||
FAR struct virtqueue *virtq,
|
|
||||||
uint32_t queue_sel);
|
|
||||||
|
|
||||||
void virtio_mmio_init(void);
|
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_DRIVERS_VIRTIO_MMIO */
|
||||||
#endif /* __INCLUDE_NUTTX_VIRTIO_VIRTIO_MMIO_H */
|
#endif /* __INCLUDE_NUTTX_VIRTIO_VIRTIO_MMIO_H */
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/virtio/virtio.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 __INCLUDE_NUTTX_VIRTIO_VIRTIO_H
|
||||||
|
#define __INCLUDE_NUTTX_VIRTIO_VIRTIO_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <nuttx/compiler.h>
|
||||||
|
#include <nuttx/list.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_DRIVERS_VIRTIO
|
||||||
|
|
||||||
|
#include <openamp/open_amp.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define virtio_read_config_member(vdev, structname, member, ptr) \
|
||||||
|
virtio_read_config((vdev), offsetof(structname, member), \
|
||||||
|
(ptr), sizeof(*(ptr)));
|
||||||
|
|
||||||
|
#define virtio_write_config_member(vdev, structname, member, ptr) \
|
||||||
|
virtio_write_config((vdev), offsetof(structname, member), \
|
||||||
|
(ptr), sizeof(*(ptr)));
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Type Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct virtio_driver
|
||||||
|
{
|
||||||
|
struct list_node node;
|
||||||
|
uint32_t device; /* device id */
|
||||||
|
CODE int (*probe)(FAR struct virtio_device *vdev);
|
||||||
|
CODE void (*remove)(FAR struct virtio_device *vdev);
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Driver and device register/unregister function */
|
||||||
|
|
||||||
|
int virtio_register_driver(FAR struct virtio_driver *driver);
|
||||||
|
int virtio_register_device(FAR struct virtio_device *device);
|
||||||
|
|
||||||
|
int virtio_unregister_driver(FAR struct virtio_driver *driver);
|
||||||
|
int virtio_unregister_device(FAR struct virtio_device *device);
|
||||||
|
|
||||||
|
/* Virtio alloc/free buffer API
|
||||||
|
* NOTE:
|
||||||
|
* For now, these three apis are implemented in NuttX, and direclty mapping
|
||||||
|
* to kmm_memalgin/kmm_free, so it's only compatible with virtio mmio
|
||||||
|
* transport for now. After the virtio remoteproc transport layer completed,
|
||||||
|
* these three apis should be moved to OpenAmp, and different transport layer
|
||||||
|
* provide different implementation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
FAR void *virtio_alloc_buf(FAR struct virtio_device *vdev,
|
||||||
|
size_t size, size_t align);
|
||||||
|
FAR void *virtio_zalloc_buf(FAR struct virtio_device *vdev,
|
||||||
|
size_t size, size_t align);
|
||||||
|
void virtio_free_buf(FAR struct virtio_device *vdev, FAR void *buf);
|
||||||
|
|
||||||
|
/* Virtio driver initailied function, called in NuttX driver_intialize() */
|
||||||
|
|
||||||
|
void virtio_register_drivers(void);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_DRIVERS_VIRTIO */
|
||||||
|
|
||||||
|
#endif /* __INCLUDE_NUTTX_VIRTIO_VIRTIO_H */
|
||||||
Reference in New Issue
Block a user