| 1 |
/* |
| 2 |
* Copyright (C) 2013 David Decotigny <[email protected]> |
| 3 |
* |
| 4 |
* See drv0.c for an example session. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <efi.h> |
| 8 |
#include <efilib.h> |
| 9 |
#include "drv0.h" |
| 10 |
|
| 11 |
|
| 12 |
static EFI_GUID GnuEfiAppsDrv0ProtocolGuid |
| 13 |
= GNU_EFI_APPS_DRV0_PROTOCOL_GUID; |
| 14 |
|
| 15 |
|
| 16 |
static |
| 17 |
EFI_STATUS |
| 18 |
PlayWithGnuEfiAppsDrv0Protocol(IN EFI_HANDLE DrvHandle) { |
| 19 |
EFI_STATUS Status; |
| 20 |
GNU_EFI_APPS_DRV0_PROTOCOL *drv = NULL; |
| 21 |
UINTN NumberOfHello = 0; |
| 22 |
|
| 23 |
Status = uefi_call_wrapper(BS->OpenProtocol, 6, |
| 24 |
DrvHandle, |
| 25 |
&GnuEfiAppsDrv0ProtocolGuid, |
| 26 |
(void**)&drv, |
| 27 |
DrvHandle, |
| 28 |
NULL, |
| 29 |
EFI_OPEN_PROTOCOL_GET_PROTOCOL); |
| 30 |
if (EFI_ERROR(Status)) { |
| 31 |
Print(L"Cannot open proto: %d\n", Status); |
| 32 |
return Status; |
| 33 |
} |
| 34 |
|
| 35 |
Status = uefi_call_wrapper(drv->SayHello, 2, L"Sample UEFI Driver"); |
| 36 |
if (EFI_ERROR(Status)) { |
| 37 |
Print(L"Cannot call SayHello: %d\n", Status); |
| 38 |
} |
| 39 |
|
| 40 |
Status = uefi_call_wrapper(drv->GetNumberOfHello, 2, &NumberOfHello); |
| 41 |
if (EFI_ERROR(Status)) { |
| 42 |
Print(L"Cannot call GetNumberOfHello: %d\n", Status); |
| 43 |
} else { |
| 44 |
Print(L"Hello was called %d time(s).\n", NumberOfHello); |
| 45 |
} |
| 46 |
|
| 47 |
return EFI_SUCCESS; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
EFI_STATUS |
| 52 |
efi_main (EFI_HANDLE Image, EFI_SYSTEM_TABLE *SysTab) |
| 53 |
{ |
| 54 |
EFI_STATUS Status; |
| 55 |
EFI_HANDLE *Handles = NULL; |
| 56 |
UINTN i, NoHandles = 0; |
| 57 |
|
| 58 |
InitializeLib(Image, SysTab); |
| 59 |
|
| 60 |
Status = LibLocateHandle(ByProtocol, &GnuEfiAppsDrv0ProtocolGuid, |
| 61 |
NULL, &NoHandles, &Handles); |
| 62 |
if (EFI_ERROR(Status)) { |
| 63 |
Print(L"Error looking up handles for proto: %d\n", Status); |
| 64 |
return Status; |
| 65 |
} |
| 66 |
|
| 67 |
for (i = 0 ; i < NoHandles ; ++i) |
| 68 |
{ |
| 69 |
Print(L"Playing with driver instance %d...\n", i); |
| 70 |
Status = PlayWithGnuEfiAppsDrv0Protocol(Handles[i]); |
| 71 |
if (EFI_ERROR(Status)) |
| 72 |
Print(L"Error playing with instance %d, skipping\n", i); |
| 73 |
} |
| 74 |
|
| 75 |
if (Handles) |
| 76 |
FreePool(Handles); |
| 77 |
|
| 78 |
return EFI_SUCCESS; |
| 79 |
} |