Lines Matching refs:attach
688 * calls attach() of dma_buf_ops to allow device-specific attach functionality
689 * @dmabuf: [in] buffer to attach device to.
711 struct dma_buf_attachment *attach;
720 attach = kzalloc(sizeof(*attach), GFP_KERNEL);
721 if (!attach)
724 attach->dev = dev;
725 attach->dmabuf = dmabuf;
727 attach->peer2peer = importer_ops->allow_peer2peer;
728 attach->importer_ops = importer_ops;
729 attach->importer_priv = importer_priv;
731 if (dmabuf->ops->attach) {
732 ret = dmabuf->ops->attach(dmabuf, attach);
737 list_add(&attach->node, &dmabuf->attachments);
744 if (dma_buf_attachment_is_dynamic(attach) !=
748 if (dma_buf_is_dynamic(attach->dmabuf)) {
749 dma_resv_lock(attach->dmabuf->resv, NULL);
750 ret = dma_buf_pin(attach);
755 sgt = dmabuf->ops->map_dma_buf(attach, DMA_BIDIRECTIONAL);
762 if (dma_buf_is_dynamic(attach->dmabuf))
763 dma_resv_unlock(attach->dmabuf->resv);
764 attach->sgt = sgt;
765 attach->dir = DMA_BIDIRECTIONAL;
768 return attach;
771 kfree(attach);
775 if (dma_buf_is_dynamic(attach->dmabuf))
776 dma_buf_unpin(attach);
779 if (dma_buf_is_dynamic(attach->dmabuf))
780 dma_resv_unlock(attach->dmabuf->resv);
782 dma_buf_detach(dmabuf, attach);
789 * @dmabuf: [in] buffer to attach device to.
806 * @attach: [in] attachment to be detached; is free'd after this call.
810 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
812 if (WARN_ON(!dmabuf || !attach))
815 if (attach->sgt) {
816 if (dma_buf_is_dynamic(attach->dmabuf))
817 dma_resv_lock(attach->dmabuf->resv, NULL);
819 dmabuf->ops->unmap_dma_buf(attach, attach->sgt, attach->dir);
821 if (dma_buf_is_dynamic(attach->dmabuf)) {
822 dma_buf_unpin(attach);
823 dma_resv_unlock(attach->dmabuf->resv);
828 list_del(&attach->node);
831 dmabuf->ops->detach(dmabuf, attach);
833 kfree(attach);
840 * @attach: [in] attachment which should be pinned
845 int dma_buf_pin(struct dma_buf_attachment *attach)
847 struct dma_buf *dmabuf = attach->dmabuf;
853 ret = dmabuf->ops->pin(attach);
862 * @attach: [in] attachment which should be unpinned
864 void dma_buf_unpin(struct dma_buf_attachment *attach)
866 struct dma_buf *dmabuf = attach->dmabuf;
871 dmabuf->ops->unpin(attach);
879 * @attach: [in] attachment whose scatterlist is to be returned
890 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
898 if (WARN_ON(!attach || !attach->dmabuf))
901 if (dma_buf_attachment_is_dynamic(attach))
902 dma_resv_assert_held(attach->dmabuf->resv);
904 if (attach->sgt) {
909 if (attach->dir != direction &&
910 attach->dir != DMA_BIDIRECTIONAL)
913 return attach->sgt;
916 if (dma_buf_is_dynamic(attach->dmabuf)) {
917 dma_resv_assert_held(attach->dmabuf->resv);
919 r = dma_buf_pin(attach);
925 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
929 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
931 dma_buf_unpin(attach);
933 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
934 attach->sgt = sg_table;
935 attach->dir = direction;
946 * @attach: [in] attachment to unmap buffer from
952 void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
958 if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
961 if (dma_buf_attachment_is_dynamic(attach))
962 dma_resv_assert_held(attach->dmabuf->resv);
964 if (attach->sgt == sg_table)
967 if (dma_buf_is_dynamic(attach->dmabuf))
968 dma_resv_assert_held(attach->dmabuf->resv);
970 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
972 if (dma_buf_is_dynamic(attach->dmabuf) &&
974 dma_buf_unpin(attach);
988 struct dma_buf_attachment *attach;
992 list_for_each_entry(attach, &dmabuf->attachments, node)
993 if (attach->importer_ops)
994 attach->importer_ops->move_notify(attach);