Lines Matching full:attach
777 static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach, in __map_dma_buf() argument
783 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); in __map_dma_buf()
787 if (!dma_buf_attachment_is_dynamic(attach)) { in __map_dma_buf()
788 ret = dma_resv_wait_timeout(attach->dmabuf->resv, in __map_dma_buf()
792 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, in __map_dma_buf()
843 * - &dma_buf_ops.attach()
868 * @dmabuf: [in] buffer to attach device to.
876 * Optionally this calls &dma_buf_ops.attach to allow device-specific attach
893 struct dma_buf_attachment *attach; in dma_buf_dynamic_attach() local
902 attach = kzalloc(sizeof(*attach), GFP_KERNEL); in dma_buf_dynamic_attach()
903 if (!attach) in dma_buf_dynamic_attach()
906 attach->dev = dev; in dma_buf_dynamic_attach()
907 attach->dmabuf = dmabuf; in dma_buf_dynamic_attach()
909 attach->peer2peer = importer_ops->allow_peer2peer; in dma_buf_dynamic_attach()
910 attach->importer_ops = importer_ops; in dma_buf_dynamic_attach()
911 attach->importer_priv = importer_priv; in dma_buf_dynamic_attach()
913 if (dmabuf->ops->attach) { in dma_buf_dynamic_attach()
914 ret = dmabuf->ops->attach(dmabuf, attach); in dma_buf_dynamic_attach()
919 list_add(&attach->node, &dmabuf->attachments); in dma_buf_dynamic_attach()
926 if (dma_buf_attachment_is_dynamic(attach) != in dma_buf_dynamic_attach()
930 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_dynamic_attach()
931 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_dynamic_attach()
932 ret = dmabuf->ops->pin(attach); in dma_buf_dynamic_attach()
937 sgt = __map_dma_buf(attach, DMA_BIDIRECTIONAL); in dma_buf_dynamic_attach()
944 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
945 attach->sgt = sgt; in dma_buf_dynamic_attach()
946 attach->dir = DMA_BIDIRECTIONAL; in dma_buf_dynamic_attach()
949 return attach; in dma_buf_dynamic_attach()
952 kfree(attach); in dma_buf_dynamic_attach()
956 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
957 dmabuf->ops->unpin(attach); in dma_buf_dynamic_attach()
960 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
962 dma_buf_detach(dmabuf, attach); in dma_buf_dynamic_attach()
969 * @dmabuf: [in] buffer to attach device to.
982 static void __unmap_dma_buf(struct dma_buf_attachment *attach, in __unmap_dma_buf() argument
989 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); in __unmap_dma_buf()
995 * @attach: [in] attachment to be detached; is free'd after this call.
1001 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) in dma_buf_detach() argument
1003 if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf)) in dma_buf_detach()
1008 if (attach->sgt) { in dma_buf_detach()
1010 __unmap_dma_buf(attach, attach->sgt, attach->dir); in dma_buf_detach()
1012 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_detach()
1013 dmabuf->ops->unpin(attach); in dma_buf_detach()
1015 list_del(&attach->node); in dma_buf_detach()
1020 dmabuf->ops->detach(dmabuf, attach); in dma_buf_detach()
1022 kfree(attach); in dma_buf_detach()
1028 * @attach: [in] attachment which should be pinned
1030 * Only dynamic importers (who set up @attach with dma_buf_dynamic_attach()) may
1040 int dma_buf_pin(struct dma_buf_attachment *attach) in dma_buf_pin() argument
1042 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_pin()
1045 WARN_ON(!dma_buf_attachment_is_dynamic(attach)); in dma_buf_pin()
1050 ret = dmabuf->ops->pin(attach); in dma_buf_pin()
1058 * @attach: [in] attachment which should be unpinned
1061 * any mapping of @attach again and inform the importer through
1064 void dma_buf_unpin(struct dma_buf_attachment *attach) in dma_buf_unpin() argument
1066 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_unpin()
1068 WARN_ON(!dma_buf_attachment_is_dynamic(attach)); in dma_buf_unpin()
1073 dmabuf->ops->unpin(attach); in dma_buf_unpin()
1081 * @attach: [in] attachment whose scatterlist is to be returned
1098 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, in dma_buf_map_attachment() argument
1106 if (WARN_ON(!attach || !attach->dmabuf)) in dma_buf_map_attachment()
1109 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_map_attachment()
1111 if (attach->sgt) { in dma_buf_map_attachment()
1116 if (attach->dir != direction && in dma_buf_map_attachment()
1117 attach->dir != DMA_BIDIRECTIONAL) in dma_buf_map_attachment()
1120 return attach->sgt; in dma_buf_map_attachment()
1123 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_map_attachment()
1125 r = attach->dmabuf->ops->pin(attach); in dma_buf_map_attachment()
1131 sg_table = __map_dma_buf(attach, direction); in dma_buf_map_attachment()
1135 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_map_attachment()
1137 attach->dmabuf->ops->unpin(attach); in dma_buf_map_attachment()
1139 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) { in dma_buf_map_attachment()
1140 attach->sgt = sg_table; in dma_buf_map_attachment()
1141 attach->dir = direction; in dma_buf_map_attachment()
1169 * @attach: [in] attachment whose scatterlist is to be returned
1175 dma_buf_map_attachment_unlocked(struct dma_buf_attachment *attach, in dma_buf_map_attachment_unlocked() argument
1182 if (WARN_ON(!attach || !attach->dmabuf)) in dma_buf_map_attachment_unlocked()
1185 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_map_attachment_unlocked()
1186 sg_table = dma_buf_map_attachment(attach, direction); in dma_buf_map_attachment_unlocked()
1187 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_map_attachment_unlocked()
1197 * @attach: [in] attachment to unmap buffer from
1203 void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, in dma_buf_unmap_attachment() argument
1209 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) in dma_buf_unmap_attachment()
1212 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_unmap_attachment()
1214 if (attach->sgt == sg_table) in dma_buf_unmap_attachment()
1217 __unmap_dma_buf(attach, sg_table, direction); in dma_buf_unmap_attachment()
1219 if (dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_unmap_attachment()
1221 dma_buf_unpin(attach); in dma_buf_unmap_attachment()
1229 * @attach: [in] attachment to unmap buffer from
1235 void dma_buf_unmap_attachment_unlocked(struct dma_buf_attachment *attach, in dma_buf_unmap_attachment_unlocked() argument
1241 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) in dma_buf_unmap_attachment_unlocked()
1244 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_unmap_attachment_unlocked()
1245 dma_buf_unmap_attachment(attach, sg_table, direction); in dma_buf_unmap_attachment_unlocked()
1246 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_unmap_attachment_unlocked()
1260 struct dma_buf_attachment *attach; in dma_buf_move_notify() local
1264 list_for_each_entry(attach, &dmabuf->attachments, node) in dma_buf_move_notify()
1265 if (attach->importer_ops) in dma_buf_move_notify()
1266 attach->importer_ops->move_notify(attach); in dma_buf_move_notify()