Lines Matching refs:tee

25 static int tee_alloc_ring(struct psp_tee_device *tee, int ring_size)  in tee_alloc_ring()  argument
27 struct ring_buf_manager *rb_mgr = &tee->rb_mgr; in tee_alloc_ring()
49 static void tee_free_ring(struct psp_tee_device *tee) in tee_free_ring() argument
51 struct ring_buf_manager *rb_mgr = &tee->rb_mgr; in tee_free_ring()
66 struct tee_init_ring_cmd *tee_alloc_cmd_buffer(struct psp_tee_device *tee) in tee_alloc_cmd_buffer() argument
74 cmd->hi_addr = upper_32_bits(tee->rb_mgr.ring_pa); in tee_alloc_cmd_buffer()
75 cmd->low_addr = lower_32_bits(tee->rb_mgr.ring_pa); in tee_alloc_cmd_buffer()
76 cmd->size = tee->rb_mgr.ring_size; in tee_alloc_cmd_buffer()
78 dev_dbg(tee->dev, "tee: ring address: high = 0x%x low = 0x%x size = %u\n", in tee_alloc_cmd_buffer()
89 static int tee_init_ring(struct psp_tee_device *tee) in tee_init_ring() argument
98 ret = tee_alloc_ring(tee, ring_size); in tee_init_ring()
100 dev_err(tee->dev, "tee: ring allocation failed %d\n", ret); in tee_init_ring()
104 tee->rb_mgr.wptr = 0; in tee_init_ring()
106 cmd = tee_alloc_cmd_buffer(tee); in tee_init_ring()
108 tee_free_ring(tee); in tee_init_ring()
115 ret = psp_mailbox_command(tee->psp, PSP_CMD_TEE_RING_INIT, cmd, in tee_init_ring()
118 dev_err(tee->dev, "tee: ring init command timed out, disabling TEE support\n"); in tee_init_ring()
119 tee_free_ring(tee); in tee_init_ring()
125 dev_err(tee->dev, "tee: ring init command failed (%#010lx)\n", in tee_init_ring()
127 tee_free_ring(tee); in tee_init_ring()
137 static void tee_destroy_ring(struct psp_tee_device *tee) in tee_destroy_ring() argument
142 if (!tee->rb_mgr.ring_start) in tee_destroy_ring()
148 ret = psp_mailbox_command(tee->psp, PSP_CMD_TEE_RING_DESTROY, NULL, in tee_destroy_ring()
151 dev_err(tee->dev, "tee: ring destroy command timed out, disabling TEE support\n"); in tee_destroy_ring()
154 dev_err(tee->dev, "tee: ring destroy command failed (%#010lx)\n", in tee_destroy_ring()
159 tee_free_ring(tee); in tee_destroy_ring()
165 struct psp_tee_device *tee; in tee_dev_init() local
169 tee = devm_kzalloc(dev, sizeof(*tee), GFP_KERNEL); in tee_dev_init()
170 if (!tee) in tee_dev_init()
173 psp->tee_data = tee; in tee_dev_init()
175 tee->dev = dev; in tee_dev_init()
176 tee->psp = psp; in tee_dev_init()
178 tee->io_regs = psp->io_regs; in tee_dev_init()
180 tee->vdata = (struct tee_vdata *)psp->vdata->tee; in tee_dev_init()
181 if (!tee->vdata) { in tee_dev_init()
187 ret = tee_init_ring(tee); in tee_dev_init()
207 struct psp_tee_device *tee = psp->tee_data; in tee_dev_destroy() local
209 if (!tee) in tee_dev_destroy()
212 tee_destroy_ring(tee); in tee_dev_destroy()
215 static int tee_submit_cmd(struct psp_tee_device *tee, enum tee_cmd_id cmd_id, in tee_submit_cmd() argument
224 mutex_lock(&tee->rb_mgr.mutex); in tee_submit_cmd()
230 (tee->rb_mgr.ring_start + tee->rb_mgr.wptr); in tee_submit_cmd()
232 rptr = ioread32(tee->io_regs + tee->vdata->ring_rptr_reg); in tee_submit_cmd()
237 if (!(tee->rb_mgr.wptr + sizeof(struct tee_ring_cmd) == rptr || in tee_submit_cmd()
241 dev_dbg(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", in tee_submit_cmd()
242 rptr, tee->rb_mgr.wptr); in tee_submit_cmd()
245 mutex_unlock(&tee->rb_mgr.mutex); in tee_submit_cmd()
247 mutex_lock(&tee->rb_mgr.mutex); in tee_submit_cmd()
252 (tee->rb_mgr.wptr + sizeof(struct tee_ring_cmd) == rptr || in tee_submit_cmd()
254 dev_err(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u response flag %u\n", in tee_submit_cmd()
255 rptr, tee->rb_mgr.wptr, cmd->flag); in tee_submit_cmd()
278 tee->rb_mgr.wptr += sizeof(struct tee_ring_cmd); in tee_submit_cmd()
279 if (tee->rb_mgr.wptr >= tee->rb_mgr.ring_size) in tee_submit_cmd()
280 tee->rb_mgr.wptr = 0; in tee_submit_cmd()
283 iowrite32(tee->rb_mgr.wptr, tee->io_regs + tee->vdata->ring_wptr_reg); in tee_submit_cmd()
291 mutex_unlock(&tee->rb_mgr.mutex); in tee_submit_cmd()
296 static int tee_wait_cmd_completion(struct psp_tee_device *tee, in tee_wait_cmd_completion() argument
310 dev_err(tee->dev, "tee: command 0x%x timed out, disabling PSP\n", in tee_wait_cmd_completion()
322 struct psp_tee_device *tee; in psp_tee_process_cmd() local
337 tee = psp->tee_data; in psp_tee_process_cmd()
339 ret = tee_submit_cmd(tee, cmd_id, buf, len, &resp); in psp_tee_process_cmd()
343 ret = tee_wait_cmd_completion(tee, resp, TEE_DEFAULT_RING_TIMEOUT); in psp_tee_process_cmd()