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
;
86 XenIo
->GrantTableAddress
= GrantTableAddress
;
88 XenBusDevicePath
= AllocateCopyPool (sizeof *XenBusDevicePath
,
89 &mXenBusRootDevicePathTemplate
);
90 if (!XenBusDevicePath
) {
91 DEBUG ((EFI_D_ERROR
, "%a: Out of memory\n", __FUNCTION__
));
92 Status
= EFI_OUT_OF_RESOURCES
;
95 XenBusDevicePath
->GrantTableAddress
= GrantTableAddress
;
97 Status
= gBS
->InstallMultipleProtocolInterfaces (&OutHandle
,
98 &gEfiDevicePathProtocolGuid
, XenBusDevicePath
,
99 &gXenIoProtocolGuid
, XenIo
,
101 if (!EFI_ERROR (Status
)) {
106 DEBUG ((EFI_D_ERROR
, "%a: Failed to install the EFI_DEVICE_PATH and "
107 "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",
108 __FUNCTION__
, OutHandle
, Status
));
110 FreePool (XenBusDevicePath
);
119 Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols
121 @param Handle Handle onto which the protocols have been installed
122 earlier by XenIoMmioInstall ()
124 @retval EFI_SUCCESS Protocols were uninstalled successfully
126 @return Status code returned by the boot service
127 UninstallMultipleProtocolInterfaces ()
137 VOID
*XenBusDevicePath
;
139 XenBusDevicePath
= NULL
;
140 gBS
->OpenProtocol (Handle
, &gEfiDevicePathProtocolGuid
, &XenBusDevicePath
,
141 NULL
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
144 gBS
->OpenProtocol (Handle
, &gXenIoProtocolGuid
, &XenIo
,
145 NULL
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
147 Status
= gBS
->UninstallMultipleProtocolInterfaces (Handle
,
148 &gEfiDevicePathProtocolGuid
, XenBusDevicePath
,
149 &gXenIoProtocolGuid
, XenIo
,
152 if (EFI_ERROR (Status
)) {
156 FreePool (XenBusDevicePath
);