* [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components
@ 2026-11-27 11:48 Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 1/5] drivers: firmware: xilinx: Relocate PDI library APIs to new file Jay Buddhabhatti
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Jay Buddhabhatti @ 2026-11-27 11:48 UTC (permalink / raw)
To: Michal Simek
Cc: Jay Buddhabhatti, Ronak Jain, Aravind Thokala, Harsh Jain,
linux-arm-kernel, linux-kernel, git
Split the ZynqMP firmware driver into focused modules to improve
maintainability and clarify ownership of each firmware interface. The
driver mixes platform core infrastructure, PM EEMI APIs, PDI loading,
FPGA management, and NVM access in one large file.
This series applies on top of "firmware: xilinx: cleanups and debugfs
fixes":
https://lore.kernel.org/all/cover.1795094242.git.michal.simek@amd.com/
Split the driver incrementally and keep each patch reviewable:
- Move PDI library APIs into zynqmp-pdi.c with a dedicated header.
- Move FPGA library APIs into zynqmp-fpga.c with a dedicated header.
- Move NVM library APIs into zynqmp-nvm.c with a dedicated header.
- Localize the firmware version caches.
- Split core platform/SMC infrastructure (zynqmp-core.c) from PM EEMI
APIs (zynqmp-pm.c).
Jay Buddhabhatti (1):
drivers: firmware: xilinx: Localize firmware version caches
Ronak Jain (4):
drivers: firmware: xilinx: Relocate PDI library APIs to new file
drivers: firmware: xilinx: Relocate FPGA library APIs to new file
drivers: firmware: xilinx: Relocate NVM library APIs to new file
drivers: firmware: xilinx: Split PM EEMI and core APIs in firmware
MAINTAINERS | 28 +
drivers/firmware/xilinx/Makefile | 4 +-
drivers/firmware/xilinx/zynqmp-core.c | 797 +++++++++++++++
drivers/firmware/xilinx/zynqmp-debug.h | 20 +
drivers/firmware/xilinx/zynqmp-fpga.c | 89 ++
drivers/firmware/xilinx/zynqmp-nvm.c | 35 +
drivers/firmware/xilinx/zynqmp-pdi.c | 27 +
.../firmware/xilinx/{zynqmp.c => zynqmp-pm.c} | 937 +-----------------
include/linux/firmware/xlnx-zynqmp-fpga.h | 55 +
include/linux/firmware/xlnx-zynqmp-nvm.h | 28 +
include/linux/firmware/xlnx-zynqmp-pdi.h | 34 +
include/linux/firmware/xlnx-zynqmp.h | 52 +-
12 files changed, 1134 insertions(+), 972 deletions(-)
create mode 100644 drivers/firmware/xilinx/zynqmp-core.c
create mode 100644 drivers/firmware/xilinx/zynqmp-fpga.c
create mode 100644 drivers/firmware/xilinx/zynqmp-nvm.c
create mode 100644 drivers/firmware/xilinx/zynqmp-pdi.c
rename drivers/firmware/xilinx/{zynqmp.c => zynqmp-pm.c} (63%)
create mode 100644 include/linux/firmware/xlnx-zynqmp-fpga.h
create mode 100644 include/linux/firmware/xlnx-zynqmp-nvm.h
create mode 100644 include/linux/firmware/xlnx-zynqmp-pdi.h
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] drivers: firmware: xilinx: Relocate PDI library APIs to new file
2026-11-27 11:48 [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components Jay Buddhabhatti
@ 2026-11-27 11:48 ` Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 2/5] drivers: firmware: xilinx: Relocate FPGA " Jay Buddhabhatti
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jay Buddhabhatti @ 2026-11-27 11:48 UTC (permalink / raw)
To: Michal Simek
Cc: Ronak Jain, Aravind Thokala, Harsh Jain, linux-arm-kernel,
linux-kernel, git, Jay Buddhabhatti
From: Ronak Jain <ronak.jain@amd.com>
Move the PDI library APIs into a dedicated file and header to improve
maintainability and reduce complexity in the firmware driver. Keep the
existing behavior unchanged.
Add a MAINTAINERS entry for the FPGA and PDI firmware files. List the
new PDI files in that entry.
Signed-off-by: Ronak Jain <ronak.jain@amd.com>
Co-developed-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
Signed-off-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
---
MAINTAINERS | 7 +++++
drivers/firmware/xilinx/Makefile | 3 ++-
drivers/firmware/xilinx/zynqmp-pdi.c | 27 +++++++++++++++++++
drivers/firmware/xilinx/zynqmp.c | 16 -----------
include/linux/firmware/xlnx-zynqmp-pdi.h | 34 ++++++++++++++++++++++++
include/linux/firmware/xlnx-zynqmp.h | 13 ++-------
6 files changed, 72 insertions(+), 28 deletions(-)
create mode 100644 drivers/firmware/xilinx/zynqmp-pdi.c
create mode 100644 include/linux/firmware/xlnx-zynqmp-pdi.h
diff --git a/MAINTAINERS b/MAINTAINERS
index c72a281a8167..9dfdb7ade5f6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30666,6 +30666,13 @@ S: Maintained
F: drivers/soc/xilinx/xlnx_event_manager.c
F: include/linux/firmware/xlnx-event-manager.h
+XILINX FPGA AND PDI FIRMWARE DRIVER
+M: Aravind Thokala <Aravind.Thokala@amd.com>
+L: git@amd.com
+S: Maintained
+F: drivers/firmware/xilinx/zynqmp-pdi.c
+F: include/linux/firmware/xlnx-zynqmp-pdi.h
+
XILINX GPIO DRIVER
M: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
R: Srinivas Neeli <srinivas.neeli@amd.com>
diff --git a/drivers/firmware/xilinx/Makefile b/drivers/firmware/xilinx/Makefile
index 8db0e66b6b7e..684c3d43744e 100644
--- a/drivers/firmware/xilinx/Makefile
+++ b/drivers/firmware/xilinx/Makefile
@@ -1,5 +1,6 @@
# 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-crypto.o zynqmp-pdi.o \
+ zynqmp-ufs.o zynqmp.o
obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
diff --git a/drivers/firmware/xilinx/zynqmp-pdi.c b/drivers/firmware/xilinx/zynqmp-pdi.c
new file mode 100644
index 000000000000..58085e9fdede
--- /dev/null
+++ b/drivers/firmware/xilinx/zynqmp-pdi.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Firmware layer for XilPDI APIs.
+ *
+ * Copyright (C) 2014 - 2022 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/export.h>
+#include <linux/firmware/xlnx-zynqmp.h>
+#include <linux/kernel.h>
+
+/**
+ * zynqmp_pm_load_pdi - Load and process PDI
+ * @src: Source device where PDI is located
+ * @address: PDI src address
+ *
+ * This function provides support to load PDI from Linux
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_load_pdi(const u32 src, const u64 address)
+{
+ return zynqmp_pm_invoke_fn(PM_LOAD_PDI, NULL, 3, src, lower_32_bits(address),
+ upper_32_bits(address));
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_load_pdi);
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index e89251dab9a0..bebd2bfe5744 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1675,22 +1675,6 @@ int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
}
EXPORT_SYMBOL_GPL(zynqmp_pm_set_requirement);
-/**
- * zynqmp_pm_load_pdi - Load and process PDI
- * @src: Source device where PDI is located
- * @address: PDI src address
- *
- * This function provides support to load PDI from linux
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_load_pdi(const u32 src, const u64 address)
-{
- return zynqmp_pm_invoke_fn(PM_LOAD_PDI, NULL, 3, src, lower_32_bits(address),
- upper_32_bits(address));
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_load_pdi);
-
/**
* zynqmp_pm_efuse_access - Provides access to efuse memory.
* @address: Address of the efuse params structure
diff --git a/include/linux/firmware/xlnx-zynqmp-pdi.h b/include/linux/firmware/xlnx-zynqmp-pdi.h
new file mode 100644
index 000000000000..c7e00c255d51
--- /dev/null
+++ b/include/linux/firmware/xlnx-zynqmp-pdi.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Firmware layer for XilPDI APIs.
+ *
+ * Copyright (C) 2014 - 2021 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#ifndef __FIRMWARE_ZYNQMP_PDI_H__
+#define __FIRMWARE_ZYNQMP_PDI_H__
+
+#ifndef __FIRMWARE_ZYNQMP_H__
+# error "Do not include this file directly, use <linux/firmware/xlnx-zynqmp.h>"
+#endif
+
+#include <linux/errno.h>
+#include <linux/types.h>
+
+/* Loader command */
+#define PM_LOAD_PDI 0x701
+
+/* PDI source identifier */
+#define PDI_SRC_DDR 0xF
+
+#if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE)
+int zynqmp_pm_load_pdi(const u32 src, const u64 address);
+#else
+static inline int zynqmp_pm_load_pdi(const u32 src, const u64 address)
+{
+ return -ENODEV;
+}
+#endif
+
+#endif /* __FIRMWARE_ZYNQMP_PDI_H__ */
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index b489fbd21bd2..cffec74a0436 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -16,8 +16,9 @@
#include <linux/types.h>
#include <linux/err.h>
-#include <linux/firmware/xlnx-zynqmp-ufs.h>
#include <linux/firmware/xlnx-zynqmp-crypto.h>
+#include <linux/firmware/xlnx-zynqmp-pdi.h>
+#include <linux/firmware/xlnx-zynqmp-ufs.h>
#define ZYNQMP_PM_VERSION_MAJOR 1
#define ZYNQMP_PM_VERSION_MINOR 0
@@ -101,10 +102,6 @@
#define ZYNQMP_PM_CAPABILITY_WAKEUP 0x4U
#define ZYNQMP_PM_CAPABILITY_UNUSABLE 0x8U
-/* Loader commands */
-#define PM_LOAD_PDI 0x701
-#define PDI_SRC_DDR 0xF
-
/*
* Firmware FPGA Manager flags
* XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
@@ -626,7 +623,6 @@ int zynqmp_pm_pinctrl_get_config(const u32 pin, const u32 param,
u32 *value);
int zynqmp_pm_pinctrl_set_config(const u32 pin, const u32 param,
u32 value);
-int zynqmp_pm_load_pdi(const u32 src, const u64 address);
int zynqmp_pm_register_notifier(const u32 node, const u32 event,
const u32 wake, const u32 enable);
int zynqmp_pm_feature(const u32 api_id);
@@ -881,11 +877,6 @@ static inline int zynqmp_pm_pinctrl_set_config(const u32 pin, const u32 param,
return -ENODEV;
}
-static inline int zynqmp_pm_load_pdi(const u32 src, const u64 address)
-{
- return -ENODEV;
-}
-
static inline int zynqmp_pm_register_notifier(const u32 node, const u32 event,
const u32 wake, const u32 enable)
{
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/5] drivers: firmware: xilinx: Relocate FPGA library APIs to new file
2026-11-27 11:48 [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 1/5] drivers: firmware: xilinx: Relocate PDI library APIs to new file Jay Buddhabhatti
@ 2026-11-27 11:48 ` Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 3/5] drivers: firmware: xilinx: Relocate NVM " Jay Buddhabhatti
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jay Buddhabhatti @ 2026-11-27 11:48 UTC (permalink / raw)
To: Michal Simek
Cc: Ronak Jain, Aravind Thokala, Harsh Jain, linux-arm-kernel,
linux-kernel, git, Jay Buddhabhatti
From: Ronak Jain <ronak.jain@amd.com>
Move the FPGA library APIs into a dedicated file and header to improve
maintainability and reduce complexity in the firmware driver. Keep the
existing behavior unchanged.
List the new FPGA files in the FPGA and PDI firmware MAINTAINERS entry.
Signed-off-by: Ronak Jain <ronak.jain@amd.com>
Co-developed-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
Signed-off-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
---
MAINTAINERS | 2 +
drivers/firmware/xilinx/Makefile | 4 +-
drivers/firmware/xilinx/zynqmp-fpga.c | 89 +++++++++++++++++++++++
drivers/firmware/xilinx/zynqmp.c | 78 --------------------
include/linux/firmware/xlnx-zynqmp-fpga.h | 55 ++++++++++++++
include/linux/firmware/xlnx-zynqmp.h | 32 +-------
6 files changed, 149 insertions(+), 111 deletions(-)
create mode 100644 drivers/firmware/xilinx/zynqmp-fpga.c
create mode 100644 include/linux/firmware/xlnx-zynqmp-fpga.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 9dfdb7ade5f6..8caad731367b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30670,7 +30670,9 @@ XILINX FPGA AND PDI FIRMWARE DRIVER
M: Aravind Thokala <Aravind.Thokala@amd.com>
L: git@amd.com
S: Maintained
+F: drivers/firmware/xilinx/zynqmp-fpga.c
F: drivers/firmware/xilinx/zynqmp-pdi.c
+F: include/linux/firmware/xlnx-zynqmp-fpga.h
F: include/linux/firmware/xlnx-zynqmp-pdi.h
XILINX GPIO DRIVER
diff --git a/drivers/firmware/xilinx/Makefile b/drivers/firmware/xilinx/Makefile
index 684c3d43744e..edfba4110a7c 100644
--- a/drivers/firmware/xilinx/Makefile
+++ b/drivers/firmware/xilinx/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for Xilinx firmwares
-obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp-crypto.o zynqmp-pdi.o \
- zynqmp-ufs.o zynqmp.o
+obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp-crypto.o zynqmp-fpga.o \
+ zynqmp-pdi.o zynqmp-ufs.o zynqmp.o
obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
diff --git a/drivers/firmware/xilinx/zynqmp-fpga.c b/drivers/firmware/xilinx/zynqmp-fpga.c
new file mode 100644
index 000000000000..2a3ac3a50c56
--- /dev/null
+++ b/drivers/firmware/xilinx/zynqmp-fpga.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Firmware layer for XilFPGA APIs.
+ *
+ * Copyright (C) 2014 - 2022 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/export.h>
+#include <linux/firmware/xlnx-zynqmp.h>
+#include <linux/kernel.h>
+
+/**
+ * zynqmp_pm_fpga_load - Perform the fpga load
+ * @address: Address to write to
+ * @size: pl bitstream size
+ * @flags: Bitstream type
+ * -XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
+ * -XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
+ *
+ * This function provides access to pmufw. To transfer
+ * the required bitstream into PL.
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags)
+{
+ u32 ret_payload[PAYLOAD_ARG_CNT];
+ int ret;
+
+ ret = zynqmp_pm_invoke_fn(PM_FPGA_LOAD, ret_payload, 4, lower_32_bits(address),
+ upper_32_bits(address), size, flags);
+ if (ret_payload[0])
+ return -ret_payload[0];
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_load);
+
+/**
+ * zynqmp_pm_fpga_get_status - Read value from PCAP status register
+ * @value: Value to read
+ *
+ * This function provides access to the pmufw to get the PCAP
+ * status.
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_fpga_get_status(u32 *value)
+{
+ u32 ret_payload[PAYLOAD_ARG_CNT];
+ int ret;
+
+ if (!value)
+ return -EINVAL;
+
+ ret = zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS, ret_payload, 0);
+ *value = ret_payload[1];
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
+
+/**
+ * zynqmp_pm_fpga_get_config_status - Get the FPGA configuration status.
+ * @value: Buffer to store FPGA configuration status.
+ *
+ * This function provides access to the pmufw to get the FPGA configuration
+ * status.
+ *
+ * Return: 0 on success, a negative value on error
+ */
+int zynqmp_pm_fpga_get_config_status(u32 *value)
+{
+ u32 ret_payload[PAYLOAD_ARG_CNT];
+ int ret;
+
+ if (!value)
+ return -EINVAL;
+
+ ret = zynqmp_pm_invoke_fn(PM_FPGA_READ, ret_payload, 4,
+ XILINX_ZYNQMP_PM_FPGA_CONFIG_STAT_OFFSET, 0, 0,
+ XILINX_ZYNQMP_PM_FPGA_READ_CONFIG_REG);
+
+ *value = ret_payload[1];
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_config_status);
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index bebd2bfe5744..fe887d5e9354 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1087,84 +1087,6 @@ int zynqmp_pm_reset_get_status(const u32 reset, u32 *status)
}
EXPORT_SYMBOL_GPL(zynqmp_pm_reset_get_status);
-/**
- * zynqmp_pm_fpga_load - Perform the fpga load
- * @address: Address to write to
- * @size: pl bitstream size
- * @flags: Bitstream type
- * -XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
- * -XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
- *
- * This function provides access to pmufw. To transfer
- * the required bitstream into PL.
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags)
-{
- u32 ret_payload[PAYLOAD_ARG_CNT];
- int ret;
-
- ret = zynqmp_pm_invoke_fn(PM_FPGA_LOAD, ret_payload, 4, lower_32_bits(address),
- upper_32_bits(address), size, flags);
- if (ret_payload[0])
- return -ret_payload[0];
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_load);
-
-/**
- * zynqmp_pm_fpga_get_status - Read value from PCAP status register
- * @value: Value to read
- *
- * This function provides access to the pmufw to get the PCAP
- * status
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_fpga_get_status(u32 *value)
-{
- u32 ret_payload[PAYLOAD_ARG_CNT];
- int ret;
-
- if (!value)
- return -EINVAL;
-
- ret = zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS, ret_payload, 0);
- *value = ret_payload[1];
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
-
-/**
- * zynqmp_pm_fpga_get_config_status - Get the FPGA configuration status.
- * @value: Buffer to store FPGA configuration status.
- *
- * This function provides access to the pmufw to get the FPGA configuration
- * status
- *
- * Return: 0 on success, a negative value on error
- */
-int zynqmp_pm_fpga_get_config_status(u32 *value)
-{
- u32 ret_payload[PAYLOAD_ARG_CNT];
- int ret;
-
- if (!value)
- return -EINVAL;
-
- ret = zynqmp_pm_invoke_fn(PM_FPGA_READ, ret_payload, 4,
- XILINX_ZYNQMP_PM_FPGA_CONFIG_STAT_OFFSET, 0, 0,
- XILINX_ZYNQMP_PM_FPGA_READ_CONFIG_REG);
-
- *value = ret_payload[1];
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_config_status);
-
/**
* zynqmp_pm_pinctrl_request - Request Pin from firmware
* @pin: Pin number to request
diff --git a/include/linux/firmware/xlnx-zynqmp-fpga.h b/include/linux/firmware/xlnx-zynqmp-fpga.h
new file mode 100644
index 000000000000..2e0b1dc084d1
--- /dev/null
+++ b/include/linux/firmware/xlnx-zynqmp-fpga.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Firmware layer for XilFPGA APIs.
+ *
+ * Copyright (C) 2014 - 2021 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#ifndef __FIRMWARE_ZYNQMP_FPGA_H__
+#define __FIRMWARE_ZYNQMP_FPGA_H__
+
+#ifndef __FIRMWARE_ZYNQMP_H__
+# error "Do not include this file directly, use <linux/firmware/xlnx-zynqmp.h>"
+#endif
+
+#include <linux/bits.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+
+/*
+ * Firmware FPGA Manager flags
+ * XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
+ * XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
+ */
+#define XILINX_ZYNQMP_PM_FPGA_FULL 0x0U
+#define XILINX_ZYNQMP_PM_FPGA_PARTIAL BIT(0)
+
+/* FPGA Status Reg */
+#define XILINX_ZYNQMP_PM_FPGA_CONFIG_STAT_OFFSET 7U
+#define XILINX_ZYNQMP_PM_FPGA_READ_CONFIG_REG 0U
+
+#if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE)
+int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags);
+int zynqmp_pm_fpga_get_status(u32 *value);
+int zynqmp_pm_fpga_get_config_status(u32 *value);
+#else
+static inline int zynqmp_pm_fpga_load(const u64 address, const u32 size,
+ const u32 flags)
+{
+ return -ENODEV;
+}
+
+static inline int zynqmp_pm_fpga_get_status(u32 *value)
+{
+ return -ENODEV;
+}
+
+static inline int zynqmp_pm_fpga_get_config_status(u32 *value)
+{
+ return -ENODEV;
+}
+
+#endif
+
+#endif /* __FIRMWARE_ZYNQMP_FPGA_H__ */
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index cffec74a0436..5038c9051dca 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -17,6 +17,7 @@
#include <linux/err.h>
#include <linux/firmware/xlnx-zynqmp-crypto.h>
+#include <linux/firmware/xlnx-zynqmp-fpga.h>
#include <linux/firmware/xlnx-zynqmp-pdi.h>
#include <linux/firmware/xlnx-zynqmp-ufs.h>
@@ -102,18 +103,6 @@
#define ZYNQMP_PM_CAPABILITY_WAKEUP 0x4U
#define ZYNQMP_PM_CAPABILITY_UNUSABLE 0x8U
-/*
- * Firmware FPGA Manager flags
- * XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
- * XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
- */
-#define XILINX_ZYNQMP_PM_FPGA_FULL 0x0U
-#define XILINX_ZYNQMP_PM_FPGA_PARTIAL BIT(0)
-
-/* FPGA Status Reg */
-#define XILINX_ZYNQMP_PM_FPGA_CONFIG_STAT_OFFSET 7U
-#define XILINX_ZYNQMP_PM_FPGA_READ_CONFIG_REG 0U
-
/*
* Node IDs for the Error Events.
*/
@@ -606,9 +595,6 @@ int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
const u32 qos,
const enum zynqmp_pm_request_ack ack);
int zynqmp_pm_efuse_access(const u64 address, u32 *out);
-int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags);
-int zynqmp_pm_fpga_get_status(u32 *value);
-int zynqmp_pm_fpga_get_config_status(u32 *value);
int zynqmp_pm_write_ggs(u32 index, u32 value);
int zynqmp_pm_read_ggs(u32 index, u32 *value);
int zynqmp_pm_write_pggs(u32 index, u32 value);
@@ -794,22 +780,6 @@ static inline int zynqmp_pm_efuse_access(const u64 address, u32 *out)
return -ENODEV;
}
-static inline int zynqmp_pm_fpga_load(const u64 address, const u32 size,
- const u32 flags)
-{
- return -ENODEV;
-}
-
-static inline int zynqmp_pm_fpga_get_status(u32 *value)
-{
- return -ENODEV;
-}
-
-static inline int zynqmp_pm_fpga_get_config_status(u32 *value)
-{
- return -ENODEV;
-}
-
static inline int zynqmp_pm_write_ggs(u32 index, u32 value)
{
return -ENODEV;
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] drivers: firmware: xilinx: Relocate NVM library APIs to new file
2026-11-27 11:48 [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 1/5] drivers: firmware: xilinx: Relocate PDI library APIs to new file Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 2/5] drivers: firmware: xilinx: Relocate FPGA " Jay Buddhabhatti
@ 2026-11-27 11:48 ` Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 4/5] drivers: firmware: xilinx: Localize firmware version caches Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 5/5] drivers: firmware: xilinx: Split PM EEMI and core APIs in firmware Jay Buddhabhatti
4 siblings, 0 replies; 6+ messages in thread
From: Jay Buddhabhatti @ 2026-11-27 11:48 UTC (permalink / raw)
To: Michal Simek
Cc: Ronak Jain, Aravind Thokala, Harsh Jain, linux-arm-kernel,
linux-kernel, git, Jay Buddhabhatti
From: Ronak Jain <ronak.jain@amd.com>
Move the NVM library APIs into a dedicated file and header to improve
maintainability and reduce complexity in the firmware driver. Keep the
existing behavior unchanged.
Add a MAINTAINERS entry for the crypto and NVM firmware files. Include
the new NVM files and the existing crypto files in that entry.
Signed-off-by: Ronak Jain <ronak.jain@amd.com>
Co-developed-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
Signed-off-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
---
MAINTAINERS | 9 ++++++
drivers/firmware/xilinx/Makefile | 2 +-
drivers/firmware/xilinx/zynqmp-nvm.c | 35 ++++++++++++++++++++++++
drivers/firmware/xilinx/zynqmp.c | 24 ----------------
include/linux/firmware/xlnx-zynqmp-nvm.h | 28 +++++++++++++++++++
include/linux/firmware/xlnx-zynqmp.h | 7 +----
6 files changed, 74 insertions(+), 31 deletions(-)
create mode 100644 drivers/firmware/xilinx/zynqmp-nvm.c
create mode 100644 include/linux/firmware/xlnx-zynqmp-nvm.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 8caad731367b..e010589c13e5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30660,6 +30660,15 @@ S: Maintained
F: Documentation/devicetree/bindings/net/can/xilinx,can.yaml
F: drivers/net/can/xilinx_can.c
+XILINX CRYPTO AND NVM FIRMWARE DRIVER
+M: Harsh Jain <h.jain@amd.com>
+L: git@amd.com
+S: Maintained
+F: drivers/firmware/xilinx/zynqmp-crypto.c
+F: drivers/firmware/xilinx/zynqmp-nvm.c
+F: include/linux/firmware/xlnx-zynqmp-crypto.h
+F: include/linux/firmware/xlnx-zynqmp-nvm.h
+
XILINX EVENT MANAGEMENT DRIVER
M: Michal Simek <michal.simek@amd.com>
S: Maintained
diff --git a/drivers/firmware/xilinx/Makefile b/drivers/firmware/xilinx/Makefile
index edfba4110a7c..d23d41c6a8ac 100644
--- a/drivers/firmware/xilinx/Makefile
+++ b/drivers/firmware/xilinx/Makefile
@@ -2,5 +2,5 @@
# Makefile for Xilinx firmwares
obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp-crypto.o zynqmp-fpga.o \
- zynqmp-pdi.o zynqmp-ufs.o zynqmp.o
+ zynqmp-nvm.o zynqmp-pdi.o zynqmp-ufs.o zynqmp.o
obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
diff --git a/drivers/firmware/xilinx/zynqmp-nvm.c b/drivers/firmware/xilinx/zynqmp-nvm.c
new file mode 100644
index 000000000000..15c646273aee
--- /dev/null
+++ b/drivers/firmware/xilinx/zynqmp-nvm.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Firmware layer for XilNVM APIs.
+ *
+ * Copyright (C) 2014 - 2022 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/export.h>
+#include <linux/firmware/xlnx-zynqmp.h>
+#include <linux/kernel.h>
+
+/**
+ * zynqmp_pm_efuse_access - Provides access to efuse memory.
+ * @address: Address of the efuse params structure
+ * @out: Returned output value
+ *
+ * Return: Returns status, either success or error code.
+ */
+int zynqmp_pm_efuse_access(const u64 address, u32 *out)
+{
+ u32 ret_payload[PAYLOAD_ARG_CNT];
+ int ret;
+
+ if (!out)
+ return -EINVAL;
+
+ ret = zynqmp_pm_invoke_fn(PM_EFUSE_ACCESS, ret_payload, 2,
+ upper_32_bits(address),
+ lower_32_bits(address));
+ *out = ret_payload[1];
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_efuse_access);
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index fe887d5e9354..619ead2069c5 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1597,30 +1597,6 @@ int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
}
EXPORT_SYMBOL_GPL(zynqmp_pm_set_requirement);
-/**
- * zynqmp_pm_efuse_access - Provides access to efuse memory.
- * @address: Address of the efuse params structure
- * @out: Returned output value
- *
- * Return: Returns status, either success or error code.
- */
-int zynqmp_pm_efuse_access(const u64 address, u32 *out)
-{
- u32 ret_payload[PAYLOAD_ARG_CNT];
- int ret;
-
- if (!out)
- return -EINVAL;
-
- ret = zynqmp_pm_invoke_fn(PM_EFUSE_ACCESS, ret_payload, 2,
- upper_32_bits(address),
- lower_32_bits(address));
- *out = ret_payload[1];
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_efuse_access);
-
/**
* zynqmp_pm_register_notifier() - PM API for register a subsystem
* to be notified about specific
diff --git a/include/linux/firmware/xlnx-zynqmp-nvm.h b/include/linux/firmware/xlnx-zynqmp-nvm.h
new file mode 100644
index 000000000000..65dda350b66f
--- /dev/null
+++ b/include/linux/firmware/xlnx-zynqmp-nvm.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Firmware layer for XilNVM APIs.
+ *
+ * Copyright (C) 2014 - 2021 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#ifndef __FIRMWARE_ZYNQMP_NVM_H__
+#define __FIRMWARE_ZYNQMP_NVM_H__
+
+#ifndef __FIRMWARE_ZYNQMP_H__
+# error "Do not include this file directly, use <linux/firmware/xlnx-zynqmp.h>"
+#endif
+
+#include <linux/errno.h>
+#include <linux/types.h>
+
+#if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE)
+int zynqmp_pm_efuse_access(const u64 address, u32 *out);
+#else
+static inline int zynqmp_pm_efuse_access(const u64 address, u32 *out)
+{
+ return -ENODEV;
+}
+#endif
+
+#endif /* __FIRMWARE_ZYNQMP_NVM_H__ */
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 5038c9051dca..852e952fc8e5 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -18,6 +18,7 @@
#include <linux/err.h>
#include <linux/firmware/xlnx-zynqmp-crypto.h>
#include <linux/firmware/xlnx-zynqmp-fpga.h>
+#include <linux/firmware/xlnx-zynqmp-nvm.h>
#include <linux/firmware/xlnx-zynqmp-pdi.h>
#include <linux/firmware/xlnx-zynqmp-ufs.h>
@@ -594,7 +595,6 @@ int zynqmp_pm_release_node(const u32 node);
int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
const u32 qos,
const enum zynqmp_pm_request_ack ack);
-int zynqmp_pm_efuse_access(const u64 address, u32 *out);
int zynqmp_pm_write_ggs(u32 index, u32 value);
int zynqmp_pm_read_ggs(u32 index, u32 *value);
int zynqmp_pm_write_pggs(u32 index, u32 value);
@@ -775,11 +775,6 @@ static inline int zynqmp_pm_set_requirement(const u32 node,
return -ENODEV;
}
-static inline int zynqmp_pm_efuse_access(const u64 address, u32 *out)
-{
- return -ENODEV;
-}
-
static inline int zynqmp_pm_write_ggs(u32 index, u32 value)
{
return -ENODEV;
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] drivers: firmware: xilinx: Localize firmware version caches
2026-11-27 11:48 [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components Jay Buddhabhatti
` (2 preceding siblings ...)
2026-11-27 11:48 ` [PATCH 3/5] drivers: firmware: xilinx: Relocate NVM " Jay Buddhabhatti
@ 2026-11-27 11:48 ` Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 5/5] drivers: firmware: xilinx: Split PM EEMI and core APIs in firmware Jay Buddhabhatti
4 siblings, 0 replies; 6+ messages in thread
From: Jay Buddhabhatti @ 2026-11-27 11:48 UTC (permalink / raw)
To: Michal Simek
Cc: Jay Buddhabhatti, Ronak Jain, Aravind Thokala, Harsh Jain,
linux-arm-kernel, linux-kernel, git
Keep the PM API version cache local to its getter and populate it after
a successful query. The firmware probe now keeps the returned version in
a local variable instead of passing the address of a file-wide cache.
The firmware probe is the only caller of
zynqmp_pm_get_trustzone_version(). Remove the unnecessary trustzone
version cache and keep the returned version local to the probe.
Signed-off-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
---
drivers/firmware/xilinx/zynqmp.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 619ead2069c5..374d39f34480 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -488,9 +488,6 @@ int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
smc_arg[4], smc_arg[5], smc_arg[6], smc_arg[7]);
}
-static u32 pm_api_version;
-static u32 pm_tz_version;
-
int zynqmp_pm_register_sgi(u32 sgi_num, u32 reset)
{
int ret;
@@ -512,6 +509,7 @@ int zynqmp_pm_register_sgi(u32 sgi_num, u32 reset)
int zynqmp_pm_get_api_version(u32 *version)
{
u32 ret_payload[PAYLOAD_ARG_CNT];
+ static u32 pm_api_version;
int ret;
if (!version)
@@ -524,6 +522,8 @@ int zynqmp_pm_get_api_version(u32 *version)
}
ret = zynqmp_pm_invoke_fn(PM_GET_API_VERSION, ret_payload, 0);
*version = ret_payload[1];
+ if (!ret)
+ pm_api_version = ret_payload[1];
return ret;
}
@@ -616,11 +616,6 @@ static int zynqmp_pm_get_trustzone_version(u32 *version)
if (!version)
return -EINVAL;
- /* Check is PM trustzone version already verified */
- if (pm_tz_version > 0) {
- *version = pm_tz_version;
- return 0;
- }
ret = zynqmp_pm_invoke_fn(PM_GET_TRUSTZONE_VERSION, ret_payload, 0);
*version = ret_payload[1];
@@ -2178,9 +2173,9 @@ static int zynqmp_clear_pm_state(struct device *dev)
static int zynqmp_firmware_probe(struct platform_device *pdev)
{
+ u32 pm_api_version, pm_family_code, pm_tz_version;
struct device *dev = &pdev->dev;
struct zynqmp_devinfo *devinfo;
- u32 pm_family_code;
int ret;
ret = get_set_conduit_method(dev->of_node);
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] drivers: firmware: xilinx: Split PM EEMI and core APIs in firmware
2026-11-27 11:48 [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components Jay Buddhabhatti
` (3 preceding siblings ...)
2026-11-27 11:48 ` [PATCH 4/5] drivers: firmware: xilinx: Localize firmware version caches Jay Buddhabhatti
@ 2026-11-27 11:48 ` Jay Buddhabhatti
4 siblings, 0 replies; 6+ messages in thread
From: Jay Buddhabhatti @ 2026-11-27 11:48 UTC (permalink / raw)
To: Michal Simek
Cc: Ronak Jain, Aravind Thokala, Harsh Jain, linux-arm-kernel,
linux-kernel, git, Jay Buddhabhatti
From: Ronak Jain <ronak.jain@amd.com>
Split the firmware driver into core and PM EEMI files to reduce
complexity and clarify ownership of each interface.
Add a MAINTAINERS entry for the Xilinx PM firmware driver. List the
core, PM EEMI, and debug files and the xlnx-zynqmp.h header.
Signed-off-by: Ronak Jain <ronak.jain@amd.com>
Co-developed-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
Signed-off-by: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
---
MAINTAINERS | 10 +
drivers/firmware/xilinx/Makefile | 5 +-
drivers/firmware/xilinx/zynqmp-core.c | 797 +++++++++++++++++
drivers/firmware/xilinx/zynqmp-debug.h | 20 +
.../firmware/xilinx/{zynqmp.c => zynqmp-pm.c} | 808 +-----------------
5 files changed, 841 insertions(+), 799 deletions(-)
create mode 100644 drivers/firmware/xilinx/zynqmp-core.c
rename drivers/firmware/xilinx/{zynqmp.c => zynqmp-pm.c} (66%)
diff --git a/MAINTAINERS b/MAINTAINERS
index e010589c13e5..b92675dc178a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30699,6 +30699,16 @@ L: netdev@vger.kernel.org
S: Orphan
F: drivers/net/ethernet/xilinx/ll_temac*
+XILINX PM FIRMWARE DRIVER
+M: Jay Buddhabhatti <jay.buddhabhatti@amd.com>
+L: git@amd.com
+S: Maintained
+F: drivers/firmware/xilinx/zynqmp-core.c
+F: drivers/firmware/xilinx/zynqmp-debug.c
+F: drivers/firmware/xilinx/zynqmp-debug.h
+F: drivers/firmware/xilinx/zynqmp-pm.c
+F: include/linux/firmware/xlnx-zynqmp.h
+
XILINX PWM DRIVER
M: Sean Anderson <sean.anderson@linux.dev>
S: Maintained
diff --git a/drivers/firmware/xilinx/Makefile b/drivers/firmware/xilinx/Makefile
index d23d41c6a8ac..4688389b8367 100644
--- a/drivers/firmware/xilinx/Makefile
+++ b/drivers/firmware/xilinx/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for Xilinx firmwares
-obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp-crypto.o zynqmp-fpga.o \
- zynqmp-nvm.o zynqmp-pdi.o zynqmp-ufs.o zynqmp.o
+obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp-core.o zynqmp-crypto.o \
+ zynqmp-fpga.o zynqmp-nvm.o zynqmp-pdi.o \
+ zynqmp-pm.o zynqmp-ufs.o
obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
diff --git a/drivers/firmware/xilinx/zynqmp-core.c b/drivers/firmware/xilinx/zynqmp-core.c
new file mode 100644
index 000000000000..ce9652256b9c
--- /dev/null
+++ b/drivers/firmware/xilinx/zynqmp-core.c
@@ -0,0 +1,797 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Xilinx Zynq MPSoC Firmware layer core APIs.
+ *
+ * Copyright (C) 2014 - 2022 Xilinx, Inc.
+ * Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/bitfield.h>
+#include <linux/crash_dump.h>
+#include <linux/device.h>
+#include <linux/hashtable.h>
+#include <linux/init.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <linux/firmware/xlnx-zynqmp.h>
+#include "zynqmp-debug.h"
+
+/* Max HashMap Order for PM API feature check (1<<7 = 128) */
+#define PM_API_FEATURE_CHECK_MAX_ORDER 7
+
+/* IOCTL/QUERY feature payload size */
+#define FEATURE_PAYLOAD_SIZE 2
+
+static bool feature_check_enabled;
+static DEFINE_HASHTABLE(pm_api_features_map, PM_API_FEATURE_CHECK_MAX_ORDER);
+static u32 ioctl_features[FEATURE_PAYLOAD_SIZE];
+static u32 query_features[FEATURE_PAYLOAD_SIZE];
+
+static u32 sip_svc_version;
+static struct platform_device *em_dev;
+
+static const struct mfd_cell firmware_devs[] = {
+ {
+ .name = "zynqmp_power_controller",
+ },
+};
+
+/**
+ * struct pm_api_feature_data - PM API Feature data
+ * @pm_api_id: PM API Id, used as key to index into hashmap
+ * @feature_status: status of PM API feature: valid, invalid
+ * @hentry: hlist_node that hooks this entry into hashtable
+ */
+struct pm_api_feature_data {
+ u32 pm_api_id;
+ int feature_status;
+ struct hlist_node hentry;
+};
+
+struct platform_fw_data {
+ /*
+ * Family code for platform.
+ */
+ const u32 family_code;
+};
+
+static struct platform_fw_data *active_platform_fw_data;
+
+/**
+ * zynqmp_pm_ret_code() - Convert PMU-FW error codes to Linux error codes
+ * @ret_status: PMUFW return code
+ *
+ * Return: corresponding Linux error code
+ */
+static int zynqmp_pm_ret_code(u32 ret_status)
+{
+ switch (ret_status) {
+ case XST_PM_SUCCESS:
+ case XST_PM_DOUBLE_REQ:
+ return 0;
+ case XST_PM_NO_FEATURE:
+ return -ENOTSUPP;
+ case XST_PM_INVALID_VERSION:
+ return -EOPNOTSUPP;
+ case XST_PM_NO_ACCESS:
+ return -EACCES;
+ case XST_PM_ABORT_SUSPEND:
+ return -ECANCELED;
+ case XST_PM_MULT_USER:
+ return -EUSERS;
+ case XST_PM_INTERNAL:
+ case XST_PM_CONFLICT:
+ case XST_PM_INVALID_NODE:
+ case XST_PM_INVALID_CRC:
+ default:
+ return -EINVAL;
+ }
+}
+
+static noinline int do_fw_call_fail(u32 *ret_payload, u32 num_args, ...)
+{
+ return -ENODEV;
+}
+
+/*
+ * PM function call wrapper
+ * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
+ */
+static int (*do_fw_call)(u32 *ret_payload, u32, ...) = do_fw_call_fail;
+
+/**
+ * do_fw_call_smc() - Call system-level platform management layer (SMC)
+ * @num_args: Number of variable arguments should be <= 8
+ * @ret_payload: Returned value array
+ *
+ * Invoke platform management function via SMC call (no hypervisor present).
+ *
+ * Return: Returns status, either success or error+reason
+ */
+static noinline int do_fw_call_smc(u32 *ret_payload, u32 num_args, ...)
+{
+ struct arm_smccc_res res;
+ u64 args[8] = {0};
+ va_list arg_list;
+ u8 i;
+
+ if (num_args > 8)
+ return -EINVAL;
+
+ va_start(arg_list, num_args);
+
+ for (i = 0; i < num_args; i++)
+ args[i] = va_arg(arg_list, u64);
+
+ va_end(arg_list);
+
+ arm_smccc_smc(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &res);
+
+ if (ret_payload) {
+ ret_payload[0] = lower_32_bits(res.a0);
+ ret_payload[1] = upper_32_bits(res.a0);
+ ret_payload[2] = lower_32_bits(res.a1);
+ ret_payload[3] = upper_32_bits(res.a1);
+ ret_payload[4] = lower_32_bits(res.a2);
+ ret_payload[5] = upper_32_bits(res.a2);
+ ret_payload[6] = lower_32_bits(res.a3);
+ }
+
+ return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
+}
+
+/**
+ * do_fw_call_hvc() - Call system-level platform management layer (HVC)
+ * @num_args: Number of variable arguments should be <= 8
+ * @ret_payload: Returned value array
+ *
+ * Invoke platform management function via HVC
+ * HVC-based for communication through hypervisor
+ * (no direct communication with ATF).
+ *
+ * Return: Returns status, either success or error+reason
+ */
+static noinline int do_fw_call_hvc(u32 *ret_payload, u32 num_args, ...)
+{
+ struct arm_smccc_res res;
+ u64 args[8] = {0};
+ va_list arg_list;
+ u8 i;
+
+ if (num_args > 8)
+ return -EINVAL;
+
+ va_start(arg_list, num_args);
+
+ for (i = 0; i < num_args; i++)
+ args[i] = va_arg(arg_list, u64);
+
+ va_end(arg_list);
+
+ arm_smccc_hvc(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &res);
+
+ if (ret_payload) {
+ ret_payload[0] = lower_32_bits(res.a0);
+ ret_payload[1] = upper_32_bits(res.a0);
+ ret_payload[2] = lower_32_bits(res.a1);
+ ret_payload[3] = upper_32_bits(res.a1);
+ ret_payload[4] = lower_32_bits(res.a2);
+ ret_payload[5] = upper_32_bits(res.a2);
+ ret_payload[6] = lower_32_bits(res.a3);
+ }
+
+ return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
+}
+
+static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
+{
+ int ret;
+ u64 smc_arg[2];
+ u32 module_id;
+ u32 feature_check_api_id;
+
+ module_id = FIELD_GET(MODULE_ID_MASK, api_id);
+
+ /*
+ * Feature check of APIs belonging to PM and XSEM are handled by calling
+ * PM_FEATURE_CHECK API. For other modules, call PM_API_FEATURES API.
+ */
+ if (module_id == PM_MODULE_ID || module_id == XSEM_MODULE_ID)
+ feature_check_api_id = PM_FEATURE_CHECK;
+ else
+ feature_check_api_id = PM_API_FEATURES;
+
+ if (module_id == TF_A_MODULE_ID)
+ smc_arg[1] = api_id;
+ else
+ smc_arg[1] = (api_id & API_ID_MASK);
+
+ smc_arg[0] = PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, module_id) | feature_check_api_id;
+
+ ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
+
+ /*
+ * For TF-A APIs, if the feature check with PM_API_FEATURES fails,
+ * retry with the legacy PM_FEATURE_CHECK for backward compatibility.
+ */
+ if (module_id == TF_A_MODULE_ID && ret) {
+ smc_arg[0] = PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, PM_MODULE_ID) |
+ PM_FEATURE_CHECK;
+ ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
+ }
+
+ if (ret)
+ return ret;
+
+ return ret_payload[1];
+}
+
+static int do_feature_check_call(const u32 api_id)
+{
+ int ret;
+ u32 ret_payload[PAYLOAD_ARG_CNT];
+ struct pm_api_feature_data *feature_data;
+
+ /* Check for existing entry in hash table for given api */
+ hash_for_each_possible(pm_api_features_map, feature_data, hentry,
+ api_id) {
+ if (feature_data->pm_api_id == api_id)
+ return feature_data->feature_status;
+ }
+
+ /* Add new entry if not present */
+ feature_data = kmalloc_obj(*feature_data, GFP_ATOMIC);
+ if (!feature_data)
+ return -ENOMEM;
+
+ feature_data->pm_api_id = api_id;
+ ret = __do_feature_check_call(api_id, ret_payload);
+
+ feature_data->feature_status = ret;
+ hash_add(pm_api_features_map, &feature_data->hentry, api_id);
+
+ if (api_id == PM_IOCTL)
+ /* Store supported IOCTL IDs mask */
+ memcpy(ioctl_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
+ else if (api_id == PM_QUERY_DATA)
+ /* Store supported QUERY IDs mask */
+ memcpy(query_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
+
+ return ret;
+}
+
+/**
+ * zynqmp_pm_feature() - Check whether given feature is supported or not and
+ * store supported IOCTL/QUERY ID mask
+ * @api_id: API ID to check
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_feature(const u32 api_id)
+{
+ int ret;
+
+ if (!feature_check_enabled)
+ return 0;
+
+ ret = do_feature_check_call(api_id);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_feature);
+
+/**
+ * zynqmp_pm_is_function_supported() - Check whether given IOCTL/QUERY function
+ * is supported or not
+ * @api_id: PM_IOCTL or PM_QUERY_DATA
+ * @id: IOCTL or QUERY function IDs
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id)
+{
+ int ret;
+ u32 *bit_mask;
+
+ /* Input arguments validation */
+ if (id >= 64 || (api_id != PM_IOCTL && api_id != PM_QUERY_DATA))
+ return -EINVAL;
+
+ /* Check feature check API version */
+ ret = do_feature_check_call(PM_FEATURE_CHECK);
+ if (ret < 0)
+ return ret;
+
+ /* Check if feature check version 2 is supported or not */
+ if ((ret & FIRMWARE_VERSION_MASK) == PM_API_VERSION_2) {
+ /*
+ * Call feature check for IOCTL/QUERY API to get IOCTL ID or
+ * QUERY ID feature status.
+ */
+ ret = do_feature_check_call(api_id);
+ if (ret < 0)
+ return ret;
+
+ bit_mask = (api_id == PM_IOCTL) ? ioctl_features : query_features;
+
+ if ((bit_mask[(id / 32)] & BIT((id % 32))) == 0U)
+ return -EOPNOTSUPP;
+ } else {
+ return -ENODATA;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported);
+
+/**
+ * zynqmp_pm_invoke_fw_fn() - Invoke the system-level platform management layer
+ * caller function depending on the configuration
+ * @pm_api_id: Requested PM-API call
+ * @ret_payload: Returned value array
+ * @num_args: Number of arguments to requested PM-API call
+ *
+ * Invoke platform management function for SMC or HVC call, depending on
+ * configuration.
+ * Following SMC Calling Convention (SMCCC) for SMC64:
+ * Pm Function Identifier,
+ * PM_SIP_SVC + PASS_THROUGH_FW_CMD_ID =
+ * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
+ * ((SMC_64) << FUNCID_CC_SHIFT)
+ * ((SIP_START) << FUNCID_OEN_SHIFT)
+ * (PASS_THROUGH_FW_CMD_ID))
+ *
+ * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
+ * PASS_THROUGH_FW_CMD_ID - Fixed SiP SVC call ID for FW specific calls.
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_invoke_fw_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
+{
+ /*
+ * Added SIP service call Function Identifier
+ * Make sure to stay in x0 register
+ */
+ u64 smc_arg[SMC_ARG_CNT_64];
+ int ret, i;
+ va_list arg_list;
+ u32 args[SMC_ARG_CNT_32] = {0};
+ u32 module_id;
+
+ /*
+ * According to the SMCCC: The total number of registers available for
+ * arguments is 16.
+ *
+ * In the Extended SMC format, 3 registers are used for headers, leaving
+ * up to 13 registers for arguments.
+ */
+ if (num_args > SMC_ARG_CNT_32)
+ return -EINVAL;
+
+ /* Check if feature is supported or not */
+ ret = zynqmp_pm_feature(pm_api_id);
+ if (ret < 0)
+ return ret;
+
+ va_start(arg_list, num_args);
+
+ for (i = 0; i < num_args; i++)
+ args[i] = va_arg(arg_list, u32);
+
+ va_end(arg_list);
+
+ module_id = FIELD_GET(PLM_MODULE_ID_MASK, pm_api_id);
+
+ if (module_id == 0)
+ module_id = XPM_MODULE_ID;
+
+ smc_arg[0] = PM_SIP_SVC | PASS_THROUGH_FW_CMD_ID;
+ smc_arg[1] = ((u64)args[0] << 32U) | FIELD_PREP(PLM_MODULE_ID_MASK, module_id) |
+ (pm_api_id & API_ID_MASK);
+ for (i = 1; i < (SMC_ARG_CNT_64 - 1); i++)
+ smc_arg[i + 1] = ((u64)args[(i * 2)] << 32U) | args[(i * 2) - 1];
+
+ return do_fw_call(ret_payload, 8, smc_arg[0], smc_arg[1], smc_arg[2], smc_arg[3],
+ smc_arg[4], smc_arg[5], smc_arg[6], smc_arg[7]);
+}
+
+/**
+ * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
+ * caller function depending on the configuration
+ * @pm_api_id: Requested PM-API call
+ * @ret_payload: Returned value array
+ * @num_args: Number of arguments to requested PM-API call
+ *
+ * Invoke platform management function for SMC or HVC call, depending on
+ * configuration.
+ * Following SMC Calling Convention (SMCCC) for SMC64:
+ * Pm Function Identifier,
+ * PM_SIP_SVC + PM_API_ID =
+ * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
+ * ((SMC_64) << FUNCID_CC_SHIFT)
+ * ((SIP_START) << FUNCID_OEN_SHIFT)
+ * ((PM_API_ID) & FUNCID_NUM_MASK))
+ *
+ * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
+ * PM_API_ID - Platform Management API ID.
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
+{
+ /*
+ * Added SIP service call Function Identifier
+ * Make sure to stay in x0 register
+ */
+ u64 smc_arg[8];
+ int ret, i;
+ va_list arg_list;
+ u32 args[SMC_ARG_CNT_BASIC_32] = {0};
+
+ /*
+ * According to the SMCCC: The total number of registers available for
+ * arguments is 16.
+ *
+ * In the Basic SMC format, 2 registers are used for headers, leaving
+ * up to 14 registers for arguments.
+ */
+ if (num_args > SMC_ARG_CNT_BASIC_32)
+ return -EINVAL;
+
+ /* Check if feature is supported or not */
+ ret = zynqmp_pm_feature(pm_api_id);
+ if (ret < 0)
+ return ret;
+
+ va_start(arg_list, num_args);
+
+ for (i = 0; i < num_args; i++)
+ args[i] = va_arg(arg_list, u32);
+
+ va_end(arg_list);
+
+ smc_arg[0] = PM_SIP_SVC | pm_api_id;
+ for (i = 0; i < 7; i++)
+ smc_arg[i + 1] = ((u64)args[(i * 2) + 1] << 32) | args[i * 2];
+
+ return do_fw_call(ret_payload, 8, smc_arg[0], smc_arg[1], smc_arg[2], smc_arg[3],
+ smc_arg[4], smc_arg[5], smc_arg[6], smc_arg[7]);
+}
+
+/**
+ * zynqmp_pm_get_sip_svc_version() - Get SiP service call version
+ * @version: Returned version value
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_get_sip_svc_version(u32 *version)
+{
+ struct arm_smccc_res res;
+ u64 args[SMC_ARG_CNT_64] = {0};
+
+ if (!version)
+ return -EINVAL;
+
+ /* Check if SiP SVC version already verified */
+ if (sip_svc_version > 0) {
+ *version = sip_svc_version;
+ return 0;
+ }
+
+ args[0] = GET_SIP_SVC_VERSION;
+
+ arm_smccc_smc(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &res);
+
+ *version = ((lower_32_bits(res.a0) << 16U) | lower_32_bits(res.a1));
+
+ return zynqmp_pm_ret_code(XST_PM_SUCCESS);
+}
+
+/**
+ * get_set_conduit_method() - Choose SMC or HVC based communication
+ * @np: Pointer to the device_node structure
+ *
+ * Use SMC or HVC-based functions to communicate with EL2/EL3.
+ *
+ * Return: Returns 0 on success or error code
+ */
+static int get_set_conduit_method(struct device_node *np)
+{
+ const char *method;
+
+ if (of_property_read_string(np, "method", &method)) {
+ pr_warn("%s missing \"method\" property\n", __func__);
+ return -ENXIO;
+ }
+
+ if (!strcmp("hvc", method)) {
+ do_fw_call = do_fw_call_hvc;
+ } else if (!strcmp("smc", method)) {
+ do_fw_call = do_fw_call_smc;
+ } else {
+ pr_warn("%s Invalid \"method\" property: %s\n",
+ __func__, method);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/**
+ * zynqmp_pm_get_family_info() - Get family info of platform
+ * @family: Returned family code value
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_get_family_info(u32 *family)
+{
+ if (!active_platform_fw_data)
+ return -ENODEV;
+
+ if (!family)
+ return -EINVAL;
+
+ *family = active_platform_fw_data->family_code;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_get_family_info);
+
+/**
+ * zynqmp_clear_pm_state() - Clear subsystem state
+ * @dev: Device pointer used for logging
+ *
+ * Clears PM specific data in EL3 and platform firmware.
+ *
+ * Return: Returns status, either success or error
+ */
+static int zynqmp_clear_pm_state(struct device *dev)
+{
+ u32 pm_family_code;
+ int ret;
+
+ /* Get the Family code of platform */
+ ret = zynqmp_pm_get_family_info(&pm_family_code);
+ if (ret < 0)
+ return ret;
+
+ /* Supporting on Versal and Versal Net platforms only */
+ if (pm_family_code == PM_VERSAL_FAMILY_CODE ||
+ pm_family_code == PM_VERSAL_NET_FAMILY_CODE) {
+ /* Check if EL3 firmware supports TF_A_CLEAR_PM_STATE */
+ ret = do_feature_check_call(TF_A_CLEAR_PM_STATE);
+ if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_1)) {
+ /* Clear PM specific data in EL3 firmware */
+ ret = zynqmp_pm_invoke_fn(TF_A_CLEAR_PM_STATE, NULL, 0);
+ if (ret)
+ dev_err(dev,
+ "Failed to clear EL3 PM subsystem state: %d\n", ret);
+ } else {
+ dev_warn(dev,
+ "TF_A_CLEAR_PM_STATE is not supported by EL3 firmware: %d\n",
+ ret);
+ }
+
+ /* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */
+ ret = do_feature_check_call(PM_RELEASE_NODE);
+ if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_3)) {
+ /* Attempt to release all peripheral devices via firmware */
+ ret = zynqmp_pm_release_node(PM_DEV_ALL_PERIPH);
+ if (ret)
+ dev_err(dev, "Failed to release all peripheral devices: %d\n", ret);
+ } else {
+ dev_warn(dev,
+ "Bulk device release is not supported by firmware: %d\n", ret);
+ }
+
+ /* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */
+ ret = do_feature_check_call(PM_REQUEST_NODE);
+ if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_3)) {
+ /* Attempt to request all nodes via firmware */
+ ret = zynqmp_pm_request_node(PM_DEV_ALL_PERIPH, 0, 0, 0);
+ if (ret)
+ dev_err(dev, "Failed to request all peripheral devices: %d\n", ret);
+ } else {
+ dev_warn(dev,
+ "Firmware doesn't support request all peripheral devices at once: %d\n",
+ ret);
+ }
+
+ /* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */
+ ret = do_feature_check_call(PM_REGISTER_NOTIFIER);
+ if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_3)) {
+ /* Attempt to unregister all notifier callbacks via firmware */
+ ret = zynqmp_pm_register_notifier(PM_ALL_NOTIFIERS, 0, 0, 0);
+ if (ret)
+ dev_err(dev, "Failed to unregister all notifiers: %d\n", ret);
+ } else {
+ dev_warn(dev,
+ "Firmware doesn't support unregister all notifiers at once: %d\n",
+ ret);
+ ret = 0;
+ }
+ }
+
+ return ret;
+}
+
+static int zynqmp_firmware_probe(struct platform_device *pdev)
+{
+ u32 pm_api_version, pm_family_code, pm_tz_version;
+ struct device *dev = &pdev->dev;
+ struct zynqmp_devinfo *devinfo;
+ int ret;
+
+ ret = get_set_conduit_method(dev->of_node);
+ if (ret)
+ return ret;
+
+ /* Get platform-specific firmware data from device tree match */
+ active_platform_fw_data = (struct platform_fw_data *)device_get_match_data(dev);
+ if (!active_platform_fw_data)
+ return -EINVAL;
+
+ /* Get SiP SVC version number */
+ ret = zynqmp_pm_get_sip_svc_version(&sip_svc_version);
+ if (ret)
+ return ret;
+
+ ret = do_feature_check_call(PM_FEATURE_CHECK);
+ if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_1))
+ feature_check_enabled = true;
+
+ devinfo = devm_kzalloc_obj(dev, *devinfo);
+ if (!devinfo)
+ return -ENOMEM;
+
+ devinfo->dev = dev;
+
+ platform_set_drvdata(pdev, devinfo);
+
+ /* Check PM API version number */
+ ret = zynqmp_pm_get_api_version(&pm_api_version);
+ if (ret)
+ return ret;
+
+ if (pm_api_version < ZYNQMP_PM_VERSION) {
+ panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
+ __func__,
+ ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR,
+ pm_api_version >> 16, pm_api_version & 0xFFFF);
+ }
+
+ pr_info("%s Platform Management API v%d.%d\n", __func__,
+ pm_api_version >> 16, pm_api_version & 0xFFFF);
+
+ /* Get the Family code of platform */
+ ret = zynqmp_pm_get_family_info(&pm_family_code);
+ if (ret < 0)
+ return ret;
+
+ if (is_kdump_kernel())
+ zynqmp_clear_pm_state(dev);
+
+ /* Check trustzone version number */
+ ret = zynqmp_pm_get_trustzone_version(&pm_tz_version);
+ if (ret)
+ panic("Legacy trustzone found without version support\n");
+
+ if (pm_tz_version < ZYNQMP_TZ_VERSION)
+ panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
+ __func__,
+ ZYNQMP_TZ_VERSION_MAJOR, ZYNQMP_TZ_VERSION_MINOR,
+ pm_tz_version >> 16, pm_tz_version & 0xFFFF);
+
+ pr_info("%s Trustzone version v%d.%d\n", __func__,
+ pm_tz_version >> 16, pm_tz_version & 0xFFFF);
+
+ ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
+ ARRAY_SIZE(firmware_devs), NULL, 0, NULL);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to add MFD devices %d\n", ret);
+ return ret;
+ }
+
+ ret = zynqmp_firmware_pm_sysfs_entry(pdev);
+ if (ret) {
+ pr_err("%s() Failed to create sysfs file with error%d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ zynqmp_pm_api_debugfs_init();
+
+ if (pm_family_code != PM_ZYNQMP_FAMILY_CODE) {
+ em_dev = platform_device_register_data(&pdev->dev, "xlnx_event_manager",
+ -1, NULL, 0);
+ if (IS_ERR(em_dev))
+ dev_err_probe(&pdev->dev, PTR_ERR(em_dev), "EM register fail with error\n");
+ }
+
+ return of_platform_populate(dev->of_node, NULL, NULL, dev);
+}
+
+static void zynqmp_firmware_shutdown(struct platform_device *pdev)
+{
+ zynqmp_clear_pm_state(&pdev->dev);
+}
+
+static void zynqmp_firmware_remove(struct platform_device *pdev)
+{
+ struct pm_api_feature_data *feature_data;
+ struct hlist_node *tmp;
+ int i;
+
+ mfd_remove_devices(&pdev->dev);
+ zynqmp_pm_api_debugfs_exit();
+
+ hash_for_each_safe(pm_api_features_map, i, tmp, feature_data, hentry) {
+ hash_del(&feature_data->hentry);
+ kfree(feature_data);
+ }
+
+ platform_device_unregister(em_dev);
+}
+
+static const struct platform_fw_data platform_fw_data_versal = {
+ .family_code = PM_VERSAL_FAMILY_CODE,
+};
+
+static const struct platform_fw_data platform_fw_data_versal_net = {
+ .family_code = PM_VERSAL_NET_FAMILY_CODE,
+};
+
+static const struct platform_fw_data platform_fw_data_zynqmp = {
+ .family_code = PM_ZYNQMP_FAMILY_CODE,
+};
+
+static const struct of_device_id zynqmp_firmware_of_match[] = {
+ {.compatible = "xlnx,zynqmp-firmware", .data = &platform_fw_data_zynqmp},
+ {.compatible = "xlnx,versal-firmware", .data = &platform_fw_data_versal},
+ {.compatible = "xlnx,versal-net-firmware", .data = &platform_fw_data_versal_net},
+ {},
+};
+MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
+
+static struct platform_driver zynqmp_firmware_driver = {
+ .driver = {
+ .name = "zynqmp_firmware",
+ .of_match_table = zynqmp_firmware_of_match,
+ },
+ .probe = zynqmp_firmware_probe,
+ .remove = zynqmp_firmware_remove,
+ .shutdown = zynqmp_firmware_shutdown,
+};
+module_platform_driver(zynqmp_firmware_driver);
+
+/*
+ * pm_init_finalize was previously called from the firmware driver's
+ * sync_state callback, but sync_state can be blocked indefinitely if
+ * any device consumer never probes. Use late_initcall to ensure
+ * pm_init_finalize is called reliably regardless of consumer
+ * probe status.
+ */
+static int __init zynqmp_pm_init_finalize_late(void)
+{
+ u32 pm_family_code;
+ int ret;
+
+ ret = zynqmp_pm_get_family_info(&pm_family_code);
+ if (ret)
+ return ret;
+
+ if (pm_family_code != PM_ZYNQMP_FAMILY_CODE)
+ return 0;
+
+ if (zynqmp_pm_init_finalize())
+ pr_warn("zynqmp: failed to release power management to firmware\n");
+
+ return 0;
+}
+late_initcall(zynqmp_pm_init_finalize_late);
diff --git a/drivers/firmware/xilinx/zynqmp-debug.h b/drivers/firmware/xilinx/zynqmp-debug.h
index e1515a93e9e9..053f86103eb4 100644
--- a/drivers/firmware/xilinx/zynqmp-debug.h
+++ b/drivers/firmware/xilinx/zynqmp-debug.h
@@ -13,6 +13,26 @@
#ifndef __FIRMWARE_ZYNQMP_DEBUG_H__
#define __FIRMWARE_ZYNQMP_DEBUG_H__
+#include <linux/types.h>
+
+struct device;
+struct platform_device;
+
+/**
+ * struct zynqmp_devinfo - Structure for Zynqmp device instance
+ * @dev: Device Pointer
+ * @feature_conf_id: Feature conf id
+ */
+struct zynqmp_devinfo {
+ struct device *dev;
+ u32 feature_conf_id;
+};
+
+int zynqmp_firmware_pm_sysfs_entry(struct platform_device *pdev);
+int zynqmp_pm_get_sip_svc_version(u32 *version);
+int zynqmp_pm_get_trustzone_version(u32 *version);
+int zynqmp_pm_init_finalize(void);
+
#if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE_DEBUG)
void zynqmp_pm_api_debugfs_init(void);
void zynqmp_pm_api_debugfs_exit(void);
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp-pm.c
similarity index 66%
rename from drivers/firmware/xilinx/zynqmp.c
rename to drivers/firmware/xilinx/zynqmp-pm.c
index 374d39f34480..76fc88adc0c2 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp-pm.c
@@ -11,27 +11,14 @@
* Rajan Vaja <rajanv@xilinx.com>
*/
-#include <linux/arm-smccc.h>
-#include <linux/compiler.h>
-#include <linux/crash_dump.h>
#include <linux/device.h>
-#include <linux/init.h>
-#include <linux/mfd/core.h>
-#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/of_platform.h>
+#include <linux/kernel.h>
#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include <linux/uaccess.h>
-#include <linux/hashtable.h>
+#include <linux/string.h>
#include <linux/firmware/xlnx-zynqmp.h>
-#include <linux/firmware/xlnx-event-manager.h>
#include "zynqmp-debug.h"
-/* Max HashMap Order for PM API feature check (1<<7 = 128) */
-#define PM_API_FEATURE_CHECK_MAX_ORDER 7
-
/* CRL registers and bitfields */
#define CRL_APB_BASE 0xFF5E0000U
/* BOOT_PIN_CTRL- Used to control the mode pins after boot */
@@ -39,455 +26,6 @@
/* BOOT_PIN_CTRL_MASK- out_val[11:8], out_en[3:0] */
#define CRL_APB_BOOTPIN_CTRL_MASK 0xF0FU
-/* IOCTL/QUERY feature payload size */
-#define FEATURE_PAYLOAD_SIZE 2
-
-static bool feature_check_enabled;
-static DEFINE_HASHTABLE(pm_api_features_map, PM_API_FEATURE_CHECK_MAX_ORDER);
-static u32 ioctl_features[FEATURE_PAYLOAD_SIZE];
-static u32 query_features[FEATURE_PAYLOAD_SIZE];
-
-static u32 sip_svc_version;
-static struct platform_device *em_dev;
-
-/**
- * struct zynqmp_devinfo - Structure for Zynqmp device instance
- * @dev: Device Pointer
- * @feature_conf_id: Feature conf id
- */
-struct zynqmp_devinfo {
- struct device *dev;
- u32 feature_conf_id;
-};
-
-/**
- * struct pm_api_feature_data - PM API Feature data
- * @pm_api_id: PM API Id, used as key to index into hashmap
- * @feature_status: status of PM API feature: valid, invalid
- * @hentry: hlist_node that hooks this entry into hashtable
- */
-struct pm_api_feature_data {
- u32 pm_api_id;
- int feature_status;
- struct hlist_node hentry;
-};
-
-struct platform_fw_data {
- /*
- * Family code for platform.
- */
- const u32 family_code;
-};
-
-static struct platform_fw_data *active_platform_fw_data;
-
-static const struct mfd_cell firmware_devs[] = {
- {
- .name = "zynqmp_power_controller",
- },
-};
-
-/**
- * zynqmp_pm_ret_code() - Convert PMU-FW error codes to Linux error codes
- * @ret_status: PMUFW return code
- *
- * Return: corresponding Linux error code
- */
-static int zynqmp_pm_ret_code(u32 ret_status)
-{
- switch (ret_status) {
- case XST_PM_SUCCESS:
- case XST_PM_DOUBLE_REQ:
- return 0;
- case XST_PM_NO_FEATURE:
- return -ENOTSUPP;
- case XST_PM_INVALID_VERSION:
- return -EOPNOTSUPP;
- case XST_PM_NO_ACCESS:
- return -EACCES;
- case XST_PM_ABORT_SUSPEND:
- return -ECANCELED;
- case XST_PM_MULT_USER:
- return -EUSERS;
- case XST_PM_INTERNAL:
- case XST_PM_CONFLICT:
- case XST_PM_INVALID_NODE:
- case XST_PM_INVALID_CRC:
- default:
- return -EINVAL;
- }
-}
-
-static noinline int do_fw_call_fail(u32 *ret_payload, u32 num_args, ...)
-{
- return -ENODEV;
-}
-
-/*
- * PM function call wrapper
- * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
- */
-static int (*do_fw_call)(u32 *ret_payload, u32, ...) = do_fw_call_fail;
-
-/**
- * do_fw_call_smc() - Call system-level platform management layer (SMC)
- * @num_args: Number of variable arguments should be <= 8
- * @ret_payload: Returned value array
- *
- * Invoke platform management function via SMC call (no hypervisor present).
- *
- * Return: Returns status, either success or error+reason
- */
-static noinline int do_fw_call_smc(u32 *ret_payload, u32 num_args, ...)
-{
- struct arm_smccc_res res;
- u64 args[8] = {0};
- va_list arg_list;
- u8 i;
-
- if (num_args > 8)
- return -EINVAL;
-
- va_start(arg_list, num_args);
-
- for (i = 0; i < num_args; i++)
- args[i] = va_arg(arg_list, u64);
-
- va_end(arg_list);
-
- arm_smccc_smc(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &res);
-
- if (ret_payload) {
- ret_payload[0] = lower_32_bits(res.a0);
- ret_payload[1] = upper_32_bits(res.a0);
- ret_payload[2] = lower_32_bits(res.a1);
- ret_payload[3] = upper_32_bits(res.a1);
- ret_payload[4] = lower_32_bits(res.a2);
- ret_payload[5] = upper_32_bits(res.a2);
- ret_payload[6] = lower_32_bits(res.a3);
- }
-
- return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
-}
-
-/**
- * do_fw_call_hvc() - Call system-level platform management layer (HVC)
- * @num_args: Number of variable arguments should be <= 8
- * @ret_payload: Returned value array
- *
- * Invoke platform management function via HVC
- * HVC-based for communication through hypervisor
- * (no direct communication with ATF).
- *
- * Return: Returns status, either success or error+reason
- */
-static noinline int do_fw_call_hvc(u32 *ret_payload, u32 num_args, ...)
-{
- struct arm_smccc_res res;
- u64 args[8] = {0};
- va_list arg_list;
- u8 i;
-
- if (num_args > 8)
- return -EINVAL;
-
- va_start(arg_list, num_args);
-
- for (i = 0; i < num_args; i++)
- args[i] = va_arg(arg_list, u64);
-
- va_end(arg_list);
-
- arm_smccc_hvc(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &res);
-
- if (ret_payload) {
- ret_payload[0] = lower_32_bits(res.a0);
- ret_payload[1] = upper_32_bits(res.a0);
- ret_payload[2] = lower_32_bits(res.a1);
- ret_payload[3] = upper_32_bits(res.a1);
- ret_payload[4] = lower_32_bits(res.a2);
- ret_payload[5] = upper_32_bits(res.a2);
- ret_payload[6] = lower_32_bits(res.a3);
- }
-
- return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
-}
-
-static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
-{
- int ret;
- u64 smc_arg[2];
- u32 module_id;
- u32 feature_check_api_id;
-
- module_id = FIELD_GET(MODULE_ID_MASK, api_id);
-
- /*
- * Feature check of APIs belonging to PM and XSEM are handled by calling
- * PM_FEATURE_CHECK API. For other modules, call PM_API_FEATURES API.
- */
- if (module_id == PM_MODULE_ID || module_id == XSEM_MODULE_ID)
- feature_check_api_id = PM_FEATURE_CHECK;
- else
- feature_check_api_id = PM_API_FEATURES;
-
- if (module_id == TF_A_MODULE_ID)
- smc_arg[1] = api_id;
- else
- smc_arg[1] = (api_id & API_ID_MASK);
-
- smc_arg[0] = PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, module_id) | feature_check_api_id;
-
- ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
-
- /*
- * For TF-A APIs, if the feature check with PM_API_FEATURES fails,
- * retry with the legacy PM_FEATURE_CHECK for backward compatibility.
- */
- if (module_id == TF_A_MODULE_ID && ret) {
- smc_arg[0] = PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, PM_MODULE_ID) |
- PM_FEATURE_CHECK;
- ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
- }
-
- if (ret)
- return ret;
-
- return ret_payload[1];
-}
-
-static int do_feature_check_call(const u32 api_id)
-{
- int ret;
- u32 ret_payload[PAYLOAD_ARG_CNT];
- struct pm_api_feature_data *feature_data;
-
- /* Check for existing entry in hash table for given api */
- hash_for_each_possible(pm_api_features_map, feature_data, hentry,
- api_id) {
- if (feature_data->pm_api_id == api_id)
- return feature_data->feature_status;
- }
-
- /* Add new entry if not present */
- feature_data = kmalloc_obj(*feature_data, GFP_ATOMIC);
- if (!feature_data)
- return -ENOMEM;
-
- feature_data->pm_api_id = api_id;
- ret = __do_feature_check_call(api_id, ret_payload);
-
- feature_data->feature_status = ret;
- hash_add(pm_api_features_map, &feature_data->hentry, api_id);
-
- if (api_id == PM_IOCTL)
- /* Store supported IOCTL IDs mask */
- memcpy(ioctl_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
- else if (api_id == PM_QUERY_DATA)
- /* Store supported QUERY IDs mask */
- memcpy(query_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
-
- return ret;
-}
-
-/**
- * zynqmp_pm_feature() - Check whether given feature is supported or not and
- * store supported IOCTL/QUERY ID mask
- * @api_id: API ID to check
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_feature(const u32 api_id)
-{
- int ret;
-
- if (!feature_check_enabled)
- return 0;
-
- ret = do_feature_check_call(api_id);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_feature);
-
-/**
- * zynqmp_pm_is_function_supported() - Check whether given IOCTL/QUERY function
- * is supported or not
- * @api_id: PM_IOCTL or PM_QUERY_DATA
- * @id: IOCTL or QUERY function IDs
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id)
-{
- int ret;
- u32 *bit_mask;
-
- /* Input arguments validation */
- if (id >= 64 || (api_id != PM_IOCTL && api_id != PM_QUERY_DATA))
- return -EINVAL;
-
- /* Check feature check API version */
- ret = do_feature_check_call(PM_FEATURE_CHECK);
- if (ret < 0)
- return ret;
-
- /* Check if feature check version 2 is supported or not */
- if ((ret & FIRMWARE_VERSION_MASK) == PM_API_VERSION_2) {
- /*
- * Call feature check for IOCTL/QUERY API to get IOCTL ID or
- * QUERY ID feature status.
- */
- ret = do_feature_check_call(api_id);
- if (ret < 0)
- return ret;
-
- bit_mask = (api_id == PM_IOCTL) ? ioctl_features : query_features;
-
- if ((bit_mask[(id / 32)] & BIT((id % 32))) == 0U)
- return -EOPNOTSUPP;
- } else {
- return -ENODATA;
- }
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported);
-
-/**
- * zynqmp_pm_invoke_fw_fn() - Invoke the system-level platform management layer
- * caller function depending on the configuration
- * @pm_api_id: Requested PM-API call
- * @ret_payload: Returned value array
- * @num_args: Number of arguments to requested PM-API call
- *
- * Invoke platform management function for SMC or HVC call, depending on
- * configuration.
- * Following SMC Calling Convention (SMCCC) for SMC64:
- * Pm Function Identifier,
- * PM_SIP_SVC + PASS_THROUGH_FW_CMD_ID =
- * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
- * ((SMC_64) << FUNCID_CC_SHIFT)
- * ((SIP_START) << FUNCID_OEN_SHIFT)
- * (PASS_THROUGH_FW_CMD_ID))
- *
- * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
- * PASS_THROUGH_FW_CMD_ID - Fixed SiP SVC call ID for FW specific calls.
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_invoke_fw_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
-{
- /*
- * Added SIP service call Function Identifier
- * Make sure to stay in x0 register
- */
- u64 smc_arg[SMC_ARG_CNT_64];
- int ret, i;
- va_list arg_list;
- u32 args[SMC_ARG_CNT_32] = {0};
- u32 module_id;
-
- /*
- * According to the SMCCC: The total number of registers available for
- * arguments is 16.
- *
- * In the Extended SMC format, 3 registers are used for headers, leaving
- * up to 13 registers for arguments.
- */
- if (num_args > SMC_ARG_CNT_32)
- return -EINVAL;
-
- /* Check if feature is supported or not */
- ret = zynqmp_pm_feature(pm_api_id);
- if (ret < 0)
- return ret;
-
- va_start(arg_list, num_args);
-
- for (i = 0; i < num_args; i++)
- args[i] = va_arg(arg_list, u32);
-
- va_end(arg_list);
-
- module_id = FIELD_GET(PLM_MODULE_ID_MASK, pm_api_id);
-
- if (module_id == 0)
- module_id = XPM_MODULE_ID;
-
- smc_arg[0] = PM_SIP_SVC | PASS_THROUGH_FW_CMD_ID;
- smc_arg[1] = ((u64)args[0] << 32U) | FIELD_PREP(PLM_MODULE_ID_MASK, module_id) |
- (pm_api_id & API_ID_MASK);
- for (i = 1; i < (SMC_ARG_CNT_64 - 1); i++)
- smc_arg[i + 1] = ((u64)args[(i * 2)] << 32U) | args[(i * 2) - 1];
-
- return do_fw_call(ret_payload, 8, smc_arg[0], smc_arg[1], smc_arg[2], smc_arg[3],
- smc_arg[4], smc_arg[5], smc_arg[6], smc_arg[7]);
-}
-
-/**
- * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
- * caller function depending on the configuration
- * @pm_api_id: Requested PM-API call
- * @ret_payload: Returned value array
- * @num_args: Number of arguments to requested PM-API call
- *
- * Invoke platform management function for SMC or HVC call, depending on
- * configuration.
- * Following SMC Calling Convention (SMCCC) for SMC64:
- * Pm Function Identifier,
- * PM_SIP_SVC + PM_API_ID =
- * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
- * ((SMC_64) << FUNCID_CC_SHIFT)
- * ((SIP_START) << FUNCID_OEN_SHIFT)
- * ((PM_API_ID) & FUNCID_NUM_MASK))
- *
- * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
- * PM_API_ID - Platform Management API ID.
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
-{
- /*
- * Added SIP service call Function Identifier
- * Make sure to stay in x0 register
- */
- u64 smc_arg[8];
- int ret, i;
- va_list arg_list;
- u32 args[SMC_ARG_CNT_BASIC_32] = {0};
-
- /*
- * According to the SMCCC: The total number of registers available for
- * arguments is 16.
- *
- * In the Basic SMC format, 2 registers are used for headers, leaving
- * up to 14 registers for arguments.
- */
- if (num_args > SMC_ARG_CNT_BASIC_32)
- return -EINVAL;
-
- /* Check if feature is supported or not */
- ret = zynqmp_pm_feature(pm_api_id);
- if (ret < 0)
- return ret;
-
- va_start(arg_list, num_args);
-
- for (i = 0; i < num_args; i++)
- args[i] = va_arg(arg_list, u32);
-
- va_end(arg_list);
-
- smc_arg[0] = PM_SIP_SVC | pm_api_id;
- for (i = 0; i < 7; i++)
- smc_arg[i + 1] = ((u64)args[(i * 2) + 1] << 32) | args[i * 2];
-
- return do_fw_call(ret_payload, 8, smc_arg[0], smc_arg[1], smc_arg[2], smc_arg[3],
- smc_arg[4], smc_arg[5], smc_arg[6], smc_arg[7]);
-}
-
int zynqmp_pm_register_sgi(u32 sgi_num, u32 reset)
{
int ret;
@@ -553,62 +91,13 @@ int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
}
EXPORT_SYMBOL_GPL(zynqmp_pm_get_chipid);
-/**
- * zynqmp_pm_get_family_info() - Get family info of platform
- * @family: Returned family code value
- *
- * Return: Returns status, either success or error+reason
- */
-int zynqmp_pm_get_family_info(u32 *family)
-{
- if (!active_platform_fw_data)
- return -ENODEV;
-
- if (!family)
- return -EINVAL;
-
- *family = active_platform_fw_data->family_code;
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(zynqmp_pm_get_family_info);
-
-/**
- * zynqmp_pm_get_sip_svc_version() - Get SiP service call version
- * @version: Returned version value
- *
- * Return: Returns status, either success or error+reason
- */
-static int zynqmp_pm_get_sip_svc_version(u32 *version)
-{
- struct arm_smccc_res res;
- u64 args[SMC_ARG_CNT_64] = {0};
-
- if (!version)
- return -EINVAL;
-
- /* Check if SiP SVC version already verified */
- if (sip_svc_version > 0) {
- *version = sip_svc_version;
- return 0;
- }
-
- args[0] = GET_SIP_SVC_VERSION;
-
- arm_smccc_smc(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &res);
-
- *version = ((lower_32_bits(res.a0) << 16U) | lower_32_bits(res.a1));
-
- return zynqmp_pm_ret_code(XST_PM_SUCCESS);
-}
-
/**
* zynqmp_pm_get_trustzone_version() - Get secure trustzone firmware version
* @version: Returned version value
*
* Return: Returns status, either success or error+reason
*/
-static int zynqmp_pm_get_trustzone_version(u32 *version)
+int zynqmp_pm_get_trustzone_version(u32 *version)
{
u32 ret_payload[PAYLOAD_ARG_CNT];
int ret;
@@ -622,36 +111,6 @@ static int zynqmp_pm_get_trustzone_version(u32 *version)
return ret;
}
-/**
- * get_set_conduit_method() - Choose SMC or HVC based communication
- * @np: Pointer to the device_node structure
- *
- * Use SMC or HVC-based functions to communicate with EL2/EL3.
- *
- * Return: Returns 0 on success or error code
- */
-static int get_set_conduit_method(struct device_node *np)
-{
- const char *method;
-
- if (of_property_read_string(np, "method", &method)) {
- pr_warn("%s missing \"method\" property\n", __func__);
- return -ENXIO;
- }
-
- if (!strcmp("hvc", method)) {
- do_fw_call = do_fw_call_hvc;
- } else if (!strcmp("smc", method)) {
- do_fw_call = do_fw_call_smc;
- } else {
- pr_warn("%s Invalid \"method\" property: %s\n",
- __func__, method);
- return -EINVAL;
- }
-
- return 0;
-}
-
/**
* zynqmp_pm_query_data() - Get query data from firmware
* @qdata: Variable to the zynqmp_pm_query_data structure
@@ -662,8 +121,14 @@ static int get_set_conduit_method(struct device_node *np)
int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata, u32 *out)
{
int ret, i = 0;
+ u32 sip_svc_version;
u32 ret_payload[PAYLOAD_ARG_CNT] = {0};
+ /* Get SiP SVC version number */
+ ret = zynqmp_pm_get_sip_svc_version(&sip_svc_version);
+ if (ret)
+ return ret;
+
if (sip_svc_version >= SIP_SVC_PASSTHROUGH_VERSION) {
ret = zynqmp_pm_invoke_fw_fn(PM_QUERY_DATA, ret_payload, 4,
qdata.qid, qdata.arg1,
@@ -1232,7 +697,7 @@ EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_write);
* This API function is to be used for notify the power management controller
* about the completed power management initialization.
*/
-static int zynqmp_pm_init_finalize(void)
+int zynqmp_pm_init_finalize(void)
{
return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE, NULL, 0);
}
@@ -2082,7 +1547,7 @@ static const struct attribute *zynqmp_firmware_attrs[] = {
NULL,
};
-static int zynqmp_firmware_pm_sysfs_entry(struct platform_device *pdev)
+int zynqmp_firmware_pm_sysfs_entry(struct platform_device *pdev)
{
int ret;
@@ -2094,254 +1559,3 @@ static int zynqmp_firmware_pm_sysfs_entry(struct platform_device *pdev)
return ret;
}
-
-/**
- * zynqmp_clear_pm_state() - Clear subsystem state
- * @dev: Device pointer used for logging
- *
- * Clears PM specific data in EL3 and platform firmware.
- *
- * Return: Returns status, either success or error
- */
-static int zynqmp_clear_pm_state(struct device *dev)
-{
- u32 pm_family_code;
- int ret;
-
- /* Get the Family code of platform */
- ret = zynqmp_pm_get_family_info(&pm_family_code);
- if (ret < 0)
- return ret;
-
- /* Supporting on Versal and Versal Net platforms only */
- if (pm_family_code == PM_VERSAL_FAMILY_CODE ||
- pm_family_code == PM_VERSAL_NET_FAMILY_CODE) {
- /* Check if EL3 firmware supports TF_A_CLEAR_PM_STATE */
- ret = do_feature_check_call(TF_A_CLEAR_PM_STATE);
- if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_1)) {
- /* Clear PM specific data in EL3 firmware */
- ret = zynqmp_pm_invoke_fn(TF_A_CLEAR_PM_STATE, NULL, 0);
- if (ret)
- dev_err(dev,
- "Failed to clear EL3 PM subsystem state: %d\n", ret);
- } else {
- dev_warn(dev, "TF_A_CLEAR_PM_STATE is not supported by EL3 firmware: %d\n", ret);
- }
-
- /* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */
- ret = do_feature_check_call(PM_RELEASE_NODE);
- if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_3)) {
- /* Attempt to release all peripheral devices via firmware */
- ret = zynqmp_pm_release_node(PM_DEV_ALL_PERIPH);
- if (ret)
- dev_err(dev, "Failed to release all peripheral devices: %d\n", ret);
- } else {
- dev_warn(dev,
- "Bulk device release is not supported by firmware: %d\n", ret);
- }
-
- /* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */
- ret = do_feature_check_call(PM_REQUEST_NODE);
- if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_3)) {
- /* Attempt to request all nodes via firmware */
- ret = zynqmp_pm_request_node(PM_DEV_ALL_PERIPH, 0, 0, 0);
- if (ret)
- dev_err(dev, "Failed to request all peripheral devices: %d\n", ret);
- } else {
- dev_warn(dev,
- "Firmware doesn't support request all peripheral devices at once: %d\n",
- ret);
- }
-
- /* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */
- ret = do_feature_check_call(PM_REGISTER_NOTIFIER);
- if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_3)) {
- /* Attempt to unregister all notifier callbacks via firmware */
- ret = zynqmp_pm_register_notifier(PM_ALL_NOTIFIERS, 0, 0, 0);
- if (ret)
- dev_err(dev, "Failed to unregister all notifiers: %d\n", ret);
- } else {
- dev_warn(dev,
- "Firmware doesn't support unregister all notifiers at once: %d\n",
- ret);
- ret = 0;
- }
- }
-
- return ret;
-}
-
-static int zynqmp_firmware_probe(struct platform_device *pdev)
-{
- u32 pm_api_version, pm_family_code, pm_tz_version;
- struct device *dev = &pdev->dev;
- struct zynqmp_devinfo *devinfo;
- int ret;
-
- ret = get_set_conduit_method(dev->of_node);
- if (ret)
- return ret;
-
- /* Get platform-specific firmware data from device tree match */
- active_platform_fw_data = (struct platform_fw_data *)device_get_match_data(dev);
- if (!active_platform_fw_data)
- return -EINVAL;
-
- /* Get SiP SVC version number */
- ret = zynqmp_pm_get_sip_svc_version(&sip_svc_version);
- if (ret)
- return ret;
-
- ret = do_feature_check_call(PM_FEATURE_CHECK);
- if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_1))
- feature_check_enabled = true;
-
- devinfo = devm_kzalloc_obj(dev, *devinfo);
- if (!devinfo)
- return -ENOMEM;
-
- devinfo->dev = dev;
-
- platform_set_drvdata(pdev, devinfo);
-
- /* Check PM API version number */
- ret = zynqmp_pm_get_api_version(&pm_api_version);
- if (ret)
- return ret;
-
- if (pm_api_version < ZYNQMP_PM_VERSION) {
- panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
- __func__,
- ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR,
- pm_api_version >> 16, pm_api_version & 0xFFFF);
- }
-
- pr_info("%s Platform Management API v%d.%d\n", __func__,
- pm_api_version >> 16, pm_api_version & 0xFFFF);
-
- /* Get the Family code of platform */
- ret = zynqmp_pm_get_family_info(&pm_family_code);
- if (ret < 0)
- return ret;
-
- if (is_kdump_kernel())
- zynqmp_clear_pm_state(dev);
-
- /* Check trustzone version number */
- ret = zynqmp_pm_get_trustzone_version(&pm_tz_version);
- if (ret)
- panic("Legacy trustzone found without version support\n");
-
- if (pm_tz_version < ZYNQMP_TZ_VERSION)
- panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
- __func__,
- ZYNQMP_TZ_VERSION_MAJOR, ZYNQMP_TZ_VERSION_MINOR,
- pm_tz_version >> 16, pm_tz_version & 0xFFFF);
-
- pr_info("%s Trustzone version v%d.%d\n", __func__,
- pm_tz_version >> 16, pm_tz_version & 0xFFFF);
-
- ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
- ARRAY_SIZE(firmware_devs), NULL, 0, NULL);
- if (ret) {
- dev_err(&pdev->dev, "failed to add MFD devices %d\n", ret);
- return ret;
- }
-
- ret = zynqmp_firmware_pm_sysfs_entry(pdev);
- if (ret) {
- pr_err("%s() Failed to create sysfs file with error%d\n",
- __func__, ret);
- return ret;
- }
-
- zynqmp_pm_api_debugfs_init();
-
- if (pm_family_code != PM_ZYNQMP_FAMILY_CODE) {
- em_dev = platform_device_register_data(&pdev->dev, "xlnx_event_manager",
- -1, NULL, 0);
- if (IS_ERR(em_dev))
- dev_err_probe(&pdev->dev, PTR_ERR(em_dev), "EM register fail with error\n");
- }
-
- return of_platform_populate(dev->of_node, NULL, NULL, dev);
-}
-
-static void zynqmp_firmware_shutdown(struct platform_device *pdev)
-{
- zynqmp_clear_pm_state(&pdev->dev);
-}
-
-static void zynqmp_firmware_remove(struct platform_device *pdev)
-{
- struct pm_api_feature_data *feature_data;
- struct hlist_node *tmp;
- int i;
-
- mfd_remove_devices(&pdev->dev);
- zynqmp_pm_api_debugfs_exit();
-
- hash_for_each_safe(pm_api_features_map, i, tmp, feature_data, hentry) {
- hash_del(&feature_data->hentry);
- kfree(feature_data);
- }
-
- platform_device_unregister(em_dev);
-}
-
-static const struct platform_fw_data platform_fw_data_versal = {
- .family_code = PM_VERSAL_FAMILY_CODE,
-};
-
-static const struct platform_fw_data platform_fw_data_versal_net = {
- .family_code = PM_VERSAL_NET_FAMILY_CODE,
-};
-
-static const struct platform_fw_data platform_fw_data_zynqmp = {
- .family_code = PM_ZYNQMP_FAMILY_CODE,
-};
-
-static const struct of_device_id zynqmp_firmware_of_match[] = {
- {.compatible = "xlnx,zynqmp-firmware", .data = &platform_fw_data_zynqmp},
- {.compatible = "xlnx,versal-firmware", .data = &platform_fw_data_versal},
- {.compatible = "xlnx,versal-net-firmware", .data = &platform_fw_data_versal_net},
- {},
-};
-MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
-
-static struct platform_driver zynqmp_firmware_driver = {
- .driver = {
- .name = "zynqmp_firmware",
- .of_match_table = zynqmp_firmware_of_match,
- },
- .probe = zynqmp_firmware_probe,
- .remove = zynqmp_firmware_remove,
- .shutdown = zynqmp_firmware_shutdown,
-};
-module_platform_driver(zynqmp_firmware_driver);
-
-/*
- * pm_init_finalize was previously called from the firmware driver's
- * sync_state callback, but sync_state can be blocked indefinitely if
- * any device consumer never probes. Use late_initcall to ensure
- * pm_init_finalize is called reliably regardless of consumer
- * probe status.
- */
-static int __init zynqmp_pm_init_finalize_late(void)
-{
- u32 pm_family_code;
- int ret;
-
- ret = zynqmp_pm_get_family_info(&pm_family_code);
- if (ret)
- return ret;
-
- if (pm_family_code != PM_ZYNQMP_FAMILY_CODE)
- return 0;
-
- if (zynqmp_pm_init_finalize())
- pr_warn("zynqmp: failed to release power management to firmware\n");
-
- return 0;
-}
-late_initcall(zynqmp_pm_init_finalize_late);
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-27 11:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 11:48 [PATCH 0/5] drivers: firmware: xilinx: Split ZynqMP firmware driver into modular components Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 1/5] drivers: firmware: xilinx: Relocate PDI library APIs to new file Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 2/5] drivers: firmware: xilinx: Relocate FPGA " Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 3/5] drivers: firmware: xilinx: Relocate NVM " Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 4/5] drivers: firmware: xilinx: Localize firmware version caches Jay Buddhabhatti
2026-11-27 11:48 ` [PATCH 5/5] drivers: firmware: xilinx: Split PM EEMI and core APIs in firmware Jay Buddhabhatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®