From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50419C433DF for ; Thu, 20 Aug 2020 16:07:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 141362072D for ; Thu, 20 Aug 2020 16:07:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="irl+0Ae3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729493AbgHTQH4 (ORCPT ); Thu, 20 Aug 2020 12:07:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42155 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbgHTQHz (ORCPT ); Thu, 20 Aug 2020 12:07:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597939672; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJ60GW5I7GDTJbBQqWE3EmOtkI5NSzudyRlj9VDcORI=; b=irl+0Ae3e5VdH4D1MZqpxoKQjO1g5wfIdYglLn6YWlPRsTTZc1YLuggEdM8Z35VDBfdGVj 5UtoOrKc0Bc7I0LU96Vt9MtBRR1LSMUYJyk3nHDFEF2nPqrENnBEUzutvIseY5QfqYZStB /HWQlNbfxyq0NClxAZSWwJgE3KEURo0= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-499-ceuqVSRVMFeu0-lSkEWgEQ-1; Thu, 20 Aug 2020 12:07:48 -0400 X-MC-Unique: ceuqVSRVMFeu0-lSkEWgEQ-1 Received: by mail-qt1-f199.google.com with SMTP id g10so1851400qtr.19 for ; Thu, 20 Aug 2020 09:07:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:organization:user-agent:mime-version :content-transfer-encoding; bh=qJ60GW5I7GDTJbBQqWE3EmOtkI5NSzudyRlj9VDcORI=; b=pCDBtuXDZYZGnsfW7EBzuX4ffMD0svudHyWWP1uYRKv/3WF7px/rcp05pAZj6DuEMv h+1fMXoxX1UuIHeleqrPqb43m1MVPGKlgu2V88MHI91m6GF46WkPg2fbje0XRQ7jgdpN adujZjLGLkBYJ3XaPWXUpIjYPomhbdrJCq76IZ0NTGDlCBsrGmUTPIyNkBiq4D0IxJEk WuoHjQekthTDxSdX7dhVDJps0wSO+dhdXNyLyc35u6BhQyAIMcFIvxWK5yqQPk2/vWsY wYgCaHN7zk5fv8ER240hQ7L33E7VAE9LSHHyr07wr84e0Dp9Mr5xChOlq3x83QLxwJlj yAXA== X-Gm-Message-State: AOAM532+TS+/1+Zj9Tk0nqL5weun3DwtI+2rqhq7qcBA3pnWG+9Fo88O CYK+VdDzceJ3bjIHJ8P1F1zP7JC4wCHhs+rYZAZuMpO5Cl6LFAiXkiTiQJY+M1P4Ae0IlEMUgrN 5fAwaLg8mXXtbrr9fsm3BaWLu X-Received: by 2002:a05:6214:d46:: with SMTP id 6mr3708541qvr.240.1597939667688; Thu, 20 Aug 2020 09:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO40CKZE46leN+nONQ3YVFgRPEtJrYd3+OHw2O70kDbwE+E1FviIHr4Wm0L0PBTbbLO5psCw== X-Received: by 2002:a05:6214:d46:: with SMTP id 6mr3708503qvr.240.1597939667342; Thu, 20 Aug 2020 09:07:47 -0700 (PDT) Received: from Whitewolf.lyude.net (pool-108-49-102-102.bstnma.fios.verizon.net. [108.49.102.102]) by smtp.gmail.com with ESMTPSA id t8sm2599572qke.7.2020.08.20.09.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 09:07:46 -0700 (PDT) Message-ID: Subject: Re: [RFC 19/20] drm/i915/dp: Extract drm_dp_read_dpcd_caps() From: Lyude Paul Reply-To: lyude@redhat.com To: Sean Paul Cc: nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Thomas Zimmermann , Juha-Pekka Heikkila , David Airlie , Lucas De Marchi , open list , Gwan-gyeong Mun , Manasi Navare , Uma Shankar , Rodrigo Vivi , =?ISO-8859-1?Q?Jos=E9?= Roberto de Souza , Animesh Manna , Wambui Karuga Date: Thu, 20 Aug 2020 12:07:44 -0400 In-Reply-To: <20200819152914.GE46474@art_vandelay> References: <20200811200457.134743-1-lyude@redhat.com> <20200811200457.134743-20-lyude@redhat.com> <20200819152914.GE46474@art_vandelay> Organization: Red Hat Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2020-08-19 at 11:29 -0400, Sean Paul wrote: > On Tue, Aug 11, 2020 at 04:04:56PM -0400, Lyude Paul wrote: > > Since DP 1.3, it's been possible for DP receivers to specify an > > additional set of DPCD capabilities, which can take precedence over the > > capabilities reported at DP_DPCD_REV. > > > > Basically any device supporting DP is going to need to read these in an > > identical manner, in particular nouveau, so let's go ahead and just move > > this code out of i915 into a shared DRM DP helper that we can use in > > other drivers. > > > > Signed-off-by: Lyude Paul > > --- > > drivers/gpu/drm/drm_dp_helper.c | 76 +++++++++++++++++++++ > > drivers/gpu/drm/i915/display/intel_dp.c | 60 +--------------- > > drivers/gpu/drm/i915/display/intel_dp.h | 1 - > > drivers/gpu/drm/i915/display/intel_lspcon.c | 2 +- > > include/drm/drm_dp_helper.h | 3 + > > 5 files changed, 82 insertions(+), 60 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_dp_helper.c > > b/drivers/gpu/drm/drm_dp_helper.c > > index 0ff2959c8f8e8..f9445915c6c26 100644 > > --- a/drivers/gpu/drm/drm_dp_helper.c > > +++ b/drivers/gpu/drm/drm_dp_helper.c > > @@ -423,6 +423,82 @@ bool drm_dp_send_real_edid_checksum(struct drm_dp_aux > > *aux, > > } > > EXPORT_SYMBOL(drm_dp_send_real_edid_checksum); > > > > +static int drm_dp_read_extended_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + u8 dpcd_ext[6]; > > + int ret; > > + > > + /* > > + * Prior to DP1.3 the bit represented by > > + * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > + * If it is set DP_DPCD_REV at 0000h could be at a value less than > > + * the true capability of the panel. The only way to check is to > > + * then compare 0000h and 2200h. > > + */ > > + if (!(dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > + DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > + return 0; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DP13_DPCD_REV, &dpcd_ext, > > + sizeof(dpcd_ext)); > > + if (ret != sizeof(dpcd_ext)) > > + return -EIO; > > + > > + if (dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > + DRM_DEBUG_KMS("%s: Extended DPCD rev less than base DPCD rev (%d > > > %d)\n", > > + aux->name, dpcd[DP_DPCD_REV], > > + dpcd_ext[DP_DPCD_REV]); > > Might be a good opportunity to convert all of these to drm_dbg_dp()? > > > + return 0; > > + } > > + > > + if (!memcmp(dpcd, dpcd_ext, sizeof(dpcd_ext))) > > + return 0; > > + > > + DRM_DEBUG_KMS("%s: Base DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + memcpy(dpcd, dpcd_ext, sizeof(dpcd_ext)); > > + > > + return 0; > > +} > > + > > +/** > > + * drm_dp_read_dpcd_caps() - read DPCD caps and extended DPCD caps if > > + * available > > + * @aux: DisplayPort AUX channel > > + * @dpcd: Buffer to store the resulting DPCD in > > + * > > + * Attempts to read the base DPCD caps for @aux. Additionally, this > > function > > + * checks for and reads the extended DPRX caps (%DP_DP13_DPCD_REV) if > > + * present. > > + * > > + * Returns: %0 if the DPCD was read successfully, negative error code > > + * otherwise. > > + */ > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + int ret; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DPCD_REV, dpcd, DP_RECEIVER_CAP_SIZE); > > + if (ret != DP_RECEIVER_CAP_SIZE || dpcd[DP_DPCD_REV] == 0) > > + return -EIO; > > + > > + ret = drm_dp_read_extended_dpcd_caps(aux, dpcd); > > + if (ret < 0) > > + return ret; > > I wonder if we should just go with the "regular" dpcd caps we just read in > this > case? FWIW - we generally want to just abort on failed DPCD reads since if a device doesn't implement a feature like this, it'll usually read all zeroes. Failed DPCD reads are almost always just the result of something suddenly being disconnected (excluding some cases I've seen on MST, but I think those more have to do with us sending incorrect dpcd read/write requests...) > > Regardless of my nits, > > Reviewed-by: Sean Paul > > > + > > + DRM_DEBUG_KMS("%s: DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + if (dpcd[DP_DPCD_REV] == 0) > > + ret = -EIO; > > + > > + return ret; > > +} > > +EXPORT_SYMBOL(drm_dp_read_dpcd_caps); > > + > > /** > > * drm_dp_downstream_read_info() - read DPCD downstream port info if > > available > > * @aux: DisplayPort AUX channel > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c > > b/drivers/gpu/drm/i915/display/intel_dp.c > > index e343965a483df..230aa0360dc61 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.c > > +++ b/drivers/gpu/drm/i915/display/intel_dp.c > > @@ -4449,62 +4449,6 @@ intel_dp_link_down(struct intel_encoder *encoder, > > } > > } > > > > -static void > > -intel_dp_extended_receiver_capabilities(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - u8 dpcd_ext[6]; > > - > > - /* > > - * Prior to DP1.3 the bit represented by > > - * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > - * if it is set DP_DPCD_REV at 0000h could be at a value less than > > - * the true capability of the panel. The only way to check is to > > - * then compare 0000h and 2200h. > > - */ > > - if (!(intel_dp->dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > - DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > - return; > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, DP_DP13_DPCD_REV, > > - &dpcd_ext, sizeof(dpcd_ext)) != sizeof(dpcd_ext)) { > > - drm_err(&i915->drm, > > - "DPCD failed read at extended capabilities\n"); > > - return; > > - } > > - > > - if (intel_dp->dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > - drm_dbg_kms(&i915->drm, > > - "DPCD extended DPCD rev less than base DPCD rev\n"); > > - return; > > - } > > - > > - if (!memcmp(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext))) > > - return; > > - > > - drm_dbg_kms(&i915->drm, "Base DPCD: %*ph\n", > > - (int)sizeof(intel_dp->dpcd), intel_dp->dpcd); > > - > > - memcpy(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext)); > > -} > > - > > -bool > > -intel_dp_read_dpcd(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, > > - sizeof(intel_dp->dpcd)) < 0) > > - return false; /* aux transfer failed */ > > - > > - intel_dp_extended_receiver_capabilities(intel_dp); > > - > > - drm_dbg_kms(&i915->drm, "DPCD: %*ph\n", (int)sizeof(intel_dp->dpcd), > > - intel_dp->dpcd); > > - > > - return intel_dp->dpcd[DP_DPCD_REV] != 0; > > -} > > - > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) > > { > > u8 dprx = 0; > > @@ -4563,7 +4507,7 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp) > > /* this function is meant to be called only once */ > > drm_WARN_ON(&dev_priv->drm, intel_dp->dpcd[DP_DPCD_REV] != 0); > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd) != 0) > > return false; > > > > drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, > > @@ -4650,7 +4594,7 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp) > > { > > int ret; > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd)) > > return false; > > > > /* > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.h > > b/drivers/gpu/drm/i915/display/intel_dp.h > > index b901ab850cbd9..0a3af3410d52e 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.h > > +++ b/drivers/gpu/drm/i915/display/intel_dp.h > > @@ -99,7 +99,6 @@ bool intel_dp_source_supports_hbr3(struct intel_dp > > *intel_dp); > > bool > > intel_dp_get_link_status(struct intel_dp *intel_dp, u8 *link_status); > > > > -bool intel_dp_read_dpcd(struct intel_dp *intel_dp); > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp); > > int intel_dp_link_required(int pixel_clock, int bpp); > > int intel_dp_max_data_rate(int max_link_clock, int max_lanes); > > diff --git a/drivers/gpu/drm/i915/display/intel_lspcon.c > > b/drivers/gpu/drm/i915/display/intel_lspcon.c > > index b781bf4696443..dc1b35559afdf 100644 > > --- a/drivers/gpu/drm/i915/display/intel_lspcon.c > > +++ b/drivers/gpu/drm/i915/display/intel_lspcon.c > > @@ -571,7 +571,7 @@ bool lspcon_init(struct intel_digital_port *dig_port) > > return false; > > } > > > > - if (!intel_dp_read_dpcd(dp)) { > > + if (drm_dp_read_dpcd_caps(&dp->aux, dp->dpcd) != 0) { > > DRM_ERROR("LSPCON DPCD read failed\n"); > > return false; > > } > > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h > > index 0c141fc81aaa8..11649e93e5bb6 100644 > > --- a/include/drm/drm_dp_helper.h > > +++ b/include/drm/drm_dp_helper.h > > @@ -1607,6 +1607,9 @@ static inline ssize_t drm_dp_dpcd_writeb(struct > > drm_dp_aux *aux, > > return drm_dp_dpcd_write(aux, offset, &value, 1); > > } > > > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]); > > + > > int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, > > u8 status[DP_LINK_STATUS_SIZE]); > > > > -- > > 2.26.2 > > > > _______________________________________________ > > dri-devel mailing list > > dri-devel@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Sincerely, Lyude Paul (she/her) Software Engineer at Red Hat From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lyude Paul Subject: Re: [RFC 19/20] drm/i915/dp: Extract drm_dp_read_dpcd_caps() Date: Thu, 20 Aug 2020 12:07:44 -0400 Message-ID: References: <20200811200457.134743-1-lyude@redhat.com> <20200811200457.134743-20-lyude@redhat.com> <20200819152914.GE46474@art_vandelay> Reply-To: lyude-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20200819152914.GE46474@art_vandelay> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org Sender: "Nouveau" To: Sean Paul Cc: Juha-Pekka Heikkila , David Airlie , nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, Lucas De Marchi , open list , dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, Gwan-gyeong Mun , Manasi Navare , Uma Shankar , =?ISO-8859-1?Q?Jos=E9?= Roberto de Souza , Rodrigo Vivi , Animesh Manna , Wambui Karuga List-Id: nouveau.vger.kernel.org On Wed, 2020-08-19 at 11:29 -0400, Sean Paul wrote: > On Tue, Aug 11, 2020 at 04:04:56PM -0400, Lyude Paul wrote: > > Since DP 1.3, it's been possible for DP receivers to specify an > > additional set of DPCD capabilities, which can take precedence over the > > capabilities reported at DP_DPCD_REV. > > > > Basically any device supporting DP is going to need to read these in an > > identical manner, in particular nouveau, so let's go ahead and just move > > this code out of i915 into a shared DRM DP helper that we can use in > > other drivers. > > > > Signed-off-by: Lyude Paul > > --- > > drivers/gpu/drm/drm_dp_helper.c | 76 +++++++++++++++++++++ > > drivers/gpu/drm/i915/display/intel_dp.c | 60 +--------------- > > drivers/gpu/drm/i915/display/intel_dp.h | 1 - > > drivers/gpu/drm/i915/display/intel_lspcon.c | 2 +- > > include/drm/drm_dp_helper.h | 3 + > > 5 files changed, 82 insertions(+), 60 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_dp_helper.c > > b/drivers/gpu/drm/drm_dp_helper.c > > index 0ff2959c8f8e8..f9445915c6c26 100644 > > --- a/drivers/gpu/drm/drm_dp_helper.c > > +++ b/drivers/gpu/drm/drm_dp_helper.c > > @@ -423,6 +423,82 @@ bool drm_dp_send_real_edid_checksum(struct drm_dp_aux > > *aux, > > } > > EXPORT_SYMBOL(drm_dp_send_real_edid_checksum); > > > > +static int drm_dp_read_extended_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + u8 dpcd_ext[6]; > > + int ret; > > + > > + /* > > + * Prior to DP1.3 the bit represented by > > + * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > + * If it is set DP_DPCD_REV at 0000h could be at a value less than > > + * the true capability of the panel. The only way to check is to > > + * then compare 0000h and 2200h. > > + */ > > + if (!(dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > + DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > + return 0; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DP13_DPCD_REV, &dpcd_ext, > > + sizeof(dpcd_ext)); > > + if (ret != sizeof(dpcd_ext)) > > + return -EIO; > > + > > + if (dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > + DRM_DEBUG_KMS("%s: Extended DPCD rev less than base DPCD rev (%d > > > %d)\n", > > + aux->name, dpcd[DP_DPCD_REV], > > + dpcd_ext[DP_DPCD_REV]); > > Might be a good opportunity to convert all of these to drm_dbg_dp()? > > > + return 0; > > + } > > + > > + if (!memcmp(dpcd, dpcd_ext, sizeof(dpcd_ext))) > > + return 0; > > + > > + DRM_DEBUG_KMS("%s: Base DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + memcpy(dpcd, dpcd_ext, sizeof(dpcd_ext)); > > + > > + return 0; > > +} > > + > > +/** > > + * drm_dp_read_dpcd_caps() - read DPCD caps and extended DPCD caps if > > + * available > > + * @aux: DisplayPort AUX channel > > + * @dpcd: Buffer to store the resulting DPCD in > > + * > > + * Attempts to read the base DPCD caps for @aux. Additionally, this > > function > > + * checks for and reads the extended DPRX caps (%DP_DP13_DPCD_REV) if > > + * present. > > + * > > + * Returns: %0 if the DPCD was read successfully, negative error code > > + * otherwise. > > + */ > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + int ret; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DPCD_REV, dpcd, DP_RECEIVER_CAP_SIZE); > > + if (ret != DP_RECEIVER_CAP_SIZE || dpcd[DP_DPCD_REV] == 0) > > + return -EIO; > > + > > + ret = drm_dp_read_extended_dpcd_caps(aux, dpcd); > > + if (ret < 0) > > + return ret; > > I wonder if we should just go with the "regular" dpcd caps we just read in > this > case? FWIW - we generally want to just abort on failed DPCD reads since if a device doesn't implement a feature like this, it'll usually read all zeroes. Failed DPCD reads are almost always just the result of something suddenly being disconnected (excluding some cases I've seen on MST, but I think those more have to do with us sending incorrect dpcd read/write requests...) > > Regardless of my nits, > > Reviewed-by: Sean Paul > > > + > > + DRM_DEBUG_KMS("%s: DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + if (dpcd[DP_DPCD_REV] == 0) > > + ret = -EIO; > > + > > + return ret; > > +} > > +EXPORT_SYMBOL(drm_dp_read_dpcd_caps); > > + > > /** > > * drm_dp_downstream_read_info() - read DPCD downstream port info if > > available > > * @aux: DisplayPort AUX channel > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c > > b/drivers/gpu/drm/i915/display/intel_dp.c > > index e343965a483df..230aa0360dc61 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.c > > +++ b/drivers/gpu/drm/i915/display/intel_dp.c > > @@ -4449,62 +4449,6 @@ intel_dp_link_down(struct intel_encoder *encoder, > > } > > } > > > > -static void > > -intel_dp_extended_receiver_capabilities(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - u8 dpcd_ext[6]; > > - > > - /* > > - * Prior to DP1.3 the bit represented by > > - * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > - * if it is set DP_DPCD_REV at 0000h could be at a value less than > > - * the true capability of the panel. The only way to check is to > > - * then compare 0000h and 2200h. > > - */ > > - if (!(intel_dp->dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > - DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > - return; > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, DP_DP13_DPCD_REV, > > - &dpcd_ext, sizeof(dpcd_ext)) != sizeof(dpcd_ext)) { > > - drm_err(&i915->drm, > > - "DPCD failed read at extended capabilities\n"); > > - return; > > - } > > - > > - if (intel_dp->dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > - drm_dbg_kms(&i915->drm, > > - "DPCD extended DPCD rev less than base DPCD rev\n"); > > - return; > > - } > > - > > - if (!memcmp(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext))) > > - return; > > - > > - drm_dbg_kms(&i915->drm, "Base DPCD: %*ph\n", > > - (int)sizeof(intel_dp->dpcd), intel_dp->dpcd); > > - > > - memcpy(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext)); > > -} > > - > > -bool > > -intel_dp_read_dpcd(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, > > - sizeof(intel_dp->dpcd)) < 0) > > - return false; /* aux transfer failed */ > > - > > - intel_dp_extended_receiver_capabilities(intel_dp); > > - > > - drm_dbg_kms(&i915->drm, "DPCD: %*ph\n", (int)sizeof(intel_dp->dpcd), > > - intel_dp->dpcd); > > - > > - return intel_dp->dpcd[DP_DPCD_REV] != 0; > > -} > > - > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) > > { > > u8 dprx = 0; > > @@ -4563,7 +4507,7 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp) > > /* this function is meant to be called only once */ > > drm_WARN_ON(&dev_priv->drm, intel_dp->dpcd[DP_DPCD_REV] != 0); > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd) != 0) > > return false; > > > > drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, > > @@ -4650,7 +4594,7 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp) > > { > > int ret; > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd)) > > return false; > > > > /* > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.h > > b/drivers/gpu/drm/i915/display/intel_dp.h > > index b901ab850cbd9..0a3af3410d52e 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.h > > +++ b/drivers/gpu/drm/i915/display/intel_dp.h > > @@ -99,7 +99,6 @@ bool intel_dp_source_supports_hbr3(struct intel_dp > > *intel_dp); > > bool > > intel_dp_get_link_status(struct intel_dp *intel_dp, u8 *link_status); > > > > -bool intel_dp_read_dpcd(struct intel_dp *intel_dp); > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp); > > int intel_dp_link_required(int pixel_clock, int bpp); > > int intel_dp_max_data_rate(int max_link_clock, int max_lanes); > > diff --git a/drivers/gpu/drm/i915/display/intel_lspcon.c > > b/drivers/gpu/drm/i915/display/intel_lspcon.c > > index b781bf4696443..dc1b35559afdf 100644 > > --- a/drivers/gpu/drm/i915/display/intel_lspcon.c > > +++ b/drivers/gpu/drm/i915/display/intel_lspcon.c > > @@ -571,7 +571,7 @@ bool lspcon_init(struct intel_digital_port *dig_port) > > return false; > > } > > > > - if (!intel_dp_read_dpcd(dp)) { > > + if (drm_dp_read_dpcd_caps(&dp->aux, dp->dpcd) != 0) { > > DRM_ERROR("LSPCON DPCD read failed\n"); > > return false; > > } > > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h > > index 0c141fc81aaa8..11649e93e5bb6 100644 > > --- a/include/drm/drm_dp_helper.h > > +++ b/include/drm/drm_dp_helper.h > > @@ -1607,6 +1607,9 @@ static inline ssize_t drm_dp_dpcd_writeb(struct > > drm_dp_aux *aux, > > return drm_dp_dpcd_write(aux, offset, &value, 1); > > } > > > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]); > > + > > int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, > > u8 status[DP_LINK_STATUS_SIZE]); > > > > -- > > 2.26.2 > > > > _______________________________________________ > > dri-devel mailing list > > dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Sincerely, Lyude Paul (she/her) Software Engineer at Red Hat From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AF7AC433E3 for ; Thu, 20 Aug 2020 16:08:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A4D42072D for ; Thu, 20 Aug 2020 16:08:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LfDHVtoF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A4D42072D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C76436E97E; Thu, 20 Aug 2020 16:08:00 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 151296E97E for ; Thu, 20 Aug 2020 16:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597939679; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJ60GW5I7GDTJbBQqWE3EmOtkI5NSzudyRlj9VDcORI=; b=LfDHVtoF+7DsHAYn3FDokgjlseH7qZ0uUalOnBW/eHgOi0uZ9XOVztHmewm/BUZu/drCdV n5qBL8u4I9omGYVYT2Hw7tTaAB0oBCPmlBtK7nVcB3OA2/PJapn5rc82VwbUHDUWpbdAc6 xGM8Wa27JPtTibgxTRtj/t5jxU7lra4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-B1El3C4ANbOHewYYvL0QBw-1; Thu, 20 Aug 2020 12:07:48 -0400 X-MC-Unique: B1El3C4ANbOHewYYvL0QBw-1 Received: by mail-qv1-f71.google.com with SMTP id c4so1676028qvq.15 for ; Thu, 20 Aug 2020 09:07:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:organization:user-agent:mime-version :content-transfer-encoding; bh=qJ60GW5I7GDTJbBQqWE3EmOtkI5NSzudyRlj9VDcORI=; b=N7QppDq9yaDNJNWQrXMbk51S9TJjfNmtMmtUDOWw3GOQo6mpRjOa+rVd42t/GMzYXT Eh6IOd+bkyafvc7oR2pJSkZxjPDfh95jZwwcfH1OLzua+wpEcvjZYEo50MIabYa1vpLv FJsJDkmuM652ofb6dWakh7ur+Nz8hF8Zo010+JUkYSEQ4ARpbpc63kuCKQQzp4cGqMPk EaADEMUfNDpkbEk4Agt+D9aG0hdnuZJRVJhtu9ZVjgfCRxudMp8q7VgR2bVuvKsquSGP SHdzod/cIDgfDYBDjfsSfoPb05FthvCYf56qtWoZ/UyCgCpczcuP5C9LWTkZefeOBwJl Cn9w== X-Gm-Message-State: AOAM532Hxv1pmAJQCFw91spdQgXJRyF3udkcHRCcXLSRRWQ1vREcFjI/ qNo5y+rRRPkIoj8G+qx+1B70qIk3ugFaap0bZyjyc7G3XL+0sEYlSuDak2V4XpqjAP22aRZGx7V pm5ln2G2YIaXclOLmD/yTSst3FgVh X-Received: by 2002:a05:6214:d46:: with SMTP id 6mr3708550qvr.240.1597939667759; Thu, 20 Aug 2020 09:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO40CKZE46leN+nONQ3YVFgRPEtJrYd3+OHw2O70kDbwE+E1FviIHr4Wm0L0PBTbbLO5psCw== X-Received: by 2002:a05:6214:d46:: with SMTP id 6mr3708503qvr.240.1597939667342; Thu, 20 Aug 2020 09:07:47 -0700 (PDT) Received: from Whitewolf.lyude.net (pool-108-49-102-102.bstnma.fios.verizon.net. [108.49.102.102]) by smtp.gmail.com with ESMTPSA id t8sm2599572qke.7.2020.08.20.09.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 09:07:46 -0700 (PDT) Message-ID: Subject: Re: [RFC 19/20] drm/i915/dp: Extract drm_dp_read_dpcd_caps() From: Lyude Paul To: Sean Paul Date: Thu, 20 Aug 2020 12:07:44 -0400 In-Reply-To: <20200819152914.GE46474@art_vandelay> References: <20200811200457.134743-1-lyude@redhat.com> <20200811200457.134743-20-lyude@redhat.com> <20200819152914.GE46474@art_vandelay> Organization: Red Hat User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lyude@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: lyude@redhat.com Cc: Juha-Pekka Heikkila , David Airlie , nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Lucas De Marchi , open list , dri-devel@lists.freedesktop.org, Gwan-gyeong Mun , Manasi Navare , Uma Shankar , =?ISO-8859-1?Q?Jos=E9?= Roberto de Souza , Thomas Zimmermann , Rodrigo Vivi , Animesh Manna , Wambui Karuga Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, 2020-08-19 at 11:29 -0400, Sean Paul wrote: > On Tue, Aug 11, 2020 at 04:04:56PM -0400, Lyude Paul wrote: > > Since DP 1.3, it's been possible for DP receivers to specify an > > additional set of DPCD capabilities, which can take precedence over the > > capabilities reported at DP_DPCD_REV. > > > > Basically any device supporting DP is going to need to read these in an > > identical manner, in particular nouveau, so let's go ahead and just move > > this code out of i915 into a shared DRM DP helper that we can use in > > other drivers. > > > > Signed-off-by: Lyude Paul > > --- > > drivers/gpu/drm/drm_dp_helper.c | 76 +++++++++++++++++++++ > > drivers/gpu/drm/i915/display/intel_dp.c | 60 +--------------- > > drivers/gpu/drm/i915/display/intel_dp.h | 1 - > > drivers/gpu/drm/i915/display/intel_lspcon.c | 2 +- > > include/drm/drm_dp_helper.h | 3 + > > 5 files changed, 82 insertions(+), 60 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_dp_helper.c > > b/drivers/gpu/drm/drm_dp_helper.c > > index 0ff2959c8f8e8..f9445915c6c26 100644 > > --- a/drivers/gpu/drm/drm_dp_helper.c > > +++ b/drivers/gpu/drm/drm_dp_helper.c > > @@ -423,6 +423,82 @@ bool drm_dp_send_real_edid_checksum(struct drm_dp_aux > > *aux, > > } > > EXPORT_SYMBOL(drm_dp_send_real_edid_checksum); > > > > +static int drm_dp_read_extended_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + u8 dpcd_ext[6]; > > + int ret; > > + > > + /* > > + * Prior to DP1.3 the bit represented by > > + * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > + * If it is set DP_DPCD_REV at 0000h could be at a value less than > > + * the true capability of the panel. The only way to check is to > > + * then compare 0000h and 2200h. > > + */ > > + if (!(dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > + DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > + return 0; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DP13_DPCD_REV, &dpcd_ext, > > + sizeof(dpcd_ext)); > > + if (ret != sizeof(dpcd_ext)) > > + return -EIO; > > + > > + if (dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > + DRM_DEBUG_KMS("%s: Extended DPCD rev less than base DPCD rev (%d > > > %d)\n", > > + aux->name, dpcd[DP_DPCD_REV], > > + dpcd_ext[DP_DPCD_REV]); > > Might be a good opportunity to convert all of these to drm_dbg_dp()? > > > + return 0; > > + } > > + > > + if (!memcmp(dpcd, dpcd_ext, sizeof(dpcd_ext))) > > + return 0; > > + > > + DRM_DEBUG_KMS("%s: Base DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + memcpy(dpcd, dpcd_ext, sizeof(dpcd_ext)); > > + > > + return 0; > > +} > > + > > +/** > > + * drm_dp_read_dpcd_caps() - read DPCD caps and extended DPCD caps if > > + * available > > + * @aux: DisplayPort AUX channel > > + * @dpcd: Buffer to store the resulting DPCD in > > + * > > + * Attempts to read the base DPCD caps for @aux. Additionally, this > > function > > + * checks for and reads the extended DPRX caps (%DP_DP13_DPCD_REV) if > > + * present. > > + * > > + * Returns: %0 if the DPCD was read successfully, negative error code > > + * otherwise. > > + */ > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + int ret; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DPCD_REV, dpcd, DP_RECEIVER_CAP_SIZE); > > + if (ret != DP_RECEIVER_CAP_SIZE || dpcd[DP_DPCD_REV] == 0) > > + return -EIO; > > + > > + ret = drm_dp_read_extended_dpcd_caps(aux, dpcd); > > + if (ret < 0) > > + return ret; > > I wonder if we should just go with the "regular" dpcd caps we just read in > this > case? FWIW - we generally want to just abort on failed DPCD reads since if a device doesn't implement a feature like this, it'll usually read all zeroes. Failed DPCD reads are almost always just the result of something suddenly being disconnected (excluding some cases I've seen on MST, but I think those more have to do with us sending incorrect dpcd read/write requests...) > > Regardless of my nits, > > Reviewed-by: Sean Paul > > > + > > + DRM_DEBUG_KMS("%s: DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + if (dpcd[DP_DPCD_REV] == 0) > > + ret = -EIO; > > + > > + return ret; > > +} > > +EXPORT_SYMBOL(drm_dp_read_dpcd_caps); > > + > > /** > > * drm_dp_downstream_read_info() - read DPCD downstream port info if > > available > > * @aux: DisplayPort AUX channel > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c > > b/drivers/gpu/drm/i915/display/intel_dp.c > > index e343965a483df..230aa0360dc61 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.c > > +++ b/drivers/gpu/drm/i915/display/intel_dp.c > > @@ -4449,62 +4449,6 @@ intel_dp_link_down(struct intel_encoder *encoder, > > } > > } > > > > -static void > > -intel_dp_extended_receiver_capabilities(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - u8 dpcd_ext[6]; > > - > > - /* > > - * Prior to DP1.3 the bit represented by > > - * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > - * if it is set DP_DPCD_REV at 0000h could be at a value less than > > - * the true capability of the panel. The only way to check is to > > - * then compare 0000h and 2200h. > > - */ > > - if (!(intel_dp->dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > - DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > - return; > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, DP_DP13_DPCD_REV, > > - &dpcd_ext, sizeof(dpcd_ext)) != sizeof(dpcd_ext)) { > > - drm_err(&i915->drm, > > - "DPCD failed read at extended capabilities\n"); > > - return; > > - } > > - > > - if (intel_dp->dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > - drm_dbg_kms(&i915->drm, > > - "DPCD extended DPCD rev less than base DPCD rev\n"); > > - return; > > - } > > - > > - if (!memcmp(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext))) > > - return; > > - > > - drm_dbg_kms(&i915->drm, "Base DPCD: %*ph\n", > > - (int)sizeof(intel_dp->dpcd), intel_dp->dpcd); > > - > > - memcpy(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext)); > > -} > > - > > -bool > > -intel_dp_read_dpcd(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, > > - sizeof(intel_dp->dpcd)) < 0) > > - return false; /* aux transfer failed */ > > - > > - intel_dp_extended_receiver_capabilities(intel_dp); > > - > > - drm_dbg_kms(&i915->drm, "DPCD: %*ph\n", (int)sizeof(intel_dp->dpcd), > > - intel_dp->dpcd); > > - > > - return intel_dp->dpcd[DP_DPCD_REV] != 0; > > -} > > - > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) > > { > > u8 dprx = 0; > > @@ -4563,7 +4507,7 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp) > > /* this function is meant to be called only once */ > > drm_WARN_ON(&dev_priv->drm, intel_dp->dpcd[DP_DPCD_REV] != 0); > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd) != 0) > > return false; > > > > drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, > > @@ -4650,7 +4594,7 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp) > > { > > int ret; > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd)) > > return false; > > > > /* > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.h > > b/drivers/gpu/drm/i915/display/intel_dp.h > > index b901ab850cbd9..0a3af3410d52e 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.h > > +++ b/drivers/gpu/drm/i915/display/intel_dp.h > > @@ -99,7 +99,6 @@ bool intel_dp_source_supports_hbr3(struct intel_dp > > *intel_dp); > > bool > > intel_dp_get_link_status(struct intel_dp *intel_dp, u8 *link_status); > > > > -bool intel_dp_read_dpcd(struct intel_dp *intel_dp); > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp); > > int intel_dp_link_required(int pixel_clock, int bpp); > > int intel_dp_max_data_rate(int max_link_clock, int max_lanes); > > diff --git a/drivers/gpu/drm/i915/display/intel_lspcon.c > > b/drivers/gpu/drm/i915/display/intel_lspcon.c > > index b781bf4696443..dc1b35559afdf 100644 > > --- a/drivers/gpu/drm/i915/display/intel_lspcon.c > > +++ b/drivers/gpu/drm/i915/display/intel_lspcon.c > > @@ -571,7 +571,7 @@ bool lspcon_init(struct intel_digital_port *dig_port) > > return false; > > } > > > > - if (!intel_dp_read_dpcd(dp)) { > > + if (drm_dp_read_dpcd_caps(&dp->aux, dp->dpcd) != 0) { > > DRM_ERROR("LSPCON DPCD read failed\n"); > > return false; > > } > > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h > > index 0c141fc81aaa8..11649e93e5bb6 100644 > > --- a/include/drm/drm_dp_helper.h > > +++ b/include/drm/drm_dp_helper.h > > @@ -1607,6 +1607,9 @@ static inline ssize_t drm_dp_dpcd_writeb(struct > > drm_dp_aux *aux, > > return drm_dp_dpcd_write(aux, offset, &value, 1); > > } > > > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]); > > + > > int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, > > u8 status[DP_LINK_STATUS_SIZE]); > > > > -- > > 2.26.2 > > > > _______________________________________________ > > dri-devel mailing list > > dri-devel@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Sincerely, Lyude Paul (she/her) Software Engineer at Red Hat _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 899B0C433E1 for ; Thu, 20 Aug 2020 16:07:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56AF4208C7 for ; Thu, 20 Aug 2020 16:07:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="irl+0Ae3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 56AF4208C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E6BC6E979; Thu, 20 Aug 2020 16:07:55 +0000 (UTC) X-Greylist: delayed 150927 seconds by postgrey-1.36 at gabe; Thu, 20 Aug 2020 16:07:53 UTC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id B209A6E39C for ; Thu, 20 Aug 2020 16:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597939672; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qJ60GW5I7GDTJbBQqWE3EmOtkI5NSzudyRlj9VDcORI=; b=irl+0Ae3e5VdH4D1MZqpxoKQjO1g5wfIdYglLn6YWlPRsTTZc1YLuggEdM8Z35VDBfdGVj 5UtoOrKc0Bc7I0LU96Vt9MtBRR1LSMUYJyk3nHDFEF2nPqrENnBEUzutvIseY5QfqYZStB /HWQlNbfxyq0NClxAZSWwJgE3KEURo0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-CirmtaZPPkmvvHG3EBmLVA-1; Thu, 20 Aug 2020 12:07:48 -0400 X-MC-Unique: CirmtaZPPkmvvHG3EBmLVA-1 Received: by mail-qk1-f197.google.com with SMTP id x18so1512622qkb.16 for ; Thu, 20 Aug 2020 09:07:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:organization:user-agent:mime-version :content-transfer-encoding; bh=qJ60GW5I7GDTJbBQqWE3EmOtkI5NSzudyRlj9VDcORI=; b=TCp97BgreUcJse3tnod5G9qZsYfvNz9Njg7eJavWraXXA5ZNzk0L+nbKFhWEBe3gVT qbfS0ItV9dW25NTsyIlkNCT8yDN6nx/mK+fLfXA5/M8A0JKoF7KWMHWkeTHICgJDcjfi Hg2C/h9+MU3XCtoJxunkCMq/rb1fLOLblvyopvuSELNCHmEcANNzahxFgQvgZhZ/1dGN 5yhyV3c4C6maaRmTklIQrxp7cSy1ig9Q9UY0ql3L3UfJjDJQgQkDzlRs+H+WHd03bUTx 7zYowfCPPkBoIKzjuChFEkwZTDRWEP164MxMdnQlqiex6/U6TqoJfz6fNiPphhJj8NrQ O+7w== X-Gm-Message-State: AOAM531bmiggD3QlPFdzCt/mWGaPIycVB4OHnvohHrGUSvc6JW3l1Wpg mt2A2sIedlnujyUmZIFq3vUt7wp8u5whgdeANqTl/A9v1XhvZkJwj62Ig0kOF1ralm/hpcBBrky AGzcJBoDpM/GSMjvpYfUmU2HEqE9v X-Received: by 2002:a05:6214:d46:: with SMTP id 6mr3708542qvr.240.1597939667696; Thu, 20 Aug 2020 09:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO40CKZE46leN+nONQ3YVFgRPEtJrYd3+OHw2O70kDbwE+E1FviIHr4Wm0L0PBTbbLO5psCw== X-Received: by 2002:a05:6214:d46:: with SMTP id 6mr3708503qvr.240.1597939667342; Thu, 20 Aug 2020 09:07:47 -0700 (PDT) Received: from Whitewolf.lyude.net (pool-108-49-102-102.bstnma.fios.verizon.net. [108.49.102.102]) by smtp.gmail.com with ESMTPSA id t8sm2599572qke.7.2020.08.20.09.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 09:07:46 -0700 (PDT) Message-ID: From: Lyude Paul To: Sean Paul Date: Thu, 20 Aug 2020 12:07:44 -0400 In-Reply-To: <20200819152914.GE46474@art_vandelay> References: <20200811200457.134743-1-lyude@redhat.com> <20200811200457.134743-20-lyude@redhat.com> <20200819152914.GE46474@art_vandelay> Organization: Red Hat User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lyude@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Subject: Re: [Intel-gfx] [RFC 19/20] drm/i915/dp: Extract drm_dp_read_dpcd_caps() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: lyude@redhat.com Cc: David Airlie , nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Lucas De Marchi , open list , dri-devel@lists.freedesktop.org, Thomas Zimmermann , Wambui Karuga Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Wed, 2020-08-19 at 11:29 -0400, Sean Paul wrote: > On Tue, Aug 11, 2020 at 04:04:56PM -0400, Lyude Paul wrote: > > Since DP 1.3, it's been possible for DP receivers to specify an > > additional set of DPCD capabilities, which can take precedence over the > > capabilities reported at DP_DPCD_REV. > > > > Basically any device supporting DP is going to need to read these in an > > identical manner, in particular nouveau, so let's go ahead and just move > > this code out of i915 into a shared DRM DP helper that we can use in > > other drivers. > > > > Signed-off-by: Lyude Paul > > --- > > drivers/gpu/drm/drm_dp_helper.c | 76 +++++++++++++++++++++ > > drivers/gpu/drm/i915/display/intel_dp.c | 60 +--------------- > > drivers/gpu/drm/i915/display/intel_dp.h | 1 - > > drivers/gpu/drm/i915/display/intel_lspcon.c | 2 +- > > include/drm/drm_dp_helper.h | 3 + > > 5 files changed, 82 insertions(+), 60 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_dp_helper.c > > b/drivers/gpu/drm/drm_dp_helper.c > > index 0ff2959c8f8e8..f9445915c6c26 100644 > > --- a/drivers/gpu/drm/drm_dp_helper.c > > +++ b/drivers/gpu/drm/drm_dp_helper.c > > @@ -423,6 +423,82 @@ bool drm_dp_send_real_edid_checksum(struct drm_dp_aux > > *aux, > > } > > EXPORT_SYMBOL(drm_dp_send_real_edid_checksum); > > > > +static int drm_dp_read_extended_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + u8 dpcd_ext[6]; > > + int ret; > > + > > + /* > > + * Prior to DP1.3 the bit represented by > > + * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > + * If it is set DP_DPCD_REV at 0000h could be at a value less than > > + * the true capability of the panel. The only way to check is to > > + * then compare 0000h and 2200h. > > + */ > > + if (!(dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > + DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > + return 0; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DP13_DPCD_REV, &dpcd_ext, > > + sizeof(dpcd_ext)); > > + if (ret != sizeof(dpcd_ext)) > > + return -EIO; > > + > > + if (dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > + DRM_DEBUG_KMS("%s: Extended DPCD rev less than base DPCD rev (%d > > > %d)\n", > > + aux->name, dpcd[DP_DPCD_REV], > > + dpcd_ext[DP_DPCD_REV]); > > Might be a good opportunity to convert all of these to drm_dbg_dp()? > > > + return 0; > > + } > > + > > + if (!memcmp(dpcd, dpcd_ext, sizeof(dpcd_ext))) > > + return 0; > > + > > + DRM_DEBUG_KMS("%s: Base DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + memcpy(dpcd, dpcd_ext, sizeof(dpcd_ext)); > > + > > + return 0; > > +} > > + > > +/** > > + * drm_dp_read_dpcd_caps() - read DPCD caps and extended DPCD caps if > > + * available > > + * @aux: DisplayPort AUX channel > > + * @dpcd: Buffer to store the resulting DPCD in > > + * > > + * Attempts to read the base DPCD caps for @aux. Additionally, this > > function > > + * checks for and reads the extended DPRX caps (%DP_DP13_DPCD_REV) if > > + * present. > > + * > > + * Returns: %0 if the DPCD was read successfully, negative error code > > + * otherwise. > > + */ > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]) > > +{ > > + int ret; > > + > > + ret = drm_dp_dpcd_read(aux, DP_DPCD_REV, dpcd, DP_RECEIVER_CAP_SIZE); > > + if (ret != DP_RECEIVER_CAP_SIZE || dpcd[DP_DPCD_REV] == 0) > > + return -EIO; > > + > > + ret = drm_dp_read_extended_dpcd_caps(aux, dpcd); > > + if (ret < 0) > > + return ret; > > I wonder if we should just go with the "regular" dpcd caps we just read in > this > case? FWIW - we generally want to just abort on failed DPCD reads since if a device doesn't implement a feature like this, it'll usually read all zeroes. Failed DPCD reads are almost always just the result of something suddenly being disconnected (excluding some cases I've seen on MST, but I think those more have to do with us sending incorrect dpcd read/write requests...) > > Regardless of my nits, > > Reviewed-by: Sean Paul > > > + > > + DRM_DEBUG_KMS("%s: DPCD: %*ph\n", > > + aux->name, DP_RECEIVER_CAP_SIZE, dpcd); > > + > > + if (dpcd[DP_DPCD_REV] == 0) > > + ret = -EIO; > > + > > + return ret; > > +} > > +EXPORT_SYMBOL(drm_dp_read_dpcd_caps); > > + > > /** > > * drm_dp_downstream_read_info() - read DPCD downstream port info if > > available > > * @aux: DisplayPort AUX channel > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c > > b/drivers/gpu/drm/i915/display/intel_dp.c > > index e343965a483df..230aa0360dc61 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.c > > +++ b/drivers/gpu/drm/i915/display/intel_dp.c > > @@ -4449,62 +4449,6 @@ intel_dp_link_down(struct intel_encoder *encoder, > > } > > } > > > > -static void > > -intel_dp_extended_receiver_capabilities(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - u8 dpcd_ext[6]; > > - > > - /* > > - * Prior to DP1.3 the bit represented by > > - * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved. > > - * if it is set DP_DPCD_REV at 0000h could be at a value less than > > - * the true capability of the panel. The only way to check is to > > - * then compare 0000h and 2200h. > > - */ > > - if (!(intel_dp->dpcd[DP_TRAINING_AUX_RD_INTERVAL] & > > - DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT)) > > - return; > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, DP_DP13_DPCD_REV, > > - &dpcd_ext, sizeof(dpcd_ext)) != sizeof(dpcd_ext)) { > > - drm_err(&i915->drm, > > - "DPCD failed read at extended capabilities\n"); > > - return; > > - } > > - > > - if (intel_dp->dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) { > > - drm_dbg_kms(&i915->drm, > > - "DPCD extended DPCD rev less than base DPCD rev\n"); > > - return; > > - } > > - > > - if (!memcmp(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext))) > > - return; > > - > > - drm_dbg_kms(&i915->drm, "Base DPCD: %*ph\n", > > - (int)sizeof(intel_dp->dpcd), intel_dp->dpcd); > > - > > - memcpy(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext)); > > -} > > - > > -bool > > -intel_dp_read_dpcd(struct intel_dp *intel_dp) > > -{ > > - struct drm_i915_private *i915 = dp_to_i915(intel_dp); > > - > > - if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd, > > - sizeof(intel_dp->dpcd)) < 0) > > - return false; /* aux transfer failed */ > > - > > - intel_dp_extended_receiver_capabilities(intel_dp); > > - > > - drm_dbg_kms(&i915->drm, "DPCD: %*ph\n", (int)sizeof(intel_dp->dpcd), > > - intel_dp->dpcd); > > - > > - return intel_dp->dpcd[DP_DPCD_REV] != 0; > > -} > > - > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) > > { > > u8 dprx = 0; > > @@ -4563,7 +4507,7 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp) > > /* this function is meant to be called only once */ > > drm_WARN_ON(&dev_priv->drm, intel_dp->dpcd[DP_DPCD_REV] != 0); > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd) != 0) > > return false; > > > > drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, > > @@ -4650,7 +4594,7 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp) > > { > > int ret; > > > > - if (!intel_dp_read_dpcd(intel_dp)) > > + if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd)) > > return false; > > > > /* > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.h > > b/drivers/gpu/drm/i915/display/intel_dp.h > > index b901ab850cbd9..0a3af3410d52e 100644 > > --- a/drivers/gpu/drm/i915/display/intel_dp.h > > +++ b/drivers/gpu/drm/i915/display/intel_dp.h > > @@ -99,7 +99,6 @@ bool intel_dp_source_supports_hbr3(struct intel_dp > > *intel_dp); > > bool > > intel_dp_get_link_status(struct intel_dp *intel_dp, u8 *link_status); > > > > -bool intel_dp_read_dpcd(struct intel_dp *intel_dp); > > bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp); > > int intel_dp_link_required(int pixel_clock, int bpp); > > int intel_dp_max_data_rate(int max_link_clock, int max_lanes); > > diff --git a/drivers/gpu/drm/i915/display/intel_lspcon.c > > b/drivers/gpu/drm/i915/display/intel_lspcon.c > > index b781bf4696443..dc1b35559afdf 100644 > > --- a/drivers/gpu/drm/i915/display/intel_lspcon.c > > +++ b/drivers/gpu/drm/i915/display/intel_lspcon.c > > @@ -571,7 +571,7 @@ bool lspcon_init(struct intel_digital_port *dig_port) > > return false; > > } > > > > - if (!intel_dp_read_dpcd(dp)) { > > + if (drm_dp_read_dpcd_caps(&dp->aux, dp->dpcd) != 0) { > > DRM_ERROR("LSPCON DPCD read failed\n"); > > return false; > > } > > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h > > index 0c141fc81aaa8..11649e93e5bb6 100644 > > --- a/include/drm/drm_dp_helper.h > > +++ b/include/drm/drm_dp_helper.h > > @@ -1607,6 +1607,9 @@ static inline ssize_t drm_dp_dpcd_writeb(struct > > drm_dp_aux *aux, > > return drm_dp_dpcd_write(aux, offset, &value, 1); > > } > > > > +int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux, > > + u8 dpcd[DP_RECEIVER_CAP_SIZE]); > > + > > int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux, > > u8 status[DP_LINK_STATUS_SIZE]); > > > > -- > > 2.26.2 > > > > _______________________________________________ > > dri-devel mailing list > > dri-devel@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Sincerely, Lyude Paul (she/her) Software Engineer at Red Hat _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx