Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7606459yba; Thu, 2 May 2019 12:52:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJ5pc/UGNBOkMfUtWe35eEgb21wnEP5h0trIXEpEkoliZxcWy5xuVB7rZ1M03PmMeaKb5f X-Received: by 2002:aa7:82d6:: with SMTP id f22mr6054968pfn.190.1556826774537; Thu, 02 May 2019 12:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556826774; cv=none; d=google.com; s=arc-20160816; b=zh9XvUlv4CjCg7jFW0GmntHk9ottNnNot1x2DxkVEIP4uRUe1zXdMKZa+pkB9zhpq9 P9BR6D/X6Om8M0I4Kzjk73yb+LmRm+GtWQT3+oGK5wVHagzGOdG++rzzwSW7lm6Cd6DJ X7aQhUM5SNSMEum/E7AbE4pqr6Z8piOW9d+11Ie+ayPJJb/KfedNUDpdIPkk7VROB7Qb 5pWtwz6sghw0Jel+8cxid6cHEBP9asPvtEtCE94LFB+Lv9RxOlr5OzxIcq30UhE4Vaq0 n7MXEQxqFKos2bf4PHyFlEWYfIPEmkSDJG2PmMbaSc44W4BaomQvJtUj+5Yi2/yJtuA5 NVEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iQv/EW+pxQy0WvYaV+otVZjtRHAeKNfXoG3CC92/2Uk=; b=NFlXbj+f1Xt9duvvgR/sehWGyE8Xj4ul3/YHjtvzf8Eq4v7FBbTgEpqHh3gL00Gz8t 1vFqH9KEiZtmp7kuUoTUanqyo8GmYGgDYod6EelYEaobtkWaoXNlRAKc6v1JKYoJWlB2 UzROI9wYakjSngCagjRF6dI4NrjhbXjgmfsrygo21DjuWPzFVjrNrHszLNEBBbg/yGxj v9hWtZhknnLsSqF/hUqWaCUdJvR/YPLOQjh8NK1Ab/tMRRO63SSqf/v+jNjmI6WAxv4G 3sN1dvr/V0uN6bWQ/8Gus5MJz+He9rt+MDfB0TNCkL6smFtFMEeNgJXI+YWKDFpVpnfY iFJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=MDTke5Oh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si16247pgk.47.2019.05.02.12.52.39; Thu, 02 May 2019 12:52:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=MDTke5Oh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726582AbfEBTuU (ORCPT + 99 others); Thu, 2 May 2019 15:50:20 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:37555 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbfEBTuT (ORCPT ); Thu, 2 May 2019 15:50:19 -0400 Received: by mail-qt1-f193.google.com with SMTP id e2so2447816qtb.4 for ; Thu, 02 May 2019 12:50:17 -0700 (PDT) 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=iQv/EW+pxQy0WvYaV+otVZjtRHAeKNfXoG3CC92/2Uk=; b=MDTke5OhkuWbovpVSD6D3qZvleMpftBW4urzoswDNagEWuQ3+jbUlmldjuKLIs6VwM KCLWuSXr1AbbcsD0zh8EeiEOcO6o5hCs0V7MG4/E4KsBZuy7rZmAsQl7CE4RkQ141uOG NSXDIkISyK9AzaGlk19WNTnj/pUUELNv8qDQezAG2NDNge33bWzOY/tZYCPS7Blhrr4R wwRqC8pikKHooesQtFaSNmcAthv1ZkV8BlZEVRwdhVl3d0OBGJL5b7aGubIXvzoszBmO DSxQPiGJn2/PCvvBRoPa90uW6dyF5lKwYKw1++PY6fStGFsoQNnXZtNl1cZwyJXKUOpr r8MQ== 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=iQv/EW+pxQy0WvYaV+otVZjtRHAeKNfXoG3CC92/2Uk=; b=nxcQLzRkm49SAtMHykhE4q2O6RMbcm5Vj3PS2xLKnKSG7TZGijRD8mgXZ6vw5I19sX EPoXP47pJBgx88HrdfgDw7dCLAYQdin30QjiucHiBXPZPavTUtDwzWqoBBooVAIS1E3I CRHl/HqhYXptVNln2UCitROFt3OSMithlE1anTQfQWM9PC2W2NB5b3BrVt9hSt9t80MY smZLZBes8ldb1Mz0Ro9oAuqUdqWJglrpgg6/FxwSaIFiK4d9LwUT5U+iP+PMKL3n8Pqe QZ/Iuaek2tZW3yxq+685Fk04FQojd3gaE7G8R4wWQMHW9o4Q3PI5sdNCquVJ0u/clAsn 6iDg== X-Gm-Message-State: APjAAAWqfPohaKowEVynWvyDgC14xnO2ZdSe3x7pG5H8OJPlPTjb9HZG tU/8gdjeU2VTrCtb5+SzQAbJUg== X-Received: by 2002:a0c:87bb:: with SMTP id 56mr4669280qvj.219.1556826617419; Thu, 02 May 2019 12:50:17 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id k36sm34366qtc.52.2019.05.02.12.50.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 May 2019 12:50:17 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Cc: Sean Paul , Daniel Vetter , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , linux-kernel@vger.kernel.org Subject: [PATCH v3 02/10] drm: Add drm_atomic_crtc_state_for_encoder helper Date: Thu, 2 May 2019 15:49:44 -0400 Message-Id: <20190502194956.218441-3-sean@poorly.run> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190502194956.218441-1-sean@poorly.run> References: <20190502194956.218441-1-sean@poorly.run> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Paul This patch adds a helper to tease out the currently connected crtc for an encoder, along with its state. This follows the same pattern as the drm_atomic_crtc_*_for_* macros in the atomic helpers. Since the relationship of crtc:encoder is 1:n, we don't need a loop since there is only one crtc per encoder. Instead of splitting this into 3 functions which all do the same thing, this is presented as one function. Perhaps that's too ugly and it should be split to: struct drm_crtc *drm_atomic_crtc_for_encoder(state, encoder); struct drm_crtc_state *drm_atomic_new_crtc_state_for_encoder(state, encoder); struct drm_crtc_state *drm_atomic_old_crtc_state_for_encoder(state, encoder); Suggestions welcome. Changes in v3: - Added to the set Cc: Daniel Vetter Cc: Ville Syrjälä Signed-off-by: Sean Paul --- drivers/gpu/drm/drm_atomic_helper.c | 48 +++++++++++++++++++++++++++++ include/drm/drm_atomic_helper.h | 6 ++++ 2 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 71cc7d6b0644..1f81ca8daad7 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -3591,3 +3591,51 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, return ret; } EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set); + +/** + * drm_atomic_crtc_state_for_encoder - Get crtc and new/old state for an encoder + * @state: Atomic state + * @encoder: The encoder to fetch the crtc information for + * @crtc: If not NULL, receives the currently connected crtc + * @old_crtc_state: If not NULL, receives the crtc's old state + * @new_crtc_state: If not NULL, receives the crtc's new state + * + * This function finds the crtc which is currently connected to @encoder and + * returns it as well as its old and new state. If there is no crtc currently + * connected, the function will clear @crtc, @old_crtc_state, @new_crtc_state. + * + * All of @crtc, @old_crtc_state, and @new_crtc_state are optional. + */ +void drm_atomic_crtc_state_for_encoder(struct drm_atomic_state *state, + struct drm_encoder *encoder, + struct drm_crtc **crtc, + struct drm_crtc_state **old_crtc_state, + struct drm_crtc_state **new_crtc_state) +{ + struct drm_crtc *tmp_crtc; + struct drm_crtc_state *tmp_new_crtc_state, *tmp_old_crtc_state; + u32 enc_mask = drm_encoder_mask(encoder); + int i; + + for_each_oldnew_crtc_in_state(state, tmp_crtc, tmp_old_crtc_state, + tmp_new_crtc_state, i) { + if (!(tmp_new_crtc_state->encoder_mask & enc_mask)) + continue; + + if (new_crtc_state) + *new_crtc_state = tmp_new_crtc_state; + if (old_crtc_state) + *old_crtc_state = tmp_old_crtc_state; + if (crtc) + *crtc = tmp_crtc; + return; + } + + if (new_crtc_state) + *new_crtc_state = NULL; + if (old_crtc_state) + *old_crtc_state = NULL; + if (crtc) + *crtc = NULL; +} +EXPORT_SYMBOL(drm_atomic_crtc_state_for_encoder); diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h index 58214be3bf3d..2383550a0cc8 100644 --- a/include/drm/drm_atomic_helper.h +++ b/include/drm/drm_atomic_helper.h @@ -153,6 +153,12 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, uint32_t size, struct drm_modeset_acquire_ctx *ctx); +void drm_atomic_crtc_state_for_encoder(struct drm_atomic_state *state, + struct drm_encoder *encoder, + struct drm_crtc **crtc, + struct drm_crtc_state **old_crtc_state, + struct drm_crtc_state **new_crtc_state); + /** * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC * @plane: the loop cursor -- Sean Paul, Software Engineer, Google / Chromium OS