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 fb_var_screeninfo efifb_defined = {
23 .activate = FB_ACTIVATE_NOW,
30 .vmode = FB_VMODE_NONINTERLACED,
33 static struct fb_fix_screeninfo efifb_fix = {
35 .type = FB_TYPE_PACKED_PIXELS,
36 .accel = FB_ACCEL_NONE,
37 .visual = FB_VISUAL_TRUECOLOR,
40 static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
41 unsigned blue, unsigned transp,
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.
51 if (regno >= info->cmap.len)
58 ((u32 *)(info->pseudo_palette))[regno] =
59 (red << info->var.red.offset) |
60 (green << info->var.green.offset) |
61 (blue << info->var.blue.offset);
66 static void efifb_destroy(struct fb_info *info)
68 if (info->screen_base)
69 iounmap(info->screen_base);
70 if (request_mem_succeeded)
71 release_mem_region(info->apertures->ranges[0].base,
72 info->apertures->ranges[0].size);
73 fb_dealloc_cmap(&info->cmap);
76 static struct fb_ops efifb_ops = {
78 .fb_destroy = efifb_destroy,
79 .fb_setcolreg = efifb_setcolreg,
80 .fb_fillrect = cfb_fillrect,
81 .fb_copyarea = cfb_copyarea,
82 .fb_imageblit = cfb_imageblit,
85 static int efifb_setup(char *options)
90 if (options && *options) {
91 while ((this_opt = strsep(&options, ",")) != NULL) {
92 if (!*this_opt) continue;
94 for (i = 0; i < M_UNKNOWN; i++) {
95 if (efifb_dmi_list[i].base != 0 &&
96 !strcmp(this_opt, efifb_dmi_list[i].optname)) {
97 screen_info.lfb_base = efifb_dmi_list[i].base;
98 screen_info.lfb_linelength = efifb_dmi_list[i].stride;
99 screen_info.lfb_width = efifb_dmi_list[i].width;
100 screen_info.lfb_height = efifb_dmi_list[i].height;
103 if (!strncmp(this_opt, "base:", 5))
104 screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
105 else if (!strncmp(this_opt, "stride:", 7))
106 screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
107 else if (!strncmp(this_opt, "height:", 7))
108 screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
109 else if (!strncmp(this_opt, "width:", 6))
110 screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
117 static int efifb_probe(struct platform_device *dev)
119 struct fb_info *info;
121 unsigned int size_vmode;
122 unsigned int size_remap;
123 unsigned int size_total;
126 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
129 if (fb_get_options("efifb", &option))
133 /* We don't get linelength from UGA Draw Protocol, only from
134 * EFI Graphics Protocol. So if it's not in DMI, and it's not
135 * passed in from the user, we really can't use the framebuffer.
137 if (!screen_info.lfb_linelength)
140 if (!screen_info.lfb_depth)
141 screen_info.lfb_depth = 32;
142 if (!screen_info.pages)
143 screen_info.pages = 1;
144 if (!screen_info.lfb_base) {
145 printk(KERN_DEBUG "efifb: invalid framebuffer address\n");
148 printk(KERN_INFO "efifb: probing for efifb\n");
150 /* just assume they're all unset if any are */
151 if (!screen_info.blue_size) {
152 screen_info.blue_size = 8;
153 screen_info.blue_pos = 0;
154 screen_info.green_size = 8;
155 screen_info.green_pos = 8;
156 screen_info.red_size = 8;
157 screen_info.red_pos = 16;
158 screen_info.rsvd_size = 8;
159 screen_info.rsvd_pos = 24;
162 efifb_fix.smem_start = screen_info.lfb_base;
163 efifb_defined.bits_per_pixel = screen_info.lfb_depth;
164 efifb_defined.xres = screen_info.lfb_width;
165 efifb_defined.yres = screen_info.lfb_height;
166 efifb_fix.line_length = screen_info.lfb_linelength;
168 /* size_vmode -- that is the amount of memory needed for the
169 * used video mode, i.e. the minimum amount of
171 size_vmode = efifb_defined.yres * efifb_fix.line_length;
173 /* size_total -- all video memory we have. Used for
174 * entries, ressource allocation and bounds
176 size_total = screen_info.lfb_size;
177 if (size_total < size_vmode)
178 size_total = size_vmode;
180 /* size_remap -- the amount of video memory we are going to
181 * use for efifb. With modern cards it is no
182 * option to simply use size_total as that
183 * wastes plenty of kernel address space. */
184 size_remap = size_vmode * 2;
185 if (size_remap > size_total)
186 size_remap = size_total;
187 if (size_remap % PAGE_SIZE)
188 size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE);
189 efifb_fix.smem_len = size_remap;
191 if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) {
192 request_mem_succeeded = true;
194 /* We cannot make this fatal. Sometimes this comes from magic
195 spaces our resource handlers simply don't know about */
197 "efifb: cannot reserve video memory at 0x%lx\n",
198 efifb_fix.smem_start);
201 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
203 printk(KERN_ERR "efifb: cannot allocate framebuffer\n");
205 goto err_release_mem;
207 platform_set_drvdata(dev, info);
208 info->pseudo_palette = info->par;
211 info->apertures = alloc_apertures(1);
212 if (!info->apertures) {
216 info->apertures->ranges[0].base = efifb_fix.smem_start;
217 info->apertures->ranges[0].size = size_remap;
219 info->screen_base = ioremap_wc(efifb_fix.smem_start, efifb_fix.smem_len);
220 if (!info->screen_base) {
221 printk(KERN_ERR "efifb: abort, cannot ioremap video memory "
223 efifb_fix.smem_len, efifb_fix.smem_start);
228 printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, "
229 "using %dk, total %dk\n",
230 efifb_fix.smem_start, info->screen_base,
231 size_remap/1024, size_total/1024);
232 printk(KERN_INFO "efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
233 efifb_defined.xres, efifb_defined.yres,
234 efifb_defined.bits_per_pixel, efifb_fix.line_length,
237 efifb_defined.xres_virtual = efifb_defined.xres;
238 efifb_defined.yres_virtual = efifb_fix.smem_len /
239 efifb_fix.line_length;
240 printk(KERN_INFO "efifb: scrolling: redraw\n");
241 efifb_defined.yres_virtual = efifb_defined.yres;
243 /* some dummy values for timing to make fbset happy */
244 efifb_defined.pixclock = 10000000 / efifb_defined.xres *
245 1000 / efifb_defined.yres;
246 efifb_defined.left_margin = (efifb_defined.xres / 8) & 0xf8;
247 efifb_defined.hsync_len = (efifb_defined.xres / 8) & 0xf8;
249 efifb_defined.red.offset = screen_info.red_pos;
250 efifb_defined.red.length = screen_info.red_size;
251 efifb_defined.green.offset = screen_info.green_pos;
252 efifb_defined.green.length = screen_info.green_size;
253 efifb_defined.blue.offset = screen_info.blue_pos;
254 efifb_defined.blue.length = screen_info.blue_size;
255 efifb_defined.transp.offset = screen_info.rsvd_pos;
256 efifb_defined.transp.length = screen_info.rsvd_size;
258 printk(KERN_INFO "efifb: %s: "
259 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
261 screen_info.rsvd_size,
262 screen_info.red_size,
263 screen_info.green_size,
264 screen_info.blue_size,
265 screen_info.rsvd_pos,
267 screen_info.green_pos,
268 screen_info.blue_pos);
270 efifb_fix.ypanstep = 0;
271 efifb_fix.ywrapstep = 0;
273 info->fbops = &efifb_ops;
274 info->var = efifb_defined;
275 info->fix = efifb_fix;
276 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE;
278 if ((err = fb_alloc_cmap(&info->cmap, 256, 0)) < 0) {
279 printk(KERN_ERR "efifb: cannot allocate colormap\n");
282 if ((err = register_framebuffer(info)) < 0) {
283 printk(KERN_ERR "efifb: cannot register framebuffer\n");
286 fb_info(info, "%s frame buffer device\n", info->fix.id);
290 fb_dealloc_cmap(&info->cmap);
292 iounmap(info->screen_base);
294 framebuffer_release(info);
296 if (request_mem_succeeded)
297 release_mem_region(efifb_fix.smem_start, size_total);
301 static int efifb_remove(struct platform_device *pdev)
303 struct fb_info *info = platform_get_drvdata(pdev);
305 unregister_framebuffer(info);
306 framebuffer_release(info);
311 static struct platform_driver efifb_driver = {
313 .name = "efi-framebuffer",
314 .owner = THIS_MODULE,
316 .probe = efifb_probe,
317 .remove = efifb_remove,
320 module_platform_driver(efifb_driver);
321 MODULE_LICENSE("GPL");