2 * Manage XenBus device path and I/O handles
4 * Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
6 * SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/UefiBootServicesTableLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/DevicePathLib.h>
17 #include <Library/XenIoMmioLib.h>
19 #include <Protocol/XenIo.h>
20 #include <Guid/XenBusRootDevice.h>
24 VENDOR_DEVICE_PATH Vendor
;
25 EFI_PHYSICAL_ADDRESS GrantTableAddress
;
26 EFI_DEVICE_PATH_PROTOCOL End
;
27 } XENBUS_ROOT_DEVICE_PATH
;
30 STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate
= {
35 { sizeof (VENDOR_DEVICE_PATH
) + sizeof (EFI_PHYSICAL_ADDRESS
), 0 }
37 XENBUS_ROOT_DEVICE_GUID
,
42 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
43 { sizeof (EFI_DEVICE_PATH_PROTOCOL
), 0 }
49 Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on
50 the handle pointed to by @Handle, or on a new handle if it points to
53 @param Handle Pointer to the handle to install the protocols
54 on, may point to a NULL handle.
56 @param GrantTableAddress The address of the Xen grant table
58 @retval EFI_SUCCESS Protocols were installed successfully
60 @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required
61 by the XenIo MMIO and device path protocols
63 @return Status code returned by the boot service
64 InstallMultipleProtocolInterfaces ()
69 IN OUT EFI_HANDLE
*Handle
,
70 IN EFI_PHYSICAL_ADDRESS GrantTableAddress
74 XENIO_PROTOCOL
*XenIo
;
75 XENBUS_ROOT_DEVICE_PATH
*XenBusDevicePath
;
78 ASSERT (Handle
!= NULL
);
82 XenIo
= AllocateZeroPool (sizeof *XenIo
);
84 return EFI_OUT_OF_RESOURCES
;
87 XenIo
->GrantTableAddress
= GrantTableAddress
;
89 XenBusDevicePath
= AllocateCopyPool (
90 sizeof *XenBusDevicePath
,
91 &mXenBusRootDevicePathTemplate
93 if (!XenBusDevicePath
) {
94 DEBUG ((DEBUG_ERROR
, "%a: Out of memory\n", __FUNCTION__
));
95 Status
= EFI_OUT_OF_RESOURCES
;
99 XenBusDevicePath
->GrantTableAddress
= GrantTableAddress
;
101 Status
= gBS
->InstallMultipleProtocolInterfaces (
103 &gEfiDevicePathProtocolGuid
,
109 if (!EFI_ERROR (Status
)) {
116 "%a: Failed to install the EFI_DEVICE_PATH and "
117 "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",
123 FreePool (XenBusDevicePath
);
132 Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols
134 @param Handle Handle onto which the protocols have been installed
135 earlier by XenIoMmioInstall ()
137 @retval EFI_SUCCESS Protocols were uninstalled successfully
139 @return Status code returned by the boot service
140 UninstallMultipleProtocolInterfaces ()
150 VOID
*XenBusDevicePath
;
152 XenBusDevicePath
= NULL
;
155 &gEfiDevicePathProtocolGuid
,
159 EFI_OPEN_PROTOCOL_GET_PROTOCOL
169 EFI_OPEN_PROTOCOL_GET_PROTOCOL
172 Status
= gBS
->UninstallMultipleProtocolInterfaces (
174 &gEfiDevicePathProtocolGuid
,
181 if (EFI_ERROR (Status
)) {
185 FreePool (XenBusDevicePath
);