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 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A64C5AC7C for ; Fri, 7 Aug 2026 06:49:04 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AE7B140664; Fri, 7 Aug 2026 08:48:59 +0200 (CEST) Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by mails.dpdk.org (Postfix) with ESMTP id 0E909402D1 for ; Fri, 7 Aug 2026 08:48:58 +0200 (CEST) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id DAF6C1A0137; Fri, 7 Aug 2026 08:48:57 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A2F9F1A012E; Fri, 7 Aug 2026 08:48:57 +0200 (CEST) Received: from lsv03457.swis.in-blr01.nxp.com (lsv03457.swis.in-blr01.nxp.com [92.120.147.250]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id CD02E18000B5; Fri, 7 Aug 2026 14:48:56 +0800 (+08) From: Gagandeep Singh To: dev@dpdk.org Cc: hemant.agrawal@nxp.com, Gagandeep Singh Subject: [PATCH v2 1/5] bus/platform: match device by devicetree compatible string Date: Fri, 7 Aug 2026 12:18:49 +0530 Message-Id: <20260807064853.1138187-2-g.singh@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260807064853.1138187-1-g.singh@nxp.com> References: <20260806084245.561305-1-g.singh@nxp.com> <20260807064853.1138187-1-g.singh@nxp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The platform bus currently matches a DPDK driver to a device only by comparing the kernel driver name bound to the device against the DPDK driver name. Devices bound to the generic vfio-platform kernel driver all report the same driver name, which carries no device identity, so a specific DPDK driver cannot claim its device this way. Add of_device_is_compatible(), which reads the device-tree "compatible" strings exposed under the device's of_node in sysfs and compares them against a requested string. platform_bus_match() now falls back to matching the DPDK driver name or its alias against these compatible strings, letting a driver bind to a device identified by its device-tree "compatible" value. Signed-off-by: Gagandeep Singh --- drivers/bus/platform/bus_platform_driver.h | 3 +- drivers/bus/platform/platform.c | 67 +++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/drivers/bus/platform/bus_platform_driver.h b/drivers/bus/platform/bus_platform_driver.h index e4dcbacf5e..8eabe4a1fd 100644 --- a/drivers/bus/platform/bus_platform_driver.h +++ b/drivers/bus/platform/bus_platform_driver.h @@ -121,7 +121,8 @@ static const char *pdrvinit_ ## nm ## _alias; \ RTE_INIT(pdrvinitfn_ ##nm) \ { \ (platform_drv).driver.name = RTE_STR(nm); \ - (platform_drv).driver.alias = pdrvinit_ ## nm ## _alias; \ + if (pdrvinit_ ## nm ## _alias != NULL) \ + (platform_drv).driver.alias = pdrvinit_ ## nm ## _alias; \ rte_platform_register(&(platform_drv)); \ } \ RTE_PMD_EXPORT_NAME(nm) diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c index 90d865a8df..78ca896526 100644 --- a/drivers/bus/platform/platform.c +++ b/drivers/bus/platform/platform.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(C) 2023 Marvell. + * Copyright 2026 NXP */ #include @@ -230,6 +231,57 @@ of_resource_name(const char *dev_name, int index) return NULL; } +/* + * Check whether any of the NUL-separated device-tree "compatible" strings + * exposed by the platform device matches the given string. A single pair of + * enclosing double quotes is stripped from the requested compatible so both + * quoted and unquoted spellings match the raw device-tree value. + */ +static bool +of_device_is_compatible(const char *dev_name, const char *compat) +{ + char path[PATH_MAX], buf[BUFSIZ] = { }; + char want[BUFSIZ]; + const char *s; + size_t c_len; + FILE *f; + size_t len; + + if (compat == NULL) + return false; + + /* Copy the requested compatible, dropping a pair of enclosing quotes. */ + c_len = strlen(compat); + if (c_len >= 2 && compat[0] == '"' && compat[c_len - 1] == '"') { + c_len -= 2; + if (c_len >= sizeof(want)) + c_len = sizeof(want) - 1; + memcpy(want, compat + 1, c_len); + want[c_len] = '\0'; + } else { + rte_strscpy(want, compat, sizeof(want)); + } + + snprintf(path, sizeof(path), PLATFORM_BUS_DEVICES_PATH "/%s/of_node/compatible", dev_name); + f = fopen(path, "r"); + if (f == NULL) + return false; + + /* Read the raw contents, preserving embedded NULL separators. */ + len = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + if (len == 0) + return false; + + /* Bound the walk by the read length: some kernels omit the trailing NULL. */ + for (s = buf; s < buf + len; s += strlen(s) + 1) { + if (!strcmp(s, want)) + return true; + } + + return false; +} + static int device_map_resources(struct rte_platform_device *pdev, unsigned int num) { @@ -386,8 +438,21 @@ platform_bus_match(const struct rte_driver *drv, const struct rte_device *dev) } /* match by device name */ - if (!strcmp(pdev->name, pdrv->driver.name)) + if (!strcmp(pdev->name, pdrv->driver.name)) { match = true; + goto out; + } + + /* + * The generic vfio-platform kernel driver name carries no device + * identity, so fall back to matching the device-tree "compatible" + * strings against the DPDK driver name or alias. + */ + if (of_device_is_compatible(pdev->name, pdrv->driver.name) || + of_device_is_compatible(pdev->name, pdrv->driver.alias)) { + match = true; + goto out; + } out: free(kdrv); -- 2.25.1