From patchwork Tue Jun 21 14:37:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 70568 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp2051306qgy; Tue, 21 Jun 2016 07:37:42 -0700 (PDT) X-Received: by 10.36.152.67 with SMTP id n64mr6375839itd.18.1466519862579; Tue, 21 Jun 2016 07:37:42 -0700 (PDT) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id ux14si17999789pab.68.2016.06.21.07.37.42; Tue, 21 Jun 2016 07:37:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92D406E280; Tue, 21 Jun 2016 14:37:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x233.google.com (mail-lf0-x233.google.com [IPv6:2a00:1450:4010:c07::233]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3E306E71F for ; Tue, 21 Jun 2016 14:37:37 +0000 (UTC) Received: by mail-lf0-x233.google.com with SMTP id f6so26785077lfg.0 for ; Tue, 21 Jun 2016 07:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=jrB/sJmiaAzM26KxiDSA/IeXQ0/uq3cfsuSNRA6ZeVA=; b=hbgfkgA0A1CTFcp1kdrgsBkcpvJoxS4dyQhraehNt9H+aWqP0EUjwrJ3qD6wi98tWH uRHtc+0BOafdJPLgAzu/RdUiS61NjFShPLh9x22GqGfuTIxZ5sMzCpzcgrOiuYTHAnHJ keyGlsA0UO0QFS+kMcj34OC5z+BATVfdbajs4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jrB/sJmiaAzM26KxiDSA/IeXQ0/uq3cfsuSNRA6ZeVA=; b=moLpvkesqqI7Mmg11zQB2lsvGQxjmdc1zIatBMYv1bHwm4oKkSOpmwQTeckm4RMPLK CQtFUWCaXYHbOSlur2mXTAhzdlY7vd/pg2+bAYYKkH49p2wuO9ZGqwM2b4ADEkpp1JRF KigBtk2omdQoBIbRK34FpB2Ycz8AfA7E+QmDtgzrGmwaqUM7FS+eaY6WIdgkW63S12sx KI2ILMzjnV3EO57bg/XXxslk1jM8QeIX3MT2fO6MJeP1SKckRYnQu75dy313t/+8j2CI cM7ZyLucY7u7GMbkJ7lSFPXFus6KM2BeWpNY10TTacxSu832KAAoShjsgkVv3a5N44tZ 5UsQ== X-Gm-Message-State: ALyK8tK0PpUlX4eDImVJGlATOct/XV8BstJuTPHpbAatqKSrRAsy+IuADBtccHYVZ6i1mgYf X-Received: by 10.28.94.18 with SMTP id s18mr3701596wmb.42.1466519855478; Tue, 21 Jun 2016 07:37:35 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.168.167]) by smtp.gmail.com with ESMTPSA id i14sm3302883wmg.7.2016.06.21.07.37.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jun 2016 07:37:34 -0700 (PDT) From: Benjamin Gaignard To: dri-devel@lists.freedesktop.org, vincent.abriou@st.com, fabien.dessenne@st.com, daniel@ffwll.ch Subject: [PATCH v4 1/3] drm: Add callbacks for late registering Date: Tue, 21 Jun 2016 16:37:09 +0200 Message-Id: <1466519829-4000-1-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Like what has been done for connectors add callbacks on encoder, crtc and plane to let driver do actions after drm device registration. Correspondingly, add callbacks called before unregister drm device. version 2: add drm_modeset_register_all() and drm_modeset_unregister_all() to centralize all calls version 3: in error case unwind registers in drm_modeset_register_all fix uninitialed return value inverse order of unregistration in drm_modeset_unregister_all version 4: move function definitions in drm_crtc_internal.h remove not needed documentation Signed-off-by: Benjamin Gaignard --- drivers/gpu/drm/drm_crtc.c | 115 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_crtc_internal.h | 2 + drivers/gpu/drm/drm_drv.c | 5 +- include/drm/drm_crtc.h | 77 ++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index e7c862b..a717238 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -608,6 +608,31 @@ static unsigned int drm_num_crtcs(struct drm_device *dev) return num; } +static int drm_crtc_register_all(struct drm_device *dev) +{ + struct drm_crtc *crtc; + int ret = 0; + + drm_for_each_crtc(crtc, dev) { + if (crtc->funcs->late_register) + ret = crtc->funcs->late_register(crtc); + if (ret) + return ret; + } + + return 0; +} + +static void drm_crtc_unregister_all(struct drm_device *dev) +{ + struct drm_crtc *crtc; + + drm_for_each_crtc(crtc, dev) { + if (crtc->funcs->early_unregister) + crtc->funcs->early_unregister(crtc); + } +} + /** * drm_crtc_init_with_planes - Initialise a new CRTC object with * specified primary and cursor planes. @@ -1102,6 +1127,31 @@ void drm_connector_unregister_all(struct drm_device *dev) } EXPORT_SYMBOL(drm_connector_unregister_all); +static int drm_encoder_register_all(struct drm_device *dev) +{ + struct drm_encoder *encoder; + int ret = 0; + + drm_for_each_encoder(encoder, dev) { + if (encoder->funcs->late_register) + ret = encoder->funcs->late_register(encoder); + if (ret) + return ret; + } + + return 0; +} + +static void drm_encoder_unregister_all(struct drm_device *dev) +{ + struct drm_encoder *encoder; + + drm_for_each_encoder(encoder, dev) { + if (encoder->funcs->early_unregister) + encoder->funcs->early_unregister(encoder); + } +} + /** * drm_encoder_init - Init a preallocated encoder * @dev: drm device @@ -1290,6 +1340,31 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, } EXPORT_SYMBOL(drm_universal_plane_init); +static int drm_plane_register_all(struct drm_device *dev) +{ + struct drm_plane *plane; + int ret = 0; + + drm_for_each_plane(plane, dev) { + if (plane->funcs->late_register) + ret = plane->funcs->late_register(plane); + if (ret) + return ret; + } + + return 0; +} + +static void drm_plane_unregister_all(struct drm_device *dev) +{ + struct drm_plane *plane; + + drm_for_each_plane(plane, dev) { + if (plane->funcs->early_unregister) + plane->funcs->early_unregister(plane); + } +} + /** * drm_plane_init - Initialize a legacy plane * @dev: DRM device @@ -1412,6 +1487,46 @@ void drm_plane_force_disable(struct drm_plane *plane) } EXPORT_SYMBOL(drm_plane_force_disable); +int drm_modeset_register_all(struct drm_device *dev) +{ + int ret; + + ret = drm_plane_register_all(dev); + if (ret) + goto err_plane; + + ret = drm_crtc_register_all(dev); + if (ret) + goto err_crtc; + + ret = drm_encoder_register_all(dev); + if (ret) + goto err_encoder; + + ret = drm_connector_register_all(dev); + if (ret) + goto err_connector; + + return 0; + +err_connector: + drm_encoder_unregister_all(dev); +err_encoder: + drm_crtc_unregister_all(dev); +err_crtc: + drm_plane_unregister_all(dev); +err_plane: + return ret; +} + +void drm_modeset_unregister_all(struct drm_device *dev) +{ + drm_connector_unregister_all(dev); + drm_encoder_unregister_all(dev); + drm_crtc_unregister_all(dev); + drm_plane_unregister_all(dev); +} + static int drm_mode_create_standard_properties(struct drm_device *dev) { struct drm_property *prop; diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h index a78c138..a3b0fbc 100644 --- a/drivers/gpu/drm/drm_crtc_internal.h +++ b/drivers/gpu/drm/drm_crtc_internal.h @@ -42,3 +42,5 @@ int drm_atomic_get_property(struct drm_mode_object *obj, int drm_mode_atomic_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); +int drm_modeset_register_all(struct drm_device *dev); +void drm_modeset_unregister_all(struct drm_device *dev); diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index c7101c0..8ff664f 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -34,6 +34,7 @@ #include #include #include +#include "drm_crtc_internal.h" #include "drm_legacy.h" #include "drm_internal.h" @@ -688,7 +689,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) } if (drm_core_check_feature(dev, DRIVER_MODESET)) - drm_connector_register_all(dev); + drm_modeset_register_all(dev); ret = 0; goto out_unlock; @@ -721,7 +722,7 @@ void drm_dev_unregister(struct drm_device *dev) drm_lastclose(dev); if (drm_core_check_feature(dev, DRIVER_MODESET)) - drm_connector_unregister_all(dev); + drm_modeset_unregister_all(dev); if (dev->driver->unload) dev->driver->unload(dev); diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index c273497..b4ab33f 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -704,6 +704,32 @@ struct drm_crtc_funcs { const struct drm_crtc_state *state, struct drm_property *property, uint64_t *val); + + /** + * @late_register: + * + * This optional hook can be used to register additional userspace + * interfaces attached to the crtc like debugfs interfaces. + * It is called late in the driver load sequence from drm_dev_register(). + * Everything added from this callback should be unregistered in + * the early_unregister callback. + * + * Returns: + * + * 0 on success, or a negative error code on failure. + */ + int (*late_register)(struct drm_crtc *crtc); + + /** + * @early_unregister: + * + * This optional hook should be used to unregister the additional + * userspace interfaces attached to the crtc from + * late_unregister(). It is called from drm_dev_unregister(), + * early in the driver unload sequence to disable userspace access + * before data structures are torndown. + */ + void (*early_unregister)(struct drm_crtc *crtc); }; /** @@ -1127,6 +1153,32 @@ struct drm_encoder_funcs { * hotplugged in DRM. */ void (*destroy)(struct drm_encoder *encoder); + + /** + * @late_register: + * + * This optional hook can be used to register additional userspace + * interfaces attached to the encoder like debugfs interfaces. + * It is called late in the driver load sequence from drm_dev_register(). + * Everything added from this callback should be unregistered in + * the early_unregister callback. + * + * Returns: + * + * 0 on success, or a negative error code on failure. + */ + int (*late_register)(struct drm_encoder *encoder); + + /** + * @early_unregister: + * + * This optional hook should be used to unregister the additional + * userspace interfaces attached to the encoder from + * late_unregister(). It is called from drm_dev_unregister(), + * early in the driver unload sequence to disable userspace access + * before data structures are torndown. + */ + void (*early_unregister)(struct drm_encoder *encoder); }; #define DRM_CONNECTOR_MAX_ENCODER 3 @@ -1570,6 +1622,31 @@ struct drm_plane_funcs { const struct drm_plane_state *state, struct drm_property *property, uint64_t *val); + /** + * @late_register: + * + * This optional hook can be used to register additional userspace + * interfaces attached to the plane like debugfs interfaces. + * It is called late in the driver load sequence from drm_dev_register(). + * Everything added from this callback should be unregistered in + * the early_unregister callback. + * + * Returns: + * + * 0 on success, or a negative error code on failure. + */ + int (*late_register)(struct drm_plane *plane); + + /** + * @early_unregister: + * + * This optional hook should be used to unregister the additional + * userspace interfaces attached to the plane from + * late_unregister(). It is called from drm_dev_unregister(), + * early in the driver unload sequence to disable userspace access + * before data structures are torndown. + */ + void (*early_unregister)(struct drm_plane *plane); }; enum drm_plane_type {