Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 145931
b: refs/heads/master
c: bdc2911
h: refs/heads/master
i:
  145929: e2e1d68
  145927: 6fd82e7
v: v3
  • Loading branch information
Joerg Roedel committed Jun 2, 2009
1 parent 31f357d commit e3d1c06
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 016ea6874a6d58df85b54f56997d26df13c307b2
refs/heads/master: bdc2911cde7d18580a545483844d75fdb3551729
124 changes: 103 additions & 21 deletions trunk/lib/dma-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ static const char *type2name[4] = { "single", "page",
static const char *dir2name[4] = { "DMA_BIDIRECTIONAL", "DMA_TO_DEVICE",
"DMA_FROM_DEVICE", "DMA_NONE" };

/* little merge helper - remove it after the merge window */
#ifndef BUS_NOTIFY_UNBOUND_DRIVER
#define BUS_NOTIFY_UNBOUND_DRIVER 0x0005
#endif

/*
* The access to some variables in this macro is racy. We can't use atomic_t
* here because all these variables are exported to debugfs. Some of them even
Expand Down Expand Up @@ -605,9 +610,60 @@ static int dma_debug_fs_init(void)
return -ENOMEM;
}

static int device_dma_allocations(struct device *dev)
{
struct dma_debug_entry *entry;
unsigned long flags;
int count = 0, i;

for (i = 0; i < HASH_SIZE; ++i) {
spin_lock_irqsave(&dma_entry_hash[i].lock, flags);
list_for_each_entry(entry, &dma_entry_hash[i].list, list) {
if (entry->dev == dev)
count += 1;
}
spin_unlock_irqrestore(&dma_entry_hash[i].lock, flags);
}

return count;
}

static int dma_debug_device_change(struct notifier_block *nb,
unsigned long action, void *data)
{
struct device *dev = data;
int count;


switch (action) {
case BUS_NOTIFY_UNBOUND_DRIVER:
count = device_dma_allocations(dev);
if (count == 0)
break;
err_printk(dev, NULL, "DMA-API: device driver has pending "
"DMA allocations while released from device "
"[count=%d]\n", count);
break;
default:
break;
}

return 0;
}

void dma_debug_add_bus(struct bus_type *bus)
{
/* FIXME: register notifier */
struct notifier_block *nb;

nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
if (nb == NULL) {
printk(KERN_ERR "dma_debug_add_bus: out of memory\n");
return;
}

nb->notifier_call = dma_debug_device_change;

bus_register_notifier(bus, nb);
}

/*
Expand Down Expand Up @@ -930,29 +986,48 @@ void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
entry->type = dma_debug_sg;
entry->dev = dev;
entry->paddr = sg_phys(s);
entry->size = s->length;
entry->dev_addr = s->dma_address;
entry->size = sg_dma_len(s);
entry->dev_addr = sg_dma_address(s);
entry->direction = direction;
entry->sg_call_ents = nents;
entry->sg_mapped_ents = mapped_ents;

if (!PageHighMem(sg_page(s))) {
check_for_stack(dev, sg_virt(s));
check_for_illegal_area(dev, sg_virt(s), s->length);
check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s));
}

add_dma_entry(entry);
}
}
EXPORT_SYMBOL(debug_dma_map_sg);

static int get_nr_mapped_entries(struct device *dev, struct scatterlist *s)
{
struct dma_debug_entry *entry;
struct hash_bucket *bucket;
unsigned long flags;
int mapped_ents = 0;
struct dma_debug_entry ref;

ref.dev = dev;
ref.dev_addr = sg_dma_address(s);
ref.size = sg_dma_len(s),

bucket = get_hash_bucket(&ref, &flags);
entry = hash_bucket_find(bucket, &ref);
if (entry)
mapped_ents = entry->sg_mapped_ents;
put_hash_bucket(bucket, &flags);

return mapped_ents;
}

void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
int nelems, int dir)
{
struct dma_debug_entry *entry;
struct scatterlist *s;
int mapped_ents = 0, i;
unsigned long flags;

if (unlikely(global_disable))
return;
Expand All @@ -963,23 +1038,18 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
.type = dma_debug_sg,
.dev = dev,
.paddr = sg_phys(s),
.dev_addr = s->dma_address,
.size = s->length,
.dev_addr = sg_dma_address(s),
.size = sg_dma_len(s),
.direction = dir,
.sg_call_ents = 0,
};

if (mapped_ents && i >= mapped_ents)
break;

if (mapped_ents == 0) {
struct hash_bucket *bucket;
if (!i) {
ref.sg_call_ents = nelems;
bucket = get_hash_bucket(&ref, &flags);
entry = hash_bucket_find(bucket, &ref);
if (entry)
mapped_ents = entry->sg_mapped_ents;
put_hash_bucket(bucket, &flags);
mapped_ents = get_nr_mapped_entries(dev, s);
}

check_unmap(&ref);
Expand Down Expand Up @@ -1081,14 +1151,20 @@ void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
int nelems, int direction)
{
struct scatterlist *s;
int i;
int mapped_ents = 0, i;

if (unlikely(global_disable))
return;

for_each_sg(sg, s, nelems, i) {
check_sync(dev, s->dma_address, s->dma_length, 0,
direction, true);
if (!i)
mapped_ents = get_nr_mapped_entries(dev, s);

if (i >= mapped_ents)
break;

check_sync(dev, sg_dma_address(s), sg_dma_len(s), 0,
direction, true);
}
}
EXPORT_SYMBOL(debug_dma_sync_sg_for_cpu);
Expand All @@ -1097,14 +1173,20 @@ void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
int nelems, int direction)
{
struct scatterlist *s;
int i;
int mapped_ents = 0, i;

if (unlikely(global_disable))
return;

for_each_sg(sg, s, nelems, i) {
check_sync(dev, s->dma_address, s->dma_length, 0,
direction, false);
if (!i)
mapped_ents = get_nr_mapped_entries(dev, s);

if (i >= mapped_ents)
break;

check_sync(dev, sg_dma_address(s), sg_dma_len(s), 0,
direction, false);
}
}
EXPORT_SYMBOL(debug_dma_sync_sg_for_device);
Expand Down

0 comments on commit e3d1c06

Please sign in to comment.