Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3214803lqo; Wed, 15 May 2024 03:18:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV+O2l6WMjlY5AXxlKSIdylR6yh3mbUg/IU30G8PSXEElj/fVETAGntYgD+MXp+HLRT+palfd8uWoFDphlgaMFz6bFuugG/SsJXHQRnLw== X-Google-Smtp-Source: AGHT+IEmnMfYZBpoa+KM0q72s0L1BgzSOXpw37AoSCUGTeORhAPHC7C8Qdz6WlGtS/a9/dd64M+q X-Received: by 2002:a17:902:ed8c:b0:1e2:a467:1b6b with SMTP id d9443c01a7336-1ef43d2e38bmr157193835ad.16.1715768295021; Wed, 15 May 2024 03:18:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715768295; cv=pass; d=google.com; s=arc-20160816; b=ka9XvkPJQIlsOW5tWs2uPnXfYQVLquh7qrwIrpqT5s9IAGeHfsIDlDButzyJFugQel uhQfYlY3m6H0PkMUn5h1vMsjDnqoJ92smOE3jkzEyqX0tF3CJ50b1QWbf4yVQDsULVAO iA6YXk8NLrkWDyLl2AJoND75J1XPtjh9J1Wqx/UsDSvxbhdQbgm0QE0eMOc6n00NWNR0 WReYM4HKKyp/0q0UAUYQsy6+E6Yerbj6+K/iZc8hE2mMXkVAoKoZXwQMYLSnq424DOnE 5rohL/gpdoqtssonpydZZCQqVHuBdFtiKRDM9jy2qhNbCvNWJiy9V5HjhTSFBrom1uJS bs+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=l4bPo+Qa7F8LO4Fc7UnSEAOeiesDvsWpSbzqmxMaNJ8=; fh=5OmD8AMxAEf/qWOZY68e+K2EdRDalcQdaCnlSGhdm4w=; b=mJJtasXVD5Zvp9pc88TboxhT8LaEtmCJEIRcmm3PY32wP3azNREn97C4vi9fjXh50g 5myZ7VBfWjMsU8qyIgfExga3+1ePyCuJg0VtE8VJrXof+Z4UP/T6jb4uCf8vzjrLGUJn 4EHBq0e9+3VjjxVkQgTaVBy2T8FwXY9943hAXWjS+HuqZFeZlc5wlkIei+kgreB/fEbf JGdpycuOIMPCXz5hdYgNiq4JcRuWliF3xmuDVKt4JMisA49Z7YkFQ+LtfprstfgjJMF7 iC1eTXmfF/vEOBHblsTc6bRjkulOh+QGudPaAKlTxwBgQ6BF5Btlk/0nJW8a5HNL+fk5 awCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ln2EYHxh; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-179755-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179755-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0b9cfb5bsi137425155ad.46.2024.05.15.03.18.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 03:18:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179755-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ln2EYHxh; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-179755-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179755-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3E6D228313B for ; Wed, 15 May 2024 10:18:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52CED5BAC1; Wed, 15 May 2024 10:18:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Ln2EYHxh" Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 434B457CB5 for ; Wed, 15 May 2024 10:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715768286; cv=none; b=Uac7q70NdJ+RtR9Ez3+tXmgR2QoedVa38IVWvyfDkIiMmcwb3n+MBgidXtB1RBfhDksHjCPxZg3/r3Zk1508W5kLzeVxYUsOn2E2MbP+OZ5ndu6R6mpkXkHOes5W3fN8PE2sXOfkEZBE7qiRBNbsXDudP4OXYJNwtKDCe0jVk0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715768286; c=relaxed/simple; bh=HZmSbXyU3hpvHdoAzRPMgQxxbjAHbble9Zvbis0GGM4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aMkGTiOAe0nJb8D8vd8cW7OFio49uf96MemwNWLeIDJyDq2jF3pHJwcLeYNJN39gxrijfAxYiIUwBZu62r/IE7MTOWcs4KUSzzwCa7t4JDMUcL42tpIn3PUnMXO78+HvDVi5gG1nf9qwi7kq28x462MYqGS05Z13LNqpozsmzR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Ln2EYHxh; arc=none smtp.client-ip=95.215.58.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715768281; h=from:from: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=l4bPo+Qa7F8LO4Fc7UnSEAOeiesDvsWpSbzqmxMaNJ8=; b=Ln2EYHxhwFGpKwfS/XLNBsne9LO+m3A/HUSpX7uERE6RNJb3V677vVfWXfrPYTqe/EY4p/ FuTIL18AKvEfPUoDiFODaJAg1U2iCBJXupbLIfWuy7bM8o9t4uzdALugjtu58AEn/Xpqbv +oya1XNUuClJTAKwGXIpUhvawy2OcYo= Date: Wed, 15 May 2024 18:17:52 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/2] drm/bridge: Support finding bridge with struct device To: Jani Nikula , Neil Armstrong , Maxime Ripard , Dmitry Baryshkov Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20240514154045.309925-1-sui.jingfeng@linux.dev> <20240514154045.309925-2-sui.jingfeng@linux.dev> <87v83fct2e.fsf@intel.com> Content-Language: en-US, en-AU X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sui Jingfeng In-Reply-To: <87v83fct2e.fsf@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Hi, On 5/15/24 17:39, Jani Nikula wrote: > On Tue, 14 May 2024, Sui Jingfeng wrote: >> The pointer of 'struct device' can also be used as a key to search drm >> bridge instance from the global bridge list, traditionally, fwnode and >> 'OF' based APIs requires the system has decent fwnode/OF Graph support. >> While the drm_find_bridge_by_dev() function introduced in this series >> don't has such a restriction. It only require you has a pointer to the >> backing device. Hence, it may suitable for some small and/or limited >> display subsystems. >> >> Also add the drm_bridge_add_with_dev() as a helper, which automatically >> set the .of_node field of drm_bridge instances if you call it. But it >> suitable for simple bridge drivers which one device backing one drm_bridge >> instance. >> >> Signed-off-by: Sui Jingfeng >> --- >> drivers/gpu/drm/drm_bridge.c | 39 ++++++++++++++++++++++++++++++++++++ >> include/drm/drm_bridge.h | 5 +++++ >> 2 files changed, 44 insertions(+) >> >> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c >> index 584d109330ab..1928d9d0dd3c 100644 >> --- a/drivers/gpu/drm/drm_bridge.c >> +++ b/drivers/gpu/drm/drm_bridge.c >> @@ -213,6 +213,23 @@ void drm_bridge_add(struct drm_bridge *bridge) >> } >> EXPORT_SYMBOL(drm_bridge_add); >> >> +/** >> + * drm_bridge_add_with_dev - add the given bridge to the global bridge list >> + * >> + * @bridge: bridge control structure >> + * @dev: pointer to the kernel device that this bridge is backed. >> + */ >> +void drm_bridge_add_with_dev(struct drm_bridge *bridge, struct device *dev) >> +{ >> + if (dev) { >> + bridge->kdev = dev; >> + bridge->of_node = dev->of_node; >> + } >> + >> + drm_bridge_add(bridge); >> +} >> +EXPORT_SYMBOL_GPL(drm_bridge_add_with_dev); > > I don't actually have an opinion on whether the dev parameter is useful > or not. > > But please don't add a drm_bridge_add_with_dev() and then convert more > than half the drm_bridge_add() users to that. Please just add a struct > device *dev parameter to drm_bridge_add(), and pass NULL if it's not > relevant. > To be honest, previously, I'm just do it exactly same as the way you told me here. But I'm exhausted and finally give up. Because this is again need me to modify *all* callers of drm_bridge_add(), not only those bridges in drm/bridge/, but also bridge instances in various KMS drivers. However, their some exceptions just don't fit! For example, the imx/imx8qxp-pixel-combiner.c just don't fit our simple model. Our helper function assume that one device backing one drm_bridge instance (1 to 1). Yet, that driver backing two or more bridges with one platform device (1 to 2, 1 to 3, ..., ). Hence, the imx/imx8qxp-pixel-combiner.c just can't use drm_bridge_add_with_dev(). The aux_hpd_bridge.c is also bad, it store the of_node of struct device at the .platform_data member of the struct device. > BR, > Jani. > > >> + >> static void drm_bridge_remove_void(void *bridge) >> { >> drm_bridge_remove(bridge); >> @@ -1334,6 +1351,27 @@ void drm_bridge_hpd_notify(struct drm_bridge *bridge, >> } >> EXPORT_SYMBOL_GPL(drm_bridge_hpd_notify); >> >> +struct drm_bridge *drm_find_bridge_by_dev(struct device *kdev) >> +{ >> + struct drm_bridge *bridge; >> + >> + if (!kdev) >> + return NULL; >> + >> + mutex_lock(&bridge_lock); >> + >> + list_for_each_entry(bridge, &bridge_list, list) { >> + if (bridge->kdev == kdev) { >> + mutex_unlock(&bridge_lock); >> + return bridge; >> + } >> + } >> + >> + mutex_unlock(&bridge_lock); >> + return NULL; >> +} >> +EXPORT_SYMBOL_GPL(drm_find_bridge_by_dev); >> + >> #ifdef CONFIG_OF >> /** >> * of_drm_find_bridge - find the bridge corresponding to the device node in >> @@ -1361,6 +1399,7 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np) >> return NULL; >> } >> EXPORT_SYMBOL(of_drm_find_bridge); >> + >> #endif >> >> MODULE_AUTHOR("Ajay Kumar "); >> diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h >> index 4baca0d9107b..70d8393bbd9c 100644 >> --- a/include/drm/drm_bridge.h >> +++ b/include/drm/drm_bridge.h >> @@ -715,6 +715,8 @@ struct drm_bridge { >> struct drm_private_obj base; >> /** @dev: DRM device this bridge belongs to */ >> struct drm_device *dev; >> + /** @kdev: pointer to the kernel device backing this bridge */ >> + struct device *kdev; >> /** @encoder: encoder to which this bridge is connected */ >> struct drm_encoder *encoder; >> /** @chain_node: used to form a bridge chain */ >> @@ -782,12 +784,15 @@ drm_priv_to_bridge(struct drm_private_obj *priv) >> } >> >> void drm_bridge_add(struct drm_bridge *bridge); >> +void drm_bridge_add_with_dev(struct drm_bridge *bridge, struct device *dev); >> int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge); >> void drm_bridge_remove(struct drm_bridge *bridge); >> int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, >> struct drm_bridge *previous, >> enum drm_bridge_attach_flags flags); >> >> +struct drm_bridge *drm_find_bridge_by_dev(struct device *kdev); >> + >> #ifdef CONFIG_OF >> struct drm_bridge *of_drm_find_bridge(struct device_node *np); >> #else > -- Best regards Sui