/** * struct xilinx_dpdma_chan - DPDMA channel * @vchan: virtual DMA channel * @reg: register base address * @id: channel ID * @wait_to_stop: queue to wait for outstanding transactions before stopping * @running: true if the channel is running * @first_frame: flag for the first frame of stream * @video_group: flag if multi-channel operation is needed for video channels * @lock: lock to access struct xilinx_dpdma_chan. Must be taken before * @vchan.lock, if both are to be held. * @desc_pool: descriptor allocation pool * @err_task: error IRQ bottom half handler * @desc: References to descriptors being processed * @desc.pending: Descriptor schedule to the hardware, pending execution * @desc.active: Descriptor being executed by the hardware * @xdev: DPDMA device
*/ struct xilinx_dpdma_chan { struct virt_dma_chan vchan; void __iomem *reg; unsignedint id;
/** * xilinx_dpdma_sw_desc_set_dma_addrs - Set DMA addresses in the descriptor * @xdev: DPDMA device * @sw_desc: The software descriptor in which to set DMA addresses * @prev: The previous descriptor * @dma_addr: array of dma addresses * @num_src_addr: number of addresses in @dma_addr * * Set all the DMA addresses in the hardware descriptor corresponding to @dev * from @dma_addr. If a previous descriptor is specified in @prev, its next * descriptor DMA address is set to the DMA address of @sw_desc. @prev may be * identical to @sw_desc for cyclic transfers.
*/ staticvoid xilinx_dpdma_sw_desc_set_dma_addrs(struct xilinx_dpdma_device *xdev, struct xilinx_dpdma_sw_desc *sw_desc, struct xilinx_dpdma_sw_desc *prev,
dma_addr_t dma_addr[], unsignedint num_src_addr)
{ struct xilinx_dpdma_hw_desc *hw_desc = &sw_desc->hw; unsignedint i;
hw_desc->src_addr = lower_32_bits(dma_addr[0]); if (xdev->ext_addr)
hw_desc->addr_ext |=
FIELD_PREP(XILINX_DPDMA_DESC_ADDR_EXT_SRC_ADDR_MASK,
upper_32_bits(dma_addr[0]));
for (i = 1; i < num_src_addr; i++) {
u32 *addr = &hw_desc->src_addr2;
addr[i - 1] = lower_32_bits(dma_addr[i]);
if (xdev->ext_addr) {
u32 *addr_ext = &hw_desc->addr_ext_23;
u32 addr_msb;
/** * xilinx_dpdma_chan_prep_cyclic - Prepare a cyclic dma descriptor * @chan: DPDMA channel * @buf_addr: buffer address * @buf_len: buffer length * @period_len: number of periods * @flags: tx flags argument passed in to prepare function * * Prepare a tx descriptor incudling internal software/hardware descriptors * for the given cyclic transaction. * * Return: A dma async tx descriptor on success, or NULL.
*/ staticstruct dma_async_tx_descriptor *
xilinx_dpdma_chan_prep_cyclic(struct xilinx_dpdma_chan *chan,
dma_addr_t buf_addr, size_t buf_len,
size_t period_len, unsignedlong flags)
{ struct xilinx_dpdma_tx_desc *tx_desc; struct xilinx_dpdma_sw_desc *sw_desc, *last = NULL; unsignedint periods = buf_len / period_len; unsignedint i;
tx_desc = xilinx_dpdma_chan_alloc_tx_desc(chan); if (!tx_desc) return NULL;
for (i = 0; i < periods; i++) { struct xilinx_dpdma_hw_desc *hw_desc;
if (!IS_ALIGNED(buf_addr, XILINX_DPDMA_ALIGN_BYTES)) {
dev_err(chan->xdev->dev, "buffer should be aligned at %d B\n",
XILINX_DPDMA_ALIGN_BYTES); goto error;
}
sw_desc = xilinx_dpdma_chan_alloc_sw_desc(chan); if (!sw_desc) goto error;
/** * xilinx_dpdma_chan_prep_interleaved_dma - Prepare an interleaved dma * descriptor * @chan: DPDMA channel * @xt: dma interleaved template * * Prepare a tx descriptor including internal software/hardware descriptors * based on @xt. * * Return: A DPDMA TX descriptor on success, or NULL.
*/ staticstruct xilinx_dpdma_tx_desc *
xilinx_dpdma_chan_prep_interleaved_dma(struct xilinx_dpdma_chan *chan, struct dma_interleaved_template *xt)
{ struct xilinx_dpdma_tx_desc *tx_desc; struct xilinx_dpdma_sw_desc *sw_desc; struct xilinx_dpdma_hw_desc *hw_desc;
size_t hsize = xt->sgl[0].size;
size_t stride = hsize + xt->sgl[0].icg;
if (!IS_ALIGNED(xt->src_start, XILINX_DPDMA_ALIGN_BYTES)) {
dev_err(chan->xdev->dev, "chan%u: buffer should be aligned at %d B\n",
chan->id, XILINX_DPDMA_ALIGN_BYTES); return NULL;
}
tx_desc = xilinx_dpdma_chan_alloc_tx_desc(chan); if (!tx_desc) return NULL;
sw_desc = xilinx_dpdma_chan_alloc_sw_desc(chan); if (!sw_desc) {
xilinx_dpdma_chan_free_tx_desc(&tx_desc->vdesc); return NULL;
}
/** * xilinx_dpdma_chan_enable - Enable the channel * @chan: DPDMA channel * * Enable the channel and its interrupts. Set the QoS values for video class.
*/ staticvoid xilinx_dpdma_chan_enable(struct xilinx_dpdma_chan *chan)
{
u32 reg;
for (i = ZYNQMP_DPDMA_VIDEO0; i <= ZYNQMP_DPDMA_VIDEO2; i++) { if (xdev->chan[i]->video_group && !xdev->chan[i]->running) return 0;
if (xdev->chan[i]->video_group)
channels |= BIT(i);
}
return channels;
}
/** * xilinx_dpdma_chan_queue_transfer - Queue the next transfer * @chan: DPDMA channel * * Queue the next descriptor, if any, to the hardware. If the channel is * stopped, start it first. Otherwise retrigger it with the next descriptor.
*/ staticvoid xilinx_dpdma_chan_queue_transfer(struct xilinx_dpdma_chan *chan)
{ struct xilinx_dpdma_device *xdev = chan->xdev; struct xilinx_dpdma_sw_desc *sw_desc; struct xilinx_dpdma_tx_desc *desc; struct virt_dma_desc *vdesc;
u32 reg, channels; bool first_frame;
/* * Assign the cookie to descriptors in this transaction. Only 16 bit * will be used, but it should be enough.
*/
list_for_each_entry(sw_desc, &desc->descriptors, node)
sw_desc->hw.desc_id = desc->vdesc.tx.cookie
& XILINX_DPDMA_CH_DESC_ID_MASK;
if (chan->video_group) {
channels = xilinx_dpdma_chan_video_group_ready(chan); /* * Trigger the transfer only when all channels in the group are * ready.
*/ if (!channels) return;
} else {
channels = BIT(chan->id);
}
if (first_frame)
reg = XILINX_DPDMA_GBL_TRIG_MASK(channels); else
reg = XILINX_DPDMA_GBL_RETRIG_MASK(channels);
dpdma_write(xdev->reg, XILINX_DPDMA_GBL, reg);
}
/** * xilinx_dpdma_chan_ostand - Number of outstanding transactions * @chan: DPDMA channel * * Read and return the number of outstanding transactions from register. * * Return: Number of outstanding transactions from the status register.
*/ static u32 xilinx_dpdma_chan_ostand(struct xilinx_dpdma_chan *chan)
{ return FIELD_GET(XILINX_DPDMA_CH_STATUS_OTRAN_CNT_MASK,
dpdma_read(chan->reg, XILINX_DPDMA_CH_STATUS));
}
/** * xilinx_dpdma_chan_notify_no_ostand - Notify no outstanding transaction event * @chan: DPDMA channel * * Notify waiters for no outstanding event, so waiters can stop the channel * safely. This function is supposed to be called when 'no outstanding' * interrupt is generated. The 'no outstanding' interrupt is disabled and * should be re-enabled when this event is handled. If the channel status * register still shows some number of outstanding transactions, the interrupt * remains enabled. * * Return: 0 on success. On failure, -EWOULDBLOCK if there's still outstanding * transaction(s).
*/ staticint xilinx_dpdma_chan_notify_no_ostand(struct xilinx_dpdma_chan *chan)
{
u32 cnt;
/** * xilinx_dpdma_chan_wait_no_ostand - Wait for the no outstanding irq * @chan: DPDMA channel * * Wait for the no outstanding transaction interrupt. This functions can sleep * for 50ms. * * Return: 0 on success. On failure, -ETIMEOUT for time out, or the error code * from wait_event_interruptible_timeout().
*/ staticint xilinx_dpdma_chan_wait_no_ostand(struct xilinx_dpdma_chan *chan)
{ int ret;
/* Wait for a no outstanding transaction interrupt upto 50msec */
ret = wait_event_interruptible_timeout(chan->wait_to_stop,
!xilinx_dpdma_chan_ostand(chan),
msecs_to_jiffies(50)); if (ret > 0) {
dpdma_write(chan->xdev->reg, XILINX_DPDMA_IEN,
XILINX_DPDMA_INTR_NO_OSTAND(chan->id)); return 0;
}
dev_err(chan->xdev->dev, "chan%u: not ready to stop: %d trans\n",
chan->id, xilinx_dpdma_chan_ostand(chan));
if (ret == 0) return -ETIMEDOUT;
return ret;
}
/** * xilinx_dpdma_chan_poll_no_ostand - Poll the outstanding transaction status * @chan: DPDMA channel * * Poll the outstanding transaction status, and return when there's no * outstanding transaction. This functions can be used in the interrupt context * or where the atomicity is required. Calling thread may wait more than 50ms. * * Return: 0 on success, or -ETIMEDOUT.
*/ staticint xilinx_dpdma_chan_poll_no_ostand(struct xilinx_dpdma_chan *chan)
{
u32 cnt, loop = 50000;
/* Poll at least for 50ms (20 fps). */ do {
cnt = xilinx_dpdma_chan_ostand(chan);
udelay(1);
} while (loop-- > 0 && cnt);
if (loop) {
dpdma_write(chan->xdev->reg, XILINX_DPDMA_IEN,
XILINX_DPDMA_INTR_NO_OSTAND(chan->id)); return 0;
}
dev_err(chan->xdev->dev, "chan%u: not ready to stop: %d trans\n",
chan->id, xilinx_dpdma_chan_ostand(chan));
return -ETIMEDOUT;
}
/** * xilinx_dpdma_chan_stop - Stop the channel * @chan: DPDMA channel * * Stop a previously paused channel by first waiting for completion of all * outstanding transaction and then disabling the channel. * * Return: 0 on success, or -ETIMEDOUT if the channel failed to stop.
*/ staticint xilinx_dpdma_chan_stop(struct xilinx_dpdma_chan *chan)
{ unsignedlong flags; int ret;
ret = xilinx_dpdma_chan_wait_no_ostand(chan); if (ret) return ret;
/** * xilinx_dpdma_chan_done_irq - Handle hardware descriptor completion * @chan: DPDMA channel * * Handle completion of the currently active descriptor (@chan->desc.active). As * we currently support cyclic transfers only, this just invokes the cyclic * callback. The descriptor will be completed at the VSYNC interrupt when a new * descriptor replaces it.
*/ staticvoid xilinx_dpdma_chan_done_irq(struct xilinx_dpdma_chan *chan)
{ struct xilinx_dpdma_tx_desc *active;
spin_lock(&chan->lock);
xilinx_dpdma_debugfs_desc_done_irq(chan);
active = chan->desc.active; if (active)
vchan_cyclic_callback(&active->vdesc); else
dev_warn(chan->xdev->dev, "chan%u: DONE IRQ with no active descriptor!\n",
chan->id);
spin_unlock(&chan->lock);
}
/** * xilinx_dpdma_chan_vsync_irq - Handle hardware descriptor scheduling * @chan: DPDMA channel * * At VSYNC the active descriptor may have been replaced by the pending * descriptor. Detect this through the DESC_ID and perform appropriate * bookkeeping.
*/ staticvoid xilinx_dpdma_chan_vsync_irq(struct xilinx_dpdma_chan *chan)
{ struct xilinx_dpdma_tx_desc *pending; struct xilinx_dpdma_sw_desc *sw_desc;
u32 desc_id;
spin_lock(&chan->lock);
pending = chan->desc.pending; if (!chan->running || !pending) goto out;
/* If the retrigger raced with vsync, retry at the next frame. */
sw_desc = list_first_entry(&pending->descriptors, struct xilinx_dpdma_sw_desc, node); if (sw_desc->hw.desc_id != desc_id) {
dev_dbg(chan->xdev->dev, "chan%u: vsync race lost (%u != %u), retrying\n",
chan->id, sw_desc->hw.desc_id, desc_id); goto out;
}
/* * Complete the active descriptor, if any, promote the pending * descriptor to active, and queue the next transfer, if any.
*/
spin_lock(&chan->vchan.lock); if (chan->desc.active)
vchan_cookie_complete(&chan->desc.active->vdesc);
chan->desc.active = pending;
chan->desc.pending = NULL;
/** * xilinx_dpdma_chan_handle_err - DPDMA channel error handling * @chan: DPDMA channel * * This function is called when any channel error or any global error occurs. * The function disables the paused channel by errors and determines * if the current active descriptor can be rescheduled depending on * the descriptor status.
*/ staticvoid xilinx_dpdma_chan_handle_err(struct xilinx_dpdma_chan *chan)
{ struct xilinx_dpdma_device *xdev = chan->xdev; struct xilinx_dpdma_tx_desc *active; unsignedlong flags;
/** * xilinx_dpdma_alloc_chan_resources - Allocate resources for the channel * @dchan: DMA channel * * Allocate a descriptor pool for the channel. * * Return: 0 on success, or -ENOMEM if failed to allocate a pool.
*/ staticint xilinx_dpdma_alloc_chan_resources(struct dma_chan *dchan)
{ struct xilinx_dpdma_chan *chan = to_xilinx_chan(dchan);
size_t align = __alignof__(struct xilinx_dpdma_sw_desc);
chan->desc_pool = dma_pool_create(dev_name(chan->xdev->dev),
chan->xdev->dev, sizeof(struct xilinx_dpdma_sw_desc),
align, 0); if (!chan->desc_pool) {
dev_err(chan->xdev->dev, "chan%u: failed to allocate a descriptor pool\n",
chan->id); return -ENOMEM;
}
return 0;
}
/** * xilinx_dpdma_free_chan_resources - Free all resources for the channel * @dchan: DMA channel * * Free resources associated with the virtual DMA channel, and destroy the * descriptor pool.
*/ staticvoid xilinx_dpdma_free_chan_resources(struct dma_chan *dchan)
{ struct xilinx_dpdma_chan *chan = to_xilinx_chan(dchan);
/* * The destination address doesn't need to be specified as the DPDMA is * hardwired to the destination (the DP controller). The transfer * width, burst size and port window size are thus meaningless, they're * fixed both on the DPDMA side and on the DP controller side.
*/
/* * Use the peripheral_config to indicate that the channel is part * of a video group. This requires matching use of the custom * structure in each driver.
*/
pconfig = config->peripheral_config; if (WARN_ON(pconfig && config->peripheral_size != sizeof(*pconfig))) return -EINVAL;
/** * xilinx_dpdma_terminate_all - Terminate the channel and descriptors * @dchan: DMA channel * * Pause the channel without waiting for ongoing transfers to complete. Waiting * for completion is performed by xilinx_dpdma_synchronize() that will disable * the channel to complete the stop. * * All the descriptors associated with the channel that are guaranteed not to * be touched by the hardware. The pending and active descriptor are not * touched, and will be freed either upon completion, or by * xilinx_dpdma_synchronize(). * * Return: 0 on success, or -ETIMEDOUT if the channel failed to stop.
*/ staticint xilinx_dpdma_terminate_all(struct dma_chan *dchan)
{ struct xilinx_dpdma_chan *chan = to_xilinx_chan(dchan); struct xilinx_dpdma_device *xdev = chan->xdev;
LIST_HEAD(descriptors); unsignedlong flags; unsignedint i;
/* Pause the channel (including the whole video group if applicable). */ if (chan->video_group) { for (i = ZYNQMP_DPDMA_VIDEO0; i <= ZYNQMP_DPDMA_VIDEO2; i++) { if (xdev->chan[i]->video_group &&
xdev->chan[i]->running) {
xilinx_dpdma_chan_pause(xdev->chan[i]);
xdev->chan[i]->video_group = false;
}
}
} else {
xilinx_dpdma_chan_pause(chan);
}
/* Gather all the descriptors we can free and free them. */
spin_lock_irqsave(&chan->vchan.lock, flags);
vchan_get_all_descriptors(&chan->vchan, &descriptors);
spin_unlock_irqrestore(&chan->vchan.lock, flags);
/** * xilinx_dpdma_synchronize - Synchronize callback execution * @dchan: DMA channel * * Synchronizing callback execution ensures that all previously issued * transfers have completed and all associated callbacks have been called and * have returned. * * This function waits for the DMA channel to stop. It assumes it has been * paused by a previous call to dmaengine_terminate_async(), and that no new * pending descriptors have been issued with dma_async_issue_pending(). The * behaviour is undefined otherwise.
*/ staticvoid xilinx_dpdma_synchronize(struct dma_chan *dchan)
{ struct xilinx_dpdma_chan *chan = to_xilinx_chan(dchan); unsignedlong flags;
xilinx_dpdma_chan_stop(chan);
spin_lock_irqsave(&chan->vchan.lock, flags); if (chan->desc.pending) {
vchan_terminate_vdesc(&chan->desc.pending->vdesc);
chan->desc.pending = NULL;
} if (chan->desc.active) {
vchan_terminate_vdesc(&chan->desc.active->vdesc);
chan->desc.active = NULL;
}
spin_unlock_irqrestore(&chan->vchan.lock, flags);
vchan_synchronize(&chan->vchan);
}
/* ----------------------------------------------------------------------------- * Interrupt and Tasklet Handling
*/
/** * xilinx_dpdma_err - Detect any global error * @isr: Interrupt Status Register * @eisr: Error Interrupt Status Register * * Return: True if any global error occurs, or false otherwise.
*/ staticbool xilinx_dpdma_err(u32 isr, u32 eisr)
{ if (isr & XILINX_DPDMA_INTR_GLOBAL_ERR ||
eisr & XILINX_DPDMA_EINTR_GLOBAL_ERR) returntrue;
returnfalse;
}
/** * xilinx_dpdma_handle_err_irq - Handle DPDMA error interrupt * @xdev: DPDMA device * @isr: masked Interrupt Status Register * @eisr: Error Interrupt Status Register * * Handle if any error occurs based on @isr and @eisr. This function disables * corresponding error interrupts, and those should be re-enabled once handling * is done.
*/ staticvoid xilinx_dpdma_handle_err_irq(struct xilinx_dpdma_device *xdev,
u32 isr, u32 eisr)
{ bool err = xilinx_dpdma_err(isr, eisr); unsignedint i;
/** * xilinx_dpdma_chan_err_task - Per channel tasklet for error handling * @t: pointer to the tasklet associated with this handler * * Per channel error handling tasklet. This function waits for the outstanding * transaction to complete and triggers error handling. After error handling, * re-enable channel error interrupts, and restart the channel if needed.
*/ staticvoid xilinx_dpdma_chan_err_task(struct tasklet_struct *t)
{ struct xilinx_dpdma_chan *chan = from_tasklet(chan, t, err_task); struct xilinx_dpdma_device *xdev = chan->xdev; unsignedlong flags;
/* Proceed error handling even when polling fails. */
xilinx_dpdma_chan_poll_no_ostand(chan);
if (status & XILINX_DPDMA_INTR_VSYNC) { /* * There's a single VSYNC interrupt that needs to be processed * by each running channel to update the active descriptor.
*/ for (i = 0; i < ARRAY_SIZE(xdev->chan); i++) { struct xilinx_dpdma_chan *chan = xdev->chan[i];
for (i = 0; i < ARRAY_SIZE(xdev->chan); ++i) {
ret = xilinx_dpdma_chan_init(xdev, i); if (ret < 0) {
dev_err(xdev->dev, "failed to initialize channel %u\n",
i); goto error;
}
}
ret = clk_prepare_enable(xdev->axi_clk); if (ret) {
dev_err(xdev->dev, "failed to enable the axi clock\n"); goto error;
}
ret = dma_async_device_register(ddev); if (ret) {
dev_err(xdev->dev, "failed to register the dma device\n"); goto error_dma_async;
}
ret = of_dma_controller_register(xdev->dev->of_node,
of_dma_xilinx_xlate, ddev); if (ret) {
dev_err(xdev->dev, "failed to register DMA to DT DMA helper\n"); goto error_of_dma;
}
xilinx_dpdma_enable_irq(xdev);
xilinx_dpdma_debugfs_init(xdev);
dev_info(&pdev->dev, "Xilinx DPDMA engine is probed\n");
return 0;
error_of_dma:
dma_async_device_unregister(ddev);
error_dma_async:
clk_disable_unprepare(xdev->axi_clk);
error: for (i = 0; i < ARRAY_SIZE(xdev->chan); i++)
xilinx_dpdma_chan_remove(xdev->chan[i]);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.