dmaengine: xlldma platform bus driver
PATCH 3/4 dmaengine: xlldma platform bus driver
Platform bus attachment for the Xilinx MPMC Soft Direct Memory Access Controller DMA engine.
---
drivers/dma/xlldma_plat.c +222 -0
@@ -0,0 +1,222 @@ +/* +* Xilinx Multi-Port Memory Controller (MPMC) DMA Engine support +* +* Copyright (C) 2010 Digital Design Corporation. All rights reserved. +* +* Author: +* Steve Magnani <[email protected]>, Mar 2010 +* +* Description: +* Platform bus attachment for the Xilinx MPMC Soft Direct Memory +* Access Controller DMA engine. +* +* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +*/ + +#include <linux/platform_device.h> +#include <linux/module.h> + +#include "xlldma.h" + +static int __devinit xlldma_plat_chan_probe (struct xlldma_device *xdev) +{ +struct xlldma_chan *chan; +struct resource *plat_rsrc; +int err; +struct platform_device *pdev =to_platform_device (xdev->dev); +char irq_name[9 ]; + + plat_rsrc =platform_get_resource (pdev,IORESOURCE_MEM , + xdev->common.chancnt); +if (!plat_rsrc) +return -ENXIO ; + +/* alloc channel */ + chan =kzalloc (sizeof (struct xlldma_chan ),GFP_KERNEL ); +if (!chan) { +dev_err (xdev->dev, +"No free memory for allocating dma channels!\n" ); +return -ENOMEM ; + } + +/* get dma channel register base */ + chan->reg_base =NULL ; + +/* map device registers */ + chan->reg_base =ioremap (plat_rsrc->start, + plat_rsrc->end - plat_rsrc->start +1 ); +if (chan->reg_base) { +dev_dbg (xdev->dev,"MEM base: %p\n" , chan->reg_base); + }else { +dev_err (xdev->dev,"unable to map DMA registers\n" ); + err = -ENXIO ; + goto err_no_reg; + } + + chan->xdev = xdev; + + chan->id = xdev->common.chancnt; +if (chan->id >=XLLDMA_MAX_CHANS_PER_DEVICE ) { +dev_err (xdev->dev,"There is no %d channel!\n" , chan->id); + err = -EINVAL ; + goto err_no_chan; + } + xdev->chan[chan->id] = chan; +tasklet_init (&chan->tasklet, xlldma_cleanup_tasklet, + (unsigned long )chan); + +spin_lock_init (&chan->desc_lock); +INIT_LIST_HEAD (&chan->desc_queue); +INIT_LIST_HEAD (&chan->pending_free); + + chan->common.device = &xdev->common; + +/* Add the channel to DMA device channel list */ +list_add_tail (&chan->common.device_node, &xdev->common.channels); + xdev->common.chancnt++; + +/* RX interrupt is required */ +sprintf (irq_name,"chan%d-rx" , chan->id); + plat_rsrc =platform_get_resource_byname (pdev,IORESOURCE_IRQ , + irq_name); +if (!plat_rsrc) { +dev_err (xdev->dev,"DMA channel %d - missing %s IRQ\n" , + chan->id, irq_name); + err = -ENXIO ; + goto err_no_irq; + } + + chan->rx_irq = plat_rsrc->start; +BUG_ON (plat_rsrc->end != plat_rsrc->start); + + err =request_irq (chan->rx_irq, &xlldma_chan_rx_interrupt, +IRQF_SHARED ,"xlldma-rx" , chan); +if (err) { +dev_err (xdev->dev,"request_irq error on %s, return %d\n" , + irq_name, err); + err = -ENXIO ; + goto err_no_irq; + } + +/* TX interrupt is optional - only needed for DMA_INTERRUPT */ + irq_name[6 ] ='t' ; + plat_rsrc =platform_get_resource_byname (pdev,IORESOURCE_IRQ , + irq_name); +if (plat_rsrc) { + chan->tx_irq = plat_rsrc->start; +BUG_ON (plat_rsrc->end != plat_rsrc->start); + }else { + chan->tx_irq =NO_IRQ ; + } + +if (chan->tx_irq !=NO_IRQ ) { + err =request_irq (chan->tx_irq, &xlldma_chan_tx_interrupt, +IRQF_SHARED ,"xlldma-tx" , chan); +if (err) { +dev_err (xdev->dev, +"request_irq error on %s, return %d\n" , + irq_name, err); + goto err_rx_irq; + } + } + +dev_info (xdev->dev,"#%d, tx irq %d, rx irq %d\n" , chan->id, + chan->tx_irq, chan->rx_irq); + +return 0 ; +err_rx_irq: +free_irq (chan->rx_irq, chan); +err_no_irq: +list_del (&chan->common.device_node); +err_no_chan: +iounmap (chan->reg_base); +err_no_reg: +kfree (chan); +return err; +} + +static int __devinit xlldma_plat_probe (struct platform_device *pdev) +{ +struct xlldma_device *xdev; +int i, rc; + +dev_info (&pdev->dev,"Xilinx DMA engine...\n" ); + + xdev =kzalloc (sizeof (struct xlldma_device ),GFP_KERNEL ); +if (!xdev) { +dev_err (&pdev->dev,"Not enough memory for 'priv'\n" ); + rc = -ENOMEM ; + goto fail_alloc; + } + xdev->dev = &pdev->dev; +INIT_LIST_HEAD (&xdev->common.channels); + + xdev->common.dev = &pdev->dev; +platform_set_drvdata (pdev, xdev); + +do { + rc =xlldma_plat_chan_probe (xdev); + }while (rc ==0 ); + +if (xdev->common.chancnt ==0 ) + goto fail_nochan; + + rc =xlldma_device_setup (xdev->dev); +if (rc ==0 ) +return 0 ; + +/* fail: */ +for (i =0 ; i <XLLDMA_MAX_CHANS_PER_DEVICE ; i++) { +if (xdev->chan[i]) +xlldma_chan_remove (xdev->chan[i]); + } +fail_nochan: +platform_set_drvdata (pdev,NULL ); +kfree (xdev); + +fail_alloc: +return rc; +} + +static int __devexit xlldma_plat_remove(struct platform_device *pdev) +{ +return xlldma_device_teardown (&pdev->dev); +} + +static struct platform_driver xlldma_driver = { + .probe = xlldma_plat_probe, + .remove =__devexit_p (xlldma_plat_remove), + .driver = { + .owner =THIS_MODULE , + .name ="xlldma" , + }, +}; + +static int __init xlldma_plat_init (void ) +{ +int ret; + +pr_info ("Xilinx LocalLink DMA driver\n" ); + + ret =platform_driver_register (&xlldma_driver); +if (ret) +pr_err ("xlldma: failed to register platform driver\n" ); + +return ret; +} + +static void __exit xlldma_plat_exit(void) +{ +platform_driver_unregister (&xlldma_driver); +} + +module_init (xlldma_plat_init); +module_exit (xlldma_plat_exit); + +MODULE_AUTHOR ("Digital Design Corporation" ); +MODULE_DESCRIPTION ("Xilinx LocalLink DMA Platform driver" ); +MODULE_LICENSE ("GPL" );
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500
Quoted 8 lines · Steven J. Magnani
Platform bus attachment for the Xilinx MPMC Soft Direct Memory Access Controller DMA engine.
Signed-off-by Steven J. Magnani <[email protected]>---
diff -uprNa/drivers/dma/xlldma_plat.cb/drivers/dma/xlldma_plat.cdrivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +0
-0
Not really worth putting into a separate file. Just put this hunk in the xlldma.c file to keep a few more symbols out of the global namespace.
Quoted 38 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +37
-0@@ -0,0 +1,222 @@ +/* + * Xilinx Multi-Port Memory Controller (MPMC) DMA Engine support + * + * Copyright (C) 2010 Digital Design Corporation. All rights reserved. + * + * Author: + * Steve Magnani <[email protected]>, Mar 2010 + * + * Description: + * Platform bus attachment for the Xilinx MPMC Soft Direct Memory + * Access Controller DMA engine. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + */ + +#include <linux/platform_device.h> +#include <linux/module.h> + +#include "xlldma.h" + +static int __devinit xlldma_plat_chan_probe(struct xlldma_device *xdev) +{ + struct xlldma_chan *chan; + struct resource *plat_rsrc; + int err; + struct platform_device *pdev = to_platform_device(xdev->dev); + char irq_name[9]; + + plat_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, + xdev->common.chancnt); + if (!plat_rsrc) + return -ENXIO; +
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 47
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +10
-0+ /* alloc channel */ + chan = kzalloc(sizeof(struct xlldma_chan), GFP_KERNEL); + if (!chan) { + dev_err(xdev->dev, + "No free memory for allocating dma channels!\n"); + return -ENOMEM; + } + + /* get dma channel register base */ + chan->reg_base = NULL;
Superfluous statement.
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 58
Quoted 11 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +11
-0+ + /* map device registers */ + chan->reg_base = ioremap(plat_rsrc->start, + plat_rsrc->end - plat_rsrc->start + 1); + if (chan->reg_base) { + dev_dbg(xdev->dev, "MEM base: %p\n", chan->reg_base); + } else { + dev_err(xdev->dev, "unable to map DMA registers\n"); + err = -ENXIO; + goto err_no_reg; + }
General convention is to do this the other way around. No else clause required:
if (!chan->reg_base) {
/* bail out here */
}dev_dbg(...)
Quoted 12 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +12
-0+ + chan->xdev = xdev; + + chan->id = xdev->common.chancnt; + if (chan->id >= XLLDMA_MAX_CHANS_PER_DEVICE) { + dev_err(xdev->dev, "There is no %d channel!\n", chan->id); + err = -EINVAL; + goto err_no_chan; + } + xdev->chan[chan->id] = chan; + tasklet_init(&chan->tasklet, xlldma_cleanup_tasklet, + (unsigned long)chan);
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 80
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +10
-0+ + spin_lock_init(&chan->desc_lock); + INIT_LIST_HEAD(&chan->desc_queue); + INIT_LIST_HEAD(&chan->pending_free); + + chan->common.device = &xdev->common; + + /* Add the channel to DMA device channel list */ + list_add_tail(&chan->common.device_node, &xdev->common.channels); + xdev->common.chancnt++;
Don't you need a spinlock protecting the list access?
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 83
Quoted 3 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +3
-0+ + /* RX interrupt is required */ + sprintf(irq_name, "chan%d-rx", chan->id);
Be defensive. Make irq_name at least 20 bytes long in case chan->id somehow becomes huge.
Quoted 13 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +13
-0+ plat_rsrc = platform_get_resource_byname(pdev, IORESOURCE_IRQ, + irq_name); + if (!plat_rsrc) { + dev_err(xdev->dev, "DMA channel %d - missing %s IRQ\n", + chan->id, irq_name); + err = -ENXIO; + goto err_no_irq; + } + + chan->rx_irq = plat_rsrc->start; + BUG_ON(plat_rsrc->end != plat_rsrc->start); + + err = request_irq(chan->rx_irq, &xlldma_chan_rx_interrupt,
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 106
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +10
-0+ IRQF_SHARED, "xlldma-rx", chan); + if (err) { + dev_err(xdev->dev, "request_irq error on %s, return %d\n", + irq_name, err); + err = -ENXIO; + goto err_no_irq; + } + + /* TX interrupt is optional - only needed for DMA_INTERRUPT */ + irq_name[6] = 't';
And if irq # is in the double digits? This is clever, but unclear and potentially risky. Just do another sprintf()
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 114
Quoted 8 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +8
-0+ plat_rsrc = platform_get_resource_byname(pdev, IORESOURCE_IRQ, + irq_name); + if (plat_rsrc) { + chan->tx_irq = plat_rsrc->start; + BUG_ON(plat_rsrc->end != plat_rsrc->start); + } else { + chan->tx_irq = NO_IRQ; + }
put chan->tx_irq = NO_IRQ before the if(), and you can drop the else statement (a bit simpler).
Quoted 86 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +86
-0+ + if (chan->tx_irq != NO_IRQ) { + err = request_irq(chan->tx_irq, &xlldma_chan_tx_interrupt, + IRQF_SHARED, "xlldma-tx", chan); + if (err) { + dev_err(xdev->dev, + "request_irq error on %s, return %d\n", + irq_name, err); + goto err_rx_irq; + } + } + + dev_info(xdev->dev, "#%d, tx irq %d, rx irq %d\n", chan->id, + chan->tx_irq, chan->rx_irq); + + return 0; +err_rx_irq: + free_irq(chan->rx_irq, chan); +err_no_irq: + list_del(&chan->common.device_node); +err_no_chan: + iounmap(chan->reg_base); +err_no_reg: + kfree(chan); + return err; +} + +static int __devinit xlldma_plat_probe(struct platform_device *pdev) +{ + struct xlldma_device *xdev; + int i, rc; + + dev_info(&pdev->dev, "Xilinx DMA engine...\n"); + + xdev = kzalloc(sizeof(struct xlldma_device), GFP_KERNEL); + if (!xdev) { + dev_err(&pdev->dev, "Not enough memory for 'priv'\n"); + rc = -ENOMEM; + goto fail_alloc; + } + xdev->dev = &pdev->dev; + INIT_LIST_HEAD(&xdev->common.channels); + + xdev->common.dev = &pdev->dev; + platform_set_drvdata(pdev, xdev); + + do { + rc = xlldma_plat_chan_probe(xdev); + } while (rc == 0); + + if (xdev->common.chancnt == 0) + goto fail_nochan; + + rc = xlldma_device_setup(xdev->dev); + if (rc == 0) + return 0; + +/* fail: */ + for (i = 0; i < XLLDMA_MAX_CHANS_PER_DEVICE; i++) { + if (xdev->chan[i]) + xlldma_chan_remove(xdev->chan[i]); + } +fail_nochan: + platform_set_drvdata(pdev, NULL); + kfree(xdev); + +fail_alloc: + return rc; +} + +static int __devexit xlldma_plat_remove(struct platform_device *pdev) +{ + return xlldma_device_teardown(&pdev->dev); +} + +static struct platform_driver xlldma_driver = { + .probe = xlldma_plat_probe, + .remove = __devexit_p(xlldma_plat_remove), + .driver = { + .owner = THIS_MODULE, + .name = "xlldma", + }, +}; + +static int __init xlldma_plat_init(void) +{
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 210
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +10
-0+ int ret; + + pr_info("Xilinx LocalLink DMA driver\n"); + + ret = platform_driver_register(&xlldma_driver); + if (ret) + pr_err("xlldma: failed to register platform driver\n"); + + return ret; +}
Don't bother with all this. sysfs will tell you whether or not the driver got registered. Do this instead:
+static int __init xlldma_plat_init(void)
+{
+ return platform_driver_register(&xlldma_driver);
+}
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 217
Quoted 7 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +7
-0+ +static void __exit xlldma_plat_exit(void) +{ + platform_driver_unregister(&xlldma_driver); +} + +module_init(xlldma_plat_init);
Put the module_init directly after the xlldma_plat_init() function definition.
Quoted 8 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +5
-0+module_exit(xlldma_plat_exit); + +MODULE_AUTHOR("Digital Design Corporation"); +MODULE_DESCRIPTION("Xilinx LocalLink DMA Platform driver"); +MODULE_LICENSE("GPL");
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Quoted 5 lines · Grant Likely
Quoted 3 lines · Steven J. Magnani
Platform bus attachment for the Xilinx MPMC Soft Direct Memory Access Controller DMA engine.
Quoted 9 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500
Quoted 5 lines
Signed-off-by Steven J. Magnani <[email protected]>---
diff -uprNa/drivers/dma/xlldma_plat.cb/drivers/dma/xlldma_plat.cdrivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +0
-0Not really worth putting into a separate file. Just put this hunk in the
xlldma.cfile to keep a few more symbols out of the global namespace.
I can certainly do that, but as someone who's had to add platform bus attachments to drivers that only have OF attachments, I can say from experience that the result ends up being rather messy. I thought (explicitly) decoupling the bus logic from the driver might be an improvement. Maybe it's not enough of a benefit.
Quoted 43 lines
Quoted 43 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +41
-0@@ -0,0 +1,222 @@ +/* + * Xilinx Multi-Port Memory Controller (MPMC) DMA Engine support + * + * Copyright (C) 2010 Digital Design Corporation. All rights reserved. + * + * Author: + * Steve Magnani <[email protected]>, Mar 2010 + * + * Description: + * Platform bus attachment for the Xilinx MPMC Soft Direct Memory + * Access Controller DMA engine. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + */ + +#include <linux/platform_device.h> +#include <linux/module.h> + +#include "xlldma.h" + +static int __devinit xlldma_plat_chan_probe(struct xlldma_device *xdev) +{ + struct xlldma_chan *chan; + struct resource *plat_rsrc; + int err; + struct platform_device *pdev = to_platform_device(xdev->dev); + char irq_name[9]; + + plat_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, + xdev->common.chancnt); + if (!plat_rsrc) + return -ENXIO; + + /* alloc channel */ + chan = kzalloc(sizeof(struct xlldma_chan), GFP_KERNEL); + if (!chan) { + dev_err(xdev->dev,
Quoted 8 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 47
Quoted 6 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +6
-0+ "No free memory for allocating dma channels!\n"); + return -ENOMEM; + } + + /* get dma channel register base */ + chan->reg_base = NULL;Superfluous statement.
Yup.
Quoted 13 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 58
Quoted 12 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +11
-0+ + /* map device registers */ + chan->reg_base = ioremap(plat_rsrc->start, + plat_rsrc->end - plat_rsrc->start + 1); + if (chan->reg_base) { + dev_dbg(xdev->dev, "MEM base: %p\n", chan->reg_base); + } else { + dev_err(xdev->dev, "unable to map DMA registers\n"); + err = -ENXIO; + goto err_no_reg; + }
Quoted 6 lines
General convention is to do this the other way around. No else clause required:
if (!chan->reg_base) { /* bail out here */ }
dev_dbg(...)
Agreed, it's simpler.
Quoted 18 lines
Quoted 18 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +16
-0+ + chan->xdev = xdev; + + chan->id = xdev->common.chancnt; + if (chan->id >= XLLDMA_MAX_CHANS_PER_DEVICE) { + dev_err(xdev->dev, "There is no %d channel!\n", chan->id); + err = -EINVAL; + goto err_no_chan; + } + xdev->chan[chan->id] = chan; + tasklet_init(&chan->tasklet, xlldma_cleanup_tasklet, + (unsigned long)chan); + + spin_lock_init(&chan->desc_lock); + INIT_LIST_HEAD(&chan->desc_queue); + INIT_LIST_HEAD(&chan->pending_free);
Quoted 8 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 80
Quoted 6 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +6
-0+ + chan->common.device = &xdev->common; + + /* Add the channel to DMA device channel list */ + list_add_tail(&chan->common.device_node, &xdev->common.channels); + xdev->common.chancnt++;Don't you need a spinlock protecting the list access?
I'm not sure where the concurrency would come from. At this point we're enumerating, so nothing is externally visible yet. And after we're registered, dmaengine never modifies the list.
Quoted 7 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 83
Quoted 4 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +3
-0+ + /* RX interrupt is required */ + sprintf(irq_name, "chan%d-rx", chan->id);Be defensive. Make
irq_nameat least 20 bytes long in casechan->idsomehow becomes huge.
OK
Quoted 19 lines
Quoted 19 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +18
-0+ plat_rsrc = platform_get_resource_byname(pdev, IORESOURCE_IRQ, + irq_name); + if (!plat_rsrc) { + dev_err(xdev->dev, "DMA channel %d - missing %s IRQ\n", + chan->id, irq_name); + err = -ENXIO; + goto err_no_irq; + } + + chan->rx_irq = plat_rsrc->start; + BUG_ON(plat_rsrc->end != plat_rsrc->start); + + err = request_irq(chan->rx_irq, &xlldma_chan_rx_interrupt, + IRQF_SHARED, "xlldma-rx", chan); + if (err) { + dev_err(xdev->dev, "request_irq error on %s, return %d\n", + irq_name, err); + err = -ENXIO;
Quoted 8 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 106
Quoted 5 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +5
-0+ goto err_no_irq; + } + + /* TX interrupt is optional - only needed for DMA_INTERRUPT */ + irq_name[6] = 't';And if irq # is in the double digits? This is clever, but unclear and potentially risky. Just do another
sprintf()
OK
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 114
Quoted 9 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +8
-0+ plat_rsrc = platform_get_resource_byname(pdev, IORESOURCE_IRQ, + irq_name); + if (plat_rsrc) { + chan->tx_irq = plat_rsrc->start; + BUG_ON(plat_rsrc->end != plat_rsrc->start); + } else { + chan->tx_irq = NO_IRQ; + }
Quoted 2 lines
put
chan->tx_irq=NO_IRQbefore theif(), and you can drop the else statement (a bit simpler).
OK
Quoted 102 lines
Quoted 87 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +86
-0+ + if (chan->tx_irq != NO_IRQ) { + err = request_irq(chan->tx_irq, &xlldma_chan_tx_interrupt, + IRQF_SHARED, "xlldma-tx", chan); + if (err) { + dev_err(xdev->dev, + "request_irq error on %s, return %d\n", + irq_name, err); + goto err_rx_irq; + } + } + + dev_info(xdev->dev, "#%d, tx irq %d, rx irq %d\n", chan->id, + chan->tx_irq, chan->rx_irq); + + return 0; +err_rx_irq: + free_irq(chan->rx_irq, chan); +err_no_irq: + list_del(&chan->common.device_node); +err_no_chan: + iounmap(chan->reg_base); +err_no_reg: + kfree(chan); + return err; +} + +static int __devinit xlldma_plat_probe(struct platform_device *pdev) +{ + struct xlldma_device *xdev; + int i, rc; + + dev_info(&pdev->dev, "Xilinx DMA engine...\n"); + + xdev = kzalloc(sizeof(struct xlldma_device), GFP_KERNEL); + if (!xdev) { + dev_err(&pdev->dev, "Not enough memory for 'priv'\n"); + rc = -ENOMEM; + goto fail_alloc; + } + xdev->dev = &pdev->dev; + INIT_LIST_HEAD(&xdev->common.channels); + + xdev->common.dev = &pdev->dev; + platform_set_drvdata(pdev, xdev); + + do { + rc = xlldma_plat_chan_probe(xdev); + } while (rc == 0); + + if (xdev->common.chancnt == 0) + goto fail_nochan; + + rc = xlldma_device_setup(xdev->dev); + if (rc == 0) + return 0; + +/* fail: */ + for (i = 0; i < XLLDMA_MAX_CHANS_PER_DEVICE; i++) { + if (xdev->chan[i]) + xlldma_chan_remove(xdev->chan[i]); + } +fail_nochan: + platform_set_drvdata(pdev, NULL); + kfree(xdev); + +fail_alloc: + return rc; +} + +static int __devexit xlldma_plat_remove(struct platform_device *pdev) +{ + return xlldma_device_teardown(&pdev->dev); +} + +static struct platform_driver xlldma_driver = { + .probe = xlldma_plat_probe, + .remove = __devexit_p(xlldma_plat_remove), + .driver = { + .owner = THIS_MODULE, + .name = "xlldma", + }, +}; + +static int __init xlldma_plat_init(void) +{drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 210
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +10
-0+ int ret; + + pr_info("Xilinx LocalLink DMA driver\n"); + + ret = platform_driver_register(&xlldma_driver); + if (ret) + pr_err("xlldma: failed to register platform driver\n"); + + return ret; +}Don't bother with all this. sysfs will tell you whether or not the driver got registered. Do this instead:
drivers/dma/xlldma_plat.c line 210
Quoted 4 lines
drivers/dma/xlldma_plat.c +4
-0+static int __init xlldma_plat_init (void ) +{ +return platform_driver_register (&xlldma_driver); +}
OK
Quoted 10 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 217
Quoted 8 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +7
-0+ +static void __exit xlldma_plat_exit(void) +{ + platform_driver_unregister(&xlldma_driver); +} + +module_init(xlldma_plat_init);Put the
module_initdirectly after thexlldma_plat_init()function definition.
OK
Quoted 6 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 line 222
Quoted 6 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +5
-0+module_exit(xlldma_plat_exit); + +MODULE_AUTHOR("Digital Design Corporation"); +MODULE_DESCRIPTION("Xilinx LocalLink DMA Platform driver"); +MODULE_LICENSE("GPL");
Thanks for taking the time to review this.
------------------------------------------------------------------------
Steven J. Magnani "I claim this network for MARS!
www.digidescorp.com Earthling, return my space modulator!"
#include <standard.disclaimer>
Quoted 16 lines · Steven J. Magnani
Quoted 5 lines · Grant Likely
Quoted 3 lines · Steven J. Magnani
Platform bus attachment for the Xilinx MPMC Soft Direct Memory Access Controller DMA engine.
Quoted 9 lines
drivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500
Quoted 5 lines
Signed-off-by Steven J. Magnani <[email protected]>---
diff -uprNa/drivers/dma/xlldma_plat.cb/drivers/dma/xlldma_plat.cdrivers/dma/xlldma_plat.c 2010-03-17 11:11:16.000000000 -0500 renamed from drivers/dma/xlldma_plat.c 1969-12-31 18:00:00.000000000 -0600 +0
-0Not really worth putting into a separate file. Just put this hunk in the
xlldma.cfile to keep a few more symbols out of the global namespace.
Quoted 5 lines
I can certainly do that, but as someone who's had to add platform bus attachments to drivers that only have OF attachments, I can say from experience that the result ends up being rather messy. I thought (explicitly) decoupling the bus logic from the driver might be an improvement. Maybe it's not enough of a benefit.
of_platform is geting merged with platform bus so this issue is going away. Just put it all in one file.
g.