From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.69.1617287767736639463 for ; Thu, 01 Apr 2021 07:36:07 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: chandni.cherukuri@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F68015BE; Thu, 1 Apr 2021 07:36:07 -0700 (PDT) Received: from usa.arm.com (a074744.blr.arm.com [10.162.17.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A550A3F719; Thu, 1 Apr 2021 07:36:05 -0700 (PDT) From: "chandni cherukuri" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Chandni Cherukuri Subject: [edk2-platforms][PATCH V2 7/7] Platform/ARM/Morello: Add virtio net support Date: Thu, 1 Apr 2021 20:05:37 +0530 Message-Id: <20210401143537.4799-8-chandni.cherukuri@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210401143537.4799-1-chandni.cherukuri@arm.com> References: <20210401143537.4799-1-chandni.cherukuri@arm.com> This patch registers a virtio net device for Morello FVP platform. Signed-off-by: Chandni Cherukuri --- 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 35e02be5d5ab..e579fb917348 100644 --- a/Platform/ARM/Morello/MorelloPlatformFvp.dsc +++ b/Platform/ARM/Morello/MorelloPlatformFvp.dsc @@ -47,6 +47,7 @@ [PcdsFeatureFlag.common] gArmMorelloTokenSpaceGuid.PcdVirtioBlkSupported|TRUE + gArmMorelloTokenSpaceGuid.PcdVirtioNetSupported|TRUE [PcdsFixedAtBuild.common] # Virtio Disk @@ -54,8 +55,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 7414e0666ce0..1566d3142fc3 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