return NULL;
}
vfree(pages);
- gdc_log(LOG_INFO, "[HIGH-MEM-MAP] pa(%lx) to va(%p), size: %d\n",
+ gdc_log(LOG_DEBUG, "[HIGH-MEM-MAP] pa(%lx) to va(%p), size: %d\n",
(unsigned long)phys, vaddr, npages << PAGE_SHIFT);
return vaddr;
}
void *vaddr = (void *)(PAGE_MASK & (ulong)buf->vaddr);
if (!atomic_dec_and_test(&buf->refcount)) {
- gdc_log(LOG_INFO, "gdc aml_dma_put, refcont=%d\n",
+ gdc_log(LOG_DEBUG, "gdc aml_dma_put, refcont=%d\n",
atomic_read(&buf->refcount));
return;
}
buf->vaddr = NULL;
clear_dma_buffer((struct aml_dma_buffer *)buf->priv, buf->index);
put_device(buf->dev);
- kfree(buf);
- gdc_log(LOG_INFO, "gdc free:aml_dma_buf=0x%p,buf->index=%d\n",
+
+ gdc_log(LOG_DEBUG, "gdc free:aml_dma_buf=0x%p,buf->index=%d\n",
buf, buf->index);
+ kfree(buf);
}
static void *aml_dma_alloc(struct device *dev, unsigned long attrs,
if (cma_pages) {
paddr = page_to_phys(cma_pages);
} else {
+ kfree(buf);
pr_err("failed to alloc cma pages.\n");
return NULL;
}
buf->dma_dir = dma_dir;
buf->dma_addr = paddr;
atomic_inc(&buf->refcount);
- gdc_log(LOG_INFO, "aml_dma_buf=0x%p, refcont=%d\n",
+ gdc_log(LOG_DEBUG, "aml_dma_buf=0x%p, refcont=%d\n",
buf, atomic_read(&buf->refcount));
return buf;
{
struct aml_dma_buf *buf = buf_priv;
unsigned long pfn = 0;
- unsigned long vsize = vma->vm_end - vma->vm_start;
+ unsigned long vsize;
int ret = -1;
if (!buf || !vma) {
return -EINVAL;
}
+ vsize = vma->vm_end - vma->vm_start;
+
pfn = buf->dma_addr >> PAGE_SHIFT;
ret = remap_pfn_range(vma, vma->vm_start, pfn,
vsize, vma->vm_page_prot);
}
vma->vm_flags |= VM_DONTEXPAND;
- gdc_log(LOG_INFO, "mapped dma addr 0x%08lx at 0x%08lx, size %d\n",
+ gdc_log(LOG_DEBUG, "mapped dma addr 0x%08lx at 0x%08lx, size %d\n",
(unsigned long)buf->dma_addr, vma->vm_start,
buf->size);
return 0;
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
struct page *page = phys_to_page(phys);
- if (!page) {
- sg_free_table(sgt);
- kfree(attach);
- return -ENOMEM;
- }
sg_set_page(sg, page, PAGE_SIZE, 0);
phys += PAGE_SIZE;
}
/* dmabuf keeps reference to vb2 buffer */
atomic_inc(&buf->refcount);
- gdc_log(LOG_INFO, "get_dmabuf, refcount=%d\n",
+ gdc_log(LOG_DEBUG, "get_dmabuf, refcount=%d\n",
atomic_read(&buf->refcount));
return dbuf;
if (buffer->gd_buffer[i].alloc)
continue;
else {
- gdc_log(LOG_INFO, "find_empty_dma_buffer i=%d\n", i);
+ gdc_log(LOG_DEBUG, "find_empty_dma_buffer i=%d\n", i);
found = 1;
break;
}
dma_buf_put(dbuf);
return ret;
}
- gdc_log(LOG_INFO, "buffer %d,exported as %d descriptor\n",
+ gdc_log(LOG_DEBUG, "buffer %d,exported as %d descriptor\n",
index, ret);
buffer->gd_buffer[index].fd = ret;
buffer->gd_buffer[index].dbuf = dbuf;
cfg->attach = d_att;
cfg->vaddr = vaddr;
cfg->sg = sg;
- gdc_log(LOG_INFO, "gdc_dma_buffer_map, dbuf=0x%p\n", dbuf);
+ gdc_log(LOG_DEBUG, "gdc_dma_buffer_map, dbuf=0x%p\n", dbuf);
return ret;
}
ret = gdc_dma_buffer_get_phys_internal(buffer, cfg, addr);
if (ret < 0) {
- gdc_log(LOG_INFO, "get_phys(fd=%d) failed.\n", cfg->fd);
+ gdc_log(LOG_DEBUG, "get_phys(fd=%d) failed.\n", cfg->fd);
ret = gdc_dma_buffer_map(cfg);
if (ret < 0) {
pr_err("gdc_dma_buffer_map failed\n");
dma_buf_detach(dbuf, d_att);
dma_buf_put(dbuf);
- gdc_log(LOG_INFO, "gdc_dma_buffer_unmap, dbuf=0x%p\n", dbuf);
+ gdc_log(LOG_DEBUG, "gdc_dma_buffer_unmap, dbuf=0x%p\n", dbuf);
}
void gdc_dma_buffer_dma_flush(struct device *dev, int fd)
struct dma_buf *dmabuf;
struct aml_dma_buf *buf;
- gdc_log(LOG_INFO, "gdc_dma_buffer_dma_flush fd=%d\n", fd);
+ gdc_log(LOG_DEBUG, "gdc_dma_buffer_dma_flush fd=%d\n", fd);
dmabuf = dma_buf_get(fd);
if (IS_ERR(dmabuf)) {
pr_err("dma_buf_get failed\n");
struct dma_buf *dmabuf;
struct aml_dma_buf *buf;
- gdc_log(LOG_INFO, "gdc_dma_buffer_cache_flush fd=%d\n", fd);
+ gdc_log(LOG_DEBUG, "gdc_dma_buffer_cache_flush fd=%d\n", fd);
dmabuf = dma_buf_get(fd);
if (IS_ERR(dmabuf)) {
pr_err("dma_buf_get failed\n");
#include "gdc_dmabuf.h"
#include "gdc_wq.h"
-unsigned int gdc_log_level;
+int gdc_log_level;
struct gdc_manager_s gdc_manager;
unsigned int gdc_reg_store_mode;
int trace_mode_enable;
return gdc_dma_buffer_get_phys(gdc_manager.buffer, cfg, addr);
}
-static int gdc_buffer_unmap(struct aml_dma_cfg *cfg)
-{
- return gdc_dma_buffer_unmap_info(gdc_manager.buffer, cfg);
-}
-
static int gdc_get_buffer_fd(int plane_id, struct gdc_buffer_info *buf_info)
{
int fd;
ret = meson_gdc_set_input_addr(addr, gdc_cmd);
if (ret != 0) {
gdc_log(LOG_ERR, "set input addr err\n");
- return -EINVAL;
+ goto dma_buf_unmap;
}
} else {
size = gdc_set_input_addr(i, addr, gdc_cmd);
if (size < 0) {
gdc_log(LOG_ERR, "set input addr err\n");
- return -EINVAL;
+ goto dma_buf_unmap;
}
}
- gdc_log(LOG_INFO, "plane[%d] get input addr=%lx\n",
+ gdc_log(LOG_DEBUG, "plane[%d] get input addr=%lx\n",
i, addr);
if (plane_number == 1) {
size = gdc_get_input_size(gdc_cmd);
if (size < 0) {
gdc_log(LOG_ERR, "set input addr err\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto dma_buf_unmap;
}
}
meson_gdc_dma_flush(&gdc_manager.gdc_dev->pdev->dev,
addr, size);
}
return 0;
+
+dma_buf_unmap:
+ while (i >= 0) {
+ cfg = &context->dma_cfg.input_cfg[i].dma_cfg;
+ gdc_dma_buffer_unmap(cfg);
+ context->dma_cfg.input_cfg[i].dma_used = 0;
+ i--;
+ }
+ return ret;
}
static long gdc_process_input_ion_info(struct gdc_context_s *context,
}
}
- gdc_log(LOG_INFO, "plane[%d] get input addr=%lx\n",
+ gdc_log(LOG_DEBUG, "plane[%d] get input addr=%lx\n",
i, addr);
}
return 0;
ret = gdc_set_output_addr(i, addr, gdc_cmd);
if (ret < 0) {
gdc_log(LOG_ERR, "set input addr err\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto dma_buf_unmap;
}
}
- gdc_log(LOG_INFO, "plane[%d] get output addr=%lx\n",
+ gdc_log(LOG_DEBUG, "plane[%d] get output addr=%lx\n",
i, addr);
}
+
return 0;
+
+dma_buf_unmap:
+ while (i >= 0) {
+ cfg = &context->dma_cfg.output_cfg[i].dma_cfg;
+ gdc_dma_buffer_unmap(cfg);
+ context->dma_cfg.output_cfg[i].dma_used = 0;
+ i--;
+ }
+
+ return ret;
+
}
static long gdc_process_output_ion_info(struct gdc_context_s *context,
return -EINVAL;
}
}
- gdc_log(LOG_INFO, "plane[%d] get output addr=%lx\n",
+ gdc_log(LOG_DEBUG, "plane[%d] get output addr=%lx\n",
i, addr);
}
return 0;
size_t len;
struct aml_dma_cfg *cfg = NULL;
struct gdc_cmd_s *gdc_cmd = &context->cmd;
- struct gdc_queue_item_s *pitem;
+ struct gdc_queue_item_s *pitem = NULL;
int i;
if (context == NULL || gs_ex == NULL) {
if (gs_ex->output_buffer.mem_alloc_type == AML_GDC_MEM_ION) {
ret = gdc_process_output_ion_info(context, gs_ex);
if (ret < 0) {
- mutex_unlock(&context->d_mutext);
- return -EINVAL;
+ ret = -EINVAL;
+ goto unlock_return;
}
} else if (gs_ex->output_buffer.mem_alloc_type == AML_GDC_MEM_DMABUF) {
ret = gdc_process_output_dma_info(context, gs_ex);
if (ret < 0) {
ret = -EINVAL;
- goto unmap;
+ goto unlock_return;
}
}
gdc_cmd->base_gdc = 0;
gdc_log(LOG_ERR, "ion import config fd %d failed\n",
gs_ex->config_buffer.shared_fd);
ret = -EINVAL;
- goto unmap;
+ goto unlock_return;
}
} else if (gs_ex->config_buffer.mem_alloc_type == AML_GDC_MEM_DMABUF) {
/* dma alloc */
gdc_log(LOG_ERR, "dma import config fd %d failed\n",
gs_ex->config_buffer.shared_fd);
ret = -EINVAL;
- goto unmap;
+ goto unlock_return;
}
}
gdc_cmd->gdc_config.config_addr = addr;
- gdc_log(LOG_INFO, "%s, config addr=%lx\n", __func__, addr);
+ gdc_log(LOG_DEBUG, "%s, config addr=%lx\n", __func__, addr);
if (gs_ex->input_buffer.mem_alloc_type == AML_GDC_MEM_ION) {
/* ion alloc */
ret = gdc_process_input_ion_info(context, gs_ex);
if (ret < 0) {
ret = -EINVAL;
- goto unmap;
+ goto unlock_return;
}
} else if (gs_ex->input_buffer.mem_alloc_type == AML_GDC_MEM_DMABUF) {
/* dma alloc */
ret = gdc_process_input_dma_info(context, gs_ex);
if (ret < 0) {
ret = -EINVAL;
- goto unmap;
+ goto unlock_return;
}
}
gdc_cmd->outplane = gs_ex->output_buffer.plane_number;
if (pitem == NULL) {
gdc_log(LOG_ERR, "get item error\n");
ret = -ENOMEM;
- goto unmap;
+ goto unlock_return;
}
mutex_unlock(&context->d_mutext);
if (gs_ex->config_buffer.mem_alloc_type == AML_GDC_MEM_DMABUF)
gdc_wq_add_work(context, pitem);
return 0;
-unmap:
- /* if dma buf detach it */
- for (i = 0; i < MAX_PLANE; i++) {
- if (pitem->dma_cfg.input_cfg[i].dma_used) {
- gdc_buffer_unmap
- (&pitem->dma_cfg.input_cfg[i].dma_cfg);
- pitem->dma_cfg.input_cfg[i].dma_used = 0;
- }
- if (pitem->dma_cfg.output_cfg[i].dma_used) {
- gdc_buffer_unmap
- (&pitem->dma_cfg.output_cfg[i].dma_cfg);
- pitem->dma_cfg.output_cfg[i].dma_used = 0;
- }
- }
- if (pitem->dma_cfg.config_cfg.dma_used) {
- gdc_buffer_unmap
- (&pitem->dma_cfg.config_cfg.dma_cfg);
- pitem->dma_cfg.config_cfg.dma_used = 0;
- }
+
+unlock_return:
mutex_unlock(&context->d_mutext);
return ret;
}
long ret = -1;
struct gdc_cmd_s *gdc_cmd = &context->cmd;
char *fw_name = NULL;
- struct gdc_queue_item_s *pitem;
- int i;
+ struct gdc_queue_item_s *pitem = NULL;
if (context == NULL || gs_with_fw == NULL) {
gdc_log(LOG_ERR, "Error input param\n");
(struct gdc_settings_ex *)gs_with_fw);
if (ret < 0) {
ret = -EINVAL;
- goto unmap;
+ goto release_fw_name;
}
} else if (gs_with_fw->input_buffer.mem_alloc_type ==
AML_GDC_MEM_DMABUF) {
/* dma alloc */
+ ret =
gdc_process_input_dma_info(context,
- (struct gdc_settings_ex *)gs_with_fw);
+ (struct gdc_settings_ex *)
+ gs_with_fw);
+ if (ret < 0) {
+ ret = -EINVAL;
+ goto release_fw_name;
+ }
}
gdc_cmd->outplane = gs_with_fw->output_buffer.plane_number;
release_config_firmware(gs_with_fw);
kfree(fw_name);
return 0;
+
release_fw:
release_config_firmware(gs_with_fw);
-unmap:
- /* if dma buf detach it */
- for (i = 0; i < MAX_PLANE; i++) {
- if (pitem->dma_cfg.input_cfg[i].dma_used) {
- gdc_dma_buffer_unmap
- (&pitem->dma_cfg.input_cfg[i].dma_cfg);
- pitem->dma_cfg.input_cfg[i].dma_used = 0;
- }
- if (pitem->dma_cfg.output_cfg[i].dma_used) {
- gdc_dma_buffer_unmap
- (&pitem->dma_cfg.output_cfg[i].dma_cfg);
- pitem->dma_cfg.output_cfg[i].dma_used = 0;
- }
- }
- if (pitem->dma_cfg.config_cfg.dma_used) {
- gdc_dma_buffer_unmap
- (&pitem->dma_cfg.config_cfg.dma_cfg);
- pitem->dma_cfg.config_cfg.dma_used = 0;
- }
- mutex_unlock(&context->d_mutext);
+
release_fw_name:
+ mutex_unlock(&context->d_mutext);
kfree(fw_name);
return ret;
ion_phys_addr_t addr;
int index, dma_fd;
void __user *argp = (void __user *)arg;
- struct gdc_queue_item_s *pitem;
+ struct gdc_queue_item_s *pitem = NULL;
struct device *dev = NULL;
context = (struct gdc_context_s *)file->private_data;
return -ENOMEM;
}
- of_reserved_mem_device_init(&(pdev->dev));
+ rc = of_reserved_mem_device_init(&pdev->dev);
+ if (rc != 0)
+ gdc_log(LOG_INFO, "reserve_mem is not used\n");
/* alloc mem to store config out path*/
config_out_file = kzalloc(CONFIG_PATH_LENG, GFP_KERNEL);