Lines Matching refs:attach
778 static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach,
784 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
788 if (!dma_buf_attachment_is_dynamic(attach)) {
789 ret = dma_resv_wait_timeout(attach->dmabuf->resv,
793 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
844 * - &dma_buf_ops.attach()
869 * @dmabuf: [in] buffer to attach device to.
877 * Optionally this calls &dma_buf_ops.attach to allow device-specific attach
894 struct dma_buf_attachment *attach;
903 attach = kzalloc(sizeof(*attach), GFP_KERNEL);
904 if (!attach)
907 attach->dev = dev;
908 attach->dmabuf = dmabuf;
910 attach->peer2peer = importer_ops->allow_peer2peer;
911 attach->importer_ops = importer_ops;
912 attach->importer_priv = importer_priv;
914 if (dmabuf->ops->attach) {
915 ret = dmabuf->ops->attach(dmabuf, attach);
920 list_add(&attach->node, &dmabuf->attachments);
927 if (dma_buf_attachment_is_dynamic(attach) !=
931 dma_resv_lock(attach->dmabuf->resv, NULL);
932 if (dma_buf_is_dynamic(attach->dmabuf)) {
933 ret = dmabuf->ops->pin(attach);
938 sgt = __map_dma_buf(attach, DMA_BIDIRECTIONAL);
945 dma_resv_unlock(attach->dmabuf->resv);
946 attach->sgt = sgt;
947 attach->dir = DMA_BIDIRECTIONAL;
950 return attach;
953 kfree(attach);
957 if (dma_buf_is_dynamic(attach->dmabuf))
958 dmabuf->ops->unpin(attach);
961 dma_resv_unlock(attach->dmabuf->resv);
963 dma_buf_detach(dmabuf, attach);
970 * @dmabuf: [in] buffer to attach device to.
983 static void __unmap_dma_buf(struct dma_buf_attachment *attach,
990 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
996 * @attach: [in] attachment to be detached; is free'd after this call.
1002 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
1004 if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf))
1009 if (attach->sgt) {
1011 __unmap_dma_buf(attach, attach->sgt, attach->dir);
1013 if (dma_buf_is_dynamic(attach->dmabuf))
1014 dmabuf->ops->unpin(attach);
1016 list_del(&attach->node);
1021 dmabuf->ops->detach(dmabuf, attach);
1023 kfree(attach);
1029 * @attach: [in] attachment which should be pinned
1031 * Only dynamic importers (who set up @attach with dma_buf_dynamic_attach()) may
1041 int dma_buf_pin(struct dma_buf_attachment *attach)
1043 struct dma_buf *dmabuf = attach->dmabuf;
1046 WARN_ON(!dma_buf_attachment_is_dynamic(attach));
1051 ret = dmabuf->ops->pin(attach);
1059 * @attach: [in] attachment which should be unpinned
1062 * any mapping of @attach again and inform the importer through
1065 void dma_buf_unpin(struct dma_buf_attachment *attach)
1067 struct dma_buf *dmabuf = attach->dmabuf;
1069 WARN_ON(!dma_buf_attachment_is_dynamic(attach));
1074 dmabuf->ops->unpin(attach);
1082 * @attach: [in] attachment whose scatterlist is to be returned
1099 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
1107 if (WARN_ON(!attach || !attach->dmabuf))
1110 dma_resv_assert_held(attach->dmabuf->resv);
1112 if (attach->sgt) {
1117 if (attach->dir != direction &&
1118 attach->dir != DMA_BIDIRECTIONAL)
1121 return attach->sgt;
1124 if (dma_buf_is_dynamic(attach->dmabuf)) {
1126 r = attach->dmabuf->ops->pin(attach);
1132 sg_table = __map_dma_buf(attach, direction);
1136 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
1138 attach->dmabuf->ops->unpin(attach);
1140 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
1141 attach->sgt = sg_table;
1142 attach->dir = direction;
1170 * @attach: [in] attachment whose scatterlist is to be returned
1176 dma_buf_map_attachment_unlocked(struct dma_buf_attachment *attach,
1183 if (WARN_ON(!attach || !attach->dmabuf))
1186 dma_resv_lock(attach->dmabuf->resv, NULL);
1187 sg_table = dma_buf_map_attachment(attach, direction);
1188 dma_resv_unlock(attach->dmabuf->resv);
1198 * @attach: [in] attachment to unmap buffer from
1204 void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
1210 if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
1213 dma_resv_assert_held(attach->dmabuf->resv);
1215 if (attach->sgt == sg_table)
1218 __unmap_dma_buf(attach, sg_table, direction);
1220 if (dma_buf_is_dynamic(attach->dmabuf) &&
1222 dma_buf_unpin(attach);
1230 * @attach: [in] attachment to unmap buffer from
1236 void dma_buf_unmap_attachment_unlocked(struct dma_buf_attachment *attach,
1242 if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
1245 dma_resv_lock(attach->dmabuf->resv, NULL);
1246 dma_buf_unmap_attachment(attach, sg_table, direction);
1247 dma_resv_unlock(attach->dmabuf->resv);
1261 struct dma_buf_attachment *attach;
1265 list_for_each_entry(attach, &dmabuf->attachments, node)
1266 if (attach->importer_ops)
1267 attach->importer_ops->move_notify(attach);