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 *);
180 } fb_drivers[] __initdata = {
183 * Chipset specific drivers that use resource management
185 #ifdef CONFIG_FB_RETINAZ3
186 { "retz3fb", retz3fb_init, retz3fb_setup },
188 #ifdef CONFIG_FB_AMIGA
189 { "amifb", amifb_init, amifb_setup },
191 #ifdef CONFIG_FB_CLPS711X
192 { "clps711xfb", clps711xfb_init, NULL },
194 #ifdef CONFIG_FB_CYBER
195 { "cyberfb", cyberfb_init, cyberfb_setup },
197 #ifdef CONFIG_FB_CYBER2000
198 { "cyber2000fb", cyber2000fb_init, cyber2000fb_setup },
201 { "pm2fb", pm2fb_init, pm2fb_setup },
204 { "pm3fb", pm3fb_init, pm3fb_setup },
206 #ifdef CONFIG_FB_CLGEN
207 { "clgenfb", clgenfb_init, clgenfb_setup },
210 { "atyfb", atyfb_init, atyfb_setup },
212 #ifdef CONFIG_FB_MATROX
213 { "matroxfb", matroxfb_init, matroxfb_setup },
215 #ifdef CONFIG_FB_ATY128
216 { "aty128fb", aty128fb_init, aty128fb_setup },
218 #ifdef CONFIG_FB_NEOMAGIC
219 { "neofb", neofb_init, neofb_setup },
221 #ifdef CONFIG_FB_VIRGE
222 { "virgefb", virgefb_init, virgefb_setup },
224 #ifdef CONFIG_FB_RIVA
225 { "rivafb", rivafb_init, rivafb_setup },
227 #ifdef CONFIG_FB_3DFX
228 { "tdfxfb", tdfxfb_init, tdfxfb_setup },
230 #ifdef CONFIG_FB_RADEON
231 { "radeonfb", radeonfb_init, radeonfb_setup },
233 #ifdef CONFIG_FB_RADEON_OLD
234 { "radeonfb_old", radeonfb_old_init, radeonfb_old_setup },
236 #ifdef CONFIG_FB_CONTROL
237 { "controlfb", control_init, control_setup },
239 #ifdef CONFIG_FB_PLATINUM
240 { "platinumfb", platinumfb_init, platinumfb_setup },
242 #ifdef CONFIG_FB_VALKYRIE
243 { "valkyriefb", valkyriefb_init, valkyriefb_setup },
245 #ifdef CONFIG_FB_CT65550
246 { "chipsfb", chips_init, NULL },
248 #ifdef CONFIG_FB_IMSTT
249 { "imsttfb", imsttfb_init, imsttfb_setup },
251 #ifdef CONFIG_FB_S3TRIO
252 { "s3triofb", s3triofb_init, NULL },
255 { "fm2fb", fm2fb_init, fm2fb_setup },
258 { "sisfb", sisfb_init, sisfb_setup },
260 #ifdef CONFIG_FB_TRIDENT
261 { "tridentfb", tridentfb_init, tridentfb_setup },
263 #ifdef CONFIG_FB_I810
264 { "i810fb", i810fb_init, i810fb_setup },
267 { "stifb", stifb_init, stifb_setup },
270 { "ffb", ffb_init, ffb_setup },
273 { "cg6fb", cg6_init, cg6_setup },
276 { "cg3fb", cg3_init, cg3_setup },
279 { "bw2fb", bw2_init, bw2_setup },
281 #ifdef CONFIG_FB_CG14
282 { "cg14fb", cg14_init, cg14_setup },
284 #ifdef CONFIG_FB_P9100
285 { "p9100fb", p9100_init, p9100_setup },
288 { "tcxfb", tcx_init, tcx_setup },
291 { "leofb", leo_init, leo_setup },
295 * Generic drivers that are used as fallbacks
297 * These depend on resource management and must be initialized
298 * _after_ all other frame buffer devices that use resource
303 { "offb", offb_init, NULL },
305 #ifdef CONFIG_FB_VESA
306 { "vesafb", vesafb_init, vesafb_setup },
310 * Chipset specific drivers that don't use resource management (yet)
313 #ifdef CONFIG_FB_SGIVW
314 { "sgivwfb", sgivwfb_init, sgivwfb_setup },
317 { "gbefb", gbefb_init, gbefb_setup },
319 #ifdef CONFIG_FB_ACORN
320 { "acornfb", acornfb_init, acornfb_setup },
322 #ifdef CONFIG_FB_ATARI
323 { "atafb", atafb_init, atafb_setup },
326 { "macfb", macfb_init, macfb_setup },
329 { "hgafb", hgafb_init, hgafb_setup },
332 { "igafb", igafb_init, igafb_setup },
335 { "apollofb", dnfb_init, NULL },
338 { "q40fb", q40fb_init, NULL },
341 { "tgafb", tgafb_init, tgafb_setup },
343 #ifdef CONFIG_FB_HP300
344 { "hpfb", hpfb_init, NULL },
346 #ifdef CONFIG_FB_G364
347 { "g364fb", g364fb_init, NULL },
349 #ifdef CONFIG_FB_SA1100
350 { "sa1100fb", sa1100fb_init, NULL },
353 { "pxafb", pxafb_init, pxafb_setup },
355 #ifdef CONFIG_FB_SUN3
356 { "sun3fb", sun3fb_init, sun3fb_setup },
359 { "hitfb", hitfb_init, NULL },
361 #ifdef CONFIG_FB_TX3912
362 { "tx3912fb", tx3912fb_init, tx3912fb_setup },
364 #ifdef CONFIG_FB_E1355
365 { "e1355fb", e1355fb_init, e1355fb_setup },
367 #ifdef CONFIG_FB_PVR2
368 { "pvr2fb", pvr2fb_init, pvr2fb_setup },
370 #ifdef CONFIG_FB_PMAG_BA
371 { "pmagbafb", pmagbafb_init, NULL },
373 #ifdef CONFIG_FB_PMAGB_B
374 { "pmagbbfb", pmagbbfb_init, NULL },
376 #ifdef CONFIG_FB_MAXINE
377 { "maxinefb", maxinefb_init, NULL },
379 #ifdef CONFIG_FB_VOODOO1
380 { "sstfb", sstfb_init, sstfb_setup },
382 #ifdef CONFIG_FB_KYRO
383 { "kyrofb", kyrofb_init, kyrofb_setup },
385 #ifdef CONFIG_FB_68328
386 { "68328fb", mc68x328fb_init, mc68x328fb_setup },
390 * Generic drivers that don't use resource management (yet)
393 #ifdef CONFIG_FB_VGA16
394 { "vga16fb", vga16fb_init, vga16fb_setup },
397 #ifdef CONFIG_GSP_RESOLVER
398 /* Not a real frame buffer device... */
399 { "resolverfb", NULL, resolver_video_setup },
402 #ifdef CONFIG_FB_VIRTUAL
404 * Vfb must be last to avoid that it becomes your primary display if
405 * other display devices are present
407 { "vfb", vfb_init, vfb_setup },
411 #define NUM_FB_DRIVERS (sizeof(fb_drivers)/sizeof(*fb_drivers))
412 #define FBPIXMAPSIZE 16384
414 extern const char *global_mode_option;
416 static initcall_t pref_init_funcs[FB_MAX];
417 static int num_pref_init_funcs __initdata = 0;
418 static struct notifier_block *fb_notifier_list;
419 struct fb_info *registered_fb[FB_MAX];
420 int num_registered_fb;
423 static int ofonly __initdata = 0;
429 static u8 fb_sys_inbuf(struct fb_info *info, u8 *src)
434 static void fb_sys_outbuf(struct fb_info *info, u8 *dst,
435 u8 *src, unsigned int size)
437 memcpy(dst, src, size);
440 void fb_move_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
441 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
446 for (i = height; i--; ) {
447 buf->outbuf(info, dst, src, s_pitch);
453 void fb_move_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf,
454 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
455 u32 height, u32 shift_high, u32 shift_low,
458 u8 mask = (u8) (0xfff << shift_high), tmp;
461 for (i = height; i--; ) {
462 for (j = 0; j < idx; j++) {
463 tmp = buf->inbuf(info, dst+j);
465 tmp |= *src >> shift_low;
466 buf->outbuf(info, dst+j, &tmp, 1);
467 tmp = *src << shift_high;
468 buf->outbuf(info, dst+j+1, &tmp, 1);
471 tmp = buf->inbuf(info, dst+idx);
473 tmp |= *src >> shift_low;
474 buf->outbuf(info, dst+idx, &tmp, 1);
475 if (shift_high < mod) {
476 tmp = *src << shift_high;
477 buf->outbuf(info, dst+idx+1, &tmp, 1);
485 * we need to lock this section since fb_cursor
486 * may use fb_imageblit()
488 char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size)
490 u32 align = buf->buf_align - 1, offset;
491 char *addr = buf->addr;
493 /* If IO mapped, we need to sync before access, no sharing of
496 if (buf->flags & FB_PIXMAP_IO) {
497 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
498 info->fbops->fb_sync(info);
502 /* See if we fit in the remaining pixmap space */
503 offset = buf->offset + align;
505 if (offset + size > buf->size) {
506 /* We do not fit. In order to be able to re-use the buffer,
507 * we must ensure no asynchronous DMA'ing or whatever operation
508 * is in progress, we sync for that.
510 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
511 info->fbops->fb_sync(info);
514 buf->offset = offset + size;
521 #include <linux/linux_logo.h>
523 static inline unsigned safe_shift(unsigned d, int n)
525 return n < 0 ? d >> -n : d << n;
528 static void __init fb_set_logocmap(struct fb_info *info,
529 const struct linux_logo *logo)
531 struct fb_cmap palette_cmap;
532 u16 palette_green[16];
533 u16 palette_blue[16];
536 const unsigned char *clut = logo->clut;
538 palette_cmap.start = 0;
539 palette_cmap.len = 16;
540 palette_cmap.red = palette_red;
541 palette_cmap.green = palette_green;
542 palette_cmap.blue = palette_blue;
543 palette_cmap.transp = NULL;
545 for (i = 0; i < logo->clutsize; i += n) {
546 n = logo->clutsize - i;
547 /* palette_cmap provides space for only 16 colors at once */
550 palette_cmap.start = 32 + i;
551 palette_cmap.len = n;
552 for (j = 0; j < n; ++j) {
553 palette_cmap.red[j] = clut[0] << 8 | clut[0];
554 palette_cmap.green[j] = clut[1] << 8 | clut[1];
555 palette_cmap.blue[j] = clut[2] << 8 | clut[2];
558 fb_set_cmap(&palette_cmap, 1, info);
562 static void __init fb_set_logo_truepalette(struct fb_info *info,
563 const struct linux_logo *logo,
566 unsigned char mask[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
567 unsigned char redmask, greenmask, bluemask;
568 int redshift, greenshift, blueshift;
570 const unsigned char *clut = logo->clut;
573 * We have to create a temporary palette since console palette is only
576 /* Bug: Doesn't obey msb_right ... (who needs that?) */
577 redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8];
578 greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8];
579 bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8];
580 redshift = info->var.red.offset - (8 - info->var.red.length);
581 greenshift = info->var.green.offset - (8 - info->var.green.length);
582 blueshift = info->var.blue.offset - (8 - info->var.blue.length);
584 for ( i = 0; i < logo->clutsize; i++) {
585 palette[i+32] = (safe_shift((clut[0] & redmask), redshift) |
586 safe_shift((clut[1] & greenmask), greenshift) |
587 safe_shift((clut[2] & bluemask), blueshift));
592 static void __init fb_set_logo_directpalette(struct fb_info *info,
593 const struct linux_logo *logo,
596 int redshift, greenshift, blueshift;
599 redshift = info->var.red.offset;
600 greenshift = info->var.green.offset;
601 blueshift = info->var.blue.offset;
603 for (i = 32; i < logo->clutsize; i++)
604 palette[i] = i << redshift | i << greenshift | i << blueshift;
607 static void __init fb_set_logo(struct fb_info *info,
608 const struct linux_logo *logo, u8 *dst,
612 const u8 *src = logo->data;
617 for (i = 0; i < logo->height; i++)
618 for (j = 0; j < logo->width; src++) {
621 if (j < logo->width) {
622 *dst++ = *src & 0x0f;
630 for (i = 0; i < logo->height; i++) {
633 for (j = 0; j < logo->width; j++) {
634 *dst++ = (d >> shift) & 1;
635 shift = (shift-1) & 7;
645 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
646 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
647 * the visual format and color depth of the framebuffer, the DAC, the
648 * pseudo_palette, and the logo data will be adjusted accordingly.
650 * Case 1 - linux_logo_clut224:
651 * Color exceeds the number of console colors (16), thus we set the hardware DAC
652 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
654 * For visuals that require color info from the pseudo_palette, we also construct
655 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
658 * Case 2 - linux_logo_vga16:
659 * The number of colors just matches the console colors, thus there is no need
660 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
661 * each byte contains color information for two pixels (upper and lower nibble).
662 * To be consistent with fb_imageblit() usage, we therefore separate the two
663 * nibbles into separate bytes. The "depth" flag will be set to 4.
665 * Case 3 - linux_logo_mono:
666 * This is similar with Case 2. Each byte contains information for 8 pixels.
667 * We isolate each bit and expand each into a byte. The "depth" flag will
670 static struct logo_data {
672 int needs_directpalette;
673 int needs_truepalette;
675 const struct linux_logo *logo;
678 int fb_prepare_logo(struct fb_info *info)
680 memset(&fb_logo, 0, sizeof(struct logo_data));
682 switch (info->fix.visual) {
683 case FB_VISUAL_TRUECOLOR:
684 if (info->var.bits_per_pixel >= 8)
685 fb_logo.needs_truepalette = 1;
687 case FB_VISUAL_DIRECTCOLOR:
688 if (info->var.bits_per_pixel >= 24) {
689 fb_logo.needs_directpalette = 1;
690 fb_logo.needs_cmapreset = 1;
693 case FB_VISUAL_PSEUDOCOLOR:
694 fb_logo.needs_cmapreset = 1;
698 /* Return if no suitable logo was found */
699 fb_logo.logo = fb_find_logo(info->var.bits_per_pixel);
701 if (!fb_logo.logo || fb_logo.logo->height > info->var.yres) {
705 /* What depth we asked for might be different from what we get */
706 if (fb_logo.logo->type == LINUX_LOGO_CLUT224)
708 else if (fb_logo.logo->type == LINUX_LOGO_VGA16)
712 return fb_logo.logo->height;
715 int fb_show_logo(struct fb_info *info)
717 u32 *palette = NULL, *saved_pseudo_palette = NULL;
718 unsigned char *logo_new = NULL;
719 struct fb_image image;
722 /* Return if the frame buffer is not mapped or suspended */
723 if (fb_logo.logo == NULL || info->state != FBINFO_STATE_RUNNING)
726 image.depth = fb_logo.depth;
727 image.data = fb_logo.logo->data;
729 if (fb_logo.needs_cmapreset)
730 fb_set_logocmap(info, fb_logo.logo);
732 if (fb_logo.needs_truepalette ||
733 fb_logo.needs_directpalette) {
734 palette = kmalloc(256 * 4, GFP_KERNEL);
738 if (fb_logo.needs_truepalette)
739 fb_set_logo_truepalette(info, fb_logo.logo, palette);
741 fb_set_logo_directpalette(info, fb_logo.logo, palette);
743 saved_pseudo_palette = info->pseudo_palette;
744 info->pseudo_palette = palette;
747 if (fb_logo.depth == 4) {
748 logo_new = kmalloc(fb_logo.logo->width * fb_logo.logo->height,
750 if (logo_new == NULL) {
753 if (saved_pseudo_palette)
754 info->pseudo_palette = saved_pseudo_palette;
757 image.data = logo_new;
758 fb_set_logo(info, fb_logo.logo, logo_new, fb_logo.depth);
761 image.width = fb_logo.logo->width;
762 image.height = fb_logo.logo->height;
765 for (x = 0; x < num_online_cpus() * (fb_logo.logo->width + 8) &&
766 x <= info->var.xres-fb_logo.logo->width; x += (fb_logo.logo->width + 8)) {
768 info->fbops->fb_imageblit(info, &image);
773 if (saved_pseudo_palette != NULL)
774 info->pseudo_palette = saved_pseudo_palette;
775 if (logo_new != NULL)
777 return fb_logo.logo->height;
780 int fb_prepare_logo(struct fb_info *info) { return 0; }
781 int fb_show_logo(struct fb_info *info) { return 0; }
782 #endif /* CONFIG_LOGO */
784 static int fbmem_read_proc(char *buf, char **start, off_t offset,
785 int len, int *eof, void *private)
791 for (fi = registered_fb; fi < ®istered_fb[FB_MAX] && len < 4000; fi++)
793 clen += sprintf(buf + clen, "%d %s\n",
796 *start = buf + offset;
801 return clen < len ? clen : len;
805 fb_read(struct file *file, char *buf, size_t count, loff_t *ppos)
807 unsigned long p = *ppos;
808 struct inode *inode = file->f_dentry->d_inode;
809 int fbidx = iminor(inode);
810 struct fb_info *info = registered_fb[fbidx];
812 if (!info || ! info->screen_base)
815 if (info->state != FBINFO_STATE_RUNNING)
818 if (info->fbops->fb_read)
819 return info->fbops->fb_read(file, buf, count, ppos);
821 if (p >= info->fix.smem_len)
823 if (count >= info->fix.smem_len)
824 count = info->fix.smem_len;
825 if (count + p > info->fix.smem_len)
826 count = info->fix.smem_len - p;
827 if (info->fbops->fb_sync)
828 info->fbops->fb_sync(info);
832 base_addr = info->screen_base;
833 count -= copy_to_user(buf, base_addr+p, count);
842 fb_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
844 unsigned long p = *ppos;
845 struct inode *inode = file->f_dentry->d_inode;
846 int fbidx = iminor(inode);
847 struct fb_info *info = registered_fb[fbidx];
850 if (!info || !info->screen_base)
853 if (info->state != FBINFO_STATE_RUNNING)
856 if (info->fbops->fb_write)
857 return info->fbops->fb_write(file, buf, count, ppos);
859 if (p > info->fix.smem_len)
861 if (count >= info->fix.smem_len)
862 count = info->fix.smem_len;
864 if (count + p > info->fix.smem_len) {
865 count = info->fix.smem_len - p;
868 if (info->fbops->fb_sync)
869 info->fbops->fb_sync(info);
873 base_addr = info->screen_base;
874 count -= copy_from_user(base_addr+p, buf, count);
884 static void try_to_load(int fb)
886 request_module("fb%d", fb);
888 #endif /* CONFIG_KMOD */
891 fb_load_cursor_image(struct fb_info *info)
893 unsigned int width = (info->cursor.image.width + 7) >> 3;
894 u8 *data = (u8 *) info->cursor.image.data;
896 info->sprite.outbuf(info, info->sprite.addr, data, width);
900 fb_cursor(struct fb_info *info, struct fb_cursor *sprite)
902 struct fb_cursor cursor;
905 if (copy_from_user(&cursor, sprite, sizeof(struct fb_cursor)))
908 if (cursor.set & FB_CUR_SETCUR)
909 info->cursor.enable = 1;
911 if (cursor.set & FB_CUR_SETCMAP) {
912 err = fb_copy_cmap(&cursor.image.cmap, &sprite->image.cmap, 1);
917 if (cursor.set & FB_CUR_SETSHAPE) {
918 int size = ((cursor.image.width + 7) >> 3) * cursor.image.height;
919 if ((cursor.image.height != info->cursor.image.height) ||
920 (cursor.image.width != info->cursor.image.width))
921 cursor.set |= FB_CUR_SETSIZE;
923 cursor.image.data = kmalloc(size, GFP_KERNEL);
924 if (!cursor.image.data)
927 cursor.mask = kmalloc(size, GFP_KERNEL);
929 kfree(cursor.image.data);
933 if (copy_from_user(cursor.image.data, sprite->image.data, size) ||
934 copy_from_user(cursor.mask, sprite->mask, size)) {
935 kfree(cursor.image.data);
940 info->cursor.set = cursor.set;
941 info->cursor.rop = cursor.rop;
942 err = info->fbops->fb_cursor(info, &cursor);
947 fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
949 int xoffset = var->xoffset;
950 int yoffset = var->yoffset;
953 if (xoffset < 0 || yoffset < 0 || !info->fbops->fb_pan_display ||
954 xoffset + info->var.xres > info->var.xres_virtual ||
955 yoffset + info->var.yres > info->var.yres_virtual)
957 if ((err = info->fbops->fb_pan_display(var, info)))
959 info->var.xoffset = var->xoffset;
960 info->var.yoffset = var->yoffset;
961 if (var->vmode & FB_VMODE_YWRAP)
962 info->var.vmode |= FB_VMODE_YWRAP;
964 info->var.vmode &= ~FB_VMODE_YWRAP;
969 fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
973 if ((var->activate & FB_ACTIVATE_FORCE) ||
974 memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
975 if (!info->fbops->fb_check_var) {
980 if ((err = info->fbops->fb_check_var(var, info)))
983 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
986 if (info->fbops->fb_set_par)
987 info->fbops->fb_set_par(info);
989 fb_pan_display(info, &info->var);
991 fb_set_cmap(&info->cmap, 1, info);
993 notifier_call_chain(&fb_notifier_list, FB_EVENT_MODE_CHANGE, info);
1000 fb_blank(struct fb_info *info, int blank)
1002 /* ??? Variable sized stack allocation. */
1003 u16 black[info->cmap.len];
1004 struct fb_cmap cmap;
1006 if (info->fbops->fb_blank && !info->fbops->fb_blank(blank, info))
1009 memset(black, 0, info->cmap.len * sizeof(u16));
1010 cmap.red = cmap.green = cmap.blue = black;
1011 cmap.transp = info->cmap.transp ? black : NULL;
1012 cmap.start = info->cmap.start;
1013 cmap.len = info->cmap.len;
1016 return fb_set_cmap(&cmap, 1, info);
1020 fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1023 int fbidx = iminor(inode);
1024 struct fb_info *info = registered_fb[fbidx];
1025 struct fb_ops *fb = info->fbops;
1026 struct fb_var_screeninfo var;
1027 struct fb_fix_screeninfo fix;
1028 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
1029 struct fb_con2fbmap con2fb;
1031 struct fb_cmap cmap;
1037 case FBIOGET_VSCREENINFO:
1038 return copy_to_user((void *) arg, &info->var,
1039 sizeof(var)) ? -EFAULT : 0;
1040 case FBIOPUT_VSCREENINFO:
1041 if (copy_from_user(&var, (void *) arg, sizeof(var)))
1043 acquire_console_sem();
1044 i = fb_set_var(info, &var);
1045 release_console_sem();
1047 if (copy_to_user((void *) arg, &var, sizeof(var)))
1050 case FBIOGET_FSCREENINFO:
1051 return copy_to_user((void *) arg, &info->fix,
1052 sizeof(fix)) ? -EFAULT : 0;
1054 if (copy_from_user(&cmap, (void *) arg, sizeof(cmap)))
1056 return (fb_set_cmap(&cmap, 0, info));
1058 if (copy_from_user(&cmap, (void *) arg, sizeof(cmap)))
1060 return (fb_copy_cmap(&info->cmap, &cmap, 2));
1061 case FBIOPAN_DISPLAY:
1062 if (copy_from_user(&var, (void *) arg, sizeof(var)))
1064 acquire_console_sem();
1065 i = fb_pan_display(info, &var);
1066 release_console_sem();
1069 if (copy_to_user((void *) arg, &var, sizeof(var)))
1073 acquire_console_sem();
1074 i = fb_cursor(info, (struct fb_cursor *) arg);
1075 release_console_sem();
1077 #ifdef CONFIG_FRAMEBUFFER_CONSOLE
1078 case FBIOGET_CON2FBMAP:
1079 if (copy_from_user(&con2fb, (void *)arg, sizeof(con2fb)))
1081 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
1083 con2fb.framebuffer = con2fb_map[con2fb.console-1];
1084 return copy_to_user((void *)arg, &con2fb,
1085 sizeof(con2fb)) ? -EFAULT : 0;
1086 case FBIOPUT_CON2FBMAP:
1087 if (copy_from_user(&con2fb, (void *)arg, sizeof(con2fb)))
1089 if (con2fb.console < 0 || con2fb.console > MAX_NR_CONSOLES)
1091 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
1094 if (!registered_fb[con2fb.framebuffer])
1095 try_to_load(con2fb.framebuffer);
1096 #endif /* CONFIG_KMOD */
1097 if (!registered_fb[con2fb.framebuffer])
1099 if (con2fb.console != 0)
1100 set_con2fb_map(con2fb.console-1, con2fb.framebuffer);
1104 #endif /* CONFIG_FRAMEBUFFER_CONSOLE */
1106 acquire_console_sem();
1107 i = fb_blank(info, arg);
1108 release_console_sem();
1111 if (fb->fb_ioctl == NULL)
1113 return fb->fb_ioctl(inode, file, cmd, arg, info);
1118 fb_mmap(struct file *file, struct vm_area_struct * vma)
1120 int fbidx = iminor(file->f_dentry->d_inode);
1121 struct fb_info *info = registered_fb[fbidx];
1122 struct fb_ops *fb = info->fbops;
1124 #if !defined(__sparc__) || defined(__sparc_v9__)
1125 unsigned long start;
1129 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1131 off = vma->vm_pgoff << PAGE_SHIFT;
1137 res = fb->fb_mmap(info, file, vma);
1142 #if defined(__sparc__) && !defined(__sparc_v9__)
1143 /* Should never get here, all fb drivers should have their own
1150 /* frame buffer memory */
1151 start = info->fix.smem_start;
1152 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
1154 /* memory mapped io */
1156 if (info->var.accel_flags) {
1160 start = info->fix.mmio_start;
1161 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
1165 if ((vma->vm_end - vma->vm_start + off) > len)
1168 vma->vm_pgoff = off >> PAGE_SHIFT;
1169 /* This is an IO map - tell maydump to skip this VMA */
1170 vma->vm_flags |= VM_IO;
1171 #if defined(__sparc_v9__)
1172 vma->vm_flags |= (VM_SHM | VM_LOCKED);
1173 if (io_remap_page_range(vma, vma->vm_start, off,
1174 vma->vm_end - vma->vm_start, vma->vm_page_prot, 0))
1177 #if defined(__mc68000__)
1178 #if defined(CONFIG_SUN3)
1179 pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
1180 #elif defined(CONFIG_MMU)
1181 if (CPU_IS_020_OR_030)
1182 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
1183 if (CPU_IS_040_OR_060) {
1184 pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
1185 /* Use no-cache mode, serialized */
1186 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
1189 #elif defined(__powerpc__)
1190 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
1191 #elif defined(__alpha__)
1192 /* Caching is off in the I/O space quadrant by design. */
1193 #elif defined(__i386__) || defined(__x86_64__)
1194 if (boot_cpu_data.x86 > 3)
1195 pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
1196 #elif defined(__mips__)
1197 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1198 #elif defined(__hppa__)
1199 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
1200 #elif defined(__ia64__) || defined(__arm__) || defined(__sh__)
1201 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1203 #warning What do we have to do here??
1205 if (io_remap_page_range(vma, vma->vm_start, off,
1206 vma->vm_end - vma->vm_start, vma->vm_page_prot))
1208 #endif /* !__sparc_v9__ */
1210 #endif /* !sparc32 */
1214 fb_open(struct inode *inode, struct file *file)
1216 int fbidx = iminor(inode);
1217 struct fb_info *info;
1220 if (fbidx >= FB_MAX)
1223 if (!(info = registered_fb[fbidx]))
1225 #endif /* CONFIG_KMOD */
1226 if (!(info = registered_fb[fbidx]))
1228 if (!try_module_get(info->fbops->owner))
1230 if (info->fbops->fb_open) {
1231 res = info->fbops->fb_open(info,1);
1233 module_put(info->fbops->owner);
1239 fb_release(struct inode *inode, struct file *file)
1241 int fbidx = iminor(inode);
1242 struct fb_info *info;
1245 info = registered_fb[fbidx];
1246 if (info->fbops->fb_release)
1247 info->fbops->fb_release(info,1);
1248 module_put(info->fbops->owner);
1253 static struct file_operations fb_fops = {
1254 .owner = THIS_MODULE,
1260 .release = fb_release,
1261 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1262 .get_unmapped_area = get_fb_unmapped_area,
1266 static struct class_simple *fb_class;
1269 * register_framebuffer - registers a frame buffer device
1270 * @fb_info: frame buffer info structure
1272 * Registers a frame buffer device @fb_info.
1274 * Returns negative errno on error, or zero for success.
1279 register_framebuffer(struct fb_info *fb_info)
1282 struct class_device *c;
1284 if (num_registered_fb == FB_MAX)
1286 num_registered_fb++;
1287 for (i = 0 ; i < FB_MAX; i++)
1288 if (!registered_fb[i])
1292 c = class_simple_device_add(fb_class, MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
1295 printk(KERN_WARNING "Unable to create class_device for framebuffer %d; errno = %ld\n", i, PTR_ERR(c));
1298 if (fb_info->pixmap.addr == NULL) {
1299 fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1300 if (fb_info->pixmap.addr) {
1301 fb_info->pixmap.size = FBPIXMAPSIZE;
1302 fb_info->pixmap.buf_align = 1;
1303 fb_info->pixmap.scan_align = 1;
1304 fb_info->pixmap.access_align = 4;
1305 fb_info->pixmap.flags = FB_PIXMAP_DEFAULT;
1308 fb_info->pixmap.offset = 0;
1309 if (fb_info->pixmap.outbuf == NULL)
1310 fb_info->pixmap.outbuf = fb_sys_outbuf;
1311 if (fb_info->pixmap.inbuf == NULL)
1312 fb_info->pixmap.inbuf = fb_sys_inbuf;
1314 if (fb_info->sprite.addr == NULL) {
1315 fb_info->sprite.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1316 if (fb_info->sprite.addr) {
1317 fb_info->sprite.size = FBPIXMAPSIZE;
1318 fb_info->sprite.buf_align = 1;
1319 fb_info->sprite.scan_align = 1;
1320 fb_info->sprite.access_align = 4;
1321 fb_info->sprite.flags = FB_PIXMAP_DEFAULT;
1324 fb_info->sprite.offset = 0;
1325 if (fb_info->sprite.outbuf == NULL)
1326 fb_info->sprite.outbuf = fb_sys_outbuf;
1327 if (fb_info->sprite.inbuf == NULL)
1328 fb_info->sprite.inbuf = fb_sys_inbuf;
1330 registered_fb[i] = fb_info;
1332 devfs_mk_cdev(MKDEV(FB_MAJOR, i),
1333 S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
1339 * unregister_framebuffer - releases a frame buffer device
1340 * @fb_info: frame buffer info structure
1342 * Unregisters a frame buffer device @fb_info.
1344 * Returns negative errno on error, or zero for success.
1349 unregister_framebuffer(struct fb_info *fb_info)
1354 if (!registered_fb[i])
1356 devfs_remove("fb/%d", i);
1358 if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
1359 kfree(fb_info->pixmap.addr);
1360 if (fb_info->sprite.addr && (fb_info->sprite.flags & FB_PIXMAP_DEFAULT))
1361 kfree(fb_info->sprite.addr);
1362 registered_fb[i]=NULL;
1363 num_registered_fb--;
1364 class_simple_device_remove(MKDEV(FB_MAJOR, i));
1369 * fb_register_client - register a client notifier
1370 * @nb: notifier block to callback on events
1372 int fb_register_client(struct notifier_block *nb)
1374 return notifier_chain_register(&fb_notifier_list, nb);
1378 * fb_unregister_client - unregister a client notifier
1379 * @nb: notifier block to callback on events
1381 int fb_unregister_client(struct notifier_block *nb)
1383 return notifier_chain_unregister(&fb_notifier_list, nb);
1387 * fb_set_suspend - low level driver signals suspend
1388 * @info: framebuffer affected
1389 * @state: 0 = resuming, !=0 = suspending
1391 * This is meant to be used by low level drivers to
1392 * signal suspend/resume to the core & clients.
1393 * It must be called with the console semaphore held
1395 void fb_set_suspend(struct fb_info *info, int state)
1398 notifier_call_chain(&fb_notifier_list, FB_EVENT_SUSPEND, info);
1399 info->state = FBINFO_STATE_SUSPENDED;
1401 info->state = FBINFO_STATE_RUNNING;
1402 notifier_call_chain(&fb_notifier_list, FB_EVENT_RESUME, info);
1407 * fbmem_init - init frame buffer subsystem
1409 * Initialize the frame buffer subsystem.
1411 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1420 create_proc_read_entry("fb", 0, 0, fbmem_read_proc, NULL);
1423 if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
1424 printk("unable to get major %d for fb devs\n", FB_MAJOR);
1426 fb_class = class_simple_create(THIS_MODULE, "graphics");
1427 if (IS_ERR(fb_class)) {
1428 printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
1440 * Probe for all builtin frame buffer devices
1442 for (i = 0; i < num_pref_init_funcs; i++)
1443 pref_init_funcs[i]();
1445 for (i = 0; i < NUM_FB_DRIVERS; i++)
1446 if (fb_drivers[i].init)
1447 fb_drivers[i].init();
1452 * video_setup - process command line options
1453 * @options: string of options
1455 * Process command line options for frame buffer subsystem.
1457 * NOTE: This function is a __setup and __init function.
1463 int __init video_setup(char *options)
1467 if (!options || !*options)
1471 if (!strcmp(options, "ofonly")) {
1477 if (num_pref_init_funcs == FB_MAX)
1480 for (i = 0; i < NUM_FB_DRIVERS; i++) {
1481 j = strlen(fb_drivers[i].name);
1482 if (!strncmp(options, fb_drivers[i].name, j) &&
1483 options[j] == ':') {
1484 if (!strcmp(options+j+1, "off"))
1485 fb_drivers[i].init = NULL;
1487 if (fb_drivers[i].init) {
1488 pref_init_funcs[num_pref_init_funcs++] =
1490 fb_drivers[i].init = NULL;
1492 if (fb_drivers[i].setup)
1493 fb_drivers[i].setup(options+j+1);
1500 * If we get here no fb was specified.
1501 * We consider the argument to be a global video mode option.
1503 global_mode_option = options;
1507 __setup("video=", video_setup);
1510 * Visible symbols for modules
1513 EXPORT_SYMBOL(register_framebuffer);
1514 EXPORT_SYMBOL(unregister_framebuffer);
1515 EXPORT_SYMBOL(num_registered_fb);
1516 EXPORT_SYMBOL(registered_fb);
1517 EXPORT_SYMBOL(fb_prepare_logo);
1518 EXPORT_SYMBOL(fb_show_logo);
1519 EXPORT_SYMBOL(fb_set_var);
1520 EXPORT_SYMBOL(fb_blank);
1521 EXPORT_SYMBOL(fb_pan_display);
1522 EXPORT_SYMBOL(fb_get_buffer_offset);
1523 EXPORT_SYMBOL(fb_move_buf_unaligned);
1524 EXPORT_SYMBOL(fb_move_buf_aligned);
1525 EXPORT_SYMBOL(fb_load_cursor_image);
1526 EXPORT_SYMBOL(fb_set_suspend);
1527 EXPORT_SYMBOL(fb_register_client);
1528 EXPORT_SYMBOL(fb_unregister_client);
1530 MODULE_LICENSE("GPL");