fsp_graphics.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <vbe.h>
  9. #include <video.h>
  10. #include <asm/fsp/fsp_support.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. struct pixel {
  13. u8 pos;
  14. u8 size;
  15. };
  16. static const struct fsp_framebuffer {
  17. struct pixel red;
  18. struct pixel green;
  19. struct pixel blue;
  20. struct pixel rsvd;
  21. } fsp_framebuffer_format_map[] = {
  22. [pixel_rgbx_8bpc] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
  23. [pixel_bgrx_8bpc] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
  24. };
  25. static int save_vesa_mode(struct vesa_mode_info *vesa)
  26. {
  27. const struct hob_graphics_info *ginfo;
  28. const struct fsp_framebuffer *fbinfo;
  29. ginfo = fsp_get_graphics_info(gd->arch.hob_list, NULL);
  30. /*
  31. * If there is no graphics info structure, bail out and keep
  32. * running on the serial console.
  33. */
  34. if (!ginfo) {
  35. debug("FSP graphics hand-off block not found\n");
  36. return -ENXIO;
  37. }
  38. vesa->x_resolution = ginfo->width;
  39. vesa->y_resolution = ginfo->height;
  40. vesa->bits_per_pixel = 32;
  41. vesa->bytes_per_scanline = ginfo->pixels_per_scanline * 4;
  42. vesa->phys_base_ptr = ginfo->fb_base;
  43. if (ginfo->pixel_format >= pixel_bitmask) {
  44. debug("FSP set unknown framebuffer format: %d\n",
  45. ginfo->pixel_format);
  46. return -EINVAL;
  47. }
  48. fbinfo = &fsp_framebuffer_format_map[ginfo->pixel_format];
  49. vesa->red_mask_size = fbinfo->red.size;
  50. vesa->red_mask_pos = fbinfo->red.pos;
  51. vesa->green_mask_size = fbinfo->green.size;
  52. vesa->green_mask_pos = fbinfo->green.pos;
  53. vesa->blue_mask_size = fbinfo->blue.size;
  54. vesa->blue_mask_pos = fbinfo->blue.pos;
  55. vesa->reserved_mask_size = fbinfo->rsvd.size;
  56. vesa->reserved_mask_pos = fbinfo->rsvd.pos;
  57. return 0;
  58. }
  59. static int fsp_video_probe(struct udevice *dev)
  60. {
  61. struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
  62. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  63. struct vesa_mode_info *vesa = &mode_info.vesa;
  64. int ret;
  65. printf("Video: ");
  66. /* Initialize vesa_mode_info structure */
  67. ret = save_vesa_mode(vesa);
  68. if (ret)
  69. goto err;
  70. /*
  71. * The framebuffer base address in the FSP graphics info HOB reflects
  72. * the value assigned by the FSP. After PCI enumeration the framebuffer
  73. * base address may be relocated. Let's get the updated one from device.
  74. *
  75. * For IGD, it seems to be always on BAR2.
  76. */
  77. vesa->phys_base_ptr = dm_pci_read_bar32(dev, 2);
  78. ret = vbe_setup_video_priv(vesa, uc_priv, plat);
  79. if (ret)
  80. goto err;
  81. printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
  82. vesa->bits_per_pixel);
  83. return 0;
  84. err:
  85. printf("No video mode configured in FSP!\n");
  86. return ret;
  87. }
  88. static const struct udevice_id fsp_video_ids[] = {
  89. { .compatible = "fsp-fb" },
  90. { }
  91. };
  92. U_BOOT_DRIVER(fsp_video) = {
  93. .name = "fsp_video",
  94. .id = UCLASS_VIDEO,
  95. .of_match = fsp_video_ids,
  96. .probe = fsp_video_probe,
  97. };
  98. static struct pci_device_id fsp_video_supported[] = {
  99. { PCI_DEVICE_CLASS(PCI_CLASS_DISPLAY_VGA << 8, 0xffff00) },
  100. { },
  101. };
  102. U_BOOT_PCI_DEVICE(fsp_video, fsp_video_supported);