From patchwork Tue Nov 29 19:17:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 27421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp523379wrr; Tue, 29 Nov 2022 11:19:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf56q+HAj5TiudLfGpN+qTvsQSb41aH+flBphxiZtnGiQOS7K/YB1ZRJcPud6kY0vQ9f/xJ8 X-Received: by 2002:a17:906:dfc1:b0:78d:894d:e123 with SMTP id jt1-20020a170906dfc100b0078d894de123mr32014081ejc.112.1669749543612; Tue, 29 Nov 2022 11:19:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669749543; cv=none; d=google.com; s=arc-20160816; b=ZCEGBeolmpFV+iaMnHUAvTqtqcwd51kpTfY+T0PrKz/y4XiM3udPbBxYpyQx8ORUCd ghdoMgo3FajqJ9dPpbacGf3xCR5bO9PxhmWdq9NTpqjcgAz0wkhqS7/SnIWPCarnidSF LReWaSSqoHCaAmqldw/hUMtnFCyBT3mZ2Fd+JChN6+mKLVuE5hQL2ZmonY4Ayw+eDQNu nnptLMWkk/U43haOatRJmOZtaN5rK5G1cJ+FQfOA6JzQd/2ryEv5eDAzTAgTexCqdc8b 0xhaONj+tk8yY0zI+dan7v3MSHLSMynkzIy8hVYy6eBPl2PgtdesNw7AkDfbxSY3gfQQ dyPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7gAnxaoVqEWoM5vi/BaBgxdiGzKVxjjTsGqnEeIglYs=; b=xhYkYfoFk/P3LBHp248NJPBRrjdasuwc31rOhUBkgrCoMWz4P9yWwRqz+y4YwucwfG 0PU/KV028bq8xc3QqSKEe4ITwWgpYzbHmx6k6zjU0v2xMV9nmiWrcGmZKl83jLR36C5s 7v3SafwOdoEgIJNktSN5W1p6BpXI1+CR6FT7bYS3uQ/oHfD6LcyKX5DQiwPI/gCD84SU Upj/Q2dwyCyaxsgysAH7Xrw2cc/lUrcT25Gh8UWy68919WuPcoxOVQg+ta3rUJ+S3bPZ pBj83Bbv9t5dHlKTZid6rPEiQ20sMNJk1d1po1QamWx/hmu5VEqq1PkrwdMPKCaUs4QO K8rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=Lb3U8DMa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr28-20020a1709073f9c00b007bedd130080si6720536ejc.231.2022.11.29.11.18.34; Tue, 29 Nov 2022 11:19:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=Lb3U8DMa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236345AbiK2TSB (ORCPT + 99 others); Tue, 29 Nov 2022 14:18:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235356AbiK2TR7 (ORCPT ); Tue, 29 Nov 2022 14:17:59 -0500 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26CEB20198 for ; Tue, 29 Nov 2022 11:17:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1669749469; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7gAnxaoVqEWoM5vi/BaBgxdiGzKVxjjTsGqnEeIglYs=; b=Lb3U8DMaMv86BzMM+cDyhB6ZOmgECsaSU4wa2llVOeq8427YF/e+LM6bLEc1eB2cFI1SR4 cHxQpiRDgnycev9zdcpVoeoXS8zV88XDwRPGji+L3Mg5C3mOXy4zBHGWVfl5/M/4DS7Aw9 BVcFIFgpdnmmm+0yq9xtiNKl35K8Sfs= From: Paul Cercueil To: David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH v2 01/26] drm: modeset-helper: Add DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS macro Date: Tue, 29 Nov 2022 19:17:08 +0000 Message-Id: <20221129191733.137897-2-paul@crapouillou.net> In-Reply-To: <20221129191733.137897-1-paul@crapouillou.net> References: <20221129191733.137897-1-paul@crapouillou.net> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750859297328900434?= X-GMAIL-MSGID: =?utf-8?q?1750859297328900434?= This macro can be used with simple drivers, which have their "struct drm_device" registered as their "struct device"'s drvdata, and only call drm_mode_config_pm_{suspend,resume}. The macro will define a "struct dev_pm_ops" with the name passed as argument. This object cannot be referenced directly; instead, the pm_sleep_ptr() macro should be used, like this: DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(foo_pm_ops); static struct platform_driver foo_driver = { .driver.pm = pm_sleep_ptr(&foo_pm_ops), ... }; This ensures that the generated code will be dropped by the compiler in the case where CONFIG_PM has been disabled in the config. v2: instead of exporting a dev_pm_ops, introduce the DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro. Signed-off-by: Paul Cercueil --- include/drm/drm_modeset_helper.h | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/drm/drm_modeset_helper.h b/include/drm/drm_modeset_helper.h index 995fd981cab0..2ecf0e5c2e16 100644 --- a/include/drm/drm_modeset_helper.h +++ b/include/drm/drm_modeset_helper.h @@ -41,4 +41,42 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, int drm_mode_config_helper_suspend(struct drm_device *dev); int drm_mode_config_helper_resume(struct drm_device *dev); +/** + * DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS - Generate simple PM callbacks + * + * This macro can be used by simple drivers that would otherwise only call + * drm_mode_config_helper_suspend / drm_mode_config_helper_resume in their PM + * callbacks. It will generate a struct dev_pm_ops of the given name, that can + * then be referenced in the device_driver structure. + * + * Note that it is only valid if the driver's drm_device has been registered as + * the struct device's drvdata. + * + * Additionally, the generated dev_pm_ops structure should not be referenced + * directly; instead, the pm_sleep_ptr() macro should be used, like this: + * + * DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(foo_pm_ops); + * + * static struct platform_driver foo_driver = { + * .driver.pm = pm_sleep_ptr(&foo_pm_ops), + * ... + * }; + * + * This ensures that the generated code will be dropped by the compiler in the + * case where CONFIG_PM has been disabled in the config. ++ */ + +#define DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(_name) \ + static int __##_name##_drm_mode_config_pm_suspend(struct device *dev) \ + { \ + return drm_mode_config_helper_suspend(dev_get_drvdata(dev)); \ + } \ + static int __##_name##_drm_mode_config_pm_resume(struct device *dev) \ + { \ + return drm_mode_config_helper_resume(dev_get_drvdata(dev)); \ + } \ + static DEFINE_SIMPLE_DEV_PM_OPS(_name, \ + __##_name##_drm_mode_config_pm_suspend, \ + __##_name##_drm_mode_config_pm_resume) + #endif