From f8d51a3599dd88e3146861a4dcd95b07b962e87f Mon Sep 17 00:00:00 2001 From: Jianguo Sun Date: Sat, 18 May 2024 10:42:02 +0800 Subject: [PATCH 1/3] Virtio: Add CONFIG_VIRTIO_MMIO_POLL_RESET Add CONFIG_VIRTIO_MMIO_POLL_RESET to as an option to enable synchronous reset for the MMIO based transport for virtio. Change-Id: Ide5f69aa083bee2189f4d417d95f2c8fdf61bcdb Signed-off-by: Jianguo Sun --- drivers/virtio/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index f6a22e108f94..04c437545308 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -194,4 +194,13 @@ config VIRTIO_DMA_SHARED_BUFFER This option adds a flavor of dma buffers that are backed by virtio resources. +config VIRTIO_MMIO_POLL_RESET + bool "Virti-mmio device synchronous reset support" + depends on VIRTIO_MMIO + help + Say y here to enable synchronous reset for the MMIO transport based + virtio device. After writing 0 to device_status, the driver must + wait for a read of device_status to return 0 before reinitializing + the device. + endif # VIRTIO_MENU From 4cb39792d0dacfca16ba5331014b0553e084be4c Mon Sep 17 00:00:00 2001 From: Jianguo Sun Date: Wed, 3 Apr 2024 19:59:13 +0800 Subject: [PATCH 2/3] virtio: Add polling virtio-mmio device reset completion We write 0 to device_status to initiate reset of a virtio-mmio device. The reset operation itself may or may not be completed by the time write instruction completes. Add polling device_status to return 0 to ensure reset completion before reinitializing the device. Change-Id: If15d11d090dfd0d4972ad35f49af03e076872413 Signed-off-by: Jianguo Sun Signed-off-by: Sreenad Menon --- drivers/virtio/virtio_mmio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index d73bf8083bc3..f4ae1c28f46c 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -70,6 +70,7 @@ #include #include #include +#include #ifdef CONFIG_GH_VIRTIO_DEBUG #define CREATE_TRACE_POINTS @@ -292,6 +293,13 @@ static void vm_reset(struct virtio_device *vdev) /* 0 status means a reset. */ writel(0, vm_dev->base + VIRTIO_MMIO_STATUS); +#ifdef CONFIG_VIRTIO_MMIO_POLL_RESET + /* After writing 0 to device_status, the driver MUST wait for a read of + * device_status to return 0 before reinitializing the device. + */ + while (readl(vm_dev->base + VIRTIO_MMIO_STATUS)) + usleep_range(1000, 1100); +#endif } From 46ea21adf80156e0f4b0745845cc37c6c4c742fc Mon Sep 17 00:00:00 2001 From: Jianguo Sun Date: Fri, 17 May 2024 14:54:40 +0800 Subject: [PATCH 3/3] configs: Enable CONFIG_VIRTIO_MMIO_POLL_RESET for autoghgvm With UEFI as GVM's bootloader enabled, we need support virtio-mmio device reset, which needs ensure the device reset is completed before reinitializing the device. Change-Id: I3bafe954eb09805d1baa8ff9e1bb9f35b60c34ee Signed-off-by: Jianguo Sun --- arch/arm64/configs/vendor/autoghgvm.config | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/vendor/autoghgvm.config b/arch/arm64/configs/vendor/autoghgvm.config index 00af7ef7aa11..c97c423993fc 100644 --- a/arch/arm64/configs/vendor/autoghgvm.config +++ b/arch/arm64/configs/vendor/autoghgvm.config @@ -75,6 +75,7 @@ CONFIG_VHOST_MENU=y CONFIG_VIRTIO_BLK=m CONFIG_VIRTIO_INPUT=m CONFIG_VIRTIO_MMIO=m +CONFIG_VIRTIO_MMIO_POLL_RESET=y CONFIG_VIRTIO_MMIO_SWIOTLB=y CONFIG_VIRTIO_NET=m CONFIG_VIRT_DRIVERS=y