From patchwork Tue Jun 11 20:49:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10988277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E14CF13AD for ; Tue, 11 Jun 2019 20:50:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D353F288B8 for ; Tue, 11 Jun 2019 20:50:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B77EF288B7; Tue, 11 Jun 2019 20:50:05 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 1D3B9288A7 for ; Tue, 11 Jun 2019 20:50:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B379F89218; Tue, 11 Jun 2019 20:50:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by gabe.freedesktop.org (Postfix) with ESMTPS id 25E8789218 for ; Tue, 11 Jun 2019 20:50:03 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id x2so15382362qtr.0 for ; Tue, 11 Jun 2019 13:50:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VbPNQuCWg3RsiHFnvXtXweqOT7UO7T1o/06TB09q1K4=; b=d3Z09f0Uir9ERzgA5bKwGx88HfSHGkVoB6cNe7CHg3TUNkjy0W23YeOlR2m7mDSE4y 20J1UBAxTGo6cYTCEKdGB/0z8MJrx6a8DBiDMkuzBqrIuGtaXNU64OuW7w79Rm9ecuq7 1xWJdWrT9hjnrwVRemO7JSqCgTtlf+BJwspYt0hUJ9KA0qVKbGuGzyuJcR76Y9YcVhRU wiMfSiJkx5DzG2N/oT0HzZCEc04Na8/NM+NhavdbNLLj5cWFQvhbIRKSIxhMLlJW8d5n 3hSgSRB/25FVpkwO9LlIhuwP1Nxwb3H3+khmv7YoTWmKok/Jqll+VvCtG8+sPrP5f27h aN2A== X-Gm-Message-State: APjAAAXw3BNS8EfoLd1YbAj2pzyGr1DEjH7QOTr4jiStbz4IubgT/FBr GwMF6PmKEP4lkePkKTzMzXmpC/5DLmM= X-Google-Smtp-Source: APXvYqysXTclQuxRv+/8d7q7k1GUEr4rHZr/WXirGRvvCpHwJH1M7GLwvz6QXi4Clg4X7tAs5/Yk4g== X-Received: by 2002:aed:22af:: with SMTP id p44mr8143561qtc.348.1560286202145; Tue, 11 Jun 2019 13:50:02 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id 34sm10023076qtq.59.2019.06.11.13.50.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 13:50:01 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH v6 01/11] drm: Add atomic variants of enable/disable to encoder helper funcs Date: Tue, 11 Jun 2019 16:49:53 -0400 Message-Id: <20190611204959.180855-1-sean@poorly.run> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog In-Reply-To: <20190611185352.GA16305@ravnborg.org> References: <20190611185352.GA16305@ravnborg.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VbPNQuCWg3RsiHFnvXtXweqOT7UO7T1o/06TB09q1K4=; b=RdejL3Gw2bSGFRX1fotkY0g5L83ndTwpks2oSH1P/QkJpFNzJpiXRgnF1qsYW2oQUh q2y8ulbc9+QkFD+wcblaXoRDEPgylf0Kw0Up2yRIemPyYteQVYVol6pR0kzH1iFtRCPA 6ScNBLtHRwMLa72ZdiEayqaGw/LYwEmeXK80EPE4omq9vVw4cEvChVdLDy4ZCJzvrQFY ePhDu9yoNCMWQ0yZi/r+goW8Uv85HdiL0wNBgKS1K5oXy+YLN5hmVSVxmnWcJ92ntRzw jr8mGPGGKglNIus5C7qs6hSwRaMH4acTFBzuxopNF9f1SQs+rYsthPw/O3gPkDTVnNsn FxXg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Sean Paul , David Airlie , Sean Paul , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Paul This patch adds atomic_enable and atomic_disable callbacks to the encoder helpers. This will allow encoders to make informed decisions in their start-up/shutdown based on the committed state. Aside from the new hooks, this patch also introduces the new signature for .atomic_* functions going forward. Instead of passing object state (well, encoders don't have atomic state, but let's ignore that), we pass the entire atomic state so the driver can inspect more than what's happening locally. This is particularly important for the upcoming self refresh helpers. Changes in v3: - Added patch to the set Changes in v4: - Move atomic_disable above prepare (Daniel) - Add breadcrumb to .enable() docbook (Daniel) Changes in v5: - None Changes in v6: - Tweak kerneldoc some more (Sam) Link to v3: https://patchwork.freedesktop.org/patch/msgid/20190502194956.218441-2-sean@poorly.run Link to v4: https://patchwork.freedesktop.org/patch/msgid/20190508160920.144739-2-sean@poorly.run Link to v5: https://patchwork.freedesktop.org/patch/msgid/20190611160844.257498-2-sean@poorly.run Cc: Daniel Vetter Cc: Ville Syrjälä Cc: Sam Ravnborg Tested-by: Heiko Stuebner Reviewed-by: Daniel Vetter Signed-off-by: Sean Paul --- drivers/gpu/drm/drm_atomic_helper.c | 8 +++- include/drm/drm_modeset_helper_vtables.h | 49 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 0fc63d6822451..62e29b5ebb6e3 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1002,7 +1002,9 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) /* Right function depends upon target state. */ if (funcs) { - if (new_conn_state->crtc && funcs->prepare) + if (funcs->atomic_disable) + funcs->atomic_disable(encoder, old_state); + else if (new_conn_state->crtc && funcs->prepare) funcs->prepare(encoder); else if (funcs->disable) funcs->disable(encoder); @@ -1311,7 +1313,9 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, drm_bridge_pre_enable(encoder->bridge); if (funcs) { - if (funcs->enable) + if (funcs->atomic_enable) + funcs->atomic_enable(encoder, old_state); + else if (funcs->enable) funcs->enable(encoder); else if (funcs->commit) funcs->commit(encoder); diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h index f9c94c2a13646..4cf01cd64b0cf 100644 --- a/include/drm/drm_modeset_helper_vtables.h +++ b/include/drm/drm_modeset_helper_vtables.h @@ -679,6 +679,52 @@ struct drm_encoder_helper_funcs { enum drm_connector_status (*detect)(struct drm_encoder *encoder, struct drm_connector *connector); + /** + * @atomic_disable: + * + * This callback should be used to disable the encoder. With the atomic + * drivers it is called before this encoder's CRTC has been shut off + * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that + * sequence is too simple drivers can just add their own driver private + * encoder hooks and call them from CRTC's callback by looping over all + * encoders connected to it using for_each_encoder_on_crtc(). + * + * This callback is a variant of @disable that provides the atomic state + * to the driver. If @atomic_disable is implemented, @disable is not + * called by the helpers. + * + * This hook is only used by atomic helpers. Atomic drivers don't need + * to implement it if there's no need to disable anything at the encoder + * level. To ensure that runtime PM handling (using either DPMS or the + * new "ACTIVE" property) works @atomic_disable must be the inverse of + * @atomic_enable. + */ + void (*atomic_disable)(struct drm_encoder *encoder, + struct drm_atomic_state *state); + + /** + * @atomic_enable: + * + * This callback should be used to enable the encoder. It is called + * after this encoder's CRTC has been enabled using their own + * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is + * too simple drivers can just add their own driver private encoder + * hooks and call them from CRTC's callback by looping over all encoders + * connected to it using for_each_encoder_on_crtc(). + * + * This callback is a variant of @enable that provides the atomic state + * to the driver. If @atomic_enable is implemented, @enable is not + * called by the helpers. + * + * This hook is only used by atomic helpers, it is the opposite of + * @atomic_disable. Atomic drivers don't need to implement it if there's + * no need to enable anything at the encoder level. To ensure that + * runtime PM handling works @atomic_enable must be the inverse of + * @atomic_disable. + */ + void (*atomic_enable)(struct drm_encoder *encoder, + struct drm_atomic_state *state); + /** * @disable: * @@ -695,6 +741,9 @@ struct drm_encoder_helper_funcs { * handling (using either DPMS or the new "ACTIVE" property) works * @disable must be the inverse of @enable for atomic drivers. * + * For atomic drivers also consider @atomic_disable and save yourself + * from having to read the NOTE below! + * * NOTE: * * With legacy CRTC helpers there's a big semantic difference between From patchwork Tue Jun 11 20:51:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10988279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87ED818A6 for ; Tue, 11 Jun 2019 20:51:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75C84288BD for ; Tue, 11 Jun 2019 20:51:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69E8A288CB; Tue, 11 Jun 2019 20:51:53 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 D6EAC288BF for ; Tue, 11 Jun 2019 20:51:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E51F5891D6; Tue, 11 Jun 2019 20:51:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B33D891D6 for ; Tue, 11 Jun 2019 20:51:50 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id r6so8602207qkc.0 for ; Tue, 11 Jun 2019 13:51:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AcalhdVA3Z2o4f9lC6g7CH6ly2rXGQ59skslvBdkVqs=; b=fY8aYynXCUcTJRuX2Ws3gXhst6fsGt2G8m2nfFgixVDg8twvuSelunYy2t5sEQ6x5j Z13G9wYQWad9YgO+J0guE5fLKqF05ZAhCipKcF7IvVoy7zG3wxFdy1dBy20LOsWwimq2 eGTgXeX2DDbkbim7XwkBwvR6Kd8+Q95X/E/oD53EUK1814pHJxz0Up+a3XHvEYY8XTlL giv/04McIoZ5vm0C8GIgmqMTjrjFcHiqqfwosJj4GVbfbrKzHyZ4N84bB5T7E8h8WdDd JQO4x8ypZpNfjIQW/twQfxD8zMxJGEyR/KcZbn89Bz347wm7oRwv0fgF3hGDkICKaYEi I/Ag== X-Gm-Message-State: APjAAAXAIvE+pbnxDOYajoTzuClr4/qeTyzzN+dUZ6kO6bCOcBh1QFFm NtuiOcPy9NeGd0Dx2P/f+qqPKYni8jE= X-Google-Smtp-Source: APXvYqyKIPiNPc17xOz0l+9Ogzxoyg4gklDq2fCtGNrCgZGERXtLyEJYcJXk4tkiyZpMCChD+y1rGw== X-Received: by 2002:a37:5645:: with SMTP id k66mr59144954qkb.177.1560286309349; Tue, 11 Jun 2019 13:51:49 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id d17sm6567439qtp.84.2019.06.11.13.51.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 13:51:48 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH v6 02/11] drm: Add drm_atomic_get_(old|new)_connector_for_encoder() helpers Date: Tue, 11 Jun 2019 16:51:43 -0400 Message-Id: <20190611205147.181298-1-sean@poorly.run> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog In-Reply-To: <20190611185747.GB16305@ravnborg.org> References: <20190611185747.GB16305@ravnborg.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AcalhdVA3Z2o4f9lC6g7CH6ly2rXGQ59skslvBdkVqs=; b=ZmcPz1L1SPlcO/3JNNlzmO4wh6pyD+SFvDZnTdCvUGWEimvrFq0DdOoZ3mIviQkFzb J1tyHbj+NE/JbPj+qqyFC0FPQi/1UDS4359QWvYeVTcpo74b83yjYc2QlcpK4wheuSb1 DCIIGdARw8Zgd+B8tSo4v+mO3nULmqwV+l7gFbWFihxjC/FK/5Hg+4cjJ+y/vg351dUp M7sq8KLwaklC/deQ+2ocayu8aXTCXExDGdFq5S7KPmcAZ2cMw7yufbuR9bm+c9Ky3364 mZfFTVSLX9VbTkrriUKGjwa+Lh+YOsujvD2gClCXqbMLGoOr3CtAoAVCpcWTEhAAORTX rotQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Sean Paul , David Airlie , Sean Paul , Laurent Pinchart , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Laurent Pinchart Add functions to the atomic core to retrieve the old and new connectors associated with an encoder in a drm_atomic_state. This is useful for encoders and bridges that need to access the connector, for instance for the drm_display_info. The CRTC associated with the encoder can also be retrieved through the connector state, and from it, the old and new CRTC states. Changed in v4: - Added to the set Changed in v5: - Fix up docbook (Daniel & Laurent) Changed in v6: - Updated commit subject (Sam) Link to v4: https://patchwork.freedesktop.org/patch/msgid/20190508160920.144739-3-sean@poorly.run Link to v5: https://patchwork.freedesktop.org/patch/msgid/20190611160844.257498-3-sean@poorly.run Cc: Daniel Vetter Cc: Sam Ravnborg Tested-by: Heiko Stuebner Reviewed-by: Daniel Vetter Signed-off-by: Laurent Pinchart [seanpaul removed WARNs from helpers and added docs to explain why returning NULL might be valid] Signed-off-by: Sean Paul --- drivers/gpu/drm/drm_atomic.c | 69 ++++++++++++++++++++++++++++++++++++ include/drm/drm_atomic.h | 7 ++++ include/drm/drm_connector.h | 5 +++ 3 files changed, 81 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 169f06d7c5ce4..a4e779deab0fb 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -846,6 +846,75 @@ drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state, } EXPORT_SYMBOL(drm_atomic_get_new_private_obj_state); +/** + * drm_atomic_get_old_connector_for_encoder - Get old connector for an encoder + * @state: Atomic state + * @encoder: The encoder to fetch the connector state for + * + * This function finds and returns the connector that was connected to @encoder + * as specified by the @state. + * + * If there is no connector in @state which previously had @encoder connected to + * it, this function will return NULL. While this may seem like an invalid use + * case, it is sometimes useful to differentiate commits which had no prior + * connectors attached to @encoder vs ones that did (and to inspect their + * state). This is especially true in enable hooks because the pipeline has + * changed. + * + * Returns: The old connector connected to @encoder, or NULL if the encoder is + * not connected. + */ +struct drm_connector * +drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state, + struct drm_encoder *encoder) +{ + struct drm_connector_state *conn_state; + struct drm_connector *connector; + unsigned int i; + + for_each_old_connector_in_state(state, connector, conn_state, i) { + if (conn_state->best_encoder == encoder) + return connector; + } + + return NULL; +} +EXPORT_SYMBOL(drm_atomic_get_old_connector_for_encoder); + +/** + * drm_atomic_get_new_connector_for_encoder - Get new connector for an encoder + * @state: Atomic state + * @encoder: The encoder to fetch the connector state for + * + * This function finds and returns the connector that will be connected to + * @encoder as specified by the @state. + * + * If there is no connector in @state which will have @encoder connected to it, + * this function will return NULL. While this may seem like an invalid use case, + * it is sometimes useful to differentiate commits which have no connectors + * attached to @encoder vs ones that do (and to inspect their state). This is + * especially true in disable hooks because the pipeline will change. + * + * Returns: The new connector connected to @encoder, or NULL if the encoder is + * not connected. + */ +struct drm_connector * +drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state, + struct drm_encoder *encoder) +{ + struct drm_connector_state *conn_state; + struct drm_connector *connector; + unsigned int i; + + for_each_new_connector_in_state(state, connector, conn_state, i) { + if (conn_state->best_encoder == encoder) + return connector; + } + + return NULL; +} +EXPORT_SYMBOL(drm_atomic_get_new_connector_for_encoder); + /** * drm_atomic_get_connector_state - get connector state * @state: global atomic state object diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index e937ff2beb04f..f122156478010 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -459,6 +459,13 @@ struct drm_private_state * drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state, struct drm_private_obj *obj); +struct drm_connector * +drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state, + struct drm_encoder *encoder); +struct drm_connector * +drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state, + struct drm_encoder *encoder); + /** * drm_atomic_get_existing_crtc_state - get crtc state, if it exists * @state: global atomic state object diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 47e749b74e5fc..071143bc0ebd1 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -518,6 +518,11 @@ struct drm_connector_state { * &drm_connector_helper_funcs.atomic_best_encoder or * &drm_connector_helper_funcs.best_encoder callbacks. * + * This is also used in the atomic helpers to map encoders to their + * current and previous connectors, see + * &drm_atomic_get_old_connector_for_encoder() and + * &drm_atomic_get_new_connector_for_encoder(). + * * NOTE: Atomic drivers must fill this out (either themselves or through * helpers), for otherwise the GETCONNECTOR and GETENCODER IOCTLs will * not return correct data to userspace.