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