/src/u-boot/lib/efi_selftest/efi_selftest_gop.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0+ |
2 | | /* |
3 | | * efi_selftest_gop |
4 | | * |
5 | | * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de> |
6 | | * |
7 | | * Test the graphical output protocol. |
8 | | */ |
9 | | |
10 | | #include <efi_selftest.h> |
11 | | |
12 | | static struct efi_boot_services *boottime; |
13 | | static efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; |
14 | | static struct efi_gop *gop; |
15 | | |
16 | | /* |
17 | | * Setup unit test. |
18 | | * |
19 | | * @handle: handle of the loaded image |
20 | | * @systable: system table |
21 | | * Return: EFI_ST_SUCCESS for success |
22 | | */ |
23 | | static int setup(const efi_handle_t handle, |
24 | | const struct efi_system_table *systable) |
25 | 0 | { |
26 | 0 | efi_status_t ret; |
27 | |
|
28 | 0 | boottime = systable->boottime; |
29 | |
|
30 | 0 | ret = boottime->locate_protocol(&efi_gop_guid, NULL, (void **)&gop); |
31 | 0 | if (ret != EFI_SUCCESS) { |
32 | 0 | gop = NULL; |
33 | 0 | efi_st_printf("Graphical output protocol is not available.\n"); |
34 | 0 | } |
35 | |
|
36 | 0 | return EFI_ST_SUCCESS; |
37 | 0 | } |
38 | | |
39 | | /* |
40 | | * Tear down unit test. |
41 | | * |
42 | | * Return: EFI_ST_SUCCESS for success |
43 | | */ |
44 | | static int teardown(void) |
45 | 0 | { |
46 | 0 | return EFI_ST_SUCCESS; |
47 | 0 | } |
48 | | |
49 | | /* |
50 | | * Execute unit test. |
51 | | * |
52 | | * Return: EFI_ST_SUCCESS for success |
53 | | */ |
54 | | static int execute(void) |
55 | 0 | { |
56 | 0 | efi_status_t ret; |
57 | 0 | u32 i, max_mode; |
58 | 0 | efi_uintn_t size; |
59 | 0 | struct efi_gop_mode_info *info; |
60 | |
|
61 | 0 | if (!gop) |
62 | 0 | return EFI_ST_SUCCESS; |
63 | | |
64 | 0 | if (!gop->mode) { |
65 | 0 | efi_st_error("EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE missing\n"); |
66 | 0 | return EFI_ST_FAILURE; |
67 | 0 | } |
68 | 0 | max_mode = gop->mode->max_mode; |
69 | 0 | if (!max_mode) { |
70 | 0 | efi_st_error("No graphical mode available\n"); |
71 | 0 | return EFI_ST_FAILURE; |
72 | 0 | } |
73 | 0 | efi_st_printf("Number of available modes: %u\n", max_mode); |
74 | |
|
75 | 0 | for (i = 0; i < max_mode; ++i) { |
76 | 0 | ret = gop->query_mode(gop, i, &size, &info); |
77 | 0 | if (ret != EFI_SUCCESS) { |
78 | 0 | efi_st_printf("Could not query mode %u\n", i); |
79 | 0 | return EFI_ST_FAILURE; |
80 | 0 | } |
81 | 0 | efi_st_printf("Mode %u: %u x %u\n", |
82 | 0 | i, info->width, info->height); |
83 | 0 | ret = boottime->free_pool(info); |
84 | 0 | if (ret != EFI_SUCCESS) { |
85 | 0 | efi_st_printf("FreePool failed"); |
86 | 0 | return EFI_ST_FAILURE; |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | 0 | return EFI_ST_SUCCESS; |
91 | 0 | } |
92 | | |
93 | | EFI_UNIT_TEST(gop) = { |
94 | | .name = "graphical output", |
95 | | .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
96 | | .setup = setup, |
97 | | .execute = execute, |
98 | | .teardown = teardown, |
99 | | }; |