diff options
author | Asmaa Mnebhi <asmaa@nvidia.com> | 2023-08-09 19:28:56 +0300 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2023-08-10 12:12:46 +0300 |
commit | b18a97ed9006cac03105dde68e000b8e7468848a (patch) | |
tree | b52409971b388c9c03b0c22ec47d06b2f64bb4ae /drivers/platform | |
parent | 7295a996fdab7bf83dc3d4078fa8b139b8e0a1bf (diff) | |
download | linux-b18a97ed9006cac03105dde68e000b8e7468848a.tar.xz |
mlxbf-bootctl: Support the large icmc write/read
Enable reading and writing the size of the memory region associated
with the large ICM carveout.
The max size of the large ICM carveout is 1TB, has a granularity
of 128MB and will be passed and printed in hex. The size unit is MB.
Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>
Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
Link: https://lore.kernel.org/r/20230809162857.21243-2-asmaa@nvidia.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/mellanox/mlxbf-bootctl.c | 42 | ||||
-rw-r--r-- | drivers/platform/mellanox/mlxbf-bootctl.h | 14 |
2 files changed, 56 insertions, 0 deletions
diff --git a/drivers/platform/mellanox/mlxbf-bootctl.c b/drivers/platform/mellanox/mlxbf-bootctl.c index fb9f7815c6cd..52d1272478a4 100644 --- a/drivers/platform/mellanox/mlxbf-bootctl.c +++ b/drivers/platform/mellanox/mlxbf-bootctl.c @@ -79,6 +79,8 @@ static void __iomem *mlxbf_rsh_scratch_buf_data; static const char * const mlxbf_rsh_log_level[] = { "INFO", "WARN", "ERR", "ASSERT"}; +static DEFINE_MUTEX(icm_ops_lock); + /* ARM SMC call which is atomic and no need for lock. */ static int mlxbf_bootctl_smc(unsigned int smc_op, int smc_arg) { @@ -391,6 +393,44 @@ done: return count; } +static ssize_t large_icm_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct arm_smccc_res res; + + mutex_lock(&icm_ops_lock); + arm_smccc_smc(MLNX_HANDLE_GET_ICM_INFO, 0, 0, 0, 0, + 0, 0, 0, &res); + mutex_unlock(&icm_ops_lock); + if (res.a0) + return -EPERM; + + return snprintf(buf, PAGE_SIZE, "0x%lx", res.a1); +} + +static ssize_t large_icm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct arm_smccc_res res; + unsigned long icm_data; + int err; + + err = kstrtoul(buf, MLXBF_LARGE_ICMC_MAX_STRING_SIZE, &icm_data); + if (err) + return err; + + if ((icm_data != 0 && icm_data < MLXBF_LARGE_ICMC_SIZE_MIN) || + icm_data > MLXBF_LARGE_ICMC_SIZE_MAX || icm_data % MLXBF_LARGE_ICMC_GRANULARITY) + return -EPERM; + + mutex_lock(&icm_ops_lock); + arm_smccc_smc(MLNX_HANDLE_SET_ICM_INFO, icm_data, 0, 0, 0, 0, 0, 0, &res); + mutex_unlock(&icm_ops_lock); + + return res.a0 ? -EPERM : count; +} + static DEVICE_ATTR_RW(post_reset_wdog); static DEVICE_ATTR_RW(reset_action); static DEVICE_ATTR_RW(second_reset_action); @@ -398,6 +438,7 @@ static DEVICE_ATTR_RO(lifecycle_state); static DEVICE_ATTR_RO(secure_boot_fuse_state); static DEVICE_ATTR_WO(fw_reset); static DEVICE_ATTR_WO(rsh_log); +static DEVICE_ATTR_RW(large_icm); static struct attribute *mlxbf_bootctl_attrs[] = { &dev_attr_post_reset_wdog.attr, @@ -407,6 +448,7 @@ static struct attribute *mlxbf_bootctl_attrs[] = { &dev_attr_secure_boot_fuse_state.attr, &dev_attr_fw_reset.attr, &dev_attr_rsh_log.attr, + &dev_attr_large_icm.attr, NULL }; diff --git a/drivers/platform/mellanox/mlxbf-bootctl.h b/drivers/platform/mellanox/mlxbf-bootctl.h index b48243f60a59..fc5019c90fc5 100644 --- a/drivers/platform/mellanox/mlxbf-bootctl.h +++ b/drivers/platform/mellanox/mlxbf-bootctl.h @@ -81,6 +81,15 @@ */ #define MLXBF_BOOTCTL_FW_RESET 0x8200000D +/* + * SMC function IDs to set and get the large ICM carveout size + * stored in the eeprom. + */ +#define MLNX_HANDLE_SET_ICM_INFO 0x82000012 +#define MLNX_HANDLE_GET_ICM_INFO 0x82000013 + +#define MAX_ICM_BUFFER_SIZE 10 + /* SMC function IDs for SiP Service queries */ #define MLXBF_BOOTCTL_SIP_SVC_CALL_COUNT 0x8200ff00 #define MLXBF_BOOTCTL_SIP_SVC_UID 0x8200ff01 @@ -106,4 +115,9 @@ /* Additional value to disable the MLXBF_BOOTCTL_SET_SECOND_RESET_ACTION. */ #define MLXBF_BOOTCTL_NONE 0x7fffffff /* Don't change next boot action */ +#define MLXBF_LARGE_ICMC_MAX_STRING_SIZE 16 +#define MLXBF_LARGE_ICMC_SIZE_MIN 0x80 +#define MLXBF_LARGE_ICMC_SIZE_MAX 0x100000 +#define MLXBF_LARGE_ICMC_GRANULARITY MLXBF_LARGE_ICMC_SIZE_MIN + #endif /* __MLXBF_BOOTCTL_H__ */ |