xref: /linux/drivers/firmware/efi/sysfb_efi.c (revision 15d27b15de965043d6f8e23bc7f34386fcd1a772)
1d391c582SJavier Martinez Canillas // SPDX-License-Identifier: GPL-2.0-or-later
2d391c582SJavier Martinez Canillas /*
38633ef82SJavier Martinez Canillas  * Generic System Framebuffers
4d391c582SJavier Martinez Canillas  * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
5d391c582SJavier Martinez Canillas  *
6d391c582SJavier Martinez Canillas  * EFI Quirks Copyright (c) 2006 Edgar Hucek <gimli@dark-green.com>
7d391c582SJavier Martinez Canillas  */
8d391c582SJavier Martinez Canillas 
9d391c582SJavier Martinez Canillas /*
10d391c582SJavier Martinez Canillas  * EFI Quirks
11d391c582SJavier Martinez Canillas  * Several EFI systems do not correctly advertise their boot framebuffers.
12d391c582SJavier Martinez Canillas  * Hence, we use this static table of known broken machines and fix up the
13d391c582SJavier Martinez Canillas  * information so framebuffer drivers can load correctly.
14d391c582SJavier Martinez Canillas  */
15d391c582SJavier Martinez Canillas 
16d391c582SJavier Martinez Canillas #include <linux/dmi.h>
17d391c582SJavier Martinez Canillas #include <linux/err.h>
18d391c582SJavier Martinez Canillas #include <linux/efi.h>
19d391c582SJavier Martinez Canillas #include <linux/init.h>
20d391c582SJavier Martinez Canillas #include <linux/kernel.h>
21d391c582SJavier Martinez Canillas #include <linux/mm.h>
228633ef82SJavier Martinez Canillas #include <linux/of_address.h>
23d391c582SJavier Martinez Canillas #include <linux/pci.h>
248633ef82SJavier Martinez Canillas #include <linux/platform_device.h>
25d391c582SJavier Martinez Canillas #include <linux/screen_info.h>
26d391c582SJavier Martinez Canillas #include <linux/sysfb.h>
27d391c582SJavier Martinez Canillas #include <video/vga.h>
28d391c582SJavier Martinez Canillas 
29d391c582SJavier Martinez Canillas #include <asm/efi.h>
30d391c582SJavier Martinez Canillas 
31d391c582SJavier Martinez Canillas enum {
32d391c582SJavier Martinez Canillas 	OVERRIDE_NONE = 0x0,
33d391c582SJavier Martinez Canillas 	OVERRIDE_BASE = 0x1,
34d391c582SJavier Martinez Canillas 	OVERRIDE_STRIDE = 0x2,
35d391c582SJavier Martinez Canillas 	OVERRIDE_HEIGHT = 0x4,
36d391c582SJavier Martinez Canillas 	OVERRIDE_WIDTH = 0x8,
37d391c582SJavier Martinez Canillas };
38d391c582SJavier Martinez Canillas 
39d391c582SJavier Martinez Canillas struct efifb_dmi_info efifb_dmi_list[] = {
40d391c582SJavier Martinez Canillas 	[M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
41d391c582SJavier Martinez Canillas 	[M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE }, /* guess */
42d391c582SJavier Martinez Canillas 	[M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE },
43d391c582SJavier Martinez Canillas 	[M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, /* guess */
44d391c582SJavier Martinez Canillas 	[M_I24_8_1] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
45d391c582SJavier Martinez Canillas 	[M_I24_10_1] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080, OVERRIDE_NONE },
46d391c582SJavier Martinez Canillas 	[M_I27_11_1] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440, OVERRIDE_NONE },
47d391c582SJavier Martinez Canillas 	[M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768, OVERRIDE_NONE },
48d391c582SJavier Martinez Canillas 	[M_MINI_3_1] = { "mini31", 0x40010000, 1024 * 4, 1024, 768, OVERRIDE_NONE },
49d391c582SJavier Martinez Canillas 	[M_MINI_4_1] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
50d391c582SJavier Martinez Canillas 	[M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
51d391c582SJavier Martinez Canillas 	[M_MB_5_1] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
52d391c582SJavier Martinez Canillas 	[M_MB_6_1] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
53d391c582SJavier Martinez Canillas 	[M_MB_7_1] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
54d391c582SJavier Martinez Canillas 	[M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
55d391c582SJavier Martinez Canillas 	/* 11" Macbook Air 3,1 passes the wrong stride */
56d391c582SJavier Martinez Canillas 	[M_MBA_3] = { "mba3", 0, 2048 * 4, 0, 0, OVERRIDE_STRIDE },
57d391c582SJavier Martinez Canillas 	[M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
58d391c582SJavier Martinez Canillas 	[M_MBP_2] = { "mbp2", 0, 0, 0, 0, OVERRIDE_NONE }, /* placeholder */
59d391c582SJavier Martinez Canillas 	[M_MBP_2_2] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
60d391c582SJavier Martinez Canillas 	[M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
61d391c582SJavier Martinez Canillas 	[M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
62d391c582SJavier Martinez Canillas 	[M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
63d391c582SJavier Martinez Canillas 	[M_MBP_5_2] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
64d391c582SJavier Martinez Canillas 	[M_MBP_5_3] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE },
65d391c582SJavier Martinez Canillas 	[M_MBP_6_1] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200, OVERRIDE_NONE },
66d391c582SJavier Martinez Canillas 	[M_MBP_6_2] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050, OVERRIDE_NONE },
67d391c582SJavier Martinez Canillas 	[M_MBP_7_1] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800, OVERRIDE_NONE },
68d391c582SJavier Martinez Canillas 	[M_MBP_8_2] = { "mbp82", 0x90010000, 1472 * 4, 1440, 900, OVERRIDE_NONE },
69d391c582SJavier Martinez Canillas 	[M_UNKNOWN] = { NULL, 0, 0, 0, 0, OVERRIDE_NONE }
70d391c582SJavier Martinez Canillas };
71d391c582SJavier Martinez Canillas 
72d391c582SJavier Martinez Canillas void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
73d391c582SJavier Martinez Canillas {
74d391c582SJavier Martinez Canillas 	int i;
75d391c582SJavier Martinez Canillas 
76d391c582SJavier Martinez Canillas 	for (i = 0; i < M_UNKNOWN; i++) {
77d391c582SJavier Martinez Canillas 		if (efifb_dmi_list[i].base != 0 &&
78d391c582SJavier Martinez Canillas 		    !strcmp(opt, efifb_dmi_list[i].optname)) {
79d391c582SJavier Martinez Canillas 			si->lfb_base = efifb_dmi_list[i].base;
80d391c582SJavier Martinez Canillas 			si->lfb_linelength = efifb_dmi_list[i].stride;
81d391c582SJavier Martinez Canillas 			si->lfb_width = efifb_dmi_list[i].width;
82d391c582SJavier Martinez Canillas 			si->lfb_height = efifb_dmi_list[i].height;
83d391c582SJavier Martinez Canillas 		}
84d391c582SJavier Martinez Canillas 	}
85d391c582SJavier Martinez Canillas }
86d391c582SJavier Martinez Canillas 
87d391c582SJavier Martinez Canillas #define choose_value(dmivalue, fwvalue, field, flags) ({	\
88d391c582SJavier Martinez Canillas 		typeof(fwvalue) _ret_ = fwvalue;		\
89d391c582SJavier Martinez Canillas 		if ((flags) & (field))				\
90d391c582SJavier Martinez Canillas 			_ret_ = dmivalue;			\
91d391c582SJavier Martinez Canillas 		else if ((fwvalue) == 0)			\
92d391c582SJavier Martinez Canillas 			_ret_ = dmivalue;			\
93d391c582SJavier Martinez Canillas 		_ret_;						\
94d391c582SJavier Martinez Canillas 	})
95d391c582SJavier Martinez Canillas 
96d391c582SJavier Martinez Canillas static int __init efifb_set_system(const struct dmi_system_id *id)
97d391c582SJavier Martinez Canillas {
98d391c582SJavier Martinez Canillas 	struct efifb_dmi_info *info = id->driver_data;
99d391c582SJavier Martinez Canillas 
100d391c582SJavier Martinez Canillas 	if (info->base == 0 && info->height == 0 && info->width == 0 &&
101d391c582SJavier Martinez Canillas 	    info->stride == 0)
102d391c582SJavier Martinez Canillas 		return 0;
103d391c582SJavier Martinez Canillas 
104d391c582SJavier Martinez Canillas 	/* Trust the bootloader over the DMI tables */
105d391c582SJavier Martinez Canillas 	if (screen_info.lfb_base == 0) {
106d391c582SJavier Martinez Canillas #if defined(CONFIG_PCI)
107d391c582SJavier Martinez Canillas 		struct pci_dev *dev = NULL;
108d391c582SJavier Martinez Canillas 		int found_bar = 0;
109d391c582SJavier Martinez Canillas #endif
110d391c582SJavier Martinez Canillas 		if (info->base) {
111d391c582SJavier Martinez Canillas 			screen_info.lfb_base = choose_value(info->base,
112d391c582SJavier Martinez Canillas 				screen_info.lfb_base, OVERRIDE_BASE,
113d391c582SJavier Martinez Canillas 				info->flags);
114d391c582SJavier Martinez Canillas 
115d391c582SJavier Martinez Canillas #if defined(CONFIG_PCI)
116d391c582SJavier Martinez Canillas 			/* make sure that the address in the table is actually
117d391c582SJavier Martinez Canillas 			 * on a VGA device's PCI BAR */
118d391c582SJavier Martinez Canillas 
119d391c582SJavier Martinez Canillas 			for_each_pci_dev(dev) {
120d391c582SJavier Martinez Canillas 				int i;
121d391c582SJavier Martinez Canillas 				if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
122d391c582SJavier Martinez Canillas 					continue;
123d391c582SJavier Martinez Canillas 				for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
124d391c582SJavier Martinez Canillas 					resource_size_t start, end;
125d391c582SJavier Martinez Canillas 					unsigned long flags;
126d391c582SJavier Martinez Canillas 
127d391c582SJavier Martinez Canillas 					flags = pci_resource_flags(dev, i);
128d391c582SJavier Martinez Canillas 					if (!(flags & IORESOURCE_MEM))
129d391c582SJavier Martinez Canillas 						continue;
130d391c582SJavier Martinez Canillas 
131d391c582SJavier Martinez Canillas 					if (flags & IORESOURCE_UNSET)
132d391c582SJavier Martinez Canillas 						continue;
133d391c582SJavier Martinez Canillas 
134d391c582SJavier Martinez Canillas 					if (pci_resource_len(dev, i) == 0)
135d391c582SJavier Martinez Canillas 						continue;
136d391c582SJavier Martinez Canillas 
137d391c582SJavier Martinez Canillas 					start = pci_resource_start(dev, i);
138d391c582SJavier Martinez Canillas 					end = pci_resource_end(dev, i);
139d391c582SJavier Martinez Canillas 					if (screen_info.lfb_base >= start &&
140d391c582SJavier Martinez Canillas 					    screen_info.lfb_base < end) {
141d391c582SJavier Martinez Canillas 						found_bar = 1;
142d391c582SJavier Martinez Canillas 						break;
143d391c582SJavier Martinez Canillas 					}
144d391c582SJavier Martinez Canillas 				}
145d391c582SJavier Martinez Canillas 			}
146d391c582SJavier Martinez Canillas 			if (!found_bar)
147d391c582SJavier Martinez Canillas 				screen_info.lfb_base = 0;
148d391c582SJavier Martinez Canillas #endif
149d391c582SJavier Martinez Canillas 		}
150d391c582SJavier Martinez Canillas 	}
151d391c582SJavier Martinez Canillas 	if (screen_info.lfb_base) {
152d391c582SJavier Martinez Canillas 		screen_info.lfb_linelength = choose_value(info->stride,
153d391c582SJavier Martinez Canillas 			screen_info.lfb_linelength, OVERRIDE_STRIDE,
154d391c582SJavier Martinez Canillas 			info->flags);
155d391c582SJavier Martinez Canillas 		screen_info.lfb_width = choose_value(info->width,
156d391c582SJavier Martinez Canillas 			screen_info.lfb_width, OVERRIDE_WIDTH,
157d391c582SJavier Martinez Canillas 			info->flags);
158d391c582SJavier Martinez Canillas 		screen_info.lfb_height = choose_value(info->height,
159d391c582SJavier Martinez Canillas 			screen_info.lfb_height, OVERRIDE_HEIGHT,
160d391c582SJavier Martinez Canillas 			info->flags);
161d391c582SJavier Martinez Canillas 		if (screen_info.orig_video_isVGA == 0)
162d391c582SJavier Martinez Canillas 			screen_info.orig_video_isVGA = VIDEO_TYPE_EFI;
163d391c582SJavier Martinez Canillas 	} else {
164d391c582SJavier Martinez Canillas 		screen_info.lfb_linelength = 0;
165d391c582SJavier Martinez Canillas 		screen_info.lfb_width = 0;
166d391c582SJavier Martinez Canillas 		screen_info.lfb_height = 0;
167d391c582SJavier Martinez Canillas 		screen_info.orig_video_isVGA = 0;
168d391c582SJavier Martinez Canillas 		return 0;
169d391c582SJavier Martinez Canillas 	}
170d391c582SJavier Martinez Canillas 
171d391c582SJavier Martinez Canillas 	printk(KERN_INFO "efifb: dmi detected %s - framebuffer at 0x%08x "
172d391c582SJavier Martinez Canillas 			 "(%dx%d, stride %d)\n", id->ident,
173d391c582SJavier Martinez Canillas 			 screen_info.lfb_base, screen_info.lfb_width,
174d391c582SJavier Martinez Canillas 			 screen_info.lfb_height, screen_info.lfb_linelength);
175d391c582SJavier Martinez Canillas 
176d391c582SJavier Martinez Canillas 	return 1;
177d391c582SJavier Martinez Canillas }
178d391c582SJavier Martinez Canillas 
179d391c582SJavier Martinez Canillas #define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid)		\
180d391c582SJavier Martinez Canillas 	{							\
181d391c582SJavier Martinez Canillas 		efifb_set_system,				\
182d391c582SJavier Martinez Canillas 		name,						\
183d391c582SJavier Martinez Canillas 		{						\
184d391c582SJavier Martinez Canillas 			DMI_MATCH(DMI_BIOS_VENDOR, vendor),	\
185d391c582SJavier Martinez Canillas 			DMI_MATCH(DMI_PRODUCT_NAME, name)	\
186d391c582SJavier Martinez Canillas 		},						\
187d391c582SJavier Martinez Canillas 		&efifb_dmi_list[enumid]				\
188d391c582SJavier Martinez Canillas 	}
189d391c582SJavier Martinez Canillas 
190d391c582SJavier Martinez Canillas static const struct dmi_system_id efifb_dmi_system_table[] __initconst = {
191d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
192d391c582SJavier Martinez Canillas 	/* At least one of these two will be right; maybe both? */
193d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
194d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20),
195d391c582SJavier Martinez Canillas 	/* At least one of these two will be right; maybe both? */
196d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24),
197d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24),
198d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR),
199d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1),
200d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1),
201d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1),
202d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI),
203d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1),
204d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1),
205d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB),
206d391c582SJavier Martinez Canillas 	/* At least one of these two will be right; maybe both? */
207d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB),
208d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB),
209d391c582SJavier Martinez Canillas 	/* At least one of these two will be right; maybe both? */
210d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB),
211d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB),
212d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB),
213d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1),
214d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1),
215d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1),
216d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA),
217d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir3,1", M_MBA_3),
218d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP),
219d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2),
220d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2),
221d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2),
222d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR),
223d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR),
224d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4),
225d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1),
226d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2),
227d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3),
228d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1),
229d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2),
230d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1),
231d391c582SJavier Martinez Canillas 	EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro8,2", M_MBP_8_2),
232d391c582SJavier Martinez Canillas 	{},
233d391c582SJavier Martinez Canillas };
234d391c582SJavier Martinez Canillas 
235d391c582SJavier Martinez Canillas /*
236d391c582SJavier Martinez Canillas  * Some devices have a portrait LCD but advertise a landscape resolution (and
237d391c582SJavier Martinez Canillas  * pitch). We simply swap width and height for these devices so that we can
238d391c582SJavier Martinez Canillas  * correctly deal with some of them coming with multiple resolutions.
239d391c582SJavier Martinez Canillas  */
240d391c582SJavier Martinez Canillas static const struct dmi_system_id efifb_dmi_swap_width_height[] __initconst = {
241d391c582SJavier Martinez Canillas 	{
242d391c582SJavier Martinez Canillas 		/*
243d391c582SJavier Martinez Canillas 		 * Lenovo MIIX310-10ICR, only some batches have the troublesome
244d391c582SJavier Martinez Canillas 		 * 800x1280 portrait screen. Luckily the portrait version has
245d391c582SJavier Martinez Canillas 		 * its own BIOS version, so we match on that.
246d391c582SJavier Martinez Canillas 		 */
247d391c582SJavier Martinez Canillas 		.matches = {
248d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
249d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10ICR"),
250d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1HCN44WW"),
251d391c582SJavier Martinez Canillas 		},
252d391c582SJavier Martinez Canillas 	},
253d391c582SJavier Martinez Canillas 	{
254d391c582SJavier Martinez Canillas 		/* Lenovo MIIX 320-10ICR with 800x1280 portrait screen */
255d391c582SJavier Martinez Canillas 		.matches = {
256d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
257d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_PRODUCT_VERSION,
258d391c582SJavier Martinez Canillas 					"Lenovo MIIX 320-10ICR"),
259d391c582SJavier Martinez Canillas 		},
260d391c582SJavier Martinez Canillas 	},
261d391c582SJavier Martinez Canillas 	{
262d391c582SJavier Martinez Canillas 		/* Lenovo D330 with 800x1280 or 1200x1920 portrait screen */
263d391c582SJavier Martinez Canillas 		.matches = {
264d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
265d391c582SJavier Martinez Canillas 			DMI_EXACT_MATCH(DMI_PRODUCT_VERSION,
266d391c582SJavier Martinez Canillas 					"Lenovo ideapad D330-10IGM"),
267d391c582SJavier Martinez Canillas 		},
268d391c582SJavier Martinez Canillas 	},
269d391c582SJavier Martinez Canillas 	{},
270d391c582SJavier Martinez Canillas };
271d391c582SJavier Martinez Canillas 
2728633ef82SJavier Martinez Canillas static bool efifb_overlaps_pci_range(const struct of_pci_range *range)
2738633ef82SJavier Martinez Canillas {
2748633ef82SJavier Martinez Canillas 	u64 fb_base = screen_info.lfb_base;
2758633ef82SJavier Martinez Canillas 
2768633ef82SJavier Martinez Canillas 	if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
2778633ef82SJavier Martinez Canillas 		fb_base |= (u64)(unsigned long)screen_info.ext_lfb_base << 32;
2788633ef82SJavier Martinez Canillas 
2798633ef82SJavier Martinez Canillas 	return fb_base >= range->cpu_addr &&
2808633ef82SJavier Martinez Canillas 	       fb_base < (range->cpu_addr + range->size);
2818633ef82SJavier Martinez Canillas }
2828633ef82SJavier Martinez Canillas 
2838633ef82SJavier Martinez Canillas static struct device_node *find_pci_overlap_node(void)
2848633ef82SJavier Martinez Canillas {
2858633ef82SJavier Martinez Canillas 	struct device_node *np;
2868633ef82SJavier Martinez Canillas 
2878633ef82SJavier Martinez Canillas 	for_each_node_by_type(np, "pci") {
2888633ef82SJavier Martinez Canillas 		struct of_pci_range_parser parser;
2898633ef82SJavier Martinez Canillas 		struct of_pci_range range;
2908633ef82SJavier Martinez Canillas 		int err;
2918633ef82SJavier Martinez Canillas 
2928633ef82SJavier Martinez Canillas 		err = of_pci_range_parser_init(&parser, np);
2938633ef82SJavier Martinez Canillas 		if (err) {
2948633ef82SJavier Martinez Canillas 			pr_warn("of_pci_range_parser_init() failed: %d\n", err);
2958633ef82SJavier Martinez Canillas 			continue;
2968633ef82SJavier Martinez Canillas 		}
2978633ef82SJavier Martinez Canillas 
2988633ef82SJavier Martinez Canillas 		for_each_of_pci_range(&parser, &range)
2998633ef82SJavier Martinez Canillas 			if (efifb_overlaps_pci_range(&range))
3008633ef82SJavier Martinez Canillas 				return np;
3018633ef82SJavier Martinez Canillas 	}
3028633ef82SJavier Martinez Canillas 	return NULL;
3038633ef82SJavier Martinez Canillas }
3048633ef82SJavier Martinez Canillas 
3058633ef82SJavier Martinez Canillas /*
3068633ef82SJavier Martinez Canillas  * If the efifb framebuffer is backed by a PCI graphics controller, we have
3078633ef82SJavier Martinez Canillas  * to ensure that this relation is expressed using a device link when
3088633ef82SJavier Martinez Canillas  * running in DT mode, or the probe order may be reversed, resulting in a
3098633ef82SJavier Martinez Canillas  * resource reservation conflict on the memory window that the efifb
3108633ef82SJavier Martinez Canillas  * framebuffer steals from the PCIe host bridge.
3118633ef82SJavier Martinez Canillas  */
3128633ef82SJavier Martinez Canillas static int efifb_add_links(struct fwnode_handle *fwnode)
3138633ef82SJavier Martinez Canillas {
3148633ef82SJavier Martinez Canillas 	struct device_node *sup_np;
3158633ef82SJavier Martinez Canillas 
3168633ef82SJavier Martinez Canillas 	sup_np = find_pci_overlap_node();
3178633ef82SJavier Martinez Canillas 
3188633ef82SJavier Martinez Canillas 	/*
3198633ef82SJavier Martinez Canillas 	 * If there's no PCI graphics controller backing the efifb, we are
3208633ef82SJavier Martinez Canillas 	 * done here.
3218633ef82SJavier Martinez Canillas 	 */
3228633ef82SJavier Martinez Canillas 	if (!sup_np)
3238633ef82SJavier Martinez Canillas 		return 0;
3248633ef82SJavier Martinez Canillas 
3258633ef82SJavier Martinez Canillas 	fwnode_link_add(fwnode, of_fwnode_handle(sup_np));
3268633ef82SJavier Martinez Canillas 	of_node_put(sup_np);
3278633ef82SJavier Martinez Canillas 
3288633ef82SJavier Martinez Canillas 	return 0;
3298633ef82SJavier Martinez Canillas }
3308633ef82SJavier Martinez Canillas 
3318633ef82SJavier Martinez Canillas static const struct fwnode_operations efifb_fwnode_ops = {
3328633ef82SJavier Martinez Canillas 	.add_links = efifb_add_links,
3338633ef82SJavier Martinez Canillas };
3348633ef82SJavier Martinez Canillas 
335*15d27b15SRandy Dunlap #ifdef CONFIG_EFI
3368633ef82SJavier Martinez Canillas static struct fwnode_handle efifb_fwnode;
3378633ef82SJavier Martinez Canillas 
3388633ef82SJavier Martinez Canillas __init void sysfb_apply_efi_quirks(struct platform_device *pd)
339d391c582SJavier Martinez Canillas {
340d391c582SJavier Martinez Canillas 	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI ||
341d391c582SJavier Martinez Canillas 	    !(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS))
342d391c582SJavier Martinez Canillas 		dmi_check_system(efifb_dmi_system_table);
343d391c582SJavier Martinez Canillas 
344d391c582SJavier Martinez Canillas 	if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI &&
345d391c582SJavier Martinez Canillas 	    dmi_check_system(efifb_dmi_swap_width_height)) {
346d391c582SJavier Martinez Canillas 		u16 temp = screen_info.lfb_width;
347d391c582SJavier Martinez Canillas 
348d391c582SJavier Martinez Canillas 		screen_info.lfb_width = screen_info.lfb_height;
349d391c582SJavier Martinez Canillas 		screen_info.lfb_height = temp;
350d391c582SJavier Martinez Canillas 		screen_info.lfb_linelength = 4 * screen_info.lfb_width;
351d391c582SJavier Martinez Canillas 	}
3528633ef82SJavier Martinez Canillas 
3538633ef82SJavier Martinez Canillas 	if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI && IS_ENABLED(CONFIG_PCI)) {
3548633ef82SJavier Martinez Canillas 		fwnode_init(&efifb_fwnode, &efifb_fwnode_ops);
3558633ef82SJavier Martinez Canillas 		pd->dev.fwnode = &efifb_fwnode;
3568633ef82SJavier Martinez Canillas 	}
357d391c582SJavier Martinez Canillas }
358*15d27b15SRandy Dunlap #endif
359