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
14void xefi_init(efi_handle img, efi_system_table* sys);
15
16void xefi_wait_any_key(void);
17void xefi_fatal(const char* msg, efi_status status);
18char16_t* xefi_handle_to_str(efi_handle handle);
19const char *xefi_strerror(efi_status status);
20const char16_t* xefi_wstrerror(efi_status status);
21size_t strlen_16(char16_t* str);
22
23char16_t* xefi_devpath_to_str(efi_device_path_protocol* path);
24
25int 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
29efi_status xefi_open_protocol(efi_handle h, efi_guid* guid, void** ifc);
30efi_status xefi_close_protocol(efi_handle h, efi_guid* guid);
31
32efi_file_protocol* xefi_open_file(char16_t* filename);
33void* xefi_read_file(efi_file_protocol* file, size_t* _sz, size_t front_bytes);
34void* xefi_load_file(char16_t* filename, size_t* size_out, size_t front_bytes);
35
36efi_status xefi_find_pci_mmio(efi_boot_services* bs, uint8_t cls, uint8_t sub, uint8_t ifc, uint64_t* mmio);
37
38// GUIDs
39extern efi_guid SimpleFileSystemProtocol;
40extern efi_guid FileInfoGUID;
41
42typedef struct {
43    efi_handle img;
44    efi_system_table* sys;
45    efi_boot_services* bs;
46    efi_simple_text_output_protocol* conout;
47} xefi_global;
48
49extern xefi_global xefi_global_state;
50
51// Global Context
52#define gImg (xefi_global_state.img)
53#define gSys (xefi_global_state.sys)
54#define gBS (xefi_global_state.bs)
55#define gConOut (xefi_global_state.conout)
56
57