18 #include <linux/module.h>
22 #include <linux/sched.h>
23 #include <linux/slab.h>
34 #define MAGIC_DC_MEM 0x0733ac61
35 #define MAGIC_CHECK(is, should) \
36 if (unlikely((is) != (should))) { \
37 pr_err("magic mismatch: %x expected %x\n", (is), (should)); \
41 static int __videobuf_dc_alloc(
struct device *
dev,
56 dev_err(dev,
"dma_map_single failed\n");
68 dev_err(dev,
"memory alloc size %ld failed\n", mem->
size);
77 static void __videobuf_dc_free(
struct device *
dev,
96 dev_dbg(map->
q->dev,
"vm_open %p [count=%u,vma=%08lx-%08lx]\n",
108 dev_dbg(q->
dev,
"vm_close %p [count=%u,vma=%08lx-%08lx]\n",
112 if (0 == map->
count) {
116 videobuf_queue_lock(q);
126 if (q->
bufs[i]->map != map)
129 mem = q->
bufs[
i]->priv;
145 __videobuf_dc_free(q->
dev, mem);
150 q->
bufs[
i]->baddr = 0;
155 videobuf_queue_unlock(q);
159 static const struct vm_operations_struct videobuf_vm_ops = {
160 .open = videobuf_vm_open,
161 .close = videobuf_vm_close,
191 unsigned long prev_pfn, this_pfn;
192 unsigned long pages_done, user_address;
211 user_address = vb->
baddr;
214 ret =
follow_pfn(vma, user_address, &this_pfn);
220 else if (this_pfn != (prev_pfn + 1))
242 vb = kzalloc(size +
sizeof(*mem),
GFP_KERNEL);
255 return __videobuf_alloc_vb(size,
false);
260 return __videobuf_alloc_vb(size,
true);
284 dev_dbg(q->
dev,
"%s memory method MMAP\n", __func__);
288 dev_err(q->
dev,
"memory is not alloced/mmapped.\n");
293 dev_dbg(q->
dev,
"%s memory method USERPTR\n", __func__);
297 return videobuf_dma_contig_user_get(mem, vb);
306 dev_dbg(q->
dev,
"%s memory method OVERLAY/unknown\n", __func__);
360 size = (size < mem->
size) ? size : mem->
size;
368 dev_err(q->
dev,
"mmap: remap failed with error %d. ",
380 dev_err(q->
dev,
"mmap: virt_to_page failed\n");
381 __videobuf_dc_free(q->
dev, mem);
386 dev_err(q->
dev,
"mmap: insert failed with error %d\n",
388 __videobuf_dc_free(q->
dev, mem);
401 vma->
vm_ops = &videobuf_vm_ops;
405 dev_dbg(q->
dev,
"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
409 videobuf_vm_open(vma);
420 .alloc_vb = __videobuf_alloc_uncached,
421 .iolock = __videobuf_iolock,
422 .mmap_mapper = __videobuf_mmap_mapper,
423 .vaddr = __videobuf_to_vaddr,
428 .alloc_vb = __videobuf_alloc_cached,
429 .iolock = __videobuf_iolock,
430 .sync = __videobuf_sync,
431 .mmap_mapper = __videobuf_mmap_mapper,
432 .vaddr = __videobuf_to_vaddr,
443 struct mutex *ext_lock)
446 priv, &qops, ext_lock);
460 priv, &qops_cached, ext_lock);
496 videobuf_dma_contig_user_put(mem);
502 __videobuf_dc_free(q->
dev, mem);