Home | History | Annotate | Download | only in efi_selftest
      1 // SPDX-License-Identifier: GPL-2.0+
      2 /*
      3  * efi_selftest_gop
      4  *
      5  * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk (at) 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_GOP_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 {
     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  *
     42  * @return:	EFI_ST_SUCCESS for success
     43  */
     44 static int teardown(void)
     45 {
     46 	return EFI_ST_SUCCESS;
     47 }
     48 
     49 /*
     50  * Execute unit test.
     51  *
     52  * @return:	EFI_ST_SUCCESS for success
     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);
     83 	}
     84 
     85 	return EFI_ST_SUCCESS;
     86 }
     87 
     88 EFI_UNIT_TEST(gop) = {
     89 	.name = "graphical output",
     90 	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
     91 	.setup = setup,
     92 	.execute = execute,
     93 	.teardown = teardown,
     94 };
     95