videobuf2-dma-sg.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * videobuf2-dma-sg.c - dma scatter/gather memory allocator for videobuf2
  3. *
  4. * Copyright (C) 2010 Samsung Electronics
  5. *
  6. * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/mm.h>
  14. #include <linux/refcount.h>
  15. #include <linux/scatterlist.h>
  16. #include <linux/sched.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <media/videobuf2-v4l2.h>
  20. #include <media/videobuf2-memops.h>
  21. #include <media/videobuf2-dma-sg.h>
  22. static int debug;
  23. module_param(debug, int, 0644);
  24. #define dprintk(level, fmt, arg...) \
  25. do { \
  26. if (debug >= level) \
  27. printk(KERN_DEBUG "vb2-dma-sg: " fmt, ## arg); \
  28. } while (0)
  29. struct vb2_dma_sg_buf {
  30. struct device *dev;
  31. void *vaddr;
  32. struct page **pages;
  33. struct frame_vector *vec;
  34. int offset;
  35. enum dma_data_direction dma_dir;
  36. struct sg_table sg_table;
  37. /*
  38. * This will point to sg_table when used with the MMAP or USERPTR
  39. * memory model, and to the dma_buf sglist when used with the
  40. * DMABUF memory model.
  41. */
  42. struct sg_table *dma_sgt;
  43. size_t size;
  44. unsigned int num_pages;
  45. refcount_t refcount;
  46. struct vb2_vmarea_handler handler;
  47. struct dma_buf_attachment *db_attach;
  48. };
  49. static void vb2_dma_sg_put(void *buf_priv);
  50. static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,
  51. gfp_t gfp_flags)
  52. {
  53. unsigned int last_page = 0;
  54. int size = buf->size;
  55. while (size > 0) {
  56. struct page *pages;
  57. int order;
  58. int i;
  59. order = get_order(size);
  60. /* Dont over allocate*/
  61. if ((PAGE_SIZE << order) > size)
  62. order--;
  63. pages = NULL;
  64. while (!pages) {
  65. pages = alloc_pages(GFP_KERNEL | __GFP_ZERO |
  66. __GFP_NOWARN | gfp_flags, order);
  67. if (pages)
  68. break;
  69. if (order == 0) {
  70. while (last_page--)
  71. __free_page(buf->pages[last_page]);
  72. return -ENOMEM;
  73. }
  74. order--;
  75. }
  76. split_page(pages, order);
  77. for (i = 0; i < (1 << order); i++)
  78. buf->pages[last_page++] = &pages[i];
  79. size -= PAGE_SIZE << order;
  80. }
  81. return 0;
  82. }
  83. static void *vb2_dma_sg_alloc(struct device *dev, unsigned long dma_attrs,
  84. unsigned long size, enum dma_data_direction dma_dir,
  85. gfp_t gfp_flags)
  86. {
  87. struct vb2_dma_sg_buf *buf;
  88. struct sg_table *sgt;
  89. int ret;
  90. int num_pages;
  91. if (WARN_ON(!dev))
  92. return ERR_PTR(-EINVAL);
  93. buf = kzalloc(sizeof *buf, GFP_KERNEL);
  94. if (!buf)
  95. return ERR_PTR(-ENOMEM);
  96. buf->vaddr = NULL;
  97. buf->dma_dir = dma_dir;
  98. buf->offset = 0;
  99. buf->size = size;
  100. /* size is already page aligned */
  101. buf->num_pages = size >> PAGE_SHIFT;
  102. buf->dma_sgt = &buf->sg_table;
  103. buf->pages = kzalloc(buf->num_pages * sizeof(struct page *),
  104. GFP_KERNEL);
  105. if (!buf->pages)
  106. goto fail_pages_array_alloc;
  107. ret = vb2_dma_sg_alloc_compacted(buf, gfp_flags);
  108. if (ret)
  109. goto fail_pages_alloc;
  110. ret = sg_alloc_table_from_pages(buf->dma_sgt, buf->pages,
  111. buf->num_pages, 0, size, GFP_KERNEL);
  112. if (ret)
  113. goto fail_table_alloc;
  114. /* Prevent the device from being released while the buffer is used */
  115. buf->dev = get_device(dev);
  116. sgt = &buf->sg_table;
  117. /*
  118. * No need to sync to the device, this will happen later when the
  119. * prepare() memop is called.
  120. */
  121. sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
  122. buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
  123. if (!sgt->nents)
  124. goto fail_map;
  125. buf->handler.refcount = &buf->refcount;
  126. buf->handler.put = vb2_dma_sg_put;
  127. buf->handler.arg = buf;
  128. refcount_set(&buf->refcount, 1);
  129. dprintk(1, "%s: Allocated buffer of %d pages\n",
  130. __func__, buf->num_pages);
  131. return buf;
  132. fail_map:
  133. put_device(buf->dev);
  134. sg_free_table(buf->dma_sgt);
  135. fail_table_alloc:
  136. num_pages = buf->num_pages;
  137. while (num_pages--)
  138. __free_page(buf->pages[num_pages]);
  139. fail_pages_alloc:
  140. kfree(buf->pages);
  141. fail_pages_array_alloc:
  142. kfree(buf);
  143. return ERR_PTR(-ENOMEM);
  144. }
  145. static void vb2_dma_sg_put(void *buf_priv)
  146. {
  147. struct vb2_dma_sg_buf *buf = buf_priv;
  148. struct sg_table *sgt = &buf->sg_table;
  149. int i = buf->num_pages;
  150. if (refcount_dec_and_test(&buf->refcount)) {
  151. dprintk(1, "%s: Freeing buffer of %d pages\n", __func__,
  152. buf->num_pages);
  153. dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
  154. buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
  155. if (buf->vaddr)
  156. vm_unmap_ram(buf->vaddr, buf->num_pages);
  157. sg_free_table(buf->dma_sgt);
  158. while (--i >= 0)
  159. __free_page(buf->pages[i]);
  160. kfree(buf->pages);
  161. put_device(buf->dev);
  162. kfree(buf);
  163. }
  164. }
  165. static void vb2_dma_sg_prepare(void *buf_priv)
  166. {
  167. struct vb2_dma_sg_buf *buf = buf_priv;
  168. struct sg_table *sgt = buf->dma_sgt;
  169. /* DMABUF exporter will flush the cache for us */
  170. if (buf->db_attach)
  171. return;
  172. dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents,
  173. buf->dma_dir);
  174. }
  175. static void vb2_dma_sg_finish(void *buf_priv)
  176. {
  177. struct vb2_dma_sg_buf *buf = buf_priv;
  178. struct sg_table *sgt = buf->dma_sgt;
  179. /* DMABUF exporter will flush the cache for us */
  180. if (buf->db_attach)
  181. return;
  182. dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir);
  183. }
  184. static void *vb2_dma_sg_get_userptr(struct device *dev, unsigned long vaddr,
  185. unsigned long size,
  186. enum dma_data_direction dma_dir)
  187. {
  188. struct vb2_dma_sg_buf *buf;
  189. struct sg_table *sgt;
  190. struct frame_vector *vec;
  191. if (WARN_ON(!dev))
  192. return ERR_PTR(-EINVAL);
  193. buf = kzalloc(sizeof *buf, GFP_KERNEL);
  194. if (!buf)
  195. return ERR_PTR(-ENOMEM);
  196. buf->vaddr = NULL;
  197. buf->dev = dev;
  198. buf->dma_dir = dma_dir;
  199. buf->offset = vaddr & ~PAGE_MASK;
  200. buf->size = size;
  201. buf->dma_sgt = &buf->sg_table;
  202. vec = vb2_create_framevec(vaddr, size, buf->dma_dir == DMA_FROM_DEVICE);
  203. if (IS_ERR(vec))
  204. goto userptr_fail_pfnvec;
  205. buf->vec = vec;
  206. buf->pages = frame_vector_pages(vec);
  207. if (IS_ERR(buf->pages))
  208. goto userptr_fail_sgtable;
  209. buf->num_pages = frame_vector_count(vec);
  210. if (sg_alloc_table_from_pages(buf->dma_sgt, buf->pages,
  211. buf->num_pages, buf->offset, size, 0))
  212. goto userptr_fail_sgtable;
  213. sgt = &buf->sg_table;
  214. /*
  215. * No need to sync to the device, this will happen later when the
  216. * prepare() memop is called.
  217. */
  218. sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
  219. buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
  220. if (!sgt->nents)
  221. goto userptr_fail_map;
  222. return buf;
  223. userptr_fail_map:
  224. sg_free_table(&buf->sg_table);
  225. userptr_fail_sgtable:
  226. vb2_destroy_framevec(vec);
  227. userptr_fail_pfnvec:
  228. kfree(buf);
  229. return ERR_PTR(-ENOMEM);
  230. }
  231. /*
  232. * @put_userptr: inform the allocator that a USERPTR buffer will no longer
  233. * be used
  234. */
  235. static void vb2_dma_sg_put_userptr(void *buf_priv)
  236. {
  237. struct vb2_dma_sg_buf *buf = buf_priv;
  238. struct sg_table *sgt = &buf->sg_table;
  239. int i = buf->num_pages;
  240. dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
  241. __func__, buf->num_pages);
  242. dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir,
  243. DMA_ATTR_SKIP_CPU_SYNC);
  244. if (buf->vaddr)
  245. vm_unmap_ram(buf->vaddr, buf->num_pages);
  246. sg_free_table(buf->dma_sgt);
  247. while (--i >= 0) {
  248. if (buf->dma_dir == DMA_FROM_DEVICE)
  249. set_page_dirty_lock(buf->pages[i]);
  250. }
  251. vb2_destroy_framevec(buf->vec);
  252. kfree(buf);
  253. }
  254. static void *vb2_dma_sg_vaddr(void *buf_priv)
  255. {
  256. struct vb2_dma_sg_buf *buf = buf_priv;
  257. BUG_ON(!buf);
  258. if (!buf->vaddr) {
  259. if (buf->db_attach)
  260. buf->vaddr = dma_buf_vmap(buf->db_attach->dmabuf);
  261. else
  262. buf->vaddr = vm_map_ram(buf->pages,
  263. buf->num_pages, -1, PAGE_KERNEL);
  264. }
  265. /* add offset in case userptr is not page-aligned */
  266. return buf->vaddr ? buf->vaddr + buf->offset : NULL;
  267. }
  268. static unsigned int vb2_dma_sg_num_users(void *buf_priv)
  269. {
  270. struct vb2_dma_sg_buf *buf = buf_priv;
  271. return refcount_read(&buf->refcount);
  272. }
  273. static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma)
  274. {
  275. struct vb2_dma_sg_buf *buf = buf_priv;
  276. unsigned long uaddr = vma->vm_start;
  277. unsigned long usize = vma->vm_end - vma->vm_start;
  278. int i = 0;
  279. if (!buf) {
  280. printk(KERN_ERR "No memory to map\n");
  281. return -EINVAL;
  282. }
  283. do {
  284. int ret;
  285. ret = vm_insert_page(vma, uaddr, buf->pages[i++]);
  286. if (ret) {
  287. printk(KERN_ERR "Remapping memory, error: %d\n", ret);
  288. return ret;
  289. }
  290. uaddr += PAGE_SIZE;
  291. usize -= PAGE_SIZE;
  292. } while (usize > 0);
  293. /*
  294. * Use common vm_area operations to track buffer refcount.
  295. */
  296. vma->vm_private_data = &buf->handler;
  297. vma->vm_ops = &vb2_common_vm_ops;
  298. vma->vm_ops->open(vma);
  299. return 0;
  300. }
  301. /*********************************************/
  302. /* DMABUF ops for exporters */
  303. /*********************************************/
  304. struct vb2_dma_sg_attachment {
  305. struct sg_table sgt;
  306. enum dma_data_direction dma_dir;
  307. };
  308. static int vb2_dma_sg_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev,
  309. struct dma_buf_attachment *dbuf_attach)
  310. {
  311. struct vb2_dma_sg_attachment *attach;
  312. unsigned int i;
  313. struct scatterlist *rd, *wr;
  314. struct sg_table *sgt;
  315. struct vb2_dma_sg_buf *buf = dbuf->priv;
  316. int ret;
  317. attach = kzalloc(sizeof(*attach), GFP_KERNEL);
  318. if (!attach)
  319. return -ENOMEM;
  320. sgt = &attach->sgt;
  321. /* Copy the buf->base_sgt scatter list to the attachment, as we can't
  322. * map the same scatter list to multiple attachments at the same time.
  323. */
  324. ret = sg_alloc_table(sgt, buf->dma_sgt->orig_nents, GFP_KERNEL);
  325. if (ret) {
  326. kfree(attach);
  327. return -ENOMEM;
  328. }
  329. rd = buf->dma_sgt->sgl;
  330. wr = sgt->sgl;
  331. for (i = 0; i < sgt->orig_nents; ++i) {
  332. sg_set_page(wr, sg_page(rd), rd->length, rd->offset);
  333. rd = sg_next(rd);
  334. wr = sg_next(wr);
  335. }
  336. attach->dma_dir = DMA_NONE;
  337. dbuf_attach->priv = attach;
  338. return 0;
  339. }
  340. static void vb2_dma_sg_dmabuf_ops_detach(struct dma_buf *dbuf,
  341. struct dma_buf_attachment *db_attach)
  342. {
  343. struct vb2_dma_sg_attachment *attach = db_attach->priv;
  344. struct sg_table *sgt;
  345. if (!attach)
  346. return;
  347. sgt = &attach->sgt;
  348. /* release the scatterlist cache */
  349. if (attach->dma_dir != DMA_NONE)
  350. dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
  351. attach->dma_dir);
  352. sg_free_table(sgt);
  353. kfree(attach);
  354. db_attach->priv = NULL;
  355. }
  356. static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
  357. struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
  358. {
  359. struct vb2_dma_sg_attachment *attach = db_attach->priv;
  360. /* stealing dmabuf mutex to serialize map/unmap operations */
  361. struct mutex *lock = &db_attach->dmabuf->lock;
  362. struct sg_table *sgt;
  363. mutex_lock(lock);
  364. sgt = &attach->sgt;
  365. /* return previously mapped sg table */
  366. if (attach->dma_dir == dma_dir) {
  367. mutex_unlock(lock);
  368. return sgt;
  369. }
  370. /* release any previous cache */
  371. if (attach->dma_dir != DMA_NONE) {
  372. dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
  373. attach->dma_dir);
  374. attach->dma_dir = DMA_NONE;
  375. }
  376. /* mapping to the client with new direction */
  377. sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
  378. dma_dir);
  379. if (!sgt->nents) {
  380. pr_err("failed to map scatterlist\n");
  381. mutex_unlock(lock);
  382. return ERR_PTR(-EIO);
  383. }
  384. attach->dma_dir = dma_dir;
  385. mutex_unlock(lock);
  386. return sgt;
  387. }
  388. static void vb2_dma_sg_dmabuf_ops_unmap(struct dma_buf_attachment *db_attach,
  389. struct sg_table *sgt, enum dma_data_direction dma_dir)
  390. {
  391. /* nothing to be done here */
  392. }
  393. static void vb2_dma_sg_dmabuf_ops_release(struct dma_buf *dbuf)
  394. {
  395. /* drop reference obtained in vb2_dma_sg_get_dmabuf */
  396. vb2_dma_sg_put(dbuf->priv);
  397. }
  398. static void *vb2_dma_sg_dmabuf_ops_kmap(struct dma_buf *dbuf, unsigned long pgnum)
  399. {
  400. struct vb2_dma_sg_buf *buf = dbuf->priv;
  401. return buf->vaddr ? buf->vaddr + pgnum * PAGE_SIZE : NULL;
  402. }
  403. static void *vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf)
  404. {
  405. struct vb2_dma_sg_buf *buf = dbuf->priv;
  406. return vb2_dma_sg_vaddr(buf);
  407. }
  408. static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
  409. struct vm_area_struct *vma)
  410. {
  411. return vb2_dma_sg_mmap(dbuf->priv, vma);
  412. }
  413. static struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
  414. .attach = vb2_dma_sg_dmabuf_ops_attach,
  415. .detach = vb2_dma_sg_dmabuf_ops_detach,
  416. .map_dma_buf = vb2_dma_sg_dmabuf_ops_map,
  417. .unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap,
  418. .map = vb2_dma_sg_dmabuf_ops_kmap,
  419. .map_atomic = vb2_dma_sg_dmabuf_ops_kmap,
  420. .vmap = vb2_dma_sg_dmabuf_ops_vmap,
  421. .mmap = vb2_dma_sg_dmabuf_ops_mmap,
  422. .release = vb2_dma_sg_dmabuf_ops_release,
  423. };
  424. static struct dma_buf *vb2_dma_sg_get_dmabuf(void *buf_priv, unsigned long flags)
  425. {
  426. struct vb2_dma_sg_buf *buf = buf_priv;
  427. struct dma_buf *dbuf;
  428. DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
  429. exp_info.ops = &vb2_dma_sg_dmabuf_ops;
  430. exp_info.size = buf->size;
  431. exp_info.flags = flags;
  432. exp_info.priv = buf;
  433. if (WARN_ON(!buf->dma_sgt))
  434. return NULL;
  435. dbuf = dma_buf_export(&exp_info);
  436. if (IS_ERR(dbuf))
  437. return NULL;
  438. /* dmabuf keeps reference to vb2 buffer */
  439. refcount_inc(&buf->refcount);
  440. return dbuf;
  441. }
  442. /*********************************************/
  443. /* callbacks for DMABUF buffers */
  444. /*********************************************/
  445. static int vb2_dma_sg_map_dmabuf(void *mem_priv)
  446. {
  447. struct vb2_dma_sg_buf *buf = mem_priv;
  448. struct sg_table *sgt;
  449. if (WARN_ON(!buf->db_attach)) {
  450. pr_err("trying to pin a non attached buffer\n");
  451. return -EINVAL;
  452. }
  453. if (WARN_ON(buf->dma_sgt)) {
  454. pr_err("dmabuf buffer is already pinned\n");
  455. return 0;
  456. }
  457. /* get the associated scatterlist for this buffer */
  458. sgt = dma_buf_map_attachment(buf->db_attach, buf->dma_dir);
  459. if (IS_ERR(sgt)) {
  460. pr_err("Error getting dmabuf scatterlist\n");
  461. return -EINVAL;
  462. }
  463. buf->dma_sgt = sgt;
  464. buf->vaddr = NULL;
  465. return 0;
  466. }
  467. static void vb2_dma_sg_unmap_dmabuf(void *mem_priv)
  468. {
  469. struct vb2_dma_sg_buf *buf = mem_priv;
  470. struct sg_table *sgt = buf->dma_sgt;
  471. if (WARN_ON(!buf->db_attach)) {
  472. pr_err("trying to unpin a not attached buffer\n");
  473. return;
  474. }
  475. if (WARN_ON(!sgt)) {
  476. pr_err("dmabuf buffer is already unpinned\n");
  477. return;
  478. }
  479. if (buf->vaddr) {
  480. dma_buf_vunmap(buf->db_attach->dmabuf, buf->vaddr);
  481. buf->vaddr = NULL;
  482. }
  483. dma_buf_unmap_attachment(buf->db_attach, sgt, buf->dma_dir);
  484. buf->dma_sgt = NULL;
  485. }
  486. static void vb2_dma_sg_detach_dmabuf(void *mem_priv)
  487. {
  488. struct vb2_dma_sg_buf *buf = mem_priv;
  489. /* if vb2 works correctly you should never detach mapped buffer */
  490. if (WARN_ON(buf->dma_sgt))
  491. vb2_dma_sg_unmap_dmabuf(buf);
  492. /* detach this attachment */
  493. dma_buf_detach(buf->db_attach->dmabuf, buf->db_attach);
  494. kfree(buf);
  495. }
  496. static void *vb2_dma_sg_attach_dmabuf(struct device *dev, struct dma_buf *dbuf,
  497. unsigned long size, enum dma_data_direction dma_dir)
  498. {
  499. struct vb2_dma_sg_buf *buf;
  500. struct dma_buf_attachment *dba;
  501. if (WARN_ON(!dev))
  502. return ERR_PTR(-EINVAL);
  503. if (dbuf->size < size)
  504. return ERR_PTR(-EFAULT);
  505. buf = kzalloc(sizeof(*buf), GFP_KERNEL);
  506. if (!buf)
  507. return ERR_PTR(-ENOMEM);
  508. buf->dev = dev;
  509. /* create attachment for the dmabuf with the user device */
  510. dba = dma_buf_attach(dbuf, buf->dev);
  511. if (IS_ERR(dba)) {
  512. pr_err("failed to attach dmabuf\n");
  513. kfree(buf);
  514. return dba;
  515. }
  516. buf->dma_dir = dma_dir;
  517. buf->size = size;
  518. buf->db_attach = dba;
  519. return buf;
  520. }
  521. static void *vb2_dma_sg_cookie(void *buf_priv)
  522. {
  523. struct vb2_dma_sg_buf *buf = buf_priv;
  524. return buf->dma_sgt;
  525. }
  526. const struct vb2_mem_ops vb2_dma_sg_memops = {
  527. .alloc = vb2_dma_sg_alloc,
  528. .put = vb2_dma_sg_put,
  529. .get_userptr = vb2_dma_sg_get_userptr,
  530. .put_userptr = vb2_dma_sg_put_userptr,
  531. .prepare = vb2_dma_sg_prepare,
  532. .finish = vb2_dma_sg_finish,
  533. .vaddr = vb2_dma_sg_vaddr,
  534. .mmap = vb2_dma_sg_mmap,
  535. .num_users = vb2_dma_sg_num_users,
  536. .get_dmabuf = vb2_dma_sg_get_dmabuf,
  537. .map_dmabuf = vb2_dma_sg_map_dmabuf,
  538. .unmap_dmabuf = vb2_dma_sg_unmap_dmabuf,
  539. .attach_dmabuf = vb2_dma_sg_attach_dmabuf,
  540. .detach_dmabuf = vb2_dma_sg_detach_dmabuf,
  541. .cookie = vb2_dma_sg_cookie,
  542. };
  543. EXPORT_SYMBOL_GPL(vb2_dma_sg_memops);
  544. MODULE_DESCRIPTION("dma scatter/gather memory handling routines for videobuf2");
  545. MODULE_AUTHOR("Andrzej Pietrasiewicz");
  546. MODULE_LICENSE("GPL");