// SPDX-License-Identifier: GPL-2.0-or-later /* * Freescale MPC85xx, MPC83xx DMA Engine support * * Copyright (C) 2007-2010 Freescale Semiconductor, Inc. All rights reserved. * * Author: * Zhang Wei <wei.zhang@freescale.com>, Jul 2007 * Ebony Zhu <ebony.zhu@freescale.com>, May 2007 * * Description: * DMA engine driver for Freescale MPC8540 DMA controller, which is * also fit for MPC8560, MPC8555, MPC8548, MPC8641, and etc. * The support for MPC8349 DMA controller is also added. * * This driver instructs the DMA controller to issue the PCI Read Multiple * command for PCI read operations, instead of using the default PCI Read Line * command. Please be aware that this setting may result in read pre-fetching * on some platforms.
*/
/* * Start the DMA controller * * Preconditions: * - the CDAR register must point to the start descriptor * - the MRn[CS] bit must be cleared
*/ staticvoid dma_start(struct fsldma_chan *chan)
{
u32 mode;
staticvoid dma_halt(struct fsldma_chan *chan)
{
u32 mode; int i;
/* read the mode register */
mode = get_mr(chan);
/* * The 85xx controller supports channel abort, which will stop * the current transfer. On 83xx, this bit is the transfer error * mask bit, which should not be changed.
*/ if ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) {
mode |= FSL_DMA_MR_CA;
set_mr(chan, mode);
/* wait for the DMA controller to become idle */ for (i = 0; i < 100; i++) { if (dma_is_idle(chan)) return;
udelay(10);
}
if (!dma_is_idle(chan))
chan_err(chan, "DMA halt timeout!\n");
}
/** * fsl_chan_set_src_loop_size - Set source address hold transfer size * @chan : Freescale DMA channel * @size : Address loop size, 0 for disable loop * * The set source address hold transfer size. The source * address hold or loop transfer size is when the DMA transfer * data from source address (SA), if the loop size is 4, the DMA will * read data from SA, SA + 1, SA + 2, SA + 3, then loop back to SA, * SA + 1 ... and so on.
*/ staticvoid fsl_chan_set_src_loop_size(struct fsldma_chan *chan, int size)
{
u32 mode;
mode = get_mr(chan);
switch (size) { case 0:
mode &= ~FSL_DMA_MR_SAHE; break; case 1: case 2: case 4: case 8:
mode &= ~FSL_DMA_MR_SAHTS_MASK;
mode |= FSL_DMA_MR_SAHE | (__ilog2(size) << 14); break;
}
set_mr(chan, mode);
}
/** * fsl_chan_set_dst_loop_size - Set destination address hold transfer size * @chan : Freescale DMA channel * @size : Address loop size, 0 for disable loop * * The set destination address hold transfer size. The destination * address hold or loop transfer size is when the DMA transfer * data to destination address (TA), if the loop size is 4, the DMA will * write data to TA, TA + 1, TA + 2, TA + 3, then loop back to TA, * TA + 1 ... and so on.
*/ staticvoid fsl_chan_set_dst_loop_size(struct fsldma_chan *chan, int size)
{
u32 mode;
mode = get_mr(chan);
switch (size) { case 0:
mode &= ~FSL_DMA_MR_DAHE; break; case 1: case 2: case 4: case 8:
mode &= ~FSL_DMA_MR_DAHTS_MASK;
mode |= FSL_DMA_MR_DAHE | (__ilog2(size) << 16); break;
}
set_mr(chan, mode);
}
/** * fsl_chan_set_request_count - Set DMA Request Count for external control * @chan : Freescale DMA channel * @size : Number of bytes to transfer in a single request * * The Freescale DMA channel can be controlled by the external signal DREQ#. * The DMA request count is how many bytes are allowed to transfer before * pausing the channel, after which a new assertion of DREQ# resumes channel * operation. * * A size of 0 disables external pause control. The maximum size is 1024.
*/ staticvoid fsl_chan_set_request_count(struct fsldma_chan *chan, int size)
{
u32 mode;
/** * fsl_chan_toggle_ext_pause - Toggle channel external pause status * @chan : Freescale DMA channel * @enable : 0 is disabled, 1 is enabled. * * The Freescale DMA channel can be controlled by the external signal DREQ#. * The DMA Request Count feature should be used in addition to this feature * to set the number of bytes to transfer before pausing the channel.
*/ staticvoid fsl_chan_toggle_ext_pause(struct fsldma_chan *chan, int enable)
{ if (enable)
chan->feature |= FSL_DMA_CHAN_PAUSE_EXT; else
chan->feature &= ~FSL_DMA_CHAN_PAUSE_EXT;
}
/** * fsl_chan_toggle_ext_start - Toggle channel external start status * @chan : Freescale DMA channel * @enable : 0 is disabled, 1 is enabled. * * If enable the external start, the channel can be started by an * external DMA start pin. So the dma_start() does not start the * transfer immediately. The DMA channel will wait for the * control pin asserted.
*/ staticvoid fsl_chan_toggle_ext_start(struct fsldma_chan *chan, int enable)
{ if (enable)
chan->feature |= FSL_DMA_CHAN_START_EXT; else
chan->feature &= ~FSL_DMA_CHAN_START_EXT;
}
int fsl_dma_external_start(struct dma_chan *dchan, int enable)
{ struct fsldma_chan *chan;
if (list_empty(&chan->ld_pending)) goto out_splice;
/* * Add the hardware descriptor to the chain of hardware descriptors * that already exists in memory. * * This will un-set the EOL bit of the existing transaction, and the * last link in this transaction will become the EOL descriptor.
*/
set_desc_next(chan, &tail->hw, desc->async_tx.phys);
/* * Add the software descriptor and all children to the list * of pending transactions
*/
out_splice:
list_splice_tail_init(&desc->tx_list, &chan->ld_pending);
}
#ifdef CONFIG_PM if (unlikely(chan->pm_state != RUNNING)) {
chan_dbg(chan, "cannot submit due to suspend\n");
spin_unlock_bh(&chan->desc_lock); return -1;
} #endif
/* * assign cookies to all of the software descriptors * that make up this transaction
*/
list_for_each_entry(child, &desc->tx_list, node) {
cookie = dma_cookie_assign(&child->async_tx);
}
/* put this transaction onto the tail of the pending queue */
append_ld_queue(chan, desc);
/** * fsldma_clean_completed_descriptor - free all descriptors which * has been completed and acked * @chan: Freescale DMA channel * * This function is used on all completed and acked descriptors. * All descriptors should only be freed in this function.
*/ staticvoid fsldma_clean_completed_descriptor(struct fsldma_chan *chan)
{ struct fsl_desc_sw *desc, *_desc;
/* Run the callback for each descriptor, in order */
list_for_each_entry_safe(desc, _desc, &chan->ld_completed, node) if (async_tx_test_ack(&desc->async_tx))
fsl_dma_free_descriptor(chan, desc);
}
/** * fsldma_run_tx_complete_actions - cleanup a single link descriptor * @chan: Freescale DMA channel * @desc: descriptor to cleanup and free * @cookie: Freescale DMA transaction identifier * * This function is used on a descriptor which has been executed by the DMA * controller. It will run any callbacks, submit any dependencies.
*/ static dma_cookie_t fsldma_run_tx_complete_actions(struct fsldma_chan *chan, struct fsl_desc_sw *desc, dma_cookie_t cookie)
{ struct dma_async_tx_descriptor *txd = &desc->async_tx;
dma_cookie_t ret = cookie;
BUG_ON(txd->cookie < 0);
if (txd->cookie > 0) {
ret = txd->cookie;
dma_descriptor_unmap(txd); /* Run the link descriptor callback function */
dmaengine_desc_get_callback_invoke(txd, NULL);
}
/* Run any dependencies */
dma_run_dependencies(txd);
return ret;
}
/** * fsldma_clean_running_descriptor - move the completed descriptor from * ld_running to ld_completed * @chan: Freescale DMA channel * @desc: the descriptor which is completed * * Free the descriptor directly if acked by async_tx api, or move it to * queue ld_completed.
*/ staticvoid fsldma_clean_running_descriptor(struct fsldma_chan *chan, struct fsl_desc_sw *desc)
{ /* Remove from the list of transactions */
list_del(&desc->node);
/* * the client is allowed to attach dependent operations * until 'ack' is set
*/ if (!async_tx_test_ack(&desc->async_tx)) { /* * Move this descriptor to the list of descriptors which is * completed, but still awaiting the 'ack' bit to be set.
*/
list_add_tail(&desc->node, &chan->ld_completed); return;
}
/** * fsl_chan_xfer_ld_queue - transfer any pending transactions * @chan : Freescale DMA channel * * HARDWARE STATE: idle * LOCKING: must hold chan->desc_lock
*/ staticvoid fsl_chan_xfer_ld_queue(struct fsldma_chan *chan)
{ struct fsl_desc_sw *desc;
/* * If the list of pending descriptors is empty, then we * don't need to do any work at all
*/ if (list_empty(&chan->ld_pending)) {
chan_dbg(chan, "no pending LDs\n"); return;
}
/* * The DMA controller is not idle, which means that the interrupt * handler will start any queued transactions when it runs after * this transaction finishes
*/ if (!chan->idle) {
chan_dbg(chan, "DMA controller still busy\n"); return;
}
/* * If there are some link descriptors which have not been * transferred, we need to start the controller
*/
/* * Move all elements from the queue of pending transactions * onto the list of running transactions
*/
chan_dbg(chan, "idle, starting controller\n");
desc = list_first_entry(&chan->ld_pending, struct fsl_desc_sw, node);
list_splice_tail_init(&chan->ld_pending, &chan->ld_running);
/* * The 85xx DMA controller doesn't clear the channel start bit * automatically at the end of a transfer. Therefore we must clear * it in software before starting the transfer.
*/ if ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) {
u32 mode;
/* * Program the descriptor's address into the DMA controller, * then start the DMA transaction
*/
set_cdar(chan, desc->async_tx.phys);
get_cdar(chan);
dma_start(chan);
chan->idle = false;
}
/** * fsldma_cleanup_descriptors - cleanup link descriptors which are completed * and move them to ld_completed to free until flag 'ack' is set * @chan: Freescale DMA channel * * This function is used on descriptors which have been executed by the DMA * controller. It will run any callbacks, submit any dependencies, then * free these descriptors if flag 'ack' is set.
*/ staticvoid fsldma_cleanup_descriptors(struct fsldma_chan *chan)
{ struct fsl_desc_sw *desc, *_desc;
dma_cookie_t cookie = 0;
dma_addr_t curr_phys = get_cdar(chan); int seen_current = 0;
fsldma_clean_completed_descriptor(chan);
/* Run the callback for each descriptor, in order */
list_for_each_entry_safe(desc, _desc, &chan->ld_running, node) { /* * do not advance past the current descriptor loaded into the * hardware channel, subsequent descriptors are either in * process or have not been submitted
*/ if (seen_current) break;
/* * stop the search if we reach the current descriptor and the * channel is busy
*/ if (desc->async_tx.phys == curr_phys) {
seen_current = 1; if (!dma_is_idle(chan)) break;
}
/* * Start any pending transactions automatically * * In the ideal case, we keep the DMA controller busy while we go * ahead and free the descriptors below.
*/
fsl_chan_xfer_ld_queue(chan);
if (cookie > 0)
chan->common.completed_cookie = cookie;
}
/** * fsl_dma_alloc_chan_resources - Allocate resources for DMA channel. * @chan : Freescale DMA channel * * This function will create a dma pool for descriptor allocation. * * Return - The number of descriptors allocated.
*/ staticint fsl_dma_alloc_chan_resources(struct dma_chan *dchan)
{ struct fsldma_chan *chan = to_fsl_chan(dchan);
/* Has this channel already been allocated? */ if (chan->desc_pool) return 1;
/* * We need the descriptor to be aligned to 32bytes * for meeting FSL DMA specification requirement.
*/
chan->desc_pool = dma_pool_create(chan->name, chan->dev, sizeof(struct fsl_desc_sw),
__alignof__(struct fsl_desc_sw), 0); if (!chan->desc_pool) {
chan_err(chan, "unable to allocate descriptor pool\n"); return -ENOMEM;
}
/* there is at least one descriptor free to be allocated */ return 1;
}
/** * fsldma_free_desc_list - Free all descriptors in a queue * @chan: Freescae DMA channel * @list: the list to free * * LOCKING: must hold chan->desc_lock
*/ staticvoid fsldma_free_desc_list(struct fsldma_chan *chan, struct list_head *list)
{ struct fsl_desc_sw *desc, *_desc;
/* Remove and free all of the descriptors in the LD queue */
fsldma_free_desc_list(chan, &chan->ld_pending);
fsldma_free_desc_list(chan, &chan->ld_running);
fsldma_free_desc_list(chan, &chan->ld_completed);
chan->idle = true;
/* make sure the channel supports setting burst size */ if (!chan->set_request_count) return -ENXIO;
/* we set the controller burst size depending on direction */ if (config->direction == DMA_MEM_TO_DEV)
size = config->dst_addr_width * config->dst_maxburst; else
size = config->src_addr_width * config->src_maxburst;
/* save and clear the status register */
stat = get_sr(chan);
set_sr(chan, stat);
chan_dbg(chan, "irq: stat = 0x%x\n", stat);
/* check that this was really our device */
stat &= ~(FSL_DMA_SR_CB | FSL_DMA_SR_CH); if (!stat) return IRQ_NONE;
if (stat & FSL_DMA_SR_TE)
chan_err(chan, "Transfer Error!\n");
/* * Programming Error * The DMA_INTERRUPT async_tx is a NULL transfer, which will * trigger a PE interrupt.
*/ if (stat & FSL_DMA_SR_PE) {
chan_dbg(chan, "irq: Programming Error INT\n");
stat &= ~FSL_DMA_SR_PE; if (get_bcr(chan) != 0)
chan_err(chan, "Programming Error!\n");
}
/* * For MPC8349, EOCDI event need to update cookie * and start the next transfer if it exist.
*/ if (stat & FSL_DMA_SR_EOCDI) {
chan_dbg(chan, "irq: End-of-Chain link INT\n");
stat &= ~FSL_DMA_SR_EOCDI;
}
/* * If it current transfer is the end-of-transfer, * we should clear the Channel Start bit for * prepare next transfer.
*/ if (stat & FSL_DMA_SR_EOLNI) {
chan_dbg(chan, "irq: End-of-link INT\n");
stat &= ~FSL_DMA_SR_EOLNI;
}
/* check that the DMA controller is really idle */ if (!dma_is_idle(chan))
chan_err(chan, "irq: controller not idle!\n");
/* check that we handled all of the bits */ if (stat)
chan_err(chan, "irq: unhandled sr 0x%08x\n", stat);
/* * Schedule the tasklet to handle all cleanup of the current * transaction. It will start a new transaction if there is * one pending.
*/
tasklet_schedule(&chan->tasklet);
chan_dbg(chan, "irq: Exit\n"); return IRQ_HANDLED;
}
for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) {
chan = fdev->chan[i]; if (chan && chan->irq) {
chan_dbg(chan, "free per-channel IRQ\n");
free_irq(chan->irq, chan);
}
}
}
staticint fsldma_request_irqs(struct fsldma_device *fdev)
{ struct fsldma_chan *chan; int ret; int i;
/* if we have a per-controller IRQ, use that */ if (fdev->irq) {
dev_dbg(fdev->dev, "request per-controller IRQ\n");
ret = request_irq(fdev->irq, fsldma_ctrl_irq, IRQF_SHARED, "fsldma-controller", fdev); return ret;
}
/* no per-controller IRQ, use the per-channel IRQs */ for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) {
chan = fdev->chan[i]; if (!chan) continue;
if (!chan->irq) {
chan_err(chan, "interrupts property missing in device tree\n");
ret = -ENODEV; goto out_unwind;
}
chan_dbg(chan, "request per-channel IRQ\n");
ret = request_irq(chan->irq, fsldma_chan_irq, IRQF_SHARED, "fsldma-chan", chan); if (ret) {
chan_err(chan, "unable to request per-channel IRQ\n"); goto out_unwind;
}
}
return 0;
out_unwind: for (/* none */; i >= 0; i--) {
chan = fdev->chan[i]; if (!chan) continue;
fdev->dev = &op->dev;
INIT_LIST_HEAD(&fdev->common.channels); /* The DMA address bits supported for this device. */
fdev->addr_bits = (long)device_get_match_data(fdev->dev);
/* ioremap the registers for use */
fdev->regs = of_iomap(op->dev.of_node, 0); if (!fdev->regs) {
dev_err(&op->dev, "unable to ioremap registers\n");
err = -ENOMEM; goto out_free;
}
/* map the channel IRQ if it exists, but don't hookup the handler yet */
fdev->irq = irq_of_parse_and_map(op->dev.of_node, 0);
/* * We cannot use of_platform_bus_probe() because there is no * of_platform_bus_remove(). Instead, we manually instantiate every DMA * channel object.
*/
for_each_child_of_node(op->dev.of_node, child) { if (of_device_is_compatible(child, "fsl,eloplus-dma-channel")) {
fsl_dma_chan_probe(fdev, child,
FSL_DMA_IP_85XX | FSL_DMA_BIG_ENDIAN, "fsl,eloplus-dma-channel");
}
/* * Hookup the IRQ handler(s) * * If we have a per-controller interrupt, we prefer that to the * per-channel interrupts to reduce the number of shared interrupt * handlers on the same IRQ line
*/
err = fsldma_request_irqs(fdev); if (err) {
dev_err(fdev->dev, "unable to request IRQs\n"); goto out_free_fdev;
}
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.