2 * Generic System Framebuffers on x86
3 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
5 * EFI Quirks Copyright (c) 2006 Edgar Hucek <gimli@dark-green.com>
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)
15 * Several EFI systems do not correctly advertise their boot framebuffers.
16 * Hence, we use this static table of known broken machines and fix up the
17 * information so framebuffer drivers can load corectly.
20 #include <linux/dmi.h>
21 #include <linux/err.h>
22 #include <linux/efi.h>
23 #include <linux/init.h>
24 #include <linux/kernel.h>
26 #include <linux/pci.h>
27 #include <linux/screen_info.h>
28 #include <video/vga.h>
31 #include <asm/sysfb.h>
36 OVERRIDE_STRIDE
= 0x2,
37 OVERRIDE_HEIGHT
= 0x4,
41 struct efifb_dmi_info efifb_dmi_list
[] = {
42 [M_I17
] = { "i17", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE
},
43 [M_I20
] = { "i20", 0x80010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE
}, /* guess */
44 [M_I20_SR
] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE
},
45 [M_I24
] = { "i24", 0x80010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE
}, /* guess */
46 [M_I24_8_1
] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE
},
47 [M_I24_10_1
] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080, OVERRIDE_NONE
},
48 [M_I27_11_1
] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440, OVERRIDE_NONE
},
49 [M_MINI
]= { "mini", 0x80000000, 2048 * 4, 1024, 768, OVERRIDE_NONE
},
50 [M_MINI_3_1
] = { "mini31", 0x40010000, 1024 * 4, 1024, 768, OVERRIDE_NONE
},
51 [M_MINI_4_1
] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE
},
52 [M_MB
] = { "macbook", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE
},
53 [M_MB_5_1
] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE
},
54 [M_MB_6_1
] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE
},
55 [M_MB_7_1
] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE
},
56 [M_MBA
] = { "mba", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE
},
57 /* 11" Macbook Air 3,1 passes the wrong stride */
58 [M_MBA_3
] = { "mba3", 0, 2048 * 4, 0, 0, OVERRIDE_STRIDE
},
59 [M_MBP
] = { "mbp", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE
},
60 [M_MBP_2
] = { "mbp2", 0, 0, 0, 0, OVERRIDE_NONE
}, /* placeholder */
61 [M_MBP_2_2
] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE
},
62 [M_MBP_SR
] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900, OVERRIDE_NONE
},
63 [M_MBP_4
] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE
},
64 [M_MBP_5_1
] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE
},
65 [M_MBP_5_2
] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE
},
66 [M_MBP_5_3
] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE
},
67 [M_MBP_6_1
] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200, OVERRIDE_NONE
},
68 [M_MBP_6_2
] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050, OVERRIDE_NONE
},
69 [M_MBP_7_1
] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800, OVERRIDE_NONE
},
70 [M_MBP_8_2
] = { "mbp82", 0x90010000, 1472 * 4, 1440, 900, OVERRIDE_NONE
},
71 [M_UNKNOWN
] = { NULL
, 0, 0, 0, 0, OVERRIDE_NONE
}
74 void efifb_setup_from_dmi(struct screen_info
*si
, const char *opt
)
78 for (i
= 0; i
< M_UNKNOWN
; i
++) {
79 if (efifb_dmi_list
[i
].base
!= 0 &&
80 !strcmp(opt
, efifb_dmi_list
[i
].optname
)) {
81 si
->lfb_base
= efifb_dmi_list
[i
].base
;
82 si
->lfb_linelength
= efifb_dmi_list
[i
].stride
;
83 si
->lfb_width
= efifb_dmi_list
[i
].width
;
84 si
->lfb_height
= efifb_dmi_list
[i
].height
;
89 #define choose_value(dmivalue, fwvalue, field, flags) ({ \
90 typeof(fwvalue) _ret_ = fwvalue; \
91 if ((flags) & (field)) \
93 else if ((fwvalue) == 0) \
98 static int __init
efifb_set_system(const struct dmi_system_id
*id
)
100 struct efifb_dmi_info
*info
= id
->driver_data
;
102 if (info
->base
== 0 && info
->height
== 0 && info
->width
== 0 &&
106 /* Trust the bootloader over the DMI tables */
107 if (screen_info
.lfb_base
== 0) {
108 #if defined(CONFIG_PCI)
109 struct pci_dev
*dev
= NULL
;
113 screen_info
.lfb_base
= choose_value(info
->base
,
114 screen_info
.lfb_base
, OVERRIDE_BASE
,
117 #if defined(CONFIG_PCI)
118 /* make sure that the address in the table is actually
119 * on a VGA device's PCI BAR */
121 for_each_pci_dev(dev
) {
123 if ((dev
->class >> 8) != PCI_CLASS_DISPLAY_VGA
)
125 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
126 resource_size_t start
, end
;
129 flags
= pci_resource_flags(dev
, i
);
130 if (!(flags
& IORESOURCE_MEM
))
133 if (flags
& IORESOURCE_UNSET
)
136 if (pci_resource_len(dev
, i
) == 0)
139 start
= pci_resource_start(dev
, i
);
140 end
= pci_resource_end(dev
, i
);
141 if (screen_info
.lfb_base
>= start
&&
142 screen_info
.lfb_base
< end
) {
149 screen_info
.lfb_base
= 0;
153 if (screen_info
.lfb_base
) {
154 screen_info
.lfb_linelength
= choose_value(info
->stride
,
155 screen_info
.lfb_linelength
, OVERRIDE_STRIDE
,
157 screen_info
.lfb_width
= choose_value(info
->width
,
158 screen_info
.lfb_width
, OVERRIDE_WIDTH
,
160 screen_info
.lfb_height
= choose_value(info
->height
,
161 screen_info
.lfb_height
, OVERRIDE_HEIGHT
,
163 if (screen_info
.orig_video_isVGA
== 0)
164 screen_info
.orig_video_isVGA
= VIDEO_TYPE_EFI
;
166 screen_info
.lfb_linelength
= 0;
167 screen_info
.lfb_width
= 0;
168 screen_info
.lfb_height
= 0;
169 screen_info
.orig_video_isVGA
= 0;
173 printk(KERN_INFO
"efifb: dmi detected %s - framebuffer at 0x%08x "
174 "(%dx%d, stride %d)\n", id
->ident
,
175 screen_info
.lfb_base
, screen_info
.lfb_width
,
176 screen_info
.lfb_height
, screen_info
.lfb_linelength
);
181 #define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid) \
186 DMI_MATCH(DMI_BIOS_VENDOR, vendor), \
187 DMI_MATCH(DMI_PRODUCT_NAME, name) \
189 &efifb_dmi_list[enumid] \
192 static const struct dmi_system_id efifb_dmi_system_table
[] __initconst
= {
193 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17
),
194 /* At least one of these two will be right; maybe both? */
195 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20
),
196 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20
),
197 /* At least one of these two will be right; maybe both? */
198 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24
),
199 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24
),
200 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR
),
201 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1
),
202 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1
),
203 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1
),
204 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI
),
205 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1
),
206 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1
),
207 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB
),
208 /* At least one of these two will be right; maybe both? */
209 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB
),
210 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB
),
211 /* At least one of these two will be right; maybe both? */
212 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB
),
213 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB
),
214 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB
),
215 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1
),
216 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1
),
217 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1
),
218 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA
),
219 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir3,1", M_MBA_3
),
220 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP
),
221 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2
),
222 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2
),
223 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2
),
224 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR
),
225 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR
),
226 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4
),
227 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1
),
228 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2
),
229 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3
),
230 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1
),
231 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2
),
232 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1
),
233 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro8,2", M_MBP_8_2
),
237 __init
void sysfb_apply_efi_quirks(void)
239 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_EFI
||
240 !(screen_info
.capabilities
& VIDEO_CAPABILITY_SKIP_QUIRKS
))
241 dmi_check_system(efifb_dmi_system_table
);