Skip to content

Commit 77fcdf5

Browse files
tnmyshmathieupoirier
authored andcommitted
remoteproc: xlnx: Add sram support
AMD-Xilinx zynqmp platform contains on-chip sram memory (OCM). R5 cores can access OCM and access is faster than DDR memory but slower than TCM memories available. Sram region can have optional multiple power-domains. Platform management firmware is responsible to operate these power-domains. Signed-off-by: Tanmay Shah <[email protected]> Link: https://lore.kernel.org/r/[email protected] [Fixed dma_addr_t type cast when calling rproc_mem_entry_init()] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 9ab27eb commit 77fcdf5

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

drivers/remoteproc/xlnx_r5_remoteproc.c

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ struct mem_bank_data {
5656
char *bank_name;
5757
};
5858

59+
/**
60+
* struct zynqmp_sram_bank - sram bank description
61+
*
62+
* @sram_res: sram address region information
63+
* @da: device address of sram
64+
*/
65+
struct zynqmp_sram_bank {
66+
struct resource sram_res;
67+
u32 da;
68+
};
69+
5970
/**
6071
* struct mbox_info
6172
*
@@ -120,6 +131,8 @@ static const struct mem_bank_data zynqmp_tcm_banks_lockstep[] = {
120131
* struct zynqmp_r5_core
121132
*
122133
* @rsc_tbl_va: resource table virtual address
134+
* @sram: Array of sram memories assigned to this core
135+
* @num_sram: number of sram for this core
123136
* @dev: device of RPU instance
124137
* @np: device node of RPU instance
125138
* @tcm_bank_count: number TCM banks accessible to this RPU
@@ -131,6 +144,8 @@ static const struct mem_bank_data zynqmp_tcm_banks_lockstep[] = {
131144
*/
132145
struct zynqmp_r5_core {
133146
void __iomem *rsc_tbl_va;
147+
struct zynqmp_sram_bank *sram;
148+
int num_sram;
134149
struct device *dev;
135150
struct device_node *np;
136151
int tcm_bank_count;
@@ -494,6 +509,45 @@ static int add_mem_regions_carveout(struct rproc *rproc)
494509
return 0;
495510
}
496511

512+
static int add_sram_carveouts(struct rproc *rproc)
513+
{
514+
struct zynqmp_r5_core *r5_core = rproc->priv;
515+
struct rproc_mem_entry *rproc_mem;
516+
struct zynqmp_sram_bank *sram;
517+
dma_addr_t dma_addr;
518+
size_t len;
519+
int da, i;
520+
521+
for (i = 0; i < r5_core->num_sram; i++) {
522+
sram = &r5_core->sram[i];
523+
524+
dma_addr = (dma_addr_t)sram->sram_res.start;
525+
526+
len = resource_size(&sram->sram_res);
527+
da = sram->da;
528+
529+
rproc_mem = rproc_mem_entry_init(&rproc->dev, NULL,
530+
dma_addr,
531+
len, da,
532+
zynqmp_r5_mem_region_map,
533+
zynqmp_r5_mem_region_unmap,
534+
sram->sram_res.name);
535+
if (!rproc_mem) {
536+
dev_err(&rproc->dev, "failed to add sram %s da=0x%x, size=0x%lx",
537+
sram->sram_res.name, da, len);
538+
return -ENOMEM;
539+
}
540+
541+
rproc_add_carveout(rproc, rproc_mem);
542+
rproc_coredump_add_segment(rproc, da, len);
543+
544+
dev_dbg(&rproc->dev, "sram carveout %s addr=%llx, da=0x%x, size=0x%lx",
545+
sram->sram_res.name, dma_addr, da, len);
546+
}
547+
548+
return 0;
549+
}
550+
497551
/*
498552
* tcm_mem_unmap()
499553
* @rproc: single R5 core's corresponding rproc instance
@@ -669,6 +723,12 @@ static int zynqmp_r5_rproc_prepare(struct rproc *rproc)
669723
return ret;
670724
}
671725

726+
ret = add_sram_carveouts(rproc);
727+
if (ret) {
728+
dev_err(&rproc->dev, "failed to get sram carveout %d\n", ret);
729+
return ret;
730+
}
731+
672732
return 0;
673733
}
674734

@@ -881,6 +941,77 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)
881941
return ERR_PTR(ret);
882942
}
883943

944+
static int zynqmp_r5_get_sram_banks(struct zynqmp_r5_core *r5_core)
945+
{
946+
struct device_node *np = r5_core->np;
947+
struct device *dev = r5_core->dev;
948+
struct zynqmp_sram_bank *sram;
949+
struct device_node *sram_np;
950+
int num_sram, i, ret;
951+
u64 abs_addr, size;
952+
953+
/* "sram" is optional property. Do not fail, if unavailable. */
954+
if (!of_property_present(r5_core->np, "sram"))
955+
return 0;
956+
957+
num_sram = of_property_count_elems_of_size(np, "sram", sizeof(phandle));
958+
if (num_sram <= 0) {
959+
dev_err(dev, "Invalid sram property, ret = %d\n",
960+
num_sram);
961+
return -EINVAL;
962+
}
963+
964+
sram = devm_kcalloc(dev, num_sram,
965+
sizeof(struct zynqmp_sram_bank), GFP_KERNEL);
966+
if (!sram)
967+
return -ENOMEM;
968+
969+
for (i = 0; i < num_sram; i++) {
970+
sram_np = of_parse_phandle(np, "sram", i);
971+
if (!sram_np) {
972+
dev_err(dev, "failed to get sram %d phandle\n", i);
973+
return -EINVAL;
974+
}
975+
976+
if (!of_device_is_available(sram_np)) {
977+
dev_err(dev, "sram device not available\n");
978+
ret = -EINVAL;
979+
goto fail_sram_get;
980+
}
981+
982+
ret = of_address_to_resource(sram_np, 0, &sram[i].sram_res);
983+
if (ret) {
984+
dev_err(dev, "addr to res failed\n");
985+
goto fail_sram_get;
986+
}
987+
988+
/* Get SRAM device address */
989+
ret = of_property_read_reg(sram_np, i, &abs_addr, &size);
990+
if (ret) {
991+
dev_err(dev, "failed to get reg property\n");
992+
goto fail_sram_get;
993+
}
994+
995+
sram[i].da = (u32)abs_addr;
996+
997+
of_node_put(sram_np);
998+
999+
dev_dbg(dev, "sram %d: name=%s, addr=0x%llx, da=0x%x, size=0x%llx\n",
1000+
i, sram[i].sram_res.name, sram[i].sram_res.start,
1001+
sram[i].da, resource_size(&sram[i].sram_res));
1002+
}
1003+
1004+
r5_core->sram = sram;
1005+
r5_core->num_sram = num_sram;
1006+
1007+
return 0;
1008+
1009+
fail_sram_get:
1010+
of_node_put(sram_np);
1011+
1012+
return ret;
1013+
}
1014+
8841015
static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
8851016
{
8861017
int i, j, tcm_bank_count, ret, tcm_pd_idx, pd_count;
@@ -1095,6 +1226,10 @@ static int zynqmp_r5_core_init(struct zynqmp_r5_cluster *cluster,
10951226
return ret;
10961227
}
10971228
}
1229+
1230+
ret = zynqmp_r5_get_sram_banks(r5_core);
1231+
if (ret)
1232+
return ret;
10981233
}
10991234

11001235
return 0;

0 commit comments

Comments
 (0)