diff options
Diffstat (limited to 'drivers/usb/mon')
-rw-r--r-- | drivers/usb/mon/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/mon/mon_dma.c | 55 | ||||
-rw-r--r-- | drivers/usb/mon/mon_text.c | 35 | ||||
-rw-r--r-- | drivers/usb/mon/usb_mon.h | 4 |
4 files changed, 77 insertions, 19 deletions
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile index b0015b8a1d1f..3cf3ea3a88ed 100644 --- a/drivers/usb/mon/Makefile +++ b/drivers/usb/mon/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for USB Core files and filesystem | 2 | # Makefile for USB Core files and filesystem |
3 | # | 3 | # |
4 | 4 | ||
5 | usbmon-objs := mon_main.o mon_stat.o mon_text.o | 5 | usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_dma.o |
6 | 6 | ||
7 | # This does not use CONFIG_USB_MON because we want this to use a tristate. | 7 | # This does not use CONFIG_USB_MON because we want this to use a tristate. |
8 | obj-$(CONFIG_USB) += usbmon.o | 8 | obj-$(CONFIG_USB) += usbmon.o |
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 | ||
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c index 26266b30028e..417464dea9f6 100644 --- a/drivers/usb/mon/mon_text.c +++ b/drivers/usb/mon/mon_text.c | |||
@@ -91,25 +91,11 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, | |||
91 | int len, char ev_type) | 91 | int len, char ev_type) |
92 | { | 92 | { |
93 | int pipe = urb->pipe; | 93 | int pipe = urb->pipe; |
94 | unsigned char *data; | ||
95 | |||
96 | /* | ||
97 | * The check to see if it's safe to poke at data has an enormous | ||
98 | * number of corner cases, but it seems that the following is | ||
99 | * more or less safe. | ||
100 | * | ||
101 | * We do not even try to look transfer_buffer, because it can | ||
102 | * contain non-NULL garbage in case the upper level promised to | ||
103 | * set DMA for the HCD. | ||
104 | */ | ||
105 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) | ||
106 | return 'D'; | ||
107 | 94 | ||
108 | if (len <= 0) | 95 | if (len <= 0) |
109 | return 'L'; | 96 | return 'L'; |
110 | 97 | if (len >= DATA_MAX) | |
111 | if ((data = urb->transfer_buffer) == NULL) | 98 | len = DATA_MAX; |
112 | return 'Z'; /* '0' would be not as pretty. */ | ||
113 | 99 | ||
114 | /* | 100 | /* |
115 | * Bulk is easy to shortcut reliably. | 101 | * Bulk is easy to shortcut reliably. |
@@ -126,8 +112,21 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, | |||
126 | } | 112 | } |
127 | } | 113 | } |
128 | 114 | ||
129 | if (len >= DATA_MAX) | 115 | /* |
130 | len = DATA_MAX; | 116 | * The check to see if it's safe to poke at data has an enormous |
117 | * number of corner cases, but it seems that the following is | ||
118 | * more or less safe. | ||
119 | * | ||
120 | * We do not even try to look transfer_buffer, because it can | ||
121 | * contain non-NULL garbage in case the upper level promised to | ||
122 | * set DMA for the HCD. | ||
123 | */ | ||
124 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) | ||
125 | return mon_dmapeek(ep->data, urb->transfer_dma, len); | ||
126 | |||
127 | if (urb->transfer_buffer == NULL) | ||
128 | return 'Z'; /* '0' would be not as pretty. */ | ||
129 | |||
131 | memcpy(ep->data, urb->transfer_buffer, len); | 130 | memcpy(ep->data, urb->transfer_buffer, len); |
132 | return 0; | 131 | return 0; |
133 | } | 132 | } |
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h index 9b06784d2c48..4be0f9346071 100644 --- a/drivers/usb/mon/usb_mon.h +++ b/drivers/usb/mon/usb_mon.h | |||
@@ -45,6 +45,10 @@ struct mon_reader { | |||
45 | void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r); | 45 | void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r); |
46 | void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); | 46 | void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); |
47 | 47 | ||
48 | /* | ||
49 | */ | ||
50 | extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len); | ||
51 | |||
48 | extern struct semaphore mon_lock; | 52 | extern struct semaphore mon_lock; |
49 | 53 | ||
50 | extern struct file_operations mon_fops_text; | 54 | extern struct file_operations mon_fops_text; |