Commit Graph

75 Commits

Author SHA1 Message Date
yangsong8 8c13b8df1d syslog: convert \n to \r\n in syslog framework layer
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2024-10-17 02:29:51 +08:00
Bowen Wang 89c49c53a7 virtio-mmio/pci: add alloc_buf/free_buf for mmio and pci transport layer
And remove the virtio_alloc/free_buf implementation in virtio.c, because
these two apis has been moved to the OpenAMP

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-09 23:32:58 +08:00
wangyongrong 0b1f45d600 rptun: rptun implements notify_wait through rvdev->notify_wait_cb
notify_wait has been remove in remoteproc ops and virtio_dispatch and
has been moved to the struct rpmsg_virtio_device in new OpenAMP,
so change the rptun too,

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-09 23:32:58 +08:00
Yongrong Wang 1b24139020 virtio-pci/mmio: Features change to 64 bit in all virtio_dispatch and fix compile warning
virtio/virtio-pci-legacy.c:399:48: warning: passing argument 2 of ‘pci_bus_write_io_dword’ makes integer from pointer without a cast [-Wint-con>
  399 |   pci_write_io_dword(vpdev->dev, vpdev->ioaddr + VIRTIO_PCI_GUEST_FEATURES,
      |                                                ^
      |                                                |
      |                                                void *
/home/wyr/work/code/project/vela/nuttx/include/nuttx/pci/pci.h:559:65: note: expected ‘uintptr_t’ {aka ‘long unsigned int’} but argument is of >
  559 | int pci_bus_write_io_dword(FAR struct pci_bus_s *bus, uintptr_t where,
      |                                                       ~~~~~~~~~~^~~~~

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-09 23:32:58 +08:00
wangyongrong 5aeb644bc5 virtio: adapt to the new OpenAMP
Sync all the virtio api usage to sync with new OpenAMP

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-09 23:32:58 +08:00
Yongrong Wang 26ac220810 virtio devices: update virtqueue operate buffer add lock API
1. Use the virtqueue_xxx_lock() api;
2. Add spinlock for some virtio and vhost drivers that do not
   use spinlock to protect the virtqueues;

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
Bowen Wang fd9efb600c virtio/virtio-net: add spinlock for the virtqueue
virtqueues are used in irq and thread, so add spinlock to protect
them.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-06 08:37:53 +08:00
Bowen Wang c0edb0f402 virtio/virtio-net: calculate the correct buffer number
Avoid exceed the virtqueue length limit when adding buffer to the
virtqueue.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong 377f184019 virtio-rpmb.c: add spin lock for virtqueue add/get buffer
Virtqueeus are used in both user thread and interrupt, so add spinlock
to proetect them.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong e8a8052a8a virtio-serial.c: add spin lock for virtqueue add/get buffer
Virtqueeus are used in both user thread and interrupt, so add spinlock
to proetect them.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong 67ceba3cd6 virtio-blk.c: add spin lock to fix get/add virtqueue buffer at the same time err
Virtqueues are used in both user thread and interrupt, so add spinlock to protect
them.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong 58aca26b1b virtio-blk.c: change virtio blk req and resp to local variables
So we can remove the mutex lock to improve the virtio-block driver
performance

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong 735dc6e2bf virtio-rng.c: add spin lock to fix get/add virtqueue buffer at the same time err
the virtqueue should be protected by the spinlock, because the virtqueues are used
both in worker and interrupt.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong f6f151a8e1 virtio-blk: add VIRTIO_BLK_F_BLK_SIZE feature
Support configure the virtio block device block size to other value
(default value is 512)

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong ef58c71582 virtio-blk: add VIRTIO_BLK_F_RO feature
When feature VIRTIO_BLK_F_RO is set, virtio-blk only support read
operation.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
wangyongrong 7ec167392c virtio-blk: add VIRTIO_BLK_F_FLUSH features
Should support the flush command only when virtio device support
feature VIRTIO_BLK_F_FLUSH

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-06 08:37:53 +08:00
Bowen Wang 7eda1700c2 virtio/virtio-rng: make virtio-rng work for remoteproc transport layer
For remoteproc transport layer, the virtio drivers can not use the malloced
memory from the default system heap to communicate with the virtio devices,
the buffers placed in virtqueue should be in the share memory region
(mallcoed virtio_alloc_buf()).

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-06 08:37:53 +08:00
Bowen Wang 106040df6c virtio-serial: support custom the virtio serial device name
By setting config CONFIG_DRIVERS_VIRTIO_SERIAL_NAME to "ttyXX0;ttyXX1;..."
to customize the virtio serial name.

For example:
If CONFIG_DRIVERS_VIRTIO_SERIAL_NAME="ttyBT;ttyTest0;ttyTest1",
virtio-serial will register three uart devices with names:
"/dev/ttyBT", "/dev/ttyTest0", "/dev/ttyTest1" to the VFS.

nsh> ls dev
/dev:
 console
 null
 telnet
 ttyBT
 ttyS0
 ttyTest0
 ttyTest1
 zero

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-06 08:37:53 +08:00
Bowen Wang 84d2aae63b virtio-mmio: add secure virtio mmio device register api
In secure state, call virtio_register_mmio_device_secure() to
register the secure virtio mmio device;
In non-secure state, call virtio_register_mmio_device() to
register the non-secure virtio mmio device;
Board should ensure not mixed use the secure and non-seucre mmio
device.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-06 08:37:53 +08:00
shipei 551b9b1626 audio:add getlatency for virtio snd driver
add getlatency in virtio snd driver

Signed-off-by: shipei <shipei@xiaomi.com>
2024-10-06 08:37:53 +08:00
Xiang Xiao 347c2dae29 driver/virtio: Check driver isn't NULL before calling remove
since the device mayn't bind to the driver yet

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-05 12:05:13 -03:00
Bowen Wang 51d6e8f49e virtio/vhost: assign the virtio/vhost_drvier to device->priv before probe
So the driver can get the driver pointer by vdev/hdev->priv,
and later vdev/hdev->priv can be used to store other data such as the
virtio/vhost drivers' private data.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-03 17:37:40 +08:00
p-szafonimateusz 8723aa7125 drivers: fix gcc14 errors for virtio
fix gcc14 errors for virtio

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-09-16 11:25:40 -03:00
wangyongrong 639843ade3 virtio-pci: fix set virtio device features error
Should assgin back the feature to the vdev->features

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-15 02:22:16 +08:00
wangyongrong b0d70b76cb virtio-pci.c: polling mode support
1. Some platforms do not support interrupt mode (PCI_MSI/MSIX),
so add polling mode support, so these platforms can also use virtio-pci;
2. In some cases, we do not want to use the interrupt for virtio driver
to avoid time jitter, so add the polling mode support;
3. If CONFIG_DRIVERS_VIRTIO_PCI_POLLING_PERIOD <= 0, interrupt mode.
   if CONFIG_DRIVERS_VIRTIO_PCI_POLLING_PERIOD > 0, polling mode.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-15 02:22:16 +08:00
wangyongrong ee6bc2e7df virtio-pci: extract common part of virtio pci modern and leagcy
Extrace common part of virtio pci modern and legacy to virtio-pci to
reduce the duplicated code.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-15 02:22:16 +08:00
wangyongrong d54d07b62c virtio-pci: add virtio pci legacy support
Follow the virtio spec, support the virtio pci Legacy

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
Signed-off-by: andi <andi6@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-15 02:22:16 +08:00
wangyongrong decfc9ad65 virtio-pci-modern: replace pci_read/write_mmio_xxx with pci_read/write_io_xxx
Use IO api to access the io region

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-15 02:22:16 +08:00
wangyongrong 877e462990 vitrio-pci.c: add virtio-pci transport support for Nuttx
1. only support pci modern device;
2. need the pci controller support MSI/MSI-X;
It has been verified based on virtio-rng and virtio-net.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-15 02:22:16 +08:00
Bowen Wang 0fbfcf4caf virtio-blk: support called read/write in interrupt
Coredump need call the block read/write ops in interrupt
Not consider the ops called in thread and intterupt simultaneously.
Only used for coredump now.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-10 11:35:35 +08:00
Petro Karashchenko d252b6229f nuttx: use sizeof instead of define or number in snprintf
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
liqinhui e04aa9ac51 wifisim: Support the setting of the number of simulated WiFi interfaces.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-08-21 13:25:53 +08:00
Zhe Weng 648c52fc4b drivers/virtio-net: Use `reclaim` in `ops` to finish TODO
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-08-21 01:39:34 +08:00
liuhongchao fb37391ea6 drivers/input: enable touch/kbd/mouse for virtio input
Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2024-08-19 20:08:50 +08:00
liuhongchao 7495014b17 drivers/input: Add goldfish events driver
Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2024-08-18 10:54:22 -03:00
Zhe Weng 504af7a1fa drivers/virtio-net: Support VIRTIO_F_ANY_LAYOUT
According to Virtual I/O Spec:
When using legacy interfaces, transitional drivers which have not negotiated VIRTIO_F_ANY_LAYOUT MUST use a single descriptor for the struct virtio_net_hdr on both transmit and receive, with the network data in the following descriptors.

https://docs.oasis-open.org/virtio/virtio/v1.2/cs01/virtio-v1.2-cs01.html#x1-2280006 (Section 5.1.6.6)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-08-16 21:15:31 +08:00
Yanfeng Liu 3fecf46097 virtio/serial: initial CONSOLE support
This adds DRIVERS_VIRTIO_SERIAL_CONSOLE config and related logic to
virtio serial so that it can be used as console device. Note that
due to its dependency on OS services, this console is available late
so it is not proper for debugging too early booting issues.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-07-26 12:01:29 +08:00
Yanfeng Liu 1eb96c3446 virtio/gpu: minor revision on virtio_gpu_send_cmd()
This revises comments and completes reclaiming buf param.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-04-01 00:27:16 +08:00
Yanfeng Liu 715f8de1bb virtio/cmake: sync with makefile system
This adds drivers like virtio-gpu etc to cmake system to be in line
with the makefile system.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-03-31 08:04:47 -03:00
chao an 6d50274ebe nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications

In file included from libuv/src/unix/internal.h:25,
                 from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
   57 | #define container_of(ptr, type, member) \
      |
In file included from nuttx/include/nuttx/list.h:47,
                 from nuttx/include/nuttx/tls.h:40,
                 from nuttx/include/nuttx/sched.h:48,
                 from nuttx/include/nuttx/arch.h:87,
                 from nuttx/include/nuttx/userspace.h:35,
                 from nuttx/include/nuttx/mm/mm.h:30,
                 from nuttx/include/nuttx/kmalloc.h:34,
                 from nuttx/include/nuttx/lib/lib.h:31,
                 from nuttx/include/stdio.h:35,
                 from apps/system/libuv/libuv/include/uv.h:59,
                 from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
   48 | #define container_of(ptr, type, member) \
      |

Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 19:44:54 +08:00
Bowen Wang ca22e95577 virtio: move metal_init to the virtio_register_drivers()
Only call metal_init() once for virtio framework

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-02-18 04:09:44 -08:00
Bowen Wang e9a146bbfc virtio-mmio: use byte to byte in read/write config when length != 1,2,4,8
The length of some config elements are not equal to 1,2,4,8, so we can't
assert in virtio_mmio_config_read/write() direclty when length != 1,2,4,8

For example, in virtio_net_config from virtio spec v1.2
struct virtio_net_config {
	u8 mac[6];
	le16 status;
	le16 max_virtqueue_pairs;
	le16 mtu;
	le32 speed;
	u8 duplex;
	u8 rss_max_key_size;
	le16 rss_max_indirection_table_length;
	le32 supported_hash_types;
};

The mac length is 6 and not equal to 1,2,4,8

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-06 04:23:05 -08:00
Bowen Wang a8d21c3876 virtio-mmio: avoid output error log when not found mmio device
Not found the mmio device is a normal case, so should not print the
error log.
This commit change the log level to info when not found the mmio
device.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-04 20:28:21 -08:00
Bowen Wang 409431b2ad virtio-mmio: ack the interrupt as soon as possible
Follow the linux does, avoid miss mmio interrupt

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-04 20:05:29 -08:00
Xiang Xiao b9bd88d9d3 rptun: Select OPENMAP under RPTUN
to simplify the IPC related configuration

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-12-28 11:08:57 +08:00
liqinhui 41a3c8a5e3 virtio-net:Fix the compile error.
CC:  virtio/virtio-net.c virtio/virtio-net.c: In function 'virtio_net_set_macaddr':
virtio/virtio-net.c:595:17: error: invalid operands to binary % (have 'struct net_driver_s *' and 'int')
  595 |             dev % 256
      |                 ^
make[1]: *** [Makefile:107: virtio-net.o] Error 1
make: *** [tools/LibTargets.mk:101: drivers/libdrivers.a] Error 2
make: *** Waiting for unfinished jobs....

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-21 01:21:01 -08:00
liqinhui 98e3615b60 net/netdev: Modify the logic for setting the IFF_RUNNING status of interfaces.
Refer to the logic of the `netif_carrier_on` on linux.
https://github.com/torvalds/linux/blob/master/net/sched/sch_generic.c#L575

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-15 18:24:23 -08:00
liqinhui 6a8c638d57 qemu/wifi: Add the virtual wifi function on the emulator.
-The qemu wifi fucntion only supports the STA mode and the following
 operations:
 wapi mode wlan0 2
 wapi scan wlan0
 wapi psk wlan0 password 3
 wapi essid wlan0 wifi_name 1
 wapi show wlan0
 wapi disconnect wlan0
-Eanble the virtual wifi function with the MACRO `CONFIG_DRIVERS_WIFI_SIM`.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-14 20:22:12 -08:00
jianglianfang 5f631e2b2b virtio-gpu: convert virito-gpu fb_register to virtio_gpu_fb_register
Signed-off-by: jianglianfang <jianglianfang@xiaomi.com>
2023-12-13 09:05:17 -08:00
liqinhui 73ceb049af virtio-net: Support for setting MAC addresses of the virtio-net interfaces.
Refers to https://docs.oasis-open.org/virtio/virtio/v1.2/cs01/virtio-v1.2-cs01.html#x1-2230004
A driver SHOULD negotiate VIRTIO_NET_F_MAC if the device offers it.
If the driver negotiates the VIRTIO_NET_F_MAC feature, the driver MUST
set the physical address of the NIC to mac. Otherwise, it SHOULD use a
locally-administered MAC address.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-13 05:00:59 -08:00