drm/fb_helper: allow adding/removing connectors later
authorDave Airlie <airlied@redhat.com>
Thu, 5 Jun 2014 04:01:30 +0000 (14:01 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 8 Jul 2014 01:39:45 +0000 (11:39 +1000)
This is required to get fbcon probing to work on new connectors,
callers should acquire the mode config lock before calling these.

Reviewed-by: Todd Previte <tprevite@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_fb_helper.c
include/drm/drm_fb_helper.h

index bdee6eb..3144db9 100644 (file)
@@ -119,6 +119,58 @@ fail:
 }
 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
 
+int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector)
+{
+       struct drm_fb_helper_connector **temp;
+       struct drm_fb_helper_connector *fb_helper_connector;
+
+       WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
+       if (fb_helper->connector_count + 1 > fb_helper->connector_info_alloc_count) {
+               temp = krealloc(fb_helper->connector_info, sizeof(struct drm_fb_helper_connector) * (fb_helper->connector_count + 1), GFP_KERNEL);
+               if (!temp)
+                       return -ENOMEM;
+
+               fb_helper->connector_info_alloc_count = fb_helper->connector_count + 1;
+               fb_helper->connector_info = temp;
+       }
+
+
+       fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
+       if (!fb_helper_connector)
+               return -ENOMEM;
+
+       fb_helper_connector->connector = connector;
+       fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
+       return 0;
+}
+EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
+
+int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
+                                      struct drm_connector *connector)
+{
+       struct drm_fb_helper_connector *fb_helper_connector;
+       int i, j;
+
+       WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
+
+       for (i = 0; i < fb_helper->connector_count; i++) {
+               if (fb_helper->connector_info[i]->connector == connector)
+                       break;
+       }
+
+       if (i == fb_helper->connector_count)
+               return -EINVAL;
+       fb_helper_connector = fb_helper->connector_info[i];
+
+       for (j = i + 1; j < fb_helper->connector_count; j++) {
+               fb_helper->connector_info[j - 1] = fb_helper->connector_info[j];
+       }
+       fb_helper->connector_count--;
+       kfree(fb_helper_connector);
+       return 0;
+}
+EXPORT_SYMBOL(drm_fb_helper_remove_one_connector);
+
 static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
 {
        struct drm_fb_helper_connector *fb_helper_conn;
@@ -596,6 +648,7 @@ int drm_fb_helper_init(struct drm_device *dev,
                kfree(fb_helper->crtc_info);
                return -ENOMEM;
        }
+       fb_helper->connector_info_alloc_count = dev->mode_config.num_connector;
        fb_helper->connector_count = 0;
 
        for (i = 0; i < crtc_count; i++) {
index 1cf587f..bfd329d 100644 (file)
@@ -86,6 +86,7 @@ struct drm_fb_helper {
        int crtc_count;
        struct drm_fb_helper_crtc *crtc_info;
        int connector_count;
+       int connector_info_alloc_count;
        struct drm_fb_helper_connector **connector_info;
        const struct drm_fb_helper_funcs *funcs;
        struct fb_info *fbdev;
@@ -130,4 +131,7 @@ struct drm_display_mode *
 drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
                      int width, int height);
 
+int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector);
+int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
+                                      struct drm_connector *connector);
 #endif