From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> To: dri-devel@lists.freedesktop.org Cc: linux-sh@vger.kernel.org Subject: [PATCH 29/38] drm: rcar-du: Implement asynchronous commit support Date: Wed, 25 Feb 2015 21:54:49 +0000 [thread overview] Message-ID: <1424901298-6829-30-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw) In-Reply-To: <1424901298-6829-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Implement a custom .atomic_commit() handler that supports asynchronous commits using a work queue. This can be used for userspace-driven asynchronous commits, as well as for an atomic page flip implementation. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> --- drivers/gpu/drm/rcar-du/rcar_du_drv.c | 3 + drivers/gpu/drm/rcar-du/rcar_du_drv.h | 6 ++ drivers/gpu/drm/rcar-du/rcar_du_kms.c | 105 +++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c index 8ab4c69c599b..1d9e4f8568ae 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c @@ -19,6 +19,7 @@ #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/slab.h> +#include <linux/wait.h> #include <drm/drmP.h> #include <drm/drm_crtc_helper.h> @@ -163,6 +164,8 @@ static int rcar_du_load(struct drm_device *dev, unsigned long flags) return -ENOMEM; } + init_waitqueue_head(&rcdu->commit.wait); + rcdu->dev = &pdev->dev; rcdu->info = np ? of_match_device(rcar_du_of_table, rcdu->dev)->data : (void *)platform_get_device_id(pdev)->driver_data; diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.h b/drivers/gpu/drm/rcar-du/rcar_du_drv.h index d1ede13cb1d5..c7c538dd2e68 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.h @@ -15,6 +15,7 @@ #define __RCAR_DU_DRV_H__ #include <linux/kernel.h> +#include <linux/wait.h> #include "rcar_du_crtc.h" #include "rcar_du_group.h" @@ -84,6 +85,11 @@ struct rcar_du_device { unsigned int dpad0_source; struct rcar_du_lvdsenc *lvds[RCAR_DU_MAX_LVDS]; + + struct { + wait_queue_head_t wait; + u32 pending; + } commit; }; static inline bool rcar_du_has(struct rcar_du_device *rcdu, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-du/rcar_du_kms.c index 2b36f4f2980f..cec35e405248 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -12,6 +12,7 @@ */ #include <drm/drmP.h> +#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_crtc.h> #include <drm/drm_crtc_helper.h> @@ -19,6 +20,7 @@ #include <drm/drm_gem_cma_helper.h> #include <linux/of_graph.h> +#include <linux/wait.h> #include "rcar_du_crtc.h" #include "rcar_du_drv.h" @@ -186,11 +188,112 @@ static void rcar_du_output_poll_changed(struct drm_device *dev) drm_fbdev_cma_hotplug_event(rcdu->fbdev); } +/* ----------------------------------------------------------------------------- + * Atomic Updates + */ + +struct rcar_du_commit { + struct work_struct work; + struct drm_device *dev; + struct drm_atomic_state *state; + u32 crtcs; +}; + +static void rcar_du_atomic_complete(struct rcar_du_commit *commit) +{ + struct drm_device *dev = commit->dev; + struct rcar_du_device *rcdu = dev->dev_private; + struct drm_atomic_state *old_state = commit->state; + + /* Apply the atomic update. */ + drm_atomic_helper_commit_modeset_disables(dev, old_state); + drm_atomic_helper_commit_planes(dev, old_state); + drm_atomic_helper_commit_modeset_enables(dev, old_state); + + drm_atomic_helper_wait_for_vblanks(dev, old_state); + + drm_atomic_helper_cleanup_planes(dev, old_state); + + drm_atomic_state_free(old_state); + + /* Complete the commit, wake up any waiter. */ + spin_lock(&rcdu->commit.wait.lock); + rcdu->commit.pending &= ~commit->crtcs; + wake_up_all_locked(&rcdu->commit.wait); + spin_unlock(&rcdu->commit.wait.lock); + + kfree(commit); +} + +static void rcar_du_atomic_work(struct work_struct *work) +{ + struct rcar_du_commit *commit + container_of(work, struct rcar_du_commit, work); + + rcar_du_atomic_complete(commit); +} + +static int rcar_du_atomic_commit(struct drm_device *dev, + struct drm_atomic_state *state, bool async) +{ + struct rcar_du_device *rcdu = dev->dev_private; + struct rcar_du_commit *commit; + unsigned int i; + int ret; + + ret = drm_atomic_helper_prepare_planes(dev, state); + if (ret) + return ret; + + /* Allocate the commit object. */ + commit = kzalloc(sizeof(*commit), GFP_KERNEL); + if (commit = NULL) + return -ENOMEM; + + INIT_WORK(&commit->work, rcar_du_atomic_work); + commit->dev = dev; + commit->state = state; + + /* Wait until all affected CRTCs have completed previous commits and + * mark them as pending. + */ + for (i = 0; i < dev->mode_config.num_crtc; ++i) { + if (state->crtcs[i]) + commit->crtcs |= 1 << drm_crtc_index(state->crtcs[i]); + } + + spin_lock(&rcdu->commit.wait.lock); + ret = wait_event_interruptible_locked(rcdu->commit.wait, + !(rcdu->commit.pending & commit->crtcs)); + if (ret = 0) + rcdu->commit.pending |= commit->crtcs; + spin_unlock(&rcdu->commit.wait.lock); + + if (ret) { + kfree(commit); + return ret; + } + + /* Swap the state, this is the point of no return. */ + drm_atomic_helper_swap_state(dev, state); + + if (async) + schedule_work(&commit->work); + else + rcar_du_atomic_complete(commit); + + return 0; +} + +/* ----------------------------------------------------------------------------- + * Initialization + */ + static const struct drm_mode_config_funcs rcar_du_mode_config_funcs = { .fb_create = rcar_du_fb_create, .output_poll_changed = rcar_du_output_poll_changed, .atomic_check = drm_atomic_helper_check, - .atomic_commit = drm_atomic_helper_commit, + .atomic_commit = rcar_du_atomic_commit, }; static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu, -- 2.0.5
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> To: dri-devel@lists.freedesktop.org Cc: linux-sh@vger.kernel.org Subject: [PATCH 29/38] drm: rcar-du: Implement asynchronous commit support Date: Wed, 25 Feb 2015 23:54:49 +0200 [thread overview] Message-ID: <1424901298-6829-30-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw) In-Reply-To: <1424901298-6829-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Implement a custom .atomic_commit() handler that supports asynchronous commits using a work queue. This can be used for userspace-driven asynchronous commits, as well as for an atomic page flip implementation. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> --- drivers/gpu/drm/rcar-du/rcar_du_drv.c | 3 + drivers/gpu/drm/rcar-du/rcar_du_drv.h | 6 ++ drivers/gpu/drm/rcar-du/rcar_du_kms.c | 105 +++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c index 8ab4c69c599b..1d9e4f8568ae 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c @@ -19,6 +19,7 @@ #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/slab.h> +#include <linux/wait.h> #include <drm/drmP.h> #include <drm/drm_crtc_helper.h> @@ -163,6 +164,8 @@ static int rcar_du_load(struct drm_device *dev, unsigned long flags) return -ENOMEM; } + init_waitqueue_head(&rcdu->commit.wait); + rcdu->dev = &pdev->dev; rcdu->info = np ? of_match_device(rcar_du_of_table, rcdu->dev)->data : (void *)platform_get_device_id(pdev)->driver_data; diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.h b/drivers/gpu/drm/rcar-du/rcar_du_drv.h index d1ede13cb1d5..c7c538dd2e68 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.h +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.h @@ -15,6 +15,7 @@ #define __RCAR_DU_DRV_H__ #include <linux/kernel.h> +#include <linux/wait.h> #include "rcar_du_crtc.h" #include "rcar_du_group.h" @@ -84,6 +85,11 @@ struct rcar_du_device { unsigned int dpad0_source; struct rcar_du_lvdsenc *lvds[RCAR_DU_MAX_LVDS]; + + struct { + wait_queue_head_t wait; + u32 pending; + } commit; }; static inline bool rcar_du_has(struct rcar_du_device *rcdu, diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-du/rcar_du_kms.c index 2b36f4f2980f..cec35e405248 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -12,6 +12,7 @@ */ #include <drm/drmP.h> +#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_crtc.h> #include <drm/drm_crtc_helper.h> @@ -19,6 +20,7 @@ #include <drm/drm_gem_cma_helper.h> #include <linux/of_graph.h> +#include <linux/wait.h> #include "rcar_du_crtc.h" #include "rcar_du_drv.h" @@ -186,11 +188,112 @@ static void rcar_du_output_poll_changed(struct drm_device *dev) drm_fbdev_cma_hotplug_event(rcdu->fbdev); } +/* ----------------------------------------------------------------------------- + * Atomic Updates + */ + +struct rcar_du_commit { + struct work_struct work; + struct drm_device *dev; + struct drm_atomic_state *state; + u32 crtcs; +}; + +static void rcar_du_atomic_complete(struct rcar_du_commit *commit) +{ + struct drm_device *dev = commit->dev; + struct rcar_du_device *rcdu = dev->dev_private; + struct drm_atomic_state *old_state = commit->state; + + /* Apply the atomic update. */ + drm_atomic_helper_commit_modeset_disables(dev, old_state); + drm_atomic_helper_commit_planes(dev, old_state); + drm_atomic_helper_commit_modeset_enables(dev, old_state); + + drm_atomic_helper_wait_for_vblanks(dev, old_state); + + drm_atomic_helper_cleanup_planes(dev, old_state); + + drm_atomic_state_free(old_state); + + /* Complete the commit, wake up any waiter. */ + spin_lock(&rcdu->commit.wait.lock); + rcdu->commit.pending &= ~commit->crtcs; + wake_up_all_locked(&rcdu->commit.wait); + spin_unlock(&rcdu->commit.wait.lock); + + kfree(commit); +} + +static void rcar_du_atomic_work(struct work_struct *work) +{ + struct rcar_du_commit *commit = + container_of(work, struct rcar_du_commit, work); + + rcar_du_atomic_complete(commit); +} + +static int rcar_du_atomic_commit(struct drm_device *dev, + struct drm_atomic_state *state, bool async) +{ + struct rcar_du_device *rcdu = dev->dev_private; + struct rcar_du_commit *commit; + unsigned int i; + int ret; + + ret = drm_atomic_helper_prepare_planes(dev, state); + if (ret) + return ret; + + /* Allocate the commit object. */ + commit = kzalloc(sizeof(*commit), GFP_KERNEL); + if (commit == NULL) + return -ENOMEM; + + INIT_WORK(&commit->work, rcar_du_atomic_work); + commit->dev = dev; + commit->state = state; + + /* Wait until all affected CRTCs have completed previous commits and + * mark them as pending. + */ + for (i = 0; i < dev->mode_config.num_crtc; ++i) { + if (state->crtcs[i]) + commit->crtcs |= 1 << drm_crtc_index(state->crtcs[i]); + } + + spin_lock(&rcdu->commit.wait.lock); + ret = wait_event_interruptible_locked(rcdu->commit.wait, + !(rcdu->commit.pending & commit->crtcs)); + if (ret == 0) + rcdu->commit.pending |= commit->crtcs; + spin_unlock(&rcdu->commit.wait.lock); + + if (ret) { + kfree(commit); + return ret; + } + + /* Swap the state, this is the point of no return. */ + drm_atomic_helper_swap_state(dev, state); + + if (async) + schedule_work(&commit->work); + else + rcar_du_atomic_complete(commit); + + return 0; +} + +/* ----------------------------------------------------------------------------- + * Initialization + */ + static const struct drm_mode_config_funcs rcar_du_mode_config_funcs = { .fb_create = rcar_du_fb_create, .output_poll_changed = rcar_du_output_poll_changed, .atomic_check = drm_atomic_helper_check, - .atomic_commit = drm_atomic_helper_commit, + .atomic_commit = rcar_du_atomic_commit, }; static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu, -- 2.0.5
next prev parent reply other threads:[~2015-02-25 21:54 UTC|newest] Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-25 21:54 [PATCH 00/38] Renesas R-Car DU atomic updates support Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 01/38] drm/atomic: Rename drm_atomic_helper_commit_pre_planes() state argument Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 02/38] drm/atomic-helper: Rename commmit_post/pre_planes Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 03/38] drm/atomic-helpers: make mode_set hooks optional Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 04/38] drm/atomic-helpers: Fix documentation typos and wrong copy&paste Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 05/38] drm: adv7511: Fix DDC error interrupt handling Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 06/38] drm: adv7511: Fix nested sleep when reading EDID Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 07/38] drm: rcar-du: Don't disable unused functions at init time Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 08/38] drm: rcar-du: Remove drm_fbdev_cma_restore_mode() call " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 09/38] drm: rcar-du: Don't set connector->encoder " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 10/38] drm: rcar-du: Reorder CRTC functions Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 11/38] drm: rcar-du: Wait for page flip completion when turning the CRTC off Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 12/38] drm: rcar-du: Turn vblank on/off when enabling/disabling CRTC Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 13/38] drm: rcar-du: Disable fbdev emulation when no connector is present Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 14/38] drm: rcar-du: Define macros for the max number of groups, CRTCs and LVDS Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 15/38] drm: rcar-du: Implement universal plane support Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 16/38] drm: rcar-du: Fix hardware plane allocation Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 17/38] drm: rcar-du: Implement planes atomic operations Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 18/38] drm: rcar-du: Handle primary plane config through atomic plane ops Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 19/38] drm: rcar-du: Wire up atomic state object scaffolding Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 20/38] drm: rcar-du: Remove private copy of plane size and position Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 21/38] drm: rcar-du: Replace LVDS encoder DPMS by enable/disable Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 22/38] drm: rcar-du: Rework encoder enable/disable for atomic updates Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 23/38] drm: rcar-du: Rework HDMI " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 24/38] drm: rcar-du: Rework CRTC " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 25/38] drm: rcar-du: Switch plane update to atomic helpers Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 26/38] drm: rcar-du: Switch mode config " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 27/38] drm: rcar-du: Switch connector DPMS " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 28/38] drm: rcar-du: Replace encoder mode_fixup with atomic_check Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart [this message] 2015-02-25 21:54 ` [PATCH 29/38] drm: rcar-du: Implement asynchronous commit support Laurent Pinchart 2015-02-25 21:54 ` [PATCH 30/38] drm: rcar-du: Switch page flip to atomic helpers Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 31/38] drm: rcar-du: Switch plane set_property " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 32/38] drm: rcar-du: Rework plane setup code Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 33/38] drm: rcar-du: Replace plane crtc and enabled fields by plane state Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 34/38] drm: rcar-du: Remove unneeded rcar_du_crtc plane field Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 35/38] drm: rcar-du: Move plane format to plane state Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 36/38] drm: rcar-du: Move plane commit code from CRTC start to CRTC resume Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 37/38] drm: rcar-du: Move group locking inside rcar_du_crtc_update_planes() Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 38/38] drm: rcar-du: Fix race condition in hardware plane allocator Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-26 0:43 ` [PATCH 00/38] Renesas R-Car DU atomic updates support Magnus Damm 2015-02-26 0:43 ` Magnus Damm 2015-02-26 9:23 ` Laurent Pinchart 2015-02-26 9:23 ` Laurent Pinchart 2015-02-27 0:14 ` Magnus Damm 2015-02-27 0:14 ` Magnus Damm 2015-02-27 10:43 ` Laurent Pinchart 2015-02-27 10:43 ` Laurent Pinchart
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1424901298-6829-30-git-send-email-laurent.pinchart+renesas@ideasonboard.com \ --to=laurent.pinchart+renesas@ideasonboard.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=linux-sh@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.