fbdev: add support for handoff from firmware to hw framebuffers
[sfrench/cifs-2.6.git] / drivers / video / fbmem.c
index 2ac32e6b5953bb981e8bc57f9516584bc868d1c9..f8a09bf8d0cdecb0963116a4fb7a7d3793ed798d 100644 (file)
@@ -1097,8 +1097,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
                        return -EINVAL;
                con2fb.framebuffer = -1;
                event.data = &con2fb;
+               if (!lock_fb_info(info))
+                       return -ENODEV;
                event.info = info;
                fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event);
+               unlock_fb_info(info);
                ret = copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
                break;
        case FBIOPUT_CON2FBMAP:
@@ -1115,8 +1118,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
                        break;
                }
                event.data = &con2fb;
+               if (!lock_fb_info(info))
+                       return -ENODEV;
                event.info = info;
                ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
+               unlock_fb_info(info);
                break;
        case FBIOBLANK:
                if (!lock_fb_info(info))
@@ -1456,6 +1462,16 @@ static int fb_check_foreignness(struct fb_info *fi)
        return 0;
 }
 
+static bool fb_do_apertures_overlap(struct fb_info *gen, struct fb_info *hw)
+{
+       /* is the generic aperture base the same as the HW one */
+       if (gen->aperture_base == hw->aperture_base)
+               return true;
+       /* is the generic aperture base inside the hw base->hw base+size */
+       if (gen->aperture_base > hw->aperture_base && gen->aperture_base <= hw->aperture_base + hw->aperture_size)
+               return true;
+       return false;
+}
 /**
  *     register_framebuffer - registers a frame buffer device
  *     @fb_info: frame buffer info structure
@@ -1479,6 +1495,23 @@ register_framebuffer(struct fb_info *fb_info)
        if (fb_check_foreignness(fb_info))
                return -ENOSYS;
 
+       /* check all firmware fbs and kick off if the base addr overlaps */
+       for (i = 0 ; i < FB_MAX; i++) {
+               if (!registered_fb[i])
+                       continue;
+
+               if (registered_fb[i]->flags & FBINFO_MISC_FIRMWARE) {
+                       if (fb_do_apertures_overlap(registered_fb[i], fb_info)) {
+                               printk(KERN_ERR "fb: conflicting fb hw usage "
+                                      "%s vs %s - removing generic driver\n",
+                                      fb_info->fix.id,
+                                      registered_fb[i]->fix.id);
+                               unregister_framebuffer(registered_fb[i]);
+                               break;
+                       }
+               }
+       }
+
        num_registered_fb++;
        for (i = 0 ; i < FB_MAX; i++)
                if (!registered_fb[i])
@@ -1521,7 +1554,10 @@ register_framebuffer(struct fb_info *fb_info)
        registered_fb[i] = fb_info;
 
        event.info = fb_info;
+       if (!lock_fb_info(fb_info))
+               return -ENODEV;
        fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
+       unlock_fb_info(fb_info);
        return 0;
 }
 
@@ -1555,8 +1591,12 @@ unregister_framebuffer(struct fb_info *fb_info)
                goto done;
        }
 
+
+       if (!lock_fb_info(fb_info))
+               return -ENODEV;
        event.info = fb_info;
        ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
+       unlock_fb_info(fb_info);
 
        if (ret) {
                ret = -EINVAL;
@@ -1573,6 +1613,10 @@ unregister_framebuffer(struct fb_info *fb_info)
        device_destroy(fb_class, MKDEV(FB_MAJOR, i));
        event.info = fb_info;
        fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
+
+       /* this may free fb info */
+       if (fb_info->fbops->fb_destroy)
+               fb_info->fbops->fb_destroy(fb_info);
 done:
        return ret;
 }
@@ -1590,6 +1634,8 @@ void fb_set_suspend(struct fb_info *info, int state)
 {
        struct fb_event event;
 
+       if (!lock_fb_info(info))
+               return;
        event.info = info;
        if (state) {
                fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
@@ -1598,6 +1644,7 @@ void fb_set_suspend(struct fb_info *info, int state)
                info->state = FBINFO_STATE_RUNNING;
                fb_notifier_call_chain(FB_EVENT_RESUME, &event);
        }
+       unlock_fb_info(info);
 }
 
 /**
@@ -1667,8 +1714,11 @@ int fb_new_modelist(struct fb_info *info)
        err = 1;
 
        if (!list_empty(&info->modelist)) {
+               if (!lock_fb_info(info))
+                       return -ENODEV;
                event.info = info;
                err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
+               unlock_fb_info(info);
        }
 
        return err;