TianoCore EDK2 master
Loading...
Searching...
No Matches
XenPvBlkDxe.c
Go to the documentation of this file.
1
15#include "XenPvBlkDxe.h"
16
17#include "BlockFront.h"
18
26 XEN_PV_BLK_DXE_VERSION,
27 NULL,
28 NULL
29};
30
41EFIAPI
43 IN EFI_HANDLE ImageHandle
44 )
45{
46 EFI_STATUS Status;
47
48 EFI_HANDLE *HandleBuffer;
49 UINTN HandleCount;
50 UINTN Index;
51
52 //
53 // Retrieve array of all handles in the handle database
54 //
55 Status = gBS->LocateHandleBuffer (
57 NULL,
58 NULL,
59 &HandleCount,
60 &HandleBuffer
61 );
62 if (EFI_ERROR (Status)) {
63 return Status;
64 }
65
66 //
67 // Disconnect the current driver from handles in the handle database
68 //
69 for (Index = 0; Index < HandleCount; Index++) {
70 gBS->DisconnectController (HandleBuffer[Index], gImageHandle, NULL);
71 }
72
73 //
74 // Free the array of handles
75 //
76 FreePool (HandleBuffer);
77
78 //
79 // Uninstall protocols installed in the driver entry point
80 //
81 Status = gBS->UninstallMultipleProtocolInterfaces (
82 ImageHandle,
83 &gEfiDriverBindingProtocolGuid,
85 &gEfiComponentNameProtocolGuid,
87 &gEfiComponentName2ProtocolGuid,
89 NULL
90 );
91 if (EFI_ERROR (Status)) {
92 return Status;
93 }
94
95 return EFI_SUCCESS;
96}
97
110EFIAPI
112 IN EFI_HANDLE ImageHandle,
113 IN EFI_SYSTEM_TABLE *SystemTable
114 )
115{
116 EFI_STATUS Status;
117
118 //
119 // Install UEFI Driver Model protocol(s).
120 //
122 ImageHandle,
123 SystemTable,
125 ImageHandle,
128 );
129 ASSERT_EFI_ERROR (Status);
130
131 return Status;
132}
133
177EFIAPI
180 IN EFI_HANDLE ControllerHandle,
181 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
182 )
183{
184 EFI_STATUS Status;
185 XENBUS_PROTOCOL *XenBusIo;
186
187 Status = gBS->OpenProtocol (
188 ControllerHandle,
189 &gXenBusProtocolGuid,
190 (VOID **)&XenBusIo,
191 This->DriverBindingHandle,
192 ControllerHandle,
193 EFI_OPEN_PROTOCOL_BY_DRIVER
194 );
195 if (EFI_ERROR (Status)) {
196 return Status;
197 }
198
199 if (AsciiStrCmp (XenBusIo->Type, "vbd") == 0) {
200 Status = EFI_SUCCESS;
201 } else {
202 Status = EFI_UNSUPPORTED;
203 }
204
205 gBS->CloseProtocol (
206 ControllerHandle,
207 &gXenBusProtocolGuid,
208 This->DriverBindingHandle,
209 ControllerHandle
210 );
211
212 return Status;
213}
214
251EFIAPI
254 IN EFI_HANDLE ControllerHandle,
255 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
256 )
257{
258 EFI_STATUS Status;
259 XENBUS_PROTOCOL *XenBusIo;
261 EFI_BLOCK_IO_MEDIA *Media;
262
263 Status = gBS->OpenProtocol (
264 ControllerHandle,
265 &gXenBusProtocolGuid,
266 (VOID **)&XenBusIo,
267 This->DriverBindingHandle,
268 ControllerHandle,
269 EFI_OPEN_PROTOCOL_BY_DRIVER
270 );
271 if (EFI_ERROR (Status)) {
272 return Status;
273 }
274
275 Status = XenPvBlockFrontInitialization (XenBusIo, XenBusIo->Node, &Dev);
276 if (EFI_ERROR (Status)) {
277 goto CloseProtocol;
278 }
279
280 CopyMem (&Dev->BlockIo, &gXenPvBlkDxeBlockIo, sizeof (EFI_BLOCK_IO_PROTOCOL));
281 Media = AllocateCopyPool (
282 sizeof (EFI_BLOCK_IO_MEDIA),
284 );
285 if (Dev->MediaInfo.VDiskInfo & VDISK_REMOVABLE) {
286 Media->RemovableMedia = TRUE;
287 }
288
289 Media->MediaPresent = TRUE;
290 Media->ReadOnly = !Dev->MediaInfo.ReadWrite;
291 if (Dev->MediaInfo.CdRom) {
292 //
293 // If it's a cdrom, the blocksize value need to be 2048 for OVMF to
294 // recognize it as a cdrom:
295 // MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
296 //
297 Media->BlockSize = 2048;
298 Media->LastBlock = DivU64x32 (
299 Dev->MediaInfo.Sectors,
300 Media->BlockSize / Dev->MediaInfo.SectorSize
301 ) - 1;
302 } else {
303 Media->BlockSize = Dev->MediaInfo.SectorSize;
304 Media->LastBlock = Dev->MediaInfo.Sectors - 1;
305 }
306
307 ASSERT (Media->BlockSize % 512 == 0);
308 Dev->BlockIo.Media = Media;
309
310 Status = gBS->InstallMultipleProtocolInterfaces (
311 &ControllerHandle,
312 &gEfiBlockIoProtocolGuid,
313 &Dev->BlockIo,
314 NULL
315 );
316 if (EFI_ERROR (Status)) {
317 DEBUG ((DEBUG_ERROR, "XenPvBlk: install protocol fail: %r\n", Status));
318 goto UninitBlockFront;
319 }
320
321 return EFI_SUCCESS;
322
323UninitBlockFront:
324 FreePool (Media);
325 XenPvBlockFrontShutdown (Dev);
326CloseProtocol:
327 gBS->CloseProtocol (
328 ControllerHandle,
329 &gXenBusProtocolGuid,
330 This->DriverBindingHandle,
331 ControllerHandle
332 );
333 return Status;
334}
335
363EFIAPI
366 IN EFI_HANDLE ControllerHandle,
367 IN UINTN NumberOfChildren,
368 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
369 )
370{
371 EFI_BLOCK_IO_PROTOCOL *BlockIo;
373 EFI_BLOCK_IO_MEDIA *Media;
374 EFI_STATUS Status;
375
376 Status = gBS->OpenProtocol (
377 ControllerHandle,
378 &gEfiBlockIoProtocolGuid,
379 (VOID **)&BlockIo,
380 This->DriverBindingHandle,
381 ControllerHandle,
382 EFI_OPEN_PROTOCOL_GET_PROTOCOL
383 );
384 if (EFI_ERROR (Status)) {
385 return Status;
386 }
387
388 Status = gBS->UninstallProtocolInterface (
389 ControllerHandle,
390 &gEfiBlockIoProtocolGuid,
391 BlockIo
392 );
393 if (EFI_ERROR (Status)) {
394 return Status;
395 }
396
397 Media = BlockIo->Media;
398 Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo);
399 XenPvBlockFrontShutdown (Dev);
400
401 FreePool (Media);
402
403 gBS->CloseProtocol (
404 ControllerHandle,
405 &gXenBusProtocolGuid,
406 This->DriverBindingHandle,
407 ControllerHandle
408 );
409
410 return EFI_SUCCESS;
411}
UINT64 UINTN
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
GLOBAL_REMOVE_IF_UNREFERENCED EFI_BLOCK_IO_PROTOCOL gXenPvBlkDxeBlockIo
Definition: BlockIo.c:40
GLOBAL_REMOVE_IF_UNREFERENCED EFI_BLOCK_IO_MEDIA gXenPvBlkDxeBlockIoMedia
Definition: BlockIo.c:21
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gXenPvBlkDxeComponentName2
Definition: ComponentName.c:26
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gXenPvBlkDxeComponentName
Definition: ComponentName.c:16
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
@ AllHandles
Definition: UefiSpec.h:1509
EFI_STATUS EFIAPI XenPvBlkDxeDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: XenPvBlkDxe.c:364
EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding
Definition: XenPvBlkDxe.c:22
EFI_STATUS EFIAPI XenPvBlkDxeDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: XenPvBlkDxe.c:178
EFI_STATUS EFIAPI XenPvBlkDxeDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: XenPvBlkDxe.c:111
EFI_STATUS EFIAPI XenPvBlkDxeDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: XenPvBlkDxe.c:252
EFI_STATUS EFIAPI XenPvBlkDxeUnload(IN EFI_HANDLE ImageHandle)
Definition: XenPvBlkDxe.c:42
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo.h:224
BOOLEAN RemovableMedia
Definition: BlockIo.h:137
UINT32 BlockSize
Definition: BlockIo.h:167
EFI_LBA LastBlock
Definition: BlockIo.h:178
BOOLEAN MediaPresent
Definition: BlockIo.h:144
BOOLEAN ReadOnly
Definition: BlockIo.h:156