Prepare v2025.01
[u-boot.git] / include / efi_selftest.h
blob1b708849bcb9f3b07995b399d996add754324b2e
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3 * EFI application loader
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 */
8 #ifndef _EFI_SELFTEST_H
9 #define _EFI_SELFTEST_H
11 #include <efi.h>
12 #include <efi_api.h>
13 #include <efi_loader.h>
14 #include <linker_lists.h>
16 #define EFI_ST_SUCCESS 0
17 #define EFI_ST_FAILURE 1
18 #define EFI_ST_SUCCESS_STR u"SUCCESS"
20 extern const struct efi_system_table *st_systable;
21 extern const struct efi_boot_services *st_boottime;
23 /**
24 * efi_st_printf() - print a message
26 * @...: format string followed by fields to print
28 #define efi_st_printf(...) \
29 (efi_st_printc(-1, __VA_ARGS__))
31 /**
32 * efi_st_error() - prints an error message
34 * @...: format string followed by fields to print
36 #define efi_st_error(...) \
37 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
38 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
40 /**
41 * efi_st_todo() - prints a TODO message
43 * @...: format string followed by fields to print
45 #define efi_st_todo(...) \
46 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
47 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
49 /**
50 * enum efi_test_phase - phase when test will be executed
52 * A test may be setup and executed at boottime,
53 * it may be setup at boottime and executed at runtime,
54 * or it may be setup and executed at runtime.
56 enum efi_test_phase {
57 /**
58 * @EFI_EXECUTE_BEFORE_BOOTTIME_EXIT:
60 * Setup, execute, and teardown are executed before ExitBootServices().
62 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
63 /**
64 * @EFI_SETUP_BEFORE_BOOTTIME_EXIT:
66 * Setup is executed before ExitBootServices() while execute, and
67 * teardown are executed after ExitBootServices().
69 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
70 /**
71 * @EFI_SETTING_VIRTUAL_ADDRESS_MAP:
73 * Execute calls SetVirtualAddressMap(). Setup is executed before
74 * ExitBootServices() while execute is executed after
75 * ExitBootServices(), and after the execute of tests marked as
76 * @EFI_SETUP_BEFORE_BOOTTIME_EXIT. Teardown is executed thereafter.
78 EFI_SETTING_VIRTUAL_ADDRESS_MAP,
81 extern struct efi_simple_text_output_protocol *con_out;
82 extern struct efi_simple_text_input_protocol *con_in;
84 /**
85 * efi_st_exit_boot_services() - exit the boot services
87 * * The size of the memory map is determined.
88 * * Pool memory is allocated to copy the memory map.
89 * * The memory map is copied and the map key is obtained.
90 * * The map key is used to exit the boot services.
92 void efi_st_exit_boot_services(void);
94 /**
95 * efi_st_printc() - print a colored message
97 * @color: color, see constants in efi_api.h, use -1 for no color
98 * @fmt: printf style format string
99 * @...: arguments to be printed
101 void efi_st_printc(int color, const char *fmt, ...)
102 __attribute__ ((format (__printf__, 2, 3)));
105 * efi_st_translate_char() - translate a Unicode character to a string
107 * @code: Unicode character
108 * Return: string
110 u16 *efi_st_translate_char(u16 code);
113 * efi_st_translate_code() - translate a scan code to a human readable string
115 * This function translates the scan code returned by the simple text input
116 * protocol to a human readable string, e.g. 0x04 is translated to u"Left".
118 * @code: scan code
119 * Return: Unicode string
121 u16 *efi_st_translate_code(u16 code);
124 * efi_st_strcmp_16_8() - compare an u16 string to a char string
126 * This function compares each u16 value to the char value at the same
127 * position. This function is only useful for ANSI strings.
129 * @buf1: u16 string
130 * @buf2: char string
131 * Return: 0 if both buffers contain equivalent strings
133 int efi_st_strcmp_16_8(const u16 *buf1, const unsigned char *buf2);
136 * efi_st_get_config_table() - get configuration table
138 * @guid: GUID of the configuration table
139 * Return: pointer to configuration table or NULL
141 void *efi_st_get_config_table(const efi_guid_t *guid);
144 * efi_st_get_key() - reads an Unicode character from the input device
146 * Return: Unicode character
148 u16 efi_st_get_key(void);
151 * efi_st_query_variable_common - Common variable tests for boottime/runtime
153 * @runtime: Pointer to services table
154 * @attributes: Attributes used
156 * Return: EFI_ST_SUCCESS/FAILURE
158 int efi_st_query_variable_common(struct efi_runtime_services *runtime,
159 u32 attributes);
162 * struct efi_unit_test - EFI unit test
164 * The &struct efi_unit_test structure provides a interface to an EFI unit test.
166 * @name: name of the unit test used in the user interface
167 * @phase: specifies when setup and execute are executed
168 * @setup: set up function of the unit test
169 * @execute: execute function of the unit test
170 * @teardown: tear down function of the unit test
171 * @on_request: flag indicating that the test shall only be executed on request
173 struct efi_unit_test {
174 const char *name;
175 const enum efi_test_phase phase;
176 int (*setup)(const efi_handle_t handle,
177 const struct efi_system_table *systable);
178 int (*execute)(void);
179 int (*teardown)(void);
180 bool on_request;
184 * EFI_UNIT_TEST() - macro to declare a new EFI unit test
186 * The macro EFI_UNIT_TEST() declares an EFI unit test using the &struct
187 * efi_unit_test structure. The test is added to a linker generated list which
188 * is evaluated by the 'bootefi selftest' command.
190 * @__name: string identifying the unit test in the linker generated list
192 #define EFI_UNIT_TEST(__name) \
193 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
195 #endif /* _EFI_SELFTEST_H */