firmware: qcom: scm: Add minidump SRAM support

On most Qualcomm SoCs where minidump is supported, a word in always-on
SRAM is shared between the operating system (OS) and boot firmware.
Before DDR is initialized on the warm reset following a crash, firmware
reads this word to decide if minidump is enabled and collect a minidump,
and where to deliver it (USB upload to a host, or save to local
storage). The OS is expected to select one of the destinations.

The SRAM region is described by a 'sram' phandle on the SCM DT node.
If the property is absent the feature is silently disabled, keeping
existing SoCs unaffected.

Expose a 'minidump_dest' module parameter (default: usb) so the user
can select the destination. Only the string names "usb" or "storage"
are accepted.

Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20260624190830.3131112-6-mukesh.ojha@oss.qualcomm.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
This commit is contained in:
Mukesh Ojha
2026-07-13 09:43:24 -05:00
committed by Bjorn Andersson
parent d0a05db99b
commit 7bd52a0d45
+92
View File
@@ -59,6 +59,7 @@ struct qcom_scm {
int scm_vote_count;
u64 dload_mode_addr;
void __iomem *minidump_sram;
struct qcom_tzmem_pool *mempool;
unsigned int wq_cnt;
@@ -143,6 +144,20 @@ static const u8 qcom_scm_cpu_warm_bits[QCOM_SCM_BOOT_MAX_CPUS] = {
#define QCOM_DLOAD_MINIDUMP 2
#define QCOM_DLOAD_BOTHDUMP 3
/* Minidump destination values written to always-on SRAM for boot firmware */
#define QCOM_MINIDUMP_DEST_USB 0x0
#define QCOM_MINIDUMP_DEST_STORAGE 0x2
static u32 minidump_dest = QCOM_MINIDUMP_DEST_USB;
static const struct {
const char *name;
u32 val;
} minidump_dest_map[] = {
{ "usb", QCOM_MINIDUMP_DEST_USB },
{ "storage", QCOM_MINIDUMP_DEST_STORAGE },
};
#define QCOM_SCM_DEFAULT_WAITQ_COUNT 1
static const char * const qcom_scm_convention_names[] = {
@@ -551,6 +566,14 @@ static void qcom_scm_set_download_mode(struct qcom_scm *scm, u32 dload_mode)
if (ret)
dev_err(scm->dev, "failed to set download mode: %d\n", ret);
/*
* Write the destination into the always-on SRAM so boot firmware
* can read it before DDR is initialised on the next warm reset.
* Only written when minidump is active;
*/
if (scm->minidump_sram && (dload_mode & QCOM_DLOAD_MINIDUMP))
writel_relaxed(minidump_dest, scm->minidump_sram);
}
struct qcom_scm_pas_context *devm_qcom_scm_pas_context_alloc(struct device *dev,
@@ -2007,6 +2030,29 @@ int qcom_scm_gpu_init_regs(u32 gpu_req)
}
EXPORT_SYMBOL_GPL(qcom_scm_gpu_init_regs);
static int qcom_scm_map_minidump_sram(struct device *dev, void __iomem **out)
{
struct device_node *np = dev->of_node;
struct device_node *sram_np;
struct resource res;
int ret;
sram_np = of_parse_phandle(np, "sram", 0);
if (!sram_np)
return 0;
ret = of_address_to_resource(sram_np, 0, &res);
of_node_put(sram_np);
if (ret)
return ret;
*out = devm_ioremap(dev, res.start, resource_size(&res));
if (!*out)
return -ENOMEM;
return 0;
}
static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
{
struct device_node *tcsr;
@@ -2705,6 +2751,47 @@ static const struct kernel_param_ops download_mode_param_ops = {
module_param_cb(download_mode, &download_mode_param_ops, NULL, 0644);
MODULE_PARM_DESC(download_mode, "download mode: off/0/N for no dump mode, full/on/1/Y for full dump mode, mini for minidump mode and full,mini for both full and minidump mode together are acceptable values");
static int get_minidump_dest(char *buffer, const struct kernel_param *kp)
{
int i;
for (i = 0; i < ARRAY_SIZE(minidump_dest_map); i++)
if (minidump_dest == minidump_dest_map[i].val)
return sysfs_emit(buffer, "%s\n", minidump_dest_map[i].name);
return sysfs_emit(buffer, "unknown\n");
}
static int set_minidump_dest(const char *val, const struct kernel_param *kp)
{
struct qcom_scm *scm;
int i;
for (i = 0; i < ARRAY_SIZE(minidump_dest_map); i++)
if (sysfs_streq(val, minidump_dest_map[i].name))
break;
if (i >= ARRAY_SIZE(minidump_dest_map))
return -EINVAL;
minidump_dest = minidump_dest_map[i].val;
/* Pairs with smp_store_release() in qcom_scm_probe(). */
scm = smp_load_acquire(&__scm);
if (scm && scm->minidump_sram && (download_mode & QCOM_DLOAD_MINIDUMP))
writel_relaxed(minidump_dest, scm->minidump_sram);
return 0;
}
static const struct kernel_param_ops minidump_dest_param_ops = {
.get = get_minidump_dest,
.set = set_minidump_dest,
};
module_param_cb(minidump_dest, &minidump_dest_param_ops, NULL, 0644);
MODULE_PARM_DESC(minidump_dest, "Minidump SRAM destination: usb (default) or storage");
static int qcom_scm_probe(struct platform_device *pdev)
{
struct qcom_tzmem_pool_config pool_config;
@@ -2722,6 +2809,11 @@ static int qcom_scm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret,
"Failed to get download mode address\n");
ret = qcom_scm_map_minidump_sram(&pdev->dev, &scm->minidump_sram);
if (ret < 0)
return dev_err_probe(&pdev->dev, ret,
"Failed to map minidump SRAM\n");
mutex_init(&scm->scm_bw_lock);
scm->path = devm_of_icc_get(&pdev->dev, NULL);