Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4abe3520 authored by Dave Airlie's avatar Dave Airlie
Browse files

drm/kms/fb: use slow work mechanism for normal hotplug also.



a) slow work is always used now for any fbcon hotplug, as its not
   a fast task and is more suited to being ran under slow work.

b) attempt to not do any fbdev changes when X is running as we'll
   just mess it up. This hooks set_par to hopefully do the changes
   once X hands control to fbdev.

This also adds the nouveau/intel hotplug support.

Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 5c4426a7
Loading
Loading
Loading
Loading
+124 −83
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ MODULE_LICENSE("GPL and additional rights");

static LIST_HEAD(kernel_fb_helper_list);

static struct slow_work_ops output_status_change_ops;

/* simple single crtc case helper function */
int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
{
@@ -420,54 +422,81 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
	kfree(helper->crtc_info);
}

int drm_fb_helper_init_crtc_count(struct drm_device *dev,
				  struct drm_fb_helper *helper,
				  int crtc_count, int max_conn_count)
int drm_fb_helper_init(struct drm_device *dev,
		       struct drm_fb_helper *fb_helper,
		       int crtc_count, int max_conn_count,
		       bool polled)
{
	struct drm_crtc *crtc;
	int ret = 0;
	int i;

	INIT_LIST_HEAD(&helper->kernel_fb_list);
	helper->dev = dev;
	helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
	if (!helper->crtc_info)
	fb_helper->dev = dev;
	fb_helper->poll_enabled = polled;

	slow_work_register_user(THIS_MODULE);
	delayed_slow_work_init(&fb_helper->output_status_change_slow_work,
			       &output_status_change_ops);

	INIT_LIST_HEAD(&fb_helper->kernel_fb_list);

	fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
	if (!fb_helper->crtc_info)
		return -ENOMEM;
	helper->crtc_count = crtc_count;

	helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
	if (!helper->connector_info) {
		kfree(helper->crtc_info);
	fb_helper->crtc_count = crtc_count;
	fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
	if (!fb_helper->connector_info) {
		kfree(fb_helper->crtc_info);
		return -ENOMEM;
	}
	helper->connector_count = 0;
	fb_helper->connector_count = 0;

	for (i = 0; i < crtc_count; i++) {
		helper->crtc_info[i].mode_set.connectors =
		fb_helper->crtc_info[i].mode_set.connectors =
			kcalloc(max_conn_count,
				sizeof(struct drm_connector *),
				GFP_KERNEL);

		if (!helper->crtc_info[i].mode_set.connectors) {
		if (!fb_helper->crtc_info[i].mode_set.connectors) {
			ret = -ENOMEM;
			goto out_free;
		}
		helper->crtc_info[i].mode_set.num_connectors = 0;
		fb_helper->crtc_info[i].mode_set.num_connectors = 0;
	}

	i = 0;
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
		helper->crtc_info[i].crtc_id = crtc->base.id;
		helper->crtc_info[i].mode_set.crtc = crtc;
		fb_helper->crtc_info[i].crtc_id = crtc->base.id;
		fb_helper->crtc_info[i].mode_set.crtc = crtc;
		i++;
	}
	helper->conn_limit = max_conn_count;
	fb_helper->conn_limit = max_conn_count;
	return 0;
out_free:
	drm_fb_helper_crtc_free(helper);
	drm_fb_helper_crtc_free(fb_helper);
	return -ENOMEM;
}
EXPORT_SYMBOL(drm_fb_helper_init_crtc_count);
EXPORT_SYMBOL(drm_fb_helper_init);

void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
{
	if (!list_empty(&fb_helper->kernel_fb_list)) {
		list_del(&fb_helper->kernel_fb_list);
		if (list_empty(&kernel_fb_helper_list)) {
			printk(KERN_INFO "unregistered panic notifier\n");
			atomic_notifier_chain_unregister(&panic_notifier_list,
							 &paniced);
			unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
		}
	}

	drm_fb_helper_crtc_free(fb_helper);

	delayed_slow_work_cancel(&fb_helper->output_status_change_slow_work);
	slow_work_unregister_user(THIS_MODULE);
}
EXPORT_SYMBOL(drm_fb_helper_fini);

static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
		     u16 blue, u16 regno, struct fb_info *info)
@@ -710,6 +739,11 @@ int drm_fb_helper_set_par(struct fb_info *info)
		}
	}
	mutex_unlock(&dev->mode_config.mutex);

	if (fb_helper->delayed_hotplug) {
		fb_helper->delayed_hotplug = false;
		delayed_slow_work_enqueue(&fb_helper->output_status_change_slow_work, 0);
	}
	return 0;
}
EXPORT_SYMBOL(drm_fb_helper_set_par);
@@ -751,7 +785,7 @@ int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
{
	int new_fb = 0;
	int crtc_count = 0;
	int ret, i;
	int i;
	struct fb_info *info;
	struct drm_fb_helper_surface_size sizes;
	int gamma_size = 0;
@@ -827,7 +861,7 @@ int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
	}

	/* push down into drivers */
	new_fb = (*fb_helper->fb_probe)(fb_helper, &sizes);
	new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
	if (new_fb < 0)
		return new_fb;

@@ -840,11 +874,7 @@ int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,

	if (new_fb) {
		info->var.pixclock = 0;
		ret = fb_alloc_cmap(&info->cmap, gamma_size, 0);
		if (ret)
			return ret;
		if (register_framebuffer(info) < 0) {
			fb_dealloc_cmap(&info->cmap);
			return -EINVAL;
		}

@@ -870,23 +900,6 @@ int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
}
EXPORT_SYMBOL(drm_fb_helper_single_fb_probe);

void drm_fb_helper_free(struct drm_fb_helper *helper)
{
	if (!list_empty(&helper->kernel_fb_list)) {
		list_del(&helper->kernel_fb_list);
		if (list_empty(&kernel_fb_helper_list)) {
			printk(KERN_INFO "unregistered panic notifier\n");
			atomic_notifier_chain_unregister(&panic_notifier_list,
							 &paniced);
			unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
		}
	}
	drm_fb_helper_crtc_free(helper);
	if (helper->fbdev->cmap.len)
		fb_dealloc_cmap(&helper->fbdev->cmap);
}
EXPORT_SYMBOL(drm_fb_helper_free);

void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
			    uint32_t depth)
{
@@ -1291,7 +1304,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
 * RETURNS:
 * Zero if everything went ok, nonzero otherwise.
 */
bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper)
bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
{
	struct drm_device *dev = fb_helper->dev;
	int count = 0;
@@ -1304,13 +1317,12 @@ bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper)
	count = drm_fb_helper_probe_connector_modes(fb_helper,
						    dev->mode_config.max_width,
						    dev->mode_config.max_height);

	/*
	 * we shouldn't end up with no modes here.
	 */
	if (count == 0) {
		if (fb_helper->poll_enabled) {
			delayed_slow_work_enqueue(&fb_helper->output_poll_slow_work,
			delayed_slow_work_enqueue(&fb_helper->output_status_change_slow_work,
						  5*HZ);
			printk(KERN_INFO "No connectors reported connected with modes - started polling\n");
		} else
@@ -1318,85 +1330,114 @@ bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper)
	}
	drm_setup_crtcs(fb_helper);

	return 0;
	return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
}
EXPORT_SYMBOL(drm_fb_helper_initial_config);

bool drm_helper_fb_hotplug_event(struct drm_fb_helper *fb_helper,
				 u32 max_width, u32 max_height, bool polled)
/* we got a hotplug irq - need to update fbcon */
void drm_helper_fb_hpd_irq_event(struct drm_fb_helper *fb_helper)
{
	/* if we don't have the fbdev registered yet do nothing */
	if (!fb_helper->fbdev)
		return;

	/* schedule a slow work asap */
	delayed_slow_work_enqueue(&fb_helper->output_status_change_slow_work, 0);
}
EXPORT_SYMBOL(drm_helper_fb_hpd_irq_event);

bool drm_helper_fb_hotplug_event(struct drm_fb_helper *fb_helper, bool polled)
{
	int count = 0;
	int ret;
	u32 max_width, max_height, bpp_sel;

	if (!fb_helper->fb)
		return false;
	DRM_DEBUG_KMS("\n");

	max_width = fb_helper->fb->width;
	max_height = fb_helper->fb->height;
	bpp_sel = fb_helper->fb->bits_per_pixel;

	count = drm_fb_helper_probe_connector_modes(fb_helper, max_width,
						    max_height);
	if (fb_helper->poll_enabled && !polled) {
		if (count) {
			delayed_slow_work_cancel(&fb_helper->output_poll_slow_work);
			delayed_slow_work_cancel(&fb_helper->output_status_change_slow_work);
		} else {
			ret = delayed_slow_work_enqueue(&fb_helper->output_poll_slow_work, 5*HZ);
			ret = delayed_slow_work_enqueue(&fb_helper->output_status_change_slow_work, 5*HZ);
		}
	}
	drm_setup_crtcs(fb_helper);

	return true;
	return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
}
EXPORT_SYMBOL(drm_helper_fb_hotplug_event);

static void output_poll_execute(struct slow_work *work)
/*
 * delayed work queue execution function
 * - check if fbdev is actually in use on the gpu
 *   - if not set delayed flag and repoll if necessary
 * - check for connector status change
 * - repoll if 0 modes found
 *- call driver output status changed notifier
 */
static void output_status_change_execute(struct slow_work *work)
{
	struct delayed_slow_work *delayed_work = container_of(work, struct delayed_slow_work, work);
	struct drm_fb_helper *fb_helper = container_of(delayed_work, struct drm_fb_helper, output_poll_slow_work);
	struct drm_device *dev = fb_helper->dev;
	struct drm_fb_helper *fb_helper = container_of(delayed_work, struct drm_fb_helper, output_status_change_slow_work);
	struct drm_connector *connector;
	enum drm_connector_status old_status, status;
	bool repoll = true, changed = false;
	bool repoll, changed = false;
	int ret;
	int i;
	bool bound = false, crtcs_bound = false;
	struct drm_crtc *crtc;

	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
	repoll = fb_helper->poll_enabled;

	/* first of all check the fbcon framebuffer is actually bound to any crtc */
	/* take into account that no crtc at all maybe bound */
	list_for_each_entry(crtc, &fb_helper->dev->mode_config.crtc_list, head) {
		if (crtc->fb)
			crtcs_bound = true;
		if (crtc->fb == fb_helper->fb)
			bound = true;
	}

	if (bound == false && crtcs_bound) {
		fb_helper->delayed_hotplug = true;
		goto requeue;
	}

	for (i = 0; i < fb_helper->connector_count; i++) {
		connector = fb_helper->connector_info[i]->connector;
		old_status = connector->status;
		status = connector->funcs->detect(connector);
		if (old_status != status) {
			changed = true;
			/* something changed */
		}
		if (status == connector_status_connected) {
		if (status == connector_status_connected && repoll) {
			DRM_DEBUG("%s is connected - stop polling\n", drm_get_connector_name(connector));
			repoll = false;
		}
	}

	if (changed) {
		if (fb_helper->funcs->fb_output_status_changed)
			fb_helper->funcs->fb_output_status_changed(fb_helper);
	}

requeue:
	if (repoll) {
		ret = delayed_slow_work_enqueue(delayed_work, 5*HZ);
		if (ret)
			DRM_ERROR("delayed enqueue failed %d\n", ret);
	}

	if (changed) {
		if (fb_helper->fb_poll_changed)
			fb_helper->fb_poll_changed(fb_helper);
	}
}

struct slow_work_ops output_poll_ops = {
	.execute = output_poll_execute,
static struct slow_work_ops output_status_change_ops = {
	.execute = output_status_change_execute,
};
void drm_fb_helper_poll_init(struct drm_fb_helper *fb_helper)
{
	int ret;

	ret = slow_work_register_user(THIS_MODULE);

	delayed_slow_work_init(&fb_helper->output_poll_slow_work, &output_poll_ops);
	fb_helper->poll_enabled = true;
}
EXPORT_SYMBOL(drm_fb_helper_poll_init);

void drm_fb_helper_poll_fini(struct drm_fb_helper *fb_helper)
{
	delayed_slow_work_cancel(&fb_helper->output_poll_slow_work);
	slow_work_unregister_user(THIS_MODULE);
}
EXPORT_SYMBOL(drm_fb_helper_poll_fini);
+1 −0
Original line number Diff line number Diff line
@@ -266,6 +266,7 @@ static void i915_hotplug_work_func(struct work_struct *work)
		}
	}
	/* Just fire off a uevent and let userspace tell us what to do */
	intelfb_hotplug(dev, false);
	drm_sysfs_hotplug_event(dev);
}

+2 −0
Original line number Diff line number Diff line
@@ -228,4 +228,6 @@ extern int intel_overlay_put_image(struct drm_device *dev, void *data,
				   struct drm_file *file_priv);
extern int intel_overlay_attrs(struct drm_device *dev, void *data,
			       struct drm_file *file_priv);

void intelfb_hotplug(struct drm_device *dev, bool polled);
#endif /* __INTEL_DRV_H__ */
+23 −19
Original line number Diff line number Diff line
@@ -65,12 +65,6 @@ static struct fb_ops intelfb_ops = {
	.fb_setcmap = drm_fb_helper_setcmap,
};

static struct drm_fb_helper_funcs intel_fb_helper_funcs = {
	.gamma_set = intel_crtc_fb_gamma_set,
	.gamma_get = intel_crtc_fb_gamma_get,
};


static int intelfb_create(struct intel_fbdev *ifbdev,
			  struct drm_fb_helper_surface_size *sizes)
{
@@ -129,7 +123,6 @@ static int intelfb_create(struct intel_fbdev *ifbdev,

	ifbdev->helper.fb = fb;
	ifbdev->helper.fbdev = info;
	ifbdev->helper.funcs = &intel_fb_helper_funcs;

	strcpy(info->fix.id, "inteldrmfb");

@@ -154,6 +147,12 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
		ret = -ENOSPC;
		goto out_unpin;
	}

	ret = fb_alloc_cmap(&info->cmap, 256, 0);
	if (ret) {
		ret = -ENOMEM;
		goto out_unpin;
	}
	info->screen_size = size;

//	memset(info->screen_base, 0, size);
@@ -205,15 +204,18 @@ static int intel_fb_find_or_create_single(struct drm_fb_helper *helper,
	return new_fb;
}

static int intelfb_probe(struct intel_fbdev *ifbdev)
void intelfb_hotplug(struct drm_device *dev, bool polled)
{
	int ret;

	DRM_DEBUG_KMS("\n");
	ret = drm_fb_helper_single_fb_probe(&ifbdev->helper, 32);
	return ret;
	drm_i915_private_t *dev_priv = dev->dev_private;
	drm_helper_fb_hpd_irq_event(&dev_priv->fbdev->helper);
}

static struct drm_fb_helper_funcs intel_fb_helper_funcs = {
	.gamma_set = intel_crtc_fb_gamma_set,
	.gamma_get = intel_crtc_fb_gamma_get,
	.fb_probe = intel_fb_find_or_create_single,
};

int intel_fbdev_destroy(struct drm_device *dev,
			struct intel_fbdev *ifbdev)
{
@@ -224,10 +226,12 @@ int intel_fbdev_destroy(struct drm_device *dev,
		info = ifbdev->helper.fbdev;
		unregister_framebuffer(info);
		iounmap(info->screen_base);
		if (info->cmap.len)
			fb_dealloc_cmap(&info->cmap);
		framebuffer_release(info);
	}

	drm_fb_helper_free(&ifbdev->helper);
	drm_fb_helper_fini(&ifbdev->helper);

	drm_framebuffer_cleanup(&ifb->base);
	if (ifb->obj)
@@ -246,13 +250,13 @@ int intel_fbdev_init(struct drm_device *dev)
		return -ENOMEM;

	dev_priv->fbdev = ifbdev;
	ifbdev->helper.funcs = &intel_fb_helper_funcs;

	drm_fb_helper_init(dev, &ifbdev->helper, 2,
			   INTELFB_CONN_LIMIT, false);

	drm_fb_helper_init_crtc_count(dev, &ifbdev->helper, 2,
				      INTELFB_CONN_LIMIT);
	drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
	ifbdev->helper.fb_probe = intel_fb_find_or_create_single;
	drm_fb_helper_initial_config(&ifbdev->helper);
	intelfb_probe(ifbdev);
	drm_fb_helper_initial_config(&ifbdev->helper, 32);
	return 0;
}

+28 −17
Original line number Diff line number Diff line
@@ -156,11 +156,6 @@ static void nouveau_fbcon_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
	*blue = nv_crtc->lut.b[regno];
}

static struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = {
	.gamma_set = nouveau_fbcon_gamma_set,
	.gamma_get = nouveau_fbcon_gamma_get
};

#if defined(__i386__) || defined(__x86_64__)
static bool
nouveau_fbcon_has_vesafb_or_efifb(struct drm_device *dev)
@@ -272,6 +267,12 @@ nouveau_fbcon_create(struct nouveau_fbdev *nfbdev,
		goto out_unref;
	}

	ret = fb_alloc_cmap(&info->cmap, 256, 0);
	if (ret) {
		ret = -ENOMEM;
		goto out_unref;
	}

	info->par = nfbdev;

	nouveau_framebuffer_init(dev, &nfbdev->nouveau_fb, &mode_cmd, nvbo);
@@ -282,7 +283,6 @@ nouveau_fbcon_create(struct nouveau_fbdev *nfbdev,
	/* setup helper */
	nfbdev->helper.fb = fb;
	nfbdev->helper.fbdev = info;
	nfbdev->helper.funcs = &nouveau_fbcon_helper_funcs;

	strcpy(info->fix.id, "nouveaufb");
	if (nouveau_nofbaccel)
@@ -381,12 +381,15 @@ nouveau_fbcon_find_or_create_single(struct drm_fb_helper *helper,
	return new_fb;
}

static int
nouveau_fbcon_probe(struct nouveau_fbdev *nfbdev)
void nouveau_fbcon_hotplug(struct drm_device *dev)
{
	NV_DEBUG_KMS(nfbdev->dev, "\n");
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	drm_helper_fb_hpd_irq_event(&dev_priv->nfbdev->helper);
}

	return drm_fb_helper_single_fb_probe(&nfbdev->helper, 32);
static void nouveau_fbcon_output_status_changed(struct drm_fb_helper *fb_helper)
{
	drm_helper_fb_hotplug_event(fb_helper, true);
}

int
@@ -398,6 +401,8 @@ nouveau_fbcon_destroy(struct drm_device *dev, struct nouveau_fbdev *nfbdev)
	if (nfbdev->helper.fbdev) {
		info = nfbdev->helper.fbdev;
		unregister_framebuffer(info);
		if (info->cmap.len)
			fb_dealloc_cmap(&info->cmap);
		framebuffer_release(info);
	}

@@ -406,7 +411,7 @@ nouveau_fbcon_destroy(struct drm_device *dev, struct nouveau_fbdev *nfbdev)
		drm_gem_object_unreference_unlocked(nouveau_fb->nvbo->gem);
		nouveau_fb->nvbo = NULL;
	}
	drm_fb_helper_free(&nfbdev->helper);
	drm_fb_helper_fini(&nfbdev->helper);
	drm_framebuffer_cleanup(&nouveau_fb->base);
	return 0;
}
@@ -420,6 +425,14 @@ void nouveau_fbcon_gpu_lockup(struct fb_info *info)
	info->flags |= FBINFO_HWACCEL_DISABLED;
}

static struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = {
	.gamma_set = nouveau_fbcon_gamma_set,
	.gamma_get = nouveau_fbcon_gamma_get,
	.fb_probe = nouveau_fbcon_find_or_create_single,
	.fb_output_status_changed = nouveau_fbcon_output_status_changed,
};


int nouveau_fbcon_init(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
@@ -431,14 +444,12 @@ int nouveau_fbcon_init(struct drm_device *dev)

	nfbdev->dev = dev;
	dev_priv->nfbdev = nfbdev;
	nfbdev->helper.funcs = &nouveau_fbcon_helper_funcs;

	drm_fb_helper_init_crtc_count(dev, &nfbdev->helper,
				      2, 4);
	nfbdev->helper.fb_probe = nouveau_fbcon_find_or_create_single;
	drm_fb_helper_init(dev, &nfbdev->helper,
			   2, 4, true);
	drm_fb_helper_single_add_all_connectors(&nfbdev->helper);

	drm_fb_helper_initial_config(&nfbdev->helper);
	nouveau_fbcon_probe(nfbdev);
	drm_fb_helper_initial_config(&nfbdev->helper, 32);
	return 0;
}

Loading