videobuf-dma-sg.c 16.1 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;

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

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

91 92 93 94 95 96 97
/*
 * 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,
						int nr_pages, int offset)
98 99
{
	struct scatterlist *sglist;
100
	int i;
101 102 103

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

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

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

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

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

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

140
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
141 142 143

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

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

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

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

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

179 180 181 182
	dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
		data, size, dma->nr_pages);

	err = get_user_pages(current, current->mm,
183 184 185
			     data & PAGE_MASK, dma->nr_pages,
			     rw == READ, 1, /* force */
			     dma->pages, NULL);
186

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

195 196 197 198
int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
			   unsigned long data, unsigned long size)
{
	int ret;
199

200 201 202 203 204 205
	down_read(&current->mm->mmap_sem);
	ret = videobuf_dma_init_user_locked(dma, direction, data, size);
	up_read(&current->mm->mmap_sem);

	return ret;
}
206
EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
207

208 209 210
int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
			     int nr_pages)
{
211 212
	dprintk(1, "init kernel [%d pages]\n", nr_pages);

213
	dma->direction = direction;
214 215
	dma->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
	if (NULL == dma->vaddr) {
216
		dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
217 218
		return -ENOMEM;
	}
219 220

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

224
	memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT);
225
	dma->nr_pages = nr_pages;
226

227 228
	return 0;
}
229
EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
230 231 232 233

int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
			      dma_addr_t addr, int nr_pages)
{
234 235
	dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
		nr_pages, (unsigned long)addr);
236
	dma->direction = direction;
237

238 239 240 241 242
	if (0 == addr)
		return -EINVAL;

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

244 245
	return 0;
}
246
EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
247

248
int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
249
{
250
	MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
251 252 253 254 255 256
	BUG_ON(0 == dma->nr_pages);

	if (dma->pages) {
		dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
						   dma->offset);
	}
257 258
	if (dma->vaddr) {
		dma->sglist = videobuf_vmalloc_to_sg(dma->vaddr,
259
						     dma->nr_pages);
260 261
	}
	if (dma->bus_addr) {
262
		dma->sglist = vmalloc(sizeof(*dma->sglist));
263
		if (NULL != dma->sglist) {
264 265 266 267 268
			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;
269 270 271
		}
	}
	if (NULL == dma->sglist) {
272
		dprintk(1, "scatterlist is NULL\n");
273 274 275
		return -ENOMEM;
	}
	if (!dma->bus_addr) {
276
		dma->sglen = dma_map_sg(dev, dma->sglist,
277 278 279
					dma->nr_pages, dma->direction);
		if (0 == dma->sglen) {
			printk(KERN_WARNING
280
			       "%s: videobuf_map_sg failed\n", __func__);
281
			vfree(dma->sglist);
282 283
			dma->sglist = NULL;
			dma->sglen = 0;
284
			return -ENOMEM;
285 286
		}
	}
287

288 289
	return 0;
}
290
EXPORT_SYMBOL_GPL(videobuf_dma_map);
291

292
int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
293
{
294
	MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
295

296 297 298
	if (!dma->sglen)
		return 0;

299
	dma_unmap_sg(dev, dma->sglist, dma->sglen, dma->direction);
300

301
	vfree(dma->sglist);
302 303
	dma->sglist = NULL;
	dma->sglen = 0;
304

305 306
	return 0;
}
307
EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
308 309 310

int videobuf_dma_free(struct videobuf_dmabuf *dma)
{
311 312
	int i;
	MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
313 314 315
	BUG_ON(dma->sglen);

	if (dma->pages) {
316
		for (i = 0; i < dma->nr_pages; i++)
317 318 319 320 321
			page_cache_release(dma->pages[i]);
		kfree(dma->pages);
		dma->pages = NULL;
	}

322 323
	vfree(dma->vaddr);
	dma->vaddr = NULL;
324

325
	if (dma->bus_addr)
326
		dma->bus_addr = 0;
327
	dma->direction = DMA_NONE;
328

329 330
	return 0;
}
331
EXPORT_SYMBOL_GPL(videobuf_dma_free);
332 333 334

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

335
static void videobuf_vm_open(struct vm_area_struct *vma)
336 337 338
{
	struct videobuf_mapping *map = vma->vm_private_data;

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

342 343 344
	map->count++;
}

345
static void videobuf_vm_close(struct vm_area_struct *vma)
346 347 348
{
	struct videobuf_mapping *map = vma->vm_private_data;
	struct videobuf_queue *q = map->q;
349
	struct videobuf_dma_sg_memory *mem;
350 351
	int i;

352 353
	dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
		map->count, vma->vm_start, vma->vm_end);
354 355 356

	map->count--;
	if (0 == map->count) {
357
		dprintk(1, "munmap %p q=%p\n", map, q);
358
		mutex_lock(&q->vb_lock);
359 360 361
		for (i = 0; i < VIDEO_MAX_FRAME; i++) {
			if (NULL == q->bufs[i])
				continue;
362
			mem = q->bufs[i]->priv;
363 364 365
			if (!mem)
				continue;

366
			MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
367

368
			if (q->bufs[i]->map != map)
369
				continue;
370
			q->bufs[i]->map   = NULL;
371
			q->bufs[i]->baddr = 0;
372
			q->ops->buf_release(q, q->bufs[i]);
373
		}
374
		mutex_unlock(&q->vb_lock);
375 376 377 378 379 380 381 382 383 384 385
		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.
 */
386
static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
387 388 389
{
	struct page *page;

390 391 392 393
	dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
		(unsigned long)vmf->virtual_address,
		vma->vm_start, vma->vm_end);

394 395
	page = alloc_page(GFP_USER | __GFP_DMA32);
	if (!page)
396
		return VM_FAULT_OOM;
397
	clear_user_highpage(page, (unsigned long)vmf->virtual_address);
398
	vmf->page = page;
399

400
	return 0;
401 402
}

403 404 405 406
static const struct vm_operations_struct videobuf_vm_ops = {
	.open	= videobuf_vm_open,
	.close	= videobuf_vm_close,
	.fault	= videobuf_vm_fault,
407 408 409
};

/* ---------------------------------------------------------------------
410
 * SG handlers for the generic methods
411 412 413 414 415
 */

/* Allocated area consists on 3 parts:
	struct video_buffer
	struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
416
	struct videobuf_dma_sg_memory
417 418
 */

419
static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
420
{
421
	struct videobuf_dma_sg_memory *mem;
422 423
	struct videobuf_buffer *vb;

424
	vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
425 426
	if (!vb)
		return vb;
427

428 429
	mem = vb->priv = ((char *)vb) + size;
	mem->magic = MAGIC_SG_MEM;
430 431 432

	videobuf_dma_init(&mem->dma);

433 434 435
	dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
		__func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
		mem, (long)sizeof(*mem));
436 437 438 439

	return vb;
}

440
static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
441 442 443 444 445 446
{
	struct videobuf_dma_sg_memory *mem = buf->priv;
	BUG_ON(!mem);

	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);

447
	return mem->dma.vaddr;
448 449
}

450 451 452
static int __videobuf_iolock(struct videobuf_queue *q,
			     struct videobuf_buffer *vb,
			     struct v4l2_framebuffer *fbuf)
453
{
454
	int err, pages;
455
	dma_addr_t bus;
456
	struct videobuf_dma_sg_memory *mem = vb->priv;
457 458
	BUG_ON(!mem);

459
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
460 461 462 463 464 465 466

	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;
467 468 469
			err = videobuf_dma_init_kernel(&mem->dma,
						       DMA_FROM_DEVICE,
						       pages);
470 471
			if (0 != err)
				return err;
472
		} else if (vb->memory == V4L2_MEMORY_USERPTR) {
473
			/* dma directly to userspace */
474 475 476
			err = videobuf_dma_init_user(&mem->dma,
						     DMA_FROM_DEVICE,
						     vb->baddr, vb->bsize);
477 478
			if (0 != err)
				return err;
479 480 481 482 483 484 485
		} 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,
486
						      DMA_FROM_DEVICE,
487 488 489
						      vb->baddr, vb->bsize);
			if (0 != err)
				return err;
490 491 492 493 494 495 496 497 498 499 500 501 502
		}
		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;
503
		err = videobuf_dma_init_overlay(&mem->dma, DMA_FROM_DEVICE,
504 505 506 507 508 509 510
						bus, pages);
		if (0 != err)
			return err;
		break;
	default:
		BUG();
	}
511
	err = videobuf_dma_map(q->dev, &mem->dma);
512 513 514 515 516 517 518 519 520
	if (0 != err)
		return err;

	return 0;
}

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

524
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
525
	MAGIC_CHECK(mem->dma.magic, MAGIC_DMABUF);
526

527
	dma_sync_sg_for_cpu(q->dev, mem->dma.sglist,
528
			    mem->dma.sglen, mem->dma.direction);
529 530

	return 0;
531 532 533
}

static int __videobuf_mmap_mapper(struct videobuf_queue *q,
534 535
				  struct videobuf_buffer *buf,
				  struct vm_area_struct *vma)
536
{
537
	struct videobuf_dma_sg_memory *mem = buf->priv;
538
	struct videobuf_mapping *map;
539
	unsigned int first, last, size = 0, i;
540 541 542 543
	int retval;

	retval = -EINVAL;

544 545 546 547 548 549 550 551
	/* This function maintains backwards compatibility with V4L1 and will
	 * map more than one buffer if the vma length is equal to the combined
	 * size of multiple buffers than it will map them together.  See
	 * VIDIOCGMBUF in the v4l spec
	 *
	 * TODO: Allow drivers to specify if they support this mode
	 */

552 553 554
	BUG_ON(!mem);
	MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);

555 556
	/* look for first buffer to map */
	for (first = 0; first < VIDEO_MAX_FRAME; first++) {
557 558
		if (buf == q->bufs[first]) {
			size = PAGE_ALIGN(q->bufs[first]->bsize);
559
			break;
560
		}
561
	}
562 563

	/* paranoia, should never happen since buf is always valid. */
564
	if (!size) {
565
		dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
566
				(vma->vm_pgoff << PAGE_SHIFT));
567 568 569
		goto done;
	}

570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
	last = first;
#ifdef CONFIG_VIDEO_V4L1_COMPAT
	if (size != (vma->vm_end - vma->vm_start)) {
		/* look for last buffer to map */
		for (last = first + 1; last < VIDEO_MAX_FRAME; last++) {
			if (NULL == q->bufs[last])
				continue;
			if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
				continue;
			if (q->bufs[last]->map) {
				retval = -EBUSY;
				goto done;
			}
			size += PAGE_ALIGN(q->bufs[last]->bsize);
			if (size == (vma->vm_end - vma->vm_start))
				break;
		}
		if (VIDEO_MAX_FRAME == last) {
			dprintk(1, "mmap app bug: size invalid [size=0x%lx]\n",
					(vma->vm_end - vma->vm_start));
590 591 592
			goto done;
		}
	}
593
#endif
594 595 596

	/* create mapping + update buffer list */
	retval = -ENOMEM;
597
	map = kmalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
598 599
	if (NULL == map)
		goto done;
600 601 602 603 604

	size = 0;
	for (i = first; i <= last; i++) {
		if (NULL == q->bufs[i])
			continue;
605
		q->bufs[i]->map   = map;
606
		q->bufs[i]->baddr = vma->vm_start + size;
607
		size += PAGE_ALIGN(q->bufs[i]->bsize);
608
	}
609

610 611 612 613 614 615
	map->count    = 1;
	map->q        = q;
	vma->vm_ops   = &videobuf_vm_ops;
	vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
	vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
	vma->vm_private_data = map;
616 617
	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);
618 619
	retval = 0;

620
done:
621 622 623
	return retval;
}

624
static struct videobuf_qtype_ops sg_ops = {
625 626
	.magic        = MAGIC_QTYPE_OPS,

627
	.alloc_vb     = __videobuf_alloc_vb,
628 629 630
	.iolock       = __videobuf_iolock,
	.sync         = __videobuf_sync,
	.mmap_mapper  = __videobuf_mmap_mapper,
631
	.vaddr        = __videobuf_to_vaddr,
632 633
};

634
void *videobuf_sg_alloc(size_t size)
635 636 637 638
{
	struct videobuf_queue q;

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

641
	q.msize = size;
642

643
	return videobuf_alloc_vb(&q);
644
}
645
EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
646

647
void videobuf_queue_sg_init(struct videobuf_queue *q,
648
			 const struct videobuf_queue_ops *ops,
649
			 struct device *dev,
650 651 652 653 654 655
			 spinlock_t *irqlock,
			 enum v4l2_buf_type type,
			 enum v4l2_field field,
			 unsigned int msize,
			 void *priv)
{
656
	videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
657
				 priv, &sg_ops);
658
}
659
EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
660