Lines Matching full:attach
699 static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach, in __map_dma_buf() argument
704 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); in __map_dma_buf()
714 * @dmabuf: [in] buffer to attach device to.
722 * Optionally this calls &dma_buf_ops.attach to allow device-specific attach
739 struct dma_buf_attachment *attach; in dma_buf_dynamic_attach() local
748 attach = kzalloc(sizeof(*attach), GFP_KERNEL); in dma_buf_dynamic_attach()
749 if (!attach) in dma_buf_dynamic_attach()
752 attach->dev = dev; in dma_buf_dynamic_attach()
753 attach->dmabuf = dmabuf; in dma_buf_dynamic_attach()
755 attach->peer2peer = importer_ops->allow_peer2peer; in dma_buf_dynamic_attach()
756 attach->importer_ops = importer_ops; in dma_buf_dynamic_attach()
757 attach->importer_priv = importer_priv; in dma_buf_dynamic_attach()
759 if (dmabuf->ops->attach) { in dma_buf_dynamic_attach()
760 ret = dmabuf->ops->attach(dmabuf, attach); in dma_buf_dynamic_attach()
765 list_add(&attach->node, &dmabuf->attachments); in dma_buf_dynamic_attach()
772 if (dma_buf_attachment_is_dynamic(attach) != in dma_buf_dynamic_attach()
776 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_dynamic_attach()
777 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_dynamic_attach()
778 ret = dmabuf->ops->pin(attach); in dma_buf_dynamic_attach()
783 sgt = __map_dma_buf(attach, DMA_BIDIRECTIONAL); in dma_buf_dynamic_attach()
790 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
791 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
792 attach->sgt = sgt; in dma_buf_dynamic_attach()
793 attach->dir = DMA_BIDIRECTIONAL; in dma_buf_dynamic_attach()
796 return attach; in dma_buf_dynamic_attach()
799 kfree(attach); in dma_buf_dynamic_attach()
803 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
804 dmabuf->ops->unpin(attach); in dma_buf_dynamic_attach()
807 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
808 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
810 dma_buf_detach(dmabuf, attach); in dma_buf_dynamic_attach()
817 * @dmabuf: [in] buffer to attach device to.
830 static void __unmap_dma_buf(struct dma_buf_attachment *attach, in __unmap_dma_buf() argument
837 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); in __unmap_dma_buf()
843 * @attach: [in] attachment to be detached; is free'd after this call.
849 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) in dma_buf_detach() argument
851 if (WARN_ON(!dmabuf || !attach)) in dma_buf_detach()
854 if (attach->sgt) { in dma_buf_detach()
855 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_detach()
856 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_detach()
858 __unmap_dma_buf(attach, attach->sgt, attach->dir); in dma_buf_detach()
860 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_detach()
861 dmabuf->ops->unpin(attach); in dma_buf_detach()
862 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_detach()
867 list_del(&attach->node); in dma_buf_detach()
870 dmabuf->ops->detach(dmabuf, attach); in dma_buf_detach()
872 kfree(attach); in dma_buf_detach()
878 * @attach: [in] attachment which should be pinned
880 * Only dynamic importers (who set up @attach with dma_buf_dynamic_attach()) may
890 int dma_buf_pin(struct dma_buf_attachment *attach) in dma_buf_pin() argument
892 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_pin()
895 WARN_ON(!dma_buf_attachment_is_dynamic(attach)); in dma_buf_pin()
900 ret = dmabuf->ops->pin(attach); in dma_buf_pin()
908 * @attach: [in] attachment which should be unpinned
911 * any mapping of @attach again and inform the importer through
914 void dma_buf_unpin(struct dma_buf_attachment *attach) in dma_buf_unpin() argument
916 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_unpin()
918 WARN_ON(!dma_buf_attachment_is_dynamic(attach)); in dma_buf_unpin()
923 dmabuf->ops->unpin(attach); in dma_buf_unpin()
931 * @attach: [in] attachment whose scatterlist is to be returned
948 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, in dma_buf_map_attachment() argument
956 if (WARN_ON(!attach || !attach->dmabuf)) in dma_buf_map_attachment()
959 if (dma_buf_attachment_is_dynamic(attach)) in dma_buf_map_attachment()
960 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_map_attachment()
962 if (attach->sgt) { in dma_buf_map_attachment()
967 if (attach->dir != direction && in dma_buf_map_attachment()
968 attach->dir != DMA_BIDIRECTIONAL) in dma_buf_map_attachment()
971 return attach->sgt; in dma_buf_map_attachment()
974 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_map_attachment()
975 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_map_attachment()
977 r = attach->dmabuf->ops->pin(attach); in dma_buf_map_attachment()
983 sg_table = __map_dma_buf(attach, direction); in dma_buf_map_attachment()
987 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_map_attachment()
989 attach->dmabuf->ops->unpin(attach); in dma_buf_map_attachment()
991 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) { in dma_buf_map_attachment()
992 attach->sgt = sg_table; in dma_buf_map_attachment()
993 attach->dir = direction; in dma_buf_map_attachment()
1021 * @attach: [in] attachment to unmap buffer from
1027 void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, in dma_buf_unmap_attachment() argument
1033 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) in dma_buf_unmap_attachment()
1036 if (dma_buf_attachment_is_dynamic(attach)) in dma_buf_unmap_attachment()
1037 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_unmap_attachment()
1039 if (attach->sgt == sg_table) in dma_buf_unmap_attachment()
1042 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_unmap_attachment()
1043 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_unmap_attachment()
1045 __unmap_dma_buf(attach, sg_table, direction); in dma_buf_unmap_attachment()
1047 if (dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_unmap_attachment()
1049 dma_buf_unpin(attach); in dma_buf_unmap_attachment()
1063 struct dma_buf_attachment *attach; in dma_buf_move_notify() local
1067 list_for_each_entry(attach, &dmabuf->attachments, node) in dma_buf_move_notify()
1068 if (attach->importer_ops) in dma_buf_move_notify()
1069 attach->importer_ops->move_notify(attach); in dma_buf_move_notify()