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>
50 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
51 #include "console/fbcon.h"
54 * Frame buffer device initialization and setup routines
57 extern int acornfb_init(void);
58 extern int acornfb_setup(char*);
59 extern int amba_clcdfb_init(void);
60 extern int amifb_init(void);
61 extern int amifb_setup(char*);
62 extern int atafb_init(void);
63 extern int atafb_setup(char*);
64 extern int macfb_init(void);
65 extern int macfb_setup(char*);
66 extern int cyberfb_init(void);
67 extern int cyberfb_setup(char*);
68 extern int pm2fb_init(void);
69 extern int pm2fb_setup(char*);
70 extern int pm3fb_init(void);
71 extern int pm3fb_setup(char*);
72 extern int clps711xfb_init(void);
73 extern int cyber2000fb_init(void);
74 extern int cyber2000fb_setup(char*);
75 extern int retz3fb_init(void);
76 extern int retz3fb_setup(char*);
77 extern int cirrusfb_init(void);
78 extern int cirrusfb_setup(char*);
79 extern int hitfb_init(void);
80 extern int vfb_init(void);
81 extern int vfb_setup(char*);
82 extern int offb_init(void);
83 extern int atyfb_init(void);
84 extern int atyfb_setup(char*);
85 extern int aty128fb_init(void);
86 extern int aty128fb_setup(char*);
87 extern int neofb_init(void);
88 extern int neofb_setup(char*);
89 extern int igafb_init(void);
90 extern int igafb_setup(char*);
91 extern int imsttfb_init(void);
92 extern int imsttfb_setup(char*);
93 extern int dnfb_init(void);
94 extern int tgafb_init(void);
95 extern int tgafb_setup(char*);
96 extern int virgefb_init(void);
97 extern int virgefb_setup(char*);
98 extern int resolver_video_setup(char*);
99 extern int s3triofb_init(void);
100 extern int vesafb_init(void);
101 extern int vesafb_setup(char*);
102 extern int vga16fb_init(void);
103 extern int vga16fb_setup(char*);
104 extern int hgafb_init(void);
105 extern int hgafb_setup(char*);
106 extern int matroxfb_init(void);
107 extern int matroxfb_setup(char*);
108 extern int hpfb_init(void);
109 extern int platinumfb_init(void);
110 extern int platinumfb_setup(char*);
111 extern int control_init(void);
112 extern int control_setup(char*);
113 extern int valkyriefb_init(void);
114 extern int valkyriefb_setup(char*);
115 extern int chips_init(void);
116 extern int g364fb_init(void);
117 extern int sa1100fb_init(void);
118 extern int pxafb_init(void);
119 extern int pxafb_setup(char*);
120 extern int fm2fb_init(void);
121 extern int fm2fb_setup(char*);
122 extern int q40fb_init(void);
123 extern int sun3fb_init(void);
124 extern int sun3fb_setup(char *);
125 extern int sgivwfb_init(void);
126 extern int sgivwfb_setup(char*);
127 extern int gbefb_init(void);
128 extern int gbefb_setup(char*);
129 extern int rivafb_init(void);
130 extern int rivafb_setup(char*);
131 extern int tdfxfb_init(void);
132 extern int tdfxfb_setup(char*);
133 extern int tridentfb_init(void);
134 extern int tridentfb_setup(char*);
135 extern int sisfb_init(void);
136 extern int sisfb_setup(char*);
137 extern int stifb_init(void);
138 extern int stifb_setup(char*);
139 extern int pmagbafb_init(void);
140 extern int pmagbbfb_init(void);
141 extern int maxinefb_init(void);
142 extern int tx3912fb_init(void);
143 extern int tx3912fb_setup(char*);
144 extern int radeonfb_init(void);
145 extern int radeonfb_setup(char*);
146 extern int radeonfb_old_init(void);
147 extern int radeonfb_old_setup(char*);
148 extern int e1355fb_init(void);
149 extern int e1355fb_setup(char*);
150 extern int pvr2fb_init(void);
151 extern int pvr2fb_setup(char*);
152 extern int sstfb_init(void);
153 extern int sstfb_setup(char*);
154 extern int i810fb_init(void);
155 extern int i810fb_setup(char*);
156 extern int ffb_init(void);
157 extern int ffb_setup(char*);
158 extern int cg6_init(void);
159 extern int cg6_setup(char*);
160 extern int cg3_init(void);
161 extern int cg3_setup(char*);
162 extern int bw2_init(void);
163 extern int bw2_setup(char*);
164 extern int cg14_init(void);
165 extern int cg14_setup(char*);
166 extern int p9100_init(void);
167 extern int p9100_setup(char*);
168 extern int tcx_init(void);
169 extern int tcx_setup(char*);
170 extern int leo_init(void);
171 extern int leo_setup(char*);
172 extern int kyrofb_init(void);
173 extern int kyrofb_setup(char*);
174 extern int mc68x328fb_init(void);
175 extern int mc68x328fb_setup(char *);
176 extern int asiliantfb_init(void);
182 } fb_drivers[] __initdata = {
185 * Chipset specific drivers that use resource management
187 #ifdef CONFIG_FB_RETINAZ3
188 { "retz3fb", retz3fb_init, retz3fb_setup },
190 #ifdef CONFIG_FB_AMIGA
191 { "amifb", amifb_init, amifb_setup },
193 #ifdef CONFIG_FB_CLPS711X
194 { "clps711xfb", clps711xfb_init, NULL },
196 #ifdef CONFIG_FB_CYBER
197 { "cyberfb", cyberfb_init, cyberfb_setup },
199 #ifdef CONFIG_FB_CYBER2000
200 { "cyber2000fb", cyber2000fb_init, cyber2000fb_setup },
202 #ifdef CONFIG_FB_ARMCLCD
203 { "ambaclcdfb", amba_clcdfb_init, NULL },
206 { "pm2fb", pm2fb_init, pm2fb_setup },
209 { "pm3fb", pm3fb_init, pm3fb_setup },
211 #ifdef CONFIG_FB_CIRRUS
212 { "cirrusfb", cirrusfb_init, cirrusfb_setup },
215 { "atyfb", atyfb_init, atyfb_setup },
217 #ifdef CONFIG_FB_MATROX
218 { "matroxfb", matroxfb_init, matroxfb_setup },
220 #ifdef CONFIG_FB_ATY128
221 { "aty128fb", aty128fb_init, aty128fb_setup },
223 #ifdef CONFIG_FB_NEOMAGIC
224 { "neofb", neofb_init, neofb_setup },
226 #ifdef CONFIG_FB_VIRGE
227 { "virgefb", virgefb_init, virgefb_setup },
229 #ifdef CONFIG_FB_RIVA
230 { "rivafb", rivafb_init, rivafb_setup },
232 #ifdef CONFIG_FB_3DFX
233 { "tdfxfb", tdfxfb_init, tdfxfb_setup },
235 #ifdef CONFIG_FB_RADEON
236 { "radeonfb", radeonfb_init, radeonfb_setup },
238 #ifdef CONFIG_FB_RADEON_OLD
239 { "radeonfb_old", radeonfb_old_init, radeonfb_old_setup },
241 #ifdef CONFIG_FB_CONTROL
242 { "controlfb", control_init, control_setup },
244 #ifdef CONFIG_FB_PLATINUM
245 { "platinumfb", platinumfb_init, platinumfb_setup },
247 #ifdef CONFIG_FB_VALKYRIE
248 { "valkyriefb", valkyriefb_init, valkyriefb_setup },
250 #ifdef CONFIG_FB_CT65550
251 { "chipsfb", chips_init, NULL },
253 #ifdef CONFIG_FB_IMSTT
254 { "imsttfb", imsttfb_init, imsttfb_setup },
256 #ifdef CONFIG_FB_S3TRIO
257 { "s3triofb", s3triofb_init, NULL },
260 { "fm2fb", fm2fb_init, fm2fb_setup },
263 { "sisfb", sisfb_init, sisfb_setup },
265 #ifdef CONFIG_FB_TRIDENT
266 { "tridentfb", tridentfb_init, tridentfb_setup },
268 #ifdef CONFIG_FB_I810
269 { "i810fb", i810fb_init, i810fb_setup },
272 { "stifb", stifb_init, stifb_setup },
275 { "ffb", ffb_init, ffb_setup },
278 { "cg6fb", cg6_init, cg6_setup },
281 { "cg3fb", cg3_init, cg3_setup },
284 { "bw2fb", bw2_init, bw2_setup },
286 #ifdef CONFIG_FB_CG14
287 { "cg14fb", cg14_init, cg14_setup },
289 #ifdef CONFIG_FB_P9100
290 { "p9100fb", p9100_init, p9100_setup },
293 { "tcxfb", tcx_init, tcx_setup },
296 { "leofb", leo_init, leo_setup },
300 * Generic drivers that are used as fallbacks
302 * These depend on resource management and must be initialized
303 * _after_ all other frame buffer devices that use resource
308 { "offb", offb_init, NULL },
310 #ifdef CONFIG_FB_VESA
311 { "vesafb", vesafb_init, vesafb_setup },
315 * Chipset specific drivers that don't use resource management (yet)
318 #ifdef CONFIG_FB_SGIVW
319 { "sgivwfb", sgivwfb_init, sgivwfb_setup },
322 { "gbefb", gbefb_init, gbefb_setup },
324 #ifdef CONFIG_FB_ACORN
325 { "acornfb", acornfb_init, acornfb_setup },
327 #ifdef CONFIG_FB_ATARI
328 { "atafb", atafb_init, atafb_setup },
331 { "macfb", macfb_init, macfb_setup },
334 { "hgafb", hgafb_init, hgafb_setup },
337 { "igafb", igafb_init, igafb_setup },
340 { "apollofb", dnfb_init, NULL },
343 { "q40fb", q40fb_init, NULL },
346 { "tgafb", tgafb_init, tgafb_setup },
348 #ifdef CONFIG_FB_HP300
349 { "hpfb", hpfb_init, NULL },
351 #ifdef CONFIG_FB_G364
352 { "g364fb", g364fb_init, NULL },
354 #ifdef CONFIG_FB_SA1100
355 { "sa1100fb", sa1100fb_init, NULL },
358 { "pxafb", pxafb_init, pxafb_setup },
360 #ifdef CONFIG_FB_SUN3
361 { "sun3fb", sun3fb_init, sun3fb_setup },
364 { "hitfb", hitfb_init, NULL },
366 #ifdef CONFIG_FB_TX3912
367 { "tx3912fb", tx3912fb_init, tx3912fb_setup },
369 #ifdef CONFIG_FB_E1355
370 { "e1355fb", e1355fb_init, e1355fb_setup },
372 #ifdef CONFIG_FB_PVR2
373 { "pvr2fb", pvr2fb_init, pvr2fb_setup },
375 #ifdef CONFIG_FB_PMAG_BA
376 { "pmagbafb", pmagbafb_init, NULL },
378 #ifdef CONFIG_FB_PMAGB_B
379 { "pmagbbfb", pmagbbfb_init, NULL },
381 #ifdef CONFIG_FB_MAXINE
382 { "maxinefb", maxinefb_init, NULL },
384 #ifdef CONFIG_FB_VOODOO1
385 { "sstfb", sstfb_init, sstfb_setup },
387 #ifdef CONFIG_FB_KYRO
388 { "kyrofb", kyrofb_init, kyrofb_setup },
390 #ifdef CONFIG_FB_68328
391 { "68328fb", mc68x328fb_init, mc68x328fb_setup },
393 #ifdef CONFIG_FB_ASILIANT
394 { "asiliantfb", asiliantfb_init, NULL },
398 * Generic drivers that don't use resource management (yet)
401 #ifdef CONFIG_FB_VGA16
402 { "vga16fb", vga16fb_init, vga16fb_setup },
405 #ifdef CONFIG_GSP_RESOLVER
406 /* Not a real frame buffer device... */
407 { "resolverfb", NULL, resolver_video_setup },
410 #ifdef CONFIG_FB_VIRTUAL
412 * Vfb must be last to avoid that it becomes your primary display if
413 * other display devices are present
415 { "vfb", vfb_init, vfb_setup },
419 #define NUM_FB_DRIVERS (sizeof(fb_drivers)/sizeof(*fb_drivers))
420 #define FBPIXMAPSIZE 16384
422 extern const char *global_mode_option;
424 static initcall_t pref_init_funcs[FB_MAX];
425 static int num_pref_init_funcs __initdata = 0;
426 static struct notifier_block *fb_notifier_list;
427 struct fb_info *registered_fb[FB_MAX];
428 int num_registered_fb;
431 static int ofonly __initdata = 0;
438 int fb_get_color_depth(struct fb_info *info)
440 struct fb_var_screeninfo *var = &info->var;
442 if (var->green.length == var->blue.length &&
443 var->green.length == var->red.length &&
444 !var->green.offset && !var->blue.offset &&
446 return var->green.length;
448 return (var->green.length + var->red.length +
451 EXPORT_SYMBOL(fb_get_color_depth);
456 void fb_iomove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
457 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
462 for (i = height; i--; ) {
463 buf->outbuf(info, dst, src, s_pitch);
469 void fb_sysmove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
470 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
475 for (i = height; i--; ) {
476 for (j = 0; j < s_pitch; j++)
483 void fb_iomove_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf,
484 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
485 u32 height, u32 shift_high, u32 shift_low,
488 u8 mask = (u8) (0xfff << shift_high), tmp;
491 for (i = height; i--; ) {
492 for (j = 0; j < idx; j++) {
493 tmp = buf->inbuf(info, dst+j);
495 tmp |= *src >> shift_low;
496 buf->outbuf(info, dst+j, &tmp, 1);
497 tmp = *src << shift_high;
498 buf->outbuf(info, dst+j+1, &tmp, 1);
501 tmp = buf->inbuf(info, dst+idx);
503 tmp |= *src >> shift_low;
504 buf->outbuf(info, dst+idx, &tmp, 1);
505 if (shift_high < mod) {
506 tmp = *src << shift_high;
507 buf->outbuf(info, dst+idx+1, &tmp, 1);
514 void fb_sysmove_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf,
515 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
516 u32 height, u32 shift_high, u32 shift_low,
519 u8 mask = (u8) (0xfff << shift_high), tmp;
522 for (i = height; i--; ) {
523 for (j = 0; j < idx; j++) {
526 tmp |= *src >> shift_low;
528 tmp = *src << shift_high;
534 tmp |= *src >> shift_low;
536 if (shift_high < mod) {
537 tmp = *src << shift_high;
546 * we need to lock this section since fb_cursor
547 * may use fb_imageblit()
549 char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size)
551 u32 align = buf->buf_align - 1, offset;
552 char *addr = buf->addr;
554 /* If IO mapped, we need to sync before access, no sharing of
557 if (buf->flags & FB_PIXMAP_IO) {
558 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
559 info->fbops->fb_sync(info);
563 /* See if we fit in the remaining pixmap space */
564 offset = buf->offset + align;
566 if (offset + size > buf->size) {
567 /* We do not fit. In order to be able to re-use the buffer,
568 * we must ensure no asynchronous DMA'ing or whatever operation
569 * is in progress, we sync for that.
571 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
572 info->fbops->fb_sync(info);
575 buf->offset = offset + size;
582 #include <linux/linux_logo.h>
584 static inline unsigned safe_shift(unsigned d, int n)
586 return n < 0 ? d >> -n : d << n;
589 static void fb_set_logocmap(struct fb_info *info,
590 const struct linux_logo *logo)
592 struct fb_cmap palette_cmap;
593 u16 palette_green[16];
594 u16 palette_blue[16];
597 const unsigned char *clut = logo->clut;
599 palette_cmap.start = 0;
600 palette_cmap.len = 16;
601 palette_cmap.red = palette_red;
602 palette_cmap.green = palette_green;
603 palette_cmap.blue = palette_blue;
604 palette_cmap.transp = NULL;
606 for (i = 0; i < logo->clutsize; i += n) {
607 n = logo->clutsize - i;
608 /* palette_cmap provides space for only 16 colors at once */
611 palette_cmap.start = 32 + i;
612 palette_cmap.len = n;
613 for (j = 0; j < n; ++j) {
614 palette_cmap.red[j] = clut[0] << 8 | clut[0];
615 palette_cmap.green[j] = clut[1] << 8 | clut[1];
616 palette_cmap.blue[j] = clut[2] << 8 | clut[2];
619 fb_set_cmap(&palette_cmap, info);
623 static void fb_set_logo_truepalette(struct fb_info *info,
624 const struct linux_logo *logo,
627 unsigned char mask[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
628 unsigned char redmask, greenmask, bluemask;
629 int redshift, greenshift, blueshift;
631 const unsigned char *clut = logo->clut;
634 * We have to create a temporary palette since console palette is only
637 /* Bug: Doesn't obey msb_right ... (who needs that?) */
638 redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8];
639 greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8];
640 bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8];
641 redshift = info->var.red.offset - (8 - info->var.red.length);
642 greenshift = info->var.green.offset - (8 - info->var.green.length);
643 blueshift = info->var.blue.offset - (8 - info->var.blue.length);
645 for ( i = 0; i < logo->clutsize; i++) {
646 palette[i+32] = (safe_shift((clut[0] & redmask), redshift) |
647 safe_shift((clut[1] & greenmask), greenshift) |
648 safe_shift((clut[2] & bluemask), blueshift));
653 static void fb_set_logo_directpalette(struct fb_info *info,
654 const struct linux_logo *logo,
657 int redshift, greenshift, blueshift;
660 redshift = info->var.red.offset;
661 greenshift = info->var.green.offset;
662 blueshift = info->var.blue.offset;
664 for (i = 32; i < logo->clutsize; i++)
665 palette[i] = i << redshift | i << greenshift | i << blueshift;
668 static void fb_set_logo(struct fb_info *info,
669 const struct linux_logo *logo, u8 *dst,
673 const u8 *src = logo->data;
674 u8 d, xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0;
676 if (fb_get_color_depth(info) == 3)
681 for (i = 0; i < logo->height; i++)
682 for (j = 0; j < logo->width; src++) {
685 if (j < logo->width) {
686 *dst++ = *src & 0x0f;
692 for (i = 0; i < logo->height; i++) {
693 for (j = 0; j < logo->width; src++) {
695 for (k = 7; k >= 0; k--) {
696 *dst++ = ((d >> k) & 1) ? fg : 0;
706 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
707 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
708 * the visual format and color depth of the framebuffer, the DAC, the
709 * pseudo_palette, and the logo data will be adjusted accordingly.
711 * Case 1 - linux_logo_clut224:
712 * Color exceeds the number of console colors (16), thus we set the hardware DAC
713 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
715 * For visuals that require color info from the pseudo_palette, we also construct
716 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
719 * Case 2 - linux_logo_vga16:
720 * The number of colors just matches the console colors, thus there is no need
721 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
722 * each byte contains color information for two pixels (upper and lower nibble).
723 * To be consistent with fb_imageblit() usage, we therefore separate the two
724 * nibbles into separate bytes. The "depth" flag will be set to 4.
726 * Case 3 - linux_logo_mono:
727 * This is similar with Case 2. Each byte contains information for 8 pixels.
728 * We isolate each bit and expand each into a byte. The "depth" flag will
731 static struct logo_data {
733 int needs_directpalette;
734 int needs_truepalette;
736 const struct linux_logo *logo;
739 int fb_prepare_logo(struct fb_info *info)
741 int depth = fb_get_color_depth(info);
743 memset(&fb_logo, 0, sizeof(struct logo_data));
745 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
746 depth = info->var.blue.length;
747 if (info->var.red.length < depth)
748 depth = info->var.red.length;
749 if (info->var.green.length < depth)
750 depth = info->var.green.length;
754 switch (info->fix.visual) {
755 case FB_VISUAL_TRUECOLOR:
756 fb_logo.needs_truepalette = 1;
758 case FB_VISUAL_DIRECTCOLOR:
759 fb_logo.needs_directpalette = 1;
760 fb_logo.needs_cmapreset = 1;
762 case FB_VISUAL_PSEUDOCOLOR:
763 fb_logo.needs_cmapreset = 1;
768 /* Return if no suitable logo was found */
769 fb_logo.logo = fb_find_logo(depth);
771 if (!fb_logo.logo || fb_logo.logo->height > info->var.yres) {
775 /* What depth we asked for might be different from what we get */
776 if (fb_logo.logo->type == LINUX_LOGO_CLUT224)
778 else if (fb_logo.logo->type == LINUX_LOGO_VGA16)
782 return fb_logo.logo->height;
785 int fb_show_logo(struct fb_info *info)
787 u32 *palette = NULL, *saved_pseudo_palette = NULL;
788 unsigned char *logo_new = NULL;
789 struct fb_image image;
792 /* Return if the frame buffer is not mapped or suspended */
793 if (fb_logo.logo == NULL || info->state != FBINFO_STATE_RUNNING)
797 image.data = fb_logo.logo->data;
799 if (fb_logo.needs_cmapreset)
800 fb_set_logocmap(info, fb_logo.logo);
802 if (fb_logo.needs_truepalette ||
803 fb_logo.needs_directpalette) {
804 palette = kmalloc(256 * 4, GFP_KERNEL);
808 if (fb_logo.needs_truepalette)
809 fb_set_logo_truepalette(info, fb_logo.logo, palette);
811 fb_set_logo_directpalette(info, fb_logo.logo, palette);
813 saved_pseudo_palette = info->pseudo_palette;
814 info->pseudo_palette = palette;
817 if (fb_logo.depth <= 4) {
818 logo_new = kmalloc(fb_logo.logo->width * fb_logo.logo->height,
820 if (logo_new == NULL) {
823 if (saved_pseudo_palette)
824 info->pseudo_palette = saved_pseudo_palette;
827 image.data = logo_new;
828 fb_set_logo(info, fb_logo.logo, logo_new, fb_logo.depth);
831 image.width = fb_logo.logo->width;
832 image.height = fb_logo.logo->height;
835 for (x = 0; x < num_online_cpus() * (fb_logo.logo->width + 8) &&
836 x <= info->var.xres-fb_logo.logo->width; x += (fb_logo.logo->width + 8)) {
838 info->fbops->fb_imageblit(info, &image);
843 if (saved_pseudo_palette != NULL)
844 info->pseudo_palette = saved_pseudo_palette;
845 if (logo_new != NULL)
847 return fb_logo.logo->height;
850 int fb_prepare_logo(struct fb_info *info) { return 0; }
851 int fb_show_logo(struct fb_info *info) { return 0; }
852 #endif /* CONFIG_LOGO */
854 static int fbmem_read_proc(char *buf, char **start, off_t offset,
855 int len, int *eof, void *private)
861 for (fi = registered_fb; fi < ®istered_fb[FB_MAX] && len < 4000; fi++)
863 clen += sprintf(buf + clen, "%d %s\n",
866 *start = buf + offset;
871 return clen < len ? clen : len;
875 fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
877 unsigned long p = *ppos;
878 struct inode *inode = file->f_dentry->d_inode;
879 int fbidx = iminor(inode);
880 struct fb_info *info = registered_fb[fbidx];
882 if (!info || ! info->screen_base)
885 if (info->state != FBINFO_STATE_RUNNING)
888 if (info->fbops->fb_read)
889 return info->fbops->fb_read(file, buf, count, ppos);
891 if (p >= info->fix.smem_len)
893 if (count >= info->fix.smem_len)
894 count = info->fix.smem_len;
895 if (count + p > info->fix.smem_len)
896 count = info->fix.smem_len - p;
897 if (info->fbops->fb_sync)
898 info->fbops->fb_sync(info);
902 base_addr = info->screen_base;
903 count -= copy_to_user(buf, base_addr+p, count);
912 fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
914 unsigned long p = *ppos;
915 struct inode *inode = file->f_dentry->d_inode;
916 int fbidx = iminor(inode);
917 struct fb_info *info = registered_fb[fbidx];
920 if (!info || !info->screen_base)
923 if (info->state != FBINFO_STATE_RUNNING)
926 if (info->fbops->fb_write)
927 return info->fbops->fb_write(file, buf, count, ppos);
929 if (p > info->fix.smem_len)
931 if (count >= info->fix.smem_len)
932 count = info->fix.smem_len;
934 if (count + p > info->fix.smem_len) {
935 count = info->fix.smem_len - p;
938 if (info->fbops->fb_sync)
939 info->fbops->fb_sync(info);
943 base_addr = info->screen_base;
944 count -= copy_from_user(base_addr+p, buf, count);
954 static void try_to_load(int fb)
956 request_module("fb%d", fb);
958 #endif /* CONFIG_KMOD */
961 fb_load_cursor_image(struct fb_info *info)
963 unsigned int width = (info->cursor.image.width + 7) >> 3;
964 u8 *data = (u8 *) info->cursor.image.data;
966 if (info->sprite.outbuf)
967 info->sprite.outbuf(info, info->sprite.addr, data, width);
969 memcpy(info->sprite.addr, data, width);
973 fb_cursor(struct fb_info *info, struct fb_cursor_user __user *sprite)
975 struct fb_cursor_user cursor_user;
976 struct fb_cursor cursor;
977 char *data = NULL, *mask = NULL;
978 u16 *red = NULL, *green = NULL, *blue = NULL, *transp = NULL;
981 if (copy_from_user(&cursor_user, sprite, sizeof(struct fb_cursor_user)))
984 memcpy(&cursor, &cursor_user, sizeof(cursor_user));
986 cursor.image.data = NULL;
987 cursor.image.cmap.red = NULL;
988 cursor.image.cmap.green = NULL;
989 cursor.image.cmap.blue = NULL;
990 cursor.image.cmap.transp = NULL;
993 if (cursor.set & FB_CUR_SETCUR)
994 info->cursor.enable = 1;
996 if (cursor.set & FB_CUR_SETCMAP) {
997 unsigned len = cursor.image.cmap.len;
1002 red = kmalloc(len, GFP_USER);
1003 green = kmalloc(len, GFP_USER);
1004 blue = kmalloc(len, GFP_USER);
1005 if (!red || !green || !blue)
1007 if (cursor_user.image.cmap.transp) {
1008 transp = kmalloc(len, GFP_USER);
1013 if (copy_from_user(red, cursor_user.image.cmap.red, len))
1015 if (copy_from_user(green, cursor_user.image.cmap.green, len))
1017 if (copy_from_user(blue, cursor_user.image.cmap.blue, len))
1020 if (copy_from_user(transp,
1021 cursor_user.image.cmap.transp, len))
1024 cursor.image.cmap.red = red;
1025 cursor.image.cmap.green = green;
1026 cursor.image.cmap.blue = blue;
1027 cursor.image.cmap.transp = transp;
1030 if (cursor.set & FB_CUR_SETSHAPE) {
1031 int size = ((cursor.image.width + 7) >> 3) * cursor.image.height;
1033 if ((cursor.image.height != info->cursor.image.height) ||
1034 (cursor.image.width != info->cursor.image.width))
1035 cursor.set |= FB_CUR_SETSIZE;
1038 data = kmalloc(size, GFP_USER);
1039 mask = kmalloc(size, GFP_USER);
1044 if (copy_from_user(data, cursor_user.image.data, size) ||
1045 copy_from_user(mask, cursor_user.mask, size))
1048 cursor.image.data = data;
1051 info->cursor.set = cursor.set;
1052 info->cursor.rop = cursor.rop;
1053 err = info->fbops->fb_cursor(info, &cursor);
1065 fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
1067 int xoffset = var->xoffset;
1068 int yoffset = var->yoffset;
1071 if (xoffset < 0 || yoffset < 0 || !info->fbops->fb_pan_display ||
1072 xoffset + info->var.xres > info->var.xres_virtual ||
1073 yoffset + info->var.yres > info->var.yres_virtual)
1075 if ((err = info->fbops->fb_pan_display(var, info)))
1077 info->var.xoffset = var->xoffset;
1078 info->var.yoffset = var->yoffset;
1079 if (var->vmode & FB_VMODE_YWRAP)
1080 info->var.vmode |= FB_VMODE_YWRAP;
1082 info->var.vmode &= ~FB_VMODE_YWRAP;
1087 fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
1091 if (var->activate & FB_ACTIVATE_INV_MODE) {
1092 struct fb_videomode mode1, mode2;
1095 fb_var_to_videomode(&mode1, var);
1096 fb_var_to_videomode(&mode2, &info->var);
1097 /* make sure we don't delete the videomode of current var */
1098 ret = fb_mode_is_equal(&mode1, &mode2);
1101 struct fb_event event;
1104 event.data = &mode1;
1105 ret = notifier_call_chain(&fb_notifier_list,
1106 FB_EVENT_MODE_DELETE, &event);
1110 fb_delete_videomode(&mode1, &info->monspecs.modelist);
1115 if ((var->activate & FB_ACTIVATE_FORCE) ||
1116 memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
1117 if (!info->fbops->fb_check_var) {
1122 if ((err = info->fbops->fb_check_var(var, info)))
1125 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
1126 struct fb_videomode mode;
1129 if (info->fbops->fb_set_par)
1130 info->fbops->fb_set_par(info);
1132 fb_pan_display(info, &info->var);
1134 fb_set_cmap(&info->cmap, info);
1136 fb_var_to_videomode(&mode, &info->var);
1137 fb_add_videomode(&mode, &info->monspecs.modelist);
1139 if (info->flags & FBINFO_MISC_MODECHANGEUSER) {
1140 struct fb_event event;
1142 info->flags &= ~FBINFO_MISC_MODECHANGEUSER;
1144 notifier_call_chain(&fb_notifier_list,
1145 FB_EVENT_MODE_CHANGE, &event);
1153 fb_blank(struct fb_info *info, int blank)
1155 /* ??? Variable sized stack allocation. */
1156 u16 black[info->cmap.len];
1157 struct fb_cmap cmap;
1159 if (info->fbops->fb_blank && !info->fbops->fb_blank(blank, info))
1162 memset(black, 0, info->cmap.len * sizeof(u16));
1163 cmap.red = cmap.green = cmap.blue = black;
1164 cmap.transp = info->cmap.transp ? black : NULL;
1165 cmap.start = info->cmap.start;
1166 cmap.len = info->cmap.len;
1169 return fb_set_cmap(&cmap, info);
1173 fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1176 int fbidx = iminor(inode);
1177 struct fb_info *info = registered_fb[fbidx];
1178 struct fb_ops *fb = info->fbops;
1179 struct fb_var_screeninfo var;
1180 struct fb_fix_screeninfo fix;
1181 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
1182 struct fb_con2fbmap con2fb;
1184 struct fb_cmap_user cmap;
1185 void __user *argp = (void __user *)arg;
1191 case FBIOGET_VSCREENINFO:
1192 return copy_to_user(argp, &info->var,
1193 sizeof(var)) ? -EFAULT : 0;
1194 case FBIOPUT_VSCREENINFO:
1195 if (copy_from_user(&var, argp, sizeof(var)))
1197 acquire_console_sem();
1198 info->flags |= FBINFO_MISC_MODECHANGEUSER;
1199 i = fb_set_var(info, &var);
1200 info->flags &= ~FBINFO_MISC_MODECHANGEUSER;
1201 release_console_sem();
1203 if (copy_to_user(argp, &var, sizeof(var)))
1206 case FBIOGET_FSCREENINFO:
1207 return copy_to_user(argp, &info->fix,
1208 sizeof(fix)) ? -EFAULT : 0;
1210 if (copy_from_user(&cmap, argp, sizeof(cmap)))
1212 return (fb_set_user_cmap(&cmap, info));
1214 if (copy_from_user(&cmap, argp, sizeof(cmap)))
1216 return fb_cmap_to_user(&info->cmap, &cmap);
1217 case FBIOPAN_DISPLAY:
1218 if (copy_from_user(&var, argp, sizeof(var)))
1220 acquire_console_sem();
1221 i = fb_pan_display(info, &var);
1222 release_console_sem();
1225 if (copy_to_user(argp, &var, sizeof(var)))
1229 acquire_console_sem();
1230 i = fb_cursor(info, argp);
1231 release_console_sem();
1233 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
1234 case FBIOGET_CON2FBMAP:
1235 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
1237 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
1239 con2fb.framebuffer = con2fb_map[con2fb.console-1];
1240 return copy_to_user(argp, &con2fb,
1241 sizeof(con2fb)) ? -EFAULT : 0;
1242 case FBIOPUT_CON2FBMAP:
1243 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
1245 if (con2fb.console < 0 || con2fb.console > MAX_NR_CONSOLES)
1247 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
1250 if (!registered_fb[con2fb.framebuffer])
1251 try_to_load(con2fb.framebuffer);
1252 #endif /* CONFIG_KMOD */
1253 if (!registered_fb[con2fb.framebuffer])
1255 if (con2fb.console > 0 && con2fb.console < MAX_NR_CONSOLES)
1256 return set_con2fb_map(con2fb.console-1,
1257 con2fb.framebuffer);
1259 #endif /* CONFIG_FRAMEBUFFER_CONSOLE */
1261 acquire_console_sem();
1262 i = fb_blank(info, arg);
1263 release_console_sem();
1266 if (fb->fb_ioctl == NULL)
1268 return fb->fb_ioctl(inode, file, cmd, arg, info);
1273 fb_mmap(struct file *file, struct vm_area_struct * vma)
1275 int fbidx = iminor(file->f_dentry->d_inode);
1276 struct fb_info *info = registered_fb[fbidx];
1277 struct fb_ops *fb = info->fbops;
1279 #if !defined(__sparc__) || defined(__sparc_v9__)
1280 unsigned long start;
1284 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1286 off = vma->vm_pgoff << PAGE_SHIFT;
1292 res = fb->fb_mmap(info, file, vma);
1297 #if defined(__sparc__) && !defined(__sparc_v9__)
1298 /* Should never get here, all fb drivers should have their own
1305 /* frame buffer memory */
1306 start = info->fix.smem_start;
1307 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
1309 /* memory mapped io */
1311 if (info->var.accel_flags) {
1315 start = info->fix.mmio_start;
1316 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
1320 if ((vma->vm_end - vma->vm_start + off) > len)
1323 vma->vm_pgoff = off >> PAGE_SHIFT;
1324 /* This is an IO map - tell maydump to skip this VMA */
1325 vma->vm_flags |= VM_IO;
1326 #if defined(__sparc_v9__)
1327 vma->vm_flags |= (VM_SHM | VM_LOCKED);
1328 if (io_remap_page_range(vma, vma->vm_start, off,
1329 vma->vm_end - vma->vm_start, vma->vm_page_prot, 0))
1332 #if defined(__mc68000__)
1333 #if defined(CONFIG_SUN3)
1334 pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
1335 #elif defined(CONFIG_MMU)
1336 if (CPU_IS_020_OR_030)
1337 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
1338 if (CPU_IS_040_OR_060) {
1339 pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
1340 /* Use no-cache mode, serialized */
1341 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
1344 #elif defined(__powerpc__)
1345 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
1346 #elif defined(__alpha__)
1347 /* Caching is off in the I/O space quadrant by design. */
1348 #elif defined(__i386__) || defined(__x86_64__)
1349 if (boot_cpu_data.x86 > 3)
1350 pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
1351 #elif defined(__mips__)
1352 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1353 #elif defined(__hppa__)
1354 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
1355 #elif defined(__ia64__) || defined(__arm__) || defined(__sh__)
1356 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1358 #warning What do we have to do here??
1360 if (io_remap_page_range(vma, vma->vm_start, off,
1361 vma->vm_end - vma->vm_start, vma->vm_page_prot))
1363 #endif /* !__sparc_v9__ */
1365 #endif /* !sparc32 */
1369 fb_open(struct inode *inode, struct file *file)
1371 int fbidx = iminor(inode);
1372 struct fb_info *info;
1375 if (fbidx >= FB_MAX)
1378 if (!(info = registered_fb[fbidx]))
1380 #endif /* CONFIG_KMOD */
1381 if (!(info = registered_fb[fbidx]))
1383 if (!try_module_get(info->fbops->owner))
1385 if (info->fbops->fb_open) {
1386 res = info->fbops->fb_open(info,1);
1388 module_put(info->fbops->owner);
1394 fb_release(struct inode *inode, struct file *file)
1396 int fbidx = iminor(inode);
1397 struct fb_info *info;
1400 info = registered_fb[fbidx];
1401 if (info->fbops->fb_release)
1402 info->fbops->fb_release(info,1);
1403 module_put(info->fbops->owner);
1408 static struct file_operations fb_fops = {
1409 .owner = THIS_MODULE,
1415 .release = fb_release,
1416 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1417 .get_unmapped_area = get_fb_unmapped_area,
1421 static struct class_simple *fb_class;
1424 * register_framebuffer - registers a frame buffer device
1425 * @fb_info: frame buffer info structure
1427 * Registers a frame buffer device @fb_info.
1429 * Returns negative errno on error, or zero for success.
1434 register_framebuffer(struct fb_info *fb_info)
1437 struct class_device *c;
1439 if (num_registered_fb == FB_MAX)
1441 num_registered_fb++;
1442 for (i = 0 ; i < FB_MAX; i++)
1443 if (!registered_fb[i])
1447 c = class_simple_device_add(fb_class, MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
1450 printk(KERN_WARNING "Unable to create class_device for framebuffer %d; errno = %ld\n", i, PTR_ERR(c));
1453 if (fb_info->pixmap.addr == NULL) {
1454 fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1455 if (fb_info->pixmap.addr) {
1456 fb_info->pixmap.size = FBPIXMAPSIZE;
1457 fb_info->pixmap.buf_align = 1;
1458 fb_info->pixmap.scan_align = 1;
1459 fb_info->pixmap.access_align = 4;
1460 fb_info->pixmap.flags = FB_PIXMAP_DEFAULT;
1463 fb_info->pixmap.offset = 0;
1465 if (fb_info->sprite.addr == NULL) {
1466 fb_info->sprite.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1467 if (fb_info->sprite.addr) {
1468 fb_info->sprite.size = FBPIXMAPSIZE;
1469 fb_info->sprite.buf_align = 1;
1470 fb_info->sprite.scan_align = 1;
1471 fb_info->sprite.access_align = 4;
1472 fb_info->sprite.flags = FB_PIXMAP_DEFAULT;
1475 fb_info->sprite.offset = 0;
1477 if (!fb_info->monspecs.modelist.prev ||
1478 !fb_info->monspecs.modelist.next ||
1479 list_empty(&fb_info->monspecs.modelist)) {
1480 struct fb_videomode mode;
1482 INIT_LIST_HEAD(&fb_info->monspecs.modelist);
1483 fb_var_to_videomode(&mode, &fb_info->var);
1484 fb_add_videomode(&mode, &fb_info->monspecs.modelist);
1487 registered_fb[i] = fb_info;
1489 devfs_mk_cdev(MKDEV(FB_MAJOR, i),
1490 S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
1496 * unregister_framebuffer - releases a frame buffer device
1497 * @fb_info: frame buffer info structure
1499 * Unregisters a frame buffer device @fb_info.
1501 * Returns negative errno on error, or zero for success.
1506 unregister_framebuffer(struct fb_info *fb_info)
1511 if (!registered_fb[i])
1513 devfs_remove("fb/%d", i);
1515 if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
1516 kfree(fb_info->pixmap.addr);
1517 if (fb_info->sprite.addr && (fb_info->sprite.flags & FB_PIXMAP_DEFAULT))
1518 kfree(fb_info->sprite.addr);
1519 fb_destroy_modelist(&fb_info->monspecs.modelist);
1520 registered_fb[i]=NULL;
1521 num_registered_fb--;
1522 class_simple_device_remove(MKDEV(FB_MAJOR, i));
1527 * fb_register_client - register a client notifier
1528 * @nb: notifier block to callback on events
1530 int fb_register_client(struct notifier_block *nb)
1532 return notifier_chain_register(&fb_notifier_list, nb);
1536 * fb_unregister_client - unregister a client notifier
1537 * @nb: notifier block to callback on events
1539 int fb_unregister_client(struct notifier_block *nb)
1541 return notifier_chain_unregister(&fb_notifier_list, nb);
1545 * fb_set_suspend - low level driver signals suspend
1546 * @info: framebuffer affected
1547 * @state: 0 = resuming, !=0 = suspending
1549 * This is meant to be used by low level drivers to
1550 * signal suspend/resume to the core & clients.
1551 * It must be called with the console semaphore held
1553 void fb_set_suspend(struct fb_info *info, int state)
1555 struct fb_event event;
1559 notifier_call_chain(&fb_notifier_list, FB_EVENT_SUSPEND, &event);
1560 info->state = FBINFO_STATE_SUSPENDED;
1562 info->state = FBINFO_STATE_RUNNING;
1563 notifier_call_chain(&fb_notifier_list, FB_EVENT_RESUME, &event);
1568 * fbmem_init - init frame buffer subsystem
1570 * Initialize the frame buffer subsystem.
1572 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1581 create_proc_read_entry("fb", 0, NULL, fbmem_read_proc, NULL);
1584 if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
1585 printk("unable to get major %d for fb devs\n", FB_MAJOR);
1587 fb_class = class_simple_create(THIS_MODULE, "graphics");
1588 if (IS_ERR(fb_class)) {
1589 printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
1601 * Probe for all builtin frame buffer devices
1603 for (i = 0; i < num_pref_init_funcs; i++)
1604 pref_init_funcs[i]();
1606 for (i = 0; i < NUM_FB_DRIVERS; i++)
1607 if (fb_drivers[i].init)
1608 fb_drivers[i].init();
1613 * video_setup - process command line options
1614 * @options: string of options
1616 * Process command line options for frame buffer subsystem.
1618 * NOTE: This function is a __setup and __init function.
1624 int __init video_setup(char *options)
1628 if (!options || !*options)
1632 if (!strcmp(options, "ofonly")) {
1638 if (num_pref_init_funcs == FB_MAX)
1641 for (i = 0; i < NUM_FB_DRIVERS; i++) {
1642 j = strlen(fb_drivers[i].name);
1643 if (!strncmp(options, fb_drivers[i].name, j) &&
1644 options[j] == ':') {
1645 if (!strcmp(options+j+1, "off"))
1646 fb_drivers[i].init = NULL;
1648 if (fb_drivers[i].init) {
1649 pref_init_funcs[num_pref_init_funcs++] =
1651 fb_drivers[i].init = NULL;
1653 if (fb_drivers[i].setup)
1654 fb_drivers[i].setup(options+j+1);
1661 * If we get here no fb was specified.
1662 * We consider the argument to be a global video mode option.
1664 global_mode_option = options;
1668 __setup("video=", video_setup);
1671 * Visible symbols for modules
1674 EXPORT_SYMBOL(register_framebuffer);
1675 EXPORT_SYMBOL(unregister_framebuffer);
1676 EXPORT_SYMBOL(num_registered_fb);
1677 EXPORT_SYMBOL(registered_fb);
1678 EXPORT_SYMBOL(fb_prepare_logo);
1679 EXPORT_SYMBOL(fb_show_logo);
1680 EXPORT_SYMBOL(fb_set_var);
1681 EXPORT_SYMBOL(fb_blank);
1682 EXPORT_SYMBOL(fb_pan_display);
1683 EXPORT_SYMBOL(fb_get_buffer_offset);
1684 EXPORT_SYMBOL(fb_iomove_buf_unaligned);
1685 EXPORT_SYMBOL(fb_iomove_buf_aligned);
1686 EXPORT_SYMBOL(fb_sysmove_buf_unaligned);
1687 EXPORT_SYMBOL(fb_sysmove_buf_aligned);
1688 EXPORT_SYMBOL(fb_load_cursor_image);
1689 EXPORT_SYMBOL(fb_set_suspend);
1690 EXPORT_SYMBOL(fb_register_client);
1691 EXPORT_SYMBOL(fb_unregister_client);
1693 MODULE_LICENSE("GPL");