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 amifb_init(void);
60 extern int amifb_setup(char*);
61 extern int atafb_init(void);
62 extern int atafb_setup(char*);
63 extern int macfb_init(void);
64 extern int macfb_setup(char*);
65 extern int cyberfb_init(void);
66 extern int cyberfb_setup(char*);
67 extern int pm2fb_init(void);
68 extern int pm2fb_setup(char*);
69 extern int pm3fb_init(void);
70 extern int pm3fb_setup(char*);
71 extern int clps711xfb_init(void);
72 extern int cyber2000fb_init(void);
73 extern int cyber2000fb_setup(char*);
74 extern int retz3fb_init(void);
75 extern int retz3fb_setup(char*);
76 extern int clgenfb_init(void);
77 extern int clgenfb_setup(char*);
78 extern int hitfb_init(void);
79 extern int vfb_init(void);
80 extern int vfb_setup(char*);
81 extern int offb_init(void);
82 extern int atyfb_init(void);
83 extern int atyfb_setup(char*);
84 extern int aty128fb_init(void);
85 extern int aty128fb_setup(char*);
86 extern int neofb_init(void);
87 extern int neofb_setup(char*);
88 extern int igafb_init(void);
89 extern int igafb_setup(char*);
90 extern int imsttfb_init(void);
91 extern int imsttfb_setup(char*);
92 extern int dnfb_init(void);
93 extern int tgafb_init(void);
94 extern int tgafb_setup(char*);
95 extern int virgefb_init(void);
96 extern int virgefb_setup(char*);
97 extern int resolver_video_setup(char*);
98 extern int s3triofb_init(void);
99 extern int vesafb_init(void);
100 extern int vesafb_setup(char*);
101 extern int vga16fb_init(void);
102 extern int vga16fb_setup(char*);
103 extern int hgafb_init(void);
104 extern int hgafb_setup(char*);
105 extern int matroxfb_init(void);
106 extern int matroxfb_setup(char*);
107 extern int hpfb_init(void);
108 extern int platinumfb_init(void);
109 extern int platinumfb_setup(char*);
110 extern int control_init(void);
111 extern int control_setup(char*);
112 extern int valkyriefb_init(void);
113 extern int valkyriefb_setup(char*);
114 extern int chips_init(void);
115 extern int g364fb_init(void);
116 extern int sa1100fb_init(void);
117 extern int pxafb_init(void);
118 extern int pxafb_setup(char*);
119 extern int fm2fb_init(void);
120 extern int fm2fb_setup(char*);
121 extern int q40fb_init(void);
122 extern int sun3fb_init(void);
123 extern int sun3fb_setup(char *);
124 extern int sgivwfb_init(void);
125 extern int sgivwfb_setup(char*);
126 extern int gbefb_init(void);
127 extern int gbefb_setup(char*);
128 extern int rivafb_init(void);
129 extern int rivafb_setup(char*);
130 extern int tdfxfb_init(void);
131 extern int tdfxfb_setup(char*);
132 extern int tridentfb_init(void);
133 extern int tridentfb_setup(char*);
134 extern int sisfb_init(void);
135 extern int sisfb_setup(char*);
136 extern int stifb_init(void);
137 extern int stifb_setup(char*);
138 extern int pmagbafb_init(void);
139 extern int pmagbbfb_init(void);
140 extern int maxinefb_init(void);
141 extern int tx3912fb_init(void);
142 extern int tx3912fb_setup(char*);
143 extern int radeonfb_init(void);
144 extern int radeonfb_setup(char*);
145 extern int radeonfb_old_init(void);
146 extern int radeonfb_old_setup(char*);
147 extern int e1355fb_init(void);
148 extern int e1355fb_setup(char*);
149 extern int pvr2fb_init(void);
150 extern int pvr2fb_setup(char*);
151 extern int sstfb_init(void);
152 extern int sstfb_setup(char*);
153 extern int i810fb_init(void);
154 extern int i810fb_setup(char*);
155 extern int ffb_init(void);
156 extern int ffb_setup(char*);
157 extern int cg6_init(void);
158 extern int cg6_setup(char*);
159 extern int cg3_init(void);
160 extern int cg3_setup(char*);
161 extern int bw2_init(void);
162 extern int bw2_setup(char*);
163 extern int cg14_init(void);
164 extern int cg14_setup(char*);
165 extern int p9100_init(void);
166 extern int p9100_setup(char*);
167 extern int tcx_init(void);
168 extern int tcx_setup(char*);
169 extern int leo_init(void);
170 extern int leo_setup(char*);
171 extern int kyrofb_init(void);
172 extern int kyrofb_setup(char*);
173 extern int mc68x328fb_init(void);
174 extern int mc68x328fb_setup(char *);
175 extern int asiliantfb_init(void);
181 } fb_drivers[] __initdata = {
184 * Chipset specific drivers that use resource management
186 #ifdef CONFIG_FB_RETINAZ3
187 { "retz3fb", retz3fb_init, retz3fb_setup },
189 #ifdef CONFIG_FB_AMIGA
190 { "amifb", amifb_init, amifb_setup },
192 #ifdef CONFIG_FB_CLPS711X
193 { "clps711xfb", clps711xfb_init, NULL },
195 #ifdef CONFIG_FB_CYBER
196 { "cyberfb", cyberfb_init, cyberfb_setup },
198 #ifdef CONFIG_FB_CYBER2000
199 { "cyber2000fb", cyber2000fb_init, cyber2000fb_setup },
202 { "pm2fb", pm2fb_init, pm2fb_setup },
205 { "pm3fb", pm3fb_init, pm3fb_setup },
207 #ifdef CONFIG_FB_CLGEN
208 { "clgenfb", clgenfb_init, clgenfb_setup },
211 { "atyfb", atyfb_init, atyfb_setup },
213 #ifdef CONFIG_FB_MATROX
214 { "matroxfb", matroxfb_init, matroxfb_setup },
216 #ifdef CONFIG_FB_ATY128
217 { "aty128fb", aty128fb_init, aty128fb_setup },
219 #ifdef CONFIG_FB_NEOMAGIC
220 { "neofb", neofb_init, neofb_setup },
222 #ifdef CONFIG_FB_VIRGE
223 { "virgefb", virgefb_init, virgefb_setup },
225 #ifdef CONFIG_FB_RIVA
226 { "rivafb", rivafb_init, rivafb_setup },
228 #ifdef CONFIG_FB_3DFX
229 { "tdfxfb", tdfxfb_init, tdfxfb_setup },
231 #ifdef CONFIG_FB_RADEON
232 { "radeonfb", radeonfb_init, radeonfb_setup },
234 #ifdef CONFIG_FB_RADEON_OLD
235 { "radeonfb_old", radeonfb_old_init, radeonfb_old_setup },
237 #ifdef CONFIG_FB_CONTROL
238 { "controlfb", control_init, control_setup },
240 #ifdef CONFIG_FB_PLATINUM
241 { "platinumfb", platinumfb_init, platinumfb_setup },
243 #ifdef CONFIG_FB_VALKYRIE
244 { "valkyriefb", valkyriefb_init, valkyriefb_setup },
246 #ifdef CONFIG_FB_CT65550
247 { "chipsfb", chips_init, NULL },
249 #ifdef CONFIG_FB_IMSTT
250 { "imsttfb", imsttfb_init, imsttfb_setup },
252 #ifdef CONFIG_FB_S3TRIO
253 { "s3triofb", s3triofb_init, NULL },
256 { "fm2fb", fm2fb_init, fm2fb_setup },
259 { "sisfb", sisfb_init, sisfb_setup },
261 #ifdef CONFIG_FB_TRIDENT
262 { "tridentfb", tridentfb_init, tridentfb_setup },
264 #ifdef CONFIG_FB_I810
265 { "i810fb", i810fb_init, i810fb_setup },
268 { "stifb", stifb_init, stifb_setup },
271 { "ffb", ffb_init, ffb_setup },
274 { "cg6fb", cg6_init, cg6_setup },
277 { "cg3fb", cg3_init, cg3_setup },
280 { "bw2fb", bw2_init, bw2_setup },
282 #ifdef CONFIG_FB_CG14
283 { "cg14fb", cg14_init, cg14_setup },
285 #ifdef CONFIG_FB_P9100
286 { "p9100fb", p9100_init, p9100_setup },
289 { "tcxfb", tcx_init, tcx_setup },
292 { "leofb", leo_init, leo_setup },
296 * Generic drivers that are used as fallbacks
298 * These depend on resource management and must be initialized
299 * _after_ all other frame buffer devices that use resource
304 { "offb", offb_init, NULL },
306 #ifdef CONFIG_FB_VESA
307 { "vesafb", vesafb_init, vesafb_setup },
311 * Chipset specific drivers that don't use resource management (yet)
314 #ifdef CONFIG_FB_SGIVW
315 { "sgivwfb", sgivwfb_init, sgivwfb_setup },
318 { "gbefb", gbefb_init, gbefb_setup },
320 #ifdef CONFIG_FB_ACORN
321 { "acornfb", acornfb_init, acornfb_setup },
323 #ifdef CONFIG_FB_ATARI
324 { "atafb", atafb_init, atafb_setup },
327 { "macfb", macfb_init, macfb_setup },
330 { "hgafb", hgafb_init, hgafb_setup },
333 { "igafb", igafb_init, igafb_setup },
336 { "apollofb", dnfb_init, NULL },
339 { "q40fb", q40fb_init, NULL },
342 { "tgafb", tgafb_init, tgafb_setup },
344 #ifdef CONFIG_FB_HP300
345 { "hpfb", hpfb_init, NULL },
347 #ifdef CONFIG_FB_G364
348 { "g364fb", g364fb_init, NULL },
350 #ifdef CONFIG_FB_SA1100
351 { "sa1100fb", sa1100fb_init, NULL },
354 { "pxafb", pxafb_init, pxafb_setup },
356 #ifdef CONFIG_FB_SUN3
357 { "sun3fb", sun3fb_init, sun3fb_setup },
360 { "hitfb", hitfb_init, NULL },
362 #ifdef CONFIG_FB_TX3912
363 { "tx3912fb", tx3912fb_init, tx3912fb_setup },
365 #ifdef CONFIG_FB_E1355
366 { "e1355fb", e1355fb_init, e1355fb_setup },
368 #ifdef CONFIG_FB_PVR2
369 { "pvr2fb", pvr2fb_init, pvr2fb_setup },
371 #ifdef CONFIG_FB_PMAG_BA
372 { "pmagbafb", pmagbafb_init, NULL },
374 #ifdef CONFIG_FB_PMAGB_B
375 { "pmagbbfb", pmagbbfb_init, NULL },
377 #ifdef CONFIG_FB_MAXINE
378 { "maxinefb", maxinefb_init, NULL },
380 #ifdef CONFIG_FB_VOODOO1
381 { "sstfb", sstfb_init, sstfb_setup },
383 #ifdef CONFIG_FB_KYRO
384 { "kyrofb", kyrofb_init, kyrofb_setup },
386 #ifdef CONFIG_FB_68328
387 { "68328fb", mc68x328fb_init, mc68x328fb_setup },
389 #ifdef CONFIG_FB_ASILIANT
390 { "asiliantfb", asiliantfb_init, NULL },
394 * Generic drivers that don't use resource management (yet)
397 #ifdef CONFIG_FB_VGA16
398 { "vga16fb", vga16fb_init, vga16fb_setup },
401 #ifdef CONFIG_GSP_RESOLVER
402 /* Not a real frame buffer device... */
403 { "resolverfb", NULL, resolver_video_setup },
406 #ifdef CONFIG_FB_VIRTUAL
408 * Vfb must be last to avoid that it becomes your primary display if
409 * other display devices are present
411 { "vfb", vfb_init, vfb_setup },
415 #define NUM_FB_DRIVERS (sizeof(fb_drivers)/sizeof(*fb_drivers))
416 #define FBPIXMAPSIZE 16384
418 extern const char *global_mode_option;
420 static initcall_t pref_init_funcs[FB_MAX];
421 static int num_pref_init_funcs __initdata = 0;
422 static struct notifier_block *fb_notifier_list;
423 struct fb_info *registered_fb[FB_MAX];
424 int num_registered_fb;
427 static int ofonly __initdata = 0;
433 static u8 fb_sys_inbuf(struct fb_info *info, u8 *src)
438 static void fb_sys_outbuf(struct fb_info *info, u8 *dst,
439 u8 *src, unsigned int size)
441 memcpy(dst, src, size);
444 void fb_move_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
445 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
450 for (i = height; i--; ) {
451 buf->outbuf(info, dst, src, s_pitch);
457 void fb_move_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf,
458 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
459 u32 height, u32 shift_high, u32 shift_low,
462 u8 mask = (u8) (0xfff << shift_high), tmp;
465 for (i = height; i--; ) {
466 for (j = 0; j < idx; j++) {
467 tmp = buf->inbuf(info, dst+j);
469 tmp |= *src >> shift_low;
470 buf->outbuf(info, dst+j, &tmp, 1);
471 tmp = *src << shift_high;
472 buf->outbuf(info, dst+j+1, &tmp, 1);
475 tmp = buf->inbuf(info, dst+idx);
477 tmp |= *src >> shift_low;
478 buf->outbuf(info, dst+idx, &tmp, 1);
479 if (shift_high < mod) {
480 tmp = *src << shift_high;
481 buf->outbuf(info, dst+idx+1, &tmp, 1);
489 * we need to lock this section since fb_cursor
490 * may use fb_imageblit()
492 char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size)
494 u32 align = buf->buf_align - 1, offset;
495 char *addr = buf->addr;
497 /* If IO mapped, we need to sync before access, no sharing of
500 if (buf->flags & FB_PIXMAP_IO) {
501 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
502 info->fbops->fb_sync(info);
506 /* See if we fit in the remaining pixmap space */
507 offset = buf->offset + align;
509 if (offset + size > buf->size) {
510 /* We do not fit. In order to be able to re-use the buffer,
511 * we must ensure no asynchronous DMA'ing or whatever operation
512 * is in progress, we sync for that.
514 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
515 info->fbops->fb_sync(info);
518 buf->offset = offset + size;
525 #include <linux/linux_logo.h>
527 static inline unsigned safe_shift(unsigned d, int n)
529 return n < 0 ? d >> -n : d << n;
532 static void __init fb_set_logocmap(struct fb_info *info,
533 const struct linux_logo *logo)
535 struct fb_cmap palette_cmap;
536 u16 palette_green[16];
537 u16 palette_blue[16];
540 const unsigned char *clut = logo->clut;
542 palette_cmap.start = 0;
543 palette_cmap.len = 16;
544 palette_cmap.red = palette_red;
545 palette_cmap.green = palette_green;
546 palette_cmap.blue = palette_blue;
547 palette_cmap.transp = NULL;
549 for (i = 0; i < logo->clutsize; i += n) {
550 n = logo->clutsize - i;
551 /* palette_cmap provides space for only 16 colors at once */
554 palette_cmap.start = 32 + i;
555 palette_cmap.len = n;
556 for (j = 0; j < n; ++j) {
557 palette_cmap.red[j] = clut[0] << 8 | clut[0];
558 palette_cmap.green[j] = clut[1] << 8 | clut[1];
559 palette_cmap.blue[j] = clut[2] << 8 | clut[2];
562 fb_set_cmap(&palette_cmap, 1, info);
566 static void __init fb_set_logo_truepalette(struct fb_info *info,
567 const struct linux_logo *logo,
570 unsigned char mask[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
571 unsigned char redmask, greenmask, bluemask;
572 int redshift, greenshift, blueshift;
574 const unsigned char *clut = logo->clut;
577 * We have to create a temporary palette since console palette is only
580 /* Bug: Doesn't obey msb_right ... (who needs that?) */
581 redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8];
582 greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8];
583 bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8];
584 redshift = info->var.red.offset - (8 - info->var.red.length);
585 greenshift = info->var.green.offset - (8 - info->var.green.length);
586 blueshift = info->var.blue.offset - (8 - info->var.blue.length);
588 for ( i = 0; i < logo->clutsize; i++) {
589 palette[i+32] = (safe_shift((clut[0] & redmask), redshift) |
590 safe_shift((clut[1] & greenmask), greenshift) |
591 safe_shift((clut[2] & bluemask), blueshift));
596 static void __init fb_set_logo_directpalette(struct fb_info *info,
597 const struct linux_logo *logo,
600 int redshift, greenshift, blueshift;
603 redshift = info->var.red.offset;
604 greenshift = info->var.green.offset;
605 blueshift = info->var.blue.offset;
607 for (i = 32; i < logo->clutsize; i++)
608 palette[i] = i << redshift | i << greenshift | i << blueshift;
611 static void __init fb_set_logo(struct fb_info *info,
612 const struct linux_logo *logo, u8 *dst,
616 const u8 *src = logo->data;
621 for (i = 0; i < logo->height; i++)
622 for (j = 0; j < logo->width; src++) {
625 if (j < logo->width) {
626 *dst++ = *src & 0x0f;
634 for (i = 0; i < logo->height; i++) {
637 for (j = 0; j < logo->width; j++) {
638 *dst++ = (d >> shift) & 1;
639 shift = (shift-1) & 7;
649 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
650 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
651 * the visual format and color depth of the framebuffer, the DAC, the
652 * pseudo_palette, and the logo data will be adjusted accordingly.
654 * Case 1 - linux_logo_clut224:
655 * Color exceeds the number of console colors (16), thus we set the hardware DAC
656 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
658 * For visuals that require color info from the pseudo_palette, we also construct
659 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
662 * Case 2 - linux_logo_vga16:
663 * The number of colors just matches the console colors, thus there is no need
664 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
665 * each byte contains color information for two pixels (upper and lower nibble).
666 * To be consistent with fb_imageblit() usage, we therefore separate the two
667 * nibbles into separate bytes. The "depth" flag will be set to 4.
669 * Case 3 - linux_logo_mono:
670 * This is similar with Case 2. Each byte contains information for 8 pixels.
671 * We isolate each bit and expand each into a byte. The "depth" flag will
674 static struct logo_data {
676 int needs_directpalette;
677 int needs_truepalette;
679 const struct linux_logo *logo;
682 int fb_prepare_logo(struct fb_info *info)
684 memset(&fb_logo, 0, sizeof(struct logo_data));
686 switch (info->fix.visual) {
687 case FB_VISUAL_TRUECOLOR:
688 if (info->var.bits_per_pixel >= 8)
689 fb_logo.needs_truepalette = 1;
691 case FB_VISUAL_DIRECTCOLOR:
692 if (info->var.bits_per_pixel >= 24) {
693 fb_logo.needs_directpalette = 1;
694 fb_logo.needs_cmapreset = 1;
697 case FB_VISUAL_PSEUDOCOLOR:
698 fb_logo.needs_cmapreset = 1;
702 /* Return if no suitable logo was found */
703 fb_logo.logo = fb_find_logo(info->var.bits_per_pixel);
705 if (!fb_logo.logo || fb_logo.logo->height > info->var.yres) {
709 /* What depth we asked for might be different from what we get */
710 if (fb_logo.logo->type == LINUX_LOGO_CLUT224)
712 else if (fb_logo.logo->type == LINUX_LOGO_VGA16)
716 return fb_logo.logo->height;
719 int fb_show_logo(struct fb_info *info)
721 u32 *palette = NULL, *saved_pseudo_palette = NULL;
722 unsigned char *logo_new = NULL;
723 struct fb_image image;
726 /* Return if the frame buffer is not mapped or suspended */
727 if (fb_logo.logo == NULL || info->state != FBINFO_STATE_RUNNING)
730 image.depth = fb_logo.depth;
731 image.data = fb_logo.logo->data;
733 if (fb_logo.needs_cmapreset)
734 fb_set_logocmap(info, fb_logo.logo);
736 if (fb_logo.needs_truepalette ||
737 fb_logo.needs_directpalette) {
738 palette = kmalloc(256 * 4, GFP_KERNEL);
742 if (fb_logo.needs_truepalette)
743 fb_set_logo_truepalette(info, fb_logo.logo, palette);
745 fb_set_logo_directpalette(info, fb_logo.logo, palette);
747 saved_pseudo_palette = info->pseudo_palette;
748 info->pseudo_palette = palette;
751 if (fb_logo.depth == 4) {
752 logo_new = kmalloc(fb_logo.logo->width * fb_logo.logo->height,
754 if (logo_new == NULL) {
757 if (saved_pseudo_palette)
758 info->pseudo_palette = saved_pseudo_palette;
761 image.data = logo_new;
762 fb_set_logo(info, fb_logo.logo, logo_new, fb_logo.depth);
765 image.width = fb_logo.logo->width;
766 image.height = fb_logo.logo->height;
769 for (x = 0; x < num_online_cpus() * (fb_logo.logo->width + 8) &&
770 x <= info->var.xres-fb_logo.logo->width; x += (fb_logo.logo->width + 8)) {
772 info->fbops->fb_imageblit(info, &image);
777 if (saved_pseudo_palette != NULL)
778 info->pseudo_palette = saved_pseudo_palette;
779 if (logo_new != NULL)
781 return fb_logo.logo->height;
784 int fb_prepare_logo(struct fb_info *info) { return 0; }
785 int fb_show_logo(struct fb_info *info) { return 0; }
786 #endif /* CONFIG_LOGO */
788 static int fbmem_read_proc(char *buf, char **start, off_t offset,
789 int len, int *eof, void *private)
795 for (fi = registered_fb; fi < ®istered_fb[FB_MAX] && len < 4000; fi++)
797 clen += sprintf(buf + clen, "%d %s\n",
800 *start = buf + offset;
805 return clen < len ? clen : len;
809 fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
811 unsigned long p = *ppos;
812 struct inode *inode = file->f_dentry->d_inode;
813 int fbidx = iminor(inode);
814 struct fb_info *info = registered_fb[fbidx];
816 if (!info || ! info->screen_base)
819 if (info->state != FBINFO_STATE_RUNNING)
822 if (info->fbops->fb_read)
823 return info->fbops->fb_read(file, buf, count, ppos);
825 if (p >= info->fix.smem_len)
827 if (count >= info->fix.smem_len)
828 count = info->fix.smem_len;
829 if (count + p > info->fix.smem_len)
830 count = info->fix.smem_len - p;
831 if (info->fbops->fb_sync)
832 info->fbops->fb_sync(info);
836 base_addr = info->screen_base;
837 count -= copy_to_user(buf, base_addr+p, count);
846 fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
848 unsigned long p = *ppos;
849 struct inode *inode = file->f_dentry->d_inode;
850 int fbidx = iminor(inode);
851 struct fb_info *info = registered_fb[fbidx];
854 if (!info || !info->screen_base)
857 if (info->state != FBINFO_STATE_RUNNING)
860 if (info->fbops->fb_write)
861 return info->fbops->fb_write(file, buf, count, ppos);
863 if (p > info->fix.smem_len)
865 if (count >= info->fix.smem_len)
866 count = info->fix.smem_len;
868 if (count + p > info->fix.smem_len) {
869 count = info->fix.smem_len - p;
872 if (info->fbops->fb_sync)
873 info->fbops->fb_sync(info);
877 base_addr = info->screen_base;
878 count -= copy_from_user(base_addr+p, buf, count);
888 static void try_to_load(int fb)
890 request_module("fb%d", fb);
892 #endif /* CONFIG_KMOD */
895 fb_load_cursor_image(struct fb_info *info)
897 unsigned int width = (info->cursor.image.width + 7) >> 3;
898 u8 *data = (u8 *) info->cursor.image.data;
900 info->sprite.outbuf(info, info->sprite.addr, data, width);
904 fb_cursor(struct fb_info *info, struct fb_cursor *sprite)
906 struct fb_cursor cursor;
909 if (copy_from_user(&cursor, sprite, sizeof(struct fb_cursor)))
912 if (cursor.set & FB_CUR_SETCUR)
913 info->cursor.enable = 1;
915 if (cursor.set & FB_CUR_SETCMAP) {
916 err = fb_copy_cmap(&cursor.image.cmap, &sprite->image.cmap, 1);
921 if (cursor.set & FB_CUR_SETSHAPE) {
922 int size = ((cursor.image.width + 7) >> 3) * cursor.image.height;
925 if ((cursor.image.height != info->cursor.image.height) ||
926 (cursor.image.width != info->cursor.image.width))
927 cursor.set |= FB_CUR_SETSIZE;
929 data = kmalloc(size, GFP_KERNEL);
933 mask = kmalloc(size, GFP_KERNEL);
939 if (copy_from_user(data, sprite->image.data, size) ||
940 copy_from_user(mask, sprite->mask, size)) {
945 cursor.image.data = data;
948 info->cursor.set = cursor.set;
949 info->cursor.rop = cursor.rop;
950 err = info->fbops->fb_cursor(info, &cursor);
955 fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
957 int xoffset = var->xoffset;
958 int yoffset = var->yoffset;
961 if (xoffset < 0 || yoffset < 0 || !info->fbops->fb_pan_display ||
962 xoffset + info->var.xres > info->var.xres_virtual ||
963 yoffset + info->var.yres > info->var.yres_virtual)
965 if ((err = info->fbops->fb_pan_display(var, info)))
967 info->var.xoffset = var->xoffset;
968 info->var.yoffset = var->yoffset;
969 if (var->vmode & FB_VMODE_YWRAP)
970 info->var.vmode |= FB_VMODE_YWRAP;
972 info->var.vmode &= ~FB_VMODE_YWRAP;
977 fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
981 if ((var->activate & FB_ACTIVATE_FORCE) ||
982 memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
983 if (!info->fbops->fb_check_var) {
988 if ((err = info->fbops->fb_check_var(var, info)))
991 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
994 if (info->fbops->fb_set_par)
995 info->fbops->fb_set_par(info);
997 fb_pan_display(info, &info->var);
999 fb_set_cmap(&info->cmap, 1, info);
1001 notifier_call_chain(&fb_notifier_list, FB_EVENT_MODE_CHANGE, info);
1008 fb_blank(struct fb_info *info, int blank)
1010 /* ??? Variable sized stack allocation. */
1011 u16 black[info->cmap.len];
1012 struct fb_cmap cmap;
1014 if (info->fbops->fb_blank && !info->fbops->fb_blank(blank, info))
1017 memset(black, 0, info->cmap.len * sizeof(u16));
1018 cmap.red = cmap.green = cmap.blue = black;
1019 cmap.transp = info->cmap.transp ? black : NULL;
1020 cmap.start = info->cmap.start;
1021 cmap.len = info->cmap.len;
1024 return fb_set_cmap(&cmap, 1, info);
1028 fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1031 int fbidx = iminor(inode);
1032 struct fb_info *info = registered_fb[fbidx];
1033 struct fb_ops *fb = info->fbops;
1034 struct fb_var_screeninfo var;
1035 struct fb_fix_screeninfo fix;
1036 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
1037 struct fb_con2fbmap con2fb;
1039 struct fb_cmap cmap;
1045 case FBIOGET_VSCREENINFO:
1046 return copy_to_user((void *) arg, &info->var,
1047 sizeof(var)) ? -EFAULT : 0;
1048 case FBIOPUT_VSCREENINFO:
1049 if (copy_from_user(&var, (void *) arg, sizeof(var)))
1051 acquire_console_sem();
1052 i = fb_set_var(info, &var);
1053 release_console_sem();
1055 if (copy_to_user((void *) arg, &var, sizeof(var)))
1058 case FBIOGET_FSCREENINFO:
1059 return copy_to_user((void *) arg, &info->fix,
1060 sizeof(fix)) ? -EFAULT : 0;
1062 if (copy_from_user(&cmap, (void *) arg, sizeof(cmap)))
1064 return (fb_set_cmap(&cmap, 0, info));
1066 if (copy_from_user(&cmap, (void *) arg, sizeof(cmap)))
1068 return (fb_copy_cmap(&info->cmap, &cmap, 2));
1069 case FBIOPAN_DISPLAY:
1070 if (copy_from_user(&var, (void *) arg, sizeof(var)))
1072 acquire_console_sem();
1073 i = fb_pan_display(info, &var);
1074 release_console_sem();
1077 if (copy_to_user((void *) arg, &var, sizeof(var)))
1081 acquire_console_sem();
1082 i = fb_cursor(info, (struct fb_cursor *) arg);
1083 release_console_sem();
1085 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
1086 case FBIOGET_CON2FBMAP:
1087 if (copy_from_user(&con2fb, (void *)arg, sizeof(con2fb)))
1089 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
1091 con2fb.framebuffer = con2fb_map[con2fb.console-1];
1092 return copy_to_user((void *)arg, &con2fb,
1093 sizeof(con2fb)) ? -EFAULT : 0;
1094 case FBIOPUT_CON2FBMAP:
1095 if (copy_from_user(&con2fb, (void *)arg, sizeof(con2fb)))
1097 if (con2fb.console < 0 || con2fb.console > MAX_NR_CONSOLES)
1099 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
1102 if (!registered_fb[con2fb.framebuffer])
1103 try_to_load(con2fb.framebuffer);
1104 #endif /* CONFIG_KMOD */
1105 if (!registered_fb[con2fb.framebuffer])
1107 if (con2fb.console != 0)
1108 set_con2fb_map(con2fb.console-1, con2fb.framebuffer);
1112 #endif /* CONFIG_FRAMEBUFFER_CONSOLE */
1114 acquire_console_sem();
1115 i = fb_blank(info, arg);
1116 release_console_sem();
1119 if (fb->fb_ioctl == NULL)
1121 return fb->fb_ioctl(inode, file, cmd, arg, info);
1126 fb_mmap(struct file *file, struct vm_area_struct * vma)
1128 int fbidx = iminor(file->f_dentry->d_inode);
1129 struct fb_info *info = registered_fb[fbidx];
1130 struct fb_ops *fb = info->fbops;
1132 #if !defined(__sparc__) || defined(__sparc_v9__)
1133 unsigned long start;
1137 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1139 off = vma->vm_pgoff << PAGE_SHIFT;
1145 res = fb->fb_mmap(info, file, vma);
1150 #if defined(__sparc__) && !defined(__sparc_v9__)
1151 /* Should never get here, all fb drivers should have their own
1158 /* frame buffer memory */
1159 start = info->fix.smem_start;
1160 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
1162 /* memory mapped io */
1164 if (info->var.accel_flags) {
1168 start = info->fix.mmio_start;
1169 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
1173 if ((vma->vm_end - vma->vm_start + off) > len)
1176 vma->vm_pgoff = off >> PAGE_SHIFT;
1177 /* This is an IO map - tell maydump to skip this VMA */
1178 vma->vm_flags |= VM_IO;
1179 #if defined(__sparc_v9__)
1180 vma->vm_flags |= (VM_SHM | VM_LOCKED);
1181 if (io_remap_page_range(vma, vma->vm_start, off,
1182 vma->vm_end - vma->vm_start, vma->vm_page_prot, 0))
1185 #if defined(__mc68000__)
1186 #if defined(CONFIG_SUN3)
1187 pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
1188 #elif defined(CONFIG_MMU)
1189 if (CPU_IS_020_OR_030)
1190 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
1191 if (CPU_IS_040_OR_060) {
1192 pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
1193 /* Use no-cache mode, serialized */
1194 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
1197 #elif defined(__powerpc__)
1198 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
1199 #elif defined(__alpha__)
1200 /* Caching is off in the I/O space quadrant by design. */
1201 #elif defined(__i386__) || defined(__x86_64__)
1202 if (boot_cpu_data.x86 > 3)
1203 pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
1204 #elif defined(__mips__)
1205 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1206 #elif defined(__hppa__)
1207 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
1208 #elif defined(__ia64__) || defined(__arm__) || defined(__sh__)
1209 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1211 #warning What do we have to do here??
1213 if (io_remap_page_range(vma, vma->vm_start, off,
1214 vma->vm_end - vma->vm_start, vma->vm_page_prot))
1216 #endif /* !__sparc_v9__ */
1218 #endif /* !sparc32 */
1222 fb_open(struct inode *inode, struct file *file)
1224 int fbidx = iminor(inode);
1225 struct fb_info *info;
1228 if (fbidx >= FB_MAX)
1231 if (!(info = registered_fb[fbidx]))
1233 #endif /* CONFIG_KMOD */
1234 if (!(info = registered_fb[fbidx]))
1236 if (!try_module_get(info->fbops->owner))
1238 if (info->fbops->fb_open) {
1239 res = info->fbops->fb_open(info,1);
1241 module_put(info->fbops->owner);
1247 fb_release(struct inode *inode, struct file *file)
1249 int fbidx = iminor(inode);
1250 struct fb_info *info;
1253 info = registered_fb[fbidx];
1254 if (info->fbops->fb_release)
1255 info->fbops->fb_release(info,1);
1256 module_put(info->fbops->owner);
1261 static struct file_operations fb_fops = {
1262 .owner = THIS_MODULE,
1268 .release = fb_release,
1269 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1270 .get_unmapped_area = get_fb_unmapped_area,
1274 static struct class_simple *fb_class;
1277 * register_framebuffer - registers a frame buffer device
1278 * @fb_info: frame buffer info structure
1280 * Registers a frame buffer device @fb_info.
1282 * Returns negative errno on error, or zero for success.
1287 register_framebuffer(struct fb_info *fb_info)
1290 struct class_device *c;
1292 if (num_registered_fb == FB_MAX)
1294 num_registered_fb++;
1295 for (i = 0 ; i < FB_MAX; i++)
1296 if (!registered_fb[i])
1300 c = class_simple_device_add(fb_class, MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
1303 printk(KERN_WARNING "Unable to create class_device for framebuffer %d; errno = %ld\n", i, PTR_ERR(c));
1306 if (fb_info->pixmap.addr == NULL) {
1307 fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1308 if (fb_info->pixmap.addr) {
1309 fb_info->pixmap.size = FBPIXMAPSIZE;
1310 fb_info->pixmap.buf_align = 1;
1311 fb_info->pixmap.scan_align = 1;
1312 fb_info->pixmap.access_align = 4;
1313 fb_info->pixmap.flags = FB_PIXMAP_DEFAULT;
1316 fb_info->pixmap.offset = 0;
1317 if (fb_info->pixmap.outbuf == NULL)
1318 fb_info->pixmap.outbuf = fb_sys_outbuf;
1319 if (fb_info->pixmap.inbuf == NULL)
1320 fb_info->pixmap.inbuf = fb_sys_inbuf;
1322 if (fb_info->sprite.addr == NULL) {
1323 fb_info->sprite.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1324 if (fb_info->sprite.addr) {
1325 fb_info->sprite.size = FBPIXMAPSIZE;
1326 fb_info->sprite.buf_align = 1;
1327 fb_info->sprite.scan_align = 1;
1328 fb_info->sprite.access_align = 4;
1329 fb_info->sprite.flags = FB_PIXMAP_DEFAULT;
1332 fb_info->sprite.offset = 0;
1333 if (fb_info->sprite.outbuf == NULL)
1334 fb_info->sprite.outbuf = fb_sys_outbuf;
1335 if (fb_info->sprite.inbuf == NULL)
1336 fb_info->sprite.inbuf = fb_sys_inbuf;
1338 registered_fb[i] = fb_info;
1340 devfs_mk_cdev(MKDEV(FB_MAJOR, i),
1341 S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
1347 * unregister_framebuffer - releases a frame buffer device
1348 * @fb_info: frame buffer info structure
1350 * Unregisters a frame buffer device @fb_info.
1352 * Returns negative errno on error, or zero for success.
1357 unregister_framebuffer(struct fb_info *fb_info)
1362 if (!registered_fb[i])
1364 devfs_remove("fb/%d", i);
1366 if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
1367 kfree(fb_info->pixmap.addr);
1368 if (fb_info->sprite.addr && (fb_info->sprite.flags & FB_PIXMAP_DEFAULT))
1369 kfree(fb_info->sprite.addr);
1370 registered_fb[i]=NULL;
1371 num_registered_fb--;
1372 class_simple_device_remove(MKDEV(FB_MAJOR, i));
1377 * fb_register_client - register a client notifier
1378 * @nb: notifier block to callback on events
1380 int fb_register_client(struct notifier_block *nb)
1382 return notifier_chain_register(&fb_notifier_list, nb);
1386 * fb_unregister_client - unregister a client notifier
1387 * @nb: notifier block to callback on events
1389 int fb_unregister_client(struct notifier_block *nb)
1391 return notifier_chain_unregister(&fb_notifier_list, nb);
1395 * fb_set_suspend - low level driver signals suspend
1396 * @info: framebuffer affected
1397 * @state: 0 = resuming, !=0 = suspending
1399 * This is meant to be used by low level drivers to
1400 * signal suspend/resume to the core & clients.
1401 * It must be called with the console semaphore held
1403 void fb_set_suspend(struct fb_info *info, int state)
1406 notifier_call_chain(&fb_notifier_list, FB_EVENT_SUSPEND, info);
1407 info->state = FBINFO_STATE_SUSPENDED;
1409 info->state = FBINFO_STATE_RUNNING;
1410 notifier_call_chain(&fb_notifier_list, FB_EVENT_RESUME, info);
1415 * fbmem_init - init frame buffer subsystem
1417 * Initialize the frame buffer subsystem.
1419 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1428 create_proc_read_entry("fb", 0, 0, fbmem_read_proc, NULL);
1431 if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
1432 printk("unable to get major %d for fb devs\n", FB_MAJOR);
1434 fb_class = class_simple_create(THIS_MODULE, "graphics");
1435 if (IS_ERR(fb_class)) {
1436 printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
1448 * Probe for all builtin frame buffer devices
1450 for (i = 0; i < num_pref_init_funcs; i++)
1451 pref_init_funcs[i]();
1453 for (i = 0; i < NUM_FB_DRIVERS; i++)
1454 if (fb_drivers[i].init)
1455 fb_drivers[i].init();
1460 * video_setup - process command line options
1461 * @options: string of options
1463 * Process command line options for frame buffer subsystem.
1465 * NOTE: This function is a __setup and __init function.
1471 int __init video_setup(char *options)
1475 if (!options || !*options)
1479 if (!strcmp(options, "ofonly")) {
1485 if (num_pref_init_funcs == FB_MAX)
1488 for (i = 0; i < NUM_FB_DRIVERS; i++) {
1489 j = strlen(fb_drivers[i].name);
1490 if (!strncmp(options, fb_drivers[i].name, j) &&
1491 options[j] == ':') {
1492 if (!strcmp(options+j+1, "off"))
1493 fb_drivers[i].init = NULL;
1495 if (fb_drivers[i].init) {
1496 pref_init_funcs[num_pref_init_funcs++] =
1498 fb_drivers[i].init = NULL;
1500 if (fb_drivers[i].setup)
1501 fb_drivers[i].setup(options+j+1);
1508 * If we get here no fb was specified.
1509 * We consider the argument to be a global video mode option.
1511 global_mode_option = options;
1515 __setup("video=", video_setup);
1518 * Visible symbols for modules
1521 EXPORT_SYMBOL(register_framebuffer);
1522 EXPORT_SYMBOL(unregister_framebuffer);
1523 EXPORT_SYMBOL(num_registered_fb);
1524 EXPORT_SYMBOL(registered_fb);
1525 EXPORT_SYMBOL(fb_prepare_logo);
1526 EXPORT_SYMBOL(fb_show_logo);
1527 EXPORT_SYMBOL(fb_set_var);
1528 EXPORT_SYMBOL(fb_blank);
1529 EXPORT_SYMBOL(fb_pan_display);
1530 EXPORT_SYMBOL(fb_get_buffer_offset);
1531 EXPORT_SYMBOL(fb_move_buf_unaligned);
1532 EXPORT_SYMBOL(fb_move_buf_aligned);
1533 EXPORT_SYMBOL(fb_load_cursor_image);
1534 EXPORT_SYMBOL(fb_set_suspend);
1535 EXPORT_SYMBOL(fb_register_client);
1536 EXPORT_SYMBOL(fb_unregister_client);
1538 MODULE_LICENSE("GPL");