Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Introduce stm32mp remoteproc PTA and driver #6470

Merged
merged 5 commits into from
Dec 15, 2023

Conversation

arnopo
Copy link
Contributor

@arnopo arnopo commented Nov 17, 2023

This series introduces the stm32mp remoteproc PTA and the stm32_remoteproc driver , which enable the authentication of signed images for the stm32mp157 platform.

  1. The remote proc TA implements platform-specific requirements associated to the remoteproc PTA API introduced in Introduce remote proc trusted application #6300. The API commit is also part of this PR for build purposes, and should be removed if Introduce remote proc trusted application #6300 is merged.

  2. The stm32mp_remoteproc driver is responsible for relying on the device tree, which is very similar to the Linux one. Note that the remoteproc node is a sub-node of the AHB simple bus. The AHB bus defines the dma-range property that specifoes memory translation between the Cortex-M4 mapping and the Cortex-A7 mapping. This is necessary to find the address translation between the address found in the ELF file and the address to load the segment. For instance, the RETRAM address is 0 from the Cortex-M4 perspective and 0x38000000 from the Cortex-A7 perspective.

For more details a presentation is available here: LHR23-214 OP-TEE to extend the root of trust to the coprocessor

Related pull request:

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit "drivers: Add stm32mp1 remoteproc driver" should define a default value for CFG_DRIVERS_REMOTEPROC and provide an inline description comment.

Ditto for commit "pta: stm32mp: add new remoteproc pta" regarding CFG_RPROC_PTA.

My main concern here is detailed in my review comment on stm32_rproc_get() function (see #6470 (comment)).
(edited: add a link to my comment)

core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/pta/stm32mp/remoteproc_pta.c Show resolved Hide resolved
@arnopo
Copy link
Contributor Author

arnopo commented Dec 6, 2023

Commit "drivers: Add stm32mp1 remoteproc driver" should define a default value for CFG_DRIVERS_REMOTEPROC and provide an inline description comment.

Ditto for commit "pta: stm32mp: add new remoteproc pta" regarding CFG_RPROC_PTA.

Please could you detail where I should declare default value? I was expecting that platforms declare it if supported, else config was set to n by default.

Copy link
Contributor Author

@arnopo arnopo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have taken into account @etienne-lms comment or responded to them.
However, I have not yet take into account #6470 (comment). I would waiting feedback from
@jforissier, @jenswi-linaro on the way I propose to use UUID for the platform PTA.

core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
return TEE_ERROR_ACCESS_DENIED;
}

TEE_Result stm32_rproc_unmap(uint32_t firmware_id, paddr_t pa, size_t size)

This comment was marked as resolved.

core/drivers/remoteproc/stm32_remoteproc.c Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/drivers/remoteproc/stm32_remoteproc.c Outdated Show resolved Hide resolved
core/pta/stm32mp/remoteproc_pta.c Show resolved Hide resolved
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have few comments on the fixup commits. I'm fine if you squash and rebase once addressed.

struct stm32_rproc_mem *mems = NULL;
vaddr_t *va = NULL;
paddr_t pa = virt_to_phys(va);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you replace the 2 space chars with a single one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this passes a va or a pointer to a va?
I think it should be either void *va or vaddr_t va here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I will keep void * to be aligned with core_mmu_add_mapping and core_mmu_add_mapping functions

unsigned int i = 0;

if (!rproc)
if (!rproc || !va)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!va or !pa (note: pa will be 0 if va is 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, pa seems more interesting to test as set to 0 if virt_to_phys fails.

core/drivers/remoteproc/stm32_remoteproc.c Show resolved Hide resolved
TEE_PARAM_TYPE_NONE,
TEE_PARAM_TYPE_NONE,
TEE_PARAM_TYPE_NONE);
struct ts_ctx *ctx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= NULL

@arnopo arnopo force-pushed the remoteproc_platform branch 2 times, most recently from 8aab84f to 3dce5d2 Compare December 12, 2023 18:25
Copy link
Contributor Author

@arnopo arnopo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested by @etienne-lms, I have updated the PR based on comment, squashed the fixups and rebased the PR.
On top of that I have added a new fixup that adds additional fixes.

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I will keep void * to be aligned with core_mmu_add_mapping and core_mmu_add_mapping functions

struct stm32_rproc_mem *mems = NULL;
vaddr_t *va = NULL;
paddr_t pa = virt_to_phys(va);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

unsigned int i = 0;

if (!rproc)
if (!rproc || !va)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, pa seems more interesting to test as set to 0 if virt_to_phys fails.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com> for commits
"drivers: Add stm32mp1 remoteproc driver" and
"pta: stm32mp: add new remoteproc pta" with a comment in each addressed.

for (i = 0; i < nranges; i++) {
uint32_t da = fdt32_to_cpu(list[i++]);
uint32_t pa = fdt32_to_cpu(list[i++]);
uint32_t size = fdt32_to_cpu(list[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: here I would prefer:

	for (i = 0; i < nranges; i += 3) {
		uint32_t da = fdt32_to_cpu(list[i]);
		uint32_t pa = fdt32_to_cpu(list[i + 1]);
		uint32_t size = fdt32_to_cpu(list[i + 2]);
		(...)

*/
static TEE_Result
rproc_pta_open_session(uint32_t pt, TEE_Param params[TEE_NUM_PARAMS],
void **sess_ctx __unused)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer:

static TEE_Result rproc_pta_open_session(uint32_t pt,
					 TEE_Param params[TEE_NUM_PARAMS],
					 void **sess_ctx __unused)

@arnopo
Copy link
Contributor Author

arnopo commented Dec 13, 2023

Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com> for commits "drivers: Add stm32mp1 remoteproc driver" and "pta: stm32mp: add new remoteproc pta" with a comment in each addressed.

Done, thanks @etienne-lms for the reviews!

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>for commits
"plat-stm32mp1: Add the remoteproc TA in early-TA list" and
"dts: stm32: update m4_rproc to support the remoteproc OPTEE framework".

Copy link
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments on "drivers: Add stm32mp1 remoteproc driver".

s/coherence/consistency/ in the commit description. Other comments below.

mk/config.mk Outdated
CFG_DRIVERS_REMOTEPROC ?= n

# CFG_RPROC_PTA, when enabled, embeds remote processor management PTA service.
CFG_RPROC_PTA ?= n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind s/CFG_RPROC_PTA/CFG_REMOTEPROC_PTA/ for consistency with CFG_DRIVERS_REMOTEPROC (and better "grepability", too)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes much better I also move the declaration in the patch that introduce the remoteproc PTA

return res;
}

static TEE_Result __stm32_rproc_stop(struct stm32_rproc_instance *rproc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leading underscores/double underscores are not really recommended, why not simply rproc_stop()? It is a static function the name can remain very short and generic with no risk of collision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commit " pta: stm32mp: add new remoteproc pta"

s/pta/PTA/ in the suject (the pta: prefix is OK in lowercase).

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>

@@ -151,6 +151,7 @@ CFG_CORE_ASLR ?= n

CFG_STM32MP_REMOTEPROC ?= n
CFG_DRIVERS_REMOTEPROC ?= $(CFG_STM32MP_REMOTEPROC)
CFG_RPROC_PTA ?= $(CFG_STM32MP_REMOTEPROC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already mentioned I would prefer CFG_REMOTEPROC_PTA

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For "plat-stm32mp1: Add the remoteproc TA in early-TA list":

s/early-TA/early TA/

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

Copy link
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For "dts: stm32: update m4_rproc to support the remoteproc OPTEE framework":

s/OPTEE/OP-TEE/

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>

Copy link
Contributor Author

@arnopo arnopo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jforissier : I have take, into account your comments. In addition I have re-dispatched the CFG-REMOTEPROC-PTA between commits. As consequence, I don't add your tag and @etienne-lms one in commits.
Please, could you confirm that the fixups are ok for you then i will squash them add the tags in commits messages.

return res;
}

static TEE_Result __stm32_rproc_stop(struct stm32_rproc_instance *rproc)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -151,6 +151,7 @@ CFG_CORE_ASLR ?= n

CFG_STM32MP_REMOTEPROC ?= n
CFG_DRIVERS_REMOTEPROC ?= $(CFG_STM32MP_REMOTEPROC)
CFG_RPROC_PTA ?= $(CFG_STM32MP_REMOTEPROC)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

mk/config.mk Outdated
CFG_DRIVERS_REMOTEPROC ?= n

# CFG_RPROC_PTA, when enabled, embeds remote processor management PTA service.
CFG_RPROC_PTA ?= n
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes much better I also move the declaration in the patch that introduce the remoteproc PTA

@jforissier
Copy link
Contributor

@arnopo yes the fixups look good, thanks. When squashing you may also add:

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>

... to "drivers: Add stm32mp1 remoteproc driver".

The remoteproc PTA is charge of providing interface to authenticate
firmware images and managing the remote processor live cycle.
The remoteproc PTA supports platform specificity in the
management of a remote processor:
- firmware authentication based on a platform key,
- load of the segments in remote processor memories,
- start/stop of the remote processor,
- remote processor addresses conversion.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
This driver is responsible for configuring the registers and memories of
the remote processor.
- It stores information about memories assigned to the remote processor
  based on the device tree.
- It ensures consistency between the registered memory and the addresses
of the firmware segments to be loaded.
- Additionally, it is responsible for starting and stopping the remote
processor core.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Add remoteproc PTA for the stm32mp1 platform.
The PTA relies on the stm32_remoteproc driver for the remoteproc
management.
It is charge of providing interface for authenticating firmware images
and managing the remote processor live cycle.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
@arnopo
Copy link
Contributor Author

arnopo commented Dec 15, 2023

I rebased on top of master branch to fix merge conflic introduced by 1d12969 ("core: add CFG_AUTO_MAX_PA_BITS", 2023-12-13)

On the stm32mp1 platform, it is possible to load firmware during the
bootloader stage, for instance, by U-boot. To enable this feature,
The remoteproc TA should be added to the list of early-TAs.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Update device tree to support the load of the remoteproc firmware
by OP-TEE.
- declare m_ipc_shm memory region that can contain the remote processor
  resource table and trace buffer,
- update reset to align declaration with the Linux devicetree

To enable the load of the coprocessor firmware by OP-TEE, user have
to update the m4_rproc node compatible property:
-"st,stm32mp1-m4": the load is managed by Linux or U-boot,
-"st,stm32mp1-m4-tee": the load is managed by OP-TEE.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
@arnopo
Copy link
Contributor Author

arnopo commented Dec 15, 2023

+1 update to fix a typo in commit adding the acked-by

@jforissier jforissier merged commit 7c9920c into OP-TEE:master Dec 15, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants