static int alloc_ion_mem(struct smem_client *client, size_t size, u32 align, u32 flags, int domain, int partition, struct msm_smem *mem) { struct ion_handle *hndl; unsigned long iova = 0; unsigned long buffer_size = 0; unsigned long ionflags = 0; unsigned long heap_mask = 0; int rc = 0; if (flags == SMEM_CACHED) ionflags = ION_SET_CACHED(ionflags); else ionflags = ION_SET_UNCACHED(ionflags); heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID); if (align < 4096) align = 4096; size = (size + 4095) & (~4095); pr_debug("\n in %s domain: %d, Partition: %d\n", __func__, domain, partition); hndl = ion_alloc(client->clnt, size, align, heap_mask, ionflags); if (IS_ERR_OR_NULL(hndl)) { pr_err("Failed to allocate shared memory = %p, %d, %d, 0x%x\n", client, size, align, ionflags); rc = -ENOMEM; goto fail_shared_mem_alloc; } mem->mem_type = client->mem_type; mem->smem_priv = hndl; mem->domain = domain; mem->partition_num = partition; mem->kvaddr = ion_map_kernel(client->clnt, hndl); if (!mem->kvaddr) { pr_err("Failed to map shared mem in kernel\n"); rc = -EIO; goto fail_map; } rc = get_device_address(client->clnt, hndl, mem->domain, mem->partition_num, align, &iova, &buffer_size); if (rc) { pr_err("Failed to get device address: %d\n", rc); goto fail_device_address; } mem->device_addr = iova; pr_debug("device_address = 0x%lx, kvaddr = 0x%p\n", mem->device_addr, mem->kvaddr); mem->size = size; return rc; fail_device_address: ion_unmap_kernel(client->clnt, hndl); fail_map: ion_free(client->clnt, hndl); fail_shared_mem_alloc: return rc; }
static int alloc_ion_mem(struct smem_client *client, size_t size, u32 align, u32 flags, struct msm_smem *mem) { struct ion_handle *hndl; size_t len; unsigned long ionflags = 0; unsigned long heap_mask = 0; int rc = 0; if (size == 0) goto skip_mem_alloc; if (flags == SMEM_CACHED) ionflags = ION_SET_CACHED(ionflags); else ionflags = ION_SET_UNCACHED(ionflags); heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID); hndl = ion_alloc(client->clnt, size, align, heap_mask, ionflags); if (IS_ERR_OR_NULL(hndl)) { pr_err("Failed to allocate shared memory = %p, %d, %d, 0x%x\n", client, size, align, ionflags); rc = -ENOMEM; goto fail_shared_mem_alloc; } mem->mem_type = client->mem_type; mem->smem_priv = hndl; if (ion_phys(client->clnt, hndl, &mem->paddr, &len)) { pr_err("Failed to get physical address\n"); rc = -EIO; goto fail_map; } mem->device_addr = mem->paddr; mem->size = size; mem->kvaddr = ion_map_kernel(client->clnt, hndl); if (!mem->kvaddr) { pr_err("Failed to map shared mem in kernel\n"); rc = -EIO; goto fail_map; } return rc; fail_map: ion_free(client->clnt, hndl); fail_shared_mem_alloc: skip_mem_alloc: return rc; }