From patchwork Thu Feb 9 15:41:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihail Atanassov X-Patchwork-Id: 9565223 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A29C601C3 for ; Thu, 9 Feb 2017 17:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48E9F2849B for ; Thu, 9 Feb 2017 17:15:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DC9928541; Thu, 9 Feb 2017 17:15:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D0DE02849B for ; Thu, 9 Feb 2017 17:15:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 34F5F6EB46; Thu, 9 Feb 2017 17:15:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0054.outbound.protection.outlook.com [104.47.2.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id A74956EB46 for ; Thu, 9 Feb 2017 17:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=bwRXeWkLpZU5A3D+CgrcV/0kFdzPkgVAptWqwjsDTjY=; b=RiHiIJWo5KhddBYjYOo14mECLs397JA2aDhH+S0+ob2LhRLBWD8wGwN77+nzO2iX6HRqB6vjquNxdzu++TUFAblG+A4KfKzwbyOPtfiZGuczCa1DyAKaiuRtdYkz+XpBCEapKswOc+U1C+BXbcVlbwgLLQEiMjG2/iO72xbZG6A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Mihail.Atanassov@arm.com; Received: from e110433-lin.cambridge.arm.com (217.140.96.140) by HE1PR08MB0892.eurprd08.prod.outlook.com (10.164.53.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Thu, 9 Feb 2017 15:41:48 +0000 From: Mihail Atanassov To: Subject: [PATCH] drm: Add helper macro for duplicating custom drm_*_state Date: Thu, 9 Feb 2017 15:41:42 +0000 Message-ID: <1486654902-2558-2-git-send-email-mihail.atanassov@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486654902-2558-1-git-send-email-mihail.atanassov@arm.com> References: <1486654902-2558-1-git-send-email-mihail.atanassov@arm.com> MIME-Version: 1.0 X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: HE1PR0701CA0046.eurprd07.prod.outlook.com (10.168.191.14) To HE1PR08MB0892.eurprd08.prod.outlook.com (10.164.53.30) X-MS-Office365-Filtering-Correlation-Id: 5677f36b-5ef7-47fb-15b8-08d451022971 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:HE1PR08MB0892; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0892; 3:3R8WMoN0rv+Ucq+Ottm+Oi2sQgzOwulTNTxgs+0gY4Qp8KE0qWswxuice4fXgeo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mP2UlXg6OeCNsdBpMCd9u7Lh9AkZIvCMnfMggMyWjdIOr1SVG6we7BW4J+jXpMoAYaq+MtxlOT2/8TH9U9jhES1VcsmM8P8DnTR3n1dimOG+fpOa2b2h4hOTMTqUtEThiqoQ= NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123560025)(20161123555025)(20161123564025)(20161123558025)(6072148); SRVR:HE1PR08MB0892; BCL:0; PCL:0; RULEID:; SRVR:HE1PR08MB0892; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0892; 4:HYq3PjSPA2yAkq9VvkTevELXJTrOp6eLTY73CjcuXqGPJuRRv0Wm8F+lNYc83hVMOPwLVrJbMLF5WIdBKXBW1m1tnRPWZtoZatjuBfR8e2VwuvYYViw2SH48GhXw3mhIdvc4OS0h+1g/pPeyuMQvwf7FQCrBUQ/Svrw/21uQ5XmhCC8+Vmm5WFKWXB9BjLb/VDmv95VDX5E0qRLd8sa6J/S3V9vzcUBFh+xosh6L249IUdRAW+DRJPtFcIjbXSrXG8cvVSx8eF0vdEYcaGl5Krn1vlUO4iB0AvlB09oczKegMI/N8gFDCKbl2Z+6sYZBkn+YtOYv9kfwzGKLeXiyso0+Rf1lVNfVxlRMOWAfSx8YMgxybh8JzTcvJQBliK34LLzEvhbg3/jIzCf3/u6rJrVLZBziPZDs8aW/xmXQzNF0udbzSGmcqn56+mWa4KUKT8kCXaDxrHJ7P6PWiMeD8vrOusd1Cn/i9QKKKY04eoDrQGlmlcyuPp65ouNzf904pXIUZDgFHkEwV1KAE8iSA0ImwQltBbtDyfmR7NMFbJpwjugS823XwbDBnQRjZ8WBhrGIYNZRIh/K/rekRKR2BylpAXOGct6t6fSUY1yPrus/Ath6mEi/+0WwkRDapestExRylGd90Uiyl4iZ+B3iELyks6BwrfvBXVWQ0OW+AkE= X-Forefront-PRVS: 02135EB356 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39850400002)(39410400002)(39860400002)(39450400003)(39840400002)(199003)(189002)(2906002)(54906002)(4326007)(76176999)(66066001)(97736004)(50986999)(189998001)(101416001)(106356001)(47776003)(5003940100001)(5890100001)(53936002)(2351001)(6486002)(33646002)(6116002)(50466002)(68736007)(42186005)(25786008)(48376002)(105586002)(86362001)(2950100002)(36756003)(81166006)(92566002)(7736002)(305945005)(50226002)(8676002)(6666003)(81156014)(6916009)(110136004)(5660300001)(3846002)(38730400002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR08MB0892; H:e110433-lin.cambridge.arm.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR08MB0892; 23:s1jpnqtx+LkBdyiDZgDrl19K0xz8fgFSQ6+W85kFH?= =?us-ascii?Q?WgjjbnmSng22sFIwKRtooB3ZsXpCMw2DzS94CDwjftKLZhybGB2r4viC1sPY?= =?us-ascii?Q?qfFb3D4hV8hroWJxaeVLOuuJQFMBES7NPgiz1ii51Hnp6a80NZgWnCCw0BIl?= =?us-ascii?Q?UjdzVOVePEs/L2b2pXjTDXCZGcRaQJ2AdlchBdQHTYMg19CnzPUHDq1/WMpJ?= =?us-ascii?Q?S+YcBbwDrkx4PIwuU9AuxoL96M5NujFoTJNQ/Iz2kLgbtKS6XEEAYGeU85hA?= =?us-ascii?Q?WBjdZLsIZynx2On2naei9aU0HdxVCgA3qdoS51NjnHn0EyR4ENqBOwYPvmxX?= =?us-ascii?Q?/CcsKxlkBWchoEEZAXDQoYs7Yj8pPAmKATcPfOwqujTAOVRwqklKiW/VZnJv?= =?us-ascii?Q?WSVhvxkjXRGCs2ywpxCkLlgoxLgvWb2qVPkn4nIBKqpCYikwEXDftPd3oS05?= =?us-ascii?Q?Q6MrQ4A9FzVtIMkkgh8wQqsqSeLIDtgX/byEObCiXgoqiP3DTB5l5w9pJoq+?= =?us-ascii?Q?sgzMCvfBJZQFyYViWWgyYFLoWobCfQ9gPRNJAla725vXUp8fxe/FeUiv/vNL?= =?us-ascii?Q?44LoF2BTQyKxft28YL/e0SOeVmh/hlnKEnAHNdrxtaI8Y5rtcVkKLX7Lcfq8?= =?us-ascii?Q?kxYXab2j7D7teNkK/rcHyneqkt4khwyug1+CycE8vXVON3STfZ4YfjxsXdsC?= =?us-ascii?Q?XsWBSzalIorYZJw6XkqcRYi/0LJN4dVUrUYX7W7fzhF/+rBQ0Pec6kbBDwMb?= =?us-ascii?Q?A20s/NgLFdiQa3Gqf2n8T3fHULyjB9SRorMSQbaRYxQ2n+UGZAbijB8a6ocd?= =?us-ascii?Q?rsbsN/JrmWiKMBNq7NdOPW8knxK9EpthjNE39d/7/lXBIKuBIV0rODz5zE5h?= =?us-ascii?Q?1f4qYNyFJt0ALLBCfSMwLVtPDuT6hAwIp7o1LNJwwo4PyJpdl+21fwadhwKi?= =?us-ascii?Q?VBZITfW2oHWJDxkaptdLj44KZvl+TI47u4ILPn7vrlrHoMX6bzRNd5G/3vZK?= =?us-ascii?Q?8Wz6eXpHp6VV1G8kGbMMQP+IevQ0QELFjN7zpCHF63uOsEi8O5aSwqGNDYp4?= =?us-ascii?Q?jihtwRM7JLn2GMUJpM1FcVRJYULpSem4P+7Ov9vc23/sLkdHlTczZciq7om/?= =?us-ascii?Q?PZPlqidu/PKKtD2G/f7Scf49/qia28Or27UsJDCLPR3JSSuGH+OOm06+ryx4?= =?us-ascii?Q?XFhfYUXgjgAoLqbuVGA/UBS67WwrnYbrtHOV+8gMOKbJqm4v+TcEZDtgg=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0892; 6:DmXYM867JXlHwvay1obnWyhWnppvQdEzQYoL4RG10E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/s1Mo9lNym234AS3EV7Q1rucn2AkCgfbOuQjRx735tOEJO0p4bavtuHQm2Nw/89xAWw2IXyEeW1U8KhAVkzHDRTHTJ7QLEFLdbPQTemaRL0OA1RqvKP06PUIdInnSqSOeK2SbfGsiVO4eK4KZVIMLQZL/SYuSF6tSUzF2rxinoiqzHXNMgJMw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2017 15:41:48.7468 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB0892 Cc: Liviu Dudau , linux-kernel@vger.kernel.org, Daniel Vetter , nd@arm.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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