|
@@ -35,6 +35,7 @@ struct virt_dma_chan {
|
|
struct list_head desc_completed;
|
|
struct list_head desc_completed;
|
|
|
|
|
|
struct virt_dma_desc *cyclic;
|
|
struct virt_dma_desc *cyclic;
|
|
|
|
+ struct virt_dma_desc *vd_terminated;
|
|
};
|
|
};
|
|
|
|
|
|
static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan)
|
|
static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan)
|
|
@@ -103,6 +104,20 @@ static inline void vchan_cookie_complete(struct virt_dma_desc *vd)
|
|
tasklet_schedule(&vc->task);
|
|
tasklet_schedule(&vc->task);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * vchan_vdesc_fini - Free or reuse a descriptor
|
|
|
|
+ * @vd: virtual descriptor to free/reuse
|
|
|
|
+ */
|
|
|
|
+static inline void vchan_vdesc_fini(struct virt_dma_desc *vd)
|
|
|
|
+{
|
|
|
|
+ struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
|
|
|
|
+
|
|
|
|
+ if (dmaengine_desc_test_reuse(&vd->tx))
|
|
|
|
+ list_add(&vd->node, &vc->desc_allocated);
|
|
|
|
+ else
|
|
|
|
+ vc->desc_free(vd);
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* vchan_cyclic_callback - report the completion of a period
|
|
* vchan_cyclic_callback - report the completion of a period
|
|
* @vd: virtual descriptor
|
|
* @vd: virtual descriptor
|
|
@@ -115,6 +130,25 @@ static inline void vchan_cyclic_callback(struct virt_dma_desc *vd)
|
|
tasklet_schedule(&vc->task);
|
|
tasklet_schedule(&vc->task);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * vchan_terminate_vdesc - Disable pending cyclic callback
|
|
|
|
+ * @vd: virtual descriptor to be terminated
|
|
|
|
+ *
|
|
|
|
+ * vc.lock must be held by caller
|
|
|
|
+ */
|
|
|
|
+static inline void vchan_terminate_vdesc(struct virt_dma_desc *vd)
|
|
|
|
+{
|
|
|
|
+ struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
|
|
|
|
+
|
|
|
|
+ /* free up stuck descriptor */
|
|
|
|
+ if (vc->vd_terminated)
|
|
|
|
+ vchan_vdesc_fini(vc->vd_terminated);
|
|
|
|
+
|
|
|
|
+ vc->vd_terminated = vd;
|
|
|
|
+ if (vc->cyclic == vd)
|
|
|
|
+ vc->cyclic = NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* vchan_next_desc - peek at the next descriptor to be processed
|
|
* vchan_next_desc - peek at the next descriptor to be processed
|
|
* @vc: virtual channel to obtain descriptor from
|
|
* @vc: virtual channel to obtain descriptor from
|
|
@@ -168,10 +202,20 @@ static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
|
|
* Makes sure that all scheduled or active callbacks have finished running. For
|
|
* Makes sure that all scheduled or active callbacks have finished running. For
|
|
* proper operation the caller has to ensure that no new callbacks are scheduled
|
|
* proper operation the caller has to ensure that no new callbacks are scheduled
|
|
* after the invocation of this function started.
|
|
* after the invocation of this function started.
|
|
|
|
+ * Free up the terminated cyclic descriptor to prevent memory leakage.
|
|
*/
|
|
*/
|
|
static inline void vchan_synchronize(struct virt_dma_chan *vc)
|
|
static inline void vchan_synchronize(struct virt_dma_chan *vc)
|
|
{
|
|
{
|
|
|
|
+ unsigned long flags;
|
|
|
|
+
|
|
tasklet_kill(&vc->task);
|
|
tasklet_kill(&vc->task);
|
|
|
|
+
|
|
|
|
+ spin_lock_irqsave(&vc->lock, flags);
|
|
|
|
+ if (vc->vd_terminated) {
|
|
|
|
+ vchan_vdesc_fini(vc->vd_terminated);
|
|
|
|
+ vc->vd_terminated = NULL;
|
|
|
|
+ }
|
|
|
|
+ spin_unlock_irqrestore(&vc->lock, flags);
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|
|
#endif
|