drm_prime.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * Copyright © 2012 Red Hat
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Dave Airlie <airlied@redhat.com>
  25. * Rob Clark <rob.clark@linaro.org>
  26. *
  27. */
  28. #include <linux/export.h>
  29. #include <linux/dma-buf.h>
  30. #include <drm/drmP.h>
  31. /*
  32. * DMA-BUF/GEM Object references and lifetime overview:
  33. *
  34. * On the export the dma_buf holds a reference to the exporting GEM
  35. * object. It takes this reference in handle_to_fd_ioctl, when it
  36. * first calls .prime_export and stores the exporting GEM object in
  37. * the dma_buf priv. This reference is released when the dma_buf
  38. * object goes away in the driver .release function.
  39. *
  40. * On the import the importing GEM object holds a reference to the
  41. * dma_buf (which in turn holds a ref to the exporting GEM object).
  42. * It takes that reference in the fd_to_handle ioctl.
  43. * It calls dma_buf_get, creates an attachment to it and stores the
  44. * attachment in the GEM object. When this attachment is destroyed
  45. * when the imported object is destroyed, we remove the attachment
  46. * and drop the reference to the dma_buf.
  47. *
  48. * Thus the chain of references always flows in one direction
  49. * (avoiding loops): importing_gem -> dmabuf -> exporting_gem
  50. *
  51. * Self-importing: if userspace is using PRIME as a replacement for flink
  52. * then it will get a fd->handle request for a GEM object that it created.
  53. * Drivers should detect this situation and return back the gem object
  54. * from the dma-buf private. Prime will do this automatically for drivers that
  55. * use the drm_gem_prime_{import,export} helpers.
  56. */
  57. struct drm_prime_member {
  58. struct list_head entry;
  59. struct dma_buf *dma_buf;
  60. uint32_t handle;
  61. };
  62. struct drm_prime_attachment {
  63. struct sg_table *sgt;
  64. enum dma_data_direction dir;
  65. };
  66. static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle)
  67. {
  68. struct drm_prime_member *member;
  69. member = kmalloc(sizeof(*member), GFP_KERNEL);
  70. if (!member)
  71. return -ENOMEM;
  72. get_dma_buf(dma_buf);
  73. member->dma_buf = dma_buf;
  74. member->handle = handle;
  75. list_add(&member->entry, &prime_fpriv->head);
  76. return 0;
  77. }
  78. static int drm_gem_map_attach(struct dma_buf *dma_buf,
  79. struct device *target_dev,
  80. struct dma_buf_attachment *attach)
  81. {
  82. struct drm_prime_attachment *prime_attach;
  83. struct drm_gem_object *obj = dma_buf->priv;
  84. struct drm_device *dev = obj->dev;
  85. prime_attach = kzalloc(sizeof(*prime_attach), GFP_KERNEL);
  86. if (!prime_attach)
  87. return -ENOMEM;
  88. prime_attach->dir = DMA_NONE;
  89. attach->priv = prime_attach;
  90. if (!dev->driver->gem_prime_pin)
  91. return 0;
  92. return dev->driver->gem_prime_pin(obj);
  93. }
  94. static void drm_gem_map_detach(struct dma_buf *dma_buf,
  95. struct dma_buf_attachment *attach)
  96. {
  97. struct drm_prime_attachment *prime_attach = attach->priv;
  98. struct drm_gem_object *obj = dma_buf->priv;
  99. struct drm_device *dev = obj->dev;
  100. struct sg_table *sgt;
  101. if (dev->driver->gem_prime_unpin)
  102. dev->driver->gem_prime_unpin(obj);
  103. if (!prime_attach)
  104. return;
  105. sgt = prime_attach->sgt;
  106. if (sgt) {
  107. if (prime_attach->dir != DMA_NONE)
  108. dma_unmap_sg(attach->dev, sgt->sgl, sgt->nents,
  109. prime_attach->dir);
  110. sg_free_table(sgt);
  111. }
  112. kfree(sgt);
  113. kfree(prime_attach);
  114. attach->priv = NULL;
  115. }
  116. static void drm_prime_remove_buf_handle_locked(
  117. struct drm_prime_file_private *prime_fpriv,
  118. struct dma_buf *dma_buf)
  119. {
  120. struct drm_prime_member *member, *safe;
  121. list_for_each_entry_safe(member, safe, &prime_fpriv->head, entry) {
  122. if (member->dma_buf == dma_buf) {
  123. dma_buf_put(dma_buf);
  124. list_del(&member->entry);
  125. kfree(member);
  126. }
  127. }
  128. }
  129. static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,
  130. enum dma_data_direction dir)
  131. {
  132. struct drm_prime_attachment *prime_attach = attach->priv;
  133. struct drm_gem_object *obj = attach->dmabuf->priv;
  134. struct sg_table *sgt;
  135. if (WARN_ON(dir == DMA_NONE || !prime_attach))
  136. return ERR_PTR(-EINVAL);
  137. /* return the cached mapping when possible */
  138. if (prime_attach->dir == dir)
  139. return prime_attach->sgt;
  140. /*
  141. * two mappings with different directions for the same attachment are
  142. * not allowed
  143. */
  144. if (WARN_ON(prime_attach->dir != DMA_NONE))
  145. return ERR_PTR(-EBUSY);
  146. sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
  147. if (!IS_ERR(sgt)) {
  148. if (!dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir)) {
  149. sg_free_table(sgt);
  150. kfree(sgt);
  151. sgt = ERR_PTR(-ENOMEM);
  152. } else {
  153. prime_attach->sgt = sgt;
  154. prime_attach->dir = dir;
  155. }
  156. }
  157. return sgt;
  158. }
  159. static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
  160. struct sg_table *sgt, enum dma_data_direction dir)
  161. {
  162. /* nothing to be done here */
  163. }
  164. void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
  165. {
  166. struct drm_gem_object *obj = dma_buf->priv;
  167. if (obj->export_dma_buf == dma_buf) {
  168. /* drop the reference on the export fd holds */
  169. obj->export_dma_buf = NULL;
  170. drm_gem_object_unreference_unlocked(obj);
  171. }
  172. }
  173. EXPORT_SYMBOL(drm_gem_dmabuf_release);
  174. static void *drm_gem_dmabuf_vmap(struct dma_buf *dma_buf)
  175. {
  176. struct drm_gem_object *obj = dma_buf->priv;
  177. struct drm_device *dev = obj->dev;
  178. return dev->driver->gem_prime_vmap(obj);
  179. }
  180. static void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr)
  181. {
  182. struct drm_gem_object *obj = dma_buf->priv;
  183. struct drm_device *dev = obj->dev;
  184. dev->driver->gem_prime_vunmap(obj, vaddr);
  185. }
  186. static void *drm_gem_dmabuf_kmap_atomic(struct dma_buf *dma_buf,
  187. unsigned long page_num)
  188. {
  189. return NULL;
  190. }
  191. static void drm_gem_dmabuf_kunmap_atomic(struct dma_buf *dma_buf,
  192. unsigned long page_num, void *addr)
  193. {
  194. }
  195. static void *drm_gem_dmabuf_kmap(struct dma_buf *dma_buf,
  196. unsigned long page_num)
  197. {
  198. return NULL;
  199. }
  200. static void drm_gem_dmabuf_kunmap(struct dma_buf *dma_buf,
  201. unsigned long page_num, void *addr)
  202. {
  203. }
  204. static int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf,
  205. struct vm_area_struct *vma)
  206. {
  207. struct drm_gem_object *obj = dma_buf->priv;
  208. struct drm_device *dev = obj->dev;
  209. if (!dev->driver->gem_prime_mmap)
  210. return -ENOSYS;
  211. return dev->driver->gem_prime_mmap(obj, vma);
  212. }
  213. static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = {
  214. .attach = drm_gem_map_attach,
  215. .detach = drm_gem_map_detach,
  216. .map_dma_buf = drm_gem_map_dma_buf,
  217. .unmap_dma_buf = drm_gem_unmap_dma_buf,
  218. .release = drm_gem_dmabuf_release,
  219. .kmap = drm_gem_dmabuf_kmap,
  220. .kmap_atomic = drm_gem_dmabuf_kmap_atomic,
  221. .kunmap = drm_gem_dmabuf_kunmap,
  222. .kunmap_atomic = drm_gem_dmabuf_kunmap_atomic,
  223. .mmap = drm_gem_dmabuf_mmap,
  224. .vmap = drm_gem_dmabuf_vmap,
  225. .vunmap = drm_gem_dmabuf_vunmap,
  226. };
  227. /**
  228. * DOC: PRIME Helpers
  229. *
  230. * Drivers can implement @gem_prime_export and @gem_prime_import in terms of
  231. * simpler APIs by using the helper functions @drm_gem_prime_export and
  232. * @drm_gem_prime_import. These functions implement dma-buf support in terms of
  233. * five lower-level driver callbacks:
  234. *
  235. * Export callbacks:
  236. *
  237. * - @gem_prime_pin (optional): prepare a GEM object for exporting
  238. *
  239. * - @gem_prime_get_sg_table: provide a scatter/gather table of pinned pages
  240. *
  241. * - @gem_prime_vmap: vmap a buffer exported by your driver
  242. *
  243. * - @gem_prime_vunmap: vunmap a buffer exported by your driver
  244. *
  245. * Import callback:
  246. *
  247. * - @gem_prime_import_sg_table (import): produce a GEM object from another
  248. * driver's scatter/gather table
  249. */
  250. struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  251. struct drm_gem_object *obj, int flags)
  252. {
  253. return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, flags);
  254. }
  255. EXPORT_SYMBOL(drm_gem_prime_export);
  256. int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  257. struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  258. int *prime_fd)
  259. {
  260. struct drm_gem_object *obj;
  261. void *buf;
  262. int ret = 0;
  263. struct dma_buf *dmabuf;
  264. obj = drm_gem_object_lookup(dev, file_priv, handle);
  265. if (!obj)
  266. return -ENOENT;
  267. mutex_lock(&file_priv->prime.lock);
  268. /* re-export the original imported object */
  269. if (obj->import_attach) {
  270. dmabuf = obj->import_attach->dmabuf;
  271. goto out_have_obj;
  272. }
  273. if (obj->export_dma_buf) {
  274. dmabuf = obj->export_dma_buf;
  275. goto out_have_obj;
  276. }
  277. buf = dev->driver->gem_prime_export(dev, obj, flags);
  278. if (IS_ERR(buf)) {
  279. /* normally the created dma-buf takes ownership of the ref,
  280. * but if that fails then drop the ref
  281. */
  282. ret = PTR_ERR(buf);
  283. goto out;
  284. }
  285. obj->export_dma_buf = buf;
  286. /* if we've exported this buffer the cheat and add it to the import list
  287. * so we get the correct handle back
  288. */
  289. ret = drm_prime_add_buf_handle(&file_priv->prime,
  290. obj->export_dma_buf, handle);
  291. if (ret)
  292. goto fail_put_dmabuf;
  293. ret = dma_buf_fd(buf, flags);
  294. if (ret < 0)
  295. goto fail_rm_handle;
  296. *prime_fd = ret;
  297. mutex_unlock(&file_priv->prime.lock);
  298. return 0;
  299. out_have_obj:
  300. get_dma_buf(dmabuf);
  301. ret = dma_buf_fd(dmabuf, flags);
  302. if (ret < 0) {
  303. dma_buf_put(dmabuf);
  304. } else {
  305. *prime_fd = ret;
  306. ret = 0;
  307. }
  308. goto out;
  309. fail_rm_handle:
  310. drm_prime_remove_buf_handle_locked(&file_priv->prime, buf);
  311. fail_put_dmabuf:
  312. /* clear NOT to be checked when releasing dma_buf */
  313. obj->export_dma_buf = NULL;
  314. dma_buf_put(buf);
  315. out:
  316. drm_gem_object_unreference_unlocked(obj);
  317. mutex_unlock(&file_priv->prime.lock);
  318. return ret;
  319. }
  320. EXPORT_SYMBOL(drm_gem_prime_handle_to_fd);
  321. struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  322. struct dma_buf *dma_buf)
  323. {
  324. struct dma_buf_attachment *attach;
  325. struct sg_table *sgt;
  326. struct drm_gem_object *obj;
  327. int ret;
  328. if (!dev->driver->gem_prime_import_sg_table)
  329. return ERR_PTR(-EINVAL);
  330. if (dma_buf->ops == &drm_gem_prime_dmabuf_ops) {
  331. obj = dma_buf->priv;
  332. if (obj->dev == dev) {
  333. /*
  334. * Importing dmabuf exported from out own gem increases
  335. * refcount on gem itself instead of f_count of dmabuf.
  336. */
  337. drm_gem_object_reference(obj);
  338. return obj;
  339. }
  340. }
  341. attach = dma_buf_attach(dma_buf, dev->dev);
  342. if (IS_ERR(attach))
  343. return ERR_CAST(attach);
  344. get_dma_buf(dma_buf);
  345. sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
  346. if (IS_ERR_OR_NULL(sgt)) {
  347. ret = PTR_ERR(sgt);
  348. goto fail_detach;
  349. }
  350. obj = dev->driver->gem_prime_import_sg_table(dev, dma_buf->size, sgt);
  351. if (IS_ERR(obj)) {
  352. ret = PTR_ERR(obj);
  353. goto fail_unmap;
  354. }
  355. obj->import_attach = attach;
  356. return obj;
  357. fail_unmap:
  358. dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL);
  359. fail_detach:
  360. dma_buf_detach(dma_buf, attach);
  361. dma_buf_put(dma_buf);
  362. return ERR_PTR(ret);
  363. }
  364. EXPORT_SYMBOL(drm_gem_prime_import);
  365. int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  366. struct drm_file *file_priv, int prime_fd, uint32_t *handle)
  367. {
  368. struct dma_buf *dma_buf;
  369. struct drm_gem_object *obj;
  370. int ret;
  371. dma_buf = dma_buf_get(prime_fd);
  372. if (IS_ERR(dma_buf))
  373. return PTR_ERR(dma_buf);
  374. mutex_lock(&file_priv->prime.lock);
  375. ret = drm_prime_lookup_buf_handle(&file_priv->prime,
  376. dma_buf, handle);
  377. if (!ret) {
  378. ret = 0;
  379. goto out_put;
  380. }
  381. /* never seen this one, need to import */
  382. obj = dev->driver->gem_prime_import(dev, dma_buf);
  383. if (IS_ERR(obj)) {
  384. ret = PTR_ERR(obj);
  385. goto out_put;
  386. }
  387. ret = drm_gem_handle_create(file_priv, obj, handle);
  388. drm_gem_object_unreference_unlocked(obj);
  389. if (ret)
  390. goto out_put;
  391. ret = drm_prime_add_buf_handle(&file_priv->prime,
  392. dma_buf, *handle);
  393. if (ret)
  394. goto fail;
  395. mutex_unlock(&file_priv->prime.lock);
  396. dma_buf_put(dma_buf);
  397. return 0;
  398. fail:
  399. /* hmm, if driver attached, we are relying on the free-object path
  400. * to detach.. which seems ok..
  401. */
  402. drm_gem_handle_delete(file_priv, *handle);
  403. out_put:
  404. dma_buf_put(dma_buf);
  405. mutex_unlock(&file_priv->prime.lock);
  406. return ret;
  407. }
  408. EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
  409. int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
  410. struct drm_file *file_priv)
  411. {
  412. struct drm_prime_handle *args = data;
  413. uint32_t flags;
  414. if (!drm_core_check_feature(dev, DRIVER_PRIME))
  415. return -EINVAL;
  416. if (!dev->driver->prime_handle_to_fd)
  417. return -ENOSYS;
  418. /* check flags are valid */
  419. if (args->flags & ~DRM_CLOEXEC)
  420. return -EINVAL;
  421. /* we only want to pass DRM_CLOEXEC which is == O_CLOEXEC */
  422. flags = args->flags & DRM_CLOEXEC;
  423. return dev->driver->prime_handle_to_fd(dev, file_priv,
  424. args->handle, flags, &args->fd);
  425. }
  426. int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
  427. struct drm_file *file_priv)
  428. {
  429. struct drm_prime_handle *args = data;
  430. if (!drm_core_check_feature(dev, DRIVER_PRIME))
  431. return -EINVAL;
  432. if (!dev->driver->prime_fd_to_handle)
  433. return -ENOSYS;
  434. return dev->driver->prime_fd_to_handle(dev, file_priv,
  435. args->fd, &args->handle);
  436. }
  437. /*
  438. * drm_prime_pages_to_sg
  439. *
  440. * this helper creates an sg table object from a set of pages
  441. * the driver is responsible for mapping the pages into the
  442. * importers address space
  443. */
  444. struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages)
  445. {
  446. struct sg_table *sg = NULL;
  447. int ret;
  448. sg = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
  449. if (!sg) {
  450. ret = -ENOMEM;
  451. goto out;
  452. }
  453. ret = sg_alloc_table_from_pages(sg, pages, nr_pages, 0,
  454. nr_pages << PAGE_SHIFT, GFP_KERNEL);
  455. if (ret)
  456. goto out;
  457. return sg;
  458. out:
  459. kfree(sg);
  460. return ERR_PTR(ret);
  461. }
  462. EXPORT_SYMBOL(drm_prime_pages_to_sg);
  463. /* export an sg table into an array of pages and addresses
  464. this is currently required by the TTM driver in order to do correct fault
  465. handling */
  466. int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  467. dma_addr_t *addrs, int max_pages)
  468. {
  469. unsigned count;
  470. struct scatterlist *sg;
  471. struct page *page;
  472. u32 len, offset;
  473. int pg_index;
  474. dma_addr_t addr;
  475. pg_index = 0;
  476. for_each_sg(sgt->sgl, sg, sgt->nents, count) {
  477. len = sg->length;
  478. offset = sg->offset;
  479. page = sg_page(sg);
  480. addr = sg_dma_address(sg);
  481. while (len > 0) {
  482. if (WARN_ON(pg_index >= max_pages))
  483. return -1;
  484. pages[pg_index] = page;
  485. if (addrs)
  486. addrs[pg_index] = addr;
  487. page++;
  488. addr += PAGE_SIZE;
  489. len -= PAGE_SIZE;
  490. pg_index++;
  491. }
  492. }
  493. return 0;
  494. }
  495. EXPORT_SYMBOL(drm_prime_sg_to_page_addr_arrays);
  496. /* helper function to cleanup a GEM/prime object */
  497. void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg)
  498. {
  499. struct dma_buf_attachment *attach;
  500. struct dma_buf *dma_buf;
  501. attach = obj->import_attach;
  502. if (sg)
  503. dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL);
  504. dma_buf = attach->dmabuf;
  505. dma_buf_detach(attach->dmabuf, attach);
  506. /* remove the reference */
  507. dma_buf_put(dma_buf);
  508. }
  509. EXPORT_SYMBOL(drm_prime_gem_destroy);
  510. void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv)
  511. {
  512. INIT_LIST_HEAD(&prime_fpriv->head);
  513. mutex_init(&prime_fpriv->lock);
  514. }
  515. EXPORT_SYMBOL(drm_prime_init_file_private);
  516. void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv)
  517. {
  518. /* by now drm_gem_release should've made sure the list is empty */
  519. WARN_ON(!list_empty(&prime_fpriv->head));
  520. }
  521. EXPORT_SYMBOL(drm_prime_destroy_file_private);
  522. int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle)
  523. {
  524. struct drm_prime_member *member;
  525. list_for_each_entry(member, &prime_fpriv->head, entry) {
  526. if (member->dma_buf == dma_buf) {
  527. *handle = member->handle;
  528. return 0;
  529. }
  530. }
  531. return -ENOENT;
  532. }
  533. EXPORT_SYMBOL(drm_prime_lookup_buf_handle);
  534. void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf)
  535. {
  536. mutex_lock(&prime_fpriv->lock);
  537. drm_prime_remove_buf_handle_locked(prime_fpriv, dma_buf);
  538. mutex_unlock(&prime_fpriv->lock);
  539. }
  540. EXPORT_SYMBOL(drm_prime_remove_buf_handle);