Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Framebuffer driver for EFI/UEFI based system |
| 3 | * |
| 4 | * (c) 2006 Edgar Hucek <gimli@dark-green.com> |
| 5 | * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de> |
| 6 | * |
| 7 | */ |
| 8 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 9 | #include <linux/kernel.h> |
Ard Biesheuvel | 21289ec | 2016-04-25 21:06:50 +0100 | [diff] [blame] | 10 | #include <linux/efi.h> |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 11 | #include <linux/errno.h> |
| 12 | #include <linux/fb.h> |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 13 | #include <linux/pci.h> |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/screen_info.h> |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 16 | #include <video/vga.h> |
Ard Biesheuvel | 21289ec | 2016-04-25 21:06:50 +0100 | [diff] [blame] | 17 | #include <asm/efi.h> |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 18 | |
Andy Lutomirski | da0241f | 2011-05-26 10:13:32 -0400 | [diff] [blame] | 19 | static bool request_mem_succeeded = false; |
Dave Airlie | dd0c41f | 2017-07-31 18:45:41 +0200 | [diff] [blame] | 20 | static bool nowc = false; |
Andy Lutomirski | da0241f | 2011-05-26 10:13:32 -0400 | [diff] [blame] | 21 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 22 | static struct fb_var_screeninfo efifb_defined = { |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 23 | .activate = FB_ACTIVATE_NOW, |
| 24 | .height = -1, |
| 25 | .width = -1, |
| 26 | .right_margin = 32, |
| 27 | .upper_margin = 16, |
| 28 | .lower_margin = 4, |
| 29 | .vsync_len = 4, |
| 30 | .vmode = FB_VMODE_NONINTERLACED, |
| 31 | }; |
| 32 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 33 | static struct fb_fix_screeninfo efifb_fix = { |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 34 | .id = "EFI VGA", |
| 35 | .type = FB_TYPE_PACKED_PIXELS, |
| 36 | .accel = FB_ACCEL_NONE, |
| 37 | .visual = FB_VISUAL_TRUECOLOR, |
| 38 | }; |
| 39 | |
| 40 | static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 41 | unsigned blue, unsigned transp, |
| 42 | struct fb_info *info) |
| 43 | { |
| 44 | /* |
| 45 | * Set a single color register. The values supplied are |
| 46 | * already rounded down to the hardware's capabilities |
| 47 | * (according to the entries in the `var' structure). Return |
| 48 | * != 0 for invalid regno. |
| 49 | */ |
| 50 | |
| 51 | if (regno >= info->cmap.len) |
| 52 | return 1; |
| 53 | |
| 54 | if (regno < 16) { |
Max Staudt | d50b3f4 | 2016-06-13 19:15:59 +0200 | [diff] [blame] | 55 | red >>= 16 - info->var.red.length; |
| 56 | green >>= 16 - info->var.green.length; |
| 57 | blue >>= 16 - info->var.blue.length; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 58 | ((u32 *)(info->pseudo_palette))[regno] = |
| 59 | (red << info->var.red.offset) | |
| 60 | (green << info->var.green.offset) | |
| 61 | (blue << info->var.blue.offset); |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
Marcin Slusarz | 89f3f21 | 2010-02-22 12:44:22 -0800 | [diff] [blame] | 66 | static void efifb_destroy(struct fb_info *info) |
| 67 | { |
| 68 | if (info->screen_base) |
| 69 | iounmap(info->screen_base); |
Andy Lutomirski | da0241f | 2011-05-26 10:13:32 -0400 | [diff] [blame] | 70 | if (request_mem_succeeded) |
| 71 | release_mem_region(info->apertures->ranges[0].base, |
| 72 | info->apertures->ranges[0].size); |
Peter Jones | 907355a | 2013-07-25 11:48:11 -0400 | [diff] [blame] | 73 | fb_dealloc_cmap(&info->cmap); |
Marcin Slusarz | 89f3f21 | 2010-02-22 12:44:22 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 76 | static struct fb_ops efifb_ops = { |
| 77 | .owner = THIS_MODULE, |
Marcin Slusarz | 89f3f21 | 2010-02-22 12:44:22 -0800 | [diff] [blame] | 78 | .fb_destroy = efifb_destroy, |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 79 | .fb_setcolreg = efifb_setcolreg, |
| 80 | .fb_fillrect = cfb_fillrect, |
| 81 | .fb_copyarea = cfb_copyarea, |
| 82 | .fb_imageblit = cfb_imageblit, |
| 83 | }; |
| 84 | |
David Herrmann | e6816a8 | 2013-08-02 14:05:26 +0200 | [diff] [blame] | 85 | static int efifb_setup(char *options) |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 86 | { |
| 87 | char *this_opt; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 88 | |
Matthew Garrett | b4aa016 | 2012-04-16 16:26:05 -0400 | [diff] [blame] | 89 | if (options && *options) { |
| 90 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 91 | if (!*this_opt) continue; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 92 | |
Ard Biesheuvel | 21289ec | 2016-04-25 21:06:50 +0100 | [diff] [blame] | 93 | efifb_setup_from_dmi(&screen_info, this_opt); |
| 94 | |
Matthew Garrett | b4aa016 | 2012-04-16 16:26:05 -0400 | [diff] [blame] | 95 | if (!strncmp(this_opt, "base:", 5)) |
| 96 | screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0); |
| 97 | else if (!strncmp(this_opt, "stride:", 7)) |
| 98 | screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4; |
| 99 | else if (!strncmp(this_opt, "height:", 7)) |
| 100 | screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0); |
| 101 | else if (!strncmp(this_opt, "width:", 6)) |
| 102 | screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0); |
Dave Airlie | dd0c41f | 2017-07-31 18:45:41 +0200 | [diff] [blame] | 103 | else if (!strcmp(this_opt, "nowc")) |
| 104 | nowc = true; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 105 | } |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 106 | } |
Matthew Garrett | b4aa016 | 2012-04-16 16:26:05 -0400 | [diff] [blame] | 107 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
Matt Fleming | ae2ee62 | 2015-08-25 16:32:55 +0100 | [diff] [blame] | 111 | static inline bool fb_base_is_valid(void) |
| 112 | { |
| 113 | if (screen_info.lfb_base) |
| 114 | return true; |
| 115 | |
| 116 | if (!(screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)) |
| 117 | return false; |
| 118 | |
| 119 | if (screen_info.ext_lfb_base) |
| 120 | return true; |
| 121 | |
| 122 | return false; |
| 123 | } |
| 124 | |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 125 | #define efifb_attr_decl(name, fmt) \ |
| 126 | static ssize_t name##_show(struct device *dev, \ |
| 127 | struct device_attribute *attr, \ |
| 128 | char *buf) \ |
| 129 | { \ |
| 130 | return sprintf(buf, fmt "\n", (screen_info.lfb_##name)); \ |
| 131 | } \ |
| 132 | static DEVICE_ATTR_RO(name) |
| 133 | |
| 134 | efifb_attr_decl(base, "0x%x"); |
| 135 | efifb_attr_decl(linelength, "%u"); |
| 136 | efifb_attr_decl(height, "%u"); |
| 137 | efifb_attr_decl(width, "%u"); |
| 138 | efifb_attr_decl(depth, "%u"); |
| 139 | |
| 140 | static struct attribute *efifb_attrs[] = { |
| 141 | &dev_attr_base.attr, |
| 142 | &dev_attr_linelength.attr, |
| 143 | &dev_attr_width.attr, |
| 144 | &dev_attr_height.attr, |
| 145 | &dev_attr_depth.attr, |
| 146 | NULL |
| 147 | }; |
| 148 | ATTRIBUTE_GROUPS(efifb); |
| 149 | |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 150 | static bool pci_dev_disabled; /* FB base matches BAR of a disabled device */ |
| 151 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 152 | static struct pci_dev *efifb_pci_dev; /* dev with BAR covering the efifb */ |
| 153 | static struct resource *bar_resource; |
| 154 | static u64 bar_offset; |
| 155 | |
David Herrmann | e6816a8 | 2013-08-02 14:05:26 +0200 | [diff] [blame] | 156 | static int efifb_probe(struct platform_device *dev) |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 157 | { |
| 158 | struct fb_info *info; |
| 159 | int err; |
| 160 | unsigned int size_vmode; |
| 161 | unsigned int size_remap; |
| 162 | unsigned int size_total; |
David Herrmann | e6816a8 | 2013-08-02 14:05:26 +0200 | [diff] [blame] | 163 | char *option = NULL; |
| 164 | |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 165 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled) |
David Herrmann | e6816a8 | 2013-08-02 14:05:26 +0200 | [diff] [blame] | 166 | return -ENODEV; |
| 167 | |
| 168 | if (fb_get_options("efifb", &option)) |
| 169 | return -ENODEV; |
| 170 | efifb_setup(option); |
| 171 | |
| 172 | /* We don't get linelength from UGA Draw Protocol, only from |
| 173 | * EFI Graphics Protocol. So if it's not in DMI, and it's not |
| 174 | * passed in from the user, we really can't use the framebuffer. |
| 175 | */ |
| 176 | if (!screen_info.lfb_linelength) |
| 177 | return -ENODEV; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 178 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 179 | if (!screen_info.lfb_depth) |
| 180 | screen_info.lfb_depth = 32; |
| 181 | if (!screen_info.pages) |
| 182 | screen_info.pages = 1; |
Matt Fleming | ae2ee62 | 2015-08-25 16:32:55 +0100 | [diff] [blame] | 183 | if (!fb_base_is_valid()) { |
Matthew Garrett | 133bb07 | 2009-04-13 14:39:44 -0700 | [diff] [blame] | 184 | printk(KERN_DEBUG "efifb: invalid framebuffer address\n"); |
| 185 | return -ENODEV; |
| 186 | } |
| 187 | printk(KERN_INFO "efifb: probing for efifb\n"); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 188 | |
| 189 | /* just assume they're all unset if any are */ |
| 190 | if (!screen_info.blue_size) { |
| 191 | screen_info.blue_size = 8; |
| 192 | screen_info.blue_pos = 0; |
| 193 | screen_info.green_size = 8; |
| 194 | screen_info.green_pos = 8; |
| 195 | screen_info.red_size = 8; |
| 196 | screen_info.red_pos = 16; |
| 197 | screen_info.rsvd_size = 8; |
| 198 | screen_info.rsvd_pos = 24; |
| 199 | } |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 200 | |
| 201 | efifb_fix.smem_start = screen_info.lfb_base; |
Matt Fleming | ae2ee62 | 2015-08-25 16:32:55 +0100 | [diff] [blame] | 202 | |
| 203 | if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) { |
| 204 | u64 ext_lfb_base; |
| 205 | |
| 206 | ext_lfb_base = (u64)(unsigned long)screen_info.ext_lfb_base << 32; |
| 207 | efifb_fix.smem_start |= ext_lfb_base; |
| 208 | } |
| 209 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 210 | if (bar_resource && |
| 211 | bar_resource->start + bar_offset != efifb_fix.smem_start) { |
| 212 | dev_info(&efifb_pci_dev->dev, |
| 213 | "BAR has moved, updating efifb address\n"); |
| 214 | efifb_fix.smem_start = bar_resource->start + bar_offset; |
| 215 | } |
| 216 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 217 | efifb_defined.bits_per_pixel = screen_info.lfb_depth; |
| 218 | efifb_defined.xres = screen_info.lfb_width; |
| 219 | efifb_defined.yres = screen_info.lfb_height; |
| 220 | efifb_fix.line_length = screen_info.lfb_linelength; |
| 221 | |
| 222 | /* size_vmode -- that is the amount of memory needed for the |
| 223 | * used video mode, i.e. the minimum amount of |
| 224 | * memory we need. */ |
| 225 | size_vmode = efifb_defined.yres * efifb_fix.line_length; |
| 226 | |
| 227 | /* size_total -- all video memory we have. Used for |
| 228 | * entries, ressource allocation and bounds |
| 229 | * checking. */ |
| 230 | size_total = screen_info.lfb_size; |
| 231 | if (size_total < size_vmode) |
| 232 | size_total = size_vmode; |
| 233 | |
| 234 | /* size_remap -- the amount of video memory we are going to |
| 235 | * use for efifb. With modern cards it is no |
| 236 | * option to simply use size_total as that |
| 237 | * wastes plenty of kernel address space. */ |
| 238 | size_remap = size_vmode * 2; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 239 | if (size_remap > size_total) |
| 240 | size_remap = size_total; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 241 | if (size_remap % PAGE_SIZE) |
| 242 | size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 243 | efifb_fix.smem_len = size_remap; |
| 244 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 245 | if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) { |
Andy Lutomirski | da0241f | 2011-05-26 10:13:32 -0400 | [diff] [blame] | 246 | request_mem_succeeded = true; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 247 | } else { |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 248 | /* We cannot make this fatal. Sometimes this comes from magic |
| 249 | spaces our resource handlers simply don't know about */ |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 250 | pr_warn("efifb: cannot reserve video memory at 0x%lx\n", |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 251 | efifb_fix.smem_start); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 252 | } |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 253 | |
| 254 | info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev); |
| 255 | if (!info) { |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 256 | pr_err("efifb: cannot allocate framebuffer\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 257 | err = -ENOMEM; |
| 258 | goto err_release_mem; |
| 259 | } |
David Herrmann | 65b4021 | 2014-01-23 15:14:55 +0100 | [diff] [blame] | 260 | platform_set_drvdata(dev, info); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 261 | info->pseudo_palette = info->par; |
| 262 | info->par = NULL; |
| 263 | |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 264 | info->apertures = alloc_apertures(1); |
| 265 | if (!info->apertures) { |
| 266 | err = -ENOMEM; |
| 267 | goto err_release_fb; |
| 268 | } |
| 269 | info->apertures->ranges[0].base = efifb_fix.smem_start; |
| 270 | info->apertures->ranges[0].size = size_remap; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 271 | |
Dave Airlie | dd0c41f | 2017-07-31 18:45:41 +0200 | [diff] [blame] | 272 | if (nowc) |
| 273 | info->screen_base = ioremap(efifb_fix.smem_start, efifb_fix.smem_len); |
| 274 | else |
| 275 | info->screen_base = ioremap_wc(efifb_fix.smem_start, efifb_fix.smem_len); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 276 | if (!info->screen_base) { |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 277 | pr_err("efifb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 278 | efifb_fix.smem_len, efifb_fix.smem_start); |
| 279 | err = -EIO; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 280 | goto err_release_fb; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 283 | pr_info("efifb: framebuffer at 0x%lx, using %dk, total %dk\n", |
Andy Lutomirski | a53dd25 | 2016-05-11 16:57:47 -0700 | [diff] [blame] | 284 | efifb_fix.smem_start, size_remap/1024, size_total/1024); |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 285 | pr_info("efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n", |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 286 | efifb_defined.xres, efifb_defined.yres, |
| 287 | efifb_defined.bits_per_pixel, efifb_fix.line_length, |
| 288 | screen_info.pages); |
| 289 | |
| 290 | efifb_defined.xres_virtual = efifb_defined.xres; |
| 291 | efifb_defined.yres_virtual = efifb_fix.smem_len / |
| 292 | efifb_fix.line_length; |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 293 | pr_info("efifb: scrolling: redraw\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 294 | efifb_defined.yres_virtual = efifb_defined.yres; |
| 295 | |
| 296 | /* some dummy values for timing to make fbset happy */ |
| 297 | efifb_defined.pixclock = 10000000 / efifb_defined.xres * |
| 298 | 1000 / efifb_defined.yres; |
| 299 | efifb_defined.left_margin = (efifb_defined.xres / 8) & 0xf8; |
| 300 | efifb_defined.hsync_len = (efifb_defined.xres / 8) & 0xf8; |
| 301 | |
| 302 | efifb_defined.red.offset = screen_info.red_pos; |
| 303 | efifb_defined.red.length = screen_info.red_size; |
| 304 | efifb_defined.green.offset = screen_info.green_pos; |
| 305 | efifb_defined.green.length = screen_info.green_size; |
| 306 | efifb_defined.blue.offset = screen_info.blue_pos; |
| 307 | efifb_defined.blue.length = screen_info.blue_size; |
| 308 | efifb_defined.transp.offset = screen_info.rsvd_pos; |
| 309 | efifb_defined.transp.length = screen_info.rsvd_size; |
| 310 | |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 311 | pr_info("efifb: %s: " |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 312 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", |
| 313 | "Truecolor", |
| 314 | screen_info.rsvd_size, |
| 315 | screen_info.red_size, |
| 316 | screen_info.green_size, |
| 317 | screen_info.blue_size, |
| 318 | screen_info.rsvd_pos, |
| 319 | screen_info.red_pos, |
| 320 | screen_info.green_pos, |
| 321 | screen_info.blue_pos); |
| 322 | |
| 323 | efifb_fix.ypanstep = 0; |
| 324 | efifb_fix.ywrapstep = 0; |
| 325 | |
| 326 | info->fbops = &efifb_ops; |
| 327 | info->var = efifb_defined; |
| 328 | info->fix = efifb_fix; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 329 | info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 330 | |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 331 | err = sysfs_create_groups(&dev->dev.kobj, efifb_groups); |
| 332 | if (err) { |
| 333 | pr_err("efifb: cannot add sysfs attrs\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 334 | goto err_unmap; |
| 335 | } |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 336 | err = fb_alloc_cmap(&info->cmap, 256, 0); |
| 337 | if (err < 0) { |
| 338 | pr_err("efifb: cannot allocate colormap\n"); |
| 339 | goto err_groups; |
| 340 | } |
| 341 | err = register_framebuffer(info); |
| 342 | if (err < 0) { |
| 343 | pr_err("efifb: cannot register framebuffer\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 344 | goto err_fb_dealoc; |
| 345 | } |
Joe Perches | 31b6780 | 2013-09-19 18:35:55 -0700 | [diff] [blame] | 346 | fb_info(info, "%s frame buffer device\n", info->fix.id); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 347 | return 0; |
| 348 | |
| 349 | err_fb_dealoc: |
| 350 | fb_dealloc_cmap(&info->cmap); |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 351 | err_groups: |
| 352 | sysfs_remove_groups(&dev->dev.kobj, efifb_groups); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 353 | err_unmap: |
| 354 | iounmap(info->screen_base); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 355 | err_release_fb: |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 356 | framebuffer_release(info); |
| 357 | err_release_mem: |
Andy Lutomirski | da0241f | 2011-05-26 10:13:32 -0400 | [diff] [blame] | 358 | if (request_mem_succeeded) |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 359 | release_mem_region(efifb_fix.smem_start, size_total); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 360 | return err; |
| 361 | } |
| 362 | |
David Herrmann | 65b4021 | 2014-01-23 15:14:55 +0100 | [diff] [blame] | 363 | static int efifb_remove(struct platform_device *pdev) |
| 364 | { |
| 365 | struct fb_info *info = platform_get_drvdata(pdev); |
| 366 | |
| 367 | unregister_framebuffer(info); |
Peter Jones | 753375a | 2016-10-18 15:33:17 +0100 | [diff] [blame] | 368 | sysfs_remove_groups(&pdev->dev.kobj, efifb_groups); |
David Herrmann | 65b4021 | 2014-01-23 15:14:55 +0100 | [diff] [blame] | 369 | framebuffer_release(info); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 374 | static struct platform_driver efifb_driver = { |
David Herrmann | e6816a8 | 2013-08-02 14:05:26 +0200 | [diff] [blame] | 375 | .driver = { |
| 376 | .name = "efi-framebuffer", |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 377 | }, |
David Herrmann | e6816a8 | 2013-08-02 14:05:26 +0200 | [diff] [blame] | 378 | .probe = efifb_probe, |
David Herrmann | 65b4021 | 2014-01-23 15:14:55 +0100 | [diff] [blame] | 379 | .remove = efifb_remove, |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 380 | }; |
| 381 | |
Ard Biesheuvel | 07ea7ec | 2016-04-25 21:06:51 +0100 | [diff] [blame] | 382 | builtin_platform_driver(efifb_driver); |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 383 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 384 | #if defined(CONFIG_PCI) |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 385 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 386 | static void record_efifb_bar_resource(struct pci_dev *dev, int idx, u64 offset) |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 387 | { |
| 388 | u16 word; |
| 389 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 390 | efifb_pci_dev = dev; |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 391 | |
| 392 | pci_read_config_word(dev, PCI_COMMAND, &word); |
| 393 | if (!(word & PCI_COMMAND_MEMORY)) { |
| 394 | pci_dev_disabled = true; |
| 395 | dev_err(&dev->dev, |
| 396 | "BAR %d: assigned to efifb but device is disabled!\n", |
| 397 | idx); |
| 398 | return; |
| 399 | } |
| 400 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 401 | bar_resource = &dev->resource[idx]; |
| 402 | bar_offset = offset; |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 403 | |
| 404 | dev_info(&dev->dev, "BAR %d: assigned to efifb\n", idx); |
| 405 | } |
| 406 | |
| 407 | static void efifb_fixup_resources(struct pci_dev *dev) |
| 408 | { |
| 409 | u64 base = screen_info.lfb_base; |
| 410 | u64 size = screen_info.lfb_size; |
| 411 | int i; |
| 412 | |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 413 | if (efifb_pci_dev || screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 414 | return; |
| 415 | |
| 416 | if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) |
| 417 | base |= (u64)screen_info.ext_lfb_base << 32; |
| 418 | |
| 419 | if (!base) |
| 420 | return; |
| 421 | |
Bjorn Helgaas | 92a16c8 | 2017-05-19 14:37:53 -0500 | [diff] [blame] | 422 | for (i = 0; i <= PCI_STD_RESOURCE_END; i++) { |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 423 | struct resource *res = &dev->resource[i]; |
| 424 | |
| 425 | if (!(res->flags & IORESOURCE_MEM)) |
| 426 | continue; |
| 427 | |
| 428 | if (res->start <= base && res->end >= base + size - 1) { |
Ard Biesheuvel | dcf8f5c | 2017-08-18 20:49:40 +0100 | [diff] [blame^] | 429 | record_efifb_bar_resource(dev, i, base - res->start); |
Ard Biesheuvel | 55d728a | 2017-04-04 16:27:44 +0100 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY, |
| 435 | 16, efifb_fixup_resources); |
| 436 | |
| 437 | #endif |