2 * Framebuffer driver for EFI/UEFI based system
4 * (c) 2006 Edgar Hucek <gimli@dark-green.com>
5 * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
13 #include <linux/platform_device.h>
14 #include <linux/screen_info.h>
15 #include <linux/dmi.h>
16 #include <linux/pci.h>
17 #include <video/vga.h>
18 #include <asm/sysfb.h>
20 static bool request_mem_succeeded = false;
22 static struct pci_dev *default_vga;
24 static struct fb_var_screeninfo efifb_defined = {
25 .activate = FB_ACTIVATE_NOW,
32 .vmode = FB_VMODE_NONINTERLACED,
35 static struct fb_fix_screeninfo efifb_fix = {
37 .type = FB_TYPE_PACKED_PIXELS,
38 .accel = FB_ACCEL_NONE,
39 .visual = FB_VISUAL_TRUECOLOR,
42 static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
43 unsigned blue, unsigned transp,
47 * Set a single color register. The values supplied are
48 * already rounded down to the hardware's capabilities
49 * (according to the entries in the `var' structure). Return
50 * != 0 for invalid regno.
53 if (regno >= info->cmap.len)
60 ((u32 *)(info->pseudo_palette))[regno] =
61 (red << info->var.red.offset) |
62 (green << info->var.green.offset) |
63 (blue << info->var.blue.offset);
68 static void efifb_destroy(struct fb_info *info)
70 if (info->screen_base)
71 iounmap(info->screen_base);
72 if (request_mem_succeeded)
73 release_mem_region(info->apertures->ranges[0].base,
74 info->apertures->ranges[0].size);
75 fb_dealloc_cmap(&info->cmap);
76 framebuffer_release(info);
79 static struct fb_ops efifb_ops = {
81 .fb_destroy = efifb_destroy,
82 .fb_setcolreg = efifb_setcolreg,
83 .fb_fillrect = cfb_fillrect,
84 .fb_copyarea = cfb_copyarea,
85 .fb_imageblit = cfb_imageblit,
88 struct pci_dev *vga_default_device(void)
93 EXPORT_SYMBOL_GPL(vga_default_device);
95 void vga_set_default_device(struct pci_dev *pdev)
100 static int efifb_setup(char *options)
104 struct pci_dev *dev = NULL;
106 if (options && *options) {
107 while ((this_opt = strsep(&options, ",")) != NULL) {
108 if (!*this_opt) continue;
110 for (i = 0; i < M_UNKNOWN; i++) {
111 if (!strcmp(this_opt, efifb_dmi_list[i].optname) &&
112 efifb_dmi_list[i].base != 0) {
113 screen_info.lfb_base = efifb_dmi_list[i].base;
114 screen_info.lfb_linelength = efifb_dmi_list[i].stride;
115 screen_info.lfb_width = efifb_dmi_list[i].width;
116 screen_info.lfb_height = efifb_dmi_list[i].height;
119 if (!strncmp(this_opt, "base:", 5))
120 screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
121 else if (!strncmp(this_opt, "stride:", 7))
122 screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
123 else if (!strncmp(this_opt, "height:", 7))
124 screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
125 else if (!strncmp(this_opt, "width:", 6))
126 screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
130 for_each_pci_dev(dev) {
133 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
136 for (i=0; i < DEVICE_COUNT_RESOURCE; i++) {
137 resource_size_t start, end;
139 if (!(pci_resource_flags(dev, i) & IORESOURCE_MEM))
142 start = pci_resource_start(dev, i);
143 end = pci_resource_end(dev, i);
148 if (screen_info.lfb_base >= start &&
149 (screen_info.lfb_base + screen_info.lfb_size) < end)
157 static int efifb_probe(struct platform_device *dev)
159 struct fb_info *info;
161 unsigned int size_vmode;
162 unsigned int size_remap;
163 unsigned int size_total;
166 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
169 if (fb_get_options("efifb", &option))
173 /* We don't get linelength from UGA Draw Protocol, only from
174 * EFI Graphics Protocol. So if it's not in DMI, and it's not
175 * passed in from the user, we really can't use the framebuffer.
177 if (!screen_info.lfb_linelength)
180 if (!screen_info.lfb_depth)
181 screen_info.lfb_depth = 32;
182 if (!screen_info.pages)
183 screen_info.pages = 1;
184 if (!screen_info.lfb_base) {
185 printk(KERN_DEBUG "efifb: invalid framebuffer address\n");
188 printk(KERN_INFO "efifb: probing for efifb\n");
190 /* just assume they're all unset if any are */
191 if (!screen_info.blue_size) {
192 screen_info.blue_size = 8;
193 screen_info.blue_pos = 0;
194 screen_info.green_size = 8;
195 screen_info.green_pos = 8;
196 screen_info.red_size = 8;
197 screen_info.red_pos = 16;
198 screen_info.rsvd_size = 8;
199 screen_info.rsvd_pos = 24;
202 efifb_fix.smem_start = screen_info.lfb_base;
203 efifb_defined.bits_per_pixel = screen_info.lfb_depth;
204 efifb_defined.xres = screen_info.lfb_width;
205 efifb_defined.yres = screen_info.lfb_height;
206 efifb_fix.line_length = screen_info.lfb_linelength;
208 /* size_vmode -- that is the amount of memory needed for the
209 * used video mode, i.e. the minimum amount of
211 size_vmode = efifb_defined.yres * efifb_fix.line_length;
213 /* size_total -- all video memory we have. Used for
214 * entries, ressource allocation and bounds
216 size_total = screen_info.lfb_size;
217 if (size_total < size_vmode)
218 size_total = size_vmode;
220 /* size_remap -- the amount of video memory we are going to
221 * use for efifb. With modern cards it is no
222 * option to simply use size_total as that
223 * wastes plenty of kernel address space. */
224 size_remap = size_vmode * 2;
225 if (size_remap > size_total)
226 size_remap = size_total;
227 if (size_remap % PAGE_SIZE)
228 size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE);
229 efifb_fix.smem_len = size_remap;
231 if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) {
232 request_mem_succeeded = true;
234 /* We cannot make this fatal. Sometimes this comes from magic
235 spaces our resource handlers simply don't know about */
237 "efifb: cannot reserve video memory at 0x%lx\n",
238 efifb_fix.smem_start);
241 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
243 printk(KERN_ERR "efifb: cannot allocate framebuffer\n");
245 goto err_release_mem;
247 info->pseudo_palette = info->par;
250 info->apertures = alloc_apertures(1);
251 if (!info->apertures) {
255 info->apertures->ranges[0].base = efifb_fix.smem_start;
256 info->apertures->ranges[0].size = size_remap;
258 info->screen_base = ioremap_wc(efifb_fix.smem_start, efifb_fix.smem_len);
259 if (!info->screen_base) {
260 printk(KERN_ERR "efifb: abort, cannot ioremap video memory "
262 efifb_fix.smem_len, efifb_fix.smem_start);
267 printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, "
268 "using %dk, total %dk\n",
269 efifb_fix.smem_start, info->screen_base,
270 size_remap/1024, size_total/1024);
271 printk(KERN_INFO "efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
272 efifb_defined.xres, efifb_defined.yres,
273 efifb_defined.bits_per_pixel, efifb_fix.line_length,
276 efifb_defined.xres_virtual = efifb_defined.xres;
277 efifb_defined.yres_virtual = efifb_fix.smem_len /
278 efifb_fix.line_length;
279 printk(KERN_INFO "efifb: scrolling: redraw\n");
280 efifb_defined.yres_virtual = efifb_defined.yres;
282 /* some dummy values for timing to make fbset happy */
283 efifb_defined.pixclock = 10000000 / efifb_defined.xres *
284 1000 / efifb_defined.yres;
285 efifb_defined.left_margin = (efifb_defined.xres / 8) & 0xf8;
286 efifb_defined.hsync_len = (efifb_defined.xres / 8) & 0xf8;
288 efifb_defined.red.offset = screen_info.red_pos;
289 efifb_defined.red.length = screen_info.red_size;
290 efifb_defined.green.offset = screen_info.green_pos;
291 efifb_defined.green.length = screen_info.green_size;
292 efifb_defined.blue.offset = screen_info.blue_pos;
293 efifb_defined.blue.length = screen_info.blue_size;
294 efifb_defined.transp.offset = screen_info.rsvd_pos;
295 efifb_defined.transp.length = screen_info.rsvd_size;
297 printk(KERN_INFO "efifb: %s: "
298 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
300 screen_info.rsvd_size,
301 screen_info.red_size,
302 screen_info.green_size,
303 screen_info.blue_size,
304 screen_info.rsvd_pos,
306 screen_info.green_pos,
307 screen_info.blue_pos);
309 efifb_fix.ypanstep = 0;
310 efifb_fix.ywrapstep = 0;
312 info->fbops = &efifb_ops;
313 info->var = efifb_defined;
314 info->fix = efifb_fix;
315 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE;
317 if ((err = fb_alloc_cmap(&info->cmap, 256, 0)) < 0) {
318 printk(KERN_ERR "efifb: cannot allocate colormap\n");
321 if ((err = register_framebuffer(info)) < 0) {
322 printk(KERN_ERR "efifb: cannot register framebuffer\n");
325 printk(KERN_INFO "fb%d: %s frame buffer device\n",
326 info->node, info->fix.id);
330 fb_dealloc_cmap(&info->cmap);
332 iounmap(info->screen_base);
334 framebuffer_release(info);
336 if (request_mem_succeeded)
337 release_mem_region(efifb_fix.smem_start, size_total);
341 static struct platform_driver efifb_driver = {
343 .name = "efi-framebuffer",
344 .owner = THIS_MODULE,
346 .probe = efifb_probe,
349 module_platform_driver(efifb_driver);
350 MODULE_LICENSE("GPL");