| 7b76de3d | 24-Jul-2024 |
Alvin Chang <alvinga@andestech.com> |
core: riscv: Let platform choose native and foreign interrupts
Platform may want to choose different types of native and foreign interrupts. This commit adds two definitions for the platforms: 1. PL
core: riscv: Let platform choose native and foreign interrupts
Platform may want to choose different types of native and foreign interrupts. This commit adds two definitions for the platforms: 1. PLAT_THREAD_EXCP_FOREIGN_INTR: to define platform specific foreign interrupts 2. PLAT_THREAD_EXCP_NATIVE_INTR: to define platform specific native interrupts.
For RISC-V virt machine, we define all external/mtimer/software interrupts as foreign interrupts. For RISC-V spike platform, we define external interrupts as foreign interrupts, and mtimer/software interrupts as native interrupts.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 8d5bae1c | 24-Jul-2024 |
Alvin Chang <alvinga@andestech.com> |
core: riscv: Implement foreign interrupt handler
In SMP based OP-TEE system, the foreign interrupts, which are handled outside OP-TEE, might be injected during the execution of OP-TEE. When OP-TEE r
core: riscv: Implement foreign interrupt handler
In SMP based OP-TEE system, the foreign interrupts, which are handled outside OP-TEE, might be injected during the execution of OP-TEE. When OP-TEE receives such foreign interrupts, it should suspend current thread and yield the execution to the foreign domains to handle those foreign interrupts.
This commit implements thread_foreign_interrupt_handler(), which is expected to be called during trap handling. The job of this function are suspending the current thread, and returning to the other domain to let them handle the foreign interrupts.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| d1d1ca23 | 23-Oct-2023 |
Alvin Chang <alvinga@andestech.com> |
core: riscv: Apply STATUS helper for RPC resume
Since RPC resume is a kind of exception return, we invoke xstatus_for_xret() to prepare the CSR STATUS for exception return. But the actual value of S
core: riscv: Apply STATUS helper for RPC resume
Since RPC resume is a kind of exception return, we invoke xstatus_for_xret() to prepare the CSR STATUS for exception return. But the actual value of STATUS when calling thread_rpc() is still saved in stack. This is to unify the behavior between RPC suspend and resume.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Tested-by: Marouene Boubakri <marouene.boubakri@nxp.com> Reviewed-by: Marouene Boubakri <marouene.boubakri@nxp.com>
show more ...
|
| 09653bca | 23-Oct-2023 |
Alvin Chang <alvinga@andestech.com> |
core: riscv: Apply exception return to resume thread
In current implementation, the thread is resumed by function return. It is not suitable for all scenarios, especially when the thread should be r
core: riscv: Apply exception return to resume thread
In current implementation, the thread is resumed by function return. It is not suitable for all scenarios, especially when the thread should be resumed to user mode. The kernel mode can not return to user mode by pure function return.
This commit applies exception return to resume the thread. The EPC and IE are added into thread context. The xstatus_for_xret() helper function is added to prepare the value of CSR STATUS for exception return. Currently we only consider PIE(previous interrupt-enable) and PP(previous privilege mode) for exception return.
We clear thread context when the context is reinitialized, enable native interrupt, and setup kernel GP/TP. The thread_resume() now takes care of restoring CSR EPC, STATUS, IE, SCRATCH and all general-purpose registers. Finally it executes exception return to target privilege mode encoded in CSR STATUS. The registers GP and TP are also restored since user mode may use them.
This commit also modify the usage of CSR SCRATCH. In current implementation the SCRATCH is used to save kernel stack pointer when the thread is in user mode. The value of TP, which stores thread_core_local structure, is saved into kernel stack before entering user mode. The trap handler can then get TP(thread_core_local) from kernel stack. This is not suitable for SMP system, since the thread might be resumed to another core, and that core gets wrong TP from kernel stack. Fix it by directly storing TP into CSR SCRATCH.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Reviewed-by: Marouene Boubakri <marouene.boubakri@nxp.com> Tested-by: Marouene Boubakri <marouene.boubakri@nxp.com>
show more ...
|
| 0fb22936 | 11-Oct-2023 |
Alvin Chang <alvinga@andestech.com> |
core: riscv: Implement SBI based protocol
Rename thread_return_from_nsec_call() to thread_return_to_ree() for more general behavior, since TEE might not only be called by REE, but also do something
core: riscv: Implement SBI based protocol
Rename thread_return_from_nsec_call() to thread_return_to_ree() for more general behavior, since TEE might not only be called by REE, but also do something on its own initiative (e.g., handle secure interrupts).
This commit also implements SBI based protocol used to return control to REE. The register a7 encodes SBI TEE extension ID, which is temporarily defined here. We may have ratified SBI TEE extension in the future and we can apply ratified ID at that time. The register a6 is unused and encoded as 0. The returned arguments are encoded into registers a0~a5 and should be provided by the caller.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| b0f61f0c | 29-Aug-2023 |
Marouene Boubakri <marouene.boubakri@nxp.com> |
core: riscv: thread_private_arch.h: add std and fast calls prototypes
This commit adds the following prototypes to thread_private_arch.h: - thread_std_abi_entry() - __thread_std_abi_entry() - thread
core: riscv: thread_private_arch.h: add std and fast calls prototypes
This commit adds the following prototypes to thread_private_arch.h: - thread_std_abi_entry() - __thread_std_abi_entry() - thread_handle_fast_abi() - thread_handle_std_abi()
Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com> Reviewed-by: Alvin Chang <alvinga@andestech.com> Tested-by: Alvin Chang <alvinga@andestech.com>
show more ...
|
| 3db1b3e3 | 18-Jul-2023 |
Alvin Chang <alvinga@andestech.com> |
core: riscv: Support Privileged Access Never by CSR status.SUM bit
The SUM (Supervisor User Memory access) bit modifies the privilege with which S-mode loads and stores the user virtual memory. When
core: riscv: Support Privileged Access Never by CSR status.SUM bit
The SUM (Supervisor User Memory access) bit modifies the privilege with which S-mode loads and stores the user virtual memory. When SUM bit is 0, S-mode accesses to pages whose U bit of corresponding PTE is set will fault. When SUM bit is 1, these accesses are permitted.
When CFG_PAN is disabled in RISC-V architecture, the status.SUM bit is initialized as 1 by default. Therefore all accesses to user pages will succeed. When CFG_PAN is enabled, the status.SUM bit is initialized as 0, and only set to 1 when kernel needs to access user pages.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Tested-by: Marouene Boubakri <marouene.boubakri@nxp.com> Reviewed-by: Marouene Boubakri <marouene.boubakri@nxp.com>
show more ...
|