efifb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * Framebuffer driver for EFI/UEFI based system
  3. *
  4. * (c) 2006 Edgar Hucek <gimli@dark-green.com>
  5. * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
  6. *
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/errno.h>
  11. #include <linux/fb.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/screen_info.h>
  14. #include <linux/dmi.h>
  15. #include <linux/pci.h>
  16. #include <video/vga.h>
  17. static bool request_mem_succeeded = false;
  18. static struct fb_var_screeninfo efifb_defined __devinitdata = {
  19. .activate = FB_ACTIVATE_NOW,
  20. .height = -1,
  21. .width = -1,
  22. .right_margin = 32,
  23. .upper_margin = 16,
  24. .lower_margin = 4,
  25. .vsync_len = 4,
  26. .vmode = FB_VMODE_NONINTERLACED,
  27. };
  28. static struct fb_fix_screeninfo efifb_fix __devinitdata = {
  29. .id = "EFI VGA",
  30. .type = FB_TYPE_PACKED_PIXELS,
  31. .accel = FB_ACCEL_NONE,
  32. .visual = FB_VISUAL_TRUECOLOR,
  33. };
  34. enum {
  35. M_I17, /* 17-Inch iMac */
  36. M_I20, /* 20-Inch iMac */
  37. M_I20_SR, /* 20-Inch iMac (Santa Rosa) */
  38. M_I24, /* 24-Inch iMac */
  39. M_I24_8_1, /* 24-Inch iMac, 8,1th gen */
  40. M_I24_10_1, /* 24-Inch iMac, 10,1th gen */
  41. M_I27_11_1, /* 27-Inch iMac, 11,1th gen */
  42. M_MINI, /* Mac Mini */
  43. M_MINI_3_1, /* Mac Mini, 3,1th gen */
  44. M_MINI_4_1, /* Mac Mini, 4,1th gen */
  45. M_MB, /* MacBook */
  46. M_MB_2, /* MacBook, 2nd rev. */
  47. M_MB_3, /* MacBook, 3rd rev. */
  48. M_MB_5_1, /* MacBook, 5th rev. */
  49. M_MB_6_1, /* MacBook, 6th rev. */
  50. M_MB_7_1, /* MacBook, 7th rev. */
  51. M_MB_SR, /* MacBook, 2nd gen, (Santa Rosa) */
  52. M_MBA, /* MacBook Air */
  53. M_MBA_3, /* Macbook Air, 3rd rev */
  54. M_MBP, /* MacBook Pro */
  55. M_MBP_2, /* MacBook Pro 2nd gen */
  56. M_MBP_2_2, /* MacBook Pro 2,2nd gen */
  57. M_MBP_SR, /* MacBook Pro (Santa Rosa) */
  58. M_MBP_4, /* MacBook Pro, 4th gen */
  59. M_MBP_5_1, /* MacBook Pro, 5,1th gen */
  60. M_MBP_5_2, /* MacBook Pro, 5,2th gen */
  61. M_MBP_5_3, /* MacBook Pro, 5,3rd gen */
  62. M_MBP_6_1, /* MacBook Pro, 6,1th gen */
  63. M_MBP_6_2, /* MacBook Pro, 6,2th gen */
  64. M_MBP_7_1, /* MacBook Pro, 7,1th gen */
  65. M_MBP_8_2, /* MacBook Pro, 8,2nd gen */
  66. M_UNKNOWN /* placeholder */
  67. };
  68. #define OVERRIDE_NONE 0x0
  69. #define OVERRIDE_BASE 0x1
  70. #define OVERRIDE_STRIDE 0x2
  71. #define OVERRIDE_HEIGHT 0x4
  72. #define OVERRIDE_WIDTH 0x8
  73. static struct efifb_dmi_info {
  74. char *optname;
  75. unsigned long base;
  76. int stride;
  77. int width;
  78. int height;
  79. int flags;
  80. } dmi_list[] __initdata = {
  81. [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  82. [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE }, /* guess */
  83. [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE },
  84. [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, /* guess */
  85. [M_I24_8_1] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  86. [M_I24_10_1] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080, OVERRIDE_NONE },
  87. [M_I27_11_1] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440, OVERRIDE_NONE },
  88. [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768, OVERRIDE_NONE },
  89. [M_MINI_3_1] = { "mini31", 0x40010000, 1024 * 4, 1024, 768, OVERRIDE_NONE },
  90. [M_MINI_4_1] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  91. [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  92. [M_MB_5_1] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  93. [M_MB_6_1] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  94. [M_MB_7_1] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  95. [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  96. /* 11" Macbook Air 3,1 passes the wrong stride */
  97. [M_MBA_3] = { "mba3", 0, 2048 * 4, 0, 0, OVERRIDE_STRIDE },
  98. [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  99. [M_MBP_2] = { "mbp2", 0, 0, 0, 0, OVERRIDE_NONE }, /* placeholder */
  100. [M_MBP_2_2] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  101. [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
  102. [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  103. [M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
  104. [M_MBP_5_2] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  105. [M_MBP_5_3] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
  106. [M_MBP_6_1] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
  107. [M_MBP_6_2] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050, OVERRIDE_NONE },
  108. [M_MBP_7_1] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
  109. [M_MBP_8_2] = { "mbp82", 0x90010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
  110. [M_UNKNOWN] = { NULL, 0, 0, 0, 0, OVERRIDE_NONE }
  111. };
  112. static int set_system(const struct dmi_system_id *id);
  113. #define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid) \
  114. { set_system, name, { \
  115. DMI_MATCH(DMI_BIOS_VENDOR, vendor), \
  116. DMI_MATCH(DMI_PRODUCT_NAME, name) }, \
  117. &dmi_list[enumid] }
  118. static const struct dmi_system_id dmi_system_table[] __initconst = {
  119. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
  120. /* At least one of these two will be right; maybe both? */
  121. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
  122. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20),
  123. /* At least one of these two will be right; maybe both? */
  124. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24),
  125. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24),
  126. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR),
  127. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1),
  128. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1),
  129. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1),
  130. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI),
  131. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1),
  132. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1),
  133. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB),
  134. /* At least one of these two will be right; maybe both? */
  135. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB),
  136. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB),
  137. /* At least one of these two will be right; maybe both? */
  138. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB),
  139. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB),
  140. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB),
  141. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1),
  142. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1),
  143. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1),
  144. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA),
  145. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir3,1", M_MBA_3),
  146. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP),
  147. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2),
  148. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2),
  149. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2),
  150. EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR),
  151. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR),
  152. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4),
  153. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1),
  154. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2),
  155. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3),
  156. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1),
  157. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2),
  158. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1),
  159. EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro8,2", M_MBP_8_2),
  160. {},
  161. };
  162. #define choose_value(dmivalue, fwvalue, field, flags) ({ \
  163. typeof(fwvalue) _ret_ = fwvalue; \
  164. if ((flags) & (field)) \
  165. _ret_ = dmivalue; \
  166. else if ((fwvalue) == 0) \
  167. _ret_ = dmivalue; \
  168. _ret_; \
  169. })
  170. static int set_system(const struct dmi_system_id *id)
  171. {
  172. struct efifb_dmi_info *info = id->driver_data;
  173. if (info->base == 0 && info->height == 0 && info->width == 0
  174. && info->stride == 0)
  175. return 0;
  176. /* Trust the bootloader over the DMI tables */
  177. if (screen_info.lfb_base == 0) {
  178. #if defined(CONFIG_PCI)
  179. struct pci_dev *dev = NULL;
  180. int found_bar = 0;
  181. #endif
  182. if (info->base) {
  183. screen_info.lfb_base = choose_value(info->base,
  184. screen_info.lfb_base, OVERRIDE_BASE,
  185. info->flags);
  186. #if defined(CONFIG_PCI)
  187. /* make sure that the address in the table is actually
  188. * on a VGA device's PCI BAR */
  189. for_each_pci_dev(dev) {
  190. int i;
  191. if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
  192. continue;
  193. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  194. resource_size_t start, end;
  195. start = pci_resource_start(dev, i);
  196. if (start == 0)
  197. break;
  198. end = pci_resource_end(dev, i);
  199. if (screen_info.lfb_base >= start &&
  200. screen_info.lfb_base < end) {
  201. found_bar = 1;
  202. }
  203. }
  204. }
  205. if (!found_bar)
  206. screen_info.lfb_base = 0;
  207. #endif
  208. }
  209. }
  210. if (screen_info.lfb_base) {
  211. screen_info.lfb_linelength = choose_value(info->stride,
  212. screen_info.lfb_linelength, OVERRIDE_STRIDE,
  213. info->flags);
  214. screen_info.lfb_width = choose_value(info->width,
  215. screen_info.lfb_width, OVERRIDE_WIDTH,
  216. info->flags);
  217. screen_info.lfb_height = choose_value(info->height,
  218. screen_info.lfb_height, OVERRIDE_HEIGHT,
  219. info->flags);
  220. if (screen_info.orig_video_isVGA == 0)
  221. screen_info.orig_video_isVGA = VIDEO_TYPE_EFI;
  222. } else {
  223. screen_info.lfb_linelength = 0;
  224. screen_info.lfb_width = 0;
  225. screen_info.lfb_height = 0;
  226. screen_info.orig_video_isVGA = 0;
  227. return 0;
  228. }
  229. printk(KERN_INFO "efifb: dmi detected %s - framebuffer at 0x%08x "
  230. "(%dx%d, stride %d)\n", id->ident,
  231. screen_info.lfb_base, screen_info.lfb_width,
  232. screen_info.lfb_height, screen_info.lfb_linelength);
  233. return 1;
  234. }
  235. static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
  236. unsigned blue, unsigned transp,
  237. struct fb_info *info)
  238. {
  239. /*
  240. * Set a single color register. The values supplied are
  241. * already rounded down to the hardware's capabilities
  242. * (according to the entries in the `var' structure). Return
  243. * != 0 for invalid regno.
  244. */
  245. if (regno >= info->cmap.len)
  246. return 1;
  247. if (regno < 16) {
  248. red >>= 8;
  249. green >>= 8;
  250. blue >>= 8;
  251. ((u32 *)(info->pseudo_palette))[regno] =
  252. (red << info->var.red.offset) |
  253. (green << info->var.green.offset) |
  254. (blue << info->var.blue.offset);
  255. }
  256. return 0;
  257. }
  258. static void efifb_destroy(struct fb_info *info)
  259. {
  260. if (info->screen_base)
  261. iounmap(info->screen_base);
  262. if (request_mem_succeeded)
  263. release_mem_region(info->apertures->ranges[0].base,
  264. info->apertures->ranges[0].size);
  265. framebuffer_release(info);
  266. }
  267. static struct fb_ops efifb_ops = {
  268. .owner = THIS_MODULE,
  269. .fb_destroy = efifb_destroy,
  270. .fb_setcolreg = efifb_setcolreg,
  271. .fb_fillrect = cfb_fillrect,
  272. .fb_copyarea = cfb_copyarea,
  273. .fb_imageblit = cfb_imageblit,
  274. };
  275. static int __init efifb_setup(char *options)
  276. {
  277. char *this_opt;
  278. int i;
  279. if (!options || !*options)
  280. return 0;
  281. while ((this_opt = strsep(&options, ",")) != NULL) {
  282. if (!*this_opt) continue;
  283. for (i = 0; i < M_UNKNOWN; i++) {
  284. if (!strcmp(this_opt, dmi_list[i].optname) &&
  285. dmi_list[i].base != 0) {
  286. screen_info.lfb_base = dmi_list[i].base;
  287. screen_info.lfb_linelength = dmi_list[i].stride;
  288. screen_info.lfb_width = dmi_list[i].width;
  289. screen_info.lfb_height = dmi_list[i].height;
  290. }
  291. }
  292. if (!strncmp(this_opt, "base:", 5))
  293. screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
  294. else if (!strncmp(this_opt, "stride:", 7))
  295. screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
  296. else if (!strncmp(this_opt, "height:", 7))
  297. screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
  298. else if (!strncmp(this_opt, "width:", 6))
  299. screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
  300. }
  301. return 0;
  302. }
  303. static int __init efifb_probe(struct platform_device *dev)
  304. {
  305. struct fb_info *info;
  306. int err;
  307. unsigned int size_vmode;
  308. unsigned int size_remap;
  309. unsigned int size_total;
  310. if (!screen_info.lfb_depth)
  311. screen_info.lfb_depth = 32;
  312. if (!screen_info.pages)
  313. screen_info.pages = 1;
  314. if (!screen_info.lfb_base) {
  315. printk(KERN_DEBUG "efifb: invalid framebuffer address\n");
  316. return -ENODEV;
  317. }
  318. printk(KERN_INFO "efifb: probing for efifb\n");
  319. /* just assume they're all unset if any are */
  320. if (!screen_info.blue_size) {
  321. screen_info.blue_size = 8;
  322. screen_info.blue_pos = 0;
  323. screen_info.green_size = 8;
  324. screen_info.green_pos = 8;
  325. screen_info.red_size = 8;
  326. screen_info.red_pos = 16;
  327. screen_info.rsvd_size = 8;
  328. screen_info.rsvd_pos = 24;
  329. }
  330. efifb_fix.smem_start = screen_info.lfb_base;
  331. efifb_defined.bits_per_pixel = screen_info.lfb_depth;
  332. efifb_defined.xres = screen_info.lfb_width;
  333. efifb_defined.yres = screen_info.lfb_height;
  334. efifb_fix.line_length = screen_info.lfb_linelength;
  335. /* size_vmode -- that is the amount of memory needed for the
  336. * used video mode, i.e. the minimum amount of
  337. * memory we need. */
  338. size_vmode = efifb_defined.yres * efifb_fix.line_length;
  339. /* size_total -- all video memory we have. Used for
  340. * entries, ressource allocation and bounds
  341. * checking. */
  342. size_total = screen_info.lfb_size;
  343. if (size_total < size_vmode)
  344. size_total = size_vmode;
  345. /* size_remap -- the amount of video memory we are going to
  346. * use for efifb. With modern cards it is no
  347. * option to simply use size_total as that
  348. * wastes plenty of kernel address space. */
  349. size_remap = size_vmode * 2;
  350. if (size_remap > size_total)
  351. size_remap = size_total;
  352. if (size_remap % PAGE_SIZE)
  353. size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE);
  354. efifb_fix.smem_len = size_remap;
  355. if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) {
  356. request_mem_succeeded = true;
  357. } else {
  358. /* We cannot make this fatal. Sometimes this comes from magic
  359. spaces our resource handlers simply don't know about */
  360. printk(KERN_WARNING
  361. "efifb: cannot reserve video memory at 0x%lx\n",
  362. efifb_fix.smem_start);
  363. }
  364. info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
  365. if (!info) {
  366. printk(KERN_ERR "efifb: cannot allocate framebuffer\n");
  367. err = -ENOMEM;
  368. goto err_release_mem;
  369. }
  370. info->pseudo_palette = info->par;
  371. info->par = NULL;
  372. info->apertures = alloc_apertures(1);
  373. if (!info->apertures) {
  374. err = -ENOMEM;
  375. goto err_release_fb;
  376. }
  377. info->apertures->ranges[0].base = efifb_fix.smem_start;
  378. info->apertures->ranges[0].size = size_remap;
  379. info->screen_base = ioremap_wc(efifb_fix.smem_start, efifb_fix.smem_len);
  380. if (!info->screen_base) {
  381. printk(KERN_ERR "efifb: abort, cannot ioremap video memory "
  382. "0x%x @ 0x%lx\n",
  383. efifb_fix.smem_len, efifb_fix.smem_start);
  384. err = -EIO;
  385. goto err_release_fb;
  386. }
  387. printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, "
  388. "using %dk, total %dk\n",
  389. efifb_fix.smem_start, info->screen_base,
  390. size_remap/1024, size_total/1024);
  391. printk(KERN_INFO "efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
  392. efifb_defined.xres, efifb_defined.yres,
  393. efifb_defined.bits_per_pixel, efifb_fix.line_length,
  394. screen_info.pages);
  395. efifb_defined.xres_virtual = efifb_defined.xres;
  396. efifb_defined.yres_virtual = efifb_fix.smem_len /
  397. efifb_fix.line_length;
  398. printk(KERN_INFO "efifb: scrolling: redraw\n");
  399. efifb_defined.yres_virtual = efifb_defined.yres;
  400. /* some dummy values for timing to make fbset happy */
  401. efifb_defined.pixclock = 10000000 / efifb_defined.xres *
  402. 1000 / efifb_defined.yres;
  403. efifb_defined.left_margin = (efifb_defined.xres / 8) & 0xf8;
  404. efifb_defined.hsync_len = (efifb_defined.xres / 8) & 0xf8;
  405. efifb_defined.red.offset = screen_info.red_pos;
  406. efifb_defined.red.length = screen_info.red_size;
  407. efifb_defined.green.offset = screen_info.green_pos;
  408. efifb_defined.green.length = screen_info.green_size;
  409. efifb_defined.blue.offset = screen_info.blue_pos;
  410. efifb_defined.blue.length = screen_info.blue_size;
  411. efifb_defined.transp.offset = screen_info.rsvd_pos;
  412. efifb_defined.transp.length = screen_info.rsvd_size;
  413. printk(KERN_INFO "efifb: %s: "
  414. "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
  415. "Truecolor",
  416. screen_info.rsvd_size,
  417. screen_info.red_size,
  418. screen_info.green_size,
  419. screen_info.blue_size,
  420. screen_info.rsvd_pos,
  421. screen_info.red_pos,
  422. screen_info.green_pos,
  423. screen_info.blue_pos);
  424. efifb_fix.ypanstep = 0;
  425. efifb_fix.ywrapstep = 0;
  426. info->fbops = &efifb_ops;
  427. info->var = efifb_defined;
  428. info->fix = efifb_fix;
  429. info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE;
  430. if ((err = fb_alloc_cmap(&info->cmap, 256, 0)) < 0) {
  431. printk(KERN_ERR "efifb: cannot allocate colormap\n");
  432. goto err_unmap;
  433. }
  434. if ((err = register_framebuffer(info)) < 0) {
  435. printk(KERN_ERR "efifb: cannot register framebuffer\n");
  436. goto err_fb_dealoc;
  437. }
  438. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  439. info->node, info->fix.id);
  440. return 0;
  441. err_fb_dealoc:
  442. fb_dealloc_cmap(&info->cmap);
  443. err_unmap:
  444. iounmap(info->screen_base);
  445. err_release_fb:
  446. framebuffer_release(info);
  447. err_release_mem:
  448. if (request_mem_succeeded)
  449. release_mem_region(efifb_fix.smem_start, size_total);
  450. return err;
  451. }
  452. static struct platform_driver efifb_driver = {
  453. .driver = {
  454. .name = "efifb",
  455. },
  456. };
  457. static struct platform_device efifb_device = {
  458. .name = "efifb",
  459. };
  460. static int __init efifb_init(void)
  461. {
  462. int ret;
  463. char *option = NULL;
  464. dmi_check_system(dmi_system_table);
  465. if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
  466. return -ENODEV;
  467. if (fb_get_options("efifb", &option))
  468. return -ENODEV;
  469. efifb_setup(option);
  470. /* We don't get linelength from UGA Draw Protocol, only from
  471. * EFI Graphics Protocol. So if it's not in DMI, and it's not
  472. * passed in from the user, we really can't use the framebuffer.
  473. */
  474. if (!screen_info.lfb_linelength)
  475. return -ENODEV;
  476. ret = platform_device_register(&efifb_device);
  477. if (ret)
  478. return ret;
  479. /*
  480. * This is not just an optimization. We will interfere
  481. * with a real driver if we get reprobed, so don't allow
  482. * it.
  483. */
  484. ret = platform_driver_probe(&efifb_driver, efifb_probe);
  485. if (ret) {
  486. platform_device_unregister(&efifb_device);
  487. return ret;
  488. }
  489. return ret;
  490. }
  491. module_init(efifb_init);
  492. MODULE_LICENSE("GPL");