From patchwork Thu Nov 6 19:07:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 652 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 03D7034E755 for ; Thu, 6 Nov 2025 19:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762456094; cv=none; b=p+3EbhqqF/1fREY70EHc/jWXNIXM57O1o4RAKlabD6AG5CasGjhTuex7FcOVpzajUq40f3je4f4CJYOC1Mklcq05fTl/laBnmtnYkrZ3ZLl394R26HS+UnQrzSxJOX8YYOohDVuoqWxzJyAmJnVsq+3BTnVUuK0HlmYwQKTubhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762456094; c=relaxed/simple; bh=O33tzwOMuFzj5je6ou6p3VavVz9CrO7CoaSioDAC7d0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FNZ897sPctj4jqncbwgDBnirOfuNcjyQCUj1yb0TOcZPL8s5ivw5p8ll+8Ol2SsEfL1UV5GF9KhN3WcXPKwhbSbI5yARM2Z5F34ZKVUqqriNoApgwl3ryQ/fX3UNX2RiOv4jW/sRcuNtjhKp9yi2An5Y6RVw0hbJuwpLsgwyQJY= 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=XBY9Y6++; arc=none smtp.client-ip=209.85.218.41 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="XBY9Y6++" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-b7273abc418so16702066b.1 for ; Thu, 06 Nov 2025 11:08:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1762456090; x=1763060890; 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=UC7o/Lm5tysqi1r/QiS1zppEaC6hX+4dTRHAwtxyreU=; b=XBY9Y6++lHb4Ppsat3qds/xRBVERM+I8Iam/6NAwz1LDvYVYXfAhGykPHa82EzFa5q ygkTihY68KMyxfmcLv9voPHx8LwgdgaORwS/Fzr9a1gbvxP2eu+1/EX8ab14qf0PY5ZY +3JqrGXSREdydZ84rV322mywAVEzjCh3IASTsnjHSuxg5Pk88CK+dIQfYmfOdE9X28uu mSLDRgXd4HqbGSabh/xadBRht289VoGFqDF1U8Gx034wNvj0Y0Yz2VQ8t5Pwa9n+miUv hC9DK/4L9QT8RhLjZoAMU1+MYase+ePfFa/2kZzTPlx1J4AHO7QTGQDDvGb1LV22KqdL nsmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762456090; x=1763060890; 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=UC7o/Lm5tysqi1r/QiS1zppEaC6hX+4dTRHAwtxyreU=; b=KRUlZWTAuRRVcpFNWsBWmS7WrNbrLU5CFvJDkDmNe5XD6wIQEp495IrDx7vxW/+bEo mUZ+1gW7GrQsiX1pw5NPkcSPWIfppfXr13JZOWCCJ+8Y+dFXbAkeeKhpqVhKFl4+zuBs nACckYFSKvKwHlW1V7KhdREwU/bDFfeQL2cx6iS+GSNIhI7zIwlEYZSCuCx4qUKB/Pj1 Ob/5oR2htx1tgdoGWThkPXUsKSAn3Qf8Gf3eNzvohfQDvO57jr7CHh/Q0ASh/dEEJR2R eLaxN6CaLbzZcsWf9Y0TztWD4KyCHxRC3x6qS9oAQC+J8KwQMxRRe1Kmtij5oUln1S+C ssnA== X-Forwarded-Encrypted: i=1; AJvYcCW25QhAybBT4cCe42vT6kN76n58tpoo8WhiYxyosce+DIv/kK1Zcs8WFp26mf343OR2S0bCXAC+oH5+Lw==@lists.linux.dev X-Gm-Message-State: AOJu0YyWUYnFQlFmeTKdxBbPPmlukANu57xDzBvn4reeIX66dcynG5lo xgyapkH3mTqNy64XhuLPoHYvjHLaPrzuBa4WW9TV5WhytIAV/IO6JnXQc7qmZ1bttGE= X-Gm-Gg: ASbGnct5CjzVof2qArwFhsQ74ASCi1y2TzLXFzdLp4S4f9NAbflbOEBYcVlKJ9cT61q ITkEdtwjFmoY8dXXkQIKnNbgxn6zIkrhDXfja0WZkJUydwxS89eiP7Q6xGIjUzPcEmAdHLh20DP qySVhwPXpX4NRaP0NBCf8/vRRax9tMIqYo+gWDIjzhayIrqOLcksOyCQvGIrVa3uC18A2Z7KEn5 m8cJDzHtabCbm8gDxk2TxPabpEGTt8qA9MBf0qwcBoNPBGAFR8F2z+jOxwip9P4d03x4rGbtI0s G6bcEzGk8BWsgLCeVgJmCb0wOKYsTQRubHAeQAdO/TxpLKLbsxm4r/ULX5t1fdC5WQ3rql1FvAG HT6CW2MeCgYfltOgleNtC5trm+nnLsyGdjT69QJ8wVKgQqQa2wRUC7+XBZGAuTNk/j7phP2+Qs/ IasJtRh5oyh9RMxDM9pB9wjlkXNy4= X-Google-Smtp-Source: AGHT+IH4u0visRizZo2d3rYJCHF6DFTUhu6yOMzJeaTU5w4S3ldRzQL6ooWntCfuedndsflKkieXmA== X-Received: by 2002:a17:907:1c01:b0:b6a:382a:1516 with SMTP id a640c23a62f3a-b72c0d52bf6mr17951666b.5.1762456090174; Thu, 06 Nov 2025 11:08:10 -0800 (PST) Received: from [127.0.1.1] ([178.197.219.123]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72bfa2510esm26739566b.72.2025.11.06.11.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 11:08:09 -0800 (PST) From: Krzysztof Kozlowski Date: Thu, 06 Nov 2025 20:07:08 +0100 Subject: [PATCH 01/13] 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: <20251106-b4-of-match-matchine-data-v1-1-d780ea1780c2@linaro.org> References: <20251106-b4-of-match-matchine-data-v1-0-d780ea1780c2@linaro.org> In-Reply-To: <20251106-b4-of-match-matchine-data-v1-0-d780ea1780c2@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=3693; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=O33tzwOMuFzj5je6ou6p3VavVz9CrO7CoaSioDAC7d0=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBpDPIJjcqOIsRPKVtKm1n48qkLFTKl0iTeRLJML O0ig2VobJSJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCaQzyCQAKCRDBN2bmhouD 16upD/0ZvU0jba0Dx7VybPnYT2mGXlqQGiRbmnASkWMky8rIi6Sp8RSTLDhpclz2LmVx2skpz9v 0r6fP/FAMEFShI7EOBA+3f2t6USlukHdnPVV5xooagFdsMEyVL6+LwbgBm0f51zE6VM/tdjSDvM lCVONspGTJH1L/sttThdI2ovYpqbZYDhIgRcyLipKeWZte4YfeSzgnv3mOsaZFNFZKNt1Y8jn5q lAnXZCY6RgamYZplen5FS1RlMwii6jqAT4iMGTBELYGQSe4sB6WFyV4jpa5ZvU6gKmSjgMPVrAa u+SHuX1DmTVBI+iqI+OHv0K5lS2PQIvbQOYEI1nVsSxLPQj3FZDmO2dIMvtZq/A1xk150fjigAN IXNMW7CdnSTV4oloo/K2XJKpIqVWKtkjEMeQz8y3d7z+i9ufMn+SvYkCQwhDWwr26gkfEIHxLRd GcS4JoNkEeK1NPDp1DJsvbGwTtKcfxX5AE/GI11SX5KqZmCOcZfsh3AxXQsI6q/r/HIoj0pWGr/ aawjN/1UsCSiEDwm7T0yFZgc40VQp5wqrhuIZclvDr0ycCO6vt4LEFykBHRt5xA27HSsxSWVT35 oEZvCZypUBmVZTUMfjm3P2tcxblSskFAWSXealeXfawQqRW3usvcwdwSGsJ4wz1RkezOFDOI08h PmOXu5HeggsWkCw== 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. 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;