call.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Copyright (c) 2015, Linaro Limited
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #include <linux/arm-smccc.h>
  15. #include <linux/device.h>
  16. #include <linux/err.h>
  17. #include <linux/errno.h>
  18. #include <linux/mm.h>
  19. #include <linux/slab.h>
  20. #include <linux/tee_drv.h>
  21. #include <linux/types.h>
  22. #include <linux/uaccess.h>
  23. #include "optee_private.h"
  24. #include "optee_smc.h"
  25. struct optee_call_waiter {
  26. struct list_head list_node;
  27. struct completion c;
  28. };
  29. static void optee_cq_wait_init(struct optee_call_queue *cq,
  30. struct optee_call_waiter *w)
  31. {
  32. /*
  33. * We're preparing to make a call to secure world. In case we can't
  34. * allocate a thread in secure world we'll end up waiting in
  35. * optee_cq_wait_for_completion().
  36. *
  37. * Normally if there's no contention in secure world the call will
  38. * complete and we can cleanup directly with optee_cq_wait_final().
  39. */
  40. mutex_lock(&cq->mutex);
  41. /*
  42. * We add ourselves to the queue, but we don't wait. This
  43. * guarantees that we don't lose a completion if secure world
  44. * returns busy and another thread just exited and try to complete
  45. * someone.
  46. */
  47. init_completion(&w->c);
  48. list_add_tail(&w->list_node, &cq->waiters);
  49. mutex_unlock(&cq->mutex);
  50. }
  51. static void optee_cq_wait_for_completion(struct optee_call_queue *cq,
  52. struct optee_call_waiter *w)
  53. {
  54. wait_for_completion(&w->c);
  55. mutex_lock(&cq->mutex);
  56. /* Move to end of list to get out of the way for other waiters */
  57. list_del(&w->list_node);
  58. reinit_completion(&w->c);
  59. list_add_tail(&w->list_node, &cq->waiters);
  60. mutex_unlock(&cq->mutex);
  61. }
  62. static void optee_cq_complete_one(struct optee_call_queue *cq)
  63. {
  64. struct optee_call_waiter *w;
  65. list_for_each_entry(w, &cq->waiters, list_node) {
  66. if (!completion_done(&w->c)) {
  67. complete(&w->c);
  68. break;
  69. }
  70. }
  71. }
  72. static void optee_cq_wait_final(struct optee_call_queue *cq,
  73. struct optee_call_waiter *w)
  74. {
  75. /*
  76. * We're done with the call to secure world. The thread in secure
  77. * world that was used for this call is now available for some
  78. * other task to use.
  79. */
  80. mutex_lock(&cq->mutex);
  81. /* Get out of the list */
  82. list_del(&w->list_node);
  83. /* Wake up one eventual waiting task */
  84. optee_cq_complete_one(cq);
  85. /*
  86. * If we're completed we've got a completion from another task that
  87. * was just done with its call to secure world. Since yet another
  88. * thread now is available in secure world wake up another eventual
  89. * waiting task.
  90. */
  91. if (completion_done(&w->c))
  92. optee_cq_complete_one(cq);
  93. mutex_unlock(&cq->mutex);
  94. }
  95. /* Requires the filpstate mutex to be held */
  96. static struct optee_session *find_session(struct optee_context_data *ctxdata,
  97. u32 session_id)
  98. {
  99. struct optee_session *sess;
  100. list_for_each_entry(sess, &ctxdata->sess_list, list_node)
  101. if (sess->session_id == session_id)
  102. return sess;
  103. return NULL;
  104. }
  105. /**
  106. * optee_do_call_with_arg() - Do an SMC to OP-TEE in secure world
  107. * @ctx: calling context
  108. * @parg: physical address of message to pass to secure world
  109. *
  110. * Does and SMC to OP-TEE in secure world and handles eventual resulting
  111. * Remote Procedure Calls (RPC) from OP-TEE.
  112. *
  113. * Returns return code from secure world, 0 is OK
  114. */
  115. u32 optee_do_call_with_arg(struct tee_context *ctx, phys_addr_t parg)
  116. {
  117. struct optee *optee = tee_get_drvdata(ctx->teedev);
  118. struct optee_call_waiter w;
  119. struct optee_rpc_param param = { };
  120. struct optee_call_ctx call_ctx = { };
  121. u32 ret;
  122. param.a0 = OPTEE_SMC_CALL_WITH_ARG;
  123. reg_pair_from_64(&param.a1, &param.a2, parg);
  124. /* Initialize waiter */
  125. optee_cq_wait_init(&optee->call_queue, &w);
  126. while (true) {
  127. struct arm_smccc_res res;
  128. optee->invoke_fn(param.a0, param.a1, param.a2, param.a3,
  129. param.a4, param.a5, param.a6, param.a7,
  130. &res);
  131. if (res.a0 == OPTEE_SMC_RETURN_ETHREAD_LIMIT) {
  132. /*
  133. * Out of threads in secure world, wait for a thread
  134. * become available.
  135. */
  136. optee_cq_wait_for_completion(&optee->call_queue, &w);
  137. } else if (OPTEE_SMC_RETURN_IS_RPC(res.a0)) {
  138. param.a0 = res.a0;
  139. param.a1 = res.a1;
  140. param.a2 = res.a2;
  141. param.a3 = res.a3;
  142. optee_handle_rpc(ctx, &param, &call_ctx);
  143. } else {
  144. ret = res.a0;
  145. break;
  146. }
  147. }
  148. optee_rpc_finalize_call(&call_ctx);
  149. /*
  150. * We're done with our thread in secure world, if there's any
  151. * thread waiters wake up one.
  152. */
  153. optee_cq_wait_final(&optee->call_queue, &w);
  154. return ret;
  155. }
  156. static struct tee_shm *get_msg_arg(struct tee_context *ctx, size_t num_params,
  157. struct optee_msg_arg **msg_arg,
  158. phys_addr_t *msg_parg)
  159. {
  160. int rc;
  161. struct tee_shm *shm;
  162. struct optee_msg_arg *ma;
  163. shm = tee_shm_alloc(ctx, OPTEE_MSG_GET_ARG_SIZE(num_params),
  164. TEE_SHM_MAPPED);
  165. if (IS_ERR(shm))
  166. return shm;
  167. ma = tee_shm_get_va(shm, 0);
  168. if (IS_ERR(ma)) {
  169. rc = PTR_ERR(ma);
  170. goto out;
  171. }
  172. rc = tee_shm_get_pa(shm, 0, msg_parg);
  173. if (rc)
  174. goto out;
  175. memset(ma, 0, OPTEE_MSG_GET_ARG_SIZE(num_params));
  176. ma->num_params = num_params;
  177. *msg_arg = ma;
  178. out:
  179. if (rc) {
  180. tee_shm_free(shm);
  181. return ERR_PTR(rc);
  182. }
  183. return shm;
  184. }
  185. int optee_open_session(struct tee_context *ctx,
  186. struct tee_ioctl_open_session_arg *arg,
  187. struct tee_param *param)
  188. {
  189. struct optee_context_data *ctxdata = ctx->data;
  190. int rc;
  191. struct tee_shm *shm;
  192. struct optee_msg_arg *msg_arg;
  193. phys_addr_t msg_parg;
  194. struct optee_session *sess = NULL;
  195. /* +2 for the meta parameters added below */
  196. shm = get_msg_arg(ctx, arg->num_params + 2, &msg_arg, &msg_parg);
  197. if (IS_ERR(shm))
  198. return PTR_ERR(shm);
  199. msg_arg->cmd = OPTEE_MSG_CMD_OPEN_SESSION;
  200. msg_arg->cancel_id = arg->cancel_id;
  201. /*
  202. * Initialize and add the meta parameters needed when opening a
  203. * session.
  204. */
  205. msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT |
  206. OPTEE_MSG_ATTR_META;
  207. msg_arg->params[1].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT |
  208. OPTEE_MSG_ATTR_META;
  209. memcpy(&msg_arg->params[0].u.value, arg->uuid, sizeof(arg->uuid));
  210. memcpy(&msg_arg->params[1].u.value, arg->uuid, sizeof(arg->clnt_uuid));
  211. msg_arg->params[1].u.value.c = arg->clnt_login;
  212. rc = optee_to_msg_param(msg_arg->params + 2, arg->num_params, param);
  213. if (rc)
  214. goto out;
  215. sess = kzalloc(sizeof(*sess), GFP_KERNEL);
  216. if (!sess) {
  217. rc = -ENOMEM;
  218. goto out;
  219. }
  220. if (optee_do_call_with_arg(ctx, msg_parg)) {
  221. msg_arg->ret = TEEC_ERROR_COMMUNICATION;
  222. msg_arg->ret_origin = TEEC_ORIGIN_COMMS;
  223. }
  224. if (msg_arg->ret == TEEC_SUCCESS) {
  225. /* A new session has been created, add it to the list. */
  226. sess->session_id = msg_arg->session;
  227. mutex_lock(&ctxdata->mutex);
  228. list_add(&sess->list_node, &ctxdata->sess_list);
  229. mutex_unlock(&ctxdata->mutex);
  230. } else {
  231. kfree(sess);
  232. }
  233. if (optee_from_msg_param(param, arg->num_params, msg_arg->params + 2)) {
  234. arg->ret = TEEC_ERROR_COMMUNICATION;
  235. arg->ret_origin = TEEC_ORIGIN_COMMS;
  236. /* Close session again to avoid leakage */
  237. optee_close_session(ctx, msg_arg->session);
  238. } else {
  239. arg->session = msg_arg->session;
  240. arg->ret = msg_arg->ret;
  241. arg->ret_origin = msg_arg->ret_origin;
  242. }
  243. out:
  244. tee_shm_free(shm);
  245. return rc;
  246. }
  247. int optee_close_session(struct tee_context *ctx, u32 session)
  248. {
  249. struct optee_context_data *ctxdata = ctx->data;
  250. struct tee_shm *shm;
  251. struct optee_msg_arg *msg_arg;
  252. phys_addr_t msg_parg;
  253. struct optee_session *sess;
  254. /* Check that the session is valid and remove it from the list */
  255. mutex_lock(&ctxdata->mutex);
  256. sess = find_session(ctxdata, session);
  257. if (sess)
  258. list_del(&sess->list_node);
  259. mutex_unlock(&ctxdata->mutex);
  260. if (!sess)
  261. return -EINVAL;
  262. kfree(sess);
  263. shm = get_msg_arg(ctx, 0, &msg_arg, &msg_parg);
  264. if (IS_ERR(shm))
  265. return PTR_ERR(shm);
  266. msg_arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
  267. msg_arg->session = session;
  268. optee_do_call_with_arg(ctx, msg_parg);
  269. tee_shm_free(shm);
  270. return 0;
  271. }
  272. int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
  273. struct tee_param *param)
  274. {
  275. struct optee_context_data *ctxdata = ctx->data;
  276. struct tee_shm *shm;
  277. struct optee_msg_arg *msg_arg;
  278. phys_addr_t msg_parg;
  279. struct optee_session *sess;
  280. int rc;
  281. /* Check that the session is valid */
  282. mutex_lock(&ctxdata->mutex);
  283. sess = find_session(ctxdata, arg->session);
  284. mutex_unlock(&ctxdata->mutex);
  285. if (!sess)
  286. return -EINVAL;
  287. shm = get_msg_arg(ctx, arg->num_params, &msg_arg, &msg_parg);
  288. if (IS_ERR(shm))
  289. return PTR_ERR(shm);
  290. msg_arg->cmd = OPTEE_MSG_CMD_INVOKE_COMMAND;
  291. msg_arg->func = arg->func;
  292. msg_arg->session = arg->session;
  293. msg_arg->cancel_id = arg->cancel_id;
  294. rc = optee_to_msg_param(msg_arg->params, arg->num_params, param);
  295. if (rc)
  296. goto out;
  297. if (optee_do_call_with_arg(ctx, msg_parg)) {
  298. msg_arg->ret = TEEC_ERROR_COMMUNICATION;
  299. msg_arg->ret_origin = TEEC_ORIGIN_COMMS;
  300. }
  301. if (optee_from_msg_param(param, arg->num_params, msg_arg->params)) {
  302. msg_arg->ret = TEEC_ERROR_COMMUNICATION;
  303. msg_arg->ret_origin = TEEC_ORIGIN_COMMS;
  304. }
  305. arg->ret = msg_arg->ret;
  306. arg->ret_origin = msg_arg->ret_origin;
  307. out:
  308. tee_shm_free(shm);
  309. return rc;
  310. }
  311. int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session)
  312. {
  313. struct optee_context_data *ctxdata = ctx->data;
  314. struct tee_shm *shm;
  315. struct optee_msg_arg *msg_arg;
  316. phys_addr_t msg_parg;
  317. struct optee_session *sess;
  318. /* Check that the session is valid */
  319. mutex_lock(&ctxdata->mutex);
  320. sess = find_session(ctxdata, session);
  321. mutex_unlock(&ctxdata->mutex);
  322. if (!sess)
  323. return -EINVAL;
  324. shm = get_msg_arg(ctx, 0, &msg_arg, &msg_parg);
  325. if (IS_ERR(shm))
  326. return PTR_ERR(shm);
  327. msg_arg->cmd = OPTEE_MSG_CMD_CANCEL;
  328. msg_arg->session = session;
  329. msg_arg->cancel_id = cancel_id;
  330. optee_do_call_with_arg(ctx, msg_parg);
  331. tee_shm_free(shm);
  332. return 0;
  333. }
  334. /**
  335. * optee_enable_shm_cache() - Enables caching of some shared memory allocation
  336. * in OP-TEE
  337. * @optee: main service struct
  338. */
  339. void optee_enable_shm_cache(struct optee *optee)
  340. {
  341. struct optee_call_waiter w;
  342. /* We need to retry until secure world isn't busy. */
  343. optee_cq_wait_init(&optee->call_queue, &w);
  344. while (true) {
  345. struct arm_smccc_res res;
  346. optee->invoke_fn(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0,
  347. 0, &res);
  348. if (res.a0 == OPTEE_SMC_RETURN_OK)
  349. break;
  350. optee_cq_wait_for_completion(&optee->call_queue, &w);
  351. }
  352. optee_cq_wait_final(&optee->call_queue, &w);
  353. }
  354. /**
  355. * optee_disable_shm_cache() - Disables caching of some shared memory allocation
  356. * in OP-TEE
  357. * @optee: main service struct
  358. */
  359. void optee_disable_shm_cache(struct optee *optee)
  360. {
  361. struct optee_call_waiter w;
  362. /* We need to retry until secure world isn't busy. */
  363. optee_cq_wait_init(&optee->call_queue, &w);
  364. while (true) {
  365. union {
  366. struct arm_smccc_res smccc;
  367. struct optee_smc_disable_shm_cache_result result;
  368. } res;
  369. optee->invoke_fn(OPTEE_SMC_DISABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0,
  370. 0, &res.smccc);
  371. if (res.result.status == OPTEE_SMC_RETURN_ENOTAVAIL)
  372. break; /* All shm's freed */
  373. if (res.result.status == OPTEE_SMC_RETURN_OK) {
  374. struct tee_shm *shm;
  375. shm = reg_pair_to_ptr(res.result.shm_upper32,
  376. res.result.shm_lower32);
  377. tee_shm_free(shm);
  378. } else {
  379. optee_cq_wait_for_completion(&optee->call_queue, &w);
  380. }
  381. }
  382. optee_cq_wait_final(&optee->call_queue, &w);
  383. }
  384. #define PAGELIST_ENTRIES_PER_PAGE \
  385. ((OPTEE_MSG_NONCONTIG_PAGE_SIZE / sizeof(u64)) - 1)
  386. /**
  387. * optee_fill_pages_list() - write list of user pages to given shared
  388. * buffer.
  389. *
  390. * @dst: page-aligned buffer where list of pages will be stored
  391. * @pages: array of pages that represents shared buffer
  392. * @num_pages: number of entries in @pages
  393. * @page_offset: offset of user buffer from page start
  394. *
  395. * @dst should be big enough to hold list of user page addresses and
  396. * links to the next pages of buffer
  397. */
  398. void optee_fill_pages_list(u64 *dst, struct page **pages, int num_pages,
  399. size_t page_offset)
  400. {
  401. int n = 0;
  402. phys_addr_t optee_page;
  403. /*
  404. * Refer to OPTEE_MSG_ATTR_NONCONTIG description in optee_msg.h
  405. * for details.
  406. */
  407. struct {
  408. u64 pages_list[PAGELIST_ENTRIES_PER_PAGE];
  409. u64 next_page_data;
  410. } *pages_data;
  411. /*
  412. * Currently OP-TEE uses 4k page size and it does not looks
  413. * like this will change in the future. On other hand, there are
  414. * no know ARM architectures with page size < 4k.
  415. * Thus the next built assert looks redundant. But the following
  416. * code heavily relies on this assumption, so it is better be
  417. * safe than sorry.
  418. */
  419. BUILD_BUG_ON(PAGE_SIZE < OPTEE_MSG_NONCONTIG_PAGE_SIZE);
  420. pages_data = (void *)dst;
  421. /*
  422. * If linux page is bigger than 4k, and user buffer offset is
  423. * larger than 4k/8k/12k/etc this will skip first 4k pages,
  424. * because they bear no value data for OP-TEE.
  425. */
  426. optee_page = page_to_phys(*pages) +
  427. round_down(page_offset, OPTEE_MSG_NONCONTIG_PAGE_SIZE);
  428. while (true) {
  429. pages_data->pages_list[n++] = optee_page;
  430. if (n == PAGELIST_ENTRIES_PER_PAGE) {
  431. pages_data->next_page_data =
  432. virt_to_phys(pages_data + 1);
  433. pages_data++;
  434. n = 0;
  435. }
  436. optee_page += OPTEE_MSG_NONCONTIG_PAGE_SIZE;
  437. if (!(optee_page & ~PAGE_MASK)) {
  438. if (!--num_pages)
  439. break;
  440. pages++;
  441. optee_page = page_to_phys(*pages);
  442. }
  443. }
  444. }
  445. /*
  446. * The final entry in each pagelist page is a pointer to the next
  447. * pagelist page.
  448. */
  449. static size_t get_pages_list_size(size_t num_entries)
  450. {
  451. int pages = DIV_ROUND_UP(num_entries, PAGELIST_ENTRIES_PER_PAGE);
  452. return pages * OPTEE_MSG_NONCONTIG_PAGE_SIZE;
  453. }
  454. u64 *optee_allocate_pages_list(size_t num_entries)
  455. {
  456. return alloc_pages_exact(get_pages_list_size(num_entries), GFP_KERNEL);
  457. }
  458. void optee_free_pages_list(void *list, size_t num_entries)
  459. {
  460. free_pages_exact(list, get_pages_list_size(num_entries));
  461. }
  462. static bool is_normal_memory(pgprot_t p)
  463. {
  464. #if defined(CONFIG_ARM)
  465. return (pgprot_val(p) & L_PTE_MT_MASK) == L_PTE_MT_WRITEALLOC;
  466. #elif defined(CONFIG_ARM64)
  467. return (pgprot_val(p) & PTE_ATTRINDX_MASK) == PTE_ATTRINDX(MT_NORMAL);
  468. #else
  469. #error "Unuspported architecture"
  470. #endif
  471. }
  472. static int __check_mem_type(struct vm_area_struct *vma, unsigned long end)
  473. {
  474. while (vma && is_normal_memory(vma->vm_page_prot)) {
  475. if (vma->vm_end >= end)
  476. return 0;
  477. vma = vma->vm_next;
  478. }
  479. return -EINVAL;
  480. }
  481. static int check_mem_type(unsigned long start, size_t num_pages)
  482. {
  483. struct mm_struct *mm = current->mm;
  484. int rc;
  485. down_read(&mm->mmap_sem);
  486. rc = __check_mem_type(find_vma(mm, start),
  487. start + num_pages * PAGE_SIZE);
  488. up_read(&mm->mmap_sem);
  489. return rc;
  490. }
  491. int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm,
  492. struct page **pages, size_t num_pages,
  493. unsigned long start)
  494. {
  495. struct tee_shm *shm_arg = NULL;
  496. struct optee_msg_arg *msg_arg;
  497. u64 *pages_list;
  498. phys_addr_t msg_parg;
  499. int rc;
  500. if (!num_pages)
  501. return -EINVAL;
  502. rc = check_mem_type(start, num_pages);
  503. if (rc)
  504. return rc;
  505. pages_list = optee_allocate_pages_list(num_pages);
  506. if (!pages_list)
  507. return -ENOMEM;
  508. shm_arg = get_msg_arg(ctx, 1, &msg_arg, &msg_parg);
  509. if (IS_ERR(shm_arg)) {
  510. rc = PTR_ERR(shm_arg);
  511. goto out;
  512. }
  513. optee_fill_pages_list(pages_list, pages, num_pages,
  514. tee_shm_get_page_offset(shm));
  515. msg_arg->cmd = OPTEE_MSG_CMD_REGISTER_SHM;
  516. msg_arg->params->attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
  517. OPTEE_MSG_ATTR_NONCONTIG;
  518. msg_arg->params->u.tmem.shm_ref = (unsigned long)shm;
  519. msg_arg->params->u.tmem.size = tee_shm_get_size(shm);
  520. /*
  521. * In the least bits of msg_arg->params->u.tmem.buf_ptr we
  522. * store buffer offset from 4k page, as described in OP-TEE ABI.
  523. */
  524. msg_arg->params->u.tmem.buf_ptr = virt_to_phys(pages_list) |
  525. (tee_shm_get_page_offset(shm) & (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1));
  526. if (optee_do_call_with_arg(ctx, msg_parg) ||
  527. msg_arg->ret != TEEC_SUCCESS)
  528. rc = -EINVAL;
  529. tee_shm_free(shm_arg);
  530. out:
  531. optee_free_pages_list(pages_list, num_pages);
  532. return rc;
  533. }
  534. int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm)
  535. {
  536. struct tee_shm *shm_arg;
  537. struct optee_msg_arg *msg_arg;
  538. phys_addr_t msg_parg;
  539. int rc = 0;
  540. shm_arg = get_msg_arg(ctx, 1, &msg_arg, &msg_parg);
  541. if (IS_ERR(shm_arg))
  542. return PTR_ERR(shm_arg);
  543. msg_arg->cmd = OPTEE_MSG_CMD_UNREGISTER_SHM;
  544. msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT;
  545. msg_arg->params[0].u.rmem.shm_ref = (unsigned long)shm;
  546. if (optee_do_call_with_arg(ctx, msg_parg) ||
  547. msg_arg->ret != TEEC_SUCCESS)
  548. rc = -EINVAL;
  549. tee_shm_free(shm_arg);
  550. return rc;
  551. }
  552. int optee_shm_register_supp(struct tee_context *ctx, struct tee_shm *shm,
  553. struct page **pages, size_t num_pages,
  554. unsigned long start)
  555. {
  556. /*
  557. * We don't want to register supplicant memory in OP-TEE.
  558. * Instead information about it will be passed in RPC code.
  559. */
  560. return check_mem_type(start, num_pages);
  561. }
  562. int optee_shm_unregister_supp(struct tee_context *ctx, struct tee_shm *shm)
  563. {
  564. return 0;
  565. }