From fcb9e4ae4670e13bc0023e658303fe72d4dfd4ae Mon Sep 17 00:00:00 2001
From: Frazer Carsley <frazer.carsley@arm.com>
Date: Mon, 19 Jan 2026 15:00:29 +0000
Subject: [PATCH] corstone1000: Enable virtio-net support

Add virtio-net support in Corstone1000 FVP

Signed-off-by: Emekcan Aras <emekcan.aras@arm.com>
Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Upstream-Status: Pending [Not submitted to upstream yet]
---
 arch/arm/dts/corstone1000-fvp.dts        |  6 ++++
 board/armltd/corstone1000/corstone1000.c | 42 ++++++++++++++++++++----
 configs/corstone1000_defconfig           |  2 ++
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/corstone1000-fvp.dts b/arch/arm/dts/corstone1000-fvp.dts
index 3076fb9f344..cd8a132271e 100644
--- a/arch/arm/dts/corstone1000-fvp.dts
+++ b/arch/arm/dts/corstone1000-fvp.dts
@@ -21,6 +21,12 @@
 		reg-io-width = <2>;
 	};
 
+	virtio: virtio-net@40400000 {
+		compatible = "virtio,mmio";
+		reg = <0x40400000 0x10000>;
+		interrupts = <145>;
+	};
+
 	vmmc_v3_3d: fixed_v3_3d {
 		compatible = "regulator-fixed";
 		regulator-name = "vmmc_supply";
diff --git a/board/armltd/corstone1000/corstone1000.c b/board/armltd/corstone1000/corstone1000.c
index 9189640ef75..39fd10ed653 100644
--- a/board/armltd/corstone1000/corstone1000.c
+++ b/board/armltd/corstone1000/corstone1000.c
@@ -20,6 +20,7 @@
 #include <dm/platform_data/serial_pl01x.h>
 #include <asm/armv8/mmu.h>
 #include <asm/global_data.h>
+#include <generated/dt.h>
 #include <linux/bitfield.h>
 
 #define CORSTONE1000_KERNEL_PARTS 2
@@ -201,13 +202,21 @@ static struct mm_region corstone1000_mem_map[] = {
 			PTE_BLOCK_NON_SHARE |
 			PTE_BLOCK_PXN | PTE_BLOCK_UXN
 	}, {
-		/* ethernet */
+		/* virtio-net */
+		.virt = 0x40400000UL,
+			.phys = 0x40400000UL,
+			.size = 0x00100000UL,
+			.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+				PTE_BLOCK_NON_SHARE |
+				PTE_BLOCK_PXN | PTE_BLOCK_UXN
+	}, {
+		/* Ethernet */
 		.virt = 0x40100000UL,
-		.phys = 0x40100000UL,
-		.size = 0x00100000UL,
-		.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
-			PTE_BLOCK_NON_SHARE |
-			PTE_BLOCK_PXN | PTE_BLOCK_UXN
+			.phys = 0x40100000UL,
+			.size = 0x00100000UL,
+			.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+				PTE_BLOCK_NON_SHARE |
+				PTE_BLOCK_PXN | PTE_BLOCK_UXN
 	}, {
 		/* MMC0 */
 		.virt = 0x40300000UL,
@@ -367,3 +376,24 @@ efi_status_t fwu_notify_exit_boot_services(void)
 out:
 	return efi_ret;
 }
+
+int board_late_init(void)
+{
+	struct udevice *virtio_bus = NULL, *virtio_child = NULL;
+	const char *cmp_dtb = DEVICE_TREE;
+	int ret;
+
+	if (!strcmp(cmp_dtb, "corstone1000-fvp")) {
+		ret = uclass_first_device_err(UCLASS_VIRTIO, &virtio_bus);
+		if (!virtio_bus) {
+			log_err("Cannot find virtio device, err (%d)\n", ret);
+			return ret;
+		}
+		while (virtio_bus) {
+			device_foreach_child_probe(virtio_child, virtio_bus);
+			uclass_next_device(&virtio_bus);
+		}
+	}
+
+	return 0;
+}
diff --git a/configs/corstone1000_defconfig b/configs/corstone1000_defconfig
index 00c3bb5f557..450d69762ab 100644
--- a/configs/corstone1000_defconfig
+++ b/configs/corstone1000_defconfig
@@ -78,6 +78,8 @@ CONFIG_TEE=y
 CONFIG_OPTEE=y
 CONFIG_USB=y
 CONFIG_USB_ISP1760=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_VIRTIO_NET=y
 # CONFIG_RANDOM_UUID is not set
 CONFIG_ERRNO_STR=y
 # CONFIG_HEXDUMP is not set
