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=-7.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 B5176C433ED for ; Tue, 4 May 2021 08:00:29 +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 6047C6139A for ; Tue, 4 May 2021 08:00:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6047C6139A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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 DEB496EAA5; Tue, 4 May 2021 08:00:27 +0000 (UTC) Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8F3FC6EAA1; Tue, 4 May 2021 08:00:26 +0000 (UTC) Received: by mail-pf1-x431.google.com with SMTP id q2so6608331pfh.13; Tue, 04 May 2021 01:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=1ylC9ShWY/I9eI56AJKrNab7WRbCq2Eeo1b2uR5U/0o=; b=WoDRZi3ibdURrXMHIzg8bPhqKgmZnc7R+BPnaQm//YcSrK+vXcQBnYGWm3Cl8rd7k6 plmBjRCM0gilvagiyAHy5f+7pxs9VPdz5i5H95duq+7zOJ6wv1xsBqKhFcKn6KR1rR8k aySPD0qbgRtnPyzebxipAGW9EEiV8xdCCQQ6WFIyMO6GAxxPFE9WR8KiMTCU6/B3nNJ8 r7xooVURDoKpNk1Co9GxI19ElUXIfkFOcO+U3jkwV6TL3auLtEHuJ6mClAEIZxnOL1Vf mg6r7aHzB+Vt3E8YwX0+xd+WPJzuv0yuDr82cZmNtHeO9VzrmDUXD1+E6pafnHNb1UBS o5UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=1ylC9ShWY/I9eI56AJKrNab7WRbCq2Eeo1b2uR5U/0o=; b=beFYTXzitL1reTkh3ljRH6XdFoe6zKY7AIl9YXxIJQvsRr1AmEl2jvgzvXqFeXFvvx CgN38MvNqYtKUNGFZhIIAcP+lNYmmD/QESChxbCWo4JF9U1mWZtM4pvz10ODkzAZdlsy ZBqGcUpHw6fk8VDSg8VEgNVphchrtvp0BIGEzUUl0erS6WPxXFjrMsNXvl+95qAHpkLc 4q2/yJOoIYGChWhejLsGBAf/eQO8xcw4P+zlw2IfjyRdSQAswa62/Y3XyXO+PI09rjwZ jFEOFYuTGUIV3L9Iy1KcNSjhSQJaXk6fY6Fxj5DthJZuQ0/6eU02HlRcXP4wLdcariIS LJMg== X-Gm-Message-State: AOAM531WrcQ1D7pLcTMwjReve1HJTo8SPcqB5CDT3tLBRoBgx3VW47Jv NHRWZUQTXfPdqitnNRikWTQc4sTdXLsY2imrCTk= X-Google-Smtp-Source: ABdhPJyuUN5rgPtYKhds3x5z8XTw2huk9MRxeC4zY+lzV4WprRJbjikwSEY6sPJskffQkfLXmFhft8Vq98Q3sGBdwKg= X-Received: by 2002:a62:528e:0:b029:1f5:c5ee:a487 with SMTP id g136-20020a62528e0000b02901f5c5eea487mr22574807pfb.7.1620115226202; Tue, 04 May 2021 01:00:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90b:d81:0:0:0:0 with HTTP; Tue, 4 May 2021 01:00:25 -0700 (PDT) In-Reply-To: <20210503154647.142551-4-hdegoede@redhat.com> References: <20210503154647.142551-1-hdegoede@redhat.com> <20210503154647.142551-4-hdegoede@redhat.com> From: Andy Shevchenko Date: Tue, 4 May 2021 11:00:25 +0300 Message-ID: Subject: Re: [PATCH 3/9] drm/connector: Add drm_connector_find_by_fwnode() function (v2) To: Hans de Goede 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: , Cc: "dri-devel@lists.freedesktop.org" , Heikki Krogerus , Thomas Zimmermann , David Airlie , Greg Kroah-Hartman , intel-gfx , "platform-driver-x86@vger.kernel.org" , "linux-usb@vger.kernel.org" , Rodrigo Vivi , Guenter Roeck Content-Type: multipart/mixed; boundary="===============1484547767==" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" --===============1484547767== Content-Type: multipart/alternative; boundary="0000000000008d93ff05c17c7856" --0000000000008d93ff05c17c7856 Content-Type: text/plain; charset="UTF-8" On Monday, May 3, 2021, Hans de Goede wrote: > Add a function to find a connector based on a fwnode. > > This will be used by the new drm_connector_oob_hotplug_event() > function which is added by the next patch in this patch-set. > > Changes in v2: > - Complete rewrite to use a global connector list in drm_connector.c > rather then using a class-dev-iter in drm_sysfs.c > > Signed-off-by: Hans de Goede > --- > drivers/gpu/drm/drm_connector.c | 50 +++++++++++++++++++++++++++++ > drivers/gpu/drm/drm_crtc_internal.h | 1 + > include/drm/drm_connector.h | 8 +++++ > 3 files changed, 59 insertions(+) > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_ > connector.c > index 87c68563e6c3..ef759d6add81 100644 > --- a/drivers/gpu/drm/drm_connector.c > +++ b/drivers/gpu/drm/drm_connector.c > @@ -66,6 +66,14 @@ > * support can instead use e.g. drm_helper_hpd_irq_event(). > */ > > +/* > + * Global connector list for drm_connector_find_by_fwnode(). > + * Note drm_connector_[un]register() first take connector->lock and then > + * take the connector_list_lock. > + */ > +static DEFINE_MUTEX(connector_list_lock); > +static LIST_HEAD(connector_list); > + > struct drm_conn_prop_enum_list { > int type; > const char *name; > @@ -267,6 +275,7 @@ int drm_connector_init(struct drm_device *dev, > goto out_put_type_id; > } > > + INIT_LIST_HEAD(&connector->global_connector_list_entry); > INIT_LIST_HEAD(&connector->probed_modes); > INIT_LIST_HEAD(&connector->modes); > mutex_init(&connector->mutex); > @@ -540,6 +549,9 @@ int drm_connector_register(struct drm_connector > *connector) > drm_privacy_screen_register_notifier(connector->privacy_ > screen, > &connector->privacy_screen_ > notifier); > > + mutex_lock(&connector_list_lock); > + list_add_tail(&connector->global_connector_list_entry, > &connector_list); > + mutex_unlock(&connector_list_lock); > goto unlock; > > err_debugfs: > @@ -568,6 +580,10 @@ void drm_connector_unregister(struct drm_connector > *connector) > return; > } > > + mutex_lock(&connector_list_lock); > + list_del_init(&connector->global_connector_list_entry); > + mutex_unlock(&connector_list_lock); > + > if (connector->privacy_screen) > drm_privacy_screen_unregister_notifier( > connector->privacy_screen, > @@ -2676,6 +2692,40 @@ int drm_mode_getconnector(struct drm_device *dev, > void *data, > return ret; > } > > +/** > + * drm_connector_find_by_fwnode - Find a connector based on the > associated fwnode > + * @fwnode: fwnode for which to find the matching drm_connector > + * > + * This functions looks up a drm_connector based on its associated > fwnode. When > + * a connector is found a reference to the connector is returned. The > caller must > + * call drm_connector_put() to release this reference when it is done > with the > + * connector. > + * > + * Returns: A reference to the found connector or an ERR_PTR(). > + */ > +struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle > *fwnode) > +{ > + struct drm_connector *connector, *found = ERR_PTR(-ENODEV); > + > + if (!fwnode) > + return ERR_PTR(-ENODEV); > + > + mutex_lock(&connector_list_lock); > + > + list_for_each_entry(connector, &connector_list, > global_connector_list_entry) { > + if (connector->fwnode == fwnode || > + (connector->fwnode && connector->fwnode->secondary == > fwnode)) { > + drm_connector_get(connector); > + found = connector; > + break; > + } > + } > + > + mutex_unlock(&connector_list_lock); > + > + return found; If I am not mistaken you can replace this with return list_entry_is_head(); call and remove additional Boolean variable. > +} > + > > /** > * DOC: Tile group > diff --git a/drivers/gpu/drm/drm_crtc_internal.h > b/drivers/gpu/drm/drm_crtc_internal.h > index 54d4cf1233e9..6e28fc00a740 100644 > --- a/drivers/gpu/drm/drm_crtc_internal.h > +++ b/drivers/gpu/drm/drm_crtc_internal.h > @@ -185,6 +185,7 @@ int drm_connector_set_obj_prop(struct drm_mode_object > *obj, > int drm_connector_create_standard_properties(struct drm_device *dev); > const char *drm_get_connector_force_name(enum drm_connector_force force); > void drm_connector_free_work_fn(struct work_struct *work); > +struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle > *fwnode); > > /* IOCTL */ > int drm_connector_property_set_ioctl(struct drm_device *dev, > diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h > index d20bfd7576ed..ae377354e48e 100644 > --- a/include/drm/drm_connector.h > +++ b/include/drm/drm_connector.h > @@ -1267,6 +1267,14 @@ struct drm_connector { > */ > struct list_head head; > > + /** > + * @global_connector_list_entry: > + * > + * Connector entry in the global connector-list, used by > + * drm_connector_find_by_fwnode(). > + */ > + struct list_head global_connector_list_entry; > + > /** @base: base KMS object */ > struct drm_mode_object base; > > -- > 2.31.1 > > -- With Best Regards, Andy Shevchenko --0000000000008d93ff05c17c7856 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Monday, May 3, 2021, Hans de Goede <hdegoede@redhat.com> wrote:
Add a function to find a connector based on a fwnode.

This will be used by the new drm_connector_oob_hotplug_event()
function which is added by the next patch in this patch-set.

Changes in v2:
- Complete rewrite to use a global connector list in drm_connector.c
=C2=A0 rather then using a class-dev-iter in drm_sysfs.c

Signed-off-by: Hans de Goede <hde= goede@redhat.com>
---
=C2=A0drivers/gpu/drm/drm_connector.c=C2=A0 =C2=A0 =C2=A0| 50 ++++++++= +++++++++++++++++++++
=C2=A0drivers/gpu/drm/drm_crtc_internal.h |=C2=A0 1 +
=C2=A0include/drm/drm_connector.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 = 8 +++++
=C2=A03 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 87c68563e6c3..ef759d6add81 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -66,6 +66,14 @@
=C2=A0 * support can instead use e.g. drm_helper_hpd_irq_event().
=C2=A0 */

+/*
+ * Global connector list for drm_connector_find_by_fwnode().
+ * Note drm_connector_[un]register() first take connector->lock and the= n
+ * take the connector_list_lock.
+ */
+static DEFINE_MUTEX(connector_list_lock);
+static LIST_HEAD(connector_list);
+
=C2=A0struct drm_conn_prop_enum_list {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int type;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 const char *name;
@@ -267,6 +275,7 @@ int drm_connector_init(struct drm_device *dev,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto out_put_type_i= d;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

+=C2=A0 =C2=A0 =C2=A0 =C2=A0INIT_LIST_HEAD(&connector->global_c= onnector_list_entry);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 INIT_LIST_HEAD(&connector->probed_m= odes);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 INIT_LIST_HEAD(&connector->modes);<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 mutex_init(&connector->mutex);
@@ -540,6 +549,9 @@ int drm_connector_register(struct drm_connector *connec= tor)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 drm_privacy_screen_= register_notifier(connector->privacy_screen,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0&connector->privacy_screen_notifier);

+=C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_lock(&connector_list_lock);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0list_add_tail(&connector->global_co= nnector_list_entry, &connector_list);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_unlock(&connector_list_lock); =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto unlock;

=C2=A0err_debugfs:
@@ -568,6 +580,10 @@ void drm_connector_unregister(struct drm_connecto= r *connector)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

+=C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_lock(&connector_list_lock);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0list_del_init(&connector->global_co= nnector_list_entry);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_unlock(&connector_list_lock); +
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (connector->privacy_screen)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 drm_privacy_screen_= unregister_notifier(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 connecto= r->privacy_screen,
@@ -2676,6 +2692,40 @@ int drm_mode_getconnector(struct drm_device *dev, vo= id *data,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ret;
=C2=A0}

+/**
+ * drm_connector_find_by_fwnode - Find a connector based on the associated= fwnode
+ * @fwnode: fwnode for which to find the matching drm_connector
+ *
+ * This functions looks up a drm_connector based on its associated fwnode.= When
+ * a connector is found a reference to the connector is returned. The call= er must
+ * call drm_connector_put() to release this reference when it is done with= the
+ * connector.
+ *
+ * Returns: A reference to the found connector or an ERR_PTR().
+ */
+struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_hand= le *fwnode)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct drm_connector *connector, *found =3D ERR= _PTR(-ENODEV);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!fwnode)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return ERR_PTR(-ENO= DEV);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_lock(&connector_list_lock);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0list_for_each_entry(connector, &connector_l= ist, global_connector_list_entry) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (connector->f= wnode =3D=3D fwnode ||
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(conn= ector->fwnode && connector->fwnode->secondary =3D=3D fwnod= e)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0drm_connector_get(connector);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0found =3D connector;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0break;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0mutex_unlock(&connector_list_lock); +
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return found;

<= br>
If I am not mistaken you can replace this with

=
return list_entry_is_head();

call and r= emove additional Boolean variable.
=C2=A0
+}
+

=C2=A0/**
=C2=A0 * DOC: Tile group
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm= _crtc_internal.h
index 54d4cf1233e9..6e28fc00a740 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -185,6 +185,7 @@ int drm_connector_set_obj_prop(struct drm_mode_obj= ect *obj,
=C2=A0int drm_connector_create_standard_properties(struct drm_device *= dev);
=C2=A0const char *drm_get_connector_force_name(enum drm_connector_forc= e force);
=C2=A0void drm_connector_free_work_fn(struct work_struct *work);
+struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_hand= le *fwnode);

=C2=A0/* IOCTL */
=C2=A0int drm_connector_property_set_ioctl(struct drm_device *dev,
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index d20bfd7576ed..ae377354e48e 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -1267,6 +1267,14 @@ struct drm_connector {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct list_head head;

+=C2=A0 =C2=A0 =C2=A0 =C2=A0/**
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * @global_connector_list_entry:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 *
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * Connector entry in the global connector-list= , used by
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * drm_connector_find_by_fwnode().
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct list_head global_connector_list_entry; +
=C2=A0 =C2=A0 =C2=A0 =C2=A0 /** @base: base KMS object */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct drm_mode_object base;
=C2=A0
--
2.31.1



--
With Best Regards,
Andy Shevchenko

--0000000000008d93ff05c17c7856-- --===============1484547767== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel --===============1484547767==--