blob: eaee188de7ef60db32784f3f3d7a9fbe26fac95d [file] [log] [blame]
Tom Rinif739fcd2018-05-07 17:02:21 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +02002/*
3 * EFI application loader
4 *
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +02006 */
7
8#ifndef _EFI_SELFTEST_H
9#define _EFI_SELFTEST_H
10
11#include <common.h>
12#include <efi.h>
13#include <efi_api.h>
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +020014#include <efi_loader.h>
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020015#include <linker_lists.h>
16
Heinrich Schuchardte67e7242017-10-04 15:31:26 +020017#define EFI_ST_SUCCESS 0
18#define EFI_ST_FAILURE 1
Heinrich Schuchardta9a25cc2018-09-30 13:26:36 +020019#define EFI_ST_SUCCESS_STR L"SUCCESS"
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020020/*
Heinrich Schuchardt853540c2018-01-11 08:15:54 +010021 * Prints a message.
22 */
23#define efi_st_printf(...) \
24 (efi_st_printc(-1, __VA_ARGS__))
25
26/*
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020027 * Prints an error message.
28 *
29 * @... format string followed by fields to print
30 */
31#define efi_st_error(...) \
Heinrich Schuchardt853540c2018-01-11 08:15:54 +010032 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
33 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020034
35/*
Heinrich Schuchardt927ca892017-11-06 21:17:43 +010036 * Prints a TODO message.
37 *
38 * @... format string followed by fields to print
39 */
40#define efi_st_todo(...) \
Heinrich Schuchardt853540c2018-01-11 08:15:54 +010041 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
42 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
Heinrich Schuchardt927ca892017-11-06 21:17:43 +010043
44/*
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020045 * A test may be setup and executed at boottime,
46 * it may be setup at boottime and executed at runtime,
47 * or it may be setup and executed at runtime.
48 */
49enum efi_test_phase {
50 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
51 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
52 EFI_SETUP_AFTER_BOOTTIME_EXIT,
53};
54
55extern struct efi_simple_text_output_protocol *con_out;
Heinrich Schuchardt3e603ec2018-09-08 10:20:10 +020056extern struct efi_simple_text_input_protocol *con_in;
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020057
58/*
59 * Exit the boot services.
60 *
61 * The size of the memory map is determined.
62 * Pool memory is allocated to copy the memory map.
63 * The memory amp is copied and the map key is obtained.
64 * The map key is used to exit the boot services.
65 */
66void efi_st_exit_boot_services(void);
67
68/*
Heinrich Schuchardt853540c2018-01-11 08:15:54 +010069 * Print a colored message
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020070 *
Heinrich Schuchardt853540c2018-01-11 08:15:54 +010071 * @color color, see constants in efi_api.h, use -1 for no color
72 * @fmt printf format
73 * @... arguments to be printed
74 * on return position of terminating zero word
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020075 */
Heinrich Schuchardt853540c2018-01-11 08:15:54 +010076void efi_st_printc(int color, const char *fmt, ...)
77 __attribute__ ((format (__printf__, 2, 3)));
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020078
Heinrich Schuchardt262ff412018-09-11 22:38:04 +020079/**
80 * efi_st_translate_char() - translate a unicode character to a string
81 *
82 * @code: unicode character
83 * Return: string
84 */
85u16 *efi_st_translate_char(u16 code);
86
87/**
88 * efi_st_translate_code() - translate a scan code to a human readable string
89 *
90 * @code: unicode character
91 * Return: string
92 */
93u16 *efi_st_translate_code(u16 code);
94
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020095/*
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +020096 * Compare an u16 string to a char string.
97 *
98 * @buf1: u16 string
99 * @buf2: char string
100 * @return: 0 if both buffers contain the same bytes
101 */
102int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
103
104/*
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200105 * Reads an Unicode character from the input device.
106 *
107 * @return: Unicode character
108 */
109u16 efi_st_get_key(void);
110
111/**
112 * struct efi_unit_test - EFI unit test
113 *
114 * An efi_unit_test provides a interface to an EFI unit test.
115 *
116 * @name: name of unit test
117 * @phase: specifies when setup and execute are executed
118 * @setup: set up the unit test
119 * @teardown: tear down the unit test
120 * @execute: execute the unit test
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200121 * @on_request: test is only executed on request
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200122 */
123struct efi_unit_test {
124 const char *name;
125 const enum efi_test_phase phase;
126 int (*setup)(const efi_handle_t handle,
127 const struct efi_system_table *systable);
128 int (*execute)(void);
129 int (*teardown)(void);
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200130 bool on_request;
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200131};
132
133/* Declare a new EFI unit test */
134#define EFI_UNIT_TEST(__name) \
135 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
136
137#endif /* _EFI_SELFTEST_H */