From nobody Fri Dec 27 12:02:55 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE62714884C; Mon, 9 Dec 2024 16:50:24 +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=1733763026; cv=none; b=cA/iQm75vzRQ+v2UMqZ5LqjVwtam7TQn/TU1yr8mfivgldYColPh+hcYOx7ApECpKHr+HOB8m7ka+3qN8EFyXvgXuIJUbKC9q8jcbFe7KLMQRUAB+gggp0QWI1e7IlfMA3nFr8yJCmzI3ScOfnNUjE9FRqJm5UlbJD9d0TePztI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733763026; c=relaxed/simple; bh=QOJ+12hGDkUho7wq6DP7RfEJABK+teP6XEI9hXaFyuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O3wNhOwNLvf5KaCjUa+ACu6TSYTWZsURp5W+3/vM1R70nQwO3AeZjBncN1El5z+rYNYxqcEXkd7qE35FzYAIVr2kJNv84Qkb9jdlSGhIPa06gv7h2fkUw5QtHosg8TAbblYC2ypqhDCx+ioVQ4NR9JSH4hfJKZewZhe7Z/tTl8g= 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; 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 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 116181650; Mon, 9 Dec 2024 08:50:52 -0800 (PST) Received: from pluto.guest.local (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 440603F720; Mon, 9 Dec 2024 08:50:21 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, dan.carpenter@linaro.org, johan+linaro@kernel.org, Cristian Marussi Subject: [PATCH v2 1/3] firmware: arm_scmi: Support vendor protocol modules autoloading Date: Mon, 9 Dec 2024 16:49:55 +0000 Message-ID: <20241209164957.1801886-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209164957.1801886-1-cristian.marussi@arm.com> References: <20241209164957.1801886-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 vendor protocols namespace is shared amongst all vendors so that there can be multiple implementation for the same protocol ID by different vendors, exposing completely different functionalities and used by distinct SCMI vendor drivers. For these reasons, at runtime, when some driver asks for a protocol, the proper implementation to use is chosen based on the SCMI vendor/subvendor/ impl_version data as advertised by the platform SCMI server and gathered from the SCMI core during stack initialization: this enables proper runtime selection of vendor protocols even when many different protocols from different vendors are built into the same image via a common defconfig. This same selection mechanism works similarly well even when all the vendor protocols are compiled as loadable modules, as long as all such required protocol modules have been previously loaded by some other means. Add support for the automatic loading of vendor protocol modules, based on protocol/vendor IDs, when an SCMI driver attempts to use such a protocol. Reported-by: Johan Hovold Closes: https://lore.kernel.org/lkml/ZytnRc94iKUfMYH0@hovoldconsulting.com/ Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 56 ++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index eeed1689b208..60050da54bf2 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,8 @@ #define CREATE_TRACE_POINTS #include =20 +#define SCMI_VENDOR_MODULE_ALIAS_FMT "scmi-protocol-0x%02x-%s" + static DEFINE_IDA(scmi_id); =20 static DEFINE_XARRAY(scmi_protocols); @@ -275,6 +278,44 @@ scmi_vendor_protocol_lookup(int protocol_id, char *ven= dor_id, return proto; } =20 +static const struct scmi_protocol * +scmi_vendor_protocol_get(int protocol_id, struct scmi_revision_info *versi= on) +{ + const struct scmi_protocol *proto; + + proto =3D scmi_vendor_protocol_lookup(protocol_id, version->vendor_id, + version->sub_vendor_id, + version->impl_ver); + if (!proto) { + int ret; + + pr_debug("Looking for '" SCMI_VENDOR_MODULE_ALIAS_FMT "'\n", + protocol_id, version->vendor_id); + + /* Note that vendor_id is mandatory for vendor protocols */ + ret =3D request_module(SCMI_VENDOR_MODULE_ALIAS_FMT, + protocol_id, version->vendor_id); + if (ret) { + pr_warn("Problem loading module for protocol 0x%x\n", + protocol_id); + return NULL; + } + + /* Lookup again, once modules loaded */ + proto =3D scmi_vendor_protocol_lookup(protocol_id, + version->vendor_id, + version->sub_vendor_id, + version->impl_ver); + } + + if (proto) + pr_info("Loaded SCMI Vendor Protocol 0x%x - %s %s %X\n", + protocol_id, proto->vendor_id ?: "", + proto->sub_vendor_id ?: "", proto->impl_ver); + + return proto; +} + static const struct scmi_protocol * scmi_protocol_get(int protocol_id, struct scmi_revision_info *version) { @@ -283,10 +324,8 @@ scmi_protocol_get(int protocol_id, struct scmi_revisio= n_info *version) if (protocol_id < SCMI_PROTOCOL_VENDOR_BASE) proto =3D xa_load(&scmi_protocols, protocol_id); else - proto =3D scmi_vendor_protocol_lookup(protocol_id, - version->vendor_id, - version->sub_vendor_id, - version->impl_ver); + proto =3D scmi_vendor_protocol_get(protocol_id, version); + if (!proto || !try_module_get(proto->owner)) { pr_warn("SCMI Protocol 0x%x not found!\n", protocol_id); return NULL; @@ -294,11 +333,6 @@ scmi_protocol_get(int protocol_id, struct scmi_revisio= n_info *version) =20 pr_debug("Found SCMI Protocol 0x%x\n", protocol_id); =20 - if (protocol_id >=3D SCMI_PROTOCOL_VENDOR_BASE) - pr_info("Loaded SCMI Vendor Protocol 0x%x - %s %s %X\n", - protocol_id, proto->vendor_id ?: "", - proto->sub_vendor_id ?: "", proto->impl_ver); - return proto; } =20 @@ -366,7 +400,9 @@ int scmi_protocol_register(const struct scmi_protocol *= proto) return ret; } =20 - pr_debug("Registered SCMI Protocol 0x%x\n", proto->id); + pr_debug("Registered SCMI Protocol 0x%x - %s %s 0x%08X\n", + proto->id, proto->vendor_id, proto->sub_vendor_id, + proto->impl_ver); =20 return 0; } --=20 2.47.0 From nobody Fri Dec 27 12:02:55 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC0A0153828; Mon, 9 Dec 2024 16:50:27 +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=1733763029; cv=none; b=NqN5byZ7tjXYaPmG6nVYJkDFa/2MJpbRLU8kPY/2+NUTAYIC9FyM+rVOS40V/I4U6uGvKYUqrZSUWHCDEMPnvDV2Lyha5YrDBBJGJvEkbvVWzDRYk8Xspu7+0ZkJRXRLJk4XbVvCaiDGttSCUmlh6CHd1NY1e/SJM5Seutwbd/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733763029; c=relaxed/simple; bh=JvvO0mLZmvW+mUErG0I/0z7JGOhDtRD0iHTUI1KeHN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O4/amssFlDy/yR4TPwBoySCV6mDVzj5TCzU7wj/WRZCDstDrebXxrLtdscEA8YvxP0/IAR+35CvUi0ZuXQwIv8OOnhoHJNa+spzfb/q3vp7bDHx/H+1d55Wx0UhZeOmUGbR2EVQ4r2CG3Q2UhWQvEnGDjQb+/DwtjO9wOY2VQbU= 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; 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 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 2E4D6168F; Mon, 9 Dec 2024 08:50:55 -0800 (PST) Received: from pluto.guest.local (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5AF623F720; Mon, 9 Dec 2024 08:50:24 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, dan.carpenter@linaro.org, johan+linaro@kernel.org, Cristian Marussi , Peng Fan Subject: [PATCH v2 2/3] firmware: arm_scmi: Add module aliases to i.MX vendor protocols Date: Mon, 9 Dec 2024 16:49:56 +0000 Message-ID: <20241209164957.1801886-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209164957.1801886-1-cristian.marussi@arm.com> References: <20241209164957.1801886-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" Using the pattern 'scmi-protocol-0x-' as MODULE_ALIAS allows the SCMI core to autoload this protocol, if built as a module, when its protocol operations are requested by an SCMI driver. Cc: Peng Fan Acked-by: Peng Fan Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c | 5 +++-- drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c | 5 +++-- include/linux/scmi_imx_protocol.h | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c b/drivers/f= irmware/arm_scmi/vendors/imx/imx-sm-bbm.c index 17799eacf06c..aa176c1a5eef 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c @@ -374,10 +374,11 @@ static const struct scmi_protocol scmi_imx_bbm =3D { .ops =3D &scmi_imx_bbm_proto_ops, .events =3D &scmi_imx_bbm_protocol_events, .supported_version =3D SCMI_PROTOCOL_SUPPORTED_VERSION, - .vendor_id =3D "NXP", - .sub_vendor_id =3D "IMX", + .vendor_id =3D SCMI_IMX_VENDOR, + .sub_vendor_id =3D SCMI_IMX_SUBVENDOR, }; module_scmi_protocol(scmi_imx_bbm); =20 +MODULE_ALIAS("scmi-protocol-" __stringify(SCMI_PROTOCOL_IMX_BBM) "-" SCMI_= IMX_VENDOR); MODULE_DESCRIPTION("i.MX SCMI BBM driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c b/drivers/= firmware/arm_scmi/vendors/imx/imx-sm-misc.c index a86ab9b35953..83b69fc4fba5 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c @@ -309,10 +309,11 @@ static const struct scmi_protocol scmi_imx_misc =3D { .ops =3D &scmi_imx_misc_proto_ops, .events =3D &scmi_imx_misc_protocol_events, .supported_version =3D SCMI_PROTOCOL_SUPPORTED_VERSION, - .vendor_id =3D "NXP", - .sub_vendor_id =3D "IMX", + .vendor_id =3D SCMI_IMX_VENDOR, + .sub_vendor_id =3D SCMI_IMX_SUBVENDOR, }; module_scmi_protocol(scmi_imx_misc); =20 +MODULE_ALIAS("scmi-protocol-" __stringify(SCMI_PROTOCOL_IMX_MISC) "-" SCMI= _IMX_VENDOR); MODULE_DESCRIPTION("i.MX SCMI MISC driver"); MODULE_LICENSE("GPL"); diff --git a/include/linux/scmi_imx_protocol.h b/include/linux/scmi_imx_pro= tocol.h index 066216f1357a..53b356a26414 100644 --- a/include/linux/scmi_imx_protocol.h +++ b/include/linux/scmi_imx_protocol.h @@ -13,10 +13,11 @@ #include #include =20 -enum scmi_nxp_protocol { - SCMI_PROTOCOL_IMX_BBM =3D 0x81, - SCMI_PROTOCOL_IMX_MISC =3D 0x84, -}; +#define SCMI_PROTOCOL_IMX_BBM 0x81 +#define SCMI_PROTOCOL_IMX_MISC 0x84 + +#define SCMI_IMX_VENDOR "NXP" +#define SCMI_IMX_SUBVENDOR "IMX" =20 struct scmi_imx_bbm_proto_ops { int (*rtc_time_set)(const struct scmi_protocol_handle *ph, u32 id, --=20 2.47.0 From nobody Fri Dec 27 12:02:55 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D90341547F2; Mon, 9 Dec 2024 16:50:30 +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=1733763032; cv=none; b=P+g5bEX4bQuJ7phtKvWpHiGRtsgS85UmUywzRrk8Vx+Ir7tvfRlGuqRfmHgpQL8HJ2buA4MZwybKHbk3Yb07biMB7/6zvyCu+OpUZjAjmYLY/3rAEoXjVeHTFouxoVuKEuzRIRblp4iOGnwcgLqdI29Pii57Q3FOCvNgAptAIPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733763032; c=relaxed/simple; bh=wQAJR3PGJ00qhM2mIn9A9yT4Eg8X7acxsZcv4ljCrsw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OABl95Rrew1NazhqDnHyhr+zr3awLyH34BqaP0IcLRGGj4Q6nAqpuCRLG7a4zPGq99nk4wUMYEFpaucKy3rjTDz0EcP5NiVZTk1Nbv11yD5BaseRnxgiwDu9ATmg79IRqqiM86R4iypCUVonpmaf5TdJIe9FuD+u2qy5sv+mXoo= 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; 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 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 3A07E175D; Mon, 9 Dec 2024 08:50:58 -0800 (PST) Received: from pluto.guest.local (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 965393F720; Mon, 9 Dec 2024 08:50:27 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, dan.carpenter@linaro.org, johan+linaro@kernel.org, Cristian Marussi Subject: [PATCH v2 3/3] firmware: arm_scmi: Add aliases to transport modules Date: Mon, 9 Dec 2024 16:49:57 +0000 Message-ID: <20241209164957.1801886-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209164957.1801886-1-cristian.marussi@arm.com> References: <20241209164957.1801886-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 transports when built as loadable modules should be loaded by the subsystem they plug into, based on the related subsystem specific aliases. Add, where missing, the MODULE_DEVICE_TABLE() directives needed to generate the aliases required to enable autoloading for SCMI transports. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/transports/mailbox.c | 1 + drivers/firmware/arm_scmi/transports/smc.c | 1 + drivers/firmware/arm_scmi/transports/virtio.c | 1 + 3 files changed, 3 insertions(+) diff --git a/drivers/firmware/arm_scmi/transports/mailbox.c b/drivers/firmw= are/arm_scmi/transports/mailbox.c index b66df2981456..bd041c99b92b 100644 --- a/drivers/firmware/arm_scmi/transports/mailbox.c +++ b/drivers/firmware/arm_scmi/transports/mailbox.c @@ -378,6 +378,7 @@ static const struct of_device_id scmi_of_match[] =3D { { .compatible =3D "arm,scmi" }, { /* Sentinel */ }, }; +MODULE_DEVICE_TABLE(of, scmi_of_match); =20 DEFINE_SCMI_TRANSPORT_DRIVER(scmi_mailbox, scmi_mailbox_driver, scmi_mailbox_desc, scmi_of_match, core); diff --git a/drivers/firmware/arm_scmi/transports/smc.c b/drivers/firmware/= arm_scmi/transports/smc.c index f632a62cfb3e..21abb571e4f2 100644 --- a/drivers/firmware/arm_scmi/transports/smc.c +++ b/drivers/firmware/arm_scmi/transports/smc.c @@ -301,6 +301,7 @@ static const struct of_device_id scmi_of_match[] =3D { { .compatible =3D "qcom,scmi-smc" }, { /* Sentinel */ }, }; +MODULE_DEVICE_TABLE(of, scmi_of_match); =20 DEFINE_SCMI_TRANSPORT_DRIVER(scmi_smc, scmi_smc_driver, scmi_smc_desc, scmi_of_match, core); diff --git a/drivers/firmware/arm_scmi/transports/virtio.c b/drivers/firmwa= re/arm_scmi/transports/virtio.c index 41aea33776a9..cb934db9b2b4 100644 --- a/drivers/firmware/arm_scmi/transports/virtio.c +++ b/drivers/firmware/arm_scmi/transports/virtio.c @@ -921,6 +921,7 @@ static const struct virtio_device_id id_table[] =3D { { VIRTIO_ID_SCMI, VIRTIO_DEV_ANY_ID }, { 0 } }; +MODULE_DEVICE_TABLE(virtio, id_table); =20 static struct virtio_driver virtio_scmi_driver =3D { .driver.name =3D "scmi-virtio", --=20 2.47.0