2 * linux/drivers/video/fbmem.c
4 * Copyright (C) 1994 Martin Schaller
6 * 2001 - Documented with DocBook
7 * - Brad Douglas <brad@neruo.com>
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive
14 #include <linux/config.h>
15 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/smp_lock.h>
21 #include <linux/kernel.h>
22 #include <linux/major.h>
23 #include <linux/slab.h>
25 #include <linux/mman.h>
26 #include <linux/tty.h>
27 #include <linux/init.h>
28 #include <linux/linux_logo.h>
29 #include <linux/proc_fs.h>
30 #include <linux/console.h>
32 #include <linux/kmod.h>
34 #include <linux/devfs_fs_kernel.h>
35 #include <linux/err.h>
36 #include <linux/kernel.h>
37 #include <linux/device.h>
38 #include <linux/efi.h>
40 #if defined(__mc68000__) || defined(CONFIG_APUS)
41 #include <asm/setup.h>
45 #include <asm/uaccess.h>
47 #include <asm/pgtable.h>
52 * Frame buffer device initialization and setup routines
55 #define FBPIXMAPSIZE (1024 * 8)
57 static struct notifier_block
*fb_notifier_list
;
58 struct fb_info
*registered_fb
[FB_MAX
];
59 int num_registered_fb
;
65 int fb_get_color_depth(struct fb_var_screeninfo
*var
,
66 struct fb_fix_screeninfo
*fix
)
70 if (fix
->visual
== FB_VISUAL_MONO01
||
71 fix
->visual
== FB_VISUAL_MONO10
)
74 if (var
->green
.length
== var
->blue
.length
&&
75 var
->green
.length
== var
->red
.length
&&
76 var
->green
.offset
== var
->blue
.offset
&&
77 var
->green
.offset
== var
->red
.offset
)
78 depth
= var
->green
.length
;
80 depth
= var
->green
.length
+ var
->red
.length
+
86 EXPORT_SYMBOL(fb_get_color_depth
);
89 * Data padding functions.
91 void fb_pad_aligned_buffer(u8
*dst
, u32 d_pitch
, u8
*src
, u32 s_pitch
, u32 height
)
93 __fb_pad_aligned_buffer(dst
, d_pitch
, src
, s_pitch
, height
);
95 EXPORT_SYMBOL(fb_pad_aligned_buffer
);
97 void fb_pad_unaligned_buffer(u8
*dst
, u32 d_pitch
, u8
*src
, u32 idx
, u32 height
,
98 u32 shift_high
, u32 shift_low
, u32 mod
)
100 u8 mask
= (u8
) (0xfff << shift_high
), tmp
;
103 for (i
= height
; i
--; ) {
104 for (j
= 0; j
< idx
; j
++) {
107 tmp
|= *src
>> shift_low
;
109 tmp
= *src
<< shift_high
;
115 tmp
|= *src
>> shift_low
;
117 if (shift_high
< mod
) {
118 tmp
= *src
<< shift_high
;
125 EXPORT_SYMBOL(fb_pad_unaligned_buffer
);
128 * we need to lock this section since fb_cursor
129 * may use fb_imageblit()
131 char* fb_get_buffer_offset(struct fb_info
*info
, struct fb_pixmap
*buf
, u32 size
)
133 u32 align
= buf
->buf_align
- 1, offset
;
134 char *addr
= buf
->addr
;
136 /* If IO mapped, we need to sync before access, no sharing of
139 if (buf
->flags
& FB_PIXMAP_IO
) {
140 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
141 info
->fbops
->fb_sync(info
);
145 /* See if we fit in the remaining pixmap space */
146 offset
= buf
->offset
+ align
;
148 if (offset
+ size
> buf
->size
) {
149 /* We do not fit. In order to be able to re-use the buffer,
150 * we must ensure no asynchronous DMA'ing or whatever operation
151 * is in progress, we sync for that.
153 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
154 info
->fbops
->fb_sync(info
);
157 buf
->offset
= offset
+ size
;
164 #include <linux/linux_logo.h>
166 static inline unsigned safe_shift(unsigned d
, int n
)
168 return n
< 0 ? d
>> -n
: d
<< n
;
171 static void fb_set_logocmap(struct fb_info
*info
,
172 const struct linux_logo
*logo
)
174 struct fb_cmap palette_cmap
;
175 u16 palette_green
[16];
176 u16 palette_blue
[16];
179 const unsigned char *clut
= logo
->clut
;
181 palette_cmap
.start
= 0;
182 palette_cmap
.len
= 16;
183 palette_cmap
.red
= palette_red
;
184 palette_cmap
.green
= palette_green
;
185 palette_cmap
.blue
= palette_blue
;
186 palette_cmap
.transp
= NULL
;
188 for (i
= 0; i
< logo
->clutsize
; i
+= n
) {
189 n
= logo
->clutsize
- i
;
190 /* palette_cmap provides space for only 16 colors at once */
193 palette_cmap
.start
= 32 + i
;
194 palette_cmap
.len
= n
;
195 for (j
= 0; j
< n
; ++j
) {
196 palette_cmap
.red
[j
] = clut
[0] << 8 | clut
[0];
197 palette_cmap
.green
[j
] = clut
[1] << 8 | clut
[1];
198 palette_cmap
.blue
[j
] = clut
[2] << 8 | clut
[2];
201 fb_set_cmap(&palette_cmap
, info
);
205 static void fb_set_logo_truepalette(struct fb_info
*info
,
206 const struct linux_logo
*logo
,
209 unsigned char mask
[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
210 unsigned char redmask
, greenmask
, bluemask
;
211 int redshift
, greenshift
, blueshift
;
213 const unsigned char *clut
= logo
->clut
;
216 * We have to create a temporary palette since console palette is only
219 /* Bug: Doesn't obey msb_right ... (who needs that?) */
220 redmask
= mask
[info
->var
.red
.length
< 8 ? info
->var
.red
.length
: 8];
221 greenmask
= mask
[info
->var
.green
.length
< 8 ? info
->var
.green
.length
: 8];
222 bluemask
= mask
[info
->var
.blue
.length
< 8 ? info
->var
.blue
.length
: 8];
223 redshift
= info
->var
.red
.offset
- (8 - info
->var
.red
.length
);
224 greenshift
= info
->var
.green
.offset
- (8 - info
->var
.green
.length
);
225 blueshift
= info
->var
.blue
.offset
- (8 - info
->var
.blue
.length
);
227 for ( i
= 0; i
< logo
->clutsize
; i
++) {
228 palette
[i
+32] = (safe_shift((clut
[0] & redmask
), redshift
) |
229 safe_shift((clut
[1] & greenmask
), greenshift
) |
230 safe_shift((clut
[2] & bluemask
), blueshift
));
235 static void fb_set_logo_directpalette(struct fb_info
*info
,
236 const struct linux_logo
*logo
,
239 int redshift
, greenshift
, blueshift
;
242 redshift
= info
->var
.red
.offset
;
243 greenshift
= info
->var
.green
.offset
;
244 blueshift
= info
->var
.blue
.offset
;
246 for (i
= 32; i
< logo
->clutsize
; i
++)
247 palette
[i
] = i
<< redshift
| i
<< greenshift
| i
<< blueshift
;
250 static void fb_set_logo(struct fb_info
*info
,
251 const struct linux_logo
*logo
, u8
*dst
,
255 const u8
*src
= logo
->data
;
256 u8
xor = (info
->fix
.visual
== FB_VISUAL_MONO01
) ? 0xff : 0;
259 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 3)
262 if (info
->fix
.visual
== FB_VISUAL_MONO01
||
263 info
->fix
.visual
== FB_VISUAL_MONO10
)
264 fg
= ~((u8
) (0xfff << info
->var
.green
.length
));
268 for (i
= 0; i
< logo
->height
; i
++)
269 for (j
= 0; j
< logo
->width
; src
++) {
272 if (j
< logo
->width
) {
273 *dst
++ = *src
& 0x0f;
279 for (i
= 0; i
< logo
->height
; i
++) {
280 for (j
= 0; j
< logo
->width
; src
++) {
282 for (k
= 7; k
>= 0; k
--) {
283 *dst
++ = ((d
>> k
) & 1) ? fg
: 0;
293 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
294 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
295 * the visual format and color depth of the framebuffer, the DAC, the
296 * pseudo_palette, and the logo data will be adjusted accordingly.
298 * Case 1 - linux_logo_clut224:
299 * Color exceeds the number of console colors (16), thus we set the hardware DAC
300 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
302 * For visuals that require color info from the pseudo_palette, we also construct
303 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
306 * Case 2 - linux_logo_vga16:
307 * The number of colors just matches the console colors, thus there is no need
308 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
309 * each byte contains color information for two pixels (upper and lower nibble).
310 * To be consistent with fb_imageblit() usage, we therefore separate the two
311 * nibbles into separate bytes. The "depth" flag will be set to 4.
313 * Case 3 - linux_logo_mono:
314 * This is similar with Case 2. Each byte contains information for 8 pixels.
315 * We isolate each bit and expand each into a byte. The "depth" flag will
318 static struct logo_data
{
320 int needs_directpalette
;
321 int needs_truepalette
;
323 const struct linux_logo
*logo
;
326 static void fb_rotate_logo_ud(const u8
*in
, u8
*out
, u32 width
, u32 height
)
328 u32 size
= width
* height
, i
;
332 for (i
= size
; i
--; )
336 static void fb_rotate_logo_cw(const u8
*in
, u8
*out
, u32 width
, u32 height
)
338 int i
, j
, w
= width
- 1;
340 for (i
= 0; i
< height
; i
++)
341 for (j
= 0; j
< width
; j
++)
342 out
[height
* j
+ w
- i
] = *in
++;
345 static void fb_rotate_logo_ccw(const u8
*in
, u8
*out
, u32 width
, u32 height
)
347 int i
, j
, w
= width
- 1;
349 for (i
= 0; i
< height
; i
++)
350 for (j
= 0; j
< width
; j
++)
351 out
[height
* (w
- j
) + i
] = *in
++;
354 static void fb_rotate_logo(struct fb_info
*info
, u8
*dst
,
355 struct fb_image
*image
, int rotate
)
359 if (rotate
== FB_ROTATE_UD
) {
360 image
->dx
= info
->var
.xres
- image
->width
;
361 image
->dy
= info
->var
.yres
- image
->height
;
362 fb_rotate_logo_ud(image
->data
, dst
, image
->width
,
364 } else if (rotate
== FB_ROTATE_CW
) {
366 image
->width
= image
->height
;
368 image
->dx
= info
->var
.xres
- image
->height
;
369 fb_rotate_logo_cw(image
->data
, dst
, image
->width
,
371 } else if (rotate
== FB_ROTATE_CCW
) {
373 image
->width
= image
->height
;
375 image
->dy
= info
->var
.yres
- image
->width
;
376 fb_rotate_logo_ccw(image
->data
, dst
, image
->width
,
383 static void fb_do_show_logo(struct fb_info
*info
, struct fb_image
*image
,
388 if (rotate
== FB_ROTATE_UR
) {
389 for (x
= 0; x
< num_online_cpus() &&
390 x
* (fb_logo
.logo
->width
+ 8) <=
391 info
->var
.xres
- fb_logo
.logo
->width
; x
++) {
392 info
->fbops
->fb_imageblit(info
, image
);
393 image
->dx
+= fb_logo
.logo
->width
+ 8;
395 } else if (rotate
== FB_ROTATE_UD
) {
396 for (x
= 0; x
< num_online_cpus() &&
397 x
* (fb_logo
.logo
->width
+ 8) <=
398 info
->var
.xres
- fb_logo
.logo
->width
; x
++) {
399 info
->fbops
->fb_imageblit(info
, image
);
400 image
->dx
-= fb_logo
.logo
->width
+ 8;
402 } else if (rotate
== FB_ROTATE_CW
) {
403 for (x
= 0; x
< num_online_cpus() &&
404 x
* (fb_logo
.logo
->width
+ 8) <=
405 info
->var
.yres
- fb_logo
.logo
->width
; x
++) {
406 info
->fbops
->fb_imageblit(info
, image
);
407 image
->dy
+= fb_logo
.logo
->width
+ 8;
409 } else if (rotate
== FB_ROTATE_CCW
) {
410 for (x
= 0; x
< num_online_cpus() &&
411 x
* (fb_logo
.logo
->width
+ 8) <=
412 info
->var
.yres
- fb_logo
.logo
->width
; x
++) {
413 info
->fbops
->fb_imageblit(info
, image
);
414 image
->dy
-= fb_logo
.logo
->width
+ 8;
419 int fb_prepare_logo(struct fb_info
*info
, int rotate
)
421 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
424 memset(&fb_logo
, 0, sizeof(struct logo_data
));
426 if (info
->flags
& FBINFO_MISC_TILEBLITTING
)
429 if (info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
430 depth
= info
->var
.blue
.length
;
431 if (info
->var
.red
.length
< depth
)
432 depth
= info
->var
.red
.length
;
433 if (info
->var
.green
.length
< depth
)
434 depth
= info
->var
.green
.length
;
438 switch (info
->fix
.visual
) {
439 case FB_VISUAL_TRUECOLOR
:
440 fb_logo
.needs_truepalette
= 1;
442 case FB_VISUAL_DIRECTCOLOR
:
443 fb_logo
.needs_directpalette
= 1;
444 fb_logo
.needs_cmapreset
= 1;
446 case FB_VISUAL_PSEUDOCOLOR
:
447 fb_logo
.needs_cmapreset
= 1;
452 /* Return if no suitable logo was found */
453 fb_logo
.logo
= fb_find_logo(depth
);
455 if (rotate
== FB_ROTATE_UR
|| rotate
== FB_ROTATE_UD
)
456 yres
= info
->var
.yres
;
458 yres
= info
->var
.xres
;
460 if (fb_logo
.logo
&& fb_logo
.logo
->height
> yres
) {
465 /* What depth we asked for might be different from what we get */
466 if (fb_logo
.logo
->type
== LINUX_LOGO_CLUT224
)
468 else if (fb_logo
.logo
->type
== LINUX_LOGO_VGA16
)
472 return fb_logo
.logo
->height
;
475 int fb_show_logo(struct fb_info
*info
, int rotate
)
477 u32
*palette
= NULL
, *saved_pseudo_palette
= NULL
;
478 unsigned char *logo_new
= NULL
, *logo_rotate
= NULL
;
479 struct fb_image image
;
481 /* Return if the frame buffer is not mapped or suspended */
482 if (fb_logo
.logo
== NULL
|| info
->state
!= FBINFO_STATE_RUNNING
)
486 image
.data
= fb_logo
.logo
->data
;
488 if (fb_logo
.needs_cmapreset
)
489 fb_set_logocmap(info
, fb_logo
.logo
);
491 if (fb_logo
.needs_truepalette
||
492 fb_logo
.needs_directpalette
) {
493 palette
= kmalloc(256 * 4, GFP_KERNEL
);
497 if (fb_logo
.needs_truepalette
)
498 fb_set_logo_truepalette(info
, fb_logo
.logo
, palette
);
500 fb_set_logo_directpalette(info
, fb_logo
.logo
, palette
);
502 saved_pseudo_palette
= info
->pseudo_palette
;
503 info
->pseudo_palette
= palette
;
506 if (fb_logo
.depth
<= 4) {
507 logo_new
= kmalloc(fb_logo
.logo
->width
* fb_logo
.logo
->height
,
509 if (logo_new
== NULL
) {
511 if (saved_pseudo_palette
)
512 info
->pseudo_palette
= saved_pseudo_palette
;
515 image
.data
= logo_new
;
516 fb_set_logo(info
, fb_logo
.logo
, logo_new
, fb_logo
.depth
);
521 image
.width
= fb_logo
.logo
->width
;
522 image
.height
= fb_logo
.logo
->height
;
525 logo_rotate
= kmalloc(fb_logo
.logo
->width
*
526 fb_logo
.logo
->height
, GFP_KERNEL
);
528 fb_rotate_logo(info
, logo_rotate
, &image
, rotate
);
531 fb_do_show_logo(info
, &image
, rotate
);
534 if (saved_pseudo_palette
!= NULL
)
535 info
->pseudo_palette
= saved_pseudo_palette
;
538 return fb_logo
.logo
->height
;
541 int fb_prepare_logo(struct fb_info
*info
, int rotate
) { return 0; }
542 int fb_show_logo(struct fb_info
*info
, int rotate
) { return 0; }
543 #endif /* CONFIG_LOGO */
545 static int fbmem_read_proc(char *buf
, char **start
, off_t offset
,
546 int len
, int *eof
, void *private)
552 for (fi
= registered_fb
; fi
< ®istered_fb
[FB_MAX
] && len
< 4000; fi
++)
554 clen
+= sprintf(buf
+ clen
, "%d %s\n",
557 *start
= buf
+ offset
;
562 return clen
< len
? clen
: len
;
566 fb_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
568 unsigned long p
= *ppos
;
569 struct inode
*inode
= file
->f_dentry
->d_inode
;
570 int fbidx
= iminor(inode
);
571 struct fb_info
*info
= registered_fb
[fbidx
];
574 int c
, i
, cnt
= 0, err
= 0;
575 unsigned long total_size
;
577 if (!info
|| ! info
->screen_base
)
580 if (info
->state
!= FBINFO_STATE_RUNNING
)
583 if (info
->fbops
->fb_read
)
584 return info
->fbops
->fb_read(file
, buf
, count
, ppos
);
586 total_size
= info
->screen_size
;
588 total_size
= info
->fix
.smem_len
;
592 if (count
>= total_size
)
594 if (count
+ p
> total_size
)
595 count
= total_size
- p
;
598 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
603 src
= (u32 __iomem
*) (info
->screen_base
+ p
);
605 if (info
->fbops
->fb_sync
)
606 info
->fbops
->fb_sync(info
);
609 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
611 for (i
= c
>> 2; i
--; )
612 *dst
++ = fb_readl(src
++);
614 u8
*dst8
= (u8
*) dst
;
615 u8 __iomem
*src8
= (u8 __iomem
*) src
;
617 for (i
= c
& 3; i
--;)
618 *dst8
++ = fb_readb(src8
++);
620 src
= (u32 __iomem
*) src8
;
623 if (copy_to_user(buf
, buffer
, c
)) {
634 return (err
) ? err
: cnt
;
638 fb_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
640 unsigned long p
= *ppos
;
641 struct inode
*inode
= file
->f_dentry
->d_inode
;
642 int fbidx
= iminor(inode
);
643 struct fb_info
*info
= registered_fb
[fbidx
];
646 int c
, i
, cnt
= 0, err
;
647 unsigned long total_size
;
649 if (!info
|| !info
->screen_base
)
652 if (info
->state
!= FBINFO_STATE_RUNNING
)
655 if (info
->fbops
->fb_write
)
656 return info
->fbops
->fb_write(file
, buf
, count
, ppos
);
658 total_size
= info
->screen_size
;
660 total_size
= info
->fix
.smem_len
;
664 if (count
>= total_size
)
667 if (count
+ p
> total_size
) {
668 count
= total_size
- p
;
672 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
677 dst
= (u32 __iomem
*) (info
->screen_base
+ p
);
679 if (info
->fbops
->fb_sync
)
680 info
->fbops
->fb_sync(info
);
683 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
685 if (copy_from_user(src
, buf
, c
)) {
689 for (i
= c
>> 2; i
--; )
690 fb_writel(*src
++, dst
++);
692 u8
*src8
= (u8
*) src
;
693 u8 __iomem
*dst8
= (u8 __iomem
*) dst
;
695 for (i
= c
& 3; i
--; )
696 fb_writeb(*src8
++, dst8
++);
698 dst
= (u32 __iomem
*) dst8
;
707 return (err
) ? err
: cnt
;
711 static void try_to_load(int fb
)
713 request_module("fb%d", fb
);
715 #endif /* CONFIG_KMOD */
718 fb_pan_display(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
720 int xoffset
= var
->xoffset
;
721 int yoffset
= var
->yoffset
;
724 if (xoffset
< 0 || yoffset
< 0 || !info
->fbops
->fb_pan_display
||
725 xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
||
726 yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
728 if ((err
= info
->fbops
->fb_pan_display(var
, info
)))
730 info
->var
.xoffset
= var
->xoffset
;
731 info
->var
.yoffset
= var
->yoffset
;
732 if (var
->vmode
& FB_VMODE_YWRAP
)
733 info
->var
.vmode
|= FB_VMODE_YWRAP
;
735 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
740 fb_set_var(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
742 int err
, flags
= info
->flags
;
744 if (var
->activate
& FB_ACTIVATE_INV_MODE
) {
745 struct fb_videomode mode1
, mode2
;
748 fb_var_to_videomode(&mode1
, var
);
749 fb_var_to_videomode(&mode2
, &info
->var
);
750 /* make sure we don't delete the videomode of current var */
751 ret
= fb_mode_is_equal(&mode1
, &mode2
);
754 struct fb_event event
;
758 ret
= notifier_call_chain(&fb_notifier_list
,
759 FB_EVENT_MODE_DELETE
, &event
);
763 fb_delete_videomode(&mode1
, &info
->modelist
);
768 if ((var
->activate
& FB_ACTIVATE_FORCE
) ||
769 memcmp(&info
->var
, var
, sizeof(struct fb_var_screeninfo
))) {
770 if (!info
->fbops
->fb_check_var
) {
775 if ((err
= info
->fbops
->fb_check_var(var
, info
)))
778 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
779 struct fb_videomode mode
;
783 if (info
->fbops
->fb_set_par
)
784 info
->fbops
->fb_set_par(info
);
786 fb_pan_display(info
, &info
->var
);
788 fb_set_cmap(&info
->cmap
, info
);
790 fb_var_to_videomode(&mode
, &info
->var
);
792 if (info
->modelist
.prev
&& info
->modelist
.next
&&
793 !list_empty(&info
->modelist
))
794 err
= fb_add_videomode(&mode
, &info
->modelist
);
796 if (!err
&& (flags
& FBINFO_MISC_USEREVENT
)) {
797 struct fb_event event
;
798 int evnt
= (var
->activate
& FB_ACTIVATE_ALL
) ?
799 FB_EVENT_MODE_CHANGE_ALL
:
800 FB_EVENT_MODE_CHANGE
;
802 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
804 notifier_call_chain(&fb_notifier_list
, evnt
,
813 fb_blank(struct fb_info
*info
, int blank
)
817 if (blank
> FB_BLANK_POWERDOWN
)
818 blank
= FB_BLANK_POWERDOWN
;
820 if (info
->fbops
->fb_blank
)
821 ret
= info
->fbops
->fb_blank(blank
, info
);
824 struct fb_event event
;
828 notifier_call_chain(&fb_notifier_list
, FB_EVENT_BLANK
, &event
);
835 fb_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
838 int fbidx
= iminor(inode
);
839 struct fb_info
*info
= registered_fb
[fbidx
];
840 struct fb_ops
*fb
= info
->fbops
;
841 struct fb_var_screeninfo var
;
842 struct fb_fix_screeninfo fix
;
843 struct fb_con2fbmap con2fb
;
844 struct fb_cmap_user cmap
;
845 struct fb_event event
;
846 void __user
*argp
= (void __user
*)arg
;
852 case FBIOGET_VSCREENINFO
:
853 return copy_to_user(argp
, &info
->var
,
854 sizeof(var
)) ? -EFAULT
: 0;
855 case FBIOPUT_VSCREENINFO
:
856 if (copy_from_user(&var
, argp
, sizeof(var
)))
858 acquire_console_sem();
859 info
->flags
|= FBINFO_MISC_USEREVENT
;
860 i
= fb_set_var(info
, &var
);
861 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
862 release_console_sem();
864 if (copy_to_user(argp
, &var
, sizeof(var
)))
867 case FBIOGET_FSCREENINFO
:
868 return copy_to_user(argp
, &info
->fix
,
869 sizeof(fix
)) ? -EFAULT
: 0;
871 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
873 return (fb_set_user_cmap(&cmap
, info
));
875 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
877 return fb_cmap_to_user(&info
->cmap
, &cmap
);
878 case FBIOPAN_DISPLAY
:
879 if (copy_from_user(&var
, argp
, sizeof(var
)))
881 acquire_console_sem();
882 i
= fb_pan_display(info
, &var
);
883 release_console_sem();
886 if (copy_to_user(argp
, &var
, sizeof(var
)))
891 case FBIOGET_CON2FBMAP
:
892 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
894 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
896 con2fb
.framebuffer
= -1;
898 event
.data
= &con2fb
;
899 notifier_call_chain(&fb_notifier_list
,
900 FB_EVENT_GET_CONSOLE_MAP
, &event
);
901 return copy_to_user(argp
, &con2fb
,
902 sizeof(con2fb
)) ? -EFAULT
: 0;
903 case FBIOPUT_CON2FBMAP
:
904 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
906 if (con2fb
.console
< 0 || con2fb
.console
> MAX_NR_CONSOLES
)
908 if (con2fb
.framebuffer
< 0 || con2fb
.framebuffer
>= FB_MAX
)
911 if (!registered_fb
[con2fb
.framebuffer
])
912 try_to_load(con2fb
.framebuffer
);
913 #endif /* CONFIG_KMOD */
914 if (!registered_fb
[con2fb
.framebuffer
])
917 event
.data
= &con2fb
;
918 return notifier_call_chain(&fb_notifier_list
,
919 FB_EVENT_SET_CONSOLE_MAP
,
922 acquire_console_sem();
923 info
->flags
|= FBINFO_MISC_USEREVENT
;
924 i
= fb_blank(info
, arg
);
925 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
926 release_console_sem();
929 if (fb
->fb_ioctl
== NULL
)
931 return fb
->fb_ioctl(inode
, file
, cmd
, arg
, info
);
937 fb_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
939 int fbidx
= iminor(file
->f_dentry
->d_inode
);
940 struct fb_info
*info
= registered_fb
[fbidx
];
941 struct fb_ops
*fb
= info
->fbops
;
944 if (fb
->fb_compat_ioctl
== NULL
)
947 ret
= fb
->fb_compat_ioctl(file
, cmd
, arg
, info
);
954 fb_mmap(struct file
*file
, struct vm_area_struct
* vma
)
956 int fbidx
= iminor(file
->f_dentry
->d_inode
);
957 struct fb_info
*info
= registered_fb
[fbidx
];
958 struct fb_ops
*fb
= info
->fbops
;
960 #if !defined(__sparc__) || defined(__sparc_v9__)
965 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
))
967 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
973 res
= fb
->fb_mmap(info
, file
, vma
);
978 #if defined(__sparc__) && !defined(__sparc_v9__)
979 /* Should never get here, all fb drivers should have their own
986 /* frame buffer memory */
987 start
= info
->fix
.smem_start
;
988 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.smem_len
);
990 /* memory mapped io */
992 if (info
->var
.accel_flags
) {
996 start
= info
->fix
.mmio_start
;
997 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.mmio_len
);
1001 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
1004 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
1005 /* This is an IO map - tell maydump to skip this VMA */
1006 vma
->vm_flags
|= VM_IO
| VM_RESERVED
;
1007 #if defined(__sparc_v9__)
1008 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
1009 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
1012 #if defined(__mc68000__)
1013 #if defined(CONFIG_SUN3)
1014 pgprot_val(vma
->vm_page_prot
) |= SUN3_PAGE_NOCACHE
;
1015 #elif defined(CONFIG_MMU)
1016 if (CPU_IS_020_OR_030
)
1017 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE030
;
1018 if (CPU_IS_040_OR_060
) {
1019 pgprot_val(vma
->vm_page_prot
) &= _CACHEMASK040
;
1020 /* Use no-cache mode, serialized */
1021 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE_S
;
1024 #elif defined(__powerpc__)
1025 vma
->vm_page_prot
= phys_mem_access_prot(file
, off
>> PAGE_SHIFT
,
1026 vma
->vm_end
- vma
->vm_start
,
1028 #elif defined(__alpha__)
1029 /* Caching is off in the I/O space quadrant by design. */
1030 #elif defined(__i386__) || defined(__x86_64__)
1031 if (boot_cpu_data
.x86
> 3)
1032 pgprot_val(vma
->vm_page_prot
) |= _PAGE_PCD
;
1033 #elif defined(__mips__)
1034 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1035 #elif defined(__hppa__)
1036 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NO_CACHE
;
1037 #elif defined(__arm__) || defined(__sh__) || defined(__m32r__)
1038 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
1039 #elif defined(__ia64__)
1040 if (efi_range_is_wc(vma
->vm_start
, vma
->vm_end
- vma
->vm_start
))
1041 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
1043 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1045 #warning What do we have to do here??
1047 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
1048 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
1050 #endif /* !__sparc_v9__ */
1052 #endif /* !sparc32 */
1056 fb_open(struct inode
*inode
, struct file
*file
)
1058 int fbidx
= iminor(inode
);
1059 struct fb_info
*info
;
1062 if (fbidx
>= FB_MAX
)
1065 if (!(info
= registered_fb
[fbidx
]))
1067 #endif /* CONFIG_KMOD */
1068 if (!(info
= registered_fb
[fbidx
]))
1070 if (!try_module_get(info
->fbops
->owner
))
1072 if (info
->fbops
->fb_open
) {
1073 res
= info
->fbops
->fb_open(info
,1);
1075 module_put(info
->fbops
->owner
);
1081 fb_release(struct inode
*inode
, struct file
*file
)
1083 int fbidx
= iminor(inode
);
1084 struct fb_info
*info
;
1087 info
= registered_fb
[fbidx
];
1088 if (info
->fbops
->fb_release
)
1089 info
->fbops
->fb_release(info
,1);
1090 module_put(info
->fbops
->owner
);
1095 static struct file_operations fb_fops
= {
1096 .owner
= THIS_MODULE
,
1100 #ifdef CONFIG_COMPAT
1101 .compat_ioctl
= fb_compat_ioctl
,
1105 .release
= fb_release
,
1106 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1107 .get_unmapped_area
= get_fb_unmapped_area
,
1111 static struct class *fb_class
;
1114 * register_framebuffer - registers a frame buffer device
1115 * @fb_info: frame buffer info structure
1117 * Registers a frame buffer device @fb_info.
1119 * Returns negative errno on error, or zero for success.
1124 register_framebuffer(struct fb_info
*fb_info
)
1127 struct fb_event event
;
1128 struct fb_videomode mode
;
1130 if (num_registered_fb
== FB_MAX
)
1132 num_registered_fb
++;
1133 for (i
= 0 ; i
< FB_MAX
; i
++)
1134 if (!registered_fb
[i
])
1138 fb_info
->class_device
= class_device_create(fb_class
, NULL
, MKDEV(FB_MAJOR
, i
),
1139 fb_info
->device
, "fb%d", i
);
1140 if (IS_ERR(fb_info
->class_device
)) {
1142 printk(KERN_WARNING
"Unable to create class_device for framebuffer %d; errno = %ld\n", i
, PTR_ERR(fb_info
->class_device
));
1143 fb_info
->class_device
= NULL
;
1145 fb_init_class_device(fb_info
);
1147 if (fb_info
->pixmap
.addr
== NULL
) {
1148 fb_info
->pixmap
.addr
= kmalloc(FBPIXMAPSIZE
, GFP_KERNEL
);
1149 if (fb_info
->pixmap
.addr
) {
1150 fb_info
->pixmap
.size
= FBPIXMAPSIZE
;
1151 fb_info
->pixmap
.buf_align
= 1;
1152 fb_info
->pixmap
.scan_align
= 1;
1153 fb_info
->pixmap
.access_align
= 32;
1154 fb_info
->pixmap
.flags
= FB_PIXMAP_DEFAULT
;
1157 fb_info
->pixmap
.offset
= 0;
1159 if (!fb_info
->modelist
.prev
|| !fb_info
->modelist
.next
)
1160 INIT_LIST_HEAD(&fb_info
->modelist
);
1162 fb_var_to_videomode(&mode
, &fb_info
->var
);
1163 fb_add_videomode(&mode
, &fb_info
->modelist
);
1164 registered_fb
[i
] = fb_info
;
1166 devfs_mk_cdev(MKDEV(FB_MAJOR
, i
),
1167 S_IFCHR
| S_IRUGO
| S_IWUGO
, "fb/%d", i
);
1168 event
.info
= fb_info
;
1169 notifier_call_chain(&fb_notifier_list
,
1170 FB_EVENT_FB_REGISTERED
, &event
);
1176 * unregister_framebuffer - releases a frame buffer device
1177 * @fb_info: frame buffer info structure
1179 * Unregisters a frame buffer device @fb_info.
1181 * Returns negative errno on error, or zero for success.
1186 unregister_framebuffer(struct fb_info
*fb_info
)
1191 if (!registered_fb
[i
])
1193 devfs_remove("fb/%d", i
);
1195 if (fb_info
->pixmap
.addr
&& (fb_info
->pixmap
.flags
& FB_PIXMAP_DEFAULT
))
1196 kfree(fb_info
->pixmap
.addr
);
1197 fb_destroy_modelist(&fb_info
->modelist
);
1198 registered_fb
[i
]=NULL
;
1199 num_registered_fb
--;
1200 fb_cleanup_class_device(fb_info
);
1201 class_device_destroy(fb_class
, MKDEV(FB_MAJOR
, i
));
1206 * fb_register_client - register a client notifier
1207 * @nb: notifier block to callback on events
1209 int fb_register_client(struct notifier_block
*nb
)
1211 return notifier_chain_register(&fb_notifier_list
, nb
);
1215 * fb_unregister_client - unregister a client notifier
1216 * @nb: notifier block to callback on events
1218 int fb_unregister_client(struct notifier_block
*nb
)
1220 return notifier_chain_unregister(&fb_notifier_list
, nb
);
1224 * fb_set_suspend - low level driver signals suspend
1225 * @info: framebuffer affected
1226 * @state: 0 = resuming, !=0 = suspending
1228 * This is meant to be used by low level drivers to
1229 * signal suspend/resume to the core & clients.
1230 * It must be called with the console semaphore held
1232 void fb_set_suspend(struct fb_info
*info
, int state
)
1234 struct fb_event event
;
1238 notifier_call_chain(&fb_notifier_list
, FB_EVENT_SUSPEND
, &event
);
1239 info
->state
= FBINFO_STATE_SUSPENDED
;
1241 info
->state
= FBINFO_STATE_RUNNING
;
1242 notifier_call_chain(&fb_notifier_list
, FB_EVENT_RESUME
, &event
);
1247 * fbmem_init - init frame buffer subsystem
1249 * Initialize the frame buffer subsystem.
1251 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1258 create_proc_read_entry("fb", 0, NULL
, fbmem_read_proc
, NULL
);
1261 if (register_chrdev(FB_MAJOR
,"fb",&fb_fops
))
1262 printk("unable to get major %d for fb devs\n", FB_MAJOR
);
1264 fb_class
= class_create(THIS_MODULE
, "graphics");
1265 if (IS_ERR(fb_class
)) {
1266 printk(KERN_WARNING
"Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class
));
1273 module_init(fbmem_init
);
1277 class_destroy(fb_class
);
1278 unregister_chrdev(FB_MAJOR
, "fb");
1281 module_exit(fbmem_exit
);
1282 MODULE_LICENSE("GPL");
1283 MODULE_DESCRIPTION("Framebuffer base");
1285 subsys_initcall(fbmem_init
);
1288 int fb_new_modelist(struct fb_info
*info
)
1290 struct fb_event event
;
1291 struct fb_var_screeninfo var
= info
->var
;
1292 struct list_head
*pos
, *n
;
1293 struct fb_modelist
*modelist
;
1294 struct fb_videomode
*m
, mode
;
1297 list_for_each_safe(pos
, n
, &info
->modelist
) {
1298 modelist
= list_entry(pos
, struct fb_modelist
, list
);
1299 m
= &modelist
->mode
;
1300 fb_videomode_to_var(&var
, m
);
1301 var
.activate
= FB_ACTIVATE_TEST
;
1302 err
= fb_set_var(info
, &var
);
1303 fb_var_to_videomode(&mode
, &var
);
1304 if (err
|| !fb_mode_is_equal(m
, &mode
)) {
1312 if (!list_empty(&info
->modelist
)) {
1314 err
= notifier_call_chain(&fb_notifier_list
,
1315 FB_EVENT_NEW_MODELIST
,
1322 static char *video_options
[FB_MAX
];
1325 extern const char *global_mode_option
;
1328 * fb_get_options - get kernel boot parameters
1329 * @name: framebuffer name as it would appear in
1330 * the boot parameter line
1331 * (video=<name>:<options>)
1332 * @option: the option will be stored here
1334 * NOTE: Needed to maintain backwards compatibility
1336 int fb_get_options(char *name
, char **option
)
1338 char *opt
, *options
= NULL
;
1339 int opt_len
, retval
= 0;
1340 int name_len
= strlen(name
), i
;
1342 if (name_len
&& ofonly
&& strncmp(name
, "offb", 4))
1345 if (name_len
&& !retval
) {
1346 for (i
= 0; i
< FB_MAX
; i
++) {
1347 if (video_options
[i
] == NULL
)
1349 opt_len
= strlen(video_options
[i
]);
1352 opt
= video_options
[i
];
1353 if (!strncmp(name
, opt
, name_len
) &&
1354 opt
[name_len
] == ':')
1355 options
= opt
+ name_len
+ 1;
1358 if (options
&& !strncmp(options
, "off", 3))
1368 * video_setup - process command line options
1369 * @options: string of options
1371 * Process command line options for frame buffer subsystem.
1373 * NOTE: This function is a __setup and __init function.
1374 * It only stores the options. Drivers have to call
1375 * fb_get_options() as necessary.
1380 static int __init
video_setup(char *options
)
1384 if (!options
|| !*options
)
1387 if (!global
&& !strncmp(options
, "ofonly", 6)) {
1392 if (!global
&& !strstr(options
, "fb:")) {
1393 global_mode_option
= options
;
1398 for (i
= 0; i
< FB_MAX
; i
++) {
1399 if (video_options
[i
] == NULL
) {
1400 video_options
[i
] = options
;
1409 __setup("video=", video_setup
);
1412 * Visible symbols for modules
1415 EXPORT_SYMBOL(register_framebuffer
);
1416 EXPORT_SYMBOL(unregister_framebuffer
);
1417 EXPORT_SYMBOL(num_registered_fb
);
1418 EXPORT_SYMBOL(registered_fb
);
1419 EXPORT_SYMBOL(fb_prepare_logo
);
1420 EXPORT_SYMBOL(fb_show_logo
);
1421 EXPORT_SYMBOL(fb_set_var
);
1422 EXPORT_SYMBOL(fb_blank
);
1423 EXPORT_SYMBOL(fb_pan_display
);
1424 EXPORT_SYMBOL(fb_get_buffer_offset
);
1425 EXPORT_SYMBOL(fb_set_suspend
);
1426 EXPORT_SYMBOL(fb_register_client
);
1427 EXPORT_SYMBOL(fb_unregister_client
);
1428 EXPORT_SYMBOL(fb_get_options
);
1429 EXPORT_SYMBOL(fb_new_modelist
);
1431 MODULE_LICENSE("GPL");