videobuf2-dma-sg.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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. unsigned long 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 = kvmalloc_array(buf->num_pages, sizeof(struct page *),
  104. GFP_KERNEL | __GFP_ZERO);
  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. kvfree(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. kvfree(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, dma_dir == DMA_FROM_DEVICE ||
  203. dma_dir == DMA_BIDIRECTIONAL);
  204. if (IS_ERR(vec))
  205. goto userptr_fail_pfnvec;
  206. buf->vec = vec;
  207. buf->pages = frame_vector_pages(vec);
  208. if (IS_ERR(buf->pages))
  209. goto userptr_fail_sgtable;
  210. buf->num_pages = frame_vector_count(vec);
  211. if (sg_alloc_table_from_pages(buf->dma_sgt, buf->pages,
  212. buf->num_pages, buf->offset, size, 0))
  213. goto userptr_fail_sgtable;
  214. sgt = &buf->sg_table;
  215. /*
  216. * No need to sync to the device, this will happen later when the
  217. * prepare() memop is called.
  218. */
  219. sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
  220. buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
  221. if (!sgt->nents)
  222. goto userptr_fail_map;
  223. return buf;
  224. userptr_fail_map:
  225. sg_free_table(&buf->sg_table);
  226. userptr_fail_sgtable:
  227. vb2_destroy_framevec(vec);
  228. userptr_fail_pfnvec:
  229. kfree(buf);
  230. return ERR_PTR(-ENOMEM);
  231. }
  232. /*
  233. * @put_userptr: inform the allocator that a USERPTR buffer will no longer
  234. * be used
  235. */
  236. static void vb2_dma_sg_put_userptr(void *buf_priv)
  237. {
  238. struct vb2_dma_sg_buf *buf = buf_priv;
  239. struct sg_table *sgt = &buf->sg_table;
  240. int i = buf->num_pages;
  241. dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
  242. __func__, buf->num_pages);
  243. dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir,
  244. DMA_ATTR_SKIP_CPU_SYNC);
  245. if (buf->vaddr)
  246. vm_unmap_ram(buf->vaddr, buf->num_pages);
  247. sg_free_table(buf->dma_sgt);
  248. if (buf->dma_dir == DMA_FROM_DEVICE ||
  249. buf->dma_dir == DMA_BIDIRECTIONAL)
  250. while (--i >= 0)
  251. set_page_dirty_lock(buf->pages[i]);
  252. vb2_destroy_framevec(buf->vec);
  253. kfree(buf);
  254. }
  255. static void *vb2_dma_sg_vaddr(void *buf_priv)
  256. {
  257. struct vb2_dma_sg_buf *buf = buf_priv;
  258. BUG_ON(!buf);
  259. if (!buf->vaddr) {
  260. if (buf->db_attach)
  261. buf->vaddr = dma_buf_vmap(buf->db_attach->dmabuf);
  262. else
  263. buf->vaddr = vm_map_ram(buf->pages,
  264. buf->num_pages, -1, PAGE_KERNEL);
  265. }
  266. /* add offset in case userptr is not page-aligned */
  267. return buf->vaddr ? buf->vaddr + buf->offset : NULL;
  268. }
  269. static unsigned int vb2_dma_sg_num_users(void *buf_priv)
  270. {
  271. struct vb2_dma_sg_buf *buf = buf_priv;
  272. return refcount_read(&buf->refcount);
  273. }
  274. static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma)
  275. {
  276. struct vb2_dma_sg_buf *buf = buf_priv;
  277. unsigned long uaddr = vma->vm_start;
  278. unsigned long usize = vma->vm_end - vma->vm_start;
  279. int i = 0;
  280. if (!buf) {
  281. printk(KERN_ERR "No memory to map\n");
  282. return -EINVAL;
  283. }
  284. do {
  285. int ret;
  286. ret = vm_insert_page(vma, uaddr, buf->pages[i++]);
  287. if (ret) {
  288. printk(KERN_ERR "Remapping memory, error: %d\n", ret);
  289. return ret;
  290. }
  291. uaddr += PAGE_SIZE;
  292. usize -= PAGE_SIZE;
  293. } while (usize > 0);
  294. /*
  295. * Use common vm_area operations to track buffer refcount.
  296. */
  297. vma->vm_private_data = &buf->handler;
  298. vma->vm_ops = &vb2_common_vm_ops;
  299. vma->vm_ops->open(vma);
  300. return 0;
  301. }
  302. /*********************************************/
  303. /* DMABUF ops for exporters */
  304. /*********************************************/
  305. struct vb2_dma_sg_attachment {
  306. struct sg_table sgt;
  307. enum dma_data_direction dma_dir;
  308. };
  309. static int vb2_dma_sg_dmabuf_ops_attach(struct dma_buf *dbuf,
  310. struct dma_buf_attachment *dbuf_attach)
  311. {
  312. struct vb2_dma_sg_attachment *attach;
  313. unsigned int i;
  314. struct scatterlist *rd, *wr;
  315. struct sg_table *sgt;
  316. struct vb2_dma_sg_buf *buf = dbuf->priv;
  317. int ret;
  318. attach = kzalloc(sizeof(*attach), GFP_KERNEL);
  319. if (!attach)
  320. return -ENOMEM;
  321. sgt = &attach->sgt;
  322. /* Copy the buf->base_sgt scatter list to the attachment, as we can't
  323. * map the same scatter list to multiple attachments at the same time.
  324. */
  325. ret = sg_alloc_table(sgt, buf->dma_sgt->orig_nents, GFP_KERNEL);
  326. if (ret) {
  327. kfree(attach);
  328. return -ENOMEM;
  329. }
  330. rd = buf->dma_sgt->sgl;
  331. wr = sgt->sgl;
  332. for (i = 0; i < sgt->orig_nents; ++i) {
  333. sg_set_page(wr, sg_page(rd), rd->length, rd->offset);
  334. rd = sg_next(rd);
  335. wr = sg_next(wr);
  336. }
  337. attach->dma_dir = DMA_NONE;
  338. dbuf_attach->priv = attach;
  339. return 0;
  340. }
  341. static void vb2_dma_sg_dmabuf_ops_detach(struct dma_buf *dbuf,
  342. struct dma_buf_attachment *db_attach)
  343. {
  344. struct vb2_dma_sg_attachment *attach = db_attach->priv;
  345. struct sg_table *sgt;
  346. if (!attach)
  347. return;
  348. sgt = &attach->sgt;
  349. /* release the scatterlist cache */
  350. if (attach->dma_dir != DMA_NONE)
  351. dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
  352. attach->dma_dir);
  353. sg_free_table(sgt);
  354. kfree(attach);
  355. db_attach->priv = NULL;
  356. }
  357. static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
  358. struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
  359. {
  360. struct vb2_dma_sg_attachment *attach = db_attach->priv;
  361. /* stealing dmabuf mutex to serialize map/unmap operations */
  362. struct mutex *lock = &db_attach->dmabuf->lock;
  363. struct sg_table *sgt;
  364. mutex_lock(lock);
  365. sgt = &attach->sgt;
  366. /* return previously mapped sg table */
  367. if (attach->dma_dir == dma_dir) {
  368. mutex_unlock(lock);
  369. return sgt;
  370. }
  371. /* release any previous cache */
  372. if (attach->dma_dir != DMA_NONE) {
  373. dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
  374. attach->dma_dir);
  375. attach->dma_dir = DMA_NONE;
  376. }
  377. /* mapping to the client with new direction */
  378. sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
  379. dma_dir);
  380. if (!sgt->nents) {
  381. pr_err("failed to map scatterlist\n");
  382. mutex_unlock(lock);
  383. return ERR_PTR(-EIO);
  384. }
  385. attach->dma_dir = dma_dir;
  386. mutex_unlock(lock);
  387. return sgt;
  388. }
  389. static void vb2_dma_sg_dmabuf_ops_unmap(struct dma_buf_attachment *db_attach,
  390. struct sg_table *sgt, enum dma_data_direction dma_dir)
  391. {
  392. /* nothing to be done here */
  393. }
  394. static void vb2_dma_sg_dmabuf_ops_release(struct dma_buf *dbuf)
  395. {
  396. /* drop reference obtained in vb2_dma_sg_get_dmabuf */
  397. vb2_dma_sg_put(dbuf->priv);
  398. }
  399. static void *vb2_dma_sg_dmabuf_ops_kmap(struct dma_buf *dbuf, unsigned long pgnum)
  400. {
  401. struct vb2_dma_sg_buf *buf = dbuf->priv;
  402. return buf->vaddr ? buf->vaddr + pgnum * PAGE_SIZE : NULL;
  403. }
  404. static void *vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf)
  405. {
  406. struct vb2_dma_sg_buf *buf = dbuf->priv;
  407. return vb2_dma_sg_vaddr(buf);
  408. }
  409. static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
  410. struct vm_area_struct *vma)
  411. {
  412. return vb2_dma_sg_mmap(dbuf->priv, vma);
  413. }
  414. static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
  415. .attach = vb2_dma_sg_dmabuf_ops_attach,
  416. .detach = vb2_dma_sg_dmabuf_ops_detach,
  417. .map_dma_buf = vb2_dma_sg_dmabuf_ops_map,
  418. .unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap,
  419. .map = 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");