sysfb_simplefb.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Generic System Framebuffers on x86
  3. * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 2 of the License, or (at your option)
  8. * any later version.
  9. */
  10. /*
  11. * simple-framebuffer probing
  12. * Try to convert "screen_info" into a "simple-framebuffer" compatible mode.
  13. * If the mode is incompatible, we return "false" and let the caller create
  14. * legacy nodes instead.
  15. */
  16. #include <linux/err.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/platform_data/simplefb.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/screen_info.h>
  23. #include <asm/sysfb.h>
  24. static const char simplefb_resname[] = "BOOTFB";
  25. static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
  26. /* try parsing x86 screen_info into a simple-framebuffer mode struct */
  27. __init bool parse_mode(const struct screen_info *si,
  28. struct simplefb_platform_data *mode)
  29. {
  30. const struct simplefb_format *f;
  31. __u8 type;
  32. unsigned int i;
  33. type = si->orig_video_isVGA;
  34. if (type != VIDEO_TYPE_VLFB && type != VIDEO_TYPE_EFI)
  35. return false;
  36. for (i = 0; i < ARRAY_SIZE(formats); ++i) {
  37. f = &formats[i];
  38. if (si->lfb_depth == f->bits_per_pixel &&
  39. si->red_size == f->red.length &&
  40. si->red_pos == f->red.offset &&
  41. si->green_size == f->green.length &&
  42. si->green_pos == f->green.offset &&
  43. si->blue_size == f->blue.length &&
  44. si->blue_pos == f->blue.offset &&
  45. si->rsvd_size == f->transp.length &&
  46. si->rsvd_pos == f->transp.offset) {
  47. mode->format = f->name;
  48. mode->width = si->lfb_width;
  49. mode->height = si->lfb_height;
  50. mode->stride = si->lfb_linelength;
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. __init int create_simplefb(const struct screen_info *si,
  57. const struct simplefb_platform_data *mode)
  58. {
  59. struct platform_device *pd;
  60. struct resource res;
  61. u64 base, size;
  62. u32 length;
  63. /*
  64. * If the 64BIT_BASE capability is set, ext_lfb_base will contain the
  65. * upper half of the base address. Assemble the address, then make sure
  66. * it is valid and we can actually access it.
  67. */
  68. base = si->lfb_base;
  69. if (si->capabilities & VIDEO_CAPABILITY_64BIT_BASE)
  70. base |= (u64)si->ext_lfb_base << 32;
  71. if (!base || (u64)(resource_size_t)base != base) {
  72. printk(KERN_DEBUG "sysfb: inaccessible VRAM base\n");
  73. return -EINVAL;
  74. }
  75. /*
  76. * Don't use lfb_size as IORESOURCE size, since it may contain the
  77. * entire VMEM, and thus require huge mappings. Use just the part we
  78. * need, that is, the part where the framebuffer is located. But verify
  79. * that it does not exceed the advertised VMEM.
  80. * Note that in case of VBE, the lfb_size is shifted by 16 bits for
  81. * historical reasons.
  82. */
  83. size = si->lfb_size;
  84. if (si->orig_video_isVGA == VIDEO_TYPE_VLFB)
  85. size <<= 16;
  86. length = mode->height * mode->stride;
  87. length = PAGE_ALIGN(length);
  88. if (length > size) {
  89. printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n");
  90. return -EINVAL;
  91. }
  92. /* setup IORESOURCE_MEM as framebuffer memory */
  93. memset(&res, 0, sizeof(res));
  94. res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  95. res.name = simplefb_resname;
  96. res.start = base;
  97. res.end = res.start + length - 1;
  98. if (res.end <= res.start)
  99. return -EINVAL;
  100. pd = platform_device_register_resndata(NULL, "simple-framebuffer", 0,
  101. &res, 1, mode, sizeof(*mode));
  102. return PTR_ERR_OR_ZERO(pd);
  103. }