GNU Linux-libre 4.19.286-gnu1
[releases.git] / drivers / video / fbdev / efifb.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Framebuffer driver for EFI/UEFI based system
4  *
5  * (c) 2006 Edgar Hucek <gimli@dark-green.com>
6  * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
7  *
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/efi.h>
12 #include <linux/efi-bgrt.h>
13 #include <linux/errno.h>
14 #include <linux/fb.h>
15 #include <linux/pci.h>
16 #include <linux/platform_device.h>
17 #include <linux/printk.h>
18 #include <linux/screen_info.h>
19 #include <video/vga.h>
20 #include <asm/efi.h>
21 #include <drm/drm_utils.h> /* For drm_get_panel_orientation_quirk */
22 #include <drm/drm_connector.h>  /* For DRM_MODE_PANEL_ORIENTATION_* */
23
24 struct bmp_file_header {
25         u16 id;
26         u32 file_size;
27         u32 reserved;
28         u32 bitmap_offset;
29 } __packed;
30
31 struct bmp_dib_header {
32         u32 dib_header_size;
33         s32 width;
34         s32 height;
35         u16 planes;
36         u16 bpp;
37         u32 compression;
38         u32 bitmap_size;
39         u32 horz_resolution;
40         u32 vert_resolution;
41         u32 colors_used;
42         u32 colors_important;
43 } __packed;
44
45 static bool use_bgrt = true;
46 static bool request_mem_succeeded = false;
47 static u64 mem_flags = EFI_MEMORY_WC | EFI_MEMORY_UC;
48
49 static struct fb_var_screeninfo efifb_defined = {
50         .activate               = FB_ACTIVATE_NOW,
51         .height                 = -1,
52         .width                  = -1,
53         .right_margin           = 32,
54         .upper_margin           = 16,
55         .lower_margin           = 4,
56         .vsync_len              = 4,
57         .vmode                  = FB_VMODE_NONINTERLACED,
58 };
59
60 static struct fb_fix_screeninfo efifb_fix = {
61         .id                     = "EFI VGA",
62         .type                   = FB_TYPE_PACKED_PIXELS,
63         .accel                  = FB_ACCEL_NONE,
64         .visual                 = FB_VISUAL_TRUECOLOR,
65 };
66
67 static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
68                            unsigned blue, unsigned transp,
69                            struct fb_info *info)
70 {
71         /*
72          *  Set a single color register. The values supplied are
73          *  already rounded down to the hardware's capabilities
74          *  (according to the entries in the `var' structure). Return
75          *  != 0 for invalid regno.
76          */
77
78         if (regno >= info->cmap.len)
79                 return 1;
80
81         if (regno < 16) {
82                 red   >>= 16 - info->var.red.length;
83                 green >>= 16 - info->var.green.length;
84                 blue  >>= 16 - info->var.blue.length;
85                 ((u32 *)(info->pseudo_palette))[regno] =
86                         (red   << info->var.red.offset)   |
87                         (green << info->var.green.offset) |
88                         (blue  << info->var.blue.offset);
89         }
90         return 0;
91 }
92
93 /*
94  * If fbcon deffered console takeover is configured, the intent is for the
95  * framebuffer to show the boot graphics (e.g. vendor logo) until there is some
96  * (error) message to display. But the boot graphics may have been destroyed by
97  * e.g. option ROM output, detect this and restore the boot graphics.
98  */
99 #if defined CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER && \
100     defined CONFIG_ACPI_BGRT
101 static void efifb_copy_bmp(u8 *src, u32 *dst, int width, struct screen_info *si)
102 {
103         u8 r, g, b;
104
105         while (width--) {
106                 b = *src++;
107                 g = *src++;
108                 r = *src++;
109                 *dst++ = (r << si->red_pos)   |
110                          (g << si->green_pos) |
111                          (b << si->blue_pos);
112         }
113 }
114
115 #ifdef CONFIG_X86
116 /*
117  * On x86 some firmwares use a low non native resolution for the display when
118  * they have shown some text messages. While keeping the bgrt filled with info
119  * for the native resolution. If the bgrt image intended for the native
120  * resolution still fits, it will be displayed very close to the right edge of
121  * the display looking quite bad. This function checks for this.
122  */
123 static bool efifb_bgrt_sanity_check(struct screen_info *si, u32 bmp_width)
124 {
125         /*
126          * All x86 firmwares horizontally center the image (the yoffset
127          * calculations differ between boards, but xoffset is predictable).
128          */
129         u32 expected_xoffset = (si->lfb_width - bmp_width) / 2;
130
131         return bgrt_tab.image_offset_x == expected_xoffset;
132 }
133 #else
134 static bool efifb_bgrt_sanity_check(struct screen_info *si, u32 bmp_width)
135 {
136         return true;
137 }
138 #endif
139
140 static void efifb_show_boot_graphics(struct fb_info *info)
141 {
142         u32 bmp_width, bmp_height, bmp_pitch, screen_pitch, dst_x, y, src_y;
143         struct screen_info *si = &screen_info;
144         struct bmp_file_header *file_header;
145         struct bmp_dib_header *dib_header;
146         void *bgrt_image = NULL;
147         u8 *dst = info->screen_base;
148
149         if (!use_bgrt)
150                 return;
151
152         if (!bgrt_tab.image_address) {
153                 pr_info("efifb: No BGRT, not showing boot graphics\n");
154                 return;
155         }
156
157         /* Avoid flashing the logo if we're going to print std probe messages */
158         if (console_loglevel > CONSOLE_LOGLEVEL_QUIET)
159                 return;
160
161         /* bgrt_tab.status is unreliable, so we don't check it */
162
163         if (si->lfb_depth != 32) {
164                 pr_info("efifb: not 32 bits, not showing boot graphics\n");
165                 return;
166         }
167
168         bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
169                               MEMREMAP_WB);
170         if (!bgrt_image) {
171                 pr_warn("efifb: Ignoring BGRT: failed to map image memory\n");
172                 return;
173         }
174
175         if (bgrt_image_size < (sizeof(*file_header) + sizeof(*dib_header)))
176                 goto error;
177
178         file_header = bgrt_image;
179         if (file_header->id != 0x4d42 || file_header->reserved != 0)
180                 goto error;
181
182         dib_header = bgrt_image + sizeof(*file_header);
183         if (dib_header->dib_header_size != 40 || dib_header->width < 0 ||
184             dib_header->planes != 1 || dib_header->bpp != 24 ||
185             dib_header->compression != 0)
186                 goto error;
187
188         bmp_width = dib_header->width;
189         bmp_height = abs(dib_header->height);
190         bmp_pitch = round_up(3 * bmp_width, 4);
191         screen_pitch = si->lfb_linelength;
192
193         if ((file_header->bitmap_offset + bmp_pitch * bmp_height) >
194                                 bgrt_image_size)
195                 goto error;
196
197         if ((bgrt_tab.image_offset_x + bmp_width) > si->lfb_width ||
198             (bgrt_tab.image_offset_y + bmp_height) > si->lfb_height)
199                 goto error;
200
201         if (!efifb_bgrt_sanity_check(si, bmp_width))
202                 goto error;
203
204         pr_info("efifb: showing boot graphics\n");
205
206         for (y = 0; y < si->lfb_height; y++, dst += si->lfb_linelength) {
207                 /* Only background? */
208                 if (y < bgrt_tab.image_offset_y ||
209                     y >= (bgrt_tab.image_offset_y + bmp_height)) {
210                         memset(dst, 0, 4 * si->lfb_width);
211                         continue;
212                 }
213
214                 src_y = y - bgrt_tab.image_offset_y;
215                 /* Positive header height means upside down row order */
216                 if (dib_header->height > 0)
217                         src_y = (bmp_height - 1) - src_y;
218
219                 memset(dst, 0, bgrt_tab.image_offset_x * 4);
220                 dst_x = bgrt_tab.image_offset_x;
221                 efifb_copy_bmp(bgrt_image + file_header->bitmap_offset +
222                                             src_y * bmp_pitch,
223                                (u32 *)dst + dst_x, bmp_width, si);
224                 dst_x += bmp_width;
225                 memset((u32 *)dst + dst_x, 0, (si->lfb_width - dst_x) * 4);
226         }
227
228         memunmap(bgrt_image);
229         return;
230
231 error:
232         memunmap(bgrt_image);
233         pr_warn("efifb: Ignoring BGRT: unexpected or invalid BMP data\n");
234 }
235 #else
236 static inline void efifb_show_boot_graphics(struct fb_info *info) {}
237 #endif
238
239 static void efifb_destroy(struct fb_info *info)
240 {
241         if (info->screen_base) {
242                 if (mem_flags & (EFI_MEMORY_UC | EFI_MEMORY_WC))
243                         iounmap(info->screen_base);
244                 else
245                         memunmap(info->screen_base);
246         }
247         if (request_mem_succeeded)
248                 release_mem_region(info->apertures->ranges[0].base,
249                                    info->apertures->ranges[0].size);
250         fb_dealloc_cmap(&info->cmap);
251 }
252
253 static struct fb_ops efifb_ops = {
254         .owner          = THIS_MODULE,
255         .fb_destroy     = efifb_destroy,
256         .fb_setcolreg   = efifb_setcolreg,
257         .fb_fillrect    = cfb_fillrect,
258         .fb_copyarea    = cfb_copyarea,
259         .fb_imageblit   = cfb_imageblit,
260 };
261
262 static int efifb_setup(char *options)
263 {
264         char *this_opt;
265
266         if (options && *options) {
267                 while ((this_opt = strsep(&options, ",")) != NULL) {
268                         if (!*this_opt) continue;
269
270                         efifb_setup_from_dmi(&screen_info, this_opt);
271
272                         if (!strncmp(this_opt, "base:", 5))
273                                 screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
274                         else if (!strncmp(this_opt, "stride:", 7))
275                                 screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
276                         else if (!strncmp(this_opt, "height:", 7))
277                                 screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
278                         else if (!strncmp(this_opt, "width:", 6))
279                                 screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
280                         else if (!strcmp(this_opt, "nowc"))
281                                 mem_flags &= ~EFI_MEMORY_WC;
282                         else if (!strcmp(this_opt, "nobgrt"))
283                                 use_bgrt = false;
284                 }
285         }
286
287         return 0;
288 }
289
290 static inline bool fb_base_is_valid(void)
291 {
292         if (screen_info.lfb_base)
293                 return true;
294
295         if (!(screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE))
296                 return false;
297
298         if (screen_info.ext_lfb_base)
299                 return true;
300
301         return false;
302 }
303
304 #define efifb_attr_decl(name, fmt)                                      \
305 static ssize_t name##_show(struct device *dev,                          \
306                            struct device_attribute *attr,               \
307                            char *buf)                                   \
308 {                                                                       \
309         return sprintf(buf, fmt "\n", (screen_info.lfb_##name));        \
310 }                                                                       \
311 static DEVICE_ATTR_RO(name)
312
313 efifb_attr_decl(base, "0x%x");
314 efifb_attr_decl(linelength, "%u");
315 efifb_attr_decl(height, "%u");
316 efifb_attr_decl(width, "%u");
317 efifb_attr_decl(depth, "%u");
318
319 static struct attribute *efifb_attrs[] = {
320         &dev_attr_base.attr,
321         &dev_attr_linelength.attr,
322         &dev_attr_width.attr,
323         &dev_attr_height.attr,
324         &dev_attr_depth.attr,
325         NULL
326 };
327 ATTRIBUTE_GROUPS(efifb);
328
329 static bool pci_dev_disabled;   /* FB base matches BAR of a disabled device */
330
331 static struct pci_dev *efifb_pci_dev;   /* dev with BAR covering the efifb */
332 static struct resource *bar_resource;
333 static u64 bar_offset;
334
335 static int efifb_probe(struct platform_device *dev)
336 {
337         struct fb_info *info;
338         int err, orientation;
339         unsigned int size_vmode;
340         unsigned int size_remap;
341         unsigned int size_total;
342         char *option = NULL;
343         efi_memory_desc_t md;
344
345         if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled)
346                 return -ENODEV;
347
348         if (fb_get_options("efifb", &option))
349                 return -ENODEV;
350         efifb_setup(option);
351
352         /* We don't get linelength from UGA Draw Protocol, only from
353          * EFI Graphics Protocol.  So if it's not in DMI, and it's not
354          * passed in from the user, we really can't use the framebuffer.
355          */
356         if (!screen_info.lfb_linelength)
357                 return -ENODEV;
358
359         if (!screen_info.lfb_depth)
360                 screen_info.lfb_depth = 32;
361         if (!screen_info.pages)
362                 screen_info.pages = 1;
363         if (!fb_base_is_valid()) {
364                 printk(KERN_DEBUG "efifb: invalid framebuffer address\n");
365                 return -ENODEV;
366         }
367         printk(KERN_INFO "efifb: probing for efifb\n");
368
369         /* just assume they're all unset if any are */
370         if (!screen_info.blue_size) {
371                 screen_info.blue_size = 8;
372                 screen_info.blue_pos = 0;
373                 screen_info.green_size = 8;
374                 screen_info.green_pos = 8;
375                 screen_info.red_size = 8;
376                 screen_info.red_pos = 16;
377                 screen_info.rsvd_size = 8;
378                 screen_info.rsvd_pos = 24;
379         }
380
381         efifb_fix.smem_start = screen_info.lfb_base;
382
383         if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) {
384                 u64 ext_lfb_base;
385
386                 ext_lfb_base = (u64)(unsigned long)screen_info.ext_lfb_base << 32;
387                 efifb_fix.smem_start |= ext_lfb_base;
388         }
389
390         if (bar_resource &&
391             bar_resource->start + bar_offset != efifb_fix.smem_start) {
392                 dev_info(&efifb_pci_dev->dev,
393                          "BAR has moved, updating efifb address\n");
394                 efifb_fix.smem_start = bar_resource->start + bar_offset;
395         }
396
397         efifb_defined.bits_per_pixel = screen_info.lfb_depth;
398         efifb_defined.xres = screen_info.lfb_width;
399         efifb_defined.yres = screen_info.lfb_height;
400         efifb_fix.line_length = screen_info.lfb_linelength;
401
402         /*   size_vmode -- that is the amount of memory needed for the
403          *                 used video mode, i.e. the minimum amount of
404          *                 memory we need. */
405         size_vmode = efifb_defined.yres * efifb_fix.line_length;
406
407         /*   size_total -- all video memory we have. Used for
408          *                 entries, ressource allocation and bounds
409          *                 checking. */
410         size_total = screen_info.lfb_size;
411         if (size_total < size_vmode)
412                 size_total = size_vmode;
413
414         /*   size_remap -- the amount of video memory we are going to
415          *                 use for efifb.  With modern cards it is no
416          *                 option to simply use size_total as that
417          *                 wastes plenty of kernel address space. */
418         size_remap  = size_vmode * 2;
419         if (size_remap > size_total)
420                 size_remap = size_total;
421         if (size_remap % PAGE_SIZE)
422                 size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE);
423         efifb_fix.smem_len = size_remap;
424
425         if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) {
426                 request_mem_succeeded = true;
427         } else {
428                 /* We cannot make this fatal. Sometimes this comes from magic
429                    spaces our resource handlers simply don't know about */
430                 pr_warn("efifb: cannot reserve video memory at 0x%lx\n",
431                         efifb_fix.smem_start);
432         }
433
434         info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
435         if (!info) {
436                 pr_err("efifb: cannot allocate framebuffer\n");
437                 err = -ENOMEM;
438                 goto err_release_mem;
439         }
440         platform_set_drvdata(dev, info);
441         info->pseudo_palette = info->par;
442         info->par = NULL;
443
444         info->apertures = alloc_apertures(1);
445         if (!info->apertures) {
446                 err = -ENOMEM;
447                 goto err_release_fb;
448         }
449         info->apertures->ranges[0].base = efifb_fix.smem_start;
450         info->apertures->ranges[0].size = size_remap;
451
452         if (efi_enabled(EFI_MEMMAP) &&
453             !efi_mem_desc_lookup(efifb_fix.smem_start, &md)) {
454                 if ((efifb_fix.smem_start + efifb_fix.smem_len) >
455                     (md.phys_addr + (md.num_pages << EFI_PAGE_SHIFT))) {
456                         pr_err("efifb: video memory @ 0x%lx spans multiple EFI memory regions\n",
457                                efifb_fix.smem_start);
458                         err = -EIO;
459                         goto err_release_fb;
460                 }
461                 /*
462                  * If the UEFI memory map covers the efifb region, we may only
463                  * remap it using the attributes the memory map prescribes.
464                  */
465                 md.attribute &= EFI_MEMORY_UC | EFI_MEMORY_WC |
466                                 EFI_MEMORY_WT | EFI_MEMORY_WB;
467                 if (md.attribute) {
468                         mem_flags |= EFI_MEMORY_WT | EFI_MEMORY_WB;
469                         mem_flags &= md.attribute;
470                 }
471         }
472         if (mem_flags & EFI_MEMORY_WC)
473                 info->screen_base = ioremap_wc(efifb_fix.smem_start,
474                                                efifb_fix.smem_len);
475         else if (mem_flags & EFI_MEMORY_UC)
476                 info->screen_base = ioremap(efifb_fix.smem_start,
477                                             efifb_fix.smem_len);
478         else if (mem_flags & EFI_MEMORY_WT)
479                 info->screen_base = memremap(efifb_fix.smem_start,
480                                              efifb_fix.smem_len, MEMREMAP_WT);
481         else if (mem_flags & EFI_MEMORY_WB)
482                 info->screen_base = memremap(efifb_fix.smem_start,
483                                              efifb_fix.smem_len, MEMREMAP_WB);
484         if (!info->screen_base) {
485                 pr_err("efifb: abort, cannot remap video memory 0x%x @ 0x%lx\n",
486                         efifb_fix.smem_len, efifb_fix.smem_start);
487                 err = -EIO;
488                 goto err_release_fb;
489         }
490
491         efifb_show_boot_graphics(info);
492
493         pr_info("efifb: framebuffer at 0x%lx, using %dk, total %dk\n",
494                efifb_fix.smem_start, size_remap/1024, size_total/1024);
495         pr_info("efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
496                efifb_defined.xres, efifb_defined.yres,
497                efifb_defined.bits_per_pixel, efifb_fix.line_length,
498                screen_info.pages);
499
500         efifb_defined.xres_virtual = efifb_defined.xres;
501         efifb_defined.yres_virtual = efifb_fix.smem_len /
502                                         efifb_fix.line_length;
503         pr_info("efifb: scrolling: redraw\n");
504         efifb_defined.yres_virtual = efifb_defined.yres;
505
506         /* some dummy values for timing to make fbset happy */
507         efifb_defined.pixclock     = 10000000 / efifb_defined.xres *
508                                         1000 / efifb_defined.yres;
509         efifb_defined.left_margin  = (efifb_defined.xres / 8) & 0xf8;
510         efifb_defined.hsync_len    = (efifb_defined.xres / 8) & 0xf8;
511
512         efifb_defined.red.offset    = screen_info.red_pos;
513         efifb_defined.red.length    = screen_info.red_size;
514         efifb_defined.green.offset  = screen_info.green_pos;
515         efifb_defined.green.length  = screen_info.green_size;
516         efifb_defined.blue.offset   = screen_info.blue_pos;
517         efifb_defined.blue.length   = screen_info.blue_size;
518         efifb_defined.transp.offset = screen_info.rsvd_pos;
519         efifb_defined.transp.length = screen_info.rsvd_size;
520
521         pr_info("efifb: %s: "
522                "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
523                "Truecolor",
524                screen_info.rsvd_size,
525                screen_info.red_size,
526                screen_info.green_size,
527                screen_info.blue_size,
528                screen_info.rsvd_pos,
529                screen_info.red_pos,
530                screen_info.green_pos,
531                screen_info.blue_pos);
532
533         efifb_fix.ypanstep  = 0;
534         efifb_fix.ywrapstep = 0;
535
536         info->fbops = &efifb_ops;
537         info->var = efifb_defined;
538         info->fix = efifb_fix;
539         info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE;
540
541         orientation = drm_get_panel_orientation_quirk(efifb_defined.xres,
542                                                       efifb_defined.yres);
543         switch (orientation) {
544         default:
545                 info->fbcon_rotate_hint = FB_ROTATE_UR;
546                 break;
547         case DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP:
548                 info->fbcon_rotate_hint = FB_ROTATE_UD;
549                 break;
550         case DRM_MODE_PANEL_ORIENTATION_LEFT_UP:
551                 info->fbcon_rotate_hint = FB_ROTATE_CCW;
552                 break;
553         case DRM_MODE_PANEL_ORIENTATION_RIGHT_UP:
554                 info->fbcon_rotate_hint = FB_ROTATE_CW;
555                 break;
556         }
557
558         err = sysfs_create_groups(&dev->dev.kobj, efifb_groups);
559         if (err) {
560                 pr_err("efifb: cannot add sysfs attrs\n");
561                 goto err_unmap;
562         }
563         err = fb_alloc_cmap(&info->cmap, 256, 0);
564         if (err < 0) {
565                 pr_err("efifb: cannot allocate colormap\n");
566                 goto err_groups;
567         }
568         err = register_framebuffer(info);
569         if (err < 0) {
570                 pr_err("efifb: cannot register framebuffer\n");
571                 goto err_fb_dealoc;
572         }
573         fb_info(info, "%s frame buffer device\n", info->fix.id);
574         return 0;
575
576 err_fb_dealoc:
577         fb_dealloc_cmap(&info->cmap);
578 err_groups:
579         sysfs_remove_groups(&dev->dev.kobj, efifb_groups);
580 err_unmap:
581         if (mem_flags & (EFI_MEMORY_UC | EFI_MEMORY_WC))
582                 iounmap(info->screen_base);
583         else
584                 memunmap(info->screen_base);
585 err_release_fb:
586         framebuffer_release(info);
587 err_release_mem:
588         if (request_mem_succeeded)
589                 release_mem_region(efifb_fix.smem_start, size_total);
590         return err;
591 }
592
593 static int efifb_remove(struct platform_device *pdev)
594 {
595         struct fb_info *info = platform_get_drvdata(pdev);
596
597         unregister_framebuffer(info);
598         sysfs_remove_groups(&pdev->dev.kobj, efifb_groups);
599         framebuffer_release(info);
600
601         return 0;
602 }
603
604 static struct platform_driver efifb_driver = {
605         .driver = {
606                 .name = "efi-framebuffer",
607         },
608         .probe = efifb_probe,
609         .remove = efifb_remove,
610 };
611
612 builtin_platform_driver(efifb_driver);
613
614 #if defined(CONFIG_PCI)
615
616 static void record_efifb_bar_resource(struct pci_dev *dev, int idx, u64 offset)
617 {
618         u16 word;
619
620         efifb_pci_dev = dev;
621
622         pci_read_config_word(dev, PCI_COMMAND, &word);
623         if (!(word & PCI_COMMAND_MEMORY)) {
624                 pci_dev_disabled = true;
625                 dev_err(&dev->dev,
626                         "BAR %d: assigned to efifb but device is disabled!\n",
627                         idx);
628                 return;
629         }
630
631         bar_resource = &dev->resource[idx];
632         bar_offset = offset;
633
634         dev_info(&dev->dev, "BAR %d: assigned to efifb\n", idx);
635 }
636
637 static void efifb_fixup_resources(struct pci_dev *dev)
638 {
639         u64 base = screen_info.lfb_base;
640         u64 size = screen_info.lfb_size;
641         int i;
642
643         if (efifb_pci_dev || screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
644                 return;
645
646         if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
647                 base |= (u64)screen_info.ext_lfb_base << 32;
648
649         if (!base)
650                 return;
651
652         for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
653                 struct resource *res = &dev->resource[i];
654
655                 if (!(res->flags & IORESOURCE_MEM))
656                         continue;
657
658                 if (res->start <= base && res->end >= base + size - 1) {
659                         record_efifb_bar_resource(dev, i, base - res->start);
660                         break;
661                 }
662         }
663 }
664 DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY,
665                                16, efifb_fixup_resources);
666
667 #endif