From 8710e08f9e0889b8ce142ca51ad3f707009c64a6 Mon Sep 17 00:00:00 2001 From: Chandni Cherukuri Date: Mon, 19 Apr 2021 11:10:43 +0530 Subject: Platform/ARM/Morello: Add virtio net support This patch registers a virtio net device for Morello FVP platform. Signed-off-by: Chandni Cherukuri Reviewed-by: Sami Mujawar --- .../Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf | 2 + .../Morello/Drivers/PlatformDxe/VirtioDevices.c | 58 ++++++++++++++++++++++ .../Include/Guid/MorelloVirtioDevicesFormSet.h | 3 ++ Platform/ARM/Morello/MorelloPlatform.dec | 6 +++ Platform/ARM/Morello/MorelloPlatformFvp.dsc | 7 +++ Platform/ARM/Morello/MorelloPlatformFvp.fdf | 6 +++ 6 files changed, 82 insertions(+) diff --git a/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf index e4882343..c36c62f0 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/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c index 72d02b2b..365e5fdd 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__)); + } + } + } } diff --git a/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h b/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h index 77adffbf..b8bd40c1 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/MorelloPlatform.dec b/Platform/ARM/Morello/MorelloPlatform.dec index 9a674593..6f5c1c1b 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 ad316ccf..ee612296 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 dc3eccd2..851ee315 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 -- cgit v1.2.3