mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-13 01:32:18 -04:00
remoteproc: k3-r5: Re-order internal memory initialization functions
The internal memory struct pointer, 'mem', will be refactored from k3_r5_core struct into k3_r5_rproc struct in a future commit. Therefore, move the internal memory initialization function, k3_r5_core_of_get_internal_memories() above k3_r5_cluster_rproc_init() so that the former can be invoked by the later. While at it, also re-order the k3_r5_core_of_get_sram_memories() to keep all the internal memory initialization functions at one place. Signed-off-by: Beleswar Padhi <b-padhi@ti.com> Tested-by: Judith Mendez <jm@ti.com> Reviewed-by: Andrew Davis <afd@ti.com> Link: https://lore.kernel.org/r/20250513054510.3439842-6-b-padhi@ti.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
This commit is contained in:
committed by
Mathieu Poirier
parent
2353252459
commit
b9229c0732
@@ -1227,6 +1227,135 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev,
|
||||
struct k3_r5_core *core)
|
||||
{
|
||||
static const char * const mem_names[] = {"atcm", "btcm"};
|
||||
struct device *dev = &pdev->dev;
|
||||
struct resource *res;
|
||||
int num_mems;
|
||||
int i;
|
||||
|
||||
num_mems = ARRAY_SIZE(mem_names);
|
||||
core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL);
|
||||
if (!core->mem)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < num_mems; i++) {
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
mem_names[i]);
|
||||
if (!res) {
|
||||
dev_err(dev, "found no memory resource for %s\n",
|
||||
mem_names[i]);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!devm_request_mem_region(dev, res->start,
|
||||
resource_size(res),
|
||||
dev_name(dev))) {
|
||||
dev_err(dev, "could not request %s region for resource\n",
|
||||
mem_names[i]);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/*
|
||||
* TCMs are designed in general to support RAM-like backing
|
||||
* memories. So, map these as Normal Non-Cached memories. This
|
||||
* also avoids/fixes any potential alignment faults due to
|
||||
* unaligned data accesses when using memcpy() or memset()
|
||||
* functions (normally seen with device type memory).
|
||||
*/
|
||||
core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
|
||||
resource_size(res));
|
||||
if (!core->mem[i].cpu_addr) {
|
||||
dev_err(dev, "failed to map %s memory\n", mem_names[i]);
|
||||
return -ENOMEM;
|
||||
}
|
||||
core->mem[i].bus_addr = res->start;
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* The R5F cores can place ATCM & BTCM anywhere in its address
|
||||
* based on the corresponding Region Registers in the System
|
||||
* Control coprocessor. For now, place ATCM and BTCM at
|
||||
* addresses 0 and 0x41010000 (same as the bus address on AM65x
|
||||
* SoCs) based on loczrama setting
|
||||
*/
|
||||
if (!strcmp(mem_names[i], "atcm")) {
|
||||
core->mem[i].dev_addr = core->loczrama ?
|
||||
0 : K3_R5_TCM_DEV_ADDR;
|
||||
} else {
|
||||
core->mem[i].dev_addr = core->loczrama ?
|
||||
K3_R5_TCM_DEV_ADDR : 0;
|
||||
}
|
||||
core->mem[i].size = resource_size(res);
|
||||
|
||||
dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
|
||||
mem_names[i], &core->mem[i].bus_addr,
|
||||
core->mem[i].size, core->mem[i].cpu_addr,
|
||||
core->mem[i].dev_addr);
|
||||
}
|
||||
core->num_mems = num_mems;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int k3_r5_core_of_get_sram_memories(struct platform_device *pdev,
|
||||
struct k3_r5_core *core)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *sram_np;
|
||||
struct resource res;
|
||||
int num_sram;
|
||||
int i, ret;
|
||||
|
||||
num_sram = of_property_count_elems_of_size(np, "sram", sizeof(phandle));
|
||||
if (num_sram <= 0) {
|
||||
dev_dbg(dev, "device does not use reserved on-chip memories, num_sram = %d\n",
|
||||
num_sram);
|
||||
return 0;
|
||||
}
|
||||
|
||||
core->sram = devm_kcalloc(dev, num_sram, sizeof(*core->sram), GFP_KERNEL);
|
||||
if (!core->sram)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < num_sram; i++) {
|
||||
sram_np = of_parse_phandle(np, "sram", i);
|
||||
if (!sram_np)
|
||||
return -EINVAL;
|
||||
|
||||
if (!of_device_is_available(sram_np)) {
|
||||
of_node_put(sram_np);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = of_address_to_resource(sram_np, 0, &res);
|
||||
of_node_put(sram_np);
|
||||
if (ret)
|
||||
return -EINVAL;
|
||||
|
||||
core->sram[i].bus_addr = res.start;
|
||||
core->sram[i].dev_addr = res.start;
|
||||
core->sram[i].size = resource_size(&res);
|
||||
core->sram[i].cpu_addr = devm_ioremap_wc(dev, res.start,
|
||||
resource_size(&res));
|
||||
if (!core->sram[i].cpu_addr) {
|
||||
dev_err(dev, "failed to parse and map sram%d memory at %pad\n",
|
||||
i, &res.start);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
dev_dbg(dev, "memory sram%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
|
||||
i, &core->sram[i].bus_addr,
|
||||
core->sram[i].size, core->sram[i].cpu_addr,
|
||||
core->sram[i].dev_addr);
|
||||
}
|
||||
core->num_sram = num_sram;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int k3_r5_cluster_rproc_init(struct platform_device *pdev)
|
||||
{
|
||||
struct k3_r5_cluster *cluster = platform_get_drvdata(pdev);
|
||||
@@ -1366,135 +1495,6 @@ static void k3_r5_cluster_rproc_exit(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev,
|
||||
struct k3_r5_core *core)
|
||||
{
|
||||
static const char * const mem_names[] = {"atcm", "btcm"};
|
||||
struct device *dev = &pdev->dev;
|
||||
struct resource *res;
|
||||
int num_mems;
|
||||
int i;
|
||||
|
||||
num_mems = ARRAY_SIZE(mem_names);
|
||||
core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL);
|
||||
if (!core->mem)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < num_mems; i++) {
|
||||
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
||||
mem_names[i]);
|
||||
if (!res) {
|
||||
dev_err(dev, "found no memory resource for %s\n",
|
||||
mem_names[i]);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!devm_request_mem_region(dev, res->start,
|
||||
resource_size(res),
|
||||
dev_name(dev))) {
|
||||
dev_err(dev, "could not request %s region for resource\n",
|
||||
mem_names[i]);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/*
|
||||
* TCMs are designed in general to support RAM-like backing
|
||||
* memories. So, map these as Normal Non-Cached memories. This
|
||||
* also avoids/fixes any potential alignment faults due to
|
||||
* unaligned data accesses when using memcpy() or memset()
|
||||
* functions (normally seen with device type memory).
|
||||
*/
|
||||
core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
|
||||
resource_size(res));
|
||||
if (!core->mem[i].cpu_addr) {
|
||||
dev_err(dev, "failed to map %s memory\n", mem_names[i]);
|
||||
return -ENOMEM;
|
||||
}
|
||||
core->mem[i].bus_addr = res->start;
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* The R5F cores can place ATCM & BTCM anywhere in its address
|
||||
* based on the corresponding Region Registers in the System
|
||||
* Control coprocessor. For now, place ATCM and BTCM at
|
||||
* addresses 0 and 0x41010000 (same as the bus address on AM65x
|
||||
* SoCs) based on loczrama setting
|
||||
*/
|
||||
if (!strcmp(mem_names[i], "atcm")) {
|
||||
core->mem[i].dev_addr = core->loczrama ?
|
||||
0 : K3_R5_TCM_DEV_ADDR;
|
||||
} else {
|
||||
core->mem[i].dev_addr = core->loczrama ?
|
||||
K3_R5_TCM_DEV_ADDR : 0;
|
||||
}
|
||||
core->mem[i].size = resource_size(res);
|
||||
|
||||
dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
|
||||
mem_names[i], &core->mem[i].bus_addr,
|
||||
core->mem[i].size, core->mem[i].cpu_addr,
|
||||
core->mem[i].dev_addr);
|
||||
}
|
||||
core->num_mems = num_mems;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int k3_r5_core_of_get_sram_memories(struct platform_device *pdev,
|
||||
struct k3_r5_core *core)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *sram_np;
|
||||
struct resource res;
|
||||
int num_sram;
|
||||
int i, ret;
|
||||
|
||||
num_sram = of_property_count_elems_of_size(np, "sram", sizeof(phandle));
|
||||
if (num_sram <= 0) {
|
||||
dev_dbg(dev, "device does not use reserved on-chip memories, num_sram = %d\n",
|
||||
num_sram);
|
||||
return 0;
|
||||
}
|
||||
|
||||
core->sram = devm_kcalloc(dev, num_sram, sizeof(*core->sram), GFP_KERNEL);
|
||||
if (!core->sram)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < num_sram; i++) {
|
||||
sram_np = of_parse_phandle(np, "sram", i);
|
||||
if (!sram_np)
|
||||
return -EINVAL;
|
||||
|
||||
if (!of_device_is_available(sram_np)) {
|
||||
of_node_put(sram_np);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = of_address_to_resource(sram_np, 0, &res);
|
||||
of_node_put(sram_np);
|
||||
if (ret)
|
||||
return -EINVAL;
|
||||
|
||||
core->sram[i].bus_addr = res.start;
|
||||
core->sram[i].dev_addr = res.start;
|
||||
core->sram[i].size = resource_size(&res);
|
||||
core->sram[i].cpu_addr = devm_ioremap_wc(dev, res.start,
|
||||
resource_size(&res));
|
||||
if (!core->sram[i].cpu_addr) {
|
||||
dev_err(dev, "failed to parse and map sram%d memory at %pad\n",
|
||||
i, &res.start);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
dev_dbg(dev, "memory sram%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
|
||||
i, &core->sram[i].bus_addr,
|
||||
core->sram[i].size, core->sram[i].cpu_addr,
|
||||
core->sram[i].dev_addr);
|
||||
}
|
||||
core->num_sram = num_sram;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void k3_r5_release_tsp(void *data)
|
||||
{
|
||||
struct ti_sci_proc *tsp = data;
|
||||
|
||||
Reference in New Issue
Block a user