From nobody Thu Jun 11 17:32:41 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C8743A1E72; Sun, 10 May 2026 16:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429162; cv=none; b=ZdZ8h5JqJSHYT78FBt8jJwPAjmx6Q+OMpXK0QNgkPF7YwwvWsQdZ3uouJzPSkMSL0ceYX8k6tYZ5MYRazt6SDUqUUwlQPINZa5jMhgRwmVRFlKeDLeopEXtR3m6/8kEqCsyIHkzkk6RpKwKq6NC3XR11BT2y09QDHnasrCKUuK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429162; c=relaxed/simple; bh=w9BUYaJkPdlrqRsI2rYzDAZGFyxczOTFgyyyubfwW9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qAADyOVAX7scyz09rzsWwAp+wNArMc6UpiNFAVoyOxqpDoxCramre+cjfooYOwTDPu+z4+2113dvMPzMKoB6Wd/8cDagPGnvOfi04PS28iNWFFwuzHLudwGApjA7xDHRxEByht7ql0K4eI8sPdzGjg0OF366OzWLMyGBq+P8v5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=cTOicdDi; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="cTOicdDi" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B05592972; Sun, 10 May 2026 09:05:54 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 756863F836; Sun, 10 May 2026 09:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778429160; bh=w9BUYaJkPdlrqRsI2rYzDAZGFyxczOTFgyyyubfwW9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cTOicdDiG7K6UW6wTuwcB3Wf0LetuVK7dyjZw4US4XCbsD4wa4q8AaCOTqj/XnXCt GXjTYPEEYwMzT9c2+VfKlHPLCD6woWGpmlSTUTs06QZTFCSTWbEbGpo4ZkgOZh9m0t 4KQhujdiQlJAxgGSi0Nc0vpZhT8LJ+F9xnTql1mg= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@kernel.org, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, gatien.chevallier@foss.st.com, u.kleine-koenig@baylibre.com, dakr@kernel.org, Cristian Marussi Subject: [PATCH v2 1/4] firmware: arm_scmi: Add transport instance handles Date: Sun, 10 May 2026 17:05:24 +0100 Message-ID: <20260510160527.3537474-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260510160527.3537474-1-cristian.marussi@arm.com> References: <20260510160527.3537474-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SCMI transport drivers are initialized first and then the control is passed to the SCMI core stack: some of these transports are dependent also on some external subsytem which will have to be initialized upfront, before the transport driver itself can be deemed operational. Transport drivers like virtio or optee need a way to defer the core SCMI probing till they are fully initialized and operational and also a way to pass back the device reference to be used as a supplier while building the devlink relations. SCMI transport drivers can be probed multiple times when used in a multiple instance configuration but the capability to carry-on with multiple probes depends on the support provided by the underlying transport driver. This change will also allow for the removal of the frowned-upon trick of registering a platform driver only after the end of the transport drivers porbe to avoid explicit probe deferrals. Signed-off-by: Cristian Marussi --- v1 -> v2 - saving *th handle into scmi_transport to simplify freeing path - add a return value to supplier_put --- drivers/firmware/arm_scmi/common.h | 52 +++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi= /common.h index 7c9617d080a0..af6f9f498e14 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -462,6 +463,28 @@ struct scmi_transport_core_operations { const struct scmi_message_operations *msg; }; =20 +/** + * struct scmi_transport_handle - Transport instance handle + * @supplier_get: A helper to retrieve the device descriptor, identifying = the + * transport driver serving this SCMI instance, which will be + * used as a supplier for the core SCMI driver: returning an + * error here causes the probe sequence to be interrupted and + * return that same error code, so that each transport can decide + * which policy to implement by choosing an appropriate error. + * @supplier_put: A helper to signal that the specified transport supplier= is + * no more being used and it is made available again. + * + * Note that these helpers are needed and provided only by those transports + * whose initialization relies on some other subsystem and whose relations= to + * the core SCMI driver is not tracked by firmware descriptions. + */ +struct scmi_transport_handle { + struct device __must_check *(*supplier_get) + (const struct scmi_transport_handle *th); + int (*supplier_put)(const struct scmi_transport_handle *th, + struct device *dev); +}; + /** * struct scmi_transport - A structure representing a configured transport * @@ -470,35 +493,52 @@ struct scmi_transport_core_operations { * @desc: Transport descriptor * @core_ops: A pointer to a pointer used by the core SCMI stack to make t= he * core transport operations accessible to the transports. + * @th: An optional pointer to the transport handle */ struct scmi_transport { struct device *supplier; struct scmi_desc desc; struct scmi_transport_core_operations **core_ops; + const struct scmi_transport_handle *th; }; =20 #define DEFINE_SCMI_TRANSPORT_DRIVER(__tag, __drv, __desc, __match, __core= _ops)\ static void __tag##_dev_free(void *data) \ { \ struct platform_device *spdev =3D data; \ + struct scmi_transport *strans; \ + \ + strans =3D dev_get_platdata(&spdev->dev); \ + if (strans && strans->th) \ + strans->th->supplier_put(strans->th, strans->supplier); \ \ platform_device_unregister(spdev); \ } \ \ static int __tag##_probe(struct platform_device *pdev) \ { \ - struct device *dev =3D &pdev->dev; \ + struct device *dev =3D &pdev->dev, *supplier; \ struct platform_device *spdev; \ struct scmi_transport strans; \ int ret; \ \ + supplier =3D dev; \ + strans.th =3D device_get_match_data(dev); \ + if (strans.th) { \ + supplier =3D strans.th->supplier_get(strans.th); \ + if (IS_ERR(supplier)) \ + return PTR_ERR(supplier); \ + } \ + \ spdev =3D platform_device_alloc("arm-scmi", PLATFORM_DEVID_AUTO); \ - if (!spdev) \ - return -ENOMEM; \ + if (!spdev) { \ + ret =3D -ENOMEM; \ + goto err_mem; \ + } \ \ device_set_of_node_from_dev(&spdev->dev, dev); \ \ - strans.supplier =3D dev; \ + strans.supplier =3D supplier; \ memcpy(&strans.desc, &(__desc), sizeof(strans.desc)); \ strans.core_ops =3D &(__core_ops); \ \ @@ -515,6 +555,10 @@ static int __tag##_probe(struct platform_device *pdev)= \ \ err: \ platform_device_put(spdev); \ +err_mem: \ + if (strans.th) \ + strans.th->supplier_put(strans.th, supplier); \ + \ return ret; \ } \ \ --=20 2.53.0 From nobody Thu Jun 11 17:32:41 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 850E33AE6E9; Sun, 10 May 2026 16:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429165; cv=none; b=E+t/DhJ9bRai7PU+F8/A50EKEmB376Tm2bWab78NX/l2GbGYt4GWIbWX6em2NosD6NOgZebRLnt0/B5SAE3LmU+ifT9f14TC1zVThkqY09IYVHSmnul9vKq1uI6nM202jqPJtCCyyIrN+R1oC8V879m3vJK8wY4bfDmrOprdVX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429165; c=relaxed/simple; bh=F8vJTCBI4I5uGCkR814PIgh1GPQVvIXCgM00JJbgA/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LEMev+O/LZ8s2yrJut8Ov1A+xZOKdzZ39hLcA27/Y+D6R7xSSuyrXWLehWm7T5H1vnkT1vlepzwfohDKOt2+Qw7PS3SeyBo1jNhCwTZuxui7cMMjnTOC/mPS9NC46Rb4aLg7W5O2KcTmj8U+ZFBCZOYMzsUQ8d4qoYkpfP7Vuog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Cko+oeNM; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Cko+oeNM" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 912462A68; Sun, 10 May 2026 09:05:57 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5765D3F836; Sun, 10 May 2026 09:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778429162; bh=F8vJTCBI4I5uGCkR814PIgh1GPQVvIXCgM00JJbgA/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cko+oeNMv/Ig3vwFiSCaMydLGhIpo+I5VdahVwH9YwqnVijIMjv5v5s2uQ8p0wAPn uQXpdbRXUem7YRI9oAXmAEE0MtKmDNSMLjqHBkeltJzSAsmF7W2E7TTn4w8aOzIfHC 8UyoP8ed4eV7lDKp7fElGu0djPCfA9aNXovtuhg8= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@kernel.org, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, gatien.chevallier@foss.st.com, u.kleine-koenig@baylibre.com, dakr@kernel.org, Cristian Marussi Subject: [PATCH v2 2/4] firmware: arm_scmi: Add a generic transport supplier Date: Sun, 10 May 2026 17:05:25 +0100 Message-ID: <20260510160527.3537474-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260510160527.3537474-1-cristian.marussi@arm.com> References: <20260510160527.3537474-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the capability to define a common generic transport supplier which embeds the logic needed to support one single unique instance of transport supplier. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/common.h | 111 +++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi= /common.h index af6f9f498e14..e2885173594a 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -502,6 +502,117 @@ struct scmi_transport { const struct scmi_transport_handle *th; }; =20 +/** + * struct scmi_transport_supplier - Transport descriptor + * @mtx: A mutex to protect @available + * @available: A reference to an initialized transport device, when availa= ble. + * This reference is implicitly used to track the status of the + * supplier and it can cycle through the following 3 states: + * 1. NOT_READY - PTR_ERR(-EPROBE_DEFER): no supplier available; + * this is the transport initial state. + * 2. AVAILABLE - : a transport supplier has been + * initialized and it is available, ready to use. + * 3. BUSY _ PTR_ERR(-EBUSY): transport supplier is currently in us= e. + * @th: An embedded transport handle object that embeds the helpers + * implementing the above mentioned logic + * + * Note that this transport driver enforces single instance probing. + */ +struct scmi_transport_supplier { + /* Protect @available */ + struct mutex mtx; + struct device *available; + const struct scmi_transport_handle th; +}; + +#define to_sup(t) container_of(t, struct scmi_transport_supplier, th) + +/** + * scmi_transport_supplier_put - A helper to dispose of a supplier + * @th: A reference to the transport handle to use + * @supplier: A reference to the device supplier to manage, cannot be NULL + * or ERR_PTR. + * + * Note that putting a supplier will have different effect based on the + * current state of scmi_transport_supplier.available: + * - NOT_READY/BUSY: @supplier will be set as the new available device: t= his + * can be used to made available a supplier OR stop using one. + * - AVAILABLE: if the @supplier we are disposing of matches the currently + * available one, roll back to NOT_READY state. + * Any other attempt to override an available supplier with a + * new one is rejected, effectively enforcing one single supplier. + * + * Return: 0 on Success, errno otherwise. + */ +static inline int +scmi_transport_supplier_put(const struct scmi_transport_handle *th, + struct device *supplier) +{ + struct scmi_transport_supplier *sup =3D to_sup(th); + + /* Nothing to do when the provided supplier was never real */ + if (IS_ERR_OR_NULL(supplier)) + return 0; + + guard(mutex)(&sup->mtx); + switch (PTR_ERR_OR_ZERO(sup->available)) { + case -EPROBE_DEFER: + case -EBUSY: + sup->available =3D supplier; + break; + case 0: + /* Putting a supplier when in the AVAILABLE state causes a + * transition back to the NOT_READY state, BUT only if the + * supplier we are disposing of was exactly the device that was + * previously made readily available. + */ + if (supplier !=3D sup->available) + return -EINVAL; + sup->available =3D ERR_PTR(-EPROBE_DEFER); + break; + default: + return -EINVAL; + } + + return 0; +} + +/** + * scmi_transport_supplier_get - A helper to get hold of a supplier + * @th: A reference to the transport handle to use + * + * Note that, trying to get a supplier device can return: + * - a ready to use supplier device, (subsequently made unavailable) + * - PTR_ERR(-EPROBE_DEFER): no supplier is available + * - PTR_ERR(-BUSY): supplier was already taken by a previous get + * + * This allows the probe to defer and wait when a possible device can + * be reasonably expected to appear. + * + * Return: a usable supplier device on Success or PTR_ERR on Failure. + */ +static inline struct device * +scmi_transport_supplier_get(const struct scmi_transport_handle *th) +{ + struct scmi_transport_supplier *sup =3D to_sup(th); + struct device *supplier; + + guard(mutex)(&sup->mtx); + supplier =3D sup->available; + if (!IS_ERR(sup->available)) + sup->available =3D ERR_PTR(-EBUSY); + + return supplier; +} + +#define DEFINE_SCMI_TRANSPORT_SUPPLIER(__supplier) \ +struct scmi_transport_supplier __supplier =3D { \ + .mtx =3D __MUTEX_INITIALIZER(__supplier.mtx), \ + .available =3D INIT_ERR_PTR(-EPROBE_DEFER), \ + .th.supplier_get =3D scmi_transport_supplier_get, \ + .th.supplier_put =3D scmi_transport_supplier_put, \ +} + #define DEFINE_SCMI_TRANSPORT_DRIVER(__tag, __drv, __desc, __match, __core= _ops)\ static void __tag##_dev_free(void *data) \ { \ --=20 2.53.0 From nobody Thu Jun 11 17:32:41 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B1483ACF13; Sun, 10 May 2026 16:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429168; cv=none; b=qB8F2DYYJn9nvMurR2rbq8RcCFSf1azkDuG0dZ5AWXcK4qu7RcEOAgh4ECj26R32ffzDooJGCNW2rRLJGeTBC41HOQ3Ru/LRx2AZb+ZoEF6ysqWrWOU9DrqYkYaH/OaHw8MxiZguEpJtq14x7oPOxYKCog74C5fUW2xWuMkGs8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429168; c=relaxed/simple; bh=VoP9MzxO+x8ngK9bt91ncy4odq1+TRH2nb39mF9mq/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PYPVyiyurud+aSNiLzydr0865JpKVFLHFWzm0OBTmFsQACipYrfcierevn54QYQLzfmCAu7ljPPM5cxxJwopZH8A51SYTfDP82RoROlYtg/1bomfPnxaGYJwDHpO9aFiU/wRWC0XEeP77jr43gf59bRowugZGzil/xaQ3BS/AoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Hb5UTIhM; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Hb5UTIhM" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9AEB726AC; Sun, 10 May 2026 09:06:00 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3781C3F836; Sun, 10 May 2026 09:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778429165; bh=VoP9MzxO+x8ngK9bt91ncy4odq1+TRH2nb39mF9mq/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hb5UTIhMZsjtKox+UHqLPnIoZwkaNAdFcP3Ja8Qyt8DMTOYlgEq0wzQgA0SvT+DRP KZmsLPcnWBg0QSr/DxZH7XuIDEPnYfPno1dSAJRpTRp3c85M/FEm84EyWmWgMnusny w0PomRABGEXfrPhzdNL5/s/Cw2bsS/gR2eco70W0= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@kernel.org, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, gatien.chevallier@foss.st.com, u.kleine-koenig@baylibre.com, dakr@kernel.org, Cristian Marussi Subject: [PATCH v2 3/4] firmware: arm_scmi: virtio: Rework transport probe sequence Date: Sun, 10 May 2026 17:05:26 +0100 Message-ID: <20260510160527.3537474-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260510160527.3537474-1-cristian.marussi@arm.com> References: <20260510160527.3537474-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new per-instance transport handles helpers to synchronize and optionally defer the core SCMI driver probe up until the transport driver has completely been initialized and it is fully operational as a supplier. Introduce proper module init/exit routines while removing the ugly trick of registering a driver from within the probe sequence of another one, just to avoid to have to deal with probe deferrals. Signed-off-by: Cristian Marussi --- v1 -> v2 - fixed __MUTEX_INITILIAZER() usage - use common generic supplier definitions - get rid of init/cleanup wrappers - fixed possible race between supplier made available and scmi_dev made visible - restored initial virtio_device_ready() logic, taking care to reset device on failure too --- drivers/firmware/arm_scmi/transports/virtio.c | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/arm_scmi/transports/virtio.c b/drivers/firmwa= re/arm_scmi/transports/virtio.c index 326c4a93e44b..3282d8271839 100644 --- a/drivers/firmware/arm_scmi/transports/virtio.c +++ b/drivers/firmware/arm_scmi/transports/virtio.c @@ -4,7 +4,7 @@ * (SCMI). * * Copyright (C) 2020-2022 OpenSynergy. - * Copyright (C) 2021-2024 ARM Ltd. + * Copyright (C) 2021-2026 ARM Ltd. */ =20 /** @@ -116,6 +116,8 @@ static struct scmi_transport_core_operations *core; /* Only one SCMI VirtIO device can possibly exist */ static struct virtio_device *scmi_vdev; =20 +static DEFINE_SCMI_TRANSPORT_SUPPLIER(scmi_virtio_supplier); + static void scmi_vio_channel_ready(struct scmi_vio_channel *vioch, struct scmi_chan_info *cinfo) { @@ -394,6 +396,10 @@ static bool virtio_chan_available(struct device_node *= of_node, int idx) return false; } =20 + dev_dbg(&scmi_vdev->dev, "%s Channel %sAVAILABLE on SCMI Virtio device.\n= ", + idx =3D=3D VIRTIO_SCMI_VQ_TX ? "TX" : "RX", + (vioch && !vioch->cinfo) ? "" : "NOT "); + return vioch && !vioch->cinfo; } =20 @@ -410,7 +416,7 @@ static int virtio_chan_setup(struct scmi_chan_info *cin= fo, struct device *dev, int i; =20 if (!scmi_vdev) - return -EPROBE_DEFER; + return -EINVAL; =20 vioch =3D &((struct scmi_vio_channel *)scmi_vdev->priv)[index]; =20 @@ -460,6 +466,9 @@ static int virtio_chan_setup(struct scmi_chan_info *cin= fo, struct device *dev, =20 scmi_vio_channel_ready(vioch, cinfo); =20 + dev_dbg(&scmi_vdev->dev, "%s Channel SETUP on SCMI Virtio device.\n", + tx ? "TX" : "RX"); + return 0; } =20 @@ -801,7 +810,7 @@ static struct scmi_desc scmi_virtio_desc =3D { }; =20 static const struct of_device_id scmi_of_match[] =3D { - { .compatible =3D "arm,scmi-virtio" }, + { .compatible =3D "arm,scmi-virtio", .data =3D &scmi_virtio_supplier.th}, { /* Sentinel */ }, }; =20 @@ -864,33 +873,33 @@ static int scmi_vio_probe(struct virtio_device *vdev) sz =3D MSG_TOKEN_MAX; } channels[i].max_msg =3D sz; + dev_dbg(dev, "VQ%d initialized with max_msg: %d\n", i, sz); } =20 vdev->priv =3D channels; - /* Ensure initialized scmi_vdev is visible */ smp_store_mb(scmi_vdev, vdev); =20 /* Set device ready */ virtio_device_ready(vdev); =20 - ret =3D platform_driver_register(&scmi_virtio_driver); + ret =3D scmi_transport_supplier_put(&scmi_virtio_supplier.th, &vdev->dev); if (ret) { + virtio_reset_device(vdev); vdev->priv =3D NULL; vdev->config->del_vqs(vdev); /* Ensure NULLified scmi_vdev is visible */ smp_store_mb(scmi_vdev, NULL); - return ret; } =20 + dev_dbg(dev, "Probed and initialized SCMI Virtio device.\n"); + return 0; } =20 static void scmi_vio_remove(struct virtio_device *vdev) { - platform_driver_unregister(&scmi_virtio_driver); - /* * Once we get here, virtio_chan_free() will have already been called by * the SCMI core for any existing channel and, as a consequence, all the @@ -900,8 +909,10 @@ static void scmi_vio_remove(struct virtio_device *vdev) */ virtio_reset_device(vdev); vdev->config->del_vqs(vdev); + /* Ensure scmi_vdev is visible as NULL */ smp_store_mb(scmi_vdev, NULL); + scmi_transport_supplier_put(&scmi_virtio_supplier.th, &vdev->dev); } =20 static int scmi_vio_validate(struct virtio_device *vdev) @@ -936,7 +947,30 @@ static struct virtio_driver virtio_scmi_driver =3D { .validate =3D scmi_vio_validate, }; =20 -module_virtio_driver(virtio_scmi_driver); +static int __init scmi_transport_virtio_init(void) +{ + int ret; + + ret =3D register_virtio_driver(&virtio_scmi_driver); + if (ret) + return ret; + + ret =3D platform_driver_register(&scmi_virtio_driver); + if (ret) { + unregister_virtio_driver(&virtio_scmi_driver); + return ret; + } + + return ret; +} +module_init(scmi_transport_virtio_init); + +static void __exit scmi_transport_virtio_exit(void) +{ + platform_driver_unregister(&scmi_virtio_driver); + unregister_virtio_driver(&virtio_scmi_driver); +} +module_exit(scmi_transport_virtio_exit); =20 MODULE_AUTHOR("Igor Skalkin "); MODULE_AUTHOR("Peter Hilber "); --=20 2.53.0 From nobody Thu Jun 11 17:32:41 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B41C3A1A58; Sun, 10 May 2026 16:06:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429180; cv=none; b=RYCEZwAQAk4pbxvNHgzuLt0+JyT4AYkbn2LEIYPTbrpvC9TcuAvwBlFyqASld/E/RXYHOa0o3UIYSScT6gdZ01/pJF6KS4XDB8JH+m4W4FWu2xJRbzwc5HMl9u62DsYIItwsm5TEEjw3wYUJy6E0sjeN46ailsyYFjKQrUQ32SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778429180; c=relaxed/simple; bh=Yvl5e0/bXtH3DqoJuR+H+WomG2HEBPx9dK1/VFX327c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h3WEGa1TWwqnCUrS7Wlc6Gszw80IHTLCSlgUxIi7B9ArDCRhH2ks0RyHetC9GmqmksHB2RLHGTjxJsJjXijdYeCZNClgn2kK3UC//9VQ8Wcj8uy7aIdidVER1cXv7RP4gIui8OnFhlTVA2H/MdFbEN7KMXHkBIesFIrjuYkHrqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=cmII/EMT; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="cmII/EMT" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 89BE827B5; Sun, 10 May 2026 09:06:03 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 446173F836; Sun, 10 May 2026 09:06:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778429168; bh=Yvl5e0/bXtH3DqoJuR+H+WomG2HEBPx9dK1/VFX327c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmII/EMT+K0ivX+5X1kyLo0EW7NzboZzHQfElWwz9ap5aR17PpmAlfSIzVPQlvDAm 4qtayWkWca51phdrVavqtMi7DejboyMIyRh7ZhbmvcvbfdmUcmetZcl5HCrEjVf2z3 qYG13l6rVzb3c/Rb0nWST/k4jiB/HOPUXXz2De/Y= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@kernel.org, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, gatien.chevallier@foss.st.com, u.kleine-koenig@baylibre.com, dakr@kernel.org, Cristian Marussi Subject: [PATCH v2 4/4] firmware: arm_scmi: optee: Rework transport probe sequence Date: Sun, 10 May 2026 17:05:27 +0100 Message-ID: <20260510160527.3537474-5-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260510160527.3537474-1-cristian.marussi@arm.com> References: <20260510160527.3537474-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new per-instance transport handles helpers to synchronize and optionally defer the core SCMI driver probe up until the transport driver has completely been initialized and it is fully operational as a supplier. Introduce proper module init/exit routines while removing the ugly trick of registering a driver from within the probe sequence of another one, just to avoid to have to deal with probe deferrals. Signed-off-by: Cristian Marussi --- v1 -> v2 - fixed __MUTEX_INITILIAZER() usage - use common generic supplier definitions - get rid of init/cleanup wrappers - use proper barrier on scmi_optee_agent --- drivers/firmware/arm_scmi/transports/optee.c | 46 +++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/arm_scmi/transports/optee.c b/drivers/firmwar= e/arm_scmi/transports/optee.c index 07ae18d5279d..dbe32e141748 100644 --- a/drivers/firmware/arm_scmi/transports/optee.c +++ b/drivers/firmware/arm_scmi/transports/optee.c @@ -154,6 +154,8 @@ static struct scmi_transport_core_operations *core; /* There can be only 1 SCMI service in OP-TEE we connect to */ static struct scmi_optee_agent *scmi_optee_private; =20 +static DEFINE_SCMI_TRANSPORT_SUPPLIER(scmi_optee_supplier); + /* Open a session toward SCMI OP-TEE service with REE_KERNEL identity */ static int open_session(struct scmi_optee_agent *agent, u32 *tee_session) { @@ -522,7 +524,7 @@ static struct scmi_desc scmi_optee_desc =3D { }; =20 static const struct of_device_id scmi_of_match[] =3D { - { .compatible =3D "linaro,scmi-optee" }, + { .compatible =3D "linaro,scmi-optee", .data =3D &scmi_optee_supplier.th}, { /* Sentinel */ }, }; =20 @@ -561,18 +563,20 @@ static int scmi_optee_service_probe(struct tee_client= _device *scmi_pta) if (ret) goto err; =20 - /* Ensure agent resources are all visible before scmi_optee_private is */ + /* Ensure initialized scmi_optee_private is visible */ smp_mb(); scmi_optee_private =3D agent; =20 - ret =3D platform_driver_register(&scmi_optee_driver); - if (ret) { - scmi_optee_private =3D NULL; - goto err; - } + ret =3D scmi_transport_supplier_put(&scmi_optee_supplier.th, agent->dev); + if (ret) + goto err_put; =20 return 0; =20 +err_put: + /* Ensure cleared reference is visible before resources are released */ + smp_store_mb(scmi_optee_private, NULL); + err: tee_client_close_context(tee_ctx); =20 @@ -586,13 +590,12 @@ static void scmi_optee_service_remove(struct tee_clie= nt_device *scmi_pta) if (!scmi_optee_private) return; =20 - platform_driver_unregister(&scmi_optee_driver); - if (!list_empty(&scmi_optee_private->channel_list)) return; =20 /* Ensure cleared reference is visible before resources are released */ smp_store_mb(scmi_optee_private, NULL); + scmi_transport_supplier_put(&scmi_optee_supplier.th, agent->dev); =20 tee_client_close_context(agent->tee_ctx); } @@ -616,7 +619,30 @@ static struct tee_client_driver scmi_optee_service_dri= ver =3D { }, }; =20 -module_tee_client_driver(scmi_optee_service_driver); +static int __init scmi_transport_optee_init(void) +{ + int ret; + + ret =3D tee_client_driver_register(&scmi_optee_service_driver); + if (ret) + return ret; + + ret =3D platform_driver_register(&scmi_optee_driver); + if (ret) { + tee_client_driver_unregister(&scmi_optee_service_driver); + return ret; + } + + return ret; +} +module_init(scmi_transport_optee_init); + +static void __exit scmi_transport_optee_exit(void) +{ + platform_driver_unregister(&scmi_optee_driver); + tee_client_driver_unregister(&scmi_optee_service_driver); +} +module_exit(scmi_transport_optee_exit); =20 MODULE_AUTHOR("Etienne Carriere "); MODULE_DESCRIPTION("SCMI OPTEE Transport driver"); --=20 2.53.0