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