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