Lines Matching refs:attach

789  * @attach:    [in]    attachment which should be pinned
794 int dma_buf_pin(struct dma_buf_attachment *attach)
796 struct dma_buf *dmabuf = attach->dmabuf;
802 ret = dmabuf->ops->pin(attach);
811 * calls attach() of dma_buf_ops to allow device-specific attach functionality
812 * @dmabuf: [in] buffer to attach device to.
832 struct dma_buf_attachment *attach;
843 attach = kzalloc(sizeof(*attach), GFP_KERNEL);
844 if (!attach) {
848 attach->dev = dev;
849 attach->dmabuf = dmabuf;
851 attach->peer2peer = importer_ops->allow_peer2peer;
853 attach->importer_ops = importer_ops;
854 attach->importer_priv = importer_priv;
856 if (dmabuf->ops->attach) {
857 ret = dmabuf->ops->attach(dmabuf, attach);
863 list_add(&attach->node, &dmabuf->attachments);
870 if (dma_buf_attachment_is_dynamic(attach) != dma_buf_is_dynamic(dmabuf)) {
873 if (dma_buf_is_dynamic(attach->dmabuf)) {
874 dma_resv_lock(attach->dmabuf->resv, NULL);
875 ret = dma_buf_pin(attach);
881 sgt = dmabuf->ops->map_dma_buf(attach, DMA_BIDIRECTIONAL);
889 if (dma_buf_is_dynamic(attach->dmabuf)) {
890 dma_resv_unlock(attach->dmabuf->resv);
892 attach->sgt = sgt;
893 attach->dir = DMA_BIDIRECTIONAL;
896 return attach;
899 kfree(attach);
903 if (dma_buf_is_dynamic(attach->dmabuf)) {
904 dma_buf_unpin(attach);
908 if (dma_buf_is_dynamic(attach->dmabuf)) {
909 dma_resv_unlock(attach->dmabuf->resv);
912 dma_buf_detach(dmabuf, attach);
919 * @dmabuf: [in] buffer to attach device to.
935 * @attach: [in] attachment to be detached; is free'd after this call.
939 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
941 if (WARN_ON(!dmabuf || !attach)) {
945 if (attach->sgt) {
946 if (dma_buf_is_dynamic(attach->dmabuf)) {
947 dma_resv_lock(attach->dmabuf->resv, NULL);
950 dmabuf->ops->unmap_dma_buf(attach, attach->sgt, attach->dir);
952 if (dma_buf_is_dynamic(attach->dmabuf)) {
953 dma_buf_unpin(attach);
954 dma_resv_unlock(attach->dmabuf->resv);
959 list_del(&attach->node);
962 dmabuf->ops->detach(dmabuf, attach);
965 kfree(attach);
972 * @attach: [in] attachment which should be unpinned
974 void dma_buf_unpin(struct dma_buf_attachment *attach)
976 struct dma_buf *dmabuf = attach->dmabuf;
981 dmabuf->ops->unpin(attach);
990 * @attach: [in] attachment whose scatterlist is to be returned
1001 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, enum dma_data_direction direction)
1008 if (WARN_ON(!attach || !attach->dmabuf)) {
1012 if (dma_buf_attachment_is_dynamic(attach)) {
1013 dma_resv_assert_held(attach->dmabuf->resv);
1016 if (attach->sgt) {
1021 if (attach->dir != direction && attach->dir != DMA_BIDIRECTIONAL) {
1025 return attach->sgt;
1028 if (dma_buf_is_dynamic(attach->dmabuf)) {
1029 dma_resv_assert_held(attach->dmabuf->resv);
1031 r = dma_buf_pin(attach);
1038 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
1043 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) && !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
1044 dma_buf_unpin(attach);
1047 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
1048 attach->sgt = sg_table;
1049 attach->dir = direction;
1060 * @attach: [in] attachment to unmap buffer from
1066 void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, struct sg_table *sg_table,
1071 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) {
1075 if (dma_buf_attachment_is_dynamic(attach)) {
1076 dma_resv_assert_held(attach->dmabuf->resv);
1079 if (attach->sgt == sg_table) {
1083 if (dma_buf_is_dynamic(attach->dmabuf)) {
1084 dma_resv_assert_held(attach->dmabuf->resv);
1087 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
1089 if (dma_buf_is_dynamic(attach->dmabuf) && !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
1090 dma_buf_unpin(attach);
1105 struct dma_buf_attachment *attach;
1109 list_for_each_entry(attach, &dmabuf->attachments, node) if (attach->importer_ops)
1110 attach->importer_ops->move_notify(attach);