mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mihail Atanassov <mihail.atanassov@arm.com>
To: <dri-devel@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Sean Paul <seanpaul@chromium.org>,
	"David Airlie" <airlied@linux.ie>,
	Liviu Dudau <liviu.dudau@arm.com>,
	Brian Starkey <brian.starkey@arm.com>,
	<linux-kernel@vger.kernel.org>, <nd@arm.com>
Subject: [PATCH] drm: Add helper macro for duplicating custom drm_*_state
Date: Thu, 9 Feb 2017 15:41:42 +0000	[thread overview]
Message-ID: <1486654902-2558-2-git-send-email-mihail.atanassov@arm.com> (raw)
In-Reply-To: <1486654902-2558-1-git-send-email-mihail.atanassov@arm.com>

Assuming a derived struct of the form:

struct foo_bar_state
{
	struct drm_bar_state bar_state;
	struct foo_private priv;
	struct foo_private2 *priv2;
};

memcpy priv and priv2 to the new instance of foo_bar_state. The
intention is to use this macro in ->atomic_duplicate_state in conjunction with
__drm_atomic_helper_*_duplicate_state, which already copies the relevant
drm_*_state struct.

There's an equality check for new_state and old_state to ensure that
they are distinct instances of the same type, and a BUILD_BUG if the
base struct (bar_state in the above example) is not first in the derived
struct, to avoid missing any data before it and corrupting the base's data.

Signed-off-by: Mihail Atanassov <mihail.atanassov@arm.com>
---
 include/drm/drm_atomic_helper.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index d066e94..ecc6a82 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -171,6 +171,39 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
 				       uint32_t size);
 
 /**
+ * drm_atomic_duplicate_custom_state - helper macro for duplicating
+ * driver-private additions to drm_*_state.
+ * @new_state: pointer to destination state struct
+ * @old_state: pointer to source state struct
+ * @basename: name of the drm_*_state member of the new_state/old_state struct
+ *
+ * Copies the data after the base struct until the end of the custom struct,
+ * e.g. given a structure
+ *
+ * struct foo_bar_state {
+ * 	struct drm_bar_state base;
+ * 	struct foo_private priv;
+ * 	struct foo_private2 *priv2;
+ * };
+ *
+ * this copies priv and priv2. NB: the base struct *must* be the first element
+ * of the derived struct, and new_state and old_state have to be two distinct
+ * instances.
+ */
+#define drm_atomic_helper_duplicate_custom_state(new_state, old_state, basename) \
+	do { \
+		size_t base_size = sizeof(new_state->basename); \
+		size_t base_offset = offsetof(typeof(*new_state), basename); \
+		\
+		BUILD_BUG_ON(base_offset != 0); \
+		if (new_state == old_state) /* Type-check */ \
+			break; \
+		memcpy((char *)new_state + base_size, \
+		       (char *)old_state + base_size, \
+		       sizeof(*new_state) - base_size); \
+	} while(0)
+
+/**
  * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
  * @plane: the loop cursor
  * @crtc:  the crtc whose planes are iterated
-- 
1.9.1

  reply	other threads:[~2017-02-09 16:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 15:41 [RFC] drm: Helper macro for drm state duplication Mihail Atanassov
2017-02-09 15:41 ` Mihail Atanassov [this message]
2017-02-09 17:35   ` [PATCH] drm: Add helper macro for duplicating custom drm_*_state Daniel Vetter
2017-02-09 17:38   ` Daniel Vetter
2017-02-09 16:57 ` [RFC] drm: Helper macro for drm state duplication Daniel Vetter
2017-02-09 17:18   ` Liviu Dudau

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=1486654902-2558-2-git-send-email-mihail.atanassov@arm.com \
    --to=mihail.atanassov@arm.com \
    --cc=airlied@linux.ie \
    --cc=brian.starkey@arm.com \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=nd@arm.com \
    --cc=seanpaul@chromium.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: 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

all inboxes | Powered by JetHome®