dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Shawn Guo <shawnguo@kernel.org>
To: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Neil Armstrong <narmstrong@baylibre.com>,
	Liviu Dudau <liviu.dudau@arm.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Marek Vasut <marex@denx.de>,
	Alexey Brodkin <abrodkin@synopsys.com>,
	Russell King <linux@armlinux.org.uk>,
	Xinliang Liu <z.liuxinliang@hisilicon.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Mali DP Maintainers <malidp@foss.arm.com>,
	Ben Skeggs <bskeggs@redhat.com>, Jyri Sarha <jsarha@ti.com>,
	dri-devel@lists.freedesktop.org,
	Maxime Ripard <maxime.ripard@free-electrons.com>
Subject: [PATCH v3 01/23] drm: add vblank hooks to struct drm_crtc_funcs
Date: Tue,  7 Feb 2017 17:16:13 +0800	[thread overview]
Message-ID: <1486458995-31018-2-git-send-email-shawnguo@kernel.org> (raw)
In-Reply-To: <1486458995-31018-1-git-send-email-shawnguo@kernel.org>

From: Shawn Guo <shawn.guo@linaro.org>

The vblank is mostly CRTC specific and implemented as part of CRTC
driver.  Let's keep the vblank hooks struct drm_driver for legacy
drivers, and add corresponding hooks in struct drm_crtc_funcs.  These
hooks take struct drm_crtc pointer as argument, and will be called by
core vblank handling code for DRIVER_MODESET drivers.

The new hooks get plugged into core by adding wrapper functions for
vblank handling code.  The .get_vblank_counter hook is effectively
optional, as we provide drm_vblank_no_hw_counter() as the default
fallback in the wrapper function.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/gpu/drm/drm_irq.c | 53 +++++++++++++++++++++++++++++++++++++++++------
 include/drm/drm_crtc.h    | 44 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_drv.h     |  9 ++++++++
 3 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index e06cf11ebb4a..646b3e57b9ad 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -89,6 +89,21 @@ static void store_vblank(struct drm_device *dev, unsigned int pipe,
 	write_sequnlock(&vblank->seqlock);
 }
 
+static u32 __get_vblank_counter(struct drm_device *dev, unsigned int pipe)
+{
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		if (crtc->funcs->get_vblank_counter)
+			return crtc->funcs->get_vblank_counter(crtc);
+	}
+
+	if (dev->driver->get_vblank_counter)
+		return dev->driver->get_vblank_counter(dev, pipe);
+
+	return drm_vblank_no_hw_counter(dev, pipe);
+}
+
 /*
  * Reset the stored timestamp for the current vblank count to correspond
  * to the last vblank occurred.
@@ -112,9 +127,9 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
 	 * when drm_vblank_enable() applies the diff
 	 */
 	do {
-		cur_vblank = dev->driver->get_vblank_counter(dev, pipe);
+		cur_vblank = __get_vblank_counter(dev, pipe);
 		rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, 0);
-	} while (cur_vblank != dev->driver->get_vblank_counter(dev, pipe) && --count > 0);
+	} while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0);
 
 	/*
 	 * Only reinitialize corresponding vblank timestamp if high-precision query
@@ -168,9 +183,9 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe,
 	 * corresponding vblank timestamp.
 	 */
 	do {
-		cur_vblank = dev->driver->get_vblank_counter(dev, pipe);
+		cur_vblank = __get_vblank_counter(dev, pipe);
 		rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, flags);
-	} while (cur_vblank != dev->driver->get_vblank_counter(dev, pipe) && --count > 0);
+	} while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0);
 
 	if (dev->max_vblank_count != 0) {
 		/* trust the hw counter when it's around */
@@ -275,6 +290,20 @@ u32 drm_accurate_vblank_count(struct drm_crtc *crtc)
 }
 EXPORT_SYMBOL(drm_accurate_vblank_count);
 
+static void __disable_vblank(struct drm_device *dev, unsigned int pipe)
+{
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		if (crtc->funcs->disable_vblank) {
+			crtc->funcs->disable_vblank(crtc);
+			return;
+		}
+	}
+
+	dev->driver->disable_vblank(dev, pipe);
+}
+
 /*
  * Disable vblank irq's on crtc, make sure that last vblank count
  * of hardware and corresponding consistent software vblank counter
@@ -298,7 +327,7 @@ static void vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
 	 * hardware potentially runtime suspended.
 	 */
 	if (vblank->enabled) {
-		dev->driver->disable_vblank(dev, pipe);
+		__disable_vblank(dev, pipe);
 		vblank->enabled = false;
 	}
 
@@ -1027,6 +1056,18 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 }
 EXPORT_SYMBOL(drm_crtc_send_vblank_event);
 
+static int __enable_vblank(struct drm_device *dev, unsigned int pipe)
+{
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		if (crtc->funcs->enable_vblank)
+			return crtc->funcs->enable_vblank(crtc);
+	}
+
+	return dev->driver->enable_vblank(dev, pipe);
+}
+
 /**
  * drm_vblank_enable - enable the vblank interrupt on a CRTC
  * @dev: DRM device
@@ -1052,7 +1093,7 @@ static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
 		 * timestamps. Filtercode in drm_handle_vblank() will
 		 * prevent double-accounting of same vblank interval.
 		 */
-		ret = dev->driver->enable_vblank(dev, pipe);
+		ret = __enable_vblank(dev, pipe);
 		DRM_DEBUG("enabling vblank on crtc %u, ret: %d\n", pipe, ret);
 		if (ret)
 			atomic_dec(&vblank->refcount);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 8f0b195e4a59..4323acefa596 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -601,6 +601,50 @@ struct drm_crtc_funcs {
 	 */
 	void (*atomic_print_state)(struct drm_printer *p,
 				   const struct drm_crtc_state *state);
+
+	/**
+	 * @get_vblank_counter:
+	 *
+	 * Driver callback for fetching a raw hardware vblank counter for the
+	 * CRTC. It's meant to be used by new drivers as the replacement of
+	 * &drm_driver.get_vblank_counter hook.
+	 *
+	 * This callback is optional. If a device doesn't have a hardware
+	 * counter, the driver can simply leave the hook as NULL. The DRM core
+	 * will account for missed vblank events while interrupts where disabled
+	 * based on system timestamps.
+	 *
+	 * Wraparound handling and loss of events due to modesetting is dealt
+	 * with in the DRM core code, as long as drivers call
+	 * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
+	 * enabling a CRTC.
+	 *
+	 * Returns:
+	 *
+	 * Raw vblank counter value.
+	 */
+	u32 (*get_vblank_counter)(struct drm_crtc *crtc);
+
+	/**
+	 * @enable_vblank:
+	 *
+	 * Enable vblank interrupts for the CRTC. It's meant to be used by
+	 * new drivers as the replacement of &drm_driver.enable_vblank hook.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, appropriate errno if the vblank interrupt cannot
+	 * be enabled.
+	 */
+	int (*enable_vblank)(struct drm_crtc *crtc);
+
+	/**
+	 * @disable_vblank:
+	 *
+	 * Disable vblank interrupts for the CRTC. It's meant to be used by
+	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
+	 */
+	void (*disable_vblank)(struct drm_crtc *crtc);
 };
 
 /**
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index f2c0040ddc3a..40ae89106594 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -130,6 +130,9 @@ struct drm_driver {
 	 * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
 	 * enabling a CRTC.
 	 *
+	 * This is deprecated and should not be used by new drivers.
+	 * Use &drm_crtc_funcs.get_vblank_counter instead.
+	 *
 	 * Returns:
 	 *
 	 * Raw vblank counter value.
@@ -142,6 +145,9 @@ struct drm_driver {
 	 * Enable vblank interrupts for the CRTC specified with the pipe
 	 * argument.
 	 *
+	 * This is deprecated and should not be used by new drivers.
+	 * Use &drm_crtc_funcs.enable_vblank instead.
+	 *
 	 * Returns:
 	 *
 	 * Zero on success, appropriate errno if the given @crtc's vblank
@@ -154,6 +160,9 @@ struct drm_driver {
 	 *
 	 * Disable vblank interrupts for the CRTC specified with the pipe
 	 * argument.
+	 *
+	 * This is deprecated and should not be used by new drivers.
+	 * Use &drm_crtc_funcs.disable_vblank instead.
 	 */
 	void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
 
-- 
1.9.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-02-07  9:17 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-07  9:16 [PATCH v3 00/23] Add vblank hooks to struct drm_crtc_funcs Shawn Guo
2017-02-07  9:16 ` Shawn Guo [this message]
2017-02-07 10:38   ` [PATCH v3 01/23] drm: add " Andrzej Hajda
2017-02-07 10:52     ` Daniel Vetter
2017-02-07 11:50       ` Thierry Reding
2017-02-07 11:04   ` Thierry Reding
2017-02-07 14:01   ` Laurent Pinchart
2017-02-07  9:16 ` [PATCH v3 02/23] drm: remove drm_vblank_no_hw_counter assignment from driver code Shawn Guo
2017-02-07  9:27   ` Maxime Ripard
2017-02-07  9:46   ` Boris Brezillon
2017-02-07 10:09   ` Neil Armstrong
2017-02-07 10:22   ` Russell King - ARM Linux
2017-02-07 10:42   ` Laurent Pinchart
2017-02-07 10:44     ` Russell King - ARM Linux
2017-02-07 10:58       ` Laurent Pinchart
2017-02-07 11:01       ` Thierry Reding
2017-02-07 11:54   ` Alexey Brodkin
2017-02-07 15:21   ` Liviu Dudau
2017-02-08 19:58   ` Eric Anholt
2017-02-07  9:16 ` [PATCH v3 03/23] drm: unexport function drm_vblank_no_hw_counter() Shawn Guo
2017-02-07 10:56   ` Laurent Pinchart
2017-02-07  9:16 ` [PATCH v3 04/23] drm: hdlcd: use vblank hooks in struct drm_crtc_funcs Shawn Guo
2017-02-07  9:16 ` [PATCH v3 05/23] drm: malidp: " Shawn Guo
2017-02-07 15:22   ` Liviu Dudau
2017-02-07  9:16 ` [PATCH v3 06/23] drm: armada: " Shawn Guo
2017-02-07 10:23   ` Russell King - ARM Linux
2017-02-07  9:16 ` [PATCH v3 07/23] drm: atmel: " Shawn Guo
2017-02-07  9:46   ` Boris Brezillon
2017-02-07  9:16 ` [PATCH v3 08/23] drm: exynos: " Shawn Guo
2017-02-07 10:47   ` Andrzej Hajda
2017-02-07  9:16 ` [PATCH v3 09/23] drm: fsl-dcu: " Shawn Guo
2017-02-08  5:01   ` Stefan Agner
2017-02-08 12:04     ` Daniel Vetter
2017-02-07  9:16 ` [PATCH v3 10/23] drm: hibmc: " Shawn Guo
2017-02-08 15:39   ` Sean Paul
2017-02-16  3:28   ` Xinliang Liu
2017-02-07  9:16 ` [PATCH v3 11/23] drm: kirin: " Shawn Guo
2017-02-16  3:23   ` Xinliang Liu
2017-02-21 16:20     ` Sean Paul
2017-02-07  9:16 ` [PATCH v3 12/23] drm: imx: remove struct imx_drm_crtc and imx_drm_crtc_helper_funcs Shawn Guo
2017-02-07 10:10   ` Philipp Zabel
2017-02-07  9:16 ` [PATCH v3 13/23] drm: mediatek: use vblank hooks in struct drm_crtc_funcs Shawn Guo
2017-02-21 16:21   ` Sean Paul
2017-02-07  9:16 ` [PATCH v3 14/23] drm: meson: " Shawn Guo
2017-02-07 10:09   ` Neil Armstrong
2017-02-07  9:16 ` [PATCH v3 15/23] drm: qxl: " Shawn Guo
2017-02-21 16:21   ` Sean Paul
2017-02-07  9:16 ` [PATCH v3 16/23] drm: rcar-du: " Shawn Guo
2017-02-07 14:03   ` Laurent Pinchart
2017-02-07  9:16 ` [PATCH v3 17/23] drm: rockchip: remove struct rockchip_crtc_funcs Shawn Guo
2017-02-07 15:35   ` Sean Paul
2017-02-07  9:16 ` [PATCH v3 18/23] drm: shmobile: use vblank hooks in struct drm_crtc_funcs Shawn Guo
2017-02-07 14:05   ` Laurent Pinchart
2017-02-07  9:16 ` [PATCH v3 19/23] drm: sun4i: " Shawn Guo
2017-02-07  9:28   ` Maxime Ripard
2017-02-07  9:16 ` [PATCH v3 20/23] drm: tegra: " Shawn Guo
2017-02-07 11:02   ` Thierry Reding
2017-02-07  9:16 ` [PATCH v3 21/23] drm: tilcdc: " Shawn Guo
2017-02-07  9:38   ` Jyri Sarha
2017-02-07  9:16 ` [PATCH v3 22/23] drm: vc4: " Shawn Guo
2017-02-08 19:56   ` Eric Anholt
2017-02-07  9:16 ` [PATCH v3 23/23] drm: zte: " Shawn Guo
2017-02-07 15:34   ` Sean Paul
2017-02-08 11:30 ` [PATCH v3 00/23] Add vblank hooks to " Tomi Valkeinen
2017-02-08 18:10   ` Laurent Pinchart
2017-02-08 18:24     ` Daniel Vetter
2017-02-08 15:49 ` Sean Paul
2017-02-09  8:36   ` Shawn Guo

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=1486458995-31018-2-git-send-email-shawnguo@kernel.org \
    --to=shawnguo@kernel.org \
    --cc=abrodkin@synopsys.com \
    --cc=bskeggs@redhat.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jsarha@ti.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux@armlinux.org.uk \
    --cc=liviu.dudau@arm.com \
    --cc=malidp@foss.arm.com \
    --cc=marex@denx.de \
    --cc=maxime.ripard@free-electrons.com \
    --cc=narmstrong@baylibre.com \
    --cc=tomi.valkeinen@ti.com \
    --cc=z.liuxinliang@hisilicon.com \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).