Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp321621pxa; Wed, 26 Aug 2020 11:31:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIpM58iBcmxdu1ivxG8mz3E7Ny3P/K67mBZpy1l0T9zftSzUC3RN8V5jIUoc8LqrMsuI91 X-Received: by 2002:a17:906:52d9:: with SMTP id w25mr16666300ejn.491.1598466713878; Wed, 26 Aug 2020 11:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598466713; cv=none; d=google.com; s=arc-20160816; b=mDzl5quuqkFK5UCWb3ZUmblo4AeG4hDpKahdL8ueujE90aWIb+o5ojzDNwSYcnmL2s ndsrmDXjD42eB8QAExXKbO3UZ7KzlhzAmXz6hUH/QXetMh/uXzFkrov5rp/LonAy9HeC x7QX72498re//DWuUDW+V9SVGcX7Mrn8MaJprM3vHyaIOW/aEv0lv8dILEE5SyJ4TK53 O8SfHksArZwYr481ClyjAPYWFjPOKcWC/mPE7rHZl1Ozj5Pszxv9JBwvx0riz89BIJzw wxoj53mKo6YVOMHH4yqfG5a4XKVa3tIitthTLDvR5F2+yoxcarpbGGxJ1CKobmPdouWU xXEQ== 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=ZJ5kpt/WAEIymxMLjU7/mIu1Y5rO6SXEfMby99xIlTM=; b=b9aDJJZ0kOPYVvE+z9DNLe35S1nRo7RsV1cp52fMo6kj9JP+qMohyQ5dUXz4wp3APp u020cMYWvMQvZKRKw+q7L9VbE3OW2t2ELekJklEgICRLlVmGDDFazEHlZpIJI8p1J5Zs XVNgiebnlkR5706xC0U1rDZwHUGGVGzPEdjvS0u237lRQbk7FmsQ2TDCVan9Az3fih+2 KjLO4PyGvWWUC0PXKRdh5Vnfti0DCByNfATlnxvRWTZzrp0VWqMgqehE6XsqhL35HnPE 3nruLQXzb/ENFllkQNfYoAQVrDpV/BhoYT5FmZKvSXK93cc41eGm0g5BxKP5DFaX1XmY BFOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZtliMg4q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn20si2749217ejc.377.2020.08.26.11.31.30; Wed, 26 Aug 2020 11:31:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZtliMg4q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbgHZS0p (ORCPT + 99 others); Wed, 26 Aug 2020 14:26:45 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:26940 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727080AbgHZSZ5 (ORCPT ); Wed, 26 Aug 2020 14:25:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598466355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJ5kpt/WAEIymxMLjU7/mIu1Y5rO6SXEfMby99xIlTM=; b=ZtliMg4qAst50+UyCQ5LHLg17aCG8GZtJU8e4paYkna1R77FxWWUlHpOQ04UHGJ5Yu/Qdy 8v7YQMNP6DCJHJla6yqEb9BsgXPNWK3unjgdiSN+1hCC17zn4T1KFT4JzVOgz4iAPHhc7J CGHOM1wKgi/nSNS4aYjAf5tw5ye+eKk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-65-03i35tn7N4WZM9wlukLHow-1; Wed, 26 Aug 2020 14:25:53 -0400 X-MC-Unique: 03i35tn7N4WZM9wlukLHow-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D30F7189E618; Wed, 26 Aug 2020 18:25:50 +0000 (UTC) Received: from Whitewolf.redhat.com (ovpn-119-77.rdu2.redhat.com [10.10.119.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id E159B100238E; Wed, 26 Aug 2020 18:25:48 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org Cc: Sean Paul , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= , Manasi Navare , Uma Shankar , Gwan-gyeong Mun , Imre Deak , Wambui Karuga , Lucas De Marchi , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 13/20] drm/i915/dp: Extract drm_dp_read_downstream_info() Date: Wed, 26 Aug 2020 14:24:49 -0400 Message-Id: <20200826182456.322681-14-lyude@redhat.com> In-Reply-To: <20200826182456.322681-1-lyude@redhat.com> References: <20200826182456.322681-1-lyude@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We're going to be doing the same probing process in nouveau for determining downstream DP port capabilities, so let's deduplicate the work by moving i915's code for handling this into a shared helper: drm_dp_read_downstream_info(). Note that when we do this, we also do make some functional changes while we're at it: * We always clear the downstream port info before trying to read it, just to make things easier for the caller * We skip reading downstream port info if the DPCD indicates that we don't support downstream port info * We only read as many bytes as needed for the reported number of downstream ports, no sense in reading the whole thing every time v2: * Fixup logic for calculating the downstream port length to account for the fact that downstream port caps can be either 1 byte or 4 bytes long. We can actually skip fixing the max_clock/max_bpc helpers here since they all check for DP_DETAILED_CAP_INFO_AVAILABLE anyway. * Fix ret code check for drm_dp_dpcd_read v5: * Change name from drm_dp_downstream_read_info() to drm_dp_read_downstream_info() * Also, add "See Also" sections for the various downstream info functions (drm_dp_read_downstream_info(), drm_dp_downstream_max_clock(), drm_dp_downstream_max_bpc()) Reviewed-by: Sean Paul Signed-off-by: Lyude Paul squash! drm/i915/dp: Extract drm_dp_read_downstream_info() Signed-off-by: Lyude Paul --- drivers/gpu/drm/drm_dp_helper.c | 62 ++++++++++++++++++++++++- drivers/gpu/drm/i915/display/intel_dp.c | 14 +----- include/drm/drm_dp_helper.h | 3 ++ 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index 4c21cf69dad5a..f3643894ad951 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -423,6 +423,56 @@ bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux, } EXPORT_SYMBOL(drm_dp_send_real_edid_checksum); +static u8 drm_dp_downstream_port_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE]) +{ + u8 port_count = dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_PORT_COUNT_MASK; + + if (dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DETAILED_CAP_INFO_AVAILABLE && port_count > 4) + port_count = 4; + + return port_count; +} + +/** + * drm_dp_read_downstream_info() - read DPCD downstream port info if available + * @aux: DisplayPort AUX channel + * @dpcd: A cached copy of the port's DPCD + * @downstream_ports: buffer to store the downstream port info in + * + * See also: + * drm_dp_downstream_max_clock() + * drm_dp_downstream_max_bpc() + * + * Returns: 0 if either the downstream port info was read successfully or + * there was no downstream info to read, or a negative error code otherwise. + */ +int drm_dp_read_downstream_info(struct drm_dp_aux *aux, + const u8 dpcd[DP_RECEIVER_CAP_SIZE], + u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]) +{ + int ret; + u8 len; + + memset(downstream_ports, 0, DP_MAX_DOWNSTREAM_PORTS); + + /* No downstream info to read */ + if (!drm_dp_is_branch(dpcd) || + dpcd[DP_DPCD_REV] < DP_DPCD_REV_10 || + !(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT)) + return 0; + + len = drm_dp_downstream_port_count(dpcd); + if (dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DETAILED_CAP_INFO_AVAILABLE) + len *= 4; + + ret = drm_dp_dpcd_read(aux, DP_DOWNSTREAM_PORT_0, downstream_ports, len); + if (ret < 0) + return ret; + + return ret == len ? 0 : -EIO; +} +EXPORT_SYMBOL(drm_dp_read_downstream_info); + /** * drm_dp_downstream_max_clock() - extract branch device max * pixel rate for legacy VGA @@ -431,7 +481,11 @@ EXPORT_SYMBOL(drm_dp_send_real_edid_checksum); * @dpcd: DisplayPort configuration data * @port_cap: port capabilities * - * Returns max clock in kHz on success or 0 if max clock not defined + * See also: + * drm_dp_read_downstream_info() + * drm_dp_downstream_max_bpc() + * + * Returns: Max clock in kHz on success or 0 if max clock not defined */ int drm_dp_downstream_max_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE], const u8 port_cap[4]) @@ -462,7 +516,11 @@ EXPORT_SYMBOL(drm_dp_downstream_max_clock); * @dpcd: DisplayPort configuration data * @port_cap: port capabilities * - * Returns max bpc on success or 0 if max bpc not defined + * See also: + * drm_dp_read_downstream_info() + * drm_dp_downstream_max_clock() + * + * Returns: Max bpc on success or 0 if max bpc not defined */ int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE], const u8 port_cap[4]) diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c index 4c7314b7a84e4..9c4b806af8c79 100644 --- a/drivers/gpu/drm/i915/display/intel_dp.c +++ b/drivers/gpu/drm/i915/display/intel_dp.c @@ -4685,18 +4685,8 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp) return false; } - if (!drm_dp_is_branch(intel_dp->dpcd)) - return true; /* native DP sink */ - - if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) - return true; /* no per-port downstream info */ - - if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, - intel_dp->downstream_ports, - DP_MAX_DOWNSTREAM_PORTS) < 0) - return false; /* downstream port status fetch failed */ - - return true; + return drm_dp_read_downstream_info(&intel_dp->aux, intel_dp->dpcd, + intel_dp->downstream_ports) == 0; } static bool diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index 5c28199248626..b8716b200666f 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -1613,6 +1613,9 @@ int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux, u8 real_edid_checksum); +int drm_dp_read_downstream_info(struct drm_dp_aux *aux, + const u8 dpcd[DP_RECEIVER_CAP_SIZE], + u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]); int drm_dp_downstream_max_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE], const u8 port_cap[4]); int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE], -- 2.26.2