|
28 | 28 | #include <linux/uaccess.h>
|
29 | 29 | #include "optee_private.h"
|
30 | 30 | #include "optee_smc.h"
|
| 31 | +#include "shm_pool.h" |
31 | 32 |
|
32 | 33 | #define DRIVER_NAME "optee"
|
33 | 34 |
|
@@ -219,6 +220,10 @@ static void optee_get_version(struct tee_device *teedev,
|
219 | 220 | .impl_caps = TEE_OPTEE_CAP_TZ,
|
220 | 221 | .gen_caps = TEE_GEN_CAP_GP,
|
221 | 222 | };
|
| 223 | + struct optee *optee = tee_get_drvdata(teedev); |
| 224 | + |
| 225 | + if (optee->sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) |
| 226 | + v.gen_caps |= TEE_GEN_CAP_REG_MEM; |
222 | 227 | *vers = v;
|
223 | 228 | }
|
224 | 229 |
|
@@ -397,21 +402,22 @@ static bool optee_msg_exchange_capabilities(optee_invoke_fn *invoke_fn,
|
397 | 402 | }
|
398 | 403 |
|
399 | 404 | static struct tee_shm_pool *
|
400 |
| -optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm) |
| 405 | +optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm, |
| 406 | + u32 sec_caps) |
401 | 407 | {
|
402 | 408 | union {
|
403 | 409 | struct arm_smccc_res smccc;
|
404 | 410 | struct optee_smc_get_shm_config_result result;
|
405 | 411 | } res;
|
406 |
| - struct tee_shm_pool *pool; |
407 | 412 | unsigned long vaddr;
|
408 | 413 | phys_addr_t paddr;
|
409 | 414 | size_t size;
|
410 | 415 | phys_addr_t begin;
|
411 | 416 | phys_addr_t end;
|
412 | 417 | void *va;
|
413 |
| - struct tee_shm_pool_mem_info priv_info; |
414 |
| - struct tee_shm_pool_mem_info dmabuf_info; |
| 418 | + struct tee_shm_pool_mgr *priv_mgr; |
| 419 | + struct tee_shm_pool_mgr *dmabuf_mgr; |
| 420 | + void *rc; |
415 | 421 |
|
416 | 422 | invoke_fn(OPTEE_SMC_GET_SHM_CONFIG, 0, 0, 0, 0, 0, 0, 0, &res.smccc);
|
417 | 423 | if (res.result.status != OPTEE_SMC_RETURN_OK) {
|
@@ -441,22 +447,49 @@ optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm)
|
441 | 447 | }
|
442 | 448 | vaddr = (unsigned long)va;
|
443 | 449 |
|
444 |
| - priv_info.vaddr = vaddr; |
445 |
| - priv_info.paddr = paddr; |
446 |
| - priv_info.size = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; |
447 |
| - dmabuf_info.vaddr = vaddr + OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; |
448 |
| - dmabuf_info.paddr = paddr + OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; |
449 |
| - dmabuf_info.size = size - OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; |
450 |
| - |
451 |
| - pool = tee_shm_pool_alloc_res_mem(&priv_info, &dmabuf_info); |
452 |
| - if (IS_ERR(pool)) { |
453 |
| - memunmap(va); |
454 |
| - goto out; |
| 450 | + /* |
| 451 | + * If OP-TEE can work with unregistered SHM, we will use own pool |
| 452 | + * for private shm |
| 453 | + */ |
| 454 | + if (sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) { |
| 455 | + rc = optee_shm_pool_alloc_pages(); |
| 456 | + if (IS_ERR(rc)) |
| 457 | + goto err_memunmap; |
| 458 | + priv_mgr = rc; |
| 459 | + } else { |
| 460 | + const size_t sz = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; |
| 461 | + |
| 462 | + rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, sz, |
| 463 | + 3 /* 8 bytes aligned */); |
| 464 | + if (IS_ERR(rc)) |
| 465 | + goto err_memunmap; |
| 466 | + priv_mgr = rc; |
| 467 | + |
| 468 | + vaddr += sz; |
| 469 | + paddr += sz; |
| 470 | + size -= sz; |
455 | 471 | }
|
456 | 472 |
|
| 473 | + rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, size, PAGE_SHIFT); |
| 474 | + if (IS_ERR(rc)) |
| 475 | + goto err_free_priv_mgr; |
| 476 | + dmabuf_mgr = rc; |
| 477 | + |
| 478 | + rc = tee_shm_pool_alloc(priv_mgr, dmabuf_mgr); |
| 479 | + if (IS_ERR(rc)) |
| 480 | + goto err_free_dmabuf_mgr; |
| 481 | + |
457 | 482 | *memremaped_shm = va;
|
458 |
| -out: |
459 |
| - return pool; |
| 483 | + |
| 484 | + return rc; |
| 485 | + |
| 486 | +err_free_dmabuf_mgr: |
| 487 | + tee_shm_pool_mgr_destroy(dmabuf_mgr); |
| 488 | +err_free_priv_mgr: |
| 489 | + tee_shm_pool_mgr_destroy(priv_mgr); |
| 490 | +err_memunmap: |
| 491 | + memunmap(va); |
| 492 | + return rc; |
460 | 493 | }
|
461 | 494 |
|
462 | 495 | /* Simple wrapper functions to be able to use a function pointer */
|
@@ -534,7 +567,7 @@ static struct optee *optee_probe(struct device_node *np)
|
534 | 567 | if (!(sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM))
|
535 | 568 | return ERR_PTR(-EINVAL);
|
536 | 569 |
|
537 |
| - pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm); |
| 570 | + pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm, sec_caps); |
538 | 571 | if (IS_ERR(pool))
|
539 | 572 | return (void *)pool;
|
540 | 573 |
|
|
0 commit comments