]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c
OvmfPkg/SmmCpuFeaturesLib: SEV: encrypt+free pages of init. save state map
[mirror_edk2.git] / OvmfPkg / Library / XenIoMmioLib / XenIoMmioLib.c
CommitLineData
0169352e
AB
1/** @file\r
2* Manage XenBus device path and I/O handles\r
3*\r
4* Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
5*\r
6* This program and the accompanying materials are\r
7* licensed and made available under the terms and conditions of the BSD License\r
8* which accompanies this distribution. The full text of the license may be found at\r
9* http://opensource.org/licenses/bsd-license.php\r
10*\r
11* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13*\r
14**/\r
15\r
16#include <Library/BaseLib.h>\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/UefiLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/DevicePathLib.h>\r
23#include <Library/XenIoMmioLib.h>\r
24\r
25#include <Protocol/XenIo.h>\r
26#include <Guid/XenBusRootDevice.h>\r
27\r
28#pragma pack (1)\r
29typedef struct {\r
30 VENDOR_DEVICE_PATH Vendor;\r
31 EFI_PHYSICAL_ADDRESS GrantTableAddress;\r
32 EFI_DEVICE_PATH_PROTOCOL End;\r
33} XENBUS_ROOT_DEVICE_PATH;\r
34#pragma pack ()\r
35\r
36STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = {\r
37 {\r
38 {\r
39 HARDWARE_DEVICE_PATH,\r
40 HW_VENDOR_DP,\r
41 { sizeof (VENDOR_DEVICE_PATH) + sizeof (EFI_PHYSICAL_ADDRESS), 0 }\r
42 },\r
43 XENBUS_ROOT_DEVICE_GUID,\r
44 },\r
45 0,\r
46 {\r
47 END_DEVICE_PATH_TYPE,\r
48 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
49 { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
50 }\r
51};\r
52\r
53/**\r
54\r
55 Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on\r
56 the handle pointed to by @Handle, or on a new handle if it points to\r
57 NULL\r
58\r
59 @param Handle Pointer to the handle to install the protocols\r
60 on, may point to a NULL handle.\r
61\r
62 @param GrantTableAddress The address of the Xen grant table\r
63\r
64 @retval EFI_SUCCESS Protocols were installed successfully\r
65\r
66 @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required\r
67 by the XenIo MMIO and device path protocols\r
68\r
69 @return Status code returned by the boot service\r
70 InstallMultipleProtocolInterfaces ()\r
71\r
72**/\r
73EFI_STATUS\r
74XenIoMmioInstall (\r
75 IN OUT EFI_HANDLE *Handle,\r
76 IN EFI_PHYSICAL_ADDRESS GrantTableAddress\r
77 )\r
78{\r
79 EFI_STATUS Status;\r
80 XENIO_PROTOCOL *XenIo;\r
81 XENBUS_ROOT_DEVICE_PATH *XenBusDevicePath;\r
82 EFI_HANDLE OutHandle;\r
83\r
84 ASSERT (Handle != NULL);\r
85\r
86 OutHandle = *Handle;\r
87\r
88 XenIo = AllocateZeroPool (sizeof *XenIo);\r
89 if (!XenIo) {\r
90 return EFI_OUT_OF_RESOURCES;\r
91 }\r
92 XenIo->GrantTableAddress = GrantTableAddress;\r
93\r
94 XenBusDevicePath = AllocateCopyPool (sizeof *XenBusDevicePath,\r
95 &mXenBusRootDevicePathTemplate);\r
96 if (!XenBusDevicePath) {\r
97 DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));\r
98 Status = EFI_OUT_OF_RESOURCES;\r
99 goto FreeXenIo;\r
100 }\r
101 XenBusDevicePath->GrantTableAddress = GrantTableAddress;\r
102\r
103 Status = gBS->InstallMultipleProtocolInterfaces (&OutHandle,\r
104 &gEfiDevicePathProtocolGuid, XenBusDevicePath,\r
105 &gXenIoProtocolGuid, XenIo,\r
106 NULL);\r
107 if (!EFI_ERROR (Status)) {\r
108 *Handle = OutHandle;\r
109 return EFI_SUCCESS;\r
110 }\r
111 \r
112 DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH and "\r
113 "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",\r
114 __FUNCTION__, OutHandle, Status));\r
115\r
116 FreePool (XenBusDevicePath);\r
117\r
118FreeXenIo:\r
119 FreePool (XenIo);\r
120 return Status;\r
121}\r
122\r
123/**\r
124\r
125 Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols\r
126\r
127 @param Handle Handle onto which the protocols have been installed\r
128 earlier by XenIoMmioInstall ()\r
129\r
130 @retval EFI_SUCCESS Protocols were uninstalled successfully\r
131\r
132 @return Status code returned by the boot service\r
133 UninstallMultipleProtocolInterfaces ()\r
134\r
135**/\r
136EFI_STATUS\r
137XenIoMmioUninstall (\r
138 IN EFI_HANDLE Handle\r
139 )\r
140{\r
141 EFI_STATUS Status;\r
142 VOID *XenIo;\r
143 VOID *XenBusDevicePath;\r
144\r
145 XenBusDevicePath = NULL;\r
146 gBS->OpenProtocol (Handle, &gEfiDevicePathProtocolGuid, &XenBusDevicePath,\r
147 NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
148\r
149 XenIo = NULL;\r
150 gBS->OpenProtocol (Handle, &gXenIoProtocolGuid, &XenIo,\r
151 NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
152\r
153 Status = gBS->UninstallMultipleProtocolInterfaces (Handle,\r
154 &gEfiDevicePathProtocolGuid, XenBusDevicePath,\r
155 &gXenIoProtocolGuid, XenIo,\r
156 NULL);\r
157\r
158 if (EFI_ERROR (Status)) {\r
159 return Status;\r
160 }\r
161\r
162 FreePool (XenBusDevicePath);\r
163 FreePool (XenIo);\r
164\r
165 return EFI_SUCCESS;\r
166}\r