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