PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/x86/kernel/sysfb_efi.c

https://gitlab.com/webhaikal/SenseiOneplus3
C | 214 lines | 173 code | 16 blank | 25 comment | 27 complexity | af931517eb01e7b8490704399032bd97 MD5 | raw file
  1. /*
  2. * Generic System Framebuffers on x86
  3. * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
  4. *
  5. * EFI Quirks Copyright (c) 2006 Edgar Hucek <gimli@dark-green.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. /*
  13. * EFI Quirks
  14. * Several EFI systems do not correctly advertise their boot framebuffers.
  15. * Hence, we use this static table of known broken machines and fix up the
  16. * information so framebuffer drivers can load corectly.
  17. */
  18. #include <linux/dmi.h>
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/mm.h>
  23. #include <linux/pci.h>
  24. #include <linux/screen_info.h>
  25. #include <video/vga.h>
  26. #include <asm/sysfb.h>
  27. enum {
  28. OVERRIDE_NONE = 0x0,
  29. OVERRIDE_BASE = 0x1,
  30. OVERRIDE_STRIDE = 0x2,
  31. OVERRIDE_HEIGHT = 0x4,
  32. OVERRIDE_WIDTH = 0x8,
  33. };
  34. struct efifb_dmi_info efifb_dmi_list[] = {
  35. [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  36. [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE }, /* guess */
  37. [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE },
  38. [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, /* guess */
  39. [M_I24_8_1] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  40. [M_I24_10_1] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080, OVERRIDE_NONE },
  41. [M_I27_11_1] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440, OVERRIDE_NONE },
  42. [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768, OVERRIDE_NONE },
  43. [M_MINI_3_1] = { "mini31", 0x40010000, 1024 * 4, 1024, 768, OVERRIDE_NONE },
  44. [M_MINI_4_1] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  45. [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  46. [M_MB_5_1] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  47. [M_MB_6_1] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  48. [M_MB_7_1] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  49. [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  50. /* 11" Macbook Air 3,1 passes the wrong stride */
  51. [M_MBA_3] = { "mba3", 0, 2048 * 4, 0, 0, OVERRIDE_STRIDE },
  52. [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  53. [M_MBP_2] = { "mbp2", 0, 0, 0, 0, OVERRIDE_NONE }, /* placeholder */
  54. [M_MBP_2_2] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  55. [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
  56. [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  57. [M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
  58. [M_MBP_5_2] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  59. [M_MBP_5_3] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
  60. [M_MBP_6_1] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  61. [M_MBP_6_2] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050, OVERRIDE_NONE },
  62. [M_MBP_7_1] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  63. [M_MBP_8_2] = { "mbp82", 0x90010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  64. [M_UNKNOWN] = { NULL, 0, 0, 0, 0, OVERRIDE_NONE }
  65. };
  66. #define choose_value(dmivalue, fwvalue, field, flags) ({ \
  67. typeof(fwvalue) _ret_ = fwvalue; \
  68. if ((flags) & (field)) \
  69. _ret_ = dmivalue; \
  70. else if ((fwvalue) == 0) \
  71. _ret_ = dmivalue; \
  72. _ret_; \
  73. })
  74. static int __init efifb_set_system(const struct dmi_system_id *id)
  75. {
  76. struct efifb_dmi_info *info = id->driver_data;
  77. if (info->base == 0 && info->height == 0 && info->width == 0 &&
  78. info->stride == 0)
  79. return 0;
  80. /* Trust the bootloader over the DMI tables */
  81. if (screen_info.lfb_base == 0) {
  82. #if defined(CONFIG_PCI)
  83. struct pci_dev *dev = NULL;
  84. int found_bar = 0;
  85. #endif
  86. if (info->base) {
  87. screen_info.lfb_base = choose_value(info->base,
  88. screen_info.lfb_base, OVERRIDE_BASE,
  89. info->flags);
  90. #if defined(CONFIG_PCI)
  91. /* make sure that the address in the table is actually
  92. * on a VGA device's PCI BAR */
  93. for_each_pci_dev(dev) {
  94. int i;
  95. if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
  96. continue;
  97. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  98. resource_size_t start, end;
  99. start = pci_resource_start(dev, i);
  100. if (start == 0)
  101. break;
  102. end = pci_resource_end(dev, i);
  103. if (screen_info.lfb_base >= start &&
  104. screen_info.lfb_base < end) {
  105. found_bar = 1;
  106. }
  107. }
  108. }
  109. if (!found_bar)
  110. screen_info.lfb_base = 0;
  111. #endif
  112. }
  113. }
  114. if (screen_info.lfb_base) {
  115. screen_info.lfb_linelength = choose_value(info->stride,
  116. screen_info.lfb_linelength, OVERRIDE_STRIDE,
  117. info->flags);
  118. screen_info.lfb_width = choose_value(info->width,
  119. screen_info.lfb_width, OVERRIDE_WIDTH,
  120. info->flags);
  121. screen_info.lfb_height = choose_value(info->height,
  122. screen_info.lfb_height, OVERRIDE_HEIGHT,
  123. info->flags);
  124. if (screen_info.orig_video_isVGA == 0)
  125. screen_info.orig_video_isVGA = VIDEO_TYPE_EFI;
  126. } else {
  127. screen_info.lfb_linelength = 0;
  128. screen_info.lfb_width = 0;
  129. screen_info.lfb_height = 0;
  130. screen_info.orig_video_isVGA = 0;
  131. return 0;
  132. }
  133. printk(KERN_INFO "efifb: dmi detected %s - framebuffer at 0x%08x "
  134. "(%dx%d, stride %d)\n", id->ident,
  135. screen_info.lfb_base, screen_info.lfb_width,
  136. screen_info.lfb_height, screen_info.lfb_linelength);
  137. return 1;
  138. }
  139. #define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid) \
  140. { \
  141. efifb_set_system, \
  142. name, \
  143. { \
  144. DMI_MATCH(DMI_BIOS_VENDOR, vendor), \
  145. DMI_MATCH(DMI_PRODUCT_NAME, name) \
  146. }, \
  147. &efifb_dmi_list[enumid] \
  148. }
  149. static const struct dmi_system_id efifb_dmi_system_table[] __initconst = {
  150. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
  151. /* At least one of these two will be right; maybe both? */
  152. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
  153. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20),
  154. /* At least one of these two will be right; maybe both? */
  155. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24),
  156. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24),
  157. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR),
  158. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1),
  159. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1),
  160. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1),
  161. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI),
  162. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1),
  163. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1),
  164. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB),
  165. /* At least one of these two will be right; maybe both? */
  166. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB),
  167. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB),
  168. /* At least one of these two will be right; maybe both? */
  169. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB),
  170. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB),
  171. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB),
  172. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1),
  173. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1),
  174. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1),
  175. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA),
  176. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir3,1", M_MBA_3),
  177. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP),
  178. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2),
  179. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2),
  180. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2),
  181. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR),
  182. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR),
  183. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4),
  184. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1),
  185. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2),
  186. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3),
  187. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1),
  188. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2),
  189. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1),
  190. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro8,2", M_MBP_8_2),
  191. {},
  192. };
  193. __init void sysfb_apply_efi_quirks(void)
  194. {
  195. if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI ||
  196. !(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS))
  197. dmi_check_system(efifb_dmi_system_table);
  198. }