From patchwork Wed Nov 12 10:28:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 627 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 907A8303A1C for ; Wed, 12 Nov 2025 10:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762943352; cv=none; b=XWi8NgaM2scUlUpcJxv44U8n26o67+xNQuPgeWzcC0z67UhdtVBIUAJ8JpTzRUC1lxG66S5pkzKmh/guUzCxqZqIKnLEA+JskBDQxiGPH6O7ZKoeVQunhICwlnsSvDh43cgjpHY/HmFTDZKzjrnXLo8t8qSD4EkIZdHlXIHf5+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762943352; c=relaxed/simple; bh=97pN+hZe6aOdQXzqXH/jzMv6/WG6YtpXykn+P6/wWxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WeAx3ZmaCwsiBREkTiTO8aeMU4idJnhLAzVDC3Qg20gWePJ3KBaxVaO7yGCTmeo0wHs13Eq5onZLOe7Hj7/qySrbBpqCF886bAGI2SzojFwXcLaxJRR1svFGiGa/yMfPFLRkHqEelP+RIjB/1fu4tgKYeQEDemF9uS5fuhhBM/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nFIPVlTy; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nFIPVlTy" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-42b2a64d425so83821f8f.0 for ; Wed, 12 Nov 2025 02:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1762943347; x=1763548147; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Xtn1agn38vYYRSDmrX8xmfCfXiGeMgWG3lL/9kBn0bY=; b=nFIPVlTyAju0XRUGhGVMm7R6FmoTLC5UFikSTfbGgYKVTIGEGVmrh8+rowpXklDb7q w1Al1QSYCZpoH7P1UVVt5imHbr8omDsKWk+WtOG4W8+pqEwFR7VBu7z45YrjgWcvJv9Z KCzYbwdxyQZj+rzAD8ai+W46Be+1YRojhFRKYv1+Sobypz90b4cCxysc8mnortB9KnD1 LRXiBlFwlCW4v4cFtarH/nbbtEHjWewRnlEn77Fm1N1Tq+GJRwMlyc9leP9Qw6MnsEo1 G86rKlc5tTa1R8uaTmopyfXa2+5UyKpC6+utkO11UGf/5QoK2hjua7MAmNx7DVXM5hCQ vqPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762943347; x=1763548147; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Xtn1agn38vYYRSDmrX8xmfCfXiGeMgWG3lL/9kBn0bY=; b=Sw/JhcNzwzPR2AF+2XVKPu2iWhHRzTGY8xnMw9lNPfj7rHKlOsY8fq7VMJpGOQjHgx PG/Nzbm1IuAYL1bglQMUtQbjCcVTjwUDRpaZidYXz7qcRACcVAdUziomod6fvANrJlMz erzbedOvq2XNDnXeEtPuYqYGD/Pknl1e4lgUKRl+gxKf2xfOMNJAaiPJpebCYTR6P3K5 2d74FSDFvvCWMgPxKFQvEiUbdniOvmucJz8e7kkVCfM53Byx8tz/IOaT4afOHkrePMY8 RIWD/8uvQ/eWrSKz0gdZ2ceO1LcStHvdQpWw4fYFm9Fjh2S5UwSpZF18zB6qOA+jrNpa /NQg== X-Forwarded-Encrypted: i=1; AJvYcCWZwlLEVmDkgpFqU0tZEnxDSIf6MN5CuLQTpnej0WBe/8VXMtWDMfe+dW4QViN8woiK64injjgAkrDKdA==@lists.linux.dev X-Gm-Message-State: AOJu0YxRCCUc1oqO/X04Bxtq3zy1HMtpXu1eAFtETLFM2fO5xyiJgVgT FHjwqCCGzNncgY3MDOEb9AJvInqEPExAY4eHN13J2eYn/AoyV4AnX7rBqg49dMNs0xM= X-Gm-Gg: ASbGnctlDI/8b5GshVMKgl+1g3b244xGbhssOWf8D7WSOo4/Kc9rMGHLYdpTWMfCyvZ CbAaYUWKpX+Zqdeh/GhwUujH5/4QY900euoIy6w4yPeNsp+4bbkYWCNR3TMHAtWnOn6ETjtp7+5 N/Kk2P/4Yu95n4afuznZw9TXAspIJbQNNopTowqebMnXsefJmIpYMaKYgWSAEYs1BY5labccCkH 9Q3bLTs6SKEhGwNF8lorC0jt4IFzSnnQjqlhItOz+uiv4cJkk6l5RDuc3fL4qYsXkYrAeb/yWRM AL7b/k160vVdCBh8PgP7+c3K6HMNt5ZFriT/YZBxh1sWAB/Ri7afMIF1utFXJtv0gkS7PCwKDxw l2UOL3XYRoRg3X1rqoq/bGTcv5xswfWdk1G8dcVAZmdDOVA5Dx+/Khyn6F/kGpAuDJXIEORnPDw 2gDRWcPLjKOKWQU8IG X-Google-Smtp-Source: AGHT+IEqw4rhZRyDy+yPmdGyXuh1FmIzLY034EYTwmwGfWZRi5DR0a/TjWaTQc0ZSjDYk6R/6C4iqQ== X-Received: by 2002:a05:6000:2087:b0:42b:2da3:ac30 with SMTP id ffacd0b85a97d-42b4bb875c4mr1198295f8f.2.1762943346620; Wed, 12 Nov 2025 02:29:06 -0800 (PST) Received: from [127.0.1.1] ([178.197.219.123]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b32ecf522sm22020001f8f.45.2025.11.12.02.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 02:29:06 -0800 (PST) From: Krzysztof Kozlowski Date: Wed, 12 Nov 2025 11:28:46 +0100 Subject: [PATCH v2 01/11] of: Add wrappers to match root node with OF device ID tables Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20251112-b4-of-match-matchine-data-v2-1-d46b72003fd6@linaro.org> References: <20251112-b4-of-match-matchine-data-v2-0-d46b72003fd6@linaro.org> In-Reply-To: <20251112-b4-of-match-matchine-data-v2-0-d46b72003fd6@linaro.org> To: Rob Herring , Saravana Kannan , "Rafael J. Wysocki" , Viresh Kumar , Matthias Brugger , AngeloGioacchino Del Regno , Yangtao Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Lorenzo Pieralisi , Daniel Lezcano , Bjorn Andersson , Konrad Dybcio , Thomas Gleixner , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Maximilian Luz , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Daniel Lezcano , Thierry Reding , Jonathan Hunter Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-tegra@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3774; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=97pN+hZe6aOdQXzqXH/jzMv6/WG6YtpXykn+P6/wWxo=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBpFGFkNYeOuoYzpykLoG20VsmMhHx83ITlx4eh3 nQhR2/+8c+JAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCaRRhZAAKCRDBN2bmhouD 1+WoD/0TKoeUAmx+UOxM0JybjWAMODukmdMBn6gauxFIVRlljF/oKwZMabgzYrNN21aWkVxl2Gx YzAxkQ/qwOh0Kdg86awylIZT+BceJmpZHLGj/zlXD7z1Kp2Ib/Kvukk1qf78AAs+4CkVn6XLbMm SfzvNCXZAFS/Wmwt570i9P1qKzGcXPrFmD4MBRBDKcQbzpnZXtKtATET5wD1DdrmwA6VvwTWg8L p0SrRLcNqaiA690mMfLZ7XlwD14yyWMuYn3NzN0WwFvYKWh2yqTxVxjNKzEoCRxn+6Lh6E//R1R UotKfqNNiO5iZadxiAimw/mkju2Kc5uaLsCPVtoLaIALM1ORhiyi23/oZKufSjy2XuBogIcXmzT fUnq0U1+Oeh5KRBAcI4FJ5EDuOL2QM3vVPw5CHBaTVxUvCg72PkhHxk2T41dJ0MliQNhFjNBVIM i0zNFwh00b3UiSNkrkGSas79QDK4rhMiYBsgfZUGYjST+qh/p6kM7ccxpbMz3tirdbvMsZxEufo M7xuNl4R9dMgRs7AKLfaIIsojl8PL6NpZNLEoFVh6RzLDTt1v687levEf1VfBoqiRy85HTPXUJr NsuSFe0RR2EjGM7CjvRbVfguXXSnUnV9PtpU259qszWKt0OBGoXxH4O/Co15e4lndqJuZVDKFX0 WigE1E0XpsiiR1A== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Status: O Several drivers duplicate same code for getting reference to the root node, matching it against 'struct of_device_id' table and getting out the match data from the table entry. There is a of_machine_compatible_match() wrapper but it takes array of strings, which is not suitable for many drivers since they want the driver data associated with each compatible. Add two wrappers, similar to existing of_device_get_match_data(): 1. of_machine_device_match() doing only matching against 'struct of_device_id' and returning bool. 2. of_machine_get_match_data() doing the matching and returning associated driver data for found compatible. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Krzysztof Kozlowski --- All further patches depend on this. --- drivers/of/base.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 7043acd971a0..0b65039ece53 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -434,6 +434,53 @@ bool of_machine_compatible_match(const char *const *compats) } EXPORT_SYMBOL(of_machine_compatible_match); +/** + * of_machine_device_match - Test root of device tree against a of_device_id array + * @matches: NULL terminated array of of_device_id match structures to search in + * + * Returns true if the root node has any of the given compatible values in its + * compatible property. + */ +bool of_machine_device_match(const struct of_device_id *matches) +{ + struct device_node *root; + const struct of_device_id *match = NULL; + + root = of_find_node_by_path("/"); + if (root) { + match = of_match_node(matches, root); + of_node_put(root); + } + + return match != NULL; +} +EXPORT_SYMBOL(of_machine_device_match); + +/** + * of_machine_get_match_data - Tell if root of device tree has a matching of_match structure + * @matches: NULL terminated array of of_device_id match structures to search in + * + * Returns data associated with matched entry or NULL + */ +const void *of_machine_get_match_data(const struct of_device_id *matches) +{ + const struct of_device_id *match; + struct device_node *root; + + root = of_find_node_by_path("/"); + if (!root) + return NULL; + + match = of_match_node(matches, root); + of_node_put(root); + + if (!match) + return NULL; + + return match->data; +} +EXPORT_SYMBOL(of_machine_get_match_data); + static bool __of_device_is_status(const struct device_node *device, const char * const*strings) { diff --git a/include/linux/of.h b/include/linux/of.h index 121a288ca92d..01bb3affcd49 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -407,6 +407,8 @@ extern int of_alias_get_id(const struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); bool of_machine_compatible_match(const char *const *compats); +bool of_machine_device_match(const struct of_device_id *matches); +const void *of_machine_get_match_data(const struct of_device_id *matches); /** * of_machine_is_compatible - Test root of device tree for a given compatible value @@ -855,6 +857,17 @@ static inline bool of_machine_compatible_match(const char *const *compats) return false; } +static inline bool of_machine_device_match(const struct of_device_id *matches) +{ + return false; +} + +static inline const void * +of_machine_get_match_data(const struct of_device_id *matches) +{ + return NULL; +} + static inline bool of_console_check(const struct device_node *dn, const char *name, int index) { return false;