coreboot_fb.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * coreboot Framebuffer driver.
  3. *
  4. * Copyright (C) 2011 The Chromium OS authors
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/arch/tables.h>
  10. #include <asm/arch/sysinfo.h>
  11. #include <video_fb.h>
  12. #include "videomodes.h"
  13. /*
  14. * The Graphic Device
  15. */
  16. GraphicDevice ctfb;
  17. static int parse_coreboot_table_fb(GraphicDevice *gdev)
  18. {
  19. struct cb_framebuffer *fb = lib_sysinfo.framebuffer;
  20. /* If there is no framebuffer structure, bail out and keep
  21. * running on the serial console.
  22. */
  23. if (!fb)
  24. return 0;
  25. gdev->winSizeX = fb->x_resolution;
  26. gdev->winSizeY = fb->y_resolution;
  27. gdev->plnSizeX = fb->x_resolution;
  28. gdev->plnSizeY = fb->y_resolution;
  29. gdev->gdfBytesPP = fb->bits_per_pixel / 8;
  30. switch (fb->bits_per_pixel) {
  31. case 24:
  32. gdev->gdfIndex = GDF_32BIT_X888RGB;
  33. break;
  34. case 16:
  35. gdev->gdfIndex = GDF_16BIT_565RGB;
  36. break;
  37. default:
  38. gdev->gdfIndex = GDF__8BIT_INDEX;
  39. break;
  40. }
  41. gdev->isaBase = CONFIG_SYS_ISA_IO_BASE_ADDRESS;
  42. gdev->pciBase = (unsigned int)fb->physical_address;
  43. gdev->frameAdrs = (unsigned int)fb->physical_address;
  44. gdev->memSize = fb->bytes_per_line * fb->y_resolution;
  45. gdev->vprBase = (unsigned int)fb->physical_address;
  46. gdev->cprBase = (unsigned int)fb->physical_address;
  47. return 1;
  48. }
  49. void *video_hw_init(void)
  50. {
  51. GraphicDevice *gdev = &ctfb;
  52. int bits_per_pixel;
  53. printf("Video: ");
  54. if (!parse_coreboot_table_fb(gdev)) {
  55. printf("No video mode configured in coreboot!\n");
  56. return NULL;
  57. }
  58. bits_per_pixel = gdev->gdfBytesPP * 8;
  59. /* fill in Graphic device struct */
  60. sprintf(gdev->modeIdent, "%dx%dx%d", gdev->winSizeX, gdev->winSizeY,
  61. bits_per_pixel);
  62. printf("%s\n", gdev->modeIdent);
  63. memset((void *)gdev->pciBase, 0,
  64. gdev->winSizeX * gdev->winSizeY * gdev->gdfBytesPP);
  65. return (void *)gdev;
  66. }