Fallback to dma_alloc_coherent if shmbridge is disabled

If shmbridge is not enabled, allocate memory through
dma_alloc_coherent instead of shmbridge pool. This will make the
clients independent of whether shmbridge is enabled or
disabled.

Change-Id: I293872a2e57dec77d660de1bd857a425d4888a5b
Signed-off-by: Anmolpreet Kaur <anmolpre@codeaurora.org>
This commit is contained in:
Anmolpreet Kaur 2020-12-18 19:42:20 +05:30
commit c9a383d796

View file

@ -280,6 +280,30 @@ int32_t qtee_shmbridge_allocate_shm(size_t size, struct qtee_shm *shm)
int32_t ret = 0;
unsigned long va;
if (IS_ERR_OR_NULL(shm)) {
pr_err("qtee_shm is NULL\n");
ret = -EINVAL;
goto exit;
}
if (!qtee_shmbridge_is_enabled()) {
void *buf = NULL;
dma_addr_t coh_pmem;
pr_err("shmbridge is not enabled, allocating via dma_aloc\n");
size = (size + PAGE_SIZE) & PAGE_MASK;
buf = dma_alloc_coherent(default_bridge.dev, size, &coh_pmem, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
shm->vaddr = buf;
shm->paddr = coh_pmem;
shm->size = size;
goto exit;
}
if (size > DEFAULT_BRIDGE_SIZE) {
pr_err("requestd size %zu is larger than bridge size %d\n",
size, DEFAULT_BRIDGE_SIZE);
@ -287,11 +311,6 @@ int32_t qtee_shmbridge_allocate_shm(size_t size, struct qtee_shm *shm)
goto exit;
}
if (IS_ERR_OR_NULL(shm)) {
pr_err("qtee_shm is NULL\n");
ret = -EINVAL;
goto exit;
}
size = roundup(size, 1 << default_bridge.min_alloc_order);
va = gen_pool_alloc(default_bridge.genpool, size);
@ -320,14 +339,19 @@ void qtee_shmbridge_free_shm(struct qtee_shm *shm)
{
if (IS_ERR_OR_NULL(shm) || !shm->vaddr)
return;
gen_pool_free(default_bridge.genpool, (unsigned long)shm->vaddr,
shm->size);
if (!qtee_shmbridge_is_enabled())
dma_free_coherent(default_bridge.dev, shm->size, shm->vaddr, shm->paddr);
else
gen_pool_free(default_bridge.genpool, (unsigned long)shm->vaddr,
shm->size);
}
EXPORT_SYMBOL(qtee_shmbridge_free_shm);
/* cache clean operation for buffer sub-allocated from default bridge */
void qtee_shmbridge_flush_shm_buf(struct qtee_shm *shm)
{
if (!qtee_shmbridge_is_enabled())
return;
if (shm)
return dma_sync_single_for_device(default_bridge.dev,
shm->paddr, shm->size, DMA_TO_DEVICE);
@ -337,6 +361,8 @@ EXPORT_SYMBOL(qtee_shmbridge_flush_shm_buf);
/* cache invalidation operation for buffer sub-allocated from default bridge */
void qtee_shmbridge_inv_shm_buf(struct qtee_shm *shm)
{
if (!qtee_shmbridge_is_enabled())
return;
if (shm)
return dma_sync_single_for_cpu(default_bridge.dev,
shm->paddr, shm->size, DMA_FROM_DEVICE);