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