]>
Commit | Line | Data |
---|---|---|
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 | |
b26f0cf9 | 6 | * SPDX-License-Identifier: BSD-2-Clause-Patent\r |
0169352e AB |
7 | *\r |
8 | **/\r | |
9 | \r | |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/UefiBootServicesTableLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
13 | #include <Library/UefiLib.h>\r | |
14 | #include <Library/BaseMemoryLib.h>\r | |
15 | #include <Library/MemoryAllocationLib.h>\r | |
16 | #include <Library/DevicePathLib.h>\r | |
17 | #include <Library/XenIoMmioLib.h>\r | |
18 | \r | |
19 | #include <Protocol/XenIo.h>\r | |
20 | #include <Guid/XenBusRootDevice.h>\r | |
21 | \r | |
22 | #pragma pack (1)\r | |
23 | typedef struct {\r | |
ac0a286f MK |
24 | VENDOR_DEVICE_PATH Vendor;\r |
25 | EFI_PHYSICAL_ADDRESS GrantTableAddress;\r | |
26 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
0169352e AB |
27 | } XENBUS_ROOT_DEVICE_PATH;\r |
28 | #pragma pack ()\r | |
29 | \r | |
ac0a286f | 30 | STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = {\r |
0169352e AB |
31 | {\r |
32 | {\r | |
33 | HARDWARE_DEVICE_PATH,\r | |
34 | HW_VENDOR_DP,\r | |
35 | { sizeof (VENDOR_DEVICE_PATH) + sizeof (EFI_PHYSICAL_ADDRESS), 0 }\r | |
36 | },\r | |
37 | XENBUS_ROOT_DEVICE_GUID,\r | |
38 | },\r | |
39 | 0,\r | |
40 | {\r | |
41 | END_DEVICE_PATH_TYPE,\r | |
42 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
ac0a286f | 43 | { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r |
0169352e AB |
44 | }\r |
45 | };\r | |
46 | \r | |
47 | /**\r | |
48 | \r | |
49 | Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on\r | |
50 | the handle pointed to by @Handle, or on a new handle if it points to\r | |
51 | NULL\r | |
52 | \r | |
53 | @param Handle Pointer to the handle to install the protocols\r | |
54 | on, may point to a NULL handle.\r | |
55 | \r | |
56 | @param GrantTableAddress The address of the Xen grant table\r | |
57 | \r | |
58 | @retval EFI_SUCCESS Protocols were installed successfully\r | |
59 | \r | |
60 | @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required\r | |
61 | by the XenIo MMIO and device path protocols\r | |
62 | \r | |
63 | @return Status code returned by the boot service\r | |
64 | InstallMultipleProtocolInterfaces ()\r | |
65 | \r | |
66 | **/\r | |
67 | EFI_STATUS\r | |
68 | XenIoMmioInstall (\r | |
ac0a286f MK |
69 | IN OUT EFI_HANDLE *Handle,\r |
70 | IN EFI_PHYSICAL_ADDRESS GrantTableAddress\r | |
0169352e AB |
71 | )\r |
72 | {\r | |
ac0a286f MK |
73 | EFI_STATUS Status;\r |
74 | XENIO_PROTOCOL *XenIo;\r | |
75 | XENBUS_ROOT_DEVICE_PATH *XenBusDevicePath;\r | |
76 | EFI_HANDLE OutHandle;\r | |
0169352e AB |
77 | \r |
78 | ASSERT (Handle != NULL);\r | |
79 | \r | |
80 | OutHandle = *Handle;\r | |
81 | \r | |
82 | XenIo = AllocateZeroPool (sizeof *XenIo);\r | |
83 | if (!XenIo) {\r | |
84 | return EFI_OUT_OF_RESOURCES;\r | |
85 | }\r | |
ac0a286f | 86 | \r |
0169352e AB |
87 | XenIo->GrantTableAddress = GrantTableAddress;\r |
88 | \r | |
ac0a286f MK |
89 | XenBusDevicePath = AllocateCopyPool (\r |
90 | sizeof *XenBusDevicePath,\r | |
91 | &mXenBusRootDevicePathTemplate\r | |
92 | );\r | |
0169352e | 93 | if (!XenBusDevicePath) {\r |
70d5086c | 94 | DEBUG ((DEBUG_ERROR, "%a: Out of memory\n", __FUNCTION__));\r |
0169352e AB |
95 | Status = EFI_OUT_OF_RESOURCES;\r |
96 | goto FreeXenIo;\r | |
97 | }\r | |
ac0a286f | 98 | \r |
0169352e AB |
99 | XenBusDevicePath->GrantTableAddress = GrantTableAddress;\r |
100 | \r | |
ac0a286f MK |
101 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
102 | &OutHandle,\r | |
103 | &gEfiDevicePathProtocolGuid,\r | |
104 | XenBusDevicePath,\r | |
105 | &gXenIoProtocolGuid,\r | |
106 | XenIo,\r | |
107 | NULL\r | |
108 | );\r | |
0169352e AB |
109 | if (!EFI_ERROR (Status)) {\r |
110 | *Handle = OutHandle;\r | |
111 | return EFI_SUCCESS;\r | |
112 | }\r | |
4040754d | 113 | \r |
ac0a286f MK |
114 | DEBUG ((\r |
115 | DEBUG_ERROR,\r | |
116 | "%a: Failed to install the EFI_DEVICE_PATH and "\r | |
0169352e | 117 | "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",\r |
ac0a286f MK |
118 | __FUNCTION__,\r |
119 | OutHandle,\r | |
120 | Status\r | |
121 | ));\r | |
0169352e AB |
122 | \r |
123 | FreePool (XenBusDevicePath);\r | |
124 | \r | |
125 | FreeXenIo:\r | |
126 | FreePool (XenIo);\r | |
127 | return Status;\r | |
128 | }\r | |
129 | \r | |
130 | /**\r | |
131 | \r | |
132 | Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols\r | |
133 | \r | |
134 | @param Handle Handle onto which the protocols have been installed\r | |
135 | earlier by XenIoMmioInstall ()\r | |
136 | \r | |
137 | @retval EFI_SUCCESS Protocols were uninstalled successfully\r | |
138 | \r | |
139 | @return Status code returned by the boot service\r | |
140 | UninstallMultipleProtocolInterfaces ()\r | |
141 | \r | |
142 | **/\r | |
143 | EFI_STATUS\r | |
144 | XenIoMmioUninstall (\r | |
ac0a286f | 145 | IN EFI_HANDLE Handle\r |
0169352e AB |
146 | )\r |
147 | {\r | |
ac0a286f MK |
148 | EFI_STATUS Status;\r |
149 | VOID *XenIo;\r | |
150 | VOID *XenBusDevicePath;\r | |
0169352e AB |
151 | \r |
152 | XenBusDevicePath = NULL;\r | |
ac0a286f MK |
153 | gBS->OpenProtocol (\r |
154 | Handle,\r | |
155 | &gEfiDevicePathProtocolGuid,\r | |
156 | &XenBusDevicePath,\r | |
157 | NULL,\r | |
158 | NULL,\r | |
159 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
160 | );\r | |
0169352e AB |
161 | \r |
162 | XenIo = NULL;\r | |
ac0a286f MK |
163 | gBS->OpenProtocol (\r |
164 | Handle,\r | |
165 | &gXenIoProtocolGuid,\r | |
166 | &XenIo,\r | |
167 | NULL,\r | |
168 | NULL,\r | |
169 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
170 | );\r | |
171 | \r | |
172 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
173 | Handle,\r | |
174 | &gEfiDevicePathProtocolGuid,\r | |
175 | XenBusDevicePath,\r | |
176 | &gXenIoProtocolGuid,\r | |
177 | XenIo,\r | |
178 | NULL\r | |
179 | );\r | |
0169352e AB |
180 | \r |
181 | if (EFI_ERROR (Status)) {\r | |
182 | return Status;\r | |
183 | }\r | |
184 | \r | |
185 | FreePool (XenBusDevicePath);\r | |
186 | FreePool (XenIo);\r | |
187 | \r | |
188 | return EFI_SUCCESS;\r | |
189 | }\r |