+/** @file\r
+\r
+ Driver for the XenIo protocol\r
+\r
+ This driver simply allocate space for the grant tables.\r
+\r
+ Copyright (c) 2019, Citrix Systems, Inc.\r
+\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/XenIoMmioLib.h>\r
+#include <Library/XenPlatformLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeXenIoPvhDxe (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ VOID *Allocation;\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE XenIoHandle;\r
+\r
+ Allocation = NULL;\r
+ XenIoHandle = NULL;\r
+\r
+ if (!XenPvhDetected ()) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ Allocation = AllocateReservedPages (FixedPcdGet32 (PcdXenGrantFrames));\r
+ if (Allocation == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Error;\r
+ }\r
+\r
+ Status = XenIoMmioInstall (&XenIoHandle, (UINTN) Allocation);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+\r
+Error:\r
+ if (Allocation != NULL) {\r
+ FreePages (Allocation, FixedPcdGet32 (PcdXenGrantFrames));\r
+ }\r
+ return Status;\r
+}\r