1# Tzdriver driver
2
3## Introduction
4
5Tzdriver is a kernel driver deployed on the REE side, supporting communication between REE and TEE. Tzdriver processes commands from Tee Client and sends instructions to switch from REE to TEE. Tzdriver supports data sharing between REE and TEE by managing shared memory.
6
7Tzdriver includes the following main modules:
8
9smc: Send smc instructions to switch the CPU from the REE side to the TEE side for operation.
10
11session_manager: Manage communication sessions between REE and TEE.
12
13mailbox:Data is shared between REE and TEE through the mailbox.
14
15cmd_monitor:Monitor the operation of SMC instructions and provides a timeout detection mechanism.
16
17tzdebug:Create debugfs debugging nodes to facilitate developers in debugging TEE functionality
18
19tlogger:TEE log driver module, supporting TEE log recording and printing.
20
21Figure 1: Tzdriver architecture diagram
22
23![](figures/tzdriver.drawio_en.png)
24
25## Directory
26
27```
28/kernel/linux/common_modules/tzdriver
29├── core
30│   ├── cmdmonitor.c                # SMC instruction execution monitoring
31    ├── gp_ops.c                    # GP TEE specification processing logic
32    ├── mailbox_mempool.c           # REE and TEE shared memory management
33    ├── session_manager.c           # Session management for CA access to TA
34    ├── smc_smp.c                   # Send SMC command to switch to TEE
35    ├── tzdebug.c                   # Debugging module
36├── tlogger                         # TEE log driver
37```
38
39## Configuration Option
40
41If you want to enable the Tzdriver driver, you need to modify the defconfig file of the device in the Linux kernel code repository and add configuration options for Tzdriver:
42
43```
44#
45# TEEOS
46#
47CONFIG_TZDRIVER=y
48CONFIG_CPU_AFF_NR=1
49CONFIG_KERNEL_CLIENT=y
50CONFIG_TEELOG=y
51CONFIG_PAGES_MEM=y
52CONFIG_THIRDPARTY_COMPATIBLE=y
53```
54
55The meanings of each option are shown in the table below:
56
57**Table 1** Configuration Options Description
58
59| Parameters                        | Description                                                       |
60| ---------------------------- | ------------------------------------------------------------ |
61| CONFIG_TZDRIVER              | Tzdriver module switch.                                            |
62| CONFIG_CPU_AFF_NR            | CA binding core function, non-zero values represent restrictions on CPUID less than CONFIG_ CPU_ AFF_ NR's CPU can enter TEE, where 0 represents unlimited. Currently, Tzdriver only supports running on 0 cores, so the value is 1. |
63| CONFIG_KERNEL_CLIENT         | Support the kernel CA option.                                               |
64| CONFIG_TEELOG                | TEE log switch, it is recommended to enable.                                 |
65| CONFIG_PAGES_MEM             | TEE log memory management, it is recommended to enable.                        |
66| CONFIG_THIRDPARTY_COMPATIBLE | Used for compatibility with third-party optee, such as the RK3568 chip, which requires this option to be enabled. |
67
68## Compile Command
69
70Tzdriver is compiled together with the kernel. Taking the rk3568 chip as an example, the "boot_linux.img" can be compiled separately. The compilation command is as follows
71
72```
73./build.sh --product-name rk3568 --ccache --build-target kernel --gn-args linux_kernel_version=\"linux-5.10\"
74```
75
76## Related code repository
77
78[tee_client](https://gitee.com/openharmony/tee_tee_client)
79