diff options
author | Pete Zaitcev <zaitcev@redhat.com> | 2005-08-15 19:53:57 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-08 19:28:36 -0400 |
commit | 0256839619d9b1e933cafc83e7f0deaad4216465 (patch) | |
tree | afadd5815781a99e06ebb537d8ac677d307c09fe /drivers/usb/mon/mon_dma.c | |
parent | d0384200f6b608e77fb5ddf7dfae1bf0e42c1c6e (diff) |
[PATCH] usbmon in 2.6.13: peeking into DMA areas
This code looks at urb->transfer_dma, maps the page and takes the data.
I am looking for volunteers to contribute architectures other than i386
or to develop an architecure-neutral API for it (or point me that it
was done already).
Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/mon/mon_dma.c')
-rw-r--r-- | drivers/usb/mon/mon_dma.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/drivers/usb/mon/mon_dma.c b/drivers/usb/mon/mon_dma.c new file mode 100644 index 000000000000..0a1367b760a0 --- /dev/null +++ b/drivers/usb/mon/mon_dma.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * The USB Monitor, inspired by Dave Harding's USBMon. | ||
3 | * | ||
4 | * mon_dma.c: Library which snoops on DMA areas. | ||
5 | * | ||
6 | * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com) | ||
7 | */ | ||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/list.h> | ||
10 | #include <linux/highmem.h> | ||
11 | #include <asm/page.h> | ||
12 | |||
13 | #include <linux/usb.h> /* Only needed for declarations in usb_mon.h */ | ||
14 | #include "usb_mon.h" | ||
15 | |||
16 | #ifdef __i386__ /* CONFIG_ARCH_I386 does not exit */ | ||
17 | #define MON_HAS_UNMAP 1 | ||
18 | |||
19 | #define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT) | ||
20 | |||
21 | char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len) | ||
22 | { | ||
23 | struct page *pg; | ||
24 | unsigned long flags; | ||
25 | unsigned char *map; | ||
26 | unsigned char *ptr; | ||
27 | |||
28 | /* | ||
29 | * On i386, a DMA handle is the "physical" address of a page. | ||
30 | * In other words, the bus address is equal to physical address. | ||
31 | * There is no IOMMU. | ||
32 | */ | ||
33 | pg = phys_to_page(dma_addr); | ||
34 | |||
35 | /* | ||
36 | * We are called from hardware IRQs in case of callbacks. | ||
37 | * But we can be called from softirq or process context in case | ||
38 | * of submissions. In such case, we need to protect KM_IRQ0. | ||
39 | */ | ||
40 | local_irq_save(flags); | ||
41 | map = kmap_atomic(pg, KM_IRQ0); | ||
42 | ptr = map + (dma_addr & (PAGE_SIZE-1)); | ||
43 | memcpy(dst, ptr, len); | ||
44 | kunmap_atomic(map, KM_IRQ0); | ||
45 | local_irq_restore(flags); | ||
46 | return 0; | ||
47 | } | ||
48 | #endif /* __i386__ */ | ||
49 | |||
50 | #ifndef MON_HAS_UNMAP | ||
51 | char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len) | ||
52 | { | ||
53 | return 'D'; | ||
54 | } | ||
55 | #endif | ||