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 memcpy(dst
, src
, s_pitch
);
91 EXPORT_SYMBOL(fb_pad_aligned_buffer
);
93 void fb_pad_unaligned_buffer(u8
*dst
, u32 d_pitch
, u8
*src
, u32 idx
, u32 height
,
94 u32 shift_high
, u32 shift_low
, u32 mod
)
96 u8 mask
= (u8
) (0xfff << shift_high
), tmp
;
99 for (i
= height
; i
--; ) {
100 for (j
= 0; j
< idx
; j
++) {
103 tmp
|= *src
>> shift_low
;
105 tmp
= *src
<< shift_high
;
111 tmp
|= *src
>> shift_low
;
113 if (shift_high
< mod
) {
114 tmp
= *src
<< shift_high
;
121 EXPORT_SYMBOL(fb_pad_unaligned_buffer
);
124 * we need to lock this section since fb_cursor
125 * may use fb_imageblit()
127 char* fb_get_buffer_offset(struct fb_info
*info
, struct fb_pixmap
*buf
, u32 size
)
129 u32 align
= buf
->buf_align
- 1, offset
;
130 char *addr
= buf
->addr
;
132 /* If IO mapped, we need to sync before access, no sharing of
135 if (buf
->flags
& FB_PIXMAP_IO
) {
136 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
137 info
->fbops
->fb_sync(info
);
141 /* See if we fit in the remaining pixmap space */
142 offset
= buf
->offset
+ align
;
144 if (offset
+ size
> buf
->size
) {
145 /* We do not fit. In order to be able to re-use the buffer,
146 * we must ensure no asynchronous DMA'ing or whatever operation
147 * is in progress, we sync for that.
149 if (info
->fbops
->fb_sync
&& (buf
->flags
& FB_PIXMAP_SYNC
))
150 info
->fbops
->fb_sync(info
);
153 buf
->offset
= offset
+ size
;
160 #include <linux/linux_logo.h>
162 static inline unsigned safe_shift(unsigned d
, int n
)
164 return n
< 0 ? d
>> -n
: d
<< n
;
167 static void fb_set_logocmap(struct fb_info
*info
,
168 const struct linux_logo
*logo
)
170 struct fb_cmap palette_cmap
;
171 u16 palette_green
[16];
172 u16 palette_blue
[16];
175 const unsigned char *clut
= logo
->clut
;
177 palette_cmap
.start
= 0;
178 palette_cmap
.len
= 16;
179 palette_cmap
.red
= palette_red
;
180 palette_cmap
.green
= palette_green
;
181 palette_cmap
.blue
= palette_blue
;
182 palette_cmap
.transp
= NULL
;
184 for (i
= 0; i
< logo
->clutsize
; i
+= n
) {
185 n
= logo
->clutsize
- i
;
186 /* palette_cmap provides space for only 16 colors at once */
189 palette_cmap
.start
= 32 + i
;
190 palette_cmap
.len
= n
;
191 for (j
= 0; j
< n
; ++j
) {
192 palette_cmap
.red
[j
] = clut
[0] << 8 | clut
[0];
193 palette_cmap
.green
[j
] = clut
[1] << 8 | clut
[1];
194 palette_cmap
.blue
[j
] = clut
[2] << 8 | clut
[2];
197 fb_set_cmap(&palette_cmap
, info
);
201 static void fb_set_logo_truepalette(struct fb_info
*info
,
202 const struct linux_logo
*logo
,
205 unsigned char mask
[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
206 unsigned char redmask
, greenmask
, bluemask
;
207 int redshift
, greenshift
, blueshift
;
209 const unsigned char *clut
= logo
->clut
;
212 * We have to create a temporary palette since console palette is only
215 /* Bug: Doesn't obey msb_right ... (who needs that?) */
216 redmask
= mask
[info
->var
.red
.length
< 8 ? info
->var
.red
.length
: 8];
217 greenmask
= mask
[info
->var
.green
.length
< 8 ? info
->var
.green
.length
: 8];
218 bluemask
= mask
[info
->var
.blue
.length
< 8 ? info
->var
.blue
.length
: 8];
219 redshift
= info
->var
.red
.offset
- (8 - info
->var
.red
.length
);
220 greenshift
= info
->var
.green
.offset
- (8 - info
->var
.green
.length
);
221 blueshift
= info
->var
.blue
.offset
- (8 - info
->var
.blue
.length
);
223 for ( i
= 0; i
< logo
->clutsize
; i
++) {
224 palette
[i
+32] = (safe_shift((clut
[0] & redmask
), redshift
) |
225 safe_shift((clut
[1] & greenmask
), greenshift
) |
226 safe_shift((clut
[2] & bluemask
), blueshift
));
231 static void fb_set_logo_directpalette(struct fb_info
*info
,
232 const struct linux_logo
*logo
,
235 int redshift
, greenshift
, blueshift
;
238 redshift
= info
->var
.red
.offset
;
239 greenshift
= info
->var
.green
.offset
;
240 blueshift
= info
->var
.blue
.offset
;
242 for (i
= 32; i
< logo
->clutsize
; i
++)
243 palette
[i
] = i
<< redshift
| i
<< greenshift
| i
<< blueshift
;
246 static void fb_set_logo(struct fb_info
*info
,
247 const struct linux_logo
*logo
, u8
*dst
,
251 const u8
*src
= logo
->data
;
252 u8 d
, xor = (info
->fix
.visual
== FB_VISUAL_MONO01
) ? 0xff : 0;
254 if (fb_get_color_depth(&info
->var
) == 3)
259 for (i
= 0; i
< logo
->height
; i
++)
260 for (j
= 0; j
< logo
->width
; src
++) {
263 if (j
< logo
->width
) {
264 *dst
++ = *src
& 0x0f;
270 for (i
= 0; i
< logo
->height
; i
++) {
271 for (j
= 0; j
< logo
->width
; src
++) {
273 for (k
= 7; k
>= 0; k
--) {
274 *dst
++ = ((d
>> k
) & 1) ? fg
: 0;
284 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
285 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
286 * the visual format and color depth of the framebuffer, the DAC, the
287 * pseudo_palette, and the logo data will be adjusted accordingly.
289 * Case 1 - linux_logo_clut224:
290 * Color exceeds the number of console colors (16), thus we set the hardware DAC
291 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
293 * For visuals that require color info from the pseudo_palette, we also construct
294 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
297 * Case 2 - linux_logo_vga16:
298 * The number of colors just matches the console colors, thus there is no need
299 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
300 * each byte contains color information for two pixels (upper and lower nibble).
301 * To be consistent with fb_imageblit() usage, we therefore separate the two
302 * nibbles into separate bytes. The "depth" flag will be set to 4.
304 * Case 3 - linux_logo_mono:
305 * This is similar with Case 2. Each byte contains information for 8 pixels.
306 * We isolate each bit and expand each into a byte. The "depth" flag will
309 static struct logo_data
{
311 int needs_directpalette
;
312 int needs_truepalette
;
314 const struct linux_logo
*logo
;
317 int fb_prepare_logo(struct fb_info
*info
)
319 int depth
= fb_get_color_depth(&info
->var
);
321 memset(&fb_logo
, 0, sizeof(struct logo_data
));
323 if (info
->flags
& FBINFO_MISC_TILEBLITTING
)
326 if (info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
327 depth
= info
->var
.blue
.length
;
328 if (info
->var
.red
.length
< depth
)
329 depth
= info
->var
.red
.length
;
330 if (info
->var
.green
.length
< depth
)
331 depth
= info
->var
.green
.length
;
335 switch (info
->fix
.visual
) {
336 case FB_VISUAL_TRUECOLOR
:
337 fb_logo
.needs_truepalette
= 1;
339 case FB_VISUAL_DIRECTCOLOR
:
340 fb_logo
.needs_directpalette
= 1;
341 fb_logo
.needs_cmapreset
= 1;
343 case FB_VISUAL_PSEUDOCOLOR
:
344 fb_logo
.needs_cmapreset
= 1;
349 /* Return if no suitable logo was found */
350 fb_logo
.logo
= fb_find_logo(depth
);
352 if (!fb_logo
.logo
|| fb_logo
.logo
->height
> info
->var
.yres
) {
356 /* What depth we asked for might be different from what we get */
357 if (fb_logo
.logo
->type
== LINUX_LOGO_CLUT224
)
359 else if (fb_logo
.logo
->type
== LINUX_LOGO_VGA16
)
363 return fb_logo
.logo
->height
;
366 int fb_show_logo(struct fb_info
*info
)
368 u32
*palette
= NULL
, *saved_pseudo_palette
= NULL
;
369 unsigned char *logo_new
= NULL
;
370 struct fb_image image
;
373 /* Return if the frame buffer is not mapped or suspended */
374 if (fb_logo
.logo
== NULL
|| info
->state
!= FBINFO_STATE_RUNNING
)
378 image
.data
= fb_logo
.logo
->data
;
380 if (fb_logo
.needs_cmapreset
)
381 fb_set_logocmap(info
, fb_logo
.logo
);
383 if (fb_logo
.needs_truepalette
||
384 fb_logo
.needs_directpalette
) {
385 palette
= kmalloc(256 * 4, GFP_KERNEL
);
389 if (fb_logo
.needs_truepalette
)
390 fb_set_logo_truepalette(info
, fb_logo
.logo
, palette
);
392 fb_set_logo_directpalette(info
, fb_logo
.logo
, palette
);
394 saved_pseudo_palette
= info
->pseudo_palette
;
395 info
->pseudo_palette
= palette
;
398 if (fb_logo
.depth
<= 4) {
399 logo_new
= kmalloc(fb_logo
.logo
->width
* fb_logo
.logo
->height
,
401 if (logo_new
== NULL
) {
403 if (saved_pseudo_palette
)
404 info
->pseudo_palette
= saved_pseudo_palette
;
407 image
.data
= logo_new
;
408 fb_set_logo(info
, fb_logo
.logo
, logo_new
, fb_logo
.depth
);
411 image
.width
= fb_logo
.logo
->width
;
412 image
.height
= fb_logo
.logo
->height
;
415 for (x
= 0; x
< num_online_cpus() * (fb_logo
.logo
->width
+ 8) &&
416 x
<= info
->var
.xres
-fb_logo
.logo
->width
; x
+= (fb_logo
.logo
->width
+ 8)) {
418 info
->fbops
->fb_imageblit(info
, &image
);
422 if (saved_pseudo_palette
!= NULL
)
423 info
->pseudo_palette
= saved_pseudo_palette
;
425 return fb_logo
.logo
->height
;
428 int fb_prepare_logo(struct fb_info
*info
) { return 0; }
429 int fb_show_logo(struct fb_info
*info
) { return 0; }
430 #endif /* CONFIG_LOGO */
432 static int fbmem_read_proc(char *buf
, char **start
, off_t offset
,
433 int len
, int *eof
, void *private)
439 for (fi
= registered_fb
; fi
< ®istered_fb
[FB_MAX
] && len
< 4000; fi
++)
441 clen
+= sprintf(buf
+ clen
, "%d %s\n",
444 *start
= buf
+ offset
;
449 return clen
< len
? clen
: len
;
453 fb_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
455 unsigned long p
= *ppos
;
456 struct inode
*inode
= file
->f_dentry
->d_inode
;
457 int fbidx
= iminor(inode
);
458 struct fb_info
*info
= registered_fb
[fbidx
];
461 int c
, i
, cnt
= 0, err
= 0;
462 unsigned long total_size
;
464 if (!info
|| ! info
->screen_base
)
467 if (info
->state
!= FBINFO_STATE_RUNNING
)
470 if (info
->fbops
->fb_read
)
471 return info
->fbops
->fb_read(file
, buf
, count
, ppos
);
473 total_size
= info
->screen_size
;
475 total_size
= info
->fix
.smem_len
;
479 if (count
>= total_size
)
481 if (count
+ p
> total_size
)
482 count
= total_size
- p
;
485 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
490 src
= (u32 __iomem
*) (info
->screen_base
+ p
);
492 if (info
->fbops
->fb_sync
)
493 info
->fbops
->fb_sync(info
);
496 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
498 for (i
= c
>> 2; i
--; )
499 *dst
++ = fb_readl(src
++);
501 u8
*dst8
= (u8
*) dst
;
502 u8 __iomem
*src8
= (u8 __iomem
*) src
;
504 for (i
= c
& 3; i
--;)
505 *dst8
++ = fb_readb(src8
++);
507 src
= (u32 __iomem
*) src8
;
510 if (copy_to_user(buf
, buffer
, c
)) {
521 return (err
) ? err
: cnt
;
525 fb_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
527 unsigned long p
= *ppos
;
528 struct inode
*inode
= file
->f_dentry
->d_inode
;
529 int fbidx
= iminor(inode
);
530 struct fb_info
*info
= registered_fb
[fbidx
];
533 int c
, i
, cnt
= 0, err
;
534 unsigned long total_size
;
536 if (!info
|| !info
->screen_base
)
539 if (info
->state
!= FBINFO_STATE_RUNNING
)
542 if (info
->fbops
->fb_write
)
543 return info
->fbops
->fb_write(file
, buf
, count
, ppos
);
545 total_size
= info
->screen_size
;
547 total_size
= info
->fix
.smem_len
;
551 if (count
>= total_size
)
554 if (count
+ p
> total_size
) {
555 count
= total_size
- p
;
559 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
,
564 dst
= (u32 __iomem
*) (info
->screen_base
+ p
);
566 if (info
->fbops
->fb_sync
)
567 info
->fbops
->fb_sync(info
);
570 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
572 if (copy_from_user(src
, buf
, c
)) {
576 for (i
= c
>> 2; i
--; )
577 fb_writel(*src
++, dst
++);
579 u8
*src8
= (u8
*) src
;
580 u8 __iomem
*dst8
= (u8 __iomem
*) dst
;
582 for (i
= c
& 3; i
--; )
583 fb_writeb(*src8
++, dst8
++);
585 dst
= (u32 __iomem
*) dst8
;
594 return (err
) ? err
: cnt
;
598 static void try_to_load(int fb
)
600 request_module("fb%d", fb
);
602 #endif /* CONFIG_KMOD */
605 fb_pan_display(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
607 int xoffset
= var
->xoffset
;
608 int yoffset
= var
->yoffset
;
611 if (xoffset
< 0 || yoffset
< 0 || !info
->fbops
->fb_pan_display
||
612 xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
||
613 yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
615 if ((err
= info
->fbops
->fb_pan_display(var
, info
)))
617 info
->var
.xoffset
= var
->xoffset
;
618 info
->var
.yoffset
= var
->yoffset
;
619 if (var
->vmode
& FB_VMODE_YWRAP
)
620 info
->var
.vmode
|= FB_VMODE_YWRAP
;
622 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
627 fb_set_var(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
631 if (var
->activate
& FB_ACTIVATE_INV_MODE
) {
632 struct fb_videomode mode1
, mode2
;
635 fb_var_to_videomode(&mode1
, var
);
636 fb_var_to_videomode(&mode2
, &info
->var
);
637 /* make sure we don't delete the videomode of current var */
638 ret
= fb_mode_is_equal(&mode1
, &mode2
);
641 struct fb_event event
;
645 ret
= notifier_call_chain(&fb_notifier_list
,
646 FB_EVENT_MODE_DELETE
, &event
);
650 fb_delete_videomode(&mode1
, &info
->modelist
);
655 if ((var
->activate
& FB_ACTIVATE_FORCE
) ||
656 memcmp(&info
->var
, var
, sizeof(struct fb_var_screeninfo
))) {
657 if (!info
->fbops
->fb_check_var
) {
662 if ((err
= info
->fbops
->fb_check_var(var
, info
)))
665 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
) {
666 struct fb_videomode mode
;
670 if (info
->fbops
->fb_set_par
)
671 info
->fbops
->fb_set_par(info
);
673 fb_pan_display(info
, &info
->var
);
675 fb_set_cmap(&info
->cmap
, info
);
677 fb_var_to_videomode(&mode
, &info
->var
);
679 if (info
->modelist
.prev
&& info
->modelist
.next
&&
680 !list_empty(&info
->modelist
))
681 err
= fb_add_videomode(&mode
, &info
->modelist
);
683 if (!err
&& info
->flags
& FBINFO_MISC_USEREVENT
) {
684 struct fb_event event
;
686 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
688 notifier_call_chain(&fb_notifier_list
,
689 FB_EVENT_MODE_CHANGE
,
698 fb_blank(struct fb_info
*info
, int blank
)
702 if (blank
> FB_BLANK_POWERDOWN
)
703 blank
= FB_BLANK_POWERDOWN
;
705 if (info
->fbops
->fb_blank
)
706 ret
= info
->fbops
->fb_blank(blank
, info
);
709 struct fb_event event
;
713 notifier_call_chain(&fb_notifier_list
, FB_EVENT_BLANK
, &event
);
720 fb_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
723 int fbidx
= iminor(inode
);
724 struct fb_info
*info
= registered_fb
[fbidx
];
725 struct fb_ops
*fb
= info
->fbops
;
726 struct fb_var_screeninfo var
;
727 struct fb_fix_screeninfo fix
;
728 struct fb_con2fbmap con2fb
;
729 struct fb_cmap_user cmap
;
730 struct fb_event event
;
731 void __user
*argp
= (void __user
*)arg
;
737 case FBIOGET_VSCREENINFO
:
738 return copy_to_user(argp
, &info
->var
,
739 sizeof(var
)) ? -EFAULT
: 0;
740 case FBIOPUT_VSCREENINFO
:
741 if (copy_from_user(&var
, argp
, sizeof(var
)))
743 acquire_console_sem();
744 info
->flags
|= FBINFO_MISC_USEREVENT
;
745 i
= fb_set_var(info
, &var
);
746 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
747 release_console_sem();
749 if (copy_to_user(argp
, &var
, sizeof(var
)))
752 case FBIOGET_FSCREENINFO
:
753 return copy_to_user(argp
, &info
->fix
,
754 sizeof(fix
)) ? -EFAULT
: 0;
756 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
758 return (fb_set_user_cmap(&cmap
, info
));
760 if (copy_from_user(&cmap
, argp
, sizeof(cmap
)))
762 return fb_cmap_to_user(&info
->cmap
, &cmap
);
763 case FBIOPAN_DISPLAY
:
764 if (copy_from_user(&var
, argp
, sizeof(var
)))
766 acquire_console_sem();
767 i
= fb_pan_display(info
, &var
);
768 release_console_sem();
771 if (copy_to_user(argp
, &var
, sizeof(var
)))
776 case FBIOGET_CON2FBMAP
:
777 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
779 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
781 con2fb
.framebuffer
= -1;
783 event
.data
= &con2fb
;
784 notifier_call_chain(&fb_notifier_list
,
785 FB_EVENT_GET_CONSOLE_MAP
, &event
);
786 return copy_to_user(argp
, &con2fb
,
787 sizeof(con2fb
)) ? -EFAULT
: 0;
788 case FBIOPUT_CON2FBMAP
:
789 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
791 if (con2fb
.console
< 0 || con2fb
.console
> MAX_NR_CONSOLES
)
793 if (con2fb
.framebuffer
< 0 || con2fb
.framebuffer
>= FB_MAX
)
796 if (!registered_fb
[con2fb
.framebuffer
])
797 try_to_load(con2fb
.framebuffer
);
798 #endif /* CONFIG_KMOD */
799 if (!registered_fb
[con2fb
.framebuffer
])
802 event
.data
= &con2fb
;
803 return notifier_call_chain(&fb_notifier_list
,
804 FB_EVENT_SET_CONSOLE_MAP
,
807 acquire_console_sem();
808 info
->flags
|= FBINFO_MISC_USEREVENT
;
809 i
= fb_blank(info
, arg
);
810 info
->flags
&= ~FBINFO_MISC_USEREVENT
;
811 release_console_sem();
814 if (fb
->fb_ioctl
== NULL
)
816 return fb
->fb_ioctl(inode
, file
, cmd
, arg
, info
);
822 fb_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
824 int fbidx
= iminor(file
->f_dentry
->d_inode
);
825 struct fb_info
*info
= registered_fb
[fbidx
];
826 struct fb_ops
*fb
= info
->fbops
;
829 if (fb
->fb_compat_ioctl
== NULL
)
832 ret
= fb
->fb_compat_ioctl(file
, cmd
, arg
, info
);
839 fb_mmap(struct file
*file
, struct vm_area_struct
* vma
)
841 int fbidx
= iminor(file
->f_dentry
->d_inode
);
842 struct fb_info
*info
= registered_fb
[fbidx
];
843 struct fb_ops
*fb
= info
->fbops
;
845 #if !defined(__sparc__) || defined(__sparc_v9__)
850 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
))
852 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
858 res
= fb
->fb_mmap(info
, file
, vma
);
863 #if defined(__sparc__) && !defined(__sparc_v9__)
864 /* Should never get here, all fb drivers should have their own
871 /* frame buffer memory */
872 start
= info
->fix
.smem_start
;
873 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.smem_len
);
875 /* memory mapped io */
877 if (info
->var
.accel_flags
) {
881 start
= info
->fix
.mmio_start
;
882 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + info
->fix
.mmio_len
);
886 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
889 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
890 /* This is an IO map - tell maydump to skip this VMA */
891 vma
->vm_flags
|= VM_IO
| VM_RESERVED
;
892 #if defined(__sparc_v9__)
893 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
894 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
897 #if defined(__mc68000__)
898 #if defined(CONFIG_SUN3)
899 pgprot_val(vma
->vm_page_prot
) |= SUN3_PAGE_NOCACHE
;
900 #elif defined(CONFIG_MMU)
901 if (CPU_IS_020_OR_030
)
902 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE030
;
903 if (CPU_IS_040_OR_060
) {
904 pgprot_val(vma
->vm_page_prot
) &= _CACHEMASK040
;
905 /* Use no-cache mode, serialized */
906 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NOCACHE_S
;
909 #elif defined(__powerpc__)
910 vma
->vm_page_prot
= phys_mem_access_prot(file
, off
,
911 vma
->vm_end
- vma
->vm_start
,
913 #elif defined(__alpha__)
914 /* Caching is off in the I/O space quadrant by design. */
915 #elif defined(__i386__) || defined(__x86_64__)
916 if (boot_cpu_data
.x86
> 3)
917 pgprot_val(vma
->vm_page_prot
) |= _PAGE_PCD
;
918 #elif defined(__mips__)
919 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
920 #elif defined(__hppa__)
921 pgprot_val(vma
->vm_page_prot
) |= _PAGE_NO_CACHE
;
922 #elif defined(__arm__) || defined(__sh__) || defined(__m32r__)
923 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
924 #elif defined(__ia64__)
925 if (efi_range_is_wc(vma
->vm_start
, vma
->vm_end
- vma
->vm_start
))
926 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
928 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
930 #warning What do we have to do here??
932 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
933 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
935 #endif /* !__sparc_v9__ */
937 #endif /* !sparc32 */
941 fb_open(struct inode
*inode
, struct file
*file
)
943 int fbidx
= iminor(inode
);
944 struct fb_info
*info
;
950 if (!(info
= registered_fb
[fbidx
]))
952 #endif /* CONFIG_KMOD */
953 if (!(info
= registered_fb
[fbidx
]))
955 if (!try_module_get(info
->fbops
->owner
))
957 if (info
->fbops
->fb_open
) {
958 res
= info
->fbops
->fb_open(info
,1);
960 module_put(info
->fbops
->owner
);
966 fb_release(struct inode
*inode
, struct file
*file
)
968 int fbidx
= iminor(inode
);
969 struct fb_info
*info
;
972 info
= registered_fb
[fbidx
];
973 if (info
->fbops
->fb_release
)
974 info
->fbops
->fb_release(info
,1);
975 module_put(info
->fbops
->owner
);
980 static struct file_operations fb_fops
= {
981 .owner
= THIS_MODULE
,
986 .compat_ioctl
= fb_compat_ioctl
,
990 .release
= fb_release
,
991 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
992 .get_unmapped_area
= get_fb_unmapped_area
,
996 static struct class *fb_class
;
999 * register_framebuffer - registers a frame buffer device
1000 * @fb_info: frame buffer info structure
1002 * Registers a frame buffer device @fb_info.
1004 * Returns negative errno on error, or zero for success.
1009 register_framebuffer(struct fb_info
*fb_info
)
1012 struct fb_event event
;
1014 if (num_registered_fb
== FB_MAX
)
1016 num_registered_fb
++;
1017 for (i
= 0 ; i
< FB_MAX
; i
++)
1018 if (!registered_fb
[i
])
1022 fb_info
->class_device
= class_device_create(fb_class
, MKDEV(FB_MAJOR
, i
),
1023 fb_info
->device
, "fb%d", i
);
1024 if (IS_ERR(fb_info
->class_device
)) {
1026 printk(KERN_WARNING
"Unable to create class_device for framebuffer %d; errno = %ld\n", i
, PTR_ERR(fb_info
->class_device
));
1027 fb_info
->class_device
= NULL
;
1029 fb_init_class_device(fb_info
);
1031 if (fb_info
->pixmap
.addr
== NULL
) {
1032 fb_info
->pixmap
.addr
= kmalloc(FBPIXMAPSIZE
, GFP_KERNEL
);
1033 if (fb_info
->pixmap
.addr
) {
1034 fb_info
->pixmap
.size
= FBPIXMAPSIZE
;
1035 fb_info
->pixmap
.buf_align
= 1;
1036 fb_info
->pixmap
.scan_align
= 1;
1037 fb_info
->pixmap
.access_align
= 32;
1038 fb_info
->pixmap
.flags
= FB_PIXMAP_DEFAULT
;
1041 fb_info
->pixmap
.offset
= 0;
1043 if (!fb_info
->modelist
.prev
||
1044 !fb_info
->modelist
.next
||
1045 list_empty(&fb_info
->modelist
)) {
1046 struct fb_videomode mode
;
1048 INIT_LIST_HEAD(&fb_info
->modelist
);
1049 fb_var_to_videomode(&mode
, &fb_info
->var
);
1050 fb_add_videomode(&mode
, &fb_info
->modelist
);
1053 registered_fb
[i
] = fb_info
;
1055 devfs_mk_cdev(MKDEV(FB_MAJOR
, i
),
1056 S_IFCHR
| S_IRUGO
| S_IWUGO
, "fb/%d", i
);
1057 event
.info
= fb_info
;
1058 notifier_call_chain(&fb_notifier_list
,
1059 FB_EVENT_FB_REGISTERED
, &event
);
1065 * unregister_framebuffer - releases a frame buffer device
1066 * @fb_info: frame buffer info structure
1068 * Unregisters a frame buffer device @fb_info.
1070 * Returns negative errno on error, or zero for success.
1075 unregister_framebuffer(struct fb_info
*fb_info
)
1080 if (!registered_fb
[i
])
1082 devfs_remove("fb/%d", i
);
1084 if (fb_info
->pixmap
.addr
&& (fb_info
->pixmap
.flags
& FB_PIXMAP_DEFAULT
))
1085 kfree(fb_info
->pixmap
.addr
);
1086 fb_destroy_modelist(&fb_info
->modelist
);
1087 registered_fb
[i
]=NULL
;
1088 num_registered_fb
--;
1089 fb_cleanup_class_device(fb_info
);
1090 class_device_destroy(fb_class
, MKDEV(FB_MAJOR
, i
));
1095 * fb_register_client - register a client notifier
1096 * @nb: notifier block to callback on events
1098 int fb_register_client(struct notifier_block
*nb
)
1100 return notifier_chain_register(&fb_notifier_list
, nb
);
1104 * fb_unregister_client - unregister a client notifier
1105 * @nb: notifier block to callback on events
1107 int fb_unregister_client(struct notifier_block
*nb
)
1109 return notifier_chain_unregister(&fb_notifier_list
, nb
);
1113 * fb_set_suspend - low level driver signals suspend
1114 * @info: framebuffer affected
1115 * @state: 0 = resuming, !=0 = suspending
1117 * This is meant to be used by low level drivers to
1118 * signal suspend/resume to the core & clients.
1119 * It must be called with the console semaphore held
1121 void fb_set_suspend(struct fb_info
*info
, int state
)
1123 struct fb_event event
;
1127 notifier_call_chain(&fb_notifier_list
, FB_EVENT_SUSPEND
, &event
);
1128 info
->state
= FBINFO_STATE_SUSPENDED
;
1130 info
->state
= FBINFO_STATE_RUNNING
;
1131 notifier_call_chain(&fb_notifier_list
, FB_EVENT_RESUME
, &event
);
1136 * fbmem_init - init frame buffer subsystem
1138 * Initialize the frame buffer subsystem.
1140 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1147 create_proc_read_entry("fb", 0, NULL
, fbmem_read_proc
, NULL
);
1150 if (register_chrdev(FB_MAJOR
,"fb",&fb_fops
))
1151 printk("unable to get major %d for fb devs\n", FB_MAJOR
);
1153 fb_class
= class_create(THIS_MODULE
, "graphics");
1154 if (IS_ERR(fb_class
)) {
1155 printk(KERN_WARNING
"Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class
));
1162 module_init(fbmem_init
);
1166 class_destroy(fb_class
);
1169 module_exit(fbmem_exit
);
1170 MODULE_LICENSE("GPL");
1171 MODULE_DESCRIPTION("Framebuffer base");
1173 subsys_initcall(fbmem_init
);
1176 int fb_new_modelist(struct fb_info
*info
)
1178 struct fb_event event
;
1179 struct fb_var_screeninfo var
= info
->var
;
1180 struct list_head
*pos
, *n
;
1181 struct fb_modelist
*modelist
;
1182 struct fb_videomode
*m
, mode
;
1185 list_for_each_safe(pos
, n
, &info
->modelist
) {
1186 modelist
= list_entry(pos
, struct fb_modelist
, list
);
1187 m
= &modelist
->mode
;
1188 fb_videomode_to_var(&var
, m
);
1189 var
.activate
= FB_ACTIVATE_TEST
;
1190 err
= fb_set_var(info
, &var
);
1191 fb_var_to_videomode(&mode
, &var
);
1192 if (err
|| !fb_mode_is_equal(m
, &mode
)) {
1200 if (!list_empty(&info
->modelist
)) {
1202 err
= notifier_call_chain(&fb_notifier_list
,
1203 FB_EVENT_NEW_MODELIST
,
1210 static char *video_options
[FB_MAX
];
1213 extern const char *global_mode_option
;
1216 * fb_get_options - get kernel boot parameters
1217 * @name: framebuffer name as it would appear in
1218 * the boot parameter line
1219 * (video=<name>:<options>)
1220 * @option: the option will be stored here
1222 * NOTE: Needed to maintain backwards compatibility
1224 int fb_get_options(char *name
, char **option
)
1226 char *opt
, *options
= NULL
;
1227 int opt_len
, retval
= 0;
1228 int name_len
= strlen(name
), i
;
1230 if (name_len
&& ofonly
&& strncmp(name
, "offb", 4))
1233 if (name_len
&& !retval
) {
1234 for (i
= 0; i
< FB_MAX
; i
++) {
1235 if (video_options
[i
] == NULL
)
1237 opt_len
= strlen(video_options
[i
]);
1240 opt
= video_options
[i
];
1241 if (!strncmp(name
, opt
, name_len
) &&
1242 opt
[name_len
] == ':')
1243 options
= opt
+ name_len
+ 1;
1246 if (options
&& !strncmp(options
, "off", 3))
1256 * video_setup - process command line options
1257 * @options: string of options
1259 * Process command line options for frame buffer subsystem.
1261 * NOTE: This function is a __setup and __init function.
1262 * It only stores the options. Drivers have to call
1263 * fb_get_options() as necessary.
1268 static int __init
video_setup(char *options
)
1272 if (!options
|| !*options
)
1275 if (!global
&& !strncmp(options
, "ofonly", 6)) {
1280 if (!global
&& !strstr(options
, "fb:")) {
1281 global_mode_option
= options
;
1286 for (i
= 0; i
< FB_MAX
; i
++) {
1287 if (video_options
[i
] == NULL
) {
1288 video_options
[i
] = options
;
1297 __setup("video=", video_setup
);
1300 * Visible symbols for modules
1303 EXPORT_SYMBOL(register_framebuffer
);
1304 EXPORT_SYMBOL(unregister_framebuffer
);
1305 EXPORT_SYMBOL(num_registered_fb
);
1306 EXPORT_SYMBOL(registered_fb
);
1307 EXPORT_SYMBOL(fb_prepare_logo
);
1308 EXPORT_SYMBOL(fb_show_logo
);
1309 EXPORT_SYMBOL(fb_set_var
);
1310 EXPORT_SYMBOL(fb_blank
);
1311 EXPORT_SYMBOL(fb_pan_display
);
1312 EXPORT_SYMBOL(fb_get_buffer_offset
);
1313 EXPORT_SYMBOL(fb_set_suspend
);
1314 EXPORT_SYMBOL(fb_register_client
);
1315 EXPORT_SYMBOL(fb_unregister_client
);
1316 EXPORT_SYMBOL(fb_get_options
);
1317 EXPORT_SYMBOL(fb_new_modelist
);
1319 MODULE_LICENSE("GPL");