Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 2 | * |
| 3 | * Based on videobuf-dma-contig.c, |
| 4 | * (c) 2008 Magnus Damm |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 and |
| 8 | * only version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * helper functions for physically contiguous pmem capture buffers |
| 16 | * The functions support contiguous memory allocations using pmem |
| 17 | * kernel API. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/pagemap.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/io.h> |
| 27 | #include <linux/android_pmem.h> |
| 28 | #include <linux/memory_alloc.h> |
| 29 | #include <media/videobuf2-msm-mem.h> |
| 30 | #include <media/msm_camera.h> |
| 31 | #include <mach/memory.h> |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 32 | #include <mach/msm_subsystem_map.h> |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 33 | #include <media/videobuf2-core.h> |
| 34 | |
| 35 | #define MAGIC_PMEM 0x0733ac64 |
| 36 | #define MAGIC_CHECK(is, should) \ |
| 37 | if (unlikely((is) != (should))) { \ |
| 38 | pr_err("magic mismatch: %x expected %x\n", (is), (should)); \ |
| 39 | BUG(); \ |
| 40 | } |
| 41 | |
| 42 | #ifdef CONFIG_MSM_CAMERA_DEBUG |
| 43 | #define D(fmt, args...) pr_debug("videobuf-msm-mem: " fmt, ##args) |
| 44 | #else |
| 45 | #define D(fmt, args...) do {} while (0) |
| 46 | #endif |
| 47 | |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 48 | static int32_t msm_mem_allocate(struct videobuf2_contig_pmem *mem) |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 49 | { |
| 50 | int32_t phyaddr; |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 51 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 52 | int rc, len; |
| 53 | mem->client = msm_ion_client_create(-1, "camera"); |
| 54 | if (IS_ERR((void *)mem->client)) { |
| 55 | pr_err("%s Could not create client\n", __func__); |
| 56 | goto client_failed; |
| 57 | } |
| 58 | mem->ion_handle = ion_alloc(mem->client, mem->size, SZ_4K, |
| 59 | (0x1 << ION_CP_MM_HEAP_ID | 0x1 << ION_IOMMU_HEAP_ID)); |
| 60 | if (IS_ERR((void *)mem->ion_handle)) { |
| 61 | pr_err("%s Could not allocate\n", __func__); |
| 62 | goto alloc_failed; |
| 63 | } |
| 64 | rc = ion_phys(mem->client, mem->ion_handle, (ion_phys_addr_t *)&phyaddr, |
| 65 | (size_t *)&len); |
| 66 | if (rc < 0) { |
| 67 | pr_err("%s Could not get physical address\n", __func__); |
| 68 | goto phys_failed; |
| 69 | } |
| 70 | #else |
| 71 | phyaddr = allocate_contiguous_ebi_nomap(mem->size, SZ_4K); |
| 72 | #endif |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 73 | return phyaddr; |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 74 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 75 | phys_failed: |
| 76 | ion_free(mem->client, mem->ion_handle); |
| 77 | alloc_failed: |
| 78 | ion_client_destroy(mem->client); |
| 79 | client_failed: |
| 80 | return 0; |
| 81 | #endif |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 84 | static int32_t msm_mem_free(struct videobuf2_contig_pmem *mem) |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 85 | { |
| 86 | int32_t rc = 0; |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 87 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 88 | ion_free(mem->client, mem->ion_handle); |
| 89 | ion_client_destroy(mem->client); |
| 90 | #else |
| 91 | free_contiguous_memory_by_paddr(mem->phyaddr); |
| 92 | #endif |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 93 | return rc; |
| 94 | } |
| 95 | |
| 96 | static void videobuf2_vm_close(struct vm_area_struct *vma) |
| 97 | { |
| 98 | struct videobuf2_contig_pmem *mem = vma->vm_private_data; |
| 99 | D("vm_close %p [count=%u,vma=%08lx-%08lx]\n", |
| 100 | mem, mem->count, vma->vm_start, vma->vm_end); |
| 101 | mem->count--; |
| 102 | } |
| 103 | static void videobuf2_vm_open(struct vm_area_struct *vma) |
| 104 | { |
| 105 | struct videobuf2_contig_pmem *mem = vma->vm_private_data; |
| 106 | D("vm_open %p [count=%u,vma=%08lx-%08lx]\n", |
| 107 | mem, mem->count, vma->vm_start, vma->vm_end); |
| 108 | mem->count++; |
| 109 | } |
| 110 | |
| 111 | static const struct vm_operations_struct videobuf2_vm_ops = { |
| 112 | .open = videobuf2_vm_open, |
| 113 | .close = videobuf2_vm_close, |
| 114 | }; |
| 115 | |
| 116 | static void *msm_vb2_mem_ops_alloc(void *alloc_ctx, unsigned long size) |
| 117 | { |
| 118 | struct videobuf2_contig_pmem *mem; |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 119 | unsigned int flags = 0; |
| 120 | long rc; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 121 | mem = kzalloc(sizeof(*mem), GFP_KERNEL); |
| 122 | if (!mem) |
| 123 | return ERR_PTR(-ENOMEM); |
| 124 | |
| 125 | mem->magic = MAGIC_PMEM; |
| 126 | mem->size = PAGE_ALIGN(size); |
| 127 | mem->alloc_ctx = alloc_ctx; |
| 128 | mem->is_userptr = 0; |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 129 | mem->phyaddr = msm_mem_allocate(mem); |
Ankit Premrajka | a5ea3a9 | 2011-08-04 17:54:17 -0700 | [diff] [blame] | 130 | if (!mem->phyaddr) { |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 131 | pr_err("%s : pmem memory allocation failed\n", __func__); |
| 132 | kfree(mem); |
| 133 | return ERR_PTR(-ENOMEM); |
| 134 | } |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 135 | flags = MSM_SUBSYSTEM_MAP_IOVA; |
| 136 | mem->subsys_id = MSM_SUBSYSTEM_CAMERA; |
| 137 | mem->msm_buffer = msm_subsystem_map_buffer(mem->phyaddr, mem->size, |
| 138 | flags, &(mem->subsys_id), 1); |
| 139 | if (IS_ERR((void *)mem->msm_buffer)) { |
| 140 | pr_err("%s: msm_subsystem_map_buffer failed\n", __func__); |
| 141 | rc = PTR_ERR((void *)mem->msm_buffer); |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 142 | msm_mem_free(mem); |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 143 | kfree(mem); |
| 144 | return ERR_PTR(-ENOMEM); |
| 145 | } |
Kiran Kumar H N | ceea762 | 2011-08-23 14:01:03 -0700 | [diff] [blame] | 146 | mem->mapped_phyaddr = mem->msm_buffer->iova[0]; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 147 | return mem; |
| 148 | } |
| 149 | static void msm_vb2_mem_ops_put(void *buf_priv) |
| 150 | { |
| 151 | struct videobuf2_contig_pmem *mem = buf_priv; |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 152 | if (!mem->is_userptr) { |
| 153 | D("%s Freeing memory ", __func__); |
| 154 | if (msm_subsystem_unmap_buffer(mem->msm_buffer) < 0) |
| 155 | D("%s unmapped memory\n", __func__); |
Ankit Premrajka | d814743 | 2012-01-06 09:45:11 -0800 | [diff] [blame^] | 156 | msm_mem_free(mem); |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 157 | } |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 158 | kfree(mem); |
| 159 | } |
| 160 | int videobuf2_pmem_contig_mmap_get(struct videobuf2_contig_pmem *mem, |
Kiran Kumar H N | 5e08d77 | 2011-10-03 10:19:15 -0700 | [diff] [blame] | 161 | struct videobuf2_msm_offset *offset, |
| 162 | enum videobuf2_buffer_type buffer_type, |
| 163 | int path) |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 164 | { |
Kiran Kumar H N | 5e08d77 | 2011-10-03 10:19:15 -0700 | [diff] [blame] | 165 | if (offset) |
| 166 | mem->offset = *offset; |
| 167 | else |
| 168 | memset(&mem->offset, 0, sizeof(struct videobuf2_msm_offset)); |
| 169 | mem->buffer_type = buffer_type; |
| 170 | mem->path = path; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_mmap_get); |
| 174 | |
| 175 | /** |
| 176 | * videobuf_pmem_contig_user_get() - setup user space memory pointer |
| 177 | * @mem: per-buffer private videobuf-contig-pmem data |
| 178 | * @vb: video buffer to map |
| 179 | * |
| 180 | * This function validates and sets up a pointer to user space memory. |
| 181 | * Only physically contiguous pfn-mapped memory is accepted. |
| 182 | * |
| 183 | * Returns 0 if successful. |
| 184 | */ |
| 185 | int videobuf2_pmem_contig_user_get(struct videobuf2_contig_pmem *mem, |
Kiran Kumar H N | 5e08d77 | 2011-10-03 10:19:15 -0700 | [diff] [blame] | 186 | struct videobuf2_msm_offset *offset, |
| 187 | enum videobuf2_buffer_type buffer_type, |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 188 | uint32_t addr_offset, int path, |
| 189 | struct ion_client *client) |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 190 | { |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 191 | unsigned long len; |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 192 | int rc = 0; |
| 193 | #ifndef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 194 | unsigned long kvstart; |
| 195 | #endif |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 196 | unsigned int flags = 0; |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 197 | unsigned long paddr = 0; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 198 | if (mem->phyaddr != 0) |
| 199 | return 0; |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 200 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 201 | mem->ion_handle = ion_import_fd(client, (int)mem->vaddr); |
| 202 | if (IS_ERR_OR_NULL(mem->ion_handle)) { |
| 203 | pr_err("%s ION import failed\n", __func__); |
| 204 | return PTR_ERR(mem->ion_handle); |
| 205 | } |
| 206 | rc = ion_phys(client, mem->ion_handle, (ion_phys_addr_t *)&mem->phyaddr, |
| 207 | (size_t *)&len); |
| 208 | #elif CONFIG_ANDROID_PMEM |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 209 | rc = get_pmem_file((int)mem->vaddr, (unsigned long *)&mem->phyaddr, |
| 210 | &kvstart, &len, &mem->file); |
| 211 | if (rc < 0) { |
| 212 | pr_err("%s: get_pmem_file fd %d error %d\n", |
| 213 | __func__, (int)mem->vaddr, rc); |
| 214 | return rc; |
| 215 | } |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 216 | #else |
| 217 | paddr = 0; |
| 218 | kvstart = 0; |
| 219 | #endif |
Kiran Kumar H N | 5e08d77 | 2011-10-03 10:19:15 -0700 | [diff] [blame] | 220 | if (offset) |
| 221 | mem->offset = *offset; |
| 222 | else |
| 223 | memset(&mem->offset, 0, sizeof(struct videobuf2_msm_offset)); |
| 224 | mem->path = path; |
| 225 | mem->buffer_type = buffer_type; |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 226 | paddr = mem->phyaddr; |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 227 | flags = MSM_SUBSYSTEM_MAP_IOVA; |
| 228 | mem->subsys_id = MSM_SUBSYSTEM_CAMERA; |
Ankit Premrajka | 1b9b9a4 | 2011-08-05 15:49:42 -0700 | [diff] [blame] | 229 | mem->msm_buffer = msm_subsystem_map_buffer(mem->phyaddr, len, |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 230 | flags, &(mem->subsys_id), 1); |
| 231 | if (IS_ERR((void *)mem->msm_buffer)) { |
| 232 | pr_err("%s: msm_subsystem_map_buffer failed\n", __func__); |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 233 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 234 | ion_free(client, mem->ion_handle); |
| 235 | #elif CONFIG_ANDROID_PMEM |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 236 | put_pmem_file(mem->file); |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 237 | #endif |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 238 | return PTR_ERR((void *)mem->msm_buffer); |
| 239 | } |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 240 | paddr = mem->msm_buffer->iova[0]; |
| 241 | mem->mapped_phyaddr = paddr + addr_offset; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 242 | return rc; |
| 243 | } |
| 244 | EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_user_get); |
| 245 | |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 246 | void videobuf2_pmem_contig_user_put(struct videobuf2_contig_pmem *mem, |
| 247 | struct ion_client *client) |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 248 | { |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 249 | if (msm_subsystem_unmap_buffer(mem->msm_buffer) < 0) |
| 250 | D("%s unmapped memory\n", __func__); |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 251 | if (mem->is_userptr) { |
| 252 | #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION |
| 253 | ion_free(client, mem->ion_handle); |
| 254 | #elif CONFIG_ANDROID_PMEM |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 255 | put_pmem_file(mem->file); |
Ankit Premrajka | 748a70a | 2011-11-01 08:22:04 -0700 | [diff] [blame] | 256 | #endif |
| 257 | } |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 258 | mem->is_userptr = 0; |
| 259 | mem->phyaddr = 0; |
| 260 | mem->size = 0; |
Kiran Kumar H N | ceea762 | 2011-08-23 14:01:03 -0700 | [diff] [blame] | 261 | mem->mapped_phyaddr = 0; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 262 | } |
| 263 | EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_user_put); |
| 264 | |
| 265 | static void *msm_vb2_mem_ops_get_userptr(void *alloc_ctx, unsigned long vaddr, |
| 266 | unsigned long size, int write) |
| 267 | { |
| 268 | struct videobuf2_contig_pmem *mem; |
| 269 | mem = kzalloc(sizeof(*mem), GFP_KERNEL); |
| 270 | if (!mem) |
| 271 | return ERR_PTR(-ENOMEM); |
| 272 | mem->magic = MAGIC_PMEM; |
| 273 | mem->is_userptr = 1; |
| 274 | mem->vaddr = (void *)vaddr; |
| 275 | mem->size = size; |
| 276 | mem->alloc_ctx = alloc_ctx; |
| 277 | return mem; |
| 278 | } |
| 279 | static void msm_vb2_mem_ops_put_userptr(void *buf_priv) |
| 280 | { |
| 281 | kfree(buf_priv); |
| 282 | } |
| 283 | |
| 284 | static void *msm_vb2_mem_ops_vaddr(void *buf_priv) |
| 285 | { |
| 286 | struct videobuf2_contig_pmem *mem = buf_priv; |
| 287 | return mem->vaddr; |
| 288 | } |
| 289 | static void *msm_vb2_mem_ops_cookie(void *buf_priv) |
| 290 | { |
| 291 | return buf_priv; |
| 292 | } |
| 293 | static unsigned int msm_vb2_mem_ops_num_users(void *buf_priv) |
| 294 | { |
| 295 | struct videobuf2_contig_pmem *mem = buf_priv; |
| 296 | MAGIC_CHECK(mem->magic, MAGIC_PMEM); |
| 297 | return mem->count; |
| 298 | } |
| 299 | static int msm_vb2_mem_ops_mmap(void *buf_priv, struct vm_area_struct *vma) |
| 300 | { |
| 301 | struct videobuf2_contig_pmem *mem; |
| 302 | int retval; |
| 303 | unsigned long size; |
| 304 | D("%s\n", __func__); |
| 305 | mem = buf_priv; |
| 306 | D("mem = 0x%x\n", (u32)mem); |
| 307 | BUG_ON(!mem); |
| 308 | MAGIC_CHECK(mem->magic, MAGIC_PMEM); |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 309 | /* Try to remap memory */ |
| 310 | size = vma->vm_end - vma->vm_start; |
| 311 | size = (size < mem->size) ? size : mem->size; |
| 312 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 313 | retval = remap_pfn_range(vma, vma->vm_start, |
| 314 | mem->phyaddr >> PAGE_SHIFT, |
| 315 | size, vma->vm_page_prot); |
| 316 | if (retval) { |
| 317 | pr_err("mmap: remap failed with error %d. ", retval); |
| 318 | goto error; |
| 319 | } |
| 320 | mem->vaddr = (void *)vma->vm_start; |
| 321 | vma->vm_ops = &videobuf2_vm_ops; |
| 322 | vma->vm_flags |= VM_DONTEXPAND; |
| 323 | vma->vm_private_data = mem; |
| 324 | |
| 325 | D("mmap %p: %08lx-%08lx (%lx) pgoff %08lx\n", |
| 326 | map, vma->vm_start, vma->vm_end, |
| 327 | (long int)mem->bsize, vma->vm_pgoff); |
| 328 | videobuf2_vm_open(vma); |
| 329 | return 0; |
| 330 | error: |
| 331 | return -ENOMEM; |
| 332 | } |
| 333 | |
| 334 | static struct vb2_mem_ops msm_vb2_mem_ops = { |
| 335 | .alloc = msm_vb2_mem_ops_alloc, |
| 336 | .put = msm_vb2_mem_ops_put, |
| 337 | .get_userptr = msm_vb2_mem_ops_get_userptr, |
| 338 | .put_userptr = msm_vb2_mem_ops_put_userptr, |
| 339 | .vaddr = msm_vb2_mem_ops_vaddr, |
| 340 | .cookie = msm_vb2_mem_ops_cookie, |
| 341 | .num_users = msm_vb2_mem_ops_num_users, |
| 342 | .mmap = msm_vb2_mem_ops_mmap |
| 343 | }; |
| 344 | |
| 345 | void videobuf2_queue_pmem_contig_init(struct vb2_queue *q, |
| 346 | enum v4l2_buf_type type, |
| 347 | const struct vb2_ops *ops, |
| 348 | unsigned int size, |
| 349 | void *priv) |
| 350 | { |
| 351 | memset(q, 0, sizeof(struct vb2_queue)); |
| 352 | q->mem_ops = &msm_vb2_mem_ops; |
| 353 | q->ops = ops; |
| 354 | q->drv_priv = priv; |
| 355 | q->type = type; |
| 356 | q->io_modes = VB2_MMAP | VB2_USERPTR; |
| 357 | q->io_flags = 0; |
| 358 | q->buf_struct_size = size; |
| 359 | vb2_queue_init(q); |
| 360 | } |
| 361 | EXPORT_SYMBOL_GPL(videobuf2_queue_pmem_contig_init); |
| 362 | |
Ankit Premrajka | c6864b8 | 2011-07-15 11:43:41 -0700 | [diff] [blame] | 363 | unsigned long videobuf2_to_pmem_contig(struct vb2_buffer *vb, |
| 364 | unsigned int plane_no) |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 365 | { |
| 366 | struct videobuf2_contig_pmem *mem; |
| 367 | mem = vb2_plane_cookie(vb, plane_no); |
| 368 | BUG_ON(!mem); |
| 369 | MAGIC_CHECK(mem->magic, MAGIC_PMEM); |
Kiran Kumar H N | ceea762 | 2011-08-23 14:01:03 -0700 | [diff] [blame] | 370 | return mem->mapped_phyaddr; |
Mingcheng Zhu | 9812bd3 | 2011-07-22 22:57:11 -0700 | [diff] [blame] | 371 | } |
| 372 | EXPORT_SYMBOL_GPL(videobuf2_to_pmem_contig); |
| 373 | |
| 374 | MODULE_DESCRIPTION("helper module to manage video4linux PMEM contig buffers"); |
| 375 | MODULE_LICENSE("GPL v2"); |