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