drm_gem_dma_helper.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * drm gem DMA helper functions
  4. *
  5. * Copyright (C) 2012 Sascha Hauer, Pengutronix
  6. *
  7. * Based on Samsung Exynos code
  8. *
  9. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  10. */
  11. #include <linux/dma-buf.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/export.h>
  14. #include <linux/mm.h>
  15. #include <linux/module.h>
  16. #include <linux/mutex.h>
  17. #include <linux/slab.h>
  18. #include <drm/drm.h>
  19. #include <drm/drm_device.h>
  20. #include <drm/drm_drv.h>
  21. #include <drm/drm_gem_dma_helper.h>
  22. #include <drm/drm_vma_manager.h>
  23. /**
  24. * DOC: dma helpers
  25. *
  26. * The DRM GEM/DMA helpers are a means to provide buffer objects that are
  27. * presented to the device as a contiguous chunk of memory. This is useful
  28. * for devices that do not support scatter-gather DMA (either directly or
  29. * by using an intimately attached IOMMU).
  30. *
  31. * For devices that access the memory bus through an (external) IOMMU then
  32. * the buffer objects are allocated using a traditional page-based
  33. * allocator and may be scattered through physical memory. However they
  34. * are contiguous in the IOVA space so appear contiguous to devices using
  35. * them.
  36. *
  37. * For other devices then the helpers rely on CMA to provide buffer
  38. * objects that are physically contiguous in memory.
  39. *
  40. * For GEM callback helpers in struct &drm_gem_object functions, see likewise
  41. * named functions with an _object_ infix (e.g., drm_gem_dma_object_vmap() wraps
  42. * drm_gem_dma_vmap()). These helpers perform the necessary type conversion.
  43. */
  44. static const struct drm_gem_object_funcs drm_gem_dma_default_funcs = {
  45. .free = drm_gem_dma_object_free,
  46. .print_info = drm_gem_dma_object_print_info,
  47. .get_sg_table = drm_gem_dma_object_get_sg_table,
  48. .vmap = drm_gem_dma_object_vmap,
  49. .mmap = drm_gem_dma_object_mmap,
  50. .vm_ops = &drm_gem_dma_vm_ops,
  51. };
  52. /**
  53. * __drm_gem_dma_create - Create a GEM DMA object without allocating memory
  54. * @drm: DRM device
  55. * @size: size of the object to allocate
  56. * @private: true if used for internal purposes
  57. *
  58. * This function creates and initializes a GEM DMA object of the given size,
  59. * but doesn't allocate any memory to back the object.
  60. *
  61. * Returns:
  62. * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
  63. * error code on failure.
  64. */
  65. static struct drm_gem_dma_object *
  66. __drm_gem_dma_create(struct drm_device *drm, size_t size, bool private)
  67. {
  68. struct drm_gem_dma_object *dma_obj;
  69. struct drm_gem_object *gem_obj;
  70. int ret = 0;
  71. if (drm->driver->gem_create_object) {
  72. gem_obj = drm->driver->gem_create_object(drm, size);
  73. if (IS_ERR(gem_obj))
  74. return ERR_CAST(gem_obj);
  75. dma_obj = to_drm_gem_dma_obj(gem_obj);
  76. } else {
  77. dma_obj = kzalloc(sizeof(*dma_obj), GFP_KERNEL);
  78. if (!dma_obj)
  79. return ERR_PTR(-ENOMEM);
  80. gem_obj = &dma_obj->base;
  81. }
  82. if (!gem_obj->funcs)
  83. gem_obj->funcs = &drm_gem_dma_default_funcs;
  84. if (private) {
  85. drm_gem_private_object_init(drm, gem_obj, size);
  86. /* Always use writecombine for dma-buf mappings */
  87. dma_obj->map_noncoherent = false;
  88. } else {
  89. ret = drm_gem_object_init(drm, gem_obj, size);
  90. }
  91. if (ret)
  92. goto error;
  93. ret = drm_gem_create_mmap_offset(gem_obj);
  94. if (ret) {
  95. drm_gem_object_release(gem_obj);
  96. goto error;
  97. }
  98. return dma_obj;
  99. error:
  100. kfree(dma_obj);
  101. return ERR_PTR(ret);
  102. }
  103. /**
  104. * drm_gem_dma_create - allocate an object with the given size
  105. * @drm: DRM device
  106. * @size: size of the object to allocate
  107. *
  108. * This function creates a DMA GEM object and allocates memory as backing store.
  109. * The allocated memory will occupy a contiguous chunk of bus address space.
  110. *
  111. * For devices that are directly connected to the memory bus then the allocated
  112. * memory will be physically contiguous. For devices that access through an
  113. * IOMMU, then the allocated memory is not expected to be physically contiguous
  114. * because having contiguous IOVAs is sufficient to meet a devices DMA
  115. * requirements.
  116. *
  117. * Returns:
  118. * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
  119. * error code on failure.
  120. */
  121. struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
  122. size_t size)
  123. {
  124. struct drm_gem_dma_object *dma_obj;
  125. int ret;
  126. size = round_up(size, PAGE_SIZE);
  127. dma_obj = __drm_gem_dma_create(drm, size, false);
  128. if (IS_ERR(dma_obj))
  129. return dma_obj;
  130. if (dma_obj->map_noncoherent) {
  131. dma_obj->vaddr = dma_alloc_noncoherent(drm->dev, size,
  132. &dma_obj->dma_addr,
  133. DMA_TO_DEVICE,
  134. GFP_KERNEL | __GFP_NOWARN);
  135. } else {
  136. dma_obj->vaddr = dma_alloc_wc(drm->dev, size,
  137. &dma_obj->dma_addr,
  138. GFP_KERNEL | __GFP_NOWARN);
  139. }
  140. if (!dma_obj->vaddr) {
  141. drm_dbg(drm, "failed to allocate buffer with size %zu\n",
  142. size);
  143. ret = -ENOMEM;
  144. goto error;
  145. }
  146. return dma_obj;
  147. error:
  148. drm_gem_object_put(&dma_obj->base);
  149. return ERR_PTR(ret);
  150. }
  151. EXPORT_SYMBOL_GPL(drm_gem_dma_create);
  152. /**
  153. * drm_gem_dma_create_with_handle - allocate an object with the given size and
  154. * return a GEM handle to it
  155. * @file_priv: DRM file-private structure to register the handle for
  156. * @drm: DRM device
  157. * @size: size of the object to allocate
  158. * @handle: return location for the GEM handle
  159. *
  160. * This function creates a DMA GEM object, allocating a chunk of memory as
  161. * backing store. The GEM object is then added to the list of object associated
  162. * with the given file and a handle to it is returned.
  163. *
  164. * The allocated memory will occupy a contiguous chunk of bus address space.
  165. * See drm_gem_dma_create() for more details.
  166. *
  167. * Returns:
  168. * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
  169. * error code on failure.
  170. */
  171. static struct drm_gem_dma_object *
  172. drm_gem_dma_create_with_handle(struct drm_file *file_priv,
  173. struct drm_device *drm, size_t size,
  174. uint32_t *handle)
  175. {
  176. struct drm_gem_dma_object *dma_obj;
  177. struct drm_gem_object *gem_obj;
  178. int ret;
  179. dma_obj = drm_gem_dma_create(drm, size);
  180. if (IS_ERR(dma_obj))
  181. return dma_obj;
  182. gem_obj = &dma_obj->base;
  183. /*
  184. * allocate a id of idr table where the obj is registered
  185. * and handle has the id what user can see.
  186. */
  187. ret = drm_gem_handle_create(file_priv, gem_obj, handle);
  188. /* drop reference from allocate - handle holds it now. */
  189. drm_gem_object_put(gem_obj);
  190. if (ret)
  191. return ERR_PTR(ret);
  192. return dma_obj;
  193. }
  194. /**
  195. * drm_gem_dma_free - free resources associated with a DMA GEM object
  196. * @dma_obj: DMA GEM object to free
  197. *
  198. * This function frees the backing memory of the DMA GEM object, cleans up the
  199. * GEM object state and frees the memory used to store the object itself.
  200. * If the buffer is imported and the virtual address is set, it is released.
  201. */
  202. void drm_gem_dma_free(struct drm_gem_dma_object *dma_obj)
  203. {
  204. struct drm_gem_object *gem_obj = &dma_obj->base;
  205. struct iosys_map map = IOSYS_MAP_INIT_VADDR(dma_obj->vaddr);
  206. if (gem_obj->import_attach) {
  207. if (dma_obj->vaddr)
  208. dma_buf_vunmap_unlocked(gem_obj->import_attach->dmabuf, &map);
  209. drm_prime_gem_destroy(gem_obj, dma_obj->sgt);
  210. } else if (dma_obj->vaddr) {
  211. if (dma_obj->map_noncoherent)
  212. dma_free_noncoherent(gem_obj->dev->dev, dma_obj->base.size,
  213. dma_obj->vaddr, dma_obj->dma_addr,
  214. DMA_TO_DEVICE);
  215. else
  216. dma_free_wc(gem_obj->dev->dev, dma_obj->base.size,
  217. dma_obj->vaddr, dma_obj->dma_addr);
  218. }
  219. drm_gem_object_release(gem_obj);
  220. kfree(dma_obj);
  221. }
  222. EXPORT_SYMBOL_GPL(drm_gem_dma_free);
  223. /**
  224. * drm_gem_dma_dumb_create_internal - create a dumb buffer object
  225. * @file_priv: DRM file-private structure to create the dumb buffer for
  226. * @drm: DRM device
  227. * @args: IOCTL data
  228. *
  229. * This aligns the pitch and size arguments to the minimum required. This is
  230. * an internal helper that can be wrapped by a driver to account for hardware
  231. * with more specific alignment requirements. It should not be used directly
  232. * as their &drm_driver.dumb_create callback.
  233. *
  234. * Returns:
  235. * 0 on success or a negative error code on failure.
  236. */
  237. int drm_gem_dma_dumb_create_internal(struct drm_file *file_priv,
  238. struct drm_device *drm,
  239. struct drm_mode_create_dumb *args)
  240. {
  241. unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
  242. struct drm_gem_dma_object *dma_obj;
  243. if (args->pitch < min_pitch)
  244. args->pitch = min_pitch;
  245. if (args->size < args->pitch * args->height)
  246. args->size = args->pitch * args->height;
  247. dma_obj = drm_gem_dma_create_with_handle(file_priv, drm, args->size,
  248. &args->handle);
  249. return PTR_ERR_OR_ZERO(dma_obj);
  250. }
  251. EXPORT_SYMBOL_GPL(drm_gem_dma_dumb_create_internal);
  252. /**
  253. * drm_gem_dma_dumb_create - create a dumb buffer object
  254. * @file_priv: DRM file-private structure to create the dumb buffer for
  255. * @drm: DRM device
  256. * @args: IOCTL data
  257. *
  258. * This function computes the pitch of the dumb buffer and rounds it up to an
  259. * integer number of bytes per pixel. Drivers for hardware that doesn't have
  260. * any additional restrictions on the pitch can directly use this function as
  261. * their &drm_driver.dumb_create callback.
  262. *
  263. * For hardware with additional restrictions, drivers can adjust the fields
  264. * set up by userspace and pass the IOCTL data along to the
  265. * drm_gem_dma_dumb_create_internal() function.
  266. *
  267. * Returns:
  268. * 0 on success or a negative error code on failure.
  269. */
  270. int drm_gem_dma_dumb_create(struct drm_file *file_priv,
  271. struct drm_device *drm,
  272. struct drm_mode_create_dumb *args)
  273. {
  274. struct drm_gem_dma_object *dma_obj;
  275. args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
  276. args->size = args->pitch * args->height;
  277. dma_obj = drm_gem_dma_create_with_handle(file_priv, drm, args->size,
  278. &args->handle);
  279. return PTR_ERR_OR_ZERO(dma_obj);
  280. }
  281. EXPORT_SYMBOL_GPL(drm_gem_dma_dumb_create);
  282. const struct vm_operations_struct drm_gem_dma_vm_ops = {
  283. .open = drm_gem_vm_open,
  284. .close = drm_gem_vm_close,
  285. };
  286. EXPORT_SYMBOL_GPL(drm_gem_dma_vm_ops);
  287. #ifndef CONFIG_MMU
  288. /**
  289. * drm_gem_dma_get_unmapped_area - propose address for mapping in noMMU cases
  290. * @filp: file object
  291. * @addr: memory address
  292. * @len: buffer size
  293. * @pgoff: page offset
  294. * @flags: memory flags
  295. *
  296. * This function is used in noMMU platforms to propose address mapping
  297. * for a given buffer.
  298. * It's intended to be used as a direct handler for the struct
  299. * &file_operations.get_unmapped_area operation.
  300. *
  301. * Returns:
  302. * mapping address on success or a negative error code on failure.
  303. */
  304. unsigned long drm_gem_dma_get_unmapped_area(struct file *filp,
  305. unsigned long addr,
  306. unsigned long len,
  307. unsigned long pgoff,
  308. unsigned long flags)
  309. {
  310. struct drm_gem_dma_object *dma_obj;
  311. struct drm_gem_object *obj = NULL;
  312. struct drm_file *priv = filp->private_data;
  313. struct drm_device *dev = priv->minor->dev;
  314. struct drm_vma_offset_node *node;
  315. if (drm_dev_is_unplugged(dev))
  316. return -ENODEV;
  317. drm_vma_offset_lock_lookup(dev->vma_offset_manager);
  318. node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
  319. pgoff,
  320. len >> PAGE_SHIFT);
  321. if (likely(node)) {
  322. obj = container_of(node, struct drm_gem_object, vma_node);
  323. /*
  324. * When the object is being freed, after it hits 0-refcnt it
  325. * proceeds to tear down the object. In the process it will
  326. * attempt to remove the VMA offset and so acquire this
  327. * mgr->vm_lock. Therefore if we find an object with a 0-refcnt
  328. * that matches our range, we know it is in the process of being
  329. * destroyed and will be freed as soon as we release the lock -
  330. * so we have to check for the 0-refcnted object and treat it as
  331. * invalid.
  332. */
  333. if (!kref_get_unless_zero(&obj->refcount))
  334. obj = NULL;
  335. }
  336. drm_vma_offset_unlock_lookup(dev->vma_offset_manager);
  337. if (!obj)
  338. return -EINVAL;
  339. if (!drm_vma_node_is_allowed(node, priv)) {
  340. drm_gem_object_put(obj);
  341. return -EACCES;
  342. }
  343. dma_obj = to_drm_gem_dma_obj(obj);
  344. drm_gem_object_put(obj);
  345. return dma_obj->vaddr ? (unsigned long)dma_obj->vaddr : -EINVAL;
  346. }
  347. EXPORT_SYMBOL_GPL(drm_gem_dma_get_unmapped_area);
  348. #endif
  349. /**
  350. * drm_gem_dma_print_info() - Print &drm_gem_dma_object info for debugfs
  351. * @dma_obj: DMA GEM object
  352. * @p: DRM printer
  353. * @indent: Tab indentation level
  354. *
  355. * This function prints dma_addr and vaddr for use in e.g. debugfs output.
  356. */
  357. void drm_gem_dma_print_info(const struct drm_gem_dma_object *dma_obj,
  358. struct drm_printer *p, unsigned int indent)
  359. {
  360. drm_printf_indent(p, indent, "dma_addr=%pad\n", &dma_obj->dma_addr);
  361. drm_printf_indent(p, indent, "vaddr=%p\n", dma_obj->vaddr);
  362. }
  363. EXPORT_SYMBOL(drm_gem_dma_print_info);
  364. /**
  365. * drm_gem_dma_get_sg_table - provide a scatter/gather table of pinned
  366. * pages for a DMA GEM object
  367. * @dma_obj: DMA GEM object
  368. *
  369. * This function exports a scatter/gather table by calling the standard
  370. * DMA mapping API.
  371. *
  372. * Returns:
  373. * A pointer to the scatter/gather table of pinned pages or NULL on failure.
  374. */
  375. struct sg_table *drm_gem_dma_get_sg_table(struct drm_gem_dma_object *dma_obj)
  376. {
  377. struct drm_gem_object *obj = &dma_obj->base;
  378. struct sg_table *sgt;
  379. int ret;
  380. sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
  381. if (!sgt)
  382. return ERR_PTR(-ENOMEM);
  383. ret = dma_get_sgtable(obj->dev->dev, sgt, dma_obj->vaddr,
  384. dma_obj->dma_addr, obj->size);
  385. if (ret < 0)
  386. goto out;
  387. return sgt;
  388. out:
  389. kfree(sgt);
  390. return ERR_PTR(ret);
  391. }
  392. EXPORT_SYMBOL_GPL(drm_gem_dma_get_sg_table);
  393. /**
  394. * drm_gem_dma_prime_import_sg_table - produce a DMA GEM object from another
  395. * driver's scatter/gather table of pinned pages
  396. * @dev: device to import into
  397. * @attach: DMA-BUF attachment
  398. * @sgt: scatter/gather table of pinned pages
  399. *
  400. * This function imports a scatter/gather table exported via DMA-BUF by
  401. * another driver. Imported buffers must be physically contiguous in memory
  402. * (i.e. the scatter/gather table must contain a single entry). Drivers that
  403. * use the DMA helpers should set this as their
  404. * &drm_driver.gem_prime_import_sg_table callback.
  405. *
  406. * Returns:
  407. * A pointer to a newly created GEM object or an ERR_PTR-encoded negative
  408. * error code on failure.
  409. */
  410. struct drm_gem_object *
  411. drm_gem_dma_prime_import_sg_table(struct drm_device *dev,
  412. struct dma_buf_attachment *attach,
  413. struct sg_table *sgt)
  414. {
  415. struct drm_gem_dma_object *dma_obj;
  416. /* check if the entries in the sg_table are contiguous */
  417. if (drm_prime_get_contiguous_size(sgt) < attach->dmabuf->size)
  418. return ERR_PTR(-EINVAL);
  419. /* Create a DMA GEM buffer. */
  420. dma_obj = __drm_gem_dma_create(dev, attach->dmabuf->size, true);
  421. if (IS_ERR(dma_obj))
  422. return ERR_CAST(dma_obj);
  423. dma_obj->dma_addr = sg_dma_address(sgt->sgl);
  424. dma_obj->sgt = sgt;
  425. drm_dbg_prime(dev, "dma_addr = %pad, size = %zu\n", &dma_obj->dma_addr,
  426. attach->dmabuf->size);
  427. return &dma_obj->base;
  428. }
  429. EXPORT_SYMBOL_GPL(drm_gem_dma_prime_import_sg_table);
  430. /**
  431. * drm_gem_dma_vmap - map a DMA GEM object into the kernel's virtual
  432. * address space
  433. * @dma_obj: DMA GEM object
  434. * @map: Returns the kernel virtual address of the DMA GEM object's backing
  435. * store.
  436. *
  437. * This function maps a buffer into the kernel's virtual address space.
  438. * Since the DMA buffers are already mapped into the kernel virtual address
  439. * space this simply returns the cached virtual address.
  440. *
  441. * Returns:
  442. * 0 on success, or a negative error code otherwise.
  443. */
  444. int drm_gem_dma_vmap(struct drm_gem_dma_object *dma_obj,
  445. struct iosys_map *map)
  446. {
  447. iosys_map_set_vaddr(map, dma_obj->vaddr);
  448. return 0;
  449. }
  450. EXPORT_SYMBOL_GPL(drm_gem_dma_vmap);
  451. /**
  452. * drm_gem_dma_mmap - memory-map an exported DMA GEM object
  453. * @dma_obj: DMA GEM object
  454. * @vma: VMA for the area to be mapped
  455. *
  456. * This function maps a buffer into a userspace process's address space.
  457. * In addition to the usual GEM VMA setup it immediately faults in the entire
  458. * object instead of using on-demand faulting.
  459. *
  460. * Returns:
  461. * 0 on success or a negative error code on failure.
  462. */
  463. int drm_gem_dma_mmap(struct drm_gem_dma_object *dma_obj, struct vm_area_struct *vma)
  464. {
  465. struct drm_gem_object *obj = &dma_obj->base;
  466. int ret;
  467. /*
  468. * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the
  469. * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map
  470. * the whole buffer.
  471. */
  472. vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
  473. vm_flags_mod(vma, VM_DONTEXPAND, VM_PFNMAP);
  474. if (dma_obj->map_noncoherent) {
  475. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  476. ret = dma_mmap_pages(dma_obj->base.dev->dev,
  477. vma, vma->vm_end - vma->vm_start,
  478. virt_to_page(dma_obj->vaddr));
  479. } else {
  480. ret = dma_mmap_wc(dma_obj->base.dev->dev, vma, dma_obj->vaddr,
  481. dma_obj->dma_addr,
  482. vma->vm_end - vma->vm_start);
  483. }
  484. if (ret)
  485. drm_gem_vm_close(vma);
  486. return ret;
  487. }
  488. EXPORT_SYMBOL_GPL(drm_gem_dma_mmap);
  489. /**
  490. * drm_gem_dma_prime_import_sg_table_vmap - PRIME import another driver's
  491. * scatter/gather table and get the virtual address of the buffer
  492. * @dev: DRM device
  493. * @attach: DMA-BUF attachment
  494. * @sgt: Scatter/gather table of pinned pages
  495. *
  496. * This function imports a scatter/gather table using
  497. * drm_gem_dma_prime_import_sg_table() and uses dma_buf_vmap() to get the kernel
  498. * virtual address. This ensures that a DMA GEM object always has its virtual
  499. * address set. This address is released when the object is freed.
  500. *
  501. * This function can be used as the &drm_driver.gem_prime_import_sg_table
  502. * callback. The &DRM_GEM_DMA_DRIVER_OPS_VMAP macro provides a shortcut to set
  503. * the necessary DRM driver operations.
  504. *
  505. * Returns:
  506. * A pointer to a newly created GEM object or an ERR_PTR-encoded negative
  507. * error code on failure.
  508. */
  509. struct drm_gem_object *
  510. drm_gem_dma_prime_import_sg_table_vmap(struct drm_device *dev,
  511. struct dma_buf_attachment *attach,
  512. struct sg_table *sgt)
  513. {
  514. struct drm_gem_dma_object *dma_obj;
  515. struct drm_gem_object *obj;
  516. struct iosys_map map;
  517. int ret;
  518. ret = dma_buf_vmap_unlocked(attach->dmabuf, &map);
  519. if (ret) {
  520. DRM_ERROR("Failed to vmap PRIME buffer\n");
  521. return ERR_PTR(ret);
  522. }
  523. obj = drm_gem_dma_prime_import_sg_table(dev, attach, sgt);
  524. if (IS_ERR(obj)) {
  525. dma_buf_vunmap_unlocked(attach->dmabuf, &map);
  526. return obj;
  527. }
  528. dma_obj = to_drm_gem_dma_obj(obj);
  529. dma_obj->vaddr = map.vaddr;
  530. return obj;
  531. }
  532. EXPORT_SYMBOL(drm_gem_dma_prime_import_sg_table_vmap);
  533. MODULE_DESCRIPTION("DRM DMA memory-management helpers");
  534. MODULE_IMPORT_NS(DMA_BUF);
  535. MODULE_LICENSE("GPL");