aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/efifb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/video/efifb.c')
-rw-r--r--drivers/video/efifb.c303
1 files changed, 30 insertions, 273 deletions
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index 50fe668c6172..7f9ff75d0db2 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -15,6 +15,7 @@
15#include <linux/dmi.h> 15#include <linux/dmi.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <video/vga.h> 17#include <video/vga.h>
18#include <asm/sysfb.h>
18 19
19static bool request_mem_succeeded = false; 20static bool request_mem_succeeded = false;
20 21
@@ -38,223 +39,6 @@ static struct fb_fix_screeninfo efifb_fix = {
38 .visual = FB_VISUAL_TRUECOLOR, 39 .visual = FB_VISUAL_TRUECOLOR,
39}; 40};
40 41
41enum {
42 M_I17, /* 17-Inch iMac */
43 M_I20, /* 20-Inch iMac */
44 M_I20_SR, /* 20-Inch iMac (Santa Rosa) */
45 M_I24, /* 24-Inch iMac */
46 M_I24_8_1, /* 24-Inch iMac, 8,1th gen */
47 M_I24_10_1, /* 24-Inch iMac, 10,1th gen */
48 M_I27_11_1, /* 27-Inch iMac, 11,1th gen */
49 M_MINI, /* Mac Mini */
50 M_MINI_3_1, /* Mac Mini, 3,1th gen */
51 M_MINI_4_1, /* Mac Mini, 4,1th gen */
52 M_MB, /* MacBook */
53 M_MB_2, /* MacBook, 2nd rev. */
54 M_MB_3, /* MacBook, 3rd rev. */
55 M_MB_5_1, /* MacBook, 5th rev. */
56 M_MB_6_1, /* MacBook, 6th rev. */
57 M_MB_7_1, /* MacBook, 7th rev. */
58 M_MB_SR, /* MacBook, 2nd gen, (Santa Rosa) */
59 M_MBA, /* MacBook Air */
60 M_MBA_3, /* Macbook Air, 3rd rev */
61 M_MBP, /* MacBook Pro */
62 M_MBP_2, /* MacBook Pro 2nd gen */
63 M_MBP_2_2, /* MacBook Pro 2,2nd gen */
64 M_MBP_SR, /* MacBook Pro (Santa Rosa) */
65 M_MBP_4, /* MacBook Pro, 4th gen */
66 M_MBP_5_1, /* MacBook Pro, 5,1th gen */
67 M_MBP_5_2, /* MacBook Pro, 5,2th gen */
68 M_MBP_5_3, /* MacBook Pro, 5,3rd gen */
69 M_MBP_6_1, /* MacBook Pro, 6,1th gen */
70 M_MBP_6_2, /* MacBook Pro, 6,2th gen */
71 M_MBP_7_1, /* MacBook Pro, 7,1th gen */
72 M_MBP_8_2, /* MacBook Pro, 8,2nd gen */
73 M_UNKNOWN /* placeholder */
74};
75
76#define OVERRIDE_NONE 0x0
77#define OVERRIDE_BASE 0x1
78#define OVERRIDE_STRIDE 0x2
79#define OVERRIDE_HEIGHT 0x4
80#define OVERRIDE_WIDTH 0x8
81
82static struct efifb_dmi_info {
83 char *optname;
84 unsigned long base;
85 int stride;
86 int width;
87 int height;
88 int flags;
89} dmi_list[] __initdata = {
90 [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
91 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE }, /* guess */
92 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE },
93 [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, /* guess */
94 [M_I24_8_1] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
95 [M_I24_10_1] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080, OVERRIDE_NONE },
96 [M_I27_11_1] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440, OVERRIDE_NONE },
97 [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768, OVERRIDE_NONE },
98 [M_MINI_3_1] = { "mini31", 0x40010000, 1024 * 4, 1024, 768, OVERRIDE_NONE },
99 [M_MINI_4_1] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
100 [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
101 [M_MB_5_1] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
102 [M_MB_6_1] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
103 [M_MB_7_1] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
104 [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
105 /* 11" Macbook Air 3,1 passes the wrong stride */
106 [M_MBA_3] = { "mba3", 0, 2048 * 4, 0, 0, OVERRIDE_STRIDE },
107 [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
108 [M_MBP_2] = { "mbp2", 0, 0, 0, 0, OVERRIDE_NONE }, /* placeholder */
109 [M_MBP_2_2] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
110 [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
111 [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
112 [M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
113 [M_MBP_5_2] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
114 [M_MBP_5_3] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
115 [M_MBP_6_1] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
116 [M_MBP_6_2] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050, OVERRIDE_NONE },
117 [M_MBP_7_1] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
118 [M_MBP_8_2] = { "mbp82", 0x90010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
119 [M_UNKNOWN] = { NULL, 0, 0, 0, 0, OVERRIDE_NONE }
120};
121
122static int set_system(const struct dmi_system_id *id);
123
124#define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid) \
125 { set_system, name, { \
126 DMI_MATCH(DMI_BIOS_VENDOR, vendor), \
127 DMI_MATCH(DMI_PRODUCT_NAME, name) }, \
128 &dmi_list[enumid] }
129
130static const struct dmi_system_id dmi_system_table[] __initconst = {
131 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
132 /* At least one of these two will be right; maybe both? */
133 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
134 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20),
135 /* At least one of these two will be right; maybe both? */
136 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24),
137 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24),
138 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR),
139 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1),
140 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1),
141 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1),
142 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI),
143 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1),
144 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1),
145 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB),
146 /* At least one of these two will be right; maybe both? */
147 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB),
148 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB),
149 /* At least one of these two will be right; maybe both? */
150 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB),
151 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB),
152 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB),
153 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1),
154 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1),
155 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1),
156 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA),
157 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir3,1", M_MBA_3),
158 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP),
159 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2),
160 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2),
161 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2),
162 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR),
163 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR),
164 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4),
165 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1),
166 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2),
167 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3),
168 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1),
169 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2),
170 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1),
171 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro8,2", M_MBP_8_2),
172 {},
173};
174
175#define choose_value(dmivalue, fwvalue, field, flags) ({ \
176 typeof(fwvalue) _ret_ = fwvalue; \
177 if ((flags) & (field)) \
178 _ret_ = dmivalue; \
179 else if ((fwvalue) == 0) \
180 _ret_ = dmivalue; \
181 _ret_; \
182 })
183
184static int set_system(const struct dmi_system_id *id)
185{
186 struct efifb_dmi_info *info = id->driver_data;
187
188 if (info->base == 0 && info->height == 0 && info->width == 0
189 && info->stride == 0)
190 return 0;
191
192 /* Trust the bootloader over the DMI tables */
193 if (screen_info.lfb_base == 0) {
194#if defined(CONFIG_PCI)
195 struct pci_dev *dev = NULL;
196 int found_bar = 0;
197#endif
198 if (info->base) {
199 screen_info.lfb_base = choose_value(info->base,
200 screen_info.lfb_base, OVERRIDE_BASE,
201 info->flags);
202
203#if defined(CONFIG_PCI)
204 /* make sure that the address in the table is actually
205 * on a VGA device's PCI BAR */
206
207 for_each_pci_dev(dev) {
208 int i;
209 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
210 continue;
211 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
212 resource_size_t start, end;
213
214 start = pci_resource_start(dev, i);
215 if (start == 0)
216 break;
217 end = pci_resource_end(dev, i);
218 if (screen_info.lfb_base >= start &&
219 screen_info.lfb_base < end) {
220 found_bar = 1;
221 }
222 }
223 }
224 if (!found_bar)
225 screen_info.lfb_base = 0;
226#endif
227 }
228 }
229 if (screen_info.lfb_base) {
230 screen_info.lfb_linelength = choose_value(info->stride,
231 screen_info.lfb_linelength, OVERRIDE_STRIDE,
232 info->flags);
233 screen_info.lfb_width = choose_value(info->width,
234 screen_info.lfb_width, OVERRIDE_WIDTH,
235 info->flags);
236 screen_info.lfb_height = choose_value(info->height,
237 screen_info.lfb_height, OVERRIDE_HEIGHT,
238 info->flags);
239 if (screen_info.orig_video_isVGA == 0)
240 screen_info.orig_video_isVGA = VIDEO_TYPE_EFI;
241 } else {
242 screen_info.lfb_linelength = 0;
243 screen_info.lfb_width = 0;
244 screen_info.lfb_height = 0;
245 screen_info.orig_video_isVGA = 0;
246 return 0;
247 }
248
249 printk(KERN_INFO "efifb: dmi detected %s - framebuffer at 0x%08x "
250 "(%dx%d, stride %d)\n", id->ident,
251 screen_info.lfb_base, screen_info.lfb_width,
252 screen_info.lfb_height, screen_info.lfb_linelength);
253
254
255 return 1;
256}
257
258static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, 42static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
259 unsigned blue, unsigned transp, 43 unsigned blue, unsigned transp,
260 struct fb_info *info) 44 struct fb_info *info)
@@ -288,6 +72,7 @@ static void efifb_destroy(struct fb_info *info)
288 if (request_mem_succeeded) 72 if (request_mem_succeeded)
289 release_mem_region(info->apertures->ranges[0].base, 73 release_mem_region(info->apertures->ranges[0].base,
290 info->apertures->ranges[0].size); 74 info->apertures->ranges[0].size);
75 fb_dealloc_cmap(&info->cmap);
291 framebuffer_release(info); 76 framebuffer_release(info);
292} 77}
293 78
@@ -312,7 +97,7 @@ void vga_set_default_device(struct pci_dev *pdev)
312 default_vga = pdev; 97 default_vga = pdev;
313} 98}
314 99
315static int __init efifb_setup(char *options) 100static int efifb_setup(char *options)
316{ 101{
317 char *this_opt; 102 char *this_opt;
318 int i; 103 int i;
@@ -323,12 +108,12 @@ static int __init efifb_setup(char *options)
323 if (!*this_opt) continue; 108 if (!*this_opt) continue;
324 109
325 for (i = 0; i < M_UNKNOWN; i++) { 110 for (i = 0; i < M_UNKNOWN; i++) {
326 if (!strcmp(this_opt, dmi_list[i].optname) && 111 if (!strcmp(this_opt, efifb_dmi_list[i].optname) &&
327 dmi_list[i].base != 0) { 112 efifb_dmi_list[i].base != 0) {
328 screen_info.lfb_base = dmi_list[i].base; 113 screen_info.lfb_base = efifb_dmi_list[i].base;
329 screen_info.lfb_linelength = dmi_list[i].stride; 114 screen_info.lfb_linelength = efifb_dmi_list[i].stride;
330 screen_info.lfb_width = dmi_list[i].width; 115 screen_info.lfb_width = efifb_dmi_list[i].width;
331 screen_info.lfb_height = dmi_list[i].height; 116 screen_info.lfb_height = efifb_dmi_list[i].height;
332 } 117 }
333 } 118 }
334 if (!strncmp(this_opt, "base:", 5)) 119 if (!strncmp(this_opt, "base:", 5))
@@ -369,13 +154,28 @@ static int __init efifb_setup(char *options)
369 return 0; 154 return 0;
370} 155}
371 156
372static int __init efifb_probe(struct platform_device *dev) 157static int efifb_probe(struct platform_device *dev)
373{ 158{
374 struct fb_info *info; 159 struct fb_info *info;
375 int err; 160 int err;
376 unsigned int size_vmode; 161 unsigned int size_vmode;
377 unsigned int size_remap; 162 unsigned int size_remap;
378 unsigned int size_total; 163 unsigned int size_total;
164 char *option = NULL;
165
166 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
167 return -ENODEV;
168
169 if (fb_get_options("efifb", &option))
170 return -ENODEV;
171 efifb_setup(option);
172
173 /* We don't get linelength from UGA Draw Protocol, only from
174 * EFI Graphics Protocol. So if it's not in DMI, and it's not
175 * passed in from the user, we really can't use the framebuffer.
176 */
177 if (!screen_info.lfb_linelength)
178 return -ENODEV;
379 179
380 if (!screen_info.lfb_depth) 180 if (!screen_info.lfb_depth)
381 screen_info.lfb_depth = 32; 181 screen_info.lfb_depth = 32;
@@ -539,55 +339,12 @@ err_release_mem:
539} 339}
540 340
541static struct platform_driver efifb_driver = { 341static struct platform_driver efifb_driver = {
542 .driver = { 342 .driver = {
543 .name = "efifb", 343 .name = "efi-framebuffer",
344 .owner = THIS_MODULE,
544 }, 345 },
346 .probe = efifb_probe,
545}; 347};
546 348
547static struct platform_device efifb_device = { 349module_platform_driver(efifb_driver);
548 .name = "efifb",
549};
550
551static int __init efifb_init(void)
552{
553 int ret;
554 char *option = NULL;
555
556 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI ||
557 !(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS))
558 dmi_check_system(dmi_system_table);
559
560 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
561 return -ENODEV;
562
563 if (fb_get_options("efifb", &option))
564 return -ENODEV;
565 efifb_setup(option);
566
567 /* We don't get linelength from UGA Draw Protocol, only from
568 * EFI Graphics Protocol. So if it's not in DMI, and it's not
569 * passed in from the user, we really can't use the framebuffer.
570 */
571 if (!screen_info.lfb_linelength)
572 return -ENODEV;
573
574 ret = platform_device_register(&efifb_device);
575 if (ret)
576 return ret;
577
578 /*
579 * This is not just an optimization. We will interfere
580 * with a real driver if we get reprobed, so don't allow
581 * it.
582 */
583 ret = platform_driver_probe(&efifb_driver, efifb_probe);
584 if (ret) {
585 platform_device_unregister(&efifb_device);
586 return ret;
587 }
588
589 return ret;
590}
591module_init(efifb_init);
592
593MODULE_LICENSE("GPL"); 350MODULE_LICENSE("GPL");