Skip to contentSkip to conversation

Add dynamic CSU register sysfs interface

PATCH In review Ronak Jain 2 participants 4 messages May 20 – May 25 Arm/Zynq architecture

lore
Share & tools
lore

Ronak Jain

author
#0 lore raw

v2 cover Add dynamic CSU register sysfs interface

This patch series adds support for exposing CSU registers through a sysfs interface. The implementation uses dynamic discovery via the PM_QUERY_DATA firmware API to determine available registers at runtime, making the interface flexible and maintainable without requiring kernel changes when firmware capabilities evolve.

Background:

The ZynqMP platform has several CSU registers that are useful for system configuration and debugging. Previously, accessing these registers required direct memory access or custom tools. This series provides a standardized sysfs interface that leverages existing firmware APIs for secure access.

Key Features:

- Dynamic register discovery using PM_QUERY_DATA API
* PM_QID_GET_NODE_COUNT: Query number of available registers
* PM_QID_GET_NODE_NAME: Query register names by index
- Automatic sysfs attribute creation under csu_registers/ group
- Read operations via existing IOCTL_READ_REG firmware API
- Write operations via existing IOCTL_MASK_WRITE_REG firmware API
- Firmware-enforced access control for read-only registers

Currently Supported Registers:

- multiboot (CSU_MULTI_BOOT): Boot mode configuration
- idcode (CSU_IDCODE): Device identification (read-only)
- pcap-status (CSU_PCAP_STATUS): PCAP status (read-only)

The sysfs interface is available at:
/sys/devices/platform/firmware:zynqmp-firmware/csu_registers/

Usage Examples:

Reading a register:

  # cat /sys/devices/platform/firmware:zynqmp-firmware/csu_registers/idcode

Writing a register (mask and value in hex):

  # echo "0xFFFFFFFF 0x0" > /sys/devices/platform/firmware:zynqmp-firmware/csu_registers/multiboot

Testing:

- Verified register read operations return correct values
- Verified write operations update registers correctly
- Verified read-only registers reject write attempts
- Verified dynamic discovery works with different firmware versions

Changes in v2:
Patch #1
- Update date

Patch #2:
- Removed unused csu_reg_count field from struct zynqmp_csu_data and its kernel-doc entry.
- Added explicit devm_kfree() on the csu_regs and attrs allocation failure paths, plus on devm_device_add_group() failure — keeps the footprint minimal when CSU is optional.
- Expanded the 0644 sysfs-mode inline comment into a block comment explaining the firmware-enforced access-control limitation.Also, update the commit message accordingly.
- Added zynqmp_pm_is_function_supported check for PM_QID_GET_NODE_NAME ID to mirror the PM_QID_GET_NODE_COUNT verification.

Ronak Jain (2):
Documentation: ABI: add sysfs interface for ZynqMP CSU registers
firmware: zynqmp: Add dynamic CSU register discovery and sysfs
interface

 .../ABI/stable/sysfs-driver-firmware-zynqmp   |  33 +++
 MAINTAINERS                                   |  10 +
 drivers/firmware/xilinx/Makefile              |   2 +-
 drivers/firmware/xilinx/zynqmp-csu-reg.c      | 258 ++++++++++++++++++
 drivers/firmware/xilinx/zynqmp-csu-reg.h      |  18 ++
 drivers/firmware/xilinx/zynqmp.c              |   6 +
 include/linux/firmware/xlnx-zynqmp.h          |   4 +-
 7 files changed, 329 insertions(+), 2 deletions(-)
 create mode 100644 drivers/firmware/xilinx/zynqmp-csu-reg.c
 create mode 100644 drivers/firmware/xilinx/zynqmp-csu-reg.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/2 Documentation: ABI: add sysfs interface for ZynqMP CSU registers

Document the new sysfs interface that exposes Configuration Security Unit (CSU) registers through the zynqmp-firmware driver.

The interface is available under:

/sys/devices/platform/firmware:zynqmp-firmware/csu_registers/

The CSU registers are discovered at boot time using the PM_QUERY_DATA firmware API. The following registers are currently supported:

  - multiboot     (CSU_MULTI_BOOT)
  - idcode        (CSU_IDCODE, read-only)
  - pcap-status   (CSU_PCAP_STATUS, read-only)

Read operations use the existing IOCTL_READ_REG firmware interface, while write operations use IOCTL_MASK_WRITE_REG.

Access control is enforced by the firmware. Write attempts to read-only registers are rejected by firmware even though the sysfs file permissions allow writes.

Document the ABI entry accordingly.

---
 .../ABI/stable/sysfs-driver-firmware-zynqmp   | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)
Documentation/ABI/stable/sysfs-driver-firmware-zynqmp +33 -0
index c3fec3c835af..f9b004e33696 100644
@@ -254,3 +254,36 @@ Description:
 		The expected result is 500.
 
 Users:		Xilinx
+
+What:		/sys/devices/platform/firmware\:zynqmp-firmware/csu_registers/*
+Date:		May 2026
+KernelVersion:	7.1
+Contact:	"Ronak Jain" <[email protected]>
+Description:
+		Read/Write CSU (Configuration Security Unit) registers.
+
+		This interface provides dynamic access to CSU registers that are
+		discovered from the firmware at boot time using PM_QUERY_DATA API.
+
+		The supported registers are:
+
+		- multiboot: CSU_MULTI_BOOT register
+		- idcode: CSU_IDCODE register (read-only)
+		- pcap-status: CSU_PCAP_STATUS register (read-only)
+
+		Read operations use the existing IOCTL_READ_REG API.
+		Write operations use the existing IOCTL_MASK_WRITE_REG API.
+
+		The firmware enforces access control - read-only registers will reject
+		write attempts even though the sysfs permissions show write access.
+
+		Usage for reading::
+
+		    # cat /sys/devices/platform/firmware\:zynqmp-firmware/csu_registers/multiboot
+		    # cat /sys/devices/platform/firmware\:zynqmp-firmware/csu_registers/idcode
+
+		Usage for writing (mask and value are in hexadecimal)::
+
+		    # echo 0xFFFFFFF 0x0 > /sys/devices/platform/firmware\:zynqmp-firmware/csu_registers/multiboot
+
+Users:		Xilinx/AMD
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/2 firmware: zynqmp: Add dynamic CSU register discovery and sysfs interface

In reply to Ronak Jain

Add support for dynamically discovering and exposing Configuration Security Unit (CSU) registers through sysfs. Leverage the existing PM_QUERY_DATA API to discover available registers at runtime, making the interface flexible and maintainable.

Key features:
- Dynamic register discovery using PM_QUERY_DATA API
* PM_QID_GET_NODE_COUNT: Query number of available registers
* PM_QID_GET_NODE_NAME: Query register names by index
- Automatic sysfs attribute creation under csu_registers/ group
- Read operations via existing IOCTL_READ_REG API
- Write operations via existing IOCTL_MASK_WRITE_REG API

The sysfs interface is created at:
/sys/devices/platform/firmware:zynqmp-firmware/csu_registers/

Currently supported registers include:
- multiboot (CSU_MULTI_BOOT)
- idcode (CSU_IDCODE, read-only)
- pcap-status (CSU_PCAP_STATUS, read-only)

The dynamic discovery approach allows firmware to control which registers are exposed without requiring kernel changes, improving maintainability and security.

The firmware does not currently expose per-register access mode information, so the kernel cannot distinguish read-only registers from read-write ones at discovery time. All discovered registers are therefore created with sysfs mode 0644, and the firmware is responsible for rejecting writes to registers it treats as read-only (for example idcode and pcap-status); that error is propagated back to userspace from the store callback. If a per-register access-mode query is added to the firmware in the future, sysfs permissions can be tightened to match.

CSU register discovery is an optional feature: on firmware that lacks support for PM_QID_GET_NODE_COUNT or PM_QID_GET_NODE_NAME, the probe returns gracefully without exposing any sysfs entries. To keep the memory footprint minimal on that path, partial devm allocations made during discovery are explicitly released on failure so that no memory lingers until device unbind when the feature is unavailable.

---
 MAINTAINERS                              |  10 +
 drivers/firmware/xilinx/Makefile         |   2 +-
 drivers/firmware/xilinx/zynqmp-csu-reg.c | 258 +++++++++++++++++++++++
 drivers/firmware/xilinx/zynqmp-csu-reg.h |  18 ++
 drivers/firmware/xilinx/zynqmp.c         |   6 +
 include/linux/firmware/xlnx-zynqmp.h     |   4 +-
 6 files changed, 296 insertions(+), 2 deletions(-)
 create mode 100644 drivers/firmware/xilinx/zynqmp-csu-reg.c
 create mode 100644 drivers/firmware/xilinx/zynqmp-csu-reg.h
MAINTAINERS +10 -0
index b3e05a3186aa..f1b42935b40d 100644
@@ -29490,6 +29490,16 @@ F:	drivers/dma/xilinx/xdma.c
 F:	include/linux/dma/amd_xdma.h
 F:	include/linux/platform_data/amd_xdma.h
 
+XILINX ZYNQMP CSU REGISTER DRIVER
+M:	Senthil Nathan Thangaraj <[email protected]>
+R:	Michal Simek <[email protected]>
+R:	Ronak Jain <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
+F:	drivers/firmware/xilinx/zynqmp-csu-reg.c
+F:	drivers/firmware/xilinx/zynqmp-csu-reg.h
+
 XILINX ZYNQMP DPDMA DRIVER
 M:	Laurent Pinchart <[email protected]>
 L:	[email protected]
drivers/firmware/xilinx/Makefile +1 -1
index 8db0e66b6b7e..6203f41daaa6 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for Xilinx firmwares
 
-obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp.o zynqmp-ufs.o zynqmp-crypto.o
+obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp.o zynqmp-ufs.o zynqmp-crypto.o zynqmp-csu-reg.o
 obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
drivers/firmware/xilinx/zynqmp-csu-reg.c new file +258 -0

258 lines not on this page · raw message

drivers/firmware/xilinx/zynqmp-csu-reg.h new file +18 -0
new file mode 100644
index 000000000000..b12415db3496
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Xilinx Zynq MPSoC CSU Register Access
+ *
+ * Copyright (C) 2026 Advanced Micro Devices, Inc.
+ *
+ *  Michal Simek <[email protected]>
+ *  Ronak Jain <[email protected]>
+ */
+
+#ifndef __ZYNQMP_CSU_REG_H__
+#define __ZYNQMP_CSU_REG_H__
+
+#include <linux/platform_device.h>
+
+int zynqmp_csu_discover_registers(struct platform_device *pdev);
+
+#endif /* __ZYNQMP_CSU_REG_H__ */
drivers/firmware/xilinx/zynqmp.c +6 -0
index af838b2dc327..155a7a9b3777 100644
@@ -27,6 +27,7 @@
 
 #include <linux/firmware/xlnx-zynqmp.h>
 #include <linux/firmware/xlnx-event-manager.h>
+#include "zynqmp-csu-reg.h"
 #include "zynqmp-debug.h"
 
 /* Max HashMap Order for PM API feature check (1<<7 = 128) */
@@ -2148,6 +2149,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)
 			dev_err_probe(&pdev->dev, PTR_ERR(em_dev), "EM register fail with error\n");
 	}
 
+	/* Discover CSU registers dynamically */
+	ret = zynqmp_csu_discover_registers(pdev);
+	if (ret)
+		dev_warn(&pdev->dev, "CSU register discovery failed: %d\n", ret);
+
 	return of_platform_populate(dev->of_node, NULL, NULL, dev);
 }
 
include/linux/firmware/xlnx-zynqmp.h +3 -1
index 7e27b0f7bf7e..a956e315be82 100644
@@ -3,7 +3,7 @@
  * Xilinx Zynq MPSoC Firmware layer
  *
  *  Copyright (C) 2014-2021 Xilinx
- *  Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc.
+ *  Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
  *
  *  Michal Simek <[email protected]>
  *  Davorin Mista <[email protected]>
@@ -262,6 +262,8 @@ enum pm_query_id {
 	PM_QID_CLOCK_GET_NUM_CLOCKS = 12,
 	PM_QID_CLOCK_GET_MAX_DIVISOR = 13,
 	PM_QID_PINCTRL_GET_ATTRIBUTES = 15,
+	PM_QID_GET_NODE_NAME = 16,
+	PM_QID_GET_NODE_COUNT = 17,
 };
 
 enum rpu_oper_mode {
Signature · 1 line
2.34.1
maintainer
#3 lore raw
In reply to Ronak Jain
Quoted 78 lines · Ronak Jain

This patch series adds support for exposing CSU registers through a sysfs interface. The implementation uses dynamic discovery via the PM_QUERY_DATA firmware API to determine available registers at runtime, making the interface flexible and maintainable without requiring kernel changes when firmware capabilities evolve.

Background:

The ZynqMP platform has several CSU registers that are useful for system configuration and debugging. Previously, accessing these registers required direct memory access or custom tools. This series provides a standardized sysfs interface that leverages existing firmware APIs for secure access.

Key Features:

- Dynamic register discovery using PM_QUERY_DATA API
* PM_QID_GET_NODE_COUNT: Query number of available registers
* PM_QID_GET_NODE_NAME: Query register names by index
- Automatic sysfs attribute creation under csu_registers/ group
- Read operations via existing IOCTL_READ_REG firmware API
- Write operations via existing IOCTL_MASK_WRITE_REG firmware API
- Firmware-enforced access control for read-only registers

Currently Supported Registers:

- multiboot (CSU_MULTI_BOOT): Boot mode configuration
- idcode (CSU_IDCODE): Device identification (read-only)
- pcap-status (CSU_PCAP_STATUS): PCAP status (read-only)

The sysfs interface is available at:
/sys/devices/platform/firmware:zynqmp-firmware/csu_registers/

Usage Examples:

Reading a register:

   # cat /sys/devices/platform/firmware:zynqmp-firmware/csu_registers/idcode

Writing a register (mask and value in hex):

   # echo "0xFFFFFFFF 0x0" > /sys/devices/platform/firmware:zynqmp-firmware/csu_registers/multiboot

Testing:

- Verified register read operations return correct values
- Verified write operations update registers correctly
- Verified read-only registers reject write attempts
- Verified dynamic discovery works with different firmware versions

Changes in v2:
Patch #1
- Update date

Patch #2:
- Removed unused csu_reg_count field from struct zynqmp_csu_data and its kernel-doc entry.
- Added explicit devm_kfree() on the csu_regs and attrs allocation failure paths, plus on devm_device_add_group() failure — keeps the footprint minimal when CSU is optional.
- Expanded the 0644 sysfs-mode inline comment into a block comment explaining the firmware-enforced access-control limitation.Also, update the commit message accordingly.
- Added zynqmp_pm_is_function_supported check for PM_QID_GET_NODE_NAME ID to mirror the PM_QID_GET_NODE_COUNT verification.

Ronak Jain (2):
Documentation: ABI: add sysfs interface for ZynqMP CSU registers
firmware: zynqmp: Add dynamic CSU register discovery and sysfs
interface

  .../ABI/stable/sysfs-driver-firmware-zynqmp   |  33 +++
  MAINTAINERS                                   |  10 +
  drivers/firmware/xilinx/Makefile              |   2 +-
  drivers/firmware/xilinx/zynqmp-csu-reg.c      | 258 ++++++++++++++++++
  drivers/firmware/xilinx/zynqmp-csu-reg.h      |  18 ++
  drivers/firmware/xilinx/zynqmp.c              |   6 +
  include/linux/firmware/xlnx-zynqmp.h          |   4 +-
  7 files changed, 329 insertions(+), 2 deletions(-)
Quoted 3 lines

create mode 100644 drivers/firmware/xilinx/zynqmp-csu-reg.c create mode 100644 drivers/firmware/xilinx/zynqmp-csu-reg.h

Applied with kernel version changed to 7.2.

Thanks,
Michal