TianoCore EDK2 master
Loading...
Searching...
No Matches
XenIoMmioLib.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
13#include <Library/UefiLib.h>
18
19#include <Protocol/XenIo.h>
21
22#pragma pack (1)
23typedef struct {
24 VENDOR_DEVICE_PATH Vendor;
25 EFI_PHYSICAL_ADDRESS GrantTableAddress;
28#pragma pack ()
29
30STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = {
31 {
32 {
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
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
125FreeXenIo:
126 FreePool (XenIo);
127 return Status;
128}
129
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}
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_VENDOR_DP
Definition: DevicePath.h:133
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS XenIoMmioUninstall(IN EFI_HANDLE Handle)
Definition: XenIoMmioLib.c:144
EFI_STATUS XenIoMmioInstall(IN OUT EFI_HANDLE *Handle, IN EFI_PHYSICAL_ADDRESS GrantTableAddress)
Definition: XenIoMmioLib.c:68