Commit 8a5d6899 authored by Andrew Davis's avatar Andrew Davis Committed by Mathieu Poirier

remoteproc: k3-dsp: Use devm_ioremap_wc() helper

Use a device lifecycle managed ioremap helper function. This helps prevent
mistakes like unmapping out of order in cleanup functions and forgetting
to unmap on all error paths.
Signed-off-by: default avatarAndrew Davis <afd@ti.com>
Link: https://lore.kernel.org/r/20240205182753.36978-5-afd@ti.comSigned-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
parent 57ec3c12
...@@ -598,16 +598,13 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc) ...@@ -598,16 +598,13 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc)
/* use remaining reserved memory regions for static carveouts */ /* use remaining reserved memory regions for static carveouts */
for (i = 0; i < num_rmems; i++) { for (i = 0; i < num_rmems; i++) {
rmem_np = of_parse_phandle(np, "memory-region", i + 1); rmem_np = of_parse_phandle(np, "memory-region", i + 1);
if (!rmem_np) { if (!rmem_np)
ret = -EINVAL; return -EINVAL;
goto unmap_rmem;
}
rmem = of_reserved_mem_lookup(rmem_np); rmem = of_reserved_mem_lookup(rmem_np);
if (!rmem) { if (!rmem) {
of_node_put(rmem_np); of_node_put(rmem_np);
ret = -EINVAL; return -EINVAL;
goto unmap_rmem;
} }
of_node_put(rmem_np); of_node_put(rmem_np);
...@@ -615,12 +612,11 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc) ...@@ -615,12 +612,11 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc)
/* 64-bit address regions currently not supported */ /* 64-bit address regions currently not supported */
kproc->rmem[i].dev_addr = (u32)rmem->base; kproc->rmem[i].dev_addr = (u32)rmem->base;
kproc->rmem[i].size = rmem->size; kproc->rmem[i].size = rmem->size;
kproc->rmem[i].cpu_addr = ioremap_wc(rmem->base, rmem->size); kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
if (!kproc->rmem[i].cpu_addr) { if (!kproc->rmem[i].cpu_addr) {
dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n", dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
i + 1, &rmem->base, &rmem->size); i + 1, &rmem->base, &rmem->size);
ret = -ENOMEM; return -ENOMEM;
goto unmap_rmem;
} }
dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n", dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
...@@ -631,19 +627,6 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc) ...@@ -631,19 +627,6 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc)
kproc->num_rmems = num_rmems; kproc->num_rmems = num_rmems;
return 0; return 0;
unmap_rmem:
for (i--; i >= 0; i--)
iounmap(kproc->rmem[i].cpu_addr);
return ret;
}
static void k3_dsp_reserved_mem_exit(struct k3_dsp_rproc *kproc)
{
int i;
for (i = 0; i < kproc->num_rmems; i++)
iounmap(kproc->rmem[i].cpu_addr);
} }
static void k3_dsp_release_tsp(void *data) static void k3_dsp_release_tsp(void *data)
...@@ -752,10 +735,8 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) ...@@ -752,10 +735,8 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id, ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id,
NULL, &p_state); NULL, &p_state);
if (ret) { if (ret)
dev_err_probe(dev, ret, "failed to get initial state, mode cannot be determined\n"); return dev_err_probe(dev, ret, "failed to get initial state, mode cannot be determined\n");
goto release_mem;
}
/* configure J721E devices for either remoteproc or IPC-only mode */ /* configure J721E devices for either remoteproc or IPC-only mode */
if (p_state) { if (p_state) {
...@@ -779,8 +760,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) ...@@ -779,8 +760,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
if (data->uses_lreset) { if (data->uses_lreset) {
ret = reset_control_status(kproc->reset); ret = reset_control_status(kproc->reset);
if (ret < 0) { if (ret < 0) {
dev_err_probe(dev, ret, "failed to get reset status\n"); return dev_err_probe(dev, ret, "failed to get reset status\n");
goto release_mem;
} else if (ret == 0) { } else if (ret == 0) {
dev_warn(dev, "local reset is deasserted for device\n"); dev_warn(dev, "local reset is deasserted for device\n");
k3_dsp_rproc_reset(kproc); k3_dsp_rproc_reset(kproc);
...@@ -789,18 +769,12 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) ...@@ -789,18 +769,12 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
} }
ret = rproc_add(rproc); ret = rproc_add(rproc);
if (ret) { if (ret)
dev_err_probe(dev, ret, "failed to add register device with remoteproc core\n"); return dev_err_probe(dev, ret, "failed to add register device with remoteproc core\n");
goto release_mem;
}
platform_set_drvdata(pdev, kproc); platform_set_drvdata(pdev, kproc);
return 0; return 0;
release_mem:
k3_dsp_reserved_mem_exit(kproc);
return ret;
} }
static void k3_dsp_rproc_remove(struct platform_device *pdev) static void k3_dsp_rproc_remove(struct platform_device *pdev)
...@@ -820,8 +794,6 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev) ...@@ -820,8 +794,6 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)
} }
rproc_del(kproc->rproc); rproc_del(kproc->rproc);
k3_dsp_reserved_mem_exit(kproc);
} }
static const struct k3_dsp_mem_data c66_mems[] = { static const struct k3_dsp_mem_data c66_mems[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment