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>
39 #if defined(__mc68000__) || defined(CONFIG_APUS)
40 #include <asm/setup.h>
44 #include <asm/uaccess.h>
46 #include <asm/pgtable.h>
51 * Frame buffer device initialization and setup routines
54 #define FBPIXMAPSIZE 16384
56 static struct notifier_block
*fb_notifier_list
;
57 struct fb_info
*registered_fb
[FB_MAX
];
58 int num_registered_fb
;
64 int fb_get_color_depth(struct fb_info
*info
)
66 struct fb_var_screeninfo
*var
= &info
->var
;
68 if (var
->green
.length
== var
->blue
.length
&&
69 var
->green
.length
== var
->red
.length
&&
70 !var
->green
.offset
&& !var
->blue
.offset
&&
72 return var
->green
.length
;
74 return (var
->green
.length
+ var
->red
.length
+
77 EXPORT_SYMBOL(fb_get_color_depth
);
82 void fb_iomove_buf_aligned(struct fb_info
*info
, struct fb_pixmap
*buf
,
83 u8
*dst
, u32 d_pitch
, u8
*src
, u32 s_pitch
,
88 for (i
= height
; i
--; ) {
89 buf
->outbuf(info
, dst
, src
, s_pitch
);
95 void fb_sysmove_buf_aligned(struct fb_info
*info
, struct fb_pixmap
*buf
,
96 u8
*dst
, u32 d_pitch
, u8
*src
, u32 s_pitch
,
101 for (i
= height
; i
--; ) {
102 for (j
= 0; j
< s_pitch
; j
++)
109 void fb_iomove_buf_unaligned(struct fb_info
*info
, struct fb_pixmap
*buf
,
110 u8
*dst
, u32 d_pitch
, u8
*src
, u32 idx
,
111 u32 height
, u32 shift_high
, u32 shift_low
,
114 u8 mask
= (u8
) (0xfff << shift_high
), tmp
;
117 for (i
= height
; i
--; ) {
118 for (j
= 0; j
< idx
; j
++) {
119 tmp
= buf
->inbuf(info
, dst
+j
);
121 tmp
|= *src
>> shift_low
;
122 buf
->outbuf(info
, dst
+j
, &tmp
, 1);
123 tmp
= *src
<< shift_high
;
124 buf
->outbuf(info
, dst
+j
+1, &tmp
, 1);
127 tmp
= buf
->inbuf(info
, dst
+idx
);
129 tmp
|= *src
>> shift_low
;
130 buf
->outbuf(info
, dst
+idx
, &tmp
, 1);
131 if (shift_high
< mod
) {
132 tmp
= *src
<< shift_high
;
133 buf
->outbuf(info
, dst
+idx
+1, &tmp
, 1);
140 void fb_sysmove_buf_unaligned(struct fb_info
*info
, struct fb_pixmap
*buf
,
141 u8
*dst
, u32 d_pitch
, u8
*src
, u32 idx
,
142 u32 height
, u32 shift_high
, u32 shift_low
,
145 u8 mask
= (u8
) (0xfff << shift_high
), tmp
;
148 for (i
= height
; i
--; ) {
149 for (j
= 0; j
< idx
; j
++) {
152 tmp
|= *src
>> shift_low
;
154 tmp
= *src
<< shift_high
;
160 tmp
|= *src
>> shift_low
;
162 if (shift_high
< mod
) {
163 tmp
= *src
<< shift_high
;
172 * we need to lock this section since fb_cursor
173 * may use fb_imageblit()
175 char* fb_get_buffer_offset(struct fb_info
*info
, struct fb_pixmap
*buf
, u32 size
)
177 u32 align
= buf
->buf_align
- 1, offset
;
178 char *addr
= buf
->addr
;
180 /* If IO mapped, we need to sync before access, no sharing of
183 if (buf
->flags
& FB_PIXMAP_IO
) {
184 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
185 info
->fbops
->fb_sync(info
);
189 /* See if we fit in the remaining pixmap space */
190 offset
= buf
->offset
+ align
;
192 if (offset
+ size
> buf
->size
) {
193 /* We do not fit. In order to be able to re-use the buffer,
194 * we must ensure no asynchronous DMA'ing or whatever operation
195 * is in progress, we sync for that.
197 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
198 info
->fbops
->fb_sync(info
);
201 buf
->offset
= offset
+ size
;
208 #include <linux/linux_logo.h>
210 static inline unsigned safe_shift(unsigned d
, int n
)
212 return n
< 0 ? d
>> -n
: d
<< n
;
215 static void fb_set_logocmap(struct fb_info
*info
,
216 const struct linux_logo
*logo
)
218 struct fb_cmap palette_cmap
;
219 u16 palette_green
[16];
220 u16 palette_blue
[16];
223 const unsigned char *clut
= logo
->clut
;
225 palette_cmap
.start
= 0;
226 palette_cmap
.len
= 16;
227 palette_cmap
.red
= palette_red
;
228 palette_cmap
.green
= palette_green
;
229 palette_cmap
.blue
= palette_blue
;
230 palette_cmap
.transp
= NULL
;
232 for (i
= 0; i
< logo
->clutsize
; i
+= n
) {
233 n
= logo
->clutsize
- i
;
234 /* palette_cmap provides space for only 16 colors at once */
237 palette_cmap
.start
= 32 + i
;
238 palette_cmap
.len
= n
;
239 for (j
= 0; j
< n
; ++j
) {
240 palette_cmap
.red
[j
] = clut
[0] << 8 | clut
[0];
241 palette_cmap
.green
[j
] = clut
[1] << 8 | clut
[1];
242 palette_cmap
.blue
[j
] = clut
[2] << 8 | clut
[2];
245 fb_set_cmap(&palette_cmap
, info
);
249 static void fb_set_logo_truepalette(struct fb_info
*info
,
250 const struct linux_logo
*logo
,
253 unsigned char mask
[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
254 unsigned char redmask
, greenmask
, bluemask
;
255 int redshift
, greenshift
, blueshift
;
257 const unsigned char *clut
= logo
->clut
;
260 * We have to create a temporary palette since console palette is only
263 /* Bug: Doesn't obey msb_right ... (who needs that?) */
264 redmask
= mask
[info
->var
.red
.length
< 8 ? info
->var
.red
.length
: 8];
265 greenmask
= mask
[info
->var
.green
.length
< 8 ? info
->var
.green
.length
: 8];
266 bluemask
= mask
[info
->var
.blue
.length
< 8 ? info
->var
.blue
.length
: 8];
267 redshift
= info
->var
.red
.offset
- (8 - info
->var
.red
.length
);
268 greenshift
= info
->var
.green
.offset
- (8 - info
->var
.green
.length
);
269 blueshift
= info
->var
.blue
.offset
- (8 - info
->var
.blue
.length
);
271 for ( i
= 0; i
< logo
->clutsize
; i
++) {
272 palette
[i
+32] = (safe_shift((clut
[0] & redmask
), redshift
) |
273 safe_shift((clut
[1] & greenmask
), greenshift
) |
274 safe_shift((clut
[2] & bluemask
), blueshift
));
279 static void fb_set_logo_directpalette(struct fb_info
*info
,
280 const struct linux_logo
*logo
,
283 int redshift
, greenshift
, blueshift
;
286 redshift
= info
->var
.red
.offset
;
287 greenshift
= info
->var
.green
.offset
;
288 blueshift
= info
->var
.blue
.offset
;
290 for (i
= 32; i
< logo
->clutsize
; i
++)
291 palette
[i
] = i
<< redshift
| i
<< greenshift
| i
<< blueshift
;
294 static void fb_set_logo(struct fb_info
*info
,
295 const struct linux_logo
*logo
, u8
*dst
,
299 const u8
*src
= logo
->data
;
300 u8 d
, xor = (info
->fix
.visual
== FB_VISUAL_MONO01
) ? 0xff : 0;
302 if (fb_get_color_depth(info
) == 3)
307 for (i
= 0; i
< logo
->height
; i
++)
308 for (j
= 0; j
< logo
->width
; src
++) {
311 if (j
< logo
->width
) {
312 *dst
++ = *src
& 0x0f;
318 for (i
= 0; i
< logo
->height
; i
++) {
319 for (j
= 0; j
< logo
->width
; src
++) {
321 for (k
= 7; k
>= 0; k
--) {
322 *dst
++ = ((d
>> k
) & 1) ? fg
: 0;
332 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
333 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
334 * the visual format and color depth of the framebuffer, the DAC, the
335 * pseudo_palette, and the logo data will be adjusted accordingly.
337 * Case 1 - linux_logo_clut224:
338 * Color exceeds the number of console colors (16), thus we set the hardware DAC
339 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
341 * For visuals that require color info from the pseudo_palette, we also construct
342 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
345 * Case 2 - linux_logo_vga16:
346 * The number of colors just matches the console colors, thus there is no need
347 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
348 * each byte contains color information for two pixels (upper and lower nibble).
349 * To be consistent with fb_imageblit() usage, we therefore separate the two
350 * nibbles into separate bytes. The "depth" flag will be set to 4.
352 * Case 3 - linux_logo_mono:
353 * This is similar with Case 2. Each byte contains information for 8 pixels.
354 * We isolate each bit and expand each into a byte. The "depth" flag will
357 static struct logo_data
{
359 int needs_directpalette
;
360 int needs_truepalette
;
362 const struct linux_logo
*logo
;
365 int fb_prepare_logo(struct fb_info
*info
)
367 int depth
= fb_get_color_depth(info
);
369 memset(&fb_logo
, 0, sizeof(struct logo_data
));
371 if (info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
372 depth
= info
->var
.blue
.length
;
373 if (info
->var
.red
.length
< depth
)
374 depth
= info
->var
.red
.length
;
375 if (info
->var
.green
.length
< depth
)
376 depth
= info
->var
.green
.length
;
380 switch (info
->fix
.visual
) {
381 case FB_VISUAL_TRUECOLOR
:
382 fb_logo
.needs_truepalette
= 1;
384 case FB_VISUAL_DIRECTCOLOR
:
385 fb_logo
.needs_directpalette
= 1;
386 fb_logo
.needs_cmapreset
= 1;
388 case FB_VISUAL_PSEUDOCOLOR
:
389 fb_logo
.needs_cmapreset
= 1;
394 /* Return if no suitable logo was found */
395 fb_logo
.logo
= fb_find_logo(depth
);
397 if (!fb_logo
.logo
|| fb_logo
.logo
->height
> info
->var
.yres
) {
401 /* What depth we asked for might be different from what we get */
402 if (fb_logo
.logo
->type
== LINUX_LOGO_CLUT224
)
404 else if (fb_logo
.logo
->type
== LINUX_LOGO_VGA16
)
408 return fb_logo
.logo
->height
;
411 int fb_show_logo(struct fb_info
*info
)
413 u32
*palette
= NULL
, *saved_pseudo_palette
= NULL
;
414 unsigned char *logo_new
= NULL
;
415 struct fb_image image
;
418 /* Return if the frame buffer is not mapped or suspended */
419 if (fb_logo
.logo
== NULL
|| info
->state
!= FBINFO_STATE_RUNNING
)
423 image
.data
= fb_logo
.logo
->data
;
425 if (fb_logo
.needs_cmapreset
)
426 fb_set_logocmap(info
, fb_logo
.logo
);
428 if (fb_logo
.needs_truepalette
||
429 fb_logo
.needs_directpalette
) {
430 palette
= kmalloc(256 * 4, GFP_KERNEL
);
434 if (fb_logo
.needs_truepalette
)
435 fb_set_logo_truepalette(info
, fb_logo
.logo
, palette
);
437 fb_set_logo_directpalette(info
, fb_logo
.logo
, palette
);
439 saved_pseudo_palette
= info
->pseudo_palette
;
440 info
->pseudo_palette
= palette
;
443 if (fb_logo
.depth
<= 4) {
444 logo_new
= kmalloc(fb_logo
.logo
->width
* fb_logo
.logo
->height
,
446 if (logo_new
== NULL
) {
449 if (saved_pseudo_palette
)
450 info
->pseudo_palette
= saved_pseudo_palette
;
453 image
.data
= logo_new
;
454 fb_set_logo(info
, fb_logo
.logo
, logo_new
, fb_logo
.depth
);
457 image
.width
= fb_logo
.logo
->width
;
458 image
.height
= fb_logo
.logo
->height
;
461 for (x
= 0; x
< num_online_cpus() * (fb_logo
.logo
->width
+ 8) &&
462 x
<= info
->var
.xres
-fb_logo
.logo
->width
; x
+= (fb_logo
.logo
->width
+ 8)) {
464 info
->fbops
->fb_imageblit(info
, &image
);
469 if (saved_pseudo_palette
!= NULL
)
470 info
->pseudo_palette
= saved_pseudo_palette
;
471 if (logo_new
!= NULL
)
473 return fb_logo
.logo
->height
;
476 int fb_prepare_logo(struct fb_info
*info
) { return 0; }
477 int fb_show_logo(struct fb_info
*info
) { return 0; }
478 #endif /* CONFIG_LOGO */
480 static int fbmem_read_proc(char *buf
, char **start
, off_t offset
,
481 int len
, int *eof
, void *private)
487 for (fi
= registered_fb
; fi
< ®istered_fb
[FB_MAX
] && len
< 4000; fi
++)
489 clen
+= sprintf(buf
+ clen
, "%d %s\n",
492 *start
= buf
+ offset
;
497 return clen
< len
? clen
: len
;
501 fb_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
503 unsigned long p
= *ppos
;
504 struct inode
*inode
= file
->f_dentry
->d_inode
;
505 int fbidx
= iminor(inode
);
506 struct fb_info
*info
= registered_fb
[fbidx
];
507 u32
*buffer
, *dst
, *src
;
508 int c
, i
, cnt
= 0, err
= 0;
509 unsigned long total_size
;
511 if (!info
|| ! info
->screen_base
)
514 if (info
->state
!= FBINFO_STATE_RUNNING
)
517 if (info
->fbops
->fb_read
)
518 return info
->fbops
->fb_read(file
, buf
, count
, ppos
);
520 total_size
= info
->screen_size
;
522 total_size
= info
->fix
.smem_len
;
526 if (count
>= total_size
)
528 if (count
+ p
> total_size
)
529 count
= total_size
- p
;
532 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
537 src
= (u32
*) (info
->screen_base
+ p
);
539 if (info
->fbops
->fb_sync
)
540 info
->fbops
->fb_sync(info
);
543 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
545 for (i
= c
>> 2; i
--; )
546 *dst
++ = fb_readl(src
++);
548 u8
*dst8
= (u8
*) dst
;
549 u8
*src8
= (u8
*) src
;
551 for (i
= c
& 3; i
--;)
552 *dst8
++ = fb_readb(src8
++);
557 if (copy_to_user(buf
, buffer
, c
)) {
568 return (err
) ? err
: cnt
;
572 fb_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
574 unsigned long p
= *ppos
;
575 struct inode
*inode
= file
->f_dentry
->d_inode
;
576 int fbidx
= iminor(inode
);
577 struct fb_info
*info
= registered_fb
[fbidx
];
578 u32
*buffer
, *dst
, *src
;
579 int c
, i
, cnt
= 0, err
;
580 unsigned long total_size
;
582 if (!info
|| !info
->screen_base
)
585 if (info
->state
!= FBINFO_STATE_RUNNING
)
588 if (info
->fbops
->fb_write
)
589 return info
->fbops
->fb_write(file
, buf
, count
, ppos
);
591 total_size
= info
->screen_size
;
593 total_size
= info
->fix
.smem_len
;
597 if (count
>= total_size
)
600 if (count
+ p
> total_size
) {
601 count
= total_size
- p
;
605 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
610 dst
= (u32
*) (info
->screen_base
+ p
);
612 if (info
->fbops
->fb_sync
)
613 info
->fbops
->fb_sync(info
);
616 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
618 if (copy_from_user(src
, buf
, c
)) {
622 for (i
= c
>> 2; i
--; )
623 fb_writel(*src
++, dst
++);
625 u8
*src8
= (u8
*) src
;
626 u8
*dst8
= (u8
*) dst
;
628 for (i
= c
& 3; i
--; )
629 fb_writeb(*src8
++, dst8
++);
640 return (err
) ? err
: cnt
;
644 static void try_to_load(int fb
)
646 request_module("fb%d", fb
);
648 #endif /* CONFIG_KMOD */
651 fb_load_cursor_image(struct fb_info
*info
)
653 unsigned int width
= (info
->cursor
.image
.width
+ 7) >> 3;
654 u8
*data
= (u8
*) info
->cursor
.image
.data
;
656 if (info
->sprite
.outbuf
)
657 info
->sprite
.outbuf(info
, info
->sprite
.addr
, data
, width
);
659 memcpy(info
->sprite
.addr
, data
, width
);
663 fb_cursor(struct fb_info
*info
, struct fb_cursor_user __user
*sprite
)
665 struct fb_cursor_user cursor_user
;
666 struct fb_cursor cursor
;
667 char *data
= NULL
, *mask
= NULL
, *info_mask
= NULL
;
668 u16
*red
= NULL
, *green
= NULL
, *blue
= NULL
, *transp
= NULL
;
671 if (copy_from_user(&cursor_user
, sprite
, sizeof(struct fb_cursor_user
)))
674 memcpy(&cursor
, &cursor_user
, sizeof(cursor_user
));
675 cursor
.mask
= info
->cursor
.mask
;
676 cursor
.image
.data
= info
->cursor
.image
.data
;
677 cursor
.image
.cmap
.red
= info
->cursor
.image
.cmap
.red
;
678 cursor
.image
.cmap
.green
= info
->cursor
.image
.cmap
.green
;
679 cursor
.image
.cmap
.blue
= info
->cursor
.image
.cmap
.blue
;
680 cursor
.image
.cmap
.transp
= info
->cursor
.image
.cmap
.transp
;
683 if (cursor
.set
& FB_CUR_SETCUR
)
684 info
->cursor
.enable
= 1;
686 if (cursor
.set
& FB_CUR_SETCMAP
) {
687 unsigned len
= cursor
.image
.cmap
.len
;
692 red
= kmalloc(len
, GFP_USER
);
693 green
= kmalloc(len
, GFP_USER
);
694 blue
= kmalloc(len
, GFP_USER
);
695 if (!red
|| !green
|| !blue
)
697 if (cursor_user
.image
.cmap
.transp
) {
698 transp
= kmalloc(len
, GFP_USER
);
703 if (copy_from_user(red
, cursor_user
.image
.cmap
.red
, len
))
705 if (copy_from_user(green
, cursor_user
.image
.cmap
.green
, len
))
707 if (copy_from_user(blue
, cursor_user
.image
.cmap
.blue
, len
))
710 if (copy_from_user(transp
,
711 cursor_user
.image
.cmap
.transp
, len
))
714 cursor
.image
.cmap
.red
= red
;
715 cursor
.image
.cmap
.green
= green
;
716 cursor
.image
.cmap
.blue
= blue
;
717 cursor
.image
.cmap
.transp
= transp
;
720 if (cursor
.set
& FB_CUR_SETSHAPE
) {
721 int size
= ((cursor
.image
.width
+ 7) >> 3) * cursor
.image
.height
;
723 if ((cursor
.image
.height
!= info
->cursor
.image
.height
) ||
724 (cursor
.image
.width
!= info
->cursor
.image
.width
))
725 cursor
.set
|= FB_CUR_SETSIZE
;
728 data
= kmalloc(size
, GFP_USER
);
729 mask
= kmalloc(size
, GFP_USER
);
734 if (copy_from_user(data
, cursor_user
.image
.data
, size
) ||
735 copy_from_user(mask
, cursor_user
.mask
, size
))
738 cursor
.image
.data
= data
;
740 info_mask
= (char *) info
->cursor
.mask
;
741 info
->cursor
.mask
= mask
;
743 info
->cursor
.set
= cursor
.set
;
744 info
->cursor
.rop
= cursor
.rop
;
745 err
= info
->fbops
->fb_cursor(info
, &cursor
);
754 info
->cursor
.mask
= info_mask
;
759 fb_pan_display(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
761 int xoffset
= var
->xoffset
;
762 int yoffset
= var
->yoffset
;
765 if (xoffset
< 0 || yoffset
< 0 || !info
->fbops
->fb_pan_display
||
766 xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
||
767 yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
769 if ((err
= info
->fbops
->fb_pan_display(var
, info
)))
771 info
->var
.xoffset
= var
->xoffset
;
772 info
->var
.yoffset
= var
->yoffset
;
773 if (var
->vmode
& FB_VMODE_YWRAP
)
774 info
->var
.vmode
|= FB_VMODE_YWRAP
;
776 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
781 fb_set_var(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
785 if (var
->activate
& FB_ACTIVATE_INV_MODE
) {
786 struct fb_videomode mode1
, mode2
;
789 fb_var_to_videomode(&mode1
, var
);
790 fb_var_to_videomode(&mode2
, &info
->var
);
791 /* make sure we don't delete the videomode of current var */
792 ret
= fb_mode_is_equal(&mode1
, &mode2
);
795 struct fb_event event
;
799 ret
= notifier_call_chain(&fb_notifier_list
,
800 FB_EVENT_MODE_DELETE
, &event
);
804 fb_delete_videomode(&mode1
, &info
->modelist
);
809 if ((var
->activate
& FB_ACTIVATE_FORCE
) ||
810 memcmp(&info
->var
, var
, sizeof(struct fb_var_screeninfo
))) {
811 if (!info
->fbops
->fb_check_var
) {
816 if ((err
= info
->fbops
->fb_check_var(var
, info
)))
819 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
820 struct fb_videomode mode
;
823 if (info
->fbops
->fb_set_par
)
824 info
->fbops
->fb_set_par(info
);
826 fb_pan_display(info
, &info
->var
);
828 fb_set_cmap(&info
->cmap
, info
);
830 fb_var_to_videomode(&mode
, &info
->var
);
831 fb_add_videomode(&mode
, &info
->modelist
);
833 if (info
->flags
& FBINFO_MISC_MODECHANGEUSER
) {
834 struct fb_event event
;
836 info
->flags
&= ~FBINFO_MISC_MODECHANGEUSER
;
838 notifier_call_chain(&fb_notifier_list
,
839 FB_EVENT_MODE_CHANGE
, &event
);
847 fb_blank(struct fb_info
*info
, int blank
)
849 /* ??? Variable sized stack allocation. */
850 u16 black
[info
->cmap
.len
];
853 if (info
->fbops
->fb_blank
&& !info
->fbops
->fb_blank(blank
, info
))
856 memset(black
, 0, info
->cmap
.len
* sizeof(u16
));
857 cmap
.red
= cmap
.green
= cmap
.blue
= black
;
858 cmap
.transp
= info
->cmap
.transp
? black
: NULL
;
859 cmap
.start
= info
->cmap
.start
;
860 cmap
.len
= info
->cmap
.len
;
863 return fb_set_cmap(&cmap
, info
);
867 fb_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
870 int fbidx
= iminor(inode
);
871 struct fb_info
*info
= registered_fb
[fbidx
];
872 struct fb_ops
*fb
= info
->fbops
;
873 struct fb_var_screeninfo var
;
874 struct fb_fix_screeninfo fix
;
875 struct fb_con2fbmap con2fb
;
876 struct fb_cmap_user cmap
;
877 struct fb_event event
;
878 void __user
*argp
= (void __user
*)arg
;
884 case FBIOGET_VSCREENINFO
:
885 return copy_to_user(argp
, &info
->var
,
886 sizeof(var
)) ? -EFAULT
: 0;
887 case FBIOPUT_VSCREENINFO
:
888 if (copy_from_user(&var
, argp
, sizeof(var
)))
890 acquire_console_sem();
891 info
->flags
|= FBINFO_MISC_MODECHANGEUSER
;
892 i
= fb_set_var(info
, &var
);
893 info
->flags
&= ~FBINFO_MISC_MODECHANGEUSER
;
894 release_console_sem();
896 if (copy_to_user(argp
, &var
, sizeof(var
)))
899 case FBIOGET_FSCREENINFO
:
900 return copy_to_user(argp
, &info
->fix
,
901 sizeof(fix
)) ? -EFAULT
: 0;
903 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
905 return (fb_set_user_cmap(&cmap
, info
));
907 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
909 return fb_cmap_to_user(&info
->cmap
, &cmap
);
910 case FBIOPAN_DISPLAY
:
911 if (copy_from_user(&var
, argp
, sizeof(var
)))
913 acquire_console_sem();
914 i
= fb_pan_display(info
, &var
);
915 release_console_sem();
918 if (copy_to_user(argp
, &var
, sizeof(var
)))
922 acquire_console_sem();
923 i
= fb_cursor(info
, argp
);
924 release_console_sem();
926 case FBIOGET_CON2FBMAP
:
927 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
929 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
931 con2fb
.framebuffer
= -1;
933 event
.data
= &con2fb
;
934 notifier_call_chain(&fb_notifier_list
,
935 FB_EVENT_GET_CONSOLE_MAP
, &event
);
936 return copy_to_user(argp
, &con2fb
,
937 sizeof(con2fb
)) ? -EFAULT
: 0;
938 case FBIOPUT_CON2FBMAP
:
939 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
941 if (con2fb
.console
< 0 || con2fb
.console
> MAX_NR_CONSOLES
)
943 if (con2fb
.framebuffer
< 0 || con2fb
.framebuffer
>= FB_MAX
)
946 if (!registered_fb
[con2fb
.framebuffer
])
947 try_to_load(con2fb
.framebuffer
);
948 #endif /* CONFIG_KMOD */
949 if (!registered_fb
[con2fb
.framebuffer
])
951 if (con2fb
.console
> 0 && con2fb
.console
< MAX_NR_CONSOLES
) {
953 event
.data
= &con2fb
;
954 return notifier_call_chain(&fb_notifier_list
,
955 FB_EVENT_SET_CONSOLE_MAP
,
960 acquire_console_sem();
961 i
= fb_blank(info
, arg
);
962 release_console_sem();
965 if (fb
->fb_ioctl
== NULL
)
967 return fb
->fb_ioctl(inode
, file
, cmd
, arg
, info
);
972 fb_mmap(struct file
*file
, struct vm_area_struct
* vma
)
974 int fbidx
= iminor(file
->f_dentry
->d_inode
);
975 struct fb_info
*info
= registered_fb
[fbidx
];
976 struct fb_ops
*fb
= info
->fbops
;
978 #if !defined(__sparc__) || defined(__sparc_v9__)
983 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
))
985 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
991 res
= fb
->fb_mmap(info
, file
, vma
);
996 #if defined(__sparc__) && !defined(__sparc_v9__)
997 /* Should never get here, all fb drivers should have their own
1004 /* frame buffer memory */
1005 start
= info
->fix
.smem_start
;
1006 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.smem_len
);
1008 /* memory mapped io */
1010 if (info
->var
.accel_flags
) {
1014 start
= info
->fix
.mmio_start
;
1015 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.mmio_len
);
1019 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
1022 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
1023 /* This is an IO map - tell maydump to skip this VMA */
1024 vma
->vm_flags
|= VM_IO
;
1025 #if defined(__sparc_v9__)
1026 vma
->vm_flags
|= (VM_SHM
| VM_LOCKED
);
1027 if (io_remap_page_range(vma
, vma
->vm_start
, off
,
1028 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
, 0))
1031 #if defined(__mc68000__)
1032 #if defined(CONFIG_SUN3)
1033 pgprot_val(vma
->vm_page_prot
) |= SUN3_PAGE_NOCACHE
;
1034 #elif defined(CONFIG_MMU)
1035 if (CPU_IS_020_OR_030
)
1036 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE030
;
1037 if (CPU_IS_040_OR_060
) {
1038 pgprot_val(vma
->vm_page_prot
) &= _CACHEMASK040
;
1039 /* Use no-cache mode, serialized */
1040 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE_S
;
1043 #elif defined(__powerpc__)
1044 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NO_CACHE
|_PAGE_GUARDED
;
1045 #elif defined(__alpha__)
1046 /* Caching is off in the I/O space quadrant by design. */
1047 #elif defined(__i386__) || defined(__x86_64__)
1048 if (boot_cpu_data
.x86
> 3)
1049 pgprot_val(vma
->vm_page_prot
) |= _PAGE_PCD
;
1050 #elif defined(__mips__)
1051 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1052 #elif defined(__hppa__)
1053 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NO_CACHE
;
1054 #elif defined(__ia64__) || defined(__arm__) || defined(__sh__)
1055 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
1057 #warning What do we have to do here??
1059 if (io_remap_page_range(vma
, vma
->vm_start
, off
,
1060 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
1062 #endif /* !__sparc_v9__ */
1064 #endif /* !sparc32 */
1068 fb_open(struct inode
*inode
, struct file
*file
)
1070 int fbidx
= iminor(inode
);
1071 struct fb_info
*info
;
1074 if (fbidx
>= FB_MAX
)
1077 if (!(info
= registered_fb
[fbidx
]))
1079 #endif /* CONFIG_KMOD */
1080 if (!(info
= registered_fb
[fbidx
]))
1082 if (!try_module_get(info
->fbops
->owner
))
1084 if (info
->fbops
->fb_open
) {
1085 res
= info
->fbops
->fb_open(info
,1);
1087 module_put(info
->fbops
->owner
);
1093 fb_release(struct inode
*inode
, struct file
*file
)
1095 int fbidx
= iminor(inode
);
1096 struct fb_info
*info
;
1099 info
= registered_fb
[fbidx
];
1100 if (info
->fbops
->fb_release
)
1101 info
->fbops
->fb_release(info
,1);
1102 module_put(info
->fbops
->owner
);
1107 static struct file_operations fb_fops
= {
1108 .owner
= THIS_MODULE
,
1114 .release
= fb_release
,
1115 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1116 .get_unmapped_area
= get_fb_unmapped_area
,
1120 static struct class_simple
*fb_class
;
1123 * register_framebuffer - registers a frame buffer device
1124 * @fb_info: frame buffer info structure
1126 * Registers a frame buffer device @fb_info.
1128 * Returns negative errno on error, or zero for success.
1133 register_framebuffer(struct fb_info
*fb_info
)
1136 struct class_device
*c
;
1137 struct fb_event event
;
1139 if (num_registered_fb
== FB_MAX
)
1141 num_registered_fb
++;
1142 for (i
= 0 ; i
< FB_MAX
; i
++)
1143 if (!registered_fb
[i
])
1147 c
= class_simple_device_add(fb_class
, MKDEV(FB_MAJOR
, i
), NULL
, "fb%d", i
);
1150 printk(KERN_WARNING
"Unable to create class_device for framebuffer %d; errno = %ld\n", i
, PTR_ERR(c
));
1153 if (fb_info
->pixmap
.addr
== NULL
) {
1154 fb_info
->pixmap
.addr
= kmalloc(FBPIXMAPSIZE
, GFP_KERNEL
);
1155 if (fb_info
->pixmap
.addr
) {
1156 fb_info
->pixmap
.size
= FBPIXMAPSIZE
;
1157 fb_info
->pixmap
.buf_align
= 1;
1158 fb_info
->pixmap
.scan_align
= 1;
1159 fb_info
->pixmap
.access_align
= 4;
1160 fb_info
->pixmap
.flags
= FB_PIXMAP_DEFAULT
;
1163 fb_info
->pixmap
.offset
= 0;
1165 if (fb_info
->sprite
.addr
== NULL
) {
1166 fb_info
->sprite
.addr
= kmalloc(FBPIXMAPSIZE
, GFP_KERNEL
);
1167 if (fb_info
->sprite
.addr
) {
1168 fb_info
->sprite
.size
= FBPIXMAPSIZE
;
1169 fb_info
->sprite
.buf_align
= 1;
1170 fb_info
->sprite
.scan_align
= 1;
1171 fb_info
->sprite
.access_align
= 4;
1172 fb_info
->sprite
.flags
= FB_PIXMAP_DEFAULT
;
1175 fb_info
->sprite
.offset
= 0;
1177 if (!fb_info
->modelist
.prev
||
1178 !fb_info
->modelist
.next
||
1179 list_empty(&fb_info
->modelist
)) {
1180 struct fb_videomode mode
;
1182 INIT_LIST_HEAD(&fb_info
->modelist
);
1183 fb_var_to_videomode(&mode
, &fb_info
->var
);
1184 fb_add_videomode(&mode
, &fb_info
->modelist
);
1187 registered_fb
[i
] = fb_info
;
1189 devfs_mk_cdev(MKDEV(FB_MAJOR
, i
),
1190 S_IFCHR
| S_IRUGO
| S_IWUGO
, "fb/%d", i
);
1191 event
.info
= fb_info
;
1192 notifier_call_chain(&fb_notifier_list
,
1193 FB_EVENT_FB_REGISTERED
, &event
);
1199 * unregister_framebuffer - releases a frame buffer device
1200 * @fb_info: frame buffer info structure
1202 * Unregisters a frame buffer device @fb_info.
1204 * Returns negative errno on error, or zero for success.
1209 unregister_framebuffer(struct fb_info
*fb_info
)
1214 if (!registered_fb
[i
])
1216 devfs_remove("fb/%d", i
);
1218 if (fb_info
->pixmap
.addr
&& (fb_info
->pixmap
.flags
& FB_PIXMAP_DEFAULT
))
1219 kfree(fb_info
->pixmap
.addr
);
1220 if (fb_info
->sprite
.addr
&& (fb_info
->sprite
.flags
& FB_PIXMAP_DEFAULT
))
1221 kfree(fb_info
->sprite
.addr
);
1222 fb_destroy_modelist(&fb_info
->modelist
);
1223 registered_fb
[i
]=NULL
;
1224 num_registered_fb
--;
1225 class_simple_device_remove(MKDEV(FB_MAJOR
, i
));
1230 * fb_register_client - register a client notifier
1231 * @nb: notifier block to callback on events
1233 int fb_register_client(struct notifier_block
*nb
)
1235 return notifier_chain_register(&fb_notifier_list
, nb
);
1239 * fb_unregister_client - unregister a client notifier
1240 * @nb: notifier block to callback on events
1242 int fb_unregister_client(struct notifier_block
*nb
)
1244 return notifier_chain_unregister(&fb_notifier_list
, nb
);
1248 * fb_set_suspend - low level driver signals suspend
1249 * @info: framebuffer affected
1250 * @state: 0 = resuming, !=0 = suspending
1252 * This is meant to be used by low level drivers to
1253 * signal suspend/resume to the core & clients.
1254 * It must be called with the console semaphore held
1256 void fb_set_suspend(struct fb_info
*info
, int state
)
1258 struct fb_event event
;
1262 notifier_call_chain(&fb_notifier_list
, FB_EVENT_SUSPEND
, &event
);
1263 info
->state
= FBINFO_STATE_SUSPENDED
;
1265 info
->state
= FBINFO_STATE_RUNNING
;
1266 notifier_call_chain(&fb_notifier_list
, FB_EVENT_RESUME
, &event
);
1271 * fbmem_init - init frame buffer subsystem
1273 * Initialize the frame buffer subsystem.
1275 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1282 create_proc_read_entry("fb", 0, NULL
, fbmem_read_proc
, NULL
);
1285 if (register_chrdev(FB_MAJOR
,"fb",&fb_fops
))
1286 printk("unable to get major %d for fb devs\n", FB_MAJOR
);
1288 fb_class
= class_simple_create(THIS_MODULE
, "graphics");
1289 if (IS_ERR(fb_class
)) {
1290 printk(KERN_WARNING
"Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class
));
1295 module_init(fbmem_init
);
1297 #define NR_FB_DRIVERS 64
1298 static char *video_options
[NR_FB_DRIVERS
];
1302 * fb_get_options - get kernel boot parameters
1303 * @name - framebuffer name as it would appear in
1304 * the boot parameter line
1305 * (video=<name>:<options>)
1307 * NOTE: Needed to maintain backwards compatibility
1309 int fb_get_options(char *name
, char **option
)
1311 char *opt
, *options
= NULL
;
1312 int opt_len
, retval
= 0;
1313 int name_len
= strlen(name
), i
;
1315 if (name_len
&& ofonly
&& strncmp(name
, "offb", 4))
1318 if (name_len
&& !retval
) {
1319 for (i
= 0; i
< NR_FB_DRIVERS
; i
++) {
1320 if (video_options
[i
] == NULL
)
1322 opt_len
= strlen(video_options
[i
]);
1325 opt
= video_options
[i
];
1326 if (!strncmp(name
, opt
, name_len
) &&
1327 opt
[name_len
] == ':')
1328 options
= opt
+ name_len
+ 1;
1331 if (options
&& !strncmp(options
, "off", 3))
1341 * video_setup - process command line options
1342 * @options: string of options
1344 * Process command line options for frame buffer subsystem.
1346 * NOTE: This function is a __setup and __init function.
1347 * It only stores the options. Drivers have to call
1348 * fb_get_options() as necessary.
1354 int __init
video_setup(char *options
)
1358 if (!options
|| !*options
)
1361 for (i
= 0; i
< NR_FB_DRIVERS
; i
++) {
1362 if (!strncmp(options
, "ofonly", 6))
1364 if (video_options
[i
] == NULL
) {
1365 video_options
[i
] = options
;
1372 __setup("video=", video_setup
);
1375 * Visible symbols for modules
1378 EXPORT_SYMBOL(register_framebuffer
);
1379 EXPORT_SYMBOL(unregister_framebuffer
);
1380 EXPORT_SYMBOL(num_registered_fb
);
1381 EXPORT_SYMBOL(registered_fb
);
1382 EXPORT_SYMBOL(fb_prepare_logo
);
1383 EXPORT_SYMBOL(fb_show_logo
);
1384 EXPORT_SYMBOL(fb_set_var
);
1385 EXPORT_SYMBOL(fb_blank
);
1386 EXPORT_SYMBOL(fb_pan_display
);
1387 EXPORT_SYMBOL(fb_get_buffer_offset
);
1388 EXPORT_SYMBOL(fb_iomove_buf_unaligned
);
1389 EXPORT_SYMBOL(fb_iomove_buf_aligned
);
1390 EXPORT_SYMBOL(fb_sysmove_buf_unaligned
);
1391 EXPORT_SYMBOL(fb_sysmove_buf_aligned
);
1392 EXPORT_SYMBOL(fb_load_cursor_image
);
1393 EXPORT_SYMBOL(fb_set_suspend
);
1394 EXPORT_SYMBOL(fb_register_client
);
1395 EXPORT_SYMBOL(fb_unregister_client
);
1396 EXPORT_SYMBOL(fb_get_options
);
1398 MODULE_LICENSE("GPL");