Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | Introduction |
| 2 | ============ |
| 3 | |
| 4 | The tzcom (TrustZone Communicator) device driver provides IOCTLs for userspace |
| 5 | to communicate with TrustZone Operating Environment (TZBSP) using Secure |
| 6 | Channel Manager (SCM) interface. It also provides a way for TZBSP to utilize |
| 7 | services in HLOS. |
| 8 | |
| 9 | Hardware description |
| 10 | ==================== |
| 11 | |
| 12 | The hardware interaction is specified in Secure Channel Manager for TZBSP design |
| 13 | document. This driver exercises the SCM interface (scm_call). |
| 14 | |
| 15 | Software description |
| 16 | ==================== |
| 17 | |
| 18 | This driver is a character device driver and following operations are registered: |
| 19 | - tzcom_open() |
| 20 | - tzcom_release() |
| 21 | - tzcom_ioctl() |
| 22 | |
| 23 | |
| 24 | This driver provides following IOCTL methods: |
| 25 | TZCOM_IOCTL_REGISTER_SERVICE_REQ - to register HLOS service |
| 26 | TZCOM_IOCTL_UNREGISTER_SERVICE_REQ - to unregister HLOS service |
| 27 | TZCOM_IOCTL_SEND_CMD_REQ - send a command to a service |
| 28 | TZCOM_IOCTL_READ_NEXT_CMD_REQ - wait for a cmd from TZBSP to use HLOS service |
| 29 | TZCOM_IOCTL_CONTINUE_CMD_REQ - continue the last incomplete cmd on TZBSP |
| 30 | |
| 31 | TZCOM_IOCTL_REGISTER_SERVICE_REQ sequence diagram: |
| 32 | |
| 33 | +--------------+ +---------------+ |
| 34 | | USERSPACE | | TZCOM | |
| 35 | +------+-------+ +-------+-------+ |
| 36 | | REGISTER_SERVICE | |
| 37 | |----------------->| ___ |
| 38 | | |,-' ``. |
| 39 | | + verify &`. |
| 40 | | | add | |
| 41 | | | service | |
| 42 | | | to a list| |
| 43 | | registered |<-.._,,,,/ |
| 44 | |<-----------------| |
| 45 | | | |
| 46 | |
| 47 | TZCOM_IOCTL_READ_NEXT_CMD_REQ, TZCOM_IOCTL_SEND_CMD_REQ and |
| 48 | TZCOM_IOCTL_CONTINUE_CMD_REQ sequence: |
| 49 | |
| 50 | +--------------+ +---------------+ +-------------+ +----------------+ |
| 51 | | USERSPACE | | TZCOM | | SCM | | TZBSP | |
| 52 | +---+--+-------+ +-------+-------+ +------+------+ +-------+--------+ |
| 53 | | | READ_NEXT_CMD | | | |
| 54 | +--|----------------->| | | |
| 55 | | | |.--------. | | |
| 56 | | | || BLOCKED| | | |
| 57 | | | |`--------' | | |
| 58 | | | | | | |
| 59 | | | | | | |
| 60 | | | SEND_CMD | | | |
| 61 | | +----------------->| | | |
| 62 | | | | scm_call | | |
| 63 | | | +---------------->| SEND_CMD | |
| 64 | | | | +---------------->| |
| 65 | | | | | cmd incomplete | |
| 66 | | | | scm_call returns|<----------------+ |
| 67 | | | |<----------------+ | |
| 68 | | | | | | |
| 69 | | | |,-'''-. | | |
| 70 | | | + READ `. | | |
| 71 | | | | NEXT | | | |
| 72 | | | | CMD / | | |
| 73 | | | READ_NEXT_CMD ret|<.____,' | | |
| 74 | |<-|------------------+ | | |
| 75 | ,---. | | | | | |
| 76 | / \ | | | | | |
| 77 | /perform\| | | | | |
| 78 | received) | | | | |
| 79 | \command/| | | | | |
| 80 | \ / | | | | | |
| 81 | `---' | | | | | |
| 82 | | | | | | |
| 83 | | | CONTINUE_CMD | | | |
| 84 | +--|----------------->| | | |
| 85 | | | returns | _,... | | |
| 86 | | | immediately |' `. | | |
| 87 | | | | fill in`. | | |
| 88 | | | | incomplete | | |
| 89 | | | | cmd ; | | |
| 90 | | |<-...---' | | |
| 91 | | | scm_call | | |
| 92 | | +---------------->| SEND_CMD | |
| 93 | | | +---------------->| |
| 94 | | | | cmd complete | |
| 95 | | | scm_call returns|<----------------+ |
| 96 | |SEND_CMD return |<----------------+ | |
| 97 | |<-----------------+ | | |
| 98 | | | | | |
| 99 | |
| 100 | |
| 101 | |
| 102 | There are three shared buffers between TZCOM driver and TZBSP. |
| 103 | 1) For command and response buffers for SEND_CMD requests |
| 104 | 2) For commands originated from TZBSP and their corresponding responses |
| 105 | 3) For debug service |
| 106 | |
| 107 | When calling IOCTL_SEND_CMD_REQ from userspace, command request and response |
| 108 | buffers are initialized and provided in the IOCTL arguments. Where request and |
| 109 | response buffers will be passed as an arguments to the smc_call method. |
| 110 | |
| 111 | The requests are synchronous. The driver will put the process to sleep, |
| 112 | waiting for the completion of the requests using wait_for_completion(). |
| 113 | |
| 114 | This driver uses kmalloc for shared buffer pools which get initialized at driver |
| 115 | initialization. There are three buffers each 20 KB. If any of the buffers fail |
| 116 | to initialize then driver will fail to load. Assumption is the allocated |
| 117 | memory for buffers is contiguous. |
| 118 | |
| 119 | |
| 120 | Design |
| 121 | ====== |
| 122 | |
| 123 | The goal of this driver is to provide a communication API for the userspace |
| 124 | application to execute services in TrustZone as well as TrustZone operating |
| 125 | environment to access services in HLOS. |
| 126 | |
| 127 | Currently TZ->HLOS communication happens from a blocking call to READ_NEXT_CMD |
| 128 | that is initiated from the userspace and on receiving a command request from TZ |
| 129 | service, command is placed on a queue to unblock READ_NEXT_CMD call. This could |
| 130 | have been solved by using a callback, but the practice of invoking callbacks in |
| 131 | userspace from kernel is discouraged. |
| 132 | |
| 133 | Power Management |
| 134 | ================ |
| 135 | |
| 136 | n/a |
| 137 | |
| 138 | SMP/multi-core |
| 139 | ============== |
| 140 | |
| 141 | TZCOM allows multiple services being registered from HLOS and multiple processes |
| 142 | or threads can call IOCTL_READ_NEXT_MSG. These services will block until new |
| 143 | data arrives on the shared buffer (buffer #2 as mentioned in Software |
| 144 | Description). This is achieved using wait queues. |
| 145 | |
| 146 | Security |
| 147 | ======== |
| 148 | |
| 149 | Please refer to Security Channel Manager design document. |
| 150 | |
| 151 | Performance |
| 152 | =========== |
| 153 | |
| 154 | Every scm_call is a context switch between non-trusted and trusted operating |
| 155 | environment. There are no performance related matrix for scm_call available as |
| 156 | of now. |
| 157 | |
| 158 | Interface |
| 159 | ========= |
| 160 | |
| 161 | This driver will have a /dev/tzcom node and following IOCTL calls can be made. |
| 162 | |
| 163 | Userspace API (ioctl calls): |
| 164 | TZCOM_IOCTL_REGISTER_SERVICE_REQ - to register HLOS service |
| 165 | TZCOM_IOCTL_UNREGISTER_SERVICE_REQ - to unregister HLOS service |
| 166 | TZCOM_IOCTL_SEND_CMD_REQ - send a command to a service |
| 167 | TZCOM_IOCTL_READ_NEXT_CMD_REQ - wait for a cmd from TZBSP to use HLOS service |
| 168 | TZCOM_IOCTL_CONTINUE_CMD_REQ - continue the last incomplete cmd on TZBSP |
| 169 | |
| 170 | |
| 171 | Dependencies |
| 172 | ============ |
| 173 | |
| 174 | This driver interacts with Trustzone operating environment, thus depends on |
| 175 | the TZBSP supported architecture. |
| 176 | |
| 177 | |
| 178 | To do |
| 179 | ===== |
| 180 | |
| 181 | TBD |