Lines Matching full:attach

791 static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach,  in __map_dma_buf()  argument
797 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); in __map_dma_buf()
801 if (!dma_buf_attachment_is_dynamic(attach)) { in __map_dma_buf()
802 ret = dma_resv_wait_timeout(attach->dmabuf->resv, in __map_dma_buf()
806 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, in __map_dma_buf()
857 * - &dma_buf_ops.attach()
882 * @dmabuf: [in] buffer to attach device to.
890 * Optionally this calls &dma_buf_ops.attach to allow device-specific attach
907 struct dma_buf_attachment *attach; in dma_buf_dynamic_attach() local
916 attach = kzalloc(sizeof(*attach), GFP_KERNEL); in dma_buf_dynamic_attach()
917 if (!attach) in dma_buf_dynamic_attach()
920 attach->dev = dev; in dma_buf_dynamic_attach()
921 attach->dmabuf = dmabuf; in dma_buf_dynamic_attach()
923 attach->peer2peer = importer_ops->allow_peer2peer; in dma_buf_dynamic_attach()
924 attach->importer_ops = importer_ops; in dma_buf_dynamic_attach()
925 attach->importer_priv = importer_priv; in dma_buf_dynamic_attach()
927 if (dmabuf->ops->attach) { in dma_buf_dynamic_attach()
928 ret = dmabuf->ops->attach(dmabuf, attach); in dma_buf_dynamic_attach()
933 list_add(&attach->node, &dmabuf->attachments); in dma_buf_dynamic_attach()
940 if (dma_buf_attachment_is_dynamic(attach) != in dma_buf_dynamic_attach()
944 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_dynamic_attach()
945 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_dynamic_attach()
946 ret = dmabuf->ops->pin(attach); in dma_buf_dynamic_attach()
951 sgt = __map_dma_buf(attach, DMA_BIDIRECTIONAL); in dma_buf_dynamic_attach()
958 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
959 attach->sgt = sgt; in dma_buf_dynamic_attach()
960 attach->dir = DMA_BIDIRECTIONAL; in dma_buf_dynamic_attach()
963 return attach; in dma_buf_dynamic_attach()
966 kfree(attach); in dma_buf_dynamic_attach()
970 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
971 dmabuf->ops->unpin(attach); in dma_buf_dynamic_attach()
974 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
976 dma_buf_detach(dmabuf, attach); in dma_buf_dynamic_attach()
983 * @dmabuf: [in] buffer to attach device to.
996 static void __unmap_dma_buf(struct dma_buf_attachment *attach, in __unmap_dma_buf() argument
1003 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); in __unmap_dma_buf()
1009 * @attach: [in] attachment to be detached; is free'd after this call.
1015 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) in dma_buf_detach() argument
1017 if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf)) in dma_buf_detach()
1022 if (attach->sgt) { in dma_buf_detach()
1024 __unmap_dma_buf(attach, attach->sgt, attach->dir); in dma_buf_detach()
1026 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_detach()
1027 dmabuf->ops->unpin(attach); in dma_buf_detach()
1029 list_del(&attach->node); in dma_buf_detach()
1034 dmabuf->ops->detach(dmabuf, attach); in dma_buf_detach()
1036 kfree(attach); in dma_buf_detach()
1042 * @attach: [in] attachment which should be pinned
1044 * Only dynamic importers (who set up @attach with dma_buf_dynamic_attach()) may
1054 int dma_buf_pin(struct dma_buf_attachment *attach) in dma_buf_pin() argument
1056 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_pin()
1059 WARN_ON(!dma_buf_attachment_is_dynamic(attach)); in dma_buf_pin()
1064 ret = dmabuf->ops->pin(attach); in dma_buf_pin()
1072 * @attach: [in] attachment which should be unpinned
1075 * any mapping of @attach again and inform the importer through
1078 void dma_buf_unpin(struct dma_buf_attachment *attach) in dma_buf_unpin() argument
1080 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_unpin()
1082 WARN_ON(!dma_buf_attachment_is_dynamic(attach)); in dma_buf_unpin()
1087 dmabuf->ops->unpin(attach); in dma_buf_unpin()
1095 * @attach: [in] attachment whose scatterlist is to be returned
1112 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, in dma_buf_map_attachment() argument
1120 if (WARN_ON(!attach || !attach->dmabuf)) in dma_buf_map_attachment()
1123 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_map_attachment()
1125 if (attach->sgt) { in dma_buf_map_attachment()
1130 if (attach->dir != direction && in dma_buf_map_attachment()
1131 attach->dir != DMA_BIDIRECTIONAL) in dma_buf_map_attachment()
1134 return attach->sgt; in dma_buf_map_attachment()
1137 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_map_attachment()
1139 r = attach->dmabuf->ops->pin(attach); in dma_buf_map_attachment()
1145 sg_table = __map_dma_buf(attach, direction); in dma_buf_map_attachment()
1149 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_map_attachment()
1151 attach->dmabuf->ops->unpin(attach); in dma_buf_map_attachment()
1153 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) { in dma_buf_map_attachment()
1154 attach->sgt = sg_table; in dma_buf_map_attachment()
1155 attach->dir = direction; in dma_buf_map_attachment()
1183 * @attach: [in] attachment whose scatterlist is to be returned
1189 dma_buf_map_attachment_unlocked(struct dma_buf_attachment *attach, in dma_buf_map_attachment_unlocked() argument
1196 if (WARN_ON(!attach || !attach->dmabuf)) in dma_buf_map_attachment_unlocked()
1199 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_map_attachment_unlocked()
1200 sg_table = dma_buf_map_attachment(attach, direction); in dma_buf_map_attachment_unlocked()
1201 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_map_attachment_unlocked()
1211 * @attach: [in] attachment to unmap buffer from
1217 void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, in dma_buf_unmap_attachment() argument
1223 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) in dma_buf_unmap_attachment()
1226 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_unmap_attachment()
1228 if (attach->sgt == sg_table) in dma_buf_unmap_attachment()
1231 __unmap_dma_buf(attach, sg_table, direction); in dma_buf_unmap_attachment()
1233 if (dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_unmap_attachment()
1235 dma_buf_unpin(attach); in dma_buf_unmap_attachment()
1243 * @attach: [in] attachment to unmap buffer from
1249 void dma_buf_unmap_attachment_unlocked(struct dma_buf_attachment *attach, in dma_buf_unmap_attachment_unlocked() argument
1255 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) in dma_buf_unmap_attachment_unlocked()
1258 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_unmap_attachment_unlocked()
1259 dma_buf_unmap_attachment(attach, sg_table, direction); in dma_buf_unmap_attachment_unlocked()
1260 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_unmap_attachment_unlocked()
1274 struct dma_buf_attachment *attach; in dma_buf_move_notify() local
1278 list_for_each_entry(attach, &dmabuf->attachments, node) in dma_buf_move_notify()
1279 if (attach->importer_ops) in dma_buf_move_notify()
1280 attach->importer_ops->move_notify(attach); in dma_buf_move_notify()