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 inline bool fb_base_is_valid(void)
119 if (screen_info
.lfb_base
)
122 if (!(screen_info
.capabilities
& VIDEO_CAPABILITY_64BIT_BASE
))
125 if (screen_info
.ext_lfb_base
)
131 static int efifb_probe(struct platform_device
*dev
)
133 struct fb_info
*info
;
135 unsigned int size_vmode
;
136 unsigned int size_remap
;
137 unsigned int size_total
;
140 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_EFI
)
143 if (fb_get_options("efifb", &option
))
147 /* We don't get linelength from UGA Draw Protocol, only from
148 * EFI Graphics Protocol. So if it's not in DMI, and it's not
149 * passed in from the user, we really can't use the framebuffer.
151 if (!screen_info
.lfb_linelength
)
154 if (!screen_info
.lfb_depth
)
155 screen_info
.lfb_depth
= 32;
156 if (!screen_info
.pages
)
157 screen_info
.pages
= 1;
158 if (!fb_base_is_valid()) {
159 printk(KERN_DEBUG
"efifb: invalid framebuffer address\n");
162 printk(KERN_INFO
"efifb: probing for efifb\n");
164 /* just assume they're all unset if any are */
165 if (!screen_info
.blue_size
) {
166 screen_info
.blue_size
= 8;
167 screen_info
.blue_pos
= 0;
168 screen_info
.green_size
= 8;
169 screen_info
.green_pos
= 8;
170 screen_info
.red_size
= 8;
171 screen_info
.red_pos
= 16;
172 screen_info
.rsvd_size
= 8;
173 screen_info
.rsvd_pos
= 24;
176 efifb_fix
.smem_start
= screen_info
.lfb_base
;
178 if (screen_info
.capabilities
& VIDEO_CAPABILITY_64BIT_BASE
) {
181 ext_lfb_base
= (u64
)(unsigned long)screen_info
.ext_lfb_base
<< 32;
182 efifb_fix
.smem_start
|= ext_lfb_base
;
185 efifb_defined
.bits_per_pixel
= screen_info
.lfb_depth
;
186 efifb_defined
.xres
= screen_info
.lfb_width
;
187 efifb_defined
.yres
= screen_info
.lfb_height
;
188 efifb_fix
.line_length
= screen_info
.lfb_linelength
;
190 /* size_vmode -- that is the amount of memory needed for the
191 * used video mode, i.e. the minimum amount of
193 size_vmode
= efifb_defined
.yres
* efifb_fix
.line_length
;
195 /* size_total -- all video memory we have. Used for
196 * entries, ressource allocation and bounds
198 size_total
= screen_info
.lfb_size
;
199 if (size_total
< size_vmode
)
200 size_total
= size_vmode
;
202 /* size_remap -- the amount of video memory we are going to
203 * use for efifb. With modern cards it is no
204 * option to simply use size_total as that
205 * wastes plenty of kernel address space. */
206 size_remap
= size_vmode
* 2;
207 if (size_remap
> size_total
)
208 size_remap
= size_total
;
209 if (size_remap
% PAGE_SIZE
)
210 size_remap
+= PAGE_SIZE
- (size_remap
% PAGE_SIZE
);
211 efifb_fix
.smem_len
= size_remap
;
213 if (request_mem_region(efifb_fix
.smem_start
, size_remap
, "efifb")) {
214 request_mem_succeeded
= true;
216 /* We cannot make this fatal. Sometimes this comes from magic
217 spaces our resource handlers simply don't know about */
219 "efifb: cannot reserve video memory at 0x%lx\n",
220 efifb_fix
.smem_start
);
223 info
= framebuffer_alloc(sizeof(u32
) * 16, &dev
->dev
);
225 printk(KERN_ERR
"efifb: cannot allocate framebuffer\n");
227 goto err_release_mem
;
229 platform_set_drvdata(dev
, info
);
230 info
->pseudo_palette
= info
->par
;
233 info
->apertures
= alloc_apertures(1);
234 if (!info
->apertures
) {
238 info
->apertures
->ranges
[0].base
= efifb_fix
.smem_start
;
239 info
->apertures
->ranges
[0].size
= size_remap
;
241 info
->screen_base
= ioremap_wc(efifb_fix
.smem_start
, efifb_fix
.smem_len
);
242 if (!info
->screen_base
) {
243 printk(KERN_ERR
"efifb: abort, cannot ioremap video memory "
245 efifb_fix
.smem_len
, efifb_fix
.smem_start
);
250 printk(KERN_INFO
"efifb: framebuffer at 0x%lx, mapped to 0x%p, "
251 "using %dk, total %dk\n",
252 efifb_fix
.smem_start
, info
->screen_base
,
253 size_remap
/1024, size_total
/1024);
254 printk(KERN_INFO
"efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
255 efifb_defined
.xres
, efifb_defined
.yres
,
256 efifb_defined
.bits_per_pixel
, efifb_fix
.line_length
,
259 efifb_defined
.xres_virtual
= efifb_defined
.xres
;
260 efifb_defined
.yres_virtual
= efifb_fix
.smem_len
/
261 efifb_fix
.line_length
;
262 printk(KERN_INFO
"efifb: scrolling: redraw\n");
263 efifb_defined
.yres_virtual
= efifb_defined
.yres
;
265 /* some dummy values for timing to make fbset happy */
266 efifb_defined
.pixclock
= 10000000 / efifb_defined
.xres
*
267 1000 / efifb_defined
.yres
;
268 efifb_defined
.left_margin
= (efifb_defined
.xres
/ 8) & 0xf8;
269 efifb_defined
.hsync_len
= (efifb_defined
.xres
/ 8) & 0xf8;
271 efifb_defined
.red
.offset
= screen_info
.red_pos
;
272 efifb_defined
.red
.length
= screen_info
.red_size
;
273 efifb_defined
.green
.offset
= screen_info
.green_pos
;
274 efifb_defined
.green
.length
= screen_info
.green_size
;
275 efifb_defined
.blue
.offset
= screen_info
.blue_pos
;
276 efifb_defined
.blue
.length
= screen_info
.blue_size
;
277 efifb_defined
.transp
.offset
= screen_info
.rsvd_pos
;
278 efifb_defined
.transp
.length
= screen_info
.rsvd_size
;
280 printk(KERN_INFO
"efifb: %s: "
281 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
283 screen_info
.rsvd_size
,
284 screen_info
.red_size
,
285 screen_info
.green_size
,
286 screen_info
.blue_size
,
287 screen_info
.rsvd_pos
,
289 screen_info
.green_pos
,
290 screen_info
.blue_pos
);
292 efifb_fix
.ypanstep
= 0;
293 efifb_fix
.ywrapstep
= 0;
295 info
->fbops
= &efifb_ops
;
296 info
->var
= efifb_defined
;
297 info
->fix
= efifb_fix
;
298 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_MISC_FIRMWARE
;
300 if ((err
= fb_alloc_cmap(&info
->cmap
, 256, 0)) < 0) {
301 printk(KERN_ERR
"efifb: cannot allocate colormap\n");
304 if ((err
= register_framebuffer(info
)) < 0) {
305 printk(KERN_ERR
"efifb: cannot register framebuffer\n");
308 fb_info(info
, "%s frame buffer device\n", info
->fix
.id
);
312 fb_dealloc_cmap(&info
->cmap
);
314 iounmap(info
->screen_base
);
316 framebuffer_release(info
);
318 if (request_mem_succeeded
)
319 release_mem_region(efifb_fix
.smem_start
, size_total
);
323 static int efifb_remove(struct platform_device
*pdev
)
325 struct fb_info
*info
= platform_get_drvdata(pdev
);
327 unregister_framebuffer(info
);
328 framebuffer_release(info
);
333 static struct platform_driver efifb_driver
= {
335 .name
= "efi-framebuffer",
337 .probe
= efifb_probe
,
338 .remove
= efifb_remove
,
341 module_platform_driver(efifb_driver
);
342 MODULE_LICENSE("GPL");