static int alloc_gathers(struct nvhost_job *job, int num_cmdbufs) { int err = 0; job->gather_mem = NULL; job->gathers = NULL; job->gather_mem_size = 0; if (num_cmdbufs) { /* Allocate memory */ job->gather_mem = nvmap_alloc(job->nvmap, gather_size(num_cmdbufs), 32, NVMAP_HANDLE_CACHEABLE, 0); if (IS_ERR_OR_NULL(job->gather_mem)) { err = PTR_ERR(job->gather_mem); if (!job->gather_mem) err = -ENOMEM; job->gather_mem = NULL; goto error; } job->gather_mem_size = gather_size(num_cmdbufs); /* Map memory to kernel */ job->gathers = nvmap_mmap(job->gather_mem); if (IS_ERR_OR_NULL(job->gathers)) { err = PTR_ERR(job->gathers); if (!job->gathers) err = -ENOMEM; job->gathers = NULL; goto error; } } return 0; error: free_gathers(job); return err; }
static int realloc_gathers(struct nvhost_job *oldjob, struct nvhost_job *newjob, int num_cmdbufs) { int err = 0; /* Check if we can reuse gather buffer */ if (oldjob->gather_mem_size < gather_size(num_cmdbufs) || oldjob->nvmap != newjob->nvmap) { free_gathers(oldjob); err = alloc_gathers(newjob, num_cmdbufs); } else { newjob->gather_mem = oldjob->gather_mem; newjob->gathers = oldjob->gathers; newjob->gather_mem_size = oldjob->gather_mem_size; oldjob->gather_mem = NULL; oldjob->gathers = NULL; oldjob->gather_mem_size = 0; } return err; }