Skip to content

Commit b33f246

Browse files
committed
efi_selftest: export efi_st_get_config_table()
We can use efi_st_get_config_table() in multiple unit tests. Export the function. Export system-table and boot-services. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
1 parent afb70d1 commit b33f246

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

include/efi_selftest.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#define EFI_ST_FAILURE 1
1919
#define EFI_ST_SUCCESS_STR u"SUCCESS"
2020

21+
extern const struct efi_system_table *st_systable;
22+
extern const struct efi_boot_services *st_boottime;
23+
2124
/**
2225
* efi_st_printf() - print a message
2326
*
@@ -130,6 +133,14 @@ u16 *efi_st_translate_code(u16 code);
130133
*/
131134
int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
132135

136+
/**
137+
* efi_st_get_config_table() - get configuration table
138+
*
139+
* @guid: GUID of the configuration table
140+
* Return: pointer to configuration table or NULL
141+
*/
142+
void *efi_st_get_config_table(const efi_guid_t *guid);
143+
133144
/**
134145
* efi_st_get_key() - reads an Unicode character from the input device
135146
*

lib/efi_selftest/efi_selftest.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#define EFI_ST_EXECUTE 2
1515
#define EFI_ST_TEARDOWN 4
1616

17-
static const struct efi_system_table *systable;
18-
static const struct efi_boot_services *boottime;
17+
const struct efi_system_table *st_systable;
18+
const struct efi_boot_services *st_boottime;
1919
static const struct efi_runtime_services *runtime;
2020
static efi_handle_t handle;
2121
static u16 reset_message[] = u"Selftest completed";
@@ -41,7 +41,7 @@ void efi_st_exit_boot_services(void)
4141
/* Do not detach devices in ExitBootServices. We need the console. */
4242
efi_st_keep_devices = true;
4343

44-
ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
44+
ret = st_boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
4545
&desc_version);
4646
if (ret != EFI_BUFFER_TOO_SMALL) {
4747
efi_st_error(
@@ -50,19 +50,19 @@ void efi_st_exit_boot_services(void)
5050
}
5151
/* Allocate extra space for newly allocated memory */
5252
map_size += sizeof(struct efi_mem_desc);
53-
ret = boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size,
53+
ret = st_boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size,
5454
(void **)&memory_map);
5555
if (ret != EFI_SUCCESS) {
5656
efi_st_error("AllocatePool did not return EFI_SUCCESS\n");
5757
return;
5858
}
59-
ret = boottime->get_memory_map(&map_size, memory_map, &map_key,
59+
ret = st_boottime->get_memory_map(&map_size, memory_map, &map_key,
6060
&desc_size, &desc_version);
6161
if (ret != EFI_SUCCESS) {
6262
efi_st_error("GetMemoryMap did not return EFI_SUCCESS\n");
6363
return;
6464
}
65-
ret = boottime->exit_boot_services(handle, map_key);
65+
ret = st_boottime->exit_boot_services(handle, map_key);
6666
if (ret != EFI_SUCCESS) {
6767
efi_st_error("ExitBootServices did not return EFI_SUCCESS\n");
6868
return;
@@ -84,7 +84,7 @@ static int setup(struct efi_unit_test *test, unsigned int *failures)
8484
if (!test->setup)
8585
return EFI_ST_SUCCESS;
8686
efi_st_printc(EFI_LIGHTBLUE, "\nSetting up '%s'\n", test->name);
87-
ret = test->setup(handle, systable);
87+
ret = test->setup(handle, st_systable);
8888
if (ret != EFI_ST_SUCCESS) {
8989
efi_st_error("Setting up '%s' failed\n", test->name);
9090
++*failures;
@@ -240,8 +240,8 @@ void efi_st_do_tests(const u16 *testname, unsigned int phase,
240240
* All tests use a driver model and are run in three phases:
241241
* setup, execute, teardown.
242242
*
243-
* A test may be setup and executed at boottime,
244-
* it may be setup at boottime and executed at runtime,
243+
* A test may be setup and executed at st_boottime,
244+
* it may be setup at st_boottime and executed at runtime,
245245
* or it may be setup and executed at runtime.
246246
*
247247
* After executing all tests the system is reset.
@@ -257,14 +257,14 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
257257
struct efi_loaded_image *loaded_image;
258258
efi_status_t ret;
259259

260-
systable = systab;
261-
boottime = systable->boottime;
262-
runtime = systable->runtime;
260+
st_systable = systab;
261+
st_boottime = st_systable->boottime;
262+
runtime = st_systable->runtime;
263263
handle = image_handle;
264-
con_out = systable->con_out;
265-
con_in = systable->con_in;
264+
con_out = st_systable->con_out;
265+
con_in = st_systable->con_in;
266266

267-
ret = boottime->handle_protocol(image_handle, &efi_guid_loaded_image,
267+
ret = st_boottime->handle_protocol(image_handle, &efi_guid_loaded_image,
268268
(void **)&loaded_image);
269269
if (ret != EFI_SUCCESS) {
270270
efi_st_error("Cannot open loaded image protocol\n");
@@ -280,9 +280,9 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
280280
list_all_tests();
281281
/*
282282
* TODO:
283-
* Once the Exit boottime service is correctly
283+
* Once the Exit st_boottime service is correctly
284284
* implemented we should call
285-
* boottime->exit(image_handle, EFI_SUCCESS, 0, NULL);
285+
* st_boottime->exit(image_handle, EFI_SUCCESS, 0, NULL);
286286
* here, cf.
287287
* https://lists.denx.de/pipermail/u-boot/2017-October/308720.html
288288
*/
@@ -300,7 +300,7 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
300300
efi_unit_test));
301301

302302
/* Allocate buffer for setup results */
303-
ret = boottime->allocate_pool(EFI_RUNTIME_SERVICES_DATA, sizeof(int) *
303+
ret = st_boottime->allocate_pool(EFI_RUNTIME_SERVICES_DATA, sizeof(int) *
304304
ll_entry_count(struct efi_unit_test,
305305
efi_unit_test),
306306
(void **)&setup_status);
@@ -309,7 +309,7 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
309309
return ret;
310310
}
311311

312-
/* Execute boottime tests */
312+
/* Execute st_boottime tests */
313313
efi_st_do_tests(testname, EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
314314
EFI_ST_SETUP | EFI_ST_EXECUTE | EFI_ST_TEARDOWN,
315315
&failures);

lib/efi_selftest/efi_selftest_fdt.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,6 @@ static char *get_property(const u16 *property, const u16 *node)
144144
return NULL;
145145
}
146146

147-
/**
148-
* efi_st_get_config_table() - get configuration table
149-
*
150-
* @guid: GUID of the configuration table
151-
* Return: pointer to configuration table or NULL
152-
*/
153-
static void *efi_st_get_config_table(const efi_guid_t *guid)
154-
{
155-
size_t i;
156-
157-
for (i = 0; i < systab.nr_tables; i++) {
158-
if (!guidcmp(guid, &systemtab->tables[i].guid))
159-
return systemtab->tables[i].table;
160-
}
161-
return NULL;
162-
}
163-
164147
/*
165148
* Setup unit test.
166149
*

lib/efi_selftest/efi_selftest_util.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,14 @@ int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2)
110110
}
111111
return 0;
112112
}
113+
114+
void *efi_st_get_config_table(const efi_guid_t *guid)
115+
{
116+
size_t i;
117+
118+
for (i = 0; i < st_systable->nr_tables; i++) {
119+
if (!guidcmp(guid, &st_systable->tables[i].guid))
120+
return st_systable->tables[i].table;
121+
}
122+
return NULL;
123+
}

0 commit comments

Comments
 (0)