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