linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / video / fbmem.c
index 93ffcdd..b1b4d13 100644 (file)
@@ -11,6 +11,7 @@
  * for more details.
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/compat.h>
@@ -23,7 +24,7 @@
 #include <linux/slab.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
-#include <linux/vt.h>
+#include <linux/tty.h>
 #include <linux/init.h>
 #include <linux/linux_logo.h>
 #include <linux/proc_fs.h>
@@ -31,7 +32,9 @@
 #ifdef CONFIG_KMOD
 #include <linux/kmod.h>
 #endif
+#include <linux/devfs_fs_kernel.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/efi.h>
 
@@ -52,6 +55,7 @@
 
 #define FBPIXMAPSIZE   (1024 * 8)
 
+static struct notifier_block *fb_notifier_list;
 struct fb_info *registered_fb[FB_MAX];
 int num_registered_fb;
 
@@ -158,6 +162,7 @@ char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size
 }
 
 #ifdef CONFIG_LOGO
+#include <linux/linux_logo.h>
 
 static inline unsigned safe_shift(unsigned d, int n)
 {
@@ -331,11 +336,11 @@ static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height)
 
 static void fb_rotate_logo_cw(const u8 *in, u8 *out, u32 width, u32 height)
 {
-       int i, j, h = height - 1;
+       int i, j, w = width - 1;
 
        for (i = 0; i < height; i++)
                for (j = 0; j < width; j++)
-                               out[height * j + h - i] = *in++;
+                       out[height * j + w - i] = *in++;
 }
 
 static void fb_rotate_logo_ccw(const u8 *in, u8 *out, u32 width, u32 height)
@@ -353,24 +358,24 @@ static void fb_rotate_logo(struct fb_info *info, u8 *dst,
        u32 tmp;
 
        if (rotate == FB_ROTATE_UD) {
-               fb_rotate_logo_ud(image->data, dst, image->width,
-                                 image->height);
                image->dx = info->var.xres - image->width;
                image->dy = info->var.yres - image->height;
-       } else if (rotate == FB_ROTATE_CW) {
-               fb_rotate_logo_cw(image->data, dst, image->width,
+               fb_rotate_logo_ud(image->data, dst, image->width,
                                  image->height);
+       } else if (rotate == FB_ROTATE_CW) {
                tmp = image->width;
                image->width = image->height;
                image->height = tmp;
-               image->dx = info->var.xres - image->width;
+               image->dx = info->var.xres - image->height;
+               fb_rotate_logo_cw(image->data, dst, image->width,
+                                 image->height);
        } else if (rotate == FB_ROTATE_CCW) {
-               fb_rotate_logo_ccw(image->data, dst, image->width,
-                                  image->height);
                tmp = image->width;
                image->width = image->height;
                image->height = tmp;
-               image->dy = info->var.yres - image->height;
+               image->dy = info->var.yres - image->width;
+               fb_rotate_logo_ccw(image->data, dst, image->width,
+                                  image->height);
        }
 
        image->data = dst;
@@ -430,11 +435,6 @@ int fb_prepare_logo(struct fb_info *info, int rotate)
                        depth = info->var.green.length;
        }
 
-       if (info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR && depth > 4) {
-               /* assume console colormap */
-               depth = 4;
-       }
-
        if (depth >= 8) {
                switch (info->fix.visual) {
                case FB_VISUAL_TRUECOLOR:
@@ -791,7 +791,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
 
                    event.info = info;
                    event.data = &mode1;
-                   ret = fb_notifier_call_chain(FB_EVENT_MODE_DELETE, &event);
+                   ret = notifier_call_chain(&fb_notifier_list,
+                                             FB_EVENT_MODE_DELETE, &event);
                }
 
                if (!ret)
@@ -836,7 +837,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
 
                                info->flags &= ~FBINFO_MISC_USEREVENT;
                                event.info = info;
-                               fb_notifier_call_chain(evnt, &event);
+                               notifier_call_chain(&fb_notifier_list, evnt,
+                                                   &event);
                        }
                }
        }
@@ -859,7 +861,7 @@ fb_blank(struct fb_info *info, int blank)
 
                event.info = info;
                event.data = &blank;
-               fb_notifier_call_chain(FB_EVENT_BLANK, &event);
+               notifier_call_chain(&fb_notifier_list, FB_EVENT_BLANK, &event);
        }
 
        return ret;
@@ -930,7 +932,8 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                con2fb.framebuffer = -1;
                event.info = info;
                event.data = &con2fb;
-               fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event);
+               notifier_call_chain(&fb_notifier_list,
+                                   FB_EVENT_GET_CONSOLE_MAP, &event);
                return copy_to_user(argp, &con2fb,
                                    sizeof(con2fb)) ? -EFAULT : 0;
        case FBIOPUT_CON2FBMAP:
@@ -948,8 +951,9 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                    return -EINVAL;
                event.info = info;
                event.data = &con2fb;
-               return fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP,
-                                             &event);
+               return notifier_call_chain(&fb_notifier_list,
+                                          FB_EVENT_SET_CONSOLE_MAP,
+                                          &event);
        case FBIOBLANK:
                acquire_console_sem();
                info->flags |= FBINFO_MISC_USEREVENT;
@@ -1172,6 +1176,11 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
        vma->vm_pgoff = off >> PAGE_SHIFT;
        /* This is an IO map - tell maydump to skip this VMA */
        vma->vm_flags |= VM_IO | VM_RESERVED;
+#if defined(__sparc_v9__)
+       if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
+                               vma->vm_end - vma->vm_start, vma->vm_page_prot))
+               return -EAGAIN;
+#else
 #if defined(__mc68000__)
 #if defined(CONFIG_SUN3)
        pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
@@ -1193,7 +1202,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
 #elif defined(__i386__) || defined(__x86_64__)
        if (boot_cpu_data.x86 > 3)
                pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
-#elif defined(__mips__) || defined(__sparc_v9__)
+#elif defined(__mips__)
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 #elif defined(__hppa__)
        pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
@@ -1210,6 +1219,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
        if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
                             vma->vm_end - vma->vm_start, vma->vm_page_prot))
                return -EAGAIN;
+#endif /* !__sparc_v9__ */
        return 0;
 #endif /* !sparc32 */
 }
@@ -1269,8 +1279,8 @@ static struct file_operations fb_fops = {
 #endif
 };
 
-struct class *fb_class;
-EXPORT_SYMBOL(fb_class);
+static struct class *fb_class;
+
 /**
  *     register_framebuffer - registers a frame buffer device
  *     @fb_info: frame buffer info structure
@@ -1324,8 +1334,11 @@ register_framebuffer(struct fb_info *fb_info)
        fb_add_videomode(&mode, &fb_info->modelist);
        registered_fb[i] = fb_info;
 
+       devfs_mk_cdev(MKDEV(FB_MAJOR, i),
+                       S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
        event.info = fb_info;
-       fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
+       notifier_call_chain(&fb_notifier_list,
+                           FB_EVENT_FB_REGISTERED, &event);
        return 0;
 }
 
@@ -1343,26 +1356,41 @@ register_framebuffer(struct fb_info *fb_info)
 int
 unregister_framebuffer(struct fb_info *fb_info)
 {
-       struct fb_event event;
        int i;
 
        i = fb_info->node;
        if (!registered_fb[i])
                return -EINVAL;
+       devfs_remove("fb/%d", i);
 
-       if (fb_info->pixmap.addr &&
-           (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
+       if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
                kfree(fb_info->pixmap.addr);
        fb_destroy_modelist(&fb_info->modelist);
        registered_fb[i]=NULL;
        num_registered_fb--;
        fb_cleanup_class_device(fb_info);
        class_device_destroy(fb_class, MKDEV(FB_MAJOR, i));
-       event.info = fb_info;
-       fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
        return 0;
 }
 
+/**
+ *     fb_register_client - register a client notifier
+ *     @nb: notifier block to callback on events
+ */
+int fb_register_client(struct notifier_block *nb)
+{
+       return notifier_chain_register(&fb_notifier_list, nb);
+}
+
+/**
+ *     fb_unregister_client - unregister a client notifier
+ *     @nb: notifier block to callback on events
+ */
+int fb_unregister_client(struct notifier_block *nb)
+{
+       return notifier_chain_unregister(&fb_notifier_list, nb);
+}
+
 /**
  *     fb_set_suspend - low level driver signals suspend
  *     @info: framebuffer affected
@@ -1378,11 +1406,11 @@ void fb_set_suspend(struct fb_info *info, int state)
 
        event.info = info;
        if (state) {
-               fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
+               notifier_call_chain(&fb_notifier_list, FB_EVENT_SUSPEND, &event);
                info->state = FBINFO_STATE_SUSPENDED;
        } else {
                info->state = FBINFO_STATE_RUNNING;
-               fb_notifier_call_chain(FB_EVENT_RESUME, &event);
+               notifier_call_chain(&fb_notifier_list, FB_EVENT_RESUME, &event);
        }
 }
 
@@ -1400,6 +1428,7 @@ fbmem_init(void)
 {
        create_proc_read_entry("fb", 0, NULL, fbmem_read_proc, NULL);
 
+       devfs_mk_dir("fb");
        if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
                printk("unable to get major %d for fb devs\n", FB_MAJOR);
 
@@ -1453,12 +1482,36 @@ int fb_new_modelist(struct fb_info *info)
 
        if (!list_empty(&info->modelist)) {
                event.info = info;
-               err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
+               err = notifier_call_chain(&fb_notifier_list,
+                                          FB_EVENT_NEW_MODELIST,
+                                          &event);
        }
 
        return err;
 }
 
+/**
+ * fb_con_duit - user<->fbcon passthrough
+ * @info: struct fb_info
+ * @event: notification event to be passed to fbcon
+ * @data: private data
+ *
+ * DESCRIPTION
+ * This function is an fbcon-user event passing channel
+ * which bypasses fbdev.  This is hopefully temporary
+ * until a user interface for fbcon is created
+ */
+int fb_con_duit(struct fb_info *info, int event, void *data)
+{
+       struct fb_event evnt;
+
+       evnt.info = info;
+       evnt.data = data;
+
+       return notifier_call_chain(&fb_notifier_list, event, &evnt);
+}
+EXPORT_SYMBOL(fb_con_duit);
+
 static char *video_options[FB_MAX];
 static int ofonly;
 
@@ -1545,7 +1598,7 @@ static int __init video_setup(char *options)
                }
        }
 
-       return 1;
+       return 0;
 }
 __setup("video=", video_setup);
 #endif
@@ -1565,6 +1618,9 @@ EXPORT_SYMBOL(fb_blank);
 EXPORT_SYMBOL(fb_pan_display);
 EXPORT_SYMBOL(fb_get_buffer_offset);
 EXPORT_SYMBOL(fb_set_suspend);
+EXPORT_SYMBOL(fb_register_client);
+EXPORT_SYMBOL(fb_unregister_client);
 EXPORT_SYMBOL(fb_get_options);
+EXPORT_SYMBOL(fb_new_modelist);
 
 MODULE_LICENSE("GPL");