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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF079CAC582 for ; Fri, 12 Sep 2025 07:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YaWj+Wtj/24uprPfhMzjPFyopaRjb/i1iqDzvUVq8gE=; b=NbWThNRf0fcbVs8wOCyiuxras2 q/xYoxWuI69Fxz2woEfwN6Ufvob1OAfpy8kjP6JKjW7iaHSR+HReZxMZCM4G/gShfHUyRZ0/JDQWv 9tnuvqGBg7X0dIGZOK3A19r522oTLWSVB/6HKSHiFtRB7iTC9Amv46E47Ldp4AEfhD89Cap0x2W4z pqW2VJIG7xZbewbOvOfF8o9rP7R1IWeNr5dhlaWHkN02UkU43fHgxpanpliwWgK6TiaEXVxcgzVVn EA9qMdhicB2lFrLk6j/zUhglJBv/GKtxaLjh1ywJ4Jroql1COdwOvHqAhycxlR0clw2ubxEoEESPp OWgvf7GA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uwxnD-00000007Wve-0agu; Fri, 12 Sep 2025 07:01:59 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uwxn9-00000007Ws9-2upM for linux-arm-kernel@lists.infradead.org; Fri, 12 Sep 2025 07:01:57 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3db9641b725so1303315f8f.2 for ; Fri, 12 Sep 2025 00:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757660513; x=1758265313; darn=lists.infradead.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=YaWj+Wtj/24uprPfhMzjPFyopaRjb/i1iqDzvUVq8gE=; b=HtW+rGb6rwiy9Bw0sfDLs+OlG5Tt6gHrk7NEAG+hcVsWwPFqsKI58h/7T8mk2pAxNf 0YweUp1ccf69ULWd8LxDqTzogEluzl/GG0wQFlfaeDKAsCwrLG0vrXWvscioBThdDnGx WW50/BqRKo0E6bub63BrfvNOTCtt0YuLpjbx+wC2itb3iCt31MWG/xEet7CmyN3hh7Zu Kb0x1lkRY63Socms/9b8r6AAoGArb1bF4H1xdMVLZIpt2aFrWpV/Ic9Raqs3odVWe2v1 IQebuD0QCQ04TcQ2psJJniKBcwYTr702b0YE6rrQgBFE9KV/9b9uPYDBMxGTGAp3B5JU uUuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757660513; x=1758265313; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YaWj+Wtj/24uprPfhMzjPFyopaRjb/i1iqDzvUVq8gE=; b=sH8NqCoGcTH/SzcTyYh+NzVmwLq1h3tjYEbRMPDtwfoYGp+8FSw+sUpnPpIW9kEd/u 3LLG1XyQnUav59Ni/N5omjMpKgCOyYs1vOlomef8+uqenIZGeX2qUlYeoQJpQx4ILDGZ f4SwaDP43j0rk5msQToUbo/RpE7Agj7wV/H03pcRz1oilUxha+1DrrFNFF8CXgwUv9Ev wWHfOyDllxWX0MTTfoiiqzVr175roFtnE9SdsipTOFF8iE/TNa2bzX7W+cBO36WfnuGD 9YaLdPnr3AkYD8Z7yCStpFt2Q+KApxiVoI99y0Dgluny5d4EF5SPTMgdDhDDGl9Q5PHe BUrA== X-Forwarded-Encrypted: i=1; AJvYcCUSMI/lOdbhnbViPaKL3sd6V4KogZFUd4BOWwlzKcXft+NS7HaDd+DAqAN4EwgSKVxixPi95tSWocCgSD0GXw5i@lists.infradead.org X-Gm-Message-State: AOJu0YzpBlVRbHNOIl0LGpHM0OxPslkejaVc3bDfmJ7oZ037uM1gsJ5i X8uQBue6Caz6LGd3Z17r00wwEto8Y+F1cYvOMGKt95Auh0roip+0MCBe X-Gm-Gg: ASbGncuEte+NQADRK/VKUWEjHt6Qy2hcG00Lu7ucsfC6HEkBeG/LFsWEzV9fZnrmsqX dSGmsXSAWZrH4hOMa2bgsNF5yk7L+0E46vyo31sxFZF2B683LlQpYXNwB5QoyE51/zEcZuRWkMq wAj3OQ57Tmm0Y/XJLt/WkTL+DBmUD4ZFPrGPZlh8l+oWonkKuFT4nI+EBm/K153hGiy4xuXG9wR mn6cWEmppaakfgtYclHz+MJuQekqDxCTy6k6v7iJcTLTR4vmOfHTfWGNLQ4W2F0vRT10ic8TIEp iJEKeGRKFeUxF+jS1H+idaGeyzEX8XZ0T05unD/qSZ4IDnCvZLAJCpyqd1YBHOr6wpBRR8IvPRT vCvoF2aZrLRiDp82Wr0iRnF3sO7tyVlM= X-Google-Smtp-Source: AGHT+IEOlpS//jr2i1NsakDvG6pEzwnvWvf80bQZB97SnNY1RtBItPkLSDjlNWiHmg/Wj/paRb2sRQ== X-Received: by 2002:a05:6000:2407:b0:3ce:9872:fd3 with SMTP id ffacd0b85a97d-3e765a2dd81mr1373225f8f.34.1757660513106; Fri, 12 Sep 2025 00:01:53 -0700 (PDT) Received: from [192.168.2.177] ([91.116.220.47]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e015775f1sm54638945e9.8.2025.09.12.00.01.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Sep 2025 00:01:52 -0700 (PDT) Message-ID: <6f60bb97-86fc-4cda-a373-a991547bbd77@gmail.com> Date: Fri, 12 Sep 2025 09:01:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] remoteproc: mtk_scp: Construct FW path if firmware-name not present To: AngeloGioacchino Del Regno , linux-remoteproc@vger.kernel.org Cc: arnd@arndb.de, andersson@kernel.org, mathieu.poirier@linaro.org, wenst@chromium.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com References: <20250911140043.190801-1-angelogioacchino.delregno@collabora.com> Content-Language: en-US, ca-ES, es-ES From: Matthias Brugger Autocrypt: addr=matthias.bgg@gmail.com; keydata= xsFNBFP1zgUBEAC21D6hk7//0kOmsUrE3eZ55kjc9DmFPKIz6l4NggqwQjBNRHIMh04BbCMY fL3eT7ZsYV5nur7zctmJ+vbszoOASXUpfq8M+S5hU2w7sBaVk5rpH9yW8CUWz2+ZpQXPJcFa OhLZuSKB1F5JcvLbETRjNzNU7B3TdS2+zkgQQdEyt7Ij2HXGLJ2w+yG2GuR9/iyCJRf10Okq gTh//XESJZ8S6KlOWbLXRE+yfkKDXQx2Jr1XuVvM3zPqH5FMg8reRVFsQ+vI0b+OlyekT/Xe 0Hwvqkev95GG6x7yseJwI+2ydDH6M5O7fPKFW5mzAdDE2g/K9B4e2tYK6/rA7Fq4cqiAw1+u EgO44+eFgv082xtBez5WNkGn18vtw0LW3ESmKh19u6kEGoi0WZwslCNaGFrS4M7OH+aOJeqK fx5dIv2CEbxc6xnHY7dwkcHikTA4QdbdFeUSuj4YhIZ+0QlDVtS1QEXyvZbZky7ur9rHkZvP ZqlUsLJ2n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44ziQUK9diAgfE/8GhXP0JlMwRUBlXNtErJgItR/XAuFwfO6BOI43P19YwEsuyQq+rubW2Wv rWY2Bj2dXDAKUxS4TuLUf2v/b9Rct36ljzbNxeEWt+Yq4IOY6QHnE+w4xVAkfwjT+Vup8sCp +zFJv9fVUpo/bjePOL4PMP1y+PYrp4PmPmRwoklBpy1ep8m8XURv46fGUHUEIsTwPWs2Q87k 7vjYyrcyAOarX2X5pvMQvpAMADGf2Z3wrCsDdG25w2HztweUNd9QEprtJG8GNNzMOD4cQ82T a7eGvPWPeXauWJDLVR9jHtWT9Ot3BQgmApLxACvwvD1a69jaFKov28SPHxUCQ9Y1Y/Ct In-Reply-To: <20250911140043.190801-1-angelogioacchino.delregno@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250912_000155_788343_71DB44D9 X-CRM114-Status: GOOD ( 38.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 11/09/2025 16:00, AngeloGioacchino Del Regno wrote: > After a reply on the mailing lists [1] it emerged that the DT > property "firmware-name" should not be relied on because of > possible issues with firmware versions. > For MediaTek SCP, there has never been any firmware version vs > driver version desync issue but, regardless, the firmwares are > always using the same name and they're always located in a path > with a specific pattern. > > Instead of unconditionally always relying on the firmware-name > devicetree property to get a path to the SCP FW file, drivers > should construct a name based on what firmware it knows and > what hardware it is running on. > > In order to do that, add a `scp_get_default_fw_path()` function > that constructs the path and filename based on two of the infos > that the driver can get: > 1. The compatible string with the highest priority (so, the > first one at index 0); and > 2. The type of SCP HW - single-core or multi-core. > > This means that the default firmware path is generated as: > - Single core SCP: mediatek/(soc_model)/scp.img > for example: mediatek/mt8183/scp.img; > > - Multi core SCP: mediatek/(soc_model)/scp_c(core_number).img > for example: mediatek/mt8188/scp_c0.img for Core 0, and > mediatek/mt8188/scp_c1.img for Core 1. > As we inventing a naming scheme here: if we decide that signle core FW is calle scp_c0.img we can get rid of some code. > Note that the generated firmware path is being used only if the > "firmware-name" devicetree property is not present in the SCP > node or in the SCP Core node(s). > > [1 - Reply regarding firmware-name property] > Link: https://lore.kernel.org/all/7e8718b0-df78-44a6-a102-89529d6abcce@app.fastmail.com/ > Signed-off-by: AngeloGioacchino Del Regno > --- > drivers/remoteproc/mtk_scp.c | 64 ++++++++++++++++++++++++++++++++---- > 1 file changed, 58 insertions(+), 6 deletions(-) > > diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c > index 8206a1766481..80fcb4b053b3 100644 > --- a/drivers/remoteproc/mtk_scp.c > +++ b/drivers/remoteproc/mtk_scp.c > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > > #include "mtk_common.h" > #include "remoteproc_internal.h" > @@ -1093,22 +1094,73 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp) > } > } > > +/** > + * scp_get_default_fw_path() - Get default SCP firmware path > + * @dev: SCP Device > + * @core_id: SCP Core number > + * > + * This function generates a path based on the following format: > + * mediatek/(soc_model)/scp(_cX).img; for multi-core or > + * mediatek/(soc_model)/scp.img for single core SCP HW > + * > + * Return: A devm allocated string containing the full path to > + * a SCP firmware or an error pointer > + */ > +static const char *scp_get_default_fw_path(struct device *dev, int core_id) > +{ > + struct device_node *np = core_id < 0 ? dev->of_node : dev->parent->of_node; > + char scp_fw_file[7] = "scp_cX"; We provide a string that we later overwrite. I'd prefer to have just the reservation without any 'artificial' string in it. > + const char *compatible, *soc; > + int ret; > + > + /* Use only the first compatible string */ > + ret = of_property_read_string_index(np, "compatible", 0, &compatible); > + if (ret) > + return ERR_PTR(ret); > + > + /* If the compatible string's length is implausible bail out early */ > + if (strlen(compatible) < strlen("mediatek,mtXXXX-scp")) Seems like a double check of compatible. Why is dt-bindings for that not enough? > + return ERR_PTR(-EINVAL); > + > + /* If the compatible string starts with "mediatek,mt" assume that it's ok */ > + if (!str_has_prefix(compatible, "mediatek,mt")) Same here. > + return ERR_PTR(-EINVAL); > + > + if (core_id >= 0) > + ret = snprintf(scp_fw_file, ARRAY_SIZE(scp_fw_file), "scp_c%1d", core_id); > + else > + ret = snprintf(scp_fw_file, ARRAY_SIZE(scp_fw_file), "scp"); > + if (ret <= 0) > + return ERR_PTR(ret); > + > + soc = &compatible[strlen("mediatek,")]; > + > + return devm_kasprintf(dev, GFP_KERNEL, "mediatek/%.*s/%s.img", > + (int)strlen("mtXXXX"), soc, scp_fw_file); > +} > + > static struct mtk_scp *scp_rproc_init(struct platform_device *pdev, > struct mtk_scp_of_cluster *scp_cluster, > - const struct mtk_scp_of_data *of_data) > + const struct mtk_scp_of_data *of_data, > + int core_id) > { > struct device *dev = &pdev->dev; > struct device_node *np = dev->of_node; > struct mtk_scp *scp; > struct rproc *rproc; > struct resource *res; > - const char *fw_name = "scp.img"; > + const char *fw_name; > int ret, i; > const struct mtk_scp_sizes_data *scp_sizes; > > ret = rproc_of_parse_firmware(dev, 0, &fw_name); > - if (ret < 0 && ret != -EINVAL) > - return ERR_PTR(ret); > + if (ret) { > + fw_name = scp_get_default_fw_path(dev, core_id); Wouldn't it make more sense to encapsulate the whole fw_name retrival in one function, e.g. scp_get_fw_path. > + if (IS_ERR(fw_name)) { > + dev_err(dev, "Cannot get firmware path: %ld\n", PTR_ERR(fw_name)); > + return ERR_CAST(fw_name); > + } > + } > > rproc = devm_rproc_alloc(dev, np->name, &scp_ops, fw_name, sizeof(*scp)); > if (!rproc) { > @@ -1212,7 +1264,7 @@ static int scp_add_single_core(struct platform_device *pdev, > struct mtk_scp *scp; > int ret; > > - scp = scp_rproc_init(pdev, scp_cluster, of_device_get_match_data(dev)); > + scp = scp_rproc_init(pdev, scp_cluster, of_device_get_match_data(dev), -1); > if (IS_ERR(scp)) > return PTR_ERR(scp); > > @@ -1259,7 +1311,7 @@ static int scp_add_multi_core(struct platform_device *pdev, > goto init_fail; > } > > - scp = scp_rproc_init(cpdev, scp_cluster, cluster_of_data[core_id]); > + scp = scp_rproc_init(cpdev, scp_cluster, cluster_of_data[core_id], core_id); > put_device(&cpdev->dev); > if (IS_ERR(scp)) { > ret = PTR_ERR(scp);