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

[RFC] SCMI PTA with OCALL #4535

Closed
wants to merge 8 commits into from

Conversation

etienne-lms
Copy link
Contributor

This P-R is based on:

@HernanGatta, you see in this serie a commit leveraging OCALL to create a provisioned threaded entry in OP-TEE:
core: pta: scmi: ocall threaded context (54d0a2a).

@etienne-lms etienne-lms marked this pull request as draft April 5, 2021 15:04
@etienne-lms etienne-lms force-pushed the scmi-pta-ocall branch 2 times, most recently from 04af9c2 to 60a25fd Compare April 7, 2021 09:31
@etienne-lms etienne-lms marked this pull request as ready for review April 7, 2021 12:24
@etienne-lms etienne-lms marked this pull request as draft April 7, 2021 12:24
@jenswi-linaro
Copy link
Contributor

I think it would help the review if you could provide an overview of how this is supposed to work. It seems you're spawning a thread somewhere. What's the purpose with that thread, etc?

@etienne-lms
Copy link
Contributor Author

Sorry, I was to push the Linux drivers but saw to many hoary things so spent time on fixing cleaning after creating this RFC.

The more synthetic description I went to is the one in pta_scmi_client.h.
Here it is, slightly rephrased.

We start from the REE kernel (a U-Boot or Linux driver): caller requests an Ocall context and use it to pass SCMI messages.

  1. REE opens a session toward PTA SCMI and invokes PTA command PTA_SCMI_CMD_GET_CHANNEL fix Ocall capability to get an Ocall capable channel handler.

  2. REE invokes command PTA_SCMI_CAPS_OCALL_THREAD with an Ocall context.

  3. Upon support of Ocall, PTA returns to REE with RPC Ocall command PTA_SCMI_OCALL_CMD_THREAD_READY.
    REE saves the invocation context (params structure used in the OP-TEE invocation, holding the OCALL meta-data) and uses it for the next PTA invocations.

  4. REE can return from the Ocall with output param[0].value.a set to PTA_SCMI_OCALL_PROCESS_CHANNEL to have an SCMI message processed.
    In such case, OP-TEE processes the message and returns to REE again with an RPC Ocall command PTA_SCMI_OCALL_CMD_THREAD_READY. The SCMI response is in the shared memory buffer.
    If PTA founds an issue in the communication, it does not perform a RPC Ocall but returns from command invocation at 2. with an error result.

  5. Alternatively REE can return from the Ocall with output param[0].value.a set to PTA_SCMI_OCALL_CLOSE_THREAD.
    This will request OP-TEE to successfully terminate the Ocall and return from initial command invocation at 2. REE can then close the TEE session.

At anytime, if an error is reported by Ocall commands and replies, PTA SCMI returns from initial invocation at 2. which releases the Ocall context.

At channel setup, REE driver executes steps 1., 2. and 3.
When a REE agent wants to post an SCMI message, agent goes through step 4.
At channel release, REE driver executes step 5.

@jenswi-linaro
Copy link
Contributor

I'm sorry, I don't get it. Would it be possible to draw some diagram with plantuml for instance?

@etienne-lms
Copy link
Contributor Author

etienne-lms commented Apr 14, 2021

okay, i'll prepare something.
I have now a decent implementation in linux drivers. i'll share. i'm off for few days so likely update P-Rs early next week.

@jenswi-linaro
Copy link
Contributor

Thanks

etienne-lms and others added 8 commits April 15, 2021 21:11
Adds a PTA interface to REE SCMI agents to get SCMI message communication
channel for processing in OP-TEE SCMI server.

Currently implement supports for a SCMI server built with
CFG_SCMI_MSG_SMT=y. The implementation is made so that an
alternate SCMI server implementation can added.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Support posting message without buffer memref:
  Implement PTA_SCMI_CMD_PROCESS_SMT_MESSAGE where client provides the
  shared memory buffer reference with SCMI message notification instead
  of using a memory buffer statically assigned for the communication
  channel.

Fix PTA_SCMI_CMD_GET_CHANNEL description inline comment.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Enable SCMI PTA for REE to interface SCMI services in a threaded context.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
checkpatch suggests using the BIT macro instead of a left shift.

Signed-off-by: Hernan Gatta <hegatta@microsoft.com>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Adds the ability for Core to perform "Out Calls", or OCALLs. OCALLs
allow OP-TEE Core PTA services to invoke commands on their corresponding
client in the same way that client can invoke commands on TAs.

Adds a new capability that reports whether OP-TEE was built with OCALL
support.

Signed-off-by: Hernan Gatta <hegatta@microsoft.com>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
[etienne: split CFG_OCALL into CFG_{CORE|USER}_OCALL, no libutee, no pta]
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Using Ocall (CFG_CORE_OCALL=y), the SCMI agent and PTA can provision a
secure thread for SCMI message passing/processing.

The channel exchange protocol using OP-TEE Ocall is described in the
PTA API header file pta_scmi_client.h.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Enable CFG_CORE_OCALL to leverage Ocall suuport and provision a secure
thread for SCMI message execution in a threaded context. Default to 3
threads  since SCMI Linux driver will provision one for SCMI
communication.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Adds the ability for TAs to perform "Out Calls", or OCALLs. OCALLs allow
TAs to invoke commands on their corresponding CA in the same way that CAs
can invoke commands on TAs. Also, adds a new capability that reports
whether OP-TEE was built with OCALL support.

Signed-off-by: Hernan Gatta <hegatta@microsoft.com>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
[etienne: here the CFG_USER_OCALL part of the orginal patch]
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
@etienne-lms
Copy link
Contributor Author

scmi pta - ocall context

@etienne-lms
Copy link
Contributor Author

I've posted the Linux part in linaro-swg/linux#90.
I hope the illustration above clarifies the context.

@jenswi-linaro
Copy link
Contributor

Thanks, very helpful.
What is the plan here? The PR is still "work in progress" what kind of feedback are you looking for?

@etienne-lms
Copy link
Contributor Author

This P-R is based on #3673 (ocall) and #4533 (scmi pta).
I thought #4533 could be reviewed on its own to get the SCMI PTA basics being merged once accepted.
Once merged, I think it would be easier to get ocall support and the scmi pta ocall changes reviewed.

Or maybe should I abandon #4533 and consider only this P-R including the OCall part?

@jenswi-linaro
Copy link
Contributor

To make a good review I need a proper proposal to review, that is something that will be merged once it's done. If a commit isn't final I don't think it makes sense to make a deep dive as things are going to change before it's merged

However, I you want to include OCALL we need to finalize the kernel driver part of it first since that's the tricky part. I'm especially concerned about the shared memory part, I don't want to risk committing to an ABI that we in the end can't use.

@etienne-lms
Copy link
Contributor Author

Let's start with the starter and first get SCMI PTA minimal features: #4533.
I close this P-R and will preserve the branch related to it for the record.

ldebieve pushed a commit to STMicroelectronics/optee_os that referenced this pull request Jun 16, 2022
Using Ocall (CFG_CORE_OCALL=y), the SCMI agent and PTA can provision a
secure thread for SCMI message passing/processing.

The channel exchange protocol using OP-TEE Ocall is described in the
PTA API header file pta_scmi_client.h

Note: this change was originally posted to OP-TEE through pull request
OP-TEE#4535.

Change-Id: I995192c660cd837fa7ccc025f5c95363e3b01937
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-on: https://gerrit.st.com/c/mpu/oe/optee/optee_os/+/202484
Tested-by: Etienne CARRIERE <etienne.carriere@foss.st.com>
Reviewed-by: Etienne CARRIERE <etienne.carriere@foss.st.com>
Reviewed-by: Lionel DEBIEVE <lionel.debieve@foss.st.com>
arnout pushed a commit to arnout/optee_os that referenced this pull request Jan 6, 2023
Using Ocall (CFG_CORE_OCALL=y), the SCMI agent and PTA can provision a
secure thread for SCMI message passing/processing.

The channel exchange protocol using OP-TEE Ocall is described in the
PTA API header file pta_scmi_client.h

Note: this change was originally posted to OP-TEE through pull request
OP-TEE#4535.

Change-Id: I995192c660cd837fa7ccc025f5c95363e3b01937
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-on: https://gerrit.st.com/c/mpu/oe/optee/optee_os/+/202484
Tested-by: Etienne CARRIERE <etienne.carriere@foss.st.com>
Reviewed-by: Etienne CARRIERE <etienne.carriere@foss.st.com>
Reviewed-by: Lionel DEBIEVE <lionel.debieve@foss.st.com>
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.

None yet

3 participants