17 #include <linux/module.h>
19 #include <linux/slab.h>
22 #include <linux/pci.h>
26 #include <asm/pgtable.h>
30 #define MAGIC_DMABUF 0x17760309
31 #define MAGIC_VMAL_MEM 0x18221223
33 #define MAGIC_CHECK(is, should) \
34 if (unlikely((is) != (should))) { \
35 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
47 #define dprintk(level, fmt, arg...) \
49 printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg)
58 dprintk(2,
"vm_open %p [count=%u,vma=%08lx-%08lx]\n", map,
70 dprintk(2,
"vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
74 if (0 == map->
count) {
77 dprintk(1,
"munmap %p q=%p\n", map, q);
78 videobuf_queue_lock(q);
88 if (q->
bufs[i]->map != map)
91 mem = q->
bufs[
i]->priv;
104 dprintk(1,
"%s: buf[%d] freeing (%p)\n",
105 __func__, i, mem->
vaddr);
112 q->
bufs[
i]->baddr = 0;
117 videobuf_queue_unlock(q);
123 static const struct vm_operations_struct videobuf_vm_ops = {
124 .open = videobuf_vm_open,
125 .close = videobuf_vm_close,
143 vb = kzalloc(size +
sizeof(*mem),
GFP_KERNEL);
147 mem = vb->
priv = ((
char *)vb) +
size;
150 dprintk(1,
"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
151 __func__, vb, (
long)
sizeof(*vb), (
long)size -
sizeof(*vb),
152 mem, (
long)
sizeof(*mem));
170 dprintk(1,
"%s memory method MMAP\n", __func__);
181 dprintk(1,
"%s memory method USERPTR\n", __func__);
197 dprintk(1,
"vmalloc is at addr %p (%d pages)\n",
222 dprintk(1,
"%s memory method OVERLAY/unknown\n", __func__);
262 dprintk(1,
"vmalloc is at addr %p (%d pages)\n", mem->
vaddr, pages);
272 vma->
vm_ops = &videobuf_vm_ops;
273 vma->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
276 dprintk(1,
"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
278 (
long int)buf->
bsize,
281 videobuf_vm_open(vma);
294 .alloc_vb = __videobuf_alloc_vb,
295 .iolock = __videobuf_iolock,
296 .mmap_mapper = __videobuf_mmap_mapper,
308 struct mutex *ext_lock)
311 priv, &qops, ext_lock);