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