drv0_use.c 1.9 KB

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