efi_selftest_gop.c 1.9 KB

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