[edk2-platforms][PATCH V3 7/7] Platform/ARM/Morello: Add virtio net support


chandni cherukuri
 

This patch registers a virtio net device for Morello
FVP platform.

Signed-off-by: Chandni Cherukuri <chandni.cherukuri@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---
Platform/ARM/Morello/MorelloPlatform.dec | 6 ++
Platform/ARM/Morello/MorelloPlatformFvp.dsc | 7 +++
Platform/ARM/Morello/MorelloPlatformFvp.fdf | 6 ++
Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf | 2 +
Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h | 3 +
Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c | 58 ++++++++++++++++++++
6 files changed, 82 insertions(+)

diff --git a/Platform/ARM/Morello/MorelloPlatform.dec b/Platform/ARM/Morello/MorelloPlatform.dec
index 9a674593cb3c..6f5c1c1b59fc 100644
--- a/Platform/ARM/Morello/MorelloPlatform.dec
+++ b/Platform/ARM/Morello/MorelloPlatform.dec
@@ -55,6 +55,12 @@
gArmMorelloTokenSpaceGuid.PcdPciMmio64Translation|0x0|UINT64|0x00000017
gArmMorelloTokenSpaceGuid.PcdPciExpressBaseAddress|0x20000000|UINT64|0x00000018

+ # Virtio Net device
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetBaseAddress|0x00000000|UINT32|0x00000019
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetSize|0x00000000|UINT32|0x0000001A
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetInterrupt|0x00000000|UINT32|0x0000001B
+
[PcdsFeatureFlag.common]
gArmMorelloTokenSpaceGuid.PcdRamDiskSupported|FALSE|BOOLEAN|0x00000007
gArmMorelloTokenSpaceGuid.PcdVirtioBlkSupported|FALSE|BOOLEAN|0x00000008
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetSupported|FALSE|BOOLEAN|0x0000001C
diff --git a/Platform/ARM/Morello/MorelloPlatformFvp.dsc b/Platform/ARM/Morello/MorelloPlatformFvp.dsc
index ad316ccfb94f..ee612296a80e 100644
--- a/Platform/ARM/Morello/MorelloPlatformFvp.dsc
+++ b/Platform/ARM/Morello/MorelloPlatformFvp.dsc
@@ -50,6 +50,7 @@

[PcdsFeatureFlag.common]
gArmMorelloTokenSpaceGuid.PcdVirtioBlkSupported|TRUE
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetSupported|TRUE

[PcdsFixedAtBuild.common]
# Virtio Disk
@@ -57,8 +58,14 @@
gArmMorelloTokenSpaceGuid.PcdVirtioBlkSize|0x200
gArmMorelloTokenSpaceGuid.PcdVirtioBlkInterrupt|128

+ # Virtio Net
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetBaseAddress|0x1C180000
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetSize|0x200
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetInterrupt|134
+
[Components.common]
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+ OvmfPkg/VirtioNetDxe/VirtioNet.inf

# Platform driver
Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf
diff --git a/Platform/ARM/Morello/MorelloPlatformFvp.fdf b/Platform/ARM/Morello/MorelloPlatformFvp.fdf
index dc3eccd2f3ba..851ee3159b3d 100644
--- a/Platform/ARM/Morello/MorelloPlatformFvp.fdf
+++ b/Platform/ARM/Morello/MorelloPlatformFvp.fdf
@@ -120,6 +120,12 @@ READ_LOCK_STATUS = TRUE
# Virtio Block Device support
INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+ # Networking stack
+ !include NetworkPkg/Network.fdf.inc
+
+ # Virtio Net support
+ INF OvmfPkg/VirtioNetDxe/VirtioNet.inf
+
# FAT filesystem + GPT/MBR partitioning
INF FatPkg/EnhancedFatDxe/Fat.inf
INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
diff --git a/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf
index e4882343fc77..c36c62f05a39 100644
--- a/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf
+++ b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf
@@ -34,11 +34,13 @@
[FeaturePcd]
gArmMorelloTokenSpaceGuid.PcdRamDiskSupported
gArmMorelloTokenSpaceGuid.PcdVirtioBlkSupported
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetSupported

[FixedPcd]
gArmMorelloTokenSpaceGuid.PcdRamDiskBase
gArmMorelloTokenSpaceGuid.PcdRamDiskSize
gArmMorelloTokenSpaceGuid.PcdVirtioBlkBaseAddress
+ gArmMorelloTokenSpaceGuid.PcdVirtioNetBaseAddress

[Depex]
gEfiRamDiskProtocolGuid
diff --git a/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h b/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h
index 77adffbfd984..b8bd40c104a2 100644
--- a/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h
+++ b/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h
@@ -11,4 +11,7 @@
#define MORELLO_VIRTIO_BLOCK_GUID \
{ 0x2B6E62D0, 0x9346, 0x4E1A, { 0xAA, 0x1E, 0xCB, 0x01, 0xC3, 0x23, 0x4A, 0x00 } }

+#define MORELLO_VIRTIO_NET_GUID \
+ { 0x4B428575, 0xD09B, 0x45EE, { 0xAC, 0x91, 0xB1, 0x36, 0xBE, 0xD6, 0x70, 0x2B } }
+
#endif //MORELLO_VIRTIO_DEVICES_FORMSET_H_
diff --git a/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c
index 72d02b2b3bd2..365e5fdd7685 100644
--- a/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c
+++ b/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c
@@ -40,6 +40,29 @@ STATIC VIRTIO_DEVICE_PATH mVirtioBlockDevicePath =
}
};

+STATIC VIRTIO_DEVICE_PATH mVirtioNetDevicePath =
+{
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ {
+ (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
+ }
+ },
+ MORELLO_VIRTIO_NET_GUID,
+ },
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ sizeof (EFI_DEVICE_PATH_PROTOCOL),
+ 0
+ }
+ }
+};
+
/**
Initialize platform Virtio devices.

@@ -51,8 +74,10 @@ InitVirtioDevices (
{
EFI_STATUS Status;
EFI_HANDLE mVirtIoBlkController;
+ EFI_HANDLE mVirtIoNetController;

mVirtIoBlkController = NULL;
+ mVirtIoNetController = NULL;

// Install protocol interface for storage device
if (FeaturePcdGet (PcdVirtioBlkSupported)) {
@@ -87,4 +112,37 @@ InitVirtioDevices (
}
}
}
+
+ // Install protocol interface for network device
+ if (FeaturePcdGet (PcdVirtioNetSupported)) {
+
+ Status = gBS->InstallProtocolInterface (
+ &mVirtIoNetController,
+ &gEfiDevicePathProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mVirtioNetDevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to install EFI_DEVICE_PATH protocol "
+ "for Virtio Net (Status = %r)\n",
+ __FUNCTION__, Status));
+ } else {
+ // Declare the Virtio Net device
+ Status = VirtioMmioInstallDevice (
+ FixedPcdGet32 (PcdVirtioNetBaseAddress),
+ mVirtIoNetController
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Unable to find Virtio Block MMIO device "
+ "(Status == %r)\n", __FUNCTION__, Status));
+ gBS->UninstallProtocolInterface (
+ mVirtIoNetController,
+ &gEfiDevicePathProtocolGuid,
+ &mVirtioNetDevicePath
+ );
+ } else {
+ DEBUG ((DEBUG_INIT, "%a: Installed Virtio Net\n", __FUNCTION__));
+ }
+ }
+ }
}
--
2.17.1