Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,26 @@
# SPDX-License-Identifier: GPL-2.0
# Kconfig for Xilinx firmwares
menu "Zynq MPSoC Firmware Drivers"
depends on ARCH_ZYNQMP
config ZYNQMP_FIRMWARE
bool "Enable Xilinx Zynq MPSoC firmware interface"
depends on ARCH_ZYNQMP
default y if ARCH_ZYNQMP
select MFD_CORE
help
Firmware interface driver is used by different
drivers to communicate with the firmware for
various platform management services.
Say yes to enable ZynqMP firmware interface driver.
If in doubt, say N.
config ZYNQMP_FIRMWARE_DEBUG
bool "Enable Xilinx Zynq MPSoC firmware debug APIs"
depends on ZYNQMP_FIRMWARE && DEBUG_FS
help
Say yes to enable ZynqMP firmware interface debug APIs.
If in doubt, say N.
endmenu
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for Xilinx firmwares
obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp.o zynqmp-ufs.o zynqmp-crypto.o
obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
@@ -0,0 +1,238 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Firmware layer for XilSecure APIs.
*
* Copyright (C) 2014-2022 Xilinx, Inc.
* Copyright (C) 2022-2025 Advanced Micro Devices, Inc.
*/
#include <linux/firmware/xlnx-zynqmp.h>
#include <linux/module.h>
/**
* zynqmp_pm_aes_engine - Access AES hardware to encrypt/decrypt the data using
* AES-GCM core.
* @address: Address of the AesParams structure.
* @out: Returned output value
*
* Return: Returns status, either success or error code.
*/
int zynqmp_pm_aes_engine(const u64 address, u32 *out)
{
u32 ret_payload[PAYLOAD_ARG_CNT];
int ret;
if (!out)
return -EINVAL;
ret = zynqmp_pm_invoke_fn(PM_SECURE_AES, ret_payload, 2, upper_32_bits(address),
lower_32_bits(address));
*out = ret_payload[1];
return ret;
}
EXPORT_SYMBOL_GPL(zynqmp_pm_aes_engine);
/**
* zynqmp_pm_sha_hash - Access the SHA engine to calculate the hash
* @address: Address of the data/ Address of output buffer where
* hash should be stored.
* @size: Size of the data.
* @flags:
* BIT(0) - for initializing csudma driver and SHA3(Here address
* and size inputs can be NULL).
* BIT(1) - to call Sha3_Update API which can be called multiple
* times when data is not contiguous.
* BIT(2) - to get final hash of the whole updated data.
* Hash will be overwritten at provided address with
* 48 bytes.
*
* Return: Returns status, either success or error code.
*/
int zynqmp_pm_sha_hash(const u64 address, const u32 size, const u32 flags)
{
u32 lower_addr = lower_32_bits(address);
u32 upper_addr = upper_32_bits(address);
return zynqmp_pm_invoke_fn(PM_SECURE_SHA, NULL, 4, upper_addr, lower_addr, size, flags);
}
EXPORT_SYMBOL_GPL(zynqmp_pm_sha_hash);
/**
* xlnx_get_crypto_dev_data() - Get crypto dev data of platform
* @feature_map: List of available feature map of all platform
*
* Return: Returns crypto dev data, either address crypto dev or ERR PTR
*/
void *xlnx_get_crypto_dev_data(struct xlnx_feature *feature_map)
{
struct xlnx_feature *feature;
u32 pm_family_code;
int ret;
/* Get the Family code and sub family code of platform */
ret = zynqmp_pm_get_family_info(&pm_family_code);
if (ret < 0)
return ERR_PTR(ret);
feature = feature_map;
for (; feature->family; feature++) {
if (feature->family == pm_family_code) {
ret = zynqmp_pm_feature(feature->feature_id);
if (ret < 0)
return ERR_PTR(ret);
return feature->data;
}
}
return ERR_PTR(-ENODEV);
}
EXPORT_SYMBOL_GPL(xlnx_get_crypto_dev_data);
/**
* versal_pm_aes_key_write - Write AES key registers
* @keylen: Size of the input key to be written
* @keysrc: Key Source to be selected to which provided
* key should be updated
* @keyaddr: Address of a buffer which should contain the key
* to be written
*
* This function provides support to write AES volatile user keys.
*
* Return: Returns status, either success or error+reason
*/
int versal_pm_aes_key_write(const u32 keylen,
const u32 keysrc, const u64 keyaddr)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_WRITE_KEY, NULL, 4,
keylen, keysrc,
lower_32_bits(keyaddr),
upper_32_bits(keyaddr));
}
EXPORT_SYMBOL_GPL(versal_pm_aes_key_write);
/**
* versal_pm_aes_key_zero - Zeroise AES User key registers
* @keysrc: Key Source to be selected to which provided
* key should be updated
*
* This function provides support to zeroise AES volatile user keys.
*
* Return: Returns status, either success or error+reason
*/
int versal_pm_aes_key_zero(const u32 keysrc)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_KEY_ZERO, NULL, 1, keysrc);
}
EXPORT_SYMBOL_GPL(versal_pm_aes_key_zero);
/**
* versal_pm_aes_op_init - Init AES operation
* @hw_req: AES op init structure address
*
* This function provides support to init AES operation.
*
* Return: Returns status, either success or error+reason
*/
int versal_pm_aes_op_init(const u64 hw_req)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_OP_INIT, NULL, 2,
lower_32_bits(hw_req),
upper_32_bits(hw_req));
}
EXPORT_SYMBOL_GPL(versal_pm_aes_op_init);
/**
* versal_pm_aes_update_aad - AES update aad
* @aad_addr: AES aad address
* @aad_len: AES aad data length
*
* This function provides support to update AAD data.
*
* Return: Returns status, either success or error+reason
*/
int versal_pm_aes_update_aad(const u64 aad_addr, const u32 aad_len)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_UPDATE_AAD, NULL, 3,
lower_32_bits(aad_addr),
upper_32_bits(aad_addr),
aad_len);
}
EXPORT_SYMBOL_GPL(versal_pm_aes_update_aad);
/**
* versal_pm_aes_enc_update - Access AES hardware to encrypt the data using
* AES-GCM core.
* @in_params: Address of the AesParams structure
* @in_addr: Address of input buffer
*
* Return: Returns status, either success or error code.
*/
int versal_pm_aes_enc_update(const u64 in_params, const u64 in_addr)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_ENCRYPT_UPDATE, NULL, 4,
lower_32_bits(in_params),
upper_32_bits(in_params),
lower_32_bits(in_addr),
upper_32_bits(in_addr));
}
EXPORT_SYMBOL_GPL(versal_pm_aes_enc_update);
/**
* versal_pm_aes_enc_final - Access AES hardware to store the GCM tag
* @gcm_addr: Address of the gcm tag
*
* Return: Returns status, either success or error code.
*/
int versal_pm_aes_enc_final(const u64 gcm_addr)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_ENCRYPT_FINAL, NULL, 2,
lower_32_bits(gcm_addr),
upper_32_bits(gcm_addr));
}
EXPORT_SYMBOL_GPL(versal_pm_aes_enc_final);
/**
* versal_pm_aes_dec_update - Access AES hardware to decrypt the data using
* AES-GCM core.
* @in_params: Address of the AesParams structure
* @in_addr: Address of input buffer
*
* Return: Returns status, either success or error code.
*/
int versal_pm_aes_dec_update(const u64 in_params, const u64 in_addr)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_DECRYPT_UPDATE, NULL, 4,
lower_32_bits(in_params),
upper_32_bits(in_params),
lower_32_bits(in_addr),
upper_32_bits(in_addr));
}
EXPORT_SYMBOL_GPL(versal_pm_aes_dec_update);
/**
* versal_pm_aes_dec_final - Access AES hardware to get the GCM tag
* @gcm_addr: Address of the gcm tag
*
* Return: Returns status, either success or error code.
*/
int versal_pm_aes_dec_final(const u64 gcm_addr)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_DECRYPT_FINAL, NULL, 2,
lower_32_bits(gcm_addr),
upper_32_bits(gcm_addr));
}
EXPORT_SYMBOL_GPL(versal_pm_aes_dec_final);
/**
* versal_pm_aes_init - Init AES block
*
* This function initialise AES block.
*
* Return: Returns status, either success or error+reason
*/
int versal_pm_aes_init(void)
{
return zynqmp_pm_invoke_fn(XSECURE_API_AES_INIT, NULL, 0);
}
EXPORT_SYMBOL_GPL(versal_pm_aes_init);
@@ -0,0 +1,412 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Xilinx Zynq MPSoC Firmware layer for debugfs APIs
*
* Copyright (C) 2014-2018 Xilinx, Inc.
* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc.
*
* Michal Simek <michal.simek@amd.com>
* Davorin Mista <davorin.mista@aggios.com>
* Jolly Shah <jollys@xilinx.com>
* Rajan Vaja <rajanv@xilinx.com>
*/
#include <linux/compiler.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/firmware/xlnx-zynqmp.h>
#include "zynqmp-debug.h"
#define PM_API_NAME_LEN 50
struct pm_api_info {
u32 api_id;
char api_name[PM_API_NAME_LEN];
char api_name_len;
};
static char debugfs_buf[PAGE_SIZE];
#define PM_API(id) {id, #id, strlen(#id)}
static struct pm_api_info pm_api_list[] = {
PM_API(PM_FORCE_POWERDOWN),
PM_API(PM_REQUEST_WAKEUP),
PM_API(PM_SYSTEM_SHUTDOWN),
PM_API(PM_REQUEST_NODE),
PM_API(PM_RELEASE_NODE),
PM_API(PM_SET_REQUIREMENT),
PM_API(PM_GET_API_VERSION),
PM_API(PM_GET_NODE_STATUS),
PM_API(PM_REGISTER_NOTIFIER),
PM_API(PM_RESET_ASSERT),
PM_API(PM_RESET_GET_STATUS),
PM_API(PM_GET_CHIPID),
PM_API(PM_PINCTRL_SET_FUNCTION),
PM_API(PM_PINCTRL_CONFIG_PARAM_GET),
PM_API(PM_PINCTRL_CONFIG_PARAM_SET),
PM_API(PM_IOCTL),
PM_API(PM_CLOCK_ENABLE),
PM_API(PM_CLOCK_DISABLE),
PM_API(PM_CLOCK_GETSTATE),
PM_API(PM_CLOCK_SETDIVIDER),
PM_API(PM_CLOCK_GETDIVIDER),
PM_API(PM_CLOCK_SETPARENT),
PM_API(PM_CLOCK_GETPARENT),
PM_API(PM_QUERY_DATA),
};
static struct dentry *firmware_debugfs_root;
/**
* zynqmp_pm_ioctl - PM IOCTL for device control and configs
* @node: Node ID of the device
* @ioctl: ID of the requested IOCTL
* @arg1: Argument 1 of requested IOCTL call
* @arg2: Argument 2 of requested IOCTL call
* @arg3: Argument 3 of requested IOCTL call
* @out: Returned output value
*
* Return: Returns status, either success or error+reason
*/
static int zynqmp_pm_ioctl(const u32 node, const u32 ioctl, const u32 arg1,
const u32 arg2, const u32 arg3, u32 *out)
{
return zynqmp_pm_invoke_fn(PM_IOCTL, out, 5, node, ioctl, arg1, arg2, arg3);
}
/**
* zynqmp_pm_argument_value() - Extract argument value from a PM-API request
* @arg: Entered PM-API argument in string format
*
* Return: Argument value in unsigned integer format on success
* 0 otherwise
*/
static u64 zynqmp_pm_argument_value(char *arg)
{
u64 value;
if (!arg)
return 0;
if (!kstrtou64(arg, 0, &value))
return value;
return 0;
}
/**
* get_pm_api_id() - Extract API-ID from a PM-API request
* @pm_api_req: Entered PM-API argument in string format
* @pm_id: API-ID
*
* Return: 0 on success else error code
*/
static int get_pm_api_id(char *pm_api_req, u32 *pm_id)
{
int i;
for (i = 0; i < ARRAY_SIZE(pm_api_list) ; i++) {
if (!strncasecmp(pm_api_req, pm_api_list[i].api_name,
pm_api_list[i].api_name_len)) {
*pm_id = pm_api_list[i].api_id;
break;
}
}
/* If no name was entered look for PM-API ID instead */
if (i == ARRAY_SIZE(pm_api_list) && kstrtouint(pm_api_req, 10, pm_id))
return -EINVAL;
return 0;
}
static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)
{
u32 pm_api_version;
int ret;
struct zynqmp_pm_query_data qdata = {0};
switch (pm_id) {
case PM_GET_API_VERSION:
ret = zynqmp_pm_get_api_version(&pm_api_version);
sprintf(debugfs_buf, "PM-API Version = %d.%d\n",
pm_api_version >> 16, pm_api_version & 0xffff);
break;
case PM_FORCE_POWERDOWN:
ret = zynqmp_pm_force_pwrdwn(pm_api_arg[0],
pm_api_arg[1] ? pm_api_arg[1] :
ZYNQMP_PM_REQUEST_ACK_NO);
break;
case PM_REQUEST_WAKEUP:
ret = zynqmp_pm_request_wake(pm_api_arg[0],
pm_api_arg[1], pm_api_arg[2],
pm_api_arg[3] ? pm_api_arg[3] :
ZYNQMP_PM_REQUEST_ACK_NO);
break;
case PM_SYSTEM_SHUTDOWN:
ret = zynqmp_pm_system_shutdown(pm_api_arg[0], pm_api_arg[1]);
break;
case PM_REQUEST_NODE:
ret = zynqmp_pm_request_node(pm_api_arg[0],
pm_api_arg[1] ? pm_api_arg[1] :
ZYNQMP_PM_CAPABILITY_ACCESS,
pm_api_arg[2] ? pm_api_arg[2] : 0,
pm_api_arg[3] ? pm_api_arg[3] :
ZYNQMP_PM_REQUEST_ACK_BLOCKING);
break;
case PM_RELEASE_NODE:
ret = zynqmp_pm_release_node(pm_api_arg[0]);
break;
case PM_SET_REQUIREMENT:
ret = zynqmp_pm_set_requirement(pm_api_arg[0],
pm_api_arg[1] ? pm_api_arg[1] :
ZYNQMP_PM_CAPABILITY_CONTEXT,
pm_api_arg[2] ?
pm_api_arg[2] : 0,
pm_api_arg[3] ? pm_api_arg[3] :
ZYNQMP_PM_REQUEST_ACK_BLOCKING);
break;
case PM_GET_NODE_STATUS:
ret = zynqmp_pm_get_node_status(pm_api_arg[0],
&pm_api_ret[0],
&pm_api_ret[1],
&pm_api_ret[2]);
if (!ret)
sprintf(debugfs_buf,
"GET_NODE_STATUS:\n\tNodeId: %llu\n\tStatus: %u\n\tRequirements: %u\n\tUsage: %u\n",
pm_api_arg[0], pm_api_ret[0],
pm_api_ret[1], pm_api_ret[2]);
break;
case PM_REGISTER_NOTIFIER:
ret = zynqmp_pm_register_notifier(pm_api_arg[0],
pm_api_arg[1] ?
pm_api_arg[1] : 0,
pm_api_arg[2] ?
pm_api_arg[2] : 0,
pm_api_arg[3] ?
pm_api_arg[3] : 0);
break;
case PM_RESET_ASSERT:
ret = zynqmp_pm_reset_assert(pm_api_arg[0], pm_api_arg[1]);
break;
case PM_RESET_GET_STATUS:
ret = zynqmp_pm_reset_get_status(pm_api_arg[0], &pm_api_ret[0]);
if (!ret)
sprintf(debugfs_buf, "Reset status: %u\n",
pm_api_ret[0]);
break;
case PM_GET_CHIPID:
ret = zynqmp_pm_get_chipid(&pm_api_ret[0], &pm_api_ret[1]);
if (!ret)
sprintf(debugfs_buf, "Idcode: %#x, Version:%#x\n",
pm_api_ret[0], pm_api_ret[1]);
break;
case PM_PINCTRL_SET_FUNCTION:
ret = zynqmp_pm_pinctrl_set_function(pm_api_arg[0],
pm_api_arg[1]);
break;
case PM_PINCTRL_CONFIG_PARAM_GET:
ret = zynqmp_pm_pinctrl_get_config(pm_api_arg[0], pm_api_arg[1],
&pm_api_ret[0]);
if (!ret)
sprintf(debugfs_buf,
"Pin: %llu, Param: %llu, Value: %u\n",
pm_api_arg[0], pm_api_arg[1],
pm_api_ret[0]);
break;
case PM_PINCTRL_CONFIG_PARAM_SET:
ret = zynqmp_pm_pinctrl_set_config(pm_api_arg[0],
pm_api_arg[1],
pm_api_arg[2]);
break;
case PM_IOCTL:
ret = zynqmp_pm_ioctl(pm_api_arg[0], pm_api_arg[1],
pm_api_arg[2], pm_api_arg[3],
pm_api_arg[4], &pm_api_ret[0]);
if (!ret && (pm_api_arg[1] == IOCTL_GET_RPU_OPER_MODE ||
pm_api_arg[1] == IOCTL_GET_PLL_FRAC_MODE ||
pm_api_arg[1] == IOCTL_GET_PLL_FRAC_DATA ||
pm_api_arg[1] == IOCTL_READ_GGS ||
pm_api_arg[1] == IOCTL_READ_PGGS ||
pm_api_arg[1] == IOCTL_READ_REG))
sprintf(debugfs_buf, "IOCTL return value: %u\n",
pm_api_ret[1]);
if (!ret && pm_api_arg[1] == IOCTL_GET_QOS)
sprintf(debugfs_buf, "Default QoS: %u\nCurrent QoS: %u\n",
pm_api_ret[1], pm_api_ret[2]);
break;
case PM_CLOCK_ENABLE:
ret = zynqmp_pm_clock_enable(pm_api_arg[0]);
break;
case PM_CLOCK_DISABLE:
ret = zynqmp_pm_clock_disable(pm_api_arg[0]);
break;
case PM_CLOCK_GETSTATE:
ret = zynqmp_pm_clock_getstate(pm_api_arg[0], &pm_api_ret[0]);
if (!ret)
sprintf(debugfs_buf, "Clock state: %u\n",
pm_api_ret[0]);
break;
case PM_CLOCK_SETDIVIDER:
ret = zynqmp_pm_clock_setdivider(pm_api_arg[0], pm_api_arg[1]);
break;
case PM_CLOCK_GETDIVIDER:
ret = zynqmp_pm_clock_getdivider(pm_api_arg[0], &pm_api_ret[0]);
if (!ret)
sprintf(debugfs_buf, "Divider Value: %d\n",
pm_api_ret[0]);
break;
case PM_CLOCK_SETPARENT:
ret = zynqmp_pm_clock_setparent(pm_api_arg[0], pm_api_arg[1]);
break;
case PM_CLOCK_GETPARENT:
ret = zynqmp_pm_clock_getparent(pm_api_arg[0], &pm_api_ret[0]);
if (!ret)
sprintf(debugfs_buf,
"Clock parent Index: %u\n", pm_api_ret[0]);
break;
case PM_QUERY_DATA:
qdata.qid = pm_api_arg[0];
qdata.arg1 = pm_api_arg[1];
qdata.arg2 = pm_api_arg[2];
qdata.arg3 = pm_api_arg[3];
ret = zynqmp_pm_query_data(qdata, pm_api_ret);
if (ret)
break;
switch (qdata.qid) {
case PM_QID_CLOCK_GET_NAME:
sprintf(debugfs_buf, "Clock name = %s\n",
(char *)pm_api_ret);
break;
case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
sprintf(debugfs_buf, "Multiplier = %d, Divider = %d\n",
pm_api_ret[1], pm_api_ret[2]);
break;
default:
sprintf(debugfs_buf,
"data[0] = 0x%08x\ndata[1] = 0x%08x\n data[2] = 0x%08x\ndata[3] = 0x%08x\n",
pm_api_ret[0], pm_api_ret[1],
pm_api_ret[2], pm_api_ret[3]);
}
break;
default:
sprintf(debugfs_buf, "Unsupported PM-API request\n");
ret = -EINVAL;
}
return ret;
}
/**
* zynqmp_pm_debugfs_api_write() - debugfs write function
* @file: User file
* @ptr: User entered PM-API string
* @len: Length of the userspace buffer
* @off: Offset within the file
*
* Used for triggering pm api functions by writing
* echo <pm_api_id> > /sys/kernel/debug/zynqmp_pm/power or
* echo <pm_api_name> > /sys/kernel/debug/zynqmp_pm/power
*
* Return: Number of bytes copied if PM-API request succeeds,
* the corresponding error code otherwise
*/
static ssize_t zynqmp_pm_debugfs_api_write(struct file *file,
const char __user *ptr, size_t len,
loff_t *off)
{
char *kern_buff, *tmp_buff;
char *pm_api_req;
u32 pm_id = 0;
u64 pm_api_arg[5] = {0, 0, 0, 0, 0};
/* Return values from PM APIs calls */
u32 pm_api_ret[4] = {0, 0, 0, 0};
int ret;
int i = 0;
strcpy(debugfs_buf, "");
if (*off != 0 || len <= 1 || len > PAGE_SIZE - 1)
return -EINVAL;
kern_buff = memdup_user_nul(ptr, len);
if (IS_ERR(kern_buff))
return PTR_ERR(kern_buff);
tmp_buff = kern_buff;
/* Read the API name from a user request */
pm_api_req = strsep(&kern_buff, " ");
ret = get_pm_api_id(pm_api_req, &pm_id);
if (ret < 0)
goto err;
/* Read node_id and arguments from the PM-API request */
pm_api_req = strsep(&kern_buff, " ");
while ((i < ARRAY_SIZE(pm_api_arg)) && pm_api_req) {
pm_api_arg[i++] = zynqmp_pm_argument_value(pm_api_req);
pm_api_req = strsep(&kern_buff, " ");
}
ret = process_api_request(pm_id, pm_api_arg, pm_api_ret);
err:
kfree(tmp_buff);
if (ret)
return ret;
return len;
}
/**
* zynqmp_pm_debugfs_api_read() - debugfs read function
* @file: User file
* @ptr: Requested pm_api_version string
* @len: Length of the userspace buffer
* @off: Offset within the file
*
* Return: Length of the version string on success
* else error code
*/
static ssize_t zynqmp_pm_debugfs_api_read(struct file *file, char __user *ptr,
size_t len, loff_t *off)
{
return simple_read_from_buffer(ptr, len, off, debugfs_buf,
strlen(debugfs_buf));
}
/* Setup debugfs fops */
static const struct file_operations fops_zynqmp_pm_dbgfs = {
.owner = THIS_MODULE,
.write = zynqmp_pm_debugfs_api_write,
.read = zynqmp_pm_debugfs_api_read,
};
/**
* zynqmp_pm_api_debugfs_init - Initialize debugfs interface
*
* Return: None
*/
void zynqmp_pm_api_debugfs_init(void)
{
/* Initialize debugfs interface */
firmware_debugfs_root = debugfs_create_dir("zynqmp-firmware", NULL);
debugfs_create_file("pm", 0660, firmware_debugfs_root, NULL,
&fops_zynqmp_pm_dbgfs);
}
/**
* zynqmp_pm_api_debugfs_exit - Remove debugfs interface
*
* Return: None
*/
void zynqmp_pm_api_debugfs_exit(void)
{
debugfs_remove_recursive(firmware_debugfs_root);
}
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Xilinx Zynq MPSoC Firmware layer
*
* Copyright (C) 2014-2018 Xilinx
*
* Michal Simek <michal.simek@amd.com>
* Davorin Mista <davorin.mista@aggios.com>
* Jolly Shah <jollys@xilinx.com>
* Rajan Vaja <rajanv@xilinx.com>
*/
#ifndef __FIRMWARE_ZYNQMP_DEBUG_H__
#define __FIRMWARE_ZYNQMP_DEBUG_H__
#if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE_DEBUG)
void zynqmp_pm_api_debugfs_init(void);
void zynqmp_pm_api_debugfs_exit(void);
#else
static inline void zynqmp_pm_api_debugfs_init(void) { }
static inline void zynqmp_pm_api_debugfs_exit(void) { }
#endif
#endif /* __FIRMWARE_ZYNQMP_DEBUG_H__ */
@@ -0,0 +1,118 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Firmware Layer for UFS APIs
*
* Copyright (C) 2025 Advanced Micro Devices, Inc.
*/
#include <linux/firmware/xlnx-zynqmp.h>
#include <linux/module.h>
/* Register Node IDs */
#define PM_REGNODE_PMC_IOU_SLCR 0x30000002 /* PMC IOU SLCR */
#define PM_REGNODE_EFUSE_CACHE 0x30000003 /* EFUSE Cache */
/* Register Offsets for PMC IOU SLCR */
#define SRAM_CSR_OFFSET 0x104C /* SRAM Control and Status */
#define TXRX_CFGRDY_OFFSET 0x1054 /* M-PHY TX-RX Config ready */
/* Masks for SRAM Control and Status Register */
#define SRAM_CSR_INIT_DONE_MASK BIT(0) /* SRAM initialization done */
#define SRAM_CSR_EXT_LD_DONE_MASK BIT(1) /* SRAM External load done */
#define SRAM_CSR_BYPASS_MASK BIT(2) /* Bypass SRAM interface */
/* Mask to check M-PHY TX-RX configuration readiness */
#define TX_RX_CFG_RDY_MASK GENMASK(3, 0)
/* Register Offsets for EFUSE Cache */
#define UFS_CAL_1_OFFSET 0xBE8 /* UFS Calibration Value */
/**
* zynqmp_pm_is_mphy_tx_rx_config_ready - check M-PHY TX-RX config readiness
* @is_ready: Store output status (true/false)
*
* Return: Returns 0 on success or error value on failure.
*/
int zynqmp_pm_is_mphy_tx_rx_config_ready(bool *is_ready)
{
u32 regval;
int ret;
if (!is_ready)
return -EINVAL;
ret = zynqmp_pm_sec_read_reg(PM_REGNODE_PMC_IOU_SLCR, TXRX_CFGRDY_OFFSET, &regval);
if (ret)
return ret;
regval &= TX_RX_CFG_RDY_MASK;
if (regval)
*is_ready = true;
else
*is_ready = false;
return ret;
}
EXPORT_SYMBOL_GPL(zynqmp_pm_is_mphy_tx_rx_config_ready);
/**
* zynqmp_pm_is_sram_init_done - check SRAM initialization
* @is_done: Store output status (true/false)
*
* Return: Returns 0 on success or error value on failure.
*/
int zynqmp_pm_is_sram_init_done(bool *is_done)
{
u32 regval;
int ret;
if (!is_done)
return -EINVAL;
ret = zynqmp_pm_sec_read_reg(PM_REGNODE_PMC_IOU_SLCR, SRAM_CSR_OFFSET, &regval);
if (ret)
return ret;
regval &= SRAM_CSR_INIT_DONE_MASK;
if (regval)
*is_done = true;
else
*is_done = false;
return ret;
}
EXPORT_SYMBOL_GPL(zynqmp_pm_is_sram_init_done);
/**
* zynqmp_pm_set_sram_bypass - Set SRAM bypass Control
*
* Return: Returns 0 on success or error value on failure.
*/
int zynqmp_pm_set_sram_bypass(void)
{
u32 sram_csr;
int ret;
ret = zynqmp_pm_sec_read_reg(PM_REGNODE_PMC_IOU_SLCR, SRAM_CSR_OFFSET, &sram_csr);
if (ret)
return ret;
sram_csr &= ~SRAM_CSR_EXT_LD_DONE_MASK;
sram_csr |= SRAM_CSR_BYPASS_MASK;
return zynqmp_pm_sec_mask_write_reg(PM_REGNODE_PMC_IOU_SLCR, SRAM_CSR_OFFSET,
GENMASK(2, 1), sram_csr);
}
EXPORT_SYMBOL_GPL(zynqmp_pm_set_sram_bypass);
/**
* zynqmp_pm_get_ufs_calibration_values - Read UFS calibration values
* @val: Store the calibration value
*
* Return: Returns 0 on success or error value on failure.
*/
int zynqmp_pm_get_ufs_calibration_values(u32 *val)
{
return zynqmp_pm_sec_read_reg(PM_REGNODE_EFUSE_CACHE, UFS_CAL_1_OFFSET, val);
}
EXPORT_SYMBOL_GPL(zynqmp_pm_get_ufs_calibration_values);
File diff suppressed because it is too large Load Diff