2 * Manage XenBus device path and I/O handles
4 * Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
6 * This program and the accompanying materials are
7 * licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/DevicePathLib.h>
23 #include <Library/XenIoMmioLib.h>
25 #include <Protocol/XenIo.h>
26 #include <Guid/XenBusRootDevice.h>
30 VENDOR_DEVICE_PATH Vendor
;
31 EFI_PHYSICAL_ADDRESS GrantTableAddress
;
32 EFI_DEVICE_PATH_PROTOCOL End
;
33 } XENBUS_ROOT_DEVICE_PATH
;
36 STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate
= {
41 { sizeof (VENDOR_DEVICE_PATH
) + sizeof (EFI_PHYSICAL_ADDRESS
), 0 }
43 XENBUS_ROOT_DEVICE_GUID
,
48 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
49 { sizeof (EFI_DEVICE_PATH_PROTOCOL
), 0 }
55 Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on
56 the handle pointed to by @Handle, or on a new handle if it points to
59 @param Handle Pointer to the handle to install the protocols
60 on, may point to a NULL handle.
62 @param GrantTableAddress The address of the Xen grant table
64 @retval EFI_SUCCESS Protocols were installed successfully
66 @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required
67 by the XenIo MMIO and device path protocols
69 @return Status code returned by the boot service
70 InstallMultipleProtocolInterfaces ()
75 IN OUT EFI_HANDLE
*Handle
,
76 IN EFI_PHYSICAL_ADDRESS GrantTableAddress
80 XENIO_PROTOCOL
*XenIo
;
81 XENBUS_ROOT_DEVICE_PATH
*XenBusDevicePath
;
84 ASSERT (Handle
!= NULL
);
88 XenIo
= AllocateZeroPool (sizeof *XenIo
);
90 return EFI_OUT_OF_RESOURCES
;
92 XenIo
->GrantTableAddress
= GrantTableAddress
;
94 XenBusDevicePath
= AllocateCopyPool (sizeof *XenBusDevicePath
,
95 &mXenBusRootDevicePathTemplate
);
96 if (!XenBusDevicePath
) {
97 DEBUG ((EFI_D_ERROR
, "%a: Out of memory\n", __FUNCTION__
));
98 Status
= EFI_OUT_OF_RESOURCES
;
101 XenBusDevicePath
->GrantTableAddress
= GrantTableAddress
;
103 Status
= gBS
->InstallMultipleProtocolInterfaces (&OutHandle
,
104 &gEfiDevicePathProtocolGuid
, XenBusDevicePath
,
105 &gXenIoProtocolGuid
, XenIo
,
107 if (!EFI_ERROR (Status
)) {
112 DEBUG ((EFI_D_ERROR
, "%a: Failed to install the EFI_DEVICE_PATH and "
113 "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",
114 __FUNCTION__
, OutHandle
, Status
));
116 FreePool (XenBusDevicePath
);
125 Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols
127 @param Handle Handle onto which the protocols have been installed
128 earlier by XenIoMmioInstall ()
130 @retval EFI_SUCCESS Protocols were uninstalled successfully
132 @return Status code returned by the boot service
133 UninstallMultipleProtocolInterfaces ()
143 VOID
*XenBusDevicePath
;
145 XenBusDevicePath
= NULL
;
146 gBS
->OpenProtocol (Handle
, &gEfiDevicePathProtocolGuid
, &XenBusDevicePath
,
147 NULL
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
150 gBS
->OpenProtocol (Handle
, &gXenIoProtocolGuid
, &XenIo
,
151 NULL
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
153 Status
= gBS
->UninstallMultipleProtocolInterfaces (Handle
,
154 &gEfiDevicePathProtocolGuid
, XenBusDevicePath
,
155 &gXenIoProtocolGuid
, XenIo
,
158 if (EFI_ERROR (Status
)) {
162 FreePool (XenBusDevicePath
);