efi_selftest_gop.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include <efi_selftest.h>
  10. static struct efi_boot_services *boottime;
  11. static efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  12. static struct efi_gop *gop;
  13. /*
  14. * Setup unit test.
  15. *
  16. * @handle: handle of the loaded image
  17. * @systable: system table
  18. * @return: EFI_ST_SUCCESS for success
  19. */
  20. static int setup(const efi_handle_t handle,
  21. const struct efi_system_table *systable)
  22. {
  23. efi_status_t ret;
  24. boottime = systable->boottime;
  25. ret = boottime->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
  26. if (ret != EFI_SUCCESS) {
  27. gop = NULL;
  28. efi_st_printf("Graphical output protocol is not available.\n");
  29. }
  30. return EFI_ST_SUCCESS;
  31. }
  32. /*
  33. * Tear down unit test.
  34. *
  35. * @return: EFI_ST_SUCCESS for success
  36. */
  37. static int teardown(void)
  38. {
  39. return EFI_ST_SUCCESS;
  40. }
  41. /*
  42. * Execute unit test.
  43. *
  44. * @return: EFI_ST_SUCCESS for success
  45. */
  46. static int execute(void)
  47. {
  48. efi_status_t ret;
  49. u32 i, max_mode;
  50. efi_uintn_t size;
  51. struct efi_gop_mode_info *info;
  52. if (!gop)
  53. return EFI_ST_SUCCESS;
  54. if (!gop->mode) {
  55. efi_st_error("EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE missing\n");
  56. return EFI_ST_FAILURE;
  57. }
  58. max_mode = gop->mode->max_mode;
  59. if (!max_mode) {
  60. efi_st_error("No graphical mode available\n");
  61. return EFI_ST_FAILURE;
  62. }
  63. efi_st_printf("Number of available modes: %u\n", max_mode);
  64. for (i = 0; i < max_mode; ++i) {
  65. ret = gop->query_mode(gop, i, &size, &info);
  66. if (ret != EFI_SUCCESS) {
  67. efi_st_printf("Could not query mode %u\n", i);
  68. return EFI_ST_FAILURE;
  69. }
  70. efi_st_printf("Mode %u: %u x %u\n",
  71. i, info->width, info->height);
  72. ret = boottime->free_pool(info);
  73. if (ret != EFI_SUCCESS) {
  74. efi_st_printf("FreePool failed");
  75. return EFI_ST_FAILURE;
  76. }
  77. }
  78. return EFI_ST_SUCCESS;
  79. }
  80. EFI_UNIT_TEST(gop) = {
  81. .name = "graphical output",
  82. .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
  83. .setup = setup,
  84. .execute = execute,
  85. .teardown = teardown,
  86. };