AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/07/25 20:52 flow patch-triage
0m Args:
null

Results:
{
  "EnableConfigs": [
    "ARM_SCMI_PROTOCOL",
    "ARM_SCMI_SYSTEM_TELEMETRY",
    "ARM_SCMI_DEBUG_PROTOCOLS"
  ],
  "FocusSymbols": [
    "scmi_tlm_unlocked_ioctl",
    "scmi_tlm_abi_info_get_ioctl",
    "scmi_tlm_config_get_ioctl",
    "scmi_tlm_config_set_ioctl",
    "scmi_tlm_intervals_get_ioctl",
    "scmi_tlm_de_config_set_ioctl",
    "scmi_tlm_de_config_get_ioctl",
    "scmi_tlm_de_info_get_ioctl",
    "scmi_tlm_des_list_get_ioctl",
    "scmi_tlm_de_value_get_ioctl",
    "scmi_tlm_grp_info_get_ioctl",
    "scmi_tlm_grp_desc_get_ioctl",
    "scmi_tlm_grps_list_get_ioctl",
    "scmi_tlm_des_read_ioctl",
    "scmi_tlm_des_batch_read_ioctl",
    "scmi_tlm_shmtis_list_get_ioctl",
    "scmi_tlm_reset_ioctl",
    "scmi_tlm_shmti_mmap",
    "scmi_telemetry_dbg_shmti_read"
  ],
  "Reasoning": "The patch introduces a new SCMI System Telemetry driver and protocol, exposing a new character device (`/dev/scmi/tlm_\u003cN\u003e`) with a comprehensive set of ioctls for userspace to interact with the telemetry data. This is a significant new userspace API and core logic that should be fuzzed.",
  "WorthFuzzing": true
}

1/1 2026/07/25 20:52 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit aaf7d7ca7d7df47750f7803a93ee63c6c6503fa3\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Sat Jul 25 20:52:08 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/ABI/testing/debugfs-scmi b/Documentation/ABI/testing/debugfs-scmi\nindex ee7179ab2edfc7..edbbe360321d8a 100644\n--- a/Documentation/ABI/testing/debugfs-scmi\n+++ b/Documentation/ABI/testing/debugfs-scmi\n@@ -68,3 +68,25 @@ Description:\tMax number of concurrently allowed in-flight SCMI messages for\n \t\tthe currently configured SCMI transport for instance \u003cn\u003e on the\n \t\tRX channels.\n Users:\t\tDebugging, any userspace test suite\n+\n+What:\t\t/sys/kernel/debug/scmi/\u003cn\u003e/protocols/0x\u003cm\u003e/\n+Date:\t\tNov 2026\n+KernelVersion:\t7.3\n+Contact:\tcristian.marussi@arm.com\n+Description:\tA subdirectory grouping debug entries related to protocol \u003cm\u003e\n+\t\tfor instance \u003cn\u003e. Each protocol owns and defines the subtree\n+\t\tof entries rooted under this directory.\n+Users:\t\tDebugging, any userspace test suite\n+\n+What:\t\t/sys/kernel/debug/scmi/\u003cn\u003e/protocols/0x1B/shmtis/\u003cm\u003e\n+Date:\t\tNov 2026\n+KernelVersion:\t7.3\n+Contact:\tcristian.marussi@arm.com\n+Description:\tA set of RO files exposed by the Telemetry protocol (0x1B) in\n+\t\torder to dump the latest snapshot of each SHMTI memory area in\n+\t\tbinary format: each file is named by its SHMTI id.\n+\t\tFile is seekable and a seek to position zero on an open file\n+\t\tcauses the SHMTI snapshot to be refreshed; file timestamps are\n+\t\tupdated after each snapshot.\n+\t\tThis directory reports SHMTIs for instance \u003cn\u003e.\n+Users:\t\tDebugging, any userspace test suite\ndiff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml\nindex d06cca9273c483..be733f8d60a02e 100644\n--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml\n+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml\n@@ -324,6 +324,14 @@ properties:\n     required:\n       - reg\n \n+  protocol@1b:\n+    $ref: '#/$defs/protocol-node'\n+    unevaluatedProperties: false\n+\n+    properties:\n+      reg:\n+        const: 0x1b\n+\n unevaluatedProperties: false\n \n $defs:\ndiff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst\nindex a68b1bea57a85c..22daa7ebf78ee5 100644\n--- a/Documentation/userspace-api/index.rst\n+++ b/Documentation/userspace-api/index.rst\n@@ -54,6 +54,7 @@ Devices and I/O\n    dcdbas\n    vduse\n    isapnp\n+   stlm\n \n Everything else\n ===============\ndiff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst\nindex 3f0ef1e27eb07d..de136c5967f496 100644\n--- a/Documentation/userspace-api/ioctl/ioctl-number.rst\n+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst\n@@ -399,6 +399,7 @@ Code  Seq#    Include File                                             Comments\n 0xE5  00-3F  linux/fuse.h\n 0xEC  00-01  drivers/platform/chrome/cros_ec_dev.h                     ChromeOS EC driver\n 0xEE  00-09  uapi/linux/pfrut.h                                        Platform Firmware Runtime Update and Telemetry\n+0xF1  00-FF  uapi/linux/scmi.h\t\t\t\t\t       ARM SCMI Subsystem\n 0xF3  00-3F  drivers/usb/misc/sisusbvga/sisusb.h                       sisfb (in development)\n                                                                        \u003cmailto:thomas@winischhofer.net\u003e\n 0xF6  all                                                              LTTng Linux Trace Toolkit Next Generation\ndiff --git a/Documentation/userspace-api/stlm.rst b/Documentation/userspace-api/stlm.rst\nnew file mode 100644\nindex 00000000000000..e34226b11373f4\n--- /dev/null\n+++ b/Documentation/userspace-api/stlm.rst\n@@ -0,0 +1,143 @@\n+.. SPDX-License-Identifier: GPL-2.0\n+.. stlm:\n+\n+=======================================\n+STLM - ARM SCMI Telemetry Userspace API\n+=======================================\n+\n+.. contents::\n+\n+Overview\n+========\n+\n+ARM SCMI is a System and Configuration Management protocol, based on a\n+client-server model, that defines a number of messages that allows a\n+client/agent like Linux to discover, configure and make use of services\n+provided by the server/platform firmware.\n+\n+SCMI v4.0 [1] introduced support for System Telemetry, through which an\n+agent can dynamically enumerate, configure and collect Telemetry Data\n+Events (DE) exposed by the platform.\n+\n+The SCMI System Telemetry driver exposes one or more dedicated devices,\n+named as tlm_\u003cN\u003e, grouped under /dev/scmi/, one for each discovered SCMI\n+instance.\n+\n+A IOCTL based interface is defined in order to enumerate, configure and\n+read telemetry data, as succinctly described in the following.\n+\n+For more details on the uAPI, please see include/uapi/linux/scmi.h\n+\n+Resources Enumeration\n+=====================\n+\n+ - SCMI_TLM_GET_INFO: Gather basic Telemetry features like number of\n+   resources and versioning information.\n+\n+ - SCMI_TLM_GET_INTRVS: Enumerate available update intervals.\n+\n+ - SCMI_TLM_GET_DE_INFO: Retrieve DataEvent description.\n+\n+ - SCMI_TLM_GET_DE_LIST: Retrieve the list of all the existent DataEvent\n+   descriptors.\n+\n+ - SCMI_TLM_GET_GRP_LIST: Gather a list of descriptors for all defined Groups.\n+\n+ - SCMI_TLM_GET_GRP_INFO: Gather information for a specific Group.\n+\n+ - SCMI_TLM_GET_GRP_DESC: Gather detailed group composition information for\n+   the specified Group.\n+\n+\n+Configuration\n+=============\n+\n+ - SCMI_TLM_GET_CFG / SCMI_TLM_SET_CFG: Get or set the whole instance, or a\n+   specific group, configuration.\n+\n+ - SCMI_TLM_GET_DE_CFG / SCMI_TLM_SET_DE_CFG: Get or set the configuration\n+   of a specific DataEvent.\n+\n+ - SCMI_TLM_GET_ALL_CFG / SCMI_TLM_SET_ALL_CFG: Get or set the cumulative\n+   configuration of ALL the DataEvents defined on the platform.\n+\n+Data Collection\n+===============\n+\n+ - SCMI_TLM_DE_READ: Report the last updated sample for the specified\n+   DataEvent.\n+\n+ - SCMI_TLM_BULK_READ: Report the last samples for all the currently enabled\n+   DataEvents.\n+\n+ - SCMI_TLM_BATCH_READ: Report the last samples for the DataEvents IDs\n+   specified within the samples input params.\n+\n+ - SCMI_TLM_SINGLE_READ: Trigger an immediate platform-side DataEvent\n+   update and report the collected samples.\n+\n+Memory Mapped Raw Access\n+------------------------\n+\n+ - SCMI_TLM_GET_SHMTI_LIST: Gather a list of open file descriptors, one for\n+   each SHMTI memory areas defined for this instance, that can be used to\n+   memory-map such areas in the calling process address space so as to be\n+   able to directly access the SCMI Telemetry SHMTI areas shared by the\n+   platform firmware, and parse the TDCF format.\n+   The SCMI Telemetry TDCF format is defined in the specification at [1].\n+\n+\n+Example\n+=======\n+\n+.. code-block:: c\n+\n+\tint main(int argc, char **argv)\n+\t{\n+\t\tstruct scmi_tlm_de_config des_cfg = {};\n+\t\tstruct scmi_tlm_config cfg = {};\n+\t\tstruct scmi_tlm_de_sample samples[3] = {};\n+\t\tstruct scmi_tlm_data_read data = {};\n+\t\tint fd, ret;\n+\n+\t\tfd = open(\"/dev/scmi/tlm_0\", O_RDWR);\n+\t\tif (fd \u003c 0)\n+\t\t\treturn fd;\n+\n+\t\t/* Enable ALL Data Events with timestamps*/\n+\t\tdes_cfg.enable = 1;\n+\t\tdes_cfg.t_enable = 1;\n+\t\tret = ioctl(fd, SCMI_TLM_SET_ALL_CFG, \u0026des_cfg);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\t/* Enable Telemetry as a whole, set a 400ms update interval */\n+\t\tcfg.enable = 1;\n+\t\tcfg.active.secs = 400;\n+\t\tcfg.active.exp = -3;\n+\n+\t\tret = ioctl(fd, SCMI_TLM_SET_CFG, \u0026cfg);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\t/* Read a selection of DEs */\n+\t\tsamples[0].id = 0xA001;\n+\t\tsamples[1].id = 0x0002;\n+\t\tsamples[2].id = 0x1010;\n+\t\tdata.num_samples = 3;\n+\t\tdata.samples = (unsigned long)samples;\n+\n+\t\tret = ioctl(fd, SCMI_TLM_BATCH_READ, \u0026data);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\tfor (int i = 0; i \u003c 3; i++)\n+\t\t\tfprintf(stdout, \"%llu: 0x%08X -\u003e %llu\\n\",\n+\t\t\t\t\tsamples[i].tstamp, samples[i].id, samples[i].val);\n+\n+\t\treturn 0;\n+\t}\n+\n+References\n+==========\n+[1]: https://developer.arm.com/documentation/den0056/latest/\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex a900d8ee05c94b..f5cc87baebd75e 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -26300,6 +26300,7 @@ F:\tdrivers/regulator/scmi-regulator.c\n F:\tdrivers/reset/reset-scmi.c\n F:\tinclude/linux/sc[mp]i_protocol.h\n F:\tinclude/trace/events/scmi.h\n+F:\tinclude/uapi/linux/scmi.h\n F:\tinclude/uapi/linux/virtio_scmi.h\n \n SYSTEM CONTROL MANAGEMENT INTERFACE (SCMI) i.MX Extension Message Protocol drivers\ndiff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig\nindex 783c24a20e2919..e7d8dd9fa907f4 100644\n--- a/drivers/firmware/arm_scmi/Kconfig\n+++ b/drivers/firmware/arm_scmi/Kconfig\n@@ -69,6 +69,20 @@ config ARM_SCMI_DEBUG_COUNTERS\n \t  such useful debug counters. This can be helpful for debugging and\n \t  SCMI monitoring.\n \n+config ARM_SCMI_DEBUG_PROTOCOLS\n+\tbool \"Enable SCMI protocols debug\"\n+\tselect ARM_SCMI_NEED_DEBUGFS\n+\tdepends on DEBUG_FS\n+\tdefault n\n+\thelp\n+\t  Enables per-protocol specific debug features, where available.\n+\t  When provided, such per-protocol debugfs entries are grouped\n+\t  inside a common a subtree named by the protocol number and rooted\n+\t  under a per-instance 'protocols' directory.\n+\n+\t  Such per-protocol entries subtree structure is freely defined\n+\t  within the related protocol code.\n+\n config ARM_SCMI_QUIRKS\n \tbool \"Enable SCMI Quirks framework\"\n \tdepends on JUMP_LABEL || COMPILE_TEST\n@@ -99,4 +113,14 @@ config ARM_SCMI_POWER_CONTROL\n \t  called scmi_power_control. Note this may be needed early in boot to\n \t  catch early shutdown/reboot SCMI requests.\n \n+config ARM_SCMI_SYSTEM_TELEMETRY\n+\ttristate \"SCMI System Telemetry driver\"\n+\tdepends on ARM_SCMI_PROTOCOL || (COMPILE_TEST \u0026\u0026 OF)\n+\thelp\n+\t  This enables SCMI Systemn Telemetry support that allows userspace to\n+\t  retrieve ARM Telemetry data made available via SCMI.\n+\n+\t  This driver can also be built as a module.  If so, the module will be\n+\t  called scmi_system_telemetry.\n+\n endmenu\ndiff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile\nindex 780cd62b2f78aa..20f8d55840a5fe 100644\n--- a/drivers/firmware/arm_scmi/Makefile\n+++ b/drivers/firmware/arm_scmi/Makefile\n@@ -8,7 +8,7 @@ scmi-driver-$(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT) += raw_mode.o\n scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o\n scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o\n scmi-protocols-y := base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o\n-scmi-protocols-y += pinctrl.o\n+scmi-protocols-y += pinctrl.o telemetry.o\n scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)\n \n obj-$(CONFIG_ARM_SCMI_PROTOCOL) += transports/\n@@ -18,3 +18,4 @@ obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o\n obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o\n \n obj-$(CONFIG_ARM_SCMI_POWER_CONTROL) += scmi_power_control.o\n+obj-$(CONFIG_ARM_SCMI_SYSTEM_TELEMETRY) += scmi_system_telemetry.o\ndiff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h\nindex b9723c105fc1b5..5bed1a9f2de590 100644\n--- a/drivers/firmware/arm_scmi/common.h\n+++ b/drivers/firmware/arm_scmi/common.h\n@@ -18,6 +18,7 @@\n #include \u003clinux/list.h\u003e\n #include \u003clinux/module.h\u003e\n #include \u003clinux/property.h\u003e\n+#include \u003clinux/notifier.h\u003e\n #include \u003clinux/refcount.h\u003e\n #include \u003clinux/scmi_protocol.h\u003e\n #include \u003clinux/spinlock.h\u003e\n@@ -46,6 +47,8 @@ enum scmi_error_codes {\n \tSCMI_ERR_GENERIC = -8,\t/* Generic Error */\n \tSCMI_ERR_HARDWARE = -9,\t/* Hardware Error */\n \tSCMI_ERR_PROTOCOL = -10,/* Protocol Error */\n+\tSCMI_ERR_IN_USE = -11,  /* In Use Error */\n+\tSCMI_ERR_PARTIAL = -12, /* Partial Error */\n };\n \n static const int scmi_linux_errmap[] = {\n@@ -61,6 +64,8 @@ static const int scmi_linux_errmap[] = {\n \t-EIO,\t\t\t/* SCMI_ERR_GENERIC */\n \t-EREMOTEIO,\t\t/* SCMI_ERR_HARDWARE */\n \t-EPROTO,\t\t/* SCMI_ERR_PROTOCOL */\n+\t-EBUSY,\t\t\t/* SCMI_ERR_IN_USE */\n+\t-EINVAL,\t\t/* SCMI_ERR_PARTIAL */\n };\n \n static inline int scmi_to_linux_errno(int errno)\n@@ -317,6 +322,7 @@ enum debug_counters {\n /**\n  * struct scmi_debug_info  - Debug common info\n  * @top_dentry: A reference to the top debugfs dentry\n+ * @protos: A reference to the top debugfs protocols subdirectory\n  * @name: Name of this SCMI instance\n  * @type: Type of this SCMI instance\n  * @is_atomic: Flag to state if the transport of this instance is atomic\n@@ -324,6 +330,7 @@ enum debug_counters {\n  */\n struct scmi_debug_info {\n \tstruct dentry *top_dentry;\n+\tstruct dentry *protos;\n \tconst char *name;\n \tconst char *type;\n \tbool is_atomic;\n@@ -681,8 +688,19 @@ static struct platform_driver __drv = {\t\t\t\t\t       \\\n \t.probe = __tag##_probe,\t\t\t\t\t\t       \\\n }\n \n+struct scmi_protocol_notifier {\n+\tu8 proto_id;\n+\tu8 evt_id;\n+\tconst u32 *src_id;\n+\tstruct notifier_block *nb;\n+};\n+\n void scmi_notification_instance_data_set(const struct scmi_handle *handle,\n \t\t\t\t\t void *priv);\n void *scmi_notification_instance_data_get(const struct scmi_handle *handle);\n+int scmi_protocol_notifier_register(const struct scmi_handle *handle,\n+\t\t\t\t    struct scmi_protocol_notifier *pno);\n+int scmi_protocol_notifier_unregister(const struct scmi_handle *handle,\n+\t\t\t\t      struct scmi_protocol_notifier *pno);\n int scmi_inflight_count(const struct scmi_handle *handle);\n #endif /* _SCMI_COMMON_H */\ndiff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c\nindex 3e0d975ec94c44..82a7d2f690949d 100644\n--- a/drivers/firmware/arm_scmi/driver.c\n+++ b/drivers/firmware/arm_scmi/driver.c\n@@ -18,6 +18,7 @@\n \n #include \u003clinux/bitmap.h\u003e\n #include \u003clinux/cleanup.h\u003e\n+#include \u003clinux/dcache.h\u003e\n #include \u003clinux/debugfs.h\u003e\n #include \u003clinux/device.h\u003e\n #include \u003clinux/export.h\u003e\n@@ -90,6 +91,8 @@ struct scmi_xfers_info {\n  * @gid: A reference for per-protocol devres management.\n  * @users: A refcount to track effective users of this protocol.\n  * @priv: Reference for optional protocol private data.\n+ * @pno: A protocol instance notifier descriptor: active only when the\n+ *\t included notifier block @nb is non-NULL.\n  * @version: Protocol version supported by the platform as detected at runtime.\n  * @negotiated_version: When the platform supports a newer protocol version,\n  *\t\t\tthe agent will try to negotiate with the platform the\n@@ -99,6 +102,8 @@ struct scmi_xfers_info {\n  *\t\t\thas completed.\n  * @ph: An embedded protocol handle that will be passed down to protocol\n  *\tinitialization code to identify this instance.\n+ * @dbg: An optional reference to this protocol top debugfs directory; it will\n+ *\t be automatically recursively removed on protocol de-initialization.\n  *\n  * Each protocol is initialized independently once for each SCMI platform in\n  * which is defined by DT and implemented by the SCMI server fw.\n@@ -109,9 +114,11 @@ struct scmi_protocol_instance {\n \tvoid\t\t\t\t*gid;\n \trefcount_t\t\t\tusers;\n \tvoid\t\t\t\t*priv;\n+\tstruct scmi_protocol_notifier   pno;\n \tunsigned int\t\t\tversion;\n \tunsigned int\t\t\tnegotiated_version;\n \tstruct scmi_protocol_handle\tph;\n+\tstruct dentry\t\t\t*dbg;\n };\n \n #define ph_to_pi(h)\tcontainer_of(h, struct scmi_protocol_instance, ph)\n@@ -1655,6 +1662,24 @@ static void *scmi_get_protocol_priv(const struct scmi_protocol_handle *ph)\n \treturn pi-\u003epriv;\n }\n \n+static int\n+scmi_register_instance_notifier(const struct scmi_protocol_handle *ph, u8 evt_id,\n+\t\t\t\tconst u32 *src_id, struct notifier_block *nb)\n+{\n+\tstruct scmi_protocol_instance *pi = ph_to_pi(ph);\n+\n+\tpi-\u003epno.proto_id = pi-\u003eproto-\u003eid;\n+\tpi-\u003epno.evt_id = evt_id;\n+\tpi-\u003epno.src_id = src_id;\n+\t/*\n+\t * Ensure the descriptor fields are visibile when the notifier block is\n+\t * made available\n+\t */\n+\tsmp_store_mb(pi-\u003epno.nb, nb);\n+\n+\treturn 0;\n+}\n+\n static const struct scmi_xfer_ops xfer_ops = {\n \t.xfer_get_init = xfer_get_init,\n \t.reset_rx_to_maxsz = reset_rx_to_maxsz,\n@@ -2072,6 +2097,25 @@ static void scmi_common_fastchannel_db_ring(struct scmi_fc_db_info *db)\n \t\tSCMI_PROTO_FC_RING_DB(64);\n }\n \n+static struct dentry *\n+scmi_debugfs_proto_dentry_get(const struct scmi_protocol_handle *ph)\n+{\n+\tstruct scmi_protocol_instance *pi = ph_to_pi(ph);\n+\tstruct scmi_info *info = handle_to_scmi_info(pi-\u003ehandle);\n+\n+\tif (!IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_PROTOCOLS) || !info-\u003edbg)\n+\t\treturn ERR_PTR(-ENODEV);\n+\n+\tif (!pi-\u003edbg) {\n+\t\tchar proto_dir[8];\n+\n+\t\tsnprintf(proto_dir, 8, \"0x%02X\", pi-\u003eproto-\u003eid);\n+\t\tpi-\u003edbg = debugfs_create_dir(proto_dir, info-\u003edbg-\u003eprotos);\n+\t}\n+\n+\treturn pi-\u003edbg;\n+}\n+\n static const struct scmi_proto_helpers_ops helpers_ops = {\n \t.extended_name_get = scmi_common_extended_name_get,\n \t.get_max_msg_size = scmi_common_get_max_msg_size,\n@@ -2082,6 +2126,7 @@ static const struct scmi_proto_helpers_ops helpers_ops = {\n \t.protocol_msg_check = scmi_protocol_msg_check,\n \t.fastchannel_init = scmi_common_fastchannel_init,\n \t.fastchannel_db_ring = scmi_common_fastchannel_db_ring,\n+\t.debugfs_proto_dentry_get = scmi_debugfs_proto_dentry_get,\n };\n \n /**\n@@ -2255,6 +2300,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,\n \tpi-\u003eph.hops = \u0026helpers_ops;\n \tpi-\u003eph.set_priv = scmi_set_protocol_priv;\n \tpi-\u003eph.get_priv = scmi_get_protocol_priv;\n+\tpi-\u003eph.instance_notifier_register = scmi_register_instance_notifier;\n \trefcount_set(\u0026pi-\u003eusers, 1);\n \n \t/*\n@@ -2293,6 +2339,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,\n \treturn pi;\n \n clean:\n+\tdebugfs_remove_recursive(pi-\u003edbg);\n \t/* Take care to put the protocol module's owner before releasing all */\n \tscmi_protocol_put(proto);\n \tdevres_release_group(handle-\u003edev, gid);\n@@ -2317,24 +2364,37 @@ static struct scmi_protocol_instance * __must_check\n scmi_get_protocol_instance(const struct scmi_handle *handle, u8 protocol_id)\n {\n \tstruct scmi_protocol_instance *pi;\n+\tstruct notifier_block *proto_notifier_nb = NULL;\n \tstruct scmi_info *info = handle_to_scmi_info(handle);\n \n-\tmutex_lock(\u0026info-\u003eprotocols_mtx);\n-\tpi = idr_find(\u0026info-\u003eprotocols, protocol_id);\n+\tscoped_guard(mutex, \u0026info-\u003eprotocols_mtx) {\n+\t\tpi = idr_find(\u0026info-\u003eprotocols, protocol_id);\n+\t\tif (pi) {\n+\t\t\trefcount_inc(\u0026pi-\u003eusers);\n+\t\t} else {\n+\t\t\tconst struct scmi_protocol *proto;\n \n-\tif (pi) {\n-\t\trefcount_inc(\u0026pi-\u003eusers);\n-\t} else {\n-\t\tconst struct scmi_protocol *proto;\n+\t\t\t/* Fails if protocol not registered on bus */\n+\t\t\tproto = scmi_protocol_get(protocol_id, \u0026info-\u003eversion);\n+\t\t\tif (!proto)\n+\t\t\t\treturn ERR_PTR(-EPROBE_DEFER);\n \n-\t\t/* Fails if protocol not registered on bus */\n-\t\tproto = scmi_protocol_get(protocol_id, \u0026info-\u003eversion);\n-\t\tif (proto)\n \t\t\tpi = scmi_alloc_init_protocol_instance(info, proto);\n-\t\telse\n-\t\t\tpi = ERR_PTR(-EPROBE_DEFER);\n+\t\t\tif (IS_ERR(pi))\n+\t\t\t\treturn pi;\n+\n+\t\t\tproto_notifier_nb = READ_ONCE(pi-\u003epno.nb);\n+\t\t}\n+\t}\n+\n+\tif (proto_notifier_nb) {\n+\t\tint ret;\n+\n+\t\tret = scmi_protocol_notifier_register(pi-\u003ehandle, \u0026pi-\u003epno);\n+\t\tif (ret)\n+\t\t\tdev_warn(handle-\u003edev,\n+\t\t\t\t \"Failed to register protocol notifier\\n\");\n \t}\n-\tmutex_unlock(\u0026info-\u003eprotocols_mtx);\n \n \treturn pi;\n }\n@@ -2365,16 +2425,34 @@ int scmi_protocol_acquire(const struct scmi_handle *handle, u8 protocol_id)\n void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id)\n {\n \tstruct scmi_info *info = handle_to_scmi_info(handle);\n+\tstruct notifier_block *proto_notifier_nb = NULL;\n \tstruct scmi_protocol_instance *pi;\n \n-\tmutex_lock(\u0026info-\u003eprotocols_mtx);\n-\tpi = idr_find(\u0026info-\u003eprotocols, protocol_id);\n-\tif (WARN_ON(!pi))\n-\t\tgoto out;\n+\tscoped_guard(mutex, \u0026info-\u003eprotocols_mtx) {\n+\t\tpi = idr_find(\u0026info-\u003eprotocols, protocol_id);\n+\t\tif (WARN_ON(!pi))\n+\t\t\treturn;\n \n+\t\tproto_notifier_nb = pi-\u003epno.nb;\n+\t\t/* Ensure NULL is visible */\n+\t\tsmp_store_mb(pi-\u003epno.nb, NULL);\n+\t}\n+\n+\tif (proto_notifier_nb) {\n+\t\tint ret;\n+\n+\t\tret = scmi_protocol_notifier_unregister(pi-\u003ehandle, \u0026pi-\u003epno);\n+\t\tif (ret)\n+\t\t\tdev_err(handle-\u003edev,\n+\t\t\t\t\"Failed to release protocol notifier\\n\");\n+\t}\n+\n+\tguard(mutex)(\u0026info-\u003eprotocols_mtx);\n \tif (refcount_dec_and_test(\u0026pi-\u003eusers)) {\n \t\tvoid *gid = pi-\u003egid;\n \n+\t\tdebugfs_remove_recursive(pi-\u003edbg);\n+\n \t\tif (pi-\u003eproto-\u003eevents)\n \t\t\tscmi_deregister_protocol_events(handle, protocol_id);\n \n@@ -2389,9 +2467,6 @@ void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id)\n \t\tdev_dbg(handle-\u003edev, \"De-Initialized protocol: 0x%X\\n\",\n \t\t\tprotocol_id);\n \t}\n-\n-out:\n-\tmutex_unlock(\u0026info-\u003eprotocols_mtx);\n }\n \n void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph,\n@@ -3100,6 +3175,9 @@ static struct scmi_debug_info *scmi_debugfs_common_setup(struct scmi_info *info)\n \tif (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_COUNTERS))\n \t\tscmi_debugfs_counters_setup(dbg, trans);\n \n+\tif (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_PROTOCOLS))\n+\t\tdbg-\u003eprotos = debugfs_create_dir(\"protocols\", top_dentry);\n+\n \tdbg-\u003etop_dentry = top_dentry;\n \n \tif (devm_add_action_or_reset(info-\u003edev,\n@@ -3252,6 +3330,7 @@ static int scmi_probe(struct platform_device *pdev)\n \tidr_init(\u0026info-\u003erx_idr);\n \n \thandle = \u0026info-\u003ehandle;\n+\thandle-\u003eid = info-\u003eid;\n \thandle-\u003edev = info-\u003edev;\n \thandle-\u003eversion = \u0026info-\u003eversion;\n \thandle-\u003edevm_protocol_acquire = scmi_devm_protocol_acquire;\n@@ -3532,6 +3611,7 @@ static int __init scmi_driver_init(void)\n \tscmi_system_register();\n \tscmi_powercap_register();\n \tscmi_pinctrl_register();\n+\tscmi_telemetry_register();\n \n \treturn platform_driver_register(\u0026scmi_driver);\n }\n@@ -3550,6 +3630,7 @@ static void __exit scmi_driver_exit(void)\n \tscmi_system_unregister();\n \tscmi_powercap_unregister();\n \tscmi_pinctrl_unregister();\n+\tscmi_telemetry_unregister();\n \n \tplatform_driver_unregister(\u0026scmi_driver);\n \ndiff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi/notify.c\nindex 0a192cf2deab62..938d575e22fe0d 100644\n--- a/drivers/firmware/arm_scmi/notify.c\n+++ b/drivers/firmware/arm_scmi/notify.c\n@@ -595,7 +595,13 @@ int scmi_notify(const struct scmi_handle *handle, u8 proto_id, u8 evt_id,\n \tif (!r_evt)\n \t\treturn -EINVAL;\n \n-\tif (len \u003e r_evt-\u003eevt-\u003emax_payld_sz) {\n+\t/*\n+\t * Events with a zero max_payld_sz are sized to be of the maximum\n+\t * size allowed by the transport: no need to be size-checked here\n+\t * since the transport layer would have already dropped such\n+\t * over-sized messages.\n+\t */\n+\tif (r_evt-\u003eevt-\u003emax_payld_sz \u0026\u0026 len \u003e r_evt-\u003eevt-\u003emax_payld_sz) {\n \t\tdev_err(handle-\u003edev, \"discard badly sized message\\n\");\n \t\treturn -EINVAL;\n \t}\n@@ -754,7 +760,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,\n \t\t\t\t  const struct scmi_protocol_handle *ph,\n \t\t\t\t  const struct scmi_protocol_events *ee)\n {\n-\tint i;\n+\tint i, max_msg_sz;\n \tunsigned int num_sources;\n \tsize_t payld_sz = 0;\n \tstruct scmi_registered_events_desc *pd;\n@@ -769,6 +775,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,\n \tif (!ni)\n \t\treturn -ENOMEM;\n \n+\tmax_msg_sz = ph-\u003ehops-\u003eget_max_msg_size(ph);\n+\n \t/* num_sources cannot be \u003c= 0 */\n \tif (ee-\u003enum_sources) {\n \t\tnum_sources = ee-\u003enum_sources;\n@@ -781,8 +789,13 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,\n \t}\n \n \tevt = ee-\u003eevts;\n-\tfor (i = 0; i \u003c ee-\u003enum_events; i++)\n-\t\tpayld_sz = max_t(size_t, payld_sz, evt[i].max_payld_sz);\n+\tfor (i = 0; i \u003c ee-\u003enum_events; i++) {\n+\t\tif (evt[i].max_payld_sz == 0) {\n+\t\t\tpayld_sz = max_msg_sz;\n+\t\t\tbreak;\n+\t\t}\n+\t\tpayld_sz = max(payld_sz, evt[i].max_payld_sz);\n+\t}\n \tpayld_sz += sizeof(struct scmi_event_header);\n \n \tpd = scmi_allocate_registered_events_desc(ni, proto_id, ee-\u003equeue_sz,\n@@ -811,7 +824,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,\n \t\tmutex_init(\u0026r_evt-\u003esources_mtx);\n \n \t\tr_evt-\u003ereport = devm_kzalloc(ni-\u003ehandle-\u003edev,\n-\t\t\t\t\t     evt-\u003emax_report_sz, GFP_KERNEL);\n+\t\t\t\t\t     evt-\u003emax_report_sz ?: max_msg_sz,\n+\t\t\t\t\t     GFP_KERNEL);\n \t\tif (!r_evt-\u003ereport)\n \t\t\treturn -ENOMEM;\n \n@@ -1406,6 +1420,13 @@ static int scmi_notifier_register(const struct scmi_handle *handle,\n \treturn ret;\n }\n \n+int scmi_protocol_notifier_register(const struct scmi_handle *handle,\n+\t\t\t\t    struct scmi_protocol_notifier *pno)\n+{\n+\treturn scmi_notifier_register(handle, pno-\u003eproto_id, pno-\u003eevt_id,\n+\t\t\t\t      pno-\u003esrc_id, pno-\u003enb);\n+}\n+\n /**\n  * scmi_notifier_unregister()  - Unregister a notifier_block for an event\n  * @handle: The handle identifying the platform instance against which the\n@@ -1463,6 +1484,13 @@ static int scmi_notifier_unregister(const struct scmi_handle *handle,\n \treturn 0;\n }\n \n+int scmi_protocol_notifier_unregister(const struct scmi_handle *handle,\n+\t\t\t\t      struct scmi_protocol_notifier *pno)\n+{\n+\treturn scmi_notifier_unregister(handle, pno-\u003eproto_id, pno-\u003eevt_id,\n+\t\t\t\t\tpno-\u003esrc_id, pno-\u003enb);\n+}\n+\n struct scmi_notifier_devres {\n \tconst struct scmi_handle *handle;\n \tu8 proto_id;\ndiff --git a/drivers/firmware/arm_scmi/notify.h b/drivers/firmware/arm_scmi/notify.h\nindex 76758a736cf47a..ecfa4b746487d3 100644\n--- a/drivers/firmware/arm_scmi/notify.h\n+++ b/drivers/firmware/arm_scmi/notify.h\n@@ -18,8 +18,12 @@\n /**\n  * struct scmi_event  - Describes an event to be supported\n  * @id: Event ID\n- * @max_payld_sz: Max possible size for the payload of a notification message\n- * @max_report_sz: Max possible size for the report of a notification message\n+ * @max_payld_sz: Max possible size for the payload of a notification message.\n+ *\t\t  Set to zero to use the maximum payload size allowed by the\n+ *\t\t  transport.\n+ * @max_report_sz: Max possible size for the report of a notification message.\n+ *\t\t  Set to zero to use the maximum payload size allowed by the\n+ *\t\t  transport.\n  *\n  * Each SCMI protocol, during its initialization phase, can describe the events\n  * it wishes to support in a few struct scmi_event and pass them to the core\ndiff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h\nindex 15ad5162e37a90..04e196a9fbf4af 100644\n--- a/drivers/firmware/arm_scmi/protocols.h\n+++ b/drivers/firmware/arm_scmi/protocols.h\n@@ -11,6 +11,7 @@\n \n #include \u003clinux/bitfield.h\u003e\n #include \u003clinux/completion.h\u003e\n+#include \u003clinux/debugfs.h\u003e\n #include \u003clinux/device.h\u003e\n #include \u003clinux/errno.h\u003e\n #include \u003clinux/kernel.h\u003e\n@@ -166,6 +167,13 @@ struct scmi_proto_helpers_ops;\n  *\t  can be used by the protocol implementation to generate SCMI messages.\n  * @set_priv: A method to set protocol private data for this instance.\n  * @get_priv: A method to get protocol private data previously set.\n+ * @instance_notifier_register: A method to register interest for specific\n+ *\t\t\t\tnotifications from within a protocol\n+ *\t\t\t\timplementation unit: ONLY one instance notifier\n+ *\t\t\t\tcan be registered per-protocol.\n+ *\t\t\t\tThe related notifier block will be registered\n+ *\t\t\t\tright after the protocol is initialized and\n+ *\t\t\t\tautomatically removed on protocol release.\n  *\n  * This structure represents a protocol initialized against specific SCMI\n  * instance and it will be used as follows:\n@@ -185,6 +193,9 @@ struct scmi_protocol_handle {\n \tconst struct scmi_proto_helpers_ops *hops;\n \tint (*set_priv)(const struct scmi_protocol_handle *ph, void *priv);\n \tvoid *(*get_priv)(const struct scmi_protocol_handle *ph);\n+\tint (*instance_notifier_register)(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\t  u8 evt_id, const u32 *src_id,\n+\t\t\t\t\t  struct notifier_block *nb);\n };\n \n /**\n@@ -274,6 +285,9 @@ struct scmi_fc_info {\n  *\t\t      gathering FC descriptions from the SCMI platform server.\n  * @fastchannel_db_ring: A common helper to ring a FC doorbell.\n  * @get_max_msg_size: A common helper to get the maximum message size.\n+ * @debugfs_proto_dentry_get: A common helper to get a per-protocol debugfs top\n+ *\t\t\t      directory to use as a root. It will be\n+ *\t\t\t      recursively removed on protocol de-initialization.\n  */\n struct scmi_proto_helpers_ops {\n \tint (*extended_name_get)(const struct scmi_protocol_handle *ph,\n@@ -297,6 +311,8 @@ struct scmi_proto_helpers_ops {\n \t\t\t\t u32 *rate_limit);\n \tvoid (*fastchannel_db_ring)(struct scmi_fc_db_info *db);\n \tint (*get_max_msg_size)(const struct scmi_protocol_handle *ph);\n+\tstruct dentry *(*debugfs_proto_dentry_get)\n+\t\t(const struct scmi_protocol_handle *ph);\n };\n \n /**\n@@ -391,5 +407,6 @@ DECLARE_SCMI_REGISTER_UNREGISTER(sensors);\n DECLARE_SCMI_REGISTER_UNREGISTER(voltage);\n DECLARE_SCMI_REGISTER_UNREGISTER(system);\n DECLARE_SCMI_REGISTER_UNREGISTER(powercap);\n+DECLARE_SCMI_REGISTER_UNREGISTER(telemetry);\n \n #endif /* _SCMI_PROTOCOLS_H */\ndiff --git a/drivers/firmware/arm_scmi/scmi_system_telemetry.c b/drivers/firmware/arm_scmi/scmi_system_telemetry.c\nnew file mode 100644\nindex 00000000000000..06042e37912d2e\n--- /dev/null\n+++ b/drivers/firmware/arm_scmi/scmi_system_telemetry.c\n@@ -0,0 +1,1135 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * SCMI - System Telemetry Driver\n+ *\n+ * Copyright (C) 2026 ARM Ltd.\n+ */\n+\n+#include \u003clinux/anon_inodes.h\u003e\n+#include \u003clinux/atomic.h\u003e\n+#include \u003clinux/ctype.h\u003e\n+#include \u003clinux/cdev.h\u003e\n+#include \u003clinux/device.h\u003e\n+#include \u003clinux/err.h\u003e\n+#include \u003clinux/fs.h\u003e\n+#include \u003clinux/list.h\u003e\n+#include \u003clinux/mm.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/overflow.h\u003e\n+#include \u003clinux/scmi_protocol.h\u003e\n+#include \u003clinux/slab.h\u003e\n+#include \u003clinux/sprintf.h\u003e\n+#include \u003clinux/string.h\u003e\n+#include \u003clinux/types.h\u003e\n+#include \u003clinux/uaccess.h\u003e\n+#include \u003clinux/wait.h\u003e\n+\n+#include \u003cuapi/linux/scmi.h\u003e\n+\n+#define SCMI_TLM_DRIVER\t\t\"scmi-telemetry-driver\"\n+#define SCMI_TLM_NUM_DEVS\t256\n+\n+#define MAX_BULK_LINE_CHAR_LENGTH\t\t64\n+\n+/*\n+ * Break if inadvertently struct scmi_telemetry_de_sample deviates from the\n+ * UAPI counterpart struct scmi_tlm_de_sample: this allows more performant\n+ * single DE reads.\n+ */\n+#define SCMI_DE_SAMPLE_BUILD_SANITY_CHECK\t\t\t\t  \\\n+({\t\t\t\t\t\t\t\t\t  \\\n+\tBUILD_BUG_ON_MSG(sizeof(struct scmi_telemetry_de_sample) !=\t  \\\n+\t\t\t sizeof(struct scmi_tlm_de_sample),\t\t  \\\n+\t\t\t \"UAPI DE sample mismatch !\");\t\t\t  \\\n+\tASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, id,\t  \\\n+\t\t\t     offsetof(struct scmi_tlm_de_sample, id));\t  \\\n+\tASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, pad,\t  \\\n+\t\t\t     offsetof(struct scmi_tlm_de_sample, pad));\t  \\\n+\tASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, tstamp,\t  \\\n+\t\t\t     offsetof(struct scmi_tlm_de_sample, tstamp));\\\n+\tASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, val,\t  \\\n+\t\t\t     offsetof(struct scmi_tlm_de_sample, val));\t  \\\n+})\n+\n+static dev_t stlm_devt;\n+\n+/**\n+ * struct scmi_tlm_setup  - Telemetry setup descriptor\n+ * @dev: A reference to the related device\n+ * @ph: A reference to the protocol handle to be used with the ops\n+ * @rinfo: A reference to the resource info descriptor\n+ * @ops: A reference to the protocol ops\n+ */\n+struct scmi_tlm_setup {\n+\tstruct device *dev;\n+\tstruct scmi_protocol_handle *ph;\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\tconst struct scmi_telemetry_proto_ops *ops;\n+};\n+\n+/**\n+ * struct scmi_tlm_instance  - Telemetry instance descriptor\n+ * @id: Progressive number identifying this probed instance.\n+ * @devt: The dev_t descriptor attached to this instance\n+ * @cdev:\n+ * @node: A node to link this in the list of all instances.\n+ * @tsp: A reference to the SCMI instance data.\n+ * @info: A reference to this instance SCMI Telemetry info data.\n+ */\n+struct scmi_tlm_instance {\n+\tunsigned int id;\n+\tdev_t devt;\n+\tstruct cdev cdev;\n+\tstruct list_head node;\n+\tstruct scmi_tlm_setup *tsp;\n+\tconst struct scmi_telemetry_info *info;\n+};\n+\n+#define to_instance(c)\tcontainer_of(c, struct scmi_tlm_instance, cdev)\n+\n+struct scmi_tlm_shmti_ctx {\n+\tstruct scmi_telemetry_shmti_info *shmti;\n+\tstruct kref kref;\n+};\n+\n+#define to_shmti_ctx(c)\tcontainer_of(c, struct scmi_tlm_shmti_ctx, kref)\n+\n+static inline void scmi_tlm_to_uapi_abi_info(struct scmi_tlm_abi_info *out,\n+\t\t\t\t\t     const struct scmi_telemetry_info *in)\n+{\n+\tu8 *impl_version = (u8 *)in-\u003ebase.de_impl_version;\n+\n+\tout-\u003esize = sizeof(*out);\n+\tout-\u003eabi_version = SCMI_TLM_CURRENT_ABI_VERSION;\n+\tout-\u003eabi_features = SCMI_TLM_ABI_FEAT_RESET;\n+\t/* Each word composing the UUID was stored in big-endian */\n+\tfor (int i = 0; i \u003c SCMI_TLM_DE_IMPL_UUID_MAX; i++)\n+\t\tout-\u003ede_impl_version[i] = impl_version[i];\n+\n+\tout-\u003enum_des = in-\u003ebase.num_des;\n+\tout-\u003enum_groups = in-\u003ebase.num_groups;\n+\tout-\u003enum_intervals = in-\u003ebase.num_intervals;\n+\tout-\u003enum_shmtis = in-\u003ebase.num_shmtis;\n+\tout-\u003efeatures = in-\u003ereset_support ? SCMI_TLM_BASE_SUPPORT_RESET : 0;\n+\tout-\u003efeatures |= in-\u003esingle_read_support ?\n+\t\tSCMI_TLM_BASE_SUPPORT_SINGLE_SAMPLE : 0;\n+\tout-\u003efeatures |= in-\u003eper_group_config_support ?\n+\t\tSCMI_TLM_BASE_SUPPORT_GROUP_CONFIG : 0;\n+\tout-\u003efeatures |= in-\u003econtinuos_update_support ?\n+\t\tSCMI_TLM_BASE_SUPPORT_UPDATE_NOTIFICATION : 0;\n+\tout-\u003ereserved = 0;\n+}\n+\n+static inline void\n+scmi_tlm_to_uapi_intervals(struct scmi_tlm_intervals *out,\n+\t\t\t   struct scmi_telemetry_intervals *in,\n+\t\t\t   struct scmi_tlm_update_interval *out_interv)\n+{\n+\tunsigned int *in_interv = in-\u003eupdate_intervals;\n+\n+\tout-\u003enum_intervals = 0;\n+\tfor (int i = 0; i \u003c in-\u003enum_intervals; i++) {\n+\t\tout_interv[i].secs =\n+\t\t\tSCMI_TLM_GET_UPDATE_INTERVAL_SECS(in_interv[i]);\n+\t\tout_interv[i].exp =\n+\t\t\tSCMI_TLM_GET_UPDATE_INTERVAL_EXP(in_interv[i]);\n+\n+\t\t/* Count returned items */\n+\t\tout-\u003enum_intervals++;\n+\t}\n+}\n+\n+static inline void scmi_tlm_to_uapi_de_info(struct scmi_tlm_de_info *out,\n+\t\t\t\t\t    struct scmi_telemetry_de_info *in)\n+{\n+\tout-\u003eid = in-\u003eid;\n+\tout-\u003egrp_id = in-\u003egrp_id;\n+\tout-\u003edata_sz = in-\u003edata_sz;\n+\tout-\u003etype = in-\u003etype;\n+\tout-\u003eunit = in-\u003eunit;\n+\tout-\u003eunit_exp = in-\u003eunit_exp;\n+\tout-\u003ets_rate = in-\u003ets_rate;\n+\tout-\u003einstance_id = in-\u003einstance_id;\n+\tout-\u003ecompo_instance_id = in-\u003ecompo_instance_id;\n+\tout-\u003ecompo_type = in-\u003ecompo_type;\n+\tout-\u003epersistent = !!in-\u003epersistent;\n+\tout-\u003eflags = in-\u003egrp_id != SCMI_TLM_GRP_INVALID ?\n+\t\tSCMI_TLM_DEINFO_GROUP : 0;\n+\tout-\u003epad[0] = 0;\n+\tout-\u003epad[1] = 0;\n+\tout-\u003epad2 = 0;\n+\tmemcpy(out-\u003ename, in-\u003ename, 16);\n+}\n+\n+static inline void\n+scmi_tlm_to_uapi_des_list(struct scmi_tlm_des_list *out,\n+\t\t\t  const struct scmi_telemetry_res_info *in,\n+\t\t\t  struct scmi_tlm_de_info *des)\n+{\n+\tout-\u003enum_des = 0;\n+\tfor (int i = 0; i \u003c in-\u003enum_des; i++) {\n+\t\tscmi_tlm_to_uapi_de_info(\u0026des[i], \u0026in-\u003edei_store[i]);\n+\n+\t\t/* Count returned items */\n+\t\tout-\u003enum_des++;\n+\t}\n+}\n+\n+static inline void scmi_tlm_to_uapi_grp_info(struct scmi_tlm_grp_info *out,\n+\t\t\t\t\t     struct scmi_telemetry_grp_info *in)\n+{\n+\tout-\u003egrp_id = in-\u003egrp_id;\n+\tout-\u003enum_des = in-\u003enum_des;\n+\tout-\u003enum_intervals = in-\u003enum_intervals;\n+\tout-\u003epad = 0;\n+}\n+\n+static inline void\n+scmi_tlm_to_uapi_grps_list(struct scmi_tlm_grps_list *out,\n+\t\t\t   const struct scmi_telemetry_res_info *in,\n+\t\t\t   struct scmi_tlm_grp_info *ginfo)\n+{\n+\tstruct scmi_tlm_grp_info *out_ginfo = ginfo;\n+\n+\tout-\u003enum_grps = 0;\n+\tfor (int i = 0; i \u003c in-\u003enum_groups; i++) {\n+\t\tscmi_tlm_to_uapi_grp_info(\u0026out_ginfo[i], \u0026in-\u003egrps_store[i]);\n+\n+\t\t/* Count returned items */\n+\t\tout-\u003enum_grps++;\n+\t}\n+}\n+\n+static inline void\n+scmi_tlm_to_uapi_composing_des(struct scmi_tlm_grp_desc *out,\n+\t\t\t       const struct scmi_telemetry_res_info *in,\n+\t\t\t       u32 *composing_des)\n+{\n+\tstruct scmi_telemetry_grp_info *ginfo = \u0026in-\u003egrps_store[out-\u003egrp_id];\n+\tstruct scmi_telemetry_group *grp = \u0026in-\u003egrps[out-\u003egrp_id];\n+\n+\tout-\u003enum_des = 0;\n+\tfor (int i = 0; i \u003c ginfo-\u003enum_des; i++) {\n+\t\tcomposing_des[i] = in-\u003edes[grp-\u003edes[i]]-\u003einfo-\u003eid;\n+\n+\t\t/* Count returned items */\n+\t\tout-\u003enum_des++;\n+\t}\n+}\n+\n+/**\n+ * scmi_telemetry_res_info_get  - Resources info getter\n+ * @tsp: A reference to the telemetry instance setup\n+ *\n+ * On first call this helper takes care to retrieve and cache all the resources\n+ * descriptor from the platform, then, on the following invocations it will\n+ * always return the cached value.\n+ */\n+static inline const struct scmi_telemetry_res_info *\n+scmi_telemetry_res_info_get(struct scmi_tlm_setup *tsp)\n+{\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\n+\tif (READ_ONCE(tsp-\u003erinfo))\n+\t\treturn tsp-\u003erinfo;\n+\n+\trinfo = tsp-\u003eops-\u003eres_get(tsp-\u003eph);\n+\t/* Cache the retrieved resource info value */\n+\tsmp_store_mb(tsp-\u003erinfo, rinfo);\n+\n+\treturn rinfo;\n+}\n+\n+static long\n+scmi_tlm_abi_info_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tstruct scmi_tlm_abi_info base = {};\n+\tvoid __user *uptr = (void __user *)arg;\n+\tbool ignored_trailing;\n+\tu32 usize;\n+\tint err;\n+\n+\tif (get_user(usize, (u32 __user *)arg))\n+\t\treturn -EFAULT;\n+\n+\tif (usize \u003c offsetofend(struct scmi_tlm_abi_info, reserved))\n+\t\treturn -EINVAL;\n+\n+\tif (copy_struct_from_user(\u0026base, sizeof(base), uptr, usize))\n+\t\treturn -EFAULT;\n+\n+\tscmi_tlm_to_uapi_abi_info(\u0026base, ti-\u003einfo);\n+\terr = copy_struct_to_user(uptr, usize, \u0026base, sizeof(base),\n+\t\t\t\t  \u0026ignored_trailing);\n+\tif (err)\n+\t\treturn err;\n+\n+\tif (ignored_trailing)\n+\t\treturn -EMSGSIZE;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_config_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_config cfg;\n+\n+\tif (copy_from_user(\u0026cfg, uptr, sizeof(cfg)))\n+\t\treturn -EFAULT;\n+\n+\tif (cfg.pad || cfg.flags \u0026 ~SCMI_TLM_CONFIG_FLAGS)\n+\t\treturn -EINVAL;\n+\n+\tif (!(SCMI_TLM_CONFIG_IS_GROUP(cfg.flags))) {\n+\t\tunsigned int active = ti-\u003einfo-\u003eactive_update_interval;\n+\n+\t\tcfg.enable = !!ti-\u003einfo-\u003eenabled;\n+\t\tcfg.active.secs = SCMI_TLM_GET_UPDATE_INTERVAL_SECS(active);\n+\t\tcfg.active.exp = SCMI_TLM_GET_UPDATE_INTERVAL_EXP(active);\n+\t} else {\n+\t\tconst struct scmi_telemetry_res_info *rinfo;\n+\t\tstruct scmi_telemetry_group *grp;\n+\t\tunsigned int active;\n+\n+\t\trinfo = scmi_telemetry_res_info_get(ti-\u003etsp);\n+\t\tif (cfg.grp_id \u003e= rinfo-\u003enum_groups)\n+\t\t\treturn -EINVAL;\n+\n+\t\tgrp = \u0026rinfo-\u003egrps[cfg.grp_id];\n+\t\tactive = grp-\u003eactive_update_interval;\n+\n+\t\tcfg.enable = grp-\u003eenabled;\n+\t\tcfg.t_enable = grp-\u003etstamp_enabled;\n+\t\tcfg.active.secs = SCMI_TLM_GET_UPDATE_INTERVAL_SECS(active);\n+\t\tcfg.active.exp = SCMI_TLM_GET_UPDATE_INTERVAL_EXP(active);\n+\t}\n+\n+\tif (copy_to_user(uptr, \u0026cfg, sizeof(cfg)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_config_set_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tstruct scmi_tlm_config cfg;\n+\tunsigned int active;\n+\tbool ena, t_ena;\n+\n+\tif (copy_from_user(\u0026cfg, uptr, sizeof(cfg)))\n+\t\treturn -EFAULT;\n+\n+\tif (cfg.pad || cfg.flags \u0026 ~SCMI_TLM_CONFIG_FLAGS)\n+\t\treturn -EINVAL;\n+\n+\tena = !!cfg.enable;\n+\tt_ena = !!cfg.t_enable;\n+\tif (!SCMI_TLM_CONFIG_IS_GROUP(cfg.flags)) {\n+\t\tcfg.grp_id = SCMI_TLM_GRP_INVALID;\n+\t} else {\n+\t\tint ret;\n+\n+\t\tret = tsp-\u003eops-\u003estate_set(tsp-\u003eph, true, cfg.grp_id, \u0026ena, \u0026t_ena);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tactive = SCMI_TLM_BUILD_UPDATE_INTERVAL(cfg.active.secs, cfg.active.exp);\n+\n+\treturn tsp-\u003eops-\u003ecollection_configure(tsp-\u003eph, cfg.grp_id, \u0026ena, \u0026active, NULL);\n+}\n+\n+static long\n+scmi_tlm_intervals_get_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t     unsigned long arg)\n+{\n+\tstruct scmi_telemetry_intervals *tlm_ivs;\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_intervals ivs;\n+\tsize_t ivs_intrv_sz;\n+\n+\tif (copy_from_user(\u0026ivs, uptr, sizeof(ivs)))\n+\t\treturn -EFAULT;\n+\n+\tif (ivs.pad[0] || ivs.pad[1] || ivs.pad[2] || ivs.pad2 ||\n+\t    ivs.flags \u0026 ~SCMI_TLM_INTERV_FLAGS)\n+\t\treturn -EINVAL;\n+\n+\tif (!SCMI_TLM_INTERV_IS_GROUP(ivs.flags)) {\n+\t\ttlm_ivs = ti-\u003einfo-\u003eintervals;\n+\t} else {\n+\t\tconst struct scmi_telemetry_res_info *rinfo;\n+\n+\t\trinfo = scmi_telemetry_res_info_get(ti-\u003etsp);\n+\t\tif (ivs.grp_id \u003e= rinfo-\u003enum_groups)\n+\t\t\treturn -EINVAL;\n+\n+\t\ttlm_ivs = rinfo-\u003egrps[ivs.grp_id].intervals;\n+\t}\n+\n+\t/* Reject only undersized buffers */\n+\tif (ivs.num_intervals \u003c tlm_ivs-\u003enum_intervals)\n+\t\treturn -ENOSPC;\n+\n+\t/* A local scratch buffer... */\n+\tivs_intrv_sz = ivs.num_intervals * sizeof(struct scmi_tlm_update_interval);\n+\tstruct scmi_tlm_update_interval *ivs_intrv __free(kfree) =\n+\t\tkzalloc(ivs_intrv_sz, GFP_KERNEL);\n+\tif (!ivs_intrv)\n+\t\treturn -ENOMEM;\n+\n+\tif (copy_from_user(ivs_intrv, u64_to_user_ptr(ivs.intervals),\n+\t\t\t   ivs_intrv_sz))\n+\t\treturn -EFAULT;\n+\n+\t/* Passing the array as a param avoids dancing with uptr-\u003eintervals */\n+\tscmi_tlm_to_uapi_intervals(\u0026ivs, tlm_ivs, ivs_intrv);\n+\tif (copy_to_user(u64_to_user_ptr(ivs.intervals),\n+\t\t\t (void *)ivs_intrv, ivs_intrv_sz))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026ivs, sizeof(ivs)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_de_config_set_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t     unsigned long arg, bool all)\n+{\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tstruct scmi_tlm_de_config tcfg;\n+\tbool ena, t_ena;\n+\tint ret;\n+\n+\tif (copy_from_user(\u0026tcfg, uptr, sizeof(tcfg)))\n+\t\treturn -EFAULT;\n+\n+\tif (tcfg.pad)\n+\t\treturn -EINVAL;\n+\n+\tena = !!tcfg.enable;\n+\tt_ena = !!tcfg.t_enable;\n+\tif (!all)\n+\t\treturn tsp-\u003eops-\u003estate_set(tsp-\u003eph, false, tcfg.id, \u0026ena, \u0026t_ena);\n+\n+\trinfo = scmi_telemetry_res_info_get(tsp);\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_des; i++) {\n+\t\tret = tsp-\u003eops-\u003estate_set(tsp-\u003eph, false,\n+\t\t\t\t\t  rinfo-\u003edes[i]-\u003einfo-\u003eid, \u0026ena, \u0026t_ena);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_de_config_get_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t     unsigned long arg, bool all)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tstruct scmi_tlm_de_config tcfg;\n+\tbool ena, t_ena;\n+\tint ret;\n+\n+\tif (copy_from_user(\u0026tcfg, uptr, sizeof(tcfg)))\n+\t\treturn -EFAULT;\n+\n+\tif (tcfg.pad)\n+\t\treturn -EINVAL;\n+\n+\tena = !!tcfg.enable;\n+\tt_ena = !!tcfg.t_enable;\n+\tret = tsp-\u003eops-\u003estate_get(tsp-\u003eph, all ? NULL : \u0026tcfg.id, \u0026ena, \u0026t_ena);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\ttcfg.enable = ena;\n+\ttcfg.t_enable = t_ena;\n+\tif (copy_to_user(uptr, \u0026tcfg, sizeof(tcfg)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_de_info_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tconst struct scmi_telemetry_de *de;\n+\tstruct scmi_tlm_de_info dei;\n+\n+\tif (copy_from_user(\u0026dei, uptr, sizeof(dei)))\n+\t\treturn -EFAULT;\n+\n+\t/* Flags does NOT make sense in the input param */\n+\tif (dei.pad[0] || dei.pad[1] || dei.flags)\n+\t\treturn -EINVAL;\n+\n+\tde = tsp-\u003eops-\u003ede_lookup(tsp-\u003eph, dei.id);\n+\tif (!de)\n+\t\treturn -EINVAL;\n+\n+\tscmi_tlm_to_uapi_de_info(\u0026dei, de-\u003einfo);\n+\tif (copy_to_user(uptr, \u0026dei, sizeof(dei)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_des_list_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_des_list dsl;\n+\tsize_t dsl_des_sz;\n+\n+\tif (copy_from_user(\u0026dsl, uptr, sizeof(dsl)))\n+\t\treturn -EFAULT;\n+\n+\tif (dsl.pad)\n+\t\treturn -EINVAL;\n+\n+\trinfo = scmi_telemetry_res_info_get(ti-\u003etsp);\n+\t/* Reject only undersized buffers */\n+\tif (dsl.num_des \u003c rinfo-\u003enum_des)\n+\t\treturn -ENOSPC;\n+\n+\t/* A local scratch buffer... */\n+\tdsl_des_sz = dsl.num_des * sizeof(struct scmi_tlm_de_info);\n+\tstruct scmi_tlm_de_info *dsl_des __free(kfree) =\n+\t\tkzalloc(dsl_des_sz, GFP_KERNEL);\n+\tif (!dsl_des)\n+\t\treturn -ENOMEM;\n+\n+\tif (copy_from_user(dsl_des, u64_to_user_ptr(dsl.des), dsl_des_sz))\n+\t\treturn -EFAULT;\n+\n+\t/* Passing the array as a param avoids dancing with uptr-\u003eintervals */\n+\tscmi_tlm_to_uapi_des_list(\u0026dsl, rinfo, dsl_des);\n+\tif (copy_to_user(u64_to_user_ptr(dsl.des), (void *)dsl_des, dsl_des_sz))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026dsl, sizeof(dsl)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_de_value_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tstruct scmi_tlm_de_sample sample;\n+\tint ret;\n+\n+\tSCMI_DE_SAMPLE_BUILD_SANITY_CHECK;\n+\n+\tif (copy_from_user(\u0026sample, uptr, sizeof(sample)))\n+\t\treturn -EFAULT;\n+\n+\tif (sample.pad)\n+\t\treturn -EINVAL;\n+\n+\tret = tsp-\u003eops-\u003ede_data_read(tsp-\u003eph,\n+\t\t\t\t     (struct scmi_telemetry_de_sample *)\u0026sample);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (copy_to_user(uptr, \u0026sample, sizeof(sample)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_grp_info_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_grp_info ginfo;\n+\n+\tif (copy_from_user(\u0026ginfo, uptr, sizeof(ginfo)))\n+\t\treturn -EFAULT;\n+\n+\tif (ginfo.pad)\n+\t\treturn -EINVAL;\n+\n+\trinfo = scmi_telemetry_res_info_get(ti-\u003etsp);\n+\tif (ginfo.grp_id \u003e= rinfo-\u003enum_groups)\n+\t\treturn -EINVAL;\n+\n+\tscmi_tlm_to_uapi_grp_info(\u0026ginfo, \u0026rinfo-\u003egrps_store[ginfo.grp_id]);\n+\tif (copy_to_user(uptr, \u0026ginfo, sizeof(ginfo)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_grp_desc_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_grp_desc gdesc;\n+\tsize_t composing_sz;\n+\n+\tif (copy_from_user(\u0026gdesc, uptr, sizeof(gdesc)))\n+\t\treturn -EFAULT;\n+\n+\trinfo = scmi_telemetry_res_info_get(ti-\u003etsp);\n+\tif (gdesc.grp_id \u003e= rinfo-\u003enum_groups)\n+\t\treturn -EINVAL;\n+\n+\t/* Reject only undersized buffers */\n+\tif (gdesc.num_des \u003c rinfo-\u003egrps_store[gdesc.grp_id].num_des)\n+\t\treturn -ENOSPC;\n+\n+\t/* A local scratch buffer... */\n+\tcomposing_sz = gdesc.num_des * sizeof(u32);\n+\tu32 *composing_des __free(kfree) = kzalloc(composing_sz, GFP_KERNEL);\n+\tif (!composing_des)\n+\t\treturn -ENOMEM;\n+\n+\tif (copy_from_user(composing_des, u64_to_user_ptr(gdesc.composing_des),\n+\t\t\t   composing_sz))\n+\t\treturn -EFAULT;\n+\n+\t/* Passing the array as a param avoids dancing with uptr-\u003eintervals */\n+\tscmi_tlm_to_uapi_composing_des(\u0026gdesc, rinfo, composing_des);\n+\tif (copy_to_user(u64_to_user_ptr(gdesc.composing_des), composing_des,\n+\t\t\t composing_sz))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026gdesc, sizeof(gdesc)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long\n+scmi_tlm_grps_list_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)\n+{\n+\tconst struct scmi_telemetry_res_info *rinfo;\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_grps_list gsl;\n+\tsize_t ginfo_sz;\n+\n+\tif (copy_from_user(\u0026gsl, uptr, sizeof(gsl)))\n+\t\treturn -EFAULT;\n+\n+\tif (gsl.pad)\n+\t\treturn -EINVAL;\n+\n+\trinfo = scmi_telemetry_res_info_get(ti-\u003etsp);\n+\t/* Reject only undersized buffers */\n+\tif (gsl.num_grps \u003c rinfo-\u003enum_groups)\n+\t\treturn -ENOSPC;\n+\n+\t/* A local scratch buffer... */\n+\tginfo_sz = gsl.num_grps * sizeof(struct scmi_tlm_grp_info);\n+\tstruct scmi_tlm_grp_info *ginfo __free(kfree) =\n+\t\tkzalloc(ginfo_sz, GFP_KERNEL);\n+\tif (!ginfo)\n+\t\treturn -ENOMEM;\n+\n+\tif (copy_from_user(ginfo, u64_to_user_ptr(gsl.grps), ginfo_sz))\n+\t\treturn -EFAULT;\n+\n+\tscmi_tlm_to_uapi_grps_list(\u0026gsl, rinfo, ginfo);\n+\tif (copy_to_user(u64_to_user_ptr(gsl.grps), ginfo, ginfo_sz))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026gsl, sizeof(gsl)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long scmi_tlm_des_read_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t\t    unsigned long arg, bool single)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tstruct scmi_tlm_data_read bulk;\n+\tunsigned int grp_id;\n+\tint ret;\n+\n+\tif (copy_from_user(\u0026bulk, uptr, sizeof(bulk)))\n+\t\treturn -EFAULT;\n+\n+\tif (bulk.pad[0] || bulk.pad[1] || bulk.pad[2] || bulk.pad2 ||\n+\t    bulk.flags \u0026 ~SCMI_TLM_READ_FLAGS)\n+\t\treturn -EINVAL;\n+\n+\tif (!SCMI_TLM_READ_IS_GROUP(bulk.flags)) {\n+\t\tgrp_id = SCMI_TLM_GRP_INVALID;\n+\t} else {\n+\t\tconst struct scmi_telemetry_res_info *rinfo;\n+\n+\t\trinfo = scmi_telemetry_res_info_get(tsp);\n+\t\tif (bulk.grp_id \u003e= rinfo-\u003enum_groups)\n+\t\t\treturn -EINVAL;\n+\n+\t\tgrp_id = bulk.grp_id;\n+\t}\n+\n+\tstruct scmi_telemetry_de_sample *samples __free(kfree) =\n+\t\tkcalloc(bulk.num_samples, sizeof(*samples), GFP_KERNEL);\n+\tif (!samples)\n+\t\treturn -ENOMEM;\n+\n+\tif (!single)\n+\t\tret = tsp-\u003eops-\u003edes_bulk_read(tsp-\u003eph, grp_id,\n+\t\t\t\t\t      \u0026bulk.num_samples, samples);\n+\telse\n+\t\tret = tsp-\u003eops-\u003edes_sample_get(tsp-\u003eph, grp_id,\n+\t\t\t\t\t       \u0026bulk.num_samples, samples);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (copy_to_user(u64_to_user_ptr(bulk.samples), samples,\n+\t\t\t bulk.num_samples * sizeof(*samples)))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026bulk, sizeof(bulk)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long scmi_tlm_des_batch_read_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t\t\t  unsigned long arg)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_setup *tsp = ti-\u003etsp;\n+\tstruct scmi_tlm_data_read batch;\n+\n+\tif (copy_from_user(\u0026batch, uptr, sizeof(batch)))\n+\t\treturn -EFAULT;\n+\n+\tif (batch.pad[0] || batch.pad[1] || batch.pad[2] || batch.pad2 ||\n+\t    batch.flags \u0026 ~SCMI_TLM_READ_FLAGS)\n+\t\treturn -EINVAL;\n+\n+\tstruct scmi_telemetry_de_sample *samples __free(kfree) =\n+\t\tkcalloc(batch.num_samples, sizeof(*samples), GFP_KERNEL);\n+\tif (!samples)\n+\t\treturn -ENOMEM;\n+\n+\t/* Read all the requested samples */\n+\tif (copy_from_user(samples, u64_to_user_ptr(batch.samples),\n+\t\t\t   batch.num_samples * sizeof(*samples)))\n+\t\treturn -EFAULT;\n+\n+\tfor (int i = 0; i \u003c batch.num_samples; i++) {\n+\t\tint ret;\n+\n+\t\tret = tsp-\u003eops-\u003ede_data_read(tsp-\u003eph, \u0026samples[i]);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tif (copy_to_user(u64_to_user_ptr(batch.samples), samples,\n+\t\t\t batch.num_samples * sizeof(*samples)))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026batch, sizeof(batch)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static struct scmi_tlm_shmti_ctx *\n+scmi_tlm_shmti_ctx_alloc(struct scmi_telemetry_shmti_info *shmti)\n+{\n+\tstruct scmi_tlm_shmti_ctx *ctx;\n+\n+\tctx = kzalloc_obj(*ctx);\n+\tif (!ctx)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tctx-\u003eshmti = shmti;\n+\tkref_init(\u0026ctx-\u003ekref);\n+\n+\treturn ctx;\n+}\n+\n+static void scmi_tlm_shmti_ctx_release(struct kref *kref)\n+{\n+\tstruct scmi_tlm_shmti_ctx *ctx = to_shmti_ctx(kref);\n+\n+\tkfree(ctx);\n+}\n+\n+static struct scmi_tlm_shmti_ctx *\n+scmi_tlm_shmti_ctx_get(struct scmi_tlm_shmti_ctx *ctx)\n+{\n+\tkref_get(\u0026ctx-\u003ekref);\n+\n+\treturn ctx;\n+}\n+\n+static void scmi_tlm_shmti_ctx_put(struct scmi_tlm_shmti_ctx *ctx)\n+{\n+\tkref_put(\u0026ctx-\u003ekref, scmi_tlm_shmti_ctx_release);\n+}\n+\n+static void scmi_tlm_shmti_vma_open(struct vm_area_struct *vma)\n+{\n+\tscmi_tlm_shmti_ctx_get(vma-\u003evm_private_data);\n+}\n+\n+static void scmi_tlm_shmti_vma_close(struct vm_area_struct *vma)\n+{\n+\tscmi_tlm_shmti_ctx_put(vma-\u003evm_private_data);\n+}\n+\n+static const struct vm_operations_struct scmi_tlm_shmti_vm_ops = {\n+\t.open = scmi_tlm_shmti_vma_open,\n+\t.close = scmi_tlm_shmti_vma_close,\n+};\n+\n+static int scmi_tlm_shmti_mmap(struct file *filp, struct vm_area_struct *vma)\n+{\n+\tstruct scmi_tlm_shmti_ctx *ctx = filp-\u003eprivate_data;\n+\tunsigned long npages, expect, needed, req = vma-\u003evm_end - vma-\u003evm_start;\n+\tphys_addr_t base;\n+\tsize_t map_sz;\n+\tint ret;\n+\n+\tif (vma-\u003evm_flags \u0026 VM_WRITE)\n+\t\treturn -EPERM;\n+\n+\tif (req \u003c ctx-\u003eshmti-\u003elen)\n+\t\treturn -EINVAL;\n+\n+\t/* Align \u0026 reject oversized requests */\n+\tbase = ctx-\u003eshmti-\u003ephys \u0026 PAGE_MASK;\n+\tneeded = ctx-\u003eshmti-\u003elen + ctx-\u003eshmti-\u003eoffset;\n+\texpect = DIV_ROUND_UP(needed, PAGE_SIZE);\n+\tnpages = req \u003e\u003e PAGE_SHIFT;\n+\tif (npages \u003e expect)\n+\t\treturn -EINVAL;\n+\n+\tmap_sz = PAGE_ALIGN(needed);\n+\tvma-\u003evm_private_data = scmi_tlm_shmti_ctx_get(ctx);\n+\tvma-\u003evm_ops = \u0026scmi_tlm_shmti_vm_ops;\n+\t/* Set appropriate caching attributes */\n+\tvma-\u003evm_page_prot = pgprot_noncached(vma-\u003evm_page_prot);\n+\n+\t/* Map physical address range into user space */\n+\tret = vm_iomap_memory(vma, base, map_sz);\n+\tif (ret) {\n+\t\tscmi_tlm_shmti_ctx_put(ctx);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int scmi_tlm_shmti_release(struct inode *ino, struct file *filp)\n+{\n+\tscmi_tlm_shmti_ctx_put(filp-\u003eprivate_data);\n+\n+\treturn 0;\n+}\n+\n+static const struct file_operations scmi_tlm_shmti_fops = {\n+\t.owner = THIS_MODULE,\n+\t.mmap = scmi_tlm_shmti_mmap,\n+\t.release = scmi_tlm_shmti_release,\n+};\n+\n+static void\n+scmi_tlm_allocate_anon_fds(const struct scmi_tlm_instance *ti,\n+\t\t\t   struct scmi_tlm_shmtis_list *out,\n+\t\t\t   struct scmi_tlm_shmti_info *shinfo)\n+{\n+\tconst struct scmi_telemetry_info *info = ti-\u003einfo;\n+\tstruct device *dev = ti-\u003etsp-\u003edev;\n+\tint idx = 0;\n+\n+\tout-\u003enum_shmtis = 0;\n+\tfor (int i = 0; i \u003c info-\u003ebase.num_shmtis; i++) {\n+\t\tstruct scmi_telemetry_shmti_info *shmti = info-\u003eshmtis[i];\n+\t\tstruct scmi_tlm_shmti_ctx *ctx;\n+\t\tint fd;\n+\n+\t\tctx = scmi_tlm_shmti_ctx_alloc(shmti);\n+\t\tif (IS_ERR(ctx)) {\n+\t\t\tdev_err(dev, \"Failed CTX_ALLOC on SID: %u\\n\", shmti-\u003esid);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tfd = anon_inode_getfd(SCMI_TLM_DRIVER, \u0026scmi_tlm_shmti_fops, ctx,\n+\t\t\t\t      O_RDONLY | O_CLOEXEC);\n+\t\tif (fd \u003c 0) {\n+\t\t\tscmi_tlm_shmti_ctx_put(ctx);\n+\t\t\tdev_err(dev, \"Failed ANON INODE on SID: %u\\n\", shmti-\u003esid);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tshinfo[idx].sid = shmti-\u003esid;\n+\t\tshinfo[idx].fd = fd;\n+\t\tshinfo[idx].len = shmti-\u003elen;\n+\t\tshinfo[idx].offset = shmti-\u003eoffset;\n+\n+\t\t/* Count returned items */\n+\t\tout-\u003enum_shmtis++;\n+\t\tidx++;\n+\t}\n+}\n+\n+static long\n+scmi_tlm_shmtis_list_get_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t       unsigned long arg)\n+{\n+\tvoid __user *uptr = (void __user *)arg;\n+\tstruct scmi_tlm_shmtis_list ssl;\n+\tsize_t shinfo_sz;\n+\n+\tif (copy_from_user(\u0026ssl, uptr, sizeof(ssl)))\n+\t\treturn -EFAULT;\n+\n+\tif (ssl.pad)\n+\t\treturn -EINVAL;\n+\n+\t/* Reject only undersized buffers */\n+\tif (ssl.num_shmtis \u003c ti-\u003einfo-\u003ebase.num_shmtis)\n+\t\treturn -ENOSPC;\n+\n+\t/* A local scratch buffer... */\n+\tshinfo_sz = ssl.num_shmtis * sizeof(struct scmi_tlm_shmti_info);\n+\tstruct scmi_tlm_shmti_info *shinfo __free(kfree) =\n+\t\tkzalloc(shinfo_sz, GFP_KERNEL);\n+\tif (!shinfo)\n+\t\treturn -ENOMEM;\n+\n+\tif (copy_from_user(shinfo, u64_to_user_ptr(ssl.shmtis), shinfo_sz))\n+\t\treturn -EFAULT;\n+\n+\tscmi_tlm_allocate_anon_fds(ti, \u0026ssl, shinfo);\n+\tif (copy_to_user(u64_to_user_ptr(ssl.shmtis), shinfo, shinfo_sz))\n+\t\treturn -EFAULT;\n+\n+\tif (copy_to_user(uptr, \u0026ssl, sizeof(ssl)))\n+\t\treturn -EFAULT;\n+\n+\treturn 0;\n+}\n+\n+static long scmi_tlm_reset_ioctl(const struct scmi_tlm_instance *ti,\n+\t\t\t\t unsigned long arg)\n+{\n+\treturn ti-\u003etsp-\u003eops-\u003ereset(ti-\u003etsp-\u003eph);\n+}\n+\n+static long scmi_tlm_unlocked_ioctl(struct file *filp, unsigned int cmd,\n+\t\t\t\t    unsigned long arg)\n+{\n+\tstruct inode *ino = file_inode(filp);\n+\tstruct scmi_tlm_instance *ti = to_instance(ino-\u003ei_cdev);\n+\n+\tswitch (cmd) {\n+\tcase SCMI_TLM_GET_ABI_INFO:\n+\t\treturn scmi_tlm_abi_info_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_CFG:\n+\t\treturn scmi_tlm_config_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_SET_CFG:\n+\t\treturn scmi_tlm_config_set_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_INTRVS:\n+\t\treturn scmi_tlm_intervals_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_DE_CFG:\n+\t\treturn scmi_tlm_de_config_get_ioctl(ti, arg, false);\n+\tcase SCMI_TLM_SET_DE_CFG:\n+\t\treturn scmi_tlm_de_config_set_ioctl(ti, arg, false);\n+\tcase SCMI_TLM_GET_DE_INFO:\n+\t\treturn scmi_tlm_de_info_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_DE_LIST:\n+\t\treturn scmi_tlm_des_list_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_DE_READ:\n+\t\treturn scmi_tlm_de_value_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_ALL_CFG:\n+\t\treturn scmi_tlm_de_config_get_ioctl(ti, arg, true);\n+\tcase SCMI_TLM_SET_ALL_CFG:\n+\t\treturn scmi_tlm_de_config_set_ioctl(ti, arg, true);\n+\tcase SCMI_TLM_GET_GRP_LIST:\n+\t\treturn scmi_tlm_grps_list_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_GRP_INFO:\n+\t\treturn scmi_tlm_grp_info_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_GRP_DESC:\n+\t\treturn scmi_tlm_grp_desc_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_SINGLE_READ:\n+\t\treturn scmi_tlm_des_read_ioctl(ti, arg, true);\n+\tcase SCMI_TLM_BULK_READ:\n+\t\treturn scmi_tlm_des_read_ioctl(ti, arg, false);\n+\tcase SCMI_TLM_BATCH_READ:\n+\t\treturn scmi_tlm_des_batch_read_ioctl(ti, arg);\n+\tcase SCMI_TLM_GET_SHMTI_LIST:\n+\t\treturn scmi_tlm_shmtis_list_get_ioctl(ti, arg);\n+\tcase SCMI_TLM_RESET:\n+\t\treturn scmi_tlm_reset_ioctl(ti, arg);\n+\tdefault:\n+\t\treturn -ENOTTY;\n+\t}\n+}\n+\n+static const struct file_operations stlm_fops = {\n+\t.owner = THIS_MODULE,\n+\t.open = nonseekable_open,\n+\t.unlocked_ioctl = scmi_tlm_unlocked_ioctl,\n+\t.compat_ioctl = compat_ptr_ioctl,\n+};\n+\n+static struct scmi_tlm_instance *scmi_tlm_init(struct scmi_tlm_setup *tsp,\n+\t\t\t\t\t       unsigned int instance_id)\n+{\n+\tstruct device *dev = tsp-\u003edev;\n+\tstruct scmi_tlm_instance *ti;\n+\n+\tti = devm_kzalloc(dev, sizeof(*ti), GFP_KERNEL);\n+\tif (!ti)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tti-\u003einfo = tsp-\u003eops-\u003einfo_get(tsp-\u003eph);\n+\tif (!ti-\u003einfo)\n+\t\treturn dev_err_ptr_probe(dev,\n+\t\t\t\t\t -EINVAL, \"invalid Telemetry info !\\n\");\n+\n+\tti-\u003eid = instance_id;\n+\tti-\u003etsp = tsp;\n+\n+\treturn ti;\n+}\n+\n+static char *scmi_tlm_devnode(const struct device *dev, umode_t *mode)\n+{\n+\treturn kasprintf(GFP_KERNEL, \"scmi/%s\", dev_name(dev));\n+}\n+\n+static struct class stlm_class = {\n+\t.name    = \"stlm\",\n+\t.devnode = scmi_tlm_devnode,\n+};\n+\n+static int scmi_telemetry_probe(struct scmi_device *sdev)\n+{\n+\tconst struct scmi_handle *handle = sdev-\u003ehandle;\n+\tstruct device *tdev, *dev = \u0026sdev-\u003edev;\n+\tstruct scmi_protocol_handle *ph;\n+\tstruct scmi_tlm_instance *ti;\n+\tstruct scmi_tlm_setup *tsp;\n+\tunsigned int instance;\n+\tconst void *ops;\n+\tint ret;\n+\n+\tif (!handle)\n+\t\treturn -ENODEV;\n+\n+\tops = handle-\u003edevm_protocol_get(sdev, sdev-\u003eprotocol_id, \u0026ph);\n+\tif (IS_ERR(ops))\n+\t\treturn dev_err_probe(dev, PTR_ERR(ops),\n+\t\t\t\t     \"Cannot access protocol:0x%X\\n\",\n+\t\t\t\t     sdev-\u003eprotocol_id);\n+\n+\ttsp = devm_kzalloc(dev, sizeof(*tsp), GFP_KERNEL);\n+\tif (!tsp)\n+\t\treturn -ENOMEM;\n+\n+\ttsp-\u003edev = dev;\n+\ttsp-\u003eops = ops;\n+\ttsp-\u003eph = ph;\n+\n+\tinstance = handle-\u003eid;\n+\tif (instance \u003e= SCMI_TLM_NUM_DEVS)\n+\t\treturn -ENOSPC;\n+\n+\tti = scmi_tlm_init(tsp, instance);\n+\tif (IS_ERR(ti))\n+\t\treturn PTR_ERR(ti);\n+\n+\tcdev_init(\u0026ti-\u003ecdev, \u0026stlm_fops);\n+\tti-\u003ecdev.owner = THIS_MODULE;\n+\tti-\u003edevt = MKDEV(MAJOR(stlm_devt), MINOR(stlm_devt) + instance);\n+\tret = cdev_add(\u0026ti-\u003ecdev, ti-\u003edevt, 1);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\ttdev = device_create(\u0026stlm_class, NULL, ti-\u003edevt, ti, \"tlm_%d\", ti-\u003eid);\n+\tif (IS_ERR(tdev)) {\n+\t\tcdev_del(\u0026ti-\u003ecdev);\n+\t\treturn  PTR_ERR(tdev);\n+\t}\n+\n+\tdev_set_drvdata(\u0026sdev-\u003edev, ti);\n+\n+\treturn 0;\n+}\n+\n+static void scmi_telemetry_remove(struct scmi_device *sdev)\n+{\n+\tstruct scmi_tlm_instance *ti;\n+\n+\tti = dev_get_drvdata(\u0026sdev-\u003edev);\n+\tif (!ti)\n+\t\treturn;\n+\n+\tdevice_destroy(\u0026stlm_class, ti-\u003edevt);\n+\tcdev_del(\u0026ti-\u003ecdev);\n+}\n+\n+static const struct scmi_device_id scmi_id_table[] = {\n+\t{ SCMI_PROTOCOL_TELEMETRY, \"telemetry\" },\n+\t{ }\n+};\n+MODULE_DEVICE_TABLE(scmi, scmi_id_table);\n+\n+static struct scmi_driver scmi_telemetry_driver = {\n+\t.name = SCMI_TLM_DRIVER,\n+\t.probe = scmi_telemetry_probe,\n+\t.remove = scmi_telemetry_remove,\n+\t.id_table = scmi_id_table,\n+};\n+\n+static int __init scmi_telemetry_init(void)\n+{\n+\tint ret;\n+\n+\tret = alloc_chrdev_region(\u0026stlm_devt, 0, SCMI_TLM_NUM_DEVS,\n+\t\t\t\t  SCMI_TLM_DRIVER);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = class_register(\u0026stlm_class);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\treturn scmi_register(\u0026scmi_telemetry_driver);\n+}\n+module_init(scmi_telemetry_init);\n+\n+static void __exit scmi_telemetry_exit(void)\n+{\n+\tscmi_unregister(\u0026scmi_telemetry_driver);\n+\tunregister_chrdev_region(stlm_devt, SCMI_TLM_NUM_DEVS);\n+\tclass_unregister(\u0026stlm_class);\n+}\n+module_exit(scmi_telemetry_exit);\n+\n+MODULE_AUTHOR(\"Cristian Marussi \u003ccristian.marussi@arm.com\u003e\");\n+MODULE_DESCRIPTION(\"ARM SCMI Telemetry Driver\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/drivers/firmware/arm_scmi/telemetry.c b/drivers/firmware/arm_scmi/telemetry.c\nnew file mode 100644\nindex 00000000000000..cfa3bfb1ad3d75\n--- /dev/null\n+++ b/drivers/firmware/arm_scmi/telemetry.c\n@@ -0,0 +1,3470 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * System Control and Management Interface (SCMI) Telemetry Protocol\n+ *\n+ * Copyright (C) 2026 ARM Ltd.\n+ */\n+\n+#include \u003clinux/atomic.h\u003e\n+#include \u003clinux/bitfield.h\u003e\n+#include \u003clinux/device.h\u003e\n+#include \u003clinux/compiler_types.h\u003e\n+#include \u003clinux/completion.h\u003e\n+#include \u003clinux/err.h\u003e\n+#include \u003clinux/fs.h\u003e\n+#include \u003clinux/debugfs.h\u003e\n+#include \u003clinux/delay.h\u003e\n+#include \u003clinux/io.h\u003e\n+#include \u003clinux/limits.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/mutex.h\u003e\n+#include \u003clinux/refcount.h\u003e\n+#include \u003clinux/slab.h\u003e\n+#include \u003clinux/sprintf.h\u003e\n+#include \u003clinux/string.h\u003e\n+#include \u003clinux/xarray.h\u003e\n+#include \u003clinux/wait.h\u003e\n+\n+#include \"protocols.h\"\n+#include \"notify.h\"\n+\n+#include \u003ctrace/events/scmi.h\u003e\n+\n+/* Updated only after ALL the mandatory features for that version are merged */\n+#define SCMI_PROTOCOL_SUPPORTED_VERSION\t\t0x10000\n+\n+#define SCMI_TLM_GENERATION_ONE\t\t(SCMI_TLM_GENERATION_INVALID + 1U)\n+#define SCMI_TLM_TDCF_MAX_RETRIES\t5\n+\n+enum scmi_telemetry_protocol_cmd {\n+\tTELEMETRY_LIST_SHMTI = 0x3,\n+\tTELEMETRY_DE_DESCRIPTION = 0x4,\n+\tTELEMETRY_LIST_UPDATE_INTERVALS = 0x5,\n+\tTELEMETRY_DE_CONFIGURE = 0x6,\n+\tTELEMETRY_DE_ENABLED_LIST = 0x7,\n+\tTELEMETRY_CONFIG_SET = 0x8,\n+\tTELEMETRY_READING_COMPLETE = TELEMETRY_CONFIG_SET,\n+\tTELEMETRY_CONFIG_GET = 0x9,\n+\tTELEMETRY_RESET = 0xA,\n+};\n+\n+struct scmi_msg_resp_telemetry_protocol_attributes {\n+\t__le32 de_num;\n+\t__le32 groups_num;\n+\t__le32 de_implementation_rev_dword[SCMI_TLM_DE_IMPL_MAX_DWORDS];\n+\t__le32 attributes;\n+#define SUPPORTS_SINGLE_READ(x)\t\t(le32_get_bits((x), BIT(31)))\n+#define SUPPORTS_CONTINUOS_UPDATE(x)\t(le32_get_bits((x), BIT(30)))\n+#define SUPPORTS_PER_GROUP_CONFIG(x)\t(le32_get_bits((x), BIT(18)))\n+#define SUPPORTS_RESET(x)\t\t(le32_get_bits((x), BIT(17)))\n+#define SUPPORTS_FC(x)\t\t\t(le32_get_bits((x), BIT(16)))\n+\t__le32 default_blk_ts_rate;\n+};\n+\n+struct scmi_telemetry_update_notify_payld {\n+\t__le32 agent_id;\n+\t__le32 status;\n+\t__le32 num_dwords;\n+\t__le32 array[] __counted_by(num_dwords);\n+};\n+\n+struct scmi_shmti_desc {\n+\t__le32 id;\n+\t__le32 addr_low;\n+\t__le32 addr_high;\n+\t__le32 length;\n+\t__le32 flags;\n+};\n+\n+struct scmi_msg_resp_telemetry_shmti_list {\n+\t__le32 num_shmti;\n+\tstruct scmi_shmti_desc desc[] __counted_by(num_shmti);\n+};\n+\n+struct de_desc_fc {\n+\t__le32 addr_low;\n+\t__le32 addr_high;\n+\t__le32 size;\n+};\n+\n+struct scmi_de_desc {\n+\t__le32 id;\n+\t__le32 grp_id;\n+\t__le32 data_sz;\n+\t__le32 attr_1;\n+#define\tIS_NAME_SUPPORTED(d)\t(le32_get_bits((d)-\u003eattr_1, BIT(31)))\n+#define\tIS_FC_SUPPORTED(d)\t(le32_get_bits((d)-\u003eattr_1, BIT(30)))\n+#define\tGET_DE_TYPE(d)\t\t(le32_get_bits((d)-\u003eattr_1, GENMASK(29, 22)))\n+#define\tIS_PERSISTENT(d)\t(le32_get_bits((d)-\u003eattr_1, BIT(21)))\n+#define GET_DE_UNIT_EXP(d)\t\t\t\t\t\t\\\n+\t({\t\t\t\t\t\t\t\t\\\n+\t\t__u32 __signed_exp =\t\t\t\t\t\\\n+\t\t\tle32_get_bits((d)-\u003eattr_1, GENMASK(20, 13));\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\t\tsign_extend32(__signed_exp, 7);\t\t\t\t\\\n+\t})\n+#define\tGET_DE_UNIT(d)\t\t(le32_get_bits((d)-\u003eattr_1, GENMASK(12, 5)))\n+#define\tTSTAMP_SUPPORT(d)\t(le32_get_bits((d)-\u003eattr_1, GENMASK(1, 0)))\n+\t__le32 attr_2;\n+#define\tGET_DE_INSTA_ID(d)\t(le32_get_bits((d)-\u003eattr_2, GENMASK(31, 24)))\n+#define\tGET_COMPO_INSTA_ID(d)\t(le32_get_bits((d)-\u003eattr_2, GENMASK(23, 8)))\n+#define\tGET_COMPO_TYPE(d)\t(le32_get_bits((d)-\u003eattr_2, GENMASK(7, 0)))\n+\t__le32 reserved;\n+};\n+\n+#define SCMI_TDE_VAR_SZ(_t)\t\t\t\t\t\t       \\\n+\t({\t\t\t\t\t\t\t\t       \\\n+\t\tstruct telemetry_de *__t = _t;\t\t\t\t       \\\n+\t\tsize_t _sz = 0;\t\t\t\t\t\t       \\\n+\t\t\t\t\t\t\t\t\t       \\\n+\t\t_sz += __t-\u003ets_type == TSTAMP_LINE ? sizeof(__le32) : 0;       \\\n+\t\t_sz += __t-\u003ede.fc_support ? sizeof(struct de_desc_fc) : 0;     \\\n+\t\t_sz += __t-\u003ede.name_support ? SCMI_SHORT_NAME_MAX_SIZE : 0;    \\\n+\t\t\t\t\t\t\t\t\t       \\\n+\t\t_sz;\t\t\t\t\t\t\t       \\\n+\t})\n+\n+struct scmi_msg_resp_telemetry_de_description {\n+\t__le32 num_desc;\n+\tstruct scmi_de_desc desc[] __counted_by(num_desc);\n+};\n+\n+struct scmi_msg_telemetry_update_intervals {\n+\t__le32 index;\n+\t__le32 group_identifier;\n+#define\tALL_DES_NO_GROUP\t0x0\n+#define SPECIFIC_GROUP_DES\t0x1\n+#define ALL_DES_ANY_GROUP\t0x2\n+\t__le32 flags;\n+};\n+\n+struct scmi_msg_resp_telemetry_update_intervals {\n+\t__le32 flags;\n+#define INTERVALS_DISCRETE(x)\t(le32_get_bits((x), BIT(12)) == 0)\n+\t__le32 intervals[];\n+};\n+\n+struct scmi_msg_telemetry_de_enabled_list {\n+\t__le32 index;\n+\t__le32 flags;\n+};\n+\n+struct scmi_enabled_de_desc {\n+\t__le32 id;\n+\t__le32 mode;\n+};\n+\n+struct scmi_msg_resp_telemetry_de_enabled_list {\n+\t__le32 flags;\n+\tstruct scmi_enabled_de_desc entry[];\n+};\n+\n+struct scmi_msg_telemetry_de_configure {\n+\t__le32 id;\n+\t__le32 flags;\n+#define DE_ENABLE_NO_TSTAMP\tBIT(0)\n+#define DE_ENABLE_WTH_TSTAMP\tBIT(1)\n+#define DE_DISABLE_ALL\t\tBIT(2)\n+#define GROUP_SELECTOR\t\tBIT(3)\n+#define EVENT_DE\t\t0\n+#define EVENT_GROUP\t\t1\n+#define DE_DISABLE_ONE\t\t0x0\n+};\n+\n+struct scmi_msg_resp_telemetry_de_configure {\n+\t__le32 shmti_id;\n+#define IS_SHMTI_ID_VALID(x)\t((x) != 0xFFFFFFFF)\n+\t__le32 shmti_de_offset;\n+\t__le32 blk_ts_offset;\n+};\n+\n+struct scmi_msg_telemetry_config_set {\n+\t__le32 grp_id;\n+\t__le32 control;\n+#define TELEMETRY_ENABLE\t\t(BIT(0))\n+\n+#define TELEMETRY_MODE_SET(x)\t\t(FIELD_PREP(GENMASK(4, 1), (x)))\n+#define\tTLM_ONDEMAND\t\t\t(0)\n+#define\tTLM_NOTIFS\t\t\t(1)\n+#define\tTLM_SINGLE\t\t\t(2)\n+#define TELEMETRY_MODE_ONDEMAND\t\tTELEMETRY_MODE_SET(TLM_ONDEMAND)\n+#define TELEMETRY_MODE_NOTIFS\t\tTELEMETRY_MODE_SET(TLM_NOTIFS)\n+#define TELEMETRY_MODE_SINGLE\t\tTELEMETRY_MODE_SET(TLM_SINGLE)\n+\n+#define TLM_ORPHANS\t\t\t(0)\n+#define TLM_GROUP\t\t\t(1)\n+#define TLM_ALL\t\t\t\t(2)\n+#define TELEMETRY_SET_SELECTOR(x)\t(FIELD_PREP(GENMASK(8, 5), (x)))\n+#define\tTELEMETRY_SET_SELECTOR_ORPHANS\tTELEMETRY_SET_SELECTOR(TLM_ORPHANS)\n+#define\tTELEMETRY_SET_SELECTOR_GROUP\tTELEMETRY_SET_SELECTOR(TLM_GROUP)\n+#define\tTELEMETRY_SET_SELECTOR_ALL\tTELEMETRY_SET_SELECTOR(TLM_ALL)\n+\t__le32 sampling_rate;\n+};\n+\n+struct scmi_msg_resp_telemetry_reading_complete {\n+\t__le32 num_dwords;\n+\t__le32 dwords[] __counted_by(num_dwords);\n+};\n+\n+struct scmi_msg_telemetry_config_get {\n+\t__le32 grp_id;\n+\t__le32 flags;\n+#define TELEMETRY_GET_SELECTOR(x)\t(FIELD_PREP(GENMASK(3, 0), (x)))\n+#define\tTELEMETRY_GET_SELECTOR_ORPHANS\tTELEMETRY_GET_SELECTOR(TLM_ORPHANS)\n+#define\tTELEMETRY_GET_SELECTOR_GROUP\tTELEMETRY_GET_SELECTOR(TLM_GROUP)\n+#define\tTELEMETRY_GET_SELECTOR_ALL\tTELEMETRY_GET_SELECTOR(TLM_ALL)\n+};\n+\n+struct scmi_msg_resp_telemetry_config_get {\n+\t__le32 control;\n+\t__le32 sampling_rate;\n+};\n+\n+/* TDCF */\n+\n+#define _I(__a)\t\t(ioread32((void __iomem *)(__a)))\n+\n+#define TO_CPU_64(h, l)\t((((u64)(h)) \u003c\u003c 32) | (l))\n+\n+/*\n+ * Define the behaviour of a SHMTI scan defining what information will\n+ * be gathered and which Telemetry items can be updated.\n+ */\n+enum scan_mode {\n+\tSCAN_LOOKUP,\t/* Update only value/tstamp */\n+\tSCAN_UPDATE,\t/* Update also location offset */\n+\tSCAN_DISCOVERY  /* Update xa_des: allows for new DEs to be discovered */\n+};\n+\n+struct fc_line {\n+\t__le32 data_low;\n+\t__le32 data_high;\n+};\n+\n+struct fc_tsline {\n+\t__le32 data_low;\n+\t__le32 data_high;\n+\t__le32 ts_low;\n+\t__le32 ts_high;\n+};\n+\n+struct line {\n+\t__le32 data_low;\n+\t__le32 data_high;\n+};\n+\n+struct blk_tsline {\n+\t__le32 ts_low;\n+\t__le32 ts_high;\n+};\n+\n+struct tsline {\n+\t__le32 data_low;\n+\t__le32 data_high;\n+\t__le32 ts_low;\n+\t__le32 ts_high;\n+};\n+\n+struct uuid_line {\n+\t__be32 dwords[SCMI_TLM_DE_IMPL_MAX_DWORDS];\n+};\n+\n+#define LINE_DATA_GET_RAW(f)\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\\\n+\ttypeof(f) _f = (f);\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\\\n+\t(TO_CPU_64(_f-\u003edata_high, _f-\u003edata_low));\t\t\\\n+})\n+\n+#define LINE_DATA_GET(f)\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\\\n+\ttypeof(f) _f = (f);\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\\\n+\t(TO_CPU_64(_I(\u0026_f-\u003edata_high), _I(\u0026_f-\u003edata_low)));\t\\\n+})\n+\n+#define LINE_TSTAMP_GET_RAW(f)\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\\\n+\ttypeof(f) _f = (f);\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\\\n+\t(TO_CPU_64(_f-\u003ets_high, _f-\u003ets_low));\t\t\t\\\n+})\n+\n+#define LINE_TSTAMP_GET(f)\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\\\n+\ttypeof(f) _f = (f);\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\\\n+\t(TO_CPU_64(_I(\u0026_f-\u003ets_high), _I(\u0026_f-\u003ets_low)));\t\t\\\n+})\n+\n+#define BLK_TS_STAMP(f)\t\tLINE_TSTAMP_GET(f)\n+#define BLK_TS_RATE(p)\t\tPAYLD_ID(p)\n+\n+enum tdcf_line_types {\n+\tTDCF_DATA_LINE,\n+\tTDCF_BLK_TS_LINE,\n+\tTDCF_UUID_LINE,\n+};\n+\n+struct payload {\n+\t__le32 meta;\n+#define PAYLD_META(x)\t\t(_I(\u0026((x)-\u003emeta)))\n+#define LINE_TYPE_RAW(m)\t(FIELD_GET(GENMASK(7, 4), (m)))\n+#define LINE_TYPE(x)\t\t(LINE_TYPE_RAW(PAYLD_META(x)))\n+#define IS_DATA_LINE(x)\t\t(LINE_TYPE(x) == TDCF_DATA_LINE)\n+#define IS_BLK_TS_LINE(x)\t(LINE_TYPE(x) == TDCF_BLK_TS_LINE)\n+#define IS_UUID_LINE(x)\t\t(LINE_TYPE(x) == TDCF_UUID_LINE)\n+#define USE_BLK_TS_RAW(m)\t((m) \u0026 BIT(3))\n+#define USE_BLK_TS(x)\t\t(USE_BLK_TS_RAW(PAYLD_META(x)))\n+#define HAS_LINE_EXT_RAW(m)\t((m) \u0026 BIT(2))\n+#define HAS_LINE_EXT(x)\t\t(HAS_LINE_EXT_RAW(PAYLD_META(x)))\n+#define LINE_TS_VALID_RAW(m)\t((m) \u0026 BIT(1))\n+#define LINE_TS_VALID(x)\t(LINE_TS_VALID_RAW(PAYLD_META(x)))\n+#define\tDATA_INVALID_RAW(m)\t((m) \u0026 BIT(0))\n+#define\tDATA_INVALID(x)\t\t(DATA_INVALID_RAW(PAYLD_META(x)))\n+#define\tBLK_TS_INVALID(p)\t\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\t\\\n+\tu32 _m = PAYLD_META(p);\t\t\t\t\t\t\\\n+\tbool invalid;\t\t\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\tinvalid  = LINE_TS_VALID_RAW(_m) || HAS_LINE_EXT_RAW(_m) ||\t\\\n+\t\t\tUSE_BLK_TS_RAW(_m) || DATA_INVALID_RAW(_m);\t\\\n+\tinvalid;\t\t\t\t\t\t\t\\\n+})\n+\n+#define\tUUID_INVALID(p)\t\t\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\t\\\n+\tu32 _m = PAYLD_META(p);\t\t\t\t\t\t\\\n+\tbool invalid;\t\t\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\tinvalid = LINE_TS_VALID_RAW(_m) || USE_BLK_TS_RAW(_m) ||\t\\\n+\t\t\tDATA_INVALID_RAW(_m) || !HAS_LINE_EXT_RAW(_m);\t\\\n+\tinvalid;\t\t\t\t\t\t\t\\\n+})\n+\t__le32 id;\n+\tunion {\n+\t\tstruct line l;\n+\t\tstruct tsline tsl;\n+\t\tstruct blk_tsline blk_tsl;\n+\t\tstruct uuid_line uuid_l;\n+\t};\n+};\n+\n+#define PAYLD_ID(x)\t(_I(\u0026(((struct payload __iomem *)(x))-\u003eid)))\n+\n+#define LINE_DATA_PAYLD_WORDS\t\t\t\t\t\t       \\\n+\t((sizeof(u32) + sizeof(u32) + sizeof(struct line)) / sizeof(u32))\n+#define EXT_LINE_DATA_PAYLD_WORDS\t\t\t\t\t       \\\n+\t((sizeof(u32) + sizeof(u32) + sizeof(struct tsline)) / sizeof(u32))\n+\n+#define LINE_LENGTH_WORDS_RAW(m)\t\t\t\t\\\n+\t(HAS_LINE_EXT_RAW((m)) ? EXT_LINE_DATA_PAYLD_WORDS : LINE_DATA_PAYLD_WORDS)\n+\n+#define LINE_LENGTH_WORDS(x)\t\tLINE_LENGTH_WORDS_RAW(PAYLD_META(x))\n+\n+#define LINE_LENGTH_QWORDS(x)\t\t((LINE_LENGTH_WORDS(x)) / 2)\n+#define LINE_LENGTH_BYTES(x)\t\t((LINE_LENGTH_WORDS(x)) * sizeof(u32))\n+\n+struct prlg {\n+\tu32 sign_start;\n+#define SIGNATURE_START\t0x5442474E\t/* TBGN */\n+\tu32 match_start;\n+\tu32 num_qwords;\n+\tu32 hdr_meta_1;\n+#define TDCF_REVISION_GET(x)\t(le32_get_bits((x)-\u003ehdr_meta_1, GENMASK(7, 0)))\n+};\n+\n+struct eplg {\n+\tu32 match_end;\n+\tu32 sign_end;\n+#define SIGNATURE_END\t0x54454E44\t/* TEND */\n+};\n+\n+#define TDCF_EPLG_SZ\t(sizeof(struct eplg))\n+\n+struct tdcf {\n+\tstruct prlg prlg;\n+\tunsigned char payld[];\n+};\n+\n+#define QWORDS(_t)\t(_I(\u0026(_t)-\u003eprlg.num_qwords))\n+\n+#define SHMTI_MIN_SIZE\t(sizeof(struct tdcf) + TDCF_EPLG_SZ)\n+\n+#define TDCF_START_SIGNATURE(x)\t(_I(\u0026((x)-\u003eprlg.sign_start)))\n+#define TDCF_START_SEQ_GET(x)\t(_I(\u0026((x)-\u003eprlg.match_start)))\n+#define IS_BAD_START_SEQ(s)\t((s) \u0026 0x1)\n+\n+#define TDCF_END_SEQ_GET(e)\t(_I(\u0026((e)-\u003ematch_end)))\n+#define TDCF_END_SIGNATURE(e)\t(_I(\u0026((e)-\u003esign_end)))\n+#define\tTDCF_BAD_END_SEQ\tGENMASK(31, 0)\n+\n+struct telemetry_shmti {\n+\tu32 flags;\n+\tvoid __iomem *base;\n+\tu32 last_magic;\n+\tstruct scmi_telemetry_shmti_info info;\n+};\n+\n+struct scmi_telemetry_dbg_shmti {\n+\tstruct telemetry_shmti *shmti;\n+\tsize_t buf_sz;\n+\tvoid *buf;\n+\t/* Protect this descriptor from concurrent readers using it */\n+\tstruct mutex mtx;\n+};\n+\n+#define SHMTI_EPLG(s)\t\t\t\t\t\t\\\n+\t({\t\t\t\t\t\t\t\\\n+\t\tstruct telemetry_shmti *_s = (s);\t\t\\\n+\t\tstruct eplg __iomem *_eplg;\t\t\t\\\n+\t\t\t\t\t\t\t\t\\\n+\t\t_eplg = _s-\u003ebase + _s-\u003einfo.len - TDCF_EPLG_SZ;\t\\\n+\t\t(_eplg);\t\t\t\t\t\\\n+\t})\n+\n+#define SHMTI_OVERFLOWS(_n, _s)\t\t\t\t\t\t\\\n+\t({\t\t\t\t\t\t\t\t\\\n+\t\tstruct telemetry_shmti *__s = (_s);\t\t\t\\\n+\t\tvoid *__n = (_n);\t\t\t\t\t\\\n+\t\tbool oflow;\t\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\t\t__n += LINE_LENGTH_BYTES((struct payload __iomem *)__n);\\\n+\t\toflow = __n \u003e= __s-\u003ebase + __s-\u003einfo.len;\t\t\\\n+\t\toflow;\t\t\t\t\t\t\t\\\n+\t})\n+\n+struct telemetry_line {\n+\trefcount_t users;\n+\tu32 last_magic;\n+\tstruct payload __iomem *payld;\n+\tstruct xarray *xa_lines;\n+\t/* Protect line accesses  */\n+\tstruct mutex mtx;\n+};\n+\n+struct telemetry_block_ts {\n+\tu64 last_ts;\n+\tu32 last_rate;\n+\tstruct telemetry_line line;\n+};\n+\n+#define to_blkts(l)\tcontainer_of(l, struct telemetry_block_ts, line)\n+\n+struct telemetry_uuid {\n+\tu32 de_impl_version[SCMI_TLM_DE_IMPL_MAX_DWORDS];\n+\tstruct telemetry_line line;\n+};\n+\n+#define to_uuid(l)\tcontainer_of(l, struct telemetry_uuid, line)\n+\n+enum timestamps {\n+\tTSTAMP_NONE,\n+\tTSTAMP_LINE,\n+\tTSTAMP_BLK\n+};\n+\n+struct telemetry_de {\n+\tenum timestamps ts_type;\n+\tu32 ts_rate;\n+\tbool enumerated;\n+\tbool cached_msg;\n+\tvoid __iomem *base;\n+\tstruct eplg __iomem *eplg;\n+\tu32 offset;\n+\t/* NOTE THAT DE data_sz is registered in scmi_telemetry_de */\n+\tu32 fc_size;\n+\t/* Protect last_val/ts/magic accesses  */\n+\tstruct mutex mtx;\n+\tu64 last_val;\n+\tu64 last_ts;\n+\tu32 last_magic;\n+\tstruct list_head item;\n+\tstruct telemetry_block_ts *bts;\n+\tstruct telemetry_uuid *uuid;\n+\tstruct scmi_telemetry_de de;\n+};\n+\n+#define to_tde(d)\tcontainer_of(d, struct telemetry_de, de)\n+\n+static inline bool scmi_tde_has_tstamp(struct telemetry_de *t)\n+{\n+\treturn t-\u003ede.tstamp_support \u0026\u0026 t-\u003ede.tstamp_enabled;\n+}\n+\n+#define DE_ENABLED_WITH_TSTAMP\t2\n+\n+enum de_state {\n+\tENA_STATE,\n+\tENA_TSTAMP,\n+\tENA_MAX\n+};\n+\n+struct telemetry_info {\n+\tbool streaming_mode;\n+\tunsigned int num_shmti;\n+\tunsigned int num_des_tstamp;\n+\tatomic_t des_enabled[ENA_MAX];\n+\tunsigned int default_blk_ts_rate;\n+\tconst struct scmi_protocol_handle *ph;\n+\tstruct telemetry_shmti *shmti;\n+\tstruct telemetry_de *tdes;\n+\tstruct scmi_telemetry_group *grps;\n+\tstruct xarray xa_des;\n+\tstruct xarray xa_lines;\n+\t/* Mutex to protect access to @free_des */\n+\tstruct mutex free_mtx;\n+\tstruct list_head free_des;\n+\tstruct list_head fcs_des;\n+\tstruct scmi_telemetry_info info;\n+\tstruct wait_queue_head gen_wq;\n+\tstruct notifier_block telemetry_nb;\n+\tatomic_t rinfo_initializing;\n+\tstruct completion rinfo_initdone;\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\tstruct scmi_telemetry_res_info *(*res_get)(struct telemetry_info *ti);\n+};\n+\n+#define telemetry_nb_to_info(x)\t\\\n+\tcontainer_of(x, struct telemetry_info, telemetry_nb)\n+\n+static struct scmi_telemetry_res_info *\n+__scmi_telemetry_resources_get(struct telemetry_info *ti);\n+\n+static int scmi_telemetry_shmti_scan(struct telemetry_info *ti,\n+\t\t\t\t     unsigned int shmti_id, enum scan_mode mode);\n+\n+static inline void\n+scmi_telemetry_de_state_update(struct telemetry_info *ti, enum de_state state,\n+\t\t\t       bool *current_state, const bool next_state)\n+{\n+\tif (!current_state || *current_state != next_state)\n+\t\tatomic_add(next_state ? 1 : -1, \u0026ti-\u003edes_enabled[state]);\n+\n+\tif (current_state)\n+\t\t*current_state = next_state;\n+\n+\tdev_dbg(ti-\u003eph-\u003edev, \"Telemetry des_enabled[%s]:%u\\n\",\n+\t\tstate == ENA_STATE ? \"STATE\" : \"TSTAMP\",\n+\t\tatomic_read(\u0026ti-\u003edes_enabled[state]));\n+}\n+\n+static struct telemetry_de *\n+scmi_telemetry_free_tde_get(struct telemetry_info *ti)\n+{\n+\tstruct telemetry_de *tde;\n+\n+\tguard(mutex)(\u0026ti-\u003efree_mtx);\n+\n+\ttde = list_first_entry_or_null(\u0026ti-\u003efree_des, struct telemetry_de, item);\n+\tif (!tde)\n+\t\treturn tde;\n+\n+\tlist_del(\u0026tde-\u003eitem);\n+\n+\treturn tde;\n+}\n+\n+static void scmi_telemetry_free_tde_put(struct telemetry_info *ti,\n+\t\t\t\t\tstruct telemetry_de *tde)\n+{\n+\tguard(mutex)(\u0026ti-\u003efree_mtx);\n+\n+\tlist_add_tail(\u0026tde-\u003eitem, \u0026ti-\u003efree_des);\n+}\n+\n+static struct telemetry_de *scmi_telemetry_tde_lookup(struct telemetry_info *ti,\n+\t\t\t\t\t\t      unsigned int de_id)\n+{\n+\tstruct scmi_telemetry_de *de;\n+\n+\tde = xa_load(\u0026ti-\u003exa_des, de_id);\n+\tif (!de)\n+\t\treturn NULL;\n+\n+\treturn to_tde(de);\n+}\n+\n+static struct telemetry_de *scmi_telemetry_tde_get(struct telemetry_info *ti,\n+\t\t\t\t\t\t   unsigned int de_id)\n+{\n+\tstruct telemetry_de *tde;\n+\n+\t/* Pick a new tde */\n+\ttde = scmi_telemetry_free_tde_get(ti);\n+\tif (!tde) {\n+\t\tdev_err(ti-\u003eph-\u003edev, \"Cannot allocate DE for ID:0x%08X\\n\", de_id);\n+\t\treturn ERR_PTR(-ENOSPC);\n+\t}\n+\n+\treturn tde;\n+}\n+\n+static int scmi_telemetry_tde_register(struct telemetry_info *ti,\n+\t\t\t\t       struct telemetry_de *tde)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\tint ret;\n+\n+\tif (rinfo-\u003enum_des \u003e= ti-\u003einfo.base.num_des) {\n+\t\tret = -ENOSPC;\n+\t\tgoto err;\n+\t}\n+\n+\t/* Store DE pointer by de_id ... */\n+\tret = xa_insert(\u0026ti-\u003exa_des, tde-\u003ede.info-\u003eid, \u0026tde-\u003ede, GFP_KERNEL);\n+\tif (ret)\n+\t\tgoto err;\n+\n+\t/* ... and in the general array */\n+\trinfo-\u003edes[rinfo-\u003enum_des++] = \u0026tde-\u003ede;\n+\n+\treturn 0;\n+\n+err:\n+\tdev_err(ti-\u003eph-\u003edev, \"Cannot register DE for ID:0x%08X\\n\",\n+\t\ttde-\u003ede.info-\u003eid);\n+\n+\treturn ret;\n+}\n+\n+static bool\n+scmi_telemetry_tde_cache_unchanged(struct telemetry_de *tde, u32 magic)\n+{\n+\tguard(mutex)(\u0026tde-\u003emtx);\n+\n+\treturn tde-\u003elast_magic == magic;\n+}\n+\n+static void\n+scmi_telemetry_tde_cache_update(struct telemetry_de *tde,\n+\t\t\t\tstruct scmi_telemetry_de_sample *sample,\n+\t\t\t\tu32 *magic)\n+{\n+\tguard(mutex)(\u0026tde-\u003emtx);\n+\n+\ttde-\u003elast_magic = magic ? *magic : TDCF_BAD_END_SEQ;\n+\ttde-\u003elast_val = sample-\u003eval;\n+\ttde-\u003elast_ts = scmi_tde_has_tstamp(tde) ? sample-\u003etstamp : 0;\n+\t/* Update returned value too */\n+\tsample-\u003etstamp = tde-\u003elast_ts;\n+}\n+\n+static int\n+scmi_telemetry_tde_cache_lookup(struct telemetry_de *tde,\n+\t\t\t\tstruct scmi_telemetry_de_sample *sample,\n+\t\t\t\tu32 *magic)\n+{\n+\tguard(mutex)(\u0026tde-\u003emtx);\n+\n+\tif (magic \u0026\u0026 tde-\u003elast_magic != *magic)\n+\t\treturn -EAGAIN;\n+\n+\tsample-\u003eid = tde-\u003ede.info-\u003eid;\n+\tsample-\u003eval = tde-\u003elast_val;\n+\tsample-\u003etstamp = tde-\u003elast_ts;\n+\n+\treturn 0;\n+}\n+\n+static inline void __scmi_telemetry_generation_set(struct telemetry_info *ti,\n+\t\t\t\t\t\t   unsigned int new)\n+{\n+\tatomic_set_release(\u0026ti-\u003einfo.generation, new);\n+\n+\twake_up_all(\u0026ti-\u003egen_wq);\n+}\n+\n+static inline void scmi_telemetry_generation_update(struct telemetry_info *ti)\n+{\n+\tunsigned int next;\n+\n+\t/* Wrap around skipping invalid generation 0 */\n+\tnext = (atomic_read(\u0026ti-\u003einfo.generation) + 1) ?: SCMI_TLM_GENERATION_ONE;\n+\n+\t__scmi_telemetry_generation_set(ti, next);\n+}\n+\n+static inline void scmi_telemetry_generation_reset(struct telemetry_info *ti)\n+{\n+\t__scmi_telemetry_generation_set(ti, SCMI_TLM_GENERATION_ONE);\n+}\n+\n+struct scmi_tlm_de_priv {\n+\tstruct telemetry_info *ti;\n+\tvoid *next;\n+};\n+\n+static int\n+scmi_telemetry_protocol_attributes_get(struct telemetry_info *ti)\n+{\n+\tstruct scmi_msg_resp_telemetry_protocol_attributes *resp;\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\tstruct scmi_xfer *t;\n+\tint ret;\n+\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0,\n+\t\t\t\t      sizeof(*resp), \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tresp = t-\u003erx.buf;\n+\tret = ph-\u003exops-\u003edo_xfer(ph, t);\n+\tif (!ret) {\n+\t\t__le32 attr = resp-\u003eattributes;\n+\n+\t\tti-\u003einfo.base.num_des = le32_to_cpu(resp-\u003ede_num);\n+\t\tti-\u003einfo.base.num_groups = le32_to_cpu(resp-\u003egroups_num);\n+\t\tfor (int i = 0; i \u003c SCMI_TLM_DE_IMPL_MAX_DWORDS; i++)\n+\t\t\tti-\u003einfo.base.de_impl_version[i] =\n+\t\t\t\tle32_to_cpu(resp-\u003ede_implementation_rev_dword[i]);\n+\t\tti-\u003einfo.single_read_support = SUPPORTS_SINGLE_READ(attr);\n+\t\tti-\u003einfo.continuos_update_support = SUPPORTS_CONTINUOS_UPDATE(attr);\n+\t\tti-\u003einfo.per_group_config_support = SUPPORTS_PER_GROUP_CONFIG(attr);\n+\t\tti-\u003einfo.reset_support = SUPPORTS_RESET(attr);\n+\t\tti-\u003einfo.fc_support = SUPPORTS_FC(attr);\n+\t\tti-\u003enum_shmti = le32_get_bits(attr, GENMASK(15, 0));\n+\t\tti-\u003edefault_blk_ts_rate = le32_to_cpu(resp-\u003edefault_blk_ts_rate);\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\treturn ret;\n+}\n+\n+static void iter_tlm_prepare_message(void *message,\n+\t\t\t\t     unsigned int desc_index, const void *priv)\n+{\n+\tput_unaligned_le32(desc_index, message);\n+}\n+\n+static int iter_de_descr_update_state(struct scmi_iterator_state *st,\n+\t\t\t\t      const void *response, void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_de_description *r = response;\n+\tstruct scmi_tlm_de_priv *p = priv;\n+\n+\tst-\u003enum_returned = le32_get_bits(r-\u003enum_desc, GENMASK(15, 0));\n+\tst-\u003enum_remaining = le32_get_bits(r-\u003enum_desc, GENMASK(31, 16));\n+\n+\tif (st-\u003erx_len \u003c (sizeof(*r) + sizeof(r-\u003edesc[0]) * st-\u003enum_returned))\n+\t\treturn -EINVAL;\n+\n+\t/* Initialized to first descriptor */\n+\tp-\u003enext = (void *)r-\u003edesc;\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_de_descriptor_parse(struct telemetry_info *ti,\n+\t\t\t\t\t      struct telemetry_de *tde,\n+\t\t\t\t\t      void **next, size_t rx_len)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\tconst struct scmi_de_desc *desc = *next;\n+\tunsigned int grp_id;\n+\tsize_t payld_sz = sizeof(*desc);\n+\n+\tif (rx_len \u003c payld_sz)\n+\t\treturn -ENOSPC;\n+\n+\ttde-\u003ede.info-\u003eid = le32_to_cpu(desc-\u003eid);\n+\tgrp_id = le32_to_cpu(desc-\u003egrp_id);\n+\tif (grp_id != SCMI_TLM_GRP_INVALID) {\n+\t\t/* Group descriptors are empty but allocated at this point */\n+\t\tif (grp_id \u003e= ti-\u003einfo.base.num_groups)\n+\t\t\treturn -EINVAL;\n+\n+\t\t/* Link to parent group */\n+\t\ttde-\u003ede.grp = \u0026rinfo-\u003egrps[grp_id];\n+\t}\n+\n+\ttde-\u003ede.info-\u003egrp_id = grp_id;\n+\ttde-\u003ede.info-\u003edata_sz = le32_to_cpu(desc-\u003edata_sz);\n+\ttde-\u003ede.info-\u003etype = GET_DE_TYPE(desc);\n+\ttde-\u003ede.info-\u003eunit = GET_DE_UNIT(desc);\n+\ttde-\u003ede.info-\u003eunit_exp = GET_DE_UNIT_EXP(desc);\n+\ttde-\u003ede.info-\u003einstance_id = GET_DE_INSTA_ID(desc);\n+\ttde-\u003ede.info-\u003ecompo_instance_id = GET_COMPO_INSTA_ID(desc);\n+\ttde-\u003ede.info-\u003ecompo_type = GET_COMPO_TYPE(desc);\n+\ttde-\u003ede.info-\u003epersistent = IS_PERSISTENT(desc);\n+\ttde-\u003ets_type = TSTAMP_SUPPORT(desc);\n+\ttde-\u003ede.tstamp_support = !!tde-\u003ets_type;\n+\t/* Count timestamped DEs */\n+\tti-\u003enum_des_tstamp += !!tde-\u003ede.tstamp_support;\n+\ttde-\u003ede.fc_support = IS_FC_SUPPORTED(desc);\n+\ttde-\u003ede.name_support = IS_NAME_SUPPORTED(desc);\n+\t/* Update DE_DESCRIPTOR size for the next iteration */\n+\t*next += sizeof(*desc);\n+\n+\tpayld_sz += SCMI_TDE_VAR_SZ(tde);\n+\tif (rx_len \u003c payld_sz)\n+\t\treturn -ENOSPC;\n+\n+\tif (tde-\u003ets_type == TSTAMP_LINE) {\n+\t\t__le32 *line_ts_rate = *next;\n+\n+\t\ttde-\u003ede.info-\u003ets_rate = le32_to_cpu((*line_ts_rate));\n+\n+\t\t/* Variably sized depending on TS support */\n+\t\t*next += sizeof(*line_ts_rate);\n+\t} else if (tde-\u003ets_type == TSTAMP_BLK) {\n+\t\t/* Setup default BLK TS value at first */\n+\t\ttde-\u003ede.info-\u003ets_rate = ti-\u003edefault_blk_ts_rate;\n+\t}\n+\n+\tif (tde-\u003ede.fc_support) {\n+\t\tu32 size;\n+\t\tu64 phys_addr;\n+\t\tvoid __iomem *addr;\n+\t\tstruct de_desc_fc *dfc;\n+\n+\t\tdfc = *next;\n+\t\tphys_addr = le32_to_cpu(dfc-\u003eaddr_low);\n+\t\tphys_addr |= (u64)le32_to_cpu(dfc-\u003eaddr_high) \u003c\u003c 32;\n+\n+\t\tsize = le32_to_cpu(dfc-\u003esize);\n+\t\taddr = devm_ioremap(ti-\u003eph-\u003edev, phys_addr, size);\n+\t\tif (!addr)\n+\t\t\treturn -EADDRNOTAVAIL;\n+\n+\t\ttde-\u003ebase = addr;\n+\t\ttde-\u003eoffset = 0;\n+\t\ttde-\u003efc_size = size;\n+\n+\t\t/* Variably sized depending on FC support */\n+\t\t*next += sizeof(*dfc);\n+\t}\n+\n+\tif (tde-\u003ede.name_support) {\n+\t\tconst char *de_name = *next;\n+\n+\t\tstrscpy(tde-\u003ede.info-\u003ename, de_name, SCMI_SHORT_NAME_MAX_SIZE);\n+\t\t/* Variably sized depending on name support */\n+\t\t*next += SCMI_SHORT_NAME_MAX_SIZE;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int iter_de_descr_process_response(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\t  const void *response,\n+\t\t\t\t\t  struct scmi_iterator_state *st,\n+\t\t\t\t\t  void *priv)\n+{\n+\tstruct scmi_tlm_de_priv *p = priv;\n+\tstruct telemetry_info *ti = p-\u003eti;\n+\tconst struct scmi_de_desc *desc = p-\u003enext;\n+\tstruct telemetry_de *tde;\n+\tbool discovered = false;\n+\tunsigned int de_id;\n+\tint ret;\n+\n+\tde_id = le32_to_cpu(desc-\u003eid);\n+\t/* Check if this DE has already been discovered by other means... */\n+\ttde = scmi_telemetry_tde_lookup(ti, de_id);\n+\tif (!tde) {\n+\t\t/* Create a new one */\n+\t\ttde = scmi_telemetry_tde_get(ti, de_id);\n+\t\tif (IS_ERR(tde))\n+\t\t\treturn PTR_ERR(tde);\n+\n+\t\tdiscovered = true;\n+\t} else if (tde-\u003eenumerated) {\n+\t\t/* Cannot be a duplicate of a DE already created by enumeration */\n+\t\tdev_err(ph-\u003edev,\n+\t\t\t\"Discovered INVALID DE with DUPLICATED ID:0x%08X\\n\",\n+\t\t\tde_id);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tret = scmi_telemetry_de_descriptor_parse(ti, tde, \u0026p-\u003enext, st-\u003erx_len);\n+\tif (ret) {\n+\t\tdev_err(ph-\u003edev, \"Malformed DE Descriptor - ret:%d\\n\", ret);\n+\t\tgoto err;\n+\t}\n+\n+\t/* Now fully enumerated */\n+\ttde-\u003eenumerated = true;\n+\n+\tif (discovered) {\n+\t\t/* Register if it was not already ... */\n+\t\tret = scmi_telemetry_tde_register(ti, tde);\n+\t\tif (ret)\n+\t\t\tgoto err;\n+\t}\n+\n+\t/* Add to FastChannels list */\n+\tif (tde-\u003ede.fc_support)\n+\t\tlist_add(\u0026tde-\u003eitem, \u0026ti-\u003efcs_des);\n+\n+\t/* Account for this DE in group num_de counter */\n+\tif (tde-\u003ede.grp)\n+\t\ttde-\u003ede.grp-\u003einfo-\u003enum_des++;\n+\n+\treturn 0;\n+\n+err:\n+\t/* DE not enumerated at this point were created in this call */\n+\tif (discovered)\n+\t\tscmi_telemetry_free_tde_put(ti, tde);\n+\n+\treturn ret;\n+}\n+\n+static int scmi_telemetry_config_lookup(struct telemetry_info *ti,\n+\t\t\t\t\tunsigned int grp_id, bool *enabled,\n+\t\t\t\t\tunsigned int *active_update_interval)\n+{\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\tstruct scmi_msg_telemetry_config_get *msg;\n+\tstruct scmi_msg_resp_telemetry_config_get *resp;\n+\tstruct scmi_xfer *t;\n+\tu32 flags;\n+\tint ret;\n+\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, TELEMETRY_CONFIG_GET,\n+\t\t\t\t      sizeof(*msg), sizeof(*resp), \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmsg = t-\u003etx.buf;\n+\tmsg-\u003egrp_id = cpu_to_le32(grp_id);\n+\tflags = grp_id == SCMI_TLM_GRP_INVALID ?\n+\t\tTELEMETRY_GET_SELECTOR_ORPHANS : TELEMETRY_GET_SELECTOR_GROUP;\n+\tmsg-\u003eflags = cpu_to_le32(flags);\n+\n+\tresp = t-\u003erx.buf;\n+\tret = ph-\u003exops-\u003edo_xfer(ph, t);\n+\tif (!ret) {\n+\t\t*enabled = le32_get_bits(resp-\u003econtrol, TELEMETRY_ENABLE);\n+\t\t*active_update_interval =\n+\t\t\tSCMI_TLM_GET_UPDATE_INTERVAL(le32_to_cpu(resp-\u003esampling_rate));\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\treturn ret;\n+}\n+\n+static int scmi_telemetry_group_config_lookup(struct telemetry_info *ti,\n+\t\t\t\t\t      struct scmi_telemetry_group *grp)\n+{\n+\treturn scmi_telemetry_config_lookup(ti, grp-\u003einfo-\u003egrp_id, \u0026grp-\u003eenabled,\n+\t\t\t\t\t    \u0026grp-\u003eactive_update_interval);\n+}\n+\n+static void iter_enabled_list_prepare_message(void *message,\n+\t\t\t\t\t      unsigned int desc_index,\n+\t\t\t\t\t      const void *priv)\n+{\n+\tstruct scmi_msg_telemetry_de_enabled_list *msg = message;\n+\n+\tmsg-\u003eindex = cpu_to_le32(desc_index);\n+\tmsg-\u003eflags = 0;\n+}\n+\n+static int iter_enabled_list_update_state(struct scmi_iterator_state *st,\n+\t\t\t\t\t  const void *response, void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_de_enabled_list *r = response;\n+\n+\tst-\u003enum_returned = le32_get_bits(r-\u003eflags, GENMASK(15, 0));\n+\tst-\u003enum_remaining = le32_get_bits(r-\u003eflags, GENMASK(31, 16));\n+\n+\tif (st-\u003erx_len \u003c (sizeof(*r) + sizeof(r-\u003eentry[0]) * st-\u003enum_returned))\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * total enabled is not declared previously anywhere so we\n+\t * assume it's returned+remaining on first call.\n+\t */\n+\tif (!st-\u003emax_resources)\n+\t\tst-\u003emax_resources = st-\u003enum_returned + st-\u003enum_remaining;\n+\n+\treturn 0;\n+}\n+\n+static int\n+iter_enabled_list_process_response(const struct scmi_protocol_handle *ph,\n+\t\t\t\t   const void *response,\n+\t\t\t\t   struct scmi_iterator_state *st, void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_de_enabled_list *r = response;\n+\tconst struct scmi_enabled_de_desc *desc;\n+\tstruct telemetry_info *ti = priv;\n+\tstruct telemetry_de *tde;\n+\tu32 de_id;\n+\tint ret;\n+\n+\tdesc = \u0026r-\u003eentry[st-\u003eloop_idx];\n+\tde_id = le32_to_cpu(desc-\u003eid);\n+\tif (scmi_telemetry_tde_lookup(ti, de_id)) {\n+\t\tdev_err(ph-\u003edev,\n+\t\t\t\"Found INVALID DE with DUPLICATED ID:0x%08X\\n\", de_id);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\ttde = scmi_telemetry_tde_get(ti, de_id);\n+\tif (IS_ERR(tde))\n+\t\treturn PTR_ERR(tde);\n+\n+\ttde-\u003ede.info-\u003eid = de_id;\n+\ttde-\u003ede.enabled = true;\n+\ttde-\u003ede.tstamp_enabled = le32_to_cpu(desc-\u003emode) == DE_ENABLED_WITH_TSTAMP;\n+\n+\tret = scmi_telemetry_tde_register(ti, tde);\n+\tif (ret) {\n+\t\tscmi_telemetry_free_tde_put(ti, tde);\n+\t\treturn ret;\n+\t}\n+\n+\tscmi_telemetry_de_state_update(ti, ENA_STATE, NULL, true);\n+\tif (tde-\u003ede.tstamp_enabled)\n+\t\tscmi_telemetry_de_state_update(ti, ENA_TSTAMP, NULL, true);\n+\n+\tdev_dbg(ph-\u003edev, \"Registered new ENABLED DE with ID:0x%08X\\n\",\n+\t\ttde-\u003ede.info-\u003eid);\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_enumerate_des_enabled_list(struct telemetry_info *ti)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\tstruct scmi_iterator_ops ops = {\n+\t\t.prepare_message = iter_enabled_list_prepare_message,\n+\t\t.update_state = iter_enabled_list_update_state,\n+\t\t.process_response = iter_enabled_list_process_response,\n+\t};\n+\tvoid *iter;\n+\tint ret;\n+\n+\titer = ph-\u003ehops-\u003eiter_response_init(ph, \u0026ops, 0,\n+\t\t\t\t\t    TELEMETRY_DE_ENABLED_LIST,\n+\t\t\t\t\t    sizeof(u32) * 2, ti);\n+\tif (IS_ERR(iter))\n+\t\treturn PTR_ERR(iter);\n+\n+\tret = ph-\u003ehops-\u003eiter_response_run(iter);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tdev_info(ti-\u003eph-\u003edev, \"Found %u enabled DEs.\\n\", rinfo-\u003enum_des);\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_initial_state_lookup(struct telemetry_info *ti)\n+{\n+\tstruct device *dev = ti-\u003eph-\u003edev;\n+\tint ret;\n+\n+\tret = scmi_telemetry_config_lookup(ti, SCMI_TLM_GRP_INVALID,\n+\t\t\t\t\t   \u0026ti-\u003einfo.enabled,\n+\t\t\t\t\t   \u0026ti-\u003einfo.active_update_interval);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (!ti-\u003einfo.enabled)\n+\t\treturn 0;\n+\n+\t/*\n+\t * When Telemetry is found already enabled on the platform, proceed with\n+\t * passive discovery using DE_ENABLED_LIST and TDCF scanning: note that\n+\t * this CAN only discover DEs exposed via SHMTIs.\n+\t * FastChannel DEs need a proper DE_DESCRIPTION enumeration, while, even\n+\t * though incoming Notifications could be used for passive discovery too,\n+\t * it would carry a considerable risk of assimilating trash as DEs.\n+\t */\n+\tdev_info(dev,\n+\t\t \"Telemetry found enabled with update interval %lux10^%d\\n\",\n+\t\t SCMI_TLM_GET_UPDATE_INTERVAL_SECS(ti-\u003einfo.active_update_interval),\n+\t\t SCMI_TLM_GET_UPDATE_INTERVAL_EXP(ti-\u003einfo.active_update_interval));\n+\t/*\n+\t * Query enabled DEs list: collect states. It will include DEs from any\n+\t * interface. Enabled groups still NOT enumerated.\n+\t */\n+\tret = scmi_telemetry_enumerate_des_enabled_list(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot query enabled DE list. Abort.\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\t/* Discover DEs on SHMTis: collect states/offsets/values */\n+\tfor (int id = 0; id \u003c ti-\u003enum_shmti; id++) {\n+\t\tret = scmi_telemetry_shmti_scan(ti, id, SCAN_DISCOVERY);\n+\t\tif (ret)\n+\t\t\tdev_warn(dev,\n+\t\t\t\t \"Failed discovery-scan of SHMTI ID:%d - ret:%d\\n\",\n+\t\t\t\t id, ret);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+scmi_telemetry_de_groups_init(struct device *dev, struct telemetry_info *ti)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\n+\t/* Allocate all groups DEs IDs arrays at first ... */\n+\tfor (int i = 0; i \u003c ti-\u003einfo.base.num_groups; i++) {\n+\t\tstruct scmi_telemetry_group *grp = \u0026rinfo-\u003egrps[i];\n+\t\tsize_t des_str_sz;\n+\n+\t\tunsigned int *des __free(kfree) = kcalloc(grp-\u003einfo-\u003enum_des,\n+\t\t\t\t\t\t\t  sizeof(unsigned int),\n+\t\t\t\t\t\t\t  GFP_KERNEL);\n+\t\tif (!des)\n+\t\t\treturn -ENOMEM;\n+\n+\t\t/*\n+\t\t * Max size 32bit ID string in Hex: 0xCAFECAFE\n+\t\t *  - 10 digits + ' '/'\\n' = 11 bytes per  number\n+\t\t *  - terminating NUL character\n+\t\t */\n+\t\tdes_str_sz = grp-\u003einfo-\u003enum_des * 11 + 1;\n+\t\tchar *des_str __free(kfree) = kzalloc(des_str_sz, GFP_KERNEL);\n+\t\tif (!des_str)\n+\t\t\treturn -ENOMEM;\n+\n+\t\tgrp-\u003edes = no_free_ptr(des);\n+\t\tgrp-\u003edes_str = no_free_ptr(des_str);\n+\t\t/* Reset group DE counter */\n+\t\tgrp-\u003einfo-\u003enum_des = 0;\n+\t}\n+\n+\t/* Scan DEs and populate DE IDs arrays for all groups */\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_des; i++) {\n+\t\tstruct scmi_telemetry_group *grp = rinfo-\u003edes[i]-\u003egrp;\n+\n+\t\tif (!grp)\n+\t\t\tcontinue;\n+\n+\t\t/*\n+\t\t * Note that, at this point, num_des is guaranteed to be\n+\t\t * sane (in-bounds) by construction.\n+\t\t */\n+\t\tgrp-\u003edes[grp-\u003einfo-\u003enum_des++] = i;\n+\t}\n+\n+\t/* Build composing DES string */\n+\tfor (int i = 0; i \u003c ti-\u003einfo.base.num_groups; i++) {\n+\t\tstruct scmi_telemetry_group *grp = \u0026rinfo-\u003egrps[i];\n+\t\tsize_t bufsize = grp-\u003einfo-\u003enum_des * 11 + 1;\n+\t\tchar *buf = grp-\u003edes_str;\n+\n+\t\tfor (int j = 0; j \u003c grp-\u003einfo-\u003enum_des; j++) {\n+\t\t\tchar term = j != (grp-\u003einfo-\u003enum_des - 1) ? ' ' : '\\0';\n+\t\t\tint len;\n+\n+\t\t\tlen = scnprintf(buf, bufsize, \"0x%08X%c\",\n+\t\t\t\t\trinfo-\u003edes[grp-\u003edes[j]]-\u003einfo-\u003eid, term);\n+\n+\t\t\tbuf += len;\n+\t\t\tbufsize -= len;\n+\t\t}\n+\t}\n+\n+\tfor (int i = 0; i \u003c ti-\u003einfo.base.num_groups; i++)\n+\t\tscmi_telemetry_group_config_lookup(ti, \u0026rinfo-\u003egrps[i]);\n+\n+\trinfo-\u003enum_groups = ti-\u003einfo.base.num_groups;\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_de_descriptors_get(struct telemetry_info *ti)\n+{\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\n+\tstruct scmi_iterator_ops ops = {\n+\t\t.prepare_message = iter_tlm_prepare_message,\n+\t\t.update_state = iter_de_descr_update_state,\n+\t\t.process_response = iter_de_descr_process_response,\n+\t};\n+\tstruct scmi_tlm_de_priv tpriv = {\n+\t\t.ti = ti,\n+\t\t.next = NULL,\n+\t};\n+\tvoid *iter;\n+\tint ret;\n+\n+\tif (!ti-\u003einfo.base.num_des)\n+\t\treturn 0;\n+\n+\titer = ph-\u003ehops-\u003eiter_response_init(ph, \u0026ops, ti-\u003einfo.base.num_des,\n+\t\t\t\t\t    TELEMETRY_DE_DESCRIPTION,\n+\t\t\t\t\t    sizeof(u32), \u0026tpriv);\n+\tif (IS_ERR(iter))\n+\t\treturn PTR_ERR(iter);\n+\n+\tret = ph-\u003ehops-\u003eiter_response_run(iter);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\treturn scmi_telemetry_de_groups_init(ph-\u003edev, ti);\n+}\n+\n+struct scmi_tlm_ivl_priv {\n+\tstruct device *dev;\n+\tstruct scmi_telemetry_intervals **intrvs;\n+\tunsigned int grp_id;\n+\tunsigned int flags;\n+};\n+\n+static void iter_intervals_prepare_message(void *message,\n+\t\t\t\t\t   unsigned int desc_index,\n+\t\t\t\t\t   const void *priv)\n+{\n+\tstruct scmi_msg_telemetry_update_intervals *msg = message;\n+\tconst struct scmi_tlm_ivl_priv *p = priv;\n+\n+\tmsg-\u003eindex = cpu_to_le32(desc_index);\n+\tmsg-\u003egroup_identifier = cpu_to_le32(p-\u003egrp_id);\n+\tmsg-\u003eflags = cpu_to_le32(FIELD_PREP(GENMASK(3, 0), p-\u003eflags));\n+}\n+\n+static int iter_intervals_update_state(struct scmi_iterator_state *st,\n+\t\t\t\t       const void *response, void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_update_intervals *r = response;\n+\n+\tst-\u003enum_returned = le32_get_bits(r-\u003eflags, GENMASK(11, 0));\n+\tst-\u003enum_remaining = le32_get_bits(r-\u003eflags, GENMASK(31, 16));\n+\n+\tif (st-\u003erx_len \u003c (sizeof(*r) + sizeof(r-\u003eintervals[0]) * st-\u003enum_returned))\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * total intervals is not declared previously anywhere so we\n+\t * assume it's returned+remaining on first call.\n+\t */\n+\tif (!st-\u003emax_resources) {\n+\t\tstruct scmi_tlm_ivl_priv *p = priv;\n+\t\tstruct scmi_telemetry_intervals *intrvs;\n+\t\tbool discrete;\n+\t\tint inum;\n+\n+\t\tdiscrete = INTERVALS_DISCRETE(r-\u003eflags);\n+\t\t/* Check consistency on first call */\n+\t\tif (!discrete \u0026\u0026 (st-\u003enum_returned != 3 || st-\u003enum_remaining != 0))\n+\t\t\treturn -EINVAL;\n+\n+\t\tinum = st-\u003enum_returned + st-\u003enum_remaining;\n+\t\tintrvs = kzalloc(sizeof(*intrvs) + inum * sizeof(__u32), GFP_KERNEL);\n+\t\tif (!intrvs)\n+\t\t\treturn -ENOMEM;\n+\n+\t\tintrvs-\u003enum_intervals = inum;\n+\t\tintrvs-\u003ediscrete = discrete;\n+\t\tst-\u003emax_resources = intrvs-\u003enum_intervals;\n+\n+\t\t*p-\u003eintrvs = intrvs;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+iter_intervals_process_response(const struct scmi_protocol_handle *ph,\n+\t\t\t\tconst void *response,\n+\t\t\t\tstruct scmi_iterator_state *st, void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_update_intervals *r = response;\n+\tstruct scmi_tlm_ivl_priv *p = priv;\n+\tstruct scmi_telemetry_intervals *intrvs = *p-\u003eintrvs;\n+\tunsigned int idx = st-\u003eloop_idx;\n+\n+\tintrvs-\u003eupdate_intervals[st-\u003edesc_index + idx] =\n+\t\tle32_to_cpu(r-\u003eintervals[idx]);\n+\n+\treturn 0;\n+}\n+\n+static int\n+scmi_tlm_enumerate_update_intervals(struct telemetry_info *ti,\n+\t\t\t\t    struct scmi_telemetry_intervals **intervals,\n+\t\t\t\t    int grp_id, unsigned int flags)\n+{\n+\tstruct scmi_iterator_ops ops = {\n+\t\t.prepare_message = iter_intervals_prepare_message,\n+\t\t.update_state = iter_intervals_update_state,\n+\t\t.process_response = iter_intervals_process_response,\n+\t};\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\tstruct scmi_telemetry_intervals *intrvs = NULL;\n+\tstruct scmi_tlm_ivl_priv ipriv = {\n+\t\t.dev = ph-\u003edev,\n+\t\t.grp_id = grp_id,\n+\t\t.intrvs = \u0026intrvs,\n+\t\t.flags = flags,\n+\t};\n+\tvoid *iter;\n+\tint ret;\n+\n+\titer = ph-\u003ehops-\u003eiter_response_init(ph, \u0026ops, 0,\n+\t\tTELEMETRY_LIST_UPDATE_INTERVALS,\n+\t\tsizeof(struct scmi_msg_telemetry_update_intervals),\n+\t\t\u0026ipriv);\n+\tif (IS_ERR(iter))\n+\t\treturn PTR_ERR(iter);\n+\n+\t/* Cleanup iterator inner allocations on failure */\n+\tret = ph-\u003ehops-\u003eiter_response_run(iter);\n+\tif (ret) {\n+\t\tkfree(intrvs);\n+\t\treturn ret;\n+\t}\n+\n+\t*intervals = intrvs;\n+\n+\treturn 0;\n+}\n+\n+static int\n+scmi_telemetry_enumerate_groups_intervals(struct telemetry_info *ti)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\n+\tif (!ti-\u003einfo.per_group_config_support)\n+\t\treturn 0;\n+\n+\tfor (int id = 0; id \u003c rinfo-\u003enum_groups; id++) {\n+\t\tint ret;\n+\n+\t\tret = scmi_tlm_enumerate_update_intervals(ti,\n+\t\t\t\t\t\t\t  \u0026rinfo-\u003egrps[id].intervals,\n+\t\t\t\t\t\t\t  id, SPECIFIC_GROUP_DES);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\trinfo-\u003egrps_store[id].num_intervals =\n+\t\t\trinfo-\u003egrps[id].intervals-\u003enum_intervals;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void scmi_telemetry_intervals_free(void *interval)\n+{\n+\tkfree(interval);\n+}\n+\n+static int\n+scmi_telemetry_enumerate_common_intervals(struct telemetry_info *ti)\n+{\n+\tunsigned int flags;\n+\tint ret;\n+\n+\tflags = !ti-\u003einfo.per_group_config_support ?\n+\t\tALL_DES_ANY_GROUP : ALL_DES_NO_GROUP;\n+\n+\tret = scmi_tlm_enumerate_update_intervals(ti, \u0026ti-\u003einfo.intervals,\n+\t\t\t\t\t\t  SCMI_TLM_GRP_INVALID, flags);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* A copy for UAPI access... */\n+\tti-\u003einfo.base.num_intervals = ti-\u003einfo.intervals-\u003enum_intervals;\n+\n+\t/* Delegate freeing of allocated intervals to unbind time */\n+\treturn devm_add_action_or_reset(ti-\u003eph-\u003edev,\n+\t\t\t\t\tscmi_telemetry_intervals_free,\n+\t\t\t\t\tti-\u003einfo.intervals);\n+}\n+\n+static int scmi_telemetry_dbg_shmti_open(struct inode *inode, struct file *filp)\n+{\n+\tstruct scmi_telemetry_dbg_shmti *sblob;\n+\tstruct telemetry_shmti *shmti;\n+\n+\tif (!inode-\u003ei_private)\n+\t\treturn -ENODEV;\n+\n+\tshmti = inode-\u003ei_private;\n+\tsblob = kzalloc_obj(*sblob);\n+\tif (!sblob)\n+\t\treturn -ENOMEM;\n+\n+\tsblob-\u003eshmti = shmti;\n+\tsblob-\u003ebuf = kzalloc(shmti-\u003einfo.len, GFP_KERNEL);\n+\tif (!sblob-\u003ebuf) {\n+\t\tkfree(sblob);\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tmutex_init(\u0026sblob-\u003emtx);\n+\n+\tfilp-\u003eprivate_data = sblob;\n+\n+\treturn 0;\n+}\n+\n+static ssize_t scmi_telemetry_dbg_shmti_read(struct file *filp, char __user *buf,\n+\t\t\t\t\t     size_t count, loff_t *ppos)\n+{\n+\tstruct scmi_telemetry_dbg_shmti *sblob = filp-\u003eprivate_data;\n+\n+\t/* Dump on first read and again after each rewind to start pos */\n+\tguard(mutex)(\u0026sblob-\u003emtx);\n+\tif (!sblob-\u003ebuf_sz || *ppos == 0) {\n+\t\tmemcpy_fromio(sblob-\u003ebuf, sblob-\u003eshmti-\u003ebase,\n+\t\t\t      sblob-\u003eshmti-\u003einfo.len);\n+\t\tsblob-\u003ebuf_sz = sblob-\u003eshmti-\u003einfo.len;\n+\t\t/* update inode timestamps */\n+\t\tsimple_inode_init_ts(file_inode(filp));\n+\t}\n+\n+\treturn simple_read_from_buffer(buf, count, ppos, sblob-\u003ebuf, sblob-\u003ebuf_sz);\n+}\n+\n+static int scmi_telemetry_dbg_shmti_release(struct inode *inode, struct file *filp)\n+{\n+\tstruct scmi_telemetry_dbg_shmti *sblob = filp-\u003eprivate_data;\n+\n+\tkfree(sblob-\u003ebuf);\n+\tkfree(sblob);\n+\n+\treturn 0;\n+}\n+\n+static const struct file_operations scmi_telemetry_dbg_shmti_fops = {\n+\t.open = scmi_telemetry_dbg_shmti_open,\n+\t.release = scmi_telemetry_dbg_shmti_release,\n+\t.read = scmi_telemetry_dbg_shmti_read,\n+\t.llseek = generic_file_llseek,\n+\t.owner = THIS_MODULE,\n+};\n+\n+static void scmi_telemetry_debugfs_initialize(struct telemetry_info *ti)\n+{\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\tstruct dentry *top, *shmti_top;\n+\n+\ttop = ph-\u003ehops-\u003edebugfs_proto_dentry_get(ph);\n+\tshmti_top = debugfs_create_dir(\"shmtis\", top);\n+\n+\tfor (unsigned int i = 0; i \u003c ti-\u003enum_shmti; i++) {\n+\t\tchar id[16];\n+\n+\t\tsnprintf(id, 16, \"%u\", i);\n+\t\tdebugfs_create_file_size(id, 0444, shmti_top, \u0026ti-\u003eshmti[i],\n+\t\t\t\t\t \u0026scmi_telemetry_dbg_shmti_fops,\n+\t\t\t\t\t ti-\u003eshmti[i].info.len);\n+\t}\n+}\n+\n+static int iter_shmti_update_state(struct scmi_iterator_state *st,\n+\t\t\t\t   const void *response, void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_shmti_list *r = response;\n+\n+\tst-\u003enum_returned = le32_get_bits(r-\u003enum_shmti, GENMASK(15, 0));\n+\tst-\u003enum_remaining = le32_get_bits(r-\u003enum_shmti, GENMASK(31, 16));\n+\n+\tif (st-\u003erx_len \u003c (sizeof(*r) + sizeof(r-\u003edesc[0]) * st-\u003enum_returned))\n+\t\treturn -EINVAL;\n+\n+\treturn 0;\n+}\n+\n+static inline int\n+scmi_telemetry_shmti_validate(struct device *dev, struct telemetry_shmti *shmti)\n+{\n+\tstruct tdcf __iomem *tdcf = shmti-\u003ebase;\n+\tu32 sign_start, sign_end;\n+\n+\tsign_start = TDCF_START_SIGNATURE(tdcf);\n+\tsign_end = TDCF_END_SIGNATURE(SHMTI_EPLG(shmti));\n+\n+\tif (sign_start != SIGNATURE_START || sign_end != SIGNATURE_END) {\n+\t\tdev_err(dev,\n+\t\t\t\"BAD signature for SHMTI ID:%u @phys:%pK - START:0x%04X END:0x%04X\\n\",\n+\t\t\tshmti-\u003einfo.sid, shmti-\u003ebase, sign_start, sign_end);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int iter_shmti_process_response(const struct scmi_protocol_handle *ph,\n+\t\t\t\t       const void *response,\n+\t\t\t\t       struct scmi_iterator_state *st,\n+\t\t\t\t       void *priv)\n+{\n+\tconst struct scmi_msg_resp_telemetry_shmti_list *r = response;\n+\tstruct telemetry_info *ti = priv;\n+\tstruct telemetry_shmti *shmti;\n+\tconst struct scmi_shmti_desc *desc;\n+\tvoid __iomem *addr;\n+\tu64 phys_addr;\n+\tu32 len;\n+\n+\tdesc = \u0026r-\u003edesc[st-\u003eloop_idx];\n+\tshmti = \u0026ti-\u003eshmti[st-\u003edesc_index + st-\u003eloop_idx];\n+\n+\tshmti-\u003einfo.sid = le32_to_cpu(desc-\u003eid);\n+\tshmti-\u003eflags = le32_to_cpu(desc-\u003eflags);\n+\tphys_addr = le32_to_cpu(desc-\u003eaddr_low);\n+\tphys_addr |= (u64)le32_to_cpu(desc-\u003eaddr_high) \u003c\u003c 32;\n+\n+\tlen = le32_to_cpu(desc-\u003elength);\n+\tif (len \u003c SHMTI_MIN_SIZE) {\n+\t\tdev_err(ph-\u003edev, \"Invalid length for SHMTI ID:%u len:%u\\n\",\n+\t\t\tshmti-\u003einfo.sid, len);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\taddr = devm_ioremap(ph-\u003edev, phys_addr, len);\n+\tif (!addr)\n+\t\treturn -EADDRNOTAVAIL;\n+\n+\tshmti-\u003ebase = addr;\n+\tshmti-\u003einfo.len = len;\n+\tshmti-\u003einfo.phys = phys_addr;\n+\tshmti-\u003einfo.offset = shmti-\u003einfo.phys \u0026 ~PAGE_MASK;\n+\n+\treturn scmi_telemetry_shmti_validate(ph-\u003edev, shmti);\n+}\n+\n+static int scmi_telemetry_shmti_list(const struct scmi_protocol_handle *ph,\n+\t\t\t\t     struct telemetry_info *ti)\n+{\n+\tstruct scmi_iterator_ops ops = {\n+\t\t.prepare_message = iter_tlm_prepare_message,\n+\t\t.update_state = iter_shmti_update_state,\n+\t\t.process_response = iter_shmti_process_response,\n+\t};\n+\tvoid *iter;\n+\n+\titer = ph-\u003ehops-\u003eiter_response_init(ph, \u0026ops, ti-\u003enum_shmti,\n+\t\t\t\t\t    TELEMETRY_LIST_SHMTI,\n+\t\t\t\t\t    sizeof(u32), ti);\n+\tif (IS_ERR(iter))\n+\t\treturn PTR_ERR(iter);\n+\n+\treturn ph-\u003ehops-\u003eiter_response_run(iter);\n+}\n+\n+static int scmi_telemetry_enumerate_shmti(struct telemetry_info *ti)\n+{\n+\tconst struct scmi_protocol_handle *ph = ti-\u003eph;\n+\tstruct scmi_telemetry_shmti_info **shmtis;\n+\tint ret;\n+\n+\tif (!ti-\u003enum_shmti)\n+\t\treturn 0;\n+\n+\tti-\u003eshmti = devm_kcalloc(ph-\u003edev, ti-\u003enum_shmti, sizeof(*ti-\u003eshmti),\n+\t\t\t\t GFP_KERNEL);\n+\tif (!ti-\u003eshmti)\n+\t\treturn -ENOMEM;\n+\n+\tret = scmi_telemetry_shmti_list(ph, ti);\n+\tif (ret) {\n+\t\tdev_err(ph-\u003edev, \"Cannot get SHMTI list descriptors\");\n+\t\treturn ret;\n+\t}\n+\n+\t/* Expose initialized SHMTIs references */\n+\tshmtis = devm_kcalloc(ph-\u003edev, ti-\u003enum_shmti,\n+\t\t\t      sizeof(*shmtis), GFP_KERNEL);\n+\tif (!shmtis)\n+\t\treturn -ENOMEM;\n+\n+\tfor (int i = 0; i \u003c ti-\u003enum_shmti; i++)\n+\t\tshmtis[i] = \u0026ti-\u003eshmti[i].info;\n+\n+\tti-\u003einfo.shmtis = shmtis;\n+\tti-\u003einfo.base.num_shmtis = ti-\u003enum_shmti;\n+\n+\treturn 0;\n+}\n+\n+static const struct scmi_telemetry_info *\n+scmi_telemetry_info_get(const struct scmi_protocol_handle *ph)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\treturn \u0026ti-\u003einfo;\n+}\n+\n+static const struct scmi_telemetry_de *\n+scmi_telemetry_de_lookup(const struct scmi_protocol_handle *ph, u32 id)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\tti-\u003eres_get(ti);\n+\treturn xa_load(\u0026ti-\u003exa_des, id);\n+}\n+\n+static const struct scmi_telemetry_res_info *\n+scmi_telemetry_resources_get(const struct scmi_protocol_handle *ph)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\treturn ti-\u003eres_get(ti);\n+}\n+\n+static u64\n+scmi_telemetry_blkts_read(u32 magic, struct telemetry_block_ts *bts)\n+{\n+\tif (WARN_ON(!bts || !refcount_read(\u0026bts-\u003eline.users)))\n+\t\treturn 0;\n+\n+\tguard(mutex)(\u0026bts-\u003eline.mtx);\n+\n+\tif (bts-\u003eline.last_magic == magic)\n+\t\treturn bts-\u003elast_ts;\n+\n+\t/* Note that the bts-\u003elast_rate can change ONLY on creation */\n+\tbts-\u003elast_ts = BLK_TS_STAMP(\u0026bts-\u003eline.payld-\u003eblk_tsl);\n+\tbts-\u003eline.last_magic = magic;\n+\n+\treturn bts-\u003elast_ts;\n+}\n+\n+static void scmi_telemetry_blkts_update(struct telemetry_info *ti, u32 magic,\n+\t\t\t\t\tstruct telemetry_block_ts *bts)\n+{\n+\tguard(mutex)(\u0026bts-\u003eline.mtx);\n+\n+\tif (bts-\u003eline.last_magic != magic) {\n+\t\tbts-\u003elast_ts = BLK_TS_STAMP(\u0026bts-\u003eline.payld-\u003eblk_tsl);\n+\t\tbts-\u003elast_rate = BLK_TS_RATE(bts-\u003eline.payld);\n+\t\t/* BLK_TS clock rate value can change ONLY here on creation */\n+\t\tif (!bts-\u003elast_rate)\n+\t\t\tbts-\u003elast_rate = ti-\u003edefault_blk_ts_rate;\n+\t\tbts-\u003eline.last_magic = magic;\n+\t}\n+}\n+\n+static void scmi_telemetry_line_put(struct telemetry_line *line, void *blob)\n+{\n+\tif (refcount_dec_and_test(\u0026line-\u003eusers)) {\n+\t\tscoped_guard(mutex, \u0026line-\u003emtx)\n+\t\t\txa_erase(line-\u003exa_lines, (unsigned long)line-\u003epayld);\n+\t\tkfree(blob);\n+\t}\n+}\n+\n+static void scmi_telemetry_blkts_unlink(struct telemetry_de *tde)\n+{\n+\tscmi_telemetry_line_put(\u0026tde-\u003ebts-\u003eline, tde-\u003ebts);\n+\ttde-\u003ebts = NULL;\n+}\n+\n+static void scmi_telemetry_uuid_unlink(struct telemetry_de *tde)\n+{\n+\tscmi_telemetry_line_put(\u0026tde-\u003euuid-\u003eline, tde-\u003euuid);\n+\ttde-\u003euuid = NULL;\n+}\n+\n+static void scmi_telemetry_de_unlink(struct scmi_telemetry_de *de)\n+{\n+\tstruct telemetry_de *tde = to_tde(de);\n+\n+\t/* Unlink all related lines triggering their deallocation */\n+\tif (tde-\u003ebts)\n+\t\tscmi_telemetry_blkts_unlink(tde);\n+\tif (tde-\u003euuid)\n+\t\tscmi_telemetry_uuid_unlink(tde);\n+}\n+\n+static struct telemetry_line *\n+scmi_telemetry_line_get(struct xarray *xa_lines, struct payload __iomem *payld)\n+{\n+\tstruct telemetry_line *line;\n+\n+\tline = xa_load(xa_lines, (unsigned long)payld);\n+\tif (!line)\n+\t\treturn NULL;\n+\n+\trefcount_inc(\u0026line-\u003eusers);\n+\n+\treturn line;\n+}\n+\n+static int\n+scmi_telemetry_line_init(struct telemetry_line *line, struct xarray *xa_lines,\n+\t\t\t struct payload __iomem *payld)\n+{\n+\trefcount_set(\u0026line-\u003eusers, 1);\n+\tline-\u003epayld = payld;\n+\tline-\u003exa_lines = xa_lines;\n+\tmutex_init(\u0026line-\u003emtx);\n+\n+\treturn xa_insert(xa_lines, (unsigned long)payld, line, GFP_KERNEL);\n+}\n+\n+static struct telemetry_block_ts *\n+scmi_telemetry_blkts_create(struct device *dev, struct xarray *xa_lines,\n+\t\t\t    struct payload __iomem *payld)\n+{\n+\tstruct telemetry_block_ts *bts;\n+\tint ret;\n+\n+\tbts = kzalloc_obj(*bts);\n+\tif (!bts)\n+\t\treturn NULL;\n+\n+\tret = scmi_telemetry_line_init(\u0026bts-\u003eline, xa_lines, payld);\n+\tif (ret) {\n+\t\tkfree(bts);\n+\t\treturn NULL;\n+\t}\n+\n+\ttrace_scmi_tlm_collect(0, (__force u64)payld, 0, \"SHMTI_NEW_BLKTS\");\n+\n+\treturn bts;\n+}\n+\n+static struct telemetry_block_ts *\n+scmi_telemetry_blkts_get_or_create(struct device *dev, struct xarray *xa_lines,\n+\t\t\t\t   struct payload __iomem *payld)\n+{\n+\tstruct telemetry_line *line;\n+\n+\tline = scmi_telemetry_line_get(xa_lines, payld);\n+\tif (line)\n+\t\treturn to_blkts(line);\n+\n+\treturn scmi_telemetry_blkts_create(dev, xa_lines, payld);\n+}\n+\n+static struct telemetry_uuid *\n+scmi_telemetry_uuid_create(struct device *dev, struct xarray *xa_lines,\n+\t\t\t   struct payload __iomem *payld)\n+{\n+\tstruct telemetry_uuid *uuid;\n+\tstruct uuid_line __iomem *uuid_l = \u0026payld-\u003euuid_l;\n+\tint ret;\n+\n+\tuuid = kzalloc_obj(*uuid);\n+\tif (!uuid)\n+\t\treturn NULL;\n+\n+\tfor (int i = 0; i \u003c SCMI_TLM_DE_IMPL_MAX_DWORDS; i++)\n+\t\t/*\n+\t\t * Fetch BigEndian in-memory UUID fields as per SCMIv4.0\n+\t\t * specification 3.12.2.2\n+\t\t */\n+\t\tuuid-\u003ede_impl_version[i] = ioread32be(\u0026uuid_l-\u003edwords[i]);\n+\n+\tret = scmi_telemetry_line_init(\u0026uuid-\u003eline, xa_lines, payld);\n+\tif (ret) {\n+\t\tkfree(uuid);\n+\t\treturn NULL;\n+\t}\n+\n+\ttrace_scmi_tlm_collect(0, (__force u64)payld, 0, \"SHMTI_NEW_UUID\");\n+\n+\treturn uuid;\n+}\n+\n+static struct telemetry_uuid *\n+scmi_telemetry_uuid_get_or_create(struct device *dev, struct xarray *xa_lines,\n+\t\t\t\t  struct payload __iomem *payld)\n+{\n+\tstruct telemetry_line *line;\n+\n+\tline = scmi_telemetry_line_get(xa_lines, payld);\n+\tif (line)\n+\t\treturn to_uuid(line);\n+\n+\treturn scmi_telemetry_uuid_create(dev, xa_lines, payld);\n+}\n+\n+static void scmi_telemetry_tdcf_uuid_parse(struct telemetry_info *ti,\n+\t\t\t\t\t   struct payload __iomem *payld,\n+\t\t\t\t\t   struct telemetry_shmti *shmti,\n+\t\t\t\t\t   void **active_uuid)\n+{\n+\tstruct telemetry_uuid *uuid;\n+\n+\tif (UUID_INVALID(payld)) {\n+\t\ttrace_scmi_tlm_access(0, \"UUID_INVALID\", 0, 0);\n+\t\treturn;\n+\t}\n+\n+\t/* A UUID descriptor MUST be returned: it is found or it is created */\n+\tuuid = scmi_telemetry_uuid_get_or_create(ti-\u003eph-\u003edev, \u0026ti-\u003exa_lines,\n+\t\t\t\t\t\t payld);\n+\tif (WARN_ON(!uuid))\n+\t\treturn;\n+\n+\t*active_uuid = uuid;\n+}\n+\n+static struct payload __iomem *\n+scmi_telemetry_nearest_line_by_type(struct telemetry_shmti *shmti,\n+\t\t\t\t    void __iomem *last, enum tdcf_line_types ltype)\n+{\n+\tstruct tdcf __iomem *tdcf = shmti-\u003ebase;\n+\tvoid __iomem *next, *found = NULL;\n+\n+\t/* Scan from start of TDCF payloads up to last_payld */\n+\tnext = tdcf-\u003epayld;\n+\twhile (next \u003c last) {\n+\t\tif (LINE_TYPE((struct payload __iomem *)next) == ltype)\n+\t\t\tfound = next;\n+\n+\t\tnext += LINE_LENGTH_BYTES((struct payload __iomem *)next);\n+\t}\n+\n+\treturn found;\n+}\n+\n+static struct telemetry_block_ts *\n+scmi_telemetry_blkts_bind(struct device *dev, struct telemetry_shmti *shmti,\n+\t\t\t  struct payload __iomem *payld, struct xarray *xa_lines,\n+\t\t\t  struct payload __iomem *bts_payld)\n+{\n+\t/* Trigger a manual search when no BLK_TS payload offset was provided */\n+\tif (!bts_payld) {\n+\t\t/* Find the BLK_TS immediately preceding this DE payld */\n+\t\tbts_payld = scmi_telemetry_nearest_line_by_type(shmti, payld,\n+\t\t\t\t\t\t\t\tTDCF_BLK_TS_LINE);\n+\t\tif (!bts_payld)\n+\t\t\treturn NULL;\n+\t}\n+\n+\treturn scmi_telemetry_blkts_get_or_create(dev, xa_lines, bts_payld);\n+}\n+\n+/**\n+ * scmi_telemetry_tdcf_blkts_parse  - A BLK_TS line parser\n+ *\n+ * @ti: A reference to the telemetry_info descriptor\n+ * @payld: TDCF payld line to process\n+ * @shmti: SHMTI descriptor inside which the scan is happening\n+ * @active_bts: Input/output reference to keep track of the last blk_ts found\n+ *\n+ * Process a valid TDCF BLK_TS line and, after having looked up or created a\n+ * blk_ts descriptor, update the related data and return it as the currently\n+ * active blk_ts, given that it is effectively the last found during this\n+ * scan.\n+ */\n+static void scmi_telemetry_tdcf_blkts_parse(struct telemetry_info *ti,\n+\t\t\t\t\t    struct payload __iomem *payld,\n+\t\t\t\t\t    struct telemetry_shmti *shmti,\n+\t\t\t\t\t    void **active_bts)\n+{\n+\tstruct telemetry_block_ts *bts;\n+\n+\t/* Check for spec compliance */\n+\tif (BLK_TS_INVALID(payld)) {\n+\t\ttrace_scmi_tlm_access(0, \"BLK_TS_INVALID\", 0, 0);\n+\t\treturn;\n+\t}\n+\n+\t/* A BLK_TS descriptor MUST be returned: it is found or it is created */\n+\tbts = scmi_telemetry_blkts_get_or_create(ti-\u003eph-\u003edev,\n+\t\t\t\t\t\t \u0026ti-\u003exa_lines, payld);\n+\tif (WARN_ON(!bts))\n+\t\treturn;\n+\n+\t/* Update the descriptor with the lastest TS */\n+\tscmi_telemetry_blkts_update(ti, shmti-\u003elast_magic, bts);\n+\t*active_bts = bts;\n+}\n+\n+static inline struct telemetry_de *\n+scmi_telemetry_tde_allocate(struct telemetry_info *ti, u32 de_id,\n+\t\t\t    struct payload __iomem *payld)\n+{\n+\tstruct telemetry_de *tde;\n+\n+\ttde = scmi_telemetry_tde_get(ti, de_id);\n+\tif (IS_ERR(tde))\n+\t\treturn NULL;\n+\n+\ttde-\u003ede.info-\u003eid = de_id;\n+\ttde-\u003ede.enabled = true;\n+\ttde-\u003ede.tstamp_enabled = LINE_TS_VALID(payld) || USE_BLK_TS(payld);\n+\n+\tif (scmi_telemetry_tde_register(ti, tde)) {\n+\t\tscmi_telemetry_free_tde_put(ti, tde);\n+\t\treturn NULL;\n+\t}\n+\n+\tscmi_telemetry_de_state_update(ti, ENA_STATE, NULL, true);\n+\tif (tde-\u003ede.tstamp_enabled)\n+\t\tscmi_telemetry_de_state_update(ti, ENA_TSTAMP, NULL, true);\n+\n+\treturn tde;\n+}\n+\n+static inline void\n+scmi_telemetry_line_data_parse(struct telemetry_de *tde,\n+\t\t\t       struct scmi_telemetry_de_sample *sample,\n+\t\t\t       struct payload __iomem *payld, u32 magic)\n+{\n+\t/* Data is always valid since we are NOT handling BLK TS lines here */\n+\tsample-\u003eval = LINE_DATA_GET(\u0026payld-\u003el);\n+\tif (USE_BLK_TS(payld)) {\n+\t\t/* Read out the actual BLK_TS */\n+\t\tsample-\u003etstamp = scmi_telemetry_blkts_read(magic, tde-\u003ebts);\n+\t} else if (LINE_TS_VALID(payld)) {\n+\t\t/*\n+\t\t * Note that LINE_TS_VALID implies HAS_LINE_EXT and that\n+\t\t * the per DE line_ts_rate is advertised in the DE\n+\t\t * descriptor.\n+\t\t */\n+\t\tsample-\u003etstamp = LINE_TSTAMP_GET(\u0026payld-\u003etsl);\n+\t} else {\n+\t\tsample-\u003etstamp = 0;\n+\t}\n+\n+\t/* Trace originally read tstamp */\n+\ttrace_scmi_tlm_collect(sample-\u003etstamp, tde-\u003ede.info-\u003eid,\n+\t\t\t       sample-\u003eval, \"SHMTI_DE_READ\");\n+\n+\tscmi_telemetry_tde_cache_update(tde, sample, \u0026magic);\n+}\n+\n+static inline void scmi_telemetry_bts_link(struct telemetry_de *tde,\n+\t\t\t\t\t   struct telemetry_block_ts *bts)\n+{\n+\tguard(mutex)(\u0026bts-\u003eline.mtx);\n+\trefcount_inc(\u0026bts-\u003eline.users);\n+\ttde-\u003ebts = bts;\n+\t/* Update TS clock rate if provided by the BLK_TS */\n+\tif (tde-\u003ebts-\u003elast_rate)\n+\t\ttde-\u003ede.info-\u003ets_rate = tde-\u003ebts-\u003elast_rate;\n+}\n+\n+static inline void scmi_telemetry_uuid_link(struct telemetry_de *tde,\n+\t\t\t\t\t    struct telemetry_uuid *uuid)\n+{\n+\trefcount_inc(\u0026uuid-\u003eline.users);\n+\ttde-\u003euuid = uuid;\n+}\n+\n+/**\n+ * scmi_telemetry_tdcf_data_parse  - TDCF DataLine parsing\n+ * @ti: A reference to the telemetry info descriptor\n+ * @payld: Line payload to parse\n+ * @shmti: A reference to the containing SHMTI area\n+ * @mode: A flag to determine the behaviour of the scan\n+ * @active_bts: A pointer to keep track and report any found BLK timestamp line\n+ * @active_uuid: A pointer to keep track and report any found UUID line\n+ *\n+ * This routine takes care to:\n+ *  - verify line consistency in relation to the used flags and the current\n+ *    context: e.g. is there an active preceding BLK_TS line if the DataLine\n+ *    sports a USE_BLKTS flag ?\n+ *  - verify the related Data Event ID exists OR create a brand new DE\n+ *    (depending on the @mode of operation)\n+ *  - links any active BLK_TS or UUID line to the current DE\n+ *  - read and save value/tstamp for the DE ONLY if anything has changed (by\n+ *    tracking the last TDCF magic) and update related magic: this allows to\n+ *    minimize future needs of single-DE reads\n+ *\n+ *    Modes of operation.\n+ *\n+ *    The scan behaviour depends on the chosen @mode:\n+ *    - SCAN_LOOKUP: the basic scan which aims to update value associated to\n+ *\t\t     existing DEs. Any discovered DataLine that could NOT be\n+ *\t\t     matched to an existing, previously discovered, DE is\n+ *\t\t     discarded. This is the normal scan behaviour.\n+ *    - SCAN_UPDATE: a more advanced scan which provides all the SCAN_LOOKUP\n+ *\t\t     features plus takes care to update the DEs location\n+ *\t\t     coordinates inside the SHMTI: note that the related DEs are\n+ *\t\t     still supposed to have been previously discovered when\n+ *\t\t     this scan runs. This is used to update location\n+ *\t\t     coordinates for DEs contained in a Group when such group\n+ *\t\t     is enabled.\n+ *    - SCAN_DISCOVERY: the most advanced scan available which provides all\n+ *\t\t\tthe SCAN_LOOKUP features plus discovery capabilities:\n+ *\t\t\tany DataLine referring to a previously unknown DE leads\n+ *\t\t\tto the allocation of a new DE descriptor.\n+ *\t\t\tThis mode is used on the first scan at init time, ONLY\n+ *\t\t\tif Telemetry was found to be already enabled at boot on\n+ *\t\t\tthe platform side: this helps to maximize gathered\n+ *\t\t\tinformation when dealing with out of spec firmwares.\n+ *\t\t\tAny usage of this discovery mode other than in a boot-on\n+ *\t\t\tenabled scenario is discouraged since it can easily\n+ *\t\t\tlead to spurious DE discoveries.\n+ */\n+static void scmi_telemetry_tdcf_data_parse(struct telemetry_info *ti,\n+\t\t\t\t\t   struct payload __iomem *payld,\n+\t\t\t\t\t   struct telemetry_shmti *shmti,\n+\t\t\t\t\t   enum scan_mode mode,\n+\t\t\t\t\t   void *active_bts, void *active_uuid)\n+{\n+\tstruct scmi_telemetry_de_sample sample = {};\n+\tbool use_blk_ts = USE_BLK_TS(payld);\n+\tstruct telemetry_de *tde;\n+\tu32 de_id;\n+\n+\tde_id = PAYLD_ID(payld);\n+\t/* Discard malformed lines...a preceding BLK_TS must exist */\n+\tif (use_blk_ts \u0026\u0026 !active_bts) {\n+\t\ttrace_scmi_tlm_access(de_id, \"BAD_USE_BLK_TS\", 0, 0);\n+\t\treturn;\n+\t}\n+\n+\t/* Is this DE ID known ? */\n+\ttde = scmi_telemetry_tde_lookup(ti, de_id);\n+\tif (!tde) {\n+\t\tif (mode != SCAN_DISCOVERY) {\n+\t\t\ttrace_scmi_tlm_access(de_id, \"DE_INVALID\", 0, 0);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\t/* In SCAN_DISCOVERY mode we allocate new DEs for unknown IDs */\n+\t\ttde = scmi_telemetry_tde_allocate(ti, de_id, payld);\n+\t\tif (!tde)\n+\t\t\treturn;\n+\t}\n+\n+\t/* Update DE location refs if requested: normally done only on enable */\n+\tif (mode \u003e= SCAN_UPDATE) {\n+\t\ttde-\u003ebase = shmti-\u003ebase;\n+\t\ttde-\u003eeplg = SHMTI_EPLG(shmti);\n+\t\ttde-\u003eoffset = (void __iomem *)payld - (void __iomem *)shmti-\u003ebase;\n+\n+\t\tdev_dbg(ti-\u003eph-\u003edev,\n+\t\t\t\"TDCF-updated DE_ID:0x%08X - shmti:%pK  offset:%u\\n\",\n+\t\t\ttde-\u003ede.info-\u003eid, tde-\u003ebase, tde-\u003eoffset);\n+\t}\n+\n+\t/* Has any value/tstamp really changed ?*/\n+\tif (scmi_telemetry_tde_cache_unchanged(tde, shmti-\u003elast_magic))\n+\t\treturn;\n+\n+\t/* Link the related BTS when needed, it's unlinked on disable */\n+\tif (use_blk_ts \u0026\u0026 !tde-\u003ebts)\n+\t\tscmi_telemetry_bts_link(tde, active_bts);\n+\n+\t/* Link the active UUID when existent, it's unlinked on disable */\n+\tif (active_uuid)\n+\t\tscmi_telemetry_uuid_link(tde, active_uuid);\n+\n+\t/* Parse data words ... only for the sake of updating TDE cache */\n+\tscmi_telemetry_line_data_parse(tde, \u0026sample, payld, shmti-\u003elast_magic);\n+}\n+\n+static int scmi_telemetry_tdcf_line_parse(struct telemetry_info *ti,\n+\t\t\t\t\t  struct payload __iomem *payld,\n+\t\t\t\t\t  struct telemetry_shmti *shmti,\n+\t\t\t\t\t  enum scan_mode mode,\n+\t\t\t\t\t  void **active_bts, void **active_uuid)\n+{\n+\tint used_qwords;\n+\n+\tused_qwords = LINE_LENGTH_QWORDS(payld);\n+\t/* Invalid lines are not an error, could simply be disabled DEs */\n+\tif (DATA_INVALID(payld)) {\n+\t\ttrace_scmi_tlm_access(PAYLD_ID(payld), \"TDCF_INVALID\", 0, 0);\n+\t\treturn used_qwords;\n+\t}\n+\n+\tswitch (LINE_TYPE(payld)) {\n+\tcase TDCF_DATA_LINE:\n+\t\tscmi_telemetry_tdcf_data_parse(ti, payld, shmti, mode,\n+\t\t\t\t\t       *active_bts, *active_uuid);\n+\t\tbreak;\n+\tcase TDCF_BLK_TS_LINE:\n+\t\tscmi_telemetry_tdcf_blkts_parse(ti, payld, shmti, active_bts);\n+\t\tbreak;\n+\tcase TDCF_UUID_LINE:\n+\t\tscmi_telemetry_tdcf_uuid_parse(ti, payld, shmti, active_uuid);\n+\t\tbreak;\n+\tdefault:\n+\t\ttrace_scmi_tlm_access(PAYLD_ID(payld), \"TDCF_UNKNOWN\", 0, 0);\n+\t\tbreak;\n+\t}\n+\n+\treturn used_qwords;\n+}\n+\n+/**\n+ * scmi_telemetry_shmti_scan  - Full SHMTI scan\n+ * @ti: A reference to the telemetry info descriptor\n+ * @shmti_id: ID of the SHMTI area that has to be scanned\n+ * @mode: A flag to determine the behaviour of the scan\n+ *\n+ * Return: 0 on Success\n+ */\n+static int scmi_telemetry_shmti_scan(struct telemetry_info *ti,\n+\t\t\t\t     unsigned int shmti_id, enum scan_mode mode)\n+{\n+\tstruct telemetry_shmti *shmti = \u0026ti-\u003eshmti[shmti_id];\n+\tstruct tdcf __iomem *tdcf = shmti-\u003ebase;\n+\tint retries = SCMI_TLM_TDCF_MAX_RETRIES;\n+\tu32 startm = 0, endm = TDCF_BAD_END_SEQ;\n+\n+\tif (!tdcf)\n+\t\treturn -ENODEV;\n+\n+\tdo {\n+\t\tvoid *active_bts = NULL, *active_uuid = NULL;\n+\t\tunsigned int qwords;\n+\t\tvoid __iomem *next;\n+\n+\t\t/* A bit of exponential backoff between retries */\n+\t\tfsleep((SCMI_TLM_TDCF_MAX_RETRIES - retries) * 1000);\n+\n+\t\t/*\n+\t\t * Note that during a full SHMTI scan the magic seq numbers are\n+\t\t * checked only at the start and at the end of the scan, NOT\n+\t\t * between each parsed line and this has these consequences:\n+\t\t *  - TDCF magic numbers accesses are reduced to 2 reads\n+\t\t *  - the set of values obtained from a full scan belong all\n+\t\t *    to the same platform update (same magic number)\n+\t\t *  - a SHMTI full scan is an all or nothing operation: when\n+\t\t *    a potentially corrupted read is detected along the way\n+\t\t *    (MSEQ_MISMATCH) another full scan is triggered.\n+\t\t */\n+\t\tstartm = TDCF_START_SEQ_GET(tdcf);\n+\t\tif (IS_BAD_START_SEQ(startm)) {\n+\t\t\ttrace_scmi_tlm_access(0, \"MSEQ_BADSTART\", startm, 0);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* On a BAD_SEQ this will be updated on the next attempt */\n+\t\tshmti-\u003elast_magic = startm;\n+\n+\t\tqwords = QWORDS(tdcf);\n+\t\tnext = tdcf-\u003epayld;\n+\t\twhile (qwords) {\n+\t\t\tint used_qwords;\n+\n+\t\t\tif (SHMTI_OVERFLOWS(next, shmti)) {\n+\t\t\t\ttrace_scmi_tlm_access(PAYLD_ID(next),\n+\t\t\t\t\t\t      \"SHMTI_OVERFLOW\", startm, 0);\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tused_qwords = scmi_telemetry_tdcf_line_parse(ti, next,\n+\t\t\t\t\t\t\t\t     shmti, mode,\n+\t\t\t\t\t\t\t\t     \u0026active_bts,\n+\t\t\t\t\t\t\t\t     \u0026active_uuid);\n+\t\t\tif (qwords \u003c used_qwords) {\n+\t\t\t\ttrace_scmi_tlm_access(PAYLD_ID(next),\n+\t\t\t\t\t\t      \"BAD_QWORDS\", startm, 0);\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tnext += used_qwords * 8;\n+\t\t\tqwords -= used_qwords;\n+\t\t}\n+\n+\t\tendm = TDCF_END_SEQ_GET(SHMTI_EPLG(shmti));\n+\t\tif (startm != endm)\n+\t\t\ttrace_scmi_tlm_access(0, \"MSEQ_MISMATCH\", startm, endm);\n+\t} while (startm != endm \u0026\u0026 --retries);\n+\n+\tif (startm != endm) {\n+\t\ttrace_scmi_tlm_access(0, \"TDCF_SCAN_FAIL\", startm, endm);\n+\t\treturn -EPROTO;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_group_state_update(struct telemetry_info *ti,\n+\t\t\t\t\t     struct scmi_telemetry_group *grp,\n+\t\t\t\t\t     const bool *enable, const bool *tstamp)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\n+\trinfo = ti-\u003eres_get(ti);\n+\tfor (int i = 0; i \u003c grp-\u003einfo-\u003enum_des; i++) {\n+\t\tstruct scmi_telemetry_de *de = rinfo-\u003edes[grp-\u003edes[i]];\n+\n+\t\tif (enable)\n+\t\t\tscmi_telemetry_de_state_update(ti, ENA_STATE,\n+\t\t\t\t\t\t       \u0026de-\u003eenabled, *enable);\n+\n+\t\tif (tstamp \u0026\u0026 de-\u003etstamp_support)\n+\t\t\tscmi_telemetry_de_state_update(ti, ENA_TSTAMP,\n+\t\t\t\t\t\t       \u0026de-\u003etstamp_enabled, *tstamp);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void scmi_telemetry_group_unlink(struct telemetry_info *ti,\n+\t\t\t\t\tstruct scmi_telemetry_group *grp)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\n+\trinfo = ti-\u003eres_get(ti);\n+\t/* Unlink the related BLK_TS/UUID lines of DEs composing the group */\n+\tfor (int i = 0; i \u003c grp-\u003einfo-\u003enum_des; i++)\n+\t\tscmi_telemetry_de_unlink(rinfo-\u003edes[grp-\u003edes[i]]);\n+}\n+\n+static int\n+scmi_telemetry_state_set_resp_process(struct telemetry_info *ti, void *obj,\n+\t\t\t\t      void *r, bool is_group)\n+{\n+\tstruct scmi_msg_resp_telemetry_de_configure *resp = r;\n+\tu32 sid = le32_to_cpu(resp-\u003eshmti_id);\n+\n+\t/* Update DE SHMTI and offset, if applicable */\n+\tif (IS_SHMTI_ID_VALID(sid)) {\n+\t\tif (sid \u003e= ti-\u003enum_shmti)\n+\t\t\treturn -EPROTO;\n+\n+\t\t/*\n+\t\t * Update SHMTI/offset while skipping non-SHMTI-DEs like\n+\t\t * FCs and notif-only.\n+\t\t */\n+\t\tif (!is_group) {\n+\t\t\tstruct telemetry_de *tde;\n+\t\t\tstruct payload __iomem *payld;\n+\t\t\tstruct scmi_telemetry_de *de = obj;\n+\t\t\tu32 de_offs;\n+\n+\t\t\tde_offs = le32_to_cpu(resp-\u003eshmti_de_offset);\n+\t\t\tpayld = ti-\u003eshmti[sid].base;\n+\t\t\t/* Check boundary first... */\n+\t\t\tif (de_offs + LINE_LENGTH_BYTES(payld) \u003e=\n+\t\t\t    ti-\u003eshmti[sid].info.len)\n+\t\t\t\treturn -EPROTO;\n+\n+\t\t\ttde = to_tde(de);\n+\t\t\t/*...then assign */\n+\t\t\ttde-\u003ebase = ti-\u003eshmti[sid].base;\n+\t\t\ttde-\u003eoffset = de_offs;\n+\t\t\t/* A handy reference to the Epilogue updated */\n+\t\t\ttde-\u003eeplg = SHMTI_EPLG(\u0026ti-\u003eshmti[sid]);\n+\n+\t\t\tpayld = tde-\u003ebase + tde-\u003eoffset;\n+\t\t\tif (USE_BLK_TS(payld) \u0026\u0026 !tde-\u003ebts) {\n+\t\t\t\tstruct payload __iomem *bts_payld;\n+\t\t\t\tu32 bts_offs;\n+\n+\t\t\t\tbts_offs = le32_to_cpu(resp-\u003eblk_ts_offset);\n+\t\t\t\tbts_payld = (bts_offs) ? tde-\u003ebase + bts_offs : NULL;\n+\n+\t\t\t\t/* Check SHMTI overflow on returned offset */\n+\t\t\t\tif (bts_payld \u0026\u0026\n+\t\t\t\t    SHMTI_OVERFLOWS(bts_payld, \u0026ti-\u003eshmti[sid]))\n+\t\t\t\t\treturn -ENOSPC;\n+\n+\t\t\t\ttde-\u003ebts = scmi_telemetry_blkts_bind(ti-\u003eph-\u003edev,\n+\t\t\t\t\t\t\t\t     \u0026ti-\u003eshmti[sid],\n+\t\t\t\t\t\t\t\t     payld,\n+\t\t\t\t\t\t\t\t     \u0026ti-\u003exa_lines,\n+\t\t\t\t\t\t\t\t     bts_payld);\n+\t\t\t\tif (WARN_ON(!tde-\u003ebts))\n+\t\t\t\t\treturn -EPROTO;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tint ret;\n+\n+\t\t\t/*\n+\t\t\t * A full SHMTI scan is needed when enabling a\n+\t\t\t * group or its timestamps in order to retrieve\n+\t\t\t * offsets: note that when group-timestamp is\n+\t\t\t * enabled for composing DEs a re-scan is needed\n+\t\t\t * since some DEs could have been relocated due\n+\t\t\t * to lack of space in the TDCF.\n+\t\t\t */\n+\t\t\tret = scmi_telemetry_shmti_scan(ti, sid, SCAN_UPDATE);\n+\t\t\tif (ret) {\n+\t\t\t\tdev_err(ti-\u003eph-\u003edev,\n+\t\t\t\t\t\"Failed group-scan of SHMTI ID:%d - ret:%d\\n\",\n+\t\t\t\t\tsid, ret);\n+\t\t\t\treturn ret;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\t/* Unlink the related BLK_TS/UUID lines on disable */\n+\t\tif (!is_group)\n+\t\t\tscmi_telemetry_de_unlink(obj);\n+\t\telse\n+\t\t\tscmi_telemetry_group_unlink(ti, obj);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int __scmi_telemetry_state_set(const struct scmi_protocol_handle *ph,\n+\t\t\t\t      bool is_group, const bool *enable,\n+\t\t\t\t      bool *enabled_state, const bool *tstamp,\n+\t\t\t\t      bool *tstamp_enabled_state, void *obj)\n+{\n+\tstruct scmi_msg_resp_telemetry_de_configure *resp;\n+\tstruct scmi_msg_telemetry_de_configure *msg;\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tstruct scmi_telemetry_de *de = !is_group ? obj : NULL;\n+\tstruct scmi_telemetry_group *grp = is_group ? obj : NULL;\n+\tunsigned int obj_id = !is_group ? de-\u003einfo-\u003eid : grp-\u003einfo-\u003egrp_id;\n+\tstruct scmi_xfer *t;\n+\tint ret;\n+\n+\tif (!enabled_state || !tstamp_enabled_state)\n+\t\treturn -EINVAL;\n+\n+\t/* Is anything to do at all on this DE ? */\n+\tif (!is_group \u0026\u0026 (!enable || *enable == *enabled_state) \u0026\u0026\n+\t    (!tstamp || *tstamp == *tstamp_enabled_state))\n+\t\treturn 0;\n+\n+\t/*\n+\t * DE is currently disabled AND no enable state change was requested,\n+\t * while timestamp is being changed: update only local state...no need\n+\t * to send a message.\n+\t */\n+\tif (!is_group \u0026\u0026 !enable \u0026\u0026 !*enabled_state) {\n+\t\tif (de-\u003etstamp_support)\n+\t\t\tscmi_telemetry_de_state_update(ti, ENA_TSTAMP,\n+\t\t\t\t\t\t       tstamp_enabled_state,\n+\t\t\t\t\t\t       *tstamp);\n+\n+\t\t/* A local change can have an impact anyway */\n+\t\tscmi_telemetry_generation_update(ti);\n+\t\treturn 0;\n+\t}\n+\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, TELEMETRY_DE_CONFIGURE,\n+\t\t\t\t      sizeof(*msg), sizeof(*resp), \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmsg = t-\u003etx.buf;\n+\t/* Note that BOTH DE and GROUPS have a first ID field.. */\n+\tmsg-\u003eid = cpu_to_le32(obj_id);\n+\t/* Default to disable mode for one DE */\n+\tmsg-\u003eflags = DE_DISABLE_ONE;\n+\tmsg-\u003eflags |= cpu_to_le32(FIELD_PREP(GENMASK(3, 3),\n+\t\t\t\t is_group ? EVENT_GROUP : EVENT_DE));\n+\n+\tif ((!enable \u0026\u0026 *enabled_state) || (enable \u0026\u0026 *enable)) {\n+\t\t/* Already enabled but tstamp_enabled state changed */\n+\t\tif (tstamp) {\n+\t\t\t/* Here, tstamp cannot be NULL too */\n+\t\t\tmsg-\u003eflags |= cpu_to_le32(*tstamp ?\n+\t\t\t\t\tDE_ENABLE_WTH_TSTAMP : DE_ENABLE_NO_TSTAMP);\n+\t\t} else {\n+\t\t\tmsg-\u003eflags |= cpu_to_le32(*tstamp_enabled_state ?\n+\t\t\t\t\tDE_ENABLE_WTH_TSTAMP : DE_ENABLE_NO_TSTAMP);\n+\t\t}\n+\t}\n+\n+\tresp = t-\u003erx.buf;\n+\tret = ph-\u003exops-\u003edo_xfer(ph, t);\n+\tif (!ret) {\n+\t\tret = scmi_telemetry_state_set_resp_process(ti, obj, resp, is_group);\n+\t\tif (!ret) {\n+\t\t\t/* Update cached state on success */\n+\t\t\tif (enable) {\n+\t\t\t\tif (!is_group)\n+\t\t\t\t\tscmi_telemetry_de_state_update(ti, ENA_STATE,\n+\t\t\t\t\t\t\t\t       enabled_state,\n+\t\t\t\t\t\t\t\t       *enable);\n+\t\t\t\telse\n+\t\t\t\t\t*enabled_state = *enable;\n+\t\t\t}\n+\t\t\tif (tstamp) {\n+\t\t\t\tif (!is_group) {\n+\t\t\t\t\tif (de-\u003etstamp_support)\n+\t\t\t\t\t\tscmi_telemetry_de_state_update(ti, ENA_TSTAMP,\n+\t\t\t\t\t\t\t\t\t       tstamp_enabled_state,\n+\t\t\t\t\t\t\t\t\t       *tstamp);\n+\t\t\t\t} else {\n+\t\t\t\t\t*tstamp_enabled_state = *tstamp;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tif (is_group)\n+\t\t\t\tscmi_telemetry_group_state_update(ti, grp, enable,\n+\t\t\t\t\t\t\t\t  tstamp);\n+\t\t}\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\tif (!ret)\n+\t\tscmi_telemetry_generation_update(ti);\n+\n+\treturn ret;\n+}\n+\n+static int scmi_telemetry_state_get(const struct scmi_protocol_handle *ph,\n+\t\t\t\t    const u32 *id, bool *enabled, bool *tstamp_enabled)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tstruct scmi_telemetry_de *de;\n+\n+\tif (!enabled || !tstamp_enabled)\n+\t\treturn -EINVAL;\n+\n+\tif (!id) {\n+\t\t/* Returning the all_des_* state */\n+\t\t*enabled =\n+\t\t\t(atomic_read(\u0026ti-\u003edes_enabled[ENA_STATE]) == ti-\u003einfo.base.num_des);\n+\t\t*tstamp_enabled =\n+\t\t\t(atomic_read(\u0026ti-\u003edes_enabled[ENA_TSTAMP]) == ti-\u003enum_des_tstamp);\n+\n+\t\treturn 0;\n+\t}\n+\n+\tde = xa_load(\u0026ti-\u003exa_des, *id);\n+\tif (!de)\n+\t\treturn -ENODEV;\n+\n+\t*enabled = de-\u003eenabled;\n+\t*tstamp_enabled = de-\u003etstamp_enabled;\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_state_set(const struct scmi_protocol_handle *ph,\n+\t\t\t\t    bool is_group, u32 id, const bool *enable,\n+\t\t\t\t    const bool *tstamp)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tbool *enabled_state, *tstamp_enabled_state;\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\tvoid *obj;\n+\n+\trinfo = ti-\u003eres_get(ti);\n+\tif (!is_group) {\n+\t\tstruct scmi_telemetry_de *de;\n+\n+\t\tde = xa_load(\u0026ti-\u003exa_des, id);\n+\t\tif (!de)\n+\t\t\treturn -ENODEV;\n+\n+\t\tenabled_state = \u0026de-\u003eenabled;\n+\t\ttstamp_enabled_state = \u0026de-\u003etstamp_enabled;\n+\t\tobj = de;\n+\t} else {\n+\t\tstruct scmi_telemetry_group *grp;\n+\n+\t\tif (id \u003e= ti-\u003einfo.base.num_groups)\n+\t\t\treturn -EINVAL;\n+\n+\t\tgrp = \u0026rinfo-\u003egrps[id];\n+\n+\t\tenabled_state = \u0026grp-\u003eenabled;\n+\t\ttstamp_enabled_state = \u0026grp-\u003etstamp_enabled;\n+\t\tobj = grp;\n+\t}\n+\n+\treturn __scmi_telemetry_state_set(ph, is_group, enable, enabled_state,\n+\t\t\t\t\t  tstamp, tstamp_enabled_state, obj);\n+}\n+\n+static int scmi_telemetry_all_disable(const struct scmi_protocol_handle *ph,\n+\t\t\t\t      bool is_group)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tstruct scmi_msg_telemetry_de_configure *msg;\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\tstruct scmi_xfer *t;\n+\tint ret;\n+\n+\trinfo = ti-\u003eres_get(ti);\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, TELEMETRY_DE_CONFIGURE,\n+\t\t\t\t      sizeof(*msg), 0, \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmsg = t-\u003etx.buf;\n+\tmsg-\u003eflags = cpu_to_le32(DE_DISABLE_ALL);\n+\tif (is_group)\n+\t\tmsg-\u003eflags |= cpu_to_le32(GROUP_SELECTOR);\n+\tret = ph-\u003exops-\u003edo_xfer(ph, t);\n+\tif (!ret) {\n+\t\tfor (int i = 0; i \u003c rinfo-\u003enum_des; i++)\n+\t\t\tscmi_telemetry_de_state_update(ti, ENA_STATE,\n+\t\t\t\t\t\t       \u0026rinfo-\u003edes[i]-\u003eenabled,\n+\t\t\t\t\t\t       false);\n+\t\tif (is_group) {\n+\t\t\tfor (int i = 0; i \u003c ti-\u003einfo.base.num_groups; i++) {\n+\t\t\t\trinfo-\u003egrps[i].enabled = false;\n+\t\t\t\tscmi_telemetry_group_unlink(ti, \u0026rinfo-\u003egrps[i]);\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\tif (!ret)\n+\t\tscmi_telemetry_generation_update(ti);\n+\n+\treturn ret;\n+}\n+\n+static int\n+scmi_telemetry_collection_configure(const struct scmi_protocol_handle *ph,\n+\t\t\t\t    unsigned int res_id, const bool *enable,\n+\t\t\t\t    const unsigned int *update_interval_ms,\n+\t\t\t\t    const enum scmi_telemetry_collection *mode)\n+{\n+\tbool tlm_enable, is_group = res_id != SCMI_TLM_GRP_INVALID;\n+\tenum scmi_telemetry_collection *current_mode, next_mode;\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tstruct scmi_msg_telemetry_config_set *msg;\n+\tunsigned int *active_update_interval;\n+\tstruct scmi_xfer *t;\n+\t__le32 interval;\n+\tu32 control;\n+\tint ret;\n+\n+\tif (mode \u0026\u0026 *mode == SCMI_TLM_NOTIFICATION \u0026\u0026\n+\t    !ti-\u003einfo.continuos_update_support)\n+\t\treturn -EINVAL;\n+\n+\tif (is_group \u0026\u0026 res_id \u003e= ti-\u003einfo.base.num_groups)\n+\t\treturn -EINVAL;\n+\n+\tif (!is_group) {\n+\t\tactive_update_interval = \u0026ti-\u003einfo.active_update_interval;\n+\t\tcurrent_mode = \u0026ti-\u003einfo.current_mode;\n+\t} else {\n+\t\tstruct scmi_telemetry_res_info *rinfo;\n+\n+\t\trinfo = ti-\u003eres_get(ti);\n+\t\tactive_update_interval =\n+\t\t\t\u0026rinfo-\u003egrps[res_id].active_update_interval;\n+\t\tcurrent_mode = \u0026rinfo-\u003egrps[res_id].current_mode;\n+\t}\n+\n+\tif (!enable \u0026\u0026 !update_interval_ms \u0026\u0026 (!mode || *mode == *current_mode))\n+\t\treturn 0;\n+\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, TELEMETRY_CONFIG_SET,\n+\t\t\t\t      sizeof(*msg), 0, \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (!update_interval_ms)\n+\t\tinterval = cpu_to_le32(*active_update_interval);\n+\telse\n+\t\tinterval = cpu_to_le32(*update_interval_ms);\n+\n+\ttlm_enable = enable ? *enable : ti-\u003einfo.enabled;\n+\tnext_mode = mode ? *mode : *current_mode;\n+\n+\tmsg = t-\u003etx.buf;\n+\tmsg-\u003egrp_id = cpu_to_le32(res_id);\n+\tcontrol = tlm_enable ? TELEMETRY_ENABLE : 0;\n+\tcontrol |= !is_group ? TELEMETRY_SET_SELECTOR_ALL : TELEMETRY_SET_SELECTOR_GROUP;\n+\tcontrol |= TELEMETRY_MODE_SET(next_mode);\n+\tmsg-\u003econtrol = cpu_to_le32(control);\n+\tmsg-\u003esampling_rate = interval;\n+\tret = ph-\u003exops-\u003edo_xfer(ph, t);\n+\tif (!ret) {\n+\t\tti-\u003einfo.enabled = tlm_enable;\n+\t\t*current_mode = next_mode;\n+\t\tti-\u003einfo.notif_enabled = *current_mode == SCMI_TLM_NOTIFICATION;\n+\t\tif (update_interval_ms)\n+\t\t\t*active_update_interval = le32_to_cpu(interval);\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\tif (!ret)\n+\t\tscmi_telemetry_generation_update(ti);\n+\n+\treturn ret;\n+}\n+\n+static inline void\n+scmi_telemetry_de_data_fc_read(struct telemetry_de *tde,\n+\t\t\t       struct scmi_telemetry_de_sample *sample)\n+{\n+\tstruct fc_tsline __iomem *fc = tde-\u003ebase + tde-\u003eoffset;\n+\n+\tsample-\u003eval = LINE_DATA_GET(fc);\n+\tsample-\u003etstamp = LINE_TSTAMP_GET(fc);\n+\n+\t/* Trace originally read tstamp */\n+\ttrace_scmi_tlm_collect(sample-\u003etstamp, tde-\u003ede.info-\u003eid, sample-\u003eval,\n+\t\t\t       \"FC_READ\");\n+\n+\tscmi_telemetry_tde_cache_update(tde, sample, NULL);\n+}\n+\n+static void scmi_telemetry_scan_update(struct telemetry_info *ti)\n+{\n+\tstruct telemetry_de *tde;\n+\n+\t/* Scan all SHMTIs ... */\n+\tfor (int id = 0; id \u003c ti-\u003enum_shmti; id++) {\n+\t\tint ret;\n+\n+\t\tret = scmi_telemetry_shmti_scan(ti, id, SCAN_LOOKUP);\n+\t\tif (ret)\n+\t\t\tdev_warn(ti-\u003eph-\u003edev,\n+\t\t\t\t \"Failed update-scan of SHMTI ID:%d - ret:%d\\n\",\n+\t\t\t\t id, ret);\n+\t}\n+\n+\tif (!ti-\u003einfo.fc_support)\n+\t\treturn;\n+\n+\t/* Need to enumerate resources to access fastchannels */\n+\tti-\u003eres_get(ti);\n+\tlist_for_each_entry(tde, \u0026ti-\u003efcs_des, item) {\n+\t\tstruct scmi_telemetry_de_sample sample = {};\n+\n+\t\tif (!tde-\u003ede.enabled)\n+\t\t\tcontinue;\n+\n+\t\t/* Only for the sake of updating TDE cache */\n+\t\tscmi_telemetry_de_data_fc_read(tde, \u0026sample);\n+\t}\n+}\n+\n+/*\n+ * TDCF and TS Line Management Notes\n+ * ---------------------------------\n+ *\n+ * TDCF Payload Metadata notable bits:\n+ *  - Bit[3]: USE BLK Tstamp\n+ *  - Bit[2]: Line-Extension Field present (LineTstamp)\n+ *  - Bit[1]: Tstamp VALID\n+ *  - Bit[0]: Data INVALID\n+ *\n+ * CASE_1:\n+ * -------\n+ *\t+ A DE is enabled with timestamp disabled, so the TS fields are\n+ *\t  NOT present\n+ *\t  -\u003e BIT[3:0] = 0000b\n+ *\n+ *\t  - 1/A LINE_TSTAMP\n+ *\t  ------------------\n+ *\t     + that DE is then 're-enabled' with TS: so it was ON, it remains\n+ *\t       ON but using DE_CONFIGURE I now enabled also TS, so the\n+ *\t       platform relocates it at the end of the SHMTI and return the\n+ *\t       new offset\n+ *\t       -\u003e BIT[3:0] = 0110b\n+ *\n+ *\t  - 1/B BLK_TSTAMP\n+ *\t  ------------------\n+ *\t     + that DE is then 're-enabled' with BLK TS: so it was ON, it\n+ *\t       remains ON but using DE_CONFIGURE, we now also enabled the TS,\n+ *\t       so the platform will:\n+ *\t       - IF a preceding BLK_TS line exist (with same clk rate)\n+ *\t         it relocates the DE at the end of the SHMTI and return the\n+ *\t         new offset (if there is enough room, if not in another SHMTI)\n+ *\t       - IF a preceding BLK_TS line DOES NOT exist (with same clk rate)\n+ *\t         it creates a new BLK_TS line at the end of the SHMTI and then\n+ *\t         relocates the DE after the new BLK_TS and return the\n+ *\t         new offset (if there is enough room, if not in another SHMTI)\n+ *\t       -\u003e BIT[3:1] = 1010b\n+ *\n+ *\t+ the hole left from the relocated DE can be reused by the platform\n+ *\tto fit another equally sized DE. (i.e. without shuffling around any\n+ *\tother enabled DE, since that would cause a change of the known offset)\n+ *\tanyway it will be marked as:\n+ *\t-\u003e BIT[3:0] = 0101b iff it was a LINE_TSTAMP\n+ *\t-\u003e BIT[3:0] = 0001b iff it was a BLK_TSTAMP\n+ *\n+ * CASE_2:\n+ * -------\n+ *\t+ A DE is enabled with LINE timestamp enabled, so the TS_Line is there\n+ *\t  -\u003e BIT[3:0] = 0110b\n+ *\t+ that DE has its timestamp disabled: again, you can do this without\n+ *\t  disabling it fully but just disabling the TS, so now that TS_line\n+ *\t  fields are still physically there but NOT valid\n+ *\t  -\u003e BIT[3:0] = 0100b\n+ *\t+ the hole from the timestamp remain there unused until\n+ *\t\t- you enable again the TS so the hole is used again\n+ *\t\t  -\u003e BIT[3:0] = 0110b\n+ *\t\t\tOR\n+ *\t\t- you disable fully the DE and then re-enable it with the TS\n+ *\t\t  -\u003e potentially CASE_1 the DE is relocated on enable\n+ *\t+ same kind of dynamic applies if the DE had a BLK_TS line\n+ */\n+static struct payload __iomem *\n+scmi_telemetry_tdcf_de_payld_get(struct telemetry_de *tde)\n+{\n+\tstruct payload __iomem *payld;\n+\n+\tpayld = tde-\u003ebase + tde-\u003eoffset;\n+\tif (DATA_INVALID(payld)) {\n+\t\ttrace_scmi_tlm_access(PAYLD_ID(payld), \"DE_DATA_INVALID\", 0, 0);\n+\t\treturn IOMEM_ERR_PTR(-EINVAL);\n+\t}\n+\n+\tif (IS_BLK_TS_LINE(payld)) {\n+\t\ttrace_scmi_tlm_access(tde-\u003ede.info-\u003eid, \"BAD_DE_META\", 0, 0);\n+\t\treturn IOMEM_ERR_PTR(-EPROTO);\n+\t}\n+\n+\tif (PAYLD_ID(payld) != tde-\u003ede.info-\u003eid) {\n+\t\ttrace_scmi_tlm_access(tde-\u003ede.info-\u003eid, \"DE_ID_MISMATCH\", 0, 0);\n+\t\treturn IOMEM_ERR_PTR(-ENODEV);\n+\t}\n+\n+\t/*\n+\t * A valid line using BLK_TS should have been initialized with the\n+\t * related BLK_TS when enabled.\n+\t */\n+\tif (WARN_ON((USE_BLK_TS(payld) \u0026\u0026 !tde-\u003ebts))) {\n+\t\ttrace_scmi_tlm_access(tde-\u003ede.info-\u003eid, \"BAD_USE_BLK_TS\", 0, 0);\n+\t\treturn IOMEM_ERR_PTR(-EPROTO);\n+\t}\n+\n+\treturn payld;\n+}\n+\n+static int\n+scmi_telemetry_tdcf_de_parse(struct telemetry_de *tde,\n+\t\t\t     struct scmi_telemetry_de_sample *sample)\n+{\n+\tint retries = SCMI_TLM_TDCF_MAX_RETRIES;\n+\tstruct tdcf __iomem *tdcf = tde-\u003ebase;\n+\tu32 startm = 0, endm = TDCF_BAD_END_SEQ;\n+\n+\tif (!tdcf)\n+\t\treturn -ENODEV;\n+\n+\tdo {\n+\t\tstruct payload __iomem *payld;\n+\t\tint err;\n+\n+\t\t/* A bit of exponential backoff between retries */\n+\t\tfsleep((SCMI_TLM_TDCF_MAX_RETRIES - retries) * 1000);\n+\n+\t\tstartm = TDCF_START_SEQ_GET(tdcf);\n+\t\tif (IS_BAD_START_SEQ(startm)) {\n+\t\t\ttrace_scmi_tlm_access(tde-\u003ede.info-\u003eid, \"MSEQ_BADSTART\",\n+\t\t\t\t\t      startm, 0);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Return last readings if nothing changed */\n+\t\terr = scmi_telemetry_tde_cache_lookup(tde, sample, \u0026startm);\n+\t\tif (!err)\n+\t\t\treturn 0;\n+\n+\t\t/* Retry also when payld get gave a transient error (-EINVAL) */\n+\t\tpayld = scmi_telemetry_tdcf_de_payld_get(tde);\n+\t\tif (!IS_ERR(payld))\n+\t\t\tscmi_telemetry_line_data_parse(tde, sample, payld, startm);\n+\t\telse if (PTR_ERR(payld) != -EINVAL)\n+\t\t\treturn PTR_ERR(payld);\n+\n+\t\tendm = TDCF_END_SEQ_GET(tde-\u003eeplg);\n+\t\tif (startm != endm)\n+\t\t\ttrace_scmi_tlm_access(tde-\u003ede.info-\u003eid, \"MSEQ_MISMATCH\",\n+\t\t\t\t\t      startm, endm);\n+\t} while (startm != endm \u0026\u0026 --retries);\n+\n+\tif (startm != endm) {\n+\t\ttrace_scmi_tlm_access(tde-\u003ede.info-\u003eid, \"TDCF_DE_FAIL\",\n+\t\t\t\t      startm, endm);\n+\t\treturn -EPROTO;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_de_access(struct telemetry_de *tde,\n+\t\t\t\t    struct scmi_telemetry_de_sample *sample)\n+{\n+\tif (!tde-\u003ede.fc_support)\n+\t\treturn scmi_telemetry_tdcf_de_parse(tde, sample);\n+\n+\tscmi_telemetry_de_data_fc_read(tde, sample);\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_de_collect(struct telemetry_info *ti,\n+\t\t\t\t     struct scmi_telemetry_de *de,\n+\t\t\t\t     struct scmi_telemetry_de_sample *sample)\n+{\n+\tstruct telemetry_de *tde = to_tde(de);\n+\n+\tif (!de-\u003eenabled)\n+\t\treturn -ENODATA;\n+\n+\t/*\n+\t * DE readings returns cached values when:\n+\t *  - DE data value was retrieved via notification/delayed_response\n+\t */\n+\tif (tde-\u003ecached_msg)\n+\t\treturn scmi_telemetry_tde_cache_lookup(tde, sample, NULL);\n+\n+\treturn scmi_telemetry_de_access(tde, sample);\n+}\n+\n+static int scmi_telemetry_de_data_read(const struct scmi_protocol_handle *ph,\n+\t\t\t\t       struct scmi_telemetry_de_sample *sample)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tstruct scmi_telemetry_de *de;\n+\n+\tif (!ti-\u003einfo.enabled || !sample)\n+\t\treturn -ENODATA;\n+\n+\tde = xa_load(\u0026ti-\u003exa_des, sample-\u003eid);\n+\tif (!de)\n+\t\treturn -ENOENT;\n+\n+\treturn scmi_telemetry_de_collect(ti, de, sample);\n+}\n+\n+static int\n+scmi_telemetry_samples_collect(struct telemetry_info *ti, int grp_id,\n+\t\t\t       int *num_samples,\n+\t\t\t       struct scmi_telemetry_de_sample *samples)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\tint max_samples;\n+\n+\tmax_samples = *num_samples;\n+\t*num_samples = 0;\n+\n+\trinfo = ti-\u003eres_get(ti);\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_des; i++) {\n+\t\tstruct scmi_telemetry_de *de;\n+\n+\t\tde = rinfo-\u003edes[i];\n+\t\t/* Skip disabled DEs and not belonging to the selected Group */\n+\t\tif (!de-\u003eenabled ||\n+\t\t    (grp_id != SCMI_TLM_GRP_INVALID \u0026\u0026\n+\t\t     (!de-\u003egrp || de-\u003egrp-\u003einfo-\u003egrp_id != grp_id)))\n+\t\t\tcontinue;\n+\n+\t\t/* Must be checked here to skip disabled and non selected */\n+\t\tif (*num_samples == max_samples)\n+\t\t\treturn -ENOSPC;\n+\n+\t\t/* Note that this cannot fail when passing a NULL magic */\n+\t\tscmi_telemetry_tde_cache_lookup(to_tde(de),\n+\t\t\t\t\t\t\u0026samples[(*num_samples)++], NULL);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_des_bulk_read(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\tint grp_id, int *num_samples,\n+\t\t\t\t\tstruct scmi_telemetry_de_sample *samples)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\tif (!ti-\u003einfo.enabled || !num_samples || !samples)\n+\t\treturn -EINVAL;\n+\n+\t/* Trigger a full SHMTIs \u0026 FCs scan */\n+\tscmi_telemetry_scan_update(ti);\n+\n+\t/* Collect all last cached values */\n+\treturn scmi_telemetry_samples_collect(ti, grp_id, num_samples, samples);\n+}\n+\n+static void\n+scmi_telemetry_msg_payld_process(struct telemetry_info *ti,\n+\t\t\t\t unsigned int num_dwords, u32 *dwords,\n+\t\t\t\t size_t payld_bytes)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\tu32 next = 0;\n+\n+\trinfo = ti-\u003eres_get(ti);\n+\tif (!rinfo-\u003efully_enumerated) {\n+\t\tdev_warn_once(ti-\u003eph-\u003edev,\n+\t\t\t      \"Cannot process DEs in message payload. Drop.\\n\");\n+\t\treturn;\n+\t}\n+\n+\twhile (next \u003c num_dwords) {\n+\t\tstruct payload *payld = (struct payload *)\u0026dwords[next];\n+\t\tstruct scmi_telemetry_de_sample sample = {};\n+\t\tstruct scmi_telemetry_de *de;\n+\t\tstruct telemetry_de *tde;\n+\t\tunsigned int wlen;\n+\t\tu32 de_id;\n+\n+\t\twlen = LINE_LENGTH_WORDS_RAW(payld-\u003emeta);\n+\t\t/* Check Boundary */\n+\t\tif (next + wlen \u003e payld_bytes / sizeof(u32))\n+\t\t\treturn;\n+\n+\t\tnext += wlen;\n+\t\tif (DATA_INVALID_RAW(payld-\u003emeta)) {\n+\t\t\ttrace_scmi_tlm_access(payld-\u003eid, \"MSG_INVALID\", 0, 0);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tde_id = le32_to_cpu(payld-\u003eid);\n+\t\tde = xa_load(\u0026ti-\u003exa_des, de_id);\n+\t\tif (!de || !de-\u003eenabled) {\n+\t\t\ttrace_scmi_tlm_access(de_id, de ? \"MSG_DE_DISABLED\" :\n+\t\t\t\t\t      \"MSG_DE_UNKNOWN\", 0, 0);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\ttde = to_tde(de);\n+\t\tscoped_guard(mutex, \u0026tde-\u003emtx) {\n+\t\t\ttde-\u003ecached_msg = true;\n+\t\t\ttde-\u003elast_val = LINE_DATA_GET_RAW(\u0026payld-\u003etsl);\n+\t\t\t/* TODO BLK_TS in notification payloads */\n+\t\t\ttde-\u003elast_ts = HAS_LINE_EXT_RAW(payld-\u003emeta) \u0026\u0026\n+\t\t\t\tLINE_TS_VALID_RAW(payld-\u003emeta) ?\n+\t\t\t\tLINE_TSTAMP_GET_RAW(\u0026payld-\u003etsl) : 0;\n+\t\t\tsample.val = tde-\u003elast_val;\n+\t\t\tsample.tstamp = tde-\u003elast_ts;\n+\t\t}\n+\n+\t\t/* Trace originally read tstamp */\n+\t\ttrace_scmi_tlm_collect(sample.tstamp, de-\u003einfo-\u003eid, sample.val,\n+\t\t\t\t       \"MESSAGE\");\n+\n+\t\tscmi_telemetry_tde_cache_update(tde, \u0026sample, NULL);\n+\t}\n+}\n+\n+static int scmi_telemetry_des_sample_get(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\t int grp_id, int *num_samples,\n+\t\t\t\t\t struct scmi_telemetry_de_sample *samples)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\tstruct scmi_msg_telemetry_config_set *msg;\n+\tstruct scmi_xfer *t;\n+\tbool is_group;\n+\tu32 control;\n+\tint ret;\n+\n+\tif (!ti-\u003einfo.enabled || !num_samples || !samples)\n+\t\treturn -EINVAL;\n+\n+\tis_group = grp_id != SCMI_TLM_GRP_INVALID;\n+\tif (is_group \u0026\u0026 grp_id \u003e= ti-\u003einfo.base.num_groups)\n+\t\treturn -EINVAL;\n+\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, TELEMETRY_CONFIG_SET,\n+\t\t\t\t      sizeof(*msg), 0, \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmsg = t-\u003etx.buf;\n+\tmsg-\u003egrp_id = cpu_to_le32(grp_id);\n+\tcontrol = TELEMETRY_ENABLE;\n+\tcontrol |= !is_group ? TELEMETRY_SET_SELECTOR_ALL :\n+\t\tTELEMETRY_SET_SELECTOR_GROUP;\n+\tcontrol |= TELEMETRY_MODE_SINGLE;\n+\tmsg-\u003econtrol = cpu_to_le32(control);\n+\tmsg-\u003esampling_rate = 0;\n+\n+\tret = ph-\u003exops-\u003edo_xfer_with_response(ph, t);\n+\tif (!ret) {\n+\t\tstruct scmi_msg_resp_telemetry_reading_complete *r = t-\u003erx.buf;\n+\n+\t\t/* Update cached DEs values from payload */\n+\t\tif (r-\u003enum_dwords)\n+\t\t\tscmi_telemetry_msg_payld_process(ti, le32_to_cpu(r-\u003enum_dwords),\n+\t\t\t\t\t\t\t (u32 *)r-\u003edwords,\n+\t\t\t\t\t\t\t t-\u003erx.len - sizeof(*r));\n+\n+\t\t/* Scan and update SMHTIs and FCs */\n+\t\tscmi_telemetry_scan_update(ti);\n+\n+\t\t/* Collect all last cached values */\n+\t\tret = scmi_telemetry_samples_collect(ti, grp_id, num_samples,\n+\t\t\t\t\t\t     samples);\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\treturn ret;\n+}\n+\n+static void scmi_telemetry_local_resources_reset(struct telemetry_info *ti)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo;\n+\n+\tti-\u003einfo.enabled = false;\n+\tti-\u003einfo.notif_enabled = false;\n+\tti-\u003einfo.current_mode = SCMI_TLM_ONDEMAND;\n+\n+\t/* Get rinfo as it is...without triggering an enumeration */\n+\trinfo = __scmi_telemetry_resources_get(ti);\n+\t/* Clear all local state...*/\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_des; i++) {\n+\t\trinfo-\u003edes[i]-\u003eenabled = false;\n+\t\trinfo-\u003edes[i]-\u003etstamp_enabled = false;\n+\n+\t\tscmi_telemetry_de_unlink(rinfo-\u003edes[i]);\n+\t}\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_groups; i++) {\n+\t\trinfo-\u003egrps[i].enabled = false;\n+\t\trinfo-\u003egrps[i].tstamp_enabled = false;\n+\t\trinfo-\u003egrps[i].current_mode = SCMI_TLM_ONDEMAND;\n+\t\trinfo-\u003egrps[i].active_update_interval = 0;\n+\t}\n+\n+\tatomic_set(\u0026ti-\u003edes_enabled[ENA_STATE], 0);\n+\tatomic_set(\u0026ti-\u003edes_enabled[ENA_TSTAMP], 0);\n+}\n+\n+static int scmi_telemetry_reset(const struct scmi_protocol_handle *ph)\n+{\n+\tstruct scmi_xfer *t;\n+\tint ret;\n+\n+\tret = ph-\u003exops-\u003exfer_get_init(ph, TELEMETRY_RESET, sizeof(u32), 0, \u0026t);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tput_unaligned_le32(0, t-\u003etx.buf);\n+\tret = ph-\u003exops-\u003edo_xfer(ph, t);\n+\tif (!ret) {\n+\t\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\t\tscmi_telemetry_local_resources_reset(ti);\n+\n+\t\t/* Reset generation now that server has been reset */\n+\t\tscmi_telemetry_generation_reset(ti);\n+\n+\t\t/* Fetch again the states from platform. */\n+\t\tret = scmi_telemetry_initial_state_lookup(ti);\n+\t\tif (ret)\n+\t\t\tdev_warn(ph-\u003edev,\n+\t\t\t\t FW_BUG \"Cannot retrieve initial state after reset.\\n\");\n+\t}\n+\n+\tph-\u003exops-\u003exfer_put(ph, t);\n+\n+\treturn ret;\n+}\n+\n+static struct wait_queue_head *\n+scmi_telemetry_event_wq_get(const struct scmi_protocol_handle *ph)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\treturn \u0026ti-\u003egen_wq;\n+}\n+\n+static const struct scmi_telemetry_proto_ops tlm_proto_ops = {\n+\t.info_get = scmi_telemetry_info_get,\n+\t.de_lookup = scmi_telemetry_de_lookup,\n+\t.res_get = scmi_telemetry_resources_get,\n+\t.state_get = scmi_telemetry_state_get,\n+\t.state_set = scmi_telemetry_state_set,\n+\t.all_disable = scmi_telemetry_all_disable,\n+\t.collection_configure = scmi_telemetry_collection_configure,\n+\t.de_data_read = scmi_telemetry_de_data_read,\n+\t.des_bulk_read = scmi_telemetry_des_bulk_read,\n+\t.des_sample_get = scmi_telemetry_des_sample_get,\n+\t.reset = scmi_telemetry_reset,\n+\t.event_wq_get = scmi_telemetry_event_wq_get,\n+};\n+\n+static bool\n+scmi_telemetry_notify_supported(const struct scmi_protocol_handle *ph,\n+\t\t\t\tu8 evt_id, u32 src_id)\n+{\n+\tstruct telemetry_info *ti = ph-\u003eget_priv(ph);\n+\n+\treturn ti-\u003einfo.continuos_update_support;\n+}\n+\n+static int\n+scmi_telemetry_set_notify_enabled(const struct scmi_protocol_handle *ph,\n+\t\t\t\t  u8 evt_id, u32 src_id, bool enable)\n+{\n+\treturn 0;\n+}\n+\n+static void *\n+scmi_telemetry_fill_custom_report(const struct scmi_protocol_handle *ph,\n+\t\t\t\t  u8 evt_id, ktime_t timestamp,\n+\t\t\t\t  const void *payld, size_t payld_sz,\n+\t\t\t\t  void *report, u32 *src_id)\n+{\n+\tconst struct scmi_telemetry_update_notify_payld *p = payld;\n+\tstruct scmi_telemetry_update_report *r = report;\n+\n+\t/* At least sized as an empty notification */\n+\tif (payld_sz \u003c sizeof(*p))\n+\t\treturn NULL;\n+\n+\tr-\u003etimestamp = timestamp;\n+\tr-\u003eagent_id = le32_to_cpu(p-\u003eagent_id);\n+\tr-\u003estatus = le32_to_cpu(p-\u003estatus);\n+\tr-\u003enum_dwords = le32_to_cpu(p-\u003enum_dwords);\n+\n+\tif (r-\u003enum_dwords * sizeof(r-\u003edwords[0]) \u003e payld_sz)\n+\t\treturn NULL;\n+\n+\t/*\n+\t * Allocated dwords and report are sized as max_msg_size, so as\n+\t * to allow for the maximum payload permitted by the configured\n+\t * transport. Overflow is not possible since out-of-size messages\n+\t * are dropped at the transport layer.\n+\t */\n+\tif (r-\u003enum_dwords)\n+\t\tmemcpy_from_le32(r-\u003edwords, p-\u003earray, r-\u003enum_dwords);\n+\n+\t*src_id = 0;\n+\n+\treturn r;\n+}\n+\n+static const struct scmi_event tlm_events[] = {\n+\t{\n+\t\t.id = SCMI_EVENT_TELEMETRY_UPDATE,\n+\t\t.max_payld_sz = 0,\n+\t\t.max_report_sz = 0,\n+\t},\n+};\n+\n+static const struct scmi_event_ops tlm_event_ops = {\n+\t.is_notify_supported = scmi_telemetry_notify_supported,\n+\t.set_notify_enabled = scmi_telemetry_set_notify_enabled,\n+\t.fill_custom_report = scmi_telemetry_fill_custom_report,\n+};\n+\n+static const struct scmi_protocol_events tlm_protocol_events = {\n+\t.queue_sz = SCMI_PROTO_QUEUE_SZ,\n+\t.ops = \u0026tlm_event_ops,\n+\t.evts = tlm_events,\n+\t.num_events = ARRAY_SIZE(tlm_events),\n+\t.num_sources = 1,\n+};\n+\n+static int scmi_telemetry_notifier(struct notifier_block *nb,\n+\t\t\t\t   unsigned long event, void *data)\n+{\n+\tstruct scmi_telemetry_update_report *er = data;\n+\tstruct telemetry_info *ti = telemetry_nb_to_info(nb);\n+\n+\tif (er-\u003estatus) {\n+\t\ttrace_scmi_tlm_access(0, \"BAD_NOTIF_MSG\", 0, 0);\n+\t\treturn NOTIFY_DONE;\n+\t}\n+\n+\ttrace_scmi_tlm_access(0, \"TLM_UPDATE_MSG\", 0, 0);\n+\t/* Lookup the embedded DEs in the notification payload ... */\n+\tif (er-\u003enum_dwords) {\n+\t\tsize_t payld_bytes = sizeof(er-\u003edwords[0]) * er-\u003enum_dwords;\n+\n+\t\t/* The report payload size was bound checked on rx */\n+\t\tscmi_telemetry_msg_payld_process(ti, er-\u003enum_dwords, er-\u003edwords,\n+\t\t\t\t\t\t payld_bytes);\n+\t}\n+\n+\t/* ...scan the SHMTI/FCs for any other DE updates. */\n+\tif (ti-\u003estreaming_mode)\n+\t\tscmi_telemetry_scan_update(ti);\n+\n+\treturn NOTIFY_OK;\n+}\n+\n+/**\n+ * scmi_telemetry_resources_alloc  - Resources allocation\n+ * @ti: A reference to the telemetry info descriptor for this instance\n+ *\n+ * This allocates and initializes dedicated resources for the maximum possible\n+ * number of needed telemetry resources, based on information gathered from\n+ * the initial enumeration: these allocations represent an upper bound on\n+ * the number of discoverable telemetry resources and they will be later\n+ * populated during late deferred further discovery phases.\n+ *\n+ * Return: 0 on Success, errno otherwise\n+ */\n+static int scmi_telemetry_resources_alloc(struct telemetry_info *ti)\n+{\n+\t/* Array to hold pointers to discovered DEs */\n+\tstruct scmi_telemetry_de **des __free(kfree) =\n+\t\tkcalloc(ti-\u003einfo.base.num_des, sizeof(*des), GFP_KERNEL);\n+\tif (!des)\n+\t\treturn -ENOMEM;\n+\n+\t/* The allocated DE descriptors */\n+\tstruct telemetry_de *tdes __free(kfree) =\n+\t\tkcalloc(ti-\u003einfo.base.num_des, sizeof(*tdes), GFP_KERNEL);\n+\tif (!tdes)\n+\t\treturn -ENOMEM;\n+\n+\t/* Allocate a set of contiguous DE info descriptors. */\n+\tstruct scmi_telemetry_de_info *dei_store __free(kfree) =\n+\t\tkcalloc(ti-\u003einfo.base.num_des, sizeof(*dei_store), GFP_KERNEL);\n+\tif (!dei_store)\n+\t\treturn -ENOMEM;\n+\n+\t/* Array to hold descriptors of discovered GROUPs */\n+\tstruct scmi_telemetry_group *grps __free(kfree) =\n+\t\tkcalloc(ti-\u003einfo.base.num_groups, sizeof(*grps), GFP_KERNEL);\n+\tif (!grps)\n+\t\treturn -ENOMEM;\n+\n+\t/* Allocate a set of contiguous Group info descriptors. */\n+\tstruct scmi_telemetry_grp_info *grps_store __free(kfree) =\n+\t\tkcalloc(ti-\u003einfo.base.num_groups, sizeof(*grps_store), GFP_KERNEL);\n+\tif (!grps_store)\n+\t\treturn -ENOMEM;\n+\n+\tstruct scmi_telemetry_res_info *rinfo __free(kfree) =\n+\t\tkzalloc(sizeof(*rinfo), GFP_KERNEL);\n+\tif (!rinfo)\n+\t\treturn -ENOMEM;\n+\n+\tmutex_init(\u0026ti-\u003efree_mtx);\n+\tINIT_LIST_HEAD(\u0026ti-\u003efree_des);\n+\tfor (int i = 0; i \u003c ti-\u003einfo.base.num_des; i++) {\n+\t\tmutex_init(\u0026tdes[i].mtx);\n+\t\t/* Bind contiguous DE info structures */\n+\t\ttdes[i].de.info = \u0026dei_store[i];\n+\t\tlist_add_tail(\u0026tdes[i].item, \u0026ti-\u003efree_des);\n+\t}\n+\n+\tfor (int i = 0; i \u003c ti-\u003einfo.base.num_groups; i++) {\n+\t\tgrps_store[i].grp_id = i;\n+\t\t/* Bind contiguous Group info struct */\n+\t\tgrps[i].info = \u0026grps_store[i];\n+\t}\n+\n+\tINIT_LIST_HEAD(\u0026ti-\u003efcs_des);\n+\n+\tti-\u003etdes = no_free_ptr(tdes);\n+\n+\trinfo-\u003edes = no_free_ptr(des);\n+\trinfo-\u003edei_store = no_free_ptr(dei_store);\n+\trinfo-\u003egrps = no_free_ptr(grps);\n+\trinfo-\u003egrps_store = no_free_ptr(grps_store);\n+\n+\tti-\u003erinfo = no_free_ptr(rinfo);\n+\n+\treturn 0;\n+}\n+\n+static void scmi_telemetry_groups_free(struct scmi_telemetry_res_info *rinfo)\n+{\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_groups; i++) {\n+\t\tstruct scmi_telemetry_group *grp = \u0026rinfo-\u003egrps[i];\n+\n+\t\tkfree(grp-\u003edes);\n+\t\tkfree(grp-\u003edes_str);\n+\t\tkfree(grp-\u003eintervals);\n+\t}\n+}\n+\n+static void scmi_telemetry_resources_free(void *arg)\n+{\n+\tstruct telemetry_info *ti = arg;\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\n+\t/*\n+\t * Unlinking all the BLK_TS/UUID lines related to a DE triggers also\n+\t * the deallocation of such lines when the embedded refcount hits zero.\n+\t */\n+\tfor (int i = 0; i \u003c rinfo-\u003enum_des; i++)\n+\t\tscmi_telemetry_de_unlink(rinfo-\u003edes[i]);\n+\n+\txa_destroy(\u0026ti-\u003exa_des);\n+\txa_destroy(\u0026ti-\u003exa_lines);\n+\tkfree(ti-\u003etdes);\n+\tkfree(rinfo-\u003edes);\n+\tkfree(rinfo-\u003edei_store);\n+\tscmi_telemetry_groups_free(rinfo);\n+\tkfree(rinfo-\u003egrps);\n+\tkfree(rinfo-\u003egrps_store);\n+\n+\tkfree(rinfo);\n+\n+\tti-\u003erinfo = NULL;\n+}\n+\n+static struct scmi_telemetry_res_info *\n+__scmi_telemetry_resources_get(struct telemetry_info *ti)\n+{\n+\treturn ti-\u003erinfo;\n+}\n+\n+/**\n+ * scmi_telemetry_resources_enumerate  - Enumeration helper\n+ * @ti: A reference to the telemetry info descriptor for this instance\n+ *\n+ * This helper is configured to be called once on the first enumeration\n+ * attempt, when triggered by invoking ti-\u003eres_get() from somewhere else.\n+ * Once run it substitues itself in ti-\u003eres_get() with the simple accessor\n+ * __scmi_telemetry_resources_get, which returns a descriptor to the resources\n+ * that were possibly discovered.\n+ *\n+ * Note that, while it attempts to fully enumerate Data Events and Groups, it\n+ * does NOT fail when such enumerations fail, instead it simply gives up with\n+ * the end result that only a partially populated, but consistent, resources\n+ * descriptor will be returned; in such a case the incomplete descriptor will\n+ * be marked as NOT fully_enumerated: this design enables the kernel to deal\n+ * with badly implemented out-of-spec firmware support while keep on providing\n+ * a minimal sane, albeit possibly incomplete, set of telemetry respources.\n+ *\n+ * Return: A reference to a fully or partially populated resources descriptor\n+ */\n+static struct scmi_telemetry_res_info *\n+scmi_telemetry_resources_enumerate(struct telemetry_info *ti)\n+{\n+\tstruct scmi_telemetry_res_info *rinfo = ti-\u003erinfo;\n+\tstruct device *dev = ti-\u003eph-\u003edev;\n+\tint ret;\n+\n+\t/*\n+\t * Ensure this init function can be called only once and\n+\t * handles properly concurrent calls.\n+\t */\n+\tif (atomic_cmpxchg(\u0026ti-\u003erinfo_initializing, 0, 1)) {\n+\t\tif (!completion_done(\u0026ti-\u003erinfo_initdone))\n+\t\t\twait_for_completion(\u0026ti-\u003erinfo_initdone);\n+\t\tgoto out;\n+\t}\n+\n+\tret = scmi_telemetry_de_descriptors_get(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot fully enumerate DEs resources. Degraded system.\\n\");\n+\t\tgoto done;\n+\t}\n+\n+\tret = scmi_telemetry_enumerate_groups_intervals(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot fully enumerate group intervals. Degraded system.\\n\");\n+\t\tgoto done;\n+\t}\n+\n+\t/* If we got here, the enumeration was fully successful */\n+\trinfo-\u003efully_enumerated = true;\n+done:\n+\t/* Disable initialization permanently */\n+\tsmp_store_mb(ti-\u003eres_get, __scmi_telemetry_resources_get);\n+\tcomplete_all(\u0026ti-\u003erinfo_initdone);\n+\n+out:\n+\treturn rinfo;\n+}\n+\n+/**\n+ * scmi_telemetry_instance_init  - Instance initializer\n+ * @ti: A reference to the telemetry info descriptor for this instance\n+ *\n+ * Note that this allocates and initialize all the resources possibly needed\n+ * and then setups the @scmi_telemetry_resources_enumerate helper as the\n+ * default method for the first call to ti-\u003eres_get(): this mechanism enables\n+ * the possibility of optionally implementing deferred enumeration policies\n+ * which optionally delay the discovery phase and related SCMI message exchanges\n+ * to a later point in time.\n+ *\n+ * Return: 0 on Success, errno otherwise\n+ */\n+static int scmi_telemetry_instance_init(struct telemetry_info *ti)\n+{\n+\tint ret;\n+\n+\t/* Allocate and Initialize on first call... */\n+\tret = scmi_telemetry_resources_alloc(ti);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\txa_init(\u0026ti-\u003exa_des);\n+\txa_init(\u0026ti-\u003exa_lines);\n+\tret = devm_add_action_or_reset(ti-\u003eph-\u003edev,\n+\t\t\t\t       scmi_telemetry_resources_free, ti);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Generation counter init */\n+\tatomic_set(\u0026ti-\u003einfo.generation, SCMI_TLM_GENERATION_ONE);\n+\tinit_waitqueue_head(\u0026ti-\u003egen_wq);\n+\tatomic_set(\u0026ti-\u003edes_enabled[ENA_STATE], 0);\n+\tatomic_set(\u0026ti-\u003edes_enabled[ENA_TSTAMP], 0);\n+\t/* Setup resources lazy initialization */\n+\tatomic_set(\u0026ti-\u003erinfo_initializing, 0);\n+\tinit_completion(\u0026ti-\u003erinfo_initdone);\n+\t/* Ensure the new res_get() operation is visible after this point */\n+\tsmp_store_mb(ti-\u003eres_get, scmi_telemetry_resources_enumerate);\n+\n+\treturn 0;\n+}\n+\n+static int scmi_telemetry_protocol_init(const struct scmi_protocol_handle *ph)\n+{\n+\tstruct device *dev = ph-\u003edev;\n+\tstruct telemetry_info *ti;\n+\tint ret;\n+\n+\tdev_dbg(dev, \"Telemetry Version %d.%d\\n\",\n+\t\tPROTOCOL_REV_MAJOR(ph-\u003eversion), PROTOCOL_REV_MINOR(ph-\u003eversion));\n+\n+\tti = devm_kzalloc(dev, sizeof(*ti), GFP_KERNEL);\n+\tif (!ti)\n+\t\treturn -ENOMEM;\n+\n+\tti-\u003eph = ph;\n+\n+\tret = scmi_telemetry_protocol_attributes_get(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot retrieve protocol attributes. Abort.\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tret = scmi_telemetry_instance_init(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Cannot initialize instance. Abort.\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tret = scmi_telemetry_enumerate_common_intervals(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot enumerate update intervals. Abort.\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tret = scmi_telemetry_enumerate_shmti(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot enumerate SHMTIs. Abort.\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tret = scmi_telemetry_initial_state_lookup(ti);\n+\tif (ret) {\n+\t\tdev_err(dev, FW_BUG \"Cannot retrieve initial state. Abort.\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tti-\u003einfo.base.version = ph-\u003eversion;\n+\n+\tret = ph-\u003eset_priv(ph, ti);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * Register a notifier anyway straight upon protocol initialization\n+\t * since there could be some DEs that are ONLY reported by notifications\n+\t * even though the chosen collection method was SHMTI/FCs.\n+\t */\n+\tif (ti-\u003einfo.continuos_update_support) {\n+\t\tti-\u003etelemetry_nb.notifier_call = \u0026scmi_telemetry_notifier;\n+\t\tret = ph-\u003einstance_notifier_register(ph, SCMI_EVENT_TELEMETRY_UPDATE,\n+\t\t\t\t\t\t     NULL, \u0026ti-\u003etelemetry_nb);\n+\t\tif (ret) {\n+\t\t\tdev_err(ph-\u003edev,\n+\t\t\t\t\"Could NOT register Telemetry notifier\\n\");\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\tif (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_PROTOCOLS))\n+\t\tscmi_telemetry_debugfs_initialize(ti);\n+\n+\treturn 0;\n+}\n+\n+static const struct scmi_protocol scmi_telemetry = {\n+\t.id = SCMI_PROTOCOL_TELEMETRY,\n+\t.owner = THIS_MODULE,\n+\t.instance_init = \u0026scmi_telemetry_protocol_init,\n+\t.ops = \u0026tlm_proto_ops,\n+\t.events = \u0026tlm_protocol_events,\n+\t.supported_version = SCMI_PROTOCOL_SUPPORTED_VERSION,\n+};\n+\n+DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(telemetry, scmi_telemetry)\ndiff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h\nindex 5ab73b1ab9aa4f..8dc65de424481d 100644\n--- a/include/linux/scmi_protocol.h\n+++ b/include/linux/scmi_protocol.h\n@@ -2,16 +2,18 @@\n /*\n  * SCMI Message Protocol driver header\n  *\n- * Copyright (C) 2018-2021 ARM Ltd.\n+ * Copyright (C) 2018-2026 ARM Ltd.\n  */\n \n #ifndef _LINUX_SCMI_PROTOCOL_H\n #define _LINUX_SCMI_PROTOCOL_H\n \n #include \u003clinux/bitfield.h\u003e\n+#include \u003clinux/bitops.h\u003e\n #include \u003clinux/device.h\u003e\n #include \u003clinux/notifier.h\u003e\n #include \u003clinux/types.h\u003e\n+#include \u003clinux/wait.h\u003e\n \n #define SCMI_MAX_STR_SIZE\t\t64\n #define SCMI_SHORT_NAME_MAX_SIZE\t16\n@@ -824,6 +826,230 @@ struct scmi_pinctrl_proto_ops {\n \tint (*pin_free)(const struct scmi_protocol_handle *ph, u32 pin);\n };\n \n+enum scmi_telemetry_de_type {\n+\tSCMI_TLM_DE_TYPE_USPECIFIED,\n+\tSCMI_TLM_DE_TYPE_ACCUMUL_IDLE_RESIDENCY,\n+\tSCMI_TLM_DE_TYPE_ACCUMUL_IDLE_COUNTS,\n+\tSCMI_TLM_DE_TYPE_ACCUMUL_OTHERS,\n+\tSCMI_TLM_DE_TYPE_INSTA_IDLE_STATE,\n+\tSCMI_TLM_DE_TYPE_INSTA_OTHERS,\n+\tSCMI_TLM_DE_TYPE_AVERAGE,\n+\tSCMI_TLM_DE_TYPE_STATUS,\n+\tSCMI_TLM_DE_TYPE_RESERVED_START,\n+\tSCMI_TLM_DE_TYPE_RESERVED_END = 0xef,\n+\tSCMI_TLM_DE_TYPE_OEM_START = 0xf0,\n+\tSCMI_TLM_DE_TYPE_OEM_END = 0xff,\n+};\n+\n+enum scmi_telemetry_compo_type {\n+\tSCMI_TLM_COMPO_TYPE_USPECIFIED,\n+\tSCMI_TLM_COMPO_TYPE_CPU,\n+\tSCMI_TLM_COMPO_TYPE_CLUSTER,\n+\tSCMI_TLM_COMPO_TYPE_GPU,\n+\tSCMI_TLM_COMPO_TYPE_NPU,\n+\tSCMI_TLM_COMPO_TYPE_INTERCONNECT,\n+\tSCMI_TLM_COMPO_TYPE_MEM_CNTRL,\n+\tSCMI_TLM_COMPO_TYPE_L1_CACHE,\n+\tSCMI_TLM_COMPO_TYPE_L2_CACHE,\n+\tSCMI_TLM_COMPO_TYPE_L3_CACHE,\n+\tSCMI_TLM_COMPO_TYPE_LL_CACHE,\n+\tSCMI_TLM_COMPO_TYPE_SYS_CACHE,\n+\tSCMI_TLM_COMPO_TYPE_DISP_CNTRL,\n+\tSCMI_TLM_COMPO_TYPE_IPU,\n+\tSCMI_TLM_COMPO_TYPE_CHIPLET,\n+\tSCMI_TLM_COMPO_TYPE_PACKAGE,\n+\tSCMI_TLM_COMPO_TYPE_SOC,\n+\tSCMI_TLM_COMPO_TYPE_SYSTEM,\n+\tSCMI_TLM_COMPO_TYPE_SMCU,\n+\tSCMI_TLM_COMPO_TYPE_ACCEL,\n+\tSCMI_TLM_COMPO_TYPE_BATTERY,\n+\tSCMI_TLM_COMPO_TYPE_CHARGER,\n+\tSCMI_TLM_COMPO_TYPE_PMIC,\n+\tSCMI_TLM_COMPO_TYPE_BOARD,\n+\tSCMI_TLM_COMPO_TYPE_MEMORY,\n+\tSCMI_TLM_COMPO_TYPE_PERIPH,\n+\tSCMI_TLM_COMPO_TYPE_PERIPH_SUBC,\n+\tSCMI_TLM_COMPO_TYPE_LID,\n+\tSCMI_TLM_COMPO_TYPE_DISPLAY,\n+\tSCMI_TLM_COMPO_TYPE_RESERVED_START = 0x1d,\n+\tSCMI_TLM_COMPO_TYPE_RESERVED_END = 0xdf,\n+\tSCMI_TLM_COMPO_TYPE_OEM_START = 0xe0,\n+\tSCMI_TLM_COMPO_TYPE_OEM_END = 0xff,\n+};\n+\n+#define\tSCMI_TLM_GET_UPDATE_INTERVAL_SECS(x)\t(FIELD_GET(GENMASK(20, 5), (x)))\n+#define SCMI_TLM_GET_UPDATE_INTERVAL_EXP(x)\t(sign_extend32((x), 4))\n+\n+#define SCMI_TLM_GET_UPDATE_INTERVAL(x)\t\t(FIELD_GET(GENMASK(20, 0), (x)))\n+#define SCMI_TLM_BUILD_UPDATE_INTERVAL(s, e)\t\t\t\t    \\\n+\t(FIELD_PREP(GENMASK(20, 5), (s)) | FIELD_PREP(GENMASK(4, 0), (e)))\n+\n+enum scmi_telemetry_collection {\n+\tSCMI_TLM_ONDEMAND,\n+\tSCMI_TLM_NOTIFICATION,\n+\tSCMI_TLM_SINGLE_READ,\n+};\n+\n+#define SCMI_TLM_GENERATION_INVALID\t0U\n+#define SCMI_TLM_GRP_INVALID\t\t0xFFFFFFFF\n+#define SCMI_TLM_DE_IMPL_MAX_DWORDS\t4\n+\n+struct scmi_telemetry_intervals {\n+\tunsigned int grp_id;\n+\tbool discrete;\n+\tunsigned int num_intervals;\n+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_LOW\t0\n+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_HIGH\t1\n+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_STEP\t2\n+\tunsigned int update_intervals[] __counted_by(num_intervals);\n+};\n+\n+struct scmi_telemetry_grp_info {\n+\tunsigned int grp_id;\n+\tunsigned int num_des;\n+\tunsigned int num_intervals;\n+};\n+\n+struct scmi_telemetry_group {\n+\tbool enabled;\n+\tbool tstamp_enabled;\n+\tunsigned int *des;\n+\tchar *des_str;\n+\tstruct scmi_telemetry_grp_info *info;\n+\tunsigned int active_update_interval;\n+\tstruct scmi_telemetry_intervals *intervals;\n+\tenum scmi_telemetry_collection current_mode;\n+};\n+\n+struct scmi_telemetry_de_info {\n+\tunsigned int id;\n+\tunsigned int grp_id;\n+\tunsigned int data_sz;\n+\tunsigned int type;\n+\tunsigned int unit;\n+\tint unit_exp;\n+\tunsigned int ts_rate;\n+\tunsigned int instance_id;\n+\tunsigned int compo_instance_id;\n+\tunsigned int compo_type;\n+\tbool persistent;\n+\tchar name[16];\n+};\n+\n+struct scmi_telemetry_de {\n+\tbool tstamp_support;\n+\tbool fc_support;\n+\tbool name_support;\n+\tstruct scmi_telemetry_de_info *info;\n+\tstruct scmi_telemetry_group *grp;\n+\tbool enabled;\n+\tbool tstamp_enabled;\n+};\n+\n+struct scmi_telemetry_res_info {\n+\tbool fully_enumerated;\n+\tunsigned int num_des;\n+\tstruct scmi_telemetry_de **des;\n+\tstruct scmi_telemetry_de_info *dei_store;\n+\tunsigned int num_groups;\n+\tstruct scmi_telemetry_group *grps;\n+\tstruct scmi_telemetry_grp_info *grps_store;\n+};\n+\n+struct scmi_telemetry_base_info {\n+\tunsigned int version;\n+\tunsigned int de_impl_version[SCMI_TLM_DE_IMPL_MAX_DWORDS];\n+\tunsigned int num_des;\n+\tunsigned int num_groups;\n+\tunsigned int num_intervals;\n+\tunsigned int num_shmtis;\n+};\n+\n+struct scmi_telemetry_shmti_info {\n+\tunsigned int sid;\n+\tunsigned int len;\n+\tunsigned long offset;\n+\tphys_addr_t phys;\n+};\n+\n+struct scmi_telemetry_info {\n+\tbool single_read_support;\n+\tbool continuos_update_support;\n+\tbool per_group_config_support;\n+\tbool reset_support;\n+\tbool fc_support;\n+\tstruct scmi_telemetry_base_info base;\n+\tunsigned int active_update_interval;\n+\tstruct scmi_telemetry_intervals *intervals;\n+\tstruct scmi_telemetry_shmti_info **shmtis;\n+\tbool enabled;\n+\tbool notif_enabled;\n+\tenum scmi_telemetry_collection current_mode;\n+\tatomic_t generation;\n+};\n+\n+struct scmi_telemetry_de_sample {\n+\tunsigned int id;\n+\tunsigned int pad;\n+\tunsigned long long tstamp;\n+\tunsigned long long val;\n+};\n+\n+/**\n+ * struct scmi_telemetry_proto_ops - represents the various operations provided\n+ *\tby SCMI Telemetry Protocol\n+ *\n+ * @info_get: get the general Telemetry information.\n+ * @de_lookup: get a specific DE descriptor from the DE id.\n+ * @res_get: get a reference to the Telemetry resources descriptor.\n+ * @state_get: retrieve the specific DE or GROUP state, if NULL returns the\n+ *\t       cumulative state of all DEs.\n+ * @state_set: enable/disable the specific DE or GROUP with or without timestamps.\n+ * @all_disable: disable ALL DEs or GROUPs.\n+ * @collection_configure: choose a sampling rate and enable SHMTI/FC sampling\n+ *\t\t\t  for on demand collection via @de_data_read or async\n+ *\t\t\t  notificatioins for all the enabled DEs.\n+ * @de_data_read: on-demand read of a single DE and related optional timestamp:\n+ *\t\t  the value will be retrieved at the proper SHMTI offset OR\n+ *\t\t  from the dedicated FC area (if supported by that DE).\n+ * @des_bulk_read: on-demand read of all the currently enabled DEs, or just\n+ *\t\t   the ones belonging to a specific group when provided.\n+ * @des_sample_get: on-demand read of all the currently enabled DEs, or just\n+ *\t\t    the ones belonging to a specific group when provided.\n+ *\t\t    This causes an immediate update platform-side of all the\n+ *\t\t    enabled DEs.\n+ * @reset: reset configuration and telemetry data.\n+ * @event_wq_get: get a reference to the event waitqueue for this instance.\n+ */\n+struct scmi_telemetry_proto_ops {\n+\tconst struct scmi_telemetry_info __must_check *(*info_get)\n+\t\t(const struct scmi_protocol_handle *ph);\n+\tconst struct scmi_telemetry_de __must_check *(*de_lookup)\n+\t\t(const struct scmi_protocol_handle *ph, u32 id);\n+\tconst struct scmi_telemetry_res_info __must_check *(*res_get)\n+\t\t(const struct scmi_protocol_handle *ph);\n+\tint (*state_get)(const struct scmi_protocol_handle *ph,\n+\t\t\t const u32 *id, bool *enabled, bool *tstamp_enabled);\n+\tint (*state_set)(const struct scmi_protocol_handle *ph,\n+\t\t\t bool is_group, u32 id, const bool *enable,\n+\t\t\t const bool *tstamp);\n+\tint (*all_disable)(const struct scmi_protocol_handle *ph, bool group);\n+\tint (*collection_configure)(const struct scmi_protocol_handle *ph,\n+\t\t\t\t    unsigned int res_id, const bool *enable,\n+\t\t\t\t    const unsigned int *update_interval_ms,\n+\t\t\t\t    const enum scmi_telemetry_collection *mode);\n+\tint __must_check (*de_data_read)(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\t struct scmi_telemetry_de_sample *sample);\n+\tint __must_check (*des_bulk_read)(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\t  int grp_id, int *num_samples,\n+\t\t\t\t\t  struct scmi_telemetry_de_sample *samples);\n+\tint __must_check (*des_sample_get)(const struct scmi_protocol_handle *ph,\n+\t\t\t\t\t   int grp_id, int *num_samples,\n+\t\t\t\t\t   struct scmi_telemetry_de_sample *samples);\n+\tint (*reset)(const struct scmi_protocol_handle *ph);\n+\tstruct wait_queue_head *(*event_wq_get)(const struct scmi_protocol_handle *ph);\n+};\n+\n /**\n  * struct scmi_notify_ops  - represents notifications' operations provided by\n  * SCMI core\n@@ -884,6 +1110,10 @@ struct scmi_notify_ops {\n /**\n  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.\n  *\n+ * @id: A unique positive natural integer identifying the SCMI Instance\n+ *\tassociated with this handle to be used across all drivers for\n+ *\tnaming purposes: same identifier used internally as the root for\n+ *\tthe debugfs per-instance tree.\n  * @dev: pointer to the SCMI device\n  * @version: pointer to the structure containing SCMI version information\n  * @devm_protocol_acquire: devres managed method to get hold of a protocol,\n@@ -904,6 +1134,7 @@ struct scmi_notify_ops {\n  * @notify_ops: pointer to set of notifications related operations\n  */\n struct scmi_handle {\n+\tunsigned int id;\n \tstruct device *dev;\n \tstruct scmi_base_info *version;\n \n@@ -915,7 +1146,6 @@ struct scmi_handle {\n \tvoid (*devm_protocol_put)(struct scmi_device *sdev, u8 proto);\n \tbool (*is_transport_atomic)(const struct scmi_handle *handle,\n \t\t\t\t    unsigned int *atomic_threshold);\n-\n \tconst struct scmi_notify_ops *notify_ops;\n };\n \n@@ -930,6 +1160,7 @@ enum scmi_std_protocol {\n \tSCMI_PROTOCOL_VOLTAGE = 0x17,\n \tSCMI_PROTOCOL_POWERCAP = 0x18,\n \tSCMI_PROTOCOL_PINCTRL = 0x19,\n+\tSCMI_PROTOCOL_TELEMETRY = 0x1b,\n };\n \n enum scmi_system_events {\n@@ -1028,6 +1259,7 @@ enum scmi_notification_events {\n \tSCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,\n \tSCMI_EVENT_POWERCAP_CAP_CHANGED = 0x0,\n \tSCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED = 0x1,\n+\tSCMI_EVENT_TELEMETRY_UPDATE = 0x0,\n };\n \n struct scmi_power_state_changed_report {\n@@ -1115,4 +1347,12 @@ struct scmi_powercap_meas_changed_report {\n \tunsigned int\tdomain_id;\n \tunsigned int\tpower;\n };\n+\n+struct scmi_telemetry_update_report {\n+\tktime_t\t\ttimestamp;\n+\tunsigned int\tagent_id;\n+\tint\t\tstatus;\n+\tunsigned int\tnum_dwords;\n+\tunsigned int\tdwords[];\n+};\n #endif /* _LINUX_SCMI_PROTOCOL_H */\ndiff --git a/include/trace/events/scmi.h b/include/trace/events/scmi.h\nindex 703b7bb68e4429..b70b26e467b8db 100644\n--- a/include/trace/events/scmi.h\n+++ b/include/trace/events/scmi.h\n@@ -7,7 +7,8 @@\n \n #include \u003clinux/tracepoint.h\u003e\n \n-#define TRACE_SCMI_MAX_TAG_LEN\t6\n+#define TRACE_SCMI_MAX_TAG_LEN\t\t6\n+#define TRACE_SCMI_TLM_MAX_TAG_LEN\t16\n \n TRACE_EVENT(scmi_fc_call,\n \tTP_PROTO(u8 protocol_id, u8 msg_id, u32 res_id, u32 val1, u32 val2),\n@@ -180,6 +181,51 @@ TRACE_EVENT(scmi_msg_dump,\n \t\t  __entry-\u003etag, __entry-\u003emsg_id, __entry-\u003eseq, __entry-\u003estatus,\n \t\t__print_hex_str(__get_dynamic_array(cmd), __entry-\u003elen))\n );\n+\n+TRACE_EVENT(scmi_tlm_access,\n+\tTP_PROTO(u64 de_id, unsigned char *tag, u64 startm, u64 endm),\n+\tTP_ARGS(de_id, tag, startm, endm),\n+\n+\tTP_STRUCT__entry(\n+\t\t__field(u64, de_id)\n+\t\t__array(char, tag, TRACE_SCMI_TLM_MAX_TAG_LEN)\n+\t\t__field(u64, startm)\n+\t\t__field(u64, endm)\n+\t),\n+\n+\tTP_fast_assign(\n+\t\t__entry-\u003ede_id = de_id;\n+\t\tstrscpy(__entry-\u003etag, tag, TRACE_SCMI_TLM_MAX_TAG_LEN);\n+\t\t__entry-\u003estartm = startm;\n+\t\t__entry-\u003eendm = endm;\n+\t),\n+\n+\tTP_printk(\"de_id=0x%llX [%s] - startm=%016llX endm=%016llX\",\n+\t\t  __entry-\u003ede_id, __entry-\u003etag, __entry-\u003estartm, __entry-\u003eendm)\n+);\n+\n+TRACE_EVENT(scmi_tlm_collect,\n+\tTP_PROTO(u64 ts, u64 de_id, u64 value, unsigned char *tag),\n+\tTP_ARGS(ts, de_id, value, tag),\n+\n+\tTP_STRUCT__entry(\n+\t\t__field(u64, ts)\n+\t\t__field(u64, de_id)\n+\t\t__field(u64, value)\n+\t\t__array(char, tag, TRACE_SCMI_TLM_MAX_TAG_LEN)\n+\t),\n+\n+\tTP_fast_assign(\n+\t\t__entry-\u003ets = ts;\n+\t\t__entry-\u003ede_id = de_id;\n+\t\t__entry-\u003evalue = value;\n+\t\tstrscpy(__entry-\u003etag, tag, TRACE_SCMI_TLM_MAX_TAG_LEN);\n+\t),\n+\n+\tTP_printk(\"ts=%llu  de_id=0x%04llX  value=%016llu [%s]\",\n+\t\t  __entry-\u003ets, __entry-\u003ede_id, __entry-\u003evalue, __entry-\u003etag)\n+);\n+\n #endif /* _TRACE_SCMI_H */\n \n /* This part must be outside protection */\ndiff --git a/include/uapi/linux/scmi.h b/include/uapi/linux/scmi.h\nnew file mode 100644\nindex 00000000000000..3684d390be0666\n--- /dev/null\n+++ b/include/uapi/linux/scmi.h\n@@ -0,0 +1,373 @@\n+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */\n+/*\n+ * Copyright (C) 2026 ARM Ltd.\n+ */\n+#ifndef _UAPI_LINUX_SCMI_H\n+#define _UAPI_LINUX_SCMI_H\n+\n+/*\n+ * Userspace interface SCMI Telemetry\n+ */\n+\n+#include \u003clinux/ioctl.h\u003e\n+#include \u003clinux/types.h\u003e\n+\n+#define SCMI_TLM_ABI_VERSION_V1\t\t\t1\n+#define SCMI_TLM_CURRENT_ABI_VERSION\t\tSCMI_TLM_ABI_VERSION_V1\n+\n+#define SCMI_TLM_DE_IMPL_UUID_MAX\t16\n+\n+/**\n+ * struct scmi_tlm_abi_info - Basic information on the ABI/instance\n+ *\n+ * @size: sizeof this structure\n+ * @abi_version: ABI Version\n+ * @abi_features: ABI capabilities bitmap\n+ * @de_impl_version: SCMI Telemetry DE implementation revision\n+ * @num_des: Number of defined DEs\n+ * @num_groups: Number of defined DEs groups\n+ * @num_intervals: Number of available update intervals (instance-level)\n+ * @num_shmtis: Number of discovered SHMTI areas\n+ * @features: Instance specific SCMI feature-support bitmap\n+ * @reserved: Some room for future expansion without the need to resize\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_ABI_INFO\n+ */\n+struct scmi_tlm_abi_info {\n+\t__u32 size;\n+\t__u32 abi_version;\n+\t__u32 abi_features;\n+#define SCMI_TLM_ABI_FEAT_RESET\t\t\t\t(1 \u003c\u003c 0)\n+\t__u8 de_impl_version[SCMI_TLM_DE_IMPL_UUID_MAX];\n+\t__u32 num_des;\n+\t__u32 num_groups;\n+\t__u32 num_intervals;\n+\t__u32 num_shmtis;\n+\t__u32 features;\n+#define SCMI_TLM_BASE_SUPPORT_RESET\t\t\t(1 \u003c\u003c 0)\n+#define SCMI_TLM_BASE_SUPPORT_SINGLE_SAMPLE\t\t(1 \u003c\u003c 1)\n+#define SCMI_TLM_BASE_SUPPORT_GROUP_CONFIG\t\t(1 \u003c\u003c 2)\n+#define SCMI_TLM_BASE_SUPPORT_UPDATE_NOTIFICATION\t(1 \u003c\u003c 3)\n+\t__u64 reserved;\n+};\n+\n+/**\n+ * struct scmi_tlm_update_interval  - Update interval descriptor\n+ *\n+ * @secs: integer representing seconds\n+ * @exp: signed integer representing the base 10 exponent used as a multiplier\n+ *\t with @secs to represent the interval\n+ *\n+ * The resulting update interval is calculated as: \u003csecs\u003e * 10 ^ \u003cexp\u003e\n+ */\n+struct scmi_tlm_update_interval {\n+\t__u32 secs;\n+\t__s32 exp;\n+};\n+\n+/**\n+ * struct scmi_tlm_config  - Whole instance or group configuration\n+ *\n+ * @enable: Enable/Disable Telemetry for the whole instance or the group\n+ * @t_enable: Enable/Disable timestamping for all the DEs belonging to a group\n+ * @flags: Bitmask to represent special characteristics\n+ * @pad: Padding fields to enforce alignment\n+ * @grp_id: Identifier of the target group upon which this configuration will\n+ *\t    be applied: ignored if not marked as a group in @flags\n+ * @active: Get/Set currently active update interval for the whole instance or\n+ *\t    a group\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_CFG\n+ *\tWO - SCMI_TLM_SET_CFG\n+ */\n+struct scmi_tlm_config {\n+\t__u8 enable;\n+\t__u8 t_enable;\n+\t__u8 flags;\n+#define SCMI_TLM_CONFIG_GROUP\t\t(1 \u003c\u003c 0)\n+#define SCMI_TLM_CONFIG_FLAGS\t\t(SCMI_TLM_CONFIG_GROUP)\n+#define SCMI_TLM_CONFIG_IS_GROUP(f)\t((f) \u0026 SCMI_TLM_CONFIG_GROUP)\n+\t__u8 pad;\n+\t__u32 grp_id;\n+\tstruct scmi_tlm_update_interval active;\n+};\n+\n+/**\n+ * struct scmi_tlm_intervals  - Update intervals descriptor\n+ *\n+ * @grp_id: Identifier of the target group upon which this configuration\n+ *\t    will be applied: ignored if not marked as a group in @flags\n+ * @flags: Bitmask to represent special characteristics. When the interval\n+ *\t   is NOT marked as SCMI_TLM_INTERV_DISCRETE, @intervals will\n+ *\t   contain a triplet: min/max/step\n+ * @pad: Padding fields to enforce alignment\n+ * @num_intervals: Number of entries of @intervals\n+ * @pad2: Padding fields to enforce alignment\n+ * @intervals: A pointer to an array of struct scmi_tlm_update_interval\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_INTRVS\n+ */\n+struct scmi_tlm_intervals {\n+\t__u32 grp_id;\n+\t__u8 flags;\n+#define SCMI_TLM_INTERV_GROUP\t(1 \u003c\u003c 0)\n+#define SCMI_TLM_INTERV_DISCRETE\t(1 \u003c\u003c 1)\n+#define SCMI_TLM_INTERV_FLAGS\t\t\t\t\t\\\n+\t(SCMI_TLM_INTERV_GROUP | SCMI_TLM_INTERV_DISCRETE)\n+#define SCMI_TLM_INTERV_IS_GROUP(f)\t((f) \u0026 SCMI_TLM_INTERV_GROUP)\n+\t__u8 pad[3];\n+\t__u32 num_intervals;\n+\t__u32 pad2;\n+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_LOW\t0\n+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_HIGH\t1\n+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_STEP\t2\n+\t__u64 intervals;\n+};\n+\n+/**\n+ * struct scmi_tlm_de_config  - DE configuration\n+ *\n+ * @id: Identifier of the DE to act upon (ignored by SCMI_TLM_GET/SET_ALL_CFG)\n+ * @enable: A boolean to enable/disable the DE\n+ * @t_enable: A boolean to enable/disable the timestamp for this DE\n+ *\t      (if supported)\n+ * @pad: Padding fields to enforce alignment\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_DE_CFG\n+ *\tRW - SCMI_TLM_SET_DE_CFG\n+ *\tRW - SCMI_TLM_GET_ALL_CFG\n+ *\tRW - SCMI_TLM_SET_ALL_CFG\n+ */\n+struct scmi_tlm_de_config {\n+\t__u32 id;\n+\t__u32 enable;\n+\t__u32 t_enable;\n+\t__u32 pad;\n+};\n+\n+/**\n+ * struct scmi_tlm_de_info  - DataEvent Descriptor\n+ *\n+ * @id: DE identifier\n+ * @grp_id: Identifier of the group which this DE belongs to; valid only if\n+ *\t    this DE is marked as belonging to a group in @flags.\n+ * @data_sz: DE data size in bytes\n+ * @type: DE type\n+ * @unit: DE unit of measurements\n+ * @unit_exp: Power-of-10 multiplier for DE unit\n+ * @ts_rate: Clock rate in kHz used to generate the DE timestamp\n+ * @instance_id: DE instance ID\n+ * @compo_instance_id: DE component instance ID\n+ * @compo_type: Type of component which is associated to this DE\n+ * @persistent: Data value for this DE survives reboot (non-cold ones)\n+ * @flags: Bitmask to represent special characteristics\n+ * @pad: Padding fields to enforce alignment\n+ * @pad2: Padding fields to enforce alignment\n+ * @name: Name of this DE\n+ *\n+ * Used to get the full description of a DE: it reflects DE Descriptors\n+ * definitions in SCMI V4.0 specification at 3.12.4.6.\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_DE_INFO\n+ */\n+struct scmi_tlm_de_info {\n+\t__u32 id;\n+\t__u32 grp_id;\n+\t__u32 data_sz;\n+\t__u32 type;\n+\t__u32 unit;\n+\t__s32 unit_exp;\n+\t__u32 ts_rate;\n+\t__u32 instance_id;\n+\t__u32 compo_instance_id;\n+\t__u32 compo_type;\n+\t__u8 persistent;\n+\t__u8 flags;\n+#define SCMI_TLM_DEINFO_GROUP\t\t(1 \u003c\u003c 0)\n+#define SCMI_TLM_DEINFO_FLAGS\t\t(SCMI_TLM_DEINFO_GROUP)\n+#define SCMI_TLM_DEINFO_HAS_GROUP(f)\t((f) \u0026 SCMI_TLM_DEINFO_GROUP)\n+\t__u8 pad[2];\n+\t__u32 pad2;\n+\t__u8 name[16];\n+};\n+\n+/**\n+ * struct scmi_tlm_des_list  - List of all defined DEs\n+ *\n+ * @num_des: Number of entries in @des\n+ * @pad: Padding fields to enforce alignment\n+ * @des: A reference to an array containing struct scmi_tlm_de_info\n+ *\t descriptors for all the existent DEs\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_DE_LIST\n+ */\n+struct scmi_tlm_des_list {\n+\t__u32 num_des;\n+\t__u32 pad;\n+\t__u64 des;\n+};\n+\n+/**\n+ * struct scmi_tlm_de_sample - A DataEvent reading\n+ *\n+ * @id: DE identifier\n+ * @pad: Padding fields to enforce alignment.\n+ * @tstamp: DE reading timestamp (0 if timestamp NOT supported)\n+ * @val: Reading of the DE data value\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_DE_VALUE\n+ */\n+struct scmi_tlm_de_sample {\n+\t__u32 id;\n+\t__u32 pad;\n+\t__u64 tstamp;\n+\t__u64 val;\n+};\n+\n+/**\n+ * struct scmi_tlm_data_read - Bulk read of a number of DataEvents\n+ *\n+ * @grp_id: Optional group ID number, ignored if not marked as a group request\n+ *\t    in @flags and not supported by SCMI_TLM_BATCH_READ\n+ * @flags: Bitmask to represent special characteristics\n+ * @pad: Padding fields to enforce alignment\n+ * @pad2: Padding fields to enforce alignment\n+ * @num_samples: Number of entries returned in @samples\n+ * @samples: A reference to an array of struct scmi_tlm_de_sample containing\n+ *\t     an entry for each DE\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_SINGLE_SAMPLE\n+ *\tRW - SCMI_TLM_BULK_READ\n+ *\tRW - SCMI_TLM_BATCH_READ\n+ */\n+struct scmi_tlm_data_read {\n+\t__u32 grp_id;\n+\t__u8 flags;\n+#define SCMI_TLM_READ_GROUP\t\t(1 \u003c\u003c 0)\n+#define SCMI_TLM_READ_FLAGS\t\t(SCMI_TLM_READ_GROUP)\n+#define SCMI_TLM_READ_IS_GROUP(f)\t((f) \u0026 SCMI_TLM_READ_GROUP)\n+\t__u8 pad[3];\n+\t__u32 pad2;\n+\t__u32 num_samples;\n+\t__u64 samples;\n+};\n+\n+/**\n+ * struct scmi_tlm_grp_info  - Group info descriptor\n+ *\n+ * @grp_id: Group ID number\n+ * @num_des: Number of DEs part of this group\n+ * @num_intervals: Number of update intervals supported. Zero if group does not\n+ *\t\t   support per-group update interval configuration.\n+ * @pad: Padding fields to enforce alignment\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_GRP_INFO\n+ */\n+struct scmi_tlm_grp_info {\n+\t__u32 grp_id;\n+\t__u32 num_des;\n+\t__u32 num_intervals;\n+\t__u32 pad;\n+};\n+\n+/**\n+ * struct scmi_tlm_grps_list  - Group info descriptor list\n+ *\n+ * @num_grps: Number of entries returned in @grps\n+ * @pad: Padding fields to enforce alignment\n+ * @grps: A reference to an array of struct scmi_tlm_grp_info containing an\n+ *\t  entry for each defined group\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_GRP_LIST\n+ */\n+struct scmi_tlm_grps_list {\n+\t__u32 num_grps;\n+\t__u32 pad;\n+\t__u64 grps;\n+};\n+\n+/**\n+ * struct scmi_tlm_grp_desc  - Group descriptor\n+ *\n+ * @grp_id: Group ID number\n+ * @num_des: Number of DEs composing this group\n+ * @composing_des: A reference to an array of __u32 elements containing the\n+ *\t\t   DataEvent IDs composing this group.\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_GRP_DESC\n+ */\n+struct scmi_tlm_grp_desc {\n+\t__u32 grp_id;\n+\t__u32 num_des;\n+\t__u64 composing_des;\n+};\n+\n+/**\n+ * struct scmi_tlm_shmti_info  - SHMTI descriptor\n+ *\n+ * @sid: SHMTI ID\n+ * @fd: Associated opened file descriptor to use for mmap\n+ * @len: Size of the SHMTI to be used with mmap on this SHMTI\n+ * @offset: Offset in the mmap where the specified SHMTI start\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_SHMTI_LIST\n+ */\n+struct scmi_tlm_shmti_info {\n+\t__u32 sid;\n+\t__u32 fd;\n+\t__u32 len;\n+\t__u32 offset;\n+};\n+\n+/**\n+ * struct scmi_tlm_shmtis_list  - SHMTIs List\n+ *\n+ * @num_shmtis: Number of entries returned in @shmtis\n+ * @pad: Padding fields to enforce alignment\n+ * @shmtis: A reference to an array of struct scmi_tlm_shmti_info containing\n+ *\t    an entry for each defined SHMTI\n+ *\n+ * Used by:\n+ *\tRW - SCMI_TLM_GET_SHMTI_LIST\n+ */\n+struct scmi_tlm_shmtis_list {\n+\t__u32 num_shmtis;\n+\t__u32 pad;\n+\t__u64 shmtis;\n+};\n+\n+#define SCMI_TLM_IOCTL_MAGIC 0xF1\n+\n+#define SCMI_TLM_GET_ABI_INFO\t_IOWR(SCMI_TLM_IOCTL_MAGIC,  0x00, struct scmi_tlm_abi_info)\n+#define SCMI_TLM_GET_CFG\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x01, struct scmi_tlm_config)\n+#define SCMI_TLM_SET_CFG\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x02, struct scmi_tlm_config)\n+#define SCMI_TLM_GET_INTRVS\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x03, struct scmi_tlm_intervals)\n+#define SCMI_TLM_GET_DE_CFG\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x04, struct scmi_tlm_de_config)\n+#define SCMI_TLM_SET_DE_CFG\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x05, struct scmi_tlm_de_config)\n+#define SCMI_TLM_GET_DE_INFO\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x06, struct scmi_tlm_de_info)\n+#define SCMI_TLM_GET_DE_LIST\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x07, struct scmi_tlm_des_list)\n+#define SCMI_TLM_DE_READ\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x08, struct scmi_tlm_de_sample)\n+#define SCMI_TLM_GET_ALL_CFG\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x09, struct scmi_tlm_de_config)\n+#define SCMI_TLM_SET_ALL_CFG\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0A, struct scmi_tlm_de_config)\n+#define SCMI_TLM_GET_GRP_LIST\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0B, struct scmi_tlm_grps_list)\n+#define SCMI_TLM_GET_GRP_INFO\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0C, struct scmi_tlm_grp_info)\n+#define SCMI_TLM_GET_GRP_DESC\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0D, struct scmi_tlm_grp_desc)\n+#define SCMI_TLM_SINGLE_READ\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0E, struct scmi_tlm_data_read)\n+#define SCMI_TLM_BULK_READ\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0F, struct scmi_tlm_data_read)\n+#define SCMI_TLM_BATCH_READ\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x10, struct scmi_tlm_data_read)\n+#define SCMI_TLM_GET_SHMTI_LIST\t_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x11, struct scmi_tlm_shmtis_list)\n+#define SCMI_TLM_RESET\t\t_IO(SCMI_TLM_IOCTL_MAGIC, 0x12)\n+\n+#endif /* _UAPI_LINUX_SCMI_H */\ndiff --git a/tools/testing/scmi/Makefile b/tools/testing/scmi/Makefile\nnew file mode 100644\nindex 00000000000000..a6a101f8398baa\n--- /dev/null\n+++ b/tools/testing/scmi/Makefile\n@@ -0,0 +1,25 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+\n+CC?=$(CROSS_COMPILE)gcc\n+OBJS = stlm.o\n+\n+CFLAGS=-Wall -static -std=gnu11 -I ../../../include/uapi/\n+ifneq ($(DEBUG), )\n+\tCFLAGS+=-O0 -g -ggdb\n+else\n+\tCFLAGS+=-static\n+endif\n+\n+all: stlm\n+\n+stlm: $(OBJS)\n+\t$(CC) $(CFLAGS) $^ -o $@\n+\n+%.o: %.c\n+\t$(CC) $(CFLAGS) -c $\u003c\n+\n+clean:\n+\trm -f *.o\n+\trm -f stlm\n+\n+.PHONY: clean\ndiff --git a/tools/testing/scmi/stlm.c b/tools/testing/scmi/stlm.c\nnew file mode 100644\nindex 00000000000000..8fcdba5783c70d\n--- /dev/null\n+++ b/tools/testing/scmi/stlm.c\n@@ -0,0 +1,1191 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003climits.h\u003e\n+#include \u003cpoll.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstddef.h\u003e\n+#include \u003cstdint.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+#include \u003csys/mman.h\u003e\n+\n+#include \u003cunistd.h\u003e\n+\n+#include \u003clinux/scmi.h\u003e\n+\n+#define SLEEP_MS\t3000\n+\n+#define IOCTL_ERR_STR(_ioctl)\t\"IOCTL:\" #_ioctl\n+\n+#define USAGE_STRING \\\n+\t\"\\t[OPTIONS]\\n\" \\\n+\t\"\\t -i \u003cinstance_path\u003e\\t\\tUse this device instance path. Default: /dev/scmi/tlm_0\\n\" \\\n+\t\"\\t[COMMANDS]\\n\" \\\n+\t\"\\t info [full] - Display summarized (or full) configuration and information data\\n\" \\\n+\t\"\\t shmti [check][dump \u003csid\u003e] - SHMTI operations\\n\" \\\n+\t\"\\t\\t check - Sanity check of all SHMTis\\n\" \\\n+\t\"\\t\\t dump [\u003csid\u003e] - Binary dump of \u003csid\u003e or all SHMTI areas\\n\" \\\n+\t\"\\t des - Display detailed DEs info and config data\\n\" \\\n+\t\"\\t groups - Display detailed GROUPS info and config data\\n\" \\\n+\t\"\\t cfg [SUB-COMMANDS] - Configure Telemetry\\n\" \\\n+\t\"\\t\\t tlm on|off - Enable or disable Telemetry as a whole\\n\" \\\n+\t\"\\t\\t update \u003cmsecs\u003e - Set global update interval\\n\" \\\n+\t\"\\t\\t all_des [[on|off]:[on|off]] - Enable or disable ALL DEs with or wout TS\\n\" \\\n+\t\"\\t\\t de [\u003cde_id\u003e [[on|off]:[on|off]]] - Get/Set configuration of one or ALL de\\n\" \\\n+\t\"\\t\\t group [\u003cgrp_id\u003e] [[on|off]:[on|off]:[\u003cupdate_msecs\u003e]] - Get/Set GROUP configuration\\n\" \\\n+\t\"\\t single - Perform a single sample read\\n\" \\\n+\t\"\\t bulk - Perform a bulk read\\n\" \\\n+\t\"\\t batch \u003cde_id\u003e [de_id [de_id]... ] - Perform a batch read of the DE IDs listed in input\\n\" \\\n+\t\"\\t reset - Perform a Telemetry subsytem reset platform-side\\n\"\n+\n+struct tlm_de {\n+\tstruct scmi_tlm_de_info *info;\n+\tstruct scmi_tlm_de_config cfg;\n+\tstruct scmi_tlm_de_sample sample;\n+};\n+\n+struct tlm_group {\n+\tint fd;\n+\tstruct scmi_tlm_grp_info *info;\n+\tstruct scmi_tlm_grp_desc *desc;\n+\tstruct scmi_tlm_intervals *ivs;\n+};\n+\n+struct tlm_state {\n+\tint fd;\n+\tconst char *path;\n+\tstruct scmi_tlm_abi_info info;\n+\tstruct scmi_tlm_config cfg;\n+\tstruct scmi_tlm_intervals *ivs;\n+\tstruct scmi_tlm_shmtis_list *ssl;\n+\tunsigned int num_des;\n+\tstruct tlm_de *des;\n+\tunsigned int num_groups;\n+\tstruct tlm_group *grps;\n+};\n+\n+struct parsed_args {\n+\tconst char *instance;\n+\tconst char *cmd;\n+\tunsigned int cnt;\n+\tchar **opts;\n+};\n+\n+static inline void dump_des(struct tlm_state *st)\n+{\n+\tfprintf(stdout, \"\\n+ Found #%d DEs:\\n\", st-\u003enum_des);\n+\tfor (int i = 0; i \u003c st-\u003enum_des; i++) {\n+\t\tfprintf(stdout, \"\\t[0x%08X][%s]\\n\",\n+\t\t\tst-\u003edes[i].info-\u003eid, st-\u003edes[i].info-\u003ename);\n+\t\tfprintf(stdout, \"\\t\\tGRP_ID:0x%08X  SZ:%u  TYPE:%u  UNIT:%u  UNIT_EXP:%d  TS_RATE:%d\\n\",\n+\t\t\tst-\u003edes[i].info-\u003egrp_id, st-\u003edes[i].info-\u003edata_sz,\n+\t\t\tst-\u003edes[i].info-\u003etype, st-\u003edes[i].info-\u003eunit,\n+\t\t\tst-\u003edes[i].info-\u003eunit_exp, st-\u003edes[i].info-\u003ets_rate);\n+\t\tfprintf(stdout, \"\\t\\tINST_ID:%u  COMPO_ID:%u  COMPO_TYPE:%u  PERSIST:%u\\n\\n\",\n+\t\t\tst-\u003edes[i].info-\u003einstance_id, st-\u003edes[i].info-\u003ecompo_instance_id,\n+\t\t\tst-\u003edes[i].info-\u003ecompo_type, st-\u003edes[i].info-\u003epersistent);\n+\t}\n+\tfprintf(stdout, \"\\n\");\n+\n+\tfor (int i = 0; i \u003c st-\u003enum_des; i++) {\n+\t\tstruct tlm_de *de = \u0026st-\u003edes[i];\n+\n+\t\t/* Collect fresh sample */\n+\t\tif (de-\u003ecfg.enable) {\n+\t\t\tint ret;\n+\n+\t\t\tde-\u003esample.id = de-\u003einfo-\u003eid;\n+\t\t\tret = ioctl(st-\u003efd, SCMI_TLM_DE_READ, \u0026de-\u003esample);\n+\t\t\tif (ret)\n+\t\t\t\tperror(IOCTL_ERR_STR(SCMI_TLM_DE_READ));\n+\t\t}\n+\n+\t\tfprintf(stdout, \"\\t[0x%08X][%s]\\t\\t%s %s\\n\\t\\t--\u003e\u003e TS:%16llu %016llX\\n\",\n+\t\t\tde-\u003einfo-\u003eid, de-\u003einfo-\u003ename,\n+\t\t\tde-\u003ecfg.enable ? \"ON\" : \"OFF\",\n+\t\t\tde-\u003ecfg.t_enable ? \"/TS_ON \" : \"/TS_OFF\",\n+\t\t\tde-\u003esample.tstamp, de-\u003esample.val);\n+\t}\n+\tfprintf(stdout, \"\\n\");\n+}\n+\n+static inline void dump_groups(struct tlm_state *st)\n+{\n+\tfprintf(stdout, \"\\n+ Found %d GRPs: \", st-\u003enum_groups);\n+\tfor (int i = 0; i \u003c st-\u003enum_groups; i++) {\n+\t\tstruct scmi_tlm_update_interval *grp_intrvs;\n+\t\tstruct tlm_group *grp = \u0026st-\u003egrps[i];\n+\t\tuint32_t *composing_des;\n+\n+\t\tfprintf(stdout, \"\\n\\tGRP_ID:%d  DES#:%d  INTRVS#:%d\\n\",\n+\t\t\tgrp-\u003einfo-\u003egrp_id, grp-\u003einfo-\u003enum_des,\n+\t\t\tgrp-\u003einfo-\u003enum_intervals);\n+\n+\t\tfprintf(stdout, \"\\tGRP Intervals:\\n\");\n+\t\tgrp_intrvs = (struct scmi_tlm_update_interval *)grp-\u003eivs-\u003eintervals;\n+\t\tfor (int j = 0; j \u003c grp-\u003eivs-\u003enum_intervals; j++)\n+\t\t\tfprintf(stdout, \"\\t[%d]::%u,%d\\n\", j,\n+\t\t\t\tgrp_intrvs[j].secs, grp_intrvs[j].exp);\n+\n+\t\tcomposing_des = (uint32_t *)grp-\u003edesc-\u003ecomposing_des;\n+\t\tfprintf(stdout, \"\\tCOMPOSING_DES:\");\n+\t\tfor (int j = 0; j \u003c grp-\u003edesc-\u003enum_des; j++)\n+\t\t\tfprintf(stdout, \"0x%08X \", composing_des[j]);\n+\t\tfprintf(stdout, \"\\n\");\n+\t}\n+}\n+\n+static inline void dump_state(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_update_interval *intervals;\n+\tstruct scmi_tlm_shmti_info *shinfo;\n+\n+\tfprintf(stdout, \"- SYSTEM TELEMETRY @instance: %s\\n\\n\", st-\u003epath);\n+\tfprintf(stdout, \"+ ABI Version: %u\\n\", st-\u003einfo.abi_version);\n+\tfprintf(stdout, \"+ ABI Features: 0x%04X\\n\", st-\u003einfo.abi_features);\n+\tfprintf(stdout, \"\\t (RESET:%u)\\n\",\n+\t\t!!(st-\u003einfo.abi_features \u0026 SCMI_TLM_ABI_FEAT_RESET));\n+\tfprintf(stdout, \"+ SCMI Features: 0x%04X\\n\", st-\u003einfo.features);\n+\tfprintf(stdout, \"\\t (RESET:%u\",\n+\t\t!!(st-\u003einfo.features \u0026 SCMI_TLM_BASE_SUPPORT_RESET));\n+\tfprintf(stdout, \" SINGLE_SAMPLE:%u\",\n+\t\t!!(st-\u003einfo.features \u0026 SCMI_TLM_BASE_SUPPORT_SINGLE_SAMPLE));\n+\tfprintf(stdout, \" GROUP_CONFIG:%u\",\n+\t\t!!(st-\u003einfo.features \u0026 SCMI_TLM_BASE_SUPPORT_GROUP_CONFIG));\n+\tfprintf(stdout, \" UPDATE_NOTIFICATIONS:%u)\\n\",\n+\t\t!!(st-\u003einfo.features \u0026 SCMI_TLM_BASE_SUPPORT_UPDATE_NOTIFICATION));\n+\tfprintf(stdout, \"+ DEs#: %d\\n\", st-\u003einfo.num_des);\n+\tfprintf(stdout, \"+ GRPS#: %d\\n\", st-\u003einfo.num_groups);\n+\tfprintf(stdout, \"+ INTRV#: %d\\n\", st-\u003einfo.num_intervals);\n+\tfprintf(stdout, \"+ SHMTIS#: %d\\n\", st-\u003einfo.num_shmtis);\n+\n+\tfprintf(stdout, \"+ Primary UUID: \");\n+\tfor (int i = 0; i \u003c SCMI_TLM_DE_IMPL_UUID_MAX; i++) {\n+\t\tfprintf(stdout, \"%02X\", st-\u003einfo.de_impl_version[i]);\n+\t\tswitch (i) {\n+\t\tcase 3:\n+\t\tcase 5:\n+\t\tcase 7:\n+\t\tcase 9:\n+\t\t\tfprintf(stdout, \"%c\", '-');\n+\t\t\tbreak;\n+\t\tcase 15:\n+\t\t\tfprintf(stdout, \"%c\", '\\n');\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tfprintf(stdout, \"\\n+ TLM_ENABLED: %d\\n\", st-\u003ecfg.enable);\n+\tfprintf(stdout, \"+ CURRENT_UPDATE_INTERVAL: %u,%d\\n\",\n+\t\tst-\u003ecfg.active.secs, st-\u003ecfg.active.exp);\n+\n+\tfprintf(stdout, \"\\n+ Found #%u Global Update Intervals\\n\",\n+\t\tst-\u003eivs-\u003enum_intervals);\n+\tintervals = (struct scmi_tlm_update_interval *)st-\u003eivs-\u003eintervals;\n+\tfor (int i = 0; i \u003c st-\u003eivs-\u003enum_intervals; i++)\n+\t\tfprintf(stdout, \"\\t[%d]::%u,%d\\n\", i,\n+\t\t\tintervals[i].secs, intervals[i].exp);\n+\n+\tfprintf(stdout, \"\\n+ Found #%u SHMTI areas\\n\", st-\u003essl-\u003enum_shmtis);\n+\tshinfo = (struct scmi_tlm_shmti_info *)st-\u003essl-\u003eshmtis;\n+\tfor (int i = 0; i \u003c st-\u003essl-\u003enum_shmtis; i++)\n+\t\tfprintf(stdout, \"\\t[%d]:: FD:%u  LEN:%u\\n\",\n+\t\t\tshinfo[i].sid, shinfo[i].fd, shinfo[i].len);\n+\n+\tif (st-\u003einfo.num_des != st-\u003enum_des) {\n+\t\tfprintf(stdout, \"\\n++++++ DES NOT FULLY_ENUMERATED ++++++\\n\");\n+\t\tfprintf(stdout, \"+++ DECLARED:%u  ENUMERATED:%u +++\\n\",\n+\t\t\tst-\u003einfo.num_des, st-\u003enum_des);\n+\t}\n+\n+\tif (args \u0026\u0026 args-\u003ecnt \u0026\u0026 args-\u003eopts \u0026\u0026\n+\t    !strncmp(args-\u003eopts[0], \"full\", strlen(args-\u003eopts[0]))) {\n+\t\tdump_des(st);\n+\t\tdump_groups(st);\n+\t}\n+}\n+\n+static int discover_base_info(int fd, struct scmi_tlm_abi_info *info)\n+{\n+\tint ret;\n+\n+\tinfo-\u003esize = sizeof(*info);\n+\tret = ioctl(fd, SCMI_TLM_GET_ABI_INFO, info);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_ABI_INFO));\n+\t\treturn ret;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static struct scmi_tlm_des_list *scmi_get_des_list(int fd, int num_des)\n+{\n+\tstruct scmi_tlm_des_list *dsl;\n+\tstruct scmi_tlm_de_info *dei;\n+\tsize_t sz, d_sz;\n+\tint ret;\n+\n+\tsz = sizeof(*dsl);\n+\tdsl = malloc(sz);\n+\tif (!dsl)\n+\t\treturn NULL;\n+\n+\tbzero(dsl, sz);\n+\n+\td_sz = sizeof(*dei) * num_des;\n+\tdei = malloc(d_sz);\n+\tif (!dei) {\n+\t\tfree(dsl);\n+\t\treturn NULL;\n+\t}\n+\n+\tbzero(dei, d_sz);\n+\n+\tdsl-\u003enum_des = num_des;\n+\tdsl-\u003edes = (uint64_t)dei;\n+\tret = ioctl(fd, SCMI_TLM_GET_DE_LIST, dsl);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_DE_LIST));\n+\t\treturn NULL;\n+\t}\n+\n+\treturn dsl;\n+}\n+\n+static struct tlm_de *enumerate_des(struct tlm_state *st)\n+{\n+\tstruct scmi_tlm_des_list *dsl;\n+\tstruct tlm_de *des;\n+\n+\tdsl = scmi_get_des_list(st-\u003efd, st-\u003einfo.num_des);\n+\tif (!dsl)\n+\t\treturn NULL;\n+\n+\tst-\u003enum_des = dsl-\u003enum_des;\n+\tdes = malloc(sizeof(*des) * st-\u003enum_des);\n+\tif (!des)\n+\t\treturn NULL;\n+\n+\tbzero(des, sizeof(*des) * st-\u003enum_des);\n+\tfor (int i = 0; i \u003c st-\u003enum_des; i++) {\n+\t\tstruct tlm_de *de = \u0026des[i];\n+\t\tint ret;\n+\n+\t\tde-\u003einfo = \u0026(((struct scmi_tlm_de_info *)dsl-\u003edes)[i]);\n+\t\tde-\u003ecfg.id = de-\u003einfo-\u003eid;\n+\t\tret = ioctl(st-\u003efd, SCMI_TLM_GET_DE_CFG, \u0026de-\u003ecfg);\n+\t\tif (ret) {\n+\t\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_DE_CFG));\n+\t\t\tcontinue;\n+\t\t}\n+\t}\n+\n+\treturn des;\n+}\n+\n+static int get_current_config(int fd, struct scmi_tlm_config *cfg)\n+{\n+\tint ret;\n+\n+\tret = ioctl(fd, SCMI_TLM_GET_CFG, cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static struct scmi_tlm_grps_list *scmi_get_grps_list(int fd, int num_groups)\n+{\n+\tstruct scmi_tlm_grps_list *gsl;\n+\tstruct scmi_tlm_grp_info *grps;\n+\tsize_t sz, grps_sz;\n+\tint ret;\n+\n+\tsz = sizeof(*gsl);\n+\tgsl = malloc(sz);\n+\tif (!gsl)\n+\t\treturn NULL;\n+\n+\tbzero(gsl, sz);\n+\tgrps_sz = sizeof(*grps) * num_groups;\n+\tgrps = malloc(grps_sz);\n+\tif (!grps) {\n+\t\tfree(gsl);\n+\t\treturn NULL;\n+\t}\n+\n+\tgsl-\u003enum_grps = num_groups;\n+\tgsl-\u003egrps = (uint64_t)grps;\n+\tret = ioctl(fd, SCMI_TLM_GET_GRP_LIST, gsl);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_GRP_LIST));\n+\t\tfree(grps);\n+\t\tfree(gsl);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn gsl;\n+}\n+\n+static struct scmi_tlm_intervals *\n+enumerate_intervals(int fd, int num_intervals, unsigned int *grp_id)\n+{\n+\tstruct scmi_tlm_update_interval *intervs;\n+\tstruct scmi_tlm_intervals *ivs;\n+\tsize_t sz, i_sz;\n+\tint ret;\n+\n+\tsz = sizeof(*ivs);\n+\tivs = malloc(sz);\n+\tif (!ivs)\n+\t\treturn NULL;\n+\n+\tbzero(ivs, sz);\n+\n+\ti_sz = sizeof(*intervs) * num_intervals;\n+\tintervs = malloc(i_sz);\n+\tif (!intervs) {\n+\t\tfree(ivs);\n+\t\treturn NULL;\n+\t}\n+\n+\tbzero(intervs, i_sz);\n+\n+\tivs-\u003enum_intervals = num_intervals;\n+\tivs-\u003eintervals = (uint64_t)intervs;\n+\tif (grp_id) {\n+\t\tivs-\u003egrp_id = *grp_id;\n+\t\tivs-\u003eflags = SCMI_TLM_INTERV_GROUP;\n+\t}\n+\n+\tret = ioctl(fd, SCMI_TLM_GET_INTRVS, ivs);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_INTRVS));\n+\t\tfree(ivs);\n+\t\tfree(intervs);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn ivs;\n+}\n+\n+static struct scmi_tlm_shmtis_list *enumerate_shmtis(struct tlm_state *st)\n+{\n+\tstruct scmi_tlm_shmti_info *shmtis;\n+\tstruct scmi_tlm_shmtis_list *ssl;\n+\tsize_t sz, shmtis_sz;\n+\tint ret;\n+\n+\tsz = sizeof(*ssl);\n+\tssl = malloc(sz);\n+\tif (!ssl)\n+\t\treturn NULL;\n+\n+\tbzero(ssl, sz);\n+\tshmtis_sz = sizeof(*shmtis) * st-\u003einfo.num_shmtis;\n+\tshmtis = malloc(shmtis_sz);\n+\tif (!shmtis) {\n+\t\tfree(ssl);\n+\t\treturn NULL;\n+\t}\n+\n+\tssl-\u003enum_shmtis = st-\u003einfo.num_shmtis;\n+\tssl-\u003eshmtis = (uint64_t)shmtis;\n+\tret = ioctl(st-\u003efd, SCMI_TLM_GET_SHMTI_LIST, ssl);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_SHMTI_LIST));\n+\t\tfree(shmtis);\n+\t\tfree(ssl);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn ssl;\n+}\n+\n+static struct tlm_group *enumerate_groups(struct tlm_state *st)\n+{\n+\tstruct scmi_tlm_grps_list *gsl;\n+\tstruct tlm_group *grps;\n+\n+\tgsl = scmi_get_grps_list(st-\u003efd, st-\u003einfo.num_groups);\n+\tif (!gsl)\n+\t\treturn NULL;\n+\n+\tst-\u003enum_groups = gsl-\u003enum_grps;\n+\tgrps = malloc(sizeof(*grps) * st-\u003enum_groups);\n+\tif (!grps)\n+\t\treturn NULL;\n+\n+\tbzero(grps, sizeof(*grps) * st-\u003enum_groups);\n+\tfor (int i = 0; i \u003c st-\u003enum_groups; i++) {\n+\t\tstruct tlm_group *grp = \u0026grps[i];\n+\t\tsize_t size, composing_sz;\n+\t\tuint32_t *composing_des;\n+\t\tint ret;\n+\n+\t\tgrp-\u003einfo = \u0026(((struct scmi_tlm_grp_info *)gsl-\u003egrps)[i]);\n+\t\tsize = sizeof(*grp-\u003edesc);\n+\t\tgrp-\u003edesc = malloc(size);\n+\t\tif (!grp-\u003edesc)\n+\t\t\treturn NULL;\n+\n+\t\tbzero(grp-\u003edesc, size);\n+\t\tcomposing_sz = sizeof(uint32_t) * grp-\u003einfo-\u003enum_des;\n+\t\tcomposing_des = malloc(composing_sz);\n+\t\tif (!composing_des) //XXX BAD Cleanup\n+\t\t\treturn NULL;\n+\n+\t\tgrp-\u003edesc-\u003egrp_id = grp-\u003einfo-\u003egrp_id;\n+\t\tgrp-\u003edesc-\u003enum_des = grp-\u003einfo-\u003enum_des;\n+\t\tgrp-\u003edesc-\u003ecomposing_des = (uint64_t)composing_des;\n+\t\tret = ioctl(st-\u003efd, SCMI_TLM_GET_GRP_DESC, grp-\u003edesc);\n+\t\tif (ret) {\n+\t\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_GRP_DESC));\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tgrp-\u003eivs = enumerate_intervals(st-\u003efd, grp-\u003einfo-\u003enum_intervals,\n+\t\t\t\t\t       \u0026grp-\u003einfo-\u003egrp_id);\n+\t}\n+\n+\treturn grps;\n+}\n+\n+static int gather_tlm_state(struct tlm_state *st)\n+{\n+\tint ret;\n+\n+\tret = discover_base_info(st-\u003efd, \u0026st-\u003einfo);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tst-\u003eivs = enumerate_intervals(st-\u003efd, st-\u003einfo.num_intervals, NULL);\n+\tif (!st-\u003eivs)\n+\t\treturn -1;\n+\n+\tret = get_current_config(st-\u003efd, \u0026st-\u003ecfg);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (st-\u003einfo.num_des)\n+\t\tst-\u003edes = enumerate_des(st);\n+\n+\tif (st-\u003einfo.num_groups)\n+\t\tst-\u003egrps = enumerate_groups(st);\n+\n+\tif (st-\u003einfo.num_shmtis)\n+\t\tst-\u003essl = enumerate_shmtis(st);\n+\n+\treturn 0;\n+}\n+\n+static struct tlm_state *open_session(const char *path)\n+{\n+\tstruct tlm_state *st;\n+\n+\tst = malloc(sizeof(*st));\n+\tif (!st)\n+\t\treturn NULL;\n+\n+\tst-\u003efd = open(path, O_RDWR);\n+\tif (st-\u003efd \u003c 0) {\n+\t\tperror(\"open\");\n+\t\tfree(st);\n+\t\treturn NULL;\n+\t}\n+\n+\tst-\u003epath = path;\n+\n+\treturn st;\n+}\n+\n+#define MAX_GENERATIONS\t\t5\n+\n+#if 0\n+static void get_tlm_generation(struct tlm_state *st)\n+{\n+\tint fd, i = 0;\n+\tstruct pollfd pfds[1];\n+\n+\tfd = openat(st-\u003edfd, \"generation\", O_RDONLY);\n+\tif (fd \u003c 0) {\n+\t\tperror(\"openat\");\n+\t\treturn;\n+\t}\n+\n+\tpfds[0].fd = fd;\n+\tpfds[0].events = POLLIN;\n+\n+\tdo {\n+\t\tint ret;\n+\n+\t\tpfds[0].revents = 0;\n+\t\tret = poll(pfds, 1, -1);\n+\t\tif (ret \u003c 0) {\n+\t\t\tperror(\"poll generation\");\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (!pfds[0].revents)\n+\t\t\tcontinue;\n+\n+\t\tif (pfds[0].revents \u0026 POLLIN) {\n+\t\t\tint n;\n+\t\t\tchar buf[32] = {};\n+\n+\t\t\tn = read(fd, buf, 32);\n+\t\t\tif (n \u003c 0) {\n+\t\t\t\tperror(\"read generation\");\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tfprintf(stdout, \"Generation[%u]: %s\\n\", i, buf);\n+\t\t}\n+\t} while (i++ \u003c MAX_GENERATIONS);\n+\n+\tclose(fd);\n+}\n+#endif\n+\n+static int dump_shmti(struct scmi_tlm_shmti_info *shmti)\n+{\n+\tvoid *tdcf;\n+\tssize_t bytes = 0;\n+\n+\ttdcf = mmap(NULL, shmti-\u003elen, PROT_READ, MAP_SHARED, shmti-\u003efd, 0);\n+\tif (tdcf == MAP_FAILED) {\n+\t\tfprintf(stderr, \"%s\\n\", strerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\ttdcf += shmti-\u003eoffset;\n+\tdo {\n+\t\tbytes += write(1, tdcf + bytes, shmti-\u003elen - bytes);\n+\t\tif (bytes \u003c 0)\n+\t\t\treturn -1;\n+\t} while (bytes \u003c shmti-\u003elen);\n+\n+\treturn bytes;\n+}\n+\n+static int shmti_dump(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_shmti_info *shmti;\n+\tunsigned long first, last;\n+\n+\tif (args-\u003ecnt \u003e 1) {\n+\t\tfirst = last = strtoul(args-\u003eopts[1], NULL, 0);\n+\t\tif (first == ULONG_MAX || errno == -EINVAL ||\n+\t\t    first \u003e= st-\u003essl-\u003enum_shmtis)\n+\t\t\treturn -1;\n+\t} else {\n+\t\tfirst = 0;\n+\t\tlast = st-\u003essl-\u003enum_shmtis - 1;\n+\t}\n+\n+\tfor (int sid = first; sid \u003c= last; sid++) {\n+\t\tint ret;\n+\n+\t\tshmti = \u0026(((struct scmi_tlm_shmti_info *)(st-\u003essl-\u003eshmtis))[sid]);\n+\t\tfprintf(stderr, \"Binary DUMP of SHMTI[%u] LEN:%u\\n\",\n+\t\t\tshmti-\u003esid, shmti-\u003elen);\n+\n+\t\tret = dump_shmti(shmti);\n+\t\tif (!ret)\n+\t\t\tfprintf(stderr, \"...FAILED DUMP of SHMTI[%u] !!!\\n\", sid);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int shmti_check(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_shmti_info *shmtis;\n+\n+\tshmtis = (struct scmi_tlm_shmti_info *)st-\u003essl-\u003eshmtis;\n+\n+\tfprintf(stdout, \"\\n- SHMTI mmap SANITY CHECK -\\n-------------------\\n\");\n+\n+\tfor (int i = 0; i \u003c st-\u003essl-\u003enum_shmtis; i++) {\n+\t\tunsigned long *start, *end;\n+\t\tvoid *tdcf;\n+\t\tchar *buf;\n+\n+\t\tfprintf(stdout, \"Mapping SHMTI[%u] - SID:%u  LEN:%u  FD:%u  OFFS:%u\\n\",\n+\t\t\ti, shmtis[i].sid, shmtis[i].len, shmtis[i].fd, shmtis[i].offset);\n+\n+\t\ttdcf = mmap(NULL, shmtis[i].len, PROT_READ, MAP_SHARED,\n+\t\t\t    shmtis[i].fd, 0);\n+\t\tif (tdcf == MAP_FAILED) {\n+\t\t\tfprintf(stderr, \"%s\\n\", strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tstart = tdcf + shmtis[i].offset;\n+\t\tend = tdcf + shmtis[i].offset + shmtis[i].len;\n+\n+\t\tfprintf(stdout, \"-----------------------------------------------------\\n\");\n+\t\tfprintf(stdout, \"Mapped SHMTI - SID:%u  %u@%p\\n\",\n+\t\t\tshmtis[i].sid, shmtis[i].offset, tdcf);\n+\n+\t\tbuf = (char *)start;\n+\t\tfor (int j = 0; j \u003c 4; j++)\n+\t\t\tfprintf(stdout, \"%c \", buf[j]);\n+\n+\t\tfprintf(stdout, \" ===\u003e \");\n+\n+\t\tbuf = ((char *)end) - 4;\n+\t\tfor (int j = 0 ; j \u003c 4; j++)\n+\t\t\tfprintf(stdout, \"%c \", buf[j]);\n+\t\tfprintf(stdout, \"\\n-----------------------------------------------------\\n\");\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int shmti_ops(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tif (!args-\u003ecnt || !args-\u003eopts)\n+\t\treturn -1;\n+\n+\tif (!strncmp(args-\u003eopts[0], \"dump\", strlen(args-\u003eopts[0])))\n+\t\treturn shmti_dump(st, args);\n+\tif (!strncmp(args-\u003eopts[0], \"check\", strlen(args-\u003eopts[0])))\n+\t\treturn shmti_check(st, args);\n+\n+\treturn -1;\n+}\n+\n+static int parse_options(int argc, char **argv, struct parsed_args *args)\n+{\n+\tint opt = 0;\n+\n+\t/* Set defaults */\n+\targs-\u003einstance = \"/dev/scmi/tlm_0\";\n+\twhile ((opt = getopt(argc, argv, \"i:h\")) != -1) {\n+\t\tswitch (opt) {\n+\t\tcase 'i':\n+\t\t\targs-\u003einstance = optarg;\n+\t\t\tbreak;\n+\t\tcase 'h':\n+\t\tdefault:\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t}\n+\n+\tif (optind \u003c= argc) {\n+\t\tif (optind \u003c argc - 1) {\n+\t\t\targs-\u003ecnt = argc - 1 - optind;\n+\t\t\targs-\u003eopts = malloc(sizeof(*args-\u003eopts) * args-\u003ecnt);\n+\t\t\tif (!args-\u003eopts)\n+\t\t\t\treturn -1;\n+\t\t}\n+\n+\t\targs-\u003ecmd = argv[optind];\n+\t\tfor (int i = 0, j = optind + 1; j \u003c argc; i++, j++)\n+\t\t\targs-\u003eopts[i] = argv[j];\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static inline void usage(char *program_name)\n+{\n+\tprintf(\"Usage: %s [OPTIONS] [CMD [CMD_OPTS]...]\\n\", program_name);\n+\tprintf(\"%s\", USAGE_STRING);\n+}\n+\n+static inline struct scmi_tlm_data_read *bulk_buffer_alloc(struct tlm_state *st)\n+{\n+\tstruct scmi_tlm_de_sample *samples;\n+\tstruct scmi_tlm_data_read *bulk;\n+\tsize_t bulk_sz, samples_sz;\n+\n+\tbulk_sz = sizeof(*bulk);\n+\tbulk = malloc(bulk_sz);\n+\tif (!bulk)\n+\t\treturn NULL;\n+\n+\tbzero(bulk, bulk_sz);\n+\tsamples_sz = st-\u003einfo.num_des * sizeof(*samples);\n+\tsamples = malloc(samples_sz);\n+\tif (!samples) {\n+\t\tfree(bulk);\n+\t\treturn NULL;\n+\t}\n+\n+\tbzero(samples, samples_sz);\n+\tbulk-\u003esamples = (uint64_t)samples;\n+\tbulk-\u003enum_samples = st-\u003einfo.num_des;\n+\n+\treturn bulk;\n+}\n+\n+static int single_read(struct tlm_state *st)\n+{\n+\tstruct scmi_tlm_de_sample *samples;\n+\tstruct scmi_tlm_data_read *bulk;\n+\tint ret;\n+\n+\tbulk = bulk_buffer_alloc(st);\n+\tif (!bulk)\n+\t\treturn -1;\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_SINGLE_READ, bulk);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_SINGLE_READ));\n+\t\treturn -1;\n+\t}\n+\n+\tfprintf(stdout, \"\\n- Single ASYNC read -\\n-------------------\\n\");\n+\tsamples = (struct scmi_tlm_de_sample *)bulk-\u003esamples;\n+\tfor (int i = 0; i \u003c bulk-\u003enum_samples; i++)\n+\t\tfprintf(stdout, \"0x%08X %016llu %016llX\\n\",\n+\t\t\tsamples[i].id, samples[i].tstamp, samples[i].val);\n+\n+\treturn 0;\n+}\n+\n+static int bulk_read(struct tlm_state *st)\n+{\n+\tstruct scmi_tlm_de_sample *samples;\n+\tstruct scmi_tlm_data_read *bulk;\n+\tint ret;\n+\n+\tbulk = bulk_buffer_alloc(st);\n+\tif (!bulk)\n+\t\treturn -1;\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_BULK_READ, bulk);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_BULK_READ));\n+\t\treturn -1;\n+\t}\n+\n+\tfprintf(stdout, \"\\n- BULK read -\\n-------------------\\n\");\n+\tsamples = (struct scmi_tlm_de_sample *)bulk-\u003esamples;\n+\tfor (int i = 0; i \u003c bulk-\u003enum_samples; i++)\n+\t\tfprintf(stdout, \"0x%08X %016llu %016llX\\n\",\n+\t\t\tsamples[i].id, samples[i].tstamp, samples[i].val);\n+\n+\treturn 0;\n+}\n+\n+static int tlm_reset(struct tlm_state *st)\n+{\n+\tint ret;\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_RESET);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_RESET));\n+\t\treturn -1;\n+\t}\n+\n+\tfprintf(stdout, \"\\n--- TLM RESET ISSUED\\n\");\n+\n+\treturn 0;\n+}\n+\n+static int batch_read(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_de_sample *samples;\n+\tstruct scmi_tlm_data_read *bulk;\n+\tint ret;\n+\n+\tif (!args-\u003eopts || !args-\u003ecnt)\n+\t\treturn -1;\n+\n+\tbulk = bulk_buffer_alloc(st);\n+\tif (!bulk)\n+\t\treturn -1;\n+\n+\tsamples = (struct scmi_tlm_de_sample *)bulk-\u003esamples;\n+\tbulk-\u003enum_samples = args-\u003ecnt;\n+\tfor (int i = 0; i \u003c bulk-\u003enum_samples; i++) {\n+\t\tunsigned long val;\n+\n+\t\tval = strtoul(args-\u003eopts[i], NULL, 0);\n+\t\tif (val == ULONG_MAX || errno == -EINVAL)\n+\t\t\tcontinue;\n+\n+\t\tsamples[i].id = (unsigned int)val;\n+\t}\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_BATCH_READ, bulk);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_BATCH_READ));\n+\t\treturn -1;\n+\t}\n+\n+\tfprintf(stdout, \"\\n- BATCH read -\\n-------------------\\n\");\n+\tfor (int i = 0; i \u003c bulk-\u003enum_samples; i++)\n+\t\tfprintf(stdout, \"0x%08X %016llu %016llX\\n\",\n+\t\t\tsamples[i].id, samples[i].tstamp, samples[i].val);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * \u003cena\u003e:\u003ct_ena\u003e[:\u003cupdate_msecs\u003e]\n+ */\n+static void\n+parse_item_cfg(char *str, bool *ena, bool *t_ena, unsigned int *update)\n+{\n+\tchar *tok;\n+\n+\tif (!ena)\n+\t\treturn;\n+\n+\ttok = strtok(str, \":\");\n+\tif (tok)\n+\t\t*ena = strncmp(tok, \"on\", strlen(tok)) == 0;\n+\n+\tif (!t_ena)\n+\t\treturn;\n+\n+\ttok = strtok(NULL, \":\");\n+\tif (tok)\n+\t\t*t_ena = strncmp(tok, \"on\", strlen(tok)) == 0;\n+\n+\tif (!update)\n+\t\treturn;\n+\n+\ttok = strtok(NULL, \":\");\n+\tif (tok) {\n+\t\tunsigned long val;\n+\n+\t\tval = strtoul(tok, NULL, 0);\n+\t\tif (val == ULONG_MAX || errno == -EINVAL)\n+\t\t\treturn;\n+\n+\t\t*update = (unsigned int)val;\n+\t}\n+}\n+\n+static int configure_all_des(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_de_config de_cfg = {};\n+\tbool ena, t_ena;\n+\tint ret;\n+\n+\tif (!args-\u003eopts)\n+\t\treturn -1;\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_GET_ALL_CFG, \u0026de_cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_ALL_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\tfprintf(stdout, \"--- [GET] ALL DEs ON:%d  T_ON:%d\\n\",\n+\t\tde_cfg.enable, de_cfg.t_enable);\n+\n+\tif (args-\u003ecnt \u003c 2)\n+\t\treturn 0;\n+\n+\tparse_item_cfg(args-\u003eopts[1], \u0026ena, \u0026t_ena, NULL);\n+\tde_cfg.enable = !!ena;\n+\tde_cfg.t_enable = !!t_ena;\n+\n+\tfprintf(stdout, \"--- [SET] ALL DEs ON:%d  T_ON:%d\\n\",\n+\t\tde_cfg.enable, de_cfg.t_enable);\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_SET_ALL_CFG, \u0026de_cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_SET_ALL_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int de_config_get(struct tlm_state *st, struct scmi_tlm_de_config *de_cfg)\n+{\n+\tint ret;\n+\n+\t/* Get current config */\n+\tret = ioctl(st-\u003efd, SCMI_TLM_GET_DE_CFG, de_cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_DE_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int configure_de(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_de_config de_cfg = {};\n+\tbool ena, t_ena;\n+\tunsigned long val;\n+\tint ret;\n+\n+\tif (!args-\u003eopts)\n+\t\treturn -1;\n+\n+\tif (args-\u003ecnt \u003c 2) {\n+\t\t/* Dump all DE configs */\n+\t\tfor (int i = 0; i \u003c st-\u003enum_des; i++) {\n+\t\t\tde_cfg.id = st-\u003edes[i].info-\u003eid;\n+\t\t\tret = de_config_get(st, \u0026de_cfg);\n+\t\t\tif (!ret)\n+\t\t\t\tfprintf(stdout,\n+\t\t\t\t\t\"--- [GET] -\u003e DE:0x%08X  ON:%d  T_ON:%d\\n\",\n+\t\t\t\t\tde_cfg.id, de_cfg.enable, de_cfg.t_enable);\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/*Dump one DE config */\n+\tval = strtoul(args-\u003eopts[1], NULL, 0);\n+\tif (val == ULONG_MAX || errno == -EINVAL)\n+\t\treturn -1;\n+\n+\tde_cfg.id = (unsigned int)val;\n+\tret = de_config_get(st, \u0026de_cfg);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tfprintf(stdout, \"--- [GET] -\u003e DE:0x%08X  ON:%d  T_ON:%d\\n\",\n+\t\tde_cfg.id, de_cfg.enable, de_cfg.t_enable);\n+\n+\tif (args-\u003ecnt \u003c 3)\n+\t\treturn 0;\n+\n+\t/* Configure one DE: */\n+\tparse_item_cfg(args-\u003eopts[2], \u0026ena, \u0026t_ena, NULL);\n+\tde_cfg.enable = !!ena;\n+\tde_cfg.t_enable = !!t_ena;\n+\n+\tfprintf(stdout, \"--- [SET] -\u003e DE:0x%08X  ON:%d  T_ON:%d\\n\",\n+\t\tde_cfg.id, de_cfg.enable, de_cfg.t_enable);\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_SET_DE_CFG, \u0026de_cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_SET_DE_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int grp_config_get(struct tlm_state *st, struct scmi_tlm_config *cfg)\n+{\n+\tint ret;\n+\n+\t/* Get current config */\n+\tret = ioctl(st-\u003efd, SCMI_TLM_GET_CFG, cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_GET_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int configure_group(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_config cfg = {};\n+\tbool ena, t_ena;\n+\tunsigned long val;\n+\tint ret;\n+\n+\tif (!args-\u003eopts)\n+\t\treturn -1;\n+\n+\tif (args-\u003ecnt \u003c 2) {\n+\t\t/* Dump all GRPS configs */\n+\t\tfor (int i = 0; i \u003c st-\u003enum_groups; i++) {\n+\t\t\tcfg.grp_id = st-\u003egrps[i].info-\u003egrp_id;\n+\t\t\tcfg.active.exp = -3;\n+\t\t\tcfg.flags = SCMI_TLM_CONFIG_GROUP;\n+\t\t\tret = grp_config_get(st, \u0026cfg);\n+\t\t\tif (!ret)\n+\t\t\t\tfprintf(stdout,\n+\t\t\t\t\t\"--- [GET] -\u003e GROUP:0x%08X  ON:%d  T_ON:%d  INTRV:%u,%d\\n\",\n+\t\t\t\t\tcfg.grp_id, cfg.enable, cfg.t_enable,\n+\t\t\t\t\tcfg.active.secs, cfg.active.exp);\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/*Dump one GROUP config */\n+\tval = strtoul(args-\u003eopts[1], NULL, 0);\n+\tif (val == ULONG_MAX || errno == -EINVAL)\n+\t\treturn -1;\n+\n+\tcfg.grp_id = (unsigned int)val;\n+\tcfg.flags = SCMI_TLM_CONFIG_GROUP;\n+\tcfg.active.exp = -3;\n+\tret = grp_config_get(st, \u0026cfg);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tfprintf(stdout, \"--- [GET] -\u003e GROUP:0x%08X  ON:%d  T_ON:%d  INTRV:%u,%d\\n\",\n+\t\tcfg.grp_id, cfg.enable, cfg.t_enable, cfg.active.secs, cfg.active.exp);\n+\n+\tif (args-\u003ecnt \u003c 3)\n+\t\treturn 0;\n+\n+\t/* Configure one GROUP */\n+\tparse_item_cfg(args-\u003eopts[2], \u0026ena, \u0026t_ena, \u0026cfg.active.secs);\n+\tcfg.enable = !!ena;\n+\tcfg.t_enable = !!t_ena;\n+\n+\tfprintf(stdout, \"--- [SET] -\u003e GROUP:0x%08X  ON:%d  T_ON:%d  INTRV:%u,%d\\n\",\n+\t\tcfg.grp_id, cfg.enable, cfg.t_enable,\n+\t\tcfg.active.secs, cfg.active.exp);\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_SET_CFG, \u0026cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_SET_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int configure_telemetry(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_config cfg = st-\u003ecfg;\n+\tbool val;\n+\tint ret;\n+\n+\tif (args-\u003ecnt \u003c 2 || !args-\u003eopts)\n+\t\treturn -1;\n+\n+\tval = strncmp(args-\u003eopts[1], \"on\", strlen(args-\u003eopts[1])) == 0;\n+\n+\tcfg.enable = !!val;\n+\tcfg.flags = 0;\n+\n+\tfprintf(stdout, \"\\n---%sabling Telemetry\\n\", val ? \"En\" : \"Dis\");\n+\tret = ioctl(st-\u003efd, SCMI_TLM_SET_CFG, \u0026cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_SET_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int configure_update(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tstruct scmi_tlm_config cfg = st-\u003ecfg;\n+\tunsigned long val;\n+\tint ret;\n+\n+\tif (args-\u003ecnt \u003c 2 || !args-\u003eopts)\n+\t\treturn -1;\n+\n+\tval = strtoul(args-\u003eopts[1], NULL, 0);\n+\tif (val == ULONG_MAX || errno == -EINVAL)\n+\t\treturn -1;\n+\n+\tcfg.flags = 0;\n+\tif (!val) {\n+\t\tcfg.enable = val;\n+\t\tfprintf(stdout, \"\\n---Disabling Telemetry\\n\");\n+\t} else {\n+\t\tcfg.enable = !!val;\n+\t\tcfg.active.secs = val;\n+\t\tcfg.active.exp = -3;\n+\t\tfprintf(stdout, \"\\n--- Setting update interval to %lu\\n\", val);\n+\t}\n+\n+\tret = ioctl(st-\u003efd, SCMI_TLM_SET_CFG, \u0026cfg);\n+\tif (ret) {\n+\t\tperror(IOCTL_ERR_STR(SCMI_TLM_SET_CFG));\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int configure(struct tlm_state *st, struct parsed_args *args)\n+{\n+\tif (!args-\u003ecnt || !args-\u003eopts)\n+\t\treturn -1;\n+\n+\tif (!strncmp(args-\u003eopts[0], \"all_des\", strlen(args-\u003eopts[0])))\n+\t\treturn configure_all_des(st, args);\n+\tif (!strncmp(args-\u003eopts[0], \"tlm\", strlen(args-\u003eopts[0])))\n+\t\treturn configure_telemetry(st, args);\n+\tif (!strncmp(args-\u003eopts[0], \"update\", strlen(args-\u003eopts[0])))\n+\t\treturn configure_update(st, args);\n+\tif (!strncmp(args-\u003eopts[0], \"de\", strlen(args-\u003eopts[0])))\n+\t\treturn configure_de(st, args);\n+\tif (!strncmp(args-\u003eopts[0], \"group\", strlen(args-\u003eopts[0])))\n+\t\treturn configure_group(st, args);\n+\n+\treturn -1;\n+}\n+\n+static inline void full_scan_and_dump(struct tlm_state *st)\n+{\n+\tdump_state(st, NULL);\n+\tdump_des(st);\n+\tdump_groups(st);\n+}\n+\n+int main(int argc, char **argv)\n+{\n+\tstruct parsed_args args = {};\n+\tstruct tlm_state *st;\n+\tint ret;\n+\n+\t//get_tlm_generation(\u0026st);\n+\n+\tret = parse_options(argc, argv, \u0026args);\n+\tif (ret) {\n+\t\tusage(argv[0]);\n+\t\treturn ret;\n+\t}\n+\n+\tst = open_session(args.instance);\n+\tif (!st)\n+\t\treturn -1;\n+\n+\tret = gather_tlm_state(st);\n+\tif (ret) {\n+\t\tfree(st);\n+\t\treturn ret;\n+\t}\n+\n+\tif (!args.cmd) {\n+\t\tfull_scan_and_dump(st);\n+\t} else if (!strncmp(args.cmd, \"info\", strlen(args.cmd))) {\n+\t\tdump_state(st, \u0026args);\n+\t} else if (!strncmp(args.cmd, \"shmti\", strlen(args.cmd))) {\n+\t\tshmti_ops(st, \u0026args);\n+\t} else if (!strncmp(args.cmd, \"des\", strlen(args.cmd))) {\n+\t\tdump_des(st);\n+\t} else if (!strncmp(args.cmd, \"groups\", strlen(args.cmd))) {\n+\t\tdump_groups(st);\n+\t} else if (!strncmp(args.cmd, \"cfg\", strlen(args.cmd))) {\n+\t\tconfigure(st, \u0026args);\n+\t} else if (!strncmp(args.cmd, \"single\", strlen(args.cmd))) {\n+\t\tsingle_read(st);\n+\t} else if (!strncmp(args.cmd, \"bulk\", strlen(args.cmd))) {\n+\t\tbulk_read(st);\n+\t} else if (!strncmp(args.cmd, \"batch\", strlen(args.cmd))) {\n+\t\tbatch_read(st, \u0026args);\n+\t} else if (!strncmp(args.cmd, \"reset\", strlen(args.cmd))) {\n+\t\ttlm_reset(st);\n+\t} else {\n+\t\tfprintf(stderr, \"Unknown command '%s'\\n\", args.cmd);\n+\t\tusage(argv[0]);\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n"
}

2/1 2026/07/25 20:52 agent patch-evaluator
0m Model:
best-expensive

Args:
null

Results:
{
  "EnableConfigs": [
    "ARM_SCMI_PROTOCOL",
    "ARM_SCMI_SYSTEM_TELEMETRY",
    "ARM_SCMI_DEBUG_PROTOCOLS"
  ],
  "FocusSymbols": [
    "scmi_tlm_unlocked_ioctl",
    "scmi_tlm_abi_info_get_ioctl",
    "scmi_tlm_config_get_ioctl",
    "scmi_tlm_config_set_ioctl",
    "scmi_tlm_intervals_get_ioctl",
    "scmi_tlm_de_config_set_ioctl",
    "scmi_tlm_de_config_get_ioctl",
    "scmi_tlm_de_info_get_ioctl",
    "scmi_tlm_des_list_get_ioctl",
    "scmi_tlm_de_value_get_ioctl",
    "scmi_tlm_grp_info_get_ioctl",
    "scmi_tlm_grp_desc_get_ioctl",
    "scmi_tlm_grps_list_get_ioctl",
    "scmi_tlm_des_read_ioctl",
    "scmi_tlm_des_batch_read_ioctl",
    "scmi_tlm_shmtis_list_get_ioctl",
    "scmi_tlm_reset_ioctl",
    "scmi_tlm_shmti_mmap",
    "scmi_telemetry_dbg_shmti_read"
  ],
  "Reasoning": "The patch introduces a new SCMI System Telemetry driver and protocol, exposing a new character device (`/dev/scmi/tlm_\u003cN\u003e`) with a comprehensive set of ioctls for userspace to interact with the telemetry data. This is a significant new userspace API and core logic that should be fuzzed.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer.
Your job is to review a provided patch series and determine
if it makes functional changes to the kernel that should be fuzzed.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively
use your code access tools to examine the actual source code and confirm any assumptions.

Return WorthFuzzing=false if the patch only contains:
- Modifications to Documentation/, Kconfig files, or code comments.
- Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints.
- Changes to numeric constants or macros that do not functionally alter execution flow.
- Code paths that are impossible to reach in virtualized environments like GCE or QEMU,
  even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim).
- Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed,
  ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU.
- Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove)
  that are executed only during PCI hot-unplug or sysfs driver unbind operations.

If it modifies reachable core kernel logic, drivers, or architectures, use your code search
tools to verify the code can be executed, then return WorthFuzzing=true.

When returning WorthFuzzing=true, you MUST ALSO:
1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols.
   Avoid listing generic hot-path functions to prevent skewed test distributions.
   Prefer non-static, non-inlined API entrypoint functions over internal static helper functions
   (which are inlined by the compiler and do not have distinct symbol addresses).
2. Identify any specific CONFIG_ options required to properly test this new/modified feature.
   Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions.
   Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs
   needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs
   output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit aaf7d7ca7d7df47750f7803a93ee63c6c6503fa3
Author: syz-cluster <triage@syzkaller.com>
Date:   Sat Jul 25 20:52:08 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/ABI/testing/debugfs-scmi b/Documentation/ABI/testing/debugfs-scmi
index ee7179ab2edfc7..edbbe360321d8a 100644
--- a/Documentation/ABI/testing/debugfs-scmi
+++ b/Documentation/ABI/testing/debugfs-scmi
@@ -68,3 +68,25 @@ Description:	Max number of concurrently allowed in-flight SCMI messages for
 		the currently configured SCMI transport for instance <n> on the
 		RX channels.
 Users:		Debugging, any userspace test suite
+
+What:		/sys/kernel/debug/scmi/<n>/protocols/0x<m>/
+Date:		Nov 2026
+KernelVersion:	7.3
+Contact:	cristian.marussi@arm.com
+Description:	A subdirectory grouping debug entries related to protocol <m>
+		for instance <n>. Each protocol owns and defines the subtree
+		of entries rooted under this directory.
+Users:		Debugging, any userspace test suite
+
+What:		/sys/kernel/debug/scmi/<n>/protocols/0x1B/shmtis/<m>
+Date:		Nov 2026
+KernelVersion:	7.3
+Contact:	cristian.marussi@arm.com
+Description:	A set of RO files exposed by the Telemetry protocol (0x1B) in
+		order to dump the latest snapshot of each SHMTI memory area in
+		binary format: each file is named by its SHMTI id.
+		File is seekable and a seek to position zero on an open file
+		causes the SHMTI snapshot to be refreshed; file timestamps are
+		updated after each snapshot.
+		This directory reports SHMTIs for instance <n>.
+Users:		Debugging, any userspace test suite
diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index d06cca9273c483..be733f8d60a02e 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -324,6 +324,14 @@ properties:
     required:
       - reg
 
+  protocol@1b:
+    $ref: '#/$defs/protocol-node'
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        const: 0x1b
+
 unevaluatedProperties: false
 
 $defs:
diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
index a68b1bea57a85c..22daa7ebf78ee5 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -54,6 +54,7 @@ Devices and I/O
    dcdbas
    vduse
    isapnp
+   stlm
 
 Everything else
 ===============
diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index 3f0ef1e27eb07d..de136c5967f496 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -399,6 +399,7 @@ Code  Seq#    Include File                                             Comments
 0xE5  00-3F  linux/fuse.h
 0xEC  00-01  drivers/platform/chrome/cros_ec_dev.h                     ChromeOS EC driver
 0xEE  00-09  uapi/linux/pfrut.h                                        Platform Firmware Runtime Update and Telemetry
+0xF1  00-FF  uapi/linux/scmi.h					       ARM SCMI Subsystem
 0xF3  00-3F  drivers/usb/misc/sisusbvga/sisusb.h                       sisfb (in development)
                                                                        <mailto:thomas@winischhofer.net>
 0xF6  all                                                              LTTng Linux Trace Toolkit Next Generation
diff --git a/Documentation/userspace-api/stlm.rst b/Documentation/userspace-api/stlm.rst
new file mode 100644
index 00000000000000..e34226b11373f4
--- /dev/null
+++ b/Documentation/userspace-api/stlm.rst
@@ -0,0 +1,143 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. stlm:
+
+=======================================
+STLM - ARM SCMI Telemetry Userspace API
+=======================================
+
+.. contents::
+
+Overview
+========
+
+ARM SCMI is a System and Configuration Management protocol, based on a
+client-server model, that defines a number of messages that allows a
+client/agent like Linux to discover, configure and make use of services
+provided by the server/platform firmware.
+
+SCMI v4.0 [1] introduced support for System Telemetry, through which an
+agent can dynamically enumerate, configure and collect Telemetry Data
+Events (DE) exposed by the platform.
+
+The SCMI System Telemetry driver exposes one or more dedicated devices,
+named as tlm_<N>, grouped under /dev/scmi/, one for each discovered SCMI
+instance.
+
+A IOCTL based interface is defined in order to enumerate, configure and
+read telemetry data, as succinctly described in the following.
+
+For more details on the uAPI, please see include/uapi/linux/scmi.h
+
+Resources Enumeration
+=====================
+
+ - SCMI_TLM_GET_INFO: Gather basic Telemetry features like number of
+   resources and versioning information.
+
+ - SCMI_TLM_GET_INTRVS: Enumerate available update intervals.
+
+ - SCMI_TLM_GET_DE_INFO: Retrieve DataEvent description.
+
+ - SCMI_TLM_GET_DE_LIST: Retrieve the list of all the existent DataEvent
+   descriptors.
+
+ - SCMI_TLM_GET_GRP_LIST: Gather a list of descriptors for all defined Groups.
+
+ - SCMI_TLM_GET_GRP_INFO: Gather information for a specific Group.
+
+ - SCMI_TLM_GET_GRP_DESC: Gather detailed group composition information for
+   the specified Group.
+
+
+Configuration
+=============
+
+ - SCMI_TLM_GET_CFG / SCMI_TLM_SET_CFG: Get or set the whole instance, or a
+   specific group, configuration.
+
+ - SCMI_TLM_GET_DE_CFG / SCMI_TLM_SET_DE_CFG: Get or set the configuration
+   of a specific DataEvent.
+
+ - SCMI_TLM_GET_ALL_CFG / SCMI_TLM_SET_ALL_CFG: Get or set the cumulative
+   configuration of ALL the DataEvents defined on the platform.
+
+Data Collection
+===============
+
+ - SCMI_TLM_DE_READ: Report the last updated sample for the specified
+   DataEvent.
+
+ - SCMI_TLM_BULK_READ: Report the last samples for all the currently enabled
+   DataEvents.
+
+ - SCMI_TLM_BATCH_READ: Report the last samples for the DataEvents IDs
+   specified within the samples input params.
+
+ - SCMI_TLM_SINGLE_READ: Trigger an immediate platform-side DataEvent
+   update and report the collected samples.
+
+Memory Mapped Raw Access
+------------------------
+
+ - SCMI_TLM_GET_SHMTI_LIST: Gather a list of open file descriptors, one for
+   each SHMTI memory areas defined for this instance, that can be used to
+   memory-map such areas in the calling process address space so as to be
+   able to directly access the SCMI Telemetry SHMTI areas shared by the
+   platform firmware, and parse the TDCF format.
+   The SCMI Telemetry TDCF format is defined in the specification at [1].
+
+
+Example
+=======
+
+.. code-block:: c
+
+	int main(int argc, char **argv)
+	{
+		struct scmi_tlm_de_config des_cfg = {};
+		struct scmi_tlm_config cfg = {};
+		struct scmi_tlm_de_sample samples[3] = {};
+		struct scmi_tlm_data_read data = {};
+		int fd, ret;
+
+		fd = open("/dev/scmi/tlm_0", O_RDWR);
+		if (fd < 0)
+			return fd;
+
+		/* Enable ALL Data Events with timestamps*/
+		des_cfg.enable = 1;
+		des_cfg.t_enable = 1;
+		ret = ioctl(fd, SCMI_TLM_SET_ALL_CFG, &des_cfg);
+		if (ret)
+			return ret;
+
+		/* Enable Telemetry as a whole, set a 400ms update interval */
+		cfg.enable = 1;
+		cfg.active.secs = 400;
+		cfg.active.exp = -3;
+
+		ret = ioctl(fd, SCMI_TLM_SET_CFG, &cfg);
+		if (ret)
+			return ret;
+
+		/* Read a selection of DEs */
+		samples[0].id = 0xA001;
+		samples[1].id = 0x0002;
+		samples[2].id = 0x1010;
+		data.num_samples = 3;
+		data.samples = (unsigned long)samples;
+
+		ret = ioctl(fd, SCMI_TLM_BATCH_READ, &data);
+		if (ret)
+			return ret;
+
+		for (int i = 0; i < 3; i++)
+			fprintf(stdout, "%llu: 0x%08X -> %llu\n",
+					samples[i].tstamp, samples[i].id, samples[i].val);
+
+		return 0;
+	}
+
+References
+==========
+[1]: https://developer.arm.com/documentation/den0056/latest/
diff --git a/MAINTAINERS b/MAINTAINERS
index a900d8ee05c94b..f5cc87baebd75e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26300,6 +26300,7 @@ F:	drivers/regulator/scmi-regulator.c
 F:	drivers/reset/reset-scmi.c
 F:	include/linux/sc[mp]i_protocol.h
 F:	include/trace/events/scmi.h
+F:	include/uapi/linux/scmi.h
 F:	include/uapi/linux/virtio_scmi.h
 
 SYSTEM CONTROL MANAGEMENT INTERFACE (SCMI) i.MX Extension Message Protocol drivers
diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index 783c24a20e2919..e7d8dd9fa907f4 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -69,6 +69,20 @@ config ARM_SCMI_DEBUG_COUNTERS
 	  such useful debug counters. This can be helpful for debugging and
 	  SCMI monitoring.
 
+config ARM_SCMI_DEBUG_PROTOCOLS
+	bool "Enable SCMI protocols debug"
+	select ARM_SCMI_NEED_DEBUGFS
+	depends on DEBUG_FS
+	default n
+	help
+	  Enables per-protocol specific debug features, where available.
+	  When provided, such per-protocol debugfs entries are grouped
+	  inside a common a subtree named by the protocol number and rooted
+	  under a per-instance 'protocols' directory.
+
+	  Such per-protocol entries subtree structure is freely defined
+	  within the related protocol code.
+
 config ARM_SCMI_QUIRKS
 	bool "Enable SCMI Quirks framework"
 	depends on JUMP_LABEL || COMPILE_TEST
@@ -99,4 +113,14 @@ config ARM_SCMI_POWER_CONTROL
 	  called scmi_power_control. Note this may be needed early in boot to
 	  catch early shutdown/reboot SCMI requests.
 
+config ARM_SCMI_SYSTEM_TELEMETRY
+	tristate "SCMI System Telemetry driver"
+	depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF)
+	help
+	  This enables SCMI Systemn Telemetry support that allows userspace to
+	  retrieve ARM Telemetry data made available via SCMI.
+
+	  This driver can also be built as a module.  If so, the module will be
+	  called scmi_system_telemetry.
+
 endmenu
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index 780cd62b2f78aa..20f8d55840a5fe 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -8,7 +8,7 @@ scmi-driver-$(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT) += raw_mode.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
 scmi-protocols-y := base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o
-scmi-protocols-y += pinctrl.o
+scmi-protocols-y += pinctrl.o telemetry.o
 scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
 
 obj-$(CONFIG_ARM_SCMI_PROTOCOL) += transports/
@@ -18,3 +18,4 @@ obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o
 obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
 
 obj-$(CONFIG_ARM_SCMI_POWER_CONTROL) += scmi_power_control.o
+obj-$(CONFIG_ARM_SCMI_SYSTEM_TELEMETRY) += scmi_system_telemetry.o
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index b9723c105fc1b5..5bed1a9f2de590 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -18,6 +18,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/property.h>
+#include <linux/notifier.h>
 #include <linux/refcount.h>
 #include <linux/scmi_protocol.h>
 #include <linux/spinlock.h>
@@ -46,6 +47,8 @@ enum scmi_error_codes {
 	SCMI_ERR_GENERIC = -8,	/* Generic Error */
 	SCMI_ERR_HARDWARE = -9,	/* Hardware Error */
 	SCMI_ERR_PROTOCOL = -10,/* Protocol Error */
+	SCMI_ERR_IN_USE = -11,  /* In Use Error */
+	SCMI_ERR_PARTIAL = -12, /* Partial Error */
 };
 
 static const int scmi_linux_errmap[] = {
@@ -61,6 +64,8 @@ static const int scmi_linux_errmap[] = {
 	-EIO,			/* SCMI_ERR_GENERIC */
 	-EREMOTEIO,		/* SCMI_ERR_HARDWARE */
 	-EPROTO,		/* SCMI_ERR_PROTOCOL */
+	-EBUSY,			/* SCMI_ERR_IN_USE */
+	-EINVAL,		/* SCMI_ERR_PARTIAL */
 };
 
 static inline int scmi_to_linux_errno(int errno)
@@ -317,6 +322,7 @@ enum debug_counters {
 /**
  * struct scmi_debug_info  - Debug common info
  * @top_dentry: A reference to the top debugfs dentry
+ * @protos: A reference to the top debugfs protocols subdirectory
  * @name: Name of this SCMI instance
  * @type: Type of this SCMI instance
  * @is_atomic: Flag to state if the transport of this instance is atomic
@@ -324,6 +330,7 @@ enum debug_counters {
  */
 struct scmi_debug_info {
 	struct dentry *top_dentry;
+	struct dentry *protos;
 	const char *name;
 	const char *type;
 	bool is_atomic;
@@ -681,8 +688,19 @@ static struct platform_driver __drv = {					       \
 	.probe = __tag##_probe,						       \
 }
 
+struct scmi_protocol_notifier {
+	u8 proto_id;
+	u8 evt_id;
+	const u32 *src_id;
+	struct notifier_block *nb;
+};
+
 void scmi_notification_instance_data_set(const struct scmi_handle *handle,
 					 void *priv);
 void *scmi_notification_instance_data_get(const struct scmi_handle *handle);
+int scmi_protocol_notifier_register(const struct scmi_handle *handle,
+				    struct scmi_protocol_notifier *pno);
+int scmi_protocol_notifier_unregister(const struct scmi_handle *handle,
+				      struct scmi_protocol_notifier *pno);
 int scmi_inflight_count(const struct scmi_handle *handle);
 #endif /* _SCMI_COMMON_H */
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 3e0d975ec94c44..82a7d2f690949d 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -18,6 +18,7 @@
 
 #include <linux/bitmap.h>
 #include <linux/cleanup.h>
+#include <linux/dcache.h>
 #include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/export.h>
@@ -90,6 +91,8 @@ struct scmi_xfers_info {
  * @gid: A reference for per-protocol devres management.
  * @users: A refcount to track effective users of this protocol.
  * @priv: Reference for optional protocol private data.
+ * @pno: A protocol instance notifier descriptor: active only when the
+ *	 included notifier block @nb is non-NULL.
  * @version: Protocol version supported by the platform as detected at runtime.
  * @negotiated_version: When the platform supports a newer protocol version,
  *			the agent will try to negotiate with the platform the
@@ -99,6 +102,8 @@ struct scmi_xfers_info {
  *			has completed.
  * @ph: An embedded protocol handle that will be passed down to protocol
  *	initialization code to identify this instance.
+ * @dbg: An optional reference to this protocol top debugfs directory; it will
+ *	 be automatically recursively removed on protocol de-initialization.
  *
  * Each protocol is initialized independently once for each SCMI platform in
  * which is defined by DT and implemented by the SCMI server fw.
@@ -109,9 +114,11 @@ struct scmi_protocol_instance {
 	void				*gid;
 	refcount_t			users;
 	void				*priv;
+	struct scmi_protocol_notifier   pno;
 	unsigned int			version;
 	unsigned int			negotiated_version;
 	struct scmi_protocol_handle	ph;
+	struct dentry			*dbg;
 };
 
 #define ph_to_pi(h)	container_of(h, struct scmi_protocol_instance, ph)
@@ -1655,6 +1662,24 @@ static void *scmi_get_protocol_priv(const struct scmi_protocol_handle *ph)
 	return pi->priv;
 }
 
+static int
+scmi_register_instance_notifier(const struct scmi_protocol_handle *ph, u8 evt_id,
+				const u32 *src_id, struct notifier_block *nb)
+{
+	struct scmi_protocol_instance *pi = ph_to_pi(ph);
+
+	pi->pno.proto_id = pi->proto->id;
+	pi->pno.evt_id = evt_id;
+	pi->pno.src_id = src_id;
+	/*
+	 * Ensure the descriptor fields are visibile when the notifier block is
+	 * made available
+	 */
+	smp_store_mb(pi->pno.nb, nb);
+
+	return 0;
+}
+
 static const struct scmi_xfer_ops xfer_ops = {
 	.xfer_get_init = xfer_get_init,
 	.reset_rx_to_maxsz = reset_rx_to_maxsz,
@@ -2072,6 +2097,25 @@ static void scmi_common_fastchannel_db_ring(struct scmi_fc_db_info *db)
 		SCMI_PROTO_FC_RING_DB(64);
 }
 
+static struct dentry *
+scmi_debugfs_proto_dentry_get(const struct scmi_protocol_handle *ph)
+{
+	struct scmi_protocol_instance *pi = ph_to_pi(ph);
+	struct scmi_info *info = handle_to_scmi_info(pi->handle);
+
+	if (!IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_PROTOCOLS) || !info->dbg)
+		return ERR_PTR(-ENODEV);
+
+	if (!pi->dbg) {
+		char proto_dir[8];
+
+		snprintf(proto_dir, 8, "0x%02X", pi->proto->id);
+		pi->dbg = debugfs_create_dir(proto_dir, info->dbg->protos);
+	}
+
+	return pi->dbg;
+}
+
 static const struct scmi_proto_helpers_ops helpers_ops = {
 	.extended_name_get = scmi_common_extended_name_get,
 	.get_max_msg_size = scmi_common_get_max_msg_size,
@@ -2082,6 +2126,7 @@ static const struct scmi_proto_helpers_ops helpers_ops = {
 	.protocol_msg_check = scmi_protocol_msg_check,
 	.fastchannel_init = scmi_common_fastchannel_init,
 	.fastchannel_db_ring = scmi_common_fastchannel_db_ring,
+	.debugfs_proto_dentry_get = scmi_debugfs_proto_dentry_get,
 };
 
 /**
@@ -2255,6 +2300,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,
 	pi->ph.hops = &helpers_ops;
 	pi->ph.set_priv = scmi_set_protocol_priv;
 	pi->ph.get_priv = scmi_get_protocol_priv;
+	pi->ph.instance_notifier_register = scmi_register_instance_notifier;
 	refcount_set(&pi->users, 1);
 
 	/*
@@ -2293,6 +2339,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,
 	return pi;
 
 clean:
+	debugfs_remove_recursive(pi->dbg);
 	/* Take care to put the protocol module's owner before releasing all */
 	scmi_protocol_put(proto);
 	devres_release_group(handle->dev, gid);
@@ -2317,24 +2364,37 @@ static struct scmi_protocol_instance * __must_check
 scmi_get_protocol_instance(const struct scmi_handle *handle, u8 protocol_id)
 {
 	struct scmi_protocol_instance *pi;
+	struct notifier_block *proto_notifier_nb = NULL;
 	struct scmi_info *info = handle_to_scmi_info(handle);
 
-	mutex_lock(&info->protocols_mtx);
-	pi = idr_find(&info->protocols, protocol_id);
+	scoped_guard(mutex, &info->protocols_mtx) {
+		pi = idr_find(&info->protocols, protocol_id);
+		if (pi) {
+			refcount_inc(&pi->users);
+		} else {
+			const struct scmi_protocol *proto;
 
-	if (pi) {
-		refcount_inc(&pi->users);
-	} else {
-		const struct scmi_protocol *proto;
+			/* Fails if protocol not registered on bus */
+			proto = scmi_protocol_get(protocol_id, &info->version);
+			if (!proto)
+				return ERR_PTR(-EPROBE_DEFER);
 
-		/* Fails if protocol not registered on bus */
-		proto = scmi_protocol_get(protocol_id, &info->version);
-		if (proto)
 			pi = scmi_alloc_init_protocol_instance(info, proto);
-		else
-			pi = ERR_PTR(-EPROBE_DEFER);
+			if (IS_ERR(pi))
+				return pi;
+
+			proto_notifier_nb = READ_ONCE(pi->pno.nb);
+		}
+	}
+
+	if (proto_notifier_nb) {
+		int ret;
+
+		ret = scmi_protocol_notifier_register(pi->handle, &pi->pno);
+		if (ret)
+			dev_warn(handle->dev,
+				 "Failed to register protocol notifier\n");
 	}
-	mutex_unlock(&info->protocols_mtx);
 
 	return pi;
 }
@@ -2365,16 +2425,34 @@ int scmi_protocol_acquire(const struct scmi_handle *handle, u8 protocol_id)
 void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id)
 {
 	struct scmi_info *info = handle_to_scmi_info(handle);
+	struct notifier_block *proto_notifier_nb = NULL;
 	struct scmi_protocol_instance *pi;
 
-	mutex_lock(&info->protocols_mtx);
-	pi = idr_find(&info->protocols, protocol_id);
-	if (WARN_ON(!pi))
-		goto out;
+	scoped_guard(mutex, &info->protocols_mtx) {
+		pi = idr_find(&info->protocols, protocol_id);
+		if (WARN_ON(!pi))
+			return;
 
+		proto_notifier_nb = pi->pno.nb;
+		/* Ensure NULL is visible */
+		smp_store_mb(pi->pno.nb, NULL);
+	}
+
+	if (proto_notifier_nb) {
+		int ret;
+
+		ret = scmi_protocol_notifier_unregister(pi->handle, &pi->pno);
+		if (ret)
+			dev_err(handle->dev,
+				"Failed to release protocol notifier\n");
+	}
+
+	guard(mutex)(&info->protocols_mtx);
 	if (refcount_dec_and_test(&pi->users)) {
 		void *gid = pi->gid;
 
+		debugfs_remove_recursive(pi->dbg);
+
 		if (pi->proto->events)
 			scmi_deregister_protocol_events(handle, protocol_id);
 
@@ -2389,9 +2467,6 @@ void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id)
 		dev_dbg(handle->dev, "De-Initialized protocol: 0x%X\n",
 			protocol_id);
 	}
-
-out:
-	mutex_unlock(&info->protocols_mtx);
 }
 
 void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph,
@@ -3100,6 +3175,9 @@ static struct scmi_debug_info *scmi_debugfs_common_setup(struct scmi_info *info)
 	if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_COUNTERS))
 		scmi_debugfs_counters_setup(dbg, trans);
 
+	if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_PROTOCOLS))
+		dbg->protos = debugfs_create_dir("protocols", top_dentry);
+
 	dbg->top_dentry = top_dentry;
 
 	if (devm_add_action_or_reset(info->dev,
@@ -3252,6 +3330,7 @@ static int scmi_probe(struct platform_device *pdev)
 	idr_init(&info->rx_idr);
 
 	handle = &info->handle;
+	handle->id = info->id;
 	handle->dev = info->dev;
 	handle->version = &info->version;
 	handle->devm_protocol_acquire = scmi_devm_protocol_acquire;
@@ -3532,6 +3611,7 @@ static int __init scmi_driver_init(void)
 	scmi_system_register();
 	scmi_powercap_register();
 	scmi_pinctrl_register();
+	scmi_telemetry_register();
 
 	return platform_driver_register(&scmi_driver);
 }
@@ -3550,6 +3630,7 @@ static void __exit scmi_driver_exit(void)
 	scmi_system_unregister();
 	scmi_powercap_unregister();
 	scmi_pinctrl_unregister();
+	scmi_telemetry_unregister();
 
 	platform_driver_unregister(&scmi_driver);
 
diff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi/notify.c
index 0a192cf2deab62..938d575e22fe0d 100644
--- a/drivers/firmware/arm_scmi/notify.c
+++ b/drivers/firmware/arm_scmi/notify.c
@@ -595,7 +595,13 @@ int scmi_notify(const struct scmi_handle *handle, u8 proto_id, u8 evt_id,
 	if (!r_evt)
 		return -EINVAL;
 
-	if (len > r_evt->evt->max_payld_sz) {
+	/*
+	 * Events with a zero max_payld_sz are sized to be of the maximum
+	 * size allowed by the transport: no need to be size-checked here
+	 * since the transport layer would have already dropped such
+	 * over-sized messages.
+	 */
+	if (r_evt->evt->max_payld_sz && len > r_evt->evt->max_payld_sz) {
 		dev_err(handle->dev, "discard badly sized message\n");
 		return -EINVAL;
 	}
@@ -754,7 +760,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 				  const struct scmi_protocol_handle *ph,
 				  const struct scmi_protocol_events *ee)
 {
-	int i;
+	int i, max_msg_sz;
 	unsigned int num_sources;
 	size_t payld_sz = 0;
 	struct scmi_registered_events_desc *pd;
@@ -769,6 +775,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 	if (!ni)
 		return -ENOMEM;
 
+	max_msg_sz = ph->hops->get_max_msg_size(ph);
+
 	/* num_sources cannot be <= 0 */
 	if (ee->num_sources) {
 		num_sources = ee->num_sources;
@@ -781,8 +789,13 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 	}
 
 	evt = ee->evts;
-	for (i = 0; i < ee->num_events; i++)
-		payld_sz = max_t(size_t, payld_sz, evt[i].max_payld_sz);
+	for (i = 0; i < ee->num_events; i++) {
+		if (evt[i].max_payld_sz == 0) {
+			payld_sz = max_msg_sz;
+			break;
+		}
+		payld_sz = max(payld_sz, evt[i].max_payld_sz);
+	}
 	payld_sz += sizeof(struct scmi_event_header);
 
 	pd = scmi_allocate_registered_events_desc(ni, proto_id, ee->queue_sz,
@@ -811,7 +824,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 		mutex_init(&r_evt->sources_mtx);
 
 		r_evt->report = devm_kzalloc(ni->handle->dev,
-					     evt->max_report_sz, GFP_KERNEL);
+					     evt->max_report_sz ?: max_msg_sz,
+					     GFP_KERNEL);
 		if (!r_evt->report)
 			return -ENOMEM;
 
@@ -1406,6 +1420,13 @@ static int scmi_notifier_register(const struct scmi_handle *handle,
 	return ret;
 }
 
+int scmi_protocol_notifier_register(const struct scmi_handle *handle,
+				    struct scmi_protocol_notifier *pno)
+{
+	return scmi_notifier_register(handle, pno->proto_id, pno->evt_id,
+				      pno->src_id, pno->nb);
+}
+
 /**
  * scmi_notifier_unregister()  - Unregister a notifier_block for an event
  * @handle: The handle identifying the platform instance against which the
@@ -1463,6 +1484,13 @@ static int scmi_notifier_unregister(const struct scmi_handle *handle,
 	return 0;
 }
 
+int scmi_protocol_notifier_unregister(const struct scmi_handle *handle,
+				      struct scmi_protocol_notifier *pno)
+{
+	return scmi_notifier_unregister(handle, pno->proto_id, pno->evt_id,
+					pno->src_id, pno->nb);
+}
+
 struct scmi_notifier_devres {
 	const struct scmi_handle *handle;
 	u8 proto_id;
diff --git a/drivers/firmware/arm_scmi/notify.h b/drivers/firmware/arm_scmi/notify.h
index 76758a736cf47a..ecfa4b746487d3 100644
--- a/drivers/firmware/arm_scmi/notify.h
+++ b/drivers/firmware/arm_scmi/notify.h
@@ -18,8 +18,12 @@
 /**
  * struct scmi_event  - Describes an event to be supported
  * @id: Event ID
- * @max_payld_sz: Max possible size for the payload of a notification message
- * @max_report_sz: Max possible size for the report of a notification message
+ * @max_payld_sz: Max possible size for the payload of a notification message.
+ *		  Set to zero to use the maximum payload size allowed by the
+ *		  transport.
+ * @max_report_sz: Max possible size for the report of a notification message.
+ *		  Set to zero to use the maximum payload size allowed by the
+ *		  transport.
  *
  * Each SCMI protocol, during its initialization phase, can describe the events
  * it wishes to support in a few struct scmi_event and pass them to the core
diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h
index 15ad5162e37a90..04e196a9fbf4af 100644
--- a/drivers/firmware/arm_scmi/protocols.h
+++ b/drivers/firmware/arm_scmi/protocols.h
@@ -11,6 +11,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/completion.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -166,6 +167,13 @@ struct scmi_proto_helpers_ops;
  *	  can be used by the protocol implementation to generate SCMI messages.
  * @set_priv: A method to set protocol private data for this instance.
  * @get_priv: A method to get protocol private data previously set.
+ * @instance_notifier_register: A method to register interest for specific
+ *				notifications from within a protocol
+ *				implementation unit: ONLY one instance notifier
+ *				can be registered per-protocol.
+ *				The related notifier block will be registered
+ *				right after the protocol is initialized and
+ *				automatically removed on protocol release.
  *
  * This structure represents a protocol initialized against specific SCMI
  * instance and it will be used as follows:
@@ -185,6 +193,9 @@ struct scmi_protocol_handle {
 	const struct scmi_proto_helpers_ops *hops;
 	int (*set_priv)(const struct scmi_protocol_handle *ph, void *priv);
 	void *(*get_priv)(const struct scmi_protocol_handle *ph);
+	int (*instance_notifier_register)(const struct scmi_protocol_handle *ph,
+					  u8 evt_id, const u32 *src_id,
+					  struct notifier_block *nb);
 };
 
 /**
@@ -274,6 +285,9 @@ struct scmi_fc_info {
  *		      gathering FC descriptions from the SCMI platform server.
  * @fastchannel_db_ring: A common helper to ring a FC doorbell.
  * @get_max_msg_size: A common helper to get the maximum message size.
+ * @debugfs_proto_dentry_get: A common helper to get a per-protocol debugfs top
+ *			      directory to use as a root. It will be
+ *			      recursively removed on protocol de-initialization.
  */
 struct scmi_proto_helpers_ops {
 	int (*extended_name_get)(const struct scmi_protocol_handle *ph,
@@ -297,6 +311,8 @@ struct scmi_proto_helpers_ops {
 				 u32 *rate_limit);
 	void (*fastchannel_db_ring)(struct scmi_fc_db_info *db);
 	int (*get_max_msg_size)(const struct scmi_protocol_handle *ph);
+	struct dentry *(*debugfs_proto_dentry_get)
+		(const struct scmi_protocol_handle *ph);
 };
 
 /**
@@ -391,5 +407,6 @@ DECLARE_SCMI_REGISTER_UNREGISTER(sensors);
 DECLARE_SCMI_REGISTER_UNREGISTER(voltage);
 DECLARE_SCMI_REGISTER_UNREGISTER(system);
 DECLARE_SCMI_REGISTER_UNREGISTER(powercap);
+DECLARE_SCMI_REGISTER_UNREGISTER(telemetry);
 
 #endif /* _SCMI_PROTOCOLS_H */
diff --git a/drivers/firmware/arm_scmi/scmi_system_telemetry.c b/drivers/firmware/arm_scmi/scmi_system_telemetry.c
new file mode 100644
index 00000000000000..06042e37912d2e
--- /dev/null
+++ b/drivers/firmware/arm_scmi/scmi_system_telemetry.c
@@ -0,0 +1,1135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SCMI - System Telemetry Driver
+ *
+ * Copyright (C) 2026 ARM Ltd.
+ */
+
+#include <linux/anon_inodes.h>
+#include <linux/atomic.h>
+#include <linux/ctype.h>
+#include <linux/cdev.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/list.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/overflow.h>
+#include <linux/scmi_protocol.h>
+#include <linux/slab.h>
+#include <linux/sprintf.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
+#include <linux/wait.h>
+
+#include <uapi/linux/scmi.h>
+
+#define SCMI_TLM_DRIVER		"scmi-telemetry-driver"
+#define SCMI_TLM_NUM_DEVS	256
+
+#define MAX_BULK_LINE_CHAR_LENGTH		64
+
+/*
+ * Break if inadvertently struct scmi_telemetry_de_sample deviates from the
+ * UAPI counterpart struct scmi_tlm_de_sample: this allows more performant
+ * single DE reads.
+ */
+#define SCMI_DE_SAMPLE_BUILD_SANITY_CHECK				  \
+({									  \
+	BUILD_BUG_ON_MSG(sizeof(struct scmi_telemetry_de_sample) !=	  \
+			 sizeof(struct scmi_tlm_de_sample),		  \
+			 "UAPI DE sample mismatch !");			  \
+	ASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, id,	  \
+			     offsetof(struct scmi_tlm_de_sample, id));	  \
+	ASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, pad,	  \
+			     offsetof(struct scmi_tlm_de_sample, pad));	  \
+	ASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, tstamp,	  \
+			     offsetof(struct scmi_tlm_de_sample, tstamp));\
+	ASSERT_STRUCT_OFFSET(struct scmi_telemetry_de_sample, val,	  \
+			     offsetof(struct scmi_tlm_de_sample, val));	  \
+})
+
+static dev_t stlm_devt;
+
+/**
+ * struct scmi_tlm_setup  - Telemetry setup descriptor
+ * @dev: A reference to the related device
+ * @ph: A reference to the protocol handle to be used with the ops
+ * @rinfo: A reference to the resource info descriptor
+ * @ops: A reference to the protocol ops
+ */
+struct scmi_tlm_setup {
+	struct device *dev;
+	struct scmi_protocol_handle *ph;
+	const struct scmi_telemetry_res_info *rinfo;
+	const struct scmi_telemetry_proto_ops *ops;
+};
+
+/**
+ * struct scmi_tlm_instance  - Telemetry instance descriptor
+ * @id: Progressive number identifying this probed instance.
+ * @devt: The dev_t descriptor attached to this instance
+ * @cdev:
+ * @node: A node to link this in the list of all instances.
+ * @tsp: A reference to the SCMI instance data.
+ * @info: A reference to this instance SCMI Telemetry info data.
+ */
+struct scmi_tlm_instance {
+	unsigned int id;
+	dev_t devt;
+	struct cdev cdev;
+	struct list_head node;
+	struct scmi_tlm_setup *tsp;
+	const struct scmi_telemetry_info *info;
+};
+
+#define to_instance(c)	container_of(c, struct scmi_tlm_instance, cdev)
+
+struct scmi_tlm_shmti_ctx {
+	struct scmi_telemetry_shmti_info *shmti;
+	struct kref kref;
+};
+
+#define to_shmti_ctx(c)	container_of(c, struct scmi_tlm_shmti_ctx, kref)
+
+static inline void scmi_tlm_to_uapi_abi_info(struct scmi_tlm_abi_info *out,
+					     const struct scmi_telemetry_info *in)
+{
+	u8 *impl_version = (u8 *)in->base.de_impl_version;
+
+	out->size = sizeof(*out);
+	out->abi_version = SCMI_TLM_CURRENT_ABI_VERSION;
+	out->abi_features = SCMI_TLM_ABI_FEAT_RESET;
+	/* Each word composing the UUID was stored in big-endian */
+	for (int i = 0; i < SCMI_TLM_DE_IMPL_UUID_MAX; i++)
+		out->de_impl_version[i] = impl_version[i];
+
+	out->num_des = in->base.num_des;
+	out->num_groups = in->base.num_groups;
+	out->num_intervals = in->base.num_intervals;
+	out->num_shmtis = in->base.num_shmtis;
+	out->features = in->reset_support ? SCMI_TLM_BASE_SUPPORT_RESET : 0;
+	out->features |= in->single_read_support ?
+		SCMI_TLM_BASE_SUPPORT_SINGLE_SAMPLE : 0;
+	out->features |= in->per_group_config_support ?
+		SCMI_TLM_BASE_SUPPORT_GROUP_CONFIG : 0;
+	out->features |= in->continuos_update_support ?
+		SCMI_TLM_BASE_SUPPORT_UPDATE_NOTIFICATION : 0;
+	out->reserved = 0;
+}
+
+static inline void
+scmi_tlm_to_uapi_intervals(struct scmi_tlm_intervals *out,
+			   struct scmi_telemetry_intervals *in,
+			   struct scmi_tlm_update_interval *out_interv)
+{
+	unsigned int *in_interv = in->update_intervals;
+
+	out->num_intervals = 0;
+	for (int i = 0; i < in->num_intervals; i++) {
+		out_interv[i].secs =
+			SCMI_TLM_GET_UPDATE_INTERVAL_SECS(in_interv[i]);
+		out_interv[i].exp =
+			SCMI_TLM_GET_UPDATE_INTERVAL_EXP(in_interv[i]);
+
+		/* Count returned items */
+		out->num_intervals++;
+	}
+}
+
+static inline void scmi_tlm_to_uapi_de_info(struct scmi_tlm_de_info *out,
+					    struct scmi_telemetry_de_info *in)
+{
+	out->id = in->id;
+	out->grp_id = in->grp_id;
+	out->data_sz = in->data_sz;
+	out->type = in->type;
+	out->unit = in->unit;
+	out->unit_exp = in->unit_exp;
+	out->ts_rate = in->ts_rate;
+	out->instance_id = in->instance_id;
+	out->compo_instance_id = in->compo_instance_id;
+	out->compo_type = in->compo_type;
+	out->persistent = !!in->persistent;
+	out->flags = in->grp_id != SCMI_TLM_GRP_INVALID ?
+		SCMI_TLM_DEINFO_GROUP : 0;
+	out->pad[0] = 0;
+	out->pad[1] = 0;
+	out->pad2 = 0;
+	memcpy(out->name, in->name, 16);
+}
+
+static inline void
+scmi_tlm_to_uapi_des_list(struct scmi_tlm_des_list *out,
+			  const struct scmi_telemetry_res_info *in,
+			  struct scmi_tlm_de_info *des)
+{
+	out->num_des = 0;
+	for (int i = 0; i < in->num_des; i++) {
+		scmi_tlm_to_uapi_de_info(&des[i], &in->dei_store[i]);
+
+		/* Count returned items */
+		out->num_des++;
+	}
+}
+
+static inline void scmi_tlm_to_uapi_grp_info(struct scmi_tlm_grp_info *out,
+					     struct scmi_telemetry_grp_info *in)
+{
+	out->grp_id = in->grp_id;
+	out->num_des = in->num_des;
+	out->num_intervals = in->num_intervals;
+	out->pad = 0;
+}
+
+static inline void
+scmi_tlm_to_uapi_grps_list(struct scmi_tlm_grps_list *out,
+			   const struct scmi_telemetry_res_info *in,
+			   struct scmi_tlm_grp_info *ginfo)
+{
+	struct scmi_tlm_grp_info *out_ginfo = ginfo;
+
+	out->num_grps = 0;
+	for (int i = 0; i < in->num_groups; i++) {
+		scmi_tlm_to_uapi_grp_info(&out_ginfo[i], &in->grps_store[i]);
+
+		/* Count returned items */
+		out->num_grps++;
+	}
+}
+
+static inline void
+scmi_tlm_to_uapi_composing_des(struct scmi_tlm_grp_desc *out,
+			       const struct scmi_telemetry_res_info *in,
+			       u32 *composing_des)
+{
+	struct scmi_telemetry_grp_info *ginfo = &in->grps_store[out->grp_id];
+	struct scmi_telemetry_group *grp = &in->grps[out->grp_id];
+
+	out->num_des = 0;
+	for (int i = 0; i < ginfo->num_des; i++) {
+		composing_des[i] = in->des[grp->des[i]]->info->id;
+
+		/* Count returned items */
+		out->num_des++;
+	}
+}
+
+/**
+ * scmi_telemetry_res_info_get  - Resources info getter
+ * @tsp: A reference to the telemetry instance setup
+ *
+ * On first call this helper takes care to retrieve and cache all the resources
+ * descriptor from the platform, then, on the following invocations it will
+ * always return the cached value.
+ */
+static inline const struct scmi_telemetry_res_info *
+scmi_telemetry_res_info_get(struct scmi_tlm_setup *tsp)
+{
+	const struct scmi_telemetry_res_info *rinfo;
+
+	if (READ_ONCE(tsp->rinfo))
+		return tsp->rinfo;
+
+	rinfo = tsp->ops->res_get(tsp->ph);
+	/* Cache the retrieved resource info value */
+	smp_store_mb(tsp->rinfo, rinfo);
+
+	return rinfo;
+}
+
+static long
+scmi_tlm_abi_info_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	struct scmi_tlm_abi_info base = {};
+	void __user *uptr = (void __user *)arg;
+	bool ignored_trailing;
+	u32 usize;
+	int err;
+
+	if (get_user(usize, (u32 __user *)arg))
+		return -EFAULT;
+
+	if (usize < offsetofend(struct scmi_tlm_abi_info, reserved))
+		return -EINVAL;
+
+	if (copy_struct_from_user(&base, sizeof(base), uptr, usize))
+		return -EFAULT;
+
+	scmi_tlm_to_uapi_abi_info(&base, ti->info);
+	err = copy_struct_to_user(uptr, usize, &base, sizeof(base),
+				  &ignored_trailing);
+	if (err)
+		return err;
+
+	if (ignored_trailing)
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+static long
+scmi_tlm_config_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_config cfg;
+
+	if (copy_from_user(&cfg, uptr, sizeof(cfg)))
+		return -EFAULT;
+
+	if (cfg.pad || cfg.flags & ~SCMI_TLM_CONFIG_FLAGS)
+		return -EINVAL;
+
+	if (!(SCMI_TLM_CONFIG_IS_GROUP(cfg.flags))) {
+		unsigned int active = ti->info->active_update_interval;
+
+		cfg.enable = !!ti->info->enabled;
+		cfg.active.secs = SCMI_TLM_GET_UPDATE_INTERVAL_SECS(active);
+		cfg.active.exp = SCMI_TLM_GET_UPDATE_INTERVAL_EXP(active);
+	} else {
+		const struct scmi_telemetry_res_info *rinfo;
+		struct scmi_telemetry_group *grp;
+		unsigned int active;
+
+		rinfo = scmi_telemetry_res_info_get(ti->tsp);
+		if (cfg.grp_id >= rinfo->num_groups)
+			return -EINVAL;
+
+		grp = &rinfo->grps[cfg.grp_id];
+		active = grp->active_update_interval;
+
+		cfg.enable = grp->enabled;
+		cfg.t_enable = grp->tstamp_enabled;
+		cfg.active.secs = SCMI_TLM_GET_UPDATE_INTERVAL_SECS(active);
+		cfg.active.exp = SCMI_TLM_GET_UPDATE_INTERVAL_EXP(active);
+	}
+
+	if (copy_to_user(uptr, &cfg, sizeof(cfg)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_config_set_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	struct scmi_tlm_config cfg;
+	unsigned int active;
+	bool ena, t_ena;
+
+	if (copy_from_user(&cfg, uptr, sizeof(cfg)))
+		return -EFAULT;
+
+	if (cfg.pad || cfg.flags & ~SCMI_TLM_CONFIG_FLAGS)
+		return -EINVAL;
+
+	ena = !!cfg.enable;
+	t_ena = !!cfg.t_enable;
+	if (!SCMI_TLM_CONFIG_IS_GROUP(cfg.flags)) {
+		cfg.grp_id = SCMI_TLM_GRP_INVALID;
+	} else {
+		int ret;
+
+		ret = tsp->ops->state_set(tsp->ph, true, cfg.grp_id, &ena, &t_ena);
+		if (ret)
+			return ret;
+	}
+
+	active = SCMI_TLM_BUILD_UPDATE_INTERVAL(cfg.active.secs, cfg.active.exp);
+
+	return tsp->ops->collection_configure(tsp->ph, cfg.grp_id, &ena, &active, NULL);
+}
+
+static long
+scmi_tlm_intervals_get_ioctl(const struct scmi_tlm_instance *ti,
+			     unsigned long arg)
+{
+	struct scmi_telemetry_intervals *tlm_ivs;
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_intervals ivs;
+	size_t ivs_intrv_sz;
+
+	if (copy_from_user(&ivs, uptr, sizeof(ivs)))
+		return -EFAULT;
+
+	if (ivs.pad[0] || ivs.pad[1] || ivs.pad[2] || ivs.pad2 ||
+	    ivs.flags & ~SCMI_TLM_INTERV_FLAGS)
+		return -EINVAL;
+
+	if (!SCMI_TLM_INTERV_IS_GROUP(ivs.flags)) {
+		tlm_ivs = ti->info->intervals;
+	} else {
+		const struct scmi_telemetry_res_info *rinfo;
+
+		rinfo = scmi_telemetry_res_info_get(ti->tsp);
+		if (ivs.grp_id >= rinfo->num_groups)
+			return -EINVAL;
+
+		tlm_ivs = rinfo->grps[ivs.grp_id].intervals;
+	}
+
+	/* Reject only undersized buffers */
+	if (ivs.num_intervals < tlm_ivs->num_intervals)
+		return -ENOSPC;
+
+	/* A local scratch buffer... */
+	ivs_intrv_sz = ivs.num_intervals * sizeof(struct scmi_tlm_update_interval);
+	struct scmi_tlm_update_interval *ivs_intrv __free(kfree) =
+		kzalloc(ivs_intrv_sz, GFP_KERNEL);
+	if (!ivs_intrv)
+		return -ENOMEM;
+
+	if (copy_from_user(ivs_intrv, u64_to_user_ptr(ivs.intervals),
+			   ivs_intrv_sz))
+		return -EFAULT;
+
+	/* Passing the array as a param avoids dancing with uptr->intervals */
+	scmi_tlm_to_uapi_intervals(&ivs, tlm_ivs, ivs_intrv);
+	if (copy_to_user(u64_to_user_ptr(ivs.intervals),
+			 (void *)ivs_intrv, ivs_intrv_sz))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &ivs, sizeof(ivs)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_de_config_set_ioctl(const struct scmi_tlm_instance *ti,
+			     unsigned long arg, bool all)
+{
+	const struct scmi_telemetry_res_info *rinfo;
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	struct scmi_tlm_de_config tcfg;
+	bool ena, t_ena;
+	int ret;
+
+	if (copy_from_user(&tcfg, uptr, sizeof(tcfg)))
+		return -EFAULT;
+
+	if (tcfg.pad)
+		return -EINVAL;
+
+	ena = !!tcfg.enable;
+	t_ena = !!tcfg.t_enable;
+	if (!all)
+		return tsp->ops->state_set(tsp->ph, false, tcfg.id, &ena, &t_ena);
+
+	rinfo = scmi_telemetry_res_info_get(tsp);
+	for (int i = 0; i < rinfo->num_des; i++) {
+		ret = tsp->ops->state_set(tsp->ph, false,
+					  rinfo->des[i]->info->id, &ena, &t_ena);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static long
+scmi_tlm_de_config_get_ioctl(const struct scmi_tlm_instance *ti,
+			     unsigned long arg, bool all)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	struct scmi_tlm_de_config tcfg;
+	bool ena, t_ena;
+	int ret;
+
+	if (copy_from_user(&tcfg, uptr, sizeof(tcfg)))
+		return -EFAULT;
+
+	if (tcfg.pad)
+		return -EINVAL;
+
+	ena = !!tcfg.enable;
+	t_ena = !!tcfg.t_enable;
+	ret = tsp->ops->state_get(tsp->ph, all ? NULL : &tcfg.id, &ena, &t_ena);
+	if (ret)
+		return ret;
+
+	tcfg.enable = ena;
+	tcfg.t_enable = t_ena;
+	if (copy_to_user(uptr, &tcfg, sizeof(tcfg)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_de_info_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	const struct scmi_telemetry_de *de;
+	struct scmi_tlm_de_info dei;
+
+	if (copy_from_user(&dei, uptr, sizeof(dei)))
+		return -EFAULT;
+
+	/* Flags does NOT make sense in the input param */
+	if (dei.pad[0] || dei.pad[1] || dei.flags)
+		return -EINVAL;
+
+	de = tsp->ops->de_lookup(tsp->ph, dei.id);
+	if (!de)
+		return -EINVAL;
+
+	scmi_tlm_to_uapi_de_info(&dei, de->info);
+	if (copy_to_user(uptr, &dei, sizeof(dei)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_des_list_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	const struct scmi_telemetry_res_info *rinfo;
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_des_list dsl;
+	size_t dsl_des_sz;
+
+	if (copy_from_user(&dsl, uptr, sizeof(dsl)))
+		return -EFAULT;
+
+	if (dsl.pad)
+		return -EINVAL;
+
+	rinfo = scmi_telemetry_res_info_get(ti->tsp);
+	/* Reject only undersized buffers */
+	if (dsl.num_des < rinfo->num_des)
+		return -ENOSPC;
+
+	/* A local scratch buffer... */
+	dsl_des_sz = dsl.num_des * sizeof(struct scmi_tlm_de_info);
+	struct scmi_tlm_de_info *dsl_des __free(kfree) =
+		kzalloc(dsl_des_sz, GFP_KERNEL);
+	if (!dsl_des)
+		return -ENOMEM;
+
+	if (copy_from_user(dsl_des, u64_to_user_ptr(dsl.des), dsl_des_sz))
+		return -EFAULT;
+
+	/* Passing the array as a param avoids dancing with uptr->intervals */
+	scmi_tlm_to_uapi_des_list(&dsl, rinfo, dsl_des);
+	if (copy_to_user(u64_to_user_ptr(dsl.des), (void *)dsl_des, dsl_des_sz))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &dsl, sizeof(dsl)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_de_value_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	struct scmi_tlm_de_sample sample;
+	int ret;
+
+	SCMI_DE_SAMPLE_BUILD_SANITY_CHECK;
+
+	if (copy_from_user(&sample, uptr, sizeof(sample)))
+		return -EFAULT;
+
+	if (sample.pad)
+		return -EINVAL;
+
+	ret = tsp->ops->de_data_read(tsp->ph,
+				     (struct scmi_telemetry_de_sample *)&sample);
+	if (ret)
+		return ret;
+
+	if (copy_to_user(uptr, &sample, sizeof(sample)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_grp_info_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	const struct scmi_telemetry_res_info *rinfo;
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_grp_info ginfo;
+
+	if (copy_from_user(&ginfo, uptr, sizeof(ginfo)))
+		return -EFAULT;
+
+	if (ginfo.pad)
+		return -EINVAL;
+
+	rinfo = scmi_telemetry_res_info_get(ti->tsp);
+	if (ginfo.grp_id >= rinfo->num_groups)
+		return -EINVAL;
+
+	scmi_tlm_to_uapi_grp_info(&ginfo, &rinfo->grps_store[ginfo.grp_id]);
+	if (copy_to_user(uptr, &ginfo, sizeof(ginfo)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_grp_desc_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	const struct scmi_telemetry_res_info *rinfo;
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_grp_desc gdesc;
+	size_t composing_sz;
+
+	if (copy_from_user(&gdesc, uptr, sizeof(gdesc)))
+		return -EFAULT;
+
+	rinfo = scmi_telemetry_res_info_get(ti->tsp);
+	if (gdesc.grp_id >= rinfo->num_groups)
+		return -EINVAL;
+
+	/* Reject only undersized buffers */
+	if (gdesc.num_des < rinfo->grps_store[gdesc.grp_id].num_des)
+		return -ENOSPC;
+
+	/* A local scratch buffer... */
+	composing_sz = gdesc.num_des * sizeof(u32);
+	u32 *composing_des __free(kfree) = kzalloc(composing_sz, GFP_KERNEL);
+	if (!composing_des)
+		return -ENOMEM;
+
+	if (copy_from_user(composing_des, u64_to_user_ptr(gdesc.composing_des),
+			   composing_sz))
+		return -EFAULT;
+
+	/* Passing the array as a param avoids dancing with uptr->intervals */
+	scmi_tlm_to_uapi_composing_des(&gdesc, rinfo, composing_des);
+	if (copy_to_user(u64_to_user_ptr(gdesc.composing_des), composing_des,
+			 composing_sz))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &gdesc, sizeof(gdesc)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+scmi_tlm_grps_list_get_ioctl(const struct scmi_tlm_instance *ti, unsigned long arg)
+{
+	const struct scmi_telemetry_res_info *rinfo;
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_grps_list gsl;
+	size_t ginfo_sz;
+
+	if (copy_from_user(&gsl, uptr, sizeof(gsl)))
+		return -EFAULT;
+
+	if (gsl.pad)
+		return -EINVAL;
+
+	rinfo = scmi_telemetry_res_info_get(ti->tsp);
+	/* Reject only undersized buffers */
+	if (gsl.num_grps < rinfo->num_groups)
+		return -ENOSPC;
+
+	/* A local scratch buffer... */
+	ginfo_sz = gsl.num_grps * sizeof(struct scmi_tlm_grp_info);
+	struct scmi_tlm_grp_info *ginfo __free(kfree) =
+		kzalloc(ginfo_sz, GFP_KERNEL);
+	if (!ginfo)
+		return -ENOMEM;
+
+	if (copy_from_user(ginfo, u64_to_user_ptr(gsl.grps), ginfo_sz))
+		return -EFAULT;
+
+	scmi_tlm_to_uapi_grps_list(&gsl, rinfo, ginfo);
+	if (copy_to_user(u64_to_user_ptr(gsl.grps), ginfo, ginfo_sz))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &gsl, sizeof(gsl)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long scmi_tlm_des_read_ioctl(const struct scmi_tlm_instance *ti,
+				    unsigned long arg, bool single)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	struct scmi_tlm_data_read bulk;
+	unsigned int grp_id;
+	int ret;
+
+	if (copy_from_user(&bulk, uptr, sizeof(bulk)))
+		return -EFAULT;
+
+	if (bulk.pad[0] || bulk.pad[1] || bulk.pad[2] || bulk.pad2 ||
+	    bulk.flags & ~SCMI_TLM_READ_FLAGS)
+		return -EINVAL;
+
+	if (!SCMI_TLM_READ_IS_GROUP(bulk.flags)) {
+		grp_id = SCMI_TLM_GRP_INVALID;
+	} else {
+		const struct scmi_telemetry_res_info *rinfo;
+
+		rinfo = scmi_telemetry_res_info_get(tsp);
+		if (bulk.grp_id >= rinfo->num_groups)
+			return -EINVAL;
+
+		grp_id = bulk.grp_id;
+	}
+
+	struct scmi_telemetry_de_sample *samples __free(kfree) =
+		kcalloc(bulk.num_samples, sizeof(*samples), GFP_KERNEL);
+	if (!samples)
+		return -ENOMEM;
+
+	if (!single)
+		ret = tsp->ops->des_bulk_read(tsp->ph, grp_id,
+					      &bulk.num_samples, samples);
+	else
+		ret = tsp->ops->des_sample_get(tsp->ph, grp_id,
+					       &bulk.num_samples, samples);
+	if (ret)
+		return ret;
+
+	if (copy_to_user(u64_to_user_ptr(bulk.samples), samples,
+			 bulk.num_samples * sizeof(*samples)))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &bulk, sizeof(bulk)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long scmi_tlm_des_batch_read_ioctl(const struct scmi_tlm_instance *ti,
+					  unsigned long arg)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_setup *tsp = ti->tsp;
+	struct scmi_tlm_data_read batch;
+
+	if (copy_from_user(&batch, uptr, sizeof(batch)))
+		return -EFAULT;
+
+	if (batch.pad[0] || batch.pad[1] || batch.pad[2] || batch.pad2 ||
+	    batch.flags & ~SCMI_TLM_READ_FLAGS)
+		return -EINVAL;
+
+	struct scmi_telemetry_de_sample *samples __free(kfree) =
+		kcalloc(batch.num_samples, sizeof(*samples), GFP_KERNEL);
+	if (!samples)
+		return -ENOMEM;
+
+	/* Read all the requested samples */
+	if (copy_from_user(samples, u64_to_user_ptr(batch.samples),
+			   batch.num_samples * sizeof(*samples)))
+		return -EFAULT;
+
+	for (int i = 0; i < batch.num_samples; i++) {
+		int ret;
+
+		ret = tsp->ops->de_data_read(tsp->ph, &samples[i]);
+		if (ret)
+			return ret;
+	}
+
+	if (copy_to_user(u64_to_user_ptr(batch.samples), samples,
+			 batch.num_samples * sizeof(*samples)))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &batch, sizeof(batch)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static struct scmi_tlm_shmti_ctx *
+scmi_tlm_shmti_ctx_alloc(struct scmi_telemetry_shmti_info *shmti)
+{
+	struct scmi_tlm_shmti_ctx *ctx;
+
+	ctx = kzalloc_obj(*ctx);
+	if (!ctx)
+		return ERR_PTR(-ENOMEM);
+
+	ctx->shmti = shmti;
+	kref_init(&ctx->kref);
+
+	return ctx;
+}
+
+static void scmi_tlm_shmti_ctx_release(struct kref *kref)
+{
+	struct scmi_tlm_shmti_ctx *ctx = to_shmti_ctx(kref);
+
+	kfree(ctx);
+}
+
+static struct scmi_tlm_shmti_ctx *
+scmi_tlm_shmti_ctx_get(struct scmi_tlm_shmti_ctx *ctx)
+{
+	kref_get(&ctx->kref);
+
+	return ctx;
+}
+
+static void scmi_tlm_shmti_ctx_put(struct scmi_tlm_shmti_ctx *ctx)
+{
+	kref_put(&ctx->kref, scmi_tlm_shmti_ctx_release);
+}
+
+static void scmi_tlm_shmti_vma_open(struct vm_area_struct *vma)
+{
+	scmi_tlm_shmti_ctx_get(vma->vm_private_data);
+}
+
+static void scmi_tlm_shmti_vma_close(struct vm_area_struct *vma)
+{
+	scmi_tlm_shmti_ctx_put(vma->vm_private_data);
+}
+
+static const struct vm_operations_struct scmi_tlm_shmti_vm_ops = {
+	.open = scmi_tlm_shmti_vma_open,
+	.close = scmi_tlm_shmti_vma_close,
+};
+
+static int scmi_tlm_shmti_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	struct scmi_tlm_shmti_ctx *ctx = filp->private_data;
+	unsigned long npages, expect, needed, req = vma->vm_end - vma->vm_start;
+	phys_addr_t base;
+	size_t map_sz;
+	int ret;
+
+	if (vma->vm_flags & VM_WRITE)
+		return -EPERM;
+
+	if (req < ctx->shmti->len)
+		return -EINVAL;
+
+	/* Align & reject oversized requests */
+	base = ctx->shmti->phys & PAGE_MASK;
+	needed = ctx->shmti->len + ctx->shmti->offset;
+	expect = DIV_ROUND_UP(needed, PAGE_SIZE);
+	npages = req >> PAGE_SHIFT;
+	if (npages > expect)
+		return -EINVAL;
+
+	map_sz = PAGE_ALIGN(needed);
+	vma->vm_private_data = scmi_tlm_shmti_ctx_get(ctx);
+	vma->vm_ops = &scmi_tlm_shmti_vm_ops;
+	/* Set appropriate caching attributes */
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+	/* Map physical address range into user space */
+	ret = vm_iomap_memory(vma, base, map_sz);
+	if (ret) {
+		scmi_tlm_shmti_ctx_put(ctx);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int scmi_tlm_shmti_release(struct inode *ino, struct file *filp)
+{
+	scmi_tlm_shmti_ctx_put(filp->private_data);
+
+	return 0;
+}
+
+static const struct file_operations scmi_tlm_shmti_fops = {
+	.owner = THIS_MODULE,
+	.mmap = scmi_tlm_shmti_mmap,
+	.release = scmi_tlm_shmti_release,
+};
+
+static void
+scmi_tlm_allocate_anon_fds(const struct scmi_tlm_instance *ti,
+			   struct scmi_tlm_shmtis_list *out,
+			   struct scmi_tlm_shmti_info *shinfo)
+{
+	const struct scmi_telemetry_info *info = ti->info;
+	struct device *dev = ti->tsp->dev;
+	int idx = 0;
+
+	out->num_shmtis = 0;
+	for (int i = 0; i < info->base.num_shmtis; i++) {
+		struct scmi_telemetry_shmti_info *shmti = info->shmtis[i];
+		struct scmi_tlm_shmti_ctx *ctx;
+		int fd;
+
+		ctx = scmi_tlm_shmti_ctx_alloc(shmti);
+		if (IS_ERR(ctx)) {
+			dev_err(dev, "Failed CTX_ALLOC on SID: %u\n", shmti->sid);
+			continue;
+		}
+
+		fd = anon_inode_getfd(SCMI_TLM_DRIVER, &scmi_tlm_shmti_fops, ctx,
+				      O_RDONLY | O_CLOEXEC);
+		if (fd < 0) {
+			scmi_tlm_shmti_ctx_put(ctx);
+			dev_err(dev, "Failed ANON INODE on SID: %u\n", shmti->sid);
+			continue;
+		}
+
+		shinfo[idx].sid = shmti->sid;
+		shinfo[idx].fd = fd;
+		shinfo[idx].len = shmti->len;
+		shinfo[idx].offset = shmti->offset;
+
+		/* Count returned items */
+		out->num_shmtis++;
+		idx++;
+	}
+}
+
+static long
+scmi_tlm_shmtis_list_get_ioctl(const struct scmi_tlm_instance *ti,
+			       unsigned long arg)
+{
+	void __user *uptr = (void __user *)arg;
+	struct scmi_tlm_shmtis_list ssl;
+	size_t shinfo_sz;
+
+	if (copy_from_user(&ssl, uptr, sizeof(ssl)))
+		return -EFAULT;
+
+	if (ssl.pad)
+		return -EINVAL;
+
+	/* Reject only undersized buffers */
+	if (ssl.num_shmtis < ti->info->base.num_shmtis)
+		return -ENOSPC;
+
+	/* A local scratch buffer... */
+	shinfo_sz = ssl.num_shmtis * sizeof(struct scmi_tlm_shmti_info);
+	struct scmi_tlm_shmti_info *shinfo __free(kfree) =
+		kzalloc(shinfo_sz, GFP_KERNEL);
+	if (!shinfo)
+		return -ENOMEM;
+
+	if (copy_from_user(shinfo, u64_to_user_ptr(ssl.shmtis), shinfo_sz))
+		return -EFAULT;
+
+	scmi_tlm_allocate_anon_fds(ti, &ssl, shinfo);
+	if (copy_to_user(u64_to_user_ptr(ssl.shmtis), shinfo, shinfo_sz))
+		return -EFAULT;
+
+	if (copy_to_user(uptr, &ssl, sizeof(ssl)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long scmi_tlm_reset_ioctl(const struct scmi_tlm_instance *ti,
+				 unsigned long arg)
+{
+	return ti->tsp->ops->reset(ti->tsp->ph);
+}
+
+static long scmi_tlm_unlocked_ioctl(struct file *filp, unsigned int cmd,
+				    unsigned long arg)
+{
+	struct inode *ino = file_inode(filp);
+	struct scmi_tlm_instance *ti = to_instance(ino->i_cdev);
+
+	switch (cmd) {
+	case SCMI_TLM_GET_ABI_INFO:
+		return scmi_tlm_abi_info_get_ioctl(ti, arg);
+	case SCMI_TLM_GET_CFG:
+		return scmi_tlm_config_get_ioctl(ti, arg);
+	case SCMI_TLM_SET_CFG:
+		return scmi_tlm_config_set_ioctl(ti, arg);
+	case SCMI_TLM_GET_INTRVS:
+		return scmi_tlm_intervals_get_ioctl(ti, arg);
+	case SCMI_TLM_GET_DE_CFG:
+		return scmi_tlm_de_config_get_ioctl(ti, arg, false);
+	case SCMI_TLM_SET_DE_CFG:
+		return scmi_tlm_de_config_set_ioctl(ti, arg, false);
+	case SCMI_TLM_GET_DE_INFO:
+		return scmi_tlm_de_info_get_ioctl(ti, arg);
+	case SCMI_TLM_GET_DE_LIST:
+		return scmi_tlm_des_list_get_ioctl(ti, arg);
+	case SCMI_TLM_DE_READ:
+		return scmi_tlm_de_value_get_ioctl(ti, arg);
+	case SCMI_TLM_GET_ALL_CFG:
+		return scmi_tlm_de_config_get_ioctl(ti, arg, true);
+	case SCMI_TLM_SET_ALL_CFG:
+		return scmi_tlm_de_config_set_ioctl(ti, arg, true);
+	case SCMI_TLM_GET_GRP_LIST:
+		return scmi_tlm_grps_list_get_ioctl(ti, arg);
+	case SCMI_TLM_GET_GRP_INFO:
+		return scmi_tlm_grp_info_get_ioctl(ti, arg);
+	case SCMI_TLM_GET_GRP_DESC:
+		return scmi_tlm_grp_desc_get_ioctl(ti, arg);
+	case SCMI_TLM_SINGLE_READ:
+		return scmi_tlm_des_read_ioctl(ti, arg, true);
+	case SCMI_TLM_BULK_READ:
+		return scmi_tlm_des_read_ioctl(ti, arg, false);
+	case SCMI_TLM_BATCH_READ:
+		return scmi_tlm_des_batch_read_ioctl(ti, arg);
+	case SCMI_TLM_GET_SHMTI_LIST:
+		return scmi_tlm_shmtis_list_get_ioctl(ti, arg);
+	case SCMI_TLM_RESET:
+		return scmi_tlm_reset_ioctl(ti, arg);
+	default:
+		return -ENOTTY;
+	}
+}
+
+static const struct file_operations stlm_fops = {
+	.owner = THIS_MODULE,
+	.open = nonseekable_open,
+	.unlocked_ioctl = scmi_tlm_unlocked_ioctl,
+	.compat_ioctl = compat_ptr_ioctl,
+};
+
+static struct scmi_tlm_instance *scmi_tlm_init(struct scmi_tlm_setup *tsp,
+					       unsigned int instance_id)
+{
+	struct device *dev = tsp->dev;
+	struct scmi_tlm_instance *ti;
+
+	ti = devm_kzalloc(dev, sizeof(*ti), GFP_KERNEL);
+	if (!ti)
+		return ERR_PTR(-ENOMEM);
+
+	ti->info = tsp->ops->info_get(tsp->ph);
+	if (!ti->info)
+		return dev_err_ptr_probe(dev,
+					 -EINVAL, "invalid Telemetry info !\n");
+
+	ti->id = instance_id;
+	ti->tsp = tsp;
+
+	return ti;
+}
+
+static char *scmi_tlm_devnode(const struct device *dev, umode_t *mode)
+{
+	return kasprintf(GFP_KERNEL, "scmi/%s", dev_name(dev));
+}
+
+static struct class stlm_class = {
+	.name    = "stlm",
+	.devnode = scmi_tlm_devnode,
+};
+
+static int scmi_telemetry_probe(struct scmi_device *sdev)
+{
+	const struct scmi_handle *handle = sdev->handle;
+	struct device *tdev, *dev = &sdev->dev;
+	struct scmi_protocol_handle *ph;
+	struct scmi_tlm_instance *ti;
+	struct scmi_tlm_setup *tsp;
+	unsigned int instance;
+	const void *ops;
+	int ret;
+
+	if (!handle)
+		return -ENODEV;
+
+	ops = handle->devm_protocol_get(sdev, sdev->protocol_id, &ph);
+	if (IS_ERR(ops))
+		return dev_err_probe(dev, PTR_ERR(ops),
+				     "Cannot access protocol:0x%X\n",
+				     sdev->protocol_id);
+
+	tsp = devm_kzalloc(dev, sizeof(*tsp), GFP_KERNEL);
+	if (!tsp)
+		return -ENOMEM;
+
+	tsp->dev = dev;
+	tsp->ops = ops;
+	tsp->ph = ph;
+
+	instance = handle->id;
+	if (instance >= SCMI_TLM_NUM_DEVS)
+		return -ENOSPC;
+
+	ti = scmi_tlm_init(tsp, instance);
+	if (IS_ERR(ti))
+		return PTR_ERR(ti);
+
+	cdev_init(&ti->cdev, &stlm_fops);
+	ti->cdev.owner = THIS_MODULE;
+	ti->devt = MKDEV(MAJOR(stlm_devt), MINOR(stlm_devt) + instance);
+	ret = cdev_add(&ti->cdev, ti->devt, 1);
+	if (ret)
+		return ret;
+
+	tdev = device_create(&stlm_class, NULL, ti->devt, ti, "tlm_%d", ti->id);
+	if (IS_ERR(tdev)) {
+		cdev_del(&ti->cdev);
+		return  PTR_ERR(tdev);
+	}
+
+	dev_set_drvdata(&sdev->dev, ti);
+
+	return 0;
+}
+
+static void scmi_telemetry_remove(struct scmi_device *sdev)
+{
+	struct scmi_tlm_instance *ti;
+
+	ti = dev_get_drvdata(&sdev->dev);
+	if (!ti)
+		return;
+
+	device_destroy(&stlm_class, ti->devt);
+	cdev_del(&ti->cdev);
+}
+
+static const struct scmi_device_id scmi_id_table[] = {
+	{ SCMI_PROTOCOL_TELEMETRY, "telemetry" },
+	{ }
+};
+MODULE_DEVICE_TABLE(scmi, scmi_id_table);
+
+static struct scmi_driver scmi_telemetry_driver = {
+	.name = SCMI_TLM_DRIVER,
+	.probe = scmi_telemetry_probe,
+	.remove = scmi_telemetry_remove,
+	.id_table = scmi_id_table,
+};
+
+static int __init scmi_telemetry_init(void)
+{
+	int ret;
+
+	ret = alloc_chrdev_region(&stlm_devt, 0, SCMI_TLM_NUM_DEVS,
+				  SCMI_TLM_DRIVER);
+	if (ret)
+		return ret;
+
+	ret = class_register(&stlm_class);
+	if (ret)
+		return ret;
+
+	return scmi_register(&scmi_telemetry_driver);
+}
+module_init(scmi_telemetry_init);
+
+static void __exit scmi_telemetry_exit(void)
+{
+	scmi_unregister(&scmi_telemetry_driver);
+	unregister_chrdev_region(stlm_devt, SCMI_TLM_NUM_DEVS);
+	class_unregister(&stlm_class);
+}
+module_exit(scmi_telemetry_exit);
+
+MODULE_AUTHOR("Cristian Marussi <cristian.marussi@arm.com>");
+MODULE_DESCRIPTION("ARM SCMI Telemetry Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/firmware/arm_scmi/telemetry.c b/drivers/firmware/arm_scmi/telemetry.c
new file mode 100644
index 00000000000000..cfa3bfb1ad3d75
--- /dev/null
+++ b/drivers/firmware/arm_scmi/telemetry.c
@@ -0,0 +1,3470 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) Telemetry Protocol
+ *
+ * Copyright (C) 2026 ARM Ltd.
+ */
+
+#include <linux/atomic.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/compiler_types.h>
+#include <linux/completion.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/limits.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/refcount.h>
+#include <linux/slab.h>
+#include <linux/sprintf.h>
+#include <linux/string.h>
+#include <linux/xarray.h>
+#include <linux/wait.h>
+
+#include "protocols.h"
+#include "notify.h"
+
+#include <trace/events/scmi.h>
+
+/* Updated only after ALL the mandatory features for that version are merged */
+#define SCMI_PROTOCOL_SUPPORTED_VERSION		0x10000
+
+#define SCMI_TLM_GENERATION_ONE		(SCMI_TLM_GENERATION_INVALID + 1U)
+#define SCMI_TLM_TDCF_MAX_RETRIES	5
+
+enum scmi_telemetry_protocol_cmd {
+	TELEMETRY_LIST_SHMTI = 0x3,
+	TELEMETRY_DE_DESCRIPTION = 0x4,
+	TELEMETRY_LIST_UPDATE_INTERVALS = 0x5,
+	TELEMETRY_DE_CONFIGURE = 0x6,
+	TELEMETRY_DE_ENABLED_LIST = 0x7,
+	TELEMETRY_CONFIG_SET = 0x8,
+	TELEMETRY_READING_COMPLETE = TELEMETRY_CONFIG_SET,
+	TELEMETRY_CONFIG_GET = 0x9,
+	TELEMETRY_RESET = 0xA,
+};
+
+struct scmi_msg_resp_telemetry_protocol_attributes {
+	__le32 de_num;
+	__le32 groups_num;
+	__le32 de_implementation_rev_dword[SCMI_TLM_DE_IMPL_MAX_DWORDS];
+	__le32 attributes;
+#define SUPPORTS_SINGLE_READ(x)		(le32_get_bits((x), BIT(31)))
+#define SUPPORTS_CONTINUOS_UPDATE(x)	(le32_get_bits((x), BIT(30)))
+#define SUPPORTS_PER_GROUP_CONFIG(x)	(le32_get_bits((x), BIT(18)))
+#define SUPPORTS_RESET(x)		(le32_get_bits((x), BIT(17)))
+#define SUPPORTS_FC(x)			(le32_get_bits((x), BIT(16)))
+	__le32 default_blk_ts_rate;
+};
+
+struct scmi_telemetry_update_notify_payld {
+	__le32 agent_id;
+	__le32 status;
+	__le32 num_dwords;
+	__le32 array[] __counted_by(num_dwords);
+};
+
+struct scmi_shmti_desc {
+	__le32 id;
+	__le32 addr_low;
+	__le32 addr_high;
+	__le32 length;
+	__le32 flags;
+};
+
+struct scmi_msg_resp_telemetry_shmti_list {
+	__le32 num_shmti;
+	struct scmi_shmti_desc desc[] __counted_by(num_shmti);
+};
+
+struct de_desc_fc {
+	__le32 addr_low;
+	__le32 addr_high;
+	__le32 size;
+};
+
+struct scmi_de_desc {
+	__le32 id;
+	__le32 grp_id;
+	__le32 data_sz;
+	__le32 attr_1;
+#define	IS_NAME_SUPPORTED(d)	(le32_get_bits((d)->attr_1, BIT(31)))
+#define	IS_FC_SUPPORTED(d)	(le32_get_bits((d)->attr_1, BIT(30)))
+#define	GET_DE_TYPE(d)		(le32_get_bits((d)->attr_1, GENMASK(29, 22)))
+#define	IS_PERSISTENT(d)	(le32_get_bits((d)->attr_1, BIT(21)))
+#define GET_DE_UNIT_EXP(d)						\
+	({								\
+		__u32 __signed_exp =					\
+			le32_get_bits((d)->attr_1, GENMASK(20, 13));	\
+									\
+		sign_extend32(__signed_exp, 7);				\
+	})
+#define	GET_DE_UNIT(d)		(le32_get_bits((d)->attr_1, GENMASK(12, 5)))
+#define	TSTAMP_SUPPORT(d)	(le32_get_bits((d)->attr_1, GENMASK(1, 0)))
+	__le32 attr_2;
+#define	GET_DE_INSTA_ID(d)	(le32_get_bits((d)->attr_2, GENMASK(31, 24)))
+#define	GET_COMPO_INSTA_ID(d)	(le32_get_bits((d)->attr_2, GENMASK(23, 8)))
+#define	GET_COMPO_TYPE(d)	(le32_get_bits((d)->attr_2, GENMASK(7, 0)))
+	__le32 reserved;
+};
+
+#define SCMI_TDE_VAR_SZ(_t)						       \
+	({								       \
+		struct telemetry_de *__t = _t;				       \
+		size_t _sz = 0;						       \
+									       \
+		_sz += __t->ts_type == TSTAMP_LINE ? sizeof(__le32) : 0;       \
+		_sz += __t->de.fc_support ? sizeof(struct de_desc_fc) : 0;     \
+		_sz += __t->de.name_support ? SCMI_SHORT_NAME_MAX_SIZE : 0;    \
+									       \
+		_sz;							       \
+	})
+
+struct scmi_msg_resp_telemetry_de_description {
+	__le32 num_desc;
+	struct scmi_de_desc desc[] __counted_by(num_desc);
+};
+
+struct scmi_msg_telemetry_update_intervals {
+	__le32 index;
+	__le32 group_identifier;
+#define	ALL_DES_NO_GROUP	0x0
+#define SPECIFIC_GROUP_DES	0x1
+#define ALL_DES_ANY_GROUP	0x2
+	__le32 flags;
+};
+
+struct scmi_msg_resp_telemetry_update_intervals {
+	__le32 flags;
+#define INTERVALS_DISCRETE(x)	(le32_get_bits((x), BIT(12)) == 0)
+	__le32 intervals[];
+};
+
+struct scmi_msg_telemetry_de_enabled_list {
+	__le32 index;
+	__le32 flags;
+};
+
+struct scmi_enabled_de_desc {
+	__le32 id;
+	__le32 mode;
+};
+
+struct scmi_msg_resp_telemetry_de_enabled_list {
+	__le32 flags;
+	struct scmi_enabled_de_desc entry[];
+};
+
+struct scmi_msg_telemetry_de_configure {
+	__le32 id;
+	__le32 flags;
+#define DE_ENABLE_NO_TSTAMP	BIT(0)
+#define DE_ENABLE_WTH_TSTAMP	BIT(1)
+#define DE_DISABLE_ALL		BIT(2)
+#define GROUP_SELECTOR		BIT(3)
+#define EVENT_DE		0
+#define EVENT_GROUP		1
+#define DE_DISABLE_ONE		0x0
+};
+
+struct scmi_msg_resp_telemetry_de_configure {
+	__le32 shmti_id;
+#define IS_SHMTI_ID_VALID(x)	((x) != 0xFFFFFFFF)
+	__le32 shmti_de_offset;
+	__le32 blk_ts_offset;
+};
+
+struct scmi_msg_telemetry_config_set {
+	__le32 grp_id;
+	__le32 control;
+#define TELEMETRY_ENABLE		(BIT(0))
+
+#define TELEMETRY_MODE_SET(x)		(FIELD_PREP(GENMASK(4, 1), (x)))
+#define	TLM_ONDEMAND			(0)
+#define	TLM_NOTIFS			(1)
+#define	TLM_SINGLE			(2)
+#define TELEMETRY_MODE_ONDEMAND		TELEMETRY_MODE_SET(TLM_ONDEMAND)
+#define TELEMETRY_MODE_NOTIFS		TELEMETRY_MODE_SET(TLM_NOTIFS)
+#define TELEMETRY_MODE_SINGLE		TELEMETRY_MODE_SET(TLM_SINGLE)
+
+#define TLM_ORPHANS			(0)
+#define TLM_GROUP			(1)
+#define TLM_ALL				(2)
+#define TELEMETRY_SET_SELECTOR(x)	(FIELD_PREP(GENMASK(8, 5), (x)))
+#define	TELEMETRY_SET_SELECTOR_ORPHANS	TELEMETRY_SET_SELECTOR(TLM_ORPHANS)
+#define	TELEMETRY_SET_SELECTOR_GROUP	TELEMETRY_SET_SELECTOR(TLM_GROUP)
+#define	TELEMETRY_SET_SELECTOR_ALL	TELEMETRY_SET_SELECTOR(TLM_ALL)
+	__le32 sampling_rate;
+};
+
+struct scmi_msg_resp_telemetry_reading_complete {
+	__le32 num_dwords;
+	__le32 dwords[] __counted_by(num_dwords);
+};
+
+struct scmi_msg_telemetry_config_get {
+	__le32 grp_id;
+	__le32 flags;
+#define TELEMETRY_GET_SELECTOR(x)	(FIELD_PREP(GENMASK(3, 0), (x)))
+#define	TELEMETRY_GET_SELECTOR_ORPHANS	TELEMETRY_GET_SELECTOR(TLM_ORPHANS)
+#define	TELEMETRY_GET_SELECTOR_GROUP	TELEMETRY_GET_SELECTOR(TLM_GROUP)
+#define	TELEMETRY_GET_SELECTOR_ALL	TELEMETRY_GET_SELECTOR(TLM_ALL)
+};
+
+struct scmi_msg_resp_telemetry_config_get {
+	__le32 control;
+	__le32 sampling_rate;
+};
+
+/* TDCF */
+
+#define _I(__a)		(ioread32((void __iomem *)(__a)))
+
+#define TO_CPU_64(h, l)	((((u64)(h)) << 32) | (l))
+
+/*
+ * Define the behaviour of a SHMTI scan defining what information will
+ * be gathered and which Telemetry items can be updated.
+ */
+enum scan_mode {
+	SCAN_LOOKUP,	/* Update only value/tstamp */
+	SCAN_UPDATE,	/* Update also location offset */
+	SCAN_DISCOVERY  /* Update xa_des: allows for new DEs to be discovered */
+};
+
+struct fc_line {
+	__le32 data_low;
+	__le32 data_high;
+};
+
+struct fc_tsline {
+	__le32 data_low;
+	__le32 data_high;
+	__le32 ts_low;
+	__le32 ts_high;
+};
+
+struct line {
+	__le32 data_low;
+	__le32 data_high;
+};
+
+struct blk_tsline {
+	__le32 ts_low;
+	__le32 ts_high;
+};
+
+struct tsline {
+	__le32 data_low;
+	__le32 data_high;
+	__le32 ts_low;
+	__le32 ts_high;
+};
+
+struct uuid_line {
+	__be32 dwords[SCMI_TLM_DE_IMPL_MAX_DWORDS];
+};
+
+#define LINE_DATA_GET_RAW(f)					\
+({								\
+	typeof(f) _f = (f);					\
+								\
+	(TO_CPU_64(_f->data_high, _f->data_low));		\
+})
+
+#define LINE_DATA_GET(f)					\
+({								\
+	typeof(f) _f = (f);					\
+								\
+	(TO_CPU_64(_I(&_f->data_high), _I(&_f->data_low)));	\
+})
+
+#define LINE_TSTAMP_GET_RAW(f)					\
+({								\
+	typeof(f) _f = (f);					\
+								\
+	(TO_CPU_64(_f->ts_high, _f->ts_low));			\
+})
+
+#define LINE_TSTAMP_GET(f)					\
+({								\
+	typeof(f) _f = (f);					\
+								\
+	(TO_CPU_64(_I(&_f->ts_high), _I(&_f->ts_low)));		\
+})
+
+#define BLK_TS_STAMP(f)		LINE_TSTAMP_GET(f)
+#define BLK_TS_RATE(p)		PAYLD_ID(p)
+
+enum tdcf_line_types {
+	TDCF_DATA_LINE,
+	TDCF_BLK_TS_LINE,
+	TDCF_UUID_LINE,
+};
+
+struct payload {
+	__le32 meta;
+#define PAYLD_META(x)		(_I(&((x)->meta)))
+#define LINE_TYPE_RAW(m)	(FIELD_GET(GENMASK(7, 4), (m)))
+#define LINE_TYPE(x)		(LINE_TYPE_RAW(PAYLD_META(x)))
+#define IS_DATA_LINE(x)		(LINE_TYPE(x) == TDCF_DATA_LINE)
+#define IS_BLK_TS_LINE(x)	(LINE_TYPE(x) == TDCF_BLK_TS_LINE)
+#define IS_UUID_LINE(x)		(LINE_TYPE(x) == TDCF_UUID_LINE)
+#define USE_BLK_TS_RAW(m)	((m) & BIT(3))
+#define USE_BLK_TS(x)		(USE_BLK_TS_RAW(PAYLD_META(x)))
+#define HAS_LINE_EXT_RAW(m)	((m) & BIT(2))
+#define HAS_LINE_EXT(x)		(HAS_LINE_EXT_RAW(PAYLD_META(x)))
+#define LINE_TS_VALID_RAW(m)	((m) & BIT(1))
+#define LINE_TS_VALID(x)	(LINE_TS_VALID_RAW(PAYLD_META(x)))
+#define	DATA_INVALID_RAW(m)	((m) & BIT(0))
+#define	DATA_INVALID(x)		(DATA_INVALID_RAW(PAYLD_META(x)))
+#define	BLK_TS_INVALID(p)						\
+({									\
+	u32 _m = PAYLD_META(p);						\
+	bool invalid;							\
+									\
+	invalid  = LINE_TS_VALID_RAW(_m) || HAS_LINE_EXT_RAW(_m) ||	\
+			USE_BLK_TS_RAW(_m) || DATA_INVALID_RAW(_m);	\
+	invalid;							\
+})
+
+#define	UUID_INVALID(p)							\
+({									\
+	u32 _m = PAYLD_META(p);						\
+	bool invalid;							\
+									\
+	invalid = LINE_TS_VALID_RAW(_m) || USE_BLK_TS_RAW(_m) ||	\
+			DATA_INVALID_RAW(_m) || !HAS_LINE_EXT_RAW(_m);	\
+	invalid;							\
+})
+	__le32 id;
+	union {
+		struct line l;
+		struct tsline tsl;
+		struct blk_tsline blk_tsl;
+		struct uuid_line uuid_l;
+	};
+};
+
+#define PAYLD_ID(x)	(_I(&(((struct payload __iomem *)(x))->id)))
+
+#define LINE_DATA_PAYLD_WORDS						       \
+	((sizeof(u32) + sizeof(u32) + sizeof(struct line)) / sizeof(u32))
+#define EXT_LINE_DATA_PAYLD_WORDS					       \
+	((sizeof(u32) + sizeof(u32) + sizeof(struct tsline)) / sizeof(u32))
+
+#define LINE_LENGTH_WORDS_RAW(m)				\
+	(HAS_LINE_EXT_RAW((m)) ? EXT_LINE_DATA_PAYLD_WORDS : LINE_DATA_PAYLD_WORDS)
+
+#define LINE_LENGTH_WORDS(x)		LINE_LENGTH_WORDS_RAW(PAYLD_META(x))
+
+#define LINE_LENGTH_QWORDS(x)		((LINE_LENGTH_WORDS(x)) / 2)
+#define LINE_LENGTH_BYTES(x)		((LINE_LENGTH_WORDS(x)) * sizeof(u32))
+
+struct prlg {
+	u32 sign_start;
+#define SIGNATURE_START	0x5442474E	/* TBGN */
+	u32 match_start;
+	u32 num_qwords;
+	u32 hdr_meta_1;
+#define TDCF_REVISION_GET(x)	(le32_get_bits((x)->hdr_meta_1, GENMASK(7, 0)))
+};
+
+struct eplg {
+	u32 match_end;
+	u32 sign_end;
+#define SIGNATURE_END	0x54454E44	/* TEND */
+};
+
+#define TDCF_EPLG_SZ	(sizeof(struct eplg))
+
+struct tdcf {
+	struct prlg prlg;
+	unsigned char payld[];
+};
+
+#define QWORDS(_t)	(_I(&(_t)->prlg.num_qwords))
+
+#define SHMTI_MIN_SIZE	(sizeof(struct tdcf) + TDCF_EPLG_SZ)
+
+#define TDCF_START_SIGNATURE(x)	(_I(&((x)->prlg.sign_start)))
+#define TDCF_START_SEQ_GET(x)	(_I(&((x)->prlg.match_start)))
+#define IS_BAD_START_SEQ(s)	((s) & 0x1)
+
+#define TDCF_END_SEQ_GET(e)	(_I(&((e)->match_end)))
+#define TDCF_END_SIGNATURE(e)	(_I(&((e)->sign_end)))
+#define	TDCF_BAD_END_SEQ	GENMASK(31, 0)
+
+struct telemetry_shmti {
+	u32 flags;
+	void __iomem *base;
+	u32 last_magic;
+	struct scmi_telemetry_shmti_info info;
+};
+
+struct scmi_telemetry_dbg_shmti {
+	struct telemetry_shmti *shmti;
+	size_t buf_sz;
+	void *buf;
+	/* Protect this descriptor from concurrent readers using it */
+	struct mutex mtx;
+};
+
+#define SHMTI_EPLG(s)						\
+	({							\
+		struct telemetry_shmti *_s = (s);		\
+		struct eplg __iomem *_eplg;			\
+								\
+		_eplg = _s->base + _s->info.len - TDCF_EPLG_SZ;	\
+		(_eplg);					\
+	})
+
+#define SHMTI_OVERFLOWS(_n, _s)						\
+	({								\
+		struct telemetry_shmti *__s = (_s);			\
+		void *__n = (_n);					\
+		bool oflow;						\
+									\
+		__n += LINE_LENGTH_BYTES((struct payload __iomem *)__n);\
+		oflow = __n >= __s->base + __s->info.len;		\
+		oflow;							\
+	})
+
+struct telemetry_line {
+	refcount_t users;
+	u32 last_magic;
+	struct payload __iomem *payld;
+	struct xarray *xa_lines;
+	/* Protect line accesses  */
+	struct mutex mtx;
+};
+
+struct telemetry_block_ts {
+	u64 last_ts;
+	u32 last_rate;
+	struct telemetry_line line;
+};
+
+#define to_blkts(l)	container_of(l, struct telemetry_block_ts, line)
+
+struct telemetry_uuid {
+	u32 de_impl_version[SCMI_TLM_DE_IMPL_MAX_DWORDS];
+	struct telemetry_line line;
+};
+
+#define to_uuid(l)	container_of(l, struct telemetry_uuid, line)
+
+enum timestamps {
+	TSTAMP_NONE,
+	TSTAMP_LINE,
+	TSTAMP_BLK
+};
+
+struct telemetry_de {
+	enum timestamps ts_type;
+	u32 ts_rate;
+	bool enumerated;
+	bool cached_msg;
+	void __iomem *base;
+	struct eplg __iomem *eplg;
+	u32 offset;
+	/* NOTE THAT DE data_sz is registered in scmi_telemetry_de */
+	u32 fc_size;
+	/* Protect last_val/ts/magic accesses  */
+	struct mutex mtx;
+	u64 last_val;
+	u64 last_ts;
+	u32 last_magic;
+	struct list_head item;
+	struct telemetry_block_ts *bts;
+	struct telemetry_uuid *uuid;
+	struct scmi_telemetry_de de;
+};
+
+#define to_tde(d)	container_of(d, struct telemetry_de, de)
+
+static inline bool scmi_tde_has_tstamp(struct telemetry_de *t)
+{
+	return t->de.tstamp_support && t->de.tstamp_enabled;
+}
+
+#define DE_ENABLED_WITH_TSTAMP	2
+
+enum de_state {
+	ENA_STATE,
+	ENA_TSTAMP,
+	ENA_MAX
+};
+
+struct telemetry_info {
+	bool streaming_mode;
+	unsigned int num_shmti;
+	unsigned int num_des_tstamp;
+	atomic_t des_enabled[ENA_MAX];
+	unsigned int default_blk_ts_rate;
+	const struct scmi_protocol_handle *ph;
+	struct telemetry_shmti *shmti;
+	struct telemetry_de *tdes;
+	struct scmi_telemetry_group *grps;
+	struct xarray xa_des;
+	struct xarray xa_lines;
+	/* Mutex to protect access to @free_des */
+	struct mutex free_mtx;
+	struct list_head free_des;
+	struct list_head fcs_des;
+	struct scmi_telemetry_info info;
+	struct wait_queue_head gen_wq;
+	struct notifier_block telemetry_nb;
+	atomic_t rinfo_initializing;
+	struct completion rinfo_initdone;
+	struct scmi_telemetry_res_info *rinfo;
+	struct scmi_telemetry_res_info *(*res_get)(struct telemetry_info *ti);
+};
+
+#define telemetry_nb_to_info(x)	\
+	container_of(x, struct telemetry_info, telemetry_nb)
+
+static struct scmi_telemetry_res_info *
+__scmi_telemetry_resources_get(struct telemetry_info *ti);
+
+static int scmi_telemetry_shmti_scan(struct telemetry_info *ti,
+				     unsigned int shmti_id, enum scan_mode mode);
+
+static inline void
+scmi_telemetry_de_state_update(struct telemetry_info *ti, enum de_state state,
+			       bool *current_state, const bool next_state)
+{
+	if (!current_state || *current_state != next_state)
+		atomic_add(next_state ? 1 : -1, &ti->des_enabled[state]);
+
+	if (current_state)
+		*current_state = next_state;
+
+	dev_dbg(ti->ph->dev, "Telemetry des_enabled[%s]:%u\n",
+		state == ENA_STATE ? "STATE" : "TSTAMP",
+		atomic_read(&ti->des_enabled[state]));
+}
+
+static struct telemetry_de *
+scmi_telemetry_free_tde_get(struct telemetry_info *ti)
+{
+	struct telemetry_de *tde;
+
+	guard(mutex)(&ti->free_mtx);
+
+	tde = list_first_entry_or_null(&ti->free_des, struct telemetry_de, item);
+	if (!tde)
+		return tde;
+
+	list_del(&tde->item);
+
+	return tde;
+}
+
+static void scmi_telemetry_free_tde_put(struct telemetry_info *ti,
+					struct telemetry_de *tde)
+{
+	guard(mutex)(&ti->free_mtx);
+
+	list_add_tail(&tde->item, &ti->free_des);
+}
+
+static struct telemetry_de *scmi_telemetry_tde_lookup(struct telemetry_info *ti,
+						      unsigned int de_id)
+{
+	struct scmi_telemetry_de *de;
+
+	de = xa_load(&ti->xa_des, de_id);
+	if (!de)
+		return NULL;
+
+	return to_tde(de);
+}
+
+static struct telemetry_de *scmi_telemetry_tde_get(struct telemetry_info *ti,
+						   unsigned int de_id)
+{
+	struct telemetry_de *tde;
+
+	/* Pick a new tde */
+	tde = scmi_telemetry_free_tde_get(ti);
+	if (!tde) {
+		dev_err(ti->ph->dev, "Cannot allocate DE for ID:0x%08X\n", de_id);
+		return ERR_PTR(-ENOSPC);
+	}
+
+	return tde;
+}
+
+static int scmi_telemetry_tde_register(struct telemetry_info *ti,
+				       struct telemetry_de *tde)
+{
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+	int ret;
+
+	if (rinfo->num_des >= ti->info.base.num_des) {
+		ret = -ENOSPC;
+		goto err;
+	}
+
+	/* Store DE pointer by de_id ... */
+	ret = xa_insert(&ti->xa_des, tde->de.info->id, &tde->de, GFP_KERNEL);
+	if (ret)
+		goto err;
+
+	/* ... and in the general array */
+	rinfo->des[rinfo->num_des++] = &tde->de;
+
+	return 0;
+
+err:
+	dev_err(ti->ph->dev, "Cannot register DE for ID:0x%08X\n",
+		tde->de.info->id);
+
+	return ret;
+}
+
+static bool
+scmi_telemetry_tde_cache_unchanged(struct telemetry_de *tde, u32 magic)
+{
+	guard(mutex)(&tde->mtx);
+
+	return tde->last_magic == magic;
+}
+
+static void
+scmi_telemetry_tde_cache_update(struct telemetry_de *tde,
+				struct scmi_telemetry_de_sample *sample,
+				u32 *magic)
+{
+	guard(mutex)(&tde->mtx);
+
+	tde->last_magic = magic ? *magic : TDCF_BAD_END_SEQ;
+	tde->last_val = sample->val;
+	tde->last_ts = scmi_tde_has_tstamp(tde) ? sample->tstamp : 0;
+	/* Update returned value too */
+	sample->tstamp = tde->last_ts;
+}
+
+static int
+scmi_telemetry_tde_cache_lookup(struct telemetry_de *tde,
+				struct scmi_telemetry_de_sample *sample,
+				u32 *magic)
+{
+	guard(mutex)(&tde->mtx);
+
+	if (magic && tde->last_magic != *magic)
+		return -EAGAIN;
+
+	sample->id = tde->de.info->id;
+	sample->val = tde->last_val;
+	sample->tstamp = tde->last_ts;
+
+	return 0;
+}
+
+static inline void __scmi_telemetry_generation_set(struct telemetry_info *ti,
+						   unsigned int new)
+{
+	atomic_set_release(&ti->info.generation, new);
+
+	wake_up_all(&ti->gen_wq);
+}
+
+static inline void scmi_telemetry_generation_update(struct telemetry_info *ti)
+{
+	unsigned int next;
+
+	/* Wrap around skipping invalid generation 0 */
+	next = (atomic_read(&ti->info.generation) + 1) ?: SCMI_TLM_GENERATION_ONE;
+
+	__scmi_telemetry_generation_set(ti, next);
+}
+
+static inline void scmi_telemetry_generation_reset(struct telemetry_info *ti)
+{
+	__scmi_telemetry_generation_set(ti, SCMI_TLM_GENERATION_ONE);
+}
+
+struct scmi_tlm_de_priv {
+	struct telemetry_info *ti;
+	void *next;
+};
+
+static int
+scmi_telemetry_protocol_attributes_get(struct telemetry_info *ti)
+{
+	struct scmi_msg_resp_telemetry_protocol_attributes *resp;
+	const struct scmi_protocol_handle *ph = ti->ph;
+	struct scmi_xfer *t;
+	int ret;
+
+	ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0,
+				      sizeof(*resp), &t);
+	if (ret)
+		return ret;
+
+	resp = t->rx.buf;
+	ret = ph->xops->do_xfer(ph, t);
+	if (!ret) {
+		__le32 attr = resp->attributes;
+
+		ti->info.base.num_des = le32_to_cpu(resp->de_num);
+		ti->info.base.num_groups = le32_to_cpu(resp->groups_num);
+		for (int i = 0; i < SCMI_TLM_DE_IMPL_MAX_DWORDS; i++)
+			ti->info.base.de_impl_version[i] =
+				le32_to_cpu(resp->de_implementation_rev_dword[i]);
+		ti->info.single_read_support = SUPPORTS_SINGLE_READ(attr);
+		ti->info.continuos_update_support = SUPPORTS_CONTINUOS_UPDATE(attr);
+		ti->info.per_group_config_support = SUPPORTS_PER_GROUP_CONFIG(attr);
+		ti->info.reset_support = SUPPORTS_RESET(attr);
+		ti->info.fc_support = SUPPORTS_FC(attr);
+		ti->num_shmti = le32_get_bits(attr, GENMASK(15, 0));
+		ti->default_blk_ts_rate = le32_to_cpu(resp->default_blk_ts_rate);
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	return ret;
+}
+
+static void iter_tlm_prepare_message(void *message,
+				     unsigned int desc_index, const void *priv)
+{
+	put_unaligned_le32(desc_index, message);
+}
+
+static int iter_de_descr_update_state(struct scmi_iterator_state *st,
+				      const void *response, void *priv)
+{
+	const struct scmi_msg_resp_telemetry_de_description *r = response;
+	struct scmi_tlm_de_priv *p = priv;
+
+	st->num_returned = le32_get_bits(r->num_desc, GENMASK(15, 0));
+	st->num_remaining = le32_get_bits(r->num_desc, GENMASK(31, 16));
+
+	if (st->rx_len < (sizeof(*r) + sizeof(r->desc[0]) * st->num_returned))
+		return -EINVAL;
+
+	/* Initialized to first descriptor */
+	p->next = (void *)r->desc;
+
+	return 0;
+}
+
+static int scmi_telemetry_de_descriptor_parse(struct telemetry_info *ti,
+					      struct telemetry_de *tde,
+					      void **next, size_t rx_len)
+{
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+	const struct scmi_de_desc *desc = *next;
+	unsigned int grp_id;
+	size_t payld_sz = sizeof(*desc);
+
+	if (rx_len < payld_sz)
+		return -ENOSPC;
+
+	tde->de.info->id = le32_to_cpu(desc->id);
+	grp_id = le32_to_cpu(desc->grp_id);
+	if (grp_id != SCMI_TLM_GRP_INVALID) {
+		/* Group descriptors are empty but allocated at this point */
+		if (grp_id >= ti->info.base.num_groups)
+			return -EINVAL;
+
+		/* Link to parent group */
+		tde->de.grp = &rinfo->grps[grp_id];
+	}
+
+	tde->de.info->grp_id = grp_id;
+	tde->de.info->data_sz = le32_to_cpu(desc->data_sz);
+	tde->de.info->type = GET_DE_TYPE(desc);
+	tde->de.info->unit = GET_DE_UNIT(desc);
+	tde->de.info->unit_exp = GET_DE_UNIT_EXP(desc);
+	tde->de.info->instance_id = GET_DE_INSTA_ID(desc);
+	tde->de.info->compo_instance_id = GET_COMPO_INSTA_ID(desc);
+	tde->de.info->compo_type = GET_COMPO_TYPE(desc);
+	tde->de.info->persistent = IS_PERSISTENT(desc);
+	tde->ts_type = TSTAMP_SUPPORT(desc);
+	tde->de.tstamp_support = !!tde->ts_type;
+	/* Count timestamped DEs */
+	ti->num_des_tstamp += !!tde->de.tstamp_support;
+	tde->de.fc_support = IS_FC_SUPPORTED(desc);
+	tde->de.name_support = IS_NAME_SUPPORTED(desc);
+	/* Update DE_DESCRIPTOR size for the next iteration */
+	*next += sizeof(*desc);
+
+	payld_sz += SCMI_TDE_VAR_SZ(tde);
+	if (rx_len < payld_sz)
+		return -ENOSPC;
+
+	if (tde->ts_type == TSTAMP_LINE) {
+		__le32 *line_ts_rate = *next;
+
+		tde->de.info->ts_rate = le32_to_cpu((*line_ts_rate));
+
+		/* Variably sized depending on TS support */
+		*next += sizeof(*line_ts_rate);
+	} else if (tde->ts_type == TSTAMP_BLK) {
+		/* Setup default BLK TS value at first */
+		tde->de.info->ts_rate = ti->default_blk_ts_rate;
+	}
+
+	if (tde->de.fc_support) {
+		u32 size;
+		u64 phys_addr;
+		void __iomem *addr;
+		struct de_desc_fc *dfc;
+
+		dfc = *next;
+		phys_addr = le32_to_cpu(dfc->addr_low);
+		phys_addr |= (u64)le32_to_cpu(dfc->addr_high) << 32;
+
+		size = le32_to_cpu(dfc->size);
+		addr = devm_ioremap(ti->ph->dev, phys_addr, size);
+		if (!addr)
+			return -EADDRNOTAVAIL;
+
+		tde->base = addr;
+		tde->offset = 0;
+		tde->fc_size = size;
+
+		/* Variably sized depending on FC support */
+		*next += sizeof(*dfc);
+	}
+
+	if (tde->de.name_support) {
+		const char *de_name = *next;
+
+		strscpy(tde->de.info->name, de_name, SCMI_SHORT_NAME_MAX_SIZE);
+		/* Variably sized depending on name support */
+		*next += SCMI_SHORT_NAME_MAX_SIZE;
+	}
+
+	return 0;
+}
+
+static int iter_de_descr_process_response(const struct scmi_protocol_handle *ph,
+					  const void *response,
+					  struct scmi_iterator_state *st,
+					  void *priv)
+{
+	struct scmi_tlm_de_priv *p = priv;
+	struct telemetry_info *ti = p->ti;
+	const struct scmi_de_desc *desc = p->next;
+	struct telemetry_de *tde;
+	bool discovered = false;
+	unsigned int de_id;
+	int ret;
+
+	de_id = le32_to_cpu(desc->id);
+	/* Check if this DE has already been discovered by other means... */
+	tde = scmi_telemetry_tde_lookup(ti, de_id);
+	if (!tde) {
+		/* Create a new one */
+		tde = scmi_telemetry_tde_get(ti, de_id);
+		if (IS_ERR(tde))
+			return PTR_ERR(tde);
+
+		discovered = true;
+	} else if (tde->enumerated) {
+		/* Cannot be a duplicate of a DE already created by enumeration */
+		dev_err(ph->dev,
+			"Discovered INVALID DE with DUPLICATED ID:0x%08X\n",
+			de_id);
+		return -EINVAL;
+	}
+
+	ret = scmi_telemetry_de_descriptor_parse(ti, tde, &p->next, st->rx_len);
+	if (ret) {
+		dev_err(ph->dev, "Malformed DE Descriptor - ret:%d\n", ret);
+		goto err;
+	}
+
+	/* Now fully enumerated */
+	tde->enumerated = true;
+
+	if (discovered) {
+		/* Register if it was not already ... */
+		ret = scmi_telemetry_tde_register(ti, tde);
+		if (ret)
+			goto err;
+	}
+
+	/* Add to FastChannels list */
+	if (tde->de.fc_support)
+		list_add(&tde->item, &ti->fcs_des);
+
+	/* Account for this DE in group num_de counter */
+	if (tde->de.grp)
+		tde->de.grp->info->num_des++;
+
+	return 0;
+
+err:
+	/* DE not enumerated at this point were created in this call */
+	if (discovered)
+		scmi_telemetry_free_tde_put(ti, tde);
+
+	return ret;
+}
+
+static int scmi_telemetry_config_lookup(struct telemetry_info *ti,
+					unsigned int grp_id, bool *enabled,
+					unsigned int *active_update_interval)
+{
+	const struct scmi_protocol_handle *ph = ti->ph;
+	struct scmi_msg_telemetry_config_get *msg;
+	struct scmi_msg_resp_telemetry_config_get *resp;
+	struct scmi_xfer *t;
+	u32 flags;
+	int ret;
+
+	ret = ph->xops->xfer_get_init(ph, TELEMETRY_CONFIG_GET,
+				      sizeof(*msg), sizeof(*resp), &t);
+	if (ret)
+		return ret;
+
+	msg = t->tx.buf;
+	msg->grp_id = cpu_to_le32(grp_id);
+	flags = grp_id == SCMI_TLM_GRP_INVALID ?
+		TELEMETRY_GET_SELECTOR_ORPHANS : TELEMETRY_GET_SELECTOR_GROUP;
+	msg->flags = cpu_to_le32(flags);
+
+	resp = t->rx.buf;
+	ret = ph->xops->do_xfer(ph, t);
+	if (!ret) {
+		*enabled = le32_get_bits(resp->control, TELEMETRY_ENABLE);
+		*active_update_interval =
+			SCMI_TLM_GET_UPDATE_INTERVAL(le32_to_cpu(resp->sampling_rate));
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	return ret;
+}
+
+static int scmi_telemetry_group_config_lookup(struct telemetry_info *ti,
+					      struct scmi_telemetry_group *grp)
+{
+	return scmi_telemetry_config_lookup(ti, grp->info->grp_id, &grp->enabled,
+					    &grp->active_update_interval);
+}
+
+static void iter_enabled_list_prepare_message(void *message,
+					      unsigned int desc_index,
+					      const void *priv)
+{
+	struct scmi_msg_telemetry_de_enabled_list *msg = message;
+
+	msg->index = cpu_to_le32(desc_index);
+	msg->flags = 0;
+}
+
+static int iter_enabled_list_update_state(struct scmi_iterator_state *st,
+					  const void *response, void *priv)
+{
+	const struct scmi_msg_resp_telemetry_de_enabled_list *r = response;
+
+	st->num_returned = le32_get_bits(r->flags, GENMASK(15, 0));
+	st->num_remaining = le32_get_bits(r->flags, GENMASK(31, 16));
+
+	if (st->rx_len < (sizeof(*r) + sizeof(r->entry[0]) * st->num_returned))
+		return -EINVAL;
+
+	/*
+	 * total enabled is not declared previously anywhere so we
+	 * assume it's returned+remaining on first call.
+	 */
+	if (!st->max_resources)
+		st->max_resources = st->num_returned + st->num_remaining;
+
+	return 0;
+}
+
+static int
+iter_enabled_list_process_response(const struct scmi_protocol_handle *ph,
+				   const void *response,
+				   struct scmi_iterator_state *st, void *priv)
+{
+	const struct scmi_msg_resp_telemetry_de_enabled_list *r = response;
+	const struct scmi_enabled_de_desc *desc;
+	struct telemetry_info *ti = priv;
+	struct telemetry_de *tde;
+	u32 de_id;
+	int ret;
+
+	desc = &r->entry[st->loop_idx];
+	de_id = le32_to_cpu(desc->id);
+	if (scmi_telemetry_tde_lookup(ti, de_id)) {
+		dev_err(ph->dev,
+			"Found INVALID DE with DUPLICATED ID:0x%08X\n", de_id);
+		return -EINVAL;
+	}
+
+	tde = scmi_telemetry_tde_get(ti, de_id);
+	if (IS_ERR(tde))
+		return PTR_ERR(tde);
+
+	tde->de.info->id = de_id;
+	tde->de.enabled = true;
+	tde->de.tstamp_enabled = le32_to_cpu(desc->mode) == DE_ENABLED_WITH_TSTAMP;
+
+	ret = scmi_telemetry_tde_register(ti, tde);
+	if (ret) {
+		scmi_telemetry_free_tde_put(ti, tde);
+		return ret;
+	}
+
+	scmi_telemetry_de_state_update(ti, ENA_STATE, NULL, true);
+	if (tde->de.tstamp_enabled)
+		scmi_telemetry_de_state_update(ti, ENA_TSTAMP, NULL, true);
+
+	dev_dbg(ph->dev, "Registered new ENABLED DE with ID:0x%08X\n",
+		tde->de.info->id);
+
+	return 0;
+}
+
+static int scmi_telemetry_enumerate_des_enabled_list(struct telemetry_info *ti)
+{
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+	const struct scmi_protocol_handle *ph = ti->ph;
+	struct scmi_iterator_ops ops = {
+		.prepare_message = iter_enabled_list_prepare_message,
+		.update_state = iter_enabled_list_update_state,
+		.process_response = iter_enabled_list_process_response,
+	};
+	void *iter;
+	int ret;
+
+	iter = ph->hops->iter_response_init(ph, &ops, 0,
+					    TELEMETRY_DE_ENABLED_LIST,
+					    sizeof(u32) * 2, ti);
+	if (IS_ERR(iter))
+		return PTR_ERR(iter);
+
+	ret = ph->hops->iter_response_run(iter);
+	if (ret)
+		return ret;
+
+	dev_info(ti->ph->dev, "Found %u enabled DEs.\n", rinfo->num_des);
+
+	return 0;
+}
+
+static int scmi_telemetry_initial_state_lookup(struct telemetry_info *ti)
+{
+	struct device *dev = ti->ph->dev;
+	int ret;
+
+	ret = scmi_telemetry_config_lookup(ti, SCMI_TLM_GRP_INVALID,
+					   &ti->info.enabled,
+					   &ti->info.active_update_interval);
+	if (ret)
+		return ret;
+
+	if (!ti->info.enabled)
+		return 0;
+
+	/*
+	 * When Telemetry is found already enabled on the platform, proceed with
+	 * passive discovery using DE_ENABLED_LIST and TDCF scanning: note that
+	 * this CAN only discover DEs exposed via SHMTIs.
+	 * FastChannel DEs need a proper DE_DESCRIPTION enumeration, while, even
+	 * though incoming Notifications could be used for passive discovery too,
+	 * it would carry a considerable risk of assimilating trash as DEs.
+	 */
+	dev_info(dev,
+		 "Telemetry found enabled with update interval %lux10^%d\n",
+		 SCMI_TLM_GET_UPDATE_INTERVAL_SECS(ti->info.active_update_interval),
+		 SCMI_TLM_GET_UPDATE_INTERVAL_EXP(ti->info.active_update_interval));
+	/*
+	 * Query enabled DEs list: collect states. It will include DEs from any
+	 * interface. Enabled groups still NOT enumerated.
+	 */
+	ret = scmi_telemetry_enumerate_des_enabled_list(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot query enabled DE list. Abort.\n");
+		return ret;
+	}
+
+	/* Discover DEs on SHMTis: collect states/offsets/values */
+	for (int id = 0; id < ti->num_shmti; id++) {
+		ret = scmi_telemetry_shmti_scan(ti, id, SCAN_DISCOVERY);
+		if (ret)
+			dev_warn(dev,
+				 "Failed discovery-scan of SHMTI ID:%d - ret:%d\n",
+				 id, ret);
+	}
+
+	return 0;
+}
+
+static int
+scmi_telemetry_de_groups_init(struct device *dev, struct telemetry_info *ti)
+{
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+
+	/* Allocate all groups DEs IDs arrays at first ... */
+	for (int i = 0; i < ti->info.base.num_groups; i++) {
+		struct scmi_telemetry_group *grp = &rinfo->grps[i];
+		size_t des_str_sz;
+
+		unsigned int *des __free(kfree) = kcalloc(grp->info->num_des,
+							  sizeof(unsigned int),
+							  GFP_KERNEL);
+		if (!des)
+			return -ENOMEM;
+
+		/*
+		 * Max size 32bit ID string in Hex: 0xCAFECAFE
+		 *  - 10 digits + ' '/'\n' = 11 bytes per  number
+		 *  - terminating NUL character
+		 */
+		des_str_sz = grp->info->num_des * 11 + 1;
+		char *des_str __free(kfree) = kzalloc(des_str_sz, GFP_KERNEL);
+		if (!des_str)
+			return -ENOMEM;
+
+		grp->des = no_free_ptr(des);
+		grp->des_str = no_free_ptr(des_str);
+		/* Reset group DE counter */
+		grp->info->num_des = 0;
+	}
+
+	/* Scan DEs and populate DE IDs arrays for all groups */
+	for (int i = 0; i < rinfo->num_des; i++) {
+		struct scmi_telemetry_group *grp = rinfo->des[i]->grp;
+
+		if (!grp)
+			continue;
+
+		/*
+		 * Note that, at this point, num_des is guaranteed to be
+		 * sane (in-bounds) by construction.
+		 */
+		grp->des[grp->info->num_des++] = i;
+	}
+
+	/* Build composing DES string */
+	for (int i = 0; i < ti->info.base.num_groups; i++) {
+		struct scmi_telemetry_group *grp = &rinfo->grps[i];
+		size_t bufsize = grp->info->num_des * 11 + 1;
+		char *buf = grp->des_str;
+
+		for (int j = 0; j < grp->info->num_des; j++) {
+			char term = j != (grp->info->num_des - 1) ? ' ' : '\0';
+			int len;
+
+			len = scnprintf(buf, bufsize, "0x%08X%c",
+					rinfo->des[grp->des[j]]->info->id, term);
+
+			buf += len;
+			bufsize -= len;
+		}
+	}
+
+	for (int i = 0; i < ti->info.base.num_groups; i++)
+		scmi_telemetry_group_config_lookup(ti, &rinfo->grps[i]);
+
+	rinfo->num_groups = ti->info.base.num_groups;
+
+	return 0;
+}
+
+static int scmi_telemetry_de_descriptors_get(struct telemetry_info *ti)
+{
+	const struct scmi_protocol_handle *ph = ti->ph;
+
+	struct scmi_iterator_ops ops = {
+		.prepare_message = iter_tlm_prepare_message,
+		.update_state = iter_de_descr_update_state,
+		.process_response = iter_de_descr_process_response,
+	};
+	struct scmi_tlm_de_priv tpriv = {
+		.ti = ti,
+		.next = NULL,
+	};
+	void *iter;
+	int ret;
+
+	if (!ti->info.base.num_des)
+		return 0;
+
+	iter = ph->hops->iter_response_init(ph, &ops, ti->info.base.num_des,
+					    TELEMETRY_DE_DESCRIPTION,
+					    sizeof(u32), &tpriv);
+	if (IS_ERR(iter))
+		return PTR_ERR(iter);
+
+	ret = ph->hops->iter_response_run(iter);
+	if (ret)
+		return ret;
+
+	return scmi_telemetry_de_groups_init(ph->dev, ti);
+}
+
+struct scmi_tlm_ivl_priv {
+	struct device *dev;
+	struct scmi_telemetry_intervals **intrvs;
+	unsigned int grp_id;
+	unsigned int flags;
+};
+
+static void iter_intervals_prepare_message(void *message,
+					   unsigned int desc_index,
+					   const void *priv)
+{
+	struct scmi_msg_telemetry_update_intervals *msg = message;
+	const struct scmi_tlm_ivl_priv *p = priv;
+
+	msg->index = cpu_to_le32(desc_index);
+	msg->group_identifier = cpu_to_le32(p->grp_id);
+	msg->flags = cpu_to_le32(FIELD_PREP(GENMASK(3, 0), p->flags));
+}
+
+static int iter_intervals_update_state(struct scmi_iterator_state *st,
+				       const void *response, void *priv)
+{
+	const struct scmi_msg_resp_telemetry_update_intervals *r = response;
+
+	st->num_returned = le32_get_bits(r->flags, GENMASK(11, 0));
+	st->num_remaining = le32_get_bits(r->flags, GENMASK(31, 16));
+
+	if (st->rx_len < (sizeof(*r) + sizeof(r->intervals[0]) * st->num_returned))
+		return -EINVAL;
+
+	/*
+	 * total intervals is not declared previously anywhere so we
+	 * assume it's returned+remaining on first call.
+	 */
+	if (!st->max_resources) {
+		struct scmi_tlm_ivl_priv *p = priv;
+		struct scmi_telemetry_intervals *intrvs;
+		bool discrete;
+		int inum;
+
+		discrete = INTERVALS_DISCRETE(r->flags);
+		/* Check consistency on first call */
+		if (!discrete && (st->num_returned != 3 || st->num_remaining != 0))
+			return -EINVAL;
+
+		inum = st->num_returned + st->num_remaining;
+		intrvs = kzalloc(sizeof(*intrvs) + inum * sizeof(__u32), GFP_KERNEL);
+		if (!intrvs)
+			return -ENOMEM;
+
+		intrvs->num_intervals = inum;
+		intrvs->discrete = discrete;
+		st->max_resources = intrvs->num_intervals;
+
+		*p->intrvs = intrvs;
+	}
+
+	return 0;
+}
+
+static int
+iter_intervals_process_response(const struct scmi_protocol_handle *ph,
+				const void *response,
+				struct scmi_iterator_state *st, void *priv)
+{
+	const struct scmi_msg_resp_telemetry_update_intervals *r = response;
+	struct scmi_tlm_ivl_priv *p = priv;
+	struct scmi_telemetry_intervals *intrvs = *p->intrvs;
+	unsigned int idx = st->loop_idx;
+
+	intrvs->update_intervals[st->desc_index + idx] =
+		le32_to_cpu(r->intervals[idx]);
+
+	return 0;
+}
+
+static int
+scmi_tlm_enumerate_update_intervals(struct telemetry_info *ti,
+				    struct scmi_telemetry_intervals **intervals,
+				    int grp_id, unsigned int flags)
+{
+	struct scmi_iterator_ops ops = {
+		.prepare_message = iter_intervals_prepare_message,
+		.update_state = iter_intervals_update_state,
+		.process_response = iter_intervals_process_response,
+	};
+	const struct scmi_protocol_handle *ph = ti->ph;
+	struct scmi_telemetry_intervals *intrvs = NULL;
+	struct scmi_tlm_ivl_priv ipriv = {
+		.dev = ph->dev,
+		.grp_id = grp_id,
+		.intrvs = &intrvs,
+		.flags = flags,
+	};
+	void *iter;
+	int ret;
+
+	iter = ph->hops->iter_response_init(ph, &ops, 0,
+		TELEMETRY_LIST_UPDATE_INTERVALS,
+		sizeof(struct scmi_msg_telemetry_update_intervals),
+		&ipriv);
+	if (IS_ERR(iter))
+		return PTR_ERR(iter);
+
+	/* Cleanup iterator inner allocations on failure */
+	ret = ph->hops->iter_response_run(iter);
+	if (ret) {
+		kfree(intrvs);
+		return ret;
+	}
+
+	*intervals = intrvs;
+
+	return 0;
+}
+
+static int
+scmi_telemetry_enumerate_groups_intervals(struct telemetry_info *ti)
+{
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+
+	if (!ti->info.per_group_config_support)
+		return 0;
+
+	for (int id = 0; id < rinfo->num_groups; id++) {
+		int ret;
+
+		ret = scmi_tlm_enumerate_update_intervals(ti,
+							  &rinfo->grps[id].intervals,
+							  id, SPECIFIC_GROUP_DES);
+		if (ret)
+			return ret;
+
+		rinfo->grps_store[id].num_intervals =
+			rinfo->grps[id].intervals->num_intervals;
+	}
+
+	return 0;
+}
+
+static void scmi_telemetry_intervals_free(void *interval)
+{
+	kfree(interval);
+}
+
+static int
+scmi_telemetry_enumerate_common_intervals(struct telemetry_info *ti)
+{
+	unsigned int flags;
+	int ret;
+
+	flags = !ti->info.per_group_config_support ?
+		ALL_DES_ANY_GROUP : ALL_DES_NO_GROUP;
+
+	ret = scmi_tlm_enumerate_update_intervals(ti, &ti->info.intervals,
+						  SCMI_TLM_GRP_INVALID, flags);
+	if (ret)
+		return ret;
+
+	/* A copy for UAPI access... */
+	ti->info.base.num_intervals = ti->info.intervals->num_intervals;
+
+	/* Delegate freeing of allocated intervals to unbind time */
+	return devm_add_action_or_reset(ti->ph->dev,
+					scmi_telemetry_intervals_free,
+					ti->info.intervals);
+}
+
+static int scmi_telemetry_dbg_shmti_open(struct inode *inode, struct file *filp)
+{
+	struct scmi_telemetry_dbg_shmti *sblob;
+	struct telemetry_shmti *shmti;
+
+	if (!inode->i_private)
+		return -ENODEV;
+
+	shmti = inode->i_private;
+	sblob = kzalloc_obj(*sblob);
+	if (!sblob)
+		return -ENOMEM;
+
+	sblob->shmti = shmti;
+	sblob->buf = kzalloc(shmti->info.len, GFP_KERNEL);
+	if (!sblob->buf) {
+		kfree(sblob);
+		return -ENOMEM;
+	}
+
+	mutex_init(&sblob->mtx);
+
+	filp->private_data = sblob;
+
+	return 0;
+}
+
+static ssize_t scmi_telemetry_dbg_shmti_read(struct file *filp, char __user *buf,
+					     size_t count, loff_t *ppos)
+{
+	struct scmi_telemetry_dbg_shmti *sblob = filp->private_data;
+
+	/* Dump on first read and again after each rewind to start pos */
+	guard(mutex)(&sblob->mtx);
+	if (!sblob->buf_sz || *ppos == 0) {
+		memcpy_fromio(sblob->buf, sblob->shmti->base,
+			      sblob->shmti->info.len);
+		sblob->buf_sz = sblob->shmti->info.len;
+		/* update inode timestamps */
+		simple_inode_init_ts(file_inode(filp));
+	}
+
+	return simple_read_from_buffer(buf, count, ppos, sblob->buf, sblob->buf_sz);
+}
+
+static int scmi_telemetry_dbg_shmti_release(struct inode *inode, struct file *filp)
+{
+	struct scmi_telemetry_dbg_shmti *sblob = filp->private_data;
+
+	kfree(sblob->buf);
+	kfree(sblob);
+
+	return 0;
+}
+
+static const struct file_operations scmi_telemetry_dbg_shmti_fops = {
+	.open = scmi_telemetry_dbg_shmti_open,
+	.release = scmi_telemetry_dbg_shmti_release,
+	.read = scmi_telemetry_dbg_shmti_read,
+	.llseek = generic_file_llseek,
+	.owner = THIS_MODULE,
+};
+
+static void scmi_telemetry_debugfs_initialize(struct telemetry_info *ti)
+{
+	const struct scmi_protocol_handle *ph = ti->ph;
+	struct dentry *top, *shmti_top;
+
+	top = ph->hops->debugfs_proto_dentry_get(ph);
+	shmti_top = debugfs_create_dir("shmtis", top);
+
+	for (unsigned int i = 0; i < ti->num_shmti; i++) {
+		char id[16];
+
+		snprintf(id, 16, "%u", i);
+		debugfs_create_file_size(id, 0444, shmti_top, &ti->shmti[i],
+					 &scmi_telemetry_dbg_shmti_fops,
+					 ti->shmti[i].info.len);
+	}
+}
+
+static int iter_shmti_update_state(struct scmi_iterator_state *st,
+				   const void *response, void *priv)
+{
+	const struct scmi_msg_resp_telemetry_shmti_list *r = response;
+
+	st->num_returned = le32_get_bits(r->num_shmti, GENMASK(15, 0));
+	st->num_remaining = le32_get_bits(r->num_shmti, GENMASK(31, 16));
+
+	if (st->rx_len < (sizeof(*r) + sizeof(r->desc[0]) * st->num_returned))
+		return -EINVAL;
+
+	return 0;
+}
+
+static inline int
+scmi_telemetry_shmti_validate(struct device *dev, struct telemetry_shmti *shmti)
+{
+	struct tdcf __iomem *tdcf = shmti->base;
+	u32 sign_start, sign_end;
+
+	sign_start = TDCF_START_SIGNATURE(tdcf);
+	sign_end = TDCF_END_SIGNATURE(SHMTI_EPLG(shmti));
+
+	if (sign_start != SIGNATURE_START || sign_end != SIGNATURE_END) {
+		dev_err(dev,
+			"BAD signature for SHMTI ID:%u @phys:%pK - START:0x%04X END:0x%04X\n",
+			shmti->info.sid, shmti->base, sign_start, sign_end);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int iter_shmti_process_response(const struct scmi_protocol_handle *ph,
+				       const void *response,
+				       struct scmi_iterator_state *st,
+				       void *priv)
+{
+	const struct scmi_msg_resp_telemetry_shmti_list *r = response;
+	struct telemetry_info *ti = priv;
+	struct telemetry_shmti *shmti;
+	const struct scmi_shmti_desc *desc;
+	void __iomem *addr;
+	u64 phys_addr;
+	u32 len;
+
+	desc = &r->desc[st->loop_idx];
+	shmti = &ti->shmti[st->desc_index + st->loop_idx];
+
+	shmti->info.sid = le32_to_cpu(desc->id);
+	shmti->flags = le32_to_cpu(desc->flags);
+	phys_addr = le32_to_cpu(desc->addr_low);
+	phys_addr |= (u64)le32_to_cpu(desc->addr_high) << 32;
+
+	len = le32_to_cpu(desc->length);
+	if (len < SHMTI_MIN_SIZE) {
+		dev_err(ph->dev, "Invalid length for SHMTI ID:%u len:%u\n",
+			shmti->info.sid, len);
+		return -EINVAL;
+	}
+
+	addr = devm_ioremap(ph->dev, phys_addr, len);
+	if (!addr)
+		return -EADDRNOTAVAIL;
+
+	shmti->base = addr;
+	shmti->info.len = len;
+	shmti->info.phys = phys_addr;
+	shmti->info.offset = shmti->info.phys & ~PAGE_MASK;
+
+	return scmi_telemetry_shmti_validate(ph->dev, shmti);
+}
+
+static int scmi_telemetry_shmti_list(const struct scmi_protocol_handle *ph,
+				     struct telemetry_info *ti)
+{
+	struct scmi_iterator_ops ops = {
+		.prepare_message = iter_tlm_prepare_message,
+		.update_state = iter_shmti_update_state,
+		.process_response = iter_shmti_process_response,
+	};
+	void *iter;
+
+	iter = ph->hops->iter_response_init(ph, &ops, ti->num_shmti,
+					    TELEMETRY_LIST_SHMTI,
+					    sizeof(u32), ti);
+	if (IS_ERR(iter))
+		return PTR_ERR(iter);
+
+	return ph->hops->iter_response_run(iter);
+}
+
+static int scmi_telemetry_enumerate_shmti(struct telemetry_info *ti)
+{
+	const struct scmi_protocol_handle *ph = ti->ph;
+	struct scmi_telemetry_shmti_info **shmtis;
+	int ret;
+
+	if (!ti->num_shmti)
+		return 0;
+
+	ti->shmti = devm_kcalloc(ph->dev, ti->num_shmti, sizeof(*ti->shmti),
+				 GFP_KERNEL);
+	if (!ti->shmti)
+		return -ENOMEM;
+
+	ret = scmi_telemetry_shmti_list(ph, ti);
+	if (ret) {
+		dev_err(ph->dev, "Cannot get SHMTI list descriptors");
+		return ret;
+	}
+
+	/* Expose initialized SHMTIs references */
+	shmtis = devm_kcalloc(ph->dev, ti->num_shmti,
+			      sizeof(*shmtis), GFP_KERNEL);
+	if (!shmtis)
+		return -ENOMEM;
+
+	for (int i = 0; i < ti->num_shmti; i++)
+		shmtis[i] = &ti->shmti[i].info;
+
+	ti->info.shmtis = shmtis;
+	ti->info.base.num_shmtis = ti->num_shmti;
+
+	return 0;
+}
+
+static const struct scmi_telemetry_info *
+scmi_telemetry_info_get(const struct scmi_protocol_handle *ph)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+
+	return &ti->info;
+}
+
+static const struct scmi_telemetry_de *
+scmi_telemetry_de_lookup(const struct scmi_protocol_handle *ph, u32 id)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+
+	ti->res_get(ti);
+	return xa_load(&ti->xa_des, id);
+}
+
+static const struct scmi_telemetry_res_info *
+scmi_telemetry_resources_get(const struct scmi_protocol_handle *ph)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+
+	return ti->res_get(ti);
+}
+
+static u64
+scmi_telemetry_blkts_read(u32 magic, struct telemetry_block_ts *bts)
+{
+	if (WARN_ON(!bts || !refcount_read(&bts->line.users)))
+		return 0;
+
+	guard(mutex)(&bts->line.mtx);
+
+	if (bts->line.last_magic == magic)
+		return bts->last_ts;
+
+	/* Note that the bts->last_rate can change ONLY on creation */
+	bts->last_ts = BLK_TS_STAMP(&bts->line.payld->blk_tsl);
+	bts->line.last_magic = magic;
+
+	return bts->last_ts;
+}
+
+static void scmi_telemetry_blkts_update(struct telemetry_info *ti, u32 magic,
+					struct telemetry_block_ts *bts)
+{
+	guard(mutex)(&bts->line.mtx);
+
+	if (bts->line.last_magic != magic) {
+		bts->last_ts = BLK_TS_STAMP(&bts->line.payld->blk_tsl);
+		bts->last_rate = BLK_TS_RATE(bts->line.payld);
+		/* BLK_TS clock rate value can change ONLY here on creation */
+		if (!bts->last_rate)
+			bts->last_rate = ti->default_blk_ts_rate;
+		bts->line.last_magic = magic;
+	}
+}
+
+static void scmi_telemetry_line_put(struct telemetry_line *line, void *blob)
+{
+	if (refcount_dec_and_test(&line->users)) {
+		scoped_guard(mutex, &line->mtx)
+			xa_erase(line->xa_lines, (unsigned long)line->payld);
+		kfree(blob);
+	}
+}
+
+static void scmi_telemetry_blkts_unlink(struct telemetry_de *tde)
+{
+	scmi_telemetry_line_put(&tde->bts->line, tde->bts);
+	tde->bts = NULL;
+}
+
+static void scmi_telemetry_uuid_unlink(struct telemetry_de *tde)
+{
+	scmi_telemetry_line_put(&tde->uuid->line, tde->uuid);
+	tde->uuid = NULL;
+}
+
+static void scmi_telemetry_de_unlink(struct scmi_telemetry_de *de)
+{
+	struct telemetry_de *tde = to_tde(de);
+
+	/* Unlink all related lines triggering their deallocation */
+	if (tde->bts)
+		scmi_telemetry_blkts_unlink(tde);
+	if (tde->uuid)
+		scmi_telemetry_uuid_unlink(tde);
+}
+
+static struct telemetry_line *
+scmi_telemetry_line_get(struct xarray *xa_lines, struct payload __iomem *payld)
+{
+	struct telemetry_line *line;
+
+	line = xa_load(xa_lines, (unsigned long)payld);
+	if (!line)
+		return NULL;
+
+	refcount_inc(&line->users);
+
+	return line;
+}
+
+static int
+scmi_telemetry_line_init(struct telemetry_line *line, struct xarray *xa_lines,
+			 struct payload __iomem *payld)
+{
+	refcount_set(&line->users, 1);
+	line->payld = payld;
+	line->xa_lines = xa_lines;
+	mutex_init(&line->mtx);
+
+	return xa_insert(xa_lines, (unsigned long)payld, line, GFP_KERNEL);
+}
+
+static struct telemetry_block_ts *
+scmi_telemetry_blkts_create(struct device *dev, struct xarray *xa_lines,
+			    struct payload __iomem *payld)
+{
+	struct telemetry_block_ts *bts;
+	int ret;
+
+	bts = kzalloc_obj(*bts);
+	if (!bts)
+		return NULL;
+
+	ret = scmi_telemetry_line_init(&bts->line, xa_lines, payld);
+	if (ret) {
+		kfree(bts);
+		return NULL;
+	}
+
+	trace_scmi_tlm_collect(0, (__force u64)payld, 0, "SHMTI_NEW_BLKTS");
+
+	return bts;
+}
+
+static struct telemetry_block_ts *
+scmi_telemetry_blkts_get_or_create(struct device *dev, struct xarray *xa_lines,
+				   struct payload __iomem *payld)
+{
+	struct telemetry_line *line;
+
+	line = scmi_telemetry_line_get(xa_lines, payld);
+	if (line)
+		return to_blkts(line);
+
+	return scmi_telemetry_blkts_create(dev, xa_lines, payld);
+}
+
+static struct telemetry_uuid *
+scmi_telemetry_uuid_create(struct device *dev, struct xarray *xa_lines,
+			   struct payload __iomem *payld)
+{
+	struct telemetry_uuid *uuid;
+	struct uuid_line __iomem *uuid_l = &payld->uuid_l;
+	int ret;
+
+	uuid = kzalloc_obj(*uuid);
+	if (!uuid)
+		return NULL;
+
+	for (int i = 0; i < SCMI_TLM_DE_IMPL_MAX_DWORDS; i++)
+		/*
+		 * Fetch BigEndian in-memory UUID fields as per SCMIv4.0
+		 * specification 3.12.2.2
+		 */
+		uuid->de_impl_version[i] = ioread32be(&uuid_l->dwords[i]);
+
+	ret = scmi_telemetry_line_init(&uuid->line, xa_lines, payld);
+	if (ret) {
+		kfree(uuid);
+		return NULL;
+	}
+
+	trace_scmi_tlm_collect(0, (__force u64)payld, 0, "SHMTI_NEW_UUID");
+
+	return uuid;
+}
+
+static struct telemetry_uuid *
+scmi_telemetry_uuid_get_or_create(struct device *dev, struct xarray *xa_lines,
+				  struct payload __iomem *payld)
+{
+	struct telemetry_line *line;
+
+	line = scmi_telemetry_line_get(xa_lines, payld);
+	if (line)
+		return to_uuid(line);
+
+	return scmi_telemetry_uuid_create(dev, xa_lines, payld);
+}
+
+static void scmi_telemetry_tdcf_uuid_parse(struct telemetry_info *ti,
+					   struct payload __iomem *payld,
+					   struct telemetry_shmti *shmti,
+					   void **active_uuid)
+{
+	struct telemetry_uuid *uuid;
+
+	if (UUID_INVALID(payld)) {
+		trace_scmi_tlm_access(0, "UUID_INVALID", 0, 0);
+		return;
+	}
+
+	/* A UUID descriptor MUST be returned: it is found or it is created */
+	uuid = scmi_telemetry_uuid_get_or_create(ti->ph->dev, &ti->xa_lines,
+						 payld);
+	if (WARN_ON(!uuid))
+		return;
+
+	*active_uuid = uuid;
+}
+
+static struct payload __iomem *
+scmi_telemetry_nearest_line_by_type(struct telemetry_shmti *shmti,
+				    void __iomem *last, enum tdcf_line_types ltype)
+{
+	struct tdcf __iomem *tdcf = shmti->base;
+	void __iomem *next, *found = NULL;
+
+	/* Scan from start of TDCF payloads up to last_payld */
+	next = tdcf->payld;
+	while (next < last) {
+		if (LINE_TYPE((struct payload __iomem *)next) == ltype)
+			found = next;
+
+		next += LINE_LENGTH_BYTES((struct payload __iomem *)next);
+	}
+
+	return found;
+}
+
+static struct telemetry_block_ts *
+scmi_telemetry_blkts_bind(struct device *dev, struct telemetry_shmti *shmti,
+			  struct payload __iomem *payld, struct xarray *xa_lines,
+			  struct payload __iomem *bts_payld)
+{
+	/* Trigger a manual search when no BLK_TS payload offset was provided */
+	if (!bts_payld) {
+		/* Find the BLK_TS immediately preceding this DE payld */
+		bts_payld = scmi_telemetry_nearest_line_by_type(shmti, payld,
+								TDCF_BLK_TS_LINE);
+		if (!bts_payld)
+			return NULL;
+	}
+
+	return scmi_telemetry_blkts_get_or_create(dev, xa_lines, bts_payld);
+}
+
+/**
+ * scmi_telemetry_tdcf_blkts_parse  - A BLK_TS line parser
+ *
+ * @ti: A reference to the telemetry_info descriptor
+ * @payld: TDCF payld line to process
+ * @shmti: SHMTI descriptor inside which the scan is happening
+ * @active_bts: Input/output reference to keep track of the last blk_ts found
+ *
+ * Process a valid TDCF BLK_TS line and, after having looked up or created a
+ * blk_ts descriptor, update the related data and return it as the currently
+ * active blk_ts, given that it is effectively the last found during this
+ * scan.
+ */
+static void scmi_telemetry_tdcf_blkts_parse(struct telemetry_info *ti,
+					    struct payload __iomem *payld,
+					    struct telemetry_shmti *shmti,
+					    void **active_bts)
+{
+	struct telemetry_block_ts *bts;
+
+	/* Check for spec compliance */
+	if (BLK_TS_INVALID(payld)) {
+		trace_scmi_tlm_access(0, "BLK_TS_INVALID", 0, 0);
+		return;
+	}
+
+	/* A BLK_TS descriptor MUST be returned: it is found or it is created */
+	bts = scmi_telemetry_blkts_get_or_create(ti->ph->dev,
+						 &ti->xa_lines, payld);
+	if (WARN_ON(!bts))
+		return;
+
+	/* Update the descriptor with the lastest TS */
+	scmi_telemetry_blkts_update(ti, shmti->last_magic, bts);
+	*active_bts = bts;
+}
+
+static inline struct telemetry_de *
+scmi_telemetry_tde_allocate(struct telemetry_info *ti, u32 de_id,
+			    struct payload __iomem *payld)
+{
+	struct telemetry_de *tde;
+
+	tde = scmi_telemetry_tde_get(ti, de_id);
+	if (IS_ERR(tde))
+		return NULL;
+
+	tde->de.info->id = de_id;
+	tde->de.enabled = true;
+	tde->de.tstamp_enabled = LINE_TS_VALID(payld) || USE_BLK_TS(payld);
+
+	if (scmi_telemetry_tde_register(ti, tde)) {
+		scmi_telemetry_free_tde_put(ti, tde);
+		return NULL;
+	}
+
+	scmi_telemetry_de_state_update(ti, ENA_STATE, NULL, true);
+	if (tde->de.tstamp_enabled)
+		scmi_telemetry_de_state_update(ti, ENA_TSTAMP, NULL, true);
+
+	return tde;
+}
+
+static inline void
+scmi_telemetry_line_data_parse(struct telemetry_de *tde,
+			       struct scmi_telemetry_de_sample *sample,
+			       struct payload __iomem *payld, u32 magic)
+{
+	/* Data is always valid since we are NOT handling BLK TS lines here */
+	sample->val = LINE_DATA_GET(&payld->l);
+	if (USE_BLK_TS(payld)) {
+		/* Read out the actual BLK_TS */
+		sample->tstamp = scmi_telemetry_blkts_read(magic, tde->bts);
+	} else if (LINE_TS_VALID(payld)) {
+		/*
+		 * Note that LINE_TS_VALID implies HAS_LINE_EXT and that
+		 * the per DE line_ts_rate is advertised in the DE
+		 * descriptor.
+		 */
+		sample->tstamp = LINE_TSTAMP_GET(&payld->tsl);
+	} else {
+		sample->tstamp = 0;
+	}
+
+	/* Trace originally read tstamp */
+	trace_scmi_tlm_collect(sample->tstamp, tde->de.info->id,
+			       sample->val, "SHMTI_DE_READ");
+
+	scmi_telemetry_tde_cache_update(tde, sample, &magic);
+}
+
+static inline void scmi_telemetry_bts_link(struct telemetry_de *tde,
+					   struct telemetry_block_ts *bts)
+{
+	guard(mutex)(&bts->line.mtx);
+	refcount_inc(&bts->line.users);
+	tde->bts = bts;
+	/* Update TS clock rate if provided by the BLK_TS */
+	if (tde->bts->last_rate)
+		tde->de.info->ts_rate = tde->bts->last_rate;
+}
+
+static inline void scmi_telemetry_uuid_link(struct telemetry_de *tde,
+					    struct telemetry_uuid *uuid)
+{
+	refcount_inc(&uuid->line.users);
+	tde->uuid = uuid;
+}
+
+/**
+ * scmi_telemetry_tdcf_data_parse  - TDCF DataLine parsing
+ * @ti: A reference to the telemetry info descriptor
+ * @payld: Line payload to parse
+ * @shmti: A reference to the containing SHMTI area
+ * @mode: A flag to determine the behaviour of the scan
+ * @active_bts: A pointer to keep track and report any found BLK timestamp line
+ * @active_uuid: A pointer to keep track and report any found UUID line
+ *
+ * This routine takes care to:
+ *  - verify line consistency in relation to the used flags and the current
+ *    context: e.g. is there an active preceding BLK_TS line if the DataLine
+ *    sports a USE_BLKTS flag ?
+ *  - verify the related Data Event ID exists OR create a brand new DE
+ *    (depending on the @mode of operation)
+ *  - links any active BLK_TS or UUID line to the current DE
+ *  - read and save value/tstamp for the DE ONLY if anything has changed (by
+ *    tracking the last TDCF magic) and update related magic: this allows to
+ *    minimize future needs of single-DE reads
+ *
+ *    Modes of operation.
+ *
+ *    The scan behaviour depends on the chosen @mode:
+ *    - SCAN_LOOKUP: the basic scan which aims to update value associated to
+ *		     existing DEs. Any discovered DataLine that could NOT be
+ *		     matched to an existing, previously discovered, DE is
+ *		     discarded. This is the normal scan behaviour.
+ *    - SCAN_UPDATE: a more advanced scan which provides all the SCAN_LOOKUP
+ *		     features plus takes care to update the DEs location
+ *		     coordinates inside the SHMTI: note that the related DEs are
+ *		     still supposed to have been previously discovered when
+ *		     this scan runs. This is used to update location
+ *		     coordinates for DEs contained in a Group when such group
+ *		     is enabled.
+ *    - SCAN_DISCOVERY: the most advanced scan available which provides all
+ *			the SCAN_LOOKUP features plus discovery capabilities:
+ *			any DataLine referring to a previously unknown DE leads
+ *			to the allocation of a new DE descriptor.
+ *			This mode is used on the first scan at init time, ONLY
+ *			if Telemetry was found to be already enabled at boot on
+ *			the platform side: this helps to maximize gathered
+ *			information when dealing with out of spec firmwares.
+ *			Any usage of this discovery mode other than in a boot-on
+ *			enabled scenario is discouraged since it can easily
+ *			lead to spurious DE discoveries.
+ */
+static void scmi_telemetry_tdcf_data_parse(struct telemetry_info *ti,
+					   struct payload __iomem *payld,
+					   struct telemetry_shmti *shmti,
+					   enum scan_mode mode,
+					   void *active_bts, void *active_uuid)
+{
+	struct scmi_telemetry_de_sample sample = {};
+	bool use_blk_ts = USE_BLK_TS(payld);
+	struct telemetry_de *tde;
+	u32 de_id;
+
+	de_id = PAYLD_ID(payld);
+	/* Discard malformed lines...a preceding BLK_TS must exist */
+	if (use_blk_ts && !active_bts) {
+		trace_scmi_tlm_access(de_id, "BAD_USE_BLK_TS", 0, 0);
+		return;
+	}
+
+	/* Is this DE ID known ? */
+	tde = scmi_telemetry_tde_lookup(ti, de_id);
+	if (!tde) {
+		if (mode != SCAN_DISCOVERY) {
+			trace_scmi_tlm_access(de_id, "DE_INVALID", 0, 0);
+			return;
+		}
+
+		/* In SCAN_DISCOVERY mode we allocate new DEs for unknown IDs */
+		tde = scmi_telemetry_tde_allocate(ti, de_id, payld);
+		if (!tde)
+			return;
+	}
+
+	/* Update DE location refs if requested: normally done only on enable */
+	if (mode >= SCAN_UPDATE) {
+		tde->base = shmti->base;
+		tde->eplg = SHMTI_EPLG(shmti);
+		tde->offset = (void __iomem *)payld - (void __iomem *)shmti->base;
+
+		dev_dbg(ti->ph->dev,
+			"TDCF-updated DE_ID:0x%08X - shmti:%pK  offset:%u\n",
+			tde->de.info->id, tde->base, tde->offset);
+	}
+
+	/* Has any value/tstamp really changed ?*/
+	if (scmi_telemetry_tde_cache_unchanged(tde, shmti->last_magic))
+		return;
+
+	/* Link the related BTS when needed, it's unlinked on disable */
+	if (use_blk_ts && !tde->bts)
+		scmi_telemetry_bts_link(tde, active_bts);
+
+	/* Link the active UUID when existent, it's unlinked on disable */
+	if (active_uuid)
+		scmi_telemetry_uuid_link(tde, active_uuid);
+
+	/* Parse data words ... only for the sake of updating TDE cache */
+	scmi_telemetry_line_data_parse(tde, &sample, payld, shmti->last_magic);
+}
+
+static int scmi_telemetry_tdcf_line_parse(struct telemetry_info *ti,
+					  struct payload __iomem *payld,
+					  struct telemetry_shmti *shmti,
+					  enum scan_mode mode,
+					  void **active_bts, void **active_uuid)
+{
+	int used_qwords;
+
+	used_qwords = LINE_LENGTH_QWORDS(payld);
+	/* Invalid lines are not an error, could simply be disabled DEs */
+	if (DATA_INVALID(payld)) {
+		trace_scmi_tlm_access(PAYLD_ID(payld), "TDCF_INVALID", 0, 0);
+		return used_qwords;
+	}
+
+	switch (LINE_TYPE(payld)) {
+	case TDCF_DATA_LINE:
+		scmi_telemetry_tdcf_data_parse(ti, payld, shmti, mode,
+					       *active_bts, *active_uuid);
+		break;
+	case TDCF_BLK_TS_LINE:
+		scmi_telemetry_tdcf_blkts_parse(ti, payld, shmti, active_bts);
+		break;
+	case TDCF_UUID_LINE:
+		scmi_telemetry_tdcf_uuid_parse(ti, payld, shmti, active_uuid);
+		break;
+	default:
+		trace_scmi_tlm_access(PAYLD_ID(payld), "TDCF_UNKNOWN", 0, 0);
+		break;
+	}
+
+	return used_qwords;
+}
+
+/**
+ * scmi_telemetry_shmti_scan  - Full SHMTI scan
+ * @ti: A reference to the telemetry info descriptor
+ * @shmti_id: ID of the SHMTI area that has to be scanned
+ * @mode: A flag to determine the behaviour of the scan
+ *
+ * Return: 0 on Success
+ */
+static int scmi_telemetry_shmti_scan(struct telemetry_info *ti,
+				     unsigned int shmti_id, enum scan_mode mode)
+{
+	struct telemetry_shmti *shmti = &ti->shmti[shmti_id];
+	struct tdcf __iomem *tdcf = shmti->base;
+	int retries = SCMI_TLM_TDCF_MAX_RETRIES;
+	u32 startm = 0, endm = TDCF_BAD_END_SEQ;
+
+	if (!tdcf)
+		return -ENODEV;
+
+	do {
+		void *active_bts = NULL, *active_uuid = NULL;
+		unsigned int qwords;
+		void __iomem *next;
+
+		/* A bit of exponential backoff between retries */
+		fsleep((SCMI_TLM_TDCF_MAX_RETRIES - retries) * 1000);
+
+		/*
+		 * Note that during a full SHMTI scan the magic seq numbers are
+		 * checked only at the start and at the end of the scan, NOT
+		 * between each parsed line and this has these consequences:
+		 *  - TDCF magic numbers accesses are reduced to 2 reads
+		 *  - the set of values obtained from a full scan belong all
+		 *    to the same platform update (same magic number)
+		 *  - a SHMTI full scan is an all or nothing operation: when
+		 *    a potentially corrupted read is detected along the way
+		 *    (MSEQ_MISMATCH) another full scan is triggered.
+		 */
+		startm = TDCF_START_SEQ_GET(tdcf);
+		if (IS_BAD_START_SEQ(startm)) {
+			trace_scmi_tlm_access(0, "MSEQ_BADSTART", startm, 0);
+			continue;
+		}
+
+		/* On a BAD_SEQ this will be updated on the next attempt */
+		shmti->last_magic = startm;
+
+		qwords = QWORDS(tdcf);
+		next = tdcf->payld;
+		while (qwords) {
+			int used_qwords;
+
+			if (SHMTI_OVERFLOWS(next, shmti)) {
+				trace_scmi_tlm_access(PAYLD_ID(next),
+						      "SHMTI_OVERFLOW", startm, 0);
+				return -EINVAL;
+			}
+
+			used_qwords = scmi_telemetry_tdcf_line_parse(ti, next,
+								     shmti, mode,
+								     &active_bts,
+								     &active_uuid);
+			if (qwords < used_qwords) {
+				trace_scmi_tlm_access(PAYLD_ID(next),
+						      "BAD_QWORDS", startm, 0);
+				return -EINVAL;
+			}
+
+			next += used_qwords * 8;
+			qwords -= used_qwords;
+		}
+
+		endm = TDCF_END_SEQ_GET(SHMTI_EPLG(shmti));
+		if (startm != endm)
+			trace_scmi_tlm_access(0, "MSEQ_MISMATCH", startm, endm);
+	} while (startm != endm && --retries);
+
+	if (startm != endm) {
+		trace_scmi_tlm_access(0, "TDCF_SCAN_FAIL", startm, endm);
+		return -EPROTO;
+	}
+
+	return 0;
+}
+
+static int scmi_telemetry_group_state_update(struct telemetry_info *ti,
+					     struct scmi_telemetry_group *grp,
+					     const bool *enable, const bool *tstamp)
+{
+	struct scmi_telemetry_res_info *rinfo;
+
+	rinfo = ti->res_get(ti);
+	for (int i = 0; i < grp->info->num_des; i++) {
+		struct scmi_telemetry_de *de = rinfo->des[grp->des[i]];
+
+		if (enable)
+			scmi_telemetry_de_state_update(ti, ENA_STATE,
+						       &de->enabled, *enable);
+
+		if (tstamp && de->tstamp_support)
+			scmi_telemetry_de_state_update(ti, ENA_TSTAMP,
+						       &de->tstamp_enabled, *tstamp);
+	}
+
+	return 0;
+}
+
+static void scmi_telemetry_group_unlink(struct telemetry_info *ti,
+					struct scmi_telemetry_group *grp)
+{
+	struct scmi_telemetry_res_info *rinfo;
+
+	rinfo = ti->res_get(ti);
+	/* Unlink the related BLK_TS/UUID lines of DEs composing the group */
+	for (int i = 0; i < grp->info->num_des; i++)
+		scmi_telemetry_de_unlink(rinfo->des[grp->des[i]]);
+}
+
+static int
+scmi_telemetry_state_set_resp_process(struct telemetry_info *ti, void *obj,
+				      void *r, bool is_group)
+{
+	struct scmi_msg_resp_telemetry_de_configure *resp = r;
+	u32 sid = le32_to_cpu(resp->shmti_id);
+
+	/* Update DE SHMTI and offset, if applicable */
+	if (IS_SHMTI_ID_VALID(sid)) {
+		if (sid >= ti->num_shmti)
+			return -EPROTO;
+
+		/*
+		 * Update SHMTI/offset while skipping non-SHMTI-DEs like
+		 * FCs and notif-only.
+		 */
+		if (!is_group) {
+			struct telemetry_de *tde;
+			struct payload __iomem *payld;
+			struct scmi_telemetry_de *de = obj;
+			u32 de_offs;
+
+			de_offs = le32_to_cpu(resp->shmti_de_offset);
+			payld = ti->shmti[sid].base;
+			/* Check boundary first... */
+			if (de_offs + LINE_LENGTH_BYTES(payld) >=
+			    ti->shmti[sid].info.len)
+				return -EPROTO;
+
+			tde = to_tde(de);
+			/*...then assign */
+			tde->base = ti->shmti[sid].base;
+			tde->offset = de_offs;
+			/* A handy reference to the Epilogue updated */
+			tde->eplg = SHMTI_EPLG(&ti->shmti[sid]);
+
+			payld = tde->base + tde->offset;
+			if (USE_BLK_TS(payld) && !tde->bts) {
+				struct payload __iomem *bts_payld;
+				u32 bts_offs;
+
+				bts_offs = le32_to_cpu(resp->blk_ts_offset);
+				bts_payld = (bts_offs) ? tde->base + bts_offs : NULL;
+
+				/* Check SHMTI overflow on returned offset */
+				if (bts_payld &&
+				    SHMTI_OVERFLOWS(bts_payld, &ti->shmti[sid]))
+					return -ENOSPC;
+
+				tde->bts = scmi_telemetry_blkts_bind(ti->ph->dev,
+								     &ti->shmti[sid],
+								     payld,
+								     &ti->xa_lines,
+								     bts_payld);
+				if (WARN_ON(!tde->bts))
+					return -EPROTO;
+			}
+		} else {
+			int ret;
+
+			/*
+			 * A full SHMTI scan is needed when enabling a
+			 * group or its timestamps in order to retrieve
+			 * offsets: note that when group-timestamp is
+			 * enabled for composing DEs a re-scan is needed
+			 * since some DEs could have been relocated due
+			 * to lack of space in the TDCF.
+			 */
+			ret = scmi_telemetry_shmti_scan(ti, sid, SCAN_UPDATE);
+			if (ret) {
+				dev_err(ti->ph->dev,
+					"Failed group-scan of SHMTI ID:%d - ret:%d\n",
+					sid, ret);
+				return ret;
+			}
+		}
+	} else {
+		/* Unlink the related BLK_TS/UUID lines on disable */
+		if (!is_group)
+			scmi_telemetry_de_unlink(obj);
+		else
+			scmi_telemetry_group_unlink(ti, obj);
+	}
+
+	return 0;
+}
+
+static int __scmi_telemetry_state_set(const struct scmi_protocol_handle *ph,
+				      bool is_group, const bool *enable,
+				      bool *enabled_state, const bool *tstamp,
+				      bool *tstamp_enabled_state, void *obj)
+{
+	struct scmi_msg_resp_telemetry_de_configure *resp;
+	struct scmi_msg_telemetry_de_configure *msg;
+	struct telemetry_info *ti = ph->get_priv(ph);
+	struct scmi_telemetry_de *de = !is_group ? obj : NULL;
+	struct scmi_telemetry_group *grp = is_group ? obj : NULL;
+	unsigned int obj_id = !is_group ? de->info->id : grp->info->grp_id;
+	struct scmi_xfer *t;
+	int ret;
+
+	if (!enabled_state || !tstamp_enabled_state)
+		return -EINVAL;
+
+	/* Is anything to do at all on this DE ? */
+	if (!is_group && (!enable || *enable == *enabled_state) &&
+	    (!tstamp || *tstamp == *tstamp_enabled_state))
+		return 0;
+
+	/*
+	 * DE is currently disabled AND no enable state change was requested,
+	 * while timestamp is being changed: update only local state...no need
+	 * to send a message.
+	 */
+	if (!is_group && !enable && !*enabled_state) {
+		if (de->tstamp_support)
+			scmi_telemetry_de_state_update(ti, ENA_TSTAMP,
+						       tstamp_enabled_state,
+						       *tstamp);
+
+		/* A local change can have an impact anyway */
+		scmi_telemetry_generation_update(ti);
+		return 0;
+	}
+
+	ret = ph->xops->xfer_get_init(ph, TELEMETRY_DE_CONFIGURE,
+				      sizeof(*msg), sizeof(*resp), &t);
+	if (ret)
+		return ret;
+
+	msg = t->tx.buf;
+	/* Note that BOTH DE and GROUPS have a first ID field.. */
+	msg->id = cpu_to_le32(obj_id);
+	/* Default to disable mode for one DE */
+	msg->flags = DE_DISABLE_ONE;
+	msg->flags |= cpu_to_le32(FIELD_PREP(GENMASK(3, 3),
+				 is_group ? EVENT_GROUP : EVENT_DE));
+
+	if ((!enable && *enabled_state) || (enable && *enable)) {
+		/* Already enabled but tstamp_enabled state changed */
+		if (tstamp) {
+			/* Here, tstamp cannot be NULL too */
+			msg->flags |= cpu_to_le32(*tstamp ?
+					DE_ENABLE_WTH_TSTAMP : DE_ENABLE_NO_TSTAMP);
+		} else {
+			msg->flags |= cpu_to_le32(*tstamp_enabled_state ?
+					DE_ENABLE_WTH_TSTAMP : DE_ENABLE_NO_TSTAMP);
+		}
+	}
+
+	resp = t->rx.buf;
+	ret = ph->xops->do_xfer(ph, t);
+	if (!ret) {
+		ret = scmi_telemetry_state_set_resp_process(ti, obj, resp, is_group);
+		if (!ret) {
+			/* Update cached state on success */
+			if (enable) {
+				if (!is_group)
+					scmi_telemetry_de_state_update(ti, ENA_STATE,
+								       enabled_state,
+								       *enable);
+				else
+					*enabled_state = *enable;
+			}
+			if (tstamp) {
+				if (!is_group) {
+					if (de->tstamp_support)
+						scmi_telemetry_de_state_update(ti, ENA_TSTAMP,
+									       tstamp_enabled_state,
+									       *tstamp);
+				} else {
+					*tstamp_enabled_state = *tstamp;
+				}
+			}
+
+			if (is_group)
+				scmi_telemetry_group_state_update(ti, grp, enable,
+								  tstamp);
+		}
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	if (!ret)
+		scmi_telemetry_generation_update(ti);
+
+	return ret;
+}
+
+static int scmi_telemetry_state_get(const struct scmi_protocol_handle *ph,
+				    const u32 *id, bool *enabled, bool *tstamp_enabled)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+	struct scmi_telemetry_de *de;
+
+	if (!enabled || !tstamp_enabled)
+		return -EINVAL;
+
+	if (!id) {
+		/* Returning the all_des_* state */
+		*enabled =
+			(atomic_read(&ti->des_enabled[ENA_STATE]) == ti->info.base.num_des);
+		*tstamp_enabled =
+			(atomic_read(&ti->des_enabled[ENA_TSTAMP]) == ti->num_des_tstamp);
+
+		return 0;
+	}
+
+	de = xa_load(&ti->xa_des, *id);
+	if (!de)
+		return -ENODEV;
+
+	*enabled = de->enabled;
+	*tstamp_enabled = de->tstamp_enabled;
+
+	return 0;
+}
+
+static int scmi_telemetry_state_set(const struct scmi_protocol_handle *ph,
+				    bool is_group, u32 id, const bool *enable,
+				    const bool *tstamp)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+	bool *enabled_state, *tstamp_enabled_state;
+	struct scmi_telemetry_res_info *rinfo;
+	void *obj;
+
+	rinfo = ti->res_get(ti);
+	if (!is_group) {
+		struct scmi_telemetry_de *de;
+
+		de = xa_load(&ti->xa_des, id);
+		if (!de)
+			return -ENODEV;
+
+		enabled_state = &de->enabled;
+		tstamp_enabled_state = &de->tstamp_enabled;
+		obj = de;
+	} else {
+		struct scmi_telemetry_group *grp;
+
+		if (id >= ti->info.base.num_groups)
+			return -EINVAL;
+
+		grp = &rinfo->grps[id];
+
+		enabled_state = &grp->enabled;
+		tstamp_enabled_state = &grp->tstamp_enabled;
+		obj = grp;
+	}
+
+	return __scmi_telemetry_state_set(ph, is_group, enable, enabled_state,
+					  tstamp, tstamp_enabled_state, obj);
+}
+
+static int scmi_telemetry_all_disable(const struct scmi_protocol_handle *ph,
+				      bool is_group)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+	struct scmi_msg_telemetry_de_configure *msg;
+	struct scmi_telemetry_res_info *rinfo;
+	struct scmi_xfer *t;
+	int ret;
+
+	rinfo = ti->res_get(ti);
+	ret = ph->xops->xfer_get_init(ph, TELEMETRY_DE_CONFIGURE,
+				      sizeof(*msg), 0, &t);
+	if (ret)
+		return ret;
+
+	msg = t->tx.buf;
+	msg->flags = cpu_to_le32(DE_DISABLE_ALL);
+	if (is_group)
+		msg->flags |= cpu_to_le32(GROUP_SELECTOR);
+	ret = ph->xops->do_xfer(ph, t);
+	if (!ret) {
+		for (int i = 0; i < rinfo->num_des; i++)
+			scmi_telemetry_de_state_update(ti, ENA_STATE,
+						       &rinfo->des[i]->enabled,
+						       false);
+		if (is_group) {
+			for (int i = 0; i < ti->info.base.num_groups; i++) {
+				rinfo->grps[i].enabled = false;
+				scmi_telemetry_group_unlink(ti, &rinfo->grps[i]);
+			}
+		}
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	if (!ret)
+		scmi_telemetry_generation_update(ti);
+
+	return ret;
+}
+
+static int
+scmi_telemetry_collection_configure(const struct scmi_protocol_handle *ph,
+				    unsigned int res_id, const bool *enable,
+				    const unsigned int *update_interval_ms,
+				    const enum scmi_telemetry_collection *mode)
+{
+	bool tlm_enable, is_group = res_id != SCMI_TLM_GRP_INVALID;
+	enum scmi_telemetry_collection *current_mode, next_mode;
+	struct telemetry_info *ti = ph->get_priv(ph);
+	struct scmi_msg_telemetry_config_set *msg;
+	unsigned int *active_update_interval;
+	struct scmi_xfer *t;
+	__le32 interval;
+	u32 control;
+	int ret;
+
+	if (mode && *mode == SCMI_TLM_NOTIFICATION &&
+	    !ti->info.continuos_update_support)
+		return -EINVAL;
+
+	if (is_group && res_id >= ti->info.base.num_groups)
+		return -EINVAL;
+
+	if (!is_group) {
+		active_update_interval = &ti->info.active_update_interval;
+		current_mode = &ti->info.current_mode;
+	} else {
+		struct scmi_telemetry_res_info *rinfo;
+
+		rinfo = ti->res_get(ti);
+		active_update_interval =
+			&rinfo->grps[res_id].active_update_interval;
+		current_mode = &rinfo->grps[res_id].current_mode;
+	}
+
+	if (!enable && !update_interval_ms && (!mode || *mode == *current_mode))
+		return 0;
+
+	ret = ph->xops->xfer_get_init(ph, TELEMETRY_CONFIG_SET,
+				      sizeof(*msg), 0, &t);
+	if (ret)
+		return ret;
+
+	if (!update_interval_ms)
+		interval = cpu_to_le32(*active_update_interval);
+	else
+		interval = cpu_to_le32(*update_interval_ms);
+
+	tlm_enable = enable ? *enable : ti->info.enabled;
+	next_mode = mode ? *mode : *current_mode;
+
+	msg = t->tx.buf;
+	msg->grp_id = cpu_to_le32(res_id);
+	control = tlm_enable ? TELEMETRY_ENABLE : 0;
+	control |= !is_group ? TELEMETRY_SET_SELECTOR_ALL : TELEMETRY_SET_SELECTOR_GROUP;
+	control |= TELEMETRY_MODE_SET(next_mode);
+	msg->control = cpu_to_le32(control);
+	msg->sampling_rate = interval;
+	ret = ph->xops->do_xfer(ph, t);
+	if (!ret) {
+		ti->info.enabled = tlm_enable;
+		*current_mode = next_mode;
+		ti->info.notif_enabled = *current_mode == SCMI_TLM_NOTIFICATION;
+		if (update_interval_ms)
+			*active_update_interval = le32_to_cpu(interval);
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	if (!ret)
+		scmi_telemetry_generation_update(ti);
+
+	return ret;
+}
+
+static inline void
+scmi_telemetry_de_data_fc_read(struct telemetry_de *tde,
+			       struct scmi_telemetry_de_sample *sample)
+{
+	struct fc_tsline __iomem *fc = tde->base + tde->offset;
+
+	sample->val = LINE_DATA_GET(fc);
+	sample->tstamp = LINE_TSTAMP_GET(fc);
+
+	/* Trace originally read tstamp */
+	trace_scmi_tlm_collect(sample->tstamp, tde->de.info->id, sample->val,
+			       "FC_READ");
+
+	scmi_telemetry_tde_cache_update(tde, sample, NULL);
+}
+
+static void scmi_telemetry_scan_update(struct telemetry_info *ti)
+{
+	struct telemetry_de *tde;
+
+	/* Scan all SHMTIs ... */
+	for (int id = 0; id < ti->num_shmti; id++) {
+		int ret;
+
+		ret = scmi_telemetry_shmti_scan(ti, id, SCAN_LOOKUP);
+		if (ret)
+			dev_warn(ti->ph->dev,
+				 "Failed update-scan of SHMTI ID:%d - ret:%d\n",
+				 id, ret);
+	}
+
+	if (!ti->info.fc_support)
+		return;
+
+	/* Need to enumerate resources to access fastchannels */
+	ti->res_get(ti);
+	list_for_each_entry(tde, &ti->fcs_des, item) {
+		struct scmi_telemetry_de_sample sample = {};
+
+		if (!tde->de.enabled)
+			continue;
+
+		/* Only for the sake of updating TDE cache */
+		scmi_telemetry_de_data_fc_read(tde, &sample);
+	}
+}
+
+/*
+ * TDCF and TS Line Management Notes
+ * ---------------------------------
+ *
+ * TDCF Payload Metadata notable bits:
+ *  - Bit[3]: USE BLK Tstamp
+ *  - Bit[2]: Line-Extension Field present (LineTstamp)
+ *  - Bit[1]: Tstamp VALID
+ *  - Bit[0]: Data INVALID
+ *
+ * CASE_1:
+ * -------
+ *	+ A DE is enabled with timestamp disabled, so the TS fields are
+ *	  NOT present
+ *	  -> BIT[3:0] = 0000b
+ *
+ *	  - 1/A LINE_TSTAMP
+ *	  ------------------
+ *	     + that DE is then 're-enabled' with TS: so it was ON, it remains
+ *	       ON but using DE_CONFIGURE I now enabled also TS, so the
+ *	       platform relocates it at the end of the SHMTI and return the
+ *	       new offset
+ *	       -> BIT[3:0] = 0110b
+ *
+ *	  - 1/B BLK_TSTAMP
+ *	  ------------------
+ *	     + that DE is then 're-enabled' with BLK TS: so it was ON, it
+ *	       remains ON but using DE_CONFIGURE, we now also enabled the TS,
+ *	       so the platform will:
+ *	       - IF a preceding BLK_TS line exist (with same clk rate)
+ *	         it relocates the DE at the end of the SHMTI and return the
+ *	         new offset (if there is enough room, if not in another SHMTI)
+ *	       - IF a preceding BLK_TS line DOES NOT exist (with same clk rate)
+ *	         it creates a new BLK_TS line at the end of the SHMTI and then
+ *	         relocates the DE after the new BLK_TS and return the
+ *	         new offset (if there is enough room, if not in another SHMTI)
+ *	       -> BIT[3:1] = 1010b
+ *
+ *	+ the hole left from the relocated DE can be reused by the platform
+ *	to fit another equally sized DE. (i.e. without shuffling around any
+ *	other enabled DE, since that would cause a change of the known offset)
+ *	anyway it will be marked as:
+ *	-> BIT[3:0] = 0101b iff it was a LINE_TSTAMP
+ *	-> BIT[3:0] = 0001b iff it was a BLK_TSTAMP
+ *
+ * CASE_2:
+ * -------
+ *	+ A DE is enabled with LINE timestamp enabled, so the TS_Line is there
+ *	  -> BIT[3:0] = 0110b
+ *	+ that DE has its timestamp disabled: again, you can do this without
+ *	  disabling it fully but just disabling the TS, so now that TS_line
+ *	  fields are still physically there but NOT valid
+ *	  -> BIT[3:0] = 0100b
+ *	+ the hole from the timestamp remain there unused until
+ *		- you enable again the TS so the hole is used again
+ *		  -> BIT[3:0] = 0110b
+ *			OR
+ *		- you disable fully the DE and then re-enable it with the TS
+ *		  -> potentially CASE_1 the DE is relocated on enable
+ *	+ same kind of dynamic applies if the DE had a BLK_TS line
+ */
+static struct payload __iomem *
+scmi_telemetry_tdcf_de_payld_get(struct telemetry_de *tde)
+{
+	struct payload __iomem *payld;
+
+	payld = tde->base + tde->offset;
+	if (DATA_INVALID(payld)) {
+		trace_scmi_tlm_access(PAYLD_ID(payld), "DE_DATA_INVALID", 0, 0);
+		return IOMEM_ERR_PTR(-EINVAL);
+	}
+
+	if (IS_BLK_TS_LINE(payld)) {
+		trace_scmi_tlm_access(tde->de.info->id, "BAD_DE_META", 0, 0);
+		return IOMEM_ERR_PTR(-EPROTO);
+	}
+
+	if (PAYLD_ID(payld) != tde->de.info->id) {
+		trace_scmi_tlm_access(tde->de.info->id, "DE_ID_MISMATCH", 0, 0);
+		return IOMEM_ERR_PTR(-ENODEV);
+	}
+
+	/*
+	 * A valid line using BLK_TS should have been initialized with the
+	 * related BLK_TS when enabled.
+	 */
+	if (WARN_ON((USE_BLK_TS(payld) && !tde->bts))) {
+		trace_scmi_tlm_access(tde->de.info->id, "BAD_USE_BLK_TS", 0, 0);
+		return IOMEM_ERR_PTR(-EPROTO);
+	}
+
+	return payld;
+}
+
+static int
+scmi_telemetry_tdcf_de_parse(struct telemetry_de *tde,
+			     struct scmi_telemetry_de_sample *sample)
+{
+	int retries = SCMI_TLM_TDCF_MAX_RETRIES;
+	struct tdcf __iomem *tdcf = tde->base;
+	u32 startm = 0, endm = TDCF_BAD_END_SEQ;
+
+	if (!tdcf)
+		return -ENODEV;
+
+	do {
+		struct payload __iomem *payld;
+		int err;
+
+		/* A bit of exponential backoff between retries */
+		fsleep((SCMI_TLM_TDCF_MAX_RETRIES - retries) * 1000);
+
+		startm = TDCF_START_SEQ_GET(tdcf);
+		if (IS_BAD_START_SEQ(startm)) {
+			trace_scmi_tlm_access(tde->de.info->id, "MSEQ_BADSTART",
+					      startm, 0);
+			continue;
+		}
+
+		/* Return last readings if nothing changed */
+		err = scmi_telemetry_tde_cache_lookup(tde, sample, &startm);
+		if (!err)
+			return 0;
+
+		/* Retry also when payld get gave a transient error (-EINVAL) */
+		payld = scmi_telemetry_tdcf_de_payld_get(tde);
+		if (!IS_ERR(payld))
+			scmi_telemetry_line_data_parse(tde, sample, payld, startm);
+		else if (PTR_ERR(payld) != -EINVAL)
+			return PTR_ERR(payld);
+
+		endm = TDCF_END_SEQ_GET(tde->eplg);
+		if (startm != endm)
+			trace_scmi_tlm_access(tde->de.info->id, "MSEQ_MISMATCH",
+					      startm, endm);
+	} while (startm != endm && --retries);
+
+	if (startm != endm) {
+		trace_scmi_tlm_access(tde->de.info->id, "TDCF_DE_FAIL",
+				      startm, endm);
+		return -EPROTO;
+	}
+
+	return 0;
+}
+
+static int scmi_telemetry_de_access(struct telemetry_de *tde,
+				    struct scmi_telemetry_de_sample *sample)
+{
+	if (!tde->de.fc_support)
+		return scmi_telemetry_tdcf_de_parse(tde, sample);
+
+	scmi_telemetry_de_data_fc_read(tde, sample);
+
+	return 0;
+}
+
+static int scmi_telemetry_de_collect(struct telemetry_info *ti,
+				     struct scmi_telemetry_de *de,
+				     struct scmi_telemetry_de_sample *sample)
+{
+	struct telemetry_de *tde = to_tde(de);
+
+	if (!de->enabled)
+		return -ENODATA;
+
+	/*
+	 * DE readings returns cached values when:
+	 *  - DE data value was retrieved via notification/delayed_response
+	 */
+	if (tde->cached_msg)
+		return scmi_telemetry_tde_cache_lookup(tde, sample, NULL);
+
+	return scmi_telemetry_de_access(tde, sample);
+}
+
+static int scmi_telemetry_de_data_read(const struct scmi_protocol_handle *ph,
+				       struct scmi_telemetry_de_sample *sample)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+	struct scmi_telemetry_de *de;
+
+	if (!ti->info.enabled || !sample)
+		return -ENODATA;
+
+	de = xa_load(&ti->xa_des, sample->id);
+	if (!de)
+		return -ENOENT;
+
+	return scmi_telemetry_de_collect(ti, de, sample);
+}
+
+static int
+scmi_telemetry_samples_collect(struct telemetry_info *ti, int grp_id,
+			       int *num_samples,
+			       struct scmi_telemetry_de_sample *samples)
+{
+	struct scmi_telemetry_res_info *rinfo;
+	int max_samples;
+
+	max_samples = *num_samples;
+	*num_samples = 0;
+
+	rinfo = ti->res_get(ti);
+	for (int i = 0; i < rinfo->num_des; i++) {
+		struct scmi_telemetry_de *de;
+
+		de = rinfo->des[i];
+		/* Skip disabled DEs and not belonging to the selected Group */
+		if (!de->enabled ||
+		    (grp_id != SCMI_TLM_GRP_INVALID &&
+		     (!de->grp || de->grp->info->grp_id != grp_id)))
+			continue;
+
+		/* Must be checked here to skip disabled and non selected */
+		if (*num_samples == max_samples)
+			return -ENOSPC;
+
+		/* Note that this cannot fail when passing a NULL magic */
+		scmi_telemetry_tde_cache_lookup(to_tde(de),
+						&samples[(*num_samples)++], NULL);
+	}
+
+	return 0;
+}
+
+static int scmi_telemetry_des_bulk_read(const struct scmi_protocol_handle *ph,
+					int grp_id, int *num_samples,
+					struct scmi_telemetry_de_sample *samples)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+
+	if (!ti->info.enabled || !num_samples || !samples)
+		return -EINVAL;
+
+	/* Trigger a full SHMTIs & FCs scan */
+	scmi_telemetry_scan_update(ti);
+
+	/* Collect all last cached values */
+	return scmi_telemetry_samples_collect(ti, grp_id, num_samples, samples);
+}
+
+static void
+scmi_telemetry_msg_payld_process(struct telemetry_info *ti,
+				 unsigned int num_dwords, u32 *dwords,
+				 size_t payld_bytes)
+{
+	struct scmi_telemetry_res_info *rinfo;
+	u32 next = 0;
+
+	rinfo = ti->res_get(ti);
+	if (!rinfo->fully_enumerated) {
+		dev_warn_once(ti->ph->dev,
+			      "Cannot process DEs in message payload. Drop.\n");
+		return;
+	}
+
+	while (next < num_dwords) {
+		struct payload *payld = (struct payload *)&dwords[next];
+		struct scmi_telemetry_de_sample sample = {};
+		struct scmi_telemetry_de *de;
+		struct telemetry_de *tde;
+		unsigned int wlen;
+		u32 de_id;
+
+		wlen = LINE_LENGTH_WORDS_RAW(payld->meta);
+		/* Check Boundary */
+		if (next + wlen > payld_bytes / sizeof(u32))
+			return;
+
+		next += wlen;
+		if (DATA_INVALID_RAW(payld->meta)) {
+			trace_scmi_tlm_access(payld->id, "MSG_INVALID", 0, 0);
+			continue;
+		}
+
+		de_id = le32_to_cpu(payld->id);
+		de = xa_load(&ti->xa_des, de_id);
+		if (!de || !de->enabled) {
+			trace_scmi_tlm_access(de_id, de ? "MSG_DE_DISABLED" :
+					      "MSG_DE_UNKNOWN", 0, 0);
+			continue;
+		}
+
+		tde = to_tde(de);
+		scoped_guard(mutex, &tde->mtx) {
+			tde->cached_msg = true;
+			tde->last_val = LINE_DATA_GET_RAW(&payld->tsl);
+			/* TODO BLK_TS in notification payloads */
+			tde->last_ts = HAS_LINE_EXT_RAW(payld->meta) &&
+				LINE_TS_VALID_RAW(payld->meta) ?
+				LINE_TSTAMP_GET_RAW(&payld->tsl) : 0;
+			sample.val = tde->last_val;
+			sample.tstamp = tde->last_ts;
+		}
+
+		/* Trace originally read tstamp */
+		trace_scmi_tlm_collect(sample.tstamp, de->info->id, sample.val,
+				       "MESSAGE");
+
+		scmi_telemetry_tde_cache_update(tde, &sample, NULL);
+	}
+}
+
+static int scmi_telemetry_des_sample_get(const struct scmi_protocol_handle *ph,
+					 int grp_id, int *num_samples,
+					 struct scmi_telemetry_de_sample *samples)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+	struct scmi_msg_telemetry_config_set *msg;
+	struct scmi_xfer *t;
+	bool is_group;
+	u32 control;
+	int ret;
+
+	if (!ti->info.enabled || !num_samples || !samples)
+		return -EINVAL;
+
+	is_group = grp_id != SCMI_TLM_GRP_INVALID;
+	if (is_group && grp_id >= ti->info.base.num_groups)
+		return -EINVAL;
+
+	ret = ph->xops->xfer_get_init(ph, TELEMETRY_CONFIG_SET,
+				      sizeof(*msg), 0, &t);
+	if (ret)
+		return ret;
+
+	msg = t->tx.buf;
+	msg->grp_id = cpu_to_le32(grp_id);
+	control = TELEMETRY_ENABLE;
+	control |= !is_group ? TELEMETRY_SET_SELECTOR_ALL :
+		TELEMETRY_SET_SELECTOR_GROUP;
+	control |= TELEMETRY_MODE_SINGLE;
+	msg->control = cpu_to_le32(control);
+	msg->sampling_rate = 0;
+
+	ret = ph->xops->do_xfer_with_response(ph, t);
+	if (!ret) {
+		struct scmi_msg_resp_telemetry_reading_complete *r = t->rx.buf;
+
+		/* Update cached DEs values from payload */
+		if (r->num_dwords)
+			scmi_telemetry_msg_payld_process(ti, le32_to_cpu(r->num_dwords),
+							 (u32 *)r->dwords,
+							 t->rx.len - sizeof(*r));
+
+		/* Scan and update SMHTIs and FCs */
+		scmi_telemetry_scan_update(ti);
+
+		/* Collect all last cached values */
+		ret = scmi_telemetry_samples_collect(ti, grp_id, num_samples,
+						     samples);
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	return ret;
+}
+
+static void scmi_telemetry_local_resources_reset(struct telemetry_info *ti)
+{
+	struct scmi_telemetry_res_info *rinfo;
+
+	ti->info.enabled = false;
+	ti->info.notif_enabled = false;
+	ti->info.current_mode = SCMI_TLM_ONDEMAND;
+
+	/* Get rinfo as it is...without triggering an enumeration */
+	rinfo = __scmi_telemetry_resources_get(ti);
+	/* Clear all local state...*/
+	for (int i = 0; i < rinfo->num_des; i++) {
+		rinfo->des[i]->enabled = false;
+		rinfo->des[i]->tstamp_enabled = false;
+
+		scmi_telemetry_de_unlink(rinfo->des[i]);
+	}
+	for (int i = 0; i < rinfo->num_groups; i++) {
+		rinfo->grps[i].enabled = false;
+		rinfo->grps[i].tstamp_enabled = false;
+		rinfo->grps[i].current_mode = SCMI_TLM_ONDEMAND;
+		rinfo->grps[i].active_update_interval = 0;
+	}
+
+	atomic_set(&ti->des_enabled[ENA_STATE], 0);
+	atomic_set(&ti->des_enabled[ENA_TSTAMP], 0);
+}
+
+static int scmi_telemetry_reset(const struct scmi_protocol_handle *ph)
+{
+	struct scmi_xfer *t;
+	int ret;
+
+	ret = ph->xops->xfer_get_init(ph, TELEMETRY_RESET, sizeof(u32), 0, &t);
+	if (ret)
+		return ret;
+
+	put_unaligned_le32(0, t->tx.buf);
+	ret = ph->xops->do_xfer(ph, t);
+	if (!ret) {
+		struct telemetry_info *ti = ph->get_priv(ph);
+
+		scmi_telemetry_local_resources_reset(ti);
+
+		/* Reset generation now that server has been reset */
+		scmi_telemetry_generation_reset(ti);
+
+		/* Fetch again the states from platform. */
+		ret = scmi_telemetry_initial_state_lookup(ti);
+		if (ret)
+			dev_warn(ph->dev,
+				 FW_BUG "Cannot retrieve initial state after reset.\n");
+	}
+
+	ph->xops->xfer_put(ph, t);
+
+	return ret;
+}
+
+static struct wait_queue_head *
+scmi_telemetry_event_wq_get(const struct scmi_protocol_handle *ph)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+
+	return &ti->gen_wq;
+}
+
+static const struct scmi_telemetry_proto_ops tlm_proto_ops = {
+	.info_get = scmi_telemetry_info_get,
+	.de_lookup = scmi_telemetry_de_lookup,
+	.res_get = scmi_telemetry_resources_get,
+	.state_get = scmi_telemetry_state_get,
+	.state_set = scmi_telemetry_state_set,
+	.all_disable = scmi_telemetry_all_disable,
+	.collection_configure = scmi_telemetry_collection_configure,
+	.de_data_read = scmi_telemetry_de_data_read,
+	.des_bulk_read = scmi_telemetry_des_bulk_read,
+	.des_sample_get = scmi_telemetry_des_sample_get,
+	.reset = scmi_telemetry_reset,
+	.event_wq_get = scmi_telemetry_event_wq_get,
+};
+
+static bool
+scmi_telemetry_notify_supported(const struct scmi_protocol_handle *ph,
+				u8 evt_id, u32 src_id)
+{
+	struct telemetry_info *ti = ph->get_priv(ph);
+
+	return ti->info.continuos_update_support;
+}
+
+static int
+scmi_telemetry_set_notify_enabled(const struct scmi_protocol_handle *ph,
+				  u8 evt_id, u32 src_id, bool enable)
+{
+	return 0;
+}
+
+static void *
+scmi_telemetry_fill_custom_report(const struct scmi_protocol_handle *ph,
+				  u8 evt_id, ktime_t timestamp,
+				  const void *payld, size_t payld_sz,
+				  void *report, u32 *src_id)
+{
+	const struct scmi_telemetry_update_notify_payld *p = payld;
+	struct scmi_telemetry_update_report *r = report;
+
+	/* At least sized as an empty notification */
+	if (payld_sz < sizeof(*p))
+		return NULL;
+
+	r->timestamp = timestamp;
+	r->agent_id = le32_to_cpu(p->agent_id);
+	r->status = le32_to_cpu(p->status);
+	r->num_dwords = le32_to_cpu(p->num_dwords);
+
+	if (r->num_dwords * sizeof(r->dwords[0]) > payld_sz)
+		return NULL;
+
+	/*
+	 * Allocated dwords and report are sized as max_msg_size, so as
+	 * to allow for the maximum payload permitted by the configured
+	 * transport. Overflow is not possible since out-of-size messages
+	 * are dropped at the transport layer.
+	 */
+	if (r->num_dwords)
+		memcpy_from_le32(r->dwords, p->array, r->num_dwords);
+
+	*src_id = 0;
+
+	return r;
+}
+
+static const struct scmi_event tlm_events[] = {
+	{
+		.id = SCMI_EVENT_TELEMETRY_UPDATE,
+		.max_payld_sz = 0,
+		.max_report_sz = 0,
+	},
+};
+
+static const struct scmi_event_ops tlm_event_ops = {
+	.is_notify_supported = scmi_telemetry_notify_supported,
+	.set_notify_enabled = scmi_telemetry_set_notify_enabled,
+	.fill_custom_report = scmi_telemetry_fill_custom_report,
+};
+
+static const struct scmi_protocol_events tlm_protocol_events = {
+	.queue_sz = SCMI_PROTO_QUEUE_SZ,
+	.ops = &tlm_event_ops,
+	.evts = tlm_events,
+	.num_events = ARRAY_SIZE(tlm_events),
+	.num_sources = 1,
+};
+
+static int scmi_telemetry_notifier(struct notifier_block *nb,
+				   unsigned long event, void *data)
+{
+	struct scmi_telemetry_update_report *er = data;
+	struct telemetry_info *ti = telemetry_nb_to_info(nb);
+
+	if (er->status) {
+		trace_scmi_tlm_access(0, "BAD_NOTIF_MSG", 0, 0);
+		return NOTIFY_DONE;
+	}
+
+	trace_scmi_tlm_access(0, "TLM_UPDATE_MSG", 0, 0);
+	/* Lookup the embedded DEs in the notification payload ... */
+	if (er->num_dwords) {
+		size_t payld_bytes = sizeof(er->dwords[0]) * er->num_dwords;
+
+		/* The report payload size was bound checked on rx */
+		scmi_telemetry_msg_payld_process(ti, er->num_dwords, er->dwords,
+						 payld_bytes);
+	}
+
+	/* ...scan the SHMTI/FCs for any other DE updates. */
+	if (ti->streaming_mode)
+		scmi_telemetry_scan_update(ti);
+
+	return NOTIFY_OK;
+}
+
+/**
+ * scmi_telemetry_resources_alloc  - Resources allocation
+ * @ti: A reference to the telemetry info descriptor for this instance
+ *
+ * This allocates and initializes dedicated resources for the maximum possible
+ * number of needed telemetry resources, based on information gathered from
+ * the initial enumeration: these allocations represent an upper bound on
+ * the number of discoverable telemetry resources and they will be later
+ * populated during late deferred further discovery phases.
+ *
+ * Return: 0 on Success, errno otherwise
+ */
+static int scmi_telemetry_resources_alloc(struct telemetry_info *ti)
+{
+	/* Array to hold pointers to discovered DEs */
+	struct scmi_telemetry_de **des __free(kfree) =
+		kcalloc(ti->info.base.num_des, sizeof(*des), GFP_KERNEL);
+	if (!des)
+		return -ENOMEM;
+
+	/* The allocated DE descriptors */
+	struct telemetry_de *tdes __free(kfree) =
+		kcalloc(ti->info.base.num_des, sizeof(*tdes), GFP_KERNEL);
+	if (!tdes)
+		return -ENOMEM;
+
+	/* Allocate a set of contiguous DE info descriptors. */
+	struct scmi_telemetry_de_info *dei_store __free(kfree) =
+		kcalloc(ti->info.base.num_des, sizeof(*dei_store), GFP_KERNEL);
+	if (!dei_store)
+		return -ENOMEM;
+
+	/* Array to hold descriptors of discovered GROUPs */
+	struct scmi_telemetry_group *grps __free(kfree) =
+		kcalloc(ti->info.base.num_groups, sizeof(*grps), GFP_KERNEL);
+	if (!grps)
+		return -ENOMEM;
+
+	/* Allocate a set of contiguous Group info descriptors. */
+	struct scmi_telemetry_grp_info *grps_store __free(kfree) =
+		kcalloc(ti->info.base.num_groups, sizeof(*grps_store), GFP_KERNEL);
+	if (!grps_store)
+		return -ENOMEM;
+
+	struct scmi_telemetry_res_info *rinfo __free(kfree) =
+		kzalloc(sizeof(*rinfo), GFP_KERNEL);
+	if (!rinfo)
+		return -ENOMEM;
+
+	mutex_init(&ti->free_mtx);
+	INIT_LIST_HEAD(&ti->free_des);
+	for (int i = 0; i < ti->info.base.num_des; i++) {
+		mutex_init(&tdes[i].mtx);
+		/* Bind contiguous DE info structures */
+		tdes[i].de.info = &dei_store[i];
+		list_add_tail(&tdes[i].item, &ti->free_des);
+	}
+
+	for (int i = 0; i < ti->info.base.num_groups; i++) {
+		grps_store[i].grp_id = i;
+		/* Bind contiguous Group info struct */
+		grps[i].info = &grps_store[i];
+	}
+
+	INIT_LIST_HEAD(&ti->fcs_des);
+
+	ti->tdes = no_free_ptr(tdes);
+
+	rinfo->des = no_free_ptr(des);
+	rinfo->dei_store = no_free_ptr(dei_store);
+	rinfo->grps = no_free_ptr(grps);
+	rinfo->grps_store = no_free_ptr(grps_store);
+
+	ti->rinfo = no_free_ptr(rinfo);
+
+	return 0;
+}
+
+static void scmi_telemetry_groups_free(struct scmi_telemetry_res_info *rinfo)
+{
+	for (int i = 0; i < rinfo->num_groups; i++) {
+		struct scmi_telemetry_group *grp = &rinfo->grps[i];
+
+		kfree(grp->des);
+		kfree(grp->des_str);
+		kfree(grp->intervals);
+	}
+}
+
+static void scmi_telemetry_resources_free(void *arg)
+{
+	struct telemetry_info *ti = arg;
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+
+	/*
+	 * Unlinking all the BLK_TS/UUID lines related to a DE triggers also
+	 * the deallocation of such lines when the embedded refcount hits zero.
+	 */
+	for (int i = 0; i < rinfo->num_des; i++)
+		scmi_telemetry_de_unlink(rinfo->des[i]);
+
+	xa_destroy(&ti->xa_des);
+	xa_destroy(&ti->xa_lines);
+	kfree(ti->tdes);
+	kfree(rinfo->des);
+	kfree(rinfo->dei_store);
+	scmi_telemetry_groups_free(rinfo);
+	kfree(rinfo->grps);
+	kfree(rinfo->grps_store);
+
+	kfree(rinfo);
+
+	ti->rinfo = NULL;
+}
+
+static struct scmi_telemetry_res_info *
+__scmi_telemetry_resources_get(struct telemetry_info *ti)
+{
+	return ti->rinfo;
+}
+
+/**
+ * scmi_telemetry_resources_enumerate  - Enumeration helper
+ * @ti: A reference to the telemetry info descriptor for this instance
+ *
+ * This helper is configured to be called once on the first enumeration
+ * attempt, when triggered by invoking ti->res_get() from somewhere else.
+ * Once run it substitues itself in ti->res_get() with the simple accessor
+ * __scmi_telemetry_resources_get, which returns a descriptor to the resources
+ * that were possibly discovered.
+ *
+ * Note that, while it attempts to fully enumerate Data Events and Groups, it
+ * does NOT fail when such enumerations fail, instead it simply gives up with
+ * the end result that only a partially populated, but consistent, resources
+ * descriptor will be returned; in such a case the incomplete descriptor will
+ * be marked as NOT fully_enumerated: this design enables the kernel to deal
+ * with badly implemented out-of-spec firmware support while keep on providing
+ * a minimal sane, albeit possibly incomplete, set of telemetry respources.
+ *
+ * Return: A reference to a fully or partially populated resources descriptor
+ */
+static struct scmi_telemetry_res_info *
+scmi_telemetry_resources_enumerate(struct telemetry_info *ti)
+{
+	struct scmi_telemetry_res_info *rinfo = ti->rinfo;
+	struct device *dev = ti->ph->dev;
+	int ret;
+
+	/*
+	 * Ensure this init function can be called only once and
+	 * handles properly concurrent calls.
+	 */
+	if (atomic_cmpxchg(&ti->rinfo_initializing, 0, 1)) {
+		if (!completion_done(&ti->rinfo_initdone))
+			wait_for_completion(&ti->rinfo_initdone);
+		goto out;
+	}
+
+	ret = scmi_telemetry_de_descriptors_get(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot fully enumerate DEs resources. Degraded system.\n");
+		goto done;
+	}
+
+	ret = scmi_telemetry_enumerate_groups_intervals(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot fully enumerate group intervals. Degraded system.\n");
+		goto done;
+	}
+
+	/* If we got here, the enumeration was fully successful */
+	rinfo->fully_enumerated = true;
+done:
+	/* Disable initialization permanently */
+	smp_store_mb(ti->res_get, __scmi_telemetry_resources_get);
+	complete_all(&ti->rinfo_initdone);
+
+out:
+	return rinfo;
+}
+
+/**
+ * scmi_telemetry_instance_init  - Instance initializer
+ * @ti: A reference to the telemetry info descriptor for this instance
+ *
+ * Note that this allocates and initialize all the resources possibly needed
+ * and then setups the @scmi_telemetry_resources_enumerate helper as the
+ * default method for the first call to ti->res_get(): this mechanism enables
+ * the possibility of optionally implementing deferred enumeration policies
+ * which optionally delay the discovery phase and related SCMI message exchanges
+ * to a later point in time.
+ *
+ * Return: 0 on Success, errno otherwise
+ */
+static int scmi_telemetry_instance_init(struct telemetry_info *ti)
+{
+	int ret;
+
+	/* Allocate and Initialize on first call... */
+	ret = scmi_telemetry_resources_alloc(ti);
+	if (ret)
+		return ret;
+
+	xa_init(&ti->xa_des);
+	xa_init(&ti->xa_lines);
+	ret = devm_add_action_or_reset(ti->ph->dev,
+				       scmi_telemetry_resources_free, ti);
+	if (ret)
+		return ret;
+
+	/* Generation counter init */
+	atomic_set(&ti->info.generation, SCMI_TLM_GENERATION_ONE);
+	init_waitqueue_head(&ti->gen_wq);
+	atomic_set(&ti->des_enabled[ENA_STATE], 0);
+	atomic_set(&ti->des_enabled[ENA_TSTAMP], 0);
+	/* Setup resources lazy initialization */
+	atomic_set(&ti->rinfo_initializing, 0);
+	init_completion(&ti->rinfo_initdone);
+	/* Ensure the new res_get() operation is visible after this point */
+	smp_store_mb(ti->res_get, scmi_telemetry_resources_enumerate);
+
+	return 0;
+}
+
+static int scmi_telemetry_protocol_init(const struct scmi_protocol_handle *ph)
+{
+	struct device *dev = ph->dev;
+	struct telemetry_info *ti;
+	int ret;
+
+	dev_dbg(dev, "Telemetry Version %d.%d\n",
+		PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version));
+
+	ti = devm_kzalloc(dev, sizeof(*ti), GFP_KERNEL);
+	if (!ti)
+		return -ENOMEM;
+
+	ti->ph = ph;
+
+	ret = scmi_telemetry_protocol_attributes_get(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot retrieve protocol attributes. Abort.\n");
+		return ret;
+	}
+
+	ret = scmi_telemetry_instance_init(ti);
+	if (ret) {
+		dev_err(dev, "Cannot initialize instance. Abort.\n");
+		return ret;
+	}
+
+	ret = scmi_telemetry_enumerate_common_intervals(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot enumerate update intervals. Abort.\n");
+		return ret;
+	}
+
+	ret = scmi_telemetry_enumerate_shmti(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot enumerate SHMTIs. Abort.\n");
+		return ret;
+	}
+
+	ret = scmi_telemetry_initial_state_lookup(ti);
+	if (ret) {
+		dev_err(dev, FW_BUG "Cannot retrieve initial state. Abort.\n");
+		return ret;
+	}
+
+	ti->info.base.version = ph->version;
+
+	ret = ph->set_priv(ph, ti);
+	if (ret)
+		return ret;
+
+	/*
+	 * Register a notifier anyway straight upon protocol initialization
+	 * since there could be some DEs that are ONLY reported by notifications
+	 * even though the chosen collection method was SHMTI/FCs.
+	 */
+	if (ti->info.continuos_update_support) {
+		ti->telemetry_nb.notifier_call = &scmi_telemetry_notifier;
+		ret = ph->instance_notifier_register(ph, SCMI_EVENT_TELEMETRY_UPDATE,
+						     NULL, &ti->telemetry_nb);
+		if (ret) {
+			dev_err(ph->dev,
+				"Could NOT register Telemetry notifier\n");
+			return ret;
+		}
+	}
+
+	if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_PROTOCOLS))
+		scmi_telemetry_debugfs_initialize(ti);
+
+	return 0;
+}
+
+static const struct scmi_protocol scmi_telemetry = {
+	.id = SCMI_PROTOCOL_TELEMETRY,
+	.owner = THIS_MODULE,
+	.instance_init = &scmi_telemetry_protocol_init,
+	.ops = &tlm_proto_ops,
+	.events = &tlm_protocol_events,
+	.supported_version = SCMI_PROTOCOL_SUPPORTED_VERSION,
+};
+
+DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(telemetry, scmi_telemetry)
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index 5ab73b1ab9aa4f..8dc65de424481d 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -2,16 +2,18 @@
 /*
  * SCMI Message Protocol driver header
  *
- * Copyright (C) 2018-2021 ARM Ltd.
+ * Copyright (C) 2018-2026 ARM Ltd.
  */
 
 #ifndef _LINUX_SCMI_PROTOCOL_H
 #define _LINUX_SCMI_PROTOCOL_H
 
 #include <linux/bitfield.h>
+#include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/notifier.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 
 #define SCMI_MAX_STR_SIZE		64
 #define SCMI_SHORT_NAME_MAX_SIZE	16
@@ -824,6 +826,230 @@ struct scmi_pinctrl_proto_ops {
 	int (*pin_free)(const struct scmi_protocol_handle *ph, u32 pin);
 };
 
+enum scmi_telemetry_de_type {
+	SCMI_TLM_DE_TYPE_USPECIFIED,
+	SCMI_TLM_DE_TYPE_ACCUMUL_IDLE_RESIDENCY,
+	SCMI_TLM_DE_TYPE_ACCUMUL_IDLE_COUNTS,
+	SCMI_TLM_DE_TYPE_ACCUMUL_OTHERS,
+	SCMI_TLM_DE_TYPE_INSTA_IDLE_STATE,
+	SCMI_TLM_DE_TYPE_INSTA_OTHERS,
+	SCMI_TLM_DE_TYPE_AVERAGE,
+	SCMI_TLM_DE_TYPE_STATUS,
+	SCMI_TLM_DE_TYPE_RESERVED_START,
+	SCMI_TLM_DE_TYPE_RESERVED_END = 0xef,
+	SCMI_TLM_DE_TYPE_OEM_START = 0xf0,
+	SCMI_TLM_DE_TYPE_OEM_END = 0xff,
+};
+
+enum scmi_telemetry_compo_type {
+	SCMI_TLM_COMPO_TYPE_USPECIFIED,
+	SCMI_TLM_COMPO_TYPE_CPU,
+	SCMI_TLM_COMPO_TYPE_CLUSTER,
+	SCMI_TLM_COMPO_TYPE_GPU,
+	SCMI_TLM_COMPO_TYPE_NPU,
+	SCMI_TLM_COMPO_TYPE_INTERCONNECT,
+	SCMI_TLM_COMPO_TYPE_MEM_CNTRL,
+	SCMI_TLM_COMPO_TYPE_L1_CACHE,
+	SCMI_TLM_COMPO_TYPE_L2_CACHE,
+	SCMI_TLM_COMPO_TYPE_L3_CACHE,
+	SCMI_TLM_COMPO_TYPE_LL_CACHE,
+	SCMI_TLM_COMPO_TYPE_SYS_CACHE,
+	SCMI_TLM_COMPO_TYPE_DISP_CNTRL,
+	SCMI_TLM_COMPO_TYPE_IPU,
+	SCMI_TLM_COMPO_TYPE_CHIPLET,
+	SCMI_TLM_COMPO_TYPE_PACKAGE,
+	SCMI_TLM_COMPO_TYPE_SOC,
+	SCMI_TLM_COMPO_TYPE_SYSTEM,
+	SCMI_TLM_COMPO_TYPE_SMCU,
+	SCMI_TLM_COMPO_TYPE_ACCEL,
+	SCMI_TLM_COMPO_TYPE_BATTERY,
+	SCMI_TLM_COMPO_TYPE_CHARGER,
+	SCMI_TLM_COMPO_TYPE_PMIC,
+	SCMI_TLM_COMPO_TYPE_BOARD,
+	SCMI_TLM_COMPO_TYPE_MEMORY,
+	SCMI_TLM_COMPO_TYPE_PERIPH,
+	SCMI_TLM_COMPO_TYPE_PERIPH_SUBC,
+	SCMI_TLM_COMPO_TYPE_LID,
+	SCMI_TLM_COMPO_TYPE_DISPLAY,
+	SCMI_TLM_COMPO_TYPE_RESERVED_START = 0x1d,
+	SCMI_TLM_COMPO_TYPE_RESERVED_END = 0xdf,
+	SCMI_TLM_COMPO_TYPE_OEM_START = 0xe0,
+	SCMI_TLM_COMPO_TYPE_OEM_END = 0xff,
+};
+
+#define	SCMI_TLM_GET_UPDATE_INTERVAL_SECS(x)	(FIELD_GET(GENMASK(20, 5), (x)))
+#define SCMI_TLM_GET_UPDATE_INTERVAL_EXP(x)	(sign_extend32((x), 4))
+
+#define SCMI_TLM_GET_UPDATE_INTERVAL(x)		(FIELD_GET(GENMASK(20, 0), (x)))
+#define SCMI_TLM_BUILD_UPDATE_INTERVAL(s, e)				    \
+	(FIELD_PREP(GENMASK(20, 5), (s)) | FIELD_PREP(GENMASK(4, 0), (e)))
+
+enum scmi_telemetry_collection {
+	SCMI_TLM_ONDEMAND,
+	SCMI_TLM_NOTIFICATION,
+	SCMI_TLM_SINGLE_READ,
+};
+
+#define SCMI_TLM_GENERATION_INVALID	0U
+#define SCMI_TLM_GRP_INVALID		0xFFFFFFFF
+#define SCMI_TLM_DE_IMPL_MAX_DWORDS	4
+
+struct scmi_telemetry_intervals {
+	unsigned int grp_id;
+	bool discrete;
+	unsigned int num_intervals;
+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_LOW	0
+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_HIGH	1
+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_STEP	2
+	unsigned int update_intervals[] __counted_by(num_intervals);
+};
+
+struct scmi_telemetry_grp_info {
+	unsigned int grp_id;
+	unsigned int num_des;
+	unsigned int num_intervals;
+};
+
+struct scmi_telemetry_group {
+	bool enabled;
+	bool tstamp_enabled;
+	unsigned int *des;
+	char *des_str;
+	struct scmi_telemetry_grp_info *info;
+	unsigned int active_update_interval;
+	struct scmi_telemetry_intervals *intervals;
+	enum scmi_telemetry_collection current_mode;
+};
+
+struct scmi_telemetry_de_info {
+	unsigned int id;
+	unsigned int grp_id;
+	unsigned int data_sz;
+	unsigned int type;
+	unsigned int unit;
+	int unit_exp;
+	unsigned int ts_rate;
+	unsigned int instance_id;
+	unsigned int compo_instance_id;
+	unsigned int compo_type;
+	bool persistent;
+	char name[16];
+};
+
+struct scmi_telemetry_de {
+	bool tstamp_support;
+	bool fc_support;
+	bool name_support;
+	struct scmi_telemetry_de_info *info;
+	struct scmi_telemetry_group *grp;
+	bool enabled;
+	bool tstamp_enabled;
+};
+
+struct scmi_telemetry_res_info {
+	bool fully_enumerated;
+	unsigned int num_des;
+	struct scmi_telemetry_de **des;
+	struct scmi_telemetry_de_info *dei_store;
+	unsigned int num_groups;
+	struct scmi_telemetry_group *grps;
+	struct scmi_telemetry_grp_info *grps_store;
+};
+
+struct scmi_telemetry_base_info {
+	unsigned int version;
+	unsigned int de_impl_version[SCMI_TLM_DE_IMPL_MAX_DWORDS];
+	unsigned int num_des;
+	unsigned int num_groups;
+	unsigned int num_intervals;
+	unsigned int num_shmtis;
+};
+
+struct scmi_telemetry_shmti_info {
+	unsigned int sid;
+	unsigned int len;
+	unsigned long offset;
+	phys_addr_t phys;
+};
+
+struct scmi_telemetry_info {
+	bool single_read_support;
+	bool continuos_update_support;
+	bool per_group_config_support;
+	bool reset_support;
+	bool fc_support;
+	struct scmi_telemetry_base_info base;
+	unsigned int active_update_interval;
+	struct scmi_telemetry_intervals *intervals;
+	struct scmi_telemetry_shmti_info **shmtis;
+	bool enabled;
+	bool notif_enabled;
+	enum scmi_telemetry_collection current_mode;
+	atomic_t generation;
+};
+
+struct scmi_telemetry_de_sample {
+	unsigned int id;
+	unsigned int pad;
+	unsigned long long tstamp;
+	unsigned long long val;
+};
+
+/**
+ * struct scmi_telemetry_proto_ops - represents the various operations provided
+ *	by SCMI Telemetry Protocol
+ *
+ * @info_get: get the general Telemetry information.
+ * @de_lookup: get a specific DE descriptor from the DE id.
+ * @res_get: get a reference to the Telemetry resources descriptor.
+ * @state_get: retrieve the specific DE or GROUP state, if NULL returns the
+ *	       cumulative state of all DEs.
+ * @state_set: enable/disable the specific DE or GROUP with or without timestamps.
+ * @all_disable: disable ALL DEs or GROUPs.
+ * @collection_configure: choose a sampling rate and enable SHMTI/FC sampling
+ *			  for on demand collection via @de_data_read or async
+ *			  notificatioins for all the enabled DEs.
+ * @de_data_read: on-demand read of a single DE and related optional timestamp:
+ *		  the value will be retrieved at the proper SHMTI offset OR
+ *		  from the dedicated FC area (if supported by that DE).
+ * @des_bulk_read: on-demand read of all the currently enabled DEs, or just
+ *		   the ones belonging to a specific group when provided.
+ * @des_sample_get: on-demand read of all the currently enabled DEs, or just
+ *		    the ones belonging to a specific group when provided.
+ *		    This causes an immediate update platform-side of all the
+ *		    enabled DEs.
+ * @reset: reset configuration and telemetry data.
+ * @event_wq_get: get a reference to the event waitqueue for this instance.
+ */
+struct scmi_telemetry_proto_ops {
+	const struct scmi_telemetry_info __must_check *(*info_get)
+		(const struct scmi_protocol_handle *ph);
+	const struct scmi_telemetry_de __must_check *(*de_lookup)
+		(const struct scmi_protocol_handle *ph, u32 id);
+	const struct scmi_telemetry_res_info __must_check *(*res_get)
+		(const struct scmi_protocol_handle *ph);
+	int (*state_get)(const struct scmi_protocol_handle *ph,
+			 const u32 *id, bool *enabled, bool *tstamp_enabled);
+	int (*state_set)(const struct scmi_protocol_handle *ph,
+			 bool is_group, u32 id, const bool *enable,
+			 const bool *tstamp);
+	int (*all_disable)(const struct scmi_protocol_handle *ph, bool group);
+	int (*collection_configure)(const struct scmi_protocol_handle *ph,
+				    unsigned int res_id, const bool *enable,
+				    const unsigned int *update_interval_ms,
+				    const enum scmi_telemetry_collection *mode);
+	int __must_check (*de_data_read)(const struct scmi_protocol_handle *ph,
+					 struct scmi_telemetry_de_sample *sample);
+	int __must_check (*des_bulk_read)(const struct scmi_protocol_handle *ph,
+					  int grp_id, int *num_samples,
+					  struct scmi_telemetry_de_sample *samples);
+	int __must_check (*des_sample_get)(const struct scmi_protocol_handle *ph,
+					   int grp_id, int *num_samples,
+					   struct scmi_telemetry_de_sample *samples);
+	int (*reset)(const struct scmi_protocol_handle *ph);
+	struct wait_queue_head *(*event_wq_get)(const struct scmi_protocol_handle *ph);
+};
+
 /**
  * struct scmi_notify_ops  - represents notifications' operations provided by
  * SCMI core
@@ -884,6 +1110,10 @@ struct scmi_notify_ops {
 /**
  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
  *
+ * @id: A unique positive natural integer identifying the SCMI Instance
+ *	associated with this handle to be used across all drivers for
+ *	naming purposes: same identifier used internally as the root for
+ *	the debugfs per-instance tree.
  * @dev: pointer to the SCMI device
  * @version: pointer to the structure containing SCMI version information
  * @devm_protocol_acquire: devres managed method to get hold of a protocol,
@@ -904,6 +1134,7 @@ struct scmi_notify_ops {
  * @notify_ops: pointer to set of notifications related operations
  */
 struct scmi_handle {
+	unsigned int id;
 	struct device *dev;
 	struct scmi_base_info *version;
 
@@ -915,7 +1146,6 @@ struct scmi_handle {
 	void (*devm_protocol_put)(struct scmi_device *sdev, u8 proto);
 	bool (*is_transport_atomic)(const struct scmi_handle *handle,
 				    unsigned int *atomic_threshold);
-
 	const struct scmi_notify_ops *notify_ops;
 };
 
@@ -930,6 +1160,7 @@ enum scmi_std_protocol {
 	SCMI_PROTOCOL_VOLTAGE = 0x17,
 	SCMI_PROTOCOL_POWERCAP = 0x18,
 	SCMI_PROTOCOL_PINCTRL = 0x19,
+	SCMI_PROTOCOL_TELEMETRY = 0x1b,
 };
 
 enum scmi_system_events {
@@ -1028,6 +1259,7 @@ enum scmi_notification_events {
 	SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
 	SCMI_EVENT_POWERCAP_CAP_CHANGED = 0x0,
 	SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED = 0x1,
+	SCMI_EVENT_TELEMETRY_UPDATE = 0x0,
 };
 
 struct scmi_power_state_changed_report {
@@ -1115,4 +1347,12 @@ struct scmi_powercap_meas_changed_report {
 	unsigned int	domain_id;
 	unsigned int	power;
 };
+
+struct scmi_telemetry_update_report {
+	ktime_t		timestamp;
+	unsigned int	agent_id;
+	int		status;
+	unsigned int	num_dwords;
+	unsigned int	dwords[];
+};
 #endif /* _LINUX_SCMI_PROTOCOL_H */
diff --git a/include/trace/events/scmi.h b/include/trace/events/scmi.h
index 703b7bb68e4429..b70b26e467b8db 100644
--- a/include/trace/events/scmi.h
+++ b/include/trace/events/scmi.h
@@ -7,7 +7,8 @@
 
 #include <linux/tracepoint.h>
 
-#define TRACE_SCMI_MAX_TAG_LEN	6
+#define TRACE_SCMI_MAX_TAG_LEN		6
+#define TRACE_SCMI_TLM_MAX_TAG_LEN	16
 
 TRACE_EVENT(scmi_fc_call,
 	TP_PROTO(u8 protocol_id, u8 msg_id, u32 res_id, u32 val1, u32 val2),
@@ -180,6 +181,51 @@ TRACE_EVENT(scmi_msg_dump,
 		  __entry->tag, __entry->msg_id, __entry->seq, __entry->status,
 		__print_hex_str(__get_dynamic_array(cmd), __entry->len))
 );
+
+TRACE_EVENT(scmi_tlm_access,
+	TP_PROTO(u64 de_id, unsigned char *tag, u64 startm, u64 endm),
+	TP_ARGS(de_id, tag, startm, endm),
+
+	TP_STRUCT__entry(
+		__field(u64, de_id)
+		__array(char, tag, TRACE_SCMI_TLM_MAX_TAG_LEN)
+		__field(u64, startm)
+		__field(u64, endm)
+	),
+
+	TP_fast_assign(
+		__entry->de_id = de_id;
+		strscpy(__entry->tag, tag, TRACE_SCMI_TLM_MAX_TAG_LEN);
+		__entry->startm = startm;
+		__entry->endm = endm;
+	),
+
+	TP_printk("de_id=0x%llX [%s] - startm=%016llX endm=%016llX",
+		  __entry->de_id, __entry->tag, __entry->startm, __entry->endm)
+);
+
+TRACE_EVENT(scmi_tlm_collect,
+	TP_PROTO(u64 ts, u64 de_id, u64 value, unsigned char *tag),
+	TP_ARGS(ts, de_id, value, tag),
+
+	TP_STRUCT__entry(
+		__field(u64, ts)
+		__field(u64, de_id)
+		__field(u64, value)
+		__array(char, tag, TRACE_SCMI_TLM_MAX_TAG_LEN)
+	),
+
+	TP_fast_assign(
+		__entry->ts = ts;
+		__entry->de_id = de_id;
+		__entry->value = value;
+		strscpy(__entry->tag, tag, TRACE_SCMI_TLM_MAX_TAG_LEN);
+	),
+
+	TP_printk("ts=%llu  de_id=0x%04llX  value=%016llu [%s]",
+		  __entry->ts, __entry->de_id, __entry->value, __entry->tag)
+);
+
 #endif /* _TRACE_SCMI_H */
 
 /* This part must be outside protection */
diff --git a/include/uapi/linux/scmi.h b/include/uapi/linux/scmi.h
new file mode 100644
index 00000000000000..3684d390be0666
--- /dev/null
+++ b/include/uapi/linux/scmi.h
@@ -0,0 +1,373 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2026 ARM Ltd.
+ */
+#ifndef _UAPI_LINUX_SCMI_H
+#define _UAPI_LINUX_SCMI_H
+
+/*
+ * Userspace interface SCMI Telemetry
+ */
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+#define SCMI_TLM_ABI_VERSION_V1			1
+#define SCMI_TLM_CURRENT_ABI_VERSION		SCMI_TLM_ABI_VERSION_V1
+
+#define SCMI_TLM_DE_IMPL_UUID_MAX	16
+
+/**
+ * struct scmi_tlm_abi_info - Basic information on the ABI/instance
+ *
+ * @size: sizeof this structure
+ * @abi_version: ABI Version
+ * @abi_features: ABI capabilities bitmap
+ * @de_impl_version: SCMI Telemetry DE implementation revision
+ * @num_des: Number of defined DEs
+ * @num_groups: Number of defined DEs groups
+ * @num_intervals: Number of available update intervals (instance-level)
+ * @num_shmtis: Number of discovered SHMTI areas
+ * @features: Instance specific SCMI feature-support bitmap
+ * @reserved: Some room for future expansion without the need to resize
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_ABI_INFO
+ */
+struct scmi_tlm_abi_info {
+	__u32 size;
+	__u32 abi_version;
+	__u32 abi_features;
+#define SCMI_TLM_ABI_FEAT_RESET				(1 << 0)
+	__u8 de_impl_version[SCMI_TLM_DE_IMPL_UUID_MAX];
+	__u32 num_des;
+	__u32 num_groups;
+	__u32 num_intervals;
+	__u32 num_shmtis;
+	__u32 features;
+#define SCMI_TLM_BASE_SUPPORT_RESET			(1 << 0)
+#define SCMI_TLM_BASE_SUPPORT_SINGLE_SAMPLE		(1 << 1)
+#define SCMI_TLM_BASE_SUPPORT_GROUP_CONFIG		(1 << 2)
+#define SCMI_TLM_BASE_SUPPORT_UPDATE_NOTIFICATION	(1 << 3)
+	__u64 reserved;
+};
+
+/**
+ * struct scmi_tlm_update_interval  - Update interval descriptor
+ *
+ * @secs: integer representing seconds
+ * @exp: signed integer representing the base 10 exponent used as a multiplier
+ *	 with @secs to represent the interval
+ *
+ * The resulting update interval is calculated as: <secs> * 10 ^ <exp>
+ */
+struct scmi_tlm_update_interval {
+	__u32 secs;
+	__s32 exp;
+};
+
+/**
+ * struct scmi_tlm_config  - Whole instance or group configuration
+ *
+ * @enable: Enable/Disable Telemetry for the whole instance or the group
+ * @t_enable: Enable/Disable timestamping for all the DEs belonging to a group
+ * @flags: Bitmask to represent special characteristics
+ * @pad: Padding fields to enforce alignment
+ * @grp_id: Identifier of the target group upon which this configuration will
+ *	    be applied: ignored if not marked as a group in @flags
+ * @active: Get/Set currently active update interval for the whole instance or
+ *	    a group
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_CFG
+ *	WO - SCMI_TLM_SET_CFG
+ */
+struct scmi_tlm_config {
+	__u8 enable;
+	__u8 t_enable;
+	__u8 flags;
+#define SCMI_TLM_CONFIG_GROUP		(1 << 0)
+#define SCMI_TLM_CONFIG_FLAGS		(SCMI_TLM_CONFIG_GROUP)
+#define SCMI_TLM_CONFIG_IS_GROUP(f)	((f) & SCMI_TLM_CONFIG_GROUP)
+	__u8 pad;
+	__u32 grp_id;
+	struct scmi_tlm_update_interval active;
+};
+
+/**
+ * struct scmi_tlm_intervals  - Update intervals descriptor
+ *
+ * @grp_id: Identifier of the target group upon which this configuration
+ *	    will be applied: ignored if not marked as a group in @flags
+ * @flags: Bitmask to represent special characteristics. When the interval
+ *	   is NOT marked as SCMI_TLM_INTERV_DISCRETE, @intervals will
+ *	   contain a triplet: min/max/step
+ * @pad: Padding fields to enforce alignment
+ * @num_intervals: Number of entries of @intervals
+ * @pad2: Padding fields to enforce alignment
+ * @intervals: A pointer to an array of struct scmi_tlm_update_interval
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_INTRVS
+ */
+struct scmi_tlm_intervals {
+	__u32 grp_id;
+	__u8 flags;
+#define SCMI_TLM_INTERV_GROUP	(1 << 0)
+#define SCMI_TLM_INTERV_DISCRETE	(1 << 1)
+#define SCMI_TLM_INTERV_FLAGS					\
+	(SCMI_TLM_INTERV_GROUP | SCMI_TLM_INTERV_DISCRETE)
+#define SCMI_TLM_INTERV_IS_GROUP(f)	((f) & SCMI_TLM_INTERV_GROUP)
+	__u8 pad[3];
+	__u32 num_intervals;
+	__u32 pad2;
+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_LOW	0
+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_HIGH	1
+#define SCMI_TLM_UPDATE_INTVL_SEGMENT_STEP	2
+	__u64 intervals;
+};
+
+/**
+ * struct scmi_tlm_de_config  - DE configuration
+ *
+ * @id: Identifier of the DE to act upon (ignored by SCMI_TLM_GET/SET_ALL_CFG)
+ * @enable: A boolean to enable/disable the DE
+ * @t_enable: A boolean to enable/disable the timestamp for this DE
+ *	      (if supported)
+ * @pad: Padding fields to enforce alignment
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_DE_CFG
+ *	RW - SCMI_TLM_SET_DE_CFG
+ *	RW - SCMI_TLM_GET_ALL_CFG
+ *	RW - SCMI_TLM_SET_ALL_CFG
+ */
+struct scmi_tlm_de_config {
+	__u32 id;
+	__u32 enable;
+	__u32 t_enable;
+	__u32 pad;
+};
+
+/**
+ * struct scmi_tlm_de_info  - DataEvent Descriptor
+ *
+ * @id: DE identifier
+ * @grp_id: Identifier of the group which this DE belongs to; valid only if
+ *	    this DE is marked as belonging to a group in @flags.
+ * @data_sz: DE data size in bytes
+ * @type: DE type
+ * @unit: DE unit of measurements
+ * @unit_exp: Power-of-10 multiplier for DE unit
+ * @ts_rate: Clock rate in kHz used to generate the DE timestamp
+ * @instance_id: DE instance ID
+ * @compo_instance_id: DE component instance ID
+ * @compo_type: Type of component which is associated to this DE
+ * @persistent: Data value for this DE survives reboot (non-cold ones)
+ * @flags: Bitmask to represent special characteristics
+ * @pad: Padding fields to enforce alignment
+ * @pad2: Padding fields to enforce alignment
+ * @name: Name of this DE
+ *
+ * Used to get the full description of a DE: it reflects DE Descriptors
+ * definitions in SCMI V4.0 specification at 3.12.4.6.
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_DE_INFO
+ */
+struct scmi_tlm_de_info {
+	__u32 id;
+	__u32 grp_id;
+	__u32 data_sz;
+	__u32 type;
+	__u32 unit;
+	__s32 unit_exp;
+	__u32 ts_rate;
+	__u32 instance_id;
+	__u32 compo_instance_id;
+	__u32 compo_type;
+	__u8 persistent;
+	__u8 flags;
+#define SCMI_TLM_DEINFO_GROUP		(1 << 0)
+#define SCMI_TLM_DEINFO_FLAGS		(SCMI_TLM_DEINFO_GROUP)
+#define SCMI_TLM_DEINFO_HAS_GROUP(f)	((f) & SCMI_TLM_DEINFO_GROUP)
+	__u8 pad[2];
+	__u32 pad2;
+	__u8 name[16];
+};
+
+/**
+ * struct scmi_tlm_des_list  - List of all defined DEs
+ *
+ * @num_des: Number of entries in @des
+ * @pad: Padding fields to enforce alignment
+ * @des: A reference to an array containing struct scmi_tlm_de_info
+ *	 descriptors for all the existent DEs
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_DE_LIST
+ */
+struct scmi_tlm_des_list {
+	__u32 num_des;
+	__u32 pad;
+	__u64 des;
+};
+
+/**
+ * struct scmi_tlm_de_sample - A DataEvent reading
+ *
+ * @id: DE identifier
+ * @pad: Padding fields to enforce alignment.
+ * @tstamp: DE reading timestamp (0 if timestamp NOT supported)
+ * @val: Reading of the DE data value
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_DE_VALUE
+ */
+struct scmi_tlm_de_sample {
+	__u32 id;
+	__u32 pad;
+	__u64 tstamp;
+	__u64 val;
+};
+
+/**
+ * struct scmi_tlm_data_read - Bulk read of a number of DataEvents
+ *
+ * @grp_id: Optional group ID number, ignored if not marked as a group request
+ *	    in @flags and not supported by SCMI_TLM_BATCH_READ
+ * @flags: Bitmask to represent special characteristics
+ * @pad: Padding fields to enforce alignment
+ * @pad2: Padding fields to enforce alignment
+ * @num_samples: Number of entries returned in @samples
+ * @samples: A reference to an array of struct scmi_tlm_de_sample containing
+ *	     an entry for each DE
+ *
+ * Used by:
+ *	RW - SCMI_TLM_SINGLE_SAMPLE
+ *	RW - SCMI_TLM_BULK_READ
+ *	RW - SCMI_TLM_BATCH_READ
+ */
+struct scmi_tlm_data_read {
+	__u32 grp_id;
+	__u8 flags;
+#define SCMI_TLM_READ_GROUP		(1 << 0)
+#define SCMI_TLM_READ_FLAGS		(SCMI_TLM_READ_GROUP)
+#define SCMI_TLM_READ_IS_GROUP(f)	((f) & SCMI_TLM_READ_GROUP)
+	__u8 pad[3];
+	__u32 pad2;
+	__u32 num_samples;
+	__u64 samples;
+};
+
+/**
+ * struct scmi_tlm_grp_info  - Group info descriptor
+ *
+ * @grp_id: Group ID number
+ * @num_des: Number of DEs part of this group
+ * @num_intervals: Number of update intervals supported. Zero if group does not
+ *		   support per-group update interval configuration.
+ * @pad: Padding fields to enforce alignment
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_GRP_INFO
+ */
+struct scmi_tlm_grp_info {
+	__u32 grp_id;
+	__u32 num_des;
+	__u32 num_intervals;
+	__u32 pad;
+};
+
+/**
+ * struct scmi_tlm_grps_list  - Group info descriptor list
+ *
+ * @num_grps: Number of entries returned in @grps
+ * @pad: Padding fields to enforce alignment
+ * @grps: A reference to an array of struct scmi_tlm_grp_info containing an
+ *	  entry for each defined group
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_GRP_LIST
+ */
+struct scmi_tlm_grps_list {
+	__u32 num_grps;
+	__u32 pad;
+	__u64 grps;
+};
+
+/**
+ * struct scmi_tlm_grp_desc  - Group descriptor
+ *
+ * @grp_id: Group ID number
+ * @num_des: Number of DEs composing this group
+ * @composing_des: A reference to an array of __u32 elements containing the
+ *		   DataEvent IDs composing this group.
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_GRP_DESC
+ */
+struct scmi_tlm_grp_desc {
+	__u32 grp_id;
+	__u32 num_des;
+	__u64 composing_des;
+};
+
+/**
+ * struct scmi_tlm_shmti_info  - SHMTI descriptor
+ *
+ * @sid: SHMTI ID
+ * @fd: Associated opened file descriptor to use for mmap
+ * @len: Size of the SHMTI to be used with mmap on this SHMTI
+ * @offset: Offset in the mmap where the specified SHMTI start
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_SHMTI_LIST
+ */
+struct scmi_tlm_shmti_info {
+	__u32 sid;
+	__u32 fd;
+	__u32 len;
+	__u32 offset;
+};
+
+/**
+ * struct scmi_tlm_shmtis_list  - SHMTIs List
+ *
+ * @num_shmtis: Number of entries returned in @shmtis
+ * @pad: Padding fields to enforce alignment
+ * @shmtis: A reference to an array of struct scmi_tlm_shmti_info containing
+ *	    an entry for each defined SHMTI
+ *
+ * Used by:
+ *	RW - SCMI_TLM_GET_SHMTI_LIST
+ */
+struct scmi_tlm_shmtis_list {
+	__u32 num_shmtis;
+	__u32 pad;
+	__u64 shmtis;
+};
+
+#define SCMI_TLM_IOCTL_MAGIC 0xF1
+
+#define SCMI_TLM_GET_ABI_INFO	_IOWR(SCMI_TLM_IOCTL_MAGIC,  0x00, struct scmi_tlm_abi_info)
+#define SCMI_TLM_GET_CFG	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x01, struct scmi_tlm_config)
+#define SCMI_TLM_SET_CFG	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x02, struct scmi_tlm_config)
+#define SCMI_TLM_GET_INTRVS	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x03, struct scmi_tlm_intervals)
+#define SCMI_TLM_GET_DE_CFG	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x04, struct scmi_tlm_de_config)
+#define SCMI_TLM_SET_DE_CFG	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x05, struct scmi_tlm_de_config)
+#define SCMI_TLM_GET_DE_INFO	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x06, struct scmi_tlm_de_info)
+#define SCMI_TLM_GET_DE_LIST	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x07, struct scmi_tlm_des_list)
+#define SCMI_TLM_DE_READ	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x08, struct scmi_tlm_de_sample)
+#define SCMI_TLM_GET_ALL_CFG	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x09, struct scmi_tlm_de_config)
+#define SCMI_TLM_SET_ALL_CFG	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0A, struct scmi_tlm_de_config)
+#define SCMI_TLM_GET_GRP_LIST	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0B, struct scmi_tlm_grps_list)
+#define SCMI_TLM_GET_GRP_INFO	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0C, struct scmi_tlm_grp_info)
+#define SCMI_TLM_GET_GRP_DESC	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0D, struct scmi_tlm_grp_desc)
+#define SCMI_TLM_SINGLE_READ	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0E, struct scmi_tlm_data_read)
+#define SCMI_TLM_BULK_READ	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x0F, struct scmi_tlm_data_read)
+#define SCMI_TLM_BATCH_READ	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x10, struct scmi_tlm_data_read)
+#define SCMI_TLM_GET_SHMTI_LIST	_IOWR(SCMI_TLM_IOCTL_MAGIC, 0x11, struct scmi_tlm_shmtis_list)
+#define SCMI_TLM_RESET		_IO(SCMI_TLM_IOCTL_MAGIC, 0x12)
+
+#endif /* _UAPI_LINUX_SCMI_H */
diff --git a/tools/testing/scmi/Makefile b/tools/testing/scmi/Makefile
new file mode 100644
index 00000000000000..a6a101f8398baa
--- /dev/null
+++ b/tools/testing/scmi/Makefile
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+CC?=$(CROSS_COMPILE)gcc
+OBJS = stlm.o
+
+CFLAGS=-Wall -static -std=gnu11 -I ../../../include/uapi/
+ifneq ($(DEBUG), )
+	CFLAGS+=-O0 -g -ggdb
+else
+	CFLAGS+=-static
+endif
+
+all: stlm
+
+stlm: $(OBJS)
+	$(CC) $(CFLAGS) $^ -o $@
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+clean:
+	rm -f *.o
+	rm -f stlm
+
+.PHONY: clean
diff --git a/tools/testing/scmi/stlm.c b/tools/testing/scmi/stlm.c
new file mode 100644
index 00000000000000..8fcdba5783c70d
--- /dev/null
+++ b/tools/testing/scmi/stlm.c
@@ -0,0 +1,1191 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <poll.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+
+#include <unistd.h>
+
+#include <linux/scmi.h>
+
+#define SLEEP_MS	3000
+
+#define IOCTL_ERR_STR(_ioctl)	"IOCTL:" #_ioctl
+
+#define USAGE_STRING \
+	"\t[OPTIONS]\n" \
+	"\t -i <instance_path>\t\tUse this device instance path. Default: /dev/scmi/tlm_0\n" \
+	"\t[COMMANDS]\n" \
+	"\t info [full] - Display summarized (or full) configuration and information data\n" \
+	"\t shmti [check][dump <sid>] - SHMTI operations\n" \
+	"\t\t check - Sanity check of all SHMTis\n" \
+	"\t\t dump [<sid>] - Binary dump of <sid> or all SHMTI areas\n" \
+	"\t des - Display detailed DEs info and config data\n" \
+	"\t groups - Display detailed GROUPS info and config data\n" \
+	"\t cfg [SUB-COMMANDS] - Configure Telemetry\n" \
+	"\t\t tlm on|off - Enable or disable Telemetry as a whole\n" \
+	"\t\t update <msecs> - Set global update interval\n" \
+	"\t\t all_des [[on|off]:[on|off]] - Enable or disable ALL DEs with or wout TS\n" \
+	"\t\t de [<de_id> [[on|off]:[on|off]]] - Get/Set configuration of one or ALL de\n" \
+	"\t\t group [<grp_id>] [[on|off]:[on|off]:[<update_msecs>]] - Get/Set GROUP configuration\n" \
+	"\t single - Perform a single sample read\n" \
+	"\t bulk - Perform a bulk read\n" \
+	"\t batch <de_id> [de_id [de_id]... ] - Perform a batch read of the DE IDs listed in input\n" \
+	"\t reset - Perform a Telemetry subsytem reset platform-side\n"
+
+struct tlm_de {
+	struct scmi_tlm_de_info *info;
+	struct scmi_tlm_de_config cfg;
+	struct scmi_tlm_de_sample sample;
+};
+
+struct tlm_group {
+	int fd;
+	struct scmi_tlm_grp_info *info;
+	struct scmi_tlm_grp_desc *desc;
+	struct scmi_tlm_intervals *ivs;
+};
+
+struct tlm_state {
+	int fd;
+	const char *path;
+	struct scmi_tlm_abi_info info;
+	struct scmi_tlm_config cfg;
+	struct scmi_tlm_intervals *ivs;
+	struct scmi_tlm_shmtis_list *ssl;
+	unsigned int num_des;
+	struct tlm_de *des;
+	unsigned int num_groups;
+	struct tlm_group *grps;
+};
+
+struct parsed_args {
+	const char *instance;
+	const char *cmd;
+	unsigned int cnt;
+	char **opts;
+};
+
+static inline void dump_des(struct tlm_state *st)
+{
+	fprintf(stdout, "\n+ Found #%d DEs:\n", st->num_des);
+	for (int i = 0; i < st->num_des; i++) {
+		fprintf(stdout, "\t[0x%08X][%s]\n",
+			st->des[i].info->id, st->des[i].info->name);
+		fprintf(stdout, "\t\tGRP_ID:0x%08X  SZ:%u  TYPE:%u  UNIT:%u  UNIT_EXP:%d  TS_RATE:%d\n",
+			st->des[i].info->grp_id, st->des[i].info->data_sz,
+			st->des[i].info->type, st->des[i].info->unit,
+			st->des[i].info->unit_exp, st->des[i].info->ts_rate);
+		fprintf(stdout, "\t\tINST_ID:%u  COMPO_ID:%u  COMPO_TYPE:%u  PERSIST:%u\n\n",
+			st->des[i].info->instance_id, st->des[i].info->compo_instance_id,
+			st->des[i].info->compo_type, st->des[i].info->persistent);
+	}
+	fprintf(stdout, "\n");
+
+	for (int i = 0; i < st->num_des; i++) {
+		struct tlm_de *de = &st->des[i];
+
+		/* Collect fresh sample */
+		if (de->cfg.enable) {
+			int ret;
+
+			de->sample.id = de->info->id;
+			ret = ioctl(st->fd, SCMI_TLM_DE_READ, &de->sample);
+			if (ret)
+				perror(IOCTL_ERR_STR(SCMI_TLM_DE_READ));
+		}
+
+		fprintf(stdout, "\t[0x%08X][%s]\t\t%s %s\n\t\t-->> TS:%16llu %016llX\n",
+			de->info->id, de->info->name,
+			de->cfg.enable ? "ON" : "OFF",
+			de->cfg.t_enable ? "/TS_ON " : "/TS_OFF",
+			de->sample.tstamp, de->sample.val);
+	}
+	fprintf(stdout, "\n");
+}
+
+static inline void dump_groups(struct tlm_state *st)
+{
+	fprintf(stdout, "\n+ Found %d GRPs: ", st->num_groups);
+	for (int i = 0; i < st->num_groups; i++) {
+		struct scmi_tlm_update_interval *grp_intrvs;
+		struct tlm_group *grp = &st->grps[i];
+		uint32_t *composing_des;
+
+		fprintf(stdout, "\n\tGRP_ID:%d  DES#:%d  INTRVS#:%d\n",
+			grp->info->grp_id, grp->info->num_des,
+			grp->info->num_intervals);
+
+		fprintf(stdout, "\tGRP Intervals:\n");
+		grp_intrvs = (struct scmi_tlm_update_interval *)grp->ivs->intervals;
+		for (int j = 0; j < grp->ivs->num_intervals; j++)
+			fprintf(stdout, "\t[%d]::%u,%d\n", j,
+				grp_intrvs[j].secs, grp_intrvs[j].exp);
+
+		composing_des = (uint32_t *)grp->desc->composing_des;
+		fprintf(stdout, "\tCOMPOSING_DES:");
+		for (int j = 0; j < grp->desc->num_des; j++)
+			fprintf(stdout, "0x%08X ", composing_des[j]);
+		fprintf(stdout, "\n");
+	}
+}
+
+static inline void dump_state(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_update_interval *intervals;
+	struct scmi_tlm_shmti_info *shinfo;
+
+	fprintf(stdout, "- SYSTEM TELEMETRY @instance: %s\n\n", st->path);
+	fprintf(stdout, "+ ABI Version: %u\n", st->info.abi_version);
+	fprintf(stdout, "+ ABI Features: 0x%04X\n", st->info.abi_features);
+	fprintf(stdout, "\t (RESET:%u)\n",
+		!!(st->info.abi_features & SCMI_TLM_ABI_FEAT_RESET));
+	fprintf(stdout, "+ SCMI Features: 0x%04X\n", st->info.features);
+	fprintf(stdout, "\t (RESET:%u",
+		!!(st->info.features & SCMI_TLM_BASE_SUPPORT_RESET));
+	fprintf(stdout, " SINGLE_SAMPLE:%u",
+		!!(st->info.features & SCMI_TLM_BASE_SUPPORT_SINGLE_SAMPLE));
+	fprintf(stdout, " GROUP_CONFIG:%u",
+		!!(st->info.features & SCMI_TLM_BASE_SUPPORT_GROUP_CONFIG));
+	fprintf(stdout, " UPDATE_NOTIFICATIONS:%u)\n",
+		!!(st->info.features & SCMI_TLM_BASE_SUPPORT_UPDATE_NOTIFICATION));
+	fprintf(stdout, "+ DEs#: %d\n", st->info.num_des);
+	fprintf(stdout, "+ GRPS#: %d\n", st->info.num_groups);
+	fprintf(stdout, "+ INTRV#: %d\n", st->info.num_intervals);
+	fprintf(stdout, "+ SHMTIS#: %d\n", st->info.num_shmtis);
+
+	fprintf(stdout, "+ Primary UUID: ");
+	for (int i = 0; i < SCMI_TLM_DE_IMPL_UUID_MAX; i++) {
+		fprintf(stdout, "%02X", st->info.de_impl_version[i]);
+		switch (i) {
+		case 3:
+		case 5:
+		case 7:
+		case 9:
+			fprintf(stdout, "%c", '-');
+			break;
+		case 15:
+			fprintf(stdout, "%c", '\n');
+			break;
+		}
+	}
+
+	fprintf(stdout, "\n+ TLM_ENABLED: %d\n", st->cfg.enable);
+	fprintf(stdout, "+ CURRENT_UPDATE_INTERVAL: %u,%d\n",
+		st->cfg.active.secs, st->cfg.active.exp);
+
+	fprintf(stdout, "\n+ Found #%u Global Update Intervals\n",
+		st->ivs->num_intervals);
+	intervals = (struct scmi_tlm_update_interval *)st->ivs->intervals;
+	for (int i = 0; i < st->ivs->num_intervals; i++)
+		fprintf(stdout, "\t[%d]::%u,%d\n", i,
+			intervals[i].secs, intervals[i].exp);
+
+	fprintf(stdout, "\n+ Found #%u SHMTI areas\n", st->ssl->num_shmtis);
+	shinfo = (struct scmi_tlm_shmti_info *)st->ssl->shmtis;
+	for (int i = 0; i < st->ssl->num_shmtis; i++)
+		fprintf(stdout, "\t[%d]:: FD:%u  LEN:%u\n",
+			shinfo[i].sid, shinfo[i].fd, shinfo[i].len);
+
+	if (st->info.num_des != st->num_des) {
+		fprintf(stdout, "\n++++++ DES NOT FULLY_ENUMERATED ++++++\n");
+		fprintf(stdout, "+++ DECLARED:%u  ENUMERATED:%u +++\n",
+			st->info.num_des, st->num_des);
+	}
+
+	if (args && args->cnt && args->opts &&
+	    !strncmp(args->opts[0], "full", strlen(args->opts[0]))) {
+		dump_des(st);
+		dump_groups(st);
+	}
+}
+
+static int discover_base_info(int fd, struct scmi_tlm_abi_info *info)
+{
+	int ret;
+
+	info->size = sizeof(*info);
+	ret = ioctl(fd, SCMI_TLM_GET_ABI_INFO, info);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_ABI_INFO));
+		return ret;
+	}
+
+	return ret;
+}
+
+static struct scmi_tlm_des_list *scmi_get_des_list(int fd, int num_des)
+{
+	struct scmi_tlm_des_list *dsl;
+	struct scmi_tlm_de_info *dei;
+	size_t sz, d_sz;
+	int ret;
+
+	sz = sizeof(*dsl);
+	dsl = malloc(sz);
+	if (!dsl)
+		return NULL;
+
+	bzero(dsl, sz);
+
+	d_sz = sizeof(*dei) * num_des;
+	dei = malloc(d_sz);
+	if (!dei) {
+		free(dsl);
+		return NULL;
+	}
+
+	bzero(dei, d_sz);
+
+	dsl->num_des = num_des;
+	dsl->des = (uint64_t)dei;
+	ret = ioctl(fd, SCMI_TLM_GET_DE_LIST, dsl);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_DE_LIST));
+		return NULL;
+	}
+
+	return dsl;
+}
+
+static struct tlm_de *enumerate_des(struct tlm_state *st)
+{
+	struct scmi_tlm_des_list *dsl;
+	struct tlm_de *des;
+
+	dsl = scmi_get_des_list(st->fd, st->info.num_des);
+	if (!dsl)
+		return NULL;
+
+	st->num_des = dsl->num_des;
+	des = malloc(sizeof(*des) * st->num_des);
+	if (!des)
+		return NULL;
+
+	bzero(des, sizeof(*des) * st->num_des);
+	for (int i = 0; i < st->num_des; i++) {
+		struct tlm_de *de = &des[i];
+		int ret;
+
+		de->info = &(((struct scmi_tlm_de_info *)dsl->des)[i]);
+		de->cfg.id = de->info->id;
+		ret = ioctl(st->fd, SCMI_TLM_GET_DE_CFG, &de->cfg);
+		if (ret) {
+			perror(IOCTL_ERR_STR(SCMI_TLM_GET_DE_CFG));
+			continue;
+		}
+	}
+
+	return des;
+}
+
+static int get_current_config(int fd, struct scmi_tlm_config *cfg)
+{
+	int ret;
+
+	ret = ioctl(fd, SCMI_TLM_GET_CFG, cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_CFG));
+		return ret;
+	}
+
+	return ret;
+}
+
+static struct scmi_tlm_grps_list *scmi_get_grps_list(int fd, int num_groups)
+{
+	struct scmi_tlm_grps_list *gsl;
+	struct scmi_tlm_grp_info *grps;
+	size_t sz, grps_sz;
+	int ret;
+
+	sz = sizeof(*gsl);
+	gsl = malloc(sz);
+	if (!gsl)
+		return NULL;
+
+	bzero(gsl, sz);
+	grps_sz = sizeof(*grps) * num_groups;
+	grps = malloc(grps_sz);
+	if (!grps) {
+		free(gsl);
+		return NULL;
+	}
+
+	gsl->num_grps = num_groups;
+	gsl->grps = (uint64_t)grps;
+	ret = ioctl(fd, SCMI_TLM_GET_GRP_LIST, gsl);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_GRP_LIST));
+		free(grps);
+		free(gsl);
+		return NULL;
+	}
+
+	return gsl;
+}
+
+static struct scmi_tlm_intervals *
+enumerate_intervals(int fd, int num_intervals, unsigned int *grp_id)
+{
+	struct scmi_tlm_update_interval *intervs;
+	struct scmi_tlm_intervals *ivs;
+	size_t sz, i_sz;
+	int ret;
+
+	sz = sizeof(*ivs);
+	ivs = malloc(sz);
+	if (!ivs)
+		return NULL;
+
+	bzero(ivs, sz);
+
+	i_sz = sizeof(*intervs) * num_intervals;
+	intervs = malloc(i_sz);
+	if (!intervs) {
+		free(ivs);
+		return NULL;
+	}
+
+	bzero(intervs, i_sz);
+
+	ivs->num_intervals = num_intervals;
+	ivs->intervals = (uint64_t)intervs;
+	if (grp_id) {
+		ivs->grp_id = *grp_id;
+		ivs->flags = SCMI_TLM_INTERV_GROUP;
+	}
+
+	ret = ioctl(fd, SCMI_TLM_GET_INTRVS, ivs);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_INTRVS));
+		free(ivs);
+		free(intervs);
+		return NULL;
+	}
+
+	return ivs;
+}
+
+static struct scmi_tlm_shmtis_list *enumerate_shmtis(struct tlm_state *st)
+{
+	struct scmi_tlm_shmti_info *shmtis;
+	struct scmi_tlm_shmtis_list *ssl;
+	size_t sz, shmtis_sz;
+	int ret;
+
+	sz = sizeof(*ssl);
+	ssl = malloc(sz);
+	if (!ssl)
+		return NULL;
+
+	bzero(ssl, sz);
+	shmtis_sz = sizeof(*shmtis) * st->info.num_shmtis;
+	shmtis = malloc(shmtis_sz);
+	if (!shmtis) {
+		free(ssl);
+		return NULL;
+	}
+
+	ssl->num_shmtis = st->info.num_shmtis;
+	ssl->shmtis = (uint64_t)shmtis;
+	ret = ioctl(st->fd, SCMI_TLM_GET_SHMTI_LIST, ssl);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_SHMTI_LIST));
+		free(shmtis);
+		free(ssl);
+		return NULL;
+	}
+
+	return ssl;
+}
+
+static struct tlm_group *enumerate_groups(struct tlm_state *st)
+{
+	struct scmi_tlm_grps_list *gsl;
+	struct tlm_group *grps;
+
+	gsl = scmi_get_grps_list(st->fd, st->info.num_groups);
+	if (!gsl)
+		return NULL;
+
+	st->num_groups = gsl->num_grps;
+	grps = malloc(sizeof(*grps) * st->num_groups);
+	if (!grps)
+		return NULL;
+
+	bzero(grps, sizeof(*grps) * st->num_groups);
+	for (int i = 0; i < st->num_groups; i++) {
+		struct tlm_group *grp = &grps[i];
+		size_t size, composing_sz;
+		uint32_t *composing_des;
+		int ret;
+
+		grp->info = &(((struct scmi_tlm_grp_info *)gsl->grps)[i]);
+		size = sizeof(*grp->desc);
+		grp->desc = malloc(size);
+		if (!grp->desc)
+			return NULL;
+
+		bzero(grp->desc, size);
+		composing_sz = sizeof(uint32_t) * grp->info->num_des;
+		composing_des = malloc(composing_sz);
+		if (!composing_des) //XXX BAD Cleanup
+			return NULL;
+
+		grp->desc->grp_id = grp->info->grp_id;
+		grp->desc->num_des = grp->info->num_des;
+		grp->desc->composing_des = (uint64_t)composing_des;
+		ret = ioctl(st->fd, SCMI_TLM_GET_GRP_DESC, grp->desc);
+		if (ret) {
+			perror(IOCTL_ERR_STR(SCMI_TLM_GET_GRP_DESC));
+			continue;
+		}
+
+		grp->ivs = enumerate_intervals(st->fd, grp->info->num_intervals,
+					       &grp->info->grp_id);
+	}
+
+	return grps;
+}
+
+static int gather_tlm_state(struct tlm_state *st)
+{
+	int ret;
+
+	ret = discover_base_info(st->fd, &st->info);
+	if (ret)
+		return ret;
+
+	st->ivs = enumerate_intervals(st->fd, st->info.num_intervals, NULL);
+	if (!st->ivs)
+		return -1;
+
+	ret = get_current_config(st->fd, &st->cfg);
+	if (ret)
+		return ret;
+
+	if (st->info.num_des)
+		st->des = enumerate_des(st);
+
+	if (st->info.num_groups)
+		st->grps = enumerate_groups(st);
+
+	if (st->info.num_shmtis)
+		st->ssl = enumerate_shmtis(st);
+
+	return 0;
+}
+
+static struct tlm_state *open_session(const char *path)
+{
+	struct tlm_state *st;
+
+	st = malloc(sizeof(*st));
+	if (!st)
+		return NULL;
+
+	st->fd = open(path, O_RDWR);
+	if (st->fd < 0) {
+		perror("open");
+		free(st);
+		return NULL;
+	}
+
+	st->path = path;
+
+	return st;
+}
+
+#define MAX_GENERATIONS		5
+
+#if 0
+static void get_tlm_generation(struct tlm_state *st)
+{
+	int fd, i = 0;
+	struct pollfd pfds[1];
+
+	fd = openat(st->dfd, "generation", O_RDONLY);
+	if (fd < 0) {
+		perror("openat");
+		return;
+	}
+
+	pfds[0].fd = fd;
+	pfds[0].events = POLLIN;
+
+	do {
+		int ret;
+
+		pfds[0].revents = 0;
+		ret = poll(pfds, 1, -1);
+		if (ret < 0) {
+			perror("poll generation");
+			break;
+		}
+
+		if (!pfds[0].revents)
+			continue;
+
+		if (pfds[0].revents & POLLIN) {
+			int n;
+			char buf[32] = {};
+
+			n = read(fd, buf, 32);
+			if (n < 0) {
+				perror("read generation");
+				break;
+			}
+
+			fprintf(stdout, "Generation[%u]: %s\n", i, buf);
+		}
+	} while (i++ < MAX_GENERATIONS);
+
+	close(fd);
+}
+#endif
+
+static int dump_shmti(struct scmi_tlm_shmti_info *shmti)
+{
+	void *tdcf;
+	ssize_t bytes = 0;
+
+	tdcf = mmap(NULL, shmti->len, PROT_READ, MAP_SHARED, shmti->fd, 0);
+	if (tdcf == MAP_FAILED) {
+		fprintf(stderr, "%s\n", strerror(errno));
+		return -1;
+	}
+
+	tdcf += shmti->offset;
+	do {
+		bytes += write(1, tdcf + bytes, shmti->len - bytes);
+		if (bytes < 0)
+			return -1;
+	} while (bytes < shmti->len);
+
+	return bytes;
+}
+
+static int shmti_dump(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_shmti_info *shmti;
+	unsigned long first, last;
+
+	if (args->cnt > 1) {
+		first = last = strtoul(args->opts[1], NULL, 0);
+		if (first == ULONG_MAX || errno == -EINVAL ||
+		    first >= st->ssl->num_shmtis)
+			return -1;
+	} else {
+		first = 0;
+		last = st->ssl->num_shmtis - 1;
+	}
+
+	for (int sid = first; sid <= last; sid++) {
+		int ret;
+
+		shmti = &(((struct scmi_tlm_shmti_info *)(st->ssl->shmtis))[sid]);
+		fprintf(stderr, "Binary DUMP of SHMTI[%u] LEN:%u\n",
+			shmti->sid, shmti->len);
+
+		ret = dump_shmti(shmti);
+		if (!ret)
+			fprintf(stderr, "...FAILED DUMP of SHMTI[%u] !!!\n", sid);
+	}
+
+	return 0;
+}
+
+static int shmti_check(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_shmti_info *shmtis;
+
+	shmtis = (struct scmi_tlm_shmti_info *)st->ssl->shmtis;
+
+	fprintf(stdout, "\n- SHMTI mmap SANITY CHECK -\n-------------------\n");
+
+	for (int i = 0; i < st->ssl->num_shmtis; i++) {
+		unsigned long *start, *end;
+		void *tdcf;
+		char *buf;
+
+		fprintf(stdout, "Mapping SHMTI[%u] - SID:%u  LEN:%u  FD:%u  OFFS:%u\n",
+			i, shmtis[i].sid, shmtis[i].len, shmtis[i].fd, shmtis[i].offset);
+
+		tdcf = mmap(NULL, shmtis[i].len, PROT_READ, MAP_SHARED,
+			    shmtis[i].fd, 0);
+		if (tdcf == MAP_FAILED) {
+			fprintf(stderr, "%s\n", strerror(errno));
+			return -1;
+		}
+
+		start = tdcf + shmtis[i].offset;
+		end = tdcf + shmtis[i].offset + shmtis[i].len;
+
+		fprintf(stdout, "-----------------------------------------------------\n");
+		fprintf(stdout, "Mapped SHMTI - SID:%u  %u@%p\n",
+			shmtis[i].sid, shmtis[i].offset, tdcf);
+
+		buf = (char *)start;
+		for (int j = 0; j < 4; j++)
+			fprintf(stdout, "%c ", buf[j]);
+
+		fprintf(stdout, " ===> ");
+
+		buf = ((char *)end) - 4;
+		for (int j = 0 ; j < 4; j++)
+			fprintf(stdout, "%c ", buf[j]);
+		fprintf(stdout, "\n-----------------------------------------------------\n");
+	}
+
+	return 0;
+}
+
+static int shmti_ops(struct tlm_state *st, struct parsed_args *args)
+{
+	if (!args->cnt || !args->opts)
+		return -1;
+
+	if (!strncmp(args->opts[0], "dump", strlen(args->opts[0])))
+		return shmti_dump(st, args);
+	if (!strncmp(args->opts[0], "check", strlen(args->opts[0])))
+		return shmti_check(st, args);
+
+	return -1;
+}
+
+static int parse_options(int argc, char **argv, struct parsed_args *args)
+{
+	int opt = 0;
+
+	/* Set defaults */
+	args->instance = "/dev/scmi/tlm_0";
+	while ((opt = getopt(argc, argv, "i:h")) != -1) {
+		switch (opt) {
+		case 'i':
+			args->instance = optarg;
+			break;
+		case 'h':
+		default:
+			return -EINVAL;
+		}
+	}
+
+	if (optind <= argc) {
+		if (optind < argc - 1) {
+			args->cnt = argc - 1 - optind;
+			args->opts = malloc(sizeof(*args->opts) * args->cnt);
+			if (!args->opts)
+				return -1;
+		}
+
+		args->cmd = argv[optind];
+		for (int i = 0, j = optind + 1; j < argc; i++, j++)
+			args->opts[i] = argv[j];
+	}
+
+	return 0;
+}
+
+static inline void usage(char *program_name)
+{
+	printf("Usage: %s [OPTIONS] [CMD [CMD_OPTS]...]\n", program_name);
+	printf("%s", USAGE_STRING);
+}
+
+static inline struct scmi_tlm_data_read *bulk_buffer_alloc(struct tlm_state *st)
+{
+	struct scmi_tlm_de_sample *samples;
+	struct scmi_tlm_data_read *bulk;
+	size_t bulk_sz, samples_sz;
+
+	bulk_sz = sizeof(*bulk);
+	bulk = malloc(bulk_sz);
+	if (!bulk)
+		return NULL;
+
+	bzero(bulk, bulk_sz);
+	samples_sz = st->info.num_des * sizeof(*samples);
+	samples = malloc(samples_sz);
+	if (!samples) {
+		free(bulk);
+		return NULL;
+	}
+
+	bzero(samples, samples_sz);
+	bulk->samples = (uint64_t)samples;
+	bulk->num_samples = st->info.num_des;
+
+	return bulk;
+}
+
+static int single_read(struct tlm_state *st)
+{
+	struct scmi_tlm_de_sample *samples;
+	struct scmi_tlm_data_read *bulk;
+	int ret;
+
+	bulk = bulk_buffer_alloc(st);
+	if (!bulk)
+		return -1;
+
+	ret = ioctl(st->fd, SCMI_TLM_SINGLE_READ, bulk);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_SINGLE_READ));
+		return -1;
+	}
+
+	fprintf(stdout, "\n- Single ASYNC read -\n-------------------\n");
+	samples = (struct scmi_tlm_de_sample *)bulk->samples;
+	for (int i = 0; i < bulk->num_samples; i++)
+		fprintf(stdout, "0x%08X %016llu %016llX\n",
+			samples[i].id, samples[i].tstamp, samples[i].val);
+
+	return 0;
+}
+
+static int bulk_read(struct tlm_state *st)
+{
+	struct scmi_tlm_de_sample *samples;
+	struct scmi_tlm_data_read *bulk;
+	int ret;
+
+	bulk = bulk_buffer_alloc(st);
+	if (!bulk)
+		return -1;
+
+	ret = ioctl(st->fd, SCMI_TLM_BULK_READ, bulk);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_BULK_READ));
+		return -1;
+	}
+
+	fprintf(stdout, "\n- BULK read -\n-------------------\n");
+	samples = (struct scmi_tlm_de_sample *)bulk->samples;
+	for (int i = 0; i < bulk->num_samples; i++)
+		fprintf(stdout, "0x%08X %016llu %016llX\n",
+			samples[i].id, samples[i].tstamp, samples[i].val);
+
+	return 0;
+}
+
+static int tlm_reset(struct tlm_state *st)
+{
+	int ret;
+
+	ret = ioctl(st->fd, SCMI_TLM_RESET);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_RESET));
+		return -1;
+	}
+
+	fprintf(stdout, "\n--- TLM RESET ISSUED\n");
+
+	return 0;
+}
+
+static int batch_read(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_de_sample *samples;
+	struct scmi_tlm_data_read *bulk;
+	int ret;
+
+	if (!args->opts || !args->cnt)
+		return -1;
+
+	bulk = bulk_buffer_alloc(st);
+	if (!bulk)
+		return -1;
+
+	samples = (struct scmi_tlm_de_sample *)bulk->samples;
+	bulk->num_samples = args->cnt;
+	for (int i = 0; i < bulk->num_samples; i++) {
+		unsigned long val;
+
+		val = strtoul(args->opts[i], NULL, 0);
+		if (val == ULONG_MAX || errno == -EINVAL)
+			continue;
+
+		samples[i].id = (unsigned int)val;
+	}
+
+	ret = ioctl(st->fd, SCMI_TLM_BATCH_READ, bulk);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_BATCH_READ));
+		return -1;
+	}
+
+	fprintf(stdout, "\n- BATCH read -\n-------------------\n");
+	for (int i = 0; i < bulk->num_samples; i++)
+		fprintf(stdout, "0x%08X %016llu %016llX\n",
+			samples[i].id, samples[i].tstamp, samples[i].val);
+
+	return 0;
+}
+
+/*
+ * <ena>:<t_ena>[:<update_msecs>]
+ */
+static void
+parse_item_cfg(char *str, bool *ena, bool *t_ena, unsigned int *update)
+{
+	char *tok;
+
+	if (!ena)
+		return;
+
+	tok = strtok(str, ":");
+	if (tok)
+		*ena = strncmp(tok, "on", strlen(tok)) == 0;
+
+	if (!t_ena)
+		return;
+
+	tok = strtok(NULL, ":");
+	if (tok)
+		*t_ena = strncmp(tok, "on", strlen(tok)) == 0;
+
+	if (!update)
+		return;
+
+	tok = strtok(NULL, ":");
+	if (tok) {
+		unsigned long val;
+
+		val = strtoul(tok, NULL, 0);
+		if (val == ULONG_MAX || errno == -EINVAL)
+			return;
+
+		*update = (unsigned int)val;
+	}
+}
+
+static int configure_all_des(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_de_config de_cfg = {};
+	bool ena, t_ena;
+	int ret;
+
+	if (!args->opts)
+		return -1;
+
+	ret = ioctl(st->fd, SCMI_TLM_GET_ALL_CFG, &de_cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_ALL_CFG));
+		return ret;
+	}
+
+	fprintf(stdout, "--- [GET] ALL DEs ON:%d  T_ON:%d\n",
+		de_cfg.enable, de_cfg.t_enable);
+
+	if (args->cnt < 2)
+		return 0;
+
+	parse_item_cfg(args->opts[1], &ena, &t_ena, NULL);
+	de_cfg.enable = !!ena;
+	de_cfg.t_enable = !!t_ena;
+
+	fprintf(stdout, "--- [SET] ALL DEs ON:%d  T_ON:%d\n",
+		de_cfg.enable, de_cfg.t_enable);
+
+	ret = ioctl(st->fd, SCMI_TLM_SET_ALL_CFG, &de_cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_SET_ALL_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int de_config_get(struct tlm_state *st, struct scmi_tlm_de_config *de_cfg)
+{
+	int ret;
+
+	/* Get current config */
+	ret = ioctl(st->fd, SCMI_TLM_GET_DE_CFG, de_cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_DE_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int configure_de(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_de_config de_cfg = {};
+	bool ena, t_ena;
+	unsigned long val;
+	int ret;
+
+	if (!args->opts)
+		return -1;
+
+	if (args->cnt < 2) {
+		/* Dump all DE configs */
+		for (int i = 0; i < st->num_des; i++) {
+			de_cfg.id = st->des[i].info->id;
+			ret = de_config_get(st, &de_cfg);
+			if (!ret)
+				fprintf(stdout,
+					"--- [GET] -> DE:0x%08X  ON:%d  T_ON:%d\n",
+					de_cfg.id, de_cfg.enable, de_cfg.t_enable);
+		}
+
+		return 0;
+	}
+
+	/*Dump one DE config */
+	val = strtoul(args->opts[1], NULL, 0);
+	if (val == ULONG_MAX || errno == -EINVAL)
+		return -1;
+
+	de_cfg.id = (unsigned int)val;
+	ret = de_config_get(st, &de_cfg);
+	if (ret)
+		return ret;
+
+	fprintf(stdout, "--- [GET] -> DE:0x%08X  ON:%d  T_ON:%d\n",
+		de_cfg.id, de_cfg.enable, de_cfg.t_enable);
+
+	if (args->cnt < 3)
+		return 0;
+
+	/* Configure one DE: */
+	parse_item_cfg(args->opts[2], &ena, &t_ena, NULL);
+	de_cfg.enable = !!ena;
+	de_cfg.t_enable = !!t_ena;
+
+	fprintf(stdout, "--- [SET] -> DE:0x%08X  ON:%d  T_ON:%d\n",
+		de_cfg.id, de_cfg.enable, de_cfg.t_enable);
+
+	ret = ioctl(st->fd, SCMI_TLM_SET_DE_CFG, &de_cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_SET_DE_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int grp_config_get(struct tlm_state *st, struct scmi_tlm_config *cfg)
+{
+	int ret;
+
+	/* Get current config */
+	ret = ioctl(st->fd, SCMI_TLM_GET_CFG, cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_GET_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int configure_group(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_config cfg = {};
+	bool ena, t_ena;
+	unsigned long val;
+	int ret;
+
+	if (!args->opts)
+		return -1;
+
+	if (args->cnt < 2) {
+		/* Dump all GRPS configs */
+		for (int i = 0; i < st->num_groups; i++) {
+			cfg.grp_id = st->grps[i].info->grp_id;
+			cfg.active.exp = -3;
+			cfg.flags = SCMI_TLM_CONFIG_GROUP;
+			ret = grp_config_get(st, &cfg);
+			if (!ret)
+				fprintf(stdout,
+					"--- [GET] -> GROUP:0x%08X  ON:%d  T_ON:%d  INTRV:%u,%d\n",
+					cfg.grp_id, cfg.enable, cfg.t_enable,
+					cfg.active.secs, cfg.active.exp);
+		}
+
+		return 0;
+	}
+
+	/*Dump one GROUP config */
+	val = strtoul(args->opts[1], NULL, 0);
+	if (val == ULONG_MAX || errno == -EINVAL)
+		return -1;
+
+	cfg.grp_id = (unsigned int)val;
+	cfg.flags = SCMI_TLM_CONFIG_GROUP;
+	cfg.active.exp = -3;
+	ret = grp_config_get(st, &cfg);
+	if (ret)
+		return ret;
+
+	fprintf(stdout, "--- [GET] -> GROUP:0x%08X  ON:%d  T_ON:%d  INTRV:%u,%d\n",
+		cfg.grp_id, cfg.enable, cfg.t_enable, cfg.active.secs, cfg.active.exp);
+
+	if (args->cnt < 3)
+		return 0;
+
+	/* Configure one GROUP */
+	parse_item_cfg(args->opts[2], &ena, &t_ena, &cfg.active.secs);
+	cfg.enable = !!ena;
+	cfg.t_enable = !!t_ena;
+
+	fprintf(stdout, "--- [SET] -> GROUP:0x%08X  ON:%d  T_ON:%d  INTRV:%u,%d\n",
+		cfg.grp_id, cfg.enable, cfg.t_enable,
+		cfg.active.secs, cfg.active.exp);
+
+	ret = ioctl(st->fd, SCMI_TLM_SET_CFG, &cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_SET_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int configure_telemetry(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_config cfg = st->cfg;
+	bool val;
+	int ret;
+
+	if (args->cnt < 2 || !args->opts)
+		return -1;
+
+	val = strncmp(args->opts[1], "on", strlen(args->opts[1])) == 0;
+
+	cfg.enable = !!val;
+	cfg.flags = 0;
+
+	fprintf(stdout, "\n---%sabling Telemetry\n", val ? "En" : "Dis");
+	ret = ioctl(st->fd, SCMI_TLM_SET_CFG, &cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_SET_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int configure_update(struct tlm_state *st, struct parsed_args *args)
+{
+	struct scmi_tlm_config cfg = st->cfg;
+	unsigned long val;
+	int ret;
+
+	if (args->cnt < 2 || !args->opts)
+		return -1;
+
+	val = strtoul(args->opts[1], NULL, 0);
+	if (val == ULONG_MAX || errno == -EINVAL)
+		return -1;
+
+	cfg.flags = 0;
+	if (!val) {
+		cfg.enable = val;
+		fprintf(stdout, "\n---Disabling Telemetry\n");
+	} else {
+		cfg.enable = !!val;
+		cfg.active.secs = val;
+		cfg.active.exp = -3;
+		fprintf(stdout, "\n--- Setting update interval to %lu\n", val);
+	}
+
+	ret = ioctl(st->fd, SCMI_TLM_SET_CFG, &cfg);
+	if (ret) {
+		perror(IOCTL_ERR_STR(SCMI_TLM_SET_CFG));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int configure(struct tlm_state *st, struct parsed_args *args)
+{
+	if (!args->cnt || !args->opts)
+		return -1;
+
+	if (!strncmp(args->opts[0], "all_des", strlen(args->opts[0])))
+		return configure_all_des(st, args);
+	if (!strncmp(args->opts[0], "tlm", strlen(args->opts[0])))
+		return configure_telemetry(st, args);
+	if (!strncmp(args->opts[0], "update", strlen(args->opts[0])))
+		return configure_update(st, args);
+	if (!strncmp(args->opts[0], "de", strlen(args->opts[0])))
+		return configure_de(st, args);
+	if (!strncmp(args->opts[0], "group", strlen(args->opts[0])))
+		return configure_group(st, args);
+
+	return -1;
+}
+
+static inline void full_scan_and_dump(struct tlm_state *st)
+{
+	dump_state(st, NULL);
+	dump_des(st);
+	dump_groups(st);
+}
+
+int main(int argc, char **argv)
+{
+	struct parsed_args args = {};
+	struct tlm_state *st;
+	int ret;
+
+	//get_tlm_generation(&st);
+
+	ret = parse_options(argc, argv, &args);
+	if (ret) {
+		usage(argv[0]);
+		return ret;
+	}
+
+	st = open_session(args.instance);
+	if (!st)
+		return -1;
+
+	ret = gather_tlm_state(st);
+	if (ret) {
+		free(st);
+		return ret;
+	}
+
+	if (!args.cmd) {
+		full_scan_and_dump(st);
+	} else if (!strncmp(args.cmd, "info", strlen(args.cmd))) {
+		dump_state(st, &args);
+	} else if (!strncmp(args.cmd, "shmti", strlen(args.cmd))) {
+		shmti_ops(st, &args);
+	} else if (!strncmp(args.cmd, "des", strlen(args.cmd))) {
+		dump_des(st);
+	} else if (!strncmp(args.cmd, "groups", strlen(args.cmd))) {
+		dump_groups(st);
+	} else if (!strncmp(args.cmd, "cfg", strlen(args.cmd))) {
+		configure(st, &args);
+	} else if (!strncmp(args.cmd, "single", strlen(args.cmd))) {
+		single_read(st);
+	} else if (!strncmp(args.cmd, "bulk", strlen(args.cmd))) {
+		bulk_read(st);
+	} else if (!strncmp(args.cmd, "batch", strlen(args.cmd))) {
+		batch_read(st, &args);
+	} else if (!strncmp(args.cmd, "reset", strlen(args.cmd))) {
+		tlm_reset(st);
+	} else {
+		fprintf(stderr, "Unknown command '%s'\n", args.cmd);
+		usage(argv[0]);
+		return -1;
+	}
+
+	return 0;
+}

3/2 2026/07/25 20:52 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 89435
							output: 423
							thoughts: 2588
						

Thoughts:
**SCMI Telemetry Driver Analysis for Fuzzing**

Okay, so we've got a new patch introducing an SCMI Telemetry driver and associated protocol. My immediate thoughts are: this is a candidate for fuzzing. It's a new character device, `/dev/scmi/tlm_<N>`, with a set of ioctls, defined in `include/uapi/linux/scmi.h`. The driver itself is in `drivers/firmware/arm_scmi/scmi_system_telemetry.c` and `drivers/firmware/arm_scmi/telemetry.c`. We're dealing with an ARM standard here, SCMI (System Control and Management Interface), so it’s likely reachable in QEMU. Specifically, virtio-scmi support in QEMU should allow us to test it.

First, let's verify if the relevant config options are set. The primary one is `CONFIG_ARM_SCMI_SYSTEM_TELEMETRY`, which depends on `ARM_SCMI_PROTOCOL`. The patch also introduces `CONFIG_ARM_SCMI_DEBUG_PROTOCOLS`, which is optional but good to enable for debugging purposes. I can confirm these configs are set in `drivers/firmware/arm_scmi/Kconfig`.

Now, the core of the fuzzing target. The main ioctl handler, the entry point for interaction, is `scmi_tlm_unlocked_ioctl` in `drivers/firmware/arm_scmi/scmi_system_telemetry.c`. Within that, there are a bunch of sub-functions and ioctls to consider. Specifically:

*   `scmi_tlm_abi_info_get_ioctl`
*   `scmi_tlm_config_get_ioctl`
*   `scmi_tlm_config_set_ioctl`
*   `scmi_tlm_intervals_get_ioctl`
*   `scmi_tlm_de_config_set_ioctl`
*   `scmi_tlm_de_config_get_ioctl`
*   `scmi_tlm_de_info_get_ioctl`
*   `scmi_tlm_des_list_get_ioctl`
*   `scmi_tlm_de_value_get_ioctl`
*   `scmi_tlm_grp_info_get_ioctl`
*   `scmi_tlm_grp_desc_get_ioctl`
*   `scmi_tlm_grps_list_get_ioctl`
*   `scmi_tlm_des_read_ioctl`
*   `scmi_tlm_des_batch_read_ioctl`
*   `scmi_tlm_shmtis_list_get_ioctl`
*   `scmi_tlm_reset_ioctl`

Additionally, we need to look at memory mapping operations:

*   `scmi_tlm_shmti_mmap`

Finally, since the `scmi_tlm_unlocked_ioctl` calls multiple sub-functions, these sub-functions should be included in the fuzzing scope.

Although `scmi_tlm_unlocked_ioctl` is declared static, meaning it might not be directly exported, Syzkaller can still target it effectively by fuzzing the ioctl system call on the character device file. Syzkaller can use this and the other ioctl functions to guide the fuzzer. We should be sure that we have `ARM_SCMI_PROTOCOL` and `ARM_SCMI_SYSTEM_TELEMETRY` enabled to ensure that the driver and its device file are created.

Also important to note is the interaction between our target and `scmi_telemetry_probe`. This is where the character device is created, and this is called when an SCMI device with protocol `SCMI_PROTOCOL_TELEMETRY` is probed. To probe this, we need an SCMI transport, such as `ARM_SCMI_TRANSPORT_VIRTIO`. Even if there is no device instantiated directly, we should still mark this as `WorthFuzzing=true` because it is a new kernel API.

Therefore, the key focus symbols I'll feed to the fuzzer are:

*   `scmi_tlm_unlocked_ioctl`
*   `scmi_tlm_abi_info_get_ioctl`
*   `scmi_tlm_config_get_ioctl`
*   `scmi_tlm_config_set_ioctl`
*   `scmi_tlm_intervals_get_ioctl`
*   `scmi_tlm


4/2 2026/07/25 20:52 tool set-results
0m Args:
{
  "EnableConfigs": [
    "ARM_SCMI_PROTOCOL",
    "ARM_SCMI_SYSTEM_TELEMETRY",
    "ARM_SCMI_DEBUG_PROTOCOLS"
  ],
  "FocusSymbols": [
    "scmi_tlm_unlocked_ioctl",
    "scmi_tlm_abi_info_get_ioctl",
    "scmi_tlm_config_get_ioctl",
    "scmi_tlm_config_set_ioctl",
    "scmi_tlm_intervals_get_ioctl",
    "scmi_tlm_de_config_set_ioctl",
    "scmi_tlm_de_config_get_ioctl",
    "scmi_tlm_de_info_get_ioctl",
    "scmi_tlm_des_list_get_ioctl",
    "scmi_tlm_de_value_get_ioctl",
    "scmi_tlm_grp_info_get_ioctl",
    "scmi_tlm_grp_desc_get_ioctl",
    "scmi_tlm_grps_list_get_ioctl",
    "scmi_tlm_des_read_ioctl",
    "scmi_tlm_des_batch_read_ioctl",
    "scmi_tlm_shmtis_list_get_ioctl",
    "scmi_tlm_reset_ioctl",
    "scmi_tlm_shmti_mmap",
    "scmi_telemetry_dbg_shmti_read"
  ],
  "Reasoning": "The patch introduces a new SCMI System Telemetry driver and protocol, exposing a new character device (`/dev/scmi/tlm_\u003cN\u003e`) with a comprehensive set of ioctls for userspace to interact with the telemetry data. This is a significant new userspace API and core logic that should be fuzzed.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "ARM_SCMI_PROTOCOL",
    "ARM_SCMI_SYSTEM_TELEMETRY",
    "ARM_SCMI_DEBUG_PROTOCOLS"
  ],
  "FocusSymbols": [
    "scmi_tlm_unlocked_ioctl",
    "scmi_tlm_abi_info_get_ioctl",
    "scmi_tlm_config_get_ioctl",
    "scmi_tlm_config_set_ioctl",
    "scmi_tlm_intervals_get_ioctl",
    "scmi_tlm_de_config_set_ioctl",
    "scmi_tlm_de_config_get_ioctl",
    "scmi_tlm_de_info_get_ioctl",
    "scmi_tlm_des_list_get_ioctl",
    "scmi_tlm_de_value_get_ioctl",
    "scmi_tlm_grp_info_get_ioctl",
    "scmi_tlm_grp_desc_get_ioctl",
    "scmi_tlm_grps_list_get_ioctl",
    "scmi_tlm_des_read_ioctl",
    "scmi_tlm_des_batch_read_ioctl",
    "scmi_tlm_shmtis_list_get_ioctl",
    "scmi_tlm_reset_ioctl",
    "scmi_tlm_shmti_mmap",
    "scmi_telemetry_dbg_shmti_read"
  ],
  "Reasoning": "The patch introduces a new SCMI System Telemetry driver and protocol, exposing a new character device (`/dev/scmi/tlm_\u003cN\u003e`) with a comprehensive set of ioctls for userspace to interact with the telemetry data. This is a significant new userspace API and core logic that should be fuzzed.",
  "WorthFuzzing": true
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)