Skip to content

Instantly share code, notes, and snippets.

@neuberfran
Created January 27, 2024 17:36
Show Gist options
  • Save neuberfran/d0f0d8355f8c424420842381eb0db218 to your computer and use it in GitHub Desktop.
Save neuberfran/d0f0d8355f8c424420842381eb0db218 to your computer and use it in GitHub Desktop.
static int imx_rproc_addr_init(struct imx_rproc *priv,
struct platform_device *pdev)
{
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
int a, b = 0, err, nph;
/* remap required addresses */
for (a = 0; a < dcfg->att_size; a++) {
const struct imx_rproc_att *att = &dcfg->att[a];
if (!(att->flags & ATT_OWN))
continue;
if (att->flags & ATT_CORE_MASK) {
if (!((1 << priv->id) & (att->flags & ATT_CORE_MASK)))
continue;
}
if (b >= IMX7D_RPROC_MEM_MAX)
break;
priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev,
att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
dev_err(dev, "devm_ioremap failed\n");
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
priv->mem[b].size = att->size;
b++;
}
/* memory-region is optional property */
nph = of_count_phandle_with_args(np, "memory-region", NULL);
if (nph <= 0)
return 0;
/* remap optional addresses */
for (a = 0; a < nph; a++) {
struct device_node *node;
struct resource res;
node = of_parse_phandle(np, "memory-region", a);
err = of_address_to_resource(node, 0, &res);
if (err) {
dev_err(dev, "unable to resolve memory region\n");
return err;
}
if (b >= IMX7D_RPROC_MEM_MAX)
break;
/* Not use resource version, because we might share region*/
priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev, res.start, resource_size(&res));
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "devm_ioremap %pR failed\n", &res);
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
priv->mem[b].sys_addr = res.start;
priv->mem[b].size = resource_size(&res);
b++;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment