]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtualizationPkg: add XenIoMmioLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 28 Feb 2015 20:34:16 +0000 (20:34 +0000)
committerlersek <lersek@Edk2>
Sat, 28 Feb 2015 20:34:16 +0000 (20:34 +0000)
This adds a XenIoMmioLib declaration and implementation that can
be invoked to install the XENIO_PROTOCOL and a corresponding
grant table address on a EFI handle.

Contributed-under: TianoCore Contribution Agreement 1.0
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16979 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/Include/Library/XenIoMmioLib.h [new file with mode: 0644]
OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c [new file with mode: 0644]
OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf [new file with mode: 0644]
OvmfPkg/OvmfPkg.dec

diff --git a/OvmfPkg/Include/Library/XenIoMmioLib.h b/OvmfPkg/Include/Library/XenIoMmioLib.h
new file mode 100644 (file)
index 0000000..3986c72
--- /dev/null
@@ -0,0 +1,64 @@
+/** @file\r
+*  Manage XenBus device path and I/O handles\r
+*\r
+*  Copyright (c) 2015, 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
+#ifndef _XENIO_MMIO_DEVICE_LIB_H_\r
+#define _XENIO_MMIO_DEVICE_LIB_H_\r
+\r
+/**\r
+\r
+  Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on\r
+  the handle pointed to by @Handle, or on a new handle if it points to\r
+  NULL\r
+\r
+  @param  Handle                Pointer to the handle to install the protocols\r
+                                on, may point to a NULL handle.\r
+\r
+  @param  GrantTableAddress     The address of the Xen grant table\r
+\r
+  @retval EFI_SUCCESS           Protocols were installed successfully\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  The function failed to allocate memory required\r
+                                by the XenIo MMIO and device path protocols\r
+\r
+  @return                       Status code returned by the boot service\r
+                                InstallMultipleProtocolInterfaces ()\r
+\r
+**/\r
+EFI_STATUS\r
+XenIoMmioInstall (\r
+  IN OUT   EFI_HANDLE              *Handle,\r
+  IN       EFI_PHYSICAL_ADDRESS    GrantTableAddress\r
+  );\r
+\r
+\r
+/**\r
+\r
+  Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols\r
+\r
+  @param  Handle          Handle onto which the protocols have been installed\r
+                          earlier by XenIoMmioInstall ()\r
+\r
+  @retval EFI_SUCCESS     Protocols were uninstalled successfully\r
+\r
+  @return                 Status code returned by the boot service\r
+                          UninstallMultipleProtocolInterfaces ()\r
+\r
+**/\r
+EFI_STATUS\r
+XenIoMmioUninstall (\r
+  IN       EFI_HANDLE              Handle\r
+  );\r
+\r
+#endif\r
diff --git a/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c b/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c
new file mode 100644 (file)
index 0000000..c710e85
--- /dev/null
@@ -0,0 +1,166 @@
+/** @file\r
+*  Manage XenBus device path and I/O handles\r
+*\r
+*  Copyright (c) 2015, 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/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/XenIoMmioLib.h>\r
+\r
+#include <Protocol/XenIo.h>\r
+#include <Guid/XenBusRootDevice.h>\r
+\r
+#pragma pack (1)\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH                  Vendor;\r
+  EFI_PHYSICAL_ADDRESS                GrantTableAddress;\r
+  EFI_DEVICE_PATH_PROTOCOL            End;\r
+} XENBUS_ROOT_DEVICE_PATH;\r
+#pragma pack ()\r
+\r
+STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = {\r
+  {\r
+    {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      { sizeof (VENDOR_DEVICE_PATH) + sizeof (EFI_PHYSICAL_ADDRESS), 0 }\r
+    },\r
+    XENBUS_ROOT_DEVICE_GUID,\r
+  },\r
+  0,\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
+  }\r
+};\r
+\r
+/**\r
+\r
+  Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on\r
+  the handle pointed to by @Handle, or on a new handle if it points to\r
+  NULL\r
+\r
+  @param  Handle                Pointer to the handle to install the protocols\r
+                                on, may point to a NULL handle.\r
+\r
+  @param  GrantTableAddress     The address of the Xen grant table\r
+\r
+  @retval EFI_SUCCESS           Protocols were installed successfully\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  The function failed to allocate memory required\r
+                                by the XenIo MMIO and device path protocols\r
+\r
+  @return                       Status code returned by the boot service\r
+                                InstallMultipleProtocolInterfaces ()\r
+\r
+**/\r
+EFI_STATUS\r
+XenIoMmioInstall (\r
+  IN OUT   EFI_HANDLE              *Handle,\r
+  IN       EFI_PHYSICAL_ADDRESS    GrantTableAddress\r
+  )\r
+{\r
+  EFI_STATUS                     Status;\r
+  XENIO_PROTOCOL                 *XenIo;\r
+  XENBUS_ROOT_DEVICE_PATH        *XenBusDevicePath;\r
+  EFI_HANDLE                     OutHandle;\r
+\r
+  ASSERT (Handle != NULL);\r
+\r
+  OutHandle = *Handle;\r
+\r
+  XenIo = AllocateZeroPool (sizeof *XenIo);\r
+  if (!XenIo) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  XenIo->GrantTableAddress = GrantTableAddress;\r
+\r
+  XenBusDevicePath = AllocateCopyPool (sizeof *XenBusDevicePath,\r
+                       &mXenBusRootDevicePathTemplate);\r
+  if (!XenBusDevicePath) {\r
+    DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto FreeXenIo;\r
+  }\r
+  XenBusDevicePath->GrantTableAddress = GrantTableAddress;\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (&OutHandle,\r
+                  &gEfiDevicePathProtocolGuid, XenBusDevicePath,\r
+                  &gXenIoProtocolGuid, XenIo,\r
+                  NULL);\r
+  if (!EFI_ERROR (Status)) {\r
+    *Handle = OutHandle;\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH and "\r
+    "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",\r
+    __FUNCTION__, OutHandle, Status));\r
+\r
+  FreePool (XenBusDevicePath);\r
+\r
+FreeXenIo:\r
+  FreePool (XenIo);\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+  Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols\r
+\r
+  @param  Handle          Handle onto which the protocols have been installed\r
+                          earlier by XenIoMmioInstall ()\r
+\r
+  @retval EFI_SUCCESS     Protocols were uninstalled successfully\r
+\r
+  @return                 Status code returned by the boot service\r
+                          UninstallMultipleProtocolInterfaces ()\r
+\r
+**/\r
+EFI_STATUS\r
+XenIoMmioUninstall (\r
+  IN       EFI_HANDLE              Handle\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  VOID          *XenIo;\r
+  VOID          *XenBusDevicePath;\r
+\r
+  XenBusDevicePath = NULL;\r
+  gBS->OpenProtocol (Handle, &gEfiDevicePathProtocolGuid, &XenBusDevicePath,\r
+         NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
+\r
+  XenIo = NULL;\r
+  gBS->OpenProtocol (Handle, &gXenIoProtocolGuid, &XenIo,\r
+         NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
+\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (Handle,\r
+                  &gEfiDevicePathProtocolGuid, XenBusDevicePath,\r
+                  &gXenIoProtocolGuid, XenIo,\r
+                  NULL);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  FreePool (XenBusDevicePath);\r
+  FreePool (XenIo);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf b/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf
new file mode 100644 (file)
index 0000000..16cc453
--- /dev/null
@@ -0,0 +1,39 @@
+## @file\r
+#  Manage XenBus device path and I/O handles\r
+#\r
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are 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
+#  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
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = XenIoMmioLib\r
+  FILE_GUID                      = de9bdc19-8434-47bb-be3c-7f28f2101fd0\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = XenIoMmioLib\r
+\r
+[Sources]\r
+  XenIoMmioLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+\r
+[Guids]\r
+  gXenBusRootDeviceGuid\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid\r
+  gXenIoProtocolGuid\r
index d61600225919ff6d7d36e910c1215a7419e0554e..4cb70dc98e797678338bc934b9c6dfd5fdc24a94 100644 (file)
   #\r
   XenHypercallLib|Include/Library/XenHypercallLib.h\r
 \r
+  ##  @libraryclass  Manage XenBus device path and I/O handles\r
+  #\r
+  XenIoMmioLib|Include/Library/XenIoMmioLib.h\r
+\r
 [Guids]\r
   gUefiOvmfPkgTokenSpaceGuid      = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}\r
   gEfiXenInfoGuid                 = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}\r