]>
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 | |
24 | VENDOR_DEVICE_PATH Vendor;\r | |
25 | EFI_PHYSICAL_ADDRESS GrantTableAddress;\r | |
26 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
27 | } XENBUS_ROOT_DEVICE_PATH;\r | |
28 | #pragma pack ()\r | |
29 | \r | |
30 | STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = {\r | |
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 | |
43 | { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r | |
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 | |
69 | IN OUT EFI_HANDLE *Handle,\r | |
70 | IN EFI_PHYSICAL_ADDRESS GrantTableAddress\r | |
71 | )\r | |
72 | {\r | |
73 | EFI_STATUS Status;\r | |
74 | XENIO_PROTOCOL *XenIo;\r | |
75 | XENBUS_ROOT_DEVICE_PATH *XenBusDevicePath;\r | |
76 | EFI_HANDLE OutHandle;\r | |
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 | |
86 | XenIo->GrantTableAddress = GrantTableAddress;\r | |
87 | \r | |
88 | XenBusDevicePath = AllocateCopyPool (sizeof *XenBusDevicePath,\r | |
89 | &mXenBusRootDevicePathTemplate);\r | |
90 | if (!XenBusDevicePath) {\r | |
91 | DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));\r | |
92 | Status = EFI_OUT_OF_RESOURCES;\r | |
93 | goto FreeXenIo;\r | |
94 | }\r | |
95 | XenBusDevicePath->GrantTableAddress = GrantTableAddress;\r | |
96 | \r | |
97 | Status = gBS->InstallMultipleProtocolInterfaces (&OutHandle,\r | |
98 | &gEfiDevicePathProtocolGuid, XenBusDevicePath,\r | |
99 | &gXenIoProtocolGuid, XenIo,\r | |
100 | NULL);\r | |
101 | if (!EFI_ERROR (Status)) {\r | |
102 | *Handle = OutHandle;\r | |
103 | return EFI_SUCCESS;\r | |
104 | }\r | |
4040754d | 105 | \r |
0169352e AB |
106 | DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH and "\r |
107 | "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",\r | |
108 | __FUNCTION__, OutHandle, Status));\r | |
109 | \r | |
110 | FreePool (XenBusDevicePath);\r | |
111 | \r | |
112 | FreeXenIo:\r | |
113 | FreePool (XenIo);\r | |
114 | return Status;\r | |
115 | }\r | |
116 | \r | |
117 | /**\r | |
118 | \r | |
119 | Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols\r | |
120 | \r | |
121 | @param Handle Handle onto which the protocols have been installed\r | |
122 | earlier by XenIoMmioInstall ()\r | |
123 | \r | |
124 | @retval EFI_SUCCESS Protocols were uninstalled successfully\r | |
125 | \r | |
126 | @return Status code returned by the boot service\r | |
127 | UninstallMultipleProtocolInterfaces ()\r | |
128 | \r | |
129 | **/\r | |
130 | EFI_STATUS\r | |
131 | XenIoMmioUninstall (\r | |
132 | IN EFI_HANDLE Handle\r | |
133 | )\r | |
134 | {\r | |
135 | EFI_STATUS Status;\r | |
136 | VOID *XenIo;\r | |
137 | VOID *XenBusDevicePath;\r | |
138 | \r | |
139 | XenBusDevicePath = NULL;\r | |
140 | gBS->OpenProtocol (Handle, &gEfiDevicePathProtocolGuid, &XenBusDevicePath,\r | |
141 | NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
142 | \r | |
143 | XenIo = NULL;\r | |
144 | gBS->OpenProtocol (Handle, &gXenIoProtocolGuid, &XenIo,\r | |
145 | NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
146 | \r | |
147 | Status = gBS->UninstallMultipleProtocolInterfaces (Handle,\r | |
148 | &gEfiDevicePathProtocolGuid, XenBusDevicePath,\r | |
149 | &gXenIoProtocolGuid, XenIo,\r | |
150 | NULL);\r | |
151 | \r | |
152 | if (EFI_ERROR (Status)) {\r | |
153 | return Status;\r | |
154 | }\r | |
155 | \r | |
156 | FreePool (XenBusDevicePath);\r | |
157 | FreePool (XenIo);\r | |
158 | \r | |
159 | return EFI_SUCCESS;\r | |
160 | }\r |