Skip to content

Commit

Permalink
fixup! drivers: Add stm32mp1 remoteproc driver
Browse files Browse the repository at this point in the history
- Rename fw_id to proc_id,
- change stm32_rproc_unmap() parameter from pa to va,
- add check on dma-range length that shoub be a multiple of 3 32-bit words,
- return error instead of ignore memory-regions not well declared,
- fiw various typos

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Change-Id: I8a62af700e7339c24c3a5e65bf9557e83c902382
  • Loading branch information
arnopo committed Dec 6, 2023
1 parent 6735610 commit 3b7214c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 56 deletions.
74 changes: 38 additions & 36 deletions core/drivers/remoteproc/stm32_remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,29 @@ struct stm32_rproc_instance {
/**
* struct stm32_rproc_compat_data - rproc associated data for compatible list
*
* @firmware_id: identifies the remoteproc firmware to load
* @rproc_id: identifies the remote processor
*/
struct stm32_rproc_compat_data {
uint32_t firmware_id;
uint32_t rproc_id;
};

static SLIST_HEAD(, stm32_rproc_instance) rproc_list =
SLIST_HEAD_INITIALIZER(rproc_list);

void *stm32_rproc_get(uint32_t firmware_id)
void *stm32_rproc_get(uint32_t rproc_id)
{
struct stm32_rproc_instance *rproc = NULL;

SLIST_FOREACH(rproc, &rproc_list, link)
if (rproc->cdata->firmware_id == firmware_id)
return rproc;
if (rproc->cdata->rproc_id == rproc_id)
break;

return NULL;
return rproc;
}

TEE_Result stm32_rproc_start(uint32_t firmware_id)
TEE_Result stm32_rproc_start(uint32_t rproc_id)
{
struct stm32_rproc_instance *rproc = stm32_rproc_get(firmware_id);
struct stm32_rproc_instance *rproc = stm32_rproc_get(rproc_id);
TEE_Result res = TEE_ERROR_GENERIC;

if (!rproc || !rproc->hold_boot)
Expand Down Expand Up @@ -107,20 +107,20 @@ static TEE_Result __stm32_rproc_stop(struct stm32_rproc_instance *rproc)
return res;
}

TEE_Result stm32_rproc_stop(uint32_t firmware_id)
TEE_Result stm32_rproc_stop(uint32_t rproc_id)
{
struct stm32_rproc_instance *rproc = stm32_rproc_get(firmware_id);
struct stm32_rproc_instance *rproc = stm32_rproc_get(rproc_id);

if (!rproc)
return TEE_ERROR_BAD_PARAMETERS;

return __stm32_rproc_stop(rproc);
}

TEE_Result stm32_rproc_da_to_pa(uint32_t firmware_id, paddr_t da, size_t size,
TEE_Result stm32_rproc_da_to_pa(uint32_t rproc_id, paddr_t da, size_t size,
paddr_t *pa)
{
struct stm32_rproc_instance *rproc = stm32_rproc_get(firmware_id);
struct stm32_rproc_instance *rproc = stm32_rproc_get(rproc_id);
struct stm32_rproc_mem *mems = NULL;
unsigned int i = 0;

Expand All @@ -138,18 +138,18 @@ TEE_Result stm32_rproc_da_to_pa(uint32_t firmware_id, paddr_t da, size_t size,
* delta between the requested DA and the
* reserved-memory DA address.
*/
*pa = mems[i].addr + (da - mems[i].da);
*pa = mems[i].addr + da - mems[i].da;
return TEE_SUCCESS;
}
}

return TEE_ERROR_ACCESS_DENIED;
}

TEE_Result stm32_rproc_map(uint32_t firmware_id, paddr_t pa, size_t size,
TEE_Result stm32_rproc_map(uint32_t rproc_id, paddr_t pa, size_t size,
void **va)
{
struct stm32_rproc_instance *rproc = stm32_rproc_get(firmware_id);
struct stm32_rproc_instance *rproc = stm32_rproc_get(rproc_id);
struct stm32_rproc_mem *mems = NULL;
unsigned int i = 0;

Expand All @@ -174,14 +174,14 @@ TEE_Result stm32_rproc_map(uint32_t firmware_id, paddr_t pa, size_t size,
return TEE_ERROR_ACCESS_DENIED;
}

TEE_Result stm32_rproc_unmap(uint32_t firmware_id, paddr_t pa, size_t size)
TEE_Result stm32_rproc_unmap(uint32_t rproc_id, vaddr_t *va, size_t size)
{
struct stm32_rproc_instance *rproc = stm32_rproc_get(firmware_id);
struct stm32_rproc_instance *rproc = stm32_rproc_get(rproc_id);
struct stm32_rproc_mem *mems = NULL;
vaddr_t *va = NULL;
paddr_t pa = virt_to_phys(va);
unsigned int i = 0;

if (!rproc)
if (!rproc || !va)
return TEE_ERROR_BAD_PARAMETERS;

mems = rproc->regions;
Expand All @@ -191,10 +191,6 @@ TEE_Result stm32_rproc_unmap(uint32_t firmware_id, paddr_t pa, size_t size)
mems[i].size))
continue;

va = (void *)core_mmu_get_va(pa, MEM_AREA_RAM_NSEC, size);
if (!va)
return TEE_ERROR_ACCESS_DENIED;

/* Flush the cache before unmapping the memory */
dcache_clean_range(va, size);

Expand Down Expand Up @@ -227,12 +223,17 @@ static TEE_Result stm32_rproc_get_dma_range(struct stm32_rproc_mem *region,

list = fdt_getprop(fdt, ahb_node, "dma-ranges", &len);
if (!list) {
if (len != -FDT_ERR_NOTFOUND)
return TEE_ERROR_GENERIC;
/* Same memory mapping */
DMSG("No dma-ranges found in DT");
region->da = region->addr;
return TEE_SUCCESS;
}

if ((len % (sizeof(uint32_t) * 3)))
return TEE_ERROR_GENERIC;

nranges = len / sizeof(uint32_t);

for (i = 0; i < nranges; i++) {
Expand All @@ -243,15 +244,14 @@ static TEE_Result stm32_rproc_get_dma_range(struct stm32_rproc_mem *region,
if (core_is_buffer_inside(region->addr, region->size,
pa, size)) {
region->da = da + (region->addr - pa);
DMSG("device address found : %#"PRIxPA, region->da);
return TEE_SUCCESS;
}
}

return TEE_ERROR_BAD_PARAMETERS;
}

/* Get device tree memory regions reserved for the Cortex-M an the IPC */
/* Get device tree memory regions reserved for the Cortex-M and the IPC */
static TEE_Result stm32_rproc_parse_mems(struct stm32_rproc_instance *rproc,
const void *fdt, int node)
{
Expand All @@ -264,8 +264,8 @@ static TEE_Result stm32_rproc_parse_mems(struct stm32_rproc_instance *rproc,

list = fdt_getprop(fdt, node, "memory-region", &len);
if (!list) {
DMSG("No memory regions found in DT");
return TEE_ERROR_NO_DATA;
EMSG("No memory regions found in DT");
return TEE_ERROR_GENERIC;
}

n_regions = len / sizeof(uint32_t);
Expand All @@ -274,18 +274,21 @@ static TEE_Result stm32_rproc_parse_mems(struct stm32_rproc_instance *rproc,
if (!regions)
return TEE_ERROR_OUT_OF_MEMORY;

rproc->n_regions = 0;
for (i = 0; i < n_regions; i++) {
int pnode = 0;
const fdt32_t *prop = NULL;

pnode = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(list[i]));
if (pnode < 0)
continue;
if (pnode < 0) {
res = TEE_ERROR_GENERIC;
goto err;
}

prop = fdt_getprop(fdt, pnode, "reg", NULL);
if (!prop)
continue;
if (!prop) {
res = TEE_ERROR_GENERIC;
goto err;
}

regions[i].addr = fdt32_to_cpu(prop[0]);
regions[i].size = fdt32_to_cpu(prop[1]);
Expand All @@ -302,9 +305,9 @@ static TEE_Result stm32_rproc_parse_mems(struct stm32_rproc_instance *rproc,
DMSG("register region %#"PRIxPA" size %#zx",
regions[i].addr, regions[i].size);

rproc->n_regions++;
}

rproc->n_regions = n_regions;
rproc->regions = regions;

return TEE_SUCCESS;
Expand Down Expand Up @@ -333,7 +336,6 @@ static TEE_Result stm32_rproc_probe(const void *fdt, int node,

rproc->cdata = comp_data;

/* Get memory regions */
res = stm32_rproc_parse_mems(rproc, fdt, node);
if (res)
goto err;
Expand Down Expand Up @@ -371,13 +373,13 @@ static TEE_Result stm32_rproc_probe(const void *fdt, int node,
}

static const struct stm32_rproc_compat_data stm32_rproc_m4_compat = {
.firmware_id = STM32_M4_FW_ID,
.rproc_id = STM32_M4_RPROC_ID,
};

static const struct dt_device_match stm32_rproc_match_table[] = {
{
.compatible = "st,stm32mp1-m4-tee",
.compat_data = (void *)&stm32_rproc_m4_compat,
.compat_data = &stm32_rproc_m4_compat,
},
{ }
};
Expand Down
42 changes: 22 additions & 20 deletions core/include/drivers/stm32_remoteproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,61 @@
#include <tee_api_types.h>
#include <types_ext.h>

/* IDs of the supported firmwares*/
#define STM32_M4_FW_ID 0
/* IDs of the supported remote processors*/
#define STM32_M4_RPROC_ID 0

/*
* stm32_rproc_get() - get the rproc handle associated to a firmware ID
* @firmware_id unique identifier of the firmware
* Return a pointer to the rproc firmware handle related to @fw_id or NULL.
* stm32_rproc_get() - get the rproc handle associated to a remote processor ID
* @rproc_id unique identifier of the remote processor
* Return a pointer to the rproc firmware handle related to @rproc_id or NULL.
*/
void *stm32_rproc_get(uint32_t firmware_id);
void *stm32_rproc_get(uint32_t rproc_id);

/*
* stm32_rproc_da_to_pa() - Convert the coprocessor device address to a CPU
* physical address.
* @firmware_id unique identifier of the firmware
* physical address.
* @rproc_id unique identifier of the remote processor
* @da device memory address from the remote processor space
* perspective.
* @size size of the memory
* @pa Output CPU physical address associated to @da.
* Return TEE_SUCCESS or appropriate error.
*/
TEE_Result stm32_rproc_da_to_pa(uint32_t firmware_id, paddr_t da, size_t size,
TEE_Result stm32_rproc_da_to_pa(uint32_t rproc_id, paddr_t da, size_t size,
paddr_t *pa);

/*
* stm32_rproc_map() - map the physical address if valid
* @firmware_id unique identifier of the firmware
* @rproc_id unique identifier of the remote processor
* @pa physical address from the CPU space perspective
* @size size of the memory
* @va Output CPU virtual address associated to @pa.
* Return TEE_SUCCESS or appropriate error.
*/
TEE_Result stm32_rproc_map(uint32_t firmware_id, paddr_t pa, size_t size,
TEE_Result stm32_rproc_map(uint32_t rproc_id, paddr_t pa, size_t size,
void **va);

/*
* stm32_rproc_unmap() - ummap the physical address mapped with stm32_rproc_map
* @firmware_id unique identifier of the firmware
* @pa physical address from the CPU space perspective
* stm32_rproc_unmap() - ummap the virtual address mapped with stm32_rproc_map
* @rproc_id unique identifier of the remote processor
* @va virtual address
* @size size of the memory
* Return TEE_SUCCESS or appropriate error.
*/
TEE_Result stm32_rproc_unmap(uint32_t firmware_id, paddr_t pa, size_t size);
TEE_Result stm32_rproc_unmap(uint32_t rproc_id, vaddr_t *va, size_t size);

/*
* stm32_rproc_start() - start the remote processor core
* @firmware_id unique identifier of the firmware
* @rproc_id unique identifier of the remote processor
* Return TEE_SUCCESS or appropriate error.
*/
TEE_Result stm32_rproc_start(uint32_t firmware_id);
TEE_Result stm32_rproc_start(uint32_t rproc_id);

/*
* stm32_rproc_start() - stop the remote processor core
* @firmware_id unique identifier of the firmware
* stm32_rproc_stop() - stop the remote processor core
* @rproc_id unique identifier of the remote processor
* Return TEE_SUCCESS or appropriate error.
*/
TEE_Result stm32_rproc_stop(uint32_t firmware_id);
TEE_Result stm32_rproc_stop(uint32_t rproc_id);

#endif /* __DRIVERS_STM32_REMOTEPROC_H */

0 comments on commit 3b7214c

Please sign in to comment.