videobuf-dma-sg.c 16.4 KB
Newer Older
1
/*
2
 * helper functions for SG DMA video4linux capture buffers
3
 *
4
 * The functions expect the hardware being able to scatter gather
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * (i.e. the buffers are not linear in physical memory, but fragmented
 * into PAGE_SIZE chunks).  They also assume the driver does not need
 * to touch the video data.
 *
 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
 *
 * Highly based on video-buf written originally by:
 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
 * (c) 2006 Ted Walther and John Sokol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
24
#include <linux/sched.h>
25 26 27
#include <linux/slab.h>
#include <linux/interrupt.h>

28
#include <linux/dma-mapping.h>
29 30
#include <linux/vmalloc.h>
#include <linux/pagemap.h>
31
#include <linux/scatterlist.h>
32 33 34 35 36 37 38 39
#include <asm/page.h>
#include <asm/pgtable.h>

#include <media/videobuf-dma-sg.h>

#define MAGIC_DMABUF 0x19721112
#define MAGIC_SG_MEM 0x17890714

40 41 42 43 44 45
#define MAGIC_CHECK(is, should)						\
	if (unlikely((is) != (should))) {				\
		printk(KERN_ERR "magic mismatch: %x (expected %x)\n",	\
				is, should);				\
		BUG();							\
	}
46

47
static int debug;
48 49
module_param(debug, int, 0644);

50
MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
51 52 53
MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
MODULE_LICENSE("GPL");

54 55 56
#define dprintk(level, fmt, arg...)					\
	if (debug >= level)						\
		printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
57 58 59

/* --------------------------------------------------------------------- */

60 61 62 63 64 65 66
/*
 * Return a scatterlist for some page-aligned vmalloc()'ed memory
 * block (NULL on errors).  Memory for the scatterlist is allocated
 * using kmalloc.  The caller must free the memory.
 */
static struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt,
						  int nr_pages)
67 68 69 70 71
{
	struct scatterlist *sglist;
	struct page *pg;
	int i;

J
Joe Perches 已提交
72
	sglist = vzalloc(nr_pages * sizeof(*sglist));
73 74
	if (NULL == sglist)
		return NULL;
J
Jens Axboe 已提交
75
	sg_init_table(sglist, nr_pages);
76 77 78 79 80
	for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
		pg = vmalloc_to_page(virt);
		if (NULL == pg)
			goto err;
		BUG_ON(PageHighMem(pg));
81
		sg_set_page(&sglist[i], pg, PAGE_SIZE, 0);
82 83 84
	}
	return sglist;

85
err:
86
	vfree(sglist);
87 88 89
	return NULL;
}

90 91 92 93 94 95
/*
 * Return a scatterlist for a an array of userpages (NULL on errors).
 * Memory for the scatterlist is allocated using kmalloc.  The caller
 * must free the memory.
 */
static struct scatterlist *videobuf_pages_to_sg(struct page **pages,
96
					int nr_pages, int offset, size_t size)
97 98
{
	struct scatterlist *sglist;
99
	int i;
100 101 102

	if (NULL == pages[0])
		return NULL;
103
	sglist = vmalloc(nr_pages * sizeof(*sglist));
104 105
	if (NULL == sglist)
		return NULL;
J
Jens Axboe 已提交
106
	sg_init_table(sglist, nr_pages);
107 108 109 110

	if (PageHighMem(pages[0]))
		/* DMA to highmem pages might not work */
		goto highmem;
111 112 113
	sg_set_page(&sglist[0], pages[0],
			min_t(size_t, PAGE_SIZE - offset, size), offset);
	size -= min_t(size_t, PAGE_SIZE - offset, size);
114 115 116 117 118
	for (i = 1; i < nr_pages; i++) {
		if (NULL == pages[i])
			goto nopage;
		if (PageHighMem(pages[i]))
			goto highmem;
119 120
		sg_set_page(&sglist[i], pages[i], min_t(size_t, PAGE_SIZE, size), 0);
		size -= min_t(size_t, PAGE_SIZE, size);
121 122 123
	}
	return sglist;

124 125
nopage:
	dprintk(2, "sgl: oops - no page\n");
126
	vfree(sglist);
127 128
	return NULL;

129 130
highmem:
	dprintk(2, "sgl: oops - highmem page\n");
131
	vfree(sglist);
132 133 134 135 136
	return NULL;
}

/* --------------------------------------------------------------------- */

137
struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf)
138
{
139 140
	struct videobuf_dma_sg_memory *mem = buf->priv;
	BUG_ON(!mem);
141

142
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
143 144 145

	return &mem->dma;
}
146
EXPORT_SYMBOL_GPL(videobuf_to_dma);
147

148
static void videobuf_dma_init(struct videobuf_dmabuf *dma)
149
{
150
	memset(dma, 0, sizeof(*dma));
151 152 153
	dma->magic = MAGIC_DMABUF;
}

154 155
static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
			int direction, unsigned long data, unsigned long size)
156
{
157
	unsigned long first, last;
158
	int err, rw = 0;
159
	unsigned int flags = FOLL_FORCE;
160 161 162

	dma->direction = direction;
	switch (dma->direction) {
163 164 165 166 167 168 169 170
	case DMA_FROM_DEVICE:
		rw = READ;
		break;
	case DMA_TO_DEVICE:
		rw = WRITE;
		break;
	default:
		BUG();
171 172 173 174
	}

	first = (data          & PAGE_MASK) >> PAGE_SHIFT;
	last  = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
175 176
	dma->offset = data & ~PAGE_MASK;
	dma->size = size;
177
	dma->nr_pages = last-first+1;
178
	dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
179 180 181
	if (NULL == dma->pages)
		return -ENOMEM;

182 183 184
	if (rw == READ)
		flags |= FOLL_WRITE;

185 186 187
	dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
		data, size, dma->nr_pages);

188
	err = get_user_pages(data & PAGE_MASK, dma->nr_pages,
189
			     flags, dma->pages, NULL);
190

191 192
	if (err != dma->nr_pages) {
		dma->nr_pages = (err >= 0) ? err : 0;
193
		dprintk(1, "get_user_pages: err=%d [%d]\n", err, dma->nr_pages);
194 195 196 197 198
		return err < 0 ? err : -EINVAL;
	}
	return 0;
}

199
static int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
200 201 202
			   unsigned long data, unsigned long size)
{
	int ret;
203

204 205 206 207 208 209 210
	down_read(&current->mm->mmap_sem);
	ret = videobuf_dma_init_user_locked(dma, direction, data, size);
	up_read(&current->mm->mmap_sem);

	return ret;
}

211
static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
212 213
			     int nr_pages)
{
214 215
	int i;

216 217
	dprintk(1, "init kernel [%d pages]\n", nr_pages);

218
	dma->direction = direction;
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
	dma->vaddr_pages = kcalloc(nr_pages, sizeof(*dma->vaddr_pages),
				   GFP_KERNEL);
	if (!dma->vaddr_pages)
		return -ENOMEM;

	dma->dma_addr = kcalloc(nr_pages, sizeof(*dma->dma_addr), GFP_KERNEL);
	if (!dma->dma_addr) {
		kfree(dma->vaddr_pages);
		return -ENOMEM;
	}
	for (i = 0; i < nr_pages; i++) {
		void *addr;

		addr = dma_alloc_coherent(dma->dev, PAGE_SIZE,
					  &(dma->dma_addr[i]), GFP_KERNEL);
		if (addr == NULL)
			goto out_free_pages;

		dma->vaddr_pages[i] = virt_to_page(addr);
	}
	dma->vaddr = vmap(dma->vaddr_pages, nr_pages, VM_MAP | VM_IOREMAP,
			  PAGE_KERNEL);
241
	if (NULL == dma->vaddr) {
242
		dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
243
		goto out_free_pages;
244
	}
245 246

	dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
247
				(unsigned long)dma->vaddr,
248
				nr_pages << PAGE_SHIFT);
249

250
	memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT);
251
	dma->nr_pages = nr_pages;
252

253
	return 0;
254 255
out_free_pages:
	while (i > 0) {
256 257
		void *addr;

258
		i--;
259 260
		addr = page_address(dma->vaddr_pages[i]);
		dma_free_coherent(dma->dev, PAGE_SIZE, addr, dma->dma_addr[i]);
261 262 263 264 265 266 267 268
	}
	kfree(dma->dma_addr);
	dma->dma_addr = NULL;
	kfree(dma->vaddr_pages);
	dma->vaddr_pages = NULL;

	return -ENOMEM;

269 270
}

271
static int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
272 273
			      dma_addr_t addr, int nr_pages)
{
274 275
	dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
		nr_pages, (unsigned long)addr);
276
	dma->direction = direction;
277

278 279 280 281 282
	if (0 == addr)
		return -EINVAL;

	dma->bus_addr = addr;
	dma->nr_pages = nr_pages;
283

284 285 286
	return 0;
}

287
static int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
288
{
289
	MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
290 291 292 293
	BUG_ON(0 == dma->nr_pages);

	if (dma->pages) {
		dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
294
						   dma->offset, dma->size);
295
	}
296 297
	if (dma->vaddr) {
		dma->sglist = videobuf_vmalloc_to_sg(dma->vaddr,
298
						     dma->nr_pages);
299 300
	}
	if (dma->bus_addr) {
301
		dma->sglist = vmalloc(sizeof(*dma->sglist));
302
		if (NULL != dma->sglist) {
303 304 305 306 307
			dma->sglen = 1;
			sg_dma_address(&dma->sglist[0])	= dma->bus_addr
							& PAGE_MASK;
			dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
			sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
308 309 310
		}
	}
	if (NULL == dma->sglist) {
311
		dprintk(1, "scatterlist is NULL\n");
312 313 314
		return -ENOMEM;
	}
	if (!dma->bus_addr) {
315
		dma->sglen = dma_map_sg(dev, dma->sglist,
316 317 318
					dma->nr_pages, dma->direction);
		if (0 == dma->sglen) {
			printk(KERN_WARNING
319
			       "%s: videobuf_map_sg failed\n", __func__);
320
			vfree(dma->sglist);
321 322
			dma->sglist = NULL;
			dma->sglen = 0;
323
			return -ENOMEM;
324 325
		}
	}
326

327 328 329
	return 0;
}

330
int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
331
{
332
	MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
333

334 335 336
	if (!dma->sglen)
		return 0;

337
	dma_unmap_sg(dev, dma->sglist, dma->sglen, dma->direction);
338

339
	vfree(dma->sglist);
340 341
	dma->sglist = NULL;
	dma->sglen = 0;
342

343 344
	return 0;
}
345
EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
346 347 348

int videobuf_dma_free(struct videobuf_dmabuf *dma)
{
349 350
	int i;
	MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
351 352 353
	BUG_ON(dma->sglen);

	if (dma->pages) {
354
		for (i = 0; i < dma->nr_pages; i++)
355
			put_page(dma->pages[i]);
356 357 358 359
		kfree(dma->pages);
		dma->pages = NULL;
	}

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
	if (dma->dma_addr) {
		for (i = 0; i < dma->nr_pages; i++) {
			void *addr;

			addr = page_address(dma->vaddr_pages[i]);
			dma_free_coherent(dma->dev, PAGE_SIZE, addr,
					  dma->dma_addr[i]);
		}
		kfree(dma->dma_addr);
		dma->dma_addr = NULL;
		kfree(dma->vaddr_pages);
		dma->vaddr_pages = NULL;
		vunmap(dma->vaddr);
		dma->vaddr = NULL;
	}
375

376
	if (dma->bus_addr)
377
		dma->bus_addr = 0;
378
	dma->direction = DMA_NONE;
379

380 381
	return 0;
}
382
EXPORT_SYMBOL_GPL(videobuf_dma_free);
383 384 385

/* --------------------------------------------------------------------- */

386
static void videobuf_vm_open(struct vm_area_struct *vma)
387 388 389
{
	struct videobuf_mapping *map = vma->vm_private_data;

390 391 392
	dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
		map->count, vma->vm_start, vma->vm_end);

393 394 395
	map->count++;
}

396
static void videobuf_vm_close(struct vm_area_struct *vma)
397 398 399
{
	struct videobuf_mapping *map = vma->vm_private_data;
	struct videobuf_queue *q = map->q;
400
	struct videobuf_dma_sg_memory *mem;
401 402
	int i;

403 404
	dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
		map->count, vma->vm_start, vma->vm_end);
405

406 407
	map->count--;
	if (0 == map->count) {
408
		dprintk(1, "munmap %p q=%p\n", map, q);
409
		videobuf_queue_lock(q);
410 411 412
		for (i = 0; i < VIDEO_MAX_FRAME; i++) {
			if (NULL == q->bufs[i])
				continue;
413
			mem = q->bufs[i]->priv;
414 415 416
			if (!mem)
				continue;

417
			MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
418

419
			if (q->bufs[i]->map != map)
420
				continue;
421
			q->bufs[i]->map   = NULL;
422
			q->bufs[i]->baddr = 0;
423
			q->ops->buf_release(q, q->bufs[i]);
424
		}
425
		videobuf_queue_unlock(q);
426 427 428 429 430 431 432 433 434 435 436
		kfree(map);
	}
	return;
}

/*
 * Get a anonymous page for the mapping.  Make sure we can DMA to that
 * memory location with 32bit PCI devices (i.e. don't use highmem for
 * now ...).  Bounce buffers don't work very well for the data rates
 * video capture has.
 */
437
static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
438 439 440
{
	struct page *page;

441 442 443 444
	dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
		(unsigned long)vmf->virtual_address,
		vma->vm_start, vma->vm_end);

445 446
	page = alloc_page(GFP_USER | __GFP_DMA32);
	if (!page)
447
		return VM_FAULT_OOM;
448
	clear_user_highpage(page, (unsigned long)vmf->virtual_address);
449
	vmf->page = page;
450

451
	return 0;
452 453
}

454 455 456 457
static const struct vm_operations_struct videobuf_vm_ops = {
	.open	= videobuf_vm_open,
	.close	= videobuf_vm_close,
	.fault	= videobuf_vm_fault,
458 459 460
};

/* ---------------------------------------------------------------------
461
 * SG handlers for the generic methods
462 463 464 465 466
 */

/* Allocated area consists on 3 parts:
	struct video_buffer
	struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
467
	struct videobuf_dma_sg_memory
468 469
 */

470
static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
471
{
472
	struct videobuf_dma_sg_memory *mem;
473 474
	struct videobuf_buffer *vb;

475
	vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
476 477
	if (!vb)
		return vb;
478

479 480
	mem = vb->priv = ((char *)vb) + size;
	mem->magic = MAGIC_SG_MEM;
481 482 483

	videobuf_dma_init(&mem->dma);

484 485 486
	dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
		__func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
		mem, (long)sizeof(*mem));
487 488 489 490

	return vb;
}

491
static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
492 493 494 495 496 497
{
	struct videobuf_dma_sg_memory *mem = buf->priv;
	BUG_ON(!mem);

	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);

498
	return mem->dma.vaddr;
499 500
}

501 502 503
static int __videobuf_iolock(struct videobuf_queue *q,
			     struct videobuf_buffer *vb,
			     struct v4l2_framebuffer *fbuf)
504
{
505
	int err, pages;
506
	dma_addr_t bus;
507
	struct videobuf_dma_sg_memory *mem = vb->priv;
508 509
	BUG_ON(!mem);

510
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
511

512 513 514 515 516
	if (!mem->dma.dev)
		mem->dma.dev = q->dev;
	else
		WARN_ON(mem->dma.dev != q->dev);

517 518 519 520 521 522
	switch (vb->memory) {
	case V4L2_MEMORY_MMAP:
	case V4L2_MEMORY_USERPTR:
		if (0 == vb->baddr) {
			/* no userspace addr -- kernel bounce buffer */
			pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
523 524 525
			err = videobuf_dma_init_kernel(&mem->dma,
						       DMA_FROM_DEVICE,
						       pages);
526 527
			if (0 != err)
				return err;
528
		} else if (vb->memory == V4L2_MEMORY_USERPTR) {
529
			/* dma directly to userspace */
530 531 532
			err = videobuf_dma_init_user(&mem->dma,
						     DMA_FROM_DEVICE,
						     vb->baddr, vb->bsize);
533 534
			if (0 != err)
				return err;
535 536 537 538 539 540 541
		} else {
			/* NOTE: HACK: videobuf_iolock on V4L2_MEMORY_MMAP
			buffers can only be called from videobuf_qbuf
			we take current->mm->mmap_sem there, to prevent
			locking inversion, so don't take it here */

			err = videobuf_dma_init_user_locked(&mem->dma,
542
						      DMA_FROM_DEVICE,
543 544 545
						      vb->baddr, vb->bsize);
			if (0 != err)
				return err;
546 547 548 549 550 551 552 553 554 555 556 557 558
		}
		break;
	case V4L2_MEMORY_OVERLAY:
		if (NULL == fbuf)
			return -EINVAL;
		/* FIXME: need sanity checks for vb->boff */
		/*
		 * Using a double cast to avoid compiler warnings when
		 * building for PAE. Compiler doesn't like direct casting
		 * of a 32 bit ptr to 64 bit integer.
		 */
		bus   = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
		pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
559
		err = videobuf_dma_init_overlay(&mem->dma, DMA_FROM_DEVICE,
560 561 562 563 564 565 566
						bus, pages);
		if (0 != err)
			return err;
		break;
	default:
		BUG();
	}
567
	err = videobuf_dma_map(q->dev, &mem->dma);
568 569 570 571 572 573 574 575 576
	if (0 != err)
		return err;

	return 0;
}

static int __videobuf_sync(struct videobuf_queue *q,
			   struct videobuf_buffer *buf)
{
577
	struct videobuf_dma_sg_memory *mem = buf->priv;
578 579
	BUG_ON(!mem || !mem->dma.sglen);

580
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
581
	MAGIC_CHECK(mem->dma.magic, MAGIC_DMABUF);
582

583
	dma_sync_sg_for_cpu(q->dev, mem->dma.sglist,
584
			    mem->dma.sglen, mem->dma.direction);
585 586

	return 0;
587 588 589
}

static int __videobuf_mmap_mapper(struct videobuf_queue *q,
590 591
				  struct videobuf_buffer *buf,
				  struct vm_area_struct *vma)
592
{
593
	struct videobuf_dma_sg_memory *mem = buf->priv;
594
	struct videobuf_mapping *map;
595
	unsigned int first, last, size = 0, i;
596 597 598 599
	int retval;

	retval = -EINVAL;

600 601 602
	BUG_ON(!mem);
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);

603 604
	/* look for first buffer to map */
	for (first = 0; first < VIDEO_MAX_FRAME; first++) {
605 606
		if (buf == q->bufs[first]) {
			size = PAGE_ALIGN(q->bufs[first]->bsize);
607
			break;
608
		}
609
	}
610 611

	/* paranoia, should never happen since buf is always valid. */
612
	if (!size) {
613
		dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
614
				(vma->vm_pgoff << PAGE_SHIFT));
615 616 617
		goto done;
	}

618
	last = first;
619 620 621

	/* create mapping + update buffer list */
	retval = -ENOMEM;
622
	map = kmalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
623 624
	if (NULL == map)
		goto done;
625 626 627 628 629

	size = 0;
	for (i = first; i <= last; i++) {
		if (NULL == q->bufs[i])
			continue;
630
		q->bufs[i]->map   = map;
631
		q->bufs[i]->baddr = vma->vm_start + size;
632
		size += PAGE_ALIGN(q->bufs[i]->bsize);
633
	}
634

635 636 637
	map->count    = 1;
	map->q        = q;
	vma->vm_ops   = &videobuf_vm_ops;
638
	vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
639 640
	vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
	vma->vm_private_data = map;
641 642
	dprintk(1, "mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
		map, q, vma->vm_start, vma->vm_end, vma->vm_pgoff, first, last);
643 644
	retval = 0;

645
done:
646 647 648
	return retval;
}

649
static struct videobuf_qtype_ops sg_ops = {
650 651
	.magic        = MAGIC_QTYPE_OPS,

652
	.alloc_vb     = __videobuf_alloc_vb,
653 654 655
	.iolock       = __videobuf_iolock,
	.sync         = __videobuf_sync,
	.mmap_mapper  = __videobuf_mmap_mapper,
656
	.vaddr        = __videobuf_to_vaddr,
657 658
};

659
void *videobuf_sg_alloc(size_t size)
660 661 662 663
{
	struct videobuf_queue q;

	/* Required to make generic handler to call __videobuf_alloc */
664
	q.int_ops = &sg_ops;
665

666
	q.msize = size;
667

668
	return videobuf_alloc_vb(&q);
669
}
670
EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
671

672
void videobuf_queue_sg_init(struct videobuf_queue *q,
673
			 const struct videobuf_queue_ops *ops,
674
			 struct device *dev,
675 676 677 678
			 spinlock_t *irqlock,
			 enum v4l2_buf_type type,
			 enum v4l2_field field,
			 unsigned int msize,
679 680
			 void *priv,
			 struct mutex *ext_lock)
681
{
682
	videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
683
				 priv, &sg_ops, ext_lock);
684
}
685
EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
686