TianoCore EDK2 master
Loading...
Searching...
No Matches
EmuBlockIo.c
Go to the documentation of this file.
1
8#include "EmuBlockIo.h"
9
24EFIAPI
27 IN BOOLEAN ExtendedVerification
28 )
29{
30 EFI_STATUS Status;
31 EMU_BLOCK_IO_PRIVATE *Private;
32 EFI_TPL OldTpl;
33
34 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
35
36 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
37
38 Status = Private->Io->Reset (Private->Io, ExtendedVerification);
39
40 gBS->RestoreTPL (OldTpl);
41 return Status;
42}
43
78EFIAPI
81 IN UINT32 MediaId,
82 IN EFI_LBA LBA,
84 IN UINTN BufferSize,
85 OUT VOID *Buffer
86 )
87{
88 EFI_STATUS Status;
89 EMU_BLOCK_IO_PRIVATE *Private;
90 EFI_TPL OldTpl;
91
92 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
93
94 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
95
96 Status = Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);
97
98 gBS->RestoreTPL (OldTpl);
99 return Status;
100}
101
134EFIAPI
137 IN UINT32 MediaId,
138 IN EFI_LBA LBA,
140 IN UINTN BufferSize,
141 IN VOID *Buffer
142 )
143{
144 EFI_STATUS Status;
145 EMU_BLOCK_IO_PRIVATE *Private;
146 EFI_TPL OldTpl;
147
148 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
149
150 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
151
152 Status = Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);
153
154 gBS->RestoreTPL (OldTpl);
155 return Status;
156}
157
181EFIAPI
185 )
186{
187 EFI_STATUS Status;
188 EMU_BLOCK_IO_PRIVATE *Private;
189 EFI_TPL OldTpl;
190
191 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
192
193 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
194
195 Status = Private->Io->FlushBlocks (Private->Io, Token);
196
197 gBS->RestoreTPL (OldTpl);
198 return Status;
199}
200
213EFIAPI
216 IN BOOLEAN ExtendedVerification
217 )
218{
219 EFI_STATUS Status;
220 EMU_BLOCK_IO_PRIVATE *Private;
221 EFI_TPL OldTpl;
222
223 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
224
225 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
226
227 Status = Private->Io->Reset (Private->Io, ExtendedVerification);
228
229 gBS->RestoreTPL (OldTpl);
230 return Status;
231}
232
253EFIAPI
256 IN UINT32 MediaId,
257 IN EFI_LBA Lba,
258 IN UINTN BufferSize,
259 OUT VOID *Buffer
260 )
261{
262 EFI_STATUS Status;
263 EMU_BLOCK_IO_PRIVATE *Private;
264 EFI_TPL OldTpl;
266
267 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
268
269 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
270
271 Token.Event = NULL;
272 Status = Private->Io->ReadBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);
273
274 gBS->RestoreTPL (OldTpl);
275 return Status;
276}
277
299EFIAPI
302 IN UINT32 MediaId,
303 IN EFI_LBA Lba,
304 IN UINTN BufferSize,
305 IN VOID *Buffer
306 )
307{
308 EFI_STATUS Status;
309 EMU_BLOCK_IO_PRIVATE *Private;
310 EFI_TPL OldTpl;
312
313 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
314
315 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
316
317 Token.Event = NULL;
318 Status = Private->Io->WriteBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);
319
320 gBS->RestoreTPL (OldTpl);
321 return Status;
322}
323
335EFIAPI
338 )
339{
340 EFI_STATUS Status;
341 EMU_BLOCK_IO_PRIVATE *Private;
342 EFI_TPL OldTpl;
344
345 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
346
347 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
348
349 Token.Event = NULL;
350 Status = Private->Io->FlushBlocks (Private->Io, &Token);
351
352 gBS->RestoreTPL (OldTpl);
353 return Status;
354}
355
399EFIAPI
402 IN EFI_HANDLE Handle,
403 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
404 )
405{
406 EFI_STATUS Status;
407 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
408
409 //
410 // Open the IO Abstraction(s) needed to perform the supported test
411 //
412 Status = gBS->OpenProtocol (
413 Handle,
414 &gEmuIoThunkProtocolGuid,
415 (VOID **)&EmuIoThunk,
416 This->DriverBindingHandle,
417 Handle,
418 EFI_OPEN_PROTOCOL_BY_DRIVER
419 );
420 if (EFI_ERROR (Status)) {
421 return Status;
422 }
423
424 //
425 // Make sure GUID is for a File System handle.
426 //
427 Status = EFI_UNSUPPORTED;
428 if (CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {
429 Status = EFI_SUCCESS;
430 }
431
432 //
433 // Close the I/O Abstraction(s) used to perform the supported test
434 //
435 gBS->CloseProtocol (
436 Handle,
437 &gEmuIoThunkProtocolGuid,
438 This->DriverBindingHandle,
439 Handle
440 );
441 return Status;
442}
443
480EFIAPI
483 IN EFI_HANDLE Handle,
484 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
485 )
486{
487 EFI_STATUS Status;
488 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
489 EMU_BLOCK_IO_PRIVATE *Private = NULL;
490
491 //
492 // Grab the protocols we need
493 //
494
495 Status = gBS->OpenProtocol (
496 Handle,
497 &gEmuIoThunkProtocolGuid,
498 (void *)&EmuIoThunk,
499 This->DriverBindingHandle,
500 Handle,
501 EFI_OPEN_PROTOCOL_BY_DRIVER
502 );
503 if (EFI_ERROR (Status)) {
504 return Status;
505 }
506
507 if (!CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {
508 Status = EFI_UNSUPPORTED;
509 goto Done;
510 }
511
512 Status = EmuIoThunk->Open (EmuIoThunk);
513 if (EFI_ERROR (Status)) {
514 goto Done;
515 }
516
517 Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));
518 if (Private == NULL) {
519 goto Done;
520 }
521
522 Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;
523 Private->IoThunk = EmuIoThunk;
524 Private->Io = EmuIoThunk->Interface;
525 Private->EfiHandle = Handle;
526
527 Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;
528 Private->BlockIo.Media = &Private->Media;
529 Private->BlockIo.Reset = EmuBlockIoReset;
530 Private->BlockIo.ReadBlocks = EmuBlockIoReadBlocks;
531 Private->BlockIo.WriteBlocks = EmuBlockIoWriteBlocks;
532 Private->BlockIo.FlushBlocks = EmuBlockIoFlushBlocks;
533
534 Private->BlockIo2.Media = &Private->Media;
535 Private->BlockIo2.Reset = EmuBlockIo2Reset;
536 Private->BlockIo2.ReadBlocksEx = EmuBlockIo2ReadBlocksEx;
537 Private->BlockIo2.WriteBlocksEx = EmuBlockIo2WriteBlocksEx;
538 Private->BlockIo2.FlushBlocksEx = EmuBlockIo2Flush;
539
540 Private->ControllerNameTable = NULL;
541
542 Status = Private->Io->CreateMapping (Private->Io, &Private->Media);
543 if (EFI_ERROR (Status)) {
544 goto Done;
545 }
546
548 "eng",
549 gEmuBlockIoComponentName.SupportedLanguages,
550 &Private->ControllerNameTable,
551 EmuIoThunk->ConfigString,
552 TRUE
553 );
554
556 "en",
557 gEmuBlockIoComponentName2.SupportedLanguages,
558 &Private->ControllerNameTable,
559 EmuIoThunk->ConfigString,
560 FALSE
561 );
562
563 Status = gBS->InstallMultipleProtocolInterfaces (
564 &Handle,
565 &gEfiBlockIoProtocolGuid,
566 &Private->BlockIo,
567 &gEfiBlockIo2ProtocolGuid,
568 &Private->BlockIo2,
569 NULL
570 );
571
572Done:
573 if (EFI_ERROR (Status)) {
574 if (Private != NULL) {
575 if (Private->ControllerNameTable != NULL) {
576 FreeUnicodeStringTable (Private->ControllerNameTable);
577 }
578
579 gBS->FreePool (Private);
580 }
581
582 gBS->CloseProtocol (
583 Handle,
584 &gEmuIoThunkProtocolGuid,
585 This->DriverBindingHandle,
586 Handle
587 );
588 }
589
590 return Status;
591}
592
620EFIAPI
623 IN EFI_HANDLE Handle,
624 IN UINTN NumberOfChildren,
625 IN EFI_HANDLE *ChildHandleBuffer
626 )
627{
628 EFI_BLOCK_IO_PROTOCOL *BlockIo;
629 EFI_STATUS Status;
630 EMU_BLOCK_IO_PRIVATE *Private;
631
632 //
633 // Get our context back
634 //
635 Status = gBS->OpenProtocol (
636 Handle,
637 &gEfiBlockIoProtocolGuid,
638 (void *)&BlockIo,
639 This->DriverBindingHandle,
640 Handle,
641 EFI_OPEN_PROTOCOL_GET_PROTOCOL
642 );
643 if (EFI_ERROR (Status)) {
644 return EFI_UNSUPPORTED;
645 }
646
647 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
648
649 Status = gBS->UninstallMultipleProtocolInterfaces (
650 Private->EfiHandle,
651 &gEfiBlockIoProtocolGuid,
652 &Private->BlockIo,
653 &gEfiBlockIo2ProtocolGuid,
654 &Private->BlockIo2,
655 NULL
656 );
657 if (!EFI_ERROR (Status)) {
658 Status = gBS->CloseProtocol (
659 Handle,
660 &gEmuIoThunkProtocolGuid,
661 This->DriverBindingHandle,
662 Handle
663 );
664 ASSERT_EFI_ERROR (Status);
665 //
666 // Destroy the IO interface.
667 //
668 Status = Private->IoThunk->Close (Private->IoThunk);
669 ASSERT_EFI_ERROR (Status);
670 //
671 // Free our instance data
672 //
673 FreeUnicodeStringTable (Private->ControllerNameTable);
674 FreePool (Private);
675 }
676
677 return Status;
678}
679
680EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding = {
684 0xa,
685 NULL,
686 NULL
687};
688
700EFIAPI
702 IN EFI_HANDLE ImageHandle,
703 IN EFI_SYSTEM_TABLE *SystemTable
704 )
705{
706 EFI_STATUS Status;
707
709 ImageHandle,
710 SystemTable,
711 &gEmuBlockIoDriverBinding,
712 ImageHandle,
713 &gEmuBlockIoComponentName,
714 &gEmuBlockIoComponentName2,
715 NULL,
716 NULL,
717 &gEmuBlockIoDriverDiagnostics,
718 &gEmuBlockIoDriverDiagnostics2
719 );
720 ASSERT_EFI_ERROR (Status);
721
722 return Status;
723}
UINT64 UINTN
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI EmuBlockIo2ReadBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA LBA, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: EmuBlockIo.c:79
EFI_STATUS EFIAPI EmuBlockIo2Reset(IN EFI_BLOCK_IO2_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: EmuBlockIo.c:25
EFI_STATUS EFIAPI EmuBlockIoReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: EmuBlockIo.c:214
EFI_STATUS EFIAPI EmuBlockIo2Flush(IN EFI_BLOCK_IO2_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
Definition: EmuBlockIo.c:182
EFI_STATUS EFIAPI EmuBlockIoReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: EmuBlockIo.c:254
EFI_STATUS EFIAPI EmuBlockIoDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: EmuBlockIo.c:400
EFI_STATUS EFIAPI EmuBlockIoDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: EmuBlockIo.c:481
EFI_STATUS EFIAPI EmuBlockIoWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
Definition: EmuBlockIo.c:300
EFI_STATUS EFIAPI EmuBlockIo2WriteBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA LBA, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, IN VOID *Buffer)
Definition: EmuBlockIo.c:135
EFI_STATUS EFIAPI EmuBlockIoFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
Definition: EmuBlockIo.c:336
EFI_STATUS EFIAPI InitializeEmuBlockIo(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: EmuBlockIo.c:701
EFI_STATUS EFIAPI EmuBlockIoDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: EmuBlockIo.c:621
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI AddUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable, IN CONST CHAR16 *UnicodeString, IN BOOLEAN Iso639Language)
Definition: UefiLib.c:1087
EFI_STATUS EFIAPI EfiLibInstallAllDriverProtocols2(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, IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration OPTIONAL, IN CONST EFI_DRIVER_CONFIGURATION2_PROTOCOL *DriverConfiguration2 OPTIONAL, IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics OPTIONAL, IN CONST EFI_DRIVER_DIAGNOSTICS2_PROTOCOL *DriverDiagnostics2 OPTIONAL)
EFI_STATUS EFIAPI FreeUnicodeStringTable(IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable)
Definition: UefiLib.c:1257
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo2.h:187
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo.h:224
CHAR16 * ConfigString
Only be valid after Open() is called.
Definition: EmuIoThunk.h:33
EFI_EVENT Event
Definition: BlockIo2.h:34