1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <efi/boot-services.h>
8 #include <efi/system-table.h>
9 #include <efi/types.h>
10 #include <efi/protocol/device-path.h>
11 #include <efi/protocol/file.h>
12 #include <efi/protocol/simple-text-output.h>
13 
14 void xefi_init(efi_handle img, efi_system_table* sys);
15 
16 void xefi_wait_any_key(void);
17 void xefi_fatal(const char* msg, efi_status status);
18 char16_t* xefi_handle_to_str(efi_handle handle);
19 const char *xefi_strerror(efi_status status);
20 const char16_t* xefi_wstrerror(efi_status status);
21 size_t strlen_16(char16_t* str);
22 
23 char16_t* xefi_devpath_to_str(efi_device_path_protocol* path);
24 
25 int xefi_cmp_guid(efi_guid* guid1, efi_guid* guid2);
26 
27 // Convenience wrappers for Open/Close protocol for use by
28 // UEFI app code that's not a driver model participant
29 efi_status xefi_open_protocol(efi_handle h, efi_guid* guid, void** ifc);
30 efi_status xefi_close_protocol(efi_handle h, efi_guid* guid);
31 
32 efi_file_protocol* xefi_open_file(const char16_t* filename);
33 void* xefi_read_file(efi_file_protocol* file, size_t* _sz, size_t front_bytes);
34 void* xefi_load_file(const char16_t* filename, size_t* size_out,
35                      size_t front_bytes);
36 
37 efi_status xefi_find_pci_mmio(efi_boot_services* bs, uint8_t cls, uint8_t sub, uint8_t ifc, uint64_t* mmio);
38 
39 // GUIDs
40 extern efi_guid SimpleFileSystemProtocol;
41 extern efi_guid FileInfoGUID;
42 
43 typedef struct {
44     efi_handle img;
45     efi_system_table* sys;
46     efi_boot_services* bs;
47     efi_simple_text_output_protocol* conout;
48 } xefi_global;
49 
50 extern xefi_global xefi_global_state;
51 
52 // Global Context
53 #define gImg (xefi_global_state.img)
54 #define gSys (xefi_global_state.sys)
55 #define gBS (xefi_global_state.bs)
56 #define gConOut (xefi_global_state.conout)
57