Release 4.14 arch/sh/drivers/dma/dma-api.c
/*
* arch/sh/drivers/dma/dma-api.c
*
* SuperH-specific DMA management API
*
* Copyright (C) 2003, 2004, 2005 Paul Mundt
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/list.h>
#include <linux/platform_device.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <asm/dma.h>
DEFINE_SPINLOCK(dma_spin_lock);
static LIST_HEAD(registered_dmac_list);
struct dma_info *get_dma_info(unsigned int chan)
{
struct dma_info *info;
/*
* Look for each DMAC's range to determine who the owner of
* the channel is.
*/
list_for_each_entry(info, ®istered_dmac_list, list) {
if ((chan < info->first_vchannel_nr) ||
(chan >= info->first_vchannel_nr + info->nr_channels))
continue;
return info;
}
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 26 | 46.43% | 1 | 16.67% |
Andrew Morton | 18 | 32.14% | 2 | 33.33% |
Paul Mundt | 6 | 10.71% | 1 | 16.67% |
Linus Torvalds | 4 | 7.14% | 1 | 16.67% |
Adrian McMenamin | 2 | 3.57% | 1 | 16.67% |
Total | 56 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(get_dma_info);
struct dma_info *get_dma_info_by_name(const char *dmac_name)
{
struct dma_info *info;
list_for_each_entry(info, ®istered_dmac_list, list) {
if (dmac_name && (strcmp(dmac_name, info->name) != 0))
continue;
else
return info;
}
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 40 | 76.92% | 1 | 33.33% |
Andrew Morton | 11 | 21.15% | 1 | 33.33% |
Linus Torvalds | 1 | 1.92% | 1 | 33.33% |
Total | 52 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(get_dma_info_by_name);
static unsigned int get_nr_channels(void)
{
struct dma_info *info;
unsigned int nr = 0;
if (unlikely(list_empty(®istered_dmac_list)))
return nr;
list_for_each_entry(info, ®istered_dmac_list, list)
nr += info->nr_channels;
return nr;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Mundt | 51 | 100.00% | 1 | 100.00% |
Total | 51 | 100.00% | 1 | 100.00% |
struct dma_channel *get_dma_channel(unsigned int chan)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel;
int i;
if (unlikely(!info))
return ERR_PTR(-EINVAL);
for (i = 0; i < info->nr_channels; i++) {
channel = &info->channels[i];
if (channel->vchan == chan)
return channel;
}
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 47 | 55.29% | 1 | 20.00% |
Andrew Morton | 35 | 41.18% | 2 | 40.00% |
Linus Torvalds | 2 | 2.35% | 1 | 20.00% |
Adrian McMenamin | 1 | 1.18% | 1 | 20.00% |
Total | 85 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(get_dma_channel);
int get_dma_residue(unsigned int chan)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel = get_dma_channel(chan);
if (info->ops->get_residue)
return info->ops->get_residue(channel);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 38 | 76.00% | 2 | 50.00% |
Linus Torvalds | 9 | 18.00% | 1 | 25.00% |
Mark Glaisher | 3 | 6.00% | 1 | 25.00% |
Total | 50 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(get_dma_residue);
static int search_cap(const char **haystack, const char *needle)
{
const char **p;
for (p = haystack; *p; p++)
if (strcmp(*p, needle) == 0)
return 1;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 35 | 66.04% | 1 | 25.00% |
Linus Torvalds | 10 | 18.87% | 1 | 25.00% |
Andrew Morton | 8 | 15.09% | 2 | 50.00% |
Total | 53 | 100.00% | 4 | 100.00% |
/**
* request_dma_bycap - Allocate a DMA channel based on its capabilities
* @dmac: List of DMA controllers to search
* @caps: List of capabilities
*
* Search all channels of all DMA controllers to find a channel which
* matches the requested capabilities. The result is the channel
* number if a match is found, or %-ENODEV if no match is found.
*
* Note that not all DMA controllers export capabilities, in which
* case they can never be allocated using this API, and so
* request_dma() must be used specifying the channel number.
*/
int request_dma_bycap(const char **dmac, const char **caps, const char *dev_id)
{
unsigned int found = 0;
struct dma_info *info;
const char **p;
int i;
BUG_ON(!dmac || !caps);
list_for_each_entry(info, ®istered_dmac_list, list)
if (strcmp(*dmac, info->name) == 0) {
found = 1;
break;
}
if (!found)
return -ENODEV;
for (i = 0; i < info->nr_channels; i++) {
struct dma_channel *channel = &info->channels[i];
if (unlikely(!channel->caps))
continue;
for (p = caps; *p; p++) {
if (!search_cap(channel->caps, *p))
break;
if (request_dma(channel->chan, dev_id) == 0)
return channel->chan;
}
}
return -EINVAL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 180 | 100.00% | 1 | 100.00% |
Total | 180 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(request_dma_bycap);
int dmac_search_free_channel(const char *dev_id)
{
struct dma_channel *channel = { 0 };
struct dma_info *info = get_dma_info(0);
int i;
for (i = 0; i < info->nr_channels; i++) {
channel = &info->channels[i];
if (unlikely(!channel))
return -ENODEV;
if (atomic_read(&channel->busy) == 0)
break;
}
if (info->ops->request) {
int result = info->ops->request(channel);
if (result)
return result;
atomic_set(&channel->busy, 1);
return channel->chan;
}
return -ENOSYS;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 132 | 100.00% | 1 | 100.00% |
Total | 132 | 100.00% | 1 | 100.00% |
int request_dma(unsigned int chan, const char *dev_id)
{
struct dma_channel *channel = { 0 };
struct dma_info *info = get_dma_info(chan);
int result;
channel = get_dma_channel(chan);
if (atomic_xchg(&channel->busy, 1))
return -EBUSY;
strlcpy(channel->dev_id, dev_id, sizeof(channel->dev_id));
if (info->ops->request) {
result = info->ops->request(channel);
if (result)
atomic_set(&channel->busy, 0);
return result;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 77 | 66.38% | 1 | 25.00% |
Andrew Morton | 29 | 25.00% | 2 | 50.00% |
Linus Torvalds | 10 | 8.62% | 1 | 25.00% |
Total | 116 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(request_dma);
void free_dma(unsigned int chan)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel = get_dma_channel(chan);
if (info->ops->free)
info->ops->free(channel);
atomic_set(&channel->busy, 0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 35 | 62.50% | 2 | 50.00% |
Linus Torvalds | 18 | 32.14% | 1 | 25.00% |
Mark Glaisher | 3 | 5.36% | 1 | 25.00% |
Total | 56 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(free_dma);
void dma_wait_for_completion(unsigned int chan)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel = get_dma_channel(chan);
if (channel->flags & DMA_TEI_CAPABLE) {
wait_event(channel->wait_queue,
(info->ops->get_residue(channel) == 0));
return;
}
while (info->ops->get_residue(channel))
cpu_relax();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 55 | 74.32% | 3 | 60.00% |
Mark Glaisher | 14 | 18.92% | 1 | 20.00% |
Linus Torvalds | 5 | 6.76% | 1 | 20.00% |
Total | 74 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(dma_wait_for_completion);
int register_chan_caps(const char *dmac, struct dma_chan_caps *caps)
{
struct dma_info *info;
unsigned int found = 0;
int i;
list_for_each_entry(info, ®istered_dmac_list, list)
if (strcmp(dmac, info->name) == 0) {
found = 1;
break;
}
if (unlikely(!found))
return -ENODEV;
for (i = 0; i < info->nr_channels; i++, caps++) {
struct dma_channel *channel;
if ((info->first_channel_nr + i) != caps->ch_num)
return -EINVAL;
channel = &info->channels[i];
channel->caps = caps->caplist;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 130 | 97.74% | 1 | 33.33% |
Linus Torvalds | 2 | 1.50% | 1 | 33.33% |
Andrew Morton | 1 | 0.75% | 1 | 33.33% |
Total | 133 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(register_chan_caps);
void dma_configure_channel(unsigned int chan, unsigned long flags)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel = get_dma_channel(chan);
if (info->ops->configure)
info->ops->configure(channel, flags);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 29 | 55.77% | 2 | 50.00% |
Linus Torvalds | 20 | 38.46% | 1 | 25.00% |
Mark Glaisher | 3 | 5.77% | 1 | 25.00% |
Total | 52 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(dma_configure_channel);
int dma_xfer(unsigned int chan, unsigned long from,
unsigned long to, size_t size, unsigned int mode)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel = get_dma_channel(chan);
channel->sar = from;
channel->dar = to;
channel->count = size;
channel->mode = mode;
return info->ops->xfer(channel);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 52 | 66.67% | 2 | 50.00% |
Linus Torvalds | 23 | 29.49% | 1 | 25.00% |
Mark Glaisher | 3 | 3.85% | 1 | 25.00% |
Total | 78 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(dma_xfer);
int dma_extend(unsigned int chan, unsigned long op, void *param)
{
struct dma_info *info = get_dma_info(chan);
struct dma_channel *channel = get_dma_channel(chan);
if (info->ops->extend)
return info->ops->extend(channel, op, param);
return -ENOSYS;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 63 | 100.00% | 1 | 100.00% |
Total | 63 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(dma_extend);
static int dma_proc_show(struct seq_file *m, void *v)
{
struct dma_info *info = v;
if (list_empty(®istered_dmac_list))
return 0;
/*
* Iterate over each registered DMAC
*/
list_for_each_entry(info, ®istered_dmac_list, list) {
int i;
/*
* Iterate over each channel
*/
for (i = 0; i < info->nr_channels; i++) {
struct dma_channel *channel = info->channels + i;
if (!(channel->flags & DMA_CONFIGURED))
continue;
seq_printf(m, "%2d: %14s %s\n", i,
info->name, channel->dev_id);
}
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 73 | 67.59% | 2 | 40.00% |
Linus Torvalds | 18 | 16.67% | 1 | 20.00% |
David Howells | 11 | 10.19% | 1 | 20.00% |
Paul Mundt | 6 | 5.56% | 1 | 20.00% |
Total | 108 | 100.00% | 5 | 100.00% |
static int dma_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, dma_proc_show, NULL);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Howells | 24 | 92.31% | 1 | 50.00% |
Andrew Morton | 2 | 7.69% | 1 | 50.00% |
Total | 26 | 100.00% | 2 | 100.00% |
static const struct file_operations dma_proc_fops = {
.open = dma_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
int register_dmac(struct dma_info *info)
{
unsigned int total_channels, i;
INIT_LIST_HEAD(&info->list);
printk(KERN_INFO "DMA: Registering %s handler (%d channel%s).\n",
info->name, info->nr_channels, info->nr_channels > 1 ? "s" : "");
BUG_ON((info->flags & DMAC_CHANNELS_CONFIGURED) && !info->channels);
info->pdev = platform_device_register_simple(info->name, -1,
NULL, 0);
if (IS_ERR(info->pdev))
return PTR_ERR(info->pdev);
/*
* Don't touch pre-configured channels
*/
if (!(info->flags & DMAC_CHANNELS_CONFIGURED)) {
unsigned int size;
size = sizeof(struct dma_channel) * info->nr_channels;
info->channels = kzalloc(size, GFP_KERNEL);
if (!info->channels)
return -ENOMEM;
}
total_channels = get_nr_channels();
info->first_vchannel_nr = total_channels;
for (i = 0; i < info->nr_channels; i++) {
struct dma_channel *chan = &info->channels[i];
atomic_set(&chan->busy, 0);
chan->chan = info->first_channel_nr + i;
chan->vchan = info->first_channel_nr + i + total_channels;
memcpy(chan->dev_id, "Unused", 7);
if (info->flags & DMAC_CHANNELS_TEI_CAPABLE)
chan->flags |= DMA_TEI_CAPABLE;
init_waitqueue_head(&chan->wait_queue);
dma_create_sysfs_files(chan, info);
}
list_add(&info->list, ®istered_dmac_list);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Morton | 169 | 60.79% | 3 | 37.50% |
Paul Mundt | 64 | 23.02% | 2 | 25.00% |
Mark Glaisher | 22 | 7.91% | 1 | 12.50% |
Linus Torvalds | 17 | 6.12% | 1 | 12.50% |
Adrian McMenamin | 6 | 2.16% | 1 | 12.50% |
Total | 278 | 100.00% | 8 | 100.00% |
EXPORT_SYMBOL(register_dmac);
void unregister_dmac(struct dma_info *info)
{
unsigned int i;
for (i = 0; i < info->nr_channels; i++)
dma_remove_sysfs_files(info->channels + i, info);
if (!(info->flags & DMAC_CHANNELS_CONFIGURED))
kfree(info->channels);
list_del(&info->list);
platform_device_unregister(info->pdev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Mundt | 37 | 50.68% | 1 | 50.00% |
Andrew Morton | 36 | 49.32% | 1 | 50.00% |
Total | 73 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(unregister_dmac);
static int __init dma_api_init(void)
{
printk(KERN_NOTICE "DMA: Registering DMA API.\n");
return proc_create("dma", 0, NULL, &dma_proc_fops) ? 0 : -ENOMEM;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds | 12 | 36.36% | 1 | 20.00% |
Andrew Morton | 11 | 33.33% | 1 | 20.00% |
Vasiliy Kulikov | 5 | 15.15% | 1 | 20.00% |
David Howells | 4 | 12.12% | 1 | 20.00% |
Mark Glaisher | 1 | 3.03% | 1 | 20.00% |
Total | 33 | 100.00% | 5 | 100.00% |
subsys_initcall(dma_api_init);
MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
MODULE_DESCRIPTION("DMA API for SuperH");
MODULE_LICENSE("GPL");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Glaisher | 853 | 44.59% | 1 | 6.67% |
Andrew Morton | 627 | 32.78% | 3 | 20.00% |
Linus Torvalds | 171 | 8.94% | 1 | 6.67% |
Paul Mundt | 167 | 8.73% | 2 | 13.33% |
David Howells | 69 | 3.61% | 1 | 6.67% |
Adrian McMenamin | 9 | 0.47% | 1 | 6.67% |
Vasiliy Kulikov | 5 | 0.26% | 1 | 6.67% |
Thomas Gleixner | 4 | 0.21% | 1 | 6.67% |
Manuel Lauss | 3 | 0.16% | 1 | 6.67% |
Tejun Heo | 3 | 0.16% | 1 | 6.67% |
Simon Arlott | 1 | 0.05% | 1 | 6.67% |
Al Viro | 1 | 0.05% | 1 | 6.67% |
Total | 1913 | 100.00% | 15 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.