[PATCH v3 0/7] Add eFuse access for ZynqMP

From: Lukas Funke lukas.funke@weidmueller.com
This series adds a driver to read and write ZynqMP eFuses [1]. The driver can be accessed by the 'fuse read' and 'fuse write' commands
Example:
=> fuse read 0 0xc 3 Reading bank 0:
Word 0x0000000c: 3cb16685 013af244 40000000
Note: Accessing eFuses requires eFuse access to be enabled in the underlying PMU firmware.
Use cases are: - Reading/writing user specific eFuses to enable device specific implementations - Revoking SPK IDs - Reading SoC version/DNA
[1] https://docs.amd.com/r/en-US/ug1085-zynq-ultrascale-trm/eFUSE
Changes in v3: - Align ZynqMP eFuse driver with Linux kernel - Adapt versal, versal-net and zynqmp to use common chip-id function - Enable CMD_FUSE and ZYNQMP_EFUSE for zynqmp_virt and zynqmp_kria defconfig - Use 'dev_err' instead 'log_msg_ret' if possible
Changes in v2: - Drop vendor specific fuse cmd, use existing fuse cmd - Minor code refactoring (reverse x-mas tree)
Lukas Funke (7): configs: zynqmp_kria: Enable CMD_FUSE and ZYNQMP_EFUSE configs: zynqmp_virt: Enable CMD_FUSE and ZYNQMP_EFUSE soc: xilinx: versal: Use zynqmp_pm_get_chipid() to get chip revision soc: xilinx: versal-net: Use zynqmp_pm_get_chipid() to get chip revision soc: xilinx: zynqmp: Use zynqmp_pm_get_chipid() to get chip revision firmware: zynqmp: Add support to access efuses drivers: misc: Add driver to access ZynqMP efuses
configs/xilinx_zynqmp_kria_defconfig | 2 + configs/xilinx_zynqmp_virt_defconfig | 2 + drivers/firmware/firmware-zynqmp.c | 31 +++ drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 1 + drivers/misc/zynqmp_efuse.c | 360 +++++++++++++++++++++++++++ drivers/soc/soc_xilinx_versal.c | 13 +- drivers/soc/soc_xilinx_versal_net.c | 13 +- drivers/soc/soc_xilinx_zynqmp.c | 21 +- include/zynqmp_firmware.h | 2 + 10 files changed, 427 insertions(+), 26 deletions(-) create mode 100644 drivers/misc/zynqmp_efuse.c

From: Lukas Funke lukas.funke@weidmueller.com
Enable CMD_FUSE and ZYNQMP_EFUSE in order to be able to write ZyqnMP eFuses from within the bootloader for Kria SoM.
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
(no changes since v1)
configs/xilinx_zynqmp_virt_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/xilinx_zynqmp_virt_defconfig b/configs/xilinx_zynqmp_virt_defconfig index ee87beb19c6..1edd4ac77b1 100644 --- a/configs/xilinx_zynqmp_virt_defconfig +++ b/configs/xilinx_zynqmp_virt_defconfig @@ -65,6 +65,7 @@ CONFIG_CMD_DFU=y CONFIG_CMD_FPGA_LOADBP=y CONFIG_CMD_FPGA_LOADP=y CONFIG_CMD_FPGA_LOAD_SECURE=y +CONFIG_CMD_FUSE=y CONFIG_CMD_GPIO=y CONFIG_CMD_PWM=y CONFIG_CMD_GPT=y @@ -147,6 +148,7 @@ CONFIG_I2C_MUX_PCA954x=y CONFIG_LED=y CONFIG_LED_GPIO=y CONFIG_MISC=y +CONFIG_ZYNQMP_EFUSE=y CONFIG_I2C_EEPROM=y CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_IO_VOLTAGE=y

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Enable CMD_FUSE and ZYNQMP_EFUSE in order to be able to write ZyqnMP eFuses from within the bootloader for Kria SoM.
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
(no changes since v1)
configs/xilinx_zynqmp_virt_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/xilinx_zynqmp_virt_defconfig b/configs/xilinx_zynqmp_virt_defconfig index ee87beb19c6..1edd4ac77b1 100644 --- a/configs/xilinx_zynqmp_virt_defconfig +++ b/configs/xilinx_zynqmp_virt_defconfig @@ -65,6 +65,7 @@ CONFIG_CMD_DFU=y CONFIG_CMD_FPGA_LOADBP=y CONFIG_CMD_FPGA_LOADP=y CONFIG_CMD_FPGA_LOAD_SECURE=y +CONFIG_CMD_FUSE=y CONFIG_CMD_GPIO=y CONFIG_CMD_PWM=y CONFIG_CMD_GPT=y @@ -147,6 +148,7 @@ CONFIG_I2C_MUX_PCA954x=y CONFIG_LED=y CONFIG_LED_GPIO=y CONFIG_MISC=y +CONFIG_ZYNQMP_EFUSE=y CONFIG_I2C_EEPROM=y CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_IO_VOLTAGE=y
The patch itself is fine but it should be after symbol is defined. It means Kconfig change first and then enable it.
M

From: Lukas Funke lukas.funke@weidmueller.com
Enable CMD_FUSE and ZYNQMP_EFUSE in order to be able to write ZyqnMP eFuses from within the bootloader.
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
(no changes since v1)
configs/xilinx_zynqmp_kria_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/xilinx_zynqmp_kria_defconfig b/configs/xilinx_zynqmp_kria_defconfig index ba42f0c7848..ac91dccbe64 100644 --- a/configs/xilinx_zynqmp_kria_defconfig +++ b/configs/xilinx_zynqmp_kria_defconfig @@ -65,6 +65,7 @@ CONFIG_CMD_DFU=y CONFIG_CMD_FPGA_LOADBP=y CONFIG_CMD_FPGA_LOADP=y CONFIG_CMD_FPGA_LOAD_SECURE=y +CONFIG_CMD_FUSE=y CONFIG_CMD_GPIO=y CONFIG_CMD_PWM=y CONFIG_CMD_GPT=y @@ -147,6 +148,7 @@ CONFIG_I2C_MUX_PCA954x=y CONFIG_LED=y CONFIG_LED_GPIO=y CONFIG_MISC=y +CONFIG_ZYNQMP_EFUSE=y CONFIG_I2C_EEPROM=y CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_IO_VOLTAGE=y

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Enable CMD_FUSE and ZYNQMP_EFUSE in order to be able to write ZyqnMP eFuses from within the bootloader.
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
(no changes since v1)
configs/xilinx_zynqmp_kria_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/xilinx_zynqmp_kria_defconfig b/configs/xilinx_zynqmp_kria_defconfig index ba42f0c7848..ac91dccbe64 100644 --- a/configs/xilinx_zynqmp_kria_defconfig +++ b/configs/xilinx_zynqmp_kria_defconfig @@ -65,6 +65,7 @@ CONFIG_CMD_DFU=y CONFIG_CMD_FPGA_LOADBP=y CONFIG_CMD_FPGA_LOADP=y CONFIG_CMD_FPGA_LOAD_SECURE=y +CONFIG_CMD_FUSE=y CONFIG_CMD_GPIO=y CONFIG_CMD_PWM=y CONFIG_CMD_GPT=y @@ -147,6 +148,7 @@ CONFIG_I2C_MUX_PCA954x=y CONFIG_LED=y CONFIG_LED_GPIO=y CONFIG_MISC=y +CONFIG_ZYNQMP_EFUSE=y CONFIG_I2C_EEPROM=y CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_IO_VOLTAGE=y
Feel free to merge it with Kria. No need for two patches.
M

From: Lukas Funke lukas.funke@weidmueller.com
Use common zynqmp_pm_get_chipid() function to get the chip revision
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
(no changes since v1)
drivers/soc/soc_xilinx_versal.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/soc/soc_xilinx_versal.c b/drivers/soc/soc_xilinx_versal.c index 3d8c25c19bb..3d949c4e612 100644 --- a/drivers/soc/soc_xilinx_versal.c +++ b/drivers/soc/soc_xilinx_versal.c @@ -45,23 +45,22 @@ static const struct soc_ops soc_xilinx_versal_ops = { static int soc_xilinx_versal_probe(struct udevice *dev) { struct soc_xilinx_versal_priv *priv = dev_get_priv(dev); - u32 ret_payload[PAYLOAD_ARG_CNT]; + u32 idcode, version; int ret;
priv->family = versal_family;
- if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) { - ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, - ret_payload); + if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) { + ret = zynqmp_pm_get_chipid(&idcode, &version); if (ret) return ret; } else { - ret_payload[2] = readl(VERSAL_PS_PMC_VERSION); - if (!ret_payload[2]) + version = readl(VERSAL_PS_PMC_VERSION); + if (!version) return -EINVAL; }
- priv->revision = ret_payload[2] >> VERSAL_PS_VER_SHIFT; + priv->revision = version >> VERSAL_PS_VER_SHIFT;
return 0; }

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Use common zynqmp_pm_get_chipid() function to get the chip revision
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
(no changes since v1)
drivers/soc/soc_xilinx_versal.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/soc/soc_xilinx_versal.c b/drivers/soc/soc_xilinx_versal.c index 3d8c25c19bb..3d949c4e612 100644 --- a/drivers/soc/soc_xilinx_versal.c +++ b/drivers/soc/soc_xilinx_versal.c @@ -45,23 +45,22 @@ static const struct soc_ops soc_xilinx_versal_ops = { static int soc_xilinx_versal_probe(struct udevice *dev) { struct soc_xilinx_versal_priv *priv = dev_get_priv(dev);
- u32 ret_payload[PAYLOAD_ARG_CNT];
u32 idcode, version; int ret;
priv->family = versal_family;
- if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
ret_payload);
- if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) {
ret = zynqmp_pm_get_chipid(&idcode, &version);
This function is defined in 6/7 that's why this will fail when it compiles which end up in non bisectable tree.
if (ret) return ret;
} else {
ret_payload[2] = readl(VERSAL_PS_PMC_VERSION);
if (!ret_payload[2])
version = readl(VERSAL_PS_PMC_VERSION);
}if (!version) return -EINVAL;
- priv->revision = ret_payload[2] >> VERSAL_PS_VER_SHIFT;
priv->revision = version >> VERSAL_PS_VER_SHIFT;
return 0; }
But code is ok.
M

From: Lukas Funke lukas.funke@weidmueller.com
Use common zynqmp_pm_get_chipid() function to get the chip revision
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
(no changes since v1)
drivers/soc/soc_xilinx_versal_net.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/soc/soc_xilinx_versal_net.c b/drivers/soc/soc_xilinx_versal_net.c index 146d068bb4a..76467a3bbb5 100644 --- a/drivers/soc/soc_xilinx_versal_net.c +++ b/drivers/soc/soc_xilinx_versal_net.c @@ -47,23 +47,22 @@ static const struct soc_ops soc_xilinx_versal_net_ops = { static int soc_xilinx_versal_net_probe(struct udevice *dev) { struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev); - u32 ret_payload[PAYLOAD_ARG_CNT]; + u32 idcode, version; int ret;
priv->family = versal_family;
- if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) { - ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, - ret_payload); + if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) { + ret = zynqmp_pm_get_chipid(&idcode, &version); if (ret) return ret; } else { - ret_payload[2] = readl(PMC_TAP_VERSION); - if (!ret_payload[2]) + version = readl(PMC_TAP_VERSION); + if (!version) return -EINVAL; }
- priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]); + priv->revision = FIELD_GET(PS_VERSION_MASK, version);
return 0; }

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Use common zynqmp_pm_get_chipid() function to get the chip revision
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
(no changes since v1)
drivers/soc/soc_xilinx_versal_net.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/soc/soc_xilinx_versal_net.c b/drivers/soc/soc_xilinx_versal_net.c index 146d068bb4a..76467a3bbb5 100644 --- a/drivers/soc/soc_xilinx_versal_net.c +++ b/drivers/soc/soc_xilinx_versal_net.c @@ -47,23 +47,22 @@ static const struct soc_ops soc_xilinx_versal_net_ops = { static int soc_xilinx_versal_net_probe(struct udevice *dev) { struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
- u32 ret_payload[PAYLOAD_ARG_CNT];
u32 idcode, version; int ret;
priv->family = versal_family;
- if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
ret_payload);
- if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) {
if (ret) return ret; } else {ret = zynqmp_pm_get_chipid(&idcode, &version);
ret_payload[2] = readl(PMC_TAP_VERSION);
if (!ret_payload[2])
version = readl(PMC_TAP_VERSION);
}if (!version) return -EINVAL;
- priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]);
priv->revision = FIELD_GET(PS_VERSION_MASK, version);
return 0; }
Reviewed-by: Michal Simek michal.simek@amd.com
Thanks, Michal

From: Lukas Funke lukas.funke@weidmueller.com
Use common zynqmp_pm_get_chipid() function to get the chip revision
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
(no changes since v1)
drivers/soc/soc_xilinx_zynqmp.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/soc/soc_xilinx_zynqmp.c b/drivers/soc/soc_xilinx_zynqmp.c index d8b4f172a39..8a65810b7d7 100644 --- a/drivers/soc/soc_xilinx_zynqmp.c +++ b/drivers/soc/soc_xilinx_zynqmp.c @@ -346,22 +346,21 @@ static const struct soc_ops soc_xilinx_zynqmp_ops = { static int soc_xilinx_zynqmp_probe(struct udevice *dev) { struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev); - u32 ret_payload[PAYLOAD_ARG_CNT]; + u32 idcode, version; int ret;
priv->family = zynqmp_family;
- if (!IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) - ret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &ret_payload[2]); + if (!CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) + ret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &version); else - ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, - ret_payload); + ret = zynqmp_pm_get_chipid(&idcode, &version); if (ret < 0) return ret;
- priv->revision = ret_payload[2] & ZYNQMP_PS_VER_MASK; + priv->revision = version & ZYNQMP_PS_VER_MASK;
- if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) { + if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) { /* * Firmware returns: * payload[0][31:0] = status of the operation @@ -370,11 +369,9 @@ static int soc_xilinx_zynqmp_probe(struct udevice *dev) * payload[2][28:20] = EXTENDED_IDCODE * payload[2][29] = PL_INIT */ - u32 idcode = ret_payload[1]; - u32 idcode2 = ret_payload[2] >> - ZYNQMP_CSU_VERSION_EMPTY_SHIFT; - dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode, - idcode2); + u32 idcode2 = version >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT; + + dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode, idcode2);
ret = soc_xilinx_zynqmp_detect_machine(dev, idcode, idcode2); if (ret)

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Use common zynqmp_pm_get_chipid() function to get the chip revision
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
(no changes since v1)
drivers/soc/soc_xilinx_zynqmp.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/soc/soc_xilinx_zynqmp.c b/drivers/soc/soc_xilinx_zynqmp.c index d8b4f172a39..8a65810b7d7 100644 --- a/drivers/soc/soc_xilinx_zynqmp.c +++ b/drivers/soc/soc_xilinx_zynqmp.c @@ -346,22 +346,21 @@ static const struct soc_ops soc_xilinx_zynqmp_ops = { static int soc_xilinx_zynqmp_probe(struct udevice *dev) { struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
- u32 ret_payload[PAYLOAD_ARG_CNT];
u32 idcode, version; int ret;
priv->family = zynqmp_family;
- if (!IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE))
ret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &ret_payload[2]);
- if (!CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE))
elseret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &version);
ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
ret_payload);
if (ret < 0) return ret;ret = zynqmp_pm_get_chipid(&idcode, &version);
- priv->revision = ret_payload[2] & ZYNQMP_PS_VER_MASK;
- priv->revision = version & ZYNQMP_PS_VER_MASK;
- if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
- if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) { /*
- Firmware returns:
- payload[0][31:0] = status of the operation
@@ -370,11 +369,9 @@ static int soc_xilinx_zynqmp_probe(struct udevice *dev) * payload[2][28:20] = EXTENDED_IDCODE * payload[2][29] = PL_INIT */
u32 idcode = ret_payload[1];
u32 idcode2 = ret_payload[2] >>
ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode,
idcode2);
u32 idcode2 = version >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode, idcode2);
ret = soc_xilinx_zynqmp_detect_machine(dev, idcode, idcode2); if (ret)
Looks good. Reviewed-by: Michal Simek michal.simek@amd.com
Thanks, Michal

From: Lukas Funke lukas.funke@weidmueller.com
Add functions to access efuses through PMU firmware interface.
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
(no changes since v1)
drivers/firmware/firmware-zynqmp.c | 31 ++++++++++++++++++++++++++++++ include/zynqmp_firmware.h | 2 ++ 2 files changed, 33 insertions(+)
diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c index dfad798a2e7..8e9687693dd 100644 --- a/drivers/firmware/firmware-zynqmp.c +++ b/drivers/firmware/firmware-zynqmp.c @@ -211,6 +211,37 @@ int zynqmp_pm_feature(const u32 api_id) return ret_payload[1] & FIRMWARE_VERSION_MASK; }
+int zynqmp_pm_get_chipid(u32 *idcode, u32 *version) +{ + u32 ret_payload[PAYLOAD_ARG_CNT]; + int ret; + + if (!idcode || !version) + return -EINVAL; + + ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload); + *idcode = ret_payload[1]; + *version = ret_payload[2]; + + return ret; +} + +int zynqmp_pm_efuse_access(const u64 address, u32 *out) +{ + u32 ret_payload[PAYLOAD_ARG_CNT]; + int ret; + + if (!out) + return -EINVAL; + + ret = xilinx_pm_request(PM_EFUSE_ACCESS, upper_32_bits(address), + lower_32_bits(address), 0, 0, ret_payload); + + *out = ret_payload[1]; + + return ret; +} + int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id) { int ret; diff --git a/include/zynqmp_firmware.h b/include/zynqmp_firmware.h index 73198a6a6ea..7f18b4d59bf 100644 --- a/include/zynqmp_firmware.h +++ b/include/zynqmp_firmware.h @@ -453,6 +453,8 @@ int xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config, u32 value); int zynqmp_pm_set_gem_config(u32 node, enum pm_gem_config_type config, u32 value); +int zynqmp_pm_get_chipid(u32 *idcode, u32 *version); +int zynqmp_pm_efuse_access(const u64 address, u32 *out); int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id); int zynqmp_mmio_read(const u32 address, u32 *value); int zynqmp_mmio_write(const u32 address, const u32 mask, const u32 value);

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Add functions to access efuses through PMU firmware interface.
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
(no changes since v1)
drivers/firmware/firmware-zynqmp.c | 31 ++++++++++++++++++++++++++++++ include/zynqmp_firmware.h | 2 ++ 2 files changed, 33 insertions(+)
diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c index dfad798a2e7..8e9687693dd 100644 --- a/drivers/firmware/firmware-zynqmp.c +++ b/drivers/firmware/firmware-zynqmp.c @@ -211,6 +211,37 @@ int zynqmp_pm_feature(const u32 api_id) return ret_payload[1] & FIRMWARE_VERSION_MASK; }
+int zynqmp_pm_get_chipid(u32 *idcode, u32 *version) +{
- u32 ret_payload[PAYLOAD_ARG_CNT];
- int ret;
- if (!idcode || !version)
return -EINVAL;
- ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
- *idcode = ret_payload[1];
- *version = ret_payload[2];
- return ret;
+}
+int zynqmp_pm_efuse_access(const u64 address, u32 *out) +{
- u32 ret_payload[PAYLOAD_ARG_CNT];
- int ret;
- if (!out)
return -EINVAL;
- ret = xilinx_pm_request(PM_EFUSE_ACCESS, upper_32_bits(address),
lower_32_bits(address), 0, 0, ret_payload);
- *out = ret_payload[1];
- return ret;
+}
- int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id) { int ret;
diff --git a/include/zynqmp_firmware.h b/include/zynqmp_firmware.h index 73198a6a6ea..7f18b4d59bf 100644 --- a/include/zynqmp_firmware.h +++ b/include/zynqmp_firmware.h @@ -453,6 +453,8 @@ int xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config, u32 value); int zynqmp_pm_set_gem_config(u32 node, enum pm_gem_config_type config, u32 value); +int zynqmp_pm_get_chipid(u32 *idcode, u32 *version); +int zynqmp_pm_efuse_access(const u64 address, u32 *out); int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id); int zynqmp_mmio_read(const u32 address, u32 *value); int zynqmp_mmio_write(const u32 address, const u32 mask, const u32 value);
Reviewed-by: Michal Simek michal.simek@amd.com
Thanks, Michal

From: Lukas Funke lukas.funke@weidmueller.com
Add driver to access ZynqMP efuses. This is a u-boot port of [1].
Note: Accessing eFuses requires eFuse access to be enabled in the underlying PMU firmware.
[1] https://lore.kernel.org/all/20240224114516.86365-8-srinivas.kandagatla@linar...
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com ---
Changes in v3: - Align ZynqMP eFuse driver with Linux kernel - Adapt versal, versal-net and zynqmp to use common chip-id function - Enable CMD_FUSE and ZYNQMP_EFUSE for zynqmp_virt and zynqmp_kria defconfig - Use 'dev_err' instead 'log_msg_ret' if possible
Changes in v2: - Drop vendor specific fuse cmd, use existing fuse cmd - Minor code refactoring (reverse x-mas tree)
drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 1 + drivers/misc/zynqmp_efuse.c | 360 ++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 drivers/misc/zynqmp_efuse.c
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 6009d55f400..c07f50c9a76 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -298,6 +298,14 @@ config FSL_SEC_MON Security Monitor can be transitioned on any security failures, like software violations or hardware security violations.
+config ZYNQMP_EFUSE + bool "Enable ZynqMP eFUSE Driver" + depends on ZYNQMP_FIRMWARE + help + Enable access to Zynq UltraScale (ZynqMP) eFUSEs thought PMU firmware + interface. ZnyqMP has 256 eFUSEs where some of them are security related + and cannot be read back (i.e. AES key). + choice prompt "Security monitor interaction endianess" depends on FSL_SEC_MON diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index e53d52c47b3..68ba5648eab 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -92,3 +92,4 @@ obj-$(CONFIG_ESM_K3) += k3_esm.o obj-$(CONFIG_ESM_PMIC) += esm_pmic.o obj-$(CONFIG_SL28CPLD) += sl28cpld.o obj-$(CONFIG_SPL_SOCFPGA_DT_REG) += socfpga_dtreg.o +obj-$(CONFIG_ZYNQMP_EFUSE) += zynqmp_efuse.o diff --git a/drivers/misc/zynqmp_efuse.c b/drivers/misc/zynqmp_efuse.c new file mode 100644 index 00000000000..d12de7494d2 --- /dev/null +++ b/drivers/misc/zynqmp_efuse.c @@ -0,0 +1,360 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2014 - 2015 Xilinx, Inc. + * Michal Simek michal.simek@amd.com + * + * (C) Copyright 2024 Weidmueller Interface GmbH + * Lukas Funke lukas.funke@weidmueller.com + */ + +#include <compiler.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <zynqmp_firmware.h> +#include <asm/dma-mapping.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <misc.h> + +#define SILICON_REVISION_MASK 0xF +#define P_USER_0_64_UPPER_MASK GENMASK(31, 16) +#define P_USER_127_LOWER_4_BIT_MASK GENMASK(3, 0) +#define WORD_INBYTES 4 +#define SOC_VER_SIZE 0x4 +#define EFUSE_MEMORY_SIZE 0x177 +#define UNUSED_SPACE 0x8 +#define ZYNQMP_NVMEM_SIZE (SOC_VER_SIZE + UNUSED_SPACE + \ + EFUSE_MEMORY_SIZE) +#define SOC_VERSION_OFFSET 0x0 +#define EFUSE_START_OFFSET 0xC +#define EFUSE_END_OFFSET 0xFC +#define EFUSE_PUF_START_OFFSET 0x100 +#define EFUSE_PUF_MID_OFFSET 0x140 +#define EFUSE_PUF_END_OFFSET 0x17F +#define EFUSE_NOT_ENABLED 29 + +/* + * efuse access type + */ +enum efuse_access { + EFUSE_READ = 0, + EFUSE_WRITE +}; + +/** + * struct xilinx_efuse - the basic structure + * @src: address of the buffer to store the data to be write/read + * @size: read/write word count + * @offset: read/write offset + * @flag: 0 - represents efuse read and 1- represents efuse write + * @pufuserfuse:0 - represents non-puf efuses, offset is used for read/write + * 1 - represents puf user fuse row number. + * + * this structure stores all the required details to + * read/write efuse memory. + */ +struct xilinx_efuse { + u64 src; + u32 size; + u32 offset; + enum efuse_access flag; + u32 pufuserfuse; +}; + +/** + * struct efuse_map_entry - offset and length of zynqmp fuses + * @offset: offset of efuse to be read/write + * @length: length of efuse + */ +struct efuse_map_entry { + u32 offset; + u32 length; +}; + +struct efuse_map_entry zynqmp_efuse_table[] = { + {0x000, 0x04}, /* soc revision */ + {0x00c, 0x0c}, /* SoC DNA */ + {0x020, 0x04}, /* efuse-usr0 */ + {0x024, 0x04}, /* efuse-usr1 */ + {0x028, 0x04}, /* efuse-usr2 */ + {0x02c, 0x04}, /* efuse-usr3 */ + {0x030, 0x04}, /* efuse-usr4 */ + {0x034, 0x04}, /* efuse-usr5 */ + {0x038, 0x04}, /* efuse-usr6 */ + {0x03c, 0x04}, /* efuse-usr7 */ + {0x040, 0x04}, /* efuse-miscusr */ + {0x050, 0x04}, /* efuse-chash */ + {0x054, 0x04}, /* efuse-pufmisc */ + {0x058, 0x04}, /* efuse-sec */ + {0x05c, 0x04}, /* efuse-spkid */ + {0x060, 0x30}, /* efuse-aeskey */ + {0x0a0, 0x30}, /* ppk0-hash */ + {0x0d0, 0x30}, /* ppk1-hash */ + {0x100, 0x7f}, /* pufuser */ +}; + +static int zynqmp_efuse_get_length(u32 offset, u32 *base_offset, u32 *len) +{ + struct efuse_map_entry *fuse; + int i; + + for (i = 0; i < ARRAY_SIZE(zynqmp_efuse_table); ++i) { + fuse = &zynqmp_efuse_table[i]; + if (offset >= fuse->offset && + offset < fuse->offset + fuse->length) { + *base_offset = fuse->offset; + *len = fuse->length; + return 0; + } + } + + return -ENOENT; +} + +static int zynqmp_efuse_access(void *context, unsigned int offset, + void *val, size_t bytes, enum efuse_access flag, + unsigned int pufflag) +{ + struct udevice *dev = context; + struct xilinx_efuse *efuse; + ulong dma_addr; + ulong dma_buf; + size_t words = bytes / WORD_INBYTES; + int ret; + int value; + char *data; + + if (bytes % WORD_INBYTES != 0) { + dev_err(dev, "Bytes requested should be word aligned\n"); + return -EOPNOTSUPP; + } + + if (pufflag == 0 && offset % WORD_INBYTES) { + dev_err(dev, "Offset requested should be word aligned\n"); + return -EOPNOTSUPP; + } + + if (pufflag == 1 && flag == EFUSE_WRITE) { + memcpy(&value, val, bytes); + if ((offset == EFUSE_PUF_START_OFFSET || + offset == EFUSE_PUF_MID_OFFSET) && + value & P_USER_0_64_UPPER_MASK) { + dev_err(dev, "Only lower 4 bytes are allowed to be programmed in P_USER_0 & P_USER_64\n"); + return -EOPNOTSUPP; + } + + if (offset == EFUSE_PUF_END_OFFSET && + (value & P_USER_127_LOWER_4_BIT_MASK)) { + dev_err(dev, "Only MSB 28 bits are allowed to be programmed for P_USER_127\n"); + return -EOPNOTSUPP; + } + } + + efuse = dma_alloc_coherent(sizeof(struct xilinx_efuse), &dma_addr); + if (!efuse) + return -ENOMEM; + + data = dma_alloc_coherent(bytes, &dma_buf); + if (!data) { + ret = -ENOMEM; + goto efuse_data_fail; + } + + if (flag == EFUSE_WRITE) { + memcpy(data, val, bytes); + efuse->flag = EFUSE_WRITE; + } else { + efuse->flag = EFUSE_READ; + } + + efuse->src = dma_buf; + efuse->size = words; + efuse->offset = offset; + efuse->pufuserfuse = pufflag; + + flush_dcache_range((ulong)efuse, (ulong)efuse + + roundup(sizeof(struct xilinx_efuse), ARCH_DMA_MINALIGN)); + flush_dcache_range((ulong)data, (ulong)data + + roundup(sizeof(struct xilinx_efuse), ARCH_DMA_MINALIGN)); + + zynqmp_pm_efuse_access(dma_addr, (u32 *)&ret); + if (ret != 0) { + if (ret == EFUSE_NOT_ENABLED) { + dev_err(dev, "efuse access is not enabled\n"); + ret = -EOPNOTSUPP; + } else { + dev_err(dev, "Error in efuse read %x\n", ret); + ret = -EPERM; + } + goto efuse_access_err; + } + + if (flag == EFUSE_READ) + memcpy(val, data, bytes); +efuse_access_err: + dma_free_coherent(data); +efuse_data_fail: + dma_free_coherent(efuse); + + return ret; +} + +static int zynqmp_nvmem_read(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct udevice *dev = context; + int ret; + int pufflag = 0; + int idcode; + int version; + + if (offset >= EFUSE_PUF_START_OFFSET && offset <= EFUSE_PUF_END_OFFSET) + pufflag = 1; + + switch (offset) { + /* Soc version offset is zero */ + case SOC_VERSION_OFFSET: + if (bytes != SOC_VER_SIZE) + return -EOPNOTSUPP; + + ret = zynqmp_pm_get_chipid((u32 *)&idcode, (u32 *)&version); + if (ret < 0) + return ret; + + dev_dbg(dev, "Read chipid val %x %x\n", idcode, version); + *(int *)val = version & SILICON_REVISION_MASK; + break; + /* Efuse offset starts from 0xc */ + case EFUSE_START_OFFSET ... EFUSE_END_OFFSET: + case EFUSE_PUF_START_OFFSET ... EFUSE_PUF_END_OFFSET: + ret = zynqmp_efuse_access(context, offset, val, + bytes, EFUSE_READ, pufflag); + break; + default: + *(u32 *)val = 0xDEADBEEF; + ret = 0; + break; + } + + return ret; +} + +static int zynqmp_nvmem_write(void *context, + unsigned int offset, void *val, size_t bytes) +{ + int pufflag = 0; + + if (offset < EFUSE_START_OFFSET || offset > EFUSE_PUF_END_OFFSET) + return -EOPNOTSUPP; + + if (offset >= EFUSE_PUF_START_OFFSET && offset <= EFUSE_PUF_END_OFFSET) + pufflag = 1; + + return zynqmp_efuse_access(context, offset, + val, bytes, EFUSE_WRITE, pufflag); +} + +int fuse_read(u32 bank, u32 word, u32 *val) +{ + u32 base_offset, offset, len; + struct udevice *dev; + u8 buf[128]; /* maximal size of efuse is 0x7f (pufuse) */ + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(zynqmp_efuse), &dev); + if (ret) + return log_msg_ret("uclass_drv", ret); + + ret = zynqmp_efuse_get_length(word, &base_offset, &len); + if (ret) { + dev_err(dev, "Invalid eFuse word offset\n"); + return ret; + } + + if (len > sizeof(buf)) + return -EINVAL; + + memset(buf, 0, sizeof(buf)); + + ret = misc_read(dev, base_offset, (void *)buf, len); + if (ret) { + dev_err(dev, "Cannot read eFuse @%u: %d", word, ret); + return ret; + } + + offset = word - base_offset; + *val = ((u32 *)buf)[offset]; + + return 0; +} + +int fuse_prog(u32 bank, u32 word, u32 val) +{ + u32 base_offset, len; + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(zynqmp_efuse), &dev); + if (ret) + return log_msg_ret("uclass_drv", ret); + + ret = zynqmp_efuse_get_length(word, &base_offset, &len); + if (ret) { + dev_err(dev, "Invalid eFuse word offset\n"); + return ret; + } + + if (word != base_offset || len != sizeof(val)) + return -EINVAL; + + ret = misc_write(dev, word, (void *)&val, sizeof(val)); + if (ret) { + dev_err(dev, "Cannot write eFuse @%u: %d", word, ret); + return ret; + } + + return 0; +} + +int fuse_sense(u32 bank, u32 word, u32 *val) +{ + /* sense is not supported */ + return -ENOSYS; +} + +int fuse_override(u32 bank, u32 word, u32 val) +{ + /* overriding is not supported */ + return -ENOSYS; +} + +static int zynqmp_nvmem_read_compat(struct udevice *dev, int offset, + void *val, int bytes) +{ + return zynqmp_nvmem_read((void *)dev, offset, val, bytes); +} + +static int zynqmp_nvmem_write_compat(struct udevice *dev, int offset, + const void *val, int bytes) +{ + return zynqmp_nvmem_write((void *)dev, offset, (void *)val, bytes); +} + +static const struct udevice_id zynqmp_efuse_match[] = { + { .compatible = "xlnx,zynqmp-nvmem-fw", }, + { /* sentinel */ }, +}; + +static const struct misc_ops zynqmp_efuse_ops = { + .read = zynqmp_nvmem_read_compat, + .write = zynqmp_nvmem_write_compat, +}; + +U_BOOT_DRIVER(zynqmp_efuse) = { + .name = "zynqmp_efuse", + .id = UCLASS_MISC, + .of_match = zynqmp_efuse_match, + .ops = &zynqmp_efuse_ops, +};

On 6/4/24 16:27, lukas.funke-oss@weidmueller.com wrote:
From: Lukas Funke lukas.funke@weidmueller.com
Add driver to access ZynqMP efuses. This is a u-boot port of [1].
Note: Accessing eFuses requires eFuse access to be enabled in the underlying PMU firmware.
[1] https://lore.kernel.org/all/20240224114516.86365-8-srinivas.kandagatla@linar...
Signed-off-by: Lukas Funke lukas.funke@weidmueller.com
Changes in v3:
- Align ZynqMP eFuse driver with Linux kernel
- Adapt versal, versal-net and zynqmp to use common chip-id function
- Enable CMD_FUSE and ZYNQMP_EFUSE for zynqmp_virt and zynqmp_kria defconfig
- Use 'dev_err' instead 'log_msg_ret' if possible
Changes in v2:
Drop vendor specific fuse cmd, use existing fuse cmd
Minor code refactoring (reverse x-mas tree)
drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 1 + drivers/misc/zynqmp_efuse.c | 360 ++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 drivers/misc/zynqmp_efuse.c
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 6009d55f400..c07f50c9a76 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -298,6 +298,14 @@ config FSL_SEC_MON Security Monitor can be transitioned on any security failures, like software violations or hardware security violations.
+config ZYNQMP_EFUSE
- bool "Enable ZynqMP eFUSE Driver"
- depends on ZYNQMP_FIRMWARE
- help
Enable access to Zynq UltraScale (ZynqMP) eFUSEs thought PMU firmware
interface. ZnyqMP has 256 eFUSEs where some of them are security related
and cannot be read back (i.e. AES key).
- choice prompt "Security monitor interaction endianess" depends on FSL_SEC_MON
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index e53d52c47b3..68ba5648eab 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -92,3 +92,4 @@ obj-$(CONFIG_ESM_K3) += k3_esm.o obj-$(CONFIG_ESM_PMIC) += esm_pmic.o obj-$(CONFIG_SL28CPLD) += sl28cpld.o obj-$(CONFIG_SPL_SOCFPGA_DT_REG) += socfpga_dtreg.o +obj-$(CONFIG_ZYNQMP_EFUSE) += zynqmp_efuse.o diff --git a/drivers/misc/zynqmp_efuse.c b/drivers/misc/zynqmp_efuse.c new file mode 100644 index 00000000000..d12de7494d2 --- /dev/null +++ b/drivers/misc/zynqmp_efuse.c @@ -0,0 +1,360 @@ +// SPDX-License-Identifier: GPL-2.0+ +/*
- (C) Copyright 2014 - 2015 Xilinx, Inc.
- Michal Simek michal.simek@amd.com
Not sure which version you used as source but please sync up with kernel version you used. I expect there will be much newer dates because efuse were added recently.
- (C) Copyright 2024 Weidmueller Interface GmbH
- Lukas Funke lukas.funke@weidmueller.com
- */
+#include <compiler.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <zynqmp_firmware.h> +#include <asm/dma-mapping.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <misc.h>
+#define SILICON_REVISION_MASK 0xF +#define P_USER_0_64_UPPER_MASK GENMASK(31, 16) +#define P_USER_127_LOWER_4_BIT_MASK GENMASK(3, 0) +#define WORD_INBYTES 4 +#define SOC_VER_SIZE 0x4 +#define EFUSE_MEMORY_SIZE 0x177 +#define UNUSED_SPACE 0x8 +#define ZYNQMP_NVMEM_SIZE (SOC_VER_SIZE + UNUSED_SPACE + \
EFUSE_MEMORY_SIZE)
+#define SOC_VERSION_OFFSET 0x0 +#define EFUSE_START_OFFSET 0xC +#define EFUSE_END_OFFSET 0xFC +#define EFUSE_PUF_START_OFFSET 0x100 +#define EFUSE_PUF_MID_OFFSET 0x140 +#define EFUSE_PUF_END_OFFSET 0x17F +#define EFUSE_NOT_ENABLED 29
+/*
- efuse access type
- */
+enum efuse_access {
- EFUSE_READ = 0,
- EFUSE_WRITE
+};
+/**
- struct xilinx_efuse - the basic structure
- @src: address of the buffer to store the data to be write/read
- @size: read/write word count
- @offset: read/write offset
- @flag: 0 - represents efuse read and 1- represents efuse write
- @pufuserfuse:0 - represents non-puf efuses, offset is used for read/write
1 - represents puf user fuse row number.
- this structure stores all the required details to
- read/write efuse memory.
- */
+struct xilinx_efuse {
- u64 src;
- u32 size;
- u32 offset;
- enum efuse_access flag;
- u32 pufuserfuse;
+};
+/**
- struct efuse_map_entry - offset and length of zynqmp fuses
- @offset: offset of efuse to be read/write
- @length: length of efuse
- */
+struct efuse_map_entry {
- u32 offset;
- u32 length;
+};
+struct efuse_map_entry zynqmp_efuse_table[] = {
- {0x000, 0x04}, /* soc revision */
- {0x00c, 0x0c}, /* SoC DNA */
- {0x020, 0x04}, /* efuse-usr0 */
- {0x024, 0x04}, /* efuse-usr1 */
- {0x028, 0x04}, /* efuse-usr2 */
- {0x02c, 0x04}, /* efuse-usr3 */
- {0x030, 0x04}, /* efuse-usr4 */
- {0x034, 0x04}, /* efuse-usr5 */
- {0x038, 0x04}, /* efuse-usr6 */
- {0x03c, 0x04}, /* efuse-usr7 */
- {0x040, 0x04}, /* efuse-miscusr */
- {0x050, 0x04}, /* efuse-chash */
- {0x054, 0x04}, /* efuse-pufmisc */
- {0x058, 0x04}, /* efuse-sec */
- {0x05c, 0x04}, /* efuse-spkid */
- {0x060, 0x30}, /* efuse-aeskey */
- {0x0a0, 0x30}, /* ppk0-hash */
- {0x0d0, 0x30}, /* ppk1-hash */
- {0x100, 0x7f}, /* pufuser */
+};
+static int zynqmp_efuse_get_length(u32 offset, u32 *base_offset, u32 *len) +{
- struct efuse_map_entry *fuse;
- int i;
- for (i = 0; i < ARRAY_SIZE(zynqmp_efuse_table); ++i) {
fuse = &zynqmp_efuse_table[i];
if (offset >= fuse->offset &&
offset < fuse->offset + fuse->length) {
*base_offset = fuse->offset;
*len = fuse->length;
return 0;
}
nit: wrong indentation one less tab for }
- }
- return -ENOENT;
+}
+static int zynqmp_efuse_access(void *context, unsigned int offset,
void *val, size_t bytes, enum efuse_access flag,
unsigned int pufflag)
+{
- struct udevice *dev = context;
- struct xilinx_efuse *efuse;
- ulong dma_addr;
- ulong dma_buf;
- size_t words = bytes / WORD_INBYTES;
- int ret;
- int value;
- char *data;
- if (bytes % WORD_INBYTES != 0) {
dev_err(dev, "Bytes requested should be word aligned\n");
return -EOPNOTSUPP;
- }
- if (pufflag == 0 && offset % WORD_INBYTES) {
dev_err(dev, "Offset requested should be word aligned\n");
return -EOPNOTSUPP;
- }
- if (pufflag == 1 && flag == EFUSE_WRITE) {
memcpy(&value, val, bytes);
if ((offset == EFUSE_PUF_START_OFFSET ||
offset == EFUSE_PUF_MID_OFFSET) &&
value & P_USER_0_64_UPPER_MASK) {
dev_err(dev, "Only lower 4 bytes are allowed to be programmed in P_USER_0 & P_USER_64\n");
return -EOPNOTSUPP;
}
if (offset == EFUSE_PUF_END_OFFSET &&
(value & P_USER_127_LOWER_4_BIT_MASK)) {
dev_err(dev, "Only MSB 28 bits are allowed to be programmed for P_USER_127\n");
return -EOPNOTSUPP;
}
- }
- efuse = dma_alloc_coherent(sizeof(struct xilinx_efuse), &dma_addr);
- if (!efuse)
return -ENOMEM;
- data = dma_alloc_coherent(bytes, &dma_buf);
- if (!data) {
ret = -ENOMEM;
goto efuse_data_fail;
- }
- if (flag == EFUSE_WRITE) {
memcpy(data, val, bytes);
efuse->flag = EFUSE_WRITE;
- } else {
efuse->flag = EFUSE_READ;
- }
- efuse->src = dma_buf;
- efuse->size = words;
- efuse->offset = offset;
- efuse->pufuserfuse = pufflag;
- flush_dcache_range((ulong)efuse, (ulong)efuse +
roundup(sizeof(struct xilinx_efuse), ARCH_DMA_MINALIGN));
- flush_dcache_range((ulong)data, (ulong)data +
roundup(sizeof(struct xilinx_efuse), ARCH_DMA_MINALIGN));
- zynqmp_pm_efuse_access(dma_addr, (u32 *)&ret);
- if (ret != 0) {
if (ret == EFUSE_NOT_ENABLED) {
dev_err(dev, "efuse access is not enabled\n");
ret = -EOPNOTSUPP;
} else {
dev_err(dev, "Error in efuse read %x\n", ret);
ret = -EPERM;
}
goto efuse_access_err;
- }
- if (flag == EFUSE_READ)
memcpy(val, data, bytes);
+efuse_access_err:
- dma_free_coherent(data);
+efuse_data_fail:
- dma_free_coherent(efuse);
- return ret;
+}
+static int zynqmp_nvmem_read(void *context, unsigned int offset, void *val,
size_t bytes)
+{
- struct udevice *dev = context;
- int ret;
- int pufflag = 0;
- int idcode;
- int version;
- if (offset >= EFUSE_PUF_START_OFFSET && offset <= EFUSE_PUF_END_OFFSET)
pufflag = 1;
- switch (offset) {
- /* Soc version offset is zero */
- case SOC_VERSION_OFFSET:
if (bytes != SOC_VER_SIZE)
return -EOPNOTSUPP;
ret = zynqmp_pm_get_chipid((u32 *)&idcode, (u32 *)&version);
if (ret < 0)
return ret;
dev_dbg(dev, "Read chipid val %x %x\n", idcode, version);
*(int *)val = version & SILICON_REVISION_MASK;
break;
- /* Efuse offset starts from 0xc */
- case EFUSE_START_OFFSET ... EFUSE_END_OFFSET:
- case EFUSE_PUF_START_OFFSET ... EFUSE_PUF_END_OFFSET:
ret = zynqmp_efuse_access(context, offset, val,
bytes, EFUSE_READ, pufflag);
break;
- default:
*(u32 *)val = 0xDEADBEEF;
ret = 0;
break;
- }
- return ret;
+}
+static int zynqmp_nvmem_write(void *context,
unsigned int offset, void *val, size_t bytes)
+{
- int pufflag = 0;
- if (offset < EFUSE_START_OFFSET || offset > EFUSE_PUF_END_OFFSET)
return -EOPNOTSUPP;
- if (offset >= EFUSE_PUF_START_OFFSET && offset <= EFUSE_PUF_END_OFFSET)
pufflag = 1;
- return zynqmp_efuse_access(context, offset,
val, bytes, EFUSE_WRITE, pufflag);
+}
+int fuse_read(u32 bank, u32 word, u32 *val) +{
- u32 base_offset, offset, len;
- struct udevice *dev;
- u8 buf[128]; /* maximal size of efuse is 0x7f (pufuse) */
- int ret;
- ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(zynqmp_efuse), &dev);
- if (ret)
return log_msg_ret("uclass_drv", ret);
- ret = zynqmp_efuse_get_length(word, &base_offset, &len);
- if (ret) {
dev_err(dev, "Invalid eFuse word offset\n");
return ret;
- }
- if (len > sizeof(buf))
return -EINVAL;
- memset(buf, 0, sizeof(buf));
- ret = misc_read(dev, base_offset, (void *)buf, len);
- if (ret) {
dev_err(dev, "Cannot read eFuse @%u: %d", word, ret);
return ret;
- }
- offset = word - base_offset;
- *val = ((u32 *)buf)[offset];
- return 0;
+}
+int fuse_prog(u32 bank, u32 word, u32 val) +{
- u32 base_offset, len;
- struct udevice *dev;
- int ret;
- ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_DRIVER_GET(zynqmp_efuse), &dev);
- if (ret)
return log_msg_ret("uclass_drv", ret);
- ret = zynqmp_efuse_get_length(word, &base_offset, &len);
- if (ret) {
dev_err(dev, "Invalid eFuse word offset\n");
return ret;
- }
- if (word != base_offset || len != sizeof(val))
return -EINVAL;
- ret = misc_write(dev, word, (void *)&val, sizeof(val));
- if (ret) {
dev_err(dev, "Cannot write eFuse @%u: %d", word, ret);
return ret;
- }
- return 0;
+}
+int fuse_sense(u32 bank, u32 word, u32 *val) +{
- /* sense is not supported */
- return -ENOSYS;
+}
+int fuse_override(u32 bank, u32 word, u32 val) +{
- /* overriding is not supported */
- return -ENOSYS;
+}
+static int zynqmp_nvmem_read_compat(struct udevice *dev, int offset,
void *val, int bytes)
+{
- return zynqmp_nvmem_read((void *)dev, offset, val, bytes);
+}
+static int zynqmp_nvmem_write_compat(struct udevice *dev, int offset,
const void *val, int bytes)
+{
- return zynqmp_nvmem_write((void *)dev, offset, (void *)val, bytes);
+}
+static const struct udevice_id zynqmp_efuse_match[] = {
- { .compatible = "xlnx,zynqmp-nvmem-fw", },
- { /* sentinel */ },
+};
+static const struct misc_ops zynqmp_efuse_ops = {
- .read = zynqmp_nvmem_read_compat,
- .write = zynqmp_nvmem_write_compat,
+};
+U_BOOT_DRIVER(zynqmp_efuse) = {
- .name = "zynqmp_efuse",
- .id = UCLASS_MISC,
- .of_match = zynqmp_efuse_match,
- .ops = &zynqmp_efuse_ops,
+};
The rest looks good. When that small things are fixed I will merge it.
Thanks, Michal
participants (2)
-
lukas.funke-oss@weidmueller.com
-
Michal Simek