From patchwork Mon Aug 7 14:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 13344299 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A65D2C04FE0 for ; Mon, 7 Aug 2023 14:04:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232142AbjHGOEO (ORCPT ); Mon, 7 Aug 2023 10:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235196AbjHGODv (ORCPT ); Mon, 7 Aug 2023 10:03:51 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BCA63ABE; Mon, 7 Aug 2023 07:02:58 -0700 (PDT) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 377E2mg4094662; Mon, 7 Aug 2023 09:02:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1691416968; bh=AgbQDfGfdzuWvDzkkcxAemP/8XRwP7vbhe7oAQMiZfk=; h=From:To:CC:Subject:Date; b=uKXIq4ucw8Lh6f3LZJFTPnsxiyzZytCKCwnnavv7NfYWvnBCIQRFJvCNuC/NnZ+7K j5EMG7suKLnsofsl77hdF0rhu1KdcBWnlXDlhXqXX4dBtO1jnAqUZX80vimxCp3mic AEFZdsp35SAnkHJQX+ic+G/CNHY2SY2+x9eemH/s= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 377E2m1X052987 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 7 Aug 2023 09:02:48 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 7 Aug 2023 09:02:48 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 7 Aug 2023 09:02:48 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 377E2mLB130367; Mon, 7 Aug 2023 09:02:48 -0500 From: Nishanth Menon To: Mathieu Poirier , Bjorn Andersson CC: , , , Nishanth Menon , Robert Nelson , Kevin Cahalan Subject: [PATCH] remoteproc: core: Honor device tree /alias entries when assigning IDs Date: Mon, 7 Aug 2023 09:02:47 -0500 Message-ID: <20230807140247.956255-1-nm@ti.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org On many platforms, such as Beaglebone-AI64 with many remote processors, firmware configurations provided by the distributions can vary substantially depending on the distribution build's functionality and the specific remote cores enabled in that variant. Ensuring consistent udev rules mapping remoteproc nodes to constant remote proc device indices across distributions (yocto, ubuntu, debian and it's variants, ...) on a board basis can be challenging due to the various functions of these distributions. Varied device node paths create challenges for applications that operate on remote processors, especially in minimal embedded systems(initrd like) that may not have udev-like capabilities and rely on a more straightforward bare filesystem. This challenge is similar to that faced by I2C, RTC or the GPIO subsystems. Assign remoteproc device IDs based on device tree /aliases entries if present, falling back to the existing numbering scheme if there is no /aliases entry (which includes when the system isn't booted using DT) or a numbering conflict. If the alias node is not present, the driver behaves as before. Cc: Robert Nelson Reported-by: Kevin Cahalan Signed-off-by: Nishanth Menon Reviewed-by: Hari Nagalla --- Test log: Beaglebone-AI64 https://gist.github.com/nmenon/365cf80d6c0685dd9be7c2cb18d7c937 (along with a test change to force the sequence of initialization) The report occurred on Beagle discord channel - so I am not sure how to share the logs of the report. drivers/remoteproc/remoteproc_core.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 695cce218e8c..a12f3d37b8de 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -2417,6 +2418,25 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) return 0; } +static int rproc_device_get_id(struct device *dev) +{ + int of_id = -1, id = -1; + + if (dev->of_node) + of_id = of_alias_get_id(dev->of_node, "remoteproc"); + + if (of_id >= 0) { + id = ida_simple_get(&rproc_dev_index, of_id, of_id + 1, GFP_KERNEL); + if (id < 0) + dev_warn(dev, "/aliases ID %d not available\n", of_id); + } + + if (id < 0) + id = ida_alloc(&rproc_dev_index, GFP_KERNEL); + + return id; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -2476,7 +2496,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, goto put_device; /* Assign a unique device index and name */ - rproc->index = ida_alloc(&rproc_dev_index, GFP_KERNEL); + rproc->index = rproc_device_get_id(dev); if (rproc->index < 0) { dev_err(dev, "ida_alloc failed: %d\n", rproc->index); goto put_device;