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