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
)
67 if (var
->green
.length
== var
->blue
.length
&&
68 var
->green
.length
== var
->red
.length
&&
69 !var
->green
.offset
&& !var
->blue
.offset
&&
71 return var
->green
.length
;
73 return (var
->green
.length
+ var
->red
.length
+
76 EXPORT_SYMBOL(fb_get_color_depth
);
79 * Data padding functions.
81 void fb_pad_aligned_buffer(u8
*dst
, u32 d_pitch
, u8
*src
, u32 s_pitch
, u32 height
)
85 for (i
= height
; i
--; ) {
86 /* s_pitch is a few bytes at the most, memcpy is suboptimal */
87 for (j
= 0; j
< s_pitch
; j
++)
93 EXPORT_SYMBOL(fb_pad_aligned_buffer
);
95 void fb_pad_unaligned_buffer(u8
*dst
, u32 d_pitch
, u8
*src
, u32 idx
, u32 height
,
96 u32 shift_high
, u32 shift_low
, u32 mod
)
98 u8 mask
= (u8
) (0xfff << shift_high
), tmp
;
101 for (i
= height
; i
--; ) {
102 for (j
= 0; j
< idx
; j
++) {
105 tmp
|= *src
>> shift_low
;
107 tmp
= *src
<< shift_high
;
113 tmp
|= *src
>> shift_low
;
115 if (shift_high
< mod
) {
116 tmp
= *src
<< shift_high
;
123 EXPORT_SYMBOL(fb_pad_unaligned_buffer
);
126 * we need to lock this section since fb_cursor
127 * may use fb_imageblit()
129 char* fb_get_buffer_offset(struct fb_info
*info
, struct fb_pixmap
*buf
, u32 size
)
131 u32 align
= buf
->buf_align
- 1, offset
;
132 char *addr
= buf
->addr
;
134 /* If IO mapped, we need to sync before access, no sharing of
137 if (buf
->flags
& FB_PIXMAP_IO
) {
138 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
139 info
->fbops
->fb_sync(info
);
143 /* See if we fit in the remaining pixmap space */
144 offset
= buf
->offset
+ align
;
146 if (offset
+ size
> buf
->size
) {
147 /* We do not fit. In order to be able to re-use the buffer,
148 * we must ensure no asynchronous DMA'ing or whatever operation
149 * is in progress, we sync for that.
151 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
152 info
->fbops
->fb_sync(info
);
155 buf
->offset
= offset
+ size
;
162 #include <linux/linux_logo.h>
164 static inline unsigned safe_shift(unsigned d
, int n
)
166 return n
< 0 ? d
>> -n
: d
<< n
;
169 static void fb_set_logocmap(struct fb_info
*info
,
170 const struct linux_logo
*logo
)
172 struct fb_cmap palette_cmap
;
173 u16 palette_green
[16];
174 u16 palette_blue
[16];
177 const unsigned char *clut
= logo
->clut
;
179 palette_cmap
.start
= 0;
180 palette_cmap
.len
= 16;
181 palette_cmap
.red
= palette_red
;
182 palette_cmap
.green
= palette_green
;
183 palette_cmap
.blue
= palette_blue
;
184 palette_cmap
.transp
= NULL
;
186 for (i
= 0; i
< logo
->clutsize
; i
+= n
) {
187 n
= logo
->clutsize
- i
;
188 /* palette_cmap provides space for only 16 colors at once */
191 palette_cmap
.start
= 32 + i
;
192 palette_cmap
.len
= n
;
193 for (j
= 0; j
< n
; ++j
) {
194 palette_cmap
.red
[j
] = clut
[0] << 8 | clut
[0];
195 palette_cmap
.green
[j
] = clut
[1] << 8 | clut
[1];
196 palette_cmap
.blue
[j
] = clut
[2] << 8 | clut
[2];
199 fb_set_cmap(&palette_cmap
, info
);
203 static void fb_set_logo_truepalette(struct fb_info
*info
,
204 const struct linux_logo
*logo
,
207 unsigned char mask
[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
208 unsigned char redmask
, greenmask
, bluemask
;
209 int redshift
, greenshift
, blueshift
;
211 const unsigned char *clut
= logo
->clut
;
214 * We have to create a temporary palette since console palette is only
217 /* Bug: Doesn't obey msb_right ... (who needs that?) */
218 redmask
= mask
[info
->var
.red
.length
< 8 ? info
->var
.red
.length
: 8];
219 greenmask
= mask
[info
->var
.green
.length
< 8 ? info
->var
.green
.length
: 8];
220 bluemask
= mask
[info
->var
.blue
.length
< 8 ? info
->var
.blue
.length
: 8];
221 redshift
= info
->var
.red
.offset
- (8 - info
->var
.red
.length
);
222 greenshift
= info
->var
.green
.offset
- (8 - info
->var
.green
.length
);
223 blueshift
= info
->var
.blue
.offset
- (8 - info
->var
.blue
.length
);
225 for ( i
= 0; i
< logo
->clutsize
; i
++) {
226 palette
[i
+32] = (safe_shift((clut
[0] & redmask
), redshift
) |
227 safe_shift((clut
[1] & greenmask
), greenshift
) |
228 safe_shift((clut
[2] & bluemask
), blueshift
));
233 static void fb_set_logo_directpalette(struct fb_info
*info
,
234 const struct linux_logo
*logo
,
237 int redshift
, greenshift
, blueshift
;
240 redshift
= info
->var
.red
.offset
;
241 greenshift
= info
->var
.green
.offset
;
242 blueshift
= info
->var
.blue
.offset
;
244 for (i
= 32; i
< logo
->clutsize
; i
++)
245 palette
[i
] = i
<< redshift
| i
<< greenshift
| i
<< blueshift
;
248 static void fb_set_logo(struct fb_info
*info
,
249 const struct linux_logo
*logo
, u8
*dst
,
253 const u8
*src
= logo
->data
;
254 u8 d
, xor = (info
->fix
.visual
== FB_VISUAL_MONO01
) ? 0xff : 0;
256 if (fb_get_color_depth(&info
->var
) == 3)
261 for (i
= 0; i
< logo
->height
; i
++)
262 for (j
= 0; j
< logo
->width
; src
++) {
265 if (j
< logo
->width
) {
266 *dst
++ = *src
& 0x0f;
272 for (i
= 0; i
< logo
->height
; i
++) {
273 for (j
= 0; j
< logo
->width
; src
++) {
275 for (k
= 7; k
>= 0; k
--) {
276 *dst
++ = ((d
>> k
) & 1) ? fg
: 0;
286 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
287 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
288 * the visual format and color depth of the framebuffer, the DAC, the
289 * pseudo_palette, and the logo data will be adjusted accordingly.
291 * Case 1 - linux_logo_clut224:
292 * Color exceeds the number of console colors (16), thus we set the hardware DAC
293 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
295 * For visuals that require color info from the pseudo_palette, we also construct
296 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
299 * Case 2 - linux_logo_vga16:
300 * The number of colors just matches the console colors, thus there is no need
301 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
302 * each byte contains color information for two pixels (upper and lower nibble).
303 * To be consistent with fb_imageblit() usage, we therefore separate the two
304 * nibbles into separate bytes. The "depth" flag will be set to 4.
306 * Case 3 - linux_logo_mono:
307 * This is similar with Case 2. Each byte contains information for 8 pixels.
308 * We isolate each bit and expand each into a byte. The "depth" flag will
311 static struct logo_data
{
313 int needs_directpalette
;
314 int needs_truepalette
;
316 const struct linux_logo
*logo
;
319 int fb_prepare_logo(struct fb_info
*info
)
321 int depth
= fb_get_color_depth(&info
->var
);
323 memset(&fb_logo
, 0, sizeof(struct logo_data
));
325 if (info
->flags
& FBINFO_MISC_TILEBLITTING
)
328 if (info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
329 depth
= info
->var
.blue
.length
;
330 if (info
->var
.red
.length
< depth
)
331 depth
= info
->var
.red
.length
;
332 if (info
->var
.green
.length
< depth
)
333 depth
= info
->var
.green
.length
;
337 switch (info
->fix
.visual
) {
338 case FB_VISUAL_TRUECOLOR
:
339 fb_logo
.needs_truepalette
= 1;
341 case FB_VISUAL_DIRECTCOLOR
:
342 fb_logo
.needs_directpalette
= 1;
343 fb_logo
.needs_cmapreset
= 1;
345 case FB_VISUAL_PSEUDOCOLOR
:
346 fb_logo
.needs_cmapreset
= 1;
351 /* Return if no suitable logo was found */
352 fb_logo
.logo
= fb_find_logo(depth
);
354 if (!fb_logo
.logo
|| fb_logo
.logo
->height
> info
->var
.yres
) {
358 /* What depth we asked for might be different from what we get */
359 if (fb_logo
.logo
->type
== LINUX_LOGO_CLUT224
)
361 else if (fb_logo
.logo
->type
== LINUX_LOGO_VGA16
)
365 return fb_logo
.logo
->height
;
368 int fb_show_logo(struct fb_info
*info
)
370 u32
*palette
= NULL
, *saved_pseudo_palette
= NULL
;
371 unsigned char *logo_new
= NULL
;
372 struct fb_image image
;
375 /* Return if the frame buffer is not mapped or suspended */
376 if (fb_logo
.logo
== NULL
|| info
->state
!= FBINFO_STATE_RUNNING
)
380 image
.data
= fb_logo
.logo
->data
;
382 if (fb_logo
.needs_cmapreset
)
383 fb_set_logocmap(info
, fb_logo
.logo
);
385 if (fb_logo
.needs_truepalette
||
386 fb_logo
.needs_directpalette
) {
387 palette
= kmalloc(256 * 4, GFP_KERNEL
);
391 if (fb_logo
.needs_truepalette
)
392 fb_set_logo_truepalette(info
, fb_logo
.logo
, palette
);
394 fb_set_logo_directpalette(info
, fb_logo
.logo
, palette
);
396 saved_pseudo_palette
= info
->pseudo_palette
;
397 info
->pseudo_palette
= palette
;
400 if (fb_logo
.depth
<= 4) {
401 logo_new
= kmalloc(fb_logo
.logo
->width
* fb_logo
.logo
->height
,
403 if (logo_new
== NULL
) {
405 if (saved_pseudo_palette
)
406 info
->pseudo_palette
= saved_pseudo_palette
;
409 image
.data
= logo_new
;
410 fb_set_logo(info
, fb_logo
.logo
, logo_new
, fb_logo
.depth
);
413 image
.width
= fb_logo
.logo
->width
;
414 image
.height
= fb_logo
.logo
->height
;
417 for (x
= 0; x
< num_online_cpus() * (fb_logo
.logo
->width
+ 8) &&
418 x
<= info
->var
.xres
-fb_logo
.logo
->width
; x
+= (fb_logo
.logo
->width
+ 8)) {
420 info
->fbops
->fb_imageblit(info
, &image
);
424 if (saved_pseudo_palette
!= NULL
)
425 info
->pseudo_palette
= saved_pseudo_palette
;
427 return fb_logo
.logo
->height
;
430 int fb_prepare_logo(struct fb_info
*info
) { return 0; }
431 int fb_show_logo(struct fb_info
*info
) { return 0; }
432 #endif /* CONFIG_LOGO */
434 static int fbmem_read_proc(char *buf
, char **start
, off_t offset
,
435 int len
, int *eof
, void *private)
441 for (fi
= registered_fb
; fi
< ®istered_fb
[FB_MAX
] && len
< 4000; fi
++)
443 clen
+= sprintf(buf
+ clen
, "%d %s\n",
446 *start
= buf
+ offset
;
451 return clen
< len
? clen
: len
;
455 fb_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
457 unsigned long p
= *ppos
;
458 struct inode
*inode
= file
->f_dentry
->d_inode
;
459 int fbidx
= iminor(inode
);
460 struct fb_info
*info
= registered_fb
[fbidx
];
463 int c
, i
, cnt
= 0, err
= 0;
464 unsigned long total_size
;
466 if (!info
|| ! info
->screen_base
)
469 if (info
->state
!= FBINFO_STATE_RUNNING
)
472 if (info
->fbops
->fb_read
)
473 return info
->fbops
->fb_read(file
, buf
, count
, ppos
);
475 total_size
= info
->screen_size
;
477 total_size
= info
->fix
.smem_len
;
481 if (count
>= total_size
)
483 if (count
+ p
> total_size
)
484 count
= total_size
- p
;
487 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
492 src
= (u32 __iomem
*) (info
->screen_base
+ p
);
494 if (info
->fbops
->fb_sync
)
495 info
->fbops
->fb_sync(info
);
498 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
500 for (i
= c
>> 2; i
--; )
501 *dst
++ = fb_readl(src
++);
503 u8
*dst8
= (u8
*) dst
;
504 u8 __iomem
*src8
= (u8 __iomem
*) src
;
506 for (i
= c
& 3; i
--;)
507 *dst8
++ = fb_readb(src8
++);
509 src
= (u32 __iomem
*) src8
;
512 if (copy_to_user(buf
, buffer
, c
)) {
523 return (err
) ? err
: cnt
;
527 fb_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
529 unsigned long p
= *ppos
;
530 struct inode
*inode
= file
->f_dentry
->d_inode
;
531 int fbidx
= iminor(inode
);
532 struct fb_info
*info
= registered_fb
[fbidx
];
535 int c
, i
, cnt
= 0, err
;
536 unsigned long total_size
;
538 if (!info
|| !info
->screen_base
)
541 if (info
->state
!= FBINFO_STATE_RUNNING
)
544 if (info
->fbops
->fb_write
)
545 return info
->fbops
->fb_write(file
, buf
, count
, ppos
);
547 total_size
= info
->screen_size
;
549 total_size
= info
->fix
.smem_len
;
553 if (count
>= total_size
)
556 if (count
+ p
> total_size
) {
557 count
= total_size
- p
;
561 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
566 dst
= (u32 __iomem
*) (info
->screen_base
+ p
);
568 if (info
->fbops
->fb_sync
)
569 info
->fbops
->fb_sync(info
);
572 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
574 if (copy_from_user(src
, buf
, c
)) {
578 for (i
= c
>> 2; i
--; )
579 fb_writel(*src
++, dst
++);
581 u8
*src8
= (u8
*) src
;
582 u8 __iomem
*dst8
= (u8 __iomem
*) dst
;
584 for (i
= c
& 3; i
--; )
585 fb_writeb(*src8
++, dst8
++);
587 dst
= (u32 __iomem
*) dst8
;
596 return (err
) ? err
: cnt
;
600 static void try_to_load(int fb
)
602 request_module("fb%d", fb
);
604 #endif /* CONFIG_KMOD */
607 fb_pan_display(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
609 int xoffset
= var
->xoffset
;
610 int yoffset
= var
->yoffset
;
613 if (xoffset
< 0 || yoffset
< 0 || !info
->fbops
->fb_pan_display
||
614 xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
||
615 yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
617 if ((err
= info
->fbops
->fb_pan_display(var
, info
)))
619 info
->var
.xoffset
= var
->xoffset
;
620 info
->var
.yoffset
= var
->yoffset
;
621 if (var
->vmode
& FB_VMODE_YWRAP
)
622 info
->var
.vmode
|= FB_VMODE_YWRAP
;
624 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
629 fb_set_var(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
631 int err
, flags
= info
->flags
;
633 if (var
->activate
& FB_ACTIVATE_INV_MODE
) {
634 struct fb_videomode mode1
, mode2
;
637 fb_var_to_videomode(&mode1
, var
);
638 fb_var_to_videomode(&mode2
, &info
->var
);
639 /* make sure we don't delete the videomode of current var */
640 ret
= fb_mode_is_equal(&mode1
, &mode2
);
643 struct fb_event event
;
647 ret
= notifier_call_chain(&fb_notifier_list
,
648 FB_EVENT_MODE_DELETE
, &event
);
652 fb_delete_videomode(&mode1
, &info
->modelist
);
657 if ((var
->activate
& FB_ACTIVATE_FORCE
) ||
658 memcmp(&info
->var
, var
, sizeof(struct fb_var_screeninfo
))) {
659 if (!info
->fbops
->fb_check_var
) {
664 if ((err
= info
->fbops
->fb_check_var(var
, info
)))
667 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
668 struct fb_videomode mode
;
672 if (info
->fbops
->fb_set_par
)
673 info
->fbops
->fb_set_par(info
);
675 fb_pan_display(info
, &info
->var
);
677 fb_set_cmap(&info
->cmap
, info
);
679 fb_var_to_videomode(&mode
, &info
->var
);
681 if (info
->modelist
.prev
&& info
->modelist
.next
&&
682 !list_empty(&info
->modelist
))
683 err
= fb_add_videomode(&mode
, &info
->modelist
);
685 if (!err
&& (flags
& FBINFO_MISC_USEREVENT
)) {
686 struct fb_event event
;
688 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
690 notifier_call_chain(&fb_notifier_list
,
691 FB_EVENT_MODE_CHANGE
,
700 fb_blank(struct fb_info
*info
, int blank
)
704 if (blank
> FB_BLANK_POWERDOWN
)
705 blank
= FB_BLANK_POWERDOWN
;
707 if (info
->fbops
->fb_blank
)
708 ret
= info
->fbops
->fb_blank(blank
, info
);
711 struct fb_event event
;
715 notifier_call_chain(&fb_notifier_list
, FB_EVENT_BLANK
, &event
);
722 fb_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
725 int fbidx
= iminor(inode
);
726 struct fb_info
*info
= registered_fb
[fbidx
];
727 struct fb_ops
*fb
= info
->fbops
;
728 struct fb_var_screeninfo var
;
729 struct fb_fix_screeninfo fix
;
730 struct fb_con2fbmap con2fb
;
731 struct fb_cmap_user cmap
;
732 struct fb_event event
;
733 void __user
*argp
= (void __user
*)arg
;
739 case FBIOGET_VSCREENINFO
:
740 return copy_to_user(argp
, &info
->var
,
741 sizeof(var
)) ? -EFAULT
: 0;
742 case FBIOPUT_VSCREENINFO
:
743 if (copy_from_user(&var
, argp
, sizeof(var
)))
745 acquire_console_sem();
746 info
->flags
|= FBINFO_MISC_USEREVENT
;
747 i
= fb_set_var(info
, &var
);
748 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
749 release_console_sem();
751 if (copy_to_user(argp
, &var
, sizeof(var
)))
754 case FBIOGET_FSCREENINFO
:
755 return copy_to_user(argp
, &info
->fix
,
756 sizeof(fix
)) ? -EFAULT
: 0;
758 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
760 return (fb_set_user_cmap(&cmap
, info
));
762 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
764 return fb_cmap_to_user(&info
->cmap
, &cmap
);
765 case FBIOPAN_DISPLAY
:
766 if (copy_from_user(&var
, argp
, sizeof(var
)))
768 acquire_console_sem();
769 i
= fb_pan_display(info
, &var
);
770 release_console_sem();
773 if (copy_to_user(argp
, &var
, sizeof(var
)))
778 case FBIOGET_CON2FBMAP
:
779 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
781 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
783 con2fb
.framebuffer
= -1;
785 event
.data
= &con2fb
;
786 notifier_call_chain(&fb_notifier_list
,
787 FB_EVENT_GET_CONSOLE_MAP
, &event
);
788 return copy_to_user(argp
, &con2fb
,
789 sizeof(con2fb
)) ? -EFAULT
: 0;
790 case FBIOPUT_CON2FBMAP
:
791 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
793 if (con2fb
.console
< 0 || con2fb
.console
> MAX_NR_CONSOLES
)
795 if (con2fb
.framebuffer
< 0 || con2fb
.framebuffer
>= FB_MAX
)
798 if (!registered_fb
[con2fb
.framebuffer
])
799 try_to_load(con2fb
.framebuffer
);
800 #endif /* CONFIG_KMOD */
801 if (!registered_fb
[con2fb
.framebuffer
])
804 event
.data
= &con2fb
;
805 return notifier_call_chain(&fb_notifier_list
,
806 FB_EVENT_SET_CONSOLE_MAP
,
809 acquire_console_sem();
810 info
->flags
|= FBINFO_MISC_USEREVENT
;
811 i
= fb_blank(info
, arg
);
812 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
813 release_console_sem();
816 if (fb
->fb_ioctl
== NULL
)
818 return fb
->fb_ioctl(inode
, file
, cmd
, arg
, info
);
824 fb_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
826 int fbidx
= iminor(file
->f_dentry
->d_inode
);
827 struct fb_info
*info
= registered_fb
[fbidx
];
828 struct fb_ops
*fb
= info
->fbops
;
831 if (fb
->fb_compat_ioctl
== NULL
)
834 ret
= fb
->fb_compat_ioctl(file
, cmd
, arg
, info
);
841 fb_mmap(struct file
*file
, struct vm_area_struct
* vma
)
843 int fbidx
= iminor(file
->f_dentry
->d_inode
);
844 struct fb_info
*info
= registered_fb
[fbidx
];
845 struct fb_ops
*fb
= info
->fbops
;
847 #if !defined(__sparc__) || defined(__sparc_v9__)
852 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
))
854 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
860 res
= fb
->fb_mmap(info
, file
, vma
);
865 #if defined(__sparc__) && !defined(__sparc_v9__)
866 /* Should never get here, all fb drivers should have their own
873 /* frame buffer memory */
874 start
= info
->fix
.smem_start
;
875 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.smem_len
);
877 /* memory mapped io */
879 if (info
->var
.accel_flags
) {
883 start
= info
->fix
.mmio_start
;
884 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.mmio_len
);
888 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
891 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
892 /* This is an IO map - tell maydump to skip this VMA */
893 vma
->vm_flags
|= VM_IO
| VM_RESERVED
;
894 #if defined(__sparc_v9__)
895 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
896 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
899 #if defined(__mc68000__)
900 #if defined(CONFIG_SUN3)
901 pgprot_val(vma
->vm_page_prot
) |= SUN3_PAGE_NOCACHE
;
902 #elif defined(CONFIG_MMU)
903 if (CPU_IS_020_OR_030
)
904 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE030
;
905 if (CPU_IS_040_OR_060
) {
906 pgprot_val(vma
->vm_page_prot
) &= _CACHEMASK040
;
907 /* Use no-cache mode, serialized */
908 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE_S
;
911 #elif defined(__powerpc__)
912 vma
->vm_page_prot
= phys_mem_access_prot(file
, off
,
913 vma
->vm_end
- vma
->vm_start
,
915 #elif defined(__alpha__)
916 /* Caching is off in the I/O space quadrant by design. */
917 #elif defined(__i386__) || defined(__x86_64__)
918 if (boot_cpu_data
.x86
> 3)
919 pgprot_val(vma
->vm_page_prot
) |= _PAGE_PCD
;
920 #elif defined(__mips__)
921 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
922 #elif defined(__hppa__)
923 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NO_CACHE
;
924 #elif defined(__arm__) || defined(__sh__) || defined(__m32r__)
925 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
926 #elif defined(__ia64__)
927 if (efi_range_is_wc(vma
->vm_start
, vma
->vm_end
- vma
->vm_start
))
928 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
930 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
932 #warning What do we have to do here??
934 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
935 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
937 #endif /* !__sparc_v9__ */
939 #endif /* !sparc32 */
943 fb_open(struct inode
*inode
, struct file
*file
)
945 int fbidx
= iminor(inode
);
946 struct fb_info
*info
;
952 if (!(info
= registered_fb
[fbidx
]))
954 #endif /* CONFIG_KMOD */
955 if (!(info
= registered_fb
[fbidx
]))
957 if (!try_module_get(info
->fbops
->owner
))
959 if (info
->fbops
->fb_open
) {
960 res
= info
->fbops
->fb_open(info
,1);
962 module_put(info
->fbops
->owner
);
968 fb_release(struct inode
*inode
, struct file
*file
)
970 int fbidx
= iminor(inode
);
971 struct fb_info
*info
;
974 info
= registered_fb
[fbidx
];
975 if (info
->fbops
->fb_release
)
976 info
->fbops
->fb_release(info
,1);
977 module_put(info
->fbops
->owner
);
982 static struct file_operations fb_fops
= {
983 .owner
= THIS_MODULE
,
988 .compat_ioctl
= fb_compat_ioctl
,
992 .release
= fb_release
,
993 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
994 .get_unmapped_area
= get_fb_unmapped_area
,
998 static struct class *fb_class
;
1001 * register_framebuffer - registers a frame buffer device
1002 * @fb_info: frame buffer info structure
1004 * Registers a frame buffer device @fb_info.
1006 * Returns negative errno on error, or zero for success.
1011 register_framebuffer(struct fb_info
*fb_info
)
1014 struct fb_event event
;
1016 if (num_registered_fb
== FB_MAX
)
1018 num_registered_fb
++;
1019 for (i
= 0 ; i
< FB_MAX
; i
++)
1020 if (!registered_fb
[i
])
1024 fb_info
->class_device
= class_device_create(fb_class
, MKDEV(FB_MAJOR
, i
),
1025 fb_info
->device
, "fb%d", i
);
1026 if (IS_ERR(fb_info
->class_device
)) {
1028 printk(KERN_WARNING
"Unable to create class_device for framebuffer %d; errno = %ld\n", i
, PTR_ERR(fb_info
->class_device
));
1029 fb_info
->class_device
= NULL
;
1031 fb_init_class_device(fb_info
);
1033 if (fb_info
->pixmap
.addr
== NULL
) {
1034 fb_info
->pixmap
.addr
= kmalloc(FBPIXMAPSIZE
, GFP_KERNEL
);
1035 if (fb_info
->pixmap
.addr
) {
1036 fb_info
->pixmap
.size
= FBPIXMAPSIZE
;
1037 fb_info
->pixmap
.buf_align
= 1;
1038 fb_info
->pixmap
.scan_align
= 1;
1039 fb_info
->pixmap
.access_align
= 32;
1040 fb_info
->pixmap
.flags
= FB_PIXMAP_DEFAULT
;
1043 fb_info
->pixmap
.offset
= 0;
1045 if (!fb_info
->modelist
.prev
||
1046 !fb_info
->modelist
.next
||
1047 list_empty(&fb_info
->modelist
)) {
1048 struct fb_videomode mode
;
1050 INIT_LIST_HEAD(&fb_info
->modelist
);
1051 fb_var_to_videomode(&mode
, &fb_info
->var
);
1052 fb_add_videomode(&mode
, &fb_info
->modelist
);
1055 registered_fb
[i
] = fb_info
;
1057 devfs_mk_cdev(MKDEV(FB_MAJOR
, i
),
1058 S_IFCHR
| S_IRUGO
| S_IWUGO
, "fb/%d", i
);
1059 event
.info
= fb_info
;
1060 notifier_call_chain(&fb_notifier_list
,
1061 FB_EVENT_FB_REGISTERED
, &event
);
1067 * unregister_framebuffer - releases a frame buffer device
1068 * @fb_info: frame buffer info structure
1070 * Unregisters a frame buffer device @fb_info.
1072 * Returns negative errno on error, or zero for success.
1077 unregister_framebuffer(struct fb_info
*fb_info
)
1082 if (!registered_fb
[i
])
1084 devfs_remove("fb/%d", i
);
1086 if (fb_info
->pixmap
.addr
&& (fb_info
->pixmap
.flags
& FB_PIXMAP_DEFAULT
))
1087 kfree(fb_info
->pixmap
.addr
);
1088 fb_destroy_modelist(&fb_info
->modelist
);
1089 registered_fb
[i
]=NULL
;
1090 num_registered_fb
--;
1091 fb_cleanup_class_device(fb_info
);
1092 class_device_destroy(fb_class
, MKDEV(FB_MAJOR
, i
));
1097 * fb_register_client - register a client notifier
1098 * @nb: notifier block to callback on events
1100 int fb_register_client(struct notifier_block
*nb
)
1102 return notifier_chain_register(&fb_notifier_list
, nb
);
1106 * fb_unregister_client - unregister a client notifier
1107 * @nb: notifier block to callback on events
1109 int fb_unregister_client(struct notifier_block
*nb
)
1111 return notifier_chain_unregister(&fb_notifier_list
, nb
);
1115 * fb_set_suspend - low level driver signals suspend
1116 * @info: framebuffer affected
1117 * @state: 0 = resuming, !=0 = suspending
1119 * This is meant to be used by low level drivers to
1120 * signal suspend/resume to the core & clients.
1121 * It must be called with the console semaphore held
1123 void fb_set_suspend(struct fb_info
*info
, int state
)
1125 struct fb_event event
;
1129 notifier_call_chain(&fb_notifier_list
, FB_EVENT_SUSPEND
, &event
);
1130 info
->state
= FBINFO_STATE_SUSPENDED
;
1132 info
->state
= FBINFO_STATE_RUNNING
;
1133 notifier_call_chain(&fb_notifier_list
, FB_EVENT_RESUME
, &event
);
1138 * fbmem_init - init frame buffer subsystem
1140 * Initialize the frame buffer subsystem.
1142 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1149 create_proc_read_entry("fb", 0, NULL
, fbmem_read_proc
, NULL
);
1152 if (register_chrdev(FB_MAJOR
,"fb",&fb_fops
))
1153 printk("unable to get major %d for fb devs\n", FB_MAJOR
);
1155 fb_class
= class_create(THIS_MODULE
, "graphics");
1156 if (IS_ERR(fb_class
)) {
1157 printk(KERN_WARNING
"Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class
));
1164 module_init(fbmem_init
);
1168 class_destroy(fb_class
);
1169 unregister_chrdev(FB_MAJOR
, "fb");
1172 module_exit(fbmem_exit
);
1173 MODULE_LICENSE("GPL");
1174 MODULE_DESCRIPTION("Framebuffer base");
1176 subsys_initcall(fbmem_init
);
1179 int fb_new_modelist(struct fb_info
*info
)
1181 struct fb_event event
;
1182 struct fb_var_screeninfo var
= info
->var
;
1183 struct list_head
*pos
, *n
;
1184 struct fb_modelist
*modelist
;
1185 struct fb_videomode
*m
, mode
;
1188 list_for_each_safe(pos
, n
, &info
->modelist
) {
1189 modelist
= list_entry(pos
, struct fb_modelist
, list
);
1190 m
= &modelist
->mode
;
1191 fb_videomode_to_var(&var
, m
);
1192 var
.activate
= FB_ACTIVATE_TEST
;
1193 err
= fb_set_var(info
, &var
);
1194 fb_var_to_videomode(&mode
, &var
);
1195 if (err
|| !fb_mode_is_equal(m
, &mode
)) {
1203 if (!list_empty(&info
->modelist
)) {
1205 err
= notifier_call_chain(&fb_notifier_list
,
1206 FB_EVENT_NEW_MODELIST
,
1213 static char *video_options
[FB_MAX
];
1216 extern const char *global_mode_option
;
1219 * fb_get_options - get kernel boot parameters
1220 * @name: framebuffer name as it would appear in
1221 * the boot parameter line
1222 * (video=<name>:<options>)
1223 * @option: the option will be stored here
1225 * NOTE: Needed to maintain backwards compatibility
1227 int fb_get_options(char *name
, char **option
)
1229 char *opt
, *options
= NULL
;
1230 int opt_len
, retval
= 0;
1231 int name_len
= strlen(name
), i
;
1233 if (name_len
&& ofonly
&& strncmp(name
, "offb", 4))
1236 if (name_len
&& !retval
) {
1237 for (i
= 0; i
< FB_MAX
; i
++) {
1238 if (video_options
[i
] == NULL
)
1240 opt_len
= strlen(video_options
[i
]);
1243 opt
= video_options
[i
];
1244 if (!strncmp(name
, opt
, name_len
) &&
1245 opt
[name_len
] == ':')
1246 options
= opt
+ name_len
+ 1;
1249 if (options
&& !strncmp(options
, "off", 3))
1259 * video_setup - process command line options
1260 * @options: string of options
1262 * Process command line options for frame buffer subsystem.
1264 * NOTE: This function is a __setup and __init function.
1265 * It only stores the options. Drivers have to call
1266 * fb_get_options() as necessary.
1271 static int __init
video_setup(char *options
)
1275 if (!options
|| !*options
)
1278 if (!global
&& !strncmp(options
, "ofonly", 6)) {
1283 if (!global
&& !strstr(options
, "fb:")) {
1284 global_mode_option
= options
;
1289 for (i
= 0; i
< FB_MAX
; i
++) {
1290 if (video_options
[i
] == NULL
) {
1291 video_options
[i
] = options
;
1300 __setup("video=", video_setup
);
1303 * Visible symbols for modules
1306 EXPORT_SYMBOL(register_framebuffer
);
1307 EXPORT_SYMBOL(unregister_framebuffer
);
1308 EXPORT_SYMBOL(num_registered_fb
);
1309 EXPORT_SYMBOL(registered_fb
);
1310 EXPORT_SYMBOL(fb_prepare_logo
);
1311 EXPORT_SYMBOL(fb_show_logo
);
1312 EXPORT_SYMBOL(fb_set_var
);
1313 EXPORT_SYMBOL(fb_blank
);
1314 EXPORT_SYMBOL(fb_pan_display
);
1315 EXPORT_SYMBOL(fb_get_buffer_offset
);
1316 EXPORT_SYMBOL(fb_set_suspend
);
1317 EXPORT_SYMBOL(fb_register_client
);
1318 EXPORT_SYMBOL(fb_unregister_client
);
1319 EXPORT_SYMBOL(fb_get_options
);
1320 EXPORT_SYMBOL(fb_new_modelist
);
1322 MODULE_LICENSE("GPL");