blob: 07b619901c07ec1f9f526dc01822972680d9cba6 [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +02002/*
3 * EFI application loader
4 *
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
Heinrich Schuchardtd33ae3e2017-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 Schuchardt02efd5d2017-10-18 18:13:13 +020014#include <efi_loader.h>
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020015#include <linker_lists.h>
16
Heinrich Schuchardt1afe5f72017-10-04 15:31:26 +020017#define EFI_ST_SUCCESS 0
18#define EFI_ST_FAILURE 1
Heinrich Schuchardt1696dd02018-09-30 13:26:36 +020019#define EFI_ST_SUCCESS_STR L"SUCCESS"
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020020
21/**
22 * efi_st_printf() - print a message
23 *
24 * @...: format string followed by fields to print
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010025 */
26#define efi_st_printf(...) \
27 (efi_st_printc(-1, __VA_ARGS__))
28
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020029/**
30 * efi_st_error() - prints an error message
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020031 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020032 * @...: format string followed by fields to print
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020033 */
34#define efi_st_error(...) \
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010035 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
36 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020037
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020038/**
39 * efi_st_todo() - prints a TODO message
Heinrich Schuchardtc53591c2017-11-06 21:17:43 +010040 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020041 * @...: format string followed by fields to print
Heinrich Schuchardtc53591c2017-11-06 21:17:43 +010042 */
43#define efi_st_todo(...) \
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010044 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
45 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
Heinrich Schuchardtc53591c2017-11-06 21:17:43 +010046
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020047/**
48 * enum efi_test_phase - phase when test will be executed
49 *
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020050 * A test may be setup and executed at boottime,
51 * it may be setup at boottime and executed at runtime,
52 * or it may be setup and executed at runtime.
53 */
54enum efi_test_phase {
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020055 /**
56 * @EFI_EXECUTE_BEFORE_BOOTTIME_EXIT: - execute before ExitBootServices
57 *
58 * Setup, execute, and teardown are executed before ExitBootServices().
59 */
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020060 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020061 /**
62 * @EFI_SETUP_BEFORE_BOOTTIME_EXIT: - setup before ExitBootServices
63 *
64 * Setup is executed before ExitBootServices() while execute, and
65 * teardown are executed after ExitBootServices().
66 */
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020067 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020068 /**
Heinrich Schuchardtc7c782a2021-03-24 17:48:01 +010069 * @EFI_SETTING_VIRTUAL_ADDRESS_MAP - calls SetVirtualAddressMap()
70 * Execute calls SetVirtualAddressMap().
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020071 */
Heinrich Schuchardtc7c782a2021-03-24 17:48:01 +010072 EFI_SETTING_VIRTUAL_ADDRESS_MAP,
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020073};
74
75extern struct efi_simple_text_output_protocol *con_out;
Heinrich Schuchardt3dabffd2018-09-08 10:20:10 +020076extern struct efi_simple_text_input_protocol *con_in;
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020077
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020078/**
79 * efi_st_exit_boot_services() - exit the boot services
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020080 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020081 * * The size of the memory map is determined.
82 * * Pool memory is allocated to copy the memory map.
83 * * The memory map is copied and the map key is obtained.
84 * * The map key is used to exit the boot services.
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020085 */
86void efi_st_exit_boot_services(void);
87
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020088/**
89 * efi_st_printc() - print a colored message
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020090 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020091 * @color: color, see constants in efi_api.h, use -1 for no color
92 * @fmt: printf style format string
93 * @...: arguments to be printed
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020094 */
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010095void efi_st_printc(int color, const char *fmt, ...)
96 __attribute__ ((format (__printf__, 2, 3)));
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020097
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +020098/**
Heinrich Schuchardta42e6292020-05-09 07:33:43 +020099 * efi_st_translate_char() - translate a Unicode character to a string
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +0200100 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200101 * @code: Unicode character
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +0200102 * Return: string
103 */
104u16 *efi_st_translate_char(u16 code);
105
106/**
107 * efi_st_translate_code() - translate a scan code to a human readable string
108 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200109 * This function translates the scan code returned by the simple text input
110 * protocol to a human readable string, e.g. 0x04 is translated to L"Left".
111 *
112 * @code: scan code
113 * Return: Unicode string
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +0200114 */
115u16 *efi_st_translate_code(u16 code);
116
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200117/**
118 * efi_st_strcmp_16_8() - compare an u16 string to a char string
119 *
120 * This function compares each u16 value to the char value at the same
121 * position. This function is only useful for ANSI strings.
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +0200122 *
123 * @buf1: u16 string
124 * @buf2: char string
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200125 * Return: 0 if both buffers contain equivalent strings
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +0200126 */
127int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
128
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200129/**
130 * efi_st_get_key() - reads an Unicode character from the input device
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200131 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200132 * Return: Unicode character
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200133 */
134u16 efi_st_get_key(void);
135
136/**
137 * struct efi_unit_test - EFI unit test
138 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200139 * The &struct efi_unit_test structure provides a interface to an EFI unit test.
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200140 *
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200141 * @name: name of the unit test used in the user interface
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200142 * @phase: specifies when setup and execute are executed
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200143 * @setup: set up function of the unit test
144 * @execute: execute function of the unit test
145 * @teardown: tear down function of the unit test
146 * @on_request: flag indicating that the test shall only be executed on request
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200147 */
148struct efi_unit_test {
149 const char *name;
150 const enum efi_test_phase phase;
151 int (*setup)(const efi_handle_t handle,
152 const struct efi_system_table *systable);
153 int (*execute)(void);
154 int (*teardown)(void);
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +0200155 bool on_request;
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200156};
157
Heinrich Schuchardta42e6292020-05-09 07:33:43 +0200158/**
159 * EFI_UNIT_TEST() - macro to declare a new EFI unit test
160 *
161 * The macro EFI_UNIT_TEST() declares an EFI unit test using the &struct
162 * efi_unit_test structure. The test is added to a linker generated list which
163 * is evaluated by the 'bootefi selftest' command.
164 *
165 * @__name: string identifying the unit test in the linker generated list
166 */
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200167#define EFI_UNIT_TEST(__name) \
168 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
169
170#endif /* _EFI_SELFTEST_H */