#\r
# Platform Driver\r
#\r
- ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf\r
+ ArmVirtPkg/VirtioFdtDxe/VirtioFdtDxe.inf\r
ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf\r
ArmVirtPkg/HighMemDxe/HighMemDxe.inf\r
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf\r
\r
INF MdeModulePkg/Core/Dxe/DxeMain.inf\r
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
- INF ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf\r
+ INF ArmVirtPkg/VirtioFdtDxe/VirtioFdtDxe.inf\r
INF ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf\r
INF ArmVirtPkg/HighMemDxe/HighMemDxe.inf\r
\r
#\r
# Platform Driver\r
#\r
- ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf\r
+ ArmVirtPkg/VirtioFdtDxe/VirtioFdtDxe.inf\r
ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf\r
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf\r
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf\r
\r
INF MdeModulePkg/Core/Dxe/DxeMain.inf\r
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
- INF ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf\r
+ INF ArmVirtPkg/VirtioFdtDxe/VirtioFdtDxe.inf\r
INF ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf\r
\r
#\r
+++ /dev/null
-/** @file\r
-* Device tree enumeration DXE driver for ARM Virtual Machines\r
-*\r
-* Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
-*\r
-* This program and the accompanying materials are\r
-* licensed and made available under the terms and conditions of the BSD License\r
-* which accompanies this distribution. The full text of the license may be found at\r
-* http://opensource.org/licenses/bsd-license.php\r
-*\r
-* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-*\r
-**/\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/VirtioMmioDeviceLib.h>\r
-#include <Library/DevicePathLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/DxeServicesLib.h>\r
-#include <Library/HobLib.h>\r
-#include <libfdt.h>\r
-#include <Library/XenIoMmioLib.h>\r
-\r
-#include <Guid/VirtioMmioTransport.h>\r
-#include <Guid/FdtHob.h>\r
-\r
-#pragma pack (1)\r
-typedef struct {\r
- VENDOR_DEVICE_PATH Vendor;\r
- UINT64 PhysBase;\r
- EFI_DEVICE_PATH_PROTOCOL End;\r
-} VIRTIO_TRANSPORT_DEVICE_PATH;\r
-#pragma pack ()\r
-\r
-typedef enum {\r
- PropertyTypeUnknown,\r
- PropertyTypeVirtio,\r
- PropertyTypeXen,\r
-} PROPERTY_TYPE;\r
-\r
-typedef struct {\r
- PROPERTY_TYPE Type;\r
- CHAR8 Compatible[32];\r
-} PROPERTY;\r
-\r
-STATIC CONST PROPERTY CompatibleProperties[] = {\r
- { PropertyTypeVirtio, "virtio,mmio" },\r
- { PropertyTypeXen, "xen,xen" },\r
- { PropertyTypeUnknown, "" }\r
-};\r
-\r
-STATIC\r
-PROPERTY_TYPE\r
-GetTypeFromNode (\r
- IN CONST CHAR8 *NodeType,\r
- IN UINTN Size\r
- )\r
-{\r
- CONST CHAR8 *Compatible;\r
- CONST PROPERTY *CompatibleProperty;\r
-\r
- //\r
- // A 'compatible' node may contain a sequence of NULL terminated\r
- // compatible strings so check each one\r
- //\r
- for (Compatible = NodeType; Compatible < NodeType + Size && *Compatible;\r
- Compatible += 1 + AsciiStrLen (Compatible)) {\r
- for (CompatibleProperty = CompatibleProperties; CompatibleProperty->Compatible[0]; CompatibleProperty++) {\r
- if (AsciiStrCmp (CompatibleProperty->Compatible, Compatible) == 0) {\r
- return CompatibleProperty->Type;\r
- }\r
- }\r
- }\r
- return PropertyTypeUnknown;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeVirtFdtDxe (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- VOID *Hob;\r
- VOID *DeviceTreeBase;\r
- INT32 Node, Prev;\r
- EFI_STATUS Status;\r
- CONST CHAR8 *Type;\r
- INT32 Len;\r
- PROPERTY_TYPE PropType;\r
- CONST VOID *RegProp;\r
- VIRTIO_TRANSPORT_DEVICE_PATH *DevicePath;\r
- EFI_HANDLE Handle;\r
- UINT64 RegBase;\r
-\r
- Hob = GetFirstGuidHob(&gFdtHobGuid);\r
- if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {\r
- return EFI_NOT_FOUND;\r
- }\r
- DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);\r
-\r
- if (fdt_check_header (DeviceTreeBase) != 0) {\r
- DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__, DeviceTreeBase));\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, DeviceTreeBase));\r
-\r
- //\r
- // Now enumerate the nodes and install peripherals that we are interested in,\r
- // i.e., GIC, RTC and virtio MMIO nodes\r
- //\r
- for (Prev = 0;; Prev = Node) {\r
- Node = fdt_next_node (DeviceTreeBase, Prev, NULL);\r
- if (Node < 0) {\r
- break;\r
- }\r
-\r
- Type = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);\r
- if (Type == NULL) {\r
- continue;\r
- }\r
-\r
- PropType = GetTypeFromNode (Type, Len);\r
- if (PropType == PropertyTypeUnknown) {\r
- continue;\r
- }\r
-\r
- //\r
- // Get the 'reg' property of this node. For now, we will assume\r
- // 8 byte quantities for base and size, respectively.\r
- // TODO use #cells root properties instead\r
- //\r
- RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);\r
- ASSERT (RegProp != NULL);\r
-\r
- switch (PropType) {\r
- case PropertyTypeVirtio:\r
- ASSERT (Len == 16);\r
- //\r
- // Create a unique device path for this transport on the fly\r
- //\r
- RegBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);\r
- DevicePath = (VIRTIO_TRANSPORT_DEVICE_PATH *)CreateDeviceNode (\r
- HARDWARE_DEVICE_PATH,\r
- HW_VENDOR_DP,\r
- sizeof (VIRTIO_TRANSPORT_DEVICE_PATH));\r
- if (DevicePath == NULL) {\r
- DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));\r
- break;\r
- }\r
-\r
- CopyMem (&DevicePath->Vendor.Guid, &gVirtioMmioTransportGuid,\r
- sizeof (EFI_GUID));\r
- DevicePath->PhysBase = RegBase;\r
- SetDevicePathNodeLength (&DevicePath->Vendor,\r
- sizeof (*DevicePath) - sizeof (DevicePath->End));\r
- SetDevicePathEndNode (&DevicePath->End);\r
-\r
- Handle = NULL;\r
- Status = gBS->InstallProtocolInterface (&Handle,\r
- &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,\r
- DevicePath);\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH "\r
- "protocol on a new handle (Status == %r)\n",\r
- __FUNCTION__, Status));\r
- FreePool (DevicePath);\r
- break;\r
- }\r
-\r
- Status = VirtioMmioInstallDevice (RegBase, Handle);\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "%a: Failed to install VirtIO transport @ 0x%Lx "\r
- "on handle %p (Status == %r)\n", __FUNCTION__, RegBase,\r
- Handle, Status));\r
-\r
- Status = gBS->UninstallProtocolInterface (Handle,\r
- &gEfiDevicePathProtocolGuid, DevicePath);\r
- ASSERT_EFI_ERROR (Status);\r
- FreePool (DevicePath);\r
- }\r
- break;\r
-\r
- case PropertyTypeXen:\r
- ASSERT (Len == 16);\r
-\r
- //\r
- // Retrieve the reg base from this node and wire it up to the\r
- // MMIO flavor of the XenBus root device I/O protocol\r
- //\r
- RegBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);\r
- Handle = NULL;\r
- Status = XenIoMmioInstall (&Handle, RegBase);\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "%a: XenIoMmioInstall () failed on a new handle "\r
- "(Status == %r)\n", __FUNCTION__, Status));\r
- break;\r
- }\r
-\r
- DEBUG ((EFI_D_INFO, "Found Xen node with Grant table @ 0x%Lx\n", RegBase));\r
-\r
- break;\r
-\r
- default:\r
- break;\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-## @file\r
-# Device tree enumeration DXE driver for ARM Virtual Machines\r
-#\r
-# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
-#\r
-# This program and the accompanying materials are\r
-# licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = VirtFdtDxe\r
- FILE_GUID = 9AD7DCB4-E6EC-472E-96BF-81C219A3F77E\r
- MODULE_TYPE = DXE_DRIVER\r
- VERSION_STRING = 1.0\r
-\r
- ENTRY_POINT = InitializeVirtFdtDxe\r
-\r
-[Sources]\r
- VirtFdtDxe.c\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
- ArmPkg/ArmPkg.dec\r
- ArmPlatformPkg/ArmPlatformPkg.dec\r
- ArmVirtPkg/ArmVirtPkg.dec\r
- EmbeddedPkg/EmbeddedPkg.dec\r
- OvmfPkg/OvmfPkg.dec\r
-\r
-[LibraryClasses]\r
- BaseLib\r
- PcdLib\r
- UefiDriverEntryPoint\r
- DxeServicesLib\r
- FdtLib\r
- VirtioMmioDeviceLib\r
- HobLib\r
- XenIoMmioLib\r
-\r
-[Guids]\r
- gVirtioMmioTransportGuid\r
- gFdtHobGuid\r
-\r
-[Protocols]\r
- gEfiDevicePathProtocolGuid\r
-\r
-[Depex]\r
- TRUE\r
--- /dev/null
+/** @file\r
+* Virtio FDT client protocol driver for virtio,mmio DT node\r
+*\r
+* Copyright (c) 2014 - 2016, Linaro Ltd. All rights reserved.<BR>\r
+*\r
+* This program and the accompanying materials are\r
+* licensed and made available under the terms and conditions of the BSD License\r
+* which accompanies this distribution. The full text of the license may be found at\r
+* http://opensource.org/licenses/bsd-license.php\r
+*\r
+* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/VirtioMmioDeviceLib.h>\r
+\r
+#include <Guid/VirtioMmioTransport.h>\r
+\r
+#include <Protocol/FdtClient.h>\r
+\r
+#pragma pack (1)\r
+typedef struct {\r
+ VENDOR_DEVICE_PATH Vendor;\r
+ UINT64 PhysBase;\r
+ EFI_DEVICE_PATH_PROTOCOL End;\r
+} VIRTIO_TRANSPORT_DEVICE_PATH;\r
+#pragma pack ()\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeVirtioFdtDxe (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status, FindNodeStatus;\r
+ FDT_CLIENT_PROTOCOL *FdtClient;\r
+ INT32 Node;\r
+ CONST UINT64 *Reg;\r
+ UINT32 RegSize;\r
+ VIRTIO_TRANSPORT_DEVICE_PATH *DevicePath;\r
+ EFI_HANDLE Handle;\r
+ UINT64 RegBase;\r
+\r
+ Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
+ (VOID **)&FdtClient);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient,\r
+ "virtio,mmio", &Node);\r
+ !EFI_ERROR (FindNodeStatus);\r
+ FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient,\r
+ "virtio,mmio", Node, &Node)) {\r
+\r
+ Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r
+ (CONST VOID **)&Reg, &RegSize);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n",\r
+ __FUNCTION__, Status));\r
+ continue;\r
+ }\r
+\r
+ ASSERT (RegSize == 16);\r
+\r
+ //\r
+ // Create a unique device path for this transport on the fly\r
+ //\r
+ RegBase = SwapBytes64 (*Reg);\r
+ DevicePath = (VIRTIO_TRANSPORT_DEVICE_PATH *)CreateDeviceNode (\r
+ HARDWARE_DEVICE_PATH,\r
+ HW_VENDOR_DP,\r
+ sizeof (VIRTIO_TRANSPORT_DEVICE_PATH));\r
+ if (DevicePath == NULL) {\r
+ DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));\r
+ continue;\r
+ }\r
+\r
+ CopyGuid (&DevicePath->Vendor.Guid, &gVirtioMmioTransportGuid);\r
+ DevicePath->PhysBase = RegBase;\r
+ SetDevicePathNodeLength (&DevicePath->Vendor,\r
+ sizeof (*DevicePath) - sizeof (DevicePath->End));\r
+ SetDevicePathEndNode (&DevicePath->End);\r
+\r
+ Handle = NULL;\r
+ Status = gBS->InstallProtocolInterface (&Handle,\r
+ &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,\r
+ DevicePath);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH "\r
+ "protocol on a new handle (Status == %r)\n",\r
+ __FUNCTION__, Status));\r
+ FreePool (DevicePath);\r
+ continue;\r
+ }\r
+\r
+ Status = VirtioMmioInstallDevice (RegBase, Handle);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "%a: Failed to install VirtIO transport @ 0x%Lx "\r
+ "on handle %p (Status == %r)\n", __FUNCTION__, RegBase,\r
+ Handle, Status));\r
+\r
+ Status = gBS->UninstallProtocolInterface (Handle,\r
+ &gEfiDevicePathProtocolGuid, DevicePath);\r
+ ASSERT_EFI_ERROR (Status);\r
+ FreePool (DevicePath);\r
+ continue;\r
+ }\r
+ }\r
+\r
+ if (EFI_ERROR (FindNodeStatus) && FindNodeStatus != EFI_NOT_FOUND) {\r
+ DEBUG ((EFI_D_ERROR, "%a: Error occurred while iterating DT nodes "\r
+ "(FindNodeStatus == %r)\n", __FUNCTION__, FindNodeStatus));\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+## @file\r
+# Virtio FDT client protocol driver for virtio,mmio DT node\r
+#\r
+# Copyright (c) 2014 - 2016, Linaro Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are\r
+# licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = VirtioFdtDxe\r
+ FILE_GUID = 0049858F-8CA7-4CCD-918B-D952CBF32975\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+\r
+ ENTRY_POINT = InitializeVirtioFdtDxe\r
+\r
+[Sources]\r
+ VirtioFdtDxe.c\r
+\r
+[Packages]\r
+ ArmVirtPkg/ArmVirtPkg.dec\r
+ MdePkg/MdePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ DevicePathLib\r
+ MemoryAllocationLib\r
+ UefiBootServicesTableLib\r
+ UefiDriverEntryPoint\r
+ VirtioMmioDeviceLib\r
+\r
+[Guids]\r
+ gVirtioMmioTransportGuid\r
+\r
+[Protocols]\r
+ gEfiDevicePathProtocolGuid ## PRODUCES\r
+ gFdtClientProtocolGuid ## CONSUMES\r
+\r
+[Depex]\r
+ gFdtClientProtocolGuid\r