msm: v4l2: fix support for test app.
This commit fixes bug in query-cap ioctl and
adds ION support for case where buffers are
allocated in the kernel with mmap. This change
is required to fix the V4L2 command line test app.
Change-Id: I50a535e8a0af60ff7d86341a3f726ed81a630fb0
Signed-off-by: Ankit Premrajka <ankitp@codeaurora.org>
diff --git a/drivers/media/video/msm/msm.c b/drivers/media/video/msm/msm.c
index 8df6243..363e437 100644
--- a/drivers/media/video/msm/msm.c
+++ b/drivers/media/video/msm/msm.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@@ -674,14 +674,12 @@
static int msm_camera_v4l2_querycap(struct file *f, void *pctx,
struct v4l2_capability *pcaps)
{
- struct msm_cam_v4l2_device *pcam = video_drvdata(f);
D("%s\n", __func__);
WARN_ON(pctx != f->private_data);
/* some other day, some other time */
/*cap->version = LINUX_VERSION_CODE; */
- strlcpy(pcaps->driver, pcam->pdev->name, sizeof(pcaps->driver));
pcaps->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
return 0;
}
diff --git a/drivers/media/video/videobuf2-msm-mem.c b/drivers/media/video/videobuf2-msm-mem.c
index fa7e3fd..37b935b 100644
--- a/drivers/media/video/videobuf2-msm-mem.c
+++ b/drivers/media/video/videobuf2-msm-mem.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
*
* Based on videobuf-dma-contig.c,
* (c) 2008 Magnus Damm
@@ -45,17 +45,51 @@
#define D(fmt, args...) do {} while (0)
#endif
-static int32_t msm_mem_allocate(const size_t size)
+static int32_t msm_mem_allocate(struct videobuf2_contig_pmem *mem)
{
int32_t phyaddr;
- phyaddr = allocate_contiguous_ebi_nomap(size, SZ_4K);
+#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
+ int rc, len;
+ mem->client = msm_ion_client_create(-1, "camera");
+ if (IS_ERR((void *)mem->client)) {
+ pr_err("%s Could not create client\n", __func__);
+ goto client_failed;
+ }
+ mem->ion_handle = ion_alloc(mem->client, mem->size, SZ_4K,
+ (0x1 << ION_CP_MM_HEAP_ID | 0x1 << ION_IOMMU_HEAP_ID));
+ if (IS_ERR((void *)mem->ion_handle)) {
+ pr_err("%s Could not allocate\n", __func__);
+ goto alloc_failed;
+ }
+ rc = ion_phys(mem->client, mem->ion_handle, (ion_phys_addr_t *)&phyaddr,
+ (size_t *)&len);
+ if (rc < 0) {
+ pr_err("%s Could not get physical address\n", __func__);
+ goto phys_failed;
+ }
+#else
+ phyaddr = allocate_contiguous_ebi_nomap(mem->size, SZ_4K);
+#endif
return phyaddr;
+#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
+phys_failed:
+ ion_free(mem->client, mem->ion_handle);
+alloc_failed:
+ ion_client_destroy(mem->client);
+client_failed:
+ return 0;
+#endif
}
-static int32_t msm_mem_free(const int32_t phyaddr)
+static int32_t msm_mem_free(struct videobuf2_contig_pmem *mem)
{
int32_t rc = 0;
- free_contiguous_memory_by_paddr(phyaddr);
+#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
+ ion_free(mem->client, mem->ion_handle);
+ ion_client_destroy(mem->client);
+#else
+ free_contiguous_memory_by_paddr(mem->phyaddr);
+#endif
return rc;
}
@@ -92,7 +126,7 @@
mem->size = PAGE_ALIGN(size);
mem->alloc_ctx = alloc_ctx;
mem->is_userptr = 0;
- mem->phyaddr = msm_mem_allocate(mem->size);
+ mem->phyaddr = msm_mem_allocate(mem);
if (!mem->phyaddr) {
pr_err("%s : pmem memory allocation failed\n", __func__);
kfree(mem);
@@ -105,7 +139,7 @@
if (IS_ERR((void *)mem->msm_buffer)) {
pr_err("%s: msm_subsystem_map_buffer failed\n", __func__);
rc = PTR_ERR((void *)mem->msm_buffer);
- msm_mem_free(mem->phyaddr);
+ msm_mem_free(mem);
kfree(mem);
return ERR_PTR(-ENOMEM);
}
@@ -119,7 +153,7 @@
D("%s Freeing memory ", __func__);
if (msm_subsystem_unmap_buffer(mem->msm_buffer) < 0)
D("%s unmapped memory\n", __func__);
- msm_mem_free(mem->phyaddr);
+ msm_mem_free(mem);
}
kfree(mem);
}
diff --git a/include/media/videobuf2-msm-mem.h b/include/media/videobuf2-msm-mem.h
index 916c458..0c7cf8c 100644
--- a/include/media/videobuf2-msm-mem.h
+++ b/include/media/videobuf2-msm-mem.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@@ -60,6 +60,7 @@
int subsys_id;
unsigned long mapped_phyaddr;
struct ion_handle *ion_handle;
+ struct ion_client *client;
};
void videobuf2_queue_pmem_contig_init(struct vb2_queue *q,
enum v4l2_buf_type type,