2 * linux/drivers/video/fbmem.c
4 * Copyright (C) 1994 Martin Schaller
6 * 2001 - Documented with DocBook
7 * - Brad Douglas <brad@neruo.com>
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive
14 #include <linux/config.h>
15 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/smp_lock.h>
21 #include <linux/kernel.h>
22 #include <linux/major.h>
23 #include <linux/slab.h>
25 #include <linux/mman.h>
26 #include <linux/tty.h>
27 #include <linux/init.h>
28 #include <linux/linux_logo.h>
29 #include <linux/proc_fs.h>
30 #include <linux/console.h>
32 #include <linux/kmod.h>
34 #include <linux/devfs_fs_kernel.h>
35 #include <linux/err.h>
36 #include <linux/kernel.h>
37 #include <linux/device.h>
38 #include <linux/efi.h>
40 #if defined(__mc68000__) || defined(CONFIG_APUS)
41 #include <asm/setup.h>
45 #include <asm/uaccess.h>
47 #include <asm/pgtable.h>
52 * Frame buffer device initialization and setup routines
55 #define FBPIXMAPSIZE (1024 * 8)
57 static struct notifier_block *fb_notifier_list;
58 struct fb_info *registered_fb[FB_MAX];
59 int num_registered_fb;
65 int fb_get_color_depth(struct fb_info *info)
67 struct fb_var_screeninfo *var = &info->var;
69 if (var->green.length == var->blue.length &&
70 var->green.length == var->red.length &&
71 !var->green.offset && !var->blue.offset &&
73 return var->green.length;
75 return (var->green.length + var->red.length +
78 EXPORT_SYMBOL(fb_get_color_depth);
83 void fb_iomove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
84 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
89 for (i = height; i--; ) {
90 buf->outbuf(info, dst, src, s_pitch);
96 void fb_sysmove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
97 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
102 for (i = height; i--; ) {
103 for (j = 0; j < s_pitch; j++)
110 void fb_iomove_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf,
111 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
112 u32 height, u32 shift_high, u32 shift_low,
115 u8 mask = (u8) (0xfff << shift_high), tmp;
118 for (i = height; i--; ) {
119 for (j = 0; j < idx; j++) {
120 tmp = buf->inbuf(info, dst+j);
122 tmp |= *src >> shift_low;
123 buf->outbuf(info, dst+j, &tmp, 1);
124 tmp = *src << shift_high;
125 buf->outbuf(info, dst+j+1, &tmp, 1);
128 tmp = buf->inbuf(info, dst+idx);
130 tmp |= *src >> shift_low;
131 buf->outbuf(info, dst+idx, &tmp, 1);
132 if (shift_high < mod) {
133 tmp = *src << shift_high;
134 buf->outbuf(info, dst+idx+1, &tmp, 1);
141 void fb_sysmove_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf,
142 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
143 u32 height, u32 shift_high, u32 shift_low,
146 u8 mask = (u8) (0xfff << shift_high), tmp;
149 for (i = height; i--; ) {
150 for (j = 0; j < idx; j++) {
153 tmp |= *src >> shift_low;
155 tmp = *src << shift_high;
161 tmp |= *src >> shift_low;
163 if (shift_high < mod) {
164 tmp = *src << shift_high;
173 * we need to lock this section since fb_cursor
174 * may use fb_imageblit()
176 char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size)
178 u32 align = buf->buf_align - 1, offset;
179 char *addr = buf->addr;
181 /* If IO mapped, we need to sync before access, no sharing of
184 if (buf->flags & FB_PIXMAP_IO) {
185 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
186 info->fbops->fb_sync(info);
190 /* See if we fit in the remaining pixmap space */
191 offset = buf->offset + align;
193 if (offset + size > buf->size) {
194 /* We do not fit. In order to be able to re-use the buffer,
195 * we must ensure no asynchronous DMA'ing or whatever operation
196 * is in progress, we sync for that.
198 if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
199 info->fbops->fb_sync(info);
202 buf->offset = offset + size;
209 #include <linux/linux_logo.h>
211 static inline unsigned safe_shift(unsigned d, int n)
213 return n < 0 ? d >> -n : d << n;
216 static void fb_set_logocmap(struct fb_info *info,
217 const struct linux_logo *logo)
219 struct fb_cmap palette_cmap;
220 u16 palette_green[16];
221 u16 palette_blue[16];
224 const unsigned char *clut = logo->clut;
226 palette_cmap.start = 0;
227 palette_cmap.len = 16;
228 palette_cmap.red = palette_red;
229 palette_cmap.green = palette_green;
230 palette_cmap.blue = palette_blue;
231 palette_cmap.transp = NULL;
233 for (i = 0; i < logo->clutsize; i += n) {
234 n = logo->clutsize - i;
235 /* palette_cmap provides space for only 16 colors at once */
238 palette_cmap.start = 32 + i;
239 palette_cmap.len = n;
240 for (j = 0; j < n; ++j) {
241 palette_cmap.red[j] = clut[0] << 8 | clut[0];
242 palette_cmap.green[j] = clut[1] << 8 | clut[1];
243 palette_cmap.blue[j] = clut[2] << 8 | clut[2];
246 fb_set_cmap(&palette_cmap, info);
250 static void fb_set_logo_truepalette(struct fb_info *info,
251 const struct linux_logo *logo,
254 unsigned char mask[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
255 unsigned char redmask, greenmask, bluemask;
256 int redshift, greenshift, blueshift;
258 const unsigned char *clut = logo->clut;
261 * We have to create a temporary palette since console palette is only
264 /* Bug: Doesn't obey msb_right ... (who needs that?) */
265 redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8];
266 greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8];
267 bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8];
268 redshift = info->var.red.offset - (8 - info->var.red.length);
269 greenshift = info->var.green.offset - (8 - info->var.green.length);
270 blueshift = info->var.blue.offset - (8 - info->var.blue.length);
272 for ( i = 0; i < logo->clutsize; i++) {
273 palette[i+32] = (safe_shift((clut[0] & redmask), redshift) |
274 safe_shift((clut[1] & greenmask), greenshift) |
275 safe_shift((clut[2] & bluemask), blueshift));
280 static void fb_set_logo_directpalette(struct fb_info *info,
281 const struct linux_logo *logo,
284 int redshift, greenshift, blueshift;
287 redshift = info->var.red.offset;
288 greenshift = info->var.green.offset;
289 blueshift = info->var.blue.offset;
291 for (i = 32; i < logo->clutsize; i++)
292 palette[i] = i << redshift | i << greenshift | i << blueshift;
295 static void fb_set_logo(struct fb_info *info,
296 const struct linux_logo *logo, u8 *dst,
300 const u8 *src = logo->data;
301 u8 d, xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0;
303 if (fb_get_color_depth(info) == 3)
308 for (i = 0; i < logo->height; i++)
309 for (j = 0; j < logo->width; src++) {
312 if (j < logo->width) {
313 *dst++ = *src & 0x0f;
319 for (i = 0; i < logo->height; i++) {
320 for (j = 0; j < logo->width; src++) {
322 for (k = 7; k >= 0; k--) {
323 *dst++ = ((d >> k) & 1) ? fg : 0;
333 * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
334 * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
335 * the visual format and color depth of the framebuffer, the DAC, the
336 * pseudo_palette, and the logo data will be adjusted accordingly.
338 * Case 1 - linux_logo_clut224:
339 * Color exceeds the number of console colors (16), thus we set the hardware DAC
340 * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
342 * For visuals that require color info from the pseudo_palette, we also construct
343 * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
346 * Case 2 - linux_logo_vga16:
347 * The number of colors just matches the console colors, thus there is no need
348 * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
349 * each byte contains color information for two pixels (upper and lower nibble).
350 * To be consistent with fb_imageblit() usage, we therefore separate the two
351 * nibbles into separate bytes. The "depth" flag will be set to 4.
353 * Case 3 - linux_logo_mono:
354 * This is similar with Case 2. Each byte contains information for 8 pixels.
355 * We isolate each bit and expand each into a byte. The "depth" flag will
358 static struct logo_data {
360 int needs_directpalette;
361 int needs_truepalette;
363 const struct linux_logo *logo;
366 int fb_prepare_logo(struct fb_info *info)
368 int depth = fb_get_color_depth(info);
370 memset(&fb_logo, 0, sizeof(struct logo_data));
372 if (info->flags & FBINFO_MISC_TILEBLITTING)
375 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
376 depth = info->var.blue.length;
377 if (info->var.red.length < depth)
378 depth = info->var.red.length;
379 if (info->var.green.length < depth)
380 depth = info->var.green.length;
384 switch (info->fix.visual) {
385 case FB_VISUAL_TRUECOLOR:
386 fb_logo.needs_truepalette = 1;
388 case FB_VISUAL_DIRECTCOLOR:
389 fb_logo.needs_directpalette = 1;
390 fb_logo.needs_cmapreset = 1;
392 case FB_VISUAL_PSEUDOCOLOR:
393 fb_logo.needs_cmapreset = 1;
398 /* Return if no suitable logo was found */
399 fb_logo.logo = fb_find_logo(depth);
401 if (!fb_logo.logo || fb_logo.logo->height > info->var.yres) {
405 /* What depth we asked for might be different from what we get */
406 if (fb_logo.logo->type == LINUX_LOGO_CLUT224)
408 else if (fb_logo.logo->type == LINUX_LOGO_VGA16)
412 return fb_logo.logo->height;
415 int fb_show_logo(struct fb_info *info)
417 u32 *palette = NULL, *saved_pseudo_palette = NULL;
418 unsigned char *logo_new = NULL;
419 struct fb_image image;
422 /* Return if the frame buffer is not mapped or suspended */
423 if (fb_logo.logo == NULL || info->state != FBINFO_STATE_RUNNING)
427 image.data = fb_logo.logo->data;
429 if (fb_logo.needs_cmapreset)
430 fb_set_logocmap(info, fb_logo.logo);
432 if (fb_logo.needs_truepalette ||
433 fb_logo.needs_directpalette) {
434 palette = kmalloc(256 * 4, GFP_KERNEL);
438 if (fb_logo.needs_truepalette)
439 fb_set_logo_truepalette(info, fb_logo.logo, palette);
441 fb_set_logo_directpalette(info, fb_logo.logo, palette);
443 saved_pseudo_palette = info->pseudo_palette;
444 info->pseudo_palette = palette;
447 if (fb_logo.depth <= 4) {
448 logo_new = kmalloc(fb_logo.logo->width * fb_logo.logo->height,
450 if (logo_new == NULL) {
453 if (saved_pseudo_palette)
454 info->pseudo_palette = saved_pseudo_palette;
457 image.data = logo_new;
458 fb_set_logo(info, fb_logo.logo, logo_new, fb_logo.depth);
461 image.width = fb_logo.logo->width;
462 image.height = fb_logo.logo->height;
465 for (x = 0; x < num_online_cpus() * (fb_logo.logo->width + 8) &&
466 x <= info->var.xres-fb_logo.logo->width; x += (fb_logo.logo->width + 8)) {
468 info->fbops->fb_imageblit(info, &image);
473 if (saved_pseudo_palette != NULL)
474 info->pseudo_palette = saved_pseudo_palette;
475 if (logo_new != NULL)
477 return fb_logo.logo->height;
480 int fb_prepare_logo(struct fb_info *info) { return 0; }
481 int fb_show_logo(struct fb_info *info) { return 0; }
482 #endif /* CONFIG_LOGO */
484 static int fbmem_read_proc(char *buf, char **start, off_t offset,
485 int len, int *eof, void *private)
491 for (fi = registered_fb; fi < ®istered_fb[FB_MAX] && len < 4000; fi++)
493 clen += sprintf(buf + clen, "%d %s\n",
496 *start = buf + offset;
501 return clen < len ? clen : len;
505 fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
507 unsigned long p = *ppos;
508 struct inode *inode = file->f_dentry->d_inode;
509 int fbidx = iminor(inode);
510 struct fb_info *info = registered_fb[fbidx];
513 int c, i, cnt = 0, err = 0;
514 unsigned long total_size;
516 if (!info || ! info->screen_base)
519 if (info->state != FBINFO_STATE_RUNNING)
522 if (info->fbops->fb_read)
523 return info->fbops->fb_read(file, buf, count, ppos);
525 total_size = info->screen_size;
527 total_size = info->fix.smem_len;
531 if (count >= total_size)
533 if (count + p > total_size)
534 count = total_size - p;
537 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
542 src = (u32 __iomem *) (info->screen_base + p);
544 if (info->fbops->fb_sync)
545 info->fbops->fb_sync(info);
548 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
550 for (i = c >> 2; i--; )
551 *dst++ = fb_readl(src++);
553 u8 *dst8 = (u8 *) dst;
554 u8 __iomem *src8 = (u8 __iomem *) src;
556 for (i = c & 3; i--;)
557 *dst8++ = fb_readb(src8++);
559 src = (u32 __iomem *) src8;
562 if (copy_to_user(buf, buffer, c)) {
573 return (err) ? err : cnt;
577 fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
579 unsigned long p = *ppos;
580 struct inode *inode = file->f_dentry->d_inode;
581 int fbidx = iminor(inode);
582 struct fb_info *info = registered_fb[fbidx];
585 int c, i, cnt = 0, err;
586 unsigned long total_size;
588 if (!info || !info->screen_base)
591 if (info->state != FBINFO_STATE_RUNNING)
594 if (info->fbops->fb_write)
595 return info->fbops->fb_write(file, buf, count, ppos);
597 total_size = info->screen_size;
599 total_size = info->fix.smem_len;
603 if (count >= total_size)
606 if (count + p > total_size) {
607 count = total_size - p;
611 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
616 dst = (u32 __iomem *) (info->screen_base + p);
618 if (info->fbops->fb_sync)
619 info->fbops->fb_sync(info);
622 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
624 if (copy_from_user(src, buf, c)) {
628 for (i = c >> 2; i--; )
629 fb_writel(*src++, dst++);
631 u8 *src8 = (u8 *) src;
632 u8 __iomem *dst8 = (u8 __iomem *) dst;
634 for (i = c & 3; i--; )
635 fb_writeb(*src8++, dst8++);
637 dst = (u32 __iomem *) dst8;
646 return (err) ? err : cnt;
650 static void try_to_load(int fb)
652 request_module("fb%d", fb);
654 #endif /* CONFIG_KMOD */
657 fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
659 int xoffset = var->xoffset;
660 int yoffset = var->yoffset;
663 if (xoffset < 0 || yoffset < 0 || !info->fbops->fb_pan_display ||
664 xoffset + info->var.xres > info->var.xres_virtual ||
665 yoffset + info->var.yres > info->var.yres_virtual)
667 if ((err = info->fbops->fb_pan_display(var, info)))
669 info->var.xoffset = var->xoffset;
670 info->var.yoffset = var->yoffset;
671 if (var->vmode & FB_VMODE_YWRAP)
672 info->var.vmode |= FB_VMODE_YWRAP;
674 info->var.vmode &= ~FB_VMODE_YWRAP;
679 fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
683 if (var->activate & FB_ACTIVATE_INV_MODE) {
684 struct fb_videomode mode1, mode2;
687 fb_var_to_videomode(&mode1, var);
688 fb_var_to_videomode(&mode2, &info->var);
689 /* make sure we don't delete the videomode of current var */
690 ret = fb_mode_is_equal(&mode1, &mode2);
693 struct fb_event event;
697 ret = notifier_call_chain(&fb_notifier_list,
698 FB_EVENT_MODE_DELETE, &event);
702 fb_delete_videomode(&mode1, &info->modelist);
707 if ((var->activate & FB_ACTIVATE_FORCE) ||
708 memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
709 if (!info->fbops->fb_check_var) {
714 if ((err = info->fbops->fb_check_var(var, info)))
717 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
718 struct fb_videomode mode;
722 if (info->fbops->fb_set_par)
723 info->fbops->fb_set_par(info);
725 fb_pan_display(info, &info->var);
727 fb_set_cmap(&info->cmap, info);
729 fb_var_to_videomode(&mode, &info->var);
731 if (info->modelist.prev && info->modelist.next &&
732 !list_empty(&info->modelist))
733 err = fb_add_videomode(&mode, &info->modelist);
735 if (!err && info->flags & FBINFO_MISC_USEREVENT) {
736 struct fb_event event;
738 info->flags &= ~FBINFO_MISC_USEREVENT;
740 notifier_call_chain(&fb_notifier_list,
741 FB_EVENT_MODE_CHANGE,
750 fb_blank(struct fb_info *info, int blank)
754 if (blank > FB_BLANK_POWERDOWN)
755 blank = FB_BLANK_POWERDOWN;
757 if (info->fbops->fb_blank)
758 ret = info->fbops->fb_blank(blank, info);
761 struct fb_event event;
765 notifier_call_chain(&fb_notifier_list, FB_EVENT_BLANK, &event);
772 fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
775 int fbidx = iminor(inode);
776 struct fb_info *info = registered_fb[fbidx];
777 struct fb_ops *fb = info->fbops;
778 struct fb_var_screeninfo var;
779 struct fb_fix_screeninfo fix;
780 struct fb_con2fbmap con2fb;
781 struct fb_cmap_user cmap;
782 struct fb_event event;
783 void __user *argp = (void __user *)arg;
789 case FBIOGET_VSCREENINFO:
790 return copy_to_user(argp, &info->var,
791 sizeof(var)) ? -EFAULT : 0;
792 case FBIOPUT_VSCREENINFO:
793 if (copy_from_user(&var, argp, sizeof(var)))
795 acquire_console_sem();
796 info->flags |= FBINFO_MISC_USEREVENT;
797 i = fb_set_var(info, &var);
798 info->flags &= ~FBINFO_MISC_USEREVENT;
799 release_console_sem();
801 if (copy_to_user(argp, &var, sizeof(var)))
804 case FBIOGET_FSCREENINFO:
805 return copy_to_user(argp, &info->fix,
806 sizeof(fix)) ? -EFAULT : 0;
808 if (copy_from_user(&cmap, argp, sizeof(cmap)))
810 return (fb_set_user_cmap(&cmap, info));
812 if (copy_from_user(&cmap, argp, sizeof(cmap)))
814 return fb_cmap_to_user(&info->cmap, &cmap);
815 case FBIOPAN_DISPLAY:
816 if (copy_from_user(&var, argp, sizeof(var)))
818 acquire_console_sem();
819 i = fb_pan_display(info, &var);
820 release_console_sem();
823 if (copy_to_user(argp, &var, sizeof(var)))
828 case FBIOGET_CON2FBMAP:
829 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
831 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
833 con2fb.framebuffer = -1;
835 event.data = &con2fb;
836 notifier_call_chain(&fb_notifier_list,
837 FB_EVENT_GET_CONSOLE_MAP, &event);
838 return copy_to_user(argp, &con2fb,
839 sizeof(con2fb)) ? -EFAULT : 0;
840 case FBIOPUT_CON2FBMAP:
841 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
843 if (con2fb.console < 0 || con2fb.console > MAX_NR_CONSOLES)
845 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
848 if (!registered_fb[con2fb.framebuffer])
849 try_to_load(con2fb.framebuffer);
850 #endif /* CONFIG_KMOD */
851 if (!registered_fb[con2fb.framebuffer])
854 event.data = &con2fb;
855 return notifier_call_chain(&fb_notifier_list,
856 FB_EVENT_SET_CONSOLE_MAP,
859 acquire_console_sem();
860 info->flags |= FBINFO_MISC_USEREVENT;
861 i = fb_blank(info, arg);
862 info->flags &= ~FBINFO_MISC_USEREVENT;
863 release_console_sem();
866 if (fb->fb_ioctl == NULL)
868 return fb->fb_ioctl(inode, file, cmd, arg, info);
874 fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
876 int fbidx = iminor(file->f_dentry->d_inode);
877 struct fb_info *info = registered_fb[fbidx];
878 struct fb_ops *fb = info->fbops;
880 if (fb->fb_compat_ioctl == NULL)
883 ret = fb->fb_compat_ioctl(file, cmd, arg, info);
890 fb_mmap(struct file *file, struct vm_area_struct * vma)
892 int fbidx = iminor(file->f_dentry->d_inode);
893 struct fb_info *info = registered_fb[fbidx];
894 struct fb_ops *fb = info->fbops;
896 #if !defined(__sparc__) || defined(__sparc_v9__)
901 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
903 off = vma->vm_pgoff << PAGE_SHIFT;
909 res = fb->fb_mmap(info, file, vma);
914 #if defined(__sparc__) && !defined(__sparc_v9__)
915 /* Should never get here, all fb drivers should have their own
922 /* frame buffer memory */
923 start = info->fix.smem_start;
924 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
926 /* memory mapped io */
928 if (info->var.accel_flags) {
932 start = info->fix.mmio_start;
933 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
937 if ((vma->vm_end - vma->vm_start + off) > len)
940 vma->vm_pgoff = off >> PAGE_SHIFT;
941 /* This is an IO map - tell maydump to skip this VMA */
942 vma->vm_flags |= VM_IO | VM_RESERVED;
943 #if defined(__sparc_v9__)
944 if (io_remap_page_range(vma, vma->vm_start, off,
945 vma->vm_end - vma->vm_start, vma->vm_page_prot, 0))
948 #if defined(__mc68000__)
949 #if defined(CONFIG_SUN3)
950 pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
951 #elif defined(CONFIG_MMU)
952 if (CPU_IS_020_OR_030)
953 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
954 if (CPU_IS_040_OR_060) {
955 pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
956 /* Use no-cache mode, serialized */
957 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
960 #elif defined(__powerpc__)
961 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
962 #elif defined(__alpha__)
963 /* Caching is off in the I/O space quadrant by design. */
964 #elif defined(__i386__) || defined(__x86_64__)
965 if (boot_cpu_data.x86 > 3)
966 pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
967 #elif defined(__mips__)
968 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
969 #elif defined(__hppa__)
970 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
971 #elif defined(__arm__) || defined(__sh__) || defined(__m32r__)
972 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
973 #elif defined(__ia64__)
974 if (efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start))
975 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
977 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
979 #warning What do we have to do here??
981 if (io_remap_page_range(vma, vma->vm_start, off,
982 vma->vm_end - vma->vm_start, vma->vm_page_prot))
984 #endif /* !__sparc_v9__ */
986 #endif /* !sparc32 */
990 fb_open(struct inode *inode, struct file *file)
992 int fbidx = iminor(inode);
993 struct fb_info *info;
999 if (!(info = registered_fb[fbidx]))
1001 #endif /* CONFIG_KMOD */
1002 if (!(info = registered_fb[fbidx]))
1004 if (!try_module_get(info->fbops->owner))
1006 if (info->fbops->fb_open) {
1007 res = info->fbops->fb_open(info,1);
1009 module_put(info->fbops->owner);
1015 fb_release(struct inode *inode, struct file *file)
1017 int fbidx = iminor(inode);
1018 struct fb_info *info;
1021 info = registered_fb[fbidx];
1022 if (info->fbops->fb_release)
1023 info->fbops->fb_release(info,1);
1024 module_put(info->fbops->owner);
1029 static struct file_operations fb_fops = {
1030 .owner = THIS_MODULE,
1034 #ifdef CONFIG_COMPAT
1035 .compat_ioctl = fb_compat_ioctl,
1039 .release = fb_release,
1040 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1041 .get_unmapped_area = get_fb_unmapped_area,
1045 static struct class_simple *fb_class;
1048 * register_framebuffer - registers a frame buffer device
1049 * @fb_info: frame buffer info structure
1051 * Registers a frame buffer device @fb_info.
1053 * Returns negative errno on error, or zero for success.
1058 register_framebuffer(struct fb_info *fb_info)
1061 struct class_device *c;
1062 struct fb_event event;
1064 if (num_registered_fb == FB_MAX)
1066 num_registered_fb++;
1067 for (i = 0 ; i < FB_MAX; i++)
1068 if (!registered_fb[i])
1072 c = class_simple_device_add(fb_class, MKDEV(FB_MAJOR, i),
1073 fb_info->device, "fb%d", i);
1076 printk(KERN_WARNING "Unable to create class_device for framebuffer %d; errno = %ld\n", i, PTR_ERR(c));
1079 if (fb_info->pixmap.addr == NULL) {
1080 fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
1081 if (fb_info->pixmap.addr) {
1082 fb_info->pixmap.size = FBPIXMAPSIZE;
1083 fb_info->pixmap.buf_align = 1;
1084 fb_info->pixmap.scan_align = 1;
1085 fb_info->pixmap.access_align = 4;
1086 fb_info->pixmap.flags = FB_PIXMAP_DEFAULT;
1089 fb_info->pixmap.offset = 0;
1091 if (!fb_info->modelist.prev ||
1092 !fb_info->modelist.next ||
1093 list_empty(&fb_info->modelist)) {
1094 struct fb_videomode mode;
1096 INIT_LIST_HEAD(&fb_info->modelist);
1097 fb_var_to_videomode(&mode, &fb_info->var);
1098 fb_add_videomode(&mode, &fb_info->modelist);
1101 registered_fb[i] = fb_info;
1103 devfs_mk_cdev(MKDEV(FB_MAJOR, i),
1104 S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
1105 event.info = fb_info;
1106 notifier_call_chain(&fb_notifier_list,
1107 FB_EVENT_FB_REGISTERED, &event);
1113 * unregister_framebuffer - releases a frame buffer device
1114 * @fb_info: frame buffer info structure
1116 * Unregisters a frame buffer device @fb_info.
1118 * Returns negative errno on error, or zero for success.
1123 unregister_framebuffer(struct fb_info *fb_info)
1128 if (!registered_fb[i])
1130 devfs_remove("fb/%d", i);
1132 if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
1133 kfree(fb_info->pixmap.addr);
1134 fb_destroy_modelist(&fb_info->modelist);
1135 registered_fb[i]=NULL;
1136 num_registered_fb--;
1137 class_simple_device_remove(MKDEV(FB_MAJOR, i));
1142 * fb_register_client - register a client notifier
1143 * @nb: notifier block to callback on events
1145 int fb_register_client(struct notifier_block *nb)
1147 return notifier_chain_register(&fb_notifier_list, nb);
1151 * fb_unregister_client - unregister a client notifier
1152 * @nb: notifier block to callback on events
1154 int fb_unregister_client(struct notifier_block *nb)
1156 return notifier_chain_unregister(&fb_notifier_list, nb);
1160 * fb_set_suspend - low level driver signals suspend
1161 * @info: framebuffer affected
1162 * @state: 0 = resuming, !=0 = suspending
1164 * This is meant to be used by low level drivers to
1165 * signal suspend/resume to the core & clients.
1166 * It must be called with the console semaphore held
1168 void fb_set_suspend(struct fb_info *info, int state)
1170 struct fb_event event;
1174 notifier_call_chain(&fb_notifier_list, FB_EVENT_SUSPEND, &event);
1175 info->state = FBINFO_STATE_SUSPENDED;
1177 info->state = FBINFO_STATE_RUNNING;
1178 notifier_call_chain(&fb_notifier_list, FB_EVENT_RESUME, &event);
1183 * fbmem_init - init frame buffer subsystem
1185 * Initialize the frame buffer subsystem.
1187 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
1194 create_proc_read_entry("fb", 0, NULL, fbmem_read_proc, NULL);
1197 if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
1198 printk("unable to get major %d for fb devs\n", FB_MAJOR);
1200 fb_class = class_simple_create(THIS_MODULE, "graphics");
1201 if (IS_ERR(fb_class)) {
1202 printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
1207 subsys_initcall(fbmem_init);
1209 static char *video_options[FB_MAX];
1213 * fb_get_options - get kernel boot parameters
1214 * @name - framebuffer name as it would appear in
1215 * the boot parameter line
1216 * (video=<name>:<options>)
1218 * NOTE: Needed to maintain backwards compatibility
1220 int fb_get_options(char *name, char **option)
1222 char *opt, *options = NULL;
1223 int opt_len, retval = 0;
1224 int name_len = strlen(name), i;
1226 if (name_len && ofonly && strncmp(name, "offb", 4))
1229 if (name_len && !retval) {
1230 for (i = 0; i < FB_MAX; i++) {
1231 if (video_options[i] == NULL)
1233 opt_len = strlen(video_options[i]);
1236 opt = video_options[i];
1237 if (!strncmp(name, opt, name_len) &&
1238 opt[name_len] == ':')
1239 options = opt + name_len + 1;
1242 if (options && !strncmp(options, "off", 3))
1252 * video_setup - process command line options
1253 * @options: string of options
1255 * Process command line options for frame buffer subsystem.
1257 * NOTE: This function is a __setup and __init function.
1258 * It only stores the options. Drivers have to call
1259 * fb_get_options() as necessary.
1265 extern const char *global_mode_option;
1267 int __init video_setup(char *options)
1271 if (!options || !*options)
1274 if (!global && !strncmp(options, "ofonly", 6)) {
1279 if (!global && !strstr(options, "fb:")) {
1280 global_mode_option = options;
1285 for (i = 0; i < FB_MAX; i++) {
1286 if (video_options[i] == NULL) {
1287 video_options[i] = options;
1296 __setup("video=", video_setup);
1299 * Visible symbols for modules
1302 EXPORT_SYMBOL(register_framebuffer);
1303 EXPORT_SYMBOL(unregister_framebuffer);
1304 EXPORT_SYMBOL(num_registered_fb);
1305 EXPORT_SYMBOL(registered_fb);
1306 EXPORT_SYMBOL(fb_prepare_logo);
1307 EXPORT_SYMBOL(fb_show_logo);
1308 EXPORT_SYMBOL(fb_set_var);
1309 EXPORT_SYMBOL(fb_blank);
1310 EXPORT_SYMBOL(fb_pan_display);
1311 EXPORT_SYMBOL(fb_get_buffer_offset);
1312 EXPORT_SYMBOL(fb_iomove_buf_unaligned);
1313 EXPORT_SYMBOL(fb_iomove_buf_aligned);
1314 EXPORT_SYMBOL(fb_sysmove_buf_unaligned);
1315 EXPORT_SYMBOL(fb_sysmove_buf_aligned);
1316 EXPORT_SYMBOL(fb_set_suspend);
1317 EXPORT_SYMBOL(fb_register_client);
1318 EXPORT_SYMBOL(fb_unregister_client);
1319 EXPORT_SYMBOL(fb_get_options);
1321 MODULE_LICENSE("GPL");