Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp3086615lqt; Tue, 23 Apr 2024 09:55:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUgKpmJGKWXJCFvdBjgzpkfDmH/HkYryrqF/3CES0hrbWa75IzGPkX7JmLRmqbXwU/KeinSzy/AloOyJwqHd6YgMejgxk6smUaGae24jQ== X-Google-Smtp-Source: AGHT+IFAPETxM0P7xVjR1hKd7u6DrpGIv2UyiV6q7C1862M6fyQ+lLNoRBiV/B6GwDcYqzPz7l5a X-Received: by 2002:a17:902:6f08:b0:1e7:b7b7:7b44 with SMTP id w8-20020a1709026f0800b001e7b7b77b44mr45673plk.15.1713891315469; Tue, 23 Apr 2024 09:55:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713891315; cv=pass; d=google.com; s=arc-20160816; b=JSgSdZbeT4CCcXw1itl1ehtlSwgU4mG9eAtYd7MJ09OPQ9nYBPLcfqgKGDq+WsHKnI XNq1BesDNVF7IxKGBjM20pr8VK/jPCOidw4Xpgc8c1iwtuXpqvdzfTPk2jK5Oa5k6j7t ZMtqkl9BdbZDfyJbZ7c3nwUQmhZDcczwBxJqZ1k6OFLq7rzCHSXbIZL0Ge8VLQF556zb m5eQ+LtLiVGfJ/vy7/upOCWw1N+xTExR411mOil77iiX+GcIUiw2n+FDq7HC6HjB5cr8 PCrv4Ftr+tX3mQI6fmreiedI5pfeOrTUxXRKHnR+ISeCNZ+15UxyYmNR8IfK8jo4Or0F oysw== 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=NpkgavKs1CpvzyYWvr/KmghPS7XN/sSEyN3iKhZAgIE=; fh=ytwc1ooIR7N6GWgEGui7NT8E370tKVnk4Jx4Qn0uVwI=; b=Jj9A1YAlfY7hBOf6xEcY08dDkYXXb9gcN74eN6DaUewMivt9ISSGtg4GzaEqj4Bxnw h3VtUXmf83BWsCVkKBKsMBGIK1iYeE5T+om49RimpFWnKVGVXVOQCGJtNszJlJGIOHEn nEJgL2eYQSNqiGGJCYZP5wAghZhC3wqpN8Me7CJM0aX2HiYAq5wssa+kcYNA+4qgQK2U XmQ+rTzEATsnusz7FZeBxjmbppSi/PSwETwlToUSDgRqJ9TDhdL46tgds981WI98fl2m xDvUTMW8oVAxYYiQ6CQ2z1P80D0+WTlkujOo/ztyJkClinLmIWcfHtHXk/YR/3dmJDy8 7IAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nxKPOILR; 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-155596-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155596-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q15-20020a170902f78f00b001e0af97a0bbsi10206461pln.433.2024.04.23.09.55.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 09:55:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155596-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nxKPOILR; 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-155596-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155596-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 72F4D287AC6 for ; Tue, 23 Apr 2024 16:49:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B7D513D60B; Tue, 23 Apr 2024 16:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nxKPOILR" Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 8A79F13D50F for ; Tue, 23 Apr 2024 16:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713890977; cv=none; b=nj6e0USK7r92cJNaP/4cm96Tm94/QOBT9FeU7uzezI12n747vaHKxyly1bOi5HokNLIvoZpwkB7LgnxGOHAokJoI854Q4M1zjTIpMl6Rnv7uY6pFG9pINrqfik8JycCgSyypVQJdr2jNzHmLS5DRz5Vxmsqu7P78vqcqVySQpX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713890977; c=relaxed/simple; bh=JK9cWcqCBSN2kQEjqq9Rxdq9K2hbeoRzvX/uzKL2aGg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ULLDusCyEFq34lr1ULziqNnPTsbelz/ivGRlpHgSBmN44+NcngGvGV/K3i4W9Vsa9e4OP9dyvZy+D4Hd9Thi2zZeMKN7E/53+Afs6LKhCSiVA5L7Z1HlQ8wFf39lUn6PyFVoyh7Aua+xm5WlTa8tGA4huWcDhyLIXU4HsQqAj+g= 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=nxKPOILR; arc=none smtp.client-ip=95.215.58.186 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=1713890972; 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=NpkgavKs1CpvzyYWvr/KmghPS7XN/sSEyN3iKhZAgIE=; b=nxKPOILREIiSPcSzvRoxxF7C3v1XYuoI7y/JLtnsFqYWO1VZyiR2Ag3rmvwEgZLbM//UoP TM/mbZDshJBwF9wBvF8KmECASF+XwmF6PrYWWs3jQ6GPDcLFT5iwxHisR7ESWNRTSVAA7o 0SMfw5XgcfT5O23of6TrhSgzXD+ek+g= Date: Wed, 24 Apr 2024 00:49:18 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2] software node: Implement device_get_match_data fwnode callback To: Andy Shevchenko Cc: dri-devel@lists.freedesktop.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" References: <20240422164658.217037-1-sui.jingfeng@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sui Jingfeng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Hi, Thanks a for you reviewing my patch. On 2024/4/23 21:28, Andy Shevchenko wrote: > On Tue, Apr 23, 2024 at 12:46:58AM +0800, Sui Jingfeng wrote: >> Because the software node backend of the fwnode API framework lacks an >> implementation for the .device_get_match_data function callback. This >> makes it difficult to use(and/or test) a few drivers that originates > Missing space before opening parenthesis. OK, will be fixed at the next version. >> from DT world on the non-DT platform. >> >> Implement the .device_get_match_data fwnode callback, device drivers or >> platform setup codes are expected to provide a string property, named as >> "compatible", the value of this software node string property is used to >> match against the compatible entries in the of_device_id table. > Yep and again, how is this related? If you want to test a driver originating > from DT, you would probably want to have a DT (overlay) to be provided. There are a few reasons, please fixed me if I'm wrong. DT (overlay) can be possible solution, but DT (overlay) still depend on DT. For example, one of my x86 computer with Ubuntu 22.04 Linux/x86 6.5.0-28-generic kernel configuration do not has the DT enabled. This means that the default kernel configuration is decided by the downstream OS distribution. It is not decided by usual programmers. This means that out-of-tree device drivers can never utilize DT or DT overlay, right? I means that Linux kernel is intended to be used by both in-tree drivers and out-of-tree drivers. Out-of-tree device drivers don't have a chance to alter kernel config, they can only managed to get their source code compiled against the Linux kernel the host in-using. Some out-of-tree device drivers using DKMS to get their source code compiled, with the kernel configuration already *fixed*. So they don't have a opportunity to use DT overlay. Relying on DT overlay is *still* *DT* *dependent*, and I not seeing matured solution get merged into upstream kernel yet. However, software node has *already* been merged into Linux kernel. It can be used on both DT systems and non-DT systems. Software node has the least requirement, it is *handy* for interact with drivers who only need a small set properties. In short, I still think my patch maybe useful for some peoples. DT overlay support on X86 is not matured yet, need some extra work. For out-of-tree kernel module on downstream kernel. Select DT and DT overlay on X86 is out-of-control. And I don't want to restrict the freedom of developers. >> This also helps to keep the three backends of the fwnode API aligned as >> much as possible, which is a fundamential step to make device driver >> OF-independent truely possible. >> >> Fixes: ffb42e64561e ("drm/tiny/repaper: Make driver OF-independent") >> Fixes: 5703d6ae9573 ("drm/tiny/st7735r: Make driver OF-independent") > How is it a fix? Because the drm/tiny/repaper driver and drm/tiny/st7735r driver requires extra device properties. We can not make them OF-independent simply by switching to device_get_match_data(). As the device_get_match_data() is a *no-op* on non-DT environment. Hence, before my patch is applied, the two "Make driver OF-independent" patch have no effect. Using device_get_match_data() itself is exactly *same* with using of_device_get_match_data() as long as the .device_get_match_data hook is not implemented. See my analysis below: When the .device_get_match_data hook is not implemented: 1) On DT systems, device_get_match_data() just redirect to of_fwnode_device_get_match_data(), which is just a wrapper of of_device_get_match_data(). 2) On Non-DT system, device_get_match_data() has *ZERO* effect, it just return NULL. Therefore, device_get_match_data() adds *ZERO* benefits to the mentioned drivers if the .device_get_match_data is not implemented. Only when the .device_get_match_data hook get implemented, device_get_match_data() can redirect tosoftware_node_get_match_data() function in this patch. Therefore, the two driver has a way to get a proper driver match data on non-DT environment. Beside, the users of those two driver can provide additional software node property at platform setup code. as long as at somewhere before the driver is probed. So the two driver really became OF-independent after applied my patch. >> Closes: https://lore.kernel.org/lkml/20230223203713.hcse3mkbq3m6sogb@skbuf/ > Yes, and then Reported-by, which is missing here. > >> Cc: Andy Shevchenko >> Cc: Daniel Scally >> Cc: Heikki Krogerus >> Cc: Sakari Ailus >> Cc: Greg Kroah-Hartman >> Cc: "Rafael J. Wysocki" > Please, move these after the cutter '---' line (note you may have that line in > your local repo). > > ... > OK, thanks a lot for teaching me. >> +static const void * >> +software_node_get_match_data(const struct fwnode_handle *fwnode, >> + const struct device *dev) >> +{ >> + struct swnode *swnode = to_swnode(fwnode); >> + const struct of_device_id *matches = dev->driver->of_match_table; >> + const char *val = NULL; >> + int ret; >> + ret = property_entry_read_string_array(swnode->node->properties, >> + "compatible", &val, 1); > And if there are more than one compatible provided? Nope, I think this is kind of limitation of the software node, platform setup code generally could provide a compatible property. No duplicate name is allowed. But we the best explanation would be platform setup code should provide the "best" or "default" compatible property. >> + if (ret < 0 || !val) >> + return NULL; >> + while (matches && matches->compatible[0]) { > First part of the conditional is invariant to the loop. Can be simply Right, thanks. > matches = dev->driver->of_match_table; > if (!matches) > return NULL; > > while (...) > >> + if (!strcmp(matches->compatible, val)) >> + return matches->data; >> + >> + matches++; >> + } >> + >> + return NULL; >> +} -- Best regards, Sui